@intuned/runtime 1.1.5 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/.npmrc.d +1 -0
  2. package/CHANGELOG.md +5 -1
  3. package/WebTemplate.zip +0 -0
  4. package/bin/intuned +2 -0
  5. package/dist/commands/api/run.js +2 -1
  6. package/dist/commands/intuned-cli/commands/attempt.command.d.ts +1 -0
  7. package/dist/commands/intuned-cli/commands/attempt.command.js +8 -0
  8. package/dist/commands/intuned-cli/commands/attempt_api.command.d.ts +1 -0
  9. package/dist/commands/intuned-cli/commands/attempt_api.command.js +40 -0
  10. package/dist/commands/intuned-cli/commands/attempt_authsession.command.d.ts +1 -0
  11. package/dist/commands/intuned-cli/commands/attempt_authsession.command.js +8 -0
  12. package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.d.ts +1 -0
  13. package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.js +24 -0
  14. package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.d.ts +1 -0
  15. package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.js +36 -0
  16. package/dist/commands/intuned-cli/commands/build.command.d.ts +1 -0
  17. package/dist/commands/intuned-cli/commands/build.command.js +12 -0
  18. package/dist/commands/intuned-cli/commands/command.d.ts +2 -0
  19. package/dist/commands/intuned-cli/commands/command.js +9 -0
  20. package/dist/commands/intuned-cli/commands/deploy.command.d.ts +1 -0
  21. package/dist/commands/intuned-cli/commands/deploy.command.js +46 -0
  22. package/dist/commands/intuned-cli/commands/index.d.ts +15 -0
  23. package/dist/commands/intuned-cli/commands/index.js +170 -0
  24. package/dist/commands/intuned-cli/commands/init.command.d.ts +1 -0
  25. package/dist/commands/intuned-cli/commands/init.command.js +14 -0
  26. package/dist/commands/intuned-cli/commands/run.command.d.ts +1 -0
  27. package/dist/commands/intuned-cli/commands/run.command.js +8 -0
  28. package/dist/commands/intuned-cli/commands/run_api.command.d.ts +1 -0
  29. package/dist/commands/intuned-cli/commands/run_api.command.js +54 -0
  30. package/dist/commands/intuned-cli/commands/run_authsession.command.d.ts +20 -0
  31. package/dist/commands/intuned-cli/commands/run_authsession.command.js +13 -0
  32. package/dist/commands/intuned-cli/commands/run_authsession_create.command.d.ts +1 -0
  33. package/dist/commands/intuned-cli/commands/run_authsession_create.command.js +39 -0
  34. package/dist/commands/intuned-cli/commands/run_authsession_update.command.d.ts +1 -0
  35. package/dist/commands/intuned-cli/commands/run_authsession_update.command.js +39 -0
  36. package/dist/commands/intuned-cli/commands/run_authsession_validate.command.d.ts +1 -0
  37. package/dist/commands/intuned-cli/commands/run_authsession_validate.command.js +37 -0
  38. package/dist/commands/intuned-cli/commands/types.d.ts +21 -0
  39. package/dist/commands/intuned-cli/commands/types.js +21 -0
  40. package/dist/{common/cli/constants.d.ts → commands/intuned-cli/constants/index.d.ts} +5 -6
  41. package/dist/{common/cli/constants.js → commands/intuned-cli/constants/index.js} +27 -7
  42. package/dist/commands/intuned-cli/constants/readme.d.ts +1 -0
  43. package/dist/commands/intuned-cli/constants/readme.js +150 -0
  44. package/dist/commands/intuned-cli/controller/__test__/api.test.js +280 -0
  45. package/dist/commands/intuned-cli/controller/__test__/authSession.test.js +676 -0
  46. package/dist/commands/intuned-cli/controller/api.d.ts +44 -0
  47. package/dist/commands/intuned-cli/controller/api.js +181 -0
  48. package/dist/commands/intuned-cli/controller/authSession.d.ts +198 -0
  49. package/dist/commands/intuned-cli/controller/authSession.js +292 -0
  50. package/dist/commands/intuned-cli/controller/build.d.ts +1 -0
  51. package/dist/commands/intuned-cli/controller/build.js +36 -0
  52. package/dist/commands/intuned-cli/controller/deploy.d.ts +15 -0
  53. package/dist/commands/{deploy/utils.js → intuned-cli/controller/deploy.js} +114 -107
  54. package/dist/commands/intuned-cli/controller/index.d.ts +1 -0
  55. package/dist/commands/intuned-cli/controller/index.js +46 -0
  56. package/dist/commands/intuned-cli/controller/init.d.ts +5 -0
  57. package/dist/commands/intuned-cli/controller/init.js +136 -0
  58. package/dist/commands/intuned-cli/helpers/api.d.ts +3 -0
  59. package/dist/commands/intuned-cli/helpers/api.js +19 -0
  60. package/dist/commands/intuned-cli/helpers/auth.d.ts +41 -0
  61. package/dist/commands/intuned-cli/helpers/auth.js +129 -0
  62. package/dist/commands/intuned-cli/helpers/backend.d.ts +8 -0
  63. package/dist/commands/intuned-cli/helpers/backend.js +26 -0
  64. package/dist/commands/intuned-cli/helpers/context.d.ts +3 -0
  65. package/dist/commands/intuned-cli/helpers/context.js +33 -0
  66. package/dist/commands/intuned-cli/helpers/errors.d.ts +14 -0
  67. package/dist/commands/intuned-cli/helpers/errors.js +55 -0
  68. package/dist/commands/intuned-cli/helpers/index.d.ts +10 -0
  69. package/dist/commands/intuned-cli/helpers/index.js +115 -0
  70. package/dist/commands/intuned-cli/helpers/intunedJson.d.ts +1 -0
  71. package/dist/{common/cli/utils.js → commands/intuned-cli/helpers/intunedJson.js} +0 -16
  72. package/dist/commands/intuned-cli/helpers/proxy.d.ts +5 -0
  73. package/dist/commands/intuned-cli/helpers/proxy.js +23 -0
  74. package/dist/commands/intuned-cli/helpers/terminal.d.ts +5 -0
  75. package/dist/commands/intuned-cli/helpers/terminal.js +13 -0
  76. package/dist/commands/intuned-cli/helpers/timeout.d.ts +1 -0
  77. package/dist/commands/intuned-cli/helpers/timeout.js +23 -0
  78. package/dist/commands/intuned-cli/helpers/validation.d.ts +2 -0
  79. package/dist/commands/intuned-cli/helpers/validation.js +12 -0
  80. package/dist/commands/intuned-cli/index.d.ts +1 -0
  81. package/dist/commands/intuned-cli/index.js +16 -0
  82. package/dist/commands/intuned-cli/main.d.ts +1 -0
  83. package/dist/commands/intuned-cli/main.js +15 -0
  84. package/dist/{common/cli → commands/intuned-cli}/types.d.ts +2 -33
  85. package/dist/common/constants.d.ts +1 -0
  86. package/dist/common/constants.js +2 -1
  87. package/dist/common/runApi/index.d.ts +3 -0
  88. package/dist/common/runApi/index.js +13 -10
  89. package/dist/common/runApi/types.d.ts +140 -9
  90. package/dist/common/runApi/types.js +28 -27
  91. package/package.json +8 -8
  92. package/tsconfig.json +2 -1
  93. package/bin/check-auth-session +0 -3
  94. package/bin/cli-build +0 -3
  95. package/bin/create-auth-session +0 -3
  96. package/bin/deploy +0 -3
  97. package/bin/init +0 -3
  98. package/bin/run-api +0 -3
  99. package/dist/commands/cli-auth-sessions/check.d.ts +0 -2
  100. package/dist/commands/cli-auth-sessions/check.js +0 -40
  101. package/dist/commands/cli-auth-sessions/create.d.ts +0 -2
  102. package/dist/commands/cli-auth-sessions/create.js +0 -53
  103. package/dist/commands/cli-auth-sessions/utils.d.ts +0 -28
  104. package/dist/commands/cli-auth-sessions/utils.js +0 -284
  105. package/dist/commands/cli-build/cli-build.d.ts +0 -2
  106. package/dist/commands/cli-build/cli-build.js +0 -20
  107. package/dist/commands/deploy/deploy.d.ts +0 -2
  108. package/dist/commands/deploy/deploy.js +0 -47
  109. package/dist/commands/deploy/utils.d.ts +0 -16
  110. package/dist/commands/init/init.d.ts +0 -2
  111. package/dist/commands/init/init.js +0 -22
  112. package/dist/commands/init/utils.d.ts +0 -11
  113. package/dist/commands/init/utils.js +0 -175
  114. package/dist/commands/run-api-cli/run-api.d.ts +0 -2
  115. package/dist/commands/run-api-cli/run-api.js +0 -57
  116. package/dist/commands/run-api-cli/utils.d.ts +0 -9
  117. package/dist/commands/run-api-cli/utils.js +0 -144
  118. package/dist/common/cli/cliReadme.d.ts +0 -1
  119. package/dist/common/cli/cliReadme.js +0 -92
  120. package/dist/common/cli/utils.d.ts +0 -6
  121. /package/dist/{common/cli → commands/intuned-cli}/types.js +0 -0
