@prosopo/procaptcha-frictionless 2.3.2 → 2.4.2
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/dist/ProcaptchaFrictionless.d.ts +1 -1
- package/dist/ProcaptchaFrictionless.d.ts.map +1 -1
- package/dist/ProcaptchaFrictionless.js +70 -46
- package/dist/ProcaptchaFrictionless.js.map +1 -1
- package/dist/customDetectBot.d.ts +4 -0
- package/dist/customDetectBot.d.ts.map +1 -0
- package/dist/customDetectBot.js +27 -0
- package/dist/customDetectBot.js.map +1 -0
- package/dist/detectorLoader.d.ts +4 -0
- package/dist/detectorLoader.d.ts.map +1 -0
- package/dist/detectorLoader.js +2 -0
- package/dist/detectorLoader.js.map +1 -0
- package/package.json +9 -9
- package/vite.cjs.config.ts +1 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { type ProcaptchaFrictionlessProps } from "@prosopo/types";
|
|
2
|
-
export declare const ProcaptchaFrictionless: ({ config, callbacks, detectBot, }: ProcaptchaFrictionlessProps) => import("react/jsx-runtime").JSX.Element;
|
|
2
|
+
export declare const ProcaptchaFrictionless: ({ config, callbacks, restart, detectBot, }: ProcaptchaFrictionlessProps) => import("react/jsx-runtime").JSX.Element;
|
|
3
3
|
//# sourceMappingURL=ProcaptchaFrictionless.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProcaptchaFrictionless.d.ts","sourceRoot":"","sources":["../src/ProcaptchaFrictionless.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ProcaptchaFrictionless.d.ts","sourceRoot":"","sources":["../src/ProcaptchaFrictionless.tsx"],"names":[],"mappings":"AAiBA,OAAO,EAGN,KAAK,2BAA2B,EAEhC,MAAM,gBAAgB,CAAC;AA8BxB,eAAO,MAAM,sBAAsB,+CAKhC,2BAA2B,4CA2G7B,CAAC"}
|
|
@@ -1,58 +1,82 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
import { ProsopoEnvError } from "@prosopo/common";
|
|
4
|
-
import { getRandomActiveProvider } from "@prosopo/procaptcha-common";
|
|
2
|
+
import { getDefaultEvents, providerRetry } from "@prosopo/procaptcha-common";
|
|
5
3
|
import { ProcaptchaPow } from "@prosopo/procaptcha-pow";
|
|
6
4
|
import { Procaptcha } from "@prosopo/procaptcha-react";
|
|
7
5
|
import { ProcaptchaConfigSchema, } from "@prosopo/types";
|
|
8
6
|
import { ProcaptchaPlaceholder } from "@prosopo/web-components";
|
|
9
|
-
import { useEffect, useState } from "react";
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
:
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
captchaType: captcha.captchaType,
|
|
27
|
-
sessionId: captcha.sessionId,
|
|
28
|
-
provider: provider,
|
|
29
|
-
status: captcha.status,
|
|
30
|
-
userAccount: userAccount,
|
|
7
|
+
import { useEffect, useRef, useState } from "react";
|
|
8
|
+
import customDetectBot from "./customDetectBot.js";
|
|
9
|
+
const renderPlaceholder = ({ config, callbacks, errorMessage, }) => (_jsx(ProcaptchaPlaceholder, { config: config, callbacks: callbacks, errorMessage: errorMessage }));
|
|
10
|
+
const defaultLoadingState = (attemptCount) => ({
|
|
11
|
+
loading: false,
|
|
12
|
+
attemptCount: attemptCount || 0,
|
|
13
|
+
});
|
|
14
|
+
export const ProcaptchaFrictionless = ({ config, callbacks, restart, detectBot = customDetectBot, }) => {
|
|
15
|
+
const stateRef = useRef(defaultLoadingState(0));
|
|
16
|
+
const events = getDefaultEvents(callbacks);
|
|
17
|
+
const [componentToRender, setComponentToRender] = useState(renderPlaceholder({
|
|
18
|
+
config,
|
|
19
|
+
callbacks,
|
|
20
|
+
errorMessage: stateRef.current.errorMessage,
|
|
21
|
+
}));
|
|
22
|
+
const resetState = (attemptCount) => {
|
|
23
|
+
stateRef.current = defaultLoadingState(attemptCount || stateRef.current.attemptCount);
|
|
31
24
|
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
25
|
+
const fallOverWithStyle = (errorMessage) => {
|
|
26
|
+
setComponentToRender(renderPlaceholder({
|
|
27
|
+
config,
|
|
28
|
+
callbacks,
|
|
29
|
+
errorMessage: errorMessage || "Cannot load CAPTCHA",
|
|
30
|
+
}));
|
|
31
|
+
};
|
|
32
|
+
const restartComponentTimeout = () => {
|
|
33
|
+
setTimeout(() => {
|
|
34
|
+
resetState(0);
|
|
35
|
+
events.onReset();
|
|
36
|
+
restart();
|
|
37
|
+
}, 10000);
|
|
38
|
+
};
|
|
39
|
+
const start = async () => {
|
|
40
|
+
await providerRetry(async () => {
|
|
41
|
+
stateRef.current.attemptCount += 1;
|
|
42
|
+
const configOutput = ProcaptchaConfigSchema.parse(config);
|
|
43
|
+
const result = await detectBot(configOutput);
|
|
44
|
+
if (result.error?.message) {
|
|
45
|
+
stateRef.current = {
|
|
46
|
+
...stateRef.current,
|
|
47
|
+
loading: false,
|
|
48
|
+
errorMessage: result.error?.message,
|
|
44
49
|
};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
else {
|
|
49
|
-
setComponentToRender(_jsx(ProcaptchaPow, { config: config, callbacks: callbacks, frictionlessState: frictionlessState }));
|
|
50
|
-
}
|
|
50
|
+
events.onError(new Error(result.error?.message));
|
|
51
|
+
fallOverWithStyle(result.error?.message);
|
|
52
|
+
return;
|
|
51
53
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
const frictionlessState = {
|
|
55
|
+
provider: result.provider,
|
|
56
|
+
sessionId: result.sessionId,
|
|
57
|
+
userAccount: result.userAccount,
|
|
58
|
+
restart,
|
|
59
|
+
};
|
|
60
|
+
if (result.captchaType === "image") {
|
|
61
|
+
setComponentToRender(_jsx(Procaptcha, { config: config, callbacks: callbacks, frictionlessState: frictionlessState }));
|
|
55
62
|
}
|
|
63
|
+
else {
|
|
64
|
+
setComponentToRender(_jsx(ProcaptchaPow, { config: config, callbacks: callbacks, frictionlessState: frictionlessState }));
|
|
65
|
+
stateRef.current = {
|
|
66
|
+
...stateRef.current,
|
|
67
|
+
loading: false,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}, start, resetState, stateRef.current.attemptCount, 5).finally(() => {
|
|
71
|
+
if (stateRef.current.attemptCount >= 5) {
|
|
72
|
+
fallOverWithStyle();
|
|
73
|
+
restartComponentTimeout();
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
const detectAndSetComponent = async () => {
|
|
79
|
+
await start();
|
|
56
80
|
};
|
|
57
81
|
detectAndSetComponent();
|
|
58
82
|
}, [config, callbacks, detectBot, config.language]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProcaptchaFrictionless.js","sourceRoot":"","sources":["../src/ProcaptchaFrictionless.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"ProcaptchaFrictionless.js","sourceRoot":"","sources":["../src/ProcaptchaFrictionless.tsx"],"names":[],"mappings":";AAcA,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAEN,sBAAsB,GAGtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM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B,CACnB,KAAC,aAAa,IACb,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,SAAS,EACpB,iBAAiB,EAAE,iBAAiB,GACnC,CACF,CAAC;gBAEF,QAAQ,CAAC,OAAO,GAAG;oBAClB,GAAG,QAAQ,CAAC,OAAO;oBACnB,OAAO,EAAE,KAAK;iBACd,CAAC;YACH,CAAC;QACF,CAAC,EACD,KAAK,EACL,UAAU,EACV,QAAQ,CAAC,OAAO,CAAC,YAAY,EAC7B,CAAC,CACD,CAAC,OAAO,CAAC,GAAG,EAAE;YACd,IAAI,QAAQ,CAAC,OAAO,CAAC,YAAY,IAAI,CAAC,EAAE,CAAC;gBACxC,iBAAiB,EAAE,CAAC;gBACpB,uBAAuB,EAAE,CAAC;YAC3B,CAAC;QACF,CAAC,CAAC,CAAC;IACJ,CAAC,CAAC;IAGF,SAAS,CAAC,GAAG,EAAE;QACd,MAAM,qBAAqB,GAAG,KAAK,IAAI,EAAE;YACxC,MAAM,KAAK,EAAE,CAAC;QACf,CAAC,CAAC;QAEF,qBAAqB,EAAE,CAAC;IACzB,CAAC,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEpD,OAAO,iBAAiB,CAAC;AAC1B,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"customDetectBot.d.ts","sourceRoot":"","sources":["../src/customDetectBot.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EACX,oBAAoB,EAEpB,MAAM,gBAAgB,CAAC;AAIxB,QAAA,MAAM,eAAe,EAAE,oBAiCtB,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ProviderApi } from "@prosopo/api";
|
|
2
|
+
import { ProsopoEnvError } from "@prosopo/common";
|
|
3
|
+
import { getRandomActiveProvider } from "@prosopo/procaptcha-common";
|
|
4
|
+
import { ExtensionLoader } from "@prosopo/procaptcha-common";
|
|
5
|
+
import { DetectorLoader } from "./detectorLoader.js";
|
|
6
|
+
const customDetectBot = async (config) => {
|
|
7
|
+
const detect = await DetectorLoader();
|
|
8
|
+
const botScore = await detect();
|
|
9
|
+
const ext = new (await ExtensionLoader(config.web2))();
|
|
10
|
+
const userAccount = await ext.getAccount(config);
|
|
11
|
+
if (!config.account.address) {
|
|
12
|
+
throw new ProsopoEnvError("GENERAL.SITE_KEY_MISSING");
|
|
13
|
+
}
|
|
14
|
+
const provider = await getRandomActiveProvider(config);
|
|
15
|
+
const providerApi = new ProviderApi(provider.provider.url, config.account.address);
|
|
16
|
+
const captcha = await providerApi.getFrictionlessCaptcha(botScore.token, config.account.address, userAccount.account.address);
|
|
17
|
+
return {
|
|
18
|
+
captchaType: captcha.captchaType,
|
|
19
|
+
sessionId: captcha.sessionId,
|
|
20
|
+
provider: provider,
|
|
21
|
+
status: captcha.status,
|
|
22
|
+
userAccount: userAccount,
|
|
23
|
+
error: captcha.error,
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export default customDetectBot;
|
|
27
|
+
//# sourceMappingURL=customDetectBot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"customDetectBot.js","sourceRoot":"","sources":["../src/customDetectBot.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAM7D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,MAAM,eAAe,GAAyB,KAAK,EAClD,MAAoC,EACE,EAAE;IACxC,MAAM,MAAM,GAAG,MAAM,cAAc,EAAE,CAAC;IACtC,MAAM,QAAQ,GAAsB,MAAM,MAAM,EAAE,CAAC;IACnD,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;IACvD,MAAM,WAAW,GAAG,MAAM,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IAEjD,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QAC7B,MAAM,IAAI,eAAe,CAAC,0BAA0B,CAAC,CAAC;IACvD,CAAC;IAGD,MAAM,QAAQ,GAAG,MAAM,uBAAuB,CAAC,MAAM,CAAC,CAAC;IACvD,MAAM,WAAW,GAAG,IAAI,WAAW,CAClC,QAAQ,CAAC,QAAQ,CAAC,GAAG,EACrB,MAAM,CAAC,OAAO,CAAC,OAAO,CACtB,CAAC;IAEF,MAAM,OAAO,GAAG,MAAM,WAAW,CAAC,sBAAsB,CACvD,QAAQ,CAAC,KAAK,EACd,MAAM,CAAC,OAAO,CAAC,OAAO,EACtB,WAAW,CAAC,OAAO,CAAC,OAAO,CAC3B,CAAC;IAEF,OAAO;QACN,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,QAAQ,EAAE,QAAQ;QAClB,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,WAAW,EAAE,WAAW;QACxB,KAAK,EAAE,OAAO,CAAC,KAAK;KACpB,CAAC;AACH,CAAC,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detectorLoader.d.ts","sourceRoot":"","sources":["../src/detectorLoader.ts"],"names":[],"mappings":"AAcA,KAAK,YAAY,GAAG,cAAc,mBAAmB,EAAE,OAAO,CAAC;AAE/D,eAAO,MAAM,cAAc,QAAa,OAAO,CAAC,YAAY,CAChB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detectorLoader.js","sourceRoot":"","sources":["../src/detectorLoader.ts"],"names":[],"mappings":"AAgBA,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,IAA2B,EAAE,CAC/D,CAAC,MAAM,MAAM,CAAC,mBAAmB,CAAC,CAAC,CAAC,OAAO,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prosopo/procaptcha-frictionless",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.2",
|
|
4
4
|
"author": "PROSOPO LIMITED <info@prosopo.io>",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -26,17 +26,17 @@
|
|
|
26
26
|
},
|
|
27
27
|
"browserslist": ["> 0.5%, last 2 versions, not dead"],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@prosopo/detector": "2.
|
|
30
|
-
"@prosopo/locale
|
|
31
|
-
"@prosopo/procaptcha-pow": "2.
|
|
32
|
-
"@prosopo/procaptcha-react": "2.
|
|
33
|
-
"@prosopo/types": "2.
|
|
34
|
-
"@prosopo/web-components": "2.
|
|
35
|
-
"express": "4.21.
|
|
29
|
+
"@prosopo/detector": "2.4.2",
|
|
30
|
+
"@prosopo/locale": "2.4.2",
|
|
31
|
+
"@prosopo/procaptcha-pow": "2.4.2",
|
|
32
|
+
"@prosopo/procaptcha-react": "2.4.2",
|
|
33
|
+
"@prosopo/types": "2.4.2",
|
|
34
|
+
"@prosopo/web-components": "2.4.2",
|
|
35
|
+
"express": "4.21.2",
|
|
36
36
|
"react": "18.3.1"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@prosopo/config": "2.
|
|
39
|
+
"@prosopo/config": "2.4.2",
|
|
40
40
|
"@vitest/coverage-v8": "2.1.1",
|
|
41
41
|
"concurrently": "9.0.1",
|
|
42
42
|
"del-cli": "6.0.0",
|
package/vite.cjs.config.ts
CHANGED