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

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,9 @@ 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 _getPort = _interopRequireDefault(require("get-port"));
20
+ var _promises = require("timers/promises");
18
21
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
19
22
  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
23
  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 +56,63 @@ async function getProductionPlaywrightConstructs({
53
56
  headless = true,
54
57
  storageState,
55
58
  downloadsPath,
56
- importFunction
59
+ hookOptions
57
60
  }) {
58
- let context;
59
- let page;
61
+ const extraArgs = [];
62
+ const port = await (0, _getPort.default)();
60
63
  let hook = null;
61
- if (importFunction) {
62
- hook = await loadInitializeContextHook(importFunction);
64
+ if (hookOptions) {
65
+ hook = await loadInitializeContextHook(hookOptions.importFunction);
63
66
  }
67
+ const userDataDir = await createUserDirWithPreferences();
64
68
  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");
69
+ extraArgs.push(`--remote-debugging-port=${port}`);
70
+ }
71
+ const originalContext = await playwright.chromium.launchPersistentContext(userDataDir, {
72
+ headless,
73
+ viewport: null,
74
+ proxy,
75
+ downloadsPath,
76
+ args: extraArgs
77
+ });
78
+ const cdpAddress = `http://localhost:${port}`;
79
+ await (0, _promises.setTimeout)(3000);
80
+ originalContext.once("close", async () => {
81
+ try {
82
+ await (0, _fsExtra.rm)(userDataDir, {
83
+ recursive: true,
84
+ force: true,
85
+ retryDelay: 1000,
86
+ maxRetries: 5
87
+ });
88
+ } catch (error) {
89
+ console.error("Failed to remove user data dir", error);
77
90
  }
78
- const userDataDir = await createUserDirWithPreferences();
79
- context = await playwright.chromium.launchPersistentContext(userDataDir, {
80
- headless,
81
- viewport: null,
82
- proxy,
83
- downloadsPath
91
+ });
92
+ let page = originalContext.pages().at(0) ?? null;
93
+ let context = originalContext;
94
+ if (hookOptions && hook) {
95
+ const hookResult = await hook({
96
+ apiName: hookOptions.apiName,
97
+ apiParameters: hookOptions.parameters,
98
+ cdpAddress
84
99
  });
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);
100
+ if (hookResult !== null) {
101
+ ({
102
+ page,
103
+ context: context
104
+ } = hookResult);
105
+ const {
106
+ hookVars
107
+ } = hookResult;
108
+ const executionContext = (0, _asyncLocalStorage.getExecutionContext)();
109
+ if (hookVars && executionContext) {
110
+ executionContext.hookVars = hookVars;
95
111
  }
96
- });
97
- page = context.pages().at(0) ?? null;
112
+ context.once("close", async () => {
113
+ await originalContext.close();
114
+ });
115
+ }
98
116
  }
99
117
  if (storageState) {
100
118
  await loadSessionToContext({
@@ -117,26 +135,37 @@ async function getProductionPlaywrightConstructs({
117
135
  context
118
136
  };
119
137
  }
120
- async function getPlaywrightConstructsForMode(mode, cdpAddress, authSession, importFunction) {
121
- let hook = null;
122
- if (importFunction) {
123
- hook = await loadInitializeContextHook(importFunction);
138
+ async function getPlaywrightConstructsForMode(mode, cdpAddress, authSession, hookOptions) {
139
+ let context = null;
140
+ let page = null;
141
+ if (hookOptions && cdpAddress) {
142
+ const hook = await loadInitializeContextHook(hookOptions.importFunction);
143
+ if (hook) {
144
+ const hookResult = await hook({
145
+ cdpAddress,
146
+ apiName: hookOptions.apiName,
147
+ apiParameters: hookOptions.parameters
148
+ });
149
+ if (hookResult !== null) {
150
+ ({
151
+ page,
152
+ context
153
+ } = hookResult);
154
+ const {
155
+ hookVars
156
+ } = hookResult;
157
+ const executionContext = (0, _asyncLocalStorage.getExecutionContext)();
158
+ if (hookVars && executionContext) {
159
+ executionContext.hookVars = hookVars;
160
+ }
161
+ }
162
+ }
124
163
  }
125
164
  if (mode == "playwright-standalone") {
126
165
  if (!cdpAddress) {
127
166
  throw new Error("cdpAddress is required");
128
167
  }
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 {
168
+ if (!context) {
140
169
  ({
141
170
  context
142
171
  } = 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.3",
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
- }