Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Appwrite Console SDK

![License](https://img.shields.io/github/license/appwrite/sdk-for-console.svg?style=flat-square)
![Version](https://img.shields.io/badge/api%20version-1.6.1-blue.svg?style=flat-square)
![Version](https://img.shields.io/badge/api%20version-1.6.2-blue.svg?style=flat-square)
[![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator)
[![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite)
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)
Expand Down
23 changes: 20 additions & 3 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,12 @@ class Client {
* @returns {this}
*/
setEndpoint(endpoint: string): this {
if (!endpoint.startsWith('http://') && !endpoint.startsWith('https://')) {
throw new AppwriteException('Invalid endpoint URL: ' + endpoint);
}

this.config.endpoint = endpoint;
this.config.endpointRealtime = this.config.endpointRealtime || this.config.endpoint.replace('https://', 'wss://').replace('http://', 'ws://');
this.config.endpointRealtime = endpoint.replace('https://', 'wss://').replace('http://', 'ws://');

return this;
}
Expand All @@ -344,8 +348,11 @@ class Client {
* @returns {this}
*/
setEndpointRealtime(endpointRealtime: string): this {
this.config.endpointRealtime = endpointRealtime;
if (!endpointRealtime.startsWith('ws://') && !endpointRealtime.startsWith('wss://')) {
throw new AppwriteException('Invalid realtime endpoint URL: ' + endpointRealtime);
}

this.config.endpointRealtime = endpointRealtime;
return this;
}

Expand Down Expand Up @@ -669,6 +676,10 @@ class Client {
async chunkedUpload(method: string, url: URL, headers: Headers = {}, originalPayload: Payload = {}, onProgress: (progress: UploadProgress) => void) {
const file = Object.values(originalPayload).find((value) => value instanceof File);

if (!file) {
throw new Error('File not found in payload');
}

if (file.size <= Client.CHUNK_SIZE) {
return await this.call(method, url, headers, originalPayload);
}
Expand Down Expand Up @@ -736,7 +747,13 @@ class Client {
}

if (400 <= response.status) {
throw new AppwriteException(data?.message, response.status, data?.type, data);
let responseText = '';
if (response.headers.get('content-type')?.includes('application/json') || responseType === 'arrayBuffer') {
responseText = JSON.stringify(data);
} else {
responseText = data?.message;
}
throw new AppwriteException(data?.message, response.status, data?.type, responseText);
}

const cookieFallback = response.headers.get('X-Fallback-Cookies');
Expand Down
124 changes: 118 additions & 6 deletions src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ export namespace Models {
/**
* Collection attributes.
*/
attributes: string[];
attributes: (Models.AttributeBoolean | Models.AttributeInteger | Models.AttributeFloat | Models.AttributeEmail | Models.AttributeEnum | Models.AttributeUrl | Models.AttributeIp | Models.AttributeDatetime | Models.AttributeRelationship | Models.AttributeString)[];
/**
* Collection indexes.
*/
Expand All @@ -611,7 +611,7 @@ export namespace Models {
/**
* List of attributes.
*/
attributes: string[];
attributes: (Models.AttributeBoolean | Models.AttributeInteger | Models.AttributeFloat | Models.AttributeEmail | Models.AttributeEnum | Models.AttributeUrl | Models.AttributeIp | Models.AttributeDatetime | Models.AttributeRelationship | Models.AttributeString)[];
}
/**
* AttributeString
Expand Down Expand Up @@ -4340,6 +4340,10 @@ export namespace Models {
* Region ID
*/
$id: string;
/**
* User ID
*/
userId: string;
/**
* Street address
*/
Expand Down Expand Up @@ -4456,11 +4460,11 @@ export namespace Models {
/**
* Additional resources
*/
usage: AdditionalResource[];
usage: UsageBillingPlan;
/**
* Addons
*/
addons: BillingPlanAddon[];
addons: BillingPlanAddon;
/**
* Custom SMTP
*/
Expand Down Expand Up @@ -4514,6 +4518,15 @@ export namespace Models {
* BillingPlanAddon
*/
export type BillingPlanAddon = {
/**
* Addon seats
*/
seats: BillingPlanAddonDetails;
}
/**
* BillingPlanAddonDetails
*/
export type BillingPlanAddonDetails = {
/**
* Is the addon supported in the plan?
*/
Expand All @@ -4539,6 +4552,39 @@ export namespace Models {
*/
value: number;
}
/**
* BillingLimits
*/
export type BillingLimits = {
/**
* Bandwidth limit
*/
bandwidth: number;
/**
* Storage limit
*/
storage: number;
/**
* Users limit
*/
users: number;
/**
* Executions limit
*/
executions: number;
/**
* GBHours limit
*/
GBHours: number;
/**
* Image transformations limit
*/
imageTransformations: number;
/**
* Auth phone limit
*/
authPhone: number;
}
/**
* Campaign
*/
Expand Down Expand Up @@ -4624,6 +4670,10 @@ export namespace Models {
* Status of the coupon. Can be one of `disabled`, `active` or `expired`.
*/
status: string;
/**
* If the coupon is only valid for new organizations or not.
*/
onlyNewOrgs: boolean;
}
/**
* Credit
Expand Down Expand Up @@ -4726,7 +4776,7 @@ export namespace Models {
/**
* Usage breakdown per resource
*/
usage: object;
usage: UsageInvoice[];
/**
* Invoice Amount
*/
Expand Down Expand Up @@ -4899,7 +4949,7 @@ export namespace Models {
/**
* Billing limits reached
*/
billingLimits: object;
billingLimits: BillingLimits;
/**
* Billing plan downgrade
*/
Expand Down Expand Up @@ -5285,6 +5335,68 @@ export namespace Models {
*/
authPhoneEstimate: number;
}
/**
* UsageInvoice
*/
export type UsageInvoice = {
/**
* Invoice name
*/
name: string;
/**
* Invoice value
*/
value: number;
/**
* Invoice amount
*/
amount: number;
/**
* Invoice rate
*/
rate: number;
/**
* Invoice description
*/
desc: string;
}
/**
* usageBillingPlan
*/
export type UsageBillingPlan = {
/**
* Bandwidth additional resources
*/
bandwidth: AdditionalResource;
/**
* Executions additional resources
*/
executions: AdditionalResource;
/**
* Member additional resources
*/
member: AdditionalResource;
/**
* Realtime additional resources
*/
realtime: AdditionalResource;
/**
* Storage additional resources
*/
storage: AdditionalResource;
/**
* User additional resources
*/
users: AdditionalResource;
/**
* GBHour additional resources
*/
GBHours: AdditionalResource;
/**
* Image transformation additional resources
*/
imageTransformations: AdditionalResource;
}
/**
* Aggregation team list
*/
Expand Down
Loading