@intuned/runtime-dev 1.6.0-dev-52 → 1.6.0-dev-52-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.
package/.babelrc CHANGED
@@ -4,8 +4,8 @@
4
4
  "@babel/preset-env",
5
5
  {
6
6
  "targets": {
7
- "chrome": 115,
8
- "node": "16"
7
+ "chrome": 130,
8
+ "node": "20"
9
9
  },
10
10
  "modules": "commonjs"
11
11
  }
@@ -106,7 +106,7 @@ _commander.program.description("run the user function in the cli for testing pur
106
106
  inputData = {};
107
107
  }
108
108
  let authSessionParametersJson = undefined;
109
- if (!(0, _isNil.default)(options === null || options === void 0 ? void 0 : options.authSessionParameters)) {
109
+ if (!(0, _isNil.default)(options?.authSessionParameters)) {
110
110
  authSessionParametersJson = JSON.parse(options.authSessionParameters);
111
111
  }
112
112
  await (0, _asyncLocalStorage.runWithContext)({
@@ -32,7 +32,7 @@ _commander.program.description("Create an auth session").argument("[auth-session
32
32
  if (!createApiExists) {
33
33
  throw new Error("Auth session create API not implemented, please create it in the auth sessions specified directory");
34
34
  }
35
- const authSessionInput = (await (0, _utils2.loadParameters)(options === null || options === void 0 ? void 0 : options.input)) ?? {};
35
+ const authSessionInput = (await (0, _utils2.loadParameters)(options?.input)) ?? {};
36
36
  const session = await (0, _utils.runCreateApi)(authSessionInput);
37
37
  if (!session) {
38
38
  console.error(_chalk.default.red("Failed to create auth session."));
@@ -32,9 +32,8 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
32
32
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
33
33
  async function isAuthEnabled() {
34
34
  try {
35
- var _intunedJson$authSess;
36
35
  const intunedJson = await fs.readJSON(_path.default.join(process.cwd(), "Intuned.json"));
37
- return Boolean(intunedJson === null || intunedJson === void 0 || (_intunedJson$authSess = intunedJson.authSessions) === null || _intunedJson$authSess === void 0 ? void 0 : _intunedJson$authSess.enabled);
36
+ return Boolean(intunedJson?.authSessions?.enabled);
38
37
  } catch (error) {
39
38
  return false;
40
39
  }
@@ -32,10 +32,9 @@ function compileTypeScript(apiFilePath) {
32
32
  };
33
33
  }
34
34
  function findFirstExecutableLine(sourceFile) {
35
- var _defaultExportSymbol$;
36
35
  let functionBody;
37
36
  const defaultExportSymbol = sourceFile.getDefaultExportSymbol();
38
- const defaultExportDeclaration = defaultExportSymbol === null || defaultExportSymbol === void 0 || (_defaultExportSymbol$ = defaultExportSymbol.getDeclarations()) === null || _defaultExportSymbol$ === void 0 ? void 0 : _defaultExportSymbol$[0];
37
+ const defaultExportDeclaration = defaultExportSymbol?.getDeclarations()?.[0];
39
38
  if (defaultExportDeclaration) {
40
39
  if (defaultExportDeclaration.getKind() === _tsMorph.ts.SyntaxKind.FunctionDeclaration) {
41
40
  functionBody = defaultExportDeclaration.getBody();
@@ -45,9 +44,8 @@ function findFirstExecutableLine(sourceFile) {
45
44
  const expression = exportAssignment.getExpression();
46
45
  if (!expression) continue;
47
46
  if (expression.getKind() === _tsMorph.ts.SyntaxKind.Identifier || expression.getKind() === _tsMorph.ts.SyntaxKind.FunctionExpression || expression.getKind() === _tsMorph.ts.SyntaxKind.ArrowFunction) {
48
- var _sourceFile$getVariab;
49
47
  const identifier = expression.getText();
50
- const possiblyExportedFunction = sourceFile.getFunction(identifier) || ((_sourceFile$getVariab = sourceFile.getVariableStatement(identifier)) === null || _sourceFile$getVariab === void 0 ? void 0 : _sourceFile$getVariab.getDescendants().find(node => node.getKind() === _tsMorph.ts.SyntaxKind.FunctionExpression || node.getKind() === _tsMorph.ts.SyntaxKind.ArrowFunction));
48
+ const possiblyExportedFunction = sourceFile.getFunction(identifier) || sourceFile.getVariableStatement(identifier)?.getDescendants().find(node => node.getKind() === _tsMorph.ts.SyntaxKind.FunctionExpression || node.getKind() === _tsMorph.ts.SyntaxKind.ArrowFunction);
51
49
  if (possiblyExportedFunction) {
52
50
  functionBody = possiblyExportedFunction.getBody();
53
51
  break;
@@ -228,13 +228,12 @@ const validateIntunedProject = async () => {
228
228
  name: "package.json",
229
229
  check: async () => {
230
230
  try {
231
- var _packageJson$dependen;
232
231
  const packageJsonPath = path.join(currentDirectoryToDeploy, "package.json");
233
232
  await fs.exists(packageJsonPath);
234
233
  const packageJson = JSON.parse(await fs.readFile(packageJsonPath, {
235
234
  encoding: "utf-8"
236
235
  }));
237
- const userCodePlaywrightVersion = (_packageJson$dependen = packageJson.dependencies) === null || _packageJson$dependen === void 0 ? void 0 : _packageJson$dependen.playwright;
236
+ const userCodePlaywrightVersion = packageJson.dependencies?.playwright;
238
237
  if (userCodePlaywrightVersion !== _constants.CURRENT_PLAYWRIGHT_VERSION) {
239
238
  return {
240
239
  isValid: false,
@@ -66,14 +66,12 @@ function runAutomationCLI(importFunction) {
66
66
  let generator = null;
67
67
  const abortController = new AbortController();
68
68
  client.on("error", err => {
69
- var _generator;
70
- void ((_generator = generator) === null || _generator === void 0 ? void 0 : _generator.throw(err).catch(() => undefined));
69
+ void generator?.throw(err).catch(() => undefined);
71
70
  });
72
71
  const interruptSignalHandler = async () => {
73
- var _generator2;
74
72
  abortController.abort();
75
73
  await (0, _promises.setTimeout)(60_000);
76
- void ((_generator2 = generator) === null || _generator2 === void 0 ? void 0 : _generator2.throw(new Error("Interrupted")).catch(() => undefined));
74
+ void generator?.throw(new Error("Interrupted")).catch(() => undefined);
77
75
  client.end();
78
76
  process.exit(1);
79
77
  };
@@ -214,7 +212,7 @@ function runAutomationCLI(importFunction) {
214
212
  _commander.program.parse(process.argv);
215
213
  }
216
214
  function getProxyUrlFromRunOptions(runOptions) {
217
- if ((runOptions === null || runOptions === void 0 ? void 0 : runOptions.environment) !== "standalone") return undefined;
215
+ if (runOptions?.environment !== "standalone") return undefined;
218
216
  const proxy = runOptions.proxy;
219
217
  if (!proxy) return undefined;
220
218
  const url = new URL(proxy.server);
@@ -62,10 +62,10 @@ async function writeResultToFile(runId, result, payloadToAppend) {
62
62
  }
63
63
  async function runApiViaCLI(apiName, inputData, options) {
64
64
  let authSessionPathToUse = null;
65
- if (options !== null && options !== void 0 && options.authSession) {
65
+ if (options?.authSession) {
66
66
  const {
67
67
  authSessionInstanceStoragePath
68
- } = await (0, _utils.retrieveAuthSessionInstance)(options === null || options === void 0 ? void 0 : options.authSession, true);
68
+ } = await (0, _utils.retrieveAuthSessionInstance)(options?.authSession, true);
69
69
  authSessionPathToUse = authSessionInstanceStoragePath;
70
70
  }
71
71
  if (authSessionPathToUse) {
@@ -82,17 +82,17 @@ async function runApiViaCLI(apiName, inputData, options) {
82
82
  }
83
83
  const {
84
84
  metadata
85
- } = await (0, _utils.retrieveAuthSessionInstance)(options === null || options === void 0 ? void 0 : options.authSession);
86
- if ((metadata === null || metadata === void 0 ? void 0 : metadata.authSessionType) === "MANUAL") {
85
+ } = await (0, _utils.retrieveAuthSessionInstance)(options?.authSession);
86
+ if (metadata?.authSessionType === "MANUAL") {
87
87
  throw new Error("Expired Auth session is recorder-based, please provide a new one or refresh it manually");
88
88
  }
89
- const authSessionInput = (metadata === null || metadata === void 0 ? void 0 : metadata.authSessionInput) ?? {};
89
+ const authSessionInput = metadata?.authSessionInput ?? {};
90
90
  try {
91
91
  const refresehAuthSessionInstance = await (0, _utils.runCreateApiViaCLI)(authSessionInput);
92
92
  if (!refresehAuthSessionInstance) {
93
93
  throw new Error("Failed to refresh auth session");
94
94
  }
95
- await (0, _utils.storeAuthSessionInstance)(refresehAuthSessionInstance, options === null || options === void 0 ? void 0 : options.authSession, authSessionInput);
95
+ await (0, _utils.storeAuthSessionInstance)(refresehAuthSessionInstance, options?.authSession, authSessionInput);
96
96
  const checkResult = await (0, _utils.runCheckApiViaCLI)(authSessionPathToUse);
97
97
  if (!checkResult) {
98
98
  throw new Error("Failed to refresh auth session");
@@ -30,23 +30,7 @@ async function setStorageState(context, state) {
30
30
  }
31
31
  }
32
32
  }
33
- if ("sessionStorage" in state && state.sessionStorage) {
34
- await context.addInitScript(storage => {
35
- for (const {
36
- origin,
37
- sessionStorage
38
- } of storage) {
39
- if (window.location.origin === origin) {
40
- for (const item of sessionStorage) {
41
- const value = window.sessionStorage.getItem(item.name);
42
- if (!value) {
43
- window.sessionStorage.setItem(item.name, item.value);
44
- }
45
- }
46
- }
47
- }
48
- }, state.sessionStorage);
49
- }
33
+ if ("sessionStorage" in state && state.sessionStorage) {}
50
34
  await page.close();
51
35
  }
52
36
  async function getStorageState(context) {
@@ -36,8 +36,7 @@ class JwtTokenManager {
36
36
  return Math.max(timeToRefresh, timeWindow);
37
37
  }
38
38
  async scheduleTokenRefresh() {
39
- var _process$env$RUN_ENVI;
40
- if (((_process$env$RUN_ENVI = process.env.RUN_ENVIRONMENT) === null || _process$env$RUN_ENVI === void 0 ? void 0 : _process$env$RUN_ENVI.toLowerCase()) !== "authoring") return;
39
+ if (process.env.RUN_ENVIRONMENT?.toLowerCase() !== "authoring") return;
41
40
  const timeToRefresh = this.timeToRefresh;
42
41
  if (timeToRefresh === undefined) return;
43
42
  if (this.tokenRefreshTimeout) clearTimeout(this.tokenRefreshTimeout);
@@ -51,8 +50,7 @@ class JwtTokenManager {
51
50
  }, timeToRefresh);
52
51
  }
53
52
  async refreshToken() {
54
- var _process$env$RUN_ENVI2;
55
- if (((_process$env$RUN_ENVI2 = process.env.RUN_ENVIRONMENT) === null || _process$env$RUN_ENVI2 === void 0 ? void 0 : _process$env$RUN_ENVI2.toLowerCase()) !== "authoring") return;
53
+ if (process.env.RUN_ENVIRONMENT?.toLowerCase() !== "authoring") return;
56
54
  const res = await this.fetchWithToken(this.refreshTokenPath, {
57
55
  method: "GET"
58
56
  });
@@ -65,7 +63,7 @@ class JwtTokenManager {
65
63
  if (newToken) this._token = newToken;
66
64
  }
67
65
  fetchWithToken(...[input, init]) {
68
- const headers = new Headers(init === null || init === void 0 ? void 0 : init.headers);
66
+ const headers = new Headers(init?.headers);
69
67
  headers.set("Authorization", `Bearer ${this.token}`);
70
68
  return (0, _crossFetch.default)(input, {
71
69
  ...init,
@@ -22,11 +22,10 @@ const runAutomationErrorCodes = exports.runAutomationErrorCodes = [apiNotFoundEr
22
22
  class RunAutomationError {
23
23
  wrapped = false;
24
24
  get json() {
25
- var _this$cause;
26
25
  return {
27
26
  code: this.code,
28
27
  details: this.details,
29
- cause: (_this$cause = this.cause) === null || _this$cause === void 0 ? void 0 : _this$cause.json
28
+ cause: this.cause?.json
30
29
  };
31
30
  }
32
31
  }
@@ -136,10 +135,10 @@ class AutomationError extends RunAutomationError {
136
135
  };
137
136
  }
138
137
  this.statusCode = 500;
139
- this.message = `[${(error === null || error === void 0 ? void 0 : error.name) ?? error}] ${error === null || error === void 0 ? void 0 : error.message}`;
138
+ this.message = `[${error?.name ?? error}] ${error?.message}`;
140
139
  this.details = {
141
- name: error === null || error === void 0 ? void 0 : error.name,
142
- message: error === null || error === void 0 ? void 0 : error.message
140
+ name: error?.name,
141
+ message: error?.message
143
142
  };
144
143
  }
145
144
  }
@@ -80,17 +80,15 @@ async function* runApiGenerator({
80
80
  return;
81
81
  }
82
82
  try {
83
- var _context;
84
- await ((_context = context) === null || _context === void 0 ? void 0 : _context.tracing.stop({
83
+ await context?.tracing.stop({
85
84
  path: tracing.filePath
86
- }));
85
+ });
87
86
  } catch (error) {
88
- console.log(errorMessage, error === null || error === void 0 ? void 0 : error.message);
87
+ console.log(errorMessage, error?.message);
89
88
  await (0, _fsExtra.remove)(tracing.filePath);
90
89
  }
91
90
  }
92
91
  async function* runAutomation() {
93
- var _getExecutionContext;
94
92
  let page;
95
93
  const validatedModuleResult = await importUsingImportFunction(automationFunction.name, importFunction);
96
94
  if (validatedModuleResult.isErr()) {
@@ -98,7 +96,7 @@ async function* runApiGenerator({
98
96
  }
99
97
  const importedModule = validatedModuleResult.value;
100
98
  let checkFn;
101
- if (auth !== null && auth !== void 0 && auth.runCheck) {
99
+ if (auth?.runCheck) {
102
100
  if (!auth.session) {
103
101
  return (0, _neverthrow.err)(new _errors.AuthRequiredError());
104
102
  }
@@ -130,7 +128,7 @@ async function* runApiGenerator({
130
128
  headless,
131
129
  proxy,
132
130
  downloadsPath,
133
- storageState: auth === null || auth === void 0 ? void 0 : auth.session
131
+ storageState: auth?.session
134
132
  }));
135
133
  } else {
136
134
  const {
@@ -140,7 +138,7 @@ async function* runApiGenerator({
140
138
  ({
141
139
  page,
142
140
  context
143
- } = await (0, _getPlaywrightConstructs.getPlaywrightConstructsForMode)(mode, cdpAddress, auth === null || auth === void 0 ? void 0 : auth.session));
141
+ } = await (0, _getPlaywrightConstructs.getPlaywrightConstructsForMode)(mode, cdpAddress, auth?.session));
144
142
  }
145
143
  if (tracing.enabled) {
146
144
  await context.tracing.start({
@@ -185,7 +183,7 @@ async function* runApiGenerator({
185
183
  }
186
184
  return (0, _neverthrow.ok)({
187
185
  result,
188
- extendedPayloads: (_getExecutionContext = (0, _asyncLocalStorage.getExecutionContext)()) === null || _getExecutionContext === void 0 ? void 0 : _getExecutionContext.extendedPayloads,
186
+ extendedPayloads: (0, _asyncLocalStorage.getExecutionContext)()?.extendedPayloads,
189
187
  session: retrieveSession ? await (0, _contextStorageStateHelpers.getStorageState)(context) : undefined
190
188
  });
191
189
  }
@@ -206,11 +204,10 @@ async function* runApiGenerator({
206
204
  } catch (error) {
207
205
  return (0, _neverthrow.err)(new _errors.AutomationError(error));
208
206
  } finally {
209
- var _context2;
210
207
  await saveTraceIfNeeded({
211
208
  errorMessage: "failed to save trace"
212
209
  });
213
- await ((_context2 = context) === null || _context2 === void 0 ? void 0 : _context2.close());
210
+ await context?.close();
214
211
  if (downloadsPath !== undefined) {
215
212
  await fs.remove(downloadsPath);
216
213
  }
@@ -24,13 +24,12 @@ var _enums = require("./enums");
24
24
  runId: "test-run-id",
25
25
  extendedPayloads: []
26
26
  }, () => {
27
- var _getExecutionContext, _getExecutionContext2;
28
- (0, _vitest.expect)((_getExecutionContext = (0, _asyncLocalStorage.getExecutionContext)()) === null || _getExecutionContext === void 0 ? void 0 : _getExecutionContext.extendedPayloads).toEqual([]);
27
+ (0, _vitest.expect)((0, _asyncLocalStorage.getExecutionContext)()?.extendedPayloads).toEqual([]);
29
28
  (0, _.extendPayload)({
30
29
  api: "test-api",
31
30
  parameters: {}
32
31
  });
33
- (0, _vitest.expect)((_getExecutionContext2 = (0, _asyncLocalStorage.getExecutionContext)()) === null || _getExecutionContext2 === void 0 ? void 0 : _getExecutionContext2.extendedPayloads).toEqual([{
32
+ (0, _vitest.expect)((0, _asyncLocalStorage.getExecutionContext)()?.extendedPayloads).toEqual([{
34
33
  api: "test-api",
35
34
  parameters: {}
36
35
  }]);
@@ -47,7 +46,7 @@ var _enums = require("./enums");
47
46
  parameters: {}
48
47
  });
49
48
  const context = (0, _asyncLocalStorage.getExecutionContext)();
50
- (0, _vitest.expect)(context === null || context === void 0 ? void 0 : context.extendedPayloads).toHaveLength(4);
49
+ (0, _vitest.expect)(context?.extendedPayloads).toHaveLength(4);
51
50
  });
52
51
  });
53
52
  });
@@ -16,6 +16,6 @@ function extendPayload(payload) {
16
16
  context.extendedPayloads = [...items];
17
17
  return;
18
18
  }
19
- context === null || context === void 0 || context.extendedPayloads.push(...items);
19
+ context?.extendedPayloads.push(...items);
20
20
  (0, _extendTimeout.extendTimeout)();
21
21
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intuned/runtime-dev",
3
- "version": "1.6.0-dev-52",
3
+ "version": "1.6.0-dev-52-1",
4
4
  "description": "Intuned runtime",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",