@intuned/runtime-dev 1.1.8-bot-detection → 1.2.0-cli.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 (104) hide show
  1. package/.babelrc +2 -2
  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 +8 -2
  6. package/dist/commands/auth-sessions/run-check.js +18 -4
  7. package/dist/commands/auth-sessions/run-create.js +2 -1
  8. package/dist/commands/cli-auth-sessions/create.js +1 -1
  9. package/dist/commands/cli-auth-sessions/utils.d.ts +1 -1
  10. package/dist/commands/cli-auth-sessions/utils.js +2 -3
  11. package/dist/commands/common/browserUtils.d.ts +1 -1
  12. package/dist/commands/common/browserUtils.js +1 -1
  13. package/dist/commands/common/getFirstLineNumber.js +2 -4
  14. package/dist/commands/deploy/utils.js +1 -2
  15. package/dist/commands/init/utils.js +1 -7
  16. package/dist/commands/interface/run.js +7 -6
  17. package/dist/commands/intuned-cli/commands/attempt.command.d.ts +1 -0
  18. package/dist/commands/intuned-cli/commands/attempt.command.js +8 -0
  19. package/dist/commands/intuned-cli/commands/attempt_api.command.d.ts +1 -0
  20. package/dist/commands/intuned-cli/commands/attempt_api.command.js +40 -0
  21. package/dist/commands/intuned-cli/commands/attempt_authsession.command.d.ts +1 -0
  22. package/dist/commands/intuned-cli/commands/attempt_authsession.command.js +8 -0
  23. package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.d.ts +1 -0
  24. package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.js +24 -0
  25. package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.d.ts +1 -0
  26. package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.js +36 -0
  27. package/dist/commands/intuned-cli/commands/build.command.d.ts +1 -0
  28. package/dist/commands/intuned-cli/commands/build.command.js +12 -0
  29. package/dist/commands/intuned-cli/commands/command.d.ts +2 -0
  30. package/dist/commands/intuned-cli/commands/command.js +9 -0
  31. package/dist/commands/intuned-cli/commands/deploy.command.d.ts +1 -0
  32. package/dist/commands/intuned-cli/commands/deploy.command.js +47 -0
  33. package/dist/commands/intuned-cli/commands/helpers.d.ts +26 -0
  34. package/dist/commands/intuned-cli/commands/helpers.js +126 -0
  35. package/dist/commands/intuned-cli/commands/index.d.ts +15 -0
  36. package/dist/commands/intuned-cli/commands/index.js +170 -0
  37. package/dist/commands/intuned-cli/commands/init.command.d.ts +1 -0
  38. package/dist/commands/intuned-cli/commands/init.command.js +14 -0
  39. package/dist/commands/intuned-cli/commands/run.command.d.ts +1 -0
  40. package/dist/commands/intuned-cli/commands/run.command.js +8 -0
  41. package/dist/commands/intuned-cli/commands/run_api.command.d.ts +1 -0
  42. package/dist/commands/intuned-cli/commands/run_api.command.js +54 -0
  43. package/dist/commands/intuned-cli/commands/run_authsession.command.d.ts +21 -0
  44. package/dist/commands/intuned-cli/commands/run_authsession.command.js +13 -0
  45. package/dist/commands/intuned-cli/commands/run_authsession_create.command.d.ts +1 -0
  46. package/dist/commands/intuned-cli/commands/run_authsession_create.command.js +39 -0
  47. package/dist/commands/intuned-cli/commands/run_authsession_update.command.d.ts +1 -0
  48. package/dist/commands/intuned-cli/commands/run_authsession_update.command.js +39 -0
  49. package/dist/commands/intuned-cli/commands/run_authsession_validate.command.d.ts +1 -0
  50. package/dist/commands/intuned-cli/commands/run_authsession_validate.command.js +37 -0
  51. package/dist/commands/intuned-cli/commands/types.d.ts +21 -0
  52. package/dist/commands/intuned-cli/commands/types.js +21 -0
  53. package/dist/commands/intuned-cli/controller/api.d.ts +19 -0
  54. package/dist/commands/intuned-cli/controller/api.js +179 -0
  55. package/dist/commands/intuned-cli/controller/authSession.d.ts +32 -0
  56. package/dist/commands/intuned-cli/controller/authSession.js +295 -0
  57. package/dist/commands/intuned-cli/controller/build.d.ts +1 -0
  58. package/dist/commands/intuned-cli/controller/build.js +36 -0
  59. package/dist/commands/intuned-cli/controller/deploy.d.ts +15 -0
  60. package/dist/commands/intuned-cli/controller/deploy.js +397 -0
  61. package/dist/commands/intuned-cli/controller/index.d.ts +1 -0
  62. package/dist/commands/intuned-cli/controller/index.js +45 -0
  63. package/dist/commands/intuned-cli/controller/init.d.ts +5 -0
  64. package/dist/commands/intuned-cli/controller/init.js +139 -0
  65. package/dist/commands/intuned-cli/index.d.ts +1 -0
  66. package/dist/commands/intuned-cli/index.js +16 -0
  67. package/dist/commands/intuned-cli/main.d.ts +1 -0
  68. package/dist/commands/intuned-cli/main.js +12 -0
  69. package/dist/commands/intuned-cli/terminal.d.ts +1 -0
  70. package/dist/commands/intuned-cli/terminal.js +12 -0
  71. package/dist/commands/run-api-cli/utils.js +6 -6
  72. package/dist/common/assets/browser_scripts.js +2509 -2143
  73. package/dist/common/asyncLocalStorage/index.d.ts +1 -2
  74. package/dist/common/backendFunctions/getAuthSessionParameters.d.ts +1 -0
  75. package/dist/common/backendFunctions/getAuthSessionParameters.js +38 -0
  76. package/dist/common/cli/cliReadme.d.ts +1 -1
  77. package/dist/common/cli/cliReadme.js +14 -23
  78. package/dist/common/cli/constants.d.ts +4 -2
  79. package/dist/common/cli/constants.js +7 -3
  80. package/dist/common/cli/types.d.ts +2 -2
  81. package/dist/common/cli/utils.d.ts +5 -2
  82. package/dist/common/cli/utils.js +6 -2
  83. package/dist/common/constants.d.ts +1 -0
  84. package/dist/common/constants.js +2 -1
  85. package/dist/common/contextStorageStateHelpers.d.ts +1 -1
  86. package/dist/common/getPlaywrightConstructs.d.ts +1 -1
  87. package/dist/common/getPlaywrightConstructs.js +12 -12
  88. package/dist/common/jwtTokenManager.js +3 -5
  89. package/dist/common/runApi/errors.d.ts +1 -1
  90. package/dist/common/runApi/errors.js +5 -6
  91. package/dist/common/runApi/index.d.ts +4 -1
  92. package/dist/common/runApi/index.js +21 -21
  93. package/dist/index.d.ts +1 -1
  94. package/dist/index.js +6 -0
  95. package/dist/runtime/executionHelpers.test.js +3 -4
  96. package/dist/runtime/export.d.ts +16 -0
  97. package/dist/runtime/extendPayload.js +1 -1
  98. package/dist/runtime/extendTimeout.js +0 -7
  99. package/dist/runtime/getAuthSessionParameters.d.ts +1 -0
  100. package/dist/runtime/getAuthSessionParameters.js +20 -0
  101. package/dist/runtime/index.d.ts +1 -0
  102. package/dist/runtime/index.js +7 -0
  103. package/package.json +10 -7
  104. package/template.tsconfig.json +4 -7