@@ -0,0 +1 @@
1
+ export declare const runBuild: () => Promise<boolean>;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.runBuild = void 0;
7
+ var fs = _interopRequireWildcard(require("fs-extra"));
8
+ var path = _interopRequireWildcard(require("path"));
9
+ var _child_process = require("child_process");
10
+ var _util = require("util");
11
+ var _terminal = require("../helpers/terminal");
12
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
13
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
14
+ const execPromise = (0, _util.promisify)(_child_process.exec);
15
+ const runBuild = async () => {
16
+ const distPath = path.join(process.cwd(), "dist");
17
+ if (await fs.exists(distPath)) {
18
+ await fs.remove(distPath);
19
+ }
20
+ const buildCommand = "tsc";
21
+ try {
22
+ await execPromise(buildCommand);
23
+ (0, _terminal.terminal)(`^g^+✨ Build completed successfully!^:\n`);
24
+ return true;
25
+ } catch (error) {
26
+ (0, _terminal.terminal)(`^r^+An error occurred during the build process:^:\n`);
27
+ if ("stdout" in error) {
28
+ (0, _terminal.terminal)(`${error.stdout}\n`);
29
+ } else {
30
+ (0, _terminal.terminal)(`^${error.message}^:\n`);
31
+ }
32
+ (0, _terminal.terminal)(`^r^+Build failed^:\n`);
33
+ return false;
34
+ }
35
+ };
36
+ exports.runBuild = runBuild;
@@ -0,0 +1,15 @@
1
+ import { z } from "zod";
2
+ import type { AuthCredentials, FileSystemTree } from "../types";
3
+ export declare function convertProjectToCodeTree(projectPath: string): Promise<FileSystemTree>;
4
+ export declare function runDeployProject(projectName: string, auth: AuthCredentials): Promise<void>;
5
+ export declare const projectNameSchema: z.ZodEffects<z.ZodString, string, string>;
6
+ export declare const validateProjectName: (projectName: string) => {
7
+ isValid: true;
8
+ } | {
9
+ isValid: false;
10
+ errorMessage: string;
11
+ };
12
+ export declare const validateIntunedProject: () => Promise<{
13
+ isValid: boolean;
14
+ errorMessage?: string;
15
+ }>;
@@ -4,25 +4,25 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.convertProjectToCodeTree = convertProjectToCodeTree;
7
- exports.deployProject = deployProject;
8
- exports.validateProjectName = exports.validateIntunedProject = exports.runBuild = void 0;
7
+ exports.projectNameSchema = void 0;
8
+ exports.runDeployProject = runDeployProject;
9
+ exports.validateProjectName = exports.validateIntunedProject = void 0;
9
10
  var fs = _interopRequireWildcard(require("fs-extra"));
