@amedia/user 0.13.7 → 0.13.9

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,3 @@
1
1
  export declare const AUTOLOGIN_COOKIE_TTL = 60000;
2
- export declare const attemptAutologin: () => Promise<void>;
2
+ export declare const attemptAutoLoginJob: () => Promise<void>;
3
+ export declare const attemptPaywallAutoLogin: () => Promise<void>;
@@ -1,10 +1,3 @@
1
- declare const log: {
2
- error: (message: string, context: Object) => void;
3
- warn: (message: string, context: Object) => void;
4
- info: (message: string, context: Object) => void;
5
- debug: (message: string, context: Object) => void;
6
- };
7
1
  export declare class UserDeactivatedError extends Error {
8
2
  }
9
3
  export declare const activateSubscription: (accessFeatures: string[]) => Promise<string[]>;
10
- export default log;
@@ -0,0 +1,7 @@
1
+ declare const log: {
2
+ error: (message: string, context: Object) => void;
3
+ warn: (message: string, context: Object) => void;
4
+ info: (message: string, context: Object) => void;
5
+ debug: (message: string, context: Object) => void;
6
+ };
7
+ export default log;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+ export {};
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  /*! For license information please see index.js.LICENSE.txt */
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 s="";for(var c in i)i[c]&&(s+="; "+c,!0!==i[c]&&(s+="="+i[c].split(";")[0]));return document.cookie=t+"="+n+s}}function a(e,n){if("undefined"!=typeof document){for(var o={},i=document.cookie?document.cookie.split("; "):[],a=0;a<i.length;a++){var s=i[a].split("="),c=s.slice(1).join("=");n||'"'!==c.charAt(0)||(c=c.slice(1,-1));try{var u=t(s[0]);if(c=(r.read||r)(c,u)||t(c),n)try{c=JSON.parse(c)}catch(e){}if(o[u]=c,e===u)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,s){if(!n[a]){if(!t[a]){if(i)return i(a,!0);var c=new Error("Cannot find module '"+a+"'");throw c.code="MODULE_NOT_FOUND",c}var u=n[a]={exports:{}};t[a][0].call(u.exports,(function(e){return o(t[a][1][e]||e)}),u,u.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),s=e.document.createTextNode("");a.observe(s,{characterData:!0}),n=function(){s.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 c=new e.MessageChannel;c.port1.onmessage=f,n=function(){c.port2.postMessage(0)}}var u=[];function f(){var e,t;r=!0;for(var n=u.length;n;){for(t=u,u=[],e=-1;++e<n;)t[e]();n=u.length}r=!1}t.exports=function(e){1!==u.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"],s=["FULFILLED"],c=["PENDING"];function u(e){if("function"!=typeof e)throw new TypeError("resolver must be a function");this.state=c,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=u,u.prototype.catch=function(e){return this.then(null,e)},u.prototype.then=function(e,t){if("function"!=typeof e&&this.state===s||"function"!=typeof t&&this.state===a)return this;var n=new this.constructor(o);return this.state!==c?l(n,this.state===s?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=s,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},u.resolve=function(e){return e instanceof this?e:i.resolve(new this(o),e)},u.reject=function(e){var t=new this(o);return i.reject(t,e)},u.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),s=0,c=-1,u=new this(o);++c<n;)f(e[c],c);return u;function f(e,o){t.resolve(e).then((function(e){a[o]=e,++s!==n||r||(r=!0,i.resolve(u,a))}),(function(e){r||(r=!0,i.reject(u,e))}))}},u.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 s=-1,c=new this(o);++s<r;)n=e[s],t.resolve(n).then((function(e){a||(a=!0,i.resolve(c,e))}),(function(e){a||(a=!0,i.reject(c,e))}));return c}},{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 s(e,t){t&&e.then((function(e){t(null,e)}),(function(e){t(e)}))}function c(e,t,n){"function"==typeof t&&e.then(t),"function"==typeof n&&e.catch(n)}function u(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 C(e){return i([g(atob(e.data))],{type:e.type})}function T(e){return e&&e.__local_forage_encoded_blob}function I(e){var t=this,n=t._initReady().then((function(){var e=v[t._dbInfo.name];if(e&&e.dbReady)return e.dbReady}));return c(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=I);var i=[];function s(){return a.resolve()}for(var c=0;c<o.forages.length;c++){var u=o.forages[c];u!==t&&i.push(u._initReady().catch(s))}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(),s=1;a.onsuccess=function(){var n=a.result;if(n){var r=n.value;T(r)&&(r=C(r));var o=e(r,n.key,s++);void 0!==o?t(o):n.continue()}else t()},a.onerror=function(){r(a.error)}}catch(e){r(e)}}))})).catch(r)}));return s(r,t),r},getItem:function(e,t){var n=this;e=u(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),T(e)&&(e=C(e)),t(e)},a.onerror=function(){r(a.error)}}catch(e){r(e)}}))})).catch(r)}));return s(r,t),r},setItem:function(e,t,n){var r=this;e=u(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 s=a.objectStore(r._dbInfo.storeName);null===t&&(t=void 0);var c=s.put(t,e);a.oncomplete=function(){void 0===t&&(t=null),n(t)},a.onabort=a.onerror=function(){var e=c.error?c.error:c.transaction.error;o(e)}}catch(e){o(e)}}))})).catch(o)}));return s(o,n),o},removeItem:function(e,t){var n=this;e=u(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 s(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 s(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 s(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),s=!1,c=a.openKeyCursor();c.onsuccess=function(){var n=c.result;n?0===e||s?t(n.key):(s=!0,n.advance(e)):t(null)},c.onerror=function(){r(c.error)}}catch(e){r(e)}}))})).catch(r)}));return s(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 s(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 c=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?c.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 s=0;s<i.length;s++){var c=i[s];c._dbInfo.db=null,c._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}))}})):c.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 s(r,t),r}};var j="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",P=/^~~local_forage_type~([^~]+)~/,U="__lfsc__:",k=U.length,L="arbf",x="blob",F="si08",D="ui08",M="uic8",B="si16",$="si32",V="ur16",q="ui32",G="fl32",K="fl64",Y=k+L.length,z=Object.prototype.toString;function H(e){var t,n,r,o,i,a=.75*e.length,s=e.length,c=0;"="===e[e.length-1]&&(a--,"="===e[e.length-2]&&a--);var u=new ArrayBuffer(a),f=new Uint8Array(u);for(t=0;t<s;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[c++]=n<<2|r>>4,f[c++]=(15&r)<<4|o>>2,f[c++]=(3&o)<<6|63&i;return u}function W(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+=L):(r=e.buffer,"[object Int8Array]"===n?o+=F:"[object Uint8Array]"===n?o+=D:"[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+=G:"[object Float64Array]"===n?o+=K:t(new Error("Failed to get type for BinaryArray"))),t(o+W(r))}else if("[object Blob]"===n){var i=new FileReader;i.onload=function(){var n="~~local_forage_type~"+e.type+"~"+W(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===x&&P.test(n)){var o=n.match(P);t=o[1],n=n.substring(o[0].length)}var a=H(n);switch(r){case L:return a;case x:return i([a],{type:t});case F:return new Int8Array(a);case D: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 G:return new Float32Array(a);case K:return new Float64Array(a);default:throw new Error("Unkown type: "+r)}},stringToBuffer:H,bufferToString:W};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,s){s.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=u(e);var i=new a((function(i,a){o.ready().then((function(){void 0===t&&(t=null);var s=t,c=o._dbInfo;c.serializer.serialize(t,(function(t,u){u?a(u):c.db.transaction((function(n){X(n,c,"INSERT OR REPLACE INTO "+c.storeName+" (key, value) VALUES (?, ?)",[e,t],(function(){i(s)}),(function(e,t){a(t)}))}),(function(t){if(t.code===t.QUOTA_ERR){if(r>0)return void i(Z.apply(o,[e,s,n,r-1]));a(t)}}))}))})).catch(a)}));return s(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,s=0;s<a;s++){var c=i.item(s),u=c.value;if(u&&(u=o.serializer.deserialize(u)),void 0!==(u=e(u,c.key,s+1)))return void t(u)}t()}),(function(e,t){r(t)}))}))})).catch(r)}));return s(r,t),r},getItem:function(e,t){var n=this;e=u(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 s(r,t),r},setItem:function(e,t,n){return Z.apply(this,[e,t,n,1])},removeItem:function(e,t){var n=this;e=u(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 s(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 s(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 s(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 s(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 s(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 s(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=[],s=0,c=e.storeNames.length;s<c;s++)i.push(o(e.storeNames[s]));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,s=0;s<i;s++){var c=localStorage.key(s);if(0===c.indexOf(r)){var u=localStorage.getItem(c);if(u&&(u=t.serializer.deserialize(u)),void 0!==(u=e(u,c.substring(o),a++)))return u}}}));return s(r,t),r},getItem:function(e,t){var n=this;e=u(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 s(r,t),r},setItem:function(e,t,n){var r=this;e=u(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 s(o,n),o},removeItem:function(e,t){var n=this;e=u(e);var r=n.ready().then((function(){var t=n._dbInfo;localStorage.removeItem(t.keyPrefix+e)}));return s(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 s(n,e),n},length:function(e){var t=this.keys().then((function(e){return e.length}));return s(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 s(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 s(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 s(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)},se={},ce={},ue={INDEXEDDB:N,WEBSQL:te,LOCALSTORAGE:oe},fe=[ue.INDEXEDDB._driver,ue.WEBSQL._driver,ue.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),ue)if(ue.hasOwnProperty(n)){var r=ue[n],o=r._driver;this[n]=o,se[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"),c=0,u=i.length;c<u;c++){var f=i[c];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 s(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){se[r]&&console.info("Redefining LocalForage driver: "+r),se[r]=e,ce[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 c(r,t,n),r},e.prototype.driver=function(){return this._driver||null},e.prototype.getDriver=function(e,t,n){var r=se[e]?a.resolve(se[e]):a.reject(new Error("Driver not found."));return c(r,t,n),r},e.prototype.getSerializer=function(e){var t=a.resolve(Q);return c(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 c(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 s(e){return r._extend(e),i(),r._ready=r._initStorage(r._config),r._ready}var u=null!==this._driverSet?this._driverSet.catch((function(){return a.resolve()})):a.resolve();return this._driverSet=u.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(s).catch(n)}i();var c=new Error("No available storage method found.");return r._driverSet=a.reject(c),r._driverSet}()}}(o)}))})).catch((function(){i();var e=new Error("No available storage method found.");return r._driverSet=a.reject(e),r._driverSet})),c(this._driverSet,t,n),this._driverSet},e.prototype.supports=function(e){return!!ce[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,s=e.slice(0,n),c=e[n];return{enforce:function(e){return function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];if(t.length<s.length){var u="Expected "+s.length+" arguments but only received "+t.length,f=a.FAILURE.ARGUMENT_INCORRECT(u);throw new i.ValidationError(f)}for(var l=0;l<s.length;l++)s[l].check(t[l]);var d=e.apply(void 0,o([],r(t)));if(!(d instanceof Promise))throw u="Expected function to return a promise, but instead got "+d,f=a.FAILURE.RETURN_INCORRECT(u),new i.ValidationError(f);return d.then(c.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,s=e.slice(0,n),c=e[n];return{enforce:function(e){return function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];if(t.length<s.length){var u="Expected "+s.length+" arguments but only received "+t.length,f=a.FAILURE.ARGUMENT_INCORRECT(u);throw new i.ValidationError(f)}for(var l=0;l<s.length;l++)s[l].check(t[l]);return c.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=[],s=0;s<n;s++)a.push(s);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 s=i.value,c=(t.name||t.constructor.name+".prototype")+("string"==typeof n?'["'+n+'"]':"["+String(n)+"]"),u=a(t,n,e.length);if(u.length!==e.length)throw new Error("Number of `@checked` runtypes and @check parameters not matched.");if(u.length>s.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=u[n],a=e.validate(t[i]);if(!a.success){var s=c+", argument #"+i+": "+a.message,f=o.FAILURE.ARGUMENT_INCORRECT(s);throw new r.ValidationError(f)}})),s.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),s=a.next();!s.done;s=a.next()){var c=r(s.value,2),u=c[0],f=c[1];if(u.guard(t))return f(t)}}catch(e){o={error:e}}finally{try{s&&!s.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 s=Object.keys(o.fields);return s.length?"{ "+s.map((function(e){return""+r(o)+e+(a=e,s=(i=o).isPartial,c=i.fields,(s||void 0!==a&&"optional"===c[a].tag?"?":"")+": ")+("optional"===o.fields[e].tag?n(!1,t)(o.fields[e].underlying):n(!1,t)(o.fields[e]))+";";var i,a,s,c})).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),s=i.map((function(o){return r.innerValidate(e,t[o],n)})),c=i.reduce((function(e,t){var n=s[t];return n.success||(e[t]=n.details||n.message),e}),[]);return 0!==o.enumerableKeysOf(c).length?o.FAILURE.CONTENT_INCORRECT(a,c):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,s={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(s,i):i?o.SUCCESS(r.value):o.FAILURE.CONSTRAINT_FAILED(s)}),s)},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),s=n(611),c=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?c:t,u=a.default(i),f={tag:"dictionary",key:u,value:e};return r.create((function(t,o){if(null==t||"object"!=typeof t)return s.FAILURE.TYPE_INCORRECT(f,t);if(Object.getPrototypeOf(t)!==Object.prototype&&(!Array.isArray(t)||"string"===u))return s.FAILURE.TYPE_INCORRECT(f,t);var a=/^(?:NaN|-?\d+(?:\.\d+)?)$/u,c=s.enumerableKeysOf(t),l=c.reduce((function(c,u){var l="string"==typeof u&&a.test(u),d=l?n.g.Number(u):u;return(l?i.guard(d)||i.guard(u):i.guard(d))?c[u]=r.innerValidate(e,t[u],o):c[u]=s.FAILURE.KEY_INCORRECT(f,i.reflect,d),c}),{}),d=c.reduce((function(e,t){var n=l[t];return n.success||(e[t]=n.details||n.message),e}),{});return 0!==s.enumerableKeysOf(d).length?s.FAILURE.CONTENT_INCORRECT(f,d):s.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,s;try{for(var c=r(e),u=c.next();!u.done;u=c.next()){var f=u.value,l=o.innerValidate(f,t,n);if(!l.success)return l}}catch(e){a={error:e}}finally{try{u&&!u.done&&(s=c.return)&&s.call(c)}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 s(e,t,n){var c,u={tag:"record",isPartial:t,isReadonly:n,fields:e};return(c=i.create((function(n,s){if(null==n)return a.FAILURE.TYPE_INCORRECT(u,n);var c=a.enumerableKeysOf(e);if(0!==c.length&&"object"!=typeof n)return a.FAILURE.TYPE_INCORRECT(u,n);var f=o([],r(new Set(o(o([],r(c)),r(a.enumerableKeysOf(n)))))),l=f.reduce((function(r,o){var c=a.hasKey(o,e),u=a.hasKey(o,n);if(c){var f=e[o],l=t||"optional"===f.reflect.tag;if(u){var d=n[o];r[o]=l&&void 0===d?a.SUCCESS(d):i.innerValidate(f,d,s)}else r[o]=l?a.SUCCESS(void 0):a.FAILURE.PROPERTY_MISSING(f.reflect)}else{if(!u)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(u,d):a.SUCCESS(n)}),u)).asPartial=function(){return s(c.fields,!0,c.isReadonly)},c.asReadonly=function(){return s(c.fields,c.isPartial,!0)},c.pick=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n={};return e.forEach((function(e){n[e]=c.fields[e]})),s(n,c.isPartial,c.isReadonly)},c.omit=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n={};return a.enumerableKeysOf(c.fields).forEach((function(t){e.includes(t)||(n[t]=c.fields[t])})),s(n,c.isPartial,c.isReadonly)},c}t.InternalRecord=s,t.Record=function(e){return s(e,!1,!1)},t.Partial=function(e){return s(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),s=a.map((function(n){return r.innerValidate(e[n],t[n],i)})),c=a.reduce((function(e,t){var n=s[t];return n.success||(e[t]=n.details||n.message),e}),[]);return 0!==o.enumerableKeysOf(c).length?o.FAILURE.CONTENT_INCORRECT(n,c):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 s,c,u,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){s={error:e}}finally{try{y&&!y.done&&(c=p.return)&&c.call(p)}finally{if(s)throw s.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){u={error:e}}finally{try{E&&!E.done&&(f=b.return)&&f.call(b)}finally{if(u)throw u.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 C=r(e),T=C.next();!T.done;T=C.next()){var I=T.value;if(o.innerValidate(I,t,n).success)return i.SUCCESS(t)}}catch(e){v={error:e}}finally{try{T&&!T.done&&(h=C.return)&&h.call(C)}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,{Hr:()=>ut,vg:()=>Se,EX:()=>ft,kS:()=>lt,Lk:()=>dt,Hc:()=>vt});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{c(r.next(e))}catch(e){i(e)}}function s(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}c((r=r.apply(e,t||[])).next())}))};const s=(n,r,o)=>{const i={};Object.keys(o).forEach((e=>{if(["string","number","boolean"].includes(typeof o[e]))i[e]=o[e];else try{i[e]=JSON.stringify(o[e])}catch(t){i[e]=o[e]}})),function(e,t){const n=new FormData;Object.keys(t).forEach((e=>n.append(e,t[e]))),fetch(e,{method:"POST",body:n,headers:{Accept:"application/json"}}).then((e=>{if(!e.ok)throw new Error(`Error, status: ${e.status}, text: ${e.statusText}`)}))}(`/api/mercury/v1/log/${n}`,Object.assign(Object.assign({},i),{message:r,url:t(),domain:e()}))},c={error:(e,t)=>s("error",e,t),warn:(e,t)=>s("warn",e,t),info:(e,t)=>s("info",e,t),debug:(e,t)=>s("debug",e,t)};class u extends Error{}const f=c;const l=e=>{const t={message:e.message};return Object.getOwnPropertyNames(e).forEach((n=>{t[n]=e[n]})),t},d=e=>{const t={};return Object.getOwnPropertyNames(e).forEach((n=>{t[n]=e[n]})),t},v=(e,t,n)=>{((e,t={})=>{let n=e,r=t||{};if(n instanceof Error){const e=l(n);n=e.message,r=Object.assign(Object.assign({},r),{error:e})}if(r=Object.assign(Object.assign({},r),{origin:"@amedia/user"}),t instanceof Error){const e=l(t);r=Object.assign(Object.assign({},r),{[Object.keys(r).includes("error")?"contextError":"error"]:e})}else if(r instanceof Response){const e=d(r);r=Object.assign(Object.assign({},r),{response:e})}else Object.keys(r).forEach((e=>{r[e]instanceof Error?r[e]=l(r[e]):r[e]instanceof Response&&(r[e]=d(r[e]))}));return Promise.resolve({message:n,context:r})})(t,n).then((({message:t,context:n})=>f[e](t,n)))},h=(e,t)=>v("warn",e,t),p=(e,t)=>v("error",e,t);let y;var g;"undefined"!=typeof window&&(g=window,y=g);const m=(e,t)=>{y?y.addEventListener(e,(e=>{e.stopImmediatePropagation(),t.apply(y,[e])})):p("No root element to bind event to!")},b=(e,t)=>{y?y.addEventListener(e,(e=>{t.apply(y,[e])})):p("No root element to bind event to!")},E=e=>{y?y.dispatchEvent(e):p("No root element to dispatch event on!")};var _=n(529);const w={},S=e=>{const t=w[e];return t?(delete w[e],t):[]},R=()=>{const e="undefined"!=typeof window?window:n.g;return e.amediaUserCache||(e.amediaUserCache={})},O={get:e=>{const t=R()[e];return Promise.resolve(t)},set:(e,t,n)=>(R()[e]={key:e,data:t,expires:n},Promise.resolve()),remove:e=>(delete R()[e],Promise.resolve()),clear:()=>(("undefined"!=typeof window?window:n.g).amediaUserCache={},Promise.resolve())};const C=()=>O,T=e=>C().remove(e),I=(e,t)=>{return n=void 0,r=void 0,i=function*(){const n=yield C().get(e);if(!n)return Promise.resolve();if(Date.now()>n.expires)return T(e),Promise.resolve();try{return t.check(n.data)}catch(t){return p(t,{cacheData:n.data}),T(e),Promise.resolve()}},new((o=void 0)||(o=Promise))((function(e,t){function a(e){try{c(i.next(e))}catch(e){t(e)}}function s(e){try{c(i.throw(e))}catch(e){t(e)}}function c(t){var n;t.done?e(t.value):(n=t.value,n instanceof o?n:new o((function(e){e(n)}))).then(a,s)}c((i=i.apply(n,r||[])).next())}));var n,r,o,i},A=(e,t,n)=>C().set(e,t,Date.now()+n);function N(e,t,n,r){return new Promise(((o,i)=>{((e,t)=>{w[e]||(w[e]=[]),w[e].push(t)})(e,{resolve:o,reject:i}),(e=>{var t;return(null===(t=w[e])||void 0===t?void 0:t.length)||0})(e)>1||I(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;A(e,r,n.ttl),S(e).forEach((e=>{e.resolve(n.data)}))})).catch((()=>{S(e).forEach((e=>{e.reject()}))})):S(e).forEach((e=>{e.resolve(t)}))}))}))}const j=(0,_.Record)({id:_.Number,domain:_.String}),P=(0,_.Record)({status:(0,_.Literal)("success"),access:(0,_.Union)((0,_.Literal)("granted"),(0,_.Literal)("denied")),publication:j,access_features:(0,_.Array)(_.String)}),U=(0,_.Record)({status:(0,_.Literal)("success"),cookie:_.String,access_features:(0,_.Array)(_.String)}),k=(0,_.Record)({status:(0,_.Literal)("success"),vstoken_cookie:_.String,uuid:_.String,access_features:(0,_.Array)(_.String)});var L=n(905);const x={},F={},D=(e,t)=>{x[e]=t,(e=>{var t;null===(t=F[e])||void 0===t||t.forEach((t=>t(x[e])))})(e)},M=(e,t)=>{D(e,(0,L.Z)(x[e]||{},t))},B=D,$=e=>x[e],V=(e,t)=>{F[e]||(F[e]=[]),F[e].push(t)},q=["avbrutt","kansellert","cancelled","aborted","failed to fetch","abgebrochen","the operation was aborted."];var G=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{c(r.next(e))}catch(e){i(e)}}function s(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}c((r=r.apply(e,t||[])).next())}))};const K=(0,_.Partial)({user_uuid:_.String,user_name:_.String,tracking_key:_.String}),Y=(0,_.Record)({code:_.String}),z=(0,_.Record)({errors:(0,_.Array)(Y)}),H=["session.not_found","session.not_specified","user.deactivated"],W=["session.invalid_for_domain","user.not_found"],Q=e=>G(void 0,void 0,void 0,(function*(){let t;try{[t]=z.check(yield e.json()).errors}catch(t){return n=null==t?void 0:t.message,q.includes(n.toLowerCase().trim())?Promise.resolve():(p("Unable to parse error body from pluto",{error:t,response:e}),Promise.reject(t))}var n;return H.includes(null==t?void 0:t.code)?Promise.resolve():W.includes(null==t?void 0:t.code)?(h(`Pluto responded with HTTP/${e.status}: (${t.code}) while fetching current session`,{error:t,response:e}),Promise.resolve()):(p(`Pluto responded with HTTP/${e.status}: ${e.statusText}) when fetching current session`,{error:t,response:e}),Promise.reject())})),J=()=>fetch("/api/pluto/v1/sessions/current").then((e=>e.ok?e.json():Q(e).then((()=>({}))))).then((e=>{const t={ttl:-1,data:e};if(0===Object.keys(e).length)return t;try{return{ttl:1e4,data:K.check(e)}}catch(n){return p(n,{json:e}),t}})),X=e=>G(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}`)}M("state",{isLoggedIn:!1})}))}));let Z;const ee=self||window,te="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||void 0!==ee.msCrypto&&"function"==typeof ee.msCrypto.getRandomValues&&ee.msCrypto.getRandomValues.bind(ee.msCrypto);if(te){const e=new Uint8Array(16);Z=function(){return te(e),e}}else{const e=new Array(16);Z=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 ne=[];for(let e=0;e<256;++e)ne[e]=(e+256).toString(16).substr(1);function re(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=Z();return e[6]=15&e[6]|64,e[8]=63&e[8]|128,function(e,t){let n=0;const r=ne;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)}(),s=new CustomEvent(`amedia-rpc-event:${e}:${t}`,{detail:{eventId:a,args:n}});if(self.dispatchEvent(s),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 oe{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]=re(this.component,e),this[e](...t)}}}let ie;const ae=(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},se=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 ae(t,r)}return null};function ce(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===se(e)&&(document.cookie=a.replace(/; expires=[^;]*/,"")),a}function ue(e){ce(e)}const fe=e=>{window.location.href=e};const le=()=>{return e=void 0,t=void 0,r=function*(){return Promise.all([X(o()),C().clear()]).then((()=>{(ie||(ie=new oe({version:"1.0.0",component:"userdata-session",methods:["userAuthenticated"]}),ie)).userAuthenticated(!1),ue("VSTOKEN"),ue("aid.session"),ue("aid_invitation_code"),ue("aid-reload-article"),ue("VSTOKEN2")})).catch((e=>{p("Failure while logging out",e)}))},new((n=void 0)||(n=Promise))((function(o,i){function a(e){try{c(r.next(e))}catch(e){i(e)}}function s(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}c((r=r.apply(e,t||[])).next())}));var e,t,n,r},de=()=>G(void 0,void 0,void 0,(function*(){return N("getCurrentSession",K,J).then((e=>{return M("state",{isLoggedIn:void 0!==e.user_uuid}),{uuid:(t=e).user_uuid,name:t.user_name,trackingKey:t.tracking_key};var t}))}));var ve=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{c(r.next(e))}catch(e){i(e)}}function s(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}c((r=r.apply(e,t||[])).next())}))};const he=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((t=>a(void 0,void 0,void 0,(function*(){const n=yield t.text();let r;try{r=JSON.parse(n)}catch(r){c.error("Activate subscription. Response from mercury does not contain parsable json",{error:r,response:t,accessFeatures:e,body:n})}if(!t.ok){if(401===t.status&&"user_deactivated"===(null==r?void 0:r.status))throw new u;return[]}return null==r?void 0:r.access_features}))))})))(e)}catch(e){if(e instanceof u)return le(),Promise.resolve([]);throw e}},pe=(e,t)=>t.length<1||t.filter((t=>e.includes(t))).length>0,ye=e=>ve(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 U.check(e)}catch(t){throw p(t,{json:e}),t}})))(e);return"success"===t.status&&ce("VSTOKEN",t.cookie,365,"/"),{success:"success"===t.status,accessFeatures:t.access_features}})),ge=e=>ve(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 k.check(e)}catch(t){throw p(t,{json:e}),t}})))(e);return"success"===t.status&&ce("VSTOKEN2",t.vstoken_cookie,1,"/"),{success:"success"===t.status,accessFeatures:t.access_features}}));var me,be;!function(e){e.REQUEST_ACTIVATION="amedia-user.activation.request-activation",e.ON_ACTIVATION_COMPLETE="amedia-user.activation.on-activation-complete"}(me||(me={})),m(me.REQUEST_ACTIVATION,(e=>{he(e.detail.accessFeatures).then((e=>{E(new CustomEvent(me.ON_ACTIVATION_COMPLETE,{detail:{accessFeatures:e}}))}))})),function(e){e.REQUEST_STATE="amedia-user.request-state",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"}(be||(be={}));const Ee=(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(!Ee(e[o],t[o]))return!1}return!0};function _e(e,t){return!!(e&&e.length>0)&&(!(t&&Object.keys(t).length>0)||e.filter((e=>!Object.keys(t).includes(e))).length>0)}class we{constructor(e,t){this.attributes=e,this.namespaces=t}withAttributes(e){return new we([...this.attributes||[],...e],this.namespaces)}withStorage(e){return new we(this.attributes,[...this.namespaces||[],...e])}subscribe(e){let t=this.setupLocalCache();b(be.ON_STATE_UPDATED,(n=>{const r=n.detail;Object.keys(t.state).length>0&&Ee(t.state,r)||(t=Object.assign(Object.assign({},t),{state:r}),e(t))})),E(new CustomEvent(be.REQUEST_STATE)),Array.isArray(this.attributes)&&this.attributes.length>0&&(b(be.ON_ATTRIBUTES_UPDATED,(n=>{const r=this.processUserAttributesEvent(n);Object.keys(t.attributes).length>0&&Ee(t.attributes,r)||(t=Object.assign(Object.assign({},t),{attributes:r}),e(t))})),E(new CustomEvent(be.REQUEST_USER_ATTRIBUTES,{detail:this.attributes}))),Array.isArray(this.namespaces)&&this.namespaces.length>0&&(b(be.ON_STORAGE_UPDATED,(n=>{const r=this.processStorageEvent(n);Ee(t.storage,r)||(t=Object.assign(Object.assign({},t),{storage:r}),e(t))})),E(new CustomEvent(be.REQUEST_STORAGE_NAMESPACES,{detail:this.namespaces})))}fetch(){return new Promise((e=>{this.subscribe((t=>{void 0!==t.state.isLoggedIn&&(!1!==t.state.isLoggedIn&&(_e(this.attributes,t.attributes)||_e(this.namespaces,t.storage))||e(t))}))}))}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&&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 Se=we;var Re=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{c(r.next(e))}catch(e){i(e)}}function s(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}c((r=r.apply(e,t||[])).next())}))};const Oe="jupiter";function Ce(){return Re(this,void 0,void 0,(function*(){const e="VSTOKEN",t=o(),n=se(e);let r=!1;(new Se).withAttributes(["uuid"]).subscribe((({attributes:o,state:i})=>Re(this,void 0,void 0,(function*(){if(!1===i.isLoggedIn)return void("string"==typeof n&&ue(e));if(!o.uuid||void 0===i.isLoggedIn||r)return;if(r=!0,"string"!=typeof n)return void(yield ye(t));const a=n.split(":"),s=new Date(1e3*parseInt(a[1],10));s.setDate(s.getDate()-1),s.getTime()>Date.now()&&a[3]===o.uuid&&t.includes(a[4])&&a[5]===Oe||(yield ye(t))}))))}))}function Te(){const e="VSTOKEN2",t=o(),n=se(e);(new Se).fetch().then((({state:{isLoggedIn:r}})=>Re(this,void 0,void 0,(function*(){if(r){if("string"!=typeof n)return void(yield ge(t));const e=n.split(":"),r=new Date(1e3*parseInt(e[1],10));if(r.setMinutes(r.getMinutes()-30),r.getTime()>Date.now()&&t.includes(e[4])&&e[5]===Oe)return;yield ge(t)}else ue(e)})))).then((()=>{}))}const Ie="haveTriedThirdPartyLoginCheck",Ae=(0,_.Record)({user_name:_.String,tracking_key:_.String});const Ne="have-tried-autologin",je=[{name:"third_party",handler:function(){return e=this,t=void 0,r=function*(){return!(yield I(Ie,_.Boolean))&&(yield A(Ie,!0,36e5),!!(yield fetch(`https://${i()}/api/pluto/v1/sessions/current`,{mode:"cors",credentials:"include"}).then((e=>e.ok?e.json():Q(e).then((()=>null)).catch((()=>null)))).then((e=>{if(!e)return null;try{return Ae.check(e)}catch(t){return p(t,{data:e}),null}}))))},new((n=void 0)||(n=Promise))((function(o,i){function a(e){try{c(r.next(e))}catch(e){i(e)}}function s(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}c((r=r.apply(e,t||[])).next())}));var e,t,n,r}}],Pe=()=>{return e=void 0,n=void 0,o=function*(){if(function(){try{return window.self!==window.top}catch(e){return!0}}())return;const{state:{isLoggedIn:e}}=yield(new Se).fetch();if(!e&&!function(){const e=se(Ne);if(e&&"object"!=typeof e)try{if(Date.now()-parseInt(e,10)<6e4)return!0}catch(e){ue(Ne)}return ce(Ne,Date.now(),Date.now()+6e4),!1}())for(const e of je)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()),fe(n.href),!1}return!0}))))return},new((r=void 0)||(r=Promise))((function(t,i){function a(e){try{c(o.next(e))}catch(e){i(e)}}function s(e){try{c(o.throw(e))}catch(e){i(e)}}function c(e){var n;e.done?t(e.value):(n=e.value,n instanceof r?n:new r((function(e){e(n)}))).then(a,s)}c((o=o.apply(e,n||[])).next())}));var e,n,r,o};var Ue=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{c(r.next(e))}catch(e){i(e)}}function s(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}c((r=r.apply(e,t||[])).next())}))};const ke=[Pe,function(){return Promise.all([Ce(),Te()])},function(){(new Se).subscribe((({state:e})=>{!1===e.isLoggedIn&&(B("userAttributes",{}),B("storage",{}))}))}];var Le;!function(e){e.LOADED="amedia-user.janitor.loaded"}(Le||(Le={}));var xe=n(483),Fe=n(808);let De;const Me="undefined"==typeof self?window:self,Be="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||void 0!==Me.msCrypto&&"function"==typeof Me.msCrypto.getRandomValues&&Me.msCrypto.getRandomValues.bind(Me.msCrypto);if(Be){const e=new Uint8Array(16);De=function(){return Be(e),e}}else{const e=new Array(16);De=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 $e=[];for(let e=0;e<256;++e)$e[e]=(e+256).toString(16).substr(1);function Ve(){const e=De();return e[6]=15&e[6]|64,e[8]=63&e[8]|128,function(e,t){let n=0;const r=$e;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)}xe.config({name:"aid:userdata"});const qe=self.location.hostname.replace(/(.*\.)([^.]+\.\w+$)/,"$2");function Ge(){let e=Fe.get("amedia:fpbid");return e||(e=Ve(),Fe.set("amedia:fpbid",e,{expires:3650,domain:qe,sameSite:"strict"})),Promise.resolve(e)}function Ke(e){return Fe.set("amedia:visitid",e,{expires:new Date(Date.now()+18e5),domain:qe,sameSite:"strict"}),xe.setItem("visitid",e).then((()=>e))}function Ye(){const e=Date.now();return Ke(`${Ve()}|${e}`)}function ze(){return function(){const e=Fe.get("amedia:visitid");return e?Promise.resolve(e):xe.getItem("visitid")}().then((e=>e||Ye())).then((e=>{const[t,n]=e.split("|");return!t||n&&Date.now()-18e5>n?Ye():Ke(`${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))}}(ze))));var He=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{c(r.next(e))}catch(e){i(e)}}function s(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}c((r=r.apply(e,t||[])).next())}))};const We=3e5,Qe=(0,_.Record)({namespaces:(0,_.Dictionary)(_.Unknown,_.String)}),Je=(e,t="GET",n)=>fetch(e,{method:t,body:n&&JSON.stringify(n),headers:{"Content-Type":"application/json",Accept:"application/json"}}),Xe=(e,t={ignoreCache:!1})=>He(void 0,void 0,void 0,(function*(){if(0===e.length)throw new Error("namespaces array cannot be of length 0");return N("europa",Qe,(()=>Je(`/api/europa/v1/me/${e.join(",")}`).then((t=>He(void 0,void 0,void 0,(function*(){const n=yield t.text();return t.ok?JSON.parse(n):(400!==t.status&&p(`Could not get namespaces for: ${e}, status: ${t.status}`,{response:t,body:n}),{namespaces:{}})})))).then((e=>({ttl:We,data:e})))),(n=>!t.ignoreCache||0===Object.keys(n.namespaces).filter((t=>!Object.keys(e).includes(t))).length)).then((e=>e.namespaces))}));const Ze=(0,_.Record)({allowResearchUsage:_.Boolean,connectWithSurveys:_.Boolean,personalizedAds:_.Boolean,personalizedContent:_.Boolean}),et=e=>"true"===e||!0===e,tt=(0,_.Dictionary)(_.Unknown,_.String).And((0,_.Partial)({ad_segments:_.String,ad_segments_user:_.String,amedia_employee:_.Boolean,amedia_employee_user:_.Boolean,age:_.Number,age_user:_.Number,birth_year:_.String,birth_year_user:_.String,gender:_.String,gender_user:_.String,grunnkrets:_.String,grunnkrets_user:_.String,postcode:_.String,postcode_user:_.String,shared_account:_.Boolean,shared_account_user:_.Boolean,user_grouping_number:_.String,user_grouping_number_user:_.String})),nt=e=>({extraData:e}),rt=()=>new Promise((e=>{var t;const n=null===(t=$("state"))||void 0===t?void 0:t.isLoggedIn;!1!==n&&!0!==n?V("state",(({isLoggedIn:t})=>{!1!==t&&!0!==t||e(t)})):e(n)})),ot=()=>new Promise((e=>rt().then((t=>{t&&e()})))),it={uuid:de,name:de,trackingKey:de,access:()=>ot().then((()=>((e=["newspaper"])=>((e,t)=>N("checkForAccess",P,(()=>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=P.check(e);return{ttl:"granted"===t.access?1e4:0,data:t}}catch(t){throw p(t,{json:e}),t}})))).then((e=>({access:e.access_features}))))(o(),e))())),extraData:()=>Promise.all([Ge(),rt()]).then((([e,t])=>{var n;return((e,t,n)=>N("getNebulaInfo",tt,(()=>((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:tt.check(e)}}catch(t){throw p(t,{json:e}),t}}))})(e,t,n))).then(nt))(window.location.hostname,e,t?null===(n=$("userAttributes"))||void 0===n?void 0:n.trackingKey:void 0)})),privacyPreferences:()=>ot().then((()=>{return e=void 0,t=void 0,r=function*(){return N("privacyPreferences",Ze,(()=>Xe(["privacy_preferences"]).then((e=>{const t=e.privacy_preferences;return{ttl:3e5,data:{allowResearchUsage:et(t.allow_research_usage),connectWithSurveys:et(t.connect_with_surveys),personalizedAds:et(t.personalized_ads),personalizedContent:et(t.personalized_content)}}})))).then((e=>({privacyPreferences:e})))},new((n=void 0)||(n=Promise))((function(o,i){function a(e){try{c(r.next(e))}catch(e){i(e)}}function s(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}c((r=r.apply(e,t||[])).next())}));var e,t,n,r}))};class at extends Error{constructor(e,t){super(e),this.code=t}}at.ERROR_RELOADED_NO_ACCESS="RELOADED_NO_ACCESS",at.ERROR_ENABLING_ACCESS_FAILED="ENABLING_ACCESS_FAILED",at.ERROR_NO_ACCESS_AFTER_SUCCESSFUL_ACTIVATION_WITH_REQUESTED_ACCESS_FEATURES="NO_ACCESS_AFTER_SUCCESSFUL_ACTIVATION_WITH_REQUESTED_ACCESS_FEATURES";const st=at;var ct=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{c(r.next(e))}catch(e){i(e)}}function s(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}c((r=r.apply(e,t||[])).next())}))};const ut=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 ct(this,void 0,void 0,(function*(){const{state:{isLoggedIn:e}}=yield(new Se).fetch();if(!e)return yield Pe(),{isLoggedIn:!1,hasAccess:!1,accessFeatures:[]};let n=yield this.setAccessCookiesAndGetAccessFeatures(this.requestedAccessFeatures);if(n.denied){if(n=yield this.activateAccess(this.requestedAccessFeatures),n.denied)return{isLoggedIn:!0,hasAccess:!1,accessFeatures:n.accessFeatures};if(n=yield this.setAccessCookiesAndGetAccessFeatures(this.requestedAccessFeatures),n.denied)throw new st("New subscription was attached and checked successfully, but internal systems disagree about current newspaper access.",st.ERROR_NO_ACCESS_AFTER_SUCCESSFUL_ACTIVATION_WITH_REQUESTED_ACCESS_FEATURES)}if(this.reload||this.requestedUrl){if(r=this.requestedUrl,se("aid-paywall-reload-performed")===(r||t()))throw new st("Unlock check already performed.",st.ERROR_RELOADED_NO_ACCESS);(e=>{const n=new Date;n.setTime(n.getTime()+12e4),ce("aid-paywall-reload-performed",e||t(),n)})(this.requestedUrl),this.reload&&window.location.reload(),this.requestedUrl&&(e=>{window.location.replace(e)})(this.requestedUrl)}var r;return{isLoggedIn:!0,hasAccess:!0,accessFeatures:n.accessFeatures}}))}setAccessCookiesAndGetAccessFeatures(e){return(t=o(),ve(void 0,void 0,void 0,(function*(){const e=[];return e.push(ye(t).catch((()=>Promise.resolve({success:!1,accessFeatures:[]})))),e.push(ge(t).catch((()=>Promise.resolve({success:!1,accessFeatures:[]})))),Promise.all(e).then((e=>e.reduce(((e,t)=>({success:e.success&&t.success,accessFeatures:e.accessFeatures.concat(t.accessFeatures).filter(((e,t,n)=>n.indexOf(e)===t)).sort()})),{success:!0,accessFeatures:[]})))}))).then((t=>{const n=!pe(t.accessFeatures,e);if(!t.success&&n)throw new st("Could not set access cookies",st.ERROR_ENABLING_ACCESS_FAILED);return{denied:n,accessFeatures:t.accessFeatures}}));var t}activateAccess(e){return ct(this,void 0,void 0,(function*(){const t=yield he(this.requestedAccessFeatures);return{denied:!pe(t,e),accessFeatures:t}}))}},ft=e=>(e=>{const t=new URL(`https://${i()}/aid/logg_inn/${o()}/`);t.searchParams.set("requestedUrl",e instanceof URL?e.href:e),fe(t.href)})(e||t()),lt=()=>le(),dt=e=>new Promise((t=>{b(me.ON_ACTIVATION_COMPLETE,(n=>{const r=n.detail.accessFeatures;t({hasAccess:pe(r,e),accessFeatures:r})})),E(new CustomEvent(me.REQUEST_ACTIVATION,{detail:{accessFeatures:e}}))})),vt=e=>{E(new CustomEvent(be.UPDATE_STORAGE,{detail:e}))};"undefined"==typeof process&&(m(be.REQUEST_STATE,(()=>{const e=$("state");e&&Object.keys(e).length>0&&E(new CustomEvent(be.ON_STATE_UPDATED,{detail:e})),V("state",(e=>{E(new CustomEvent(be.ON_STATE_UPDATED,{detail:e}))}))})),V("userAttributes",(e=>{E(new CustomEvent(be.ON_ATTRIBUTES_UPDATED,{detail:e}))})),m(be.REQUEST_USER_ATTRIBUTES,(e=>{const t=e.detail,n=$("userAttributes")||{};Object.keys(n).length>0&&E(new CustomEvent(be.ON_ATTRIBUTES_UPDATED,{detail:n}));const r=t.filter((e=>void 0===n[e]));r.length>0&&(e=>{const t=[];e.forEach((e=>{const n=it[e];n?t.includes(n)||t.push(n):h(`Unknown attribute ${e} was requested`)}));const n=[];t.forEach((e=>{n.push(e().then((e=>{M("userAttributes",e)})).catch((t=>{h(`User attribute call failed (${e.toString()})`,t)})))})),Promise.all(n).then((()=>{}))})(r)})),V("storage",(e=>{E(new CustomEvent(be.ON_STORAGE_UPDATED,{detail:e}))})),m(be.REQUEST_STORAGE_NAMESPACES,(e=>{ot().then((()=>{const t=e.detail,n=$("storage")||{};Object.keys(n).length>0&&E(new CustomEvent(be.ON_STORAGE_UPDATED,{detail:n}));const r=t.filter((e=>void 0===n[e]));r.length>0&&Xe(r).then((e=>{M("storage",e)}))}))})),m(be.UPDATE_STORAGE,(e=>{ot().then((()=>{var t;t=e.detail,Object.keys(t).forEach((e=>((e,t)=>He(void 0,void 0,void 0,(function*(){const n=yield Je(`/api/europa/v1/me/${e}`,"PATCH",t);return n.ok?((e,t)=>He(void 0,void 0,void 0,(function*(){const n=yield I("europa",Qe),r=n?Object.assign(Object.assign({},n),{namespaces:Object.assign(Object.assign({},n.namespaces),{[e]:t})}):{namespaces:{[e]:t}};return A("europa",r,Date.now()+We)})))(e,t):(p(`Could not get namespace: ${e}, status: ${n.status}, statusText: ${n.statusText}`,n),{})})))(e,t[e])))}))})),Ue(void 0,void 0,void 0,(function*(){let e=!1;m(Le.LOADED,(()=>{e||(e=!0,function(){Ue(this,void 0,void 0,(function*(){for(const e of ke)yield e()}))}())})),E(new CustomEvent(Le.LOADED))})))})();var o=r.Hr,i=r.vg,a=r.EX,s=r.kS,c=r.Lk,u=r.Hc;export{o as PaywallUnlockRequest,i as UserDataRequest,a as goToLoginPage,s as logout,c as tryActivateSubscriptionAccess,u as updateStorage};
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 s="";for(var c in i)i[c]&&(s+="; "+c,!0!==i[c]&&(s+="="+i[c].split(";")[0]));return document.cookie=t+"="+n+s}}function a(e,n){if("undefined"!=typeof document){for(var o={},i=document.cookie?document.cookie.split("; "):[],a=0;a<i.length;a++){var s=i[a].split("="),c=s.slice(1).join("=");n||'"'!==c.charAt(0)||(c=c.slice(1,-1));try{var u=t(s[0]);if(c=(r.read||r)(c,u)||t(c),n)try{c=JSON.parse(c)}catch(e){}if(o[u]=c,e===u)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,s){if(!n[a]){if(!t[a]){if(i)return i(a,!0);var c=new Error("Cannot find module '"+a+"'");throw c.code="MODULE_NOT_FOUND",c}var u=n[a]={exports:{}};t[a][0].call(u.exports,(function(e){return o(t[a][1][e]||e)}),u,u.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),s=e.document.createTextNode("");a.observe(s,{characterData:!0}),n=function(){s.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 c=new e.MessageChannel;c.port1.onmessage=f,n=function(){c.port2.postMessage(0)}}var u=[];function f(){var e,t;r=!0;for(var n=u.length;n;){for(t=u,u=[],e=-1;++e<n;)t[e]();n=u.length}r=!1}t.exports=function(e){1!==u.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"],s=["FULFILLED"],c=["PENDING"];function u(e){if("function"!=typeof e)throw new TypeError("resolver must be a function");this.state=c,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=u,u.prototype.catch=function(e){return this.then(null,e)},u.prototype.then=function(e,t){if("function"!=typeof e&&this.state===s||"function"!=typeof t&&this.state===a)return this;var n=new this.constructor(o);return this.state!==c?l(n,this.state===s?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=s,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},u.resolve=function(e){return e instanceof this?e:i.resolve(new this(o),e)},u.reject=function(e){var t=new this(o);return i.reject(t,e)},u.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),s=0,c=-1,u=new this(o);++c<n;)f(e[c],c);return u;function f(e,o){t.resolve(e).then((function(e){a[o]=e,++s!==n||r||(r=!0,i.resolve(u,a))}),(function(e){r||(r=!0,i.reject(u,e))}))}},u.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 s=-1,c=new this(o);++s<r;)n=e[s],t.resolve(n).then((function(e){a||(a=!0,i.resolve(c,e))}),(function(e){a||(a=!0,i.reject(c,e))}));return c}},{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 s(e,t){t&&e.then((function(e){t(null,e)}),(function(e){t(e)}))}function c(e,t,n){"function"==typeof t&&e.then(t),"function"==typeof n&&e.catch(n)}function u(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 T(e){return i([g(atob(e.data))],{type:e.type})}function C(e){return e&&e.__local_forage_encoded_blob}function I(e){var t=this,n=t._initReady().then((function(){var e=v[t._dbInfo.name];if(e&&e.dbReady)return e.dbReady}));return c(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=I);var i=[];function s(){return a.resolve()}for(var c=0;c<o.forages.length;c++){var u=o.forages[c];u!==t&&i.push(u._initReady().catch(s))}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(),s=1;a.onsuccess=function(){var n=a.result;if(n){var r=n.value;C(r)&&(r=T(r));var o=e(r,n.key,s++);void 0!==o?t(o):n.continue()}else t()},a.onerror=function(){r(a.error)}}catch(e){r(e)}}))})).catch(r)}));return s(r,t),r},getItem:function(e,t){var n=this;e=u(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=T(e)),t(e)},a.onerror=function(){r(a.error)}}catch(e){r(e)}}))})).catch(r)}));return s(r,t),r},setItem:function(e,t,n){var r=this;e=u(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 s=a.objectStore(r._dbInfo.storeName);null===t&&(t=void 0);var c=s.put(t,e);a.oncomplete=function(){void 0===t&&(t=null),n(t)},a.onabort=a.onerror=function(){var e=c.error?c.error:c.transaction.error;o(e)}}catch(e){o(e)}}))})).catch(o)}));return s(o,n),o},removeItem:function(e,t){var n=this;e=u(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 s(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 s(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 s(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),s=!1,c=a.openKeyCursor();c.onsuccess=function(){var n=c.result;n?0===e||s?t(n.key):(s=!0,n.advance(e)):t(null)},c.onerror=function(){r(c.error)}}catch(e){r(e)}}))})).catch(r)}));return s(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 s(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 c=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?c.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 s=0;s<i.length;s++){var c=i[s];c._dbInfo.db=null,c._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}))}})):c.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 s(r,t),r}};var j="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",P=/^~~local_forage_type~([^~]+)~/,U="__lfsc__:",k=U.length,L="arbf",x="blob",F="si08",D="ui08",M="uic8",B="si16",$="si32",V="ur16",q="ui32",G="fl32",K="fl64",Y=k+L.length,z=Object.prototype.toString;function H(e){var t,n,r,o,i,a=.75*e.length,s=e.length,c=0;"="===e[e.length-1]&&(a--,"="===e[e.length-2]&&a--);var u=new ArrayBuffer(a),f=new Uint8Array(u);for(t=0;t<s;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[c++]=n<<2|r>>4,f[c++]=(15&r)<<4|o>>2,f[c++]=(3&o)<<6|63&i;return u}function W(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+=L):(r=e.buffer,"[object Int8Array]"===n?o+=F:"[object Uint8Array]"===n?o+=D:"[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+=G:"[object Float64Array]"===n?o+=K:t(new Error("Failed to get type for BinaryArray"))),t(o+W(r))}else if("[object Blob]"===n){var i=new FileReader;i.onload=function(){var n="~~local_forage_type~"+e.type+"~"+W(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===x&&P.test(n)){var o=n.match(P);t=o[1],n=n.substring(o[0].length)}var a=H(n);switch(r){case L:return a;case x:return i([a],{type:t});case F:return new Int8Array(a);case D: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 G:return new Float32Array(a);case K:return new Float64Array(a);default:throw new Error("Unkown type: "+r)}},stringToBuffer:H,bufferToString:W};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,s){s.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=u(e);var i=new a((function(i,a){o.ready().then((function(){void 0===t&&(t=null);var s=t,c=o._dbInfo;c.serializer.serialize(t,(function(t,u){u?a(u):c.db.transaction((function(n){X(n,c,"INSERT OR REPLACE INTO "+c.storeName+" (key, value) VALUES (?, ?)",[e,t],(function(){i(s)}),(function(e,t){a(t)}))}),(function(t){if(t.code===t.QUOTA_ERR){if(r>0)return void i(Z.apply(o,[e,s,n,r-1]));a(t)}}))}))})).catch(a)}));return s(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,s=0;s<a;s++){var c=i.item(s),u=c.value;if(u&&(u=o.serializer.deserialize(u)),void 0!==(u=e(u,c.key,s+1)))return void t(u)}t()}),(function(e,t){r(t)}))}))})).catch(r)}));return s(r,t),r},getItem:function(e,t){var n=this;e=u(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 s(r,t),r},setItem:function(e,t,n){return Z.apply(this,[e,t,n,1])},removeItem:function(e,t){var n=this;e=u(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 s(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 s(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 s(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 s(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 s(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 s(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=[],s=0,c=e.storeNames.length;s<c;s++)i.push(o(e.storeNames[s]));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,s=0;s<i;s++){var c=localStorage.key(s);if(0===c.indexOf(r)){var u=localStorage.getItem(c);if(u&&(u=t.serializer.deserialize(u)),void 0!==(u=e(u,c.substring(o),a++)))return u}}}));return s(r,t),r},getItem:function(e,t){var n=this;e=u(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 s(r,t),r},setItem:function(e,t,n){var r=this;e=u(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 s(o,n),o},removeItem:function(e,t){var n=this;e=u(e);var r=n.ready().then((function(){var t=n._dbInfo;localStorage.removeItem(t.keyPrefix+e)}));return s(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 s(n,e),n},length:function(e){var t=this.keys().then((function(e){return e.length}));return s(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 s(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 s(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 s(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)},se={},ce={},ue={INDEXEDDB:N,WEBSQL:te,LOCALSTORAGE:oe},fe=[ue.INDEXEDDB._driver,ue.WEBSQL._driver,ue.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),ue)if(ue.hasOwnProperty(n)){var r=ue[n],o=r._driver;this[n]=o,se[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"),c=0,u=i.length;c<u;c++){var f=i[c];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 s(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){se[r]&&console.info("Redefining LocalForage driver: "+r),se[r]=e,ce[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 c(r,t,n),r},e.prototype.driver=function(){return this._driver||null},e.prototype.getDriver=function(e,t,n){var r=se[e]?a.resolve(se[e]):a.reject(new Error("Driver not found."));return c(r,t,n),r},e.prototype.getSerializer=function(e){var t=a.resolve(Q);return c(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 c(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 s(e){return r._extend(e),i(),r._ready=r._initStorage(r._config),r._ready}var u=null!==this._driverSet?this._driverSet.catch((function(){return a.resolve()})):a.resolve();return this._driverSet=u.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(s).catch(n)}i();var c=new Error("No available storage method found.");return r._driverSet=a.reject(c),r._driverSet}()}}(o)}))})).catch((function(){i();var e=new Error("No available storage method found.");return r._driverSet=a.reject(e),r._driverSet})),c(this._driverSet,t,n),this._driverSet},e.prototype.supports=function(e){return!!ce[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,s=e.slice(0,n),c=e[n];return{enforce:function(e){return function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];if(t.length<s.length){var u="Expected "+s.length+" arguments but only received "+t.length,f=a.FAILURE.ARGUMENT_INCORRECT(u);throw new i.ValidationError(f)}for(var l=0;l<s.length;l++)s[l].check(t[l]);var d=e.apply(void 0,o([],r(t)));if(!(d instanceof Promise))throw u="Expected function to return a promise, but instead got "+d,f=a.FAILURE.RETURN_INCORRECT(u),new i.ValidationError(f);return d.then(c.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,s=e.slice(0,n),c=e[n];return{enforce:function(e){return function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];if(t.length<s.length){var u="Expected "+s.length+" arguments but only received "+t.length,f=a.FAILURE.ARGUMENT_INCORRECT(u);throw new i.ValidationError(f)}for(var l=0;l<s.length;l++)s[l].check(t[l]);return c.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=[],s=0;s<n;s++)a.push(s);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 s=i.value,c=(t.name||t.constructor.name+".prototype")+("string"==typeof n?'["'+n+'"]':"["+String(n)+"]"),u=a(t,n,e.length);if(u.length!==e.length)throw new Error("Number of `@checked` runtypes and @check parameters not matched.");if(u.length>s.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=u[n],a=e.validate(t[i]);if(!a.success){var s=c+", argument #"+i+": "+a.message,f=o.FAILURE.ARGUMENT_INCORRECT(s);throw new r.ValidationError(f)}})),s.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),s=a.next();!s.done;s=a.next()){var c=r(s.value,2),u=c[0],f=c[1];if(u.guard(t))return f(t)}}catch(e){o={error:e}}finally{try{s&&!s.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 s=Object.keys(o.fields);return s.length?"{ "+s.map((function(e){return""+r(o)+e+(a=e,s=(i=o).isPartial,c=i.fields,(s||void 0!==a&&"optional"===c[a].tag?"?":"")+": ")+("optional"===o.fields[e].tag?n(!1,t)(o.fields[e].underlying):n(!1,t)(o.fields[e]))+";";var i,a,s,c})).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),s=i.map((function(o){return r.innerValidate(e,t[o],n)})),c=i.reduce((function(e,t){var n=s[t];return n.success||(e[t]=n.details||n.message),e}),[]);return 0!==o.enumerableKeysOf(c).length?o.FAILURE.CONTENT_INCORRECT(a,c):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,s={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(s,i):i?o.SUCCESS(r.value):o.FAILURE.CONSTRAINT_FAILED(s)}),s)},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),s=n(611),c=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?c:t,u=a.default(i),f={tag:"dictionary",key:u,value:e};return r.create((function(t,o){if(null==t||"object"!=typeof t)return s.FAILURE.TYPE_INCORRECT(f,t);if(Object.getPrototypeOf(t)!==Object.prototype&&(!Array.isArray(t)||"string"===u))return s.FAILURE.TYPE_INCORRECT(f,t);var a=/^(?:NaN|-?\d+(?:\.\d+)?)$/u,c=s.enumerableKeysOf(t),l=c.reduce((function(c,u){var l="string"==typeof u&&a.test(u),d=l?n.g.Number(u):u;return(l?i.guard(d)||i.guard(u):i.guard(d))?c[u]=r.innerValidate(e,t[u],o):c[u]=s.FAILURE.KEY_INCORRECT(f,i.reflect,d),c}),{}),d=c.reduce((function(e,t){var n=l[t];return n.success||(e[t]=n.details||n.message),e}),{});return 0!==s.enumerableKeysOf(d).length?s.FAILURE.CONTENT_INCORRECT(f,d):s.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,s;try{for(var c=r(e),u=c.next();!u.done;u=c.next()){var f=u.value,l=o.innerValidate(f,t,n);if(!l.success)return l}}catch(e){a={error:e}}finally{try{u&&!u.done&&(s=c.return)&&s.call(c)}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 s(e,t,n){var c,u={tag:"record",isPartial:t,isReadonly:n,fields:e};return(c=i.create((function(n,s){if(null==n)return a.FAILURE.TYPE_INCORRECT(u,n);var c=a.enumerableKeysOf(e);if(0!==c.length&&"object"!=typeof n)return a.FAILURE.TYPE_INCORRECT(u,n);var f=o([],r(new Set(o(o([],r(c)),r(a.enumerableKeysOf(n)))))),l=f.reduce((function(r,o){var c=a.hasKey(o,e),u=a.hasKey(o,n);if(c){var f=e[o],l=t||"optional"===f.reflect.tag;if(u){var d=n[o];r[o]=l&&void 0===d?a.SUCCESS(d):i.innerValidate(f,d,s)}else r[o]=l?a.SUCCESS(void 0):a.FAILURE.PROPERTY_MISSING(f.reflect)}else{if(!u)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(u,d):a.SUCCESS(n)}),u)).asPartial=function(){return s(c.fields,!0,c.isReadonly)},c.asReadonly=function(){return s(c.fields,c.isPartial,!0)},c.pick=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n={};return e.forEach((function(e){n[e]=c.fields[e]})),s(n,c.isPartial,c.isReadonly)},c.omit=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n={};return a.enumerableKeysOf(c.fields).forEach((function(t){e.includes(t)||(n[t]=c.fields[t])})),s(n,c.isPartial,c.isReadonly)},c}t.InternalRecord=s,t.Record=function(e){return s(e,!1,!1)},t.Partial=function(e){return s(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),s=a.map((function(n){return r.innerValidate(e[n],t[n],i)})),c=a.reduce((function(e,t){var n=s[t];return n.success||(e[t]=n.details||n.message),e}),[]);return 0!==o.enumerableKeysOf(c).length?o.FAILURE.CONTENT_INCORRECT(n,c):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 s,c,u,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){s={error:e}}finally{try{y&&!y.done&&(c=p.return)&&c.call(p)}finally{if(s)throw s.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){u={error:e}}finally{try{E&&!E.done&&(f=b.return)&&f.call(b)}finally{if(u)throw u.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 T=r(e),C=T.next();!C.done;C=T.next()){var I=C.value;if(o.innerValidate(I,t,n).success)return i.SUCCESS(t)}}catch(e){v={error:e}}finally{try{C&&!C.done&&(h=T.return)&&h.call(T)}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,{Hr:()=>ft,vg:()=>we,EX:()=>lt,kS:()=>dt,Lk:()=>vt,Hc:()=>ht});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},a=(n,r,o)=>{const i={};Object.keys(o).forEach((e=>{if(["string","number","boolean"].includes(typeof o[e]))i[e]=o[e];else try{i[e]=JSON.stringify(o[e])}catch(t){i[e]=o[e]}})),function(e,t){const n=new FormData;Object.keys(t).forEach((e=>n.append(e,t[e]))),fetch(e,{method:"POST",body:n,headers:{Accept:"application/json"}}).then((e=>{if(!e.ok)throw new Error(`Error, status: ${e.status}, text: ${e.statusText}`)}))}(`/api/mercury/v1/log/${n}`,Object.assign(Object.assign({},i),{message:r,url:t(),domain:e()}))},s={error:(e,t)=>a("error",e,t),warn:(e,t)=>a("warn",e,t),info:(e,t)=>a("info",e,t),debug:(e,t)=>a("debug",e,t)};const c=e=>{const t={message:e.message};return Object.getOwnPropertyNames(e).forEach((n=>{t[n]=e[n]})),t},u=e=>{const t={};return Object.getOwnPropertyNames(e).forEach((n=>{t[n]=e[n]})),t},f=(e,t,n)=>{((e,t={})=>{let n=e,r=t||{};if(n instanceof Error){const e=c(n);n=e.message,r=Object.assign(Object.assign({},r),{error:e})}if(r=Object.assign(Object.assign({},r),{origin:"@amedia/user"}),t instanceof Error){const e=c(t);r=Object.assign(Object.assign({},r),{[Object.keys(r).includes("error")?"contextError":"error"]:e})}else if(r instanceof Response){const e=u(r);r=Object.assign(Object.assign({},r),{response:e})}else Object.keys(r).forEach((e=>{r[e]instanceof Error?r[e]=c(r[e]):r[e]instanceof Response&&(r[e]=u(r[e]))}));return Promise.resolve({message:n,context:r})})(t,n).then((({message:t,context:n})=>s[e](t,n)))},l=(e,t)=>f("warn",e,t),d=(e,t)=>f("error",e,t);let v;var h;"undefined"!=typeof window&&(h=window,v=h);const p=(e,t)=>{v?v.addEventListener(e,(e=>{e.stopImmediatePropagation(),t.apply(v,[e])})):d("No root element to bind event to!")},y=(e,t)=>{v?v.addEventListener(e,(e=>{t.apply(v,[e])})):d("No root element to bind event to!")},g=e=>{v?v.dispatchEvent(e):d("No root element to dispatch event on!")};var m=n(529);const b={},E=e=>{const t=b[e];return t?(delete b[e],t):[]},_=()=>{const e="undefined"!=typeof window?window:n.g;return e.amediaUserCache||(e.amediaUserCache={})},w={get:e=>{const t=_()[e];return Promise.resolve(t)},set:(e,t,n)=>(_()[e]={key:e,data:t,expires:n},Promise.resolve()),remove:e=>(delete _()[e],Promise.resolve()),clear:()=>(("undefined"!=typeof window?window:n.g).amediaUserCache={},Promise.resolve())};const S=()=>w,R=e=>S().remove(e),O=(e,t)=>{return n=void 0,r=void 0,i=function*(){const n=yield S().get(e);if(!n)return Promise.resolve();if(Date.now()>n.expires)return R(e),Promise.resolve();try{return t.check(n.data)}catch(t){return d(t,{cacheData:n.data}),R(e),Promise.resolve()}},new((o=void 0)||(o=Promise))((function(e,t){function a(e){try{c(i.next(e))}catch(e){t(e)}}function s(e){try{c(i.throw(e))}catch(e){t(e)}}function c(t){var n;t.done?e(t.value):(n=t.value,n instanceof o?n:new o((function(e){e(n)}))).then(a,s)}c((i=i.apply(n,r||[])).next())}));var n,r,o,i},T=(e,t,n)=>S().set(e,t,Date.now()+n);function C(e,t,n,r){return new Promise(((o,i)=>{((e,t)=>{b[e]||(b[e]=[]),b[e].push(t)})(e,{resolve:o,reject:i}),(e=>{var t;return(null===(t=b[e])||void 0===t?void 0:t.length)||0})(e)>1||O(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;T(e,r,n.ttl),E(e).forEach((e=>{e.resolve(n.data)}))})).catch((()=>{E(e).forEach((e=>{e.reject()}))})):E(e).forEach((e=>{e.resolve(t)}))}))}))}const I=(0,m.Record)({id:m.Number,domain:m.String}),A=(0,m.Record)({status:(0,m.Literal)("success"),access:(0,m.Union)((0,m.Literal)("granted"),(0,m.Literal)("denied")),publication:I,access_features:(0,m.Array)(m.String)}),N=(0,m.Record)({status:(0,m.Literal)("success"),cookie:m.String,access_features:(0,m.Array)(m.String)}),j=(0,m.Record)({status:(0,m.Literal)("success"),vstoken_cookie:m.String,uuid:m.String,access_features:(0,m.Array)(m.String)});var P=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{c(r.next(e))}catch(e){i(e)}}function s(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}c((r=r.apply(e,t||[])).next())}))};class U extends Error{}var k=n(905);const L={},x={},F=(e,t)=>{L[e]=t,(e=>{var t;null===(t=x[e])||void 0===t||t.forEach((t=>t(L[e])))})(e)},D=(e,t)=>{F(e,(0,k.Z)(L[e]||{},t))},M=F,B=e=>L[e],$=(e,t)=>{x[e]||(x[e]=[]),x[e].push(t)},V=["avbrutt","kansellert","cancelled","aborted","failed to fetch","abgebrochen","the operation was aborted."];var q=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{c(r.next(e))}catch(e){i(e)}}function s(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}c((r=r.apply(e,t||[])).next())}))};const G=(0,m.Partial)({user_uuid:m.String,user_name:m.String,tracking_key:m.String}),K=(0,m.Record)({code:m.String}),Y=(0,m.Record)({errors:(0,m.Array)(K)}),z=["session.not_found","session.not_specified","user.deactivated"],H=["session.invalid_for_domain","user.not_found"],W=e=>q(void 0,void 0,void 0,(function*(){let t;try{[t]=Y.check(yield e.json()).errors}catch(t){return n=null==t?void 0:t.message,V.includes(n.toLowerCase().trim())?Promise.resolve():(d("Unable to parse error body from pluto",{error:t,response:e}),Promise.reject(t))}var n;return z.includes(null==t?void 0:t.code)?Promise.resolve():H.includes(null==t?void 0:t.code)?(l(`Pluto responded with HTTP/${e.status}: (${t.code}) while fetching current session`,{error:t,response:e}),Promise.resolve()):(d(`Pluto responded with HTTP/${e.status}: ${e.statusText}) when fetching current session`,{error:t,response:e}),Promise.reject())})),Q=()=>fetch("/api/pluto/v1/sessions/current").then((e=>e.ok?e.json():W(e).then((()=>({}))))).then((e=>{const t={ttl:-1,data:e};if(0===Object.keys(e).length)return t;try{return{ttl:1e4,data:G.check(e)}}catch(n){return d(n,{json:e}),t}})),J=e=>q(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}`)}D("state",{isLoggedIn:!1})}))}));let X;const Z=self||window,ee="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||void 0!==Z.msCrypto&&"function"==typeof Z.msCrypto.getRandomValues&&Z.msCrypto.getRandomValues.bind(Z.msCrypto);if(ee){const e=new Uint8Array(16);X=function(){return ee(e),e}}else{const e=new Array(16);X=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 te=[];for(let e=0;e<256;++e)te[e]=(e+256).toString(16).substr(1);function ne(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=X();return e[6]=15&e[6]|64,e[8]=63&e[8]|128,function(e,t){let n=0;const r=te;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)}(),s=new CustomEvent(`amedia-rpc-event:${e}:${t}`,{detail:{eventId:a,args:n}});if(self.dispatchEvent(s),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 re{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]=ne(this.component,e),this[e](...t)}}}let oe;const ie=(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},ae=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 ie(t,r)}return null};function se(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===ae(e)&&(document.cookie=a.replace(/; expires=[^;]*/,"")),a}function ce(e){se(e)}const ue=e=>{window.location.href=e};const fe=()=>{return e=void 0,t=void 0,r=function*(){return Promise.all([J(o()),S().clear()]).then((()=>{(oe||(oe=new re({version:"1.0.0",component:"userdata-session",methods:["userAuthenticated"]}),oe)).userAuthenticated(!1),ce("VSTOKEN"),ce("aid.session"),ce("aid_invitation_code"),ce("aid-reload-article"),ce("VSTOKEN2")})).catch((e=>{d("Failure while logging out",e)}))},new((n=void 0)||(n=Promise))((function(o,i){function a(e){try{c(r.next(e))}catch(e){i(e)}}function s(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}c((r=r.apply(e,t||[])).next())}));var e,t,n,r},le=()=>q(void 0,void 0,void 0,(function*(){return C("getCurrentSession",G,Q).then((e=>{return D("state",{isLoggedIn:void 0!==e.user_uuid}),{uuid:(t=e).user_uuid,name:t.user_name,trackingKey:t.tracking_key};var t}))}));var de=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{c(r.next(e))}catch(e){i(e)}}function s(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}c((r=r.apply(e,t||[])).next())}))};const ve=e=>{try{return(e=>P(void 0,void 0,void 0,(function*(){return fetch(`/api/mercury/v2/access/activate?publication_wwwdomain=${o()}&access_features=${e.join(",")}`,{method:"post"}).then((t=>P(void 0,void 0,void 0,(function*(){const n=yield t.text();let r;try{r=JSON.parse(n)}catch(r){d(`Activate subscription failed. Mercury (HTTP/${t.status}: ${n})`,{error:r,response:t,accessFeatures:e,body:n})}if(!t.ok){if(401===t.status&&"user_deactivated"===(null==r?void 0:r.status))throw new U;return 400===t.status&&"no_session_found"===(null==r?void 0:r.status)||d(`Activate subscription failed. Mercury (HTTP/${t.status}: ${n})`,{response:t,accessFeatures:e,body:n}),[]}return null==r?void 0:r.access_features}))))})))(e)}catch(e){if(e instanceof U)return fe(),Promise.resolve([]);throw e}},he=(e,t)=>t.length<1||t.filter((t=>e.includes(t))).length>0,pe=e=>de(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 N.check(e)}catch(t){throw d(t,{json:e}),t}})))(e);return"success"===t.status&&se("VSTOKEN",t.cookie,365,"/"),{success:"success"===t.status,accessFeatures:t.access_features}})),ye=e=>de(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 j.check(e)}catch(t){throw d(t,{json:e}),t}})))(e);return"success"===t.status&&se("VSTOKEN2",t.vstoken_cookie,1,"/"),{success:"success"===t.status,accessFeatures:t.access_features}}));var ge,me;!function(e){e.REQUEST_ACTIVATION="amedia-user.activation.request-activation",e.ON_ACTIVATION_COMPLETE="amedia-user.activation.on-activation-complete"}(ge||(ge={})),p(ge.REQUEST_ACTIVATION,(e=>{ve(e.detail.accessFeatures).then((e=>{g(new CustomEvent(ge.ON_ACTIVATION_COMPLETE,{detail:{accessFeatures:e}}))}))})),function(e){e.REQUEST_STATE="amedia-user.request-state",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"}(me||(me={}));const be=(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(!be(e[o],t[o]))return!1}return!0};function Ee(e,t){return!!(e&&e.length>0)&&(!(t&&Object.keys(t).length>0)||e.filter((e=>!Object.keys(t).includes(e))).length>0)}class _e{constructor(e,t){this.attributes=e,this.namespaces=t}withAttributes(e){return new _e([...this.attributes||[],...e],this.namespaces)}withStorage(e){return new _e(this.attributes,[...this.namespaces||[],...e])}subscribe(e){let t=this.setupLocalCache();y(me.ON_STATE_UPDATED,(n=>{const r=n.detail;Object.keys(t.state).length>0&&be(t.state,r)||(t=Object.assign(Object.assign({},t),{state:r}),e(t))})),g(new CustomEvent(me.REQUEST_STATE)),Array.isArray(this.attributes)&&this.attributes.length>0&&(y(me.ON_ATTRIBUTES_UPDATED,(n=>{const r=this.processUserAttributesEvent(n);Object.keys(t.attributes).length>0&&be(t.attributes,r)||(t=Object.assign(Object.assign({},t),{attributes:r}),e(t))})),g(new CustomEvent(me.REQUEST_USER_ATTRIBUTES,{detail:this.attributes}))),Array.isArray(this.namespaces)&&this.namespaces.length>0&&(y(me.ON_STORAGE_UPDATED,(n=>{const r=this.processStorageEvent(n);be(t.storage,r)||(t=Object.assign(Object.assign({},t),{storage:r}),e(t))})),g(new CustomEvent(me.REQUEST_STORAGE_NAMESPACES,{detail:this.namespaces})))}fetch(){return new Promise((e=>{this.subscribe((t=>{void 0!==t.state.isLoggedIn&&(!1!==t.state.isLoggedIn&&(Ee(this.attributes,t.attributes)||Ee(this.namespaces,t.storage))||e(t))}))}))}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&&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 we=_e;var Se=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{c(r.next(e))}catch(e){i(e)}}function s(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}c((r=r.apply(e,t||[])).next())}))};const Re="jupiter";function Oe(){return Se(this,void 0,void 0,(function*(){const e="VSTOKEN",t=o(),n=ae(e);let r=!1;(new we).withAttributes(["uuid"]).subscribe((({attributes:o,state:i})=>Se(this,void 0,void 0,(function*(){if(!1===i.isLoggedIn)return void("string"==typeof n&&ce(e));if(!o.uuid||void 0===i.isLoggedIn||r)return;if(r=!0,"string"!=typeof n)return void(yield pe(t));const a=n.split(":"),s=new Date(1e3*parseInt(a[1],10));s.setDate(s.getDate()-1),s.getTime()>Date.now()&&a[3]===o.uuid&&t.includes(a[4])&&a[5]===Re||(yield pe(t))}))))}))}function Te(){const e="VSTOKEN2",t=o(),n=ae(e);(new we).fetch().then((({state:{isLoggedIn:r}})=>Se(this,void 0,void 0,(function*(){if(r){if("string"!=typeof n)return void(yield ye(t));const e=n.split(":"),r=new Date(1e3*parseInt(e[1],10));if(r.setMinutes(r.getMinutes()-30),r.getTime()>Date.now()&&t.includes(e[4])&&e[5]===Re)return;yield ye(t)}else ce(e)})))).then((()=>{}))}const Ce="haveTriedThirdPartyLoginCheck",Ie=(0,m.Record)({user_name:m.String,tracking_key:m.String});function Ae(){return e=this,t=void 0,r=function*(){return!(yield O(Ce,m.Boolean))&&(yield T(Ce,!0,36e5),!!(yield fetch(`https://${i()}/api/pluto/v1/sessions/current`,{mode:"cors",credentials:"include"}).then((e=>e.ok?e.json():W(e).then((()=>null)).catch((()=>null)))).then((e=>{if(!e)return null;try{return Ie.check(e)}catch(t){return d(t,{data:e}),null}}))))},new((n=void 0)||(n=Promise))((function(o,i){function a(e){try{c(r.next(e))}catch(e){i(e)}}function s(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}c((r=r.apply(e,t||[])).next())}));var e,t,n,r}var Ne=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{c(r.next(e))}catch(e){i(e)}}function s(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}c((r=r.apply(e,t||[])).next())}))};const je="has-tried-autologin";function Pe(){const e=ae(je);if(e&&"object"!=typeof e)try{if(Date.now()-parseInt(e,10)<6e4)return!0}catch(e){ce(je)}return se(je,Date.now(),Date.now()+6e4),!1}const Ue=e=>Ne(void 0,void 0,void 0,(function*(){if(function(){try{return window.self!==window.top}catch(e){return!0}}())return;const{state:{isLoggedIn:n}}=yield(new we).fetch();if(!n)for(const n of e)if(!(yield n.handler().then((e=>{if(e){if(Pe())return!1;const e=new URL(`https://${i()}/aid/logg_inn/auto`);return e.searchParams.set("context",`auto_login_${n.name}`),e.searchParams.set("requestedUrl",t()),ue(e.href),!1}return!0}))))return}));var ke=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{c(r.next(e))}catch(e){i(e)}}function s(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}c((r=r.apply(e,t||[])).next())}))};const Le=[()=>Ne(void 0,void 0,void 0,(function*(){return Ue([{name:"third_party",handler:Ae}])})),function(){return Promise.all([Oe(),Te()])},function(){(new we).subscribe((({state:e})=>{!1===e.isLoggedIn&&(M("userAttributes",{}),M("storage",{}))}))}];var xe;!function(e){e.LOADED="amedia-user.janitor.loaded"}(xe||(xe={}));var Fe=n(483),De=n(808);let Me;const Be="undefined"==typeof self?window:self,$e="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||void 0!==Be.msCrypto&&"function"==typeof Be.msCrypto.getRandomValues&&Be.msCrypto.getRandomValues.bind(Be.msCrypto);if($e){const e=new Uint8Array(16);Me=function(){return $e(e),e}}else{const e=new Array(16);Me=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 Ve=[];for(let e=0;e<256;++e)Ve[e]=(e+256).toString(16).substr(1);function qe(){const e=Me();return e[6]=15&e[6]|64,e[8]=63&e[8]|128,function(e,t){let n=0;const r=Ve;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)}Fe.config({name:"aid:userdata"});const Ge=self.location.hostname.replace(/(.*\.)([^.]+\.\w+$)/,"$2");function Ke(){let e=De.get("amedia:fpbid");return e||(e=qe(),De.set("amedia:fpbid",e,{expires:3650,domain:Ge,sameSite:"strict"})),Promise.resolve(e)}function Ye(e){return De.set("amedia:visitid",e,{expires:new Date(Date.now()+18e5),domain:Ge,sameSite:"strict"}),Fe.setItem("visitid",e).then((()=>e))}function ze(){const e=Date.now();return Ye(`${qe()}|${e}`)}function He(){return function(){const e=De.get("amedia:visitid");return e?Promise.resolve(e):Fe.getItem("visitid")}().then((e=>e||ze())).then((e=>{const[t,n]=e.split("|");return!t||n&&Date.now()-18e5>n?ze():Ye(`${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))}}(He))));var We=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{c(r.next(e))}catch(e){i(e)}}function s(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}c((r=r.apply(e,t||[])).next())}))};const Qe=3e5,Je=(0,m.Record)({namespaces:(0,m.Dictionary)(m.Unknown,m.String)}),Xe=(e,t="GET",n)=>fetch(e,{method:t,body:n&&JSON.stringify(n),headers:{"Content-Type":"application/json",Accept:"application/json"}}),Ze=(e,t={ignoreCache:!1})=>We(void 0,void 0,void 0,(function*(){if(0===e.length)throw new Error("namespaces array cannot be of length 0");return C("europa",Je,(()=>Xe(`/api/europa/v1/me/${e.join(",")}`).then((t=>We(void 0,void 0,void 0,(function*(){const n=yield t.text();return t.ok?JSON.parse(n):(400!==t.status&&d(`Could not get namespaces for: ${e}, status: ${t.status}`,{response:t,body:n}),{namespaces:{}})})))).then((e=>({ttl:Qe,data:e})))),(n=>!t.ignoreCache||0===Object.keys(n.namespaces).filter((t=>!Object.keys(e).includes(t))).length)).then((e=>e.namespaces))}));const et=(0,m.Record)({allowResearchUsage:m.Boolean,connectWithSurveys:m.Boolean,personalizedAds:m.Boolean,personalizedContent:m.Boolean}),tt=e=>"true"===e||!0===e,nt=(0,m.Dictionary)(m.Unknown,m.String).And((0,m.Partial)({ad_segments:m.String,ad_segments_user:m.String,amedia_employee:m.Boolean,amedia_employee_user:m.Boolean,age:m.Number,age_user:m.Number,birth_year:m.String,birth_year_user:m.String,gender:m.String,gender_user:m.String,grunnkrets:m.String,grunnkrets_user:m.String,postcode:m.String,postcode_user:m.String,shared_account:m.Boolean,shared_account_user:m.Boolean,user_grouping_number:m.String,user_grouping_number_user:m.String})),rt=e=>({extraData:e}),ot=()=>new Promise((e=>{var t;const n=null===(t=B("state"))||void 0===t?void 0:t.isLoggedIn;!1!==n&&!0!==n?$("state",(({isLoggedIn:t})=>{!1!==t&&!0!==t||e(t)})):e(n)})),it=()=>new Promise((e=>ot().then((t=>{t&&e()})))),at={uuid:le,name:le,trackingKey:le,access:()=>it().then((()=>((e=["newspaper"])=>((e,t)=>C("checkForAccess",A,(()=>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=A.check(e);return{ttl:"granted"===t.access?1e4:0,data:t}}catch(t){throw d(t,{json:e}),t}})))).then((e=>({access:e.access_features}))))(o(),e))())),extraData:()=>Promise.all([Ke(),ot()]).then((([e,t])=>{var n;return((e,t,n)=>C("getNebulaInfo",nt,(()=>((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:nt.check(e)}}catch(t){throw d(t,{json:e}),t}}))})(e,t,n))).then(rt))(window.location.hostname,e,t?null===(n=B("userAttributes"))||void 0===n?void 0:n.trackingKey:void 0)})),privacyPreferences:()=>it().then((()=>{return e=void 0,t=void 0,r=function*(){return C("privacyPreferences",et,(()=>Ze(["privacy_preferences"]).then((e=>{const t=e.privacy_preferences;return{ttl:3e5,data:{allowResearchUsage:tt(t.allow_research_usage),connectWithSurveys:tt(t.connect_with_surveys),personalizedAds:tt(t.personalized_ads),personalizedContent:tt(t.personalized_content)}}})))).then((e=>({privacyPreferences:e})))},new((n=void 0)||(n=Promise))((function(o,i){function a(e){try{c(r.next(e))}catch(e){i(e)}}function s(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}c((r=r.apply(e,t||[])).next())}));var e,t,n,r}))};class st extends Error{constructor(e,t){super(e),this.code=t}}st.ERROR_RELOADED_NO_ACCESS="RELOADED_NO_ACCESS",st.ERROR_ENABLING_ACCESS_FAILED="ENABLING_ACCESS_FAILED",st.ERROR_NO_ACCESS_AFTER_SUCCESSFUL_ACTIVATION_WITH_REQUESTED_ACCESS_FEATURES="NO_ACCESS_AFTER_SUCCESSFUL_ACTIVATION_WITH_REQUESTED_ACCESS_FEATURES";const ct=st;var ut=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{c(r.next(e))}catch(e){i(e)}}function s(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}c((r=r.apply(e,t||[])).next())}))};const ft=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 ut(this,void 0,void 0,(function*(){const{state:{isLoggedIn:e}}=yield(new we).withAttributes(["name"]).fetch();if(!e)return yield Ne(void 0,void 0,void 0,(function*(){return Ue([{name:"paywall",handler:()=>Promise.resolve(!0)}])})),{isLoggedIn:!1,hasAccess:!1,accessFeatures:[]};let n=yield this.setAccessCookiesAndGetAccessFeatures(this.requestedAccessFeatures);if(n.denied){if(n=yield this.activateAccess(this.requestedAccessFeatures),n.denied)return{isLoggedIn:!0,hasAccess:!1,accessFeatures:n.accessFeatures};if(n=yield this.setAccessCookiesAndGetAccessFeatures(this.requestedAccessFeatures),n.denied)throw new ct("New subscription was attached and checked successfully, but internal systems disagree about current newspaper access.",ct.ERROR_NO_ACCESS_AFTER_SUCCESSFUL_ACTIVATION_WITH_REQUESTED_ACCESS_FEATURES)}if(this.reload||this.requestedUrl){if(r=this.requestedUrl,ae("aid-paywall-reload-performed")===(r||t()))throw new ct("Unlock check already performed.",ct.ERROR_RELOADED_NO_ACCESS);(e=>{const n=new Date;n.setTime(n.getTime()+12e4),se("aid-paywall-reload-performed",e||t(),n)})(this.requestedUrl),this.reload&&window.location.reload(),this.requestedUrl&&(e=>{window.location.replace(e)})(this.requestedUrl)}var r;return{isLoggedIn:!0,hasAccess:!0,accessFeatures:n.accessFeatures}}))}setAccessCookiesAndGetAccessFeatures(e){return(t=o(),de(void 0,void 0,void 0,(function*(){const e=[];return e.push(pe(t).catch((()=>Promise.resolve({success:!1,accessFeatures:[]})))),e.push(ye(t).catch((()=>Promise.resolve({success:!1,accessFeatures:[]})))),Promise.all(e).then((e=>e.reduce(((e,t)=>({success:e.success&&t.success,accessFeatures:e.accessFeatures.concat(t.accessFeatures).filter(((e,t,n)=>n.indexOf(e)===t)).sort()})),{success:!0,accessFeatures:[]})))}))).then((t=>{const n=!he(t.accessFeatures,e);if(!t.success&&n)throw new ct("Could not set access cookies",ct.ERROR_ENABLING_ACCESS_FAILED);return{denied:n,accessFeatures:t.accessFeatures}}));var t}activateAccess(e){return ut(this,void 0,void 0,(function*(){const t=yield ve(this.requestedAccessFeatures);return{denied:!he(t,e),accessFeatures:t}}))}},lt=e=>(e=>{const t=new URL(`https://${i()}/aid/logg_inn/${o()}/`);t.searchParams.set("requestedUrl",e instanceof URL?e.href:e),ue(t.href)})(e||t()),dt=()=>fe(),vt=e=>new Promise((t=>{y(ge.ON_ACTIVATION_COMPLETE,(n=>{const r=n.detail.accessFeatures;t({hasAccess:he(r,e),accessFeatures:r})})),g(new CustomEvent(ge.REQUEST_ACTIVATION,{detail:{accessFeatures:e}}))})),ht=e=>{g(new CustomEvent(me.UPDATE_STORAGE,{detail:e}))};"undefined"==typeof process&&(p(me.REQUEST_STATE,(()=>{const e=B("state");e&&Object.keys(e).length>0&&g(new CustomEvent(me.ON_STATE_UPDATED,{detail:e})),$("state",(e=>{g(new CustomEvent(me.ON_STATE_UPDATED,{detail:e}))}))})),$("userAttributes",(e=>{g(new CustomEvent(me.ON_ATTRIBUTES_UPDATED,{detail:e}))})),p(me.REQUEST_USER_ATTRIBUTES,(e=>{const t=e.detail,n=B("userAttributes")||{};Object.keys(n).length>0&&g(new CustomEvent(me.ON_ATTRIBUTES_UPDATED,{detail:n}));const r=t.filter((e=>void 0===n[e]));r.length>0&&(e=>{const t=[];e.forEach((e=>{const n=at[e];n?t.includes(n)||t.push(n):l(`Unknown attribute ${e} was requested`)}));const n=[];t.forEach((e=>{n.push(e().then((e=>{D("userAttributes",e)})).catch((t=>{l(`User attribute call failed (${e.toString()})`,t)})))})),Promise.all(n).then((()=>{}))})(r)})),$("storage",(e=>{g(new CustomEvent(me.ON_STORAGE_UPDATED,{detail:e}))})),p(me.REQUEST_STORAGE_NAMESPACES,(e=>{it().then((()=>{const t=e.detail,n=B("storage")||{};Object.keys(n).length>0&&g(new CustomEvent(me.ON_STORAGE_UPDATED,{detail:n}));const r=t.filter((e=>void 0===n[e]));r.length>0&&Ze(r).then((e=>{D("storage",e)}))}))})),p(me.UPDATE_STORAGE,(e=>{it().then((()=>{var t;t=e.detail,Object.keys(t).forEach((e=>((e,t)=>We(void 0,void 0,void 0,(function*(){const n=yield Xe(`/api/europa/v1/me/${e}`,"PATCH",t);return n.ok?((e,t)=>We(void 0,void 0,void 0,(function*(){const n=yield O("europa",Je),r=n?Object.assign(Object.assign({},n),{namespaces:Object.assign(Object.assign({},n.namespaces),{[e]:t})}):{namespaces:{[e]:t}};return T("europa",r,Date.now()+Qe)})))(e,t):(d(`Could not get namespace: ${e}, status: ${n.status}, statusText: ${n.statusText}`,n),{})})))(e,t[e])))}))})),ke(void 0,void 0,void 0,(function*(){let e=!1;p(xe.LOADED,(()=>{e||(e=!0,function(){ke(this,void 0,void 0,(function*(){for(const e of Le)yield e()}))}())})),g(new CustomEvent(xe.LOADED))})))})();var o=r.Hr,i=r.vg,a=r.EX,s=r.kS,c=r.Lk,u=r.Hc;export{o as PaywallUnlockRequest,i as UserDataRequest,a as goToLoginPage,s as logout,c as tryActivateSubscriptionAccess,u as updateStorage};
package/eik.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "user-js",
3
- "version": "0.13.4",
3
+ "version": "0.13.9",
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.13.7",
3
+ "version": "0.13.9",
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)",
@@ -5,7 +5,11 @@
5
5
  import store from '../store';
6
6
 
7
7
  import * as thirdPartyCookie from './thirdPartyCookie';
8
- import { attemptAutologin, AUTOLOGIN_COOKIE_TTL } from './index';
8
+ import {
9
+ attemptAutoLoginJob,
10
+ attemptPaywallAutoLogin,
11
+ AUTOLOGIN_COOKIE_TTL,
12
+ } from './index';
9
13
  import * as location from '../utils/location';
10
14
  import * as url from '../utils/url';
11
15
  import * as cookie from '../lib/cookie';
@@ -21,36 +25,42 @@ function itShouldNotNavigateAway() {
21
25
  });
22
26
  }
23
27
 
24
- function itShouldNotAttemptAutoLogin() {
25
- it('should not try third party auto login', () => {
26
- expect(thirdPartyCookie.default).toHaveBeenCalledTimes(0);
28
+ function itShouldCallThirdPartyCookieStrategy() {
29
+ it('should try third party auto login', () => {
30
+ expect(thirdPartyCookie.default).toHaveBeenCalledTimes(1);
27
31
  });
28
32
  }
29
33
 
30
- function itShouldAttemptAutoLogin() {
31
- it('should try third party auto login', () => {
32
- expect(thirdPartyCookie.default).toHaveBeenCalledTimes(1);
34
+ function itShouldNavigateToAutoLogin(context) {
35
+ it(`should navigate to auto with context ${context}`, async () => {
36
+ expect(location.navigateTo).toHaveBeenCalledWith(
37
+ `https://www.aid.no/aid/logg_inn/auto?context=auto_login_${context}&requestedUrl=https%3A%2F%2Fwww.avisnavn.no%2Fabo%2F%3Fquery%3Dparam`
38
+ );
33
39
  });
34
40
  }
35
41
 
36
- describe('autologin', () => {
42
+ let getCookieSpy: jasmine.Spy;
43
+
44
+ beforeEach(() => {
45
+ restoreAllMocks();
46
+ resetAllMocks();
47
+ spyOn(location, 'navigateTo');
48
+ spyOn(url, 'getAidDomain').and.returnValue('www.aid.no');
49
+ spyOn(url, 'getCurrentUrl').and.returnValue(
50
+ 'https://www.avisnavn.no/abo/?query=param'
51
+ );
52
+ getCookieSpy = spyOn(cookie, 'getCookie').and.returnValue('0');
53
+ spyOn(cookie, 'setCookie');
54
+ });
55
+
56
+ describe('attemptAutoLoginJob', () => {
37
57
  let shouldPerformAutoLogin = false;
38
- let getCookieSpy: jasmine.Spy;
39
58
 
40
59
  beforeEach(() => {
41
- restoreAllMocks();
42
- resetAllMocks();
43
60
  shouldPerformAutoLogin = false;
44
- spyOn(location, 'navigateTo');
45
- spyOn(url, 'getAidDomain').and.returnValue('www.aid.no');
46
- spyOn(url, 'getCurrentUrl').and.returnValue(
47
- 'https://www.avisnavn.no/abo/?query=param'
48
- );
49
61
  jest
50
62
  .spyOn(thirdPartyCookie, 'default')
51
63
  .mockImplementation(() => Promise.resolve(shouldPerformAutoLogin));
52
- getCookieSpy = spyOn(cookie, 'getCookie').and.returnValue('0');
53
- spyOn(cookie, 'setCookie');
54
64
  });
55
65
 
56
66
  describe('when already logged in', () => {
@@ -68,7 +78,7 @@ describe('autologin', () => {
68
78
  });
69
79
  });
70
80
  store.set('state', { isLoggedIn: true });
71
- await attemptAutologin();
81
+ await attemptAutoLoginJob();
72
82
  });
73
83
 
74
84
  it('should not try third party auto login', () => {
@@ -99,36 +109,31 @@ describe('autologin', () => {
99
109
  delete global.top; // Set window.top to something other than window.self
100
110
  // @ts-ignore
101
111
  global.top = {};
102
- await attemptAutologin();
112
+ await attemptAutoLoginJob();
103
113
  });
104
114
  afterEach(() => {
105
115
  // @ts-ignore
106
116
  global.top = originalTop;
107
117
  });
108
118
 
109
- itShouldNotAttemptAutoLogin();
110
119
  itShouldNotNavigateAway();
111
120
  });
112
121
 
113
122
  describe('when a strategy triggers auto login', () => {
114
123
  beforeEach(async () => {
115
124
  shouldPerformAutoLogin = true;
116
- await attemptAutologin();
125
+ await attemptAutoLoginJob();
117
126
  });
118
127
 
119
- itShouldAttemptAutoLogin();
120
- it('should navigate to auto', async () => {
121
- expect(location.navigateTo).toHaveBeenCalledWith(
122
- 'https://www.aid.no/aid/logg_inn/auto?context=auto_login_third_party&requestedUrl=https%3A%2F%2Fwww.avisnavn.no%2Fabo%2F%3Fquery%3Dparam'
123
- );
124
- });
128
+ itShouldCallThirdPartyCookieStrategy();
129
+ itShouldNavigateToAutoLogin('third_party');
125
130
  });
126
131
  describe('when no strategy triggers auto login', () => {
127
132
  beforeEach(async () => {
128
- await attemptAutologin();
133
+ await attemptAutoLoginJob();
129
134
  });
130
135
 
131
- itShouldAttemptAutoLogin();
136
+ itShouldCallThirdPartyCookieStrategy();
132
137
  itShouldNotNavigateAway();
133
138
  });
134
139
 
@@ -136,9 +141,10 @@ describe('autologin', () => {
136
141
  describe('when tried within the last minute', () => {
137
142
  beforeEach(async () => {
138
143
  getCookieSpy.and.returnValue(Date.now());
139
- await attemptAutologin();
144
+ await attemptAutoLoginJob();
140
145
  });
141
- itShouldNotAttemptAutoLogin();
146
+ itShouldCallThirdPartyCookieStrategy();
147
+ itShouldNotNavigateAway();
142
148
  });
143
149
 
144
150
  describe('when last attempt is old', () => {
@@ -146,9 +152,97 @@ describe('autologin', () => {
146
152
  getCookieSpy.and.returnValue(
147
153
  Date.now() - AUTOLOGIN_COOKIE_TTL - 1000
148
154
  );
149
- await attemptAutologin();
155
+ await attemptAutoLoginJob();
156
+ });
157
+ itShouldCallThirdPartyCookieStrategy();
158
+ itShouldNotNavigateAway();
159
+ });
160
+ });
161
+ });
162
+ });
163
+
164
+ describe('attemptPaywallAutoLogin', () => {
165
+ beforeEach(() => {});
166
+
167
+ describe('when already logged in', () => {
168
+ beforeEach(async () => {
169
+ jest
170
+ .spyOn(UserDataRequest.prototype, 'subscribe')
171
+ .mockImplementation((callback) => {
172
+ callback({
173
+ attributes: {
174
+ name: 'Some name',
175
+ },
176
+ state: {
177
+ isLoggedIn: true,
178
+ },
179
+ });
180
+ });
181
+ store.set('state', { isLoggedIn: true });
182
+ await attemptPaywallAutoLogin();
183
+ });
184
+ });
185
+
186
+ describe('when not already logged in', () => {
187
+ beforeEach(async () => {
188
+ jest
189
+ .spyOn(UserDataRequest.prototype, 'subscribe')
190
+ .mockImplementation((callback) => {
191
+ callback({
192
+ attributes: {},
193
+ state: {
194
+ isLoggedIn: false,
195
+ },
196
+ });
197
+ });
198
+ store.set('state', { isLoggedIn: false });
199
+ });
200
+
201
+ describe('when in iframe (Dr. Edition)', () => {
202
+ let originalTop;
203
+ beforeEach(async () => {
204
+ originalTop = global.top;
205
+ // @ts-ignore
206
+ delete global.top; // Set window.top to something other than window.self
207
+ // @ts-ignore
208
+ global.top = {};
209
+ await attemptPaywallAutoLogin();
210
+ });
211
+ afterEach(() => {
212
+ // @ts-ignore
213
+ global.top = originalTop;
214
+ });
215
+
216
+ itShouldNotNavigateAway();
217
+ });
218
+
219
+ describe('when not in iframe', () => {
220
+ describe('when already tried cookie is not found', () => {
221
+ beforeEach(async () => {
222
+ getCookieSpy.and.returnValue(undefined);
223
+ await attemptPaywallAutoLogin();
224
+ });
225
+ itShouldNavigateToAutoLogin('paywall');
226
+ });
227
+
228
+ describe('when already tried cookie was found', () => {
229
+ describe('when tried within the last minute', () => {
230
+ beforeEach(async () => {
231
+ getCookieSpy.and.returnValue(Date.now());
232
+ await attemptPaywallAutoLogin();
233
+ });
234
+ itShouldNotNavigateAway();
235
+ });
236
+
237
+ describe('when last attempt is old', () => {
238
+ beforeEach(async () => {
239
+ getCookieSpy.and.returnValue(
240
+ Date.now() - AUTOLOGIN_COOKIE_TTL - 1000
241
+ );
242
+ await attemptPaywallAutoLogin();
243
+ });
244
+ itShouldNavigateToAutoLogin('paywall');
150
245
  });
151
- itShouldAttemptAutoLogin();
152
246
  });
153
247
  });
154
248
  });
@@ -4,16 +4,9 @@ import { navigateTo } from '../utils/location';
4
4
  import { getCookie, removeCookie, setCookie } from '../lib/cookie';
5
5
  import UserDataRequest from '../lib/UserDataRequest';
6
6
 
7
- const AUTOLOGIN_COOKIE = 'have-tried-autologin';
7
+ const AUTOLOGIN_COOKIE = 'has-tried-autologin';
8
8
  export const AUTOLOGIN_COOKIE_TTL = 60000; // One minute
9
9
 
10
- const strategies = [
11
- {
12
- name: 'third_party',
13
- handler: thirdPartyCookie,
14
- },
15
- ];
16
-
17
10
  function inIframe() {
18
11
  try {
19
12
  return window.self !== window.top;
@@ -22,7 +15,7 @@ function inIframe() {
22
15
  }
23
16
  }
24
17
 
25
- function haveAlreadyAttemptedAutoLogin() {
18
+ function hasAlreadyAttemptedAutoLogin() {
26
19
  const cookie = getCookie(AUTOLOGIN_COOKIE);
27
20
  if (cookie && typeof cookie !== 'object') {
28
21
  try {
@@ -37,7 +30,7 @@ function haveAlreadyAttemptedAutoLogin() {
37
30
  return false;
38
31
  }
39
32
 
40
- export const attemptAutologin = async () => {
33
+ const attemptAutologin = async (strategies) => {
41
34
  if (inIframe()) {
42
35
  // Avoid auto-login on preview for dr edition.
43
36
  return;
@@ -50,10 +43,6 @@ export const attemptAutologin = async () => {
50
43
  return;
51
44
  }
52
45
 
53
- if (haveAlreadyAttemptedAutoLogin()) {
54
- return;
55
- }
56
-
57
46
  // eslint-disable-next-line no-restricted-syntax
58
47
  for (const strategy of strategies) {
59
48
  // eslint-disable-next-line no-await-in-loop
@@ -61,6 +50,10 @@ export const attemptAutologin = async () => {
61
50
  .handler()
62
51
  .then((shouldPerformAutoLogin) => {
63
52
  if (shouldPerformAutoLogin) {
53
+ if (hasAlreadyAttemptedAutoLogin()) {
54
+ return false;
55
+ }
56
+
64
57
  // Try to get newspaper cookie
65
58
  const url = new URL(`https://${getAidDomain()}/aid/logg_inn/auto`);
66
59
  url.searchParams.set('context', `auto_login_${strategy.name}`);
@@ -76,3 +69,19 @@ export const attemptAutologin = async () => {
76
69
  }
77
70
  }
78
71
  };
72
+
73
+ export const attemptAutoLoginJob = async () =>
74
+ attemptAutologin([
75
+ {
76
+ name: 'third_party',
77
+ handler: thirdPartyCookie,
78
+ },
79
+ ]);
80
+
81
+ export const attemptPaywallAutoLogin = async () =>
82
+ attemptAutologin([
83
+ {
84
+ name: 'paywall',
85
+ handler: () => Promise.resolve(true),
86
+ },
87
+ ]);
@@ -3,10 +3,7 @@
3
3
  */
4
4
 
5
5
  import fetch from 'jest-fetch-mock';
6
- import backendLog, {
7
- activateSubscription,
8
- UserDeactivatedError,
9
- } from './mercury';
6
+ import { activateSubscription, UserDeactivatedError } from './mercury';
10
7
  import restoreAllMocks = jest.restoreAllMocks;
11
8
 
12
9
  beforeEach(() => {
@@ -14,24 +11,6 @@ beforeEach(() => {
14
11
  fetch.resetMocks();
15
12
  });
16
13
 
17
- describe('Mercury backendlog', () => {
18
- it('should include level in url', () => {
19
- backendLog.error('jest message', {});
20
- expect(fetch).toHaveBeenCalledWith(
21
- expect.stringContaining('/error'),
22
- expect.anything()
23
- );
24
- expect(fetch).toHaveBeenCalledTimes(1);
25
- });
26
-
27
- it('should include additional context as query parameters', () => {
28
- backendLog.error('jest message', { referrer: 'https://www.rb.no/' });
29
- const formData = fetch.mock.calls[0][1]?.body as FormData;
30
-
31
- expect(formData?.get('referrer')).toEqual('https://www.rb.no/');
32
- });
33
- });
34
-
35
14
  describe('activateSubscription()', () => {
36
15
  it('should throw error if user is deactivated', async () => {
37
16
  fetch.mockResponse(JSON.stringify({ status: 'user_deactivated' }), {
@@ -1,58 +1,5 @@
1
- import {
2
- getCurrentHostname,
3
- getCurrentPublicationDomain,
4
- getCurrentUrl,
5
- } from '../utils/url';
6
-
7
- function postLog(url: string, query: { [index: string]: any }) {
8
- const body = new FormData();
9
- Object.keys(query).forEach((key) => body.append(key, query[key]));
10
- const options: RequestInit = {
11
- method: 'POST',
12
- body,
13
- headers: {
14
- Accept: 'application/json',
15
- },
16
- };
17
- fetch(url, options).then((res) => {
18
- if (!res.ok) {
19
- throw new Error(`Error, status: ${res.status}, text: ${res.statusText}`);
20
- }
21
- });
22
- }
23
-
24
- const backendLog = (level: string, message: string, context: Object) => {
25
- const internalContext = {};
26
- Object.keys(context).forEach((key) => {
27
- if (['string', 'number', 'boolean'].includes(typeof context[key])) {
28
- internalContext[key] = context[key];
29
- return;
30
- }
31
- try {
32
- internalContext[key] = JSON.stringify(context[key]);
33
- } catch (e) {
34
- internalContext[key] = context[key];
35
- }
36
- });
37
- const extendedContext = {
38
- ...internalContext,
39
- message,
40
- url: getCurrentUrl(),
41
- domain: getCurrentHostname(),
42
- };
43
- postLog(`/api/mercury/v1/log/${level}`, extendedContext);
44
- };
45
-
46
- const log = {
47
- error: (message: string, context: Object) =>
48
- backendLog('error', message, context),
49
- warn: (message: string, context: Object) =>
50
- backendLog('warn', message, context),
51
- info: (message: string, context: Object) =>
52
- backendLog('info', message, context),
53
- debug: (message: string, context: Object) =>
54
- backendLog('debug', message, context),
55
- };
1
+ import log from '../utils/log';
2
+ import { getCurrentPublicationDomain } from '../utils/url';
56
3
 
57
4
  export class UserDeactivatedError extends Error {}
58
5
 
@@ -73,17 +20,24 @@ export const activateSubscription = async (
73
20
  data = JSON.parse(body);
74
21
  } catch (error) {
75
22
  log.error(
76
- 'Activate subscription. Response from mercury does not contain parsable json',
23
+ `Activate subscription failed. Mercury (HTTP/${response.status}: ${body})`,
77
24
  { error, response, accessFeatures, body }
78
25
  );
79
26
  }
80
27
  if (!response.ok) {
28
+ // User deactivated
81
29
  if (response.status === 401 && data?.status === 'user_deactivated') {
82
30
  throw new UserDeactivatedError();
83
31
  }
32
+ // Not logged in
33
+ if (response.status === 400 && data?.status === 'no_session_found') {
34
+ return [];
35
+ }
36
+ log.error(
37
+ `Activate subscription failed. Mercury (HTTP/${response.status}: ${body})`,
38
+ { response, accessFeatures, body }
39
+ );
84
40
  return [];
85
41
  }
86
42
  return data?.access_features;
87
43
  });
88
-
89
- export default log;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+
5
+ import fetch from 'jest-fetch-mock';
6
+ import backendLog from './mercuryLog';
7
+ import restoreAllMocks = jest.restoreAllMocks;
8
+
9
+ beforeEach(() => {
10
+ restoreAllMocks();
11
+ fetch.resetMocks();
12
+ });
13
+
14
+ describe('Mercury backendlog', () => {
15
+ it('should include level in url', () => {
16
+ backendLog.error('jest message', {});
17
+ expect(fetch).toHaveBeenCalledWith(
18
+ expect.stringContaining('/error'),
19
+ expect.anything()
20
+ );
21
+ expect(fetch).toHaveBeenCalledTimes(1);
22
+ });
23
+
24
+ it('should include additional context as query parameters', () => {
25
+ backendLog.error('jest message', { referrer: 'https://www.rb.no/' });
26
+ const formData = fetch.mock.calls[0][1]?.body as FormData;
27
+
28
+ expect(formData?.get('referrer')).toEqual('https://www.rb.no/');
29
+ });
30
+ });
@@ -0,0 +1,56 @@
1
+ import { getCurrentHostname, getCurrentUrl } from '../utils/url';
2
+
3
+ /**
4
+ * Extracted from mercury.tsx so other calls to mercury can log properly
5
+ */
6
+ function postLog(url: string, query: { [index: string]: any }) {
7
+ const body = new FormData();
8
+ Object.keys(query).forEach((key) => body.append(key, query[key]));
9
+ const options: RequestInit = {
10
+ method: 'POST',
11
+ body,
12
+ headers: {
13
+ Accept: 'application/json',
14
+ },
15
+ };
16
+ fetch(url, options).then((res) => {
17
+ if (!res.ok) {
18
+ throw new Error(`Error, status: ${res.status}, text: ${res.statusText}`);
19
+ }
20
+ });
21
+ }
22
+
23
+ const backendLog = (level: string, message: string, context: Object) => {
24
+ const internalContext = {};
25
+ Object.keys(context).forEach((key) => {
26
+ if (['string', 'number', 'boolean'].includes(typeof context[key])) {
27
+ internalContext[key] = context[key];
28
+ return;
29
+ }
30
+ try {
31
+ internalContext[key] = JSON.stringify(context[key]);
32
+ } catch (e) {
33
+ internalContext[key] = context[key];
34
+ }
35
+ });
36
+ const extendedContext = {
37
+ ...internalContext,
38
+ message,
39
+ url: getCurrentUrl(),
40
+ domain: getCurrentHostname(),
41
+ };
42
+ postLog(`/api/mercury/v1/log/${level}`, extendedContext);
43
+ };
44
+
45
+ const log = {
46
+ error: (message: string, context: Object) =>
47
+ backendLog('error', message, context),
48
+ warn: (message: string, context: Object) =>
49
+ backendLog('warn', message, context),
50
+ info: (message: string, context: Object) =>
51
+ backendLog('info', message, context),
52
+ debug: (message: string, context: Object) =>
53
+ backendLog('debug', message, context),
54
+ };
55
+
56
+ export default log;
@@ -1,9 +1,9 @@
1
1
  import accessCookieRefresher from './jobs/accessCookieRefresher';
2
2
  import { removeUserStorage } from './jobs/removeUserStorage';
3
3
  import { dispatch, listenWithExclusivity } from '../utils/customEventWrapper';
4
- import { attemptAutologin } from '../autologin';
4
+ import { attemptAutoLoginJob } from '../autologin';
5
5
 
6
- const jobs = [attemptAutologin, accessCookieRefresher, removeUserStorage];
6
+ const jobs = [attemptAutoLoginJob, accessCookieRefresher, removeUserStorage];
7
7
 
8
8
  async function performJobs() {
9
9
  // eslint-disable-next-line no-restricted-syntax
@@ -58,7 +58,7 @@ function itShouldAttemptActivationWithAccessFeatures(accessFeatures: string[]) {
58
58
 
59
59
  describe('PaywallUnlocker', () => {
60
60
  beforeEach(() => {
61
- spyOn(autologin, 'attemptAutologin').mockResolvedValue();
61
+ spyOn(autologin, 'attemptPaywallAutoLogin').mockResolvedValue();
62
62
  spyOn(authorization, 'setHasPerformedPaywallReload');
63
63
  spyOn(authorization, 'activate');
64
64
  spyOn(location, 'reload').mockReturnValue();
@@ -74,7 +74,7 @@ describe('PaywallUnlocker', () => {
74
74
  });
75
75
 
76
76
  it('should attempt autologin', async () => {
77
- expect(autologin.attemptAutologin).toHaveBeenCalledTimes(1);
77
+ expect(autologin.attemptPaywallAutoLogin).toHaveBeenCalledTimes(1);
78
78
  });
79
79
 
80
80
  it('should return no access', () => {
@@ -96,7 +96,7 @@ describe('PaywallUnlocker', () => {
96
96
  });
97
97
 
98
98
  it('should not attempt autologin', () => {
99
- expect(autologin.attemptAutologin).not.toHaveBeenCalled();
99
+ expect(autologin.attemptPaywallAutoLogin).not.toHaveBeenCalled();
100
100
  });
101
101
 
102
102
  itShouldNotRedirect();
@@ -9,7 +9,7 @@ import { getCurrentPublicationDomain } from '../utils/url';
9
9
  import * as location from '../utils/location';
10
10
  import PaywallError from '../exceptions/PaywallError';
11
11
  import UserDataRequest from './UserDataRequest';
12
- import { attemptAutologin } from '../autologin';
12
+ import { attemptPaywallAutoLogin } from '../autologin';
13
13
 
14
14
  type UnlockResponse = {
15
15
  isLoggedIn: boolean;
@@ -42,11 +42,11 @@ class PaywallUnlockRequest {
42
42
  public async tryUnlock(): Promise<UnlockResponse> {
43
43
  const {
44
44
  state: { isLoggedIn },
45
- } = await new UserDataRequest().fetch();
45
+ } = await new UserDataRequest().withAttributes(['name']).fetch();
46
46
  if (!isLoggedIn) {
47
47
  // Will attempt one or more strategies for creating a first party session
48
48
  // Redirects/reloads might occur
49
- await attemptAutologin();
49
+ await attemptPaywallAutoLogin();
50
50
  return {
51
51
  isLoggedIn: false,
52
52
  hasAccess: false,
package/src/utils/log.ts CHANGED
@@ -1,4 +1,4 @@
1
- import mercury from '../clients/mercury';
1
+ import mercury from '../clients/mercuryLog';
2
2
 
3
3
  export type Logger = {
4
4
  debug: (message: string | Error, context?: Object) => void;