react-native-appwrite 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/.github/ISSUE_TEMPLATE/bug.yaml +82 -0
  2. package/.github/ISSUE_TEMPLATE/documentation.yaml +32 -0
  3. package/.github/ISSUE_TEMPLATE/feature.yaml +40 -0
  4. package/.github/workflows/publish.yml +33 -0
  5. package/.gitpod.yml +10 -0
  6. package/CHANGELOG.md +1 -0
  7. package/LICENSE +12 -0
  8. package/README.md +111 -0
  9. package/dist/cjs/sdk.js +3127 -0
  10. package/dist/cjs/sdk.js.map +1 -0
  11. package/dist/esm/sdk.js +3108 -0
  12. package/dist/esm/sdk.js.map +1 -0
  13. package/dist/iife/sdk.js +3126 -0
  14. package/docs/examples/account/create-anonymous-session.md +18 -0
  15. package/docs/examples/account/create-email-session.md +18 -0
  16. package/docs/examples/account/create-j-w-t.md +18 -0
  17. package/docs/examples/account/create-magic-u-r-l-session.md +18 -0
  18. package/docs/examples/account/create-o-auth2session.md +14 -0
  19. package/docs/examples/account/create-phone-session.md +18 -0
  20. package/docs/examples/account/create-phone-verification.md +18 -0
  21. package/docs/examples/account/create-recovery.md +18 -0
  22. package/docs/examples/account/create-verification.md +18 -0
  23. package/docs/examples/account/create.md +18 -0
  24. package/docs/examples/account/delete-identity.md +18 -0
  25. package/docs/examples/account/delete-session.md +18 -0
  26. package/docs/examples/account/delete-sessions.md +18 -0
  27. package/docs/examples/account/get-prefs.md +18 -0
  28. package/docs/examples/account/get-session.md +18 -0
  29. package/docs/examples/account/get.md +18 -0
  30. package/docs/examples/account/list-identities.md +18 -0
  31. package/docs/examples/account/list-logs.md +18 -0
  32. package/docs/examples/account/list-sessions.md +18 -0
  33. package/docs/examples/account/update-email.md +18 -0
  34. package/docs/examples/account/update-magic-u-r-l-session.md +18 -0
  35. package/docs/examples/account/update-name.md +18 -0
  36. package/docs/examples/account/update-password.md +18 -0
  37. package/docs/examples/account/update-phone-session.md +18 -0
  38. package/docs/examples/account/update-phone-verification.md +18 -0
  39. package/docs/examples/account/update-phone.md +18 -0
  40. package/docs/examples/account/update-prefs.md +18 -0
  41. package/docs/examples/account/update-recovery.md +18 -0
  42. package/docs/examples/account/update-session.md +18 -0
  43. package/docs/examples/account/update-status.md +18 -0
  44. package/docs/examples/account/update-verification.md +18 -0
  45. package/docs/examples/avatars/get-browser.md +14 -0
  46. package/docs/examples/avatars/get-credit-card.md +14 -0
  47. package/docs/examples/avatars/get-favicon.md +14 -0
  48. package/docs/examples/avatars/get-flag.md +14 -0
  49. package/docs/examples/avatars/get-image.md +14 -0
  50. package/docs/examples/avatars/get-initials.md +14 -0
  51. package/docs/examples/avatars/get-q-r.md +14 -0
  52. package/docs/examples/databases/create-document.md +18 -0
  53. package/docs/examples/databases/delete-document.md +18 -0
  54. package/docs/examples/databases/get-document.md +18 -0
  55. package/docs/examples/databases/list-documents.md +18 -0
  56. package/docs/examples/databases/update-document.md +18 -0
  57. package/docs/examples/functions/create-execution.md +18 -0
  58. package/docs/examples/functions/get-execution.md +18 -0
  59. package/docs/examples/functions/list-executions.md +18 -0
  60. package/docs/examples/graphql/mutation.md +18 -0
  61. package/docs/examples/graphql/query.md +18 -0
  62. package/docs/examples/locale/get.md +18 -0
  63. package/docs/examples/locale/list-codes.md +18 -0
  64. package/docs/examples/locale/list-continents.md +18 -0
  65. package/docs/examples/locale/list-countries-e-u.md +18 -0
  66. package/docs/examples/locale/list-countries-phones.md +18 -0
  67. package/docs/examples/locale/list-countries.md +18 -0
  68. package/docs/examples/locale/list-currencies.md +18 -0
  69. package/docs/examples/locale/list-languages.md +18 -0
  70. package/docs/examples/storage/create-file.md +18 -0
  71. package/docs/examples/storage/delete-file.md +18 -0
  72. package/docs/examples/storage/get-file-download.md +14 -0
  73. package/docs/examples/storage/get-file-preview.md +14 -0
  74. package/docs/examples/storage/get-file-view.md +14 -0
  75. package/docs/examples/storage/get-file.md +18 -0
  76. package/docs/examples/storage/list-files.md +18 -0
  77. package/docs/examples/storage/update-file.md +18 -0
  78. package/docs/examples/teams/create-membership.md +18 -0
  79. package/docs/examples/teams/create.md +18 -0
  80. package/docs/examples/teams/delete-membership.md +18 -0
  81. package/docs/examples/teams/delete.md +18 -0
  82. package/docs/examples/teams/get-membership.md +18 -0
  83. package/docs/examples/teams/get-prefs.md +18 -0
  84. package/docs/examples/teams/get.md +18 -0
  85. package/docs/examples/teams/list-memberships.md +18 -0
  86. package/docs/examples/teams/list.md +18 -0
  87. package/docs/examples/teams/update-membership-status.md +18 -0
  88. package/docs/examples/teams/update-membership.md +18 -0
  89. package/docs/examples/teams/update-name.md +18 -0
  90. package/docs/examples/teams/update-prefs.md +18 -0
  91. package/package.json +47 -0
  92. package/rollup.config.js +31 -0
  93. package/src/client.ts +437 -0
  94. package/src/id.ts +9 -0
  95. package/src/index.ts +14 -0
  96. package/src/models.ts +1021 -0
  97. package/src/permission.ts +22 -0
  98. package/src/query.ts +74 -0
  99. package/src/role.ts +100 -0
  100. package/src/service.ts +30 -0
  101. package/src/services/account.ts +1066 -0
  102. package/src/services/avatars.ts +352 -0
  103. package/src/services/databases.ts +216 -0
  104. package/src/services/functions.ts +125 -0
  105. package/src/services/graphql.ts +68 -0
  106. package/src/services/locale.ts +169 -0
  107. package/src/services/storage.ts +411 -0
  108. package/src/services/teams.ts +484 -0
  109. package/tsconfig.json +24 -0
