New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@uniformdev/mesh-sdk

Package Overview
Dependencies
Maintainers
9
Versions
711
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@uniformdev/mesh-sdk - npm Package Compare versions

Comparing version

to
16.0.1-alpha.164

10

dist/index.d.ts

@@ -64,2 +64,7 @@ interface ContextData {

declare type CSSHeight = '-moz-initial' | 'inherit' | 'initial' | 'revert' | 'unset' | '-moz-max-content' | '-moz-min-content' | '-webkit-fit-content' | 'auto' | 'fit-content' | 'max-content' | 'min-content' | `${number}${'px' | 'em' | 'rem' | 'vh'}`;
declare type SetValueOptions = Pick<ValidationResult, 'isValid' | 'validationMessage'>;
interface ValidationResult {
isValid?: boolean;
validationMessage?: string;
}

@@ -127,4 +132,5 @@ interface SdkWindow {

getValue: () => TValue;
setValue: (value: TSetValue) => Promise<void>;
setValue: (value: TSetValue, options?: SetValueOptions) => Promise<void>;
getMetadata: () => TMetadata;
setValidationResult: (value: ValidationResult) => Promise<void>;
}

@@ -139,2 +145,2 @@ /**

export { CSSHeight, ContextData, DialogContext, DialogOptions, DialogParamValue, DialogParams, DialogResponseData, DialogResponseHandler, DialogResponseHandlers, DialogType, LocationDialogResponse, MeshLocation, SdkWindow, UniformMeshSDK, initializeUniformMeshSDK };
export { CSSHeight, ContextData, DialogContext, DialogOptions, DialogParamValue, DialogParams, DialogResponseData, DialogResponseHandler, DialogResponseHandlers, DialogType, LocationDialogResponse, MeshLocation, SdkWindow, SetValueOptions, UniformMeshSDK, ValidationResult, initializeUniformMeshSDK };

2

dist/index.esm.js

@@ -1,1 +0,1 @@

var R=(n,e)=>e?{log(o,...t){return console.log(`${n}: ${o}`,...t)},error(o,...t){return console.error(`${n}: ${o}`,...t)}}:{log(){},error(){}};var T=5e3;var c=class extends Error{constructor(){super("Request timed out"),Object.setPrototypeOf(this,c.prototype),this.name="RequestTimeoutError"}},u=class extends Error{constructor(){super("Client destroyed"),Object.setPrototypeOf(this,u.prototype),this.name="ClientDestroyedError"}};var b=()=>{let n=()=>{},e=()=>{},o=new Promise((t,i)=>{n=t,e=i});return{resolve:n,reject:e,promise:o}},m=(n=16)=>[...Array(n)].map(()=>(~~(Math.random()*36)).toString(36)).join(""),h=(n,e)=>{let{[e]:o,...t}=n;return t},k=n=>({message:n.message,name:n.name,stack:n.stack}),L=({name:n,message:e,stack:o})=>{switch(n){case c.name:return new c;default:{let t=new Error(e);return t.name=n,t.stack=o,t}}},E=n=>{let e=n.data,o="none";return e instanceof Error&&(o="error",e=k(e)),{...n,serialization:o,data:e}},v=n=>n.serialization==="error"?{...n,data:L(n.data)}:n;var f=class{constructor({debug:e=!1,requestTimeout:o=T}={}){this.debug=e,this.requestTimeout=o,this.channel=b(),this.eventSubscriptions={},this.responseSubscriptions={},this.requestSubscriptions={},this.onDestroyRequestHandlers={},this.destroyed=!1,this.logger=this.getLogger(),this.getChannel().then(()=>{this.logger.log("Secure parent <-> child channel established")}).catch(t=>{this.logger.log(t)})}async send(e,o){return this.postMessage("event",e,o)}on(e,o){this.eventSubscriptions[e]||(this.eventSubscriptions[e]={});let t=m(8);return this.eventSubscriptions[e][t]=o,this.logger.log(`Registered handler for event "${e}"`),()=>{this.eventSubscriptions[e]=h(this.eventSubscriptions[e],t),this.logger.log(`Unsubscribed handler for event ${e}`)}}async request(e,o,t={}){let a=(await this.postMessage("request",e,o)).id,s=()=>{this.responseSubscriptions=h(this.responseSubscriptions,a)},r=()=>{this.onDestroyRequestHandlers=h(this.responseSubscriptions,a)};return new Promise((l,p)=>{let D,x=(S,O)=>{clearTimeout(D),s(),r(),O.type==="error_response"?p(S):l(S)},I=()=>{clearTimeout(D),p(new u)};this.responseSubscriptions[a]=x,this.onDestroyRequestHandlers[a]=I,D=setTimeout(()=>{s(),r(),p(new c)},t.timeout||this.requestTimeout)})}onRequest(e,o){let t=async(i,a)=>{try{let s=await o(i,a);this.postMessage("response",e,s,a.id)}catch(s){this.postMessage("error_response",e,s,a.id)}};return this.requestSubscriptions[e]=t,()=>{this.requestSubscriptions=h(this.requestSubscriptions,e)}}async getChannel(){if(await this.channel.promise,this.destroyed)throw new u;return this.channel.promise}async messageListener(e){try{await this.getChannel();let o=this.isValidMessage(e),t=v(e.data);if(o)switch(t.type){case"event":{this.handleEvent(t);break}case"request":{this.handleRequest(t);break}case"error_response":case"response":{this.handleResponse(t);break}}else this.logger.error("Invalid message format. Skipping.")}catch(o){this.logger.error(o)}}handleEvent(e){let o=this.eventSubscriptions[e.key];o&&Object.values(o).forEach(t=>t(e.data,e))}handleRequest(e){let o=this.requestSubscriptions[e.key];o&&(o(e.data,e),this.logger.log(`Handled request type ${e.key}`))}handleResponse(e){let o=e.requestId,t=o&&this.responseSubscriptions[o];t&&t(e.data,e)}async postMessage(e,o,t,i){let{port:a}=await this.getChannel();if(this.destroyed)throw new u;let s=E({type:e,apiVersion:"framepost/v1",key:o,data:t,id:m(),requestId:i});return this.logger.log("posting message from child to parent",s),a.postMessage(s),s}initListener(e){this.isInitMessage(e)?(this.onChannelInit(e),this.messagePort&&(this.messagePort.onmessage=this.messageListener.bind(this)),this.resolveChannel(e)):this.logger.error("Invalid message format. Skipping.")}isValidMessage(e){let o=e.data;return o.type&&o.id&&o.apiVersion==="framepost/v1"}isInitMessage(e){return this.isValidMessage(e)&&e.data.type==="channel_init"}resolveChannel(e){if(this.messagePort){let o={port:this.messagePort,origin:e.origin,context:e.data.data};this.channel.resolve(o)}}getInitMessage(e){return E({type:"channel_init",apiVersion:"framepost/v1",key:"",data:e,id:m()})}destroy(){this.destroyed=!0,this.channel.reject(new u),this.messagePort&&this.messagePort.close(),Object.values(this.onDestroyRequestHandlers).forEach(e=>e())}};var y=class extends f{constructor(o={}){super(o);this.context=o.context||null,this.initListener=this.initListener.bind(this),window.addEventListener("message",this.initListener)}getLogger(){return R("child-client",this.debug)}onChannelInit(o){window.removeEventListener("message",this.initListener),this.messagePort=o.ports[0];let t=this.getInitMessage(this.context);this.logger.log("channel init, posting init message from child to parent",t),this.messagePort.postMessage(t)}destroy(){super.destroy(),window.removeEventListener("message",this.initListener)}};async function M({dialogResponseHandlers:n}){let e=new y({debug:!1});window.parent.postMessage("parents just don't understand","*");let o=await e.request("initialize");return e.onRequest("dialog-value",async t=>{let i=n[t.dialogId];!i||(t.value?i.resolve({value:t.value,dialogId:t.dialogId}):t.error&&i.reject(t.error),delete n[t.dialogId])}),{initData:o,parent:{resize:async t=>{e.request("resize",{height:t})},getValue:async()=>{let t=await e.request("getValue");return t==null?void 0:t.data},setValue:async t=>{await e.request("setValue",t)},getMetadata:async()=>{let t=await e.request("getMetadata");return t==null?void 0:t.data},openDialog:async({dialogType:t,data:i,options:a})=>{if(V(a==null?void 0:a.params)>1e5)throw new Error("Dialog parameters object is too large, maximum size is 100KB");let s=await e.request("openDialog",{dialogType:t,dialogData:i,options:a}),r=s==null?void 0:s.dialogId;if(!!r)return new Promise((l,p)=>{n[r]={resolve:l,reject:p}})},closeDialog:async({dialogId:t,dialogType:i,dialogData:a})=>{await e.request("closeDialog",{dialogId:t,dialogType:i,dialogData:a})}}}}function V(n){if(!n||typeof Blob=="undefined")return 0;try{let e=JSON.stringify(n);return new Blob([e]).size}catch(e){throw new Error("Error calculating object size: "+e.message)}}var w,C=({onHeightChange:n,autoResizingDisabled:e})=>{if(typeof window=="undefined")return;let o=window,t=r=>{if(r&&r!==w){w=r,n==null||n(r);return}let l=`${Math.ceil(o.document.documentElement.getBoundingClientRect().height)}px`;l!==w&&(w=l,n==null||n(l))},i=()=>{t()},a=e?void 0:new MutationObserver(i),s={instance:o,height:o.document.documentElement.getBoundingClientRect().height,observer:a,enableAutoResizing:()=>{a==null||a.observe(document.body,{attributes:!0,childList:!0,subtree:!0,characterData:!0}),o.addEventListener("resize",i)},disableAutoResizing:()=>{a==null||a.disconnect(),o.removeEventListener("resize",i)},updateHeight:t};return e||s.enableAutoResizing(),s};var P={};async function oe({autoResizingDisabled:n}={}){var e;if(typeof window!="undefined"&&typeof window.UniformMeshSDK=="undefined"){if(typeof window.parent=="undefined"||window.parent==window)throw new Error("It appears you are trying to connect with the Uniform Mesh SDK outside of an iframe. Be sure you are loading your app via a location URL configured in the Uniform dashboard.");let o=await M({dialogResponseHandlers:P}),{initData:t,parent:i}=o,a={getCurrentLocation:()=>({getValue:()=>t.locationValue,setValue:async s=>{await i.setValue(s),t.locationValue=s},getMetadata:()=>t.locationMetadata}),currentWindow:C({onHeightChange:s=>{i.resize(s)},autoResizingDisabled:(e=t.dialogContext)!=null&&e.contentHeight?!0:n}),version:t.uniformApiVersion,openLocationDialog:async({locationKey:s,options:r})=>{let l=await i.openDialog({dialogType:"location",data:{locationKey:s},options:r});if(!!l)return{dialogId:l.dialogId,value:l.value,closeDialog:async()=>{await i.closeDialog({dialogId:l.dialogId,dialogType:"location"})}}},closeLocationDialog:async({dialogId:s})=>{await i.closeDialog({dialogId:s,dialogType:"location"})},openConfirmationDialog:async({titleText:s,bodyText:r})=>{let l=await i.openDialog({dialogType:"confirm",data:{titleText:s,bodyText:r}});if(!!l)return{dialogId:l.dialogId,value:l.value,closeDialog:async()=>{await i.closeDialog({dialogId:void 0,dialogType:"confirm"})}}},closeConfirmationDialog:async()=>{await i.closeDialog({dialogId:void 0,dialogType:"confirm"})},openCurrentLocationDialog:async({options:s})=>{let r=await i.openDialog({dialogType:"location",data:{},options:s});if(!!r)return{dialogId:r.dialogId,value:r.value,closeDialog:async()=>{await i.closeDialog({dialogId:void 0,dialogType:"location"})}}},closeCurrentLocationDialog:async()=>{await i.closeDialog({dialogId:void 0,dialogType:"location"})},dialogContext:t.dialogContext};return window.UniformMeshSDK=a,a}}export{oe as initializeUniformMeshSDK};
var E=(n,e)=>e?{log(o,...t){return console.log(`${n}: ${o}`,...t)},error(o,...t){return console.error(`${n}: ${o}`,...t)}}:{log(){},error(){}};var T=5e3;var c=class extends Error{constructor(){super("Request timed out"),Object.setPrototypeOf(this,c.prototype),this.name="RequestTimeoutError"}},u=class extends Error{constructor(){super("Client destroyed"),Object.setPrototypeOf(this,u.prototype),this.name="ClientDestroyedError"}};var b=()=>{let n=()=>{},e=()=>{},o=new Promise((t,i)=>{n=t,e=i});return{resolve:n,reject:e,promise:o}},m=(n=16)=>[...Array(n)].map(()=>(~~(Math.random()*36)).toString(36)).join(""),h=(n,e)=>{let{[e]:o,...t}=n;return t},O=n=>({message:n.message,name:n.name,stack:n.stack}),k=({name:n,message:e,stack:o})=>{switch(n){case c.name:return new c;default:{let t=new Error(e);return t.name=n,t.stack=o,t}}},R=n=>{let e=n.data,o="none";return e instanceof Error&&(o="error",e=O(e)),{...n,serialization:o,data:e}},v=n=>n.serialization==="error"?{...n,data:k(n.data)}:n;var f=class{constructor({debug:e=!1,requestTimeout:o=T}={}){this.debug=e,this.requestTimeout=o,this.channel=b(),this.eventSubscriptions={},this.responseSubscriptions={},this.requestSubscriptions={},this.onDestroyRequestHandlers={},this.destroyed=!1,this.logger=this.getLogger(),this.getChannel().then(()=>{this.logger.log("Secure parent <-> child channel established")}).catch(t=>{this.logger.log(t)})}async send(e,o){return this.postMessage("event",e,o)}on(e,o){this.eventSubscriptions[e]||(this.eventSubscriptions[e]={});let t=m(8);return this.eventSubscriptions[e][t]=o,this.logger.log(`Registered handler for event "${e}"`),()=>{this.eventSubscriptions[e]=h(this.eventSubscriptions[e],t),this.logger.log(`Unsubscribed handler for event ${e}`)}}async request(e,o,t={}){let a=(await this.postMessage("request",e,o)).id,s=()=>{this.responseSubscriptions=h(this.responseSubscriptions,a)},r=()=>{this.onDestroyRequestHandlers=h(this.responseSubscriptions,a)};return new Promise((l,p)=>{let D,x=(S,I)=>{clearTimeout(D),s(),r(),I.type==="error_response"?p(S):l(S)},V=()=>{clearTimeout(D),p(new u)};this.responseSubscriptions[a]=x,this.onDestroyRequestHandlers[a]=V,D=setTimeout(()=>{s(),r(),p(new c)},t.timeout||this.requestTimeout)})}onRequest(e,o){let t=async(i,a)=>{try{let s=await o(i,a);this.postMessage("response",e,s,a.id)}catch(s){this.postMessage("error_response",e,s,a.id)}};return this.requestSubscriptions[e]=t,()=>{this.requestSubscriptions=h(this.requestSubscriptions,e)}}async getChannel(){if(await this.channel.promise,this.destroyed)throw new u;return this.channel.promise}async messageListener(e){try{await this.getChannel();let o=this.isValidMessage(e),t=v(e.data);if(o)switch(t.type){case"event":{this.handleEvent(t);break}case"request":{this.handleRequest(t);break}case"error_response":case"response":{this.handleResponse(t);break}}else this.logger.error("Invalid message format. Skipping.")}catch(o){this.logger.error(o)}}handleEvent(e){let o=this.eventSubscriptions[e.key];o&&Object.values(o).forEach(t=>t(e.data,e))}handleRequest(e){let o=this.requestSubscriptions[e.key];o&&(o(e.data,e),this.logger.log(`Handled request type ${e.key}`))}handleResponse(e){let o=e.requestId,t=o&&this.responseSubscriptions[o];t&&t(e.data,e)}async postMessage(e,o,t,i){let{port:a}=await this.getChannel();if(this.destroyed)throw new u;let s=R({type:e,apiVersion:"framepost/v1",key:o,data:t,id:m(),requestId:i});return this.logger.log("posting message from child to parent",s),a.postMessage(s),s}initListener(e){this.isInitMessage(e)?(this.onChannelInit(e),this.messagePort&&(this.messagePort.onmessage=this.messageListener.bind(this)),this.resolveChannel(e)):this.logger.error("Invalid message format. Skipping.")}isValidMessage(e){let o=e.data;return o.type&&o.id&&o.apiVersion==="framepost/v1"}isInitMessage(e){return this.isValidMessage(e)&&e.data.type==="channel_init"}resolveChannel(e){if(this.messagePort){let o={port:this.messagePort,origin:e.origin,context:e.data.data};this.channel.resolve(o)}}getInitMessage(e){return R({type:"channel_init",apiVersion:"framepost/v1",key:"",data:e,id:m()})}destroy(){this.destroyed=!0,this.channel.reject(new u),this.messagePort&&this.messagePort.close(),Object.values(this.onDestroyRequestHandlers).forEach(e=>e())}};var y=class extends f{constructor(o={}){super(o);this.context=o.context||null,this.initListener=this.initListener.bind(this),window.addEventListener("message",this.initListener)}getLogger(){return E("child-client",this.debug)}onChannelInit(o){window.removeEventListener("message",this.initListener),this.messagePort=o.ports[0];let t=this.getInitMessage(this.context);this.logger.log("channel init, posting init message from child to parent",t),this.messagePort.postMessage(t)}destroy(){super.destroy(),window.removeEventListener("message",this.initListener)}};async function M({dialogResponseHandlers:n}){let e=new y({debug:!1});window.parent.postMessage("parents just don't understand","*");let o=await e.request("initialize");return e.onRequest("dialog-value",async t=>{let i=n[t.dialogId];!i||(t.value?i.resolve({value:t.value,dialogId:t.dialogId}):t.error&&i.reject(t.error),delete n[t.dialogId])}),{initData:o,parent:{resize:async t=>{e.request("resize",{height:t})},getValue:async()=>{let t=await e.request("getValue");return t==null?void 0:t.data},setValue:async(t,i)=>{await e.request("setValue",{uniformMeshLocationValue:t,options:i})},setValidationResult:async t=>{await e.request("setValidationResult",{value:t})},getMetadata:async()=>{let t=await e.request("getMetadata");return t==null?void 0:t.data},openDialog:async({dialogType:t,data:i,options:a})=>{if(L(a==null?void 0:a.params)>1e5)throw new Error("Dialog parameters object is too large, maximum size is 100KB");let s=await e.request("openDialog",{dialogType:t,dialogData:i,options:a}),r=s==null?void 0:s.dialogId;if(!!r)return new Promise((l,p)=>{n[r]={resolve:l,reject:p}})},closeDialog:async({dialogId:t,dialogType:i,dialogData:a})=>{await e.request("closeDialog",{dialogId:t,dialogType:i,dialogData:a})}}}}function L(n){if(!n||typeof Blob=="undefined")return 0;try{let e=JSON.stringify(n);return new Blob([e]).size}catch(e){throw new Error("Error calculating object size: "+e.message)}}var w,C=({onHeightChange:n,autoResizingDisabled:e})=>{if(typeof window=="undefined")return;let o=window,t=r=>{if(r&&r!==w){w=r,n==null||n(r);return}let l=`${Math.ceil(o.document.documentElement.getBoundingClientRect().height)}px`;l!==w&&(w=l,n==null||n(l))},i=()=>{t()},a=e?void 0:new MutationObserver(i),s={instance:o,height:o.document.documentElement.getBoundingClientRect().height,observer:a,enableAutoResizing:()=>{a==null||a.observe(document.body,{attributes:!0,childList:!0,subtree:!0,characterData:!0}),o.addEventListener("resize",i)},disableAutoResizing:()=>{a==null||a.disconnect(),o.removeEventListener("resize",i)},updateHeight:t};return e||s.enableAutoResizing(),s};var P={};async function oe({autoResizingDisabled:n}={}){var e;if(typeof window!="undefined"&&typeof window.UniformMeshSDK=="undefined"){if(typeof window.parent=="undefined"||window.parent==window)throw new Error("It appears you are trying to connect with the Uniform Mesh SDK outside of an iframe. Be sure you are loading your app via a location URL configured in the Uniform dashboard.");let o=await M({dialogResponseHandlers:P}),{initData:t,parent:i}=o,a={getCurrentLocation:()=>({getValue:()=>t.locationValue,setValue:async(s,r)=>{await i.setValue(s,r),t.locationValue=s},getMetadata:()=>t.locationMetadata,setValidationResult:async s=>{await i.setValidationResult(s)}}),currentWindow:C({onHeightChange:s=>{i.resize(s)},autoResizingDisabled:(e=t.dialogContext)!=null&&e.contentHeight?!0:n}),version:t.uniformApiVersion,openLocationDialog:async({locationKey:s,options:r})=>{let l=await i.openDialog({dialogType:"location",data:{locationKey:s},options:r});if(!!l)return{dialogId:l.dialogId,value:l.value,closeDialog:async()=>{await i.closeDialog({dialogId:l.dialogId,dialogType:"location"})}}},closeLocationDialog:async({dialogId:s})=>{await i.closeDialog({dialogId:s,dialogType:"location"})},openConfirmationDialog:async({titleText:s,bodyText:r})=>{let l=await i.openDialog({dialogType:"confirm",data:{titleText:s,bodyText:r}});if(!!l)return{dialogId:l.dialogId,value:l.value,closeDialog:async()=>{await i.closeDialog({dialogId:void 0,dialogType:"confirm"})}}},closeConfirmationDialog:async()=>{await i.closeDialog({dialogId:void 0,dialogType:"confirm"})},openCurrentLocationDialog:async({options:s})=>{let r=await i.openDialog({dialogType:"location",data:{},options:s});if(!!r)return{dialogId:r.dialogId,value:r.value,closeDialog:async()=>{await i.closeDialog({dialogId:void 0,dialogType:"location"})}}},closeCurrentLocationDialog:async()=>{await i.closeDialog({dialogId:void 0,dialogType:"location"})},dialogContext:t.dialogContext};return window.UniformMeshSDK=a,a}}export{oe as initializeUniformMeshSDK};

@@ -1,1 +0,1 @@

var D=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var P=(n,e)=>{for(var o in e)D(n,o,{get:e[o],enumerable:!0})},q=(n,e,o,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of L(e))!V.call(n,i)&&i!==o&&D(n,i,{get:()=>e[i],enumerable:!(t=k(e,i))||t.enumerable});return n};var z=n=>q(D({},"__esModule",{value:!0}),n);var A={};P(A,{initializeUniformMeshSDK:()=>Q});module.exports=z(A);var R=(n,e)=>e?{log(o,...t){return console.log(`${n}: ${o}`,...t)},error(o,...t){return console.error(`${n}: ${o}`,...t)}}:{log(){},error(){}};var T=5e3;var g=class extends Error{constructor(){super("Request timed out"),Object.setPrototypeOf(this,g.prototype),this.name="RequestTimeoutError"}},c=class extends Error{constructor(){super("Client destroyed"),Object.setPrototypeOf(this,c.prototype),this.name="ClientDestroyedError"}};var b=()=>{let n=()=>{},e=()=>{},o=new Promise((t,i)=>{n=t,e=i});return{resolve:n,reject:e,promise:o}},h=(n=16)=>[...Array(n)].map(()=>(~~(Math.random()*36)).toString(36)).join(""),p=(n,e)=>{let{[e]:o,...t}=n;return t},H=n=>({message:n.message,name:n.name,stack:n.stack}),N=({name:n,message:e,stack:o})=>{switch(n){case g.name:return new g;default:{let t=new Error(e);return t.name=n,t.stack=o,t}}},E=n=>{let e=n.data,o="none";return e instanceof Error&&(o="error",e=H(e)),{...n,serialization:o,data:e}},v=n=>n.serialization==="error"?{...n,data:N(n.data)}:n;var m=class{constructor({debug:e=!1,requestTimeout:o=T}={}){this.debug=e,this.requestTimeout=o,this.channel=b(),this.eventSubscriptions={},this.responseSubscriptions={},this.requestSubscriptions={},this.onDestroyRequestHandlers={},this.destroyed=!1,this.logger=this.getLogger(),this.getChannel().then(()=>{this.logger.log("Secure parent <-> child channel established")}).catch(t=>{this.logger.log(t)})}async send(e,o){return this.postMessage("event",e,o)}on(e,o){this.eventSubscriptions[e]||(this.eventSubscriptions[e]={});let t=h(8);return this.eventSubscriptions[e][t]=o,this.logger.log(`Registered handler for event "${e}"`),()=>{this.eventSubscriptions[e]=p(this.eventSubscriptions[e],t),this.logger.log(`Unsubscribed handler for event ${e}`)}}async request(e,o,t={}){let a=(await this.postMessage("request",e,o)).id,s=()=>{this.responseSubscriptions=p(this.responseSubscriptions,a)},r=()=>{this.onDestroyRequestHandlers=p(this.responseSubscriptions,a)};return new Promise((l,u)=>{let w,x=(S,O)=>{clearTimeout(w),s(),r(),O.type==="error_response"?u(S):l(S)},I=()=>{clearTimeout(w),u(new c)};this.responseSubscriptions[a]=x,this.onDestroyRequestHandlers[a]=I,w=setTimeout(()=>{s(),r(),u(new g)},t.timeout||this.requestTimeout)})}onRequest(e,o){let t=async(i,a)=>{try{let s=await o(i,a);this.postMessage("response",e,s,a.id)}catch(s){this.postMessage("error_response",e,s,a.id)}};return this.requestSubscriptions[e]=t,()=>{this.requestSubscriptions=p(this.requestSubscriptions,e)}}async getChannel(){if(await this.channel.promise,this.destroyed)throw new c;return this.channel.promise}async messageListener(e){try{await this.getChannel();let o=this.isValidMessage(e),t=v(e.data);if(o)switch(t.type){case"event":{this.handleEvent(t);break}case"request":{this.handleRequest(t);break}case"error_response":case"response":{this.handleResponse(t);break}}else this.logger.error("Invalid message format. Skipping.")}catch(o){this.logger.error(o)}}handleEvent(e){let o=this.eventSubscriptions[e.key];o&&Object.values(o).forEach(t=>t(e.data,e))}handleRequest(e){let o=this.requestSubscriptions[e.key];o&&(o(e.data,e),this.logger.log(`Handled request type ${e.key}`))}handleResponse(e){let o=e.requestId,t=o&&this.responseSubscriptions[o];t&&t(e.data,e)}async postMessage(e,o,t,i){let{port:a}=await this.getChannel();if(this.destroyed)throw new c;let s=E({type:e,apiVersion:"framepost/v1",key:o,data:t,id:h(),requestId:i});return this.logger.log("posting message from child to parent",s),a.postMessage(s),s}initListener(e){this.isInitMessage(e)?(this.onChannelInit(e),this.messagePort&&(this.messagePort.onmessage=this.messageListener.bind(this)),this.resolveChannel(e)):this.logger.error("Invalid message format. Skipping.")}isValidMessage(e){let o=e.data;return o.type&&o.id&&o.apiVersion==="framepost/v1"}isInitMessage(e){return this.isValidMessage(e)&&e.data.type==="channel_init"}resolveChannel(e){if(this.messagePort){let o={port:this.messagePort,origin:e.origin,context:e.data.data};this.channel.resolve(o)}}getInitMessage(e){return E({type:"channel_init",apiVersion:"framepost/v1",key:"",data:e,id:h()})}destroy(){this.destroyed=!0,this.channel.reject(new c),this.messagePort&&this.messagePort.close(),Object.values(this.onDestroyRequestHandlers).forEach(e=>e())}};var f=class extends m{constructor(o={}){super(o);this.context=o.context||null,this.initListener=this.initListener.bind(this),window.addEventListener("message",this.initListener)}getLogger(){return R("child-client",this.debug)}onChannelInit(o){window.removeEventListener("message",this.initListener),this.messagePort=o.ports[0];let t=this.getInitMessage(this.context);this.logger.log("channel init, posting init message from child to parent",t),this.messagePort.postMessage(t)}destroy(){super.destroy(),window.removeEventListener("message",this.initListener)}};async function M({dialogResponseHandlers:n}){let e=new f({debug:!1});window.parent.postMessage("parents just don't understand","*");let o=await e.request("initialize");return e.onRequest("dialog-value",async t=>{let i=n[t.dialogId];!i||(t.value?i.resolve({value:t.value,dialogId:t.dialogId}):t.error&&i.reject(t.error),delete n[t.dialogId])}),{initData:o,parent:{resize:async t=>{e.request("resize",{height:t})},getValue:async()=>{let t=await e.request("getValue");return t==null?void 0:t.data},setValue:async t=>{await e.request("setValue",t)},getMetadata:async()=>{let t=await e.request("getMetadata");return t==null?void 0:t.data},openDialog:async({dialogType:t,data:i,options:a})=>{if(U(a==null?void 0:a.params)>1e5)throw new Error("Dialog parameters object is too large, maximum size is 100KB");let s=await e.request("openDialog",{dialogType:t,dialogData:i,options:a}),r=s==null?void 0:s.dialogId;if(!!r)return new Promise((l,u)=>{n[r]={resolve:l,reject:u}})},closeDialog:async({dialogId:t,dialogType:i,dialogData:a})=>{await e.request("closeDialog",{dialogId:t,dialogType:i,dialogData:a})}}}}function U(n){if(!n||typeof Blob=="undefined")return 0;try{let e=JSON.stringify(n);return new Blob([e]).size}catch(e){throw new Error("Error calculating object size: "+e.message)}}var y,C=({onHeightChange:n,autoResizingDisabled:e})=>{if(typeof window=="undefined")return;let o=window,t=r=>{if(r&&r!==y){y=r,n==null||n(r);return}let l=`${Math.ceil(o.document.documentElement.getBoundingClientRect().height)}px`;l!==y&&(y=l,n==null||n(l))},i=()=>{t()},a=e?void 0:new MutationObserver(i),s={instance:o,height:o.document.documentElement.getBoundingClientRect().height,observer:a,enableAutoResizing:()=>{a==null||a.observe(document.body,{attributes:!0,childList:!0,subtree:!0,characterData:!0}),o.addEventListener("resize",i)},disableAutoResizing:()=>{a==null||a.disconnect(),o.removeEventListener("resize",i)},updateHeight:t};return e||s.enableAutoResizing(),s};var W={};async function Q({autoResizingDisabled:n}={}){var e;if(typeof window!="undefined"&&typeof window.UniformMeshSDK=="undefined"){if(typeof window.parent=="undefined"||window.parent==window)throw new Error("It appears you are trying to connect with the Uniform Mesh SDK outside of an iframe. Be sure you are loading your app via a location URL configured in the Uniform dashboard.");let o=await M({dialogResponseHandlers:W}),{initData:t,parent:i}=o,a={getCurrentLocation:()=>({getValue:()=>t.locationValue,setValue:async s=>{await i.setValue(s),t.locationValue=s},getMetadata:()=>t.locationMetadata}),currentWindow:C({onHeightChange:s=>{i.resize(s)},autoResizingDisabled:(e=t.dialogContext)!=null&&e.contentHeight?!0:n}),version:t.uniformApiVersion,openLocationDialog:async({locationKey:s,options:r})=>{let l=await i.openDialog({dialogType:"location",data:{locationKey:s},options:r});if(!!l)return{dialogId:l.dialogId,value:l.value,closeDialog:async()=>{await i.closeDialog({dialogId:l.dialogId,dialogType:"location"})}}},closeLocationDialog:async({dialogId:s})=>{await i.closeDialog({dialogId:s,dialogType:"location"})},openConfirmationDialog:async({titleText:s,bodyText:r})=>{let l=await i.openDialog({dialogType:"confirm",data:{titleText:s,bodyText:r}});if(!!l)return{dialogId:l.dialogId,value:l.value,closeDialog:async()=>{await i.closeDialog({dialogId:void 0,dialogType:"confirm"})}}},closeConfirmationDialog:async()=>{await i.closeDialog({dialogId:void 0,dialogType:"confirm"})},openCurrentLocationDialog:async({options:s})=>{let r=await i.openDialog({dialogType:"location",data:{},options:s});if(!!r)return{dialogId:r.dialogId,value:r.value,closeDialog:async()=>{await i.closeDialog({dialogId:void 0,dialogType:"location"})}}},closeCurrentLocationDialog:async()=>{await i.closeDialog({dialogId:void 0,dialogType:"location"})},dialogContext:t.dialogContext};return window.UniformMeshSDK=a,a}}0&&(module.exports={initializeUniformMeshSDK});
var D=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var L=Object.prototype.hasOwnProperty;var P=(n,e)=>{for(var o in e)D(n,o,{get:e[o],enumerable:!0})},q=(n,e,o,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of k(e))!L.call(n,i)&&i!==o&&D(n,i,{get:()=>e[i],enumerable:!(t=O(e,i))||t.enumerable});return n};var z=n=>q(D({},"__esModule",{value:!0}),n);var A={};P(A,{initializeUniformMeshSDK:()=>Q});module.exports=z(A);var E=(n,e)=>e?{log(o,...t){return console.log(`${n}: ${o}`,...t)},error(o,...t){return console.error(`${n}: ${o}`,...t)}}:{log(){},error(){}};var T=5e3;var g=class extends Error{constructor(){super("Request timed out"),Object.setPrototypeOf(this,g.prototype),this.name="RequestTimeoutError"}},c=class extends Error{constructor(){super("Client destroyed"),Object.setPrototypeOf(this,c.prototype),this.name="ClientDestroyedError"}};var b=()=>{let n=()=>{},e=()=>{},o=new Promise((t,i)=>{n=t,e=i});return{resolve:n,reject:e,promise:o}},h=(n=16)=>[...Array(n)].map(()=>(~~(Math.random()*36)).toString(36)).join(""),p=(n,e)=>{let{[e]:o,...t}=n;return t},H=n=>({message:n.message,name:n.name,stack:n.stack}),N=({name:n,message:e,stack:o})=>{switch(n){case g.name:return new g;default:{let t=new Error(e);return t.name=n,t.stack=o,t}}},R=n=>{let e=n.data,o="none";return e instanceof Error&&(o="error",e=H(e)),{...n,serialization:o,data:e}},v=n=>n.serialization==="error"?{...n,data:N(n.data)}:n;var m=class{constructor({debug:e=!1,requestTimeout:o=T}={}){this.debug=e,this.requestTimeout=o,this.channel=b(),this.eventSubscriptions={},this.responseSubscriptions={},this.requestSubscriptions={},this.onDestroyRequestHandlers={},this.destroyed=!1,this.logger=this.getLogger(),this.getChannel().then(()=>{this.logger.log("Secure parent <-> child channel established")}).catch(t=>{this.logger.log(t)})}async send(e,o){return this.postMessage("event",e,o)}on(e,o){this.eventSubscriptions[e]||(this.eventSubscriptions[e]={});let t=h(8);return this.eventSubscriptions[e][t]=o,this.logger.log(`Registered handler for event "${e}"`),()=>{this.eventSubscriptions[e]=p(this.eventSubscriptions[e],t),this.logger.log(`Unsubscribed handler for event ${e}`)}}async request(e,o,t={}){let a=(await this.postMessage("request",e,o)).id,s=()=>{this.responseSubscriptions=p(this.responseSubscriptions,a)},r=()=>{this.onDestroyRequestHandlers=p(this.responseSubscriptions,a)};return new Promise((l,u)=>{let w,x=(S,I)=>{clearTimeout(w),s(),r(),I.type==="error_response"?u(S):l(S)},V=()=>{clearTimeout(w),u(new c)};this.responseSubscriptions[a]=x,this.onDestroyRequestHandlers[a]=V,w=setTimeout(()=>{s(),r(),u(new g)},t.timeout||this.requestTimeout)})}onRequest(e,o){let t=async(i,a)=>{try{let s=await o(i,a);this.postMessage("response",e,s,a.id)}catch(s){this.postMessage("error_response",e,s,a.id)}};return this.requestSubscriptions[e]=t,()=>{this.requestSubscriptions=p(this.requestSubscriptions,e)}}async getChannel(){if(await this.channel.promise,this.destroyed)throw new c;return this.channel.promise}async messageListener(e){try{await this.getChannel();let o=this.isValidMessage(e),t=v(e.data);if(o)switch(t.type){case"event":{this.handleEvent(t);break}case"request":{this.handleRequest(t);break}case"error_response":case"response":{this.handleResponse(t);break}}else this.logger.error("Invalid message format. Skipping.")}catch(o){this.logger.error(o)}}handleEvent(e){let o=this.eventSubscriptions[e.key];o&&Object.values(o).forEach(t=>t(e.data,e))}handleRequest(e){let o=this.requestSubscriptions[e.key];o&&(o(e.data,e),this.logger.log(`Handled request type ${e.key}`))}handleResponse(e){let o=e.requestId,t=o&&this.responseSubscriptions[o];t&&t(e.data,e)}async postMessage(e,o,t,i){let{port:a}=await this.getChannel();if(this.destroyed)throw new c;let s=R({type:e,apiVersion:"framepost/v1",key:o,data:t,id:h(),requestId:i});return this.logger.log("posting message from child to parent",s),a.postMessage(s),s}initListener(e){this.isInitMessage(e)?(this.onChannelInit(e),this.messagePort&&(this.messagePort.onmessage=this.messageListener.bind(this)),this.resolveChannel(e)):this.logger.error("Invalid message format. Skipping.")}isValidMessage(e){let o=e.data;return o.type&&o.id&&o.apiVersion==="framepost/v1"}isInitMessage(e){return this.isValidMessage(e)&&e.data.type==="channel_init"}resolveChannel(e){if(this.messagePort){let o={port:this.messagePort,origin:e.origin,context:e.data.data};this.channel.resolve(o)}}getInitMessage(e){return R({type:"channel_init",apiVersion:"framepost/v1",key:"",data:e,id:h()})}destroy(){this.destroyed=!0,this.channel.reject(new c),this.messagePort&&this.messagePort.close(),Object.values(this.onDestroyRequestHandlers).forEach(e=>e())}};var f=class extends m{constructor(o={}){super(o);this.context=o.context||null,this.initListener=this.initListener.bind(this),window.addEventListener("message",this.initListener)}getLogger(){return E("child-client",this.debug)}onChannelInit(o){window.removeEventListener("message",this.initListener),this.messagePort=o.ports[0];let t=this.getInitMessage(this.context);this.logger.log("channel init, posting init message from child to parent",t),this.messagePort.postMessage(t)}destroy(){super.destroy(),window.removeEventListener("message",this.initListener)}};async function M({dialogResponseHandlers:n}){let e=new f({debug:!1});window.parent.postMessage("parents just don't understand","*");let o=await e.request("initialize");return e.onRequest("dialog-value",async t=>{let i=n[t.dialogId];!i||(t.value?i.resolve({value:t.value,dialogId:t.dialogId}):t.error&&i.reject(t.error),delete n[t.dialogId])}),{initData:o,parent:{resize:async t=>{e.request("resize",{height:t})},getValue:async()=>{let t=await e.request("getValue");return t==null?void 0:t.data},setValue:async(t,i)=>{await e.request("setValue",{uniformMeshLocationValue:t,options:i})},setValidationResult:async t=>{await e.request("setValidationResult",{value:t})},getMetadata:async()=>{let t=await e.request("getMetadata");return t==null?void 0:t.data},openDialog:async({dialogType:t,data:i,options:a})=>{if(U(a==null?void 0:a.params)>1e5)throw new Error("Dialog parameters object is too large, maximum size is 100KB");let s=await e.request("openDialog",{dialogType:t,dialogData:i,options:a}),r=s==null?void 0:s.dialogId;if(!!r)return new Promise((l,u)=>{n[r]={resolve:l,reject:u}})},closeDialog:async({dialogId:t,dialogType:i,dialogData:a})=>{await e.request("closeDialog",{dialogId:t,dialogType:i,dialogData:a})}}}}function U(n){if(!n||typeof Blob=="undefined")return 0;try{let e=JSON.stringify(n);return new Blob([e]).size}catch(e){throw new Error("Error calculating object size: "+e.message)}}var y,C=({onHeightChange:n,autoResizingDisabled:e})=>{if(typeof window=="undefined")return;let o=window,t=r=>{if(r&&r!==y){y=r,n==null||n(r);return}let l=`${Math.ceil(o.document.documentElement.getBoundingClientRect().height)}px`;l!==y&&(y=l,n==null||n(l))},i=()=>{t()},a=e?void 0:new MutationObserver(i),s={instance:o,height:o.document.documentElement.getBoundingClientRect().height,observer:a,enableAutoResizing:()=>{a==null||a.observe(document.body,{attributes:!0,childList:!0,subtree:!0,characterData:!0}),o.addEventListener("resize",i)},disableAutoResizing:()=>{a==null||a.disconnect(),o.removeEventListener("resize",i)},updateHeight:t};return e||s.enableAutoResizing(),s};var W={};async function Q({autoResizingDisabled:n}={}){var e;if(typeof window!="undefined"&&typeof window.UniformMeshSDK=="undefined"){if(typeof window.parent=="undefined"||window.parent==window)throw new Error("It appears you are trying to connect with the Uniform Mesh SDK outside of an iframe. Be sure you are loading your app via a location URL configured in the Uniform dashboard.");let o=await M({dialogResponseHandlers:W}),{initData:t,parent:i}=o,a={getCurrentLocation:()=>({getValue:()=>t.locationValue,setValue:async(s,r)=>{await i.setValue(s,r),t.locationValue=s},getMetadata:()=>t.locationMetadata,setValidationResult:async s=>{await i.setValidationResult(s)}}),currentWindow:C({onHeightChange:s=>{i.resize(s)},autoResizingDisabled:(e=t.dialogContext)!=null&&e.contentHeight?!0:n}),version:t.uniformApiVersion,openLocationDialog:async({locationKey:s,options:r})=>{let l=await i.openDialog({dialogType:"location",data:{locationKey:s},options:r});if(!!l)return{dialogId:l.dialogId,value:l.value,closeDialog:async()=>{await i.closeDialog({dialogId:l.dialogId,dialogType:"location"})}}},closeLocationDialog:async({dialogId:s})=>{await i.closeDialog({dialogId:s,dialogType:"location"})},openConfirmationDialog:async({titleText:s,bodyText:r})=>{let l=await i.openDialog({dialogType:"confirm",data:{titleText:s,bodyText:r}});if(!!l)return{dialogId:l.dialogId,value:l.value,closeDialog:async()=>{await i.closeDialog({dialogId:void 0,dialogType:"confirm"})}}},closeConfirmationDialog:async()=>{await i.closeDialog({dialogId:void 0,dialogType:"confirm"})},openCurrentLocationDialog:async({options:s})=>{let r=await i.openDialog({dialogType:"location",data:{},options:s});if(!!r)return{dialogId:r.dialogId,value:r.value,closeDialog:async()=>{await i.closeDialog({dialogId:void 0,dialogType:"location"})}}},closeCurrentLocationDialog:async()=>{await i.closeDialog({dialogId:void 0,dialogType:"location"})},dialogContext:t.dialogContext};return window.UniformMeshSDK=a,a}}0&&(module.exports={initializeUniformMeshSDK});
{
"name": "@uniformdev/mesh-sdk",
"version": "16.0.0",
"version": "16.0.1-alpha.164+c3b15fc3f",
"description": "Uniform Mesh Framework SDK",

@@ -31,3 +31,3 @@ "license": "SEE LICENSE IN LICENSE.txt",

},
"gitHead": "72f1d98e96004c4ebf4bea49bf27aa4ecc036e33"
"gitHead": "c3b15fc3f3101dd990d7adfe84cb7e0bad77899d"
}

Sorry, the diff of this file is not supported yet