@prosopo/procaptcha-pow 2.10.23 → 2.10.25

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.
Files changed (47) hide show
  1. package/.turbo/turbo-build$colon$cjs.log +12 -10
  2. package/.turbo/turbo-build$colon$tsc.log +19 -19
  3. package/.turbo/turbo-build.log +14 -11
  4. package/CHANGELOG.md +46 -0
  5. package/dist/_virtual/_rolldown/runtime.js +3 -0
  6. package/dist/cjs/components/ProcaptchaPoW.cjs +6 -9
  7. package/dist/cjs/components/ProcaptchaWidget.cjs +117 -127
  8. package/dist/cjs/index.cjs +2 -4
  9. package/dist/cjs/services/Manager.cjs +193 -277
  10. package/dist/components/ProcaptchaPoW.js +6 -8
  11. package/dist/components/ProcaptchaWidget.d.ts.map +1 -1
  12. package/dist/components/ProcaptchaWidget.js +117 -127
  13. package/dist/components/ProcaptchaWidget.js.map +1 -1
  14. package/dist/index.js +2 -4
  15. package/dist/services/Manager.d.ts.map +1 -1
  16. package/dist/services/Manager.js +189 -274
  17. package/dist/services/Manager.js.map +1 -1
  18. package/dist/tests/manager.unit.test.d.ts +2 -0
  19. package/dist/tests/manager.unit.test.d.ts.map +1 -0
  20. package/dist/tests/manager.unit.test.js +752 -0
  21. package/dist/tests/manager.unit.test.js.map +1 -0
  22. package/dist/tests/managerHarness.d.ts +17 -0
  23. package/dist/tests/managerHarness.d.ts.map +1 -0
  24. package/dist/tests/managerHarness.js +70 -0
  25. package/dist/tests/managerHarness.js.map +1 -0
  26. package/dist/tests/procaptchaPoW.unit.test.d.ts +2 -0
  27. package/dist/tests/procaptchaPoW.unit.test.d.ts.map +1 -0
  28. package/dist/tests/procaptchaPoW.unit.test.js +79 -0
  29. package/dist/tests/procaptchaPoW.unit.test.js.map +1 -0
  30. package/dist/tests/procaptchaPow.test-d.d.ts +2 -0
  31. package/dist/tests/procaptchaPow.test-d.d.ts.map +1 -0
  32. package/dist/tests/procaptchaPow.test-d.js +62 -0
  33. package/dist/tests/procaptchaPow.test-d.js.map +1 -0
  34. package/dist/tests/procaptchaWidget.unit.test.d.ts +2 -0
  35. package/dist/tests/procaptchaWidget.unit.test.d.ts.map +1 -0
  36. package/dist/tests/procaptchaWidget.unit.test.js +410 -0
  37. package/dist/tests/procaptchaWidget.unit.test.js.map +1 -0
  38. package/package.json +18 -13
  39. package/src/components/ProcaptchaWidget.tsx +22 -5
  40. package/src/services/Manager.ts +9 -5
  41. package/src/tests/manager.unit.test.ts +1105 -0
  42. package/src/tests/managerHarness.ts +135 -0
  43. package/src/tests/procaptchaPoW.unit.test.ts +120 -0
  44. package/src/tests/procaptchaPow.test-d.ts +122 -0
  45. package/src/tests/procaptchaWidget.unit.test.ts +571 -0
  46. package/tsconfig.tsbuildinfo +1 -1
  47. package/vite.test.config.ts +25 -0
@@ -1,5 +1,5 @@
1
1
 
2
- > @prosopo/procaptcha-pow@2.10.23 build:cjs
2
+ > @prosopo/procaptcha-pow@2.10.25 build:cjs
3
3
  > NODE_ENV=${NODE_ENV:-development}; vite build --config vite.cjs.config.ts --mode $NODE_ENV
4
4
 
5
5
  ViteCommonJSConfig: .
@@ -39,14 +39,16 @@ ViteCommonJSConfig: .
39
39
  '@prosopo/keyring'
40
40
  ]
41
41
  }
