@intuned/runtime-dev 1.3.18-interface.15 → 1.3.18-interface.16

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 (223) hide show
  1. package/dist/commands/api/run.d.ts +6 -0
  2. package/dist/commands/api/run.js +119 -0
  3. package/dist/commands/auth-sessions/load.d.ts +2 -0
  4. package/dist/commands/auth-sessions/load.js +35 -0
  5. package/dist/commands/auth-sessions/run-check.d.ts +2 -0
  6. package/dist/commands/auth-sessions/run-check.js +74 -0
  7. package/dist/commands/auth-sessions/run-create.d.ts +2 -0
  8. package/dist/commands/auth-sessions/run-create.js +78 -0
  9. package/dist/commands/browser/save-state.d.ts +2 -0
  10. package/dist/commands/browser/save-state.js +17 -0
  11. package/dist/commands/browser/start-browser.d.ts +2 -0
  12. package/dist/commands/browser/start-browser.js +14 -0
  13. package/dist/commands/build.d.ts +1 -0
  14. package/dist/commands/build.js +83 -0
  15. package/dist/commands/common/browserUtils.d.ts +14 -0
  16. package/dist/commands/common/browserUtils.js +57 -0
  17. package/dist/commands/common/getFirstLineNumber.d.ts +9 -0
  18. package/dist/commands/common/getFirstLineNumber.js +101 -0
  19. package/dist/commands/common/getFirstLineNumber.test.js +227 -0
  20. package/dist/commands/common/projectExclusions.d.ts +2 -0
  21. package/dist/commands/common/projectExclusions.js +8 -0
  22. package/dist/commands/common/sendMessageToClient.d.ts +1 -0
  23. package/dist/commands/common/sendMessageToClient.js +10 -0
  24. package/dist/commands/common/tsNodeImport.d.ts +2 -0
  25. package/dist/commands/common/tsNodeImport.js +42 -0
  26. package/dist/commands/common/utils/fileUtils.d.ts +6 -0
  27. package/dist/commands/common/utils/fileUtils.js +32 -0
  28. package/dist/commands/common/utils/interfaceClient.d.ts +31 -0
  29. package/dist/commands/common/utils/interfaceClient.js +98 -0
  30. package/dist/commands/common/utils/settings.d.ts +2 -0
  31. package/dist/commands/common/utils/settings.js +31 -0
  32. package/dist/commands/common/utils/template.d.ts +2 -0
  33. package/dist/commands/common/utils/template.js +30 -0
  34. package/dist/commands/get-headless-user-agent.d.ts +1 -0
  35. package/dist/commands/get-headless-user-agent.js +18 -0
  36. package/dist/commands/interface/pingPong.d.ts +2 -0
  37. package/dist/commands/interface/pingPong.js +11 -0
  38. package/dist/commands/interface/run.d.ts +1 -0
  39. package/dist/commands/interface/run.js +189 -0
  40. package/dist/commands/interface/runApi.d.ts +1 -0
  41. package/dist/commands/interface/runApi.js +102 -0
  42. package/dist/commands/intuned-cli/commands/attempt.command.d.ts +1 -0
  43. package/dist/commands/intuned-cli/commands/attempt.command.js +8 -0
  44. package/dist/commands/intuned-cli/commands/attempt_api.command.d.ts +1 -0
  45. package/dist/commands/intuned-cli/commands/attempt_api.command.js +30 -0
  46. package/dist/commands/intuned-cli/commands/attempt_authsession.command.d.ts +1 -0
  47. package/dist/commands/intuned-cli/commands/attempt_authsession.command.js +8 -0
  48. package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.d.ts +1 -0
  49. package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.js +19 -0
  50. package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.d.ts +1 -0
  51. package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.js +24 -0
  52. package/dist/commands/intuned-cli/commands/authsession.command.d.ts +1 -0
  53. package/dist/commands/intuned-cli/commands/authsession.command.js +8 -0
  54. package/dist/commands/intuned-cli/commands/authsession_record.command.d.ts +1 -0
  55. package/dist/commands/intuned-cli/commands/authsession_record.command.js +32 -0
  56. package/dist/commands/intuned-cli/commands/authsession_scaffold.command.d.ts +1 -0
  57. package/dist/commands/intuned-cli/commands/authsession_scaffold.command.js +16 -0
  58. package/dist/commands/intuned-cli/commands/build.command.d.ts +1 -0
  59. package/dist/commands/intuned-cli/commands/build.command.js +12 -0
  60. package/dist/commands/intuned-cli/commands/command.d.ts +2 -0
  61. package/dist/commands/intuned-cli/commands/command.js +9 -0
  62. package/dist/commands/intuned-cli/commands/deploy.command.d.ts +1 -0
  63. package/dist/commands/intuned-cli/commands/deploy.command.js +42 -0
  64. package/dist/commands/intuned-cli/commands/index.d.ts +18 -0
  65. package/dist/commands/intuned-cli/commands/index.js +203 -0
  66. package/dist/commands/intuned-cli/commands/provision.command.d.ts +13 -0
  67. package/dist/commands/intuned-cli/commands/provision.command.js +50 -0
  68. package/dist/commands/intuned-cli/commands/run.command.d.ts +1 -0
  69. package/dist/commands/intuned-cli/commands/run.command.js +8 -0
  70. package/dist/commands/intuned-cli/commands/run_api.command.d.ts +1 -0
  71. package/dist/commands/intuned-cli/commands/run_api.command.js +46 -0
  72. package/dist/commands/intuned-cli/commands/run_authsession.command.d.ts +35 -0
  73. package/dist/commands/intuned-cli/commands/run_authsession.command.js +17 -0
  74. package/dist/commands/intuned-cli/commands/run_authsession_create.command.d.ts +1 -0
  75. package/dist/commands/intuned-cli/commands/run_authsession_create.command.js +35 -0
  76. package/dist/commands/intuned-cli/commands/run_authsession_update.command.d.ts +1 -0
  77. package/dist/commands/intuned-cli/commands/run_authsession_update.command.js +35 -0
  78. package/dist/commands/intuned-cli/commands/run_authsession_validate.command.d.ts +1 -0
  79. package/dist/commands/intuned-cli/commands/run_authsession_validate.command.js +33 -0
  80. package/dist/commands/intuned-cli/commands/types.d.ts +39 -0
  81. package/dist/commands/intuned-cli/commands/types.js +33 -0
  82. package/dist/commands/intuned-cli/constants/index.d.ts +17 -0
  83. package/dist/commands/intuned-cli/constants/index.js +25 -0
  84. package/dist/commands/intuned-cli/controller/__test__/api.test.js +398 -0
  85. package/dist/commands/intuned-cli/controller/__test__/authSession.test.js +1060 -0
  86. package/dist/commands/intuned-cli/controller/api.d.ts +42 -0
  87. package/dist/commands/intuned-cli/controller/api.js +194 -0
  88. package/dist/commands/intuned-cli/controller/authSession.d.ts +209 -0
  89. package/dist/commands/intuned-cli/controller/authSession.js +425 -0
  90. package/dist/commands/intuned-cli/controller/build.d.ts +1 -0
  91. package/dist/commands/intuned-cli/controller/build.js +35 -0
  92. package/dist/commands/intuned-cli/controller/deploy.d.ts +5 -0
  93. package/dist/commands/intuned-cli/controller/deploy.js +317 -0
  94. package/dist/commands/intuned-cli/controller/index.d.ts +1 -0
  95. package/dist/commands/intuned-cli/controller/index.js +45 -0
  96. package/dist/commands/intuned-cli/controller/provision.d.ts +21 -0
  97. package/dist/commands/intuned-cli/controller/provision.js +299 -0
  98. package/dist/commands/intuned-cli/controller/scaffold.d.ts +1 -0
  99. package/dist/commands/intuned-cli/controller/scaffold.js +77 -0
  100. package/dist/commands/intuned-cli/helpers/__test__/browser.test.js +152 -0
  101. package/dist/commands/intuned-cli/helpers/__test__/tracing.test.js +41 -0
  102. package/dist/commands/intuned-cli/helpers/api.d.ts +3 -0
  103. package/dist/commands/intuned-cli/helpers/api.js +16 -0
  104. package/dist/commands/intuned-cli/helpers/auth.d.ts +46 -0
  105. package/dist/commands/intuned-cli/helpers/auth.js +147 -0
  106. package/dist/commands/intuned-cli/helpers/backend.d.ts +8 -0
  107. package/dist/commands/intuned-cli/helpers/backend.js +35 -0
  108. package/dist/commands/intuned-cli/helpers/browser.d.ts +14 -0
  109. package/dist/commands/intuned-cli/helpers/browser.js +93 -0
  110. package/dist/commands/intuned-cli/helpers/context.d.ts +3 -0
  111. package/dist/commands/intuned-cli/helpers/context.js +33 -0
  112. package/dist/commands/intuned-cli/helpers/errors.d.ts +16 -0
  113. package/dist/commands/intuned-cli/helpers/errors.js +44 -0
  114. package/dist/commands/intuned-cli/helpers/index.d.ts +12 -0
  115. package/dist/commands/intuned-cli/helpers/index.js +137 -0
  116. package/dist/commands/intuned-cli/helpers/intunedJson.d.ts +39 -0
  117. package/dist/commands/intuned-cli/helpers/intunedJson.js +20 -0
  118. package/dist/commands/intuned-cli/helpers/prompts.d.ts +3 -0
  119. package/dist/commands/intuned-cli/helpers/prompts.js +71 -0
  120. package/dist/commands/intuned-cli/helpers/proxy.d.ts +5 -0
  121. package/dist/commands/intuned-cli/helpers/proxy.js +23 -0
  122. package/dist/commands/intuned-cli/helpers/terminal.d.ts +5 -0
  123. package/dist/commands/intuned-cli/helpers/terminal.js +13 -0
  124. package/dist/commands/intuned-cli/helpers/timeout.d.ts +1 -0
  125. package/dist/commands/intuned-cli/helpers/timeout.js +23 -0
  126. package/dist/commands/intuned-cli/helpers/traces.d.ts +2 -0
  127. package/dist/commands/intuned-cli/helpers/traces.js +32 -0
  128. package/dist/commands/intuned-cli/helpers/validation.d.ts +2 -0
  129. package/dist/commands/intuned-cli/helpers/validation.js +14 -0
  130. package/dist/commands/intuned-cli/helpers/wrapper.d.ts +2 -0
  131. package/dist/commands/intuned-cli/helpers/wrapper.js +76 -0
  132. package/dist/commands/intuned-cli/index.d.ts +1 -0
  133. package/dist/commands/intuned-cli/index.js +16 -0
  134. package/dist/commands/intuned-cli/main.d.ts +1 -0
  135. package/dist/commands/intuned-cli/main.js +35 -0
  136. package/dist/commands/intuned-cli/types.d.ts +70 -0
  137. package/dist/commands/intuned-cli/types.js +22 -0
  138. package/dist/commands/ts-check.d.ts +2 -0
  139. package/dist/commands/ts-check.js +55 -0
  140. package/dist/common/Logger/Logger/index.d.ts +12 -0
  141. package/dist/common/Logger/Logger/index.js +60 -0
  142. package/dist/common/Logger/Logger/types.d.ts +8 -0
  143. package/dist/common/Logger/Logger/types.js +5 -0
  144. package/dist/common/Logger/index.d.ts +12 -0
  145. package/dist/common/Logger/index.js +60 -0
  146. package/dist/common/Logger/types.d.ts +8 -0
  147. package/dist/common/Logger/types.js +5 -0
  148. package/dist/common/assets/browser_scripts.js +2580 -0
  149. package/dist/common/asyncLocalStorage/index.d.ts +16 -0
  150. package/dist/common/asyncLocalStorage/index.js +17 -0
  151. package/dist/common/backendFunctions/getAuthSessionParameters.d.ts +1 -0
  152. package/dist/common/backendFunctions/getAuthSessionParameters.js +38 -0
  153. package/dist/common/binStartupScript.d.ts +1 -0
  154. package/dist/common/binStartupScript.js +36 -0
  155. package/dist/common/browserTabs.d.ts +72 -0
  156. package/dist/common/browserTabs.js +74 -0
  157. package/dist/common/cleanEnvironmentVariables.d.ts +1 -0
  158. package/dist/common/cleanEnvironmentVariables.js +16 -0
  159. package/dist/common/constants.d.ts +11 -0
  160. package/dist/common/constants.js +17 -0
  161. package/dist/common/contextStorageStateHelpers.d.ts +22 -0
  162. package/dist/common/contextStorageStateHelpers.js +84 -0
  163. package/dist/common/extension/extensionsHelpers.d.ts +11 -0
  164. package/dist/common/extension/extensionsHelpers.js +147 -0
  165. package/dist/common/extension/intunedExtensionServer.d.ts +24 -0
  166. package/dist/common/extension/intunedExtensionServer.js +178 -0
  167. package/dist/common/extension/types.d.ts +219 -0
  168. package/dist/common/extension/types.js +51 -0
  169. package/dist/common/formatZodError.d.ts +2 -0
  170. package/dist/common/formatZodError.js +18 -0
  171. package/dist/common/intunedJson.d.ts +229 -0
  172. package/dist/common/intunedJson.js +132 -0
  173. package/dist/common/jwtTokenManager.d.ts +17 -0
  174. package/dist/common/jwtTokenManager.js +113 -0
  175. package/dist/common/launchBrowser.d.ts +34 -0
  176. package/dist/common/launchBrowser.js +247 -0
  177. package/dist/common/playwrightContext.d.ts +29 -0
  178. package/dist/common/playwrightContext.js +148 -0
  179. package/dist/common/runApi/importUsingImportFunction.d.ts +7 -0
  180. package/dist/common/runApi/importUsingImportFunction.js +46 -0
  181. package/dist/common/runApi/index.d.ts +8 -0
  182. package/dist/common/runApi/index.js +178 -0
  183. package/dist/common/settingsSchema.d.ts +537 -0
  184. package/dist/common/settingsSchema.js +57 -0
  185. package/dist/common/setupContextHook.d.ts +16 -0
  186. package/dist/common/setupContextHook.js +22 -0
  187. package/dist/common/telemetry.d.ts +3 -0
  188. package/dist/common/telemetry.js +31 -0
  189. package/dist/index.d.ts +4 -0
  190. package/dist/index.js +117 -0
  191. package/dist/runtime/RunError.d.ts +5 -0
  192. package/dist/runtime/RunError.js +19 -0
  193. package/dist/runtime/attemptStore.d.ts +2 -0
  194. package/dist/runtime/attemptStore.js +23 -0
  195. package/dist/runtime/captcha.d.ts +15 -0
  196. package/dist/runtime/captcha.js +191 -0
  197. package/dist/runtime/captcha.test.js +821 -0
  198. package/dist/runtime/downloadDirectory.d.ts +1 -0
  199. package/dist/runtime/downloadDirectory.js +19 -0
  200. package/dist/runtime/enums.d.js +5 -0
  201. package/dist/runtime/enums.d.ts +11 -0
  202. package/dist/runtime/enums.js +18 -0
  203. package/dist/runtime/executionHelpers.test.js +52 -0
  204. package/dist/runtime/export.d.js +5 -0
  205. package/dist/runtime/export.d.ts +284 -0
  206. package/dist/runtime/extendPayload.d.ts +2 -0
  207. package/dist/runtime/extendPayload.js +21 -0
  208. package/dist/runtime/extendTimeout.d.ts +1 -0
  209. package/dist/runtime/extendTimeout.js +23 -0
  210. package/dist/runtime/getAiGatewayConfig.d.ts +10 -0
  211. package/dist/runtime/getAiGatewayConfig.js +16 -0
  212. package/dist/runtime/getAuthSessionParameters.d.ts +1 -0
  213. package/dist/runtime/getAuthSessionParameters.js +20 -0
  214. package/dist/runtime/index.d.ts +10 -0
  215. package/dist/runtime/index.js +111 -0
  216. package/dist/runtime/persistentStore.d.ts +2 -0
  217. package/dist/runtime/persistentStore.js +37 -0
  218. package/dist/runtime/persistentStore.test.js +101 -0
  219. package/dist/runtime/runInfo.d.ts +2 -0
  220. package/dist/runtime/runInfo.js +21 -0
  221. package/dist/vendor/runtime-interface.d.ts +1 -0
  222. package/dist/vendor/runtime-interface.js +474 -0
  223. package/package.json +2 -2
