@owlmeans/web-captcha-recaptcha 0.0.0-stage → 0.2.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.
- package/README.md +87 -2
- package/agent-meta/manifest.json +16 -0
- package/agent-meta/skills/web-captcha-recaptcha/SKILL.md +78 -0
- package/build/append.d.ts +8 -0
- package/build/append.d.ts.map +1 -0
- package/build/append.js +8 -0
- package/build/append.js.map +1 -0
- package/build/client.d.ts +8 -0
- package/build/client.d.ts.map +1 -0
- package/build/client.js +20 -0
- package/build/client.js.map +1 -0
- package/build/consts.d.ts +34 -0
- package/build/consts.d.ts.map +1 -0
- package/build/consts.js +76 -0
- package/build/consts.js.map +1 -0
- package/build/index.d.ts +6 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +5 -0
- package/build/index.js.map +1 -0
- package/build/loader.d.ts +9 -0
- package/build/loader.d.ts.map +1 -0
- package/build/loader.js +105 -0
- package/build/loader.js.map +1 -0
- package/build/react/checkbox.d.ts +8 -0
- package/build/react/checkbox.d.ts.map +1 -0
- package/build/react/checkbox.js +9 -0
- package/build/react/checkbox.js.map +1 -0
- package/build/react.d.ts +2 -0
- package/build/react.d.ts.map +1 -0
- package/build/react.js +2 -0
- package/build/react.js.map +1 -0
- package/build/types.d.ts +58 -0
- package/build/types.d.ts.map +1 -0
- package/build/types.js +2 -0
- package/build/types.js.map +1 -0
- package/package.json +58 -4
- package/src/append.ts +12 -0
- package/src/client.ts +22 -0
- package/src/consts.ts +87 -0
- package/src/index.ts +5 -0
- package/src/loader.ts +123 -0
- package/src/react/checkbox.tsx +17 -0
- package/src/react.ts +1 -0
- package/src/types.ts +60 -0
- package/tests/client.spec.ts +63 -0
- package/tests/context.ts +73 -0
- package/tests/loader.spec.ts +120 -0
- package/tests/react.spec.ts +36 -0
- package/tsconfig.json +16 -0
package/README.md
CHANGED
|
@@ -1,3 +1,88 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @owlmeans/web-captcha-recaptcha
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The Google reCAPTCHA client for `@owlmeans/web-captcha`: the lazy, invisible v3 loader, Google's
|
|
4
|
+
notice in eight languages, the advertised site-key record, the helper that registers the client in
|
|
5
|
+
the page's `captchaClients`, and — from `./react` — Google's v2 checkbox as a captcha widget. A form
|
|
6
|
+
that is advertised the `recaptcha` provider (the server half is `@owlmeans/captcha-recaptcha`) asks
|
|
7
|
+
this client for its token. The package root carries no React, so an embedded bundle can import it
|
|
8
|
+
alone.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
bun add @owlmeans/web-captcha-recaptcha@^0.2.0
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Concepts
|
|
17
|
+
|
|
18
|
+
- **Client** — `makeRecaptchaClient(options)` is a `CaptchaClient` with id `'recaptcha'`: `load`
|
|
19
|
+
injects `api.js?render=<site key>` once per key, `execute(siteKey, action)` asks
|
|
20
|
+
`grecaptcha.execute` for a fresh token. Nothing touches the page until then.
|
|
21
|
+
- **Badge and notice** — the loader hides Google's badge; the client ships the notice a page then
|
|
22
|
+
shows (`RECAPTCHA_TEXTS`, `RECAPTCHA_NOTICE`), which `captchaNoticeHelper.noticeOf(client, lng)`
|
|
23
|
+
resolves in the reader's language.
|
|
24
|
+
- **Widget** — `RecaptchaCheckbox` (`./react`) renders the v2 checkbox; give it to the client and a
|
|
25
|
+
panel's captcha sign-in renders it (with a v2 site key).
|
|
26
|
+
- **Explicit** — `appendRecaptchaClient()` registers the client; importing registers nothing.
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import { appendRecaptchaClient } from '@owlmeans/web-captcha-recaptcha'
|
|
32
|
+
|
|
33
|
+
appendRecaptchaClient() // in the app's context factory
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
import { RecaptchaCheckbox } from '@owlmeans/web-captcha-recaptcha/react'
|
|
38
|
+
|
|
39
|
+
appendRecaptchaClient({ widget: RecaptchaCheckbox }) // a panel app showing the checkbox
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
import { makeRecaptchaClient } from '@owlmeans/web-captcha-recaptcha'
|
|
44
|
+
|
|
45
|
+
const client = makeRecaptchaClient() // an embedded bundle, without the registry
|
|
46
|
+
await client.load(siteKey)
|
|
47
|
+
const token = await client.execute(siteKey, 'inquiry')
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## API
|
|
51
|
+
|
|
52
|
+
| Export | Description |
|
|
53
|
+
|---|---|
|
|
54
|
+
| `appendRecaptchaClient(options?, clients?)` | Register the client in `captchaClients` (or the registry given); returns it |
|
|
55
|
+
| `makeRecaptchaClient(options?)` | The client; `options.loader`, `widget`, `siteKeyRecord` (default `CMOD_RECAPTCHA`) |
|
|
56
|
+
| `createRecaptchaLoader(options?)`, `recaptchaLoader` | The v3 loader: `prepare(siteKey)`, `token(siteKey, action)`; options `hideBadge`, `loadTimeout`, `executeTimeout`, `scriptUrl`, `document`, `window` |
|
|
57
|
+
| `RecaptchaCheckbox` (`./react`) | The v2 checkbox widget |
|
|
58
|
+
| `RECAPTCHA_PROVIDER`, `CMOD_RECAPTCHA` | `'recaptcha'`, `'_client-external:re-captcha'` |
|
|
59
|
+
| `RECAPTCHA_TEXTS`, `RECAPTCHA_NOTICE`, `RECAPTCHA_PRIVACY_URL`, `RECAPTCHA_TERMS_URL` | Google's notice and its links |
|
|
60
|
+
| `RECAPTCHA_SCRIPT_URL`, `RECAPTCHA_LOAD_TIMEOUT`, `RECAPTCHA_EXECUTE_TIMEOUT`, `RECAPTCHA_SCRIPT_ATTRIBUTE`, `RECAPTCHA_STYLE_ATTRIBUTE`, `RECAPTCHA_BADGE_CSS` | The loader's script, timeouts and marks |
|
|
61
|
+
| `RecaptchaClient`, `RecaptchaClientOptions`, `RecaptchaLoader`, `RecaptchaLoaderOptions`, `Grecaptcha`, `RecaptchaWindow`, `RecaptchaDocument` | Types |
|
|
62
|
+
|
|
63
|
+
## Related packages
|
|
64
|
+
|
|
65
|
+
- [`@owlmeans/web-captcha`](https://github.com/owlmeans/common/tree/main/packages/web-captcha) (common) — the `CaptchaClient` contract, `captchaClients` and the notice helper
|
|
66
|
+
- [`@owlmeans/web-auth-email`](https://github.com/owlmeans/common/tree/main/packages/web-auth-email) (common) — e-mail sign-in, which asks this client for a token
|
|
67
|
+
- [`@owlmeans/web-panel`](https://github.com/owlmeans/common/tree/main/packages/web-panel) (common) — its captcha sign-in renders `RecaptchaCheckbox` when given as `widget`
|
|
68
|
+
- [`@owlmeans/captcha-recaptcha`](../captcha-recaptcha) — the server half that verifies the token
|
|
69
|
+
|
|
70
|
+
## License
|
|
71
|
+
|
|
72
|
+
MIT
|
|
73
|
+
|
|
74
|
+
<!-- owlmeans:agent-guidance:start -->
|
|
75
|
+
## Agent guidance
|
|
76
|
+
|
|
77
|
+
This package ships embedded agent skills under `agent-meta/`. After installing your
|
|
78
|
+
`@owlmeans/*` packages, run the OwlMeans agent-skills installer to place them into
|
|
79
|
+
your project's skill store (`.agents/skills/`):
|
|
80
|
+
|
|
81
|
+
```sh
|
|
82
|
+
npx @owlmeans/agent-skills@^0.2.0
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
The embedded files are version-matched to this package release. Do not edit them
|
|
86
|
+
directly — they are regenerated on each publish. To contribute guidance edits,
|
|
87
|
+
open a PR against the source monorepo.
|
|
88
|
+
<!-- owlmeans:agent-guidance:end -->
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 3,
|
|
3
|
+
"package": "@owlmeans/web-captcha-recaptcha",
|
|
4
|
+
"version": "0.2.0",
|
|
5
|
+
"generatedAt": "2026-11-15T13:38:38.778Z",
|
|
6
|
+
"canonicalRepo": "https://github.com/owlmeans/connect",
|
|
7
|
+
"entries": [
|
|
8
|
+
{
|
|
9
|
+
"kind": "skill",
|
|
10
|
+
"name": "web-captcha-recaptcha",
|
|
11
|
+
"category": "package-specific",
|
|
12
|
+
"file": "skills/web-captcha-recaptcha/SKILL.md",
|
|
13
|
+
"canonicalPath": ".agents/skills/web-captcha-recaptcha/SKILL.md"
|
|
14
|
+
}
|
|
15
|
+
]
|
|
16
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: web-captcha-recaptcha
|
|
3
|
+
description: How to use @owlmeans/web-captcha-recaptcha (OwlMeans connect) — the Google reCAPTCHA client for @owlmeans/web-captcha. makeRecaptchaClient / appendRecaptchaClient (explicit registration in captchaClients), the lazy v3 loader (createRecaptchaLoader, recaptchaLoader — one script per site key, the badge hidden, a failed load forgotten), Google's notice in eight languages (RECAPTCHA_TEXTS, RECAPTCHA_NOTICE), CMOD_RECAPTCHA, and the v2 checkbox widget RecaptchaCheckbox (./react). Auto-invoked when a web app, an e-mail sign-in card or an embedded widget needs a reCAPTCHA token, when registering the reCAPTCHA client, rendering Google's notice or the checkbox, or debugging a reCAPTCHA load failure.
|
|
4
|
+
user-invocable: false
|
|
5
|
+
---
|
|
6
|
+
<!-- AUTO-GENERATED — do not edit. Regenerate via sync-agent-meta. -->
|
|
7
|
+
|
|
8
|
+
# @owlmeans/web-captcha-recaptcha
|
|
9
|
+
|
|
10
|
+
**Layer:** Web (no `@owlmeans/*` dependency but `@owlmeans/web-captcha`; React and
|
|
11
|
+
`react-google-recaptcha` reach only `./react`)
|
|
12
|
+
**Repo:** OwlMeans connect (`@owlmeans/web-captcha-recaptcha`) — the Google-specific half; the
|
|
13
|
+
contract, the registry and `useCaptcha` are common's `@owlmeans/web-captcha`
|
|
14
|
+
**Install:** `"@owlmeans/web-captcha-recaptcha": "^0.2.0"` in `dependencies`
|
|
15
|
+
**Server half:** `@owlmeans/captcha-recaptcha` (provider id `recaptcha`)
|
|
16
|
+
|
|
17
|
+
## Public API surface
|
|
18
|
+
|
|
19
|
+
| Symbol | Kind | Purpose |
|
|
20
|
+
|---|---|---|
|
|
21
|
+
| `appendRecaptchaClient(opts?, clients = captchaClients)` | fn | Registers the client (same id replaces) and returns it |
|
|
22
|
+
| `makeRecaptchaClient(opts?)` | fn | The `CaptchaClient`: `id: 'recaptcha'`, `load` / `execute` over the v3 loader, `notice`, `texts`, `siteKeyRecord: CMOD_RECAPTCHA`, `widget` when given |
|
|
23
|
+
| `createRecaptchaLoader(opts?)`, `recaptchaLoader` | fn / instance | Google's v3 loader: `prepare(siteKey)`, `token(siteKey, action)` |
|
|
24
|
+
| `RecaptchaCheckbox` (`./react`) | component | The v2 checkbox as a `CaptchaWidget` (`react-google-recaptcha`): `siteKey`, `onToken` (expiry → `null`), `onReady`, `onError`, `language` → `hl` |
|
|
25
|
+
| `RECAPTCHA_PROVIDER` | const | `'recaptcha'` — equal to the server provider's id |
|
|
26
|
+
| `CMOD_RECAPTCHA` | const | `'_client-external:re-captcha'` — the advertised client record whose `value` is the site key |
|
|
27
|
+
| `RECAPTCHA_TEXTS`, `RECAPTCHA_NOTICE` | const | Google's notice (`notice`, `privacy`, `terms`) in en, pl, ru, be, uk, es, de, fr; its two links |
|
|
28
|
+
| `RECAPTCHA_SCRIPT_URL`, `RECAPTCHA_LOAD_TIMEOUT`, `RECAPTCHA_EXECUTE_TIMEOUT` | const | `https://www.google.com/recaptcha/api.js`, `15_000`, `20_000` |
|
|
29
|
+
| `RECAPTCHA_SCRIPT_ATTRIBUTE`, `RECAPTCHA_STYLE_ATTRIBUTE`, `RECAPTCHA_BADGE_CSS`, `RECAPTCHA_PRIVACY_URL`, `RECAPTCHA_TERMS_URL` | const | What the loader marks and injects; Google's documents |
|
|
30
|
+
| `RecaptchaClientOptions` | interface | `{ loader?, widget?, siteKeyRecord? }` |
|
|
31
|
+
| `RecaptchaLoaderOptions` | interface | `hideBadge` (default `true`), `loadTimeout`, `executeTimeout`, `scriptUrl`, `document` / `window` |
|
|
32
|
+
| `RecaptchaClient`, `RecaptchaLoader`, `Grecaptcha`, `RecaptchaWindow`, `RecaptchaDocument` | types | |
|
|
33
|
+
|
|
34
|
+
## Wiring
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
// a web app's context factory — explicit, once
|
|
38
|
+
appendRecaptchaClient() // invisible v3: the e-mail card, forms
|
|
39
|
+
|
|
40
|
+
// a panel app whose captcha sign-in shows Google's checkbox (needs a v2 site key)
|
|
41
|
+
import { RecaptchaCheckbox } from '@owlmeans/web-captcha-recaptcha/react'
|
|
42
|
+
appendRecaptchaClient({ widget: RecaptchaCheckbox })
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
An embedded IIFE bundle (an inquiry widget) imports the package ROOT only and uses the client
|
|
46
|
+
directly, without the registry: `makeInquiryApi({ captcha: makeRecaptchaClient() })`. The root never
|
|
47
|
+
imports React or `react-google-recaptcha`.
|
|
48
|
+
|
|
49
|
+
## Behaviour
|
|
50
|
+
|
|
51
|
+
- **Lazy** — `api.js?render=<site key>` is injected on the first `load` / `execute`; safe at import,
|
|
52
|
+
under server rendering and in tests; without a page a call fails with
|
|
53
|
+
`CaptchaLoadError('unavailable')`.
|
|
54
|
+
- **One script per site key per loader**; concurrent calls share the load; a failed load is
|
|
55
|
+
forgotten, so the next call injects again.
|
|
56
|
+
- **Badge** — the loader hides Google's badge with one document rule; the page must then show
|
|
57
|
+
Google's notice (the client's `notice` + `texts`, read with `captchaNoticeHelper.noticeOf`). Pass
|
|
58
|
+
`hideBadge: false` to keep the badge.
|
|
59
|
+
- **Failures** — `load`, `timeout` (15 s), `unavailable` (no page, or the script without its API),
|
|
60
|
+
`execute` (no token within 20 s).
|
|
61
|
+
- A new language goes into `RECAPTCHA_TEXTS` with all three keys and both placeholders
|
|
62
|
+
(`tests/client.spec.ts` checks it).
|
|
63
|
+
|
|
64
|
+
## Tests
|
|
65
|
+
|
|
66
|
+
`bun test ./tests` — category A: the loader over a stand-in `document`/`window` (no browser), the
|
|
67
|
+
client and its registration, the texts in eight languages, and the checkbox element's props.
|
|
68
|
+
|
|
69
|
+
## External docs
|
|
70
|
+
|
|
71
|
+
- https://developers.google.com/recaptcha/docs/v3 — `api.js?render=<site key>`, `grecaptcha.ready` then `execute(siteKey, { action })` per protected action
|
|
72
|
+
- https://developers.google.com/recaptcha/docs/faq — hiding the badge requires the notice text with links to Google's Privacy Policy and Terms of Service in the user flow
|
|
73
|
+
- https://github.com/dozoisch/react-google-recaptcha — the v2 checkbox component: `sitekey`, `onChange`, `onExpired`, `onErrored`, `asyncScriptOnLoad`, `hl`
|
|
74
|
+
|
|
75
|
+
## Related
|
|
76
|
+
|
|
77
|
+
`web-captcha` (the contract and registry, common) · `captcha-recaptcha` (the server half) ·
|
|
78
|
+
`web-auth-email` (the e-mail card asks this client) · `web-panel` / `mui-panel` (render its widget)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CaptchaClients } from '@owlmeans/web-captcha';
|
|
2
|
+
import type { RecaptchaClient, RecaptchaClientOptions } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Register the reCAPTCHA client in the page's captcha clients (or the registry given), so a form
|
|
5
|
+
* that is advertised the `recaptcha` provider finds it. Call it once while the app is set up.
|
|
6
|
+
*/
|
|
7
|
+
export declare const appendRecaptchaClient: <W = unknown>(options?: RecaptchaClientOptions<W>, clients?: CaptchaClients) => RecaptchaClient<W>;
|
|
8
|
+
//# sourceMappingURL=append.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"append.d.ts","sourceRoot":"","sources":["../src/append.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAE3D,OAAO,KAAK,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AAEzE;;;GAGG;AACH,eAAO,MAAM,qBAAqB,GAAI,CAAC,GAAG,OAAO,YACtC,sBAAsB,CAAC,CAAC,CAAC,YAAgB,cAAc,KAC/D,eAAe,CAAC,CAAC,CAAmD,CAAA"}
|
package/build/append.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { captchaClients } from '@owlmeans/web-captcha';
|
|
2
|
+
import { makeRecaptchaClient } from './client.js';
|
|
3
|
+
/**
|
|
4
|
+
* Register the reCAPTCHA client in the page's captcha clients (or the registry given), so a form
|
|
5
|
+
* that is advertised the `recaptcha` provider finds it. Call it once while the app is set up.
|
|
6
|
+
*/
|
|
7
|
+
export const appendRecaptchaClient = (options = {}, clients = captchaClients) => clients.register(makeRecaptchaClient(options));
|
|
8
|
+
//# sourceMappingURL=append.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"append.js","sourceRoot":"","sources":["../src/append.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAEtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAGjD;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,OAAO,GAA8B,EAAE,EAAE,OAAO,GAAmB,cAAc,EAC7D,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { RecaptchaClient, RecaptchaClientOptions } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* The reCAPTCHA client of `@owlmeans/web-captcha`: tokens from the invisible, score-based v3 loader,
|
|
4
|
+
* Google's notice (the loader hides the badge) in eight languages, and — when given — an interactive
|
|
5
|
+
* widget (`RecaptchaCheckbox` of `./react`, the v2 checkbox) for a page that renders one.
|
|
6
|
+
*/
|
|
7
|
+
export declare const makeRecaptchaClient: <W = unknown>(options?: RecaptchaClientOptions<W>) => RecaptchaClient<W>;
|
|
8
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AAEzE;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,GAAI,CAAC,GAAG,OAAO,YAAW,sBAAsB,CAAC,CAAC,CAAC,KAAQ,eAAe,CAAC,CAAC,CAY3G,CAAA"}
|
package/build/client.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CMOD_RECAPTCHA, RECAPTCHA_NOTICE, RECAPTCHA_PROVIDER, RECAPTCHA_TEXTS } from './consts.js';
|
|
2
|
+
import { recaptchaLoader } from './loader.js';
|
|
3
|
+
/**
|
|
4
|
+
* The reCAPTCHA client of `@owlmeans/web-captcha`: tokens from the invisible, score-based v3 loader,
|
|
5
|
+
* Google's notice (the loader hides the badge) in eight languages, and — when given — an interactive
|
|
6
|
+
* widget (`RecaptchaCheckbox` of `./react`, the v2 checkbox) for a page that renders one.
|
|
7
|
+
*/
|
|
8
|
+
export const makeRecaptchaClient = (options = {}) => {
|
|
9
|
+
const loader = options.loader ?? recaptchaLoader;
|
|
10
|
+
return {
|
|
11
|
+
id: RECAPTCHA_PROVIDER,
|
|
12
|
+
load: async (siteKey) => { await loader.prepare(siteKey); },
|
|
13
|
+
execute: async (siteKey, action) => await loader.token(siteKey, action),
|
|
14
|
+
notice: RECAPTCHA_NOTICE,
|
|
15
|
+
texts: RECAPTCHA_TEXTS,
|
|
16
|
+
siteKeyRecord: options.siteKeyRecord ?? CMOD_RECAPTCHA,
|
|
17
|
+
...(options.widget != null ? { widget: options.widget } : {}),
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AACnG,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAG7C;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAc,OAAO,GAA8B,EAAE,EAAsB,EAAE;IAC9G,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,eAAe,CAAA;IAEhD,OAAO;QACL,EAAE,EAAE,kBAAkB;QACtB,IAAI,EAAE,KAAK,EAAC,OAAO,EAAC,EAAE,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA,CAAC,CAAC;QACxD,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC,MAAM,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC;QACvE,MAAM,EAAE,gBAAgB;QACxB,KAAK,EAAE,eAAe;QACtB,aAAa,EAAE,OAAO,CAAC,aAAa,IAAI,cAAc;QACtD,GAAG,CAAC,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC9D,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { CaptchaNotice, CaptchaTexts } from '@owlmeans/web-captcha';
|
|
2
|
+
/**
|
|
3
|
+
* The provider id of Google reCAPTCHA — the id the server's provider (`@owlmeans/captcha-recaptcha`)
|
|
4
|
+
* advertises and a page looks this client up by.
|
|
5
|
+
*/
|
|
6
|
+
export declare const RECAPTCHA_PROVIDER = "recaptcha";
|
|
7
|
+
/** The client config record whose `value` is the site key (a Frontend record a server advertises). */
|
|
8
|
+
export declare const CMOD_RECAPTCHA = "_client-external:re-captcha";
|
|
9
|
+
/** Google's reCAPTCHA script; `?render=<site key>` selects the invisible, score-based (v3) widget. */
|
|
10
|
+
export declare const RECAPTCHA_SCRIPT_URL = "https://www.google.com/recaptcha/api.js";
|
|
11
|
+
/** Marks the script the loader injected; its value is the site key. */
|
|
12
|
+
export declare const RECAPTCHA_SCRIPT_ATTRIBUTE = "data-owlmeans-captcha";
|
|
13
|
+
/** Marks the document style that hides Google's badge. */
|
|
14
|
+
export declare const RECAPTCHA_STYLE_ATTRIBUTE = "data-owlmeans-captcha-style";
|
|
15
|
+
/**
|
|
16
|
+
* The one document-level rule the loader adds unless told not to: Google's badge hidden. A page
|
|
17
|
+
* that hides it must show Google's notice (`RECAPTCHA_TEXTS[lng].notice`) itself.
|
|
18
|
+
*/
|
|
19
|
+
export declare const RECAPTCHA_BADGE_CSS = ".grecaptcha-badge{visibility:hidden}";
|
|
20
|
+
/** How long the script may take to become ready, in milliseconds. */
|
|
21
|
+
export declare const RECAPTCHA_LOAD_TIMEOUT = 15000;
|
|
22
|
+
/** How long one `execute` may take, in milliseconds. */
|
|
23
|
+
export declare const RECAPTCHA_EXECUTE_TIMEOUT = 20000;
|
|
24
|
+
/** Google's documents the notice links to. */
|
|
25
|
+
export declare const RECAPTCHA_PRIVACY_URL = "https://policies.google.com/privacy";
|
|
26
|
+
export declare const RECAPTCHA_TERMS_URL = "https://policies.google.com/terms";
|
|
27
|
+
/** The notice's links, by the placeholder the sentence names them with. */
|
|
28
|
+
export declare const RECAPTCHA_NOTICE: CaptchaNotice;
|
|
29
|
+
/**
|
|
30
|
+
* Google's notice in the eight OwlMeans sign-in languages: the sentence (`{{privacy}}`, `{{terms}}`
|
|
31
|
+
* mark the links) and each link's label.
|
|
32
|
+
*/
|
|
33
|
+
export declare const RECAPTCHA_TEXTS: Readonly<Record<string, CaptchaTexts>>;
|
|
34
|
+
//# sourceMappingURL=consts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AAExE;;;GAGG;AACH,eAAO,MAAM,kBAAkB,cAAc,CAAA;AAE7C,sGAAsG;AACtG,eAAO,MAAM,cAAc,gCAAgC,CAAA;AAE3D,sGAAsG;AACtG,eAAO,MAAM,oBAAoB,4CAA4C,CAAA;AAE7E,uEAAuE;AACvE,eAAO,MAAM,0BAA0B,0BAA0B,CAAA;AAEjE,0DAA0D;AAC1D,eAAO,MAAM,yBAAyB,gCAAgC,CAAA;AAEtE;;;GAGG;AACH,eAAO,MAAM,mBAAmB,yCAAyC,CAAA;AAEzE,qEAAqE;AACrE,eAAO,MAAM,sBAAsB,QAAS,CAAA;AAE5C,wDAAwD;AACxD,eAAO,MAAM,yBAAyB,QAAS,CAAA;AAE/C,8CAA8C;AAC9C,eAAO,MAAM,qBAAqB,wCAAwC,CAAA;AAC1E,eAAO,MAAM,mBAAmB,sCAAsC,CAAA;AAEtE,2EAA2E;AAC3E,eAAO,MAAM,gBAAgB,EAAE,aAE7B,CAAA;AAEF;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAyCjE,CAAA"}
|
package/build/consts.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The provider id of Google reCAPTCHA — the id the server's provider (`@owlmeans/captcha-recaptcha`)
|
|
3
|
+
* advertises and a page looks this client up by.
|
|
4
|
+
*/
|
|
5
|
+
export const RECAPTCHA_PROVIDER = 'recaptcha';
|
|
6
|
+
/** The client config record whose `value` is the site key (a Frontend record a server advertises). */
|
|
7
|
+
export const CMOD_RECAPTCHA = '_client-external:re-captcha';
|
|
8
|
+
/** Google's reCAPTCHA script; `?render=<site key>` selects the invisible, score-based (v3) widget. */
|
|
9
|
+
export const RECAPTCHA_SCRIPT_URL = 'https://www.google.com/recaptcha/api.js';
|
|
10
|
+
/** Marks the script the loader injected; its value is the site key. */
|
|
11
|
+
export const RECAPTCHA_SCRIPT_ATTRIBUTE = 'data-owlmeans-captcha';
|
|
12
|
+
/** Marks the document style that hides Google's badge. */
|
|
13
|
+
export const RECAPTCHA_STYLE_ATTRIBUTE = 'data-owlmeans-captcha-style';
|
|
14
|
+
/**
|
|
15
|
+
* The one document-level rule the loader adds unless told not to: Google's badge hidden. A page
|
|
16
|
+
* that hides it must show Google's notice (`RECAPTCHA_TEXTS[lng].notice`) itself.
|
|
17
|
+
*/
|
|
18
|
+
export const RECAPTCHA_BADGE_CSS = '.grecaptcha-badge{visibility:hidden}';
|
|
19
|
+
/** How long the script may take to become ready, in milliseconds. */
|
|
20
|
+
export const RECAPTCHA_LOAD_TIMEOUT = 15_000;
|
|
21
|
+
/** How long one `execute` may take, in milliseconds. */
|
|
22
|
+
export const RECAPTCHA_EXECUTE_TIMEOUT = 20_000;
|
|
23
|
+
/** Google's documents the notice links to. */
|
|
24
|
+
export const RECAPTCHA_PRIVACY_URL = 'https://policies.google.com/privacy';
|
|
25
|
+
export const RECAPTCHA_TERMS_URL = 'https://policies.google.com/terms';
|
|
26
|
+
/** The notice's links, by the placeholder the sentence names them with. */
|
|
27
|
+
export const RECAPTCHA_NOTICE = Object.freeze({
|
|
28
|
+
links: Object.freeze({ privacy: RECAPTCHA_PRIVACY_URL, terms: RECAPTCHA_TERMS_URL }),
|
|
29
|
+
});
|
|
30
|
+
/**
|
|
31
|
+
* Google's notice in the eight OwlMeans sign-in languages: the sentence (`{{privacy}}`, `{{terms}}`
|
|
32
|
+
* mark the links) and each link's label.
|
|
33
|
+
*/
|
|
34
|
+
export const RECAPTCHA_TEXTS = Object.freeze({
|
|
35
|
+
en: Object.freeze({
|
|
36
|
+
notice: 'This site is protected by reCAPTCHA and the Google {{privacy}} and {{terms}} apply.',
|
|
37
|
+
privacy: 'Privacy Policy',
|
|
38
|
+
terms: 'Terms of Service',
|
|
39
|
+
}),
|
|
40
|
+
pl: Object.freeze({
|
|
41
|
+
notice: 'Ta strona jest chroniona przez reCAPTCHA i obowiązują w niej {{privacy}} oraz {{terms}} Google.',
|
|
42
|
+
privacy: 'Polityka prywatności',
|
|
43
|
+
terms: 'Warunki korzystania z usług',
|
|
44
|
+
}),
|
|
45
|
+
ru: Object.freeze({
|
|
46
|
+
notice: 'Этот сайт защищён reCAPTCHA, и к нему применяются {{privacy}} и {{terms}} Google.',
|
|
47
|
+
privacy: 'Политика конфиденциальности',
|
|
48
|
+
terms: 'Условия использования',
|
|
49
|
+
}),
|
|
50
|
+
be: Object.freeze({
|
|
51
|
+
notice: 'Гэты сайт абаронены reCAPTCHA, і да яго прымяняюцца {{privacy}} і {{terms}} Google.',
|
|
52
|
+
privacy: 'Палітыка прыватнасці',
|
|
53
|
+
terms: 'Умовы выкарыстання',
|
|
54
|
+
}),
|
|
55
|
+
uk: Object.freeze({
|
|
56
|
+
notice: 'Цей сайт захищено reCAPTCHA, і до нього застосовуються {{privacy}} та {{terms}} Google.',
|
|
57
|
+
privacy: 'Політика конфіденційності',
|
|
58
|
+
terms: 'Умови використання',
|
|
59
|
+
}),
|
|
60
|
+
es: Object.freeze({
|
|
61
|
+
notice: 'Este sitio está protegido por reCAPTCHA y se aplican la {{privacy}} y los {{terms}} de Google.',
|
|
62
|
+
privacy: 'Política de privacidad',
|
|
63
|
+
terms: 'Términos del servicio',
|
|
64
|
+
}),
|
|
65
|
+
de: Object.freeze({
|
|
66
|
+
notice: 'Diese Website ist durch reCAPTCHA geschützt, und es gelten die {{privacy}} und die {{terms}} von Google.',
|
|
67
|
+
privacy: 'Datenschutzerklärung',
|
|
68
|
+
terms: 'Nutzungsbedingungen',
|
|
69
|
+
}),
|
|
70
|
+
fr: Object.freeze({
|
|
71
|
+
notice: 'Ce site est protégé par reCAPTCHA, et les {{privacy}} et les {{terms}} de Google s’appliquent.',
|
|
72
|
+
privacy: 'Règles de confidentialité',
|
|
73
|
+
terms: 'Conditions d’utilisation',
|
|
74
|
+
}),
|
|
75
|
+
});
|
|
76
|
+
//# sourceMappingURL=consts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consts.js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,6BAA6B;KACrC,CAAC;IACF,EAAE,EAAE,MAAM,CAAC,MAAM,CAAC;QAChB,MAAM,EAAE,mFAAmF;QAC3F,OAAO,EAAE,6BAA6B;QACtC,KAAK,EAAE,uBAAuB;KAC/B,CAAC;IACF,EAAE,EAAE,MAAM,CAAC,MAAM,CAAC;QAChB,MAAM,EAAE,qFAAqF;QAC7F,OAAO,EAAE,sBAAsB;QAC/B,KAAK,EAAE,oBAAoB;KAC5B,CAAC;IACF,EAAE,EAAE,MAAM,CAAC,MAAM,CAAC;QAChB,MAAM,EAAE,yFAAyF;QACjG,OAAO,EAAE,2BAA2B;QACpC,KAAK,EAAE,oBAAoB;KAC5B,CAAC;IACF,EAAE,EAAE,MAAM,CAAC,MAAM,CAAC;QAChB,MAAM,EAAE,gGAAgG;QACxG,OAAO,EAAE,wBAAwB;QACjC,KAAK,EAAE,uBAAuB;KAC/B,CAAC;IACF,EAAE,EAAE,MAAM,CAAC,MAAM,CAAC;QAChB,MAAM,EAAE,0GAA0G;QAClH,OAAO,EAAE,sBAAsB;QAC/B,KAAK,EAAE,qBAAqB;KAC7B,CAAC;IACF,EAAE,EAAE,MAAM,CAAC,MAAM,CAAC;QAChB,MAAM,EAAE,gGAAgG;QACxG,OAAO,EAAE,2BAA2B;QACpC,KAAK,EAAE,0BAA0B;KAClC,CAAC;CACH,CAAC,CAAA"}
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,YAAY,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA"}
|
package/build/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { RecaptchaLoader, RecaptchaLoaderOptions } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Google's reCAPTCHA v3 loader. Nothing touches the page until `prepare` or `token` is called, so
|
|
4
|
+
* the module is safe to import during server rendering and in tests.
|
|
5
|
+
*/
|
|
6
|
+
export declare const createRecaptchaLoader: (options?: RecaptchaLoaderOptions) => RecaptchaLoader;
|
|
7
|
+
/** The shared loader of a page: one script per site key across every caller. */
|
|
8
|
+
export declare const recaptchaLoader: RecaptchaLoader;
|
|
9
|
+
//# sourceMappingURL=loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAiC,eAAe,EAAE,sBAAsB,EAAmB,MAAM,YAAY,CAAA;AAEzH;;;GAGG;AACH,eAAO,MAAM,qBAAqB,aAAa,sBAAsB,KAAQ,eA2G5E,CAAA;AAED,gFAAgF;AAChF,eAAO,MAAM,eAAe,iBAA0B,CAAA"}
|
package/build/loader.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { CaptchaLoadError } from '@owlmeans/web-captcha';
|
|
2
|
+
import { RECAPTCHA_BADGE_CSS, RECAPTCHA_EXECUTE_TIMEOUT, RECAPTCHA_LOAD_TIMEOUT, RECAPTCHA_SCRIPT_ATTRIBUTE, RECAPTCHA_SCRIPT_URL, RECAPTCHA_STYLE_ATTRIBUTE, } from './consts.js';
|
|
3
|
+
/**
|
|
4
|
+
* Google's reCAPTCHA v3 loader. Nothing touches the page until `prepare` or `token` is called, so
|
|
5
|
+
* the module is safe to import during server rendering and in tests.
|
|
6
|
+
*/
|
|
7
|
+
export const createRecaptchaLoader = (options = {}) => {
|
|
8
|
+
const hideBadge = options.hideBadge ?? true;
|
|
9
|
+
const loadTimeout = options.loadTimeout ?? RECAPTCHA_LOAD_TIMEOUT;
|
|
10
|
+
const executeTimeout = options.executeTimeout ?? RECAPTCHA_EXECUTE_TIMEOUT;
|
|
11
|
+
const scriptUrl = options.scriptUrl ?? RECAPTCHA_SCRIPT_URL;
|
|
12
|
+
const loads = new Map();
|
|
13
|
+
const documentOf = () => options.document ?? (typeof document !== 'undefined' ? document : null);
|
|
14
|
+
const windowOf = () => options.window ?? (typeof window !== 'undefined' ? window : null);
|
|
15
|
+
const addBadgeStyle = (page) => {
|
|
16
|
+
if (page.querySelector(`style[${RECAPTCHA_STYLE_ATTRIBUTE}]`) != null) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const style = page.createElement('style');
|
|
20
|
+
style.setAttribute(RECAPTCHA_STYLE_ATTRIBUTE, '');
|
|
21
|
+
style.textContent = RECAPTCHA_BADGE_CSS;
|
|
22
|
+
page.head.appendChild(style);
|
|
23
|
+
};
|
|
24
|
+
const inject = (siteKey) => new Promise((resolve, reject) => {
|
|
25
|
+
const page = documentOf();
|
|
26
|
+
const host = windowOf();
|
|
27
|
+
if (page == null || host == null) {
|
|
28
|
+
reject(new CaptchaLoadError('unavailable', 'reCAPTCHA needs a page to load into'));
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const script = page.createElement('script');
|
|
32
|
+
let settled = false;
|
|
33
|
+
let timer;
|
|
34
|
+
const fail = (reason, message) => {
|
|
35
|
+
if (!settled) {
|
|
36
|
+
settled = true;
|
|
37
|
+
clearTimeout(timer);
|
|
38
|
+
script.remove();
|
|
39
|
+
reject(new CaptchaLoadError(reason, message));
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
timer = setTimeout(() => { fail('timeout', 'reCAPTCHA did not become ready in time'); }, loadTimeout);
|
|
43
|
+
script.addEventListener('error', () => { fail('load', 'reCAPTCHA failed to load'); });
|
|
44
|
+
script.addEventListener('load', () => {
|
|
45
|
+
const grecaptcha = host.grecaptcha;
|
|
46
|
+
if (grecaptcha == null || typeof grecaptcha.ready !== 'function') {
|
|
47
|
+
fail('unavailable', 'reCAPTCHA loaded without its API');
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
grecaptcha.ready(() => {
|
|
51
|
+
if (!settled) {
|
|
52
|
+
settled = true;
|
|
53
|
+
clearTimeout(timer);
|
|
54
|
+
resolve(host.grecaptcha ?? grecaptcha);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
script.src = `${scriptUrl}${scriptUrl.includes('?') ? '&' : '?'}render=${encodeURIComponent(siteKey)}`;
|
|
59
|
+
script.async = true;
|
|
60
|
+
script.setAttribute(RECAPTCHA_SCRIPT_ATTRIBUTE, siteKey);
|
|
61
|
+
if (hideBadge) {
|
|
62
|
+
addBadgeStyle(page);
|
|
63
|
+
}
|
|
64
|
+
page.head.appendChild(script);
|
|
65
|
+
});
|
|
66
|
+
const readyOf = (siteKey) => {
|
|
67
|
+
const known = loads.get(siteKey);
|
|
68
|
+
if (known != null) {
|
|
69
|
+
return known;
|
|
70
|
+
}
|
|
71
|
+
const loading = inject(siteKey);
|
|
72
|
+
loads.set(siteKey, loading);
|
|
73
|
+
loading.catch(() => { loads.delete(siteKey); });
|
|
74
|
+
return loading;
|
|
75
|
+
};
|
|
76
|
+
const prepare = async (siteKey) => {
|
|
77
|
+
await readyOf(siteKey);
|
|
78
|
+
};
|
|
79
|
+
const token = async (siteKey, action) => {
|
|
80
|
+
const grecaptcha = await readyOf(siteKey);
|
|
81
|
+
let timer;
|
|
82
|
+
try {
|
|
83
|
+
const value = await Promise.race([
|
|
84
|
+
Promise.resolve(grecaptcha.execute(siteKey, { action })),
|
|
85
|
+
new Promise((_, reject) => {
|
|
86
|
+
timer = setTimeout(() => { reject(new Error('reCAPTCHA execute timed out')); }, executeTimeout);
|
|
87
|
+
}),
|
|
88
|
+
]);
|
|
89
|
+
if (typeof value !== 'string' || value === '') {
|
|
90
|
+
throw new Error('reCAPTCHA gave no token');
|
|
91
|
+
}
|
|
92
|
+
return value;
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
throw new CaptchaLoadError('execute', `reCAPTCHA refused: ${String(error)}`, { cause: error });
|
|
96
|
+
}
|
|
97
|
+
finally {
|
|
98
|
+
clearTimeout(timer);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
return { prepare, token };
|
|
102
|
+
};
|
|
103
|
+
/** The shared loader of a page: one script per site key across every caller. */
|
|
104
|
+
export const recaptchaLoader = createRecaptchaLoader();
|
|
105
|
+
//# sourceMappingURL=loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAExD,OAAO,EACL,mBAAmB,EAAE,yBAAyB,EAAE,sBAAsB,EAAE,0BAA0B,EAClG,oBAAoB,EAAE,yBAAyB,GAChD,MAAM,aAAa,CAAA;AAGpB;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,OAAO,GAA2B,EAAE,EAAmB,EAAE;IAC7F,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,IAAI,CAAA;IAC3C,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,sBAAsB,CAAA;IACjE,MAAM,cAAc,GAAG,OAAO,CAAC,cAAc,IAAI,yBAAyB,CAAA;IAC1E,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,oBAAoB,CAAA;IAC3D,MAAM,KAAK,GAAG,IAAI,GAAG,EAA+B,CAAA;IAEpD,MAAM,UAAU,GAAG,GAA6B,EAAE,CAChD,OAAO,CAAC,QAAQ,IAAI,CAAC,OAAO,QAAQ,KAAK,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;IAEzE,MAAM,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AA;gBAChG,CAAC,CAAC;aACH,CAAC,CAAA;YACF,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,EAAE,EAAE,CAAC;gBAC9C,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAA;YAC5C,CAAC;YACD,OAAO,KAAK,CAAA;QACd,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,gBAAgB,CAAC,SAAS,EAAE,sBAAsB,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA;QAChG,CAAC;gBAAS,CAAC;YACT,YAAY,CAAC,KAAK,CAAC,CAAA;QACrB,CAAC;IACH,CAAC,CAAA;IAED,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAA;AAC3B,CAAC,CAAA;AAED,gFAAgF;AAChF,MAAM,CAAC,MAAM,eAAe,GAAG,qBAAqB,EAAE,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CaptchaWidget } from '@owlmeans/web-captcha/react';
|
|
2
|
+
/**
|
|
3
|
+
* Google's reCAPTCHA v2 checkbox as a `@owlmeans/web-captcha` widget: give it to the client
|
|
4
|
+
* (`appendRecaptchaClient({ widget: RecaptchaCheckbox })`) and a panel's captcha sign-in renders it.
|
|
5
|
+
* Needs a v2 (checkbox) site key; an expired token is reported as `null`.
|
|
6
|
+
*/
|
|
7
|
+
export declare const RecaptchaCheckbox: CaptchaWidget;
|
|
8
|
+
//# sourceMappingURL=checkbox.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkbox.d.ts","sourceRoot":"","sources":["../../src/react/checkbox.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAEhE;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,EAAE,aAQ5B,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import ReCAPTCHA from 'react-google-recaptcha';
|
|
3
|
+
/**
|
|
4
|
+
* Google's reCAPTCHA v2 checkbox as a `@owlmeans/web-captcha` widget: give it to the client
|
|
5
|
+
* (`appendRecaptchaClient({ widget: RecaptchaCheckbox })`) and a panel's captcha sign-in renders it.
|
|
6
|
+
* Needs a v2 (checkbox) site key; an expired token is reported as `null`.
|
|
7
|
+
*/
|
|
8
|
+
export const RecaptchaCheckbox = ({ siteKey, onToken, onReady, onError, language }) => _jsx(ReCAPTCHA, { sitekey: siteKey, onChange: onToken, onExpired: () => { onToken(null); }, onErrored: () => { onError?.(new Error('reCAPTCHA could not load')); }, asyncScriptOnLoad: () => { onReady?.(); }, ...(language != null ? { hl: language } : {}) });
|
|
9
|
+
//# sourceMappingURL=checkbox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkbox.js","sourceRoot":"","sources":["../../src/react/checkbox.tsx"],"names":[],"mappings":";AAAA,OAAO,SAAS,MAAM,wBAAwB,CAAA;AAG9C;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAkB,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,CACnG,KAAC,SAAS,IACR,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,OAAO,EACjB,SAAS,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA,CAAC,CAAC,EAClC,SAAS,EAAE,GAAG,EAAE,GAAG,OAAO,EAAE,CAAC,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC,CAAA,CAAC,CAAC,EACrE,iBAAiB,EAAE,GAAG,EAAE,GAAG,OAAO,EAAE,EAAE,CAAA,CAAC,CAAC,KACpC,CAAC,QAAQ,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,GAC9C,CAAA"}
|
package/build/react.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../src/react.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA"}
|
package/build/react.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.js","sourceRoot":"","sources":["../src/react.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA"}
|