@amedia/user 0.12.10 → 0.12.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
1
  import { UserAttributes } from '../types';
2
- export declare const requestAttributes: (attributes: Array<keyof UserAttributes>) => void;
2
+ export declare const requestAttributes: (attributes: Array<keyof UserAttributes>) => Promise<void>;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,2 +1,2 @@
1
1
  import { UserAttributes } from '../types';
2
- export declare const getInfo: (publicationDomain: string, browserId: string, userKey?: string | undefined) => Promise<Pick<UserAttributes, 'extraData'>>;
2
+ export declare const getInfo: (publicationDomain: string, browserId: string, trackingKey?: string | undefined) => Promise<Pick<UserAttributes, 'extraData'>>;
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  /*! For license information please see index.js.LICENSE.txt */
2
- var e={651:(e,t,n)=>{var r,o,i;void 0===(o="function"==typeof(r=i=function(){function e(){for(var e=0,t={};e<arguments.length;e++){var n=arguments[e];for(var r in n)t[r]=n[r]}return t}function t(e){return e.replace(/(%[0-9A-Z]{2})+/g,decodeURIComponent)}return function n(r){function o(){}function i(t,n,i){if("undefined"!=typeof document){"number"==typeof(i=e({path:"/"},o.defaults,i)).expires&&(i.expires=new Date(1*new Date+864e5*i.expires)),i.expires=i.expires?i.expires.toUTCString():"";try{var a=JSON.stringify(n);/^[\{\[]/.test(a)&&(n=a)}catch(e){}n=r.write?r.write(n,t):encodeURIComponent(String(n)).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,decodeURIComponent),t=encodeURIComponent(String(t)).replace(/%(23|24|26|2B|5E|60|7C)/g,decodeURIComponent).replace(/[\(\)]/g,escape);var c="";for(var u in i)i[u]&&(c+="; "+u,!0!==i[u]&&(c+="="+i[u].split(";")[0]));return document.cookie=t+"="+n+c}}function a(e,n){if("undefined"!=typeof document){for(var o={},i=document.cookie?document.cookie.split("; "):[],a=0;a<i.length;a++){var c=i[a].split("="),u=c.slice(1).join("=");n||'"'!==u.charAt(0)||(u=u.slice(1,-1));try{var s=t(c[0]);if(u=(r.read||r)(u,s)||t(u),n)try{u=JSON.parse(u)}catch(e){}if(o[s]=u,e===s)break}catch(e){}}return e?o[e]:o}}return o.set=i,o.get=function(e){return a(e,!1)},o.getJSON=function(e){return a(e,!0)},o.remove=function(t,n){i(t,"",e(n,{expires:-1}))},o.defaults={},o.withConverter=n,o}((function(){}))})?r.call(t,n,t,e):r)||(e.exports=o),e.exports=i()},466:(e,t,n)=>{e.exports=function e(t,n,r){function o(a,c){if(!n[a]){if(!t[a]){if(i)return i(a,!0);var u=new Error("Cannot find module '"+a+"'");throw u.code="MODULE_NOT_FOUND",u}var s=n[a]={exports:{}};t[a][0].call(s.exports,(function(e){return o(t[a][1][e]||e)}),s,s.exports,e,t,n,r)}return n[a].exports}for(var i=void 0,a=0;a<r.length;a++)o(r[a]);return o}({1:[function(e,t,r){(function(e){var n,r,o=e.MutationObserver||e.WebKitMutationObserver;if(o){var i=0,a=new o(f),c=e.document.createTextNode("");a.observe(c,{characterData:!0}),n=function(){c.data=i=++i%2}}else if(e.setImmediate||void 0===e.MessageChannel)n="document"in e&&"onreadystatechange"in e.document.createElement("script")?function(){var t=e.document.createElement("script");t.onreadystatechange=function(){f(),t.onreadystatechange=null,t.parentNode.removeChild(t),t=null},e.document.documentElement.appendChild(t)}:function(){setTimeout(f,0)};else{var u=new e.MessageChannel;u.port1.onmessage=f,n=function(){u.port2.postMessage(0)}}var s=[];function f(){var e,t;r=!0;for(var n=s.length;n;){for(t=s,s=[],e=-1;++e<n;)t[e]();n=s.length}r=!1}t.exports=function(e){1!==s.push(e)||r||n()}}).call(this,void 0!==n.g?n.g:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],2:[function(e,t,n){var r=e(1);function o(){}var i={},a=["REJECTED"],c=["FULFILLED"],u=["PENDING"];function s(e){if("function"!=typeof e)throw new TypeError("resolver must be a function");this.state=u,this.queue=[],this.outcome=void 0,e!==o&&v(this,e)}function f(e,t,n){this.promise=e,"function"==typeof t&&(this.onFulfilled=t,this.callFulfilled=this.otherCallFulfilled),"function"==typeof n&&(this.onRejected=n,this.callRejected=this.otherCallRejected)}function l(e,t,n){r((function(){var r;try{r=t(n)}catch(t){return i.reject(e,t)}r===e?i.reject(e,new TypeError("Cannot resolve promise with itself")):i.resolve(e,r)}))}function d(e){var t=e&&e.then;if(e&&("object"==typeof e||"function"==typeof e)&&"function"==typeof t)return function(){t.apply(e,arguments)}}function v(e,t){var n=!1;function r(t){n||(n=!0,i.reject(e,t))}function o(t){n||(n=!0,i.resolve(e,t))}var a=h((function(){t(o,r)}));"error"===a.status&&r(a.value)}function h(e,t){var n={};try{n.value=e(t),n.status="success"}catch(e){n.status="error",n.value=e}return n}t.exports=s,s.prototype.catch=function(e){return this.then(null,e)},s.prototype.then=function(e,t){if("function"!=typeof e&&this.state===c||"function"!=typeof t&&this.state===a)return this;var n=new this.constructor(o);return this.state!==u?l(n,this.state===c?e:t,this.outcome):this.queue.push(new f(n,e,t)),n},f.prototype.callFulfilled=function(e){i.resolve(this.promise,e)},f.prototype.otherCallFulfilled=function(e){l(this.promise,this.onFulfilled,e)},f.prototype.callRejected=function(e){i.reject(this.promise,e)},f.prototype.otherCallRejected=function(e){l(this.promise,this.onRejected,e)},i.resolve=function(e,t){var n=h(d,t);if("error"===n.status)return i.reject(e,n.value);var r=n.value;if(r)v(e,r);else{e.state=c,e.outcome=t;for(var o=-1,a=e.queue.length;++o<a;)e.queue[o].callFulfilled(t)}return e},i.reject=function(e,t){e.state=a,e.outcome=t;for(var n=-1,r=e.queue.length;++n<r;)e.queue[n].callRejected(t);return e},s.resolve=function(e){return e instanceof this?e:i.resolve(new this(o),e)},s.reject=function(e){var t=new this(o);return i.reject(t,e)},s.all=function(e){var t=this;if("[object Array]"!==Object.prototype.toString.call(e))return this.reject(new TypeError("must be an array"));var n=e.length,r=!1;if(!n)return this.resolve([]);for(var a=new Array(n),c=0,u=-1,s=new this(o);++u<n;)f(e[u],u);return s;function f(e,o){t.resolve(e).then((function(e){a[o]=e,++c!==n||r||(r=!0,i.resolve(s,a))}),(function(e){r||(r=!0,i.reject(s,e))}))}},s.race=function(e){var t=this;if("[object Array]"!==Object.prototype.toString.call(e))return this.reject(new TypeError("must be an array"));var n,r=e.length,a=!1;if(!r)return this.resolve([]);for(var c=-1,u=new this(o);++c<r;)n=e[c],t.resolve(n).then((function(e){a||(a=!0,i.resolve(u,e))}),(function(e){a||(a=!0,i.reject(u,e))}));return u}},{1:1}],3:[function(e,t,r){(function(t){"function"!=typeof t.Promise&&(t.Promise=e(2))}).call(this,void 0!==n.g?n.g:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{2:2}],4:[function(e,t,n){var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};var o=function(){try{if("undefined"!=typeof indexedDB)return indexedDB;if("undefined"!=typeof webkitIndexedDB)return webkitIndexedDB;if("undefined"!=typeof mozIndexedDB)return mozIndexedDB;if("undefined"!=typeof OIndexedDB)return OIndexedDB;if("undefined"!=typeof msIndexedDB)return msIndexedDB}catch(e){return}}();function i(e,t){e=e||[],t=t||{};try{return new Blob(e,t)}catch(o){if("TypeError"!==o.name)throw o;for(var n=new("undefined"!=typeof BlobBuilder?BlobBuilder:"undefined"!=typeof MSBlobBuilder?MSBlobBuilder:"undefined"!=typeof MozBlobBuilder?MozBlobBuilder:WebKitBlobBuilder),r=0;r<e.length;r+=1)n.append(e[r]);return n.getBlob(t.type)}}"undefined"==typeof Promise&&e(3);var a=Promise;function c(e,t){t&&e.then((function(e){t(null,e)}),(function(e){t(e)}))}function u(e,t,n){"function"==typeof t&&e.then(t),"function"==typeof n&&e.catch(n)}function s(e){return"string"!=typeof e&&(console.warn(e+" used as a key, but it is not a string."),e=String(e)),e}function f(){if(arguments.length&&"function"==typeof arguments[arguments.length-1])return arguments[arguments.length-1]}var l="local-forage-detect-blob-support",d=void 0,v={},h=Object.prototype.toString,p="readonly",y="readwrite";function g(e){for(var t=e.length,n=new ArrayBuffer(t),r=new Uint8Array(n),o=0;o<t;o++)r[o]=e.charCodeAt(o);return n}function m(e){return"boolean"==typeof d?a.resolve(d):function(e){return new a((function(t){var n=e.transaction(l,y),r=i([""]);n.objectStore(l).put(r,"key"),n.onabort=function(e){e.preventDefault(),e.stopPropagation(),t(!1)},n.oncomplete=function(){var e=navigator.userAgent.match(/Chrome\/(\d+)/),n=navigator.userAgent.match(/Edge\//);t(n||!e||parseInt(e[1],10)>=43)}})).catch((function(){return!1}))}(e).then((function(e){return d=e}))}function b(e){var t=v[e.name],n={};n.promise=new a((function(e,t){n.resolve=e,n.reject=t})),t.deferredOperations.push(n),t.dbReady?t.dbReady=t.dbReady.then((function(){return n.promise})):t.dbReady=n.promise}function E(e){var t=v[e.name].deferredOperations.pop();if(t)return t.resolve(),t.promise}function _(e,t){var n=v[e.name].deferredOperations.pop();if(n)return n.reject(t),n.promise}function w(e,t){return new a((function(n,r){if(v[e.name]=v[e.name]||{forages:[],db:null,dbReady:null,deferredOperations:[]},e.db){if(!t)return n(e.db);b(e),e.db.close()}var i=[e.name];t&&i.push(e.version);var a=o.open.apply(o,i);t&&(a.onupgradeneeded=function(t){var n=a.result;try{n.createObjectStore(e.storeName),t.oldVersion<=1&&n.createObjectStore(l)}catch(n){if("ConstraintError"!==n.name)throw n;console.warn('The database "'+e.name+'" has been upgraded from version '+t.oldVersion+" to version "+t.newVersion+', but the storage "'+e.storeName+'" already exists.')}}),a.onerror=function(e){e.preventDefault(),r(a.error)},a.onsuccess=function(){n(a.result),E(e)}}))}function S(e){return w(e,!1)}function R(e){return w(e,!0)}function O(e,t){if(!e.db)return!0;var n=!e.db.objectStoreNames.contains(e.storeName),r=e.version<e.db.version,o=e.version>e.db.version;if(r&&(e.version!==t&&console.warn('The database "'+e.name+"\" can't be downgraded from version "+e.db.version+" to version "+e.version+"."),e.version=e.db.version),o||n){if(n){var i=e.db.version+1;i>e.version&&(e.version=i)}return!0}return!1}function I(e){return i([g(atob(e.data))],{type:e.type})}function C(e){return e&&e.__local_forage_encoded_blob}function T(e){var t=this,n=t._initReady().then((function(){var e=v[t._dbInfo.name];if(e&&e.dbReady)return e.dbReady}));return u(n,e,e),n}function A(e,t,n,r){void 0===r&&(r=1);try{var o=e.db.transaction(e.storeName,t);n(null,o)}catch(o){if(r>0&&(!e.db||"InvalidStateError"===o.name||"NotFoundError"===o.name))return a.resolve().then((function(){if(!e.db||"NotFoundError"===o.name&&!e.db.objectStoreNames.contains(e.storeName)&&e.version<=e.db.version)return e.db&&(e.version=e.db.version+1),R(e)})).then((function(){return function(e){b(e);for(var t=v[e.name],n=t.forages,r=0;r<n.length;r++){var o=n[r];o._dbInfo.db&&(o._dbInfo.db.close(),o._dbInfo.db=null)}return e.db=null,S(e).then((function(t){return e.db=t,O(e)?R(e):t})).then((function(r){e.db=t.db=r;for(var o=0;o<n.length;o++)n[o]._dbInfo.db=r})).catch((function(t){throw _(e,t),t}))}(e).then((function(){A(e,t,n,r-1)}))})).catch(n);n(o)}}var N={_driver:"asyncStorage",_initStorage:function(e){var t=this,n={db:null};if(e)for(var r in e)n[r]=e[r];var o=v[n.name];o||(o={forages:[],db:null,dbReady:null,deferredOperations:[]},v[n.name]=o),o.forages.push(t),t._initReady||(t._initReady=t.ready,t.ready=T);var i=[];function c(){return a.resolve()}for(var u=0;u<o.forages.length;u++){var s=o.forages[u];s!==t&&i.push(s._initReady().catch(c))}var f=o.forages.slice(0);return a.all(i).then((function(){return n.db=o.db,S(n)})).then((function(e){return n.db=e,O(n,t._defaultConfig.version)?R(n):e})).then((function(e){n.db=o.db=e,t._dbInfo=n;for(var r=0;r<f.length;r++){var i=f[r];i!==t&&(i._dbInfo.db=n.db,i._dbInfo.version=n.version)}}))},_support:function(){try{if(!o||!o.open)return!1;var e="undefined"!=typeof openDatabase&&/(Safari|iPhone|iPad|iPod)/.test(navigator.userAgent)&&!/Chrome/.test(navigator.userAgent)&&!/BlackBerry/.test(navigator.platform),t="function"==typeof fetch&&-1!==fetch.toString().indexOf("[native code");return(!e||t)&&"undefined"!=typeof indexedDB&&"undefined"!=typeof IDBKeyRange}catch(e){return!1}}(),iterate:function(e,t){var n=this,r=new a((function(t,r){n.ready().then((function(){A(n._dbInfo,p,(function(o,i){if(o)return r(o);try{var a=i.objectStore(n._dbInfo.storeName).openCursor(),c=1;a.onsuccess=function(){var n=a.result;if(n){var r=n.value;C(r)&&(r=I(r));var o=e(r,n.key,c++);void 0!==o?t(o):n.continue()}else t()},a.onerror=function(){r(a.error)}}catch(e){r(e)}}))})).catch(r)}));return c(r,t),r},getItem:function(e,t){var n=this;e=s(e);var r=new a((function(t,r){n.ready().then((function(){A(n._dbInfo,p,(function(o,i){if(o)return r(o);try{var a=i.objectStore(n._dbInfo.storeName).get(e);a.onsuccess=function(){var e=a.result;void 0===e&&(e=null),C(e)&&(e=I(e)),t(e)},a.onerror=function(){r(a.error)}}catch(e){r(e)}}))})).catch(r)}));return c(r,t),r},setItem:function(e,t,n){var r=this;e=s(e);var o=new a((function(n,o){var i;r.ready().then((function(){return i=r._dbInfo,"[object Blob]"===h.call(t)?m(i.db).then((function(e){return e?t:(n=t,new a((function(e,t){var r=new FileReader;r.onerror=t,r.onloadend=function(t){var r=btoa(t.target.result||"");e({__local_forage_encoded_blob:!0,data:r,type:n.type})},r.readAsBinaryString(n)})));var n})):t})).then((function(t){A(r._dbInfo,y,(function(i,a){if(i)return o(i);try{var c=a.objectStore(r._dbInfo.storeName);null===t&&(t=void 0);var u=c.put(t,e);a.oncomplete=function(){void 0===t&&(t=null),n(t)},a.onabort=a.onerror=function(){var e=u.error?u.error:u.transaction.error;o(e)}}catch(e){o(e)}}))})).catch(o)}));return c(o,n),o},removeItem:function(e,t){var n=this;e=s(e);var r=new a((function(t,r){n.ready().then((function(){A(n._dbInfo,y,(function(o,i){if(o)return r(o);try{var a=i.objectStore(n._dbInfo.storeName).delete(e);i.oncomplete=function(){t()},i.onerror=function(){r(a.error)},i.onabort=function(){var e=a.error?a.error:a.transaction.error;r(e)}}catch(e){r(e)}}))})).catch(r)}));return c(r,t),r},clear:function(e){var t=this,n=new a((function(e,n){t.ready().then((function(){A(t._dbInfo,y,(function(r,o){if(r)return n(r);try{var i=o.objectStore(t._dbInfo.storeName).clear();o.oncomplete=function(){e()},o.onabort=o.onerror=function(){var e=i.error?i.error:i.transaction.error;n(e)}}catch(e){n(e)}}))})).catch(n)}));return c(n,e),n},length:function(e){var t=this,n=new a((function(e,n){t.ready().then((function(){A(t._dbInfo,p,(function(r,o){if(r)return n(r);try{var i=o.objectStore(t._dbInfo.storeName).count();i.onsuccess=function(){e(i.result)},i.onerror=function(){n(i.error)}}catch(e){n(e)}}))})).catch(n)}));return c(n,e),n},key:function(e,t){var n=this,r=new a((function(t,r){e<0?t(null):n.ready().then((function(){A(n._dbInfo,p,(function(o,i){if(o)return r(o);try{var a=i.objectStore(n._dbInfo.storeName),c=!1,u=a.openKeyCursor();u.onsuccess=function(){var n=u.result;n?0===e||c?t(n.key):(c=!0,n.advance(e)):t(null)},u.onerror=function(){r(u.error)}}catch(e){r(e)}}))})).catch(r)}));return c(r,t),r},keys:function(e){var t=this,n=new a((function(e,n){t.ready().then((function(){A(t._dbInfo,p,(function(r,o){if(r)return n(r);try{var i=o.objectStore(t._dbInfo.storeName).openKeyCursor(),a=[];i.onsuccess=function(){var t=i.result;t?(a.push(t.key),t.continue()):e(a)},i.onerror=function(){n(i.error)}}catch(e){n(e)}}))})).catch(n)}));return c(n,e),n},dropInstance:function(e,t){t=f.apply(this,arguments);var n=this.config();(e="function"!=typeof e&&e||{}).name||(e.name=e.name||n.name,e.storeName=e.storeName||n.storeName);var r,i=this;if(e.name){var u=e.name===n.name&&i._dbInfo.db?a.resolve(i._dbInfo.db):S(e).then((function(t){var n=v[e.name],r=n.forages;n.db=t;for(var o=0;o<r.length;o++)r[o]._dbInfo.db=t;return t}));r=e.storeName?u.then((function(t){if(t.objectStoreNames.contains(e.storeName)){var n=t.version+1;b(e);var r=v[e.name],i=r.forages;t.close();for(var c=0;c<i.length;c++){var u=i[c];u._dbInfo.db=null,u._dbInfo.version=n}return new a((function(t,r){var i=o.open(e.name,n);i.onerror=function(e){i.result.close(),r(e)},i.onupgradeneeded=function(){i.result.deleteObjectStore(e.storeName)},i.onsuccess=function(){var e=i.result;e.close(),t(e)}})).then((function(e){r.db=e;for(var t=0;t<i.length;t++){var n=i[t];n._dbInfo.db=e,E(n._dbInfo)}})).catch((function(t){throw(_(e,t)||a.resolve()).catch((function(){})),t}))}})):u.then((function(t){b(e);var n=v[e.name],r=n.forages;t.close();for(var i=0;i<r.length;i++)r[i]._dbInfo.db=null;return new a((function(t,n){var r=o.deleteDatabase(e.name);r.onerror=r.onblocked=function(e){var t=r.result;t&&t.close(),n(e)},r.onsuccess=function(){var e=r.result;e&&e.close(),t(e)}})).then((function(e){n.db=e;for(var t=0;t<r.length;t++)E(r[t]._dbInfo)})).catch((function(t){throw(_(e,t)||a.resolve()).catch((function(){})),t}))}))}else r=a.reject("Invalid arguments");return c(r,t),r}};var j="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",P=/^~~local_forage_type~([^~]+)~/,U="__lfsc__:",k=U.length,x="arbf",L="blob",D="si08",F="ui08",M="uic8",B="si16",$="si32",V="ur16",q="ui32",K="fl32",G="fl64",Y=k+x.length,z=Object.prototype.toString;function W(e){var t,n,r,o,i,a=.75*e.length,c=e.length,u=0;"="===e[e.length-1]&&(a--,"="===e[e.length-2]&&a--);var s=new ArrayBuffer(a),f=new Uint8Array(s);for(t=0;t<c;t+=4)n=j.indexOf(e[t]),r=j.indexOf(e[t+1]),o=j.indexOf(e[t+2]),i=j.indexOf(e[t+3]),f[u++]=n<<2|r>>4,f[u++]=(15&r)<<4|o>>2,f[u++]=(3&o)<<6|63&i;return s}function H(e){var t,n=new Uint8Array(e),r="";for(t=0;t<n.length;t+=3)r+=j[n[t]>>2],r+=j[(3&n[t])<<4|n[t+1]>>4],r+=j[(15&n[t+1])<<2|n[t+2]>>6],r+=j[63&n[t+2]];return n.length%3==2?r=r.substring(0,r.length-1)+"=":n.length%3==1&&(r=r.substring(0,r.length-2)+"=="),r}var Q={serialize:function(e,t){var n="";if(e&&(n=z.call(e)),e&&("[object ArrayBuffer]"===n||e.buffer&&"[object ArrayBuffer]"===z.call(e.buffer))){var r,o=U;e instanceof ArrayBuffer?(r=e,o+=x):(r=e.buffer,"[object Int8Array]"===n?o+=D:"[object Uint8Array]"===n?o+=F:"[object Uint8ClampedArray]"===n?o+=M:"[object Int16Array]"===n?o+=B:"[object Uint16Array]"===n?o+=V:"[object Int32Array]"===n?o+=$:"[object Uint32Array]"===n?o+=q:"[object Float32Array]"===n?o+=K:"[object Float64Array]"===n?o+=G:t(new Error("Failed to get type for BinaryArray"))),t(o+H(r))}else if("[object Blob]"===n){var i=new FileReader;i.onload=function(){var n="~~local_forage_type~"+e.type+"~"+H(this.result);t("__lfsc__:blob"+n)},i.readAsArrayBuffer(e)}else try{t(JSON.stringify(e))}catch(n){console.error("Couldn't convert value into a JSON string: ",e),t(null,n)}},deserialize:function(e){if(e.substring(0,k)!==U)return JSON.parse(e);var t,n=e.substring(Y),r=e.substring(k,Y);if(r===L&&P.test(n)){var o=n.match(P);t=o[1],n=n.substring(o[0].length)}var a=W(n);switch(r){case x:return a;case L:return i([a],{type:t});case D:return new Int8Array(a);case F:return new Uint8Array(a);case M:return new Uint8ClampedArray(a);case B:return new Int16Array(a);case V:return new Uint16Array(a);case $:return new Int32Array(a);case q:return new Uint32Array(a);case K:return new Float32Array(a);case G:return new Float64Array(a);default:throw new Error("Unkown type: "+r)}},stringToBuffer:W,bufferToString:H};function J(e,t,n,r){e.executeSql("CREATE TABLE IF NOT EXISTS "+t.storeName+" (id INTEGER PRIMARY KEY, key unique, value)",[],n,r)}function X(e,t,n,r,o,i){e.executeSql(n,r,o,(function(e,a){a.code===a.SYNTAX_ERR?e.executeSql("SELECT name FROM sqlite_master WHERE type='table' AND name = ?",[t.storeName],(function(e,c){c.rows.length?i(e,a):J(e,t,(function(){e.executeSql(n,r,o,i)}),i)}),i):i(e,a)}),i)}function Z(e,t,n,r){var o=this;e=s(e);var i=new a((function(i,a){o.ready().then((function(){void 0===t&&(t=null);var c=t,u=o._dbInfo;u.serializer.serialize(t,(function(t,s){s?a(s):u.db.transaction((function(n){X(n,u,"INSERT OR REPLACE INTO "+u.storeName+" (key, value) VALUES (?, ?)",[e,t],(function(){i(c)}),(function(e,t){a(t)}))}),(function(t){if(t.code===t.QUOTA_ERR){if(r>0)return void i(Z.apply(o,[e,c,n,r-1]));a(t)}}))}))})).catch(a)}));return c(i,n),i}function ee(e){return new a((function(t,n){e.transaction((function(r){r.executeSql("SELECT name FROM sqlite_master WHERE type='table' AND name <> '__WebKitDatabaseInfoTable__'",[],(function(n,r){for(var o=[],i=0;i<r.rows.length;i++)o.push(r.rows.item(i).name);t({db:e,storeNames:o})}),(function(e,t){n(t)}))}),(function(e){n(e)}))}))}var te={_driver:"webSQLStorage",_initStorage:function(e){var t=this,n={db:null};if(e)for(var r in e)n[r]="string"!=typeof e[r]?e[r].toString():e[r];var o=new a((function(e,r){try{n.db=openDatabase(n.name,String(n.version),n.description,n.size)}catch(e){return r(e)}n.db.transaction((function(o){J(o,n,(function(){t._dbInfo=n,e()}),(function(e,t){r(t)}))}),r)}));return n.serializer=Q,o},_support:"function"==typeof openDatabase,iterate:function(e,t){var n=this,r=new a((function(t,r){n.ready().then((function(){var o=n._dbInfo;o.db.transaction((function(n){X(n,o,"SELECT * FROM "+o.storeName,[],(function(n,r){for(var i=r.rows,a=i.length,c=0;c<a;c++){var u=i.item(c),s=u.value;if(s&&(s=o.serializer.deserialize(s)),void 0!==(s=e(s,u.key,c+1)))return void t(s)}t()}),(function(e,t){r(t)}))}))})).catch(r)}));return c(r,t),r},getItem:function(e,t){var n=this;e=s(e);var r=new a((function(t,r){n.ready().then((function(){var o=n._dbInfo;o.db.transaction((function(n){X(n,o,"SELECT * FROM "+o.storeName+" WHERE key = ? LIMIT 1",[e],(function(e,n){var r=n.rows.length?n.rows.item(0).value:null;r&&(r=o.serializer.deserialize(r)),t(r)}),(function(e,t){r(t)}))}))})).catch(r)}));return c(r,t),r},setItem:function(e,t,n){return Z.apply(this,[e,t,n,1])},removeItem:function(e,t){var n=this;e=s(e);var r=new a((function(t,r){n.ready().then((function(){var o=n._dbInfo;o.db.transaction((function(n){X(n,o,"DELETE FROM "+o.storeName+" WHERE key = ?",[e],(function(){t()}),(function(e,t){r(t)}))}))})).catch(r)}));return c(r,t),r},clear:function(e){var t=this,n=new a((function(e,n){t.ready().then((function(){var r=t._dbInfo;r.db.transaction((function(t){X(t,r,"DELETE FROM "+r.storeName,[],(function(){e()}),(function(e,t){n(t)}))}))})).catch(n)}));return c(n,e),n},length:function(e){var t=this,n=new a((function(e,n){t.ready().then((function(){var r=t._dbInfo;r.db.transaction((function(t){X(t,r,"SELECT COUNT(key) as c FROM "+r.storeName,[],(function(t,n){var r=n.rows.item(0).c;e(r)}),(function(e,t){n(t)}))}))})).catch(n)}));return c(n,e),n},key:function(e,t){var n=this,r=new a((function(t,r){n.ready().then((function(){var o=n._dbInfo;o.db.transaction((function(n){X(n,o,"SELECT key FROM "+o.storeName+" WHERE id = ? LIMIT 1",[e+1],(function(e,n){var r=n.rows.length?n.rows.item(0).key:null;t(r)}),(function(e,t){r(t)}))}))})).catch(r)}));return c(r,t),r},keys:function(e){var t=this,n=new a((function(e,n){t.ready().then((function(){var r=t._dbInfo;r.db.transaction((function(t){X(t,r,"SELECT key FROM "+r.storeName,[],(function(t,n){for(var r=[],o=0;o<n.rows.length;o++)r.push(n.rows.item(o).key);e(r)}),(function(e,t){n(t)}))}))})).catch(n)}));return c(n,e),n},dropInstance:function(e,t){t=f.apply(this,arguments);var n=this.config();(e="function"!=typeof e&&e||{}).name||(e.name=e.name||n.name,e.storeName=e.storeName||n.storeName);var r,o=this;return c(r=e.name?new a((function(t){var r;r=e.name===n.name?o._dbInfo.db:openDatabase(e.name,"","",0),e.storeName?t({db:r,storeNames:[e.storeName]}):t(ee(r))})).then((function(e){return new a((function(t,n){e.db.transaction((function(r){function o(e){return new a((function(t,n){r.executeSql("DROP TABLE IF EXISTS "+e,[],(function(){t()}),(function(e,t){n(t)}))}))}for(var i=[],c=0,u=e.storeNames.length;c<u;c++)i.push(o(e.storeNames[c]));a.all(i).then((function(){t()})).catch((function(e){n(e)}))}),(function(e){n(e)}))}))})):a.reject("Invalid arguments"),t),r}};function ne(e,t){var n=e.name+"/";return e.storeName!==t.storeName&&(n+=e.storeName+"/"),n}function re(){return!function(){var e="_localforage_support_test";try{return localStorage.setItem(e,!0),localStorage.removeItem(e),!1}catch(e){return!0}}()||localStorage.length>0}var oe={_driver:"localStorageWrapper",_initStorage:function(e){var t={};if(e)for(var n in e)t[n]=e[n];return t.keyPrefix=ne(e,this._defaultConfig),re()?(this._dbInfo=t,t.serializer=Q,a.resolve()):a.reject()},_support:function(){try{return"undefined"!=typeof localStorage&&"setItem"in localStorage&&!!localStorage.setItem}catch(e){return!1}}(),iterate:function(e,t){var n=this,r=n.ready().then((function(){for(var t=n._dbInfo,r=t.keyPrefix,o=r.length,i=localStorage.length,a=1,c=0;c<i;c++){var u=localStorage.key(c);if(0===u.indexOf(r)){var s=localStorage.getItem(u);if(s&&(s=t.serializer.deserialize(s)),void 0!==(s=e(s,u.substring(o),a++)))return s}}}));return c(r,t),r},getItem:function(e,t){var n=this;e=s(e);var r=n.ready().then((function(){var t=n._dbInfo,r=localStorage.getItem(t.keyPrefix+e);return r&&(r=t.serializer.deserialize(r)),r}));return c(r,t),r},setItem:function(e,t,n){var r=this;e=s(e);var o=r.ready().then((function(){void 0===t&&(t=null);var n=t;return new a((function(o,i){var a=r._dbInfo;a.serializer.serialize(t,(function(t,r){if(r)i(r);else try{localStorage.setItem(a.keyPrefix+e,t),o(n)}catch(e){"QuotaExceededError"!==e.name&&"NS_ERROR_DOM_QUOTA_REACHED"!==e.name||i(e),i(e)}}))}))}));return c(o,n),o},removeItem:function(e,t){var n=this;e=s(e);var r=n.ready().then((function(){var t=n._dbInfo;localStorage.removeItem(t.keyPrefix+e)}));return c(r,t),r},clear:function(e){var t=this,n=t.ready().then((function(){for(var e=t._dbInfo.keyPrefix,n=localStorage.length-1;n>=0;n--){var r=localStorage.key(n);0===r.indexOf(e)&&localStorage.removeItem(r)}}));return c(n,e),n},length:function(e){var t=this.keys().then((function(e){return e.length}));return c(t,e),t},key:function(e,t){var n=this,r=n.ready().then((function(){var t,r=n._dbInfo;try{t=localStorage.key(e)}catch(e){t=null}return t&&(t=t.substring(r.keyPrefix.length)),t}));return c(r,t),r},keys:function(e){var t=this,n=t.ready().then((function(){for(var e=t._dbInfo,n=localStorage.length,r=[],o=0;o<n;o++){var i=localStorage.key(o);0===i.indexOf(e.keyPrefix)&&r.push(i.substring(e.keyPrefix.length))}return r}));return c(n,e),n},dropInstance:function(e,t){if(t=f.apply(this,arguments),!(e="function"!=typeof e&&e||{}).name){var n=this.config();e.name=e.name||n.name,e.storeName=e.storeName||n.storeName}var r,o=this;return c(r=e.name?new a((function(t){e.storeName?t(ne(e,o._defaultConfig)):t(e.name+"/")})).then((function(e){for(var t=localStorage.length-1;t>=0;t--){var n=localStorage.key(t);0===n.indexOf(e)&&localStorage.removeItem(n)}})):a.reject("Invalid arguments"),t),r}},ie=function(e,t){for(var n=e.length,r=0;r<n;){if((o=e[r])===(i=t)||"number"==typeof o&&"number"==typeof i&&isNaN(o)&&isNaN(i))return!0;r++}var o,i;return!1},ae=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)},ce={},ue={},se={INDEXEDDB:N,WEBSQL:te,LOCALSTORAGE:oe},fe=[se.INDEXEDDB._driver,se.WEBSQL._driver,se.LOCALSTORAGE._driver],le=["dropInstance"],de=["clear","getItem","iterate","key","keys","length","removeItem","setItem"].concat(le),ve={description:"",driver:fe.slice(),name:"localforage",size:4980736,storeName:"keyvaluepairs",version:1};function he(e,t){e[t]=function(){var n=arguments;return e.ready().then((function(){return e[t].apply(e,n)}))}}function pe(){for(var e=1;e<arguments.length;e++){var t=arguments[e];if(t)for(var n in t)t.hasOwnProperty(n)&&(ae(t[n])?arguments[0][n]=t[n].slice():arguments[0][n]=t[n])}return arguments[0]}var ye=new(function(){function e(t){for(var n in function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),se)if(se.hasOwnProperty(n)){var r=se[n],o=r._driver;this[n]=o,ce[o]||this.defineDriver(r)}this._defaultConfig=pe({},ve),this._config=pe({},this._defaultConfig,t),this._driverSet=null,this._initDriver=null,this._ready=!1,this._dbInfo=null,this._wrapLibraryMethodsWithReady(),this.setDriver(this._config.driver).catch((function(){}))}return e.prototype.config=function(e){if("object"===(void 0===e?"undefined":r(e))){if(this._ready)return new Error("Can't call config() after localforage has been used.");for(var t in e){if("storeName"===t&&(e[t]=e[t].replace(/\W/g,"_")),"version"===t&&"number"!=typeof e[t])return new Error("Database version must be a number.");this._config[t]=e[t]}return!("driver"in e)||!e.driver||this.setDriver(this._config.driver)}return"string"==typeof e?this._config[e]:this._config},e.prototype.defineDriver=function(e,t,n){var r=new a((function(t,n){try{var r=e._driver,o=new Error("Custom driver not compliant; see https://mozilla.github.io/localForage/#definedriver");if(!e._driver)return void n(o);for(var i=de.concat("_initStorage"),u=0,s=i.length;u<s;u++){var f=i[u];if((!ie(le,f)||e[f])&&"function"!=typeof e[f])return void n(o)}!function(){for(var t=function(e){return function(){var t=new Error("Method "+e+" is not implemented by the current driver"),n=a.reject(t);return c(n,arguments[arguments.length-1]),n}},n=0,r=le.length;n<r;n++){var o=le[n];e[o]||(e[o]=t(o))}}();var l=function(n){ce[r]&&console.info("Redefining LocalForage driver: "+r),ce[r]=e,ue[r]=n,t()};"_support"in e?e._support&&"function"==typeof e._support?e._support().then(l,n):l(!!e._support):l(!0)}catch(e){n(e)}}));return u(r,t,n),r},e.prototype.driver=function(){return this._driver||null},e.prototype.getDriver=function(e,t,n){var r=ce[e]?a.resolve(ce[e]):a.reject(new Error("Driver not found."));return u(r,t,n),r},e.prototype.getSerializer=function(e){var t=a.resolve(Q);return u(t,e),t},e.prototype.ready=function(e){var t=this,n=t._driverSet.then((function(){return null===t._ready&&(t._ready=t._initDriver()),t._ready}));return u(n,e,e),n},e.prototype.setDriver=function(e,t,n){var r=this;ae(e)||(e=[e]);var o=this._getSupportedDrivers(e);function i(){r._config.driver=r.driver()}function c(e){return r._extend(e),i(),r._ready=r._initStorage(r._config),r._ready}var s=null!==this._driverSet?this._driverSet.catch((function(){return a.resolve()})):a.resolve();return this._driverSet=s.then((function(){var e=o[0];return r._dbInfo=null,r._ready=null,r.getDriver(e).then((function(e){r._driver=e._driver,i(),r._wrapLibraryMethodsWithReady(),r._initDriver=function(e){return function(){var t=0;return function n(){for(;t<e.length;){var o=e[t];return t++,r._dbInfo=null,r._ready=null,r.getDriver(o).then(c).catch(n)}i();var u=new Error("No available storage method found.");return r._driverSet=a.reject(u),r._driverSet}()}}(o)}))})).catch((function(){i();var e=new Error("No available storage method found.");return r._driverSet=a.reject(e),r._driverSet})),u(this._driverSet,t,n),this._driverSet},e.prototype.supports=function(e){return!!ue[e]},e.prototype._extend=function(e){pe(this,e)},e.prototype._getSupportedDrivers=function(e){for(var t=[],n=0,r=e.length;n<r;n++){var o=e[n];this.supports(o)&&t.push(o)}return t},e.prototype._wrapLibraryMethodsWithReady=function(){for(var e=0,t=de.length;e<t;e++)he(this,de[e])},e.prototype.createInstance=function(t){return new e(t)},e}());t.exports=ye},{3:3}]},{},[4])(4)},896:function(e,t,n){var r=this&&this.__read||function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a},o=this&&this.__spreadArray||function(e,t){for(var n=0,r=t.length,o=e.length;n<r;n++,o++)e[o]=t[n];return e};Object.defineProperty(t,"__esModule",{value:!0}),t.AsyncContract=void 0;var i=n(174),a=n(589);t.AsyncContract=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=e.length-1,c=e.slice(0,n),u=e[n];return{enforce:function(e){return function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];if(t.length<c.length){var s="Expected "+c.length+" arguments but only received "+t.length,f=a.FAILURE.ARGUMENT_INCORRECT(s);throw new i.ValidationError(f)}for(var l=0;l<c.length;l++)c[l].check(t[l]);var d=e.apply(void 0,o([],r(t)));if(!(d instanceof Promise))throw s="Expected function to return a promise, but instead got "+d,f=a.FAILURE.RETURN_INCORRECT(s),new i.ValidationError(f);return d.then(u.check)}}}}},308:function(e,t,n){var r=this&&this.__read||function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a},o=this&&this.__spreadArray||function(e,t){for(var n=0,r=t.length,o=e.length;n<r;n++,o++)e[o]=t[n];return e};Object.defineProperty(t,"__esModule",{value:!0}),t.Contract=void 0;var i=n(174),a=n(589);t.Contract=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=e.length-1,c=e.slice(0,n),u=e[n];return{enforce:function(e){return function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];if(t.length<c.length){var s="Expected "+c.length+" arguments but only received "+t.length,f=a.FAILURE.ARGUMENT_INCORRECT(s);throw new i.ValidationError(f)}for(var l=0;l<c.length;l++)c[l].check(t[l]);return u.check(e.apply(void 0,o([],r(t))))}}}}},965:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.checked=t.check=void 0;var r=n(174),o=n(589),i=new WeakMap;function a(e,t,n){var r=i.get(e),o=r&&r.get(t);if(o)return o;for(var a=[],c=0;c<n;c++)a.push(c);return a}t.check=function(e,t,n){var r=i.get(e)||new Map;i.set(e,r);var o=r.get(t)||[];r.set(t,o),o.push(n)},t.checked=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];if(0===e.length)throw new Error("No runtype provided to `@checked`. Please remove the decorator.");return function(t,n,i){var c=i.value,u=(t.name||t.constructor.name+".prototype")+("string"==typeof n?'["'+n+'"]':"["+String(n)+"]"),s=a(t,n,e.length);if(s.length!==e.length)throw new Error("Number of `@checked` runtypes and @check parameters not matched.");if(s.length>c.length)throw new Error("Number of `@checked` runtypes exceeds actual parameter length.");i.value=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return e.forEach((function(e,n){var i=s[n],a=e.validate(t[i]);if(!a.success){var c=u+", argument #"+i+": "+a.message,f=o.FAILURE.ARGUMENT_INCORRECT(c);throw new r.ValidationError(f)}})),c.apply(this,t)}}}},174:function(e,t){var n,r=this&&this.__extends||(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)});Object.defineProperty(t,"__esModule",{value:!0}),t.ValidationError=void 0;var o=function(e){function t(n){var r=e.call(this,n.message)||this;return r.name="ValidationError",r.code=n.code,void 0!==n.details&&(r.details=n.details),Object.setPrototypeOf(r,t.prototype),r}return r(t,e),t}(Error);t.ValidationError=o},61:function(e,t,n){var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),o=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||r(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),t.InstanceOf=t.Null=t.Undefined=t.Literal=void 0,o(n(350),t),o(n(205),t),o(n(308),t),o(n(896),t),o(n(339),t),o(n(174),t),o(n(615),t),o(n(551),t),o(n(362),t);var i=n(620);Object.defineProperty(t,"Literal",{enumerable:!0,get:function(){return i.Literal}}),Object.defineProperty(t,"Undefined",{enumerable:!0,get:function(){return i.Undefined}}),Object.defineProperty(t,"Null",{enumerable:!0,get:function(){return i.Null}}),o(n(643),t),o(n(422),t),o(n(172),t),o(n(856),t),o(n(59),t),o(n(669),t),o(n(941),t),o(n(489),t),o(n(745),t),o(n(219),t),o(n(617),t),o(n(979),t),o(n(548),t);var a=n(937);Object.defineProperty(t,"InstanceOf",{enumerable:!0,get:function(){return a.InstanceOf}}),o(n(813),t),o(n(277),t),o(n(550),t),o(n(965),t)},339:function(e,t){var n=this&&this.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")},r=this&&this.__read||function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a};Object.defineProperty(t,"__esModule",{value:!0}),t.match=void 0,t.match=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return function(t){var o,i;try{for(var a=n(e),c=a.next();!c.done;c=a.next()){var u=r(c.value,2),s=u[0],f=u[1];if(s.guard(t))return f(t)}}catch(e){o={error:e}}finally{try{c&&!c.done&&(i=a.return)&&i.call(a)}finally{if(o)throw o.error}}throw new Error("No alternatives were matched")}}},350:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0})},205:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Failcode=void 0,t.Failcode={TYPE_INCORRECT:"TYPE_INCORRECT",VALUE_INCORRECT:"VALUE_INCORRECT",KEY_INCORRECT:"KEY_INCORRECT",CONTENT_INCORRECT:"CONTENT_INCORRECT",ARGUMENT_INCORRECT:"ARGUMENT_INCORRECT",RETURN_INCORRECT:"RETURN_INCORRECT",CONSTRAINT_FAILED:"CONSTRAINT_FAILED",PROPERTY_MISSING:"PROPERTY_MISSING",PROPERTY_PRESENT:"PROPERTY_PRESENT",NOTHING_EXPECTED:"NOTHING_EXPECTED"}},705:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.innerValidate=t.create=void 0;var r=n(61),o=n(268),i=n(174),a=n(589);t.create=function(e,t){return t.check=n,t.assert=n,t._innerValidate=function(n,r){return r.has(n,t)?a.SUCCESS(n):e(n,r)},t.validate=function(e){return t._innerValidate(e,(n=new WeakMap,r=function(e,t){if(null!==e&&"object"==typeof e){var r=n.get(e);n.set(e,r?r.set(t,!0):(new WeakMap).set(t,!0))}},{has:function(e,t){var o=n.get(e),i=o&&o.get(t)||!1;return r(e,t),i}}));var n,r},t.guard=function(e){return t.validate(e).success},t.Or=function(e){return r.Union(t,e)},t.And=function(e){return r.Intersect(t,e)},t.optional=function(){return r.Optional(t)},t.nullable=function(){return r.Union(t,r.Null)},t.withConstraint=function(e,n){return r.Constraint(t,e,n)},t.withGuard=function(e,n){return r.Constraint(t,e,n)},t.withBrand=function(e){return r.Brand(e,t)},t.reflect=t,t.toString=function(){return"Runtype<"+o.default(t)+">"},t;function n(e){var n=t.validate(e);if(n.success)return n.value;throw new i.ValidationError(n)}},t.innerValidate=function(e,t,n){return e._innerValidate(t,n)}},268:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});var n=function(e,t){return function(o){var i=function(t){return e?"("+t+")":t};if(t.has(o))return i("CIRCULAR "+o.tag);t.add(o);try{switch(o.tag){case"unknown":case"never":case"void":case"boolean":case"number":case"bigint":case"string":case"symbol":case"function":return o.tag;case"literal":var a=o.value;return"string"==typeof a?'"'+a+'"':String(a);case"array":return""+r(o)+n(!0,t)(o.element)+"[]";case"dictionary":return"{ [_: "+o.key+"]: "+n(!1,t)(o.value)+" }";case"record":var c=Object.keys(o.fields);return c.length?"{ "+c.map((function(e){return""+r(o)+e+(a=e,c=(i=o).isPartial,u=i.fields,(c||void 0!==a&&"optional"===u[a].tag?"?":"")+": ")+("optional"===o.fields[e].tag?n(!1,t)(o.fields[e].underlying):n(!1,t)(o.fields[e]))+";";var i,a,c,u})).join(" ")+" }":"{}";case"tuple":return"["+o.components.map(n(!1,t)).join(", ")+"]";case"union":return i(""+o.alternatives.map(n(!0,t)).join(" | "));case"intersect":return i(""+o.intersectees.map(n(!0,t)).join(" & "));case"optional":return n(e,t)(o.underlying)+" | undefined";case"constraint":return o.name||n(e,t)(o.underlying);case"instanceof":return o.ctor.name;case"brand":return n(e,t)(o.entity)}}finally{t.delete(o)}throw Error("impossible")}};function r(e){return e.isReadonly?"readonly ":""}t.default=n(!1,new Set)},669:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Array=void 0;var r=n(705),o=n(589);function i(e,t){var n,a={tag:"array",isReadonly:t,element:e};return(n=r.create((function(t,n){if(!Array.isArray(t))return o.FAILURE.TYPE_INCORRECT(a,t);var i=o.enumerableKeysOf(t),c=i.map((function(o){return r.innerValidate(e,t[o],n)})),u=i.reduce((function(e,t){var n=c[t];return n.success||(e[t]=n.details||n.message),e}),[]);return 0!==o.enumerableKeysOf(u).length?o.FAILURE.CONTENT_INCORRECT(a,u):o.SUCCESS(t)}),a)).asReadonly=function(){return i(n.element,!0)},n}t.Array=function(e){return i(e,!1)}},172:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BigInt=void 0;var r=n(705),o=n(589),i={tag:"bigint"};t.BigInt=r.create((function(e){return"bigint"==typeof e?o.SUCCESS(e):o.FAILURE.TYPE_INCORRECT(i,e)}),i)},643:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Boolean=void 0;var r=n(705),o=n(589),i={tag:"boolean"};t.Boolean=r.create((function(e){return"boolean"==typeof e?o.SUCCESS(e):o.FAILURE.TYPE_INCORRECT(i,e)}),i)},550:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Brand=void 0;var r=n(705);t.Brand=function(e,t){var n={tag:"brand",brand:e,entity:t};return r.create((function(e){return t.validate(e)}),n)}},277:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Guard=t.Constraint=void 0;var r=n(705),o=n(589),i=n(615);t.Constraint=function(e,t,n){var i=n&&n.name,a=n&&n.args,c={tag:"constraint",underlying:e,constraint:t,name:i,args:a};return r.create((function(n){var r=e.validate(n);if(!r.success)return r;var i=t(r.value);return"string"==typeof i?o.FAILURE.CONSTRAINT_FAILED(c,i):i?o.SUCCESS(r.value):o.FAILURE.CONSTRAINT_FAILED(c)}),c)},t.Guard=function(e,t){return i.Unknown.withGuard(e,t)}},745:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Dictionary=void 0;var r=n(705),o=n(856),i=n(277),a=n(268),c=n(589),u=i.Constraint(o.String,(function(e){return!isNaN(+e)}),{name:"number"});t.Dictionary=function(e,t){var i=void 0===t||"string"===t?o.String:"number"===t?u:t,s=a.default(i),f={tag:"dictionary",key:s,value:e};return r.create((function(t,o){if(null==t||"object"!=typeof t)return c.FAILURE.TYPE_INCORRECT(f,t);if(Object.getPrototypeOf(t)!==Object.prototype&&(!Array.isArray(t)||"string"===s))return c.FAILURE.TYPE_INCORRECT(f,t);var a=/^(?:NaN|-?\d+(?:\.\d+)?)$/u,u=c.enumerableKeysOf(t),l=u.reduce((function(u,s){var l="string"==typeof s&&a.test(s),d=l?n.g.Number(s):s;return(l?i.guard(d)||i.guard(s):i.guard(d))?u[s]=r.innerValidate(e,t[s],o):u[s]=c.FAILURE.KEY_INCORRECT(f,i.reflect,d),u}),{}),d=u.reduce((function(e,t){var n=l[t];return n.success||(e[t]=n.details||n.message),e}),{});return 0!==c.enumerableKeysOf(d).length?c.FAILURE.CONTENT_INCORRECT(f,d):c.SUCCESS(t)}),f)}},548:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Function=void 0;var r=n(705),o=n(589),i={tag:"function"};t.Function=r.create((function(e){return"function"==typeof e?o.SUCCESS(e):o.FAILURE.TYPE_INCORRECT(i,e)}),i)},937:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.InstanceOf=void 0;var r=n(705),o=n(589);t.InstanceOf=function(e){var t={tag:"instanceof",ctor:e};return r.create((function(n){return n instanceof e?o.SUCCESS(n):o.FAILURE.TYPE_INCORRECT(t,n)}),t)}},617:function(e,t,n){var r=this&&this.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(t,"__esModule",{value:!0}),t.Intersect=void 0;var o=n(705),i=n(589);t.Intersect=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n={tag:"intersect",intersectees:e};return o.create((function(t,n){var a,c;try{for(var u=r(e),s=u.next();!s.done;s=u.next()){var f=s.value,l=o.innerValidate(f,t,n);if(!l.success)return l}}catch(e){a={error:e}}finally{try{s&&!s.done&&(c=u.return)&&c.call(u)}finally{if(a)throw a.error}}return i.SUCCESS(t)}),n)}},813:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Lazy=void 0;var r=n(705);t.Lazy=function(e){var t,n={get tag(){return o().tag}};function o(){if(!t)for(var r in t=e())"tag"!==r&&(n[r]=t[r]);return t}return r.create((function(e){return o().validate(e)}),n)}},620:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Null=t.Undefined=t.Literal=void 0;var r=n(705),o=n(589);function i(e){return Array.isArray(e)?String(e.map(String)):"bigint"==typeof e?String(e)+"n":String(e)}function a(e){var t={tag:"literal",value:e};return r.create((function(t){return t===e?o.SUCCESS(t):o.FAILURE.VALUE_INCORRECT("literal","`"+i(e)+"`","`"+i(t)+"`")}),t)}t.Literal=a,t.Undefined=a(void 0),t.Null=a(null)},551:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Never=void 0;var r=n(705),o=n(589);t.Never=r.create(o.FAILURE.NOTHING_EXPECTED,{tag:"never"})},422:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Number=void 0;var r=n(705),o=n(589),i={tag:"number"};t.Number=r.create((function(e){return"number"==typeof e?o.SUCCESS(e):o.FAILURE.TYPE_INCORRECT(i,e)}),i)},979:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Optional=void 0;var r=n(705),o=n(589);t.Optional=function(e){var t={tag:"optional",underlying:e};return r.create((function(t){return void 0===t?o.SUCCESS(t):e.validate(t)}),t)}},489:function(e,t,n){var r=this&&this.__read||function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a},o=this&&this.__spreadArray||function(e,t){for(var n=0,r=t.length,o=e.length;n<r;n++,o++)e[o]=t[n];return e};Object.defineProperty(t,"__esModule",{value:!0}),t.Partial=t.Record=t.InternalRecord=void 0;var i=n(705),a=n(589);function c(e,t,n){var u,s={tag:"record",isPartial:t,isReadonly:n,fields:e};return(u=i.create((function(n,c){if(null==n)return a.FAILURE.TYPE_INCORRECT(s,n);var u=a.enumerableKeysOf(e);if(0!==u.length&&"object"!=typeof n)return a.FAILURE.TYPE_INCORRECT(s,n);var f=o([],r(new Set(o(o([],r(u)),r(a.enumerableKeysOf(n)))))),l=f.reduce((function(r,o){var u=a.hasKey(o,e),s=a.hasKey(o,n);if(u){var f=e[o],l=t||"optional"===f.reflect.tag;if(s){var d=n[o];r[o]=l&&void 0===d?a.SUCCESS(d):i.innerValidate(f,d,c)}else r[o]=l?a.SUCCESS(void 0):a.FAILURE.PROPERTY_MISSING(f.reflect)}else{if(!s)throw new Error("impossible");d=n[o],r[o]=a.SUCCESS(d)}return r}),{}),d=f.reduce((function(e,t){var n=l[t];return n.success||(e[t]=n.details||n.message),e}),{});return 0!==a.enumerableKeysOf(d).length?a.FAILURE.CONTENT_INCORRECT(s,d):a.SUCCESS(n)}),s)).asPartial=function(){return c(u.fields,!0,u.isReadonly)},u.asReadonly=function(){return c(u.fields,u.isPartial,!0)},u.pick=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n={};return e.forEach((function(e){n[e]=u.fields[e]})),c(n,u.isPartial,u.isReadonly)},u.omit=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n={};return a.enumerableKeysOf(u.fields).forEach((function(t){e.includes(t)||(n[t]=u.fields[t])})),c(n,u.isPartial,u.isReadonly)},u}t.InternalRecord=c,t.Record=function(e){return c(e,!1,!1)},t.Partial=function(e){return c(e,!0,!1)}},856:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.String=void 0;var r=n(705),o=n(589),i={tag:"string"};t.String=r.create((function(e){return"string"==typeof e?o.SUCCESS(e):o.FAILURE.TYPE_INCORRECT(i,e)}),i)},59:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Symbol=void 0;var r=n(705),o=n(589),i={tag:"symbol"};t.Symbol=r.create((function(e){return"symbol"==typeof e?o.SUCCESS(e):o.FAILURE.TYPE_INCORRECT(i,e)}),Object.assign((function(e){var t={tag:"symbol",key:e};return r.create((function(r){if("symbol"!=typeof r)return o.FAILURE.TYPE_INCORRECT(t,r);var i=n.g.Symbol.keyFor(r);return i!==e?o.FAILURE.VALUE_INCORRECT("symbol key",a(e),a(i)):o.SUCCESS(r)}),t)}),i));var a=function(e){return void 0===e?"undefined":'"'+e+'"'}},941:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Tuple=void 0;var r=n(705),o=n(589);t.Tuple=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n={tag:"tuple",components:e};return r.create((function(t,i){if(!Array.isArray(t))return o.FAILURE.TYPE_INCORRECT(n,t);if(t.length!==e.length)return o.FAILURE.CONSTRAINT_FAILED(n,"Expected length "+e.length+", but was "+t.length);var a=o.enumerableKeysOf(t),c=a.map((function(n){return r.innerValidate(e[n],t[n],i)})),u=a.reduce((function(e,t){var n=c[t];return n.success||(e[t]=n.details||n.message),e}),[]);return 0!==o.enumerableKeysOf(u).length?o.FAILURE.CONTENT_INCORRECT(n,u):o.SUCCESS(t)}),n)}},219:function(e,t,n){var r=this&&this.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(t,"__esModule",{value:!0}),t.Union=void 0;var o=n(705),i=n(589);t.Union=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return function(n){for(var r=0;r<e.length;r++)if(e[r].guard(n))return t[r](n)}},a={tag:"union",alternatives:e,match:n};return o.create((function(t,n){var c,u,s,f,l,d,v,h;if("object"!=typeof t||null===t){try{for(var p=r(e),y=p.next();!y.done;y=p.next()){var g=y.value;if(o.innerValidate(g,t,n).success)return i.SUCCESS(t)}}catch(e){c={error:e}}finally{try{y&&!y.done&&(u=p.return)&&u.call(p)}finally{if(c)throw c.error}}return i.FAILURE.TYPE_INCORRECT(a,t)}var m={};try{for(var b=r(e),E=b.next();!E.done;E=b.next())if("record"===(g=E.value).reflect.tag){var _=function(e){var t=g.reflect.fields[e];"literal"===t.tag&&(m[e]?m[e].every((function(e){return e!==t.value}))&&m[e].push(t.value):m[e]=[t.value])};for(var w in g.reflect.fields)_(w)}}catch(e){s={error:e}}finally{try{E&&!E.done&&(f=b.return)&&f.call(b)}finally{if(s)throw s.error}}for(var w in m)if(m[w].length===e.length)try{for(var S=(l=void 0,r(e)),R=S.next();!R.done;R=S.next())if("record"===(g=R.value).reflect.tag){var O=g.reflect.fields[w];if("literal"===O.tag&&i.hasKey(w,t)&&t[w]===O.value)return o.innerValidate(g,t,n)}}catch(e){l={error:e}}finally{try{R&&!R.done&&(d=S.return)&&d.call(S)}finally{if(l)throw l.error}}try{for(var I=r(e),C=I.next();!C.done;C=I.next()){var T=C.value;if(o.innerValidate(T,t,n).success)return i.SUCCESS(t)}}catch(e){v={error:e}}finally{try{C&&!C.done&&(h=I.return)&&h.call(I)}finally{if(v)throw v.error}}return i.FAILURE.TYPE_INCORRECT(a,t)}),a)}},615:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Unknown=void 0;var r=n(705),o=n(589);t.Unknown=r.create((function(e){return o.SUCCESS(e)}),{tag:"unknown"})},362:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Void=void 0;var r=n(615);t.Void=r.Unknown},589:function(e,t,n){var r=this&&this.__assign||function(){return(r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};Object.defineProperty(t,"__esModule",{value:!0}),t.FAILURE=t.SUCCESS=t.enumerableKeysOf=t.typeOf=t.hasKey=void 0;var o=n(205),i=n(268);t.hasKey=function(e,t){return"object"==typeof t&&null!==t&&e in t},t.typeOf=function(e){return"object"==typeof e?null===e?"null":Array.isArray(e)?"array":"Object"===e.constructor.name?"object":e.constructor.name:typeof e},t.enumerableKeysOf=function(e){return"object"==typeof e&&null!==e?Reflect.ownKeys(e).filter((function(t){var n,r;return null===(r=null===(n=e.propertyIsEnumerable)||void 0===n?void 0:n.call(e,t))||void 0===r||r})):[]},t.SUCCESS=function(e){return{success:!0,value:e}},t.FAILURE=Object.assign((function(e,t,n){return r({success:!1,code:e,message:t},n?{details:n}:{})}),{TYPE_INCORRECT:function(e,n){var r="Expected "+i.default(e)+", but was "+t.typeOf(n);return t.FAILURE(o.Failcode.TYPE_INCORRECT,r)},VALUE_INCORRECT:function(e,n,r){return t.FAILURE(o.Failcode.VALUE_INCORRECT,"Expected "+e+" "+String(n)+", but was "+String(r))},KEY_INCORRECT:function(e,n,r){return t.FAILURE(o.Failcode.KEY_INCORRECT,"Expected "+i.default(e)+" key to be "+i.default(n)+", but was "+t.typeOf(r))},CONTENT_INCORRECT:function(e,n){var r="Expected "+i.default(e)+", but was incompatible";return t.FAILURE(o.Failcode.CONTENT_INCORRECT,r,n)},ARGUMENT_INCORRECT:function(e){return t.FAILURE(o.Failcode.ARGUMENT_INCORRECT,e)},RETURN_INCORRECT:function(e){return t.FAILURE(o.Failcode.RETURN_INCORRECT,e)},CONSTRAINT_FAILED:function(e,n){var r=n?": "+n:"";return t.FAILURE(o.Failcode.CONSTRAINT_FAILED,"Failed constraint check for "+i.default(e)+r)},PROPERTY_MISSING:function(e){var n="Expected "+i.default(e)+", but was missing";return t.FAILURE(o.Failcode.PROPERTY_MISSING,n)},PROPERTY_PRESENT:function(e){var n="Expected nothing, but was "+t.typeOf(e);return t.FAILURE(o.Failcode.PROPERTY_PRESENT,n)},NOTHING_EXPECTED:function(e){var n="Expected nothing, but was "+t.typeOf(e);return t.FAILURE(o.Failcode.NOTHING_EXPECTED,n)}})},512:(e,t)=>{var n=function(e){if("object"==typeof e&&null!==e){if("function"==typeof Object.getPrototypeOf){var t=Object.getPrototypeOf(e);return t===Object.prototype||null===t}return"[object Object]"===Object.prototype.toString.call(e)}return!1},r=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return e.reduce((function(e,t){return Object.keys(t).forEach((function(o){Array.isArray(e[o])&&Array.isArray(t[o])?e[o]=Array.from(new Set(e[o].concat(t[o]))):n(e[o])&&n(t[o])?e[o]=r(e[o],t[o]):e[o]=t[o]})),e}),{})};t.Z=r}},t={};function n(r){var o=t[r];if(void 0!==o)return o.exports;var i=t[r]={exports:{}};return e[r].call(i.exports,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.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var r={};(()=>{n.d(r,{EX:()=>Je,kS:()=>Xe,$s:()=>et,Lk:()=>Ze,Hc:()=>tt,EA:()=>Qe});const e=()=>window.location.hostname,t=()=>window.location.href,o=()=>e().replace(/\.[^.]+\.api\.no/,""),i=()=>{const t=(()=>{const t=/^bed-([^.]+)\.api\.no$/.exec(e()),n=/\.([^.]+)\.api\.no/.exec(e());return t?t[1]:n?n[1]:null})();let n="www.aid.no";return"localhost"===t?n="www.aid.no.localhost.api.no":t&&(n=`www-${t}.aid.no`),n};var a=function(e,t,n,r){return new(n||(n=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 t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,c)}u((r=r.apply(e,t||[])).next())}))};const c=(n,r,o)=>{!function(e,t){const n=new FormData;Object.keys(t).forEach((e=>n.append(e,t[e]))),fetch(e,{method:"POST",body:n,headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json"}}).then((e=>{if(!e.ok)throw new Error(`Error, status: ${e.status}, text: ${e.statusText}`)}))}(`//www.aid.no/api/mercury/v1/log/${n}`,Object.assign(Object.assign({},o),{message:r,url:t(),domain:e()}))},u=(e,t)=>c("error",e,t);class s extends Error{}const f={debug:console.debug,info:console.info,warn:console.warn,error:console.error};let l;var d;"undefined"!=typeof window&&(d=window,l=d);const v=(e,t)=>{l?l.addEventListener(e,(e=>{e.stopImmediatePropagation(),t.apply(l,[e])})):f.error("No root element to bind event to!")},h=(e,t)=>{l?l.addEventListener(e,(e=>{t.apply(l,[e])})):f.error("No root element to bind event to!")},p=e=>{l?l.dispatchEvent(e):f.error("No root element to dispatch event on!")};var y=n(61);const g={},m=e=>{const t=g[e];return t?(delete g[e],t):[]},b=()=>{const e="undefined"!=typeof window?window:n.g;return e.amediaUserCache||(e.amediaUserCache={})},E={get:e=>{const t=b()[e];return Promise.resolve(t)},set:(e,t,n)=>(b()[e]={key:e,data:t,expires:n},Promise.resolve()),remove:e=>(delete b()[e],Promise.resolve()),clear:()=>(("undefined"!=typeof window?window:n.g).amediaUserCache={},Promise.resolve())};const _=()=>E,w=e=>_().remove(e),S=(e,t)=>{return n=void 0,r=void 0,i=function*(){const n=yield _().get(e);if(!n)return Promise.resolve();if(Date.now()>n.expires)return w(e),Promise.resolve();try{return t.check(n.data)}catch(t){return t instanceof y.ValidationError?f.error("Failed validating data",{data:n.data,error:t.details}):f.error("Unknown error",t),w(e),Promise.resolve()}},new((o=void 0)||(o=Promise))((function(e,t){function a(e){try{u(i.next(e))}catch(e){t(e)}}function c(e){try{u(i.throw(e))}catch(e){t(e)}}function u(t){var n;t.done?e(t.value):(n=t.value,n instanceof o?n:new o((function(e){e(n)}))).then(a,c)}u((i=i.apply(n,r||[])).next())}));var n,r,o,i},R=(e,t,n)=>_().set(e,t,Date.now()+n);function O(e,t,n,r){return new Promise(((o,i)=>{((e,t)=>{g[e]||(g[e]=[]),g[e].push(t)})(e,{resolve:o,reject:i}),(e=>{var t;return(null===(t=g[e])||void 0===t?void 0:t.length)||0})(e)>1||S(e,t).then((t=>{!t||r&&!r(t)?n().then((n=>{const r=t?((e,t)=>!e||Array.isArray(t)?t:t?"object"==typeof e&&"object"==typeof t?Object.assign(Object.assign({},e),t):t:e)(t,n.data):n.data;R(e,r,n.ttl),m(e).forEach((e=>{e.resolve(n.data)}))})).catch((()=>{m(e).forEach((e=>{e.reject()}))})):m(e).forEach((e=>{e.resolve(t)}))}))}))}const I=(0,y.Record)({id:y.Number,domain:y.String}),C=(0,y.Record)({status:(0,y.Literal)("success"),access:(0,y.Union)((0,y.Literal)("granted"),(0,y.Literal)("denied")),publication:I,access_features:(0,y.Array)(y.String)}),T=(0,y.Record)({status:(0,y.Literal)("success"),cookie:y.String,access_features:(0,y.Array)(y.String)}),A=(0,y.Record)({status:(0,y.Literal)("success"),vstoken_cookie:y.String,uuid:y.String,access_features:(0,y.Array)(y.String)}),N={},j={},P=e=>{var t;null===(t=j[e])||void 0===t||t.forEach((t=>t(N[e])))},U=(e,t)=>{N[e]=Object.assign(Object.assign({},N[e]),t),P(e)},k=(e,t)=>{N[e]=t,P(e)},x=e=>N[e],L=(e,t)=>{j[e]||(j[e]=[]),j[e].push(t)};var D=function(e,t,n,r){return new(n||(n=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 t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,c)}u((r=r.apply(e,t||[])).next())}))};const F=(0,y.Partial)({user_uuid:y.String,user_name:y.String,tracking_key:y.String}),M=e=>({uuid:e.user_uuid,name:e.user_name,trackingKey:e.tracking_key}),B=()=>fetch("/api/pluto/v1/sessions/current").then((e=>e.ok?(U("state",{isLoggedIn:!0}),e.json()):403===e.status?(U("state",{isLoggedIn:!1}),{}):(f.error(`Unknown error (${e.status}: ${e.statusText}) when fetching current session`,{response:e}),Promise.reject()))).then((e=>{const t={ttl:-1,data:e};if(0===Object.keys(e).length)return t;try{return{ttl:1e4,data:F.check(e)}}catch(e){return f.error("Invalid schema",e),t}})),$=()=>D(void 0,void 0,void 0,(function*(){return O("getCurrentSession",F,B).then(M)})),V=e=>D(void 0,void 0,void 0,(function*(){return fetch(`/api/pluto/v1/sessions/current?publication_domain=${e}`,{method:"DELETE"}).then((e=>{if(!e.ok){if(403===e.status)return;throw new Error(`Error, could not perform deleteRequest. Status: ${e.status} Text: ${e.statusText}`)}U("state",{isLoggedIn:!1})}))}));let q;const K=self||window,G="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||void 0!==K.msCrypto&&"function"==typeof K.msCrypto.getRandomValues&&K.msCrypto.getRandomValues.bind(K.msCrypto);if(G){const e=new Uint8Array(16);q=function(){return G(e),e}}else{const e=new Array(16);q=function(){for(let t,n=0;n<16;n+=1)0==(3&n)&&(t=4294967296*Math.random()),e[n]=t>>>((3&n)<<3)&255;return e}}const Y=[];for(let e=0;e<256;++e)Y[e]=(e+256).toString(16).substr(1);function z(e,t){return(...n)=>{const{resolve:r,reject:o,promise:i}=function(){let e,t,n=!1;return{promise:new Promise(((r,o)=>{e=e=>{n||r(e),n=!0},t=e=>{n||o(e),n=!0}})),resolve:e,reject:t}}(),a=function(){const e=q();return e[6]=15&e[6]|64,e[8]=63&e[8]|128,function(e,t){let n=0;const r=Y;return[r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]]].join("")}(e)}(),c=new CustomEvent(`amedia-rpc-event:${e}:${t}`,{detail:{eventId:a,args:n}});if(self.dispatchEvent(c),self.amediaNativeBridge){const r=JSON.stringify(n);self.amediaNativeBridge.callNativeMethod(e,t,r,a)}return self.addEventListener(`amedia-rpc-event:${e}:${t}:${a}`,(e=>{e.detail||r();const{error:t,result:n}=e.detail;return t?o(t):r(n)})),i}}class W{constructor({version:e,component:t,methods:n=[]}){this.component=t,this.version=e,this.queue=[],n.forEach((e=>this.addMethod(e))),this.boundLiveHandler=this.liveHandler.bind(this),self.addEventListener(`amedia-rpc-event:${t}:live`,this.boundLiveHandler),setTimeout((()=>self.dispatchEvent(new CustomEvent(`amedia-rpc-event:${t}:ready`))),0)}liveHandler(e){const[t,n]=e.detail.version.split(".").map((e=>parseInt(e,10))),[r,o]=this.version.split(".").map((e=>parseInt(e,10)));if(t!==r)throw new Error(`${this.component} version mismatch. Server version: ${t}. Client version: ${r}`);n<o&&console.warn(`${this.component} server version is on an earlier minor version (${n}) than the client (${o})`);const i=this.queue.slice(0);delete this.queue,i.forEach((e=>e())),self.removeEventListener(`amedia-rpc-event:${this.component}:live`,this.boundLiveHandler)}addMethod(e){if(this[e])throw new Error(`${e} already exists on the RPC interface.`);this[e]=(...t)=>{if(this.queue){let n,r;const o=new Promise(((e,t)=>{n=e,r=t}));return this.queue.push((()=>this[e](...t).then(n).catch(r))),o}return this[e]=z(this.component,e),this[e](...t)}}}let H;const Q=(e,t)=>{const n=t.substring(e.length,t.length);return"{"===n.substring(0,1)?JSON.parse(n):"%7B"===n.substring(0,3)?JSON.parse(decodeURIComponent(n)):"undefined"!==n?""===n||"null"===n?null:n:void 0},J=e=>{const t=`${e}=`,n=document.cookie.split(";");for(let e=n.length-1;e>=0;e-=1){const r=n[e].trim();if(0===r.indexOf(t))return Q(t,r)}return null};function X(e,t,n=Date.now(),r="/",o=!1){const i=new Date;let a=`${e}=`;return t&&""!==t||(n=-1),a+=(e=>e&&""!==e?e instanceof Object?encodeURIComponent(JSON.stringify(e)):"number"==typeof e?e.toString(10):e:"")(t),a+=((e,t)=>t?t instanceof Date?`; expires=${t.toUTCString()}`:(e.setTime(e.getTime()+24*t*60*60*1e3),`; expires=${e.toUTCString()}`):"")(i,n),a+=`; path=${r}`,o&&(a+="; secure"),document.cookie=a,n&&-1!==n&&null===J(e)&&(document.cookie=a.replace(/; expires=[^;]*/,"")),a}function Z(e){X(e)}const ee=e=>{window.location.href=e};const te=()=>{return e=void 0,t=void 0,r=function*(){return Promise.all([V(o()),_().clear()]).then((()=>{(H||(H=new W({version:"1.0.0",component:"userdata-session",methods:["userAuthenticated"]}),H)).userAuthenticated(!1),Z("VSTOKEN"),Z("aid.session"),Z("aid_invitation_code"),Z("aid-reload-article"),Z("VSTOKEN2")})).catch((e=>{f.error("Failure while logging out",e)}))},new((n=void 0)||(n=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 t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,c)}u((r=r.apply(e,t||[])).next())}));var e,t,n,r},ne=()=>$(),re=()=>{var e;return!!(null===(e=x("state"))||void 0===e?void 0:e.isLoggedIn)};var oe=function(e,t,n,r){return new(n||(n=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 t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,c)}u((r=r.apply(e,t||[])).next())}))};const ie=(e=["newspaper"])=>((e,t)=>O("checkForAccess",C,(()=>fetch(`/api/jupiter/v1/check_access_for_paper/${e}/?require=any&access_features=${t.join(",")}`).then((e=>{if(!e.ok)throw new Error(`Request not ok (${e.status}: ${e.statusText}).`);return e.json()})).then((e=>{try{const t=C.check(e);return{ttl:"granted"===t.access?1e4:0,data:t}}catch(e){throw f.error("Invalid schema",e),e}})))).then((e=>({access:e.access_features}))))(o(),e),ae=e=>{try{return(e=>a(void 0,void 0,void 0,(function*(){return fetch(`/api/mercury/v2/access/activate?publication_wwwdomain=${o()}&access_features=${e.join(",")}`,{method:"post"}).then((e=>a(void 0,void 0,void 0,(function*(){let t;try{t=yield e.json()}catch(e){u("Body does not contain parsable json",e)}if(!e.ok){if(401===e.status&&"user_deactivated"===(null==t?void 0:t.status))throw new s;return!1}return"success"===(null==t?void 0:t.status)&&"granted"===(null==t?void 0:t.access)}))))})))(e)}catch(e){if(e instanceof s)return te(),Promise.resolve(!1);throw e}},ce=(e,t)=>t.filter((t=>e.includes(t))).length>0,ue=e=>oe(void 0,void 0,void 0,(function*(){const t=yield(e=>fetch(`/api/jupiter/v1/get_vstoken/${e}`,{method:"post"}).then((e=>{if(!e.ok)throw new Error(`Request not ok (${e.status}: ${e.statusText}).`);return e.json()})).then((e=>{try{return T.check(e)}catch(e){throw f.error("Invalid schema",e),e}})))(e);return"success"===t.status&&(X("VSTOKEN",t.cookie,365,"/"),!0)})),se=e=>oe(void 0,void 0,void 0,(function*(){const t=yield(e=>fetch(`/api/jupiter/v1/non_user_access/${e}`,{method:"post"}).then((e=>{if(!e.ok)throw new Error(`Request not ok (${e.status}: ${e.statusText}).`);return e.json()})).then((e=>{try{return A.check(e)}catch(e){throw f.error("Invalid schema",e),e}})))(e);return"success"===t.status&&(X("VSTOKEN2",t.vstoken_cookie,1,"/"),!0)}));var fe;!function(e){e.REQUEST_ACTIVATION="amedia-user.activation.request-activation",e.ON_ACTIVATION_COMPLETE="amedia-user.activation.on-activation-complete"}(fe||(fe={})),v(fe.REQUEST_ACTIVATION,(e=>{ae(e.detail.accessFeatures).then((e=>{p(new CustomEvent(fe.ON_ACTIVATION_COMPLETE,{detail:{hasAccess:e}}))}))}));var le=n(466),de=n(651);let ve;const he="undefined"==typeof self?window:self,pe="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||void 0!==he.msCrypto&&"function"==typeof he.msCrypto.getRandomValues&&he.msCrypto.getRandomValues.bind(he.msCrypto);if(pe){const e=new Uint8Array(16);ve=function(){return pe(e),e}}else{const e=new Array(16);ve=function(){for(let t,n=0;n<16;n+=1)0==(3&n)&&(t=4294967296*Math.random()),e[n]=t>>>((3&n)<<3)&255;return e}}const ye=[];for(let e=0;e<256;++e)ye[e]=(e+256).toString(16).substr(1);function ge(){const e=ve();return e[6]=15&e[6]|64,e[8]=63&e[8]|128,function(e,t){let n=0;const r=ye;return[r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]]].join("")}(e)}le.config({name:"aid:userdata"});const me=self.location.hostname.replace(/(.*\.)([^.]+\.\w+$)/,"$2");function be(e){return de.set("amedia:visitid",e,{expires:new Date(Date.now()+18e5),domain:me,sameSite:"strict"}),le.setItem("visitid",e).then((()=>e))}function Ee(){const e=Date.now();return be(`${ge()}|${e}`)}function _e(){return function(){const e=de.get("amedia:visitid");return e?Promise.resolve(e):le.getItem("visitid")}().then((e=>e||Ee())).then((e=>{const[t,n]=e.split("|");return!t||n&&Date.now()-18e5>n?Ee():be(`${t}|${Date.now()}`)})).catch((e=>console.error(e)))}"undefined"!=typeof window&&["mousedown","keydown","mousemove","focus","scroll","resize","seshat-video-active","touchmove","deviceorientation"].forEach((e=>window.addEventListener(e,function(e){let t=!1;return(...n)=>{t||(e.apply(this,n),t=!0,setTimeout((()=>{t=!1}),400))}}(_e))));var we=n(512),Se=function(e,t,n,r){return new(n||(n=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 t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,c)}u((r=r.apply(e,t||[])).next())}))};const Re=3e5,Oe=(0,y.Record)({namespaces:(0,y.Dictionary)(y.Unknown,y.String)}),Ie=(e,t="GET",n)=>fetch(e,{method:t,body:n&&JSON.stringify(n),headers:{"Content-Type":"application/json",Accept:"application/json"}}),Ce=(e,t={ignoreCache:!1})=>Se(void 0,void 0,void 0,(function*(){if(0===e.length)throw new Error("namespaces array cannot be of length 0");return O("europa",Oe,(()=>Ie(`/api/europa/v1/me/${e.join(",")}`).then((t=>t.ok?t.json():(f.error(`Could not get namespaces for: ${e}, status: ${t.status}, statusText: ${t.statusText}`,t),{namespaces:{}}))).then((e=>({ttl:Re,data:e})))),(n=>!t.ignoreCache||0===Object.keys(n.namespaces).filter((t=>!Object.keys(e).includes(t))).length)).then((e=>e.namespaces))}));const Te=(0,y.Record)({allowResearchUsage:y.Boolean,connectWithSurveys:y.Boolean,personalizedAds:y.Boolean,personalizedContent:y.Boolean}),Ae=e=>"true"===e||!0===e,Ne=(0,y.Dictionary)(y.Unknown,y.String).And((0,y.Partial)({ad_segments:y.String,ad_segments_user:y.String,age:y.Number,age_user:y.Number,birth_year:y.String,birth_year_user:y.String,gender:y.String,gender_user:y.String,grunnkrets:y.String,grunnkrets_user:y.String,postcode:y.String,postcode_user:y.String,shared_account:y.Boolean,shared_account_user:y.Boolean,user_grouping_number:y.String,user_grouping_number_user:y.String})),je=e=>({extraData:e}),Pe={uuid:ne,name:ne,trackingKey:ne,access:ie,extraData:()=>function(){let e=de.get("amedia:fpbid");return e||(e=ge(),de.set("amedia:fpbid",e,{expires:3650,domain:me,sameSite:"strict"})),Promise.resolve(e)}().then((e=>{var t;return((e,t,n)=>O("getNebulaInfo",Ne,(()=>((e,t,n)=>{const r=new URL("https://services.gcloud.api.no/api/nebula/v1/info");return r.searchParams.set("domain",e),r.searchParams.set("browser_id",t),n&&r.searchParams.set("user_key",n),fetch(r.href).then((e=>e.json())).then((e=>{try{return{ttl:18e6,data:Ne.check(e)}}catch(e){throw f.error("Invalid schema",e),e}}))})(e,t,n))).then(je))(window.location.hostname,e,null===(t=x("userAttributes"))||void 0===t?void 0:t.trackingKey)})),privacyPreferences:()=>{return e=void 0,t=void 0,r=function*(){return O("privacyPreferences",Te,(()=>Ce(["privacy_preferences"]).then((e=>{const t=e.privacy_preferences;return{ttl:3e5,data:{allowResearchUsage:Ae(t.allow_research_usage),connectWithSurveys:Ae(t.connect_with_surveys),personalizedAds:Ae(t.personalized_ads),personalizedContent:Ae(t.personalized_content)}}})))).then((e=>({privacyPreferences:e})))},new((n=void 0)||(n=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 t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,c)}u((r=r.apply(e,t||[])).next())}));var e,t,n,r}};var Ue;!function(e){e.REQUEST_USER_ATTRIBUTES="amedia-user.request-user-attributes",e.REQUEST_STORAGE_NAMESPACES="amedia-user.request-storage-namespaces",e.UPDATE_STORAGE="amedua-user.update-storage-namespaces",e.ON_ATTRIBUTES_UPDATED="amedia-user.on-user-attributes-updated",e.ON_STATE_UPDATED="amedia-user.on-state-updated",e.ON_STORAGE_UPDATED="amedia-user.on-storage-updated"}(Ue||(Ue={})),L("userAttributes",(e=>{p(new CustomEvent(Ue.ON_ATTRIBUTES_UPDATED,{detail:e}))})),L("state",(e=>{p(new CustomEvent(Ue.ON_STATE_UPDATED,{detail:e}))})),L("storage",(e=>{p(new CustomEvent(Ue.ON_STORAGE_UPDATED,{detail:e}))})),v(Ue.REQUEST_USER_ATTRIBUTES,(e=>{(e=>{const t=[];for(e.forEach((e=>{const n=Pe[e];n?t.includes(n)||t.push(n):f.warn("Unknown attribute was requested")}));t.length>0;){const e=t.pop();e&&e().then((e=>U("userAttributes",(0,we.Z)(x("userAttributes")||{},e)))).catch((t=>{f.error("Call rejected",e,t)}))}})(e.detail)})),v(Ue.REQUEST_STORAGE_NAMESPACES,(e=>{var t;t=e.detail,Ce(t).then((e=>{U("storage",e)}))})),v(Ue.UPDATE_STORAGE,(e=>{var t;t=e.detail,Object.keys(t).forEach((e=>((e,t)=>Se(void 0,void 0,void 0,(function*(){const n=yield Ie(`/api/europa/v1/me/${e}`,"PATCH",t);return n.ok?((e,t)=>Se(void 0,void 0,void 0,(function*(){const n=yield S("europa",Oe),r=n?Object.assign(Object.assign({},n),{namespaces:Object.assign(Object.assign({},n.namespaces),{[e]:t})}):{namespaces:{[e]:t}};return R("europa",r,Date.now()+Re)})))(e,t):(f.error(`Could not get namespace: ${e}, status: ${n.status}, statusText: ${n.statusText}`,n),{})})))(e,t[e])))}));const ke=(e,t)=>{if(e===t)return!0;if("object"!=typeof e||"object"!=typeof t||null===e||null===t)return!1;const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(const o of n){if(!r.includes(o))return!1;if("function"==typeof e[o]||"function"==typeof t[o]){if(e[o].toString()!==t[o].toString())return!1}else if(!ke(e[o],t[o]))return!1}return!0};class xe{constructor(e,t){this.attributes=e,this.namespaces=t}withAttributes(e){return new xe([...this.attributes||[],...e],this.namespaces)}withStorage(...e){return new xe(this.attributes,[...this.namespaces||[],...e])}subscribe(e){let t=this.setupLocalCache();h(Ue.ON_STATE_UPDATED,(n=>{const r=n.detail;Object.keys(t.state).length>0&&ke(t.state,r)||(t=Object.assign(Object.assign({},t),{state:r}),e(t))})),Array.isArray(this.attributes)&&this.attributes.length>0&&(h(Ue.ON_ATTRIBUTES_UPDATED,(n=>{const r=this.processUserAttributesEvent(n);Object.keys(t.attributes).length>0&&ke(t.attributes,r)||(t=Object.assign(Object.assign({},t),{attributes:r}),e(t))})),p(new CustomEvent(Ue.REQUEST_USER_ATTRIBUTES,{detail:this.attributes}))),Array.isArray(this.namespaces)&&this.namespaces.length>0&&(h(Ue.ON_STORAGE_UPDATED,(n=>{const r=this.processStorageEvent(n);ke(t.storage,r)||(t=Object.assign(Object.assign({},t),{storage:r}),e(t))})),p(new CustomEvent(Ue.REQUEST_STORAGE_NAMESPACES,{detail:this.namespaces})))}processUserAttributesEvent(e){const t=e.detail;return this.attributes.reduce(((e,n)=>(void 0!==t[n]&&(e[n]=t[n]),e)),{})}processStorageEvent(e){const t=e.detail;return this.namespaces.reduce(((e,n)=>(void 0!==t[n]&&(e[n]=t[n]),e)),{})}setupLocalCache(){const e={state:{}};return this.attributes&&this.attributes.length>0&&(e.attributes={}),this.namespaces&&this.namespaces.length>0&&(e.storage={}),e}}const Le=xe;class De extends Error{constructor(e,t){super(e),this.code=t}}De.ERROR_RELOADED_NO_ACCESS="RELOADED_NO_ACCESS",De.ERROR_ENABLING_ACCESS_FAILED="ENABLING_ACCESS_FAILED";const Fe=De;var Me=function(e,t,n,r){return new(n||(n=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 t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,c)}u((r=r.apply(e,t||[])).next())}))};var Be=function(e,t,n,r){return new(n||(n=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 t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,c)}u((r=r.apply(e,t||[])).next())}))};function $e(){return Be(this,void 0,void 0,(function*(){const e=o(),t=J("VSTOKEN");let n=!1;(new Le).withAttributes(["uuid"]).subscribe((({attributes:r,state:o})=>Be(this,void 0,void 0,(function*(){if(!1===o.isLoggedIn)return void("string"==typeof t&&Z("VSTOKEN"));if(!r.uuid||void 0===o.isLoggedIn||n)return;if(n=!0,"string"!=typeof t)return void(yield ue(e));const i=t.split(":"),a=new Date(1e3*parseInt(i[1],10));a.setDate(a.getDate()-1),a.getTime()>Date.now()&&i[3]===r.uuid&&e.includes(i[4])&&"jupiter"===i[5]||(yield ue(e))}))))}))}function Ve(){return Be(this,void 0,void 0,(function*(){const e=o(),t=J("VSTOKEN2");if("string"!=typeof t)return void(yield se(e));const n=t.split(":"),r=new Date(1e3*parseInt(n[1],10));r.setMinutes(r.getMinutes()-30),r.getTime()>Date.now()&&e.includes(n[4])&&"jupiter"===n[5]||(yield se(e))}))}const qe="haveTriedThirdPartyLoginCheck",Ke=(0,y.Record)({user_name:y.String,tracking_key:y.String});const Ge="have-tried-autologin",Ye=[{name:"third_party",handler:function(){return e=this,t=void 0,r=function*(){return!(yield S(qe,y.Boolean))&&(yield R(qe,!0,36e5),!!(yield fetch(`https://${i()}/api/pluto/v1/sessions/current`,{mode:"cors",credentials:"include"}).then((e=>e.ok?e.json():(403!==e.status&&f.error(`Unknown error (${e.status}: ${e.statusText}) when fetching current session`,{response:e}),null))).then((e=>{if(!e)return null;try{return Ke.check(e)}catch(e){return f.error("Invalid schema",e),null}}))))},new((n=void 0)||(n=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 t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,c)}u((r=r.apply(e,t||[])).next())}));var e,t,n,r}}];var ze=function(e,t,n,r){return new(n||(n=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 t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,c)}u((r=r.apply(e,t||[])).next())}))};const We=[()=>{return e=void 0,n=void 0,o=function*(){var e;if(!function(){try{return window.self!==window.top}catch(e){return!0}}()&&(yield $(),!(null===(e=x("state"))||void 0===e?void 0:e.isLoggedIn)&&!function(){const e=J(Ge);if(e&&"object"!=typeof e)try{if(Date.now()-parseInt(e,10)<6e4)return!0}catch(e){Z(Ge)}return X(Ge,Date.now(),Date.now()+6e4),!1}()))for(const e of Ye)if(!(yield e.handler().then((n=>{if(n){const n=new URL(`https://${i()}/aid/logg_inn/auto`);return n.searchParams.set("context",`auto_login_${e.name}`),n.searchParams.set("requestedUrl",t()),ee(n.href),!1}return!0}))))return},new((r=void 0)||(r=Promise))((function(t,i){function a(e){try{u(o.next(e))}catch(e){i(e)}}function c(e){try{u(o.throw(e))}catch(e){i(e)}}function u(e){var n;e.done?t(e.value):(n=e.value,n instanceof r?n:new r((function(e){e(n)}))).then(a,c)}u((o=o.apply(e,n||[])).next())}));var e,n,r,o},function(){return Promise.all([$e(),Ve()])},function(){(new Le).subscribe((({state:e})=>{!1===e.isLoggedIn&&(k("userAttributes",{}),k("storage",{}))}))}];var He;!function(e){e.LOADED="amedia-user.janitor.loaded"}(He||(He={}));const Qe=()=>new Le,Je=e=>(e=>{const t=new URL(`https://${i()}/aid/logg_inn/${o()}/`);t.searchParams.set("requestedUrl",e instanceof URL?e.href:e),ee(t.href)})(e||t()),Xe=()=>te(),Ze=e=>new Promise((t=>{h(fe.ON_ACTIVATION_COMPLETE,(e=>t(e.detail))),p(new CustomEvent(fe.REQUEST_ACTIVATION,{detail:{accessFeatures:e}}))})),et=()=>new class{constructor(){this.requestedAccessFeatures=["newspaper"],this.reload=!1}withAccessFeatures(e){return this.requestedAccessFeatures=e,this}reloadOnAccess(){return this.reload=!0,this}redirectOnAccess(e){return this.requestedUrl=e,this}tryUnlock(){return Me(this,void 0,void 0,(function*(){if((()=>{const e=J("aid-paywall-check-performed");if(!e)return!1;const n=t();return Array.isArray(e)?e.filter((e=>e===n)).length>0:e===n})())throw new Fe("Unlock check already performed.",Fe.ERROR_RELOADED_NO_ACCESS);return!re()&&(yield $().then((()=>!re())))?{isLoggedIn:!1,hasAccess:!1,accessFeatures:[]}:this.resolveActualAccessFeatures().then((e=>ce(e,this.requestedAccessFeatures)?this.setAccessCookiesAndPerformRequestedActions(e):{isLoggedIn:!0,hasAccess:!1,accessFeatures:e}))}))}resolveActualAccessFeatures(){return Me(this,void 0,void 0,(function*(){let e=yield ie(this.requestedAccessFeatures).then((e=>e.access||[]));if(!ce(e,this.requestedAccessFeatures)){if(!(yield ae(this.requestedAccessFeatures)))return e;e=yield ie(this.requestedAccessFeatures).then((e=>e.access||[]))}return e}))}setAccessCookiesAndPerformRequestedActions(e){return(n=o(),oe(void 0,void 0,void 0,(function*(){return ue(n)&&se(n)}))).then((n=>{if(!n)throw new Fe("Could not set access cookies",Fe.ERROR_ENABLING_ACCESS_FAILED);var r;return(()=>{const e=new URL(t());e.searchParams.set("access","granted");const n=new Date;n.setTime(n.getTime()+12e4),X("aid-paywall-check-performed",e.href,n)})(),this.reload&&window.location.reload(),this.requestedUrl&&(r=this.requestedUrl,window.location.replace(r)),{isLoggedIn:!0,hasAccess:!0,accessFeatures:e}}));var n}},tt=e=>p(new CustomEvent(Ue.UPDATE_STORAGE,{detail:e}));"undefined"==typeof process&&ze(void 0,void 0,void 0,(function*(){let e=!1;v(He.LOADED,(()=>{e||(e=!0,function(){ze(this,void 0,void 0,(function*(){for(const e of We)yield e()}))}())})),p(new CustomEvent(He.LOADED))}))})();var o=r.EX,i=r.kS,a=r.$s,c=r.Lk,u=r.Hc,s=r.EA;export{o as goToLoginPage,i as logout,a as paywall,c as tryActivateSubscriptionAccess,u as updateStorage,s as user};
2
+ var e={808:(e,t,n)=>{var r,o,i;void 0===(o="function"==typeof(r=i=function(){function e(){for(var e=0,t={};e<arguments.length;e++){var n=arguments[e];for(var r in n)t[r]=n[r]}return t}function t(e){return e.replace(/(%[0-9A-Z]{2})+/g,decodeURIComponent)}return function n(r){function o(){}function i(t,n,i){if("undefined"!=typeof document){"number"==typeof(i=e({path:"/"},o.defaults,i)).expires&&(i.expires=new Date(1*new Date+864e5*i.expires)),i.expires=i.expires?i.expires.toUTCString():"";try{var a=JSON.stringify(n);/^[\{\[]/.test(a)&&(n=a)}catch(e){}n=r.write?r.write(n,t):encodeURIComponent(String(n)).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,decodeURIComponent),t=encodeURIComponent(String(t)).replace(/%(23|24|26|2B|5E|60|7C)/g,decodeURIComponent).replace(/[\(\)]/g,escape);var c="";for(var u in i)i[u]&&(c+="; "+u,!0!==i[u]&&(c+="="+i[u].split(";")[0]));return document.cookie=t+"="+n+c}}function a(e,n){if("undefined"!=typeof document){for(var o={},i=document.cookie?document.cookie.split("; "):[],a=0;a<i.length;a++){var c=i[a].split("="),u=c.slice(1).join("=");n||'"'!==u.charAt(0)||(u=u.slice(1,-1));try{var s=t(c[0]);if(u=(r.read||r)(u,s)||t(u),n)try{u=JSON.parse(u)}catch(e){}if(o[s]=u,e===s)break}catch(e){}}return e?o[e]:o}}return o.set=i,o.get=function(e){return a(e,!1)},o.getJSON=function(e){return a(e,!0)},o.remove=function(t,n){i(t,"",e(n,{expires:-1}))},o.defaults={},o.withConverter=n,o}((function(){}))})?r.call(t,n,t,e):r)||(e.exports=o),e.exports=i()},483:(e,t,n)=>{e.exports=function e(t,n,r){function o(a,c){if(!n[a]){if(!t[a]){if(i)return i(a,!0);var u=new Error("Cannot find module '"+a+"'");throw u.code="MODULE_NOT_FOUND",u}var s=n[a]={exports:{}};t[a][0].call(s.exports,(function(e){return o(t[a][1][e]||e)}),s,s.exports,e,t,n,r)}return n[a].exports}for(var i=void 0,a=0;a<r.length;a++)o(r[a]);return o}({1:[function(e,t,r){(function(e){var n,r,o=e.MutationObserver||e.WebKitMutationObserver;if(o){var i=0,a=new o(f),c=e.document.createTextNode("");a.observe(c,{characterData:!0}),n=function(){c.data=i=++i%2}}else if(e.setImmediate||void 0===e.MessageChannel)n="document"in e&&"onreadystatechange"in e.document.createElement("script")?function(){var t=e.document.createElement("script");t.onreadystatechange=function(){f(),t.onreadystatechange=null,t.parentNode.removeChild(t),t=null},e.document.documentElement.appendChild(t)}:function(){setTimeout(f,0)};else{var u=new e.MessageChannel;u.port1.onmessage=f,n=function(){u.port2.postMessage(0)}}var s=[];function f(){var e,t;r=!0;for(var n=s.length;n;){for(t=s,s=[],e=-1;++e<n;)t[e]();n=s.length}r=!1}t.exports=function(e){1!==s.push(e)||r||n()}}).call(this,void 0!==n.g?n.g:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],2:[function(e,t,n){var r=e(1);function o(){}var i={},a=["REJECTED"],c=["FULFILLED"],u=["PENDING"];function s(e){if("function"!=typeof e)throw new TypeError("resolver must be a function");this.state=u,this.queue=[],this.outcome=void 0,e!==o&&v(this,e)}function f(e,t,n){this.promise=e,"function"==typeof t&&(this.onFulfilled=t,this.callFulfilled=this.otherCallFulfilled),"function"==typeof n&&(this.onRejected=n,this.callRejected=this.otherCallRejected)}function l(e,t,n){r((function(){var r;try{r=t(n)}catch(t){return i.reject(e,t)}r===e?i.reject(e,new TypeError("Cannot resolve promise with itself")):i.resolve(e,r)}))}function d(e){var t=e&&e.then;if(e&&("object"==typeof e||"function"==typeof e)&&"function"==typeof t)return function(){t.apply(e,arguments)}}function v(e,t){var n=!1;function r(t){n||(n=!0,i.reject(e,t))}function o(t){n||(n=!0,i.resolve(e,t))}var a=h((function(){t(o,r)}));"error"===a.status&&r(a.value)}function h(e,t){var n={};try{n.value=e(t),n.status="success"}catch(e){n.status="error",n.value=e}return n}t.exports=s,s.prototype.catch=function(e){return this.then(null,e)},s.prototype.then=function(e,t){if("function"!=typeof e&&this.state===c||"function"!=typeof t&&this.state===a)return this;var n=new this.constructor(o);return this.state!==u?l(n,this.state===c?e:t,this.outcome):this.queue.push(new f(n,e,t)),n},f.prototype.callFulfilled=function(e){i.resolve(this.promise,e)},f.prototype.otherCallFulfilled=function(e){l(this.promise,this.onFulfilled,e)},f.prototype.callRejected=function(e){i.reject(this.promise,e)},f.prototype.otherCallRejected=function(e){l(this.promise,this.onRejected,e)},i.resolve=function(e,t){var n=h(d,t);if("error"===n.status)return i.reject(e,n.value);var r=n.value;if(r)v(e,r);else{e.state=c,e.outcome=t;for(var o=-1,a=e.queue.length;++o<a;)e.queue[o].callFulfilled(t)}return e},i.reject=function(e,t){e.state=a,e.outcome=t;for(var n=-1,r=e.queue.length;++n<r;)e.queue[n].callRejected(t);return e},s.resolve=function(e){return e instanceof this?e:i.resolve(new this(o),e)},s.reject=function(e){var t=new this(o);return i.reject(t,e)},s.all=function(e){var t=this;if("[object Array]"!==Object.prototype.toString.call(e))return this.reject(new TypeError("must be an array"));var n=e.length,r=!1;if(!n)return this.resolve([]);for(var a=new Array(n),c=0,u=-1,s=new this(o);++u<n;)f(e[u],u);return s;function f(e,o){t.resolve(e).then((function(e){a[o]=e,++c!==n||r||(r=!0,i.resolve(s,a))}),(function(e){r||(r=!0,i.reject(s,e))}))}},s.race=function(e){var t=this;if("[object Array]"!==Object.prototype.toString.call(e))return this.reject(new TypeError("must be an array"));var n,r=e.length,a=!1;if(!r)return this.resolve([]);for(var c=-1,u=new this(o);++c<r;)n=e[c],t.resolve(n).then((function(e){a||(a=!0,i.resolve(u,e))}),(function(e){a||(a=!0,i.reject(u,e))}));return u}},{1:1}],3:[function(e,t,r){(function(t){"function"!=typeof t.Promise&&(t.Promise=e(2))}).call(this,void 0!==n.g?n.g:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{2:2}],4:[function(e,t,n){var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};var o=function(){try{if("undefined"!=typeof indexedDB)return indexedDB;if("undefined"!=typeof webkitIndexedDB)return webkitIndexedDB;if("undefined"!=typeof mozIndexedDB)return mozIndexedDB;if("undefined"!=typeof OIndexedDB)return OIndexedDB;if("undefined"!=typeof msIndexedDB)return msIndexedDB}catch(e){return}}();function i(e,t){e=e||[],t=t||{};try{return new Blob(e,t)}catch(o){if("TypeError"!==o.name)throw o;for(var n=new("undefined"!=typeof BlobBuilder?BlobBuilder:"undefined"!=typeof MSBlobBuilder?MSBlobBuilder:"undefined"!=typeof MozBlobBuilder?MozBlobBuilder:WebKitBlobBuilder),r=0;r<e.length;r+=1)n.append(e[r]);return n.getBlob(t.type)}}"undefined"==typeof Promise&&e(3);var a=Promise;function c(e,t){t&&e.then((function(e){t(null,e)}),(function(e){t(e)}))}function u(e,t,n){"function"==typeof t&&e.then(t),"function"==typeof n&&e.catch(n)}function s(e){return"string"!=typeof e&&(console.warn(e+" used as a key, but it is not a string."),e=String(e)),e}function f(){if(arguments.length&&"function"==typeof arguments[arguments.length-1])return arguments[arguments.length-1]}var l="local-forage-detect-blob-support",d=void 0,v={},h=Object.prototype.toString,p="readonly",y="readwrite";function g(e){for(var t=e.length,n=new ArrayBuffer(t),r=new Uint8Array(n),o=0;o<t;o++)r[o]=e.charCodeAt(o);return n}function m(e){return"boolean"==typeof d?a.resolve(d):function(e){return new a((function(t){var n=e.transaction(l,y),r=i([""]);n.objectStore(l).put(r,"key"),n.onabort=function(e){e.preventDefault(),e.stopPropagation(),t(!1)},n.oncomplete=function(){var e=navigator.userAgent.match(/Chrome\/(\d+)/),n=navigator.userAgent.match(/Edge\//);t(n||!e||parseInt(e[1],10)>=43)}})).catch((function(){return!1}))}(e).then((function(e){return d=e}))}function b(e){var t=v[e.name],n={};n.promise=new a((function(e,t){n.resolve=e,n.reject=t})),t.deferredOperations.push(n),t.dbReady?t.dbReady=t.dbReady.then((function(){return n.promise})):t.dbReady=n.promise}function E(e){var t=v[e.name].deferredOperations.pop();if(t)return t.resolve(),t.promise}function _(e,t){var n=v[e.name].deferredOperations.pop();if(n)return n.reject(t),n.promise}function w(e,t){return new a((function(n,r){if(v[e.name]=v[e.name]||{forages:[],db:null,dbReady:null,deferredOperations:[]},e.db){if(!t)return n(e.db);b(e),e.db.close()}var i=[e.name];t&&i.push(e.version);var a=o.open.apply(o,i);t&&(a.onupgradeneeded=function(t){var n=a.result;try{n.createObjectStore(e.storeName),t.oldVersion<=1&&n.createObjectStore(l)}catch(n){if("ConstraintError"!==n.name)throw n;console.warn('The database "'+e.name+'" has been upgraded from version '+t.oldVersion+" to version "+t.newVersion+', but the storage "'+e.storeName+'" already exists.')}}),a.onerror=function(e){e.preventDefault(),r(a.error)},a.onsuccess=function(){n(a.result),E(e)}}))}function S(e){return w(e,!1)}function R(e){return w(e,!0)}function O(e,t){if(!e.db)return!0;var n=!e.db.objectStoreNames.contains(e.storeName),r=e.version<e.db.version,o=e.version>e.db.version;if(r&&(e.version!==t&&console.warn('The database "'+e.name+"\" can't be downgraded from version "+e.db.version+" to version "+e.version+"."),e.version=e.db.version),o||n){if(n){var i=e.db.version+1;i>e.version&&(e.version=i)}return!0}return!1}function I(e){return i([g(atob(e.data))],{type:e.type})}function C(e){return e&&e.__local_forage_encoded_blob}function T(e){var t=this,n=t._initReady().then((function(){var e=v[t._dbInfo.name];if(e&&e.dbReady)return e.dbReady}));return u(n,e,e),n}function A(e,t,n,r){void 0===r&&(r=1);try{var o=e.db.transaction(e.storeName,t);n(null,o)}catch(o){if(r>0&&(!e.db||"InvalidStateError"===o.name||"NotFoundError"===o.name))return a.resolve().then((function(){if(!e.db||"NotFoundError"===o.name&&!e.db.objectStoreNames.contains(e.storeName)&&e.version<=e.db.version)return e.db&&(e.version=e.db.version+1),R(e)})).then((function(){return function(e){b(e);for(var t=v[e.name],n=t.forages,r=0;r<n.length;r++){var o=n[r];o._dbInfo.db&&(o._dbInfo.db.close(),o._dbInfo.db=null)}return e.db=null,S(e).then((function(t){return e.db=t,O(e)?R(e):t})).then((function(r){e.db=t.db=r;for(var o=0;o<n.length;o++)n[o]._dbInfo.db=r})).catch((function(t){throw _(e,t),t}))}(e).then((function(){A(e,t,n,r-1)}))})).catch(n);n(o)}}var N={_driver:"asyncStorage",_initStorage:function(e){var t=this,n={db:null};if(e)for(var r in e)n[r]=e[r];var o=v[n.name];o||(o={forages:[],db:null,dbReady:null,deferredOperations:[]},v[n.name]=o),o.forages.push(t),t._initReady||(t._initReady=t.ready,t.ready=T);var i=[];function c(){return a.resolve()}for(var u=0;u<o.forages.length;u++){var s=o.forages[u];s!==t&&i.push(s._initReady().catch(c))}var f=o.forages.slice(0);return a.all(i).then((function(){return n.db=o.db,S(n)})).then((function(e){return n.db=e,O(n,t._defaultConfig.version)?R(n):e})).then((function(e){n.db=o.db=e,t._dbInfo=n;for(var r=0;r<f.length;r++){var i=f[r];i!==t&&(i._dbInfo.db=n.db,i._dbInfo.version=n.version)}}))},_support:function(){try{if(!o||!o.open)return!1;var e="undefined"!=typeof openDatabase&&/(Safari|iPhone|iPad|iPod)/.test(navigator.userAgent)&&!/Chrome/.test(navigator.userAgent)&&!/BlackBerry/.test(navigator.platform),t="function"==typeof fetch&&-1!==fetch.toString().indexOf("[native code");return(!e||t)&&"undefined"!=typeof indexedDB&&"undefined"!=typeof IDBKeyRange}catch(e){return!1}}(),iterate:function(e,t){var n=this,r=new a((function(t,r){n.ready().then((function(){A(n._dbInfo,p,(function(o,i){if(o)return r(o);try{var a=i.objectStore(n._dbInfo.storeName).openCursor(),c=1;a.onsuccess=function(){var n=a.result;if(n){var r=n.value;C(r)&&(r=I(r));var o=e(r,n.key,c++);void 0!==o?t(o):n.continue()}else t()},a.onerror=function(){r(a.error)}}catch(e){r(e)}}))})).catch(r)}));return c(r,t),r},getItem:function(e,t){var n=this;e=s(e);var r=new a((function(t,r){n.ready().then((function(){A(n._dbInfo,p,(function(o,i){if(o)return r(o);try{var a=i.objectStore(n._dbInfo.storeName).get(e);a.onsuccess=function(){var e=a.result;void 0===e&&(e=null),C(e)&&(e=I(e)),t(e)},a.onerror=function(){r(a.error)}}catch(e){r(e)}}))})).catch(r)}));return c(r,t),r},setItem:function(e,t,n){var r=this;e=s(e);var o=new a((function(n,o){var i;r.ready().then((function(){return i=r._dbInfo,"[object Blob]"===h.call(t)?m(i.db).then((function(e){return e?t:(n=t,new a((function(e,t){var r=new FileReader;r.onerror=t,r.onloadend=function(t){var r=btoa(t.target.result||"");e({__local_forage_encoded_blob:!0,data:r,type:n.type})},r.readAsBinaryString(n)})));var n})):t})).then((function(t){A(r._dbInfo,y,(function(i,a){if(i)return o(i);try{var c=a.objectStore(r._dbInfo.storeName);null===t&&(t=void 0);var u=c.put(t,e);a.oncomplete=function(){void 0===t&&(t=null),n(t)},a.onabort=a.onerror=function(){var e=u.error?u.error:u.transaction.error;o(e)}}catch(e){o(e)}}))})).catch(o)}));return c(o,n),o},removeItem:function(e,t){var n=this;e=s(e);var r=new a((function(t,r){n.ready().then((function(){A(n._dbInfo,y,(function(o,i){if(o)return r(o);try{var a=i.objectStore(n._dbInfo.storeName).delete(e);i.oncomplete=function(){t()},i.onerror=function(){r(a.error)},i.onabort=function(){var e=a.error?a.error:a.transaction.error;r(e)}}catch(e){r(e)}}))})).catch(r)}));return c(r,t),r},clear:function(e){var t=this,n=new a((function(e,n){t.ready().then((function(){A(t._dbInfo,y,(function(r,o){if(r)return n(r);try{var i=o.objectStore(t._dbInfo.storeName).clear();o.oncomplete=function(){e()},o.onabort=o.onerror=function(){var e=i.error?i.error:i.transaction.error;n(e)}}catch(e){n(e)}}))})).catch(n)}));return c(n,e),n},length:function(e){var t=this,n=new a((function(e,n){t.ready().then((function(){A(t._dbInfo,p,(function(r,o){if(r)return n(r);try{var i=o.objectStore(t._dbInfo.storeName).count();i.onsuccess=function(){e(i.result)},i.onerror=function(){n(i.error)}}catch(e){n(e)}}))})).catch(n)}));return c(n,e),n},key:function(e,t){var n=this,r=new a((function(t,r){e<0?t(null):n.ready().then((function(){A(n._dbInfo,p,(function(o,i){if(o)return r(o);try{var a=i.objectStore(n._dbInfo.storeName),c=!1,u=a.openKeyCursor();u.onsuccess=function(){var n=u.result;n?0===e||c?t(n.key):(c=!0,n.advance(e)):t(null)},u.onerror=function(){r(u.error)}}catch(e){r(e)}}))})).catch(r)}));return c(r,t),r},keys:function(e){var t=this,n=new a((function(e,n){t.ready().then((function(){A(t._dbInfo,p,(function(r,o){if(r)return n(r);try{var i=o.objectStore(t._dbInfo.storeName).openKeyCursor(),a=[];i.onsuccess=function(){var t=i.result;t?(a.push(t.key),t.continue()):e(a)},i.onerror=function(){n(i.error)}}catch(e){n(e)}}))})).catch(n)}));return c(n,e),n},dropInstance:function(e,t){t=f.apply(this,arguments);var n=this.config();(e="function"!=typeof e&&e||{}).name||(e.name=e.name||n.name,e.storeName=e.storeName||n.storeName);var r,i=this;if(e.name){var u=e.name===n.name&&i._dbInfo.db?a.resolve(i._dbInfo.db):S(e).then((function(t){var n=v[e.name],r=n.forages;n.db=t;for(var o=0;o<r.length;o++)r[o]._dbInfo.db=t;return t}));r=e.storeName?u.then((function(t){if(t.objectStoreNames.contains(e.storeName)){var n=t.version+1;b(e);var r=v[e.name],i=r.forages;t.close();for(var c=0;c<i.length;c++){var u=i[c];u._dbInfo.db=null,u._dbInfo.version=n}return new a((function(t,r){var i=o.open(e.name,n);i.onerror=function(e){i.result.close(),r(e)},i.onupgradeneeded=function(){i.result.deleteObjectStore(e.storeName)},i.onsuccess=function(){var e=i.result;e.close(),t(e)}})).then((function(e){r.db=e;for(var t=0;t<i.length;t++){var n=i[t];n._dbInfo.db=e,E(n._dbInfo)}})).catch((function(t){throw(_(e,t)||a.resolve()).catch((function(){})),t}))}})):u.then((function(t){b(e);var n=v[e.name],r=n.forages;t.close();for(var i=0;i<r.length;i++)r[i]._dbInfo.db=null;return new a((function(t,n){var r=o.deleteDatabase(e.name);r.onerror=r.onblocked=function(e){var t=r.result;t&&t.close(),n(e)},r.onsuccess=function(){var e=r.result;e&&e.close(),t(e)}})).then((function(e){n.db=e;for(var t=0;t<r.length;t++)E(r[t]._dbInfo)})).catch((function(t){throw(_(e,t)||a.resolve()).catch((function(){})),t}))}))}else r=a.reject("Invalid arguments");return c(r,t),r}};var j="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",P=/^~~local_forage_type~([^~]+)~/,U="__lfsc__:",k=U.length,x="arbf",L="blob",D="si08",F="ui08",M="uic8",B="si16",$="si32",V="ur16",q="ui32",K="fl32",G="fl64",Y=k+x.length,z=Object.prototype.toString;function W(e){var t,n,r,o,i,a=.75*e.length,c=e.length,u=0;"="===e[e.length-1]&&(a--,"="===e[e.length-2]&&a--);var s=new ArrayBuffer(a),f=new Uint8Array(s);for(t=0;t<c;t+=4)n=j.indexOf(e[t]),r=j.indexOf(e[t+1]),o=j.indexOf(e[t+2]),i=j.indexOf(e[t+3]),f[u++]=n<<2|r>>4,f[u++]=(15&r)<<4|o>>2,f[u++]=(3&o)<<6|63&i;return s}function H(e){var t,n=new Uint8Array(e),r="";for(t=0;t<n.length;t+=3)r+=j[n[t]>>2],r+=j[(3&n[t])<<4|n[t+1]>>4],r+=j[(15&n[t+1])<<2|n[t+2]>>6],r+=j[63&n[t+2]];return n.length%3==2?r=r.substring(0,r.length-1)+"=":n.length%3==1&&(r=r.substring(0,r.length-2)+"=="),r}var Q={serialize:function(e,t){var n="";if(e&&(n=z.call(e)),e&&("[object ArrayBuffer]"===n||e.buffer&&"[object ArrayBuffer]"===z.call(e.buffer))){var r,o=U;e instanceof ArrayBuffer?(r=e,o+=x):(r=e.buffer,"[object Int8Array]"===n?o+=D:"[object Uint8Array]"===n?o+=F:"[object Uint8ClampedArray]"===n?o+=M:"[object Int16Array]"===n?o+=B:"[object Uint16Array]"===n?o+=V:"[object Int32Array]"===n?o+=$:"[object Uint32Array]"===n?o+=q:"[object Float32Array]"===n?o+=K:"[object Float64Array]"===n?o+=G:t(new Error("Failed to get type for BinaryArray"))),t(o+H(r))}else if("[object Blob]"===n){var i=new FileReader;i.onload=function(){var n="~~local_forage_type~"+e.type+"~"+H(this.result);t("__lfsc__:blob"+n)},i.readAsArrayBuffer(e)}else try{t(JSON.stringify(e))}catch(n){console.error("Couldn't convert value into a JSON string: ",e),t(null,n)}},deserialize:function(e){if(e.substring(0,k)!==U)return JSON.parse(e);var t,n=e.substring(Y),r=e.substring(k,Y);if(r===L&&P.test(n)){var o=n.match(P);t=o[1],n=n.substring(o[0].length)}var a=W(n);switch(r){case x:return a;case L:return i([a],{type:t});case D:return new Int8Array(a);case F:return new Uint8Array(a);case M:return new Uint8ClampedArray(a);case B:return new Int16Array(a);case V:return new Uint16Array(a);case $:return new Int32Array(a);case q:return new Uint32Array(a);case K:return new Float32Array(a);case G:return new Float64Array(a);default:throw new Error("Unkown type: "+r)}},stringToBuffer:W,bufferToString:H};function J(e,t,n,r){e.executeSql("CREATE TABLE IF NOT EXISTS "+t.storeName+" (id INTEGER PRIMARY KEY, key unique, value)",[],n,r)}function X(e,t,n,r,o,i){e.executeSql(n,r,o,(function(e,a){a.code===a.SYNTAX_ERR?e.executeSql("SELECT name FROM sqlite_master WHERE type='table' AND name = ?",[t.storeName],(function(e,c){c.rows.length?i(e,a):J(e,t,(function(){e.executeSql(n,r,o,i)}),i)}),i):i(e,a)}),i)}function Z(e,t,n,r){var o=this;e=s(e);var i=new a((function(i,a){o.ready().then((function(){void 0===t&&(t=null);var c=t,u=o._dbInfo;u.serializer.serialize(t,(function(t,s){s?a(s):u.db.transaction((function(n){X(n,u,"INSERT OR REPLACE INTO "+u.storeName+" (key, value) VALUES (?, ?)",[e,t],(function(){i(c)}),(function(e,t){a(t)}))}),(function(t){if(t.code===t.QUOTA_ERR){if(r>0)return void i(Z.apply(o,[e,c,n,r-1]));a(t)}}))}))})).catch(a)}));return c(i,n),i}function ee(e){return new a((function(t,n){e.transaction((function(r){r.executeSql("SELECT name FROM sqlite_master WHERE type='table' AND name <> '__WebKitDatabaseInfoTable__'",[],(function(n,r){for(var o=[],i=0;i<r.rows.length;i++)o.push(r.rows.item(i).name);t({db:e,storeNames:o})}),(function(e,t){n(t)}))}),(function(e){n(e)}))}))}var te={_driver:"webSQLStorage",_initStorage:function(e){var t=this,n={db:null};if(e)for(var r in e)n[r]="string"!=typeof e[r]?e[r].toString():e[r];var o=new a((function(e,r){try{n.db=openDatabase(n.name,String(n.version),n.description,n.size)}catch(e){return r(e)}n.db.transaction((function(o){J(o,n,(function(){t._dbInfo=n,e()}),(function(e,t){r(t)}))}),r)}));return n.serializer=Q,o},_support:"function"==typeof openDatabase,iterate:function(e,t){var n=this,r=new a((function(t,r){n.ready().then((function(){var o=n._dbInfo;o.db.transaction((function(n){X(n,o,"SELECT * FROM "+o.storeName,[],(function(n,r){for(var i=r.rows,a=i.length,c=0;c<a;c++){var u=i.item(c),s=u.value;if(s&&(s=o.serializer.deserialize(s)),void 0!==(s=e(s,u.key,c+1)))return void t(s)}t()}),(function(e,t){r(t)}))}))})).catch(r)}));return c(r,t),r},getItem:function(e,t){var n=this;e=s(e);var r=new a((function(t,r){n.ready().then((function(){var o=n._dbInfo;o.db.transaction((function(n){X(n,o,"SELECT * FROM "+o.storeName+" WHERE key = ? LIMIT 1",[e],(function(e,n){var r=n.rows.length?n.rows.item(0).value:null;r&&(r=o.serializer.deserialize(r)),t(r)}),(function(e,t){r(t)}))}))})).catch(r)}));return c(r,t),r},setItem:function(e,t,n){return Z.apply(this,[e,t,n,1])},removeItem:function(e,t){var n=this;e=s(e);var r=new a((function(t,r){n.ready().then((function(){var o=n._dbInfo;o.db.transaction((function(n){X(n,o,"DELETE FROM "+o.storeName+" WHERE key = ?",[e],(function(){t()}),(function(e,t){r(t)}))}))})).catch(r)}));return c(r,t),r},clear:function(e){var t=this,n=new a((function(e,n){t.ready().then((function(){var r=t._dbInfo;r.db.transaction((function(t){X(t,r,"DELETE FROM "+r.storeName,[],(function(){e()}),(function(e,t){n(t)}))}))})).catch(n)}));return c(n,e),n},length:function(e){var t=this,n=new a((function(e,n){t.ready().then((function(){var r=t._dbInfo;r.db.transaction((function(t){X(t,r,"SELECT COUNT(key) as c FROM "+r.storeName,[],(function(t,n){var r=n.rows.item(0).c;e(r)}),(function(e,t){n(t)}))}))})).catch(n)}));return c(n,e),n},key:function(e,t){var n=this,r=new a((function(t,r){n.ready().then((function(){var o=n._dbInfo;o.db.transaction((function(n){X(n,o,"SELECT key FROM "+o.storeName+" WHERE id = ? LIMIT 1",[e+1],(function(e,n){var r=n.rows.length?n.rows.item(0).key:null;t(r)}),(function(e,t){r(t)}))}))})).catch(r)}));return c(r,t),r},keys:function(e){var t=this,n=new a((function(e,n){t.ready().then((function(){var r=t._dbInfo;r.db.transaction((function(t){X(t,r,"SELECT key FROM "+r.storeName,[],(function(t,n){for(var r=[],o=0;o<n.rows.length;o++)r.push(n.rows.item(o).key);e(r)}),(function(e,t){n(t)}))}))})).catch(n)}));return c(n,e),n},dropInstance:function(e,t){t=f.apply(this,arguments);var n=this.config();(e="function"!=typeof e&&e||{}).name||(e.name=e.name||n.name,e.storeName=e.storeName||n.storeName);var r,o=this;return c(r=e.name?new a((function(t){var r;r=e.name===n.name?o._dbInfo.db:openDatabase(e.name,"","",0),e.storeName?t({db:r,storeNames:[e.storeName]}):t(ee(r))})).then((function(e){return new a((function(t,n){e.db.transaction((function(r){function o(e){return new a((function(t,n){r.executeSql("DROP TABLE IF EXISTS "+e,[],(function(){t()}),(function(e,t){n(t)}))}))}for(var i=[],c=0,u=e.storeNames.length;c<u;c++)i.push(o(e.storeNames[c]));a.all(i).then((function(){t()})).catch((function(e){n(e)}))}),(function(e){n(e)}))}))})):a.reject("Invalid arguments"),t),r}};function ne(e,t){var n=e.name+"/";return e.storeName!==t.storeName&&(n+=e.storeName+"/"),n}function re(){return!function(){var e="_localforage_support_test";try{return localStorage.setItem(e,!0),localStorage.removeItem(e),!1}catch(e){return!0}}()||localStorage.length>0}var oe={_driver:"localStorageWrapper",_initStorage:function(e){var t={};if(e)for(var n in e)t[n]=e[n];return t.keyPrefix=ne(e,this._defaultConfig),re()?(this._dbInfo=t,t.serializer=Q,a.resolve()):a.reject()},_support:function(){try{return"undefined"!=typeof localStorage&&"setItem"in localStorage&&!!localStorage.setItem}catch(e){return!1}}(),iterate:function(e,t){var n=this,r=n.ready().then((function(){for(var t=n._dbInfo,r=t.keyPrefix,o=r.length,i=localStorage.length,a=1,c=0;c<i;c++){var u=localStorage.key(c);if(0===u.indexOf(r)){var s=localStorage.getItem(u);if(s&&(s=t.serializer.deserialize(s)),void 0!==(s=e(s,u.substring(o),a++)))return s}}}));return c(r,t),r},getItem:function(e,t){var n=this;e=s(e);var r=n.ready().then((function(){var t=n._dbInfo,r=localStorage.getItem(t.keyPrefix+e);return r&&(r=t.serializer.deserialize(r)),r}));return c(r,t),r},setItem:function(e,t,n){var r=this;e=s(e);var o=r.ready().then((function(){void 0===t&&(t=null);var n=t;return new a((function(o,i){var a=r._dbInfo;a.serializer.serialize(t,(function(t,r){if(r)i(r);else try{localStorage.setItem(a.keyPrefix+e,t),o(n)}catch(e){"QuotaExceededError"!==e.name&&"NS_ERROR_DOM_QUOTA_REACHED"!==e.name||i(e),i(e)}}))}))}));return c(o,n),o},removeItem:function(e,t){var n=this;e=s(e);var r=n.ready().then((function(){var t=n._dbInfo;localStorage.removeItem(t.keyPrefix+e)}));return c(r,t),r},clear:function(e){var t=this,n=t.ready().then((function(){for(var e=t._dbInfo.keyPrefix,n=localStorage.length-1;n>=0;n--){var r=localStorage.key(n);0===r.indexOf(e)&&localStorage.removeItem(r)}}));return c(n,e),n},length:function(e){var t=this.keys().then((function(e){return e.length}));return c(t,e),t},key:function(e,t){var n=this,r=n.ready().then((function(){var t,r=n._dbInfo;try{t=localStorage.key(e)}catch(e){t=null}return t&&(t=t.substring(r.keyPrefix.length)),t}));return c(r,t),r},keys:function(e){var t=this,n=t.ready().then((function(){for(var e=t._dbInfo,n=localStorage.length,r=[],o=0;o<n;o++){var i=localStorage.key(o);0===i.indexOf(e.keyPrefix)&&r.push(i.substring(e.keyPrefix.length))}return r}));return c(n,e),n},dropInstance:function(e,t){if(t=f.apply(this,arguments),!(e="function"!=typeof e&&e||{}).name){var n=this.config();e.name=e.name||n.name,e.storeName=e.storeName||n.storeName}var r,o=this;return c(r=e.name?new a((function(t){e.storeName?t(ne(e,o._defaultConfig)):t(e.name+"/")})).then((function(e){for(var t=localStorage.length-1;t>=0;t--){var n=localStorage.key(t);0===n.indexOf(e)&&localStorage.removeItem(n)}})):a.reject("Invalid arguments"),t),r}},ie=function(e,t){for(var n=e.length,r=0;r<n;){if((o=e[r])===(i=t)||"number"==typeof o&&"number"==typeof i&&isNaN(o)&&isNaN(i))return!0;r++}var o,i;return!1},ae=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)},ce={},ue={},se={INDEXEDDB:N,WEBSQL:te,LOCALSTORAGE:oe},fe=[se.INDEXEDDB._driver,se.WEBSQL._driver,se.LOCALSTORAGE._driver],le=["dropInstance"],de=["clear","getItem","iterate","key","keys","length","removeItem","setItem"].concat(le),ve={description:"",driver:fe.slice(),name:"localforage",size:4980736,storeName:"keyvaluepairs",version:1};function he(e,t){e[t]=function(){var n=arguments;return e.ready().then((function(){return e[t].apply(e,n)}))}}function pe(){for(var e=1;e<arguments.length;e++){var t=arguments[e];if(t)for(var n in t)t.hasOwnProperty(n)&&(ae(t[n])?arguments[0][n]=t[n].slice():arguments[0][n]=t[n])}return arguments[0]}var ye=new(function(){function e(t){for(var n in function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),se)if(se.hasOwnProperty(n)){var r=se[n],o=r._driver;this[n]=o,ce[o]||this.defineDriver(r)}this._defaultConfig=pe({},ve),this._config=pe({},this._defaultConfig,t),this._driverSet=null,this._initDriver=null,this._ready=!1,this._dbInfo=null,this._wrapLibraryMethodsWithReady(),this.setDriver(this._config.driver).catch((function(){}))}return e.prototype.config=function(e){if("object"===(void 0===e?"undefined":r(e))){if(this._ready)return new Error("Can't call config() after localforage has been used.");for(var t in e){if("storeName"===t&&(e[t]=e[t].replace(/\W/g,"_")),"version"===t&&"number"!=typeof e[t])return new Error("Database version must be a number.");this._config[t]=e[t]}return!("driver"in e)||!e.driver||this.setDriver(this._config.driver)}return"string"==typeof e?this._config[e]:this._config},e.prototype.defineDriver=function(e,t,n){var r=new a((function(t,n){try{var r=e._driver,o=new Error("Custom driver not compliant; see https://mozilla.github.io/localForage/#definedriver");if(!e._driver)return void n(o);for(var i=de.concat("_initStorage"),u=0,s=i.length;u<s;u++){var f=i[u];if((!ie(le,f)||e[f])&&"function"!=typeof e[f])return void n(o)}!function(){for(var t=function(e){return function(){var t=new Error("Method "+e+" is not implemented by the current driver"),n=a.reject(t);return c(n,arguments[arguments.length-1]),n}},n=0,r=le.length;n<r;n++){var o=le[n];e[o]||(e[o]=t(o))}}();var l=function(n){ce[r]&&console.info("Redefining LocalForage driver: "+r),ce[r]=e,ue[r]=n,t()};"_support"in e?e._support&&"function"==typeof e._support?e._support().then(l,n):l(!!e._support):l(!0)}catch(e){n(e)}}));return u(r,t,n),r},e.prototype.driver=function(){return this._driver||null},e.prototype.getDriver=function(e,t,n){var r=ce[e]?a.resolve(ce[e]):a.reject(new Error("Driver not found."));return u(r,t,n),r},e.prototype.getSerializer=function(e){var t=a.resolve(Q);return u(t,e),t},e.prototype.ready=function(e){var t=this,n=t._driverSet.then((function(){return null===t._ready&&(t._ready=t._initDriver()),t._ready}));return u(n,e,e),n},e.prototype.setDriver=function(e,t,n){var r=this;ae(e)||(e=[e]);var o=this._getSupportedDrivers(e);function i(){r._config.driver=r.driver()}function c(e){return r._extend(e),i(),r._ready=r._initStorage(r._config),r._ready}var s=null!==this._driverSet?this._driverSet.catch((function(){return a.resolve()})):a.resolve();return this._driverSet=s.then((function(){var e=o[0];return r._dbInfo=null,r._ready=null,r.getDriver(e).then((function(e){r._driver=e._driver,i(),r._wrapLibraryMethodsWithReady(),r._initDriver=function(e){return function(){var t=0;return function n(){for(;t<e.length;){var o=e[t];return t++,r._dbInfo=null,r._ready=null,r.getDriver(o).then(c).catch(n)}i();var u=new Error("No available storage method found.");return r._driverSet=a.reject(u),r._driverSet}()}}(o)}))})).catch((function(){i();var e=new Error("No available storage method found.");return r._driverSet=a.reject(e),r._driverSet})),u(this._driverSet,t,n),this._driverSet},e.prototype.supports=function(e){return!!ue[e]},e.prototype._extend=function(e){pe(this,e)},e.prototype._getSupportedDrivers=function(e){for(var t=[],n=0,r=e.length;n<r;n++){var o=e[n];this.supports(o)&&t.push(o)}return t},e.prototype._wrapLibraryMethodsWithReady=function(){for(var e=0,t=de.length;e<t;e++)he(this,de[e])},e.prototype.createInstance=function(t){return new e(t)},e}());t.exports=ye},{3:3}]},{},[4])(4)},36:function(e,t,n){var r=this&&this.__read||function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a},o=this&&this.__spreadArray||function(e,t){for(var n=0,r=t.length,o=e.length;n<r;n++,o++)e[o]=t[n];return e};Object.defineProperty(t,"__esModule",{value:!0}),t.AsyncContract=void 0;var i=n(888),a=n(611);t.AsyncContract=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=e.length-1,c=e.slice(0,n),u=e[n];return{enforce:function(e){return function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];if(t.length<c.length){var s="Expected "+c.length+" arguments but only received "+t.length,f=a.FAILURE.ARGUMENT_INCORRECT(s);throw new i.ValidationError(f)}for(var l=0;l<c.length;l++)c[l].check(t[l]);var d=e.apply(void 0,o([],r(t)));if(!(d instanceof Promise))throw s="Expected function to return a promise, but instead got "+d,f=a.FAILURE.RETURN_INCORRECT(s),new i.ValidationError(f);return d.then(u.check)}}}}},361:function(e,t,n){var r=this&&this.__read||function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a},o=this&&this.__spreadArray||function(e,t){for(var n=0,r=t.length,o=e.length;n<r;n++,o++)e[o]=t[n];return e};Object.defineProperty(t,"__esModule",{value:!0}),t.Contract=void 0;var i=n(888),a=n(611);t.Contract=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=e.length-1,c=e.slice(0,n),u=e[n];return{enforce:function(e){return function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];if(t.length<c.length){var s="Expected "+c.length+" arguments but only received "+t.length,f=a.FAILURE.ARGUMENT_INCORRECT(s);throw new i.ValidationError(f)}for(var l=0;l<c.length;l++)c[l].check(t[l]);return u.check(e.apply(void 0,o([],r(t))))}}}}},316:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.checked=t.check=void 0;var r=n(888),o=n(611),i=new WeakMap;function a(e,t,n){var r=i.get(e),o=r&&r.get(t);if(o)return o;for(var a=[],c=0;c<n;c++)a.push(c);return a}t.check=function(e,t,n){var r=i.get(e)||new Map;i.set(e,r);var o=r.get(t)||[];r.set(t,o),o.push(n)},t.checked=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];if(0===e.length)throw new Error("No runtype provided to `@checked`. Please remove the decorator.");return function(t,n,i){var c=i.value,u=(t.name||t.constructor.name+".prototype")+("string"==typeof n?'["'+n+'"]':"["+String(n)+"]"),s=a(t,n,e.length);if(s.length!==e.length)throw new Error("Number of `@checked` runtypes and @check parameters not matched.");if(s.length>c.length)throw new Error("Number of `@checked` runtypes exceeds actual parameter length.");i.value=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return e.forEach((function(e,n){var i=s[n],a=e.validate(t[i]);if(!a.success){var c=u+", argument #"+i+": "+a.message,f=o.FAILURE.ARGUMENT_INCORRECT(c);throw new r.ValidationError(f)}})),c.apply(this,t)}}}},888:function(e,t){var n,r=this&&this.__extends||(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)});Object.defineProperty(t,"__esModule",{value:!0}),t.ValidationError=void 0;var o=function(e){function t(n){var r=e.call(this,n.message)||this;return r.name="ValidationError",r.code=n.code,void 0!==n.details&&(r.details=n.details),Object.setPrototypeOf(r,t.prototype),r}return r(t,e),t}(Error);t.ValidationError=o},529:function(e,t,n){var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),o=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||r(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),t.InstanceOf=t.Null=t.Undefined=t.Literal=void 0,o(n(550),t),o(n(691),t),o(n(361),t),o(n(36),t),o(n(74),t),o(n(888),t),o(n(101),t),o(n(913),t),o(n(203),t);var i=n(275);Object.defineProperty(t,"Literal",{enumerable:!0,get:function(){return i.Literal}}),Object.defineProperty(t,"Undefined",{enumerable:!0,get:function(){return i.Undefined}}),Object.defineProperty(t,"Null",{enumerable:!0,get:function(){return i.Null}}),o(n(19),t),o(n(257),t),o(n(481),t),o(n(304),t),o(n(333),t),o(n(380),t),o(n(226),t),o(n(695),t),o(n(132),t),o(n(724),t),o(n(239),t),o(n(209),t),o(n(559),t);var a=n(867);Object.defineProperty(t,"InstanceOf",{enumerable:!0,get:function(){return a.InstanceOf}}),o(n(802),t),o(n(845),t),o(n(111),t),o(n(316),t)},74:function(e,t){var n=this&&this.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")},r=this&&this.__read||function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a};Object.defineProperty(t,"__esModule",{value:!0}),t.match=void 0,t.match=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return function(t){var o,i;try{for(var a=n(e),c=a.next();!c.done;c=a.next()){var u=r(c.value,2),s=u[0],f=u[1];if(s.guard(t))return f(t)}}catch(e){o={error:e}}finally{try{c&&!c.done&&(i=a.return)&&i.call(a)}finally{if(o)throw o.error}}throw new Error("No alternatives were matched")}}},550:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0})},691:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Failcode=void 0,t.Failcode={TYPE_INCORRECT:"TYPE_INCORRECT",VALUE_INCORRECT:"VALUE_INCORRECT",KEY_INCORRECT:"KEY_INCORRECT",CONTENT_INCORRECT:"CONTENT_INCORRECT",ARGUMENT_INCORRECT:"ARGUMENT_INCORRECT",RETURN_INCORRECT:"RETURN_INCORRECT",CONSTRAINT_FAILED:"CONSTRAINT_FAILED",PROPERTY_MISSING:"PROPERTY_MISSING",PROPERTY_PRESENT:"PROPERTY_PRESENT",NOTHING_EXPECTED:"NOTHING_EXPECTED"}},732:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.innerValidate=t.create=void 0;var r=n(529),o=n(233),i=n(888),a=n(611);t.create=function(e,t){return t.check=n,t.assert=n,t._innerValidate=function(n,r){return r.has(n,t)?a.SUCCESS(n):e(n,r)},t.validate=function(e){return t._innerValidate(e,(n=new WeakMap,r=function(e,t){if(null!==e&&"object"==typeof e){var r=n.get(e);n.set(e,r?r.set(t,!0):(new WeakMap).set(t,!0))}},{has:function(e,t){var o=n.get(e),i=o&&o.get(t)||!1;return r(e,t),i}}));var n,r},t.guard=function(e){return t.validate(e).success},t.Or=function(e){return r.Union(t,e)},t.And=function(e){return r.Intersect(t,e)},t.optional=function(){return r.Optional(t)},t.nullable=function(){return r.Union(t,r.Null)},t.withConstraint=function(e,n){return r.Constraint(t,e,n)},t.withGuard=function(e,n){return r.Constraint(t,e,n)},t.withBrand=function(e){return r.Brand(e,t)},t.reflect=t,t.toString=function(){return"Runtype<"+o.default(t)+">"},t;function n(e){var n=t.validate(e);if(n.success)return n.value;throw new i.ValidationError(n)}},t.innerValidate=function(e,t,n){return e._innerValidate(t,n)}},233:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});var n=function(e,t){return function(o){var i=function(t){return e?"("+t+")":t};if(t.has(o))return i("CIRCULAR "+o.tag);t.add(o);try{switch(o.tag){case"unknown":case"never":case"void":case"boolean":case"number":case"bigint":case"string":case"symbol":case"function":return o.tag;case"literal":var a=o.value;return"string"==typeof a?'"'+a+'"':String(a);case"array":return""+r(o)+n(!0,t)(o.element)+"[]";case"dictionary":return"{ [_: "+o.key+"]: "+n(!1,t)(o.value)+" }";case"record":var c=Object.keys(o.fields);return c.length?"{ "+c.map((function(e){return""+r(o)+e+(a=e,c=(i=o).isPartial,u=i.fields,(c||void 0!==a&&"optional"===u[a].tag?"?":"")+": ")+("optional"===o.fields[e].tag?n(!1,t)(o.fields[e].underlying):n(!1,t)(o.fields[e]))+";";var i,a,c,u})).join(" ")+" }":"{}";case"tuple":return"["+o.components.map(n(!1,t)).join(", ")+"]";case"union":return i(""+o.alternatives.map(n(!0,t)).join(" | "));case"intersect":return i(""+o.intersectees.map(n(!0,t)).join(" & "));case"optional":return n(e,t)(o.underlying)+" | undefined";case"constraint":return o.name||n(e,t)(o.underlying);case"instanceof":return o.ctor.name;case"brand":return n(e,t)(o.entity)}}finally{t.delete(o)}throw Error("impossible")}};function r(e){return e.isReadonly?"readonly ":""}t.default=n(!1,new Set)},380:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Array=void 0;var r=n(732),o=n(611);function i(e,t){var n,a={tag:"array",isReadonly:t,element:e};return(n=r.create((function(t,n){if(!Array.isArray(t))return o.FAILURE.TYPE_INCORRECT(a,t);var i=o.enumerableKeysOf(t),c=i.map((function(o){return r.innerValidate(e,t[o],n)})),u=i.reduce((function(e,t){var n=c[t];return n.success||(e[t]=n.details||n.message),e}),[]);return 0!==o.enumerableKeysOf(u).length?o.FAILURE.CONTENT_INCORRECT(a,u):o.SUCCESS(t)}),a)).asReadonly=function(){return i(n.element,!0)},n}t.Array=function(e){return i(e,!1)}},481:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BigInt=void 0;var r=n(732),o=n(611),i={tag:"bigint"};t.BigInt=r.create((function(e){return"bigint"==typeof e?o.SUCCESS(e):o.FAILURE.TYPE_INCORRECT(i,e)}),i)},19:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Boolean=void 0;var r=n(732),o=n(611),i={tag:"boolean"};t.Boolean=r.create((function(e){return"boolean"==typeof e?o.SUCCESS(e):o.FAILURE.TYPE_INCORRECT(i,e)}),i)},111:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Brand=void 0;var r=n(732);t.Brand=function(e,t){var n={tag:"brand",brand:e,entity:t};return r.create((function(e){return t.validate(e)}),n)}},845:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Guard=t.Constraint=void 0;var r=n(732),o=n(611),i=n(101);t.Constraint=function(e,t,n){var i=n&&n.name,a=n&&n.args,c={tag:"constraint",underlying:e,constraint:t,name:i,args:a};return r.create((function(n){var r=e.validate(n);if(!r.success)return r;var i=t(r.value);return"string"==typeof i?o.FAILURE.CONSTRAINT_FAILED(c,i):i?o.SUCCESS(r.value):o.FAILURE.CONSTRAINT_FAILED(c)}),c)},t.Guard=function(e,t){return i.Unknown.withGuard(e,t)}},132:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Dictionary=void 0;var r=n(732),o=n(304),i=n(845),a=n(233),c=n(611),u=i.Constraint(o.String,(function(e){return!isNaN(+e)}),{name:"number"});t.Dictionary=function(e,t){var i=void 0===t||"string"===t?o.String:"number"===t?u:t,s=a.default(i),f={tag:"dictionary",key:s,value:e};return r.create((function(t,o){if(null==t||"object"!=typeof t)return c.FAILURE.TYPE_INCORRECT(f,t);if(Object.getPrototypeOf(t)!==Object.prototype&&(!Array.isArray(t)||"string"===s))return c.FAILURE.TYPE_INCORRECT(f,t);var a=/^(?:NaN|-?\d+(?:\.\d+)?)$/u,u=c.enumerableKeysOf(t),l=u.reduce((function(u,s){var l="string"==typeof s&&a.test(s),d=l?n.g.Number(s):s;return(l?i.guard(d)||i.guard(s):i.guard(d))?u[s]=r.innerValidate(e,t[s],o):u[s]=c.FAILURE.KEY_INCORRECT(f,i.reflect,d),u}),{}),d=u.reduce((function(e,t){var n=l[t];return n.success||(e[t]=n.details||n.message),e}),{});return 0!==c.enumerableKeysOf(d).length?c.FAILURE.CONTENT_INCORRECT(f,d):c.SUCCESS(t)}),f)}},559:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Function=void 0;var r=n(732),o=n(611),i={tag:"function"};t.Function=r.create((function(e){return"function"==typeof e?o.SUCCESS(e):o.FAILURE.TYPE_INCORRECT(i,e)}),i)},867:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.InstanceOf=void 0;var r=n(732),o=n(611);t.InstanceOf=function(e){var t={tag:"instanceof",ctor:e};return r.create((function(n){return n instanceof e?o.SUCCESS(n):o.FAILURE.TYPE_INCORRECT(t,n)}),t)}},239:function(e,t,n){var r=this&&this.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(t,"__esModule",{value:!0}),t.Intersect=void 0;var o=n(732),i=n(611);t.Intersect=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n={tag:"intersect",intersectees:e};return o.create((function(t,n){var a,c;try{for(var u=r(e),s=u.next();!s.done;s=u.next()){var f=s.value,l=o.innerValidate(f,t,n);if(!l.success)return l}}catch(e){a={error:e}}finally{try{s&&!s.done&&(c=u.return)&&c.call(u)}finally{if(a)throw a.error}}return i.SUCCESS(t)}),n)}},802:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Lazy=void 0;var r=n(732);t.Lazy=function(e){var t,n={get tag(){return o().tag}};function o(){if(!t)for(var r in t=e())"tag"!==r&&(n[r]=t[r]);return t}return r.create((function(e){return o().validate(e)}),n)}},275:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Null=t.Undefined=t.Literal=void 0;var r=n(732),o=n(611);function i(e){return Array.isArray(e)?String(e.map(String)):"bigint"==typeof e?String(e)+"n":String(e)}function a(e){var t={tag:"literal",value:e};return r.create((function(t){return t===e?o.SUCCESS(t):o.FAILURE.VALUE_INCORRECT("literal","`"+i(e)+"`","`"+i(t)+"`")}),t)}t.Literal=a,t.Undefined=a(void 0),t.Null=a(null)},913:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Never=void 0;var r=n(732),o=n(611);t.Never=r.create(o.FAILURE.NOTHING_EXPECTED,{tag:"never"})},257:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Number=void 0;var r=n(732),o=n(611),i={tag:"number"};t.Number=r.create((function(e){return"number"==typeof e?o.SUCCESS(e):o.FAILURE.TYPE_INCORRECT(i,e)}),i)},209:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Optional=void 0;var r=n(732),o=n(611);t.Optional=function(e){var t={tag:"optional",underlying:e};return r.create((function(t){return void 0===t?o.SUCCESS(t):e.validate(t)}),t)}},695:function(e,t,n){var r=this&&this.__read||function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a},o=this&&this.__spreadArray||function(e,t){for(var n=0,r=t.length,o=e.length;n<r;n++,o++)e[o]=t[n];return e};Object.defineProperty(t,"__esModule",{value:!0}),t.Partial=t.Record=t.InternalRecord=void 0;var i=n(732),a=n(611);function c(e,t,n){var u,s={tag:"record",isPartial:t,isReadonly:n,fields:e};return(u=i.create((function(n,c){if(null==n)return a.FAILURE.TYPE_INCORRECT(s,n);var u=a.enumerableKeysOf(e);if(0!==u.length&&"object"!=typeof n)return a.FAILURE.TYPE_INCORRECT(s,n);var f=o([],r(new Set(o(o([],r(u)),r(a.enumerableKeysOf(n)))))),l=f.reduce((function(r,o){var u=a.hasKey(o,e),s=a.hasKey(o,n);if(u){var f=e[o],l=t||"optional"===f.reflect.tag;if(s){var d=n[o];r[o]=l&&void 0===d?a.SUCCESS(d):i.innerValidate(f,d,c)}else r[o]=l?a.SUCCESS(void 0):a.FAILURE.PROPERTY_MISSING(f.reflect)}else{if(!s)throw new Error("impossible");d=n[o],r[o]=a.SUCCESS(d)}return r}),{}),d=f.reduce((function(e,t){var n=l[t];return n.success||(e[t]=n.details||n.message),e}),{});return 0!==a.enumerableKeysOf(d).length?a.FAILURE.CONTENT_INCORRECT(s,d):a.SUCCESS(n)}),s)).asPartial=function(){return c(u.fields,!0,u.isReadonly)},u.asReadonly=function(){return c(u.fields,u.isPartial,!0)},u.pick=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n={};return e.forEach((function(e){n[e]=u.fields[e]})),c(n,u.isPartial,u.isReadonly)},u.omit=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n={};return a.enumerableKeysOf(u.fields).forEach((function(t){e.includes(t)||(n[t]=u.fields[t])})),c(n,u.isPartial,u.isReadonly)},u}t.InternalRecord=c,t.Record=function(e){return c(e,!1,!1)},t.Partial=function(e){return c(e,!0,!1)}},304:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.String=void 0;var r=n(732),o=n(611),i={tag:"string"};t.String=r.create((function(e){return"string"==typeof e?o.SUCCESS(e):o.FAILURE.TYPE_INCORRECT(i,e)}),i)},333:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Symbol=void 0;var r=n(732),o=n(611),i={tag:"symbol"};t.Symbol=r.create((function(e){return"symbol"==typeof e?o.SUCCESS(e):o.FAILURE.TYPE_INCORRECT(i,e)}),Object.assign((function(e){var t={tag:"symbol",key:e};return r.create((function(r){if("symbol"!=typeof r)return o.FAILURE.TYPE_INCORRECT(t,r);var i=n.g.Symbol.keyFor(r);return i!==e?o.FAILURE.VALUE_INCORRECT("symbol key",a(e),a(i)):o.SUCCESS(r)}),t)}),i));var a=function(e){return void 0===e?"undefined":'"'+e+'"'}},226:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Tuple=void 0;var r=n(732),o=n(611);t.Tuple=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n={tag:"tuple",components:e};return r.create((function(t,i){if(!Array.isArray(t))return o.FAILURE.TYPE_INCORRECT(n,t);if(t.length!==e.length)return o.FAILURE.CONSTRAINT_FAILED(n,"Expected length "+e.length+", but was "+t.length);var a=o.enumerableKeysOf(t),c=a.map((function(n){return r.innerValidate(e[n],t[n],i)})),u=a.reduce((function(e,t){var n=c[t];return n.success||(e[t]=n.details||n.message),e}),[]);return 0!==o.enumerableKeysOf(u).length?o.FAILURE.CONTENT_INCORRECT(n,u):o.SUCCESS(t)}),n)}},724:function(e,t,n){var r=this&&this.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(t,"__esModule",{value:!0}),t.Union=void 0;var o=n(732),i=n(611);t.Union=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return function(n){for(var r=0;r<e.length;r++)if(e[r].guard(n))return t[r](n)}},a={tag:"union",alternatives:e,match:n};return o.create((function(t,n){var c,u,s,f,l,d,v,h;if("object"!=typeof t||null===t){try{for(var p=r(e),y=p.next();!y.done;y=p.next()){var g=y.value;if(o.innerValidate(g,t,n).success)return i.SUCCESS(t)}}catch(e){c={error:e}}finally{try{y&&!y.done&&(u=p.return)&&u.call(p)}finally{if(c)throw c.error}}return i.FAILURE.TYPE_INCORRECT(a,t)}var m={};try{for(var b=r(e),E=b.next();!E.done;E=b.next())if("record"===(g=E.value).reflect.tag){var _=function(e){var t=g.reflect.fields[e];"literal"===t.tag&&(m[e]?m[e].every((function(e){return e!==t.value}))&&m[e].push(t.value):m[e]=[t.value])};for(var w in g.reflect.fields)_(w)}}catch(e){s={error:e}}finally{try{E&&!E.done&&(f=b.return)&&f.call(b)}finally{if(s)throw s.error}}for(var w in m)if(m[w].length===e.length)try{for(var S=(l=void 0,r(e)),R=S.next();!R.done;R=S.next())if("record"===(g=R.value).reflect.tag){var O=g.reflect.fields[w];if("literal"===O.tag&&i.hasKey(w,t)&&t[w]===O.value)return o.innerValidate(g,t,n)}}catch(e){l={error:e}}finally{try{R&&!R.done&&(d=S.return)&&d.call(S)}finally{if(l)throw l.error}}try{for(var I=r(e),C=I.next();!C.done;C=I.next()){var T=C.value;if(o.innerValidate(T,t,n).success)return i.SUCCESS(t)}}catch(e){v={error:e}}finally{try{C&&!C.done&&(h=I.return)&&h.call(I)}finally{if(v)throw v.error}}return i.FAILURE.TYPE_INCORRECT(a,t)}),a)}},101:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Unknown=void 0;var r=n(732),o=n(611);t.Unknown=r.create((function(e){return o.SUCCESS(e)}),{tag:"unknown"})},203:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Void=void 0;var r=n(101);t.Void=r.Unknown},611:function(e,t,n){var r=this&&this.__assign||function(){return(r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};Object.defineProperty(t,"__esModule",{value:!0}),t.FAILURE=t.SUCCESS=t.enumerableKeysOf=t.typeOf=t.hasKey=void 0;var o=n(691),i=n(233);t.hasKey=function(e,t){return"object"==typeof t&&null!==t&&e in t},t.typeOf=function(e){return"object"==typeof e?null===e?"null":Array.isArray(e)?"array":"Object"===e.constructor.name?"object":e.constructor.name:typeof e},t.enumerableKeysOf=function(e){return"object"==typeof e&&null!==e?Reflect.ownKeys(e).filter((function(t){var n,r;return null===(r=null===(n=e.propertyIsEnumerable)||void 0===n?void 0:n.call(e,t))||void 0===r||r})):[]},t.SUCCESS=function(e){return{success:!0,value:e}},t.FAILURE=Object.assign((function(e,t,n){return r({success:!1,code:e,message:t},n?{details:n}:{})}),{TYPE_INCORRECT:function(e,n){var r="Expected "+i.default(e)+", but was "+t.typeOf(n);return t.FAILURE(o.Failcode.TYPE_INCORRECT,r)},VALUE_INCORRECT:function(e,n,r){return t.FAILURE(o.Failcode.VALUE_INCORRECT,"Expected "+e+" "+String(n)+", but was "+String(r))},KEY_INCORRECT:function(e,n,r){return t.FAILURE(o.Failcode.KEY_INCORRECT,"Expected "+i.default(e)+" key to be "+i.default(n)+", but was "+t.typeOf(r))},CONTENT_INCORRECT:function(e,n){var r="Expected "+i.default(e)+", but was incompatible";return t.FAILURE(o.Failcode.CONTENT_INCORRECT,r,n)},ARGUMENT_INCORRECT:function(e){return t.FAILURE(o.Failcode.ARGUMENT_INCORRECT,e)},RETURN_INCORRECT:function(e){return t.FAILURE(o.Failcode.RETURN_INCORRECT,e)},CONSTRAINT_FAILED:function(e,n){var r=n?": "+n:"";return t.FAILURE(o.Failcode.CONSTRAINT_FAILED,"Failed constraint check for "+i.default(e)+r)},PROPERTY_MISSING:function(e){var n="Expected "+i.default(e)+", but was missing";return t.FAILURE(o.Failcode.PROPERTY_MISSING,n)},PROPERTY_PRESENT:function(e){var n="Expected nothing, but was "+t.typeOf(e);return t.FAILURE(o.Failcode.PROPERTY_PRESENT,n)},NOTHING_EXPECTED:function(e){var n="Expected nothing, but was "+t.typeOf(e);return t.FAILURE(o.Failcode.NOTHING_EXPECTED,n)}})},905:(e,t)=>{var n=function(e){if("object"==typeof e&&null!==e){if("function"==typeof Object.getPrototypeOf){var t=Object.getPrototypeOf(e);return t===Object.prototype||null===t}return"[object Object]"===Object.prototype.toString.call(e)}return!1},r=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return e.reduce((function(e,t){return Object.keys(t).forEach((function(o){Array.isArray(e[o])&&Array.isArray(t[o])?e[o]=Array.from(new Set(e[o].concat(t[o]))):n(e[o])&&n(t[o])?e[o]=r(e[o],t[o]):e[o]=t[o]})),e}),{})};t.Z=r}},t={};function n(r){var o=t[r];if(void 0!==o)return o.exports;var i=t[r]={exports:{}};return e[r].call(i.exports,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.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var r={};(()=>{n.d(r,{EX:()=>Xe,kS:()=>Ze,$s:()=>tt,Lk:()=>et,Hc:()=>nt,EA:()=>Je});const e=()=>window.location.hostname,t=()=>window.location.href,o=()=>e().replace(/\.[^.]+\.api\.no/,""),i=()=>{const t=(()=>{const t=/^bed-([^.]+)\.api\.no$/.exec(e()),n=/\.([^.]+)\.api\.no/.exec(e());return t?t[1]:n?n[1]:null})();let n="www.aid.no";return"localhost"===t?n="www.aid.no.localhost.api.no":t&&(n=`www-${t}.aid.no`),n};var a=function(e,t,n,r){return new(n||(n=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 t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,c)}u((r=r.apply(e,t||[])).next())}))};const c=(n,r,o)=>{!function(e,t){const n=new FormData;Object.keys(t).forEach((e=>n.append(e,t[e]))),fetch(e,{method:"POST",body:n,headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json"}}).then((e=>{if(!e.ok)throw new Error(`Error, status: ${e.status}, text: ${e.statusText}`)}))}(`//www.aid.no/api/mercury/v1/log/${n}`,Object.assign(Object.assign({},o),{message:r,url:t(),domain:e()}))},u=(e,t)=>c("error",e,t);class s extends Error{}const f={debug:console.debug,info:console.info,warn:console.warn,error:console.error};let l;var d;"undefined"!=typeof window&&(d=window,l=d);const v=(e,t)=>{l?l.addEventListener(e,(e=>{e.stopImmediatePropagation(),t.apply(l,[e])})):f.error("No root element to bind event to!")},h=(e,t)=>{l?l.addEventListener(e,(e=>{t.apply(l,[e])})):f.error("No root element to bind event to!")},p=e=>{l?l.dispatchEvent(e):f.error("No root element to dispatch event on!")};var y=n(529);const g={},m=e=>{const t=g[e];return t?(delete g[e],t):[]},b=()=>{const e="undefined"!=typeof window?window:n.g;return e.amediaUserCache||(e.amediaUserCache={})},E={get:e=>{const t=b()[e];return Promise.resolve(t)},set:(e,t,n)=>(b()[e]={key:e,data:t,expires:n},Promise.resolve()),remove:e=>(delete b()[e],Promise.resolve()),clear:()=>(("undefined"!=typeof window?window:n.g).amediaUserCache={},Promise.resolve())};const _=()=>E,w=e=>_().remove(e),S=(e,t)=>{return n=void 0,r=void 0,i=function*(){const n=yield _().get(e);if(!n)return Promise.resolve();if(Date.now()>n.expires)return w(e),Promise.resolve();try{return t.check(n.data)}catch(t){return t instanceof y.ValidationError?f.error("Failed validating data",{data:n.data,error:t.details}):f.error("Unknown error",t),w(e),Promise.resolve()}},new((o=void 0)||(o=Promise))((function(e,t){function a(e){try{u(i.next(e))}catch(e){t(e)}}function c(e){try{u(i.throw(e))}catch(e){t(e)}}function u(t){var n;t.done?e(t.value):(n=t.value,n instanceof o?n:new o((function(e){e(n)}))).then(a,c)}u((i=i.apply(n,r||[])).next())}));var n,r,o,i},R=(e,t,n)=>_().set(e,t,Date.now()+n);function O(e,t,n,r){return new Promise(((o,i)=>{((e,t)=>{g[e]||(g[e]=[]),g[e].push(t)})(e,{resolve:o,reject:i}),(e=>{var t;return(null===(t=g[e])||void 0===t?void 0:t.length)||0})(e)>1||S(e,t).then((t=>{!t||r&&!r(t)?n().then((n=>{const r=t?((e,t)=>!e||Array.isArray(t)?t:t?"object"==typeof e&&"object"==typeof t?Object.assign(Object.assign({},e),t):t:e)(t,n.data):n.data;R(e,r,n.ttl),m(e).forEach((e=>{e.resolve(n.data)}))})).catch((()=>{m(e).forEach((e=>{e.reject()}))})):m(e).forEach((e=>{e.resolve(t)}))}))}))}const I=(0,y.Record)({id:y.Number,domain:y.String}),C=(0,y.Record)({status:(0,y.Literal)("success"),access:(0,y.Union)((0,y.Literal)("granted"),(0,y.Literal)("denied")),publication:I,access_features:(0,y.Array)(y.String)}),T=(0,y.Record)({status:(0,y.Literal)("success"),cookie:y.String,access_features:(0,y.Array)(y.String)}),A=(0,y.Record)({status:(0,y.Literal)("success"),vstoken_cookie:y.String,uuid:y.String,access_features:(0,y.Array)(y.String)});var N=n(905);const j={},P={},U=(e,t)=>{j[e]=t,(e=>{var t;null===(t=P[e])||void 0===t||t.forEach((t=>t(j[e])))})(e)},k=(e,t)=>{U(e,(0,N.Z)(j[e]||{},t))},x=U,L=e=>j[e],D=(e,t)=>{P[e]||(P[e]=[]),P[e].push(t)};var F=function(e,t,n,r){return new(n||(n=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 t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,c)}u((r=r.apply(e,t||[])).next())}))};const M=(0,y.Partial)({user_uuid:y.String,user_name:y.String,tracking_key:y.String}),B=()=>fetch("/api/pluto/v1/sessions/current").then((e=>e.ok?e.json():403===e.status?{}:(f.error(`Unknown error (${e.status}: ${e.statusText}) when fetching current session`,{response:e}),Promise.reject()))).then((e=>{const t={ttl:-1,data:e};if(0===Object.keys(e).length)return t;try{return{ttl:1e4,data:M.check(e)}}catch(e){return f.error("Invalid schema",e),t}})),$=()=>F(void 0,void 0,void 0,(function*(){return O("getCurrentSession",M,B).then((e=>{return k("state",{isLoggedIn:void 0!==e.user_uuid}),{uuid:(t=e).user_uuid,name:t.user_name,trackingKey:t.tracking_key};var t}))})),V=e=>F(void 0,void 0,void 0,(function*(){return fetch(`/api/pluto/v1/sessions/current?publication_domain=${e}`,{method:"DELETE"}).then((e=>{if(!e.ok){if(403===e.status)return;throw new Error(`Error, could not perform deleteRequest. Status: ${e.status} Text: ${e.statusText}`)}k("state",{isLoggedIn:!1})}))}));let q;const K=self||window,G="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||void 0!==K.msCrypto&&"function"==typeof K.msCrypto.getRandomValues&&K.msCrypto.getRandomValues.bind(K.msCrypto);if(G){const e=new Uint8Array(16);q=function(){return G(e),e}}else{const e=new Array(16);q=function(){for(let t,n=0;n<16;n+=1)0==(3&n)&&(t=4294967296*Math.random()),e[n]=t>>>((3&n)<<3)&255;return e}}const Y=[];for(let e=0;e<256;++e)Y[e]=(e+256).toString(16).substr(1);function z(e,t){return(...n)=>{const{resolve:r,reject:o,promise:i}=function(){let e,t,n=!1;return{promise:new Promise(((r,o)=>{e=e=>{n||r(e),n=!0},t=e=>{n||o(e),n=!0}})),resolve:e,reject:t}}(),a=function(){const e=q();return e[6]=15&e[6]|64,e[8]=63&e[8]|128,function(e,t){let n=0;const r=Y;return[r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]]].join("")}(e)}(),c=new CustomEvent(`amedia-rpc-event:${e}:${t}`,{detail:{eventId:a,args:n}});if(self.dispatchEvent(c),self.amediaNativeBridge){const r=JSON.stringify(n);self.amediaNativeBridge.callNativeMethod(e,t,r,a)}return self.addEventListener(`amedia-rpc-event:${e}:${t}:${a}`,(e=>{e.detail||r();const{error:t,result:n}=e.detail;return t?o(t):r(n)})),i}}class W{constructor({version:e,component:t,methods:n=[]}){this.component=t,this.version=e,this.queue=[],n.forEach((e=>this.addMethod(e))),this.boundLiveHandler=this.liveHandler.bind(this),self.addEventListener(`amedia-rpc-event:${t}:live`,this.boundLiveHandler),setTimeout((()=>self.dispatchEvent(new CustomEvent(`amedia-rpc-event:${t}:ready`))),0)}liveHandler(e){const[t,n]=e.detail.version.split(".").map((e=>parseInt(e,10))),[r,o]=this.version.split(".").map((e=>parseInt(e,10)));if(t!==r)throw new Error(`${this.component} version mismatch. Server version: ${t}. Client version: ${r}`);n<o&&console.warn(`${this.component} server version is on an earlier minor version (${n}) than the client (${o})`);const i=this.queue.slice(0);delete this.queue,i.forEach((e=>e())),self.removeEventListener(`amedia-rpc-event:${this.component}:live`,this.boundLiveHandler)}addMethod(e){if(this[e])throw new Error(`${e} already exists on the RPC interface.`);this[e]=(...t)=>{if(this.queue){let n,r;const o=new Promise(((e,t)=>{n=e,r=t}));return this.queue.push((()=>this[e](...t).then(n).catch(r))),o}return this[e]=z(this.component,e),this[e](...t)}}}let H;const Q=(e,t)=>{const n=t.substring(e.length,t.length);return"{"===n.substring(0,1)?JSON.parse(n):"%7B"===n.substring(0,3)?JSON.parse(decodeURIComponent(n)):"undefined"!==n?""===n||"null"===n?null:n:void 0},J=e=>{const t=`${e}=`,n=document.cookie.split(";");for(let e=n.length-1;e>=0;e-=1){const r=n[e].trim();if(0===r.indexOf(t))return Q(t,r)}return null};function X(e,t,n=Date.now(),r="/",o=!1){const i=new Date;let a=`${e}=`;return t&&""!==t||(n=-1),a+=(e=>e&&""!==e?e instanceof Object?encodeURIComponent(JSON.stringify(e)):"number"==typeof e?e.toString(10):e:"")(t),a+=((e,t)=>t?t instanceof Date?`; expires=${t.toUTCString()}`:(e.setTime(e.getTime()+24*t*60*60*1e3),`; expires=${e.toUTCString()}`):"")(i,n),a+=`; path=${r}`,o&&(a+="; secure"),document.cookie=a,n&&-1!==n&&null===J(e)&&(document.cookie=a.replace(/; expires=[^;]*/,"")),a}function Z(e){X(e)}const ee=e=>{window.location.href=e};const te=()=>{return e=void 0,t=void 0,r=function*(){return Promise.all([V(o()),_().clear()]).then((()=>{(H||(H=new W({version:"1.0.0",component:"userdata-session",methods:["userAuthenticated"]}),H)).userAuthenticated(!1),Z("VSTOKEN"),Z("aid.session"),Z("aid_invitation_code"),Z("aid-reload-article"),Z("VSTOKEN2")})).catch((e=>{f.error("Failure while logging out",e)}))},new((n=void 0)||(n=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 t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,c)}u((r=r.apply(e,t||[])).next())}));var e,t,n,r},ne=()=>$(),re=()=>{var e;return!!(null===(e=L("state"))||void 0===e?void 0:e.isLoggedIn)};var oe=function(e,t,n,r){return new(n||(n=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 t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,c)}u((r=r.apply(e,t||[])).next())}))};const ie=(e=["newspaper"])=>((e,t)=>O("checkForAccess",C,(()=>fetch(`/api/jupiter/v1/check_access_for_paper/${e}/?require=any&access_features=${t.join(",")}`).then((e=>{if(!e.ok)throw new Error(`Request not ok (${e.status}: ${e.statusText}).`);return e.json()})).then((e=>{try{const t=C.check(e);return{ttl:"granted"===t.access?1e4:0,data:t}}catch(e){throw f.error("Invalid schema",e),e}})))).then((e=>({access:e.access_features}))))(o(),e),ae=e=>{try{return(e=>a(void 0,void 0,void 0,(function*(){return fetch(`/api/mercury/v2/access/activate?publication_wwwdomain=${o()}&access_features=${e.join(",")}`,{method:"post"}).then((e=>a(void 0,void 0,void 0,(function*(){let t;try{t=yield e.json()}catch(e){u("Body does not contain parsable json",e)}if(!e.ok){if(401===e.status&&"user_deactivated"===(null==t?void 0:t.status))throw new s;return!1}return"success"===(null==t?void 0:t.status)&&"granted"===(null==t?void 0:t.access)}))))})))(e)}catch(e){if(e instanceof s)return te(),Promise.resolve(!1);throw e}},ce=(e,t)=>t.filter((t=>e.includes(t))).length>0,ue=e=>oe(void 0,void 0,void 0,(function*(){const t=yield(e=>fetch(`/api/jupiter/v1/get_vstoken/${e}`,{method:"post"}).then((e=>{if(!e.ok)throw new Error(`Request not ok (${e.status}: ${e.statusText}).`);return e.json()})).then((e=>{try{return T.check(e)}catch(e){throw f.error("Invalid schema",e),e}})))(e);return"success"===t.status&&(X("VSTOKEN",t.cookie,365,"/"),!0)})),se=e=>oe(void 0,void 0,void 0,(function*(){const t=yield(e=>fetch(`/api/jupiter/v1/non_user_access/${e}`,{method:"post"}).then((e=>{if(!e.ok)throw new Error(`Request not ok (${e.status}: ${e.statusText}).`);return e.json()})).then((e=>{try{return A.check(e)}catch(e){throw f.error("Invalid schema",e),e}})))(e);return"success"===t.status&&(X("VSTOKEN2",t.vstoken_cookie,1,"/"),!0)}));var fe;!function(e){e.REQUEST_ACTIVATION="amedia-user.activation.request-activation",e.ON_ACTIVATION_COMPLETE="amedia-user.activation.on-activation-complete"}(fe||(fe={})),v(fe.REQUEST_ACTIVATION,(e=>{ae(e.detail.accessFeatures).then((e=>{p(new CustomEvent(fe.ON_ACTIVATION_COMPLETE,{detail:{hasAccess:e}}))}))}));var le=n(483),de=n(808);let ve;const he="undefined"==typeof self?window:self,pe="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||void 0!==he.msCrypto&&"function"==typeof he.msCrypto.getRandomValues&&he.msCrypto.getRandomValues.bind(he.msCrypto);if(pe){const e=new Uint8Array(16);ve=function(){return pe(e),e}}else{const e=new Array(16);ve=function(){for(let t,n=0;n<16;n+=1)0==(3&n)&&(t=4294967296*Math.random()),e[n]=t>>>((3&n)<<3)&255;return e}}const ye=[];for(let e=0;e<256;++e)ye[e]=(e+256).toString(16).substr(1);function ge(){const e=ve();return e[6]=15&e[6]|64,e[8]=63&e[8]|128,function(e,t){let n=0;const r=ye;return[r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]]].join("")}(e)}le.config({name:"aid:userdata"});const me=self.location.hostname.replace(/(.*\.)([^.]+\.\w+$)/,"$2");function be(){let e=de.get("amedia:fpbid");return e||(e=ge(),de.set("amedia:fpbid",e,{expires:3650,domain:me,sameSite:"strict"})),Promise.resolve(e)}function Ee(e){return de.set("amedia:visitid",e,{expires:new Date(Date.now()+18e5),domain:me,sameSite:"strict"}),le.setItem("visitid",e).then((()=>e))}function _e(){const e=Date.now();return Ee(`${ge()}|${e}`)}function we(){return function(){const e=de.get("amedia:visitid");return e?Promise.resolve(e):le.getItem("visitid")}().then((e=>e||_e())).then((e=>{const[t,n]=e.split("|");return!t||n&&Date.now()-18e5>n?_e():Ee(`${t}|${Date.now()}`)})).catch((e=>console.error(e)))}"undefined"!=typeof window&&["mousedown","keydown","mousemove","focus","scroll","resize","seshat-video-active","touchmove","deviceorientation"].forEach((e=>window.addEventListener(e,function(e){let t=!1;return(...n)=>{t||(e.apply(this,n),t=!0,setTimeout((()=>{t=!1}),400))}}(we))));var Se=function(e,t,n,r){return new(n||(n=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 t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,c)}u((r=r.apply(e,t||[])).next())}))};const Re=3e5,Oe=(0,y.Record)({namespaces:(0,y.Dictionary)(y.Unknown,y.String)}),Ie=(e,t="GET",n)=>fetch(e,{method:t,body:n&&JSON.stringify(n),headers:{"Content-Type":"application/json",Accept:"application/json"}}),Ce=(e,t={ignoreCache:!1})=>Se(void 0,void 0,void 0,(function*(){if(0===e.length)throw new Error("namespaces array cannot be of length 0");return O("europa",Oe,(()=>Ie(`/api/europa/v1/me/${e.join(",")}`).then((t=>t.ok?t.json():(f.error(`Could not get namespaces for: ${e}, status: ${t.status}, statusText: ${t.statusText}`,t),{namespaces:{}}))).then((e=>({ttl:Re,data:e})))),(n=>!t.ignoreCache||0===Object.keys(n.namespaces).filter((t=>!Object.keys(e).includes(t))).length)).then((e=>e.namespaces))}));const Te=(0,y.Record)({allowResearchUsage:y.Boolean,connectWithSurveys:y.Boolean,personalizedAds:y.Boolean,personalizedContent:y.Boolean}),Ae=e=>"true"===e||!0===e,Ne=(0,y.Dictionary)(y.Unknown,y.String).And((0,y.Partial)({ad_segments:y.String,ad_segments_user:y.String,amedia_employee:y.Boolean,amedia_employee_user:y.Boolean,age:y.Number,age_user:y.Number,birth_year:y.String,birth_year_user:y.String,gender:y.String,gender_user:y.String,grunnkrets:y.String,grunnkrets_user:y.String,postcode:y.String,postcode_user:y.String,shared_account:y.Boolean,shared_account_user:y.Boolean,user_grouping_number:y.String,user_grouping_number_user:y.String})),je=e=>({extraData:e}),Pe=()=>new Promise((e=>{D("state",(({isLoggedIn:t})=>{!1!==t&&!0!==t||e(t)}))})),Ue={uuid:ne,name:ne,trackingKey:ne,access:ie,extraData:()=>Promise.all([be(),Pe()]).then((([e,t])=>{var n;return((e,t,n)=>O("getNebulaInfo",Ne,(()=>((e,t,n)=>{const r=new URL("https://services.gcloud.api.no/api/nebula/v1/info");return r.searchParams.set("domain",e),r.searchParams.set("browser_id",t),n&&r.searchParams.set("user_key",n),fetch(r.href).then((e=>e.json())).then((e=>{try{return{ttl:18e6,data:Ne.check(e)}}catch(e){throw f.error("Invalid schema",e),e}}))})(e,t,n))).then(je))(window.location.hostname,e,t?null===(n=L("userAttributes"))||void 0===n?void 0:n.trackingKey:void 0)})),privacyPreferences:()=>new Promise((e=>{new Promise((e=>Pe().then((t=>{t&&e()})))).then((()=>{return(t=void 0,n=void 0,r=void 0,o=function*(){return O("privacyPreferences",Te,(()=>Ce(["privacy_preferences"]).then((e=>{const t=e.privacy_preferences;return{ttl:3e5,data:{allowResearchUsage:Ae(t.allow_research_usage),connectWithSurveys:Ae(t.connect_with_surveys),personalizedAds:Ae(t.personalized_ads),personalizedContent:Ae(t.personalized_content)}}})))).then((e=>({privacyPreferences:e})))},new(r||(r=Promise))((function(e,i){function a(e){try{u(o.next(e))}catch(e){i(e)}}function c(e){try{u(o.throw(e))}catch(e){i(e)}}function u(t){var n;t.done?e(t.value):(n=t.value,n instanceof r?n:new r((function(e){e(n)}))).then(a,c)}u((o=o.apply(t,n||[])).next())}))).then(e);var t,n,r,o}))}))};var ke;!function(e){e.REQUEST_USER_ATTRIBUTES="amedia-user.request-user-attributes",e.REQUEST_STORAGE_NAMESPACES="amedia-user.request-storage-namespaces",e.UPDATE_STORAGE="amedua-user.update-storage-namespaces",e.ON_ATTRIBUTES_UPDATED="amedia-user.on-user-attributes-updated",e.ON_STATE_UPDATED="amedia-user.on-state-updated",e.ON_STORAGE_UPDATED="amedia-user.on-storage-updated"}(ke||(ke={})),D("userAttributes",(e=>{p(new CustomEvent(ke.ON_ATTRIBUTES_UPDATED,{detail:e}))})),D("state",(e=>{p(new CustomEvent(ke.ON_STATE_UPDATED,{detail:e}))})),D("storage",(e=>{p(new CustomEvent(ke.ON_STORAGE_UPDATED,{detail:e}))})),v(ke.REQUEST_USER_ATTRIBUTES,(e=>{(e=>{const t=[];e.forEach((e=>{const n=Ue[e];n?t.includes(n)||t.push(n):f.warn("Unknown attribute was requested")}));const n=[];t.forEach((e=>{n.push(e().then((e=>{k("userAttributes",e)})).catch((t=>{f.error("Call rejected",e,t)})))})),Promise.all(n).then((()=>{}))})(e.detail)})),v(ke.REQUEST_STORAGE_NAMESPACES,(e=>{var t;t=e.detail,Ce(t).then((e=>{k("storage",e)}))})),v(ke.UPDATE_STORAGE,(e=>{var t;t=e.detail,Object.keys(t).forEach((e=>((e,t)=>Se(void 0,void 0,void 0,(function*(){const n=yield Ie(`/api/europa/v1/me/${e}`,"PATCH",t);return n.ok?((e,t)=>Se(void 0,void 0,void 0,(function*(){const n=yield S("europa",Oe),r=n?Object.assign(Object.assign({},n),{namespaces:Object.assign(Object.assign({},n.namespaces),{[e]:t})}):{namespaces:{[e]:t}};return R("europa",r,Date.now()+Re)})))(e,t):(f.error(`Could not get namespace: ${e}, status: ${n.status}, statusText: ${n.statusText}`,n),{})})))(e,t[e])))}));const xe=(e,t)=>{if(e===t)return!0;if("object"!=typeof e||"object"!=typeof t||null===e||null===t)return!1;const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(const o of n){if(!r.includes(o))return!1;if("function"==typeof e[o]||"function"==typeof t[o]){if(e[o].toString()!==t[o].toString())return!1}else if(!xe(e[o],t[o]))return!1}return!0};class Le{constructor(e,t){this.attributes=e,this.namespaces=t}withAttributes(e){return new Le([...this.attributes||[],...e],this.namespaces)}withStorage(...e){return new Le(this.attributes,[...this.namespaces||[],...e])}subscribe(e){let t=this.setupLocalCache();h(ke.ON_STATE_UPDATED,(n=>{const r=n.detail;Object.keys(t.state).length>0&&xe(t.state,r)||(t=Object.assign(Object.assign({},t),{state:r}),e(t))})),Array.isArray(this.attributes)&&this.attributes.length>0&&(h(ke.ON_ATTRIBUTES_UPDATED,(n=>{const r=this.processUserAttributesEvent(n);Object.keys(t.attributes).length>0&&xe(t.attributes,r)||(t=Object.assign(Object.assign({},t),{attributes:r}),e(t))})),p(new CustomEvent(ke.REQUEST_USER_ATTRIBUTES,{detail:this.attributes}))),Array.isArray(this.namespaces)&&this.namespaces.length>0&&(h(ke.ON_STORAGE_UPDATED,(n=>{const r=this.processStorageEvent(n);xe(t.storage,r)||(t=Object.assign(Object.assign({},t),{storage:r}),e(t))})),p(new CustomEvent(ke.REQUEST_STORAGE_NAMESPACES,{detail:this.namespaces})))}processUserAttributesEvent(e){const t=e.detail;return this.attributes.reduce(((e,n)=>(void 0!==t[n]&&(e[n]=t[n]),e)),{})}processStorageEvent(e){const t=e.detail;return this.namespaces.reduce(((e,n)=>(void 0!==t[n]&&(e[n]=t[n]),e)),{})}setupLocalCache(){const e={state:{}};return this.attributes&&this.attributes.length>0&&(e.attributes={}),this.namespaces&&this.namespaces.length>0&&(e.storage={}),e}}const De=Le;class Fe extends Error{constructor(e,t){super(e),this.code=t}}Fe.ERROR_RELOADED_NO_ACCESS="RELOADED_NO_ACCESS",Fe.ERROR_ENABLING_ACCESS_FAILED="ENABLING_ACCESS_FAILED";const Me=Fe;var Be=function(e,t,n,r){return new(n||(n=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 t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,c)}u((r=r.apply(e,t||[])).next())}))};var $e=function(e,t,n,r){return new(n||(n=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 t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,c)}u((r=r.apply(e,t||[])).next())}))};function Ve(){return $e(this,void 0,void 0,(function*(){const e=o(),t=J("VSTOKEN");let n=!1;(new De).withAttributes(["uuid"]).subscribe((({attributes:r,state:o})=>$e(this,void 0,void 0,(function*(){if(!1===o.isLoggedIn)return void("string"==typeof t&&Z("VSTOKEN"));if(!r.uuid||void 0===o.isLoggedIn||n)return;if(n=!0,"string"!=typeof t)return void(yield ue(e));const i=t.split(":"),a=new Date(1e3*parseInt(i[1],10));a.setDate(a.getDate()-1),a.getTime()>Date.now()&&i[3]===r.uuid&&e.includes(i[4])&&"jupiter"===i[5]||(yield ue(e))}))))}))}function qe(){return $e(this,void 0,void 0,(function*(){const e=o(),t=J("VSTOKEN2");if("string"!=typeof t)return void(yield se(e));const n=t.split(":"),r=new Date(1e3*parseInt(n[1],10));r.setMinutes(r.getMinutes()-30),r.getTime()>Date.now()&&e.includes(n[4])&&"jupiter"===n[5]||(yield se(e))}))}const Ke="haveTriedThirdPartyLoginCheck",Ge=(0,y.Record)({user_name:y.String,tracking_key:y.String});const Ye="have-tried-autologin",ze=[{name:"third_party",handler:function(){return e=this,t=void 0,r=function*(){return!(yield S(Ke,y.Boolean))&&(yield R(Ke,!0,36e5),!!(yield fetch(`https://${i()}/api/pluto/v1/sessions/current`,{mode:"cors",credentials:"include"}).then((e=>e.ok?e.json():(403!==e.status&&f.error(`Unknown error (${e.status}: ${e.statusText}) when fetching current session`,{response:e}),null))).then((e=>{if(!e)return null;try{return Ge.check(e)}catch(e){return f.error("Invalid schema",e),null}}))))},new((n=void 0)||(n=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 t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,c)}u((r=r.apply(e,t||[])).next())}));var e,t,n,r}}];var We=function(e,t,n,r){return new(n||(n=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 t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,c)}u((r=r.apply(e,t||[])).next())}))};const He=[()=>{return e=void 0,n=void 0,o=function*(){var e;if(!function(){try{return window.self!==window.top}catch(e){return!0}}()&&(yield $(),!(null===(e=L("state"))||void 0===e?void 0:e.isLoggedIn)&&!function(){const e=J(Ye);if(e&&"object"!=typeof e)try{if(Date.now()-parseInt(e,10)<6e4)return!0}catch(e){Z(Ye)}return X(Ye,Date.now(),Date.now()+6e4),!1}()))for(const e of ze)if(!(yield e.handler().then((n=>{if(n){const n=new URL(`https://${i()}/aid/logg_inn/auto`);return n.searchParams.set("context",`auto_login_${e.name}`),n.searchParams.set("requestedUrl",t()),ee(n.href),!1}return!0}))))return},new((r=void 0)||(r=Promise))((function(t,i){function a(e){try{u(o.next(e))}catch(e){i(e)}}function c(e){try{u(o.throw(e))}catch(e){i(e)}}function u(e){var n;e.done?t(e.value):(n=e.value,n instanceof r?n:new r((function(e){e(n)}))).then(a,c)}u((o=o.apply(e,n||[])).next())}));var e,n,r,o},function(){return Promise.all([Ve(),qe()])},function(){(new De).subscribe((({state:e})=>{!1===e.isLoggedIn&&(x("userAttributes",{}),x("storage",{}))}))}];var Qe;!function(e){e.LOADED="amedia-user.janitor.loaded"}(Qe||(Qe={}));const Je=()=>new De,Xe=e=>(e=>{const t=new URL(`https://${i()}/aid/logg_inn/${o()}/`);t.searchParams.set("requestedUrl",e instanceof URL?e.href:e),ee(t.href)})(e||t()),Ze=()=>te(),et=e=>new Promise((t=>{h(fe.ON_ACTIVATION_COMPLETE,(e=>t(e.detail))),p(new CustomEvent(fe.REQUEST_ACTIVATION,{detail:{accessFeatures:e}}))})),tt=()=>new class{constructor(){this.requestedAccessFeatures=["newspaper"],this.reload=!1}withAccessFeatures(e){return this.requestedAccessFeatures=e,this}reloadOnAccess(){return this.reload=!0,this}redirectOnAccess(e){return this.requestedUrl=e,this}tryUnlock(){return Be(this,void 0,void 0,(function*(){if((()=>{const e=J("aid-paywall-check-performed");if(!e)return!1;const n=t();return Array.isArray(e)?e.filter((e=>e===n)).length>0:e===n})())throw new Me("Unlock check already performed.",Me.ERROR_RELOADED_NO_ACCESS);return!re()&&(yield $().then((()=>!re())))?{isLoggedIn:!1,hasAccess:!1,accessFeatures:[]}:this.resolveActualAccessFeatures().then((e=>ce(e,this.requestedAccessFeatures)?this.setAccessCookiesAndPerformRequestedActions(e):{isLoggedIn:!0,hasAccess:!1,accessFeatures:e}))}))}resolveActualAccessFeatures(){return Be(this,void 0,void 0,(function*(){let e=yield ie(this.requestedAccessFeatures).then((e=>e.access||[]));if(!ce(e,this.requestedAccessFeatures)){if(!(yield ae(this.requestedAccessFeatures)))return e;e=yield ie(this.requestedAccessFeatures).then((e=>e.access||[]))}return e}))}setAccessCookiesAndPerformRequestedActions(e){return(n=o(),oe(void 0,void 0,void 0,(function*(){return ue(n)&&se(n)}))).then((n=>{if(!n)throw new Me("Could not set access cookies",Me.ERROR_ENABLING_ACCESS_FAILED);var r;return(()=>{const e=new URL(t());e.searchParams.set("access","granted");const n=new Date;n.setTime(n.getTime()+12e4),X("aid-paywall-check-performed",e.href,n)})(),this.reload&&window.location.reload(),this.requestedUrl&&(r=this.requestedUrl,window.location.replace(r)),{isLoggedIn:!0,hasAccess:!0,accessFeatures:e}}));var n}},nt=e=>p(new CustomEvent(ke.UPDATE_STORAGE,{detail:e}));"undefined"==typeof process&&We(void 0,void 0,void 0,(function*(){let e=!1;v(Qe.LOADED,(()=>{e||(e=!0,function(){We(this,void 0,void 0,(function*(){for(const e of He)yield e()}))}())})),p(new CustomEvent(Qe.LOADED))}))})();var o=r.EX,i=r.kS,a=r.$s,c=r.Lk,u=r.Hc,s=r.EA;export{o as goToLoginPage,i as logout,a as paywall,c as tryActivateSubscriptionAccess,u as updateStorage,s as user};
@@ -0,0 +1 @@
1
+ export {};
@@ -10,18 +10,14 @@ declare type StoreDataMap = {
10
10
  };
11
11
  declare type Listener<T> = (data: T) => void;
12
12
  declare const _default: {
13
+ merge: <K extends keyof StoreDataMap>(key: K, value: StoreDataMap[K]) => void;
13
14
  set: (key: keyof StoreDataMap, value: UserAttributes | State | {
14
15
  [namespace: string]: {
15
16
  [index: string]: unknown;
16
17
  };
17
18
  }) => void;
18
- replace: (key: keyof StoreDataMap, value: UserAttributes | State | {
19
- [namespace: string]: {
20
- [index: string]: unknown;
21
- };
22
- }) => void;
23
- get: <K extends keyof StoreDataMap, T = StoreDataMap[K]>(key: K) => T | undefined;
24
- on: <K_1 extends keyof StoreDataMap, T_1 = StoreDataMap[K_1]>(key: K_1, listener: Listener<T_1>) => void;
19
+ get: <K_1 extends keyof StoreDataMap, T = StoreDataMap[K_1]>(key: K_1) => T | undefined;
20
+ on: <K_2 extends keyof StoreDataMap, T_1 = StoreDataMap[K_2]>(key: K_2, listener: Listener<T_1>) => void;
25
21
  clear: () => void;
26
22
  };
27
23
  export default _default;
@@ -0,0 +1,2 @@
1
+ export declare const whenLoginStateResolved: () => Promise<boolean>;
2
+ export declare const whenIsLoggedIn: () => Promise<void>;
package/eik.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "user-js",
3
- "version": "0.12.2-esm",
3
+ "version": "0.12.12",
4
4
  "server": "https://assets.acdn.no",
5
5
  "files": {
6
6
  "user.js": "./esm/user.js",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amedia/user",
3
- "version": "0.12.10",
3
+ "version": "0.12.12",
4
4
  "description": "Client lib for working with aID user and associated data",
5
5
  "repository": "https://github.com/amedia/amedia-user-js",
6
6
  "author": "Amedia Utvikling (ID og data)",
@@ -48,7 +48,6 @@
48
48
  "rollup-plugin-peer-deps-external": "2.2.4",
49
49
  "rollup-plugin-typescript2": "0.30.0",
50
50
  "rollup-plugin-uglify": "^6.0.4",
51
- "source-map-loader": "2.0.1",
52
51
  "ts-jest": "^26.5.5",
53
52
  "ts-loader": "9.1.0",
54
53
  "tslib": "2.2.0",
@@ -3,7 +3,7 @@ import store from '../store';
3
3
 
4
4
  export const requestStorage = (namespaces: string[]) => {
5
5
  getNamespaces(namespaces).then((storage) => {
6
- store.set('storage', storage);
6
+ store.merge('storage', storage);
7
7
  });
8
8
  };
9
9
 
@@ -0,0 +1,139 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+ import fetch, { FetchMock } from 'jest-fetch-mock';
5
+ import cache from '../cache';
6
+ import store from '../store';
7
+ import { requestAttributes } from './userData';
8
+ import * as preferences from './preferences';
9
+ import * as nebula from '../clients/nebula';
10
+ import * as pluto from '../clients/pluto';
11
+ import restoreAllMocks = jest.restoreAllMocks;
12
+ import useRealTimers = jest.useRealTimers;
13
+ import useFakeTimers = jest.useFakeTimers;
14
+
15
+ describe('when fetching userData', () => {
16
+ let plutoFetchMock: FetchMock;
17
+ beforeEach(() => {
18
+ restoreAllMocks();
19
+ fetch.resetMocks();
20
+ plutoFetchMock = fetch.doMockIf('/api/pluto/v1/sessions/current');
21
+ cache.clear();
22
+ store.clear();
23
+ });
24
+
25
+ describe('when querying multiple attributes', () => {
26
+ describe('from a single source', () => {
27
+ beforeEach(async () => {
28
+ plutoFetchMock.mockOnce(
29
+ JSON.stringify({
30
+ user_uuid: '1234-123-1234',
31
+ user_name: 'Donald',
32
+ tracking_key: '4321-321-4321',
33
+ })
34
+ );
35
+ await requestAttributes(['name', 'uuid']);
36
+ });
37
+
38
+ it('should ask only once', () => {
39
+ expect(plutoFetchMock).toHaveBeenCalledTimes(1);
40
+ });
41
+
42
+ it('should have expected data in store', () => {
43
+ expect(store.get('userAttributes')).toEqual({
44
+ uuid: '1234-123-1234',
45
+ name: 'Donald',
46
+ trackingKey: '4321-321-4321',
47
+ });
48
+ });
49
+ });
50
+
51
+ describe('in quick succession', () => {
52
+ beforeEach(async () => {
53
+ plutoFetchMock.mockResponse(
54
+ JSON.stringify({
55
+ user_uuid: '1234-123-1234',
56
+ user_name: 'Donald',
57
+ tracking_key: '4321-321-4321',
58
+ })
59
+ );
60
+ await Promise.all([
61
+ requestAttributes(['name', 'uuid']),
62
+ requestAttributes(['uuid']),
63
+ requestAttributes(['name']),
64
+ requestAttributes(['name', 'uuid']),
65
+ requestAttributes(['uuid', 'name']),
66
+ ]);
67
+ });
68
+
69
+ it('should ask only once', () => {
70
+ expect(plutoFetchMock).toHaveBeenCalledTimes(1);
71
+ });
72
+
73
+ it('should have expected data in store', () => {
74
+ expect(store.get('userAttributes')).toEqual({
75
+ uuid: '1234-123-1234',
76
+ name: 'Donald',
77
+ trackingKey: '4321-321-4321',
78
+ });
79
+ });
80
+ });
81
+ });
82
+
83
+ describe('when querying for attributes that need login state to be resolved', () => {
84
+ beforeEach(() => {
85
+ useFakeTimers();
86
+ jest.spyOn(pluto, 'getCurrentSession').mockResolvedValue({});
87
+ spyOn(preferences, 'getPrivacyPreferences').and.returnValue(
88
+ Promise.resolve({})
89
+ );
90
+ spyOn(nebula, 'getInfo').and.returnValue(Promise.resolve({}));
91
+
92
+ requestAttributes(['uuid', 'extraData', 'privacyPreferences']);
93
+
94
+ expect(pluto.getCurrentSession).toHaveBeenCalled();
95
+ expect(preferences.getPrivacyPreferences).not.toHaveBeenCalled();
96
+ expect(nebula.getInfo).not.toHaveBeenCalled();
97
+ });
98
+
99
+ afterEach(() => {
100
+ useRealTimers();
101
+ });
102
+
103
+ describe('when resolves to logged in', () => {
104
+ beforeEach(() => {
105
+ store.set('state', { isLoggedIn: true });
106
+ });
107
+
108
+ it('should have called pluto', () => {
109
+ expect(pluto.getCurrentSession).toHaveBeenCalled();
110
+ });
111
+
112
+ it('should have called preferences', () => {
113
+ expect(preferences.getPrivacyPreferences).toHaveBeenCalled();
114
+ });
115
+
116
+ it('should have called nebula', () => {
117
+ expect(nebula.getInfo).toHaveBeenCalled();
118
+ });
119
+ });
120
+
121
+ describe('when resolves to guest', () => {
122
+ beforeEach(() => {
123
+ store.set('state', { isLoggedIn: false });
124
+ });
125
+
126
+ it('should have called pluto', () => {
127
+ expect(pluto.getCurrentSession).toHaveBeenCalled();
128
+ });
129
+
130
+ it('should not have called preferences', () => {
131
+ expect(preferences.getPrivacyPreferences).not.toHaveBeenCalled();
132
+ });
133
+
134
+ it('should have called nebula', () => {
135
+ expect(nebula.getInfo).toHaveBeenCalled();
136
+ });
137
+ });
138
+ });
139
+ });
@@ -1,5 +1,4 @@
1
1
  import { getBrowserId } from '@amedia/browserid';
2
- import merge from 'ts-deepmerge';
3
2
  import log from '../utils/log';
4
3
  import { UserAttributes } from '../types';
5
4
  import { getSession } from './authentication';
@@ -7,16 +6,27 @@ import { getAccess } from './authorization';
7
6
  import { getPrivacyPreferences } from './preferences';
8
7
  import store from '../store';
9
8
  import { getInfo } from '../clients/nebula';
9
+ import { whenIsLoggedIn, whenLoginStateResolved } from '../utils/loginState';
10
10
 
11
11
  const getExtraData = () =>
12
- getBrowserId().then((browserId: string) =>
12
+ Promise.all([
13
+ getBrowserId(),
14
+ whenLoginStateResolved(),
15
+ ]).then(([browserId, isLoggedIn]) =>
13
16
  getInfo(
14
17
  window.location.hostname,
15
18
  browserId,
16
- store.get('userAttributes')?.trackingKey
19
+ isLoggedIn ? store.get('userAttributes')?.trackingKey : undefined
17
20
  )
18
21
  );
19
22
 
23
+ const getPrivacyPreferencesWhenIsLoggedIn = (): Promise<
24
+ Partial<UserAttributes>
25
+ > =>
26
+ new Promise((resolve) => {
27
+ whenIsLoggedIn().then(() => getPrivacyPreferences().then(resolve));
28
+ });
29
+
20
30
  const dataServiceMap: {
21
31
  [key in keyof UserAttributes]?: () => Promise<Partial<UserAttributes>>;
22
32
  } = {
@@ -25,7 +35,7 @@ const dataServiceMap: {
25
35
  trackingKey: getSession,
26
36
  access: getAccess,
27
37
  extraData: getExtraData,
28
- privacyPreferences: getPrivacyPreferences,
38
+ privacyPreferences: getPrivacyPreferencesWhenIsLoggedIn,
29
39
  };
30
40
 
31
41
  export const requestAttributes = (attributes: Array<keyof UserAttributes>) => {
@@ -41,20 +51,17 @@ export const requestAttributes = (attributes: Array<keyof UserAttributes>) => {
41
51
  }
42
52
  });
43
53
 
44
- while (requiredServices.length > 0) {
45
- const service = requiredServices.pop();
46
- if (service) {
54
+ const promises: Promise<void>[] = [];
55
+ requiredServices.forEach((service) => {
56
+ promises.push(
47
57
  service()
48
- // TODO we need to discuss where to do the store updates. userAttributes vs state.
49
- .then((data) =>
50
- store.set(
51
- 'userAttributes',
52
- merge(store.get('userAttributes') || {}, data)
53
- )
54
- )
58
+ .then((data) => {
59
+ store.merge('userAttributes', data);
60
+ })
55
61
  .catch((error) => {
56
62
  log.error('Call rejected', service, error);
57
- });
58
- }
59
- }
63
+ })
64
+ );
65
+ });
66
+ return Promise.all(promises).then(() => {});
60
67
  };
@@ -15,6 +15,8 @@ const InfoSchema = Dictionary(Unknown, String).And(
15
15
  Partial({
16
16
  ad_segments: String,
17
17
  ad_segments_user: String,
18
+ amedia_employee: Boolean,
19
+ amedia_employee_user: Boolean,
18
20
  age: Number,
19
21
  age_user: Number,
20
22
  birth_year: String,
@@ -41,6 +43,13 @@ const getNebulaData = (
41
43
  url.searchParams.set('domain', publicationDomain);
42
44
  url.searchParams.set('browser_id', browserId);
43
45
  if (trackingKey) {
46
+ /**
47
+ * Legacy alert!
48
+ * Tracking key (what we use to track what the user is doing) was previously called user_key. This caused confusion
49
+ * with user_uuid (which is the real user id). user_key was since renamed
50
+ * to tracking_key to
51
+ * better separate the two, but nebula still likes the old name
52
+ */
44
53
  url.searchParams.set('user_key', trackingKey);
45
54
  }
46
55
  return fetch(url.href)
@@ -67,8 +76,8 @@ const mapNebulaToUserData = (
67
76
  export const getInfo = (
68
77
  publicationDomain: string,
69
78
  browserId: string,
70
- userKey?: string
79
+ trackingKey?: string
71
80
  ): Promise<Pick<UserAttributes, 'extraData'>> =>
72
81
  getOrUpdate('getNebulaInfo', InfoSchema, () =>
73
- getNebulaData(publicationDomain, browserId, userKey)
82
+ getNebulaData(publicationDomain, browserId, trackingKey)
74
83
  ).then(mapNebulaToUserData);
@@ -1,41 +1,119 @@
1
1
  import fetch from 'jest-fetch-mock';
2
2
  import cache from '../cache';
3
+ import store from '../store';
3
4
  import { getCurrentSession, removeSession } from './pluto';
5
+ import restoreAllMocks = jest.restoreAllMocks;
4
6
 
5
7
  beforeEach(async () => {
8
+ restoreAllMocks();
6
9
  fetch.resetMocks();
7
10
  await cache.clear();
8
11
  });
9
12
 
13
+ const userUUID = '3-1-33-7';
14
+ const userName = 'Earl Hickey';
15
+ const userTrackingKey = 'some tracking key';
16
+ const plutoLoggedInResponse = {
17
+ created_at:
18
+ 'Wed Apr 28 2021 16:02:04 GMT+0200 (Central European Summer Time)',
19
+ updated_at:
20
+ 'Wed Apr 28 2021 16:02:04 GMT+0200 (Central European Summer Time)',
21
+ user_uuid: userUUID,
22
+ user_name: userName,
23
+ tracking_key: userTrackingKey,
24
+ };
25
+
10
26
  describe('Pluto service', () => {
11
- it('getCurrentSession() should return session data', async () => {
12
- const data = {
13
- created_at:
14
- 'Wed Apr 28 2021 16:02:04 GMT+0200 (Central European Summer Time)',
15
- updated_at:
16
- 'Wed Apr 28 2021 16:02:04 GMT+0200 (Central European Summer Time)',
17
- user_uuid: 'some uuid',
18
- user_name: 'Earl Hickey',
19
- tracking_key: 'some tracking key',
20
- };
21
- fetch.mockResponseOnce(JSON.stringify(data));
27
+ describe('getCurrentSession()', () => {
28
+ beforeEach(() => {
29
+ jest.spyOn(store, 'merge');
30
+ });
31
+ let currentSession;
32
+ function itShouldReturnSessionDataAndSetLoggedInTrueInState() {
33
+ it('should return session data', async () => {
34
+ expect(currentSession).toEqual({
35
+ uuid: userUUID,
36
+ name: userName,
37
+ trackingKey: userTrackingKey,
38
+ });
39
+ });
40
+ it('should merge isLoggedIn:true to state in store', () => {
41
+ expect(store.merge).toHaveBeenCalledWith('state', {
42
+ isLoggedIn: true,
43
+ });
44
+ });
45
+ }
46
+ function itShouldReturnNoSessionDataAndSetLoggedInFalseInState() {
47
+ it('should return session data', async () => {
48
+ expect(currentSession).toEqual({});
49
+ });
50
+ it('should merge isLoggedIn:true to state in store', () => {
51
+ expect(store.merge).toHaveBeenCalledWith('state', {
52
+ isLoggedIn: false,
53
+ });
54
+ });
55
+ }
22
56
 
23
- const currentSession = await getCurrentSession();
24
- expect(currentSession).toEqual({
25
- uuid: 'some uuid',
26
- name: 'Earl Hickey',
27
- trackingKey: 'some tracking key',
57
+ describe('when user is logged in ', () => {
58
+ describe('When cache is empty', () => {
59
+ beforeEach(async () => {
60
+ fetch.mockResponseOnce(JSON.stringify(plutoLoggedInResponse));
61
+ currentSession = await getCurrentSession();
62
+ });
63
+ it('should call Pluto', () => {
64
+ expect(fetch).toHaveBeenCalledTimes(1);
65
+ });
66
+ itShouldReturnSessionDataAndSetLoggedInTrueInState();
67
+ });
68
+ describe('When cache is not empty', () => {
69
+ beforeEach(async () => {
70
+ cache.set('getCurrentSession', plutoLoggedInResponse, 60000);
71
+ currentSession = await getCurrentSession();
72
+ });
73
+ it('should not call Pluto', () => {
74
+ expect(fetch).toHaveBeenCalledTimes(0);
75
+ });
76
+ itShouldReturnSessionDataAndSetLoggedInTrueInState();
77
+ });
78
+ });
79
+ describe('when user is not logged in', () => {
80
+ describe('When cache is empty', () => {
81
+ beforeEach(async () => {
82
+ fetch.mockResponseOnce(() =>
83
+ Promise.resolve({
84
+ init: { status: 403 },
85
+ body: '{"code": "session.not_found"}',
86
+ })
87
+ );
88
+ currentSession = await getCurrentSession();
89
+ });
90
+ it('should call Pluto', () => {
91
+ expect(fetch).toHaveBeenCalledTimes(1);
92
+ });
93
+ itShouldReturnNoSessionDataAndSetLoggedInFalseInState();
94
+ });
95
+ describe('When cache is not empty', () => {
96
+ beforeEach(async () => {
97
+ cache.set('getCurrentSession', {}, 60000);
98
+ currentSession = await getCurrentSession();
99
+ });
100
+ it('should not call Pluto', () => {
101
+ expect(fetch).toHaveBeenCalledTimes(0);
102
+ });
103
+ itShouldReturnNoSessionDataAndSetLoggedInFalseInState();
104
+ });
28
105
  });
29
- expect(fetch).toHaveBeenCalledTimes(1);
30
106
  });
31
107
 
32
- it('removeSession() should remove session', () => {
33
- removeSession('www.rb.no');
34
- expect(
35
- fetch
36
- ).toHaveBeenCalledWith(
37
- '/api/pluto/v1/sessions/current?publication_domain=www.rb.no',
38
- { method: 'DELETE' }
39
- );
108
+ describe('removeSession()', () => {
109
+ it('should call Plut session delete', () => {
110
+ removeSession('www.rb.no');
111
+ expect(
112
+ fetch
113
+ ).toHaveBeenCalledWith(
114
+ '/api/pluto/v1/sessions/current?publication_domain=www.rb.no',
115
+ { method: 'DELETE' }
116
+ );
117
+ });
40
118
  });
41
119
  });
@@ -23,7 +23,6 @@ const fetchCurrentSession = () =>
23
23
  .then((response) => {
24
24
  if (!response.ok) {
25
25
  if (response.status === 403) {
26
- store.set('state', { isLoggedIn: false });
27
26
  return {};
28
27
  }
29
28
  log.error(
@@ -32,7 +31,6 @@ const fetchCurrentSession = () =>
32
31
  );
33
32
  return Promise.reject();
34
33
  }
35
- store.set('state', { isLoggedIn: true });
36
34
  return response.json();
37
35
  })
38
36
  .then((json) => {
@@ -58,7 +56,12 @@ export const getCurrentSession = async (): Promise<UserAttributes> =>
58
56
  'getCurrentSession',
59
57
  ServiceSessionSchema,
60
58
  fetchCurrentSession
61
- ).then(mapSessionToUserAttributes);
59
+ ).then((currentSession) => {
60
+ store.merge('state', {
61
+ isLoggedIn: currentSession.user_uuid !== undefined,
62
+ });
63
+ return mapSessionToUserAttributes(currentSession);
64
+ });
62
65
 
63
66
  export const removeSession = async (domain: string) =>
64
67
  fetch(`/api/pluto/v1/sessions/current?publication_domain=${domain}`, {
@@ -73,5 +76,5 @@ export const removeSession = async (domain: string) =>
73
76
  `Error, could not perform deleteRequest. Status: ${res.status} Text: ${res.statusText}`
74
77
  );
75
78
  }
76
- store.set('state', { isLoggedIn: false });
79
+ store.merge('state', { isLoggedIn: false });
77
80
  });
@@ -43,7 +43,7 @@ describe('Storage', () => {
43
43
 
44
44
  it('should return storage', () => {
45
45
  jest.spyOn(storage, 'requestStorage').mockImplementation(() => {
46
- store.set('storage', {
46
+ store.merge('storage', {
47
47
  namespace: {
48
48
  key: 'value',
49
49
  },
@@ -65,7 +65,7 @@ describe('Storage', () => {
65
65
 
66
66
  it('should return multiple namespaces if requested (but only requested)', () => {
67
67
  jest.spyOn(storage, 'requestStorage').mockImplementation(() => {
68
- store.set('storage', {
68
+ store.merge('storage', {
69
69
  one: {
70
70
  key1: 'value1',
71
71
  },
@@ -27,7 +27,8 @@ beforeEach(() => {
27
27
  describe('Public endpoint - userdata', () => {
28
28
  it('should alert about user data', () => {
29
29
  jest.spyOn(userData, 'requestAttributes').mockImplementation(() => {
30
- store.set('userAttributes', { name: 'Donald Duck' });
30
+ store.merge('userAttributes', { name: 'Donald Duck' });
31
+ return Promise.resolve();
31
32
  });
32
33
 
33
34
  const onUserUpdate = jest.fn();
@@ -41,9 +42,35 @@ describe('Public endpoint - userdata', () => {
41
42
  });
42
43
  });
43
44
 
45
+ it('should update with more data', () => {
46
+ jest.spyOn(userData, 'requestAttributes').mockImplementation(() => {
47
+ store.merge('userAttributes', { name: 'Donald Duck' });
48
+ store.merge('userAttributes', { uuid: '1234-123-1234' });
49
+ return Promise.resolve();
50
+ });
51
+
52
+ const onUserUpdate = jest.fn();
53
+ new User().withAttributes(['name', 'uuid']).subscribe(onUserUpdate);
54
+
55
+ expect(onUserUpdate).nthCalledWith(1, {
56
+ attributes: {
57
+ name: 'Donald Duck',
58
+ },
59
+ state: {},
60
+ });
61
+ expect(onUserUpdate).nthCalledWith(2, {
62
+ attributes: {
63
+ uuid: '1234-123-1234',
64
+ name: 'Donald Duck',
65
+ },
66
+ state: {},
67
+ });
68
+ });
69
+
44
70
  it('should not alert on same data', () => {
45
71
  jest.spyOn(userData, 'requestAttributes').mockImplementation(() => {
46
- store.set('userAttributes', { name: 'Donald Duck' });
72
+ store.merge('userAttributes', { name: 'Donald Duck' });
73
+ return Promise.resolve();
47
74
  });
48
75
 
49
76
  const onUserUpdate1 = jest.fn();
@@ -73,10 +100,12 @@ describe('Public endpoint - userdata', () => {
73
100
  jest
74
101
  .spyOn(userData, 'requestAttributes')
75
102
  .mockImplementationOnce(() => {
76
- store.set('userAttributes', { name: undefined });
103
+ store.merge('userAttributes', { name: undefined });
104
+ return Promise.resolve();
77
105
  })
78
106
  .mockImplementationOnce(() => {
79
- store.set('userAttributes', { name: 'Donald Duck' });
107
+ store.merge('userAttributes', { name: 'Donald Duck' });
108
+ return Promise.resolve();
80
109
  });
81
110
 
82
111
  const firstOnUserUpdate = jest.fn();
@@ -105,10 +134,11 @@ describe('Public endpoint - userdata', () => {
105
134
 
106
135
  it('should not return more data that requested', () => {
107
136
  jest.spyOn(userData, 'requestAttributes').mockImplementation(() => {
108
- store.set('userAttributes', {
137
+ store.merge('userAttributes', {
109
138
  name: 'Donald Duck',
110
139
  email: 'donald.duck@andeby.no',
111
140
  });
141
+ return Promise.resolve();
112
142
  });
113
143
 
114
144
  const onUserUpdate = jest.fn();
@@ -124,10 +154,11 @@ describe('Public endpoint - userdata', () => {
124
154
 
125
155
  it('should support returning multiple requested attributes', () => {
126
156
  jest.spyOn(userData, 'requestAttributes').mockImplementation(() => {
127
- store.set('userAttributes', {
157
+ store.merge('userAttributes', {
128
158
  name: 'Donald Duck',
129
159
  email: 'donald.duck@andeby.no',
130
160
  });
161
+ return Promise.resolve();
131
162
  });
132
163
 
133
164
  const onUserUpdate = jest.fn();
@@ -144,10 +175,11 @@ describe('Public endpoint - userdata', () => {
144
175
 
145
176
  it('should support requesting different attributes', () => {
146
177
  jest.spyOn(userData, 'requestAttributes').mockImplementation(() => {
147
- store.set('userAttributes', {
178
+ store.merge('userAttributes', {
148
179
  name: 'Donald Duck',
149
180
  email: 'donald.duck@andeby.no',
150
181
  });
182
+ return Promise.resolve();
151
183
  });
152
184
 
153
185
  const firstOnUserUpdate = jest.fn();
@@ -176,10 +208,11 @@ describe('Public endpoint - userdata', () => {
176
208
 
177
209
  it('should also report state changes', () => {
178
210
  jest.spyOn(userData, 'requestAttributes').mockImplementation(() => {
179
- store.set('userAttributes', {
211
+ store.merge('userAttributes', {
180
212
  name: 'Donald Duck',
181
213
  });
182
- store.set('state', { isLoggedIn: true });
214
+ store.merge('state', { isLoggedIn: true });
215
+ return Promise.resolve();
183
216
  });
184
217
 
185
218
  const onUpdate = jest.fn();
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+ import store from '../../store';
5
+ import { removeUserStorage } from './removeUserStorage';
6
+ import restoreAllMocks = jest.restoreAllMocks;
7
+
8
+ describe('removeUserStorage', () => {
9
+ beforeEach(() => {
10
+ restoreAllMocks();
11
+ spyOn(store, 'set').and.callThrough();
12
+ removeUserStorage();
13
+ });
14
+
15
+ describe('when not logged in', () => {
16
+ beforeEach(() => {
17
+ store.set('state', { isLoggedIn: true });
18
+ });
19
+
20
+ it('should not reset stores', () => {
21
+ expect(store.set).not.toHaveBeenCalledWith('userAttributes', {});
22
+ expect(store.set).not.toHaveBeenCalledWith('storage', {});
23
+ });
24
+ });
25
+
26
+ describe('when not logged in', () => {
27
+ beforeEach(() => {
28
+ store.set('state', { isLoggedIn: false });
29
+ });
30
+
31
+ it('should reset stores', () => {
32
+ expect(store.set).toHaveBeenCalledWith('userAttributes', {});
33
+ expect(store.set).toHaveBeenCalledWith('storage', {});
34
+ });
35
+ });
36
+ });
@@ -4,8 +4,8 @@ import store from '../../store';
4
4
  export function removeUserStorage() {
5
5
  new User().subscribe(({ state }) => {
6
6
  if (state.isLoggedIn === false) {
7
- store.replace('userAttributes', {});
8
- store.replace('storage', {});
7
+ store.set('userAttributes', {});
8
+ store.set('storage', {});
9
9
  }
10
10
  });
11
11
  }
@@ -6,13 +6,13 @@ beforeEach(() => {
6
6
 
7
7
  describe('Store', () => {
8
8
  it('should set in store', () => {
9
- store.set('userAttributes', { access: ['newspaper'] });
9
+ store.merge('userAttributes', { access: ['newspaper'] });
10
10
  expect(store.get('userAttributes')).toEqual({ access: ['newspaper'] });
11
11
  });
12
12
 
13
13
  it('should append in store', () => {
14
- store.set('userAttributes', { access: ['newspaper'] });
15
- store.set('userAttributes', { name: 'foo' });
14
+ store.merge('userAttributes', { access: ['newspaper'] });
15
+ store.merge('userAttributes', { name: 'foo' });
16
16
  expect(store.get('userAttributes')).toEqual({
17
17
  name: 'foo',
18
18
  access: ['newspaper'],
@@ -20,8 +20,8 @@ describe('Store', () => {
20
20
  });
21
21
 
22
22
  it('should replace in store', () => {
23
- store.set('userAttributes', { access: ['newspaper'] });
24
- store.replace('userAttributes', {});
23
+ store.merge('userAttributes', { access: ['newspaper'] });
24
+ store.set('userAttributes', {});
25
25
  expect(store.get('userAttributes')).toEqual({});
26
26
  });
27
27
 
@@ -29,7 +29,7 @@ describe('Store', () => {
29
29
  const listenerSpy = jest.fn();
30
30
  store.on('userAttributes', listenerSpy);
31
31
  expect(listenerSpy).not.toHaveBeenCalled();
32
- store.set('userAttributes', { name: 'Donald' });
32
+ store.merge('userAttributes', { name: 'Donald' });
33
33
  expect(listenerSpy).toHaveBeenCalledWith({ name: 'Donald' });
34
34
  });
35
35
 
@@ -41,7 +41,7 @@ describe('Store', () => {
41
41
  store.on('userAttributes', listenerSpy2);
42
42
  store.on('state', listenerSpy3);
43
43
 
44
- store.set('userAttributes', { name: 'Donald' });
44
+ store.merge('userAttributes', { name: 'Donald' });
45
45
  expect(listenerSpy1).toHaveBeenCalledWith({ name: 'Donald' });
46
46
  expect(listenerSpy2).toHaveBeenCalledWith({ name: 'Donald' });
47
47
  expect(listenerSpy3).not.toHaveBeenCalled();
@@ -1,3 +1,4 @@
1
+ import deepmerge from 'ts-deepmerge';
1
2
  import { State, UserAttributes } from '../types';
2
3
 
3
4
  type StoreDataMap = {
@@ -32,21 +33,23 @@ const on = <K extends keyof StoreDataMap, T = StoreDataMap[K]>(
32
33
 
33
34
  const set = (key: keyof StoreDataMap, value: StoreDataMap[typeof key]) => {
34
35
  // @ts-ignore todo Not sure why this type fails.
35
- store[key] = { ...store[key], ...value };
36
+ store[key] = value;
36
37
  emit(key);
37
38
  };
38
39
 
39
- const replace = (key: keyof StoreDataMap, value: StoreDataMap[typeof key]) => {
40
- // @ts-ignore todo Not sure why this type fails.
41
- store[key] = value;
42
- emit(key);
40
+ const merge = <K extends keyof StoreDataMap>(
41
+ key: K,
42
+ value: StoreDataMap[K]
43
+ ) => {
44
+ // @ts-ignore
45
+ set(key, deepmerge(store[key] || {}, value));
43
46
  };
44
47
 
45
48
  const get = <K extends keyof StoreDataMap, T = StoreDataMap[K]>(
46
49
  key: K
50
+ ): T | undefined =>
47
51
  // @ts-ignore Not sure why this fails
48
- ): T | undefined => store[key];
49
-
52
+ store[key];
50
53
  const clear = () => {
51
54
  store.state = undefined;
52
55
  store.userAttributes = undefined;
@@ -56,4 +59,4 @@ const clear = () => {
56
59
  });
57
60
  };
58
61
 
59
- export default { set, replace, get, on, clear };
62
+ export default { merge, set, get, on, clear };
@@ -0,0 +1,17 @@
1
+ import store from '../store';
2
+
3
+ export const whenLoginStateResolved = (): Promise<boolean> =>
4
+ new Promise((resolve) => {
5
+ store.on('state', ({ isLoggedIn }) => {
6
+ if (isLoggedIn === false || isLoggedIn === true) {
7
+ resolve(isLoggedIn);
8
+ }
9
+ });
10
+ });
11
+
12
+ export const whenIsLoggedIn = (): Promise<void> =>
13
+ new Promise((resolve) =>
14
+ whenLoginStateResolved().then((isLoggedIn) => {
15
+ if (isLoggedIn) resolve();
16
+ })
17
+ );
package/webpack.config.js CHANGED
@@ -12,11 +12,6 @@ module.exports = {
12
12
  use: ['ts-loader'],
13
13
  exclude: /node_modules/,
14
14
  },
15
- {
16
- test: /\.js$/,
17
- use: ['source-map-loader'],
18
- enforce: 'pre',
19
- },
20
15
  ],
21
16
  },
22
17
  resolve: {
@@ -1,9 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <module type="WEB_MODULE" version="4">
3
- <component name="NewModuleRootManager" inherit-compiler-output="true">
4
- <exclude-output />
5
- <content url="file://$MODULE_DIR$" />
6
- <orderEntry type="inheritedJdk" />
7
- <orderEntry type="sourceFolder" forTests="false" />
8
- </component>
9
- </module>