@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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @prosopo/procaptcha-frictionless@2.12.21 build:cjs
2
+ > @prosopo/procaptcha-frictionless@2.12.22 build:cjs
3
3
  > NODE_ENV=${NODE_ENV:-development}; vite build --config vite.cjs.config.ts --mode $NODE_ENV
4
4
 
5
5
  ViteCommonJSConfig: .
@@ -51,16 +51,17 @@ ViteCommonJSConfig: .
51
51
  '@prosopo/datasets'
52
52
  ]
53
53
  }
54
- vite v6.4.1 building SSR bundle for production...
54
+ 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.
55
+ vite v8.1.5 building ssr environment for production...
55
56
  Bundle build started
56
- transforming...
57
- Build end
58
- ✓ 5 modules transformed.
59
- Entry module "src/customDetectBot.ts" is using named and default exports together. Consumers of your bundle will have to use `..default` to access the default export, which may not be what you want. Use `output.exports: "named"` to disable this warning.
57
+ 
58
+ ✓ 6 modules transformed.
60
59
  rendering chunks...
61
- dist/cjs/index.cjs 0.24 kB
62
- dist/cjs/sessionInvalidatedRecovery.cjs 0.85 kB
63
- dist/cjs/detectorLoader.cjs 1.37 kB
64
- dist/cjs/customDetectBot.cjs 4.58 kB
65
- dist/cjs/ProcaptchaFrictionless.cjs 9.07 kB
66
- ✓ built in 158ms
60
+ computing gzip size...
61
+ dist/cjs/detectorLoader.cjs 0.16 kB │ gzip: 0.12 kB
62
+ dist/cjs/index.cjs 0.24 kB │ gzip: 0.15 kB
63
+ dist/cjs/sessionInvalidatedRecovery.cjs 2.07 kB │ gzip: 0.99 kB
64
+ dist/cjs/customDetectBot.cjs 4.22 kB │ gzip: 1.36 kB
65
+ dist/cjs/ProcaptchaFrictionless.cjs 7.00 kB │ gzip: 2.02 kB
66
+
67
+ ✓ built in 45ms
@@ -1,8 +1,8 @@
1
1
 
2
- > @prosopo/procaptcha-frictionless@2.12.21 build:tsc
2
+ > @prosopo/procaptcha-frictionless@2.12.22 build:tsc
3
3
  > tsc --build --verbose
4
4
 
5
- 10:23:05 PM - Projects in this build:
5
+ 8:59:45 PM - Projects in this build:
6
6
  * ../../dev/config/tsconfig.json
7
7
  * ../locale/tsconfig.json
8
8
  * ../util/tsconfig.json
@@ -26,49 +26,49 @@
26
26
  * ../procaptcha-react/tsconfig.json
27
27
  * tsconfig.json
28
28
 
29
- 10:23:06 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'
29
+ 8:59:45 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'
30
30
 
31
- 10:23:06 PM - Project '../locale/tsconfig.json' is up to date because newest input '../locale/src/translationKey.ts' is older than output '../locale/tsconfig.tsbuildinfo'
31
+ 8:59:45 PM - Project '../locale/tsconfig.json' is up to date because newest input '../locale/src/translationKey.ts' is older than output '../locale/tsconfig.tsbuildinfo'
32
32
 
33
- 10:23:06 PM - Project '../util/tsconfig.json' is up to date because newest input '../util/src/url.ts' is older than output '../util/tsconfig.tsbuildinfo'
33
+ 8:59:45 PM - Project '../util/tsconfig.json' is up to date because newest input '../util/src/url.ts' is older than output '../util/tsconfig.tsbuildinfo'
34
34
 
35
- 10:23:06 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'
35
+ 8:59:45 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'
36
36
 
37
- 10:23:06 PM - Project '../types/tsconfig.json' is up to date because newest input '../types/src/procaptcha/api.ts' is older than output '../types/tsconfig.tsbuildinfo'
37
+ 8:59:45 PM - Project '../types/tsconfig.json' is up to date because newest input '../types/src/provider/api.ts' is older than output '../types/tsconfig.tsbuildinfo'
38
38
 
39
- 10:23:06 PM - Project '../detector/tsconfig.json' is up to date because newest input '../detector/src/index.js' is older than output '../detector/tsconfig.tsbuildinfo'
39
+ 8:59:45 PM - Project '../detector/tsconfig.json' is up to date because newest input '../detector/src/index.js' is older than output '../detector/tsconfig.tsbuildinfo'
40
40
 
