siarashield_workspace 0.0.3 → 0.0.4
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
CHANGED
|
@@ -39,6 +39,8 @@ import { initSiaraShield, checkSiaraShieldCaptcha } from 'siarashield_workspace'
|
|
|
39
39
|
await initSiaraShield({
|
|
40
40
|
publicKey: 'TEST-CYBERSIARA',
|
|
41
41
|
loadJQuery: true,
|
|
42
|
+
// Optional: pass nonce when app uses strict CSP
|
|
43
|
+
// cspNonce: 'YOUR_NONCE_VALUE',
|
|
42
44
|
});
|
|
43
45
|
|
|
44
46
|
const result = checkSiaraShieldCaptcha();
|
|
@@ -60,6 +62,18 @@ if (result.ok) {
|
|
|
60
62
|
- Then it loads:
|
|
61
63
|
- `https://embedcdn.mycybersiara.com/CaptchaFormate/CaptchaResources.js`
|
|
62
64
|
|
|
65
|
+
## CSP (strict policy) support
|
|
66
|
+
|
|
67
|
+
- Package supports strict CSP by attaching a nonce to dynamically injected scripts.
|
|
68
|
+
- You can pass nonce in both APIs:
|
|
69
|
+
- `initSiaraShield({ ..., cspNonce: 'YOUR_NONCE' })`
|
|
70
|
+
- `<siara-shield [publicKey]="..." [cspNonce]="nonceValue"></siara-shield>`
|
|
71
|
+
- If nonce is not passed, package auto-detects from:
|
|
72
|
+
- first `<script nonce="...">`
|
|
73
|
+
- or `<meta name="csp-nonce" content="...">`
|
|
74
|
+
- Keep CSP allowlist for required hosts:
|
|
75
|
+
- `https://embedcdn.mycybersiara.com`
|
|
76
|
+
|
|
63
77
|
## Build and pack
|
|
64
78
|
|
|
65
79
|
From workspace root:
|
|
@@ -13,7 +13,7 @@ class SiaraShieldLoaderService {
|
|
|
13
13
|
constructor(document) {
|
|
14
14
|
this.document = document;
|
|
15
15
|
}
|
|
16
|
-
loadScript(src) {
|
|
16
|
+
loadScript(src, options) {
|
|
17
17
|
const existing = this.document.querySelector(`script[src="${src}"]`);
|
|
18
18
|
if (existing)
|
|
19
19
|
return Promise.resolve();
|
|
@@ -30,6 +30,9 @@ class SiaraShieldLoaderService {
|
|
|
30
30
|
const script = this.document.createElement('script');
|
|
31
31
|
script.src = src;
|
|
32
32
|
script.async = true;
|
|
33
|
+
if (options?.nonce) {
|
|
34
|
+
script.nonce = options.nonce;
|
|
35
|
+
}
|
|
33
36
|
script.onload = () => {
|
|
34
37
|
this.statusBySrc.set(src, 'loaded');
|
|
35
38
|
resolve();
|
|
@@ -60,6 +63,7 @@ class SiaraShieldComponent {
|
|
|
60
63
|
loader;
|
|
61
64
|
publicKey;
|
|
62
65
|
loadJQuery = true;
|
|
66
|
+
cspNonce;
|
|
63
67
|
/**
|
|
64
68
|
* Emits the current `CyberSiaraToken` right after a successful `checkCaptcha()`.
|
|
65
69
|
*/
|
|
@@ -70,7 +74,7 @@ class SiaraShieldComponent {
|
|
|
70
74
|
this.loader = loader;
|
|
71
75
|
}
|
|
72
76
|
async ngAfterViewInit() {
|
|
73
|
-
await this.init({ publicKey: this.publicKey, loadJQuery: this.loadJQuery });
|
|
77
|
+
await this.init({ publicKey: this.publicKey, loadJQuery: this.loadJQuery, cspNonce: this.cspNonce });
|
|
74
78
|
}
|
|
75
79
|
async init(options) {
|
|
76
80
|
if (this.initialized)
|
|
@@ -80,10 +84,13 @@ class SiaraShieldComponent {
|
|
|
80
84
|
if (!options.publicKey) {
|
|
81
85
|
throw new Error('SiaraShieldComponent: publicKey is required.');
|
|
82
86
|
}
|
|
87
|
+
const cspNonce = this.resolveCspNonce(options.cspNonce);
|
|
83
88
|
if ((options.loadJQuery ?? true) && !this.isJQueryAlreadyAvailable()) {
|
|
84
|
-
await this.loader.loadScript(JQUERY_FALLBACK_SRC$1);
|
|
89
|
+
await this.loader.loadScript(JQUERY_FALLBACK_SRC$1, { nonce: cspNonce });
|
|
85
90
|
}
|
|
86
|
-
await this.loader.loadScript('https://embedcdn.mycybersiara.com/CaptchaFormate/CaptchaResources.js'
|
|
91
|
+
await this.loader.loadScript('https://embedcdn.mycybersiara.com/CaptchaFormate/CaptchaResources.js', {
|
|
92
|
+
nonce: cspNonce,
|
|
93
|
+
});
|
|
87
94
|
const g = getSiaraShieldGlobals();
|
|
88
95
|
if (!g.initCaptcha) {
|
|
89
96
|
throw new Error('SiaraShield: initCaptcha() is not available after loading scripts.');
|
|
@@ -102,6 +109,20 @@ class SiaraShieldComponent {
|
|
|
102
109
|
const existingJqueryScript = this.host.nativeElement.ownerDocument.querySelector('script[src*="jquery"]');
|
|
103
110
|
return Boolean(existingJqueryScript);
|
|
104
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* Uses explicit nonce first. If not provided, tries to reuse nonce
|
|
114
|
+
* from the first script tag or from `<meta name="csp-nonce">`.
|
|
115
|
+
*/
|
|
116
|
+
resolveCspNonce(explicitNonce) {
|
|
117
|
+
if (explicitNonce)
|
|
118
|
+
return explicitNonce;
|
|
119
|
+
const doc = this.host.nativeElement.ownerDocument;
|
|
120
|
+
const scriptWithNonce = doc.querySelector('script[nonce]');
|
|
121
|
+
if (scriptWithNonce?.nonce)
|
|
122
|
+
return scriptWithNonce.nonce;
|
|
123
|
+
const nonceMeta = doc.querySelector('meta[name="csp-nonce"]');
|
|
124
|
+
return nonceMeta?.content || undefined;
|
|
125
|
+
}
|
|
105
126
|
/**
|
|
106
127
|
* Calls the global `CheckCaptcha()` from SiaraShield script.
|
|
107
128
|
* Returns true when captcha is valid; emits token if available.
|
|
@@ -118,7 +139,7 @@ class SiaraShieldComponent {
|
|
|
118
139
|
return ok;
|
|
119
140
|
}
|
|
120
141
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.5", ngImport: i0, type: SiaraShieldComponent, deps: [{ token: i0.ElementRef }, { token: SiaraShieldLoaderService }], target: i0.ɵɵFactoryTarget.Component });
|
|
121
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "21.2.5", type: SiaraShieldComponent, isStandalone: true, selector: "siara-shield", inputs: { publicKey: "publicKey", loadJQuery: "loadJQuery" }, outputs: { token: "token" }, ngImport: i0, template: `<div class="SiaraShield"></div>`, isInline: true, encapsulation: i0.ViewEncapsulation.None });
|
|
142
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "21.2.5", type: SiaraShieldComponent, isStandalone: true, selector: "siara-shield", inputs: { publicKey: "publicKey", loadJQuery: "loadJQuery", cspNonce: "cspNonce" }, outputs: { token: "token" }, ngImport: i0, template: `<div class="SiaraShield"></div>`, isInline: true, encapsulation: i0.ViewEncapsulation.None });
|
|
122
143
|
}
|
|
123
144
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.5", ngImport: i0, type: SiaraShieldComponent, decorators: [{
|
|
124
145
|
type: Component,
|
|
@@ -133,6 +154,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.5", ngImpor
|
|
|
133
154
|
args: [{ required: true }]
|
|
134
155
|
}], loadJQuery: [{
|
|
135
156
|
type: Input
|
|
157
|
+
}], cspNonce: [{
|
|
158
|
+
type: Input
|
|
136
159
|
}], token: [{
|
|
137
160
|
type: Output
|
|
138
161
|
}] } });
|
|
@@ -140,7 +163,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.5", ngImpor
|
|
|
140
163
|
const JQUERY_FALLBACK_SRC = 'https://embedcdn.mycybersiara.com/capcha-temple/js/jquery.min.js';
|
|
141
164
|
let pending = null;
|
|
142
165
|
let initialized = false;
|
|
143
|
-
function loadScript(src) {
|
|
166
|
+
function loadScript(src, nonce) {
|
|
144
167
|
const existing = document.querySelector(`script[src="${src}"]`);
|
|
145
168
|
if (existing)
|
|
146
169
|
return Promise.resolve();
|
|
@@ -148,11 +171,22 @@ function loadScript(src) {
|
|
|
148
171
|
const script = document.createElement('script');
|
|
149
172
|
script.src = src;
|
|
150
173
|
script.async = true;
|
|
174
|
+
if (nonce)
|
|
175
|
+
script.nonce = nonce;
|
|
151
176
|
script.onload = () => resolve();
|
|
152
177
|
script.onerror = () => reject(new Error(`Failed to load script: ${src}`));
|
|
153
178
|
document.head.appendChild(script);
|
|
154
179
|
});
|
|
155
180
|
}
|
|
181
|
+
function resolveCspNonce(explicitNonce) {
|
|
182
|
+
if (explicitNonce)
|
|
183
|
+
return explicitNonce;
|
|
184
|
+
const scriptWithNonce = document.querySelector('script[nonce]');
|
|
185
|
+
if (scriptWithNonce?.nonce)
|
|
186
|
+
return scriptWithNonce.nonce;
|
|
187
|
+
const nonceMeta = document.querySelector('meta[name="csp-nonce"]');
|
|
188
|
+
return nonceMeta?.content || undefined;
|
|
189
|
+
}
|
|
156
190
|
function isJQueryAlreadyAvailable() {
|
|
157
191
|
const g = getSiaraShieldGlobals();
|
|
158
192
|
if (typeof g.jQuery === 'function' || typeof g.$ === 'function') {
|
|
@@ -178,10 +212,11 @@ async function initSiaraShield(options) {
|
|
|
178
212
|
throw new Error('initSiaraShield: publicKey is required.');
|
|
179
213
|
}
|
|
180
214
|
pending = (async () => {
|
|
215
|
+
const cspNonce = resolveCspNonce(options.cspNonce);
|
|
181
216
|
if ((options.loadJQuery ?? true) && !isJQueryAlreadyAvailable()) {
|
|
182
|
-
await loadScript(JQUERY_FALLBACK_SRC);
|
|
217
|
+
await loadScript(JQUERY_FALLBACK_SRC, cspNonce);
|
|
183
218
|
}
|
|
184
|
-
await loadScript('https://embedcdn.mycybersiara.com/CaptchaFormate/CaptchaResources.js');
|
|
219
|
+
await loadScript('https://embedcdn.mycybersiara.com/CaptchaFormate/CaptchaResources.js', cspNonce);
|
|
185
220
|
const g = getSiaraShieldGlobals();
|
|
186
221
|
if (!g.initCaptcha) {
|
|
187
222
|
throw new Error('SiaraShield: initCaptcha() is not available after loading scripts.');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"siarashield_workspace.mjs","sources":["../../../projects/siarashield-workspace/src/lib/siara-shield.globals.ts","../../../projects/siarashield-workspace/src/lib/siara-shield-loader.service.ts","../../../projects/siarashield-workspace/src/lib/siara-shield.component.ts","../../../projects/siarashield-workspace/src/lib/siara-shield.ts","../../../projects/siarashield-workspace/src/public-api.ts","../../../projects/siarashield-workspace/src/siarashield_workspace.ts"],"sourcesContent":["export type InitCaptchaFn = (publicKey: string) => void;\nexport type CheckCaptchaFn = () => boolean;\n\nexport interface SiaraShieldGlobals {\n initCaptcha?: InitCaptchaFn;\n CheckCaptcha?: CheckCaptchaFn;\n CyberSiaraToken?: string;\n jQuery?: unknown;\n $?: unknown;\n}\n\nexport function getSiaraShieldGlobals(): SiaraShieldGlobals {\n return (globalThis as unknown as { [k: string]: unknown }) as SiaraShieldGlobals;\n}\n\n","import { DOCUMENT } from '@angular/common';\nimport { Inject, Injectable } from '@angular/core';\n\ntype ScriptStatus = 'idle' | 'loading' | 'loaded' | 'error';\n\n@Injectable({ providedIn: 'root' })\nexport class SiaraShieldLoaderService {\n private statusBySrc = new Map<string, ScriptStatus>();\n private pendingBySrc = new Map<string, Promise<void>>();\n\n constructor(@Inject(DOCUMENT) private readonly document: Document) {}\n\n loadScript(src: string): Promise<void> {\n const existing = this.document.querySelector<HTMLScriptElement>(`script[src=\"${src}\"]`);\n if (existing) return Promise.resolve();\n\n const status = this.statusBySrc.get(src);\n if (status === 'loaded') return Promise.resolve();\n if (status === 'loading') {\n const pending = this.pendingBySrc.get(src);\n if (pending) return pending;\n }\n\n this.statusBySrc.set(src, 'loading');\n\n const pending = new Promise<void>((resolve, reject) => {\n const script = this.document.createElement('script');\n script.src = src;\n script.async = true;\n script.onload = () => {\n this.statusBySrc.set(src, 'loaded');\n resolve();\n };\n script.onerror = () => {\n this.statusBySrc.set(src, 'error');\n reject(new Error(`Failed to load script: ${src}`));\n };\n this.document.head.appendChild(script);\n });\n\n this.pendingBySrc.set(src, pending);\n return pending;\n }\n}\n\n","import { AfterViewInit, Component, ElementRef, EventEmitter, Input, Output, ViewEncapsulation } from '@angular/core';\nimport { SiaraShieldLoaderService } from './siara-shield-loader.service';\nimport { getSiaraShieldGlobals } from './siara-shield.globals';\n\nconst JQUERY_FALLBACK_SRC = 'https://embedcdn.mycybersiara.com/capcha-temple/js/jquery.min.js';\n\nexport interface SiaraShieldInitOptions {\n /** SiaraShield public key. Use \"TEST-CYBERSIARA\" for staging/development. */\n publicKey: string;\n /** Loads jQuery before SiaraShield script. Keep true if your page doesn't already include jQuery. */\n loadJQuery?: boolean;\n}\n\n@Component({\n selector: 'siara-shield',\n standalone: true,\n template: `<div class=\"SiaraShield\"></div>`,\n encapsulation: ViewEncapsulation.None,\n})\nexport class SiaraShieldComponent implements AfterViewInit {\n @Input({ required: true }) publicKey!: string;\n @Input() loadJQuery = true;\n\n /**\n * Emits the current `CyberSiaraToken` right after a successful `checkCaptcha()`.\n */\n @Output() token = new EventEmitter<string>();\n\n private initialized = false;\n\n constructor(\n private readonly host: ElementRef<HTMLElement>,\n private readonly loader: SiaraShieldLoaderService,\n ) {}\n\n async ngAfterViewInit(): Promise<void> {\n await this.init({ publicKey: this.publicKey, loadJQuery: this.loadJQuery });\n }\n\n async init(options: SiaraShieldInitOptions): Promise<void> {\n if (this.initialized) return;\n\n // Ensure the host element is in DOM before scripts run.\n void this.host.nativeElement;\n\n if (!options.publicKey) {\n throw new Error('SiaraShieldComponent: publicKey is required.');\n }\n\n if ((options.loadJQuery ?? true) && !this.isJQueryAlreadyAvailable()) {\n await this.loader.loadScript(JQUERY_FALLBACK_SRC);\n }\n\n await this.loader.loadScript('https://embedcdn.mycybersiara.com/CaptchaFormate/CaptchaResources.js');\n\n const g = getSiaraShieldGlobals();\n if (!g.initCaptcha) {\n throw new Error('SiaraShield: initCaptcha() is not available after loading scripts.');\n }\n\n g.initCaptcha(options.publicKey);\n this.initialized = true;\n }\n\n /**\n * Detect preloaded jQuery from global object or an existing script tag.\n */\n private isJQueryAlreadyAvailable(): boolean {\n const g = getSiaraShieldGlobals();\n if (typeof g.jQuery === 'function' || typeof g.$ === 'function') {\n return true;\n }\n\n const existingJqueryScript = this.host.nativeElement.ownerDocument.querySelector<HTMLScriptElement>(\n 'script[src*=\"jquery\"]',\n );\n return Boolean(existingJqueryScript);\n }\n\n /**\n * Calls the global `CheckCaptcha()` from SiaraShield script.\n * Returns true when captcha is valid; emits token if available.\n */\n checkCaptcha(): boolean {\n const g = getSiaraShieldGlobals();\n if (!g.CheckCaptcha) {\n throw new Error('SiaraShield: CheckCaptcha() is not available. Did init() run?');\n }\n\n const ok = g.CheckCaptcha();\n if (ok && typeof g.CyberSiaraToken === 'string') {\n this.token.emit(g.CyberSiaraToken);\n }\n return ok;\n }\n}\n\n","import { getSiaraShieldGlobals } from './siara-shield.globals';\n\nconst JQUERY_FALLBACK_SRC = 'https://embedcdn.mycybersiara.com/capcha-temple/js/jquery.min.js';\n\nexport interface InitSiaraShieldOptions {\n /** SiaraShield public key. Use \"TEST-CYBERSIARA\" for staging/development. */\n publicKey: string;\n /**\n * Loads jQuery before SiaraShield script.\n * If your site/app already loads jQuery, set this to false (not required to load again).\n */\n loadJQuery?: boolean;\n}\n\nlet pending: Promise<void> | null = null;\nlet initialized = false;\n\nfunction loadScript(src: string): Promise<void> {\n const existing = document.querySelector<HTMLScriptElement>(`script[src=\"${src}\"]`);\n if (existing) return Promise.resolve();\n\n return new Promise<void>((resolve, reject) => {\n const script = document.createElement('script');\n script.src = src;\n script.async = true;\n script.onload = () => resolve();\n script.onerror = () => reject(new Error(`Failed to load script: ${src}`));\n document.head.appendChild(script);\n });\n}\n\nfunction isJQueryAlreadyAvailable(): boolean {\n const g = getSiaraShieldGlobals();\n if (typeof g.jQuery === 'function' || typeof g.$ === 'function') {\n return true;\n }\n\n const existingJqueryScript = document.querySelector<HTMLScriptElement>('script[src*=\"jquery\"]');\n return Boolean(existingJqueryScript);\n}\n\n/**\n * Drop-in initializer for SiaraShield.\n * - Loads required scripts (optionally jQuery)\n * - Calls global `initCaptcha(publicKey)`\n *\n * Requirements in your HTML/template:\n * - You must render: `<div class=\"SiaraShield\"></div>`\n */\nexport async function initSiaraShield(options: InitSiaraShieldOptions): Promise<void> {\n if (initialized) return;\n if (pending) return pending;\n\n if (!options?.publicKey) {\n throw new Error('initSiaraShield: publicKey is required.');\n }\n\n pending = (async () => {\n if ((options.loadJQuery ?? true) && !isJQueryAlreadyAvailable()) {\n await loadScript(JQUERY_FALLBACK_SRC);\n }\n\n await loadScript('https://embedcdn.mycybersiara.com/CaptchaFormate/CaptchaResources.js');\n\n const g = getSiaraShieldGlobals();\n if (!g.initCaptcha) {\n throw new Error('SiaraShield: initCaptcha() is not available after loading scripts.');\n }\n\n g.initCaptcha(options.publicKey);\n initialized = true;\n })();\n\n try {\n await pending;\n } finally {\n // keep `pending` cached for subsequent callers\n }\n}\n\n/**\n * Calls global `CheckCaptcha()` and returns its boolean result.\n * If successful, returns `{ ok: true, token?: string }`.\n */\nexport function checkSiaraShieldCaptcha(): { ok: boolean; token?: string } {\n const g = getSiaraShieldGlobals();\n if (!g.CheckCaptcha) {\n throw new Error('SiaraShield: CheckCaptcha() is not available. Did initSiaraShield() run?');\n }\n\n const ok = g.CheckCaptcha();\n const token = typeof g.CyberSiaraToken === 'string' ? g.CyberSiaraToken : undefined;\n return ok ? { ok: true, token } : { ok: false };\n}\n\n","/*\n * Public API Surface of siarashield-workspace\n */\n\nexport * from './lib/siarashield-workspace';\nexport * from './lib/siara-shield.component';\nexport * from './lib/siara-shield-loader.service';\nexport * from './lib/siara-shield.globals';\nexport * from './lib/siara-shield';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":["JQUERY_FALLBACK_SRC","i1.SiaraShieldLoaderService"],"mappings":";;;;SAWgB,qBAAqB,GAAA;AACnC,IAAA,OAAQ,UAAwE;AAClF;;MCPa,wBAAwB,CAAA;AAIY,IAAA,QAAA;AAHvC,IAAA,WAAW,GAAG,IAAI,GAAG,EAAwB;AAC7C,IAAA,YAAY,GAAG,IAAI,GAAG,EAAyB;AAEvD,IAAA,WAAA,CAA+C,QAAkB,EAAA;QAAlB,IA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AwB,EAAE,EAAE;AAC/D,YAAA,MAAM,UAAU,CAAC,mBAAmB,CAAC;QACvC;AAEA,QAAA,MAAM,UAAU,CAAC,sEAAsE,CAAC;AAExF,QAAA,MAAM,CAAC,GAAG,qBAAqB,EAAE;AACjC,QAAA,IAAI,CAAC,CAAC,CAAC,WAAW,EAAE;AAClB,YAAA,MAAM,IAAI,KAAK,CAAC,oEAAoE,CAAC;QACvF;AAEA,QAAA,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,SAAS,CAAC;QAChC,WAAW,GAAG,IAAI;IACpB,CAAC,GAAG;AAEJ,IAAA,IAAI;AACF,QAAA,MAAM,OAAO;IACf;YAAU;;IAEV;AACF;AAEA;;;AAGG;SACa,uBAAuB,GAAA;AACrC,IAAA,MAAM,CAAC,GAAG,qBAAqB,EAAE;AACjC,IAAA,IAAI,CAAC,CAAC,CAAC,YAAY,EAAE;AACnB,QAAA,MAAM,IAAI,KAAK,CAAC,0EAA0E,CAAC;IAC7F;AAEA,IAAA,MAAM,EAAE,GAAG,CAAC,CAAC,YAAY,EAAE;AAC3B,IAAA,MAAM,KAAK,GAAG,OAAO,CAAC,CAAC,eAAe,KAAK,QAAQ,GAAG,CAAC,CAAC,eAAe,GAAG,SAAS;AACnF,IAAA,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,EAAE,KAAK,EAAE;AACjD;;AC7FA;;AAEG;;ACFH;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"siarashield_workspace.mjs","sources":["../../../projects/siarashield-workspace/src/lib/siara-shield.globals.ts","../../../projects/siarashield-workspace/src/lib/siara-shield-loader.service.ts","../../../projects/siarashield-workspace/src/lib/siara-shield.component.ts","../../../projects/siarashield-workspace/src/lib/siara-shield.ts","../../../projects/siarashield-workspace/src/public-api.ts","../../../projects/siarashield-workspace/src/siarashield_workspace.ts"],"sourcesContent":["export type InitCaptchaFn = (publicKey: string) => void;\nexport type CheckCaptchaFn = () => boolean;\n\nexport interface SiaraShieldGlobals {\n initCaptcha?: InitCaptchaFn;\n CheckCaptcha?: CheckCaptchaFn;\n CyberSiaraToken?: string;\n jQuery?: unknown;\n $?: unknown;\n}\n\nexport function getSiaraShieldGlobals(): SiaraShieldGlobals {\n return (globalThis as unknown as { [k: string]: unknown }) as SiaraShieldGlobals;\n}\n\n","import { DOCUMENT } from '@angular/common';\nimport { Inject, Injectable } from '@angular/core';\n\ntype ScriptStatus = 'idle' | 'loading' | 'loaded' | 'error';\n\nexport interface ScriptLoadOptions {\n nonce?: string;\n}\n\n@Injectable({ providedIn: 'root' })\nexport class SiaraShieldLoaderService {\n private statusBySrc = new Map<string, ScriptStatus>();\n private pendingBySrc = new Map<string, Promise<void>>();\n\n constructor(@Inject(DOCUMENT) private readonly document: Document) {}\n\n loadScript(src: string, options?: ScriptLoadOptions): Promise<void> {\n const existing = this.document.querySelector<HTMLScriptElement>(`script[src=\"${src}\"]`);\n if (existing) return Promise.resolve();\n\n const status = this.statusBySrc.get(src);\n if (status === 'loaded') return Promise.resolve();\n if (status === 'loading') {\n const pending = this.pendingBySrc.get(src);\n if (pending) return pending;\n }\n\n this.statusBySrc.set(src, 'loading');\n\n const pending = new Promise<void>((resolve, reject) => {\n const script = this.document.createElement('script');\n script.src = src;\n script.async = true;\n if (options?.nonce) {\n script.nonce = options.nonce;\n }\n script.onload = () => {\n this.statusBySrc.set(src, 'loaded');\n resolve();\n };\n script.onerror = () => {\n this.statusBySrc.set(src, 'error');\n reject(new Error(`Failed to load script: ${src}`));\n };\n this.document.head.appendChild(script);\n });\n\n this.pendingBySrc.set(src, pending);\n return pending;\n }\n}\n\n","import { AfterViewInit, Component, ElementRef, EventEmitter, Input, Output, ViewEncapsulation } from '@angular/core';\nimport { SiaraShieldLoaderService } from './siara-shield-loader.service';\nimport { getSiaraShieldGlobals } from './siara-shield.globals';\n\nconst JQUERY_FALLBACK_SRC = 'https://embedcdn.mycybersiara.com/capcha-temple/js/jquery.min.js';\n\nexport interface SiaraShieldInitOptions {\n /** SiaraShield public key. Use \"TEST-CYBERSIARA\" for staging/development. */\n publicKey: string;\n /** Loads jQuery before SiaraShield script. Keep true if your page doesn't already include jQuery. */\n loadJQuery?: boolean;\n /** CSP nonce for strict policies (`script-src 'nonce-...'`). */\n cspNonce?: string;\n}\n\n@Component({\n selector: 'siara-shield',\n standalone: true,\n template: `<div class=\"SiaraShield\"></div>`,\n encapsulation: ViewEncapsulation.None,\n})\nexport class SiaraShieldComponent implements AfterViewInit {\n @Input({ required: true }) publicKey!: string;\n @Input() loadJQuery = true;\n @Input() cspNonce?: string;\n\n /**\n * Emits the current `CyberSiaraToken` right after a successful `checkCaptcha()`.\n */\n @Output() token = new EventEmitter<string>();\n\n private initialized = false;\n\n constructor(\n private readonly host: ElementRef<HTMLElement>,\n private readonly loader: SiaraShieldLoaderService,\n ) {}\n\n async ngAfterViewInit(): Promise<void> {\n await this.init({ publicKey: this.publicKey, loadJQuery: this.loadJQuery, cspNonce: this.cspNonce });\n }\n\n async init(options: SiaraShieldInitOptions): Promise<void> {\n if (this.initialized) return;\n\n // Ensure the host element is in DOM before scripts run.\n void this.host.nativeElement;\n\n if (!options.publicKey) {\n throw new Error('SiaraShieldComponent: publicKey is required.');\n }\n const cspNonce = this.resolveCspNonce(options.cspNonce);\n\n if ((options.loadJQuery ?? true) && !this.isJQueryAlreadyAvailable()) {\n await this.loader.loadScript(JQUERY_FALLBACK_SRC, { nonce: cspNonce });\n }\n\n await this.loader.loadScript('https://embedcdn.mycybersiara.com/CaptchaFormate/CaptchaResources.js', {\n nonce: cspNonce,\n });\n\n const g = getSiaraShieldGlobals();\n if (!g.initCaptcha) {\n throw new Error('SiaraShield: initCaptcha() is not available after loading scripts.');\n }\n\n g.initCaptcha(options.publicKey);\n this.initialized = true;\n }\n\n /**\n * Detect preloaded jQuery from global object or an existing script tag.\n */\n private isJQueryAlreadyAvailable(): boolean {\n const g = getSiaraShieldGlobals();\n if (typeof g.jQuery === 'function' || typeof g.$ === 'function') {\n return true;\n }\n\n const existingJqueryScript = this.host.nativeElement.ownerDocument.querySelector<HTMLScriptElement>(\n 'script[src*=\"jquery\"]',\n );\n return Boolean(existingJqueryScript);\n }\n\n /**\n * Uses explicit nonce first. If not provided, tries to reuse nonce\n * from the first script tag or from `<meta name=\"csp-nonce\">`.\n */\n private resolveCspNonce(explicitNonce?: string): string | undefined {\n if (explicitNonce) return explicitNonce;\n const doc = this.host.nativeElement.ownerDocument;\n const scriptWithNonce = doc.querySelector<HTMLScriptElement>('script[nonce]');\n if (scriptWithNonce?.nonce) return scriptWithNonce.nonce;\n\n const nonceMeta = doc.querySelector<HTMLMetaElement>('meta[name=\"csp-nonce\"]');\n return nonceMeta?.content || undefined;\n }\n\n /**\n * Calls the global `CheckCaptcha()` from SiaraShield script.\n * Returns true when captcha is valid; emits token if available.\n */\n checkCaptcha(): boolean {\n const g = getSiaraShieldGlobals();\n if (!g.CheckCaptcha) {\n throw new Error('SiaraShield: CheckCaptcha() is not available. Did init() run?');\n }\n\n const ok = g.CheckCaptcha();\n if (ok && typeof g.CyberSiaraToken === 'string') {\n this.token.emit(g.CyberSiaraToken);\n }\n return ok;\n }\n}\n\n","import { getSiaraShieldGlobals } from './siara-shield.globals';\n\nconst JQUERY_FALLBACK_SRC = 'https://embedcdn.mycybersiara.com/capcha-temple/js/jquery.min.js';\n\nexport interface InitSiaraShieldOptions {\n /** SiaraShield public key. Use \"TEST-CYBERSIARA\" for staging/development. */\n publicKey: string;\n /**\n * Loads jQuery before SiaraShield script.\n * If your site/app already loads jQuery, set this to false (not required to load again).\n */\n loadJQuery?: boolean;\n /** CSP nonce for strict policies (`script-src 'nonce-...'`). */\n cspNonce?: string;\n}\n\nlet pending: Promise<void> | null = null;\nlet initialized = false;\n\nfunction loadScript(src: string, nonce?: string): Promise<void> {\n const existing = document.querySelector<HTMLScriptElement>(`script[src=\"${src}\"]`);\n if (existing) return Promise.resolve();\n\n return new Promise<void>((resolve, reject) => {\n const script = document.createElement('script');\n script.src = src;\n script.async = true;\n if (nonce) script.nonce = nonce;\n script.onload = () => resolve();\n script.onerror = () => reject(new Error(`Failed to load script: ${src}`));\n document.head.appendChild(script);\n });\n}\n\nfunction resolveCspNonce(explicitNonce?: string): string | undefined {\n if (explicitNonce) return explicitNonce;\n const scriptWithNonce = document.querySelector<HTMLScriptElement>('script[nonce]');\n if (scriptWithNonce?.nonce) return scriptWithNonce.nonce;\n\n const nonceMeta = document.querySelector<HTMLMetaElement>('meta[name=\"csp-nonce\"]');\n return nonceMeta?.content || undefined;\n}\n\nfunction isJQueryAlreadyAvailable(): boolean {\n const g = getSiaraShieldGlobals();\n if (typeof g.jQuery === 'function' || typeof g.$ === 'function') {\n return true;\n }\n\n const existingJqueryScript = document.querySelector<HTMLScriptElement>('script[src*=\"jquery\"]');\n return Boolean(existingJqueryScript);\n}\n\n/**\n * Drop-in initializer for SiaraShield.\n * - Loads required scripts (optionally jQuery)\n * - Calls global `initCaptcha(publicKey)`\n *\n * Requirements in your HTML/template:\n * - You must render: `<div class=\"SiaraShield\"></div>`\n */\nexport async function initSiaraShield(options: InitSiaraShieldOptions): Promise<void> {\n if (initialized) return;\n if (pending) return pending;\n\n if (!options?.publicKey) {\n throw new Error('initSiaraShield: publicKey is required.');\n }\n\n pending = (async () => {\n const cspNonce = resolveCspNonce(options.cspNonce);\n if ((options.loadJQuery ?? true) && !isJQueryAlreadyAvailable()) {\n await loadScript(JQUERY_FALLBACK_SRC, cspNonce);\n }\n\n await loadScript('https://embedcdn.mycybersiara.com/CaptchaFormate/CaptchaResources.js', cspNonce);\n\n const g = getSiaraShieldGlobals();\n if (!g.initCaptcha) {\n throw new Error('SiaraShield: initCaptcha() is not available after loading scripts.');\n }\n\n g.initCaptcha(options.publicKey);\n initialized = true;\n })();\n\n try {\n await pending;\n } finally {\n // keep `pending` cached for subsequent callers\n }\n}\n\n/**\n * Calls global `CheckCaptcha()` and returns its boolean result.\n * If successful, returns `{ ok: true, token?: string }`.\n */\nexport function checkSiaraShieldCaptcha(): { ok: boolean; token?: string } {\n const g = getSiaraShieldGlobals();\n if (!g.CheckCaptcha) {\n throw new Error('SiaraShield: CheckCaptcha() is not available. Did initSiaraShield() run?');\n }\n\n const ok = g.CheckCaptcha();\n const token = typeof g.CyberSiaraToken === 'string' ? g.CyberSiaraToken : undefined;\n return ok ? { ok: true, token } : { ok: false };\n}\n\n","/*\n * Public API Surface of siarashield-workspace\n */\n\nexport * from './lib/siarashield-workspace';\nexport * from './lib/siara-shield.component';\nexport * from './lib/siara-shield-loader.service';\nexport * from './lib/siara-shield.globals';\nexport * from './lib/siara-shield';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":["JQUERY_FALLBACK_SRC","i1.SiaraShieldLoaderService"],"mappings":";;;;SAWgB,qBAAqB,GAAA;AACnC,IAAA,OAAQ,UAAwE;AAClF;;MCHa,wBAAwB,CAAA;AAIY,IAAA,QAAA;AAHvC,IAAA,WAAW,GAAG,IAAI,GAAG,EAAwB;AAC7C,IAAA,YAAY,GAAG,IAAI,GAAG,EAAyB;AAEvD,IAAA,WAAA,CAA+C,QAAkB,EAAA;QAAlB,IAAA,CAAA,QAAQ,GAAR,QAAQ;IAAa;IAEpE,UAAU,CAAC,GAAW,EAAE,OAA2B,EAAA;AACjD,QAAA,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAoB,CAAA,YAAA,EAAe,GAAG,CAAA,EAAA,CAAI,CAAC;AACvF,QAAA,IAAI,QAAQ;AAAE,YAAA,OAAO,OAAO,CAAC,OAAO,EAAE;QAEtC,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC;QACxC,IAAI,MAAM,KAAK,QAAQ;AAAE,YAAA,OAAO,OAAO,CAAC,OAAO,EAAE;AACjD,QAAA,IAAI,MAAM,KAAK,SAAS,EAAE;YACxB,MAAM,OAAO,GAAG,IAAI,CAAC,YAAY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M,CAAC,GAAG,qBAAqB,EAAE;AACjC,IAAA,IAAI,CAAC,CAAC,CAAC,YAAY,EAAE;AACnB,QAAA,MAAM,IAAI,KAAK,CAAC,0EAA0E,CAAC;IAC7F;AAEA,IAAA,MAAM,EAAE,GAAG,CAAC,CAAC,YAAY,EAAE;AAC3B,IAAA,MAAM,KAAK,GAAG,OAAO,CAAC,CAAC,eAAe,KAAK,QAAQ,GAAG,CAAC,CAAC,eAAe,GAAG,SAAS;AACnF,IAAA,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,EAAE,KAAK,EAAE;AACjD;;AC1GA;;AAEG;;ACFH;;AAEG;;;;"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
2
|
import { AfterViewInit, EventEmitter, ElementRef } from '@angular/core';
|
|
3
3
|
|
|
4
|
+
interface ScriptLoadOptions {
|
|
5
|
+
nonce?: string;
|
|
6
|
+
}
|
|
4
7
|
declare class SiaraShieldLoaderService {
|
|
5
8
|
private readonly document;
|
|
6
9
|
private statusBySrc;
|
|
7
10
|
private pendingBySrc;
|
|
8
11
|
constructor(document: Document);
|
|
9
|
-
loadScript(src: string): Promise<void>;
|
|
12
|
+
loadScript(src: string, options?: ScriptLoadOptions): Promise<void>;
|
|
10
13
|
static ɵfac: i0.ɵɵFactoryDeclaration<SiaraShieldLoaderService, never>;
|
|
11
14
|
static ɵprov: i0.ɵɵInjectableDeclaration<SiaraShieldLoaderService>;
|
|
12
15
|
}
|
|
@@ -16,12 +19,15 @@ interface SiaraShieldInitOptions {
|
|
|
16
19
|
publicKey: string;
|
|
17
20
|
/** Loads jQuery before SiaraShield script. Keep true if your page doesn't already include jQuery. */
|
|
18
21
|
loadJQuery?: boolean;
|
|
22
|
+
/** CSP nonce for strict policies (`script-src 'nonce-...'`). */
|
|
23
|
+
cspNonce?: string;
|
|
19
24
|
}
|
|
20
25
|
declare class SiaraShieldComponent implements AfterViewInit {
|
|
21
26
|
private readonly host;
|
|
22
27
|
private readonly loader;
|
|
23
28
|
publicKey: string;
|
|
24
29
|
loadJQuery: boolean;
|
|
30
|
+
cspNonce?: string;
|
|
25
31
|
/**
|
|
26
32
|
* Emits the current `CyberSiaraToken` right after a successful `checkCaptcha()`.
|
|
27
33
|
*/
|
|
@@ -34,13 +40,18 @@ declare class SiaraShieldComponent implements AfterViewInit {
|
|
|
34
40
|
* Detect preloaded jQuery from global object or an existing script tag.
|
|
35
41
|
*/
|
|
36
42
|
private isJQueryAlreadyAvailable;
|
|
43
|
+
/**
|
|
44
|
+
* Uses explicit nonce first. If not provided, tries to reuse nonce
|
|
45
|
+
* from the first script tag or from `<meta name="csp-nonce">`.
|
|
46
|
+
*/
|
|
47
|
+
private resolveCspNonce;
|
|
37
48
|
/**
|
|
38
49
|
* Calls the global `CheckCaptcha()` from SiaraShield script.
|
|
39
50
|
* Returns true when captcha is valid; emits token if available.
|
|
40
51
|
*/
|
|
41
52
|
checkCaptcha(): boolean;
|
|
42
53
|
static ɵfac: i0.ɵɵFactoryDeclaration<SiaraShieldComponent, never>;
|
|
43
|
-
static ɵcmp: i0.ɵɵComponentDeclaration<SiaraShieldComponent, "siara-shield", never, { "publicKey": { "alias": "publicKey"; "required": true; }; "loadJQuery": { "alias": "loadJQuery"; "required": false; }; }, { "token": "token"; }, never, never, true, never>;
|
|
54
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<SiaraShieldComponent, "siara-shield", never, { "publicKey": { "alias": "publicKey"; "required": true; }; "loadJQuery": { "alias": "loadJQuery"; "required": false; }; "cspNonce": { "alias": "cspNonce"; "required": false; }; }, { "token": "token"; }, never, never, true, never>;
|
|
44
55
|
}
|
|
45
56
|
|
|
46
57
|
type InitCaptchaFn = (publicKey: string) => void;
|
|
@@ -62,6 +73,8 @@ interface InitSiaraShieldOptions {
|
|
|
62
73
|
* If your site/app already loads jQuery, set this to false (not required to load again).
|
|
63
74
|
*/
|
|
64
75
|
loadJQuery?: boolean;
|
|
76
|
+
/** CSP nonce for strict policies (`script-src 'nonce-...'`). */
|
|
77
|
+
cspNonce?: string;
|
|
65
78
|
}
|
|
66
79
|
/**
|
|
67
80
|
* Drop-in initializer for SiaraShield.
|
|
@@ -82,4 +95,4 @@ declare function checkSiaraShieldCaptcha(): {
|
|
|
82
95
|
};
|
|
83
96
|
|
|
84
97
|
export { SiaraShieldComponent, SiaraShieldLoaderService, checkSiaraShieldCaptcha, getSiaraShieldGlobals, initSiaraShield };
|
|
85
|
-
export type { CheckCaptchaFn, InitCaptchaFn, InitSiaraShieldOptions, SiaraShieldGlobals, SiaraShieldInitOptions };
|
|
98
|
+
export type { CheckCaptchaFn, InitCaptchaFn, InitSiaraShieldOptions, ScriptLoadOptions, SiaraShieldGlobals, SiaraShieldInitOptions };
|