@intuned/runtime-dev 1.3.4-dev.4 → 1.3.4-enhancements.1

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 (70) hide show
  1. package/WebTemplate.zip +0 -0
  2. package/bin/intuned +0 -0
  3. package/dist/commands/api/run.js +1 -2
  4. package/dist/commands/auth-sessions/run-check.js +0 -1
  5. package/dist/commands/auth-sessions/run-create.js +0 -1
  6. package/dist/commands/common/projectExclusions.js +1 -1
  7. package/dist/commands/common/tsNodeImport.js +1 -1
  8. package/dist/commands/common/utils/settings.js +5 -7
  9. package/dist/commands/intuned-cli/commands/attempt_api.command.js +10 -20
  10. package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.js +2 -7
  11. package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.js +5 -17
  12. package/dist/commands/intuned-cli/commands/authsession.command.d.ts +1 -0
  13. package/dist/commands/intuned-cli/commands/authsession.command.js +8 -0
  14. package/dist/commands/intuned-cli/commands/authsession_record.command.d.ts +1 -0
  15. package/dist/commands/intuned-cli/commands/authsession_record.command.js +31 -0
  16. package/dist/commands/intuned-cli/commands/build.command.js +1 -1
  17. package/dist/commands/intuned-cli/commands/deploy.command.js +2 -7
  18. package/dist/commands/intuned-cli/commands/index.d.ts +2 -0
  19. package/dist/commands/intuned-cli/commands/index.js +22 -0
  20. package/dist/commands/intuned-cli/commands/init.command.js +1 -1
  21. package/dist/commands/intuned-cli/commands/run_api.command.js +13 -21
  22. package/dist/commands/intuned-cli/commands/run_authsession.command.d.ts +9 -1
  23. package/dist/commands/intuned-cli/commands/run_authsession.command.js +5 -1
  24. package/dist/commands/intuned-cli/commands/run_authsession_create.command.d.ts +1 -1
  25. package/dist/commands/intuned-cli/commands/run_authsession_create.command.js +16 -20
  26. package/dist/commands/intuned-cli/commands/run_authsession_update.command.d.ts +1 -1
  27. package/dist/commands/intuned-cli/commands/run_authsession_update.command.js +16 -20
  28. package/dist/commands/intuned-cli/commands/run_authsession_validate.command.d.ts +1 -1
  29. package/dist/commands/intuned-cli/commands/run_authsession_validate.command.js +16 -20
  30. package/dist/commands/intuned-cli/commands/save.command.d.ts +3 -2
  31. package/dist/commands/intuned-cli/commands/save.command.js +6 -10
  32. package/dist/commands/intuned-cli/commands/types.d.ts +10 -0
  33. package/dist/commands/intuned-cli/commands/types.js +11 -3
  34. package/dist/commands/intuned-cli/controller/__test__/api.test.js +128 -10
  35. package/dist/commands/intuned-cli/controller/__test__/authSession.test.js +428 -45
  36. package/dist/commands/intuned-cli/controller/api.d.ts +5 -7
  37. package/dist/commands/intuned-cli/controller/api.js +16 -7
  38. package/dist/commands/intuned-cli/controller/authSession.d.ts +18 -7
  39. package/dist/commands/intuned-cli/controller/authSession.js +153 -24
  40. package/dist/commands/intuned-cli/controller/save.js +10 -3
  41. package/dist/commands/intuned-cli/helpers/__test__/browser.test.js +103 -0
  42. package/dist/commands/intuned-cli/helpers/__test__/tracing.test.js +40 -0
  43. package/dist/commands/intuned-cli/helpers/auth.d.ts +7 -2
  44. package/dist/commands/intuned-cli/helpers/auth.js +38 -23
  45. package/dist/commands/intuned-cli/helpers/backend.d.ts +1 -1
  46. package/dist/commands/intuned-cli/helpers/backend.js +2 -2
  47. package/dist/commands/intuned-cli/helpers/browser.d.ts +14 -0
  48. package/dist/commands/intuned-cli/helpers/browser.js +57 -0
  49. package/dist/commands/intuned-cli/helpers/errors.d.ts +0 -1
  50. package/dist/commands/intuned-cli/helpers/errors.js +0 -22
  51. package/dist/commands/intuned-cli/helpers/index.d.ts +2 -0
  52. package/dist/commands/intuned-cli/helpers/index.js +22 -0
  53. package/dist/commands/intuned-cli/helpers/intunedJson.d.ts +69 -1
  54. package/dist/commands/intuned-cli/helpers/intunedJson.js +59 -7
  55. package/dist/commands/intuned-cli/helpers/traces.d.ts +2 -0
  56. package/dist/commands/intuned-cli/helpers/traces.js +32 -0
  57. package/dist/commands/intuned-cli/helpers/validation.js +5 -3
  58. package/dist/commands/intuned-cli/helpers/wrapper.d.ts +2 -0
  59. package/dist/commands/intuned-cli/helpers/wrapper.js +60 -0
  60. package/dist/common/constants.d.ts +0 -1
  61. package/dist/common/constants.js +1 -2
  62. package/dist/common/playwrightContext.d.ts +1 -0
  63. package/dist/common/playwrightContext.js +5 -18
  64. package/dist/common/runApi/types.d.ts +0 -5
  65. package/dist/common/runApi/types.js +1 -2
  66. package/dist/common/settingsSchema.d.ts +0 -513
  67. package/dist/common/settingsSchema.js +2 -40
  68. package/package.json +4 -1
  69. package/dist/common/extensionsHelpers.d.ts +0 -15
  70. package/dist/common/extensionsHelpers.js +0 -84
