Socket
Socket
Sign inDemoInstall

@chili-publish/publisher-interface

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@chili-publish/publisher-interface - npm Package Compare versions

Comparing version 0.4.0 to 1.0.0

2

dist/PublisherInterface.min.js

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

var e,t,r,i,o,n,s,c,a,d,u,h,l={};e=l,t="PublisherInterface",r=()=>T,i=e=>T=e,Object.defineProperty(e,t,{get:r,set:i,enumerable:!0,configurable:!0}),(n=o||(o={})).Call="call",n.Reply="reply",n.Syn="syn",n.SynAck="synAck",n.Ack="ack",(c=s||(s={})).Fulfilled="fulfilled",c.Rejected="rejected",(d=a||(a={})).ConnectionDestroyed="ConnectionDestroyed",d.ConnectionTimeout="ConnectionTimeout",d.NoIframeSrc="NoIframeSrc",(u||(u={})).DataCloneError="DataCloneError",(h||(h={})).Message="message";var g=(e,t)=>{const r=[];let i=!1;return{destroy(o){i||(i=!0,t(`${e}: Destroying connection`),r.forEach((e=>{e(o)})))},onDestroy(e){i?e():r.push(e)}}},f=e=>(...t)=>{e&&console.log("[Penpal]",...t)};const v={"http:":"80","https:":"443"},b=/^(https?:)?\/\/([^/:]+)?(:(\d+))?/,m=["file:","data:"];var w=e=>{if(e&&m.find((t=>e.startsWith(t))))return"null";const t=document.location,r=b.exec(e);let i,o,n;r?(i=r[1]?r[1]:t.protocol,o=r[2],n=r[4]):(i=t.protocol,o=t.hostname,n=t.port);return`${i}//${o}${n&&n!==v[i]?`:${n}`:""}`};const E=({name:e,message:t,stack:r})=>({name:e,message:t,stack:r}),p=e=>{const t=new Error;return Object.keys(e).forEach((r=>t[r]=e[r])),t};var y=(e,t,r)=>{const{localName:i,local:n,remote:c,originForSending:a,originForReceiving:d}=e;let l=!1;const g=e=>{if(e.source!==c||e.data.penpal!==o.Call)return;if("*"!==d&&e.origin!==d)return void r(`${i} received message from origin ${e.origin} which did not match expected origin ${d}`);const n=e.data,{methodName:h,args:g,id:f}=n;r(`${i}: Received ${h}() call`);const v=e=>t=>{if(r(`${i}: Sending ${h}() reply`),l)return void r(`${i}: Unable to send ${h}() reply due to destroyed connection`);const n={penpal:o.Reply,id:f,resolution:e,returnValue:t};e===s.Rejected&&t instanceof Error&&(n.returnValue=E(t),n.returnValueIsError=!0);try{c.postMessage(n,a)}catch(e){if(e.name===u.DataCloneError){const t={penpal:o.Reply,id:f,resolution:s.Rejected,returnValue:E(e),returnValueIsError:!0};c.postMessage(t,a)}throw e}};new Promise((e=>e(t[h].apply(t,g)))).then(v(s.Fulfilled),v(s.Rejected))};return n.addEventListener(h.Message,g),()=>{l=!0,n.removeEventListener(h.Message,g)}};let S=0;const P=e=>e?e.split("."):[],L=(e,t,r)=>{const i=P(t);return i.reduce(((e,t,o)=>(void 0===e[t]&&(e[t]={}),o===i.length-1&&(e[t]=r),e[t])),e),e},j=(e,t)=>{const r={};return Object.keys(e).forEach((i=>{const o=e[i],n=((e,t)=>{const r=P(t||"");return r.push(e),(e=>e.join("."))(r)})(i,t);"object"==typeof o&&Object.assign(r,j(o,n)),"function"==typeof o&&(r[n]=o)})),r},F=e=>{const t={};for(const r in e)L(t,r,e[r]);return t};var D=(e,t,r,i,n)=>{const{localName:c,local:d,remote:u,originForSending:l,originForReceiving:g}=t;let f=!1;n(`${c}: Connecting call sender`);const v=e=>(...t)=>{let r;n(`${c}: Sending ${e}() call`);try{u.closed&&(r=!0)}catch(e){r=!0}if(r&&i(),f){const t=new Error(`Unable to send ${e}() call due to destroyed connection`);throw t.code=a.ConnectionDestroyed,t}return new Promise(((r,i)=>{const a=++S,f=t=>{if(t.source!==u||t.data.penpal!==o.Reply||t.data.id!==a)return;if("*"!==g&&t.origin!==g)return void n(`${c} received message from origin ${t.origin} which did not match expected origin ${g}`);const l=t.data;n(`${c}: Received ${e}() reply`),d.removeEventListener(h.Message,f);let v=l.returnValue;l.returnValueIsError&&(v=p(v)),(l.resolution===s.Fulfilled?r:i)(v)};d.addEventListener(h.Message,f);const v={penpal:o.Call,id:a,methodName:e,args:t};u.postMessage(v,l)}))},b=r.reduce(((e,t)=>(e[t]=v(t),e)),{});return Object.assign(e,F(b)),()=>{f=!0}},A=(e,t,r,i,o)=>{const{destroy:n,onDestroy:s}=i;let c,a;const d={};return i=>{if("*"!==t&&i.origin!==t)return void o(`Parent: Handshake - Received ACK message from origin ${i.origin} which did not match expected origin ${t}`);o("Parent: Handshake - Received ACK");const u={localName:"Parent",local:window,remote:i.source,originForSending:r,originForReceiving:t};c&&c(),c=y(u,e,o),s(c),a&&a.forEach((e=>{delete d[e]})),a=i.data.methodNames;const h=D(d,u,a,n,o);return s(h),d}},k=(e,t,r,i)=>n=>{if(!n.source)return;if("*"!==r&&n.origin!==r)return void e(`Parent: Handshake - Received SYN message from origin ${n.origin} which did not match expected origin ${r}`);e("Parent: Handshake - Received SYN, responding with SYN-ACK");const s={penpal:o.SynAck,methodNames:Object.keys(t)};n.source.postMessage(s,i)};var I=(e,t)=>{const{destroy:r,onDestroy:i}=t,o=setInterval((()=>{e.isConnected||(clearInterval(o),r())}),6e4);i((()=>{clearInterval(o)}))},$=(e,t)=>{let r;return void 0!==e&&(r=window.setTimeout((()=>{const r=new Error(`Connection timed out after ${e}ms`);r.code=a.ConnectionTimeout,t(r)}),e)),()=>{clearTimeout(r)}},C=e=>{if(!e.src&&!e.srcdoc){const e=new Error("Iframe must have src or srcdoc property defined.");throw e.code=a.NoIframeSrc,e}},N=e=>{let{iframe:t,methods:r={},childOrigin:i,timeout:n,debug:s=!1}=e;const c=f(s),a=g("Parent",c),{onDestroy:d,destroy:u}=a;i||(C(t),i=w(t.src));const l="null"===i?"*":i,v=j(r),b=k(c,v,i,l),m=A(v,i,l,a,c);return{promise:new Promise(((e,r)=>{const i=$(n,u),s=r=>{if(r.source===t.contentWindow&&r.data)if(r.data.penpal!==o.Syn)if(r.data.penpal!==o.Ack);else{const t=m(r);t&&(i(),e(t))}else b(r)};window.addEventListener(h.Message,s),c("Parent: Awaiting handshake"),I(t,a),d((e=>{window.removeEventListener(h.Message,s),e&&r(e)}))})),destroy(){u()}}};var x,R=function(e,t,r,i){return new(r||(r=Promise))((function(o,n){function s(e){try{a(i.next(e))}catch(e){n(e)}}function c(e){try{a(i.throw(e))}catch(e){n(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,c)}a((i=i.apply(e,t||[])).next())}))},O=function(e,t,r,i){if("a"===r&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?i:"a"===r?i.call(e):i?i.value:t.get(e)},M=function(e,t,r,i,o){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!o)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!o:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?o.call(e,r):o?o.value=r:t.set(e,r),r};class T{constructor(){this.customFunction={register:function(e,t){throw new Error("Function not implemented.")},registerOnEvent:function(e,t){throw new Error("Function not implemented.")},execute:function(e,t){throw new Error("Function not implemented.")}},this.chiliEventListenerCallbacks=new Map,this.debug=!1,this.creationTime="",x.set(this,null),this.getProperty=this.getObject}static build(e,t={}){var r;return R(this,void 0,void 0,(function*(){const i=new T;var o,n;i.child=yield N({iframe:e,methods:{handleEvents:i.handleEvents.bind(i)},timeout:t.timeout,debug:t.penpalDebug}).promise,i.customFunction=(o=i.child,n=i.createDebugLog.bind(i),{register:function(e,t){return R(this,void 0,void 0,(function*(){n("registerFunction()");const r=yield o.registerFunction(e,t);if(r.isError)throw new Error(r.error)}))},registerOnEvent:function(e,t){return R(this,void 0,void 0,(function*(){n("registerFunction()");const r=yield o.registerFunctionOnEvent(e,t);if(r.isError)throw new Error(r.error)}))},execute:function(e,...t){return R(this,void 0,void 0,(function*(){n("executeRegisteredFunction()");const r=yield o.executeRegisteredFunction(e,t);if(r.isError)throw new Error(r.error);return r.ok}))}}),i.debug=null!==(r=t.penpalDebug)&&void 0!==r&&r,i.creationTime=(new Date).toLocaleString(),i.createDebugLog("build()");const s=t.events;if(null!=s&&s.length>0)for(const e of s)"string"==typeof e?i.addListener(e):i.addListener(e.name,e.func);return i}))}handleEvents(e,t){var r;return this.chiliEventListenerCallbacks.has(e)&&(null===(r=this.chiliEventListenerCallbacks.get(e))||void 0===r||r(t)),e}createDebugLog(e){this.debug&&console.log(`[PublisherInterface - ${this.creationTime}]`,`Creating ${e} call request`)}get editorObject(){return null==O(this,x,"f")&&M(this,x,{Alert:this.alert.bind(this),GetDirtyState:this.getDirtyState.bind(this),NextPage:this.nextPage.bind(this),PreviousPage:this.previousPage.bind(this),SetSelectedPage:this.setSelectedPage.bind(this),GetSelectedPage:this.getSelectedPage.bind(this),GetSelectedPageName:this.getSelectedPageName.bind(this),GetNumPages:this.getNumPages.bind(this),RemoveListener:this.removeListener.bind(this),AddListener:this.addListener.bind(this),GetObject:this.getObject.bind(this),SetProperty:this.setProperty.bind(this),ExecuteFunction:this.executeFunction.bind(this),GetPageSnapshot:this.getPageSnapshot.bind(this),GetFrameSnapshot:this.getFrameSnapshot.bind(this),GetFrameSubjectArea:this.getFrameSubjectArea.bind(this),SetFrameSubjectArea:this.setFrameSubjectArea.bind(this),ClearFrameSubjectArea:this.clearFrameSubjectArea.bind(this),GetAssetSubjectInfo:this.getAssetSubjectInfo.bind(this),SetAssetSubjectInfo:this.setAssetSubjectInfo.bind(this),ClearAssetSubjectInfo:this.clearAssetSubjectInfo.bind(this),SetVariableIsLocked:this.setVariableIsLocked.bind(this)},"f"),O(this,x,"f")}alert(e,t){return R(this,void 0,void 0,(function*(){this.createDebugLog("alert()");const r=yield this.child.alert(e,t);if(r.isError)throw new Error(r.error)}))}getDirtyState(){return R(this,void 0,void 0,(function*(){this.createDebugLog("getDirtyState()");const e=yield this.child.getDirtyState();if(e.isError)throw new Error(e.error);return e.ok}))}nextPage(){return R(this,void 0,void 0,(function*(){this.createDebugLog("nextPage()");const e=yield this.child.nextPage();if(e.isError)throw new Error(e.error)}))}previousPage(){return R(this,void 0,void 0,(function*(){this.createDebugLog("previousPage()");const e=yield this.child.previousPage();if(e.isError)throw new Error(e.error)}))}setSelectedPage(e){return R(this,void 0,void 0,(function*(){this.createDebugLog("setSelectedPage()");const t=yield this.child.setSelectedPage(e);if(t.isError)throw new Error(t.error)}))}getSelectedPage(){return R(this,void 0,void 0,(function*(){this.createDebugLog("getSelectedPage()");const e=yield this.child.getSelectedPage();if(e.isError)throw new Error(e.error);return e.ok}))}getSelectedPageName(){return R(this,void 0,void 0,(function*(){this.createDebugLog("getSelectedPageName()");const e=yield this.child.getSelectedPageName();if(e.isError)throw new Error(e.error);return e.ok}))}getNumPages(){return R(this,void 0,void 0,(function*(){this.createDebugLog("getNumPages()");const e=yield this.child.getNumPages();if(e.isError)throw new Error(e.error);return e.ok}))}removeListener(e){return R(this,void 0,void 0,(function*(){this.createDebugLog("removeListener()"),this.chiliEventListenerCallbacks.delete(e);const t=yield this.child.removeListener(e);if(t.isError)throw new Error(t.error)}))}addListener(e,t){return R(this,void 0,void 0,(function*(){this.createDebugLog("addListener()"),this.chiliEventListenerCallbacks.set(e,null==t?t=>{null!=window.OnEditorEvent&&window.OnEditorEvent(e,t)}:t);const r=yield this.child.addListener(e);if(r.isError)throw new Error(r.error)}))}getObject(e){return R(this,void 0,void 0,(function*(){this.createDebugLog("getObject()");const t=yield this.child.getObject(e);if(t.isError)throw new Error(t.error);return t.ok}))}setProperty(e,t,r){return R(this,void 0,void 0,(function*(){this.createDebugLog("setProperty()");const i=yield this.child.setProperty(e,t,r);if(i.isError)throw new Error(i.error)}))}executeFunction(e,t,...r){return R(this,void 0,void 0,(function*(){this.createDebugLog("executeFunction()");const i=yield this.child.executeFunction(e,t,r);if(i.isError)throw new Error(i.error);return i.ok}))}getPageSnapshot(e,t,r,i,o,n){return R(this,void 0,void 0,(function*(){this.createDebugLog("getPageSnapshot()");const s=yield this.child.getPageSnapshot(e,t,r,i,o,n);if(s.isError)throw new Error(s.error);return s.ok}))}getFrameSnapshot(e,t,r){return R(this,void 0,void 0,(function*(){this.createDebugLog("getFrameSnapshot()");const i=yield this.child.getFrameSnapshot(e,t,r);if(i.isError)throw new Error(i.error);return i.ok}))}getFrameSubjectArea(e){return R(this,void 0,void 0,(function*(){this.createDebugLog("getFrameSubjectArea()");const t=yield this.child.getFrameSubjectArea(e);if(t.isError)throw new Error(t.error);return t.ok}))}setFrameSubjectArea(e,t,r,i,o){return R(this,void 0,void 0,(function*(){this.createDebugLog("setFrameSubjectArea()");const n=yield this.child.setFrameSubjectArea(e,t,r,i,o);if(n.isError)throw new Error(n.error)}))}clearFrameSubjectArea(e){return R(this,void 0,void 0,(function*(){this.createDebugLog("clearFrameSubjectArea()");const t=yield this.child.clearFrameSubjectArea(e);if(t.isError)throw new Error(t.error)}))}getAssetSubjectInfo(e){return R(this,void 0,void 0,(function*(){this.createDebugLog("getAssetSubjectInfo()");const t=yield this.child.getAssetSubjectInfo(e);if(t.isError)throw new Error(t.error);return t.ok}))}setAssetSubjectInfo(e,t,r,i,o,n,s){return R(this,void 0,void 0,(function*(){this.createDebugLog("setAssetSubjectInfo()");const c=yield this.child.setAssetSubjectInfo(e,t,r,i,o,n,s);if(c.isError)throw new Error(c.error)}))}clearAssetSubjectInfo(e){return R(this,void 0,void 0,(function*(){this.createDebugLog("clearAssetSubjectInfo()");const t=yield this.child.clearAssetSubjectInfo(e);if(t.isError)throw new Error(t.error)}))}setVariableIsLocked(e,t){return R(this,void 0,void 0,(function*(){this.createDebugLog("setVariableIsLocked()");const r=yield this.child.setVariableIsLocked(e,t);if(r.isError)throw new Error(r.error)}))}}x=new WeakMap;export{T as PublisherInterface,l as default};
var e,t,r,n,i,o,s,c,a,d,u,l,h={};e=h,t="PublisherInterface",r=()=>V,n=e=>V=e,Object.defineProperty(e,t,{get:r,set:n,enumerable:!0,configurable:!0}),(o=i||(i={})).Call="call",o.Reply="reply",o.Syn="syn",o.SynAck="synAck",o.Ack="ack",(c=s||(s={})).Fulfilled="fulfilled",c.Rejected="rejected",(d=a||(a={})).ConnectionDestroyed="ConnectionDestroyed",d.ConnectionTimeout="ConnectionTimeout",d.NoIframeSrc="NoIframeSrc",(u||(u={})).DataCloneError="DataCloneError",(l||(l={})).Message="message";var g=(e,t)=>{const r=[];let n=!1;return{destroy(i){n||(n=!0,t(`${e}: Destroying connection`),r.forEach((e=>{e(i)})))},onDestroy(e){n?e():r.push(e)}}},f=e=>(...t)=>{e&&console.log("[Penpal]",...t)};const m={"http:":"80","https:":"443"},b=/^(https?:)?\/\/([^/:]+)?(:(\d+))?/,v=["file:","data:"];var w=e=>{if(e&&v.find((t=>e.startsWith(t))))return"null";const t=document.location,r=b.exec(e);let n,i,o;r?(n=r[1]?r[1]:t.protocol,i=r[2],o=r[4]):(n=t.protocol,i=t.hostname,o=t.port);return`${n}//${i}${o&&o!==m[n]?`:${o}`:""}`};const E=({name:e,message:t,stack:r})=>({name:e,message:t,stack:r}),p=e=>{const t=new Error;return Object.keys(e).forEach((r=>t[r]=e[r])),t};var y=(e,t,r)=>{const{localName:n,local:o,remote:c,originForSending:a,originForReceiving:d}=e;let h=!1;const g=e=>{if(e.source!==c||e.data.penpal!==i.Call)return;if("*"!==d&&e.origin!==d)return void r(`${n} received message from origin ${e.origin} which did not match expected origin ${d}`);const o=e.data,{methodName:l,args:g,id:f}=o;r(`${n}: Received ${l}() call`);const m=e=>t=>{if(r(`${n}: Sending ${l}() reply`),h)return void r(`${n}: Unable to send ${l}() reply due to destroyed connection`);const o={penpal:i.Reply,id:f,resolution:e,returnValue:t};e===s.Rejected&&t instanceof Error&&(o.returnValue=E(t),o.returnValueIsError=!0);try{c.postMessage(o,a)}catch(e){if(e.name===u.DataCloneError){const t={penpal:i.Reply,id:f,resolution:s.Rejected,returnValue:E(e),returnValueIsError:!0};c.postMessage(t,a)}throw e}};new Promise((e=>e(t[l].apply(t,g)))).then(m(s.Fulfilled),m(s.Rejected))};return o.addEventListener(l.Message,g),()=>{h=!0,o.removeEventListener(l.Message,g)}};let S=0;const P=e=>e?e.split("."):[],L=(e,t,r)=>{const n=P(t);return n.reduce(((e,t,i)=>(void 0===e[t]&&(e[t]={}),i===n.length-1&&(e[t]=r),e[t])),e),e},j=(e,t)=>{const r={};return Object.keys(e).forEach((n=>{const i=e[n],o=((e,t)=>{const r=P(t||"");return r.push(e),(e=>e.join("."))(r)})(n,t);"object"==typeof i&&Object.assign(r,j(i,o)),"function"==typeof i&&(r[o]=i)})),r},N=e=>{const t={};for(const r in e)L(t,r,e[r]);return t};var F=(e,t,r,n,o)=>{const{localName:c,local:d,remote:u,originForSending:h,originForReceiving:g}=t;let f=!1;o(`${c}: Connecting call sender`);const m=e=>(...t)=>{let r;o(`${c}: Sending ${e}() call`);try{u.closed&&(r=!0)}catch(e){r=!0}if(r&&n(),f){const t=new Error(`Unable to send ${e}() call due to destroyed connection`);throw t.code=a.ConnectionDestroyed,t}return new Promise(((r,n)=>{const a=++S,f=t=>{if(t.source!==u||t.data.penpal!==i.Reply||t.data.id!==a)return;if("*"!==g&&t.origin!==g)return void o(`${c} received message from origin ${t.origin} which did not match expected origin ${g}`);const h=t.data;o(`${c}: Received ${e}() reply`),d.removeEventListener(l.Message,f);let m=h.returnValue;h.returnValueIsError&&(m=p(m)),(h.resolution===s.Fulfilled?r:n)(m)};d.addEventListener(l.Message,f);const m={penpal:i.Call,id:a,methodName:e,args:t};u.postMessage(m,h)}))},b=r.reduce(((e,t)=>(e[t]=m(t),e)),{});return Object.assign(e,N(b)),()=>{f=!0}},D=(e,t,r,n,i)=>{const{destroy:o,onDestroy:s}=n;let c,a;const d={};return n=>{if("*"!==t&&n.origin!==t)return void i(`Parent: Handshake - Received ACK message from origin ${n.origin} which did not match expected origin ${t}`);i("Parent: Handshake - Received ACK");const u={localName:"Parent",local:window,remote:n.source,originForSending:r,originForReceiving:t};c&&c(),c=y(u,e,i),s(c),a&&a.forEach((e=>{delete d[e]})),a=n.data.methodNames;const l=F(d,u,a,o,i);return s(l),d}},A=(e,t,r,n)=>o=>{if(!o.source)return;if("*"!==r&&o.origin!==r)return void e(`Parent: Handshake - Received SYN message from origin ${o.origin} which did not match expected origin ${r}`);e("Parent: Handshake - Received SYN, responding with SYN-ACK");const s={penpal:i.SynAck,methodNames:Object.keys(t)};o.source.postMessage(s,n)};var I=(e,t)=>{const{destroy:r,onDestroy:n}=t,i=setInterval((()=>{e.isConnected||(clearInterval(i),r())}),6e4);n((()=>{clearInterval(i)}))},k=(e,t)=>{let r;return void 0!==e&&(r=window.setTimeout((()=>{const r=new Error(`Connection timed out after ${e}ms`);r.code=a.ConnectionTimeout,t(r)}),e)),()=>{clearTimeout(r)}},$=e=>{if(!e.src&&!e.srcdoc){const e=new Error("Iframe must have src or srcdoc property defined.");throw e.code=a.NoIframeSrc,e}},C=e=>{let{iframe:t,methods:r={},childOrigin:n,timeout:o,debug:s=!1}=e;const c=f(s),a=g("Parent",c),{onDestroy:d,destroy:u}=a;n||($(t),n=w(t.src));const h="null"===n?"*":n,m=j(r),b=A(c,m,n,h),v=D(m,n,h,a,c);return{promise:new Promise(((e,r)=>{const n=k(o,u),s=r=>{if(r.source===t.contentWindow&&r.data)if(r.data.penpal!==i.Syn)if(r.data.penpal!==i.Ack);else{const t=v(r);t&&(n(),e(t))}else b(r)};window.addEventListener(l.Message,s),c("Parent: Awaiting handshake"),I(t,a),d((e=>{window.removeEventListener(l.Message,s),e&&r(e)}))})),destroy(){u()}}};var O,R=function(e,t,r,n){return new(r||(r=Promise))((function(i,o){function s(e){try{a(n.next(e))}catch(e){o(e)}}function c(e){try{a(n.throw(e))}catch(e){o(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,c)}a((n=n.apply(e,t||[])).next())}))},x=function(e,t,r,n){if("a"===r&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?n:"a"===r?n.call(e):n?n.value:t.get(e)},M=function(e,t,r,n,i){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===n?i.call(e,r):i?i.value=r:t.set(e,r),r};const T=function(e,t){return{register:function(r,n){return R(this,void 0,void 0,(function*(){t({functionName:"registerFunction()"});const i=yield e.registerFunction(r,n);if(i.isError)throw new Error(i.error)}))},registerOnEvent:function(r,n){return R(this,void 0,void 0,(function*(){t({functionName:"registerFunction()"});const i=yield e.registerFunctionOnEvent(r,n);if(i.isError)throw new Error(i.error)}))},execute:function(r,...n){return R(this,void 0,void 0,(function*(){t({functionName:"executeRegisteredFunction()"});const i=yield e.executeRegisteredFunction(r,n);if(i.isError)throw new Error(i.error);return i.ok}))}}};class V{constructor(){this.customFunction={register:function(e,t){throw new Error("Function not implemented.")},registerOnEvent:function(e,t){throw new Error("Function not implemented.")},execute:function(e,t){throw new Error("Function not implemented.")}},this.chiliEventListenerCallbacks=new Map,this.debug=!1,this.creationTime="",O.set(this,null),this.getProperty=this.getObject}static buildWithIframe(e,t){return R(this,void 0,void 0,(function*(){return V.build(Object.assign({targetIframe:e},t))}))}static buildOnElement(e,t,r){return R(this,void 0,void 0,(function*(){return V.build(Object.assign({parentElement:e,editorURL:t},r))}))}static build(e){var t,r,n,i;return R(this,arguments,void 0,(function*(){if("IFRAME"==arguments[0].tagName){const n=null!==(t=arguments[1])&&void 0!==t?t:{};e=Object.assign(Object.assign({},n),{targetIframe:arguments[0],debug:null!==(r=e.debug)&&void 0!==r?r:n.penpalDebug})}const o=new V;o.creationTime=(new Date).toLocaleString(),o.debug=null!==(n=e.debug)&&void 0!==n&&n,o.createDebugLog({functionName:"build()",customMessage:"Calling build() with options: "+JSON.stringify(e)});const s=null!==(i=e.targetIframe)&&void 0!==i?i:document.createElement("iframe");o.iframe=s,null!=e.editorURL&&(s.src=e.editorURL);const c=C({iframe:s,methods:{handleEvents:o.handleEvents.bind(o)},timeout:e.timeout,debug:e.debug});null!=e.parentElement&&e.parentElement.appendChild(s),o.child=yield c.promise,o.customFunction=T(o.child,o.createDebugLog.bind(o));const a=e.events;if(null!=a&&a.length>0)for(const e of a)"string"==typeof e?o.addListener(e):o.addListener(e.name,e.func);return o}))}handleEvents(e,t){var r;return this.chiliEventListenerCallbacks.has(e)&&(null===(r=this.chiliEventListenerCallbacks.get(e))||void 0===r||r(t)),e}createDebugLog({functionName:e,customMessage:t}){this.debug&&(null!=t?console.log(`[PublisherInterface - ${this.creationTime}]`,`${e} : ${t}`):console.log(`[PublisherInterface - ${this.creationTime}]`,`Creating ${e} call request`))}get editorObject(){return null==x(this,O,"f")&&M(this,O,{Alert:this.alert.bind(this),GetDirtyState:this.getDirtyState.bind(this),NextPage:this.nextPage.bind(this),PreviousPage:this.previousPage.bind(this),SetSelectedPage:this.setSelectedPage.bind(this),GetSelectedPage:this.getSelectedPage.bind(this),GetSelectedPageName:this.getSelectedPageName.bind(this),GetNumPages:this.getNumPages.bind(this),RemoveListener:this.removeListener.bind(this),AddListener:this.addListener.bind(this),GetObject:this.getObject.bind(this),SetProperty:this.setProperty.bind(this),ExecuteFunction:this.executeFunction.bind(this),GetPageSnapshot:this.getPageSnapshot.bind(this),GetFrameSnapshot:this.getFrameSnapshot.bind(this),GetFrameSubjectArea:this.getFrameSubjectArea.bind(this),SetFrameSubjectArea:this.setFrameSubjectArea.bind(this),ClearFrameSubjectArea:this.clearFrameSubjectArea.bind(this),GetAssetSubjectInfo:this.getAssetSubjectInfo.bind(this),SetAssetSubjectInfo:this.setAssetSubjectInfo.bind(this),ClearAssetSubjectInfo:this.clearAssetSubjectInfo.bind(this),SetVariableIsLocked:this.setVariableIsLocked.bind(this)},"f"),x(this,O,"f")}alert(e,t){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"alert()"});const r=yield this.child.alert(e,t);if(r.isError)throw new Error(r.error)}))}getDirtyState(){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"getDirtyState()"});const e=yield this.child.getDirtyState();if(e.isError)throw new Error(e.error);return e.ok}))}nextPage(){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"nextPage()"});const e=yield this.child.nextPage();if(e.isError)throw new Error(e.error)}))}previousPage(){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"previousPage()"});const e=yield this.child.previousPage();if(e.isError)throw new Error(e.error)}))}setSelectedPage(e){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"setSelectedPage()"});const t=yield this.child.setSelectedPage(e);if(t.isError)throw new Error(t.error)}))}getSelectedPage(){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"getSelectedPage()"});const e=yield this.child.getSelectedPage();if(e.isError)throw new Error(e.error);return e.ok}))}getSelectedPageName(){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"getSelectedPageName()"});const e=yield this.child.getSelectedPageName();if(e.isError)throw new Error(e.error);return e.ok}))}getNumPages(){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"getNumPages()"});const e=yield this.child.getNumPages();if(e.isError)throw new Error(e.error);return e.ok}))}removeListener(e){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"removeListener()"}),this.chiliEventListenerCallbacks.delete(e);const t=yield this.child.removeListener(e);if(t.isError)throw new Error(t.error)}))}addListener(e,t){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"addListener()"}),this.chiliEventListenerCallbacks.set(e,null==t?t=>{null!=window.OnEditorEvent&&window.OnEditorEvent(e,t)}:t);const r=yield this.child.addListener(e);if(r.isError)throw new Error(r.error)}))}getObject(e){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"getObject()"});const t=yield this.child.getObject(e);if(t.isError)throw new Error(t.error);return t.ok}))}setProperty(e,t,r){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"setProperty()"});const n=yield this.child.setProperty(e,t,r);if(n.isError)throw new Error(n.error)}))}executeFunction(e,t,...r){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"executeFunction()"});const n=yield this.child.executeFunction(e,t,r);if(n.isError)throw new Error(n.error);return n.ok}))}getPageSnapshot(e,t,r,n,i,o){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"getPageSnapshot()"});const s=yield this.child.getPageSnapshot(e,t,r,n,i,o);if(s.isError)throw new Error(s.error);return s.ok}))}getFrameSnapshot(e,t,r){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"getFrameSnapshot()"});const n=yield this.child.getFrameSnapshot(e,t,r);if(n.isError)throw new Error(n.error);return n.ok}))}getFrameSubjectArea(e){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"getFrameSubjectArea()"});const t=yield this.child.getFrameSubjectArea(e);if(t.isError)throw new Error(t.error);return t.ok}))}setFrameSubjectArea(e,t,r,n,i){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"setFrameSubjectArea()"});const o=yield this.child.setFrameSubjectArea(e,t,r,n,i);if(o.isError)throw new Error(o.error)}))}clearFrameSubjectArea(e){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"clearFrameSubjectArea()"});const t=yield this.child.clearFrameSubjectArea(e);if(t.isError)throw new Error(t.error)}))}getAssetSubjectInfo(e){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"getAssetSubjectInfo()"});const t=yield this.child.getAssetSubjectInfo(e);if(t.isError)throw new Error(t.error);return t.ok}))}setAssetSubjectInfo(e,t,r,n,i,o,s){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"setAssetSubjectInfo()"});const c=yield this.child.setAssetSubjectInfo(e,t,r,n,i,o,s);if(c.isError)throw new Error(c.error)}))}clearAssetSubjectInfo(e){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"clearAssetSubjectInfo()"});const t=yield this.child.clearAssetSubjectInfo(e);if(t.isError)throw new Error(t.error)}))}setVariableIsLocked(e,t){return R(this,void 0,void 0,(function*(){this.createDebugLog({functionName:"setVariableIsLocked()"});const r=yield this.child.setVariableIsLocked(e,t);if(r.isError)throw new Error(r.error)}))}}O=new WeakMap;export{V as PublisherInterface,h as default};
//# sourceMappingURL=PublisherInterface.min.js.map

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

