react-native-appwrite 0.9.2 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "react-native-appwrite",
3
3
  "homepage": "https://appwrite.io/support",
4
4
  "description": "Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API",
5
- "version": "0.9.2",
5
+ "version": "0.10.1",
6
6
  "license": "BSD-3-Clause",
7
7
  "main": "dist/cjs/sdk.js",
8
8
  "exports": {
package/src/client.ts CHANGED
@@ -115,7 +115,7 @@ class Client {
115
115
  'x-sdk-name': 'React Native',
116
116
  'x-sdk-platform': 'client',
117
117
  'x-sdk-language': 'reactnative',
118
- 'x-sdk-version': '0.9.2',
118
+ 'x-sdk-version': '0.10.1',
119
119
  'X-Appwrite-Response-Format': '1.7.0',
120
120
  };
121
121
 
@@ -432,7 +432,7 @@ class Client {
432
432
  }
433
433
  }
434
434
 
435
- async call(method: string, url: URL, headers: Headers = {}, params: Payload = {}): Promise<any> {
435
+ async call(method: string, url: URL, headers: Headers = {}, params: Payload = {}, responseType = 'json'): Promise<any> {
436
436
  method = method.toUpperCase();
437
437
 
438
438
  headers = Object.assign({}, this.headers, headers);
@@ -488,6 +488,8 @@ class Client {
488
488
 
489
489
  if (response.headers.get('content-type')?.includes('application/json')) {
490
490
  data = await response.json();
491
+ } else if (responseType === 'arrayBuffer') {
492
+ data = await response.arrayBuffer();
491
493
  } else {
492
494
  data = {
493
495
  message: await response.text()
@@ -5,4 +5,5 @@ export enum ImageFormat {
5
5
  Webp = 'webp',
6
6
  Heic = 'heic',
7
7
  Avif = 'avif',
8
+ Gif = 'gif',
8
9
  }
@@ -33,9 +33,9 @@ export class Avatars extends Service {
33
33
  * @param {number} height
34
34
  * @param {number} quality
35
35
  * @throws {AppwriteException}
36
- * @returns {URL}
36
+ * @returns {ArrayBuffer}
37
37
  */
38
- getBrowser(code: Browser, width?: number, height?: number, quality?: number): URL {
38
+ getBrowser(code: Browser, width?: number, height?: number, quality?: number): Promise<ArrayBuffer> {
39
39
  if (typeof code === 'undefined') {
40
40
  throw new AppwriteException('Missing required parameter: "code"');
41
41
  }
@@ -62,7 +62,8 @@ export class Avatars extends Service {
62
62
  for (const [key, value] of Object.entries(Service.flatten(payload))) {
63
63
  uri.searchParams.append(key, value);
64
64
  }
65
- return uri;
65
+ return this.client.call('get', uri, {
66
+ }, payload, 'arrayBuffer');
66
67
  }
67
68
 
68
69
  /**
@@ -81,9 +82,9 @@ export class Avatars extends Service {
81
82
  * @param {number} height
82
83
  * @param {number} quality
83
84
  * @throws {AppwriteException}
84
- * @returns {URL}
85
+ * @returns {ArrayBuffer}
85
86
  */
86
- getCreditCard(code: CreditCard, width?: number, height?: number, quality?: number): URL {
87
+ getCreditCard(code: CreditCard, width?: number, height?: number, quality?: number): Promise<ArrayBuffer> {
87
88
  if (typeof code === 'undefined') {
88
89
  throw new AppwriteException('Missing required parameter: "code"');
89
90
  }
@@ -110,7 +111,8 @@ export class Avatars extends Service {
110
111
  for (const [key, value] of Object.entries(Service.flatten(payload))) {
111
112
  uri.searchParams.append(key, value);
112
113
  }
113
- return uri;
114
+ return this.client.call('get', uri, {
115
+ }, payload, 'arrayBuffer');
114
116
  }
115
117
 
116
118
  /**
@@ -121,9 +123,9 @@ export class Avatars extends Service {
121
123
  *
122
124
  * @param {string} url
123
125
  * @throws {AppwriteException}
124
- * @returns {URL}
126
+ * @returns {ArrayBuffer}
125
127
  */
126
- getFavicon(url: string): URL {
128
+ getFavicon(url: string): Promise<ArrayBuffer> {
127
129
  if (typeof url === 'undefined') {
128
130
  throw new AppwriteException('Missing required parameter: "url"');
129
131
  }
@@ -142,7 +144,8 @@ export class Avatars extends Service {
142
144
  for (const [key, value] of Object.entries(Service.flatten(payload))) {
143
145
  uri.searchParams.append(key, value);
144
146
  }
145
- return uri;
147
+ return this.client.call('get', uri, {
148
+ }, payload, 'arrayBuffer');
146
149
  }
147
150
 
148
151
  /**
@@ -162,9 +165,9 @@ export class Avatars extends Service {
162
165
  * @param {number} height
163
166
  * @param {number} quality
164
167
  * @throws {AppwriteException}
165
- * @returns {URL}
168
+ * @returns {ArrayBuffer}
166
169
  */
167
- getFlag(code: Flag, width?: number, height?: number, quality?: number): URL {
170
+ getFlag(code: Flag, width?: number, height?: number, quality?: number): Promise<ArrayBuffer> {
168
171
  if (typeof code === 'undefined') {
169
172
  throw new AppwriteException('Missing required parameter: "code"');
170
173
  }
@@ -191,7 +194,8 @@ export class Avatars extends Service {
191
194
  for (const [key, value] of Object.entries(Service.flatten(payload))) {
192
195
  uri.searchParams.append(key, value);
193
196
  }
194
- return uri;
197
+ return this.client.call('get', uri, {
198
+ }, payload, 'arrayBuffer');
195
199
  }
196
200
 
197
201
  /**
@@ -211,9 +215,9 @@ export class Avatars extends Service {
211
215
  * @param {number} width
212
216
  * @param {number} height
213
217
  * @throws {AppwriteException}
214
- * @returns {URL}
218
+ * @returns {ArrayBuffer}
215
219
  */
216
- getImage(url: string, width?: number, height?: number): URL {
220
+ getImage(url: string, width?: number, height?: number): Promise<ArrayBuffer> {
217
221
  if (typeof url === 'undefined') {
218
222
  throw new AppwriteException('Missing required parameter: "url"');
219
223
  }
@@ -240,7 +244,8 @@ export class Avatars extends Service {
240
244
  for (const [key, value] of Object.entries(Service.flatten(payload))) {
241
245
  uri.searchParams.append(key, value);
242
246
  }
243
- return uri;
247
+ return this.client.call('get', uri, {
248
+ }, payload, 'arrayBuffer');
244
249
  }
245
250
 
246
251
  /**
@@ -266,9 +271,9 @@ export class Avatars extends Service {
266
271
  * @param {number} height
267
272
  * @param {string} background
268
273
  * @throws {AppwriteException}
269
- * @returns {URL}
274
+ * @returns {ArrayBuffer}
270
275
  */
271
- getInitials(name?: string, width?: number, height?: number, background?: string): URL {
276
+ getInitials(name?: string, width?: number, height?: number, background?: string): Promise<ArrayBuffer> {
272
277
  const apiPath = '/avatars/initials';
273
278
  const payload: Payload = {};
274
279
 
@@ -295,7 +300,8 @@ export class Avatars extends Service {
295
300
  for (const [key, value] of Object.entries(Service.flatten(payload))) {
296
301
  uri.searchParams.append(key, value);
297
302
  }
298
- return uri;
303
+ return this.client.call('get', uri, {
304
+ }, payload, 'arrayBuffer');
299
305
  }
300
306
 
301
307
  /**
@@ -308,9 +314,9 @@ export class Avatars extends Service {
308
314
  * @param {number} margin
309
315
  * @param {boolean} download
310
316
  * @throws {AppwriteException}
311
- * @returns {URL}
317
+ * @returns {ArrayBuffer}
312
318
  */
313
- getQR(text: string, size?: number, margin?: number, download?: boolean): URL {
319
+ getQR(text: string, size?: number, margin?: number, download?: boolean): Promise<ArrayBuffer> {
314
320
  if (typeof text === 'undefined') {
315
321
  throw new AppwriteException('Missing required parameter: "text"');
316
322
  }
@@ -341,6 +347,311 @@ export class Avatars extends Service {
341
347
  for (const [key, value] of Object.entries(Service.flatten(payload))) {
342
348
  uri.searchParams.append(key, value);
343
349
  }
350
+ return this.client.call('get', uri, {
351
+ }, payload, 'arrayBuffer');
352
+ }
353
+
354
+ /**
355
+ * You can use this endpoint to show different browser icons to your users.
356
+ * The code argument receives the browser code as it appears in your user [GET
357
+ * /account/sessions](https://appwrite.io/docs/references/cloud/client-web/account#getSessions)
358
+ * endpoint. Use width, height and quality arguments to change the output
359
+ * settings.
360
+ *
361
+ * When one dimension is specified and the other is 0, the image is scaled
362
+ * with preserved aspect ratio. If both dimensions are 0, the API provides an
363
+ * image at source quality. If dimensions are not specified, the default size
364
+ * of image returned is 100x100px.
365
+ *
366
+ * @param {Browser} code
367
+ * @param {number} width
368
+ * @param {number} height
369
+ * @param {number} quality
370
+ * @throws {AppwriteException}
371
+ * @returns {URL}
372
+ */
373
+ getBrowserURL(code: Browser, width?: number, height?: number, quality?: number): URL {
374
+ const apiPath = '/avatars/browsers/{code}'.replace('{code}', code);
375
+ const payload: Payload = {};
376
+
377
+ if (typeof width !== 'undefined') {
378
+ payload['width'] = width;
379
+ }
380
+
381
+ if (typeof height !== 'undefined') {
382
+ payload['height'] = height;
383
+ }
384
+
385
+ if (typeof quality !== 'undefined') {
386
+ payload['quality'] = quality;
387
+ }
388
+
389
+ const uri = new URL(this.client.config.endpoint + apiPath);
390
+ payload['project'] = this.client.config.project;
391
+
392
+ for (const [key, value] of Object.entries(Service.flatten(payload))) {
393
+ uri.searchParams.append(key, value);
394
+ }
395
+
396
+ return uri;
397
+ }
398
+
399
+ /**
400
+ * The credit card endpoint will return you the icon of the credit card
401
+ * provider you need. Use width, height and quality arguments to change the
402
+ * output settings.
403
+ *
404
+ * When one dimension is specified and the other is 0, the image is scaled
405
+ * with preserved aspect ratio. If both dimensions are 0, the API provides an
406
+ * image at source quality. If dimensions are not specified, the default size
407
+ * of image returned is 100x100px.
408
+ *
409
+ *
410
+ * @param {CreditCard} code
411
+ * @param {number} width
412
+ * @param {number} height
413
+ * @param {number} quality
414
+ * @throws {AppwriteException}
415
+ * @returns {URL}
416
+ */
417
+ getCreditCardURL(code: CreditCard, width?: number, height?: number, quality?: number): URL {
418
+ const apiPath = '/avatars/credit-cards/{code}'.replace('{code}', code);
419
+ const payload: Payload = {};
420
+
421
+ if (typeof width !== 'undefined') {
422
+ payload['width'] = width;
423
+ }
424
+
425
+ if (typeof height !== 'undefined') {
426
+ payload['height'] = height;
427
+ }
428
+
429
+ if (typeof quality !== 'undefined') {
430
+ payload['quality'] = quality;
431
+ }
432
+
433
+ const uri = new URL(this.client.config.endpoint + apiPath);
434
+ payload['project'] = this.client.config.project;
435
+
436
+ for (const [key, value] of Object.entries(Service.flatten(payload))) {
437
+ uri.searchParams.append(key, value);
438
+ }
439
+
440
+ return uri;
441
+ }
442
+
443
+ /**
444
+ * Use this endpoint to fetch the favorite icon (AKA favicon) of any remote
445
+ * website URL.
446
+ *
447
+ * This endpoint does not follow HTTP redirects.
448
+ *
449
+ * @param {string} url
450
+ * @throws {AppwriteException}
451
+ * @returns {URL}
452
+ */
453
+ getFaviconURL(url: string): URL {
454
+ const apiPath = '/avatars/favicon';
455
+ const payload: Payload = {};
456
+
457
+ if (typeof url !== 'undefined') {
458
+ payload['url'] = url;
459
+ }
460
+
461
+ const uri = new URL(this.client.config.endpoint + apiPath);
462
+ payload['project'] = this.client.config.project;
463
+
464
+ for (const [key, value] of Object.entries(Service.flatten(payload))) {
465
+ uri.searchParams.append(key, value);
466
+ }
467
+
468
+ return uri;
469
+ }
470
+
471
+ /**
472
+ * You can use this endpoint to show different country flags icons to your
473
+ * users. The code argument receives the 2 letter country code. Use width,
474
+ * height and quality arguments to change the output settings. Country codes
475
+ * follow the [ISO 3166-1](https://en.wikipedia.org/wiki/ISO_3166-1) standard.
476
+ *
477
+ * When one dimension is specified and the other is 0, the image is scaled
478
+ * with preserved aspect ratio. If both dimensions are 0, the API provides an
479
+ * image at source quality. If dimensions are not specified, the default size
480
+ * of image returned is 100x100px.
481
+ *
482
+ *
483
+ * @param {Flag} code
484
+ * @param {number} width
485
+ * @param {number} height
486
+ * @param {number} quality
487
+ * @throws {AppwriteException}
488
+ * @returns {URL}
489
+ */
490
+ getFlagURL(code: Flag, width?: number, height?: number, quality?: number): URL {
491
+ const apiPath = '/avatars/flags/{code}'.replace('{code}', code);
492
+ const payload: Payload = {};
493
+
494
+ if (typeof width !== 'undefined') {
495
+ payload['width'] = width;
496
+ }
497
+
498
+ if (typeof height !== 'undefined') {
499
+ payload['height'] = height;
500
+ }
501
+
502
+ if (typeof quality !== 'undefined') {
503
+ payload['quality'] = quality;
504
+ }
505
+
506
+ const uri = new URL(this.client.config.endpoint + apiPath);
507
+ payload['project'] = this.client.config.project;
508
+
509
+ for (const [key, value] of Object.entries(Service.flatten(payload))) {
510
+ uri.searchParams.append(key, value);
511
+ }
512
+
513
+ return uri;
514
+ }
515
+
516
+ /**
517
+ * Use this endpoint to fetch a remote image URL and crop it to any image size
518
+ * you want. This endpoint is very useful if you need to crop and display
519
+ * remote images in your app or in case you want to make sure a 3rd party
520
+ * image is properly served using a TLS protocol.
521
+ *
522
+ * When one dimension is specified and the other is 0, the image is scaled
523
+ * with preserved aspect ratio. If both dimensions are 0, the API provides an
524
+ * image at source quality. If dimensions are not specified, the default size
525
+ * of image returned is 400x400px.
526
+ *
527
+ * This endpoint does not follow HTTP redirects.
528
+ *
529
+ * @param {string} url
530
+ * @param {number} width
531
+ * @param {number} height
532
+ * @throws {AppwriteException}
533
+ * @returns {URL}
534
+ */
535
+ getImageURL(url: string, width?: number, height?: number): URL {
536
+ const apiPath = '/avatars/image';
537
+ const payload: Payload = {};
538
+
539
+ if (typeof url !== 'undefined') {
540
+ payload['url'] = url;
541
+ }
542
+
543
+ if (typeof width !== 'undefined') {
544
+ payload['width'] = width;
545
+ }
546
+
547
+ if (typeof height !== 'undefined') {
548
+ payload['height'] = height;
549
+ }
550
+
551
+ const uri = new URL(this.client.config.endpoint + apiPath);
552
+ payload['project'] = this.client.config.project;
553
+
554
+ for (const [key, value] of Object.entries(Service.flatten(payload))) {
555
+ uri.searchParams.append(key, value);
556
+ }
557
+
558
+ return uri;
559
+ }
560
+
561
+ /**
562
+ * Use this endpoint to show your user initials avatar icon on your website or
563
+ * app. By default, this route will try to print your logged-in user name or
564
+ * email initials. You can also overwrite the user name if you pass the 'name'
565
+ * parameter. If no name is given and no user is logged, an empty avatar will
566
+ * be returned.
567
+ *
568
+ * You can use the color and background params to change the avatar colors. By
569
+ * default, a random theme will be selected. The random theme will persist for
570
+ * the user's initials when reloading the same theme will always return for
571
+ * the same initials.
572
+ *
573
+ * When one dimension is specified and the other is 0, the image is scaled
574
+ * with preserved aspect ratio. If both dimensions are 0, the API provides an
575
+ * image at source quality. If dimensions are not specified, the default size
576
+ * of image returned is 100x100px.
577
+ *
578
+ *
579
+ * @param {string} name
580
+ * @param {number} width
581
+ * @param {number} height
582
+ * @param {string} background
583
+ * @throws {AppwriteException}
584
+ * @returns {URL}
585
+ */
586
+ getInitialsURL(name?: string, width?: number, height?: number, background?: string): URL {
587
+ const apiPath = '/avatars/initials';
588
+ const payload: Payload = {};
589
+
590
+ if (typeof name !== 'undefined') {
591
+ payload['name'] = name;
592
+ }
593
+
594
+ if (typeof width !== 'undefined') {
595
+ payload['width'] = width;
596
+ }
597
+
598
+ if (typeof height !== 'undefined') {
599
+ payload['height'] = height;
600
+ }
601
+
602
+ if (typeof background !== 'undefined') {
603
+ payload['background'] = background;
604
+ }
605
+
606
+ const uri = new URL(this.client.config.endpoint + apiPath);
607
+ payload['project'] = this.client.config.project;
608
+
609
+ for (const [key, value] of Object.entries(Service.flatten(payload))) {
610
+ uri.searchParams.append(key, value);
611
+ }
612
+
613
+ return uri;
614
+ }
615
+
616
+ /**
617
+ * Converts a given plain text to a QR code image. You can use the query
618
+ * parameters to change the size and style of the resulting image.
619
+ *
620
+ *
621
+ * @param {string} text
622
+ * @param {number} size
623
+ * @param {number} margin
624
+ * @param {boolean} download
625
+ * @throws {AppwriteException}
626
+ * @returns {URL}
627
+ */
628
+ getQRURL(text: string, size?: number, margin?: number, download?: boolean): URL {
629
+ const apiPath = '/avatars/qr';
630
+ const payload: Payload = {};
631
+
632
+ if (typeof text !== 'undefined') {
633
+ payload['text'] = text;
634
+ }
635
+
636
+ if (typeof size !== 'undefined') {
637
+ payload['size'] = size;
638
+ }
639
+
640
+ if (typeof margin !== 'undefined') {
641
+ payload['margin'] = margin;
642
+ }
643
+
644
+ if (typeof download !== 'undefined') {
645
+ payload['download'] = download;
646
+ }
647
+
648
+ const uri = new URL(this.client.config.endpoint + apiPath);
649
+ payload['project'] = this.client.config.project;
650
+
651
+ for (const [key, value] of Object.entries(Service.flatten(payload))) {
652
+ uri.searchParams.append(key, value);
653
+ }
654
+
344
655
  return uri;
345
656
  }
346
657
  };
@@ -133,6 +133,10 @@ export class Databases extends Service {
133
133
  }
134
134
 
135
135
  /**
136
+ * **WARNING: Experimental Feature** - This endpoint is experimental and not
137
+ * yet officially supported. It may be subject to breaking changes or removal
138
+ * in future versions.
139
+ *
136
140
  * Create or update a Document. Before using this route, you should create a
137
141
  * new collection resource using either a [server
138
142
  * integration](https://appwrite.io/docs/server/databases#databasesCreateCollection)