@amedia/user 0.2.1 → 0.3.1
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/.babelrc +3 -0
- package/README.md +2 -2
- package/dist/index.js +1 -1
- package/dist/utils/log.d.ts +1 -1
- package/package.json +7 -1
- package/src/cache/engines/global.ts +3 -1
- package/src/cache/index.spec.ts +0 -1
- package/src/eventHandlers/userAttributes.ts +2 -1
- package/src/index.ts +14 -3
- package/src/utils/customEventWrapper.ts +19 -1
- package/src/utils/log.ts +1 -1
- package/tsconfig.json +3 -12
- package/webpack.config.js +6 -1
package/.babelrc
ADDED
package/README.md
CHANGED
|
@@ -6,12 +6,12 @@ getting access to user related data.
|
|
|
6
6
|
# Usage
|
|
7
7
|
Add this project to yours
|
|
8
8
|
```bash
|
|
9
|
-
> npm i @amedia/
|
|
9
|
+
> npm i @amedia/user
|
|
10
10
|
```
|
|
11
11
|
|
|
12
12
|
Setup a listener for the information you need
|
|
13
13
|
```ts
|
|
14
|
-
import {subscribeToUserUpdates} from '@amedia/
|
|
14
|
+
import { subscribeToUserUpdates } from '@amedia/user';
|
|
15
15
|
|
|
16
16
|
subscribeToUserUpdates(['name', 'email'], (attributes) => {
|
|
17
17
|
console.log(attributes);
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.user=r():e.user=r()}(this,(function(){return(()=>{"use strict";var e={36:function(e,r,t){var n=this&&this.__read||function(e,r){var t="function"==typeof Symbol&&e[Symbol.iterator];if(!t)return e;var n,o,a=t.call(e),i=[];try{for(;(void 0===r||r-- >0)&&!(n=a.next()).done;)i.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(t=a.return)&&t.call(a)}finally{if(o)throw o.error}}return i},o=this&&this.__spreadArray||function(e,r){for(var t=0,n=r.length,o=e.length;t<n;t++,o++)e[o]=r[t];return e};Object.defineProperty(r,"__esModule",{value:!0}),r.AsyncContract=void 0;var a=t(888),i=t(611);r.AsyncContract=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];var t=e.length-1,u=e.slice(0,t),c=e[t];return{enforce:function(e){return function(){for(var r=[],t=0;t<arguments.length;t++)r[t]=arguments[t];if(r.length<u.length){var l="Expected "+u.length+" arguments but only received "+r.length,s=i.FAILURE.ARGUMENT_INCORRECT(l);throw new a.ValidationError(s)}for(var f=0;f<u.length;f++)u[f].check(r[f]);var d=e.apply(void 0,o([],n(r)));if(!(d instanceof Promise))throw l="Expected function to return a promise, but instead got "+d,s=i.FAILURE.RETURN_INCORRECT(l),new a.ValidationError(s);return d.then(c.check)}}}}},361:function(e,r,t){var n=this&&this.__read||function(e,r){var t="function"==typeof Symbol&&e[Symbol.iterator];if(!t)return e;var n,o,a=t.call(e),i=[];try{for(;(void 0===r||r-- >0)&&!(n=a.next()).done;)i.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(t=a.return)&&t.call(a)}finally{if(o)throw o.error}}return i},o=this&&this.__spreadArray||function(e,r){for(var t=0,n=r.length,o=e.length;t<n;t++,o++)e[o]=r[t];return e};Object.defineProperty(r,"__esModule",{value:!0}),r.Contract=void 0;var a=t(888),i=t(611);r.Contract=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];var t=e.length-1,u=e.slice(0,t),c=e[t];return{enforce:function(e){return function(){for(var r=[],t=0;t<arguments.length;t++)r[t]=arguments[t];if(r.length<u.length){var l="Expected "+u.length+" arguments but only received "+r.length,s=i.FAILURE.ARGUMENT_INCORRECT(l);throw new a.ValidationError(s)}for(var f=0;f<u.length;f++)u[f].check(r[f]);return c.check(e.apply(void 0,o([],n(r))))}}}}},316:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.checked=r.check=void 0;var n=t(888),o=t(611),a=new WeakMap;function i(e,r,t){var n=a.get(e),o=n&&n.get(r);if(o)return o;for(var i=[],u=0;u<t;u++)i.push(u);return i}r.check=function(e,r,t){var n=a.get(e)||new Map;a.set(e,n);var o=n.get(r)||[];n.set(r,o),o.push(t)},r.checked=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];if(0===e.length)throw new Error("No runtype provided to `@checked`. Please remove the decorator.");return function(r,t,a){var u=a.value,c=(r.name||r.constructor.name+".prototype")+("string"==typeof t?'["'+t+'"]':"["+String(t)+"]"),l=i(r,t,e.length);if(l.length!==e.length)throw new Error("Number of `@checked` runtypes and @check parameters not matched.");if(l.length>u.length)throw new Error("Number of `@checked` runtypes exceeds actual parameter length.");a.value=function(){for(var r=[],t=0;t<arguments.length;t++)r[t]=arguments[t];return e.forEach((function(e,t){var a=l[t],i=e.validate(r[a]);if(!i.success){var u=c+", argument #"+a+": "+i.message,s=o.FAILURE.ARGUMENT_INCORRECT(u);throw new n.ValidationError(s)}})),u.apply(this,r)}}}},888:function(e,r){var t,n=this&&this.__extends||(t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,r){e.__proto__=r}||function(e,r){for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])})(e,r)},function(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)});Object.defineProperty(r,"__esModule",{value:!0}),r.ValidationError=void 0;var o=function(e){function r(t){var n=e.call(this,t.message)||this;return n.name="ValidationError",n.code=t.code,void 0!==t.details&&(n.details=t.details),Object.setPrototypeOf(n,r.prototype),n}return n(r,e),r}(Error);r.ValidationError=o},529:function(e,r,t){var n=this&&this.__createBinding||(Object.create?function(e,r,t,n){void 0===n&&(n=t),Object.defineProperty(e,n,{enumerable:!0,get:function(){return r[t]}})}:function(e,r,t,n){void 0===n&&(n=t),e[n]=r[t]}),o=this&&this.__exportStar||function(e,r){for(var t in e)"default"===t||Object.prototype.hasOwnProperty.call(r,t)||n(r,e,t)};Object.defineProperty(r,"__esModule",{value:!0}),r.InstanceOf=r.Null=r.Undefined=r.Literal=void 0,o(t(550),r),o(t(691),r),o(t(361),r),o(t(36),r),o(t(74),r),o(t(888),r),o(t(101),r),o(t(913),r),o(t(203),r);var a=t(275);Object.defineProperty(r,"Literal",{enumerable:!0,get:function(){return a.Literal}}),Object.defineProperty(r,"Undefined",{enumerable:!0,get:function(){return a.Undefined}}),Object.defineProperty(r,"Null",{enumerable:!0,get:function(){return a.Null}}),o(t(19),r),o(t(257),r),o(t(481),r),o(t(304),r),o(t(333),r),o(t(380),r),o(t(226),r),o(t(695),r),o(t(132),r),o(t(724),r),o(t(239),r),o(t(209),r),o(t(559),r);var i=t(867);Object.defineProperty(r,"InstanceOf",{enumerable:!0,get:function(){return i.InstanceOf}}),o(t(802),r),o(t(845),r),o(t(111),r),o(t(316),r)},74:function(e,r){var t=this&&this.__values||function(e){var r="function"==typeof Symbol&&Symbol.iterator,t=r&&e[r],n=0;if(t)return t.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(r?"Object is not iterable.":"Symbol.iterator is not defined.")},n=this&&this.__read||function(e,r){var t="function"==typeof Symbol&&e[Symbol.iterator];if(!t)return e;var n,o,a=t.call(e),i=[];try{for(;(void 0===r||r-- >0)&&!(n=a.next()).done;)i.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(t=a.return)&&t.call(a)}finally{if(o)throw o.error}}return i};Object.defineProperty(r,"__esModule",{value:!0}),r.match=void 0,r.match=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return function(r){var o,a;try{for(var i=t(e),u=i.next();!u.done;u=i.next()){var c=n(u.value,2),l=c[0],s=c[1];if(l.guard(r))return s(r)}}catch(e){o={error:e}}finally{try{u&&!u.done&&(a=i.return)&&a.call(i)}finally{if(o)throw o.error}}throw new Error("No alternatives were matched")}}},550:(e,r)=>{Object.defineProperty(r,"__esModule",{value:!0})},691:(e,r)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.Failcode=void 0,r.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,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.innerValidate=r.create=void 0;var n=t(529),o=t(233),a=t(888),i=t(611);r.create=function(e,r){return r.check=t,r.assert=t,r._innerValidate=function(t,n){return n.has(t,r)?i.SUCCESS(t):e(t,n)},r.validate=function(e){return r._innerValidate(e,(t=new WeakMap,n=function(e,r){if(null!==e&&"object"==typeof e){var n=t.get(e);t.set(e,n?n.set(r,!0):(new WeakMap).set(r,!0))}},{has:function(e,r){var o=t.get(e),a=o&&o.get(r)||!1;return n(e,r),a}}));var t,n},r.guard=function(e){return r.validate(e).success},r.Or=function(e){return n.Union(r,e)},r.And=function(e){return n.Intersect(r,e)},r.optional=function(){return n.Optional(r)},r.nullable=function(){return n.Union(r,n.Null)},r.withConstraint=function(e,t){return n.Constraint(r,e,t)},r.withGuard=function(e,t){return n.Constraint(r,e,t)},r.withBrand=function(e){return n.Brand(e,r)},r.reflect=r,r.toString=function(){return"Runtype<"+o.default(r)+">"},r;function t(e){var t=r.validate(e);if(t.success)return t.value;throw new a.ValidationError(t)}},r.innerValidate=function(e,r,t){return e._innerValidate(r,t)}},233:(e,r)=>{Object.defineProperty(r,"__esModule",{value:!0});var t=function(e,r){return function(o){var a=function(r){return e?"("+r+")":r};if(r.has(o))return a("CIRCULAR "+o.tag);r.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 i=o.value;return"string"==typeof i?'"'+i+'"':String(i);case"array":return""+n(o)+t(!0,r)(o.element)+"[]";case"dictionary":return"{ [_: "+o.key+"]: "+t(!1,r)(o.value)+" }";case"record":var u=Object.keys(o.fields);return u.length?"{ "+u.map((function(e){return""+n(o)+e+(i=e,u=(a=o).isPartial,c=a.fields,(u||void 0!==i&&"optional"===c[i].tag?"?":"")+": ")+("optional"===o.fields[e].tag?t(!1,r)(o.fields[e].underlying):t(!1,r)(o.fields[e]))+";";var a,i,u,c})).join(" ")+" }":"{}";case"tuple":return"["+o.components.map(t(!1,r)).join(", ")+"]";case"union":return a(""+o.alternatives.map(t(!0,r)).join(" | "));case"intersect":return a(""+o.intersectees.map(t(!0,r)).join(" & "));case"optional":return t(e,r)(o.underlying)+" | undefined";case"constraint":return o.name||t(e,r)(o.underlying);case"instanceof":return o.ctor.name;case"brand":return t(e,r)(o.entity)}}finally{r.delete(o)}throw Error("impossible")}};function n(e){return e.isReadonly?"readonly ":""}r.default=t(!1,new Set)},380:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.Array=void 0;var n=t(732),o=t(611);function a(e,r){var t,i={tag:"array",isReadonly:r,element:e};return(t=n.create((function(r,t){if(!Array.isArray(r))return o.FAILURE.TYPE_INCORRECT(i,r);var a=o.enumerableKeysOf(r),u=a.map((function(o){return n.innerValidate(e,r[o],t)})),c=a.reduce((function(e,r){var t=u[r];return t.success||(e[r]=t.details||t.message),e}),[]);return 0!==o.enumerableKeysOf(c).length?o.FAILURE.CONTENT_INCORRECT(i,c):o.SUCCESS(r)}),i)).asReadonly=function(){return a(t.element,!0)},t}r.Array=function(e){return a(e,!1)}},481:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.BigInt=void 0;var n=t(732),o=t(611),a={tag:"bigint"};r.BigInt=n.create((function(e){return"bigint"==typeof e?o.SUCCESS(e):o.FAILURE.TYPE_INCORRECT(a,e)}),a)},19:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.Boolean=void 0;var n=t(732),o=t(611),a={tag:"boolean"};r.Boolean=n.create((function(e){return"boolean"==typeof e?o.SUCCESS(e):o.FAILURE.TYPE_INCORRECT(a,e)}),a)},111:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.Brand=void 0;var n=t(732);r.Brand=function(e,r){var t={tag:"brand",brand:e,entity:r};return n.create((function(e){return r.validate(e)}),t)}},845:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.Guard=r.Constraint=void 0;var n=t(732),o=t(611),a=t(101);r.Constraint=function(e,r,t){var a=t&&t.name,i=t&&t.args,u={tag:"constraint",underlying:e,constraint:r,name:a,args:i};return n.create((function(t){var n=e.validate(t);if(!n.success)return n;var a=r(n.value);return"string"==typeof a?o.FAILURE.CONSTRAINT_FAILED(u,a):a?o.SUCCESS(n.value):o.FAILURE.CONSTRAINT_FAILED(u)}),u)},r.Guard=function(e,r){return a.Unknown.withGuard(e,r)}},132:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.Dictionary=void 0;var n=t(732),o=t(304),a=t(845),i=t(233),u=t(611),c=a.Constraint(o.String,(function(e){return!isNaN(+e)}),{name:"number"});r.Dictionary=function(e,r){var a=void 0===r||"string"===r?o.String:"number"===r?c:r,l=i.default(a),s={tag:"dictionary",key:l,value:e};return n.create((function(r,o){if(null==r||"object"!=typeof r)return u.FAILURE.TYPE_INCORRECT(s,r);if(Object.getPrototypeOf(r)!==Object.prototype&&(!Array.isArray(r)||"string"===l))return u.FAILURE.TYPE_INCORRECT(s,r);var i=/^(?:NaN|-?\d+(?:\.\d+)?)$/u,c=u.enumerableKeysOf(r),f=c.reduce((function(c,l){var f="string"==typeof l&&i.test(l),d=f?t.g.Number(l):l;return(f?a.guard(d)||a.guard(l):a.guard(d))?c[l]=n.innerValidate(e,r[l],o):c[l]=u.FAILURE.KEY_INCORRECT(s,a.reflect,d),c}),{}),d=c.reduce((function(e,r){var t=f[r];return t.success||(e[r]=t.details||t.message),e}),{});return 0!==u.enumerableKeysOf(d).length?u.FAILURE.CONTENT_INCORRECT(s,d):u.SUCCESS(r)}),s)}},559:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.Function=void 0;var n=t(732),o=t(611),a={tag:"function"};r.Function=n.create((function(e){return"function"==typeof e?o.SUCCESS(e):o.FAILURE.TYPE_INCORRECT(a,e)}),a)},867:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.InstanceOf=void 0;var n=t(732),o=t(611);r.InstanceOf=function(e){var r={tag:"instanceof",ctor:e};return n.create((function(t){return t instanceof e?o.SUCCESS(t):o.FAILURE.TYPE_INCORRECT(r,t)}),r)}},239:function(e,r,t){var n=this&&this.__values||function(e){var r="function"==typeof Symbol&&Symbol.iterator,t=r&&e[r],n=0;if(t)return t.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(r?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(r,"__esModule",{value:!0}),r.Intersect=void 0;var o=t(732),a=t(611);r.Intersect=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];var t={tag:"intersect",intersectees:e};return o.create((function(r,t){var i,u;try{for(var c=n(e),l=c.next();!l.done;l=c.next()){var s=l.value,f=o.innerValidate(s,r,t);if(!f.success)return f}}catch(e){i={error:e}}finally{try{l&&!l.done&&(u=c.return)&&u.call(c)}finally{if(i)throw i.error}}return a.SUCCESS(r)}),t)}},802:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.Lazy=void 0;var n=t(732);r.Lazy=function(e){var r,t={get tag(){return o().tag}};function o(){if(!r)for(var n in r=e())"tag"!==n&&(t[n]=r[n]);return r}return n.create((function(e){return o().validate(e)}),t)}},275:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.Null=r.Undefined=r.Literal=void 0;var n=t(732),o=t(611);function a(e){return Array.isArray(e)?String(e.map(String)):"bigint"==typeof e?String(e)+"n":String(e)}function i(e){var r={tag:"literal",value:e};return n.create((function(r){return r===e?o.SUCCESS(r):o.FAILURE.VALUE_INCORRECT("literal","`"+a(e)+"`","`"+a(r)+"`")}),r)}r.Literal=i,r.Undefined=i(void 0),r.Null=i(null)},913:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.Never=void 0;var n=t(732),o=t(611);r.Never=n.create(o.FAILURE.NOTHING_EXPECTED,{tag:"never"})},257:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.Number=void 0;var n=t(732),o=t(611),a={tag:"number"};r.Number=n.create((function(e){return"number"==typeof e?o.SUCCESS(e):o.FAILURE.TYPE_INCORRECT(a,e)}),a)},209:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.Optional=void 0;var n=t(732),o=t(611);r.Optional=function(e){var r={tag:"optional",underlying:e};return n.create((function(r){return void 0===r?o.SUCCESS(r):e.validate(r)}),r)}},695:function(e,r,t){var n=this&&this.__read||function(e,r){var t="function"==typeof Symbol&&e[Symbol.iterator];if(!t)return e;var n,o,a=t.call(e),i=[];try{for(;(void 0===r||r-- >0)&&!(n=a.next()).done;)i.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(t=a.return)&&t.call(a)}finally{if(o)throw o.error}}return i},o=this&&this.__spreadArray||function(e,r){for(var t=0,n=r.length,o=e.length;t<n;t++,o++)e[o]=r[t];return e};Object.defineProperty(r,"__esModule",{value:!0}),r.Partial=r.Record=r.InternalRecord=void 0;var a=t(732),i=t(611);function u(e,r,t){var c,l={tag:"record",isPartial:r,isReadonly:t,fields:e};return(c=a.create((function(t,u){if(null==t)return i.FAILURE.TYPE_INCORRECT(l,t);var c=i.enumerableKeysOf(e);if(0!==c.length&&"object"!=typeof t)return i.FAILURE.TYPE_INCORRECT(l,t);var s=o([],n(new Set(o(o([],n(c)),n(i.enumerableKeysOf(t)))))),f=s.reduce((function(n,o){var c=i.hasKey(o,e),l=i.hasKey(o,t);if(c){var s=e[o],f=r||"optional"===s.reflect.tag;if(l){var d=t[o];n[o]=f&&void 0===d?i.SUCCESS(d):a.innerValidate(s,d,u)}else n[o]=f?i.SUCCESS(void 0):i.FAILURE.PROPERTY_MISSING(s.reflect)}else{if(!l)throw new Error("impossible");d=t[o],n[o]=i.SUCCESS(d)}return n}),{}),d=s.reduce((function(e,r){var t=f[r];return t.success||(e[r]=t.details||t.message),e}),{});return 0!==i.enumerableKeysOf(d).length?i.FAILURE.CONTENT_INCORRECT(l,d):i.SUCCESS(t)}),l)).asPartial=function(){return u(c.fields,!0,c.isReadonly)},c.asReadonly=function(){return u(c.fields,c.isPartial,!0)},c.pick=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];var t={};return e.forEach((function(e){t[e]=c.fields[e]})),u(t,c.isPartial,c.isReadonly)},c.omit=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];var t={};return i.enumerableKeysOf(c.fields).forEach((function(r){e.includes(r)||(t[r]=c.fields[r])})),u(t,c.isPartial,c.isReadonly)},c}r.InternalRecord=u,r.Record=function(e){return u(e,!1,!1)},r.Partial=function(e){return u(e,!0,!1)}},304:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.String=void 0;var n=t(732),o=t(611),a={tag:"string"};r.String=n.create((function(e){return"string"==typeof e?o.SUCCESS(e):o.FAILURE.TYPE_INCORRECT(a,e)}),a)},333:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.Symbol=void 0;var n=t(732),o=t(611),a={tag:"symbol"};r.Symbol=n.create((function(e){return"symbol"==typeof e?o.SUCCESS(e):o.FAILURE.TYPE_INCORRECT(a,e)}),Object.assign((function(e){var r={tag:"symbol",key:e};return n.create((function(n){if("symbol"!=typeof n)return o.FAILURE.TYPE_INCORRECT(r,n);var a=t.g.Symbol.keyFor(n);return a!==e?o.FAILURE.VALUE_INCORRECT("symbol key",i(e),i(a)):o.SUCCESS(n)}),r)}),a));var i=function(e){return void 0===e?"undefined":'"'+e+'"'}},226:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.Tuple=void 0;var n=t(732),o=t(611);r.Tuple=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];var t={tag:"tuple",components:e};return n.create((function(r,a){if(!Array.isArray(r))return o.FAILURE.TYPE_INCORRECT(t,r);if(r.length!==e.length)return o.FAILURE.CONSTRAINT_FAILED(t,"Expected length "+e.length+", but was "+r.length);var i=o.enumerableKeysOf(r),u=i.map((function(t){return n.innerValidate(e[t],r[t],a)})),c=i.reduce((function(e,r){var t=u[r];return t.success||(e[r]=t.details||t.message),e}),[]);return 0!==o.enumerableKeysOf(c).length?o.FAILURE.CONTENT_INCORRECT(t,c):o.SUCCESS(r)}),t)}},724:function(e,r,t){var n=this&&this.__values||function(e){var r="function"==typeof Symbol&&Symbol.iterator,t=r&&e[r],n=0;if(t)return t.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(r?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(r,"__esModule",{value:!0}),r.Union=void 0;var o=t(732),a=t(611);r.Union=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];var t=function(){for(var r=[],t=0;t<arguments.length;t++)r[t]=arguments[t];return function(t){for(var n=0;n<e.length;n++)if(e[n].guard(t))return r[n](t)}},i={tag:"union",alternatives:e,match:t};return o.create((function(r,t){var u,c,l,s,f,d,v,E;if("object"!=typeof r||null===r){try{for(var y=n(e),R=y.next();!R.done;R=y.next()){var h=R.value;if(o.innerValidate(h,r,t).success)return a.SUCCESS(r)}}catch(e){u={error:e}}finally{try{R&&!R.done&&(c=y.return)&&c.call(y)}finally{if(u)throw u.error}}return a.FAILURE.TYPE_INCORRECT(i,r)}var p={};try{for(var _=n(e),g=_.next();!g.done;g=_.next())if("record"===(h=g.value).reflect.tag){var C=function(e){var r=h.reflect.fields[e];"literal"===r.tag&&(p[e]?p[e].every((function(e){return e!==r.value}))&&p[e].push(r.value):p[e]=[r.value])};for(var T in h.reflect.fields)C(T)}}catch(e){l={error:e}}finally{try{g&&!g.done&&(s=_.return)&&s.call(_)}finally{if(l)throw l.error}}for(var T in p)if(p[T].length===e.length)try{for(var O=(f=void 0,n(e)),b=O.next();!b.done;b=O.next())if("record"===(h=b.value).reflect.tag){var S=h.reflect.fields[T];if("literal"===S.tag&&a.hasKey(T,r)&&r[T]===S.value)return o.innerValidate(h,r,t)}}catch(e){f={error:e}}finally{try{b&&!b.done&&(d=O.return)&&d.call(O)}finally{if(f)throw f.error}}try{for(var I=n(e),m=I.next();!m.done;m=I.next()){var N=m.value;if(o.innerValidate(N,r,t).success)return a.SUCCESS(r)}}catch(e){v={error:e}}finally{try{m&&!m.done&&(E=I.return)&&E.call(I)}finally{if(v)throw v.error}}return a.FAILURE.TYPE_INCORRECT(i,r)}),i)}},101:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.Unknown=void 0;var n=t(732),o=t(611);r.Unknown=n.create((function(e){return o.SUCCESS(e)}),{tag:"unknown"})},203:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.Void=void 0;var n=t(101);r.Void=n.Unknown},611:function(e,r,t){var n=this&&this.__assign||function(){return(n=Object.assign||function(e){for(var r,t=1,n=arguments.length;t<n;t++)for(var o in r=arguments[t])Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o]);return e}).apply(this,arguments)};Object.defineProperty(r,"__esModule",{value:!0}),r.FAILURE=r.SUCCESS=r.enumerableKeysOf=r.typeOf=r.hasKey=void 0;var o=t(691),a=t(233);r.hasKey=function(e,r){return"object"==typeof r&&null!==r&&e in r},r.typeOf=function(e){return"object"==typeof e?null===e?"null":Array.isArray(e)?"array":"Object"===e.constructor.name?"object":e.constructor.name:typeof e},r.enumerableKeysOf=function(e){return"object"==typeof e&&null!==e?Reflect.ownKeys(e).filter((function(r){var t,n;return null===(n=null===(t=e.propertyIsEnumerable)||void 0===t?void 0:t.call(e,r))||void 0===n||n})):[]},r.SUCCESS=function(e){return{success:!0,value:e}},r.FAILURE=Object.assign((function(e,r,t){return n({success:!1,code:e,message:r},t?{details:t}:{})}),{TYPE_INCORRECT:function(e,t){var n="Expected "+a.default(e)+", but was "+r.typeOf(t);return r.FAILURE(o.Failcode.TYPE_INCORRECT,n)},VALUE_INCORRECT:function(e,t,n){return r.FAILURE(o.Failcode.VALUE_INCORRECT,"Expected "+e+" "+String(t)+", but was "+String(n))},KEY_INCORRECT:function(e,t,n){return r.FAILURE(o.Failcode.KEY_INCORRECT,"Expected "+a.default(e)+" key to be "+a.default(t)+", but was "+r.typeOf(n))},CONTENT_INCORRECT:function(e,t){var n="Expected "+a.default(e)+", but was incompatible";return r.FAILURE(o.Failcode.CONTENT_INCORRECT,n,t)},ARGUMENT_INCORRECT:function(e){return r.FAILURE(o.Failcode.ARGUMENT_INCORRECT,e)},RETURN_INCORRECT:function(e){return r.FAILURE(o.Failcode.RETURN_INCORRECT,e)},CONSTRAINT_FAILED:function(e,t){var n=t?": "+t:"";return r.FAILURE(o.Failcode.CONSTRAINT_FAILED,"Failed constraint check for "+a.default(e)+n)},PROPERTY_MISSING:function(e){var t="Expected "+a.default(e)+", but was missing";return r.FAILURE(o.Failcode.PROPERTY_MISSING,t)},PROPERTY_PRESENT:function(e){var t="Expected nothing, but was "+r.typeOf(e);return r.FAILURE(o.Failcode.PROPERTY_PRESENT,t)},NOTHING_EXPECTED:function(e){var t="Expected nothing, but was "+r.typeOf(e);return r.FAILURE(o.Failcode.NOTHING_EXPECTED,t)}})}},r={};function t(n){var o=r[n];if(void 0!==o)return o.exports;var a=r[n]={exports:{}};return e[n].call(a.exports,a,a.exports,t),a.exports}t.d=(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},t.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),t.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),t.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};return(()=>{t.r(n),t.d(n,{activate:()=>S,requestLogin:()=>b,subscribeToUserUpdates:()=>O});let e=window||t.g;const r=(r,t)=>{e.addEventListener(r,(e=>{e.stopImmediatePropagation(),t.apply(window,[e])}))},o=(r,t)=>{e.addEventListener(r,(e=>{t.apply(window,[e])}))},a=r=>{e.dispatchEvent(r)};var i=t(529);const u=(0,i.Record)({user_name:i.String,tracking_key:i.String}),c=(0,i.Record)({name:i.String,trackingKey:i.String}),l=window["amedia-user-cache"]={},s={get:e=>{const r=l[e];return Promise.resolve(r)},set:(e,r,t)=>(l[e]={key:e,data:r,expires:t},Promise.resolve()),remove:e=>(delete l[e],Promise.resolve())},f={debug:console.debug,info:console.log,warning:console.warn,error:console.error};const d=()=>s,v=e=>d().remove(e),E=(e,r)=>{return t=void 0,n=void 0,a=function*(){const t=yield d().get(e);if(!t)return Promise.resolve();if(Date.now()>t.expires)return v(e),Promise.resolve();try{return r.check(t.data)}catch(r){return r instanceof i.ValidationError?f.error("Failed validating data",{data:t.data,error:r.details}):f.error("Unknown error",r),v(e),Promise.resolve()}},new((o=void 0)||(o=Promise))((function(e,r){function i(e){try{c(a.next(e))}catch(e){r(e)}}function u(e){try{c(a.throw(e))}catch(e){r(e)}}function c(r){var t;r.done?e(r.value):(t=r.value,t instanceof o?t:new o((function(e){e(t)}))).then(i,u)}c((a=a.apply(t,n||[])).next())}));var t,n,o,a};let y=!1;const R="is_logged_in",h=()=>{return e=void 0,r=void 0,n=function*(){if(y)return null;y=!0;const e=yield E(R,c);if(e)return y=!1,e;const r=yield(t=void 0,n=void 0,o=void 0,a=function*(){return fetch("/api/pluto/v1/sessions/current").then((e=>{if(!e.ok)throw new Error(`Request not ok (${e.status}: ${e.statusText}).`);return e.json()})).then((e=>{try{return{name:(r=u.check(e)).user_name,trackingKey:r.tracking_key}}catch(e){throw console.error("Invalid schema",e),e}var r}))},new(o||(o=Promise))((function(e,r){function i(e){try{c(a.next(e))}catch(e){r(e)}}function u(e){try{c(a.throw(e))}catch(e){r(e)}}function c(r){var t;r.done?e(r.value):(t=r.value,t instanceof o?t:new o((function(e){e(t)}))).then(i,u)}c((a=a.apply(t,n||[])).next())})));var t,n,o,a,i,l,s;return i=R,l=r,s=Date.now()+1e4,d().set(i,l,s),y=!1,r},new((t=void 0)||(t=Promise))((function(o,a){function i(e){try{c(n.next(e))}catch(e){a(e)}}function u(e){try{c(n.throw(e))}catch(e){a(e)}}function c(e){var r;e.done?o(e.value):(r=e.value,r instanceof t?r:new t((function(e){e(r)}))).then(i,u)}c((n=n.apply(e,r||[])).next())}));var e,r,t,n};var p;!function(e){e.REQUEST_LOGIN="amedia-user.authentication.request-login",e.REQUEST_LOGOUT="amedia-user.authentication.request-logout"}(p||(p={})),r(p.REQUEST_LOGIN,(e=>{(e=>{const r=new URL("https://aid.no/logg_inn/");r.searchParams.set("requestedUrl",e||window.location.href),window.location.href=r.href})(e.detail.requestedUrl||window.location.href)})),r(p.REQUEST_LOGOUT,(()=>{}));const _={name:h,trackingKey:h};var g;!function(e){e.REQUEST_USER_ATTRIBUTES="amedia-user.request-user-attributes",e.ON_USER_ATTRIBUTES_UPDATED="amedia-user.on-user-attributes-updated"}(g||(g={})),r(g.REQUEST_USER_ATTRIBUTES,(e=>{((e,r)=>{const t=[];for(e.forEach((e=>{const r=_[e];r?t.includes(r)||t.push(r):console.warn("Unknown attribute was requested")}));t.length>0;){const e=t.pop();e&&e().then((e=>{r(e)}))}})(e.detail,(e=>{a(new CustomEvent(g.ON_USER_ATTRIBUTES_UPDATED,{detail:e}))}))}));const C=(0,i.Record)({id:i.Number,domain:i.String});var T;(0,i.Record)({status:(0,i.Literal)("success"),access:(0,i.Union)((0,i.Literal)("granted"),(0,i.Literal)("denied")),publication:C,access_features:(0,i.Array)(i.String)}),(0,i.Record)({status:(0,i.Literal)("success"),cookie:i.String,access_features:(0,i.Array)(i.String)}),(0,i.Record)({status:(0,i.Literal)("success"),vstoken_cookie:i.String,uuid:i.String,access_features:(0,i.Array)(i.String)}),function(e){e.REQUEST_ACTIVATION="amedia-user.activation.request-activation",e.ON_ACTIVATION_COMPLETE="amedia-user.activation.on-activation-complete"}(T||(T={})),r(T.REQUEST_ACTIVATION,(()=>{new Promise(((e,r)=>{setTimeout((()=>{e({status:"success"})}),1e3)})).then((e=>{a(new CustomEvent(T.ON_ACTIVATION_COMPLETE,{detail:e}))}))}));const O=(e,r)=>{o(g.ON_USER_ATTRIBUTES_UPDATED,(t=>{const n=t.detail,o={isLoggedIn:n.isLoggedIn};e.forEach((e=>{void 0!==n[e]&&(o[e]=n[e])})),r(o)})),a(new CustomEvent(g.REQUEST_USER_ATTRIBUTES,{detail:e}))},b=e=>a(new CustomEvent(p.REQUEST_LOGIN,{detail:{requestedUrl:e}})),S=()=>new Promise(((e,r)=>{o(T.ON_ACTIVATION_COMPLETE,(r=>{e(r)})),a(new CustomEvent(T.REQUEST_ACTIVATION))}))})(),n})()}));
|
|
1
|
+
!function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.user=r():e.user=r()}(this,(function(){return(()=>{"use strict";var e={896:function(e,r,t){var n=this&&this.__read||function(e,r){var t="function"==typeof Symbol&&e[Symbol.iterator];if(!t)return e;var n,o,a=t.call(e),i=[];try{for(;(void 0===r||r-- >0)&&!(n=a.next()).done;)i.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(t=a.return)&&t.call(a)}finally{if(o)throw o.error}}return i},o=this&&this.__spreadArray||function(e,r){for(var t=0,n=r.length,o=e.length;t<n;t++,o++)e[o]=r[t];return e};Object.defineProperty(r,"__esModule",{value:!0}),r.AsyncContract=void 0;var a=t(174),i=t(589);r.AsyncContract=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];var t=e.length-1,u=e.slice(0,t),c=e[t];return{enforce:function(e){return function(){for(var r=[],t=0;t<arguments.length;t++)r[t]=arguments[t];if(r.length<u.length){var l="Expected "+u.length+" arguments but only received "+r.length,f=i.FAILURE.ARGUMENT_INCORRECT(l);throw new a.ValidationError(f)}for(var s=0;s<u.length;s++)u[s].check(r[s]);var d=e.apply(void 0,o([],n(r)));if(!(d instanceof Promise))throw l="Expected function to return a promise, but instead got "+d,f=i.FAILURE.RETURN_INCORRECT(l),new a.ValidationError(f);return d.then(c.check)}}}}},308:function(e,r,t){var n=this&&this.__read||function(e,r){var t="function"==typeof Symbol&&e[Symbol.iterator];if(!t)return e;var n,o,a=t.call(e),i=[];try{for(;(void 0===r||r-- >0)&&!(n=a.next()).done;)i.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(t=a.return)&&t.call(a)}finally{if(o)throw o.error}}return i},o=this&&this.__spreadArray||function(e,r){for(var t=0,n=r.length,o=e.length;t<n;t++,o++)e[o]=r[t];return e};Object.defineProperty(r,"__esModule",{value:!0}),r.Contract=void 0;var a=t(174),i=t(589);r.Contract=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];var t=e.length-1,u=e.slice(0,t),c=e[t];return{enforce:function(e){return function(){for(var r=[],t=0;t<arguments.length;t++)r[t]=arguments[t];if(r.length<u.length){var l="Expected "+u.length+" arguments but only received "+r.length,f=i.FAILURE.ARGUMENT_INCORRECT(l);throw new a.ValidationError(f)}for(var s=0;s<u.length;s++)u[s].check(r[s]);return c.check(e.apply(void 0,o([],n(r))))}}}}},965:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.checked=r.check=void 0;var n=t(174),o=t(589),a=new WeakMap;function i(e,r,t){var n=a.get(e),o=n&&n.get(r);if(o)return o;for(var i=[],u=0;u<t;u++)i.push(u);return i}r.check=function(e,r,t){var n=a.get(e)||new Map;a.set(e,n);var o=n.get(r)||[];n.set(r,o),o.push(t)},r.checked=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];if(0===e.length)throw new Error("No runtype provided to `@checked`. Please remove the decorator.");return function(r,t,a){var u=a.value,c=(r.name||r.constructor.name+".prototype")+("string"==typeof t?'["'+t+'"]':"["+String(t)+"]"),l=i(r,t,e.length);if(l.length!==e.length)throw new Error("Number of `@checked` runtypes and @check parameters not matched.");if(l.length>u.length)throw new Error("Number of `@checked` runtypes exceeds actual parameter length.");a.value=function(){for(var r=[],t=0;t<arguments.length;t++)r[t]=arguments[t];return e.forEach((function(e,t){var a=l[t],i=e.validate(r[a]);if(!i.success){var u=c+", argument #"+a+": "+i.message,f=o.FAILURE.ARGUMENT_INCORRECT(u);throw new n.ValidationError(f)}})),u.apply(this,r)}}}},174:function(e,r){var t,n=this&&this.__extends||(t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,r){e.__proto__=r}||function(e,r){for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])})(e,r)},function(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)});Object.defineProperty(r,"__esModule",{value:!0}),r.ValidationError=void 0;var o=function(e){function r(t){var n=e.call(this,t.message)||this;return n.name="ValidationError",n.code=t.code,void 0!==t.details&&(n.details=t.details),Object.setPrototypeOf(n,r.prototype),n}return n(r,e),r}(Error);r.ValidationError=o},61:function(e,r,t){var n=this&&this.__createBinding||(Object.create?function(e,r,t,n){void 0===n&&(n=t),Object.defineProperty(e,n,{enumerable:!0,get:function(){return r[t]}})}:function(e,r,t,n){void 0===n&&(n=t),e[n]=r[t]}),o=this&&this.__exportStar||function(e,r){for(var t in e)"default"===t||Object.prototype.hasOwnProperty.call(r,t)||n(r,e,t)};Object.defineProperty(r,"__esModule",{value:!0}),r.InstanceOf=r.Null=r.Undefined=r.Literal=void 0,o(t(350),r),o(t(205),r),o(t(308),r),o(t(896),r),o(t(339),r),o(t(174),r),o(t(615),r),o(t(551),r),o(t(362),r);var a=t(620);Object.defineProperty(r,"Literal",{enumerable:!0,get:function(){return a.Literal}}),Object.defineProperty(r,"Undefined",{enumerable:!0,get:function(){return a.Undefined}}),Object.defineProperty(r,"Null",{enumerable:!0,get:function(){return a.Null}}),o(t(643),r),o(t(422),r),o(t(172),r),o(t(856),r),o(t(59),r),o(t(669),r),o(t(941),r),o(t(489),r),o(t(745),r),o(t(219),r),o(t(617),r),o(t(979),r),o(t(548),r);var i=t(937);Object.defineProperty(r,"InstanceOf",{enumerable:!0,get:function(){return i.InstanceOf}}),o(t(813),r),o(t(277),r),o(t(550),r),o(t(965),r)},339:function(e,r){var t=this&&this.__values||function(e){var r="function"==typeof Symbol&&Symbol.iterator,t=r&&e[r],n=0;if(t)return t.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(r?"Object is not iterable.":"Symbol.iterator is not defined.")},n=this&&this.__read||function(e,r){var t="function"==typeof Symbol&&e[Symbol.iterator];if(!t)return e;var n,o,a=t.call(e),i=[];try{for(;(void 0===r||r-- >0)&&!(n=a.next()).done;)i.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(t=a.return)&&t.call(a)}finally{if(o)throw o.error}}return i};Object.defineProperty(r,"__esModule",{value:!0}),r.match=void 0,r.match=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return function(r){var o,a;try{for(var i=t(e),u=i.next();!u.done;u=i.next()){var c=n(u.value,2),l=c[0],f=c[1];if(l.guard(r))return f(r)}}catch(e){o={error:e}}finally{try{u&&!u.done&&(a=i.return)&&a.call(i)}finally{if(o)throw o.error}}throw new Error("No alternatives were matched")}}},350:(e,r)=>{Object.defineProperty(r,"__esModule",{value:!0})},205:(e,r)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.Failcode=void 0,r.Failcode={TYPE_INCORRECT:"TYPE_INCORRECT",VALUE_INCORRECT:"VALUE_INCORRECT",KEY_INCORRECT:"KEY_INCORRECT",CONTENT_INCORRECT:"CONTENT_INCORRECT",ARGUMENT_INCORRECT:"ARGUMENT_INCORRECT",RETURN_INCORRECT:"RETURN_INCORRECT",CONSTRAINT_FAILED:"CONSTRAINT_FAILED",PROPERTY_MISSING:"PROPERTY_MISSING",PROPERTY_PRESENT:"PROPERTY_PRESENT",NOTHING_EXPECTED:"NOTHING_EXPECTED"}},705:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.innerValidate=r.create=void 0;var n=t(61),o=t(268),a=t(174),i=t(589);r.create=function(e,r){return r.check=t,r.assert=t,r._innerValidate=function(t,n){return n.has(t,r)?i.SUCCESS(t):e(t,n)},r.validate=function(e){return r._innerValidate(e,(t=new WeakMap,n=function(e,r){if(null!==e&&"object"==typeof e){var n=t.get(e);t.set(e,n?n.set(r,!0):(new WeakMap).set(r,!0))}},{has:function(e,r){var o=t.get(e),a=o&&o.get(r)||!1;return n(e,r),a}}));var t,n},r.guard=function(e){return r.validate(e).success},r.Or=function(e){return n.Union(r,e)},r.And=function(e){return n.Intersect(r,e)},r.optional=function(){return n.Optional(r)},r.nullable=function(){return n.Union(r,n.Null)},r.withConstraint=function(e,t){return n.Constraint(r,e,t)},r.withGuard=function(e,t){return n.Constraint(r,e,t)},r.withBrand=function(e){return n.Brand(e,r)},r.reflect=r,r.toString=function(){return"Runtype<"+o.default(r)+">"},r;function t(e){var t=r.validate(e);if(t.success)return t.value;throw new a.ValidationError(t)}},r.innerValidate=function(e,r,t){return e._innerValidate(r,t)}},268:(e,r)=>{Object.defineProperty(r,"__esModule",{value:!0});var t=function(e,r){return function(o){var a=function(r){return e?"("+r+")":r};if(r.has(o))return a("CIRCULAR "+o.tag);r.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 i=o.value;return"string"==typeof i?'"'+i+'"':String(i);case"array":return""+n(o)+t(!0,r)(o.element)+"[]";case"dictionary":return"{ [_: "+o.key+"]: "+t(!1,r)(o.value)+" }";case"record":var u=Object.keys(o.fields);return u.length?"{ "+u.map((function(e){return""+n(o)+e+(i=e,u=(a=o).isPartial,c=a.fields,(u||void 0!==i&&"optional"===c[i].tag?"?":"")+": ")+("optional"===o.fields[e].tag?t(!1,r)(o.fields[e].underlying):t(!1,r)(o.fields[e]))+";";var a,i,u,c})).join(" ")+" }":"{}";case"tuple":return"["+o.components.map(t(!1,r)).join(", ")+"]";case"union":return a(""+o.alternatives.map(t(!0,r)).join(" | "));case"intersect":return a(""+o.intersectees.map(t(!0,r)).join(" & "));case"optional":return t(e,r)(o.underlying)+" | undefined";case"constraint":return o.name||t(e,r)(o.underlying);case"instanceof":return o.ctor.name;case"brand":return t(e,r)(o.entity)}}finally{r.delete(o)}throw Error("impossible")}};function n(e){return e.isReadonly?"readonly ":""}r.default=t(!1,new Set)},669:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.Array=void 0;var n=t(705),o=t(589);function a(e,r){var t,i={tag:"array",isReadonly:r,element:e};return(t=n.create((function(r,t){if(!Array.isArray(r))return o.FAILURE.TYPE_INCORRECT(i,r);var a=o.enumerableKeysOf(r),u=a.map((function(o){return n.innerValidate(e,r[o],t)})),c=a.reduce((function(e,r){var t=u[r];return t.success||(e[r]=t.details||t.message),e}),[]);return 0!==o.enumerableKeysOf(c).length?o.FAILURE.CONTENT_INCORRECT(i,c):o.SUCCESS(r)}),i)).asReadonly=function(){return a(t.element,!0)},t}r.Array=function(e){return a(e,!1)}},172:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.BigInt=void 0;var n=t(705),o=t(589),a={tag:"bigint"};r.BigInt=n.create((function(e){return"bigint"==typeof e?o.SUCCESS(e):o.FAILURE.TYPE_INCORRECT(a,e)}),a)},643:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.Boolean=void 0;var n=t(705),o=t(589),a={tag:"boolean"};r.Boolean=n.create((function(e){return"boolean"==typeof e?o.SUCCESS(e):o.FAILURE.TYPE_INCORRECT(a,e)}),a)},550:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.Brand=void 0;var n=t(705);r.Brand=function(e,r){var t={tag:"brand",brand:e,entity:r};return n.create((function(e){return r.validate(e)}),t)}},277:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.Guard=r.Constraint=void 0;var n=t(705),o=t(589),a=t(615);r.Constraint=function(e,r,t){var a=t&&t.name,i=t&&t.args,u={tag:"constraint",underlying:e,constraint:r,name:a,args:i};return n.create((function(t){var n=e.validate(t);if(!n.success)return n;var a=r(n.value);return"string"==typeof a?o.FAILURE.CONSTRAINT_FAILED(u,a):a?o.SUCCESS(n.value):o.FAILURE.CONSTRAINT_FAILED(u)}),u)},r.Guard=function(e,r){return a.Unknown.withGuard(e,r)}},745:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.Dictionary=void 0;var n=t(705),o=t(856),a=t(277),i=t(268),u=t(589),c=a.Constraint(o.String,(function(e){return!isNaN(+e)}),{name:"number"});r.Dictionary=function(e,r){var a=void 0===r||"string"===r?o.String:"number"===r?c:r,l=i.default(a),f={tag:"dictionary",key:l,value:e};return n.create((function(r,o){if(null==r||"object"!=typeof r)return u.FAILURE.TYPE_INCORRECT(f,r);if(Object.getPrototypeOf(r)!==Object.prototype&&(!Array.isArray(r)||"string"===l))return u.FAILURE.TYPE_INCORRECT(f,r);var i=/^(?:NaN|-?\d+(?:\.\d+)?)$/u,c=u.enumerableKeysOf(r),s=c.reduce((function(c,l){var s="string"==typeof l&&i.test(l),d=s?t.g.Number(l):l;return(s?a.guard(d)||a.guard(l):a.guard(d))?c[l]=n.innerValidate(e,r[l],o):c[l]=u.FAILURE.KEY_INCORRECT(f,a.reflect,d),c}),{}),d=c.reduce((function(e,r){var t=s[r];return t.success||(e[r]=t.details||t.message),e}),{});return 0!==u.enumerableKeysOf(d).length?u.FAILURE.CONTENT_INCORRECT(f,d):u.SUCCESS(r)}),f)}},548:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.Function=void 0;var n=t(705),o=t(589),a={tag:"function"};r.Function=n.create((function(e){return"function"==typeof e?o.SUCCESS(e):o.FAILURE.TYPE_INCORRECT(a,e)}),a)},937:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.InstanceOf=void 0;var n=t(705),o=t(589);r.InstanceOf=function(e){var r={tag:"instanceof",ctor:e};return n.create((function(t){return t instanceof e?o.SUCCESS(t):o.FAILURE.TYPE_INCORRECT(r,t)}),r)}},617:function(e,r,t){var n=this&&this.__values||function(e){var r="function"==typeof Symbol&&Symbol.iterator,t=r&&e[r],n=0;if(t)return t.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(r?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(r,"__esModule",{value:!0}),r.Intersect=void 0;var o=t(705),a=t(589);r.Intersect=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];var t={tag:"intersect",intersectees:e};return o.create((function(r,t){var i,u;try{for(var c=n(e),l=c.next();!l.done;l=c.next()){var f=l.value,s=o.innerValidate(f,r,t);if(!s.success)return s}}catch(e){i={error:e}}finally{try{l&&!l.done&&(u=c.return)&&u.call(c)}finally{if(i)throw i.error}}return a.SUCCESS(r)}),t)}},813:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.Lazy=void 0;var n=t(705);r.Lazy=function(e){var r,t={get tag(){return o().tag}};function o(){if(!r)for(var n in r=e())"tag"!==n&&(t[n]=r[n]);return r}return n.create((function(e){return o().validate(e)}),t)}},620:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.Null=r.Undefined=r.Literal=void 0;var n=t(705),o=t(589);function a(e){return Array.isArray(e)?String(e.map(String)):"bigint"==typeof e?String(e)+"n":String(e)}function i(e){var r={tag:"literal",value:e};return n.create((function(r){return r===e?o.SUCCESS(r):o.FAILURE.VALUE_INCORRECT("literal","`"+a(e)+"`","`"+a(r)+"`")}),r)}r.Literal=i,r.Undefined=i(void 0),r.Null=i(null)},551:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.Never=void 0;var n=t(705),o=t(589);r.Never=n.create(o.FAILURE.NOTHING_EXPECTED,{tag:"never"})},422:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.Number=void 0;var n=t(705),o=t(589),a={tag:"number"};r.Number=n.create((function(e){return"number"==typeof e?o.SUCCESS(e):o.FAILURE.TYPE_INCORRECT(a,e)}),a)},979:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.Optional=void 0;var n=t(705),o=t(589);r.Optional=function(e){var r={tag:"optional",underlying:e};return n.create((function(r){return void 0===r?o.SUCCESS(r):e.validate(r)}),r)}},489:function(e,r,t){var n=this&&this.__read||function(e,r){var t="function"==typeof Symbol&&e[Symbol.iterator];if(!t)return e;var n,o,a=t.call(e),i=[];try{for(;(void 0===r||r-- >0)&&!(n=a.next()).done;)i.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(t=a.return)&&t.call(a)}finally{if(o)throw o.error}}return i},o=this&&this.__spreadArray||function(e,r){for(var t=0,n=r.length,o=e.length;t<n;t++,o++)e[o]=r[t];return e};Object.defineProperty(r,"__esModule",{value:!0}),r.Partial=r.Record=r.InternalRecord=void 0;var a=t(705),i=t(589);function u(e,r,t){var c,l={tag:"record",isPartial:r,isReadonly:t,fields:e};return(c=a.create((function(t,u){if(null==t)return i.FAILURE.TYPE_INCORRECT(l,t);var c=i.enumerableKeysOf(e);if(0!==c.length&&"object"!=typeof t)return i.FAILURE.TYPE_INCORRECT(l,t);var f=o([],n(new Set(o(o([],n(c)),n(i.enumerableKeysOf(t)))))),s=f.reduce((function(n,o){var c=i.hasKey(o,e),l=i.hasKey(o,t);if(c){var f=e[o],s=r||"optional"===f.reflect.tag;if(l){var d=t[o];n[o]=s&&void 0===d?i.SUCCESS(d):a.innerValidate(f,d,u)}else n[o]=s?i.SUCCESS(void 0):i.FAILURE.PROPERTY_MISSING(f.reflect)}else{if(!l)throw new Error("impossible");d=t[o],n[o]=i.SUCCESS(d)}return n}),{}),d=f.reduce((function(e,r){var t=s[r];return t.success||(e[r]=t.details||t.message),e}),{});return 0!==i.enumerableKeysOf(d).length?i.FAILURE.CONTENT_INCORRECT(l,d):i.SUCCESS(t)}),l)).asPartial=function(){return u(c.fields,!0,c.isReadonly)},c.asReadonly=function(){return u(c.fields,c.isPartial,!0)},c.pick=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];var t={};return e.forEach((function(e){t[e]=c.fields[e]})),u(t,c.isPartial,c.isReadonly)},c.omit=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];var t={};return i.enumerableKeysOf(c.fields).forEach((function(r){e.includes(r)||(t[r]=c.fields[r])})),u(t,c.isPartial,c.isReadonly)},c}r.InternalRecord=u,r.Record=function(e){return u(e,!1,!1)},r.Partial=function(e){return u(e,!0,!1)}},856:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.String=void 0;var n=t(705),o=t(589),a={tag:"string"};r.String=n.create((function(e){return"string"==typeof e?o.SUCCESS(e):o.FAILURE.TYPE_INCORRECT(a,e)}),a)},59:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.Symbol=void 0;var n=t(705),o=t(589),a={tag:"symbol"};r.Symbol=n.create((function(e){return"symbol"==typeof e?o.SUCCESS(e):o.FAILURE.TYPE_INCORRECT(a,e)}),Object.assign((function(e){var r={tag:"symbol",key:e};return n.create((function(n){if("symbol"!=typeof n)return o.FAILURE.TYPE_INCORRECT(r,n);var a=t.g.Symbol.keyFor(n);return a!==e?o.FAILURE.VALUE_INCORRECT("symbol key",i(e),i(a)):o.SUCCESS(n)}),r)}),a));var i=function(e){return void 0===e?"undefined":'"'+e+'"'}},941:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.Tuple=void 0;var n=t(705),o=t(589);r.Tuple=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];var t={tag:"tuple",components:e};return n.create((function(r,a){if(!Array.isArray(r))return o.FAILURE.TYPE_INCORRECT(t,r);if(r.length!==e.length)return o.FAILURE.CONSTRAINT_FAILED(t,"Expected length "+e.length+", but was "+r.length);var i=o.enumerableKeysOf(r),u=i.map((function(t){return n.innerValidate(e[t],r[t],a)})),c=i.reduce((function(e,r){var t=u[r];return t.success||(e[r]=t.details||t.message),e}),[]);return 0!==o.enumerableKeysOf(c).length?o.FAILURE.CONTENT_INCORRECT(t,c):o.SUCCESS(r)}),t)}},219:function(e,r,t){var n=this&&this.__values||function(e){var r="function"==typeof Symbol&&Symbol.iterator,t=r&&e[r],n=0;if(t)return t.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(r?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(r,"__esModule",{value:!0}),r.Union=void 0;var o=t(705),a=t(589);r.Union=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];var t=function(){for(var r=[],t=0;t<arguments.length;t++)r[t]=arguments[t];return function(t){for(var n=0;n<e.length;n++)if(e[n].guard(t))return r[n](t)}},i={tag:"union",alternatives:e,match:t};return o.create((function(r,t){var u,c,l,f,s,d,v,E;if("object"!=typeof r||null===r){try{for(var y=n(e),p=y.next();!p.done;p=y.next()){var R=p.value;if(o.innerValidate(R,r,t).success)return a.SUCCESS(r)}}catch(e){u={error:e}}finally{try{p&&!p.done&&(c=y.return)&&c.call(y)}finally{if(u)throw u.error}}return a.FAILURE.TYPE_INCORRECT(i,r)}var g={};try{for(var h=n(e),_=h.next();!_.done;_=h.next())if("record"===(R=_.value).reflect.tag){var O=function(e){var r=R.reflect.fields[e];"literal"===r.tag&&(g[e]?g[e].every((function(e){return e!==r.value}))&&g[e].push(r.value):g[e]=[r.value])};for(var b in R.reflect.fields)O(b)}}catch(e){l={error:e}}finally{try{_&&!_.done&&(f=h.return)&&f.call(h)}finally{if(l)throw l.error}}for(var b in g)if(g[b].length===e.length)try{for(var C=(s=void 0,n(e)),T=C.next();!T.done;T=C.next())if("record"===(R=T.value).reflect.tag){var S=R.reflect.fields[b];if("literal"===S.tag&&a.hasKey(b,r)&&r[b]===S.value)return o.innerValidate(R,r,t)}}catch(e){s={error:e}}finally{try{T&&!T.done&&(d=C.return)&&d.call(C)}finally{if(s)throw s.error}}try{for(var m=n(e),I=m.next();!I.done;I=m.next()){var N=I.value;if(o.innerValidate(N,r,t).success)return a.SUCCESS(r)}}catch(e){v={error:e}}finally{try{I&&!I.done&&(E=m.return)&&E.call(m)}finally{if(v)throw v.error}}return a.FAILURE.TYPE_INCORRECT(i,r)}),i)}},615:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.Unknown=void 0;var n=t(705),o=t(589);r.Unknown=n.create((function(e){return o.SUCCESS(e)}),{tag:"unknown"})},362:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.Void=void 0;var n=t(615);r.Void=n.Unknown},589:function(e,r,t){var n=this&&this.__assign||function(){return(n=Object.assign||function(e){for(var r,t=1,n=arguments.length;t<n;t++)for(var o in r=arguments[t])Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o]);return e}).apply(this,arguments)};Object.defineProperty(r,"__esModule",{value:!0}),r.FAILURE=r.SUCCESS=r.enumerableKeysOf=r.typeOf=r.hasKey=void 0;var o=t(205),a=t(268);r.hasKey=function(e,r){return"object"==typeof r&&null!==r&&e in r},r.typeOf=function(e){return"object"==typeof e?null===e?"null":Array.isArray(e)?"array":"Object"===e.constructor.name?"object":e.constructor.name:typeof e},r.enumerableKeysOf=function(e){return"object"==typeof e&&null!==e?Reflect.ownKeys(e).filter((function(r){var t,n;return null===(n=null===(t=e.propertyIsEnumerable)||void 0===t?void 0:t.call(e,r))||void 0===n||n})):[]},r.SUCCESS=function(e){return{success:!0,value:e}},r.FAILURE=Object.assign((function(e,r,t){return n({success:!1,code:e,message:r},t?{details:t}:{})}),{TYPE_INCORRECT:function(e,t){var n="Expected "+a.default(e)+", but was "+r.typeOf(t);return r.FAILURE(o.Failcode.TYPE_INCORRECT,n)},VALUE_INCORRECT:function(e,t,n){return r.FAILURE(o.Failcode.VALUE_INCORRECT,"Expected "+e+" "+String(t)+", but was "+String(n))},KEY_INCORRECT:function(e,t,n){return r.FAILURE(o.Failcode.KEY_INCORRECT,"Expected "+a.default(e)+" key to be "+a.default(t)+", but was "+r.typeOf(n))},CONTENT_INCORRECT:function(e,t){var n="Expected "+a.default(e)+", but was incompatible";return r.FAILURE(o.Failcode.CONTENT_INCORRECT,n,t)},ARGUMENT_INCORRECT:function(e){return r.FAILURE(o.Failcode.ARGUMENT_INCORRECT,e)},RETURN_INCORRECT:function(e){return r.FAILURE(o.Failcode.RETURN_INCORRECT,e)},CONSTRAINT_FAILED:function(e,t){var n=t?": "+t:"";return r.FAILURE(o.Failcode.CONSTRAINT_FAILED,"Failed constraint check for "+a.default(e)+n)},PROPERTY_MISSING:function(e){var t="Expected "+a.default(e)+", but was missing";return r.FAILURE(o.Failcode.PROPERTY_MISSING,t)},PROPERTY_PRESENT:function(e){var t="Expected nothing, but was "+r.typeOf(e);return r.FAILURE(o.Failcode.PROPERTY_PRESENT,t)},NOTHING_EXPECTED:function(e){var t="Expected nothing, but was "+r.typeOf(e);return r.FAILURE(o.Failcode.NOTHING_EXPECTED,t)}})}},r={};function t(n){var o=r[n];if(void 0!==o)return o.exports;var a=r[n]={exports:{}};return e[n].call(a.exports,a,a.exports,t),a.exports}t.d=(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},t.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),t.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),t.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};return(()=>{t.r(n),t.d(n,{activate:()=>j,requestLogin:()=>A,subscribeToUserUpdates:()=>w});const e={debug:console.debug,info:console.log,warn:console.warn,error:console.error};var r,o;"undefined"!=typeof window&&(o=window,r=o);var a=function(t,n){r?r.addEventListener(t,(function(e){e.stopImmediatePropagation(),n.apply(window,[e])})):e.error("No root element to bind event to!")},i=function(t,n){r?r.addEventListener(t,(function(e){n.apply(window,[e])})):e.error("No root element to bind event to!")},u=function(t){r?r.dispatchEvent(t):e.error("No root element to dispatch event on!")},c=t(61);function l(e,r,t,n,o,a,i){try{var u=e[a](i),c=u.value}catch(e){return void t(e)}u.done?r(c):Promise.resolve(c).then(n,o)}var f=(0,c.Record)({user_name:c.String,tracking_key:c.String}),s=(0,c.Record)({name:c.String,trackingKey:c.String}),d=function(){var e,r=(e=regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",fetch("/api/pluto/v1/sessions/current").then((function(e){if(!e.ok)throw new Error("Request not ok (".concat(e.status,": ").concat(e.statusText,")."));return e.json()})).then((function(e){try{return{name:(r=f.check(e)).user_name,trackingKey:r.tracking_key}}catch(e){throw console.error("Invalid schema",e),e}var r})));case 1:case"end":return e.stop()}}),e)})),function(){var r=this,t=arguments;return new Promise((function(n,o){var a=e.apply(r,t);function i(e){l(a,n,o,i,u,"next",e)}function u(e){l(a,n,o,i,u,"throw",e)}i(void 0)}))});return function(){return r.apply(this,arguments)}}(),v=("undefined"!=typeof window?window:t.g)["amedia-user-cache"]={};const E={get:function(e){var r=v[e];return Promise.resolve(r)},set:function(e,r,t){return v[e]={key:e,data:r,expires:t},Promise.resolve()},remove:function(e){return delete v[e],Promise.resolve()}};function y(e,r,t,n,o,a,i){try{var u=e[a](i),c=u.value}catch(e){return void t(e)}u.done?r(c):Promise.resolve(c).then(n,o)}var p=function(){return E},R=function(e){return p().remove(e)};const g={get:function(){var r,t=(r=regeneratorRuntime.mark((function r(t,n){var o,a;return regeneratorRuntime.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,p().get(t);case 2:if(o=r.sent){r.next=5;break}return r.abrupt("return",Promise.resolve());case 5:if(!(Date.now()>o.expires)){r.next=8;break}return R(t),r.abrupt("return",Promise.resolve());case 8:return r.prev=8,a=n.check(o.data),r.abrupt("return",a);case 13:return r.prev=13,r.t0=r.catch(8),r.t0 instanceof c.ValidationError?e.error("Failed validating data",{data:o.data,error:r.t0.details}):e.error("Unknown error",r.t0),R(t),r.abrupt("return",Promise.resolve());case 18:case"end":return r.stop()}}),r,null,[[8,13]])})),function(){var e=this,t=arguments;return new Promise((function(n,o){var a=r.apply(e,t);function i(e){y(a,n,o,i,u,"next",e)}function u(e){y(a,n,o,i,u,"throw",e)}i(void 0)}))});return function(e,r){return t.apply(this,arguments)}}(),set:function(e,r,t){return p().set(e,r,t)},remove:R};function h(e,r,t,n,o,a,i){try{var u=e[a](i),c=u.value}catch(e){return void t(e)}u.done?r(c):Promise.resolve(c).then(n,o)}var _,O=!1,b="is_logged_in",C=function(){var e,r=(e=regeneratorRuntime.mark((function e(){var r,t;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!O){e.next=2;break}return e.abrupt("return",null);case 2:return O=!0,e.next=5,g.get(b,s);case 5:if(!(r=e.sent)){e.next=9;break}return O=!1,e.abrupt("return",r);case 9:return e.next=11,d();case 11:return t=e.sent,g.set(b,t,Date.now()+1e4),O=!1,e.abrupt("return",t);case 15:case"end":return e.stop()}}),e)})),function(){var r=this,t=arguments;return new Promise((function(n,o){var a=e.apply(r,t);function i(e){h(a,n,o,i,u,"next",e)}function u(e){h(a,n,o,i,u,"throw",e)}i(void 0)}))});return function(){return r.apply(this,arguments)}}();!function(e){e.REQUEST_LOGIN="amedia-user.authentication.request-login",e.REQUEST_LOGOUT="amedia-user.authentication.request-logout"}(_||(_={})),a(_.REQUEST_LOGIN,(function(e){var r,t;r=e.detail.requestedUrl||window.location.href,(t=new URL("https://aid.no/logg_inn/")).searchParams.set("requestedUrl",r||window.location.href),window.location.href=t.href})),a(_.REQUEST_LOGOUT,(function(){}));var T,S={name:C,trackingKey:C};function m(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function I(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?m(Object(t),!0).forEach((function(r){N(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):m(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}function N(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}!function(e){e.REQUEST_USER_ATTRIBUTES="amedia-user.request-user-attributes",e.ON_USER_ATTRIBUTES_UPDATED="amedia-user.on-user-attributes-updated"}(T||(T={})),a(T.REQUEST_USER_ATTRIBUTES,(function(e){!function(e,r){var t=[];for(e.forEach((function(e){var r=S[e];r?t.includes(r)||t.push(r):console.warn("Unknown attribute was requested")}));t.length>0;){var n=t.pop();n&&n().then((function(e){r(e)}))}}(e.detail,(function(e){u(new CustomEvent(T.ON_USER_ATTRIBUTES_UPDATED,{detail:I(I({},e),{},{isLoggedIn:!(null==e||!e.name)})}))}))}));var U,P=(0,c.Record)({id:c.Number,domain:c.String});(0,c.Record)({status:(0,c.Literal)("success"),access:(0,c.Union)((0,c.Literal)("granted"),(0,c.Literal)("denied")),publication:P,access_features:(0,c.Array)(c.String)}),(0,c.Record)({status:(0,c.Literal)("success"),cookie:c.String,access_features:(0,c.Array)(c.String)}),(0,c.Record)({status:(0,c.Literal)("success"),vstoken_cookie:c.String,uuid:c.String,access_features:(0,c.Array)(c.String)}),function(e){e.REQUEST_ACTIVATION="amedia-user.activation.request-activation",e.ON_ACTIVATION_COMPLETE="amedia-user.activation.on-activation-complete"}(U||(U={})),a(U.REQUEST_ACTIVATION,(function(){new Promise((function(e,r){setTimeout((function(){e({status:"success"})}),1e3)})).then((function(e){u(new CustomEvent(U.ON_ACTIVATION_COMPLETE,{detail:e}))}))}));var w=function(r,t){i(T.ON_USER_ATTRIBUTES_UPDATED,(function(n){var o=n.detail;if(o){var a={};void 0!==o.isLoggedIn&&(a.isLoggedIn=o.isLoggedIn),r.forEach((function(e){void 0!==o[e]&&(a[e]=o[e])})),t(a)}else e.warn("Nå attributes received",o)})),u(new CustomEvent(T.REQUEST_USER_ATTRIBUTES,{detail:r}))},A=function(e){return u(new CustomEvent(_.REQUEST_LOGIN,{detail:{requestedUrl:e}}))},j=function(){return new Promise((function(e,r){i(U.ON_ACTIVATION_COMPLETE,(function(r){e(r)})),u(new CustomEvent(U.REQUEST_ACTIVATION))}))}})(),n})()}));
|
package/dist/utils/log.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amedia/user",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Client lib for working with aID user and associated data",
|
|
5
5
|
"repository": "https://github.com/amedia/amedia-user-js",
|
|
6
6
|
"author": "Amedia Utvikling (ID og data)",
|
|
@@ -11,16 +11,21 @@
|
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"dexie": "3.0.3",
|
|
14
|
+
"npm-run-all": "4.1.5",
|
|
14
15
|
"runtypes": "6.2.1"
|
|
15
16
|
},
|
|
16
17
|
"devDependencies": {
|
|
17
18
|
"@amedia/eslint-config-base": "4.0.7",
|
|
18
19
|
"@amedia/eslint-config-typescript": "4.0.10",
|
|
20
|
+
"@babel/core": "7.14.0",
|
|
21
|
+
"@babel/preset-env": "7.14.1",
|
|
22
|
+
"@babel/preset-typescript": "7.13.0",
|
|
19
23
|
"@types/convict": "6.0.1",
|
|
20
24
|
"@types/dexie": "1.3.1",
|
|
21
25
|
"@types/jest": "^26.0.23",
|
|
22
26
|
"@typescript-eslint/eslint-plugin": "4.22.0",
|
|
23
27
|
"babel-eslint": "10.1.0",
|
|
28
|
+
"babel-loader": "8.2.2",
|
|
24
29
|
"eslint": "7.24.0",
|
|
25
30
|
"eslint-config-airbnb-typescript": "12.3.1",
|
|
26
31
|
"eslint-config-prettier": "8.2.0",
|
|
@@ -28,6 +33,7 @@
|
|
|
28
33
|
"jest": "^26.6.3",
|
|
29
34
|
"jest-fetch-mock": "^3.0.3",
|
|
30
35
|
"prettier": "2.2.1",
|
|
36
|
+
"source-map-loader": "2.0.1",
|
|
31
37
|
"ts-jest": "^26.5.5",
|
|
32
38
|
"ts-loader": "9.1.0",
|
|
33
39
|
"typescript": "4.2.4",
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { CacheEntry, Engine } from '../types';
|
|
2
2
|
|
|
3
3
|
// eslint-disable-next-line no-multi-assign
|
|
4
|
-
const cache = (window
|
|
4
|
+
const cache = ((typeof window !== 'undefined' ? window : global)[
|
|
5
|
+
'amedia-user-cache'
|
|
6
|
+
] = {});
|
|
5
7
|
|
|
6
8
|
export const get = (key: string): Promise<CacheEntry> => {
|
|
7
9
|
const data = cache[key];
|
package/src/cache/index.spec.ts
CHANGED
|
@@ -6,7 +6,6 @@ import { Record, String } from 'runtypes';
|
|
|
6
6
|
import cache, { setCacheEngine } from '.';
|
|
7
7
|
import log from '../utils/log';
|
|
8
8
|
import resetAllMocks = jest.resetAllMocks;
|
|
9
|
-
import stringMatching = jasmine.stringMatching;
|
|
10
9
|
|
|
11
10
|
const TestDataSchema = Record({
|
|
12
11
|
test: String,
|
|
@@ -21,7 +21,8 @@ export const listenForUserAttributeRequests = () => {
|
|
|
21
21
|
fetchDataBasedOnAttributes(evt.detail, (attributes) => {
|
|
22
22
|
dispatch(
|
|
23
23
|
new CustomEvent(AmediaUserEvents.ON_USER_ATTRIBUTES_UPDATED, {
|
|
24
|
-
|
|
24
|
+
// TODO Fix hacky isLoggedIn
|
|
25
|
+
detail: { ...attributes, isLoggedIn: !!attributes?.name },
|
|
25
26
|
})
|
|
26
27
|
);
|
|
27
28
|
});
|
package/src/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { AmediaUserEvents } from './eventHandlers/userAttributes';
|
|
|
3
3
|
import { ActivationEvents } from './eventHandlers/activation';
|
|
4
4
|
import { dispatch, listenForAllEvents } from './utils/customEventWrapper';
|
|
5
5
|
import { UserAttributes } from './types';
|
|
6
|
+
import log from './utils/log';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Enables you to subscribe to the user attributes you care about and
|
|
@@ -25,10 +26,20 @@ export const subscribeToUserUpdates = <T extends Array<keyof UserAttributes>>(
|
|
|
25
26
|
) => {
|
|
26
27
|
listenForAllEvents(AmediaUserEvents.ON_USER_ATTRIBUTES_UPDATED, (evt) => {
|
|
27
28
|
const userAttributes = evt.detail;
|
|
29
|
+
|
|
30
|
+
if (!userAttributes) {
|
|
31
|
+
log.warn('Nå attributes received', userAttributes);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
28
35
|
// @ts-ignore
|
|
29
|
-
const responseAttributes: Pick<
|
|
30
|
-
|
|
31
|
-
|
|
36
|
+
const responseAttributes: Pick<
|
|
37
|
+
UserAttributes,
|
|
38
|
+
T[number] | 'isLoggedIn'
|
|
39
|
+
> = {};
|
|
40
|
+
if (userAttributes.isLoggedIn !== undefined) {
|
|
41
|
+
responseAttributes.isLoggedIn = userAttributes.isLoggedIn;
|
|
42
|
+
}
|
|
32
43
|
attributes.forEach((attribute) => {
|
|
33
44
|
if (userAttributes[attribute] !== undefined) {
|
|
34
45
|
responseAttributes[attribute] = userAttributes[attribute];
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
import log from './log';
|
|
2
|
+
|
|
3
|
+
let rootElement;
|
|
2
4
|
|
|
3
5
|
export const setRootElement = (element) => {
|
|
4
6
|
rootElement = element;
|
|
5
7
|
};
|
|
6
8
|
|
|
9
|
+
if (typeof window !== 'undefined') {
|
|
10
|
+
setRootElement(window);
|
|
11
|
+
}
|
|
12
|
+
|
|
7
13
|
/**
|
|
8
14
|
* This listener MUST be used by all listeners in ../eventHandlers
|
|
9
15
|
* We want to ensure that only _one_ instance of this package actually
|
|
@@ -15,6 +21,10 @@ export const listenWithExclusivity = <T extends keyof WindowEventMap>(
|
|
|
15
21
|
type: T,
|
|
16
22
|
listener: (this: Window, ev: WindowEventMap[T]) => void
|
|
17
23
|
) => {
|
|
24
|
+
if (!rootElement) {
|
|
25
|
+
log.error('No root element to bind event to!');
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
18
28
|
rootElement.addEventListener(type, (evt) => {
|
|
19
29
|
// Since this lib might me loaded multiple times, we need to prevent all other processing of this event.
|
|
20
30
|
evt.stopImmediatePropagation();
|
|
@@ -32,11 +42,19 @@ export const listenForAllEvents = <T extends keyof WindowEventMap>(
|
|
|
32
42
|
type: T,
|
|
33
43
|
listener: (this: Window, ev: WindowEventMap[T]) => void
|
|
34
44
|
) => {
|
|
45
|
+
if (!rootElement) {
|
|
46
|
+
log.error('No root element to bind event to!');
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
35
49
|
rootElement.addEventListener(type, (evt) => {
|
|
36
50
|
listener.apply(window, [evt]);
|
|
37
51
|
});
|
|
38
52
|
};
|
|
39
53
|
|
|
40
54
|
export const dispatch = <T extends Event>(event: T) => {
|
|
55
|
+
if (!rootElement) {
|
|
56
|
+
log.error('No root element to dispatch event on!');
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
41
59
|
rootElement.dispatchEvent(event);
|
|
42
60
|
};
|
package/src/utils/log.ts
CHANGED
package/tsconfig.json
CHANGED
|
@@ -1,23 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"extends": "@amedia/eslint-config-typescript/tsconfig.json",
|
|
3
3
|
"compilerOptions": {
|
|
4
|
-
"outDir": "./dist/",
|
|
5
4
|
"rootDir": "./src",
|
|
5
|
+
"outDir": "./dist/",
|
|
6
|
+
//"noImplicitAny": true,
|
|
6
7
|
"typeRoots": [
|
|
7
8
|
"./node_modules/@types"
|
|
8
9
|
],
|
|
9
|
-
"module": "ES6",
|
|
10
10
|
"lib": [
|
|
11
11
|
"DOM"
|
|
12
12
|
],
|
|
13
|
-
|
|
14
|
-
},
|
|
15
|
-
"exclude": [
|
|
16
|
-
"node_modules",
|
|
17
|
-
"config",
|
|
18
|
-
"**/*.spec.ts"
|
|
19
|
-
],
|
|
20
|
-
"include": [
|
|
21
|
-
"src/**/*",
|
|
22
|
-
]
|
|
13
|
+
}
|
|
23
14
|
}
|
package/webpack.config.js
CHANGED