appwrite-cli 6.0.0-rc.6 → 6.0.0-rc.7

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.
@@ -35,7 +35,7 @@ function convertReadStreamToReadableStream(readStream) {
35
35
  });
36
36
  }
37
37
 
38
- const projects = new Command("projects").description(commandDescriptions['projects']).configureHelp({
38
+ const projects = new Command("projects").description(commandDescriptions['projects'] ?? '').configureHelp({
39
39
  helpWidth: process.stdout.columns || 80
40
40
  })
41
41
 
@@ -74,7 +74,6 @@ const projectsList = async ({queries,search,parseOutput = true, overrideForCli =
74
74
  showConsoleLink('projects', 'list');
75
75
  } else {
76
76
  parse(response)
77
- success()
78
77
  }
79
78
  }
80
79
 
@@ -158,7 +157,6 @@ const projectsCreate = async ({projectId,name,teamId,region,description,logo,url
158
157
 
159
158
  if (parseOutput) {
160
159
  parse(response)
161
- success()
162
160
  }
163
161
 
164
162
  return response;
@@ -193,7 +191,6 @@ const projectsGet = async ({projectId,parseOutput = true, overrideForCli = false
193
191
  showConsoleLink('projects', 'get', projectId);
194
192
  } else {
195
193
  parse(response)
196
- success()
197
194
  }
198
195
  }
199
196
 
@@ -266,7 +263,6 @@ const projectsUpdate = async ({projectId,name,description,logo,url,legalName,leg
266
263
 
267
264
  if (parseOutput) {
268
265
  parse(response)
269
- success()
270
266
  }
271
267
 
272
268
  return response;
@@ -298,7 +294,6 @@ const projectsDelete = async ({projectId,parseOutput = true, overrideForCli = fa
298
294
 
299
295
  if (parseOutput) {
300
296
  parse(response)
301
- success()
302
297
  }
303
298
 
304
299
  return response;
@@ -338,7 +333,6 @@ const projectsUpdateApiStatus = async ({projectId,api,status,parseOutput = true,
338
333
 
339
334
  if (parseOutput) {
340
335
  parse(response)
341
- success()
342
336
  }
343
337
 
344
338
  return response;
@@ -374,7 +368,6 @@ const projectsUpdateApiStatusAll = async ({projectId,status,parseOutput = true,
374
368
 
375
369
  if (parseOutput) {
376
370
  parse(response)
377
- success()
378
371
  }
379
372
 
380
373
  return response;
@@ -410,7 +403,6 @@ const projectsUpdateAuthDuration = async ({projectId,duration,parseOutput = true
410
403
 
411
404
  if (parseOutput) {
412
405
  parse(response)
413
- success()
414
406
  }
415
407
 
416
408
  return response;
@@ -446,7 +438,6 @@ const projectsUpdateAuthLimit = async ({projectId,limit,parseOutput = true, over
446
438
 
447
439
  if (parseOutput) {
448
440
  parse(response)
449
- success()
450
441
  }
451
442
 
452
443
  return response;
@@ -482,7 +473,6 @@ const projectsUpdateAuthSessionsLimit = async ({projectId,limit,parseOutput = tr
482
473
 
483
474
  if (parseOutput) {
484
475
  parse(response)
485
- success()
486
476
  }
487
477
 
488
478
  return response;
@@ -519,7 +509,6 @@ const projectsUpdateMockNumbers = async ({projectId,numbers,parseOutput = true,
519
509
 
520
510
  if (parseOutput) {
521
511
  parse(response)
522
- success()
523
512
  }
524
513
 
525
514
  return response;
@@ -555,7 +544,6 @@ const projectsUpdateAuthPasswordDictionary = async ({projectId,enabled,parseOutp
555
544
 
556
545
  if (parseOutput) {
557
546
  parse(response)
558
- success()
559
547
  }
560
548
 
561
549
  return response;
@@ -591,7 +579,6 @@ const projectsUpdateAuthPasswordHistory = async ({projectId,limit,parseOutput =
591
579
 
592
580
  if (parseOutput) {
593
581
  parse(response)
594
- success()
595
582
  }
596
583
 
597
584
  return response;
@@ -627,7 +614,6 @@ const projectsUpdatePersonalDataCheck = async ({projectId,enabled,parseOutput =
627
614
 
628
615
  if (parseOutput) {
629
616
  parse(response)
630
- success()
631
617
  }
632
618
 
633
619
  return response;
@@ -663,7 +649,6 @@ const projectsUpdateSessionAlerts = async ({projectId,alerts,parseOutput = true,
663
649
 
664
650
  if (parseOutput) {
665
651
  parse(response)
666
- success()
667
652
  }
668
653
 
669
654
  return response;
@@ -700,7 +685,6 @@ const projectsUpdateAuthStatus = async ({projectId,method,status,parseOutput = t
700
685
 
701
686
  if (parseOutput) {
702
687
  parse(response)
703
- success()
704
688
  }
705
689
 
706
690
  return response;
@@ -741,7 +725,6 @@ const projectsCreateJWT = async ({projectId,scopes,duration,parseOutput = true,
741
725
 
742
726
  if (parseOutput) {
743
727
  parse(response)
744
- success()
745
728
  }
746
729
 
747
730
  return response;
@@ -776,7 +759,6 @@ const projectsListKeys = async ({projectId,parseOutput = true, overrideForCli =
776
759
  showConsoleLink('projects', 'listKeys', projectId);
777
760
  } else {
778
761
  parse(response)
779
- success()
780
762
  }
781
763
  }
782
764
 
@@ -822,7 +804,6 @@ const projectsCreateKey = async ({projectId,name,scopes,expire,parseOutput = tru
822
804
 
823
805
  if (parseOutput) {
824
806
  parse(response)
825
- success()
826
807
  }
827
808
 
828
809
  return response;
@@ -858,7 +839,6 @@ const projectsGetKey = async ({projectId,keyId,parseOutput = true, overrideForCl
858
839
  showConsoleLink('projects', 'getKey', projectId, keyId);
859
840
  } else {
860
841
  parse(response)
861
- success()
862
842
  }
863
843
  }
864
844
 
@@ -905,7 +885,6 @@ const projectsUpdateKey = async ({projectId,keyId,name,scopes,expire,parseOutput
905
885
 
906
886
  if (parseOutput) {
907
887
  parse(response)
908
- success()
909
888
  }
910
889
 
911
890
  return response;
@@ -938,7 +917,6 @@ const projectsDeleteKey = async ({projectId,keyId,parseOutput = true, overrideFo
938
917
 
939
918
  if (parseOutput) {
940
919
  parse(response)
941
- success()
942
920
  }
943
921
 
944
922
  return response;
@@ -986,7 +964,6 @@ const projectsUpdateOAuth2 = async ({projectId,provider,appId,secret,enabled,par
986
964
 
987
965
  if (parseOutput) {
988
966
  parse(response)
989
- success()
990
967
  }
991
968
 
992
969
  return response;
@@ -1021,7 +998,6 @@ const projectsListPlatforms = async ({projectId,parseOutput = true, overrideForC
1021
998
  showConsoleLink('projects', 'listPlatforms', projectId);
1022
999
  } else {
1023
1000
  parse(response)
1024
- success()
1025
1001
  }
1026
1002
  }
1027
1003
 
@@ -1074,7 +1050,6 @@ const projectsCreatePlatform = async ({projectId,type,name,key,store,hostname,pa
1074
1050
 
1075
1051
  if (parseOutput) {
1076
1052
  parse(response)
1077
- success()
1078
1053
  }
1079
1054
 
1080
1055
  return response;
@@ -1110,7 +1085,6 @@ const projectsGetPlatform = async ({projectId,platformId,parseOutput = true, ove
1110
1085
  showConsoleLink('projects', 'getPlatform', projectId, platformId);
1111
1086
  } else {
1112
1087
  parse(response)
1113
- success()
1114
1088
  }
1115
1089
  }
1116
1090
 
@@ -1160,7 +1134,6 @@ const projectsUpdatePlatform = async ({projectId,platformId,name,key,store,hostn
1160
1134
 
1161
1135
  if (parseOutput) {
1162
1136
  parse(response)
1163
- success()
1164
1137
  }
1165
1138
 
1166
1139
  return response;
@@ -1193,7 +1166,6 @@ const projectsDeletePlatform = async ({projectId,platformId,parseOutput = true,
1193
1166
 
1194
1167
  if (parseOutput) {
1195
1168
  parse(response)
1196
- success()
1197
1169
  }
1198
1170
 
1199
1171
  return response;
@@ -1233,7 +1205,6 @@ const projectsUpdateServiceStatus = async ({projectId,service,status,parseOutput
1233
1205
 
1234
1206
  if (parseOutput) {
1235
1207
  parse(response)
1236
- success()
1237
1208
  }
1238
1209
 
1239
1210
  return response;
@@ -1269,7 +1240,6 @@ const projectsUpdateServiceStatusAll = async ({projectId,status,parseOutput = tr
1269
1240
 
1270
1241
  if (parseOutput) {
1271
1242
  parse(response)
1272
- success()
1273
1243
  }
1274
1244
 
1275
1245
  return response;
@@ -1337,7 +1307,6 @@ const projectsUpdateSmtp = async ({projectId,enabled,senderName,senderEmail,repl
1337
1307
 
1338
1308
  if (parseOutput) {
1339
1309
  parse(response)
1340
- success()
1341
1310
  }
1342
1311
 
1343
1312
  return response;
@@ -1406,7 +1375,6 @@ const projectsCreateSmtpTest = async ({projectId,emails,senderName,senderEmail,h
1406
1375
 
1407
1376
  if (parseOutput) {
1408
1377
  parse(response)
1409
- success()
1410
1378
  }
1411
1379
 
1412
1380
  return response;
@@ -1442,7 +1410,6 @@ const projectsUpdateTeam = async ({projectId,teamId,parseOutput = true, override
1442
1410
 
1443
1411
  if (parseOutput) {
1444
1412
  parse(response)
1445
- success()
1446
1413
  }
1447
1414
 
1448
1415
  return response;
@@ -1476,7 +1443,6 @@ const projectsGetEmailTemplate = async ({projectId,type,locale,parseOutput = tru
1476
1443
 
1477
1444
  if (parseOutput) {
1478
1445
  parse(response)
1479
- success()
1480
1446
  }
1481
1447
 
1482
1448
  return response;
@@ -1530,7 +1496,6 @@ const projectsUpdateEmailTemplate = async ({projectId,type,locale,subject,messag
1530
1496
 
1531
1497
  if (parseOutput) {
1532
1498
  parse(response)
1533
- success()
1534
1499
  }
1535
1500
 
1536
1501
  return response;
@@ -1564,7 +1529,6 @@ const projectsDeleteEmailTemplate = async ({projectId,type,locale,parseOutput =
1564
1529
 
1565
1530
  if (parseOutput) {
1566
1531
  parse(response)
1567
- success()
1568
1532
  }
1569
1533
 
1570
1534
  return response;
@@ -1598,7 +1562,6 @@ const projectsGetSmsTemplate = async ({projectId,type,locale,parseOutput = true,
1598
1562
 
1599
1563
  if (parseOutput) {
1600
1564
  parse(response)
1601
- success()
1602
1565
  }
1603
1566
 
1604
1567
  return response;
@@ -1636,7 +1599,6 @@ const projectsUpdateSmsTemplate = async ({projectId,type,locale,message,parseOut
1636
1599
 
1637
1600
  if (parseOutput) {
1638
1601
  parse(response)
1639
- success()
1640
1602
  }
1641
1603
 
1642
1604
  return response;
@@ -1670,7 +1632,6 @@ const projectsDeleteSmsTemplate = async ({projectId,type,locale,parseOutput = tr
1670
1632
 
1671
1633
  if (parseOutput) {
1672
1634
  parse(response)
1673
- success()
1674
1635
  }
1675
1636
 
1676
1637
  return response;
@@ -1705,7 +1666,6 @@ const projectsListWebhooks = async ({projectId,parseOutput = true, overrideForCl
1705
1666
  showConsoleLink('projects', 'listWebhooks', projectId);
1706
1667
  } else {
1707
1668
  parse(response)
1708
- success()
1709
1669
  }
1710
1670
  }
1711
1671
 
@@ -1767,7 +1727,6 @@ const projectsCreateWebhook = async ({projectId,name,events,url,security,enabled
1767
1727
 
1768
1728
  if (parseOutput) {
1769
1729
  parse(response)
1770
- success()
1771
1730
  }
1772
1731
 
1773
1732
  return response;
@@ -1803,7 +1762,6 @@ const projectsGetWebhook = async ({projectId,webhookId,parseOutput = true, overr
1803
1762
  showConsoleLink('projects', 'getWebhook', projectId, webhookId);
1804
1763
  } else {
1805
1764
  parse(response)
1806
- success()
1807
1765
  }
1808
1766
  }
1809
1767
 
@@ -1866,7 +1824,6 @@ const projectsUpdateWebhook = async ({projectId,webhookId,name,events,url,securi
1866
1824
 
1867
1825
  if (parseOutput) {
1868
1826
  parse(response)
1869
- success()
1870
1827
  }
1871
1828
 
1872
1829
  return response;
@@ -1899,7 +1856,6 @@ const projectsDeleteWebhook = async ({projectId,webhookId,parseOutput = true, ov
1899
1856
 
1900
1857
  if (parseOutput) {
1901
1858
  parse(response)
1902
- success()
1903
1859
  }
1904
1860
 
1905
1861
  return response;
@@ -1932,7 +1888,6 @@ const projectsUpdateWebhookSignature = async ({projectId,webhookId,parseOutput =
1932
1888
 
1933
1889
  if (parseOutput) {
1934
1890
  parse(response)
1935
- success()
1936
1891
  }
1937
1892
 
1938
1893
  return response;
@@ -35,7 +35,7 @@ function convertReadStreamToReadableStream(readStream) {
35
35
  });
36
36
  }
37
37
 
38
- const proxy = new Command("proxy").description(commandDescriptions['proxy']).configureHelp({
38
+ const proxy = new Command("proxy").description(commandDescriptions['proxy'] ?? '').configureHelp({
39
39
  helpWidth: process.stdout.columns || 80
40
40
  })
41
41
 
@@ -71,7 +71,6 @@ const proxyListRules = async ({queries,search,parseOutput = true, overrideForCli
71
71
 
72
72
  if (parseOutput) {
73
73
  parse(response)
74
- success()
75
74
  }
76
75
 
77
76
  return response;
@@ -114,7 +113,6 @@ const proxyCreateRule = async ({domain,resourceType,resourceId,parseOutput = tru
114
113
 
115
114
  if (parseOutput) {
116
115
  parse(response)
117
- success()
118
116
  }
119
117
 
120
118
  return response;
@@ -146,7 +144,6 @@ const proxyGetRule = async ({ruleId,parseOutput = true, overrideForCli = false,
146
144
 
147
145
  if (parseOutput) {
148
146
  parse(response)
149
- success()
150
147
  }
151
148
 
152
149
  return response;
@@ -178,7 +175,6 @@ const proxyDeleteRule = async ({ruleId,parseOutput = true, overrideForCli = fals
178
175
 
179
176
  if (parseOutput) {
180
177
  parse(response)
181
- success()
182
178
  }
183
179
 
184
180
  return response;
@@ -210,7 +206,6 @@ const proxyUpdateRuleVerification = async ({ruleId,parseOutput = true, overrideF
210
206
 
211
207
  if (parseOutput) {
212
208
  parse(response)
213
- success()
214
209
  }
215
210
 
216
211
  return response;
@@ -6,7 +6,7 @@ const inquirer = require("inquirer");
6
6
  const { messagingListTopics } = require("./messaging");
7
7
  const { teamsList } = require("./teams");
8
8
  const { projectsGet } = require("./projects");
9
- const { functionsList, functionsDownloadDeployment } = require("./functions");
9
+ const { functionsList, functionsGetDeploymentDownload, functionsListDeployments } = require("./functions");
10
10
  const { databasesGet, databasesListCollections, databasesList } = require("./databases");
11
11
  const { storageListBuckets } = require("./storage");
12
12
  const { localConfig } = require("../config");
@@ -56,7 +56,7 @@ const pullSettings = async () => {
56
56
  }
57
57
  }
58
58
 
59
- const pullFunctions = async ({ code }) => {
59
+ const pullFunctions = async ({ code, withVariables }) => {
60
60
  log("Fetching functions ...");
61
61
  let total = 0;
62
62
 
@@ -83,47 +83,84 @@ const pullFunctions = async ({ code }) => {
83
83
  const localFunction = localConfig.getFunction(func.$id);
84
84
 
85
85
  func['path'] = localFunction['path'];
86
- if(!localFunction['path']) {
86
+ if (!localFunction['path']) {
87
87
  func['path'] = `functions/${func.$id}`;
88
88
  }
89
-
89
+ if (!withVariables) {
90
+ delete func['vars'];
91
+ }
90
92
  localConfig.addFunction(func);
91
93
 
92
94
  if (!fs.existsSync(func['path'])) {
93
95
  fs.mkdirSync(func['path'], { recursive: true });
94
96
  }
95
97
 
96
- if(code === false) {
98
+ if (code === false) {
97
99
  warn("Source code download skipped.");
98
- } else if(!func['deployment']) {
99
- warn("Source code download skipped because function doesn't have active deployment.");
100
- } else {
101
- if(allowCodePull === null) {
102
- const codeAnswer = await inquirer.prompt(questionsPullFunctionsCode);
103
- allowCodePull = codeAnswer.override;
100
+ continue;
101
+ }
102
+
103
+ if (allowCodePull === null) {
104
+ const codeAnswer = await inquirer.prompt(questionsPullFunctionsCode);
105
+ allowCodePull = codeAnswer.override;
106
+ }
107
+
108
+ if (!allowCodePull) {
109
+ continue;
110
+ }
111
+
112
+ let deploymentId = null;
113
+
114
+ try {
115
+ const fetchResponse = await functionsListDeployments({
116
+ functionId: func['$id'],
117
+ queries: [
118
+ JSON.stringify({ method: 'limit', values: [1] }),
119
+ JSON.stringify({ method: 'orderDesc', values: ['$id'] })
120
+ ],
121
+ parseOutput: false
122
+ });
123
+
124
+ if (fetchResponse['total'] > 0) {
125
+ deploymentId = fetchResponse['deployments'][0]['$id'];
104
126
  }
105
127
 
106
- if(allowCodePull) {
107
- log("Pulling active deployment's code ...");
108
-
109
- const compressedFileName = `${func['$id']}-${+new Date()}.tar.gz`
110
- await functionsDownloadDeployment({
111
- functionId: func['$id'],
112
- deploymentId: func['deployment'],
113
- destination: compressedFileName,
114
- overrideForCli: true,
115
- parseOutput: false
116
- });
117
-
118
- tar.extract({
119
- sync: true,
120
- cwd: func['path'],
121
- file: compressedFileName,
122
- strict: false,
123
- });
124
-
125
- fs.rmSync(compressedFileName);
128
+ } catch {
129
+ }
130
+
131
+ if (deploymentId === null) {
132
+ log("Source code download skipped because function doesn't have any available deployment");
133
+ continue;
134
+ }
135
+
136
+ log("Pulling latest deployment code ...");
137
+
138
+ const compressedFileName = `${func['$id']}-${+new Date()}.tar.gz`
139
+ await functionsGetDeploymentDownload({
140
+ functionId: func['$id'],
141
+ deploymentId,
142
+ destination: compressedFileName,
143
+ overrideForCli: true,
144
+ parseOutput: false
145
+ });
146
+
147
+ tar.extract({
148
+ sync: true,
149
+ cwd: func['path'],
150
+ file: compressedFileName,
151
+ strict: false,
152
+ });
153
+
154
+ fs.rmSync(compressedFileName);
155
+
156
+ if (withVariables) {
157
+ const envFileLocation = `${func['path']}/.env`
158
+ try {
159
+ fs.rmSync(envFileLocation);
160
+ } catch {
126
161
  }
162
+
163
+ fs.writeFileSync(envFileLocation, func['vars'].map(r => `${r.key}=${r.value}\n`).join(''))
127
164
  }
128
165
  }
129
166
 
@@ -170,7 +207,7 @@ const pullCollection = async () => {
170
207
  parseOutput: false
171
208
  }, 100, 'collections');
172
209
 
173
- for(const collection of collections) {
210
+ for (const collection of collections) {
174
211
  localConfig.addCollection({
175
212
  ...collection,
176
213
  '$createdAt': undefined,
@@ -198,7 +235,7 @@ const pullBucket = async () => {
198
235
 
199
236
  const { buckets } = await paginate(storageListBuckets, { parseOutput: false }, 100, 'buckets');
200
237
 
201
- for(const bucket of buckets) {
238
+ for (const bucket of buckets) {
202
239
  total++;
203
240
  log(`Pulling bucket ${chalk.bold(bucket['name'])} ...`);
204
241
  localConfig.addBucket(bucket);
@@ -223,7 +260,7 @@ const pullTeam = async () => {
223
260
 
224
261
  const { teams } = await paginate(teamsList, { parseOutput: false }, 100, 'teams');
225
262
 
226
- for(const team of teams) {
263
+ for (const team of teams) {
227
264
  total++;
228
265
  log(`Pulling team ${chalk.bold(team['name'])} ...`);
229
266
  localConfig.addTeam(team);
@@ -248,7 +285,7 @@ const pullMessagingTopic = async () => {
248
285
 
249
286
  const { topics } = await paginate(messagingListTopics, { parseOutput: false }, 100, 'topics');
250
287
 
251
- for(const topic of topics) {
288
+ for (const topic of topics) {
252
289
  total++;
253
290
  log(`Pulling topic ${chalk.bold(topic['name'])} ...`);
254
291
  localConfig.addMessagingTopic(topic);
@@ -279,6 +316,7 @@ pull
279
316
  .alias("functions")
280
317
  .description("Pulling your Appwrite cloud function")
281
318
  .option("--no-code", "Don't pull the function's code")
319
+ .option("--with-variables", `Pull function variables. ${chalk.red('recommend for testing purposes only')}`)
282
320
  .action(actionRunner(pullFunctions))
283
321
 
284
322
  pull