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

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 +48 -31
  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
@@ -3,76 +3,65 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports._runCreateWithRetries = exports._runCreate = exports._runCheckWithRetries = exports._runCheck = void 0;
6
7
  exports.executeAttemptCheckAuthSessionCLI = executeAttemptCheckAuthSessionCLI;
7
8
  exports.executeAttemptCreateAuthSessionCLI = executeAttemptCreateAuthSessionCLI;
8
9
  exports.executeRunCreateAuthSessionCLI = executeRunCreateAuthSessionCLI;
9
10
  exports.executeRunUpdateAuthSessionCLI = executeRunUpdateAuthSessionCLI;
10
11
  exports.executeRunValidateAuthSessionCLI = executeRunValidateAuthSessionCLI;
11
- exports.runCreate = runCreate;
12
- var _utils = require("../../cli-auth-sessions/utils");
13
- var _path = _interopRequireDefault(require("path"));
14
- var _helpers = require("../commands/helpers");
12
+ var _helpers = require("../helpers");
15
13
  var _runApi = require("../../../common/runApi");
16
14
  var _constants = require("../../../common/constants");
17
15
  var _tsNodeImport = require("../../common/tsNodeImport");
18
- var _terminal = require("../terminal");
19
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
16
+ var _terminal = require("../helpers/terminal");
20
17
  async function executeRunValidateAuthSessionCLI({
21
18
  id,
22
19
  autoRecreate,
23
20
  checkRetries,
24
21
  createRetries,
25
- useExistingContext = false,
26
22
  ...rest
27
23
  }) {
28
- const validate = async () => {
29
- (0, _terminal.terminal)(`^+Validating auth session with id ^c${id}^:\n`);
24
+ (0, _terminal.terminal)(`^+Validating auth session with id ^c${id}^:\n`);
25
+ const {
26
+ storageState
27
+ } = await (0, _helpers.loadAuthSessionInstance)(id);
28
+ await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "check");
29
+ (0, _helpers.registerGetAuthSessionParameters)(id);
30
+ const checkResult = await runCheckWithRetries({
31
+ auth: storageState,
32
+ retries: checkRetries,
33
+ ...rest
34
+ });
35
+ if (!checkResult) {
36
+ if (!autoRecreate) {
37
+ throw new _helpers.CLIError("Auto recreate is disabled, please provide a new auth session or update it manually");
38
+ }
30
39
  const {
31
- authSessionInstanceStoragePath
32
- } = await (0, _utils.retrieveAuthSessionInstance)(id, true);
33
- const authSessionPathToUse = authSessionInstanceStoragePath;
34
- await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "check");
40
+ metadata
41
+ } = await (0, _helpers.loadAuthSessionInstance)(id);
42
+ if (metadata?.authSessionType === "MANUAL") {
43
+ throw new _helpers.CLIError("Auth session is recorder-based, please provide a new one or update it manually");
44
+ }
45
+ (0, _terminal.terminal)("^+Auto recreate is enabled - trying to re-create it^:\n");
46
+ await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "create");
47
+ const authSessionInput = metadata?.authSessionInput ?? {};
48
+ const storageState = await runCreateWithRetries({
49
+ authSessionId: id,
50
+ authSessionInput,
51
+ retries: createRetries,
52
+ ...rest
53
+ });
35
54
  const checkResult = await runCheckWithRetries({
36
- authSessionPath: authSessionPathToUse,
55
+ auth: storageState,
37
56
  retries: checkRetries,
38
57
  ...rest
39
58
  });