42
- vite v6.4.1 building SSR bundle for production...
42
+ The plugin "vite-tsconfig-paths" is detected. Vite now supports tsconfig paths resolution natively via the resolve.tsconfigPaths option. You can remove the plugin and set resolve.tsconfigPaths: true in your Vite config instead.
43
+ vite v8.1.5 building ssr environment for production...
43
44
  Bundle build started
44
- transforming...
45
- Build end
46
- ✓ 4 modules transformed.
45
+ 
46
+ ✓ 5 modules transformed.
47
47
  rendering chunks...
48
- dist/cjs/index.cjs  0.25 kB
49
- dist/cjs/components/ProcaptchaPoW.cjs  0.70 kB
50
- dist/cjs/components/ProcaptchaWidget.cjs  4.57 kB
51
- dist/cjs/services/Manager.cjs 10.78 kB
52
- ✓ built in 163ms
48
+ computing gzip size...
49
+ dist/cjs/index.cjs 0.20 kB │ gzip: 0.15 kB
50
+ dist/cjs/components/ProcaptchaPoW.cjs 0.51 kB │ gzip: 0.27 kB
51
+ dist/cjs/components/ProcaptchaWidget.cjs 4.70 kB │ gzip: 1.50 kB
52
+ dist/cjs/services/Manager.cjs 9.19 kB │ gzip: 2.61 kB
53
+
54
+ ✓ built in 87ms
@@ -1,8 +1,8 @@
1
1
 
2
- > @prosopo/procaptcha-pow@2.10.23 build:tsc
2
+ > @prosopo/procaptcha-pow@2.10.25 build:tsc
3
3
  > tsc --build --verbose
4
4
 
5
- 10:22:53 PM - Projects in this build:
5
+ 12:36:38 PM - Projects in this build:
6
6
  * ../../dev/config/tsconfig.json
7
7
  * ../locale/tsconfig.json
8
8
  * ../util/tsconfig.json
@@ -20,37 +20,37 @@
20
20
  * ../procaptcha-common/tsconfig.json
21
21
  * tsconfig.json
22
22
 
23
- 10:22:53 PM - Project '../../dev/config/tsconfig.json' is up to date because newest input '../../dev/config/src/webpack/webpack.config.ts' is older than output '../../dev/config/tsconfig.tsbuildinfo'
23
+ 12:36:38 PM - Project '../../dev/config/tsconfig.json' is up to date because newest input '../../dev/config/src/webpack/index.ts' is older than output '../../dev/config/tsconfig.tsbuildinfo'
24
24
 
25
- 10:22:53 PM - Project '../locale/tsconfig.json' is up to date because newest input '../locale/src/translationKey.ts' is older than output '../locale/tsconfig.tsbuildinfo'
25
+ 12:36:38 PM - Project '../locale/tsconfig.json' is up to date because newest input '../locale/src/translationKey.ts' is older than output '../locale/tsconfig.tsbuildinfo'
26
26
 
27
- 10:22:53 PM - Project '../util/tsconfig.json' is up to date because newest input '../util/src/url.ts' is older than output '../util/tsconfig.tsbuildinfo'
27
+ 12:36:38 PM - Project '../util/tsconfig.json' is up to date because newest input '../util/src/url.ts' is older than output '../util/tsconfig.tsbuildinfo'
28
28
 
29
- 10:22:53 PM - Project '../util-crypto/tsconfig.json' is up to date because newest input '../util-crypto/src/types.ts' is older than output '../util-crypto/tsconfig.tsbuildinfo'
29
+ 12:36:38 PM - Project '../util-crypto/tsconfig.json' is up to date because newest input '../util-crypto/src/types.ts' is older than output '../util-crypto/tsconfig.tsbuildinfo'
30
30
 
31
- 10:22:53 PM - Project '../types/tsconfig.json' is up to date because newest input '../types/src/procaptcha/api.ts' is older than output '../types/tsconfig.tsbuildinfo'
31
+ 12:36:38 PM - Project '../types/tsconfig.json' is up to date because newest input '../types/src/provider/api.ts' is older than output '../types/tsconfig.tsbuildinfo'
32
32
 
