react-native-appwrite 0.9.1 → 0.10.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/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Change log
2
2
 
3
+ ## 0.10.0
4
+
5
+ * Add generate file URL methods like`getFilePreviewURL`, `getFileViewURL` etc.
6
+ * Update (breaking) existing methods like `getFilePreview` to download the image instead of returning URLs
7
+
8
+ ## 0.9.2
9
+
10
+ * Fix `devKeys` by removing credentials from requests when the key is set
11
+
12
+ ## 0.9.1
13
+
14
+ * Add `setDevkey` and `upsertDocument` methods
15
+
3
16
  ## 0.9.0
4
17
 
5
18
  * Add `token` param to `getFilePreview` and `getFileView` for File tokens usage
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Appwrite React Native SDK
2
2
 
3
3
  ![License](https://img.shields.io/github/license/appwrite/sdk-for-react-native.svg?style=flat-square)
4
- ![Version](https://img.shields.io/badge/api%20version-1.7.0-blue.svg?style=flat-square)
4
+ ![Version](https://img.shields.io/badge/api%20version-1.7.4-blue.svg?style=flat-square)
5
5
  [![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator)
6
6
  [![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite)
7
7
  [![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)
package/dist/cjs/sdk.js CHANGED
@@ -100,7 +100,7 @@ class Client {
100
100
  'x-sdk-name': 'React Native',
101
101
  'x-sdk-platform': 'client',
102
102
  'x-sdk-language': 'reactnative',
103
- 'x-sdk-version': '0.9.1',
103
+ 'x-sdk-version': '0.10.0',
104
104
  'X-Appwrite-Response-Format': '1.7.0',
105
105
  };
106
106
  this.realtime = {
@@ -392,7 +392,7 @@ class Client {
392
392
  };
393
393
  }
394
394
  call(method_1, url_1) {
395
- return __awaiter(this, arguments, void 0, function* (method, url, headers = {}, params = {}) {
395
+ return __awaiter(this, arguments, void 0, function* (method, url, headers = {}, params = {}, responseType = 'json') {
396
396
  var _a, _b;
397
397
  method = method.toUpperCase();
398
398
  headers = Object.assign({}, this.headers, headers);
@@ -400,8 +400,10 @@ class Client {
400
400
  let options = {
401
401
  method,
402
402
  headers,
403
- credentials: 'include'
404
403
  };
404
+ if (headers['X-Appwrite-Dev-Key'] === undefined) {
405
+ options.credentials = 'include';
406
+ }
405
407
  if (method === 'GET') {
406
408
  for (const [key, value] of Object.entries(Service.flatten(params))) {
407
409
  url.searchParams.append(key, value);
@@ -439,6 +441,9 @@ class Client {
439
441
  if ((_a = response.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.includes('application/json')) {
440
442
  data = yield response.json();
441
443
  }
444
+ else if (responseType === 'arrayBuffer') {
445
+ data = yield response.arrayBuffer();
446
+ }
442
447
  else {
443
448
  data = {
444
449
  message: yield response.text()
@@ -1725,7 +1730,7 @@ class Avatars extends Service {
1725
1730
  * @param {number} height
1726
1731
  * @param {number} quality
1727
1732
  * @throws {AppwriteException}
1728
- * @returns {URL}
1733
+ * @returns {ArrayBuffer}
1729
1734
  */
1730
1735
  getBrowser(code, width, height, quality) {
1731
1736
  if (typeof code === 'undefined') {
@@ -1747,7 +1752,7 @@ class Avatars extends Service {
1747
1752
  for (const [key, value] of Object.entries(Service.flatten(payload))) {
1748
1753
  uri.searchParams.append(key, value);
1749
1754
  }
1750
- return uri;
1755
+ return this.client.call('get', uri, {}, payload, 'arrayBuffer');
1751
1756
  }
1752
1757
  /**
1753
1758
  * The credit card endpoint will return you the icon of the credit card
@@ -1765,7 +1770,7 @@ class Avatars extends Service {
1765
1770
  * @param {number} height
1766
1771
  * @param {number} quality
1767
1772
  * @throws {AppwriteException}
1768
- * @returns {URL}
1773
+ * @returns {ArrayBuffer}
1769
1774
  */
1770
1775
  getCreditCard(code, width, height, quality) {
1771
1776
  if (typeof code === 'undefined') {
@@ -1787,7 +1792,7 @@ class Avatars extends Service {
1787
1792
  for (const [key, value] of Object.entries(Service.flatten(payload))) {
1788
1793
  uri.searchParams.append(key, value);
1789
1794
  }
1790
- return uri;
1795
+ return this.client.call('get', uri, {}, payload, 'arrayBuffer');
1791
1796
  }
1792
1797
  /**
1793
1798
  * Use this endpoint to fetch the favorite icon (AKA favicon) of any remote
@@ -1797,7 +1802,7 @@ class Avatars extends Service {
1797
1802
  *
1798
1803
  * @param {string} url
1799
1804
  * @throws {AppwriteException}
1800
- * @returns {URL}
1805
+ * @returns {ArrayBuffer}
1801
1806
  */
1802
1807
  getFavicon(url) {
1803
1808
  if (typeof url === 'undefined') {
@@ -1813,7 +1818,7 @@ class Avatars extends Service {
1813
1818
  for (const [key, value] of Object.entries(Service.flatten(payload))) {
1814
1819
  uri.searchParams.append(key, value);
1815
1820
  }
1816
- return uri;
1821
+ return this.client.call('get', uri, {}, payload, 'arrayBuffer');
1817
1822
  }
1818
1823
  /**
1819
1824
  * You can use this endpoint to show different country flags icons to your
@@ -1832,7 +1837,7 @@ class Avatars extends Service {
1832
1837
  * @param {number} height
1833
1838
  * @param {number} quality
1834
1839
  * @throws {AppwriteException}
1835
- * @returns {URL}
1840
+ * @returns {ArrayBuffer}
1836
1841
  */
1837
1842
  getFlag(code, width, height, quality) {
1838
1843
  if (typeof code === 'undefined') {
@@ -1854,7 +1859,7 @@ class Avatars extends Service {
1854
1859
  for (const [key, value] of Object.entries(Service.flatten(payload))) {
1855
1860
  uri.searchParams.append(key, value);
1856
1861
  }
1857
- return uri;
1862
+ return this.client.call('get', uri, {}, payload, 'arrayBuffer');
1858
1863
  }
1859
1864
  /**
1860
1865
  * Use this endpoint to fetch a remote image URL and crop it to any image size
@@ -1873,7 +1878,7 @@ class Avatars extends Service {
1873
1878
  * @param {number} width
1874
1879
  * @param {number} height
1875
1880
  * @throws {AppwriteException}
1876
- * @returns {URL}
1881
+ * @returns {ArrayBuffer}
1877
1882
  */
1878
1883
  getImage(url, width, height) {
1879
1884
  if (typeof url === 'undefined') {
@@ -1895,7 +1900,7 @@ class Avatars extends Service {
1895
1900
  for (const [key, value] of Object.entries(Service.flatten(payload))) {
1896
1901
  uri.searchParams.append(key, value);
1897
1902
  }
1898
- return uri;
1903
+ return this.client.call('get', uri, {}, payload, 'arrayBuffer');
1899
1904
  }
1900
1905
  /**
1901
1906
  * Use this endpoint to show your user initials avatar icon on your website or
@@ -1920,7 +1925,7 @@ class Avatars extends Service {
1920
1925
  * @param {number} height
1921
1926
  * @param {string} background
1922
1927
  * @throws {AppwriteException}
1923
- * @returns {URL}
1928
+ * @returns {ArrayBuffer}
1924
1929
  */
1925
1930
  getInitials(name, width, height, background) {
1926
1931
  const apiPath = '/avatars/initials';
@@ -1942,7 +1947,7 @@ class Avatars extends Service {
1942
1947
  for (const [key, value] of Object.entries(Service.flatten(payload))) {
1943
1948
  uri.searchParams.append(key, value);
1944
1949
  }
1945
- return uri;
1950
+ return this.client.call('get', uri, {}, payload, 'arrayBuffer');
1946
1951
  }
1947
1952
  /**
1948
1953
  * Converts a given plain text to a QR code image. You can use the query
@@ -1954,7 +1959,7 @@ class Avatars extends Service {
1954
1959
  * @param {number} margin
1955
1960
  * @param {boolean} download
1956
1961
  * @throws {AppwriteException}
1957
- * @returns {URL}
1962
+ * @returns {ArrayBuffer}
1958
1963
  */
1959
1964
  getQR(text, size, margin, download) {
1960
1965
  if (typeof text === 'undefined') {
@@ -1979,6 +1984,163 @@ class Avatars extends Service {
1979
1984
  for (const [key, value] of Object.entries(Service.flatten(payload))) {
1980
1985
  uri.searchParams.append(key, value);
1981
1986
  }
1987
+ return this.client.call('get', uri, {}, payload, 'arrayBuffer');
1988
+ }
1989
+ /**
1990
+ * You can use this endpoint to show different browser icons to your users.
1991
+ * The code argument receives the browser code as it appears in your user [GET
1992
+ * /account/sessions](https://appwrite.io/docs/references/cloud/client-web/account#getSessions)
1993
+ * endpoint. Use width, height and quality arguments to change the output
1994
+ * settings.
1995
+ *
1996
+ * When one dimension is specified and the other is 0, the image is scaled
1997
+ * with preserved aspect ratio. If both dimensions are 0, the API provides an
1998
+ * image at source quality. If dimensions are not specified, the default size
1999
+ * of image returned is 100x100px.
2000
+ *
2001
+ * @param {Browser} code
2002
+ * @param {number} width
2003
+ * @param {number} height
2004
+ * @param {number} quality
2005
+ * @throws {AppwriteException}
2006
+ * @returns {URL}
2007
+ */
2008
+ getBrowserURL(code, width, height, quality) {
2009
+ const apiPath = '/avatars/browsers/{code}'.replace('{code}', code);
2010
+ const uri = new URL(this.client.config.endpoint + apiPath);
2011
+ return uri;
2012
+ }
2013
+ /**
2014
+ * The credit card endpoint will return you the icon of the credit card
2015
+ * provider you need. Use width, height and quality arguments to change the
2016
+ * output settings.
2017
+ *
2018
+ * When one dimension is specified and the other is 0, the image is scaled
2019
+ * with preserved aspect ratio. If both dimensions are 0, the API provides an
2020
+ * image at source quality. If dimensions are not specified, the default size
2021
+ * of image returned is 100x100px.
2022
+ *
2023
+ *
2024
+ * @param {CreditCard} code
2025
+ * @param {number} width
2026
+ * @param {number} height
2027
+ * @param {number} quality
2028
+ * @throws {AppwriteException}
2029
+ * @returns {URL}
2030
+ */
2031
+ getCreditCardURL(code, width, height, quality) {
2032
+ const apiPath = '/avatars/credit-cards/{code}'.replace('{code}', code);
2033
+ const uri = new URL(this.client.config.endpoint + apiPath);
2034
+ return uri;
2035
+ }
2036
+ /**
2037
+ * Use this endpoint to fetch the favorite icon (AKA favicon) of any remote
2038
+ * website URL.
2039
+ *
2040
+ * This endpoint does not follow HTTP redirects.
2041
+ *
2042
+ * @param {string} url
2043
+ * @throws {AppwriteException}
2044
+ * @returns {URL}
2045
+ */
2046
+ getFaviconURL(url) {
2047
+ const apiPath = '/avatars/favicon';
2048
+ const uri = new URL(this.client.config.endpoint + apiPath);
2049
+ return uri;
2050
+ }
2051
+ /**
2052
+ * You can use this endpoint to show different country flags icons to your
2053
+ * users. The code argument receives the 2 letter country code. Use width,
2054
+ * height and quality arguments to change the output settings. Country codes
2055
+ * follow the [ISO 3166-1](https://en.wikipedia.org/wiki/ISO_3166-1) standard.
2056
+ *
2057
+ * When one dimension is specified and the other is 0, the image is scaled
2058
+ * with preserved aspect ratio. If both dimensions are 0, the API provides an
2059
+ * image at source quality. If dimensions are not specified, the default size
2060
+ * of image returned is 100x100px.
2061
+ *
2062
+ *
2063
+ * @param {Flag} code
2064
+ * @param {number} width
2065
+ * @param {number} height
2066
+ * @param {number} quality
2067
+ * @throws {AppwriteException}
2068
+ * @returns {URL}
2069
+ */
2070
+ getFlagURL(code, width, height, quality) {
2071
+ const apiPath = '/avatars/flags/{code}'.replace('{code}', code);
2072
+ const uri = new URL(this.client.config.endpoint + apiPath);
2073
+ return uri;
2074
+ }
2075
+ /**
2076
+ * Use this endpoint to fetch a remote image URL and crop it to any image size
2077
+ * you want. This endpoint is very useful if you need to crop and display
2078
+ * remote images in your app or in case you want to make sure a 3rd party
2079
+ * image is properly served using a TLS protocol.
2080
+ *
2081
+ * When one dimension is specified and the other is 0, the image is scaled
2082
+ * with preserved aspect ratio. If both dimensions are 0, the API provides an
2083
+ * image at source quality. If dimensions are not specified, the default size
2084
+ * of image returned is 400x400px.
2085
+ *
2086
+ * This endpoint does not follow HTTP redirects.
2087
+ *
2088
+ * @param {string} url
2089
+ * @param {number} width
2090
+ * @param {number} height
2091
+ * @throws {AppwriteException}
2092
+ * @returns {URL}
2093
+ */
2094
+ getImageURL(url, width, height) {
2095
+ const apiPath = '/avatars/image';
2096
+ const uri = new URL(this.client.config.endpoint + apiPath);
2097
+ return uri;
2098
+ }
2099
+ /**
2100
+ * Use this endpoint to show your user initials avatar icon on your website or
2101
+ * app. By default, this route will try to print your logged-in user name or
2102
+ * email initials. You can also overwrite the user name if you pass the 'name'
2103
+ * parameter. If no name is given and no user is logged, an empty avatar will
2104
+ * be returned.
2105
+ *
2106
+ * You can use the color and background params to change the avatar colors. By
2107
+ * default, a random theme will be selected. The random theme will persist for
2108
+ * the user's initials when reloading the same theme will always return for
2109
+ * the same initials.
2110
+ *
2111
+ * When one dimension is specified and the other is 0, the image is scaled
2112
+ * with preserved aspect ratio. If both dimensions are 0, the API provides an
2113
+ * image at source quality. If dimensions are not specified, the default size
2114
+ * of image returned is 100x100px.
2115
+ *
2116
+ *
2117
+ * @param {string} name
2118
+ * @param {number} width
2119
+ * @param {number} height
2120
+ * @param {string} background
2121
+ * @throws {AppwriteException}
2122
+ * @returns {URL}
2123
+ */
2124
+ getInitialsURL(name, width, height, background) {
2125
+ const apiPath = '/avatars/initials';
2126
+ const uri = new URL(this.client.config.endpoint + apiPath);
2127
+ return uri;
2128
+ }
2129
+ /**
2130
+ * Converts a given plain text to a QR code image. You can use the query
2131
+ * parameters to change the size and style of the resulting image.
2132
+ *
2133
+ *
2134
+ * @param {string} text
2135
+ * @param {number} size
2136
+ * @param {number} margin
2137
+ * @param {boolean} download
2138
+ * @throws {AppwriteException}
2139
+ * @returns {URL}
2140
+ */
2141
+ getQRURL(text, size, margin, download) {
2142
+ const apiPath = '/avatars/qr';
2143
+ const uri = new URL(this.client.config.endpoint + apiPath);
1982
2144
  return uri;
1983
2145
  }
1984
2146
  }
@@ -2717,7 +2879,7 @@ class Storage extends Service {
2717
2879
  * @param {string} fileId
2718
2880
  * @param {string} token
2719
2881
  * @throws {AppwriteException}
2720
- * @returns {URL}
2882
+ * @returns {ArrayBuffer}
2721
2883
  */
2722
2884
  getFileDownload(bucketId, fileId, token) {
2723
2885
  if (typeof bucketId === 'undefined') {
@@ -2736,7 +2898,7 @@ class Storage extends Service {
2736
2898
  for (const [key, value] of Object.entries(Service.flatten(payload))) {
2737
2899
  uri.searchParams.append(key, value);
2738
2900
  }
2739
- return uri;
2901
+ return this.client.call('get', uri, {}, payload, 'arrayBuffer');
2740
2902
  }
2741
2903
  /**
2742
2904
  * Get a file preview image. Currently, this method supports preview for image
@@ -2760,7 +2922,7 @@ class Storage extends Service {
2760
2922
  * @param {ImageFormat} output
2761
2923
  * @param {string} token
2762
2924
  * @throws {AppwriteException}
2763
- * @returns {URL}
2925
+ * @returns {ArrayBuffer}
2764
2926
  */
2765
2927
  getFilePreview(bucketId, fileId, width, height, gravity, quality, borderWidth, borderColor, borderRadius, opacity, rotation, background, output, token) {
2766
2928
  if (typeof bucketId === 'undefined') {
@@ -2812,7 +2974,7 @@ class Storage extends Service {
2812
2974
  for (const [key, value] of Object.entries(Service.flatten(payload))) {
2813
2975
  uri.searchParams.append(key, value);
2814
2976
  }
2815
- return uri;
2977
+ return this.client.call('get', uri, {}, payload, 'arrayBuffer');
2816
2978
  }
2817
2979
  /**
2818
2980
  * Get a file content by its unique ID. This endpoint is similar to the
@@ -2823,7 +2985,7 @@ class Storage extends Service {
2823
2985
  * @param {string} fileId
2824
2986
  * @param {string} token
2825
2987
  * @throws {AppwriteException}
2826
- * @returns {URL}
2988
+ * @returns {ArrayBuffer}
2827
2989
  */
2828
2990
  getFileView(bucketId, fileId, token) {
2829
2991
  if (typeof bucketId === 'undefined') {
@@ -2842,6 +3004,67 @@ class Storage extends Service {
2842
3004
  for (const [key, value] of Object.entries(Service.flatten(payload))) {
2843
3005
  uri.searchParams.append(key, value);
2844
3006
  }
3007
+ return this.client.call('get', uri, {}, payload, 'arrayBuffer');
3008
+ }
3009
+ /**
3010
+ * Get a file content by its unique ID. The endpoint response return with a
3011
+ * 'Content-Disposition: attachment' header that tells the browser to start
3012
+ * downloading the file to user downloads directory.
3013
+ *
3014
+ * @param {string} bucketId
3015
+ * @param {string} fileId
3016
+ * @param {string} token
3017
+ * @throws {AppwriteException}
3018
+ * @returns {URL}
3019
+ */
3020
+ getFileDownloadURL(bucketId, fileId, token) {
3021
+ const apiPath = '/storage/buckets/{bucketId}/files/{fileId}/download'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
3022
+ const uri = new URL(this.client.config.endpoint + apiPath);
3023
+ return uri;
3024
+ }
3025
+ /**
3026
+ * Get a file preview image. Currently, this method supports preview for image
3027
+ * files (jpg, png, and gif), other supported formats, like pdf, docs, slides,
3028
+ * and spreadsheets, will return the file icon image. You can also pass query
3029
+ * string arguments for cutting and resizing your preview image. Preview is
3030
+ * supported only for image files smaller than 10MB.
3031
+ *
3032
+ * @param {string} bucketId
3033
+ * @param {string} fileId
3034
+ * @param {number} width
3035
+ * @param {number} height
3036
+ * @param {ImageGravity} gravity
3037
+ * @param {number} quality
3038
+ * @param {number} borderWidth
3039
+ * @param {string} borderColor
3040
+ * @param {number} borderRadius
3041
+ * @param {number} opacity
3042
+ * @param {number} rotation
3043
+ * @param {string} background
3044
+ * @param {ImageFormat} output
3045
+ * @param {string} token
3046
+ * @throws {AppwriteException}
3047
+ * @returns {URL}
3048
+ */
3049
+ getFilePreviewURL(bucketId, fileId, width, height, gravity, quality, borderWidth, borderColor, borderRadius, opacity, rotation, background, output, token) {
3050
+ const apiPath = '/storage/buckets/{bucketId}/files/{fileId}/preview'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
3051
+ const uri = new URL(this.client.config.endpoint + apiPath);
3052
+ return uri;
3053
+ }
3054
+ /**
3055
+ * Get a file content by its unique ID. This endpoint is similar to the
3056
+ * download method but returns with no 'Content-Disposition: attachment'
3057
+ * header.
3058
+ *
3059
+ * @param {string} bucketId
3060
+ * @param {string} fileId
3061
+ * @param {string} token
3062
+ * @throws {AppwriteException}
3063
+ * @returns {URL}
3064
+ */
3065
+ getFileViewURL(bucketId, fileId, token) {
3066
+ const apiPath = '/storage/buckets/{bucketId}/files/{fileId}/view'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
3067
+ const uri = new URL(this.client.config.endpoint + apiPath);
2845
3068
  return uri;
2846
3069
  }
2847
3070
  }