@intuned/runtime-dev 1.2.0-cli.1 → 1.2.0-cli.10

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 (87) hide show
  1. package/dist/commands/api/run.js +2 -1
  2. package/dist/commands/intuned-cli/commands/attempt_api.command.js +1 -1
  3. package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.js +1 -1
  4. package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.js +1 -1
  5. package/dist/commands/intuned-cli/commands/build.command.js +1 -1
  6. package/dist/commands/intuned-cli/commands/deploy.command.js +3 -4
  7. package/dist/commands/intuned-cli/commands/init.command.js +1 -1
  8. package/dist/commands/intuned-cli/commands/run_api.command.js +1 -1
  9. package/dist/commands/intuned-cli/commands/run_authsession.command.d.ts +0 -1
  10. package/dist/commands/intuned-cli/commands/run_authsession_create.command.js +1 -1
  11. package/dist/commands/intuned-cli/commands/run_authsession_update.command.js +1 -1
  12. package/dist/commands/intuned-cli/commands/run_authsession_validate.command.js +1 -1
  13. package/dist/{common/cli/constants.d.ts → commands/intuned-cli/constants/index.d.ts} +2 -4
  14. package/dist/{common/cli/constants.js → commands/intuned-cli/constants/index.js} +22 -5
  15. package/dist/commands/intuned-cli/constants/readme.d.ts +1 -0
  16. package/dist/{common/cli/cliReadme.js → commands/intuned-cli/constants/readme.js} +13 -15
  17. package/dist/commands/intuned-cli/controller/__test__/api.test.js +280 -0
  18. package/dist/commands/intuned-cli/controller/__test__/authSession.test.js +676 -0
  19. package/dist/commands/intuned-cli/controller/api.d.ts +25 -0
  20. package/dist/commands/intuned-cli/controller/api.js +35 -36
  21. package/dist/commands/intuned-cli/controller/authSession.d.ts +176 -10
  22. package/dist/commands/intuned-cli/controller/authSession.js +125 -125
  23. package/dist/commands/intuned-cli/controller/build.js +1 -1
  24. package/dist/commands/intuned-cli/controller/deploy.d.ts +1 -1
  25. package/dist/commands/intuned-cli/controller/deploy.js +47 -32
  26. package/dist/commands/intuned-cli/controller/index.js +5 -4
  27. package/dist/commands/intuned-cli/controller/init.d.ts +1 -1
  28. package/dist/commands/intuned-cli/controller/init.js +12 -15
  29. package/dist/commands/intuned-cli/helpers/api.d.ts +3 -0
  30. package/dist/commands/intuned-cli/helpers/api.js +19 -0
  31. package/dist/commands/intuned-cli/helpers/auth.d.ts +41 -0
  32. package/dist/commands/intuned-cli/helpers/auth.js +129 -0
  33. package/dist/{common/cli/utils.d.ts → commands/intuned-cli/helpers/backend.d.ts} +0 -1
  34. package/dist/commands/intuned-cli/helpers/backend.js +26 -0
  35. package/dist/commands/intuned-cli/helpers/context.d.ts +3 -0
  36. package/dist/commands/intuned-cli/helpers/context.js +33 -0
  37. package/dist/commands/intuned-cli/helpers/errors.d.ts +14 -0
  38. package/dist/commands/intuned-cli/helpers/errors.js +55 -0
  39. package/dist/commands/intuned-cli/helpers/index.d.ts +10 -0
  40. package/dist/commands/intuned-cli/helpers/index.js +115 -0
  41. package/dist/commands/intuned-cli/helpers/intunedJson.d.ts +1 -0
  42. package/dist/{common/cli/utils.js → commands/intuned-cli/helpers/intunedJson.js} +0 -20
  43. package/dist/commands/intuned-cli/helpers/proxy.d.ts +5 -0
  44. package/dist/commands/intuned-cli/helpers/proxy.js +23 -0
  45. package/dist/commands/intuned-cli/helpers/terminal.d.ts +5 -0
  46. package/dist/commands/intuned-cli/{terminal.js → helpers/terminal.js} +3 -2
  47. package/dist/commands/intuned-cli/helpers/timeout.d.ts +1 -0
  48. package/dist/commands/intuned-cli/helpers/timeout.js +23 -0
  49. package/dist/commands/intuned-cli/helpers/validation.d.ts +2 -0
  50. package/dist/commands/intuned-cli/helpers/validation.js +12 -0
  51. package/dist/commands/intuned-cli/main.js +4 -1
  52. package/dist/{common/cli → commands/intuned-cli}/types.d.ts +1 -32
  53. package/dist/common/runApi/types.d.ts +140 -9
  54. package/dist/common/runApi/types.js +28 -27
  55. package/package.json +2 -7
  56. package/tsconfig.json +2 -1
  57. package/bin/check-auth-session +0 -3
  58. package/bin/cli-build +0 -3
  59. package/bin/create-auth-session +0 -3
  60. package/bin/deploy +0 -3
  61. package/bin/init +0 -3
  62. package/bin/run-api +0 -3
  63. package/dist/commands/cli-auth-sessions/check.d.ts +0 -2
  64. package/dist/commands/cli-auth-sessions/check.js +0 -40
  65. package/dist/commands/cli-auth-sessions/create.d.ts +0 -2
  66. package/dist/commands/cli-auth-sessions/create.js +0 -53
  67. package/dist/commands/cli-auth-sessions/utils.d.ts +0 -28
  68. package/dist/commands/cli-auth-sessions/utils.js +0 -284
  69. package/dist/commands/cli-build/cli-build.d.ts +0 -2
  70. package/dist/commands/cli-build/cli-build.js +0 -20
  71. package/dist/commands/deploy/deploy.d.ts +0 -2
  72. package/dist/commands/deploy/deploy.js +0 -47
  73. package/dist/commands/deploy/utils.d.ts +0 -16
  74. package/dist/commands/deploy/utils.js +0 -407
  75. package/dist/commands/init/init.d.ts +0 -2
  76. package/dist/commands/init/init.js +0 -22
  77. package/dist/commands/init/utils.d.ts +0 -11
  78. package/dist/commands/init/utils.js +0 -175
  79. package/dist/commands/intuned-cli/commands/helpers.d.ts +0 -26
  80. package/dist/commands/intuned-cli/commands/helpers.js +0 -134
  81. package/dist/commands/intuned-cli/terminal.d.ts +0 -1
  82. package/dist/commands/run-api-cli/run-api.d.ts +0 -2
  83. package/dist/commands/run-api-cli/run-api.js +0 -57
  84. package/dist/commands/run-api-cli/utils.d.ts +0 -9
  85. package/dist/commands/run-api-cli/utils.js +0 -144
  86. package/dist/common/cli/cliReadme.d.ts +0 -1
  87. /package/dist/{common/cli → commands/intuned-cli}/types.js +0 -0
