@intuned/runtime-dev 1.2.1-hooks.0 → 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 -232
  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,232 +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 loadGetDeployedPageAndContextHook(importFunction) {
37
- const result = await importFunction("hooks/createDeployedContextAndPage");
38
- if (result.isErr()) {
39
- throw result.error;
40
- }
41
- return result.value.default;
42
- }
43
- async function getProductionPlaywrightConstructs({
44
- proxy,
45
- headless = true,
46
- storageState,
47
- downloadsPath,
48
- importFunction
49
- }) {
50
- let context;
51
- let page;
52
- let hook = null;
53
- if (importFunction) {
54
- hook = await loadGetDeployedPageAndContextHook(importFunction);
55
- }
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");
68
- }
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
- }
90
- if (storageState) {
91
- await loadSessionToContext({
92
- context,
93
- session: storageState
94
- });
95
- }
96
- const assetsFile = _path.default.join(__dirname, "./assets/browser_scripts.js");
97
- await context.addInitScript({
98
- path: assetsFile
99
- });
100
- if (page) {
101
- const scriptString = await (0, _fsExtra.readFile)(assetsFile, "utf8");
102
- await page.evaluate(scriptString);
103
- } else {
104
- page = await context.newPage();
105
- }
106
- return {
107
- page,
108
- context
109
- };
110
- }
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
- }
123
- if (mode == "playwright-standalone") {
124
- if (!cdpAddress) {
125
- throw new Error("cdpAddress is required");
126
- }
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
- }
139
- if (!context) {
140
- throw new Error("no context found");
141
- }
142
- const assetsFile = _path.default.join(__dirname, "./assets/browser_scripts.js");
143
- await context.addInitScript({
144
- path: assetsFile
145
- });
146
- const pages = await context.pages();
147
- let page = null;
148
- if (pages.length > 0) {
149
- page = pages[0];
150
- const scriptString = await fs.readFile(assetsFile, "utf8");
151
- await page.evaluate(scriptString);
152
- } else {
153
- page = await context.newPage();
154
- }
155
- if (authSession) {
156
- await loadSessionToContext({
157
- context,
158
- session: authSession
159
- });
160
- }
161
- return {
162
- page,
163
- context
164
- };
165
- }
166
- const downloadsPath = (0, _runtime.getDownloadDirectoryPath)();
167
- if (mode === "playwright" || mode === "playwright-headless") {
168
- const productionConstructs = await getProductionPlaywrightConstructs({
169
- headless: mode === "playwright-headless",
170
- downloadsPath
171
- });
172
- if (authSession) {
173
- await loadSessionToContext({
174
- context: productionConstructs.context,
175
- session: authSession
176
- });
177
- }
178
- return {
179
- ...productionConstructs
180
- };
181
- }
182
- throw "invalid mode";
183
- }
184
- async function loadSessionToContext({
185
- context,
186
- session
187
- }) {
188
- let sessionToLoad;
189
- if (session.type === "state") {
190
- const state = session.state;
191
- if (state === undefined || state === null) {
192
- return;
193
- }
194
- sessionToLoad = state;
195
- } else {
196
- const fullPath = (0, _fileUtils.getFullPathInProject)(session.path);
197
- sessionToLoad = await fs.readJson(fullPath);
198
- }
199
- await (0, _contextStorageStateHelpers.setStorageState)(context, sessionToLoad);
200
- }
201
- async function getRemotePlaywrightContext(cdpAddress) {
202
- const playwright = await Promise.resolve().then(() => _interopRequireWildcard(require("playwright")));
203
- let browser = null;
204
- if (!cdpAddress) {
205
- throw new Error("cdpAddress is required");
206
- }
207
- const cdpAddressWithoutProtocol = cdpAddress.replace("http://", "").replace("https://", "").replace("localhost", "127.0.0.1");
208
- try {
209
- await (0, _waitOn.default)({
210
- resources: [`http-get://${cdpAddressWithoutProtocol}/json/version`],
211
- delay: 100,
212
- interval: 100,
213
- timeout: 5000,
214
- tcpTimeout: 1000,
215
- window: 1000
216
- });
217
- } catch (error) {
218
- console.error("Failed to connect to the browser");
219
- process.exit(128 + 9);
220
- }
221
- try {
222
- browser = await playwright.chromium.connectOverCDP(cdpAddress);
223
- } catch (e) {
224
- console.log(e);
225
- throw new Error("failed to connect to the browser");
226
- }
227
- const context = browser.contexts()[0];
228
- return {
229
- browser,
230
- context
231
- };
232
- }
@@ -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
- }