@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
@@ -1,7 +1,7 @@
1
1
  import { Payload } from "../../../runtime/export";
2
2
  import { RunApiStorageState } from "../../../common/runApi";
3
3
  import type { BaseCommandOptions } from "../commands/types";
4
- export declare function executeRunApiCLI({ apiName, inputData, retries, authSession, outputFile, ...rest }: {
4
+ export declare function executeRunApiCLI({ apiName, inputData, retries, authSession, outputFile, trace, ...rest }: {
5
5
  apiName: string;
6
6
  inputData: object | null | undefined;
7
7
  retries: number;
@@ -13,7 +13,7 @@ export declare function executeRunApiCLI({ apiName, inputData, retries, authSess
13
13
  };
14
14
  outputFile?: string;
15
15
  } & BaseCommandOptions): Promise<void>;
16
- export declare function executeAttemptApiCLI({ apiName, inputData, authSessionId, outputFile, ...rest }: {
16
+ export declare function executeAttemptApiCLI({ apiName, inputData, authSessionId, outputFile, trace, ...rest }: {
17
17
  apiName: string;
18
18
  inputData: object | null | undefined;
19
19
  authSessionId?: string;
@@ -29,14 +29,12 @@ declare function handleApiResult({ apiResult, outputFile, }: {
29
29
  export declare const _handleApiResult: typeof handleApiResult;
30
30
  declare function writeResultToFile(outputFile: string, result: any, payloadToAppend?: Payload[]): Promise<void>;
31
31
  export declare const _writeResultToFile: typeof writeResultToFile;
32
- declare function attemptApi({ apiName, inputData, auth, proxy, headless, timeout, }: {
32
+ declare function attemptApi({ apiName, inputData, auth, proxy, headless, timeout, traceId, keepBrowserOpen, }: {
33
33
  apiName: string;
34
34
  inputData: object | null | undefined;
35
35
  auth?: RunApiStorageState;
36
- proxy?: string | undefined;
37
- headless: boolean;
38
- timeout: number;
39
- }): Promise<{
36
+ traceId?: string;
37
+ } & Omit<BaseCommandOptions, "trace">): Promise<{
40
38
  result: any;
41
39
  payloadToAppend: Payload[] | undefined;
42
40
  }>;
@@ -13,6 +13,7 @@ var _authSession = require("./authSession");
13
13
  var _helpers = require("../helpers");
14
14
  var _terminal = require("../helpers/terminal");
15
15
  var _constants = require("../../../common/constants");
16
+ var _browser = require("../helpers/browser");
16
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); }
17
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; }
18
19
  async function executeRunApiCLI({
@@ -21,6 +22,7 @@ async function executeRunApiCLI({
21
22
  retries,
22
23
  authSession,
23
24
  outputFile,
25
+ trace,
24
26
  ...rest
25
27
  }) {
26
28
  await (0, _helpers.assertApiFileExists)(_constants.API_FOLDER_NAME, apiName);
@@ -33,6 +35,7 @@ async function executeRunApiCLI({
33
35
  if (authSession) {
34
36
  auth = await (0, _authSession.executeRunValidateAuthSessionCLI)({
35
37
  ...authSession,
38
+ trace,
36
39
  ...rest
37
40
  });
38
41
  }
@@ -41,6 +44,7 @@ async function executeRunApiCLI({
41
44
  apiName,
42
45
  inputData,
43
46
  auth,
47
+ traceId: trace ? `${apiName}-attempt-${i + 1}` : undefined,
44
48
  ...rest
45
49
  });
46
50
  } catch (error) {
@@ -68,6 +72,7 @@ async function executeAttemptApiCLI({
68
72
  inputData,
69
73
  authSessionId,
70
74
  outputFile,
75
+ trace,
71
76
  ...rest
72
77
  }) {
73
78
  (0, _terminal.terminal)(`^+Execute API attempt for ^c${apiName}^:\n`);
@@ -84,6 +89,7 @@ async function executeAttemptApiCLI({
84
89
  apiName,
85
90
  inputData,
86
91
  auth: storageState,
92
+ traceId: trace ? `${apiName}-attempt` : undefined,
87
93
  ...rest
88
94
  });
89
95
  return await handleApiResult({
@@ -142,25 +148,28 @@ async function attemptApi({
142
148
  auth,
143
149
  proxy,
144
150
  headless,
145
- timeout
151
+ timeout,
152
+ traceId,
153
+ keepBrowserOpen
146
154
  }) {
147
- return await (0, _helpers.withTimeout)(async abortSignal => {
155
+ return await (0, _helpers.withTimeout)(async abortSignal => (0, _helpers.withCLITrace)(async tracing => {
148
156
  const runApiResult = await (0, _runApi.runApi)({
149
157
  automationFunction: {
150
158
  name: `${_constants.API_FOLDER_NAME}/${apiName}`,
151
159
  params: inputData
152
160
  },
153
- runOptions: {
161
+ runOptions: await (0, _browser.getCLIRunOptions)({
154
162
  headless,
155
- environment: "standalone",
156
- proxy: proxy ? (0, _helpers.parseUrlProxy)(proxy) : undefined
157
- },
163
+ proxy,
164
+ keepBrowserOpen
165
+ }),
158
166
  auth: auth ? {
159
167
  session: {
160
168
  type: "state",
161
169
  state: auth
162
170
  }
163
171
  } : undefined,
172
+ tracing,
164
173
  importFunction: _tsNodeImport.tsNodeImport,
165
174
  abortSignal
166
175
  });
@@ -175,6 +184,6 @@ async function attemptApi({
175
184
  result,
176
185
  payloadToAppend
177
186
  };
178
- }, timeout);
187
+ }, traceId), timeout);
179
188
  }
180
189
  const _attemptApi = exports._attemptApi = attemptApi;
@@ -1,5 +1,6 @@
1
1
  import type { BaseCommandOptions } from "../commands/types";
2
2
  import { RunApiStorageState } from "../../../common/runApi";
3
+ import { AuthSessionMetadata } from "../types";
3
4
  export declare function executeRunValidateAuthSessionCLI({ id, autoRecreate, checkRetries, createRetries, ...rest }: {
4
5
  id: string;
5
6
  autoRecreate: boolean;
@@ -12,6 +13,7 @@ export declare function executeRunCreateAuthSessionCLI({ id, input, checkRetries
12
13
  checkRetries: number;
13
14
  createRetries: number;
14
15
  log?: boolean;
16
+ metadata?: AuthSessionMetadata;
15
17
  } & BaseCommandOptions): Promise<{
16
18
  cookies: {
17
19
  value: string;
@@ -126,13 +128,15 @@ export declare function executeAttemptCheckAuthSessionCLI({ id, ...rest }: {
126
128
  origin: string;
127
129
  }[] | undefined;
128
130
  }>;
129
- declare function runCheck({ auth, proxy, headless, timeout, }: {
131
+ declare function runCheck({ auth, proxy, headless, timeout, traceId, keepBrowserOpen, }: {
130
132
  auth: RunApiStorageState;
131
- } & BaseCommandOptions): Promise<boolean>;
133
+ traceId?: string;
134
+ } & Omit<BaseCommandOptions, "trace">): Promise<boolean>;
132
135
  export declare const _runCheck: typeof runCheck;
133
- declare function runCreate({ authSessionInput, proxy, headless, timeout, }: {
136
+ declare function runCreate({ authSessionInput, proxy, headless, timeout, traceId, keepBrowserOpen, }: {
134
137
  authSessionInput: Record<string, any>;
135
- } & BaseCommandOptions): Promise<{
138
+ traceId?: string;
139
+ } & Omit<BaseCommandOptions, "trace">): Promise<{
136
140
  cookies: {
137
141
  value: string;
138
142
  name: string;
@@ -161,13 +165,14 @@ declare function runCreate({ authSessionInput, proxy, headless, timeout, }: {
161
165
  export declare const _runCreate: typeof runCreate;
162
166
  declare function runCheckWithRetries({ auth, retries, ...rest }: {
163
167
  auth: RunApiStorageState;
164
- retries: number;
168
+ retries?: number;
165
169
  } & BaseCommandOptions): Promise<boolean>;
166
170
  export declare const _runCheckWithRetries: typeof runCheckWithRetries;
167
- declare function runCreateWithRetries({ authSessionId, authSessionInput, retries, ...rest }: {
171
+ declare function runCreateWithRetries({ authSessionId, authSessionInput, retries, trace, metadata, ...rest }: {
168
172
  authSessionId: string;
169
173
  authSessionInput: any;
170
- retries: number;
174
+ retries?: number;
175
+ metadata?: AuthSessionMetadata;
171
176
  } & BaseCommandOptions): Promise<{
172
177
  cookies: {
173
178
  value: string;
@@ -195,4 +200,10 @@ declare function runCreateWithRetries({ authSessionId, authSessionInput, retries
195
200
  }[] | undefined;
196
201
  }>;
197
202
  export declare const _runCreateWithRetries: typeof runCreateWithRetries;
203
+ export declare function executeRecordAuthSessionCLI({ id, checkRetries, timeout, headless, proxy, trace, keepBrowserOpen, startUrl, finishUrl, }: {
204
+ id?: string;
205
+ checkRetries: number;
206
+ startUrl: string;
207
+ finishUrl: string;
208
+ } & BaseCommandOptions): Promise<void>;
198
209
  export {};
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports._runCreateWithRetries = exports._runCreate = exports._runCheckWithRetries = exports._runCheck = void 0;
7
7
  exports.executeAttemptCheckAuthSessionCLI = executeAttemptCheckAuthSessionCLI;
8
8
  exports.executeAttemptCreateAuthSessionCLI = executeAttemptCreateAuthSessionCLI;
9
+ exports.executeRecordAuthSessionCLI = executeRecordAuthSessionCLI;
9
10
  exports.executeRunCreateAuthSessionCLI = executeRunCreateAuthSessionCLI;
10
11
  exports.executeRunUpdateAuthSessionCLI = executeRunUpdateAuthSessionCLI;
11
12
  exports.executeRunValidateAuthSessionCLI = executeRunValidateAuthSessionCLI;
@@ -14,6 +15,10 @@ var _runApi = require("../../../common/runApi");
14
15
  var _constants = require("../../../common/constants");
15
16
  var _tsNodeImport = require("../../common/tsNodeImport");
16
17
  var _terminal = require("../helpers/terminal");
18
+ var _browser = require("../helpers/browser");
19
+ var _playwrightContext = require("../../../common/playwrightContext");
20
+ var _promises = require("timers/promises");
21
+ var _contextStorageStateHelpers = require("../../../common/contextStorageStateHelpers");
17
22
  async function executeRunValidateAuthSessionCLI({
18
23
  id,
19
24
  autoRecreate,
@@ -49,6 +54,7 @@ async function executeRunValidateAuthSessionCLI({
49
54
  authSessionId: id,
50
55
  authSessionInput,
51
56
  retries: createRetries,
57
+ metadata,
52
58
  ...rest
53
59
  });
54
60
  const checkResult = await runCheckWithRetries({
@@ -71,7 +77,7 @@ async function executeRunCreateAuthSessionCLI({
71
77
  log = true,
72
78
  ...rest
73
79
  }) {
74
- id = id ?? `auth-session-${Date.now()}`;
80
+ id = id ?? generateAuthSessionId();
75
81
  (0, _terminal.terminal)(`^+Creating auth session with id ^c${id}^:\n`);
76
82
  await Promise.all([await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "create"), await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "check")]);
77
83
  const createdStorageState = await runCreateWithRetries({
@@ -102,10 +108,11 @@ async function executeRunUpdateAuthSessionCLI({
102
108
  ...rest
103
109
  }) {
104
110
  (0, _terminal.terminal)(`^+Updating auth session with id ^c${id}^:\n`);
111
+ let metadata = undefined;
105
112
  if (input === undefined) {
106
- const {
113
+ ({
107
114
  metadata
108
- } = await (0, _helpers.loadAuthSessionInstance)(id);
115
+ } = await (0, _helpers.loadAuthSessionInstance)(id));
109
116
  if (metadata?.authSessionType === "MANUAL") {
110
117
  throw new _helpers.CLIError("Auth session is recorder-based, it cannot be updated.");
111
118
  }
@@ -118,6 +125,7 @@ async function executeRunUpdateAuthSessionCLI({
118
125
  checkRetries,
119
126
  createRetries,
120
127
  log: false,
128
+ metadata,
121
129
  ...rest
122
130
  });
123
131
  (0, _terminal.terminal)(`^+^gAuth session updated successfully^:\n`);
@@ -128,13 +136,12 @@ async function executeAttemptCreateAuthSessionCLI({
128
136
  input,
129
137
  ...rest
130
138
  }) {
131
- id = id ?? `auth-session-attempt-${Date.now()}`;
139
+ id = id ?? generateAuthSessionId(true);
132
140
  (0, _terminal.terminal)(`^+Executing create auth session attempt with id ^c${id}^:\n`);
133
141
  await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "create");
134
142
  return await runCreateWithRetries({
135
143
  authSessionId: id,
136
144
  authSessionInput: input,
137
- retries: 1,
138
145
  ...rest
139
146
  });
140
147
  }
@@ -150,7 +157,6 @@ async function executeAttemptCheckAuthSessionCLI({
150
157
  } = await (0, _helpers.loadAuthSessionInstance)(id);
151
158
  const checkResult = await runCheckWithRetries({
152
159
  auth: storageState,
153
- retries: 1,
154
160
  ...rest
155
161
  });
156
162
  if (!checkResult) {
@@ -163,24 +169,27 @@ async function runCheck({
163
169
  auth,
164
170
  proxy,
165
171
  headless,
166
- timeout
172
+ timeout,
173
+ traceId,
174
+ keepBrowserOpen
167
175
  }) {
168
- return await (0, _helpers.withTimeout)(async abortSignal => {
176
+ return await (0, _helpers.withTimeout)(async abortSignal => (0, _helpers.withCLITrace)(async tracing => {
169
177
  const runApiResult = await (0, _runApi.runApi)({
170
178
  automationFunction: {
171
179
  name: `${_constants.AUTH_SESSIONS_FOLDER_NAME}/check`
172
180
  },
173
- runOptions: {
181
+ runOptions: await (0, _browser.getCLIRunOptions)({
174
182
  headless,
175
- environment: "standalone",
176
- proxy: proxy ? (0, _helpers.parseUrlProxy)(proxy) : undefined
177
- },
183
+ proxy,
184
+ keepBrowserOpen
185
+ }),
178
186
  auth: {
179
187
  session: {
180
188
  type: "state",
181
189
  state: auth
182
190
  }
183
191
  },
192
+ tracing,
184
193
  importFunction: _tsNodeImport.tsNodeImport,
185
194
  abortSignal
186
195
  });
@@ -192,27 +201,30 @@ async function runCheck({
192
201
  return false;
193
202
  }
194
203
  return result;
195
- }, timeout);
204
+ }, traceId), timeout);
196
205
  }
197
206
  const _runCheck = exports._runCheck = runCheck;
198
207
  async function runCreate({
199
208
  authSessionInput,
200
209
  proxy,
201
210
  headless,
202
- timeout
211
+ timeout,
212
+ traceId,
213
+ keepBrowserOpen
203
214
  }) {
204
- return await (0, _helpers.withTimeout)(async abortSignal => {
215
+ return await (0, _helpers.withTimeout)(async abortSignal => (0, _helpers.withCLITrace)(async tracing => {
205
216
  const result = await (0, _runApi.runApi)({
206
217
  automationFunction: {
207
218
  name: `${_constants.AUTH_SESSIONS_FOLDER_NAME}/create`,
208
219
  params: authSessionInput
209
220
  },
210
- runOptions: {
221
+ runOptions: await (0, _browser.getCLIRunOptions)({
211
222
  headless,
212
- environment: "standalone",
213
- proxy: proxy ? (0, _helpers.parseUrlProxy)(proxy) : undefined
214
- },
223
+ proxy,
224
+ keepBrowserOpen
225
+ }),
215
226
  retrieveSession: true,
227
+ tracing,
216
228
  importFunction: _tsNodeImport.tsNodeImport,
217
229
  abortSignal
218
230
  });
@@ -220,7 +232,7 @@ async function runCreate({
220
232
  throw result.error;
221
233
  }
222
234
  return result.value.session;
223
- }, timeout);
235
+ }, traceId), timeout);
224
236
  }
225
237
  const _runCreate = exports._runCreate = runCreate;
226
238
  async function runCheckWithRetries({
@@ -228,11 +240,19 @@ async function runCheckWithRetries({
228
240
  retries,
229
241
  ...rest
230
242
  }) {
231
- for (let i = 0; i < retries; i++) {
243
+ for (let i = 0; i < (retries ?? 1); i++) {
232
244
  (0, _terminal.terminal)(`\n^+Running ^cauth session check${i === 0 ? "" : ` ^/(Attempt ${i + 1})`}^:...\n`);
233
245
  try {
246
+ let traceId = undefined;
247
+ if (rest.trace) {
248
+ traceId = "authsession-check-attempt";
249
+ if (retries) {
250
+ traceId += `-${i + 1}`;
251
+ }
252
+ }
234
253
  const checkResult = await runCheck({
235
254
  auth,
255
+ traceId,
236
256
  ...rest
237
257
  });
238
258
  if (checkResult) {
@@ -256,14 +276,24 @@ async function runCreateWithRetries({
256
276
  authSessionId,
257
277
  authSessionInput,
258
278
  retries,
279
+ trace,
280
+ metadata,
259
281
  ...rest
260
282
  }) {
261
283
  let newAuthSessionInstance = null;
262
- for (let i = 0; i < retries; i++) {
284
+ for (let i = 0; i < (retries ?? 1); i++) {
263
285
  (0, _terminal.terminal)(`\n^+Running ^cauth session create${i === 0 ? "" : ` ^/(Attempt ${i + 1})`}^:...\n`);
264
286
  try {
287
+ let traceId = undefined;
288
+ if (trace) {
289
+ traceId = "authsession-create-attempt";
290
+ if (retries) {
291
+ traceId += `-${i + 1}`;
292
+ }
293
+ }
265
294
  newAuthSessionInstance = await runCreate({
266
295
  authSessionInput,
296
+ traceId,
267
297
  ...rest
268
298
  });
269
299
  (0, _terminal.terminal)(`^+^gAuth session create succeeded^:\n`);
@@ -284,8 +314,107 @@ async function runCreateWithRetries({
284
314
  state: newAuthSessionInstance,
285
315
  id: authSessionId,
286
316
  input: authSessionInput,
287
- proxy: rest.proxy
317
+ proxy: rest.proxy,
318
+ metadata
288
319
  });
289
320
  return newAuthSessionInstance;
290
321
  }
291
- const _runCreateWithRetries = exports._runCreateWithRetries = runCreateWithRetries;
322
+ const _runCreateWithRetries = exports._runCreateWithRetries = runCreateWithRetries;
323
+ async function executeRecordAuthSessionCLI({
324
+ id,
325
+ checkRetries,
326
+ timeout,
327
+ headless,
328
+ proxy,
329
+ trace = false,
330
+ keepBrowserOpen,
331
+ startUrl,
332
+ finishUrl
333
+ }) {
334
+ id = id ?? generateAuthSessionId();
335
+ (0, _terminal.terminal)(`^+Recording auth session with id ^c${id}^:\n`);
336
+ let authSession;
337
+ try {
338
+ authSession = await recordAuthSession({
339
+ startUrl,
340
+ finishUrl,
341
+ timeout,
342
+ proxy: proxy ? (0, _helpers.parseUrlProxy)(proxy) : undefined
343
+ });
344
+ } catch (error) {
345
+ if (error instanceof _helpers.CLIError) {
346
+ throw new _helpers.CLIError(`Failed to record auth session: ${error.message}`);
347
+ }
348
+ throw error;
349
+ }
350
+ await (0, _helpers.storeAuthSessionInstance)({
351
+ state: authSession,
352
+ id,
353
+ proxy,
354
+ metadata: {
355
+ createdAt: new Date().toISOString(),
356
+ updatedAt: new Date().toISOString(),
357
+ authSessionId: id,
358
+ authSessionType: "MANUAL",
359
+ recorderStartUrl: startUrl,
360
+ recorderEndUrl: finishUrl
361
+ }
362
+ });
363
+ await executeRunValidateAuthSessionCLI({
364
+ id,
365
+ headless,
366
+ timeout,
367
+ proxy,
368
+ autoRecreate: false,
369
+ checkRetries,
370
+ createRetries: 0,
371
+ trace,
372
+ keepBrowserOpen
373
+ });
374
+ (0, _terminal.terminal)(`^+^gAuth session ^c${id}^ ^+^grecorded successfully^:\n`);
375
+ }
376
+ async function recordAuthSession({
377
+ startUrl,
378
+ finishUrl,
379
+ timeout,
380
+ proxy
381
+ }) {
382
+ const {
383
+ context,
384
+ page
385
+ } = await (0, _playwrightContext.launchChromium)({
386
+ headless: false,
387
+ proxy,
388
+ appModeInitialUrl: startUrl
389
+ });
390
+ try {
391
+ if (!page.url().startsWith(startUrl)) {
392
+ await page.goto(startUrl);
393
+ }
394
+ (0, _terminal.terminal)(`^+Navigated to^ ^_${startUrl}^:\n`);
395
+ (0, _terminal.terminal)(`^+Waiting for^ ^_${finishUrl}^:...\n`);
396
+ const timeoutTimestamp = Date.now() + timeout;
397
+ while (true) {
398
+ if (Date.now() > timeoutTimestamp) {
399
+ throw new _helpers.CLIError("Timeout waiting for finish URL");
400
+ }
401
+ if (context.pages().length === 0) {
402
+ throw new _helpers.CLIError("Browser was closed before reaching the finish URL");
403
+ }
404
+ if (context.pages()[0].url().startsWith(finishUrl)) {
405
+ break;
406
+ }
407
+ await (0, _promises.setTimeout)(1000);
408
+ }
409
+ (0, _terminal.terminal)(`^+Finish URL reached, capturing auth session...^:\n`);
410
+ await page.waitForLoadState("load");
411
+ const authSession = await (0, _contextStorageStateHelpers.getStorageState)(context);
412
+ return authSession;
413
+ } finally {
414
+ await context.close();
415
+ }
416
+ }
417
+ function generateAuthSessionId(isAttempt = false) {
418
+ if (isAttempt) return `auth-session-attempt-${Date.now()}`;
419
+ return `auth-session-${Date.now()}`;
420
+ }
@@ -48,6 +48,12 @@ async function runSaveProject(projectName, auth) {
48
48
  };
49
49
  const projectPath = process.cwd();
50
50
  const codeTree = await convertProjectToCodeTree(projectPath);
51
+ const intunedSettingsFile = await (0, _helpers.getIntunedSettingsFile)();
52
+ codeTree["Intuned.json"] = {
53
+ file: {
54
+ contents: JSON.stringify(intunedSettingsFile.parse(await fs.readFile(intunedSettingsFile.path, "utf-8")))
55
+ }
56
+ };
51
57
  codeTree["tsconfig.json"] = {
52
58
  file: {
53
59
  contents: JSON.stringify(_constants.tsConfigCli, null, 2)
@@ -124,6 +130,7 @@ const validateProjectName = projectName => {
124
130
  exports.validateProjectName = validateProjectName;
125
131
  const validateIntunedProject = async () => {
126
132
  const currentDirectoryToSave = process.cwd();
133
+ const intunedSettingsFile = await (0, _helpers.getIntunedSettingsFile)();
127
134
  const validationSteps = [{
128
135
  name: "build",
129
136
  check: async () => {
@@ -172,10 +179,10 @@ const validateIntunedProject = async () => {
172
179
  }
173
180
  }
174
181
  }, {
175
- name: "Intuned.json",
182
+ name: intunedSettingsFile.name,
176
183
  check: async () => {
177
184
  try {
178
- const intunedJsonPath = path.join(currentDirectoryToSave, "Intuned.json");
185
+ const intunedJsonPath = path.join(currentDirectoryToSave, intunedSettingsFile.name);
179
186
  await fs.exists(intunedJsonPath);
180
187
  return {
181
188
  isValid: true
@@ -183,7 +190,7 @@ const validateIntunedProject = async () => {
183
190
  } catch (error) {
184
191
  return {
185
192
  isValid: false,
186
- errorMessage: "Intuned.json file not found"
193
+ errorMessage: `${intunedSettingsFile.name} file not found`
187
194
  };
188
195
  }
189
196
  }
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+
3
+ var _vitest = require("vitest");
4
+ var _browser = require("../browser");
5
+ var _playwrightContext = require("../../../../common/playwrightContext");
6
+ function getTerminal() {
7
+ return new Proxy(() => ({}), {
8
+ get: () => getTerminal(),
9
+ apply: () => ({})
10
+ });
11
+ }
12
+ _vitest.vi.mock("fs-extra", () => ({
13
+ exists: _vitest.vi.fn().mockResolvedValue(true)
14
+ }));
15
+ _vitest.vi.mock("portfinder", () => ({
16
+ getPort: _vitest.vi.fn().mockResolvedValue(1234)
17
+ }));
18
+ _vitest.vi.mock("../../../../common/playwrightContext", () => ({
19
+ launchChromium: _vitest.vi.fn().mockImplementation(async () => ({
20
+ context: {
21
+ close: _vitest.vi.fn().mockResolvedValue(undefined)
22
+ },
23
+ page: {}
24
+ }))
25
+ }));
26
+ _vitest.vi.mock("../../helpers/terminal", () => ({
27
+ terminal: getTerminal()
28
+ }));
29
+ _vitest.vi.mock("../../helpers/proxy", () => {
30
+ return {
31
+ parseUrlProxy: _vitest.vi.fn(v => v)
32
+ };
33
+ });
34
+ _vitest.vi.mock("../../helpers", async importOriginal => {
35
+ const original = await importOriginal();
36
+ return {
37
+ ...original,
38
+ terminal: getTerminal()
39
+ };
40
+ });
41
+ (0, _vitest.describe)("Browser CLI options", () => {
42
+ (0, _vitest.it)("returns standalone options if keepBrowserOpen is not set", async () => {
43
+ const options = await (0, _browser.getCLIRunOptions)({
44
+ keepBrowserOpen: false,
45
+ headless: false
46
+ });
47
+ (0, _vitest.expect)(options).toEqual(_vitest.expect.objectContaining({
48
+ environment: "standalone",
49
+ headless: false
50
+ }));
51
+ });
52
+ (0, _vitest.describe)("when keepBrowserOpen is set", () => {
53
+ beforeEach(async () => {
54
+ _vitest.vi.clearAllMocks();
55
+ await (0, _browser.closeCliBrowser)();
56
+ });
57
+ (0, _vitest.it)("launches a browser with correct parameters and returns cdp options", async () => {
58
+ const options = await (0, _browser.getCLIRunOptions)({
59
+ keepBrowserOpen: true,
60
+ headless: false,
61
+ proxy: "proxy"
62
+ });
63
+ (0, _vitest.expect)(_playwrightContext.launchChromium).toHaveBeenCalledWith({
64
+ headless: false,
65
+ cdpPort: 1234,
66
+ proxy: "proxy"
67
+ });
68
+ (0, _vitest.expect)(options).toEqual(_vitest.expect.objectContaining({
69
+ environment: "cdp",
70
+ cdpAddress: "http://localhost:1234"
71
+ }));
72
+ });
73
+ (0, _vitest.it)("keeps context open until new context", async () => {
74
+ await (0, _browser.getCLIRunOptions)({
75
+ keepBrowserOpen: true,
76
+ headless: false,
77
+ proxy: "proxy"
78
+ });
79
+ const firstContext = (0, _browser._getContextForTest)();
80
+ (0, _vitest.expect)(firstContext).not.toBeNull();
81
+ (0, _vitest.expect)(_playwrightContext.launchChromium).toHaveBeenCalledTimes(1);
82
+ await (0, _browser.getCLIRunOptions)({
83
+ keepBrowserOpen: true,
84
+ headless: false,
85
+ proxy: "proxy"
86
+ });
87
+ const secondContext = (0, _browser._getContextForTest)();
88
+ (0, _vitest.expect)(secondContext).not.toBeNull();
89
+ (0, _vitest.expect)(firstContext).not.toBe(secondContext);
90
+ (0, _vitest.expect)(_playwrightContext.launchChromium).toHaveBeenCalledTimes(2);
91
+ });
92
+ (0, _vitest.it)("keeps context open until explicitly closed", async () => {
93
+ await (0, _browser.getCLIRunOptions)({
94
+ keepBrowserOpen: true,
95
+ headless: false,
96
+ proxy: "proxy"
97
+ });
98
+ (0, _vitest.expect)((0, _browser._getContextForTest)()).not.toBeNull();
99
+ await (0, _browser.closeCliBrowser)();
100
+ (0, _vitest.expect)((0, _browser._getContextForTest)()).toBeNull();
101
+ });
102
+ });
103
+ });
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ var _vitest = require("vitest");
4
+ var _ = require("..");
5
+ function getTerminal() {
6
+ return new Proxy(() => ({}), {
7
+ get: () => getTerminal(),
8
+ apply: () => ({})
9
+ });
10
+ }
11
+ _vitest.vi.mock("fs-extra", () => ({
12
+ exists: _vitest.vi.fn().mockResolvedValue(true)
13
+ }));
14
+ _vitest.vi.mock("../../helpers/terminal", () => ({
15
+ terminal: getTerminal()
16
+ }));
17
+ _vitest.vi.mock("../../helpers", async importOriginal => {
18
+ const original = await importOriginal();
19
+ return {
20
+ ...original,
21
+ terminal: getTerminal()
22
+ };
23
+ });
24
+ (0, _vitest.describe)("Tracing wrapper", () => {
25
+ (0, _vitest.it)("calls wrapped function with disabled tracing when id is undefined", async () => {
26
+ const fn = _vitest.vi.fn();
27
+ await (0, _.withCLITrace)(fn, undefined);
28
+ (0, _vitest.expect)(fn).toHaveBeenCalledWith({
29
+ enabled: false
30
+ });
31
+ });
32
+ (0, _vitest.it)("calls wrapped function with enabled tracing when id is defined", async () => {
33
+ const fn = _vitest.vi.fn();
34
+ await (0, _.withCLITrace)(fn, "trace-id");
35
+ (0, _vitest.expect)(fn).toHaveBeenCalledWith({
36
+ enabled: true,
37
+ filePath: _vitest.expect.stringContaining("trace-id")
38
+ });
39
+ });
40
+ });