@uniformdev/mesh-sdk 14.1.1 → 14.1.2-alpha.99

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/index.d.ts CHANGED
@@ -1,9 +1,82 @@
1
+ interface ContextData {
2
+ locationKey: string;
3
+ locationValue: any;
4
+ locationMetadata: any;
5
+ uniformApiVersion: string;
6
+ dialogContext?: DialogContext;
7
+ }
8
+ interface DialogContext {
9
+ dialogId: string;
10
+ contentHeight?: CSSHeight;
11
+ }
12
+ interface DialogResponseHandlers {
13
+ [dialogId: string]: DialogResponseHandler;
14
+ }
15
+ interface DialogResponseHandler {
16
+ resolve: (value: Pick<DialogResponseData, 'value' | 'dialogId'>) => void;
17
+ reject: (reason?: unknown) => void;
18
+ }
19
+ interface DialogResponseData {
20
+ value?: unknown;
21
+ dialogId: string;
22
+ error?: string;
23
+ }
24
+ declare type DialogType = 'location' | 'confirm';
25
+ interface DialogOptions {
26
+ /**
27
+ * By default, dialogs will be closed when they set a value.
28
+ * You can disable this behavior by setting the `disableCloseDialogOnSetValue`
29
+ * property to true.
30
+ * You'll still be able to close a dialog via the `closeDialog` method
31
+ * that is returned from the `openLocationDialog` method.
32
+ */
33
+ disableCloseDialogOnSetValue?: boolean;
34
+ /**
35
+ * Options for setting the max width of the dialog.
36
+ */
37
+ maxWidth?: 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl' | '5xl' | '6xl' | 'full';
38
+ /**
39
+ * Parameters to pass to the dialog, which will be available in the dialog via
40
+ * the `metadata` object for the dialog location, e.g. `metadata.dialogParams`.
41
+ * Parameters should be simple (serializable) types, not functions or DOM
42
+ * elements or similar non-serializable objects.
43
+ */
44
+ params?: DialogParams;
45
+ /**
46
+ * Allows you to specify the height of the dialog content upon open. Note: the
47
+ * dialog itself will always be full height to match the Uniform dashboard UI.
48
+ * However, the content container within the dialog is, by default, auto-sized to
49
+ * the calculated height of the rendered content of the dialog.
50
+ * Setting the `contentHeight` option disables auto-sizing and allows you to specify
51
+ * your own height for the dialog content.
52
+ * `contentHeight` option can be specific lengths, e.g. 100vh, 500px, etc... as
53
+ * well as other standard CSS height options.
54
+ */
55
+ contentHeight?: CSSHeight;
56
+ }
57
+ declare type DialogParamValue = string | number | boolean | null | DialogParamValue[] | {
58
+ [key: string]: DialogParamValue;
59
+ };
60
+ declare type DialogParams = {
61
+ [paramName: string]: DialogParamValue;
62
+ };
63
+ 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'}`;
64
+
1
65
  interface SdkWindow {
66
+ /** The current window object. */
2
67
  instance: Window;
3
- height?: number;
68
+ /** The numerical height of the current window. */
69
+ height: number;
70
+ /** The MutationObserver object used to detect content height changes.
71
+ * Note: this property is only defined if `enableAutoResizing` is true. */
4
72
  observer?: MutationObserver;
73
+ /** Enables auto-resizing of the window (iframe) based on the size of the content. */
5
74
  enableAutoResizing: () => void;
75
+ /** Disables auto-resizing of the window (iframe) based on the size of the content. */
6
76
  disableAutoResizing: () => void;
77
+ /** `height` argument can be specific lengths, e.g. 100vh, 300px, etc...
78
+ * as well as other standard CSS height options */
79
+ updateHeight: (height: CSSHeight) => void;
7
80
  }
8
81
 
9
82
  interface UniformMeshSDK {
@@ -31,39 +104,17 @@ interface UniformMeshSDK {
31
104
  options?: DialogOptions;
32
105
  }): Promise<LocationDialogResponse<TDialogValue> | undefined>;
33
106
  closeCurrentLocationDialog(): Promise<void>;
34
- dialogContext?: {
35
- dialogId: string;
36
- };
107
+ dialogContext?: DialogContext;
37
108
  }
