@intuned/runtime-dev 1.3.0-dev-52 → 1.3.1-api-token.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 (137) hide show
  1. package/.babelrc +2 -2
  2. package/CHANGELOG.md +6 -1
  3. package/WebTemplate.zip +0 -0
  4. package/bin/intuned +2 -0
  5. package/dist/commands/api/run.js +4 -3
  6. package/dist/commands/common/browserUtils.d.ts +1 -1
  7. package/dist/commands/common/browserUtils.js +1 -1
  8. package/dist/commands/common/getFirstLineNumber.js +2 -4
  9. package/dist/commands/interface/run.js +5 -6
  10. package/dist/commands/intuned-cli/commands/attempt.command.d.ts +1 -0
  11. package/dist/commands/intuned-cli/commands/attempt.command.js +8 -0
  12. package/dist/commands/intuned-cli/commands/attempt_api.command.d.ts +1 -0
  13. package/dist/commands/intuned-cli/commands/attempt_api.command.js +40 -0
  14. package/dist/commands/intuned-cli/commands/attempt_authsession.command.d.ts +1 -0
  15. package/dist/commands/intuned-cli/commands/attempt_authsession.command.js +8 -0
  16. package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.d.ts +1 -0
  17. package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.js +24 -0
  18. package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.d.ts +1 -0
  19. package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.js +36 -0
  20. package/dist/commands/intuned-cli/commands/build.command.d.ts +1 -0
  21. package/dist/commands/intuned-cli/commands/build.command.js +12 -0
  22. package/dist/commands/intuned-cli/commands/command.d.ts +2 -0
  23. package/dist/commands/intuned-cli/commands/command.js +9 -0
  24. package/dist/commands/intuned-cli/commands/deploy.command.d.ts +1 -0
  25. package/dist/commands/intuned-cli/commands/deploy.command.js +43 -0
  26. package/dist/commands/intuned-cli/commands/index.d.ts +16 -0
  27. package/dist/commands/intuned-cli/commands/index.js +181 -0
  28. package/dist/commands/intuned-cli/commands/init.command.d.ts +1 -0
  29. package/dist/commands/intuned-cli/commands/init.command.js +13 -0
  30. package/dist/commands/intuned-cli/commands/run.command.d.ts +1 -0
  31. package/dist/commands/intuned-cli/commands/run.command.js +8 -0
  32. package/dist/commands/intuned-cli/commands/run_api.command.d.ts +1 -0
  33. package/dist/commands/intuned-cli/commands/run_api.command.js +54 -0
  34. package/dist/commands/intuned-cli/commands/run_authsession.command.d.ts +20 -0
  35. package/dist/commands/intuned-cli/commands/run_authsession.command.js +13 -0
  36. package/dist/commands/intuned-cli/commands/run_authsession_create.command.d.ts +1 -0
  37. package/dist/commands/intuned-cli/commands/run_authsession_create.command.js +39 -0
  38. package/dist/commands/intuned-cli/commands/run_authsession_update.command.d.ts +1 -0
  39. package/dist/commands/intuned-cli/commands/run_authsession_update.command.js +39 -0
  40. package/dist/commands/intuned-cli/commands/run_authsession_validate.command.d.ts +1 -0
  41. package/dist/commands/intuned-cli/commands/run_authsession_validate.command.js +37 -0
  42. package/dist/commands/intuned-cli/commands/save.command.d.ts +12 -0
  43. package/dist/commands/intuned-cli/commands/save.command.js +46 -0
  44. package/dist/commands/intuned-cli/commands/types.d.ts +21 -0
  45. package/dist/commands/intuned-cli/commands/types.js +21 -0
  46. package/dist/commands/intuned-cli/constants/index.d.ts +17 -0
  47. package/dist/commands/intuned-cli/constants/index.js +25 -0
  48. package/dist/commands/intuned-cli/controller/__test__/api.test.js +280 -0
  49. package/dist/commands/intuned-cli/controller/__test__/authSession.test.js +676 -0
  50. package/dist/commands/intuned-cli/controller/api.d.ts +44 -0
  51. package/dist/commands/intuned-cli/controller/api.js +181 -0
  52. package/dist/commands/intuned-cli/controller/authSession.d.ts +198 -0
  53. package/dist/commands/intuned-cli/controller/authSession.js +292 -0
  54. package/dist/commands/intuned-cli/controller/build.d.ts +1 -0
  55. package/dist/commands/intuned-cli/controller/build.js +36 -0
  56. package/dist/commands/intuned-cli/controller/deploy.d.ts +4 -0
  57. package/dist/commands/intuned-cli/controller/deploy.js +138 -0
  58. package/dist/commands/intuned-cli/controller/index.d.ts +1 -0
  59. package/dist/commands/intuned-cli/controller/index.js +46 -0
  60. package/dist/commands/intuned-cli/controller/save.d.ts +14 -0
  61. package/dist/commands/{deploy/utils.js → intuned-cli/controller/save.js} +164 -207
  62. package/dist/commands/intuned-cli/helpers/api.d.ts +3 -0
  63. package/dist/commands/intuned-cli/helpers/api.js +19 -0
  64. package/dist/commands/intuned-cli/helpers/auth.d.ts +41 -0
  65. package/dist/commands/intuned-cli/helpers/auth.js +129 -0
  66. package/dist/commands/intuned-cli/helpers/backend.d.ts +8 -0
  67. package/dist/commands/intuned-cli/helpers/backend.js +27 -0
  68. package/dist/commands/intuned-cli/helpers/context.d.ts +3 -0
  69. package/dist/commands/intuned-cli/helpers/context.js +33 -0
  70. package/dist/commands/intuned-cli/helpers/errors.d.ts +14 -0
  71. package/dist/commands/intuned-cli/helpers/errors.js +55 -0
  72. package/dist/commands/intuned-cli/helpers/index.d.ts +10 -0
  73. package/dist/commands/intuned-cli/helpers/index.js +115 -0
  74. package/dist/commands/intuned-cli/helpers/intunedJson.d.ts +1 -0
  75. package/dist/{common/cli/utils.js → commands/intuned-cli/helpers/intunedJson.js} +0 -16
  76. package/dist/commands/intuned-cli/helpers/proxy.d.ts +5 -0
  77. package/dist/commands/intuned-cli/helpers/proxy.js +23 -0
  78. package/dist/commands/intuned-cli/helpers/terminal.d.ts +5 -0
  79. package/dist/commands/intuned-cli/helpers/terminal.js +13 -0
  80. package/dist/commands/intuned-cli/helpers/timeout.d.ts +1 -0
  81. package/dist/commands/intuned-cli/helpers/timeout.js +23 -0
  82. package/dist/commands/intuned-cli/helpers/validation.d.ts +2 -0
  83. package/dist/commands/intuned-cli/helpers/validation.js +12 -0
  84. package/dist/commands/intuned-cli/index.d.ts +1 -0
  85. package/dist/commands/intuned-cli/index.js +16 -0
  86. package/dist/commands/intuned-cli/main.d.ts +1 -0
  87. package/dist/commands/intuned-cli/main.js +15 -0
  88. package/dist/{common/cli → commands/intuned-cli}/types.d.ts +1 -34
  89. package/dist/{common/cli → commands/intuned-cli}/types.js +1 -2
  90. package/dist/common/assets/browser_scripts.js +2509 -2143
  91. package/dist/common/constants.d.ts +4 -0
  92. package/dist/common/constants.js +6 -2
  93. package/dist/common/getPlaywrightConstructs.d.ts +1 -1
  94. package/dist/common/getPlaywrightConstructs.js +4 -12
  95. package/dist/common/jwtTokenManager.d.ts +1 -0
  96. package/dist/common/jwtTokenManager.js +16 -9
  97. package/dist/common/runApi/errors.d.ts +9 -2
  98. package/dist/common/runApi/errors.js +21 -8
  99. package/dist/common/runApi/index.d.ts +4 -1
  100. package/dist/common/runApi/index.js +33 -21
  101. package/dist/common/runApi/types.d.ts +140 -9
  102. package/dist/common/runApi/types.js +28 -27
  103. package/dist/runtime/executionHelpers.test.js +3 -4
  104. package/dist/runtime/export.d.ts +15 -0
  105. package/dist/runtime/extendPayload.js +1 -1
  106. package/package.json +11 -12
  107. package/tsconfig.json +2 -1
  108. package/bin/check-auth-session +0 -3
  109. package/bin/cli-build +0 -3
  110. package/bin/create-auth-session +0 -3
  111. package/bin/deploy +0 -3
  112. package/bin/init +0 -3
  113. package/bin/run-api +0 -3
  114. package/dist/commands/cli-auth-sessions/check.d.ts +0 -2
  115. package/dist/commands/cli-auth-sessions/check.js +0 -40
  116. package/dist/commands/cli-auth-sessions/create.d.ts +0 -2
  117. package/dist/commands/cli-auth-sessions/create.js +0 -53
  118. package/dist/commands/cli-auth-sessions/utils.d.ts +0 -28
  119. package/dist/commands/cli-auth-sessions/utils.js +0 -285
  120. package/dist/commands/cli-build/cli-build.d.ts +0 -2
  121. package/dist/commands/cli-build/cli-build.js +0 -20
  122. package/dist/commands/deploy/deploy.d.ts +0 -2
  123. package/dist/commands/deploy/deploy.js +0 -47
  124. package/dist/commands/deploy/utils.d.ts +0 -16
  125. package/dist/commands/init/init.d.ts +0 -2
  126. package/dist/commands/init/init.js +0 -22
  127. package/dist/commands/init/utils.d.ts +0 -11
  128. package/dist/commands/init/utils.js +0 -181
  129. package/dist/commands/run-api-cli/run-api.d.ts +0 -2
  130. package/dist/commands/run-api-cli/run-api.js +0 -57
  131. package/dist/commands/run-api-cli/utils.d.ts +0 -9
  132. package/dist/commands/run-api-cli/utils.js +0 -144
  133. package/dist/common/cli/cliReadme.d.ts +0 -1
  134. package/dist/common/cli/cliReadme.js +0 -92
  135. package/dist/common/cli/constants.d.ts +0 -33
  136. package/dist/common/cli/constants.js +0 -39
  137. package/dist/common/cli/utils.d.ts +0 -6
