@prosopo/procaptcha-frictionless 2.6.27 → 2.6.29

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/CHANGELOG.md CHANGED
@@ -1,5 +1,36 @@
1
1
  # @prosopo/procaptcha-frictionless
2
2
 
3
+ ## 2.6.29
4
+ ### Patch Changes
5
+
6
+ - 3573f0b: fix npm scripts bundle command
7
+ - 3573f0b: build using vite, typecheck using tsc
8
+ - efd8102: Add tests for unwrap error helper
9
+ - 3573f0b: standardise all vite based npm scripts for bundling
10
+ - Updated dependencies [2f0c830]
11
+ - Updated dependencies [93d5e50]
12
+ - Updated dependencies [3573f0b]
13
+ - Updated dependencies [3573f0b]
14
+ - Updated dependencies [efd8102]
15
+ - Updated dependencies [93d5e50]
16
+ - Updated dependencies [63519d7]
17
+ - Updated dependencies [f29fc7e]
18
+ - Updated dependencies [3573f0b]
19
+ - Updated dependencies [2d0dd8a]
20
+ - @prosopo/detector@3.0.1
21
+ - @prosopo/widget-skeleton@2.6.1
22
+ - @prosopo/locale@3.1.0
23
+ - @prosopo/types@3.0.4
24
+ - @prosopo/procaptcha-react@2.6.29
25
+ - @prosopo/procaptcha-pow@2.7.15
26
+ - @prosopo/config@3.1.1
27
+
28
+ ## 2.6.28
29
+ ### Patch Changes
30
+
31
+ - @prosopo/procaptcha-pow@2.7.14
32
+ - @prosopo/procaptcha-react@2.6.28
33
+
3
34
  ## 2.6.27
4
35
  ### Patch Changes
5
36
 
@@ -1,104 +1,169 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
1
+ import { jsx } from "react/jsx-runtime";
2
2
  import { loadI18next } from "@prosopo/locale";
3
- import { Checkbox, getDefaultEvents, providerRetry, } from "@prosopo/procaptcha-common";
3
+ import { Checkbox, getDefaultEvents, providerRetry } from "@prosopo/procaptcha-common";
4
4
  import { ProcaptchaPow } from "@prosopo/procaptcha-pow";
5
5
  import { Procaptcha } from "@prosopo/procaptcha-react";
6
- import { ProcaptchaConfigSchema, } from "@prosopo/types";
7
- import { darkTheme, lightTheme } from "@prosopo/widget-skeleton";
8
- import { useEffect, useRef, useState } from "react";
6
+ import { ProcaptchaConfigSchema } from "@prosopo/types";
7
+ import { lightTheme, darkTheme } from "@prosopo/widget-skeleton";
8
+ import { useRef, useEffect, useState } from "react";
9
9
  import customDetectBot from "./customDetectBot.js";