@@ -0,0 +1,397 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.convertProjectToCodeTree = convertProjectToCodeTree;
7
+ exports.projectNameSchema = void 0;
8
+ exports.runDeployProject = runDeployProject;
9
+ exports.validateProjectName = exports.validateIntunedProject = void 0;
10
+ var fs = _interopRequireWildcard(require("fs-extra"));
11
+ var path = _interopRequireWildcard(require("path"));
12
+ var _minimatch = require("minimatch");
13
+ var _zod = require("zod");
14
+ var _projectExclusions = _interopRequireDefault(require("../../common/projectExclusions"));
15
+ var _constants = require("../../../common/cli/constants");
16
+ var _utils = require("../../../common/cli/utils");
17
+ var _utils2 = require("../../init/utils");
18
+ var _lodash = require("lodash");
19
+ var _uuid = require("uuid");
20
+ var _terminal = require("../terminal");
21
+ var _promises = require("timers/promises");
22
+ var _helpers = require("../commands/helpers");
23
+ var _ms = _interopRequireDefault(require("ms"));
24
+ var _build = require("./build");
25
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
26
+ 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); }
27
+ 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; }
28
+ function ignoreFilesByPattern(filePath, patterns, projectPath) {
29
+ const relativePath = path.relative(projectPath, filePath);
30
+ if (relativePath.startsWith("node_modules")) {
31
+ return true;
32
+ }
33
+ for (const pattern of patterns) {
34
+ if (!pattern || pattern.startsWith("#")) continue;
35
+ if (pattern.startsWith("!")) {
36
+ if ((0, _minimatch.minimatch)(relativePath, pattern.substring(1))) {
37
+ return false;
38
+ }
39
+ } else if ((0, _minimatch.minimatch)(relativePath, pattern)) {
40
+ return true;
41
+ }
42
+ }
43
+ return false;
44
+ }
45
+ function listFilesNotIgnored(projectPath, ignorePatterns) {
46
+ const results = [];
47
+ function traverseDirectory(dirPath) {
48
+ try {
49
+ const entries = fs.readdirSync(dirPath);
50
+ for (const entry of entries) {
51
+ const fullPath = path.join(dirPath, entry);
52
+ if (ignoreFilesByPattern(fullPath, ignorePatterns, projectPath)) {
53
+ continue;
54
+ }
55
+ try {
56
+ const stats = fs.statSync(fullPath);
57
+ if (stats.isDirectory()) {
58
+ traverseDirectory(fullPath);
59
+ } else if (stats.isFile()) {
60
+ results.push(path.relative(projectPath, fullPath));
61
+ }
62
+ } catch (error) {
63
+ (0, _terminal.terminal)(`^yWarning: Could not access ${fullPath}^:\n`);
64
+ }
65
+ }
66
+ } catch (error) {
67
+ (0, _terminal.terminal)(`^YWarning: Could not read directory ${dirPath}^:\n`);
68
+ }
69
+ }
70
+ traverseDirectory(projectPath);
71
+ return results;
72
+ }
73
+ async function convertProjectToCodeTree(projectPath) {
74
+ const filesToDeploy = listFilesNotIgnored(projectPath, _projectExclusions.default);
75
+ const filesToDeployText = " " + filesToDeploy.join("\n ");
76
+ (0, _terminal.terminal)("^CFiles to be deployed:^:\n");
77
+ (0, _terminal.terminal)(filesToDeployText + "\n");
78
+ function readDirectory(dirPath) {
79
+ const tree = {};
80
+ try {
81
+ const entries = fs.readdirSync(dirPath);
82
+ for (const entry of entries) {
83
+ const entryPath = path.join(dirPath, entry);
84
+ if (ignoreFilesByPattern(entryPath, _projectExclusions.default, projectPath)) {
85
+ continue;
86
+ }
87
+ try {
88
+ const stats = fs.statSync(entryPath);
89
+ if (stats.isFile()) {
90
+ try {
91
+ const content = fs.readFileSync(entryPath, "utf-8");
92
+ tree[entry] = {
93
+ file: {
94
+ contents: content
95
+ }
96
+ };
97
+ } catch (error) {
98
+ (0, _terminal.terminal)(`^yWarning: Could not read file ${entryPath}^:\n`);
99
+ }
100
+ } else if (stats.isDirectory()) {
101
+ const subTree = readDirectory(entryPath);
102
+ if (Object.keys(subTree).length > 0) {
103
+ tree[entry] = {
104
+ directory: subTree
105
+ };
106
+ }
107
+ }
108
+ } catch (error) {
109
+ (0, _terminal.terminal)(`^yWarning: Could not access ${entryPath}^:\n`);
110
+ }
111
+ }
112
+ } catch (error) {
113
+ (0, _terminal.terminal)(`^YWarning: Could not read directory ${dirPath}^:\n`);
114
+ }
115
+ return tree;
116
+ }
117
+ const tree = readDirectory(projectPath);
118
+ await mapToIDEParams(tree);
119
+ return tree;
120
+ }
121
+ async function runDeployProject(projectName, auth) {
122
+ const {
123
+ workspaceId,
124
+ apiKey
125
+ } = auth;
126
+ const baseUrl = (0, _utils.getBaseUrl)();
127
+ const url = `${baseUrl}/api/v1/workspace/${workspaceId}/projects/create`;
128
+ const headers = {
129
+ "x-api-key": apiKey,
130
+ "Content-Type": "application/json"
131
+ };
132
+ const projectPath = process.cwd();
133
+ const codeTree = await convertProjectToCodeTree(projectPath);
134
+ codeTree["tsconfig.json"] = {
135
+ file: {
136
+ contents: JSON.stringify(_constants.tsConfigCli, null, 2)
137
+ }
138
+ };
139
+ const deployProjectPayload = {
140
+ name: projectName,
141
+ codeTree,
142
+ isCli: true,
143
+ language: "typescript"
144
+ };
145
+ const response = await fetch(url, {
146
+ headers,
147
+ method: "POST",
148
+ body: JSON.stringify(deployProjectPayload)
149
+ });
150
+ if (!response.ok) {
151
+ if (response.status === 401) {
152
+ throw new _helpers.CLIError(`Invalid API key. Please check your API key and try again.`);
153
+ }
154
+ throw new _helpers.CLIError(`^r^+Invalid response from server\n^:^R${response.status} ${await response.text()}^:\n^r^+Project deployment failed^:\n`, {
155
+ autoColor: false
156
+ });
157
+ }
158
+ (0, _terminal.terminal)("\n");
159
+ const startTime = Date.now();
160
+ let lastCheckTime = startTime;
161
+ const spinner = await _terminal.terminal.spinner("dotSpinner");
162
+ (0, _terminal.terminal)("\n");
163
+ try {
164
+ while (true) {
165
+ await (0, _promises.setTimeout)(50);
166
+ _terminal.terminal.previousLine(1);
167
+ _terminal.terminal.column(3);
168
+ _terminal.terminal.eraseLineAfter();
169
+ const timeElapsedText = ((Date.now() - startTime) / (0, _ms.default)("1 second")).toFixed(1);
170
+ (0, _terminal.terminal)(`^cDeploying ^:^K(${timeElapsedText}s)^ \n`);
171
+ if (Date.now() - lastCheckTime < _constants.PROJECT_DEPLOY_CHECK_PERIOD) {
172
+ continue;
173
+ }
174
+ lastCheckTime = Date.now();
175
+ const {
176
+ status,
177
+ message,
178
+ projectId
179
+ } = await checkIntunedProjectDeployStatus(workspaceId, projectName, apiKey);
180
+ if (status === "pending") {
181
+ const elapsedTime = Date.now() - startTime;
182
+ if (elapsedTime > _constants.PROJECT_DEPLOY_TIMEOUT) {
183
+ throw new _helpers.CLIError(`Deployment timed out after ${Math.floor(_constants.PROJECT_DEPLOY_TIMEOUT / (0, _ms.default)("1 minute"))} minutes`);
184
+ }
185
+ continue;
186
+ }
187
+ _terminal.terminal.previousLine(1);
188
+ _terminal.terminal.eraseLine();
189
+ spinner.animate(false);
190
+ if (status === "completed") {
191
+ const url = (0, _utils.getBaseUrl)();
192
+ (0, _terminal.terminal)(`\n^g^+Project deployed successfully!^:\n`);
193
+ (0, _terminal.terminal)(`^+You can check your project on the platform:^s ^c^_${url}/projects/${projectId}/details^:\n`);
194
+ return;
195
+ }
196
+ throw new _helpers.CLIError(`^r^+An error occurred while deploying project:^:\n^R${message}^:\n^r^+Project deployment failed^:\n`);
197
+ }
198
+ } catch (e) {
199
+ spinner.animate(false);
200
+ }
201
+ }
202
+ 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, {
203
+ message: "Name cannot be a UUID"
204
+ });
205
+ const validateProjectName = projectName => {
206
+ const validation = projectNameSchema.safeParse(projectName);
207
+ if (!validation.success) {
208
+ return {
209
+ isValid: false,
210
+ errorMessage: validation.error.errors[0].message
211
+ };
212
+ }
213
+ return {
214
+ isValid: true
215
+ };
216
+ };
217
+ exports.validateProjectName = validateProjectName;
218
+ const validateIntunedProject = async () => {
219
+ const currentDirectoryToDeploy = process.cwd();
220
+ const validationSteps = [{
221
+ name: "build",
222
+ check: async () => {
223
+ try {
224
+ const buildResult = await (0, _build.runBuild)();
225
+ if (!buildResult) {
226
+ return {
227
+ isValid: false,
228
+ errorMessage: "Build failed"
229
+ };
230
+ }
231
+ return {
232
+ isValid: true
233
+ };
234
+ } catch (error) {
235
+ return {
236
+ isValid: false,
237
+ errorMessage: "Build failed"
238
+ };
239
+ }
240
+ }
241
+ }, {
242
+ name: "package.json",
243
+ check: async () => {
244
+ try {
245
+ const packageJsonPath = path.join(currentDirectoryToDeploy, "package.json");
246
+ await fs.exists(packageJsonPath);
247
+ const packageJson = JSON.parse(await fs.readFile(packageJsonPath, {
248
+ encoding: "utf-8"
249
+ }));
250
+ const userCodePlaywrightVersion = packageJson.dependencies?.playwright;
251
+ if (userCodePlaywrightVersion !== _constants.CURRENT_PLAYWRIGHT_VERSION) {
252
+ return {
253
+ isValid: false,
254
+ errorMessage: `Playwright version mismatch: expected ${_constants.CURRENT_PLAYWRIGHT_VERSION}, found ${userCodePlaywrightVersion || "none"}`
255
+ };
256
+ }
257
+ return {
258
+ isValid: true
259
+ };
260
+ } catch (error) {
261
+ return {
262
+ isValid: false,
263
+ errorMessage: "Package.json file not found or cannot be read"
264
+ };
265
+ }
266
+ }
267
+ }, {
268
+ name: "Intuned.json",
269
+ check: async () => {
270
+ try {
271
+ const intunedJsonPath = path.join(currentDirectoryToDeploy, "Intuned.json");
272
+ await fs.exists(intunedJsonPath);
273
+ return {
274
+ isValid: true
275
+ };
276
+ } catch (error) {
277
+ return {
278
+ isValid: false,
279
+ errorMessage: "Intuned.json file not found"
280
+ };
281
+ }
282
+ }
283
+ }, {
284
+ name: "api folder",
285
+ check: async () => {
286
+ try {
287
+ const apiFolderPath = path.join(currentDirectoryToDeploy, "api");
288
+ await fs.access(apiFolderPath);
289
+ return {
290
+ isValid: true
291
+ };
292
+ } catch (error) {
293
+ return {
294
+ isValid: false,
295
+ errorMessage: "API folder not found"
296
+ };
297
+ }
298
+ }
299
+ }];
300
+ for (const step of validationSteps) {
301
+ const result = await step.check();
302
+ if (!result.isValid) {
303
+ return result;
304
+ }
305
+ }
306
+ return {
307
+ isValid: true
308
+ };
309
+ };
310
+ exports.validateIntunedProject = validateIntunedProject;
311
+ const checkIntunedProjectDeployStatus = async (workspaceId, projectName, apiKey) => {
312
+ const baseUrl = (0, _utils.getBaseUrl)();
313
+ const url = `${baseUrl}/api/v1/workspace/${workspaceId}/projects/create/${projectName}/result`;
314
+ const headers = {
315
+ "x-api-key": apiKey,
316
+ "Content-Type": "application/json"
317
+ };
318
+ const response = await fetch(url, {
319
+ headers,
320
+ method: "GET"
321
+ });
322
+ if (response.status === 404) {
323
+ return {
324
+ status: "not_found",
325
+ message: "Project not found"
326
+ };
327
+ }
328
+ if (!response.ok) {
329
+ throw new Error(`Error querying deployment status ${response.status}: ${await response.text()}`);
330
+ }
331
+ const data = await response.json();
332
+ if (data.status) {
333
+ return {
334
+ status: data.status,
335
+ message: data.message,
336
+ projectId: data.projectId
337
+ };
338
+ }
339
+ return {
340
+ status: "failed",
341
+ message: `Deployment failed, please try again: ${data.message}`
342
+ };
343
+ };
344
+ async function mapToIDEParams(tree) {
345
+ if (!tree) {
346
+ return;
347
+ }
348
+ if (!tree["parameters"] || (0, _utils2._isFileNode)(tree["parameters"])) {
349
+ return;
350
+ }
351
+ const apiParametersMap = {};
352
+ const cliParameters = Object.keys(tree["parameters"].directory);
353
+ const ____testParameters = {
354
+ directory: {}
355
+ };
356
+ for (const parameterKey of cliParameters) {
357
+ const parameter = tree["parameters"].directory[parameterKey];
358
+ if ((0, _utils2._isDirectoryNode)(parameter)) {
359
+ continue;
360
+ }
361
+ if ((0, _lodash.isEmpty)(parameter.file.contents)) {
362
+ continue;
363
+ }
364
+ const parameterPayload = JSON.parse(parameter.file.contents);
365
+ if (!parameterPayload["__api-name"]) {
366
+ continue;
367
+ }
368
+ const api = parameterPayload["__api-name"];
369
+ const {
370
+ "__api-name": _,
371
+ ...parameterValue
372
+ } = parameterPayload;
373
+ const testParameter = {
374
+ name: parameterKey.replace(".json", ""),
375
+ lastUsed: false,
376
+ id: (0, _uuid.v4)(),
377
+ value: JSON.stringify(parameterValue)
378
+ };
379
+ if (!apiParametersMap[api]) {
380
+ apiParametersMap[api] = [];
381
+ }
382
+ apiParametersMap[api].push(testParameter);
383
+ }
384
+ for (const api in apiParametersMap) {
385
+ if (apiParametersMap[api].length > 0) {
386
+ apiParametersMap[api][apiParametersMap[api].length - 1].lastUsed = true;
387
+ }
388
+ ____testParameters.directory[`${api}.json`] = {
389
+ file: {
390
+ contents: JSON.stringify(apiParametersMap[api], null, 2)
391
+ }
392
+ };
393
+ }
394
+ delete tree["parameters"];
395
+ tree["____testParameters"] = ____testParameters;
396
+ return;
397
+ }
@@ -0,0 +1 @@
1
+ export declare function loadParameters(parameters: string): Promise<object | null>;
@@ -0,0 +1,45 @@
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
+ 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); }
9
+ 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; }
10
+ async function loadParameters(parameters) {
11
+ let inputData;
12
+ if (await fs.exists(parameters)) {
13
+ inputData = await loadParametersFromFile(parameters);
14
+ } else {
15
+ try {
16
+ inputData = JSON.parse(parameters);
17
+ } catch (err) {
18
+ throw new Error("Parameters must be a valid JSON string or a path to a JSON file");
19
+ }
20
+ }
21
+ return inputData;
22
+ }
23
+ async function loadParametersFromFile(parametersFile) {
24
+ if (!parametersFile) {
25
+ return {};
26
+ }
27
+ try {
28
+ const filePath = parametersFile;
29
+ await fs.access(filePath);
30
+ let inputData = null;
31
+ if (parametersFile) {
32
+ inputData = await fs.readJSON(filePath);
33
+ } else {
34
+ inputData = {};
35
+ }
36
+ return inputData;
37
+ } catch (error) {
38
+ if (error.code === "ENOENT") {
39
+ throw new Error(`Parameters file not found: ${parametersFile}`);
40
+ } else if (error instanceof SyntaxError) {
41
+ throw new Error(`Invalid JSON in parameters file: ${error.message}`);
42
+ }
43
+ throw new Error(`Error reading parameters file: ${error.message}`);
44
+ }
45
+ }
@@ -0,0 +1,5 @@
1
+ import { FileSystemTree, TemplateId } from "../../../common/cli/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,139 @@
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("../../../common/cli/types");
12
+ var _path = _interopRequireDefault(require("path"));
13
+ var _projectExclusions = _interopRequireDefault(require("../../common/projectExclusions"));
14
+ var _constants = require("../../../common/cli/constants");
15
+ var _cliReadme = require("../../../common/cli/cliReadme");
16
+ var _utils = require("../../../common/cli/utils");
17
+ var _helpers = require("../commands/helpers");
18
+ var _terminal = require("../terminal");
19
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
20
+ 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); }
21
+ 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; }
22
+ function isDirectoryNode(node) {
23
+ return node.directory !== undefined;
24
+ }
25
+ function isFileNode(node) {
26
+ return node.file !== undefined;
27
+ }
28
+ async function mountFiles(cwd, tree) {
29
+ for (const name in tree) {
30
+ const fullPath = _path.default.join(cwd, name);
31
+ const node = tree[name];
32
+ if (isDirectoryNode(node)) {
33
+ await fs.ensureDir(fullPath);
34
+ await mountFiles(fullPath, node.directory);
35
+ } else if (isFileNode(node)) {
36
+ await fs.writeFile(fullPath, node.file.contents);
37
+ }
38
+ }
39
+ }
40
+ async function checkEmptyDirectory() {
41
+ const currentDir = process.cwd();
42
+ try {
43
+ const stats = await fs.stat(currentDir);
44
+ if (!stats.isDirectory()) {
45
+ throw new _helpers.CLIError("The current path is not a directory.");
46
+ }
47
+ const files = await fs.readdir(currentDir);
48
+ const significantFiles = files.filter(file => !_projectExclusions.default.includes(file));
49
+ return significantFiles.length === 0;
50
+ } catch (error) {
51
+ if (error.code === "ENOENT") {
52
+ throw new _helpers.CLIError("The specified directory does not exist.");
53
+ }
54
+ throw error;
55
+ }
56
+ }
57
+ async function selectTemplate(templateName) {
58
+ if (templateName) {
59
+ if (!_types.templateIds.includes(templateName)) {
60
+ throw new _helpers.CLIError(`Template "${templateName}" not found.`);
61
+ }
62
+ return templateName;
63
+ }
64
+ (0, _terminal.terminal)("^+Select a template (ESC to cancel):^:\n");
65
+ const {
66
+ promise: selectedCommandPromise
67
+ } = _terminal.terminal.singleColumnMenu(_types.templateIds, {
68
+ cancelable: true
69
+ });
70
+ const selectedTemplateIndex = (await selectedCommandPromise).selectedIndex;
71
+ if (selectedTemplateIndex === undefined) {
72
+ throw new _helpers.CLIError("^y^+Project initialization cancelled.^:\n", {
73
+ autoColor: false
74
+ });
75
+ }
76
+ return _types.templateIds[selectedTemplateIndex];
77
+ }
78
+ async function scaffoldProject(templateId, isTargetDirectoryEmpty) {
79
+ if (!isTargetDirectoryEmpty) {
80
+ (0, _terminal.terminal)("^+The current directory is not empty. Do you want to proceed and override files?^: (y/N)");
81
+ const {
82
+ promise
83
+ } = _terminal.terminal.yesOrNo({
84
+ no: ["n", "ENTER", "ESCAPE"],
85
+ yes: ["y"],
86
+ echoNo: " no\n",
87
+ echoYes: " yes\n"
88
+ });
89
+ const confirm = await promise;
90
+ if (!confirm) {
91
+ throw new _helpers.CLIError("^y^+Project initialization cancelled^:\n", {
92
+ autoColor: false
93
+ });
94
+ }
95
+ }
96
+ const cwd = process.cwd();
97
+ (0, _terminal.terminal)(`^c🚀 Initializing ^:^+${templateId}^:^c project...\n`);
98
+ const template = await fetchProjectTemplate(templateId);
99
+ (0, _terminal.terminal)(`^c🔨 Creating project files...^:\n`);
100
+ const codeTree = template;
101
+ await prepareCLITemplate(codeTree);
102
+ await mountFiles(cwd, codeTree);
103
+ (0, _terminal.terminal)(`^g^+🎉 Project initialized successfully!^ ^GRun ^:^+yarn^:^G to install dependencies and start coding!\n`);
104
+ }
105
+ async function fetchProjectTemplate(templateId) {
106
+ const baseUrl = (0, _utils.getBaseUrl)();
107
+ const url = `${baseUrl}/api/templates/${templateId}`;
108
+ const response = await fetch(url);
109
+ if (!response.ok) {
110
+ throw new _helpers.CLIError(`^r^+Error fetching template:\n^:^R${response.statusText} ${response.status}\n^r^+Failed to initialize project^:\n`, {
111
+ autoColor: false
112
+ });
113
+ }
114
+ const data = await response.json();
115
+ if (!data) {
116
+ throw new _helpers.CLIError("Error fetching template: Template not found");
117
+ }
118
+ return data.template;
119
+ }
120
+ async function prepareCLITemplate(codeTree) {
121
+ codeTree["parameters"] = {
122
+ directory: {}
123
+ };
124
+ codeTree["tsconfig.json"] = {
125
+ file: {
126
+ contents: JSON.stringify(_constants.tsConfigCli, null, 2)
127
+ }
128
+ };
129
+ if (isFileNode(codeTree["package.json"]) && codeTree["package.json"].file) {
130
+ const packageJson = JSON.parse(codeTree["package.json"].file.contents);
131
+ packageJson.scripts = _constants.userCLIScripts;
132
+ codeTree["package.json"].file.contents = JSON.stringify(packageJson, null, 2);
133
+ }
134
+ codeTree["README.md"] = {
135
+ file: {
136
+ contents: _cliReadme.cliReadme
137
+ }
138
+ };
139
+ }
@@ -0,0 +1 @@
1
+ export * from "./commands";
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _commands = require("./commands");
7
+ Object.keys(_commands).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _commands[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _commands[key];
14
+ }
15
+ });
16
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ var _dotenv = _interopRequireDefault(require("dotenv"));
4
+ var _commands = require("./commands");
5
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
6
+ _dotenv.default.config({
7
+ path: `.env`
8
+ });
9
+ _commands.program.configureHelp({
10
+ sortSubcommands: true
11
+ });
12
+ _commands.program.parse(process.argv);
@@ -0,0 +1 @@
1
+ export declare const terminal: import("terminal-kit/Terminal");
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.terminal = void 0;
7
+ var _terminalKit = require("terminal-kit");
8
+ const terminal = exports.terminal = (0, _terminalKit.createTerminal)({
9
+ appId: "Intuned CLI",
10
+ appName: "Intuned CLI",
11
+ stdout: process.stderr
12
+ });
@@ -62,10 +62,10 @@ async function writeResultToFile(runId, result, payloadToAppend) {
62
62
  }
