@interopio/browser-worker
Advanced tools
Comparing version 3.1.1 to 3.2.0
@@ -58,3 +58,3 @@ /*! ***************************************************************************** | ||
var dbName = "glue42core"; | ||
var dbVersion = 2; | ||
var dbVersion = 3; | ||
@@ -1162,2 +1162,5 @@ /** | ||
} | ||
if (!db.objectStoreNames.contains("prefs")) { | ||
db.createObjectStore("prefs"); | ||
} | ||
} | ||
@@ -1164,0 +1167,0 @@ }); |
@@ -64,3 +64,3 @@ (function (global, factory) { | ||
var dbName = "glue42core"; | ||
var dbVersion = 2; | ||
var dbVersion = 3; | ||
@@ -1168,2 +1168,5 @@ /** | ||
} | ||
if (!db.objectStoreNames.contains("prefs")) { | ||
db.createObjectStore("prefs"); | ||
} | ||
} | ||
@@ -1170,0 +1173,0 @@ }); |
@@ -15,2 +15,2 @@ !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(((e="undefined"!=typeof globalThis?globalThis:e||self).web=e.web||{},e.web.worker=e.web.worker||{},e.web.worker.min={}))}(this,(function(e){"use strict"; | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */function n(e,n,t,r){return new(t||(t=Promise))((function(o,i){function a(e){try{u(r.next(e))}catch(e){i(e)}}function c(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var n;e.done?o(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(a,c)}u((r=r.apply(e,n||[])).next())}))}function t(e,n){var t,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(t)throw new TypeError("Generator is already executing.");for(;a;)try{if(t=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=n.call(e,a)}catch(e){i=[6,e],r=0}finally{t=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}var r="glue42-core-worker",o=function(e){return{ok:!0,result:e}},i=function(e){return{ok:!1,error:e}},a=function(e){return!0===e.ok?Promise.resolve(e.result):Promise.reject(e.error)},c=function(e){if(!0===e.ok)return e.result;throw e.error},u=function(e,n){return!0===n.ok?o(e(n.result)):n},s=function(e,n,t){return!1===n.ok?n:!1===t.ok?t:o(e(n.result,t.result))},f=function(e,n){return!0===n.ok?n:i(e(n.error))},l=function(e,n){return!0===n.ok?e(n.result):n},d=function(){return d=Object.assign||function(e){for(var n,t=1,r=arguments.length;t<r;t++)for(var o in n=arguments[t])Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o]);return e},d.apply(this,arguments)};function p(e,n){if(e===n)return!0;if(null===e&&null===n)return!0;if(typeof e!=typeof n)return!1;if("object"==typeof e){if(Array.isArray(e)){if(!Array.isArray(n))return!1;if(e.length!==n.length)return!1;for(var t=0;t<e.length;t++)if(!p(e[t],n[t]))return!1;return!0}var r=Object.keys(e);if(r.length!==Object.keys(n).length)return!1;for(t=0;t<r.length;t++){if(!n.hasOwnProperty(r[t]))return!1;if(!p(e[r[t]],n[r[t]]))return!1}return!0}}var g=function(e){return Array.isArray(e)},v=function(e){return"object"==typeof e&&null!==e&&!g(e)},h=function(e,n){return"expected "+e+", got "+function(e){switch(typeof e){case"string":return"a string";case"number":return"a number";case"boolean":return"a boolean";case"undefined":return"undefined";case"object":return e instanceof Array?"an array":null===e?"null":"an object";default:return JSON.stringify(e)}}(n)},m=function(e){return e.map((function(e){return"string"==typeof e?"."+e:"["+e+"]"})).join("")},b=function(e,n){var t=n.at,r=function(e,n){var t={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&n.indexOf(r)<0&&(t[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)n.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(t[r[o]]=e[r[o]])}return t}(n,["at"]);return d({at:e+(t||"")},r)},y=function(){function e(n){var t=this;this.decode=n,this.run=function(e){return f((function(n){return{kind:"DecoderError",input:e,at:"input"+(n.at||""),message:n.message||""}}),t.decode(e))},this.runPromise=function(e){return a(t.run(e))},this.runWithException=function(e){return c(t.run(e))},this.map=function(n){return new e((function(e){return u(n,t.decode(e))}))},this.andThen=function(n){return new e((function(e){return l((function(t){return n(t).decode(e)}),t.decode(e))}))},this.where=function(n,r){return t.andThen((function(t){return n(t)?e.succeed(t):e.fail(r)}))}}return e.string=function(){return new e((function(e){return"string"==typeof e?o(e):i({message:h("a string",e)})}))},e.number=function(){return new e((function(e){return"number"==typeof e?o(e):i({message:h("a number",e)})}))},e.boolean=function(){return new e((function(e){return"boolean"==typeof e?o(e):i({message:h("a boolean",e)})}))},e.constant=function(n){return new e((function(e){return p(e,n)?o(n):i({message:"expected "+JSON.stringify(n)+", got "+JSON.stringify(e)})}))},e.object=function(n){return new e((function(e){if(v(e)&&n){var t={};for(var r in n)if(n.hasOwnProperty(r)){var a=n[r].decode(e[r]);if(!0!==a.ok)return void 0===e[r]?i({message:"the key '"+r+"' is required but was not present"}):i(b("."+r,a.error));void 0!==a.result&&(t[r]=a.result)}return o(t)}return v(e)?o(e):i({message:h("an object",e)})}))},e.array=function(n){return new e((function(e){if(g(e)&&n){return e.reduce((function(e,t,r){return s((function(e,n){return e.concat([n])}),e,function(e,t){return f((function(e){return b("["+t+"]",e)}),n.decode(e))}(t,r))}),o([]))}return g(e)?o(e):i({message:h("an array",e)})}))},e.tuple=function(n){return new e((function(e){if(g(e)){if(e.length!==n.length)return i({message:"expected a tuple of length "+n.length+", got one of length "+e.length});for(var t=[],r=0;r<n.length;r++){var a=n[r].decode(e[r]);if(!a.ok)return i(b("["+r+"]",a.error));t[r]=a.result}return o(t)}return i({message:h("a tuple of length "+n.length,e)})}))},e.union=function(n,t){for(var r=[],o=2;o<arguments.length;o++)r[o-2]=arguments[o];return e.oneOf.apply(e,[n,t].concat(r))},e.intersection=function(n,t){for(var r=[],i=2;i<arguments.length;i++)r[i-2]=arguments[i];return new e((function(e){return[n,t].concat(r).reduce((function(n,t){return s(Object.assign,n,t.decode(e))}),o({}))}))},e.anyJson=function(){return new e((function(e){return o(e)}))},e.unknownJson=function(){return new e((function(e){return o(e)}))},e.dict=function(n){return new e((function(e){if(v(e)){var t={};for(var r in e)if(e.hasOwnProperty(r)){var a=n.decode(e[r]);if(!0!==a.ok)return i(b("."+r,a.error));t[r]=a.result}return o(t)}return i({message:h("an object",e)})}))},e.optional=function(n){return new e((function(e){return null==e?o(void 0):n.decode(e)}))},e.oneOf=function(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];return new e((function(e){for(var t=[],r=0;r<n.length;r++){var o=n[r].decode(e);if(!0===o.ok)return o;t[r]=o.error}var a=t.map((function(e){return"at error"+(e.at||"")+": "+e.message})).join('", "');return i({message:'expected a value matching one of the decoders, got the errors ["'+a+'"]'})}))},e.withDefault=function(n,t){return new e((function(e){return o(function(e,n){return!0===n.ok?n.result:e}(n,t.decode(e)))}))},e.valueAt=function(n,t){return new e((function(e){for(var r=e,o=0;o<n.length;o++){if(void 0===r)return i({at:m(n.slice(0,o+1)),message:"path does not exist"});if("string"==typeof n[o]&&!v(r))return i({at:m(n.slice(0,o+1)),message:h("an object",r)});if("number"==typeof n[o]&&!g(r))return i({at:m(n.slice(0,o+1)),message:h("an array",r)});r=r[n[o]]}return f((function(e){return void 0===r?{at:m(n),message:"path does not exist"}:b(m(n),e)}),t.decode(r))}))},e.succeed=function(n){return new e((function(e){return o(n)}))},e.fail=function(n){return new e((function(e){return i({message:n})}))},e.lazy=function(n){return new e((function(e){return n().decode(e)}))},e}(),w=y.string;y.number;var k=y.boolean,j=y.anyJson;y.unknownJson,y.constant;var O=y.object,D=y.array;y.tuple,y.dict;var I=y.optional;y.oneOf,y.union,y.intersection,y.withDefault,y.valueAt,y.succeed;var E=y.fail;y.lazy;var S=w().where((function(e){return e.length>0}),"Expected a non-empty string"),x=function(e,n){var t=typeof e;return"function"===t?j():E("The provided argument as ".concat(n," should be of type function, provided: ").concat(typeof t))},B=O({action:S,handler:j().andThen((function(e){return x(e,"handler")}))}),C=O({platform:I(O({url:I(S),openIfMissing:I(k())})),notifications:I(O({defaultClick:I(j().andThen((function(e){return x(e,"defaultClick")}))),actionClicks:I(D(B))}))});let L=(e=21)=>crypto.getRandomValues(new Uint8Array(e)).reduce(((e,n)=>e+=(n&=63)<36?n.toString(36):n<62?(n-26).toString(36).toUpperCase():n>62?"-":"_"),"");const P=(e,n)=>n.some((n=>e instanceof n));let T,N;const M=new WeakMap,A=new WeakMap,W=new WeakMap,J=new WeakMap,V=new WeakMap;let q={get(e,n,t){if(e instanceof IDBTransaction){if("done"===n)return A.get(e);if("objectStoreNames"===n)return e.objectStoreNames||W.get(e);if("store"===n)return t.objectStoreNames[1]?void 0:t.objectStore(t.objectStoreNames[0])}return $(e[n])},set:(e,n,t)=>(e[n]=t,!0),has:(e,n)=>e instanceof IDBTransaction&&("done"===n||"store"===n)||n in e};function U(e){return e!==IDBDatabase.prototype.transaction||"objectStoreNames"in IDBTransaction.prototype?(N||(N=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])).includes(e)?function(...n){return e.apply(F(this),n),$(M.get(this))}:function(...n){return $(e.apply(F(this),n))}:function(n,...t){const r=e.call(F(this),n,...t);return W.set(r,n.sort?n.sort():[n]),$(r)}}function R(e){return"function"==typeof e?U(e):(e instanceof IDBTransaction&&function(e){if(A.has(e))return;const n=new Promise(((n,t)=>{const r=()=>{e.removeEventListener("complete",o),e.removeEventListener("error",i),e.removeEventListener("abort",i)},o=()=>{n(),r()},i=()=>{t(e.error||new DOMException("AbortError","AbortError")),r()};e.addEventListener("complete",o),e.addEventListener("error",i),e.addEventListener("abort",i)}));A.set(e,n)}(e),P(e,T||(T=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction]))?new Proxy(e,q):e)}function $(e){if(e instanceof IDBRequest)return function(e){const n=new Promise(((n,t)=>{const r=()=>{e.removeEventListener("success",o),e.removeEventListener("error",i)},o=()=>{n($(e.result)),r()},i=()=>{t(e.error),r()};e.addEventListener("success",o),e.addEventListener("error",i)}));return n.then((n=>{n instanceof IDBCursor&&M.set(n,e)})).catch((()=>{})),V.set(n,e),n}(e);if(J.has(e))return J.get(e);const n=R(e);return n!==e&&(J.set(e,n),V.set(n,e)),n}const F=e=>V.get(e);const K=["get","getKey","getAll","getAllKeys","count"],_=["put","add","delete","clear"],z=new Map;function G(e,n){if(!(e instanceof IDBDatabase)||n in e||"string"!=typeof n)return;if(z.get(n))return z.get(n);const t=n.replace(/FromIndex$/,""),r=n!==t,o=_.includes(t);if(!(t in(r?IDBIndex:IDBObjectStore).prototype)||!o&&!K.includes(t))return;const i=async function(e,...n){const i=this.transaction(e,o?"readwrite":"readonly");let a=i.store;return r&&(a=a.index(n.shift())),(await Promise.all([a[t](...n),o&&i.done]))[0]};return z.set(n,i),i}var H;q=(e=>({...e,get:(n,t,r)=>G(n,t)||e.get(n,t,r),has:(n,t)=>!!G(n,t)||e.has(n,t)}))(q);var Q=function(e){return e.split("?")[0].split("#")[0].replace(/\/$/,"")},X=function(){return void 0!==H?H:H=function(e,n,{blocked:t,upgrade:r,blocking:o,terminated:i}={}){const a=indexedDB.open(e,n),c=$(a);return r&&a.addEventListener("upgradeneeded",(e=>{r($(a.result),e.oldVersion,e.newVersion,$(a.transaction),e)})),t&&a.addEventListener("blocked",(e=>t(e.oldVersion,e.newVersion,e))),c.then((e=>{i&&e.addEventListener("close",(()=>i())),o&&e.addEventListener("versionchange",(e=>o(e.oldVersion,e.newVersion,e)))})).catch((()=>{})),c}("glue42core",2,{upgrade:function(e){e.objectStoreNames.contains("workspaceLayouts")||e.createObjectStore("workspaceLayouts"),e.objectStoreNames.contains("globalLayouts")||e.createObjectStore("globalLayouts"),e.objectStoreNames.contains("serviceWorker")||e.createObjectStore("serviceWorker")}})},Y=function(){var e=new Promise((function(e){var n=new BroadcastChannel(r),t=function(r){r.data.pong&&(n.removeEventListener("message",t),e(!0))};n.addEventListener("message",t),n.postMessage({messageType:"ping"})})),n=new Promise((function(e){return setTimeout((function(){return e(!1)}),3e3)}));return Promise.race([e,n])},Z=function(e){return n(void 0,void 0,void 0,(function(){var n,r,o;return t(this,(function(t){return(n=Object.assign({},e,{title:void 0,clickInterop:void 0,actions:void 0})).actions=null===(o=e.actions)||void 0===o?void 0:o.map((function(e){return{action:e.action,title:e.title,icon:e.icon}})),r={clickInterop:e.clickInterop,actions:e.actions,id:L()},n.data?n.data.glueData=r:n.data={glueData:r},[2,self.registration.showNotification(e.title,n)]}))}))},ee=function(e){return new Promise((function(n,t){if(!e)return t("Cannot open the platform, because a url was not provided");var o=new BroadcastChannel(r),i=function(e){e.data.platformStarted&&(o.removeEventListener("message",i),n())};o.addEventListener("message",i),self.clients.openWindow(e).catch(t),setTimeout((function(){return t("Timed out waiting for the platform to open and send a ready signal: ".concat(6e4," MS"))}),6e4)}))},ne=function(e){var o=function(e){var n;void 0===e&&(e={});var t=C.runWithException(e);return(null===(n=t.platform)||void 0===n?void 0:n.url)&&(t.platform.url=t.platform.url.replace(/\/$/,"")),t}(e);self.addEventListener("notificationclick",(function(e){var i,a=new BroadcastChannel(r);console.debug("Received a notification, checking if the platform is open");var c=Y().then((function(n){var t,r,a;i=n,console.debug("The platform is: ".concat(i?"open":"not open"));var c=e.action;if(!c&&(null===(t=o.notifications)||void 0===t?void 0:t.defaultClick))return console.debug("Calling a defined default click handler"),o.notifications.defaultClick(e,i);if(c&&(null===(a=null===(r=o.notifications)||void 0===r?void 0:r.actionClicks)||void 0===a?void 0:a.some((function(e){return e.action===c})))){var u=o.notifications.actionClicks.find((function(e){return e.action===c})).handler;return console.debug("Calling a defined action click handler for action: ".concat(c)),u(e,i)}})).then((function(){return console.debug("Getting the platform url"),function(e){return n(void 0,void 0,void 0,(function(){var n,r,o,i,a,c;return t(this,(function(t){switch(t.label){case 0:return(null===(a=e.platform)||void 0===a?void 0:a.url)?(n=e.platform.url.split("?")[0].split("#")[0],console.debug("getting url from config: ".concat(n)),[2,Q(n)]):(console.debug("starting the db"),[4,X()]);case 1:return(r=t.sent()).objectStoreNames.contains("serviceWorker")?[4,r.get("serviceWorker","workerData")]:(console.warn("there is no service worker store"),[2]);case 2:return o=t.sent(),i=null===(c=null==o?void 0:o.platformUrl)||void 0===c?void 0:c.split("?")[0].split("#")[0],[2,Q(i)]}}))}))}(o)})).then((function(r){var a,c,u;if(console.debug("Found platform url: ".concat(r)),!i&&(null===(a=o.platform)||void 0===a?void 0:a.openIfMissing))return console.debug("Opening the platform"),ee(r);var s=null===(u=null===(c=e.notification.data)||void 0===c?void 0:c.glueData)||void 0===u?void 0:u.focusPlatformOnDefaultClick;return i&&s?(console.debug("Focusing the platform"),function(e){return n(void 0,void 0,void 0,(function(){var n,r,o,i;return t(this,(function(t){switch(t.label){case 0:return e?[4,self.clients.matchAll({type:"window"})]:(console.warn("Cannot open the platform, because a url was not provided"),[2]);case 1:n=t.sent(),r=0,o=n,t.label=2;case 2:return r<o.length?(i=o[r],i.url.split("?")[0].split("#")[0].replace(/\/$/,"")!==e?[3,4]:[4,i.focus()]):[3,5];case 3:return t.sent(),[2];case 4:return r++,[3,2];case 5:return[2]}}))}))}(r)):void 0})).then((function(){var n=e.action,t=e.notification.data.glueData,r={badge:e.notification.badge,body:e.notification.body,data:e.notification.data,dir:e.notification.dir,icon:e.notification.icon,image:e.notification.image,lang:e.notification.lang,renotify:e.notification.renotify,requireInteraction:e.notification.requireInteraction,silent:e.notification.silent,tag:e.notification.tag,timestamp:e.notification.timestamp,vibrate:e.notification.vibrate};a.postMessage({messageType:"notificationClick",action:n,glueData:t,definition:r})})).catch((function(e){var n="string"==typeof e?e:JSON.stringify(e.message);a.postMessage({messageType:"notificationError",error:n})}));e.waitUntil(c)})),self.addEventListener("notificationclose",(function(e){var n=new BroadcastChannel(r);console.debug("Received a notification close event, checking if the platform is open");var t=Y().then((function(t){if(console.debug("The platform is: ".concat(t?"open":"not open")),t){var r=e.action,o=e.notification.data.glueData,i={badge:e.notification.badge,body:e.notification.body,data:e.notification.data,dir:e.notification.dir,icon:e.notification.icon,image:e.notification.image,lang:e.notification.lang,renotify:e.notification.renotify,requireInteraction:e.notification.requireInteraction,silent:e.notification.silent,tag:e.notification.tag,timestamp:e.notification.timestamp,vibrate:e.notification.vibrate};n.postMessage({messageType:"notificationClose",action:r,glueData:o,definition:i})}else console.log("The platform is not opened and will not open it for a notification close event")})).catch((function(e){var t="string"==typeof e?e:JSON.stringify(e.message);n.postMessage({messageType:"notificationError",error:t})}));e.waitUntil(t)}))};"undefined"!=typeof self&&(self.IOWorker=ne,self.openBrowserPlatform=ee,self.raiseIONotification=Z),e.default=ne,e.openBrowserPlatform=ee,e.raiseIONotification=Z,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
***************************************************************************** */function n(e,n,t,r){return new(t||(t=Promise))((function(o,i){function a(e){try{u(r.next(e))}catch(e){i(e)}}function c(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var n;e.done?o(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(a,c)}u((r=r.apply(e,n||[])).next())}))}function t(e,n){var t,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(t)throw new TypeError("Generator is already executing.");for(;a;)try{if(t=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=n.call(e,a)}catch(e){i=[6,e],r=0}finally{t=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}var r="glue42-core-worker",o=function(e){return{ok:!0,result:e}},i=function(e){return{ok:!1,error:e}},a=function(e){return!0===e.ok?Promise.resolve(e.result):Promise.reject(e.error)},c=function(e){if(!0===e.ok)return e.result;throw e.error},u=function(e,n){return!0===n.ok?o(e(n.result)):n},s=function(e,n,t){return!1===n.ok?n:!1===t.ok?t:o(e(n.result,t.result))},f=function(e,n){return!0===n.ok?n:i(e(n.error))},l=function(e,n){return!0===n.ok?e(n.result):n},d=function(){return d=Object.assign||function(e){for(var n,t=1,r=arguments.length;t<r;t++)for(var o in n=arguments[t])Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o]);return e},d.apply(this,arguments)};function p(e,n){if(e===n)return!0;if(null===e&&null===n)return!0;if(typeof e!=typeof n)return!1;if("object"==typeof e){if(Array.isArray(e)){if(!Array.isArray(n))return!1;if(e.length!==n.length)return!1;for(var t=0;t<e.length;t++)if(!p(e[t],n[t]))return!1;return!0}var r=Object.keys(e);if(r.length!==Object.keys(n).length)return!1;for(t=0;t<r.length;t++){if(!n.hasOwnProperty(r[t]))return!1;if(!p(e[r[t]],n[r[t]]))return!1}return!0}}var g=function(e){return Array.isArray(e)},v=function(e){return"object"==typeof e&&null!==e&&!g(e)},h=function(e,n){return"expected "+e+", got "+function(e){switch(typeof e){case"string":return"a string";case"number":return"a number";case"boolean":return"a boolean";case"undefined":return"undefined";case"object":return e instanceof Array?"an array":null===e?"null":"an object";default:return JSON.stringify(e)}}(n)},m=function(e){return e.map((function(e){return"string"==typeof e?"."+e:"["+e+"]"})).join("")},b=function(e,n){var t=n.at,r=function(e,n){var t={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&n.indexOf(r)<0&&(t[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)n.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(t[r[o]]=e[r[o]])}return t}(n,["at"]);return d({at:e+(t||"")},r)},y=function(){function e(n){var t=this;this.decode=n,this.run=function(e){return f((function(n){return{kind:"DecoderError",input:e,at:"input"+(n.at||""),message:n.message||""}}),t.decode(e))},this.runPromise=function(e){return a(t.run(e))},this.runWithException=function(e){return c(t.run(e))},this.map=function(n){return new e((function(e){return u(n,t.decode(e))}))},this.andThen=function(n){return new e((function(e){return l((function(t){return n(t).decode(e)}),t.decode(e))}))},this.where=function(n,r){return t.andThen((function(t){return n(t)?e.succeed(t):e.fail(r)}))}}return e.string=function(){return new e((function(e){return"string"==typeof e?o(e):i({message:h("a string",e)})}))},e.number=function(){return new e((function(e){return"number"==typeof e?o(e):i({message:h("a number",e)})}))},e.boolean=function(){return new e((function(e){return"boolean"==typeof e?o(e):i({message:h("a boolean",e)})}))},e.constant=function(n){return new e((function(e){return p(e,n)?o(n):i({message:"expected "+JSON.stringify(n)+", got "+JSON.stringify(e)})}))},e.object=function(n){return new e((function(e){if(v(e)&&n){var t={};for(var r in n)if(n.hasOwnProperty(r)){var a=n[r].decode(e[r]);if(!0!==a.ok)return void 0===e[r]?i({message:"the key '"+r+"' is required but was not present"}):i(b("."+r,a.error));void 0!==a.result&&(t[r]=a.result)}return o(t)}return v(e)?o(e):i({message:h("an object",e)})}))},e.array=function(n){return new e((function(e){if(g(e)&&n){return e.reduce((function(e,t,r){return s((function(e,n){return e.concat([n])}),e,function(e,t){return f((function(e){return b("["+t+"]",e)}),n.decode(e))}(t,r))}),o([]))}return g(e)?o(e):i({message:h("an array",e)})}))},e.tuple=function(n){return new e((function(e){if(g(e)){if(e.length!==n.length)return i({message:"expected a tuple of length "+n.length+", got one of length "+e.length});for(var t=[],r=0;r<n.length;r++){var a=n[r].decode(e[r]);if(!a.ok)return i(b("["+r+"]",a.error));t[r]=a.result}return o(t)}return i({message:h("a tuple of length "+n.length,e)})}))},e.union=function(n,t){for(var r=[],o=2;o<arguments.length;o++)r[o-2]=arguments[o];return e.oneOf.apply(e,[n,t].concat(r))},e.intersection=function(n,t){for(var r=[],i=2;i<arguments.length;i++)r[i-2]=arguments[i];return new e((function(e){return[n,t].concat(r).reduce((function(n,t){return s(Object.assign,n,t.decode(e))}),o({}))}))},e.anyJson=function(){return new e((function(e){return o(e)}))},e.unknownJson=function(){return new e((function(e){return o(e)}))},e.dict=function(n){return new e((function(e){if(v(e)){var t={};for(var r in e)if(e.hasOwnProperty(r)){var a=n.decode(e[r]);if(!0!==a.ok)return i(b("."+r,a.error));t[r]=a.result}return o(t)}return i({message:h("an object",e)})}))},e.optional=function(n){return new e((function(e){return null==e?o(void 0):n.decode(e)}))},e.oneOf=function(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];return new e((function(e){for(var t=[],r=0;r<n.length;r++){var o=n[r].decode(e);if(!0===o.ok)return o;t[r]=o.error}var a=t.map((function(e){return"at error"+(e.at||"")+": "+e.message})).join('", "');return i({message:'expected a value matching one of the decoders, got the errors ["'+a+'"]'})}))},e.withDefault=function(n,t){return new e((function(e){return o(function(e,n){return!0===n.ok?n.result:e}(n,t.decode(e)))}))},e.valueAt=function(n,t){return new e((function(e){for(var r=e,o=0;o<n.length;o++){if(void 0===r)return i({at:m(n.slice(0,o+1)),message:"path does not exist"});if("string"==typeof n[o]&&!v(r))return i({at:m(n.slice(0,o+1)),message:h("an object",r)});if("number"==typeof n[o]&&!g(r))return i({at:m(n.slice(0,o+1)),message:h("an array",r)});r=r[n[o]]}return f((function(e){return void 0===r?{at:m(n),message:"path does not exist"}:b(m(n),e)}),t.decode(r))}))},e.succeed=function(n){return new e((function(e){return o(n)}))},e.fail=function(n){return new e((function(e){return i({message:n})}))},e.lazy=function(n){return new e((function(e){return n().decode(e)}))},e}(),w=y.string;y.number;var k=y.boolean,j=y.anyJson;y.unknownJson,y.constant;var O=y.object,D=y.array;y.tuple,y.dict;var I=y.optional;y.oneOf,y.union,y.intersection,y.withDefault,y.valueAt,y.succeed;var E=y.fail;y.lazy;var S=w().where((function(e){return e.length>0}),"Expected a non-empty string"),x=function(e,n){var t=typeof e;return"function"===t?j():E("The provided argument as ".concat(n," should be of type function, provided: ").concat(typeof t))},B=O({action:S,handler:j().andThen((function(e){return x(e,"handler")}))}),C=O({platform:I(O({url:I(S),openIfMissing:I(k())})),notifications:I(O({defaultClick:I(j().andThen((function(e){return x(e,"defaultClick")}))),actionClicks:I(D(B))}))});let L=(e=21)=>crypto.getRandomValues(new Uint8Array(e)).reduce(((e,n)=>e+=(n&=63)<36?n.toString(36):n<62?(n-26).toString(36).toUpperCase():n>62?"-":"_"),"");const P=(e,n)=>n.some((n=>e instanceof n));let T,N;const M=new WeakMap,A=new WeakMap,W=new WeakMap,J=new WeakMap,V=new WeakMap;let q={get(e,n,t){if(e instanceof IDBTransaction){if("done"===n)return A.get(e);if("objectStoreNames"===n)return e.objectStoreNames||W.get(e);if("store"===n)return t.objectStoreNames[1]?void 0:t.objectStore(t.objectStoreNames[0])}return $(e[n])},set:(e,n,t)=>(e[n]=t,!0),has:(e,n)=>e instanceof IDBTransaction&&("done"===n||"store"===n)||n in e};function U(e){return e!==IDBDatabase.prototype.transaction||"objectStoreNames"in IDBTransaction.prototype?(N||(N=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])).includes(e)?function(...n){return e.apply(F(this),n),$(M.get(this))}:function(...n){return $(e.apply(F(this),n))}:function(n,...t){const r=e.call(F(this),n,...t);return W.set(r,n.sort?n.sort():[n]),$(r)}}function R(e){return"function"==typeof e?U(e):(e instanceof IDBTransaction&&function(e){if(A.has(e))return;const n=new Promise(((n,t)=>{const r=()=>{e.removeEventListener("complete",o),e.removeEventListener("error",i),e.removeEventListener("abort",i)},o=()=>{n(),r()},i=()=>{t(e.error||new DOMException("AbortError","AbortError")),r()};e.addEventListener("complete",o),e.addEventListener("error",i),e.addEventListener("abort",i)}));A.set(e,n)}(e),P(e,T||(T=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction]))?new Proxy(e,q):e)}function $(e){if(e instanceof IDBRequest)return function(e){const n=new Promise(((n,t)=>{const r=()=>{e.removeEventListener("success",o),e.removeEventListener("error",i)},o=()=>{n($(e.result)),r()},i=()=>{t(e.error),r()};e.addEventListener("success",o),e.addEventListener("error",i)}));return n.then((n=>{n instanceof IDBCursor&&M.set(n,e)})).catch((()=>{})),V.set(n,e),n}(e);if(J.has(e))return J.get(e);const n=R(e);return n!==e&&(J.set(e,n),V.set(n,e)),n}const F=e=>V.get(e);const K=["get","getKey","getAll","getAllKeys","count"],_=["put","add","delete","clear"],z=new Map;function G(e,n){if(!(e instanceof IDBDatabase)||n in e||"string"!=typeof n)return;if(z.get(n))return z.get(n);const t=n.replace(/FromIndex$/,""),r=n!==t,o=_.includes(t);if(!(t in(r?IDBIndex:IDBObjectStore).prototype)||!o&&!K.includes(t))return;const i=async function(e,...n){const i=this.transaction(e,o?"readwrite":"readonly");let a=i.store;return r&&(a=a.index(n.shift())),(await Promise.all([a[t](...n),o&&i.done]))[0]};return z.set(n,i),i}var H;q=(e=>({...e,get:(n,t,r)=>G(n,t)||e.get(n,t,r),has:(n,t)=>!!G(n,t)||e.has(n,t)}))(q);var Q=function(e){return e.split("?")[0].split("#")[0].replace(/\/$/,"")},X=function(){return void 0!==H?H:H=function(e,n,{blocked:t,upgrade:r,blocking:o,terminated:i}={}){const a=indexedDB.open(e,n),c=$(a);return r&&a.addEventListener("upgradeneeded",(e=>{r($(a.result),e.oldVersion,e.newVersion,$(a.transaction),e)})),t&&a.addEventListener("blocked",(e=>t(e.oldVersion,e.newVersion,e))),c.then((e=>{i&&e.addEventListener("close",(()=>i())),o&&e.addEventListener("versionchange",(e=>o(e.oldVersion,e.newVersion,e)))})).catch((()=>{})),c}("glue42core",3,{upgrade:function(e){e.objectStoreNames.contains("workspaceLayouts")||e.createObjectStore("workspaceLayouts"),e.objectStoreNames.contains("globalLayouts")||e.createObjectStore("globalLayouts"),e.objectStoreNames.contains("serviceWorker")||e.createObjectStore("serviceWorker"),e.objectStoreNames.contains("prefs")||e.createObjectStore("prefs")}})},Y=function(){var e=new Promise((function(e){var n=new BroadcastChannel(r),t=function(r){r.data.pong&&(n.removeEventListener("message",t),e(!0))};n.addEventListener("message",t),n.postMessage({messageType:"ping"})})),n=new Promise((function(e){return setTimeout((function(){return e(!1)}),3e3)}));return Promise.race([e,n])},Z=function(e){return n(void 0,void 0,void 0,(function(){var n,r,o;return t(this,(function(t){return(n=Object.assign({},e,{title:void 0,clickInterop:void 0,actions:void 0})).actions=null===(o=e.actions)||void 0===o?void 0:o.map((function(e){return{action:e.action,title:e.title,icon:e.icon}})),r={clickInterop:e.clickInterop,actions:e.actions,id:L()},n.data?n.data.glueData=r:n.data={glueData:r},[2,self.registration.showNotification(e.title,n)]}))}))},ee=function(e){return new Promise((function(n,t){if(!e)return t("Cannot open the platform, because a url was not provided");var o=new BroadcastChannel(r),i=function(e){e.data.platformStarted&&(o.removeEventListener("message",i),n())};o.addEventListener("message",i),self.clients.openWindow(e).catch(t),setTimeout((function(){return t("Timed out waiting for the platform to open and send a ready signal: ".concat(6e4," MS"))}),6e4)}))},ne=function(e){var o=function(e){var n;void 0===e&&(e={});var t=C.runWithException(e);return(null===(n=t.platform)||void 0===n?void 0:n.url)&&(t.platform.url=t.platform.url.replace(/\/$/,"")),t}(e);self.addEventListener("notificationclick",(function(e){var i,a=new BroadcastChannel(r);console.debug("Received a notification, checking if the platform is open");var c=Y().then((function(n){var t,r,a;i=n,console.debug("The platform is: ".concat(i?"open":"not open"));var c=e.action;if(!c&&(null===(t=o.notifications)||void 0===t?void 0:t.defaultClick))return console.debug("Calling a defined default click handler"),o.notifications.defaultClick(e,i);if(c&&(null===(a=null===(r=o.notifications)||void 0===r?void 0:r.actionClicks)||void 0===a?void 0:a.some((function(e){return e.action===c})))){var u=o.notifications.actionClicks.find((function(e){return e.action===c})).handler;return console.debug("Calling a defined action click handler for action: ".concat(c)),u(e,i)}})).then((function(){return console.debug("Getting the platform url"),function(e){return n(void 0,void 0,void 0,(function(){var n,r,o,i,a,c;return t(this,(function(t){switch(t.label){case 0:return(null===(a=e.platform)||void 0===a?void 0:a.url)?(n=e.platform.url.split("?")[0].split("#")[0],console.debug("getting url from config: ".concat(n)),[2,Q(n)]):(console.debug("starting the db"),[4,X()]);case 1:return(r=t.sent()).objectStoreNames.contains("serviceWorker")?[4,r.get("serviceWorker","workerData")]:(console.warn("there is no service worker store"),[2]);case 2:return o=t.sent(),i=null===(c=null==o?void 0:o.platformUrl)||void 0===c?void 0:c.split("?")[0].split("#")[0],[2,Q(i)]}}))}))}(o)})).then((function(r){var a,c,u;if(console.debug("Found platform url: ".concat(r)),!i&&(null===(a=o.platform)||void 0===a?void 0:a.openIfMissing))return console.debug("Opening the platform"),ee(r);var s=null===(u=null===(c=e.notification.data)||void 0===c?void 0:c.glueData)||void 0===u?void 0:u.focusPlatformOnDefaultClick;return i&&s?(console.debug("Focusing the platform"),function(e){return n(void 0,void 0,void 0,(function(){var n,r,o,i;return t(this,(function(t){switch(t.label){case 0:return e?[4,self.clients.matchAll({type:"window"})]:(console.warn("Cannot open the platform, because a url was not provided"),[2]);case 1:n=t.sent(),r=0,o=n,t.label=2;case 2:return r<o.length?(i=o[r],i.url.split("?")[0].split("#")[0].replace(/\/$/,"")!==e?[3,4]:[4,i.focus()]):[3,5];case 3:return t.sent(),[2];case 4:return r++,[3,2];case 5:return[2]}}))}))}(r)):void 0})).then((function(){var n=e.action,t=e.notification.data.glueData,r={badge:e.notification.badge,body:e.notification.body,data:e.notification.data,dir:e.notification.dir,icon:e.notification.icon,image:e.notification.image,lang:e.notification.lang,renotify:e.notification.renotify,requireInteraction:e.notification.requireInteraction,silent:e.notification.silent,tag:e.notification.tag,timestamp:e.notification.timestamp,vibrate:e.notification.vibrate};a.postMessage({messageType:"notificationClick",action:n,glueData:t,definition:r})})).catch((function(e){var n="string"==typeof e?e:JSON.stringify(e.message);a.postMessage({messageType:"notificationError",error:n})}));e.waitUntil(c)})),self.addEventListener("notificationclose",(function(e){var n=new BroadcastChannel(r);console.debug("Received a notification close event, checking if the platform is open");var t=Y().then((function(t){if(console.debug("The platform is: ".concat(t?"open":"not open")),t){var r=e.action,o=e.notification.data.glueData,i={badge:e.notification.badge,body:e.notification.body,data:e.notification.data,dir:e.notification.dir,icon:e.notification.icon,image:e.notification.image,lang:e.notification.lang,renotify:e.notification.renotify,requireInteraction:e.notification.requireInteraction,silent:e.notification.silent,tag:e.notification.tag,timestamp:e.notification.timestamp,vibrate:e.notification.vibrate};n.postMessage({messageType:"notificationClose",action:r,glueData:o,definition:i})}else console.log("The platform is not opened and will not open it for a notification close event")})).catch((function(e){var t="string"==typeof e?e:JSON.stringify(e.message);n.postMessage({messageType:"notificationError",error:t})}));e.waitUntil(t)}))};"undefined"!=typeof self&&(self.IOWorker=ne,self.openBrowserPlatform=ee,self.raiseIONotification=Z),e.default=ne,e.openBrowserPlatform=ee,e.raiseIONotification=Z,Object.defineProperty(e,"__esModule",{value:!0})})); |
{ | ||
"name": "@interopio/browser-worker", | ||
"version": "3.1.1", | ||
"version": "3.2.0", | ||
"main": "dist/web.worker.umd.js", | ||
@@ -56,3 +56,3 @@ "module": "dist/web.worker.es.js", | ||
}, | ||
"gitHead": "abd515916de960fd357dadab2b300c4bbe12f91d" | ||
"gitHead": "4f543b0cb0bd2c313785b9662a07fc442253a2ea" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
370946
2873