@truzyx/consent-widget 0.2.2 → 0.2.3

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/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var w=Object.defineProperty;var y=(n,e,t)=>e in n?w(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var a=(n,e,t)=>y(n,typeof e!="symbol"?e+"":e,t);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const c={live:"https://ui.gateway.nodbook.in",sandbox:"https://sandbox-ui.gateway.nodbook.in"},b="CONSENT_WIDGET_EVENT",h="GATEWAY_UI_READY",u="PRINCIPAL_TOKEN";function E(n){return typeof n=="object"&&n!==null&&n.type===b&&typeof n.event=="object"}function _(n){return typeof n=="object"&&n!==null&&n.type===h}const I="__consent_widget_overlay__",x=600,k=640;function C(n,e){var t;if(n)return n.replace(/\/$/,"");if(e&&c[e])return c[e];try{const o=document.getElementsByTagName("script");for(let i=o.length-1;i>=0;i--){const s=((t=o[i])==null?void 0:t.getAttribute("src"))??"";if(s.includes("consent-widget"))return new URL(s,window.location.href).origin}const r=document.currentScript;if(r!=null&&r.src)return new URL(r.src,window.location.href).origin}catch{}return window.location.origin}function v(n){const e=new URLSearchParams({auth_token:n.token,embed:"true",origin:window.location.origin});return n.mode==="preferences"?`${n.baseUrl}/consent_manager/preferences?${e.toString()}`:n.mode==="direct_consent"?(n.purposeId&&e.set("purpose_id",n.purposeId),n.orgId&&e.set("org_id",n.orgId),n.locale&&e.set("locale",n.locale),`${n.baseUrl}/consent_manager/direct_consent?${e.toString()}`):`${n.baseUrl}/consent_manager/consent/${encodeURIComponent(n.requestId??"")}?${e.toString()}`}class A{constructor(){a(this,"overlay",null);a(this,"iframe",null);a(this,"session",null);a(this,"callbacks",new Set);a(this,"listening",!1);a(this,"escHandler",e=>{var t;e.key==="Escape"&&this.close({type:"closed",requestId:(t=this.session)==null?void 0:t.requestId})});a(this,"messageHandler",e=>{var o,r;if(!this.session||!this.iframe)return;let t="";try{t=new URL(this.session.baseUrl).origin}catch{t=""}if(!(t&&e.origin!==t)&&e.source===this.iframe.contentWindow){if(_(e.data)){try{(o=this.iframe.contentWindow)==null||o.postMessage({type:u,token:this.session.token},t||"*")}catch{}return}if(typeof e.data=="object"&&e.data!==null&&e.data.type===h){try{(r=this.iframe.contentWindow)==null||r.postMessage({type:u,token:this.session.token},t||"*")}catch{}return}if(E(e.data)){const i=e.data.event;this.emit(i),this.session.autoClose&&(i.type==="consent_accepted"||i.type==="consent_declined"||i.type==="already_resolved"||i.type==="redirecting")&&this.teardown()}}})}openConsent(e,t,o){this.openDialog({...o,requestId:e,token:t,mode:"consent"})}openPreferences(e,t){this.openDialog({...t,token:e,mode:"preferences"})}openDirectConsent(e,t,o,r,i){const s=e==null?void 0:e.trim();if(!s)throw new Error("ConsentWidget.openDirectConsent: `purposeId` is required.");this.openDialog({...i,purposeId:s,token:t,orgId:o??null,locale:r,mode:"direct_consent"})}openDialog(e){var r;if(!e||typeof e.token!="string"||e.token.length===0)throw new Error("ConsentWidget: `token` is required.");const t=((r=e.purposeId)==null?void 0:r.trim())||void 0,o=e.mode??(t?"direct_consent":e.requestId?"consent":"preferences");if(o==="consent"&&!e.requestId)throw new Error("ConsentWidget: `requestId` is required for the consent dialog.");this.open({requestId:e.requestId,token:e.token,mode:o,purposeId:t,orgId:e.orgId??null,locale:e.locale,baseUrl:C(e.baseUrl,e.env),autoClose:e.autoClose??!0}),this.render(e.allowClose??!0,e.width??x,e.height??k),this.emit({type:"opened",requestId:e.requestId,data:t?{purposeId:t}:void 0})}onCallback(e){return this.callbacks.add(e),()=>{this.callbacks.delete(e)}}close(e){var r;const t=e??{type:"closed",requestId:(r=this.session)==null?void 0:r.requestId},o=this.overlay!==null;this.teardown(),o&&this.emit(t)}destroy(){this.callbacks.clear(),this.teardown()}isOpen(){return this.overlay!==null}open(e){this.teardown(),this.session=e,this.ensureListening()}ensureListening(){this.listening||(window.addEventListener("message",this.messageHandler),window.addEventListener("keydown",this.escHandler),this.listening=!0)}render(e,t,o){if(!this.session)return;const r=v(this.session),i=document.createElement("div");i.id=I,i.setAttribute("role","dialog"),i.setAttribute("aria-modal","true"),i.style.cssText=["position:fixed","inset:0","z-index:2147483647","display:flex","align-items:center","justify-content:center","background:rgba(15,23,42,0.55)","padding:16px","box-sizing:border-box"].join(";");const s=document.createElement("div"),f=Math.min(t,window.innerWidth-32),p=Math.min(o,window.innerHeight-32);if(s.style.cssText=[`width:${f}px`,"max-width:100%",`height:${p}px`,"max-height:100%","background:#fff","border-radius:16px","overflow:hidden","position:relative","box-shadow:0 25px 50px -12px rgba(0,0,0,0.35)","display:flex","flex-direction:column"].join(";"),e){const l=document.createElement("button");l.setAttribute("aria-label","Close"),l.textContent="×",l.style.cssText=["position:absolute","top:8px","right:12px","z-index:2","width:28px","height:28px","border-radius:9999px","border:none","background:rgba(15,23,42,0.06)","color:#475569","font-size:18px","line-height:1","cursor:pointer"].join(";"),l.onclick=()=>this.close(),s.appendChild(l),i.addEventListener("mousedown",m=>{m.target===i&&this.close()})}const d=document.createElement("iframe");d.src=r,d.title="Consent manager",d.setAttribute("allow","clipboard-write"),d.style.cssText=["flex:1","width:100%","height:100%","border:0","background:#fff"].join(";"),s.appendChild(d),i.appendChild(s),document.body.appendChild(i),document.documentElement.style.overflow="hidden",this.overlay=i,this.iframe=d}teardown(){var e;(e=this.overlay)!=null&&e.parentNode&&this.overlay.parentNode.removeChild(this.overlay),this.overlay=null,this.iframe=null,this.session=null,this.listening&&(window.removeEventListener("message",this.messageHandler),window.removeEventListener("keydown",this.escHandler),this.listening=!1);try{document.documentElement.style.overflow=""}catch{}}emit(e){this.callbacks.forEach(t=>{try{t(e)}catch{}})}}const g=new A;exports.ConsentWidget=g;exports.GATEWAY_BASE_URLS=c;exports.default=g;
1
+ "use strict";var w=Object.defineProperty;var y=(n,e,t)=>e in n?w(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var a=(n,e,t)=>y(n,typeof e!="symbol"?e+"":e,t);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const c={live:"https://ui.gateway.nodbook.in",sandbox:"https://sandbox-ui.gateway.nodbook.in"},b="CONSENT_WIDGET_EVENT",h="GATEWAY_UI_READY",u="PRINCIPAL_TOKEN";function E(n){return typeof n=="object"&&n!==null&&n.type===b&&typeof n.event=="object"}function _(n){return typeof n=="object"&&n!==null&&n.type===h}const x="__consent_widget_overlay__",I=600,v=640;function k(n,e){var t;if(n)return n.replace(/\/$/,"");if(e&&c[e])return c[e];try{const o=document.getElementsByTagName("script");for(let i=o.length-1;i>=0;i--){const s=((t=o[i])==null?void 0:t.getAttribute("src"))??"";if(s.includes("consent-widget"))return new URL(s,window.location.href).origin}const r=document.currentScript;if(r!=null&&r.src)return new URL(r.src,window.location.href).origin}catch{}return window.location.origin}function C(n){const e=new URLSearchParams({auth_token:n.token,embed:"true",origin:window.location.origin});return n.mode==="preferences"?`${n.baseUrl}/consent_manager/preferences?${e.toString()}`:n.mode==="direct_consent"?(n.purposeId&&e.set("purpose_id",n.purposeId),n.orgId&&e.set("org_id",n.orgId),n.locale&&e.set("locale",n.locale),`${n.baseUrl}/consent_manager/direct_consent?${e.toString()}`):`${n.baseUrl}/consent_manager/consent/${encodeURIComponent(n.requestId??"")}?${e.toString()}`}class A{constructor(){a(this,"overlay",null);a(this,"iframe",null);a(this,"session",null);a(this,"callbacks",new Set);a(this,"listening",!1);a(this,"escHandler",e=>{var t;e.key==="Escape"&&this.close({type:"closed",requestId:(t=this.session)==null?void 0:t.requestId})});a(this,"messageHandler",e=>{var o,r;if(!this.session||!this.iframe)return;let t="";try{t=new URL(this.session.baseUrl).origin}catch{t=""}if(!(t&&e.origin!==t)&&e.source===this.iframe.contentWindow){if(_(e.data)){try{(o=this.iframe.contentWindow)==null||o.postMessage({type:u,token:this.session.token},t||"*")}catch{}return}if(typeof e.data=="object"&&e.data!==null&&e.data.type===h){try{(r=this.iframe.contentWindow)==null||r.postMessage({type:u,token:this.session.token},t||"*")}catch{}return}if(E(e.data)){const i=e.data.event;this.emit(i),this.session.autoClose&&(i.type==="consent_accepted"||i.type==="consent_declined"||i.type==="already_resolved"||i.type==="redirecting")&&this.teardown()}}})}openConsent(e,t,o){this.openDialog({...o,requestId:e,token:t,mode:"consent"})}openPreferences(e,t){this.openDialog({...t,token:e,mode:"preferences"})}openDirectConsent(e,t,o,r,i){const s=e==null?void 0:e.trim();if(!s)throw new Error("ConsentWidget.openDirectConsent: `purposeId` is required.");this.openDialog({...i,purposeId:s,token:t,orgId:o??null,locale:r,mode:"direct_consent"})}openDialog(e){var r;if(!e||typeof e.token!="string"||e.token.length===0)throw new Error("ConsentWidget: `token` is required.");const t=((r=e.purposeId)==null?void 0:r.trim())||void 0,o=e.mode??(t?"direct_consent":e.requestId?"consent":"preferences");if(o==="consent"&&!e.requestId)throw new Error("ConsentWidget: `requestId` is required for the consent dialog.");this.open({requestId:e.requestId,token:e.token,mode:o,purposeId:t,orgId:e.orgId??null,locale:e.locale,baseUrl:k(e.baseUrl,e.env),autoClose:e.autoClose??!0}),this.render(e.allowClose??!0,e.width??I,e.height??v),this.emit({type:"opened",requestId:e.requestId,data:t?{purposeId:t}:void 0})}onCallback(e){return this.callbacks.add(e),()=>{this.callbacks.delete(e)}}close(e){var r;const t=e??{type:"closed",requestId:(r=this.session)==null?void 0:r.requestId},o=this.overlay!==null;this.teardown(),o&&this.emit(t)}destroy(){this.callbacks.clear(),this.teardown()}isOpen(){return this.overlay!==null}open(e){this.teardown(),this.session=e,this.ensureListening()}ensureListening(){this.listening||(window.addEventListener("message",this.messageHandler),window.addEventListener("keydown",this.escHandler),this.listening=!0)}render(e,t,o){if(!this.session)return;const r=C(this.session),i=document.createElement("div");i.id=x,i.setAttribute("role","dialog"),i.setAttribute("aria-modal","true"),i.style.cssText=["position:fixed","inset:0","z-index:2147483647","display:flex","align-items:center","justify-content:center","background:rgba(15,23,42,0.55)","padding:16px","box-sizing:border-box","pointer-events:auto"].join(";");const s=document.createElement("div"),g=Math.min(t,window.innerWidth-32),p=Math.min(o,window.innerHeight-32);if(s.style.cssText=[`width:${g}px`,"max-width:100%",`height:${p}px`,"max-height:100%","background:#fff","border-radius:16px","overflow:hidden","position:relative","box-shadow:0 25px 50px -12px rgba(0,0,0,0.35)","display:flex","flex-direction:column","pointer-events:auto"].join(";"),e){const l=document.createElement("button");l.setAttribute("aria-label","Close"),l.textContent="×",l.style.cssText=["position:absolute","top:16px","right:16px","z-index:2","width:32px","height:32px","border-radius:9999px","border:1px solid #e2e8f0","background:#ffffff","color:#475569","font-size:18px","line-height:1","cursor:pointer","box-shadow:0 4px 12px rgba(0,0,0,0.25)","pointer-events:auto"].join(";"),l.onclick=()=>this.close(),i.appendChild(l),i.addEventListener("mousedown",m=>{m.target===i&&this.close()})}const d=document.createElement("iframe");d.src=r,d.title="Consent manager",d.setAttribute("allow","clipboard-write"),d.style.cssText=["flex:1","width:100%","height:100%","border:0","background:#fff","position:relative","z-index:1","pointer-events:auto"].join(";"),s.appendChild(d),i.appendChild(s),document.body.appendChild(i),document.documentElement.style.overflow="hidden",this.overlay=i,this.iframe=d}teardown(){var e;(e=this.overlay)!=null&&e.parentNode&&this.overlay.parentNode.removeChild(this.overlay),this.overlay=null,this.iframe=null,this.session=null,this.listening&&(window.removeEventListener("message",this.messageHandler),window.removeEventListener("keydown",this.escHandler),this.listening=!1);try{document.documentElement.style.overflow=""}catch{}}emit(e){this.callbacks.forEach(t=>{try{t(e)}catch{}})}}const f=new A;exports.ConsentWidget=f;exports.GATEWAY_BASE_URLS=c;exports.default=f;
package/dist/index.js CHANGED
@@ -4,15 +4,15 @@ var a = (n, e, t) => w(n, typeof e != "symbol" ? e + "" : e, t);
4
4
  const c = {
5
5
  live: "https://ui.gateway.nodbook.in",
6
6
  sandbox: "https://sandbox-ui.gateway.nodbook.in"
7
- }, y = "CONSENT_WIDGET_EVENT", u = "GATEWAY_UI_READY", h = "PRINCIPAL_TOKEN";
7
+ }, y = "CONSENT_WIDGET_EVENT", h = "GATEWAY_UI_READY", u = "PRINCIPAL_TOKEN";
8
8
  function b(n) {
9
9
  return typeof n == "object" && n !== null && n.type === y && typeof n.event == "object";
10
10
  }
11
11
  function E(n) {
12
- return typeof n == "object" && n !== null && n.type === u;
12
+ return typeof n == "object" && n !== null && n.type === h;
13
13
  }
14
- const _ = "__consent_widget_overlay__", I = 600, x = 640;
15
- function k(n, e) {
14
+ const x = "__consent_widget_overlay__", _ = 600, I = 640;
15
+ function v(n, e) {
16
16
  var t;
17
17
  if (n) return n.replace(/\/$/, "");
18
18
  if (e && c[e]) return c[e];
@@ -29,7 +29,7 @@ function k(n, e) {
29
29
  }
30
30
  return window.location.origin;
31
31
  }
32
- function C(n) {
32
+ function k(n) {
33
33
  const e = new URLSearchParams({
34
34
  auth_token: n.token,
35
35
  embed: "true",
@@ -37,7 +37,7 @@ function C(n) {
37
37
  });
38
38
  return n.mode === "preferences" ? `${n.baseUrl}/consent_manager/preferences?${e.toString()}` : n.mode === "direct_consent" ? (n.purposeId && e.set("purpose_id", n.purposeId), n.orgId && e.set("org_id", n.orgId), n.locale && e.set("locale", n.locale), `${n.baseUrl}/consent_manager/direct_consent?${e.toString()}`) : `${n.baseUrl}/consent_manager/consent/${encodeURIComponent(n.requestId ?? "")}?${e.toString()}`;
39
39
  }
40
- class v {
40
+ class C {
41
41
  constructor() {
42
42
  a(this, "overlay", null);
43
43
  a(this, "iframe", null);
@@ -61,17 +61,17 @@ class v {
61
61
  if (E(e.data)) {
62
62
  try {
63
63
  (o = this.iframe.contentWindow) == null || o.postMessage(
64
- { type: h, token: this.session.token },
64
+ { type: u, token: this.session.token },
65
65
  t || "*"
66
66
  );
67
67
  } catch {
68
68
  }
69
69
  return;
70
70
  }
71
- if (typeof e.data == "object" && e.data !== null && e.data.type === u) {
71
+ if (typeof e.data == "object" && e.data !== null && e.data.type === h) {
72
72
  try {
73
73
  (r = this.iframe.contentWindow) == null || r.postMessage(
74
- { type: h, token: this.session.token },
74
+ { type: u, token: this.session.token },
75
75
  t || "*"
76
76
  );
77
77
  } catch {
@@ -117,12 +117,12 @@ class v {
117
117
  purposeId: t,
118
118
  orgId: e.orgId ?? null,
119
119
  locale: e.locale,
120
- baseUrl: k(e.baseUrl, e.env),
120
+ baseUrl: v(e.baseUrl, e.env),
121
121
  autoClose: e.autoClose ?? !0
122
122
  }), this.render(
123
123
  e.allowClose ?? !0,
124
- e.width ?? I,
125
- e.height ?? x
124
+ e.width ?? _,
125
+ e.height ?? I
126
126
  ), this.emit({
127
127
  type: "opened",
128
128
  requestId: e.requestId,
@@ -164,8 +164,8 @@ class v {
164
164
  }
165
165
  render(e, t, o) {
166
166
  if (!this.session) return;
167
- const r = C(this.session), i = document.createElement("div");
168
- i.id = _, i.setAttribute("role", "dialog"), i.setAttribute("aria-modal", "true"), i.style.cssText = [
167
+ const r = k(this.session), i = document.createElement("div");
168
+ i.id = x, i.setAttribute("role", "dialog"), i.setAttribute("aria-modal", "true"), i.style.cssText = [
169
169
  "position:fixed",
170
170
  "inset:0",
171
171
  "z-index:2147483647",
@@ -174,13 +174,14 @@ class v {
174
174
  "justify-content:center",
175
175
  "background:rgba(15,23,42,0.55)",
176
176
  "padding:16px",
177
- "box-sizing:border-box"
177
+ "box-sizing:border-box",
178
+ "pointer-events:auto"
178
179
  ].join(";");
179
- const s = document.createElement("div"), g = Math.min(t, window.innerWidth - 32), f = Math.min(o, window.innerHeight - 32);
180
+ const s = document.createElement("div"), f = Math.min(t, window.innerWidth - 32), g = Math.min(o, window.innerHeight - 32);
180
181
  if (s.style.cssText = [
181
- `width:${g}px`,
182
+ `width:${f}px`,
182
183
  "max-width:100%",
183
- `height:${f}px`,
184
+ `height:${g}px`,
184
185
  "max-height:100%",
185
186
  "background:#fff",
186
187
  "border-radius:16px",
@@ -188,24 +189,27 @@ class v {
188
189
  "position:relative",
189
190
  "box-shadow:0 25px 50px -12px rgba(0,0,0,0.35)",
190
191
  "display:flex",
191
- "flex-direction:column"
192
+ "flex-direction:column",
193
+ "pointer-events:auto"
192
194
  ].join(";"), e) {
193
195
  const l = document.createElement("button");
194
196
  l.setAttribute("aria-label", "Close"), l.textContent = "×", l.style.cssText = [
195
197
  "position:absolute",
196
- "top:8px",
197
- "right:12px",
198
+ "top:16px",
199
+ "right:16px",
198
200
  "z-index:2",
199
- "width:28px",
200
- "height:28px",
201
+ "width:32px",
202
+ "height:32px",
201
203
  "border-radius:9999px",
202
- "border:none",
203
- "background:rgba(15,23,42,0.06)",
204
+ "border:1px solid #e2e8f0",
205
+ "background:#ffffff",
204
206
  "color:#475569",
205
207
  "font-size:18px",
206
208
  "line-height:1",
207
- "cursor:pointer"
208
- ].join(";"), l.onclick = () => this.close(), s.appendChild(l), i.addEventListener("mousedown", (p) => {
209
+ "cursor:pointer",
210
+ "box-shadow:0 4px 12px rgba(0,0,0,0.25)",
211
+ "pointer-events:auto"
212
+ ].join(";"), l.onclick = () => this.close(), i.appendChild(l), i.addEventListener("mousedown", (p) => {
209
213
  p.target === i && this.close();
210
214
  });
211
215
  }
@@ -215,7 +219,10 @@ class v {
215
219
  "width:100%",
216
220
  "height:100%",
217
221
  "border:0",
218
- "background:#fff"
222
+ "background:#fff",
223
+ "position:relative",
224
+ "z-index:1",
225
+ "pointer-events:auto"
219
226
  ].join(";"), s.appendChild(d), i.appendChild(s), document.body.appendChild(i), document.documentElement.style.overflow = "hidden", this.overlay = i, this.iframe = d;
220
227
  }
221
228
  teardown() {
@@ -235,7 +242,7 @@ class v {
235
242
  });
236
243
  }
237
244
  }
238
- const T = new v();
245
+ const T = new C();
239
246
  export {
240
247
  T as ConsentWidget,
241
248
  c as GATEWAY_BASE_URLS,
package/dist/react.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var C=Object.defineProperty;var k=(n,e,t)=>e in n?C(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var h=(n,e,t)=>k(n,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react"),w={live:"https://ui.gateway.nodbook.in",sandbox:"https://sandbox-ui.gateway.nodbook.in"},_="CONSENT_WIDGET_EVENT",y="GATEWAY_UI_READY",b="PRINCIPAL_TOKEN";function I(n){return typeof n=="object"&&n!==null&&n.type===_&&typeof n.event=="object"}function x(n){return typeof n=="object"&&n!==null&&n.type===y}const v="__consent_widget_overlay__",A=600,T=640;function W(n,e){var t;if(n)return n.replace(/\/$/,"");if(e&&w[e])return w[e];try{const s=document.getElementsByTagName("script");for(let r=s.length-1;r>=0;r--){const c=((t=s[r])==null?void 0:t.getAttribute("src"))??"";if(c.includes("consent-widget"))return new URL(c,window.location.href).origin}const o=document.currentScript;if(o!=null&&o.src)return new URL(o.src,window.location.href).origin}catch{}return window.location.origin}function U(n){const e=new URLSearchParams({auth_token:n.token,embed:"true",origin:window.location.origin});return n.mode==="preferences"?`${n.baseUrl}/consent_manager/preferences?${e.toString()}`:n.mode==="direct_consent"?(n.purposeId&&e.set("purpose_id",n.purposeId),n.orgId&&e.set("org_id",n.orgId),n.locale&&e.set("locale",n.locale),`${n.baseUrl}/consent_manager/direct_consent?${e.toString()}`):`${n.baseUrl}/consent_manager/consent/${encodeURIComponent(n.requestId??"")}?${e.toString()}`}class q{constructor(){h(this,"overlay",null);h(this,"iframe",null);h(this,"session",null);h(this,"callbacks",new Set);h(this,"listening",!1);h(this,"escHandler",e=>{var t;e.key==="Escape"&&this.close({type:"closed",requestId:(t=this.session)==null?void 0:t.requestId})});h(this,"messageHandler",e=>{var s,o;if(!this.session||!this.iframe)return;let t="";try{t=new URL(this.session.baseUrl).origin}catch{t=""}if(!(t&&e.origin!==t)&&e.source===this.iframe.contentWindow){if(x(e.data)){try{(s=this.iframe.contentWindow)==null||s.postMessage({type:b,token:this.session.token},t||"*")}catch{}return}if(typeof e.data=="object"&&e.data!==null&&e.data.type===y){try{(o=this.iframe.contentWindow)==null||o.postMessage({type:b,token:this.session.token},t||"*")}catch{}return}if(I(e.data)){const r=e.data.event;this.emit(r),this.session.autoClose&&(r.type==="consent_accepted"||r.type==="consent_declined"||r.type==="already_resolved"||r.type==="redirecting")&&this.teardown()}}})}openConsent(e,t,s){this.openDialog({...s,requestId:e,token:t,mode:"consent"})}openPreferences(e,t){this.openDialog({...t,token:e,mode:"preferences"})}openDirectConsent(e,t,s,o,r){const c=e==null?void 0:e.trim();if(!c)throw new Error("ConsentWidget.openDirectConsent: `purposeId` is required.");this.openDialog({...r,purposeId:c,token:t,orgId:s??null,locale:o,mode:"direct_consent"})}openDialog(e){var o;if(!e||typeof e.token!="string"||e.token.length===0)throw new Error("ConsentWidget: `token` is required.");const t=((o=e.purposeId)==null?void 0:o.trim())||void 0,s=e.mode??(t?"direct_consent":e.requestId?"consent":"preferences");if(s==="consent"&&!e.requestId)throw new Error("ConsentWidget: `requestId` is required for the consent dialog.");this.open({requestId:e.requestId,token:e.token,mode:s,purposeId:t,orgId:e.orgId??null,locale:e.locale,baseUrl:W(e.baseUrl,e.env),autoClose:e.autoClose??!0}),this.render(e.allowClose??!0,e.width??A,e.height??T),this.emit({type:"opened",requestId:e.requestId,data:t?{purposeId:t}:void 0})}onCallback(e){return this.callbacks.add(e),()=>{this.callbacks.delete(e)}}close(e){var o;const t=e??{type:"closed",requestId:(o=this.session)==null?void 0:o.requestId},s=this.overlay!==null;this.teardown(),s&&this.emit(t)}destroy(){this.callbacks.clear(),this.teardown()}isOpen(){return this.overlay!==null}open(e){this.teardown(),this.session=e,this.ensureListening()}ensureListening(){this.listening||(window.addEventListener("message",this.messageHandler),window.addEventListener("keydown",this.escHandler),this.listening=!0)}render(e,t,s){if(!this.session)return;const o=U(this.session),r=document.createElement("div");r.id=v,r.setAttribute("role","dialog"),r.setAttribute("aria-modal","true"),r.style.cssText=["position:fixed","inset:0","z-index:2147483647","display:flex","align-items:center","justify-content:center","background:rgba(15,23,42,0.55)","padding:16px","box-sizing:border-box"].join(";");const c=document.createElement("div"),p=Math.min(t,window.innerWidth-32),m=Math.min(s,window.innerHeight-32);if(c.style.cssText=[`width:${p}px`,"max-width:100%",`height:${m}px`,"max-height:100%","background:#fff","border-radius:16px","overflow:hidden","position:relative","box-shadow:0 25px 50px -12px rgba(0,0,0,0.35)","display:flex","flex-direction:column"].join(";"),e){const i=document.createElement("button");i.setAttribute("aria-label","Close"),i.textContent="×",i.style.cssText=["position:absolute","top:8px","right:12px","z-index:2","width:28px","height:28px","border-radius:9999px","border:none","background:rgba(15,23,42,0.06)","color:#475569","font-size:18px","line-height:1","cursor:pointer"].join(";"),i.onclick=()=>this.close(),c.appendChild(i),r.addEventListener("mousedown",l=>{l.target===r&&this.close()})}const u=document.createElement("iframe");u.src=o,u.title="Consent manager",u.setAttribute("allow","clipboard-write"),u.style.cssText=["flex:1","width:100%","height:100%","border:0","background:#fff"].join(";"),c.appendChild(u),r.appendChild(c),document.body.appendChild(r),document.documentElement.style.overflow="hidden",this.overlay=r,this.iframe=u}teardown(){var e;(e=this.overlay)!=null&&e.parentNode&&this.overlay.parentNode.removeChild(this.overlay),this.overlay=null,this.iframe=null,this.session=null,this.listening&&(window.removeEventListener("message",this.messageHandler),window.removeEventListener("keydown",this.escHandler),this.listening=!1);try{document.documentElement.style.overflow=""}catch{}}emit(e){this.callbacks.forEach(t=>{try{t(e)}catch{}})}}const a=new q;function L(n){const{onEvent:e,closeOnUnmount:t=!0}=n??{};d.useEffect(()=>{if(e)return a.onCallback(e)},[e]),d.useEffect(()=>{if(t)return()=>{a.isOpen()&&a.close()}},[t]);const s=d.useCallback((i,l)=>{const{requestId:f,...g}=l??{};f?a.openConsent(f,i,g):a.openPreferences(i,g)},[]),o=d.useCallback((i,l,f)=>{a.openConsent(i,l,f)},[]),r=d.useCallback((i,l)=>{a.openPreferences(i,l)},[]),c=d.useCallback((i,l,f,g,E)=>{a.openDirectConsent(i,l,f,g,E)},[]),p=d.useCallback(i=>{a.close(i)},[]),m=d.useCallback(i=>a.onCallback(i),[]),u=d.useCallback(()=>a.isOpen(),[]);return{open:s,openConsent:o,openPreferences:r,openDirectConsent:c,close:p,onEvent:m,isOpen:u}}exports.useConsentWidget=L;
1
+ "use strict";var C=Object.defineProperty;var x=(n,e,t)=>e in n?C(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var h=(n,e,t)=>x(n,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react"),w={live:"https://ui.gateway.nodbook.in",sandbox:"https://sandbox-ui.gateway.nodbook.in"},k="CONSENT_WIDGET_EVENT",y="GATEWAY_UI_READY",b="PRINCIPAL_TOKEN";function _(n){return typeof n=="object"&&n!==null&&n.type===k&&typeof n.event=="object"}function I(n){return typeof n=="object"&&n!==null&&n.type===y}const v="__consent_widget_overlay__",A=600,T=640;function W(n,e){var t;if(n)return n.replace(/\/$/,"");if(e&&w[e])return w[e];try{const s=document.getElementsByTagName("script");for(let o=s.length-1;o>=0;o--){const a=((t=s[o])==null?void 0:t.getAttribute("src"))??"";if(a.includes("consent-widget"))return new URL(a,window.location.href).origin}const r=document.currentScript;if(r!=null&&r.src)return new URL(r.src,window.location.href).origin}catch{}return window.location.origin}function U(n){const e=new URLSearchParams({auth_token:n.token,embed:"true",origin:window.location.origin});return n.mode==="preferences"?`${n.baseUrl}/consent_manager/preferences?${e.toString()}`:n.mode==="direct_consent"?(n.purposeId&&e.set("purpose_id",n.purposeId),n.orgId&&e.set("org_id",n.orgId),n.locale&&e.set("locale",n.locale),`${n.baseUrl}/consent_manager/direct_consent?${e.toString()}`):`${n.baseUrl}/consent_manager/consent/${encodeURIComponent(n.requestId??"")}?${e.toString()}`}class q{constructor(){h(this,"overlay",null);h(this,"iframe",null);h(this,"session",null);h(this,"callbacks",new Set);h(this,"listening",!1);h(this,"escHandler",e=>{var t;e.key==="Escape"&&this.close({type:"closed",requestId:(t=this.session)==null?void 0:t.requestId})});h(this,"messageHandler",e=>{var s,r;if(!this.session||!this.iframe)return;let t="";try{t=new URL(this.session.baseUrl).origin}catch{t=""}if(!(t&&e.origin!==t)&&e.source===this.iframe.contentWindow){if(I(e.data)){try{(s=this.iframe.contentWindow)==null||s.postMessage({type:b,token:this.session.token},t||"*")}catch{}return}if(typeof e.data=="object"&&e.data!==null&&e.data.type===y){try{(r=this.iframe.contentWindow)==null||r.postMessage({type:b,token:this.session.token},t||"*")}catch{}return}if(_(e.data)){const o=e.data.event;this.emit(o),this.session.autoClose&&(o.type==="consent_accepted"||o.type==="consent_declined"||o.type==="already_resolved"||o.type==="redirecting")&&this.teardown()}}})}openConsent(e,t,s){this.openDialog({...s,requestId:e,token:t,mode:"consent"})}openPreferences(e,t){this.openDialog({...t,token:e,mode:"preferences"})}openDirectConsent(e,t,s,r,o){const a=e==null?void 0:e.trim();if(!a)throw new Error("ConsentWidget.openDirectConsent: `purposeId` is required.");this.openDialog({...o,purposeId:a,token:t,orgId:s??null,locale:r,mode:"direct_consent"})}openDialog(e){var r;if(!e||typeof e.token!="string"||e.token.length===0)throw new Error("ConsentWidget: `token` is required.");const t=((r=e.purposeId)==null?void 0:r.trim())||void 0,s=e.mode??(t?"direct_consent":e.requestId?"consent":"preferences");if(s==="consent"&&!e.requestId)throw new Error("ConsentWidget: `requestId` is required for the consent dialog.");this.open({requestId:e.requestId,token:e.token,mode:s,purposeId:t,orgId:e.orgId??null,locale:e.locale,baseUrl:W(e.baseUrl,e.env),autoClose:e.autoClose??!0}),this.render(e.allowClose??!0,e.width??A,e.height??T),this.emit({type:"opened",requestId:e.requestId,data:t?{purposeId:t}:void 0})}onCallback(e){return this.callbacks.add(e),()=>{this.callbacks.delete(e)}}close(e){var r;const t=e??{type:"closed",requestId:(r=this.session)==null?void 0:r.requestId},s=this.overlay!==null;this.teardown(),s&&this.emit(t)}destroy(){this.callbacks.clear(),this.teardown()}isOpen(){return this.overlay!==null}open(e){this.teardown(),this.session=e,this.ensureListening()}ensureListening(){this.listening||(window.addEventListener("message",this.messageHandler),window.addEventListener("keydown",this.escHandler),this.listening=!0)}render(e,t,s){if(!this.session)return;const r=U(this.session),o=document.createElement("div");o.id=v,o.setAttribute("role","dialog"),o.setAttribute("aria-modal","true"),o.style.cssText=["position:fixed","inset:0","z-index:2147483647","display:flex","align-items:center","justify-content:center","background:rgba(15,23,42,0.55)","padding:16px","box-sizing:border-box","pointer-events:auto"].join(";");const a=document.createElement("div"),g=Math.min(t,window.innerWidth-32),m=Math.min(s,window.innerHeight-32);if(a.style.cssText=[`width:${g}px`,"max-width:100%",`height:${m}px`,"max-height:100%","background:#fff","border-radius:16px","overflow:hidden","position:relative","box-shadow:0 25px 50px -12px rgba(0,0,0,0.35)","display:flex","flex-direction:column","pointer-events:auto"].join(";"),e){const i=document.createElement("button");i.setAttribute("aria-label","Close"),i.textContent="×",i.style.cssText=["position:absolute","top:16px","right:16px","z-index:2","width:32px","height:32px","border-radius:9999px","border:1px solid #e2e8f0","background:#ffffff","color:#475569","font-size:18px","line-height:1","cursor:pointer","box-shadow:0 4px 12px rgba(0,0,0,0.25)","pointer-events:auto"].join(";"),i.onclick=()=>this.close(),o.appendChild(i),o.addEventListener("mousedown",l=>{l.target===o&&this.close()})}const u=document.createElement("iframe");u.src=r,u.title="Consent manager",u.setAttribute("allow","clipboard-write"),u.style.cssText=["flex:1","width:100%","height:100%","border:0","background:#fff","position:relative","z-index:1","pointer-events:auto"].join(";"),a.appendChild(u),o.appendChild(a),document.body.appendChild(o),document.documentElement.style.overflow="hidden",this.overlay=o,this.iframe=u}teardown(){var e;(e=this.overlay)!=null&&e.parentNode&&this.overlay.parentNode.removeChild(this.overlay),this.overlay=null,this.iframe=null,this.session=null,this.listening&&(window.removeEventListener("message",this.messageHandler),window.removeEventListener("keydown",this.escHandler),this.listening=!1);try{document.documentElement.style.overflow=""}catch{}}emit(e){this.callbacks.forEach(t=>{try{t(e)}catch{}})}}const c=new q;function L(n){const{onEvent:e,closeOnUnmount:t=!0}=n??{};d.useEffect(()=>{if(e)return c.onCallback(e)},[e]),d.useEffect(()=>{if(t)return()=>{c.isOpen()&&c.close()}},[t]);const s=d.useCallback((i,l)=>{const{requestId:f,...p}=l??{};f?c.openConsent(f,i,p):c.openPreferences(i,p)},[]),r=d.useCallback((i,l,f)=>{c.openConsent(i,l,f)},[]),o=d.useCallback((i,l)=>{c.openPreferences(i,l)},[]),a=d.useCallback((i,l,f,p,E)=>{c.openDirectConsent(i,l,f,p,E)},[]),g=d.useCallback(i=>{c.close(i)},[]),m=d.useCallback(i=>c.onCallback(i),[]),u=d.useCallback(()=>c.isOpen(),[]);return{open:s,openConsent:r,openPreferences:o,openDirectConsent:a,close:g,onEvent:m,isOpen:u}}exports.useConsentWidget=L;
package/dist/react.js CHANGED
@@ -1,15 +1,15 @@
1
- var C = Object.defineProperty;
2
- var I = (n, e, t) => e in n ? C(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
- var u = (n, e, t) => I(n, typeof e != "symbol" ? e + "" : e, t);
1
+ var _ = Object.defineProperty;
2
+ var C = (n, e, t) => e in n ? _(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
+ var u = (n, e, t) => C(n, typeof e != "symbol" ? e + "" : e, t);
4
4
  import { useEffect as w, useCallback as h } from "react";
5
5
  const y = {
6
6
  live: "https://ui.gateway.nodbook.in",
7
7
  sandbox: "https://sandbox-ui.gateway.nodbook.in"
8
- }, x = "CONSENT_WIDGET_EVENT", E = "GATEWAY_UI_READY", b = "PRINCIPAL_TOKEN";
9
- function k(n) {
10
- return typeof n == "object" && n !== null && n.type === x && typeof n.event == "object";
11
- }
8
+ }, I = "CONSENT_WIDGET_EVENT", E = "GATEWAY_UI_READY", b = "PRINCIPAL_TOKEN";
12
9
  function v(n) {
10
+ return typeof n == "object" && n !== null && n.type === I && typeof n.event == "object";
11
+ }
12
+ function k(n) {
13
13
  return typeof n == "object" && n !== null && n.type === E;
14
14
  }
15
15
  const A = "__consent_widget_overlay__", T = 600, U = 640;
@@ -19,13 +19,13 @@ function W(n, e) {
19
19
  if (e && y[e]) return y[e];
20
20
  try {
21
21
  const i = document.getElementsByTagName("script");
22
- for (let r = i.length - 1; r >= 0; r--) {
23
- const c = ((t = i[r]) == null ? void 0 : t.getAttribute("src")) ?? "";
24
- if (c.includes("consent-widget"))
25
- return new URL(c, window.location.href).origin;
22
+ for (let o = i.length - 1; o >= 0; o--) {
23
+ const a = ((t = i[o]) == null ? void 0 : t.getAttribute("src")) ?? "";
24
+ if (a.includes("consent-widget"))
25
+ return new URL(a, window.location.href).origin;
26
26
  }
27
- const o = document.currentScript;
28
- if (o != null && o.src) return new URL(o.src, window.location.href).origin;
27
+ const r = document.currentScript;
28
+ if (r != null && r.src) return new URL(r.src, window.location.href).origin;
29
29
  } catch {
30
30
  }
31
31
  return window.location.origin;
@@ -50,7 +50,7 @@ class q {
50
50
  e.key === "Escape" && this.close({ type: "closed", requestId: (t = this.session) == null ? void 0 : t.requestId });
51
51
  });
52
52
  u(this, "messageHandler", (e) => {
53
- var i, o;
53
+ var i, r;
54
54
  if (!this.session || !this.iframe) return;
55
55
  let t = "";
56
56
  try {
@@ -59,7 +59,7 @@ class q {
59
59
  t = "";
60
60
  }
61
61
  if (!(t && e.origin !== t) && e.source === this.iframe.contentWindow) {
62
- if (v(e.data)) {
62
+ if (k(e.data)) {
63
63
  try {
64
64
  (i = this.iframe.contentWindow) == null || i.postMessage(
65
65
  { type: b, token: this.session.token },
@@ -71,7 +71,7 @@ class q {
71
71
  }
72
72
  if (typeof e.data == "object" && e.data !== null && e.data.type === E) {
73
73
  try {
74
- (o = this.iframe.contentWindow) == null || o.postMessage(
74
+ (r = this.iframe.contentWindow) == null || r.postMessage(
75
75
  { type: b, token: this.session.token },
76
76
  t || "*"
77
77
  );
@@ -79,9 +79,9 @@ class q {
79
79
  }
80
80
  return;
81
81
  }
82
- if (k(e.data)) {
83
- const r = e.data.event;
84
- this.emit(r), this.session.autoClose && (r.type === "consent_accepted" || r.type === "consent_declined" || r.type === "already_resolved" || r.type === "redirecting") && this.teardown();
82
+ if (v(e.data)) {
83
+ const o = e.data.event;
84
+ this.emit(o), this.session.autoClose && (o.type === "consent_accepted" || o.type === "consent_declined" || o.type === "already_resolved" || o.type === "redirecting") && this.teardown();
85
85
  }
86
86
  }
87
87
  });
@@ -95,20 +95,20 @@ class q {
95
95
  this.openDialog({ ...t, token: e, mode: "preferences" });
96
96
  }
97
97
  /** Open the direct-consent (permission-style) dialog for a purpose. */
98
- openDirectConsent(e, t, i, o, r) {
99
- const c = e == null ? void 0 : e.trim();
100
- if (!c)
98
+ openDirectConsent(e, t, i, r, o) {
99
+ const a = e == null ? void 0 : e.trim();
100
+ if (!a)
101
101
  throw new Error("ConsentWidget.openDirectConsent: `purposeId` is required.");
102
- this.openDialog({ ...r, purposeId: c, token: t, orgId: i ?? null, locale: o, mode: "direct_consent" });
102
+ this.openDialog({ ...o, purposeId: a, token: t, orgId: i ?? null, locale: r, mode: "direct_consent" });
103
103
  }
104
104
  /**
105
105
  * Shared opener behind `openConsent` / `openPreferences` / `openDirectConsent`.
106
106
  */
107
107
  openDialog(e) {
108
- var o;
108
+ var r;
109
109
  if (!e || typeof e.token != "string" || e.token.length === 0)
110
110
  throw new Error("ConsentWidget: `token` is required.");
111
- const t = ((o = e.purposeId) == null ? void 0 : o.trim()) || void 0, i = e.mode ?? (t ? "direct_consent" : e.requestId ? "consent" : "preferences");
111
+ const t = ((r = e.purposeId) == null ? void 0 : r.trim()) || void 0, i = e.mode ?? (t ? "direct_consent" : e.requestId ? "consent" : "preferences");
112
112
  if (i === "consent" && !e.requestId)
113
113
  throw new Error("ConsentWidget: `requestId` is required for the consent dialog.");
114
114
  this.open({
@@ -142,10 +142,10 @@ class q {
142
142
  }
143
143
  /** Programmatically close the dialog (emits a `closed` event). */
144
144
  close(e) {
145
- var o;
145
+ var r;
146
146
  const t = e ?? {
147
147
  type: "closed",
148
- requestId: (o = this.session) == null ? void 0 : o.requestId
148
+ requestId: (r = this.session) == null ? void 0 : r.requestId
149
149
  }, i = this.overlay !== null;
150
150
  this.teardown(), i && this.emit(t);
151
151
  }
@@ -165,8 +165,8 @@ class q {
165
165
  }
166
166
  render(e, t, i) {
167
167
  if (!this.session) return;
168
- const o = L(this.session), r = document.createElement("div");
169
- r.id = A, r.setAttribute("role", "dialog"), r.setAttribute("aria-modal", "true"), r.style.cssText = [
168
+ const r = L(this.session), o = document.createElement("div");
169
+ o.id = A, o.setAttribute("role", "dialog"), o.setAttribute("aria-modal", "true"), o.style.cssText = [
170
170
  "position:fixed",
171
171
  "inset:0",
172
172
  "z-index:2147483647",
@@ -175,11 +175,12 @@ class q {
175
175
  "justify-content:center",
176
176
  "background:rgba(15,23,42,0.55)",
177
177
  "padding:16px",
178
- "box-sizing:border-box"
178
+ "box-sizing:border-box",
179
+ "pointer-events:auto"
179
180
  ].join(";");
180
- const c = document.createElement("div"), p = Math.min(t, window.innerWidth - 32), m = Math.min(i, window.innerHeight - 32);
181
- if (c.style.cssText = [
182
- `width:${p}px`,
181
+ const a = document.createElement("div"), g = Math.min(t, window.innerWidth - 32), m = Math.min(i, window.innerHeight - 32);
182
+ if (a.style.cssText = [
183
+ `width:${g}px`,
183
184
  "max-width:100%",
184
185
  `height:${m}px`,
185
186
  "max-height:100%",
@@ -189,35 +190,41 @@ class q {
189
190
  "position:relative",
190
191
  "box-shadow:0 25px 50px -12px rgba(0,0,0,0.35)",
191
192
  "display:flex",
192
- "flex-direction:column"
193
+ "flex-direction:column",
194
+ "pointer-events:auto"
193
195
  ].join(";"), e) {
194
196
  const s = document.createElement("button");
195
197
  s.setAttribute("aria-label", "Close"), s.textContent = "×", s.style.cssText = [
196
198
  "position:absolute",
197
- "top:8px",
198
- "right:12px",
199
+ "top:16px",
200
+ "right:16px",
199
201
  "z-index:2",
200
- "width:28px",
201
- "height:28px",
202
+ "width:32px",
203
+ "height:32px",
202
204
  "border-radius:9999px",
203
- "border:none",
204
- "background:rgba(15,23,42,0.06)",
205
+ "border:1px solid #e2e8f0",
206
+ "background:#ffffff",
205
207
  "color:#475569",
206
208
  "font-size:18px",
207
209
  "line-height:1",
208
- "cursor:pointer"
209
- ].join(";"), s.onclick = () => this.close(), c.appendChild(s), r.addEventListener("mousedown", (l) => {
210
- l.target === r && this.close();
210
+ "cursor:pointer",
211
+ "box-shadow:0 4px 12px rgba(0,0,0,0.25)",
212
+ "pointer-events:auto"
213
+ ].join(";"), s.onclick = () => this.close(), o.appendChild(s), o.addEventListener("mousedown", (l) => {
214
+ l.target === o && this.close();
211
215
  });
212
216
  }
213
217
  const d = document.createElement("iframe");
214
- d.src = o, d.title = "Consent manager", d.setAttribute("allow", "clipboard-write"), d.style.cssText = [
218
+ d.src = r, d.title = "Consent manager", d.setAttribute("allow", "clipboard-write"), d.style.cssText = [
215
219
  "flex:1",
216
220
  "width:100%",
217
221
  "height:100%",
218
222
  "border:0",
219
- "background:#fff"
220
- ].join(";"), c.appendChild(d), r.appendChild(c), document.body.appendChild(r), document.documentElement.style.overflow = "hidden", this.overlay = r, this.iframe = d;
223
+ "background:#fff",
224
+ "position:relative",
225
+ "z-index:1",
226
+ "pointer-events:auto"
227
+ ].join(";"), a.appendChild(d), o.appendChild(a), document.body.appendChild(o), document.documentElement.style.overflow = "hidden", this.overlay = o, this.iframe = d;
221
228
  }
222
229
  teardown() {
223
230
  var e;
@@ -236,31 +243,31 @@ class q {
236
243
  });
237
244
  }
238
245
  }
239
- const a = new q();
246
+ const c = new q();
240
247
  function R(n) {
241
248
  const { onEvent: e, closeOnUnmount: t = !0 } = n ?? {};
242
249
  w(() => {
243
250
  if (e)
244
- return a.onCallback(e);
251
+ return c.onCallback(e);
245
252
  }, [e]), w(() => {
246
253
  if (t)
247
254
  return () => {
248
- a.isOpen() && a.close();
255
+ c.isOpen() && c.close();
249
256
  };
250
257
  }, [t]);
251
258
  const i = h((s, l) => {
252
- const { requestId: f, ...g } = l ?? {};
253
- f ? a.openConsent(f, s, g) : a.openPreferences(s, g);
254
- }, []), o = h((s, l, f) => {
255
- a.openConsent(s, l, f);
256
- }, []), r = h((s, l) => {
257
- a.openPreferences(s, l);
258
- }, []), c = h((s, l, f, g, _) => {
259
- a.openDirectConsent(s, l, f, g, _);
260
- }, []), p = h((s) => {
261
- a.close(s);
262
- }, []), m = h((s) => a.onCallback(s), []), d = h(() => a.isOpen(), []);
263
- return { open: i, openConsent: o, openPreferences: r, openDirectConsent: c, close: p, onEvent: m, isOpen: d };
259
+ const { requestId: f, ...p } = l ?? {};
260
+ f ? c.openConsent(f, s, p) : c.openPreferences(s, p);
261
+ }, []), r = h((s, l, f) => {
262
+ c.openConsent(s, l, f);
263
+ }, []), o = h((s, l) => {
264
+ c.openPreferences(s, l);
265
+ }, []), a = h((s, l, f, p, x) => {
266
+ c.openDirectConsent(s, l, f, p, x);
267
+ }, []), g = h((s) => {
268
+ c.close(s);
269
+ }, []), m = h((s) => c.onCallback(s), []), d = h(() => c.isOpen(), []);
270
+ return { open: i, openConsent: r, openPreferences: o, openDirectConsent: a, close: g, onEvent: m, isOpen: d };
264
271
  }
265
272
  export {
266
273
  R as useConsentWidget
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@truzyx/consent-widget",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Framework-agnostic consent + preferences widget (iframe overlay) with React hook. Reuses the gateway embed core, zero runtime dependencies for the vanilla entry.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",