@chaindoc_io/embed-sdk 1.1.0-alpha.1 → 1.1.0-alpha.2
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/CHANGELOG.md +5 -1
- package/README.md +10 -0
- package/dist/embed-sdk.umd.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,7 +5,11 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
-
## [1.1.0] -
|
|
8
|
+
## [1.1.0-alpha.2] - 2026-04-03
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- **Unit tests**: Added `ChaindocEmbed.test.ts` covering SDK initialization and signature flow.
|
|
12
|
+
- **CI workflow**: GitHub Actions CI pipeline for automated testing and build checks.
|
|
9
13
|
|
|
10
14
|
### Changed
|
|
11
15
|
- **`publicKey` documentation**: Honestly documented that `publicKey` is currently used for SDK initialization validation only — it is not sent to the iframe or used for runtime authentication. Embedded session auth is handled via OTP → JWT flow. The field is kept for forward compatibility (origin binding, usage logging, session policy).
|
package/README.md
CHANGED
|
@@ -73,6 +73,16 @@ const instance = sdk.openSignatureFlow({
|
|
|
73
73
|
});
|
|
74
74
|
```
|
|
75
75
|
|
|
76
|
+
## `publicKey` today
|
|
77
|
+
|
|
78
|
+
`publicKey` is still required and validated on SDK initialization, but it is not currently forwarded to the iframe or used for runtime authentication. The real embedded auth flow is:
|
|
79
|
+
|
|
80
|
+
1. Your backend creates an embedded session
|
|
81
|
+
2. The signer verifies OTP
|
|
82
|
+
3. The iframe receives a short-lived JWT for `/api/v1/embedded/*`
|
|
83
|
+
|
|
84
|
+
The field remains in the API for backward compatibility and future productization, but for Phase 0 it should be understood as ceremonial rather than security-critical runtime auth.
|
|
85
|
+
|
|
76
86
|
## How It Works
|
|
77
87
|
|
|
78
88
|
1. Your backend creates a signing session via Chaindoc API
|
package/dist/embed-sdk.umd.js
CHANGED
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
`.trim()}function w(){return`
|
|
35
35
|
position: relative;
|
|
36
36
|
width: 100%;
|
|
37
|
-
`.trim()}var r=class{constructor(e,t,n){this.overlay=null;this.container=null;this.previousOverflow="";this.internalEventHandlers=new Map;this.config=e,this.logger=n,this.options=t,this.state={sessionId:this.options.sessionId,mode:this.options.mode||"modal",theme:this.options.theme||"light",isReady:!1,isClosed:!1};let o=c(this.config.environment);this.allowedOrigin=g(this.config.environment);let s=h(o,this.options.sessionId,this.options.email,this.options.theme,this.options.language);this.iframe=this.createIframe(s),this.messageListener=this.handleMessage.bind(this),window.addEventListener("message",this.messageListener),this.state.mode==="modal"?this.renderModal():this.renderInline(),this.logger.log("Instance created",{sessionId:this.state.sessionId,mode:this.state.mode})}createIframe(e){let t=document.createElement("iframe");return t.src=e,t.setAttribute("style",v(this.state.mode)),t.setAttribute("sandbox","allow-scripts allow-same-origin allow-forms allow-popups"),t.setAttribute("allow","clipboard-write; camera; microphone; geolocation"),t}renderModal(){this.overlay=document.createElement("div"),this.overlay.setAttribute("style",u(this.options.zIndex??999999)),this.overlay.setAttribute("data-chaindoc-overlay","true");let e=document.createElement("div");if(e.setAttribute("style",f(this.options.modalWidth,this.options.modalHeight)),e.appendChild(this.iframe),this.overlay.appendChild(e),this.options.closeOnClickOutside!==!1&&this.overlay.addEventListener("click",t=>{t.target===this.overlay&&(this.logger.log("Clicked outside modal - closing"),this.options.onCancel?.(),this.close())}),this.options.closeOnEscape!==!1){let t=n=>{n.key==="Escape"&&(this.logger.log("ESC key pressed - closing"),this.options.onCancel?.(),this.close())};document.addEventListener("keydown",t),this._internalOn("close",()=>{document.removeEventListener("keydown",t)})}this.previousOverflow=document.body.style.overflow,document.body.style.overflow="hidden",document.body.appendChild(this.overlay)}renderInline(){if(!this.options.container)throw new Error("Container is required for inline mode");this.container=m(this.options.container);let e=document.createElement("div");e.setAttribute("style",w()),e.setAttribute("data-chaindoc-inline","true"),e.appendChild(this.iframe),this.container.appendChild(e)}handleMessage(e){if(e.origin!==this.allowedOrigin||e.source!==this.iframe.contentWindow||!p(e.data))return;let t=e.data;switch(this.logger.log("Received message:",t.type,t),t.type){case"READY":this.state.isReady=!0,this.options.onReady?.();break;case"RESIZE":"data"in t&&(this.iframe.style.height=`${t.data.height}px`);break;case"SUCCESS":"data"in t&&this.options.onSuccess?.(t.data);break;case"ERROR":"data"in t&&this.options.onError?.(t.data);break;case"CANCEL":this.options.onCancel?.();break;case"CLOSED":this.cleanup();break;case"RESEND_OTP":"data"in t&&this.options.onResendOtp?.(t.data);break;default:this.logger.warn("Unknown message type:",t)}}sendMessage(e){if(!this.iframe.contentWindow){this.logger.error("Cannot send message: iframe contentWindow not available");return}this.iframe.contentWindow.postMessage(e,this.allowedOrigin),this.logger.log("Sent message to iframe:",e.type)}close(){if(this.state.isClosed){this.logger.warn("Instance already closed");return}this.logger.log("Closing instance"),this.sendMessage({source:"chaindoc-embed",type:"CLOSE"}),setTimeout(()=>{this.state.isClosed||(this.logger.warn("Iframe did not respond to CLOSE, forcing cleanup"),this.cleanup())},3e3)}changeTheme(e){this.logger.log("Changing theme to:",e),this.state.theme=e,this.sendMessage({source:"chaindoc-embed",type:"THEME_CHANGE",data:{theme:e}})}isReady(){return this.state.isReady}getSessionId(){return this.state.sessionId}_internalOn(e,t){this.internalEventHandlers.has(e)||this.internalEventHandlers.set(e,new Set),this.internalEventHandlers.get(e).add(t)}emit(e){let t=this.internalEventHandlers.get(e);t&&t.forEach(n=>n())}cleanup(){this.state.isClosed||(this.logger.log("Cleaning up instance"),this.state.isClosed=!0,window.removeEventListener("message",this.messageListener),this.overlay&&(this.overlay.remove(),document.body.style.overflow=this.previousOverflow),this.container&&this.container.querySelector("[data-chaindoc-inline]")?.remove(),this.options.onClose?.(),this.emit("close"),this.internalEventHandlers.clear())}};var l=class{constructor(e){this.instances=new Set;if(!e.publicKey)throw new Error("ChaindocEmbed: publicKey is required");if(!e.publicKey.startsWith("pk_"))throw new Error('ChaindocEmbed: publicKey must start with "pk_"');this.config={publicKey:e.publicKey,environment:e.environment||"production",debug:e.debug||!1},this.logger=new a(this.config.debug),this.logger.log("SDK initialized",this.config)}openSignatureFlow(e){if(!e.sessionId)throw new Error("openSignatureFlow: sessionId is required");if(!e.sessionId.startsWith("ses_"))throw new Error('openSignatureFlow: sessionId must start with "ses_"');if((e.mode||"modal")==="inline"&&!e.container)throw new Error("openSignatureFlow: container is required for inline mode");this.logger.log("Opening signature flow",e);let n=new r(this.config,e,this.logger);return this.instances.add(n),n._internalOn("close",()=>{this.instances.delete(n)}),n}destroy(){this.logger.log("Destroying SDK and all instances");for(let e of this.instances)e.close();this.instances.clear()}static get version(){return"1.1.0-alpha.
|
|
37
|
+
`.trim()}var r=class{constructor(e,t,n){this.overlay=null;this.container=null;this.previousOverflow="";this.internalEventHandlers=new Map;this.config=e,this.logger=n,this.options=t,this.state={sessionId:this.options.sessionId,mode:this.options.mode||"modal",theme:this.options.theme||"light",isReady:!1,isClosed:!1};let o=c(this.config.environment);this.allowedOrigin=g(this.config.environment);let s=h(o,this.options.sessionId,this.options.email,this.options.theme,this.options.language);this.iframe=this.createIframe(s),this.messageListener=this.handleMessage.bind(this),window.addEventListener("message",this.messageListener),this.state.mode==="modal"?this.renderModal():this.renderInline(),this.logger.log("Instance created",{sessionId:this.state.sessionId,mode:this.state.mode})}createIframe(e){let t=document.createElement("iframe");return t.src=e,t.setAttribute("style",v(this.state.mode)),t.setAttribute("sandbox","allow-scripts allow-same-origin allow-forms allow-popups"),t.setAttribute("allow","clipboard-write; camera; microphone; geolocation"),t}renderModal(){this.overlay=document.createElement("div"),this.overlay.setAttribute("style",u(this.options.zIndex??999999)),this.overlay.setAttribute("data-chaindoc-overlay","true");let e=document.createElement("div");if(e.setAttribute("style",f(this.options.modalWidth,this.options.modalHeight)),e.appendChild(this.iframe),this.overlay.appendChild(e),this.options.closeOnClickOutside!==!1&&this.overlay.addEventListener("click",t=>{t.target===this.overlay&&(this.logger.log("Clicked outside modal - closing"),this.options.onCancel?.(),this.close())}),this.options.closeOnEscape!==!1){let t=n=>{n.key==="Escape"&&(this.logger.log("ESC key pressed - closing"),this.options.onCancel?.(),this.close())};document.addEventListener("keydown",t),this._internalOn("close",()=>{document.removeEventListener("keydown",t)})}this.previousOverflow=document.body.style.overflow,document.body.style.overflow="hidden",document.body.appendChild(this.overlay)}renderInline(){if(!this.options.container)throw new Error("Container is required for inline mode");this.container=m(this.options.container);let e=document.createElement("div");e.setAttribute("style",w()),e.setAttribute("data-chaindoc-inline","true"),e.appendChild(this.iframe),this.container.appendChild(e)}handleMessage(e){if(e.origin!==this.allowedOrigin||e.source!==this.iframe.contentWindow||!p(e.data))return;let t=e.data;switch(this.logger.log("Received message:",t.type,t),t.type){case"READY":this.state.isReady=!0,this.options.onReady?.();break;case"RESIZE":"data"in t&&(this.iframe.style.height=`${t.data.height}px`);break;case"SUCCESS":"data"in t&&this.options.onSuccess?.(t.data);break;case"ERROR":"data"in t&&this.options.onError?.(t.data);break;case"CANCEL":this.options.onCancel?.();break;case"CLOSED":this.cleanup();break;case"RESEND_OTP":"data"in t&&this.options.onResendOtp?.(t.data);break;default:this.logger.warn("Unknown message type:",t)}}sendMessage(e){if(!this.iframe.contentWindow){this.logger.error("Cannot send message: iframe contentWindow not available");return}this.iframe.contentWindow.postMessage(e,this.allowedOrigin),this.logger.log("Sent message to iframe:",e.type)}close(){if(this.state.isClosed){this.logger.warn("Instance already closed");return}this.logger.log("Closing instance"),this.sendMessage({source:"chaindoc-embed",type:"CLOSE"}),setTimeout(()=>{this.state.isClosed||(this.logger.warn("Iframe did not respond to CLOSE, forcing cleanup"),this.cleanup())},3e3)}changeTheme(e){this.logger.log("Changing theme to:",e),this.state.theme=e,this.sendMessage({source:"chaindoc-embed",type:"THEME_CHANGE",data:{theme:e}})}isReady(){return this.state.isReady}getSessionId(){return this.state.sessionId}_internalOn(e,t){this.internalEventHandlers.has(e)||this.internalEventHandlers.set(e,new Set),this.internalEventHandlers.get(e).add(t)}emit(e){let t=this.internalEventHandlers.get(e);t&&t.forEach(n=>n())}cleanup(){this.state.isClosed||(this.logger.log("Cleaning up instance"),this.state.isClosed=!0,window.removeEventListener("message",this.messageListener),this.overlay&&(this.overlay.remove(),document.body.style.overflow=this.previousOverflow),this.container&&this.container.querySelector("[data-chaindoc-inline]")?.remove(),this.options.onClose?.(),this.emit("close"),this.internalEventHandlers.clear())}};var l=class{constructor(e){this.instances=new Set;if(!e.publicKey)throw new Error("ChaindocEmbed: publicKey is required");if(!e.publicKey.startsWith("pk_"))throw new Error('ChaindocEmbed: publicKey must start with "pk_"');this.config={publicKey:e.publicKey,environment:e.environment||"production",debug:e.debug||!1},this.logger=new a(this.config.debug),this.logger.log("SDK initialized",this.config)}openSignatureFlow(e){if(!e.sessionId)throw new Error("openSignatureFlow: sessionId is required");if(!e.sessionId.startsWith("ses_"))throw new Error('openSignatureFlow: sessionId must start with "ses_"');if((e.mode||"modal")==="inline"&&!e.container)throw new Error("openSignatureFlow: container is required for inline mode");this.logger.log("Opening signature flow",e);let n=new r(this.config,e,this.logger);return this.instances.add(n),n._internalOn("close",()=>{this.instances.delete(n)}),n}destroy(){this.logger.log("Destroying SDK and all instances");for(let e of this.instances)e.close();this.instances.clear()}static get version(){return"1.1.0-alpha.2"}};return I(x);})();
|
|
38
38
|
//# sourceMappingURL=embed-sdk.umd.js.map
|
package/dist/index.cjs
CHANGED
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
`.trim()}function w(){return`
|
|
35
35
|
position: relative;
|
|
36
36
|
width: 100%;
|
|
37
|
-
`.trim()}var r=class{constructor(e,t,n){this.overlay=null;this.container=null;this.previousOverflow="";this.internalEventHandlers=new Map;this.config=e,this.logger=n,this.options=t,this.state={sessionId:this.options.sessionId,mode:this.options.mode||"modal",theme:this.options.theme||"light",isReady:!1,isClosed:!1};let o=c(this.config.environment);this.allowedOrigin=g(this.config.environment);let s=h(o,this.options.sessionId,this.options.email,this.options.theme,this.options.language);this.iframe=this.createIframe(s),this.messageListener=this.handleMessage.bind(this),window.addEventListener("message",this.messageListener),this.state.mode==="modal"?this.renderModal():this.renderInline(),this.logger.log("Instance created",{sessionId:this.state.sessionId,mode:this.state.mode})}createIframe(e){let t=document.createElement("iframe");return t.src=e,t.setAttribute("style",v(this.state.mode)),t.setAttribute("sandbox","allow-scripts allow-same-origin allow-forms allow-popups"),t.setAttribute("allow","clipboard-write; camera; microphone; geolocation"),t}renderModal(){this.overlay=document.createElement("div"),this.overlay.setAttribute("style",u(this.options.zIndex??999999)),this.overlay.setAttribute("data-chaindoc-overlay","true");let e=document.createElement("div");if(e.setAttribute("style",f(this.options.modalWidth,this.options.modalHeight)),e.appendChild(this.iframe),this.overlay.appendChild(e),this.options.closeOnClickOutside!==!1&&this.overlay.addEventListener("click",t=>{t.target===this.overlay&&(this.logger.log("Clicked outside modal - closing"),this.options.onCancel?.(),this.close())}),this.options.closeOnEscape!==!1){let t=n=>{n.key==="Escape"&&(this.logger.log("ESC key pressed - closing"),this.options.onCancel?.(),this.close())};document.addEventListener("keydown",t),this._internalOn("close",()=>{document.removeEventListener("keydown",t)})}this.previousOverflow=document.body.style.overflow,document.body.style.overflow="hidden",document.body.appendChild(this.overlay)}renderInline(){if(!this.options.container)throw new Error("Container is required for inline mode");this.container=m(this.options.container);let e=document.createElement("div");e.setAttribute("style",w()),e.setAttribute("data-chaindoc-inline","true"),e.appendChild(this.iframe),this.container.appendChild(e)}handleMessage(e){if(e.origin!==this.allowedOrigin||e.source!==this.iframe.contentWindow||!p(e.data))return;let t=e.data;switch(this.logger.log("Received message:",t.type,t),t.type){case"READY":this.state.isReady=!0,this.options.onReady?.();break;case"RESIZE":"data"in t&&(this.iframe.style.height=`${t.data.height}px`);break;case"SUCCESS":"data"in t&&this.options.onSuccess?.(t.data);break;case"ERROR":"data"in t&&this.options.onError?.(t.data);break;case"CANCEL":this.options.onCancel?.();break;case"CLOSED":this.cleanup();break;case"RESEND_OTP":"data"in t&&this.options.onResendOtp?.(t.data);break;default:this.logger.warn("Unknown message type:",t)}}sendMessage(e){if(!this.iframe.contentWindow){this.logger.error("Cannot send message: iframe contentWindow not available");return}this.iframe.contentWindow.postMessage(e,this.allowedOrigin),this.logger.log("Sent message to iframe:",e.type)}close(){if(this.state.isClosed){this.logger.warn("Instance already closed");return}this.logger.log("Closing instance"),this.sendMessage({source:"chaindoc-embed",type:"CLOSE"}),setTimeout(()=>{this.state.isClosed||(this.logger.warn("Iframe did not respond to CLOSE, forcing cleanup"),this.cleanup())},3e3)}changeTheme(e){this.logger.log("Changing theme to:",e),this.state.theme=e,this.sendMessage({source:"chaindoc-embed",type:"THEME_CHANGE",data:{theme:e}})}isReady(){return this.state.isReady}getSessionId(){return this.state.sessionId}_internalOn(e,t){this.internalEventHandlers.has(e)||this.internalEventHandlers.set(e,new Set),this.internalEventHandlers.get(e).add(t)}emit(e){let t=this.internalEventHandlers.get(e);t&&t.forEach(n=>n())}cleanup(){this.state.isClosed||(this.logger.log("Cleaning up instance"),this.state.isClosed=!0,window.removeEventListener("message",this.messageListener),this.overlay&&(this.overlay.remove(),document.body.style.overflow=this.previousOverflow),this.container&&this.container.querySelector("[data-chaindoc-inline]")?.remove(),this.options.onClose?.(),this.emit("close"),this.internalEventHandlers.clear())}};var l=class{constructor(e){this.instances=new Set;if(!e.publicKey)throw new Error("ChaindocEmbed: publicKey is required");if(!e.publicKey.startsWith("pk_"))throw new Error('ChaindocEmbed: publicKey must start with "pk_"');this.config={publicKey:e.publicKey,environment:e.environment||"production",debug:e.debug||!1},this.logger=new a(this.config.debug),this.logger.log("SDK initialized",this.config)}openSignatureFlow(e){if(!e.sessionId)throw new Error("openSignatureFlow: sessionId is required");if(!e.sessionId.startsWith("ses_"))throw new Error('openSignatureFlow: sessionId must start with "ses_"');if((e.mode||"modal")==="inline"&&!e.container)throw new Error("openSignatureFlow: container is required for inline mode");this.logger.log("Opening signature flow",e);let n=new r(this.config,e,this.logger);return this.instances.add(n),n._internalOn("close",()=>{this.instances.delete(n)}),n}destroy(){this.logger.log("Destroying SDK and all instances");for(let e of this.instances)e.close();this.instances.clear()}static get version(){return"1.1.0-alpha.
|
|
37
|
+
`.trim()}var r=class{constructor(e,t,n){this.overlay=null;this.container=null;this.previousOverflow="";this.internalEventHandlers=new Map;this.config=e,this.logger=n,this.options=t,this.state={sessionId:this.options.sessionId,mode:this.options.mode||"modal",theme:this.options.theme||"light",isReady:!1,isClosed:!1};let o=c(this.config.environment);this.allowedOrigin=g(this.config.environment);let s=h(o,this.options.sessionId,this.options.email,this.options.theme,this.options.language);this.iframe=this.createIframe(s),this.messageListener=this.handleMessage.bind(this),window.addEventListener("message",this.messageListener),this.state.mode==="modal"?this.renderModal():this.renderInline(),this.logger.log("Instance created",{sessionId:this.state.sessionId,mode:this.state.mode})}createIframe(e){let t=document.createElement("iframe");return t.src=e,t.setAttribute("style",v(this.state.mode)),t.setAttribute("sandbox","allow-scripts allow-same-origin allow-forms allow-popups"),t.setAttribute("allow","clipboard-write; camera; microphone; geolocation"),t}renderModal(){this.overlay=document.createElement("div"),this.overlay.setAttribute("style",u(this.options.zIndex??999999)),this.overlay.setAttribute("data-chaindoc-overlay","true");let e=document.createElement("div");if(e.setAttribute("style",f(this.options.modalWidth,this.options.modalHeight)),e.appendChild(this.iframe),this.overlay.appendChild(e),this.options.closeOnClickOutside!==!1&&this.overlay.addEventListener("click",t=>{t.target===this.overlay&&(this.logger.log("Clicked outside modal - closing"),this.options.onCancel?.(),this.close())}),this.options.closeOnEscape!==!1){let t=n=>{n.key==="Escape"&&(this.logger.log("ESC key pressed - closing"),this.options.onCancel?.(),this.close())};document.addEventListener("keydown",t),this._internalOn("close",()=>{document.removeEventListener("keydown",t)})}this.previousOverflow=document.body.style.overflow,document.body.style.overflow="hidden",document.body.appendChild(this.overlay)}renderInline(){if(!this.options.container)throw new Error("Container is required for inline mode");this.container=m(this.options.container);let e=document.createElement("div");e.setAttribute("style",w()),e.setAttribute("data-chaindoc-inline","true"),e.appendChild(this.iframe),this.container.appendChild(e)}handleMessage(e){if(e.origin!==this.allowedOrigin||e.source!==this.iframe.contentWindow||!p(e.data))return;let t=e.data;switch(this.logger.log("Received message:",t.type,t),t.type){case"READY":this.state.isReady=!0,this.options.onReady?.();break;case"RESIZE":"data"in t&&(this.iframe.style.height=`${t.data.height}px`);break;case"SUCCESS":"data"in t&&this.options.onSuccess?.(t.data);break;case"ERROR":"data"in t&&this.options.onError?.(t.data);break;case"CANCEL":this.options.onCancel?.();break;case"CLOSED":this.cleanup();break;case"RESEND_OTP":"data"in t&&this.options.onResendOtp?.(t.data);break;default:this.logger.warn("Unknown message type:",t)}}sendMessage(e){if(!this.iframe.contentWindow){this.logger.error("Cannot send message: iframe contentWindow not available");return}this.iframe.contentWindow.postMessage(e,this.allowedOrigin),this.logger.log("Sent message to iframe:",e.type)}close(){if(this.state.isClosed){this.logger.warn("Instance already closed");return}this.logger.log("Closing instance"),this.sendMessage({source:"chaindoc-embed",type:"CLOSE"}),setTimeout(()=>{this.state.isClosed||(this.logger.warn("Iframe did not respond to CLOSE, forcing cleanup"),this.cleanup())},3e3)}changeTheme(e){this.logger.log("Changing theme to:",e),this.state.theme=e,this.sendMessage({source:"chaindoc-embed",type:"THEME_CHANGE",data:{theme:e}})}isReady(){return this.state.isReady}getSessionId(){return this.state.sessionId}_internalOn(e,t){this.internalEventHandlers.has(e)||this.internalEventHandlers.set(e,new Set),this.internalEventHandlers.get(e).add(t)}emit(e){let t=this.internalEventHandlers.get(e);t&&t.forEach(n=>n())}cleanup(){this.state.isClosed||(this.logger.log("Cleaning up instance"),this.state.isClosed=!0,window.removeEventListener("message",this.messageListener),this.overlay&&(this.overlay.remove(),document.body.style.overflow=this.previousOverflow),this.container&&this.container.querySelector("[data-chaindoc-inline]")?.remove(),this.options.onClose?.(),this.emit("close"),this.internalEventHandlers.clear())}};var l=class{constructor(e){this.instances=new Set;if(!e.publicKey)throw new Error("ChaindocEmbed: publicKey is required");if(!e.publicKey.startsWith("pk_"))throw new Error('ChaindocEmbed: publicKey must start with "pk_"');this.config={publicKey:e.publicKey,environment:e.environment||"production",debug:e.debug||!1},this.logger=new a(this.config.debug),this.logger.log("SDK initialized",this.config)}openSignatureFlow(e){if(!e.sessionId)throw new Error("openSignatureFlow: sessionId is required");if(!e.sessionId.startsWith("ses_"))throw new Error('openSignatureFlow: sessionId must start with "ses_"');if((e.mode||"modal")==="inline"&&!e.container)throw new Error("openSignatureFlow: container is required for inline mode");this.logger.log("Opening signature flow",e);let n=new r(this.config,e,this.logger);return this.instances.add(n),n._internalOn("close",()=>{this.instances.delete(n)}),n}destroy(){this.logger.log("Destroying SDK and all instances");for(let e of this.instances)e.close();this.instances.clear()}static get version(){return"1.1.0-alpha.2"}};0&&(module.exports={ChaindocEmbed,EmbedInstance});
|
|
38
38
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.mjs
CHANGED
|
@@ -34,5 +34,5 @@ function l(i){switch(i){case"production":return"https://embed.chaindoc.io";case"
|
|
|
34
34
|
`.trim()}function v(){return`
|
|
35
35
|
position: relative;
|
|
36
36
|
width: 100%;
|
|
37
|
-
`.trim()}var s=class{constructor(e,t,n){this.overlay=null;this.container=null;this.previousOverflow="";this.internalEventHandlers=new Map;this.config=e,this.logger=n,this.options=t,this.state={sessionId:this.options.sessionId,mode:this.options.mode||"modal",theme:this.options.theme||"light",isReady:!1,isClosed:!1};let r=l(this.config.environment);this.allowedOrigin=c(this.config.environment);let o=g(r,this.options.sessionId,this.options.email,this.options.theme,this.options.language);this.iframe=this.createIframe(o),this.messageListener=this.handleMessage.bind(this),window.addEventListener("message",this.messageListener),this.state.mode==="modal"?this.renderModal():this.renderInline(),this.logger.log("Instance created",{sessionId:this.state.sessionId,mode:this.state.mode})}createIframe(e){let t=document.createElement("iframe");return t.src=e,t.setAttribute("style",f(this.state.mode)),t.setAttribute("sandbox","allow-scripts allow-same-origin allow-forms allow-popups"),t.setAttribute("allow","clipboard-write; camera; microphone; geolocation"),t}renderModal(){this.overlay=document.createElement("div"),this.overlay.setAttribute("style",p(this.options.zIndex??999999)),this.overlay.setAttribute("data-chaindoc-overlay","true");let e=document.createElement("div");if(e.setAttribute("style",u(this.options.modalWidth,this.options.modalHeight)),e.appendChild(this.iframe),this.overlay.appendChild(e),this.options.closeOnClickOutside!==!1&&this.overlay.addEventListener("click",t=>{t.target===this.overlay&&(this.logger.log("Clicked outside modal - closing"),this.options.onCancel?.(),this.close())}),this.options.closeOnEscape!==!1){let t=n=>{n.key==="Escape"&&(this.logger.log("ESC key pressed - closing"),this.options.onCancel?.(),this.close())};document.addEventListener("keydown",t),this._internalOn("close",()=>{document.removeEventListener("keydown",t)})}this.previousOverflow=document.body.style.overflow,document.body.style.overflow="hidden",document.body.appendChild(this.overlay)}renderInline(){if(!this.options.container)throw new Error("Container is required for inline mode");this.container=h(this.options.container);let e=document.createElement("div");e.setAttribute("style",v()),e.setAttribute("data-chaindoc-inline","true"),e.appendChild(this.iframe),this.container.appendChild(e)}handleMessage(e){if(e.origin!==this.allowedOrigin||e.source!==this.iframe.contentWindow||!m(e.data))return;let t=e.data;switch(this.logger.log("Received message:",t.type,t),t.type){case"READY":this.state.isReady=!0,this.options.onReady?.();break;case"RESIZE":"data"in t&&(this.iframe.style.height=`${t.data.height}px`);break;case"SUCCESS":"data"in t&&this.options.onSuccess?.(t.data);break;case"ERROR":"data"in t&&this.options.onError?.(t.data);break;case"CANCEL":this.options.onCancel?.();break;case"CLOSED":this.cleanup();break;case"RESEND_OTP":"data"in t&&this.options.onResendOtp?.(t.data);break;default:this.logger.warn("Unknown message type:",t)}}sendMessage(e){if(!this.iframe.contentWindow){this.logger.error("Cannot send message: iframe contentWindow not available");return}this.iframe.contentWindow.postMessage(e,this.allowedOrigin),this.logger.log("Sent message to iframe:",e.type)}close(){if(this.state.isClosed){this.logger.warn("Instance already closed");return}this.logger.log("Closing instance"),this.sendMessage({source:"chaindoc-embed",type:"CLOSE"}),setTimeout(()=>{this.state.isClosed||(this.logger.warn("Iframe did not respond to CLOSE, forcing cleanup"),this.cleanup())},3e3)}changeTheme(e){this.logger.log("Changing theme to:",e),this.state.theme=e,this.sendMessage({source:"chaindoc-embed",type:"THEME_CHANGE",data:{theme:e}})}isReady(){return this.state.isReady}getSessionId(){return this.state.sessionId}_internalOn(e,t){this.internalEventHandlers.has(e)||this.internalEventHandlers.set(e,new Set),this.internalEventHandlers.get(e).add(t)}emit(e){let t=this.internalEventHandlers.get(e);t&&t.forEach(n=>n())}cleanup(){this.state.isClosed||(this.logger.log("Cleaning up instance"),this.state.isClosed=!0,window.removeEventListener("message",this.messageListener),this.overlay&&(this.overlay.remove(),document.body.style.overflow=this.previousOverflow),this.container&&this.container.querySelector("[data-chaindoc-inline]")?.remove(),this.options.onClose?.(),this.emit("close"),this.internalEventHandlers.clear())}};var d=class{constructor(e){this.instances=new Set;if(!e.publicKey)throw new Error("ChaindocEmbed: publicKey is required");if(!e.publicKey.startsWith("pk_"))throw new Error('ChaindocEmbed: publicKey must start with "pk_"');this.config={publicKey:e.publicKey,environment:e.environment||"production",debug:e.debug||!1},this.logger=new a(this.config.debug),this.logger.log("SDK initialized",this.config)}openSignatureFlow(e){if(!e.sessionId)throw new Error("openSignatureFlow: sessionId is required");if(!e.sessionId.startsWith("ses_"))throw new Error('openSignatureFlow: sessionId must start with "ses_"');if((e.mode||"modal")==="inline"&&!e.container)throw new Error("openSignatureFlow: container is required for inline mode");this.logger.log("Opening signature flow",e);let n=new s(this.config,e,this.logger);return this.instances.add(n),n._internalOn("close",()=>{this.instances.delete(n)}),n}destroy(){this.logger.log("Destroying SDK and all instances");for(let e of this.instances)e.close();this.instances.clear()}static get version(){return"1.1.0-alpha.
|
|
37
|
+
`.trim()}var s=class{constructor(e,t,n){this.overlay=null;this.container=null;this.previousOverflow="";this.internalEventHandlers=new Map;this.config=e,this.logger=n,this.options=t,this.state={sessionId:this.options.sessionId,mode:this.options.mode||"modal",theme:this.options.theme||"light",isReady:!1,isClosed:!1};let r=l(this.config.environment);this.allowedOrigin=c(this.config.environment);let o=g(r,this.options.sessionId,this.options.email,this.options.theme,this.options.language);this.iframe=this.createIframe(o),this.messageListener=this.handleMessage.bind(this),window.addEventListener("message",this.messageListener),this.state.mode==="modal"?this.renderModal():this.renderInline(),this.logger.log("Instance created",{sessionId:this.state.sessionId,mode:this.state.mode})}createIframe(e){let t=document.createElement("iframe");return t.src=e,t.setAttribute("style",f(this.state.mode)),t.setAttribute("sandbox","allow-scripts allow-same-origin allow-forms allow-popups"),t.setAttribute("allow","clipboard-write; camera; microphone; geolocation"),t}renderModal(){this.overlay=document.createElement("div"),this.overlay.setAttribute("style",p(this.options.zIndex??999999)),this.overlay.setAttribute("data-chaindoc-overlay","true");let e=document.createElement("div");if(e.setAttribute("style",u(this.options.modalWidth,this.options.modalHeight)),e.appendChild(this.iframe),this.overlay.appendChild(e),this.options.closeOnClickOutside!==!1&&this.overlay.addEventListener("click",t=>{t.target===this.overlay&&(this.logger.log("Clicked outside modal - closing"),this.options.onCancel?.(),this.close())}),this.options.closeOnEscape!==!1){let t=n=>{n.key==="Escape"&&(this.logger.log("ESC key pressed - closing"),this.options.onCancel?.(),this.close())};document.addEventListener("keydown",t),this._internalOn("close",()=>{document.removeEventListener("keydown",t)})}this.previousOverflow=document.body.style.overflow,document.body.style.overflow="hidden",document.body.appendChild(this.overlay)}renderInline(){if(!this.options.container)throw new Error("Container is required for inline mode");this.container=h(this.options.container);let e=document.createElement("div");e.setAttribute("style",v()),e.setAttribute("data-chaindoc-inline","true"),e.appendChild(this.iframe),this.container.appendChild(e)}handleMessage(e){if(e.origin!==this.allowedOrigin||e.source!==this.iframe.contentWindow||!m(e.data))return;let t=e.data;switch(this.logger.log("Received message:",t.type,t),t.type){case"READY":this.state.isReady=!0,this.options.onReady?.();break;case"RESIZE":"data"in t&&(this.iframe.style.height=`${t.data.height}px`);break;case"SUCCESS":"data"in t&&this.options.onSuccess?.(t.data);break;case"ERROR":"data"in t&&this.options.onError?.(t.data);break;case"CANCEL":this.options.onCancel?.();break;case"CLOSED":this.cleanup();break;case"RESEND_OTP":"data"in t&&this.options.onResendOtp?.(t.data);break;default:this.logger.warn("Unknown message type:",t)}}sendMessage(e){if(!this.iframe.contentWindow){this.logger.error("Cannot send message: iframe contentWindow not available");return}this.iframe.contentWindow.postMessage(e,this.allowedOrigin),this.logger.log("Sent message to iframe:",e.type)}close(){if(this.state.isClosed){this.logger.warn("Instance already closed");return}this.logger.log("Closing instance"),this.sendMessage({source:"chaindoc-embed",type:"CLOSE"}),setTimeout(()=>{this.state.isClosed||(this.logger.warn("Iframe did not respond to CLOSE, forcing cleanup"),this.cleanup())},3e3)}changeTheme(e){this.logger.log("Changing theme to:",e),this.state.theme=e,this.sendMessage({source:"chaindoc-embed",type:"THEME_CHANGE",data:{theme:e}})}isReady(){return this.state.isReady}getSessionId(){return this.state.sessionId}_internalOn(e,t){this.internalEventHandlers.has(e)||this.internalEventHandlers.set(e,new Set),this.internalEventHandlers.get(e).add(t)}emit(e){let t=this.internalEventHandlers.get(e);t&&t.forEach(n=>n())}cleanup(){this.state.isClosed||(this.logger.log("Cleaning up instance"),this.state.isClosed=!0,window.removeEventListener("message",this.messageListener),this.overlay&&(this.overlay.remove(),document.body.style.overflow=this.previousOverflow),this.container&&this.container.querySelector("[data-chaindoc-inline]")?.remove(),this.options.onClose?.(),this.emit("close"),this.internalEventHandlers.clear())}};var d=class{constructor(e){this.instances=new Set;if(!e.publicKey)throw new Error("ChaindocEmbed: publicKey is required");if(!e.publicKey.startsWith("pk_"))throw new Error('ChaindocEmbed: publicKey must start with "pk_"');this.config={publicKey:e.publicKey,environment:e.environment||"production",debug:e.debug||!1},this.logger=new a(this.config.debug),this.logger.log("SDK initialized",this.config)}openSignatureFlow(e){if(!e.sessionId)throw new Error("openSignatureFlow: sessionId is required");if(!e.sessionId.startsWith("ses_"))throw new Error('openSignatureFlow: sessionId must start with "ses_"');if((e.mode||"modal")==="inline"&&!e.container)throw new Error("openSignatureFlow: container is required for inline mode");this.logger.log("Opening signature flow",e);let n=new s(this.config,e,this.logger);return this.instances.add(n),n._internalOn("close",()=>{this.instances.delete(n)}),n}destroy(){this.logger.log("Destroying SDK and all instances");for(let e of this.instances)e.close();this.instances.clear()}static get version(){return"1.1.0-alpha.2"}};export{d as ChaindocEmbed,s as EmbedInstance};
|
|
38
38
|
//# sourceMappingURL=index.mjs.map
|
package/package.json
CHANGED