@intuned/runtime-dev 1.2.1-hooks.1 → 1.2.1-hooks.10

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 (38) hide show
  1. package/dist/commands/api/run.js +1 -2
  2. package/dist/commands/auth-sessions/load.js +3 -3
  3. package/dist/commands/auth-sessions/run-check.js +1 -2
  4. package/dist/commands/auth-sessions/run-create.js +12 -35
  5. package/dist/commands/interface/run.d.ts +1 -1
  6. package/dist/commands/interface/run.js +14 -40
  7. package/dist/commands/intuned-cli/controller/api.js +1 -2
  8. package/dist/commands/intuned-cli/controller/authSession.d.ts +6 -6
  9. package/dist/commands/intuned-cli/controller/authSession.js +3 -4
  10. package/dist/commands/intuned-cli/helpers/auth.d.ts +1 -1
  11. package/dist/commands/intuned-cli/helpers/errors.d.ts +2 -2
  12. package/dist/commands/intuned-cli/helpers/errors.js +8 -4
  13. package/dist/common/asyncLocalStorage/index.d.ts +1 -1
  14. package/dist/common/initializeContextHook.d.ts +16 -0
  15. package/dist/common/initializeContextHook.js +15 -0
  16. package/dist/common/playwrightContext.d.ts +49 -0
  17. package/dist/common/playwrightContext.js +240 -0
  18. package/dist/common/runApi/importUsingImportFunction.d.ts +9 -0
  19. package/dist/common/runApi/importUsingImportFunction.js +46 -0
  20. package/dist/common/runApi/index.d.ts +2 -7
  21. package/dist/common/runApi/index.js +87 -174
  22. package/dist/common/runApi/types.d.ts +25 -29
  23. package/dist/common/runApi/types.js +1 -2
  24. package/dist/index.d.ts +1 -2
  25. package/dist/index.js +7 -20
  26. package/dist/runtime/export.d.ts +49 -43
  27. package/dist/runtime/index.d.ts +1 -3
  28. package/dist/runtime/index.js +6 -19
  29. package/dist/runtime/store.d.ts +2 -0
  30. package/dist/runtime/store.js +23 -0
  31. package/package.json +2 -2
  32. package/.npmrc.wtf +0 -1
  33. package/dist/common/getPlaywrightConstructs.d.ts +0 -31
  34. package/dist/common/getPlaywrightConstructs.js +0 -234
  35. package/dist/runtime/getCdpAddress.d.ts +0 -1
  36. package/dist/runtime/getCdpAddress.js +0 -11
  37. package/dist/runtime/requestMoreInfo.d.ts +0 -18
  38. package/dist/runtime/requestMoreInfo.js +0 -25