38
109
  interface LocationDialogResponse<TDialogValue> {
39
110
  /** Generated id for the dialog. */
40
111
  dialogId: string;
41
112
  /** The value set by the dialog. */
42
113
  value: TDialogValue;
43
- /** Allows for closing the dialog manually. Typically used when `closeDialogOnSetValue` is false. */
114
+ /** Allows for closing the dialog manually.
115
+ * Typically used when `closeDialogOnSetValue` is false. */
44
116
  closeDialog: () => Promise<void>;
45
117
  }
46
- declare type DialogType = 'location' | 'confirm';
47
- interface DialogOptions {
48
- /**
49
- * By default, dialogs will be closed when they set a value.
50
- * You can disable this behavior by setting the `disableCloseDialogOnSetValue` property to true.
51
- * You'll still be able to close a dialog via the `closeDialog` method that is returned from the `openLocationDialog` method.
52
- */
53
- disableCloseDialogOnSetValue?: boolean;
54
- maxWidth?: 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl' | '5xl' | '6xl' | 'full';
55
- /**
56
- * Parameters to pass to the dialog, which will be available in the dialog via the `metadata` object for the dialog location, e.g. `metadata.dialogParams`.
57
- * Parameters should be simple (serializable) types, not functions or DOM elements or similar non-serializable objects.
58
- */
59
- params?: DialogParams;
60
- }
61
- declare type DialogParamValue = string | number | boolean | null | DialogParamValue[] | {
62
- [key: string]: DialogParamValue;
63
- };
64
- declare type DialogParams = {
65
- [paramName: string]: DialogParamValue;
66
- };
67
118
  declare global {
68
119
  interface Window {
69
120
  UniformMeshSDK: UniformMeshSDK;
@@ -83,4 +134,4 @@ declare function initializeUniformMeshSDK({ autoResizingDisabled, }?: {
83
134
  autoResizingDisabled?: boolean;
84
135
  }): Promise<UniformMeshSDK | undefined>;
85
136
 
86
- export { DialogOptions, DialogParamValue, DialogParams, DialogType, LocationDialogResponse, MeshLocation, UniformMeshSDK, initializeUniformMeshSDK };
137
+ export { CSSHeight, ContextData, DialogContext, DialogOptions, DialogParamValue, DialogParams, DialogResponseData, DialogResponseHandler, DialogResponseHandlers, DialogType, LocationDialogResponse, MeshLocation, SdkWindow, UniformMeshSDK, initializeUniformMeshSDK };
package/dist/index.esm.js CHANGED
@@ -1 +1 @@
1
- var g,u=({onHeightChange:l,autoResizingDisabled:o})=>{if(typeof window=="undefined")return;let e=window,i=()=>{let t=Math.ceil(e.document.documentElement.getBoundingClientRect().height);t!==g&&(g=t,l==null||l(t))},a=o?void 0:new MutationObserver(i),n={instance:e,observer:a,height:0,enableAutoResizing:()=>{a==null||a.observe(document.body,{attributes:!0,childList:!0,subtree:!0,characterData:!0}),e.addEventListener("resize",i)},disableAutoResizing:()=>{a==null||a.disconnect(),e.removeEventListener("resize",i)}};return o||n.enableAutoResizing(),n};var D=()=>import("post-robot"),w={};async function v({autoResizingDisabled:l}={}){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 f({dialogResponseHandlers:w}),e=await o.initialize(),i={getCurrentLocation:()=>({getValue:()=>e.locationValue,setValue:async a=>{await o.setValue(a),e.locationValue=a},getMetadata:()=>e.locationMetadata}),currentWindow:u({onHeightChange:a=>{o.resize(a)},autoResizingDisabled:l}),version:e.uniformApiVersion,openLocationDialog:async({locationKey:a,options:n})=>{let t=await o.openDialog({dialogType:"location",data:{locationKey:a},options:n});if(!!t)return{dialogId:t.dialogId,value:t.value,closeDialog:async()=>{await o.closeDialog({dialogId:t.dialogId,dialogType:"location"})}}},closeLocationDialog:async({dialogId:a})=>{await o.closeDialog({dialogId:a,dialogType:"location"})},openConfirmationDialog:async({titleText:a,bodyText:n})=>{let t=await o.openDialog({dialogType:"confirm",data:{titleText:a,bodyText:n}});if(!!t)return{value:t.value,closeDialog:async()=>{await o.closeDialog({dialogId:void 0,dialogType:"confirm"})}}},closeConfirmationDialog:async()=>{await o.closeDialog({dialogId:void 0,dialogType:"confirm"})},openCurrentLocationDialog:async({options:a})=>{let n=await o.openDialog({dialogType:"location",data:{},options:a});if(!!n)return{dialogId:n.dialogId,value:n.value,closeDialog:async()=>{await o.closeDialog({dialogId:void 0,dialogType:"location"})}}},closeCurrentLocationDialog:async()=>{await o.closeDialog({dialogId:void 0,dialogType:"location"})},dialogContext:e.dialogContext};return window.UniformMeshSDK=i,i}}async function f({dialogResponseHandlers:l}){let o=await D();return o.on("dialog-value",{},async({data:e})=>{let i=l[e.dialogId];!i||(e.value?i.resolve({value:e.value,dialogId:e.dialogId}):e.error&&i.reject(e.error),delete l[e.dialogId])}),{initialize:async()=>(await o.send(window.parent,"initialize")).data,resize:async e=>{o.send(window.parent,"resize",{height:e})},getValue:async()=>{let e=await o.send(window.parent,"getValue");return e==null?void 0:e.data},setValue:async e=>{await o.send(window.parent,"setValue",e)},getMetadata:async()=>{let e=await o.send(window.parent,"getMetadata");return e==null?void 0:e.data},openDialog:async({dialogType:e,data:i,options:a})=>{var r;if(m(a==null?void 0:a.params)>1e5)throw new Error("Dialog parameters object is too large, maximum size is 100KB");let n=await o.send(window.parent,"openDialog",{dialogType:e,dialogData:i,options:a}),t=(r=n==null?void 0:n.data)==null?void 0:r.dialogId;if(!!t)return new Promise((c,p)=>{l[t]={resolve:c,reject:p}})},closeDialog:async({dialogId:e,dialogType:i,dialogData:a})=>{await o.send(window.parent,"closeDialog",{dialogId:e,dialogType:i,dialogData:a})}}}function m(l){if(!l||typeof Blob=="undefined")return 0;try{let o=JSON.stringify(l);return new Blob([o]).size}catch(o){throw new Error("Error calculating object size: "+o.message)}}export{v as initializeUniformMeshSDK};
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},L=n=>({message:n.message,name:n.name,stack:n.stack}),V=({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}}},D=n=>{let e=n.data,o="none";return e instanceof Error&&(o="error",e=L(e)),{...n,serialization:o,data:e}},v=n=>n.serialization==="error"?{...n,data:V(n.data)}:n;var w=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 r=(await this.postMessage("request",e,o)).id,s=()=>{this.responseSubscriptions=h(this.responseSubscriptions,r)},a=()=>{this.onDestroyRequestHandlers=h(this.responseSubscriptions,r)};return new Promise((l,p)=>{let y,x=(S,O)=>{clearTimeout(y),s(),a(),O.type==="error_response"?p(S):l(S)},I=()=>{clearTimeout(y),p(new u)};this.responseSubscriptions[r]=x,this.onDestroyRequestHandlers[r]=I,y=setTimeout(()=>{s(),a(),p(new c)},t.timeout||this.requestTimeout)})}onRequest(e,o){let t=async(i,r)=>{try{let s=await o(i,r);this.postMessage("response",e,s,r.id)}catch(s){this.postMessage("error_response",e,s,r.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:r}=await this.getChannel();if(this.destroyed)throw new u;let s=D({type:e,apiVersion:"framepost/v1",key:o,data:t,id:m(),requestId:i});return this.logger.log("posting message from child to parent",s),r.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 D({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 E=class extends w{constructor(e={}){super(e);this.context=e.context||null,this.initListener=this.initListener.bind(this),window.addEventListener("message",this.initListener)}getLogger(){return R("child-client",this.debug)}onChannelInit(e){window.removeEventListener("message",this.initListener),this.messagePort=e.ports[0];let o=this.getInitMessage(this.context);this.logger.log("channel init, posting init message from child to parent",o),this.messagePort.postMessage(o)}destroy(){super.destroy(),window.removeEventListener("message",this.initListener)}};async function M({dialogResponseHandlers:n}){let e=new E({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:r})=>{if(P(r==null?void 0:r.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:r}),a=s==null?void 0:s.dialogId;if(!!a)return new Promise((l,p)=>{n[a]={resolve:l,reject:p}})},closeDialog:async({dialogId:t,dialogType:i,dialogData:r})=>{await e.request("closeDialog",{dialogId:t,dialogType:i,dialogData:r})}}}}function P(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 f,C=({onHeightChange:n,autoResizingDisabled:e})=>{if(typeof window=="undefined")return;let o=window,t=a=>{if(a&&a!==f){f=a,n==null||n(a);return}let l=`${Math.ceil(o.document.documentElement.getBoundingClientRect().height)}px`;l!==f&&(f=l,n==null||n(l))},i=()=>{t()},r=e?void 0:new MutationObserver(i),s={instance:o,height:o.document.documentElement.getBoundingClientRect().height,observer:r,enableAutoResizing:()=>{r==null||r.observe(document.body,{attributes:!0,childList:!0,subtree:!0,characterData:!0}),o.addEventListener("resize",i)},disableAutoResizing:()=>{r==null||r.disconnect(),o.removeEventListener("resize",i)},updateHeight:t};return e||s.enableAutoResizing(),s};var q={};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:q}),{initData:t,parent:i}=o,r={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?void 0:e.contentHeight)?!0:n}),version:t.uniformApiVersion,openLocationDialog:async({locationKey:s,options:a})=>{let l=await i.openDialog({dialogType:"location",data:{locationKey:s},options:a});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:a})=>{let l=await i.openDialog({dialogType:"confirm",data:{titleText:s,bodyText:a}});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 a=await i.openDialog({dialogType:"location",data:{},options:s});if(!!a)return{dialogId:a.dialogId,value:a.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=r,r}}export{oe as initializeUniformMeshSDK};
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- var f=Object.create;var r=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var T=Object.getPrototypeOf,V=Object.prototype.hasOwnProperty;var d=a=>r(a,"__esModule",{value:!0});var v=(a,o)=>{for(var e in o)r(a,e,{get:o[e],enumerable:!0})},g=(a,o,e,n)=>{if(o&&typeof o=="object"||typeof o=="function")for(let i of y(o))!V.call(a,i)&&(e||i!=="default")&&r(a,i,{get:()=>o[i],enumerable:!(n=m(o,i))||n.enumerable});return a},x=(a,o)=>g(d(r(a!=null?f(T(a)):{},"default",!o&&a&&a.__esModule?{get:()=>a.default,enumerable:!0}:{value:a,enumerable:!0})),a),b=(a=>(o,e)=>a&&a.get(o)||(e=g(d({}),o,1),a&&a.set(o,e),e))(typeof WeakMap!="undefined"?new WeakMap:0);var z={};v(z,{initializeUniformMeshSDK:()=>k});var c,p=({onHeightChange:a,autoResizingDisabled:o})=>{if(typeof window=="undefined")return;let e=window,n=()=>{let l=Math.ceil(e.document.documentElement.getBoundingClientRect().height);l!==c&&(c=l,a==null||a(l))},i=o?void 0:new MutationObserver(n),t={instance:e,observer:i,height:0,enableAutoResizing:()=>{i==null||i.observe(document.body,{attributes:!0,childList:!0,subtree:!0,characterData:!0}),e.addEventListener("resize",n)},disableAutoResizing:()=>{i==null||i.disconnect(),e.removeEventListener("resize",n)}};return o||t.enableAutoResizing(),t};var I=()=>import("post-robot"),h={};async function k({autoResizingDisabled:a}={}){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:h}),e=await o.initialize(),n={getCurrentLocation:()=>({getValue:()=>e.locationValue,setValue:async i=>{await o.setValue(i),e.locationValue=i},getMetadata:()=>e.locationMetadata}),currentWindow:p({onHeightChange:i=>{o.resize(i)},autoResizingDisabled:a}),version:e.uniformApiVersion,openLocationDialog:async({locationKey:i,options:t})=>{let l=await o.openDialog({dialogType:"location",data:{locationKey:i},options:t});if(!!l)return{dialogId:l.dialogId,value:l.value,closeDialog:async()=>{await o.closeDialog({dialogId:l.dialogId,dialogType:"location"})}}},closeLocationDialog:async({dialogId:i})=>{await o.closeDialog({dialogId:i,dialogType:"location"})},openConfirmationDialog:async({titleText:i,bodyText:t})=>{let l=await o.openDialog({dialogType:"confirm",data:{titleText:i,bodyText:t}});if(!!l)return{value:l.value,closeDialog:async()=>{await o.closeDialog({dialogId:void 0,dialogType:"confirm"})}}},closeConfirmationDialog:async()=>{await o.closeDialog({dialogId:void 0,dialogType:"confirm"})},openCurrentLocationDialog:async({options:i})=>{let t=await o.openDialog({dialogType:"location",data:{},options:i});if(!!t)return{dialogId:t.dialogId,value:t.value,closeDialog:async()=>{await o.closeDialog({dialogId:void 0,dialogType:"location"})}}},closeCurrentLocationDialog:async()=>{await o.closeDialog({dialogId:void 0,dialogType:"location"})},dialogContext:e.dialogContext};return window.UniformMeshSDK=n,n}}async function M({dialogResponseHandlers:a}){let o=await I();return o.on("dialog-value",{},async({data:e})=>{let n=a[e.dialogId];!n||(e.value?n.resolve({value:e.value,dialogId:e.dialogId}):e.error&&n.reject(e.error),delete a[e.dialogId])}),{initialize:async()=>(await o.send(window.parent,"initialize")).data,resize:async e=>{o.send(window.parent,"resize",{height:e})},getValue:async()=>{let e=await o.send(window.parent,"getValue");return e==null?void 0:e.data},setValue:async e=>{await o.send(window.parent,"setValue",e)},getMetadata:async()=>{let e=await o.send(window.parent,"getMetadata");return e==null?void 0:e.data},openDialog:async({dialogType:e,data:n,options:i})=>{var s;if(R(i==null?void 0:i.params)>1e5)throw new Error("Dialog parameters object is too large, maximum size is 100KB");let t=await o.send(window.parent,"openDialog",{dialogType:e,dialogData:n,options:i}),l=(s=t==null?void 0:t.data)==null?void 0:s.dialogId;if(!!l)return new Promise((D,w)=>{a[l]={resolve:D,reject:w}})},closeDialog:async({dialogId:e,dialogType:n,dialogData:i})=>{await o.send(window.parent,"closeDialog",{dialogId:e,dialogType:n,dialogData:i})}}}function R(a){if(!a||typeof Blob=="undefined")return 0;try{let o=JSON.stringify(a);return new Blob([o]).size}catch(o){throw new Error("Error calculating object size: "+o.message)}}module.exports=b(z);0&&(module.exports={initializeUniformMeshSDK});
1
+ var y=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames;var P=Object.prototype.hasOwnProperty;var q=n=>y(n,"__esModule",{value:!0});var k=(n,e)=>{for(var o in e)y(n,o,{get:e[o],enumerable:!0})},z=(n,e,o,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of V(e))!P.call(n,i)&&(o||i!=="default")&&y(n,i,{get:()=>e[i],enumerable:!(t=L(e,i))||t.enumerable});return n};var H=(n=>(e,o)=>n&&n.get(e)||(o=z(q({}),e,1),n&&n.set(e,o),o))(typeof WeakMap!="undefined"?new WeakMap:0);var _={};k(_,{initializeUniformMeshSDK:()=>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},N=n=>({message:n.message,name:n.name,stack:n.stack}),U=({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}}},D=n=>{let e=n.data,o="none";return e instanceof Error&&(o="error",e=N(e)),{...n,serialization:o,data:e}},v=n=>n.serialization==="error"?{...n,data:U(n.data)}:n;var w=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 r=(await this.postMessage("request",e,o)).id,s=()=>{this.responseSubscriptions=p(this.responseSubscriptions,r)},a=()=>{this.onDestroyRequestHandlers=p(this.responseSubscriptions,r)};return new Promise((l,u)=>{let f,x=(S,O)=>{clearTimeout(f),s(),a(),O.type==="error_response"?u(S):l(S)},I=()=>{clearTimeout(f),u(new c)};this.responseSubscriptions[r]=x,this.onDestroyRequestHandlers[r]=I,f=setTimeout(()=>{s(),a(),u(new g)},t.timeout||this.requestTimeout)})}onRequest(e,o){let t=async(i,r)=>{try{let s=await o(i,r);this.postMessage("response",e,s,r.id)}catch(s){this.postMessage("error_response",e,s,r.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:r}=await this.getChannel();if(this.destroyed)throw new c;let s=D({type:e,apiVersion:"framepost/v1",key:o,data:t,id:h(),requestId:i});return this.logger.log("posting message from child to parent",s),r.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 D({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 E=class extends w{constructor(e={}){super(e);this.context=e.context||null,this.initListener=this.initListener.bind(this),window.addEventListener("message",this.initListener)}getLogger(){return R("child-client",this.debug)}onChannelInit(e){window.removeEventListener("message",this.initListener),this.messagePort=e.ports[0];let o=this.getInitMessage(this.context);this.logger.log("channel init, posting init message from child to parent",o),this.messagePort.postMessage(o)}destroy(){super.destroy(),window.removeEventListener("message",this.initListener)}};async function M({dialogResponseHandlers:n}){let e=new E({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:r})=>{if(W(r==null?void 0:r.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:r}),a=s==null?void 0:s.dialogId;if(!!a)return new Promise((l,u)=>{n[a]={resolve:l,reject:u}})},closeDialog:async({dialogId:t,dialogType:i,dialogData:r})=>{await e.request("closeDialog",{dialogId:t,dialogType:i,dialogData:r})}}}}function W(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 m,C=({onHeightChange:n,autoResizingDisabled:e})=>{if(typeof window=="undefined")return;let o=window,t=a=>{if(a&&a!==m){m=a,n==null||n(a);return}let l=`${Math.ceil(o.document.documentElement.getBoundingClientRect().height)}px`;l!==m&&(m=l,n==null||n(l))},i=()=>{t()},r=e?void 0:new MutationObserver(i),s={instance:o,height:o.document.documentElement.getBoundingClientRect().height,observer:r,enableAutoResizing:()=>{r==null||r.observe(document.body,{attributes:!0,childList:!0,subtree:!0,characterData:!0}),o.addEventListener("resize",i)},disableAutoResizing:()=>{r==null||r.disconnect(),o.removeEventListener("resize",i)},updateHeight:t};return e||s.enableAutoResizing(),s};var Q={};async function A({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:Q}),{initData:t,parent:i}=o,r={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?void 0:e.contentHeight)?!0:n}),version:t.uniformApiVersion,openLocationDialog:async({locationKey:s,options:a})=>{let l=await i.openDialog({dialogType:"location",data:{locationKey:s},options:a});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:a})=>{let l=await i.openDialog({dialogType:"confirm",data:{titleText:s,bodyText:a}});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 a=await i.openDialog({dialogType:"location",data:{},options:s});if(!!a)return{dialogId:a.dialogId,value:a.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=r,r}}module.exports=H(_);0&&(module.exports={initializeUniformMeshSDK});
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- var g,u=({onHeightChange:l,autoResizingDisabled:o})=>{if(typeof window=="undefined")return;let e=window,i=()=>{let t=Math.ceil(e.document.documentElement.getBoundingClientRect().height);t!==g&&(g=t,l==null||l(t))},a=o?void 0:new MutationObserver(i),n={instance:e,observer:a,height:0,enableAutoResizing:()=>{a==null||a.observe(document.body,{attributes:!0,childList:!0,subtree:!0,characterData:!0}),e.addEventListener("resize",i)},disableAutoResizing:()=>{a==null||a.disconnect(),e.removeEventListener("resize",i)}};return o||n.enableAutoResizing(),n};var D=()=>import("post-robot"),w={};async function v({autoResizingDisabled:l}={}){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 f({dialogResponseHandlers:w}),e=await o.initialize(),i={getCurrentLocation:()=>({getValue:()=>e.locationValue,setValue:async a=>{await o.setValue(a),e.locationValue=a},getMetadata:()=>e.locationMetadata}),currentWindow:u({onHeightChange:a=>{o.resize(a)},autoResizingDisabled:l}),version:e.uniformApiVersion,openLocationDialog:async({locationKey:a,options:n})=>{let t=await o.openDialog({dialogType:"location",data:{locationKey:a},options:n});if(!!t)return{dialogId:t.dialogId,value:t.value,closeDialog:async()=>{await o.closeDialog({dialogId:t.dialogId,dialogType:"location"})}}},closeLocationDialog:async({dialogId:a})=>{await o.closeDialog({dialogId:a,dialogType:"location"})},openConfirmationDialog:async({titleText:a,bodyText:n})=>{let t=await o.openDialog({dialogType:"confirm",data:{titleText:a,bodyText:n}});if(!!t)return{value:t.value,closeDialog:async()=>{await o.closeDialog({dialogId:void 0,dialogType:"confirm"})}}},closeConfirmationDialog:async()=>{await o.closeDialog({dialogId:void 0,dialogType:"confirm"})},openCurrentLocationDialog:async({options:a})=>{let n=await o.openDialog({dialogType:"location",data:{},options:a});if(!!n)return{dialogId:n.dialogId,value:n.value,closeDialog:async()=>{await o.closeDialog({dialogId:void 0,dialogType:"location"})}}},closeCurrentLocationDialog:async()=>{await o.closeDialog({dialogId:void 0,dialogType:"location"})},dialogContext:e.dialogContext};return window.UniformMeshSDK=i,i}}async function f({dialogResponseHandlers:l}){let o=await D();return o.on("dialog-value",{},async({data:e})=>{let i=l[e.dialogId];!i||(e.value?i.resolve({value:e.value,dialogId:e.dialogId}):e.error&&i.reject(e.error),delete l[e.dialogId])}),{initialize:async()=>(await o.send(window.parent,"initialize")).data,resize:async e=>{o.send(window.parent,"resize",{height:e})},getValue:async()=>{let e=await o.send(window.parent,"getValue");return e==null?void 0:e.data},setValue:async e=>{await o.send(window.parent,"setValue",e)},getMetadata:async()=>{let e=await o.send(window.parent,"getMetadata");return e==null?void 0:e.data},openDialog:async({dialogType:e,data:i,options:a})=>{var r;if(m(a==null?void 0:a.params)>1e5)throw new Error("Dialog parameters object is too large, maximum size is 100KB");let n=await o.send(window.parent,"openDialog",{dialogType:e,dialogData:i,options:a}),t=(r=n==null?void 0:n.data)==null?void 0:r.dialogId;if(!!t)return new Promise((c,p)=>{l[t]={resolve:c,reject:p}})},closeDialog:async({dialogId:e,dialogType:i,dialogData:a})=>{await o.send(window.parent,"closeDialog",{dialogId:e,dialogType:i,dialogData:a})}}}function m(l){if(!l||typeof Blob=="undefined")return 0;try{let o=JSON.stringify(l);return new Blob([o]).size}catch(o){throw new Error("Error calculating object size: "+o.message)}}export{v as initializeUniformMeshSDK};
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},L=n=>({message:n.message,name:n.name,stack:n.stack}),V=({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}}},D=n=>{let e=n.data,o="none";return e instanceof Error&&(o="error",e=L(e)),{...n,serialization:o,data:e}},v=n=>n.serialization==="error"?{...n,data:V(n.data)}:n;var w=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 r=(await this.postMessage("request",e,o)).id,s=()=>{this.responseSubscriptions=h(this.responseSubscriptions,r)},a=()=>{this.onDestroyRequestHandlers=h(this.responseSubscriptions,r)};return new Promise((l,p)=>{let y,x=(S,O)=>{clearTimeout(y),s(),a(),O.type==="error_response"?p(S):l(S)},I=()=>{clearTimeout(y),p(new u)};this.responseSubscriptions[r]=x,this.onDestroyRequestHandlers[r]=I,y=setTimeout(()=>{s(),a(),p(new c)},t.timeout||this.requestTimeout)})}onRequest(e,o){let t=async(i,r)=>{try{let s=await o(i,r);this.postMessage("response",e,s,r.id)}catch(s){this.postMessage("error_response",e,s,r.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:r}=await this.getChannel();if(this.destroyed)throw new u;let s=D({type:e,apiVersion:"framepost/v1",key:o,data:t,id:m(),requestId:i});return this.logger.log("posting message from child to parent",s),r.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 D({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 E=class extends w{constructor(e={}){super(e);this.context=e.context||null,this.initListener=this.initListener.bind(this),window.addEventListener("message",this.initListener)}getLogger(){return R("child-client",this.debug)}onChannelInit(e){window.removeEventListener("message",this.initListener),this.messagePort=e.ports[0];let o=this.getInitMessage(this.context);this.logger.log("channel init, posting init message from child to parent",o),this.messagePort.postMessage(o)}destroy(){super.destroy(),window.removeEventListener("message",this.initListener)}};async function M({dialogResponseHandlers:n}){let e=new E({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:r})=>{if(P(r==null?void 0:r.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:r}),a=s==null?void 0:s.dialogId;if(!!a)return new Promise((l,p)=>{n[a]={resolve:l,reject:p}})},closeDialog:async({dialogId:t,dialogType:i,dialogData:r})=>{await e.request("closeDialog",{dialogId:t,dialogType:i,dialogData:r})}}}}function P(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 f,C=({onHeightChange:n,autoResizingDisabled:e})=>{if(typeof window=="undefined")return;let o=window,t=a=>{if(a&&a!==f){f=a,n==null||n(a);return}let l=`${Math.ceil(o.document.documentElement.getBoundingClientRect().height)}px`;l!==f&&(f=l,n==null||n(l))},i=()=>{t()},r=e?void 0:new MutationObserver(i),s={instance:o,height:o.document.documentElement.getBoundingClientRect().height,observer:r,enableAutoResizing:()=>{r==null||r.observe(document.body,{attributes:!0,childList:!0,subtree:!0,characterData:!0}),o.addEventListener("resize",i)},disableAutoResizing:()=>{r==null||r.disconnect(),o.removeEventListener("resize",i)},updateHeight:t};return e||s.enableAutoResizing(),s};var q={};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:q}),{initData:t,parent:i}=o,r={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?void 0:e.contentHeight)?!0:n}),version:t.uniformApiVersion,openLocationDialog:async({locationKey:s,options:a})=>{let l=await i.openDialog({dialogType:"location",data:{locationKey:s},options:a});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:a})=>{let l=await i.openDialog({dialogType:"confirm",data:{titleText:s,bodyText:a}});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 a=await i.openDialog({dialogType:"location",data:{},options:s});if(!!a)return{dialogId:a.dialogId,value:a.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=r,r}}export{oe as initializeUniformMeshSDK};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/mesh-sdk",
3
- "version": "14.1.1",
3
+ "version": "14.1.2-alpha.99+0e111aa4",
4
4
  "description": "Uniform Mesh Framework SDK",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./dist/index.js",
