@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,145 @@
|
|
|
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 { loadI18next } from "@prosopo/locale";
|
|
16
|
+
import type { Ti18n } from "@prosopo/locale";
|
|
17
|
+
import {
|
|
18
|
+
getDefaultCallbacks,
|
|
19
|
+
setUserCallbacks,
|
|
20
|
+
} from "@prosopo/procaptcha-common";
|
|
21
|
+
import type { Callbacks, ProcaptchaRenderOptions } from "@prosopo/types";
|
|
22
|
+
import {
|
|
23
|
+
createWidgetSkeleton,
|
|
24
|
+
darkTheme,
|
|
25
|
+
lightTheme,
|
|
26
|
+
} from "@prosopo/widget-skeleton";
|
|
27
|
+
import type { Root } from "react-dom/client";
|
|
28
|
+
import type { CaptchaRenderer } from "./captcha/captchaRenderer.js";
|
|
29
|
+
import type { WidgetThemeResolver } from "./widgetThemeResolver.js";
|
|
30
|
+
|
|
31
|
+
class WidgetFactory {
|
|
32
|
+
private captchaRenderer: CaptchaRenderer | null = null;
|
|
33
|
+
private _i18n: Ti18n | null = null;
|
|
34
|
+
|
|
35
|
+
public constructor(
|
|
36
|
+
private readonly widgetThemeResolver: WidgetThemeResolver,
|
|
37
|
+
) {}
|
|
38
|
+
|
|
39
|
+
get i18n(): Ti18n {
|
|
40
|
+
if (this._i18n === null) {
|
|
41
|
+
throw new Error("I18n is not initialized");
|
|
42
|
+
}
|
|
43
|
+
return this._i18n;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public async createWidgets(
|
|
47
|
+
containers: Element[],
|
|
48
|
+
renderOptions: ProcaptchaRenderOptions,
|
|
49
|
+
isWeb2 = true,
|
|
50
|
+
invisible = false,
|
|
51
|
+
): Promise<Root[]> {
|
|
52
|
+
return Promise.all(
|
|
53
|
+
containers.map((container) => {
|
|
54
|
+
const callbacks = getDefaultCallbacks(container);
|
|
55
|
+
setUserCallbacks(renderOptions, callbacks, container);
|
|
56
|
+
return this.createWidget(
|
|
57
|
+
container,
|
|
58
|
+
renderOptions,
|
|
59
|
+
callbacks,
|
|
60
|
+
isWeb2,
|
|
61
|
+
invisible,
|
|
62
|
+
);
|
|
63
|
+
}),
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public async createWidget(
|
|
68
|
+
container: Element,
|
|
69
|
+
renderOptions: ProcaptchaRenderOptions,
|
|
70
|
+
callbacks: Callbacks,
|
|
71
|
+
isWeb2 = true,
|
|
72
|
+
invisible = false,
|
|
73
|
+
): Promise<Root> {
|
|
74
|
+
renderOptions.theme = this.widgetThemeResolver.resolveWidgetTheme(
|
|
75
|
+
container,
|
|
76
|
+
renderOptions,
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
const widgetTheme =
|
|
80
|
+
"light" === renderOptions.theme ? lightTheme : darkTheme;
|
|
81
|
+
|
|
82
|
+
let widgetInteractiveArea: HTMLElement;
|
|
83
|
+
let widgetContainer: HTMLElement;
|
|
84
|
+
|
|
85
|
+
// Don't create the widget skeleton if the mode is invisible
|
|
86
|
+
if (invisible) {
|
|
87
|
+
//Create new div inside the container
|
|
88
|
+
const newDiv = document.createElement("div");
|
|
89
|
+
container.appendChild(newDiv);
|
|
90
|
+
widgetInteractiveArea = newDiv as HTMLElement;
|
|
91
|
+
widgetContainer = newDiv;
|
|
92
|
+
} else {
|
|
93
|
+
const widgetResult = createWidgetSkeleton(
|
|
94
|
+
container,
|
|
95
|
+
widgetTheme,
|
|
96
|
+
"prosopo-procaptcha",
|
|
97
|
+
);
|
|
98
|
+
widgetInteractiveArea = widgetResult.widgetInteractiveArea;
|
|
99
|
+
widgetContainer = widgetResult.webComponent;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// all the captcha-rendering logic is lazy-loaded, to avoid react & zod delay the initial widget creation.
|
|
103
|
+
|
|
104
|
+
const captchaRenderer = await this.getCaptchaRenderer();
|
|
105
|
+
|
|
106
|
+
const captchaRoot = captchaRenderer.renderCaptcha(
|
|
107
|
+
{
|
|
108
|
+
identifierPrefix: "procaptcha-",
|
|
109
|
+
emotionCacheKey: "procaptcha",
|
|
110
|
+
webComponentTag: "prosopo-procaptcha",
|
|
111
|
+
},
|
|
112
|
+
widgetInteractiveArea,
|
|
113
|
+
renderOptions,
|
|
114
|
+
callbacks,
|
|
115
|
+
isWeb2,
|
|
116
|
+
this.i18n,
|
|
117
|
+
invisible,
|
|
118
|
+
widgetContainer,
|
|
119
|
+
container,
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
return captchaRoot;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
protected async getCaptchaRenderer(): Promise<CaptchaRenderer> {
|
|
126
|
+
if (this._i18n === null) {
|
|
127
|
+
this._i18n = await loadI18next(false);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (this.captchaRenderer === null) {
|
|
131
|
+
this.captchaRenderer = await this.createCaptchaRenderer();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return this.captchaRenderer;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
protected async createCaptchaRenderer(): Promise<CaptchaRenderer> {
|
|
138
|
+
const CaptchaRenderer = (await import("./captcha/captchaRenderer.js"))
|
|
139
|
+
.CaptchaRenderer;
|
|
140
|
+
|
|
141
|
+
return new CaptchaRenderer();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export { WidgetFactory };
|
|
@@ -0,0 +1,40 @@
|
|
|
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 type { ProcaptchaRenderOptions } from "@prosopo/types";
|
|
16
|
+
|
|
17
|
+
class WidgetThemeResolver {
|
|
18
|
+
private readonly themesSet = new Set(["light", "dark"]);
|
|
19
|
+
private readonly defaultTheme = "light";
|
|
20
|
+
|
|
21
|
+
public resolveWidgetTheme(
|
|
22
|
+
element: Element,
|
|
23
|
+
renderOptions: ProcaptchaRenderOptions,
|
|
24
|
+
): "light" | "dark" {
|
|
25
|
+
const themeAttribute =
|
|
26
|
+
renderOptions.theme ||
|
|
27
|
+
element.getAttribute("data-theme") ||
|
|
28
|
+
this.defaultTheme;
|
|
29
|
+
|
|
30
|
+
return this.validateTheme(themeAttribute);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
protected validateTheme(themeAttribute: string): "light" | "dark" {
|
|
34
|
+
return this.themesSet.has(themeAttribute)
|
|
35
|
+
? (themeAttribute as "light" | "dark")
|
|
36
|
+
: this.defaultTheme;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { WidgetThemeResolver };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.cjs.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"rootDir": "./src",
|
|
5
|
+
"outDir": "./dist/cjs",
|
|
6
|
+
"lib": ["es6", "dom"]
|
|
7
|
+
},
|
|
8
|
+
"include": ["src/index.ts", "src/index.html"],
|
|
9
|
+
"references": [
|
|
10
|
+
{
|
|
11
|
+
"path": "../../dev/config/tsconfig.cjs.json"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"path": "../dotenv/tsconfig.cjs.json"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"path": "../locale/tsconfig.cjs.json"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"path": "../procaptcha-frictionless/tsconfig.cjs.json"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"path": "../types/tsconfig.cjs.json"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"path": "../util/tsconfig.cjs.json"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"path": "../widget-skeleton/tsconfig.cjs.json"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"path": "../procaptcha-common/tsconfig.cjs.json"
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.esm.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"rootDir": "./src",
|
|
5
|
+
"outDir": "./dist",
|
|
6
|
+
"lib": ["es6", "dom"]
|
|
7
|
+
},
|
|
8
|
+
"include": [
|
|
9
|
+
"src",
|
|
10
|
+
"src/**/*.json",
|
|
11
|
+
"src/index.html",
|
|
12
|
+
"src/**/*.ts",
|
|
13
|
+
"src/**/*.tsx",
|
|
14
|
+
"src/**/*.d.ts"
|
|
15
|
+
],
|
|
16
|
+
"references": [
|
|
17
|
+
{
|
|
18
|
+
"path": "../../dev/config/tsconfig.json"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"path": "../dotenv"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"path": "../locale"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"path": "../procaptcha-frictionless"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"path": "../types"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"path": "../util"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"path": "../widget-skeleton"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"path": "../procaptcha-common"
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
}
|