@internetarchive/recaptcha-manager 0.1.2-alpha.1 → 1.0.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/.editorconfig +29 -29
- package/.github/workflows/ci.yml +27 -26
- package/.github/workflows/gh-pages-main.yml +39 -0
- package/.github/workflows/pr-preview.yml +63 -0
- package/.husky/pre-commit +1 -4
- package/.prettierignore +1 -0
- package/LICENSE +661 -661
- package/README.md +63 -85
- package/coverage/.gitignore +3 -0
- package/coverage/.placeholder +0 -0
- package/demo/app-root.ts +93 -93
- package/demo/index.html +21 -21
- package/dist/demo/app-root.d.ts +14 -14
- package/dist/demo/app-root.js +85 -85
- package/dist/demo/app-root.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/src/recaptcha-manager.d.ts +34 -35
- package/dist/src/recaptcha-manager.js +54 -52
- package/dist/src/recaptcha-manager.js.map +1 -1
- package/dist/src/recaptcha-widget.d.ts +38 -39
- package/dist/src/recaptcha-widget.js +95 -95
- package/dist/src/recaptcha-widget.js.map +1 -1
- package/dist/test/mock-grecaptcha.d.ts +23 -24
- package/dist/test/mock-grecaptcha.js +59 -61
- package/dist/test/mock-grecaptcha.js.map +1 -1
- package/dist/test/mock-lazy-loader.d.ts +15 -15
- package/dist/test/mock-lazy-loader.js +17 -16
- package/dist/test/mock-lazy-loader.js.map +1 -1
- package/dist/test/recaptcha-manager.test.d.ts +1 -1
- package/dist/test/recaptcha-manager.test.js +137 -137
- package/dist/test/recaptcha-manager.test.js.map +1 -1
- package/dist/vite.config.d.ts +2 -0
- package/dist/vite.config.js +25 -0
- package/dist/vite.config.js.map +1 -0
- package/eslint.config.mjs +53 -0
- package/index.ts +10 -10
- package/package.json +76 -98
- package/renovate.json +6 -0
- package/src/recaptcha-manager.ts +89 -87
- package/src/recaptcha-widget.ts +148 -148
- package/ssl/server.crt +22 -0
- package/ssl/server.key +28 -0
- package/test/mock-grecaptcha.ts +85 -87
- package/test/mock-lazy-loader.ts +39 -38
- package/test/recaptcha-manager.test.ts +151 -151
- package/tsconfig.json +31 -20
- package/vite.config.ts +25 -0
- package/web-dev-server.config.mjs +32 -28
- package/web-test-runner.config.mjs +41 -41
package/README.md
CHANGED
|
@@ -1,85 +1,63 @@
|
|
|
1
|
-

