@intuned/runtime-dev 1.1.6-dev-52 → 1.1.6-fiber.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.
@@ -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: "bundler",
30
+ moduleResolution: "NodeNext",
31
+ module: "NodeNext",
31
32
  target: "ES2021",
32
33
  outDir: "./dist",
33
34
  sourceMap: false,
@@ -1,4 +1,4 @@
1
- import * as playwright from "playwright-core";
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("playwright-core"));
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 {
@@ -91,7 +84,6 @@ async function getProductionPlaywrightConstructs({
91
84
  context
92
85
  };
93
86
  }
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
87
  async function getPlaywrightConstructsForMode(mode, cdpAddress, authSession) {
96
88
  if (mode == "playwright-standalone") {
97
89
  if (!cdpAddress) {
@@ -163,7 +155,7 @@ async function loadSessionToContext({
163
155
  await (0, _contextStorageStateHelpers.setStorageState)(context, sessionToLoad);
164
156
  }
165
157
  async function getRemotePlaywrightContext(cdpAddress) {
166
- const playwright = await Promise.resolve().then(() => _interopRequireWildcard(require("playwright-core")));
158
+ const playwright = await Promise.resolve().then(() => _interopRequireWildcard(require("playwright")));
167
159
  let browser = null;
168
160
  if (!cdpAddress) {
169
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,
@@ -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 "playwright-core";
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,16 +150,20 @@ 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) {
163
+ if (!authCheckResult.value) {
164
+ return (0, _neverthrow.err)(new _errors.AuthCheckFailedError());
165
+ }
166
+ } catch (error) {
165
167
  return (0, _neverthrow.err)(new _errors.AuthCheckFailedError());
166
168
  }
167
169
  }
@@ -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
  }
@@ -545,12 +545,12 @@ export declare const runApiParametersSchema: z.ZodObject<{
545
545
  } | undefined;
546
546
  }, {
547
547
  environment: "standalone";
548
- headless?: boolean | undefined;
549
548
  proxy?: {
550
549
  server: string;
551
550
  username: string;
552
551
  password: string;
553
552
  } | undefined;
553
+ headless?: boolean | undefined;
554
554
  }>, z.ZodObject<{
555
555
  environment: z.ZodLiteral<"cdp">;
556
556
  cdpAddress: z.ZodString;
@@ -673,12 +673,12 @@ export declare const runApiParametersSchema: z.ZodObject<{
673
673
  } | undefined;
674
674
  runOptions?: {
675
675
  environment: "standalone";
676
- headless?: boolean | undefined;
677
676
  proxy?: {
678
677
  server: string;
679
678
  username: string;
680
679
  password: string;
681
680
  } | undefined;
681
+ headless?: boolean | undefined;
682
682
  } | {
683
683
  mode: "vanilla" | "playwright" | "playwright-standalone" | "playwright-headless";
684
684
  environment: "cdp";
@@ -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
  });
@@ -201,3 +201,18 @@ export declare function requestMultipleChoice(
201
201
  * ```
202
202
  */
203
203
  export declare function requestOTP(message: string): unknown;
204
+
205
+ /**
206
+ * Retrieves the parameters for the authentication session currently being used.
207
+ *
208
+ * @returns {AuthSessionParameters} An object containing the parameters for the current authentication session.
209
+ *
210
+ * @example
211
+ * ```typescript getAuthSessionParameters
212
+ * import { getAuthSessionParameters } from "@intuned/sdk/runtime"
213
+ *
214
+ * const authSessionParams = getAuthSessionParameters();
215
+ * console.log(authSessionParams);
216
+ * ```
217
+ */
218
+ export declare function getAuthSessionParameters(): Promise<any>;
@@ -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.1.6-dev-52",
3
+ "version": "1.1.6-fiber.1",
4
4
  "description": "Intuned runtime",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",
@@ -69,7 +69,6 @@
69
69
  "@types/node": "20.4.1",
70
70
  "applicationinsights": "2.9.2",
71
71
  "babel-plugin-dynamic-import-node": "2.3.3",
72
- "boxen": "8.0.1",
73
72
  "chalk": "^4.1.2",
74
73
  "commander": "^11.0.0",
75
74
  "cross-fetch": "^4.0.0",
@@ -83,7 +82,6 @@
83
82
  "minimatch": "10.0.1",
84
83
  "nanoid": "3",
85
84
  "neverthrow": "6.1.0",
86
- "playwright": "npm:patchright@1.52.4",
87
85
  "playwright-extra": "4.3.6",
88
86
  "prettier": "2.8.0",
89
87
  "promptly": "3.2.0",
@@ -129,5 +127,9 @@
129
127
  "vite-node": "^1.1.3",
130
128
  "vite-plugin-babel-macros": "^1.0.6",
131
129
  "vitest": "^1.1.3"
132
- }
133
- }
130
+ },
131
+ "peerDependencies": {
132
+ "playwright": "*"
133
+ },
134
+ "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
135
+ }