@intuned/runtime-dev 1.2.0-dev-52 → 1.2.1-hooks.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 (135) hide show
  1. package/.babelrc +2 -2
  2. package/.npmrc.wtf +1 -0
  3. package/CHANGELOG.md +5 -1
  4. package/WebTemplate.zip +0 -0
  5. package/bin/intuned +2 -0
  6. package/dist/commands/api/run.js +4 -3
  7. package/dist/commands/common/getFirstLineNumber.js +2 -4
  8. package/dist/commands/interface/run.js +5 -6
  9. package/dist/commands/intuned-cli/commands/attempt.command.d.ts +1 -0
  10. package/dist/commands/intuned-cli/commands/attempt.command.js +8 -0
  11. package/dist/commands/intuned-cli/commands/attempt_api.command.d.ts +1 -0
  12. package/dist/commands/intuned-cli/commands/attempt_api.command.js +40 -0
  13. package/dist/commands/intuned-cli/commands/attempt_authsession.command.d.ts +1 -0
  14. package/dist/commands/intuned-cli/commands/attempt_authsession.command.js +8 -0
  15. package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.d.ts +1 -0
  16. package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.js +24 -0
  17. package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.d.ts +1 -0
  18. package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.js +36 -0
  19. package/dist/commands/intuned-cli/commands/build.command.d.ts +1 -0
  20. package/dist/commands/intuned-cli/commands/build.command.js +12 -0
  21. package/dist/commands/intuned-cli/commands/command.d.ts +2 -0
  22. package/dist/commands/intuned-cli/commands/command.js +9 -0
  23. package/dist/commands/intuned-cli/commands/deploy.command.d.ts +1 -0
  24. package/dist/commands/intuned-cli/commands/deploy.command.js +46 -0
  25. package/dist/commands/intuned-cli/commands/index.d.ts +15 -0
  26. package/dist/commands/intuned-cli/commands/index.js +170 -0
  27. package/dist/commands/intuned-cli/commands/init.command.d.ts +1 -0
  28. package/dist/commands/intuned-cli/commands/init.command.js +13 -0
  29. package/dist/commands/intuned-cli/commands/run.command.d.ts +1 -0
  30. package/dist/commands/intuned-cli/commands/run.command.js +8 -0
  31. package/dist/commands/intuned-cli/commands/run_api.command.d.ts +1 -0
  32. package/dist/commands/intuned-cli/commands/run_api.command.js +54 -0
  33. package/dist/commands/intuned-cli/commands/run_authsession.command.d.ts +20 -0
  34. package/dist/commands/intuned-cli/commands/run_authsession.command.js +13 -0
  35. package/dist/commands/intuned-cli/commands/run_authsession_create.command.d.ts +1 -0
  36. package/dist/commands/intuned-cli/commands/run_authsession_create.command.js +39 -0
  37. package/dist/commands/intuned-cli/commands/run_authsession_update.command.d.ts +1 -0
  38. package/dist/commands/intuned-cli/commands/run_authsession_update.command.js +39 -0
  39. package/dist/commands/intuned-cli/commands/run_authsession_validate.command.d.ts +1 -0
  40. package/dist/commands/intuned-cli/commands/run_authsession_validate.command.js +37 -0
  41. package/dist/commands/intuned-cli/commands/types.d.ts +21 -0
  42. package/dist/commands/intuned-cli/commands/types.js +21 -0
  43. package/dist/commands/intuned-cli/constants/index.d.ts +17 -0
  44. package/dist/commands/intuned-cli/constants/index.js +25 -0
  45. package/dist/commands/intuned-cli/controller/__test__/api.test.js +280 -0
  46. package/dist/commands/intuned-cli/controller/__test__/authSession.test.js +676 -0
  47. package/dist/commands/intuned-cli/controller/api.d.ts +44 -0
  48. package/dist/commands/intuned-cli/controller/api.js +181 -0
  49. package/dist/commands/intuned-cli/controller/authSession.d.ts +198 -0
  50. package/dist/commands/intuned-cli/controller/authSession.js +292 -0
  51. package/dist/commands/intuned-cli/controller/build.d.ts +1 -0
  52. package/dist/commands/intuned-cli/controller/build.js +36 -0
  53. package/dist/commands/intuned-cli/controller/deploy.d.ts +15 -0
  54. package/dist/commands/{deploy/utils.js → intuned-cli/controller/deploy.js} +115 -109
  55. package/dist/commands/intuned-cli/controller/index.d.ts +1 -0
  56. package/dist/commands/intuned-cli/controller/index.js +46 -0
  57. package/dist/commands/intuned-cli/helpers/api.d.ts +3 -0
  58. package/dist/commands/intuned-cli/helpers/api.js +19 -0
  59. package/dist/commands/intuned-cli/helpers/auth.d.ts +41 -0
  60. package/dist/commands/intuned-cli/helpers/auth.js +129 -0
  61. package/dist/commands/intuned-cli/helpers/backend.d.ts +8 -0
  62. package/dist/commands/intuned-cli/helpers/backend.js +26 -0
  63. package/dist/commands/intuned-cli/helpers/context.d.ts +3 -0
  64. package/dist/commands/intuned-cli/helpers/context.js +33 -0
  65. package/dist/commands/intuned-cli/helpers/errors.d.ts +14 -0
  66. package/dist/commands/intuned-cli/helpers/errors.js +55 -0
  67. package/dist/commands/intuned-cli/helpers/index.d.ts +10 -0
  68. package/dist/commands/intuned-cli/helpers/index.js +115 -0
  69. package/dist/commands/intuned-cli/helpers/intunedJson.d.ts +1 -0
  70. package/dist/{common/cli/utils.js → commands/intuned-cli/helpers/intunedJson.js} +0 -16
  71. package/dist/commands/intuned-cli/helpers/proxy.d.ts +5 -0
  72. package/dist/commands/intuned-cli/helpers/proxy.js +23 -0
  73. package/dist/commands/intuned-cli/helpers/terminal.d.ts +5 -0
  74. package/dist/commands/intuned-cli/helpers/terminal.js +13 -0
  75. package/dist/commands/intuned-cli/helpers/timeout.d.ts +1 -0
  76. package/dist/commands/intuned-cli/helpers/timeout.js +23 -0
  77. package/dist/commands/intuned-cli/helpers/validation.d.ts +2 -0
  78. package/dist/commands/intuned-cli/helpers/validation.js +12 -0
  79. package/dist/commands/intuned-cli/index.d.ts +1 -0
  80. package/dist/commands/intuned-cli/index.js +16 -0
  81. package/dist/commands/intuned-cli/main.d.ts +1 -0
  82. package/dist/commands/intuned-cli/main.js +15 -0
  83. package/dist/{common/cli → commands/intuned-cli}/types.d.ts +1 -34
  84. package/dist/{common/cli → commands/intuned-cli}/types.js +1 -2
  85. package/dist/common/assets/browser_scripts.js +2509 -2143
  86. package/dist/common/asyncLocalStorage/index.d.ts +1 -0
  87. package/dist/common/constants.d.ts +1 -0
  88. package/dist/common/constants.js +2 -1
  89. package/dist/common/getPlaywrightConstructs.d.ts +5 -4
  90. package/dist/common/getPlaywrightConstructs.js +71 -35
  91. package/dist/common/jwtTokenManager.js +3 -5
  92. package/dist/common/runApi/errors.js +5 -6
  93. package/dist/common/runApi/index.d.ts +3 -0
  94. package/dist/common/runApi/index.js +22 -21
  95. package/dist/common/runApi/types.d.ts +144 -13
  96. package/dist/common/runApi/types.js +28 -27
  97. package/dist/runtime/executionHelpers.test.js +3 -4
  98. package/dist/runtime/export.d.ts +17 -0
  99. package/dist/runtime/extendPayload.js +1 -1
  100. package/dist/runtime/getCdpAddress.d.ts +1 -0
  101. package/dist/runtime/getCdpAddress.js +11 -0
  102. package/dist/runtime/index.d.ts +1 -0
  103. package/dist/runtime/index.js +8 -1
  104. package/package.json +11 -12
  105. package/tsconfig.json +2 -1
  106. package/bin/check-auth-session +0 -3
  107. package/bin/cli-build +0 -3
  108. package/bin/create-auth-session +0 -3
  109. package/bin/deploy +0 -3
  110. package/bin/init +0 -3
  111. package/bin/run-api +0 -3
  112. package/dist/commands/cli-auth-sessions/check.d.ts +0 -2
  113. package/dist/commands/cli-auth-sessions/check.js +0 -40
  114. package/dist/commands/cli-auth-sessions/create.d.ts +0 -2
  115. package/dist/commands/cli-auth-sessions/create.js +0 -53
  116. package/dist/commands/cli-auth-sessions/utils.d.ts +0 -28
  117. package/dist/commands/cli-auth-sessions/utils.js +0 -285
  118. package/dist/commands/cli-build/cli-build.d.ts +0 -2
  119. package/dist/commands/cli-build/cli-build.js +0 -20
  120. package/dist/commands/deploy/deploy.d.ts +0 -2
  121. package/dist/commands/deploy/deploy.js +0 -47
  122. package/dist/commands/deploy/utils.d.ts +0 -16
  123. package/dist/commands/init/init.d.ts +0 -2
  124. package/dist/commands/init/init.js +0 -22
  125. package/dist/commands/init/utils.d.ts +0 -11
  126. package/dist/commands/init/utils.js +0 -181
  127. package/dist/commands/run-api-cli/run-api.d.ts +0 -2
  128. package/dist/commands/run-api-cli/run-api.js +0 -57
  129. package/dist/commands/run-api-cli/utils.d.ts +0 -9
  130. package/dist/commands/run-api-cli/utils.js +0 -144
  131. package/dist/common/cli/cliReadme.d.ts +0 -1
  132. package/dist/common/cli/cliReadme.js +0 -92
  133. package/dist/common/cli/constants.d.ts +0 -33
  134. package/dist/common/cli/constants.js +0 -39
  135. package/dist/common/cli/utils.d.ts +0 -6
