@intuned/runtime 1.3.15 → 1.3.17

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 (73) hide show
  1. package/InterfaceTemplate/index.playwright.ts +1 -1
  2. package/WebTemplate.zip +0 -0
  3. package/dist/commands/api/run.js +4 -8
  4. package/dist/commands/auth-sessions/load.js +2 -2
  5. package/dist/commands/auth-sessions/run-check.js +5 -5
  6. package/dist/commands/auth-sessions/run-create.js +3 -3
  7. package/dist/commands/build.js +1 -1
  8. package/dist/commands/common/projectExclusions.js +1 -1
  9. package/dist/commands/common/tsNodeImport.js +9 -0
  10. package/dist/commands/interface/run.js +1 -1
  11. package/dist/commands/intuned-cli/commands/attempt_api.command.js +1 -1
  12. package/dist/commands/intuned-cli/commands/attempt_authsession.command.js +1 -1
  13. package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.js +2 -2
  14. package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.js +1 -1
  15. package/dist/commands/intuned-cli/commands/authsession.command.js +1 -1
  16. package/dist/commands/intuned-cli/commands/authsession_record.command.js +1 -1
  17. package/dist/commands/intuned-cli/commands/authsession_scaffold.command.d.ts +1 -0
  18. package/dist/commands/intuned-cli/commands/authsession_scaffold.command.js +16 -0
  19. package/dist/commands/intuned-cli/commands/deploy.command.js +13 -9
  20. package/dist/commands/intuned-cli/commands/index.d.ts +2 -2
  21. package/dist/commands/intuned-cli/commands/index.js +15 -15
  22. package/dist/commands/intuned-cli/commands/{save.command.d.ts → provision.command.d.ts} +1 -1
  23. package/dist/commands/intuned-cli/commands/provision.command.js +50 -0
  24. package/dist/commands/intuned-cli/commands/run_api.command.js +1 -1
  25. package/dist/commands/intuned-cli/commands/run_authsession.command.d.ts +3 -3
  26. package/dist/commands/intuned-cli/commands/run_authsession.command.js +2 -2
  27. package/dist/commands/intuned-cli/commands/run_authsession_create.command.js +1 -1
  28. package/dist/commands/intuned-cli/commands/run_authsession_update.command.js +2 -2
  29. package/dist/commands/intuned-cli/commands/run_authsession_validate.command.js +2 -2
  30. package/dist/commands/intuned-cli/commands/types.d.ts +1 -1
  31. package/dist/commands/intuned-cli/commands/types.js +2 -2
  32. package/dist/commands/intuned-cli/controller/__test__/api.test.js +6 -5
  33. package/dist/commands/intuned-cli/controller/__test__/authSession.test.js +12 -11
  34. package/dist/commands/intuned-cli/controller/api.js +4 -1
  35. package/dist/commands/intuned-cli/controller/authSession.js +28 -28
  36. package/dist/commands/intuned-cli/controller/deploy.js +52 -10
  37. package/dist/commands/intuned-cli/controller/index.js +1 -1
  38. package/dist/commands/intuned-cli/controller/{save.d.ts → provision.d.ts} +5 -1
  39. package/dist/commands/intuned-cli/controller/provision.js +300 -0
  40. package/dist/commands/intuned-cli/controller/scaffold.d.ts +1 -0
  41. package/dist/commands/intuned-cli/controller/scaffold.js +77 -0
  42. package/dist/commands/intuned-cli/helpers/__test__/browser.test.js +1 -0
  43. package/dist/commands/intuned-cli/helpers/__test__/tracing.test.js +1 -0
  44. package/dist/commands/intuned-cli/helpers/api.js +4 -7
  45. package/dist/commands/intuned-cli/helpers/auth.js +22 -19
  46. package/dist/commands/intuned-cli/helpers/backend.js +12 -4
  47. package/dist/commands/intuned-cli/helpers/context.js +2 -2
  48. package/dist/commands/intuned-cli/helpers/prompts.d.ts +3 -0
  49. package/dist/commands/intuned-cli/helpers/prompts.js +71 -0
  50. package/dist/commands/intuned-cli/helpers/wrapper.js +12 -2
  51. package/dist/commands/intuned-cli/main.js +21 -8
  52. package/dist/commands/intuned-cli/types.d.ts +42 -13
  53. package/dist/commands/intuned-cli/types.js +12 -2
  54. package/dist/common/backendFunctions/getAuthSessionParameters.js +1 -1
  55. package/dist/common/extension/extensionsHelpers.d.ts +6 -3
  56. package/dist/common/extension/extensionsHelpers.js +45 -19
  57. package/dist/common/extension/intunedExtensionServer.d.ts +2 -5
  58. package/dist/common/extension/intunedExtensionServer.js +6 -9
  59. package/dist/common/intunedJson.js +2 -2
  60. package/dist/common/jwtTokenManager.js +2 -2
  61. package/dist/common/launchBrowser.d.ts +2 -0
  62. package/dist/common/launchBrowser.js +41 -3
  63. package/dist/common/playwrightContext.js +7 -1
  64. package/dist/common/runApi/errors.js +1 -1
  65. package/dist/common/runApi/index.js +2 -2
  66. package/dist/common/settingsSchema.d.ts +2 -1
  67. package/dist/runtime/captcha.js +25 -11
  68. package/package.json +5 -3
  69. package/dist/commands/intuned-cli/commands/init.command.d.ts +0 -1
  70. package/dist/commands/intuned-cli/commands/init.command.js +0 -13
  71. package/dist/commands/intuned-cli/commands/save.command.js +0 -42
  72. package/dist/commands/intuned-cli/controller/save.js +0 -351
  73. /package/InterfaceTemplate/{utils.ts → __utils.ts} +0 -0