40
59
  if (!checkResult) {
41
- if (!autoRecreate) {
42
- throw new _helpers.CLIError("Auto recreate is disabled, please provide a new auth session or update it manually");
43
- }
44
- const {
45
- metadata
46
- } = await (0, _utils.retrieveAuthSessionInstance)(id);
47
- if (metadata?.authSessionType === "MANUAL") {
48
- throw new _helpers.CLIError("Auth session is recorder-based, please provide a new one or update it manually");
49
- }
50
- (0, _terminal.terminal)("^+Auto recreate is enabled - trying to re-create it^:\n");
51
- await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "create");
52
- const authSessionInput = metadata?.authSessionInput ?? {};
53
- await runCreateWithRetries({
54
- authSessionId: id,
55
- authSessionInput,
56
- retries: createRetries,
57
- ...rest
58
- });
59
- const checkResult = await runCheckWithRetries({
60
- authSessionPath: authSessionPathToUse,
61
- retries: checkRetries,
62
- ...rest
63
- });
64
- if (!checkResult) {
65
- throw new _helpers.CLIError("Failed to re-create auth session");
66
- }
60
+ throw new _helpers.CLIError("Failed to re-create auth session");
67
61
  }
68
- (0, _terminal.terminal)(`^+^gAuth session validated successfully^:\n`);
69
- return authSessionPathToUse;
70
- };
71
- if (useExistingContext) {
72
- return await validate();
73
- } else {
74
- return await (0, _helpers.withCLIContext)(validate)();
75
62
  }
63
+ (0, _terminal.terminal)(`^+^gAuth session validated successfully^:\n`);
64
+ return storageState;
76
65
  }
77
66
  async function executeRunCreateAuthSessionCLI({
78
67
  id,
@@ -82,29 +71,28 @@ async function executeRunCreateAuthSessionCLI({
82
71
  log = true,
83
72
  ...rest
84
73
  }) {
85
- return (0, _helpers.withCLIContext)(async () => {
86
- id = id ?? `auth-session-${Date.now()}`;
87
- (0, _terminal.terminal)(`^+Creating auth session with id ^c${id}^:\n`);
88
- await Promise.all([await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "create"), await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "check")]);
89
- const authSessionPath = await runCreateWithRetries({
90
- authSessionId: id,
91
- authSessionInput: input,
92
- retries: createRetries,
93
- ...rest
94
- });
95
- const checkResult = await runCheckWithRetries({
96
- authSessionPath: _path.default.join(authSessionPath, "auth-session.json"),
97
- retries: checkRetries,
98
- ...rest
99
- });
100
- if (!checkResult) {
101
- throw new _helpers.CLIError("Failed to create auth session");
102
- }
103
- if (log) {
104
- (0, _terminal.terminal)(`^+^gAuth session created successfully^:\n`);
105
- }
106
- return authSessionPath;
107
- })();
74
+ id = id ?? `auth-session-${Date.now()}`;
75
+ (0, _terminal.terminal)(`^+Creating auth session with id ^c${id}^:\n`);
76
+ await Promise.all([await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "create"), await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "check")]);
77
+ const createdStorageState = await runCreateWithRetries({
78
+ authSessionId: id,
79
+ authSessionInput: input,
80
+ retries: createRetries,
81
+ ...rest
82
+ });
83
+ const auth = createdStorageState;
84
+ const checkResult = await runCheckWithRetries({
85
+ auth,
86
+ retries: checkRetries,
87
+ ...rest
88
+ });
89
+ if (!checkResult) {
90
+ throw new _helpers.CLIError("Failed to create auth session");
91
+ }
92
+ if (log) {
93
+ (0, _terminal.terminal)(`^+^gAuth session created successfully^:\n`);
94
+ }
95
+ return auth;
108
96
  }
