@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
@@ -0,0 +1 @@
1
+ export declare const runBuild: () => Promise<boolean>;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.runBuild = void 0;
7
+ var fs = _interopRequireWildcard(require("fs-extra"));
8
+ var path = _interopRequireWildcard(require("path"));
9
+ var _child_process = require("child_process");
10
+ var _util = require("util");
11
+ var _terminal = require("../helpers/terminal");
12
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
13
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
14
+ const execPromise = (0, _util.promisify)(_child_process.exec);
15
+ const runBuild = async () => {
16
+ const distPath = path.join(process.cwd(), "dist");
17
+ if (await fs.exists(distPath)) {
18
+ await fs.remove(distPath);
19
+ }
20
+ const buildCommand = "tsc";
21
+ try {
22
+ await execPromise(buildCommand);
23
+ (0, _terminal.terminal)(`^g^+✨ Build completed successfully!^:\n`);
24
+ return true;
25
+ } catch (error) {
26
+ (0, _terminal.terminal)(`^r^+An error occurred during the build process:^:\n`);
27
+ if ("stdout" in error) {
28
+ (0, _terminal.terminal)(`${error.stdout}\n`);
29
+ } else {
30
+ (0, _terminal.terminal)(`^${error.message}^:\n`);
31
+ }
32
+ (0, _terminal.terminal)(`^r^+Build failed^:\n`);
33
+ return false;
34
+ }
35
+ };
36
+ exports.runBuild = runBuild;
@@ -0,0 +1,4 @@
1
+ import { z } from "zod";
2
+ import type { AuthCredentials } from "../types";
3
+ export declare function runDeployProject(projectName: string, auth: AuthCredentials): Promise<void>;
4
+ export declare const projectNameSchema: z.ZodEffects<z.ZodString, string, string>;
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.projectNameSchema = void 0;
7
+ exports.runDeployProject = runDeployProject;
8
+ var _zod = require("zod");
9
+ var _constants = require("../constants");
10
+ var _helpers = require("../helpers");
11
+ var _terminal = require("../helpers/terminal");
12
+ var _promises = require("timers/promises");
13
+ var _ms = _interopRequireDefault(require("ms"));
14
+ var _save = require("./save");
15
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
16
+ async function runDeployProject(projectName, auth) {
17
+ await (0, _save.runSaveProject)(projectName, auth);
18
+ const {
19
+ workspaceId,
20
+ apiKey
21
+ } = auth;
22
+ const baseUrl = (0, _helpers.getBaseUrl)();
23
+ const url = `${baseUrl}/api/v1/workspace/${workspaceId}/projects/${projectName}/deploy`;
24
+ const headers = {
25
+ "x-api-key": apiKey,
26
+ "Content-Type": "application/json"
27
+ };
28
+ const response = await fetch(url, {
29
+ headers,
30
+ method: "POST"
31
+ });
32
+ if (!response.ok) {
33
+ if (response.status === 401) {
34
+ throw new _helpers.CLIError(`Invalid API key. Please check your API key and try again.`);
35
+ }
36
+ throw new _helpers.CLIError(`^r^+Invalid response from server\n^:^R${response.status} ${await response.text()}^:\n^r^+Project deployment failed^:\n`, {
37
+ autoColor: false
38
+ });
39
+ }
40
+ (0, _terminal.terminal)("\n");
41
+ const startTime = Date.now();
42
+ const timeElapsedText = () => ((Date.now() - startTime) / (0, _ms.default)("1 second")).toFixed(1);
43
+ function* getSpinnerGenerator() {
44
+ while (true) {
45
+ yield* "⠙⠹⠸⠼⠴⠦⠧⠇";
46
+ }
47
+ }
48
+ const spinnerGen = getSpinnerGenerator();
49
+ let updateSpinnerInterval = null;
50
+ if (_terminal.terminalStdout.isTTY) {
51
+ updateSpinnerInterval = setInterval(() => {
52
+ _terminal.terminal.previousLine(1);
53
+ _terminal.terminal.column(0);
54
+ _terminal.terminal.eraseLineAfter();
55
+ (0, _terminal.terminal)(`${spinnerGen.next().value} ^cDeploying ^:^K(${timeElapsedText()}s)^ \n`);
56
+ }, 50);
57
+ (0, _terminal.terminal)("\n");
58
+ } else {
59
+ (0, _terminal.terminal)(`^cDeploying ^:\n`);
60
+ }
61
+ try {
62
+ while (true) {
63
+ await (0, _promises.setTimeout)(_constants.PROJECT_DEPLOY_CHECK_PERIOD);
64
+ if (!_terminal.terminalStdout.isTTY) {
65
+ (0, _terminal.terminal)(`^cDeploying ^:^K(${timeElapsedText()}s)^ \n`);
66
+ }
67
+ const {
68
+ status,
69
+ message,
70
+ projectId,
71
+ ...rest
72
+ } = await checkIntunedProjectDeployStatus(workspaceId, projectName, apiKey);
73
+ if (status === "pending") {
74
+ const elapsedTime = Date.now() - startTime;
75
+ if (elapsedTime > _constants.PROJECT_DEPLOY_TIMEOUT) {
76
+ throw new _helpers.CLIError(`Deployment timed out after ${Math.floor(_constants.PROJECT_DEPLOY_TIMEOUT / (0, _ms.default)("1 minute"))} minutes`);
77
+ }
78
+ continue;
79
+ }
80
+ _terminal.terminal.previousLine(1);
81
+ _terminal.terminal.eraseLine();
82
+ if (updateSpinnerInterval) {
83
+ clearTimeout(updateSpinnerInterval);
84
+ }
85
+ if (status === "completed") {
86
+ const url = (0, _helpers.getBaseUrl)();
87
+ (0, _terminal.terminal)(`\n^g^+Project deployed successfully!^:\n`);
88
+ (0, _terminal.terminal)(`^+You can check your project on the platform:^s ^c^_${url}/projects/${projectId}/details^:\n`);
89
+ return;
90
+ }
91
+ let errorMessage = `^r^+An error occurred while deploying project:^:\n^R${message}^:\n`;
92
+ if (rest.reason) {
93
+ errorMessage += `^r^+Reason:^:\n^R${rest.reason}^:\n`;
94
+ }
95
+ errorMessage += `^r^+Project deployment failed^:\n`;
96
+ throw new _helpers.CLIError(errorMessage, {
97
+ autoColor: false
98
+ });
99
+ }
100
+ } catch (e) {
101
+ if (updateSpinnerInterval) {
102
+ clearTimeout(updateSpinnerInterval);
103
+ }
104
+ throw e;
105
+ }
106
+ }
107
+ 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, {
108
+ message: "Name cannot be a UUID"
109
+ });
110
+ const checkIntunedProjectDeployStatus = async (workspaceId, projectName, apiKey) => {
111
+ const baseUrl = (0, _helpers.getBaseUrl)();
112
+ const url = `${baseUrl}/api/v1/workspace/${workspaceId}/projects/${projectName}/deploy/result`;
113
+ const headers = {
114
+ "x-api-key": apiKey,
115
+ "Content-Type": "application/json"
116
+ };
117
+ const response = await fetch(url, {
118
+ headers,
119
+ method: "GET"
120
+ });
121
+ if (response.status === 404) {
122
+ return {
123
+ status: "not_found",
124
+ message: "Project not found"
125
+ };
126
+ }
127
+ if (!response.ok) {
128
+ throw new _helpers.CLIError(`Error querying deployment status ${response.status}: ${await response.text()}`);
129
+ }
130
+ const data = await response.json();
131
+ if (data.status) {
132
+ return data;
133
+ }
134
+ return {
135
+ status: "failed",
136
+ message: `Deployment failed, please try again: ${data.message}`
137
+ };
138
+ };
@@ -0,0 +1 @@
1
+ export declare function loadParameters(parameters: string): Promise<object | null>;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.loadParameters = loadParameters;
7
+ var fs = _interopRequireWildcard(require("fs-extra"));
8
+ var _helpers = require("../helpers");
9
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
10
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
11
+ async function loadParameters(parameters) {
12
+ let inputData;
13
+ if (await fs.exists(parameters)) {
14
+ inputData = await loadParametersFromFile(parameters);
15
+ } else {
16
+ try {
17
+ inputData = JSON.parse(parameters);
18
+ } catch (err) {
19
+ throw new _helpers.CLIError("Parameters must be a valid JSON string or a path to a JSON file");
20
+ }
21
+ }
22
+ return inputData;
23
+ }
24
+ async function loadParametersFromFile(parametersFile) {
25
+ if (!parametersFile) {
26
+ return {};
27
+ }
28
+ try {
29
+ const filePath = parametersFile;
30
+ await fs.access(filePath);
31
+ let inputData = null;
32
+ if (parametersFile) {
33
+ inputData = await fs.readJSON(filePath);
34
+ } else {
35
+ inputData = {};
36
+ }
37
+ return inputData;
38
+ } catch (error) {
39
+ if (error.code === "ENOENT") {
40
+ throw new _helpers.CLIError(`Parameters file not found: ${parametersFile}`);
41
+ } else if (error instanceof SyntaxError) {
42
+ throw new _helpers.CLIError(`Invalid JSON in parameters file: ${error.message}`);
43
+ }
44
+ throw new _helpers.CLIError(`Error reading parameters file: ${error.message}`);
45
+ }
46
+ }
@@ -0,0 +1,14 @@
1
+ import { z } from "zod";
2
+ import type { AuthCredentials } from "../types";
3
+ export declare function runSaveProject(projectName: string, auth: AuthCredentials): Promise<void>;
4
+ export declare const projectNameSchema: z.ZodEffects<z.ZodString, string, string>;
5
+ export declare const validateProjectName: (projectName: string) => {
6
+ isValid: true;
7
+ } | {
8
+ isValid: false;
9
+ errorMessage: string;
10
+ };
11
+ export declare const validateIntunedProject: () => Promise<{
12
+ isValid: boolean;
13
+ errorMessage?: string;
14
+ }>;