node-appwrite 4.0.2 → 6.0.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/README.md +2 -2
- package/docs/examples/account/update-session.md +20 -0
- package/docs/examples/account/{delete.md → update-status.md} +1 -1
- package/docs/examples/functions/{create-tag.md → create-deployment.md} +1 -1
- package/docs/examples/functions/{delete-tag.md → delete-deployment.md} +1 -1
- package/docs/examples/functions/{update-tag.md → get-deployment.md} +1 -1
- package/docs/examples/functions/{list-tags.md → list-deployments.md} +1 -1
- package/docs/examples/functions/retry-build.md +20 -0
- package/docs/examples/functions/{get-tag.md → update-deployment.md} +1 -1
- package/docs/examples/storage/create-bucket.md +20 -0
- package/docs/examples/storage/create-file.md +1 -1
- package/docs/examples/storage/delete-bucket.md +20 -0
- package/docs/examples/storage/delete-file.md +1 -1
- package/docs/examples/storage/get-bucket.md +20 -0
- package/docs/examples/storage/get-file-download.md +1 -1
- package/docs/examples/storage/get-file-preview.md +1 -1
- package/docs/examples/storage/get-file-view.md +1 -1
- package/docs/examples/storage/get-file.md +1 -1
- package/docs/examples/{health/get-queue-usage.md → storage/list-buckets.md} +2 -2
- package/docs/examples/storage/list-files.md +1 -1
- package/docs/examples/storage/update-bucket.md +20 -0
- package/docs/examples/storage/update-file.md +1 -1
- package/docs/examples/users/get-memberships.md +20 -0
- package/index.d.ts +485 -188
- package/lib/client.js +7 -5
- package/lib/exception.js +2 -1
- package/lib/services/account.js +49 -23
- package/lib/services/avatars.js +36 -3
- package/lib/services/database.js +7 -6
- package/lib/services/functions.js +213 -118
- package/lib/services/health.js +3 -18
- package/lib/services/locale.js +3 -0
- package/lib/services/storage.js +390 -33
- package/lib/services/teams.js +7 -0
- package/lib/services/users.js +32 -2
- package/package.json +2 -2
package/lib/services/storage.js
CHANGED
|
@@ -1,8 +1,258 @@
|
|
|
1
1
|
const Service = require('../service.js');
|
|
2
2
|
const AppwriteException = require('../exception.js');
|
|
3
|
+
const client = require('../client.js');
|
|
4
|
+
const { promisify } = require('util');
|
|
5
|
+
const fs = require('fs');
|
|
3
6
|
|
|
4
7
|
class Storage extends Service {
|
|
5
8
|
|
|
9
|
+
/**
|
|
10
|
+
* List buckets
|
|
11
|
+
*
|
|
12
|
+
* Get a list of all the storage buckets. You can use the query params to
|
|
13
|
+
* filter your results.
|
|
14
|
+
*
|
|
15
|
+
* @param {string} search
|
|
16
|
+
* @param {number} limit
|
|
17
|
+
* @param {number} offset
|
|
18
|
+
* @param {string} cursor
|
|
19
|
+
* @param {string} cursorDirection
|
|
20
|
+
* @param {string} orderType
|
|
21
|
+
* @throws {AppwriteException}
|
|
22
|
+
* @returns {Promise}
|
|
23
|
+
*/
|
|
24
|
+
async listBuckets(search, limit, offset, cursor, cursorDirection, orderType) {
|
|
25
|
+
let path = '/storage/buckets';
|
|
26
|
+
let payload = {};
|
|
27
|
+
|
|
28
|
+
if (typeof search !== 'undefined') {
|
|
29
|
+
payload['search'] = search;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (typeof limit !== 'undefined') {
|
|
33
|
+
payload['limit'] = limit;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (typeof offset !== 'undefined') {
|
|
37
|
+
payload['offset'] = offset;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (typeof cursor !== 'undefined') {
|
|
41
|
+
payload['cursor'] = cursor;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (typeof cursorDirection !== 'undefined') {
|
|
45
|
+
payload['cursorDirection'] = cursorDirection;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (typeof orderType !== 'undefined') {
|
|
49
|
+
payload['orderType'] = orderType;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return await this.client.call('get', path, {
|
|
53
|
+
'content-type': 'application/json',
|
|
54
|
+
}, payload);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Create bucket
|
|
59
|
+
*
|
|
60
|
+
* Create a new storage bucket.
|
|
61
|
+
*
|
|
62
|
+
* @param {string} bucketId
|
|
63
|
+
* @param {string} name
|
|
64
|
+
* @param {string} permission
|
|
65
|
+
* @param {string[]} read
|
|
66
|
+
* @param {string[]} write
|
|
67
|
+
* @param {boolean} enabled
|
|
68
|
+
* @param {number} maximumFileSize
|
|
69
|
+
* @param {string[]} allowedFileExtensions
|
|
70
|
+
* @param {boolean} encryption
|
|
71
|
+
* @param {boolean} antivirus
|
|
72
|
+
* @throws {AppwriteException}
|
|
73
|
+
* @returns {Promise}
|
|
74
|
+
*/
|
|
75
|
+
async createBucket(bucketId, name, permission, read, write, enabled, maximumFileSize, allowedFileExtensions, encryption, antivirus) {
|
|
76
|
+
if (typeof bucketId === 'undefined') {
|
|
77
|
+
throw new AppwriteException('Missing required parameter: "bucketId"');
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (typeof name === 'undefined') {
|
|
81
|
+
throw new AppwriteException('Missing required parameter: "name"');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (typeof permission === 'undefined') {
|
|
85
|
+
throw new AppwriteException('Missing required parameter: "permission"');
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
let path = '/storage/buckets';
|
|
89
|
+
let payload = {};
|
|
90
|
+
|
|
91
|
+
if (typeof bucketId !== 'undefined') {
|
|
92
|
+
payload['bucketId'] = bucketId;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (typeof name !== 'undefined') {
|
|
96
|
+
payload['name'] = name;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (typeof permission !== 'undefined') {
|
|
100
|
+
payload['permission'] = permission;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (typeof read !== 'undefined') {
|
|
104
|
+
payload['read'] = read;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (typeof write !== 'undefined') {
|
|
108
|
+
payload['write'] = write;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (typeof enabled !== 'undefined') {
|
|
112
|
+
payload['enabled'] = enabled;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (typeof maximumFileSize !== 'undefined') {
|
|
116
|
+
payload['maximumFileSize'] = maximumFileSize;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (typeof allowedFileExtensions !== 'undefined') {
|
|
120
|
+
payload['allowedFileExtensions'] = allowedFileExtensions;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (typeof encryption !== 'undefined') {
|
|
124
|
+
payload['encryption'] = encryption;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (typeof antivirus !== 'undefined') {
|
|
128
|
+
payload['antivirus'] = antivirus;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return await this.client.call('post', path, {
|
|
132
|
+
'content-type': 'application/json',
|
|
133
|
+
}, payload);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Get Bucket
|
|
138
|
+
*
|
|
139
|
+
* Get a storage bucket by its unique ID. This endpoint response returns a
|
|
140
|
+
* JSON object with the storage bucket metadata.
|
|
141
|
+
*
|
|
142
|
+
* @param {string} bucketId
|
|
143
|
+
* @throws {AppwriteException}
|
|
144
|
+
* @returns {Promise}
|
|
145
|
+
*/
|
|
146
|
+
async getBucket(bucketId) {
|
|
147
|
+
if (typeof bucketId === 'undefined') {
|
|
148
|
+
throw new AppwriteException('Missing required parameter: "bucketId"');
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
let path = '/storage/buckets/{bucketId}'.replace('{bucketId}', bucketId);
|
|
152
|
+
let payload = {};
|
|
153
|
+
|
|
154
|
+
return await this.client.call('get', path, {
|
|
155
|
+
'content-type': 'application/json',
|
|
156
|
+
}, payload);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Update Bucket
|
|
161
|
+
*
|
|
162
|
+
* Update a storage bucket by its unique ID.
|
|
163
|
+
*
|
|
164
|
+
* @param {string} bucketId
|
|
165
|
+
* @param {string} name
|
|
166
|
+
* @param {string} permission
|
|
167
|
+
* @param {string[]} read
|
|
168
|
+
* @param {string[]} write
|
|
169
|
+
* @param {boolean} enabled
|
|
170
|
+
* @param {number} maximumFileSize
|
|
171
|
+
* @param {string[]} allowedFileExtensions
|
|
172
|
+
* @param {boolean} encryption
|
|
173
|
+
* @param {boolean} antivirus
|
|
174
|
+
* @throws {AppwriteException}
|
|
175
|
+
* @returns {Promise}
|
|
176
|
+
*/
|
|
177
|
+
async updateBucket(bucketId, name, permission, read, write, enabled, maximumFileSize, allowedFileExtensions, encryption, antivirus) {
|
|
178
|
+
if (typeof bucketId === 'undefined') {
|
|
179
|
+
throw new AppwriteException('Missing required parameter: "bucketId"');
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (typeof name === 'undefined') {
|
|
183
|
+
throw new AppwriteException('Missing required parameter: "name"');
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (typeof permission === 'undefined') {
|
|
187
|
+
throw new AppwriteException('Missing required parameter: "permission"');
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
let path = '/storage/buckets/{bucketId}'.replace('{bucketId}', bucketId);
|
|
191
|
+
let payload = {};
|
|
192
|
+
|
|
193
|
+
if (typeof name !== 'undefined') {
|
|
194
|
+
payload['name'] = name;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (typeof permission !== 'undefined') {
|
|
198
|
+
payload['permission'] = permission;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (typeof read !== 'undefined') {
|
|
202
|
+
payload['read'] = read;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (typeof write !== 'undefined') {
|
|
206
|
+
payload['write'] = write;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (typeof enabled !== 'undefined') {
|
|
210
|
+
payload['enabled'] = enabled;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (typeof maximumFileSize !== 'undefined') {
|
|
214
|
+
payload['maximumFileSize'] = maximumFileSize;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (typeof allowedFileExtensions !== 'undefined') {
|
|
218
|
+
payload['allowedFileExtensions'] = allowedFileExtensions;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (typeof encryption !== 'undefined') {
|
|
222
|
+
payload['encryption'] = encryption;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (typeof antivirus !== 'undefined') {
|
|
226
|
+
payload['antivirus'] = antivirus;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return await this.client.call('put', path, {
|
|
230
|
+
'content-type': 'application/json',
|
|
231
|
+
}, payload);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Delete Bucket
|
|
236
|
+
*
|
|
237
|
+
* Delete a storage bucket by its unique ID.
|
|
238
|
+
*
|
|
239
|
+
* @param {string} bucketId
|
|
240
|
+
* @throws {AppwriteException}
|
|
241
|
+
* @returns {Promise}
|
|
242
|
+
*/
|
|
243
|
+
async deleteBucket(bucketId) {
|
|
244
|
+
if (typeof bucketId === 'undefined') {
|
|
245
|
+
throw new AppwriteException('Missing required parameter: "bucketId"');
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
let path = '/storage/buckets/{bucketId}'.replace('{bucketId}', bucketId);
|
|
249
|
+
let payload = {};
|
|
250
|
+
|
|
251
|
+
return await this.client.call('delete', path, {
|
|
252
|
+
'content-type': 'application/json',
|
|
253
|
+
}, payload);
|
|
254
|
+
}
|
|
255
|
+
|
|
6
256
|
/**
|
|
7
257
|
* List Files
|
|
8
258
|
*
|
|
@@ -10,6 +260,7 @@ class Storage extends Service {
|
|
|
10
260
|
* your results. On admin mode, this endpoint will return a list of all of the
|
|
11
261
|
* project's files. [Learn more about different API modes](/docs/admin).
|
|
12
262
|
*
|
|
263
|
+
* @param {string} bucketId
|
|
13
264
|
* @param {string} search
|
|
14
265
|
* @param {number} limit
|
|
15
266
|
* @param {number} offset
|
|
@@ -19,8 +270,12 @@ class Storage extends Service {
|
|
|
19
270
|
* @throws {AppwriteException}
|
|
20
271
|
* @returns {Promise}
|
|
21
272
|
*/
|
|
22
|
-
async listFiles(search, limit, offset, cursor, cursorDirection, orderType) {
|
|
23
|
-
|
|
273
|
+
async listFiles(bucketId, search, limit, offset, cursor, cursorDirection, orderType) {
|
|
274
|
+
if (typeof bucketId === 'undefined') {
|
|
275
|
+
throw new AppwriteException('Missing required parameter: "bucketId"');
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
let path = '/storage/buckets/{bucketId}/files'.replace('{bucketId}', bucketId);
|
|
24
279
|
let payload = {};
|
|
25
280
|
|
|
26
281
|
if (typeof search !== 'undefined') {
|
|
@@ -55,18 +310,38 @@ class Storage extends Service {
|
|
|
55
310
|
/**
|
|
56
311
|
* Create File
|
|
57
312
|
*
|
|
58
|
-
* Create a new file.
|
|
59
|
-
*
|
|
60
|
-
*
|
|
313
|
+
* Create a new file. Before using this route, you should create a new bucket
|
|
314
|
+
* resource using either a [server
|
|
315
|
+
* integration](/docs/server/database#storageCreateBucket) API or directly
|
|
316
|
+
* from your Appwrite console.
|
|
317
|
+
*
|
|
318
|
+
* Larger files should be uploaded using multiple requests with the
|
|
319
|
+
* [content-range](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Range)
|
|
320
|
+
* header to send a partial request with a maximum supported chunk of `5MB`.
|
|
321
|
+
* The `content-range` header values should always be in bytes.
|
|
322
|
+
*
|
|
323
|
+
* When the first request is sent, the server will return the **File** object,
|
|
324
|
+
* and the subsequent part request must include the file's **id** in
|
|
325
|
+
* `x-appwrite-id` header to allow the server to know that the partial upload
|
|
326
|
+
* is for the existing file and not for a new one.
|
|
327
|
+
*
|
|
328
|
+
* If you're creating a new file using one of the Appwrite SDKs, all the
|
|
329
|
+
* chunking logic will be managed by the SDK internally.
|
|
330
|
+
*
|
|
61
331
|
*
|
|
332
|
+
* @param {string} bucketId
|
|
62
333
|
* @param {string} fileId
|
|
63
|
-
* @param {
|
|
334
|
+
* @param {string} file
|
|
64
335
|
* @param {string[]} read
|
|
65
336
|
* @param {string[]} write
|
|
66
337
|
* @throws {AppwriteException}
|
|
67
338
|
* @returns {Promise}
|
|
68
339
|
*/
|
|
69
|
-
async createFile(fileId, file, read, write) {
|
|
340
|
+
async createFile(bucketId, fileId, file, read, write, onProgress = () => {}) {
|
|
341
|
+
if (typeof bucketId === 'undefined') {
|
|
342
|
+
throw new AppwriteException('Missing required parameter: "bucketId"');
|
|
343
|
+
}
|
|
344
|
+
|
|
70
345
|
if (typeof fileId === 'undefined') {
|
|
71
346
|
throw new AppwriteException('Missing required parameter: "fileId"');
|
|
72
347
|
}
|
|
@@ -75,7 +350,7 @@ class Storage extends Service {
|
|
|
75
350
|
throw new AppwriteException('Missing required parameter: "file"');
|
|
76
351
|
}
|
|
77
352
|
|
|
78
|
-
let path = '/storage/files';
|
|
353
|
+
let path = '/storage/buckets/{bucketId}/files'.replace('{bucketId}', bucketId);
|
|
79
354
|
let payload = {};
|
|
80
355
|
|
|
81
356
|
if (typeof fileId !== 'undefined') {
|
|
@@ -83,7 +358,7 @@ class Storage extends Service {
|
|
|
83
358
|
}
|
|
84
359
|
|
|
85
360
|
if (typeof file !== 'undefined') {
|
|
86
|
-
payload['file'] = file;
|
|
361
|
+
payload['file'] = file.toString();
|
|
87
362
|
}
|
|
88
363
|
|
|
89
364
|
if (typeof read !== 'undefined') {
|
|
@@ -94,9 +369,68 @@ class Storage extends Service {
|
|
|
94
369
|
payload['write'] = write;
|
|
95
370
|
}
|
|
96
371
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
372
|
+
const { size: size } = await promisify(fs.stat)(file);
|
|
373
|
+
|
|
374
|
+
if (size <= client.CHUNK_SIZE) {
|
|
375
|
+
payload['file'] = fs.createReadStream(file);
|
|
376
|
+
|
|
377
|
+
return await this.client.call('post', path, {
|
|
378
|
+
'content-type': 'multipart/form-data',
|
|
379
|
+
}, payload);
|
|
380
|
+
} else {
|
|
381
|
+
let id = undefined;
|
|
382
|
+
let response = undefined;
|
|
383
|
+
|
|
384
|
+
let counter = 0;
|
|
385
|
+
const totalCounters = Math.ceil(size / client.CHUNK_SIZE);
|
|
386
|
+
|
|
387
|
+
const headers = {
|
|
388
|
+
'content-type': 'multipart/form-data',
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
if(fileId != 'unique()') {
|
|
392
|
+
try {
|
|
393
|
+
response = await this.client.call('get', path + '/' + fileId, headers);
|
|
394
|
+
counter = response.chunksUploaded;
|
|
395
|
+
} catch(e) {
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
for (counter; counter < totalCounters; counter++) {
|
|
400
|
+
const start = (counter * client.CHUNK_SIZE);
|
|
401
|
+
const end = Math.min((((counter * client.CHUNK_SIZE) + client.CHUNK_SIZE) - 1), size);
|
|
402
|
+
|
|
403
|
+
headers['content-range'] = 'bytes ' + start + '-' + end + '/' + size;
|
|
404
|
+
|
|
405
|
+
if (id) {
|
|
406
|
+
headers['x-appwrite-id'] = id;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
const stream = fs.createReadStream(file, {
|
|
410
|
+
start,
|
|
411
|
+
end
|
|
412
|
+
});
|
|
413
|
+
payload['file'] = stream;
|
|
414
|
+
|
|
415
|
+
response = await this.client.call('post', path, headers, payload);
|
|
416
|
+
|
|
417
|
+
if (!id) {
|
|
418
|
+
id = response['$id'];
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
if (onProgress !== null) {
|
|
422
|
+
onProgress({
|
|
423
|
+
$id: response['$id'],
|
|
424
|
+
progress: Math.min((counter+1) * client.CHUNK_SIZE, size) / size * 100,
|
|
425
|
+
sizeUploaded: end+1,
|
|
426
|
+
chunksTotal: response['chunksTotal'],
|
|
427
|
+
chunksUploaded: response['chunksUploaded']
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
return response;
|
|
433
|
+
}
|
|
100
434
|
}
|
|
101
435
|
|
|
102
436
|
/**
|
|
@@ -105,16 +439,21 @@ class Storage extends Service {
|
|
|
105
439
|
* Get a file by its unique ID. This endpoint response returns a JSON object
|
|
106
440
|
* with the file metadata.
|
|
107
441
|
*
|
|
442
|
+
* @param {string} bucketId
|
|
108
443
|
* @param {string} fileId
|
|
109
444
|
* @throws {AppwriteException}
|
|
110
445
|
* @returns {Promise}
|
|
111
446
|
*/
|
|
112
|
-
async getFile(fileId) {
|
|
447
|
+
async getFile(bucketId, fileId) {
|
|
448
|
+
if (typeof bucketId === 'undefined') {
|
|
449
|
+
throw new AppwriteException('Missing required parameter: "bucketId"');
|
|
450
|
+
}
|
|
451
|
+
|
|
113
452
|
if (typeof fileId === 'undefined') {
|
|
114
453
|
throw new AppwriteException('Missing required parameter: "fileId"');
|
|
115
454
|
}
|
|
116
455
|
|
|
117
|
-
let path = '/storage/files/{fileId}'.replace('{fileId}', fileId);
|
|
456
|
+
let path = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
|
|
118
457
|
let payload = {};
|
|
119
458
|
|
|
120
459
|
return await this.client.call('get', path, {
|
|
@@ -128,26 +467,23 @@ class Storage extends Service {
|
|
|
128
467
|
* Update a file by its unique ID. Only users with write permissions have
|
|
129
468
|
* access to update this resource.
|
|
130
469
|
*
|
|
470
|
+
* @param {string} bucketId
|
|
131
471
|
* @param {string} fileId
|
|
132
472
|
* @param {string[]} read
|
|
133
473
|
* @param {string[]} write
|
|
134
474
|
* @throws {AppwriteException}
|
|
135
475
|
* @returns {Promise}
|
|
136
476
|
*/
|
|
137
|
-
async updateFile(fileId, read, write) {
|
|
138
|
-
if (typeof
|
|
139
|
-
throw new AppwriteException('Missing required parameter: "
|
|
477
|
+
async updateFile(bucketId, fileId, read, write) {
|
|
478
|
+
if (typeof bucketId === 'undefined') {
|
|
479
|
+
throw new AppwriteException('Missing required parameter: "bucketId"');
|
|
140
480
|
}
|
|
141
481
|
|
|
142
|
-
if (typeof
|
|
143
|
-
throw new AppwriteException('Missing required parameter: "
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
if (typeof write === 'undefined') {
|
|
147
|
-
throw new AppwriteException('Missing required parameter: "write"');
|
|
482
|
+
if (typeof fileId === 'undefined') {
|
|
483
|
+
throw new AppwriteException('Missing required parameter: "fileId"');
|
|
148
484
|
}
|
|
149
485
|
|
|
150
|
-
let path = '/storage/files/{fileId}'.replace('{fileId}', fileId);
|
|
486
|
+
let path = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
|
|
151
487
|
let payload = {};
|
|
152
488
|
|
|
153
489
|
if (typeof read !== 'undefined') {
|
|
@@ -169,16 +505,21 @@ class Storage extends Service {
|
|
|
169
505
|
* Delete a file by its unique ID. Only users with write permissions have
|
|
170
506
|
* access to delete this resource.
|
|
171
507
|
*
|
|
508
|
+
* @param {string} bucketId
|
|
172
509
|
* @param {string} fileId
|
|
173
510
|
* @throws {AppwriteException}
|
|
174
511
|
* @returns {Promise}
|
|
175
512
|
*/
|
|
176
|
-
async deleteFile(fileId) {
|
|
513
|
+
async deleteFile(bucketId, fileId) {
|
|
514
|
+
if (typeof bucketId === 'undefined') {
|
|
515
|
+
throw new AppwriteException('Missing required parameter: "bucketId"');
|
|
516
|
+
}
|
|
517
|
+
|
|
177
518
|
if (typeof fileId === 'undefined') {
|
|
178
519
|
throw new AppwriteException('Missing required parameter: "fileId"');
|
|
179
520
|
}
|
|
180
521
|
|
|
181
|
-
let path = '/storage/files/{fileId}'.replace('{fileId}', fileId);
|
|
522
|
+
let path = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
|
|
182
523
|
let payload = {};
|
|
183
524
|
|
|
184
525
|
return await this.client.call('delete', path, {
|
|
@@ -193,16 +534,21 @@ class Storage extends Service {
|
|
|
193
534
|
* 'Content-Disposition: attachment' header that tells the browser to start
|
|
194
535
|
* downloading the file to user downloads directory.
|
|
195
536
|
*
|
|
537
|
+
* @param {string} bucketId
|
|
196
538
|
* @param {string} fileId
|
|
197
539
|
* @throws {AppwriteException}
|
|
198
540
|
* @returns {Promise}
|
|
199
541
|
*/
|
|
200
|
-
async getFileDownload(fileId) {
|
|
542
|
+
async getFileDownload(bucketId, fileId) {
|
|
543
|
+
if (typeof bucketId === 'undefined') {
|
|
544
|
+
throw new AppwriteException('Missing required parameter: "bucketId"');
|
|
545
|
+
}
|
|
546
|
+
|
|
201
547
|
if (typeof fileId === 'undefined') {
|
|
202
548
|
throw new AppwriteException('Missing required parameter: "fileId"');
|
|
203
549
|
}
|
|
204
550
|
|
|
205
|
-
let path = '/storage/files/{fileId}/download'.replace('{fileId}', fileId);
|
|
551
|
+
let path = '/storage/buckets/{bucketId}/files/{fileId}/download'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
|
|
206
552
|
let payload = {};
|
|
207
553
|
|
|
208
554
|
return await this.client.call('get', path, {
|
|
@@ -216,8 +562,10 @@ class Storage extends Service {
|
|
|
216
562
|
* Get a file preview image. Currently, this method supports preview for image
|
|
217
563
|
* files (jpg, png, and gif), other supported formats, like pdf, docs, slides,
|
|
218
564
|
* and spreadsheets, will return the file icon image. You can also pass query
|
|
219
|
-
* string arguments for cutting and resizing your preview image.
|
|
565
|
+
* string arguments for cutting and resizing your preview image. Preview is
|
|
566
|
+
* supported only for image files smaller than 10MB.
|
|
220
567
|
*
|
|
568
|
+
* @param {string} bucketId
|
|
221
569
|
* @param {string} fileId
|
|
222
570
|
* @param {number} width
|
|
223
571
|
* @param {number} height
|
|
@@ -233,12 +581,16 @@ class Storage extends Service {
|
|
|
233
581
|
* @throws {AppwriteException}
|
|
234
582
|
* @returns {Promise}
|
|
235
583
|
*/
|
|
236
|
-
async getFilePreview(fileId, width, height, gravity, quality, borderWidth, borderColor, borderRadius, opacity, rotation, background, output) {
|
|
584
|
+
async getFilePreview(bucketId, fileId, width, height, gravity, quality, borderWidth, borderColor, borderRadius, opacity, rotation, background, output) {
|
|
585
|
+
if (typeof bucketId === 'undefined') {
|
|
586
|
+
throw new AppwriteException('Missing required parameter: "bucketId"');
|
|
587
|
+
}
|
|
588
|
+
|
|
237
589
|
if (typeof fileId === 'undefined') {
|
|
238
590
|
throw new AppwriteException('Missing required parameter: "fileId"');
|
|
239
591
|
}
|
|
240
592
|
|
|
241
|
-
let path = '/storage/files/{fileId}/preview'.replace('{fileId}', fileId);
|
|
593
|
+
let path = '/storage/buckets/{bucketId}/files/{fileId}/preview'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
|
|
242
594
|
let payload = {};
|
|
243
595
|
|
|
244
596
|
if (typeof width !== 'undefined') {
|
|
@@ -297,16 +649,21 @@ class Storage extends Service {
|
|
|
297
649
|
* download method but returns with no 'Content-Disposition: attachment'
|
|
298
650
|
* header.
|
|
299
651
|
*
|
|
652
|
+
* @param {string} bucketId
|
|
300
653
|
* @param {string} fileId
|
|
301
654
|
* @throws {AppwriteException}
|
|
302
655
|
* @returns {Promise}
|
|
303
656
|
*/
|
|
304
|
-
async getFileView(fileId) {
|
|
657
|
+
async getFileView(bucketId, fileId) {
|
|
658
|
+
if (typeof bucketId === 'undefined') {
|
|
659
|
+
throw new AppwriteException('Missing required parameter: "bucketId"');
|
|
660
|
+
}
|
|
661
|
+
|
|
305
662
|
if (typeof fileId === 'undefined') {
|
|
306
663
|
throw new AppwriteException('Missing required parameter: "fileId"');
|
|
307
664
|
}
|
|
308
665
|
|
|
309
|
-
let path = '/storage/files/{fileId}/view'.replace('{fileId}', fileId);
|
|
666
|
+
let path = '/storage/buckets/{bucketId}/files/{fileId}/view'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
|
|
310
667
|
let payload = {};
|
|
311
668
|
|
|
312
669
|
return await this.client.call('get', path, {
|
package/lib/services/teams.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
const Service = require('../service.js');
|
|
2
2
|
const AppwriteException = require('../exception.js');
|
|
3
|
+
const client = require('../client.js');
|
|
4
|
+
const { promisify } = require('util');
|
|
5
|
+
const fs = require('fs');
|
|
3
6
|
|
|
4
7
|
class Teams extends Service {
|
|
5
8
|
|
|
@@ -395,6 +398,10 @@ class Teams extends Service {
|
|
|
395
398
|
* Use this endpoint to allow a user to accept an invitation to join a team
|
|
396
399
|
* after being redirected back to your app from the invitation email received
|
|
397
400
|
* by the user.
|
|
401
|
+
*
|
|
402
|
+
* If the request is successful, a session for the user is automatically
|
|
403
|
+
* created.
|
|
404
|
+
*
|
|
398
405
|
*
|
|
399
406
|
* @param {string} teamId
|
|
400
407
|
* @param {string} membershipId
|
package/lib/services/users.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
const Service = require('../service.js');
|
|
2
2
|
const AppwriteException = require('../exception.js');
|
|
3
|
+
const client = require('../client.js');
|
|
4
|
+
const { promisify } = require('util');
|
|
5
|
+
const fs = require('fs');
|
|
3
6
|
|
|
4
7
|
class Users extends Service {
|
|
5
8
|
|
|
@@ -125,7 +128,11 @@ class Users extends Service {
|
|
|
125
128
|
/**
|
|
126
129
|
* Delete User
|
|
127
130
|
*
|
|
128
|
-
* Delete a user by its unique ID.
|
|
131
|
+
* Delete a user by its unique ID, thereby releasing it's ID. Since ID is
|
|
132
|
+
* released and can be reused, all user-related resources like documents or
|
|
133
|
+
* storage files should be deleted before user deletion. If you want to keep
|
|
134
|
+
* ID reserved, use the [updateStatus](/docs/server/users#usersUpdateStatus)
|
|
135
|
+
* endpoint instead.
|
|
129
136
|
*
|
|
130
137
|
* @param {string} userId
|
|
131
138
|
* @throws {AppwriteException}
|
|
@@ -207,6 +214,28 @@ class Users extends Service {
|
|
|
207
214
|
}, payload);
|
|
208
215
|
}
|
|
209
216
|
|
|
217
|
+
/**
|
|
218
|
+
* Get User Memberships
|
|
219
|
+
*
|
|
220
|
+
* Get the user membership list by its unique ID.
|
|
221
|
+
*
|
|
222
|
+
* @param {string} userId
|
|
223
|
+
* @throws {AppwriteException}
|
|
224
|
+
* @returns {Promise}
|
|
225
|
+
*/
|
|
226
|
+
async getMemberships(userId) {
|
|
227
|
+
if (typeof userId === 'undefined') {
|
|
228
|
+
throw new AppwriteException('Missing required parameter: "userId"');
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
let path = '/users/{userId}/memberships'.replace('{userId}', userId);
|
|
232
|
+
let payload = {};
|
|
233
|
+
|
|
234
|
+
return await this.client.call('get', path, {
|
|
235
|
+
'content-type': 'application/json',
|
|
236
|
+
}, payload);
|
|
237
|
+
}
|
|
238
|
+
|
|
210
239
|
/**
|
|
211
240
|
* Update Name
|
|
212
241
|
*
|
|
@@ -398,7 +427,8 @@ class Users extends Service {
|
|
|
398
427
|
/**
|
|
399
428
|
* Update User Status
|
|
400
429
|
*
|
|
401
|
-
* Update the user status by its unique ID.
|
|
430
|
+
* Update the user status by its unique ID. Use this endpoint as an
|
|
431
|
+
* alternative to deleting a user if you want to keep user's ID reserved.
|
|
402
432
|
*
|
|
403
433
|
* @param {string} userId
|
|
404
434
|
* @param {boolean} status
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "node-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": "
|
|
5
|
+
"version": "6.0.0",
|
|
6
6
|
"license": "BSD-3-Clause",
|
|
7
7
|
"main": "./index.js",
|
|
8
8
|
"types": "./index.d.ts",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"axios": "^0.
|
|
15
|
+
"axios": "^0.27.2",
|
|
16
16
|
"form-data": "^4.0.0"
|
|
17
17
|
}
|
|
18
18
|
}
|