@prosopo/procaptcha-frictionless 2.12.21 → 2.12.22
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 +13 -12
- package/.turbo/turbo-build$colon$tsc.log +25 -25
- package/.turbo/turbo-build.log +15 -12
- package/CHANGELOG.md +19 -0
- package/dist/ProcaptchaFrictionless.js +165 -236
- package/dist/_virtual/_rolldown/runtime.js +3 -0
- package/dist/cjs/ProcaptchaFrictionless.cjs +166 -259
- package/dist/cjs/customDetectBot.cjs +102 -137
- package/dist/cjs/detectorLoader.cjs +3 -25
- package/dist/cjs/index.cjs +2 -3
- package/dist/cjs/sessionInvalidatedRecovery.cjs +43 -16
- package/dist/customDetectBot.js +101 -137
- package/dist/detectorLoader.js +4 -4
- package/dist/index.js +2 -3
- package/dist/sessionInvalidatedRecovery.js +44 -18
- package/dist/tests/customDetectBotSimd.test.js +5 -3
- package/dist/tests/customDetectBotSimd.test.js.map +1 -1
- package/package.json +14 -14
- package/src/tests/customDetectBotSimd.test.ts +8 -3
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,263 +1,170 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
const require_customDetectBot = require("./customDetectBot.cjs");
|
|
2
|
+
const require_sessionInvalidatedRecovery = require("./sessionInvalidatedRecovery.cjs");
|
|
3
|
+
let _prosopo_locale = require("@prosopo/locale");
|
|
4
|
+
let _prosopo_procaptcha_common = require("@prosopo/procaptcha-common");
|
|
5
|
+
let _prosopo_types = require("@prosopo/types");
|
|
6
|
+
let _prosopo_widget_skeleton = require("@prosopo/widget-skeleton");
|
|
7
|
+
let react = require("react");
|
|
8
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
9
|
+
//#region src/ProcaptchaFrictionless.tsx
|
|
10
|
+
var ProcaptchaLoader = async () => (await import("@prosopo/procaptcha-react")).Procaptcha;
|
|
11
|
+
var ProcaptchaPuzzleLoader = async () => (await import("@prosopo/procaptcha-puzzle")).ProcaptchaPuzzle;
|
|
12
|
+
var ProcaptchaPowLoader = async () => (await import("@prosopo/procaptcha-pow")).ProcaptchaPow;
|
|
13
|
+
var renderPlaceholder = (theme, mode, errorMessage, isTranslationLoaded, translationFn, loading) => {
|
|
14
|
+
const checkboxTheme = "light" === theme ? _prosopo_widget_skeleton.lightTheme : _prosopo_widget_skeleton.darkTheme;
|
|
15
|
+
if (mode === "invisible") return null;
|
|
16
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_prosopo_procaptcha_common.Checkbox, {
|
|
17
|
+
theme: checkboxTheme,
|
|
18
|
+
onChange: async () => {},
|
|
19
|
+
checked: false,
|
|
20
|
+
labelText: isTranslationLoaded ? translationFn("WIDGET.I_AM_HUMAN") : "",
|
|
21
|
+
error: errorMessage,
|
|
22
|
+
"aria-label": "human checkbox",
|
|
23
|
+
loading
|
|
24
|
+
});
|
|
15
25
|
};
|
|
16
|
-
var
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
));
|
|
24
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
25
|
-
const jsxRuntime = require("react/jsx-runtime");
|
|
26
|
-
const locale = require("@prosopo/locale");
|
|
27
|
-
const procaptchaCommon = require("@prosopo/procaptcha-common");
|
|
28
|
-
const types = require("@prosopo/types");
|
|
29
|
-
const widgetSkeleton = require("@prosopo/widget-skeleton");
|
|
30
|
-
const react = require("react");
|
|
31
|
-
const customDetectBot = require("./customDetectBot.cjs");
|
|
32
|
-
const sessionInvalidatedRecovery = require("./sessionInvalidatedRecovery.cjs");
|
|
33
|
-
const ProcaptchaLoader = async () => (await import("@prosopo/procaptcha-react")).Procaptcha;
|
|
34
|
-
const ProcaptchaPuzzleLoader = async () => (await import("@prosopo/procaptcha-puzzle")).ProcaptchaPuzzle;
|
|
35
|
-
const ProcaptchaPowLoader = async () => (await import("@prosopo/procaptcha-pow")).ProcaptchaPow;
|
|
36
|
-
const renderPlaceholder = (theme, mode, errorMessage, isTranslationLoaded, translationFn, loading) => {
|
|
37
|
-
const checkboxTheme = "light" === theme ? widgetSkeleton.lightTheme : widgetSkeleton.darkTheme;
|
|
38
|
-
if (mode === "invisible") {
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
42
|
-
procaptchaCommon.Checkbox,
|
|
43
|
-
{
|
|
44
|
-
theme: checkboxTheme,
|
|
45
|
-
onChange: async () => {
|
|
46
|
-
},
|
|
47
|
-
checked: false,
|
|
48
|
-
labelText: isTranslationLoaded ? translationFn("WIDGET.I_AM_HUMAN") : "",
|
|
49
|
-
error: errorMessage,
|
|
50
|
-
"aria-label": "human checkbox",
|
|
51
|
-
loading
|
|
52
|
-
}
|
|
53
|
-
);
|
|
54
|
-
};
|
|
55
|
-
const defaultLoadingState = (attemptCount) => ({
|
|
56
|
-
loading: false,
|
|
57
|
-
attemptCount: attemptCount || 0
|
|
26
|
+
var defaultLoadingState = (attemptCount) => ({
|
|
27
|
+
loading: false,
|
|
28
|
+
attemptCount: attemptCount || 0
|
|
58
29
|
});
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
if (!procaptchaCommon.isSecureBrowserContext()) {
|
|
198
|
-
const errorMessage = i18n.isInitialized ? i18n.t("WIDGET.INSECURE_CONTEXT") : "Procaptcha requires a secure (HTTPS) connection";
|
|
199
|
-
events.onError(new Error(errorMessage));
|
|
200
|
-
fallOverWithStyle(errorMessage, "WIDGET.INSECURE_CONTEXT");
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
203
|
-
await procaptchaCommon.providerRetry(
|
|
204
|
-
async () => {
|
|
205
|
-
stateRef.current.attemptCount += 1;
|
|
206
|
-
const configOutput = types.ProcaptchaConfigSchema.parse(config);
|
|
207
|
-
const result = await detectBot(configOutput, container, restart, {
|
|
208
|
-
attempt: stateRef.current.attemptCount
|
|
209
|
-
});
|
|
210
|
-
if (result.error?.message) {
|
|
211
|
-
stateRef.current = {
|
|
212
|
-
...stateRef.current,
|
|
213
|
-
loading: false,
|
|
214
|
-
errorMessage: result.error?.message
|
|
215
|
-
};
|
|
216
|
-
events.onError(new Error(result.error?.message));
|
|
217
|
-
fallOverWithStyle(result.error?.message, result.error?.key);
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
const frictionlessState = {
|
|
221
|
-
provider: result.provider,
|
|
222
|
-
sessionId: result.sessionId,
|
|
223
|
-
userAccount: result.userAccount,
|
|
224
|
-
restart,
|
|
225
|
-
// Pass restart function
|
|
226
|
-
behaviorCollector1: result.behaviorCollector1,
|
|
227
|
-
behaviorCollector2: result.behaviorCollector2,
|
|
228
|
-
behaviorCollector3: result.behaviorCollector3,
|
|
229
|
-
deviceCapability: result.deviceCapability,
|
|
230
|
-
encryptBehavioralData: result.encryptBehavioralData,
|
|
231
|
-
getSimdReadings: result.getSimdReadings,
|
|
232
|
-
hp: result.hp
|
|
233
|
-
};
|
|
234
|
-
await renderForCaptchaType(result.captchaType, frictionlessState);
|
|
235
|
-
stateRef.current = {
|
|
236
|
-
...stateRef.current,
|
|
237
|
-
loading: false
|
|
238
|
-
};
|
|
239
|
-
},
|
|
240
|
-
start,
|
|
241
|
-
resetState,
|
|
242
|
-
stateRef.current.attemptCount,
|
|
243
|
-
5
|
|
244
|
-
).finally(() => {
|
|
245
|
-
if (stateRef.current.attemptCount >= 5) {
|
|
246
|
-
fallOverWithStyle();
|
|
247
|
-
restartComponentTimeout();
|
|
248
|
-
}
|
|
249
|
-
});
|
|
250
|
-
};
|
|
251
|
-
const startedForKeyRef = react.useRef(null);
|
|
252
|
-
react.useEffect(() => {
|
|
253
|
-
const key = `${config.account?.address ?? ""}|${config.language ?? ""}|${config.mode ?? ""}`;
|
|
254
|
-
if (startedForKeyRef.current === key) return;
|
|
255
|
-
startedForKeyRef.current = key;
|
|
256
|
-
void start();
|
|
257
|
-
}, [config.account?.address, config.language, config.mode]);
|
|
258
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
259
|
-
/* @__PURE__ */ jsxRuntime.jsx(procaptchaCommon.TestModeBanner, { siteKey: config.account?.address ?? "" }),
|
|
260
|
-
componentToRender
|
|
261
|
-
] });
|
|
30
|
+
var ProcaptchaFrictionless = ({ config, callbacks, restart, i18n, detectBot = require_customDetectBot.default, container }) => {
|
|
31
|
+
const stateRef = (0, react.useRef)(defaultLoadingState(0));
|
|
32
|
+
const events = (0, _prosopo_procaptcha_common.getDefaultEvents)(callbacks);
|
|
33
|
+
const pendingRetryCoordsRef = (0, react.useRef)(null);
|
|
34
|
+
const sessionInvalidatedFiredRef = (0, react.useRef)(false);
|
|
35
|
+
(0, react.useEffect)(() => {
|
|
36
|
+
if (!config.language) return;
|
|
37
|
+
if (i18n) {
|
|
38
|
+
if (i18n.language !== config.language) i18n.changeLanguage(config.language);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
(0, _prosopo_locale.loadI18next)(false, config.language);
|
|
42
|
+
}, [i18n, config.language]);
|
|
43
|
+
const [componentToRender, setComponentToRender] = (0, react.useState)(renderPlaceholder(config.theme, config.mode, stateRef.current.errorMessage, i18n.isInitialized, i18n.t, true));
|
|
44
|
+
const resetState = (attemptCount) => {
|
|
45
|
+
stateRef.current = defaultLoadingState(attemptCount || stateRef.current.attemptCount);
|
|
46
|
+
};
|
|
47
|
+
const fallOverWithStyle = (errorMessage, errorKey) => {
|
|
48
|
+
if (errorKey === "CAPTCHA.NO_SESSION_FOUND") setTimeout(() => {
|
|
49
|
+
restartComponentTimeout();
|
|
50
|
+
}, 0);
|
|
51
|
+
setComponentToRender(renderPlaceholder(config.theme, config.mode, errorMessage || "Cannot load CAPTCHA", i18n.isInitialized, i18n.t, false));
|
|
52
|
+
};
|
|
53
|
+
const restartComponentTimeout = () => {
|
|
54
|
+
setTimeout(() => {
|
|
55
|
+
resetState(0);
|
|
56
|
+
events.onReset();
|
|
57
|
+
restart();
|
|
58
|
+
}, 1e4);
|
|
59
|
+
};
|
|
60
|
+
const renderForCaptchaType = async (captchaType, frictionlessState, autoStart = false, escalationCoords) => {
|
|
61
|
+
const onEscalate = (next, newSessionId, coords) => {
|
|
62
|
+
renderForCaptchaType(next, {
|
|
63
|
+
...frictionlessState,
|
|
64
|
+
sessionId: newSessionId
|
|
65
|
+
}, true, coords);
|
|
66
|
+
};
|
|
67
|
+
const onSessionInvalidated = (x, y) => {
|
|
68
|
+
const { shouldRestart } = require_sessionInvalidatedRecovery.handleSessionInvalidated(x, y, sessionInvalidatedFiredRef, pendingRetryCoordsRef);
|
|
69
|
+
if (!shouldRestart) return;
|
|
70
|
+
resetState(0);
|
|
71
|
+
start();
|
|
72
|
+
};
|
|
73
|
+
const { autoStart: resumedAutoStart, startCoords: retryStartCoords } = require_sessionInvalidatedRecovery.consumeRetryMountProps(pendingRetryCoordsRef, autoStart);
|
|
74
|
+
const startCoords = escalationCoords ?? retryStartCoords;
|
|
75
|
+
if (captchaType === _prosopo_types.CaptchaType.image) {
|
|
76
|
+
const Procaptcha = await ProcaptchaLoader();
|
|
77
|
+
setComponentToRender(/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Procaptcha, {
|
|
78
|
+
config,
|
|
79
|
+
callbacks,
|
|
80
|
+
frictionlessState,
|
|
81
|
+
i18n,
|
|
82
|
+
autoStart: resumedAutoStart,
|
|
83
|
+
startCoords,
|
|
84
|
+
onSessionInvalidated
|
|
85
|
+
}));
|
|
86
|
+
} else if (captchaType === _prosopo_types.CaptchaType.puzzle) {
|
|
87
|
+
const ProcaptchaPuzzle = await ProcaptchaPuzzleLoader();
|
|
88
|
+
setComponentToRender(/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ProcaptchaPuzzle, {
|
|
89
|
+
config,
|
|
90
|
+
callbacks,
|
|
91
|
+
frictionlessState,
|
|
92
|
+
i18n,
|
|
93
|
+
autoStart: resumedAutoStart,
|
|
94
|
+
startCoords,
|
|
95
|
+
onSessionInvalidated
|
|
96
|
+
}));
|
|
97
|
+
} else {
|
|
98
|
+
const ProcaptchaPow = await ProcaptchaPowLoader();
|
|
99
|
+
setComponentToRender(/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ProcaptchaPow, {
|
|
100
|
+
config,
|
|
101
|
+
callbacks,
|
|
102
|
+
frictionlessState,
|
|
103
|
+
i18n,
|
|
104
|
+
onEscalate,
|
|
105
|
+
autoStart: resumedAutoStart,
|
|
106
|
+
startCoords,
|
|
107
|
+
onSessionInvalidated
|
|
108
|
+
}));
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
const start = async () => {
|
|
112
|
+
if (!(0, _prosopo_procaptcha_common.isSecureBrowserContext)()) {
|
|
113
|
+
const errorMessage = i18n.isInitialized ? i18n.t("WIDGET.INSECURE_CONTEXT") : "Procaptcha requires a secure (HTTPS) connection";
|
|
114
|
+
events.onError(new Error(errorMessage));
|
|
115
|
+
fallOverWithStyle(errorMessage, "WIDGET.INSECURE_CONTEXT");
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
await (0, _prosopo_procaptcha_common.providerRetry)(async () => {
|
|
119
|
+
stateRef.current.attemptCount += 1;
|
|
120
|
+
const result = await detectBot(_prosopo_types.ProcaptchaConfigSchema.parse(config), container, restart, { attempt: stateRef.current.attemptCount });
|
|
121
|
+
if (result.error?.message) {
|
|
122
|
+
stateRef.current = {
|
|
123
|
+
...stateRef.current,
|
|
124
|
+
loading: false,
|
|
125
|
+
errorMessage: result.error?.message
|
|
126
|
+
};
|
|
127
|
+
events.onError(new Error(result.error?.message));
|
|
128
|
+
fallOverWithStyle(result.error?.message, result.error?.key);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const frictionlessState = {
|
|
132
|
+
provider: result.provider,
|
|
133
|
+
sessionId: result.sessionId,
|
|
134
|
+
userAccount: result.userAccount,
|
|
135
|
+
restart,
|
|
136
|
+
behaviorCollector1: result.behaviorCollector1,
|
|
137
|
+
behaviorCollector2: result.behaviorCollector2,
|
|
138
|
+
behaviorCollector3: result.behaviorCollector3,
|
|
139
|
+
deviceCapability: result.deviceCapability,
|
|
140
|
+
encryptBehavioralData: result.encryptBehavioralData,
|
|
141
|
+
getSimdReadings: result.getSimdReadings,
|
|
142
|
+
hp: result.hp
|
|
143
|
+
};
|
|
144
|
+
await renderForCaptchaType(result.captchaType, frictionlessState);
|
|
145
|
+
stateRef.current = {
|
|
146
|
+
...stateRef.current,
|
|
147
|
+
loading: false
|
|
148
|
+
};
|
|
149
|
+
}, start, resetState, stateRef.current.attemptCount, 5).finally(() => {
|
|
150
|
+
if (stateRef.current.attemptCount >= 5) {
|
|
151
|
+
fallOverWithStyle();
|
|
152
|
+
restartComponentTimeout();
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
|
+
const startedForKeyRef = (0, react.useRef)(null);
|
|
157
|
+
(0, react.useEffect)(() => {
|
|
158
|
+
const key = `${config.account?.address ?? ""}|${config.language ?? ""}|${config.mode ?? ""}`;
|
|
159
|
+
if (startedForKeyRef.current === key) return;
|
|
160
|
+
startedForKeyRef.current = key;
|
|
161
|
+
start();
|
|
162
|
+
}, [
|
|
163
|
+
config.account?.address,
|
|
164
|
+
config.language,
|
|
165
|
+
config.mode
|
|
166
|
+
]);
|
|
167
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_prosopo_procaptcha_common.TestModeBanner, { siteKey: config.account?.address ?? "" }), componentToRender] });
|
|
262
168
|
};
|
|
169
|
+
//#endregion
|
|
263
170
|
exports.ProcaptchaFrictionless = ProcaptchaFrictionless;
|