@intuned/runtime-dev 1.3.13-kv.1 → 1.3.14-ts-runtime-helpers-1
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/bin/intuned-get-headless-user-agent +4 -0
- package/dist/commands/get-headless-user-agent.d.ts +1 -0
- package/dist/commands/get-headless-user-agent.js +18 -0
- package/dist/commands/intuned-cli/commands/run_authsession.command.d.ts +6 -6
- package/dist/commands/intuned-cli/commands/types.d.ts +2 -2
- package/dist/commands/intuned-cli/controller/authSession.d.ts +6 -6
- package/dist/commands/intuned-cli/helpers/auth.d.ts +1 -1
- package/dist/commands/intuned-cli/helpers/errors.d.ts +1 -1
- package/dist/commands/intuned-cli/helpers/errors.js +2 -2
- package/dist/commands/intuned-cli/helpers/intunedJson.d.ts +8 -140
- package/dist/commands/intuned-cli/helpers/intunedJson.js +12 -79
- package/dist/common/binStartupScript.js +8 -5
- package/dist/common/constants.d.ts +2 -0
- package/dist/common/constants.js +4 -2
- package/dist/common/{extensionsHelpers.d.ts → extension/extensionsHelpers.d.ts} +1 -1
- package/dist/common/{extensionsHelpers.js → extension/extensionsHelpers.js} +62 -6
- package/dist/common/extension/intunedExtensionServer.d.ts +25 -0
- package/dist/common/extension/intunedExtensionServer.js +164 -0
- package/dist/common/extension/types.d.ts +21 -0
- package/dist/common/extension/types.js +5 -0
- package/dist/common/intunedJson.d.ts +229 -0
- package/dist/common/intunedJson.js +133 -0
- package/dist/common/launchBrowser.d.ts +6 -0
- package/dist/common/launchBrowser.js +42 -17
- package/dist/common/runApi/index.js +6 -0
- package/dist/common/runApi/types.d.ts +20 -20
- package/dist/common/settingsSchema.d.ts +15 -1
- package/dist/common/settingsSchema.js +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +44 -1
- package/dist/runtime/captcha.d.ts +18 -0
- package/dist/runtime/captcha.js +190 -0
- package/dist/runtime/captcha.test.js +214 -0
- package/dist/runtime/index.d.ts +1 -0
- package/dist/runtime/index.js +43 -0
- package/dist/runtime/persistentStore.test.js +101 -0
- package/package.json +6 -3
- package/WebTemplate.zip +0 -0
|
@@ -44,6 +44,7 @@ Object.keys(_types).forEach(function (key) {
|
|
|
44
44
|
var _formatZodError = require("../formatZodError");
|
|
45
45
|
var _cleanEnvironmentVariables = require("../cleanEnvironmentVariables");
|
|
46
46
|
var _importUsingImportFunction = require("./importUsingImportFunction");
|
|
47
|
+
var _jwtTokenManager = require("../jwtTokenManager");
|
|
47
48
|
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); }
|
|
48
49
|
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; }
|
|
49
50
|
function getObjectSizeInBytes(obj) {
|
|
@@ -53,6 +54,10 @@ function getObjectSizeInBytes(obj) {
|
|
|
53
54
|
return new TextEncoder().encode(String(obj)).length;
|
|
54
55
|
}
|
|
55
56
|
}
|
|
57
|
+
function injectRuntimeEnvVars() {
|
|
58
|
+
process.env[_constants.INTUNED_AI_GATEWAY_BASE_URL_ENV_VAR] = `${_jwtTokenManager.backendFunctionsTokenManager.backendFunctionsBaseUrl}/intuned-ai-gateway`;
|
|
59
|
+
process.env[_constants.INTUNED_AI_GATEWAY_API_KEY_ENV_VAR] = _jwtTokenManager.backendFunctionsTokenManager.token ?? process.env[_constants.API_KEY_ENV_VAR_KEY];
|
|
60
|
+
}
|
|
56
61
|
async function runApi({
|
|
57
62
|
abortSignal,
|
|
58
63
|
importFunction,
|
|
@@ -80,6 +85,7 @@ async function runApi({
|
|
|
80
85
|
resolve(abortSymbol);
|
|
81
86
|
});
|
|
82
87
|
});
|
|
88
|
+
injectRuntimeEnvVars();
|
|
83
89
|
async function runAutomation() {
|
|
84
90
|
const validatedModuleResult = await (0, _importUsingImportFunction.importUsingImportFunction)({
|
|
85
91
|
path: name,
|
|
@@ -38,8 +38,8 @@ export declare const runApiStorageStateSchema: z.ZodObject<{
|
|
|
38
38
|
}, "strip", z.ZodTypeAny, {
|
|
39
39
|
path: string;
|
|
40
40
|
value: string;
|
|
41
|
-
name: string;
|
|
42
41
|
domain: string;
|
|
42
|
+
name: string;
|
|
43
43
|
expires: number;
|
|
44
44
|
httpOnly: boolean;
|
|
45
45
|
secure: boolean;
|
|
@@ -47,8 +47,8 @@ export declare const runApiStorageStateSchema: z.ZodObject<{
|
|
|
47
47
|
}, {
|
|
48
48
|
path: string;
|
|
49
49
|
value: string;
|
|
50
|
-
name: string;
|
|
51
50
|
domain: string;
|
|
51
|
+
name: string;
|
|
52
52
|
expires: number;
|
|
53
53
|
httpOnly: boolean;
|
|
54
54
|
secure: boolean;
|
|
@@ -108,8 +108,8 @@ export declare const runApiStorageStateSchema: z.ZodObject<{
|
|
|
108
108
|
cookies: {
|
|
109
109
|
path: string;
|
|
110
110
|
value: string;
|
|
111
|
-
name: string;
|
|
112
111
|
domain: string;
|
|
112
|
+
name: string;
|
|
113
113
|
expires: number;
|
|
114
114
|
httpOnly: boolean;
|
|
115
115
|
secure: boolean;
|
|
@@ -133,8 +133,8 @@ export declare const runApiStorageStateSchema: z.ZodObject<{
|
|
|
133
133
|
cookies: {
|
|
134
134
|
path: string;
|
|
135
135
|
value: string;
|
|
136
|
-
name: string;
|
|
137
136
|
domain: string;
|
|
137
|
+
name: string;
|
|
138
138
|
expires: number;
|
|
139
139
|
httpOnly: boolean;
|
|
140
140
|
secure: boolean;
|
|
@@ -180,8 +180,8 @@ export declare const runApiSessionSchema: z.ZodDiscriminatedUnion<"type", [z.Zod
|
|
|
180
180
|
}, "strip", z.ZodTypeAny, {
|
|
181
181
|
path: string;
|
|
182
182
|
value: string;
|
|
183
|
-
name: string;
|
|
184
183
|
domain: string;
|
|
184
|
+
name: string;
|
|
185
185
|
expires: number;
|
|
186
186
|
httpOnly: boolean;
|
|
187
187
|
secure: boolean;
|
|
@@ -189,8 +189,8 @@ export declare const runApiSessionSchema: z.ZodDiscriminatedUnion<"type", [z.Zod
|
|
|
189
189
|
}, {
|
|
190
190
|
path: string;
|
|
191
191
|
value: string;
|
|
192
|
-
name: string;
|
|
193
192
|
domain: string;
|
|
193
|
+
name: string;
|
|
194
194
|
expires: number;
|
|
195
195
|
httpOnly: boolean;
|
|
196
196
|
secure: boolean;
|
|
@@ -250,8 +250,8 @@ export declare const runApiSessionSchema: z.ZodDiscriminatedUnion<"type", [z.Zod
|
|
|
250
250
|
cookies: {
|
|
251
251
|
path: string;
|
|
252
252
|
value: string;
|
|
253
|
-
name: string;
|
|
254
253
|
domain: string;
|
|
254
|
+
name: string;
|
|
255
255
|
expires: number;
|
|
256
256
|
httpOnly: boolean;
|
|
257
257
|
secure: boolean;
|
|
@@ -275,8 +275,8 @@ export declare const runApiSessionSchema: z.ZodDiscriminatedUnion<"type", [z.Zod
|
|
|
275
275
|
cookies: {
|
|
276
276
|
path: string;
|
|
277
277
|
value: string;
|
|
278
|
-
name: string;
|
|
279
278
|
domain: string;
|
|
279
|
+
name: string;
|
|
280
280
|
expires: number;
|
|
281
281
|
httpOnly: boolean;
|
|
282
282
|
secure: boolean;
|
|
@@ -303,8 +303,8 @@ export declare const runApiSessionSchema: z.ZodDiscriminatedUnion<"type", [z.Zod
|
|
|
303
303
|
cookies: {
|
|
304
304
|
path: string;
|
|
305
305
|
value: string;
|
|
306
|
-
name: string;
|
|
307
306
|
domain: string;
|
|
307
|
+
name: string;
|
|
308
308
|
expires: number;
|
|
309
309
|
httpOnly: boolean;
|
|
310
310
|
secure: boolean;
|
|
@@ -331,8 +331,8 @@ export declare const runApiSessionSchema: z.ZodDiscriminatedUnion<"type", [z.Zod
|
|
|
331
331
|
cookies: {
|
|
332
332
|
path: string;
|
|
333
333
|
value: string;
|
|
334
|
-
name: string;
|
|
335
334
|
domain: string;
|
|
335
|
+
name: string;
|
|
336
336
|
expires: number;
|
|
337
337
|
httpOnly: boolean;
|
|
338
338
|
secure: boolean;
|
|
@@ -406,8 +406,8 @@ export declare const runApiParametersSchema: z.ZodObject<{
|
|
|
406
406
|
}, "strip", z.ZodTypeAny, {
|
|
407
407
|
path: string;
|
|
408
408
|
value: string;
|
|
409
|
-
name: string;
|
|
410
409
|
domain: string;
|
|
410
|
+
name: string;
|
|
411
411
|
expires: number;
|
|
412
412
|
httpOnly: boolean;
|
|
413
413
|
secure: boolean;
|
|
@@ -415,8 +415,8 @@ export declare const runApiParametersSchema: z.ZodObject<{
|
|
|
415
415
|
}, {
|
|
416
416
|
path: string;
|
|
417
417
|
value: string;
|
|
418
|
-
name: string;
|
|
419
418
|
domain: string;
|
|
419
|
+
name: string;
|
|
420
420
|
expires: number;
|
|
421
421
|
httpOnly: boolean;
|
|
422
422
|
secure: boolean;
|
|
@@ -476,8 +476,8 @@ export declare const runApiParametersSchema: z.ZodObject<{
|
|
|
476
476
|
cookies: {
|
|
477
477
|
path: string;
|
|
478
478
|
value: string;
|
|
479
|
-
name: string;
|
|
480
479
|
domain: string;
|
|
480
|
+
name: string;
|
|
481
481
|
expires: number;
|
|
482
482
|
httpOnly: boolean;
|
|
483
483
|
secure: boolean;
|
|
@@ -501,8 +501,8 @@ export declare const runApiParametersSchema: z.ZodObject<{
|
|
|
501
501
|
cookies: {
|
|
502
502
|
path: string;
|
|
503
503
|
value: string;
|
|
504
|
-
name: string;
|
|
505
504
|
domain: string;
|
|
505
|
+
name: string;
|
|
506
506
|
expires: number;
|
|
507
507
|
httpOnly: boolean;
|
|
508
508
|
secure: boolean;
|
|
@@ -529,8 +529,8 @@ export declare const runApiParametersSchema: z.ZodObject<{
|
|
|
529
529
|
cookies: {
|
|
530
530
|
path: string;
|
|
531
531
|
value: string;
|
|
532
|
-
name: string;
|
|
533
532
|
domain: string;
|
|
533
|
+
name: string;
|
|
534
534
|
expires: number;
|
|
535
535
|
httpOnly: boolean;
|
|
536
536
|
secure: boolean;
|
|
@@ -557,8 +557,8 @@ export declare const runApiParametersSchema: z.ZodObject<{
|
|
|
557
557
|
cookies: {
|
|
558
558
|
path: string;
|
|
559
559
|
value: string;
|
|
560
|
-
name: string;
|
|
561
560
|
domain: string;
|
|
561
|
+
name: string;
|
|
562
562
|
expires: number;
|
|
563
563
|
httpOnly: boolean;
|
|
564
564
|
secure: boolean;
|
|
@@ -590,8 +590,8 @@ export declare const runApiParametersSchema: z.ZodObject<{
|
|
|
590
590
|
cookies: {
|
|
591
591
|
path: string;
|
|
592
592
|
value: string;
|
|
593
|
-
name: string;
|
|
594
593
|
domain: string;
|
|
594
|
+
name: string;
|
|
595
595
|
expires: number;
|
|
596
596
|
httpOnly: boolean;
|
|
597
597
|
secure: boolean;
|
|
@@ -623,8 +623,8 @@ export declare const runApiParametersSchema: z.ZodObject<{
|
|
|
623
623
|
cookies: {
|
|
624
624
|
path: string;
|
|
625
625
|
value: string;
|
|
626
|
-
name: string;
|
|
627
626
|
domain: string;
|
|
627
|
+
name: string;
|
|
628
628
|
expires: number;
|
|
629
629
|
httpOnly: boolean;
|
|
630
630
|
secure: boolean;
|
|
@@ -724,8 +724,8 @@ export declare const runApiParametersSchema: z.ZodObject<{
|
|
|
724
724
|
cookies: {
|
|
725
725
|
path: string;
|
|
726
726
|
value: string;
|
|
727
|
-
name: string;
|
|
728
727
|
domain: string;
|
|
728
|
+
name: string;
|
|
729
729
|
expires: number;
|
|
730
730
|
httpOnly: boolean;
|
|
731
731
|
secure: boolean;
|
|
@@ -769,8 +769,8 @@ export declare const runApiParametersSchema: z.ZodObject<{
|
|
|
769
769
|
cookies: {
|
|
770
770
|
path: string;
|
|
771
771
|
value: string;
|
|
772
|
-
name: string;
|
|
773
772
|
domain: string;
|
|
773
|
+
name: string;
|
|
774
774
|
expires: number;
|
|
775
775
|
httpOnly: boolean;
|
|
776
776
|
secure: boolean;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as z from "zod";
|
|
2
2
|
export declare const captchaSolverSettingsSchema: z.ZodDefault<z.ZodObject<{
|
|
3
3
|
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
4
|
+
port: z.ZodOptional<z.ZodNumber>;
|
|
4
5
|
cloudflare: z.ZodOptional<z.ZodObject<{
|
|
5
6
|
enabled: z.ZodBoolean;
|
|
6
7
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -113,6 +114,7 @@ export declare const captchaSolverSettingsSchema: z.ZodDefault<z.ZodObject<{
|
|
|
113
114
|
maxRetries: number;
|
|
114
115
|
timeout: number;
|
|
115
116
|
};
|
|
117
|
+
port?: number | undefined;
|
|
116
118
|
cloudflare?: {
|
|
117
119
|
enabled: boolean;
|
|
118
120
|
} | undefined;
|
|
@@ -151,6 +153,7 @@ export declare const captchaSolverSettingsSchema: z.ZodDefault<z.ZodObject<{
|
|
|
151
153
|
} | undefined;
|
|
152
154
|
}, {
|
|
153
155
|
enabled?: boolean | undefined;
|
|
156
|
+
port?: number | undefined;
|
|
154
157
|
cloudflare?: {
|
|
155
158
|
enabled: boolean;
|
|
156
159
|
} | undefined;
|
|
@@ -198,7 +201,13 @@ export type CaptchaSolverSettingsWithRunContext = z.infer<typeof captchaSolverSe
|
|
|
198
201
|
workspaceId: string;
|
|
199
202
|
projectId: string;
|
|
200
203
|
baseUrl: string;
|
|
201
|
-
|
|
204
|
+
authentication: {
|
|
205
|
+
type: "apiKey";
|
|
206
|
+
apiKey: string;
|
|
207
|
+
} | {
|
|
208
|
+
type: "basic" | "bearer";
|
|
209
|
+
token?: string;
|
|
210
|
+
};
|
|
202
211
|
};
|
|
203
212
|
export declare const settingsSchema: z.ZodObject<{
|
|
204
213
|
authSessions: z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
@@ -217,6 +226,7 @@ export declare const settingsSchema: z.ZodObject<{
|
|
|
217
226
|
}>>>;
|
|
218
227
|
captchaSolver: z.ZodOptional<z.ZodDefault<z.ZodObject<{
|
|
219
228
|
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
229
|
+
port: z.ZodOptional<z.ZodNumber>;
|
|
220
230
|
cloudflare: z.ZodOptional<z.ZodObject<{
|
|
221
231
|
enabled: z.ZodBoolean;
|
|
222
232
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -329,6 +339,7 @@ export declare const settingsSchema: z.ZodObject<{
|
|
|
329
339
|
maxRetries: number;
|
|
330
340
|
timeout: number;
|
|
331
341
|
};
|
|
342
|
+
port?: number | undefined;
|
|
332
343
|
cloudflare?: {
|
|
333
344
|
enabled: boolean;
|
|
334
345
|
} | undefined;
|
|
@@ -367,6 +378,7 @@ export declare const settingsSchema: z.ZodObject<{
|
|
|
367
378
|
} | undefined;
|
|
368
379
|
}, {
|
|
369
380
|
enabled?: boolean | undefined;
|
|
381
|
+
port?: number | undefined;
|
|
370
382
|
cloudflare?: {
|
|
371
383
|
enabled: boolean;
|
|
372
384
|
} | undefined;
|
|
@@ -425,6 +437,7 @@ export declare const settingsSchema: z.ZodObject<{
|
|
|
425
437
|
maxRetries: number;
|
|
426
438
|
timeout: number;
|
|
427
439
|
};
|
|
440
|
+
port?: number | undefined;
|
|
428
441
|
cloudflare?: {
|
|
429
442
|
enabled: boolean;
|
|
430
443
|
} | undefined;
|
|
@@ -471,6 +484,7 @@ export declare const settingsSchema: z.ZodObject<{
|
|
|
471
484
|
} | undefined;
|
|
472
485
|
captchaSolver?: {
|
|
473
486
|
enabled?: boolean | undefined;
|
|
487
|
+
port?: number | undefined;
|
|
474
488
|
cloudflare?: {
|
|
475
489
|
enabled: boolean;
|
|
476
490
|
} | undefined;
|
|
@@ -28,6 +28,7 @@ const captchaSolverSolveSettingsSchema = z.object({
|
|
|
28
28
|
});
|
|
29
29
|
const captchaSolverSettingsSchema = exports.captchaSolverSettingsSchema = z.object({
|
|
30
30
|
enabled: z.boolean().default(false),
|
|
31
|
+
port: z.number().int().min(1).max(65535).optional(),
|
|
31
32
|
cloudflare: baseCaptchaSchema.optional(),
|
|
32
33
|
googleRecaptchaV2: baseCaptchaSchema.optional(),
|
|
33
34
|
googleRecaptchaV3: baseCaptchaSchema.optional(),
|
package/dist/index.d.ts
CHANGED
|
@@ -2,3 +2,4 @@ export { extendPayload, extendTimeout, runInfo, RunError, getAuthSessionParamete
|
|
|
2
2
|
export { runWithContext, getExecutionContext, } from "./common/asyncLocalStorage";
|
|
3
3
|
export { getDownloadDirectoryPath } from "./runtime/downloadDirectory";
|
|
4
4
|
export { withPlaywrightContext } from "./common/playwrightContext";
|
|
5
|
+
export { waitForCaptchaSolve, withWaitForCaptchaSolve, onCaptchaEvent, onceCaptchaEvent, removeCaptchaEventListener, pauseCaptchaSolver, resumeCaptchaSolver, } from "./runtime/captcha";
|
package/dist/index.js
CHANGED
|
@@ -45,12 +45,42 @@ Object.defineProperty(exports, "getExecutionContext", {
|
|
|
45
45
|
return _asyncLocalStorage.getExecutionContext;
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
|
+
Object.defineProperty(exports, "onCaptchaEvent", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function () {
|
|
51
|
+
return _captcha.onCaptchaEvent;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
Object.defineProperty(exports, "onceCaptchaEvent", {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return _captcha.onceCaptchaEvent;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
Object.defineProperty(exports, "pauseCaptchaSolver", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function () {
|
|
63
|
+
return _captcha.pauseCaptchaSolver;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
48
66
|
Object.defineProperty(exports, "persistentStore", {
|
|
49
67
|
enumerable: true,
|
|
50
68
|
get: function () {
|
|
51
69
|
return _runtime.persistentStore;
|
|
52
70
|
}
|
|
53
71
|
});
|
|
72
|
+
Object.defineProperty(exports, "removeCaptchaEventListener", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
get: function () {
|
|
75
|
+
return _captcha.removeCaptchaEventListener;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
Object.defineProperty(exports, "resumeCaptchaSolver", {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
get: function () {
|
|
81
|
+
return _captcha.resumeCaptchaSolver;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
54
84
|
Object.defineProperty(exports, "runInfo", {
|
|
55
85
|
enumerable: true,
|
|
56
86
|
get: function () {
|
|
@@ -63,13 +93,26 @@ Object.defineProperty(exports, "runWithContext", {
|
|
|
63
93
|
return _asyncLocalStorage.runWithContext;
|
|
64
94
|
}
|
|
65
95
|
});
|
|
96
|
+
Object.defineProperty(exports, "waitForCaptchaSolve", {
|
|
97
|
+
enumerable: true,
|
|
98
|
+
get: function () {
|
|
99
|
+
return _captcha.waitForCaptchaSolve;
|
|
100
|
+
}
|
|
101
|
+
});
|
|
66
102
|
Object.defineProperty(exports, "withPlaywrightContext", {
|
|
67
103
|
enumerable: true,
|
|
68
104
|
get: function () {
|
|
69
105
|
return _playwrightContext.withPlaywrightContext;
|
|
70
106
|
}
|
|
71
107
|
});
|
|
108
|
+
Object.defineProperty(exports, "withWaitForCaptchaSolve", {
|
|
109
|
+
enumerable: true,
|
|
110
|
+
get: function () {
|
|
111
|
+
return _captcha.withWaitForCaptchaSolve;
|
|
112
|
+
}
|
|
113
|
+
});
|
|
72
114
|
var _runtime = require("./runtime");
|
|
73
115
|
var _asyncLocalStorage = require("./common/asyncLocalStorage");
|
|
74
116
|
var _downloadDirectory = require("./runtime/downloadDirectory");
|
|
75
|
-
var _playwrightContext = require("./common/playwrightContext");
|
|
117
|
+
var _playwrightContext = require("./common/playwrightContext");
|
|
118
|
+
var _captcha = require("./runtime/captcha");
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Page, BrowserContext } from "playwright";
|
|
2
|
+
import { Captcha, CaptchaStatus, CaptchaCallback } from "../common/extension/types";
|
|
3
|
+
export type WithWaitForCaptchaSolveOptions = {
|
|
4
|
+
page: Page;
|
|
5
|
+
timeoutInMs?: number;
|
|
6
|
+
settleDurationMs?: number;
|
|
7
|
+
waitForNetworkSettled?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export declare function withWaitForCaptchaSolve<T>(callback: (page: Page) => Promise<T>, options?: WithWaitForCaptchaSolveOptions): Promise<T>;
|
|
10
|
+
export declare function waitForCaptchaSolve(page: Page, { timeoutInMs, settlePeriodInMs, }?: {
|
|
11
|
+
timeoutInMs?: number;
|
|
12
|
+
settlePeriodInMs?: number;
|
|
13
|
+
}): Promise<void>;
|
|
14
|
+
export declare function removeCaptchaEventListener(page: Page, status: CaptchaStatus, f: (captcha: Captcha) => any): Promise<void>;
|
|
15
|
+
export declare function onCaptchaEvent(page: Page, status: CaptchaStatus, f: CaptchaCallback): Promise<void>;
|
|
16
|
+
export declare function onceCaptchaEvent(page: Page, status: CaptchaStatus, f: CaptchaCallback): Promise<void>;
|
|
17
|
+
export declare function pauseCaptchaSolver(context: BrowserContext): Promise<void>;
|
|
18
|
+
export declare function resumeCaptchaSolver(context: BrowserContext): Promise<void>;
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.onCaptchaEvent = onCaptchaEvent;
|
|
7
|
+
exports.onceCaptchaEvent = onceCaptchaEvent;
|
|
8
|
+
exports.pauseCaptchaSolver = pauseCaptchaSolver;
|
|
9
|
+
exports.removeCaptchaEventListener = removeCaptchaEventListener;
|
|
10
|
+
exports.resumeCaptchaSolver = resumeCaptchaSolver;
|
|
11
|
+
exports.waitForCaptchaSolve = waitForCaptchaSolve;
|
|
12
|
+
exports.withWaitForCaptchaSolve = withWaitForCaptchaSolve;
|
|
13
|
+
var _intunedExtensionServer = require("../common/extension/intunedExtensionServer");
|
|
14
|
+
var _extensionsHelpers = require("../common/extension/extensionsHelpers");
|
|
15
|
+
async function withWaitForCaptchaSolve(callback, options) {
|
|
16
|
+
const {
|
|
17
|
+
page,
|
|
18
|
+
timeoutInMs = 10_000,
|
|
19
|
+
settleDurationMs = 5_000,
|
|
20
|
+
waitForNetworkSettled = true
|
|
21
|
+
} = options || {};
|
|
22
|
+
const extensionServer = (0, _intunedExtensionServer.getIntunedExtensionServer)();
|
|
23
|
+
let settledResolve = null;
|
|
24
|
+
let settledPromise = new Promise(resolve => {
|
|
25
|
+
settledResolve = resolve;
|
|
26
|
+
});
|
|
27
|
+
let isTimeout = false;
|
|
28
|
+
let captchasAppeared = false;
|
|
29
|
+
let hasError = false;
|
|
30
|
+
let errorMessage = "";
|
|
31
|
+
let actionDone = false;
|
|
32
|
+
const getPendingCaptchas = async () => await extensionServer.getCaptchas(page, "solving");
|
|
33
|
+
const hasNoPendingCaptchas = async () => !captchasAppeared || (await getPendingCaptchas()).length === 0;
|
|
34
|
+
const maybeSettle = async () => {
|
|
35
|
+
if (await hasNoPendingCaptchas()) {
|
|
36
|
+
settledResolve?.();
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const onCaptchaUpdate = async _captcha => {
|
|
40
|
+
const solvingCaptchas = await extensionServer.getCaptchas(page, "solving");
|
|
41
|
+
const errorCaptchas = await extensionServer.getCaptchas(page, "error");
|
|
42
|
+
if (solvingCaptchas.length > 0) {
|
|
43
|
+
captchasAppeared = true;
|
|
44
|
+
}
|
|
45
|
+
if (errorCaptchas.length > 0) {
|
|
46
|
+
hasError = true;
|
|
47
|
+
const err = errorCaptchas[0].error;
|
|
48
|
+
errorMessage = err?.code ?? "Unknown error during CAPTCHA solving.";
|
|
49
|
+
await maybeSettle();
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (solvingCaptchas.length === 0) {
|
|
53
|
+
await maybeSettle();
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const timeoutPromise = new Promise(resolve => {
|
|
57
|
+
setTimeout(() => {
|
|
58
|
+
isTimeout = true;
|
|
59
|
+
settledResolve?.();
|
|
60
|
+
resolve();
|
|
61
|
+
}, timeoutInMs);
|
|
62
|
+
});
|
|
63
|
+
await extensionServer.subscribe(page, onCaptchaUpdate);
|
|
64
|
+
try {
|
|
65
|
+
const initialPending = await getPendingCaptchas();
|
|
66
|
+
if (initialPending.length > 0) {
|
|
67
|
+
captchasAppeared = true;
|
|
68
|
+
}
|
|
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
|
+
const result = await callback(page);
|
|
76
|
+
actionDone = true;
|
|
77
|
+
if (waitForNetworkSettled) {
|
|
78
|
+
try {
|
|
79
|
+
await page.waitForLoadState("networkidle");
|
|
80
|
+
} catch (_) {}
|
|
81
|
+
}
|
|
82
|
+
await maybeSettle();
|
|
83
|
+
let shouldContinue = true;
|
|
84
|
+
while (shouldContinue) {
|
|
85
|
+
await Promise.race([settledPromise, timeoutPromise]);
|
|
86
|
+
await new Promise(r => setTimeout(r, settleDurationMs));
|
|
87
|
+
if (hasError) {
|
|
88
|
+
throw new Error(`CAPTCHA Solve Error: ${errorMessage}`);
|
|
89
|
+
}
|
|
90
|
+
const noPendingCaptchas = await hasNoPendingCaptchas();
|
|
91
|
+
if (actionDone && noPendingCaptchas || isTimeout) {
|
|
92
|
+
if (isTimeout && !noPendingCaptchas) {
|
|
93
|
+
throw new Error("CAPTCHA Solve timed out with pending captchas.");
|
|
94
|
+
}
|
|
95
|
+
shouldContinue = false;
|
|
96
|
+
} else {
|
|
97
|
+
settledPromise = new Promise(resolve => {
|
|
98
|
+
settledResolve = resolve;
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return result;
|
|
103
|
+
} finally {
|
|
104
|
+
await extensionServer.unsubscribe(page, onCaptchaUpdate);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
async function waitForCaptchaSolve(page, {
|
|
108
|
+
timeoutInMs = 10_000,
|
|
109
|
+
settlePeriodInMs = 5_000
|
|
110
|
+
} = {}) {
|
|
111
|
+
await withWaitForCaptchaSolve(async () => undefined, {
|
|
112
|
+
page,
|
|
113
|
+
timeoutInMs,
|
|
114
|
+
settleDurationMs: settlePeriodInMs,
|
|
115
|
+
waitForNetworkSettled: false
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
async function removeCaptchaEventListener(page, status, f) {
|
|
119
|
+
const extensionServer = (0, _intunedExtensionServer.getIntunedExtensionServer)();
|
|
120
|
+
await extensionServer.unsubscribe(page, f, status);
|
|
121
|
+
}
|
|
122
|
+
async function onCaptchaEvent(page, status, f) {
|
|
123
|
+
const extensionServer = (0, _intunedExtensionServer.getIntunedExtensionServer)();
|
|
124
|
+
const wrapper = async captcha => {
|
|
125
|
+
if (captcha.status === status) {
|
|
126
|
+
await f(captcha);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
await extensionServer.subscribe(page, wrapper, status);
|
|
130
|
+
}
|
|
131
|
+
async function onceCaptchaEvent(page, status, f) {
|
|
132
|
+
const extensionServer = (0, _intunedExtensionServer.getIntunedExtensionServer)();
|
|
133
|
+
const oneTimeHandler = async captcha => {
|
|
134
|
+
if (captcha.status === status) {
|
|
135
|
+
await extensionServer.unsubscribe(page, oneTimeHandler, status);
|
|
136
|
+
}
|
|
137
|
+
await f(captcha);
|
|
138
|
+
};
|
|
139
|
+
await extensionServer.subscribe(page, oneTimeHandler, status);
|
|
140
|
+
}
|
|
141
|
+
async function setAutoSolve(context, enabled) {
|
|
142
|
+
const worker = await (0, _extensionsHelpers.getIntunedExtensionWorker)(context);
|
|
143
|
+
if (!worker) {
|
|
144
|
+
if (!enabled) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
throw new Error("Intuned service worker not found");
|
|
148
|
+
}
|
|
149
|
+
await worker.evaluate(`
|
|
150
|
+
(enabled) => new Promise((resolve, reject) => {
|
|
151
|
+
const updateSettings = () => {
|
|
152
|
+
if (chrome?.storage?.local) {
|
|
153
|
+
chrome.storage.local.get('settings', (result) => {
|
|
154
|
+
if (chrome.runtime.lastError) {
|
|
155
|
+
reject(new Error(chrome.runtime.lastError.message));
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
const settings = result.settings || {};
|
|
159
|
+
if (!settings.settings) {
|
|
160
|
+
settings.settings = {};
|
|
161
|
+
}
|
|
162
|
+
settings.settings.autoSolve = enabled;
|
|
163
|
+
chrome.storage.local.set({ settings }, () => {
|
|
164
|
+
if (chrome.runtime.lastError) {
|
|
165
|
+
reject(new Error(chrome.runtime.lastError.message));
|
|
166
|
+
} else {
|
|
167
|
+
resolve(true);
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
} else {
|
|
172
|
+
setTimeout(updateSettings, 50);
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
updateSettings();
|
|
176
|
+
})
|
|
177
|
+
`, enabled);
|
|
178
|
+
}
|
|
179
|
+
async function pauseCaptchaSolver(context) {
|
|
180
|
+
if (!(0, _extensionsHelpers.isIntunedExtensionEnabled)()) {
|
|
181
|
+
throw new Error("Intuned extension is not enabled. Cannot pause captcha solver.");
|
|
182
|
+
}
|
|
183
|
+
await setAutoSolve(context, false);
|
|
184
|
+
}
|
|
185
|
+
async function resumeCaptchaSolver(context) {
|
|
186
|
+
if (!(0, _extensionsHelpers.isIntunedExtensionEnabled)()) {
|
|
187
|
+
throw new Error("Intuned extension is not enabled. Cannot resume captcha solver.");
|
|
188
|
+
}
|
|
189
|
+
await setAutoSolve(context, true);
|
|
190
|
+
}
|