@@ -8,6 +8,7 @@ interface TimeoutInfo {
8
8
  }
9
9
  export interface InternalRunInfo extends RunInfo {
10
10
  extendedPayloads: Payload[];
11
+ cdpAddress?: string;
11
12
  timeoutInfo?: TimeoutInfo;
12
13
  getAuthSessionParameters?: () => Promise<any>;
13
14
  }
@@ -1,2 +1,3 @@
1
+ export declare const API_FOLDER_NAME = "api";
1
2
  export declare const AUTH_SESSIONS_FOLDER_NAME = "auth-sessions";
2
3
  export declare const AUTH_SESSIONS_INSTANCES_FOLDER_NAME = "auth-sessions-instances";
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.AUTH_SESSIONS_INSTANCES_FOLDER_NAME = exports.AUTH_SESSIONS_FOLDER_NAME = void 0;
6
+ exports.AUTH_SESSIONS_INSTANCES_FOLDER_NAME = exports.AUTH_SESSIONS_FOLDER_NAME = exports.API_FOLDER_NAME = void 0;
7
+ const API_FOLDER_NAME = exports.API_FOLDER_NAME = "api";
7
8
  const AUTH_SESSIONS_FOLDER_NAME = exports.AUTH_SESSIONS_FOLDER_NAME = "auth-sessions";