@@ -3,127 +3,45 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.convertProjectToCodeTree = convertProjectToCodeTree;
7
- exports.deployProject = deployProject;
8
- exports.validateProjectName = exports.validateIntunedProject = exports.runBuild = void 0;
6
+ exports.projectNameSchema = void 0;
7
+ exports.runSaveProject = runSaveProject;
8
+ exports.validateProjectName = exports.validateIntunedProject = void 0;
9
9
  var fs = _interopRequireWildcard(require("fs-extra"));
10
10
  var path = _interopRequireWildcard(require("path"));
11
- var _chalk = _interopRequireDefault(require("chalk"));
12
11
  var _minimatch = require("minimatch");
13
12
  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");
13
+ var _projectExclusions = _interopRequireDefault(require("../../common/projectExclusions"));
14
+ var _constants = require("../constants");
15
+ var _helpers = require("../helpers");
20
16
  var _lodash = require("lodash");
21
17
  var _uuid = require("uuid");
18
+ var _terminal = require("../helpers/terminal");
19
+ var _build = require("./build");
20
+ var dotenv = _interopRequireWildcard(require("dotenv"));
21
+ var _constants2 = require("../../../common/constants");
22
22
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
23
23
  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
24
  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
- function ignoreFilesByPattern(filePath, patterns, projectPath) {
27
- const relativePath = path.relative(projectPath, filePath);
28
- if (relativePath.startsWith("node_modules")) {
29
- return true;
30
- }
31
- for (const pattern of patterns) {
32
- if (!pattern || pattern.startsWith("#")) continue;
33
- if (pattern.startsWith("!")) {
34
- if ((0, _minimatch.minimatch)(relativePath, pattern.substring(1))) {
35
- return false;
36
- }
37
- } else if ((0, _minimatch.minimatch)(relativePath, pattern)) {
38
- return true;
39
- }
40
- }
41
- return false;
42
- }
43
- function listFilesNotIgnored(projectPath, ignorePatterns) {
44
- const results = [];
45
- function traverseDirectory(dirPath) {
46
- try {
47
- const entries = fs.readdirSync(dirPath);
48
- for (const entry of entries) {
49
- const fullPath = path.join(dirPath, entry);
50
- if (ignoreFilesByPattern(fullPath, ignorePatterns, projectPath)) {
51
- continue;
52
- }
53
- try {
54
- const stats = fs.statSync(fullPath);
55
- if (stats.isDirectory()) {
56
- traverseDirectory(fullPath);
57
- } else if (stats.isFile()) {
58
- results.push(path.relative(projectPath, fullPath));
59
- }
60
- } catch (error) {
61
- console.log(_chalk.default.yellow(`Warning: Could not access ${fullPath}`));
62
- }
63
- }
64
- } catch (error) {
65
- console.log(_chalk.default.yellow(`Warning: Could not read directory ${dirPath}`));
66
- }
67
- }
68
- traverseDirectory(projectPath);
69
- return results;
70
- }
71
- async function convertProjectToCodeTree(projectPath) {
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);
76
- function readDirectory(dirPath) {
77
- const tree = {};
78
- try {
79
- const entries = fs.readdirSync(dirPath);
80
- for (const entry of entries) {
81
- const entryPath = path.join(dirPath, entry);
82
- if (ignoreFilesByPattern(entryPath, _projectExclusions.default, projectPath)) {
83
- continue;
84
- }
85
- try {
86
- const stats = fs.statSync(entryPath);
87
- if (stats.isFile()) {
88
- try {
89
- const content = fs.readFileSync(entryPath, "utf-8");
90
- tree[entry] = {
91
- file: {
92
- contents: content
93
- }
94
- };
95
- } catch (error) {
96
- console.log(_chalk.default.yellow(`Warning: Could not read file ${entryPath}`));
97
- }
98
- } else if (stats.isDirectory()) {
99
- const subTree = readDirectory(entryPath);
100
- if (Object.keys(subTree).length > 0) {
101
- tree[entry] = {
102
- directory: subTree
103
- };
104
- }
105
- }
106
- } catch (error) {
107
- console.log(_chalk.default.yellow(`Warning: Could not access ${entryPath}`));
108
- }
109
- }
110
- } catch (error) {
111
- console.log(_chalk.default.yellow(`Warning: Could not read directory ${dirPath}`));
112
- }
113
- return tree;
25
+ const saveProjectApiResponseSchema = _zod.z.string().transform((val, ctx) => {
26
+ try {
27
+ return JSON.parse(val);
28
+ } catch (e) {
29
+ ctx.addIssue({
30
+ code: _zod.z.ZodIssueCode.custom,
31
+ message: "Response is not valid JSON"
32
+ });
33
+ return _zod.z.NEVER;
114
34
  }
115
- console.log(_chalk.default.cyan("\n📦 Building project..."));
116
- const tree = readDirectory(projectPath);
117
- await mapToIDEParams(tree);
118
- return tree;
119
- }
120
- async function deployProject(projectName, auth) {
35
+ }).pipe(_zod.z.object({
36
+ id: _zod.z.string().uuid()
37
+ }));
38
+ async function runSaveProject(projectName, auth) {
121
39
  const {
122
40
  workspaceId,
123
41
  apiKey
124
42
  } = auth;
125
- const baseUrl = (0, _utils.getBaseUrl)();
126
- const url = `${baseUrl}/api/v1/workspace/${workspaceId}/projects/create`;
43
+ const baseUrl = (0, _helpers.getBaseUrl)();
44
+ const url = `${baseUrl}/api/v1/workspace/${workspaceId}/projects/${projectName}`;
127
45
  const headers = {
128
46
  "x-api-key": apiKey,
129
47
  "Content-Type": "application/json"
@@ -136,60 +54,64 @@ async function deployProject(projectName, auth) {
136
54
  }
137
55
  };
138
56
  const deployProjectPayload = {
139
- name: projectName,
140
57
  codeTree,
141
- isCli: true,
58
+ platformType: "CLI",
142
59
  language: "typescript"
143
60
  };
144
61
  const response = await fetch(url, {
145
62
  headers,
146
- method: "POST",
63
+ method: "PUT",
147
64
  body: JSON.stringify(deployProjectPayload)
148
65
  });
149
66
  if (!response.ok) {
150
67
  if (response.status === 401) {
151
- throw new Error(`Invalid API key. Please check your API key and try again.`);
68
+ throw new _helpers.CLIError(`Invalid API key. Please check your API key and try again.`);
152
69
  }
153
- throw new Error(`Error deploying project`);
70
+ throw new _helpers.CLIError(`^r^+Invalid response from server\n^:^R${response.status} ${await response.text()}^:\n^r^+Project deployment failed^:\n`, {
71
+ autoColor: false
72
+ });
73
+ }
74
+ (0, _terminal.terminal)("^g^+Project saved successfully!^:\n");
75
+ const body = await response.text();
76
+ const parseResult = saveProjectApiResponseSchema.safeParse(body);
77
+ if (!parseResult.success) {
78
+ (0, _terminal.terminal)(`^yWarning: Could not parse save project response:^:\n`);
79
+ (0, _terminal.terminal)(body + "\n");
80
+ return;
81
+ }
82
+ const {
83
+ id: projectId
84
+ } = parseResult.data;
85
+ const dotEnvPath = path.join(projectPath, ".env");
86
+ if (await fs.exists(dotEnvPath)) {
87
+ const envContent = await fs.readFile(dotEnvPath, "utf-8");
88
+ const dotenvContent = dotenv.parse(envContent);
89
+ let contentToAppend = "";
90
+ if (!dotenvContent[_constants2.PROJECT_ID_ENV_VAR_KEY] || dotenvContent[_constants2.PROJECT_ID_ENV_VAR_KEY] !== projectId) {
91
+ contentToAppend += `\n${_constants2.PROJECT_ID_ENV_VAR_KEY}=${projectId}`;
92
+ }
93
+ if (!dotenvContent[_constants2.WORKSPACE_ID_ENV_VAR_KEY]) {
94
+ contentToAppend += `\n${_constants2.WORKSPACE_ID_ENV_VAR_KEY}=${workspaceId}`;
95
+ }
96
+ if (!dotenvContent[_constants2.API_KEY_ENV_VAR_KEY]) {
97
+ contentToAppend += `\n${_constants2.API_KEY_ENV_VAR_KEY}=${apiKey}`;
98
+ }
99
+ if (contentToAppend) {
100
+ await fs.appendFile(dotEnvPath, contentToAppend + "\n");
101
+ (0, _terminal.terminal)(`^g^+Updated .env file with project credentials.^:\n`);
102
+ }
103
+ } else {
104
+ await fs.writeFile(dotEnvPath, `${_constants2.PROJECT_ID_ENV_VAR_KEY}=${projectId}
105
+ ${_constants2.WORKSPACE_ID_ENV_VAR_KEY}=${workspaceId}
106
+ ${_constants2.API_KEY_ENV_VAR_KEY}=${apiKey}`);
107
+ (0, _terminal.terminal)(`^g^+Created .env file with project credentials.^:\n`);
154
108
  }
155
- 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
- }
176
- const elapsedTime = Date.now() - startTime;
177
- 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`));
180
- }
181
- } catch (error) {
182
- clearInterval(checkInterval);
183
- reject(error);
184
- }
185
- }, 5000);
186
- });
187
109
  }
110
+ 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, {
111
+ message: "Name cannot be a UUID"
112
+ });
188
113
  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);
114
+ const validation = projectNameSchema.safeParse(projectName);
193
115
  if (!validation.success) {
194
116
  return {
195
117
  isValid: false,
@@ -207,7 +129,7 @@ const validateIntunedProject = async () => {
207
129
  name: "build",
208
130
  check: async () => {
209
131
  try {
210
- const buildResult = await runBuild();
132
+ const buildResult = await (0, _build.runBuild)();
211
133
  if (!buildResult) {
212
134
  return {
213
135
  isValid: false,
@@ -228,13 +150,12 @@ const validateIntunedProject = async () => {
228
150
  name: "package.json",
229
151
  check: async () => {
230
152
  try {
231
- var _packageJson$dependen;
232
153
  const packageJsonPath = path.join(currentDirectoryToDeploy, "package.json");
233
154
  await fs.exists(packageJsonPath);
234
155
  const packageJson = JSON.parse(await fs.readFile(packageJsonPath, {
235
156
  encoding: "utf-8"
236
157
  }));
237
- const userCodePlaywrightVersion = (_packageJson$dependen = packageJson.dependencies) === null || _packageJson$dependen === void 0 ? void 0 : _packageJson$dependen.playwright;
158
+ const userCodePlaywrightVersion = packageJson.dependencies?.playwright;
238
159
  if (userCodePlaywrightVersion !== _constants.CURRENT_PLAYWRIGHT_VERSION) {
239
160
  return {
240
161
  isValid: false,
@@ -295,68 +216,104 @@ const validateIntunedProject = async () => {
295
216
  };
296
217
  };
297
218
  exports.validateIntunedProject = validateIntunedProject;
298
- const checkIntunedProjectDeployStatus = async (workspaceId, projectName, apiKey) => {
299
- try {
300
- const baseUrl = (0, _utils.getBaseUrl)();
301
- const url = `${baseUrl}/api/v1/workspace/${workspaceId}/projects/create/${projectName}/result`;
302
- const headers = {
303
- "x-api-key": apiKey,
304
- "Content-Type": "application/json"
305
- };
306
- const response = await fetch(url, {
307
- headers,
308
- method: "GET"
309
- });
310
- if (response.status === 404) {
311
- return {
312
- status: "not_found",
313
- message: "Project not found"
314
- };
315
- }
316
- if (!response.ok) {
317
- throw new Error("Error querying deployment status");
318
- }
319
- const data = await response.json();
320
- if (data.status) {
321
- return {
322
- status: data.status,
323
- message: data.message,
324
- projectId: data.projectId
325
- };
219
+ function ignoreFilesByPattern(filePath, patterns, projectPath) {
220
+ const relativePath = path.relative(projectPath, filePath);
221
+ if (relativePath.startsWith("node_modules")) {
222
+ return true;
223
+ }
224
+ for (const pattern of patterns) {
225
+ if (!pattern || pattern.startsWith("#")) continue;
226
+ if (pattern.startsWith("!")) {
227
+ if ((0, _minimatch.minimatch)(relativePath, pattern.substring(1))) {
228
+ return false;
229
+ }
230
+ } else if ((0, _minimatch.minimatch)(relativePath, pattern)) {
231
+ return true;
326
232
  }
327
- return {
328
- status: "failed",
329
- message: `Deployment failed, please try again: ${data.message}`
330
- };
331
- } catch (e) {
332
- throw new Error(`Error during deployment`);
333
233
  }
334
- };
335
- const runBuild = async () => {
336
- const currentProjectDirectory = process.cwd();
337
- console.log(_chalk.default.yellow("Running build..."));
338
- const distPath = path.join(currentProjectDirectory, "dist");
339
- if (await fs.exists(distPath)) {
340
- await fs.remove(distPath);
234
+ return false;
235
+ }
236
+ function listFilesNotIgnored(projectPath, ignorePatterns) {
237
+ const results = [];
238
+ function traverseDirectory(dirPath) {
239
+ try {
240
+ const entries = fs.readdirSync(dirPath);
241
+ for (const entry of entries) {
242
+ const fullPath = path.join(dirPath, entry);
243
+ if (ignoreFilesByPattern(fullPath, ignorePatterns, projectPath)) {
244
+ continue;
245
+ }
246
+ try {
247
+ const stats = fs.statSync(fullPath);
248
+ if (stats.isDirectory()) {
249
+ traverseDirectory(fullPath);
250
+ } else if (stats.isFile()) {
251
+ results.push(path.relative(projectPath, fullPath));
252
+ }
253
+ } catch (error) {
254
+ (0, _terminal.terminal)(`^yWarning: Could not access ${fullPath}^:\n`);
255
+ }
256
+ }
257
+ } catch (error) {
258
+ (0, _terminal.terminal)(`^YWarning: Could not read directory ${dirPath}^:\n`);
259
+ }
341
260
  }
342
- const buildCommand = "tsc";
343
- try {
344
- await execPromise(buildCommand, {
345
- cwd: currentProjectDirectory
346
- });
347
- console.log(_chalk.default.green("🏗️ Build completed successfully"));
348
- return true;
349
- } catch (error) {
350
- console.error(_chalk.default.red(`Build failed: ${error.message}`));
351
- return false;
261
+ traverseDirectory(projectPath);
262
+ return results;
263
+ }
264
+ async function convertProjectToCodeTree(projectPath) {
265
+ const filesToDeploy = listFilesNotIgnored(projectPath, _projectExclusions.default);
266
+ const filesToDeployText = " " + filesToDeploy.join("\n ");
267
+ (0, _terminal.terminal)("^CFiles to be saved:^:\n");
268
+ (0, _terminal.terminal)(filesToDeployText + "\n");
269
+ function readDirectory(dirPath) {
270
+ const tree = {};
271
+ try {
272
+ const entries = fs.readdirSync(dirPath);
273
+ for (const entry of entries) {
274
+ const entryPath = path.join(dirPath, entry);
275
+ if (ignoreFilesByPattern(entryPath, _projectExclusions.default, projectPath)) {
276
+ continue;
277
+ }
278
+ try {
279
+ const stats = fs.statSync(entryPath);
280
+ if (stats.isFile()) {
281
+ try {
282
+ const content = fs.readFileSync(entryPath, "utf-8");
283
+ tree[entry] = {
284
+ file: {
285
+ contents: content
286
+ }
287
+ };
288
+ } catch (error) {
289
+ (0, _terminal.terminal)(`^yWarning: Could not read file ${entryPath}^:\n`);
290
+ }
291
+ } else if (stats.isDirectory()) {
292
+ const subTree = readDirectory(entryPath);
293
+ if (Object.keys(subTree).length > 0) {
294
+ tree[entry] = {
295
+ directory: subTree
296
+ };
297
+ }
298
+ }
299
+ } catch (error) {
300
+ (0, _terminal.terminal)(`^yWarning: Could not access ${entryPath}^:\n`);
301
+ }
302
+ }
303
+ } catch (error) {
304
+ (0, _terminal.terminal)(`^YWarning: Could not read directory ${dirPath}^:\n`);
305
+ }
306
+ return tree;
352
307
  }
353
- };
354
- exports.runBuild = runBuild;
355
- async function mapToIDEParams(tree) {
308
+ const tree = readDirectory(projectPath);
309
+ mapToIDEParams(tree);
310
+ return tree;
311
+ }
312
+ function mapToIDEParams(tree) {
356
313
  if (!tree) {
357
314
  return;
358
315
  }
359
- if (!tree["parameters"] || (0, _utils2._isFileNode)(tree["parameters"])) {
316
+ if (!tree["parameters"] || "file" in tree["parameters"]) {
360
317
  return;
361
318
  }
362
319
  const apiParametersMap = {};
@@ -366,7 +323,7 @@ async function mapToIDEParams(tree) {
366
323
  };
367
324
  for (const parameterKey of cliParameters) {
368
325
  const parameter = tree["parameters"].directory[parameterKey];
369
- if ((0, _utils2._isDirectoryNode)(parameter)) {
326
+ if ("directory" in parameter) {
370
327
  continue;
371
328
  }
372
329
  if ((0, _lodash.isEmpty)(parameter.file.contents)) {
@@ -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;
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.assertAuthConsistent = assertAuthConsistent;
7
+ exports.assertAuthEnabled = assertAuthEnabled;
8
+ exports.isAuthEnabled = isAuthEnabled;
9
+ exports.loadAuthSessionInstance = loadAuthSessionInstance;
10
+ exports.registerGetAuthSessionParameters = registerGetAuthSessionParameters;
11
+ exports.storeAuthSessionInstance = storeAuthSessionInstance;
12
+ var _constants = require("../../../common/constants");
13
+ var _path = _interopRequireDefault(require("path"));
14
+ var _fsExtra = require("fs-extra");
15
+ var _intunedJson = require("./intunedJson");
16
+ var _errors = require("./errors");
17
+ var _runApi = require("../../../common/runApi");
18
+ var _formatZodError = require("../../../common/formatZodError");
19
+ var _asyncLocalStorage = require("../../../common/asyncLocalStorage");
20
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
21
+ async function isAuthEnabled() {
22
+ try {
23
+ const intunedJson = await (0, _fsExtra.readJSON)(_path.default.join(process.cwd(), "Intuned.json"));
24
+ return Boolean(intunedJson?.authSessions?.enabled);
25
+ } catch (error) {
26
+ return false;
27
+ }
28
+ }
29
+ async function assertAuthEnabled() {
30
+ if (!(await isAuthEnabled())) {
31
+ throw new _errors.CLIAssertionError("Auth session is not enabled, enable it in Intuned.json to use it");
32
+ }
33
+ }
34
+ async function assertAuthConsistent(authSession) {
35
+ const _isAuthEnabled = await isAuthEnabled();
36
+ if (_isAuthEnabled && !authSession) {
37
+ throw new _errors.CLIAssertionError("Auth session is enabled, but no auth session is provided. Please provide an auth session ID.");
38
+ }
39
+ if (!_isAuthEnabled && authSession) {
40
+ throw new _errors.CLIAssertionError("Auth session is not enabled, enable it in Intuned.json to use it");
41
+ }
42
+ }
43
+ async function loadAuthSessionInstance(authSessionId) {
44
+ try {
45
+ const authSessionInstancePath = _path.default.join(process.cwd(), _constants.AUTH_SESSIONS_INSTANCES_FOLDER_NAME, authSessionId);
46
+ const authSessionInstanceStoragePath = _path.default.join(authSessionInstancePath, `auth-session.json`);
47
+ const authSessionInstanceMetadataPath = _path.default.join(authSessionInstancePath, `metadata.json`);
48
+ if (!(await (0, _fsExtra.exists)(authSessionInstanceStoragePath))) {
49
+ throw new _errors.CLIError(`Auth session instance with ID ${authSessionId} not found`);
50
+ }
51
+ const authSessionInstanceJson = await (0, _fsExtra.readJSON)(authSessionInstanceStoragePath);
52
+ const authSessionInstanceParseResult = _runApi.runApiStorageStateSchema.safeParse(authSessionInstanceJson);
53
+ if (!authSessionInstanceParseResult.success) {
54
+ throw new _errors.CLIError(`Auth session instance with ID ${authSessionId} is not valid: ${(0, _formatZodError.formatZodError)(authSessionInstanceParseResult.error)}`);
55
+ }
56
+ const metadata = await (0, _fsExtra.readJSON)(authSessionInstanceMetadataPath);
57
+ return {
58
+ storageState: authSessionInstanceParseResult.data,
59
+ metadata
60
+ };
61
+ } catch (error) {
62
+ throw new _errors.CLIError(`Error retrieving auth session instance: ${error.message}`);
63
+ }
64
+ }
65
+ async function storeAuthSessionInstance({
66
+ state,
67
+ id,
68
+ input,
69
+ proxy
70
+ }) {
71
+ try {
72
+ const authSessionsDirectoryPath = _path.default.join(process.cwd(), _constants.AUTH_SESSIONS_INSTANCES_FOLDER_NAME);
73
+ await (0, _fsExtra.ensureDir)(authSessionsDirectoryPath);
74
+ const authSessionInstanceId = id ?? `auth-session-${Date.now()}`;
75
+ const authSessionInstancePath = _path.default.join(authSessionsDirectoryPath, authSessionInstanceId);
76
+ const authSessionExists = await (0, _fsExtra.pathExists)(authSessionInstancePath);
77
+ await (0, _fsExtra.ensureDir)(authSessionInstancePath);
78
+ const authSessionInstanceStoragePath = _path.default.join(authSessionInstancePath, `auth-session.json`);
79
+ await (0, _fsExtra.writeJSON)(authSessionInstanceStoragePath, state, {
80
+ spaces: 2
81
+ });
82
+ const projectAuthConfig = await (0, _intunedJson.getSettingIntunedJSON)("authSessions");
83
+ let existingMetadata = {};
84
+ const authSessionInstanceMetadataPath = _path.default.join(authSessionInstancePath, `metadata.json`);
85
+ if (authSessionExists) {
86
+ try {
87
+ existingMetadata = await (0, _fsExtra.readJSON)(authSessionInstanceMetadataPath);
88
+ } catch (readError) {
89
+ existingMetadata = {};
90
+ }
91
+ }
92
+ const authSessionMetadata = {
93
+ createdAt: existingMetadata.createdAt || new Date().toISOString(),
94
+ updatedAt: new Date().toISOString(),
95
+ ...(projectAuthConfig.type === "API" && {
96
+ authSessionInput: input || existingMetadata.authSessionInput || {}
97
+ }),
98
+ authSessionId: authSessionInstanceId,
99
+ authSessionType: projectAuthConfig.type ?? existingMetadata.authSessionType ?? "API",
100
+ ...(projectAuthConfig.type === "MANUAL" && {
101
+ recorderStartUrl: projectAuthConfig.startUrl,
102
+ recorderEndUrl: projectAuthConfig.endUrl
103
+ }),
104
+ authSessionInput: input || existingMetadata.authSessionInput || {},
105
+ authSessionProxy: proxy || existingMetadata.authSessionProxy
106
+ };
107
+ await (0, _fsExtra.writeJSON)(authSessionInstanceMetadataPath, authSessionMetadata, {
108
+ spaces: 2
109
+ });
110
+ return authSessionInstancePath;
111
+ } catch (error) {
112
+ throw new _errors.CLIError(`Error storing auth session instance: ${error.message}`);
113
+ }
114
+ }
115
+ function registerGetAuthSessionParameters(authSessionId) {
116
+ async function getAuthSessionParameters() {
117
+ if (!authSessionId) {
118
+ throw new Error("getAuthSessionParameters cannot be called without using an auth session");
119
+ }
120
+ const {
121
+ metadata
122
+ } = await loadAuthSessionInstance(authSessionId);
123
+ if (metadata?.authSessionType === "MANUAL") {
124
+ throw new Error("Auth session is recorder-based, it does not have parameters.");
125
+ }
126
+ return metadata?.authSessionInput ?? {};
127
+ }
128
+ (0, _asyncLocalStorage.getExecutionContext)().getAuthSessionParameters = getAuthSessionParameters;
129
+ }
@@ -0,0 +1,8 @@
1
+ export declare function getAuthCredentials(options: {
2
+ workspaceId?: string;
3
+ apiKey?: string;
4
+ }): Promise<{
5
+ workspaceId: any;
6
+ apiKey: string;
7
+ }>;
8
+ export declare function getBaseUrl(): string;