@prosopo/procaptcha-frictionless 2.18.7 → 2.19.0

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.
Files changed (42) hide show
  1. package/.turbo/turbo-build$colon$cjs.log +4 -7
  2. package/.turbo/turbo-build$colon$tsc.log +24 -27
  3. package/.turbo/turbo-build.log +5 -11
  4. package/CHANGELOG.md +32 -0
  5. package/LICENSE +201 -0
  6. package/dist/cjs/customDetectBot.cjs +3 -3
  7. package/dist/cjs/procaptchaFrictionless.cjs +4 -1
  8. package/dist/customDetectBot.d.ts.map +1 -1
  9. package/dist/customDetectBot.js +3 -3
  10. package/dist/customDetectBot.js.map +1 -1
  11. package/dist/procaptchaFrictionless.d.ts.map +1 -1
  12. package/dist/procaptchaFrictionless.js +4 -1
  13. package/dist/procaptchaFrictionless.js.map +1 -1
  14. package/dist/tests/sessionInvalidatedRemint.test.js +26 -0
  15. package/dist/tests/sessionInvalidatedRemint.test.js.map +1 -1
  16. package/package.json +70 -69
  17. package/src/authenticatedBadge.ts +0 -170
  18. package/src/customDetectBot.ts +0 -392
  19. package/src/detectorLoader.ts +0 -133
  20. package/src/detectorPrefetch.ts +0 -115
  21. package/src/frictionlessResultGuard.ts +0 -110
  22. package/src/index.ts +0 -15
  23. package/src/procaptchaFrictionless.ts +0 -626
  24. package/src/sessionInvalidatedRecovery.ts +0 -110
  25. package/src/tests/authenticatedBadge.unit.test.ts +0 -101
  26. package/src/tests/customDetectBot.test.ts +0 -77
  27. package/src/tests/customDetectBotAssignTimeout.test.ts +0 -185
  28. package/src/tests/customDetectBotSimd.test.ts +0 -173
  29. package/src/tests/detectorLoader.test.ts +0 -108
  30. package/src/tests/detectorPrefetch.test.ts +0 -114
  31. package/src/tests/escalationClientSession.test.ts +0 -216
  32. package/src/tests/escalationHandoff.integration.test.ts +0 -356
  33. package/src/tests/executeBeforeMount.test.ts +0 -233
  34. package/src/tests/frictionlessResultGuard.test.ts +0 -179
  35. package/src/tests/manualStart.test.ts +0 -391
  36. package/src/tests/procaptchaFrictionless.test.ts +0 -468
  37. package/src/tests/sessionInvalidatedRecovery.test.ts +0 -181
  38. package/src/tests/sessionInvalidatedRemint.test.ts +0 -272
  39. package/tsconfig.cjs.json +0 -41
  40. package/tsconfig.json +0 -49
  41. package/tsconfig.tsbuildinfo +0 -1
  42. package/tsconfig.types.json +0 -9
