react-native-appwrite 0.1.0

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 (109) hide show
  1. package/.github/ISSUE_TEMPLATE/bug.yaml +82 -0
  2. package/.github/ISSUE_TEMPLATE/documentation.yaml +32 -0
  3. package/.github/ISSUE_TEMPLATE/feature.yaml +40 -0
  4. package/.github/workflows/publish.yml +33 -0
  5. package/.gitpod.yml +10 -0
  6. package/CHANGELOG.md +1 -0
  7. package/LICENSE +12 -0
  8. package/README.md +111 -0
  9. package/dist/cjs/sdk.js +3127 -0
  10. package/dist/cjs/sdk.js.map +1 -0
  11. package/dist/esm/sdk.js +3108 -0
  12. package/dist/esm/sdk.js.map +1 -0
  13. package/dist/iife/sdk.js +3126 -0
  14. package/docs/examples/account/create-anonymous-session.md +18 -0
  15. package/docs/examples/account/create-email-session.md +18 -0
  16. package/docs/examples/account/create-j-w-t.md +18 -0
  17. package/docs/examples/account/create-magic-u-r-l-session.md +18 -0
  18. package/docs/examples/account/create-o-auth2session.md +14 -0
  19. package/docs/examples/account/create-phone-session.md +18 -0
  20. package/docs/examples/account/create-phone-verification.md +18 -0
  21. package/docs/examples/account/create-recovery.md +18 -0
  22. package/docs/examples/account/create-verification.md +18 -0
  23. package/docs/examples/account/create.md +18 -0
  24. package/docs/examples/account/delete-identity.md +18 -0
  25. package/docs/examples/account/delete-session.md +18 -0
  26. package/docs/examples/account/delete-sessions.md +18 -0
  27. package/docs/examples/account/get-prefs.md +18 -0
  28. package/docs/examples/account/get-session.md +18 -0
  29. package/docs/examples/account/get.md +18 -0
  30. package/docs/examples/account/list-identities.md +18 -0
  31. package/docs/examples/account/list-logs.md +18 -0
  32. package/docs/examples/account/list-sessions.md +18 -0
  33. package/docs/examples/account/update-email.md +18 -0
  34. package/docs/examples/account/update-magic-u-r-l-session.md +18 -0
  35. package/docs/examples/account/update-name.md +18 -0
  36. package/docs/examples/account/update-password.md +18 -0
  37. package/docs/examples/account/update-phone-session.md +18 -0
  38. package/docs/examples/account/update-phone-verification.md +18 -0
  39. package/docs/examples/account/update-phone.md +18 -0
  40. package/docs/examples/account/update-prefs.md +18 -0
  41. package/docs/examples/account/update-recovery.md +18 -0
  42. package/docs/examples/account/update-session.md +18 -0
  43. package/docs/examples/account/update-status.md +18 -0
  44. package/docs/examples/account/update-verification.md +18 -0
  45. package/docs/examples/avatars/get-browser.md +14 -0
  46. package/docs/examples/avatars/get-credit-card.md +14 -0
  47. package/docs/examples/avatars/get-favicon.md +14 -0
  48. package/docs/examples/avatars/get-flag.md +14 -0
  49. package/docs/examples/avatars/get-image.md +14 -0
  50. package/docs/examples/avatars/get-initials.md +14 -0
  51. package/docs/examples/avatars/get-q-r.md +14 -0
  52. package/docs/examples/databases/create-document.md +18 -0
  53. package/docs/examples/databases/delete-document.md +18 -0
  54. package/docs/examples/databases/get-document.md +18 -0
  55. package/docs/examples/databases/list-documents.md +18 -0
  56. package/docs/examples/databases/update-document.md +18 -0
  57. package/docs/examples/functions/create-execution.md +18 -0
  58. package/docs/examples/functions/get-execution.md +18 -0
  59. package/docs/examples/functions/list-executions.md +18 -0
  60. package/docs/examples/graphql/mutation.md +18 -0
  61. package/docs/examples/graphql/query.md +18 -0
  62. package/docs/examples/locale/get.md +18 -0
  63. package/docs/examples/locale/list-codes.md +18 -0
  64. package/docs/examples/locale/list-continents.md +18 -0
  65. package/docs/examples/locale/list-countries-e-u.md +18 -0
  66. package/docs/examples/locale/list-countries-phones.md +18 -0
  67. package/docs/examples/locale/list-countries.md +18 -0
  68. package/docs/examples/locale/list-currencies.md +18 -0
  69. package/docs/examples/locale/list-languages.md +18 -0
  70. package/docs/examples/storage/create-file.md +18 -0
  71. package/docs/examples/storage/delete-file.md +18 -0
  72. package/docs/examples/storage/get-file-download.md +14 -0
  73. package/docs/examples/storage/get-file-preview.md +14 -0
  74. package/docs/examples/storage/get-file-view.md +14 -0
  75. package/docs/examples/storage/get-file.md +18 -0
  76. package/docs/examples/storage/list-files.md +18 -0
  77. package/docs/examples/storage/update-file.md +18 -0
  78. package/docs/examples/teams/create-membership.md +18 -0
  79. package/docs/examples/teams/create.md +18 -0
  80. package/docs/examples/teams/delete-membership.md +18 -0
  81. package/docs/examples/teams/delete.md +18 -0
  82. package/docs/examples/teams/get-membership.md +18 -0
  83. package/docs/examples/teams/get-prefs.md +18 -0
  84. package/docs/examples/teams/get.md +18 -0
  85. package/docs/examples/teams/list-memberships.md +18 -0
  86. package/docs/examples/teams/list.md +18 -0
  87. package/docs/examples/teams/update-membership-status.md +18 -0
  88. package/docs/examples/teams/update-membership.md +18 -0
  89. package/docs/examples/teams/update-name.md +18 -0
  90. package/docs/examples/teams/update-prefs.md +18 -0
  91. package/package.json +47 -0
  92. package/rollup.config.js +31 -0
  93. package/src/client.ts +437 -0
  94. package/src/id.ts +9 -0
  95. package/src/index.ts +14 -0
  96. package/src/models.ts +1021 -0
  97. package/src/permission.ts +22 -0
  98. package/src/query.ts +74 -0
  99. package/src/role.ts +100 -0
  100. package/src/service.ts +30 -0
  101. package/src/services/account.ts +1066 -0
  102. package/src/services/avatars.ts +352 -0
  103. package/src/services/databases.ts +216 -0
  104. package/src/services/functions.ts +125 -0
  105. package/src/services/graphql.ts +68 -0
  106. package/src/services/locale.ts +169 -0
  107. package/src/services/storage.ts +411 -0
  108. package/src/services/teams.ts +484 -0
  109. package/tsconfig.json +24 -0