41
- 10:23:06 PM - Project '../api/tsconfig.json' is up to date because newest input '../api/src/index.ts' is older than output '../api/tsconfig.tsbuildinfo'
41
+ 8:59:45 PM - Project '../api/tsconfig.json' is up to date because newest input '../api/src/index.ts' is older than output '../api/tsconfig.tsbuildinfo'
42
42
 
43
- 10:23:06 PM - Project '../logger/tsconfig.json' is up to date because newest input '../logger/src/index.ts' is older than output '../logger/tsconfig.tsbuildinfo'
43
+ 8:59:45 PM - Project '../logger/tsconfig.json' is up to date because newest input '../logger/src/index.ts' is older than output '../logger/tsconfig.tsbuildinfo'
44
44
 
45
- 10:23:06 PM - Project '../common/tsconfig.json' is up to date because newest input '../common/src/error.ts' is older than output '../common/tsconfig.tsbuildinfo'
45
+ 8:59:45 PM - Project '../common/tsconfig.json' is up to date because newest input '../common/src/tests/utils/batches.unit.test.ts' is older than output '../common/tsconfig.tsbuildinfo'
46
46
 
47
- 10:23:06 PM - Project '../fingerprintjs/tsconfig.json' is up to date because newest input '../fingerprintjs/src/utils/browser.ts' is older than output '../fingerprintjs/tsconfig.tsbuildinfo'
47
+ 8:59:45 PM - Project '../fingerprintjs/tsconfig.json' is up to date because newest input '../fingerprintjs/src/utils/browser.ts' is older than output '../fingerprintjs/tsconfig.tsbuildinfo'
48
48
 
49
- 10:23:06 PM - Project '../fingerprint/tsconfig.json' is up to date because newest input '../fingerprint/src/index.ts' is older than output '../fingerprint/tsconfig.tsbuildinfo'
49
+ 8:59:45 PM - Project '../fingerprint/tsconfig.json' is up to date because newest input '../fingerprint/src/index.ts' is older than output '../fingerprint/tsconfig.tsbuildinfo'
50
50
 
51
- 10:23:06 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'
51
+ 8:59:45 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'
52
52
 
53
- 10:23:06 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'
53
+ 8:59:45 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'
54
54
 
55
- 10:23:06 PM - Project '../keyring/tsconfig.json' is up to date because newest input '../keyring/src/index.ts' is older than output '../keyring/tsconfig.tsbuildinfo'
55
+ 8:59:45 PM - Project '../keyring/tsconfig.json' is up to date because newest input '../keyring/src/keyring/keyring.ts' is older than output '../keyring/tsconfig.tsbuildinfo'
56
56
 
57
- 10:23:06 PM - Project '../account/tsconfig.json' is up to date because newest input '../account/src/custom.d.ts' is older than output '../account/tsconfig.tsbuildinfo'
57
+ 8:59:45 PM - Project '../account/tsconfig.json' is up to date because newest input '../account/src/tests/cryptoWorker.unit.test.ts' is older than output '../account/tsconfig.tsbuildinfo'
58
58
 
59
- 10:23:06 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'
59
+ 8:59:45 PM - Project '../procaptcha-common/tsconfig.json' is up to date because newest input '../procaptcha-common/src/tests/defaultEvents.test.ts' is older than output '../procaptcha-common/tsconfig.tsbuildinfo'
60
60
 
61
- 10:23:06 PM - Project '../procaptcha-pow/tsconfig.json' is up to date because newest input '../procaptcha-pow/src/index.ts' is older than output '../procaptcha-pow/tsconfig.tsbuildinfo'
61
+ 8:59:45 PM - Project '../procaptcha-pow/tsconfig.json' is up to date because newest input '../procaptcha-pow/src/index.ts' is older than output '../procaptcha-pow/tsconfig.tsbuildinfo'
62
62
 
63
- 10:23:06 PM - Project '../procaptcha-puzzle/tsconfig.json' is up to date because newest input '../procaptcha-puzzle/src/index.ts' is older than output '../procaptcha-puzzle/tsconfig.tsbuildinfo'
63
+ 8:59:45 PM - Project '../procaptcha-puzzle/tsconfig.json' is up to date because newest input '../procaptcha-puzzle/src/index.ts' is older than output '../procaptcha-puzzle/tsconfig.tsbuildinfo'
64
64
 