33
- 10:22:53 PM - Project '../api/tsconfig.json' is up to date because newest input '../api/src/index.ts' is older than output '../api/tsconfig.tsbuildinfo'
33
+ 12:36:38 PM - Project '../api/tsconfig.json' is up to date because newest input '../api/src/tests/apiHarness.ts' is older than output '../api/tsconfig.tsbuildinfo'
34
34
 
35
- 10:22:53 PM - Project '../logger/tsconfig.json' is up to date because newest input '../logger/src/index.ts' is older than output '../logger/tsconfig.tsbuildinfo'
35
+ 12:36:38 PM - Project '../logger/tsconfig.json' is up to date because newest input '../logger/src/index.ts' is older than output '../logger/tsconfig.tsbuildinfo'
36
36
 
37
- 10:22:53 PM - Project '../common/tsconfig.json' is up to date because newest input '../common/src/error.ts' is older than output '../common/tsconfig.tsbuildinfo'
37
+ 12:36:38 PM - Project '../common/tsconfig.json' is up to date because newest input '../common/src/index.ts' is older than output '../common/tsconfig.tsbuildinfo'
38
38
 
39
- 10:22:53 PM - Project '../fingerprintjs/tsconfig.json' is up to date because newest input '../fingerprintjs/src/utils/browser.ts' is older than output '../fingerprintjs/tsconfig.tsbuildinfo'
39
+ 12:36:38 PM - Project '../fingerprintjs/tsconfig.json' is up to date because newest input '../fingerprintjs/src/utils/browser.ts' is older than output '../fingerprintjs/tsconfig.tsbuildinfo'
40
40
 
41
- 10:22:53 PM - Project '../fingerprint/tsconfig.json' is up to date because newest input '../fingerprint/src/index.ts' is older than output '../fingerprint/tsconfig.tsbuildinfo'
41
+ 12:36:38 PM - Project '../fingerprint/tsconfig.json' is up to date because newest input '../fingerprint/src/index.ts' is older than output '../fingerprint/tsconfig.tsbuildinfo'
42
42
 
43
- 10:22:53 PM - Project '../load-balancer/tsconfig.json' is up to date because newest input '../load-balancer/src/balancer.ts' is older than output '../load-balancer/tsconfig.tsbuildinfo'
43
+ 12:36:39 PM - Project '../load-balancer/tsconfig.json' is up to date because newest input '../load-balancer/src/tests/providers.unit.test.ts' is older than output '../load-balancer/tsconfig.tsbuildinfo'
44
44
 
45
- 10:22:53 PM - Project '../widget-skeleton/tsconfig.json' is up to date because newest input '../widget-skeleton/src/index.ts' is older than output '../widget-skeleton/tsconfig.tsbuildinfo'
45
+ 12:36:39 PM - Project '../widget-skeleton/tsconfig.json' is up to date because newest input '../widget-skeleton/src/webComponent/createWidget.ts' is older than output '../widget-skeleton/tsconfig.tsbuildinfo'
46
46
 
47
- 10:22:53 PM - Project '../keyring/tsconfig.json' is up to date because newest input '../keyring/src/index.ts' is older than output '../keyring/tsconfig.tsbuildinfo'
47
+ 12:36:39 PM - Project '../keyring/tsconfig.json' is up to date because newest input '../keyring/src/keyring/keyring.ts' is older than output '../keyring/tsconfig.tsbuildinfo'
48
48
 
49
- 10:22:53 PM - Project '../account/tsconfig.json' is up to date because newest input '../account/src/custom.d.ts' is older than output '../account/tsconfig.tsbuildinfo'
49
+ 12:36:39 PM - Project '../account/tsconfig.json' is up to date because newest input '../account/src/custom.d.ts' is older than output '../account/tsconfig.tsbuildinfo'
50
50
 
