@prosopo/procaptcha-frictionless 2.8.22 → 2.11.0
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/.turbo/turbo-build$colon$cjs.log +12 -14
- package/.turbo/turbo-build$colon$tsc.log +74 -0
- package/.turbo/turbo-build.log +17 -15
- package/CHANGELOG.md +791 -0
- package/dist/ProcaptchaFrictionless.d.ts +3 -0
- package/dist/ProcaptchaFrictionless.d.ts.map +1 -0
- package/dist/ProcaptchaFrictionless.js +78 -36
- package/dist/ProcaptchaFrictionless.js.map +1 -0
- package/dist/cjs/ProcaptchaFrictionless.cjs +97 -33
- package/dist/cjs/customDetectBot.cjs +49 -14
- package/dist/customDetectBot.d.ts +5 -0
- package/dist/customDetectBot.d.ts.map +1 -0
- package/dist/customDetectBot.js +50 -15
- package/dist/customDetectBot.js.map +1 -0
- package/dist/detectorLoader.d.ts +4 -0
- package/dist/detectorLoader.d.ts.map +1 -0
- package/dist/detectorLoader.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js.map +1 -0
- package/dist/tests/customDetectBot.test.d.ts +2 -0
- package/dist/tests/customDetectBot.test.d.ts.map +1 -0
- package/dist/tests/customDetectBot.test.js +45 -0
- package/dist/tests/customDetectBot.test.js.map +1 -0
- package/dist/tests/customDetectBotSimd.test.d.ts +2 -0
- package/dist/tests/customDetectBotSimd.test.d.ts.map +1 -0
- package/dist/tests/customDetectBotSimd.test.js +106 -0
- package/dist/tests/customDetectBotSimd.test.js.map +1 -0
- package/package.json +17 -14
- package/src/ProcaptchaFrictionless.tsx +286 -0
- package/src/customDetectBot.ts +160 -0
- package/src/detectorLoader.ts +18 -0
- package/src/index.ts +14 -0
- package/src/tests/customDetectBot.test.ts +77 -0
- package/src/tests/customDetectBotSimd.test.ts +159 -0
- package/tsconfig.cjs.json +48 -0
- package/tsconfig.json +55 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/tsconfig.types.json +9 -0
- package/vite.cjs.config.ts +1 -1
- package/vite.esm.config.ts +1 -1
- package/vite.test.config.ts +1 -1
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type ProcaptchaFrictionlessProps } from "@prosopo/types";
|
|
2
|
+
export declare const ProcaptchaFrictionless: ({ config, callbacks, restart, i18n, detectBot, container, }: ProcaptchaFrictionlessProps) => import("react/jsx-runtime").JSX.Element;
|
|
3
|
+
//# sourceMappingURL=ProcaptchaFrictionless.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProcaptchaFrictionless.d.ts","sourceRoot":"","sources":["../src/ProcaptchaFrictionless.tsx"],"names":[],"mappings":"AAsBA,OAAO,EAKN,KAAK,2BAA2B,EAChC,MAAM,gBAAgB,CAAC;AAqDxB,eAAO,MAAM,sBAAsB,gEAOhC,2BAA2B,4CAqM7B,CAAC"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
1
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { loadI18next } from "@prosopo/locale";
|
|
3
|
-
import { Checkbox, getDefaultEvents, providerRetry } from "@prosopo/procaptcha-common";
|
|
4
|
-
import {
|
|
5
|
-
import { Procaptcha } from "@prosopo/procaptcha-react";
|
|
6
|
-
import { ProcaptchaConfigSchema } from "@prosopo/types";
|
|
3
|
+
import { Checkbox, getDefaultEvents, isSecureBrowserContext, providerRetry, TestModeBanner } from "@prosopo/procaptcha-common";
|
|
4
|
+
import { CaptchaType, ProcaptchaConfigSchema } from "@prosopo/types";
|
|
7
5
|
import { lightTheme, darkTheme } from "@prosopo/widget-skeleton";
|
|
8
6
|
import { useRef, useEffect, useState } from "react";
|
|
9
7
|
import customDetectBot from "./customDetectBot.js";
|
|
8
|
+
const ProcaptchaLoader = async () => (await import("@prosopo/procaptcha-react")).Procaptcha;
|
|
9
|
+
const ProcaptchaPuzzleLoader = async () => (await import("@prosopo/procaptcha-puzzle")).ProcaptchaPuzzle;
|
|
10
|
+
const ProcaptchaPowLoader = async () => (await import("@prosopo/procaptcha-pow")).ProcaptchaPow;
|
|
10
11
|
const renderPlaceholder = (theme, mode, errorMessage, isTranslationLoaded, translationFn, loading) => {
|
|
11
12
|
const checkboxTheme = "light" === theme ? lightTheme : darkTheme;
|
|
12
13
|
if (mode === "invisible") {
|
|
@@ -93,7 +94,62 @@ const ProcaptchaFrictionless = ({
|
|
|
93
94
|
restart();
|
|
94
95
|
}, 1e4);
|
|
95
96
|
};
|
|
97
|
+
const renderForCaptchaType = async (captchaType, frictionlessState) => {
|
|
98
|
+
const onEscalate = (next, newSessionId) => {
|
|
99
|
+
void renderForCaptchaType(next, {
|
|
100
|
+
...frictionlessState,
|
|
101
|
+
sessionId: newSessionId
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
if (captchaType === CaptchaType.image) {
|
|
105
|
+
const Procaptcha = await ProcaptchaLoader();
|
|
106
|
+
setComponentToRender(
|
|
107
|
+
/* @__PURE__ */ jsx(
|
|
108
|
+
Procaptcha,
|
|
109
|
+
{
|
|
110
|
+
config,
|
|
111
|
+
callbacks,
|
|
112
|
+
frictionlessState,
|
|
113
|
+
i18n
|
|
114
|
+
}
|
|
115
|
+
)
|
|
116
|
+
);
|
|
117
|
+
} else if (captchaType === CaptchaType.puzzle) {
|
|
118
|
+
const ProcaptchaPuzzle = await ProcaptchaPuzzleLoader();
|
|
119
|
+
setComponentToRender(
|
|
120
|
+
/* @__PURE__ */ jsx(
|
|
121
|
+
ProcaptchaPuzzle,
|
|
122
|
+
{
|
|
123
|
+
config,
|
|
124
|
+
callbacks,
|
|
125
|
+
frictionlessState,
|
|
126
|
+
i18n
|
|
127
|
+
}
|
|
128
|
+
)
|
|
129
|
+
);
|
|
130
|
+
} else {
|
|
131
|
+
const ProcaptchaPow = await ProcaptchaPowLoader();
|
|
132
|
+
setComponentToRender(
|
|
133
|
+
/* @__PURE__ */ jsx(
|
|
134
|
+
ProcaptchaPow,
|
|
135
|
+
{
|
|
136
|
+
config,
|
|
137
|
+
callbacks,
|
|
138
|
+
frictionlessState,
|
|
139
|
+
i18n,
|
|
140
|
+
onEscalate
|
|
141
|
+
}
|
|
142
|
+
)
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
96
146
|
const start = async () => {
|
|
147
|
+
if (!isSecureBrowserContext()) {
|
|
148
|
+
const errorMessage = i18n.isInitialized ? i18n.t("WIDGET.INSECURE_CONTEXT") : "Procaptcha requires a secure (HTTPS) connection";
|
|
149
|
+
events.onError(new Error(errorMessage));
|
|
150
|
+
fallOverWithStyle(errorMessage, "WIDGET.INSECURE_CONTEXT");
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
97
153
|
await providerRetry(
|
|
98
154
|
async () => {
|
|
99
155
|
stateRef.current.attemptCount += 1;
|
|
@@ -113,38 +169,21 @@ const ProcaptchaFrictionless = ({
|
|
|
113
169
|
provider: result.provider,
|
|
114
170
|
sessionId: result.sessionId,
|
|
115
171
|
userAccount: result.userAccount,
|
|
116
|
-
restart
|
|
172
|
+
restart,
|
|
117
173
|
// Pass restart function
|
|
174
|
+
behaviorCollector1: result.behaviorCollector1,
|
|
175
|
+
behaviorCollector2: result.behaviorCollector2,
|
|
176
|
+
behaviorCollector3: result.behaviorCollector3,
|
|
177
|
+
deviceCapability: result.deviceCapability,
|
|
178
|
+
encryptBehavioralData: result.encryptBehavioralData,
|
|
179
|
+
getSimdReadings: result.getSimdReadings,
|
|
180
|
+
hp: result.hp
|
|
181
|
+
};
|
|
182
|
+
await renderForCaptchaType(result.captchaType, frictionlessState);
|
|
183
|
+
stateRef.current = {
|
|
184
|
+
...stateRef.current,
|
|
185
|
+
loading: false
|
|
118
186
|
};
|
|
119
|
-
if (result.captchaType === "image") {
|
|
120
|
-
setComponentToRender(
|
|
121
|
-
/* @__PURE__ */ jsx(
|
|
122
|
-
Procaptcha,
|
|
123
|
-
{
|
|
124
|
-
config,
|
|
125
|
-
callbacks,
|
|
126
|
-
frictionlessState,
|
|
127
|
-
i18n
|
|
128
|
-
}
|
|
129
|
-
)
|
|
130
|
-
);
|
|
131
|
-
} else {
|
|
132
|
-
setComponentToRender(
|
|
133
|
-
/* @__PURE__ */ jsx(
|
|
134
|
-
ProcaptchaPow,
|
|
135
|
-
{
|
|
136
|
-
config,
|
|
137
|
-
callbacks,
|
|
138
|
-
frictionlessState,
|
|
139
|
-
i18n
|
|
140
|
-
}
|
|
141
|
-
)
|
|
142
|
-
);
|
|
143
|
-
stateRef.current = {
|
|
144
|
-
...stateRef.current,
|
|
145
|
-
loading: false
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
187
|
},
|
|
149
188
|
start,
|
|
150
189
|
resetState,
|
|
@@ -163,7 +202,10 @@ const ProcaptchaFrictionless = ({
|
|
|
163
202
|
};
|
|
164
203
|
detectAndSetComponent();
|
|
165
204
|
}, [config, callbacks, detectBot, config.language]);
|
|
166
|
-
return
|
|
205
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
206
|
+
/* @__PURE__ */ jsx(TestModeBanner, { siteKey: config.account?.address ?? "" }),
|
|
207
|
+
componentToRender
|
|
208
|
+
] });
|
|
167
209
|
};
|
|
168
210
|
export {
|
|
169
211
|
ProcaptchaFrictionless
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProcaptchaFrictionless.js","sourceRoot":"","sources":["../src/ProcaptchaFrictionless.tsx"],"names":[],"mappings":";AAcA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EACN,QAAQ,EACR,cAAc,EACd,gBAAgB,EAChB,sBAAsB,EACtB,aAAa,GACb,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACN,WAAW,EAGX,sBAAsB,GAEtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,SAAS,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;YAC3B,CAAC;QACF,CAAC,CAAC,CAAC;IACJ,CAAC,CAAC;IAGF,SAAS,CAAC,GAAG,EAAE;QACd,MAAM,qBAAqB,GAAG,KAAK,IAAI,EAAE;YACxC,MAAM,KAAK,EAAE,CAAC;QACf,CAAC,CAAC;QAEF,qBAAqB,EAAE,CAAC;IACzB,CAAC,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEpD,OAAO,CACN,8BACC,KAAC,cAAc,IAAC,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,OAAO,IAAI,EAAE,GAAI,EACzD,iBAAiB,IAChB,CACH,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -1,14 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
2
24
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
25
|
const jsxRuntime = require("react/jsx-runtime");
|
|
4
26
|
const locale = require("@prosopo/locale");
|
|
5
27
|
const procaptchaCommon = require("@prosopo/procaptcha-common");
|
|
6
|
-
const procaptchaPow = require("@prosopo/procaptcha-pow");
|
|
7
|
-
const procaptchaReact = require("@prosopo/procaptcha-react");
|
|
8
28
|
const types = require("@prosopo/types");
|
|
9
29
|
const widgetSkeleton = require("@prosopo/widget-skeleton");
|
|
10
30
|
const react = require("react");
|
|
11
31
|
const customDetectBot = require("./customDetectBot.cjs");
|
|
32
|
+
const ProcaptchaLoader = async () => (await import("@prosopo/procaptcha-react")).Procaptcha;
|
|
33
|
+
const ProcaptchaPuzzleLoader = async () => (await import("@prosopo/procaptcha-puzzle")).ProcaptchaPuzzle;
|
|
34
|
+
const ProcaptchaPowLoader = async () => (await import("@prosopo/procaptcha-pow")).ProcaptchaPow;
|
|
12
35
|
const renderPlaceholder = (theme, mode, errorMessage, isTranslationLoaded, translationFn, loading) => {
|
|
13
36
|
const checkboxTheme = "light" === theme ? widgetSkeleton.lightTheme : widgetSkeleton.darkTheme;
|
|
14
37
|
if (mode === "invisible") {
|
|
@@ -95,7 +118,62 @@ const ProcaptchaFrictionless = ({
|
|
|
95
118
|
restart();
|
|
96
119
|
}, 1e4);
|
|
97
120
|
};
|
|
121
|
+
const renderForCaptchaType = async (captchaType, frictionlessState) => {
|
|
122
|
+
const onEscalate = (next, newSessionId) => {
|
|
123
|
+
void renderForCaptchaType(next, {
|
|
124
|
+
...frictionlessState,
|
|
125
|
+
sessionId: newSessionId
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
if (captchaType === types.CaptchaType.image) {
|
|
129
|
+
const Procaptcha = await ProcaptchaLoader();
|
|
130
|
+
setComponentToRender(
|
|
131
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
132
|
+
Procaptcha,
|
|
133
|
+
{
|
|
134
|
+
config,
|
|
135
|
+
callbacks,
|
|
136
|
+
frictionlessState,
|
|
137
|
+
i18n
|
|
138
|
+
}
|
|
139
|
+
)
|
|
140
|
+
);
|
|
141
|
+
} else if (captchaType === types.CaptchaType.puzzle) {
|
|
142
|
+
const ProcaptchaPuzzle = await ProcaptchaPuzzleLoader();
|
|
143
|
+
setComponentToRender(
|
|
144
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
145
|
+
ProcaptchaPuzzle,
|
|
146
|
+
{
|
|
147
|
+
config,
|
|
148
|
+
callbacks,
|
|
149
|
+
frictionlessState,
|
|
150
|
+
i18n
|
|
151
|
+
}
|
|
152
|
+
)
|
|
153
|
+
);
|
|
154
|
+
} else {
|
|
155
|
+
const ProcaptchaPow = await ProcaptchaPowLoader();
|
|
156
|
+
setComponentToRender(
|
|
157
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
158
|
+
ProcaptchaPow,
|
|
159
|
+
{
|
|
160
|
+
config,
|
|
161
|
+
callbacks,
|
|
162
|
+
frictionlessState,
|
|
163
|
+
i18n,
|
|
164
|
+
onEscalate
|
|
165
|
+
}
|
|
166
|
+
)
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
};
|
|
98
170
|
const start = async () => {
|
|
171
|
+
if (!procaptchaCommon.isSecureBrowserContext()) {
|
|
172
|
+
const errorMessage = i18n.isInitialized ? i18n.t("WIDGET.INSECURE_CONTEXT") : "Procaptcha requires a secure (HTTPS) connection";
|
|
173
|
+
events.onError(new Error(errorMessage));
|
|
174
|
+
fallOverWithStyle(errorMessage, "WIDGET.INSECURE_CONTEXT");
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
99
177
|
await procaptchaCommon.providerRetry(
|
|
100
178
|
async () => {
|
|
101
179
|
stateRef.current.attemptCount += 1;
|
|
@@ -115,38 +193,21 @@ const ProcaptchaFrictionless = ({
|
|
|
115
193
|
provider: result.provider,
|
|
116
194
|
sessionId: result.sessionId,
|
|
117
195
|
userAccount: result.userAccount,
|
|
118
|
-
restart
|
|
196
|
+
restart,
|
|
119
197
|
// Pass restart function
|
|
198
|
+
behaviorCollector1: result.behaviorCollector1,
|
|
199
|
+
behaviorCollector2: result.behaviorCollector2,
|
|
200
|
+
behaviorCollector3: result.behaviorCollector3,
|
|
201
|
+
deviceCapability: result.deviceCapability,
|
|
202
|
+
encryptBehavioralData: result.encryptBehavioralData,
|
|
203
|
+
getSimdReadings: result.getSimdReadings,
|
|
204
|
+
hp: result.hp
|
|
205
|
+
};
|
|
206
|
+
await renderForCaptchaType(result.captchaType, frictionlessState);
|
|
207
|
+
stateRef.current = {
|
|
208
|
+
...stateRef.current,
|
|
209
|
+
loading: false
|
|
120
210
|
};
|
|
121
|
-
if (result.captchaType === "image") {
|
|
122
|
-
setComponentToRender(
|
|
123
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
124
|
-
procaptchaReact.Procaptcha,
|
|
125
|
-
{
|
|
126
|
-
config,
|
|
127
|
-
callbacks,
|
|
128
|
-
frictionlessState,
|
|
129
|
-
i18n
|
|
130
|
-
}
|
|
131
|
-
)
|
|
132
|
-
);
|
|
133
|
-
} else {
|
|
134
|
-
setComponentToRender(
|
|
135
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
136
|
-
procaptchaPow.ProcaptchaPow,
|
|
137
|
-
{
|
|
138
|
-
config,
|
|
139
|
-
callbacks,
|
|
140
|
-
frictionlessState,
|
|
141
|
-
i18n
|
|
142
|
-
}
|
|
143
|
-
)
|
|
144
|
-
);
|
|
145
|
-
stateRef.current = {
|
|
146
|
-
...stateRef.current,
|
|
147
|
-
loading: false
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
211
|
},
|
|
151
212
|
start,
|
|
152
213
|
resetState,
|
|
@@ -165,6 +226,9 @@ const ProcaptchaFrictionless = ({
|
|
|
165
226
|
};
|
|
166
227
|
detectAndSetComponent();
|
|
167
228
|
}, [config, callbacks, detectBot, config.language]);
|
|
168
|
-
return
|
|
229
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
230
|
+
/* @__PURE__ */ jsxRuntime.jsx(procaptchaCommon.TestModeBanner, { siteKey: config.account?.address ?? "" }),
|
|
231
|
+
componentToRender
|
|
232
|
+
] });
|
|
169
233
|
};
|
|
170
234
|
exports.ProcaptchaFrictionless = ProcaptchaFrictionless;
|
|
@@ -4,7 +4,15 @@ const api = require("@prosopo/api");
|
|
|
4
4
|
const common = require("@prosopo/common");
|
|
5
5
|
const loadBalancer = require("@prosopo/load-balancer");
|
|
6
6
|
const procaptchaCommon = require("@prosopo/procaptcha-common");
|
|
7
|
+
const types = require("@prosopo/types");
|
|
7
8
|
const detectorLoader = require("./detectorLoader.cjs");
|
|
9
|
+
if (typeof window !== "undefined") {
|
|
10
|
+
const envHint = typeof process !== "undefined" ? process.env?.PROSOPO_DEFAULT_ENVIRONMENT : void 0;
|
|
11
|
+
const parsedEnv = types.EnvironmentTypesSchema.safeParse(envHint);
|
|
12
|
+
if (parsedEnv.success) {
|
|
13
|
+
loadBalancer.prefetchProviders(parsedEnv.data).catch(() => void 0);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
8
16
|
const withTimeout = async (promise, ms) => {
|
|
9
17
|
let timeoutId;
|
|
10
18
|
const timeoutPromise = new Promise((_, reject) => {
|
|
@@ -26,16 +34,20 @@ const withTimeout = async (promise, ms) => {
|
|
|
26
34
|
}
|
|
27
35
|
};
|
|
28
36
|
const customDetectBot = async (config, container, restartFn) => {
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
37
|
+
const [ExtClass, detect] = await Promise.all([
|
|
38
|
+
procaptchaCommon.ExtensionLoader(config.web2),
|
|
39
|
+
detectorLoader.DetectorLoader(),
|
|
40
|
+
loadBalancer.prefetchProviders(config.defaultEnvironment)
|
|
41
|
+
]);
|
|
42
|
+
const ext = new ExtClass();
|
|
32
43
|
const detectionResult = await detect(
|
|
33
44
|
config.defaultEnvironment,
|
|
34
45
|
loadBalancer.getRandomActiveProvider,
|
|
35
46
|
container,
|
|
36
47
|
restartFn,
|
|
37
|
-
|
|
48
|
+
() => ext.getAccount(config)
|
|
38
49
|
);
|
|
50
|
+
const userAccount = detectionResult.userAccount;
|
|
39
51
|
if (!config.account.address) {
|
|
40
52
|
throw new common.ProsopoEnvError("GENERAL.SITE_KEY_MISSING");
|
|
41
53
|
}
|
|
@@ -47,23 +59,46 @@ const customDetectBot = async (config, container, restartFn) => {
|
|
|
47
59
|
provider.provider.url,
|
|
48
60
|
config.account.address
|
|
49
61
|
);
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
1e4
|
|
58
|
-
// 10 second timeout
|
|
62
|
+
const captchaPromise = providerApi.getFrictionlessCaptcha(
|
|
63
|
+
detectionResult.token,
|
|
64
|
+
detectionResult.encryptHeadHash,
|
|
65
|
+
config.account.address,
|
|
66
|
+
userAccount.account.address,
|
|
67
|
+
config.mode,
|
|
68
|
+
void 0
|
|
59
69
|
);
|
|
70
|
+
if (detectionResult.getSimdReadings) {
|
|
71
|
+
void detectionResult.getSimdReadings(6e4).catch(() => void 0);
|
|
72
|
+
}
|
|
73
|
+
const captcha = await withTimeout(captchaPromise, 1e4);
|
|
74
|
+
if (captcha.dns_url) {
|
|
75
|
+
try {
|
|
76
|
+
void fetch(captcha.dns_url, {
|
|
77
|
+
method: "GET",
|
|
78
|
+
mode: "no-cors",
|
|
79
|
+
credentials: "omit",
|
|
80
|
+
keepalive: true,
|
|
81
|
+
cache: "no-store"
|
|
82
|
+
}).catch(() => void 0);
|
|
83
|
+
} catch {
|
|
84
|
+
}
|
|
85
|
+
}
|
|
60
86
|
return {
|
|
61
87
|
captchaType: captcha.captchaType,
|
|
62
88
|
sessionId: captcha.sessionId,
|
|
63
89
|
provider,
|
|
64
90
|
status: captcha.status,
|
|
65
91
|
userAccount,
|
|
66
|
-
error: captcha.error
|
|
92
|
+
error: captcha.error,
|
|
93
|
+
hp: captcha.hp,
|
|
94
|
+
// Map specific trackers to generic behavioral collectors
|
|
95
|
+
behaviorCollector1: detectionResult.mouseTracker,
|
|
96
|
+
behaviorCollector2: detectionResult.touchTracker,
|
|
97
|
+
behaviorCollector3: detectionResult.clickTracker,
|
|
98
|
+
deviceCapability: detectionResult.hasTouchSupport,
|
|
99
|
+
encryptBehavioralData: detectionResult.encryptBehavioralData,
|
|
100
|
+
packBehavioralData: detectionResult.packBehavioralData,
|
|
101
|
+
getSimdReadings: detectionResult.getSimdReadings
|
|
67
102
|
};
|
|
68
103
|
};
|
|
69
104
|
exports.default = customDetectBot;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { BotDetectionFunction } from "@prosopo/types";
|
|
2
|
+
export declare const withTimeout: <T>(promise: Promise<T>, ms: number) => Promise<T>;
|
|
3
|
+
declare const customDetectBot: BotDetectionFunction;
|
|
4
|
+
export default customDetectBot;
|
|
5
|
+
//# sourceMappingURL=customDetectBot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"customDetectBot.d.ts","sourceRoot":"","sources":["../src/customDetectBot.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EACX,oBAAoB,EAEpB,MAAM,gBAAgB,CAAC;AAexB,eAAO,MAAM,WAAW,GAAU,CAAC,WACzB,OAAO,CAAC,CAAC,CAAC,MACf,MAAM,KACR,OAAO,CAAC,CAAC,CAoBX,CAAC;AAEF,QAAA,MAAM,eAAe,EAAE,oBA4FtB,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
package/dist/customDetectBot.js
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import { ProviderApi } from "@prosopo/api";
|
|
2
2
|
import { ProsopoEnvError } from "@prosopo/common";
|
|
3
|
-
import { getRandomActiveProvider } from "@prosopo/load-balancer";
|
|
3
|
+
import { prefetchProviders, getRandomActiveProvider } from "@prosopo/load-balancer";
|
|
4
4
|
import { ExtensionLoader } from "@prosopo/procaptcha-common";
|
|
5
|
+
import { EnvironmentTypesSchema } from "@prosopo/types";
|
|
5
6
|
import { DetectorLoader } from "./detectorLoader.js";
|
|
7
|
+
if (typeof window !== "undefined") {
|
|
8
|
+
const envHint = typeof process !== "undefined" ? process.env?.PROSOPO_DEFAULT_ENVIRONMENT : void 0;
|
|
9
|
+
const parsedEnv = EnvironmentTypesSchema.safeParse(envHint);
|
|
10
|
+
if (parsedEnv.success) {
|
|
11
|
+
prefetchProviders(parsedEnv.data).catch(() => void 0);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
6
14
|
const withTimeout = async (promise, ms) => {
|
|
7
15
|
let timeoutId;
|
|
8
16
|
const timeoutPromise = new Promise((_, reject) => {
|
|
@@ -24,16 +32,20 @@ const withTimeout = async (promise, ms) => {
|
|
|
24
32
|
}
|
|
25
33
|
};
|
|
26
34
|
const customDetectBot = async (config, container, restartFn) => {
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
35
|
+
const [ExtClass, detect] = await Promise.all([
|
|
36
|
+
ExtensionLoader(config.web2),
|
|
37
|
+
DetectorLoader(),
|
|
38
|
+
prefetchProviders(config.defaultEnvironment)
|
|
39
|
+
]);
|
|
40
|
+
const ext = new ExtClass();
|
|
30
41
|
const detectionResult = await detect(
|
|
31
42
|
config.defaultEnvironment,
|
|
32
43
|
getRandomActiveProvider,
|
|
33
44
|
container,
|
|
34
45
|
restartFn,
|
|
35
|
-
|
|
46
|
+
() => ext.getAccount(config)
|
|
36
47
|
);
|
|
48
|
+
const userAccount = detectionResult.userAccount;
|
|
37
49
|
if (!config.account.address) {
|
|
38
50
|
throw new ProsopoEnvError("GENERAL.SITE_KEY_MISSING");
|
|
39
51
|
}
|
|
@@ -45,23 +57,46 @@ const customDetectBot = async (config, container, restartFn) => {
|
|
|
45
57
|
provider.provider.url,
|
|
46
58
|
config.account.address
|
|
47
59
|
);
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
1e4
|
|
56
|
-
// 10 second timeout
|
|
60
|
+
const captchaPromise = providerApi.getFrictionlessCaptcha(
|
|
61
|
+
detectionResult.token,
|
|
62
|
+
detectionResult.encryptHeadHash,
|
|
63
|
+
config.account.address,
|
|
64
|
+
userAccount.account.address,
|
|
65
|
+
config.mode,
|
|
66
|
+
void 0
|
|
57
67
|
);
|
|
68
|
+
if (detectionResult.getSimdReadings) {
|
|
69
|
+
void detectionResult.getSimdReadings(6e4).catch(() => void 0);
|
|
70
|
+
}
|
|
71
|
+
const captcha = await withTimeout(captchaPromise, 1e4);
|
|
72
|
+
if (captcha.dns_url) {
|
|
73
|
+
try {
|
|
74
|
+
void fetch(captcha.dns_url, {
|
|
75
|
+
method: "GET",
|
|
76
|
+
mode: "no-cors",
|
|
77
|
+
credentials: "omit",
|
|
78
|
+
keepalive: true,
|
|
79
|
+
cache: "no-store"
|
|
80
|
+
}).catch(() => void 0);
|
|
81
|
+
} catch {
|
|
82
|
+
}
|
|
83
|
+
}
|
|
58
84
|
return {
|
|
59
85
|
captchaType: captcha.captchaType,
|
|
60
86
|
sessionId: captcha.sessionId,
|
|
61
87
|
provider,
|
|
62
88
|
status: captcha.status,
|
|
63
89
|
userAccount,
|
|
64
|
-
error: captcha.error
|
|
90
|
+
error: captcha.error,
|
|
91
|
+
hp: captcha.hp,
|
|
92
|
+
// Map specific trackers to generic behavioral collectors
|
|
93
|
+
behaviorCollector1: detectionResult.mouseTracker,
|
|
94
|
+
behaviorCollector2: detectionResult.touchTracker,
|
|
95
|
+
behaviorCollector3: detectionResult.clickTracker,
|
|
96
|
+
deviceCapability: detectionResult.hasTouchSupport,
|
|
97
|
+
encryptBehavioralData: detectionResult.encryptBehavioralData,
|
|
98
|
+
packBehavioralData: detectionResult.packBehavioralData,
|
|
99
|
+
getSimdReadings: detectionResult.getSimdReadings
|
|
65
100
|
};
|
|
66
101
|
};
|
|
67
102
|
export {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"customDetectBot.js","sourceRoot":"","sources":["../src/customDetectBot.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EACN,uBAAuB,EACvB,iBAAiB,GACjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAMxD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;IACnC,MAAM,OAAO,GACZ,OAAO,OAAO,KAAK,WAAW;QAC7B,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,2BAA2B;QAC1C,CAAC,CAAC,SAAS,CAAC;IACd,MAAM,SAAS,GAAG,sBAAsB,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IAC5D,IAAI,SAAS,CAAC,OAAO,EAAE,CAAC;QACvB,iBAAiB,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IAC1D,CAAC;AACF,CAAC;AAED,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,EAC/B,OAAmB,EACnB,EAAU,EACG,EAAE;IACf,IAAI,SAAqC,CAAC;IAC1C,MAAM,cAAc,GAAG,IAAI,OAAO,CAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE;QACvD,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE;YAC3B,MAAM,CAAC,IAAI,eAAe,CAAC,aAAa,CAAC,CAA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E,eAAe,CAAC,YAAY;QAChD,kBAAkB,EAAE,eAAe,CAAC,YAAY;QAChD,kBAAkB,EAAE,eAAe,CAAC,YAAY;QAChD,gBAAgB,EAAE,eAAe,CAAC,eAAe;QACjD,qBAAqB,EAAE,eAAe,CAAC,qBAAqB;QAC5D,kBAAkB,EAAE,eAAe,CAAC,kBAAkB;QACtD,eAAe,EAAE,eAAe,CAAC,eAAe;KAChD,CAAC;AACH,CAAC,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detectorLoader.d.ts","sourceRoot":"","sources":["../src/detectorLoader.ts"],"names":[],"mappings":"AAcA,KAAK,YAAY,GAAG,cAAc,mBAAmB,EAAE,OAAO,CAAC;AAE/D,eAAO,MAAM,cAAc,QAAa,OAAO,CAAC,YAAY,CAChB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detectorLoader.js","sourceRoot":"","sources":["../src/detectorLoader.ts"],"names":[],"mappings":"AAgBA,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,IAA2B,EAAE,CAC/D,CAAC,MAAM,MAAM,CAAC,mBAAmB,CAAC,CAAC,CAAC,OAAO,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,6BAA6B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,6BAA6B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"customDetectBot.test.d.ts","sourceRoot":"","sources":["../../src/tests/customDetectBot.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { ProsopoEnvError } from "@prosopo/common";
|
|
2
|
+
import { describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { withTimeout } from "../customDetectBot.js";
|
|
4
|
+
describe("withTimeout", () => {
|
|
5
|
+
it("should resolve with the promise result when promise resolves before timeout", async () => {
|
|
6
|
+
const result = "success";
|
|
7
|
+
const promise = Promise.resolve(result);
|
|
8
|
+
const response = await withTimeout(promise, 1000);
|
|
9
|
+
expect(response).toBe(result);
|
|
10
|
+
});
|
|
11
|
+
it("should reject with original error when promise rejects before timeout", async () => {
|
|
12
|
+
const errorMessage = "Original error";
|
|
13
|
+
const promise = Promise.reject(new Error(errorMessage));
|
|
14
|
+
await expect(withTimeout(promise, 1000)).rejects.toThrow(errorMessage);
|
|
15
|
+
});
|
|
16
|
+
it("should reject with timeout error when promise does not resolve within the timeout", async () => {
|
|
17
|
+
const promise = new Promise((resolve) => {
|
|
18
|
+
setTimeout(resolve, 500);
|
|
19
|
+
});
|
|
20
|
+
vi.useFakeTimers();
|
|
21
|
+
const timeoutPromise = withTimeout(promise, 100);
|
|
22
|
+
vi.advanceTimersByTime(200);
|
|
23
|
+
await expect(timeoutPromise).rejects.toThrow(ProsopoEnvError);
|
|
24
|
+
await expect(timeoutPromise).rejects.toEqual(expect.objectContaining({
|
|
25
|
+
message: "API.UNKNOWN",
|
|
26
|
+
translationKey: "API.UNKNOWN",
|
|
27
|
+
}));
|
|
28
|
+
vi.useRealTimers();
|
|
29
|
+
});
|
|
30
|
+
it("should respect the provided timeout duration", async () => {
|
|
31
|
+
vi.useFakeTimers();
|
|
32
|
+
const fastResolve = Promise.resolve("success");
|
|
33
|
+
const fastResult = withTimeout(fastResolve, 1000);
|
|
34
|
+
const slowPromise = new Promise((resolve) => {
|
|
35
|
+
setTimeout(() => resolve("slow"), 2000);
|
|
36
|
+
});
|
|
37
|
+
const slowWithTimeout = withTimeout(slowPromise, 1000);
|
|
38
|
+
vi.advanceTimersByTime(500);
|
|
39
|
+
expect(await fastResult).toBe("success");
|
|
40
|
+
vi.advanceTimersByTime(600);
|
|
41
|
+
await expect(slowWithTimeout).rejects.toThrow(ProsopoEnvError);
|
|
42
|
+
vi.useRealTimers();
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
//# sourceMappingURL=customDetectBot.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"customDetectBot.test.js","sourceRoot":"","sources":["../../src/tests/customDetectBot.test.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEpD,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC5B,EAAE,CAAC,6EAA6E,EAAE,KAAK,IAAI,EAAE;QAC5F,MAAM,MAAM,GAAG,SAAS,CAAC;QACzB,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAExC,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAElD,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC/B,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,uEAAuE,EAAE,KAAK,IAAI,EAAE;QACtF,MAAM,YAAY,GAAG,gBAAgB,CAAC;QACtC,MAAM,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC;QAExD,MAAM,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IACxE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,mFAAmF,EAAE,KAAK,IAAI,EAAE;QAClG,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,CAAC,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