@machinemetrics/mm-react-embeddable 2.0.0 → 2.0.1-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/README.md CHANGED
@@ -23,5 +23,5 @@ the app and where it runs; footer Cancel/Approve; checkbox rows when several app
23
23
  pending; legacy rows keep their own Authorize button because a popup must open from
24
24
  the user's click on that row).
25
25
 
26
- Removed in 2.0: `EmbeddedAuthorizationPrompt`, the old default popup prompt. Its only
27
- consumer (the playground) now renders its own modal.
26
+ A host without a `credentialBroker`, or a broker answer the host may not act on, gets an
27
+ interactive entry, and the host's UI opens the popup for it.
@@ -1,9 +1,9 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),ke=require("prop-types"),Ce=require("styled-components"),re=n=>n&&n.__esModule?n:{default:n},A=re(t),E=re(ke),oe=re(Ce),G=t.createContext(null),Y=t.createContext({pending:[],authorize:()=>{},approve:()=>{},complete:()=>{},dismiss:()=>{},originEpochs:{},credentials:{},unsupported:{}}),ae="access_token",ee=n=>n?n.kind?n:n.accessToken?{kind:ae,accessToken:n.accessToken,expiresAt:n.expiresAt||null}:null:null,Te=60,we=120,_e=new Set(["host_not_allowed","unbound_host_bound_guest","invalid_token","provider_unavailable"]),J=typeof window!="undefined"&&window.location.protocol==="https:",Ie=8e3,Q=n=>{try{return new URL(n).origin}catch{return null}},ue=(n,o)=>{const i=o==null?void 0:o.origin;return!i||Q(n==null?void 0:n.authUrl)!==i?null:i},ce=n=>{if(!n||/^\d{1,3}(?:\.\d{1,3}){3}$/.test(n)||n.includes(":"))return n;const o=n.split(".");return o.length<=2?n:o.slice(-2).join(".")},te=(n,o)=>{try{const i=new URL(n),f=new URL(o);return i.protocol!==f.protocol?!0:ce(i.hostname)!==ce(f.hostname)}catch{return!0}},le=(n,{onBlocked:o,onClosed:i})=>{const f=window.open(n.authUrl,"mm-embed-auth","popup,width=600,height=700");if(!f)return o(),()=>{};const p=setInterval(()=>{f.closed&&(clearInterval(p),i())},1e3);return()=>clearInterval(p)},de=({children:n,launcher:o,broker:i})=>{const f=t.useContext(G),[p,h]=t.useState({}),[y,P]=t.useState({}),[q,B]=t.useState({}),[k,U]=t.useState({}),x=t.useRef(q);x.current=q;const w=t.useRef(p);w.current=p;const L=t.useRef(null),W=t.useRef({}),m=t.useRef({}),H=t.useRef({}),j=t.useRef(i);j.current=i;const _=t.useCallback(e=>{const r=m.current[e];if(!r)return;const s=c=>!c[e]||c[e].clientId?c:{...c,[e]:{...c[e],clientId:r}};h(s),U(s)},[]),I=t.useCallback((e,r)=>{e&&(U(s=>s[e]?s:{...s,[e]:{origin:e,reason:r,clientId:m.current[e]||null}}),_(e))},[_]),z=t.useCallback((e,{v2:r=!1,origin:s=null}={})=>{s&&(r&&x.current[s]||(h(c=>c[s]?c:{...c,[s]:{origin:s,authUrl:e.authUrl,silentUrl:e.silentUrl||null,status:r&&j.current?"broker":r&&e.silentUrl&&J?"silent":"interactive",v2:r,scope:e.scope||null,acceptsCredentials:H.current[s]||null,consent:null,error:null,clientId:e.clientId||m.current[s]||null,popupBlocked:!1}}),_(s)))},[_]),M=t.useRef({}),l=t.useCallback(e=>{M.current[e]&&(clearTimeout(M.current[e]),delete M.current[e])},[]),a=t.useCallback(e=>{l(e),h(r=>{if(!r[e])return r;const s={...r};return delete s[e],s})},[l]),u=t.useCallback(e=>{e&&(a(e),P(r=>({...r,[e]:(r[e]||0)+1})))},[a]),d=t.useCallback(e=>{h(r=>!r[e]||r[e].status==="interactive"?r:{...r,[e]:{...r[e],status:"interactive"}})},[]),R=t.useCallback(e=>{a(e.origin)},[a]),b=t.useCallback((e,r)=>{const s=ue(e,r);if(s){if(te(s,window.location.origin)){I(s,"cross-site-legacy");return}z(e,{origin:s})}},[z,I]);t.useEffect(()=>{if(!f)return;const e=[f.addListener("*","init",(r,s)=>{s!=null&&s.origin&&(r!=null&&r.clientId)&&(m.current[s.origin]=r.clientId,_(s.origin)),s!=null&&s.origin&&Array.isArray(r==null?void 0:r.acceptsCredentials)?H.current[s.origin]=r.acceptsCredentials:s!=null&&s.origin&&te(s.origin,window.location.origin)&&I(s.origin,"cross-site-legacy")}),f.addListener("*","authorize",b),f.addListener("*","login",b),f.addListener("*","credential-request",(r,s)=>z(r,{v2:!0,origin:ue(r,s)}))];return()=>e.forEach(r=>r())},[f,b,z,_,I]),t.useEffect(()=>{const e=r=>{const s=r==null?void 0:r.data;if(!s||s.type!=="authorized"&&s.type!=="authorize-failed")return;const c=Q(s.authUrl);if(!(!c||r.origin!==c)){if(s.type==="authorized"){if(s.accessToken){if(!w.current[c])return;B(T=>({...T,[c]:ee({accessToken:s.accessToken})})),a(c)}else u(c);return}d(c)}};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[a,u,d]);const O=t.useCallback((e,r)=>{const s=e==null?void 0:e.origin,c=ee(r);!s||!c||(B(T=>({...T,[s]:c})),a(s))},[a]),g=t.useCallback((e,r)=>{h(s=>s[e]?{...s,[e]:{...s[e],...r}}:s)},[]),C=t.useRef({}),S=t.useCallback(async(e,{approve:r}={})=>{const s=j.current,{origin:c}=e;let T;try{T=await s({origin:c,clientId:e.clientId,scope:e.scope,authUrl:e.authUrl},{approve:r})}catch{r?g(c,{error:{reason:"broker_unavailable"}}):g(c,{status:e.silentUrl&&J?"silent":"interactive"});return}const se=T==null?void 0:T.status,v=(T==null?void 0:T.body)||{};if(se===200&&v.credential){O(e,v.credential);return}if(se===409&&v.consentRequired){g(c,{status:"interactive",consent:{client:v.client||null,stepUp:!!v.stepUp,scope:v.scope||e.scope},error:null});return}const V=v.error||"broker_error";if(!r&&_e.has(V)){g(c,{status:e.silentUrl&&J?"silent":"interactive"});return}if(r&&V==="consent_denied"){g(c,{error:null});return}if(V==="rate_limited"&&!e.rateLimitRetried){const X=Math.min(Number(v.retryAfter)>0?Number(v.retryAfter):Te,we),Re={...e,rateLimitRetried:!0};l(c),M.current[c]=setTimeout(()=>{delete M.current[c],C.current[c]=!0,D.current(Re,{approve:r}).finally(()=>{delete C.current[c]})},X*1e3),g(c,{rateLimitRetried:!0});return}a(c),U(X=>({...X,[c]:{origin:c,reason:`broker:${V}`,detail:T||null,clientId:e.clientId||m.current[c]||null}}))},[O,g,a,l]),D=t.useRef(S);D.current=S,t.useEffect(()=>{Object.values(p).forEach(e=>{e.status!=="broker"||C.current[e.origin]||M.current[e.origin]||(C.current[e.origin]=!0,S(e).finally(()=>{delete C.current[e.origin]}))})},[p,S]);const K=t.useCallback(e=>!j.current||!(e!=null&&e.consent)?Promise.resolve():S(e,{approve:!0}),[S]);t.useEffect(()=>{const e=W.current;Object.values(p).forEach(r=>{r.status==="silent"&&!e[r.origin]&&(e[r.origin]=setTimeout(()=>{delete e[r.origin],d(r.origin)},Ie))}),Object.keys(e).forEach(r=>{(!p[r]||p[r].status!=="silent")&&(clearTimeout(e[r]),delete e[r])})},[p,d]),t.useEffect(()=>()=>{L.current&&L.current(),Object.values(W.current).forEach(clearTimeout),Object.values(M.current).forEach(clearTimeout)},[]);const Z=t.useCallback(e=>{L.current&&(L.current(),L.current=null);const r=o||le;L.current=r(e,{onBlocked:()=>{h(s=>s[e.origin]?{...s,[e.origin]:{...s[e.origin],popupBlocked:!0}}:s)},onClosed:()=>{if(e.v2){J&&h(s=>!s[e.origin]||!s[e.origin].silentUrl?s:{...s,[e.origin]:{...s[e.origin],status:"silent"}});return}u(e.origin)}})},[o,u]),$={pending:Object.values(p).filter(e=>e.status==="interactive"),authorize:Z,approve:K,complete:O,dismiss:R,originEpochs:y,credentials:q,unsupported:k},F=Object.values(p).filter(e=>e.status==="silent"&&e.silentUrl);return A.default.createElement(Y.Provider,{value:$},n,F.map(e=>A.default.createElement("iframe",{key:`mm-silent-auth-${e.origin}`,src:e.silentUrl,title:`MachineMetrics silent authorization (${e.origin})`,"aria-hidden":"true",tabIndex:-1,style:{display:"none"}})))};de.propTypes={children:E.default.node,launcher:E.default.func,broker:E.default.func};const Me=()=>t.useContext(Y),fe=n=>{const{originEpochs:o}=t.useContext(Y),i=Q(n);return i&&o[i]||0},pe=n=>{const{credentials:o}=t.useContext(Y),i=Q(n);return i&&o[i]||null},be=n=>{const{unsupported:o}=t.useContext(Y),i=Q(n);return i&&o[i]||null},ie="MMEmbeddableZoneProvider requires a boolean `ready` prop (true once the host holds the bearer its credentialBroker needs). Embedded apps will not load until it is provided.",he=({children:n,authorizationLauncher:o,credentialBroker:i,ready:f})=>{const p=f===!0,h=t.useRef(!1);t.useEffect(()=>{f!==void 0||h.current||(h.current=!0,console.error(ie),typeof window!="undefined"&&typeof window.alert=="function"&&window.alert(ie))},[f]);const[y,P]=t.useState({}),[q,B]=t.useState({}),k=t.useRef({}),U=t.useRef({}),x=t.useRef({}),w=t.useCallback((l,a)=>{var u;return!!((u=x.current[l])!=null&&u.has(a))},[]),L=t.useCallback((l,a,u)=>{P(d=>({...d,[l]:{origin:a,frameRef:u}}))},[]),W=t.useCallback(l=>{P(a=>{const u={...a};return delete u[l],u}),B(a=>{const u={...a};return delete u[l],u}),delete x.current[l]},[]);t.useEffect(()=>{const l=(u=[],d,R)=>{u.forEach(b=>b(d,R))},a=u=>{var S,D,K,Z,$,F,e;if(!((S=u==null?void 0:u.data)!=null&&S.instanceId))return;const{instanceId:d,type:R}=u.data,b=y[d],O=(K=(D=b==null?void 0:b.frameRef)==null?void 0:D.current)==null?void 0:K.contentWindow;if(!O||u.source!==O||u.origin!==b.origin)return;const g={origin:u.origin},C=k.current;if(R==="response"){const{callbackId:r,response:s,error:c}=u.data,T=U.current[r];T&&(T(s,c),delete U.current[r]);return}if(R==="mark-registered"){const{requestType:r}=u.data;x.current[d]||(x.current[d]=new Set),x.current[d].add(r);return}R==="ready"&&B(r=>({...r,[d]:!0})),l((Z=C[d])==null?void 0:Z[R],u.data,g),l(($=C["*"])==null?void 0:$[R],u.data,g),l((F=C[d])==null?void 0:F["*"],u.data,g),l((e=C["*"])==null?void 0:e["*"],u.data,g)};return window.addEventListener("message",a),()=>{window.removeEventListener("message",a)}},[y]);const m=t.useCallback((l,a,u)=>{var R,b;const d=y[l];if(!d){console.warn(`Origin not set for id: ${l}. Unable to send message.`);return}(b=(R=d==null?void 0:d.frameRef)==null?void 0:R.current)!=null&&b.contentWindow&&d.frameRef.current.contentWindow.postMessage({type:a,...u,instanceId:l},d.origin)},[y]),H=t.useRef(0),j=t.useCallback(()=>`${Date.now()}-${++H.current}`,[]),_=t.useCallback(async(l,a,u={})=>new Promise((d,R)=>{const b=j(),O=(g,C)=>{delete U.current[b],C?R(C):d(g)};U.current[b]=O,m(l,"request",{callbackId:b,requestType:a,data:u})}),[m]),I=t.useCallback((l,a)=>{m(l,"load-options",a)},[m]),z=t.useCallback((l,a)=>{m(l,"validate",a)},[m]),M=t.useMemo(()=>({registerFrame:L,unregisterFrame:W,sendMessage:m,sendRequest:_,loadOptions:I,validate:z,hasHandler:w,readyFrames:q,ready:p,addListener:(l,a,u)=>(k.current[l]||(k.current[l]={}),k.current[l][a]||(k.current[l][a]=[]),k.current[l][a].push(u),()=>{k.current[l][a]=k.current[l][a].filter(d=>d!==u)})}),[L,W,m,_,I,z,w,q,p]);return A.default.createElement(G.Provider,{value:M},A.default.createElement(de,{launcher:o,broker:i},n))},N=(n,o,i)=>{const f=t.useContext(G);if(f===null)throw new Error("useEmbeddedEffect must be used within a MMEmbeddableZoneProvider");const p=t.useRef(i);t.useEffect(()=>{p.current=i},[i]),t.useEffect(()=>{if(!(!n||!o)){if(o.startsWith("key:")){const h=o.substring(4);return f.readyFrames[n]&&f.sendMessage(n,"subscribe-key",{keyChord:h}),f.addListener(n,`key-pressed:${h}`,(...P)=>p.current(...P))}return f.addListener(n,o,(...h)=>p.current(...h))}},[f,n,o])};he.propTypes={children:E.default.node.isRequired,ready:E.default.bool.isRequired,authorizationLauncher:E.default.func,credentialBroker:E.default.func};const ne=oe.default.default||oe.default,Se=1e4,Ue="credentials",Le=(n,o)=>`${n}/mm-embedded-interop?id=${encodeURIComponent(o)}&origin=${encodeURIComponent(window.location.origin)}&caps=${Ue}`,Ae=ne.iframe`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),ge=require("prop-types"),me=require("styled-components"),V=r=>r&&r.__esModule?r:{default:r},O=V(e),k=V(ge),te=V(me),Q=e.createContext(null),Y=e.createContext({pending:[],authorize:()=>{},approve:()=>{},complete:()=>{},dismiss:()=>{},originEpochs:{},credentials:{},unsupported:{}}),oe="access_token",J=r=>r?r.kind?r:r.accessToken?{kind:oe,accessToken:r.accessToken,expiresAt:r.expiresAt||null}:null:null,Ee=60,Re=120,ke=new Set(["host_not_allowed","unbound_host_bound_guest","invalid_token","provider_unavailable"]),G=r=>{try{return new URL(r).origin}catch{return null}},re=(r,o)=>{const i=o==null?void 0:o.origin;return!i||G(r==null?void 0:r.authUrl)!==i?null:i},ne=r=>{if(!r||/^\d{1,3}(?:\.\d{1,3}){3}$/.test(r)||r.includes(":"))return r;const o=r.split(".");return o.length<=2?r:o.slice(-2).join(".")},N=(r,o)=>{try{const i=new URL(r),d=new URL(o);return i.protocol!==d.protocol?!0:ne(i.hostname)!==ne(d.hostname)}catch{return!0}},ue=(r,{onBlocked:o,onClosed:i})=>{const d=window.open(r.authUrl,"mm-embed-auth","popup,width=600,height=700");if(!d)return o(),()=>{};const R=setInterval(()=>{d.closed&&(clearInterval(R),i())},1e3);return()=>clearInterval(R)},ce=({children:r,launcher:o,broker:i})=>{const d=e.useContext(Q),[R,C]=e.useState({}),[$,v]=e.useState({}),[D,Z]=e.useState({}),[I,E]=e.useState({}),S=e.useRef(D);S.current=D;const W=e.useRef(R);W.current=R;const w=e.useRef(null),x=e.useRef({}),y=e.useRef({}),P=e.useRef(i);P.current=i;const U=e.useCallback(t=>{const s=x.current[t];if(!s)return;const n=c=>!c[t]||c[t].clientId?c:{...c,[t]:{...c[t],clientId:s}};C(n),E(n)},[]),F=e.useCallback((t,s)=>{t&&(E(n=>n[t]?n:{...n,[t]:{origin:t,reason:s,clientId:x.current[t]||null}}),U(t))},[U]),A=e.useCallback((t,{v2:s=!1,origin:n=null}={})=>{n&&(s&&S.current[n]||(C(c=>c[n]?c:{...c,[n]:{origin:n,authUrl:t.authUrl,status:s&&P.current?"broker":"interactive",v2:s,scope:t.scope||null,acceptsCredentials:y.current[n]||null,consent:null,error:null,clientId:t.clientId||x.current[n]||null,popupBlocked:!1}}),U(n)))},[U]),T=e.useRef({}),q=e.useCallback(t=>{T.current[t]&&(clearTimeout(T.current[t]),delete T.current[t])},[]),u=e.useCallback(t=>{q(t),C(s=>{if(!s[t])return s;const n={...s};return delete n[t],n})},[q]),l=e.useCallback(t=>{t&&(u(t),v(s=>({...s,[t]:(s[t]||0)+1})))},[u]),a=e.useCallback(t=>{u(t.origin)},[u]),p=e.useCallback((t,s)=>{const n=re(t,s);if(n){if(N(n,window.location.origin)){F(n,"cross-site-legacy");return}A(t,{origin:n})}},[A,F]);e.useEffect(()=>{if(!d)return;const t=[d.addListener("*","init",(s,n)=>{n!=null&&n.origin&&(s!=null&&s.clientId)&&(x.current[n.origin]=s.clientId,U(n.origin)),n!=null&&n.origin&&Array.isArray(s==null?void 0:s.acceptsCredentials)?y.current[n.origin]=s.acceptsCredentials:n!=null&&n.origin&&N(n.origin,window.location.origin)&&F(n.origin,"cross-site-legacy")}),d.addListener("*","authorize",p),d.addListener("*","login",p),d.addListener("*","credential-request",(s,n)=>A(s,{v2:!0,origin:re(s,n)}))];return()=>t.forEach(s=>s())},[d,p,A,U,F]),e.useEffect(()=>{const t=s=>{const n=s==null?void 0:s.data;if(!n||n.type!=="authorized")return;const c=G(n.authUrl);if(!c||s.origin!==c)return;const b=W.current[c];if(!(!b||b.status!=="interactive")){if(n.accessToken){Z(L=>({...L,[c]:J({accessToken:n.accessToken})})),u(c);return}l(c)}};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)},[u,l]);const h=e.useCallback((t,s)=>{const n=t==null?void 0:t.origin,c=J(s);!n||!c||(Z(b=>({...b,[n]:c})),u(n))},[u]),g=e.useCallback((t,s)=>{C(n=>n[t]?{...n,[t]:{...n[t],...s}}:n)},[]),m=e.useRef({}),_=e.useCallback(async(t,{approve:s}={})=>{const n=P.current,{origin:c}=t;let b;try{b=await n({origin:c,clientId:t.clientId,scope:t.scope,authUrl:t.authUrl},{approve:s})}catch{s?g(c,{error:{reason:"broker_unavailable"}}):g(c,{status:"interactive"});return}const L=b==null?void 0:b.status,f=(b==null?void 0:b.body)||{};if(L===200&&f.credential){h(t,f.credential);return}if(L===409&&f.consentRequired){g(c,{status:"interactive",consent:{client:f.client||null,stepUp:!!f.stepUp,scope:f.scope||t.scope},error:null});return}const z=f.error||"broker_error";if(!s&&ke.has(z)){g(c,{status:"interactive"});return}if(s&&z==="consent_denied"){g(c,{error:null});return}if(z==="rate_limited"&&!t.rateLimitRetried){const X=Math.min(Number(f.retryAfter)>0?Number(f.retryAfter):Ee,Re),he={...t,rateLimitRetried:!0};q(c),T.current[c]=setTimeout(()=>{delete T.current[c],m.current[c]=!0,M.current(he,{approve:s}).finally(()=>{delete m.current[c]})},X*1e3),g(c,{rateLimitRetried:!0});return}u(c),E(X=>({...X,[c]:{origin:c,reason:`broker:${z}`,detail:{status:L!=null?L:null,reason:z},clientId:t.clientId||x.current[c]||null}}))},[h,g,u,q]),M=e.useRef(_);M.current=_,e.useEffect(()=>{Object.values(R).forEach(t=>{t.status!=="broker"||m.current[t.origin]||T.current[t.origin]||(m.current[t.origin]=!0,_(t).finally(()=>{delete m.current[t.origin]}))})},[R,_]);const K=e.useCallback(t=>!P.current||!(t!=null&&t.consent)||m.current[t.origin]?Promise.resolve():(m.current[t.origin]=!0,_(t,{approve:!0}).finally(()=>{delete m.current[t.origin]})),[_]);e.useEffect(()=>()=>{w.current&&w.current(),Object.values(T.current).forEach(clearTimeout)},[]);const B=e.useCallback(t=>{w.current&&(w.current(),w.current=null);const s=o||ue;w.current=s(t,{onBlocked:()=>{C(n=>n[t.origin]?{...n,[t.origin]:{...n[t.origin],popupBlocked:!0}}:n)},onClosed:()=>l(t.origin)})},[o,l]),j={pending:Object.values(R).filter(t=>t.status==="interactive"),authorize:B,approve:K,complete:h,dismiss:a,originEpochs:$,credentials:D,unsupported:I};return O.default.createElement(Y.Provider,{value:j},r)};ce.propTypes={children:k.default.node,launcher:k.default.func,broker:k.default.func};const Ce=()=>e.useContext(Y),ie=r=>{const{originEpochs:o}=e.useContext(Y),i=G(r);return i&&o[i]||0},ae=r=>{const{credentials:o}=e.useContext(Y),i=G(r);return i&&o[i]||null},le=r=>{const{unsupported:o}=e.useContext(Y),i=G(r);return i&&o[i]||null},se="MMEmbeddableZoneProvider requires a boolean `ready` prop (true once the host holds the bearer its credentialBroker needs). Embedded apps will not load until it is provided.",de=({children:r,authorizationLauncher:o,credentialBroker:i,ready:d})=>{const R=d===!0,C=e.useRef(!1);e.useEffect(()=>{d!==void 0||C.current||(C.current=!0,console.error(se),typeof window!="undefined"&&typeof window.alert=="function"&&window.alert(se))},[d]);const[$,v]=e.useState({}),[D,Z]=e.useState({}),I=e.useRef({}),E=e.useRef({}),S=e.useRef({}),W=e.useCallback((u,l)=>{var a;return!!((a=S.current[u])!=null&&a.has(l))},[]),w=e.useCallback((u,l,a)=>{v(p=>({...p,[u]:{origin:l,frameRef:a}}))},[]),x=e.useCallback(u=>{v(l=>{const a={...l};return delete a[u],a}),Z(l=>{const a={...l};return delete a[u],a}),delete S.current[u],Object.keys(E.current).forEach(l=>{E.current[l].instanceId===u&&delete E.current[l]})},[]);e.useEffect(()=>()=>{E.current={}},[]),e.useEffect(()=>{const u=(a=[],p,h)=>{a.forEach(g=>g(p,h))},l=a=>{var K,B,j,t,s,n,c;if(!((K=a==null?void 0:a.data)!=null&&K.instanceId))return;const{instanceId:p,type:h}=a.data,g=$[p],m=(j=(B=g==null?void 0:g.frameRef)==null?void 0:B.current)==null?void 0:j.contentWindow;if(!m||a.source!==m||a.origin!==g.origin)return;const _={origin:a.origin},M=I.current;if(h==="response"){const{callbackId:b,response:L,error:f}=a.data,z=E.current[b];z&&z.instanceId===p&&(z.callback(L,f),delete E.current[b]);return}if(h==="mark-registered"){const{requestType:b}=a.data;S.current[p]||(S.current[p]=new Set),S.current[p].add(b);return}h==="ready"&&Z(b=>({...b,[p]:!0})),u((t=M[p])==null?void 0:t[h],a.data,_),u((s=M["*"])==null?void 0:s[h],a.data,_),u((n=M[p])==null?void 0:n["*"],a.data,_),u((c=M["*"])==null?void 0:c["*"],a.data,_)};return window.addEventListener("message",l),()=>{window.removeEventListener("message",l)}},[$]);const y=e.useCallback((u,l,a,p)=>{var g,m;const h=$[u];if(!h){console.warn(`Origin not set for id: ${u}. Unable to send message.`);return}(m=(g=h==null?void 0:h.frameRef)==null?void 0:g.current)!=null&&m.contentWindow&&h.frameRef.current.contentWindow.postMessage({type:l,...a,instanceId:u},p||h.origin)},[$]),P=e.useRef(0),U=e.useCallback(()=>`${Date.now()}-${++P.current}`,[]),F=e.useCallback(async(u,l,a={})=>new Promise((p,h)=>{const g=U(),m=(_,M)=>{delete E.current[g],M?h(M):p(_)};E.current[g]={instanceId:u,callback:m},y(u,"request",{callbackId:g,requestType:l,data:a})}),[y]),A=e.useCallback((u,l)=>{y(u,"load-options",l)},[y]),T=e.useCallback((u,l)=>{y(u,"validate",l)},[y]),q=e.useMemo(()=>({registerFrame:w,unregisterFrame:x,sendMessage:y,sendRequest:F,loadOptions:A,validate:T,hasHandler:W,readyFrames:D,ready:R,addListener:(u,l,a)=>(I.current[u]||(I.current[u]={}),I.current[u][l]||(I.current[u][l]=[]),I.current[u][l].push(a),()=>{I.current[u][l]=I.current[u][l].filter(p=>p!==a)})}),[w,x,y,F,A,T,W,D,R]);return O.default.createElement(Q.Provider,{value:q},O.default.createElement(ce,{launcher:o,broker:i},r))},H=(r,o,i)=>{const d=e.useContext(Q);if(d===null)throw new Error("useEmbeddedEffect must be used within a MMEmbeddableZoneProvider");const R=e.useRef(i);e.useEffect(()=>{R.current=i},[i]),e.useEffect(()=>{if(!(!r||!o)){if(o.startsWith("key:")){const C=o.substring(4);return d.readyFrames[r]&&d.sendMessage(r,"subscribe-key",{keyChord:C}),d.addListener(r,`key-pressed:${C}`,(...v)=>R.current(...v))}return d.addListener(r,o,(...C)=>R.current(...C))}},[d,r,o])};de.propTypes={children:k.default.node.isRequired,ready:k.default.bool.isRequired,authorizationLauncher:k.default.func,credentialBroker:k.default.func};const ee=te.default.default||te.default,we=1e4,Te="credentials",_e=(r,o)=>`${r}/mm-embedded-interop?id=${encodeURIComponent(o)}&origin=${encodeURIComponent(window.location.origin)}&caps=${Te}`,Ie=ee.iframe`
2
2
  width: 100%;
3
3
  height: 100%;
4
4
  border: none;
5
- visibility: ${n=>n.$isReady?"visible":"hidden"};
6
- `,xe=ne.div`
5
+ visibility: ${r=>r.$isReady?"visible":"hidden"};
6
+ `,Me=ee.div`
7
7
  width: 100%;
8
8
  height: 100%;
9
9
  display: flex;
@@ -16,10 +16,10 @@
16
16
  text-align: center;
17
17
  color: #555;
18
18
  font-size: 14px;
19
- `,Ee=n=>{const o=n&&n.origin||"This app",i=n&&n.reason||"";switch(i){case"broker:scope_above_ceiling":return{title:`${o} can’t be authorized here`,detail:"It asks for permissions your role doesn’t have."};case"broker:origin_mismatch":case"broker:unknown_client":return{title:`${o} can’t be authorized here`,detail:"It isn’t registered to run at this address."};case"broker:cross_company_principal":return{title:`${o} can’t be authorized here`,detail:"It can’t be authorized for this account."};default:return i.startsWith("broker:")?{title:`${o} can’t be authorized here`,detail:"Authorization was refused."}:{title:`${o} can’t be embedded here`,detail:"It needs an update to support embedding from a different domain."}}},me=({entry:n})=>{const o=Ee(n);return A.default.createElement(xe,{"data-reason":n&&n.reason||void 0},A.default.createElement("div",{style:{fontWeight:600}},o.title),A.default.createElement("div",{style:{fontSize:12,color:"#888"}},o.detail))};me.propTypes={entry:E.default.shape({origin:E.default.string,name:E.default.string,reason:E.default.string,detail:E.default.object})};const ze=ne.div`
19
+ `,fe=r=>{const o=r&&r.origin||"This app",i=r&&r.reason||"";switch(i){case"broker:scope_above_ceiling":return{title:`${o} can’t be authorized here`,detail:"It asks for permissions your role doesn’t have."};case"broker:origin_mismatch":case"broker:unknown_client":return{title:`${o} can’t be authorized here`,detail:"It isn’t registered to run at this address."};case"broker:cross_company_principal":return{title:`${o} can’t be authorized here`,detail:"It can’t be authorized for this account."};default:return i.startsWith("broker:")?{title:`${o} can’t be authorized here`,detail:"Authorization was refused."}:{title:`${o} can’t be embedded here`,detail:"It needs an update to support embedding from a different domain."}}},pe=({entry:r})=>{const o=fe(r);return O.default.createElement(Me,{"data-reason":r&&r.reason||void 0},O.default.createElement("div",{style:{fontWeight:600}},o.title),O.default.createElement("div",{style:{fontSize:12,color:"#888"}},o.detail))};pe.propTypes={entry:k.default.shape({origin:k.default.string,name:k.default.string,reason:k.default.string,detail:k.default.object})};const ye=ee.div`
20
20
  height: 100%;
21
21
  display: flex;
22
22
  flex: 1;
23
23
  align-items: center;
24
24
  justify-content: center;
25
- `,Oe=()=>A.default.createElement(ze,null,A.default.createElement("div",{style:{textAlign:"center"}},"This app couldn’t be loaded as an embeddable widget.")),ge=({id:n,src:o,path:i,onInit:f=()=>{},onTimeout:p,context:h={},params:y={},renderUnsupported:P,renderTimeout:q,...B})=>{if("isConfiguring"in B)return console.error("isConfiguring must be passed via the params prop to MMEmbeddableZone"),null;if("colorMode"in h)return console.error("colorMode must be passed via the params prop to MMEmbeddableZone"),null;if("isFullScreen"in h)return console.error("isFullScreen must be passed via the params prop to MMEmbeddableZone"),null;const k=t.useRef(),[U,x]=t.useState(),[w,L]=t.useState(0),[W,m]=t.useState(!1),[H,j]=t.useState(!1),_=fe(o),I=pe(o),z=be(o),[M,l]=t.useState(0),[a,u]=t.useState(null),{registerFrame:d,unregisterFrame:R,sendMessage:b,ready:O}=t.useContext(G),[g,C]=t.useState(),S=t.useRef(),D=t.useRef(p),K=t.useRef(f),Z=t.useRef(!1),$=t.useCallback(()=>{Z.current=!1,clearTimeout(S.current),L(0),m(!1),j(!1),u(null)},[]);t.useEffect(()=>{(_>0||M>0)&&$()},[_,M,$]),t.useEffect(()=>{D.current=p},[p]),t.useEffect(()=>{K.current=f},[f]),t.useEffect(()=>{w&&b(n,"set-context",{context:{...h}})},[h,n,w]),t.useEffect(()=>{w&&b(n,"set-params",{params:y})},[y,n,w]),t.useEffect(()=>{i!==void 0&&C((i==null?void 0:i.indexOf("/"))===0?i:`/${i}`)},[i]),t.useEffect(()=>{g===void 0||!w||b(n,"navigate",{path:g})},[g,w,n,b]),t.useEffect(()=>{if(!o||!n||!k)return;if(!O){$(),x(void 0);return}$();const r=new URL(o);return d(n,r.origin,k),K.current(),x(Le(r.origin,n)),()=>{R(n)}},[o,n,O,d,k,$]),t.useEffect(()=>{if(!(!U||Z.current))return S.current=setTimeout(()=>{m(!0),D.current&&D.current()},Se),()=>clearTimeout(S.current)},[U,o,_,M]);const F=t.useCallback(()=>{Z.current=!0,clearTimeout(S.current),m(!1)},[]);N(n,"init",r=>{F(),Array.isArray(r==null?void 0:r.acceptsCredentials)&&u(r.acceptsCredentials)}),N(n,"authorize",F),N(n,"login",F),N(n,"credential-request",()=>{F(),j(!0)}),t.useEffect(()=>{if(!H||!I)return;const r=a;if(Array.isArray(r)&&!r.includes(I.kind))return;const s=I.kind==="access_token"?{accessToken:I.accessToken}:{};b(n,"credential",{...s,credential:I})},[H,I,a,n,b]),N(n,"ready",()=>{F(),L(r=>r+1)});const e=t.useRef();return N(n,"heartbeat",()=>{e.current&&clearTimeout(e.current),e.current=setTimeout(()=>{l(r=>r+1)},6e3)}),t.useEffect(()=>()=>{e.current&&clearTimeout(e.current)},[]),z?P?P(z):A.default.createElement(me,{entry:z}):W&&!w?q?q():A.default.createElement(Oe,null):A.default.createElement(Ae,{key:`auth-epoch-${_}-frame-${M}`,$isReady:w,ref:k,src:U,...B})};ge.propTypes={id:E.default.string,src:E.default.string.isRequired,path:E.default.string,onInit:E.default.func,onTimeout:E.default.func,renderUnsupported:E.default.func,renderTimeout:E.default.func};exports.CREDENTIAL_KIND_ACCESS_TOKEN=ae;exports.EmbeddedAuthorizationContext=Y;exports.MMEmbeddableZone=ge;exports.MMEmbeddableZoneContext=G;exports.MMEmbeddableZoneProvider=he;exports.isCrossSite=te;exports.normalizeCredential=ee;exports.popupAuthorizationLauncher=le;exports.unsupportedCopy=Ee;exports.useEmbeddedAuthorizations=Me;exports.useEmbeddedCredential=pe;exports.useEmbeddedEffect=N;exports.useEmbeddedOriginEpoch=fe;exports.useEmbeddedUnsupported=be;
25
+ `,Se=()=>O.default.createElement(ye,null,O.default.createElement("div",{style:{textAlign:"center"}},"This app couldn’t be loaded as an embeddable widget.")),be=({id:r,src:o,path:i,onInit:d=()=>{},onTimeout:R,context:C={},params:$={},renderUnsupported:v,renderTimeout:D,...Z})=>{if("isConfiguring"in Z)return console.error("isConfiguring must be passed via the params prop to MMEmbeddableZone"),null;if("colorMode"in C)return console.error("colorMode must be passed via the params prop to MMEmbeddableZone"),null;if("isFullScreen"in C)return console.error("isFullScreen must be passed via the params prop to MMEmbeddableZone"),null;const I=e.useRef(),E=G(o),[S,W]=e.useState(),[w,x]=e.useState(0),[y,P]=e.useState(!1),[U,F]=e.useState(!1),A=ie(o),T=ae(o),q=le(o),[u,l]=e.useState(0),[a,p]=e.useState(null),{registerFrame:h,unregisterFrame:g,sendMessage:m,ready:_}=e.useContext(Q),[M,K]=e.useState(),B=e.useRef(),j=e.useRef(R),t=e.useRef(d),s=e.useRef(!1),n=e.useRef(),c=e.useCallback(()=>{s.current=!1,clearTimeout(B.current),clearTimeout(n.current),x(0),P(!1),F(!1),p(null)},[]);e.useEffect(()=>{(A>0||u>0)&&c()},[A,u,c]),e.useEffect(()=>{j.current=R},[R]),e.useEffect(()=>{t.current=d},[d]),e.useEffect(()=>{w&&m(r,"set-context",{context:{...C}},E)},[C,r,w,E]),e.useEffect(()=>{w&&m(r,"set-params",{params:$},E)},[$,r,w,E]),e.useEffect(()=>{i!==void 0&&K((i==null?void 0:i.indexOf("/"))===0?i:`/${i}`)},[i]),e.useEffect(()=>{M===void 0||!w||m(r,"navigate",{path:M},E)},[M,w,r,m,E]),e.useEffect(()=>{if(!o||!r||!I)return;if(!_){c(),W(void 0);return}c();const f=new URL(o);return h(r,f.origin,I),t.current(),W(_e(f.origin,r)),()=>{g(r)}},[o,r,_,h,I,c]),e.useEffect(()=>{if(!(!S||s.current))return B.current=setTimeout(()=>{P(!0),j.current&&j.current()},we),()=>clearTimeout(B.current)},[S,o,A,u]);const b=e.useCallback(()=>{s.current=!0,clearTimeout(B.current),P(!1)},[]);if(H(r,"init",f=>{b(),Array.isArray(f==null?void 0:f.acceptsCredentials)&&p(f.acceptsCredentials)}),H(r,"authorize",b),H(r,"login",b),H(r,"credential-request",()=>{b(),F(!0)}),e.useEffect(()=>{if(!U||!T)return;const f=a;if(Array.isArray(f)&&!f.includes(T.kind))return;const z=T.kind==="access_token"?{accessToken:T.accessToken}:{};m(r,"credential",{...z,credential:T},E)},[U,T,a,r,m,E]),H(r,"ready",()=>{b(),x(f=>f+1)}),H(r,"heartbeat",()=>{n.current&&clearTimeout(n.current),n.current=setTimeout(()=>{l(f=>f+1)},6e3)}),e.useEffect(()=>()=>{n.current&&clearTimeout(n.current)},[]),q)return v?v(q):O.default.createElement(pe,{entry:q});if(y&&!w)return D?D():O.default.createElement(Se,null);const L={...Z};return delete L.skipManifestCheck,O.default.createElement(Ie,{key:`auth-epoch-${A}-frame-${u}`,$isReady:w,ref:I,src:S,...L})};be.propTypes={id:k.default.string,src:k.default.string.isRequired,path:k.default.string,onInit:k.default.func,onTimeout:k.default.func,renderUnsupported:k.default.func,renderTimeout:k.default.func};exports.CREDENTIAL_KIND_ACCESS_TOKEN=oe;exports.EmbeddedAuthorizationContext=Y;exports.MMEmbeddableZone=be;exports.MMEmbeddableZoneContext=Q;exports.MMEmbeddableZoneProvider=de;exports.isCrossSite=N;exports.normalizeCredential=J;exports.popupAuthorizationLauncher=ue;exports.unsupportedCopy=fe;exports.useEmbeddedAuthorizations=Ce;exports.useEmbeddedCredential=ae;exports.useEmbeddedEffect=H;exports.useEmbeddedOriginEpoch=ie;exports.useEmbeddedUnsupported=le;