siarashield_workspace 0.0.2 → 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
@@ -1,77 +1,85 @@
1
1
  # `siarashield_workspace`
2
2
 
3
- Angular library wrapper for **CyberSiara SiaraShield** captcha.
4
-
5
- ## When you need this (and when you don't)
6
-
7
- - **Use this** if your Angular app needs to integrate **SiaraShield** captcha.
8
- - **Not required** if your app already uses a different captcha and you don't want SiaraShield.
3
+ Angular wrapper library for CyberSiara SiaraShield captcha.
9
4
 
10
5
  ## Install
11
6
 
12
- Once published:
13
-
14
7
  ```bash
15
8
  npm i siarashield_workspace
16
9
  ```
17
10
 
18
- ## Setup steps (easy integration)
11
+ ## Setup steps
19
12
 
20
- 1. Get your **public & private key** from `mycybersiara.com`
13
+ 1. **Key for staging/development/localhost**
14
+ - Use `TEST-CYBERSIARA` for testing.
15
+ - For localhost, no new key creation is required.
16
+ - For testing note from your requirement: use `TEST-CYBERSIARA` as public and private key value.
21
17
 
22
- Note: Use public key `TEST-CYBERSIARA` for staging/development.
23
-
24
- 2. Put keys in `.env` (example)
18
+ 2. **Store key in your app config**
25
19
 
26
20
  ```env
27
21
  SIARASHIELD_PUBLIC_KEY=TEST-CYBERSIARA
28
- SIARASHIELD_PRIVATE_KEY=YOUR-PRIVATE-KEY
22
+ SIARASHIELD_PRIVATE_KEY=TEST-CYBERSIARA
29
23
  ```
30
24
 
31
- 3. Add the component in your page/component (nothing else required)
25
+ 3. **jQuery loading behavior**
26
+ - If user project already has jQuery, package will not load again.
27
+ - If jQuery is missing, package loads:
28
+ - `https://embedcdn.mycybersiara.com/capcha-temple/js/jquery.min.js`
32
29
 
33
- ```ts
34
- import { Component, ViewChild } from '@angular/core';
35
- import { SiaraShieldComponent } from 'siarashield_workspace';
36
- ```
30
+ 4. **Render captcha container**
31
+ - Add this in your template where captcha should appear:
32
+ - `<div class="SiaraShield"></div>`
37
33
 
38
- 4. When you need to show the captcha, use this code (nothing else)
39
-
40
- Renders `<div class="SiaraShield"></div>`
41
-
42
- 5. Initialize captcha with your public key (example)
34
+ 5. **Initialize and validate**
43
35
 
44
36
  ```ts
45
37
  import { initSiaraShield, checkSiaraShieldCaptcha } from 'siarashield_workspace';
46
38
 
47
- await initSiaraShield({ publicKey: 'TEST-CYBERSIARA', loadJQuery: true });
39
+ await initSiaraShield({
40
+ publicKey: 'TEST-CYBERSIARA',
41
+ loadJQuery: true,
42
+ // Optional: pass nonce when app uses strict CSP
43
+ // cspNonce: 'YOUR_NONCE_VALUE',
44
+ });
48
45
 
49
- // On submit:
50
46
  const result = checkSiaraShieldCaptcha();
51
47
  if (result.ok) {
52
48
  console.log(result.token);
53
- // Please write your submit button click event function here //
49
+ // your submit API logic here
54
50
  }
55
51
  ```
56
52
 
57
- Note: Please put your submit button code inside `if (result.ok)`.
53
+ 6. **Submit only when captcha is valid**
54
+ - Put submit logic inside `if (result.ok)`.
55
+
56
+ ## jQuery behavior in this package
58
57
 
59
- ## What this library loads
58
+ - The package checks if jQuery already exists in the user project (`window.jQuery`, `window.$`, or existing jquery script tag).
59
+ - If jQuery is already available, package will **not** load it again.
60
+ - If jQuery is missing, package will load:
61
+ - `https://embedcdn.mycybersiara.com/capcha-temple/js/jquery.min.js`
62
+ - Then it loads:
63
+ - `https://embedcdn.mycybersiara.com/CaptchaFormate/CaptchaResources.js`
60
64
 
61
- - Loads:
62
- - jQuery: `https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js`
63
- (If you are used other jQuery then not need to import this one; it will work properly.)
64
- - SiaraShield script: `https://embedcdn.mycybersiara.com/CaptchaFormate/CaptchaResources.js`
65
- - Calls `initCaptcha(publicKey)`
65
+ ## CSP (strict policy) support
66
66
 
67
- ## Build & pack (for release)
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`
68
76
 
69
- From the workspace root:
77
+ ## Build and pack
78
+
79
+ From workspace root:
70
80
 
71
81
  ```bash