@@ -0,0 +1,317 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.projectNameSchema = exports.START_RUN_INPUT_QUERY_PARAM_KEY = 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 _provision = require("./provision");
15
+ var _constants2 = require("../../../common/constants");
16
+ var _path = _interopRequireDefault(require("path"));
17
+ var fs = _interopRequireWildcard(require("fs-extra"));
18
+ var _prompts = _interopRequireDefault(require("prompts"));
19
+ var _terminalLink = _interopRequireDefault(require("terminal-link"));
20
+ var _pressAnyKey = _interopRequireDefault(require("press-any-key"));
21
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
22
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
23
+ const START_RUN_INPUT_QUERY_PARAM_KEY = exports.START_RUN_INPUT_QUERY_PARAM_KEY = "startRunInput";
24
+ async function runDeployProject(projectName, auth) {
25
+ let enableFirstRunExperience = false;
26
+ let firstRunExperienceInput = undefined;
27
+ const settings = await (0, _helpers.loadIntunedJson)();
28
+ const provisionResult = await (0, _provision.runProvisionProject)(projectName, auth, true);
29
+ if (provisionResult) {
30
+ enableFirstRunExperience = provisionResult?.enableFirstRunExperience ?? false;
31
+ if (enableFirstRunExperience) {
32
+ firstRunExperienceInput = await promptFirstRunExperience(settings);
33
+ }
34
+ const {
35
+ projectId,
36
+ dotenvContent,
37
+ environmentVariablesKeys
38
+ } = provisionResult;
39
+ if (dotenvContent) {
40
+ const dotenvKeys = Object.keys(dotenvContent);
41
+ const missingKeys = dotenvKeys.filter(key => dotenvContent[key] && !environmentVariablesKeys.includes(key));
42
+ if (missingKeys.length > 0) {
43
+ (0, _terminal.terminal)(`^yWarning: The following environment variables are defined in your .env file but are not defined on Intuned platform^:\n`);
44
+ for (const key of missingKeys) {
45
+ (0, _terminal.terminal)(`^y • ${key}^:\n`);
46
+ }
47
+ (0, _terminal.terminal)(`^yPlease add them to your project or workspace on Intuned platform to ensure proper functionality.^:\n`);
48
+ const projectEnvVarsUrl = `${(0, _helpers.getBaseUrl)()}/projects/${projectId}/env-vars`;
49
+ const workspaceEnvVarsUrl = `${(0, _helpers.getBaseUrl)()}/settings/env-vars`;
50
+ if (_terminalLink.default.isSupported) {
51
+ const projectEnvVarsTerminalLink = (0, _terminalLink.default)(`[ Project Env Vars ]`, projectEnvVarsUrl).replaceAll("%", "%%");
52
+ const workspaceEnvVarsTerminalLink = (0, _terminalLink.default)(`[ Workspace Env Vars ]`, workspaceEnvVarsUrl).replaceAll("%", "%%");
53
+ (0, _terminal.terminal)(`^Y${projectEnvVarsTerminalLink} ${workspaceEnvVarsTerminalLink}^:\n`);
54
+ } else {
55
+ (0, _terminal.terminal)(`^yProject Env Vars: ^_${projectEnvVarsUrl}^:\n`);
56
+ (0, _terminal.terminal)(`^yWorkspace Env Vars: ^_${workspaceEnvVarsUrl}^:\n`);
57
+ }
58
+ try {
59
+ (0, _terminal.terminal)("Press any key to continue...");
60
+ await (0, _pressAnyKey.default)("", {
61
+ ctrlC: "reject",
62
+ hideMessage: true
63
+ });
64
+ (0, _terminal.terminal)("\n");
65
+ } catch {
66
+ throw new _helpers.AbortedCLIError();
67
+ }
68
+ }
69
+ }
70
+ }
71
+ const {
72
+ workspaceId,
73
+ apiKey
74
+ } = auth;
75
+ const baseUrl = (0, _helpers.getBaseUrl)();
76
+ const url = `${baseUrl}/api/v1/workspace/${workspaceId}/projects/${projectName}/deploy`;
77
+ const headers = {
78
+ [_constants2.API_KEY_HEADER_NAME]: apiKey,
79
+ "Content-Type": "application/json"
80
+ };
81
+ const response = await fetch(url, {
82
+ headers,
83
+ method: "POST",
84
+ body: JSON.stringify({
85
+ firstRunExperienceInput
86
+ })
87
+ });
88
+ if (!response.ok) {
89
+ if (response.status === 401) {
90
+ throw new _helpers.CLIError(`Invalid API key. The provided API key is not authorized to access this workspace.\n` + `Please verify your API key at: https://app.intuned.io/settings/api-keys`);
91
+ }
92
+ throw new _helpers.CLIError(`^r^+Invalid response from server\n^:^R${response.status} ${await response.text()}^:\n^r^+Deployment failed. Report this issue to the Intuned team.^:\n`, {
93
+ autoColor: false
94
+ });
95
+ }
96
+ (0, _terminal.terminal)("\n");
97
+ const startTime = Date.now();
98
+ const timeElapsedText = () => ((Date.now() - startTime) / (0, _ms.default)("1 second")).toFixed(1);
99
+ function* getSpinnerGenerator() {
100
+ while (true) {
101
+ yield* "⠙⠹⠸⠼⠴⠦⠧⠇";
102
+ }
103
+ }
104
+ const spinnerGen = getSpinnerGenerator();
105
+ let updateSpinnerInterval = null;
106
+ if (_terminal.terminalStdout.isTTY) {
107
+ updateSpinnerInterval = setInterval(() => {
108
+ _terminal.terminal.previousLine(1);
109
+ _terminal.terminal.column(0);
110
+ _terminal.terminal.eraseLineAfter();
111
+ (0, _terminal.terminal)(`${spinnerGen.next().value} ^cDeploying ^:^K(${timeElapsedText()}s)^ \n`);
112
+ }, 50);
113
+ (0, _terminal.terminal)("\n");
114
+ } else {
115
+ (0, _terminal.terminal)(`^cDeploying ^:\n`);
116
+ }
117
+ try {
118
+ while (true) {
119
+ await (0, _promises.setTimeout)(_constants.PROJECT_DEPLOY_CHECK_PERIOD);
120
+ if (!_terminal.terminalStdout.isTTY) {
121
+ (0, _terminal.terminal)(`^cDeploying ^:^K(${timeElapsedText()}s)^ \n`);
122
+ }
123
+ const {
124
+ status,
125
+ message,
126
+ projectId,
127
+ ...rest
128
+ } = await checkIntunedProjectDeployStatus(workspaceId, projectName, apiKey);
129
+ if (status === "pending") {
130
+ const elapsedTime = Date.now() - startTime;
131
+ if (elapsedTime > _constants.PROJECT_DEPLOY_TIMEOUT) {
132
+ throw new _helpers.CLIError(`Deployment failed - timed out after ${Math.floor(_constants.PROJECT_DEPLOY_TIMEOUT / (0, _ms.default)("1 minute"))} minutes`);
133
+ }
134
+ continue;
135
+ }
136
+ _terminal.terminal.previousLine(1);
137
+ _terminal.terminal.eraseLine();
138
+ if (updateSpinnerInterval) {
139
+ clearTimeout(updateSpinnerInterval);
140
+ }
141
+ if (status === "completed") {
142
+ const url = (0, _helpers.getBaseUrl)();
143
+ (0, _terminal.terminal)(`\n^g^+Project deployed successfully!^:\n\n`);
144
+ const projectUrl = `${url}/projects/${projectId}`;
145
+ const runsUrl = `${projectUrl}/runs`;
146
+ const jobsUrl = `${projectUrl}/jobs`;
147
+ const runsPlaygroundUrl = `${runsUrl}?${buildRunsPlaygroundQueryParams({
148
+ enableFirstRunExperience,
149
+ settings,
150
+ testAuthSessionId: rest.testAuthSessionId
151
+ })}`;
152
+ const defaultJobTriggerUrl = rest.defaultJobId ? `${jobsUrl}/${rest.defaultJobId}?action=trigger` : undefined;
153
+ const actions = [{
154
+ label: "View Project",
155
+ url: runsUrl
156
+ }, ...(settings.apiAccess.enabled ? [{
157
+ label: "Run Playground",
158
+ url: runsPlaygroundUrl
159
+ }] : []), {
160
+ label: "Manage Jobs",
161
+ url: jobsUrl
162
+ }, ...(defaultJobTriggerUrl !== undefined ? [{
163
+ label: "Trigger Default Job",
164
+ url: defaultJobTriggerUrl
165
+ }] : [])];
166
+ if (_terminalLink.default.isSupported) {
167
+ for (const action of actions) {
168
+ const link = (0, _terminalLink.default)(`[ ${action.label} ]`, action.url);
169
+ (0, _terminal.terminal)(`^+${link.replaceAll("%", "%%")}^ `);
170
+ }
171
+ (0, _terminal.terminal)("\n");
172
+ } else {
173
+ for (const action of actions) {
174
+ (0, _terminal.terminal)(`^+${action.label}:^ ^c^_${action.url}^:\n`);
175
+ }
176
+ }
177
+ return;
178
+ }
179
+ let errorMessage = `^r^+An error occurred while deploying project:^:\n^R${message}^:\n`;
180
+ if (rest.reason) {
181
+ errorMessage += `^r^+Reason:^:\n^R${rest.reason}^:\n`;
182
+ } else {
183
+ errorMessage += `^r^+Unknown error occurred, please report this issue to the Intuned team.^:\n`;
184
+ }
185
+ errorMessage += `^r^+Deployment failed^:\n`;
186
+ throw new _helpers.CLIError(errorMessage, {
187
+ autoColor: false
188
+ });
189
+ }
190
+ } catch (e) {
191
+ if (updateSpinnerInterval) {
192
+ clearTimeout(updateSpinnerInterval);
193
+ }
194
+ throw e;
195
+ }
196
+ }
197
+ const projectNameSchema = exports.projectNameSchema = _zod.z.string().min(1, "Project Name is required").max(200, "Name must be 200 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, {
198
+ message: "Name cannot be a UUID"
199
+ });
200
+ const checkIntunedProjectDeployStatus = async (workspaceId, projectName, apiKey) => {
201
+ const baseUrl = (0, _helpers.getBaseUrl)();
202
+ const url = `${baseUrl}/api/v1/workspace/${workspaceId}/projects/${projectName}/deploy/result`;
203
+ const headers = {
204
+ [_constants2.API_KEY_HEADER_NAME]: apiKey,
205
+ "Content-Type": "application/json"
206
+ };
207
+ const response = await fetch(url, {
208
+ headers,
209
+ method: "GET"
210
+ });
211
+ if (response.status === 404) {
212
+ return {
213
+ status: "not_found",
214
+ message: "Project not found"
215
+ };
216
+ }
217
+ if (!response.ok) {
218
+ throw new _helpers.CLIError(`Error querying deployment status ${response.status}: ${await response.text()}`);
219
+ }
220
+ const data = await response.json();
221
+ if (data.status) {
222
+ return data;
223
+ }
224
+ return {
225
+ status: "failed",
226
+ message: `Deployment failed, please try again: ${data.message}`
227
+ };
228
+ };
229
+ async function promptFirstRunExperience(settings) {
230
+ let testAuthSessionInput = undefined;
231
+ const shouldPromptForTestAuthSession = settings.authSessions.enabled && settings.authSessions.type === "API";
232
+ const defaultJobInput = settings.metadata?.defaultJobInput;
233
+ const shouldPromptForDefaultJob = defaultJobInput !== undefined;
234
+ if (shouldPromptForTestAuthSession) {
235
+ testAuthSessionInput = await promptFirstRunExperienceTestAuthSessionParameters({
236
+ shouldPromptForDefaultJob
237
+ });
238
+ if (!testAuthSessionInput) {
239
+ return {};
240
+ }
241
+ }
242
+ return {
243
+ testAuthSessionInput,
244
+ defaultJobInput: shouldPromptForDefaultJob ? await promptFirstRunExperienceDefaultJobParameters({
245
+ defaultJobInput
246
+ }) : undefined
247
+ };
248
+ }
249
+ async function promptFirstRunExperienceTestAuthSessionParameters({
250
+ shouldPromptForDefaultJob
251
+ }) {
252
+ const authSessionInstancesDirectory = _path.default.join(process.cwd(), _constants2.AUTH_SESSIONS_INSTANCES_FOLDER_NAME);
253
+ if (!(await fs.exists(authSessionInstancesDirectory))) {
254
+ return;
255
+ }
256
+ const authSessionId = (await fs.readdir(authSessionInstancesDirectory)).shift();
257
+ if (!authSessionId) {
258
+ return;
259
+ }
260
+ const {
261
+ metadata
262
+ } = await (0, _helpers.loadAuthSessionInstance)(authSessionId);
263
+ if (!metadata.authSessionId) {
264
+ return;
265
+ }
266
+ const message = shouldPromptForDefaultJob ? `^:^+Create a test AuthSession using^ ^c${authSessionId}^:^+ parameters?^ ^/(required for creating default job)^:` : `^:^+Create a test AuthSession using^ ^c${authSessionId}^:^+ parameters?^:`;
267
+ const {
268
+ value
269
+ } = await (0, _prompts.default)({
270
+ type: "confirm",
271
+ name: "value",
272
+ message: _terminal.terminal.str(message).toString(),
273
+ initial: true
274
+ });
275
+ if (value === undefined) {
276
+ throw new _helpers.AbortedCLIError();
277
+ }
278
+ if (value) {
279
+ return metadata.authSessionInput;
280
+ }
281
+ }
282
+ async function promptFirstRunExperienceDefaultJobParameters({
283
+ defaultJobInput
284
+ }) {
285
+ const {
286
+ value
287
+ } = await (0, _prompts.default)({
288
+ type: "confirm",
289
+ name: "value",
290
+ message: _terminal.terminal.str(`^:^+Create a default job with sample parameters?^:`).toString(),
291
+ initial: true
292
+ });
293
+ if (value === undefined) {
294
+ throw new _helpers.AbortedCLIError();
295
+ }
296
+ if (value) {
297
+ return defaultJobInput;
298
+ }
299
+ }
300
+ function buildRunsPlaygroundQueryParams({
301
+ enableFirstRunExperience,
302
+ settings,
303
+ testAuthSessionId
304
+ }) {
305
+ const params = new URLSearchParams();
306
+ if (!enableFirstRunExperience) return params.toString();
307
+ params.set(START_RUN_INPUT_QUERY_PARAM_KEY, JSON.stringify({}));
308
+ const input = settings.metadata?.defaultRunPlaygroundInput;
309
+ if (!input) return params.toString();
310
+ if (testAuthSessionId) {
311
+ input.authSessionId = testAuthSessionId;
312
+ }
313
+ params.set(START_RUN_INPUT_QUERY_PARAM_KEY, JSON.stringify({
314
+ ...input
315
+ }));
316
+ return params.toString();
317
+ }
@@ -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
+ var _helpers = require("../helpers");
9
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
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 _helpers.CLIError("Invalid 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 _helpers.CLIError(`Parameters file not found: ${parametersFile}`);
40
+ } else if (error instanceof SyntaxError) {
41
+ throw new _helpers.CLIError(`Invalid JSON in parameters file: ${error.message}`);
42
+ }
43
+ throw new _helpers.CLIError(`Error reading parameters file: ${error.message}`);
44
+ }
45
+ }
@@ -0,0 +1,21 @@
1
+ import { z } from "zod";
2
+ import type { AuthCredentials } from "../types";
3
+ export declare function runProvisionProject(projectName: string, auth: AuthCredentials, silent?: boolean): Promise<{
4
+ projectId: string;
5
+ enableFirstRunExperience: boolean | undefined;
6
+ environmentVariablesKeys: string[];
7
+ dotenvContent: {
8
+ [x: string]: string;
9
+ };
10
+ } | undefined>;
11
+ export declare const projectNameSchema: z.ZodEffects<z.ZodString, string, string>;
12
+ export declare const validateProjectName: (projectName: string) => {
13
+ isValid: true;
14
+ } | {
15
+ isValid: false;
16
+ errorMessage: string;
17
+ };
18
+ export declare const validateIntunedProject: () => Promise<{
19
+ isValid: boolean;
20
+ errorMessage?: string;
21
+ }>;
@@ -0,0 +1,299 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.projectNameSchema = void 0;
7
+ exports.runProvisionProject = runProvisionProject;
8
+ exports.validateProjectName = exports.validateIntunedProject = void 0;
9
+ var fs = _interopRequireWildcard(require("fs-extra"));
10
+ var path = _interopRequireWildcard(require("path"));
11
+ var _zod = require("zod");
12
+ var _projectExclusions = _interopRequireDefault(require("../../common/projectExclusions"));
13
+ var _constants = require("../constants");
14
+ var _helpers = require("../helpers");
15
+ var _terminal = require("../helpers/terminal");
16
+ var _build = require("./build");
17
+ var dotenv = _interopRequireWildcard(require("dotenv"));
18
+ var _constants2 = require("../../../common/constants");
19
+ var _ignore = _interopRequireDefault(require("ignore"));
20
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
21
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
22
+ const provisionProjectApiResponseSchema = _zod.z.string().transform((val, ctx) => {
23
+ try {
24
+ return JSON.parse(val);
25
+ } catch (e) {
26
+ ctx.addIssue({
27
+ code: _zod.z.ZodIssueCode.custom,
28
+ message: "Response is not valid JSON"
29
+ });
30
+ return _zod.z.NEVER;
31
+ }
32
+ }).pipe(_zod.z.object({
33
+ id: _zod.z.string().uuid(),
34
+ enableFirstRunExperience: _zod.z.boolean().optional(),
35
+ environmentVariablesKeys: _zod.z.array(_zod.z.string()).default([]).catch(() => [])
36
+ }));
37
+ async function runProvisionProject(projectName, auth, silent = false) {
38
+ const {
39
+ workspaceId,
40
+ apiKey
41
+ } = auth;
42
+ const baseUrl = (0, _helpers.getBaseUrl)();
43
+ const url = `${baseUrl}/api/v1/workspace/${workspaceId}/projects/${projectName}`;
44
+ const headers = {
45
+ [_constants2.API_KEY_HEADER_NAME]: apiKey,
46
+ "Content-Type": "application/json"
47
+ };
48
+ const projectPath = process.cwd();
49
+ const codeTree = await convertProjectToCodeTree(projectPath);
50
+ const intunedSettingsFile = await (0, _helpers.getIntunedSettingsFile)();
51
+ codeTree["Intuned.json"] = {
52
+ file: {
53
+ contents: JSON.stringify(intunedSettingsFile.parse(await fs.readFile(intunedSettingsFile.path, "utf-8")))
54
+ }
55
+ };
56
+ codeTree["tsconfig.json"] = {
57
+ file: {
58
+ contents: JSON.stringify(_constants.tsConfigCli, null, 2)
59
+ }
60
+ };
61
+ const upsertProjectPayload = {
62
+ codeTree,
63
+ platformType: "CLI",
64
+ language: "typescript"
65
+ };
66
+ const response = await fetch(url, {
67
+ headers,
68
+ method: "PUT",
69
+ body: JSON.stringify(upsertProjectPayload)
70
+ });
71
+ if (!response.ok) {
72
+ if (response.status === 401) {
73
+ throw new _helpers.CLIError(`Invalid API key. The provided API key is not authorized to access this workspace.\n` + `Please verify your API key at: https://app.intuned.io/settings/api-keys`);
74
+ }
75
+ throw new _helpers.CLIError(`^r^+Project provisioning failed:^:\n` + `^RServer returned status ${response.status}^:\n` + `^RResponse: ${await response.text()}^:\n\n` + `^yCommon causes:^:\n` + ` • Invalid workspace ID or project name\n` + ` • Insufficient permissions\n` + ` • Network connectivity issues\n` + ` • Project structure validation errors\n`, {
76
+ autoColor: false
77
+ });
78
+ }
79
+ if (!silent) {
80
+ (0, _terminal.terminal)("^g^+Project provisioned successfully!^:\n");
81
+ }
82
+ const body = await response.text();
83
+ const parseResult = provisionProjectApiResponseSchema.safeParse(body);
84
+ if (!parseResult.success) {
85
+ (0, _terminal.terminal)(`^yWarning: Could not parse provision project response:^:\n`);
86
+ (0, _terminal.terminal)(body + "\n");
87
+ return;
88
+ }
89
+ const {
90
+ id: projectId,
91
+ enableFirstRunExperience,
92
+ environmentVariablesKeys
93
+ } = parseResult.data;
94
+ const dotEnvPath = path.join(projectPath, ".env");
95
+ if (!(await fs.exists(dotEnvPath))) {
96
+ await fs.writeFile(dotEnvPath, `${_constants2.PROJECT_ID_ENV_VAR_KEY}=${projectId}
97
+ ${_constants2.WORKSPACE_ID_ENV_VAR_KEY}=${workspaceId}
98
+ ${_constants2.API_KEY_ENV_VAR_KEY}=${apiKey}`);
99
+ (0, _terminal.terminal)(`^g^+Created .env file with project credentials.^:\n`);
100
+ return {
101
+ projectId,
102
+ enableFirstRunExperience,
103
+ environmentVariablesKeys,
104
+ dotenvContent: {}
105
+ };
106
+ }
107
+ const envContent = await fs.readFile(dotEnvPath, "utf-8");
108
+ const dotenvContent = dotenv.parse(envContent);
109
+ let contentToAppend = "";
110
+ const projectCredentialsEnvVars = {
111
+ [_constants2.PROJECT_ID_ENV_VAR_KEY]: projectId,
112
+ [_constants2.WORKSPACE_ID_ENV_VAR_KEY]: workspaceId,
113
+ [_constants2.API_KEY_ENV_VAR_KEY]: apiKey
114
+ };
115
+ for (const key in projectCredentialsEnvVars) {
116
+ if (dotenvContent[key] === projectCredentialsEnvVars[key]) {
117
+ continue;
118
+ }
119
+ if (dotenvContent[key]) {
120
+ (0, _terminal.terminal)(`^yWarning: Existing ${key} in .env has invalid value. Appending correct value.^:\n`);
121
+ }
122
+ contentToAppend += `${key}=${projectCredentialsEnvVars[key]}\n`;
123
+ }
124
+ if (contentToAppend) {
125
+ await fs.appendFile(dotEnvPath, contentToAppend + "\n");
126
+ (0, _terminal.terminal)(`^g^+Updated .env file with project credentials.^:\n`);
127
+ }
128
+ const dotenvContentToReturn = {
129
+ ...dotenvContent
130
+ };
131
+ for (const key of [_constants2.PROJECT_ID_ENV_VAR_KEY, _constants2.WORKSPACE_ID_ENV_VAR_KEY, _constants2.API_KEY_ENV_VAR_KEY]) {
132
+ if (key in dotenvContentToReturn) {
133
+ delete dotenvContentToReturn[key];
134
+ }
135
+ }
136
+ return {
137
+ projectId,
138
+ enableFirstRunExperience,
139
+ environmentVariablesKeys,
140
+ dotenvContent: dotenvContentToReturn
141
+ };
142
+ }
143
+ const projectNameSchema = exports.projectNameSchema = _zod.z.string().min(1, "Name is required").max(200, "Must be 200 characters or less").regex(/^[a-z0-9]+(?:[-_][a-z0-9]+)*$/, "Can only contain lowercase letters, numbers, hyphens, and underscores in between").refine(value => !_zod.z.string().uuid().safeParse(value).success, {
144
+ message: "Cannot be a UUID"
145
+ });
146
+ const validateProjectName = projectName => {
147
+ const validation = projectNameSchema.safeParse(projectName);
148
+ if (!validation.success) {
149
+ return {
150
+ isValid: false,
151
+ errorMessage: validation.error.errors[0].message
152
+ };
153
+ }
154
+ return {
155
+ isValid: true
156
+ };
157
+ };
158
+ exports.validateProjectName = validateProjectName;
159
+ const validateIntunedProject = async () => {
160
+ const currentDirectoryToProvision = process.cwd();
161
+ const intunedSettingsFile = await (0, _helpers.getIntunedSettingsFile)();
162
+ const validationSteps = [{
163
+ name: "build",
164
+ check: async () => {
165
+ try {
166
+ const buildResult = await (0, _build.runBuild)();
167
+ if (!buildResult) {
168
+ return {
169
+ isValid: false,
170
+ errorMessage: "Build failed"
171
+ };
172
+ }
173
+ return {
174
+ isValid: true
175
+ };
176
+ } catch (error) {
177
+ return {
178
+ isValid: false,
179
+ errorMessage: "Build failed"
180
+ };
181
+ }
182
+ }
183
+ }, {
184
+ name: intunedSettingsFile.name,
185
+ check: async () => {
186
+ try {
187
+ const intunedJsonPath = path.join(currentDirectoryToProvision, intunedSettingsFile.name);
188
+ await fs.exists(intunedJsonPath);
189
+ return {
190
+ isValid: true
191
+ };
192
+ } catch (error) {
193
+ return {
194
+ isValid: false,
195
+ errorMessage: `${intunedSettingsFile.name} file not found`
196
+ };
197
+ }
198
+ }
199
+ }, {
200
+ name: "api folder",
201
+ check: async () => {
202
+ try {
203
+ const apiFolderPath = path.join(currentDirectoryToProvision, "api");
204
+ await fs.access(apiFolderPath);
205
+ return {
206
+ isValid: true
207
+ };
208
+ } catch (error) {
209
+ return {
210
+ isValid: false,
211
+ errorMessage: "API folder not found"
212
+ };
213
+ }
214
+ }
215
+ }];
216
+ for (const step of validationSteps) {
217
+ const result = await step.check();
218
+ if (!result.isValid) {
219
+ return result;
220
+ }
221
+ }
222
+ return {
223
+ isValid: true
224
+ };
225
+ };
226
+ exports.validateIntunedProject = validateIntunedProject;
227
+ async function convertProjectToCodeTree(projectPath) {
228
+ const ig = (0, _ignore.default)();
229
+ const gitIgnorePath = await findGitIgnoreFile(projectPath);
230
+ if (gitIgnorePath) {
231
+ const gitIgnoreContent = await fs.readFile(gitIgnorePath, "utf-8");
232
+ ig.add(gitIgnoreContent);
233
+ }
234
+ ig.add(_projectExclusions.default);
235
+ async function traverse(dirPath) {
236
+ const tree = {};
237
+ const fileNames = [];
238
+ const entries = await fs.readdir(dirPath, {
239
+ withFileTypes: true
240
+ });
241
+ for (const entry of entries) {
242
+ const entryPath = path.join(dirPath, entry.name);
243
+ if (ig.ignores(path.relative(projectPath, entryPath))) {
244
+ continue;
245
+ }
246
+ if (entry.isFile()) {
247
+ try {
248
+ const content = await fs.readFile(entryPath, "utf-8");
249
+ tree[entry.name] = {
250
+ file: {
251
+ contents: content
252
+ }
253
+ };
254
+ fileNames.push(path.relative(projectPath, entryPath));
255
+ } catch (error) {
256
+ (0, _terminal.terminal)(`^yWarning: Could not read file ${entryPath}^:\n`);
257
+ }
258
+ } else if (entry.isDirectory()) {
259
+ const {
260
+ tree: subTree,
261
+ fileNames: subFileNames
262
+ } = await traverse(entryPath);
263
+ fileNames.push(...subFileNames);
264
+ if (Object.keys(subTree).length > 0) {
265
+ tree[entry.name] = {
266
+ directory: subTree
267
+ };
268
+ }
269
+ }
270
+ }
271
+ return {
272
+ tree,
273
+ fileNames
274
+ };
275
+ }
276
+ const {
277
+ tree,
278
+ fileNames
279
+ } = await traverse(projectPath);
280
+ const filesToProvisionText = " " + fileNames.join("\n ");
281
+ (0, _terminal.terminal)("^CFiles to be provisioned:^:\n");
282
+ (0, _terminal.terminal)(filesToProvisionText + "\n");
283
+ return tree;
284
+ }
285
+ async function findGitIgnoreFile(projectPath) {
286
+ let currentDirectory = projectPath;
287
+ while (true) {
288
+ const gitIgnorePath = path.join(currentDirectory, ".gitignore");
289
+ if (await fs.exists(gitIgnorePath)) {
290
+ return gitIgnorePath;
291
+ }
292
+ const parentDirectory = path.dirname(currentDirectory);
293
+ if (parentDirectory === currentDirectory) {
294
+ break;
295
+ }
296
+ currentDirectory = parentDirectory;
297
+ }
298
+ return null;
299
+ }
@@ -0,0 +1 @@
1
+ export declare function scaffoldAuthSessionFiles(): Promise<void>;