@intuned/runtime-dev 1.3.14-ts-runtime-helpers-1 → 1.3.15-ts-helpers
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.
- package/dist/commands/intuned-cli/helpers/intunedJson.d.ts +1 -1
- package/dist/common/constants.d.ts +0 -2
- package/dist/common/constants.js +2 -4
- package/dist/common/extension/extensionsHelpers.js +2 -17
- package/dist/common/extension/intunedExtensionServer.d.ts +3 -1
- package/dist/common/extension/intunedExtensionServer.js +36 -19
- package/dist/common/extension/types.d.ts +206 -15
- package/dist/common/extension/types.js +47 -1
- package/dist/common/intunedJson.d.ts +6 -6
- package/dist/common/runApi/index.js +0 -6
- package/dist/index.d.ts +1 -1
- package/dist/index.js +6 -0
- package/dist/runtime/captcha.d.ts +4 -7
- package/dist/runtime/captcha.js +14 -27
- package/dist/runtime/captcha.test.js +662 -55
- package/dist/runtime/getAiGatewayConfig.d.ts +10 -0
- package/dist/runtime/getAiGatewayConfig.js +16 -0
- package/dist/runtime/index.d.ts +1 -0
- package/dist/runtime/index.js +7 -0
- package/package.json +3 -3
package/dist/runtime/captcha.js
CHANGED
|
@@ -12,13 +12,14 @@ exports.waitForCaptchaSolve = waitForCaptchaSolve;
|
|
|
12
12
|
exports.withWaitForCaptchaSolve = withWaitForCaptchaSolve;
|
|
13
13
|
var _intunedExtensionServer = require("../common/extension/intunedExtensionServer");
|
|
14
14
|
var _extensionsHelpers = require("../common/extension/extensionsHelpers");
|
|
15
|
+
var _types = require("../common/extension/types");
|
|
15
16
|
async function withWaitForCaptchaSolve(callback, options) {
|
|
16
17
|
const {
|
|
17
18
|
page,
|
|
18
19
|
timeoutInMs = 10_000,
|
|
19
20
|
settleDurationMs = 5_000,
|
|
20
21
|
waitForNetworkSettled = true
|
|
21
|
-
} = options
|
|
22
|
+
} = options;
|
|
22
23
|
const extensionServer = (0, _intunedExtensionServer.getIntunedExtensionServer)();
|
|
23
24
|
let settledResolve = null;
|
|
24
25
|
let settledPromise = new Promise(resolve => {
|
|
@@ -26,8 +27,7 @@ async function withWaitForCaptchaSolve(callback, options) {
|
|
|
26
27
|
});
|
|
27
28
|
let isTimeout = false;
|
|
28
29
|
let captchasAppeared = false;
|
|
29
|
-
let
|
|
30
|
-
let errorMessage = "";
|
|
30
|
+
let error = undefined;
|
|
31
31
|
let actionDone = false;
|
|
32
32
|
const getPendingCaptchas = async () => await extensionServer.getCaptchas(page, "solving");
|
|
33
33
|
const hasNoPendingCaptchas = async () => !captchasAppeared || (await getPendingCaptchas()).length === 0;
|
|
@@ -43,9 +43,7 @@ async function withWaitForCaptchaSolve(callback, options) {
|
|
|
43
43
|
captchasAppeared = true;
|
|
44
44
|
}
|
|
45
45
|
if (errorCaptchas.length > 0) {
|
|
46
|
-
|
|
47
|
-
const err = errorCaptchas[0].error;
|
|
48
|
-
errorMessage = err?.code ?? "Unknown error during CAPTCHA solving.";
|
|
46
|
+
error = errorCaptchas[0].error;
|
|
49
47
|
await maybeSettle();
|
|
50
48
|
return;
|
|
51
49
|
}
|
|
@@ -66,31 +64,27 @@ async function withWaitForCaptchaSolve(callback, options) {
|
|
|
66
64
|
if (initialPending.length > 0) {
|
|
67
65
|
captchasAppeared = true;
|
|
68
66
|
}
|
|
69
|
-
const initialErrors = await extensionServer.getCaptchas(page, "error");
|
|
70
|
-
if (initialErrors.length > 0) {
|
|
71
|
-
hasError = true;
|
|
72
|
-
const err = initialErrors[0].error;
|
|
73
|
-
errorMessage = err?.code ?? "Unknown error during CAPTCHA solving.";
|
|
74
|
-
}
|
|
75
67
|
const result = await callback(page);
|
|
76
68
|
actionDone = true;
|
|
77
69
|
if (waitForNetworkSettled) {
|
|
78
70
|
try {
|
|
79
71
|
await page.waitForLoadState("networkidle");
|
|
80
|
-
} catch (
|
|
72
|
+
} catch (err) {
|
|
73
|
+
console.error(`Failed to wait for networkidle. Error: ${err}`);
|
|
74
|
+
}
|
|
81
75
|
}
|
|
82
76
|
await maybeSettle();
|
|
83
77
|
let shouldContinue = true;
|
|
84
78
|
while (shouldContinue) {
|
|
85
79
|
await Promise.race([settledPromise, timeoutPromise]);
|
|
86
80
|
await new Promise(r => setTimeout(r, settleDurationMs));
|
|
87
|
-
if (
|
|
88
|
-
throw new
|
|
81
|
+
if (error) {
|
|
82
|
+
throw new _types.CaptchaSolveError(`CAPTCHA Solve Error: ${error.code}`, error);
|
|
89
83
|
}
|
|
90
84
|
const noPendingCaptchas = await hasNoPendingCaptchas();
|
|
91
85
|
if (actionDone && noPendingCaptchas || isTimeout) {
|
|
92
86
|
if (isTimeout && !noPendingCaptchas) {
|
|
93
|
-
throw new
|
|
87
|
+
throw new _types.TimeoutError("CAPTCHA Solve timed out with pending captchas.");
|
|
94
88
|
}
|
|
95
89
|
shouldContinue = false;
|
|
96
90
|
} else {
|
|
@@ -106,12 +100,12 @@ async function withWaitForCaptchaSolve(callback, options) {
|
|
|
106
100
|
}
|
|
107
101
|
async function waitForCaptchaSolve(page, {
|
|
108
102
|
timeoutInMs = 10_000,
|
|
109
|
-
|
|
103
|
+
settleDurationMs = 5_000
|
|
110
104
|
} = {}) {
|
|
111
105
|
await withWaitForCaptchaSolve(async () => undefined, {
|
|
112
106
|
page,
|
|
113
107
|
timeoutInMs,
|
|
114
|
-
settleDurationMs
|
|
108
|
+
settleDurationMs,
|
|
115
109
|
waitForNetworkSettled: false
|
|
116
110
|
});
|
|
117
111
|
}
|
|
@@ -121,19 +115,12 @@ async function removeCaptchaEventListener(page, status, f) {
|
|
|
121
115
|
}
|
|
122
116
|
async function onCaptchaEvent(page, status, f) {
|
|
123
117
|
const extensionServer = (0, _intunedExtensionServer.getIntunedExtensionServer)();
|
|
124
|
-
|
|
125
|
-
if (captcha.status === status) {
|
|
126
|
-
await f(captcha);
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
await extensionServer.subscribe(page, wrapper, status);
|
|
118
|
+
await extensionServer.subscribe(page, f, status);
|
|
130
119
|
}
|
|
131
120
|
async function onceCaptchaEvent(page, status, f) {
|
|
132
121
|
const extensionServer = (0, _intunedExtensionServer.getIntunedExtensionServer)();
|
|
133
122
|
const oneTimeHandler = async captcha => {
|
|
134
|
-
|
|
135
|
-
await extensionServer.unsubscribe(page, oneTimeHandler, status);
|
|
136
|
-
}
|
|
123
|
+
await extensionServer.unsubscribe(page, oneTimeHandler, status);
|
|
137
124
|
await f(captcha);
|
|
138
125
|
};
|
|
139
126
|
await extensionServer.subscribe(page, oneTimeHandler, status);
|