72
82
  npm run build:lib
73
83
  npm run pack:lib
74
84
  ```
75
85
 
76
- Pack output will be in `dist/siarashield-workspace`.
77
-
@@ -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();
@@ -54,11 +57,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.5", ngImpor
54
57
  args: [DOCUMENT]
55
58
  }] }] });
56
59
 
60
+ const JQUERY_FALLBACK_SRC$1 = 'https://embedcdn.mycybersiara.com/capcha-temple/js/jquery.min.js';
57
61
  class SiaraShieldComponent {
58
62
  host;
59
63
  loader;
60
64
  publicKey;
61
65
  loadJQuery = true;
66
+ cspNonce;
62
67
  /**
63
68
  * Emits the current `CyberSiaraToken` right after a successful `checkCaptcha()`.
64
69
  */
@@ -69,7 +74,7 @@ class SiaraShieldComponent {
69
74
  this.loader = loader;
70
75
  }
71
76
  async ngAfterViewInit() {
72
- await this.init({ publicKey: this.publicKey, loadJQuery: this.loadJQuery });
77
+ await this.init({ publicKey: this.publicKey, loadJQuery: this.loadJQuery, cspNonce: this.cspNonce });
73
78
  }
74
79
  async init(options) {
75
80
  if (this.initialized)
@@ -79,10 +84,13 @@ class SiaraShieldComponent {
79
84
  if (!options.publicKey) {
80
85
  throw new Error('SiaraShieldComponent: publicKey is required.');
81
86
  }
82
- if (options.loadJQuery ?? true) {
83
- await this.loader.loadScript('https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js');
87
+ const cspNonce = this.resolveCspNonce(options.cspNonce);
88
+ if ((options.loadJQuery ?? true) && !this.isJQueryAlreadyAvailable()) {
89
+ await this.loader.loadScript(JQUERY_FALLBACK_SRC$1, { nonce: cspNonce });
84
90
  }
85
- 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
+ });
86
94
  const g = getSiaraShieldGlobals();
87
95
  if (!g.initCaptcha) {
88
96
  throw new Error('SiaraShield: initCaptcha() is not available after loading scripts.');
@@ -90,6 +98,31 @@ class SiaraShieldComponent {
90
98
  g.initCaptcha(options.publicKey);
91
99
  this.initialized = true;
92
100
  }
101
+ /**
102
+ * Detect preloaded jQuery from global object or an existing script tag.
103
+ */
104
+ isJQueryAlreadyAvailable() {
105
+ const g = getSiaraShieldGlobals();
106
+ if (typeof g.jQuery === 'function' || typeof g.$ === 'function') {
107
+ return true;
108
+ }
109
+ const existingJqueryScript = this.host.nativeElement.ownerDocument.querySelector('script[src*="jquery"]');
110
+ return Boolean(existingJqueryScript);
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
+ }
93
126
  /**
94
127
  * Calls the global `CheckCaptcha()` from SiaraShield script.
95
128
  * Returns true when captcha is valid; emits token if available.
@@ -106,7 +139,7 @@ class SiaraShieldComponent {
106
139
  return ok;
107
140
  }
108
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 });
109
- 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 });
110
143
  }
111
144
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.5", ngImport: i0, type: SiaraShieldComponent, decorators: [{
112
145
  type: Component,
@@ -121,13 +154,16 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.5", ngImpor
121
154
  args: [{ required: true }]
122
155
  }], loadJQuery: [{
123
156
  type: Input
157
+ }], cspNonce: [{
158
+ type: Input
124
159
  }], token: [{
125
160
  type: Output
126
161
  }] } });
127
162
 
163
+ const JQUERY_FALLBACK_SRC = 'https://embedcdn.mycybersiara.com/capcha-temple/js/jquery.min.js';
128
164
  let pending = null;
129
165
  let initialized = false;
130
- function loadScript(src) {
166
+ function loadScript(src, nonce) {
131
167
  const existing = document.querySelector(`script[src="${src}"]`);
132
168
  if (existing)
133
169
  return Promise.resolve();
@@ -135,11 +171,30 @@ function loadScript(src) {
135
171
  const script = document.createElement('script');
136
172
  script.src = src;
137
173
  script.async = true;
174
+ if (nonce)
175
+ script.nonce = nonce;
138
176
  script.onload = () => resolve();
139
177
  script.onerror = () => reject(new Error(`Failed to load script: ${src}`));
140
178
  document.head.appendChild(script);
141
179
  });
142
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
+ }
190
+ function isJQueryAlreadyAvailable() {
191
+ const g = getSiaraShieldGlobals();
192
+ if (typeof g.jQuery === 'function' || typeof g.$ === 'function') {
193
+ return true;
194
+ }
195
+ const existingJqueryScript = document.querySelector('script[src*="jquery"]');
196
+ return Boolean(existingJqueryScript);
197
+ }
143
198
  /**
144
199
  * Drop-in initializer for SiaraShield.
145
200
  * - Loads required scripts (optionally jQuery)
@@ -157,10 +212,11 @@ async function initSiaraShield(options) {
157
212
  throw new Error('initSiaraShield: publicKey is required.');
158
213
  }
159
214
  pending = (async () => {
160
- if (options.loadJQuery ?? true) {
161
- await loadScript('https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js');
215
+ const cspNonce = resolveCspNonce(options.cspNonce);
216
+ if ((options.loadJQuery ?? true) && !isJQueryAlreadyAvailable()) {
217
+ await loadScript(JQUERY_FALLBACK_SRC, cspNonce);
162
218
  }
163
- await loadScript('https://embedcdn.mycybersiara.com/CaptchaFormate/CaptchaResources.js');
219
+ await loadScript('https://embedcdn.mycybersiara.com/CaptchaFormate/CaptchaResources.js', cspNonce);
164
220
  const g = getSiaraShieldGlobals();
165
221
  if (!g.initCaptcha) {
166
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}\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\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) {\n await this.loader.loadScript('https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js');\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 * 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\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\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) {\n await loadScript('https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js');\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":["i1.SiaraShieldLoaderService"],"mappings":";;;;SASgB,qBAAqB,GAAA;AACnC,IAAA,OAAQ,UAAwE;AAClF;;MCLa,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;AAEpE,IAAA,UAAU,CAAC,GAAW,EAAA;AACpB,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,I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A,MAAM,UAAU,CAAC,kEAAkE,CAAC;QACtF;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;;ACjFA;;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,CAAC,GAAG,CAAC,GAAG,CAAC;AAC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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,6 +1,6 @@
1
1
  {
2
2
  "name": "siarashield_workspace",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "Angular wrapper for CyberSiara SiaraShield captcha embed.",
5
5
  "keywords": [
6
6
  "cybersiara",
@@ -27,4 +27,4 @@
27
27
  "default": "./fesm2022/siarashield_workspace.mjs"
28
28
  }
29
29
  }
30
- }
30
+ }
@@ -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
  */
@@ -30,13 +36,22 @@ declare class SiaraShieldComponent implements AfterViewInit {
30
36
  constructor(host: ElementRef<HTMLElement>, loader: SiaraShieldLoaderService);
31
37
  ngAfterViewInit(): Promise<void>;
32
38
  init(options: SiaraShieldInitOptions): Promise<void>;
39
+ /**
40
+ * Detect preloaded jQuery from global object or an existing script tag.
41
+ */
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;
33
48
  /**
34
49
  * Calls the global `CheckCaptcha()` from SiaraShield script.
35
50
  * Returns true when captcha is valid; emits token if available.
36
51
  */
37
52
  checkCaptcha(): boolean;
38
53
  static ɵfac: i0.ɵɵFactoryDeclaration<SiaraShieldComponent, never>;
39
- 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>;
40
55
  }
41
56
 
42
57
  type InitCaptchaFn = (publicKey: string) => void;
@@ -45,6 +60,8 @@ interface SiaraShieldGlobals {
45
60
  initCaptcha?: InitCaptchaFn;
46
61
  CheckCaptcha?: CheckCaptchaFn;
47
62
  CyberSiaraToken?: string;
63
+ jQuery?: unknown;
64
+ $?: unknown;
48
65
  }
49
66
  declare function getSiaraShieldGlobals(): SiaraShieldGlobals;
50
67
 
@@ -56,6 +73,8 @@ interface InitSiaraShieldOptions {
56
73
  * If your site/app already loads jQuery, set this to false (not required to load again).
57
74
  */
58
75
  loadJQuery?: boolean;
76
+ /** CSP nonce for strict policies (`script-src 'nonce-...'`). */
77
+ cspNonce?: string;
59
78
  }
60
79
  /**
61
80
  * Drop-in initializer for SiaraShield.
@@ -76,4 +95,4 @@ declare function checkSiaraShieldCaptcha(): {
76
95
  };
77
96
 
78
97
  export { SiaraShieldComponent, SiaraShieldLoaderService, checkSiaraShieldCaptcha, getSiaraShieldGlobals, initSiaraShield };
79
- export type { CheckCaptchaFn, InitCaptchaFn, InitSiaraShieldOptions, SiaraShieldGlobals, SiaraShieldInitOptions };
98
+ export type { CheckCaptchaFn, InitCaptchaFn, InitSiaraShieldOptions, ScriptLoadOptions, SiaraShieldGlobals, SiaraShieldInitOptions };