@magentrix-corp/magentrix-cli 1.3.16 → 1.3.17

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 (68) hide show
  1. package/LICENSE +25 -25
  2. package/README.md +1166 -1166
  3. package/actions/autopublish.old.js +293 -293
  4. package/actions/config.js +182 -182
  5. package/actions/create.js +466 -466
  6. package/actions/help.js +164 -164
  7. package/actions/iris/buildStage.js +874 -874
  8. package/actions/iris/delete.js +256 -256
  9. package/actions/iris/dev.js +391 -391
  10. package/actions/iris/index.js +6 -6
  11. package/actions/iris/link.js +375 -375
  12. package/actions/iris/recover.js +268 -268
  13. package/actions/main.js +80 -80
  14. package/actions/publish.js +1420 -1420
  15. package/actions/pull.js +684 -684
  16. package/actions/setup.js +148 -148
  17. package/actions/status.js +17 -17
  18. package/actions/update.js +248 -248
  19. package/bin/magentrix.js +393 -393
  20. package/package.json +55 -55
  21. package/utils/assetPaths.js +158 -158
  22. package/utils/autopublishLock.js +77 -77
  23. package/utils/cacher.js +206 -206
  24. package/utils/cli/checkInstanceUrl.js +76 -74
  25. package/utils/cli/helpers/compare.js +282 -282
  26. package/utils/cli/helpers/ensureApiKey.js +63 -63
  27. package/utils/cli/helpers/ensureCredentials.js +68 -68
  28. package/utils/cli/helpers/ensureInstanceUrl.js +75 -75
  29. package/utils/cli/writeRecords.js +262 -262
  30. package/utils/compare.js +135 -135
  31. package/utils/compress.js +17 -17
  32. package/utils/config.js +527 -527
  33. package/utils/debug.js +144 -144
  34. package/utils/diagnostics/testPublishLogic.js +96 -96
  35. package/utils/diff.js +49 -49
  36. package/utils/downloadAssets.js +291 -291
  37. package/utils/filetag.js +115 -115
  38. package/utils/hash.js +14 -14
  39. package/utils/iris/backup.js +411 -411
  40. package/utils/iris/builder.js +541 -541
  41. package/utils/iris/config-reader.js +664 -664
  42. package/utils/iris/deleteHelper.js +150 -150
  43. package/utils/iris/errors.js +537 -537
  44. package/utils/iris/linker.js +601 -601
  45. package/utils/iris/lock.js +360 -360
  46. package/utils/iris/validation.js +360 -360
  47. package/utils/iris/validator.js +281 -281
  48. package/utils/iris/zipper.js +248 -248
  49. package/utils/logger.js +291 -291
  50. package/utils/magentrix/api/assets.js +220 -220
  51. package/utils/magentrix/api/auth.js +107 -107
  52. package/utils/magentrix/api/createEntity.js +61 -61
  53. package/utils/magentrix/api/deleteEntity.js +55 -55
  54. package/utils/magentrix/api/iris.js +251 -251
  55. package/utils/magentrix/api/meqlQuery.js +36 -36
  56. package/utils/magentrix/api/retrieveEntity.js +86 -86
  57. package/utils/magentrix/api/updateEntity.js +66 -66
  58. package/utils/magentrix/fetch.js +168 -168
  59. package/utils/merge.js +22 -22
  60. package/utils/permissionError.js +70 -70
  61. package/utils/preferences.js +40 -40
  62. package/utils/progress.js +469 -469
  63. package/utils/spinner.js +43 -43
  64. package/utils/template.js +52 -52
  65. package/utils/updateFileBase.js +121 -121
  66. package/utils/workspaces.js +108 -108
  67. package/vars/config.js +11 -11
  68. package/vars/global.js +50 -50