@@ -0,0 +1,1066 @@
1
+ import { Service } from '../service';
2
+ import { AppwriteException, Client } from '../client';
3
+ import type { Models } from '../models';
4
+ import type { UploadProgress, Payload } from '../client';
5
+
6
+ export class Account extends Service {
7
+
8
+ constructor(client: Client)
9
+ {
10
+ super(client);
11
+ }
12
+
13
+ /**
14
+ * Get account
15
+ *
16
+ * Get the currently logged in user.
17
+ *
18
+ * @throws {AppwriteException}
19
+ * @returns {Promise}
20
+ */
21
+ async get<Preferences extends Models.Preferences>(): Promise<Models.User<Preferences>> {
22
+ const apiPath = '/account';
23
+ const payload: Payload = {};
24
+
25
+ const uri = new URL(this.client.config.endpoint + apiPath);
26
+ return await this.client.call('get', uri, {
27
+ 'content-type': 'application/json',
28
+ }, payload);
29
+ }
30
+
31
+ /**
32
+ * Create account
33
+ *
34
+ * Use this endpoint to allow a new user to register a new account in your
35
+ * project. After the user registration completes successfully, you can use
36
+ * the
37
+ * [/account/verfication](https://appwrite.io/docs/references/cloud/client-web/account#createVerification)
38
+ * route to start verifying the user email address. To allow the new user to
39
+ * login to their new account, you need to create a new [account
40
+ * session](https://appwrite.io/docs/references/cloud/client-web/account#createEmailSession).
41
+ *
42
+ * @param {string} userId
43
+ * @param {string} email
44
+ * @param {string} password
45
+ * @param {string} name
46
+ * @throws {AppwriteException}
47
+ * @returns {Promise}
48
+ */
49
+ async create<Preferences extends Models.Preferences>(userId: string, email: string, password: string, name?: string): Promise<Models.User<Preferences>> {
50
+ if (typeof userId === 'undefined') {
51
+ throw new AppwriteException('Missing required parameter: "userId"');
52
+ }
53
+
54
+ if (typeof email === 'undefined') {
55
+ throw new AppwriteException('Missing required parameter: "email"');
56
+ }
57
+
58
+ if (typeof password === 'undefined') {
59
+ throw new AppwriteException('Missing required parameter: "password"');
60
+ }
61
+
62
+ const apiPath = '/account';
63
+ const payload: Payload = {};
64
+
65
+ if (typeof userId !== 'undefined') {
66
+ payload['userId'] = userId;
67
+ }
68
+
69
+ if (typeof email !== 'undefined') {
70
+ payload['email'] = email;
71
+ }
72
+
73
+ if (typeof password !== 'undefined') {
74
+ payload['password'] = password;
75
+ }
76
+
77
+ if (typeof name !== 'undefined') {
78
+ payload['name'] = name;
79
+ }
80
+
81
+ const uri = new URL(this.client.config.endpoint + apiPath);
82
+ return await this.client.call('post', uri, {
83
+ 'content-type': 'application/json',
84
+ }, payload);
85
+ }
86
+
87
+ /**
88
+ * Update email
89
+ *
90
+ * Update currently logged in user account email address. After changing user
91
+ * address, the user confirmation status will get reset. A new confirmation
92
+ * email is not sent automatically however you can use the send confirmation
93
+ * email endpoint again to send the confirmation email. For security measures,
94
+ * user password is required to complete this request.
95
+ * This endpoint can also be used to convert an anonymous account to a normal
96
+ * one, by passing an email address and a new password.
97
+ *
98
+ *
99
+ * @param {string} email
100
+ * @param {string} password
101
+ * @throws {AppwriteException}
102
+ * @returns {Promise}
103
+ */
104
+ async updateEmail<Preferences extends Models.Preferences>(email: string, password: string): Promise<Models.User<Preferences>> {
105
+ if (typeof email === 'undefined') {
106
+ throw new AppwriteException('Missing required parameter: "email"');
107
+ }
108
+
109
+ if (typeof password === 'undefined') {
110
+ throw new AppwriteException('Missing required parameter: "password"');
111
+ }
112
+
113
+ const apiPath = '/account/email';
114
+ const payload: Payload = {};
115
+
116
+ if (typeof email !== 'undefined') {
117
+ payload['email'] = email;
118
+ }
119
+
120
+ if (typeof password !== 'undefined') {
121
+ payload['password'] = password;
122
+ }
123
+
124
+ const uri = new URL(this.client.config.endpoint + apiPath);
125
+ return await this.client.call('patch', uri, {
126
+ 'content-type': 'application/json',
127
+ }, payload);
128
+ }
129
+
130
+ /**
131
+ * List Identities
132
+ *
133
+ * Get the list of identities for the currently logged in user.
134
+ *
135
+ * @param {string} queries
136
+ * @throws {AppwriteException}
137
+ * @returns {Promise}
138
+ */
139
+ async listIdentities(queries?: string): Promise<Models.IdentityList> {
140
+ const apiPath = '/account/identities';
141
+ const payload: Payload = {};
142
+
143
+ if (typeof queries !== 'undefined') {
144
+ payload['queries'] = queries;
145
+ }
146
+
147
+ const uri = new URL(this.client.config.endpoint + apiPath);
148
+ return await this.client.call('get', uri, {
149
+ 'content-type': 'application/json',
150
+ }, payload);
151
+ }
152
+
153
+ /**
154
+ * Delete Identity
155
+ *
156
+ * Delete an identity by its unique ID.
157
+ *
158
+ * @param {string} identityId
159
+ * @throws {AppwriteException}
160
+ * @returns {Promise}
161
+ */
162
+ async deleteIdentity(identityId: string): Promise<{}> {
163
+ if (typeof identityId === 'undefined') {
164
+ throw new AppwriteException('Missing required parameter: "identityId"');
165
+ }
166
+
167
+ const apiPath = '/account/identities/{identityId}'.replace('{identityId}', identityId);
168
+ const payload: Payload = {};
169
+
170
+ const uri = new URL(this.client.config.endpoint + apiPath);
171
+ return await this.client.call('delete', uri, {
172
+ 'content-type': 'application/json',
173
+ }, payload);
174
+ }
175
+
176
+ /**
177
+ * Create JWT
178
+ *
179
+ * Use this endpoint to create a JSON Web Token. You can use the resulting JWT
180
+ * to authenticate on behalf of the current user when working with the
181
+ * Appwrite server-side API and SDKs. The JWT secret is valid for 15 minutes
182
+ * from its creation and will be invalid if the user will logout in that time
183
+ * frame.
184
+ *
185
+ * @throws {AppwriteException}
186
+ * @returns {Promise}
187
+ */
188
+ async createJWT(): Promise<Models.Jwt> {
189
+ const apiPath = '/account/jwt';
190
+ const payload: Payload = {};
191
+
192
+ const uri = new URL(this.client.config.endpoint + apiPath);
193
+ return await this.client.call('post', uri, {
194
+ 'content-type': 'application/json',
195
+ }, payload);
196
+ }
197
+
198
+ /**
199
+ * List logs
200
+ *
201
+ * Get the list of latest security activity logs for the currently logged in
202
+ * user. Each log returns user IP address, location and date and time of log.
203
+ *
204
+ * @param {string[]} queries
205
+ * @throws {AppwriteException}
206
+ * @returns {Promise}
207
+ */
208
+ async listLogs(queries?: string[]): Promise<Models.LogList> {
209
+ const apiPath = '/account/logs';
210
+ const payload: Payload = {};
211
+
212
+ if (typeof queries !== 'undefined') {
213
+ payload['queries'] = queries;
214
+ }
215
+
216
+ const uri = new URL(this.client.config.endpoint + apiPath);
217
+ return await this.client.call('get', uri, {
218
+ 'content-type': 'application/json',
219
+ }, payload);
220
+ }
221
+
222
+ /**
223
+ * Update name
224
+ *
225
+ * Update currently logged in user account name.
226
+ *
227
+ * @param {string} name
228
+ * @throws {AppwriteException}
229
+ * @returns {Promise}
230
+ */
231
+ async updateName<Preferences extends Models.Preferences>(name: string): Promise<Models.User<Preferences>> {
232
+ if (typeof name === 'undefined') {
233
+ throw new AppwriteException('Missing required parameter: "name"');
234
+ }
235
+
236
+ const apiPath = '/account/name';
237
+ const payload: Payload = {};
238
+
239
+ if (typeof name !== 'undefined') {
240
+ payload['name'] = name;
241
+ }
242
+
243
+ const uri = new URL(this.client.config.endpoint + apiPath);
244
+ return await this.client.call('patch', uri, {
245
+ 'content-type': 'application/json',
246
+ }, payload);
247
+ }
248
+
249
+ /**
250
+ * Update password
251
+ *
252
+ * Update currently logged in user password. For validation, user is required
253
+ * to pass in the new password, and the old password. For users created with
254
+ * OAuth, Team Invites and Magic URL, oldPassword is optional.
255
+ *
256
+ * @param {string} password
257
+ * @param {string} oldPassword
258
+ * @throws {AppwriteException}
259
+ * @returns {Promise}
260
+ */
261
+ async updatePassword<Preferences extends Models.Preferences>(password: string, oldPassword?: string): Promise<Models.User<Preferences>> {
262
+ if (typeof password === 'undefined') {
263
+ throw new AppwriteException('Missing required parameter: "password"');
264
+ }
265
+
266
+ const apiPath = '/account/password';
267
+ const payload: Payload = {};
268
+
269
+ if (typeof password !== 'undefined') {
270
+ payload['password'] = password;
271
+ }
272
+
273
+ if (typeof oldPassword !== 'undefined') {
274
+ payload['oldPassword'] = oldPassword;
275
+ }
276
+
277
+ const uri = new URL(this.client.config.endpoint + apiPath);
278
+ return await this.client.call('patch', uri, {
279
+ 'content-type': 'application/json',
280
+ }, payload);
281
+ }
282
+
283
+ /**
284
+ * Update phone
285
+ *
286
+ * Update the currently logged in user's phone number. After updating the
287
+ * phone number, the phone verification status will be reset. A confirmation
288
+ * SMS is not sent automatically, however you can use the [POST
289
+ * /account/verification/phone](https://appwrite.io/docs/references/cloud/client-web/account#createPhoneVerification)
290
+ * endpoint to send a confirmation SMS.
291
+ *
292
+ * @param {string} phone
293
+ * @param {string} password
294
+ * @throws {AppwriteException}
295
+ * @returns {Promise}
296
+ */
297
+ async updatePhone<Preferences extends Models.Preferences>(phone: string, password: string): Promise<Models.User<Preferences>> {
298
+ if (typeof phone === 'undefined') {
299
+ throw new AppwriteException('Missing required parameter: "phone"');
300
+ }
301
+
302
+ if (typeof password === 'undefined') {
303
+ throw new AppwriteException('Missing required parameter: "password"');
304
+ }
305
+
306
+ const apiPath = '/account/phone';
307
+ const payload: Payload = {};
308
+
309
+ if (typeof phone !== 'undefined') {
310
+ payload['phone'] = phone;
311
+ }
312
+
313
+ if (typeof password !== 'undefined') {
314
+ payload['password'] = password;
315
+ }
316
+
317
+ const uri = new URL(this.client.config.endpoint + apiPath);
318
+ return await this.client.call('patch', uri, {
319
+ 'content-type': 'application/json',
320
+ }, payload);
321
+ }
322
+
323
+ /**
324
+ * Get account preferences
325
+ *
326
+ * Get the preferences as a key-value object for the currently logged in user.
327
+ *
328
+ * @throws {AppwriteException}
329
+ * @returns {Promise}
330
+ */
331
+ async getPrefs<Preferences extends Models.Preferences>(): Promise<Preferences> {
332
+ const apiPath = '/account/prefs';
333
+ const payload: Payload = {};
334
+
335
+ const uri = new URL(this.client.config.endpoint + apiPath);
336
+ return await this.client.call('get', uri, {
337
+ 'content-type': 'application/json',
338
+ }, payload);
339
+ }
340
+
341
+ /**
342
+ * Update preferences
343
+ *
344
+ * Update currently logged in user account preferences. The object you pass is
345
+ * stored as is, and replaces any previous value. The maximum allowed prefs
346
+ * size is 64kB and throws error if exceeded.
347
+ *
348
+ * @param {Partial<Preferences>} prefs
349
+ * @throws {AppwriteException}
350
+ * @returns {Promise}
351
+ */
352
+ async updatePrefs<Preferences extends Models.Preferences>(prefs: Partial<Preferences>): Promise<Models.User<Preferences>> {
353
+ if (typeof prefs === 'undefined') {
354
+ throw new AppwriteException('Missing required parameter: "prefs"');
355
+ }
356
+
357
+ const apiPath = '/account/prefs';
358
+ const payload: Payload = {};
359
+
360
+ if (typeof prefs !== 'undefined') {
361
+ payload['prefs'] = prefs;
362
+ }
363
+
364
+ const uri = new URL(this.client.config.endpoint + apiPath);
365
+ return await this.client.call('patch', uri, {
366
+ 'content-type': 'application/json',
367
+ }, payload);
368
+ }
369
+
370
+ /**
371
+ * Create password recovery
372
+ *
373
+ * Sends the user an email with a temporary secret key for password reset.
374
+ * When the user clicks the confirmation link he is redirected back to your
375
+ * app password reset URL with the secret key and email address values
376
+ * attached to the URL query string. Use the query string params to submit a
377
+ * request to the [PUT
378
+ * /account/recovery](https://appwrite.io/docs/references/cloud/client-web/account#updateRecovery)
379
+ * endpoint to complete the process. The verification link sent to the user's
380
+ * email address is valid for 1 hour.
381
+ *
382
+ * @param {string} email
383
+ * @param {string} url
384
+ * @throws {AppwriteException}
385
+ * @returns {Promise}
386
+ */
387
+ async createRecovery(email: string, url: string): Promise<Models.Token> {
388
+ if (typeof email === 'undefined') {
389
+ throw new AppwriteException('Missing required parameter: "email"');
390
+ }
391
+
392
+ if (typeof url === 'undefined') {
393
+ throw new AppwriteException('Missing required parameter: "url"');
394
+ }
395
+
396
+ const apiPath = '/account/recovery';
397
+ const payload: Payload = {};
398
+
399
+ if (typeof email !== 'undefined') {
400
+ payload['email'] = email;
401
+ }
402
+
403
+ if (typeof url !== 'undefined') {
404
+ payload['url'] = url;
405
+ }
406
+
407
+ const uri = new URL(this.client.config.endpoint + apiPath);
408
+ return await this.client.call('post', uri, {
409
+ 'content-type': 'application/json',
410
+ }, payload);
411
+ }
412
+
413
+ /**
414
+ * Create password recovery (confirmation)
415
+ *
416
+ * Use this endpoint to complete the user account password reset. Both the
417
+ * **userId** and **secret** arguments will be passed as query parameters to
418
+ * the redirect URL you have provided when sending your request to the [POST
419
+ * /account/recovery](https://appwrite.io/docs/references/cloud/client-web/account#createRecovery)
420
+ * endpoint.
421
+ *
422
+ * Please note that in order to avoid a [Redirect
423
+ * Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md)
424
+ * the only valid redirect URLs are the ones from domains you have set when
425
+ * adding your platforms in the console interface.
426
+ *
427
+ * @param {string} userId
428
+ * @param {string} secret
429
+ * @param {string} password
430
+ * @param {string} passwordAgain
431
+ * @throws {AppwriteException}
432
+ * @returns {Promise}
433
+ */
434
+ async updateRecovery(userId: string, secret: string, password: string, passwordAgain: string): Promise<Models.Token> {
435
+ if (typeof userId === 'undefined') {
436
+ throw new AppwriteException('Missing required parameter: "userId"');
437
+ }
438
+
439
+ if (typeof secret === 'undefined') {
440
+ throw new AppwriteException('Missing required parameter: "secret"');
441
+ }
442
+
443
+ if (typeof password === 'undefined') {
444
+ throw new AppwriteException('Missing required parameter: "password"');
445
+ }
446
+
447
+ if (typeof passwordAgain === 'undefined') {
448
+ throw new AppwriteException('Missing required parameter: "passwordAgain"');
449
+ }
450
+
451
+ const apiPath = '/account/recovery';
452
+ const payload: Payload = {};
453
+
454
+ if (typeof userId !== 'undefined') {
455
+ payload['userId'] = userId;
456
+ }
457
+
458
+ if (typeof secret !== 'undefined') {
459
+ payload['secret'] = secret;
460
+ }
461
+
462
+ if (typeof password !== 'undefined') {
463
+ payload['password'] = password;
464
+ }
465
+
466
+ if (typeof passwordAgain !== 'undefined') {
467
+ payload['passwordAgain'] = passwordAgain;
468
+ }
469
+
470
+ const uri = new URL(this.client.config.endpoint + apiPath);
471
+ return await this.client.call('put', uri, {
472
+ 'content-type': 'application/json',
473
+ }, payload);
474
+ }
475
+
476
+ /**
477
+ * List sessions
478
+ *
479
+ * Get the list of active sessions across different devices for the currently
480
+ * logged in user.
481
+ *
482
+ * @throws {AppwriteException}
483
+ * @returns {Promise}
484
+ */
485
+ async listSessions(): Promise<Models.SessionList> {
486
+ const apiPath = '/account/sessions';
487
+ const payload: Payload = {};
488
+
489
+ const uri = new URL(this.client.config.endpoint + apiPath);
490
+ return await this.client.call('get', uri, {
491
+ 'content-type': 'application/json',
492
+ }, payload);
493
+ }
494
+
495
+ /**
496
+ * Delete sessions
497
+ *
498
+ * Delete all sessions from the user account and remove any sessions cookies
499
+ * from the end client.
500
+ *
501
+ * @throws {AppwriteException}
502
+ * @returns {Promise}
503
+ */
504
+ async deleteSessions(): Promise<{}> {
505
+ const apiPath = '/account/sessions';
506
+ const payload: Payload = {};
507
+
508
+ const uri = new URL(this.client.config.endpoint + apiPath);
509
+ return await this.client.call('delete', uri, {
510
+ 'content-type': 'application/json',
511
+ }, payload);
512
+ }
513
+
514
+ /**
515
+ * Create anonymous session
516
+ *
517
+ * Use this endpoint to allow a new user to register an anonymous account in
518
+ * your project. This route will also create a new session for the user. To
519
+ * allow the new user to convert an anonymous account to a normal account, you
520
+ * need to update its [email and
521
+ * password](https://appwrite.io/docs/references/cloud/client-web/account#updateEmail)
522
+ * or create an [OAuth2
523
+ * session](https://appwrite.io/docs/references/cloud/client-web/account#CreateOAuth2Session).
524
+ *
525
+ * @throws {AppwriteException}
526
+ * @returns {Promise}
527
+ */
528
+ async createAnonymousSession(): Promise<Models.Session> {
529
+ const apiPath = '/account/sessions/anonymous';
530
+ const payload: Payload = {};
531
+
532
+ const uri = new URL(this.client.config.endpoint + apiPath);
533
+ return await this.client.call('post', uri, {
534
+ 'content-type': 'application/json',
535
+ }, payload);
536
+ }
537
+
538
+ /**
539
+ * Create email session
540
+ *
541
+ * Allow the user to login into their account by providing a valid email and
542
+ * password combination. This route will create a new session for the user.
543
+ *
544
+ * A user is limited to 10 active sessions at a time by default. [Learn more
545
+ * about session
546
+ * limits](https://appwrite.io/docs/authentication-security#limits).
547
+ *
548
+ * @param {string} email
549
+ * @param {string} password
550
+ * @throws {AppwriteException}
551
+ * @returns {Promise}
552
+ */
553
+ async createEmailSession(email: string, password: string): Promise<Models.Session> {
554
+ if (typeof email === 'undefined') {
555
+ throw new AppwriteException('Missing required parameter: "email"');
556
+ }
557
+
558
+ if (typeof password === 'undefined') {
559
+ throw new AppwriteException('Missing required parameter: "password"');
560
+ }
561
+
562
+ const apiPath = '/account/sessions/email';
563
+ const payload: Payload = {};
564
+
565
+ if (typeof email !== 'undefined') {
566
+ payload['email'] = email;
567
+ }
568
+
569
+ if (typeof password !== 'undefined') {
570
+ payload['password'] = password;
571
+ }
572
+
573
+ const uri = new URL(this.client.config.endpoint + apiPath);
574
+ return await this.client.call('post', uri, {
575
+ 'content-type': 'application/json',
576
+ }, payload);
577
+ }
578
+
579
+ /**
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)
637
+ *
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.
649
+ *
650
+ * @param {string} userId
651
+ * @param {string} secret
652
+ * @throws {AppwriteException}
653
+ * @returns {Promise}
654
+ */
655
+ async updateMagicURLSession(userId: string, secret: string): Promise<Models.Session> {
656
+ if (typeof userId === 'undefined') {
657
+ throw new AppwriteException('Missing required parameter: "userId"');
658
+ }
659
+
660
+ if (typeof secret === 'undefined') {
661
+ throw new AppwriteException('Missing required parameter: "secret"');
662
+ }
663
+
664
+ const apiPath = '/account/sessions/magic-url';
665
+ const payload: Payload = {};
666
+
667
+ if (typeof userId !== 'undefined') {
668
+ payload['userId'] = userId;
669
+ }
670
+
671
+ if (typeof secret !== 'undefined') {
672
+ payload['secret'] = secret;
673
+ }
674
+
675
+ const uri = new URL(this.client.config.endpoint + apiPath);
676
+ return await this.client.call('put', uri, {
677
+ 'content-type': 'application/json',
678
+ }, payload);
679
+ }
680
+
681
+ /**
682
+ * Create OAuth2 session
683
+ *
684
+ * Allow the user to login to their account using the OAuth2 provider of their
685
+ * choice. Each OAuth2 provider should be enabled from the Appwrite console
686
+ * first. Use the success and failure arguments to provide a redirect URL's
687
+ * back to your app when login is completed.
688
+ *
689
+ * If there is already an active session, the new session will be attached to
690
+ * the logged-in account. If there are no active sessions, the server will
691
+ * attempt to look for a user with the same email address as the email
692
+ * received from the OAuth2 provider and attach the new session to the
693
+ * existing user. If no matching user is found - the server will create a new
694
+ * user.
695
+ *
696
+ * A user is limited to 10 active sessions at a time by default. [Learn more
697
+ * about session
698
+ * limits](https://appwrite.io/docs/authentication-security#limits).
699
+ *
700
+ *
701
+ * @param {string} provider
702
+ * @param {string} success
703
+ * @param {string} failure
704
+ * @param {string[]} scopes
705
+ * @throws {AppwriteException}
706
+ * @returns {void|string}
707
+ */
708
+ createOAuth2Session(provider: string, success?: string, failure?: string, scopes?: string[]): void | URL {
709
+ if (typeof provider === 'undefined') {
710
+ throw new AppwriteException('Missing required parameter: "provider"');
711
+ }
712
+
713
+ const apiPath = '/account/sessions/oauth2/{provider}'.replace('{provider}', provider);
714
+ const payload: Payload = {};
715
+
716
+ if (typeof success !== 'undefined') {
717
+ payload['success'] = success;
718
+ }
719
+
720
+ if (typeof failure !== 'undefined') {
721
+ payload['failure'] = failure;
722
+ }
723
+
724
+ if (typeof scopes !== 'undefined') {
725
+ payload['scopes'] = scopes;
726
+ }
727
+
728
+ const uri = new URL(this.client.config.endpoint + apiPath);
729
+ payload['project'] = this.client.config.project;
730
+
731
+
732
+ for (const [key, value] of Object.entries(Service.flatten(payload))) {
733
+ uri.searchParams.append(key, value);
734
+ }
735
+ if (typeof window !== 'undefined' && window?.location) {
736
+ window.location.href = uri.toString();
737
+ } else {
738
+ return uri;
739
+ }
740
+ }
741
+
742
+ /**
743
+ * Create phone session
744
+ *
745
+ * Sends the user an SMS with a secret key for creating a session. If the
746
+ * provided user ID has not be registered, a new user will be created. Use the
747
+ * returned user ID and secret and submit a request to the [PUT
748
+ * /account/sessions/phone](https://appwrite.io/docs/references/cloud/client-web/account#updatePhoneSession)
749
+ * endpoint to complete the login process. The secret sent to the user's phone
750
+ * is valid for 15 minutes.
751
+ *
752
+ * A user is limited to 10 active sessions at a time by default. [Learn more
753
+ * about session
754
+ * limits](https://appwrite.io/docs/authentication-security#limits).
755
+ *
756
+ * @param {string} userId
757
+ * @param {string} phone
758
+ * @throws {AppwriteException}
759
+ * @returns {Promise}
760
+ */
761
+ async createPhoneSession(userId: string, phone: string): Promise<Models.Token> {
762
+ if (typeof userId === 'undefined') {
763
+ throw new AppwriteException('Missing required parameter: "userId"');
764
+ }
765
+
766
+ if (typeof phone === 'undefined') {
767
+ throw new AppwriteException('Missing required parameter: "phone"');
768
+ }
769
+
770
+ const apiPath = '/account/sessions/phone';
771
+ const payload: Payload = {};
772
+
773
+ if (typeof userId !== 'undefined') {
774
+ payload['userId'] = userId;
775
+ }
776
+
777
+ if (typeof phone !== 'undefined') {
778
+ payload['phone'] = phone;
779
+ }
780
+
781
+ const uri = new URL(this.client.config.endpoint + apiPath);
782
+ return await this.client.call('post', uri, {
783
+ 'content-type': 'application/json',
784
+ }, payload);
785
+ }
786
+
787
+ /**
788
+ * Create phone session (confirmation)
789
+ *
790
+ * Use this endpoint to complete creating a session with SMS. Use the
791
+ * **userId** from the
792
+ * [createPhoneSession](https://appwrite.io/docs/references/cloud/client-web/account#createPhoneSession)
793
+ * endpoint and the **secret** received via SMS to successfully update and
794
+ * confirm the phone session.
795
+ *
796
+ * @param {string} userId
797
+ * @param {string} secret
798
+ * @throws {AppwriteException}
799
+ * @returns {Promise}
800
+ */
801
+ async updatePhoneSession(userId: string, secret: string): Promise<Models.Session> {
802
+ if (typeof userId === 'undefined') {
803
+ throw new AppwriteException('Missing required parameter: "userId"');
804
+ }
805
+
806
+ if (typeof secret === 'undefined') {
807
+ throw new AppwriteException('Missing required parameter: "secret"');
808
+ }
809
+
810
+ const apiPath = '/account/sessions/phone';
811
+ const payload: Payload = {};
812
+
813
+ if (typeof userId !== 'undefined') {
814
+ payload['userId'] = userId;
815
+ }
816
+
817
+ if (typeof secret !== 'undefined') {
818
+ payload['secret'] = secret;
819
+ }
820
+
821
+ const uri = new URL(this.client.config.endpoint + apiPath);
822
+ return await this.client.call('put', uri, {
823
+ 'content-type': 'application/json',
824
+ }, payload);
825
+ }
826
+
827
+ /**
828
+ * Get session
829
+ *
830
+ * Use this endpoint to get a logged in user's session using a Session ID.
831
+ * Inputting 'current' will return the current session being used.
832
+ *
833
+ * @param {string} sessionId
834
+ * @throws {AppwriteException}
835
+ * @returns {Promise}
836
+ */
837
+ async getSession(sessionId: string): Promise<Models.Session> {
838
+ if (typeof sessionId === 'undefined') {
839
+ throw new AppwriteException('Missing required parameter: "sessionId"');
840
+ }
841
+
842
+ const apiPath = '/account/sessions/{sessionId}'.replace('{sessionId}', sessionId);
843
+ const payload: Payload = {};
844
+
845
+ const uri = new URL(this.client.config.endpoint + apiPath);
846
+ return await this.client.call('get', uri, {
847
+ 'content-type': 'application/json',
848
+ }, payload);
849
+ }
850
+
851
+ /**
852
+ * Update OAuth session (refresh tokens)
853
+ *
854
+ * Access tokens have limited lifespan and expire to mitigate security risks.
855
+ * If session was created using an OAuth provider, this route can be used to
856
+ * "refresh" the access token.
857
+ *
858
+ * @param {string} sessionId
859
+ * @throws {AppwriteException}
860
+ * @returns {Promise}
861
+ */
862
+ async updateSession(sessionId: string): Promise<Models.Session> {
863
+ if (typeof sessionId === 'undefined') {
864
+ throw new AppwriteException('Missing required parameter: "sessionId"');
865
+ }
866
+
867
+ const apiPath = '/account/sessions/{sessionId}'.replace('{sessionId}', sessionId);
868
+ const payload: Payload = {};
869
+
870
+ const uri = new URL(this.client.config.endpoint + apiPath);
871
+ return await this.client.call('patch', uri, {
872
+ 'content-type': 'application/json',
873
+ }, payload);
874
+ }
875
+
876
+ /**
877
+ * Delete session
878
+ *
879
+ * Logout the user. Use 'current' as the session ID to logout on this device,
880
+ * use a session ID to logout on another device. If you're looking to logout
881
+ * the user on all devices, use [Delete
882
+ * Sessions](https://appwrite.io/docs/references/cloud/client-web/account#deleteSessions)
883
+ * instead.
884
+ *
885
+ * @param {string} sessionId
886
+ * @throws {AppwriteException}
887
+ * @returns {Promise}
888
+ */
889
+ async deleteSession(sessionId: string): Promise<{}> {
890
+ if (typeof sessionId === 'undefined') {
891
+ throw new AppwriteException('Missing required parameter: "sessionId"');
892
+ }
893
+
894
+ const apiPath = '/account/sessions/{sessionId}'.replace('{sessionId}', sessionId);
895
+ const payload: Payload = {};
896
+
897
+ const uri = new URL(this.client.config.endpoint + apiPath);
898
+ return await this.client.call('delete', uri, {
899
+ 'content-type': 'application/json',
900
+ }, payload);
901
+ }
902
+
903
+ /**
904
+ * Update status
905
+ *
906
+ * Block the currently logged in user account. Behind the scene, the user
907
+ * record is not deleted but permanently blocked from any access. To
908
+ * completely delete a user, use the Users API instead.
909
+ *
910
+ * @throws {AppwriteException}
911
+ * @returns {Promise}
912
+ */
913
+ async updateStatus<Preferences extends Models.Preferences>(): Promise<Models.User<Preferences>> {
914
+ const apiPath = '/account/status';
915
+ const payload: Payload = {};
916
+
917
+ const uri = new URL(this.client.config.endpoint + apiPath);
918
+ return await this.client.call('patch', uri, {
919
+ 'content-type': 'application/json',
920
+ }, payload);
921
+ }
922
+
923
+ /**
924
+ * Create email verification
925
+ *
926
+ * Use this endpoint to send a verification message to your user email address
927
+ * to confirm they are the valid owners of that address. Both the **userId**
928
+ * and **secret** arguments will be passed as query parameters to the URL you
929
+ * have provided to be attached to the verification email. The provided URL
930
+ * should redirect the user back to your app and allow you to complete the
931
+ * verification process by verifying both the **userId** and **secret**
932
+ * parameters. Learn more about how to [complete the verification
933
+ * process](https://appwrite.io/docs/references/cloud/client-web/account#updateVerification).
934
+ * The verification link sent to the user's email address is valid for 7 days.
935
+ *
936
+ * Please note that in order to avoid a [Redirect
937
+ * Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md),
938
+ * the only valid redirect URLs are the ones from domains you have set when
939
+ * adding your platforms in the console interface.
940
+ *
941
+ *
942
+ * @param {string} url
943
+ * @throws {AppwriteException}
944
+ * @returns {Promise}
945
+ */
946
+ async createVerification(url: string): Promise<Models.Token> {
947
+ if (typeof url === 'undefined') {
948
+ throw new AppwriteException('Missing required parameter: "url"');
949
+ }
950
+
951
+ const apiPath = '/account/verification';
952
+ const payload: Payload = {};
953
+
954
+ if (typeof url !== 'undefined') {
955
+ payload['url'] = url;
956
+ }
957
+
958
+ const uri = new URL(this.client.config.endpoint + apiPath);
959
+ return await this.client.call('post', uri, {
960
+ 'content-type': 'application/json',
961
+ }, payload);
962
+ }
963
+
964
+ /**
965
+ * Create email verification (confirmation)
966
+ *
967
+ * Use this endpoint to complete the user email verification process. Use both
968
+ * the **userId** and **secret** parameters that were attached to your app URL
969
+ * to verify the user email ownership. If confirmed this route will return a
970
+ * 200 status code.
971
+ *
972
+ * @param {string} userId
973
+ * @param {string} secret
974
+ * @throws {AppwriteException}
975
+ * @returns {Promise}
976
+ */
977
+ async updateVerification(userId: string, secret: string): Promise<Models.Token> {
978
+ if (typeof userId === 'undefined') {
979
+ throw new AppwriteException('Missing required parameter: "userId"');
980
+ }
981
+
982
+ if (typeof secret === 'undefined') {
983
+ throw new AppwriteException('Missing required parameter: "secret"');
984
+ }
985
+
986
+ const apiPath = '/account/verification';
987
+ const payload: Payload = {};
988
+
989
+ if (typeof userId !== 'undefined') {
990
+ payload['userId'] = userId;
991
+ }
992
+
993
+ if (typeof secret !== 'undefined') {
994
+ payload['secret'] = secret;
995
+ }
996
+
997
+ const uri = new URL(this.client.config.endpoint + apiPath);
998
+ return await this.client.call('put', uri, {
999
+ 'content-type': 'application/json',
1000
+ }, payload);
1001
+ }
1002
+
1003
+ /**
1004
+ * Create phone verification
1005
+ *
1006
+ * Use this endpoint to send a verification SMS to the currently logged in
1007
+ * user. This endpoint is meant for use after updating a user's phone number
1008
+ * using the
1009
+ * [accountUpdatePhone](https://appwrite.io/docs/references/cloud/client-web/account#updatePhone)
1010
+ * endpoint. Learn more about how to [complete the verification
1011
+ * process](https://appwrite.io/docs/references/cloud/client-web/account#updatePhoneVerification).
1012
+ * The verification code sent to the user's phone number is valid for 15
1013
+ * minutes.
1014
+ *
1015
+ * @throws {AppwriteException}
1016
+ * @returns {Promise}
1017
+ */
1018
+ async createPhoneVerification(): Promise<Models.Token> {
1019
+ const apiPath = '/account/verification/phone';
1020
+ const payload: Payload = {};
1021
+
1022
+ const uri = new URL(this.client.config.endpoint + apiPath);
1023
+ return await this.client.call('post', uri, {
1024
+ 'content-type': 'application/json',
1025
+ }, payload);
1026
+ }
1027
+
1028
+ /**
1029
+ * Create phone verification (confirmation)
1030
+ *
1031
+ * Use this endpoint to complete the user phone verification process. Use the
1032
+ * **userId** and **secret** that were sent to your user's phone number to
1033
+ * verify the user email ownership. If confirmed this route will return a 200
1034
+ * status code.
1035
+ *
1036
+ * @param {string} userId
1037
+ * @param {string} secret
1038
+ * @throws {AppwriteException}
1039
+ * @returns {Promise}
1040
+ */
1041
+ async updatePhoneVerification(userId: string, secret: string): Promise<Models.Token> {
1042
+ if (typeof userId === 'undefined') {
1043
+ throw new AppwriteException('Missing required parameter: "userId"');
1044
+ }
1045
+
1046
+ if (typeof secret === 'undefined') {
1047
+ throw new AppwriteException('Missing required parameter: "secret"');
1048
+ }
1049
+
1050
+ const apiPath = '/account/verification/phone';
1051
+ const payload: Payload = {};
1052
+
1053
+ if (typeof userId !== 'undefined') {
1054
+ payload['userId'] = userId;
1055
+ }
1056
+
1057
+ if (typeof secret !== 'undefined') {
1058
+ payload['secret'] = secret;
1059
+ }
1060
+
1061
+ const uri = new URL(this.client.config.endpoint + apiPath);
1062
+ return await this.client.call('put', uri, {
1063
+ 'content-type': 'application/json',
1064
+ }, payload);
1065
+ }
1066
+ };