@amedia/user 0.12.20 → 0.12.30
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.
- package/dist/index.js +1 -1
- package/eik.json +1 -1
- package/package.json +1 -1
- package/src/actions/userData.spec.ts +31 -0
- package/src/clients/jupiter.spec.ts +28 -0
- package/src/clients/jupiter.ts +29 -27
- package/src/clients/pluto.spec.ts +44 -18
- package/src/clients/pluto.ts +14 -4
- package/src/lib/PaywallUnlockRequest.spec.ts +2 -0
- package/src/lib/PaywallUnlockRequest.ts +1 -1
- package/src/lib/UserDataRequest.ts +1 -2
- package/src/lib/UserDataRequest.spec.ts +0 -58
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e={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,l=a.FAILURE.ARGUMENT_INCORRECT(u);throw new i.ValidationError(l)}for(var f=0;f<s.length;f++)s[f].check(t[f]);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,l=a.FAILURE.RETURN_INCORRECT(u),new i.ValidationError(l);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,l=a.FAILURE.ARGUMENT_INCORRECT(u);throw new i.ValidationError(l)}for(var f=0;f<s.length;f++)s[f].check(t[f]);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,l=o.FAILURE.ARGUMENT_INCORRECT(s);throw new r.ValidationError(l)}})),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],l=c[1];if(u.guard(t))return l(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),l={tag:"dictionary",key:u,value:e};return r.create((function(t,o){if(null==t||"object"!=typeof t)return s.FAILURE.TYPE_INCORRECT(l,t);if(Object.getPrototypeOf(t)!==Object.prototype&&(!Array.isArray(t)||"string"===u))return s.FAILURE.TYPE_INCORRECT(l,t);var a=/^(?:NaN|-?\d+(?:\.\d+)?)$/u,c=s.enumerableKeysOf(t),f=c.reduce((function(c,u){var f="string"==typeof u&&a.test(u),d=f?n.g.Number(u):u;return(f?i.guard(d)||i.guard(u):i.guard(d))?c[u]=r.innerValidate(e,t[u],o):c[u]=s.FAILURE.KEY_INCORRECT(l,i.reflect,d),c}),{}),d=c.reduce((function(e,t){var n=f[t];return n.success||(e[t]=n.details||n.message),e}),{});return 0!==s.enumerableKeysOf(d).length?s.FAILURE.CONTENT_INCORRECT(l,d):s.SUCCESS(t)}),l)}},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 l=u.value,f=o.innerValidate(l,t,n);if(!f.success)return f}}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 l=o([],r(new Set(o(o([],r(c)),r(a.enumerableKeysOf(n)))))),f=l.reduce((function(r,o){var c=a.hasKey(o,e),u=a.hasKey(o,n);if(c){var l=e[o],f=t||"optional"===l.reflect.tag;if(u){var d=n[o];r[o]=f&&void 0===d?a.SUCCESS(d):i.innerValidate(l,d,s)}else r[o]=f?a.SUCCESS(void 0):a.FAILURE.PROPERTY_MISSING(l.reflect)}else{if(!u)throw new Error("impossible");d=n[o],r[o]=a.SUCCESS(d)}return r}),{}),d=l.reduce((function(e,t){var n=f[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,l,f,d,v,h;if("object"!=typeof t||null===t){try{for(var E=r(e),y=E.next();!y.done;y=E.next()){var p=y.value;if(o.innerValidate(p,t,n).success)return i.SUCCESS(t)}}catch(e){s={error:e}}finally{try{y&&!y.done&&(c=E.return)&&c.call(E)}finally{if(s)throw s.error}}return i.FAILURE.TYPE_INCORRECT(a,t)}var g={};try{for(var _=r(e),R=_.next();!R.done;R=_.next())if("record"===(p=R.value).reflect.tag){var m=function(e){var t=p.reflect.fields[e];"literal"===t.tag&&(g[e]?g[e].every((function(e){return e!==t.value}))&&g[e].push(t.value):g[e]=[t.value])};for(var C in p.reflect.fields)m(C)}}catch(e){u={error:e}}finally{try{R&&!R.done&&(l=_.return)&&l.call(_)}finally{if(u)throw u.error}}for(var C in g)if(g[C].length===e.length)try{for(var O=(f=void 0,r(e)),S=O.next();!S.done;S=O.next())if("record"===(p=S.value).reflect.tag){var T=p.reflect.fields[C];if("literal"===T.tag&&i.hasKey(C,t)&&t[C]===T.value)return o.innerValidate(p,t,n)}}catch(e){f={error:e}}finally{try{S&&!S.done&&(d=O.return)&&d.call(O)}finally{if(f)throw f.error}}try{for(var b=r(e),w=b.next();!w.done;w=b.next()){var A=w.value;if(o.innerValidate(A,t,n).success)return i.SUCCESS(t)}}catch(e){v={error:e}}finally{try{w&&!w.done&&(h=b.return)&&h.call(b)}finally{if(v)throw v.error}}return i.FAILURE.TYPE_INCORRECT(a,t)}),a)}},101:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Unknown=void 0;var r=n(732),o=n(611);t.Unknown=r.create((function(e){return o.SUCCESS(e)}),{tag:"unknown"})},203:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Void=void 0;var r=n(101);t.Void=r.Unknown},611:function(e,t,n){var r=this&&this.__assign||function(){return(r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};Object.defineProperty(t,"__esModule",{value:!0}),t.FAILURE=t.SUCCESS=t.enumerableKeysOf=t.typeOf=t.hasKey=void 0;var o=n(691),i=n(233);t.hasKey=function(e,t){return"object"==typeof t&&null!==t&&e in t},t.typeOf=function(e){return"object"==typeof e?null===e?"null":Array.isArray(e)?"array":"Object"===e.constructor.name?"object":e.constructor.name:typeof e},t.enumerableKeysOf=function(e){return"object"==typeof e&&null!==e?Reflect.ownKeys(e).filter((function(t){var n,r;return null===(r=null===(n=e.propertyIsEnumerable)||void 0===n?void 0:n.call(e,t))||void 0===r||r})):[]},t.SUCCESS=function(e){return{success:!0,value:e}},t.FAILURE=Object.assign((function(e,t,n){return r({success:!1,code:e,message:t},n?{details:n}:{})}),{TYPE_INCORRECT:function(e,n){var r="Expected "+i.default(e)+", but was "+t.typeOf(n);return t.FAILURE(o.Failcode.TYPE_INCORRECT,r)},VALUE_INCORRECT:function(e,n,r){return t.FAILURE(o.Failcode.VALUE_INCORRECT,"Expected "+e+" "+String(n)+", but was "+String(r))},KEY_INCORRECT:function(e,n,r){return t.FAILURE(o.Failcode.KEY_INCORRECT,"Expected "+i.default(e)+" key to be "+i.default(n)+", but was "+t.typeOf(r))},CONTENT_INCORRECT:function(e,n){var r="Expected "+i.default(e)+", but was incompatible";return t.FAILURE(o.Failcode.CONTENT_INCORRECT,r,n)},ARGUMENT_INCORRECT:function(e){return t.FAILURE(o.Failcode.ARGUMENT_INCORRECT,e)},RETURN_INCORRECT:function(e){return t.FAILURE(o.Failcode.RETURN_INCORRECT,e)},CONSTRAINT_FAILED:function(e,n){var r=n?": "+n:"";return t.FAILURE(o.Failcode.CONSTRAINT_FAILED,"Failed constraint check for "+i.default(e)+r)},PROPERTY_MISSING:function(e){var n="Expected "+i.default(e)+", but was missing";return t.FAILURE(o.Failcode.PROPERTY_MISSING,n)},PROPERTY_PRESENT:function(e){var n="Expected nothing, but was "+t.typeOf(e);return t.FAILURE(o.Failcode.PROPERTY_PRESENT,n)},NOTHING_EXPECTED:function(e){var n="Expected nothing, but was "+t.typeOf(e);return t.FAILURE(o.Failcode.NOTHING_EXPECTED,n)}})},905:(e,t)=>{var n=function(e){if("object"==typeof e&&null!==e){if("function"==typeof Object.getPrototypeOf){var t=Object.getPrototypeOf(e);return t===Object.prototype||null===t}return"[object Object]"===Object.prototype.toString.call(e)}return!1},r=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return e.reduce((function(e,t){return Object.keys(t).forEach((function(o){Array.isArray(e[o])&&Array.isArray(t[o])?e[o]=Array.from(new Set(e[o].concat(t[o]))):n(e[o])&&n(t[o])?e[o]=r(e[o],t[o]):e[o]=t[o]})),e}),{})};t.Z=r}},t={};function n(r){var o=t[r];if(void 0!==o)return o.exports;var i=t[r]={exports:{}};return e[r].call(i.exports,i,i.exports,n),i.exports}n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var r={};(()=>{n.d(r,{EX:()=>Oe,kS:()=>Se,$s:()=>Ce,Lk:()=>Te,Hc:()=>be,EA:()=>me});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)=>{!function(e,t){const n=new FormData;Object.keys(t).forEach((e=>n.append(e,t[e]))),fetch(e,{method:"POST",body:n,headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json"}}).then((e=>{if(!e.ok)throw new Error(`Error, status: ${e.status}, text: ${e.statusText}`)}))}(`//www.aid.no/api/mercury/v1/log/${n}`,Object.assign(Object.assign({},o),{message:r,url:t(),domain:e()}))},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 l=c;const f=(e,...t)=>{l.error(e,...t)};let d;var v;"undefined"!=typeof window&&(v=window,d=v);const h=(e,t)=>{d?d.addEventListener(e,(e=>{e.stopImmediatePropagation(),t.apply(d,[e])})):f("No root element to bind event to!")},E=(e,t)=>{d?d.addEventListener(e,(e=>{t.apply(d,[e])})):f("No root element to bind event to!")},y=e=>{d?d.dispatchEvent(e):f("No root element to dispatch event on!")};var p=n(529);function g(e,t,n){let r;const o=[];t instanceof p.ValidationError?(r=`Invalid ${e}`,o.push(t.details)):(r=`Unknown error after validating ${e}: (${t.message}`,o.push(t)),n&&o.push(n),f(r,...o)}const _=(0,p.Record)({id:p.Number,domain:p.String}),R=((0,p.Record)({status:(0,p.Literal)("success"),access:(0,p.Union)((0,p.Literal)("granted"),(0,p.Literal)("denied")),publication:_,access_features:(0,p.Array)(p.String)}),(0,p.Record)({status:(0,p.Literal)("success"),cookie:p.String,access_features:(0,p.Array)(p.String)})),m=(0,p.Record)({status:(0,p.Literal)("success"),vstoken_cookie:p.String,uuid:p.String,access_features:(0,p.Array)(p.String)});var C=n(905);const O={},S={},T=(e,t)=>{O[e]=t,(e=>{var t;null===(t=S[e])||void 0===t||t.forEach((t=>t(O[e])))})(e)},b=(e,t)=>{T(e,(0,C.Z)(O[e]||{},t))},w=T,A=e=>O[e];var I=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 N=(0,p.Partial)({user_uuid:p.String,user_name:p.String,tracking_key:p.String}),U=()=>{const e="undefined"!=typeof window?window:n.g;return e.amediaUserCache||(e.amediaUserCache={})},P={get:e=>{const t=U()[e];return Promise.resolve(t)},set:(e,t,n)=>(U()[e]={key:e,data:t,expires:n},Promise.resolve()),remove:e=>(delete U()[e],Promise.resolve()),clear:()=>(("undefined"!=typeof window?window:n.g).amediaUserCache={},Promise.resolve())};const L=()=>P,j=e=>L().remove(e),F=(e,t)=>{return n=void 0,r=void 0,i=function*(){const n=yield L().get(e);if(!n)return Promise.resolve();if(Date.now()>n.expires)return j(e),Promise.resolve();try{return t.check(n.data)}catch(t){return g("cache engine schema",t,{data:n.data}),j(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};let k;const x=self||window,D="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||void 0!==x.msCrypto&&"function"==typeof x.msCrypto.getRandomValues&&x.msCrypto.getRandomValues.bind(x.msCrypto);if(D){const e=new Uint8Array(16);k=function(){return D(e),e}}else{const e=new Array(16);k=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 M=[];for(let e=0;e<256;++e)M[e]=(e+256).toString(16).substr(1);function $(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=k();return e[6]=15&e[6]|64,e[8]=63&e[8]|128,function(e,t){let n=0;const r=M;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 V{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]=$(this.component,e),this[e](...t)}}}let G;const Y=(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},K=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 Y(t,r)}return null};function q(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===K(e)&&(document.cookie=a.replace(/; expires=[^;]*/,"")),a}function B(e){q(e)}const H=e=>{window.location.href=e};const Q=()=>{return e=void 0,t=void 0,r=function*(){return Promise.all([(e=o(),I(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}`)}b("state",{isLoggedIn:!1})}))}))),L().clear()]).then((()=>{(G||(G=new V({version:"1.0.0",component:"userdata-session",methods:["userAuthenticated"]}),G)).userAuthenticated(!1),B("VSTOKEN"),B("aid.session"),B("aid_invitation_code"),B("aid-reload-article"),B("VSTOKEN2")})).catch((e=>{f("Failure while logging out",e)}));var 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};var X=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 W=e=>{try{return(e=>a(void 0,void 0,void 0,(function*(){return fetch(`/api/mercury/v2/access/activate?publication_wwwdomain=${o()}&access_features=${e.join(",")}`,{method:"post"}).then((e=>a(void 0,void 0,void 0,(function*(){let t;try{t=yield e.json()}catch(e){c.error("Body does not contain parsable json",e)}if(!e.ok){if(401===e.status&&"user_deactivated"===(null==t?void 0:t.status))throw new u;return!1}return"success"===(null==t?void 0:t.status)&&"granted"===(null==t?void 0:t.access)}))))})))(e)}catch(e){if(e instanceof u)return Q(),Promise.resolve(!1);throw e}},J=(e,t)=>t.filter((t=>e.includes(t))).length>0,z=e=>X(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 R.check(e)}catch(t){throw g("GetVstokenSchema",t,{json:e}),t}})))(e);return"success"===t.status&&q("VSTOKEN",t.cookie,365,"/"),{success:"success"===t.status,accessFeatures:t.access_features}})),Z=e=>X(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 m.check(e)}catch(t){throw g("GetNonUserAccessSchema",t,{json:e}),t}})))(e);return"success"===t.status&&q("VSTOKEN2",t.vstoken_cookie,1,"/"),{success:"success"===t.status,accessFeatures:t.access_features}}));var ee,te;!function(e){e.REQUEST_ACTIVATION="amedia-user.activation.request-activation",e.ON_ACTIVATION_COMPLETE="amedia-user.activation.on-activation-complete"}(ee||(ee={})),h(ee.REQUEST_ACTIVATION,(e=>{W(e.detail.accessFeatures).then((e=>{y(new CustomEvent(ee.ON_ACTIVATION_COMPLETE,{detail:{hasAccess: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"}(te||(te={}));const ne=(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(!ne(e[o],t[o]))return!1}return!0};function re(e,t){return!!(e&&e.length>0)&&(!(t&&Object.keys(t).length>0)||e.filter((e=>!Object.keys(t).includes(e))).length>0)}class oe{constructor(e,t){this.attributes=e,this.namespaces=t}withAttributes(e){return new oe([...this.attributes||[],...e],this.namespaces)}withStorage(e){return new oe(this.attributes,[...this.namespaces||[],...e])}subscribe(e){let t=this.setupLocalCache();E(te.ON_STATE_UPDATED,(n=>{const r=n.detail;Object.keys(t.state).length>0&&ne(t.state,r)||(t=Object.assign(Object.assign({},t),{state:r}),e(t))})),y(new CustomEvent(te.REQUEST_STATE)),Array.isArray(this.attributes)&&this.attributes.length>0&&(E(te.ON_ATTRIBUTES_UPDATED,(n=>{const r=this.processUserAttributesEvent(n);Object.keys(t.attributes).length>0&&ne(t.attributes,r)||(t=Object.assign(Object.assign({},t),{attributes:r}),e(t))})),y(new CustomEvent(te.REQUEST_USER_ATTRIBUTES,{detail:this.attributes}))),Array.isArray(this.namespaces)&&this.namespaces.length>0&&(E(te.ON_STORAGE_UPDATED,(n=>{const r=this.processStorageEvent(n);ne(t.storage,r)||(t=Object.assign(Object.assign({},t),{storage:r}),e(t))})),y(new CustomEvent(te.REQUEST_STORAGE_NAMESPACES,{detail:this.namespaces})))}fetch(){return new Promise((e=>{this.subscribe((t=>{void 0!==t.state.isLoggedIn&&(!1!==t.state.isLoggedIn&&(re(this.attributes,t.attributes)||re(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.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 ie=oe;class ae extends Error{constructor(e,t){super(e),this.code=t}}ae.ERROR_RELOADED_NO_ACCESS="RELOADED_NO_ACCESS",ae.ERROR_ENABLING_ACCESS_FAILED="ENABLING_ACCESS_FAILED",ae.ERROR_NO_ACCESS_AFTER_SUCCESSFUL_ACTIVATION_WITH_REQUESTED_ACCESS_FEATURES="NO_ACCESS_AFTER_SUCCESSFUL_ACTIVATION_WITH_REQUESTED_ACCESS_FEATURES";const se=ae;const ce="haveTriedThirdPartyLoginCheck",ue=(0,p.Record)({user_name:p.String,tracking_key:p.String});const le="have-tried-autologin",fe=[{name:"third_party",handler:function(){return e=this,t=void 0,r=function*(){return!(yield F(ce,p.Boolean))&&(yield(e=ce,t=!0,n=36e5,L().set(e,t,Date.now()+n)),!!(yield fetch(`https://${i()}/api/pluto/v1/sessions/current`,{mode:"cors",credentials:"include"}).then((e=>e.ok?e.json():(403!==e.status&&f(`Unknown error (${e.status}: ${e.statusText}) when fetching current session`,{response:e}),null))).then((e=>{if(!e)return null;try{return ue.check(e)}catch(t){return g("ServiceSessionSchema",t,{data:e}),null}}))));var e,t,n},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=()=>{return e=void 0,n=void 0,o=function*(){var e;if(!function(){try{return window.self!==window.top}catch(e){return!0}}()&&(yield I(void 0,void 0,void 0,(function*(){return fetch("/api/pluto/v1/sessions/current").then((e=>e.ok?e.json():403===e.status?{}:(f(`Unknown error (${e.status}: ${e.statusText}) when fetching current session`,{response:e}),Promise.reject()))).then((e=>{if(0===Object.keys(e).length)return{};try{return N.check(e)}catch(t){return g("ServiceSessionSchema",t,{json:e}),{}}})).then((e=>{return b("state",{isLoggedIn:void 0!==e.user_uuid}),{uuid:(t=e).user_uuid,name:t.user_name,trackingKey:t.tracking_key};var t}))})),!(null===(e=A("state"))||void 0===e?void 0:e.isLoggedIn)&&!function(){const e=K(le);if(e&&"object"!=typeof e)try{if(Date.now()-parseInt(e,10)<6e4)return!0}catch(e){B(le)}return q(le,Date.now(),Date.now()+6e4),!1}()))for(const e of fe)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()),H(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};const ve=()=>new Promise((e=>{var t;const n=null===(t=A("state"))||void 0===t?void 0:t.isLoggedIn;var r,o;!1!==n&&!0!==n?(o=({isLoggedIn:t})=>{!1!==t&&!0!==t||e(t)},S[r="state"]||(S[r]=[]),S[r].push(o)):e(n)}));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 Ee="jupiter";function ye(){return he(this,void 0,void 0,(function*(){const e="VSTOKEN",t=o(),n=K(e);let r=!1;(new ie).withAttributes(["uuid"]).subscribe((({attributes:o,state:i})=>he(this,void 0,void 0,(function*(){if(!1===i.isLoggedIn)return void("string"==typeof n&&B(e));if(!o.uuid||void 0===i.isLoggedIn||r)return;if(r=!0,"string"!=typeof n)return void(yield z(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]===Ee||(yield z(t))}))))}))}function pe(){const e="VSTOKEN2",t=o(),n=K(e);return ve().then((r=>he(this,void 0,void 0,(function*(){if(r){if("string"!=typeof n)return void(yield Z(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]===Ee)return;yield Z(t)}else B(e)})))).then((()=>{}))}var ge=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 _e=[de,function(){return Promise.all([ye(),pe()])},function(){(new ie).subscribe((({state:e})=>{!1===e.isLoggedIn&&(w("userAttributes",{}),w("storage",{}))}))}];var Re;!function(e){e.LOADED="amedia-user.janitor.loaded"}(Re||(Re={}));const me=()=>new ie,Ce=()=>new class{constructor(){this.requestedAccessFeatures=["newspaper"],this.reload=!1}withAccessFeatures(e){return this.requestedAccessFeatures=e,this}reloadOnAccess(){return this.reload=!0,this}redirectOnAccess(e){return this.requestedUrl=e,this}tryUnlock(){return e=this,n=void 0,o=function*(){if((()=>{const e=K("aid-paywall-check-performed");if(!e)return!1;const n=t();return Array.isArray(e)?e.filter((e=>e===n)).length>0:e===n})())throw new se("Unlock check already performed.",se.ERROR_RELOADED_NO_ACCESS);const{state:{isLoggedIn:e}}=yield(new ie).fetch();if(!e)return yield de(),{isLoggedIn:!1,hasAccess:!1,accessFeatures:[]};let n=yield this.setAccessCookiesAndGetAccessFeatures();if(!J(n,this.requestedAccessFeatures)){if(!(yield W(this.requestedAccessFeatures)))return{isLoggedIn:!0,hasAccess:!1,accessFeatures:n};if(n=yield this.setAccessCookiesAndGetAccessFeatures(),!J(n,this.requestedAccessFeatures))throw new se("New subscription was attached and checked successfully, but internal systems disagree about current newspaper access.",se.ERROR_NO_ACCESS_AFTER_SUCCESSFUL_ACTIVATION_WITH_REQUESTED_ACCESS_FEATURES)}var r;return this.reload&&window.location.reload(),this.requestedUrl&&(r=this.requestedUrl,window.location.replace(r)),{isLoggedIn:!0,hasAccess:!0,accessFeatures:n}},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}setAccessCookiesAndGetAccessFeatures(){return(e=o(),X(void 0,void 0,void 0,(function*(){return z(e)&&Z(e)}))).then((e=>{if(!e.success)throw new se("Could not set access cookies",se.ERROR_ENABLING_ACCESS_FAILED);return(()=>{const e=new URL(t());e.searchParams.set("access","granted");const n=new Date;n.setTime(n.getTime()+12e4),q("aid-paywall-check-performed",e.href,n)})(),e.accessFeatures}));var e}},Oe=e=>(e=>{const t=new URL(`https://${i()}/aid/logg_inn/${o()}/`);t.searchParams.set("requestedUrl",e instanceof URL?e.href:e),H(t.href)})(e||t()),Se=()=>Q(),Te=e=>new Promise((t=>{E(ee.ON_ACTIVATION_COMPLETE,(e=>t(e.detail))),y(new CustomEvent(ee.REQUEST_ACTIVATION,{detail:{accessFeatures:e}}))})),be=e=>y(new CustomEvent(te.UPDATE_STORAGE,{detail:e}));"undefined"==typeof process&&ge(void 0,void 0,void 0,(function*(){let e=!1;h(Re.LOADED,(()=>{e||(e=!0,function(){ge(this,void 0,void 0,(function*(){for(const e of _e)yield e()}))}())})),y(new CustomEvent(Re.LOADED))}))})();var o=r.EX,i=r.kS,a=r.$s,s=r.Lk,c=r.Hc,u=r.EA;export{o as goToLoginPage,i as logout,a as paywall,s as tryActivateSubscriptionAccess,c as updateStorage,u as user};
|
|
1
|
+
var e={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,l=a.FAILURE.ARGUMENT_INCORRECT(u);throw new i.ValidationError(l)}for(var d=0;d<s.length;d++)s[d].check(t[d]);var f=e.apply(void 0,o([],r(t)));if(!(f instanceof Promise))throw u="Expected function to return a promise, but instead got "+f,l=a.FAILURE.RETURN_INCORRECT(u),new i.ValidationError(l);return f.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,l=a.FAILURE.ARGUMENT_INCORRECT(u);throw new i.ValidationError(l)}for(var d=0;d<s.length;d++)s[d].check(t[d]);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,l=o.FAILURE.ARGUMENT_INCORRECT(s);throw new r.ValidationError(l)}})),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],l=c[1];if(u.guard(t))return l(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),l={tag:"dictionary",key:u,value:e};return r.create((function(t,o){if(null==t||"object"!=typeof t)return s.FAILURE.TYPE_INCORRECT(l,t);if(Object.getPrototypeOf(t)!==Object.prototype&&(!Array.isArray(t)||"string"===u))return s.FAILURE.TYPE_INCORRECT(l,t);var a=/^(?:NaN|-?\d+(?:\.\d+)?)$/u,c=s.enumerableKeysOf(t),d=c.reduce((function(c,u){var d="string"==typeof u&&a.test(u),f=d?n.g.Number(u):u;return(d?i.guard(f)||i.guard(u):i.guard(f))?c[u]=r.innerValidate(e,t[u],o):c[u]=s.FAILURE.KEY_INCORRECT(l,i.reflect,f),c}),{}),f=c.reduce((function(e,t){var n=d[t];return n.success||(e[t]=n.details||n.message),e}),{});return 0!==s.enumerableKeysOf(f).length?s.FAILURE.CONTENT_INCORRECT(l,f):s.SUCCESS(t)}),l)}},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 l=u.value,d=o.innerValidate(l,t,n);if(!d.success)return d}}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 l=o([],r(new Set(o(o([],r(c)),r(a.enumerableKeysOf(n)))))),d=l.reduce((function(r,o){var c=a.hasKey(o,e),u=a.hasKey(o,n);if(c){var l=e[o],d=t||"optional"===l.reflect.tag;if(u){var f=n[o];r[o]=d&&void 0===f?a.SUCCESS(f):i.innerValidate(l,f,s)}else r[o]=d?a.SUCCESS(void 0):a.FAILURE.PROPERTY_MISSING(l.reflect)}else{if(!u)throw new Error("impossible");f=n[o],r[o]=a.SUCCESS(f)}return r}),{}),f=l.reduce((function(e,t){var n=d[t];return n.success||(e[t]=n.details||n.message),e}),{});return 0!==a.enumerableKeysOf(f).length?a.FAILURE.CONTENT_INCORRECT(u,f):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,l,d,f,v,h;if("object"!=typeof t||null===t){try{for(var E=r(e),y=E.next();!y.done;y=E.next()){var p=y.value;if(o.innerValidate(p,t,n).success)return i.SUCCESS(t)}}catch(e){s={error:e}}finally{try{y&&!y.done&&(c=E.return)&&c.call(E)}finally{if(s)throw s.error}}return i.FAILURE.TYPE_INCORRECT(a,t)}var g={};try{for(var _=r(e),R=_.next();!R.done;R=_.next())if("record"===(p=R.value).reflect.tag){var m=function(e){var t=p.reflect.fields[e];"literal"===t.tag&&(g[e]?g[e].every((function(e){return e!==t.value}))&&g[e].push(t.value):g[e]=[t.value])};for(var C in p.reflect.fields)m(C)}}catch(e){u={error:e}}finally{try{R&&!R.done&&(l=_.return)&&l.call(_)}finally{if(u)throw u.error}}for(var C in g)if(g[C].length===e.length)try{for(var O=(d=void 0,r(e)),S=O.next();!S.done;S=O.next())if("record"===(p=S.value).reflect.tag){var T=p.reflect.fields[C];if("literal"===T.tag&&i.hasKey(C,t)&&t[C]===T.value)return o.innerValidate(p,t,n)}}catch(e){d={error:e}}finally{try{S&&!S.done&&(f=O.return)&&f.call(O)}finally{if(d)throw d.error}}try{for(var b=r(e),w=b.next();!w.done;w=b.next()){var A=w.value;if(o.innerValidate(A,t,n).success)return i.SUCCESS(t)}}catch(e){v={error:e}}finally{try{w&&!w.done&&(h=b.return)&&h.call(b)}finally{if(v)throw v.error}}return i.FAILURE.TYPE_INCORRECT(a,t)}),a)}},101:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Unknown=void 0;var r=n(732),o=n(611);t.Unknown=r.create((function(e){return o.SUCCESS(e)}),{tag:"unknown"})},203:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Void=void 0;var r=n(101);t.Void=r.Unknown},611:function(e,t,n){var r=this&&this.__assign||function(){return(r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};Object.defineProperty(t,"__esModule",{value:!0}),t.FAILURE=t.SUCCESS=t.enumerableKeysOf=t.typeOf=t.hasKey=void 0;var o=n(691),i=n(233);t.hasKey=function(e,t){return"object"==typeof t&&null!==t&&e in t},t.typeOf=function(e){return"object"==typeof e?null===e?"null":Array.isArray(e)?"array":"Object"===e.constructor.name?"object":e.constructor.name:typeof e},t.enumerableKeysOf=function(e){return"object"==typeof e&&null!==e?Reflect.ownKeys(e).filter((function(t){var n,r;return null===(r=null===(n=e.propertyIsEnumerable)||void 0===n?void 0:n.call(e,t))||void 0===r||r})):[]},t.SUCCESS=function(e){return{success:!0,value:e}},t.FAILURE=Object.assign((function(e,t,n){return r({success:!1,code:e,message:t},n?{details:n}:{})}),{TYPE_INCORRECT:function(e,n){var r="Expected "+i.default(e)+", but was "+t.typeOf(n);return t.FAILURE(o.Failcode.TYPE_INCORRECT,r)},VALUE_INCORRECT:function(e,n,r){return t.FAILURE(o.Failcode.VALUE_INCORRECT,"Expected "+e+" "+String(n)+", but was "+String(r))},KEY_INCORRECT:function(e,n,r){return t.FAILURE(o.Failcode.KEY_INCORRECT,"Expected "+i.default(e)+" key to be "+i.default(n)+", but was "+t.typeOf(r))},CONTENT_INCORRECT:function(e,n){var r="Expected "+i.default(e)+", but was incompatible";return t.FAILURE(o.Failcode.CONTENT_INCORRECT,r,n)},ARGUMENT_INCORRECT:function(e){return t.FAILURE(o.Failcode.ARGUMENT_INCORRECT,e)},RETURN_INCORRECT:function(e){return t.FAILURE(o.Failcode.RETURN_INCORRECT,e)},CONSTRAINT_FAILED:function(e,n){var r=n?": "+n:"";return t.FAILURE(o.Failcode.CONSTRAINT_FAILED,"Failed constraint check for "+i.default(e)+r)},PROPERTY_MISSING:function(e){var n="Expected "+i.default(e)+", but was missing";return t.FAILURE(o.Failcode.PROPERTY_MISSING,n)},PROPERTY_PRESENT:function(e){var n="Expected nothing, but was "+t.typeOf(e);return t.FAILURE(o.Failcode.PROPERTY_PRESENT,n)},NOTHING_EXPECTED:function(e){var n="Expected nothing, but was "+t.typeOf(e);return t.FAILURE(o.Failcode.NOTHING_EXPECTED,n)}})},905:(e,t)=>{var n=function(e){if("object"==typeof e&&null!==e){if("function"==typeof Object.getPrototypeOf){var t=Object.getPrototypeOf(e);return t===Object.prototype||null===t}return"[object Object]"===Object.prototype.toString.call(e)}return!1},r=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return e.reduce((function(e,t){return Object.keys(t).forEach((function(o){Array.isArray(e[o])&&Array.isArray(t[o])?e[o]=Array.from(new Set(e[o].concat(t[o]))):n(e[o])&&n(t[o])?e[o]=r(e[o],t[o]):e[o]=t[o]})),e}),{})};t.Z=r}},t={};function n(r){var o=t[r];if(void 0!==o)return o.exports;var i=t[r]={exports:{}};return e[r].call(i.exports,i,i.exports,n),i.exports}n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var r={};(()=>{n.d(r,{EX:()=>Ae,kS:()=>Ie,$s:()=>we,Lk:()=>Ne,Hc:()=>Ue,EA:()=>be});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)=>{!function(e,t){const n=new FormData;Object.keys(t).forEach((e=>n.append(e,t[e]))),fetch(e,{method:"POST",body:n,headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json"}}).then((e=>{if(!e.ok)throw new Error(`Error, status: ${e.status}, text: ${e.statusText}`)}))}(`//www.aid.no/api/mercury/v1/log/${n}`,Object.assign(Object.assign({},o),{message:r,url:t(),domain:e()}))},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 l=c;const d=(e,...t)=>{l.error(e,...t)};let f;var v;"undefined"!=typeof window&&(v=window,f=v);const h=(e,t)=>{f?f.addEventListener(e,(e=>{e.stopImmediatePropagation(),t.apply(f,[e])})):d("No root element to bind event to!")},E=(e,t)=>{f?f.addEventListener(e,(e=>{t.apply(f,[e])})):d("No root element to bind event to!")},y=e=>{f?f.dispatchEvent(e):d("No root element to dispatch event on!")};var p=n(529);const g={},_=e=>{const t=g[e];return t?(delete g[e],t):[]},R=()=>{const e="undefined"!=typeof window?window:n.g;return e.amediaUserCache||(e.amediaUserCache={})},m={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())};function C(e,t,n){let r;const o=[];t instanceof p.ValidationError?(r=`Invalid ${e}`,o.push(t.details)):(r=`Unknown error after validating ${e}: (${t.message}`,o.push(t)),n&&o.push(n),d(r,...o)}const O=()=>m,S=e=>O().remove(e),T=(e,t)=>{return n=void 0,r=void 0,i=function*(){const n=yield O().get(e);if(!n)return Promise.resolve();if(Date.now()>n.expires)return S(e),Promise.resolve();try{return t.check(n.data)}catch(t){return C("cache engine schema",t,{data:n.data}),S(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},b=(e,t,n)=>O().set(e,t,Date.now()+n);function w(e,t,n,r){return new Promise(((o,i)=>{((e,t)=>{g[e]||(g[e]=[]),g[e].push(t)})(e,{resolve:o,reject:i}),(e=>{var t;return(null===(t=g[e])||void 0===t?void 0:t.length)||0})(e)>1||T(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;b(e,r,n.ttl),_(e).forEach((e=>{e.resolve(n.data)}))})).catch((()=>{_(e).forEach((e=>{e.reject()}))})):_(e).forEach((e=>{e.resolve(t)}))}))}))}const A=(0,p.Record)({id:p.Number,domain:p.String}),I=((0,p.Record)({status:(0,p.Literal)("success"),access:(0,p.Union)((0,p.Literal)("granted"),(0,p.Literal)("denied")),publication:A,access_features:(0,p.Array)(p.String)}),(0,p.Record)({status:(0,p.Literal)("success"),cookie:p.String,access_features:(0,p.Array)(p.String)})),N=(0,p.Record)({status:(0,p.Literal)("success"),vstoken_cookie:p.String,uuid:p.String,access_features:(0,p.Array)(p.String)});var U=n(905);const P={},j={},L=(e,t)=>{P[e]=t,(e=>{var t;null===(t=j[e])||void 0===t||t.forEach((t=>t(P[e])))})(e)},F=(e,t)=>{L(e,(0,U.Z)(P[e]||{},t))},k=L,x=e=>P[e];var D=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 M=(0,p.Partial)({user_uuid:p.String,user_name:p.String,tracking_key:p.String}),$=()=>fetch("/api/pluto/v1/sessions/current").then((e=>e.ok?e.json():403===e.status?{}:(d(`Unknown error (${e.status}: ${e.statusText}) when fetching current session`,{response:e}),Promise.reject()))).then((e=>{const t={ttl:-1,data:e};if(0===Object.keys(e).length)return t;try{return{ttl:1e4,data:M.check(e)}}catch(n){return C("ServiceSessionSchema",n,{json:e}),t}}));let V;const G=self||window,Y="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||void 0!==G.msCrypto&&"function"==typeof G.msCrypto.getRandomValues&&G.msCrypto.getRandomValues.bind(G.msCrypto);if(Y){const e=new Uint8Array(16);V=function(){return Y(e),e}}else{const e=new Array(16);V=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 K=[];for(let e=0;e<256;++e)K[e]=(e+256).toString(16).substr(1);function q(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=V();return e[6]=15&e[6]|64,e[8]=63&e[8]|128,function(e,t){let n=0;const r=K;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 B{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]=q(this.component,e),this[e](...t)}}}let H;const Q=(e,t)=>{const n=t.substring(e.length,t.length);return"{"===n.substring(0,1)?JSON.parse(n):"%7B"===n.substring(0,3)?JSON.parse(decodeURIComponent(n)):"undefined"!==n?""===n||"null"===n?null:n:void 0},X=e=>{const t=`${e}=`,n=document.cookie.split(";");for(let e=n.length-1;e>=0;e-=1){const r=n[e].trim();if(0===r.indexOf(t))return Q(t,r)}return null};function W(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===X(e)&&(document.cookie=a.replace(/; expires=[^;]*/,"")),a}function J(e){W(e)}const z=e=>{window.location.href=e};const Z=()=>{return e=void 0,t=void 0,r=function*(){return Promise.all([(e=o(),D(void 0,void 0,void 0,(function*(){return fetch(`/api/pluto/v1/sessions/current?publication_domain=${e}`,{method:"DELETE"}).then((e=>{if(!e.ok){if(403===e.status)return;throw new Error(`Error, could not perform deleteRequest. Status: ${e.status} Text: ${e.statusText}`)}F("state",{isLoggedIn:!1})}))}))),O().clear()]).then((()=>{(H||(H=new B({version:"1.0.0",component:"userdata-session",methods:["userAuthenticated"]}),H)).userAuthenticated(!1),J("VSTOKEN"),J("aid.session"),J("aid_invitation_code"),J("aid-reload-article"),J("VSTOKEN2")})).catch((e=>{d("Failure while logging out",e)}));var 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};var ee=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 te=e=>{try{return(e=>a(void 0,void 0,void 0,(function*(){return fetch(`/api/mercury/v2/access/activate?publication_wwwdomain=${o()}&access_features=${e.join(",")}`,{method:"post"}).then((e=>a(void 0,void 0,void 0,(function*(){let t;try{t=yield e.json()}catch(e){c.error("Body does not contain parsable json",e)}if(!e.ok){if(401===e.status&&"user_deactivated"===(null==t?void 0:t.status))throw new u;return!1}return"success"===(null==t?void 0:t.status)&&"granted"===(null==t?void 0:t.access)}))))})))(e)}catch(e){if(e instanceof u)return Z(),Promise.resolve(!1);throw e}},ne=(e,t)=>t.filter((t=>e.includes(t))).length>0,re=e=>ee(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 I.check(e)}catch(t){throw C("GetVstokenSchema",t,{json:e}),t}})))(e);return"success"===t.status&&W("VSTOKEN",t.cookie,365,"/"),{success:"success"===t.status,accessFeatures:t.access_features}})),oe=e=>ee(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 N.check(e)}catch(t){throw C("GetNonUserAccessSchema",t,{json:e}),t}})))(e);return"success"===t.status&&W("VSTOKEN2",t.vstoken_cookie,1,"/"),{success:"success"===t.status,accessFeatures:t.access_features}}));var ie,ae;!function(e){e.REQUEST_ACTIVATION="amedia-user.activation.request-activation",e.ON_ACTIVATION_COMPLETE="amedia-user.activation.on-activation-complete"}(ie||(ie={})),h(ie.REQUEST_ACTIVATION,(e=>{te(e.detail.accessFeatures).then((e=>{y(new CustomEvent(ie.ON_ACTIVATION_COMPLETE,{detail:{hasAccess: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"}(ae||(ae={}));const se=(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(!se(e[o],t[o]))return!1}return!0};function ce(e,t){return!!(e&&e.length>0)&&(!(t&&Object.keys(t).length>0)||e.filter((e=>!Object.keys(t).includes(e))).length>0)}class ue{constructor(e,t){this.attributes=e,this.namespaces=t}withAttributes(e){return new ue([...this.attributes||[],...e],this.namespaces)}withStorage(e){return new ue(this.attributes,[...this.namespaces||[],...e])}subscribe(e){let t=this.setupLocalCache();E(ae.ON_STATE_UPDATED,(n=>{const r=n.detail;Object.keys(t.state).length>0&&se(t.state,r)||(t=Object.assign(Object.assign({},t),{state:r}),e(t))})),y(new CustomEvent(ae.REQUEST_STATE)),Array.isArray(this.attributes)&&this.attributes.length>0&&(E(ae.ON_ATTRIBUTES_UPDATED,(n=>{const r=this.processUserAttributesEvent(n);Object.keys(t.attributes).length>0&&se(t.attributes,r)||(t=Object.assign(Object.assign({},t),{attributes:r}),e(t))})),y(new CustomEvent(ae.REQUEST_USER_ATTRIBUTES,{detail:this.attributes}))),Array.isArray(this.namespaces)&&this.namespaces.length>0&&(E(ae.ON_STORAGE_UPDATED,(n=>{const r=this.processStorageEvent(n);se(t.storage,r)||(t=Object.assign(Object.assign({},t),{storage:r}),e(t))})),y(new CustomEvent(ae.REQUEST_STORAGE_NAMESPACES,{detail:this.namespaces})))}fetch(){return new Promise((e=>{this.subscribe((t=>{void 0!==t.state.isLoggedIn&&(!1!==t.state.isLoggedIn&&(ce(this.attributes,t.attributes)||ce(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.reduce(((e,n)=>(void 0!==t[n]&&(e[n]=t[n]),e)),{})}setupLocalCache(){const e={state:{}};return this.attributes&&this.attributes.length>0&&(e.attributes={}),this.namespaces&&this.namespaces.length>0&&(e.storage={}),e}}const le=ue;class de extends Error{constructor(e,t){super(e),this.code=t}}de.ERROR_RELOADED_NO_ACCESS="RELOADED_NO_ACCESS",de.ERROR_ENABLING_ACCESS_FAILED="ENABLING_ACCESS_FAILED",de.ERROR_NO_ACCESS_AFTER_SUCCESSFUL_ACTIVATION_WITH_REQUESTED_ACCESS_FEATURES="NO_ACCESS_AFTER_SUCCESSFUL_ACTIVATION_WITH_REQUESTED_ACCESS_FEATURES";const fe=de;const ve="haveTriedThirdPartyLoginCheck",he=(0,p.Record)({user_name:p.String,tracking_key:p.String});const Ee="have-tried-autologin",ye=[{name:"third_party",handler:function(){return e=this,t=void 0,r=function*(){return!(yield T(ve,p.Boolean))&&(yield b(ve,!0,36e5),!!(yield fetch(`https://${i()}/api/pluto/v1/sessions/current`,{mode:"cors",credentials:"include"}).then((e=>e.ok?e.json():(403!==e.status&&d(`Unknown error (${e.status}: ${e.statusText}) when fetching current session`,{response:e}),null))).then((e=>{if(!e)return null;try{return he.check(e)}catch(t){return C("ServiceSessionSchema",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*(){var e;if(!function(){try{return window.self!==window.top}catch(e){return!0}}()&&(yield D(void 0,void 0,void 0,(function*(){return w("getCurrentSession",M,$).then((e=>{return F("state",{isLoggedIn:void 0!==e.user_uuid}),{uuid:(t=e).user_uuid,name:t.user_name,trackingKey:t.tracking_key};var t}))})),!(null===(e=x("state"))||void 0===e?void 0:e.isLoggedIn)&&!function(){const e=X(Ee);if(e&&"object"!=typeof e)try{if(Date.now()-parseInt(e,10)<6e4)return!0}catch(e){J(Ee)}return W(Ee,Date.now(),Date.now()+6e4),!1}()))for(const e of ye)if(!(yield e.handler().then((n=>{if(n){const n=new URL(`https://${i()}/aid/logg_inn/auto`);return n.searchParams.set("context",`auto_login_${e.name}`),n.searchParams.set("requestedUrl",t()),z(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};const ge=()=>new Promise((e=>{var t;const n=null===(t=x("state"))||void 0===t?void 0:t.isLoggedIn;var r,o;!1!==n&&!0!==n?(o=({isLoggedIn:t})=>{!1!==t&&!0!==t||e(t)},j[r="state"]||(j[r]=[]),j[r].push(o)):e(n)}));var _e=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 me(){return _e(this,void 0,void 0,(function*(){const e="VSTOKEN",t=o(),n=X(e);let r=!1;(new le).withAttributes(["uuid"]).subscribe((({attributes:o,state:i})=>_e(this,void 0,void 0,(function*(){if(!1===i.isLoggedIn)return void("string"==typeof n&&J(e));if(!o.uuid||void 0===i.isLoggedIn||r)return;if(r=!0,"string"!=typeof n)return void(yield re(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 re(t))}))))}))}function Ce(){const e="VSTOKEN2",t=o(),n=X(e);return ge().then((r=>_e(this,void 0,void 0,(function*(){if(r){if("string"!=typeof n)return void(yield oe(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 oe(t)}else J(e)})))).then((()=>{}))}var Oe=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 Se=[pe,function(){return Promise.all([me(),Ce()])},function(){(new le).subscribe((({state:e})=>{!1===e.isLoggedIn&&(k("userAttributes",{}),k("storage",{}))}))}];var Te;!function(e){e.LOADED="amedia-user.janitor.loaded"}(Te||(Te={}));const be=()=>new le,we=()=>new class{constructor(){this.requestedAccessFeatures=["newspaper"],this.reload=!1}withAccessFeatures(e){return this.requestedAccessFeatures=e,this}reloadOnAccess(){return this.reload=!0,this}redirectOnAccess(e){return this.requestedUrl=e,this}tryUnlock(){return e=this,n=void 0,o=function*(){if((()=>{const e=X("aid-paywall-check-performed");if(!e)return!1;const n=t();return Array.isArray(e)?e.filter((e=>e===n)).length>0:e===n})())throw new fe("Unlock check already performed.",fe.ERROR_RELOADED_NO_ACCESS);const{state:{isLoggedIn:e}}=yield(new le).withAttributes(["name"]).fetch();if(!e)return yield pe(),{isLoggedIn:!1,hasAccess:!1,accessFeatures:[]};let n=yield this.setAccessCookiesAndGetAccessFeatures();if(!ne(n,this.requestedAccessFeatures)){if(!(yield te(this.requestedAccessFeatures)))return{isLoggedIn:!0,hasAccess:!1,accessFeatures:n};if(n=yield this.setAccessCookiesAndGetAccessFeatures(),!ne(n,this.requestedAccessFeatures))throw new fe("New subscription was attached and checked successfully, but internal systems disagree about current newspaper access.",fe.ERROR_NO_ACCESS_AFTER_SUCCESSFUL_ACTIVATION_WITH_REQUESTED_ACCESS_FEATURES)}var r;return this.reload&&window.location.reload(),this.requestedUrl&&(r=this.requestedUrl,window.location.replace(r)),{isLoggedIn:!0,hasAccess:!0,accessFeatures:n}},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}setAccessCookiesAndGetAccessFeatures(){return(e=o(),ee(void 0,void 0,void 0,(function*(){return re(e)&&oe(e)}))).then((e=>{if(!e.success)throw new fe("Could not set access cookies",fe.ERROR_ENABLING_ACCESS_FAILED);return(()=>{const e=new URL(t());e.searchParams.set("access","granted");const n=new Date;n.setTime(n.getTime()+12e4),W("aid-paywall-check-performed",e.href,n)})(),e.accessFeatures}));var e}},Ae=e=>(e=>{const t=new URL(`https://${i()}/aid/logg_inn/${o()}/`);t.searchParams.set("requestedUrl",e instanceof URL?e.href:e),z(t.href)})(e||t()),Ie=()=>Z(),Ne=e=>new Promise((t=>{E(ie.ON_ACTIVATION_COMPLETE,(e=>t(e.detail))),y(new CustomEvent(ie.REQUEST_ACTIVATION,{detail:{accessFeatures:e}}))})),Ue=e=>y(new CustomEvent(ae.UPDATE_STORAGE,{detail:e}));"undefined"==typeof process&&Oe(void 0,void 0,void 0,(function*(){let e=!1;h(Te.LOADED,(()=>{e||(e=!0,function(){Oe(this,void 0,void 0,(function*(){for(const e of Se)yield e()}))}())})),y(new CustomEvent(Te.LOADED))}))})();var o=r.EX,i=r.kS,a=r.$s,s=r.Lk,c=r.Hc,u=r.EA;export{o as goToLoginPage,i as logout,a as paywall,s as tryActivateSubscriptionAccess,c as updateStorage,u as user};
|
package/eik.json
CHANGED
package/package.json
CHANGED
|
@@ -47,6 +47,37 @@ describe('when fetching userData', () => {
|
|
|
47
47
|
});
|
|
48
48
|
});
|
|
49
49
|
});
|
|
50
|
+
|
|
51
|
+
describe('in quick succession', () => {
|
|
52
|
+
beforeEach(async () => {
|
|
53
|
+
plutoFetchMock.mockResponse(
|
|
54
|
+
JSON.stringify({
|
|
55
|
+
user_uuid: '1234-123-1234',
|
|
56
|
+
user_name: 'Donald',
|
|
57
|
+
tracking_key: '4321-321-4321',
|
|
58
|
+
})
|
|
59
|
+
);
|
|
60
|
+
await Promise.all([
|
|
61
|
+
requestAttributes(['name', 'uuid']),
|
|
62
|
+
requestAttributes(['uuid']),
|
|
63
|
+
requestAttributes(['name']),
|
|
64
|
+
requestAttributes(['name', 'uuid']),
|
|
65
|
+
requestAttributes(['uuid', 'name']),
|
|
66
|
+
]);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('should ask only once', () => {
|
|
70
|
+
expect(plutoFetchMock).toHaveBeenCalledTimes(1);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('should have expected data in store', () => {
|
|
74
|
+
expect(store.get('userAttributes')).toEqual({
|
|
75
|
+
uuid: '1234-123-1234',
|
|
76
|
+
name: 'Donald',
|
|
77
|
+
trackingKey: '4321-321-4321',
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
});
|
|
50
81
|
});
|
|
51
82
|
|
|
52
83
|
describe('when querying for attributes that need login state to be resolved', () => {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import fetch from 'jest-fetch-mock';
|
|
2
|
+
import cache from '../cache';
|
|
2
3
|
import log from '../utils/log';
|
|
3
4
|
import {
|
|
4
5
|
checkForAccess,
|
|
@@ -9,11 +10,13 @@ import {
|
|
|
9
10
|
GetNonUserAccess,
|
|
10
11
|
getNonUserAccess,
|
|
11
12
|
} from './jupiter';
|
|
13
|
+
import anything = jasmine.anything;
|
|
12
14
|
import restoreAllMocks = jest.restoreAllMocks;
|
|
13
15
|
|
|
14
16
|
beforeEach(async () => {
|
|
15
17
|
restoreAllMocks();
|
|
16
18
|
fetch.resetMocks();
|
|
19
|
+
await cache.clear();
|
|
17
20
|
});
|
|
18
21
|
|
|
19
22
|
describe('jupiter service', () => {
|
|
@@ -65,6 +68,31 @@ describe('jupiter service', () => {
|
|
|
65
68
|
checkForAccess(publicationDomain, accessFeatures)
|
|
66
69
|
).rejects.toBeUndefined();
|
|
67
70
|
});
|
|
71
|
+
|
|
72
|
+
it('should not cache when access denied', (done) => {
|
|
73
|
+
fetch.mockResponseOnce(
|
|
74
|
+
JSON.stringify({
|
|
75
|
+
status: 'success',
|
|
76
|
+
access: 'denied',
|
|
77
|
+
publication: {
|
|
78
|
+
domain: 'www.rb.no',
|
|
79
|
+
id: 95,
|
|
80
|
+
},
|
|
81
|
+
access_features: [],
|
|
82
|
+
})
|
|
83
|
+
);
|
|
84
|
+
const cacheSetSpy = spyOn(cache, 'set');
|
|
85
|
+
expect(checkForAccess(publicationDomain, accessFeatures))
|
|
86
|
+
.resolves.toEqual({ access: [] })
|
|
87
|
+
.then(() => {
|
|
88
|
+
expect(cacheSetSpy).toHaveBeenCalledWith(
|
|
89
|
+
'checkForAccess',
|
|
90
|
+
anything(),
|
|
91
|
+
0
|
|
92
|
+
);
|
|
93
|
+
})
|
|
94
|
+
.then(done);
|
|
95
|
+
});
|
|
68
96
|
});
|
|
69
97
|
|
|
70
98
|
describe('POST /get_vstoken', () => {
|
package/src/clients/jupiter.ts
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
String,
|
|
8
8
|
Union,
|
|
9
9
|
} from 'runtypes';
|
|
10
|
+
import getOrUpdate from '../utils/getOrUpdate';
|
|
10
11
|
import { UserAttributes } from '../types';
|
|
11
12
|
import logValidationError from '../utils/logValidationError';
|
|
12
13
|
|
|
@@ -46,33 +47,34 @@ export const checkForAccess = (
|
|
|
46
47
|
publicationDomain: string,
|
|
47
48
|
accessFeatures: AccessFeatures
|
|
48
49
|
): Promise<Pick<UserAttributes, 'access'>> =>
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
50
|
+
getOrUpdate('checkForAccess', CheckAccessForPaperSchema, () =>
|
|
51
|
+
fetch(
|
|
52
|
+
`/api/jupiter/v1/check_access_for_paper/${publicationDomain}/?require=any&access_features=${accessFeatures.join(
|
|
53
|
+
','
|
|
54
|
+
)}`
|
|
55
|
+
)
|
|
56
|
+
.then((response) => {
|
|
57
|
+
if (!response.ok) {
|
|
58
|
+
// TODO Handle this.
|
|
59
|
+
throw new Error(
|
|
60
|
+
`Request not ok (${response.status}: ${response.statusText}).`
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
return response.json();
|
|
64
|
+
})
|
|
65
|
+
.then((json) => {
|
|
66
|
+
try {
|
|
67
|
+
const data = CheckAccessForPaperSchema.check(json);
|
|
68
|
+
return {
|
|
69
|
+
ttl: data.access === 'granted' ? 1000 * 10 : 0, // 10 seconds
|
|
70
|
+
data,
|
|
71
|
+
};
|
|
72
|
+
} catch (error) {
|
|
73
|
+
logValidationError('CheckAccessForPaperSchema', error, { json });
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
})
|
|
77
|
+
).then((data) => ({ access: data.access_features }));
|
|
76
78
|
|
|
77
79
|
export const getUserAccess = (publicationDomain: string): Promise<GetVstoken> =>
|
|
78
80
|
fetch(`/api/jupiter/v1/get_vstoken/${publicationDomain}`, { method: 'post' })
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import fetch from 'jest-fetch-mock';
|
|
2
|
+
import cache from '../cache';
|
|
2
3
|
import store from '../store';
|
|
3
4
|
import { getCurrentSession, removeSession } from './pluto';
|
|
4
5
|
import restoreAllMocks = jest.restoreAllMocks;
|
|
@@ -6,6 +7,7 @@ import restoreAllMocks = jest.restoreAllMocks;
|
|
|
6
7
|
beforeEach(async () => {
|
|
7
8
|
restoreAllMocks();
|
|
8
9
|
fetch.resetMocks();
|
|
10
|
+
await cache.clear();
|
|
9
11
|
});
|
|
10
12
|
|
|
11
13
|
const userUUID = '3-1-33-7';
|
|
@@ -53,34 +55,58 @@ describe('Pluto service', () => {
|
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
describe('when user is logged in ', () => {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
describe('When cache is empty', () => {
|
|
59
|
+
beforeEach(async () => {
|
|
60
|
+
fetch.mockResponseOnce(JSON.stringify(plutoLoggedInResponse));
|
|
61
|
+
currentSession = await getCurrentSession();
|
|
62
|
+
});
|
|
63
|
+
it('should call Pluto', () => {
|
|
64
|
+
expect(fetch).toHaveBeenCalledTimes(1);
|
|
65
|
+
});
|
|
66
|
+
itShouldReturnSessionDataAndSetLoggedInTrueInState();
|
|
59
67
|
});
|
|
60
|
-
|
|
61
|
-
|
|
68
|
+
describe('When cache is not empty', () => {
|
|
69
|
+
beforeEach(async () => {
|
|
70
|
+
cache.set('getCurrentSession', plutoLoggedInResponse, 60000);
|
|
71
|
+
currentSession = await getCurrentSession();
|
|
72
|
+
});
|
|
73
|
+
it('should not call Pluto', () => {
|
|
74
|
+
expect(fetch).toHaveBeenCalledTimes(0);
|
|
75
|
+
});
|
|
76
|
+
itShouldReturnSessionDataAndSetLoggedInTrueInState();
|
|
62
77
|
});
|
|
63
|
-
itShouldReturnSessionDataAndSetLoggedInTrueInState();
|
|
64
78
|
});
|
|
65
79
|
describe('when user is not logged in', () => {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
80
|
+
describe('When cache is empty', () => {
|
|
81
|
+
beforeEach(async () => {
|
|
82
|
+
fetch.mockResponseOnce(() =>
|
|
83
|
+
Promise.resolve({
|
|
84
|
+
init: { status: 403 },
|
|
85
|
+
body: '{"code": "session.not_found"}',
|
|
86
|
+
})
|
|
87
|
+
);
|
|
88
|
+
currentSession = await getCurrentSession();
|
|
89
|
+
});
|
|
90
|
+
it('should call Pluto', () => {
|
|
91
|
+
expect(fetch).toHaveBeenCalledTimes(1);
|
|
92
|
+
});
|
|
93
|
+
itShouldReturnNoSessionDataAndSetLoggedInFalseInState();
|
|
74
94
|
});
|
|
75
|
-
|
|
76
|
-
|
|
95
|
+
describe('When cache is not empty', () => {
|
|
96
|
+
beforeEach(async () => {
|
|
97
|
+
cache.set('getCurrentSession', {}, 60000);
|
|
98
|
+
currentSession = await getCurrentSession();
|
|
99
|
+
});
|
|
100
|
+
it('should not call Pluto', () => {
|
|
101
|
+
expect(fetch).toHaveBeenCalledTimes(0);
|
|
102
|
+
});
|
|
103
|
+
itShouldReturnNoSessionDataAndSetLoggedInFalseInState();
|
|
77
104
|
});
|
|
78
|
-
itShouldReturnNoSessionDataAndSetLoggedInFalseInState();
|
|
79
105
|
});
|
|
80
106
|
});
|
|
81
107
|
|
|
82
108
|
describe('removeSession()', () => {
|
|
83
|
-
it('should call
|
|
109
|
+
it('should call Plut session delete', () => {
|
|
84
110
|
removeSession('www.rb.no');
|
|
85
111
|
expect(
|
|
86
112
|
fetch
|
package/src/clients/pluto.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Partial, Static, String } from 'runtypes';
|
|
2
2
|
import log from '../utils/log';
|
|
3
|
+
import getOrUpdate from '../utils/getOrUpdate';
|
|
3
4
|
import store from '../store';
|
|
4
5
|
import { UserAttributes } from '../types';
|
|
5
6
|
import logValidationError from '../utils/logValidationError';
|
|
@@ -34,20 +35,29 @@ const fetchCurrentSession = () =>
|
|
|
34
35
|
return response.json();
|
|
35
36
|
})
|
|
36
37
|
.then((json) => {
|
|
38
|
+
const nodata = { ttl: -1, data: json };
|
|
39
|
+
|
|
37
40
|
// We are probably logged out in this case.
|
|
38
41
|
if (Object.keys(json).length === 0) {
|
|
39
|
-
return
|
|
42
|
+
return nodata;
|
|
40
43
|
}
|
|
41
44
|
try {
|
|
42
|
-
return
|
|
45
|
+
return {
|
|
46
|
+
ttl: 10000,
|
|
47
|
+
data: ServiceSessionSchema.check(json),
|
|
48
|
+
};
|
|
43
49
|
} catch (error) {
|
|
44
50
|
logValidationError('ServiceSessionSchema', error, { json });
|
|
45
|
-
return
|
|
51
|
+
return nodata;
|
|
46
52
|
}
|
|
47
53
|
});
|
|
48
54
|
|
|
49
55
|
export const getCurrentSession = async (): Promise<UserAttributes> =>
|
|
50
|
-
|
|
56
|
+
getOrUpdate(
|
|
57
|
+
'getCurrentSession',
|
|
58
|
+
ServiceSessionSchema,
|
|
59
|
+
fetchCurrentSession
|
|
60
|
+
).then((currentSession) => {
|
|
51
61
|
store.merge('state', {
|
|
52
62
|
isLoggedIn: currentSession.user_uuid !== undefined,
|
|
53
63
|
});
|
|
@@ -83,6 +83,7 @@ describe('PaywallUnlocker', () => {
|
|
|
83
83
|
let unlockResponse;
|
|
84
84
|
beforeEach(async () => {
|
|
85
85
|
store.set('state', { isLoggedIn: false });
|
|
86
|
+
store.set('userAttributes', { name: 'Donald Duck' });
|
|
86
87
|
unlockResponse = await new PaywallUnlockRequest().tryUnlock();
|
|
87
88
|
});
|
|
88
89
|
|
|
@@ -105,6 +106,7 @@ describe('PaywallUnlocker', () => {
|
|
|
105
106
|
describe('When loggen in', () => {
|
|
106
107
|
beforeEach(() => {
|
|
107
108
|
store.set('state', { isLoggedIn: true });
|
|
109
|
+
store.set('userAttributes', { name: 'Donald Duck' });
|
|
108
110
|
});
|
|
109
111
|
|
|
110
112
|
it('should not attempt autologin', () => {
|
|
@@ -50,7 +50,7 @@ class PaywallUnlockRequest {
|
|
|
50
50
|
|
|
51
51
|
const {
|
|
52
52
|
state: { isLoggedIn },
|
|
53
|
-
} = await new UserDataRequest().fetch();
|
|
53
|
+
} = await new UserDataRequest().withAttributes(['name']).fetch();
|
|
54
54
|
if (!isLoggedIn) {
|
|
55
55
|
// Will attempt one or more strategies for creating a first party session
|
|
56
56
|
// Redirects/reloads might occur
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/dot-notation */
|
|
1
2
|
import { State, UserAttributes } from '../types';
|
|
2
3
|
import { dispatch, listenForAllEvents } from '../utils/customEventWrapper';
|
|
3
4
|
import { AmediaUserEvents } from '../eventHandlers/eventMap';
|
|
@@ -183,12 +184,10 @@ class UserDataRequest<
|
|
|
183
184
|
state: {},
|
|
184
185
|
};
|
|
185
186
|
if (this.attributes && this.attributes.length > 0) {
|
|
186
|
-
// eslint-disable-next-line @typescript-eslint/dot-notation
|
|
187
187
|
previousData['attributes'] = {};
|
|
188
188
|
}
|
|
189
189
|
|
|
190
190
|
if (this.namespaces && this.namespaces.length > 0) {
|
|
191
|
-
// eslint-disable-next-line @typescript-eslint/dot-notation
|
|
192
191
|
previousData['storage'] = {};
|
|
193
192
|
}
|
|
194
193
|
return previousData;
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @jest-environment jsdom
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import store from '../store';
|
|
6
|
-
import UserDataRequest from './UserDataRequest';
|
|
7
|
-
import { listenForStateRequests } from '../eventHandlers/state';
|
|
8
|
-
import { listenForStorageRequests } from '../eventHandlers/storage';
|
|
9
|
-
import { listenForUserAttributeRequests } from '../eventHandlers/userAttributes';
|
|
10
|
-
import { setRootElement } from '../utils/customEventWrapper';
|
|
11
|
-
import * as pluto from '../clients/pluto';
|
|
12
|
-
import restoreAllMocks = jest.restoreAllMocks;
|
|
13
|
-
|
|
14
|
-
beforeEach(() => {
|
|
15
|
-
restoreAllMocks();
|
|
16
|
-
store.clear();
|
|
17
|
-
|
|
18
|
-
// We cannot use window as our event root during testing
|
|
19
|
-
// since tests are executed in parallel.
|
|
20
|
-
setRootElement(new Document());
|
|
21
|
-
jest.spyOn(pluto, 'getCurrentSession').mockResolvedValue({});
|
|
22
|
-
|
|
23
|
-
// Also, since we keep creating new root elements, we also
|
|
24
|
-
// need to attach to these new roots.
|
|
25
|
-
listenForStateRequests();
|
|
26
|
-
listenForStorageRequests();
|
|
27
|
-
listenForUserAttributeRequests();
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
describe('UserDataRequest', () => {
|
|
31
|
-
beforeEach(() => {});
|
|
32
|
-
describe('when subscribing', () => {});
|
|
33
|
-
describe('when fetching', () => {
|
|
34
|
-
describe('and not logged in', () => {
|
|
35
|
-
let fetchResponse;
|
|
36
|
-
beforeEach(async () => {
|
|
37
|
-
store.set('state', { isLoggedIn: false });
|
|
38
|
-
|
|
39
|
-
try {
|
|
40
|
-
fetchResponse = await new UserDataRequest()
|
|
41
|
-
.withAttributes(['name'])
|
|
42
|
-
.fetch();
|
|
43
|
-
} catch (e) {
|
|
44
|
-
console.log('wat', e);
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('should respond immediately since we are not logged in', () => {
|
|
49
|
-
expect(fetchResponse).toEqual({
|
|
50
|
-
state: {
|
|
51
|
-
isLoggedIn: false,
|
|
52
|
-
},
|
|
53
|
-
attributes: {},
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
});
|