react-native-appwrite 0.9.2 → 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.2',
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);
@@ -441,6 +441,9 @@ class Client {
441
441
  if ((_a = response.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.includes('application/json')) {
442
442
  data = yield response.json();
443
443
  }
444
+ else if (responseType === 'arrayBuffer') {
445
+ data = yield response.arrayBuffer();
446
+ }
444
447
  else {
445
448
  data = {
446
449
  message: yield response.text()
@@ -1727,7 +1730,7 @@ class Avatars extends Service {
1727
1730
  * @param {number} height
1728
1731
  * @param {number} quality
1729
1732
  * @throws {AppwriteException}
1730
- * @returns {URL}
1733
+ * @returns {ArrayBuffer}
1731
1734
  */
1732
1735
  getBrowser(code, width, height, quality) {
1733
1736
  if (typeof code === 'undefined') {
@@ -1749,7 +1752,7 @@ class Avatars extends Service {
1749
1752
  for (const [key, value] of Object.entries(Service.flatten(payload))) {
1750
1753
  uri.searchParams.append(key, value);
1751
1754
  }
1752
- return uri;
1755
+ return this.client.call('get', uri, {}, payload, 'arrayBuffer');
1753
1756
  }
1754
1757
  /**
1755
1758
  * The credit card endpoint will return you the icon of the credit card
@@ -1767,7 +1770,7 @@ class Avatars extends Service {
1767
1770
  * @param {number} height
1768
1771
  * @param {number} quality
1769
1772
  * @throws {AppwriteException}
1770
- * @returns {URL}
1773
+ * @returns {ArrayBuffer}
1771
1774
  */
1772
1775
  getCreditCard(code, width, height, quality) {
1773
1776
  if (typeof code === 'undefined') {
@@ -1789,7 +1792,7 @@ class Avatars extends Service {
1789
1792
  for (const [key, value] of Object.entries(Service.flatten(payload))) {
1790
1793
  uri.searchParams.append(key, value);
1791
1794
  }
1792
- return uri;
1795
+ return this.client.call('get', uri, {}, payload, 'arrayBuffer');
1793
1796
  }
1794
1797
  /**
1795
1798
  * Use this endpoint to fetch the favorite icon (AKA favicon) of any remote
@@ -1799,7 +1802,7 @@ class Avatars extends Service {
1799
1802
  *
1800
1803
  * @param {string} url
1801
1804
  * @throws {AppwriteException}
1802
- * @returns {URL}
1805
+ * @returns {ArrayBuffer}
1803
1806
  */
1804
1807
  getFavicon(url) {
1805
1808
  if (typeof url === 'undefined') {
@@ -1815,7 +1818,7 @@ class Avatars extends Service {
1815
1818
  for (const [key, value] of Object.entries(Service.flatten(payload))) {
1816
1819
  uri.searchParams.append(key, value);
1817
1820
  }
1818
- return uri;
1821
+ return this.client.call('get', uri, {}, payload, 'arrayBuffer');
1819
1822
  }
1820
1823
  /**
1821
1824
  * You can use this endpoint to show different country flags icons to your
@@ -1834,7 +1837,7 @@ class Avatars extends Service {
1834
1837
  * @param {number} height
1835
1838
  * @param {number} quality
1836
1839
  * @throws {AppwriteException}
1837
- * @returns {URL}
1840
+ * @returns {ArrayBuffer}
1838
1841
  */
1839
1842
  getFlag(code, width, height, quality) {
1840
1843
  if (typeof code === 'undefined') {
@@ -1856,7 +1859,7 @@ class Avatars extends Service {
1856
1859
  for (const [key, value] of Object.entries(Service.flatten(payload))) {
1857
1860
  uri.searchParams.append(key, value);
1858
1861
  }
1859
- return uri;
1862
+ return this.client.call('get', uri, {}, payload, 'arrayBuffer');
1860
1863
  }
1861
1864
  /**
1862
1865
  * Use this endpoint to fetch a remote image URL and crop it to any image size
@@ -1875,7 +1878,7 @@ class Avatars extends Service {
1875
1878
  * @param {number} width
1876
1879
  * @param {number} height
1877
1880
  * @throws {AppwriteException}
1878
- * @returns {URL}
1881
+ * @returns {ArrayBuffer}
1879
1882
  */
1880
1883
  getImage(url, width, height) {
1881
1884
  if (typeof url === 'undefined') {
@@ -1897,7 +1900,7 @@ class Avatars extends Service {
1897
1900
  for (const [key, value] of Object.entries(Service.flatten(payload))) {
1898
1901
  uri.searchParams.append(key, value);
1899
1902
  }
1900
- return uri;
1903
+ return this.client.call('get', uri, {}, payload, 'arrayBuffer');
1901
1904
  }
1902
1905
  /**
1903
1906
  * Use this endpoint to show your user initials avatar icon on your website or
@@ -1922,7 +1925,7 @@ class Avatars extends Service {
1922
1925
  * @param {number} height
1923
1926
  * @param {string} background
1924
1927
  * @throws {AppwriteException}
1925
- * @returns {URL}
1928
+ * @returns {ArrayBuffer}
1926
1929
  */
1927
1930
  getInitials(name, width, height, background) {
1928
1931
  const apiPath = '/avatars/initials';
@@ -1944,7 +1947,7 @@ class Avatars extends Service {
1944
1947
  for (const [key, value] of Object.entries(Service.flatten(payload))) {
1945
1948
  uri.searchParams.append(key, value);
1946
1949
  }
1947
- return uri;
1950
+ return this.client.call('get', uri, {}, payload, 'arrayBuffer');
1948
1951
  }
1949
1952
  /**
1950
1953
  * Converts a given plain text to a QR code image. You can use the query
@@ -1956,7 +1959,7 @@ class Avatars extends Service {
1956
1959
  * @param {number} margin
1957
1960
  * @param {boolean} download
1958
1961
  * @throws {AppwriteException}
1959
- * @returns {URL}
1962
+ * @returns {ArrayBuffer}
1960
1963
  */
1961
1964
  getQR(text, size, margin, download) {
1962
1965
  if (typeof text === 'undefined') {
@@ -1981,6 +1984,163 @@ class Avatars extends Service {
1981
1984
  for (const [key, value] of Object.entries(Service.flatten(payload))) {
1982
1985
  uri.searchParams.append(key, value);
1983
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);
1984
2144
  return uri;
1985
2145
  }
1986
2146
  }
@@ -2719,7 +2879,7 @@ class Storage extends Service {
2719
2879
  * @param {string} fileId
2720
2880
  * @param {string} token
2721
2881
  * @throws {AppwriteException}
2722
- * @returns {URL}
2882
+ * @returns {ArrayBuffer}
2723
2883
  */
2724
2884
  getFileDownload(bucketId, fileId, token) {
2725
2885
  if (typeof bucketId === 'undefined') {
@@ -2738,7 +2898,7 @@ class Storage extends Service {
2738
2898
  for (const [key, value] of Object.entries(Service.flatten(payload))) {
2739
2899
  uri.searchParams.append(key, value);
2740
2900
  }
2741
- return uri;
2901
+ return this.client.call('get', uri, {}, payload, 'arrayBuffer');
2742
2902
  }
2743
2903
  /**
2744
2904
  * Get a file preview image. Currently, this method supports preview for image
@@ -2762,7 +2922,7 @@ class Storage extends Service {
2762
2922
  * @param {ImageFormat} output
2763
2923
  * @param {string} token
2764
2924
  * @throws {AppwriteException}
2765
- * @returns {URL}
2925
+ * @returns {ArrayBuffer}
2766
2926
  */
2767
2927
  getFilePreview(bucketId, fileId, width, height, gravity, quality, borderWidth, borderColor, borderRadius, opacity, rotation, background, output, token) {
2768
2928
  if (typeof bucketId === 'undefined') {
@@ -2814,7 +2974,7 @@ class Storage extends Service {
2814
2974
  for (const [key, value] of Object.entries(Service.flatten(payload))) {
2815
2975
  uri.searchParams.append(key, value);
2816
2976
  }
2817
- return uri;
2977
+ return this.client.call('get', uri, {}, payload, 'arrayBuffer');
2818
2978
  }
2819
2979
  /**
2820
2980
  * Get a file content by its unique ID. This endpoint is similar to the
@@ -2825,7 +2985,7 @@ class Storage extends Service {
2825
2985
  * @param {string} fileId
2826
2986
  * @param {string} token
2827
2987
  * @throws {AppwriteException}
2828
- * @returns {URL}
2988
+ * @returns {ArrayBuffer}
2829
2989
  */
2830
2990
  getFileView(bucketId, fileId, token) {
2831
2991
  if (typeof bucketId === 'undefined') {
@@ -2844,6 +3004,67 @@ class Storage extends Service {
2844
3004
  for (const [key, value] of Object.entries(Service.flatten(payload))) {
2845
3005
  uri.searchParams.append(key, value);
2846
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);
2847
3068
  return uri;
2848
3069
  }
2849
3070
  }