@intuned/runtime-dev 1.2.1-hooks.2 → 1.2.1-hooks.4

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.
@@ -8,8 +8,8 @@ interface TimeoutInfo {
8
8
  }
9
9
  export interface InternalRunInfo extends RunInfo {
10
10
  extendedPayloads: Payload[];
11
- cdpAddress?: string;
12
11
  timeoutInfo?: TimeoutInfo;
12
+ hookVars?: Record<string, any>;
13
13
  getAuthSessionParameters?: () => Promise<any>;
14
14
  }
15
15
  export declare function getExecutionContext(): InternalRunInfo | undefined;
@@ -10,13 +10,17 @@ interface GetPlaywrightConstructsOptions {
10
10
  headless?: boolean;
11
11
  storageState?: RunApiSession;
12
12
  downloadsPath: string;
13
- importFunction?: ImportFunction;
13
+ hookOptions?: {
14
+ importFunction: ImportFunction;
15
+ apiName: string;
16
+ parameters: any;
17
+ };
14
18
  }
15
- export declare function getProductionPlaywrightConstructs({ proxy, headless, storageState, downloadsPath, importFunction, }: GetPlaywrightConstructsOptions): Promise<{
19
+ export declare function getProductionPlaywrightConstructs({ proxy, headless, storageState, downloadsPath, hookOptions, }: GetPlaywrightConstructsOptions): Promise<{
16
20
  page: playwright.Page;
17
21
  context: playwright.BrowserContext;
18
22
  }>;
19
- export declare function getPlaywrightConstructsForMode(mode: "vanilla" | "playwright" | "playwright-standalone" | "playwright-headless", cdpAddress: string | undefined, authSession?: RunApiSession, importFunction?: ImportFunction): Promise<{
23
+ export declare function getPlaywrightConstructsForMode(mode: "vanilla" | "playwright" | "playwright-standalone" | "playwright-headless", cdpAddress: string | undefined, authSession?: RunApiSession, hookOptions?: GetPlaywrightConstructsOptions["hookOptions"]): Promise<{
20
24
  page: playwright.Page;
21
25
  context: playwright.BrowserContext;
22
26
  }>;
@@ -15,6 +15,8 @@ var _path = _interopRequireWildcard(require("path"));
15
15
  var _fileUtils = require("../commands/common/utils/fileUtils");
16
16
  var _waitOn = _interopRequireDefault(require("wait-on"));
17
17
  var _runtime = require("../runtime");
18
+ var _asyncLocalStorage = require("./asyncLocalStorage");
19
+ var _promises = require("timers/promises");
18
20
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
19
21
  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); }
20
22
  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; }
