appwrite-cli 5.0.5 → 6.0.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/README.md +4 -4
  2. package/docs/examples/functions/create-build.md +1 -1
  3. package/docs/examples/functions/create-execution.md +1 -0
  4. package/docs/examples/functions/create.md +1 -0
  5. package/docs/examples/functions/delete-execution.md +3 -0
  6. package/docs/examples/functions/update-deployment-build.md +3 -0
  7. package/docs/examples/functions/update.md +1 -0
  8. package/docs/examples/projects/create-j-w-t.md +4 -0
  9. package/docs/examples/projects/update-mock-numbers.md +3 -0
  10. package/docs/examples/projects/update-session-alerts.md +3 -0
  11. package/docs/examples/users/create-j-w-t.md +4 -0
  12. package/docs/examples/vcs/get-repository-contents.md +4 -0
  13. package/index.js +34 -7
  14. package/install.ps1 +3 -3
  15. package/install.sh +2 -2
  16. package/lib/client.js +17 -3
  17. package/lib/commands/account.js +306 -152
  18. package/lib/commands/assistant.js +8 -5
  19. package/lib/commands/avatars.js +114 -58
  20. package/lib/commands/console.js +8 -5
  21. package/lib/commands/databases.js +353 -164
  22. package/lib/commands/functions.js +310 -100
  23. package/lib/commands/generic.js +206 -54
  24. package/lib/commands/graphql.js +14 -8
  25. package/lib/commands/health.js +140 -71
  26. package/lib/commands/init.js +250 -155
  27. package/lib/commands/locale.js +50 -26
  28. package/lib/commands/messaging.js +334 -156
  29. package/lib/commands/migrations.js +98 -50
  30. package/lib/commands/project.js +38 -20
  31. package/lib/commands/projects.js +449 -144
  32. package/lib/commands/proxy.js +32 -17
  33. package/lib/commands/pull.js +231 -0
  34. package/lib/commands/push.js +1518 -0
  35. package/lib/commands/run.js +282 -0
  36. package/lib/commands/storage.js +160 -76
  37. package/lib/commands/teams.js +102 -50
  38. package/lib/commands/users.js +324 -134
  39. package/lib/commands/vcs.js +102 -29
  40. package/lib/config.js +190 -18
  41. package/lib/emulation/docker.js +187 -0
  42. package/lib/emulation/utils.js +177 -0
  43. package/lib/id.js +30 -0
  44. package/lib/paginate.js +1 -2
  45. package/lib/parser.js +69 -12
  46. package/lib/questions.js +452 -80
  47. package/lib/sdks.js +1 -1
  48. package/lib/spinner.js +103 -0
  49. package/lib/utils.js +242 -4
  50. package/lib/validations.js +17 -0
  51. package/package.json +6 -2
  52. package/scoop/appwrite.json +3 -3
  53. package/lib/commands/deploy.js +0 -940
@@ -4,7 +4,7 @@ const tar = require("tar");
4
4
  const ignore = require("ignore");
5
5
  const { promisify } = require('util');
6
6
  const libClient = require('../client.js');
7
- const { getAllFiles } = require('../utils.js');
7
+ const { getAllFiles, showConsoleLink } = require('../utils.js');
8
8
  const { Command } = require('commander');
9
9
  const { sdkForProject, sdkForConsole } = require('../sdks')
10
10
  const { parse, actionRunner, parseInteger, parseBool, commandDescriptions, success, log } = require('../parser')
