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