Skip to content

release: web #113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Expand Up @@ -33,7 +33,7 @@ import { Client, Account } from "appwrite";
To install with a CDN (content delivery network) add the following scripts to the bottom of your <body> tag, but before you use any Appwrite services:

```html
<script src="https://cdn.jsdelivr.net/npm/appwrite@16.0.3"></script>
<script src="https://cdn.jsdelivr.net/npm/appwrite@16.1.0"></script>
```


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "appwrite",
"homepage": "https://appwrite.io/support",
"description": "Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API",
"version": "16.0.3",
"version": "16.1.0",
"license": "BSD-3-Clause",
"main": "dist/cjs/sdk.js",
"exports": {
Expand Down
39 changes: 34 additions & 5 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ type Headers = {
*/
type RealtimeResponse = {
/**
* Type of the response: 'error', 'event', 'connected', or 'response'.
* Type of the response: 'error', 'event', 'connected', 'pong', or 'response'.
*/
type: 'error' | 'event' | 'connected' | 'response';
type: 'error' | 'event' | 'connected' | 'response' | 'pong';

/**
* Data associated with the response based on the response type.
Expand Down Expand Up @@ -129,6 +129,8 @@ type RealtimeRequestAuthenticate = {
session: string;
}

type TimeoutHandle = ReturnType<typeof setTimeout> | number;

/**
* Realtime interface representing the structure of a realtime communication object.
*/
Expand All @@ -139,9 +141,14 @@ type Realtime = {
socket?: WebSocket;

/**
* Timeout duration for communication operations.
* Timeout for reconnect operations.
*/
timeout?: number;
timeout?: TimeoutHandle;

/**
* Heartbeat interval for the realtime connection.
*/
heartbeat?: TimeoutHandle;

/**
* URL for establishing the WebSocket connection.
Expand Down Expand Up @@ -196,6 +203,11 @@ type Realtime = {
*/
createSocket: () => void;

/**
* Function to create a new heartbeat interval.
*/
createHeartbeat: () => void;

/**
* Function to clean up resources associated with specified channels.
*
Expand Down Expand Up @@ -303,7 +315,7 @@ class Client {
'x-sdk-name': 'Web',
'x-sdk-platform': 'client',
'x-sdk-language': 'web',
'x-sdk-version': '16.0.3',
'x-sdk-version': '16.1.0',
'X-Appwrite-Response-Format': '1.6.0',
};

Expand Down Expand Up @@ -394,6 +406,7 @@ class Client {
private realtime: Realtime = {
socket: undefined,
timeout: undefined,
heartbeat: undefined,
url: '',
channels: new Set(),
subscriptions: new Map(),
Expand All @@ -419,6 +432,17 @@ class Client {
return 60_000;
}
},
createHeartbeat: () => {
if (this.realtime.heartbeat) {
clearTimeout(this.realtime.heartbeat);
}

this.realtime.heartbeat = window?.setInterval(() => {
this.realtime.socket?.send(JSON.stringify({
type: 'ping'
}));
}, 20_000);
},
createSocket: () => {
if (this.realtime.channels.size < 1) {
this.realtime.reconnect = false;
Expand Down Expand Up @@ -452,6 +476,7 @@ class Client {
this.realtime.socket.addEventListener('message', this.realtime.onMessage);
this.realtime.socket.addEventListener('open', _event => {
this.realtime.reconnectAttempts = 0;
this.realtime.createHeartbeat();
});
this.realtime.socket.addEventListener('close', event => {
if (
Expand Down Expand Up @@ -669,6 +694,10 @@ class Client {
return response;
}

async ping(): Promise<string> {
return this.call('GET', new URL(this.config.endpoint + '/ping'));
}

async call(method: string, url: URL, headers: Headers = {}, params: Payload = {}, responseType = 'json'): Promise<any> {
const { uri, options } = this.prepareRequest(method, url, headers, params);

Expand Down
1 change: 1 addition & 0 deletions src/enums/image-format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export enum ImageFormat {
Gif = 'gif',
Png = 'png',
Webp = 'webp',
Avif = 'avif',
}
10 changes: 7 additions & 3 deletions src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -842,11 +842,11 @@ export namespace Models {
*/
userId: string;
/**
* User name.
* User name. Hide this attribute by toggling membership privacy in the Console.
*/
userName: string;
/**
* User email address.
* User email address. Hide this attribute by toggling membership privacy in the Console.
*/
userEmail: string;
/**
Expand All @@ -870,7 +870,7 @@ export namespace Models {
*/
confirm: boolean;
/**
* Multi factor authentication status, true if the user has MFA enabled or false otherwise.
* Multi factor authentication status, true if the user has MFA enabled or false otherwise. Hide this attribute by toggling membership privacy in the Console.
*/
mfa: boolean;
/**
Expand Down Expand Up @@ -1198,5 +1198,9 @@ export namespace Models {
* The target identifier.
*/
identifier: string;
/**
* Is the target expired.
*/
expired: boolean;
}
}
20 changes: 10 additions & 10 deletions src/services/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ This endpoint can also be used to convert an anonymous account to a normal one,
);
}
/**
* List Identities
* List identities
*
* Get the list of identities for the currently logged in user.
*
Expand Down Expand Up @@ -273,7 +273,7 @@ This endpoint can also be used to convert an anonymous account to a normal one,
);
}
/**
* Create Authenticator
* Create authenticator
*
* Add an authenticator app to be used as an MFA factor. Verify the authenticator using the [verify authenticator](/docs/references/cloud/client-web/account#updateMfaAuthenticator) method.
*
Expand Down Expand Up @@ -302,7 +302,7 @@ This endpoint can also be used to convert an anonymous account to a normal one,
);
}
/**
* Verify Authenticator
* Verify authenticator
*
* Verify an authenticator app after adding it using the [add authenticator](/docs/references/cloud/client-web/account#createMfaAuthenticator) method.
*
Expand Down Expand Up @@ -338,7 +338,7 @@ This endpoint can also be used to convert an anonymous account to a normal one,
);
}
/**
* Delete Authenticator
* Delete authenticator
*
* Delete an authenticator for a user by ID.
*
Expand Down Expand Up @@ -367,7 +367,7 @@ This endpoint can also be used to convert an anonymous account to a normal one,
);
}
/**
* Create MFA Challenge
* Create MFA challenge
*
* Begin the process of MFA verification after sign-in. Finish the flow with [updateMfaChallenge](/docs/references/cloud/client-web/account#updateMfaChallenge) method.
*
Expand Down Expand Up @@ -399,7 +399,7 @@ This endpoint can also be used to convert an anonymous account to a normal one,
);
}
/**
* Create MFA Challenge (confirmation)
* Create MFA challenge (confirmation)
*
* Complete the MFA challenge by providing the one-time password. Finish the process of MFA verification by providing the one-time password. To begin the flow, use [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) method.
*
Expand Down Expand Up @@ -438,7 +438,7 @@ This endpoint can also be used to convert an anonymous account to a normal one,
);
}
/**
* List Factors
* List factors
*
* List the factors available on the account to be used as a MFA challange.
*
Expand All @@ -463,7 +463,7 @@ This endpoint can also be used to convert an anonymous account to a normal one,
);
}
/**
* Get MFA Recovery Codes
* Get MFA recovery codes
*
* Get recovery codes that can be used as backup for MFA flow. Before getting codes, they must be generated using [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) method. An OTP challenge is required to read recovery codes.
*
Expand All @@ -488,7 +488,7 @@ This endpoint can also be used to convert an anonymous account to a normal one,
);
}
/**
* Create MFA Recovery Codes
* Create MFA recovery codes
*
* Generate recovery codes as backup for MFA flow. It&#039;s recommended to generate and show then immediately after user successfully adds their authehticator. Recovery codes can be used as a MFA verification type in [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) method.
*
Expand All @@ -513,7 +513,7 @@ This endpoint can also be used to convert an anonymous account to a normal one,
);
}
/**
* Regenerate MFA Recovery Codes
* Regenerate MFA recovery codes
*
* Regenerate recovery codes that can be used as backup for MFA flow. Before regenerating codes, they must be first generated using [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) method. An OTP challenge is required to regenreate recovery codes.
*
Expand Down
2 changes: 1 addition & 1 deletion src/services/locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class Locale {
);
}
/**
* List Locale Codes
* List locale codes
*
* List of all locale codes in [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes).
*
Expand Down
2 changes: 1 addition & 1 deletion src/services/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ If you&#039;re creating a new file using one of the Appwrite SDKs, all the chunk
);
}
/**
* Delete File
* Delete file
*
* Delete a file by its unique ID. Only users with write permissions have access to delete this resource.
*
Expand Down
4 changes: 2 additions & 2 deletions src/services/teams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export class Teams {
/**
* List team memberships
*
* Use this endpoint to list a team&#039;s members using the team&#039;s ID. All team members have read access to this endpoint.
* Use this endpoint to list a team&#039;s members using the team&#039;s ID. All team members have read access to this endpoint. Hide sensitive attributes from the response by toggling membership privacy in the Console.
*
* @param {string} teamId
* @param {string[]} queries
Expand Down Expand Up @@ -282,7 +282,7 @@ Please note that to avoid a [Redirect Attack](https://github.com/OWASP/CheatShee
/**
* Get team membership
*
* Get a team member by the membership unique id. All team members have read access for this resource.
* Get a team member by the membership unique id. All team members have read access for this resource. Hide sensitive attributes from the response by toggling membership privacy in the Console.
*
* @param {string} teamId
* @param {string} membershipId
Expand Down