@prosopo/procaptcha-pow 2.10.22 → 2.10.24
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 -10
- package/.turbo/turbo-build$colon$tsc.log +19 -19
- package/.turbo/turbo-build.log +14 -11
- package/CHANGELOG.md +44 -0
- package/dist/_virtual/_rolldown/runtime.js +3 -0
- package/dist/cjs/components/ProcaptchaPoW.cjs +6 -9
- package/dist/cjs/components/ProcaptchaWidget.cjs +109 -127
- package/dist/cjs/index.cjs +2 -4
- package/dist/cjs/services/Manager.cjs +193 -277
- package/dist/components/ProcaptchaPoW.js +6 -8
- package/dist/components/ProcaptchaWidget.js +109 -127
- package/dist/index.js +2 -4
- package/dist/services/Manager.d.ts.map +1 -1
- package/dist/services/Manager.js +189 -274
- package/dist/services/Manager.js.map +1 -1
- package/package.json +12 -12
- package/src/services/Manager.ts +5 -4
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,129 +1,111 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useTranslation, loadI18next } from "@prosopo/locale";
|
|
3
|
-
import { useProcaptcha, buildUpdateState, Honeypot, Checkbox } from "@prosopo/procaptcha-common";
|
|
4
|
-
import { ModeEnum } from "@prosopo/types";
|
|
5
|
-
import { lightTheme, darkTheme } from "@prosopo/widget-skeleton";
|
|
6
|
-
import { useState, useRef, useEffect } from "react";
|
|
1
|
+
import "../_virtual/_rolldown/runtime.js";
|
|
7
2
|
import { Manager } from "../services/Manager.js";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
lastCoordsRef.current = { x, y };
|
|
116
|
-
await manager.current.start(x, y);
|
|
117
|
-
setLoading(false);
|
|
118
|
-
},
|
|
119
|
-
labelText: isTranslationReady ? t("WIDGET.I_AM_HUMAN") : "",
|
|
120
|
-
error: state.error?.message,
|
|
121
|
-
"aria-label": "human checkbox",
|
|
122
|
-
loading
|
|
123
|
-
}
|
|
124
|
-
)
|
|
125
|
-
] });
|
|
126
|
-
};
|
|
127
|
-
export {
|
|
128
|
-
Procaptcha as default
|
|
3
|
+
import { loadI18next, useTranslation } from "@prosopo/locale";
|
|
4
|
+
import { Checkbox, Honeypot, buildUpdateState, useProcaptcha } from "@prosopo/procaptcha-common";
|
|
5
|
+
import { ModeEnum } from "@prosopo/types";
|
|
6
|
+
import { darkTheme, lightTheme } from "@prosopo/widget-skeleton";
|
|
7
|
+
import { useEffect, useRef, useState } from "react";
|
|
8
|
+
import { Fragment, jsx, jsxs } from "@emotion/react/jsx-runtime";
|
|
9
|
+
//#region src/components/ProcaptchaWidget.tsx
|
|
10
|
+
var PROCAPTCHA_EXECUTE_EVENT = "procaptcha:execute";
|
|
11
|
+
var Procaptcha = (props) => {
|
|
12
|
+
const { t, ready: isTranslationReady } = useTranslation();
|
|
13
|
+
const config = props.config;
|
|
14
|
+
const i18n = props.i18n;
|
|
15
|
+
const theme = "light" === config.theme ? lightTheme : darkTheme;
|
|
16
|
+
const frictionlessState = props.frictionlessState;
|
|
17
|
+
const callbacks = props.callbacks || {};
|
|
18
|
+
const [state, _updateState] = useProcaptcha(useState, useRef);
|
|
19
|
+
const [loading, setLoading] = useState(false);
|
|
20
|
+
const updateState = buildUpdateState(state, _updateState);
|
|
21
|
+
const hpRef = useRef(null);
|
|
22
|
+
const manager = useRef(Manager(config, state, updateState, callbacks, frictionlessState, props.onEscalate, () => hpRef.current?.value || void 0));
|
|
23
|
+
const lastCoordsRef = useRef(null);
|
|
24
|
+
const sessionInvalidatedFiredRef = useRef(false);
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (!config.language) return;
|
|
27
|
+
if (i18n) {
|
|
28
|
+
if (i18n.language !== config.language) i18n.changeLanguage(config.language);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
loadI18next(false, config.language);
|
|
32
|
+
}, [i18n, config.language]);
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
if (!props.autoStart) return;
|
|
35
|
+
setLoading(true);
|
|
36
|
+
const coords = props.startCoords;
|
|
37
|
+
lastCoordsRef.current = coords ?? null;
|
|
38
|
+
manager.current.start(coords?.x ?? 0, coords?.y ?? 0).finally(() => {
|
|
39
|
+
setLoading(false);
|
|
40
|
+
});
|
|
41
|
+
}, [props.autoStart, props.startCoords]);
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
if (!state.error) return;
|
|
44
|
+
setLoading(false);
|
|
45
|
+
if (state.error.key !== "CAPTCHA.NO_SESSION_FOUND") return;
|
|
46
|
+
if (props.onSessionInvalidated && !sessionInvalidatedFiredRef.current) {
|
|
47
|
+
sessionInvalidatedFiredRef.current = true;
|
|
48
|
+
const coords = lastCoordsRef.current;
|
|
49
|
+
props.onSessionInvalidated(coords?.x, coords?.y);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (frictionlessState) setTimeout(() => {
|
|
53
|
+
frictionlessState.restart();
|
|
54
|
+
}, 100);
|
|
55
|
+
}, [
|
|
56
|
+
state.error,
|
|
57
|
+
frictionlessState,
|
|
58
|
+
props.onSessionInvalidated
|
|
59
|
+
]);
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
if (config.mode === ModeEnum.invisible) {
|
|
62
|
+
const handleExecuteEvent = (event) => {
|
|
63
|
+
try {
|
|
64
|
+
manager.current.start();
|
|
65
|
+
} catch (error) {
|
|
66
|
+
console.error("Error starting PoW verification:", error);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
document.addEventListener(PROCAPTCHA_EXECUTE_EVENT, handleExecuteEvent);
|
|
70
|
+
return () => {
|
|
71
|
+
document.removeEventListener(PROCAPTCHA_EXECUTE_EVENT, handleExecuteEvent);
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
return () => {};
|
|
75
|
+
}, [config.mode]);
|
|
76
|
+
const honeypot = frictionlessState?.hp ? /* @__PURE__ */ jsx(Honeypot, {
|
|
77
|
+
ref: hpRef,
|
|
78
|
+
encodedQuestion: frictionlessState.hp
|
|
79
|
+
}) : null;
|
|
80
|
+
if (config.mode === ModeEnum.invisible) return honeypot;
|
|
81
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [honeypot, /* @__PURE__ */ jsx(Checkbox, {
|
|
82
|
+
checked: state.isHuman,
|
|
83
|
+
theme,
|
|
84
|
+
onChange: async (event) => {
|
|
85
|
+
if (loading) return;
|
|
86
|
+
setLoading(true);
|
|
87
|
+
let x = 0;
|
|
88
|
+
let y = 0;
|
|
89
|
+
const mouseOrTouchEvent = event.nativeEvent;
|
|
90
|
+
if (!mouseOrTouchEvent.isTrusted) {} else if ("touches" in mouseOrTouchEvent && mouseOrTouchEvent.touches.length > 0 && mouseOrTouchEvent.touches[0]) {
|
|
91
|
+
x = mouseOrTouchEvent.touches[0].clientX;
|
|
92
|
+
y = mouseOrTouchEvent.touches[0].clientY;
|
|
93
|
+
} else if ("clientX" in mouseOrTouchEvent && "clientY" in mouseOrTouchEvent) {
|
|
94
|
+
x = mouseOrTouchEvent.clientX;
|
|
95
|
+
y = mouseOrTouchEvent.clientY;
|
|
96
|
+
}
|
|
97
|
+
lastCoordsRef.current = {
|
|
98
|
+
x,
|
|
99
|
+
y
|
|
100
|
+
};
|
|
101
|
+
await manager.current.start(x, y);
|
|
102
|
+
setLoading(false);
|
|
103
|
+
},
|
|
104
|
+
labelText: isTranslationReady ? t("WIDGET.I_AM_HUMAN") : "",
|
|
105
|
+
error: state.error?.message,
|
|
106
|
+
"aria-label": "human checkbox",
|
|
107
|
+
loading
|
|
108
|
+
})] });
|
|
129
109
|
};
|
|
110
|
+
//#endregion
|
|
111
|
+
export { Procaptcha as default };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Manager.d.ts","sourceRoot":"","sources":["../../src/services/Manager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Manager.d.ts","sourceRoot":"","sources":["../../src/services/Manager.ts"],"names":[],"mappings":"AA+BA,OAAO,EAIN,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EACxB,KAAK,2BAA2B,EAEhC,KAAK,2BAA2B,EAChC,KAAK,eAAe,EACpB,KAAK,uBAAuB,EAE5B,MAAM,gBAAgB,CAAC;AAKxB,eAAO,MAAM,OAAO,gBACN,2BAA2B,SACjC,eAAe,iBACP,uBAAuB,aAC3B,mBAAmB,sBACV,iBAAiB,eACxB,2BAA2B,qBAIrB,MAAM,MAAM,GAAG,SAAS;;uCAmFD,MAAM,IAAI;CAuTpD,CAAC"}
|