65
- 10:23:06 PM - Project '../datasets/tsconfig.json' is up to date because newest input '../datasets/src/tests/dataset.unit.test.ts' is older than output '../datasets/tsconfig.tsbuildinfo'
65
+ 8:59:45 PM - Project '../datasets/tsconfig.json' is up to date because newest input '../datasets/src/tests/mocks/data/captchas.ts' is older than output '../datasets/tsconfig.tsbuildinfo'
66
66
 
67
- 10:23:06 PM - Project '../procaptcha/tsconfig.json' is up to date because newest input '../procaptcha/src/index.ts' is older than output '../procaptcha/tsconfig.tsbuildinfo'
67
+ 8:59:46 PM - Project '../procaptcha/tsconfig.json' is up to date because newest input '../procaptcha/src/modules/Manager.ts' is older than output '../procaptcha/tsconfig.tsbuildinfo'
68
68
 
69
- 10:23:06 PM - Project '../procaptcha-react/tsconfig.json' is up to date because newest input '../procaptcha-react/src/index.ts' is older than output '../procaptcha-react/tsconfig.tsbuildinfo'
69
+ 8:59:46 PM - Project '../procaptcha-react/tsconfig.json' is up to date because newest input '../procaptcha-react/src/index.ts' is older than output '../procaptcha-react/tsconfig.tsbuildinfo'
70
70
 
71
- 10:23:06 PM - Project 'tsconfig.json' is out of date because output file 'tsconfig.tsbuildinfo' does not exist
71
+ 8:59:46 PM - Project 'tsconfig.json' is out of date because output file 'tsconfig.tsbuildinfo' does not exist
72
72
 
73
- 10:23:06 PM - Building project '/home/runner/work/captcha/captcha/packages/procaptcha-frictionless/tsconfig.json'...
73
+ 8:59:46 PM - Building project '/home/runner/work/captcha/captcha/packages/procaptcha-frictionless/tsconfig.json'...
74
74
 
@@ -1,9 +1,9 @@
1
1
 
2
- > @prosopo/procaptcha-frictionless@2.12.21 build
2
+ > @prosopo/procaptcha-frictionless@2.12.22 build
3
3
  > npm run build:cross-env -- --mode ${NODE_ENV:-development}
4
4
 
5
5
 
6
- > @prosopo/procaptcha-frictionless@2.12.21 build:cross-env
6
+ > @prosopo/procaptcha-frictionless@2.12.22 build:cross-env
7
7
  > vite build --config vite.esm.config.ts --mode production
8
8
 
9
9
  ViteEsmConfig: .
@@ -55,15 +55,18 @@ ViteEsmConfig: .
55
55
  '@prosopo/datasets'
56
56
  ]
57
57
  }
58
- vite v6.4.1 building SSR bundle for production...
58
+ 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.
59
+ vite v8.1.5 building ssr environment for production...
59
60
  Bundle build started
60
- transforming...
61
- Build end
62
- ✓ 5 modules transformed.
61
+ 
62
+ ✓ 6 modules transformed.
63
63
  rendering chunks...
64
- dist/index.js 0.11 kB
65
- dist/detectorLoader.js 0.11 kB
66
- dist/sessionInvalidatedRecovery.js 0.71 kB
67
- dist/customDetectBot.js 4.37 kB
68
- dist/ProcaptchaFrictionless.js 7.62 kB
69
- ✓ built in 258ms
64
+ computing gzip size...
65
+ dist/_virtual/_rolldown/runtime.js 0.04 kB │ gzip: 0.06 kB
66
+ dist/index.js 0.14 kB │ gzip: 0.10 kB
67
+ dist/detectorLoader.js 0.15 kB │ gzip: 0.13 kB
68
+ dist/sessionInvalidatedRecovery.js 2.01 kB │ gzip: 0.98 kB
69
+ dist/customDetectBot.js 3.97 kB │ gzip: 1.33 kB
70
+ dist/ProcaptchaFrictionless.js 6.49 kB │ gzip: 1.97 kB
71
+
72
+ ✓ built in 52ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @prosopo/procaptcha-frictionless
2
2
 