@@ -1,234 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getPlaywrightConstructsForMode = getPlaywrightConstructsForMode;
7
- exports.getProductionPlaywrightConstructs = getProductionPlaywrightConstructs;
8
- exports.getRemotePlaywrightContext = getRemotePlaywrightContext;
9
- exports.loadSessionToContext = loadSessionToContext;
10
- var playwright = _interopRequireWildcard(require("playwright"));
11
- var _fsExtra = _interopRequireWildcard(require("fs-extra"));
12
- var fs = _fsExtra;
13
- var _contextStorageStateHelpers = require("./contextStorageStateHelpers");
14
- var _path = _interopRequireWildcard(require("path"));
15
- var _fileUtils = require("../commands/common/utils/fileUtils");
16
- var _waitOn = _interopRequireDefault(require("wait-on"));
17
- var _runtime = require("../runtime");
18
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
19
- 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
- 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; }
21
- async function createUserDirWithPreferences() {
22
- const playwrightTempDir = await (0, _fsExtra.mkdtemp)("/tmp/pw-");
23
- const userDir = (0, _path.join)(playwrightTempDir, "userdir");
24
- const defaultDir = (0, _path.join)(userDir, "Default");
25
- await (0, _fsExtra.mkdir)(defaultDir, {
26
- recursive: true
27
- });
28
- const preferences = {
29
- plugins: {
30
- always_open_pdf_externally: true
31
- }
32
- };
33
- await (0, _fsExtra.writeFile)((0, _path.join)(defaultDir, "Preferences"), JSON.stringify(preferences));
34
- return userDir;
35
- }
36
- async function loadInitializeContextHook(importFunction) {
37
- const result = await importFunction("hooks/initializeContext");
38
- if (result.isErr()) {
39
- if (result.error.type === "not_found") {
40
- return null;
41
- }
42
- console.error("Error loading initializeBrowser hook");
43
- throw result.error.error;
44
- }
45
- return result.value.default;
46
- }
47
- async function getProductionPlaywrightConstructs({
48
- proxy,
49
- headless = true,
50
- storageState,
51
- downloadsPath,
52
- importFunction
53
- }) {
54
- let context;
55
- let page;
56
- let hook = null;
57
- if (importFunction) {
58
- hook = await loadInitializeContextHook(importFunction);
59
- }
60
- if (hook) {
61
- ({
62
- page,
63
- context
64
- } = await hook({
65
- type: "launch",
66
- proxy,
67
- headless
68
- }));
69
- } else {
70
- const extraArgs = ["--no-first-run", "--disable-sync", "--disable-translate", "--disable-features=TranslateUI", "--disable-features=NetworkService", "--lang=en"];
71
- if (headless) {
72
- extraArgs.push("--headless=new");
73
- }
74
- const userDataDir = await createUserDirWithPreferences();
75
- context = await playwright.chromium.launchPersistentContext(userDataDir, {
76
- headless,
77
- viewport: null,
78
- proxy,
79
- downloadsPath
80
- });
81
- context.once("close", async () => {
82
- try {
83
- await (0, _fsExtra.rm)(userDataDir, {
84
- recursive: true,
85
- force: true,
86
- retryDelay: 1000,
87
- maxRetries: 5
88
- });
89
- } catch (error) {
90
- console.error("Failed to remove user data dir", error);
91
- }
92
- });
93
- page = context.pages().at(0) ?? null;
94
- }
95
- if (storageState) {
96
- await loadSessionToContext({
97
- context,
98
- session: storageState
99
- });
100
- }
101
- const assetsFile = _path.default.join(__dirname, "./assets/browser_scripts.js");
102
- await context.addInitScript({
103
- path: assetsFile
104
- });
105
- if (page) {
106
- const scriptString = await (0, _fsExtra.readFile)(assetsFile, "utf8");
107
- await page.evaluate(scriptString);
108
- } else {
109
- page = await context.newPage();
110
- }
111
- return {
112
- page,
113
- context
114
- };
115
- }
116
- async function getPlaywrightConstructsForMode(mode, cdpAddress, authSession, importFunction) {
117
- let hook = null;
118
- if (importFunction) {
119
- hook = await loadInitializeContextHook(importFunction);
120
- }
121
- if (mode == "playwright-standalone") {
122
- if (!cdpAddress) {
123
- throw new Error("cdpAddress is required");
124
- }
125
- let context;
126
- let page = null;
127
- if (hook) {
128
- ({
129
- context,
130
- page
131
- } = await hook({
132
- type: "cdp",
133
- cdpAddress
134
- }));
135
- } else {
136
- ({
137
- context
138
- } = await getRemotePlaywrightContext(cdpAddress));
139
- }
140
- if (!context) {
141
- throw new Error("no context found");
142
- }
143
- const assetsFile = _path.default.join(__dirname, "./assets/browser_scripts.js");
144
- await context.addInitScript({
145
- path: assetsFile
146
- });
147
- const pages = context.pages();
148
- if (!page) {
149
- if (pages.length > 0) {
150
- page = pages[0];
151
- const scriptString = await fs.readFile(assetsFile, "utf8");
152
- await page.evaluate(scriptString);
153
- } else {
154
- page = await context.newPage();
155
- }
156
- }
157
- if (authSession) {
158
- await loadSessionToContext({
159
- context,
160
- session: authSession
161
- });
162
- }
163
- return {
164
- page,
165
- context
166
- };
167
- }
168
- const downloadsPath = (0, _runtime.getDownloadDirectoryPath)();
169
- if (mode === "playwright" || mode === "playwright-headless") {
170
- const productionConstructs = await getProductionPlaywrightConstructs({
171
- headless: mode === "playwright-headless",
172
- downloadsPath
173
- });
174
- if (authSession) {
175
- await loadSessionToContext({
176
- context: productionConstructs.context,
177
- session: authSession
178
- });
179
- }
180
- return {
181
- ...productionConstructs
182
- };
183
- }
184
- throw "invalid mode";
185
- }
186
- async function loadSessionToContext({
187
- context,
188
- session
189
- }) {
190
- let sessionToLoad;
191
- if (session.type === "state") {
192
- const state = session.state;
193
- if (state === undefined || state === null) {
194
- return;
195
- }
196
- sessionToLoad = state;
197
- } else {
198
- const fullPath = (0, _fileUtils.getFullPathInProject)(session.path);
199
- sessionToLoad = await fs.readJson(fullPath);
200
- }
201
- await (0, _contextStorageStateHelpers.setStorageState)(context, sessionToLoad);
202
- }
203
- async function getRemotePlaywrightContext(cdpAddress) {
204
- const playwright = await Promise.resolve().then(() => _interopRequireWildcard(require("playwright")));
205
- let browser = null;
206
- if (!cdpAddress) {
207
- throw new Error("cdpAddress is required");
208
- }
209
- const cdpAddressWithoutProtocol = cdpAddress.replace("http://", "").replace("https://", "").replace("localhost", "127.0.0.1");
210
- try {
211
- await (0, _waitOn.default)({
212
- resources: [`http-get://${cdpAddressWithoutProtocol}/json/version`],
213
- delay: 100,
214
- interval: 100,
215
- timeout: 5000,
216
- tcpTimeout: 1000,
217
- window: 1000
218
- });
219
- } catch (error) {
220
- console.error("Failed to connect to the browser");
221
- process.exit(128 + 9);
222
- }
223
- try {
224
- browser = await playwright.chromium.connectOverCDP(cdpAddress);
225
- } catch (e) {
226
- console.log(e);
227
- throw new Error("failed to connect to the browser");
228
- }
229
- const context = browser.contexts()[0];
230
- return {
231
- browser,
232
- context
233
- };
234
- }
@@ -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
- }
@@ -1,18 +0,0 @@
1
- interface RequestMoreInfoReturnTypeBase {
2
- [REQUEST_MORE_INFO_KEY]: true;
3
- action: "request_more_info";
4
- }
5
- interface RequestMultipleChoiceReturnType extends RequestMoreInfoReturnTypeBase {
6
- messageToUser: string;
7
- choices: string[];
8
- requestType: "multiple_choice";
9
- }
10
- interface RequestOtpReturnType extends RequestMoreInfoReturnTypeBase {
11
- messageToUser: string;
12
- requestType: "otp";
13
- }
14
- declare const REQUEST_MORE_INFO_KEY: unique symbol;
15
- export declare function requestOTP(messageToUser: string): RequestOtpReturnType;
16
- export declare function requestMultipleChoice(messageToUser: string, choices: string[]): RequestMultipleChoiceReturnType;
17
- export type RequestMoreInfoDetails = RequestMultipleChoiceReturnType | RequestOtpReturnType;
18
- export {};
@@ -1,25 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.requestMultipleChoice = requestMultipleChoice;
7
- exports.requestOTP = requestOTP;
8
- const REQUEST_MORE_INFO_KEY = Symbol("REQUEST_MORE_INFO");
9
- function requestOTP(messageToUser) {
10
- return {
11
- [REQUEST_MORE_INFO_KEY]: true,
12
- action: "request_more_info",
13
- messageToUser,
14
- requestType: "otp"
15
- };
16
- }
17
- function requestMultipleChoice(messageToUser, choices) {
18
- return {
19
- [REQUEST_MORE_INFO_KEY]: true,
20
- action: "request_more_info",
21
- messageToUser,
22
- requestType: "multiple_choice",
23
- choices
24
- };
25
- }