63
63
  async function runApiViaCLI(apiName, inputData, options) {
64
64
  let authSessionPathToUse = null;
65
- if (options !== null && options !== void 0 && options.authSession) {
65
+ if (options?.authSession) {
66
66
  const {
67
67
  authSessionInstanceStoragePath
68
- } = await (0, _utils.retrieveAuthSessionInstance)(options === null || options === void 0 ? void 0 : options.authSession, true);
68
+ } = await (0, _utils.retrieveAuthSessionInstance)(options?.authSession, true);
69
69
  authSessionPathToUse = authSessionInstanceStoragePath;
70
70
  }
71
71
  if (authSessionPathToUse) {
@@ -82,17 +82,17 @@ async function runApiViaCLI(apiName, inputData, options) {
82
82
  }
83
83
  const {
84
84
  metadata
85
- } = await (0, _utils.retrieveAuthSessionInstance)(options === null || options === void 0 ? void 0 : options.authSession);
86
- if ((metadata === null || metadata === void 0 ? void 0 : metadata.authSessionType) === "MANUAL") {
85
+ } = await (0, _utils.retrieveAuthSessionInstance)(options?.authSession);
86
+ if (metadata?.authSessionType === "MANUAL") {
87
87
  throw new Error("Expired Auth session is recorder-based, please provide a new one or refresh it manually");
88
88
  }
89
- const authSessionInput = (metadata === null || metadata === void 0 ? void 0 : metadata.authSessionInput) ?? {};
89
+ const authSessionInput = metadata?.authSessionInput ?? {};
90
90
  try {
91
91
  const refresehAuthSessionInstance = await (0, _utils.runCreateApiViaCLI)(authSessionInput);
92
92
  if (!refresehAuthSessionInstance) {
93
93
  throw new Error("Failed to refresh auth session");
94
94
  }
95
- await (0, _utils.storeAuthSessionInstance)(refresehAuthSessionInstance, options === null || options === void 0 ? void 0 : options.authSession, authSessionInput);
95
+ await (0, _utils.storeAuthSessionInstance)(refresehAuthSessionInstance, options?.authSession, authSessionInput);
96
96
  const checkResult = await (0, _utils.runCheckApiViaCLI)(authSessionPathToUse);
97
97
  if (!checkResult) {
98
98
  throw new Error("Failed to refresh auth session");