@@ -53,48 +55,63 @@ async function getProductionPlaywrightConstructs({
53
55
  headless = true,
54
56
  storageState,
55
57
  downloadsPath,
56
- importFunction
58
+ hookOptions
57
59
  }) {
58
- let context;
59
- let page;
60
+ const extraArgs = [];
61
+ const port = 9222;
60
62
  let hook = null;
61
- if (importFunction) {
62
- hook = await loadInitializeContextHook(importFunction);
63
+ if (hookOptions) {
64
+ hook = await loadInitializeContextHook(hookOptions.importFunction);
63
65
  }
66
+ const userDataDir = await createUserDirWithPreferences();
64
67
  if (hook) {
65
- ({
66
- page,
67
- context
68
- } = await hook({
69
- type: "launch",
70
- proxy,
71
- headless
72
- }));
73
- } else {
74
- const extraArgs = ["--no-first-run", "--disable-sync", "--disable-translate", "--disable-features=TranslateUI", "--disable-features=NetworkService", "--lang=en"];
75
- if (headless) {
76
- extraArgs.push("--headless=new");
68
+ extraArgs.push(`--remote-debugging-port=${port}`);
69
+ }
70
+ const originalContext = await playwright.chromium.launchPersistentContext(userDataDir, {
71
+ headless,
72
+ viewport: null,
73
+ proxy,
74
+ downloadsPath,
75
+ args: extraArgs
76
+ });
77
+ const cdpAddress = `http://localhost:${port}`;
78
+ await (0, _promises.setTimeout)(3000);
79
+ originalContext.once("close", async () => {
80
+ try {
81
+ await (0, _fsExtra.rm)(userDataDir, {
82
+ recursive: true,
83
+ force: true,
84
+ retryDelay: 1000,
85
+ maxRetries: 5
86
+ });
87
+ } catch (error) {
88
+ console.error("Failed to remove user data dir", error);
77
89
  }
78
- const userDataDir = await createUserDirWithPreferences();
79
- context = await playwright.chromium.launchPersistentContext(userDataDir, {
80
- headless,
81
- viewport: null,
82
- proxy,
83
- downloadsPath
90
+ });
91
+ let page = originalContext.pages().at(0) ?? null;
92
+ let context = originalContext;
93
+ if (hookOptions && hook) {
94
+ const hookResult = await hook({
95
+ apiName: hookOptions.apiName,
96
+ apiParameters: hookOptions.parameters,
97
+ cdpAddress
84
98
  });
85
- context.once("close", async () => {
86
- try {
87
- await (0, _fsExtra.rm)(userDataDir, {
88
- recursive: true,
89
- force: true,
90
- retryDelay: 1000,
91
- maxRetries: 5
92
- });
93
- } catch (error) {
94
- console.error("Failed to remove user data dir", error);
99
+ if (hookResult !== null) {
100
+ ({
101
+ page,
102
+ context
103
+ } = hookResult);
104
+ const {
105
+ hookVars
106
+ } = hookResult;
107
+ const executionContext = (0, _asyncLocalStorage.getExecutionContext)();
108
+ if (hookVars && executionContext) {
109
+ executionContext.hookVars = hookVars;
95
110
  }
96
- });
97
- page = context.pages().at(0) ?? null;
111
+ context.once("close", async () => {
112
+ await originalContext.close();
113
+ });
114
+ }
98
115
  }
99
116
  if (storageState) {
100
117
  await loadSessionToContext({
@@ -117,26 +134,37 @@ async function getProductionPlaywrightConstructs({
117
134
  context
118
135
  };
119
136
  }
120
- async function getPlaywrightConstructsForMode(mode, cdpAddress, authSession, importFunction) {
121
- let hook = null;
122
- if (importFunction) {
123
- hook = await loadInitializeContextHook(importFunction);
137
+ async function getPlaywrightConstructsForMode(mode, cdpAddress, authSession, hookOptions) {
138
+ let context = null;
139
+ let page = null;
140
+ if (hookOptions && cdpAddress) {
141
+ const hook = await loadInitializeContextHook(hookOptions.importFunction);
142
+ if (hook) {
143
+ const hookResult = await hook({
144
+ cdpAddress,
145
+ apiName: hookOptions.apiName,
146
+ apiParameters: hookOptions.parameters
147
+ });
148
+ if (hookResult !== null) {
149
+ ({
150
+ page,
151
+ context
152
+ } = hookResult);
153
+ const {
154
+ hookVars
155
+ } = hookResult;
156
+ const executionContext = (0, _asyncLocalStorage.getExecutionContext)();
157
+ if (hookVars && executionContext) {
158
+ executionContext.hookVars = hookVars;
159
+ }
160
+ }
161
+ }
124
162
  }
125
163
  if (mode == "playwright-standalone") {
126
164
  if (!cdpAddress) {
127
165
  throw new Error("cdpAddress is required");
128
166
  }
129
- let context;
130
- let page = null;
131
- if (hook) {
132
- ({
133
- context,
134
- page
135
- } = await hook({
136
- type: "cdp",
137
- cdpAddress
138
- }));
139
- } else {
167
+ if (!context) {
140
168
  ({
141
169
  context
142
170
  } = await getRemotePlaywrightContext(cdpAddress));
@@ -129,7 +129,11 @@ async function* runApiGenerator({
129
129
  proxy,
130
130
  downloadsPath,
131
131
  storageState: auth?.session,
132
- importFunction
132
+ hookOptions: {
133
+ apiName: automationFunction.name,
134
+ parameters: automationFunction.params,
135
+ importFunction
136
+ }
133
137
  }));
134
138
  } else {
135
139
  const {
@@ -139,7 +143,11 @@ async function* runApiGenerator({
139
143
  ({
140
144
  page,
141
145
  context
142
- } = await (0, _getPlaywrightConstructs.getPlaywrightConstructsForMode)(mode, cdpAddress, auth?.session, importFunction));
146
+ } = await (0, _getPlaywrightConstructs.getPlaywrightConstructsForMode)(mode, cdpAddress, auth?.session, {
147
+ apiName: automationFunction.name,
148
+ parameters: automationFunction.params,
149
+ importFunction
150
+ }));
143
151
  }
144
152
  if (tracing.enabled) {
145
153
  await context.tracing.start({
@@ -687,13 +687,13 @@ export declare const runApiParametersSchema: z.ZodObject<{
687
687
  cdpAddress: z.ZodString;
688
688
  mode: z.ZodUnion<[z.ZodLiteral<"vanilla">, z.ZodLiteral<"playwright">, z.ZodLiteral<"playwright-standalone">, z.ZodLiteral<"playwright-headless">]>;
689
689
  }, "strip", z.ZodTypeAny, {
690
- cdpAddress: string;
691
690
  mode: "vanilla" | "playwright" | "playwright-standalone" | "playwright-headless";
692
691
  environment: "cdp";
693
- }, {
694
692
  cdpAddress: string;
693
+ }, {
695
694
  mode: "vanilla" | "playwright" | "playwright-standalone" | "playwright-headless";
696
695
  environment: "cdp";
696
+ cdpAddress: string;
697
697
  }>]>>;
698
698
  retrieveSession: z.ZodDefault<z.ZodBoolean>;
699
699
  }, "strip", z.ZodTypeAny, {
@@ -716,9 +716,9 @@ export declare const runApiParametersSchema: z.ZodObject<{
716
716
  password: string;
717
717
  } | undefined;
718
718
  } | {
719
- cdpAddress: string;
720
719
  mode: "vanilla" | "playwright" | "playwright-standalone" | "playwright-headless";
721
720
  environment: "cdp";
721
+ cdpAddress: string;
722
722
  };
723
723
  retrieveSession: boolean;
724
724
  auth?: {
@@ -811,9 +811,9 @@ export declare const runApiParametersSchema: z.ZodObject<{
811
811
  password: string;
812
812
  } | undefined;
813
813
  } | {
814
- cdpAddress: string;
815
814
  mode: "vanilla" | "playwright" | "playwright-standalone" | "playwright-headless";
816
815
  environment: "cdp";
816
+ cdpAddress: string;
817
817
  } | undefined;
818
818
  retrieveSession?: boolean | undefined;
819
819
  }>;
@@ -6,4 +6,3 @@ export { RunError } from "./RunError";
6
6
  export { requestMultipleChoice, requestOTP } from "./requestMoreInfo";
7
7
  export type { RequestMoreInfoDetails } from "./requestMoreInfo";
8
8
  export { getDownloadDirectoryPath } from "./downloadDirectory";
9
- export { getCdpAddress } from "./getCdpAddress";
@@ -27,12 +27,6 @@ Object.defineProperty(exports, "getAuthSessionParameters", {
27
27
  return _getAuthSessionParameters.getAuthSessionParameters;
28
28
  }
29
29
  });
30
- Object.defineProperty(exports, "getCdpAddress", {
31
- enumerable: true,
32
- get: function () {
33
- return _getCdpAddress.getCdpAddress;
34
- }
35
- });
36
30
  Object.defineProperty(exports, "getDownloadDirectoryPath", {
37
31
  enumerable: true,
38
32
  get: function () {
@@ -63,5 +57,4 @@ var _getAuthSessionParameters = require("./getAuthSessionParameters");
63
57
  var _runInfo = require("./runInfo");
64
58
  var _RunError = require("./RunError");
65
59
  var _requestMoreInfo = require("./requestMoreInfo");
66
- var _downloadDirectory = require("./downloadDirectory");
67
- var _getCdpAddress = require("./getCdpAddress");
60
+ var _downloadDirectory = require("./downloadDirectory");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intuned/runtime-dev",
3
- "version": "1.2.1-hooks.2",
3
+ "version": "1.2.1-hooks.4",
4
4
  "description": "Intuned runtime",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",
@@ -1 +0,0 @@
1
- export declare function getCdpAddress(): string | undefined;
@@ -1,11 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getCdpAddress = getCdpAddress;
7
- var _asyncLocalStorage = require("../common/asyncLocalStorage");
8
- function getCdpAddress() {
9
- const context = (0, _asyncLocalStorage.getExecutionContext)();
10
- return context?.cdpAddress;
11
- }