3
+ ## 2.12.22
4
+ ### Patch Changes
5
+
6
+ - 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
7
+ - Updated dependencies [ab3499c]
8
+ - Updated dependencies [0e1171c]
9
+ - Updated dependencies [103318c]
10
+ - Updated dependencies [270a8d8]
11
+ - Updated dependencies [e14fce6]
12
+ - @prosopo/procaptcha-common@2.11.18
13
+ - @prosopo/procaptcha-pow@2.10.24
14
+ - @prosopo/procaptcha-puzzle@2.10.40
15
+ - @prosopo/locale@3.2.8
16
+ - @prosopo/types@4.10.0
17
+ - @prosopo/api@3.5.20
18
+ - @prosopo/common@3.1.48
19
+ - @prosopo/detector@3.5.14
20
+ - @prosopo/procaptcha-react@2.9.97
21
+
3
22
  ## 2.12.21
4
23
  ### Patch Changes
5
24
 
@@ -1,241 +1,170 @@
1
- import { jsx, jsxs, Fragment } from "react/jsx-runtime";
1
+ import customDetectBot from "./customDetectBot.js";
2
+ import { consumeRetryMountProps, handleSessionInvalidated } from "./sessionInvalidatedRecovery.js";
2
3
  import { loadI18next } from "@prosopo/locale";
3
- import { Checkbox, getDefaultEvents, isSecureBrowserContext, providerRetry, TestModeBanner } from "@prosopo/procaptcha-common";
4
+ import { Checkbox, TestModeBanner, getDefaultEvents, isSecureBrowserContext, providerRetry } from "@prosopo/procaptcha-common";
4
5
  import { CaptchaType, ProcaptchaConfigSchema } from "@prosopo/types";
5
- import { lightTheme, darkTheme } from "@prosopo/widget-skeleton";
6
- import { useRef, useEffect, useState } from "react";
7
- import customDetectBot from "./customDetectBot.js";
8
- import { handleSessionInvalidated, consumeRetryMountProps } from "./sessionInvalidatedRecovery.js";
9
- const ProcaptchaLoader = async () => (await import("@prosopo/procaptcha-react")).Procaptcha;
10
- const ProcaptchaPuzzleLoader = async () => (await import("@prosopo/procaptcha-puzzle")).ProcaptchaPuzzle;
11
- const ProcaptchaPowLoader = async () => (await import("@prosopo/procaptcha-pow")).ProcaptchaPow;
12
- const renderPlaceholder = (theme, mode, errorMessage, isTranslationLoaded, translationFn, loading) => {
13
- const checkboxTheme = "light" === theme ? lightTheme : darkTheme;
14
- if (mode === "invisible") {
15
- return null;
16
- }
17
- return /* @__PURE__ */ jsx(
18
- Checkbox,
19
- {
20
- theme: checkboxTheme,
21
- onChange: async () => {
22
- },
23
- checked: false,
24
- labelText: isTranslationLoaded ? translationFn("WIDGET.I_AM_HUMAN") : "",
25
- error: errorMessage,
26
- "aria-label": "human checkbox",
27
- loading
28
- }
29
- );
6
+ import { darkTheme, lightTheme } from "@prosopo/widget-skeleton";
7
+ import { useEffect, useRef, useState } from "react";
8
+ import { Fragment, jsx, jsxs } from "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 ? lightTheme : darkTheme;
15
+ if (mode === "invisible") return null;
16
+ return /* @__PURE__ */ jsx(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
+ });
30
25
  };
