axioma-recaptcha 6.0.107
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 +1 -0
- package/fesm2022/axioma-recaptcha.mjs +65 -0
- package/fesm2022/axioma-recaptcha.mjs.map +1 -0
- package/index.d.ts +21 -0
- package/package.json +25 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Google Recaptcha V3 client with deferred loading
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { InjectionToken, inject, DOCUMENT, Injectable } from '@angular/core';
|
|
3
|
+
import { ReplaySubject, of, mergeMap, Observable } from 'rxjs';
|
|
4
|
+
|
|
5
|
+
const RECAPTCHA_V3_SITE_KEY = new InjectionToken('RECAPTCHA_V3_SITE_KEY');
|
|
6
|
+
const RECAPTCHA_DISABLED = new InjectionToken('RECAPTCHA_DISABLED');
|
|
7
|
+
|
|
8
|
+
class RecaptchaService {
|
|
9
|
+
initialized = false;
|
|
10
|
+
document = inject(DOCUMENT);
|
|
11
|
+
key = inject(RECAPTCHA_V3_SITE_KEY);
|
|
12
|
+
disabled = inject(RECAPTCHA_DISABLED);
|
|
13
|
+
recaptcha$ = new ReplaySubject(1);
|
|
14
|
+
execute(action) {
|
|
15
|
+
this.init();
|
|
16
|
+
if (this.disabled) {
|
|
17
|
+
return of('');
|
|
18
|
+
}
|
|
19
|
+
return this.recaptcha$.pipe(mergeMap(r => new Observable(observer => r.ready(() => {
|
|
20
|
+
let promise = r.execute(this.key, { action });
|
|
21
|
+
promise.then(token => {
|
|
22
|
+
observer.next(token);
|
|
23
|
+
observer.complete();
|
|
24
|
+
}).catch(err => {
|
|
25
|
+
console.error('Recaptcha execution error:', err);
|
|
26
|
+
observer.next('');
|
|
27
|
+
});
|
|
28
|
+
}))));
|
|
29
|
+
}
|
|
30
|
+
init() {
|
|
31
|
+
if (this.initialized) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
this.initialized = true;
|
|
35
|
+
let script = this.document.createElement('script');
|
|
36
|
+
script.src = `https://www.google.com/recaptcha/api.js?render=${this.key}`;
|
|
37
|
+
script.async = true;
|
|
38
|
+
script.defer = true;
|
|
39
|
+
script.addEventListener('load', () => {
|
|
40
|
+
this.recaptcha$.next(window.grecaptcha);
|
|
41
|
+
});
|
|
42
|
+
this.document.body.appendChild(script);
|
|
43
|
+
}
|
|
44
|
+
constructor() {
|
|
45
|
+
}
|
|
46
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: RecaptchaService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
47
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: RecaptchaService, providedIn: 'root' });
|
|
48
|
+
}
|
|
49
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: RecaptchaService, decorators: [{
|
|
50
|
+
type: Injectable,
|
|
51
|
+
args: [{
|
|
52
|
+
providedIn: 'root'
|
|
53
|
+
}]
|
|
54
|
+
}], ctorParameters: () => [] });
|
|
55
|
+
|
|
56
|
+
/*
|
|
57
|
+
* Public API Surface of the library
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Generated bundle index. Do not edit.
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
export { RECAPTCHA_DISABLED, RECAPTCHA_V3_SITE_KEY, RecaptchaService };
|
|
65
|
+
//# sourceMappingURL=axioma-recaptcha.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"axioma-recaptcha.mjs","sources":["../../../projects/recaptcha/src/lib/recaptcha.token.ts","../../../projects/recaptcha/src/lib/recaptcha.service.ts","../../../projects/recaptcha/src/public-api.ts","../../../projects/recaptcha/src/axioma-recaptcha.ts"],"sourcesContent":["import { InjectionToken } from \"@angular/core\";\n\nexport const RECAPTCHA_V3_SITE_KEY = new InjectionToken<string>('RECAPTCHA_V3_SITE_KEY');\nexport const RECAPTCHA_DISABLED = new InjectionToken<boolean>('RECAPTCHA_DISABLED');","import { inject, Injectable, DOCUMENT } from '@angular/core';\nimport { Observable, of, ReplaySubject, mergeMap } from 'rxjs';\nimport { RECAPTCHA_DISABLED, RECAPTCHA_V3_SITE_KEY } from './recaptcha.token';\n\n\n@Injectable({\n providedIn: 'root'\n})\nexport class RecaptchaService {\n private initialized = false;\n private document = inject<Document>(DOCUMENT);\n private key = inject<string>(RECAPTCHA_V3_SITE_KEY);\n private disabled = inject<boolean>(RECAPTCHA_DISABLED);\n private recaptcha$ = new ReplaySubject<any>(1);\n execute(action: string): Observable<string> {\n this.init();\n if (this.disabled) {\n return of('');\n }\n return this.recaptcha$.pipe(mergeMap(r =>\n new Observable<string>(observer =>\n r.ready(() => {\n let promise = r.execute(this.key, { action }) as Promise<string>;\n promise.then(token => {\n observer.next(token);\n observer.complete();\n }).catch(err => {\n console.error('Recaptcha execution error:', err);\n observer.next('');\n });\n })\n )));\n }\n init() {\n if (this.initialized) {\n return;\n }\n this.initialized = true;\n let script = this.document.createElement('script');\n script.src = `https://www.google.com/recaptcha/api.js?render=${this.key}`;\n script.async = true;\n script.defer = true;\n script.addEventListener('load', () => {\n this.recaptcha$.next((<any>window).grecaptcha);\n });\n this.document.body.appendChild(script);\n }\n constructor() {\n\n }\n}\n","/*\n * Public API Surface of the library\n */\n\nexport * from './lib/recaptcha.service';\nexport * from './lib/recaptcha.token';","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;MAEa,qBAAqB,GAAG,IAAI,cAAc,CAAS,uBAAuB;MAC1E,kBAAkB,GAAG,IAAI,cAAc,CAAU,oBAAoB;;MCKrE,gBAAgB,CAAA;IACnB,WAAW,GAAG,KAAK;AACnB,IAAA,QAAQ,GAAG,MAAM,CAAW,QAAQ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K,GAAG,IAAI;AACnB,QAAA,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE,MAAK;YACnC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAO,MAAO,CAAC,UAAU,CAAC;AAChD,SAAC,CAAC;QACF,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;;AAExC,IAAA,WAAA,GAAA;;uGAvCW,gBAAgB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA;AAAhB,IAAA,OAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,gBAAgB,cAFf,MAAM,EAAA,CAAA;;2FAEP,gBAAgB,EAAA,UAAA,EAAA,CAAA;kBAH5B,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACV,oBAAA,UAAU,EAAE;AACb,iBAAA;;;ACPD;;AAEG;;ACFH;;AAEG;;;;"}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import * as i0 from '@angular/core';
|
|
3
|
+
import { InjectionToken } from '@angular/core';
|
|
4
|
+
|
|
5
|
+
declare class RecaptchaService {
|
|
6
|
+
private initialized;
|
|
7
|
+
private document;
|
|
8
|
+
private key;
|
|
9
|
+
private disabled;
|
|
10
|
+
private recaptcha$;
|
|
11
|
+
execute(action: string): Observable<string>;
|
|
12
|
+
init(): void;
|
|
13
|
+
constructor();
|
|
14
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<RecaptchaService, never>;
|
|
15
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<RecaptchaService>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
declare const RECAPTCHA_V3_SITE_KEY: InjectionToken<string>;
|
|
19
|
+
declare const RECAPTCHA_DISABLED: InjectionToken<boolean>;
|
|
20
|
+
|
|
21
|
+
export { RECAPTCHA_DISABLED, RECAPTCHA_V3_SITE_KEY, RecaptchaService };
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "axioma-recaptcha",
|
|
3
|
+
"author": "Petr Shelomovskiy",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"version": "6.0.107",
|
|
6
|
+
"peerDependencies": {
|
|
7
|
+
"@angular/common": "^19.2.0",
|
|
8
|
+
"@angular/core": "^19.2.0"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"tslib": "^2.3.0"
|
|
12
|
+
},
|
|
13
|
+
"sideEffects": false,
|
|
14
|
+
"module": "fesm2022/axioma-recaptcha.mjs",
|
|
15
|
+
"typings": "index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
"./package.json": {
|
|
18
|
+
"default": "./package.json"
|
|
19
|
+
},
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./index.d.ts",
|
|
22
|
+
"default": "./fesm2022/axioma-recaptcha.mjs"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|