51
- 10:22:53 PM - Project '../procaptcha-common/tsconfig.json' is up to date because newest input '../procaptcha-common/src/reactComponents/Honeypot.tsx' is older than output '../procaptcha-common/tsconfig.tsbuildinfo'
51
+ 12:36:39 PM - Project '../procaptcha-common/tsconfig.json' is up to date because newest input '../procaptcha-common/src/simdReadings.ts' is older than output '../procaptcha-common/tsconfig.tsbuildinfo'
52
52
 
53
- 10:22:53 PM - Project 'tsconfig.json' is out of date because output file 'tsconfig.tsbuildinfo' does not exist
53
+ 12:36:39 PM - Project 'tsconfig.json' is out of date because output file 'tsconfig.tsbuildinfo' does not exist
54
54
 
55
- 10:22:53 PM - Building project '/home/runner/work/captcha/captcha/packages/procaptcha-pow/tsconfig.json'...
55
+ 12:36:39 PM - Building project '/home/runner/work/captcha/captcha/packages/procaptcha-pow/tsconfig.json'...
56
56
 
@@ -1,9 +1,9 @@
1
1
 
2
- > @prosopo/procaptcha-pow@2.10.23 build
2
+ > @prosopo/procaptcha-pow@2.10.25 build
3
3
  > npm run build:cross-env -- --mode ${NODE_ENV:-development}
4
4
 
5
5
 
6
- > @prosopo/procaptcha-pow@2.10.23 build:cross-env
6
+ > @prosopo/procaptcha-pow@2.10.25 build:cross-env
7
7
  > vite build --config vite.esm.config.ts --mode production
8
8
 
9
9
  ViteEsmConfig: .
@@ -27,6 +27,7 @@ ViteEsmConfig: .
27
27
  }
28
28
  {
29
29
  externals: [
30
+ The plugin "vite-tsconfig-paths" is detected. Vite now supports tsconfig paths resolution natively via the resolve.tsconfigPaths option. You can remove the plugin and set resolve.tsconfigPaths: true in your Vite config instead.
30
31
  '@prosopo/api',
31
32
  '@prosopo/types',
32
33
  '@prosopo/locale',
@@ -43,14 +44,16 @@ ViteEsmConfig: .
43
44
  '@prosopo/keyring'
44
45
  ]
45
46
  }
46
- vite v6.4.1 building SSR bundle for production...
47
+ vite v8.1.5 building ssr environment for production...
47
48
  Bundle build started
48
- transforming...
49
- Build end
50
- ✓ 4 modules transformed.
49
+ 
50
+ ✓ 5 modules transformed.
51
51
  rendering chunks...
52
- dist/index.js  0.13 kB
53
- dist/components/ProcaptchaPoW.js  0.33 kB
54
- dist/components/ProcaptchaWidget.js  4.41 kB
55
- dist/services/Manager.js 10.61 kB
56
- ✓ built in 180ms
52
+ computing gzip size...
53
+ dist/_virtual/_rolldown/runtime.js 0.04 kB │ gzip: 0.06 kB
54
+ dist/index.js 0.13 kB │ gzip: 0.11 kB
55
+ dist/components/ProcaptchaPoW.js 0.37 kB │ gzip: 0.23 kB
56
+ dist/components/ProcaptchaWidget.js 4.30 kB │ gzip: 1.48 kB
57
+ dist/services/Manager.js 8.54 kB │ gzip: 2.57 kB
58
+
59
+ ✓ built in 83ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,51 @@
1
1
  # @prosopo/procaptcha-pow
2
2
 