8
9
  const AUTH_SESSIONS_INSTANCES_FOLDER_NAME = exports.AUTH_SESSIONS_INSTANCES_FOLDER_NAME = "auth-sessions-instances";
@@ -1,6 +1,6 @@
1
1
  import * as playwright from "playwright";
2
- import type { RunApiSession } from "./runApi";
3
- interface Proxy {
2
+ import type { ImportFunction, RunApiSession } from "./runApi";
3
+ export interface Proxy {
4
4
  server: string;
5
5
  username: string;
6
6
  password: string;
@@ -10,12 +10,13 @@ interface GetPlaywrightConstructsOptions {
10
10
  headless?: boolean;
11
11
  storageState?: RunApiSession;
12
12
  downloadsPath: string;
13
+ importFunction?: ImportFunction;
13
14
  }
14
- export declare function getProductionPlaywrightConstructs({ proxy, headless, storageState, downloadsPath, }: GetPlaywrightConstructsOptions): Promise<{
15
+ export declare function getProductionPlaywrightConstructs({ proxy, headless, storageState, downloadsPath, importFunction, }: GetPlaywrightConstructsOptions): Promise<{
15
16
  page: playwright.Page;
16
17
  context: playwright.BrowserContext;
17
18
  }>;
18
- export declare function getPlaywrightConstructsForMode(mode: "vanilla" | "playwright" | "playwright-standalone" | "playwright-headless", cdpAddress: string | undefined, authSession?: RunApiSession): Promise<{
19
+ export declare function getPlaywrightConstructsForMode(mode: "vanilla" | "playwright" | "playwright-standalone" | "playwright-headless", cdpAddress: string | undefined, authSession?: RunApiSession, importFunction?: ImportFunction): Promise<{
19
20
  page: playwright.Page;
20
21
  context: playwright.BrowserContext;
21
22
  }>;
@@ -33,42 +33,60 @@ async function createUserDirWithPreferences() {
33
33
  await (0, _fsExtra.writeFile)((0, _path.join)(defaultDir, "Preferences"), JSON.stringify(preferences));
34
34
  return userDir;
35
35
  }
36
+ async function loadGetDeployedPageAndContextHook(importFunction) {
37
+ const result = await importFunction("hooks/createDeployedContextAndPage");
38
+ if (result.isErr()) {
39
+ throw result.error;
40
+ }
41
+ return result.value.default;
42
+ }
36
43
  async function getProductionPlaywrightConstructs({
37
44
  proxy,
38
45
  headless = true,
39
46
  storageState,
40
- downloadsPath
47
+ downloadsPath,
48
+ importFunction
41
49
  }) {
42
- const extraArgs = ["--no-first-run", "--disable-sync", "--disable-translate", "--disable-features=TranslateUI", "--disable-features=NetworkService", "--lang=en"];
43
- if (headless) {
44
- extraArgs.push("--headless=new");
50
+ let context;
51
+ let page;
52
+ let hook = null;
53
+ if (importFunction) {
54
+ hook = await loadGetDeployedPageAndContextHook(importFunction);
45
55
  }
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
- const userDataDir = await createUserDirWithPreferences();
51
- const context = await playwright.chromium.launchPersistentContext(userDataDir, {
52
- headless,
53
- ignoreDefaultArgs: [...getChromiumLaunchArgsToIgnore(), "--headless"],
54
- proxy,
55
- executablePath: isChrome127There ? chromium127Path : executablePath,
56
- args: extraArgs,
57
- downloadsPath,
58
- userAgent
59
- });
60
- context.once("close", async () => {
61
- try {
62
- await (0, _fsExtra.rm)(userDataDir, {
63
- recursive: true,
64
- force: true,
65
- retryDelay: 1000,
66
- maxRetries: 5
67
- });
68
- } catch (error) {
69
- console.error("Failed to remove user data dir", error);
56
+ if (hook) {
57
+ ({
58
+ page,
59
+ context
60
+ } = await hook({
61
+ proxy,
62
+ headless
63
+ }));
64
+ } else {
65
+ const extraArgs = ["--no-first-run", "--disable-sync", "--disable-translate", "--disable-features=TranslateUI", "--disable-features=NetworkService", "--lang=en"];
66
+ if (headless) {
67
+ extraArgs.push("--headless=new");
70
68
  }
71
- });
69
+ const userDataDir = await createUserDirWithPreferences();
70
+ context = await playwright.chromium.launchPersistentContext(userDataDir, {
71
+ headless,
72
+ viewport: null,
73
+ proxy,
74
+ downloadsPath
75
+ });
76
+ context.once("close", async () => {
77
+ try {
78
+ await (0, _fsExtra.rm)(userDataDir, {
79
+ recursive: true,
80
+ force: true,
81
+ retryDelay: 1000,
82
+ maxRetries: 5
83
+ });
84
+ } catch (error) {
85
+ console.error("Failed to remove user data dir", error);
86
+ }
87
+ });
88
+ page = context.pages().at(0) ?? null;
89
+ }
72
90
  if (storageState) {
73
91
  await loadSessionToContext({
74
92
  context,
@@ -79,7 +97,6 @@ async function getProductionPlaywrightConstructs({
79
97
  await context.addInitScript({
80
98
  path: assetsFile
81
99
  });
82
- let page = context.pages().at(0);
83
100
  if (page) {
84
101
  const scriptString = await (0, _fsExtra.readFile)(assetsFile, "utf8");
85
102
  await page.evaluate(scriptString);
@@ -91,15 +108,34 @@ async function getProductionPlaywrightConstructs({
91
108
  context
92
109
  };
93
110
  }
94
- 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"];
95
- async function getPlaywrightConstructsForMode(mode, cdpAddress, authSession) {
111
+ async function loadGetIDEPageAndContextHook(importFunction) {
112
+ const result = await importFunction("hooks/createDeployedContextAndPage");
113
+ if (result.isErr()) {
114
+ throw result.error;
115
+ }
116
+ return result.value.default;
117
+ }
118
+ async function getPlaywrightConstructsForMode(mode, cdpAddress, authSession, importFunction) {
119
+ let hook = null;
120
+ if (importFunction) {
121
+ hook = await loadGetIDEPageAndContextHook(importFunction);
122
+ }
96
123
  if (mode == "playwright-standalone") {
97
124
  if (!cdpAddress) {
98
125
  throw new Error("cdpAddress is required");
99
126
  }
100
- const {
101
- context
102
- } = await getRemotePlaywrightContext(cdpAddress);
127
+ let context;
128
+ if (hook) {
129
+ ({
130
+ context
131
+ } = await hook({
132
+ cdpAddress
133
+ }));
134
+ } else {
135
+ ({
136
+ context
137
+ } = await getRemotePlaywrightContext(cdpAddress));
138
+ }
103
139
  if (!context) {
104
140
  throw new Error("no context found");
105
141
  }
@@ -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,
@@ -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("playwright"));
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
  }
@@ -8,6 +8,9 @@ export declare function runApiGenerator<ResultType = any, _YieldType = any, _Nex
8
8
  retrieveSession: true;
9
9
  }): AsyncGenerator<_YieldType, RunApiResult<ResultType, RunApiResultWithSessionOk>, _NextType>;
10
10
  export declare function runApiGenerator<ResultType = any, _YieldType = any, _NextType = any>(params: ExtendedRunApiParameters): AsyncGenerator<_YieldType, RunApiResult<ResultType>, _NextType>;
11
+ export declare function runApi<ResultType = any>(params: ExtendedRunApiParameters & {
12
+ retrieveSession: true;
13
+ }): Promise<RunApiResult<ResultType, RunApiResultWithSessionOk>>;
11
14
  export declare function runApi<ResultType = any>(params: ExtendedRunApiParameters): Promise<RunApiResult<ResultType>>;
12
15
  export declare function checkAuthSessionWithRetries(page: Page, context: BrowserContext, checkFn: (..._: any) => Promise<boolean>, retries?: number): Promise<Result<boolean, RunAutomationError>>;
13
16
  export type ImportFunction = ExtendedRunApiParameters["importFunction"];
@@ -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,8 @@ 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,
132
+ importFunction
134
133
  }));
135
134
  } else {
136
135
  const {
@@ -140,7 +139,7 @@ async function* runApiGenerator({
140
139
  ({
141
140
  page,
142
141
  context
143
- } = await (0, _getPlaywrightConstructs.getPlaywrightConstructsForMode)(mode, cdpAddress, auth === null || auth === void 0 ? void 0 : auth.session));
142
+ } = await (0, _getPlaywrightConstructs.getPlaywrightConstructsForMode)(mode, cdpAddress, auth?.session, importFunction));
144
143
  }
145
144
  if (tracing.enabled) {
146
145
  await context.tracing.start({
@@ -152,20 +151,23 @@ async function* runApiGenerator({
152
151
  }
153
152
  (0, _cleanEnvironmentVariables.cleanEnvironmentVariables)();
154
153
  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));
154
+ try {
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));
161
+ }
162
+ return authCheckResult;
161
163
  }
162
- return authCheckResult;
163
- }
164
- if (!authCheckResult.value) {
164
+ if (!authCheckResult.value) {
165
+ return (0, _neverthrow.err)(new _errors.AuthCheckFailedError());
166
+ }
167
+ } catch (error) {
165
168
  return (0, _neverthrow.err)(new _errors.AuthCheckFailedError());
166
169
  }
167
170
  }
168
- console.log("Running automation");
169
171
  const automationFunctionParameters = [...(automationFunction.params !== undefined ? [automationFunction.params] : []), page, context];
170
172
  let result;
171
173
  if (importedModule.type === "async-generator") {
@@ -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
  }
@@ -25,15 +25,146 @@ export interface RunAutomationResponse {
25
25
  status: number;
26
26
  body: RunAutomationResult;
27
27
  }
28
+ export declare const runApiStorageStateSchema: z.ZodObject<{
29
+ cookies: z.ZodArray<z.ZodObject<{
30
+ name: z.ZodString;
31
+ value: z.ZodString;
32
+ domain: z.ZodString;
33
+ path: z.ZodString;
34
+ expires: z.ZodNumber;
35
+ httpOnly: z.ZodBoolean;
36
+ secure: z.ZodBoolean;
37
+ sameSite: z.ZodEnum<["Strict", "Lax", "None"]>;
38
+ }, "strip", z.ZodTypeAny, {
39
+ value: string;
40
+ name: string;
41
+ path: string;
42
+ domain: string;
43
+ expires: number;
44
+ httpOnly: boolean;
45
+ secure: boolean;
46
+ sameSite: "Strict" | "Lax" | "None";
47
+ }, {
48
+ value: string;
49
+ name: string;
50
+ path: string;
51
+ domain: string;
52
+ expires: number;
53
+ httpOnly: boolean;
54
+ secure: boolean;
55
+ sameSite: "Strict" | "Lax" | "None";
56
+ }>, "many">;
57
+ origins: z.ZodArray<z.ZodObject<{
58
+ origin: z.ZodString;
59
+ localStorage: z.ZodArray<z.ZodObject<{
60
+ name: z.ZodString;
61
+ value: z.ZodString;
62
+ }, "strip", z.ZodTypeAny, {
63
+ value: string;
64
+ name: string;
65
+ }, {
66
+ value: string;
67
+ name: string;
68
+ }>, "many">;
69
+ }, "strip", z.ZodTypeAny, {
70
+ origin: string;
71
+ localStorage: {
72
+ value: string;
73
+ name: string;
74
+ }[];
75
+ }, {
76
+ origin: string;
77
+ localStorage: {
78
+ value: string;
79
+ name: string;
80
+ }[];
81
+ }>, "many">;
82
+ sessionStorage: z.ZodOptional<z.ZodArray<z.ZodObject<{
83
+ origin: z.ZodString;
84
+ sessionStorage: z.ZodArray<z.ZodObject<{
85
+ name: z.ZodString;
86
+ value: z.ZodString;
87
+ }, "strip", z.ZodTypeAny, {
88
+ value: string;
89
+ name: string;
90
+ }, {
91
+ value: string;
92
+ name: string;
93
+ }>, "many">;
94
+ }, "strip", z.ZodTypeAny, {
95
+ sessionStorage: {
96
+ value: string;
97
+ name: string;
98
+ }[];
99
+ origin: string;
100
+ }, {
101
+ sessionStorage: {
102
+ value: string;
103
+ name: string;
104
+ }[];
105
+ origin: string;
106
+ }>, "many">>;
107
+ }, "strip", z.ZodTypeAny, {
108
+ cookies: {
109
+ value: string;
110
+ name: string;
111
+ path: string;
112
+ domain: string;
113
+ expires: number;
114
+ httpOnly: boolean;
115
+ secure: boolean;
116
+ sameSite: "Strict" | "Lax" | "None";
117
+ }[];
118
+ origins: {
119
+ origin: string;
120
+ localStorage: {
121
+ value: string;
122
+ name: string;
123
+ }[];
124
+ }[];
125
+ sessionStorage?: {
126
+ sessionStorage: {
127
+ value: string;
128
+ name: string;
129
+ }[];
130
+ origin: string;
131
+ }[] | undefined;
132
+ }, {
133
+ cookies: {
134
+ value: string;
135
+ name: string;
136
+ path: string;
137
+ domain: string;
138
+ expires: number;
139
+ httpOnly: boolean;
140
+ secure: boolean;
141
+ sameSite: "Strict" | "Lax" | "None";
142
+ }[];
143
+ origins: {
144
+ origin: string;
145
+ localStorage: {
146
+ value: string;
147
+ name: string;
148
+ }[];
149
+ }[];
150
+ sessionStorage?: {
151
+ sessionStorage: {
152
+ value: string;
153
+ name: string;
154
+ }[];
155
+ origin: string;
156
+ }[] | undefined;
157
+ }>;
158
+ export type RunApiStorageState = z.input<typeof runApiStorageStateSchema>;
28
159
  export declare const runApiSessionSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
29
160
  type: z.ZodLiteral<"file">;
30
161
  path: z.ZodString;
31
162
  }, "strip", z.ZodTypeAny, {
32
- type: "file";
33
163
  path: string;
34
- }, {
35
164
  type: "file";
165
+ }, {
36
166
  path: string;
167
+ type: "file";
37
168
  }>, z.ZodObject<{
38
169
  type: z.ZodLiteral<"state">;
39
170
  state: z.ZodOptional<z.ZodNullable<z.ZodObject<{
@@ -255,11 +386,11 @@ export declare const runApiParametersSchema: z.ZodObject<{
255
386
  type: z.ZodLiteral<"file">;
256
387
  path: z.ZodString;
257
388
  }, "strip", z.ZodTypeAny, {
258
- type: "file";
259
389
  path: string;
260
- }, {
261
390
  type: "file";
391
+ }, {
262
392
  path: string;
393
+ type: "file";
263
394
  }>, z.ZodObject<{
264
395
  type: z.ZodLiteral<"state">;
265
396
  state: z.ZodOptional<z.ZodNullable<z.ZodObject<{
@@ -452,8 +583,8 @@ export declare const runApiParametersSchema: z.ZodObject<{
452
583
  runCheck: z.ZodDefault<z.ZodBoolean>;
453
584
  }, "strip", z.ZodTypeAny, {
454
585
  session: {
455
- type: "file";
456
586
  path: string;
587
+ type: "file";
457
588
  } | {
458
589
  type: "state";
459
590
  state?: {
@@ -486,8 +617,8 @@ export declare const runApiParametersSchema: z.ZodObject<{
486
617
  runCheck: boolean;
487
618
  }, {
488
619
  session: {
489
- type: "file";
490
620
  path: string;
621
+ type: "file";
491
622
  } | {
492
623
  type: "state";
493
624
  state?: {
@@ -556,13 +687,13 @@ export declare const runApiParametersSchema: z.ZodObject<{
556
687
  cdpAddress: z.ZodString;
557
688
  mode: z.ZodUnion<[z.ZodLiteral<"vanilla">, z.ZodLiteral<"playwright">, z.ZodLiteral<"playwright-standalone">, z.ZodLiteral<"playwright-headless">]>;
558
689
  }, "strip", z.ZodTypeAny, {
690
+ cdpAddress: string;
559
691
  mode: "vanilla" | "playwright" | "playwright-standalone" | "playwright-headless";
560
692
  environment: "cdp";
561
- cdpAddress: string;
562
693
  }, {
694
+ cdpAddress: string;
563
695
  mode: "vanilla" | "playwright" | "playwright-standalone" | "playwright-headless";
564
696
  environment: "cdp";
565
- cdpAddress: string;
566
697
  }>]>>;
567
698
  retrieveSession: z.ZodDefault<z.ZodBoolean>;
568
699
  }, "strip", z.ZodTypeAny, {
@@ -585,15 +716,15 @@ export declare const runApiParametersSchema: z.ZodObject<{
585
716
  password: string;
586
717
  } | undefined;
587
718
  } | {
719
+ cdpAddress: string;
588
720
  mode: "vanilla" | "playwright" | "playwright-standalone" | "playwright-headless";
589
721
  environment: "cdp";
590
- cdpAddress: string;
591
722
  };
592
723
  retrieveSession: boolean;
593
724
  auth?: {
594
725
  session: {
595
- type: "file";
596
726
  path: string;
727
+ type: "file";
597
728
  } | {
598
729
  type: "state";
599
730
  state?: {
@@ -638,8 +769,8 @@ export declare const runApiParametersSchema: z.ZodObject<{
638
769
  } | undefined;
639
770
  auth?: {
640
771
  session: {
641
- type: "file";
642
772
  path: string;
773
+ type: "file";
643
774
  } | {
644
775
  type: "state";
645
776
  state?: {
@@ -680,9 +811,9 @@ export declare const runApiParametersSchema: z.ZodObject<{
680
811
  password: string;
681
812
  } | undefined;
682
813
  } | {
814
+ cdpAddress: string;
683
815
  mode: "vanilla" | "playwright" | "playwright-standalone" | "playwright-headless";
684
816
  environment: "cdp";
685
- cdpAddress: string;
686
817
  } | undefined;
687
818
  retrieveSession?: boolean | undefined;
688
819
  }>;
@@ -703,6 +834,6 @@ export type RunApiResultOk<R = any> = {
703
834
  extendedPayloads?: Payload[];
704
835
  };
705
836
  export type RunApiResultWithSessionOk<R = any> = RunApiResultOk<R> & {
706
- session: StorageState;
837
+ session: RunApiStorageState;
707
838
  };
708
839
  export type RunApiResult<R = any, FullResult extends RunApiResultOk<R> = RunApiResultOk<R>> = Result<FullResult, RunAutomationError>;