10
11
  var path = _interopRequireWildcard(require("path"));
11
- var _chalk = _interopRequireDefault(require("chalk"));
12
12
  var _minimatch = require("minimatch");
13
13
  var _zod = require("zod");
14
- var _child_process = require("child_process");
15
- var _util = require("util");
16
- var _projectExclusions = _interopRequireDefault(require("../common/projectExclusions"));
17
- var _constants = require("../../common/cli/constants");
18
- var _utils = require("../../common/cli/utils");
19
- var _utils2 = require("../init/utils");
14
+ var _projectExclusions = _interopRequireDefault(require("../../common/projectExclusions"));
15
+ var _constants = require("../constants");
16
+ var _helpers = require("../helpers");
20
17
  var _lodash = require("lodash");
21
18
  var _uuid = require("uuid");
19
+ var _terminal = require("../helpers/terminal");
20
+ var _promises = require("timers/promises");
21
+ var _ms = _interopRequireDefault(require("ms"));
22
+ var _build = require("./build");
22
23
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
23
24
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
24
25
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
25
- const execPromise = (0, _util.promisify)(_child_process.exec);
26
26
  function ignoreFilesByPattern(filePath, patterns, projectPath) {
27
27
  const relativePath = path.relative(projectPath, filePath);
28
28
  if (relativePath.startsWith("node_modules")) {
@@ -58,11 +58,11 @@ function listFilesNotIgnored(projectPath, ignorePatterns) {
58
58
  results.push(path.relative(projectPath, fullPath));
59
59
  }
60
60
  } catch (error) {
61
- console.log(_chalk.default.yellow(`Warning: Could not access ${fullPath}`));
61
+ (0, _terminal.terminal)(`^yWarning: Could not access ${fullPath}^:\n`);
62
62
  }
63
63
  }
64
64
  } catch (error) {
65
- console.log(_chalk.default.yellow(`Warning: Could not read directory ${dirPath}`));
65
+ (0, _terminal.terminal)(`^YWarning: Could not read directory ${dirPath}^:\n`);
66
66
  }
67
67
  }
68
68
  traverseDirectory(projectPath);
@@ -70,9 +70,9 @@ function listFilesNotIgnored(projectPath, ignorePatterns) {
70
70
  }