3
+ ## 2.10.25
4
+ ### Patch Changes
5
+
6
+ - 34f902a: Remove the undeclared `@prosopo/load-balancer` import from the manager unit test, deriving `IpMode` from `procaptcha-common`'s `pickIpMode` instead so `lint:refs` passes.
7
+ - 9c55bcb: Add unit and type tests for the PoW widget and Manager, and fix the defects they exposed:
8
+
9
+ - a retried solve restarted at coordinates (0, 0), losing the real click telemetry an escalated widget depends on
10
+ - three paths in `ProcaptchaWidget` (checkbox change, autoStart effect, `procaptcha:execute` handler) let a rejected `manager.start()` escape as an unhandled rejection, leaving the spinner running
11
+ - Updated dependencies [1e0cf14]
12
+ - @prosopo/api@3.5.21
13
+
14
+ ## 2.10.24
15
+ ### Patch Changes
16
+
17
+ - ab3499c: feat(procaptcha): block on SIMD readings at solution submit
18
+
19
+ Solution submit is the last hop the client controls, so it's the last chance to
20
+ attach the catcher's WASM SIMD readings for a session. The image, PoW and puzzle
21
+ managers now wait for the benchmark there via a shared
22
+ `getSimdReadingsForSubmit` helper, capped at 5s, instead of attaching only
23
+ whatever the prefetch happened to have resolved.
24
+
25
+ The helper passes the budget down to the detector *and* races it locally — the
26
+ detector ships prebuilt, so a bundle that ignores `timeoutMs` (or a benchmark
27
+ wedged on a busy main thread) can't hang the submission. It never rejects: a
28
+ missing accessor, a rejection, a synchronous throw and a timeout all resolve to
29
+ `undefined` and the solution is submitted without readings, so a user is never
30
+ failed over telemetry.
31
+
32
+ The earlier frictionless POST and challenge GET hops are unchanged and remain
33
+ non-blocking.
34
+ - e14fce6: chore(deps): bump vite to 6.4.3 and mongoose to 8.24.1, and adjust types for the mongoose 8.24 Document/ObjectId changes
35
+ - Updated dependencies [2c47bb7]
36
+ - Updated dependencies [ab3499c]
37
+ - Updated dependencies [0e1171c]
38
+ - Updated dependencies [103318c]
39
+ - Updated dependencies [270a8d8]
40
+ - Updated dependencies [e14fce6]
41
+ - @prosopo/util@3.3.5
42
+ - @prosopo/procaptcha-common@2.11.18
43
+ - @prosopo/locale@3.2.8
44
+ - @prosopo/types@4.10.0
45
+ - @prosopo/api@3.5.20
46
+ - @prosopo/common@3.1.48
47
+ - @prosopo/fingerprint@2.7.19
48
+
3
49
  ## 2.10.23
4
50
  ### Patch Changes
5
51
 
@@ -0,0 +1,3 @@
1
+ import "node:module";
2
+ //#endregion
3
+ export {};
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const jsxRuntime = require("@emotion/react/jsx-runtime");
4
- const react = require("react");
5
- const _interopNamespaceDefaultOnly = (e) => Object.freeze(Object.defineProperty({ __proto__: null, default: e }, Symbol.toStringTag, { value: "Module" }));
6
- const ProcaptchaWidget = react.lazy(
7
- async () => Promise.resolve().then(() => /* @__PURE__ */ _interopNamespaceDefaultOnly(require("./ProcaptchaWidget.cjs")))
8
- );
9
- const ProcaptchaPow = (props) => /* @__PURE__ */ jsxRuntime.jsx(react.Suspense, { children: /* @__PURE__ */ jsxRuntime.jsx(ProcaptchaWidget, { ...props }) });
1
+ let react = require("react");
2
+ let _emotion_react_jsx_runtime = require("@emotion/react/jsx-runtime");
3
+ //#region src/components/ProcaptchaPoW.tsx
4
+ var ProcaptchaWidget = (0, react.lazy)(async () => Promise.resolve().then(() => require("./ProcaptchaWidget.cjs")));
5
+ var ProcaptchaPow = (props) => /* @__PURE__ */ (0, _emotion_react_jsx_runtime.jsx)(react.Suspense, { children: /* @__PURE__ */ (0, _emotion_react_jsx_runtime.jsx)(ProcaptchaWidget, { ...props }) });
6
+ //#endregion
10
7
  exports.ProcaptchaPow = ProcaptchaPow;