@@ -32,10 +32,15 @@ export declare function loadAuthSessionInstance(authSessionId: string): Promise<
32
32
  };
33
33
  metadata: AuthSessionMetadata;
34
34
  }>;
35
- export declare function storeAuthSessionInstance({ state, id, input, proxy, }: {
35
+ export declare function storeAuthSessionInstance({ state, id, input, proxy, metadata, }: {
36
36
  state: StorageState;
37
- id?: string;
37
+ id: string;
38
38
  input?: Record<string, any>;
39
39
  proxy?: string;
40
+ metadata?: AuthSessionMetadata;
40
41
  }): Promise<string>;
41
42
  export declare function registerGetAuthSessionParameters(authSessionId?: string): void;
43
+ export declare function getAuthSessionRecorderParameters(): Promise<{
44
+ startUrl: string;
45
+ finishUrl: string;
46
+ }>;
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.assertAuthConsistent = assertAuthConsistent;
7
7
  exports.assertAuthEnabled = assertAuthEnabled;
8
+ exports.getAuthSessionRecorderParameters = getAuthSessionRecorderParameters;
8
9
  exports.isAuthEnabled = isAuthEnabled;
9
10
  exports.loadAuthSessionInstance = loadAuthSessionInstance;
10
11
  exports.registerGetAuthSessionParameters = registerGetAuthSessionParameters;
@@ -20,7 +21,7 @@ var _asyncLocalStorage = require("../../../common/asyncLocalStorage");
20
21
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
21
22
  async function isAuthEnabled() {
22
23
  try {
23
- const intunedJson = await (0, _fsExtra.readJSON)(_path.default.join(process.cwd(), "Intuned.json"));
24
+ const intunedJson = await (0, _intunedJson.loadIntunedJson)();
24
25
  return Boolean(intunedJson?.authSessions?.enabled);
25
26
  } catch (error) {
26
27
  return false;
@@ -28,7 +29,7 @@ async function isAuthEnabled() {
28
29
  }
29
30
  async function assertAuthEnabled() {
30
31
  if (!(await isAuthEnabled())) {
31
- throw new _errors.CLIAssertionError("Auth session is not enabled, enable it in Intuned.json to use it");
32
+ throw new _errors.CLIAssertionError(`Auth session is not enabled, enable it in ${await (0, _intunedJson.getIntunedSettingsFileName)()} to use it`);
32
33
  }
33
34
  }
34
35
  async function assertAuthConsistent(authSession) {
@@ -37,7 +38,7 @@ async function assertAuthConsistent(authSession) {
37
38
  throw new _errors.CLIAssertionError("Auth session is enabled, but no auth session is provided. Please provide an auth session ID.");
38
39
  }
39
40
  if (!_isAuthEnabled && authSession) {
40
- throw new _errors.CLIAssertionError("Auth session is not enabled, enable it in Intuned.json to use it");
41
+ throw new _errors.CLIAssertionError(`Auth session is not enabled, enable it in ${await (0, _intunedJson.getIntunedSettingsFileName)()} to use it`);
41
42
  }
42
43
  }
43
44
  async function loadAuthSessionInstance(authSessionId) {
@@ -66,43 +67,37 @@ async function storeAuthSessionInstance({
66
67
  state,
67
68
  id,
68
69
  input,
69
- proxy
70
+ proxy,
71
+ metadata
70
72
  }) {
71
73
  try {
72
74
  const authSessionsDirectoryPath = _path.default.join(process.cwd(), _constants.AUTH_SESSIONS_INSTANCES_FOLDER_NAME);
73
75
  await (0, _fsExtra.ensureDir)(authSessionsDirectoryPath);
74
- const authSessionInstanceId = id ?? `auth-session-${Date.now()}`;
75
- const authSessionInstancePath = _path.default.join(authSessionsDirectoryPath, authSessionInstanceId);
76
- const authSessionExists = await (0, _fsExtra.pathExists)(authSessionInstancePath);
76
+ const authSessionInstancePath = _path.default.join(authSessionsDirectoryPath, id);
77
77
  await (0, _fsExtra.ensureDir)(authSessionInstancePath);
78
78
  const authSessionInstanceStoragePath = _path.default.join(authSessionInstancePath, `auth-session.json`);
79
79
  await (0, _fsExtra.writeJSON)(authSessionInstanceStoragePath, state, {
80
80
  spaces: 2
81
81
  });
82
- const projectAuthConfig = await (0, _intunedJson.getSettingIntunedJSON)("authSessions");
83
- let existingMetadata = {};
84
- const authSessionInstanceMetadataPath = _path.default.join(authSessionInstancePath, `metadata.json`);
85
- if (authSessionExists) {
86
- try {
87
- existingMetadata = await (0, _fsExtra.readJSON)(authSessionInstanceMetadataPath);
88
- } catch (readError) {
89
- existingMetadata = {};
90
- }
82
+ const projectAuthConfig = (await (0, _intunedJson.loadIntunedJson)()).authSessions;
83
+ if (!projectAuthConfig.enabled) {
84
+ throw new _errors.CLIError(`Auth sessions are not enabled in ${await (0, _intunedJson.getIntunedSettingsFileName)()}`);
91
85
  }
86
+ const authSessionInstanceMetadataPath = _path.default.join(authSessionInstancePath, `metadata.json`);
92
87
  const authSessionMetadata = {
93
- createdAt: existingMetadata.createdAt || new Date().toISOString(),
88
+ createdAt: metadata?.createdAt ?? new Date().toISOString(),
94
89
  updatedAt: new Date().toISOString(),
95
90
  ...(projectAuthConfig.type === "API" && {
96
- authSessionInput: input || existingMetadata.authSessionInput || {}
91
+ authSessionInput: input || metadata?.authSessionInput || {}
97
92
  }),
98
- authSessionId: authSessionInstanceId,
99
- authSessionType: projectAuthConfig.type ?? existingMetadata.authSessionType ?? "API",
93
+ authSessionId: id,
94
+ authSessionType: projectAuthConfig.type ?? metadata?.authSessionType ?? "API",
100
95
  ...(projectAuthConfig.type === "MANUAL" && {
101
96
  recorderStartUrl: projectAuthConfig.startUrl,
102
- recorderEndUrl: projectAuthConfig.endUrl
97
+ recorderEndUrl: projectAuthConfig.finishUrl
103
98
  }),
104
- authSessionInput: input || existingMetadata.authSessionInput || {},
105
- authSessionProxy: proxy || existingMetadata.authSessionProxy
99
+ authSessionInput: input || metadata?.authSessionInput || {},
100
+ authSessionProxy: proxy || metadata?.authSessionProxy
106
101
  };
107
102
  await (0, _fsExtra.writeJSON)(authSessionInstanceMetadataPath, authSessionMetadata, {
108
103
  spaces: 2
@@ -126,4 +121,24 @@ function registerGetAuthSessionParameters(authSessionId) {
126
121
  return metadata?.authSessionInput ?? {};
127
122
  }
128
123
  (0, _asyncLocalStorage.getExecutionContext)().getAuthSessionParameters = getAuthSessionParameters;
124
+ }
125
+ async function getAuthSessionRecorderParameters() {
126
+ const intunedJson = await (0, _intunedJson.loadIntunedJson)();
127
+ if (!intunedJson.authSessions.enabled) {
128
+ throw new _errors.CLIError(`Auth sessions are not enabled in ${await (0, _intunedJson.getIntunedSettingsFileName)()}`);
129
+ }
130
+ if (intunedJson.authSessions.type !== "MANUAL") {
131
+ throw new _errors.CLIError(`Auth session type is not recorder-based in ${await (0, _intunedJson.getIntunedSettingsFileName)()}`);
132
+ }
133
+ const {
134
+ startUrl,
135
+ finishUrl
136
+ } = intunedJson.authSessions;
137
+ if (startUrl === undefined || finishUrl === undefined) {
138
+ throw new _errors.CLIError(`Auth session type is recorder-based but start_url or finish_url is not set in ${await (0, _intunedJson.getIntunedSettingsFileName)()}`);
139
+ }
140
+ return {
141
+ startUrl,
142
+ finishUrl
143
+ };
129
144
  }
@@ -2,7 +2,7 @@ export declare function getAuthCredentials(options: {
2
2
  workspaceId?: string;
3
3
  apiKey?: string;
4
4
  }): Promise<{
5
- workspaceId: any;
5
+ workspaceId: string;
6
6
  apiKey: string;
7
7
  }>;
8
8
  export declare function getBaseUrl(): string;
@@ -9,10 +9,10 @@ var _constants = require("../../../common/constants");
9
9
  var _errors = require("./errors");
10
10
  var _intunedJson = require("./intunedJson");
11
11
  async function getAuthCredentials(options) {
12
- const workspaceId = options.workspaceId || (await (0, _intunedJson.getSettingIntunedJSON)("workspaceId"));
12
+ const workspaceId = options.workspaceId || (await (0, _intunedJson.loadIntunedJson)()).workspaceId;
13
13
  const apiKey = options.apiKey || process.env[_constants.API_KEY_ENV_VAR_KEY];
14
14
  if (!workspaceId) {
15
- throw new _errors.CLIError("Workspace ID is required. Please provide it via command line options or Intuned.json");
15
+ throw new _errors.CLIError(`Workspace ID is required. Please provide it via command line options or ${await (0, _intunedJson.getIntunedSettingsFileName)()}`);
16
16
  }
17
17
  if (!apiKey) {
18
18
  throw new _errors.CLIError(`API key is required. Please provide it via command line options or ${_constants.API_KEY_ENV_VAR_KEY} environment variable.`);
@@ -0,0 +1,14 @@
1
+ import type { BrowserContext } from "playwright";
2
+ import type { runApiParametersSchema } from "../../../common/runApi";
3
+ import { z } from "zod";
4
+ declare let context: BrowserContext | null;
5
+ export declare function _getContextForTest(): typeof context;
6
+ type RunApiRunOptions = z.infer<typeof runApiParametersSchema>["runOptions"];
7
+ export declare function getCLIRunOptions({ headless, proxy, keepBrowserOpen, }: {
8
+ headless: boolean;
9
+ proxy?: string;
10
+ keepBrowserOpen: boolean;
11
+ }): Promise<RunApiRunOptions>;
12
+ export declare function isCliBrowserLaunched(): boolean;
13
+ export declare function closeCliBrowser(): Promise<void>;
14
+ export {};
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports._getContextForTest = _getContextForTest;
7
+ exports.closeCliBrowser = closeCliBrowser;
8
+ exports.getCLIRunOptions = getCLIRunOptions;
9
+ exports.isCliBrowserLaunched = isCliBrowserLaunched;
10
+ var _playwrightContext = require("../../../common/playwrightContext");
11
+ var _portfinder = require("portfinder");
12
+ var _proxy = require("./proxy");
13
+ let context = null;
14
+ function _getContextForTest() {
15
+ if (process.env.NODE_ENV !== "test") {
16
+ throw new Error("_getContextForTest should only be used in tests");
17
+ }
18
+ return context;
19
+ }
20
+ async function getCLIRunOptions({
21
+ headless,
22
+ proxy,
23
+ keepBrowserOpen
24
+ }) {
25
+ if (context) {
26
+ await closeCliBrowser();
27
+ }
28
+ if (!keepBrowserOpen) {
29
+ return {
30
+ environment: "standalone",
31
+ headless,
32
+ proxy: proxy ? (0, _proxy.parseUrlProxy)(proxy) : undefined
33
+ };
34
+ }
35
+ const port = await (0, _portfinder.getPort)({});
36
+ ({
37
+ context
38
+ } = await (0, _playwrightContext.launchChromium)({
39
+ headless,
40
+ proxy: proxy ? (0, _proxy.parseUrlProxy)(proxy) : undefined,
41
+ cdpPort: port
42
+ }));
43
+ return {
44
+ environment: "cdp",
45
+ cdpAddress: `http://localhost:${port}`
46
+ };
47
+ }
48
+ function isCliBrowserLaunched() {
49
+ return context !== null;
50
+ }
51
+ async function closeCliBrowser() {
52
+ if (!context) return;
53
+ try {
54
+ await context.close();
55
+ context = null;
56
+ } catch (e) {}
57
+ }
@@ -11,4 +11,3 @@ export declare class CLIAssertionError extends CLIError {
11
11
  });
12
12
  }
13
13
  export declare function logAutomationError(error: RunAutomationError): void;
14
- export declare function withErrorLogging<T extends any[]>(fn: (...args: T) => Promise<unknown>): (...args: T) => Promise<never>;
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.CLIError = exports.CLIAssertionError = void 0;
7
7
  exports.logAutomationError = logAutomationError;
8
- exports.withErrorLogging = withErrorLogging;
9
8
  var _runApi = require("../../../common/runApi");
10
9
  var _terminal = require("./terminal");
11
10
  class CLIError extends Error {
@@ -35,25 +34,4 @@ function logAutomationError(error) {
35
34
  } else {
36
35
  (0, _terminal.terminal)(`^r${error.message}^:\n`);
37
36
  }
38
- }
39
- function withErrorLogging(fn) {
40
- return async (...args) => {
41
- try {
42
- await fn(...args);
43
- process.exit(0);
44
- } catch (error) {
45
- if (error instanceof CLIError) {
46
- if (error.autoColor) {
47
- (0, _terminal.terminal)(`^r^+${error.message}^:\n`);
48
- } else {
49
- (0, _terminal.terminal)(`${error.message}\n`);
50
- }
51
- } else if (error instanceof _runApi.AutomationError) {
52
- logAutomationError(error);
53
- } else {
54
- (0, _terminal.terminal)(`^r^+An error occurred:^: ^R${error.message}^:\n^r^+Please report this issue to the Intuned team.^:\n`);
55
- }
56
- process.exit(1);
57
- }
58
- };
59
37
  }
@@ -8,3 +8,5 @@ export * from "./timeout";
8
8
  export * from "./validation";
9
9
  export * from "./intunedJson";
10
10
  export * from "./backend";
11
+ export * from "./traces";
12
+ export * from "./wrapper";
@@ -112,4 +112,26 @@ Object.keys(_backend).forEach(function (key) {
112
112
  return _backend[key];
113
113
  }
114
114
  });
115
+ });
116
+ var _traces = require("./traces");
117
+ Object.keys(_traces).forEach(function (key) {
118
+ if (key === "default" || key === "__esModule") return;
119
+ if (key in exports && exports[key] === _traces[key]) return;
120
+ Object.defineProperty(exports, key, {
121
+ enumerable: true,
122
+ get: function () {
123
+ return _traces[key];
124
+ }
125
+ });
126
+ });
127
+ var _wrapper = require("./wrapper");
128
+ Object.keys(_wrapper).forEach(function (key) {
129
+ if (key === "default" || key === "__esModule") return;
130
+ if (key in exports && exports[key] === _wrapper[key]) return;
131
+ Object.defineProperty(exports, key, {
132
+ enumerable: true,
133
+ get: function () {
134
+ return _wrapper[key];
135
+ }
136
+ });
115
137
  });
@@ -1 +1,69 @@
1
- export declare function getSettingIntunedJSON(key: string): Promise<any>;
1
+ import { z } from "zod";
2
+ export declare const intunedJsonSchema: z.ZodObject<{
3
+ authSessions: z.ZodUnion<[z.ZodObject<{
4
+ enabled: z.ZodLiteral<false>;
5
+ }, "strip", z.ZodTypeAny, {
6
+ enabled: false;
7
+ }, {
8
+ enabled: false;
9
+ }>, z.ZodObject<{
10
+ enabled: z.ZodLiteral<true>;
11
+ type: z.ZodEnum<["MANUAL", "API"]>;
12
+ startUrl: z.ZodOptional<z.ZodString>;
13
+ finishUrl: z.ZodOptional<z.ZodString>;
14
+ }, "strip", z.ZodTypeAny, {
15
+ type: "API" | "MANUAL";
16
+ enabled: true;
17
+ startUrl?: string | undefined;
18
+ finishUrl?: string | undefined;
19
+ }, {
20
+ type: "API" | "MANUAL";
21
+ enabled: true;
22
+ startUrl?: string | undefined;
23
+ finishUrl?: string | undefined;
24
+ }>]>;
25
+ projectName: z.ZodOptional<z.ZodString>;
26
+ workspaceId: z.ZodOptional<z.ZodString>;
27
+ }, "strip", z.ZodTypeAny, {
28
+ authSessions: {
29
+ enabled: false;
30
+ } | {
31
+ type: "API" | "MANUAL";
32
+ enabled: true;
33
+ startUrl?: string | undefined;
34
+ finishUrl?: string | undefined;
35
+ };
36
+ projectName?: string | undefined;
37
+ workspaceId?: string | undefined;
38
+ }, {
39
+ authSessions: {
40
+ enabled: false;
41
+ } | {
42
+ type: "API" | "MANUAL";
43
+ enabled: true;
44
+ startUrl?: string | undefined;
45
+ finishUrl?: string | undefined;
46
+ };
47
+ projectName?: string | undefined;
48
+ workspaceId?: string | undefined;
49
+ }>;
50
+ export type IntunedJson = z.infer<typeof intunedJsonSchema>;
51
+ export declare const intunedSettingsFileNames: readonly ["Intuned.json", "Intuned.jsonc", "Intuned.yaml", "Intuned.yml", "Intuned.toml"];
52
+ export declare function loadIntunedJson(): Promise<{
53
+ authSessions: {
54
+ enabled: false;
55
+ } | {
56
+ type: "API" | "MANUAL";
57
+ enabled: true;
58
+ startUrl?: string | undefined;
59
+ finishUrl?: string | undefined;
60
+ };
61
+ projectName?: string | undefined;
62
+ workspaceId?: string | undefined;
63
+ }>;
64
+ export declare function getIntunedSettingsFile(): Promise<{
65
+ name: typeof intunedSettingsFileNames[number];
66
+ path: string;
67
+ parse: (content: string) => any;
68
+ }>;
69
+ export declare function getIntunedSettingsFileName(): Promise<string>;
@@ -3,17 +3,69 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getSettingIntunedJSON = getSettingIntunedJSON;
6
+ exports.getIntunedSettingsFile = getIntunedSettingsFile;
7
+ exports.getIntunedSettingsFileName = getIntunedSettingsFileName;
8
+ exports.intunedSettingsFileNames = exports.intunedJsonSchema = void 0;
9
+ exports.loadIntunedJson = loadIntunedJson;
7
10
  var _path = _interopRequireDefault(require("path"));
8
11
  var fs = _interopRequireWildcard(require("fs-extra"));
12
+ var _zod = require("zod");
13
+ var _errors = require("./errors");
14
+ var _jsoncParser = _interopRequireDefault(require("jsonc-parser"));
15
+ var YAML = _interopRequireWildcard(require("yaml"));
16
+ var TOML = _interopRequireWildcard(require("smol-toml"));
9
17
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
10
18
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
11
19
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
- async function getSettingIntunedJSON(key) {
13
- const intunedJsonPath = _path.default.join(process.cwd(), "Intuned.json");
14
- const intunedJson = await fs.readJSON(intunedJsonPath);
15
- if (intunedJson && intunedJson[key]) {
16
- return intunedJson[key];
20
+ const intunedJsonSchema = exports.intunedJsonSchema = _zod.z.object({
21
+ authSessions: _zod.z.union([_zod.z.object({
22
+ enabled: _zod.z.literal(false)
23
+ }), _zod.z.object({
24
+ enabled: _zod.z.literal(true),
25
+ type: _zod.z.enum(["MANUAL", "API"]),
26
+ startUrl: _zod.z.string().optional(),
27
+ finishUrl: _zod.z.string().optional()
28
+ })]),
29
+ projectName: _zod.z.string().optional(),
30
+ workspaceId: _zod.z.string().optional()
31
+ });
32
+ const intunedSettingsFileNames = exports.intunedSettingsFileNames = ["Intuned.json", "Intuned.jsonc", "Intuned.yaml", "Intuned.yml", "Intuned.toml"];
33
+ async function loadIntunedJson() {
34
+ const settingsFile = await getIntunedSettingsFile();
35
+ const intunedJsonContent = await fs.readFile(settingsFile.path, "utf-8");
36
+ let intunedJson;
37
+ try {
38
+ intunedJson = settingsFile.parse(intunedJsonContent);
39
+ } catch (e) {
40
+ throw new _errors.CLIError(`Failed to parse ${settingsFile.name}: ${e.message}`);
41
+ }
42
+ const parseResult = intunedJsonSchema.safeParse(intunedJson);
43
+ if (!parseResult.success) {
44
+ const formattedError = parseResult.error.errors.map(e => `- ${e.path.join(".")}: ${e.message}`).join("\n");
45
+ throw new _errors.CLIError(`${settingsFile.name} is not valid:\n${formattedError}\nPlease fix the errors and try again.`);
46
+ }
47
+ return parseResult.data;
48
+ }
49
+ const intunedSettingsParsers = {
50
+ "Intuned.json": JSON.parse,
51
+ "Intuned.jsonc": _jsoncParser.default.parse,
52
+ "Intuned.yaml": YAML.parse,
53
+ "Intuned.yml": YAML.parse,
54
+ "Intuned.toml": TOML.parse
55
+ };
56
+ async function getIntunedSettingsFile() {
57
+ for (const fileName of intunedSettingsFileNames) {
58
+ const filePath = _path.default.join(process.cwd(), fileName);
59
+ if (await fs.exists(filePath)) {
60
+ return {
61
+ name: fileName,
62
+ path: filePath,
63
+ parse: intunedSettingsParsers[fileName]
64
+ };
65
+ }
17
66
  }
18
- return null;
67
+ throw new _errors.CLIError(`No Intuned settings file found.`);
68
+ }
69
+ async function getIntunedSettingsFileName() {
70
+ return (await getIntunedSettingsFile()).name;
19
71
  }
@@ -0,0 +1,2 @@
1
+ import { RunApiParameters } from "../../../common/runApi";
2
+ export declare function withCLITrace<T>(fn: (tracing: NonNullable<RunApiParameters["tracing"]>) => T | Promise<T>, id: string | undefined): Promise<T>;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.withCLITrace = withCLITrace;
7
+ var _path = _interopRequireDefault(require("path"));
8
+ var _fsExtra = require("fs-extra");
9
+ var _terminal = require("./terminal");
10
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
+ let _count = 0;
12
+ const _traceDirName = new Date().toISOString();
13
+ function getTracePath(id) {
14
+ _count++;
15
+ return _path.default.join("traces", _traceDirName, `${_count}-${id}.zip`);
16
+ }
17
+ async function withCLITrace(fn, id) {
18
+ if (id === undefined) {
19
+ return fn({
20
+ enabled: false
21
+ });
22
+ }
23
+ const tracePath = getTracePath(id);
24
+ const result = await fn({
25
+ enabled: true,
26
+ filePath: tracePath
27
+ });
28
+ if (await (0, _fsExtra.exists)(tracePath)) {
29
+ (0, _terminal.terminal)(`^+Trace saved to^ ^_${tracePath}^:\n`);
30
+ }
31
+ return result;
32
+ }
@@ -4,9 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.logInvalidInput = logInvalidInput;
7
- var _terminal = require("./terminal");
7
+ var _errors = require("./errors");
8
8
  function logInvalidInput(result) {
9
- (0, _terminal.terminal)("^r^+Invalid input parameters:^: ^R" + result.error.errors.map(({
9
+ throw new _errors.CLIError("^r^+Invalid input parameters:^: ^R" + result.error.errors.map(({
10
10
  message
11
- }) => `^R${message}^:`).join(", ") + "\n");
11
+ }) => `^R${message}^:`).join(", ") + "\n", {
12
+ autoColor: false
13
+ });
12
14
  }
@@ -0,0 +1,2 @@
1
+ import { z } from "zod";
2
+ export declare function cliCommandWrapper<ZArgs extends z.ZodTuple<any> = z.ZodTuple<[]>, ZOptions extends z.ZodObject<any> = z.ZodObject<Record<string, never>>>(argsSchema: ZArgs | undefined, optionsSchema: ZOptions | undefined, fn: (args: z.infer<ZArgs>, options: z.infer<ZOptions>) => Promise<unknown>): (...input: any[]) => Promise<void>;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.cliCommandWrapper = cliCommandWrapper;
7
+ var _terminal = require("./terminal");
8
+ var _runApi = require("../../../common/runApi");
9
+ var _browser = require("./browser");
10
+ var _errors = require("./errors");
11
+ var _zod = require("zod");
12
+ var _validation = require("./validation");
13
+ function cliCommandWrapper(argsSchema, optionsSchema, fn) {
14
+ return async (...input) => {
15
+ let keepBrowserOpen = false;
16
+ try {
17
+ input.pop();
18
+ const options = input.pop() || {};
19
+ const args = input;
20
+ const parseResult = _zod.z.tuple([argsSchema ?? _zod.z.tuple([]), optionsSchema ?? _zod.z.object({})]).safeParse([args, options]);
21
+ if (!parseResult.success) {
22
+ return (0, _validation.logInvalidInput)(parseResult);
23
+ }
24
+ const [_, parsedOptions] = parseResult.data;
25
+ keepBrowserOpen = "keepBrowserOpen" in parsedOptions && parsedOptions.keepBrowserOpen === true;
26
+ if (keepBrowserOpen) {
27
+ (0, _terminal.terminal)(`^+--keep-open is set, the CLI will not close the last browser after the command completes^:\n`);
28
+ }
29
+ await fn(...parseResult.data);
30
+ if (keepBrowserOpen) {
31
+ await waitForUserInput();
32
+ }
33
+ await (0, _browser.closeCliBrowser)();
34
+ process.exit(0);
35
+ } catch (error) {
36
+ if (error instanceof _errors.CLIError) {
37
+ if (error.autoColor) {
38
+ (0, _terminal.terminal)(`^r^+${error.message}^:\n`);
39
+ } else {
40
+ (0, _terminal.terminal)(`${error.message}\n`);
41
+ }
42
+ } else if (error instanceof _runApi.AutomationError) {
43
+ (0, _errors.logAutomationError)(error);
44
+ } else {
45
+ (0, _terminal.terminal)(`^r^+An error occurred:^: ^R${error.message}^:\n^r^+Please report this issue to the Intuned team.^:\n`);
46
+ }
47
+ if (keepBrowserOpen) {
48
+ await waitForUserInput();
49
+ }
50
+ await (0, _browser.closeCliBrowser)();
51
+ process.exit(1);
52
+ }
53
+ };
54
+ }
55
+ async function waitForUserInput() {
56
+ if (!(0, _browser.isCliBrowserLaunched)()) return;
57
+ if (!_terminal.terminalStdout.isTTY) return;
58
+ (0, _terminal.terminal)("Press Enter to continue...");
59
+ await _terminal.terminal.inputField().promise;
60
+ }
@@ -2,7 +2,6 @@ export declare const API_FOLDER_NAME = "api";
2
2
  export declare const AUTH_SESSIONS_FOLDER_NAME = "auth-sessions";
3
3
  export declare const AUTH_SESSIONS_INSTANCES_FOLDER_NAME = "auth-sessions-instances";
4
4
  export declare const WORKSPACE_ID_ENV_VAR_KEY = "INTUNED_WORKSPACE_ID";
5
- export declare const EXTENSION_PATH_ENV_VAR_KEY = "INTUNED_EXTENSION_PATH";
6
5
  export declare const PROJECT_ID_ENV_VAR_KEY = "INTUNED_PROJECT_ID";
7
6
  export declare const API_KEY_ENV_VAR_KEY = "INTUNED_API_KEY";
8
7
  export declare const API_KEY_HEADER_NAME = "x-api-key";
@@ -3,12 +3,11 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.WORKSPACE_ID_ENV_VAR_KEY = exports.PROJECT_ID_ENV_VAR_KEY = exports.EXTENSION_PATH_ENV_VAR_KEY = exports.CLI_ENV_VAR_KEY = exports.AUTH_SESSIONS_INSTANCES_FOLDER_NAME = exports.AUTH_SESSIONS_FOLDER_NAME = exports.API_KEY_HEADER_NAME = exports.API_KEY_ENV_VAR_KEY = exports.API_FOLDER_NAME = exports.API_BASE_URL_ENV_VAR_KEY = void 0;
6
+ exports.WORKSPACE_ID_ENV_VAR_KEY = exports.PROJECT_ID_ENV_VAR_KEY = exports.CLI_ENV_VAR_KEY = exports.AUTH_SESSIONS_INSTANCES_FOLDER_NAME = exports.AUTH_SESSIONS_FOLDER_NAME = exports.API_KEY_HEADER_NAME = exports.API_KEY_ENV_VAR_KEY = exports.API_FOLDER_NAME = exports.API_BASE_URL_ENV_VAR_KEY = void 0;
7
7
  const API_FOLDER_NAME = exports.API_FOLDER_NAME = "api";
8
8
  const AUTH_SESSIONS_FOLDER_NAME = exports.AUTH_SESSIONS_FOLDER_NAME = "auth-sessions";
9
9
  const AUTH_SESSIONS_INSTANCES_FOLDER_NAME = exports.AUTH_SESSIONS_INSTANCES_FOLDER_NAME = "auth-sessions-instances";
10
10
  const WORKSPACE_ID_ENV_VAR_KEY = exports.WORKSPACE_ID_ENV_VAR_KEY = "INTUNED_WORKSPACE_ID";
11
- const EXTENSION_PATH_ENV_VAR_KEY = exports.EXTENSION_PATH_ENV_VAR_KEY = "INTUNED_EXTENSION_PATH";
12
11
  const PROJECT_ID_ENV_VAR_KEY = exports.PROJECT_ID_ENV_VAR_KEY = "INTUNED_PROJECT_ID";
13
12
  const API_KEY_ENV_VAR_KEY = exports.API_KEY_ENV_VAR_KEY = "INTUNED_API_KEY";
14
13
  const API_KEY_HEADER_NAME = exports.API_KEY_HEADER_NAME = "x-api-key";
@@ -13,6 +13,7 @@ export declare function launchChromium(options: {
13
13
  headless: boolean;
14
14
  downloadsPath?: string;
15
15
  cdpPort?: number;
16
+ appModeInitialUrl?: string;
16
17
  }): Promise<{
17
18
  page: playwright.Page;
18
19
  context: playwright.BrowserContext;