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