@@ -1,128 +1,118 @@
1
- "use strict";
2
- const jsxRuntime = require("@emotion/react/jsx-runtime");
3
- const locale = require("@prosopo/locale");
4
- const procaptchaCommon = require("@prosopo/procaptcha-common");
5
- const types = require("@prosopo/types");
6
- const widgetSkeleton = require("@prosopo/widget-skeleton");
7
- const react = require("react");
8
- const Manager = require("../services/Manager.cjs");
9
- const PROCAPTCHA_EXECUTE_EVENT = "procaptcha:execute";
10
- const Procaptcha = (props) => {
11
- const { t, ready: isTranslationReady } = locale.useTranslation();
12
- const config = props.config;
13
- const i18n = props.i18n;
14
- const theme = "light" === config.theme ? widgetSkeleton.lightTheme : widgetSkeleton.darkTheme;
15
- const frictionlessState = props.frictionlessState;
16
- const callbacks = props.callbacks || {};
17
- const [state, _updateState] = procaptchaCommon.useProcaptcha(react.useState, react.useRef);
18
- const [loading, setLoading] = react.useState(false);
19
- const updateState = procaptchaCommon.buildUpdateState(state, _updateState);
20
- const hpRef = react.useRef(null);
21
- const manager = react.useRef(
22
- Manager.Manager(
23
- config,
24
- state,
25
- updateState,
26
- callbacks,
27
- frictionlessState,
28
- props.onEscalate,
29
- () => hpRef.current?.value || void 0
30
- )
31
- );
32
- const lastCoordsRef = react.useRef(null);
33
- const sessionInvalidatedFiredRef = react.useRef(false);
34
- react.useEffect(() => {
35
- if (!config.language) return;
36
- if (i18n) {
37
- if (i18n.language !== config.language) {
38
- void i18n.changeLanguage(config.language);
39
- }
40
- return;
41
- }
42
- void locale.loadI18next(false, config.language);
43
- }, [i18n, config.language]);
44
- react.useEffect(() => {
45
- if (!props.autoStart) return;
46
- setLoading(true);
47
- const coords = props.startCoords;
48
- lastCoordsRef.current = coords ?? null;
49
- manager.current.start(coords?.x ?? 0, coords?.y ?? 0).finally(() => {
50
- setLoading(false);
51
- });
52
- }, [props.autoStart, props.startCoords]);
53
- react.useEffect(() => {
54
- if (!state.error) return;
55
- setLoading(false);
56
- if (state.error.key !== "CAPTCHA.NO_SESSION_FOUND") return;
57
- if (props.onSessionInvalidated && !sessionInvalidatedFiredRef.current) {
58
- sessionInvalidatedFiredRef.current = true;
59
- const coords = lastCoordsRef.current;
60
- props.onSessionInvalidated(coords?.x, coords?.y);
61
- return;
62
- }
63
- if (frictionlessState) {
64
- setTimeout(() => {
65
- frictionlessState.restart();
66
- }, 100);
67
- }
68
- }, [state.error, frictionlessState, props.onSessionInvalidated]);
69
- react.useEffect(() => {
70
- if (config.mode === types.ModeEnum.invisible) {
71
- const handleExecuteEvent = (event) => {
72
- try {
73
- manager.current.start();
74
- } catch (error) {
75
- console.error("Error starting PoW verification:", error);
76
- }
77
- };
78
- document.addEventListener(PROCAPTCHA_EXECUTE_EVENT, handleExecuteEvent);
79
- return () => {
80
- document.removeEventListener(
81
- PROCAPTCHA_EXECUTE_EVENT,
82
- handleExecuteEvent
83
- );
84
- };
85
- }
86
- return () => {
87
- };
88
- }, [config.mode]);
89
- const honeypot = frictionlessState?.hp ? /* @__PURE__ */ jsxRuntime.jsx(procaptchaCommon.Honeypot, { ref: hpRef, encodedQuestion: frictionlessState.hp }) : null;
90
- if (config.mode === types.ModeEnum.invisible) {
91
- return honeypot;
92
- }
93
- return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
94
- honeypot,
95
- /* @__PURE__ */ jsxRuntime.jsx(
96
- procaptchaCommon.Checkbox,
97
- {
98
- checked: state.isHuman,
99
- theme,
100
- onChange: async (event) => {
101
- if (loading) {
102
- return;
103
- }
104
- setLoading(true);
105
- let x = 0;
106
- let y = 0;
107
- const mouseOrTouchEvent = event.nativeEvent;
108
- if (!mouseOrTouchEvent.isTrusted) {
109
- } else if ("touches" in mouseOrTouchEvent && mouseOrTouchEvent.touches.length > 0 && mouseOrTouchEvent.touches[0]) {
110
- x = mouseOrTouchEvent.touches[0].clientX;
111
- y = mouseOrTouchEvent.touches[0].clientY;
112
- } else if ("clientX" in mouseOrTouchEvent && "clientY" in mouseOrTouchEvent) {
113
- x = mouseOrTouchEvent.clientX;
114
- y = mouseOrTouchEvent.clientY;
115
- }
116
- lastCoordsRef.current = { x, y };
117
- await manager.current.start(x, y);
118
- setLoading(false);
119
- },
120
- labelText: isTranslationReady ? t("WIDGET.I_AM_HUMAN") : "",
121
- error: state.error?.message,
122
- "aria-label": "human checkbox",
123
- loading
124
- }
125
- )
126
- ] });
1
+ const require_Manager = require("../services/Manager.cjs");
2
+ let _prosopo_locale = require("@prosopo/locale");
3
+ let _prosopo_procaptcha_common = require("@prosopo/procaptcha-common");
4
+ let _prosopo_types = require("@prosopo/types");
5
+ let _prosopo_widget_skeleton = require("@prosopo/widget-skeleton");
6
+ let react = require("react");
7
+ let _emotion_react_jsx_runtime = require("@emotion/react/jsx-runtime");
8
+ //#region src/components/ProcaptchaWidget.tsx
9
+ var PROCAPTCHA_EXECUTE_EVENT = "procaptcha:execute";
10
+ var Procaptcha = (props) => {
11
+ const { t, ready: isTranslationReady } = (0, _prosopo_locale.useTranslation)();
12
+ const config = props.config;
13
+ const i18n = props.i18n;
14
+ const theme = "light" === config.theme ? _prosopo_widget_skeleton.lightTheme : _prosopo_widget_skeleton.darkTheme;
15
+ const frictionlessState = props.frictionlessState;
16
+ const callbacks = props.callbacks || {};
17
+ const [state, _updateState] = (0, _prosopo_procaptcha_common.useProcaptcha)(react.useState, react.useRef);
18
+ const [loading, setLoading] = (0, react.useState)(false);
19
+ const updateState = (0, _prosopo_procaptcha_common.buildUpdateState)(state, _updateState);
20
+ const hpRef = (0, react.useRef)(null);
21
+ const manager = (0, react.useRef)(require_Manager.Manager(config, state, updateState, callbacks, frictionlessState, props.onEscalate, () => hpRef.current?.value || void 0));
22
+ const lastCoordsRef = (0, react.useRef)(null);
23
+ const sessionInvalidatedFiredRef = (0, react.useRef)(false);
24
+ (0, react.useEffect)(() => {
25
+ if (!config.language) return;
26
+ if (i18n) {
27
+ if (i18n.language !== config.language) i18n.changeLanguage(config.language);
28
+ return;
29
+ }
30
+ (0, _prosopo_locale.loadI18next)(false, config.language);
31
+ }, [i18n, config.language]);
32
+ (0, react.useEffect)(() => {
33
+ if (!props.autoStart) return;
34
+ setLoading(true);
35
+ const coords = props.startCoords;
36
+ lastCoordsRef.current = coords ?? null;
37
+ manager.current.start(coords?.x ?? 0, coords?.y ?? 0).catch((error) => {
38
+ console.error("Error starting PoW verification:", error);
39
+ }).finally(() => {
40
+ setLoading(false);
41
+ });
42
+ }, [props.autoStart, props.startCoords]);
43
+ (0, react.useEffect)(() => {
44
+ if (!state.error) return;
45
+ setLoading(false);
46
+ if (state.error.key !== "CAPTCHA.NO_SESSION_FOUND") return;
47
+ if (props.onSessionInvalidated && !sessionInvalidatedFiredRef.current) {
48
+ sessionInvalidatedFiredRef.current = true;
49
+ const coords = lastCoordsRef.current;
50
+ props.onSessionInvalidated(coords?.x, coords?.y);
51
+ return;
52
+ }
53
+ if (frictionlessState) setTimeout(() => {
54
+ frictionlessState.restart();
55
+ }, 100);
56
+ }, [
57
+ state.error,
58
+ frictionlessState,
59
+ props.onSessionInvalidated
60
+ ]);
61
+ (0, react.useEffect)(() => {
62
+ if (config.mode === _prosopo_types.ModeEnum.invisible) {
63
+ const handleExecuteEvent = (event) => {
64
+ try {
65
+ manager.current.start().catch((error) => {
66
+ console.error("Error starting PoW verification:", error);
67
+ });
68
+ } catch (error) {
69
+ console.error("Error starting PoW verification:", error);
70
+ }
71
+ };
72
+ document.addEventListener(PROCAPTCHA_EXECUTE_EVENT, handleExecuteEvent);
73
+ return () => {
74
+ document.removeEventListener(PROCAPTCHA_EXECUTE_EVENT, handleExecuteEvent);
75
+ };
76
+ }
77
+ return () => {};
78
+ }, [config.mode]);
79
+ const honeypot = frictionlessState?.hp ? /* @__PURE__ */ (0, _emotion_react_jsx_runtime.jsx)(_prosopo_procaptcha_common.Honeypot, {
80
+ ref: hpRef,
81
+ encodedQuestion: frictionlessState.hp
82
+ }) : null;
83
+ if (config.mode === _prosopo_types.ModeEnum.invisible) return honeypot;
84
+ return /* @__PURE__ */ (0, _emotion_react_jsx_runtime.jsxs)(_emotion_react_jsx_runtime.Fragment, { children: [honeypot, /* @__PURE__ */ (0, _emotion_react_jsx_runtime.jsx)(_prosopo_procaptcha_common.Checkbox, {
85
+ checked: state.isHuman,
86
+ theme,
87
+ onChange: async (event) => {
88
+ if (loading) return;
89
+ setLoading(true);
90
+ let x = 0;
91
+ let y = 0;
92
+ const mouseOrTouchEvent = event.nativeEvent;
93
+ if (!mouseOrTouchEvent.isTrusted) {} else if ("touches" in mouseOrTouchEvent && mouseOrTouchEvent.touches.length > 0 && mouseOrTouchEvent.touches[0]) {
94
+ x = mouseOrTouchEvent.touches[0].clientX;
95
+ y = mouseOrTouchEvent.touches[0].clientY;
96
+ } else if ("clientX" in mouseOrTouchEvent && "clientY" in mouseOrTouchEvent) {
97
+ x = mouseOrTouchEvent.clientX;
98
+ y = mouseOrTouchEvent.clientY;
99
+ }
100
+ lastCoordsRef.current = {
101
+ x,
102
+ y
103
+ };
104
+ try {
105
+ await manager.current.start(x, y);
106
+ } catch (error) {
107
+ console.error("Error starting PoW verification:", error);
108
+ }
109
+ setLoading(false);
110
+ },
111
+ labelText: isTranslationReady ? t("WIDGET.I_AM_HUMAN") : "",
112
+ error: state.error?.message,
113
+ "aria-label": "human checkbox",
114
+ loading
115
+ })] });
127
116
  };
128
- module.exports = Procaptcha;
117
+ //#endregion
118
+ exports.default = Procaptcha;
@@ -1,5 +1,3 @@
1
- "use strict";
2
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- require("./components/ProcaptchaWidget.cjs");
4
- const ProcaptchaPoW = require("./components/ProcaptchaPoW.cjs");
5
- exports.ProcaptchaPow = ProcaptchaPoW.ProcaptchaPow;
2
+ const require_ProcaptchaPoW = require("./components/ProcaptchaPoW.cjs");
3
+ exports.ProcaptchaPow = require_ProcaptchaPoW.ProcaptchaPow;