Skip to content

Commit 0c95b17

Browse files
authored
Merge pull request #142 from appwrite/dev
feat: Web SDK update for version 21.1.0
2 parents 2f195ce + 047a15f commit 0c95b17

File tree

8 files changed

+180
-19
lines changed

8 files changed

+180
-19
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Change Log
22

3+
## 21.1.0
4+
5+
* Deprecate `createVerification` method in `Account` service
6+
* Add `createEmailVerification` method in `Account` service
7+
38
## 18.2.0
49

510
* Add `incrementDocumentAttribute` and `decrementDocumentAttribute` support to `Databases` service

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { Client, Account } from "appwrite";
3333
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:
3434

3535
```html
36-
<script src="https://cdn.jsdelivr.net/npm/appwrite@21.0.0"></script>
36+
<script src="https://cdn.jsdelivr.net/npm/appwrite@21.1.0"></script>
3737
```
3838

3939

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Client, Account } from "appwrite";
2+
3+
const client = new Client()
4+
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
5+
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
6+
7+
const account = new Account(client);
8+
9+
const result = await account.createEmailVerification({
10+
url: 'https://example.com'
11+
});
12+
13+
console.log(result);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Client, Account } from "appwrite";
2+
3+
const client = new Client()
4+
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
5+
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
6+
7+
const account = new Account(client);
8+
9+
const result = await account.updateEmailVerification({
10+
userId: '<USER_ID>',
11+
secret: '<SECRET>'
12+
});
13+
14+
console.log(result);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "appwrite",
33
"homepage": "https://appwrite.io/support",
44
"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",
5-
"version": "21.0.0",
5+
"version": "21.1.0",
66
"license": "BSD-3-Clause",
77
"main": "dist/cjs/sdk.js",
88
"exports": {

src/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ class Client {
316316
'x-sdk-name': 'Web',
317317
'x-sdk-platform': 'client',
318318
'x-sdk-language': 'web',
319-
'x-sdk-version': '21.0.0',
319+
'x-sdk-version': '21.1.0',
320320
'X-Appwrite-Response-Format': '1.8.0',
321321
};
322322

src/services/account.ts

Lines changed: 133 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2732,6 +2732,68 @@ export class Account {
27322732
* @throws {AppwriteException}
27332733
* @returns {Promise<Models.Token>}
27342734
*/
2735+
createEmailVerification(params: { url: string }): Promise<Models.Token>;
2736+
/**
2737+
* Use this endpoint to send a verification message to your user email address to confirm they are the valid owners of that address. Both the **userId** and **secret** arguments will be passed as query parameters to the URL you have provided to be attached to the verification email. The provided URL should redirect the user back to your app and allow you to complete the verification process by verifying both the **userId** and **secret** parameters. Learn more about how to [complete the verification process](https://appwrite.io/docs/references/cloud/client-web/account#updateVerification). The verification link sent to the user's email address is valid for 7 days.
2738+
*
2739+
* Please note that in order to avoid a [Redirect Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md), the only valid redirect URLs are the ones from domains you have set when adding your platforms in the console interface.
2740+
*
2741+
*
2742+
* @param {string} url - URL to redirect the user back to your app from the verification email. Only URLs from hostnames in your project platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API.
2743+
* @throws {AppwriteException}
2744+
* @returns {Promise<Models.Token>}
2745+
* @deprecated Use the object parameter style method for a better developer experience.
2746+
*/
2747+
createEmailVerification(url: string): Promise<Models.Token>;
2748+
createEmailVerification(
2749+
paramsOrFirst: { url: string } | string
2750+
): Promise<Models.Token> {
2751+
let params: { url: string };
2752+
2753+
if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) {
2754+
params = (paramsOrFirst || {}) as { url: string };
2755+
} else {
2756+
params = {
2757+
url: paramsOrFirst as string
2758+
};
2759+
}
2760+
2761+
const url = params.url;
2762+
2763+
if (typeof url === 'undefined') {
2764+
throw new AppwriteException('Missing required parameter: "url"');
2765+
}
2766+
2767+
const apiPath = '/account/verifications/email';
2768+
const payload: Payload = {};
2769+
if (typeof url !== 'undefined') {
2770+
payload['url'] = url;
2771+
}
2772+
const uri = new URL(this.client.config.endpoint + apiPath);
2773+
2774+
const apiHeaders: { [header: string]: string } = {
2775+
'content-type': 'application/json',
2776+
}
2777+
2778+
return this.client.call(
2779+
'post',
2780+
uri,
2781+
apiHeaders,
2782+
payload
2783+
);
2784+
}
2785+
2786+
/**
2787+
* Use this endpoint to send a verification message to your user email address to confirm they are the valid owners of that address. Both the **userId** and **secret** arguments will be passed as query parameters to the URL you have provided to be attached to the verification email. The provided URL should redirect the user back to your app and allow you to complete the verification process by verifying both the **userId** and **secret** parameters. Learn more about how to [complete the verification process](https://appwrite.io/docs/references/cloud/client-web/account#updateVerification). The verification link sent to the user's email address is valid for 7 days.
2788+
*
2789+
* Please note that in order to avoid a [Redirect Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md), the only valid redirect URLs are the ones from domains you have set when adding your platforms in the console interface.
2790+
*
2791+
*
2792+
* @param {string} params.url - URL to redirect the user back to your app from the verification email. Only URLs from hostnames in your project platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API.
2793+
* @throws {AppwriteException}
2794+
* @returns {Promise<Models.Token>}
2795+
* @deprecated This API has been deprecated since 1.8.0. Please use `Account.createEmailVerification` instead.
2796+
*/
27352797
createVerification(params: { url: string }): Promise<Models.Token>;
27362798
/**
27372799
* Use this endpoint to send a verification message to your user email address to confirm they are the valid owners of that address. Both the **userId** and **secret** arguments will be passed as query parameters to the URL you have provided to be attached to the verification email. The provided URL should redirect the user back to your app and allow you to complete the verification process by verifying both the **userId** and **secret** parameters. Learn more about how to [complete the verification process](https://appwrite.io/docs/references/cloud/client-web/account#updateVerification). The verification link sent to the user's email address is valid for 7 days.
@@ -2764,7 +2826,7 @@ export class Account {
27642826
throw new AppwriteException('Missing required parameter: "url"');
27652827
}
27662828

2767-
const apiPath = '/account/verification';
2829+
const apiPath = '/account/verifications/email';
27682830
const payload: Payload = {};
27692831
if (typeof url !== 'undefined') {
27702832
payload['url'] = url;
@@ -2791,6 +2853,73 @@ export class Account {
27912853
* @throws {AppwriteException}
27922854
* @returns {Promise<Models.Token>}
27932855
*/
2856+
updateEmailVerification(params: { userId: string, secret: string }): Promise<Models.Token>;
2857+
/**
2858+
* Use this endpoint to complete the user email verification process. Use both the **userId** and **secret** parameters that were attached to your app URL to verify the user email ownership. If confirmed this route will return a 200 status code.
2859+
*
2860+
* @param {string} userId - User ID.
2861+
* @param {string} secret - Valid verification token.
2862+
* @throws {AppwriteException}
2863+
* @returns {Promise<Models.Token>}
2864+
* @deprecated Use the object parameter style method for a better developer experience.
2865+
*/
2866+
updateEmailVerification(userId: string, secret: string): Promise<Models.Token>;
2867+
updateEmailVerification(
2868+
paramsOrFirst: { userId: string, secret: string } | string,
2869+
...rest: [(string)?]
2870+
): Promise<Models.Token> {
2871+
let params: { userId: string, secret: string };
2872+
2873+
if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) {
2874+
params = (paramsOrFirst || {}) as { userId: string, secret: string };
2875+
} else {
2876+
params = {
2877+
userId: paramsOrFirst as string,
2878+
secret: rest[0] as string
2879+
};
2880+
}
2881+
2882+
const userId = params.userId;
2883+
const secret = params.secret;
2884+
2885+
if (typeof userId === 'undefined') {
2886+
throw new AppwriteException('Missing required parameter: "userId"');
2887+
}
2888+
if (typeof secret === 'undefined') {
2889+
throw new AppwriteException('Missing required parameter: "secret"');
2890+
}
2891+
2892+
const apiPath = '/account/verifications/email';
2893+
const payload: Payload = {};
2894+
if (typeof userId !== 'undefined') {
2895+
payload['userId'] = userId;
2896+
}
2897+
if (typeof secret !== 'undefined') {
2898+
payload['secret'] = secret;
2899+
}
2900+
const uri = new URL(this.client.config.endpoint + apiPath);
2901+
2902+
const apiHeaders: { [header: string]: string } = {
2903+
'content-type': 'application/json',
2904+
}
2905+
2906+
return this.client.call(
2907+
'put',
2908+
uri,
2909+
apiHeaders,
2910+
payload
2911+
);
2912+
}
2913+
2914+
/**
2915+
* Use this endpoint to complete the user email verification process. Use both the **userId** and **secret** parameters that were attached to your app URL to verify the user email ownership. If confirmed this route will return a 200 status code.
2916+
*
2917+
* @param {string} params.userId - User ID.
2918+
* @param {string} params.secret - Valid verification token.
2919+
* @throws {AppwriteException}
2920+
* @returns {Promise<Models.Token>}
2921+
* @deprecated This API has been deprecated since 1.8.0. Please use `Account.updateEmailVerification` instead.
2922+
*/
27942923
updateVerification(params: { userId: string, secret: string }): Promise<Models.Token>;
27952924
/**
27962925
* Use this endpoint to complete the user email verification process. Use both the **userId** and **secret** parameters that were attached to your app URL to verify the user email ownership. If confirmed this route will return a 200 status code.
@@ -2827,7 +2956,7 @@ export class Account {
28272956
throw new AppwriteException('Missing required parameter: "secret"');
28282957
}
28292958

2830-
const apiPath = '/account/verification';
2959+
const apiPath = '/account/verifications/email';
28312960
const payload: Payload = {};
28322961
if (typeof userId !== 'undefined') {
28332962
payload['userId'] = userId;
@@ -2857,7 +2986,7 @@ export class Account {
28572986
*/
28582987
createPhoneVerification(): Promise<Models.Token> {
28592988

2860-
const apiPath = '/account/verification/phone';
2989+
const apiPath = '/account/verifications/phone';
28612990
const payload: Payload = {};
28622991
const uri = new URL(this.client.config.endpoint + apiPath);
28632992

@@ -2917,7 +3046,7 @@ export class Account {
29173046
throw new AppwriteException('Missing required parameter: "secret"');
29183047
}
29193048

2920-
const apiPath = '/account/verification/phone';
3049+
const apiPath = '/account/verifications/phone';
29213050
const payload: Payload = {};
29223051
if (typeof userId !== 'undefined') {
29233052
payload['userId'] = userId;

0 commit comments

Comments
 (0)