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

@agility/app-sdk

Package Overview
Dependencies
Maintainers
4
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@agility/app-sdk - npm Package Compare versions

Comparing version 0.0.7 to 0.0.8

src/messages.js

2

dist/agility-cms-app-sdk.browser.js

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

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("agilityAppSDK",[],t):"object"==typeof exports?exports.agilityAppSDK=t():e.agilityAppSDK=t()}("undefined"!=typeof self?self:this,(function(){return(()=>{var e={706:(e,t,n)=>{"use strict";n.d(t,{default:()=>b});var r={};n.r(r),n.d(r,{closeFlyout:()=>f,openFlyout:()=>u,subscribeToFieldValueChanges:()=>p,updateFieldValue:()=>l});var o={};n.r(o),n.d(o,{flyouts:()=>h,initializeAppConfig:()=>v,initializeField:()=>w,locations:()=>i,resolveAppComponent:()=>_});const i={APP_LOCATION_CUSTOM_FIELD:"CustomField",APP_LOCATION_FLYOUT:"Flyout",APP_LOCATION_UNKNOWN:"Unknown",APP_LOCATION_APP_CONFIG:"AppConfig"};var a=function(e){e=e.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");var t=new RegExp("[\\?&]"+e+"=([^&#]*)").exec(window.location.search);return null===t?"":decodeURIComponent(t[1].replace(/\+/g," "))},c=function(e){return e.location+"_"+e.fieldName+"_"+e.fieldID},s=function(e){var t=e.containerRef,n=e.messageID;setInterval((function(){!function(e){var t=e.height,n=e.messageID;window.parent&&window.parent.postMessage({message:t,type:"setHeight_for_".concat(n)},"*")}({height:t.current?t.current.offsetHeight:t.offsetHeight,messageID:n})}),500)},l=function(e){var t=e.fieldName,n=e.fieldValue,r=c({location:this.location,fieldName:this.fieldName,fieldID:this.fieldID});t||(t=this.fieldName),window.parent?window.parent.postMessage({message:{fieldName:t,fieldValue:n},type:"setNewValue_for_".concat(r)},"*"):console.log("".concat(r," => 😞 Can't post message to parent."))},u=function(e){var t=e.title,n=e.size,r=e.name,o=e.onClose,a=e.params,s=c({location:i.APP_LOCATION_CUSTOM_FIELD,fieldID:this.fieldID,fieldName:this.fieldName});window.parent&&(window.parent.postMessage({message:{title:t,size:n,name:r,params:a},type:"openFlyout_for_".concat(s)},"*"),window.addEventListener("message",(function e(t){t.data.type==="closeFlyoutCallback_for_".concat(s)&&o(t.data.message),window.removeEventListener("message",e,!1)}),!1))},f=function(e){var t=e.params,n=i.APP_LOCATION_CUSTOM_FIELD,r=c({location:n,fieldID:this.fieldID,fieldName:this.fieldName});window.parent&&window.parent.postMessage({message:{location:n,fieldName:this.fieldName,fieldID:this.fieldID,params:t},type:"closeFlyout_for_".concat(r)},"*")},p=function(e){var t=e.fieldName,n=e.onChange,r=c({fieldID:this.fieldID,fieldName:this.fieldName,location:this.location});window.addEventListener("message",(function(e){e.data.type==="otherValueChanged_".concat(t,"_for_").concat(r)&&n(e.data.message)}),!1),window.parent?window.parent.postMessage({message:t,type:"subscribeToOtherValueChanges_".concat(r)},"*"):console.log("".concat(r," => 😞 Parent window not found. You must load this within Agility CMS as an iFrame."))};const h={APP_FLYOUT_SIZE_LARGE:"Large",APP_FLYOUT_SIZE_SMALL:"Small"};function d(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function y(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?d(Object(n),!0).forEach((function(t){g(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):d(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function g(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function m(e,t,n,r,o,i,a){try{var c=e[i](a),s=c.value}catch(e){return void n(e)}c.done?t(s):Promise.resolve(s).then(r,o)}n(666);var v=function(e){window.parent&&window.parent.postMessage({message:e,type:"setAppConfig_for_".concat(e.name)},"*")},w=function(){var e,t=(e=regeneratorRuntime.mark((function e(t){var n;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.containerRef,e.abrupt("return",new Promise((function(e){var t=a("fieldID"),o=a("fieldName"),i=a("location"),l=c({location:i,fieldName:o,fieldID:t});s({containerRef:n,messageID:l}),console.log("".concat(l," => Waiting for message from Agility CMS")),window.addEventListener("message",(function(t){if(t.data.type==="setInitialProps_for_".concat(l)){console.log("".concat(l," => auth, fieldValue received from Agility CMS, setting up field..."));var n=t.data.message;n.location=i,e(new function(){return y(y({},n),r)})}else console.log("".concat(l," => IGNORING MESSAGE FROM PARENT: "),t.data)}),!1),window.parent?(console.log("".concat(l," => 😀 Notifying Agility CMS this field is ready to receive messages...")),window.parent.postMessage({message:"ready",type:"ready_for_".concat(l)},"*")):console.log("".concat(l," => 😞 Parent window not found. You must load this within Agility CMS as an iFrame."))})));case 2:case"end":return e.stop()}}),e)})),function(){var t=this,n=arguments;return new Promise((function(r,o){var i=e.apply(t,n);function a(e){m(i,r,o,a,c,"next",e)}function c(e){m(i,r,o,a,c,"throw",e)}a(void 0)}))});return function(e){return t.apply(this,arguments)}}(),_=function(e){var t=O(),n=e.appComponents.find((function(e){return e.location===t.location&&(!t.name||e.name===t.name)}));if(n)return n.componentToRender;console.error("Could not render the '"+e.name+"' component for '"+t.location+"' with the name of '"+t.name+"'")},O=function(){var e=a("location");return e===i.APP_LOCATION_CUSTOM_FIELD?{location:e,name:a("fieldTypeName")}:e===i.APP_LOCATION_APP_CONFIG?{location:e}:e===i.APP_LOCATION_FLYOUT?{location:e,name:a("flyoutName")}:{location:i.APP_LOCATION_UNKNOWN,name:null}};const b=o},666:e=>{var t=function(e){"use strict";var t,n=Object.prototype,r=n.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function s(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{s({},"")}catch(e){s=function(e,t,n){return e[t]=n}}function l(e,t,n,r){var o=t&&t.prototype instanceof g?t:g,i=Object.create(o.prototype),a=new E(r||[]);return i._invoke=function(e,t,n){var r=f;return function(o,i){if(r===h)throw new Error("Generator is already running");if(r===d){if("throw"===o)throw i;return C()}for(n.method=o,n.arg=i;;){var a=n.delegate;if(a){var c=N(a,n);if(c){if(c===y)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(r===f)throw r=d,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r=h;var s=u(e,t,n);if("normal"===s.type){if(r=n.done?d:p,s.arg===y)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(r=d,n.method="throw",n.arg=s.arg)}}}(e,n,a),i}function u(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}e.wrap=l;var f="suspendedStart",p="suspendedYield",h="executing",d="completed",y={};function g(){}function m(){}function v(){}var w={};s(w,i,(function(){return this}));var _=Object.getPrototypeOf,O=_&&_(_(x([])));O&&O!==n&&r.call(O,i)&&(w=O);var b=v.prototype=g.prototype=Object.create(w);function L(e){["next","throw","return"].forEach((function(t){s(e,t,(function(e){return this._invoke(t,e)}))}))}function P(e,t){function n(o,i,a,c){var s=u(e[o],e,i);if("throw"!==s.type){var l=s.arg,f=l.value;return f&&"object"==typeof f&&r.call(f,"__await")?t.resolve(f.__await).then((function(e){n("next",e,a,c)}),(function(e){n("throw",e,a,c)})):t.resolve(f).then((function(e){l.value=e,a(l)}),(function(e){return n("throw",e,a,c)}))}c(s.arg)}var o;this._invoke=function(e,r){function i(){return new t((function(t,o){n(e,r,t,o)}))}return o=o?o.then(i,i):i()}}function N(e,n){var r=e.iterator[n.method];if(r===t){if(n.delegate=null,"throw"===n.method){if(e.iterator.return&&(n.method="return",n.arg=t,N(e,n),"throw"===n.method))return y;n.method="throw",n.arg=new TypeError("The iterator does not provide a 'throw' method")}return y}var o=u(r,e.iterator,n.arg);if("throw"===o.type)return n.method="throw",n.arg=o.arg,n.delegate=null,y;var i=o.arg;return i?i.done?(n[e.resultName]=i.value,n.next=e.nextLoc,"return"!==n.method&&(n.method="next",n.arg=t),n.delegate=null,y):i:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,y)}function I(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function A(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function E(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(I,this),this.reset(!0)}function x(e){if(e){var n=e[i];if(n)return n.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var o=-1,a=function n(){for(;++o<e.length;)if(r.call(e,o))return n.value=e[o],n.done=!1,n;return n.value=t,n.done=!0,n};return a.next=a}}return{next:C}}function C(){return{value:t,done:!0}}return m.prototype=v,s(b,"constructor",v),s(v,"constructor",m),m.displayName=s(v,c,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===m||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,v):(e.__proto__=v,s(e,c,"GeneratorFunction")),e.prototype=Object.create(b),e},e.awrap=function(e){return{__await:e}},L(P.prototype),s(P.prototype,a,(function(){return this})),e.AsyncIterator=P,e.async=function(t,n,r,o,i){void 0===i&&(i=Promise);var a=new P(l(t,n,r,o),i);return e.isGeneratorFunction(n)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},L(b),s(b,c,"Generator"),s(b,i,(function(){return this})),s(b,"toString",(function(){return"[object Generator]"})),e.keys=function(e){var t=[];for(var n in e)t.push(n);return t.reverse(),function n(){for(;t.length;){var r=t.pop();if(r in e)return n.value=r,n.done=!1,n}return n.done=!0,n}},e.values=x,E.prototype={constructor:E,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(A),!e)for(var n in this)"t"===n.charAt(0)&&r.call(this,n)&&!isNaN(+n.slice(1))&&(this[n]=t)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var n=this;function o(r,o){return c.type="throw",c.arg=e,n.next=r,o&&(n.method="next",n.arg=t),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],c=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var s=r.call(a,"catchLoc"),l=r.call(a,"finallyLoc");if(s&&l){if(this.prev<a.catchLoc)return o(a.catchLoc,!0);if(this.prev<a.finallyLoc)return o(a.finallyLoc)}else if(s){if(this.prev<a.catchLoc)return o(a.catchLoc,!0)}else{if(!l)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return o(a.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=e,a.arg=t,i?(this.method="next",this.next=i.finallyLoc,y):this.complete(a)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),y},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),A(n),y}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var o=r.arg;A(n)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,n,r){return this.delegate={iterator:x(e),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=t),y}},e}(e.exports);try{regeneratorRuntime=t}catch(e){"object"==typeof globalThis?globalThis.regeneratorRuntime=t:Function("r","regeneratorRuntime = r")(t)}}},t={};function n(r){var o=t[r];if(void 0!==o)return o.exports;var i=t[r]={exports:{}};return e[r](i,i.exports,n),i.exports}n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n(666);var r=n(706);return r.default})()}));
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("agilityAppSDK",[],t):"object"==typeof exports?exports.agilityAppSDK=t():e.agilityAppSDK=t()}("undefined"!=typeof self?self:this,(function(){return(()=>{var e={732:(e,t,r)=>{"use strict";r.d(t,{default:()=>C});var n={};r.r(n),r.d(n,{openFlyout:()=>p,subscribeToFieldValueChanges:()=>d,updateFieldValue:()=>h});var o={};r.r(o),r.d(o,{closeFlyout:()=>m});var i={};r.r(i),r.d(i,{initializeAppConfig:()=>w,initializeField:()=>b,initializeFlyout:()=>P,resolveAppComponent:()=>N,types:()=>a});const a={APP_LOCATION_CUSTOM_FIELD:"CustomField",APP_LOCATION_FLYOUT:"Flyout",APP_LOCATION_UNKNOWN:"Unknown",APP_LOCATION_APP_CONFIG:"AppConfig",APP_FLYOUT_SIZE_SMALL:"Small",APP_FLYOUT_SIZE_LARGE:"Small"};var c=function(e){e=e.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");var t=new RegExp("[\\?&]"+e+"=([^&#]*)").exec(window.location.search);return null===t?"":decodeURIComponent(t[1].replace(/\+/g," "))},u=function(e){return e.location+"_"+e.fieldName+"_"+e.fieldID},s=function(e){var t=e.containerRef,r=e.messageID;setInterval((function(){!function(e){var t=e.height,r=e.messageID;window.parent&&window.parent.postMessage({message:t,type:"setHeight_for_".concat(r)},"*")}({height:t.current?t.current.offsetHeight:t.offsetHeight,messageID:r})}),500)},l=function(e){var t=e.message,r=e.messageChannel;window.parent&&window.parent.postMessage({message:t,type:r},"*")},f=function(e){var t=e.messageChannel,r=e.persist,n=void 0!==r&&r;return new Promise((function(e){window.addEventListener("message",(function r(o){if(o.data.type===t)return n||removeEventListener("message",r,!1),void e(o.data.message)}),!1)}))},h=function(e){var t=e.fieldName,r=e.fieldValue,n=u({location:this.location,fieldName:this.fieldName,fieldID:this.fieldID});t||(t=this.fieldName),l({message:{fieldName:t,fieldValue:r},messageChannel:"setNewValue_for_".concat(n)})},p=function(e){var t=e.title,r=e.size,n=e.name,o=e.onClose,i=e.params,c=u({location:a.APP_LOCATION_CUSTOM_FIELD,fieldID:this.fieldID,fieldName:this.fieldName});l({message:{title:t,size:r,name:n,params:i},messageChannel:"openFlyout_for_".concat(c)}),f({messageChannel:"closeFlyoutCallback_for_".concat(c)}).then((function(e){o(e)}))},d=function(e){var t=e.fieldName,r=e.onChange,n=u({fieldID:this.fieldID,fieldName:this.fieldName,location:this.location});f({messageChannel:"otherValueChanged_".concat(t,"_for_").concat(n),persist:!0}).then((function(e){r(e)})),l({message:t,messageChannel:"subscribeToOtherValueChanges_".concat(n)})},m=function(e){var t=e.params,r=a.APP_LOCATION_CUSTOM_FIELD,n=u({location:r,fieldID:this.fieldID,fieldName:this.fieldName});l({message:{location:r,fieldName:this.fieldName,fieldID:this.fieldID,params:t},messageChannel:"closeFlyout_for_".concat(n)})};function y(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function g(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?y(Object(r),!0).forEach((function(t){v(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):y(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function v(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function _(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function O(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var i=e.apply(t,r);function a(e){_(i,n,o,a,c,"next",e)}function c(e){_(i,n,o,a,c,"throw",e)}a(void 0)}))}}r(666);var w=function(e){var t=c("appDefinitionID");l({message:e,messageChannel:"setAppConfig_for_".concat(t)})},b=function(){var e=O(regeneratorRuntime.mark((function e(t){var r,n;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.containerRef,e.next=3,L({containerRef:r,location:a.APP_LOCATION_CUSTOM_FIELD});case 3:return n=e.sent,e.abrupt("return",n);case 5:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),P=function(){var e=O(regeneratorRuntime.mark((function e(t){var r,n;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.containerRef,e.next=3,L({containerRef:r,location:a.APP_LOCATION_FLYOUT});case 3:return n=e.sent,e.abrupt("return",n);case 5:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),L=function(){var e=O(regeneratorRuntime.mark((function e(t){var r,i;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.containerRef,i=t.location,e.abrupt("return",new Promise((function(e){var t=c("fieldID"),h=c("fieldName"),p=u({location:i,fieldName:h,fieldID:t});s({containerRef:r,messageID:p}),f({messageChannel:"setInitialProps_for_".concat(p)}).then((function(t){t.location=i;var r={};i===a.APP_LOCATION_CUSTOM_FIELD?r=n:i===a.APP_LOCATION_FLYOUT&&(r=o),e(g(g({},t),r))})),l({message:"ready",messageChannel:"ready_for_".concat(p)})})));case 2:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),N=function(e){var t=I(),r=e.appComponents.find((function(e){return e.location===t.location&&(!t.name||e.name===t.name)}));if(r)return r.componentToRender;console.error("Could not render the '"+e.name+"' component for '"+t.location+"' with the name of '"+t.name+"'")},I=function(){var e=c("location");return e===a.APP_LOCATION_CUSTOM_FIELD?{location:e,name:c("fieldTypeName")}:e===a.APP_LOCATION_APP_CONFIG?{location:e}:e===a.APP_LOCATION_FLYOUT?{location:e,name:c("flyoutName")}:{location:a.APP_LOCATION_UNKNOWN,name:null}};const C=i},666:e=>{var t=function(e){"use strict";var t,r=Object.prototype,n=r.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function u(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{u({},"")}catch(e){u=function(e,t,r){return e[t]=r}}function s(e,t,r,n){var o=t&&t.prototype instanceof y?t:y,i=Object.create(o.prototype),a=new A(n||[]);return i._invoke=function(e,t,r){var n=f;return function(o,i){if(n===p)throw new Error("Generator is already running");if(n===d){if("throw"===o)throw i;return T()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var c=N(a,r);if(c){if(c===m)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(n===f)throw n=d,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n=p;var u=l(e,t,r);if("normal"===u.type){if(n=r.done?d:h,u.arg===m)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n=d,r.method="throw",r.arg=u.arg)}}}(e,r,a),i}function l(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}e.wrap=s;var f="suspendedStart",h="suspendedYield",p="executing",d="completed",m={};function y(){}function g(){}function v(){}var _={};u(_,i,(function(){return this}));var O=Object.getPrototypeOf,w=O&&O(O(x([])));w&&w!==r&&n.call(w,i)&&(_=w);var b=v.prototype=y.prototype=Object.create(_);function P(e){["next","throw","return"].forEach((function(t){u(e,t,(function(e){return this._invoke(t,e)}))}))}function L(e,t){function r(o,i,a,c){var u=l(e[o],e,i);if("throw"!==u.type){var s=u.arg,f=s.value;return f&&"object"==typeof f&&n.call(f,"__await")?t.resolve(f.__await).then((function(e){r("next",e,a,c)}),(function(e){r("throw",e,a,c)})):t.resolve(f).then((function(e){s.value=e,a(s)}),(function(e){return r("throw",e,a,c)}))}c(u.arg)}var o;this._invoke=function(e,n){function i(){return new t((function(t,o){r(e,n,t,o)}))}return o=o?o.then(i,i):i()}}function N(e,r){var n=e.iterator[r.method];if(n===t){if(r.delegate=null,"throw"===r.method){if(e.iterator.return&&(r.method="return",r.arg=t,N(e,r),"throw"===r.method))return m;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return m}var o=l(n,e.iterator,r.arg);if("throw"===o.type)return r.method="throw",r.arg=o.arg,r.delegate=null,m;var i=o.arg;return i?i.done?(r[e.resultName]=i.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,m):i:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,m)}function I(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function C(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function A(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(I,this),this.reset(!0)}function x(e){if(e){var r=e[i];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var o=-1,a=function r(){for(;++o<e.length;)if(n.call(e,o))return r.value=e[o],r.done=!1,r;return r.value=t,r.done=!0,r};return a.next=a}}return{next:T}}function T(){return{value:t,done:!0}}return g.prototype=v,u(b,"constructor",v),u(v,"constructor",g),g.displayName=u(v,c,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===g||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,v):(e.__proto__=v,u(e,c,"GeneratorFunction")),e.prototype=Object.create(b),e},e.awrap=function(e){return{__await:e}},P(L.prototype),u(L.prototype,a,(function(){return this})),e.AsyncIterator=L,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new L(s(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},P(b),u(b,c,"Generator"),u(b,i,(function(){return this})),u(b,"toString",(function(){return"[object Generator]"})),e.keys=function(e){var t=[];for(var r in e)t.push(r);return t.reverse(),function r(){for(;t.length;){var n=t.pop();if(n in e)return r.value=n,r.done=!1,r}return r.done=!0,r}},e.values=x,A.prototype={constructor:A,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(C),!e)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function o(n,o){return c.type="throw",c.arg=e,r.next=n,o&&(r.method="next",r.arg=t),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],c=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var u=n.call(a,"catchLoc"),s=n.call(a,"finallyLoc");if(u&&s){if(this.prev<a.catchLoc)return o(a.catchLoc,!0);if(this.prev<a.finallyLoc)return o(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return o(a.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return o(a.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=e,a.arg=t,i?(this.method="next",this.next=i.finallyLoc,m):this.complete(a)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),m},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),C(r),m}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var o=n.arg;C(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:x(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),m}},e}(e.exports);try{regeneratorRuntime=t}catch(e){"object"==typeof globalThis?globalThis.regeneratorRuntime=t:Function("r","regeneratorRuntime = r")(t)}}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var i=t[n]={exports:{}};return e[n](i,i.exports,r),i.exports}r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r(666);var n=r(732);return n.default})()}));
{
"name": "@agility/app-sdk",
"version": "0.0.7",
"version": "0.0.8",
"description": "JavaScript library for building Agility CMS apps.",

@@ -5,0 +5,0 @@ "main": "src/index.js",

# Agility CMS App SDK
>TODO: DOCS NEED UPDATING (flyoutSDK, rejig examples)
This is a JavaScript SDK for building UI Apps for Agility CMS.

@@ -24,6 +27,7 @@

At this time, only Custom Fields are supported, however there are plans to introduce new UI locations such as Sidebar apps.
At this time, only Custom Fields and Flyouts are supported, however there are plans to introduce new UI locations such as Sidebar components (that would appear on content).
### What you can Do
Just rendering your UI in a content input form isn't enough. The **App SDK ** allows you to:
Just rendering your UI in a content input form isn't enough. The **App SDK** allows you to:
- Render a custom field
- Set a custom field value

@@ -30,0 +34,0 @@ - Set the value of another field

@@ -1,3 +0,4 @@

import locations from './locations'
import types from './types'
import { getMessageID } from './utils';
import { listenForCMS, notifyCMS } from './messages';

@@ -15,13 +16,10 @@ const updateFieldValue = function ({ fieldName, fieldValue }) {

if (window.parent) {
window.parent.postMessage({
message: {
fieldName,
fieldValue
},
type: `setNewValue_for_${messageID}`
}, "*")
} else {
console.log(`${messageID} => 😞 Can't post message to parent.`)
}
notifyCMS({
message: {
fieldName,
fieldValue
} ,
messageChannel: `setNewValue_for_${messageID}`
})
}

@@ -31,3 +29,3 @@

const messageID = getMessageID({
location: locations.APP_LOCATION_CUSTOM_FIELD,
location: types.APP_LOCATION_CUSTOM_FIELD,
fieldID: this.fieldID,

@@ -37,63 +35,38 @@ fieldName: this.fieldName

if (window.parent) {
window.parent.postMessage({
message: {
title,
size,
name,
params
},
type: `openFlyout_for_${messageID}`
}, "*")
notifyCMS({
message: {
title,
size,
name,
params
},
messageChannel: `openFlyout_for_${messageID}`
})
var listener = function(e) {
if(e.data.type === `closeFlyoutCallback_for_${messageID}`) {
onClose(e.data.message);
}
window.removeEventListener("message", listener, false);
};
window.addEventListener("message", listener, false)
}
listenForCMS({ messageChannel: `closeFlyoutCallback_for_${messageID}`}).then((message) => {
onClose(message);
});
}
const closeFlyout = function ({ params }) {
const location = locations.APP_LOCATION_CUSTOM_FIELD;
const messageID = getMessageID({ location, fieldID: this.fieldID, fieldName: this.fieldName})
if (window.parent) {
window.parent.postMessage({
message: {
location,
fieldName: this.fieldName,
fieldID: this.fieldID,
params
},
type: `closeFlyout_for_${messageID}`
}, "*")
}
}
const subscribeToFieldValueChanges = function ({ fieldName, onChange}) {
const messageID = getMessageID({ fieldID: this.fieldID, fieldName: this.fieldName, location: this.location })
//open a channel to listen to messages from the CMS when field values change
window.addEventListener("message", function (e) {
//only care about these messages
if(e.data.type === `otherValueChanged_${fieldName}_for_${messageID}`) {
onChange(e.data.message);
}
}, false);
const messageID = getMessageID({
fieldID: this.fieldID,
fieldName: this.fieldName,
location: this.location
});
listenForCMS({
messageChannel: `otherValueChanged_${fieldName}_for_${messageID}`,
persist: true
}).then((message) => {
onChange(message);
})
//let the CMS know we are NOW ready to receive messages
if (window.parent) {
window.parent.postMessage({
message: fieldName,
type: `subscribeToOtherValueChanges_${messageID}`
}, "*")
} else {
console.log(`${messageID} => 😞 Parent window not found. You must load this within Agility CMS as an iFrame.`)
}
notifyCMS({
message: fieldName,
messageChannel: `subscribeToOtherValueChanges_${messageID}`
});
}

@@ -105,4 +78,3 @@

subscribeToFieldValueChanges,
openFlyout,
closeFlyout
openFlyout
}

@@ -1,7 +0,27 @@

const APP_FLYOUT_SIZE_SMALL = 'Small';
const APP_FLYOUT_SIZE_LARGE = 'Large';
import { getMessageID } from "./utils";
import types from "./types";
import { notifyCMS } from "./messages";
export default {
APP_FLYOUT_SIZE_LARGE,
APP_FLYOUT_SIZE_SMALL
const closeFlyout = function ({ params }) {
const location = types.APP_LOCATION_CUSTOM_FIELD;
const messageID = getMessageID({
location,
fieldID: this.fieldID,
fieldName: this.fieldName
})
notifyCMS({
message: {
location,
fieldName: this.fieldName,
fieldID: this.fieldID,
params
},
messageChannel: `closeFlyout_for_${messageID}`
})
}
export {
closeFlyout
}
import * as fieldMethods from './fields'
import locations from './locations'
import flyouts from './flyouts'
import * as flyoutMethods from './flyouts'
import types from './types'
import 'regenerator-runtime/runtime.js'
import { getUrlParameter, getMessageID, autoSyncFieldHeight } from './utils'
import { notifyCMS, listenForCMS } from './messages'
const initializeAppConfig = (appConfig) => {
if (window.parent) {
window.parent.postMessage({
message: appConfig,
type: `setAppConfig_for_${appConfig.name}`
}, "*")
}
const appDefinitionID = getUrlParameter('appDefinitionID');
notifyCMS({ message: appConfig, messageChannel: `setAppConfig_for_${appDefinitionID}`})
}

@@ -18,8 +15,16 @@

const initializeField = async ({ containerRef }) => {
const fieldSDK = await initializeAppComponent({ containerRef, location: types.APP_LOCATION_CUSTOM_FIELD })
return fieldSDK;
}
const initializeFlyout = async ({ containerRef }) => {
const flyoutSDK = await initializeAppComponent({ containerRef, location: types.APP_LOCATION_FLYOUT })
return flyoutSDK;
}
const initializeAppComponent = async ({ containerRef, location}) => {
// returns different available methods depending on whether this is a CustomField or a Flyout
return new Promise(resolve => {
const fieldID = getUrlParameter('fieldID');
const fieldName = getUrlParameter('fieldName');
const location = getUrlParameter('location');
var messageID = getMessageID({location, fieldName, fieldID});

@@ -30,41 +35,24 @@

//get the field ready to wait for messages from the parent
console.log(`${messageID} => Waiting for message from Agility CMS`)
//console.log(`${messageID} => Waiting for message from Agility CMS`)
//open a channel to listen to messages from the CMS
window.addEventListener("message", function (e) {
//only care about these messages
if(e.data.type === `setInitialProps_for_${messageID}`) {
console.log(`${messageID} => auth, fieldValue received from Agility CMS, setting up field...`)
listenForCMS({ messageChannel: `setInitialProps_for_${messageID}` }).then((fieldInfo) => {
fieldInfo.location = location;
let availableMethods = {};
//set field info that we can re-use later
const fieldInfo = e.data.message;
fieldInfo.location = location;
if(location === types.APP_LOCATION_CUSTOM_FIELD) {
availableMethods = fieldMethods;
} else if(location === types.APP_LOCATION_FLYOUT) {
availableMethods = flyoutMethods
}
resolve(new function() {
return {
...fieldInfo,
...fieldMethods
}
}());
//return our SDK for the appropriate UI component
resolve({
...fieldInfo,
...availableMethods
})
})
} else {
//show us the unhandled message...
console.log(`${messageID} => IGNORING MESSAGE FROM PARENT: `, e.data)
}
}, false);
notifyCMS({ message: "ready", messageChannel: `ready_for_${messageID}`})
//let the CMS know we are NOW ready to receive messages
if (window.parent) {
console.log(`${messageID} => 😀 Notifying Agility CMS this field is ready to receive messages...`)
window.parent.postMessage({
message: "ready",
type: `ready_for_${messageID}`
}, "*")
} else {
console.log(`${messageID} => 😞 Parent window not found. You must load this within Agility CMS as an iFrame.`)
}
})
}

@@ -90,3 +78,3 @@

const location = getUrlParameter('location');
if(location === locations.APP_LOCATION_CUSTOM_FIELD) {
if(location === types.APP_LOCATION_CUSTOM_FIELD) {
const fieldTypeName = getUrlParameter('fieldTypeName');

@@ -97,7 +85,7 @@ return {

}
} else if(location === locations.APP_LOCATION_APP_CONFIG) {
} else if(location === types.APP_LOCATION_APP_CONFIG) {
return {
location
}
} else if(location === locations.APP_LOCATION_FLYOUT) {
} else if(location === types.APP_LOCATION_FLYOUT) {
const flyoutName = getUrlParameter('flyoutName');

@@ -110,3 +98,3 @@ return {

return {
location: locations.APP_LOCATION_UNKNOWN,
location: types.APP_LOCATION_UNKNOWN,
name: null

@@ -121,5 +109,5 @@ };

initializeField,
initializeFlyout,
resolveAppComponent,
locations,
flyouts
types
}
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