|
|
2
|
-
|
|
3
|
-
# Internet Archive reCaptcha Manager
|
|
4
|
-
|
|
5
|
-
A library to lazy load and interact with reCaptcha
|
|
6
|
-
|
|
7
|
-
## Installation
|
|
8
|
-
|
|
9
|
-
```shell
|
|
10
|
-
>
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## Usage
|
|
14
|
-
|
|
15
|
-
```ts
|
|
16
|
-
const recaptchaManager = new RecaptchaManager({
|
|
17
|
-
defaultSiteKey: 'your-site-key',
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
// will load recaptcha library if it's not loaded
|
|
21
|
-
const recaptchaWidget = await recaptchaManager.getRecaptchaWidget({
|
|
22
|
-
recaptchaParams: {
|
|
23
|
-
tabindex: 0,
|
|
24
|
-
theme: 'light',
|
|
25
|
-
type: 'image',
|
|
26
|
-
},
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
const token = await recaptchaWidget.execute();
|
|
30
|
-
|
|
31
|
-
// submit token with your post and validate on the backend
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
For more usage examples, see `demo/app-root.ts` and `test/recaptcha-manager.test.ts`.
|
|
35
|
-
|
|
36
|
-
## Local Demo with `web-dev-server`
|
|
37
|
-
```bash
|
|
38
|
-
|
|
39
|
-
```
|
|
40
|
-
To run a local development server that serves the basic demo located in `demo/index.html`
|
|
41
|
-
|
|
42
|
-
## Testing with Web Test Runner
|
|
43
|
-
To run the suite of Web Test Runner tests, run
|
|
44
|
-
```bash
|
|
45
|
-
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
To run the tests in watch mode (for <abbr title="test driven development">TDD</abbr>, for example), run
|
|
49
|
-
|
|
50
|
-
```bash
|
|
51
|
-
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
## Linting with ESLint, Prettier, and Types
|
|
55
|
-
To scan the project for linting errors, run
|
|
56
|
-
```bash
|
|
57
|
-
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
```bash
|
|
62
|
-
|
|
63
|
-
```
|
|
64
|
-
```bash
|
|
65
|
-
yarn run lint:prettier
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
To automatically fix many linting errors, run
|
|
69
|
-
```bash
|
|
70
|
-
yarn run format
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
You can format using ESLint and Prettier individually as well
|
|
74
|
-
```bash
|
|
75
|
-
yarn run format:eslint
|
|
76
|
-
```
|
|
77
|
-
```bash
|
|
78
|
-
yarn run format:prettier
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
## Tooling configs
|
|
82
|
-
|
|
83
|
-
For most of the tools, the configuration is in the `package.json` to reduce the amount of files in your project.
|
|
84
|
-
|
|
85
|
-
If you customize the configuration a lot, you can consider moving them to individual files.
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
# Internet Archive reCaptcha Manager
|
|
4
|
+
|
|
5
|
+
A library to lazy load and interact with reCaptcha
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```shell
|
|
10
|
+
> npm install @internetarchive/recaptcha-manager
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
const recaptchaManager = new RecaptchaManager({
|
|
17
|
+
defaultSiteKey: 'your-site-key',
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// will load recaptcha library if it's not loaded
|
|
21
|
+
const recaptchaWidget = await recaptchaManager.getRecaptchaWidget({
|
|
22
|
+
recaptchaParams: {
|
|
23
|
+
tabindex: 0,
|
|
24
|
+
theme: 'light',
|
|
25
|
+
type: 'image',
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const token = await recaptchaWidget.execute();
|
|
30
|
+
|
|
31
|
+
// submit token with your post and validate on the backend
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
For more usage examples, see `demo/app-root.ts` and `test/recaptcha-manager.test.ts`.
|
|
35
|
+
|
|
36
|
+
## Local Demo with `web-dev-server`
|
|
37
|
+
```bash
|
|
38
|
+
npm run start
|
|
39
|
+
```
|
|
40
|
+
To run a local development server that serves the basic demo located in `demo/index.html`
|
|
41
|
+
|
|
42
|
+
## Testing with Web Test Runner
|
|
43
|
+
To run the suite of Web Test Runner tests, run
|
|
44
|
+
```bash
|
|
45
|
+
npm run test
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
To run the tests in watch mode (for <abbr title="test driven development">TDD</abbr>, for example), run
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
npm run test:watch
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Linting with ESLint, Prettier, and Types
|
|
55
|
+
To scan the project for linting errors, run
|
|
56
|
+
```bash
|
|
57
|
+
npm run lint
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
To automatically fix many linting errors, run
|
|
61
|
+
```bash
|
|
62
|
+
npm run format
|
|
63
|
+
```
|
|
File without changes
|
package/demo/app-root.ts
CHANGED
|
@@ -1,93 +1,93 @@
|
|
|
1
|
-
import { html, css, LitElement } from 'lit';
|
|
2
|
-
import { customElement, state } from 'lit/decorators.js';
|
|
3
|
-
import { RecaptchaWidgetInterface } from '../src/recaptcha-widget';
|
|
4
|
-
import {
|
|
5
|
-
RecaptchaManager,
|
|
6
|
-
RecaptchaManagerInterface,
|
|
7
|
-
} from '../src/recaptcha-manager';
|
|
8
|
-
|
|
9
|
-
@customElement('app-root')
|
|
10
|
-
export class AppRoot extends LitElement {
|
|
11
|
-
@state() result?: string;
|
|
12
|
-
|
|
13
|
-
@state() result2?: string;
|
|
14
|
-
|
|
15
|
-
private recaptchaManager: RecaptchaManagerInterface = new RecaptchaManager({
|
|
16
|
-
defaultSiteKey: '
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
private recaptcha1?: RecaptchaWidgetInterface;
|
|
20
|
-
|
|
21
|
-
private recaptcha2?: RecaptchaWidgetInterface;
|
|
22
|
-
|
|
23
|
-
render() {
|
|
24
|
-
return html`
|
|
25
|
-
<p>
|
|
26
|
-
<button @click="${this.loadRecaptcha}">Load Recaptcha</button
|
|
27
|
-
><button @click="${this.executeRecaptcha}">Execute Recaptcha</button>
|
|
28
|
-
</p>
|
|
29
|
-
${this.result
|
|
30
|
-
? html`<p><strong>Token:</strong></p>
|
|
31
|
-
<p>${this.result}</p>`
|
|
32
|
-
: ''}
|
|
33
|
-
<p>
|
|
34
|
-
<button @click="${this.loadRecaptcha2}">Load Another Recaptcha</button
|
|
35
|
-
><button @click="${this.executeRecaptcha2}">
|
|
36
|
-
Execute Another Recaptcha
|
|
37
|
-
</button>
|
|
38
|
-
</p>
|
|
39
|
-
${this.result2
|
|
40
|
-
? html`<p><strong>Token 2:</strong></p>
|
|
41
|
-
<p>${this.result2}</p>`
|
|
42
|
-
: ''}
|
|
43
|
-
`;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
private async loadRecaptcha() {
|
|
47
|
-
this.recaptcha1 = await this.recaptchaManager?.getRecaptchaWidget({
|
|
48
|
-
recaptchaParams: {
|
|
49
|
-
tabindex: 0,
|
|
50
|
-
theme: 'light',
|
|
51
|
-
type: 'image',
|
|
52
|
-
},
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
private async executeRecaptcha() {
|
|
57
|
-
if (!this.recaptcha1) {
|
|
58
|
-
await this.loadRecaptcha();
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (!this.recaptcha1) {
|
|
62
|
-
console.error('error loading recaptcha');
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
this.result = await this.recaptcha1.execute();
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
private async loadRecaptcha2() {
|
|
70
|
-
this.recaptcha2 = await this.recaptchaManager?.getRecaptchaWidget({
|
|
71
|
-
siteKey: '<your-site-key>',
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
private async executeRecaptcha2() {
|
|
76
|
-
if (!this.recaptcha2) {
|
|
77
|
-
await this.loadRecaptcha();
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (!this.recaptcha2) {
|
|
81
|
-
console.error('error loading recaptcha');
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
this.result2 = await this.recaptcha2.execute();
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
static styles = css`
|
|
89
|
-
:host {
|
|
90
|
-
display: block;
|
|
91
|
-
}
|
|
92
|
-
`;
|
|
93
|
-
}
|
|
1
|
+
import { html, css, LitElement } from 'lit';
|
|
2
|
+
import { customElement, state } from 'lit/decorators.js';
|
|
3
|
+
import { RecaptchaWidgetInterface } from '../src/recaptcha-widget';
|
|
4
|
+
import {
|
|
5
|
+
RecaptchaManager,
|
|
6
|
+
RecaptchaManagerInterface,
|
|
7
|
+
} from '../src/recaptcha-manager';
|
|
8
|
+
|
|
9
|
+
@customElement('app-root')
|
|
10
|
+
export class AppRoot extends LitElement {
|
|
11
|
+
@state() result?: string;
|
|
12
|
+
|
|
13
|
+
@state() result2?: string;
|
|
14
|
+
|
|
15
|
+
private recaptchaManager: RecaptchaManagerInterface = new RecaptchaManager({
|
|
16
|
+
defaultSiteKey: '6Ld64a8UAAAAAGbDwi1927ztGNw7YABQ-dqzvTN2',
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
private recaptcha1?: RecaptchaWidgetInterface;
|
|
20
|
+
|
|
21
|
+
private recaptcha2?: RecaptchaWidgetInterface;
|
|
22
|
+
|
|
23
|
+
render() {
|
|
24
|
+
return html`
|
|
25
|
+
<p>
|
|
26
|
+
<button @click="${this.loadRecaptcha}">Load Recaptcha</button
|
|
27
|
+
><button @click="${this.executeRecaptcha}">Execute Recaptcha</button>
|
|
28
|
+
</p>
|
|
29
|
+
${this.result
|
|
30
|
+
? html`<p><strong>Token:</strong></p>
|
|
31
|
+
<p>${this.result}</p>`
|
|
32
|
+
: ''}
|
|
33
|
+
<p>
|
|
34
|
+
<button @click="${this.loadRecaptcha2}">Load Another Recaptcha</button
|
|
35
|
+
><button @click="${this.executeRecaptcha2}">
|
|
36
|
+
Execute Another Recaptcha
|
|
37
|
+
</button>
|
|
38
|
+
</p>
|
|
39
|
+
${this.result2
|
|
40
|
+
? html`<p><strong>Token 2:</strong></p>
|
|
41
|
+
<p>${this.result2}</p>`
|
|
42
|
+
: ''}
|
|
43
|
+
`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private async loadRecaptcha() {
|
|
47
|
+
this.recaptcha1 = await this.recaptchaManager?.getRecaptchaWidget({
|
|
48
|
+
recaptchaParams: {
|
|
49
|
+
tabindex: 0,
|
|
50
|
+
theme: 'light',
|
|
51
|
+
type: 'image',
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private async executeRecaptcha() {
|
|
57
|
+
if (!this.recaptcha1) {
|
|
58
|
+
await this.loadRecaptcha();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (!this.recaptcha1) {
|
|
62
|
+
console.error('error loading recaptcha');
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
this.result = await this.recaptcha1.execute();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
private async loadRecaptcha2() {
|
|
70
|
+
this.recaptcha2 = await this.recaptchaManager?.getRecaptchaWidget({
|
|
71
|
+
siteKey: '<your-site-key>',
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
private async executeRecaptcha2() {
|
|
76
|
+
if (!this.recaptcha2) {
|
|
77
|
+
await this.loadRecaptcha();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (!this.recaptcha2) {
|
|
81
|
+
console.error('error loading recaptcha');
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
this.result2 = await this.recaptcha2.execute();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
static styles = css`
|
|
89
|
+
:host {
|
|
90
|
+
display: block;
|
|
91
|
+
}
|
|
92
|
+
`;
|
|
93
|
+
}
|
package/demo/index.html
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="en-GB">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8">
|
|
5
|
-
<style>
|
|
6
|
-
html {
|
|
7
|
-
font-size: 10px; /* This is to match petabox's base font size */
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
body {
|
|
11
|
-
background: #fafafa;
|
|
12
|
-
}
|
|
13
|
-
</style>
|
|
14
|
-
</head>
|
|
15
|
-
<body>
|
|
16
|
-
<app-root></app-root>
|
|
17
|
-
|
|
18
|
-
<script type="module" src="../dist/demo/app-root.js">
|
|
19
|
-
</script>
|
|
20
|
-
</body>
|
|
21
|
-
</html>
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en-GB">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<style>
|
|
6
|
+
html {
|
|
7
|
+
font-size: 10px; /* This is to match petabox's base font size */
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
body {
|
|
11
|
+
background: #fafafa;
|
|
12
|
+
}
|
|
13
|
+
</style>
|
|
14
|
+
</head>
|
|
15
|
+
<body>
|
|
16
|
+
<app-root></app-root>
|
|
17
|
+
|
|
18
|
+
<script type="module" src="../dist/demo/app-root.js">
|
|
19
|
+
</script>
|
|
20
|
+
</body>
|
|
21
|
+
</html>
|
package/dist/demo/app-root.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { LitElement } from 'lit';
|
|
2
|
-
export declare class AppRoot extends LitElement {
|
|
3
|
-
result?: string;
|
|
4
|
-
result2?: string;
|
|
5
|
-
private recaptchaManager;
|
|
6
|
-
private recaptcha1?;
|
|
7
|
-
private recaptcha2?;
|
|
8
|
-
render(): import("lit").TemplateResult<1>;
|
|
9
|
-
private loadRecaptcha;
|
|
10
|
-
private executeRecaptcha;
|
|
11
|
-
private loadRecaptcha2;
|
|
12
|
-
private executeRecaptcha2;
|
|
13
|
-
static styles: import("lit").CSSResult;
|
|
14
|
-
}
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
export declare class AppRoot extends LitElement {
|
|
3
|
+
result?: string;
|
|
4
|
+
result2?: string;
|
|
5
|
+
private recaptchaManager;
|
|
6
|
+
private recaptcha1?;
|
|
7
|
+
private recaptcha2?;
|
|
8
|
+
render(): import("lit").TemplateResult<1>;
|
|
9
|
+
private loadRecaptcha;
|
|
10
|
+
private executeRecaptcha;
|
|
11
|
+
private loadRecaptcha2;
|
|
12
|
+
private executeRecaptcha2;
|
|
13
|
+
static styles: import("lit").CSSResult;
|
|
14
|
+
}
|
package/dist/demo/app-root.js
CHANGED
|
@@ -1,86 +1,86 @@
|
|
|
1
|
-
import { __decorate } from "tslib";
|
|
2
|
-
import { html, css, LitElement } from 'lit';
|
|
3
|
-
import { customElement, state } from 'lit/decorators.js';
|
|
4
|
-
import { RecaptchaManager, } from '../src/recaptcha-manager';
|
|
5
|
-
let AppRoot = class AppRoot extends LitElement {
|
|
6
|
-
constructor() {
|
|
7
|
-
super(...arguments);
|
|
8
|
-
this.recaptchaManager = new RecaptchaManager({
|
|
9
|
-
defaultSiteKey: '
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
render() {
|
|
13
|
-
return html `
|
|
14
|
-
<p>
|
|
15
|
-
<button @click="${this.loadRecaptcha}">Load Recaptcha</button
|
|
16
|
-
><button @click="${this.executeRecaptcha}">Execute Recaptcha</button>
|
|
17
|
-
</p>
|
|
18
|
-
${this.result
|
|
19
|
-
? html `<p><strong>Token:</strong></p>
|
|
20
|
-
<p>${this.result}</p>`
|
|
21
|
-
: ''}
|
|
22
|
-
<p>
|
|
23
|
-
<button @click="${this.loadRecaptcha2}">Load Another Recaptcha</button
|
|
24
|
-
><button @click="${this.executeRecaptcha2}">
|
|
25
|
-
Execute Another Recaptcha
|
|
26
|
-
</button>
|
|
27
|
-
</p>
|
|
28
|
-
${this.result2
|
|
29
|
-
? html `<p><strong>Token 2:</strong></p>
|
|
30
|
-
<p>${this.result2}</p>`
|
|
31
|
-
: ''}
|
|
32
|
-
`;
|
|
33
|
-
}
|
|
34
|
-
async loadRecaptcha() {
|
|
35
|
-
var _a;
|
|
36
|
-
this.recaptcha1 = await ((_a = this.recaptchaManager) === null || _a === void 0 ? void 0 : _a.getRecaptchaWidget({
|
|
37
|
-
recaptchaParams: {
|
|
38
|
-
tabindex: 0,
|
|
39
|
-
theme: 'light',
|
|
40
|
-
type: 'image',
|
|
41
|
-
},
|
|
42
|
-
}));
|
|
43
|
-
}
|
|
44
|
-
async executeRecaptcha() {
|
|
45
|
-
if (!this.recaptcha1) {
|
|
46
|
-
await this.loadRecaptcha();
|
|
47
|
-
}
|
|
48
|
-
if (!this.recaptcha1) {
|
|
49
|
-
console.error('error loading recaptcha');
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
this.result = await this.recaptcha1.execute();
|
|
53
|
-
}
|
|
54
|
-
async loadRecaptcha2() {
|
|
55
|
-
var _a;
|
|
56
|
-
this.recaptcha2 = await ((_a = this.recaptchaManager) === null || _a === void 0 ? void 0 : _a.getRecaptchaWidget({
|
|
57
|
-
siteKey: '<your-site-key>',
|
|
58
|
-
}));
|
|
59
|
-
}
|
|
60
|
-
async executeRecaptcha2() {
|
|
61
|
-
if (!this.recaptcha2) {
|
|
62
|
-
await this.loadRecaptcha();
|
|
63
|
-
}
|
|
64
|
-
if (!this.recaptcha2) {
|
|
65
|
-
console.error('error loading recaptcha');
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
this.result2 = await this.recaptcha2.execute();
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
AppRoot.styles = css `
|
|
72
|
-
:host {
|
|
73
|
-
display: block;
|
|
74
|
-
}
|
|
75
|
-
`;
|
|
76
|
-
__decorate([
|
|
77
|
-
state()
|
|
78
|
-
], AppRoot.prototype, "result", void 0);
|
|
79
|
-
__decorate([
|
|
80
|
-
state()
|
|
81
|
-
], AppRoot.prototype, "result2", void 0);
|
|
82
|
-
AppRoot = __decorate([
|
|
83
|
-
customElement('app-root')
|
|
84
|
-
], AppRoot);
|
|
85
|
-
export { AppRoot };
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { html, css, LitElement } from 'lit';
|
|
3
|
+
import { customElement, state } from 'lit/decorators.js';
|
|
4
|
+
import { RecaptchaManager, } from '../src/recaptcha-manager';
|
|
5
|
+
let AppRoot = class AppRoot extends LitElement {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
this.recaptchaManager = new RecaptchaManager({
|
|
9
|
+
defaultSiteKey: '6Ld64a8UAAAAAGbDwi1927ztGNw7YABQ-dqzvTN2',
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
render() {
|
|
13
|
+
return html `
|
|
14
|
+
<p>
|
|
15
|
+
<button @click="${this.loadRecaptcha}">Load Recaptcha</button
|
|
16
|
+
><button @click="${this.executeRecaptcha}">Execute Recaptcha</button>
|
|
17
|
+
</p>
|
|
18
|
+
${this.result
|
|
19
|
+
? html `<p><strong>Token:</strong></p>
|
|
20
|
+
<p>${this.result}</p>`
|
|
21
|
+
: ''}
|
|
22
|
+
<p>
|
|
23
|
+
<button @click="${this.loadRecaptcha2}">Load Another Recaptcha</button
|
|
24
|
+
><button @click="${this.executeRecaptcha2}">
|
|
25
|
+
Execute Another Recaptcha
|
|
26
|
+
</button>
|
|
27
|
+
</p>
|
|
28
|
+
${this.result2
|
|
29
|
+
? html `<p><strong>Token 2:</strong></p>
|
|
30
|
+
<p>${this.result2}</p>`
|
|
31
|
+
: ''}
|
|
32
|
+
`;
|
|
33
|
+
}
|
|
34
|
+
async loadRecaptcha() {
|
|
35
|
+
var _a;
|
|
36
|
+
this.recaptcha1 = await ((_a = this.recaptchaManager) === null || _a === void 0 ? void 0 : _a.getRecaptchaWidget({
|
|
37
|
+
recaptchaParams: {
|
|
38
|
+
tabindex: 0,
|
|
39
|
+
theme: 'light',
|
|
40
|
+
type: 'image',
|
|
41
|
+
},
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
44
|
+
async executeRecaptcha() {
|
|
45
|
+
if (!this.recaptcha1) {
|
|
46
|
+
await this.loadRecaptcha();
|
|
47
|
+
}
|
|
48
|
+
if (!this.recaptcha1) {
|
|
49
|
+
console.error('error loading recaptcha');
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
this.result = await this.recaptcha1.execute();
|
|
53
|
+
}
|
|
54
|
+
async loadRecaptcha2() {
|
|
55
|
+
var _a;
|
|
56
|
+
this.recaptcha2 = await ((_a = this.recaptchaManager) === null || _a === void 0 ? void 0 : _a.getRecaptchaWidget({
|
|
57
|
+
siteKey: '<your-site-key>',
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
async executeRecaptcha2() {
|
|
61
|
+
if (!this.recaptcha2) {
|
|
62
|
+
await this.loadRecaptcha();
|
|
63
|
+
}
|
|
64
|
+
if (!this.recaptcha2) {
|
|
65
|
+
console.error('error loading recaptcha');
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
this.result2 = await this.recaptcha2.execute();
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
AppRoot.styles = css `
|
|
72
|
+
:host {
|
|
73
|
+
display: block;
|
|
74
|
+
}
|
|
75
|
+
`;
|
|
76
|
+
__decorate([
|
|
77
|
+
state()
|
|
78
|
+
], AppRoot.prototype, "result", void 0);
|
|
79
|
+
__decorate([
|
|
80
|
+
state()
|
|
81
|
+
], AppRoot.prototype, "result2", void 0);
|
|
82
|
+
AppRoot = __decorate([
|
|
83
|
+
customElement('app-root')
|
|
84
|
+
], AppRoot);
|
|
85
|
+
export { AppRoot };
|
|
86
86
|
//# sourceMappingURL=app-root.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-root.js","sourceRoot":"","sources":["../../demo/app-root.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAEzD,OAAO,EACL,gBAAgB,GAEjB,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"app-root.js","sourceRoot":"","sources":["../../demo/app-root.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAEzD,OAAO,EACL,gBAAgB,GAEjB,MAAM,0BAA0B,CAAC;AAG3B,IAAM,OAAO,GAAb,MAAM,OAAQ,SAAQ,UAAU;IAAhC;;QAKG,qBAAgB,GAA8B,IAAI,gBAAgB,CAAC;YACzE,cAAc,EAAE,0CAA0C;SAC3D,CAAC,CAAC;IA4EL,CAAC;IAtEC,MAAM;QACJ,OAAO,IAAI,CAAA;;0BAEW,IAAI,CAAC,aAAa;2BACjB,IAAI,CAAC,gBAAgB;;QAExC,IAAI,CAAC,MAAM;YACX,CAAC,CAAC,IAAI,CAAA;iBACG,IAAI,CAAC,MAAM,MAAM;YAC1B,CAAC,CAAC,EAAE;;0BAEc,IAAI,CAAC,cAAc;2BAClB,IAAI,CAAC,iBAAiB;;;;QAIzC,IAAI,CAAC,OAAO;YACZ,CAAC,CAAC,IAAI,CAAA;iBACG,IAAI,CAAC,OAAO,MAAM;YAC3B,CAAC,CAAC,EAAE;KACP,CAAC;IACJ,CAAC;IAEO,KAAK,CAAC,aAAa;;QACzB,IAAI,CAAC,UAAU,GAAG,MAAM,CAAA,MAAA,IAAI,CAAC,gBAAgB,0CAAE,kBAAkB,CAAC;YAChE,eAAe,EAAE;gBACf,QAAQ,EAAE,CAAC;gBACX,KAAK,EAAE,OAAO;gBACd,IAAI,EAAE,OAAO;aACd;SACF,CAAC,CAAA,CAAC;IACL,CAAC;IAEO,KAAK,CAAC,gBAAgB;QAC5B,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACrB,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC;QAC7B,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACrB,OAAO,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC;YACzC,OAAO;QACT,CAAC;QAED,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;IAChD,CAAC;IAEO,KAAK,CAAC,cAAc;;QAC1B,IAAI,CAAC,UAAU,GAAG,MAAM,CAAA,MAAA,IAAI,CAAC,gBAAgB,0CAAE,kBAAkB,CAAC;YAChE,OAAO,EAAE,iBAAiB;SAC3B,CAAC,CAAA,CAAC;IACL,CAAC;IAEO,KAAK,CAAC,iBAAiB;QAC7B,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACrB,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC;QAC7B,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACrB,OAAO,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC;YACzC,OAAO;QACT,CAAC;QAED,IAAI,CAAC,OAAO,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;IACjD,CAAC;;AAEM,cAAM,GAAG,GAAG,CAAA;;;;GAIlB,AAJY,CAIX;AAjFO;IAAR,KAAK,EAAE;uCAAiB;AAEhB;IAAR,KAAK,EAAE;wCAAkB;AAHf,OAAO;IADnB,aAAa,CAAC,UAAU,CAAC;GACb,OAAO,CAmFnB","sourcesContent":["import { html, css, LitElement } from 'lit';\nimport { customElement, state } from 'lit/decorators.js';\nimport { RecaptchaWidgetInterface } from '../src/recaptcha-widget';\nimport {\n RecaptchaManager,\n RecaptchaManagerInterface,\n} from '../src/recaptcha-manager';\n\n@customElement('app-root')\nexport class AppRoot extends LitElement {\n @state() result?: string;\n\n @state() result2?: string;\n\n private recaptchaManager: RecaptchaManagerInterface = new RecaptchaManager({\n defaultSiteKey: '6Ld64a8UAAAAAGbDwi1927ztGNw7YABQ-dqzvTN2',\n });\n\n private recaptcha1?: RecaptchaWidgetInterface;\n\n private recaptcha2?: RecaptchaWidgetInterface;\n\n render() {\n return html`\n <p>\n <button @click=\"${this.loadRecaptcha}\">Load Recaptcha</button\n ><button @click=\"${this.executeRecaptcha}\">Execute Recaptcha</button>\n </p>\n ${this.result\n ? html`<p><strong>Token:</strong></p>\n <p>${this.result}</p>`\n : ''}\n <p>\n <button @click=\"${this.loadRecaptcha2}\">Load Another Recaptcha</button\n ><button @click=\"${this.executeRecaptcha2}\">\n Execute Another Recaptcha\n </button>\n </p>\n ${this.result2\n ? html`<p><strong>Token 2:</strong></p>\n <p>${this.result2}</p>`\n : ''}\n `;\n }\n\n private async loadRecaptcha() {\n this.recaptcha1 = await this.recaptchaManager?.getRecaptchaWidget({\n recaptchaParams: {\n tabindex: 0,\n theme: 'light',\n type: 'image',\n },\n });\n }\n\n private async executeRecaptcha() {\n if (!this.recaptcha1) {\n await this.loadRecaptcha();\n }\n\n if (!this.recaptcha1) {\n console.error('error loading recaptcha');\n return;\n }\n\n this.result = await this.recaptcha1.execute();\n }\n\n private async loadRecaptcha2() {\n this.recaptcha2 = await this.recaptchaManager?.getRecaptchaWidget({\n siteKey: '<your-site-key>',\n });\n }\n\n private async executeRecaptcha2() {\n if (!this.recaptcha2) {\n await this.loadRecaptcha();\n }\n\n if (!this.recaptcha2) {\n console.error('error loading recaptcha');\n return;\n }\n\n this.result2 = await this.recaptcha2.execute();\n }\n\n static styles = css`\n :host {\n display: block;\n }\n `;\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { RecaptchaManager, RecaptchaManagerInterface, } from './src/recaptcha-manager
|
|
2
|
-
export { RecaptchaWidget, RecaptchaWidgetInterface, RecaptchaWidgetConfig, } from './src/recaptcha-widget
|
|
1
|
+
export { RecaptchaManager, RecaptchaManagerInterface, } from './src/recaptcha-manager';
|
|
2
|
+
export { RecaptchaWidget, RecaptchaWidgetInterface, RecaptchaWidgetConfig, } from './src/recaptcha-widget';
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { RecaptchaManager, } from './src/recaptcha-manager
|
|
2
|
-
export { RecaptchaWidget, } from './src/recaptcha-widget
|
|
1
|
+
export { RecaptchaManager, } from './src/recaptcha-manager';
|
|
2
|
+
export { RecaptchaWidget, } from './src/recaptcha-widget';
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,GAEjB,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,GAEjB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EACL,eAAe,GAGhB,MAAM,wBAAwB,CAAC","sourcesContent":["export {\n RecaptchaManager,\n RecaptchaManagerInterface,\n} from './src/recaptcha-manager';\n\nexport {\n RecaptchaWidget,\n RecaptchaWidgetInterface,\n RecaptchaWidgetConfig,\n} from './src/recaptcha-widget';\n"]}
|