@declarion/embed 0.44.0 → 0.47.0
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/core.js +1 -4
- package/dist/declarion-embed.iife.js +1 -1
- package/dist/react.js +7 -5
- package/dist/server.js +1 -1
- package/package.json +8 -8
package/dist/core.js
CHANGED
|
@@ -203,10 +203,7 @@ function b(e) {
|
|
|
203
203
|
case n.dirtyChanged:
|
|
204
204
|
k(a.payload);
|
|
205
205
|
break;
|
|
206
|
-
case n.navigationFailed:
|
|
207
|
-
M(a.payload);
|
|
208
|
-
break;
|
|
209
|
-
default: break;
|
|
206
|
+
case n.navigationFailed: M(a.payload);
|
|
210
207
|
}
|
|
211
208
|
}, I = v(e);
|
|
212
209
|
if (I) return console.error(`${_} ${I.message}`), e.onError?.(I), {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var DeclarionEmbed=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=`declarion-embed`,n=1,r={ready:`ready`,setToken:`set-token`,tokenExpired:`token-expired`,reloadRequired:`reload-required`,resized:`resized`,navigated:`navigated`,navigationRequested:`navigation-requested`,dirtyChanged:`dirty-changed`,navigationFailed:`navigation-failed`,navigate:`navigate`,setTheme:`set-theme`};function i(e,t){if(e.origin!==t)return{kind:`rejected`};let n=e.data;if(typeof n!=`object`||!n)return{kind:`rejected`};let r=n;return r.source!==`declarion-embed`||typeof r.protocol!=`number`||typeof r.type!=`string`?{kind:`rejected`}:r.protocol===1?{kind:`valid`,message:r}:{kind:`protocol-mismatch`,received:r.protocol}}var a={invalidOptions:`invalid-options`,getTokenFailed:`get-token-failed`,handshakeTimeout:`handshake-timeout`,reloadRequired:`reload-required`},o=class e extends Error{code;constructor(t,n,r){super(n,r),this.name=`EmbedError`,this.code=t,Object.setPrototypeOf(this,e.prototype)}},s=`embed`,c=`parent_origin`,l=`theme`,u=`1`;function d(e){let t=new URL(e.route,e.declarionOrigin);return t.searchParams.set(s,u),t.searchParams.set(c,e.parentOrigin),t.searchParams.set(`nav`,e.navigation),e.theme&&t.searchParams.set(l,e.theme),t.toString()}function f(e,t){try{let n=new URL(t,e);return n.pathname+n.search+n.hash}catch{return t}}var p=2e4,m=`Declarion embedded screen`,h=[`allow-scripts`,`allow-same-origin`,`allow-forms`,`allow-modals`,`allow-downloads`,`allow-popups`,`allow-popups-to-escape-sandbox`],g=new Set([`allow-top-navigation`,`allow-top-navigation-by-user-activation`]);function _(e){let t=new Set(h);for(let n of e??[]){let e=n.trim();e&&!g.has(e)&&t.add(e)}return Array.from(t).join(` `)}var v=`[declarion-embed]`;function y(e){let t=e=>new o(a.invalidOptions,e);if(!e.container||typeof e.container.appendChild!=`function`)return t("`container` must be a DOM element that can receive the iframe.");if(typeof e.declarionOrigin!=`string`||e.declarionOrigin===``)return t('`declarionOrigin` is required and must be the exact origin of the Declarion deployment, e.g. "https://app.example.com".');let n;try{n=new URL(e.declarionOrigin)}catch{return t(`\`declarionOrigin\` is not a valid URL: "${e.declarionOrigin}". Pass an exact origin, e.g. "https://app.example.com".`)}return n.origin===e.declarionOrigin?typeof e.route!=`string`||e.route===``?t("`route` is required and must be a Declarion screen route."):typeof e.getToken==`function`?null:t("`getToken` is required and must be an async function returning { token, expires_at }."):t(`\`declarionOrigin\` must be exactly an origin with no path, query, or trailing slash. Got "${e.declarionOrigin}"; expected "${n.origin}".`)}function b(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.token==`string`&&t.token!==``&&typeof t.expires_at==`string`&&t.expires_at!==``}function x(e){let t=!1,n=null,s=null,c=null,l=!1,u=!1,h=null,g=(t,n)=>{e.debug&&(n===void 0?console.info(`${v} ${t}`):console.info(`${v} ${t}`,n))},x=(t,n,r)=>{let i=new o(t,n,r?{cause:r}:void 0);console.error(`${v} ${n}`,r??``),e.onError?.(i)},S=(t,r)=>{if(!n?.contentWindow)return;let i={source:`declarion-embed`,protocol:1,type:t,payload:r};g(`-> iframe ${t}`,r),n.contentWindow.postMessage(i,e.declarionOrigin)},C=async()=>{let n;try{n=await e.getToken()}catch(e){x(a.getTokenFailed,"`getToken` rejected. The host backend must mint a token via auth.create_embed_session and return { token, expires_at }.",e);return}if(!b(n)){x(a.getTokenFailed,"`getToken` resolved to a malformed value. Expected { token: string, expires_at: string }.");return}if(t)return;let i={token:n.token,expires_at:n.expires_at};S(r.setToken,i),N()},w=t=>{S(r.navigate,{route:f(e.declarionOrigin,t)})},T=()=>{if(l=!0,P(),g(`<- iframe ready`),e.onEvent?.({type:r.ready}),C(),h!==null){let e=h;h=null,w(e)}},E=()=>{g(`<- iframe token-expired`),e.onEvent?.({type:r.tokenExpired}),C()},D=t=>{g(`<- iframe reload-required`,t),e.onEvent?.({type:r.reloadRequired,payload:t}),x(a.reloadRequired,`The embedded iframe requested a reload: ${t.reason}. Reload the iframe to recover.`)},O=t=>{g(`<- iframe resized`,t),!e.height&&n&&Number.isFinite(t.height)&&t.height>0&&(n.style.height=`${t.height}px`),e.onEvent?.({type:r.resized,payload:t})},k=t=>{g(`<- iframe dirty-changed`,t),e.onEvent?.({type:r.dirtyChanged,payload:t})},A=(t,n)=>{g(`<- iframe ${t}`,n),e.onEvent?.({type:t,payload:n});let i={mode:t===r.navigated?`self`:`delegated`,route:n.route,screenCode:n.screenCode,entity:n.entity,recordId:n.recordId};e.onNavigate?.(i)},j=new Set([`not_found`,`unresolved`]),M=t=>{if(typeof t?.route!=`string`||t.route.length===0||!j.has(t.reason)){g(`<- iframe navigation-failed (dropped: invalid payload)`,t);return}g(`<- iframe navigation-failed`,t),e.onEvent?.({type:r.navigationFailed,payload:t}),e.onNavigationFailed?.(t)},N=()=>{u||(u=!0,g(`handshake complete - iframe authenticated`),e.onReady?.())},P=()=>{c!==null&&(clearTimeout(c),c=null)},F=t=>{if(!n||t.source!==n.contentWindow)return;let a=i(t,e.declarionOrigin);if(a.kind===`rejected`)return;if(a.kind===`protocol-mismatch`){console.warn(`${v} protocol version mismatch: this SDK speaks protocol 1, the iframe reported protocol ${String(a.received)}. Update @declarion/embed and the Declarion deployment to matching versions.`);return}let{message:o}=a;switch(o.type){case r.ready:T();break;case r.tokenExpired:E();break;case r.reloadRequired:D(o.payload);break;case r.resized:O(o.payload);break;case r.navigated:A(r.navigated,o.payload);break;case r.navigationRequested:A(r.navigationRequested,o.payload);break;case r.dirtyChanged:k(o.payload);break;case r.navigationFailed:M(o.payload)
|
|
1
|
+
var DeclarionEmbed=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=`declarion-embed`,n=1,r={ready:`ready`,setToken:`set-token`,tokenExpired:`token-expired`,reloadRequired:`reload-required`,resized:`resized`,navigated:`navigated`,navigationRequested:`navigation-requested`,dirtyChanged:`dirty-changed`,navigationFailed:`navigation-failed`,navigate:`navigate`,setTheme:`set-theme`};function i(e,t){if(e.origin!==t)return{kind:`rejected`};let n=e.data;if(typeof n!=`object`||!n)return{kind:`rejected`};let r=n;return r.source!==`declarion-embed`||typeof r.protocol!=`number`||typeof r.type!=`string`?{kind:`rejected`}:r.protocol===1?{kind:`valid`,message:r}:{kind:`protocol-mismatch`,received:r.protocol}}var a={invalidOptions:`invalid-options`,getTokenFailed:`get-token-failed`,handshakeTimeout:`handshake-timeout`,reloadRequired:`reload-required`},o=class e extends Error{code;constructor(t,n,r){super(n,r),this.name=`EmbedError`,this.code=t,Object.setPrototypeOf(this,e.prototype)}},s=`embed`,c=`parent_origin`,l=`theme`,u=`1`;function d(e){let t=new URL(e.route,e.declarionOrigin);return t.searchParams.set(s,u),t.searchParams.set(c,e.parentOrigin),t.searchParams.set(`nav`,e.navigation),e.theme&&t.searchParams.set(l,e.theme),t.toString()}function f(e,t){try{let n=new URL(t,e);return n.pathname+n.search+n.hash}catch{return t}}var p=2e4,m=`Declarion embedded screen`,h=[`allow-scripts`,`allow-same-origin`,`allow-forms`,`allow-modals`,`allow-downloads`,`allow-popups`,`allow-popups-to-escape-sandbox`],g=new Set([`allow-top-navigation`,`allow-top-navigation-by-user-activation`]);function _(e){let t=new Set(h);for(let n of e??[]){let e=n.trim();e&&!g.has(e)&&t.add(e)}return Array.from(t).join(` `)}var v=`[declarion-embed]`;function y(e){let t=e=>new o(a.invalidOptions,e);if(!e.container||typeof e.container.appendChild!=`function`)return t("`container` must be a DOM element that can receive the iframe.");if(typeof e.declarionOrigin!=`string`||e.declarionOrigin===``)return t('`declarionOrigin` is required and must be the exact origin of the Declarion deployment, e.g. "https://app.example.com".');let n;try{n=new URL(e.declarionOrigin)}catch{return t(`\`declarionOrigin\` is not a valid URL: "${e.declarionOrigin}". Pass an exact origin, e.g. "https://app.example.com".`)}return n.origin===e.declarionOrigin?typeof e.route!=`string`||e.route===``?t("`route` is required and must be a Declarion screen route."):typeof e.getToken==`function`?null:t("`getToken` is required and must be an async function returning { token, expires_at }."):t(`\`declarionOrigin\` must be exactly an origin with no path, query, or trailing slash. Got "${e.declarionOrigin}"; expected "${n.origin}".`)}function b(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.token==`string`&&t.token!==``&&typeof t.expires_at==`string`&&t.expires_at!==``}function x(e){let t=!1,n=null,s=null,c=null,l=!1,u=!1,h=null,g=(t,n)=>{e.debug&&(n===void 0?console.info(`${v} ${t}`):console.info(`${v} ${t}`,n))},x=(t,n,r)=>{let i=new o(t,n,r?{cause:r}:void 0);console.error(`${v} ${n}`,r??``),e.onError?.(i)},S=(t,r)=>{if(!n?.contentWindow)return;let i={source:`declarion-embed`,protocol:1,type:t,payload:r};g(`-> iframe ${t}`,r),n.contentWindow.postMessage(i,e.declarionOrigin)},C=async()=>{let n;try{n=await e.getToken()}catch(e){x(a.getTokenFailed,"`getToken` rejected. The host backend must mint a token via auth.create_embed_session and return { token, expires_at }.",e);return}if(!b(n)){x(a.getTokenFailed,"`getToken` resolved to a malformed value. Expected { token: string, expires_at: string }.");return}if(t)return;let i={token:n.token,expires_at:n.expires_at};S(r.setToken,i),N()},w=t=>{S(r.navigate,{route:f(e.declarionOrigin,t)})},T=()=>{if(l=!0,P(),g(`<- iframe ready`),e.onEvent?.({type:r.ready}),C(),h!==null){let e=h;h=null,w(e)}},E=()=>{g(`<- iframe token-expired`),e.onEvent?.({type:r.tokenExpired}),C()},D=t=>{g(`<- iframe reload-required`,t),e.onEvent?.({type:r.reloadRequired,payload:t}),x(a.reloadRequired,`The embedded iframe requested a reload: ${t.reason}. Reload the iframe to recover.`)},O=t=>{g(`<- iframe resized`,t),!e.height&&n&&Number.isFinite(t.height)&&t.height>0&&(n.style.height=`${t.height}px`),e.onEvent?.({type:r.resized,payload:t})},k=t=>{g(`<- iframe dirty-changed`,t),e.onEvent?.({type:r.dirtyChanged,payload:t})},A=(t,n)=>{g(`<- iframe ${t}`,n),e.onEvent?.({type:t,payload:n});let i={mode:t===r.navigated?`self`:`delegated`,route:n.route,screenCode:n.screenCode,entity:n.entity,recordId:n.recordId};e.onNavigate?.(i)},j=new Set([`not_found`,`unresolved`]),M=t=>{if(typeof t?.route!=`string`||t.route.length===0||!j.has(t.reason)){g(`<- iframe navigation-failed (dropped: invalid payload)`,t);return}g(`<- iframe navigation-failed`,t),e.onEvent?.({type:r.navigationFailed,payload:t}),e.onNavigationFailed?.(t)},N=()=>{u||(u=!0,g(`handshake complete - iframe authenticated`),e.onReady?.())},P=()=>{c!==null&&(clearTimeout(c),c=null)},F=t=>{if(!n||t.source!==n.contentWindow)return;let a=i(t,e.declarionOrigin);if(a.kind===`rejected`)return;if(a.kind===`protocol-mismatch`){console.warn(`${v} protocol version mismatch: this SDK speaks protocol 1, the iframe reported protocol ${String(a.received)}. Update @declarion/embed and the Declarion deployment to matching versions.`);return}let{message:o}=a;switch(o.type){case r.ready:T();break;case r.tokenExpired:E();break;case r.reloadRequired:D(o.payload);break;case r.resized:O(o.payload);break;case r.navigated:A(r.navigated,o.payload);break;case r.navigationRequested:A(r.navigationRequested,o.payload);break;case r.dirtyChanged:k(o.payload);break;case r.navigationFailed:M(o.payload)}},I=y(e);if(I)return console.error(`${v} ${I.message}`),e.onError?.(I),{navigate:()=>void 0,setTheme:()=>void 0,destroy:()=>void 0};let L=e.navigation??`self`,R=window.location.origin,z;try{z=d({declarionOrigin:e.declarionOrigin,route:e.route,parentOrigin:R,navigation:L,theme:e.theme})}catch(t){return x(a.invalidOptions,`Could not build the iframe URL from route "${e.route}". \`route\` must be a valid Declarion screen route.`,t),{navigate:()=>void 0,setTheme:()=>void 0,destroy:()=>void 0}}return n=document.createElement(`iframe`),n.src=z,n.title=e.title??m,n.setAttribute(`sandbox`,_(e.extraSandbox)),n.style.width=`100%`,n.style.border=`0`,n.style.display=`block`,e.height?n.style.height=e.height:n.style.height||(n.style.height=`150px`),s=F,window.addEventListener(`message`,s),e.container.appendChild(n),g(`iframe created`,{src:z}),c=setTimeout(()=>{c=null,!l&&x(a.handshakeTimeout,`No handshake from the iframe within ${p}ms. Check that \`declarionOrigin\` exactly matches the Declarion deployment origin, that the host origin is allow-listed in the deployment's DECLARION_FRAME_ANCESTORS, and that \`route\` resolves to a real screen.`)},p),{navigate(e){if(!t){if(!l){h=e;return}w(e)}},setTheme(e){t||S(r.setTheme,{theme:e})},destroy(){t||(t=!0,P(),s&&=(window.removeEventListener(`message`,s),null),n?.parentNode&&n.parentNode.removeChild(n),n=null,g(`embed destroyed`))}}}return e.EMBED_ERROR_CODES=a,e.EMBED_MESSAGE_SOURCE=t,e.EMBED_MESSAGE_TYPES=r,e.EMBED_PROTOCOL_VERSION=n,e.EmbedError=o,e.createDeclarionEmbed=x,e})({});
|
package/dist/react.js
CHANGED
|
@@ -13,7 +13,9 @@ function c(e) {
|
|
|
13
13
|
}
|
|
14
14
|
function l(e, t) {
|
|
15
15
|
let { className: r, style: l } = e, u = o(null), d = o(null), f = o(e);
|
|
16
|
-
f.current = e
|
|
16
|
+
f.current = e;
|
|
17
|
+
let p = c(e);
|
|
18
|
+
i(() => {
|
|
17
19
|
let e = u.current;
|
|
18
20
|
if (!e) return;
|
|
19
21
|
let t = n({
|
|
@@ -36,11 +38,11 @@ function l(e, t) {
|
|
|
36
38
|
return d.current = t, () => {
|
|
37
39
|
t.destroy(), d.current = null;
|
|
38
40
|
};
|
|
39
|
-
}, [
|
|
40
|
-
let
|
|
41
|
+
}, [p]);
|
|
42
|
+
let m = o(!0);
|
|
41
43
|
return i(() => {
|
|
42
|
-
if (
|
|
43
|
-
|
|
44
|
+
if (m.current) {
|
|
45
|
+
m.current = !1;
|
|
44
46
|
return;
|
|
45
47
|
}
|
|
46
48
|
d.current?.navigate(e.route);
|
package/dist/server.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@declarion/embed",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.47.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Host integration SDK for embedding Declarion screens as white-label iframes.",
|
|
@@ -50,17 +50,17 @@
|
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@testing-library/jest-dom": "^7.0.0",
|
|
52
52
|
"@testing-library/react": "^16.3.2",
|
|
53
|
-
"@types/react": "^19.2.
|
|
54
|
-
"@types/react-dom": "^19.2.
|
|
55
|
-
"@vitejs/plugin-react": "^6.0.
|
|
56
|
-
"eslint": "^10.8.
|
|
53
|
+
"@types/react": "^19.2.18",
|
|
54
|
+
"@types/react-dom": "^19.2.4",
|
|
55
|
+
"@vitejs/plugin-react": "^6.0.5",
|
|
56
|
+
"eslint": "^10.8.1",
|
|
57
57
|
"jsdom": "^29.1.1",
|
|
58
|
-
"publint": "^0.3.
|
|
58
|
+
"publint": "^0.3.23",
|
|
59
59
|
"react": "^19.2.8",
|
|
60
60
|
"react-dom": "^19.2.8",
|
|
61
61
|
"typescript": "^6.0.3",
|
|
62
|
-
"typescript-eslint": "^8.
|
|
63
|
-
"vite": "^8.1
|
|
62
|
+
"typescript-eslint": "^8.66.0",
|
|
63
|
+
"vite": "^8.2.1",
|
|
64
64
|
"vitest": "^4.1.10"
|
|
65
65
|
},
|
|
66
66
|
"scripts": {
|