@intuned/runtime-dev 1.1.6-bot-detection → 1.1.6-fiber.0

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 (43) hide show
  1. package/.babelrc +2 -2
  2. package/dist/commands/api/run.js +8 -2
  3. package/dist/commands/auth-sessions/run-check.js +18 -4
  4. package/dist/commands/auth-sessions/run-create.js +2 -1
  5. package/dist/commands/cli-auth-sessions/create.js +1 -1
  6. package/dist/commands/cli-auth-sessions/utils.d.ts +1 -1
  7. package/dist/commands/cli-auth-sessions/utils.js +2 -3
  8. package/dist/commands/common/browserUtils.d.ts +1 -1
  9. package/dist/commands/common/browserUtils.js +1 -1
  10. package/dist/commands/common/getFirstLineNumber.js +2 -4
  11. package/dist/commands/deploy/utils.js +1 -2
  12. package/dist/commands/init/utils.js +1 -7
  13. package/dist/commands/interface/run.js +7 -6
  14. package/dist/commands/run-api-cli/utils.js +6 -6
  15. package/dist/common/assets/browser_scripts.js +2509 -2143
  16. package/dist/common/asyncLocalStorage/index.d.ts +1 -2
  17. package/dist/common/backendFunctions/getAuthSessionParameters.d.ts +1 -0
  18. package/dist/common/backendFunctions/getAuthSessionParameters.js +38 -0
  19. package/dist/common/cli/constants.d.ts +1 -0
  20. package/dist/common/cli/constants.js +2 -1
  21. package/dist/common/cli/types.d.ts +1 -1
  22. package/dist/common/contextStorageStateHelpers.d.ts +1 -1
  23. package/dist/common/contextStorageStateHelpers.js +56 -0
  24. package/dist/common/getPlaywrightConstructs.d.ts +1 -1
  25. package/dist/common/getPlaywrightConstructs.js +12 -12
  26. package/dist/common/jwtTokenManager.js +3 -5
  27. package/dist/common/runApi/errors.d.ts +1 -1
  28. package/dist/common/runApi/errors.js +5 -6
  29. package/dist/common/runApi/index.d.ts +1 -1
  30. package/dist/common/runApi/index.js +22 -21
  31. package/dist/common/runApi/types.d.ts +16 -16
  32. package/dist/index.d.ts +1 -1
  33. package/dist/index.js +6 -0
  34. package/dist/runtime/executionHelpers.test.js +3 -4
  35. package/dist/runtime/export.d.ts +16 -0
  36. package/dist/runtime/extendPayload.js +1 -1
  37. package/dist/runtime/extendTimeout.js +0 -7
  38. package/dist/runtime/getAuthSessionParameters.d.ts +1 -0
  39. package/dist/runtime/getAuthSessionParameters.js +20 -0
  40. package/dist/runtime/index.d.ts +1 -0
  41. package/dist/runtime/index.js +7 -0
  42. package/package.json +5 -6
  43. package/template.tsconfig.json +4 -7
@@ -5,12 +5,11 @@ export declare const asyncLocalStorage: AsyncLocalStorage<InternalRunInfo>;
5
5
  export declare function runWithContext<R, TArgs extends any[]>(contextData: InternalRunInfo, callback: (...args: TArgs) => R, ...args: TArgs): R;
6
6
  interface TimeoutInfo {
7
7
  extendTimeoutCallback?: () => Promise<void>;
8
- timeoutDuration?: number;
9
- timeoutTimestamp?: number;
10
8
  }
11
9
  export interface InternalRunInfo extends RunInfo {
12
10
  extendedPayloads: Payload[];
13
11
  timeoutInfo?: TimeoutInfo;
12
+ getAuthSessionParameters?: () => Promise<any>;
14
13
  }
15
14
  export declare function getExecutionContext(): InternalRunInfo | undefined;
16
15
  export {};