@@ -1,110 +0,0 @@
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 type FrictionlessGuardOutcome =
16
- | { kind: "pass" }
17
- | { kind: "error"; message: string; key?: string; retryable: boolean };
18
-
19
- /**
20
- * Error keys that describe the caller's situation rather than the provider's
21
- * health, so re-rolling onto another provider would return the same answer.
22
- *
23
- * Two groups. Integration faults (site key, origin, captcha type) need the
24
- * site owner to change something and the text is what tells them what. Policy
25
- * denials are a decision about this visitor that every provider shares —
26
- * retrying them would both mislead the user and hammer the fleet on behalf of
27
- * traffic we have just refused.
28
- *
29
- * Anything outside this list is treated as the provider failing, not the
30
- * caller: see {@link evaluateFrictionlessResult}.
31
- */
32
- const TERMINAL_ERROR_KEYS: ReadonlySet<string> = new Set([
33
- "API.SITE_KEY_NOT_REGISTERED",
34
- "API.INVALID_SITE_KEY",
35
- "API.UNAUTHORIZED_ORIGIN_URL",
36
- "API.INCORRECT_CAPTCHA_TYPE",
37
- "API.ACCESS_POLICY_BLOCK",
38
- "API.ABUSER_BLOCKED",
39
- "API.CRAWLER_BLOCKED",
40
- "API.DATACENTER_BLOCKED",
41
- "API.DISALLOWED_WEBVIEW",
42
- "API.MOBILE_BLOCKED",
43
- "API.PROXY_BLOCKED",
44
- "API.SATELLITE_BLOCKED",
45
- "API.TOR_BLOCKED",
46
- "API.VPN_BLOCKED",
47
- "API.FORBIDDEN",
48
- "API.UNAUTHORIZED",
49
- // carries its own ten-second restart in ProcaptchaFrictionless
50
- "CAPTCHA.NO_SESSION_FOUND",
51
- ]);
52
-
53
- // Fields the guard reads off the `/frictionless` result. Kept minimal
54
- // (subset of BotDetectionFunctionResult) so the helper can be exercised
55
- // without pulling in the full widget config surface.
56
- export type FrictionlessGuardInput = {
57
- captchaType?: string;
58
- error?: { message?: string; key?: string };
59
- };
60
-
61
- const MISSING_CAPTCHA_TYPE_MESSAGE =
62
- "Frictionless response missing captchaType; halting captcha mount";
63
-
64
- /**
65
- * Decide whether a `/frictionless` response is safe to mount an inner widget
66
- * against.
67
- *
68
- * `result.error?.message` catches the well-formed error shape emitted when
69
- * the provider surfaces a normal captcha error. A response with no
70
- * `captchaType` is the other failure mode: request-time short-circuits
71
- * (access-policy hard-block, decision-machine autoBan, domain / header
72
- * middleware rejections) emit a bare-string `{ error: "..." }` that does
73
- * not conform to `GetFrictionlessCaptchaResponse` but that
74
- * `HttpClientBase` returns verbatim because it does not throw on 4xx JSON.
75
- *
76
- * Without the missing-captchaType branch the caller falls through to
77
- * `renderForCaptchaType(undefined, ...)` — the default arm mounts
78
- * ProcaptchaPow, which then calls `/captcha/pow` with an undefined
79
- * sessionId and gets rejected as API.INCORRECT_CAPTCHA_TYPE (the sitekey
80
- * is frictionless-configured, so a direct pow call isn't allowed).
81
- */
82
- export const evaluateFrictionlessResult = (
83
- result: FrictionlessGuardInput,
84
- ): FrictionlessGuardOutcome => {
85
- if (result.error?.message) {
86
- const key = result.error.key;
87
- return {
88
- kind: "error",
89
- message: result.error.message,
90
- ...(key !== undefined && { key }),
91
- // A key we do not recognise means the provider failed in a way it
92
- // has no vocabulary for — API.BAD_REQUEST is what an unhandled throw
93
- // inside a handler serialises to. That is worth trying another
94
- // provider for. Retrying is gated on having a key at all: the
95
- // bare-string errors handled below are hard blocks, and re-rolling
96
- // those would hammer the fleet for traffic already refused.
97
- retryable: key !== undefined && !TERMINAL_ERROR_KEYS.has(key),
98
- };
99
- }
100
- if (!result.captchaType) {
101
- return {
102
- kind: "error",
103
- message: MISSING_CAPTCHA_TYPE_MESSAGE,
104
- retryable: false,
105
- };
106
- }
107
- return { kind: "pass" };
108
- };
109
-
110
- export { MISSING_CAPTCHA_TYPE_MESSAGE };
package/src/index.ts DELETED
@@ -1,15 +0,0 @@
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
- export * from "./procaptchaFrictionless.js";
15
- export * from "./detectorPrefetch.js";