109
97
  async function executeRunUpdateAuthSessionCLI({
110
98
  id,
@@ -114,28 +102,26 @@ async function executeRunUpdateAuthSessionCLI({
114
102
  ...rest
115
103
  }) {
116
104
  (0, _terminal.terminal)(`^+Updating auth session with id ^c${id}^:\n`);
117
- return (0, _helpers.withCLIContext)(async () => {
118
- if (input === undefined) {
119
- const {
120
- metadata
121
- } = await (0, _utils.retrieveAuthSessionInstance)(id);
122
- if (metadata?.authSessionType === "MANUAL") {
123
- throw new Error("Auth session is recorder-based, it cannot be updated.");
124
- }
125
- input = metadata?.authSessionInput ?? {};
105
+ if (input === undefined) {
106
+ const {
107
+ metadata
108
+ } = await (0, _helpers.loadAuthSessionInstance)(id);
109
+ if (metadata?.authSessionType === "MANUAL") {
110
+ throw new _helpers.CLIError("Auth session is recorder-based, it cannot be updated.");
126
111
  }
127
- await Promise.all([await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "create"), await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "check")]);
128
- const authSession = await executeRunCreateAuthSessionCLI({
129
- id,
130
- input,
131
- checkRetries,
132
- createRetries,
133
- log: false,
134
- ...rest
135
- });
136
- (0, _terminal.terminal)(`^+^gAuth session updated successfully^:\n`);
137
- return authSession;
138
- })();
112
+ input = metadata?.authSessionInput ?? {};
113
+ }
114
+ await Promise.all([await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "create"), await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "check")]);
115
+ const authSession = await executeRunCreateAuthSessionCLI({
116
+ id,
117
+ input,
118
+ checkRetries,
119
+ createRetries,
120
+ log: false,
121
+ ...rest
122
+ });
123
+ (0, _terminal.terminal)(`^+^gAuth session updated successfully^:\n`);
124
+ return authSession;
139
125
  }
140
126
  async function executeAttemptCreateAuthSessionCLI({
141
127
  id,
@@ -158,28 +144,28 @@ async function executeAttemptCheckAuthSessionCLI({
158
144
  }) {
159
145
  (0, _terminal.terminal)(`^+Executing check auth session attempt with id ^c${id}^:\n`);
160
146
  await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "check");
147
+ (0, _helpers.registerGetAuthSessionParameters)(id);
161
148
  const {
162
- authSessionInstanceStoragePath
163
- } = await (0, _utils.retrieveAuthSessionInstance)(id, true);
164
- const authSessionPathToUse = authSessionInstanceStoragePath;
149
+ storageState
150
+ } = await (0, _helpers.loadAuthSessionInstance)(id);
165
151
  const checkResult = await runCheckWithRetries({
166
- authSessionPath: authSessionPathToUse,
152
+ auth: storageState,
167
153
  retries: 1,
168
154
  ...rest
169
155
  });
170
156
  if (!checkResult) {
171
- throw new Error("Check failed");
157
+ throw new _helpers.CLIError("Check failed");
172
158
  }
173
159
  (0, _terminal.terminal)(`^+^gAuth session check passed^:\n`);
174
- return authSessionPathToUse;
160
+ return storageState;
175
161
  }