@@ -39,6 +39,7 @@ function getMockTimeout() {
39
39
  };
40
40
  }
41
41
  _vitest.vi.mock("fs-extra", () => ({
42
+ ensureDir: _vitest.vi.fn(),
42
43
  writeJSON: _vitest.vi.fn(),
43
44
  exists: _vitest.vi.fn().mockResolvedValue(true)
44
45
  }));
@@ -92,7 +93,7 @@ _vitest.vi.mock("../../helpers", async importOriginal => {
92
93
  registerGetAuthSessionParameters: _vitest.vi.fn()
93
94
  };
94
95
  });
95
- (0, _vitest.describe)("Auth session controller", () => {
96
+ (0, _vitest.describe)("AuthSession controller", () => {
96
97
  (0, _vitest.beforeEach)(() => {
97
98
  _vitest.vi.clearAllMocks();
98
99
  });
@@ -418,7 +419,7 @@ _vitest.vi.mock("../../helpers", async importOriginal => {
418
419
  });
419
420
  (0, _vitest.expect)(_helpers.withCLITrace).toHaveBeenCalledWith(_vitest.expect.any(Function), _vitest.expect.any(String));
420
421
  });
421
- (0, _vitest.it)("saves the auth session instance", async () => {
422
+ (0, _vitest.it)("saves the AuthSession instance", async () => {
422
423
  _vitest.vi.mocked(_runApi.runApi).mockResolvedValueOnce(_createSuccessResult("session"));
423
424
  _vitest.vi.mocked(_helpers.parseUrlProxy).mockReturnValueOnce("parsed-proxy");
424
425
  await (0, _authSession._runCreateWithRetries)({
@@ -576,7 +577,7 @@ _vitest.vi.mock("../../helpers", async importOriginal => {
576
577
  });
577
578
  (0, _vitest.expect)(_helpers.assertApiFileExists).toHaveBeenCalledWith("auth-sessions", "create");
578
579
  });
579
- (0, _vitest.it)("throws if auth session is manual", async () => {
580
+ (0, _vitest.it)("throws if AuthSession is manual", async () => {
580
581
  _vitest.vi.mocked(_helpers.loadAuthSessionInstance).mockResolvedValue({
581
582
  storageState: {},
582
583
  metadata: {
@@ -680,7 +681,7 @@ _vitest.vi.mock("../../helpers", async importOriginal => {
680
681
  trace: false
681
682
  })).rejects.toThrow(_helpers.CLIError);
682
683
  });
683
- (0, _vitest.it)("saves to auth session instance path if create and check succeed", async () => {
684
+ (0, _vitest.it)("saves to AuthSession instance path if create and check succeed", async () => {
684
685
  await (0, _authSession.executeRunCreateAuthSessionCLI)({
685
686
  input: "authSessionInput",
686
687
  checkRetries: 1,
@@ -694,7 +695,7 @@ _vitest.vi.mock("../../helpers", async importOriginal => {
694
695
  id: _vitest.expect.any(String)
695
696
  }));
696
697
  });
697
- (0, _vitest.it)("uses auth session id to save if provided", async () => {
698
+ (0, _vitest.it)("uses AuthSession id to save if provided", async () => {
698
699
  const result = await (0, _authSession.executeRunCreateAuthSessionCLI)({
699
700
  id: "authSessionId",
700
701
  input: "authSessionInput",
@@ -728,7 +729,7 @@ _vitest.vi.mock("../../helpers", async importOriginal => {
728
729
  _vitest.vi.mocked(_runApi.runApi).mockReset();
729
730
  _vitest.vi.mocked(_helpers.loadAuthSessionInstance).mockReset();
730
731
  });
731
- (0, _vitest.it)("throws if auth session is manual", async () => {
732
+ (0, _vitest.it)("throws if AuthSession is manual", async () => {
732
733
  _vitest.vi.mocked(_helpers.loadAuthSessionInstance).mockResolvedValue({
733
734
  storageState: {},
734
735
  metadata: {
@@ -798,7 +799,7 @@ _vitest.vi.mock("../../helpers", async importOriginal => {
798
799
  retrieveSession: true
799
800
  }));
800
801
  });
801
- (0, _vitest.it)("saves the auth session with existing input if create and check succeed without providing input", async () => {
802
+ (0, _vitest.it)("saves the AuthSession with existing input if create and check succeed without providing input", async () => {
802
803
  const result = await (0, _authSession.executeRunUpdateAuthSessionCLI)({
803
804
  id: "authSessionId",
804
805
  checkRetries: 1,
@@ -814,7 +815,7 @@ _vitest.vi.mock("../../helpers", async importOriginal => {
814
815
  proxy: undefined
815
816
  }));
816
817
  });
817
- (0, _vitest.it)("saves the auth session with new input if create and check succeed with new input", async () => {
818
+ (0, _vitest.it)("saves the AuthSession with new input if create and check succeed with new input", async () => {
818
819
  const result = await (0, _authSession.executeRunUpdateAuthSessionCLI)({
819
820
  id: "authSessionId",
820
821
  input: "newAuthSessionInput",
@@ -905,7 +906,7 @@ _vitest.vi.mock("../../helpers", async importOriginal => {
905
906
  trace: false
906
907
  })).rejects.toThrow(_helpers.CLIError);
907
908
  });
908
- (0, _vitest.it)("saves to auth session instance path if create and check succeed", async () => {
909
+ (0, _vitest.it)("saves to AuthSession instance path if create and check succeed", async () => {
909
910
  await (0, _authSession.executeAttemptCreateAuthSessionCLI)({
910
911
  input: "authSessionInput",
911
912
  headless: false,
@@ -917,7 +918,7 @@ _vitest.vi.mock("../../helpers", async importOriginal => {
917
918
  id: _vitest.expect.any(String)
918
919
  }));
919
920
  });
920
- (0, _vitest.it)("uses auth session id to save if provided", async () => {
921
+ (0, _vitest.it)("uses AuthSession id to save if provided", async () => {
921
922
  await (0, _authSession.executeAttemptCreateAuthSessionCLI)({
922
923
  id: "authSessionId",
923
924
  input: "authSessionInput",
@@ -1032,7 +1033,7 @@ _vitest.vi.mock("../../helpers", async importOriginal => {
1032
1033
  await mockTimeout.resolve();
1033
1034
  await (0, _vitest.expect)(p).rejects.toThrow(_helpers.CLIError);
1034
1035
  });
1035
- (0, _vitest.it)("stores auth session and validates it if successful", async () => {
1036
+ (0, _vitest.it)("stores AuthSession and validates it if successful", async () => {
1036
1037
  mockPage.url.mockReturnValue("finishUrl");
1037
1038
  await (0, _authSession.executeRecordAuthSessionCLI)({
1038
1039
  checkRetries: 1,
@@ -14,6 +14,8 @@ var _helpers = require("../helpers");
14
14
  var _terminal = require("../helpers/terminal");
15
15
  var _constants = require("../../../common/constants");
16
16
  var _browser = require("../helpers/browser");
17
+ var _path = _interopRequireDefault(require("path"));
18
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
17
19
  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); }
18
20
  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; }
19
21
  async function executeRunApiCLI({
@@ -48,7 +50,7 @@ async function executeRunApiCLI({
48
50
  ...rest
49
51
  });
50
52
  } catch (error) {
51
- if (error instanceof _runApi.AutomationError) {
53
+ if (error instanceof _runApi.RunAutomationError) {
52
54
  (0, _helpers.logAutomationError)(error);
53
55
  (0, _terminal.terminal)(`^r^+Attempt ${i + 1} failed^:\n`);
54
56
  continue;
@@ -133,6 +135,7 @@ async function writeResultToFile(outputFile, result, payloadToAppend) {
133
135
  resultToWrite["extendedPayloads"] = payloadToAppend;
134
136
  }
135
137
  try {
138
+ await fs.ensureDir(_path.default.dirname(outputFile));
136
139
  await fs.writeJSON(outputFile, resultToWrite, {
137
140
  spaces: 2
138
141
  });
@@ -26,7 +26,7 @@ async function executeRunValidateAuthSessionCLI({
26
26
  createRetries,
27
27
  ...rest
28
28
  }) {
29
- (0, _terminal.terminal)(`^+Validating auth session with id ^c${id}^:\n`);
29
+ (0, _terminal.terminal)(`^+Validating AuthSession with id ^c${id}^:\n`);
30
30
  const {
31
31
  storageState
32
32
  } = await (0, _helpers.loadAuthSessionInstance)(id);
@@ -39,13 +39,13 @@ async function executeRunValidateAuthSessionCLI({
39
39
  });
40
40
  if (!checkResult) {
41
41
  if (!autoRecreate) {
42
- throw new _helpers.CLIError("Auto recreate is disabled, please provide a new auth session or update it manually");
42
+ throw new _helpers.CLIError("Auto recreate is disabled. Use a different AuthSession or update it by running 'intuned run authsession update <id>' command.");
43
43
  }
44
44
  const {
45
45
  metadata
46
46
  } = await (0, _helpers.loadAuthSessionInstance)(id);
47
47
  if (metadata?.authSessionType === "MANUAL") {
48
- throw new _helpers.CLIError("Auth session is recorder-based, please provide a new one or update it manually");
48
+ throw new _helpers.CLIError("AuthSession is recorder-based, it cannot be auto-recreated. Use a different AuthSession.");
49
49
  }
50
50
  (0, _terminal.terminal)("^+Auto recreate is enabled - trying to re-create it^:\n");
51
51
  await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "create");
@@ -63,10 +63,10 @@ async function executeRunValidateAuthSessionCLI({
63
63
  ...rest
64
64
  });
65
65
  if (!checkResult) {
66
- throw new _helpers.CLIError("Failed to re-create auth session");
66
+ throw new _helpers.CLIError("Failed to re-create AuthSession");
67
67
  }
68
68
  }
69
- (0, _terminal.terminal)(`^+^gAuth session validated successfully^:\n`);
69
+ (0, _terminal.terminal)(`^+^gAuthSession validated successfully^:\n`);
70
70
  return storageState;
71
71
  }
72
72
  async function executeRunCreateAuthSessionCLI({
@@ -78,7 +78,7 @@ async function executeRunCreateAuthSessionCLI({
78
78
  ...rest
79
79
  }) {
80
80
  id = id ?? generateAuthSessionId();
81
- (0, _terminal.terminal)(`^+Creating auth session with id ^c${id}^:\n`);
81
+ (0, _terminal.terminal)(`^+Creating AuthSession with id ^c${id}^:\n`);
82
82
  await Promise.all([await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "create"), await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "check")]);
83
83
  const createdStorageState = await runCreateWithRetries({
84
84
  authSessionId: id,
@@ -93,10 +93,10 @@ async function executeRunCreateAuthSessionCLI({
93
93
  ...rest
94
94
  });
95
95
  if (!checkResult) {
96
- throw new _helpers.CLIError("Failed to create auth session");
96
+ throw new _helpers.CLIError("Failed to create AuthSession");
97
97
  }
98
98
  if (log) {
99
- (0, _terminal.terminal)(`^+^gAuth session created successfully^:\n`);
99
+ (0, _terminal.terminal)(`^+^gAuthSession created successfully^:\n`);
100
100
  }
101
101
  return auth;
102
102
  }
@@ -107,14 +107,14 @@ async function executeRunUpdateAuthSessionCLI({
107
107
  createRetries,
108
108
  ...rest
109
109
  }) {
110
- (0, _terminal.terminal)(`^+Updating auth session with id ^c${id}^:\n`);
110
+ (0, _terminal.terminal)(`^+Updating AuthSession with id ^c${id}^:\n`);
111
111
  let metadata = undefined;
112
112
  if (input === undefined) {
113
113
  ({
114
114
  metadata
115
115
  } = await (0, _helpers.loadAuthSessionInstance)(id));
116
116
  if (metadata?.authSessionType === "MANUAL") {
117
- throw new _helpers.CLIError("Auth session is recorder-based, it cannot be updated.");
117
+ throw new _helpers.CLIError("AuthSession is recorder-based, it cannot be updated. Use a different AuthSession.");
118
118
  }
119
119
  input = metadata?.authSessionInput ?? {};
120
120
  }
@@ -128,7 +128,7 @@ async function executeRunUpdateAuthSessionCLI({
128
128
  metadata,
129
129
  ...rest
130
130
  });
131
- (0, _terminal.terminal)(`^+^gAuth session updated successfully^:\n`);
131
+ (0, _terminal.terminal)(`^+^gAuthSession updated successfully^:\n`);
132
132
  return authSession;
133
133
  }
134
134
  async function executeAttemptCreateAuthSessionCLI({
@@ -137,7 +137,7 @@ async function executeAttemptCreateAuthSessionCLI({
137
137
  ...rest
138
138
  }) {
139
139
  id = id ?? generateAuthSessionId(true);
140
- (0, _terminal.terminal)(`^+Executing create auth session attempt with id ^c${id}^:\n`);
140
+ (0, _terminal.terminal)(`^+Executing create AuthSession attempt with id ^c${id}^:\n`);
141
141
  await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "create");
142
142
  return await runCreateWithRetries({
143
143
  authSessionId: id,
@@ -149,7 +149,7 @@ async function executeAttemptCheckAuthSessionCLI({
149
149
  id,
150
150
  ...rest
151
151
  }) {
152
- (0, _terminal.terminal)(`^+Executing check auth session attempt with id ^c${id}^:\n`);
152
+ (0, _terminal.terminal)(`^+Executing check AuthSession attempt with id ^c${id}^:\n`);
153
153
  await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "check");
154
154
  (0, _helpers.registerGetAuthSessionParameters)(id);
155
155
  const {
@@ -162,7 +162,7 @@ async function executeAttemptCheckAuthSessionCLI({
162
162
  if (!checkResult) {
163
163
  throw new _helpers.CLIError("Check failed");
164
164
  }
165
- (0, _terminal.terminal)(`^+^gAuth session check passed^:\n`);
165
+ (0, _terminal.terminal)(`^+^gAuthSession check passed^:\n`);
166
166
  return storageState;
167
167
  }
168
168
  async function runCheck({
@@ -245,7 +245,7 @@ async function runCheckWithRetries({
245
245
  ...rest
246
246
  }) {
247
247
  for (let i = 0; i < (retries ?? 1); i++) {
248
- (0, _terminal.terminal)(`\n^+Running ^cauth session check${i === 0 ? "" : ` ^/(Attempt ${i + 1})`}^:...\n`);
248
+ (0, _terminal.terminal)(`\n^+Running ^cAuthSession check${i === 0 ? "" : ` ^/(Attempt ${i + 1})`}^:...\n`);
249
249
  try {
250
250
  let traceId = undefined;
251
251
  if (rest.trace) {
@@ -260,7 +260,7 @@ async function runCheckWithRetries({
260
260
  ...rest
261
261
  });
262
262
  if (checkResult) {
263
- (0, _terminal.terminal)(`^+^gAuth session check passed^:\n`);
263
+ (0, _terminal.terminal)(`^+^gAuthSession check passed^:\n`);
264
264
  return true;
265
265
  }
266
266
  } catch (error) {
@@ -270,9 +270,9 @@ async function runCheckWithRetries({
270
270
  throw error;
271
271
  }
272
272
  }
273
- (0, _terminal.terminal)(`^+^yAuth session check failed^:\n`);
273
+ (0, _terminal.terminal)(`^+^yAuthSession check failed^:\n`);
274
274
  }
275
- (0, _terminal.terminal)(`^+^rAuth session check failed after ${retries} attempts^:\n`);
275
+ (0, _terminal.terminal)(`^+^rAuthSession check failed after ${retries} attempts^:\n`);
276
276
  return false;
277
277
  }
278
278
  const _runCheckWithRetries = exports._runCheckWithRetries = runCheckWithRetries;
@@ -286,7 +286,7 @@ async function runCreateWithRetries({
286
286
  }) {
287
287
  let newAuthSessionInstance = null;
288
288
  for (let i = 0; i < (retries ?? 1); i++) {
289
- (0, _terminal.terminal)(`\n^+Running ^cauth session create${i === 0 ? "" : ` ^/(Attempt ${i + 1})`}^:...\n`);
289
+ (0, _terminal.terminal)(`\n^+Running ^cAuthSession create${i === 0 ? "" : ` ^/(Attempt ${i + 1})`}^:...\n`);
290
290
  try {
291
291
  let traceId = undefined;
292
292
  if (trace) {
@@ -300,7 +300,7 @@ async function runCreateWithRetries({
300
300
  traceId,
301
301
  ...rest
302
302
  });
303
- (0, _terminal.terminal)(`^+^gAuth session create succeeded^:\n`);
303
+ (0, _terminal.terminal)(`^+^gAuthSession create succeeded^:\n`);
304
304
  break;
305
305
  } catch (error) {
306
306
  if (error instanceof _runApi.RunAutomationError) {
@@ -308,11 +308,11 @@ async function runCreateWithRetries({
308
308
  } else {
309
309
  throw error;
310
310
  }
311
- (0, _terminal.terminal)(`^+^yAuth session create failed^:\n`);
311
+ (0, _terminal.terminal)(`^+^yAuthSession create failed^:\n`);
312
312
  }
313
313
  }
314
314
  if (!newAuthSessionInstance) {
315
- throw new _helpers.CLIError(`Failed to create auth session after ${retries} retries`);
315
+ throw new _helpers.CLIError(`Failed to create AuthSession after ${retries} retries. Check errors above for more details.`);
316
316
  }
317
317
  await (0, _helpers.storeAuthSessionInstance)({
318
318
  state: newAuthSessionInstance,
@@ -336,7 +336,7 @@ async function executeRecordAuthSessionCLI({
336
336
  finishUrl
337
337
  }) {
338
338
  id = id ?? generateAuthSessionId();
339
- (0, _terminal.terminal)(`^+Recording auth session with id ^c${id}^:\n`);
339
+ (0, _terminal.terminal)(`^+Recording AuthSession with id ^c${id}^:\n`);
340
340
  let authSession;
341
341
  try {
342
342
  authSession = await recordAuthSession({
@@ -347,7 +347,7 @@ async function executeRecordAuthSessionCLI({
347
347
  });
348
348
  } catch (error) {
349
349
  if (error instanceof _helpers.CLIError) {
350
- throw new _helpers.CLIError(`Failed to record auth session: ${error.message}`);
350
+ throw new _helpers.CLIError(`Failed to record AuthSession: ${error.message}`);
351
351
  }
352
352
  throw error;
353
353
  }
@@ -375,7 +375,7 @@ async function executeRecordAuthSessionCLI({
375
375
  trace,
376
376
  keepBrowserOpen
377
377
  });
378
- (0, _terminal.terminal)(`^+^gAuth session ^c${id}^ ^+^grecorded successfully^:\n`);
378
+ (0, _terminal.terminal)(`^+^gAuthSession ^c${id}^ ^+^grecorded successfully^:\n`);
379
379
  }
380
380
  async function recordAuthSession({
381
381
  startUrl,
@@ -400,17 +400,17 @@ async function recordAuthSession({
400
400
  const timeoutTimestamp = Date.now() + timeout;
401
401
  while (true) {
402
402
  if (Date.now() > timeoutTimestamp) {
403
- throw new _helpers.CLIError("Timeout waiting for finish URL");
403
+ throw new _helpers.CLIError("AuthSession recording failed - Timeout waiting for finish URL");
404
404
  }
405
405
  if (context.pages().length === 0) {
406
- throw new _helpers.CLIError("Browser was closed before reaching the finish URL");
406
+ throw new _helpers.CLIError("AuthSession recording failed - Browser was closed before reaching the finish URL");
407
407
  }
408
408
  if (context.pages()[0].url().startsWith(finishUrl)) {
409
409
  break;
410
410
  }
411
411
  await (0, _promises.setTimeout)(1000);
412
412
  }
413
- (0, _terminal.terminal)(`^+Finish URL reached, capturing auth session...^:\n`);
413
+ (0, _terminal.terminal)(`^+Finish URL reached, capturing AuthSession...^:\n`);
414
414
  await page.waitForLoadState("load");
415
415
  const authSession = await (0, _contextStorageStateHelpers.getStorageState)(context);
416
416
  return authSession;
@@ -11,23 +11,63 @@ var _helpers = require("../helpers");
11
11
  var _terminal = require("../helpers/terminal");
12
12
  var _promises = require("timers/promises");
13
13
  var _ms = _interopRequireDefault(require("ms"));
14
- var _save = require("./save");
14
+ var _provision = require("./provision");
15
15
  var _constants2 = require("../../../common/constants");
16
16
  var _path = _interopRequireDefault(require("path"));
17
17
  var fs = _interopRequireWildcard(require("fs-extra"));
18
18
  var _prompts = _interopRequireDefault(require("prompts"));
19
19
  var _terminalLink = _interopRequireDefault(require("terminal-link"));
20
+ var _pressAnyKey = _interopRequireDefault(require("press-any-key"));
20
21
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
21
22
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
22
23
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
23
24
  const START_RUN_INPUT_QUERY_PARAM_KEY = exports.START_RUN_INPUT_QUERY_PARAM_KEY = "startRunInput";
24
25
  async function runDeployProject(projectName, auth) {
25
- const result = await (0, _save.runSaveProject)(projectName, auth);
26
- const enableFirstRunExperience = result?.enableFirstRunExperience ?? false;
26
+ let enableFirstRunExperience = false;
27
27
  let firstRunExperienceInput = undefined;
28
28
  const settings = await (0, _helpers.loadIntunedJson)();
29
- if (enableFirstRunExperience) {
30
- firstRunExperienceInput = await promptFirstRunExperience(settings);
29
+ const provisionResult = await (0, _provision.runProvisionProject)(projectName, auth, true);
30
+ if (provisionResult) {
31
+ enableFirstRunExperience = provisionResult?.enableFirstRunExperience ?? false;
32
+ if (enableFirstRunExperience) {
33
+ firstRunExperienceInput = await promptFirstRunExperience(settings);
34
+ }
35
+ const {
36
+ projectId,
37
+ dotenvContent,
38
+ environmentVariablesKeys
39
+ } = provisionResult;
40
+ if (dotenvContent) {
41
+ const dotenvKeys = Object.keys(dotenvContent);
42
+ const missingKeys = dotenvKeys.filter(key => dotenvContent[key] && !environmentVariablesKeys.includes(key));
43
+ if (missingKeys.length > 0) {
44
+ (0, _terminal.terminal)(`^yWarning: The following environment variables are defined in your .env file but are not defined on Intuned platform^:\n`);
45
+ for (const key of missingKeys) {
46
+ (0, _terminal.terminal)(`^y • ${key}^:\n`);
47
+ }
48
+ (0, _terminal.terminal)(`^yPlease add them to your project or workspace on Intuned platform to ensure proper functionality.^:\n`);
49
+ const projectEnvVarsUrl = `${(0, _helpers.getBaseUrl)()}/projects/${projectId}/env-vars`;
50
+ const workspaceEnvVarsUrl = `${(0, _helpers.getBaseUrl)()}/settings/env-vars`;
51
+ if (_terminalLink.default.isSupported) {
52
+ const projectEnvVarsTerminalLink = (0, _terminalLink.default)(`[ Project Env Vars ]`, projectEnvVarsUrl).replaceAll("%", "%%");
53
+ const workspaceEnvVarsTerminalLink = (0, _terminalLink.default)(`[ Workspace Env Vars ]`, workspaceEnvVarsUrl).replaceAll("%", "%%");
54
+ (0, _terminal.terminal)(`^Y${projectEnvVarsTerminalLink} ${workspaceEnvVarsTerminalLink}^:\n`);
55
+ } else {
56
+ (0, _terminal.terminal)(`^yProject Env Vars: ^_${projectEnvVarsUrl}^:\n`);
57
+ (0, _terminal.terminal)(`^yWorkspace Env Vars: ^_${workspaceEnvVarsUrl}^:\n`);
58
+ }
59
+ try {
60
+ (0, _terminal.terminal)("Press any key to continue...");
61
+ await (0, _pressAnyKey.default)("", {
62
+ ctrlC: "reject",
63
+ hideMessage: true
64
+ });
65
+ (0, _terminal.terminal)("\n");
66
+ } catch {
67
+ throw new _helpers.AbortedCLIError();
68
+ }
69
+ }
70
+ }
31
71
  }
32
72
  const {
33
73
  workspaceId,
@@ -48,9 +88,9 @@ async function runDeployProject(projectName, auth) {
48
88
  });
49
89
  if (!response.ok) {
50
90
  if (response.status === 401) {
51
- throw new _helpers.CLIError(`Invalid API key. Please check your API key and try again.`);
91
+ 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`);
52
92
  }
53
- throw new _helpers.CLIError(`^r^+Invalid response from server\n^:^R${response.status} ${await response.text()}^:\n^r^+Project deployment failed^:\n`, {
93
+ 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`, {
54
94
  autoColor: false
55
95
  });
56
96
  }
@@ -90,7 +130,7 @@ async function runDeployProject(projectName, auth) {
90
130
  if (status === "pending") {
91
131
  const elapsedTime = Date.now() - startTime;
92
132
  if (elapsedTime > _constants.PROJECT_DEPLOY_TIMEOUT) {
93
- throw new _helpers.CLIError(`Deployment timed out after ${Math.floor(_constants.PROJECT_DEPLOY_TIMEOUT / (0, _ms.default)("1 minute"))} minutes`);
133
+ throw new _helpers.CLIError(`Deployment failed - timed out after ${Math.floor(_constants.PROJECT_DEPLOY_TIMEOUT / (0, _ms.default)("1 minute"))} minutes`);
94
134
  }
95
135
  continue;
96
136
  }
@@ -140,8 +180,10 @@ async function runDeployProject(projectName, auth) {
140
180
  let errorMessage = `^r^+An error occurred while deploying project:^:\n^R${message}^:\n`;
141
181
  if (rest.reason) {
142
182
  errorMessage += `^r^+Reason:^:\n^R${rest.reason}^:\n`;
183
+ } else {
184
+ errorMessage += `^r^+Unknown error occurred, please report this issue to the Intuned team.^:\n`;
143
185
  }
144
- errorMessage += `^r^+Project deployment failed^:\n`;
186
+ errorMessage += `^r^+Deployment failed^:\n`;
145
187
  throw new _helpers.CLIError(errorMessage, {
146
188
  autoColor: false
147
189
  });
@@ -222,7 +264,7 @@ async function promptFirstRunExperienceTestAuthSessionParameters({
222
264
  if (!metadata.authSessionId) {
223
265
  return;
224
266
  }
225
- const message = shouldPromptForDefaultJob ? `^:^+Create a test auth session using^ ^c${authSessionId}^:^+ parameters?^ ^/(required for creating default job)^:` : `^:^+Create a test auth session using^ ^c${authSessionId}^:^+ parameters?^:`;
267
+ const message = shouldPromptForDefaultJob ? `^:^+Create a test AuthSession using^ ^c${authSessionId}^:^+ parameters?^ ^/(required for creating default job)^:` : `^:^+Create a test AuthSession using^ ^c${authSessionId}^:^+ parameters?^:`;
226
268
  const {
227
269
  value
228
270
  } = await (0, _prompts.default)({
@@ -16,7 +16,7 @@ async function loadParameters(parameters) {
16
16
  try {
17
17
  inputData = JSON.parse(parameters);
18
18
  } catch (err) {
19
- throw new _helpers.CLIError("Parameters must be a valid JSON string or a path to a JSON file");
19
+ throw new _helpers.CLIError("Invalid parameters - must be a valid JSON string or a path to a JSON file");
20
20
  }
21
21
  }
22
22
  return inputData;
@@ -1,8 +1,12 @@
1
1
  import { z } from "zod";
2
2
  import type { AuthCredentials } from "../types";
3
- export declare function runSaveProject(projectName: string, auth: AuthCredentials): Promise<{
3
+ export declare function runProvisionProject(projectName: string, auth: AuthCredentials, silent?: boolean): Promise<{
4
4
  projectId: string;
5
5
  enableFirstRunExperience: boolean | undefined;
6
+ environmentVariablesKeys: string[];
7
+ dotenvContent: {
8
+ [x: string]: string;
9
+ };
6
10
  } | undefined>;
7
11
  export declare const projectNameSchema: z.ZodEffects<z.ZodString, string, string>;
8
12
  export declare const validateProjectName: (projectName: string) => {