71
71
  async function convertProjectToCodeTree(projectPath) {
72
72
  const filesToDeploy = listFilesNotIgnored(projectPath, _projectExclusions.default);
73
- console.log(_chalk.default.cyan("\nFiles to be deployed:"));
74
- const filesToDeployText = "\n " + filesToDeploy.join("\n ");
75
- console.log(filesToDeployText);
73
+ const filesToDeployText = " " + filesToDeploy.join("\n ");
74
+ (0, _terminal.terminal)("^CFiles to be deployed:^:\n");
75
+ (0, _terminal.terminal)(filesToDeployText + "\n");
76
76
  function readDirectory(dirPath) {
77
77
  const tree = {};
78
78
  try {
@@ -93,7 +93,7 @@ async function convertProjectToCodeTree(projectPath) {
93
93
  }
94
94
  };
95
95
  } catch (error) {
96
- console.log(_chalk.default.yellow(`Warning: Could not read file ${entryPath}`));
96
+ (0, _terminal.terminal)(`^yWarning: Could not read file ${entryPath}^:\n`);
97
97
  }
98
98
  } else if (stats.isDirectory()) {
99
99
  const subTree = readDirectory(entryPath);
@@ -104,25 +104,24 @@ async function convertProjectToCodeTree(projectPath) {
104
104
  }
105
105
  }
106
106
  } catch (error) {
107
- console.log(_chalk.default.yellow(`Warning: Could not access ${entryPath}`));
107
+ (0, _terminal.terminal)(`^yWarning: Could not access ${entryPath}^:\n`);
108
108
  }
109
109
  }
110
110
  } catch (error) {
111
- console.log(_chalk.default.yellow(`Warning: Could not read directory ${dirPath}`));
111
+ (0, _terminal.terminal)(`^YWarning: Could not read directory ${dirPath}^:\n`);
112
112
  }
113
113
  return tree;
114
114
  }
115
- console.log(_chalk.default.cyan("\n📦 Building project..."));
116
115
  const tree = readDirectory(projectPath);
117
116
  await mapToIDEParams(tree);
118
117
  return tree;
119
118
  }