176
162
  async function runCheck({
177
- authSessionPath,
163
+ auth,
178
164
  proxy,
179
165
  headless,
180
166
  timeout
181
167
  }) {
182
- return await (0, _helpers.withTimeout)(async () => {
168
+ return await (0, _helpers.withTimeout)(async abortSignal => {
183
169
  const runApiResult = await (0, _runApi.runApi)({
184
170
  automationFunction: {
185
171
  name: `${_constants.AUTH_SESSIONS_FOLDER_NAME}/check`
@@ -191,37 +177,35 @@ async function runCheck({
191
177
  },
192
178
  auth: {
193
179
  session: {
194
- type: "file",
195
- path: authSessionPath
180
+ type: "state",
181
+ state: auth
196
182
  },
197
183
  runCheck: false
198
184
  },
199
- importFunction: _tsNodeImport.tsNodeImport
185
+ importFunction: _tsNodeImport.tsNodeImport,
186
+ abortSignal
200
187
  });
201
188
  if (runApiResult.isErr()) {
202
- if (runApiResult.error instanceof _runApi.AutomationError) {
203
- throw runApiResult.error;
204
- }
205
- return false;
189
+ throw runApiResult.error;
206
190
  }
207
191
  const result = runApiResult.value.result;
208
192
  if (!result) {
209
193
  return false;
210
194
  }
211
195
  return result;
212
- }, timeout)();
196
+ }, timeout);
213
197
  }
198
+ const _runCheck = exports._runCheck = runCheck;
214
199
  async function runCreate({
215
200
  authSessionInput,
216
201
  proxy,
217
202
  headless,
218
203
  timeout
219
204
  }) {
220
- return await (0, _helpers.withTimeout)(async () => {
221
- const createApiName = `${_constants.AUTH_SESSIONS_FOLDER_NAME}/create`;
205
+ return await (0, _helpers.withTimeout)(async abortSignal => {
222
206
  const result = await (0, _runApi.runApi)({
223
207
  automationFunction: {
224
- name: createApiName,
208
+ name: `${_constants.AUTH_SESSIONS_FOLDER_NAME}/create`,
225
209
  params: authSessionInput
226
210
  },
227
211
  runOptions: {
@@ -230,20 +214,18 @@ async function runCreate({
230
214
  proxy: proxy ? (0, _helpers.parseUrlProxy)(proxy) : undefined
231
215
  },
232
216
  retrieveSession: true,
233
- importFunction: _tsNodeImport.tsNodeImport
217
+ importFunction: _tsNodeImport.tsNodeImport,
218
+ abortSignal
234
219
  });
235
220
  if (result.isErr()) {
236
- if (result.error instanceof _runApi.AutomationError) {
237
- throw result.error.error;
238
- }
239
- console.error(result.error);
240
- throw new Error("Error while running create");
221
+ throw result.error;
241
222
  }
242
223
  return result.value.session;
243
- }, timeout)();
224
+ }, timeout);
244
225
  }
226
+ const _runCreate = exports._runCreate = runCreate;
245
227
  async function runCheckWithRetries({
246
- authSessionPath,
228
+ auth,
247
229
  retries,
248
230
  ...rest
249
231
  }) {
@@ -251,22 +233,29 @@ async function runCheckWithRetries({
251
233
  (0, _terminal.terminal)(`\n^+Running ^cauth session check${i === 0 ? "" : ` ^/(Attempt ${i + 1})`}^:...\n`);
252
234
  try {
253
235
  const checkResult = await runCheck({
254
- authSessionPath,
236
+ auth,
255
237
  ...rest
256
238
  });
239
+ console.log({
240
+ checkResult
241
+ });
257
242
  if (checkResult) {
258
243
  (0, _terminal.terminal)(`^+^gAuth session check passed^:\n`);
259
244
  return true;
260
245
  }
261
246
  } catch (error) {
262
- (0, _terminal.terminal)(`^+^yAuth session check failed with error ^:${error.message}^:\n`);
263
- continue;
247
+ if (error instanceof _runApi.AutomationError) {
248
+ (0, _helpers.logAutomationError)(error);
249
+ } else {
250
+ throw error;
251
+ }
264
252
  }
265
253
  (0, _terminal.terminal)(`^+^yAuth session check failed^:\n`);
266
254
  }
267
255
  (0, _terminal.terminal)(`^+^rAuth session check failed after ${retries} attempts^:\n`);
268
256
  return false;
269
257
  }
258
+ const _runCheckWithRetries = exports._runCheckWithRetries = runCheckWithRetries;
270
259
  async function runCreateWithRetries({
271
260
  authSessionId,
272
261
  authSessionInput,
@@ -284,12 +273,23 @@ async function runCreateWithRetries({
284
273
  (0, _terminal.terminal)(`^+^gAuth session create succeeded^:\n`);
285
274
  break;
286
275
  } catch (error) {
287
- (0, _terminal.terminal)(`^+^yAuth session create failed with error ^:${error.message}^:\n`);
288
- continue;
276
+ if (error instanceof _runApi.AutomationError) {
277
+ (0, _helpers.logAutomationError)(error);
278
+ } else {
279
+ throw error;
280
+ }
281
+ (0, _terminal.terminal)(`^+^yAuth session create failed^:\n`);
289
282
  }
290
283
  }
291
284
  if (!newAuthSessionInstance) {
292
285
  throw new _helpers.CLIError(`Failed to create auth session after ${retries} retries`);
293
286
  }
294
- return await (0, _utils.storeAuthSessionInstance)(newAuthSessionInstance, authSessionId, authSessionInput);
295
- }
287
+ await (0, _helpers.storeAuthSessionInstance)({
288
+ state: newAuthSessionInstance,
289
+ id: authSessionId,
290
+ input: authSessionInput,
291
+ proxy: rest.proxy
292
+ });
293
+ return newAuthSessionInstance;
294
+ }
295
+ const _runCreateWithRetries = exports._runCreateWithRetries = runCreateWithRetries;
@@ -8,7 +8,7 @@ var fs = _interopRequireWildcard(require("fs-extra"));
8
8
  var path = _interopRequireWildcard(require("path"));
9
9
  var _child_process = require("child_process");
10
10
  var _util = require("util");
11
- var _terminal = require("../terminal");
11
+ var _terminal = require("../helpers/terminal");
12
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
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
14
  const execPromise = (0, _util.promisify)(_child_process.exec);
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { AuthCredentials, FileSystemTree } from "../../../common/cli/types";
2
+ import type { AuthCredentials, FileSystemTree } from "../types";
3
3
  export declare function convertProjectToCodeTree(projectPath: string): Promise<FileSystemTree>;
4
4
  export declare function runDeployProject(projectName: string, auth: AuthCredentials): Promise<void>;
5
5
  export declare const projectNameSchema: z.ZodEffects<z.ZodString, string, string>;
@@ -12,14 +12,12 @@ var path = _interopRequireWildcard(require("path"));
12
12
  var _minimatch = require("minimatch");
13
13
  var _zod = require("zod");
14
14
  var _projectExclusions = _interopRequireDefault(require("../../common/projectExclusions"));
15
- var _constants = require("../../../common/cli/constants");
16
- var _utils = require("../../../common/cli/utils");
17
- var _utils2 = require("../../init/utils");
15
+ var _constants = require("../constants");
16
+ var _helpers = require("../helpers");
18
17
  var _lodash = require("lodash");
19
18
  var _uuid = require("uuid");
20
- var _terminal = require("../terminal");
19
+ var _terminal = require("../helpers/terminal");
21
20
  var _promises = require("timers/promises");
22
- var _helpers = require("../commands/helpers");
23
21
  var _ms = _interopRequireDefault(require("ms"));
24
22
  var _build = require("./build");
25
23
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -123,7 +121,7 @@ async function runDeployProject(projectName, auth) {
123
121
  workspaceId,
124
122
  apiKey
125
123
  } = auth;
126
- const baseUrl = (0, _utils.getBaseUrl)();
124
+ const baseUrl = (0, _helpers.getBaseUrl)();
127
125
  const url = `${baseUrl}/api/v1/workspace/${workspaceId}/projects/create`;
128
126
  const headers = {
129
127
  "x-api-key": apiKey,
@@ -157,25 +155,36 @@ async function runDeployProject(projectName, auth) {
157
155
  }
158
156
  (0, _terminal.terminal)("\n");
159
157
  const startTime = Date.now();
160
- let lastCheckTime = startTime;
161
- const spinner = await _terminal.terminal.spinner("dotSpinner");
162
- (0, _terminal.terminal)("\n");
163
- try {
158
+ const timeElapsedText = () => ((Date.now() - startTime) / (0, _ms.default)("1 second")).toFixed(1);
159
+ function* getSpinnerGenerator() {
164
160
  while (true) {
165
- await (0, _promises.setTimeout)(50);
161
+ yield* "⠙⠹⠸⠼⠴⠦⠧⠇";
162
+ }
163
+ }
164
+ const spinnerGen = getSpinnerGenerator();
165
+ let updateSpinnerInterval = null;
166
+ if (_terminal.terminalStdout.isTTY) {
167
+ updateSpinnerInterval = setInterval(() => {
166
168
  _terminal.terminal.previousLine(1);
167
- _terminal.terminal.column(3);
169
+ _terminal.terminal.column(0);
168
170
  _terminal.terminal.eraseLineAfter();
169
- const timeElapsedText = ((Date.now() - startTime) / (0, _ms.default)("1 second")).toFixed(1);
170
- (0, _terminal.terminal)(`^cDeploying ^:^K(${timeElapsedText}s)^ \n`);
171
- if (Date.now() - lastCheckTime < _constants.PROJECT_DEPLOY_CHECK_PERIOD) {
172
- continue;
171
+ (0, _terminal.terminal)(`${spinnerGen.next().value} ^cDeploying ^:^K(${timeElapsedText()}s)^ \n`);
172
+ }, 50);
173
+ (0, _terminal.terminal)("\n");
174
+ } else {
175
+ (0, _terminal.terminal)(`^cDeploying ^:\n`);
176
+ }
177
+ try {
178
+ while (true) {
179
+ await (0, _promises.setTimeout)(_constants.PROJECT_DEPLOY_CHECK_PERIOD);
180
+ if (!_terminal.terminalStdout.isTTY) {
181
+ (0, _terminal.terminal)(`^cDeploying ^:^K(${timeElapsedText()}s)^ \n`);
173
182
  }
174
- lastCheckTime = Date.now();
175
183
  const {
176
184
  status,
177
185
  message,
178
- projectId
186
+ projectId,
187
+ ...rest
179
188
  } = await checkIntunedProjectDeployStatus(workspaceId, projectName, apiKey);
180
189
  if (status === "pending") {
181
190
  const elapsedTime = Date.now() - startTime;
@@ -186,17 +195,29 @@ async function runDeployProject(projectName, auth) {
186
195
  }
187
196
  _terminal.terminal.previousLine(1);
188
197
  _terminal.terminal.eraseLine();
189
- spinner.animate(false);
198
+ if (updateSpinnerInterval) {
199
+ clearTimeout(updateSpinnerInterval);
200
+ }
190
201
  if (status === "completed") {
191
- const url = (0, _utils.getBaseUrl)();
202
+ const url = (0, _helpers.getBaseUrl)();
192
203
  (0, _terminal.terminal)(`\n^g^+Project deployed successfully!^:\n`);
193
204
  (0, _terminal.terminal)(`^+You can check your project on the platform:^s ^c^_${url}/projects/${projectId}/details^:\n`);
194
205
  return;
195
206
  }
196
- throw new _helpers.CLIError(`^r^+An error occurred while deploying project:^:\n^R${message}^:\n^r^+Project deployment failed^:\n`);
207
+ let errorMessage = `^r^+An error occurred while deploying project:^:\n^R${message}^:\n`;
208
+ if (rest.reason) {
209
+ errorMessage += `^r^+Reason:^:\n^R${rest.reason}^:\n`;
210
+ }
211
+ errorMessage += `^r^+Project deployment failed^:\n`;
212
+ throw new _helpers.CLIError(errorMessage, {
213
+ autoColor: false
214
+ });
197
215
  }
198
216
  } catch (e) {
199
- spinner.animate(false);
217
+ if (updateSpinnerInterval) {
218
+ clearTimeout(updateSpinnerInterval);
219
+ }
220
+ throw e;
200
221
  }
201
222
  }
202
223
  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, {
@@ -309,7 +330,7 @@ const validateIntunedProject = async () => {
309
330
  };
310
331
  exports.validateIntunedProject = validateIntunedProject;
311
332
  const checkIntunedProjectDeployStatus = async (workspaceId, projectName, apiKey) => {
312
- const baseUrl = (0, _utils.getBaseUrl)();
333
+ const baseUrl = (0, _helpers.getBaseUrl)();
313
334
  const url = `${baseUrl}/api/v1/workspace/${workspaceId}/projects/create/${projectName}/result`;
314
335
  const headers = {
315
336
  "x-api-key": apiKey,
@@ -326,15 +347,11 @@ const checkIntunedProjectDeployStatus = async (workspaceId, projectName, apiKey)
326
347
  };
327
348
  }
328
349
  if (!response.ok) {
329
- throw new Error(`Error querying deployment status ${response.status}: ${await response.text()}`);
350
+ throw new _helpers.CLIError(`Error querying deployment status ${response.status}: ${await response.text()}`);
330
351
  }
331
352
  const data = await response.json();
332
353
  if (data.status) {
333
- return {
334
- status: data.status,
335
- message: data.message,
336
- projectId: data.projectId
337
- };
354
+ return data;
338
355
  }
339
356
  return {
340
357
  status: "failed",
@@ -345,7 +362,7 @@ async function mapToIDEParams(tree) {
345
362
  if (!tree) {
346
363
  return;
347
364
  }
348
- if (!tree["parameters"] || (0, _utils2._isFileNode)(tree["parameters"])) {
365
+ if (!tree["parameters"] || "file" in tree["parameters"]) {
349
366
  return;
350
367
  }
351
368
  const apiParametersMap = {};
@@ -355,7 +372,7 @@ async function mapToIDEParams(tree) {
355
372
  };
356
373
  for (const parameterKey of cliParameters) {
357
374
  const parameter = tree["parameters"].directory[parameterKey];
358
- if ((0, _utils2._isDirectoryNode)(parameter)) {
375
+ if ("directory" in parameter) {
359
376
  continue;
360
377
  }
361
378
  if ((0, _lodash.isEmpty)(parameter.file.contents)) {
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.loadParameters = loadParameters;
7
7
  var fs = _interopRequireWildcard(require("fs-extra"));
8
+ var _helpers = require("../helpers");
8
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); }
9
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; }
10
11
  async function loadParameters(parameters) {
@@ -15,7 +16,7 @@ async function loadParameters(parameters) {
15
16
  try {
16
17
  inputData = JSON.parse(parameters);
17
18
  } catch (err) {
18
- throw new Error("Parameters must be a valid JSON string or a path to a JSON file");
19
+ throw new _helpers.CLIError("Parameters must be a valid JSON string or a path to a JSON file");
19
20
  }
20
21
  }
21
22
  return inputData;
@@ -36,10 +37,10 @@ async function loadParametersFromFile(parametersFile) {
36
37
  return inputData;
37
38
  } catch (error) {
38
39
  if (error.code === "ENOENT") {
39
- throw new Error(`Parameters file not found: ${parametersFile}`);
40
+ throw new _helpers.CLIError(`Parameters file not found: ${parametersFile}`);
40
41
  } else if (error instanceof SyntaxError) {
41
- throw new Error(`Invalid JSON in parameters file: ${error.message}`);
42
+ throw new _helpers.CLIError(`Invalid JSON in parameters file: ${error.message}`);
42
43
  }
43
- throw new Error(`Error reading parameters file: ${error.message}`);
44
+ throw new _helpers.CLIError(`Error reading parameters file: ${error.message}`);
44
45
  }
45
46
  }
@@ -1,4 +1,4 @@
1
- import { FileSystemTree, TemplateId } from "../../../common/cli/types";
1
+ import { FileSystemTree, TemplateId } from "../types";
2
2
  export declare function mountFiles(cwd: string, tree: FileSystemTree): Promise<void>;
3
3
  export declare function checkEmptyDirectory(): Promise<boolean>;
4
4
  export declare function selectTemplate(templateName: string): Promise<TemplateId>;