@@ -0,0 +1,68 @@
1
+ import { Service } from '../service';
2
+ import { AppwriteException, Client } from '../client';
3
+ import type { Models } from '../models';
4
+ import type { UploadProgress, Payload } from '../client';
5
+
6
+ export class Graphql extends Service {
7
+
8
+ constructor(client: Client)
9
+ {
10
+ super(client);
11
+ }
12
+
13
+ /**
14
+ * GraphQL endpoint
15
+ *
16
+ * Execute a GraphQL mutation.
17
+ *
18
+ * @param {object} query
19
+ * @throws {AppwriteException}
20
+ * @returns {Promise}
21
+ */
22
+ async query(query: object): Promise<{}> {
23
+ if (typeof query === 'undefined') {
24
+ throw new AppwriteException('Missing required parameter: "query"');
25
+ }
26
+
27
+ const apiPath = '/graphql';
28
+ const payload: Payload = {};
29
+
30
+ if (typeof query !== 'undefined') {
31
+ payload['query'] = query;
32
+ }
33
+
34
+ const uri = new URL(this.client.config.endpoint + apiPath);
35
+ return await this.client.call('post', uri, {
36
+ 'x-sdk-graphql': 'true',
37
+ 'content-type': 'application/json',
38
+ }, payload);
39
+ }
40
+
41
+ /**
42
+ * GraphQL endpoint
43
+ *
44
+ * Execute a GraphQL mutation.
45
+ *
46
+ * @param {object} query
47
+ * @throws {AppwriteException}
48
+ * @returns {Promise}
49
+ */
50
+ async mutation(query: object): Promise<{}> {
51
+ if (typeof query === 'undefined') {
52
+ throw new AppwriteException('Missing required parameter: "query"');
53
+ }
54
+
55
+ const apiPath = '/graphql/mutation';
56
+ const payload: Payload = {};
57
+
58
+ if (typeof query !== 'undefined') {
59
+ payload['query'] = query;
60
+ }
61
+
62
+ const uri = new URL(this.client.config.endpoint + apiPath);
63
+ return await this.client.call('post', uri, {
64
+ 'x-sdk-graphql': 'true',
65
+ 'content-type': 'application/json',
66
+ }, payload);
67
+ }
68
+ };
@@ -0,0 +1,169 @@
1
+ import { Service } from '../service';
2
+ import { AppwriteException, Client } from '../client';
3
+ import type { Models } from '../models';
4
+ import type { UploadProgress, Payload } from '../client';
5
+
6
+ export class Locale extends Service {
7
+
8
+ constructor(client: Client)
9
+ {
10
+ super(client);
11
+ }
12
+
13
+ /**
14
+ * Get user locale
15
+ *
16
+ * Get the current user location based on IP. Returns an object with user
17
+ * country code, country name, continent name, continent code, ip address and
18
+ * suggested currency. You can use the locale header to get the data in a
19
+ * supported language.
20
+ *
21
+ * ([IP Geolocation by DB-IP](https://db-ip.com))
22
+ *
23
+ * @throws {AppwriteException}
24
+ * @returns {Promise}
25
+ */
26
+ async get(): Promise<Models.Locale> {
27
+ const apiPath = '/locale';
28
+ const payload: Payload = {};
29
+
30
+ const uri = new URL(this.client.config.endpoint + apiPath);
31
+ return await this.client.call('get', uri, {
32
+ 'content-type': 'application/json',
33
+ }, payload);
34
+ }
35
+
36
+ /**
37
+ * List Locale Codes
38
+ *
39
+ * List of all locale codes in [ISO
40
+ * 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes).
41
+ *
42
+ * @throws {AppwriteException}
43
+ * @returns {Promise}
44
+ */
45
+ async listCodes(): Promise<Models.LocaleCodeList> {
46
+ const apiPath = '/locale/codes';
47
+ const payload: Payload = {};
48
+
49
+ const uri = new URL(this.client.config.endpoint + apiPath);
50
+ return await this.client.call('get', uri, {
51
+ 'content-type': 'application/json',
52
+ }, payload);
53
+ }
54
+
55
+ /**
56
+ * List continents
57
+ *
58
+ * List of all continents. You can use the locale header to get the data in a
59
+ * supported language.
60
+ *
61
+ * @throws {AppwriteException}
62
+ * @returns {Promise}
63
+ */
64
+ async listContinents(): Promise<Models.ContinentList> {
65
+ const apiPath = '/locale/continents';
66
+ const payload: Payload = {};
67
+
68
+ const uri = new URL(this.client.config.endpoint + apiPath);
69
+ return await this.client.call('get', uri, {
70
+ 'content-type': 'application/json',
71
+ }, payload);
72
+ }
73
+
74
+ /**
75
+ * List countries
76
+ *
77
+ * List of all countries. You can use the locale header to get the data in a
78
+ * supported language.
79
+ *
80
+ * @throws {AppwriteException}
81
+ * @returns {Promise}
82
+ */
83
+ async listCountries(): Promise<Models.CountryList> {
84
+ const apiPath = '/locale/countries';
85
+ const payload: Payload = {};
86
+
87
+ const uri = new URL(this.client.config.endpoint + apiPath);
88
+ return await this.client.call('get', uri, {
89
+ 'content-type': 'application/json',
90
+ }, payload);
91
+ }
92
+
93
+ /**
94
+ * List EU countries
95
+ *
96
+ * List of all countries that are currently members of the EU. You can use the
97
+ * locale header to get the data in a supported language.
98
+ *
99
+ * @throws {AppwriteException}
100
+ * @returns {Promise}
101
+ */
102
+ async listCountriesEU(): Promise<Models.CountryList> {
103
+ const apiPath = '/locale/countries/eu';
104
+ const payload: Payload = {};
105
+
106
+ const uri = new URL(this.client.config.endpoint + apiPath);
107
+ return await this.client.call('get', uri, {
108
+ 'content-type': 'application/json',
109
+ }, payload);
110
+ }
111
+
112
+ /**
113
+ * List countries phone codes
114
+ *
115
+ * List of all countries phone codes. You can use the locale header to get the
116
+ * data in a supported language.
117
+ *
118
+ * @throws {AppwriteException}
119
+ * @returns {Promise}
120
+ */
121
+ async listCountriesPhones(): Promise<Models.PhoneList> {
122
+ const apiPath = '/locale/countries/phones';
123
+ const payload: Payload = {};
124
+
125
+ const uri = new URL(this.client.config.endpoint + apiPath);
126
+ return await this.client.call('get', uri, {
127
+ 'content-type': 'application/json',
128
+ }, payload);
129
+ }
130
+
131
+ /**
132
+ * List currencies
133
+ *
134
+ * List of all currencies, including currency symbol, name, plural, and
135
+ * decimal digits for all major and minor currencies. You can use the locale
136
+ * header to get the data in a supported language.
137
+ *
138
+ * @throws {AppwriteException}
139
+ * @returns {Promise}
140
+ */
141
+ async listCurrencies(): Promise<Models.CurrencyList> {
142
+ const apiPath = '/locale/currencies';
143
+ const payload: Payload = {};
144
+
145
+ const uri = new URL(this.client.config.endpoint + apiPath);
146
+ return await this.client.call('get', uri, {
147
+ 'content-type': 'application/json',
148
+ }, payload);
149
+ }
150
+
151
+ /**
152
+ * List languages
153
+ *
154
+ * List of all languages classified by ISO 639-1 including 2-letter code, name
155
+ * in English, and name in the respective language.
156
+ *
157
+ * @throws {AppwriteException}
158
+ * @returns {Promise}
159
+ */
160
+ async listLanguages(): Promise<Models.LanguageList> {
161
+ const apiPath = '/locale/languages';
162
+ const payload: Payload = {};
163
+
164
+ const uri = new URL(this.client.config.endpoint + apiPath);
165
+ return await this.client.call('get', uri, {
166
+ 'content-type': 'application/json',
167
+ }, payload);
168
+ }
169
+ };
@@ -0,0 +1,411 @@
1
+ import { Service } from '../service';
2
+ import { AppwriteException, Client } from '../client';
3
+ import type { Models } from '../models';
4
+ import type { UploadProgress, Payload } from '../client';
5
+ import fs from 'react-native-fs'
6
+
7
+ export class Storage extends Service {
8
+
9
+ constructor(client: Client)
10
+ {
11
+ super(client);
12
+ }
13
+
14
+ /**
15
+ * List files
16
+ *
17
+ * Get a list of all the user files. You can use the query params to filter
18
+ * your results.
19
+ *
20
+ * @param {string} bucketId
21
+ * @param {string[]} queries
22
+ * @param {string} search
23
+ * @throws {AppwriteException}
24
+ * @returns {Promise}
25
+ */
26
+ async listFiles(bucketId: string, queries?: string[], search?: string): Promise<Models.FileList> {
27
+ if (typeof bucketId === 'undefined') {
28
+ throw new AppwriteException('Missing required parameter: "bucketId"');
29
+ }
30
+
31
+ const apiPath = '/storage/buckets/{bucketId}/files'.replace('{bucketId}', bucketId);
32
+ const payload: Payload = {};
33
+
34
+ if (typeof queries !== 'undefined') {
35
+ payload['queries'] = queries;
36
+ }
37
+
38
+ if (typeof search !== 'undefined') {
39
+ payload['search'] = search;
40
+ }
41
+
42
+ const uri = new URL(this.client.config.endpoint + apiPath);
43
+ return await this.client.call('get', uri, {
44
+ 'content-type': 'application/json',
45
+ }, payload);
46
+ }
47
+
48
+ /**
49
+ * Create file
50
+ *
51
+ * Create a new file. Before using this route, you should create a new bucket
52
+ * resource using either a [server
53
+ * integration](https://appwrite.io/docs/server/storage#storageCreateBucket)
54
+ * API or directly from your Appwrite console.
55
+ *
56
+ * Larger files should be uploaded using multiple requests with the
57
+ * [content-range](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Range)
58
+ * header to send a partial request with a maximum supported chunk of `5MB`.
59
+ * The `content-range` header values should always be in bytes.
60
+ *
61
+ * When the first request is sent, the server will return the **File** object,
62
+ * and the subsequent part request must include the file's **id** in
63
+ * `x-appwrite-id` header to allow the server to know that the partial upload
64
+ * is for the existing file and not for a new one.
65
+ *
66
+ * If you're creating a new file using one of the Appwrite SDKs, all the
67
+ * chunking logic will be managed by the SDK internally.
68
+ *
69
+ *
70
+ * @param {string} bucketId
71
+ * @param {string} fileId
72
+ * @param {any} file
73
+ * @param {string[]} permissions
74
+ * @throws {AppwriteException}
75
+ * @returns {Promise}
76
+ */
77
+ async createFile(bucketId: string, fileId: string, file: any, permissions?: string[], onProgress = (progress: UploadProgress) => {}): Promise<Models.File> {
78
+ if (typeof bucketId === 'undefined') {
79
+ throw new AppwriteException('Missing required parameter: "bucketId"');
80
+ }
81
+
82
+ if (typeof fileId === 'undefined') {
83
+ throw new AppwriteException('Missing required parameter: "fileId"');
84
+ }
85
+
86
+ if (typeof file === 'undefined') {
87
+ throw new AppwriteException('Missing required parameter: "file"');
88
+ }
89
+
90
+ const apiPath = '/storage/buckets/{bucketId}/files'.replace('{bucketId}', bucketId);
91
+ const payload: Payload = {};
92
+
93
+ if (typeof fileId !== 'undefined') {
94
+ payload['fileId'] = fileId;
95
+ }
96
+
97
+ if (typeof file !== 'undefined') {
98
+ payload['file'] = file;
99
+ }
100
+
101
+ if (typeof permissions !== 'undefined') {
102
+ payload['permissions'] = permissions;
103
+ }
104
+
105
+ const uri = new URL(this.client.config.endpoint + apiPath);
106
+
107
+ const size = file.size;
108
+
109
+ if (size <= Service.CHUNK_SIZE) {
110
+ return await this.client.call('post', uri, {
111
+ 'content-type': 'multipart/form-data',
112
+ }, payload);
113
+ }
114
+
115
+ const apiHeaders: { [header: string]: string } = {
116
+ 'content-type': 'multipart/form-data',
117
+ }
118
+
119
+ let offset = 0;
120
+ let response = undefined;
121
+ if(fileId != 'unique()') {
122
+ try {
123
+ response = await this.client.call('GET', new URL(this.client.config.endpoint + apiPath + '/' + fileId), apiHeaders);
124
+ offset = response.chunksUploaded * Service.CHUNK_SIZE;
125
+ } catch(e) {
126
+ }
127
+ }
128
+
129
+ while (offset < size) {
130
+ let end = Math.min(offset + Service.CHUNK_SIZE - 1, size - 1);
131
+
132
+ apiHeaders['content-range'] = 'bytes ' + offset + '-' + end + '/' + size;
133
+ if (response && response.$id) {
134
+ apiHeaders['x-appwrite-id'] = response.$id;
135
+ }
136
+
137
+ let chunk = await fs.read(file.uri, Service.CHUNK_SIZE, offset, 'base64');
138
+
139
+ payload['file'] = {uri: `data:${file.type};base64,${chunk}`, name: file.name, type: file.type};
140
+ response = await this.client.call('post', uri, apiHeaders, payload);
141
+
142
+ if (onProgress) {
143
+ onProgress({
144
+ $id: response.$id,
145
+ progress: (offset / size) * 100,
146
+ sizeUploaded: offset,
147
+ chunksTotal: response.chunksTotal,
148
+ chunksUploaded: response.chunksUploaded
149
+ });
150
+ }
151
+ offset += Service.CHUNK_SIZE;
152
+ }
153
+ return response;
154
+ }
155
+
156
+ /**
157
+ * Get file
158
+ *
159
+ * Get a file by its unique ID. This endpoint response returns a JSON object
160
+ * with the file metadata.
161
+ *
162
+ * @param {string} bucketId
163
+ * @param {string} fileId
164
+ * @throws {AppwriteException}
165
+ * @returns {Promise}
166
+ */
167
+ async getFile(bucketId: string, fileId: string): Promise<Models.File> {
168
+ if (typeof bucketId === 'undefined') {
169
+ throw new AppwriteException('Missing required parameter: "bucketId"');
170
+ }
171
+
172
+ if (typeof fileId === 'undefined') {
173
+ throw new AppwriteException('Missing required parameter: "fileId"');
174
+ }
175
+
176
+ const apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
177
+ const payload: Payload = {};
178
+
179
+ const uri = new URL(this.client.config.endpoint + apiPath);
180
+ return await this.client.call('get', uri, {
181
+ 'content-type': 'application/json',
182
+ }, payload);
183
+ }
184
+
185
+ /**
186
+ * Update file
187
+ *
188
+ * Update a file by its unique ID. Only users with write permissions have
189
+ * access to update this resource.
190
+ *
191
+ * @param {string} bucketId
192
+ * @param {string} fileId
193
+ * @param {string} name
194
+ * @param {string[]} permissions
195
+ * @throws {AppwriteException}
196
+ * @returns {Promise}
197
+ */
198
+ async updateFile(bucketId: string, fileId: string, name?: string, permissions?: string[]): Promise<Models.File> {
199
+ if (typeof bucketId === 'undefined') {
200
+ throw new AppwriteException('Missing required parameter: "bucketId"');
201
+ }
202
+
203
+ if (typeof fileId === 'undefined') {
204
+ throw new AppwriteException('Missing required parameter: "fileId"');
205
+ }
206
+
207
+ const apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
208
+ const payload: Payload = {};
209
+
210
+ if (typeof name !== 'undefined') {
211
+ payload['name'] = name;
212
+ }
213
+
214
+ if (typeof permissions !== 'undefined') {
215
+ payload['permissions'] = permissions;
216
+ }
217
+
218
+ const uri = new URL(this.client.config.endpoint + apiPath);
219
+ return await this.client.call('put', uri, {
220
+ 'content-type': 'application/json',
221
+ }, payload);
222
+ }
223
+
224
+ /**
225
+ * Delete File
226
+ *
227
+ * Delete a file by its unique ID. Only users with write permissions have
228
+ * access to delete this resource.
229
+ *
230
+ * @param {string} bucketId
231
+ * @param {string} fileId
232
+ * @throws {AppwriteException}
233
+ * @returns {Promise}
234
+ */
235
+ async deleteFile(bucketId: string, fileId: string): Promise<{}> {
236
+ if (typeof bucketId === 'undefined') {
237
+ throw new AppwriteException('Missing required parameter: "bucketId"');
238
+ }
239
+
240
+ if (typeof fileId === 'undefined') {
241
+ throw new AppwriteException('Missing required parameter: "fileId"');
242
+ }
243
+
244
+ const apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
245
+ const payload: Payload = {};
246
+
247
+ const uri = new URL(this.client.config.endpoint + apiPath);
248
+ return await this.client.call('delete', uri, {
249
+ 'content-type': 'application/json',
250
+ }, payload);
251
+ }
252
+
253
+ /**
254
+ * Get file for download
255
+ *
256
+ * Get a file content by its unique ID. The endpoint response return with a
257
+ * 'Content-Disposition: attachment' header that tells the browser to start
258
+ * downloading the file to user downloads directory.
259
+ *
260
+ * @param {string} bucketId
261
+ * @param {string} fileId
262
+ * @throws {AppwriteException}
263
+ * @returns {URL}
264
+ */
265
+ getFileDownload(bucketId: string, fileId: string): URL {
266
+ if (typeof bucketId === 'undefined') {
267
+ throw new AppwriteException('Missing required parameter: "bucketId"');
268
+ }
269
+
270
+ if (typeof fileId === 'undefined') {
271
+ throw new AppwriteException('Missing required parameter: "fileId"');
272
+ }
273
+
274
+ const apiPath = '/storage/buckets/{bucketId}/files/{fileId}/download'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
275
+ const payload: Payload = {};
276
+
277
+ const uri = new URL(this.client.config.endpoint + apiPath);
278
+ payload['project'] = this.client.config.project;
279
+
280
+
281
+ for (const [key, value] of Object.entries(Service.flatten(payload))) {
282
+ uri.searchParams.append(key, value);
283
+ }
284
+ return uri;
285
+ }
286
+
287
+ /**
288
+ * Get file preview
289
+ *
290
+ * Get a file preview image. Currently, this method supports preview for image
291
+ * files (jpg, png, and gif), other supported formats, like pdf, docs, slides,
292
+ * and spreadsheets, will return the file icon image. You can also pass query
293
+ * string arguments for cutting and resizing your preview image. Preview is
294
+ * supported only for image files smaller than 10MB.
295
+ *
296
+ * @param {string} bucketId
297
+ * @param {string} fileId
298
+ * @param {number} width
299
+ * @param {number} height
300
+ * @param {string} gravity
301
+ * @param {number} quality
302
+ * @param {number} borderWidth
303
+ * @param {string} borderColor
304
+ * @param {number} borderRadius
305
+ * @param {number} opacity
306
+ * @param {number} rotation
307
+ * @param {string} background
308
+ * @param {string} output
309
+ * @throws {AppwriteException}
310
+ * @returns {URL}
311
+ */
312
+ getFilePreview(bucketId: string, fileId: string, width?: number, height?: number, gravity?: string, quality?: number, borderWidth?: number, borderColor?: string, borderRadius?: number, opacity?: number, rotation?: number, background?: string, output?: string): URL {
313
+ if (typeof bucketId === 'undefined') {
314
+ throw new AppwriteException('Missing required parameter: "bucketId"');
315
+ }
316
+
317
+ if (typeof fileId === 'undefined') {
318
+ throw new AppwriteException('Missing required parameter: "fileId"');
319
+ }
320
+
321
+ const apiPath = '/storage/buckets/{bucketId}/files/{fileId}/preview'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
322
+ const payload: Payload = {};
323
+
324
+ if (typeof width !== 'undefined') {
325
+ payload['width'] = width;
326
+ }
327
+
328
+ if (typeof height !== 'undefined') {
329
+ payload['height'] = height;
330
+ }
331
+
332
+ if (typeof gravity !== 'undefined') {
333
+ payload['gravity'] = gravity;
334
+ }
335
+
336
+ if (typeof quality !== 'undefined') {
337
+ payload['quality'] = quality;
338
+ }
339
+
340
+ if (typeof borderWidth !== 'undefined') {
341
+ payload['borderWidth'] = borderWidth;
342
+ }
343
+
344
+ if (typeof borderColor !== 'undefined') {
345
+ payload['borderColor'] = borderColor;
346
+ }
347
+
348
+ if (typeof borderRadius !== 'undefined') {
349
+ payload['borderRadius'] = borderRadius;
350
+ }
351
+
352
+ if (typeof opacity !== 'undefined') {
353
+ payload['opacity'] = opacity;
354
+ }
355
+
356
+ if (typeof rotation !== 'undefined') {
357
+ payload['rotation'] = rotation;
358
+ }
359
+
360
+ if (typeof background !== 'undefined') {
361
+ payload['background'] = background;
362
+ }
363
+
364
+ if (typeof output !== 'undefined') {
365
+ payload['output'] = output;
366
+ }
367
+
368
+ const uri = new URL(this.client.config.endpoint + apiPath);
369
+ payload['project'] = this.client.config.project;
370
+
371
+
372
+ for (const [key, value] of Object.entries(Service.flatten(payload))) {
373
+ uri.searchParams.append(key, value);
374
+ }
375
+ return uri;
376
+ }
377
+
378
+ /**
379
+ * Get file for view
380
+ *
381
+ * Get a file content by its unique ID. This endpoint is similar to the
382
+ * download method but returns with no 'Content-Disposition: attachment'
383
+ * header.
384
+ *
385
+ * @param {string} bucketId
386
+ * @param {string} fileId
387
+ * @throws {AppwriteException}
388
+ * @returns {URL}
389
+ */
390
+ getFileView(bucketId: string, fileId: string): URL {
391
+ if (typeof bucketId === 'undefined') {
392
+ throw new AppwriteException('Missing required parameter: "bucketId"');
393
+ }
394
+
395
+ if (typeof fileId === 'undefined') {
396
+ throw new AppwriteException('Missing required parameter: "fileId"');
397
+ }
398
+
399
+ const apiPath = '/storage/buckets/{bucketId}/files/{fileId}/view'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
400
+ const payload: Payload = {};
401
+
402
+ const uri = new URL(this.client.config.endpoint + apiPath);
403
+ payload['project'] = this.client.config.project;
404
+
405
+
406
+ for (const [key, value] of Object.entries(Service.flatten(payload))) {
407
+ uri.searchParams.append(key, value);
408
+ }
409
+ return uri;
410
+ }
411
+ };