@prosopo/procaptcha-common 2.11.16 → 2.11.18
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 +22 -20
- package/.turbo/turbo-build$colon$tsc.log +18 -18
- package/.turbo/turbo-build.log +23 -19
- package/CHANGELOG.md +36 -0
- package/dist/_virtual/_rolldown/runtime.js +3 -0
- package/dist/callbacks/defaultCallbacks.js +100 -152
- package/dist/callbacks/defaultEvents.js +6 -6
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +23 -0
- package/dist/cjs/callbacks/defaultCallbacks.cjs +100 -151
- package/dist/cjs/callbacks/defaultEvents.cjs +6 -6
- package/dist/cjs/elements/form.cjs +10 -17
- package/dist/cjs/elements/window.cjs +17 -15
- package/dist/cjs/extensionLoader.cjs +3 -25
- package/dist/cjs/index.cjs +29 -27
- package/dist/cjs/providers.cjs +29 -42
- package/dist/cjs/reactComponents/Checkbox.cjs +102 -121
- package/dist/cjs/reactComponents/Honeypot.cjs +54 -62
- package/dist/cjs/reactComponents/Reload.cjs +59 -80
- package/dist/cjs/reactComponents/TestModeBanner.cjs +31 -44
- package/dist/cjs/simdReadings.cjs +24 -0
- package/dist/cjs/state/builder.cjs +70 -83
- package/dist/elements/form.js +10 -18
- package/dist/elements/window.js +18 -17
- package/dist/extensionLoader.js +4 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -19
- package/dist/index.js.map +1 -1
- package/dist/providers.js +29 -45
- package/dist/reactComponents/Checkbox.js +99 -121
- package/dist/reactComponents/Honeypot.js +53 -61
- package/dist/reactComponents/Reload.js +58 -80
- package/dist/reactComponents/TestModeBanner.js +30 -45
- package/dist/simdReadings.d.ts +6 -0
- package/dist/simdReadings.d.ts.map +1 -0
- package/dist/simdReadings.js +23 -0
- package/dist/simdReadings.js.map +1 -0
- package/dist/state/builder.js +71 -85
- package/dist/tests/simdReadings.test.d.ts +2 -0
- package/dist/tests/simdReadings.test.d.ts.map +1 -0
- package/dist/tests/simdReadings.test.js +76 -0
- package/dist/tests/simdReadings.test.js.map +1 -0
- package/package.json +8 -8
- package/src/index.ts +1 -0
- package/src/simdReadings.ts +45 -0
- package/src/tests/simdReadings.test.ts +149 -0
- package/tsconfig.tsbuildinfo +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prosopo/procaptcha-common",
|
|
3
|
-
"version": "2.11.
|
|
3
|
+
"version": "2.11.18",
|
|
4
4
|
"author": "PROSOPO LIMITED <info@prosopo.io>",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -34,20 +34,20 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@emotion/react": "11.11.1",
|
|
36
36
|
"@emotion/styled": "11.11.0",
|
|
37
|
-
"@prosopo/account": "2.8.
|
|
38
|
-
"@prosopo/load-balancer": "2.10.
|
|
39
|
-
"@prosopo/types": "4.
|
|
37
|
+
"@prosopo/account": "2.8.64",
|
|
38
|
+
"@prosopo/load-balancer": "2.10.16",
|
|
39
|
+
"@prosopo/types": "4.10.0",
|
|
40
40
|
"@prosopo/widget-skeleton": "2.8.4",
|
|
41
41
|
"react": "18.3.1",
|
|
42
42
|
"react-dom": "18.3.1"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@prosopo/config": "3.3.
|
|
45
|
+
"@prosopo/config": "3.3.5",
|
|
46
46
|
"@types/jsdom": "21.1.7",
|
|
47
47
|
"@types/node": "22.10.2",
|
|
48
48
|
"@types/react": "18.3.1",
|
|
49
49
|
"@types/react-dom": "18.3.1",
|
|
50
|
-
"@vitest/coverage-v8": "
|
|
50
|
+
"@vitest/coverage-v8": "4.1.10",
|
|
51
51
|
"concurrently": "9.0.1",
|
|
52
52
|
"del-cli": "6.0.0",
|
|
53
53
|
"dotenv": "16.4.5",
|
|
@@ -56,8 +56,8 @@
|
|
|
56
56
|
"tslib": "2.7.0",
|
|
57
57
|
"tsx": "4.20.3",
|
|
58
58
|
"typescript": "5.6.2",
|
|
59
|
-
"vite": "
|
|
60
|
-
"vitest": "
|
|
59
|
+
"vite": "8.1.5",
|
|
60
|
+
"vitest": "4.1.10"
|
|
61
61
|
},
|
|
62
62
|
"repository": {
|
|
63
63
|
"type": "git",
|
package/src/index.ts
CHANGED
|
@@ -17,6 +17,7 @@ export * from "./state/builder.js";
|
|
|
17
17
|
export * from "./callbacks/defaultCallbacks.js";
|
|
18
18
|
export * from "./callbacks/defaultEvents.js";
|
|
19
19
|
export * from "./extensionLoader.js";
|
|
20
|
+
export * from "./simdReadings.js";
|
|
20
21
|
export * from "./elements/window.js";
|
|
21
22
|
export * from "./reactComponents/Reload.js";
|
|
22
23
|
export * from "./reactComponents/Checkbox.js";
|
|
@@ -0,0 +1,45 @@
|
|
|
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 const SIMD_READINGS_SUBMIT_TIMEOUT_MS = 5000;
|
|
16
|
+
|
|
17
|
+
export interface SimdReadingsSource {
|
|
18
|
+
getSimdReadings?: (timeoutMs?: number) => Promise<string | undefined>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const getSimdReadingsForSubmit = async (
|
|
22
|
+
source: SimdReadingsSource | undefined,
|
|
23
|
+
timeoutMs: number = SIMD_READINGS_SUBMIT_TIMEOUT_MS,
|
|
24
|
+
): Promise<string | undefined> => {
|
|
25
|
+
if (!source?.getSimdReadings) return undefined;
|
|
26
|
+
const { getSimdReadings } = source;
|
|
27
|
+
|
|
28
|
+
let readings: Promise<string | undefined>;
|
|
29
|
+
try {
|
|
30
|
+
readings = Promise.resolve(getSimdReadings.call(source, timeoutMs));
|
|
31
|
+
} catch {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
let timeoutId: ReturnType<typeof setTimeout> | undefined;
|
|
36
|
+
const timeout = new Promise<undefined>((resolve) => {
|
|
37
|
+
timeoutId = setTimeout(() => resolve(undefined), timeoutMs);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
try {
|
|
41
|
+
return await Promise.race([readings.catch(() => undefined), timeout]);
|
|
42
|
+
} finally {
|
|
43
|
+
if (timeoutId !== undefined) clearTimeout(timeoutId);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
@@ -0,0 +1,149 @@
|
|
|
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 { afterEach, describe, expect, it, vi } from "vitest";
|
|
16
|
+
import {
|
|
17
|
+
SIMD_READINGS_SUBMIT_TIMEOUT_MS,
|
|
18
|
+
type SimdReadingsSource,
|
|
19
|
+
getSimdReadingsForSubmit,
|
|
20
|
+
} from "../simdReadings.js";
|
|
21
|
+
|
|
22
|
+
afterEach(() => {
|
|
23
|
+
vi.useRealTimers();
|
|
24
|
+
vi.restoreAllMocks();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
describe("getSimdReadingsForSubmit", () => {
|
|
28
|
+
it("blocks on the readings and returns them", async () => {
|
|
29
|
+
const getSimdReadings = vi.fn<
|
|
30
|
+
(timeoutMs?: number) => Promise<string | undefined>
|
|
31
|
+
>(async () => "ENCODED_SIMD");
|
|
32
|
+
const source: SimdReadingsSource = { getSimdReadings };
|
|
33
|
+
|
|
34
|
+
await expect(getSimdReadingsForSubmit(source)).resolves.toBe(
|
|
35
|
+
"ENCODED_SIMD",
|
|
36
|
+
);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("passes the submit timeout budget down to the detector", async () => {
|
|
40
|
+
const getSimdReadings = vi.fn<
|
|
41
|
+
(timeoutMs?: number) => Promise<string | undefined>
|
|
42
|
+
>(async () => "ENCODED_SIMD");
|
|
43
|
+
|
|
44
|
+
await getSimdReadingsForSubmit({ getSimdReadings });
|
|
45
|
+
|
|
46
|
+
expect(getSimdReadings).toHaveBeenCalledWith(
|
|
47
|
+
SIMD_READINGS_SUBMIT_TIMEOUT_MS,
|
|
48
|
+
);
|
|
49
|
+
expect(SIMD_READINGS_SUBMIT_TIMEOUT_MS).toBe(5000);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("waits for slow readings that still land inside the budget", async () => {
|
|
53
|
+
vi.useFakeTimers();
|
|
54
|
+
const getSimdReadings = vi.fn<
|
|
55
|
+
(timeoutMs?: number) => Promise<string | undefined>
|
|
56
|
+
>(
|
|
57
|
+
() =>
|
|
58
|
+
new Promise<string>((resolve) => {
|
|
59
|
+
setTimeout(() => resolve("LATE_SIMD"), 4000);
|
|
60
|
+
}),
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const pending = getSimdReadingsForSubmit({ getSimdReadings });
|
|
64
|
+
await vi.advanceTimersByTimeAsync(4000);
|
|
65
|
+
|
|
66
|
+
await expect(pending).resolves.toBe("LATE_SIMD");
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("gives up at the timeout when the detector never resolves", async () => {
|
|
70
|
+
vi.useFakeTimers();
|
|
71
|
+
const getSimdReadings = vi.fn<
|
|
72
|
+
(timeoutMs?: number) => Promise<string | undefined>
|
|
73
|
+
>(() => new Promise<string>(() => undefined));
|
|
74
|
+
|
|
75
|
+
const pending = getSimdReadingsForSubmit({ getSimdReadings });
|
|
76
|
+
await vi.advanceTimersByTimeAsync(SIMD_READINGS_SUBMIT_TIMEOUT_MS);
|
|
77
|
+
|
|
78
|
+
await expect(pending).resolves.toBeUndefined();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("honours an explicit timeout override", async () => {
|
|
82
|
+
vi.useFakeTimers();
|
|
83
|
+
const getSimdReadings = vi.fn<
|
|
84
|
+
(timeoutMs?: number) => Promise<string | undefined>
|
|
85
|
+
>(() => new Promise<string>(() => undefined));
|
|
86
|
+
|
|
87
|
+
const pending = getSimdReadingsForSubmit({ getSimdReadings }, 100);
|
|
88
|
+
await vi.advanceTimersByTimeAsync(100);
|
|
89
|
+
|
|
90
|
+
await expect(pending).resolves.toBeUndefined();
|
|
91
|
+
expect(getSimdReadings).toHaveBeenCalledWith(100);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("resolves undefined when the readings promise rejects", async () => {
|
|
95
|
+
const getSimdReadings = vi.fn<
|
|
96
|
+
(timeoutMs?: number) => Promise<string | undefined>
|
|
97
|
+
>(async () => {
|
|
98
|
+
throw new Error("benchmark failed");
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
await expect(
|
|
102
|
+
getSimdReadingsForSubmit({ getSimdReadings }),
|
|
103
|
+
).resolves.toBeUndefined();
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("resolves undefined when the accessor throws synchronously", async () => {
|
|
107
|
+
const getSimdReadings = vi.fn<
|
|
108
|
+
(timeoutMs?: number) => Promise<string | undefined>
|
|
109
|
+
>(() => {
|
|
110
|
+
throw new Error("detector exploded");
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
await expect(
|
|
114
|
+
getSimdReadingsForSubmit({ getSimdReadings }),
|
|
115
|
+
).resolves.toBeUndefined();
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it("resolves undefined without a source or accessor", async () => {
|
|
119
|
+
await expect(getSimdReadingsForSubmit(undefined)).resolves.toBeUndefined();
|
|
120
|
+
await expect(getSimdReadingsForSubmit({})).resolves.toBeUndefined();
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it("calls the accessor with the source as `this`", async () => {
|
|
124
|
+
// The detector ships prebuilt; its accessor may be a method relying on
|
|
125
|
+
// its own receiver, so it must not be invoked detached.
|
|
126
|
+
const source = {
|
|
127
|
+
marker: "SIMD_FROM_THIS",
|
|
128
|
+
getSimdReadings(this: { marker: string }): Promise<string | undefined> {
|
|
129
|
+
return Promise.resolve(this.marker);
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
await expect(getSimdReadingsForSubmit(source)).resolves.toBe(
|
|
134
|
+
"SIMD_FROM_THIS",
|
|
135
|
+
);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("clears the timeout timer once readings arrive", async () => {
|
|
139
|
+
vi.useFakeTimers();
|
|
140
|
+
const clearTimeoutSpy = vi.spyOn(globalThis, "clearTimeout");
|
|
141
|
+
const getSimdReadings = vi.fn<
|
|
142
|
+
(timeoutMs?: number) => Promise<string | undefined>
|
|
143
|
+
>(async () => "ENCODED_SIMD");
|
|
144
|
+
|
|
145
|
+
await getSimdReadingsForSubmit({ getSimdReadings });
|
|
146
|
+
|
|
147
|
+
expect(clearTimeoutSpy).toHaveBeenCalled();
|
|
148
|
+
});
|
|
149
|
+
});
|