react-native-appwrite 0.2.2 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. package/.github/workflows/publish.yml +13 -4
  2. package/CHANGELOG.md +1 -1
  3. package/LICENSE +1 -1
  4. package/README.md +22 -9
  5. package/dist/cjs/sdk.js +1193 -269
  6. package/dist/cjs/sdk.js.map +1 -1
  7. package/dist/esm/sdk.js +1193 -270
  8. package/dist/esm/sdk.js.map +1 -1
  9. package/docs/examples/account/create-anonymous-session.md +6 -13
  10. package/docs/examples/account/create-email-password-session.md +14 -0
  11. package/docs/examples/account/create-email-token.md +15 -0
  12. package/docs/examples/account/create-j-w-t.md +6 -13
  13. package/docs/examples/account/create-magic-u-r-l-token.md +16 -0
  14. package/docs/examples/account/create-mfa-authenticator.md +13 -0
  15. package/docs/examples/account/create-mfa-challenge.md +13 -0
  16. package/docs/examples/account/create-mfa-recovery-codes.md +11 -0
  17. package/docs/examples/account/create-o-auth2session.md +10 -9
  18. package/docs/examples/account/create-o-auth2token.md +15 -0
  19. package/docs/examples/account/create-phone-token.md +14 -0
  20. package/docs/examples/account/create-phone-verification.md +6 -13
  21. package/docs/examples/account/create-push-target.md +15 -0
  22. package/docs/examples/account/create-recovery.md +9 -13
  23. package/docs/examples/account/create-session.md +14 -0
  24. package/docs/examples/account/create-verification.md +8 -13
  25. package/docs/examples/account/create.md +11 -13
  26. package/docs/examples/account/delete-identity.md +8 -13
  27. package/docs/examples/account/delete-mfa-authenticator.md +14 -0
  28. package/docs/examples/account/delete-push-target.md +13 -0
  29. package/docs/examples/account/delete-session.md +8 -13
  30. package/docs/examples/account/delete-sessions.md +6 -13
  31. package/docs/examples/account/get-mfa-recovery-codes.md +11 -0
  32. package/docs/examples/account/get-prefs.md +6 -13
  33. package/docs/examples/account/get-session.md +8 -13
  34. package/docs/examples/account/get.md +6 -13
  35. package/docs/examples/account/list-identities.md +8 -13
  36. package/docs/examples/account/list-logs.md +8 -13
  37. package/docs/examples/account/list-mfa-factors.md +11 -0
  38. package/docs/examples/account/list-sessions.md +6 -13
  39. package/docs/examples/account/update-email.md +9 -13
  40. package/docs/examples/account/update-m-f-a.md +13 -0
  41. package/docs/examples/account/update-magic-u-r-l-session.md +9 -13
  42. package/docs/examples/account/update-mfa-authenticator.md +14 -0
  43. package/docs/examples/account/update-mfa-challenge.md +14 -0
  44. package/docs/examples/account/update-mfa-recovery-codes.md +11 -0
  45. package/docs/examples/account/update-name.md +8 -13
  46. package/docs/examples/account/update-password.md +9 -13
  47. package/docs/examples/account/update-phone-session.md +9 -13
  48. package/docs/examples/account/update-phone-verification.md +9 -13
  49. package/docs/examples/account/update-phone.md +9 -13
  50. package/docs/examples/account/update-prefs.md +8 -13
  51. package/docs/examples/account/update-push-target.md +14 -0
  52. package/docs/examples/account/update-recovery.md +10 -13
  53. package/docs/examples/account/update-session.md +8 -13
  54. package/docs/examples/account/update-status.md +6 -13
  55. package/docs/examples/account/update-verification.md +9 -13
  56. package/docs/examples/avatars/get-browser.md +11 -9
  57. package/docs/examples/avatars/get-credit-card.md +11 -9
  58. package/docs/examples/avatars/get-favicon.md +8 -9
  59. package/docs/examples/avatars/get-flag.md +11 -9
  60. package/docs/examples/avatars/get-image.md +10 -9
  61. package/docs/examples/avatars/get-initials.md +11 -9
  62. package/docs/examples/avatars/get-q-r.md +11 -9
  63. package/docs/examples/databases/create-document.md +12 -13
  64. package/docs/examples/databases/delete-document.md +10 -13
  65. package/docs/examples/databases/get-document.md +11 -13
  66. package/docs/examples/databases/list-documents.md +10 -13
  67. package/docs/examples/databases/update-document.md +12 -13
  68. package/docs/examples/functions/create-execution.md +13 -13
  69. package/docs/examples/functions/get-execution.md +9 -13
  70. package/docs/examples/functions/list-executions.md +10 -13
  71. package/docs/examples/graphql/mutation.md +8 -13
  72. package/docs/examples/graphql/query.md +8 -13
  73. package/docs/examples/locale/get.md +6 -13
  74. package/docs/examples/locale/list-codes.md +6 -13
  75. package/docs/examples/locale/list-continents.md +6 -13
  76. package/docs/examples/locale/list-countries-e-u.md +6 -13
  77. package/docs/examples/locale/list-countries-phones.md +6 -13
  78. package/docs/examples/locale/list-countries.md +6 -13
  79. package/docs/examples/locale/list-currencies.md +6 -13
  80. package/docs/examples/locale/list-languages.md +6 -13
  81. package/docs/examples/messaging/create-subscriber.md +15 -0
  82. package/docs/examples/messaging/delete-subscriber.md +14 -0
  83. package/docs/examples/storage/create-file.md +11 -13
  84. package/docs/examples/storage/delete-file.md +9 -13
  85. package/docs/examples/storage/get-file-download.md +9 -9
  86. package/docs/examples/storage/get-file-preview.md +20 -9
  87. package/docs/examples/storage/get-file-view.md +9 -9
  88. package/docs/examples/storage/get-file.md +9 -13
  89. package/docs/examples/storage/list-files.md +10 -13
  90. package/docs/examples/storage/update-file.md +11 -13
  91. package/docs/examples/teams/create-membership.md +14 -13
  92. package/docs/examples/teams/create.md +10 -13
  93. package/docs/examples/teams/delete-membership.md +9 -13
  94. package/docs/examples/teams/delete.md +8 -13
  95. package/docs/examples/teams/get-membership.md +9 -13
  96. package/docs/examples/teams/get-prefs.md +8 -13
  97. package/docs/examples/teams/get.md +8 -13
  98. package/docs/examples/teams/list-memberships.md +10 -13
  99. package/docs/examples/teams/list.md +9 -13
  100. package/docs/examples/teams/update-membership-status.md +11 -13
  101. package/docs/examples/teams/update-membership.md +10 -13
  102. package/docs/examples/teams/update-name.md +9 -13
  103. package/docs/examples/teams/update-prefs.md +9 -13
  104. package/package.json +1 -1
  105. package/src/client.ts +37 -11
  106. package/src/enums/authentication-factor.ts +6 -0
  107. package/src/enums/authenticator-type.ts +3 -0
  108. package/src/enums/browser.ts +16 -0
  109. package/src/enums/credit-card.ts +18 -0
  110. package/src/enums/execution-method.ts +8 -0
  111. package/src/enums/flag.ts +197 -0
  112. package/src/enums/image-format.ts +7 -0
  113. package/src/enums/image-gravity.ts +11 -0
  114. package/src/enums/o-auth-provider.ts +41 -0
  115. package/src/id.ts +23 -4
  116. package/src/index.ts +13 -2
  117. package/src/models.ts +174 -0
  118. package/src/query.ts +61 -34
  119. package/src/service.ts +4 -7
  120. package/src/services/account.ts +643 -119
  121. package/src/services/avatars.ts +12 -6
  122. package/src/services/databases.ts +7 -4
  123. package/src/services/functions.ts +6 -2
  124. package/src/services/graphql.ts +3 -0
  125. package/src/services/locale.ts +3 -0
  126. package/src/services/messaging.ts +84 -0
  127. package/src/services/storage.ts +12 -6
  128. package/src/services/teams.ts +3 -0
  129. package/types/client.d.ts +133 -0
  130. package/types/enums/authentication-factor.d.ts +6 -0
  131. package/types/enums/authenticator-type.d.ts +3 -0
  132. package/types/enums/browser.d.ts +16 -0
  133. package/types/enums/credit-card.d.ts +18 -0
  134. package/types/enums/execution-method.d.ts +8 -0
  135. package/types/enums/flag.d.ts +197 -0
  136. package/types/enums/image-format.d.ts +7 -0
  137. package/types/enums/image-gravity.d.ts +11 -0
  138. package/types/enums/o-auth-provider.d.ts +41 -0
  139. package/types/id.d.ts +5 -0
  140. package/types/index.d.ts +25 -0
  141. package/types/models.d.ts +1195 -0
  142. package/types/permission.d.ts +7 -0
  143. package/types/query.d.ts +34 -0
  144. package/types/role.d.ts +70 -0
  145. package/types/service.d.ts +8 -0
  146. package/types/services/account.d.ts +676 -0
  147. package/types/services/avatars.d.ts +149 -0
  148. package/types/services/databases.d.ts +77 -0
  149. package/types/services/functions.d.ts +49 -0
  150. package/types/services/graphql.d.ts +25 -0
  151. package/types/services/locale.d.ts +91 -0
  152. package/types/services/messaging.d.ts +29 -0
  153. package/types/services/storage.d.ts +147 -0
  154. package/types/services/teams.d.ts +197 -0
  155. package/docs/examples/account/create-email-session.md +0 -18
  156. package/docs/examples/account/create-magic-u-r-l-session.md +0 -18
  157. package/docs/examples/account/create-phone-session.md +0 -18