@@ -0,0 +1 @@
1
+ export declare function getAuthSessionParameters(): Promise<any>;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getAuthSessionParameters = getAuthSessionParameters;
7
+ var _isNil = _interopRequireDefault(require("lodash/isNil"));
8
+ var _asyncLocalStorage = require("../asyncLocalStorage");
9
+ var _zod = require("zod");
10
+ var _jwtTokenManager = require("../jwtTokenManager");
11
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
+ const authSessionParametersResponseSchema = _zod.z.object({
13
+ parameters: _zod.z.any().refine(v => v !== undefined)
14
+ });
15
+ async function getAuthSessionParameters() {
16
+ const context = (0, _asyncLocalStorage.getExecutionContext)();
17
+ if (!context) {
18
+ throw new Error("getAuthSessionParameters failed due to an internal error (context was not found).");
19
+ }
20
+ const authSessionId = context.authSessionId;
21
+ if ((0, _isNil.default)(authSessionId)) {
22
+ throw new Error("Auth sessions are not enabled");
23
+ }
24
+ const response = await (0, _jwtTokenManager.callBackendFunctionWithToken)(`auth-session/${authSessionId}/parameters`, {
25
+ method: "GET"
26
+ });
27
+ const body = await response.text();
28
+ if (!response.ok) {
29
+ throw new Error(`getAuthSessionParameters failed with status ${response.status}: ${body}`);
30
+ }
31
+ let json;
32
+ try {
33
+ json = JSON.parse(body);
34
+ } catch (e) {
35
+ throw new Error(`Expected JSON response, but got ${body}`);
36
+ }
37
+ return authSessionParametersResponseSchema.parse(json).parameters;
38
+ }
@@ -22,6 +22,7 @@ export declare const userCLIScripts: {
22
22
  export declare const tsConfigCli: {
23
23
  compilerOptions: {
24
24
  moduleResolution: string;
25
+ module: string;
25
26
  target: string;
26
27
  outDir: string;
27
28
  sourceMap: boolean;
@@ -27,7 +27,8 @@ const userCLIScripts = exports.userCLIScripts = {
27
27
  };
28
28
  const tsConfigCli = exports.tsConfigCli = {
29
29
  compilerOptions: {
30
- moduleResolution: "node",
30
+ moduleResolution: "NodeNext",
31
+ module: "NodeNext",
31
32
  target: "ES2021",
32
33
  outDir: "./dist",
33
34
  sourceMap: false,
@@ -1,5 +1,5 @@
1
1
  export declare const templateIds: string[];
2
- export type TemplateId = (typeof templateIds)[number];
2
+ export type TemplateId = typeof templateIds[number];
3
3
  /**
4
4
  * A simple, tree-like structure to describe the contents of a folder to be mounted.
5
5
  *
@@ -1,4 +1,4 @@
1
- import * as playwright from "patchright";
1
+ import * as playwright from "playwright";
2
2
  interface StorageEntry {
3
3
  name: string;
4
4
  value: string;
@@ -9,6 +9,45 @@ async function setStorageState(context, state) {
9
9
  if ("cookies" in state && state.cookies) {
10
10
  await context.addCookies(state.cookies);
11
11
  }
12
+ const page = await context.newPage();
13
+ if ("origins" in state && state.origins) {
14
+ for (const originData of state.origins || []) {
15
+ const origin = originData.origin;
16
+ await page.route(`${origin}/*`, route => route.fulfill({
17
+ body: "<html><head><title>Set Storage</title></head><body><h1>Set Storage</h1></body></html>",
18
+ contentType: "text/html",
19
+ status: 200
20
+ }));
21
+ try {
22
+ await page.goto(origin);
23
+ for (const item of originData.localStorage) {
24
+ await page.evaluate(([key, value]) => {
25
+ window.localStorage.setItem(key, value);
26
+ }, [item.name, item.value]);
27
+ }
28
+ } finally {
29
+ await page.unroute(`${origin}/*`);
30
+ }
31
+ }
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
+ }
50
+ await page.close();
12
51
  }
13
52
  async function getStorageState(context) {
14
53
  const result = {};
@@ -19,6 +58,23 @@ async function getStorageState(context) {
19
58
  const pages = await context.pages();
20
59
  for (const page of pages) {
21
60
  if (page.isClosed()) continue;
61
+ try {
62
+ const sessionData = await page.evaluate(() => {
63
+ const items = {
64
+ ...window.sessionStorage
65
+ };
66
+ return {
67
+ origin: window.location.origin,
68
+ sessionStorage: Object.entries(items).map(([name, value]) => ({
69
+ name,
70
+ value
71
+ }))
72
+ };
73
+ });
74
+ sessionDataList.push(sessionData);
75
+ } catch (error) {
76
+ console.error("Error getting sessionStorage:", error);
77
+ }
22
78
  }
23
79
  result["sessionStorage"] = sessionDataList;
24
80
  return result;
@@ -1,4 +1,4 @@
1
- import * as playwright from "patchright";
1
+ import * as playwright from "playwright";
2
2
  import type { RunApiSession } from "./runApi";
3
3
  interface Proxy {
4
4
  server: string;
@@ -7,7 +7,7 @@ exports.getPlaywrightConstructsForMode = getPlaywrightConstructsForMode;
7
7
  exports.getProductionPlaywrightConstructs = getProductionPlaywrightConstructs;
8
8
  exports.getRemotePlaywrightContext = getRemotePlaywrightContext;
9
9
  exports.loadSessionToContext = loadSessionToContext;
10
- var playwright = _interopRequireWildcard(require("patchright"));
10
+ var playwright = _interopRequireWildcard(require("playwright"));
11
11
  var _fsExtra = _interopRequireWildcard(require("fs-extra"));
12
12
  var fs = _fsExtra;
13
13
  var _contextStorageStateHelpers = require("./contextStorageStateHelpers");
@@ -43,19 +43,12 @@ async function getProductionPlaywrightConstructs({
43
43
  if (headless) {
44
44
  extraArgs.push("--headless=new");
45
45
  }
46
- const executablePath = playwright.chromium.executablePath();
47
- const chromium127Path = executablePath.replace("chromium-1117", "chromium-1124");
48
- const isChrome127There = await (0, _fsExtra.exists)(chromium127Path);
49
- const userAgent = `Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${isChrome127There ? 127 : 125}.0.0.0 Safari/537.36`;
50
46
  const userDataDir = await createUserDirWithPreferences();
51
47
  const context = await playwright.chromium.launchPersistentContext(userDataDir, {
52
48
  headless,
53
- ignoreDefaultArgs: [...getChromiumLaunchArgsToIgnore(), "--headless"],
49
+ viewport: null,
54
50
  proxy,
55
- executablePath: isChrome127There ? chromium127Path : executablePath,
56
- args: extraArgs,
57
- downloadsPath,
58
- userAgent
51
+ downloadsPath
59
52
  });
60
53
  context.once("close", async () => {
61
54
  try {
@@ -76,6 +69,9 @@ async function getProductionPlaywrightConstructs({
76
69
  });
77
70
  }
78
71
  const assetsFile = _path.default.join(__dirname, "./assets/browser_scripts.js");
72
+ await context.addInitScript({
73
+ path: assetsFile
74
+ });
79
75
  let page = context.pages().at(0);
80
76
  if (page) {
81
77
  const scriptString = await (0, _fsExtra.readFile)(assetsFile, "utf8");
@@ -88,7 +84,6 @@ async function getProductionPlaywrightConstructs({
88
84
  context
89
85
  };
90
86
  }
91
- const getChromiumLaunchArgsToIgnore = () => ["--disable-field-trial-config", "--disable-background-networking", "--enable-features=NetworkService,NetworkServiceInProcess", "--disable-background-timer-throttling", "--disable-backgrounding-occluded-windows", "--disable-back-forward-cache", "--disable-breakpad", "--disable-client-side-phishing-detection", "--disable-component-extensions-with-background-pages", "--disable-component-update", "--no-default-browser-check", "--disable-default-apps", "--disable-dev-shm-usage", "--disable-extensions", "--disable-features=ImprovedCookieControls,LazyFrameLoading,GlobalMediaControls,DestroyProfileOnBrowserClose,MediaRouter,DialMediaRouteProvider,AcceptCHFrame,AutoExpandDetailsElement,CertificateTransparencyComponentUpdater,AvoidUnnecessaryBeforeUnloadCheckSync,Translate,TranslateUI", "--allow-pre-commit-input", "--disable-hang-monitor", "--disable-ipc-flooding-protection", "--disable-prompt-on-repost", "--disable-renderer-backgrounding", "--force-color-profile=srgb", "--metrics-recording-only", "--no-first-run", "--enable-automation", "--password-store=basic", "--use-mock-keychain", "--no-service-autorun", "--export-tagged-pdf", "--enable-use-zoom-for-dsf=false"];
92
87
  async function getPlaywrightConstructsForMode(mode, cdpAddress, authSession) {
93
88
  if (mode == "playwright-standalone") {
94
89
  if (!cdpAddress) {
@@ -101,10 +96,15 @@ async function getPlaywrightConstructsForMode(mode, cdpAddress, authSession) {
101
96
  throw new Error("no context found");
102
97
  }
103
98
  const assetsFile = _path.default.join(__dirname, "./assets/browser_scripts.js");
99
+ await context.addInitScript({
100
+ path: assetsFile
101
+ });
104
102
  const pages = await context.pages();
105
103
  let page = null;
106
104
  if (pages.length > 0) {
107
105
  page = pages[0];
106
+ const scriptString = await fs.readFile(assetsFile, "utf8");
107
+ await page.evaluate(scriptString);
108
108
  } else {
109
109
  page = await context.newPage();
110
110
  }
@@ -155,7 +155,7 @@ async function loadSessionToContext({
155
155
  await (0, _contextStorageStateHelpers.setStorageState)(context, sessionToLoad);
156
156
  }
157
157
  async function getRemotePlaywrightContext(cdpAddress) {
158
- const playwright = await Promise.resolve().then(() => _interopRequireWildcard(require("patchright")));
158
+ const playwright = await Promise.resolve().then(() => _interopRequireWildcard(require("playwright")));
159
159
  let browser = null;
160
160
  if (!cdpAddress) {
161
161
  throw new Error("cdpAddress is required");
@@ -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,
@@ -10,7 +10,7 @@ export declare const maxLevelsExceededErrorCode = "MaxLevelsExceededError";
10
10
  export declare const automationError = "AutomationError";
11
11
  export declare const internalInvalidInputErrorCode = "InternalInvalidInputError";
12
12
  export declare const runAutomationErrorCodes: readonly ["APINotFoundError", "InvalidAPIError", "InvalidCheckError", "AbortedError", "AuthRequiredError", "AuthCheckNotFoundError", "AuthCheckFailedError", "MaxLevelsExceededError", "AutomationError", "InternalInvalidInputError"];
13
- export type RunAutomationErrorCode = (typeof runAutomationErrorCodes)[number];
13
+ export type RunAutomationErrorCode = typeof runAutomationErrorCodes[number];
14
14
  export declare abstract class RunAutomationError<T = any> {
15
15
  code: RunAutomationErrorCode;
16
16
  statusCode: number;
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.runAutomationErrorCodes = exports.maxLevelsExceededErrorCode = exports.invalidCheckErrorCode = exports.invalidApiErrorCode = exports.internalInvalidInputErrorCode = exports.automationError = exports.authRequiredErrorCode = exports.authCheckNotFoundErrorCode = exports.authCheckFailedErrorCode = exports.apiNotFoundErrorCode = exports.abortedErrorCode = exports.RunAutomationError = exports.MaxLevelsExceededError = exports.InvalidCheckError = exports.InvalidApiError = exports.InternalInvalidInputError = exports.AutomationError = exports.AuthRequiredError = exports.AuthCheckNotFoundError = exports.AuthCheckFailedError = exports.ApiNotFoundError = exports.AbortedError = void 0;
7
7
  var _runtime = require("../../runtime");
8
- var playwright = _interopRequireWildcard(require("patchright"));
8
+ var playwright = _interopRequireWildcard(require("playwright-core"));
9
9
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
10
10
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
11
11
  const apiNotFoundErrorCode = exports.apiNotFoundErrorCode = "APINotFoundError";
@@ -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
  }
@@ -1,6 +1,6 @@
1
1
  import { Result } from "neverthrow";
2
2
  import { RunAutomationError } from "./errors";
3
- import { Page, BrowserContext } from "patchright";
3
+ import { Page, BrowserContext } from "playwright";
4
4
  import { ExtendedRunApiParameters, RunApiResult, RunApiResultWithSessionOk } from "./types";
5
5
  export * from "./types";
6
6
  export * from "./errors";
@@ -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({
@@ -152,17 +150,21 @@ async function* runApiGenerator({
152
150
  }
153
151
  (0, _cleanEnvironmentVariables.cleanEnvironmentVariables)();
154
152
  if (checkFn !== undefined) {
155
- console.log("Running auth check");
156
- const authCheckResult = await checkAuthSessionWithRetries(page, context, checkFn, 2);
157
- if (authCheckResult.isErr()) {
158
- const error = authCheckResult.error;
159
- if (["APINotFoundError", "InvalidAPIError"].includes(error.code)) {
160
- return (0, _neverthrow.err)(new _errors.InvalidCheckError(`Auth session check function failed`, error));
153
+ try {
154
+ console.log("Running auth check");
155
+ const authCheckResult = await checkAuthSessionWithRetries(page, context, checkFn, 2);
156
+ if (authCheckResult.isErr()) {
157
+ const error = authCheckResult.error;
158
+ if (["APINotFoundError", "InvalidAPIError"].includes(error.code)) {
159
+ return (0, _neverthrow.err)(new _errors.InvalidCheckError(`Auth session check function failed`, error));
160
+ }
161
+ return authCheckResult;
161
162
  }
162
- return authCheckResult;
163
- }
164
- if (!authCheckResult.value) {
165
- return (0, _neverthrow.err)(new _errors.AuthCheckFailedError());
163
+ if (!authCheckResult.value) {
164
+ return (0, _neverthrow.err)(new _errors.AuthCheckFailedError());
165
+ }
166
+ } catch (error) {
167
+ return (0, _neverthrow.err)(new _errors.InvalidCheckError(`Auth session check function failed: ${error.message}`, error));
166
168
  }
167
169
  }
168
170
  console.log("Running automation");
@@ -185,7 +187,7 @@ async function* runApiGenerator({
185
187
  }
186
188
  return (0, _neverthrow.ok)({
187
189
  result,
188
- extendedPayloads: (_getExecutionContext = (0, _asyncLocalStorage.getExecutionContext)()) === null || _getExecutionContext === void 0 ? void 0 : _getExecutionContext.extendedPayloads,
190
+ extendedPayloads: (0, _asyncLocalStorage.getExecutionContext)()?.extendedPayloads,
189
191
  session: retrieveSession ? await (0, _contextStorageStateHelpers.getStorageState)(context) : undefined
190
192
  });
191
193
  }
@@ -206,11 +208,10 @@ async function* runApiGenerator({
206
208
  } catch (error) {
207
209
  return (0, _neverthrow.err)(new _errors.AutomationError(error));
208
210
  } finally {
209
- var _context2;
210
211
  await saveTraceIfNeeded({
211
212
  errorMessage: "failed to save trace"
212
213
  });
213
- await ((_context2 = context) === null || _context2 === void 0 ? void 0 : _context2.close());
214
+ await context?.close();
214
215
  if (downloadsPath !== undefined) {
215
216
  await fs.remove(downloadsPath);
216
217
  }
@@ -47,18 +47,18 @@ export declare const runApiSessionSchema: z.ZodDiscriminatedUnion<"type", [z.Zod
47
47
  secure: z.ZodBoolean;
48
48
  sameSite: z.ZodEnum<["Strict", "Lax", "None"]>;
49
49
  }, "strip", z.ZodTypeAny, {
50
- path: string;
51
50
  value: string;
52
51
  name: string;
52
+ path: string;
53
53
  domain: string;
54
54
  expires: number;
55
55
  httpOnly: boolean;
56
56
  secure: boolean;
57
57
  sameSite: "Strict" | "Lax" | "None";
58
58
  }, {
59
- path: string;
60
59
  value: string;
61
60
  name: string;
61
+ path: string;
62
62
  domain: string;
63
63
  expires: number;
64
64
  httpOnly: boolean;
@@ -117,9 +117,9 @@ export declare const runApiSessionSchema: z.ZodDiscriminatedUnion<"type", [z.Zod
117
117
  }>, "many">>;
118
118
  }, "strip", z.ZodTypeAny, {
119
119
  cookies: {
120
- path: string;
121
120
  value: string;
122
121
  name: string;
122
+ path: string;
123
123
  domain: string;
124
124
  expires: number;
125
125
  httpOnly: boolean;
@@ -142,9 +142,9 @@ export declare const runApiSessionSchema: z.ZodDiscriminatedUnion<"type", [z.Zod
142
142
  }[] | undefined;
143
143
  }, {
144
144
  cookies: {
145
- path: string;
146
145
  value: string;
147
146
  name: string;
147
+ path: string;
148
148
  domain: string;
149
149
  expires: number;
150
150
  httpOnly: boolean;
@@ -170,9 +170,9 @@ export declare const runApiSessionSchema: z.ZodDiscriminatedUnion<"type", [z.Zod
170
170
  type: "state";
171
171
  state?: {
172
172
  cookies: {
173
- path: string;
174
173
  value: string;
175
174
  name: string;
175
+ path: string;
176
176
  domain: string;
177
177
  expires: number;
178
178
  httpOnly: boolean;
@@ -198,9 +198,9 @@ export declare const runApiSessionSchema: z.ZodDiscriminatedUnion<"type", [z.Zod
198
198
  type: "state";
199
199
  state?: {
200
200
  cookies: {
201
- path: string;
202
201
  value: string;
203
202
  name: string;
203
+ path: string;
204
204
  domain: string;
205
205
  expires: number;
206
206
  httpOnly: boolean;
@@ -273,18 +273,18 @@ export declare const runApiParametersSchema: z.ZodObject<{
273
273
  secure: z.ZodBoolean;
274
274
  sameSite: z.ZodEnum<["Strict", "Lax", "None"]>;
275
275
  }, "strip", z.ZodTypeAny, {
276
- path: string;
277
276
  value: string;
278
277
  name: string;
278
+ path: string;
279
279
  domain: string;
280
280
  expires: number;
281
281
  httpOnly: boolean;
282
282
  secure: boolean;
283
283
  sameSite: "Strict" | "Lax" | "None";
284
284
  }, {
285
- path: string;
286
285
  value: string;
287
286
  name: string;
287
+ path: string;
288
288
  domain: string;
289
289
  expires: number;
290
290
  httpOnly: boolean;
@@ -343,9 +343,9 @@ export declare const runApiParametersSchema: z.ZodObject<{
343
343
  }>, "many">>;
344
344
  }, "strip", z.ZodTypeAny, {
345
345
  cookies: {
346
- path: string;
347
346
  value: string;
348
347
  name: string;
348
+ path: string;
349
349
  domain: string;
350
350
  expires: number;
351
351
  httpOnly: boolean;
@@ -368,9 +368,9 @@ export declare const runApiParametersSchema: z.ZodObject<{
368
368
  }[] | undefined;
369
369
  }, {
370
370
  cookies: {
371
- path: string;
372
371
  value: string;
373
372
  name: string;
373
+ path: string;
374
374
  domain: string;
375
375
  expires: number;
376
376
  httpOnly: boolean;
@@ -396,9 +396,9 @@ export declare const runApiParametersSchema: z.ZodObject<{
396
396
  type: "state";
397
397
  state?: {
398
398
  cookies: {
399
- path: string;
400
399
  value: string;
401
400
  name: string;
401
+ path: string;
402
402
  domain: string;
403
403
  expires: number;
404
404
  httpOnly: boolean;
@@ -424,9 +424,9 @@ export declare const runApiParametersSchema: z.ZodObject<{
424
424
  type: "state";
425
425
  state?: {
426
426
  cookies: {
427
- path: string;
428
427
  value: string;
429
428
  name: string;
429
+ path: string;
430
430
  domain: string;
431
431
  expires: number;
432
432
  httpOnly: boolean;
@@ -458,9 +458,9 @@ export declare const runApiParametersSchema: z.ZodObject<{
458
458
  type: "state";
459
459
  state?: {
460
460
  cookies: {
461
- path: string;
462
461
  value: string;
463
462
  name: string;
463
+ path: string;
464
464
  domain: string;
465
465
  expires: number;
466
466
  httpOnly: boolean;
@@ -492,9 +492,9 @@ export declare const runApiParametersSchema: z.ZodObject<{
492
492
  type: "state";
493
493
  state?: {
494
494
  cookies: {
495
- path: string;
496
495
  value: string;
497
496
  name: string;
497
+ path: string;
498
498
  domain: string;
499
499
  expires: number;
500
500
  httpOnly: boolean;
@@ -598,9 +598,9 @@ export declare const runApiParametersSchema: z.ZodObject<{
598
598
  type: "state";
599
599
  state?: {
600
600
  cookies: {
601
- path: string;
602
601
  value: string;
603
602
  name: string;
603
+ path: string;
604
604
  domain: string;
605
605
  expires: number;
606
606
  httpOnly: boolean;
@@ -644,9 +644,9 @@ export declare const runApiParametersSchema: z.ZodObject<{
644
644
  type: "state";
645
645
  state?: {
646
646
  cookies: {
647
- path: string;
648
647
  value: string;
649
648
  name: string;
649
+ path: string;
650
650
  domain: string;
651
651
  expires: number;
652
652
  httpOnly: boolean;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { extendPayload, extendTimeout, runInfo, RunError, requestMultipleChoice, requestOTP, } from "./runtime";
1
+ export { extendPayload, extendTimeout, runInfo, RunError, requestMultipleChoice, requestOTP, getAuthSessionParameters, } from "./runtime";
2
2
  export { runWithContext, getExecutionContext, } from "./common/asyncLocalStorage";
3
3
  export { getDownloadDirectoryPath } from "./runtime/downloadDirectory";
4
4
  export { getProductionPlaywrightConstructs } from "./common/getPlaywrightConstructs";
package/dist/index.js CHANGED
@@ -21,6 +21,12 @@ Object.defineProperty(exports, "extendTimeout", {
21
21
  return _runtime.extendTimeout;
22
22
  }
23
23
  });
24
+ Object.defineProperty(exports, "getAuthSessionParameters", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _runtime.getAuthSessionParameters;
28
+ }
29
+ });
24
30
  Object.defineProperty(exports, "getDownloadDirectoryPath", {
25
31
  enumerable: true,
26
32
  get: function () {
@@ -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
  });