package/actions/setup.js CHANGED
@@ -1,148 +1,148 @@
1
- import { ensureApiKey } from "../utils/cli/helpers/ensureApiKey.js";
2
- import { ensureInstanceUrl } from "../utils/cli/helpers/ensureInstanceUrl.js";
3
- import Config from "../utils/config.js";
4
- import { getAccessToken, tryAuthenticate } from "../utils/magentrix/api/auth.js";
5
- import { ensureVSCodeFileAssociation } from "../utils/preferences.js";
6
- import { CWD, EXPORT_ROOT, HASHED_CWD } from "../vars/global.js";
7
- import { select } from "@inquirer/prompts";
8
- import { registerWorkspace } from "../utils/workspaces.js";
9
- import debug from '../utils/debug.js';
10
-
11
- const config = new Config();
12
-
13
- /**
14
- * Runs the global setup for the Magentrix CLI.
15
- *
16
- * Prompts the user for their API key and instance URL if needed,
17
- * validates credentials by attempting authentication,
18
- * and saves them to the global config if successful.
19
- *
20
- * @async
21
- * @param {Object} cliOptions - CLI options passed from command flags
22
- * @param {string} [cliOptions.apiKey] - API key from CLI
23
- * @param {string} [cliOptions.instanceUrl] - Instance URL from CLI
24
- * @returns {Promise<{apiKey: string, instanceUrl: string}>} The saved API key and instance URL.
25
- * @throws {Error} If authentication fails with provided credentials.
26
- */
27
- export const setup = async (cliOptions = {}) => {
28
- // Validation for CLI-provided values
29
- const urlRegex = /^https:\/\/[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
30
-
31
- if (cliOptions.apiKey) {
32
- if (cliOptions.apiKey.trim().length < 12) {
33
- throw new Error('--api-key must be at least 12 characters long');
34
- }
35
- if (/\s/.test(cliOptions.apiKey)) {
36
- throw new Error('--api-key cannot contain spaces');
37
- }
38
- }
39
-
40
- if (cliOptions.instanceUrl) {
41
- let trimmedUrl = cliOptions.instanceUrl.trim();
42
- // Automatically strip trailing slashes
43
- trimmedUrl = trimmedUrl.replace(/\/+$/, '');
44
-
45
- if (!urlRegex.test(trimmedUrl)) {
46
- throw new Error('--instance-url must be in the form: https://subdomain.domain.com (no http, no extra path)');
47
- }
48
- // Update the option with the cleaned URL
49
- cliOptions.instanceUrl = trimmedUrl;
50
- }
51
-
52
- // Retry loop for authentication
53
- let authSuccess = false;
54
- let apiKey, instanceUrl, tokenData;
55
-
56
- debug.log('SETUP', `Starting setup (pathHash: ${HASHED_CWD}, CWD: ${CWD})`);
57
- debug.log('SETUP', `CLI options provided: apiKey=${cliOptions.apiKey ? 'yes' : 'no'}, instanceUrl=${cliOptions.instanceUrl || 'no'}`);
58
-
59
- while (!authSuccess) {
60
- // Get API key (from CLI or prompt)
61
- apiKey = cliOptions.apiKey
62
- ? cliOptions.apiKey.trim()
63
- : await ensureApiKey(true);
64
-
65
- // Get instance URL (from CLI or prompt)
66
- instanceUrl = cliOptions.instanceUrl
67
- ? cliOptions.instanceUrl.trim()
68
- : await ensureInstanceUrl(true);
69
-
70
- debug.log('SETUP', `Attempting authentication with instance: ${instanceUrl}`);
71
-
72
- // Validate credentials by attempting to fetch an access token
73
- try {
74
- tokenData = await tryAuthenticate(apiKey, instanceUrl);
75
- debug.log('SETUP', 'Authentication successful');
76
- authSuccess = true;
77
- } catch (error) {
78
- debug.log('SETUP', `Authentication failed: ${error.message}`);
79
- console.log(error.message);
80
- console.log();
81
-
82
- // Ask user if they want to retry
83
- try {
84
- const retry = await select({
85
- message: 'What would you like to do?',
86
- choices: [
87
- { name: 'Try again', value: 'retry' },
88
- { name: 'Exit setup', value: 'exit' }
89
- ],
90
- default: 'retry'
91
- });
92
-
93
- if (retry !== 'retry') {
94
- console.log('❌ Setup cancelled.');
95
- process.exit(0);
96
- }
97
-
98
- // Reset CLI options so user can re-enter them
99
- cliOptions.apiKey = null;
100
- cliOptions.instanceUrl = null;
101
- console.log(); // Blank line for spacing
102
- } catch (error) {
103
- // Handle Ctrl+C or other cancellation
104
- if (error.name === 'ExitPromptError') {
105
- console.log('\n❌ Setup cancelled.');
106
- process.exit(0);
107
- }
108
- throw error;
109
- }
110
- }
111
- }
112
-
113
- console.log(); // Blank line for spacing
114
-
115
- // Save values since authentication succeeded
116
- debug.log('SETUP', `Saving credentials for pathHash: ${HASHED_CWD}`);
117
- config.save('instanceUrl', instanceUrl, { global: true, pathHash: HASHED_CWD });
118
- console.log('✅ Instance URL saved securely!');
119
-
120
- config.save('apiKey', apiKey, { global: true, pathHash: HASHED_CWD });
121
- console.log('✅ API key saved securely!');
122
-
123
- config.save(
124
- 'token',
125
- { value: tokenData.token, validUntil: tokenData.validUntil },
126
- { global: true, pathHash: HASHED_CWD }
127
- );
128
-
129
- // Register this workspace in the global registry
130
- registerWorkspace(CWD, instanceUrl);
131
-
132
- // Set up the editor
133
- await ensureVSCodeFileAssociation('./');
134
-
135
- console.log(); // Blank line for spacing
136
-
137
- console.log('🎉 Setup complete.');
138
-
139
- return {
140
- apiKey,
141
- instanceUrl,
142
- token: {
143
- value: tokenData.token,
144
- validUntil: tokenData.validUntil
145
- }
146
- }
147
-
148
- };
1
+ import { ensureApiKey } from "../utils/cli/helpers/ensureApiKey.js";
2
+ import { ensureInstanceUrl } from "../utils/cli/helpers/ensureInstanceUrl.js";
3
+ import Config from "../utils/config.js";
4
+ import { getAccessToken, tryAuthenticate } from "../utils/magentrix/api/auth.js";
5
+ import { ensureVSCodeFileAssociation } from "../utils/preferences.js";
6
+ import { CWD, EXPORT_ROOT, HASHED_CWD } from "../vars/global.js";
7
+ import { select } from "@inquirer/prompts";
8
+ import { registerWorkspace } from "../utils/workspaces.js";
9
+ import debug from '../utils/debug.js';
10
+
11
+ const config = new Config();
12
+
13
+ /**
14
+ * Runs the global setup for the Magentrix CLI.
15
+ *
16
+ * Prompts the user for their API key and instance URL if needed,
17
+ * validates credentials by attempting authentication,
18
+ * and saves them to the global config if successful.
19
+ *
20
+ * @async
21
+ * @param {Object} cliOptions - CLI options passed from command flags
22
+ * @param {string} [cliOptions.apiKey] - API key from CLI
23
+ * @param {string} [cliOptions.instanceUrl] - Instance URL from CLI
24
+ * @returns {Promise<{apiKey: string, instanceUrl: string}>} The saved API key and instance URL.
25
+ * @throws {Error} If authentication fails with provided credentials.
26
+ */
27
+ export const setup = async (cliOptions = {}) => {
28
+ // Validation for CLI-provided values
29
+ const urlRegex = /^https:\/\/[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
30
+
31
+ if (cliOptions.apiKey) {
32
+ if (cliOptions.apiKey.trim().length < 12) {
33
+ throw new Error('--api-key must be at least 12 characters long');
34
+ }
35
+ if (/\s/.test(cliOptions.apiKey)) {
36
+ throw new Error('--api-key cannot contain spaces');
37
+ }
38
+ }
39
+
40
+ if (cliOptions.instanceUrl) {
41
+ let trimmedUrl = cliOptions.instanceUrl.trim();
42
+ // Automatically strip trailing slashes
43
+ trimmedUrl = trimmedUrl.replace(/\/+$/, '');
44
+
45
+ if (!urlRegex.test(trimmedUrl)) {
46
+ throw new Error('--instance-url must be in the form: https://subdomain.domain.com (no http, no extra path)');
47
+ }
48
+ // Update the option with the cleaned URL
49
+ cliOptions.instanceUrl = trimmedUrl;
50
+ }
51
+
52
+ // Retry loop for authentication
53
+ let authSuccess = false;
54
+ let apiKey, instanceUrl, tokenData;
55
+
56
+ debug.log('SETUP', `Starting setup (pathHash: ${HASHED_CWD}, CWD: ${CWD})`);
57
+ debug.log('SETUP', `CLI options provided: apiKey=${cliOptions.apiKey ? 'yes' : 'no'}, instanceUrl=${cliOptions.instanceUrl || 'no'}`);
58
+
59
+ while (!authSuccess) {
60
+ // Get API key (from CLI or prompt)
61
+ apiKey = cliOptions.apiKey
62
+ ? cliOptions.apiKey.trim()
63
+ : await ensureApiKey(true);
64
+
65
+ // Get instance URL (from CLI or prompt)
66
+ instanceUrl = cliOptions.instanceUrl
67
+ ? cliOptions.instanceUrl.trim()
68
+ : await ensureInstanceUrl(true);
69
+
70
+ debug.log('SETUP', `Attempting authentication with instance: ${instanceUrl}`);
71
+
72
+ // Validate credentials by attempting to fetch an access token
73
+ try {
74
+ tokenData = await tryAuthenticate(apiKey, instanceUrl);
75
+ debug.log('SETUP', 'Authentication successful');
76
+ authSuccess = true;
77
+ } catch (error) {
78
+ debug.log('SETUP', `Authentication failed: ${error.message}`);
79
+ console.log(error.message);
80
+ console.log();
81
+
82
+ // Ask user if they want to retry
83
+ try {
84
+ const retry = await select({
85
+ message: 'What would you like to do?',
86
+ choices: [
87
+ { name: 'Try again', value: 'retry' },
88
+ { name: 'Exit setup', value: 'exit' }
89
+ ],
90
+ default: 'retry'
91
+ });
92
+
93
+ if (retry !== 'retry') {
94
+ console.log('❌ Setup cancelled.');
95
+ process.exit(0);
96
+ }
97
+
98
+ // Reset CLI options so user can re-enter them
99
+ cliOptions.apiKey = null;
100
+ cliOptions.instanceUrl = null;
101
+ console.log(); // Blank line for spacing
102
+ } catch (error) {
103
+ // Handle Ctrl+C or other cancellation
104
+ if (error.name === 'ExitPromptError') {
105
+ console.log('\n❌ Setup cancelled.');
106
+ process.exit(0);
107
+ }
108
+ throw error;
109
+ }
110
+ }
111
+ }
112
+
113
+ console.log(); // Blank line for spacing
114
+
115
+ // Save values since authentication succeeded
116
+ debug.log('SETUP', `Saving credentials for pathHash: ${HASHED_CWD}`);
117
+ config.save('instanceUrl', instanceUrl, { global: true, pathHash: HASHED_CWD });
118
+ console.log('✅ Instance URL saved securely!');
119
+
120
+ config.save('apiKey', apiKey, { global: true, pathHash: HASHED_CWD });
121
+ console.log('✅ API key saved securely!');
122
+
123
+ config.save(
124
+ 'token',
125
+ { value: tokenData.token, validUntil: tokenData.validUntil },
126
+ { global: true, pathHash: HASHED_CWD }
127
+ );
128
+
129
+ // Register this workspace in the global registry
130
+ registerWorkspace(CWD, instanceUrl);
131
+
132
+ // Set up the editor
133
+ await ensureVSCodeFileAssociation('./');
134
+
135
+ console.log(); // Blank line for spacing
136
+
137
+ console.log('🎉 Setup complete.');
138
+
139
+ return {
140
+ apiKey,
141
+ instanceUrl,
142
+ token: {
143
+ value: tokenData.token,
144
+ validUntil: tokenData.validUntil
145
+ }
146
+ }
147
+
148
+ };
package/actions/status.js CHANGED
@@ -1,17 +1,17 @@
1
- import { showCurrentConflicts } from "../utils/cli/helpers/compare.js";
2
- import { ensureValidCredentials } from "../utils/cli/helpers/ensureCredentials.js";
3
- import { withSpinner } from "../utils/spinner.js";
4
- import { EXPORT_ROOT } from "../vars/global.js";
5
-
6
- export const status = async () => {
7
- // Clear the terminal
8
- process.stdout.write('\x1Bc');
9
-
10
- const credentials = await withSpinner('Authenticating...', async () => {
11
- return await ensureValidCredentials();
12
- });
13
-
14
- console.log();
15
-
16
- await showCurrentConflicts(EXPORT_ROOT, credentials.instanceUrl, credentials.token.value, true)
17
- };
1
+ import { showCurrentConflicts } from "../utils/cli/helpers/compare.js";
2
+ import { ensureValidCredentials } from "../utils/cli/helpers/ensureCredentials.js";
3
+ import { withSpinner } from "../utils/spinner.js";
4
+ import { EXPORT_ROOT } from "../vars/global.js";
5
+
6
+ export const status = async () => {
7
+ // Clear the terminal
8
+ process.stdout.write('\x1Bc');
9
+
10
+ const credentials = await withSpinner('Authenticating...', async () => {
11
+ return await ensureValidCredentials();
12
+ });
13
+
14
+ console.log();
15
+
16
+ await showCurrentConflicts(EXPORT_ROOT, credentials.instanceUrl, credentials.token.value, true)
17
+ };