31
- const defaultLoadingState = (attemptCount) => ({
32
- loading: false,
33
- attemptCount: attemptCount || 0
26
+ var defaultLoadingState = (attemptCount) => ({
27
+ loading: false,
28
+ attemptCount: attemptCount || 0
34
29
  });
35
- const ProcaptchaFrictionless = ({
36
- config,
37
- callbacks,
38
- restart,
39
- i18n,
40
- detectBot = customDetectBot,
41
- container
42
- }) => {
43
- const stateRef = useRef(defaultLoadingState(0));
44
- const events = getDefaultEvents(callbacks);
45
- const pendingRetryCoordsRef = useRef(null);
46
- const sessionInvalidatedFiredRef = useRef(false);
47
- useEffect(() => {
48
- if (!config.language) return;
49
- if (i18n) {
50
- if (i18n.language !== config.language) {
51
- void i18n.changeLanguage(config.language);
52
- }
53
- return;
54
- }
55
- void loadI18next(false, config.language);
56
- }, [i18n, config.language]);
57
- const [componentToRender, setComponentToRender] = useState(
58
- renderPlaceholder(
59
- config.theme,
60
- config.mode,
61
- stateRef.current.errorMessage,
62
- i18n.isInitialized,
63
- i18n.t,
64
- true
65
- )
66
- );
67
- const resetState = (attemptCount) => {
68
- stateRef.current = defaultLoadingState(
69
- attemptCount || stateRef.current.attemptCount
70
- );
71
- };
72
- const fallOverWithStyle = (errorMessage, errorKey) => {
73
- if (errorKey === "CAPTCHA.NO_SESSION_FOUND") {
74
- setTimeout(() => {
75
- restartComponentTimeout();
76
- }, 0);
77
- }
78
- setComponentToRender(
79
- renderPlaceholder(
80
- config.theme,
81
- config.mode,
82
- errorMessage || "Cannot load CAPTCHA",
83
- i18n.isInitialized,
84
- i18n.t,
85
- false
86
- )
87
- );
88
- };
89
- const restartComponentTimeout = () => {
90
- setTimeout(() => {
91
- resetState(0);
92
- events.onReset();
93
- restart();
94
- }, 1e4);
95
- };
96
- const renderForCaptchaType = async (captchaType, frictionlessState, autoStart = false, escalationCoords) => {
97
- const onEscalate = (next, newSessionId, coords) => {
98
- void renderForCaptchaType(
99
- next,
100
- {
101
- ...frictionlessState,
102
- sessionId: newSessionId
103
- },
104
- true,
105
- coords
106
- );
107
- };
108
- const onSessionInvalidated = (x, y) => {
109
- const { shouldRestart } = handleSessionInvalidated(
110
- x,
111
- y,
112
- sessionInvalidatedFiredRef,
113
- pendingRetryCoordsRef
114
- );
115
- if (!shouldRestart) return;
116
- resetState(0);
117
- void start();
118
- };
119
- const { autoStart: resumedAutoStart, startCoords: retryStartCoords } = consumeRetryMountProps(pendingRetryCoordsRef, autoStart);
120
- const startCoords = escalationCoords ?? retryStartCoords;
121
- if (captchaType === CaptchaType.image) {
122
- const Procaptcha = await ProcaptchaLoader();
123
- setComponentToRender(
124
- /* @__PURE__ */ jsx(
125
- Procaptcha,
126
- {
127
- config,
128
- callbacks,
129
- frictionlessState,
130
- i18n,
131
- autoStart: resumedAutoStart,
132
- startCoords,
133
- onSessionInvalidated
134
- }
135
- )
136
- );
137
- } else if (captchaType === CaptchaType.puzzle) {
138
- const ProcaptchaPuzzle = await ProcaptchaPuzzleLoader();
139
- setComponentToRender(
140
- /* @__PURE__ */ jsx(
141
- ProcaptchaPuzzle,
142
- {
143
- config,
144
- callbacks,
145
- frictionlessState,
146
- i18n,
147
- autoStart: resumedAutoStart,
148
- startCoords,
149
- onSessionInvalidated
150
- }
151
- )
152
- );
153
- } else {
154
- const ProcaptchaPow = await ProcaptchaPowLoader();
155
- setComponentToRender(
156
- /* @__PURE__ */ jsx(
157
- ProcaptchaPow,
158
- {
159
- config,
160
- callbacks,
161
- frictionlessState,
162
- i18n,
163
- onEscalate,
164
- autoStart: resumedAutoStart,
165
- startCoords,
166
- onSessionInvalidated
167
- }
168
- )
169
- );
170
- }
171
- };
172
- const start = async () => {
173
- if (!isSecureBrowserContext()) {
174
- const errorMessage = i18n.isInitialized ? i18n.t("WIDGET.INSECURE_CONTEXT") : "Procaptcha requires a secure (HTTPS) connection";
175
- events.onError(new Error(errorMessage));
176
- fallOverWithStyle(errorMessage, "WIDGET.INSECURE_CONTEXT");
177
- return;
178
- }
179
- await providerRetry(
180
- async () => {
181
- stateRef.current.attemptCount += 1;
182
- const configOutput = ProcaptchaConfigSchema.parse(config);
183
- const result = await detectBot(configOutput, container, restart, {
184
- attempt: stateRef.current.attemptCount
185
- });
186
- if (result.error?.message) {
187
- stateRef.current = {
188
- ...stateRef.current,
189
- loading: false,
190
- errorMessage: result.error?.message
191
- };
192
- events.onError(new Error(result.error?.message));
193
- fallOverWithStyle(result.error?.message, result.error?.key);
194
- return;
195
- }
196
- const frictionlessState = {
197
- provider: result.provider,
198
- sessionId: result.sessionId,
199
- userAccount: result.userAccount,
200
- restart,
201
- // Pass restart function
202
- behaviorCollector1: result.behaviorCollector1,
203
- behaviorCollector2: result.behaviorCollector2,
204
- behaviorCollector3: result.behaviorCollector3,
205
- deviceCapability: result.deviceCapability,
206
- encryptBehavioralData: result.encryptBehavioralData,
207
- getSimdReadings: result.getSimdReadings,
208
- hp: result.hp
209
- };
210
- await renderForCaptchaType(result.captchaType, frictionlessState);
211
- stateRef.current = {
212
- ...stateRef.current,
213
- loading: false
214
- };
215
- },
216
- start,
217
- resetState,
218
- stateRef.current.attemptCount,
219
- 5
220
- ).finally(() => {
221
- if (stateRef.current.attemptCount >= 5) {
222
- fallOverWithStyle();
223
- restartComponentTimeout();
224
- }
225
- });
226
- };
227
- const startedForKeyRef = useRef(null);
228
- useEffect(() => {
229
- const key = `${config.account?.address ?? ""}|${config.language ?? ""}|${config.mode ?? ""}`;
230
- if (startedForKeyRef.current === key) return;
231
- startedForKeyRef.current = key;
232
- void start();
233
- }, [config.account?.address, config.language, config.mode]);
234
- return /* @__PURE__ */ jsxs(Fragment, { children: [
235
- /* @__PURE__ */ jsx(TestModeBanner, { siteKey: config.account?.address ?? "" }),
236
- componentToRender
237
- ] });
238
- };
239
- export {
240
- ProcaptchaFrictionless
30
+ var ProcaptchaFrictionless = ({ config, callbacks, restart, i18n, detectBot = customDetectBot, container }) => {
31
+ const stateRef = useRef(defaultLoadingState(0));
32
+ const events = getDefaultEvents(callbacks);
33
+ const pendingRetryCoordsRef = useRef(null);
34
+ const sessionInvalidatedFiredRef = useRef(false);
35
+ useEffect(() => {
36
+ if (!config.language) return;
37
+ if (i18n) {
38
+ if (i18n.language !== config.language) i18n.changeLanguage(config.language);
39
+ return;
40
+ }
41
+ loadI18next(false, config.language);
42
+ }, [i18n, config.language]);
43
+ const [componentToRender, setComponentToRender] = 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 } = handleSessionInvalidated(x, y, sessionInvalidatedFiredRef, pendingRetryCoordsRef);
69
+ if (!shouldRestart) return;
70
+ resetState(0);
71
+ start();
72
+ };
73
+ const { autoStart: resumedAutoStart, startCoords: retryStartCoords } = consumeRetryMountProps(pendingRetryCoordsRef, autoStart);
74
+ const startCoords = escalationCoords ?? retryStartCoords;
75
+ if (captchaType === CaptchaType.image) {
76
+ const Procaptcha = await ProcaptchaLoader();
77
+ setComponentToRender(/* @__PURE__ */ jsx(Procaptcha, {
78
+ config,
79
+ callbacks,
80
+ frictionlessState,
81
+ i18n,
82
+ autoStart: resumedAutoStart,
83
+ startCoords,
84
+ onSessionInvalidated
85
+ }));
86
+ } else if (captchaType === CaptchaType.puzzle) {
87
+ const ProcaptchaPuzzle = await ProcaptchaPuzzleLoader();
88
+ setComponentToRender(/* @__PURE__ */ 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__ */ 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 (!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 providerRetry(async () => {
119
+ stateRef.current.attemptCount += 1;
120
+ const result = await detectBot(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 = useRef(null);
157
+ 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__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(TestModeBanner, { siteKey: config.account?.address ?? "" }), componentToRender] });
241
168
  };
169
+ //#endregion
170
+ export { ProcaptchaFrictionless };
@@ -0,0 +1,3 @@
1
+ import "node:module";
2
+ //#endregion
3
+ export {};