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 vcs = new Command("vcs").description(commandDescriptions['vcs']).configure
43
43
  * @typedef {Object} VcsListRepositoriesRequestParams
44
44
  * @property {string} installationId Installation Id
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 vcs = new Command("vcs").description(commandDescriptions['vcs']).configure
50
51
  /**
51
52
  * @param {VcsListRepositoriesRequestParams} params
52
53
  */
53
- const vcsListRepositories = async ({ installationId, search, parseOutput = true, sdk = undefined}) => {
54
- let client = !sdk ? await sdkForProject() : sdk;
54
+ const vcsListRepositories = async ({installationId,search,parseOutput = true, overrideForCli = false, sdk = undefined}) => {
55
+ let client = !sdk ? await sdkForProject() :
56
+ sdk;
55
57
  let apiPath = '/vcs/github/installations/{installationId}/providerRepositories'.replace('{installationId}', installationId);
56
58
  let payload = {};
57
59
  if (typeof search !== 'undefined') {
@@ -68,8 +70,9 @@ const vcsListRepositories = async ({ installationId, search, parseOutput = true,
68
70
  parse(response)
69
71
  success()
70
72
  }
71
-
73
+
72
74
  return response;
75
+
73
76
  }
74
77
 
75
78
  /**
@@ -77,6 +80,7 @@ const vcsListRepositories = async ({ installationId, search, parseOutput = true,
77
80
  * @property {string} installationId Installation Id
78
81
  * @property {string} name Repository name (slug)
79
82
  * @property {boolean} xprivate Mark repository public or private
83
+ * @property {boolean} overrideForCli
80
84
  * @property {boolean} parseOutput
81
85
  * @property {libClient | undefined} sdk
82
86
  */
@@ -84,8 +88,9 @@ const vcsListRepositories = async ({ installationId, search, parseOutput = true,
84
88
  /**
85
89
  * @param {VcsCreateRepositoryRequestParams} params
86
90
  */
87
- const vcsCreateRepository = async ({ installationId, name, xprivate, parseOutput = true, sdk = undefined}) => {
88
- let client = !sdk ? await sdkForProject() : sdk;
91
+ const vcsCreateRepository = async ({installationId,name,xprivate,parseOutput = true, overrideForCli = false, sdk = undefined}) => {
92
+ let client = !sdk ? await sdkForProject() :
93
+ sdk;
89
94
  let apiPath = '/vcs/github/installations/{installationId}/providerRepositories'.replace('{installationId}', installationId);
90
95
  let payload = {};
91
96
  if (typeof name !== 'undefined') {
@@ -105,14 +110,16 @@ const vcsCreateRepository = async ({ installationId, name, xprivate, parseOutput
105
110
  parse(response)
106
111
  success()
107
112
  }
108
-
113
+
109
114
  return response;
115
+
110
116
  }
111
117
 
112
118
  /**
113
119
  * @typedef {Object} VcsGetRepositoryRequestParams
114
120
  * @property {string} installationId Installation Id
115
121
  * @property {string} providerRepositoryId Repository Id
122
+ * @property {boolean} overrideForCli
116
123
  * @property {boolean} parseOutput
117
124
  * @property {libClient | undefined} sdk
118
125
  */
@@ -120,8 +127,9 @@ const vcsCreateRepository = async ({ installationId, name, xprivate, parseOutput
120
127
  /**
121
128
  * @param {VcsGetRepositoryRequestParams} params
122
129
  */
123
- const vcsGetRepository = async ({ installationId, providerRepositoryId, parseOutput = true, sdk = undefined}) => {
124
- let client = !sdk ? await sdkForProject() : sdk;
130
+ const vcsGetRepository = async ({installationId,providerRepositoryId,parseOutput = true, overrideForCli = false, sdk = undefined}) => {
131
+ let client = !sdk ? await sdkForProject() :
132
+ sdk;
125
133
  let apiPath = '/vcs/github/installations/{installationId}/providerRepositories/{providerRepositoryId}'.replace('{installationId}', installationId).replace('{providerRepositoryId}', providerRepositoryId);
126
134
  let payload = {};
127
135
 
@@ -135,14 +143,16 @@ const vcsGetRepository = async ({ installationId, providerRepositoryId, parseOut
135
143
  parse(response)
136
144
  success()
137
145
  }
138
-
146
+
139
147
  return response;
148
+
140
149
  }
141
150
 
142
151
  /**
143
152
  * @typedef {Object} VcsListRepositoryBranchesRequestParams
144
153
  * @property {string} installationId Installation Id
145
154
  * @property {string} providerRepositoryId Repository Id
155
+ * @property {boolean} overrideForCli
146
156
  * @property {boolean} parseOutput
147
157
  * @property {libClient | undefined} sdk
148
158
  */
@@ -150,8 +160,9 @@ const vcsGetRepository = async ({ installationId, providerRepositoryId, parseOut
150
160
  /**
151
161
  * @param {VcsListRepositoryBranchesRequestParams} params
152
162
  */
153
- const vcsListRepositoryBranches = async ({ installationId, providerRepositoryId, parseOutput = true, sdk = undefined}) => {
154
- let client = !sdk ? await sdkForProject() : sdk;
163
+ const vcsListRepositoryBranches = async ({installationId,providerRepositoryId,parseOutput = true, overrideForCli = false, sdk = undefined}) => {
164
+ let client = !sdk ? await sdkForProject() :
165
+ sdk;
155
166
  let apiPath = '/vcs/github/installations/{installationId}/providerRepositories/{providerRepositoryId}/branches'.replace('{installationId}', installationId).replace('{providerRepositoryId}', providerRepositoryId);
156
167
  let payload = {};
157
168
 
@@ -165,8 +176,46 @@ const vcsListRepositoryBranches = async ({ installationId, providerRepositoryId,
165
176
  parse(response)
166
177
  success()
167
178
  }
168
-
179
+
180
+ return response;
181
+
182
+ }
183
+
184
+ /**
185
+ * @typedef {Object} VcsGetRepositoryContentsRequestParams
186
+ * @property {string} installationId Installation Id
187
+ * @property {string} providerRepositoryId Repository Id
188
+ * @property {string} providerRootDirectory Path to get contents of nested directory
189
+ * @property {boolean} overrideForCli
190
+ * @property {boolean} parseOutput
191
+ * @property {libClient | undefined} sdk
192
+ */
193
+
194
+ /**
195
+ * @param {VcsGetRepositoryContentsRequestParams} params
196
+ */
197
+ const vcsGetRepositoryContents = async ({installationId,providerRepositoryId,providerRootDirectory,parseOutput = true, overrideForCli = false, sdk = undefined}) => {
198
+ let client = !sdk ? await sdkForProject() :
199
+ sdk;
200
+ let apiPath = '/vcs/github/installations/{installationId}/providerRepositories/{providerRepositoryId}/contents'.replace('{installationId}', installationId).replace('{providerRepositoryId}', providerRepositoryId);
201
+ let payload = {};
202
+ if (typeof providerRootDirectory !== 'undefined') {
203
+ payload['providerRootDirectory'] = providerRootDirectory;
204
+ }
205
+
206
+ let response = undefined;
207
+
208
+ response = await client.call('get', apiPath, {
209
+ 'content-type': 'application/json',
210
+ }, payload);
211
+
212
+ if (parseOutput) {
213
+ parse(response)
214
+ success()
215
+ }
216
+
169
217
  return response;
218
+
170
219
  }
171
220
 
172
221
  /**
@@ -174,6 +223,7 @@ const vcsListRepositoryBranches = async ({ installationId, providerRepositoryId,
174
223
  * @property {string} installationId Installation Id
175
224
  * @property {string} providerRepositoryId Repository Id
176
225
  * @property {string} providerRootDirectory Path to Root Directory
226
+ * @property {boolean} overrideForCli
177
227
  * @property {boolean} parseOutput
178
228
  * @property {libClient | undefined} sdk
179
229
  */
@@ -181,8 +231,9 @@ const vcsListRepositoryBranches = async ({ installationId, providerRepositoryId,
181
231
  /**
182
232
  * @param {VcsCreateRepositoryDetectionRequestParams} params
183
233
  */
184
- const vcsCreateRepositoryDetection = async ({ installationId, providerRepositoryId, providerRootDirectory, parseOutput = true, sdk = undefined}) => {
185
- let client = !sdk ? await sdkForProject() : sdk;
234
+ const vcsCreateRepositoryDetection = async ({installationId,providerRepositoryId,providerRootDirectory,parseOutput = true, overrideForCli = false, sdk = undefined}) => {
235
+ let client = !sdk ? await sdkForProject() :
236
+ sdk;
186
237
  let apiPath = '/vcs/github/installations/{installationId}/providerRepositories/{providerRepositoryId}/detection'.replace('{installationId}', installationId).replace('{providerRepositoryId}', providerRepositoryId);
187
238
  let payload = {};
188
239
  if (typeof providerRootDirectory !== 'undefined') {
@@ -199,8 +250,9 @@ const vcsCreateRepositoryDetection = async ({ installationId, providerRepository
199
250
  parse(response)
200
251
  success()
201
252
  }
202
-
253
+
203
254
  return response;
255
+
204
256
  }
205
257
 
206
258
  /**
@@ -208,6 +260,7 @@ const vcsCreateRepositoryDetection = async ({ installationId, providerRepository
208
260
  * @property {string} installationId Installation Id
209
261
  * @property {string} repositoryId VCS Repository Id
210
262
  * @property {string} providerPullRequestId GitHub Pull Request Id
263
+ * @property {boolean} overrideForCli
211
264
  * @property {boolean} parseOutput
212
265
  * @property {libClient | undefined} sdk
213
266
  */
@@ -215,8 +268,9 @@ const vcsCreateRepositoryDetection = async ({ installationId, providerRepository
215
268
  /**
216
269
  * @param {VcsUpdateExternalDeploymentsRequestParams} params
217
270
  */
218
- const vcsUpdateExternalDeployments = async ({ installationId, repositoryId, providerPullRequestId, parseOutput = true, sdk = undefined}) => {
219
- let client = !sdk ? await sdkForProject() : sdk;
271
+ const vcsUpdateExternalDeployments = async ({installationId,repositoryId,providerPullRequestId,parseOutput = true, overrideForCli = false, sdk = undefined}) => {
272
+ let client = !sdk ? await sdkForProject() :
273
+ sdk;
220
274
  let apiPath = '/vcs/github/installations/{installationId}/repositories/{repositoryId}'.replace('{installationId}', installationId).replace('{repositoryId}', repositoryId);
221
275
  let payload = {};
222
276
  if (typeof providerPullRequestId !== 'undefined') {
@@ -233,14 +287,16 @@ const vcsUpdateExternalDeployments = async ({ installationId, repositoryId, prov
233
287
  parse(response)
234
288
  success()
235
289
  }
236
-
290
+
237
291
  return response;
292
+
238
293
  }
239
294
 
240
295
  /**
241
296
  * @typedef {Object} VcsListInstallationsRequestParams
242
297
  * @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: provider, organization
243
298
  * @property {string} search Search term to filter your list results. Max length: 256 chars.
299
+ * @property {boolean} overrideForCli
244
300
  * @property {boolean} parseOutput
245
301
  * @property {libClient | undefined} sdk
246
302
  */
@@ -248,8 +304,9 @@ const vcsUpdateExternalDeployments = async ({ installationId, repositoryId, prov
248
304
  /**
249
305
  * @param {VcsListInstallationsRequestParams} params
250
306
  */
251
- const vcsListInstallations = async ({ queries, search, parseOutput = true, sdk = undefined}) => {
252
- let client = !sdk ? await sdkForProject() : sdk;
307
+ const vcsListInstallations = async ({queries,search,parseOutput = true, overrideForCli = false, sdk = undefined}) => {
308
+ let client = !sdk ? await sdkForProject() :
309
+ sdk;
253
310
  let apiPath = '/vcs/installations';
254
311
  let payload = {};
255
312
  if (typeof queries !== 'undefined') {
@@ -269,13 +326,15 @@ const vcsListInstallations = async ({ queries, search, parseOutput = true, sdk =
269
326
  parse(response)
270
327
  success()
271
328
  }
272
-
329
+
273
330
  return response;
331
+
274
332
  }
275
333
 
276
334
  /**
277
335
  * @typedef {Object} VcsGetInstallationRequestParams
278
336
  * @property {string} installationId Installation Id
337
+ * @property {boolean} overrideForCli
279
338
  * @property {boolean} parseOutput
280
339
  * @property {libClient | undefined} sdk
281
340
  */
@@ -283,8 +342,9 @@ const vcsListInstallations = async ({ queries, search, parseOutput = true, sdk =
283
342
  /**
284
343
  * @param {VcsGetInstallationRequestParams} params
285
344
  */
286
- const vcsGetInstallation = async ({ installationId, parseOutput = true, sdk = undefined}) => {
287
- let client = !sdk ? await sdkForProject() : sdk;
345
+ const vcsGetInstallation = async ({installationId,parseOutput = true, overrideForCli = false, sdk = undefined}) => {
346
+ let client = !sdk ? await sdkForProject() :
347
+ sdk;
288
348
  let apiPath = '/vcs/installations/{installationId}'.replace('{installationId}', installationId);
289
349
  let payload = {};
290
350
 
@@ -298,13 +358,15 @@ const vcsGetInstallation = async ({ installationId, parseOutput = true, sdk = un
298
358
  parse(response)
299
359
  success()
300
360
  }
301
-
361
+
302
362
  return response;
363
+
303
364
  }
304
365
 
305
366
  /**
306
367
  * @typedef {Object} VcsDeleteInstallationRequestParams
307
368
  * @property {string} installationId Installation Id
369
+ * @property {boolean} overrideForCli
308
370
  * @property {boolean} parseOutput
309
371
  * @property {libClient | undefined} sdk
310
372
  */
@@ -312,8 +374,9 @@ const vcsGetInstallation = async ({ installationId, parseOutput = true, sdk = un
312
374
  /**
313
375
  * @param {VcsDeleteInstallationRequestParams} params
314
376
  */
315
- const vcsDeleteInstallation = async ({ installationId, parseOutput = true, sdk = undefined}) => {
316
- let client = !sdk ? await sdkForProject() : sdk;
377
+ const vcsDeleteInstallation = async ({installationId,parseOutput = true, overrideForCli = false, sdk = undefined}) => {
378
+ let client = !sdk ? await sdkForProject() :
379
+ sdk;
317
380
  let apiPath = '/vcs/installations/{installationId}'.replace('{installationId}', installationId);
318
381
  let payload = {};
319
382
 
@@ -327,8 +390,9 @@ const vcsDeleteInstallation = async ({ installationId, parseOutput = true, sdk =
327
390
  parse(response)
328
391
  success()
329
392
  }
330
-
393
+
331
394
  return response;
395
+
332
396
  }
333
397
 
334
398
  vcs
@@ -360,6 +424,14 @@ vcs
360
424
  .requiredOption(`--providerRepositoryId <providerRepositoryId>`, `Repository Id`)
361
425
  .action(actionRunner(vcsListRepositoryBranches))
362
426
 
427
+ vcs
428
+ .command(`getRepositoryContents`)
429
+ .description(``)
430
+ .requiredOption(`--installationId <installationId>`, `Installation Id`)
431
+ .requiredOption(`--providerRepositoryId <providerRepositoryId>`, `Repository Id`)
432
+ .option(`--providerRootDirectory <providerRootDirectory>`, `Path to get contents of nested directory`)
433
+ .action(actionRunner(vcsGetRepositoryContents))
434
+
363
435
  vcs
364
436
  .command(`createRepositoryDetection`)
365
437
  .description(``)
@@ -401,9 +473,10 @@ module.exports = {
401
473
  vcsCreateRepository,
402
474
  vcsGetRepository,
403
475
  vcsListRepositoryBranches,
476
+ vcsGetRepositoryContents,
404
477
  vcsCreateRepositoryDetection,
405
478
  vcsUpdateExternalDeployments,
406
479
  vcsListInstallations,
407
480
  vcsGetInstallation,
408
481
  vcsDeleteInstallation
409
- };
482
+ };
package/lib/config.js CHANGED
@@ -204,6 +204,45 @@ class Local extends Config {
204
204
  this.set("buckets", buckets);
205
205
  }
206
206
 
207
+ getMessagingTopics() {
208
+ if (!this.has("topics")) {
209
+ return [];
210
+ }
211
+ return this.get("topics");
212
+ }
213
+
214
+ getMessagingTopic($id) {
215
+ if (!this.has("topics")) {
216
+ return {};
217
+ }
218
+
219
+ let topic = this.get("topics");
220
+ for (let i = 0; i < topic.length; i++) {
221
+ if (topic[i]['$id'] == $id) {
222
+ return topic[i];
223
+ }
224
+ }
225
+
226
+ return {};
227
+ }
228
+
229
+ addMessagingTopic(props) {
230
+ if (!this.has("topics")) {
231
+ this.set("topics", []);
232
+ }
233
+
234
+ let topics = this.get("topics");
235
+ for (let i = 0; i < topics.length; i++) {
236
+ if (topics[i]['$id'] === props['$id']) {
237
+ topics[i] = props;
238
+ this.set("topics", topics);
239
+ return;
240
+ }
241
+ }
242
+ topics.push(props);
243
+ this.set("topics", topics);
244
+ }
245
+
207
246
  getDatabases() {
208
247
  if (!this.has("databases")) {
209
248
  return [];
@@ -283,26 +322,75 @@ class Local extends Config {
283
322
  }
284
323
 
285
324
  getProject() {
286
- if (!this.has("projectId") || !this.has("projectName")) {
325
+ if (!this.has("projectId")) {
287
326
  return {};
288
327
  }
289
328
 
290
329
  return {
291
330
  projectId: this.get("projectId"),
292
331
  projectName: this.get("projectName"),
332
+ projectSettings: this.get('projectSettings')
293
333
  };
294
334
  }
295
335
 
296
- setProject(projectId, projectName) {
336
+ setProject(projectId, projectName = '', projectSettings = undefined) {
297
337
  this.set("projectId", projectId);
298
- this.set("projectName", projectName);
338
+
339
+ if (projectName !== '') {
340
+ this.set("projectName", projectName);
341
+ }
342
+
343
+ if (projectSettings === undefined) {
344
+ return;
345
+ }
346
+
347
+ const settings = {
348
+ services: {
349
+ account: projectSettings.serviceStatusForAccount,
350
+ avatars: projectSettings.serviceStatusForAvatars,
351
+ databases: projectSettings.serviceStatusForDatabases,
352
+ locale: projectSettings.serviceStatusForLocale,
353
+ health: projectSettings.serviceStatusForHealth,
354
+ storage: projectSettings.serviceStatusForStorage,
355
+ teams: projectSettings.serviceStatusForTeams,
356
+ users: projectSettings.serviceStatusForUsers,
357
+ functions: projectSettings.serviceStatusForFunctions,
358
+ graphql: projectSettings.serviceStatusForGraphql,
359
+ messaging: projectSettings.serviceStatusForMessaging,
360
+
361
+ },
362
+ auth: {
363
+ methods: {
364
+ jwt: projectSettings.authJWT,
365
+ phone: projectSettings.authPhone,
366
+ invites: projectSettings.authInvites,
367
+ anonymous: projectSettings.authAnonymous,
368
+ "email-otp": projectSettings.authEmailOtp,
369
+ "magic-url": projectSettings.authUsersAuthMagicURL,
370
+ "email-password": projectSettings.authEmailPassword
371
+ },
372
+ security: {
373
+ duration: projectSettings.authDuration,
374
+ limit: projectSettings.authLimit,
375
+ sessionsLimit: projectSettings.authSessionsLimit,
376
+ passwordHistory: projectSettings.authPasswordHistory,
377
+ passwordDictionary: projectSettings.authPasswordDictionary,
378
+ personalDataCheck: projectSettings.authPersonalDataCheck
379
+ }
380
+ }
381
+ };
382
+
383
+ this.set('projectSettings', settings)
299
384
  }
385
+
300
386
  }
301
387
 
302
388
  class Global extends Config {
303
389
  static CONFIG_FILE_PATH = ".appwrite/prefs.json";
304
390
 
391
+ static PREFERENCE_CURRENT = "current";
305
392
  static PREFERENCE_ENDPOINT = "endpoint";
393
+ static PREFERENCE_EMAIL = "email";
306
394
  static PREFERENCE_SELF_SIGNED = "selfSigned";
307
395
  static PREFERENCE_COOKIE = "cookie";
308
396
  static PREFERENCE_PROJECT = "project";
@@ -310,6 +398,8 @@ class Global extends Config {
310
398
  static PREFERENCE_LOCALE = "locale";
311
399
  static PREFERENCE_MODE = "mode";
312
400
 
401
+ static IGNORE_ATTRIBUTES = [Global.PREFERENCE_CURRENT, Global.PREFERENCE_SELF_SIGNED, Global.PREFERENCE_ENDPOINT, Global.PREFERENCE_COOKIE, Global.PREFERENCE_PROJECT, Global.PREFERENCE_KEY, Global.PREFERENCE_LOCALE, Global.PREFERENCE_MODE];
402
+
313
403
  static MODE_ADMIN = "admin";
314
404
  static MODE_DEFAULT = "default";
315
405
 
@@ -320,59 +410,141 @@ class Global extends Config {
320
410
  super(`${homeDir}/${path}`);
321
411
  }
322
412
 
413
+ getCurrentSession() {
414
+ if (!this.has(Global.PREFERENCE_CURRENT)) {
415
+ return "";
416
+ }
417
+ return this.get(Global.PREFERENCE_CURRENT);
418
+ }
419
+
420
+ setCurrentSession(session) {
421
+ if (session !== undefined) {
422
+ this.set(Global.PREFERENCE_CURRENT, session);
423
+ }
424
+ }
425
+
426
+ getSessionIds() {
427
+ return Object.keys(this.data).filter((key) => !Global.IGNORE_ATTRIBUTES.includes(key));
428
+ }
429
+
430
+ getSessions() {
431
+ const sessions = Object.keys(this.data).filter((key) => !Global.IGNORE_ATTRIBUTES.includes(key))
432
+
433
+ return sessions.map((session) => {
434
+
435
+ return {
436
+ id: session,
437
+ endpoint: this.data[session][Global.PREFERENCE_ENDPOINT],
438
+ email: this.data[session][Global.PREFERENCE_EMAIL]
439
+ }
440
+ })
441
+ }
442
+
443
+ addSession(session, data) {
444
+ this.set(session, data);
445
+ }
446
+
447
+ removeSession(session) {
448
+ this.delete(session);
449
+ }
450
+
451
+ getEmail() {
452
+ if (!this.hasFrom(Global.PREFERENCE_EMAIL)) {
453
+ return "";
454
+ }
455
+
456
+ return this.getFrom(Global.PREFERENCE_EMAIL);
457
+ }
458
+
459
+ setEmail(email) {
460
+ this.setTo(Global.PREFERENCE_EMAIL, email);
461
+ }
462
+
323
463
  getEndpoint() {
324
- if (!this.has(Global.PREFERENCE_ENDPOINT)) {
464
+ if (!this.hasFrom(Global.PREFERENCE_ENDPOINT)) {
325
465
  return "";
326
466
  }
327
- return this.get(Global.PREFERENCE_ENDPOINT);
467
+
468
+ return this.getFrom(Global.PREFERENCE_ENDPOINT);
328
469
  }
329
470
 
330
471
  setEndpoint(endpoint) {
331
- this.set(Global.PREFERENCE_ENDPOINT, endpoint);
472
+ this.setTo(Global.PREFERENCE_ENDPOINT, endpoint);
332
473
  }
333
474
 
334
475
  getSelfSigned() {
335
- if (!this.has(Global.PREFERENCE_SELF_SIGNED)) {
476
+ if (!this.hasFrom(Global.PREFERENCE_SELF_SIGNED)) {
336
477
  return false;
337
478
  }
338
- return this.get(Global.PREFERENCE_SELF_SIGNED);
479
+ return this.getFrom(Global.PREFERENCE_SELF_SIGNED);
339
480
  }
340
481
 
341
482
  setSelfSigned(selfSigned) {
342
- this.set(Global.PREFERENCE_SELF_SIGNED, selfSigned);
483
+ this.setTo(Global.PREFERENCE_SELF_SIGNED, selfSigned);
343
484
  }
344
485
 
345
486
  getCookie() {
346
- if (!this.has(Global.PREFERENCE_COOKIE)) {
487
+ if (!this.hasFrom(Global.PREFERENCE_COOKIE)) {
347
488
  return "";
348
489
  }
349
- return this.get(Global.PREFERENCE_COOKIE);
490
+ return this.getFrom(Global.PREFERENCE_COOKIE);
350
491
  }
351
492
 
352
493
  setCookie(cookie) {
353
- this.set(Global.PREFERENCE_COOKIE, cookie);
494
+ this.setTo(Global.PREFERENCE_COOKIE, cookie);
354
495
  }
355
496
 
356
497
  getProject() {
357
- if (!this.has(Global.PREFERENCE_PROJECT)) {
498
+ if (!this.hasFrom(Global.PREFERENCE_PROJECT)) {
358
499
  return "";
359
500
  }
360
- return this.get(Global.PREFERENCE_PROJECT);
501
+ return this.getFrom(Global.PREFERENCE_PROJECT);
361
502
  }
362
503
 
363
504
  setProject(project) {
364
- this.set(Global.PREFERENCE_PROJECT, project);
505
+ this.setTo(Global.PREFERENCE_PROJECT, project);
365
506
  }
366
507
 
367
508
  getKey() {
368
- if (!this.has(Global.PREFERENCE_KEY)) {
509
+ if (!this.hasFrom(Global.PREFERENCE_KEY)) {
369
510
  return "";
370
511
  }
371
- return this.get(Global.PREFERENCE_KEY);
512
+ return this.getFrom(Global.PREFERENCE_KEY);
372
513
  }
373
514
 
374
515
  setKey(key) {
375
- this.set(Global.PREFERENCE_KEY, key);
516
+ this.setTo(Global.PREFERENCE_KEY, key);
517
+ }
518
+
519
+ hasFrom(key) {
520
+ const current = this.getCurrentSession();
521
+
522
+ if (current) {
523
+ const config = this.get(current);
524
+
525
+ return config[key] !== undefined;
526
+ }
527
+ }
528
+
529
+ getFrom(key) {
530
+ const current = this.getCurrentSession();
531
+
532
+ if (current) {
533
+ const config = this.get(current);
534
+
535
+ return config[key];
536
+ }
537
+ }
538
+
539
+ setTo(key, value) {
540
+ const current = this.getCurrentSession();
541
+
542
+ if (current) {
543
+ const config = this.get(current);
544
+
545
+ config[key] = value;
546
+ this.write();
547
+ }
376
548
  }
377
549
  }
378
550