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,3108 @@
1
+ import 'isomorphic-form-data';
2
+ import { fetch } from 'cross-fetch';
3
+ import { Platform } from 'react-native';
4
+ import fs from 'react-native-fs';
5
+
6
+ /******************************************************************************
7
+ Copyright (c) Microsoft Corporation.
8
+
9
+ Permission to use, copy, modify, and/or distribute this software for any
10
+ purpose with or without fee is hereby granted.
11
+
12
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
13
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
14
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
15
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
16
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
17
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
18
+ PERFORMANCE OF THIS SOFTWARE.
19
+ ***************************************************************************** */
20
+
21
+ function __awaiter(thisArg, _arguments, P, generator) {
22
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
+ return new (P || (P = Promise))(function (resolve, reject) {
24
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
28
+ });
29
+ }
30
+
31
+ class Service {
32
+ constructor(client) {
33
+ this.client = client;
34
+ }
35
+ static flatten(data, prefix = '') {
36
+ let output = {};
37
+ for (const key in data) {
38
+ let value = data[key];
39
+ let finalKey = prefix ? `${prefix}[${key}]` : key;
40
+ if (Array.isArray(value)) {
41
+ output = Object.assign(output, this.flatten(value, finalKey));
42
+ }
43
+ else {
44
+ output[finalKey] = value;
45
+ }
46
+ }
47
+ return output;
48
+ }
49
+ }
50
+ Service.CHUNK_SIZE = 5 * 1024 * 1024; // 5MB
51
+
52
+ class Query {
53
+ }
54
+ Query.equal = (attribute, value) => Query.addQuery(attribute, "equal", value);
55
+ Query.notEqual = (attribute, value) => Query.addQuery(attribute, "notEqual", value);
56
+ Query.lessThan = (attribute, value) => Query.addQuery(attribute, "lessThan", value);
57
+ Query.lessThanEqual = (attribute, value) => Query.addQuery(attribute, "lessThanEqual", value);
58
+ Query.greaterThan = (attribute, value) => Query.addQuery(attribute, "greaterThan", value);
59
+ Query.greaterThanEqual = (attribute, value) => Query.addQuery(attribute, "greaterThanEqual", value);
60
+ Query.isNull = (attribute) => `isNull("${attribute}")`;
61
+ Query.isNotNull = (attribute) => `isNotNull("${attribute}")`;
62
+ Query.between = (attribute, start, end) => `between("${attribute}", ${Query.parseValues(start)}, ${Query.parseValues(end)})`;
63
+ Query.startsWith = (attribute, value) => Query.addQuery(attribute, "startsWith", value);
64
+ Query.endsWith = (attribute, value) => Query.addQuery(attribute, "endsWith", value);
65
+ Query.select = (attributes) => `select([${attributes.map((attr) => `"${attr}"`).join(",")}])`;
66
+ Query.search = (attribute, value) => Query.addQuery(attribute, "search", value);
67
+ Query.orderDesc = (attribute) => `orderDesc("${attribute}")`;
68
+ Query.orderAsc = (attribute) => `orderAsc("${attribute}")`;
69
+ Query.cursorAfter = (documentId) => `cursorAfter("${documentId}")`;
70
+ Query.cursorBefore = (documentId) => `cursorBefore("${documentId}")`;
71
+ Query.limit = (limit) => `limit(${limit})`;
72
+ Query.offset = (offset) => `offset(${offset})`;
73
+ Query.addQuery = (attribute, method, value) => value instanceof Array
74
+ ? `${method}("${attribute}", [${value
75
+ .map((v) => Query.parseValues(v))
76
+ .join(",")}])`
77
+ : `${method}("${attribute}", [${Query.parseValues(value)}])`;
78
+ Query.parseValues = (value) => typeof value === "string" || value instanceof String
79
+ ? `"${value}"`
80
+ : `${value}`;
81
+
82
+ class AppwriteException extends Error {
83
+ constructor(message, code = 0, type = '', response = '') {
84
+ super(message);
85
+ this.name = 'AppwriteException';
86
+ this.message = message;
87
+ this.code = code;
88
+ this.type = type;
89
+ this.response = response;
90
+ }
91
+ }
92
+ class Client {
93
+ constructor() {
94
+ this.config = {
95
+ endpoint: 'https://HOSTNAME/v1',
96
+ endpointRealtime: '',
97
+ project: '',
98
+ jwt: '',
99
+ locale: '',
100
+ platform: '',
101
+ };
102
+ this.headers = {
103
+ 'x-sdk-name': 'Web',
104
+ 'x-sdk-platform': 'client',
105
+ 'x-sdk-language': 'web',
106
+ 'x-sdk-version': '13.0.2',
107
+ 'X-Appwrite-Response-Format': '1.4.0',
108
+ };
109
+ this.realtime = {
110
+ socket: undefined,
111
+ timeout: undefined,
112
+ url: '',
113
+ channels: new Set(),
114
+ subscriptions: new Map(),
115
+ subscriptionsCounter: 0,
116
+ reconnect: true,
117
+ reconnectAttempts: 0,
118
+ lastMessage: undefined,
119
+ connect: () => {
120
+ clearTimeout(this.realtime.timeout);
121
+ this.realtime.timeout = window === null || window === void 0 ? void 0 : window.setTimeout(() => {
122
+ this.realtime.createSocket();
123
+ }, 50);
124
+ },
125
+ getTimeout: () => {
126
+ switch (true) {
127
+ case this.realtime.reconnectAttempts < 5:
128
+ return 1000;
129
+ case this.realtime.reconnectAttempts < 15:
130
+ return 5000;
131
+ case this.realtime.reconnectAttempts < 100:
132
+ return 10000;
133
+ default:
134
+ return 60000;
135
+ }
136
+ },
137
+ createSocket: () => {
138
+ var _a, _b;
139
+ if (this.realtime.channels.size < 1)
140
+ return;
141
+ const channels = new URLSearchParams();
142
+ channels.set('project', this.config.project);
143
+ this.realtime.channels.forEach(channel => {
144
+ channels.append('channels[]', channel);
145
+ });
146
+ const url = this.config.endpointRealtime + '/realtime?' + channels.toString();
147
+ if (url !== this.realtime.url || // Check if URL is present
148
+ !this.realtime.socket || // Check if WebSocket has not been created
149
+ ((_a = this.realtime.socket) === null || _a === void 0 ? void 0 : _a.readyState) > WebSocket.OPEN // Check if WebSocket is CLOSING (3) or CLOSED (4)
150
+ ) {
151
+ if (this.realtime.socket &&
152
+ ((_b = this.realtime.socket) === null || _b === void 0 ? void 0 : _b.readyState) < WebSocket.CLOSING // Close WebSocket if it is CONNECTING (0) or OPEN (1)
153
+ ) {
154
+ this.realtime.reconnect = false;
155
+ this.realtime.socket.close();
156
+ }
157
+ this.realtime.url = url;
158
+ // @ts-ignore
159
+ this.realtime.socket = new WebSocket(url, undefined, {
160
+ headers: {
161
+ Origin: `appwrite-${Platform.OS}://${this.config.platform}`
162
+ }
163
+ });
164
+ this.realtime.socket.addEventListener('message', this.realtime.onMessage);
165
+ this.realtime.socket.addEventListener('open', _event => {
166
+ this.realtime.reconnectAttempts = 0;
167
+ });
168
+ this.realtime.socket.addEventListener('close', event => {
169
+ var _a, _b, _c;
170
+ if (!this.realtime.reconnect ||
171
+ (((_b = (_a = this.realtime) === null || _a === void 0 ? void 0 : _a.lastMessage) === null || _b === void 0 ? void 0 : _b.type) === 'error' && // Check if last message was of type error
172
+ ((_c = this.realtime) === null || _c === void 0 ? void 0 : _c.lastMessage.data).code === 1008 // Check for policy violation 1008
173
+ )) {
174
+ this.realtime.reconnect = true;
175
+ return;
176
+ }
177
+ const timeout = this.realtime.getTimeout();
178
+ console.error(`Realtime got disconnected. Reconnect will be attempted in ${timeout / 1000} seconds.`, event.reason);
179
+ setTimeout(() => {
180
+ this.realtime.reconnectAttempts++;
181
+ this.realtime.createSocket();
182
+ }, timeout);
183
+ });
184
+ }
185
+ },
186
+ onMessage: (event) => __awaiter(this, void 0, void 0, function* () {
187
+ try {
188
+ const message = JSON.parse(event.data);
189
+ this.realtime.lastMessage = message;
190
+ switch (message.type) {
191
+ case 'event':
192
+ let data = message.data;
193
+ if (data === null || data === void 0 ? void 0 : data.channels) {
194
+ const isSubscribed = data.channels.some(channel => this.realtime.channels.has(channel));
195
+ if (!isSubscribed)
196
+ return;
197
+ this.realtime.subscriptions.forEach(subscription => {
198
+ if (data.channels.some(channel => subscription.channels.includes(channel))) {
199
+ setTimeout(() => subscription.callback(data));
200
+ }
201
+ });
202
+ }
203
+ break;
204
+ case 'error':
205
+ throw message.data;
206
+ default:
207
+ break;
208
+ }
209
+ }
210
+ catch (e) {
211
+ console.error(e);
212
+ }
213
+ }),
214
+ cleanUp: channels => {
215
+ this.realtime.channels.forEach(channel => {
216
+ if (channels.includes(channel)) {
217
+ let found = Array.from(this.realtime.subscriptions).some(([_key, subscription]) => {
218
+ return subscription.channels.includes(channel);
219
+ });
220
+ if (!found) {
221
+ this.realtime.channels.delete(channel);
222
+ }
223
+ }
224
+ });
225
+ }
226
+ };
227
+ }
228
+ /**
229
+ * Set Endpoint
230
+ *
231
+ * Your project endpoint
232
+ *
233
+ * @param {string} endpoint
234
+ *
235
+ * @returns {this}
236
+ */
237
+ setEndpoint(endpoint) {
238
+ this.config.endpoint = endpoint;
239
+ this.config.endpointRealtime = this.config.endpointRealtime || this.config.endpoint.replace('https://', 'wss://').replace('http://', 'ws://');
240
+ return this;
241
+ }
242
+ /**
243
+ * Set Realtime Endpoint
244
+ *
245
+ * @param {string} endpointRealtime
246
+ *
247
+ * @returns {this}
248
+ */
249
+ setEndpointRealtime(endpointRealtime) {
250
+ this.config.endpointRealtime = endpointRealtime;
251
+ return this;
252
+ }
253
+ /**
254
+ * Set platform
255
+ *
256
+ * Set platform. Will be used as origin for all requests.
257
+ *
258
+ * @param {string} platform
259
+ * @returns {this}
260
+ */
261
+ setPlatform(platform) {
262
+ this.config.platform = platform;
263
+ return this;
264
+ }
265
+ /**
266
+ * Set Project
267
+ *
268
+ * Your project ID
269
+ *
270
+ * @param value string
271
+ *
272
+ * @return {this}
273
+ */
274
+ setProject(value) {
275
+ this.headers['X-Appwrite-Project'] = value;
276
+ this.config.project = value;
277
+ return this;
278
+ }
279
+ /**
280
+ * Set JWT
281
+ *
282
+ * Your secret JSON Web Token
283
+ *
284
+ * @param value string
285
+ *
286
+ * @return {this}
287
+ */
288
+ setJWT(value) {
289
+ this.headers['X-Appwrite-JWT'] = value;
290
+ this.config.jwt = value;
291
+ return this;
292
+ }
293
+ /**
294
+ * Set Locale
295
+ *
296
+ * @param value string
297
+ *
298
+ * @return {this}
299
+ */
300
+ setLocale(value) {
301
+ this.headers['X-Appwrite-Locale'] = value;
302
+ this.config.locale = value;
303
+ return this;
304
+ }
305
+ /**
306
+ * Subscribes to Appwrite events and passes you the payload in realtime.
307
+ *
308
+ * @param {string|string[]} channels
309
+ * Channel to subscribe - pass a single channel as a string or multiple with an array of strings.
310
+ *
311
+ * Possible channels are:
312
+ * - account
313
+ * - collections
314
+ * - collections.[ID]
315
+ * - collections.[ID].documents
316
+ * - documents
317
+ * - documents.[ID]
318
+ * - files
319
+ * - files.[ID]
320
+ * - executions
321
+ * - executions.[ID]
322
+ * - functions.[ID]
323
+ * - teams
324
+ * - teams.[ID]
325
+ * - memberships
326
+ * - memberships.[ID]
327
+ * @param {(payload: RealtimeMessage) => void} callback Is called on every realtime update.
328
+ * @returns {() => void} Unsubscribes from events.
329
+ */
330
+ subscribe(channels, callback) {
331
+ let channelArray = typeof channels === 'string' ? [channels] : channels;
332
+ channelArray.forEach(channel => this.realtime.channels.add(channel));
333
+ const counter = this.realtime.subscriptionsCounter++;
334
+ this.realtime.subscriptions.set(counter, {
335
+ channels: channelArray,
336
+ callback
337
+ });
338
+ this.realtime.connect();
339
+ return () => {
340
+ this.realtime.subscriptions.delete(counter);
341
+ this.realtime.cleanUp(channelArray);
342
+ this.realtime.connect();
343
+ };
344
+ }
345
+ call(method, url, headers = {}, params = {}) {
346
+ var _a;
347
+ return __awaiter(this, void 0, void 0, function* () {
348
+ method = method.toUpperCase();
349
+ headers = Object.assign({}, this.headers, headers);
350
+ headers.Origin = `appwrite-${Platform.OS}://${this.config.platform}`;
351
+ let options = {
352
+ method,
353
+ headers,
354
+ credentials: 'include'
355
+ };
356
+ if (method === 'GET') {
357
+ for (const [key, value] of Object.entries(Service.flatten(params))) {
358
+ url.searchParams.append(key, value);
359
+ }
360
+ }
361
+ else {
362
+ switch (headers['content-type']) {
363
+ case 'application/json':
364
+ options.body = JSON.stringify(params);
365
+ break;
366
+ case 'multipart/form-data':
367
+ let formData = new FormData();
368
+ for (const key in params) {
369
+ if (Array.isArray(params[key])) {
370
+ params[key].forEach((value) => {
371
+ formData.append(key + '[]', value);
372
+ });
373
+ }
374
+ else {
375
+ formData.append(key, params[key]);
376
+ }
377
+ }
378
+ options.body = formData;
379
+ delete headers['content-type'];
380
+ break;
381
+ }
382
+ }
383
+ try {
384
+ let data = null;
385
+ const response = yield fetch(url.toString(), options);
386
+ if ((_a = response.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.includes('application/json')) {
387
+ data = yield response.json();
388
+ }
389
+ else {
390
+ data = {
391
+ message: yield response.text()
392
+ };
393
+ }
394
+ if (400 <= response.status) {
395
+ throw new AppwriteException(data === null || data === void 0 ? void 0 : data.message, response.status, data === null || data === void 0 ? void 0 : data.type, data);
396
+ }
397
+ return data;
398
+ }
399
+ catch (e) {
400
+ if (e instanceof AppwriteException) {
401
+ throw e;
402
+ }
403
+ throw new AppwriteException(e.message);
404
+ }
405
+ });
406
+ }
407
+ }
408
+
409
+ class Account extends Service {
410
+ constructor(client) {
411
+ super(client);
412
+ }
413
+ /**
414
+ * Get account
415
+ *
416
+ * Get the currently logged in user.
417
+ *
418
+ * @throws {AppwriteException}
419
+ * @returns {Promise}
420
+ */
421
+ get() {
422
+ return __awaiter(this, void 0, void 0, function* () {
423
+ const apiPath = '/account';
424
+ const payload = {};
425
+ const uri = new URL(this.client.config.endpoint + apiPath);
426
+ return yield this.client.call('get', uri, {
427
+ 'content-type': 'application/json',
428
+ }, payload);
429
+ });
430
+ }
431
+ /**
432
+ * Create account
433
+ *
434
+ * Use this endpoint to allow a new user to register a new account in your
435
+ * project. After the user registration completes successfully, you can use
436
+ * the
437
+ * [/account/verfication](https://appwrite.io/docs/references/cloud/client-web/account#createVerification)
438
+ * route to start verifying the user email address. To allow the new user to
439
+ * login to their new account, you need to create a new [account
440
+ * session](https://appwrite.io/docs/references/cloud/client-web/account#createEmailSession).
441
+ *
442
+ * @param {string} userId
443
+ * @param {string} email
444
+ * @param {string} password
445
+ * @param {string} name
446
+ * @throws {AppwriteException}
447
+ * @returns {Promise}
448
+ */
449
+ create(userId, email, password, name) {
450
+ return __awaiter(this, void 0, void 0, function* () {
451
+ if (typeof userId === 'undefined') {
452
+ throw new AppwriteException('Missing required parameter: "userId"');
453
+ }
454
+ if (typeof email === 'undefined') {
455
+ throw new AppwriteException('Missing required parameter: "email"');
456
+ }
457
+ if (typeof password === 'undefined') {
458
+ throw new AppwriteException('Missing required parameter: "password"');
459
+ }
460
+ const apiPath = '/account';
461
+ const payload = {};
462
+ if (typeof userId !== 'undefined') {
463
+ payload['userId'] = userId;
464
+ }
465
+ if (typeof email !== 'undefined') {
466
+ payload['email'] = email;
467
+ }
468
+ if (typeof password !== 'undefined') {
469
+ payload['password'] = password;
470
+ }
471
+ if (typeof name !== 'undefined') {
472
+ payload['name'] = name;
473
+ }
474
+ const uri = new URL(this.client.config.endpoint + apiPath);
475
+ return yield this.client.call('post', uri, {
476
+ 'content-type': 'application/json',
477
+ }, payload);
478
+ });
479
+ }
480
+ /**
481
+ * Update email
482
+ *
483
+ * Update currently logged in user account email address. After changing user
484
+ * address, the user confirmation status will get reset. A new confirmation
485
+ * email is not sent automatically however you can use the send confirmation
486
+ * email endpoint again to send the confirmation email. For security measures,
487
+ * user password is required to complete this request.
488
+ * This endpoint can also be used to convert an anonymous account to a normal
489
+ * one, by passing an email address and a new password.
490
+ *
491
+ *
492
+ * @param {string} email
493
+ * @param {string} password
494
+ * @throws {AppwriteException}
495
+ * @returns {Promise}
496
+ */
497
+ updateEmail(email, password) {
498
+ return __awaiter(this, void 0, void 0, function* () {
499
+ if (typeof email === 'undefined') {
500
+ throw new AppwriteException('Missing required parameter: "email"');
501
+ }
502
+ if (typeof password === 'undefined') {
503
+ throw new AppwriteException('Missing required parameter: "password"');
504
+ }
505
+ const apiPath = '/account/email';
506
+ const payload = {};
507
+ if (typeof email !== 'undefined') {
508
+ payload['email'] = email;
509
+ }
510
+ if (typeof password !== 'undefined') {
511
+ payload['password'] = password;
512
+ }
513
+ const uri = new URL(this.client.config.endpoint + apiPath);
514
+ return yield this.client.call('patch', uri, {
515
+ 'content-type': 'application/json',
516
+ }, payload);
517
+ });
518
+ }
519
+ /**
520
+ * List Identities
521
+ *
522
+ * Get the list of identities for the currently logged in user.
523
+ *
524
+ * @param {string} queries
525
+ * @throws {AppwriteException}
526
+ * @returns {Promise}
527
+ */
528
+ listIdentities(queries) {
529
+ return __awaiter(this, void 0, void 0, function* () {
530
+ const apiPath = '/account/identities';
531
+ const payload = {};
532
+ if (typeof queries !== 'undefined') {
533
+ payload['queries'] = queries;
534
+ }
535
+ const uri = new URL(this.client.config.endpoint + apiPath);
536
+ return yield this.client.call('get', uri, {
537
+ 'content-type': 'application/json',
538
+ }, payload);
539
+ });
540
+ }
541
+ /**
542
+ * Delete Identity
543
+ *
544
+ * Delete an identity by its unique ID.
545
+ *
546
+ * @param {string} identityId
547
+ * @throws {AppwriteException}
548
+ * @returns {Promise}
549
+ */
550
+ deleteIdentity(identityId) {
551
+ return __awaiter(this, void 0, void 0, function* () {
552
+ if (typeof identityId === 'undefined') {
553
+ throw new AppwriteException('Missing required parameter: "identityId"');
554
+ }
555
+ const apiPath = '/account/identities/{identityId}'.replace('{identityId}', identityId);
556
+ const payload = {};
557
+ const uri = new URL(this.client.config.endpoint + apiPath);
558
+ return yield this.client.call('delete', uri, {
559
+ 'content-type': 'application/json',
560
+ }, payload);
561
+ });
562
+ }
563
+ /**
564
+ * Create JWT
565
+ *
566
+ * Use this endpoint to create a JSON Web Token. You can use the resulting JWT
567
+ * to authenticate on behalf of the current user when working with the
568
+ * Appwrite server-side API and SDKs. The JWT secret is valid for 15 minutes
569
+ * from its creation and will be invalid if the user will logout in that time
570
+ * frame.
571
+ *
572
+ * @throws {AppwriteException}
573
+ * @returns {Promise}
574
+ */
575
+ createJWT() {
576
+ return __awaiter(this, void 0, void 0, function* () {
577
+ const apiPath = '/account/jwt';
578
+ const payload = {};
579
+ const uri = new URL(this.client.config.endpoint + apiPath);
580
+ return yield this.client.call('post', uri, {
581
+ 'content-type': 'application/json',
582
+ }, payload);
583
+ });
584
+ }
585
+ /**
586
+ * List logs
587
+ *
588
+ * Get the list of latest security activity logs for the currently logged in
589
+ * user. Each log returns user IP address, location and date and time of log.
590
+ *
591
+ * @param {string[]} queries
592
+ * @throws {AppwriteException}
593
+ * @returns {Promise}
594
+ */
595
+ listLogs(queries) {
596
+ return __awaiter(this, void 0, void 0, function* () {
597
+ const apiPath = '/account/logs';
598
+ const payload = {};
599
+ if (typeof queries !== 'undefined') {
600
+ payload['queries'] = queries;
601
+ }
602
+ const uri = new URL(this.client.config.endpoint + apiPath);
603
+ return yield this.client.call('get', uri, {
604
+ 'content-type': 'application/json',
605
+ }, payload);
606
+ });
607
+ }
608
+ /**
609
+ * Update name
610
+ *
611
+ * Update currently logged in user account name.
612
+ *
613
+ * @param {string} name
614
+ * @throws {AppwriteException}
615
+ * @returns {Promise}
616
+ */
617
+ updateName(name) {
618
+ return __awaiter(this, void 0, void 0, function* () {
619
+ if (typeof name === 'undefined') {
620
+ throw new AppwriteException('Missing required parameter: "name"');
621
+ }
622
+ const apiPath = '/account/name';
623
+ const payload = {};
624
+ if (typeof name !== 'undefined') {
625
+ payload['name'] = name;
626
+ }
627
+ const uri = new URL(this.client.config.endpoint + apiPath);
628
+ return yield this.client.call('patch', uri, {
629
+ 'content-type': 'application/json',
630
+ }, payload);
631
+ });
632
+ }
633
+ /**
634
+ * Update password
635
+ *
636
+ * Update currently logged in user password. For validation, user is required
637
+ * to pass in the new password, and the old password. For users created with
638
+ * OAuth, Team Invites and Magic URL, oldPassword is optional.
639
+ *
640
+ * @param {string} password
641
+ * @param {string} oldPassword
642
+ * @throws {AppwriteException}
643
+ * @returns {Promise}
644
+ */
645
+ updatePassword(password, oldPassword) {
646
+ return __awaiter(this, void 0, void 0, function* () {
647
+ if (typeof password === 'undefined') {
648
+ throw new AppwriteException('Missing required parameter: "password"');
649
+ }
650
+ const apiPath = '/account/password';
651
+ const payload = {};
652
+ if (typeof password !== 'undefined') {
653
+ payload['password'] = password;
654
+ }
655
+ if (typeof oldPassword !== 'undefined') {
656
+ payload['oldPassword'] = oldPassword;
657
+ }
658
+ const uri = new URL(this.client.config.endpoint + apiPath);
659
+ return yield this.client.call('patch', uri, {
660
+ 'content-type': 'application/json',
661
+ }, payload);
662
+ });
663
+ }
664
+ /**
665
+ * Update phone
666
+ *
667
+ * Update the currently logged in user's phone number. After updating the
668
+ * phone number, the phone verification status will be reset. A confirmation
669
+ * SMS is not sent automatically, however you can use the [POST
670
+ * /account/verification/phone](https://appwrite.io/docs/references/cloud/client-web/account#createPhoneVerification)
671
+ * endpoint to send a confirmation SMS.
672
+ *
673
+ * @param {string} phone
674
+ * @param {string} password
675
+ * @throws {AppwriteException}
676
+ * @returns {Promise}
677
+ */
678
+ updatePhone(phone, password) {
679
+ return __awaiter(this, void 0, void 0, function* () {
680
+ if (typeof phone === 'undefined') {
681
+ throw new AppwriteException('Missing required parameter: "phone"');
682
+ }
683
+ if (typeof password === 'undefined') {
684
+ throw new AppwriteException('Missing required parameter: "password"');
685
+ }
686
+ const apiPath = '/account/phone';
687
+ const payload = {};
688
+ if (typeof phone !== 'undefined') {
689
+ payload['phone'] = phone;
690
+ }
691
+ if (typeof password !== 'undefined') {
692
+ payload['password'] = password;
693
+ }
694
+ const uri = new URL(this.client.config.endpoint + apiPath);
695
+ return yield this.client.call('patch', uri, {
696
+ 'content-type': 'application/json',
697
+ }, payload);
698
+ });
699
+ }
700
+ /**
701
+ * Get account preferences
702
+ *
703
+ * Get the preferences as a key-value object for the currently logged in user.
704
+ *
705
+ * @throws {AppwriteException}
706
+ * @returns {Promise}
707
+ */
708
+ getPrefs() {
709
+ return __awaiter(this, void 0, void 0, function* () {
710
+ const apiPath = '/account/prefs';
711
+ const payload = {};
712
+ const uri = new URL(this.client.config.endpoint + apiPath);
713
+ return yield this.client.call('get', uri, {
714
+ 'content-type': 'application/json',
715
+ }, payload);
716
+ });
717
+ }
718
+ /**
719
+ * Update preferences
720
+ *
721
+ * Update currently logged in user account preferences. The object you pass is
722
+ * stored as is, and replaces any previous value. The maximum allowed prefs
723
+ * size is 64kB and throws error if exceeded.
724
+ *
725
+ * @param {Partial<Preferences>} prefs
726
+ * @throws {AppwriteException}
727
+ * @returns {Promise}
728
+ */
729
+ updatePrefs(prefs) {
730
+ return __awaiter(this, void 0, void 0, function* () {
731
+ if (typeof prefs === 'undefined') {
732
+ throw new AppwriteException('Missing required parameter: "prefs"');
733
+ }
734
+ const apiPath = '/account/prefs';
735
+ const payload = {};
736
+ if (typeof prefs !== 'undefined') {
737
+ payload['prefs'] = prefs;
738
+ }
739
+ const uri = new URL(this.client.config.endpoint + apiPath);
740
+ return yield this.client.call('patch', uri, {
741
+ 'content-type': 'application/json',
742
+ }, payload);
743
+ });
744
+ }
745
+ /**
746
+ * Create password recovery
747
+ *
748
+ * Sends the user an email with a temporary secret key for password reset.
749
+ * When the user clicks the confirmation link he is redirected back to your
750
+ * app password reset URL with the secret key and email address values
751
+ * attached to the URL query string. Use the query string params to submit a
752
+ * request to the [PUT
753
+ * /account/recovery](https://appwrite.io/docs/references/cloud/client-web/account#updateRecovery)
754
+ * endpoint to complete the process. The verification link sent to the user's
755
+ * email address is valid for 1 hour.
756
+ *
757
+ * @param {string} email
758
+ * @param {string} url
759
+ * @throws {AppwriteException}
760
+ * @returns {Promise}
761
+ */
762
+ createRecovery(email, url) {
763
+ return __awaiter(this, void 0, void 0, function* () {
764
+ if (typeof email === 'undefined') {
765
+ throw new AppwriteException('Missing required parameter: "email"');
766
+ }
767
+ if (typeof url === 'undefined') {
768
+ throw new AppwriteException('Missing required parameter: "url"');
769
+ }
770
+ const apiPath = '/account/recovery';
771
+ const payload = {};
772
+ if (typeof email !== 'undefined') {
773
+ payload['email'] = email;
774
+ }
775
+ if (typeof url !== 'undefined') {
776
+ payload['url'] = url;
777
+ }
778
+ const uri = new URL(this.client.config.endpoint + apiPath);
779
+ return yield this.client.call('post', uri, {
780
+ 'content-type': 'application/json',
781
+ }, payload);
782
+ });
783
+ }
784
+ /**
785
+ * Create password recovery (confirmation)
786
+ *
787
+ * Use this endpoint to complete the user account password reset. Both the
788
+ * **userId** and **secret** arguments will be passed as query parameters to
789
+ * the redirect URL you have provided when sending your request to the [POST
790
+ * /account/recovery](https://appwrite.io/docs/references/cloud/client-web/account#createRecovery)
791
+ * endpoint.
792
+ *
793
+ * Please note that in order to avoid a [Redirect
794
+ * Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md)
795
+ * the only valid redirect URLs are the ones from domains you have set when
796
+ * adding your platforms in the console interface.
797
+ *
798
+ * @param {string} userId
799
+ * @param {string} secret
800
+ * @param {string} password
801
+ * @param {string} passwordAgain
802
+ * @throws {AppwriteException}
803
+ * @returns {Promise}
804
+ */
805
+ updateRecovery(userId, secret, password, passwordAgain) {
806
+ return __awaiter(this, void 0, void 0, function* () {
807
+ if (typeof userId === 'undefined') {
808
+ throw new AppwriteException('Missing required parameter: "userId"');
809
+ }
810
+ if (typeof secret === 'undefined') {
811
+ throw new AppwriteException('Missing required parameter: "secret"');
812
+ }
813
+ if (typeof password === 'undefined') {
814
+ throw new AppwriteException('Missing required parameter: "password"');
815
+ }
816
+ if (typeof passwordAgain === 'undefined') {
817
+ throw new AppwriteException('Missing required parameter: "passwordAgain"');
818
+ }
819
+ const apiPath = '/account/recovery';
820
+ const payload = {};
821
+ if (typeof userId !== 'undefined') {
822
+ payload['userId'] = userId;
823
+ }
824
+ if (typeof secret !== 'undefined') {
825
+ payload['secret'] = secret;
826
+ }
827
+ if (typeof password !== 'undefined') {
828
+ payload['password'] = password;
829
+ }
830
+ if (typeof passwordAgain !== 'undefined') {
831
+ payload['passwordAgain'] = passwordAgain;
832
+ }
833
+ const uri = new URL(this.client.config.endpoint + apiPath);
834
+ return yield this.client.call('put', uri, {
835
+ 'content-type': 'application/json',
836
+ }, payload);
837
+ });
838
+ }
839
+ /**
840
+ * List sessions
841
+ *
842
+ * Get the list of active sessions across different devices for the currently
843
+ * logged in user.
844
+ *
845
+ * @throws {AppwriteException}
846
+ * @returns {Promise}
847
+ */
848
+ listSessions() {
849
+ return __awaiter(this, void 0, void 0, function* () {
850
+ const apiPath = '/account/sessions';
851
+ const payload = {};
852
+ const uri = new URL(this.client.config.endpoint + apiPath);
853
+ return yield this.client.call('get', uri, {
854
+ 'content-type': 'application/json',
855
+ }, payload);
856
+ });
857
+ }
858
+ /**
859
+ * Delete sessions
860
+ *
861
+ * Delete all sessions from the user account and remove any sessions cookies
862
+ * from the end client.
863
+ *
864
+ * @throws {AppwriteException}
865
+ * @returns {Promise}
866
+ */
867
+ deleteSessions() {
868
+ return __awaiter(this, void 0, void 0, function* () {
869
+ const apiPath = '/account/sessions';
870
+ const payload = {};
871
+ const uri = new URL(this.client.config.endpoint + apiPath);
872
+ return yield this.client.call('delete', uri, {
873
+ 'content-type': 'application/json',
874
+ }, payload);
875
+ });
876
+ }
877
+ /**
878
+ * Create anonymous session
879
+ *
880
+ * Use this endpoint to allow a new user to register an anonymous account in
881
+ * your project. This route will also create a new session for the user. To
882
+ * allow the new user to convert an anonymous account to a normal account, you
883
+ * need to update its [email and
884
+ * password](https://appwrite.io/docs/references/cloud/client-web/account#updateEmail)
885
+ * or create an [OAuth2
886
+ * session](https://appwrite.io/docs/references/cloud/client-web/account#CreateOAuth2Session).
887
+ *
888
+ * @throws {AppwriteException}
889
+ * @returns {Promise}
890
+ */
891
+ createAnonymousSession() {
892
+ return __awaiter(this, void 0, void 0, function* () {
893
+ const apiPath = '/account/sessions/anonymous';
894
+ const payload = {};
895
+ const uri = new URL(this.client.config.endpoint + apiPath);
896
+ return yield this.client.call('post', uri, {
897
+ 'content-type': 'application/json',
898
+ }, payload);
899
+ });
900
+ }
901
+ /**
902
+ * Create email session
903
+ *
904
+ * Allow the user to login into their account by providing a valid email and
905
+ * password combination. This route will create a new session for the user.
906
+ *
907
+ * A user is limited to 10 active sessions at a time by default. [Learn more
908
+ * about session
909
+ * limits](https://appwrite.io/docs/authentication-security#limits).
910
+ *
911
+ * @param {string} email
912
+ * @param {string} password
913
+ * @throws {AppwriteException}
914
+ * @returns {Promise}
915
+ */
916
+ createEmailSession(email, password) {
917
+ return __awaiter(this, void 0, void 0, function* () {
918
+ if (typeof email === 'undefined') {
919
+ throw new AppwriteException('Missing required parameter: "email"');
920
+ }
921
+ if (typeof password === 'undefined') {
922
+ throw new AppwriteException('Missing required parameter: "password"');
923
+ }
924
+ const apiPath = '/account/sessions/email';
925
+ const payload = {};
926
+ if (typeof email !== 'undefined') {
927
+ payload['email'] = email;
928
+ }
929
+ if (typeof password !== 'undefined') {
930
+ payload['password'] = password;
931
+ }
932
+ const uri = new URL(this.client.config.endpoint + apiPath);
933
+ return yield this.client.call('post', uri, {
934
+ 'content-type': 'application/json',
935
+ }, payload);
936
+ });
937
+ }
938
+ /**
939
+ * Create magic URL session
940
+ *
941
+ * Sends the user an email with a secret key for creating a session. If the
942
+ * provided user ID has not been registered, a new user will be created. When
943
+ * the user clicks the link in the email, the user is redirected back to the
944
+ * URL you provided with the secret key and userId values attached to the URL
945
+ * query string. Use the query string parameters to submit a request to the
946
+ * [PUT
947
+ * /account/sessions/magic-url](https://appwrite.io/docs/references/cloud/client-web/account#updateMagicURLSession)
948
+ * endpoint to complete the login process. The link sent to the user's email
949
+ * address is valid for 1 hour. If you are on a mobile device you can leave
950
+ * the URL parameter empty, so that the login completion will be handled by
951
+ * your Appwrite instance by default.
952
+ *
953
+ * A user is limited to 10 active sessions at a time by default. [Learn more
954
+ * about session
955
+ * limits](https://appwrite.io/docs/authentication-security#limits).
956
+ *
957
+ *
958
+ * @param {string} userId
959
+ * @param {string} email
960
+ * @param {string} url
961
+ * @throws {AppwriteException}
962
+ * @returns {Promise}
963
+ */
964
+ createMagicURLSession(userId, email, url) {
965
+ return __awaiter(this, void 0, void 0, function* () {
966
+ if (typeof userId === 'undefined') {
967
+ throw new AppwriteException('Missing required parameter: "userId"');
968
+ }
969
+ if (typeof email === 'undefined') {
970
+ throw new AppwriteException('Missing required parameter: "email"');
971
+ }
972
+ const apiPath = '/account/sessions/magic-url';
973
+ const payload = {};
974
+ if (typeof userId !== 'undefined') {
975
+ payload['userId'] = userId;
976
+ }
977
+ if (typeof email !== 'undefined') {
978
+ payload['email'] = email;
979
+ }
980
+ if (typeof url !== 'undefined') {
981
+ payload['url'] = url;
982
+ }
983
+ const uri = new URL(this.client.config.endpoint + apiPath);
984
+ return yield this.client.call('post', uri, {
985
+ 'content-type': 'application/json',
986
+ }, payload);
987
+ });
988
+ }
989
+ /**
990
+ * Create magic URL session (confirmation)
991
+ *
992
+ * Use this endpoint to complete creating the session with the Magic URL. Both
993
+ * the **userId** and **secret** arguments will be passed as query parameters
994
+ * to the redirect URL you have provided when sending your request to the
995
+ * [POST
996
+ * /account/sessions/magic-url](https://appwrite.io/docs/references/cloud/client-web/account#createMagicURLSession)
997
+ * endpoint.
998
+ *
999
+ * Please note that in order to avoid a [Redirect
1000
+ * Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md)
1001
+ * the only valid redirect URLs are the ones from domains you have set when
1002
+ * adding your platforms in the console interface.
1003
+ *
1004
+ * @param {string} userId
1005
+ * @param {string} secret
1006
+ * @throws {AppwriteException}
1007
+ * @returns {Promise}
1008
+ */
1009
+ updateMagicURLSession(userId, secret) {
1010
+ return __awaiter(this, void 0, void 0, function* () {
1011
+ if (typeof userId === 'undefined') {
1012
+ throw new AppwriteException('Missing required parameter: "userId"');
1013
+ }
1014
+ if (typeof secret === 'undefined') {
1015
+ throw new AppwriteException('Missing required parameter: "secret"');
1016
+ }
1017
+ const apiPath = '/account/sessions/magic-url';
1018
+ const payload = {};
1019
+ if (typeof userId !== 'undefined') {
1020
+ payload['userId'] = userId;
1021
+ }
1022
+ if (typeof secret !== 'undefined') {
1023
+ payload['secret'] = secret;
1024
+ }
1025
+ const uri = new URL(this.client.config.endpoint + apiPath);
1026
+ return yield this.client.call('put', uri, {
1027
+ 'content-type': 'application/json',
1028
+ }, payload);
1029
+ });
1030
+ }
1031
+ /**
1032
+ * Create OAuth2 session
1033
+ *
1034
+ * Allow the user to login to their account using the OAuth2 provider of their
1035
+ * choice. Each OAuth2 provider should be enabled from the Appwrite console
1036
+ * first. Use the success and failure arguments to provide a redirect URL's
1037
+ * back to your app when login is completed.
1038
+ *
1039
+ * If there is already an active session, the new session will be attached to
1040
+ * the logged-in account. If there are no active sessions, the server will
1041
+ * attempt to look for a user with the same email address as the email
1042
+ * received from the OAuth2 provider and attach the new session to the
1043
+ * existing user. If no matching user is found - the server will create a new
1044
+ * user.
1045
+ *
1046
+ * A user is limited to 10 active sessions at a time by default. [Learn more
1047
+ * about session
1048
+ * limits](https://appwrite.io/docs/authentication-security#limits).
1049
+ *
1050
+ *
1051
+ * @param {string} provider
1052
+ * @param {string} success
1053
+ * @param {string} failure
1054
+ * @param {string[]} scopes
1055
+ * @throws {AppwriteException}
1056
+ * @returns {void|string}
1057
+ */
1058
+ createOAuth2Session(provider, success, failure, scopes) {
1059
+ if (typeof provider === 'undefined') {
1060
+ throw new AppwriteException('Missing required parameter: "provider"');
1061
+ }
1062
+ const apiPath = '/account/sessions/oauth2/{provider}'.replace('{provider}', provider);
1063
+ const payload = {};
1064
+ if (typeof success !== 'undefined') {
1065
+ payload['success'] = success;
1066
+ }
1067
+ if (typeof failure !== 'undefined') {
1068
+ payload['failure'] = failure;
1069
+ }
1070
+ if (typeof scopes !== 'undefined') {
1071
+ payload['scopes'] = scopes;
1072
+ }
1073
+ const uri = new URL(this.client.config.endpoint + apiPath);
1074
+ payload['project'] = this.client.config.project;
1075
+ for (const [key, value] of Object.entries(Service.flatten(payload))) {
1076
+ uri.searchParams.append(key, value);
1077
+ }
1078
+ if (typeof window !== 'undefined' && (window === null || window === void 0 ? void 0 : window.location)) {
1079
+ window.location.href = uri.toString();
1080
+ }
1081
+ else {
1082
+ return uri;
1083
+ }
1084
+ }
1085
+ /**
1086
+ * Create phone session
1087
+ *
1088
+ * Sends the user an SMS with a secret key for creating a session. If the
1089
+ * provided user ID has not be registered, a new user will be created. Use the
1090
+ * returned user ID and secret and submit a request to the [PUT
1091
+ * /account/sessions/phone](https://appwrite.io/docs/references/cloud/client-web/account#updatePhoneSession)
1092
+ * endpoint to complete the login process. The secret sent to the user's phone
1093
+ * is valid for 15 minutes.
1094
+ *
1095
+ * A user is limited to 10 active sessions at a time by default. [Learn more
1096
+ * about session
1097
+ * limits](https://appwrite.io/docs/authentication-security#limits).
1098
+ *
1099
+ * @param {string} userId
1100
+ * @param {string} phone
1101
+ * @throws {AppwriteException}
1102
+ * @returns {Promise}
1103
+ */
1104
+ createPhoneSession(userId, phone) {
1105
+ return __awaiter(this, void 0, void 0, function* () {
1106
+ if (typeof userId === 'undefined') {
1107
+ throw new AppwriteException('Missing required parameter: "userId"');
1108
+ }
1109
+ if (typeof phone === 'undefined') {
1110
+ throw new AppwriteException('Missing required parameter: "phone"');
1111
+ }
1112
+ const apiPath = '/account/sessions/phone';
1113
+ const payload = {};
1114
+ if (typeof userId !== 'undefined') {
1115
+ payload['userId'] = userId;
1116
+ }
1117
+ if (typeof phone !== 'undefined') {
1118
+ payload['phone'] = phone;
1119
+ }
1120
+ const uri = new URL(this.client.config.endpoint + apiPath);
1121
+ return yield this.client.call('post', uri, {
1122
+ 'content-type': 'application/json',
1123
+ }, payload);
1124
+ });
1125
+ }
1126
+ /**
1127
+ * Create phone session (confirmation)
1128
+ *
1129
+ * Use this endpoint to complete creating a session with SMS. Use the
1130
+ * **userId** from the
1131
+ * [createPhoneSession](https://appwrite.io/docs/references/cloud/client-web/account#createPhoneSession)
1132
+ * endpoint and the **secret** received via SMS to successfully update and
1133
+ * confirm the phone session.
1134
+ *
1135
+ * @param {string} userId
1136
+ * @param {string} secret
1137
+ * @throws {AppwriteException}
1138
+ * @returns {Promise}
1139
+ */
1140
+ updatePhoneSession(userId, secret) {
1141
+ return __awaiter(this, void 0, void 0, function* () {
1142
+ if (typeof userId === 'undefined') {
1143
+ throw new AppwriteException('Missing required parameter: "userId"');
1144
+ }
1145
+ if (typeof secret === 'undefined') {
1146
+ throw new AppwriteException('Missing required parameter: "secret"');
1147
+ }
1148
+ const apiPath = '/account/sessions/phone';
1149
+ const payload = {};
1150
+ if (typeof userId !== 'undefined') {
1151
+ payload['userId'] = userId;
1152
+ }
1153
+ if (typeof secret !== 'undefined') {
1154
+ payload['secret'] = secret;
1155
+ }
1156
+ const uri = new URL(this.client.config.endpoint + apiPath);
1157
+ return yield this.client.call('put', uri, {
1158
+ 'content-type': 'application/json',
1159
+ }, payload);
1160
+ });
1161
+ }
1162
+ /**
1163
+ * Get session
1164
+ *
1165
+ * Use this endpoint to get a logged in user's session using a Session ID.
1166
+ * Inputting 'current' will return the current session being used.
1167
+ *
1168
+ * @param {string} sessionId
1169
+ * @throws {AppwriteException}
1170
+ * @returns {Promise}
1171
+ */
1172
+ getSession(sessionId) {
1173
+ return __awaiter(this, void 0, void 0, function* () {
1174
+ if (typeof sessionId === 'undefined') {
1175
+ throw new AppwriteException('Missing required parameter: "sessionId"');
1176
+ }
1177
+ const apiPath = '/account/sessions/{sessionId}'.replace('{sessionId}', sessionId);
1178
+ const payload = {};
1179
+ const uri = new URL(this.client.config.endpoint + apiPath);
1180
+ return yield this.client.call('get', uri, {
1181
+ 'content-type': 'application/json',
1182
+ }, payload);
1183
+ });
1184
+ }
1185
+ /**
1186
+ * Update OAuth session (refresh tokens)
1187
+ *
1188
+ * Access tokens have limited lifespan and expire to mitigate security risks.
1189
+ * If session was created using an OAuth provider, this route can be used to
1190
+ * "refresh" the access token.
1191
+ *
1192
+ * @param {string} sessionId
1193
+ * @throws {AppwriteException}
1194
+ * @returns {Promise}
1195
+ */
1196
+ updateSession(sessionId) {
1197
+ return __awaiter(this, void 0, void 0, function* () {
1198
+ if (typeof sessionId === 'undefined') {
1199
+ throw new AppwriteException('Missing required parameter: "sessionId"');
1200
+ }
1201
+ const apiPath = '/account/sessions/{sessionId}'.replace('{sessionId}', sessionId);
1202
+ const payload = {};
1203
+ const uri = new URL(this.client.config.endpoint + apiPath);
1204
+ return yield this.client.call('patch', uri, {
1205
+ 'content-type': 'application/json',
1206
+ }, payload);
1207
+ });
1208
+ }
1209
+ /**
1210
+ * Delete session
1211
+ *
1212
+ * Logout the user. Use 'current' as the session ID to logout on this device,
1213
+ * use a session ID to logout on another device. If you're looking to logout
1214
+ * the user on all devices, use [Delete
1215
+ * Sessions](https://appwrite.io/docs/references/cloud/client-web/account#deleteSessions)
1216
+ * instead.
1217
+ *
1218
+ * @param {string} sessionId
1219
+ * @throws {AppwriteException}
1220
+ * @returns {Promise}
1221
+ */
1222
+ deleteSession(sessionId) {
1223
+ return __awaiter(this, void 0, void 0, function* () {
1224
+ if (typeof sessionId === 'undefined') {
1225
+ throw new AppwriteException('Missing required parameter: "sessionId"');
1226
+ }
1227
+ const apiPath = '/account/sessions/{sessionId}'.replace('{sessionId}', sessionId);
1228
+ const payload = {};
1229
+ const uri = new URL(this.client.config.endpoint + apiPath);
1230
+ return yield this.client.call('delete', uri, {
1231
+ 'content-type': 'application/json',
1232
+ }, payload);
1233
+ });
1234
+ }
1235
+ /**
1236
+ * Update status
1237
+ *
1238
+ * Block the currently logged in user account. Behind the scene, the user
1239
+ * record is not deleted but permanently blocked from any access. To
1240
+ * completely delete a user, use the Users API instead.
1241
+ *
1242
+ * @throws {AppwriteException}
1243
+ * @returns {Promise}
1244
+ */
1245
+ updateStatus() {
1246
+ return __awaiter(this, void 0, void 0, function* () {
1247
+ const apiPath = '/account/status';
1248
+ const payload = {};
1249
+ const uri = new URL(this.client.config.endpoint + apiPath);
1250
+ return yield this.client.call('patch', uri, {
1251
+ 'content-type': 'application/json',
1252
+ }, payload);
1253
+ });
1254
+ }
1255
+ /**
1256
+ * Create email verification
1257
+ *
1258
+ * Use this endpoint to send a verification message to your user email address
1259
+ * to confirm they are the valid owners of that address. Both the **userId**
1260
+ * and **secret** arguments will be passed as query parameters to the URL you
1261
+ * have provided to be attached to the verification email. The provided URL
1262
+ * should redirect the user back to your app and allow you to complete the
1263
+ * verification process by verifying both the **userId** and **secret**
1264
+ * parameters. Learn more about how to [complete the verification
1265
+ * process](https://appwrite.io/docs/references/cloud/client-web/account#updateVerification).
1266
+ * The verification link sent to the user's email address is valid for 7 days.
1267
+ *
1268
+ * Please note that in order to avoid a [Redirect
1269
+ * Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md),
1270
+ * the only valid redirect URLs are the ones from domains you have set when
1271
+ * adding your platforms in the console interface.
1272
+ *
1273
+ *
1274
+ * @param {string} url
1275
+ * @throws {AppwriteException}
1276
+ * @returns {Promise}
1277
+ */
1278
+ createVerification(url) {
1279
+ return __awaiter(this, void 0, void 0, function* () {
1280
+ if (typeof url === 'undefined') {
1281
+ throw new AppwriteException('Missing required parameter: "url"');
1282
+ }
1283
+ const apiPath = '/account/verification';
1284
+ const payload = {};
1285
+ if (typeof url !== 'undefined') {
1286
+ payload['url'] = url;
1287
+ }
1288
+ const uri = new URL(this.client.config.endpoint + apiPath);
1289
+ return yield this.client.call('post', uri, {
1290
+ 'content-type': 'application/json',
1291
+ }, payload);
1292
+ });
1293
+ }
1294
+ /**
1295
+ * Create email verification (confirmation)
1296
+ *
1297
+ * Use this endpoint to complete the user email verification process. Use both
1298
+ * the **userId** and **secret** parameters that were attached to your app URL
1299
+ * to verify the user email ownership. If confirmed this route will return a
1300
+ * 200 status code.
1301
+ *
1302
+ * @param {string} userId
1303
+ * @param {string} secret
1304
+ * @throws {AppwriteException}
1305
+ * @returns {Promise}
1306
+ */
1307
+ updateVerification(userId, secret) {
1308
+ return __awaiter(this, void 0, void 0, function* () {
1309
+ if (typeof userId === 'undefined') {
1310
+ throw new AppwriteException('Missing required parameter: "userId"');
1311
+ }
1312
+ if (typeof secret === 'undefined') {
1313
+ throw new AppwriteException('Missing required parameter: "secret"');
1314
+ }
1315
+ const apiPath = '/account/verification';
1316
+ const payload = {};
1317
+ if (typeof userId !== 'undefined') {
1318
+ payload['userId'] = userId;
1319
+ }
1320
+ if (typeof secret !== 'undefined') {
1321
+ payload['secret'] = secret;
1322
+ }
1323
+ const uri = new URL(this.client.config.endpoint + apiPath);
1324
+ return yield this.client.call('put', uri, {
1325
+ 'content-type': 'application/json',
1326
+ }, payload);
1327
+ });
1328
+ }
1329
+ /**
1330
+ * Create phone verification
1331
+ *
1332
+ * Use this endpoint to send a verification SMS to the currently logged in
1333
+ * user. This endpoint is meant for use after updating a user's phone number
1334
+ * using the
1335
+ * [accountUpdatePhone](https://appwrite.io/docs/references/cloud/client-web/account#updatePhone)
1336
+ * endpoint. Learn more about how to [complete the verification
1337
+ * process](https://appwrite.io/docs/references/cloud/client-web/account#updatePhoneVerification).
1338
+ * The verification code sent to the user's phone number is valid for 15
1339
+ * minutes.
1340
+ *
1341
+ * @throws {AppwriteException}
1342
+ * @returns {Promise}
1343
+ */
1344
+ createPhoneVerification() {
1345
+ return __awaiter(this, void 0, void 0, function* () {
1346
+ const apiPath = '/account/verification/phone';
1347
+ const payload = {};
1348
+ const uri = new URL(this.client.config.endpoint + apiPath);
1349
+ return yield this.client.call('post', uri, {
1350
+ 'content-type': 'application/json',
1351
+ }, payload);
1352
+ });
1353
+ }
1354
+ /**
1355
+ * Create phone verification (confirmation)
1356
+ *
1357
+ * Use this endpoint to complete the user phone verification process. Use the
1358
+ * **userId** and **secret** that were sent to your user's phone number to
1359
+ * verify the user email ownership. If confirmed this route will return a 200
1360
+ * status code.
1361
+ *
1362
+ * @param {string} userId
1363
+ * @param {string} secret
1364
+ * @throws {AppwriteException}
1365
+ * @returns {Promise}
1366
+ */
1367
+ updatePhoneVerification(userId, secret) {
1368
+ return __awaiter(this, void 0, void 0, function* () {
1369
+ if (typeof userId === 'undefined') {
1370
+ throw new AppwriteException('Missing required parameter: "userId"');
1371
+ }
1372
+ if (typeof secret === 'undefined') {
1373
+ throw new AppwriteException('Missing required parameter: "secret"');
1374
+ }
1375
+ const apiPath = '/account/verification/phone';
1376
+ const payload = {};
1377
+ if (typeof userId !== 'undefined') {
1378
+ payload['userId'] = userId;
1379
+ }
1380
+ if (typeof secret !== 'undefined') {
1381
+ payload['secret'] = secret;
1382
+ }
1383
+ const uri = new URL(this.client.config.endpoint + apiPath);
1384
+ return yield this.client.call('put', uri, {
1385
+ 'content-type': 'application/json',
1386
+ }, payload);
1387
+ });
1388
+ }
1389
+ }
1390
+
1391
+ class Avatars extends Service {
1392
+ constructor(client) {
1393
+ super(client);
1394
+ }
1395
+ /**
1396
+ * Get browser icon
1397
+ *
1398
+ * You can use this endpoint to show different browser icons to your users.
1399
+ * The code argument receives the browser code as it appears in your user [GET
1400
+ * /account/sessions](https://appwrite.io/docs/references/cloud/client-web/account#getSessions)
1401
+ * endpoint. Use width, height and quality arguments to change the output
1402
+ * settings.
1403
+ *
1404
+ * When one dimension is specified and the other is 0, the image is scaled
1405
+ * with preserved aspect ratio. If both dimensions are 0, the API provides an
1406
+ * image at source quality. If dimensions are not specified, the default size
1407
+ * of image returned is 100x100px.
1408
+ *
1409
+ * @param {string} code
1410
+ * @param {number} width
1411
+ * @param {number} height
1412
+ * @param {number} quality
1413
+ * @throws {AppwriteException}
1414
+ * @returns {URL}
1415
+ */
1416
+ getBrowser(code, width, height, quality) {
1417
+ if (typeof code === 'undefined') {
1418
+ throw new AppwriteException('Missing required parameter: "code"');
1419
+ }
1420
+ const apiPath = '/avatars/browsers/{code}'.replace('{code}', code);
1421
+ const payload = {};
1422
+ if (typeof width !== 'undefined') {
1423
+ payload['width'] = width;
1424
+ }
1425
+ if (typeof height !== 'undefined') {
1426
+ payload['height'] = height;
1427
+ }
1428
+ if (typeof quality !== 'undefined') {
1429
+ payload['quality'] = quality;
1430
+ }
1431
+ const uri = new URL(this.client.config.endpoint + apiPath);
1432
+ payload['project'] = this.client.config.project;
1433
+ for (const [key, value] of Object.entries(Service.flatten(payload))) {
1434
+ uri.searchParams.append(key, value);
1435
+ }
1436
+ return uri;
1437
+ }
1438
+ /**
1439
+ * Get credit card icon
1440
+ *
1441
+ * The credit card endpoint will return you the icon of the credit card
1442
+ * provider you need. Use width, height and quality arguments to change the
1443
+ * output settings.
1444
+ *
1445
+ * When one dimension is specified and the other is 0, the image is scaled
1446
+ * with preserved aspect ratio. If both dimensions are 0, the API provides an
1447
+ * image at source quality. If dimensions are not specified, the default size
1448
+ * of image returned is 100x100px.
1449
+ *
1450
+ *
1451
+ * @param {string} code
1452
+ * @param {number} width
1453
+ * @param {number} height
1454
+ * @param {number} quality
1455
+ * @throws {AppwriteException}
1456
+ * @returns {URL}
1457
+ */
1458
+ getCreditCard(code, width, height, quality) {
1459
+ if (typeof code === 'undefined') {
1460
+ throw new AppwriteException('Missing required parameter: "code"');
1461
+ }
1462
+ const apiPath = '/avatars/credit-cards/{code}'.replace('{code}', code);
1463
+ const payload = {};
1464
+ if (typeof width !== 'undefined') {
1465
+ payload['width'] = width;
1466
+ }
1467
+ if (typeof height !== 'undefined') {
1468
+ payload['height'] = height;
1469
+ }
1470
+ if (typeof quality !== 'undefined') {
1471
+ payload['quality'] = quality;
1472
+ }
1473
+ const uri = new URL(this.client.config.endpoint + apiPath);
1474
+ payload['project'] = this.client.config.project;
1475
+ for (const [key, value] of Object.entries(Service.flatten(payload))) {
1476
+ uri.searchParams.append(key, value);
1477
+ }
1478
+ return uri;
1479
+ }
1480
+ /**
1481
+ * Get favicon
1482
+ *
1483
+ * Use this endpoint to fetch the favorite icon (AKA favicon) of any remote
1484
+ * website URL.
1485
+ *
1486
+ *
1487
+ * @param {string} url
1488
+ * @throws {AppwriteException}
1489
+ * @returns {URL}
1490
+ */
1491
+ getFavicon(url) {
1492
+ if (typeof url === 'undefined') {
1493
+ throw new AppwriteException('Missing required parameter: "url"');
1494
+ }
1495
+ const apiPath = '/avatars/favicon';
1496
+ const payload = {};
1497
+ if (typeof url !== 'undefined') {
1498
+ payload['url'] = url;
1499
+ }
1500
+ const uri = new URL(this.client.config.endpoint + apiPath);
1501
+ payload['project'] = this.client.config.project;
1502
+ for (const [key, value] of Object.entries(Service.flatten(payload))) {
1503
+ uri.searchParams.append(key, value);
1504
+ }
1505
+ return uri;
1506
+ }
1507
+ /**
1508
+ * Get country flag
1509
+ *
1510
+ * You can use this endpoint to show different country flags icons to your
1511
+ * users. The code argument receives the 2 letter country code. Use width,
1512
+ * height and quality arguments to change the output settings. Country codes
1513
+ * follow the [ISO 3166-1](https://en.wikipedia.org/wiki/ISO_3166-1) standard.
1514
+ *
1515
+ * When one dimension is specified and the other is 0, the image is scaled
1516
+ * with preserved aspect ratio. If both dimensions are 0, the API provides an
1517
+ * image at source quality. If dimensions are not specified, the default size
1518
+ * of image returned is 100x100px.
1519
+ *
1520
+ *
1521
+ * @param {string} code
1522
+ * @param {number} width
1523
+ * @param {number} height
1524
+ * @param {number} quality
1525
+ * @throws {AppwriteException}
1526
+ * @returns {URL}
1527
+ */
1528
+ getFlag(code, width, height, quality) {
1529
+ if (typeof code === 'undefined') {
1530
+ throw new AppwriteException('Missing required parameter: "code"');
1531
+ }
1532
+ const apiPath = '/avatars/flags/{code}'.replace('{code}', code);
1533
+ const payload = {};
1534
+ if (typeof width !== 'undefined') {
1535
+ payload['width'] = width;
1536
+ }
1537
+ if (typeof height !== 'undefined') {
1538
+ payload['height'] = height;
1539
+ }
1540
+ if (typeof quality !== 'undefined') {
1541
+ payload['quality'] = quality;
1542
+ }
1543
+ const uri = new URL(this.client.config.endpoint + apiPath);
1544
+ payload['project'] = this.client.config.project;
1545
+ for (const [key, value] of Object.entries(Service.flatten(payload))) {
1546
+ uri.searchParams.append(key, value);
1547
+ }
1548
+ return uri;
1549
+ }
1550
+ /**
1551
+ * Get image from URL
1552
+ *
1553
+ * Use this endpoint to fetch a remote image URL and crop it to any image size
1554
+ * you want. This endpoint is very useful if you need to crop and display
1555
+ * remote images in your app or in case you want to make sure a 3rd party
1556
+ * image is properly served using a TLS protocol.
1557
+ *
1558
+ * When one dimension is specified and the other is 0, the image is scaled
1559
+ * with preserved aspect ratio. If both dimensions are 0, the API provides an
1560
+ * image at source quality. If dimensions are not specified, the default size
1561
+ * of image returned is 400x400px.
1562
+ *
1563
+ *
1564
+ * @param {string} url
1565
+ * @param {number} width
1566
+ * @param {number} height
1567
+ * @throws {AppwriteException}
1568
+ * @returns {URL}
1569
+ */
1570
+ getImage(url, width, height) {
1571
+ if (typeof url === 'undefined') {
1572
+ throw new AppwriteException('Missing required parameter: "url"');
1573
+ }
1574
+ const apiPath = '/avatars/image';
1575
+ const payload = {};
1576
+ if (typeof url !== 'undefined') {
1577
+ payload['url'] = url;
1578
+ }
1579
+ if (typeof width !== 'undefined') {
1580
+ payload['width'] = width;
1581
+ }
1582
+ if (typeof height !== 'undefined') {
1583
+ payload['height'] = height;
1584
+ }
1585
+ const uri = new URL(this.client.config.endpoint + apiPath);
1586
+ payload['project'] = this.client.config.project;
1587
+ for (const [key, value] of Object.entries(Service.flatten(payload))) {
1588
+ uri.searchParams.append(key, value);
1589
+ }
1590
+ return uri;
1591
+ }
1592
+ /**
1593
+ * Get user initials
1594
+ *
1595
+ * Use this endpoint to show your user initials avatar icon on your website or
1596
+ * app. By default, this route will try to print your logged-in user name or
1597
+ * email initials. You can also overwrite the user name if you pass the 'name'
1598
+ * parameter. If no name is given and no user is logged, an empty avatar will
1599
+ * be returned.
1600
+ *
1601
+ * You can use the color and background params to change the avatar colors. By
1602
+ * default, a random theme will be selected. The random theme will persist for
1603
+ * the user's initials when reloading the same theme will always return for
1604
+ * the same initials.
1605
+ *
1606
+ * When one dimension is specified and the other is 0, the image is scaled
1607
+ * with preserved aspect ratio. If both dimensions are 0, the API provides an
1608
+ * image at source quality. If dimensions are not specified, the default size
1609
+ * of image returned is 100x100px.
1610
+ *
1611
+ *
1612
+ * @param {string} name
1613
+ * @param {number} width
1614
+ * @param {number} height
1615
+ * @param {string} background
1616
+ * @throws {AppwriteException}
1617
+ * @returns {URL}
1618
+ */
1619
+ getInitials(name, width, height, background) {
1620
+ const apiPath = '/avatars/initials';
1621
+ const payload = {};
1622
+ if (typeof name !== 'undefined') {
1623
+ payload['name'] = name;
1624
+ }
1625
+ if (typeof width !== 'undefined') {
1626
+ payload['width'] = width;
1627
+ }
1628
+ if (typeof height !== 'undefined') {
1629
+ payload['height'] = height;
1630
+ }
1631
+ if (typeof background !== 'undefined') {
1632
+ payload['background'] = background;
1633
+ }
1634
+ const uri = new URL(this.client.config.endpoint + apiPath);
1635
+ payload['project'] = this.client.config.project;
1636
+ for (const [key, value] of Object.entries(Service.flatten(payload))) {
1637
+ uri.searchParams.append(key, value);
1638
+ }
1639
+ return uri;
1640
+ }
1641
+ /**
1642
+ * Get QR code
1643
+ *
1644
+ * Converts a given plain text to a QR code image. You can use the query
1645
+ * parameters to change the size and style of the resulting image.
1646
+ *
1647
+ *
1648
+ * @param {string} text
1649
+ * @param {number} size
1650
+ * @param {number} margin
1651
+ * @param {boolean} download
1652
+ * @throws {AppwriteException}
1653
+ * @returns {URL}
1654
+ */
1655
+ getQR(text, size, margin, download) {
1656
+ if (typeof text === 'undefined') {
1657
+ throw new AppwriteException('Missing required parameter: "text"');
1658
+ }
1659
+ const apiPath = '/avatars/qr';
1660
+ const payload = {};
1661
+ if (typeof text !== 'undefined') {
1662
+ payload['text'] = text;
1663
+ }
1664
+ if (typeof size !== 'undefined') {
1665
+ payload['size'] = size;
1666
+ }
1667
+ if (typeof margin !== 'undefined') {
1668
+ payload['margin'] = margin;
1669
+ }
1670
+ if (typeof download !== 'undefined') {
1671
+ payload['download'] = download;
1672
+ }
1673
+ const uri = new URL(this.client.config.endpoint + apiPath);
1674
+ payload['project'] = this.client.config.project;
1675
+ for (const [key, value] of Object.entries(Service.flatten(payload))) {
1676
+ uri.searchParams.append(key, value);
1677
+ }
1678
+ return uri;
1679
+ }
1680
+ }
1681
+
1682
+ class Databases extends Service {
1683
+ constructor(client) {
1684
+ super(client);
1685
+ }
1686
+ /**
1687
+ * List documents
1688
+ *
1689
+ * Get a list of all the user's documents in a given collection. You can use
1690
+ * the query params to filter your results.
1691
+ *
1692
+ * @param {string} databaseId
1693
+ * @param {string} collectionId
1694
+ * @param {string[]} queries
1695
+ * @throws {AppwriteException}
1696
+ * @returns {Promise}
1697
+ */
1698
+ listDocuments(databaseId, collectionId, queries) {
1699
+ return __awaiter(this, void 0, void 0, function* () {
1700
+ if (typeof databaseId === 'undefined') {
1701
+ throw new AppwriteException('Missing required parameter: "databaseId"');
1702
+ }
1703
+ if (typeof collectionId === 'undefined') {
1704
+ throw new AppwriteException('Missing required parameter: "collectionId"');
1705
+ }
1706
+ const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId);
1707
+ const payload = {};
1708
+ if (typeof queries !== 'undefined') {
1709
+ payload['queries'] = queries;
1710
+ }
1711
+ const uri = new URL(this.client.config.endpoint + apiPath);
1712
+ return yield this.client.call('get', uri, {
1713
+ 'content-type': 'application/json',
1714
+ }, payload);
1715
+ });
1716
+ }
1717
+ /**
1718
+ * Create document
1719
+ *
1720
+ * Create a new Document. Before using this route, you should create a new
1721
+ * collection resource using either a [server
1722
+ * integration](https://appwrite.io/docs/server/databases#databasesCreateCollection)
1723
+ * API or directly from your database console.
1724
+ *
1725
+ * @param {string} databaseId
1726
+ * @param {string} collectionId
1727
+ * @param {string} documentId
1728
+ * @param {Omit<Document, keyof Models.Document>} data
1729
+ * @param {string[]} permissions
1730
+ * @throws {AppwriteException}
1731
+ * @returns {Promise}
1732
+ */
1733
+ createDocument(databaseId, collectionId, documentId, data, permissions) {
1734
+ return __awaiter(this, void 0, void 0, function* () {
1735
+ if (typeof databaseId === 'undefined') {
1736
+ throw new AppwriteException('Missing required parameter: "databaseId"');
1737
+ }
1738
+ if (typeof collectionId === 'undefined') {
1739
+ throw new AppwriteException('Missing required parameter: "collectionId"');
1740
+ }
1741
+ if (typeof documentId === 'undefined') {
1742
+ throw new AppwriteException('Missing required parameter: "documentId"');
1743
+ }
1744
+ if (typeof data === 'undefined') {
1745
+ throw new AppwriteException('Missing required parameter: "data"');
1746
+ }
1747
+ const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId);
1748
+ const payload = {};
1749
+ if (typeof documentId !== 'undefined') {
1750
+ payload['documentId'] = documentId;
1751
+ }
1752
+ if (typeof data !== 'undefined') {
1753
+ payload['data'] = data;
1754
+ }
1755
+ if (typeof permissions !== 'undefined') {
1756
+ payload['permissions'] = permissions;
1757
+ }
1758
+ const uri = new URL(this.client.config.endpoint + apiPath);
1759
+ return yield this.client.call('post', uri, {
1760
+ 'content-type': 'application/json',
1761
+ }, payload);
1762
+ });
1763
+ }
1764
+ /**
1765
+ * Get document
1766
+ *
1767
+ * Get a document by its unique ID. This endpoint response returns a JSON
1768
+ * object with the document data.
1769
+ *
1770
+ * @param {string} databaseId
1771
+ * @param {string} collectionId
1772
+ * @param {string} documentId
1773
+ * @param {string[]} queries
1774
+ * @throws {AppwriteException}
1775
+ * @returns {Promise}
1776
+ */
1777
+ getDocument(databaseId, collectionId, documentId, queries) {
1778
+ return __awaiter(this, void 0, void 0, function* () {
1779
+ if (typeof databaseId === 'undefined') {
1780
+ throw new AppwriteException('Missing required parameter: "databaseId"');
1781
+ }
1782
+ if (typeof collectionId === 'undefined') {
1783
+ throw new AppwriteException('Missing required parameter: "collectionId"');
1784
+ }
1785
+ if (typeof documentId === 'undefined') {
1786
+ throw new AppwriteException('Missing required parameter: "documentId"');
1787
+ }
1788
+ const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId);
1789
+ const payload = {};
1790
+ if (typeof queries !== 'undefined') {
1791
+ payload['queries'] = queries;
1792
+ }
1793
+ const uri = new URL(this.client.config.endpoint + apiPath);
1794
+ return yield this.client.call('get', uri, {
1795
+ 'content-type': 'application/json',
1796
+ }, payload);
1797
+ });
1798
+ }
1799
+ /**
1800
+ * Update document
1801
+ *
1802
+ * Update a document by its unique ID. Using the patch method you can pass
1803
+ * only specific fields that will get updated.
1804
+ *
1805
+ * @param {string} databaseId
1806
+ * @param {string} collectionId
1807
+ * @param {string} documentId
1808
+ * @param {Partial<Omit<Document, keyof Models.Document>>} data
1809
+ * @param {string[]} permissions
1810
+ * @throws {AppwriteException}
1811
+ * @returns {Promise}
1812
+ */
1813
+ updateDocument(databaseId, collectionId, documentId, data, permissions) {
1814
+ return __awaiter(this, void 0, void 0, function* () {
1815
+ if (typeof databaseId === 'undefined') {
1816
+ throw new AppwriteException('Missing required parameter: "databaseId"');
1817
+ }
1818
+ if (typeof collectionId === 'undefined') {
1819
+ throw new AppwriteException('Missing required parameter: "collectionId"');
1820
+ }
1821
+ if (typeof documentId === 'undefined') {
1822
+ throw new AppwriteException('Missing required parameter: "documentId"');
1823
+ }
1824
+ const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId);
1825
+ const payload = {};
1826
+ if (typeof data !== 'undefined') {
1827
+ payload['data'] = data;
1828
+ }
1829
+ if (typeof permissions !== 'undefined') {
1830
+ payload['permissions'] = permissions;
1831
+ }
1832
+ const uri = new URL(this.client.config.endpoint + apiPath);
1833
+ return yield this.client.call('patch', uri, {
1834
+ 'content-type': 'application/json',
1835
+ }, payload);
1836
+ });
1837
+ }
1838
+ /**
1839
+ * Delete document
1840
+ *
1841
+ * Delete a document by its unique ID.
1842
+ *
1843
+ * @param {string} databaseId
1844
+ * @param {string} collectionId
1845
+ * @param {string} documentId
1846
+ * @throws {AppwriteException}
1847
+ * @returns {Promise}
1848
+ */
1849
+ deleteDocument(databaseId, collectionId, documentId) {
1850
+ return __awaiter(this, void 0, void 0, function* () {
1851
+ if (typeof databaseId === 'undefined') {
1852
+ throw new AppwriteException('Missing required parameter: "databaseId"');
1853
+ }
1854
+ if (typeof collectionId === 'undefined') {
1855
+ throw new AppwriteException('Missing required parameter: "collectionId"');
1856
+ }
1857
+ if (typeof documentId === 'undefined') {
1858
+ throw new AppwriteException('Missing required parameter: "documentId"');
1859
+ }
1860
+ const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId);
1861
+ const payload = {};
1862
+ const uri = new URL(this.client.config.endpoint + apiPath);
1863
+ return yield this.client.call('delete', uri, {
1864
+ 'content-type': 'application/json',
1865
+ }, payload);
1866
+ });
1867
+ }
1868
+ }
1869
+
1870
+ class Functions extends Service {
1871
+ constructor(client) {
1872
+ super(client);
1873
+ }
1874
+ /**
1875
+ * List executions
1876
+ *
1877
+ * Get a list of all the current user function execution logs. You can use the
1878
+ * query params to filter your results.
1879
+ *
1880
+ * @param {string} functionId
1881
+ * @param {string[]} queries
1882
+ * @param {string} search
1883
+ * @throws {AppwriteException}
1884
+ * @returns {Promise}
1885
+ */
1886
+ listExecutions(functionId, queries, search) {
1887
+ return __awaiter(this, void 0, void 0, function* () {
1888
+ if (typeof functionId === 'undefined') {
1889
+ throw new AppwriteException('Missing required parameter: "functionId"');
1890
+ }
1891
+ const apiPath = '/functions/{functionId}/executions'.replace('{functionId}', functionId);
1892
+ const payload = {};
1893
+ if (typeof queries !== 'undefined') {
1894
+ payload['queries'] = queries;
1895
+ }
1896
+ if (typeof search !== 'undefined') {
1897
+ payload['search'] = search;
1898
+ }
1899
+ const uri = new URL(this.client.config.endpoint + apiPath);
1900
+ return yield this.client.call('get', uri, {
1901
+ 'content-type': 'application/json',
1902
+ }, payload);
1903
+ });
1904
+ }
1905
+ /**
1906
+ * Create execution
1907
+ *
1908
+ * Trigger a function execution. The returned object will return you the
1909
+ * current execution status. You can ping the `Get Execution` endpoint to get
1910
+ * updates on the current execution status. Once this endpoint is called, your
1911
+ * function execution process will start asynchronously.
1912
+ *
1913
+ * @param {string} functionId
1914
+ * @param {string} body
1915
+ * @param {boolean} async
1916
+ * @param {string} xpath
1917
+ * @param {string} method
1918
+ * @param {object} headers
1919
+ * @throws {AppwriteException}
1920
+ * @returns {Promise}
1921
+ */
1922
+ createExecution(functionId, body, async, xpath, method, headers) {
1923
+ return __awaiter(this, void 0, void 0, function* () {
1924
+ if (typeof functionId === 'undefined') {
1925
+ throw new AppwriteException('Missing required parameter: "functionId"');
1926
+ }
1927
+ const apiPath = '/functions/{functionId}/executions'.replace('{functionId}', functionId);
1928
+ const payload = {};
1929
+ if (typeof body !== 'undefined') {
1930
+ payload['body'] = body;
1931
+ }
1932
+ if (typeof async !== 'undefined') {
1933
+ payload['async'] = async;
1934
+ }
1935
+ if (typeof xpath !== 'undefined') {
1936
+ payload['path'] = xpath;
1937
+ }
1938
+ if (typeof method !== 'undefined') {
1939
+ payload['method'] = method;
1940
+ }
1941
+ if (typeof headers !== 'undefined') {
1942
+ payload['headers'] = headers;
1943
+ }
1944
+ const uri = new URL(this.client.config.endpoint + apiPath);
1945
+ return yield this.client.call('post', uri, {
1946
+ 'content-type': 'application/json',
1947
+ }, payload);
1948
+ });
1949
+ }
1950
+ /**
1951
+ * Get execution
1952
+ *
1953
+ * Get a function execution log by its unique ID.
1954
+ *
1955
+ * @param {string} functionId
1956
+ * @param {string} executionId
1957
+ * @throws {AppwriteException}
1958
+ * @returns {Promise}
1959
+ */
1960
+ getExecution(functionId, executionId) {
1961
+ return __awaiter(this, void 0, void 0, function* () {
1962
+ if (typeof functionId === 'undefined') {
1963
+ throw new AppwriteException('Missing required parameter: "functionId"');
1964
+ }
1965
+ if (typeof executionId === 'undefined') {
1966
+ throw new AppwriteException('Missing required parameter: "executionId"');
1967
+ }
1968
+ const apiPath = '/functions/{functionId}/executions/{executionId}'.replace('{functionId}', functionId).replace('{executionId}', executionId);
1969
+ const payload = {};
1970
+ const uri = new URL(this.client.config.endpoint + apiPath);
1971
+ return yield this.client.call('get', uri, {
1972
+ 'content-type': 'application/json',
1973
+ }, payload);
1974
+ });
1975
+ }
1976
+ }
1977
+
1978
+ class Graphql extends Service {
1979
+ constructor(client) {
1980
+ super(client);
1981
+ }
1982
+ /**
1983
+ * GraphQL endpoint
1984
+ *
1985
+ * Execute a GraphQL mutation.
1986
+ *
1987
+ * @param {object} query
1988
+ * @throws {AppwriteException}
1989
+ * @returns {Promise}
1990
+ */
1991
+ query(query) {
1992
+ return __awaiter(this, void 0, void 0, function* () {
1993
+ if (typeof query === 'undefined') {
1994
+ throw new AppwriteException('Missing required parameter: "query"');
1995
+ }
1996
+ const apiPath = '/graphql';
1997
+ const payload = {};
1998
+ if (typeof query !== 'undefined') {
1999
+ payload['query'] = query;
2000
+ }
2001
+ const uri = new URL(this.client.config.endpoint + apiPath);
2002
+ return yield this.client.call('post', uri, {
2003
+ 'x-sdk-graphql': 'true',
2004
+ 'content-type': 'application/json',
2005
+ }, payload);
2006
+ });
2007
+ }
2008
+ /**
2009
+ * GraphQL endpoint
2010
+ *
2011
+ * Execute a GraphQL mutation.
2012
+ *
2013
+ * @param {object} query
2014
+ * @throws {AppwriteException}
2015
+ * @returns {Promise}
2016
+ */
2017
+ mutation(query) {
2018
+ return __awaiter(this, void 0, void 0, function* () {
2019
+ if (typeof query === 'undefined') {
2020
+ throw new AppwriteException('Missing required parameter: "query"');
2021
+ }
2022
+ const apiPath = '/graphql/mutation';
2023
+ const payload = {};
2024
+ if (typeof query !== 'undefined') {
2025
+ payload['query'] = query;
2026
+ }
2027
+ const uri = new URL(this.client.config.endpoint + apiPath);
2028
+ return yield this.client.call('post', uri, {
2029
+ 'x-sdk-graphql': 'true',
2030
+ 'content-type': 'application/json',
2031
+ }, payload);
2032
+ });
2033
+ }
2034
+ }
2035
+
2036
+ class Locale extends Service {
2037
+ constructor(client) {
2038
+ super(client);
2039
+ }
2040
+ /**
2041
+ * Get user locale
2042
+ *
2043
+ * Get the current user location based on IP. Returns an object with user
2044
+ * country code, country name, continent name, continent code, ip address and
2045
+ * suggested currency. You can use the locale header to get the data in a
2046
+ * supported language.
2047
+ *
2048
+ * ([IP Geolocation by DB-IP](https://db-ip.com))
2049
+ *
2050
+ * @throws {AppwriteException}
2051
+ * @returns {Promise}
2052
+ */
2053
+ get() {
2054
+ return __awaiter(this, void 0, void 0, function* () {
2055
+ const apiPath = '/locale';
2056
+ const payload = {};
2057
+ const uri = new URL(this.client.config.endpoint + apiPath);
2058
+ return yield this.client.call('get', uri, {
2059
+ 'content-type': 'application/json',
2060
+ }, payload);
2061
+ });
2062
+ }
2063
+ /**
2064
+ * List Locale Codes
2065
+ *
2066
+ * List of all locale codes in [ISO
2067
+ * 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes).
2068
+ *
2069
+ * @throws {AppwriteException}
2070
+ * @returns {Promise}
2071
+ */
2072
+ listCodes() {
2073
+ return __awaiter(this, void 0, void 0, function* () {
2074
+ const apiPath = '/locale/codes';
2075
+ const payload = {};
2076
+ const uri = new URL(this.client.config.endpoint + apiPath);
2077
+ return yield this.client.call('get', uri, {
2078
+ 'content-type': 'application/json',
2079
+ }, payload);
2080
+ });
2081
+ }
2082
+ /**
2083
+ * List continents
2084
+ *
2085
+ * List of all continents. You can use the locale header to get the data in a
2086
+ * supported language.
2087
+ *
2088
+ * @throws {AppwriteException}
2089
+ * @returns {Promise}
2090
+ */
2091
+ listContinents() {
2092
+ return __awaiter(this, void 0, void 0, function* () {
2093
+ const apiPath = '/locale/continents';
2094
+ const payload = {};
2095
+ const uri = new URL(this.client.config.endpoint + apiPath);
2096
+ return yield this.client.call('get', uri, {
2097
+ 'content-type': 'application/json',
2098
+ }, payload);
2099
+ });
2100
+ }
2101
+ /**
2102
+ * List countries
2103
+ *
2104
+ * List of all countries. You can use the locale header to get the data in a
2105
+ * supported language.
2106
+ *
2107
+ * @throws {AppwriteException}
2108
+ * @returns {Promise}
2109
+ */
2110
+ listCountries() {
2111
+ return __awaiter(this, void 0, void 0, function* () {
2112
+ const apiPath = '/locale/countries';
2113
+ const payload = {};
2114
+ const uri = new URL(this.client.config.endpoint + apiPath);
2115
+ return yield this.client.call('get', uri, {
2116
+ 'content-type': 'application/json',
2117
+ }, payload);
2118
+ });
2119
+ }
2120
+ /**
2121
+ * List EU countries
2122
+ *
2123
+ * List of all countries that are currently members of the EU. You can use the
2124
+ * locale header to get the data in a supported language.
2125
+ *
2126
+ * @throws {AppwriteException}
2127
+ * @returns {Promise}
2128
+ */
2129
+ listCountriesEU() {
2130
+ return __awaiter(this, void 0, void 0, function* () {
2131
+ const apiPath = '/locale/countries/eu';
2132
+ const payload = {};
2133
+ const uri = new URL(this.client.config.endpoint + apiPath);
2134
+ return yield this.client.call('get', uri, {
2135
+ 'content-type': 'application/json',
2136
+ }, payload);
2137
+ });
2138
+ }
2139
+ /**
2140
+ * List countries phone codes
2141
+ *
2142
+ * List of all countries phone codes. You can use the locale header to get the
2143
+ * data in a supported language.
2144
+ *
2145
+ * @throws {AppwriteException}
2146
+ * @returns {Promise}
2147
+ */
2148
+ listCountriesPhones() {
2149
+ return __awaiter(this, void 0, void 0, function* () {
2150
+ const apiPath = '/locale/countries/phones';
2151
+ const payload = {};
2152
+ const uri = new URL(this.client.config.endpoint + apiPath);
2153
+ return yield this.client.call('get', uri, {
2154
+ 'content-type': 'application/json',
2155
+ }, payload);
2156
+ });
2157
+ }
2158
+ /**
2159
+ * List currencies
2160
+ *
2161
+ * List of all currencies, including currency symbol, name, plural, and
2162
+ * decimal digits for all major and minor currencies. You can use the locale
2163
+ * header to get the data in a supported language.
2164
+ *
2165
+ * @throws {AppwriteException}
2166
+ * @returns {Promise}
2167
+ */
2168
+ listCurrencies() {
2169
+ return __awaiter(this, void 0, void 0, function* () {
2170
+ const apiPath = '/locale/currencies';
2171
+ const payload = {};
2172
+ const uri = new URL(this.client.config.endpoint + apiPath);
2173
+ return yield this.client.call('get', uri, {
2174
+ 'content-type': 'application/json',
2175
+ }, payload);
2176
+ });
2177
+ }
2178
+ /**
2179
+ * List languages
2180
+ *
2181
+ * List of all languages classified by ISO 639-1 including 2-letter code, name
2182
+ * in English, and name in the respective language.
2183
+ *
2184
+ * @throws {AppwriteException}
2185
+ * @returns {Promise}
2186
+ */
2187
+ listLanguages() {
2188
+ return __awaiter(this, void 0, void 0, function* () {
2189
+ const apiPath = '/locale/languages';
2190
+ const payload = {};
2191
+ const uri = new URL(this.client.config.endpoint + apiPath);
2192
+ return yield this.client.call('get', uri, {
2193
+ 'content-type': 'application/json',
2194
+ }, payload);
2195
+ });
2196
+ }
2197
+ }
2198
+
2199
+ class Storage extends Service {
2200
+ constructor(client) {
2201
+ super(client);
2202
+ }
2203
+ /**
2204
+ * List files
2205
+ *
2206
+ * Get a list of all the user files. You can use the query params to filter
2207
+ * your results.
2208
+ *
2209
+ * @param {string} bucketId
2210
+ * @param {string[]} queries
2211
+ * @param {string} search
2212
+ * @throws {AppwriteException}
2213
+ * @returns {Promise}
2214
+ */
2215
+ listFiles(bucketId, queries, search) {
2216
+ return __awaiter(this, void 0, void 0, function* () {
2217
+ if (typeof bucketId === 'undefined') {
2218
+ throw new AppwriteException('Missing required parameter: "bucketId"');
2219
+ }
2220
+ const apiPath = '/storage/buckets/{bucketId}/files'.replace('{bucketId}', bucketId);
2221
+ const payload = {};
2222
+ if (typeof queries !== 'undefined') {
2223
+ payload['queries'] = queries;
2224
+ }
2225
+ if (typeof search !== 'undefined') {
2226
+ payload['search'] = search;
2227
+ }
2228
+ const uri = new URL(this.client.config.endpoint + apiPath);
2229
+ return yield this.client.call('get', uri, {
2230
+ 'content-type': 'application/json',
2231
+ }, payload);
2232
+ });
2233
+ }
2234
+ /**
2235
+ * Create file
2236
+ *
2237
+ * Create a new file. Before using this route, you should create a new bucket
2238
+ * resource using either a [server
2239
+ * integration](https://appwrite.io/docs/server/storage#storageCreateBucket)
2240
+ * API or directly from your Appwrite console.
2241
+ *
2242
+ * Larger files should be uploaded using multiple requests with the
2243
+ * [content-range](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Range)
2244
+ * header to send a partial request with a maximum supported chunk of `5MB`.
2245
+ * The `content-range` header values should always be in bytes.
2246
+ *
2247
+ * When the first request is sent, the server will return the **File** object,
2248
+ * and the subsequent part request must include the file's **id** in
2249
+ * `x-appwrite-id` header to allow the server to know that the partial upload
2250
+ * is for the existing file and not for a new one.
2251
+ *
2252
+ * If you're creating a new file using one of the Appwrite SDKs, all the
2253
+ * chunking logic will be managed by the SDK internally.
2254
+ *
2255
+ *
2256
+ * @param {string} bucketId
2257
+ * @param {string} fileId
2258
+ * @param {any} file
2259
+ * @param {string[]} permissions
2260
+ * @throws {AppwriteException}
2261
+ * @returns {Promise}
2262
+ */
2263
+ createFile(bucketId, fileId, file, permissions, onProgress = (progress) => { }) {
2264
+ return __awaiter(this, void 0, void 0, function* () {
2265
+ if (typeof bucketId === 'undefined') {
2266
+ throw new AppwriteException('Missing required parameter: "bucketId"');
2267
+ }
2268
+ if (typeof fileId === 'undefined') {
2269
+ throw new AppwriteException('Missing required parameter: "fileId"');
2270
+ }
2271
+ if (typeof file === 'undefined') {
2272
+ throw new AppwriteException('Missing required parameter: "file"');
2273
+ }
2274
+ const apiPath = '/storage/buckets/{bucketId}/files'.replace('{bucketId}', bucketId);
2275
+ const payload = {};
2276
+ if (typeof fileId !== 'undefined') {
2277
+ payload['fileId'] = fileId;
2278
+ }
2279
+ if (typeof file !== 'undefined') {
2280
+ payload['file'] = file;
2281
+ }
2282
+ if (typeof permissions !== 'undefined') {
2283
+ payload['permissions'] = permissions;
2284
+ }
2285
+ const uri = new URL(this.client.config.endpoint + apiPath);
2286
+ const size = file.size;
2287
+ if (size <= Service.CHUNK_SIZE) {
2288
+ return yield this.client.call('post', uri, {
2289
+ 'content-type': 'multipart/form-data',
2290
+ }, payload);
2291
+ }
2292
+ const apiHeaders = {
2293
+ 'content-type': 'multipart/form-data',
2294
+ };
2295
+ let offset = 0;
2296
+ let response = undefined;
2297
+ if (fileId != 'unique()') {
2298
+ try {
2299
+ response = yield this.client.call('GET', new URL(this.client.config.endpoint + apiPath + '/' + fileId), apiHeaders);
2300
+ offset = response.chunksUploaded * Service.CHUNK_SIZE;
2301
+ }
2302
+ catch (e) {
2303
+ }
2304
+ }
2305
+ while (offset < size) {
2306
+ let end = Math.min(offset + Service.CHUNK_SIZE - 1, size - 1);
2307
+ apiHeaders['content-range'] = 'bytes ' + offset + '-' + end + '/' + size;
2308
+ if (response && response.$id) {
2309
+ apiHeaders['x-appwrite-id'] = response.$id;
2310
+ }
2311
+ let chunk = yield fs.read(file.uri, Service.CHUNK_SIZE, offset, 'base64');
2312
+ payload['file'] = { uri: `data:${file.type};base64,${chunk}`, name: file.name, type: file.type };
2313
+ response = yield this.client.call('post', uri, apiHeaders, payload);
2314
+ if (onProgress) {
2315
+ onProgress({
2316
+ $id: response.$id,
2317
+ progress: (offset / size) * 100,
2318
+ sizeUploaded: offset,
2319
+ chunksTotal: response.chunksTotal,
2320
+ chunksUploaded: response.chunksUploaded
2321
+ });
2322
+ }
2323
+ offset += Service.CHUNK_SIZE;
2324
+ }
2325
+ return response;
2326
+ });
2327
+ }
2328
+ /**
2329
+ * Get file
2330
+ *
2331
+ * Get a file by its unique ID. This endpoint response returns a JSON object
2332
+ * with the file metadata.
2333
+ *
2334
+ * @param {string} bucketId
2335
+ * @param {string} fileId
2336
+ * @throws {AppwriteException}
2337
+ * @returns {Promise}
2338
+ */
2339
+ getFile(bucketId, fileId) {
2340
+ return __awaiter(this, void 0, void 0, function* () {
2341
+ if (typeof bucketId === 'undefined') {
2342
+ throw new AppwriteException('Missing required parameter: "bucketId"');
2343
+ }
2344
+ if (typeof fileId === 'undefined') {
2345
+ throw new AppwriteException('Missing required parameter: "fileId"');
2346
+ }
2347
+ const apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
2348
+ const payload = {};
2349
+ const uri = new URL(this.client.config.endpoint + apiPath);
2350
+ return yield this.client.call('get', uri, {
2351
+ 'content-type': 'application/json',
2352
+ }, payload);
2353
+ });
2354
+ }
2355
+ /**
2356
+ * Update file
2357
+ *
2358
+ * Update a file by its unique ID. Only users with write permissions have
2359
+ * access to update this resource.
2360
+ *
2361
+ * @param {string} bucketId
2362
+ * @param {string} fileId
2363
+ * @param {string} name
2364
+ * @param {string[]} permissions
2365
+ * @throws {AppwriteException}
2366
+ * @returns {Promise}
2367
+ */
2368
+ updateFile(bucketId, fileId, name, permissions) {
2369
+ return __awaiter(this, void 0, void 0, function* () {
2370
+ if (typeof bucketId === 'undefined') {
2371
+ throw new AppwriteException('Missing required parameter: "bucketId"');
2372
+ }
2373
+ if (typeof fileId === 'undefined') {
2374
+ throw new AppwriteException('Missing required parameter: "fileId"');
2375
+ }
2376
+ const apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
2377
+ const payload = {};
2378
+ if (typeof name !== 'undefined') {
2379
+ payload['name'] = name;
2380
+ }
2381
+ if (typeof permissions !== 'undefined') {
2382
+ payload['permissions'] = permissions;
2383
+ }
2384
+ const uri = new URL(this.client.config.endpoint + apiPath);
2385
+ return yield this.client.call('put', uri, {
2386
+ 'content-type': 'application/json',
2387
+ }, payload);
2388
+ });
2389
+ }
2390
+ /**
2391
+ * Delete File
2392
+ *
2393
+ * Delete a file by its unique ID. Only users with write permissions have
2394
+ * access to delete this resource.
2395
+ *
2396
+ * @param {string} bucketId
2397
+ * @param {string} fileId
2398
+ * @throws {AppwriteException}
2399
+ * @returns {Promise}
2400
+ */
2401
+ deleteFile(bucketId, fileId) {
2402
+ return __awaiter(this, void 0, void 0, function* () {
2403
+ if (typeof bucketId === 'undefined') {
2404
+ throw new AppwriteException('Missing required parameter: "bucketId"');
2405
+ }
2406
+ if (typeof fileId === 'undefined') {
2407
+ throw new AppwriteException('Missing required parameter: "fileId"');
2408
+ }
2409
+ const apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
2410
+ const payload = {};
2411
+ const uri = new URL(this.client.config.endpoint + apiPath);
2412
+ return yield this.client.call('delete', uri, {
2413
+ 'content-type': 'application/json',
2414
+ }, payload);
2415
+ });
2416
+ }
2417
+ /**
2418
+ * Get file for download
2419
+ *
2420
+ * Get a file content by its unique ID. The endpoint response return with a
2421
+ * 'Content-Disposition: attachment' header that tells the browser to start
2422
+ * downloading the file to user downloads directory.
2423
+ *
2424
+ * @param {string} bucketId
2425
+ * @param {string} fileId
2426
+ * @throws {AppwriteException}
2427
+ * @returns {URL}
2428
+ */
2429
+ getFileDownload(bucketId, fileId) {
2430
+ if (typeof bucketId === 'undefined') {
2431
+ throw new AppwriteException('Missing required parameter: "bucketId"');
2432
+ }
2433
+ if (typeof fileId === 'undefined') {
2434
+ throw new AppwriteException('Missing required parameter: "fileId"');
2435
+ }
2436
+ const apiPath = '/storage/buckets/{bucketId}/files/{fileId}/download'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
2437
+ const payload = {};
2438
+ const uri = new URL(this.client.config.endpoint + apiPath);
2439
+ payload['project'] = this.client.config.project;
2440
+ for (const [key, value] of Object.entries(Service.flatten(payload))) {
2441
+ uri.searchParams.append(key, value);
2442
+ }
2443
+ return uri;
2444
+ }
2445
+ /**
2446
+ * Get file preview
2447
+ *
2448
+ * Get a file preview image. Currently, this method supports preview for image
2449
+ * files (jpg, png, and gif), other supported formats, like pdf, docs, slides,
2450
+ * and spreadsheets, will return the file icon image. You can also pass query
2451
+ * string arguments for cutting and resizing your preview image. Preview is
2452
+ * supported only for image files smaller than 10MB.
2453
+ *
2454
+ * @param {string} bucketId
2455
+ * @param {string} fileId
2456
+ * @param {number} width
2457
+ * @param {number} height
2458
+ * @param {string} gravity
2459
+ * @param {number} quality
2460
+ * @param {number} borderWidth
2461
+ * @param {string} borderColor
2462
+ * @param {number} borderRadius
2463
+ * @param {number} opacity
2464
+ * @param {number} rotation
2465
+ * @param {string} background
2466
+ * @param {string} output
2467
+ * @throws {AppwriteException}
2468
+ * @returns {URL}
2469
+ */
2470
+ getFilePreview(bucketId, fileId, width, height, gravity, quality, borderWidth, borderColor, borderRadius, opacity, rotation, background, output) {
2471
+ if (typeof bucketId === 'undefined') {
2472
+ throw new AppwriteException('Missing required parameter: "bucketId"');
2473
+ }
2474
+ if (typeof fileId === 'undefined') {
2475
+ throw new AppwriteException('Missing required parameter: "fileId"');
2476
+ }
2477
+ const apiPath = '/storage/buckets/{bucketId}/files/{fileId}/preview'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
2478
+ const payload = {};
2479
+ if (typeof width !== 'undefined') {
2480
+ payload['width'] = width;
2481
+ }
2482
+ if (typeof height !== 'undefined') {
2483
+ payload['height'] = height;
2484
+ }
2485
+ if (typeof gravity !== 'undefined') {
2486
+ payload['gravity'] = gravity;
2487
+ }
2488
+ if (typeof quality !== 'undefined') {
2489
+ payload['quality'] = quality;
2490
+ }
2491
+ if (typeof borderWidth !== 'undefined') {
2492
+ payload['borderWidth'] = borderWidth;
2493
+ }
2494
+ if (typeof borderColor !== 'undefined') {
2495
+ payload['borderColor'] = borderColor;
2496
+ }
2497
+ if (typeof borderRadius !== 'undefined') {
2498
+ payload['borderRadius'] = borderRadius;
2499
+ }
2500
+ if (typeof opacity !== 'undefined') {
2501
+ payload['opacity'] = opacity;
2502
+ }
2503
+ if (typeof rotation !== 'undefined') {
2504
+ payload['rotation'] = rotation;
2505
+ }
2506
+ if (typeof background !== 'undefined') {
2507
+ payload['background'] = background;
2508
+ }
2509
+ if (typeof output !== 'undefined') {
2510
+ payload['output'] = output;
2511
+ }
2512
+ const uri = new URL(this.client.config.endpoint + apiPath);
2513
+ payload['project'] = this.client.config.project;
2514
+ for (const [key, value] of Object.entries(Service.flatten(payload))) {
2515
+ uri.searchParams.append(key, value);
2516
+ }
2517
+ return uri;
2518
+ }
2519
+ /**
2520
+ * Get file for view
2521
+ *
2522
+ * Get a file content by its unique ID. This endpoint is similar to the
2523
+ * download method but returns with no 'Content-Disposition: attachment'
2524
+ * header.
2525
+ *
2526
+ * @param {string} bucketId
2527
+ * @param {string} fileId
2528
+ * @throws {AppwriteException}
2529
+ * @returns {URL}
2530
+ */
2531
+ getFileView(bucketId, fileId) {
2532
+ if (typeof bucketId === 'undefined') {
2533
+ throw new AppwriteException('Missing required parameter: "bucketId"');
2534
+ }
2535
+ if (typeof fileId === 'undefined') {
2536
+ throw new AppwriteException('Missing required parameter: "fileId"');
2537
+ }
2538
+ const apiPath = '/storage/buckets/{bucketId}/files/{fileId}/view'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
2539
+ const payload = {};
2540
+ const uri = new URL(this.client.config.endpoint + apiPath);
2541
+ payload['project'] = this.client.config.project;
2542
+ for (const [key, value] of Object.entries(Service.flatten(payload))) {
2543
+ uri.searchParams.append(key, value);
2544
+ }
2545
+ return uri;
2546
+ }
2547
+ }
2548
+
2549
+ class Teams extends Service {
2550
+ constructor(client) {
2551
+ super(client);
2552
+ }
2553
+ /**
2554
+ * List teams
2555
+ *
2556
+ * Get a list of all the teams in which the current user is a member. You can
2557
+ * use the parameters to filter your results.
2558
+ *
2559
+ * @param {string[]} queries
2560
+ * @param {string} search
2561
+ * @throws {AppwriteException}
2562
+ * @returns {Promise}
2563
+ */
2564
+ list(queries, search) {
2565
+ return __awaiter(this, void 0, void 0, function* () {
2566
+ const apiPath = '/teams';
2567
+ const payload = {};
2568
+ if (typeof queries !== 'undefined') {
2569
+ payload['queries'] = queries;
2570
+ }
2571
+ if (typeof search !== 'undefined') {
2572
+ payload['search'] = search;
2573
+ }
2574
+ const uri = new URL(this.client.config.endpoint + apiPath);
2575
+ return yield this.client.call('get', uri, {
2576
+ 'content-type': 'application/json',
2577
+ }, payload);
2578
+ });
2579
+ }
2580
+ /**
2581
+ * Create team
2582
+ *
2583
+ * Create a new team. The user who creates the team will automatically be
2584
+ * assigned as the owner of the team. Only the users with the owner role can
2585
+ * invite new members, add new owners and delete or update the team.
2586
+ *
2587
+ * @param {string} teamId
2588
+ * @param {string} name
2589
+ * @param {string[]} roles
2590
+ * @throws {AppwriteException}
2591
+ * @returns {Promise}
2592
+ */
2593
+ create(teamId, name, roles) {
2594
+ return __awaiter(this, void 0, void 0, function* () {
2595
+ if (typeof teamId === 'undefined') {
2596
+ throw new AppwriteException('Missing required parameter: "teamId"');
2597
+ }
2598
+ if (typeof name === 'undefined') {
2599
+ throw new AppwriteException('Missing required parameter: "name"');
2600
+ }
2601
+ const apiPath = '/teams';
2602
+ const payload = {};
2603
+ if (typeof teamId !== 'undefined') {
2604
+ payload['teamId'] = teamId;
2605
+ }
2606
+ if (typeof name !== 'undefined') {
2607
+ payload['name'] = name;
2608
+ }
2609
+ if (typeof roles !== 'undefined') {
2610
+ payload['roles'] = roles;
2611
+ }
2612
+ const uri = new URL(this.client.config.endpoint + apiPath);
2613
+ return yield this.client.call('post', uri, {
2614
+ 'content-type': 'application/json',
2615
+ }, payload);
2616
+ });
2617
+ }
2618
+ /**
2619
+ * Get team
2620
+ *
2621
+ * Get a team by its ID. All team members have read access for this resource.
2622
+ *
2623
+ * @param {string} teamId
2624
+ * @throws {AppwriteException}
2625
+ * @returns {Promise}
2626
+ */
2627
+ get(teamId) {
2628
+ return __awaiter(this, void 0, void 0, function* () {
2629
+ if (typeof teamId === 'undefined') {
2630
+ throw new AppwriteException('Missing required parameter: "teamId"');
2631
+ }
2632
+ const apiPath = '/teams/{teamId}'.replace('{teamId}', teamId);
2633
+ const payload = {};
2634
+ const uri = new URL(this.client.config.endpoint + apiPath);
2635
+ return yield this.client.call('get', uri, {
2636
+ 'content-type': 'application/json',
2637
+ }, payload);
2638
+ });
2639
+ }
2640
+ /**
2641
+ * Update name
2642
+ *
2643
+ * Update the team's name by its unique ID.
2644
+ *
2645
+ * @param {string} teamId
2646
+ * @param {string} name
2647
+ * @throws {AppwriteException}
2648
+ * @returns {Promise}
2649
+ */
2650
+ updateName(teamId, name) {
2651
+ return __awaiter(this, void 0, void 0, function* () {
2652
+ if (typeof teamId === 'undefined') {
2653
+ throw new AppwriteException('Missing required parameter: "teamId"');
2654
+ }
2655
+ if (typeof name === 'undefined') {
2656
+ throw new AppwriteException('Missing required parameter: "name"');
2657
+ }
2658
+ const apiPath = '/teams/{teamId}'.replace('{teamId}', teamId);
2659
+ const payload = {};
2660
+ if (typeof name !== 'undefined') {
2661
+ payload['name'] = name;
2662
+ }
2663
+ const uri = new URL(this.client.config.endpoint + apiPath);
2664
+ return yield this.client.call('put', uri, {
2665
+ 'content-type': 'application/json',
2666
+ }, payload);
2667
+ });
2668
+ }
2669
+ /**
2670
+ * Delete team
2671
+ *
2672
+ * Delete a team using its ID. Only team members with the owner role can
2673
+ * delete the team.
2674
+ *
2675
+ * @param {string} teamId
2676
+ * @throws {AppwriteException}
2677
+ * @returns {Promise}
2678
+ */
2679
+ delete(teamId) {
2680
+ return __awaiter(this, void 0, void 0, function* () {
2681
+ if (typeof teamId === 'undefined') {
2682
+ throw new AppwriteException('Missing required parameter: "teamId"');
2683
+ }
2684
+ const apiPath = '/teams/{teamId}'.replace('{teamId}', teamId);
2685
+ const payload = {};
2686
+ const uri = new URL(this.client.config.endpoint + apiPath);
2687
+ return yield this.client.call('delete', uri, {
2688
+ 'content-type': 'application/json',
2689
+ }, payload);
2690
+ });
2691
+ }
2692
+ /**
2693
+ * List team memberships
2694
+ *
2695
+ * Use this endpoint to list a team's members using the team's ID. All team
2696
+ * members have read access to this endpoint.
2697
+ *
2698
+ * @param {string} teamId
2699
+ * @param {string[]} queries
2700
+ * @param {string} search
2701
+ * @throws {AppwriteException}
2702
+ * @returns {Promise}
2703
+ */
2704
+ listMemberships(teamId, queries, search) {
2705
+ return __awaiter(this, void 0, void 0, function* () {
2706
+ if (typeof teamId === 'undefined') {
2707
+ throw new AppwriteException('Missing required parameter: "teamId"');
2708
+ }
2709
+ const apiPath = '/teams/{teamId}/memberships'.replace('{teamId}', teamId);
2710
+ const payload = {};
2711
+ if (typeof queries !== 'undefined') {
2712
+ payload['queries'] = queries;
2713
+ }
2714
+ if (typeof search !== 'undefined') {
2715
+ payload['search'] = search;
2716
+ }
2717
+ const uri = new URL(this.client.config.endpoint + apiPath);
2718
+ return yield this.client.call('get', uri, {
2719
+ 'content-type': 'application/json',
2720
+ }, payload);
2721
+ });
2722
+ }
2723
+ /**
2724
+ * Create team membership
2725
+ *
2726
+ * Invite a new member to join your team. Provide an ID for existing users, or
2727
+ * invite unregistered users using an email or phone number. If initiated from
2728
+ * a Client SDK, Appwrite will send an email or sms with a link to join the
2729
+ * team to the invited user, and an account will be created for them if one
2730
+ * doesn't exist. If initiated from a Server SDK, the new member will be added
2731
+ * automatically to the team.
2732
+ *
2733
+ * You only need to provide one of a user ID, email, or phone number. Appwrite
2734
+ * will prioritize accepting the user ID > email > phone number if you provide
2735
+ * more than one of these parameters.
2736
+ *
2737
+ * Use the `url` parameter to redirect the user from the invitation email to
2738
+ * your app. After the user is redirected, use the [Update Team Membership
2739
+ * Status](https://appwrite.io/docs/references/cloud/client-web/teams#updateMembershipStatus)
2740
+ * endpoint to allow the user to accept the invitation to the team.
2741
+ *
2742
+ * Please note that to avoid a [Redirect
2743
+ * Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md)
2744
+ * Appwrite will accept the only redirect URLs under the domains you have
2745
+ * added as a platform on the Appwrite Console.
2746
+ *
2747
+ *
2748
+ * @param {string} teamId
2749
+ * @param {string[]} roles
2750
+ * @param {string} email
2751
+ * @param {string} userId
2752
+ * @param {string} phone
2753
+ * @param {string} url
2754
+ * @param {string} name
2755
+ * @throws {AppwriteException}
2756
+ * @returns {Promise}
2757
+ */
2758
+ createMembership(teamId, roles, email, userId, phone, url, name) {
2759
+ return __awaiter(this, void 0, void 0, function* () {
2760
+ if (typeof teamId === 'undefined') {
2761
+ throw new AppwriteException('Missing required parameter: "teamId"');
2762
+ }
2763
+ if (typeof roles === 'undefined') {
2764
+ throw new AppwriteException('Missing required parameter: "roles"');
2765
+ }
2766
+ const apiPath = '/teams/{teamId}/memberships'.replace('{teamId}', teamId);
2767
+ const payload = {};
2768
+ if (typeof email !== 'undefined') {
2769
+ payload['email'] = email;
2770
+ }
2771
+ if (typeof userId !== 'undefined') {
2772
+ payload['userId'] = userId;
2773
+ }
2774
+ if (typeof phone !== 'undefined') {
2775
+ payload['phone'] = phone;
2776
+ }
2777
+ if (typeof roles !== 'undefined') {
2778
+ payload['roles'] = roles;
2779
+ }
2780
+ if (typeof url !== 'undefined') {
2781
+ payload['url'] = url;
2782
+ }
2783
+ if (typeof name !== 'undefined') {
2784
+ payload['name'] = name;
2785
+ }
2786
+ const uri = new URL(this.client.config.endpoint + apiPath);
2787
+ return yield this.client.call('post', uri, {
2788
+ 'content-type': 'application/json',
2789
+ }, payload);
2790
+ });
2791
+ }
2792
+ /**
2793
+ * Get team membership
2794
+ *
2795
+ * Get a team member by the membership unique id. All team members have read
2796
+ * access for this resource.
2797
+ *
2798
+ * @param {string} teamId
2799
+ * @param {string} membershipId
2800
+ * @throws {AppwriteException}
2801
+ * @returns {Promise}
2802
+ */
2803
+ getMembership(teamId, membershipId) {
2804
+ return __awaiter(this, void 0, void 0, function* () {
2805
+ if (typeof teamId === 'undefined') {
2806
+ throw new AppwriteException('Missing required parameter: "teamId"');
2807
+ }
2808
+ if (typeof membershipId === 'undefined') {
2809
+ throw new AppwriteException('Missing required parameter: "membershipId"');
2810
+ }
2811
+ const apiPath = '/teams/{teamId}/memberships/{membershipId}'.replace('{teamId}', teamId).replace('{membershipId}', membershipId);
2812
+ const payload = {};
2813
+ const uri = new URL(this.client.config.endpoint + apiPath);
2814
+ return yield this.client.call('get', uri, {
2815
+ 'content-type': 'application/json',
2816
+ }, payload);
2817
+ });
2818
+ }
2819
+ /**
2820
+ * Update membership
2821
+ *
2822
+ * Modify the roles of a team member. Only team members with the owner role
2823
+ * have access to this endpoint. Learn more about [roles and
2824
+ * permissions](https://appwrite.io/docs/permissions).
2825
+ *
2826
+ *
2827
+ * @param {string} teamId
2828
+ * @param {string} membershipId
2829
+ * @param {string[]} roles
2830
+ * @throws {AppwriteException}
2831
+ * @returns {Promise}
2832
+ */
2833
+ updateMembership(teamId, membershipId, roles) {
2834
+ return __awaiter(this, void 0, void 0, function* () {
2835
+ if (typeof teamId === 'undefined') {
2836
+ throw new AppwriteException('Missing required parameter: "teamId"');
2837
+ }
2838
+ if (typeof membershipId === 'undefined') {
2839
+ throw new AppwriteException('Missing required parameter: "membershipId"');
2840
+ }
2841
+ if (typeof roles === 'undefined') {
2842
+ throw new AppwriteException('Missing required parameter: "roles"');
2843
+ }
2844
+ const apiPath = '/teams/{teamId}/memberships/{membershipId}'.replace('{teamId}', teamId).replace('{membershipId}', membershipId);
2845
+ const payload = {};
2846
+ if (typeof roles !== 'undefined') {
2847
+ payload['roles'] = roles;
2848
+ }
2849
+ const uri = new URL(this.client.config.endpoint + apiPath);
2850
+ return yield this.client.call('patch', uri, {
2851
+ 'content-type': 'application/json',
2852
+ }, payload);
2853
+ });
2854
+ }
2855
+ /**
2856
+ * Delete team membership
2857
+ *
2858
+ * This endpoint allows a user to leave a team or for a team owner to delete
2859
+ * the membership of any other team member. You can also use this endpoint to
2860
+ * delete a user membership even if it is not accepted.
2861
+ *
2862
+ * @param {string} teamId
2863
+ * @param {string} membershipId
2864
+ * @throws {AppwriteException}
2865
+ * @returns {Promise}
2866
+ */
2867
+ deleteMembership(teamId, membershipId) {
2868
+ return __awaiter(this, void 0, void 0, function* () {
2869
+ if (typeof teamId === 'undefined') {
2870
+ throw new AppwriteException('Missing required parameter: "teamId"');
2871
+ }
2872
+ if (typeof membershipId === 'undefined') {
2873
+ throw new AppwriteException('Missing required parameter: "membershipId"');
2874
+ }
2875
+ const apiPath = '/teams/{teamId}/memberships/{membershipId}'.replace('{teamId}', teamId).replace('{membershipId}', membershipId);
2876
+ const payload = {};
2877
+ const uri = new URL(this.client.config.endpoint + apiPath);
2878
+ return yield this.client.call('delete', uri, {
2879
+ 'content-type': 'application/json',
2880
+ }, payload);
2881
+ });
2882
+ }
2883
+ /**
2884
+ * Update team membership status
2885
+ *
2886
+ * Use this endpoint to allow a user to accept an invitation to join a team
2887
+ * after being redirected back to your app from the invitation email received
2888
+ * by the user.
2889
+ *
2890
+ * If the request is successful, a session for the user is automatically
2891
+ * created.
2892
+ *
2893
+ *
2894
+ * @param {string} teamId
2895
+ * @param {string} membershipId
2896
+ * @param {string} userId
2897
+ * @param {string} secret
2898
+ * @throws {AppwriteException}
2899
+ * @returns {Promise}
2900
+ */
2901
+ updateMembershipStatus(teamId, membershipId, userId, secret) {
2902
+ return __awaiter(this, void 0, void 0, function* () {
2903
+ if (typeof teamId === 'undefined') {
2904
+ throw new AppwriteException('Missing required parameter: "teamId"');
2905
+ }
2906
+ if (typeof membershipId === 'undefined') {
2907
+ throw new AppwriteException('Missing required parameter: "membershipId"');
2908
+ }
2909
+ if (typeof userId === 'undefined') {
2910
+ throw new AppwriteException('Missing required parameter: "userId"');
2911
+ }
2912
+ if (typeof secret === 'undefined') {
2913
+ throw new AppwriteException('Missing required parameter: "secret"');
2914
+ }
2915
+ const apiPath = '/teams/{teamId}/memberships/{membershipId}/status'.replace('{teamId}', teamId).replace('{membershipId}', membershipId);
2916
+ const payload = {};
2917
+ if (typeof userId !== 'undefined') {
2918
+ payload['userId'] = userId;
2919
+ }
2920
+ if (typeof secret !== 'undefined') {
2921
+ payload['secret'] = secret;
2922
+ }
2923
+ const uri = new URL(this.client.config.endpoint + apiPath);
2924
+ return yield this.client.call('patch', uri, {
2925
+ 'content-type': 'application/json',
2926
+ }, payload);
2927
+ });
2928
+ }
2929
+ /**
2930
+ * Get team preferences
2931
+ *
2932
+ * Get the team's shared preferences by its unique ID. If a preference doesn't
2933
+ * need to be shared by all team members, prefer storing them in [user
2934
+ * preferences](https://appwrite.io/docs/references/cloud/client-web/account#getPrefs).
2935
+ *
2936
+ * @param {string} teamId
2937
+ * @throws {AppwriteException}
2938
+ * @returns {Promise}
2939
+ */
2940
+ getPrefs(teamId) {
2941
+ return __awaiter(this, void 0, void 0, function* () {
2942
+ if (typeof teamId === 'undefined') {
2943
+ throw new AppwriteException('Missing required parameter: "teamId"');
2944
+ }
2945
+ const apiPath = '/teams/{teamId}/prefs'.replace('{teamId}', teamId);
2946
+ const payload = {};
2947
+ const uri = new URL(this.client.config.endpoint + apiPath);
2948
+ return yield this.client.call('get', uri, {
2949
+ 'content-type': 'application/json',
2950
+ }, payload);
2951
+ });
2952
+ }
2953
+ /**
2954
+ * Update preferences
2955
+ *
2956
+ * Update the team's preferences by its unique ID. The object you pass is
2957
+ * stored as is and replaces any previous value. The maximum allowed prefs
2958
+ * size is 64kB and throws an error if exceeded.
2959
+ *
2960
+ * @param {string} teamId
2961
+ * @param {object} prefs
2962
+ * @throws {AppwriteException}
2963
+ * @returns {Promise}
2964
+ */
2965
+ updatePrefs(teamId, prefs) {
2966
+ return __awaiter(this, void 0, void 0, function* () {
2967
+ if (typeof teamId === 'undefined') {
2968
+ throw new AppwriteException('Missing required parameter: "teamId"');
2969
+ }
2970
+ if (typeof prefs === 'undefined') {
2971
+ throw new AppwriteException('Missing required parameter: "prefs"');
2972
+ }
2973
+ const apiPath = '/teams/{teamId}/prefs'.replace('{teamId}', teamId);
2974
+ const payload = {};
2975
+ if (typeof prefs !== 'undefined') {
2976
+ payload['prefs'] = prefs;
2977
+ }
2978
+ const uri = new URL(this.client.config.endpoint + apiPath);
2979
+ return yield this.client.call('put', uri, {
2980
+ 'content-type': 'application/json',
2981
+ }, payload);
2982
+ });
2983
+ }
2984
+ }
2985
+
2986
+ class Permission {
2987
+ }
2988
+ Permission.read = (role) => {
2989
+ return `read("${role}")`;
2990
+ };
2991
+ Permission.write = (role) => {
2992
+ return `write("${role}")`;
2993
+ };
2994
+ Permission.create = (role) => {
2995
+ return `create("${role}")`;
2996
+ };
2997
+ Permission.update = (role) => {
2998
+ return `update("${role}")`;
2999
+ };
3000
+ Permission.delete = (role) => {
3001
+ return `delete("${role}")`;
3002
+ };
3003
+
3004
+ /**
3005
+ * Helper class to generate role strings for `Permission`.
3006
+ */
3007
+ class Role {
3008
+ /**
3009
+ * Grants access to anyone.
3010
+ *
3011
+ * This includes authenticated and unauthenticated users.
3012
+ *
3013
+ * @returns {string}
3014
+ */
3015
+ static any() {
3016
+ return 'any';
3017
+ }
3018
+ /**
3019
+ * Grants access to a specific user by user ID.
3020
+ *
3021
+ * You can optionally pass verified or unverified for
3022
+ * `status` to target specific types of users.
3023
+ *
3024
+ * @param {string} id
3025
+ * @param {string} status
3026
+ * @returns {string}
3027
+ */
3028
+ static user(id, status = '') {
3029
+ if (status === '') {
3030
+ return `user:${id}`;
3031
+ }
3032
+ return `user:${id}/${status}`;
3033
+ }
3034
+ /**
3035
+ * Grants access to any authenticated or anonymous user.
3036
+ *
3037
+ * You can optionally pass verified or unverified for
3038
+ * `status` to target specific types of users.
3039
+ *
3040
+ * @param {string} status
3041
+ * @returns {string}
3042
+ */
3043
+ static users(status = '') {
3044
+ if (status === '') {
3045
+ return 'users';
3046
+ }
3047
+ return `users/${status}`;
3048
+ }
3049
+ /**
3050
+ * Grants access to any guest user without a session.
3051
+ *
3052
+ * Authenticated users don't have access to this role.
3053
+ *
3054
+ * @returns {string}
3055
+ */
3056
+ static guests() {
3057
+ return 'guests';
3058
+ }
3059
+ /**
3060
+ * Grants access to a team by team ID.
3061
+ *
3062
+ * You can optionally pass a role for `role` to target
3063
+ * team members with the specified role.
3064
+ *
3065
+ * @param {string} id
3066
+ * @param {string} role
3067
+ * @returns {string}
3068
+ */
3069
+ static team(id, role = '') {
3070
+ if (role === '') {
3071
+ return `team:${id}`;
3072
+ }
3073
+ return `team:${id}/${role}`;
3074
+ }
3075
+ /**
3076
+ * Grants access to a specific member of a team.
3077
+ *
3078
+ * When the member is removed from the team, they will
3079
+ * no longer have access.
3080
+ *
3081
+ * @param {string} id
3082
+ * @returns {string}
3083
+ */
3084
+ static member(id) {
3085
+ return `member:${id}`;
3086
+ }
3087
+ /**
3088
+ * Grants access to a user with the specified label.
3089
+ *
3090
+ * @param {string} name
3091
+ * @returns {string}
3092
+ */
3093
+ static label(name) {
3094
+ return `label:${name}`;
3095
+ }
3096
+ }
3097
+
3098
+ class ID {
3099
+ static custom(id) {
3100
+ return id;
3101
+ }
3102
+ static unique() {
3103
+ return 'unique()';
3104
+ }
3105
+ }
3106
+
3107
+ export { Account, AppwriteException, Avatars, Client, Databases, Functions, Graphql, ID, Locale, Permission, Query, Role, Storage, Teams };
3108
+ //# sourceMappingURL=sdk.js.map