@@ -43,6 +43,7 @@ const storage = new Command("storage").description(commandDescriptions['storage'
43
43
  * @typedef {Object} StorageListBucketsRequestParams
44
44
  * @property {string[]} queries Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: enabled, name, fileSecurity, maximumFileSize, encryption, antivirus
45
45
  * @property {string} search Search term to filter your list results. Max length: 256 chars.
46
+ * @property {boolean} overrideForCli
46
47
  * @property {boolean} parseOutput
47
48
  * @property {libClient | undefined} sdk
48
49
  */
@@ -50,8 +51,9 @@ const storage = new Command("storage").description(commandDescriptions['storage'
50
51
  /**
51
52
  * @param {StorageListBucketsRequestParams} params
52
53
  */
53
- const storageListBuckets = async ({ queries, search, parseOutput = true, sdk = undefined}) => {
54
- let client = !sdk ? await sdkForProject() : sdk;
54
+ const storageListBuckets = async ({queries,search,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => {
55
+ let client = !sdk ? await sdkForProject() :
56
+ sdk;
55
57
  let apiPath = '/storage/buckets';
56
58
  let payload = {};
57
59
  if (typeof queries !== 'undefined') {
@@ -68,11 +70,16 @@ const storageListBuckets = async ({ queries, search, parseOutput = true, sdk = u
68
70
  }, payload);
69
71
 
70
72
  if (parseOutput) {
71
- parse(response)
72
- success()
73
+ if(console) {
74
+ showConsoleLink('storage', 'listBuckets');
75
+ } else {
76
+ parse(response)
77
+ success()
78
+ }
73
79
  }
74
-
80
+
75
81
  return response;
82
+
76
83
  }
77
84
 
78
85
  /**
@@ -87,6 +94,7 @@ const storageListBuckets = async ({ queries, search, parseOutput = true, sdk = u
87
94
  * @property {Compression} compression Compression algorithm choosen for compression. Can be one of none, [gzip](https://en.wikipedia.org/wiki/Gzip), or [zstd](https://en.wikipedia.org/wiki/Zstd), For file size above 20MB compression is skipped even if it's enabled
88
95
  * @property {boolean} encryption Is encryption enabled? For file size above 20MB encryption is skipped even if it's enabled
89
96
  * @property {boolean} antivirus Is virus scanning enabled? For file size above 20MB AntiVirus scanning is skipped even if it's enabled
97
+ * @property {boolean} overrideForCli
90
98
  * @property {boolean} parseOutput
91
99
  * @property {libClient | undefined} sdk
92
100
  */
@@ -94,8 +102,9 @@ const storageListBuckets = async ({ queries, search, parseOutput = true, sdk = u
94
102
  /**
95
103
  * @param {StorageCreateBucketRequestParams} params
96
104
  */
97
- const storageCreateBucket = async ({ bucketId, name, permissions, fileSecurity, enabled, maximumFileSize, allowedFileExtensions, compression, encryption, antivirus, parseOutput = true, sdk = undefined}) => {
98
- let client = !sdk ? await sdkForProject() : sdk;
105
+ const storageCreateBucket = async ({bucketId,name,permissions,fileSecurity,enabled,maximumFileSize,allowedFileExtensions,compression,encryption,antivirus,parseOutput = true, overrideForCli = false, sdk = undefined}) => {
106
+ let client = !sdk ? await sdkForProject() :
107
+ sdk;
99
108
  let apiPath = '/storage/buckets';
100
109
  let payload = {};
101
110
  if (typeof bucketId !== 'undefined') {
@@ -141,13 +150,15 @@ const storageCreateBucket = async ({ bucketId, name, permissions, fileSecurity,
141
150
  parse(response)
142
151
  success()
143
152
  }
144
-
153
+
145
154
  return response;
155
+
146
156
  }
147
157
 
148
158
  /**
149
159
  * @typedef {Object} StorageGetBucketRequestParams
150
160
  * @property {string} bucketId Bucket unique ID.
161
+ * @property {boolean} overrideForCli
151
162
  * @property {boolean} parseOutput
152
163
  * @property {libClient | undefined} sdk
153
164
  */
@@ -155,8 +166,9 @@ const storageCreateBucket = async ({ bucketId, name, permissions, fileSecurity,
155
166
  /**
156
167
  * @param {StorageGetBucketRequestParams} params
157
168
  */
158
- const storageGetBucket = async ({ bucketId, parseOutput = true, sdk = undefined}) => {
159
- let client = !sdk ? await sdkForProject() : sdk;
169
+ const storageGetBucket = async ({bucketId,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => {
170
+ let client = !sdk ? await sdkForProject() :
171
+ sdk;
160
172
  let apiPath = '/storage/buckets/{bucketId}'.replace('{bucketId}', bucketId);
161
173
  let payload = {};
162
174
 
@@ -167,11 +179,16 @@ const storageGetBucket = async ({ bucketId, parseOutput = true, sdk = undefined}
167
179
  }, payload);
168
180
 
169
181
  if (parseOutput) {
170
- parse(response)
171
- success()
182
+ if(console) {
183
+ showConsoleLink('storage', 'getBucket', bucketId);
184
+ } else {
185
+ parse(response)
186
+ success()
187
+ }
172
188
  }
173
-
189
+
174
190
  return response;
191
+
175
192
  }
176
193
 
177
194
  /**
@@ -186,6 +203,7 @@ const storageGetBucket = async ({ bucketId, parseOutput = true, sdk = undefined}
186
203
  * @property {Compression} compression Compression algorithm choosen for compression. Can be one of none, [gzip](https://en.wikipedia.org/wiki/Gzip), or [zstd](https://en.wikipedia.org/wiki/Zstd), For file size above 20MB compression is skipped even if it's enabled
187
204
  * @property {boolean} encryption Is encryption enabled? For file size above 20MB encryption is skipped even if it's enabled
188
205
  * @property {boolean} antivirus Is virus scanning enabled? For file size above 20MB AntiVirus scanning is skipped even if it's enabled
206
+ * @property {boolean} overrideForCli
189
207
  * @property {boolean} parseOutput
190
208
  * @property {libClient | undefined} sdk
191
209
  */
@@ -193,8 +211,9 @@ const storageGetBucket = async ({ bucketId, parseOutput = true, sdk = undefined}
193
211
  /**
194
212
  * @param {StorageUpdateBucketRequestParams} params
195
213
  */
196
- const storageUpdateBucket = async ({ bucketId, name, permissions, fileSecurity, enabled, maximumFileSize, allowedFileExtensions, compression, encryption, antivirus, parseOutput = true, sdk = undefined}) => {
197
- let client = !sdk ? await sdkForProject() : sdk;
214
+ const storageUpdateBucket = async ({bucketId,name,permissions,fileSecurity,enabled,maximumFileSize,allowedFileExtensions,compression,encryption,antivirus,parseOutput = true, overrideForCli = false, sdk = undefined}) => {
215
+ let client = !sdk ? await sdkForProject() :
216
+ sdk;
198
217
  let apiPath = '/storage/buckets/{bucketId}'.replace('{bucketId}', bucketId);
199
218
  let payload = {};
200
219
  if (typeof name !== 'undefined') {
@@ -237,13 +256,15 @@ const storageUpdateBucket = async ({ bucketId, name, permissions, fileSecurity,
237
256
  parse(response)
238
257
  success()
239
258
  }
240
-
259
+
241
260
  return response;
261
+
242
262
  }
243
263
 
244
264
  /**
245
265
  * @typedef {Object} StorageDeleteBucketRequestParams
246
266
  * @property {string} bucketId Bucket unique ID.
267
+ * @property {boolean} overrideForCli
247
268
  * @property {boolean} parseOutput
248
269
  * @property {libClient | undefined} sdk
249
270
  */
@@ -251,8 +272,9 @@ const storageUpdateBucket = async ({ bucketId, name, permissions, fileSecurity,
251
272
  /**
252
273
  * @param {StorageDeleteBucketRequestParams} params
253
274
  */
254
- const storageDeleteBucket = async ({ bucketId, parseOutput = true, sdk = undefined}) => {
255
- let client = !sdk ? await sdkForProject() : sdk;
275
+ const storageDeleteBucket = async ({bucketId,parseOutput = true, overrideForCli = false, sdk = undefined}) => {
276
+ let client = !sdk ? await sdkForProject() :
277
+ sdk;
256
278
  let apiPath = '/storage/buckets/{bucketId}'.replace('{bucketId}', bucketId);
257
279
  let payload = {};
258
280
 
@@ -266,8 +288,9 @@ const storageDeleteBucket = async ({ bucketId, parseOutput = true, sdk = undefin
266
288
  parse(response)
267
289
  success()
268
290
  }
269
-
291
+
270
292
  return response;
293
+
271
294
  }
272
295
 
273
296
  /**
@@ -275,6 +298,7 @@ const storageDeleteBucket = async ({ bucketId, parseOutput = true, sdk = undefin
275
298
  * @property {string} bucketId Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket).
276
299
  * @property {string[]} queries Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name, signature, mimeType, sizeOriginal, chunksTotal, chunksUploaded
277
300
  * @property {string} search Search term to filter your list results. Max length: 256 chars.
301
+ * @property {boolean} overrideForCli
278
302
  * @property {boolean} parseOutput
279
303
  * @property {libClient | undefined} sdk
280
304
  */
@@ -282,8 +306,9 @@ const storageDeleteBucket = async ({ bucketId, parseOutput = true, sdk = undefin
282
306
  /**
283
307
  * @param {StorageListFilesRequestParams} params
284
308
  */
285
- const storageListFiles = async ({ bucketId, queries, search, parseOutput = true, sdk = undefined}) => {
286
- let client = !sdk ? await sdkForProject() : sdk;
309
+ const storageListFiles = async ({bucketId,queries,search,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => {
310
+ let client = !sdk ? await sdkForProject() :
311
+ sdk;
287
312
  let apiPath = '/storage/buckets/{bucketId}/files'.replace('{bucketId}', bucketId);
288
313
  let payload = {};
289
314
  if (typeof queries !== 'undefined') {
@@ -300,19 +325,25 @@ const storageListFiles = async ({ bucketId, queries, search, parseOutput = true,
300
325
  }, payload);
301
326
 
302
327
  if (parseOutput) {
303
- parse(response)
304
- success()
328
+ if(console) {
329
+ showConsoleLink('storage', 'listFiles', bucketId);
330
+ } else {
331
+ parse(response)
332
+ success()
333
+ }
305
334
  }
306
-
335
+
307
336
  return response;
337
+
308
338
  }
309
339
 
310
340
  /**
311
341
  * @typedef {Object} StorageCreateFileRequestParams
312
342
  * @property {string} bucketId Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket).
313
343
  * @property {string} fileId File ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.
314
- * @property {string} file Binary file. Appwrite SDKs provide helpers to handle file input. [Learn about file input](https://appwrite.io/docs/storage#file-input).
344
+ * @property {string} file Binary file. Appwrite SDKs provide helpers to handle file input. [Learn about file input](https://appwrite.io/docs/products/storage/upload-download#input-file).
315
345
  * @property {string[]} permissions An array of permission strings. By default, only the current user is granted all permissions. [Learn more about permissions](https://appwrite.io/docs/permissions).
346
+ * @property {boolean} overrideForCli
316
347
  * @property {boolean} parseOutput
317
348
  * @property {libClient | undefined} sdk
318
349
  * @property {CallableFunction} onProgress
@@ -321,8 +352,9 @@ const storageListFiles = async ({ bucketId, queries, search, parseOutput = true,
321
352
  /**
322
353
  * @param {StorageCreateFileRequestParams} params
323
354
  */
324
- const storageCreateFile = async ({ bucketId, fileId, file, permissions, parseOutput = true, sdk = undefined, onProgress = () => {}}) => {
325
- let client = !sdk ? await sdkForProject() : sdk;
355
+ const storageCreateFile = async ({bucketId,fileId,file,permissions,parseOutput = true, overrideForCli = false, sdk = undefined,onProgress = () => {}}) => {
356
+ let client = !sdk ? await sdkForProject() :
357
+ sdk;
326
358
  let apiPath = '/storage/buckets/{bucketId}/files'.replace('{bucketId}', bucketId);
327
359
  let payload = {};
328
360
  if (typeof fileId !== 'undefined') {
@@ -342,7 +374,7 @@ const storageCreateFile = async ({ bucketId, fileId, file, permissions, parseOut
342
374
  }
343
375
 
344
376
  const size = file.size;
345
-
377
+
346
378
  const apiHeaders = {
347
379
  'content-type': 'multipart/form-data',
348
380
  };
@@ -377,7 +409,7 @@ const storageCreateFile = async ({ bucketId, fileId, file, permissions, parseOut
377
409
  }
378
410
 
379
411
  let uploadableChunkTrimmed;
380
-
412
+
381
413
  if(currentPosition + 1 >= client.CHUNK_SIZE) {
382
414
  uploadableChunkTrimmed = uploadableChunk;
383
415
  } else {
@@ -430,7 +462,7 @@ const storageCreateFile = async ({ bucketId, fileId, file, permissions, parseOut
430
462
  await uploadChunk(true);
431
463
  }
432
464
 
433
-
465
+
434
466
  if (parseOutput) {
435
467
  parse(response)
436
468
  success()
@@ -443,6 +475,7 @@ const storageCreateFile = async ({ bucketId, fileId, file, permissions, parseOut
443
475
  * @typedef {Object} StorageGetFileRequestParams
444
476
  * @property {string} bucketId Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket).
445
477
  * @property {string} fileId File ID.
478
+ * @property {boolean} overrideForCli
446
479
  * @property {boolean} parseOutput
447
480
  * @property {libClient | undefined} sdk
448
481
  */
@@ -450,8 +483,9 @@ const storageCreateFile = async ({ bucketId, fileId, file, permissions, parseOut
450
483
  /**
451
484
  * @param {StorageGetFileRequestParams} params
452
485
  */
453
- const storageGetFile = async ({ bucketId, fileId, parseOutput = true, sdk = undefined}) => {
454
- let client = !sdk ? await sdkForProject() : sdk;
486
+ const storageGetFile = async ({bucketId,fileId,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => {
487
+ let client = !sdk ? await sdkForProject() :
488
+ sdk;
455
489
  let apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
456
490
  let payload = {};
457
491
 
@@ -462,11 +496,16 @@ const storageGetFile = async ({ bucketId, fileId, parseOutput = true, sdk = unde
462
496
  }, payload);
463
497
 
464
498
  if (parseOutput) {
465
- parse(response)
466
- success()
499
+ if(console) {
500
+ showConsoleLink('storage', 'getFile', bucketId, fileId);
501
+ } else {
502
+ parse(response)
503
+ success()
504
+ }
467
505
  }
468
-
506
+
469
507
  return response;
508
+
470
509
  }
471
510
 
472
511
  /**
@@ -475,6 +514,7 @@ const storageGetFile = async ({ bucketId, fileId, parseOutput = true, sdk = unde
475
514
  * @property {string} fileId File unique ID.
476
515
  * @property {string} name Name of the file
477
516
  * @property {string[]} permissions An array of permission string. By default, the current permissions are inherited. [Learn more about permissions](https://appwrite.io/docs/permissions).
517
+ * @property {boolean} overrideForCli
478
518
  * @property {boolean} parseOutput
479
519
  * @property {libClient | undefined} sdk
480
520
  */
@@ -482,8 +522,9 @@ const storageGetFile = async ({ bucketId, fileId, parseOutput = true, sdk = unde
482
522
  /**
483
523
  * @param {StorageUpdateFileRequestParams} params
484
524
  */
485
- const storageUpdateFile = async ({ bucketId, fileId, name, permissions, parseOutput = true, sdk = undefined}) => {
486
- let client = !sdk ? await sdkForProject() : sdk;
525
+ const storageUpdateFile = async ({bucketId,fileId,name,permissions,parseOutput = true, overrideForCli = false, sdk = undefined}) => {
526
+ let client = !sdk ? await sdkForProject() :
527
+ sdk;
487
528
  let apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
488
529
  let payload = {};
489
530
  if (typeof name !== 'undefined') {
@@ -504,14 +545,16 @@ const storageUpdateFile = async ({ bucketId, fileId, name, permissions, parseOut
504
545
  parse(response)
505
546
  success()
506
547
  }
507
-
548
+
508
549
  return response;
550
+
509
551
  }
510
552
 
511
553
  /**
512
554
  * @typedef {Object} StorageDeleteFileRequestParams
513
555
  * @property {string} bucketId Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket).
514
556
  * @property {string} fileId File ID.
557
+ * @property {boolean} overrideForCli
515
558
  * @property {boolean} parseOutput
516
559
  * @property {libClient | undefined} sdk
517
560
  */
@@ -519,8 +562,9 @@ const storageUpdateFile = async ({ bucketId, fileId, name, permissions, parseOut
519
562
  /**
520
563
  * @param {StorageDeleteFileRequestParams} params
521
564
  */
522
- const storageDeleteFile = async ({ bucketId, fileId, parseOutput = true, sdk = undefined}) => {
523
- let client = !sdk ? await sdkForProject() : sdk;
565
+ const storageDeleteFile = async ({bucketId,fileId,parseOutput = true, overrideForCli = false, sdk = undefined}) => {
566
+ let client = !sdk ? await sdkForProject() :
567
+ sdk;
524
568
  let apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
525
569
  let payload = {};
526
570
 
@@ -534,14 +578,16 @@ const storageDeleteFile = async ({ bucketId, fileId, parseOutput = true, sdk = u
534
578
  parse(response)
535
579
  success()
536
580
  }
537
-
581
+
538
582
  return response;
583
+
539
584
  }
540
585
 
541
586
  /**
542
587
  * @typedef {Object} StorageGetFileDownloadRequestParams
543
588
  * @property {string} bucketId Storage bucket ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket).
544
589
  * @property {string} fileId File ID.
590
+ * @property {boolean} overrideForCli
545
591
  * @property {boolean} parseOutput
546
592
  * @property {libClient | undefined} sdk
547
593
  * @property {string} destination
@@ -550,14 +596,17 @@ const storageDeleteFile = async ({ bucketId, fileId, parseOutput = true, sdk = u
550
596
  /**
551
597
  * @param {StorageGetFileDownloadRequestParams} params
552
598
  */
553
- const storageGetFileDownload = async ({ bucketId, fileId, parseOutput = true, sdk = undefined, destination}) => {
554
- let client = !sdk ? await sdkForProject() : sdk;
599
+ const storageGetFileDownload = async ({bucketId,fileId,parseOutput = true, overrideForCli = false, sdk = undefined, destination}) => {
600
+ let client = !sdk ? await sdkForProject() :
601
+ sdk;
555
602
  let apiPath = '/storage/buckets/{bucketId}/files/{fileId}/download'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
556
603
  let payload = {};
557
- payload['project'] = localConfig.getProject().projectId
558
- payload['key'] = globalConfig.getKey();
559
- const queryParams = new URLSearchParams(payload);
560
- apiPath = `${globalConfig.getEndpoint()}${apiPath}?${queryParams.toString()}`;
604
+ if (!overrideForCli) {
605
+ payload['project'] = localConfig.getProject().projectId
606
+ payload['key'] = globalConfig.getKey();
607
+ const queryParams = new URLSearchParams(payload);
608
+ apiPath = `${globalConfig.getEndpoint()}${apiPath}?${queryParams.toString()}`;
609
+ }
561
610
 
562
611
  let response = undefined;
563
612
 
@@ -565,14 +614,18 @@ const storageGetFileDownload = async ({ bucketId, fileId, parseOutput = true, sd
565
614
  'content-type': 'application/json',
566
615
  }, payload, 'arraybuffer');
567
616
 
568
- fs.writeFileSync(destination, response);
617
+ if (overrideForCli) {
618
+ response = Buffer.from(response);
619
+ }
569
620
 
621
+ fs.writeFileSync(destination, response);
570
622
  if (parseOutput) {
571
623
  parse(response)
572
624
  success()
573
625
  }
574
-
626
+
575
627
  return response;
628
+
576
629
  }
577
630
 
578
631
  /**
@@ -590,6 +643,7 @@ const storageGetFileDownload = async ({ bucketId, fileId, parseOutput = true, sd
590
643
  * @property {number} rotation Preview image rotation in degrees. Pass an integer between -360 and 360.
591
644
  * @property {string} background Preview image background color. Only works with transparent images (png). Use a valid HEX color, no # is needed for prefix.
592
645
  * @property {ImageFormat} output Output format type (jpeg, jpg, png, gif and webp).
646
+ * @property {boolean} overrideForCli
593
647
  * @property {boolean} parseOutput
594
648
  * @property {libClient | undefined} sdk
595
649
  * @property {string} destination
@@ -598,8 +652,9 @@ const storageGetFileDownload = async ({ bucketId, fileId, parseOutput = true, sd
598
652
  /**
599
653
  * @param {StorageGetFilePreviewRequestParams} params
600
654
  */
601
- const storageGetFilePreview = async ({ bucketId, fileId, width, height, gravity, quality, borderWidth, borderColor, borderRadius, opacity, rotation, background, output, parseOutput = true, sdk = undefined, destination}) => {
602
- let client = !sdk ? await sdkForProject() : sdk;
655
+ const storageGetFilePreview = async ({bucketId,fileId,width,height,gravity,quality,borderWidth,borderColor,borderRadius,opacity,rotation,background,output,parseOutput = true, overrideForCli = false, sdk = undefined, destination}) => {
656
+ let client = !sdk ? await sdkForProject() :
657
+ sdk;
603
658
  let apiPath = '/storage/buckets/{bucketId}/files/{fileId}/preview'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
604
659
  let payload = {};
605
660
  if (typeof width !== 'undefined') {
@@ -635,10 +690,12 @@ const storageGetFilePreview = async ({ bucketId, fileId, width, height, gravity,
635
690
  if (typeof output !== 'undefined') {
636
691
  payload['output'] = output;
637
692
  }
638
- payload['project'] = localConfig.getProject().projectId
639
- payload['key'] = globalConfig.getKey();
640
- const queryParams = new URLSearchParams(payload);
641
- apiPath = `${globalConfig.getEndpoint()}${apiPath}?${queryParams.toString()}`;
693
+ if (!overrideForCli) {
694
+ payload['project'] = localConfig.getProject().projectId
695
+ payload['key'] = globalConfig.getKey();
696
+ const queryParams = new URLSearchParams(payload);
697
+ apiPath = `${globalConfig.getEndpoint()}${apiPath}?${queryParams.toString()}`;
698
+ }
642
699
 
643
700
  let response = undefined;
644
701
 
@@ -646,20 +703,25 @@ const storageGetFilePreview = async ({ bucketId, fileId, width, height, gravity,
646
703
  'content-type': 'application/json',
647
704
  }, payload, 'arraybuffer');
648
705
 
649
- fs.writeFileSync(destination, response);
706
+ if (overrideForCli) {
707
+ response = Buffer.from(response);
708
+ }
650
709
 
710
+ fs.writeFileSync(destination, response);
651
711
  if (parseOutput) {
652
712
  parse(response)
653
713
  success()
654
714
  }
655
-
715
+
656
716
  return response;
717
+
657
718
  }
658
719
 
659
720
  /**
660
721
  * @typedef {Object} StorageGetFileViewRequestParams
661
722
  * @property {string} bucketId Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket).
662
723
  * @property {string} fileId File ID.
724
+ * @property {boolean} overrideForCli
663
725
  * @property {boolean} parseOutput
664
726
  * @property {libClient | undefined} sdk
665
727
  * @property {string} destination
@@ -668,14 +730,17 @@ const storageGetFilePreview = async ({ bucketId, fileId, width, height, gravity,
668
730
  /**
669
731
  * @param {StorageGetFileViewRequestParams} params
670
732
  */
671
- const storageGetFileView = async ({ bucketId, fileId, parseOutput = true, sdk = undefined, destination}) => {
672
- let client = !sdk ? await sdkForProject() : sdk;
733
+ const storageGetFileView = async ({bucketId,fileId,parseOutput = true, overrideForCli = false, sdk = undefined, destination}) => {
734
+ let client = !sdk ? await sdkForProject() :
735
+ sdk;
673
736
  let apiPath = '/storage/buckets/{bucketId}/files/{fileId}/view'.replace('{bucketId}', bucketId).replace('{fileId}', fileId);
674
737
  let payload = {};
675
- payload['project'] = localConfig.getProject().projectId
676
- payload['key'] = globalConfig.getKey();
677
- const queryParams = new URLSearchParams(payload);
678
- apiPath = `${globalConfig.getEndpoint()}${apiPath}?${queryParams.toString()}`;
738
+ if (!overrideForCli) {
739
+ payload['project'] = localConfig.getProject().projectId
740
+ payload['key'] = globalConfig.getKey();
741
+ const queryParams = new URLSearchParams(payload);
742
+ apiPath = `${globalConfig.getEndpoint()}${apiPath}?${queryParams.toString()}`;
743
+ }
679
744
 
680
745
  let response = undefined;
681
746
 
@@ -683,19 +748,24 @@ const storageGetFileView = async ({ bucketId, fileId, parseOutput = true, sdk =
683
748
  'content-type': 'application/json',
684
749
  }, payload, 'arraybuffer');
685
750
 
686
- fs.writeFileSync(destination, response);
751
+ if (overrideForCli) {
752
+ response = Buffer.from(response);
753
+ }
687
754
 
755
+ fs.writeFileSync(destination, response);
688
756
  if (parseOutput) {
689
757
  parse(response)
690
758
  success()
691
759
  }
692
-
760
+
693
761
  return response;
762
+
694
763
  }
695
764
 
696
765
  /**
697
766
  * @typedef {Object} StorageGetUsageRequestParams
698
767
  * @property {StorageUsageRange} range Date range.
768
+ * @property {boolean} overrideForCli
699
769
  * @property {boolean} parseOutput
700
770
  * @property {libClient | undefined} sdk
701
771
  */
@@ -703,8 +773,9 @@ const storageGetFileView = async ({ bucketId, fileId, parseOutput = true, sdk =
703
773
  /**
704
774
  * @param {StorageGetUsageRequestParams} params
705
775
  */
706
- const storageGetUsage = async ({ range, parseOutput = true, sdk = undefined}) => {
707
- let client = !sdk ? await sdkForProject() : sdk;
776
+ const storageGetUsage = async ({range,parseOutput = true, overrideForCli = false, sdk = undefined}) => {
777
+ let client = !sdk ? await sdkForProject() :
778
+ sdk;
708
779
  let apiPath = '/storage/usage';
709
780
  let payload = {};
710
781
  if (typeof range !== 'undefined') {
@@ -721,14 +792,16 @@ const storageGetUsage = async ({ range, parseOutput = true, sdk = undefined}) =>
721
792
  parse(response)
722
793
  success()
723
794
  }
724
-
795
+
725
796
  return response;
797
+
726
798
  }
727
799
 
728
800
  /**
729
801
  * @typedef {Object} StorageGetBucketUsageRequestParams
730
802
  * @property {string} bucketId Bucket ID.
731
803
  * @property {StorageUsageRange} range Date range.
804
+ * @property {boolean} overrideForCli
732
805
  * @property {boolean} parseOutput
733
806
  * @property {libClient | undefined} sdk
734
807
  */
@@ -736,8 +809,9 @@ const storageGetUsage = async ({ range, parseOutput = true, sdk = undefined}) =>
736
809
  /**
737
810
  * @param {StorageGetBucketUsageRequestParams} params
738
811
  */
739
- const storageGetBucketUsage = async ({ bucketId, range, parseOutput = true, sdk = undefined}) => {
740
- let client = !sdk ? await sdkForProject() : sdk;
812
+ const storageGetBucketUsage = async ({bucketId,range,parseOutput = true, overrideForCli = false, sdk = undefined, console}) => {
813
+ let client = !sdk ? await sdkForProject() :
814
+ sdk;
741
815
  let apiPath = '/storage/{bucketId}/usage'.replace('{bucketId}', bucketId);
742
816
  let payload = {};
743
817
  if (typeof range !== 'undefined') {
@@ -751,11 +825,16 @@ const storageGetBucketUsage = async ({ bucketId, range, parseOutput = true, sdk
751
825
  }, payload);
752
826
 
753
827
  if (parseOutput) {
754
- parse(response)
755
- success()
828
+ if(console) {
829
+ showConsoleLink('storage', 'getBucketUsage', bucketId);
830
+ } else {
831
+ parse(response)
832
+ success()
833
+ }
756
834
  }
757
-
835
+
758
836
  return response;
837
+
759
838
  }
760
839
 
761
840
  storage
@@ -763,6 +842,7 @@ storage
763
842
  .description(`Get a list of all the storage buckets. You can use the query params to filter your results.`)
764
843
  .option(`--queries [queries...]`, `Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: enabled, name, fileSecurity, maximumFileSize, encryption, antivirus`)
765
844
  .option(`--search <search>`, `Search term to filter your list results. Max length: 256 chars.`)
845
+ .option(`--console`, `Get the resource console url`)
766
846
  .action(actionRunner(storageListBuckets))
767
847
 
768
848
  storage
@@ -784,6 +864,7 @@ storage
784
864
  .command(`getBucket`)
785
865
  .description(`Get a storage bucket by its unique ID. This endpoint response returns a JSON object with the storage bucket metadata.`)
786
866
  .requiredOption(`--bucketId <bucketId>`, `Bucket unique ID.`)
867
+ .option(`--console`, `Get the resource console url`)
787
868
  .action(actionRunner(storageGetBucket))
788
869
 
789
870
  storage
@@ -813,6 +894,7 @@ storage
813
894
  .requiredOption(`--bucketId <bucketId>`, `Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket).`)
814
895
  .option(`--queries [queries...]`, `Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name, signature, mimeType, sizeOriginal, chunksTotal, chunksUploaded`)
815
896
  .option(`--search <search>`, `Search term to filter your list results. Max length: 256 chars.`)
897
+ .option(`--console`, `Get the resource console url`)
816
898
  .action(actionRunner(storageListFiles))
817
899
 
818
900
  storage
@@ -820,7 +902,7 @@ storage
820
902
  .description(`Create a new file. Before using this route, you should create a new bucket resource using either a [server integration](https://appwrite.io/docs/server/storage#storageCreateBucket) API or directly from your Appwrite console. Larger files should be uploaded using multiple requests with the [content-range](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Range) header to send a partial request with a maximum supported chunk of '5MB'. The 'content-range' header values should always be in bytes. When the first request is sent, the server will return the **File** object, and the subsequent part request must include the file's **id** in 'x-appwrite-id' header to allow the server to know that the partial upload is for the existing file and not for a new one. If you're creating a new file using one of the Appwrite SDKs, all the chunking logic will be managed by the SDK internally. `)
821
903
  .requiredOption(`--bucketId <bucketId>`, `Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket).`)
822
904
  .requiredOption(`--fileId <fileId>`, `File ID. Choose a custom ID or generate a random ID with 'ID.unique()'. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.`)
823
- .requiredOption(`--file <file>`, `Binary file. Appwrite SDKs provide helpers to handle file input. [Learn about file input](https://appwrite.io/docs/storage#file-input).`)
905
+ .requiredOption(`--file <file>`, `Binary file. Appwrite SDKs provide helpers to handle file input. [Learn about file input](https://appwrite.io/docs/products/storage/upload-download#input-file).`)
824
906
  .option(`--permissions [permissions...]`, `An array of permission strings. By default, only the current user is granted all permissions. [Learn more about permissions](https://appwrite.io/docs/permissions).`)
825
907
  .action(actionRunner(storageCreateFile))
826
908
 
@@ -829,6 +911,7 @@ storage
829
911
  .description(`Get a file by its unique ID. This endpoint response returns a JSON object with the file metadata.`)
830
912
  .requiredOption(`--bucketId <bucketId>`, `Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](https://appwrite.io/docs/server/storage#createBucket).`)
831
913
  .requiredOption(`--fileId <fileId>`, `File ID.`)
914
+ .option(`--console`, `Get the resource console url`)
832
915
  .action(actionRunner(storageGetFile))
833
916
 
834
917
  storage
@@ -893,6 +976,7 @@ storage
893
976
  .description(``)
894
977
  .requiredOption(`--bucketId <bucketId>`, `Bucket ID.`)
895
978
  .option(`--range <range>`, `Date range.`)
979
+ .option(`--console`, `Get the resource console url`)
896
980
  .action(actionRunner(storageGetBucketUsage))
897
981
 
898
982
  module.exports = {
@@ -912,4 +996,4 @@ module.exports = {
912
996
  storageGetFileView,
913
997
  storageGetUsage,
914
998
  storageGetBucketUsage
915
- };
999
+ };