@@ -24,19 +24,15 @@
24
24
  "ci:verify": "run-p lint test",
25
25
  "ci:build": "tsup --minify --clean"
26
26
  },
27
- "dependencies": {
28
- "post-robot": "10.0.44"
29
- },
30
27
  "devDependencies": {
31
- "@types/jest": "27.4.0",
32
- "@types/node": "16.11.21",
33
- "@types/post-robot": "10.0.3",
34
- "eslint": "8.7.0",
35
- "jest": "27.4.7",
28
+ "@types/jest": "27.4.1",
29
+ "@types/node": "16.11.25",
30
+ "eslint": "8.9.0",
31
+ "jest": "27.5.1",
36
32
  "npm-run-all": "4.1.5",
37
33
  "rimraf": "3.0.2",
38
34
  "ts-jest": "27.1.3",
39
- "tsup": "5.11.11"
35
+ "tsup": "5.11.13"
40
36
  },
41
37
  "files": [
42
38
  "/dist"
@@ -44,5 +40,5 @@
44
40
  "publishConfig": {
45
41
  "access": "public"
46
42
  },
47
- "gitHead": "af0cab00330e67e5aab9f3891747098004317b95"
43
+ "gitHead": "0e111aa47ed0c8581baf1b049738f0967ab50a31"
48
44
  }