10
10
  const renderPlaceholder = (theme, mode, errorMessage, isTranslationLoaded, translationFn, loading) => {
11
- const checkboxTheme = "light" === theme ? lightTheme : darkTheme;
12
- if (mode === "invisible") {
13
- return null;
11
+ const checkboxTheme = "light" === theme ? lightTheme : darkTheme;
12
+ if (mode === "invisible") {
13
+ return null;
14
+ }
15
+ return /* @__PURE__ */ jsx(
16
+ Checkbox,
17
+ {
18
+ theme: checkboxTheme,
19
+ onChange: async () => {
20
+ },
21
+ checked: false,
22
+ labelText: isTranslationLoaded ? translationFn("WIDGET.I_AM_HUMAN") : "",
23
+ error: errorMessage,
24
+ "aria-label": "human checkbox",
25
+ loading
14
26
  }
15
- return (_jsx(Checkbox, { theme: checkboxTheme, onChange: async () => { }, checked: false, labelText: isTranslationLoaded ? translationFn("WIDGET.I_AM_HUMAN") : "", error: errorMessage, "aria-label": "human checkbox", loading: loading }));
27
+ );
16
28
  };
17
29
  const defaultLoadingState = (attemptCount) => ({
18
- loading: false,
19
- attemptCount: attemptCount || 0,
30
+ loading: false,
31
+ attemptCount: attemptCount || 0
20
32
  });
21
- export const ProcaptchaFrictionless = ({ config, callbacks, restart, i18n, detectBot = customDetectBot, }) => {
22
- const stateRef = useRef(defaultLoadingState(0));
23
- const events = getDefaultEvents(callbacks);
24
- useEffect(() => {
25
- if (config.language) {
26
- if (i18n) {
27
- if (i18n.language !== config.language) {
28
- i18n.changeLanguage(config.language).then((r) => r);
29
- }
30
- }
31
- else {
32
- loadI18next(false).then((i18n) => {
33
- if (i18n.language !== config.language)
34
- i18n.changeLanguage(config.language).then((r) => r);
35
- });
36
- }
33
+ const ProcaptchaFrictionless = ({
34
+ config,
35
+ callbacks,
36
+ restart,
37
+ i18n,
38
+ detectBot = customDetectBot
39
+ }) => {
40
+ const stateRef = useRef(defaultLoadingState(0));
41
+ const events = getDefaultEvents(callbacks);
42
+ useEffect(() => {
43
+ if (config.language) {
44
+ if (i18n) {
45
+ if (i18n.language !== config.language) {
46
+ i18n.changeLanguage(config.language).then((r) => r);
37
47
  }
38
- }, [i18n, config.language]);
39
- const [componentToRender, setComponentToRender] = useState(renderPlaceholder(config.theme, config.mode, stateRef.current.errorMessage, i18n.isInitialized, i18n.t, true));
40
- const resetState = (attemptCount) => {
41
- stateRef.current = defaultLoadingState(attemptCount || stateRef.current.attemptCount);
42
- };
43
- const fallOverWithStyle = (errorMessage, errorKey) => {
44
- if (errorKey === "CAPTCHA.NO_SESSION_FOUND") {
45
- setTimeout(() => {
46
- restartComponentTimeout();
47
- }, 0);
48
- }
49
- setComponentToRender(renderPlaceholder(config.theme, config.mode, errorMessage || "Cannot load CAPTCHA", i18n.isInitialized, i18n.t, false));
50
- };
51
- const restartComponentTimeout = () => {
52
- setTimeout(() => {
53
- resetState(0);
54
- events.onReset();
55
- restart();
56
- }, 10000);
57
- };
58
- const start = async () => {
59
- await providerRetry(async () => {
60
- stateRef.current.attemptCount += 1;
61
- const configOutput = ProcaptchaConfigSchema.parse(config);
62
- const result = await detectBot(configOutput);
63
- if (result.error?.message) {
64
- stateRef.current = {
65
- ...stateRef.current,
66
- loading: false,
67
- errorMessage: result.error?.message,
68
- };
69
- events.onError(new Error(result.error?.message));
70
- fallOverWithStyle(result.error?.message, result.error?.key);
71
- return;
72
- }
73
- const frictionlessState = {
74
- provider: result.provider,
75
- sessionId: result.sessionId,
76
- userAccount: result.userAccount,
77
- restart,
78
- };
79
- if (result.captchaType === "image") {
80
- setComponentToRender(_jsx(Procaptcha, { config: config, callbacks: callbacks, frictionlessState: frictionlessState, i18n: i18n }));
81
- }
82
- else {
83
- setComponentToRender(_jsx(ProcaptchaPow, { config: config, callbacks: callbacks, frictionlessState: frictionlessState, i18n: i18n }));
84
- stateRef.current = {
85
- ...stateRef.current,
86
- loading: false,
87
- };
88
- }
89
- }, start, resetState, stateRef.current.attemptCount, 5).finally(() => {
90
- if (stateRef.current.attemptCount >= 5) {
91
- fallOverWithStyle();
92
- restartComponentTimeout();
93
- }
48
+ } else {
49
+ loadI18next(false).then((i18n2) => {
50
+ if (i18n2.language !== config.language)
51
+ i18n2.changeLanguage(config.language).then((r) => r);
94
52
  });
95
- };
96
- useEffect(() => {
97
- const detectAndSetComponent = async () => {
98
- await start();
53
+ }
54
+ }
55
+ }, [i18n, config.language]);
56
+ const [componentToRender, setComponentToRender] = useState(
57
+ renderPlaceholder(
58
+ config.theme,
59
+ config.mode,
60
+ stateRef.current.errorMessage,
61
+ i18n.isInitialized,
62
+ i18n.t,
63
+ true
64
+ )
65
+ );
66
+ const resetState = (attemptCount) => {
67
+ stateRef.current = defaultLoadingState(
68
+ attemptCount || stateRef.current.attemptCount
69
+ );
70
+ };
71
+ const fallOverWithStyle = (errorMessage, errorKey) => {
72
+ if (errorKey === "CAPTCHA.NO_SESSION_FOUND") {
73
+ setTimeout(() => {
74
+ restartComponentTimeout();
75
+ }, 0);
76
+ }
77
+ setComponentToRender(
78
+ renderPlaceholder(
79
+ config.theme,
80
+ config.mode,
81
+ errorMessage || "Cannot load CAPTCHA",
82
+ i18n.isInitialized,
83
+ i18n.t,
84
+ false
85
+ )
86
+ );
87
+ };
88
+ const restartComponentTimeout = () => {
89
+ setTimeout(() => {
90
+ resetState(0);
91
+ events.onReset();
92
+ restart();
93
+ }, 1e4);
94
+ };
95
+ const start = async () => {
96
+ await providerRetry(
97
+ async () => {
98
+ stateRef.current.attemptCount += 1;
99
+ const configOutput = ProcaptchaConfigSchema.parse(config);
100
+ const result = await detectBot(configOutput);
101
+ if (result.error?.message) {
102
+ stateRef.current = {
103
+ ...stateRef.current,
104
+ loading: false,
105
+ errorMessage: result.error?.message
106
+ };
107
+ events.onError(new Error(result.error?.message));
108
+ fallOverWithStyle(result.error?.message, result.error?.key);
109
+ return;
110
+ }
111
+ const frictionlessState = {
112
+ provider: result.provider,
113
+ sessionId: result.sessionId,
114
+ userAccount: result.userAccount,
115
+ restart
116
+ // Pass restart function
99
117
  };
100
- detectAndSetComponent();
101
- }, [config, callbacks, detectBot, config.language]);
102
- return componentToRender;
118
+ if (result.captchaType === "image") {
119
+ setComponentToRender(
120
+ /* @__PURE__ */ jsx(
121
+ Procaptcha,
122
+ {
123
+ config,
124
+ callbacks,
125
+ frictionlessState,
126
+ i18n
127
+ }
128
+ )
129
+ );
130
+ } else {
131
+ setComponentToRender(
132
+ /* @__PURE__ */ jsx(
133
+ ProcaptchaPow,
134
+ {
135
+ config,
136
+ callbacks,
137
+ frictionlessState,
138
+ i18n
139
+ }
140
+ )
141
+ );
142
+ stateRef.current = {
143
+ ...stateRef.current,
144
+ loading: false
145
+ };
146
+ }
147
+ },
148
+ start,
149
+ resetState,
150
+ stateRef.current.attemptCount,
151
+ 5
152
+ ).finally(() => {
153
+ if (stateRef.current.attemptCount >= 5) {
154
+ fallOverWithStyle();
155
+ restartComponentTimeout();
156
+ }
157
+ });
158
+ };
159
+ useEffect(() => {
160
+ const detectAndSetComponent = async () => {
161
+ await start();
162
+ };
163
+ detectAndSetComponent();
164
+ }, [config, callbacks, detectBot, config.language]);
165
+ return componentToRender;
166
+ };
167
+ export {
168
+ ProcaptchaFrictionless
103
169
  };
104
- //# sourceMappingURL=ProcaptchaFrictionless.js.map