axioma-recaptcha 6.0.107 → 6.0.109
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/fesm2022/axioma-recaptcha.mjs +23 -22
- package/fesm2022/axioma-recaptcha.mjs.map +1 -1
- package/index.d.ts +13 -6
- package/package.json +1 -1
|
@@ -1,39 +1,40 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
2
|
import { InjectionToken, inject, DOCUMENT, Injectable } from '@angular/core';
|
|
3
|
-
import { ReplaySubject,
|
|
3
|
+
import { ReplaySubject, mergeMap, of, Observable } from 'rxjs';
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
const RECAPTCHA_DISABLED = new InjectionToken('RECAPTCHA_DISABLED');
|
|
5
|
+
const RECAPTCHA_CONFIG_LOADER = new InjectionToken('RECAPTCHA_CONFIG_LOADER');
|
|
7
6
|
|
|
8
7
|
class RecaptchaService {
|
|
8
|
+
configLoader = inject(RECAPTCHA_CONFIG_LOADER);
|
|
9
9
|
initialized = false;
|
|
10
10
|
document = inject(DOCUMENT);
|
|
11
|
-
key = inject(RECAPTCHA_V3_SITE_KEY);
|
|
12
|
-
disabled = inject(RECAPTCHA_DISABLED);
|
|
13
11
|
recaptcha$ = new ReplaySubject(1);
|
|
14
12
|
execute(action) {
|
|
15
|
-
this.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
13
|
+
return this.configLoader.load().pipe(mergeMap(config => {
|
|
14
|
+
if (config.disabled) {
|
|
15
|
+
console.warn('Recaptcha is disabled');
|
|
16
|
+
return of('');
|
|
17
|
+
}
|
|
18
|
+
this.init(config.siteKey);
|
|
19
|
+
return this.recaptcha$.pipe(mergeMap(r => new Observable(observer => r.ready(() => {
|
|
20
|
+
let promise = r.execute(config, { 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
|
+
}));
|
|
29
30
|
}
|
|
30
|
-
init() {
|
|
31
|
+
init(key) {
|
|
31
32
|
if (this.initialized) {
|
|
32
33
|
return;
|
|
33
34
|
}
|
|
34
35
|
this.initialized = true;
|
|
35
36
|
let script = this.document.createElement('script');
|
|
36
|
-
script.src = `https://www.google.com/recaptcha/api.js?render=${
|
|
37
|
+
script.src = `https://www.google.com/recaptcha/api.js?render=${key}`;
|
|
37
38
|
script.async = true;
|
|
38
39
|
script.defer = true;
|
|
39
40
|
script.addEventListener('load', () => {
|
|
@@ -61,5 +62,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.3", ngImpor
|
|
|
61
62
|
* Generated bundle index. Do not edit.
|
|
62
63
|
*/
|
|
63
64
|
|
|
64
|
-
export {
|
|
65
|
+
export { RECAPTCHA_CONFIG_LOADER, RecaptchaService };
|
|
65
66
|
//# sourceMappingURL=axioma-recaptcha.mjs.map
|
|
@@ -1 +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\";\
|
|
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\";\nimport { RecaptchaConfigLoader } from \"./recaptcha-config-loader\";\n\nexport const RECAPTCHA_CONFIG_LOADER = new InjectionToken<RecaptchaConfigLoader>('RECAPTCHA_CONFIG_LOADER');","import { inject, Injectable, DOCUMENT } from '@angular/core';\nimport { Observable, of, ReplaySubject, mergeMap } from 'rxjs';\nimport { RECAPTCHA_CONFIG_LOADER } from './recaptcha.token';\n\n\n@Injectable({\n providedIn: 'root'\n})\nexport class RecaptchaService {\n private configLoader = inject(RECAPTCHA_CONFIG_LOADER);\n private initialized = false;\n private document = inject<Document>(DOCUMENT);\n private recaptcha$ = new ReplaySubject<any>(1);\n execute(action: string): Observable<string> {\n return this.configLoader.load().pipe(mergeMap(config => {\n if (config.disabled) {\n console.warn('Recaptcha is disabled');\n return of('');\n }\n this.init(config.siteKey);\n return this.recaptcha$.pipe(mergeMap(r =>\n new Observable<string>(observer =>\n r.ready(() => {\n let promise = r.execute(config, { 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 }\n private init(key: string): void {\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=${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';\nexport * from './lib/recaptcha-config-loader';","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;MAGa,uBAAuB,GAAG,IAAI,cAAc,CAAwB,yBAAyB;;MCK7F,gBAAgB,CAAA;AACnB,IAAA,YAAY,GAAG,MAAM,CAAC,uBAAuB,CAAC;IAC9C,WAAW,GAAG,KAAK;AACnB,IAAA,QAAQ,GAAG,MAAM,CAAW,QAAQ,CA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D,+CAAA,EAAA,GAAG,EAAE;AACpE,QAAA,MAAM,CAAC,KAAK,GAAG,IAAI;AACnB,QAAA,MAAM,CAAC,KAAK,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;;uGAzCW,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
CHANGED
|
@@ -3,19 +3,26 @@ import * as i0 from '@angular/core';
|
|
|
3
3
|
import { InjectionToken } from '@angular/core';
|
|
4
4
|
|
|
5
5
|
declare class RecaptchaService {
|
|
6
|
+
private configLoader;
|
|
6
7
|
private initialized;
|
|
7
8
|
private document;
|
|
8
|
-
private key;
|
|
9
|
-
private disabled;
|
|
10
9
|
private recaptcha$;
|
|
11
10
|
execute(action: string): Observable<string>;
|
|
12
|
-
init
|
|
11
|
+
private init;
|
|
13
12
|
constructor();
|
|
14
13
|
static ɵfac: i0.ɵɵFactoryDeclaration<RecaptchaService, never>;
|
|
15
14
|
static ɵprov: i0.ɵɵInjectableDeclaration<RecaptchaService>;
|
|
16
15
|
}
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
interface RecaptchaConfig {
|
|
18
|
+
siteKey: string;
|
|
19
|
+
disabled: boolean;
|
|
20
|
+
}
|
|
21
|
+
interface RecaptchaConfigLoader {
|
|
22
|
+
load(): Observable<RecaptchaConfig>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
declare const RECAPTCHA_CONFIG_LOADER: InjectionToken<RecaptchaConfigLoader>;
|
|
20
26
|
|
|
21
|
-
export {
|
|
27
|
+
export { RECAPTCHA_CONFIG_LOADER, RecaptchaService };
|
|
28
|
+
export type { RecaptchaConfig, RecaptchaConfigLoader };
|