export type buildOptions = {
export type CommonBuildOptions = {
/**

@@ -9,3 +9,3 @@ * If not null, the number of milliseconds to wait for a connection to iframe before throwing an exception.

*/
penpalDebug?: boolean;
debug?: boolean;
/**

@@ -19,2 +19,23 @@ * Pass in an array of events that will be auto-added via `addListener()`

};
export type AllBuildOptions = ({
/**
* iframe element to the PublisherInterface will try to connect with
*/
targetIframe: HTMLIFrameElement;
/**
* The url that will be set on the iframe - this needs to be a valid URL with a valid API key
*/
editorURL?: string;
parentElement?: undefined;
} | {
targetIframe?: undefined;
/**
* The url that will be set on the iframe - this needs to be a valid URL with a valid API key
*/
editorURL: string;
/**
* The element that a new iframe will be created with URL from `edtiorURL`
*/
parentElement: HTMLElement;
}) & CommonBuildOptions;
export type CustomFunctionsInterface = {

@@ -46,3 +67,9 @@ /**

customFunction: CustomFunctionsInterface;
/**
* The IFrame element this PublisherInterface is connected with once successifully connected. Returns undefined if not connected.
*/
iframe: HTMLIFrameElement | undefined;
private constructor();
static buildWithIframe(targetIframe: HTMLIFrameElement, options: CommonBuildOptions): Promise<PublisherInterface>;
static buildOnElement(parentElement: HTMLElement, editorURL: string, options: CommonBuildOptions): Promise<PublisherInterface>;
/**

@@ -55,3 +82,3 @@ * The build method will wait for a connection to the other side of iframe. Must be called before iframe `onload` event is fired.

*/
static build(iframe: HTMLIFrameElement, options?: buildOptions): Promise<PublisherInterface>;
static build(options: AllBuildOptions): Promise<PublisherInterface>;
/**

@@ -58,0 +85,0 @@ * Returns an alias for editorObject with similarly named functions. This is to help with backwards compatibility, but these functions still return a Promise.

@@ -52,3 +52,5 @@ var $7i1sb$penpal = require("penpal");

return $3db7bcc71a7ab568$var$__awaiter(this, void 0, void 0, function*() {
createDebugLog("registerFunction()");
createDebugLog({
functionName: "registerFunction()"
});
const response = yield chiliWrapper.registerFunction(name, body);

@@ -60,3 +62,5 @@ if (response.isError) throw new Error(response.error);

return $3db7bcc71a7ab568$var$__awaiter(this, void 0, void 0, function*() {
createDebugLog("registerFunction()");
createDebugLog({
functionName: "registerFunction()"
});
const response = yield chiliWrapper.registerFunctionOnEvent(eventName, body);

@@ -68,3 +72,5 @@ if (response.isError) throw new Error(response.error);

return $3db7bcc71a7ab568$var$__awaiter(this, void 0, void 0, function*() {
createDebugLog("executeRegisteredFunction()");
createDebugLog({
functionName: "executeRegisteredFunction()"
});
const response = yield chiliWrapper.executeRegisteredFunction(name, args);

@@ -99,2 +105,17 @@ if (response.isError) throw new Error(response.error);

}
static buildWithIframe(targetIframe, options) {
return $3db7bcc71a7ab568$var$__awaiter(this, void 0, void 0, function*() {
return $3db7bcc71a7ab568$export$a13915682e709c4f.build(Object.assign({
targetIframe: targetIframe
}, options));
});
}
static buildOnElement(parentElement, editorURL, options) {
return $3db7bcc71a7ab568$var$__awaiter(this, void 0, void 0, function*() {
return $3db7bcc71a7ab568$export$a13915682e709c4f.build(Object.assign({
parentElement: parentElement,
editorURL: editorURL
}, options));
});
}
/**

@@ -106,7 +127,24 @@ * The build method will wait for a connection to the other side of iframe. Must be called before iframe `onload` event is fired.

* @returns {PublisherInterface}
*/ static build(iframe, options = {}) {
var _a;
return $3db7bcc71a7ab568$var$__awaiter(this, void 0, void 0, function*() {
*/ static build(options) {
var _a, _b, _c, _d;
return $3db7bcc71a7ab568$var$__awaiter(this, arguments, void 0, function*() {
// Supporting code that is expecting pre 1.0 behavior
if (arguments[0].tagName == "IFRAME") {
const originalOptions = (_a = arguments[1]) !== null && _a !== void 0 ? _a : {};
options = Object.assign(Object.assign({}, originalOptions), {
targetIframe: arguments[0],
debug: (_b = options.debug) !== null && _b !== void 0 ? _b : originalOptions["penpalDebug"]
});
}
const publisherInterface = new $3db7bcc71a7ab568$export$a13915682e709c4f();
publisherInterface.child = yield (0, $7i1sb$penpal.connectToChild)({
publisherInterface.creationTime = new Date().toLocaleString();
publisherInterface.debug = (_c = options.debug) !== null && _c !== void 0 ? _c : false;
publisherInterface.createDebugLog({
functionName: "build()",
customMessage: "Calling build() with options: " + JSON.stringify(options)
});
const iframe = (_d = options.targetIframe) !== null && _d !== void 0 ? _d : document.createElement("iframe");
publisherInterface.iframe = iframe;
if (options.editorURL != null) iframe.src = options.editorURL;
const connectionPromise = (0, $7i1sb$penpal.connectToChild)({
iframe: // The iframe to which a connection should be made

@@ -119,8 +157,7 @@ iframe,

timeout: options.timeout,
debug: options.penpalDebug
}).promise;
debug: options.debug
});
if (options.parentElement != null) options.parentElement.appendChild(iframe);
publisherInterface.child = yield connectionPromise.promise;
publisherInterface.customFunction = $3db7bcc71a7ab568$var$createCustomFunctionsInterface(publisherInterface.child, publisherInterface.createDebugLog.bind(publisherInterface));
publisherInterface.debug = (_a = options.penpalDebug) !== null && _a !== void 0 ? _a : false;
publisherInterface.creationTime = new Date().toLocaleString();
publisherInterface.createDebugLog("build()");
const events = options.events;

@@ -140,6 +177,9 @@ if (events != null && events.length > 0) {

/**
* Logs a function call creation if penpalDebug is enabled
* Logs a function call creation if debug is enabled
* @param functionName The name of the function being executed
*/ createDebugLog(functionName) {
if (this.debug) console.log(`[PublisherInterface - ${this.creationTime}]`, `Creating ${functionName} call request`);
*/ createDebugLog({ functionName: functionName , customMessage: customMessage }) {
if (this.debug) {
if (customMessage != null) console.log(`[PublisherInterface - ${this.creationTime}]`, `${functionName} : ${customMessage}`);
else console.log(`[PublisherInterface - ${this.creationTime}]`, `Creating ${functionName} call request`);
}
}

@@ -182,3 +222,5 @@ /**

return $3db7bcc71a7ab568$var$__awaiter(this, void 0, void 0, function*() {
this.createDebugLog("alert()");
this.createDebugLog({
functionName: "alert()"
});
const response = yield this.child.alert(message, title);

@@ -194,3 +236,5 @@ if (response.isError) throw new Error(response.error);

return $3db7bcc71a7ab568$var$__awaiter(this, void 0, void 0, function*() {
this.createDebugLog("getDirtyState()");
this.createDebugLog({
functionName: "getDirtyState()"
});
const response = yield this.child.getDirtyState();

@@ -206,3 +250,5 @@ if (response.isError) throw new Error(response.error);

return $3db7bcc71a7ab568$var$__awaiter(this, void 0, void 0, function*() {
this.createDebugLog("nextPage()");
this.createDebugLog({
functionName: "nextPage()"
});
const response = yield this.child.nextPage();

@@ -217,3 +263,5 @@ if (response.isError) throw new Error(response.error);

return $3db7bcc71a7ab568$var$__awaiter(this, void 0, void 0, function*() {
this.createDebugLog("previousPage()");
this.createDebugLog({
functionName: "previousPage()"
});
const response = yield this.child.previousPage();

@@ -229,3 +277,5 @@ if (response.isError) throw new Error(response.error);

return $3db7bcc71a7ab568$var$__awaiter(this, void 0, void 0, function*() {
this.createDebugLog("setSelectedPage()");
this.createDebugLog({
functionName: "setSelectedPage()"
});
const response = yield this.child.setSelectedPage(page);

@@ -242,3 +292,5 @@ if (response.isError) throw new Error(response.error);

return $3db7bcc71a7ab568$var$__awaiter(this, void 0, void 0, function*() {
this.createDebugLog("getSelectedPage()");
this.createDebugLog({
functionName: "getSelectedPage()"
});
const response = yield this.child.getSelectedPage();

@@ -255,3 +307,5 @@ if (response.isError) throw new Error(response.error);

return $3db7bcc71a7ab568$var$__awaiter(this, void 0, void 0, function*() {
this.createDebugLog("getSelectedPageName()");
this.createDebugLog({
functionName: "getSelectedPageName()"
});
const response = yield this.child.getSelectedPageName();

@@ -268,3 +322,5 @@ if (response.isError) throw new Error(response.error);

return $3db7bcc71a7ab568$var$__awaiter(this, void 0, void 0, function*() {
this.createDebugLog("getNumPages()");
this.createDebugLog({
functionName: "getNumPages()"
});
const response = yield this.child.getNumPages();

@@ -281,3 +337,5 @@ if (response.isError) throw new Error(response.error);

return $3db7bcc71a7ab568$var$__awaiter(this, void 0, void 0, function*() {
this.createDebugLog("removeListener()");
this.createDebugLog({
functionName: "removeListener()"
});
this.chiliEventListenerCallbacks.delete(eventName);

@@ -300,3 +358,5 @@ const response = yield this.child.removeListener(eventName);

return $3db7bcc71a7ab568$var$__awaiter(this, void 0, void 0, function*() {
this.createDebugLog("addListener()");
this.createDebugLog({
functionName: "addListener()"
});
this.chiliEventListenerCallbacks.set(eventName, callbackFunction == null ? (targetID)=>{

@@ -316,3 +376,5 @@ if (window.OnEditorEvent != null) window.OnEditorEvent(eventName, targetID);

return $3db7bcc71a7ab568$var$__awaiter(this, void 0, void 0, function*() {
this.createDebugLog("getObject()");
this.createDebugLog({
functionName: "getObject()"
});
const response = yield this.child.getObject(chiliPath);

@@ -331,3 +393,5 @@ if (response.isError) throw new Error(response.error);

return $3db7bcc71a7ab568$var$__awaiter(this, void 0, void 0, function*() {
this.createDebugLog("setProperty()");
this.createDebugLog({
functionName: "setProperty()"
});
const response = yield this.child.setProperty(chiliPath, property, value);

@@ -351,3 +415,5 @@ if (response.isError) throw new Error(response.error);

return $3db7bcc71a7ab568$var$__awaiter(this, void 0, void 0, function*() {
this.createDebugLog("executeFunction()");
this.createDebugLog({
functionName: "executeFunction()"
});
const response = yield this.child.executeFunction(chiliPath, functionName, args);

@@ -382,3 +448,5 @@ if (response.isError) throw new Error(response.error);

return $3db7bcc71a7ab568$var$__awaiter(this, void 0, void 0, function*() {
this.createDebugLog("getPageSnapshot()");
this.createDebugLog({
functionName: "getPageSnapshot()"
});
const response = yield this.child.getPageSnapshot(pageIndex, size, layers, frames, viewMode, transparentBackground);

@@ -398,3 +466,5 @@ if (response.isError) throw new Error(response.error);

return $3db7bcc71a7ab568$var$__awaiter(this, void 0, void 0, function*() {
this.createDebugLog("getFrameSnapshot()");
this.createDebugLog({
functionName: "getFrameSnapshot()"
});
const response = yield this.child.getFrameSnapshot(idOrTag, size, transparentBackground);

@@ -412,3 +482,5 @@ if (response.isError) throw new Error(response.error);

return $3db7bcc71a7ab568$var$__awaiter(this, void 0, void 0, function*() {
this.createDebugLog("getFrameSubjectArea()");
this.createDebugLog({
functionName: "getFrameSubjectArea()"
});
const response = yield this.child.getFrameSubjectArea(idOrTag);

@@ -429,3 +501,5 @@ if (response.isError) throw new Error(response.error);

return $3db7bcc71a7ab568$var$__awaiter(this, void 0, void 0, function*() {
this.createDebugLog("setFrameSubjectArea()");
this.createDebugLog({
functionName: "setFrameSubjectArea()"
});
const response = yield this.child.setFrameSubjectArea(idOrTag, x, y, width, height);

@@ -441,3 +515,5 @@ if (response.isError) throw new Error(response.error);

return $3db7bcc71a7ab568$var$__awaiter(this, void 0, void 0, function*() {
this.createDebugLog("clearFrameSubjectArea()");
this.createDebugLog({
functionName: "clearFrameSubjectArea()"
});
const response = yield this.child.clearFrameSubjectArea(idOrTag);

@@ -454,3 +530,5 @@ if (response.isError) throw new Error(response.error);

return $3db7bcc71a7ab568$var$__awaiter(this, void 0, void 0, function*() {
this.createDebugLog("getAssetSubjectInfo()");
this.createDebugLog({
functionName: "getAssetSubjectInfo()"
});
const response = yield this.child.getAssetSubjectInfo(frameIdOrTag);

@@ -473,3 +551,5 @@ if (response.isError) throw new Error(response.error);

return $3db7bcc71a7ab568$var$__awaiter(this, void 0, void 0, function*() {
this.createDebugLog("setAssetSubjectInfo()");
this.createDebugLog({
functionName: "setAssetSubjectInfo()"
});
const response = yield this.child.setAssetSubjectInfo(frameIdOrTag, x, y, width, height, poiX, poiY);

@@ -485,3 +565,5 @@ if (response.isError) throw new Error(response.error);

return $3db7bcc71a7ab568$var$__awaiter(this, void 0, void 0, function*() {
this.createDebugLog("clearAssetSubjectInfo()");
this.createDebugLog({
functionName: "clearAssetSubjectInfo()"
});
const response = yield this.child.clearAssetSubjectInfo(frameIdOrTag);

@@ -498,3 +580,5 @@ if (response.isError) throw new Error(response.error);

return $3db7bcc71a7ab568$var$__awaiter(this, void 0, void 0, function*() {
this.createDebugLog("setVariableIsLocked()");
this.createDebugLog({
functionName: "setVariableIsLocked()"
});
const response = yield this.child.setVariableIsLocked(variableName, isLocked);

@@ -501,0 +585,0 @@ if (response.isError) throw new Error(response.error);

{
"name": "@chili-publish/publisher-interface",
"version": "0.4.0",
"version": "1.0.0",
"author": "chili-publish",

@@ -5,0 +5,0 @@ "description": "PublisherInterface is a class object that allows you to interact with the CHILI Publisher editorObject via postMessage without the complexity of postMessage.",

@@ -1,44 +0,37 @@

# Publisher Interface
The Publisher Interface was designed to make integrating into CHILI publish Online easy.
# CHILI Publisher Interface
The **Publisher Interface** library simplifies integration with CHILI GraFx Publisher by providing a straightforward means to interact with the editorObject via postMessage. This library greatly simplifies the complexity of dealing with the same-origin policy in all browsers including Chromium-based browsers.
As a happy side effect, the setter for `document.domain`, which many integrations rely on, will become immutable at the beginning of January 2023. This means that the Publisher Interface will be the only supported way to communicate with Publisher via an `<iframe>`.
Notes:
- The Publisher JavaScript API has maintained stability for years. Thus this library reaching major version 1.x signifies that future updates will primarily address bug fixes, and should be rare. In this case, no updates is a good sign.
- Some use cases may not be supported by Publisher Interface. Refer to [here]() for unsupported use cases.
- Previously named Publisher Connector, the project has been renamed to Publisher Interface to avert confusion with future connectors plugin systems. Please update your project if you utilized the old name and library.
- As of 2023, this is the only officially supported way to integrate CHILI GraFx Publisher.
All the magic happens with `PublisherInterface` PublisherInterface is a class object that allows you to interact with the CHILI Editor editorObject via postMessage without the complexity of postMessage.
<br/>
This project is officially supported by [CHILI publish](https://chili-publish.com).
Notes:
* The Publisher JavaScript API has been stable for years, and there is no plans to add to it. So this project may not get many updates. That is a good thing, it means there is no bugs.
* Originally this project was called Publisher Connector. The name was changed to avoid confusion with the future connectors plugin system. Please update your projects if you were using the old naming convention and library.
## Contents
- [Installation](#installation)
- [Getting Started](#getting-started)
- [Debugging](#debugging)
## Documentation
You can find complete documentation on the [wiki](https://github.com/chili-publish/publisher-interface/wiki)
* [Installation](#installation) - Easy npm install.
* [Getting Started](#getting-started) - A very quick tutorial to get you started.
* [Debugging](#debugging) - Things gone wrong, check this out.
* [Integrating Publisher](https://github.com/chili-publish/publisher-interface/wiki/Integrating-Publisher) - A much longer tutorial for those starting a new project with Publisher.
* [Why I Cannot Use editorObject](https://github.com/chili-publish/publisher-interface/wiki/Why-I-Cannot-Use-editorObject) - A description of why `editorObject` can no longer be used when communicating with an `<iframe>`.
* [Differences With editorObject](https://github.com/chili-publish/publisher-interface/wiki/Differences-With-editorObject) - All the differences between `PublisherInterface` and `editorObject`.
* [Moving to Publisher Interface](https://github.com/chili-publish/publisher-interface/wiki/Moving-to-Publisher-Interface) - A guide for those who already have a project with Publisher and are now converting their current integration from `editorObject` to Publisher Interface.
* [Big List of JavaScript Use Cases](https://github.com/chili-publish/publisher-interface/wiki/Big-List-of-JavaScript-Use-Cases) - A very long list of JavaScript use cases. [WIP]
* [API Documentation](https://github.com/chili-publish/publisher-interface/wiki/API-Docs) - auto-generated documentation of the `PublisherInterface` class and associated types. Even though it is auto-generated, the comments therein were written with insight.
<br/>
📘 **Full documentation** is available on the [wiki](https://github.com/chili-publish/publisher-interface/wiki).
## Installation
You can install PublisherInterface via npm
Install Publisher Interface using npm, yarn, bun, or directly in the browser via unpkg.
```
```javascript
// npm
npm i @chili-publish/publisher-interface
```
<br/>
or through yarn
```
// yarn
yarn add @chili-publish/publisher-interface
```
<br/>
// bun
bun install @chili-publish/publisher-interface
You can also use it directly in the browser via unpkg.
```javascript
// browser
import {PublisherInterface} from "https://unpkg.com/@chili-publish/publisher-interface@latest/dist/PublisherInterface.min.js";

@@ -50,16 +43,21 @@ ```

All other dependencies are only for the developer tools such as auto generating docs, testing, and packaging.
All other dependencies are only for the developer tools such as auto generating docs, testing, and packaging. Developer dependencies will not always be up-to-date, and that is okay because our focus is to keep to keep the package up-to-date , and the developer tools only when releasing a new version.
This means that their is very little security concerns, and the limitations are the same as those found in [Penpal](https://github.com/Aaronius/penpal)
This means that there are very little security concerns, and the limitations are the same as those found in [Penpal](https://github.com/Aaronius/penpal)
### Browser Support
Publisher Interface runs successfully on the most recent versions of Chrome, Firefox, Safari, and Edge. Internet Explorer is
not supported.
Publisher Interface runs successfully on CHILI GraFx and any version greater on or above 6.5.5. It is also built to run on the most recent versions of Chrome, Firefox, Safari, and Edge. Internet Explorer is not supported.
## Getting Started
The easiest way to get started is to pull the package from unpkg.
<br/>
# Getting Started
Begin by pulling the package from unpkg, or import it if installed via NPM, yarn, or bun.
```javascript
//unpkg
import {PublisherInterface} from "https://unpkg.com/@chili-publish/publisher-interface@latest/dist/PublisherInterface.min.js";
// npm, yarn, bun
import {PublisherInterface} from "@chili-publish/publisher-interface";
```

@@ -69,5 +67,11 @@

If you downloaded via NPM you can import it with
Subsequently, within your JavaScript code:
- Retrieve the containing element
- Invoke the buildOnElement method
```javascript
import {PublisherInterface} from "@chili-publish/publisher-interface";
const editorDiv = document.getElementById("editor-div");
const publisher = PublisherInterface.buildOnElement(editorDiv, "https://example.chili-publish.online/example/editor_html.aspx?doc=3d178228-a9b9-49d0-90d9-c1c8f8b67f05&apiKey=Sczs1ruhiZcaFiqg0G0").then(
publisher => publisher.alert("Hi!")
);
```

@@ -77,28 +81,46 @@

Then in your JavaScript code, get the iframe which is loading the Publisher editor, and pass that iframe element into the `build()` function of `PublisherInterface`.
The code above will create an iframe on the element with `id` "editor-div" using the URL passed in the function as the `src`.
For iframe styling, use `publisher.iframe`.
```javascript
const iframe = document.getElementById("editor-iframe");
const publisher = PublisherInterface.build(iframe).then(
PublisherInterface => PublisherInterface.alert("Hi!")
const editorDiv = document.getElementById("editor-div");
const publisher = PublisherInterface.buildOnElement(editorDiv, "https://example.chili-publish.online/example/editor_html.aspx?doc=3d178228-a9b9-49d0-90d9-c1c8f8b67f05&apiKey=Sczs1ruhiZcaFiqg0G0").then(
publisher => {
publisher.iframe.classList.add("coolIFrameStyleInCSS");
}
);
```
🚨 **Important** - make sure that you call `build()` before the iframe `onload` event is fired. In practice this means that you should never call `build()` when that event is fired.
<br/>
<br/>
We can also use the [async and await](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Promises#async_and_await) syntax. Here is the above example using async/await:
```javascript
const editorDiv = document.getElementById("editor-div");
const publisher = await PublisherInterface.buildOnElement(editorDiv, "https://example.chili-publish.online/example/editor_html.aspx?doc=3d178228-a9b9-49d0-90d9-c1c8f8b67f05&apiKey=Sczs1ruhiZcaFiqg0G0");
publisher.iframe.classList.add("coolIFrameStyleInCSS");
```
<br/>
In simple use cases, the below example will work well.
Here is a complete example:
```html
<body>
<div id="editor-div"></div>
<iframe id="editor-iframe" style="width:1200px; height:800px"
src="https://example.chili-publish.online/example/editor_html.aspx?doc=3d178228-a9b9-49d0-90d9-c1c8f8b67f05&apiKey=Sczs1ruhiZcaFiqg0G07gMFMq07X+SG2o8KlW8oAeZGqoB1a0YkbeZU1wJK15aIhANgZmhg+13NQlxpBEq7Q=="></iframe>
src="https://example.chili-publish.online/example/editor_html.aspx?doc=3d178228-a9b9-49d0-90d9-c1c8f8b67f05&apiKey=Sczs1ruhiZcaFiqg0G0"></iframe>
<script type="module">
import {PublisherInterface} from 'https://unpkg.com/@chili-publish/publisher-interface@latest/dist/PublisherInterface.min.js';
const iframe = document.getElementById("editor-iframe");
const element = document.getElementById("editor-div");
(async () => {
const publisher = await PublisherInterface.build(iframe);
const publisher = await PublisherInterface.buildOnElement(element, "https://example.chili-publish.online/example/editor_html.aspx?doc=3d178228-a9b9-49d0-90d9-c1c8f8b67f05&apiKey=Sczs1ruhiZcaFiqg0G0");
publisher.iframe.classList.add("coolIFrameStyleInCSS");
const documentName = await publisher.getObject("document.name");
console.log(documentName);

@@ -109,48 +131,62 @@ })();

```
<br/>
When dealing with larger applications, it's important to ensure that the `iframe` and the `PublisherInterface` build method are called in the same JavaScript event loop. To do this, follow these steps:
1. Create the `iframe` element and set its `src` attribute.
2. Pass the `iframe` element to the `build` method of `PublisherInterface` and capture the promise returned from the method.
3. Append the `iframe` element to the DOM.
4. Await the promise captured in step 2 and assign it to a variable that can be used throughout your application.
## Your Own iframe
In versions before 1.0, you would need to use your own iframe when building the `PublisherInterface` class.
Example Code:
To utilize your iframe, employ the buildWithIframe() method.
```html
<body>
<script type="module">
import {PublisherInterface} from 'https://unpkg.com/@chili-publish/publisher-interface@latest/dist/PublisherInterface.min.js';
<iframe id="editor-iframe" style="width:1200px; height:800px"
src="https://example.chili-publish.online/example/editor_html.aspx?doc=3d178228-a9b9-49d0-90d9-c1c8f8b67f05&apiKey=Sczs1ruhiZcaFiqg0G0"></iframe>
<script type="module">
import {PublisherInterface} from 'https://unpkg.com/@chili-publish/publisher-interface@latest/dist/PublisherInterface.min.js';
const iframe = document.getElementById("editor-iframe");
(async () => {
const publisher = await PublisherInterface.buildWithIframe(iframe);
const documentName = await publisher.getObject("document.name");
console.log(documentName);
})();
</script>
</body>
document.addEventListener("DOMContentLoaded", async () => {
(async () => {
const iframe = document.createElement("iframe");
iframe.src = "https://example.chili-publish.online/example/editor_html.aspx?doc=3d178228-a9b9-49d0-90d9-c1c8f8b67f05&apiKey=Sczs1ruhiZcaFiqg0G07gMFMq07X+SG2o8KlW8oAeZGqoB1a0YkbeZU1wJK15aIhANgZmhg+13NQlxpBEq7Q==";
const publisherPromise = PublisherInterface.build(iframe);
document.body.appendChild(iframe);
const publisher = await publisherPromise;
const documentName = await publisher.getObject("document.name");
console.log(documentName);
})();
});
</script>
</body>
```
<br/>
🚨 **Important** - `buildWithIframe()` will not resolve if the iframe loads before build() is called. Prefer using `buildOnElement()`.
<br/>
## Debugging
To enable debugging for the underlying library, pass {penpalDebug: true} as the buildOptions in your build function.
Activate debugging by passing `{debug: true}` as the commonBuildOptions in your build function.
```javascript
PublisherInterface.build(iframe, {penpalDebug: true});
// If you are letting the iframe be built on an element
PublisherInterface.buildOnElement(element, "https://example.chili-publish.online/example/editor_html.aspx?doc=3d178228-a9b9-49d0-90d9-c1c8f8b67f05&apiKey=Sczs1ruhiZcaFiqg0G0", {debug: true})
// If you are using your own iframe
PublisherInterface.buildWithIframe(iframe, {debug: true});
```
This will display messages in the console from Penpal about the communication between the iframe and the main page.
This will display messages in the console about the communication between the iframe and the main page.
If there's a possibility of a failure to connect, you can set a timeout. If the connection is not established before the timeout, an exception will be thrown. In the example below, the build method will throw a timeout after 10 seconds if no connection is established.
<br/>
To handle potential connection failures, define a timeout as demonstrated below.
```javascript
PublisherInterface.build(iframe, {penpalDebug: true, timeout: 10000});
// If you are letting the iframe be built on an element
PublisherInterface.buildOnElement(element, "https://example.chili-publish.online/example/editor_html.aspx?doc=3d178228-a9b9-49d0-90d9-c1c8f8b67f05&apiKey=Sczs1ruhiZcaFiqg0G0", {debug: true, timeout: 10000})
// If you are using your own iframe
PublisherInterface.buildWithIframe(iframe, {debug: true, timeout: 10000});
```
If the connection is not established before the timeout, an exception will be thrown. In the example below, the build method will throw a timeout after 10 seconds if no connection is established.
<br/>
To read more, check out our [documentation](#documentation).
To read more, check out our [documentation](#documentation).

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc