@prosopo/procaptcha-bundle 3.2.10 → 4.1.7
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 +28 -35
- package/.turbo/turbo-build$colon$tsc.log +80 -0
- package/.turbo/turbo-build.log +33 -36
- package/CHANGELOG.md +575 -0
- package/dist/cjs/index.cjs +4 -9
- package/dist/cjs/util/captcha/captchaRenderer.cjs +10 -9
- package/dist/cjs/util/captcha/components/{frictionlessCaptcha.cjs → bundleCaptcha.cjs} +2 -2
- package/dist/cjs/util/config.cjs +14 -4
- package/dist/cjs/util/widgetFactory.cjs +4 -6
- package/dist/components.d.ts +2 -0
- package/dist/components.d.ts.map +1 -0
- package/dist/components.js +2 -0
- package/dist/components.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -9
- package/dist/index.js.map +1 -0
- package/dist/tests/procaptchaReady.unit.test.d.ts +2 -0
- package/dist/tests/procaptchaReady.unit.test.d.ts.map +1 -0
- package/dist/tests/procaptchaReady.unit.test.js +32 -0
- package/dist/tests/procaptchaReady.unit.test.js.map +1 -0
- package/dist/tests/util/config.test.d.ts +2 -0
- package/dist/tests/util/config.test.d.ts.map +1 -0
- package/dist/tests/util/config.test.js +69 -0
- package/dist/tests/util/config.test.js.map +1 -0
- package/dist/tests/util/renderLogic.test.d.ts +2 -0
- package/dist/tests/util/renderLogic.test.d.ts.map +1 -0
- package/dist/tests/util/renderLogic.test.js +144 -0
- package/dist/tests/util/renderLogic.test.js.map +1 -0
- package/dist/util/captcha/captchaRenderer.d.ts +19 -0
- package/dist/util/captcha/captchaRenderer.d.ts.map +1 -0
- package/dist/util/captcha/captchaRenderer.js +10 -9
- package/dist/util/captcha/captchaRenderer.js.map +1 -0
- package/dist/util/captcha/components/bundleCaptcha.d.ts +11 -0
- package/dist/util/captcha/components/bundleCaptcha.d.ts.map +1 -0
- package/dist/util/captcha/components/{frictionlessCaptcha.js → bundleCaptcha.js} +2 -2
- package/dist/util/captcha/components/bundleCaptcha.js.map +1 -0
- package/dist/util/config.d.ts +6 -0
- package/dist/util/config.d.ts.map +1 -0
- package/dist/util/config.js +14 -4
- package/dist/util/config.js.map +1 -0
- package/dist/util/configCreator.d.ts +5 -0
- package/dist/util/configCreator.d.ts.map +1 -0
- package/dist/util/configCreator.js.map +1 -0
- package/dist/util/language.d.ts +3 -0
- package/dist/util/language.d.ts.map +1 -0
- package/dist/util/language.js.map +1 -0
- package/dist/util/timeout.d.ts +3 -0
- package/dist/util/timeout.d.ts.map +1 -0
- package/dist/util/timeout.js.map +1 -0
- package/dist/util/widgetFactory.d.ts +18 -0
- package/dist/util/widgetFactory.d.ts.map +1 -0
- package/dist/util/widgetFactory.js +4 -6
- package/dist/util/widgetFactory.js.map +1 -0
- package/dist/util/widgetThemeResolver.d.ts +9 -0
- package/dist/util/widgetThemeResolver.d.ts.map +1 -0
- package/dist/util/widgetThemeResolver.js.map +1 -0
- package/package.json +14 -13
- package/src/components.ts +15 -0
- package/src/index.html +11 -0
- package/src/index.ts +259 -0
- package/src/tests/procaptchaReady.unit.test.ts +58 -0
- package/src/tests/util/config.test.ts +97 -0
- package/src/tests/util/renderLogic.test.tsx +221 -0
- package/src/util/captcha/captchaRenderer.tsx +126 -0
- package/src/util/captcha/components/bundleCaptcha.tsx +57 -0
- package/src/util/config.ts +40 -0
- package/src/util/configCreator.ts +51 -0
- package/src/util/language.ts +53 -0
- package/src/util/timeout.ts +43 -0
- package/src/util/widgetFactory.ts +145 -0
- package/src/util/widgetThemeResolver.ts +40 -0
- package/tsconfig.cjs.json +35 -0
- package/tsconfig.json +42 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/tsconfig.types.json +9 -0
- package/vite.cjs.config.ts +1 -1
- package/vite.config.ts +23 -2
- package/vite.esm.config.ts +1 -1
- package/vite.iife.config.ts +119 -0
- package/vite.serve.config.ts +23 -1
- package/vite.test.config.ts +1 -1
- package/webpack.config.cjs +1 -1
- package/dist/cjs/util/captcha/captchaComponentProvider.cjs +0 -24
- package/dist/cjs/util/captcha/captchaComponentsList.cjs +0 -12
- package/dist/cjs/util/captcha/captchaType.cjs +0 -12
- package/dist/cjs/util/captcha/components/imageCaptcha.cjs +0 -17
- package/dist/cjs/util/captcha/components/powCaptcha.cjs +0 -17
- package/dist/util/captcha/captchaComponentProvider.js +0 -24
- package/dist/util/captcha/captchaComponentsList.js +0 -12
- package/dist/util/captcha/captchaType.js +0 -12
- package/dist/util/captcha/components/imageCaptcha.js +0 -17
- package/dist/util/captcha/components/powCaptcha.js +0 -17
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configCreator.js","sourceRoot":"","sources":["../../src/util/configCreator.ts"],"names":[],"mappings":"AAeA,OAAO,EACN,sBAAsB,EAEtB,sBAAsB,GACtB,MAAM,gBAAgB,CAAC;AAExB,SAAS,YAAY,CACpB,OAAgB,EAChB,QAA0B,OAAO,EACjC,QAAqD,EACrD,IAAI,GAAG,IAAI,EACX,SAAS,GAAG,KAAK,EACjB,kBAA2B;IAE3B,IAAI,CAAC,OAAO,EAAE,CAAC;QACd,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,IAAI,EAAE,CAAC;IAC9C,CAAC;IAED,OAAO,sBAAsB,CAAC,KAAK,CAAC;QACnC,kBAAkB,EAAE,OAAO,CAAC,GAAG,CAAC,2BAA2B;YAC1D,CAAC,CAAC,sBAAsB,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC;YACvE,CAAC,CAAC,sBAAsB,CAAC,IAAI,CAAC,WAAW;QAC1C,kBAAkB,EAAE,kBAAkB,IAAI,EAAE;QAC5C,OAAO,EAAE;YACR,OAAO,EAAE,OAAO;SAChB;QACD,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,EAAE;QAC/C,aAAa,EAAE,OAAO,CAAC,GAAG,CAAC,wBAAwB,IAAI,EAAE;QACzD,IAAI;QACJ,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS;QACzC,KAAK;QACL,QAAQ;KACR,CAAC,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ProcaptchaClientConfigInput, ProcaptchaRenderOptions } from "@prosopo/types";
|
|
2
|
+
export declare const setLanguage: (renderOptions: ProcaptchaRenderOptions | undefined, element: Element, config: ProcaptchaClientConfigInput) => void;
|
|
3
|
+
//# sourceMappingURL=language.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"language.d.ts","sourceRoot":"","sources":["../../src/util/language.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EACX,2BAA2B,EAC3B,uBAAuB,EACvB,MAAM,gBAAgB,CAAC;AAcxB,eAAO,MAAM,WAAW,kBACR,uBAAuB,GAAG,SAAS,WACzC,OAAO,UACR,2BAA2B,SAQnC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"language.js","sourceRoot":"","sources":["../../src/util/language.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,cAAc,EAAkB,MAAM,iBAAiB,CAAC;AAkBjE,MAAM,CAAC,MAAM,WAAW,GAAG,CAC1B,aAAkD,EAClD,OAAgB,EAChB,MAAmC,EAClC,EAAE;IACH,MAAM,iBAAiB,GACtB,aAAa,EAAE,QAAQ,IAAI,OAAO,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC;IAElE,IAAI,iBAAiB,EAAE,CAAC;QACvB,MAAM,CAAC,QAAQ,GAAG,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;IACvD,CAAC;AACF,CAAC,CAAC;AAEF,MAAM,gBAAgB,GAAG,CAAC,iBAA4C,EAAE,EAAE;IACzE,IAAI,CAAC;QACJ,OAAO,cAAc,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;IAChD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,OAAO,CAAC,KAAK,CAAC,+BAA+B,iBAAiB,EAAE,CAAC,CAAC;QAClE,OAAO,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;AACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ProcaptchaClientConfigOutput, ProcaptchaRenderOptions } from "@prosopo/types";
|
|
2
|
+
export declare const setValidChallengeLength: (renderOptions: ProcaptchaRenderOptions | undefined, element: Element, config: ProcaptchaClientConfigOutput) => void;
|
|
3
|
+
//# sourceMappingURL=timeout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeout.d.ts","sourceRoot":"","sources":["../../src/util/timeout.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EACX,4BAA4B,EAC5B,uBAAuB,EACvB,MAAM,gBAAgB,CAAC;AASxB,eAAO,MAAM,uBAAuB,kBACpB,uBAAuB,GAAG,SAAS,WACzC,OAAO,UACR,4BAA4B,KAClC,IAaF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeout.js","sourceRoot":"","sources":["../../src/util/timeout.ts"],"names":[],"mappings":"AAyBA,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACtC,aAAkD,EAClD,OAAgB,EAChB,MAAoC,EAC7B,EAAE;IACT,MAAM,6BAA6B,GAClC,aAAa,EAAE,CAAC,wBAAwB,CAAC;QACzC,OAAO,CAAC,YAAY,CAAC,6BAA6B,CAAC,CAAC;IAErD,IAAI,6BAA6B,EAAE,CAAC;QACnC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,eAAe,GAAG,MAAM,CAAC,QAAQ,CACtD,6BAA6B,CAC7B,CAAC;QACF,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,eAAe,GAAG,MAAM,CAAC,QAAQ,CACpD,6BAA6B,CAC7B,CAAC;IACH,CAAC;AACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Ti18n } from "@prosopo/locale";
|
|
2
|
+
import type { Callbacks, ProcaptchaRenderOptions } from "@prosopo/types";
|
|
3
|
+
import type { Root } from "react-dom/client";
|
|
4
|
+
import type { CaptchaRenderer } from "./captcha/captchaRenderer.js";
|
|
5
|
+
import type { WidgetThemeResolver } from "./widgetThemeResolver.js";
|
|
6
|
+
declare class WidgetFactory {
|
|
7
|
+
private readonly widgetThemeResolver;
|
|
8
|
+
private captchaRenderer;
|
|
9
|
+
private _i18n;
|
|
10
|
+
constructor(widgetThemeResolver: WidgetThemeResolver);
|
|
11
|
+
get i18n(): Ti18n;
|
|
12
|
+
createWidgets(containers: Element[], renderOptions: ProcaptchaRenderOptions, isWeb2?: boolean, invisible?: boolean): Promise<Root[]>;
|
|
13
|
+
createWidget(container: Element, renderOptions: ProcaptchaRenderOptions, callbacks: Callbacks, isWeb2?: boolean, invisible?: boolean): Promise<Root>;
|
|
14
|
+
protected getCaptchaRenderer(): Promise<CaptchaRenderer>;
|
|
15
|
+
protected createCaptchaRenderer(): Promise<CaptchaRenderer>;
|
|
16
|
+
}
|
|
17
|
+
export { WidgetFactory };
|
|
18
|
+
//# sourceMappingURL=widgetFactory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widgetFactory.d.ts","sourceRoot":"","sources":["../../src/util/widgetFactory.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAK7C,OAAO,KAAK,EAAE,SAAS,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAMzE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAEpE,cAAM,aAAa;IAKjB,OAAO,CAAC,QAAQ,CAAC,mBAAmB;IAJrC,OAAO,CAAC,eAAe,CAAgC;IACvD,OAAO,CAAC,KAAK,CAAsB;gBAGjB,mBAAmB,EAAE,mBAAmB;IAG1D,IAAI,IAAI,IAAI,KAAK,CAKhB;IAEY,aAAa,CACzB,UAAU,EAAE,OAAO,EAAE,EACrB,aAAa,EAAE,uBAAuB,EACtC,MAAM,UAAO,EACb,SAAS,UAAQ,GACf,OAAO,CAAC,IAAI,EAAE,CAAC;IAgBL,YAAY,CACxB,SAAS,EAAE,OAAO,EAClB,aAAa,EAAE,uBAAuB,EACtC,SAAS,EAAE,SAAS,EACpB,MAAM,UAAO,EACb,SAAS,UAAQ,GACf,OAAO,CAAC,IAAI,CAAC;cAoDA,kBAAkB,IAAI,OAAO,CAAC,eAAe,CAAC;cAY9C,qBAAqB,IAAI,OAAO,CAAC,eAAe,CAAC;CAMjE;AAED,OAAO,EAAE,aAAa,EAAE,CAAC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { loadI18next } from "@prosopo/locale";
|
|
2
2
|
import { getDefaultCallbacks, setUserCallbacks } from "@prosopo/procaptcha-common";
|
|
3
|
-
import { CaptchaType } from "@prosopo/types";
|
|
4
3
|
import { lightTheme, darkTheme, createWidgetSkeleton } from "@prosopo/widget-skeleton";
|
|
5
4
|
class WidgetFactory {
|
|
6
5
|
constructor(widgetThemeResolver) {
|
|
@@ -56,8 +55,7 @@ class WidgetFactory {
|
|
|
56
55
|
{
|
|
57
56
|
identifierPrefix: "procaptcha-",
|
|
58
57
|
emotionCacheKey: "procaptcha",
|
|
59
|
-
webComponentTag: "prosopo-procaptcha"
|
|
60
|
-
defaultCaptchaType: CaptchaType.frictionless
|
|
58
|
+
webComponentTag: "prosopo-procaptcha"
|
|
61
59
|
},
|
|
62
60
|
widgetInteractiveArea,
|
|
63
61
|
renderOptions,
|
|
@@ -65,7 +63,8 @@ class WidgetFactory {
|
|
|
65
63
|
isWeb2,
|
|
66
64
|
this.i18n,
|
|
67
65
|
invisible,
|
|
68
|
-
widgetContainer
|
|
66
|
+
widgetContainer,
|
|
67
|
+
container
|
|
69
68
|
);
|
|
70
69
|
return captchaRoot;
|
|
71
70
|
}
|
|
@@ -80,8 +79,7 @@ class WidgetFactory {
|
|
|
80
79
|
}
|
|
81
80
|
async createCaptchaRenderer() {
|
|
82
81
|
const CaptchaRenderer = (await import("./captcha/captchaRenderer.js")).CaptchaRenderer;
|
|
83
|
-
|
|
84
|
-
return new CaptchaRenderer(new CaptchaComponentProvider());
|
|
82
|
+
return new CaptchaRenderer();
|
|
85
83
|
}
|
|
86
84
|
}
|
|
87
85
|
export {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widgetFactory.js","sourceRoot":"","sources":["../../src/util/widgetFactory.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ProcaptchaRenderOptions } from "@prosopo/types";
|
|
2
|
+
declare class WidgetThemeResolver {
|
|
3
|
+
private readonly themesSet;
|
|
4
|
+
private readonly defaultTheme;
|
|
5
|
+
resolveWidgetTheme(element: Element, renderOptions: ProcaptchaRenderOptions): "light" | "dark";
|
|
6
|
+
protected validateTheme(themeAttribute: string): "light" | "dark";
|
|
7
|
+
}
|
|
8
|
+
export { WidgetThemeResolver };
|
|
9
|
+
//# sourceMappingURL=widgetThemeResolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widgetThemeResolver.d.ts","sourceRoot":"","sources":["../../src/util/widgetThemeResolver.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAE9D,cAAM,mBAAmB;IACxB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA8B;IACxD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAW;IAEjC,kBAAkB,CACxB,OAAO,EAAE,OAAO,EAChB,aAAa,EAAE,uBAAuB,GACpC,OAAO,GAAG,MAAM;IASnB,SAAS,CAAC,aAAa,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,GAAG,MAAM;CAKjE;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widgetThemeResolver.js","sourceRoot":"","sources":["../../src/util/widgetThemeResolver.ts"],"names":[],"mappings":"AAgBA,MAAM,mBAAmB;IAAzB;QACkB,cAAS,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;QACvC,iBAAY,GAAG,OAAO,CAAC;IAmBzC,CAAC;IAjBO,kBAAkB,CACxB,OAAgB,EAChB,aAAsC;QAEtC,MAAM,cAAc,GACnB,aAAa,CAAC,KAAK;YACnB,OAAO,CAAC,YAAY,CAAC,YAAY,CAAC;YAClC,IAAI,CAAC,YAAY,CAAC;QAEnB,OAAO,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC;IAC3C,CAAC;IAES,aAAa,CAAC,cAAsB;QAC7C,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,cAAc,CAAC;YACxC,CAAC,CAAE,cAAmC;YACtC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC;IACtB,CAAC;CACD;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prosopo/procaptcha-bundle",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.1.7",
|
|
4
4
|
"author": "PROSOPO LIMITED <info@prosopo.io>",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -25,11 +25,13 @@
|
|
|
25
25
|
"source": "./src/index.tsx",
|
|
26
26
|
"scripts": {
|
|
27
27
|
"clean": "del-cli --verbose dist tsconfig.tsbuildinfo",
|
|
28
|
-
"build": "
|
|
28
|
+
"build": "npm run build:cross-env -- --mode ${NODE_ENV:-development}",
|
|
29
|
+
"build:cross-env": "vite build --config vite.esm.config.ts",
|
|
29
30
|
"build:tsc": "tsc --build --verbose",
|
|
30
31
|
"build:cjs": "NODE_ENV=${NODE_ENV:-development}; vite build --config vite.cjs.config.ts --mode $NODE_ENV",
|
|
31
32
|
"typecheck": "tsc --project tsconfig.types.json",
|
|
32
33
|
"bundle": "NODE_ENV=${NODE_ENV:-development}; vite build --config vite.config.ts --mode $NODE_ENV",
|
|
34
|
+
"bundle:iife": "NODE_ENV=${NODE_ENV:-development}; vite build --config vite.iife.config.ts --mode $NODE_ENV",
|
|
33
35
|
"start": "NODE_ENV=${NODE_ENV:-development}; vite serve --mode $NODE_ENV --host",
|
|
34
36
|
"bundle:webpack": "NODE_ENV=${NODE_ENV:-development}; MODE=${MODE:-$NODE_ENV}; webpack build --config webpack.config.cjs --mode $MODE",
|
|
35
37
|
"serve": "NODE_ENV=${NODE_ENV:-development}; vite serve --config vite.serve.config.ts --mode $NODE_ENV --host",
|
|
@@ -37,15 +39,13 @@
|
|
|
37
39
|
},
|
|
38
40
|
"browserslist": ["> 0.5%, last 2 versions, not dead"],
|
|
39
41
|
"dependencies": {
|
|
40
|
-
"@prosopo/dotenv": "3.0.
|
|
41
|
-
"@prosopo/locale": "3.
|
|
42
|
-
"@prosopo/procaptcha-common": "2.
|
|
43
|
-
"@prosopo/procaptcha-frictionless": "2.
|
|
44
|
-
"@prosopo/
|
|
45
|
-
"@prosopo/
|
|
46
|
-
"@prosopo/
|
|
47
|
-
"@prosopo/util": "3.2.4",
|
|
48
|
-
"@prosopo/widget-skeleton": "2.7.12",
|
|
42
|
+
"@prosopo/dotenv": "3.0.43",
|
|
43
|
+
"@prosopo/locale": "3.2.4",
|
|
44
|
+
"@prosopo/procaptcha-common": "2.10.17",
|
|
45
|
+
"@prosopo/procaptcha-frictionless": "2.11.0",
|
|
46
|
+
"@prosopo/types": "4.3.0",
|
|
47
|
+
"@prosopo/util": "3.2.15",
|
|
48
|
+
"@prosopo/widget-skeleton": "2.8.3",
|
|
49
49
|
"dotenv": "16.4.5",
|
|
50
50
|
"fast-glob": "3.3.2",
|
|
51
51
|
"jsdom": "25.0.0",
|
|
@@ -56,7 +56,8 @@
|
|
|
56
56
|
},
|
|
57
57
|
"repository": {
|
|
58
58
|
"type": "git",
|
|
59
|
-
"url": "git+https://github.com/prosopo/captcha.git"
|
|
59
|
+
"url": "git+https://github.com/prosopo/captcha.git",
|
|
60
|
+
"directory": "packages/procaptcha-bundle"
|
|
60
61
|
},
|
|
61
62
|
"bugs": {
|
|
62
63
|
"url": "https://github.com/prosopo/captcha/issues"
|
|
@@ -67,7 +68,7 @@
|
|
|
67
68
|
"registry": "https://registry.npmjs.org"
|
|
68
69
|
},
|
|
69
70
|
"devDependencies": {
|
|
70
|
-
"@prosopo/config": "3.1
|
|
71
|
+
"@prosopo/config": "3.3.1",
|
|
71
72
|
"@types/jsdom": "21.1.7",
|
|
72
73
|
"@types/node": "22.10.2",
|
|
73
74
|
"@types/react": "18.3.1",
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Copyright 2021-2026 Prosopo (UK) Ltd.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
export * from "./util/captcha/components/bundleCaptcha.js";
|
package/src/index.html
ADDED
package/src/index.ts
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
// Copyright 2021-2026 Prosopo (UK) Ltd.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
import { getWindowCallback } from "@prosopo/procaptcha-common";
|
|
16
|
+
import type { ProcaptchaRenderOptions } from "@prosopo/types";
|
|
17
|
+
import { at } from "@prosopo/util";
|
|
18
|
+
import type { Root } from "react-dom/client";
|
|
19
|
+
import { extractParams, getProcaptchaScript } from "./util/config.js";
|
|
20
|
+
import { WidgetFactory } from "./util/widgetFactory.js";
|
|
21
|
+
import { WidgetThemeResolver } from "./util/widgetThemeResolver.js";
|
|
22
|
+
|
|
23
|
+
const BUNDLE_NAMES = ["procaptcha.bundle.iife.js", "procaptcha.bundle.js"];
|
|
24
|
+
let procaptchaRoots: Root[] = [];
|
|
25
|
+
|
|
26
|
+
const widgetFactory = new WidgetFactory(new WidgetThemeResolver());
|
|
27
|
+
|
|
28
|
+
// Define a custom event name for procaptcha execution
|
|
29
|
+
const PROCAPTCHA_EXECUTE_EVENT = "procaptcha:execute";
|
|
30
|
+
|
|
31
|
+
// Define a custom event name for procaptcha ready
|
|
32
|
+
const PROCAPTCHA_READY_EVENT = "procaptcha:ready";
|
|
33
|
+
|
|
34
|
+
// Implicit render for targeting all elements with class 'procaptcha'
|
|
35
|
+
const implicitRender = async () => {
|
|
36
|
+
// Get elements with class 'procaptcha', not including buttons
|
|
37
|
+
const elements: Element[] = Array.from(
|
|
38
|
+
document.getElementsByClassName("procaptcha"),
|
|
39
|
+
).filter((element) => element.tagName.toLowerCase() !== "button");
|
|
40
|
+
|
|
41
|
+
// Set siteKey from renderOptions or from the first element's data-sitekey attribute
|
|
42
|
+
if (elements.length) {
|
|
43
|
+
const siteKey = at(elements, 0).getAttribute("data-sitekey");
|
|
44
|
+
const web3 = at(elements, 0).getAttribute("data-web3");
|
|
45
|
+
if (!siteKey) {
|
|
46
|
+
console.error("No site key found");
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const root = await widgetFactory.createWidgets(
|
|
51
|
+
elements,
|
|
52
|
+
{
|
|
53
|
+
siteKey: siteKey,
|
|
54
|
+
},
|
|
55
|
+
!(web3 === "true"),
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
procaptchaRoots.push(...root);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Check for invisible mode indicators (procaptcha class on buttons)
|
|
62
|
+
const invisibleButtons = Array.from(
|
|
63
|
+
document.getElementsByClassName("procaptcha"),
|
|
64
|
+
).filter((button) => button.tagName.toLowerCase() === "button");
|
|
65
|
+
|
|
66
|
+
if (invisibleButtons.length) {
|
|
67
|
+
for (const button of invisibleButtons) {
|
|
68
|
+
const siteKey = button.getAttribute("data-sitekey") || "";
|
|
69
|
+
const callback = button.getAttribute("data-callback") || "";
|
|
70
|
+
|
|
71
|
+
const root = await widgetFactory.createWidgets(
|
|
72
|
+
[button],
|
|
73
|
+
{
|
|
74
|
+
siteKey: siteKey,
|
|
75
|
+
callback: callback,
|
|
76
|
+
},
|
|
77
|
+
true,
|
|
78
|
+
true,
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
procaptchaRoots.push(...root);
|
|
82
|
+
|
|
83
|
+
// Add click event listener to the button
|
|
84
|
+
button.addEventListener("click", async (event) => {
|
|
85
|
+
event.preventDefault();
|
|
86
|
+
execute();
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// Explicit render for targeting specific elements
|
|
93
|
+
export const render = async (
|
|
94
|
+
element: Element,
|
|
95
|
+
renderOptions: ProcaptchaRenderOptions,
|
|
96
|
+
) => {
|
|
97
|
+
const hasInvisibleSize =
|
|
98
|
+
Object.prototype.hasOwnProperty.call(renderOptions, "size") &&
|
|
99
|
+
renderOptions.size === "invisible";
|
|
100
|
+
|
|
101
|
+
const isWeb2 = !renderOptions.web3;
|
|
102
|
+
|
|
103
|
+
if (hasInvisibleSize || element.tagName.toLowerCase() === "button") {
|
|
104
|
+
const roots = await widgetFactory.createWidgets(
|
|
105
|
+
[element],
|
|
106
|
+
renderOptions,
|
|
107
|
+
isWeb2,
|
|
108
|
+
true,
|
|
109
|
+
);
|
|
110
|
+
procaptchaRoots.push(...roots);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const roots = await widgetFactory.createWidgets(
|
|
115
|
+
[element],
|
|
116
|
+
renderOptions,
|
|
117
|
+
isWeb2,
|
|
118
|
+
false,
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
procaptchaRoots.push(...roots);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
export default function ready(fn: () => void) {
|
|
125
|
+
if (document && document.readyState !== "loading") {
|
|
126
|
+
console.log("document.readyState ready!");
|
|
127
|
+
fn();
|
|
128
|
+
} else {
|
|
129
|
+
console.log("DOMContentLoaded listener!");
|
|
130
|
+
document.addEventListener("DOMContentLoaded", () => {
|
|
131
|
+
console.log("DOMContentLoaded fired");
|
|
132
|
+
console.log(window);
|
|
133
|
+
fn();
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export const execute = () => {
|
|
139
|
+
const containers = findProcaptchaContainers();
|
|
140
|
+
|
|
141
|
+
if (containers.length === 0) {
|
|
142
|
+
console.error("No Procaptcha containers found for execution");
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Dispatch a custom event to notify React components to show the modal or perform silent verification
|
|
147
|
+
const executeEvent = new CustomEvent(PROCAPTCHA_EXECUTE_EVENT, {
|
|
148
|
+
detail: {
|
|
149
|
+
containerId: containers[0]?.id || "procaptcha-container",
|
|
150
|
+
containerCount: containers.length,
|
|
151
|
+
timestamp: Date.now(),
|
|
152
|
+
},
|
|
153
|
+
bubbles: true,
|
|
154
|
+
cancelable: true,
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
// Dispatch the event on the document
|
|
158
|
+
document.dispatchEvent(executeEvent);
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
function findProcaptchaContainers(): Element[] {
|
|
162
|
+
const containers: Element[] = [];
|
|
163
|
+
|
|
164
|
+
// Strategy 1: Look for elements with data-size="invisible"
|
|
165
|
+
const invisibleContainers = Array.from(
|
|
166
|
+
document.querySelectorAll('[data-size="invisible"]'),
|
|
167
|
+
);
|
|
168
|
+
containers.push(...invisibleContainers);
|
|
169
|
+
|
|
170
|
+
// Strategy 2: Look for elements with specific IDs
|
|
171
|
+
const idContainers = Array.from(
|
|
172
|
+
document.querySelectorAll(
|
|
173
|
+
'#procaptcha-container, [id$="-procaptcha-container"]',
|
|
174
|
+
),
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
// Strategy 3: Look for elements with class 'p-procaptcha'
|
|
178
|
+
const classContainers = Array.from(
|
|
179
|
+
document.getElementsByClassName("p-procaptcha"),
|
|
180
|
+
);
|
|
181
|
+
containers.push(...classContainers);
|
|
182
|
+
|
|
183
|
+
for (const container of idContainers) {
|
|
184
|
+
if (!containers.includes(container)) {
|
|
185
|
+
containers.push(container);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return containers;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// extend the global Window interface to include the procaptcha object
|
|
193
|
+
declare global {
|
|
194
|
+
interface Window {
|
|
195
|
+
procaptcha: {
|
|
196
|
+
ready: typeof ready;
|
|
197
|
+
render: typeof render;
|
|
198
|
+
reset: typeof reset;
|
|
199
|
+
execute: typeof execute;
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const start = () => {
|
|
205
|
+
// onLoadUrlCallback defines the name of the callback function to be called when the script is loaded
|
|
206
|
+
// onRenderExplicit takes values of either explicit or implicit
|
|
207
|
+
const { onloadUrlCallback, renderExplicit } = extractParams(BUNDLE_NAMES);
|
|
208
|
+
let readyCalled = false;
|
|
209
|
+
|
|
210
|
+
// Render the Procaptcha component implicitly if renderExplicit is not set to explicit
|
|
211
|
+
if (renderExplicit !== "explicit") {
|
|
212
|
+
getProcaptchaScript(BUNDLE_NAMES)?.addEventListener("load", () => {
|
|
213
|
+
ready(implicitRender);
|
|
214
|
+
readyCalled = true;
|
|
215
|
+
});
|
|
216
|
+
// or if the document has already loaded, call the implicit render function
|
|
217
|
+
if (document.readyState === "complete" && !readyCalled) {
|
|
218
|
+
ready(implicitRender);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (onloadUrlCallback) {
|
|
223
|
+
// Add event listener to the script tag to call the callback function when the script is loaded
|
|
224
|
+
getProcaptchaScript(BUNDLE_NAMES)?.addEventListener("load", () => {
|
|
225
|
+
const onloadCallback = getWindowCallback(onloadUrlCallback);
|
|
226
|
+
ready(onloadCallback);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
// or if the document has already loaded, call the callback function
|
|
230
|
+
if (document.readyState === "complete" && !readyCalled) {
|
|
231
|
+
const onloadCallback = getWindowCallback(onloadUrlCallback);
|
|
232
|
+
ready(onloadCallback);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
export const reset = () => {
|
|
238
|
+
for (const root of procaptchaRoots) {
|
|
239
|
+
root.unmount();
|
|
240
|
+
}
|
|
241
|
+
procaptchaRoots = [];
|
|
242
|
+
|
|
243
|
+
start();
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
// set the procaptcha attribute on the window
|
|
247
|
+
window.procaptcha = { ready, render, reset, execute };
|
|
248
|
+
|
|
249
|
+
// Dispatch a custom event to notify that window.procaptcha is ready
|
|
250
|
+
const procaptchaReadyEvent = new CustomEvent(PROCAPTCHA_READY_EVENT, {
|
|
251
|
+
detail: {
|
|
252
|
+
timestamp: Date.now(),
|
|
253
|
+
},
|
|
254
|
+
bubbles: true,
|
|
255
|
+
cancelable: false,
|
|
256
|
+
});
|
|
257
|
+
document.dispatchEvent(procaptchaReadyEvent);
|
|
258
|
+
|
|
259
|
+
start();
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// Copyright 2021-2026 Prosopo (UK) Ltd.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
import { JSDOM } from "jsdom";
|
|
16
|
+
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
17
|
+
|
|
18
|
+
describe("procaptcha:ready event", () => {
|
|
19
|
+
let dom: JSDOM;
|
|
20
|
+
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
dom = new JSDOM("<!DOCTYPE html><html><body></body></html>", {
|
|
23
|
+
url: "https://example.com",
|
|
24
|
+
});
|
|
25
|
+
// @ts-ignore
|
|
26
|
+
global.document = dom.window.document;
|
|
27
|
+
// @ts-ignore
|
|
28
|
+
global.window = dom.window as unknown as Window & typeof globalThis;
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
afterEach(() => {
|
|
32
|
+
// biome-ignore lint/suspicious/noExplicitAny: TODO fix any
|
|
33
|
+
(global as any).document = undefined;
|
|
34
|
+
// biome-ignore lint/suspicious/noExplicitAny: TODO fix any
|
|
35
|
+
(global as any).window = undefined;
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("should dispatch procaptcha:ready event when window.procaptcha is set", (done) => {
|
|
39
|
+
// Set up event listener before importing the module
|
|
40
|
+
document.addEventListener("procaptcha:ready", (event: Event) => {
|
|
41
|
+
const customEvent = event as CustomEvent;
|
|
42
|
+
expect(customEvent.detail).toBeDefined();
|
|
43
|
+
expect(typeof customEvent.detail.timestamp).toBe("number");
|
|
44
|
+
expect(customEvent.bubbles).toBe(true);
|
|
45
|
+
expect(customEvent.cancelable).toBe(false);
|
|
46
|
+
|
|
47
|
+
// Check that window.procaptcha is available when the event fires
|
|
48
|
+
expect(window.procaptcha).toBeDefined();
|
|
49
|
+
expect(window.procaptcha?.render).toBeDefined();
|
|
50
|
+
expect(window.procaptcha?.ready).toBeDefined();
|
|
51
|
+
expect(window.procaptcha?.reset).toBeDefined();
|
|
52
|
+
expect(window.procaptcha?.execute).toBeDefined();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// Import the module which should set window.procaptcha and dispatch the event
|
|
56
|
+
import("../index.js");
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// Copyright 2021-2026 Prosopo (UK) Ltd.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
import { JSDOM } from "jsdom";
|
|
16
|
+
|
|
17
|
+
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
18
|
+
import { extractParams, getProcaptchaScript } from "../../util/config.js";
|
|
19
|
+
|
|
20
|
+
describe("Config utility functions", () => {
|
|
21
|
+
let dom: JSDOM;
|
|
22
|
+
|
|
23
|
+
beforeEach(() => {
|
|
24
|
+
dom = new JSDOM("<!DOCTYPE html><html><body></body></html>", {
|
|
25
|
+
url: "https://example.com",
|
|
26
|
+
});
|
|
27
|
+
global.document = dom.window.document;
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
afterEach(() => {
|
|
31
|
+
// biome-ignore lint/suspicious/noExplicitAny: TODO fix any
|
|
32
|
+
(global as any).document = undefined;
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
describe("getProcaptchaScript", () => {
|
|
36
|
+
it("should return null when no matching script is found", () => {
|
|
37
|
+
const result = getProcaptchaScript(["nonexistent"]);
|
|
38
|
+
expect(result).toBeNull();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("should return the script element when a matching script is found", () => {
|
|
42
|
+
const script = document.createElement("script");
|
|
43
|
+
script.src = "https://example.com/procaptcha.js";
|
|
44
|
+
document.body.appendChild(script);
|
|
45
|
+
|
|
46
|
+
const result = getProcaptchaScript(["procaptcha"]);
|
|
47
|
+
expect(result).toBe(script);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe("extractParams", () => {
|
|
52
|
+
it("should return undefined values when no matching script is found", () => {
|
|
53
|
+
const result = extractParams(["nonexistent"]);
|
|
54
|
+
expect(result).toEqual({
|
|
55
|
+
onloadUrlCallback: undefined,
|
|
56
|
+
renderExplicit: undefined,
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("should extract parameters from the script URL", () => {
|
|
61
|
+
const script = document.createElement("script");
|
|
62
|
+
script.src =
|
|
63
|
+
"https://example.com/procaptcha.js?onload=onloadCallback&render=explicit";
|
|
64
|
+
document.body.appendChild(script);
|
|
65
|
+
|
|
66
|
+
const result = extractParams(["procaptcha"]);
|
|
67
|
+
expect(result).toEqual({
|
|
68
|
+
onloadUrlCallback: "onloadCallback",
|
|
69
|
+
renderExplicit: "explicit",
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("should return undefined for missing parameters", () => {
|
|
74
|
+
const script = document.createElement("script");
|
|
75
|
+
script.src = "https://example.com/procaptcha.js?onload=onloadCallback";
|
|
76
|
+
document.body.appendChild(script);
|
|
77
|
+
|
|
78
|
+
const result = extractParams(["procaptcha"]);
|
|
79
|
+
expect(result).toEqual({
|
|
80
|
+
onloadUrlCallback: "onloadCallback",
|
|
81
|
+
renderExplicit: undefined,
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("should handle scripts without query parameters", () => {
|
|
86
|
+
const script = document.createElement("script");
|
|
87
|
+
script.src = "https://example.com/procaptcha.js";
|
|
88
|
+
document.body.appendChild(script);
|
|
89
|
+
|
|
90
|
+
const result = extractParams(["procaptcha"]);
|
|
91
|
+
expect(result).toEqual({
|
|
92
|
+
onloadUrlCallback: undefined,
|
|
93
|
+
renderExplicit: undefined,
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
});
|