@@ -1,407 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.convertProjectToCodeTree = convertProjectToCodeTree;
7
- exports.deployProject = deployProject;
8
- exports.validateProjectName = exports.validateIntunedProject = exports.runBuild = void 0;
9
- var fs = _interopRequireWildcard(require("fs-extra"));
10
- var path = _interopRequireWildcard(require("path"));
11
- var _chalk = _interopRequireDefault(require("chalk"));
12
- var _minimatch = require("minimatch");
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");
20
- var _lodash = require("lodash");
21
- var _uuid = require("uuid");
22
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
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
- 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;
114
- }
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) {
121
- const {
122
- workspaceId,
123
- apiKey
124
- } = auth;
125
- const baseUrl = (0, _utils.getBaseUrl)();
126
- const url = `${baseUrl}/api/v1/workspace/${workspaceId}/projects/create`;
127
- const headers = {
128
- "x-api-key": apiKey,
129
- "Content-Type": "application/json"
130
- };
131
- const projectPath = process.cwd();
132
- const codeTree = await convertProjectToCodeTree(projectPath);
133
- codeTree["tsconfig.json"] = {
134
- file: {
135
- contents: JSON.stringify(_constants.tsConfigCli, null, 2)
136
- }
137
- };
138
- const deployProjectPayload = {
139
- name: projectName,
140
- codeTree,
141
- isCli: true,
142
- language: "typescript"
143
- };
144
- const response = await fetch(url, {
145
- headers,
146
- method: "POST",
147
- body: JSON.stringify(deployProjectPayload)
148
- });
149
- if (!response.ok) {
150
- if (response.status === 401) {
151
- throw new Error(`Invalid API key. Please check your API key and try again.`);
152
- }
153
- throw new Error(`Error deploying project`);
154
- }
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
- }
188
- 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);
193
- if (!validation.success) {
194
- return {
195
- isValid: false,
196
- errorMessage: validation.error.errors[0].message
197
- };
198
- }
199
- return {
200
- isValid: true
201
- };
202
- };
203
- exports.validateProjectName = validateProjectName;
204
- const validateIntunedProject = async () => {
205
- const currentDirectoryToDeploy = process.cwd();
206
- const validationSteps = [{
207
- name: "build",
208
- check: async () => {
209
- try {
210
- const buildResult = await runBuild();
211
- if (!buildResult) {
212
- return {
213
- isValid: false,
214
- errorMessage: "Build failed"
215
- };
216
- }
217
- return {
218
- isValid: true
219
- };
220
- } catch (error) {
221
- return {
222
- isValid: false,
223
- errorMessage: "Build failed"
224
- };
225
- }
226
- }
227
- }, {
228
- name: "package.json",
229
- check: async () => {
230
- try {
231
- const packageJsonPath = path.join(currentDirectoryToDeploy, "package.json");
232
- await fs.exists(packageJsonPath);
233
- const packageJson = JSON.parse(await fs.readFile(packageJsonPath, {
234
- encoding: "utf-8"
235
- }));
236
- const userCodePlaywrightVersion = packageJson.dependencies?.playwright;
237
- if (userCodePlaywrightVersion !== _constants.CURRENT_PLAYWRIGHT_VERSION) {
238
- return {
239
- isValid: false,
240
- errorMessage: `Playwright version mismatch: expected ${_constants.CURRENT_PLAYWRIGHT_VERSION}, found ${userCodePlaywrightVersion || "none"}`
241
- };
242
- }
243
- return {
244
- isValid: true
245
- };
246
- } catch (error) {
247
- return {
248
- isValid: false,
249
- errorMessage: "Package.json file not found or cannot be read"
250
- };
251
- }
252
- }
253
- }, {
254
- name: "Intuned.json",
255
- check: async () => {
256
- try {
257
- const intunedJsonPath = path.join(currentDirectoryToDeploy, "Intuned.json");
258
- await fs.exists(intunedJsonPath);
259
- return {
260
- isValid: true
261
- };
262
- } catch (error) {
263
- return {
264
- isValid: false,
265
- errorMessage: "Intuned.json file not found"
266
- };
267
- }
268
- }
269
- }, {
270
- name: "api folder",
271
- check: async () => {
272
- try {
273
- const apiFolderPath = path.join(currentDirectoryToDeploy, "api");
274
- await fs.access(apiFolderPath);
275
- return {
276
- isValid: true
277
- };
278
- } catch (error) {
279
- return {
280
- isValid: false,
281
- errorMessage: "API folder not found"
282
- };
283
- }
284
- }
285
- }];
286
- for (const step of validationSteps) {
287
- const result = await step.check();
288
- if (!result.isValid) {
289
- return result;
290
- }
291
- }
292
- return {
293
- isValid: true
294
- };
295
- };
296
- exports.validateIntunedProject = validateIntunedProject;
297
- 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
- }
326
- return {
327
- status: "failed",
328
- message: `Deployment failed, please try again: ${data.message}`
329
- };
330
- } catch (e) {
331
- throw new Error(`Error during deployment`);
332
- }
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);
340
- }
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;
351
- }
352
- };
353
- exports.runBuild = runBuild;
354
- async function mapToIDEParams(tree) {
355
- if (!tree) {
356
- return;
357
- }
358
- if (!tree["parameters"] || (0, _utils2._isFileNode)(tree["parameters"])) {
359
- return;
360
- }
361
- const apiParametersMap = {};
362
- const cliParameters = Object.keys(tree["parameters"].directory);
363
- const ____testParameters = {
364
- directory: {}
365
- };
366
- for (const parameterKey of cliParameters) {
367
- const parameter = tree["parameters"].directory[parameterKey];
368
- if ((0, _utils2._isDirectoryNode)(parameter)) {
369
- continue;
370
- }
371
- if ((0, _lodash.isEmpty)(parameter.file.contents)) {
372
- continue;
373
- }
374
- const parameterPayload = JSON.parse(parameter.file.contents);
375
- if (!parameterPayload["__api-name"]) {
376
- continue;
377
- }
378
- const api = parameterPayload["__api-name"];
379
- const {
380
- "__api-name": _,
381
- ...parameterValue
382
- } = parameterPayload;
383
- const testParameter = {
384
- name: parameterKey.replace(".json", ""),
385
- lastUsed: false,
386
- id: (0, _uuid.v4)(),
387
- value: JSON.stringify(parameterValue)
388
- };
389
- if (!apiParametersMap[api]) {
390
- apiParametersMap[api] = [];
391
- }
392
- apiParametersMap[api].push(testParameter);
393
- }
394
- for (const api in apiParametersMap) {
395
- if (apiParametersMap[api].length > 0) {
396
- apiParametersMap[api][apiParametersMap[api].length - 1].lastUsed = true;
397
- }
398
- ____testParameters.directory[`${api}.json`] = {
399
- file: {
400
- contents: JSON.stringify(apiParametersMap[api], null, 2)
401
- }
402
- };
403
- }
404
- delete tree["parameters"];
405
- tree["____testParameters"] = ____testParameters;
406
- return;
407
- }
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
@@ -1,22 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
-
4
- var _commander = require("commander");
5
- var _chalk = _interopRequireDefault(require("chalk"));
6
- var _dotenv = _interopRequireDefault(require("dotenv"));
7
- var _utils = require("./utils");
8
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
- _dotenv.default.config({
10
- path: `.env`
11
- });
12
- _commander.program.description("Initialize a new Intuned project from a template").argument("[template-name]", "Name of the template to use").action(async templateName => {
13
- try {
14
- const template = await (0, _utils.selectTemplate)(templateName);
15
- const isTargetDirectoryEmpty = await (0, _utils.checkEmptyDirectory)();
16
- await (0, _utils.scaffoldProject)(template, isTargetDirectoryEmpty);
17
- } catch (error) {
18
- console.error(_chalk.default.red(`\n${error.message}`));
19
- process.exit(1);
20
- }
21
- });
22
- _commander.program.parse(process.argv);
@@ -1,11 +0,0 @@
1
- import { DirectoryNode, FileNode, FileSystemTree } from "../../common/cli/types";
2
- export declare function _isDirectoryNode(node: DirectoryNode | FileNode): node is DirectoryNode;
3
- export declare function _isFileNode(node: DirectoryNode | FileNode): node is FileNode;
4
- export declare function mountFiles(cwd: string, tree: FileSystemTree): Promise<void>;
5
- export declare function checkEmptyDirectory(): Promise<boolean>;
6
- export declare function getAuthCredentials(options: any): {
7
- workspaceId: any;
8
- apiKey: any;
9
- };
10
- export declare function selectTemplate(templateName: any): Promise<any>;
11
- export declare function scaffoldProject(templateId: string, isTargetDirectoryEmpty: boolean): Promise<void>;
@@ -1,175 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports._isDirectoryNode = _isDirectoryNode;
7
- exports._isFileNode = _isFileNode;
8
- exports.checkEmptyDirectory = checkEmptyDirectory;
9
- exports.getAuthCredentials = getAuthCredentials;
10
- exports.mountFiles = mountFiles;
11
- exports.scaffoldProject = scaffoldProject;
12
- exports.selectTemplate = selectTemplate;
13
- var fs = _interopRequireWildcard(require("fs-extra"));
14
- var _types = require("../../common/cli/types");
15
- var _chalk = _interopRequireDefault(require("chalk"));
16
- var _inquirer = _interopRequireDefault(require("inquirer"));
17
- var _path = _interopRequireDefault(require("path"));
18
- var _projectExclusions = _interopRequireDefault(require("../common/projectExclusions"));
19
- var _constants = require("../../common/cli/constants");
20
- var _cliReadme = require("../../common/cli/cliReadme");
21
- var _utils = require("../../common/cli/utils");
22
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
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
- 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
- function _isDirectoryNode(node) {
26
- return node.directory !== undefined;
27
- }
28
- function _isFileNode(node) {
29
- return node.file !== undefined;
30
- }
31
- async function mountFiles(cwd, tree) {
32
- for (const name in tree) {
33
- const fullPath = _path.default.join(cwd, name);
34
- const node = tree[name];
35
- if (_isDirectoryNode(node)) {
36
- await fs.ensureDir(fullPath);
37
- await mountFiles(fullPath, node.directory);
38
- } else if (_isFileNode(node)) {
39
- await fs.writeFile(fullPath, node.file.contents);
40
- }
41
- }
42
- }
43
- async function checkEmptyDirectory() {
44
- const currentDir = process.cwd();
45
- try {
46
- const stats = await fs.stat(currentDir);
47
- if (!stats.isDirectory()) {
48
- throw new Error("The current path is not a directory.");
49
- }
50
- const files = await fs.readdir(currentDir);
51
- const significantFiles = files.filter(file => !_projectExclusions.default.includes(file));
52
- return significantFiles.length === 0;
53
- } catch (error) {
54
- if (error.code === "ENOENT") {
55
- throw new Error("The specified directory does not exist.");
56
- }
57
- throw error;
58
- }
59
- }
60
- function getAuthCredentials(options) {
61
- const workspaceId = options.workspaceId || process.env.INTUNED_WORKSPACE_ID;
62
- const apiKey = options.apiKey || process.env.INTUNED_API_KEY;
63
- const missingAuth = [];
64
- if (!workspaceId) {
65
- missingAuth.push({
66
- type: "input",
67
- name: "workspaceId",
68
- message: "Enter your Intuned workspace ID:",
69
- validate: input => input.trim() !== "" ? true : "Workspace ID is required"
70
- });
71
- }
72
- if (!apiKey) {
73
- missingAuth.push({
74
- type: "password",
75
- name: "apiKey",
76
- message: "Enter your Intuned API key:",
77
- mask: "*",
78
- validate: input => input.trim() !== "" ? true : "API key is required"
79
- });
80
- }
81
- if (missingAuth.length) {
82
- throw new Error(`Authentication failed: Missing ${missingAuth.join(" and ")}.\n\n` + `To fix this issue:\n\n` + `1. For workspaceId:\n` + ` - Add it to your intuned.json file under the "workspaceId" property\n` + ` - OR provide via command line: --workspace-id YOUR_WORKSPACE_ID\n` + ` - See how to get your workspaceId: https://docs.intunedhq.com/docs/guides/platform/how-to-get-a-workspace-id\n\n` + `2. For API key:\n` + ` - Include in your .env file INTUNED_API_KEY=your_api_key_here \n` + ` - OR provide via command line: --api-key YOUR_API_KEY\n\n` + `Run commands from the project root directory where intuned.json is located.`);
83
- }
84
- return {
85
- workspaceId,
86
- apiKey
87
- };
88
- }
89
- async function selectTemplate(templateName) {
90
- if (templateName) {
91
- const validTemplate = _types.templateIds.find(t => t === templateName);
92
- if (!validTemplate) {
93
- console.log(_chalk.default.yellow(`\n⚠️ Template "${templateName}" not found.`));
94
- } else {
95
- return templateName;
96
- }
97
- }
98
- console.log(_chalk.default.yellow("\n📋 Select a Template"));
99
- const {
100
- template
101
- } = await _inquirer.default.prompt([{
102
- type: "list",
103
- name: "template",
104
- message: "Which template would you like to use?",
105
- choices: _types.templateIds,
106
- loop: false
107
- }]);
108
- return template;
109
- }
110
- async function scaffoldProject(templateId, isTargetDirectoryEmpty) {
111
- if (!isTargetDirectoryEmpty) {
112
- const {
113
- confirm
114
- } = await _inquirer.default.prompt([{
115
- type: "confirm",
116
- name: "confirm",
117
- message: `The current directory is not empty. Do you want to proceed and override files?`,
118
- default: false,
119
- choices: [{
120
- name: "Yes,",
121
- value: true
122
- }, {
123
- name: "No",
124
- value: false
125
- }]
126
- }]);
127
- if (!confirm) {
128
- throw new Error("Project initialization cancelled");
129
- }
130
- }
131
- const cwd = process.cwd();
132
- console.log(_chalk.default.cyan(`\n🚀 Initializing ${_chalk.default.bold(templateId)} project...\n`));
133
- console.log(_chalk.default.cyan("📦 Fetching template..."));
134
- const template = await fetchProjectTemplate(templateId);
135
- console.log(_chalk.default.green(`✓ Template "${templateId}" fetched successfully`));
136
- console.log(_chalk.default.cyan("🔨 Creating project files..."));
137
- const codeTree = template;
138
- await prepareCLITemplate(codeTree);
139
- await mountFiles(cwd, codeTree);
140
- console.log(_chalk.default.green("✓ Project files created"));
141
- console.log(_chalk.default.cyan(`\n🎉 Project initialized successfully!`), _chalk.default.yellow(`\n\nRun ${_chalk.default.bold("yarn")} to install dependencies and start coding!`));
142
- }
143
- async function fetchProjectTemplate(templateId) {
144
- const baseUrl = (0, _utils.getBaseUrl)();
145
- const url = `${baseUrl}/api/templates/${templateId}`;
146
- const response = await fetch(url);
147
- if (!response.ok) {
148
- throw new Error(`Error fetching template: ${response.statusText} (${response.status})`);
149
- }
150
- const data = await response.json();
151
- if (!data) {
152
- throw new Error("Template not found");
153
- }
154
- return data.template;
155
- }
156
- async function prepareCLITemplate(codeTree) {
157
- codeTree["parameters"] = {
158
- directory: {}
159
- };
160
- codeTree["tsconfig.json"] = {
161
- file: {
162
- contents: JSON.stringify(_constants.tsConfigCli, null, 2)
163
- }
164
- };
165
- if (_isFileNode(codeTree["package.json"]) && codeTree["package.json"].file) {
166
- const packageJson = JSON.parse(codeTree["package.json"].file.contents);
167
- packageJson.scripts = _constants.userCLIScripts;
168
- codeTree["package.json"].file.contents = JSON.stringify(packageJson, null, 2);
169
- }
170
- codeTree["README.md"] = {
171
- file: {
172
- contents: _cliReadme.cliReadme
173
- }
174
- };
175
- }
@@ -1,26 +0,0 @@
1
- import { z } from "zod";
2
- import { API_FOLDER_NAME, AUTH_SESSIONS_FOLDER_NAME } from "../../../common/constants";
3
- export declare class CLIError extends Error {
4
- autoColor: boolean;
5
- constructor(message: string, options?: {
6
- autoColor?: boolean;
7
- });
8
- }
9
- export declare class CLIAssertionError extends CLIError {
10
- constructor(message: string, options?: {
11
- autoColor?: boolean;
12
- });
13
- }
14
- export declare function logInvalidInput(result: z.SafeParseError<unknown>): void;
15
- export declare function assertAuthEnabled(): Promise<void>;
16
- export declare function assertAuthConsistent(authSession: string | undefined): Promise<void>;
17
- export declare function withErrorLogging<T extends any[]>(fn: (...args: T) => Promise<unknown>): (...args: T) => Promise<never>;
18
- export declare function parseUrlProxy(proxyUrl: string): {
19
- password: string;
20
- username: string;
21
- server: string;
22
- } | undefined;
23
- export declare function withTimeout<R, P extends any[]>(fn: (...args: P) => Promise<R>, timeout: number): (...args: P) => Promise<R>;
24
- export declare function withCLIContext<R, P extends any[]>(fn: (...args: P) => Promise<R>): (...args: P) => Promise<R>;
25
- export declare function assertApiFileExists(dirname: typeof AUTH_SESSIONS_FOLDER_NAME, api: "create" | "check"): Promise<void>;
26
- export declare function assertApiFileExists(dirname: typeof API_FOLDER_NAME, api: string): Promise<void>;