@@ -2,6 +2,12 @@ import { Service } from '../service';
2
2
  import { AppwriteException, Client } from '../client';
3
3
  import type { Models } from '../models';
4
4
  import type { UploadProgress, Payload } from '../client';
5
+ import * as FileSystem from 'expo-file-system';
6
+ import { Platform } from 'react-native';
7
+
8
+ import { AuthenticatorType } from '../enums/authenticator-type';
9
+ import { AuthenticationFactor } from '../enums/authentication-factor';
10
+ import { OAuthProvider } from '../enums/o-auth-provider';
5
11
 
6
12
  export class Account extends Service {
7
13
 
@@ -132,11 +138,11 @@ export class Account extends Service {
132
138
  *
133
139
  * Get the list of identities for the currently logged in user.
134
140
  *
135
- * @param {string} queries
141
+ * @param {string[]} queries
136
142
  * @throws {AppwriteException}
137
143
  * @returns {Promise}
138
144
  */
139
- async listIdentities(queries?: string): Promise<Models.IdentityList> {
145
+ async listIdentities(queries?: string[]): Promise<Models.IdentityList> {
140
146
  const apiPath = '/account/identities';
141
147
  const payload: Payload = {};
142
148
 
@@ -151,7 +157,7 @@ export class Account extends Service {
151
157
  }
152
158
 
153
159
  /**
154
- * Delete Identity
160
+ * Delete identity
155
161
  *
156
162
  * Delete an identity by its unique ID.
157
163
  *
@@ -219,6 +225,276 @@ export class Account extends Service {
219
225
  }, payload);
220
226
  }
221
227
 
228
+ /**
229
+ * Update MFA
230
+ *
231
+ * Enable or disable MFA on an account.
232
+ *
233
+ * @param {boolean} mfa
234
+ * @throws {AppwriteException}
235
+ * @returns {Promise}
236
+ */
237
+ async updateMFA<Preferences extends Models.Preferences>(mfa: boolean): Promise<Models.User<Preferences>> {
238
+ if (typeof mfa === 'undefined') {
239
+ throw new AppwriteException('Missing required parameter: "mfa"');
240
+ }
241
+
242
+ const apiPath = '/account/mfa';
243
+ const payload: Payload = {};
244
+
245
+ if (typeof mfa !== 'undefined') {
246
+ payload['mfa'] = mfa;
247
+ }
248
+
249
+ const uri = new URL(this.client.config.endpoint + apiPath);
250
+ return await this.client.call('patch', uri, {
251
+ 'content-type': 'application/json',
252
+ }, payload);
253
+ }
254
+
255
+ /**
256
+ * Add Authenticator
257
+ *
258
+ * Add an authenticator app to be used as an MFA factor. Verify the
259
+ * authenticator using the [verify
260
+ * authenticator](/docs/references/cloud/client-web/account#updateMfaAuthenticator)
261
+ * method.
262
+ *
263
+ * @param {AuthenticatorType} type
264
+ * @throws {AppwriteException}
265
+ * @returns {Promise}
266
+ */
267
+ async createMfaAuthenticator(type: AuthenticatorType): Promise<Models.MfaType> {
268
+ if (typeof type === 'undefined') {
269
+ throw new AppwriteException('Missing required parameter: "type"');
270
+ }
271
+
272
+ const apiPath = '/account/mfa/authenticators/{type}'.replace('{type}', type);
273
+ const payload: Payload = {};
274
+
275
+ const uri = new URL(this.client.config.endpoint + apiPath);
276
+ return await this.client.call('post', uri, {
277
+ 'content-type': 'application/json',
278
+ }, payload);
279
+ }
280
+
281
+ /**
282
+ * Verify Authenticator
283
+ *
284
+ * Verify an authenticator app after adding it using the [add
285
+ * authenticator](/docs/references/cloud/client-web/account#createMfaAuthenticator)
286
+ * method. add
287
+ *
288
+ * @param {AuthenticatorType} type
289
+ * @param {string} otp
290
+ * @throws {AppwriteException}
291
+ * @returns {Promise}
292
+ */
293
+ async updateMfaAuthenticator<Preferences extends Models.Preferences>(type: AuthenticatorType, otp: string): Promise<Models.User<Preferences>> {
294
+ if (typeof type === 'undefined') {
295
+ throw new AppwriteException('Missing required parameter: "type"');
296
+ }
297
+
298
+ if (typeof otp === 'undefined') {
299
+ throw new AppwriteException('Missing required parameter: "otp"');
300
+ }
301
+
302
+ const apiPath = '/account/mfa/authenticators/{type}'.replace('{type}', type);
303
+ const payload: Payload = {};
304
+
305
+ if (typeof otp !== 'undefined') {
306
+ payload['otp'] = otp;
307
+ }
308
+
309
+ const uri = new URL(this.client.config.endpoint + apiPath);
310
+ return await this.client.call('put', uri, {
311
+ 'content-type': 'application/json',
312
+ }, payload);
313
+ }
314
+
315
+ /**
316
+ * Delete Authenticator
317
+ *
318
+ * Delete an authenticator for a user by ID.
319
+ *
320
+ * @param {AuthenticatorType} type
321
+ * @param {string} otp
322
+ * @throws {AppwriteException}
323
+ * @returns {Promise}
324
+ */
325
+ async deleteMfaAuthenticator(type: AuthenticatorType, otp: string): Promise<{}> {
326
+ if (typeof type === 'undefined') {
327
+ throw new AppwriteException('Missing required parameter: "type"');
328
+ }
329
+
330
+ if (typeof otp === 'undefined') {
331
+ throw new AppwriteException('Missing required parameter: "otp"');
332
+ }
333
+
334
+ const apiPath = '/account/mfa/authenticators/{type}'.replace('{type}', type);
335
+ const payload: Payload = {};
336
+
337
+ if (typeof otp !== 'undefined') {
338
+ payload['otp'] = otp;
339
+ }
340
+
341
+ const uri = new URL(this.client.config.endpoint + apiPath);
342
+ return await this.client.call('delete', uri, {
343
+ 'content-type': 'application/json',
344
+ }, payload);
345
+ }
346
+
347
+ /**
348
+ * Create 2FA Challenge
349
+ *
350
+ * Begin the process of MFA verification after sign-in. Finish the flow with
351
+ * [updateMfaChallenge](/docs/references/cloud/client-web/account#updateMfaChallenge)
352
+ * method.
353
+ *
354
+ * @param {AuthenticationFactor} factor
355
+ * @throws {AppwriteException}
356
+ * @returns {Promise}
357
+ */
358
+ async createMfaChallenge(factor: AuthenticationFactor): Promise<Models.MfaChallenge> {
359
+ if (typeof factor === 'undefined') {
360
+ throw new AppwriteException('Missing required parameter: "factor"');
361
+ }
362
+
363
+ const apiPath = '/account/mfa/challenge';
364
+ const payload: Payload = {};
365
+
366
+ if (typeof factor !== 'undefined') {
367
+ payload['factor'] = factor;
368
+ }
369
+
370
+ const uri = new URL(this.client.config.endpoint + apiPath);
371
+ return await this.client.call('post', uri, {
372
+ 'content-type': 'application/json',
373
+ }, payload);
374
+ }
375
+
376
+ /**
377
+ * Create MFA Challenge (confirmation)
378
+ *
379
+ * Complete the MFA challenge by providing the one-time password. Finish the
380
+ * process of MFA verification by providing the one-time password. To begin
381
+ * the flow, use
382
+ * [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge)
383
+ * method.
384
+ *
385
+ * @param {string} challengeId
386
+ * @param {string} otp
387
+ * @throws {AppwriteException}
388
+ * @returns {Promise}
389
+ */
390
+ async updateMfaChallenge(challengeId: string, otp: string): Promise<{}> {
391
+ if (typeof challengeId === 'undefined') {
392
+ throw new AppwriteException('Missing required parameter: "challengeId"');
393
+ }
394
+
395
+ if (typeof otp === 'undefined') {
396
+ throw new AppwriteException('Missing required parameter: "otp"');
397
+ }
398
+
399
+ const apiPath = '/account/mfa/challenge';
400
+ const payload: Payload = {};
401
+
402
+ if (typeof challengeId !== 'undefined') {
403
+ payload['challengeId'] = challengeId;
404
+ }
405
+
406
+ if (typeof otp !== 'undefined') {
407
+ payload['otp'] = otp;
408
+ }
409
+
410
+ const uri = new URL(this.client.config.endpoint + apiPath);
411
+ return await this.client.call('put', uri, {
412
+ 'content-type': 'application/json',
413
+ }, payload);
414
+ }
415
+
416
+ /**
417
+ * List Factors
418
+ *
419
+ * List the factors available on the account to be used as a MFA challange.
420
+ *
421
+ * @throws {AppwriteException}
422
+ * @returns {Promise}
423
+ */
424
+ async listMfaFactors(): Promise<Models.MfaFactors> {
425
+ const apiPath = '/account/mfa/factors';
426
+ const payload: Payload = {};
427
+
428
+ const uri = new URL(this.client.config.endpoint + apiPath);
429
+ return await this.client.call('get', uri, {
430
+ 'content-type': 'application/json',
431
+ }, payload);
432
+ }
433
+
434
+ /**
435
+ * Get MFA Recovery Codes
436
+ *
437
+ * Get recovery codes that can be used as backup for MFA flow. Before getting
438
+ * codes, they must be generated using
439
+ * [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes)
440
+ * method. An OTP challenge is required to read recovery codes.
441
+ *
442
+ * @throws {AppwriteException}
443
+ * @returns {Promise}
444
+ */
445
+ async getMfaRecoveryCodes(): Promise<Models.MfaRecoveryCodes> {
446
+ const apiPath = '/account/mfa/recovery-codes';
447
+ const payload: Payload = {};
448
+
449
+ const uri = new URL(this.client.config.endpoint + apiPath);
450
+ return await this.client.call('get', uri, {
451
+ 'content-type': 'application/json',
452
+ }, payload);
453
+ }
454
+
455
+ /**
456
+ * Create MFA Recovery Codes
457
+ *
458
+ * Generate recovery codes as backup for MFA flow. It's recommended to
459
+ * generate and show then immediately after user successfully adds their
460
+ * authehticator. Recovery codes can be used as a MFA verification type in
461
+ * [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge)
462
+ * method.
463
+ *
464
+ * @throws {AppwriteException}
465
+ * @returns {Promise}
466
+ */
467
+ async createMfaRecoveryCodes(): Promise<Models.MfaRecoveryCodes> {
468
+ const apiPath = '/account/mfa/recovery-codes';
469
+ const payload: Payload = {};
470
+
471
+ const uri = new URL(this.client.config.endpoint + apiPath);
472
+ return await this.client.call('post', uri, {
473
+ 'content-type': 'application/json',
474
+ }, payload);
475
+ }
476
+
477
+ /**
478
+ * Regenerate MFA Recovery Codes
479
+ *
480
+ * Regenerate recovery codes that can be used as backup for MFA flow. Before
481
+ * regenerating codes, they must be first generated using
482
+ * [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes)
483
+ * method. An OTP challenge is required to regenreate recovery codes.
484
+ *
485
+ * @throws {AppwriteException}
486
+ * @returns {Promise}
487
+ */
488
+ async updateMfaRecoveryCodes(): Promise<Models.MfaRecoveryCodes> {
489
+ const apiPath = '/account/mfa/recovery-codes';
490
+ const payload: Payload = {};
491
+
492
+ const uri = new URL(this.client.config.endpoint + apiPath);
493
+ return await this.client.call('patch', uri, {
494
+ 'content-type': 'application/json',
495
+ }, payload);
496
+ }
497
+
222
498
  /**
223
499
  * Update name
224
500
  *
@@ -345,11 +621,11 @@ export class Account extends Service {
345
621
  * stored as is, and replaces any previous value. The maximum allowed prefs
346
622
  * size is 64kB and throws error if exceeded.
347
623
  *
348
- * @param {Partial<Preferences>} prefs
624
+ * @param {object} prefs
349
625
  * @throws {AppwriteException}
350
626
  * @returns {Promise}
351
627
  */
352
- async updatePrefs<Preferences extends Models.Preferences>(prefs: Partial<Preferences>): Promise<Models.User<Preferences>> {
628
+ async updatePrefs<Preferences extends Models.Preferences>(prefs: object): Promise<Models.User<Preferences>> {
353
629
  if (typeof prefs === 'undefined') {
354
630
  throw new AppwriteException('Missing required parameter: "prefs"');
355
631
  }
@@ -427,11 +703,10 @@ export class Account extends Service {
427
703
  * @param {string} userId
428
704
  * @param {string} secret
429
705
  * @param {string} password
430
- * @param {string} passwordAgain
431
706
  * @throws {AppwriteException}
432
707
  * @returns {Promise}
433
708
  */
434
- async updateRecovery(userId: string, secret: string, password: string, passwordAgain: string): Promise<Models.Token> {
709
+ async updateRecovery(userId: string, secret: string, password: string): Promise<Models.Token> {
435
710
  if (typeof userId === 'undefined') {
436
711
  throw new AppwriteException('Missing required parameter: "userId"');
437
712
  }
@@ -444,10 +719,6 @@ export class Account extends Service {
444
719
  throw new AppwriteException('Missing required parameter: "password"');
445
720
  }
446
721
 
447
- if (typeof passwordAgain === 'undefined') {
448
- throw new AppwriteException('Missing required parameter: "passwordAgain"');
449
- }
450
-
451
722
  const apiPath = '/account/recovery';
452
723
  const payload: Payload = {};
453
724
 
@@ -463,10 +734,6 @@ export class Account extends Service {
463
734
  payload['password'] = password;
464
735
  }
465
736
 
466
- if (typeof passwordAgain !== 'undefined') {
467
- payload['passwordAgain'] = passwordAgain;
468
- }
469
-
470
737
  const uri = new URL(this.client.config.endpoint + apiPath);
471
738
  return await this.client.call('put', uri, {
472
739
  'content-type': 'application/json',
@@ -536,7 +803,7 @@ export class Account extends Service {
536
803
  }
537
804
 
538
805
  /**
539
- * Create email session
806
+ * Create email password session
540
807
  *
541
808
  * Allow the user to login into their account by providing a valid email and
542
809
  * password combination. This route will create a new session for the user.
@@ -550,7 +817,7 @@ export class Account extends Service {
550
817
  * @throws {AppwriteException}
551
818
  * @returns {Promise}
552
819
  */
553
- async createEmailSession(email: string, password: string): Promise<Models.Session> {
820
+ async createEmailPasswordSession(email: string, password: string): Promise<Models.Session> {
554
821
  if (typeof email === 'undefined') {
555
822
  throw new AppwriteException('Missing required parameter: "email"');
556
823
  }
@@ -577,75 +844,11 @@ export class Account extends Service {
577
844
  }
578
845
 
579
846
  /**
580
- * Create magic URL session
581
- *
582
- * Sends the user an email with a secret key for creating a session. If the
583
- * provided user ID has not been registered, a new user will be created. When
584
- * the user clicks the link in the email, the user is redirected back to the
585
- * URL you provided with the secret key and userId values attached to the URL
586
- * query string. Use the query string parameters to submit a request to the
587
- * [PUT
588
- * /account/sessions/magic-url](https://appwrite.io/docs/references/cloud/client-web/account#updateMagicURLSession)
589
- * endpoint to complete the login process. The link sent to the user's email
590
- * address is valid for 1 hour. If you are on a mobile device you can leave
591
- * the URL parameter empty, so that the login completion will be handled by
592
- * your Appwrite instance by default.
593
- *
594
- * A user is limited to 10 active sessions at a time by default. [Learn more
595
- * about session
596
- * limits](https://appwrite.io/docs/authentication-security#limits).
597
- *
598
- *
599
- * @param {string} userId
600
- * @param {string} email
601
- * @param {string} url
602
- * @throws {AppwriteException}
603
- * @returns {Promise}
604
- */
605
- async createMagicURLSession(userId: string, email: string, url?: string): Promise<Models.Token> {
606
- if (typeof userId === 'undefined') {
607
- throw new AppwriteException('Missing required parameter: "userId"');
608
- }
609
-
610
- if (typeof email === 'undefined') {
611
- throw new AppwriteException('Missing required parameter: "email"');
612
- }
613
-
614
- const apiPath = '/account/sessions/magic-url';
615
- const payload: Payload = {};
616
-
617
- if (typeof userId !== 'undefined') {
618
- payload['userId'] = userId;
619
- }
620
-
621
- if (typeof email !== 'undefined') {
622
- payload['email'] = email;
623
- }
624
-
625
- if (typeof url !== 'undefined') {
626
- payload['url'] = url;
627
- }
628
-
629
- const uri = new URL(this.client.config.endpoint + apiPath);
630
- return await this.client.call('post', uri, {
631
- 'content-type': 'application/json',
632
- }, payload);
633
- }
634
-
635
- /**
636
- * Create magic URL session (confirmation)
847
+ * Update magic URL session
637
848
  *
638
- * Use this endpoint to complete creating the session with the Magic URL. Both
639
- * the **userId** and **secret** arguments will be passed as query parameters
640
- * to the redirect URL you have provided when sending your request to the
641
- * [POST
642
- * /account/sessions/magic-url](https://appwrite.io/docs/references/cloud/client-web/account#createMagicURLSession)
643
- * endpoint.
644
- *
645
- * Please note that in order to avoid a [Redirect
646
- * Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md)
647
- * the only valid redirect URLs are the ones from domains you have set when
648
- * adding your platforms in the console interface.
849
+ * Use this endpoint to create a session from token. Provide the **userId**
850
+ * and **secret** parameters from the successful response of authentication
851
+ * flows initiated by token creation. For example, magic URL and phone login.
649
852
  *
650
853
  * @param {string} userId
651
854
  * @param {string} secret
@@ -698,43 +901,62 @@ export class Account extends Service {
698
901
  * limits](https://appwrite.io/docs/authentication-security#limits).
699
902
  *
700
903
  *
701
- * @param {string} provider
904
+ * @param {OAuthProvider} provider
702
905
  * @param {string} success
703
906
  * @param {string} failure
704
907
  * @param {string[]} scopes
705
908
  * @throws {AppwriteException}
706
909
  * @returns {void|string}
707
910
  */
708
- createOAuth2Session(provider: string, success?: string, failure?: string, scopes?: string[]): void | URL {
709
- throw new AppwriteException('Not yet supported');
911
+ createOAuth2Session(provider: OAuthProvider, success?: string, failure?: string, scopes?: string[]): void | URL {
912
+ if (typeof provider === 'undefined') {
913
+ throw new AppwriteException('Missing required parameter: "provider"');
914
+ }
915
+
916
+ const apiPath = '/account/sessions/oauth2/{provider}'.replace('{provider}', provider);
917
+ const payload: Payload = {};
918
+
919
+ if (typeof success !== 'undefined') {
920
+ payload['success'] = success;
921
+ }
922
+
923
+ if (typeof failure !== 'undefined') {
924
+ payload['failure'] = failure;
925
+ }
926
+
927
+ if (typeof scopes !== 'undefined') {
928
+ payload['scopes'] = scopes;
929
+ }
930
+
931
+ const uri = new URL(this.client.config.endpoint + apiPath);
932
+ payload['project'] = this.client.config.project;
933
+
934
+
935
+ for (const [key, value] of Object.entries(Service.flatten(payload))) {
936
+ uri.searchParams.append(key, value);
937
+ }
938
+ return uri;
710
939
  }
711
940
 
712
941
  /**
713
- * Create phone session
942
+ * Update phone session
714
943
  *
715
- * Sends the user an SMS with a secret key for creating a session. If the
716
- * provided user ID has not be registered, a new user will be created. Use the
717
- * returned user ID and secret and submit a request to the [PUT
718
- * /account/sessions/phone](https://appwrite.io/docs/references/cloud/client-web/account#updatePhoneSession)
719
- * endpoint to complete the login process. The secret sent to the user's phone
720
- * is valid for 15 minutes.
721
- *
722
- * A user is limited to 10 active sessions at a time by default. [Learn more
723
- * about session
724
- * limits](https://appwrite.io/docs/authentication-security#limits).
944
+ * Use this endpoint to create a session from token. Provide the **userId**
945
+ * and **secret** parameters from the successful response of authentication
946
+ * flows initiated by token creation. For example, magic URL and phone login.
725
947
  *
726
948
  * @param {string} userId
727
- * @param {string} phone
949
+ * @param {string} secret
728
950
  * @throws {AppwriteException}
729
951
  * @returns {Promise}
730
952
  */
731
- async createPhoneSession(userId: string, phone: string): Promise<Models.Token> {
953
+ async updatePhoneSession(userId: string, secret: string): Promise<Models.Session> {
732
954
  if (typeof userId === 'undefined') {
733
955
  throw new AppwriteException('Missing required parameter: "userId"');
734
956
  }
735
957
 
736
- if (typeof phone === 'undefined') {
737
- throw new AppwriteException('Missing required parameter: "phone"');
958
+ if (typeof secret === 'undefined') {
959
+ throw new AppwriteException('Missing required parameter: "secret"');
738
960
  }
739
961
 
740
962
  const apiPath = '/account/sessions/phone';
@@ -744,31 +966,29 @@ export class Account extends Service {
744
966
  payload['userId'] = userId;
745
967
  }
746
968
 
747
- if (typeof phone !== 'undefined') {
748
- payload['phone'] = phone;
969
+ if (typeof secret !== 'undefined') {
970
+ payload['secret'] = secret;
749
971
  }
750
972
 
751
973
  const uri = new URL(this.client.config.endpoint + apiPath);
752
- return await this.client.call('post', uri, {
974
+ return await this.client.call('put', uri, {
753
975
  'content-type': 'application/json',
754
976
  }, payload);
755
977
  }
756
978
 
757
979
  /**
758
- * Create phone session (confirmation)
980
+ * Create session
759
981
  *
760
- * Use this endpoint to complete creating a session with SMS. Use the
761
- * **userId** from the
762
- * [createPhoneSession](https://appwrite.io/docs/references/cloud/client-web/account#createPhoneSession)
763
- * endpoint and the **secret** received via SMS to successfully update and
764
- * confirm the phone session.
982
+ * Use this endpoint to create a session from token. Provide the **userId**
983
+ * and **secret** parameters from the successful response of authentication
984
+ * flows initiated by token creation. For example, magic URL and phone login.
765
985
  *
766
986
  * @param {string} userId
767
987
  * @param {string} secret
768
988
  * @throws {AppwriteException}
769
989
  * @returns {Promise}
770
990
  */
771
- async updatePhoneSession(userId: string, secret: string): Promise<Models.Session> {
991
+ async createSession(userId: string, secret: string): Promise<Models.Session> {
772
992
  if (typeof userId === 'undefined') {
773
993
  throw new AppwriteException('Missing required parameter: "userId"');
774
994
  }
@@ -777,7 +997,7 @@ export class Account extends Service {
777
997
  throw new AppwriteException('Missing required parameter: "secret"');
778
998
  }
779
999
 
780
- const apiPath = '/account/sessions/phone';
1000
+ const apiPath = '/account/sessions/token';
781
1001
  const payload: Payload = {};
782
1002
 
783
1003
  if (typeof userId !== 'undefined') {
@@ -789,7 +1009,7 @@ export class Account extends Service {
789
1009
  }
790
1010
 
791
1011
  const uri = new URL(this.client.config.endpoint + apiPath);
792
- return await this.client.call('put', uri, {
1012
+ return await this.client.call('post', uri, {
793
1013
  'content-type': 'application/json',
794
1014
  }, payload);
795
1015
  }
@@ -819,11 +1039,11 @@ export class Account extends Service {
819
1039
  }
820
1040
 
821
1041
  /**
822
- * Update OAuth session (refresh tokens)
1042
+ * Update session
823
1043
  *
824
- * Access tokens have limited lifespan and expire to mitigate security risks.
825
- * If session was created using an OAuth provider, this route can be used to
826
- * "refresh" the access token.
1044
+ * Use this endpoint to extend a session's length. Extending a session is
1045
+ * useful when session expiry is short. If the session was created using an
1046
+ * OAuth provider, this endpoint refreshes the access token from the provider.
827
1047
  *
828
1048
  * @param {string} sessionId
829
1049
  * @throws {AppwriteException}
@@ -890,6 +1110,310 @@ export class Account extends Service {
890
1110
  }, payload);
891
1111
  }
892
1112
 
1113
+ /**
1114
+ * Create push target
1115
+ *
1116
+ *
1117
+ * @param {string} targetId
1118
+ * @param {string} identifier
1119
+ * @param {string} providerId
1120
+ * @throws {AppwriteException}
1121
+ * @returns {Promise}
1122
+ */
1123
+ async createPushTarget(targetId: string, identifier: string, providerId?: string): Promise<Models.Target> {
1124
+ if (typeof targetId === 'undefined') {
1125
+ throw new AppwriteException('Missing required parameter: "targetId"');
1126
+ }
1127
+
1128
+ if (typeof identifier === 'undefined') {
1129
+ throw new AppwriteException('Missing required parameter: "identifier"');
1130
+ }
1131
+
1132
+ const apiPath = '/account/targets/push';
1133
+ const payload: Payload = {};
1134
+
1135
+ if (typeof targetId !== 'undefined') {
1136
+ payload['targetId'] = targetId;
1137
+ }
1138
+
1139
+ if (typeof identifier !== 'undefined') {
1140
+ payload['identifier'] = identifier;
1141
+ }
1142
+
1143
+ if (typeof providerId !== 'undefined') {
1144
+ payload['providerId'] = providerId;
1145
+ }
1146
+
1147
+ const uri = new URL(this.client.config.endpoint + apiPath);
1148
+ return await this.client.call('post', uri, {
1149
+ 'content-type': 'application/json',
1150
+ }, payload);
1151
+ }
1152
+
1153
+ /**
1154
+ * Update push target
1155
+ *
1156
+ *
1157
+ * @param {string} targetId
1158
+ * @param {string} identifier
1159
+ * @throws {AppwriteException}
1160
+ * @returns {Promise}
1161
+ */
1162
+ async updatePushTarget(targetId: string, identifier: string): Promise<Models.Target> {
1163
+ if (typeof targetId === 'undefined') {
1164
+ throw new AppwriteException('Missing required parameter: "targetId"');
1165
+ }
1166
+
1167
+ if (typeof identifier === 'undefined') {
1168
+ throw new AppwriteException('Missing required parameter: "identifier"');
1169
+ }
1170
+
1171
+ const apiPath = '/account/targets/{targetId}/push'.replace('{targetId}', targetId);
1172
+ const payload: Payload = {};
1173
+
1174
+ if (typeof identifier !== 'undefined') {
1175
+ payload['identifier'] = identifier;
1176
+ }
1177
+
1178
+ const uri = new URL(this.client.config.endpoint + apiPath);
1179
+ return await this.client.call('put', uri, {
1180
+ 'content-type': 'application/json',
1181
+ }, payload);
1182
+ }
1183
+
1184
+ /**
1185
+ * Delete push target
1186
+ *
1187
+ *
1188
+ * @param {string} targetId
1189
+ * @throws {AppwriteException}
1190
+ * @returns {Promise}
1191
+ */
1192
+ async deletePushTarget(targetId: string): Promise<{}> {
1193
+ if (typeof targetId === 'undefined') {
1194
+ throw new AppwriteException('Missing required parameter: "targetId"');
1195
+ }
1196
+
1197
+ const apiPath = '/account/targets/{targetId}/push'.replace('{targetId}', targetId);
1198
+ const payload: Payload = {};
1199
+
1200
+ const uri = new URL(this.client.config.endpoint + apiPath);
1201
+ return await this.client.call('delete', uri, {
1202
+ 'content-type': 'application/json',
1203
+ }, payload);
1204
+ }
1205
+
1206
+ /**
1207
+ * Create email token (OTP)
1208
+ *
1209
+ * Sends the user an email with a secret key for creating a session. If the
1210
+ * provided user ID has not be registered, a new user will be created. Use the
1211
+ * returned user ID and secret and submit a request to the [POST
1212
+ * /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession)
1213
+ * endpoint to complete the login process. The secret sent to the user's email
1214
+ * is valid for 15 minutes.
1215
+ *
1216
+ * A user is limited to 10 active sessions at a time by default. [Learn more
1217
+ * about session
1218
+ * limits](https://appwrite.io/docs/authentication-security#limits).
1219
+ *
1220
+ * @param {string} userId
1221
+ * @param {string} email
1222
+ * @param {boolean} phrase
1223
+ * @throws {AppwriteException}
1224
+ * @returns {Promise}
1225
+ */
1226
+ async createEmailToken(userId: string, email: string, phrase?: boolean): Promise<Models.Token> {
1227
+ if (typeof userId === 'undefined') {
1228
+ throw new AppwriteException('Missing required parameter: "userId"');
1229
+ }
1230
+
1231
+ if (typeof email === 'undefined') {
1232
+ throw new AppwriteException('Missing required parameter: "email"');
1233
+ }
1234
+
1235
+ const apiPath = '/account/tokens/email';
1236
+ const payload: Payload = {};
1237
+
1238
+ if (typeof userId !== 'undefined') {
1239
+ payload['userId'] = userId;
1240
+ }
1241
+
1242
+ if (typeof email !== 'undefined') {
1243
+ payload['email'] = email;
1244
+ }
1245
+
1246
+ if (typeof phrase !== 'undefined') {
1247
+ payload['phrase'] = phrase;
1248
+ }
1249
+
1250
+ const uri = new URL(this.client.config.endpoint + apiPath);
1251
+ return await this.client.call('post', uri, {
1252
+ 'content-type': 'application/json',
1253
+ }, payload);
1254
+ }
1255
+
1256
+ /**
1257
+ * Create magic URL token
1258
+ *
1259
+ * Sends the user an email with a secret key for creating a session. If the
1260
+ * provided user ID has not been registered, a new user will be created. When
1261
+ * the user clicks the link in the email, the user is redirected back to the
1262
+ * URL you provided with the secret key and userId values attached to the URL
1263
+ * query string. Use the query string parameters to submit a request to the
1264
+ * [POST
1265
+ * /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession)
1266
+ * endpoint to complete the login process. The link sent to the user's email
1267
+ * address is valid for 1 hour. If you are on a mobile device you can leave
1268
+ * the URL parameter empty, so that the login completion will be handled by
1269
+ * your Appwrite instance by default.
1270
+ *
1271
+ * A user is limited to 10 active sessions at a time by default. [Learn more
1272
+ * about session
1273
+ * limits](https://appwrite.io/docs/authentication-security#limits).
1274
+ *
1275
+ *
1276
+ * @param {string} userId
1277
+ * @param {string} email
1278
+ * @param {string} url
1279
+ * @param {boolean} phrase
1280
+ * @throws {AppwriteException}
1281
+ * @returns {Promise}
1282
+ */
1283
+ async createMagicURLToken(userId: string, email: string, url?: string, phrase?: boolean): Promise<Models.Token> {
1284
+ if (typeof userId === 'undefined') {
1285
+ throw new AppwriteException('Missing required parameter: "userId"');
1286
+ }
1287
+
1288
+ if (typeof email === 'undefined') {
1289
+ throw new AppwriteException('Missing required parameter: "email"');
1290
+ }
1291
+
1292
+ const apiPath = '/account/tokens/magic-url';
1293
+ const payload: Payload = {};
1294
+
1295
+ if (typeof userId !== 'undefined') {
1296
+ payload['userId'] = userId;
1297
+ }
1298
+
1299
+ if (typeof email !== 'undefined') {
1300
+ payload['email'] = email;
1301
+ }
1302
+
1303
+ if (typeof url !== 'undefined') {
1304
+ payload['url'] = url;
1305
+ }
1306
+
1307
+ if (typeof phrase !== 'undefined') {
1308
+ payload['phrase'] = phrase;
1309
+ }
1310
+
1311
+ const uri = new URL(this.client.config.endpoint + apiPath);
1312
+ return await this.client.call('post', uri, {
1313
+ 'content-type': 'application/json',
1314
+ }, payload);
1315
+ }
1316
+
1317
+ /**
1318
+ * Create OAuth2 token
1319
+ *
1320
+ * Allow the user to login to their account using the OAuth2 provider of their
1321
+ * choice. Each OAuth2 provider should be enabled from the Appwrite console
1322
+ * first. Use the success and failure arguments to provide a redirect URL's
1323
+ * back to your app when login is completed.
1324
+ *
1325
+ * If authentication succeeds, `userId` and `secret` of a token will be
1326
+ * appended to the success URL as query parameters. These can be used to
1327
+ * create a new session using the [Create
1328
+ * session](https://appwrite.io/docs/references/cloud/client-web/account#createSession)
1329
+ * endpoint.
1330
+ *
1331
+ * A user is limited to 10 active sessions at a time by default. [Learn more
1332
+ * about session
1333
+ * limits](https://appwrite.io/docs/authentication-security#limits).
1334
+ *
1335
+ * @param {OAuthProvider} provider
1336
+ * @param {string} success
1337
+ * @param {string} failure
1338
+ * @param {string[]} scopes
1339
+ * @throws {AppwriteException}
1340
+ * @returns {void|string}
1341
+ */
1342
+ createOAuth2Token(provider: OAuthProvider, success?: string, failure?: string, scopes?: string[]): void | URL {
1343
+ if (typeof provider === 'undefined') {
1344
+ throw new AppwriteException('Missing required parameter: "provider"');
1345
+ }
1346
+
1347
+ const apiPath = '/account/tokens/oauth2/{provider}'.replace('{provider}', provider);
1348
+ const payload: Payload = {};
1349
+
1350
+ if (typeof success !== 'undefined') {
1351
+ payload['success'] = success;
1352
+ }
1353
+
1354
+ if (typeof failure !== 'undefined') {
1355
+ payload['failure'] = failure;
1356
+ }
1357
+
1358
+ if (typeof scopes !== 'undefined') {
1359
+ payload['scopes'] = scopes;
1360
+ }
1361
+
1362
+ const uri = new URL(this.client.config.endpoint + apiPath);
1363
+ payload['project'] = this.client.config.project;
1364
+
1365
+
1366
+ for (const [key, value] of Object.entries(Service.flatten(payload))) {
1367
+ uri.searchParams.append(key, value);
1368
+ }
1369
+ return uri;
1370
+ }
1371
+
1372
+ /**
1373
+ * Create phone token
1374
+ *
1375
+ * Sends the user an SMS with a secret key for creating a session. If the
1376
+ * provided user ID has not be registered, a new user will be created. Use the
1377
+ * returned user ID and secret and submit a request to the [POST
1378
+ * /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession)
1379
+ * endpoint to complete the login process. The secret sent to the user's phone
1380
+ * is valid for 15 minutes.
1381
+ *
1382
+ * A user is limited to 10 active sessions at a time by default. [Learn more
1383
+ * about session
1384
+ * limits](https://appwrite.io/docs/authentication-security#limits).
1385
+ *
1386
+ * @param {string} userId
1387
+ * @param {string} phone
1388
+ * @throws {AppwriteException}
1389
+ * @returns {Promise}
1390
+ */
1391
+ async createPhoneToken(userId: string, phone: string): Promise<Models.Token> {
1392
+ if (typeof userId === 'undefined') {
1393
+ throw new AppwriteException('Missing required parameter: "userId"');
1394
+ }
1395
+
1396
+ if (typeof phone === 'undefined') {
1397
+ throw new AppwriteException('Missing required parameter: "phone"');
1398
+ }
1399
+
1400
+ const apiPath = '/account/tokens/phone';
1401
+ const payload: Payload = {};
1402
+
1403
+ if (typeof userId !== 'undefined') {
1404
+ payload['userId'] = userId;
1405
+ }
1406
+
1407
+ if (typeof phone !== 'undefined') {
1408
+ payload['phone'] = phone;
1409
+ }
1410
+
1411
+ const uri = new URL(this.client.config.endpoint + apiPath);
1412
+ return await this.client.call('post', uri, {
1413
+ 'content-type': 'application/json',
1414
+ }, payload);
1415
+ }
1416
+
893
1417
  /**
894
1418
  * Create email verification
895
1419
  *