@chaindoc_io/embed-sdk 1.0.0 → 1.0.1

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 ADDED
@@ -0,0 +1,62 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [1.0.0] - 2024-12-10
9
+
10
+ ### Added
11
+ - **Stable Release** - First production-ready version of Chaindoc Embed SDK
12
+ - Modal and inline display modes for signature flows
13
+ - PostMessage-based secure communication with iframe
14
+ - Event callbacks: `onSuccess`, `onError`, `onCancel`, `onReady`, `onClose`
15
+ - Theme switching (light/dark mode)
16
+ - Localization support for 14 languages (en, ru, uk, pl, de, es, pt, fr, et, kk, zh, hi, tr, vi)
17
+ - Full TypeScript support with type definitions
18
+ - CDN distribution via unpkg and jsDelivr
19
+ - UMD, ESM, and CommonJS build outputs
20
+ - Zero runtime dependencies
21
+
22
+ ### Changed
23
+ - Simplified SDK configuration - removed `baseUrl` property (environment-based URLs are now automatic)
24
+ - Updated embed domains for production, staging, and development environments
25
+
26
+ ### Security
27
+ - Origin validation for postMessage communication
28
+ - Sandboxed iframe with minimal required permissions
29
+
30
+ ---
31
+
32
+ ## Pre-release History
33
+
34
+ ### [0.1.0-alpha.13] - 2024-12-10
35
+ - Updated iframe base URLs to new embed domains for all environments
36
+
37
+ ### [0.1.0-alpha.12] - 2024-12-09
38
+ - Removed `baseUrl` property from configuration (breaking change)
39
+ - Simplified SDK setup - URLs are now determined automatically by environment
40
+
41
+ ### [0.1.0-alpha.11] - 2024-12-08
42
+ - Added localization support with 14 languages
43
+ - Added `language` option to signature flow configuration
44
+
45
+ ### [0.1.0-alpha.10] - 2024-12-07
46
+ - Added CDN support (unpkg, jsDelivr)
47
+ - Updated installation documentation
48
+
49
+ ### [0.1.0-alpha.9] - 2024-12-06
50
+ - Added UMD/IIFE build for CDN usage
51
+ - Refactored build configuration
52
+
53
+ ### [0.1.0-alpha.8] - 2024-12-05
54
+ - Updated documentation URLs and support contacts
55
+
56
+ ### [0.1.0-alpha.1 - 0.1.0-alpha.7] - 2024-12
57
+ - Initial alpha releases
58
+ - Core SDK implementation
59
+ - Documentation and framework guides
60
+
61
+ [1.0.0]: https://github.com/ChaindocIO/embed-sdk/releases/tag/v1.0.0
62
+ [0.1.0-alpha.13]: https://github.com/ChaindocIO/embed-sdk/releases/tag/v0.1.0-alpha.13
package/README.md CHANGED
@@ -104,9 +104,11 @@ Embeds the signing flow directly into a container element on your page - ideal f
104
104
 
105
105
  For detailed documentation, API reference, and examples, visit:
106
106
 
107
- - [Implementation Guide](docs/SDK_IMPLEMENTATION_GUIDE.md)
108
- - [API Documentation](#) _(coming soon)_
109
- - [Examples](#) _(coming soon)_
107
+ - [Introduction](https://chaindoc.io/docs/introduction)
108
+ - [Quick Start](https://chaindoc.io/docs/quick-start)
109
+ - [API Documentation](https://chaindoc.io/docs/api-docs)
110
+ - [Chaindoc SDKs](https://chaindoc.io/docs/sdks)
111
+ - [Changelog](CHANGELOG.md) - Version history
110
112
 
111
113
  ## Changelog
112
114
 
@@ -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.0.0"}};return I(x);})();
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.0.1"}};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.0.0"}};0&&(module.exports={ChaindocEmbed,EmbedInstance});
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.0.1"}};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.0.0"}};export{d as ChaindocEmbed,s as EmbedInstance};
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.0.1"}};export{d as ChaindocEmbed,s as EmbedInstance};
38
38
  //# sourceMappingURL=index.mjs.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chaindoc_io/embed-sdk",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "JavaScript/TypeScript SDK for embedding Chaindoc document signing flow via iframe",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
@@ -17,7 +17,8 @@
17
17
  "files": [
18
18
  "dist",
19
19
  "README.md",
20
- "LICENSE"
20
+ "LICENSE",
21
+ "CHANGELOG.md"
21
22
  ],
22
23
  "scripts": {
23
24
  "build": "tsup",