120
- async function deployProject(projectName, auth) {
119
+ async function runDeployProject(projectName, auth) {
121
120
  const {
122
121
  workspaceId,
123
122
  apiKey
124
123
  } = auth;
125
- const baseUrl = (0, _utils.getBaseUrl)();
124
+ const baseUrl = (0, _helpers.getBaseUrl)();
126
125
  const url = `${baseUrl}/api/v1/workspace/${workspaceId}/projects/create`;
127
126
  const headers = {
128
127
  "x-api-key": apiKey,
@@ -148,48 +147,84 @@ async function deployProject(projectName, auth) {
148
147
  });
149
148
  if (!response.ok) {
150
149
  if (response.status === 401) {
151
- throw new Error(`Invalid API key. Please check your API key and try again.`);
150
+ throw new _helpers.CLIError(`Invalid API key. Please check your API key and try again.`);
152
151
  }
153
- throw new Error(`Error deploying project`);
152
+ throw new _helpers.CLIError(`^r^+Invalid response from server\n^:^R${response.status} ${await response.text()}^:\n^r^+Project deployment failed^:\n`, {
153
+ autoColor: false
154
+ });
154
155
  }
156
+ (0, _terminal.terminal)("\n");
155
157
  const startTime = Date.now();
156
- console.log(_chalk.default.greenBright(`\n🚀 Deploying project...`));
157
- return new Promise((resolve, reject) => {
158
- const checkInterval = setInterval(async () => {
159
- try {
160
- const {
161
- status,
162
- message,
163
- projectId
164
- } = await checkIntunedProjectDeployStatus(workspaceId, projectName, apiKey);
165
- if (status === "completed" || status === "failed" || status === "not_found") {
166
- clearInterval(checkInterval);
167
- resolve(status === "completed" ? {
168
- deployDone: true,
169
- projectId
170
- } : {
171
- deployDone: false,
172
- projectId: "",
173
- deployErrorMessage: message
174
- });
175
- }
158
+ const timeElapsedText = () => ((Date.now() - startTime) / (0, _ms.default)("1 second")).toFixed(1);
159
+ function* getSpinnerGenerator() {
160
+ while (true) {
161
+ yield* "⠙⠹⠸⠼⠴⠦⠧⠇";
162
+ }
163
+ }
164
+ const spinnerGen = getSpinnerGenerator();
165
+ let updateSpinnerInterval = null;
166
+ if (_terminal.terminalStdout.isTTY) {
167
+ updateSpinnerInterval = setInterval(() => {
168
+ _terminal.terminal.previousLine(1);
169
+ _terminal.terminal.column(0);
170
+ _terminal.terminal.eraseLineAfter();
171
+ (0, _terminal.terminal)(`${spinnerGen.next().value} ^cDeploying ^:^K(${timeElapsedText()}s)^ \n`);
172
+ }, 50);
173
+ (0, _terminal.terminal)("\n");
174
+ } else {
175
+ (0, _terminal.terminal)(`^cDeploying ^:\n`);
176
+ }
177
+ try {
178
+ while (true) {
179
+ await (0, _promises.setTimeout)(_constants.PROJECT_DEPLOY_CHECK_PERIOD);
180
+ if (!_terminal.terminalStdout.isTTY) {
181
+ (0, _terminal.terminal)(`^cDeploying ^:^K(${timeElapsedText()}s)^ \n`);
182
+ }
183
+ const {
184
+ status,
185
+ message,
186
+ projectId,
187
+ ...rest
188
+ } = await checkIntunedProjectDeployStatus(workspaceId, projectName, apiKey);
189
+ if (status === "pending") {
176
190
  const elapsedTime = Date.now() - startTime;
177
191
  if (elapsedTime > _constants.PROJECT_DEPLOY_TIMEOUT) {
178
- clearInterval(checkInterval);
179
- reject(new Error(`Deployment timed out after ${Math.floor(_constants.PROJECT_DEPLOY_TIMEOUT / 1000 / 60)} minutes`));
192
+ throw new _helpers.CLIError(`Deployment timed out after ${Math.floor(_constants.PROJECT_DEPLOY_TIMEOUT / (0, _ms.default)("1 minute"))} minutes`);
180
193
  }
181
- } catch (error) {
182
- clearInterval(checkInterval);
183
- reject(error);
194
+ continue;
184
195
  }
185
- }, 5000);
186
- });
196
+ _terminal.terminal.previousLine(1);
197
+ _terminal.terminal.eraseLine();
198
+ if (updateSpinnerInterval) {
199
+ clearTimeout(updateSpinnerInterval);
200
+ }
201
+ if (status === "completed") {
202
+ const url = (0, _helpers.getBaseUrl)();
203
+ (0, _terminal.terminal)(`\n^g^+Project deployed successfully!^:\n`);
204
+ (0, _terminal.terminal)(`^+You can check your project on the platform:^s ^c^_${url}/projects/${projectId}/details^:\n`);
205
+ return;
206
+ }
207
+ let errorMessage = `^r^+An error occurred while deploying project:^:\n^R${message}^:\n`;
208
+ if (rest.reason) {
209
+ errorMessage += `^r^+Reason:^:\n^R${rest.reason}^:\n`;
210
+ }
211
+ errorMessage += `^r^+Project deployment failed^:\n`;
212
+ throw new _helpers.CLIError(errorMessage, {
213
+ autoColor: false
214
+ });
215
+ }
216
+ } catch (e) {
217
+ if (updateSpinnerInterval) {
218
+ clearTimeout(updateSpinnerInterval);
219
+ }
220
+ throw e;
221
+ }
187
222
  }
223
+ const projectNameSchema = exports.projectNameSchema = _zod.z.string().min(1, "Project Name is required").max(50, "Name must be 50 characters or less").regex(/^[a-z0-9]+(?:[-_][a-z0-9]+)*$/, "Name can only contain lowercase letters, numbers, hyphens, and underscores in between").refine(value => !_zod.z.string().uuid().safeParse(value).success, {
224
+ message: "Name cannot be a UUID"
225
+ });
188
226
  const validateProjectName = projectName => {
189
- const nameSchema = _zod.z.string().min(1, "Project Name is required").max(50, "Name must be 50 characters or less").regex(/^[a-z0-9]+(?:[-_][a-z0-9]+)*$/, "Name can only contain lowercase letters, numbers, hyphens, and underscores in between").refine(value => !_zod.z.string().uuid().safeParse(value).success, {
190
- message: "Name cannot be a UUID"
191
- });
192
- const validation = nameSchema.safeParse(projectName);
227
+ const validation = projectNameSchema.safeParse(projectName);
193
228
  if (!validation.success) {
194
229
  return {
195
230
  isValid: false,
@@ -207,7 +242,7 @@ const validateIntunedProject = async () => {
207
242
  name: "build",
208
243
  check: async () => {
209
244
  try {
210
- const buildResult = await runBuild();
245
+ const buildResult = await (0, _build.runBuild)();
211
246
  if (!buildResult) {
212
247
  return {
213
248
  isValid: false,
@@ -295,67 +330,39 @@ const validateIntunedProject = async () => {
295
330
  };
296
331
  exports.validateIntunedProject = validateIntunedProject;
297
332
  const checkIntunedProjectDeployStatus = async (workspaceId, projectName, apiKey) => {
298
- try {
299
- const baseUrl = (0, _utils.getBaseUrl)();
300
- const url = `${baseUrl}/api/v1/workspace/${workspaceId}/projects/create/${projectName}/result`;
301
- const headers = {
302
- "x-api-key": apiKey,
303
- "Content-Type": "application/json"
304
- };
305
- const response = await fetch(url, {
306
- headers,
307
- method: "GET"
308
- });
309
- if (response.status === 404) {
310
- return {
311
- status: "not_found",
312
- message: "Project not found"
313
- };
314
- }
315
- if (!response.ok) {
316
- throw new Error("Error querying deployment status");
317
- }
318
- const data = await response.json();
319
- if (data.status) {
320
- return {
321
- status: data.status,
322
- message: data.message,
323
- projectId: data.projectId
324
- };
325
- }
333
+ const baseUrl = (0, _helpers.getBaseUrl)();
334
+ const url = `${baseUrl}/api/v1/workspace/${workspaceId}/projects/create/${projectName}/result`;
335
+ const headers = {
336
+ "x-api-key": apiKey,
337
+ "Content-Type": "application/json"
338
+ };
339
+ const response = await fetch(url, {
340
+ headers,
341
+ method: "GET"
342
+ });
343
+ if (response.status === 404) {
326
344
  return {
327
- status: "failed",
328
- message: `Deployment failed, please try again: ${data.message}`
345
+ status: "not_found",
346
+ message: "Project not found"
329
347
  };
330
- } catch (e) {
331
- throw new Error(`Error during deployment`);
332
348
  }
333
- };
334
- const runBuild = async () => {
335
- const currentProjectDirectory = process.cwd();
336
- console.log(_chalk.default.yellow("Running build..."));
337
- const distPath = path.join(currentProjectDirectory, "dist");
338
- if (await fs.exists(distPath)) {
339
- await fs.remove(distPath);
349
+ if (!response.ok) {
350
+ throw new _helpers.CLIError(`Error querying deployment status ${response.status}: ${await response.text()}`);
340
351
  }
341
- const buildCommand = "tsc";
342
- try {
343
- await execPromise(buildCommand, {
344
- cwd: currentProjectDirectory
345
- });
346
- console.log(_chalk.default.green("🏗️ Build completed successfully"));
347
- return true;
348
- } catch (error) {
349
- console.error(_chalk.default.red(`Build failed: ${error.message}`));
350
- return false;
352
+ const data = await response.json();
353
+ if (data.status) {
354
+ return data;
351
355
  }
356
+ return {
357
+ status: "failed",
358
+ message: `Deployment failed, please try again: ${data.message}`
359
+ };
352
360
  };
353
- exports.runBuild = runBuild;
354
361
  async function mapToIDEParams(tree) {
355
362
  if (!tree) {
356
363
  return;
357
364
  }
358
- if (!tree["parameters"] || (0, _utils2._isFileNode)(tree["parameters"])) {
365
+ if (!tree["parameters"] || "file" in tree["parameters"]) {
359
366
  return;
360
367
  }
361
368
  const apiParametersMap = {};
@@ -365,7 +372,7 @@ async function mapToIDEParams(tree) {
365
372
  };
366
373
  for (const parameterKey of cliParameters) {
367
374
  const parameter = tree["parameters"].directory[parameterKey];
368
- if ((0, _utils2._isDirectoryNode)(parameter)) {
375
+ if ("directory" in parameter) {
369
376
  continue;
370
377
  }
371
378
  if ((0, _lodash.isEmpty)(parameter.file.contents)) {
@@ -0,0 +1 @@
1
+ export declare function loadParameters(parameters: string): Promise<object | null>;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.loadParameters = loadParameters;
7
+ var fs = _interopRequireWildcard(require("fs-extra"));
8
+ var _helpers = require("../helpers");
9
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
10
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
11
+ async function loadParameters(parameters) {
12
+ let inputData;
13
+ if (await fs.exists(parameters)) {
14
+ inputData = await loadParametersFromFile(parameters);
15
+ } else {
16
+ try {
17
+ inputData = JSON.parse(parameters);
18
+ } catch (err) {
19
+ throw new _helpers.CLIError("Parameters must be a valid JSON string or a path to a JSON file");
20
+ }
21
+ }
22
+ return inputData;
23
+ }
24
+ async function loadParametersFromFile(parametersFile) {
25
+ if (!parametersFile) {
26
+ return {};
27
+ }
28
+ try {
29
+ const filePath = parametersFile;
30
+ await fs.access(filePath);
31
+ let inputData = null;
32
+ if (parametersFile) {
33
+ inputData = await fs.readJSON(filePath);
34
+ } else {
35
+ inputData = {};
36
+ }
37
+ return inputData;
38
+ } catch (error) {
39
+ if (error.code === "ENOENT") {
40
+ throw new _helpers.CLIError(`Parameters file not found: ${parametersFile}`);
41
+ } else if (error instanceof SyntaxError) {
42
+ throw new _helpers.CLIError(`Invalid JSON in parameters file: ${error.message}`);
43
+ }
44
+ throw new _helpers.CLIError(`Error reading parameters file: ${error.message}`);
45
+ }
46
+ }
@@ -0,0 +1,5 @@
1
+ import { FileSystemTree, TemplateId } from "../types";
2
+ export declare function mountFiles(cwd: string, tree: FileSystemTree): Promise<void>;
3
+ export declare function checkEmptyDirectory(): Promise<boolean>;
4
+ export declare function selectTemplate(templateName: string): Promise<TemplateId>;
5
+ export declare function scaffoldProject(templateId: string, isTargetDirectoryEmpty: boolean): Promise<void>;
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.checkEmptyDirectory = checkEmptyDirectory;
7
+ exports.mountFiles = mountFiles;
8
+ exports.scaffoldProject = scaffoldProject;
9
+ exports.selectTemplate = selectTemplate;
10
+ var fs = _interopRequireWildcard(require("fs-extra"));
11
+ var _types = require("../types");
12
+ var _path = _interopRequireDefault(require("path"));
13
+ var _projectExclusions = _interopRequireDefault(require("../../common/projectExclusions"));
14
+ var _constants = require("../constants");
15
+ var _helpers = require("../helpers");
16
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
17
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
18
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
19
+ function isDirectoryNode(node) {
20
+ return node.directory !== undefined;
21
+ }
22
+ function isFileNode(node) {
23
+ return node.file !== undefined;
24
+ }
25
+ async function mountFiles(cwd, tree) {
26
+ for (const name in tree) {
27
+ const fullPath = _path.default.join(cwd, name);
28
+ const node = tree[name];
29
+ if (isDirectoryNode(node)) {
30
+ await fs.ensureDir(fullPath);
31
+ await mountFiles(fullPath, node.directory);
32
+ } else if (isFileNode(node)) {
33
+ await fs.writeFile(fullPath, node.file.contents);
34
+ }
35
+ }
36
+ }
37
+ async function checkEmptyDirectory() {
38
+ const currentDir = process.cwd();
39
+ try {
40
+ const stats = await fs.stat(currentDir);
41
+ if (!stats.isDirectory()) {
42
+ throw new _helpers.CLIError("The current path is not a directory.");
43
+ }
44
+ const files = await fs.readdir(currentDir);
45
+ const significantFiles = files.filter(file => !_projectExclusions.default.includes(file));
46
+ return significantFiles.length === 0;
47
+ } catch (error) {
48
+ if (error.code === "ENOENT") {
49
+ throw new _helpers.CLIError("The specified directory does not exist.");
50
+ }
51
+ throw error;
52
+ }
53
+ }
54
+ async function selectTemplate(templateName) {
55
+ if (templateName) {
56
+ if (!_types.templateIds.includes(templateName)) {
57
+ throw new _helpers.CLIError(`Template "${templateName}" not found.`);
58
+ }
59
+ return templateName;
60
+ }
61
+ (0, _helpers.terminal)("^+Select a template (ESC to cancel):^:\n");
62
+ const {
63
+ promise: selectedCommandPromise
64
+ } = _helpers.terminal.singleColumnMenu(_types.templateIds, {
65
+ cancelable: true
66
+ });
67
+ const selectedTemplateIndex = (await selectedCommandPromise).selectedIndex;
68
+ if (selectedTemplateIndex === undefined) {
69
+ throw new _helpers.CLIError("^y^+Project initialization cancelled.^:\n", {
70
+ autoColor: false
71
+ });
72
+ }
73
+ return _types.templateIds[selectedTemplateIndex];
74
+ }
75
+ async function scaffoldProject(templateId, isTargetDirectoryEmpty) {
76
+ if (!isTargetDirectoryEmpty) {
77
+ (0, _helpers.terminal)("^+The current directory is not empty. Do you want to proceed and override files?^: (y/N)");
78
+ const {
79
+ promise
80
+ } = _helpers.terminal.yesOrNo({
81
+ no: ["n", "ENTER", "ESCAPE"],
82
+ yes: ["y"],
83
+ echoNo: " no\n",
84
+ echoYes: " yes\n"
85
+ });
86
+ const confirm = await promise;
87
+ if (!confirm) {
88
+ throw new _helpers.CLIError("^y^+Project initialization cancelled^:\n", {
89
+ autoColor: false
90
+ });
91
+ }
92
+ }
93
+ const cwd = process.cwd();
94
+ (0, _helpers.terminal)(`^c🚀 Initializing ^:^+${templateId}^:^c project...\n`);
95
+ const template = await fetchProjectTemplate(templateId);
96
+ (0, _helpers.terminal)(`^c🔨 Creating project files...^:\n`);
97
+ const codeTree = template;
98
+ await prepareCLITemplate(codeTree);
99
+ await mountFiles(cwd, codeTree);
100
+ (0, _helpers.terminal)(`^g^+🎉 Project initialized successfully!^ ^GRun ^:^+yarn^:^G to install dependencies and start coding!\n`);
101
+ }
102
+ async function fetchProjectTemplate(templateId) {
103
+ const baseUrl = (0, _helpers.getBaseUrl)();
104
+ const url = `${baseUrl}/api/templates/${templateId}`;
105
+ const response = await fetch(url);
106
+ if (!response.ok) {
107
+ throw new _helpers.CLIError(`^r^+Error fetching template:\n^:^R${response.statusText} ${response.status}\n^r^+Failed to initialize project^:\n`, {
108
+ autoColor: false
109
+ });
110
+ }
111
+ const data = await response.json();
112
+ if (!data) {
113
+ throw new _helpers.CLIError("Error fetching template: Template not found");
114
+ }
115
+ return data.template;
116
+ }
117
+ async function prepareCLITemplate(codeTree) {
118
+ codeTree["parameters"] = {
119
+ directory: {}
120
+ };
121
+ codeTree["tsconfig.json"] = {
122
+ file: {
123
+ contents: JSON.stringify(_constants.tsConfigCli, null, 2)
124
+ }
125
+ };
126
+ if (isFileNode(codeTree["package.json"]) && codeTree["package.json"].file) {
127
+ const packageJson = JSON.parse(codeTree["package.json"].file.contents);
128
+ packageJson.scripts = _constants.userCLIScripts;
129
+ codeTree["package.json"].file.contents = JSON.stringify(packageJson, null, 2);
130
+ }
131
+ codeTree["README.md"] = {
132
+ file: {
133
+ contents: _constants.readme
134
+ }
135
+ };
136
+ }
@@ -0,0 +1,3 @@
1
+ import { API_FOLDER_NAME, AUTH_SESSIONS_FOLDER_NAME } from "../../../common/constants";
2
+ export declare function assertApiFileExists(dirname: typeof AUTH_SESSIONS_FOLDER_NAME, api: "create" | "check"): Promise<void>;
3
+ export declare function assertApiFileExists(dirname: typeof API_FOLDER_NAME, api: string): Promise<void>;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.assertApiFileExists = assertApiFileExists;
7
+ var _path = _interopRequireDefault(require("path"));
8
+ var _fsExtra = require("fs-extra");
9
+ var _errors = require("./errors");
10
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
+ async function assertApiFileExists(dirname, api) {
12
+ const file = `${dirname}/${api}.ts`;
13
+ const filePath = _path.default.join(process.cwd(), file);
14
+ if (!(await (0, _fsExtra.exists)(filePath))) {
15
+ throw new _errors.CLIAssertionError(`^+^r API^ ^+${dirname}/${api}^ ^r^+is not implemented.^:`, {
16
+ autoColor: false
17
+ });
18
+ }
19
+ }
@@ -0,0 +1,41 @@
1
+ import type { AuthSessionMetadata } from "../types";
2
+ import { RunApiStorageState as StorageState } from "../../../common/runApi";
3
+ export declare function isAuthEnabled(): Promise<boolean>;
4
+ export declare function assertAuthEnabled(): Promise<void>;
5
+ export declare function assertAuthConsistent(authSession: string | undefined): Promise<void>;
6
+ export declare function loadAuthSessionInstance(authSessionId: string): Promise<{
7
+ storageState: {
8
+ cookies: {
9
+ value: string;
10
+ name: string;
11
+ path: string;
12
+ domain: string;
13
+ expires: number;
14
+ httpOnly: boolean;
15
+ secure: boolean;
16
+ sameSite: "Strict" | "Lax" | "None";
17
+ }[];
18
+ origins: {
19
+ origin: string;
20
+ localStorage: {
21
+ value: string;
22
+ name: string;
23
+ }[];
24
+ }[];
25
+ sessionStorage?: {
26
+ sessionStorage: {
27
+ value: string;
28
+ name: string;
29
+ }[];
30
+ origin: string;
31
+ }[] | undefined;
32
+ };
33
+ metadata: AuthSessionMetadata;
34
+ }>;
35
+ export declare function storeAuthSessionInstance({ state, id, input, proxy, }: {
36
+ state: StorageState;
37
+ id?: string;
38
+ input?: Record<string, any>;
39
+ proxy?: string;
40
+ }): Promise<string>;
41
+ export declare function registerGetAuthSessionParameters(authSessionId?: string): void;