@telia-ace/widget-services 1.1.1-rc.1 → 1.1.1-rc.3

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.
Files changed (3) hide show
  1. package/index.js +14 -14
  2. package/index.mjs +120 -348
  3. package/package.json +2 -2
package/index.js CHANGED
@@ -1,19 +1,19 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=(t,e,...n)=>typeof e=="string"?t(`[humany] ${e}`,...n):t(e,...n),w=class{constructor(){this.keys=[],this.log=(t,...e)=>this.lookup(t,()=>w.log(...e)),this.warn=(t,...e)=>this.lookup(t,()=>w.warn(...e)),this.error=(t,...e)=>this.lookup(t,()=>w.error(...e)),this.info=(t,...e)=>this.lookup(t,()=>w.info(...e))}lookup(t,e){this.keys.indexOf(t)===-1&&(this.keys.push(t),e())}};let g=w;g.log=(...t)=>E(console.log,...t);g.warn=(...t)=>E(console.warn,...t);g.error=(...t)=>E(console.error,...t);g.info=(...t)=>E(console.info,...t);const M=t=>{let e={},n,r;if(typeof t!="object"||t===null)return t;e=Array.isArray(t)?[]:{};for(r in t)n=t[r],e[r]=typeof n=="object"&&n!==null?M(n):n;return e};function V(t){let e=0;if(t.length===0)return e.toString();for(let n=0;n<t.length;n++){const r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return e.toString()}class B{constructor(e,n){this.lockWarningTime=e,this.lockErrorTime=n,this.tasks=[],this.current=Promise.resolve(),this.next=this.next.bind(this)}add(e,n,r,s){this.tasks.push({task:e,resolve:n,reject:r,done:s}),this.next()}next(){this.current=this.current.then(()=>{const e=this.tasks.shift();if(e){let n;const r=setTimeout(()=>{process.env.NODE_ENV!=="production"&&g.warn(`A lock has exceeded ${this.lockWarningTime} ms. Waiting additional ${this.lockErrorTime} ms before rejecting the task.`,e),n=setTimeout(()=>{e.reject("lock timeout exceeded")},this.lockErrorTime)},this.lockWarningTime),s=Promise.resolve(e.task()).then(o=>(clearTimeout(r),clearTimeout(n),o));return Promise.resolve(s).then(this.next).then(()=>s.then(o=>{e.done(),e.resolve(o)})).catch(o=>(e.done(),e.reject(o),this.next()))}return Promise.resolve()})}}const N=new WeakMap;function f(t,e=5e3,n=1e3){return N.has(t)||N.set(t,new B(e,n)),r=>new Promise((s,o)=>{const i=N.get(t);i.add(r,s,o,()=>{i.tasks.length||N.delete(t)})})}var d=(t=>(t.Cookie="cookie",t.Local="local",t.Session="session",t))(d||{}),S=(t=>(t.Tenant="tenant",t.Implementation="implementation",t.Widget="widget",t))(S||{}),l=(t=>(t.Necessary="necessary",t.Functional="functional",t.Analytical="analytical",t.Marketing="marketing",t))(l||{});const F=(t,e,n,r={})=>j(t,n).then(s=>(process.env.NODE_ENV!=="production"&&s&&g.warn(`createStorageWriter: Attempted to create storage writer using unallowed category.
2
- Key: ${e}
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@telia-ace/widget-utilities"),L=require("@webprovisions/platform");var l=(e=>(e.Cookie="cookie",e.Local="local",e.Session="session",e))(l||{}),p=(e=>(e.Tenant="tenant",e.Implementation="implementation",e.Widget="widget",e))(p||{}),d=(e=>(e.Necessary="necessary",e.Functional="functional",e.Analytical="analytical",e.Marketing="marketing",e))(d||{});const K=(e,t,n,r={})=>k(e,n).then(s=>(process.env.NODE_ENV!=="production"&&s&&c.Logger.warn(`createStorageWriter: Attempted to create storage writer using unallowed category.
2
+ Key: ${t}
3
3
  Category: ${JSON.stringify(n)}
4
- Options: ${JSON.stringify(r)}`),o=>(W(t),j(t,n).then(i=>{if(i){process.env.NODE_ENV!=="production"&&g.warn(`storageWriter: Attempted to write to storage using unallowed category.
5
- Key: ${e}
4
+ Options: ${JSON.stringify(r)}`),o=>(D(e),k(e,n).then(i=>{if(i){process.env.NODE_ENV!=="production"&&c.Logger.warn(`storageWriter: Attempted to write to storage using unallowed category.
5
+ Key: ${t}
6
6
  Category: ${JSON.stringify(n)}
7
7
  Value: ${JSON.stringify(o)}
8
- Options: ${JSON.stringify(r)}`);return}const{scope:a=S.Widget,medium:c=d.Session,duration:u}=r,m=H();return m[a][e]=K(o,n,u),c===d.Cookie?ee(t,m):ne(t,c,m)})))),z=(t,e,n=d.Session)=>(W(t),typeof e>"u"?(process.env.NODE_ENV!=="production"&&g.warn("readStorage: Undefined key passed when reading storage. ",e,n),Promise.resolve(void 0)):n===d.Cookie?Z(t).then(r=>P(r,e)):te(t,n).then(r=>P(r,e))),h=t=>!!Object.entries(t).filter(([e,n])=>typeof n<"u").length,x=t=>Object.entries(t).filter(([e,n])=>typeof n<"u").forEach(([e,{value:n}])=>{typeof n>"u"&&delete t[e]}),R=(t,e)=>{const n={tenant:{...t.tenant,...e.tenant},implementation:{...t.implementation,...e.implementation},widget:{...t.widget,...e.widget}};return x(n.tenant),x(n.implementation),x(n.widget),n},G=t=>Object.entries(t).reduce((n,r)=>{const[s,o]=r;return Object.entries(o).forEach(i=>{const[a,{expiration:c}]=i;c&&n.push(c)}),n},[]).slice().sort((n,r)=>new Date(r).valueOf()-new Date(n).valueOf()).shift()||b(),C=t=>{const{name:e,implementation:{name:n,tenant:r}}=t.get("$widget");return[`humany_${r}`,`humany_${V(r+n)}`,`humany_${V(r+n+e)}`]},T=t=>{const e=new RegExp(`(?:^|;)\\s?${t}=(.*?)(?:;|$)`,"i"),n=document.cookie.match(e);return n&&n[1]&&JSON.parse(n[1])||void 0},I=(t,e,n)=>{const r=`${t}=${JSON.stringify(e).trim()}`,s=`expires=${new Date(n).toUTCString()}`,o="path=/",i="SameSite=None;Secure";return document.cookie=`${r}; ${s}; ${o}; ${i}`},_=t=>{const[e,n,r]=C(t),s=T(e)||{},o=T(n)||{},i=T(r)||{};return{tenant:s,implementation:o,widget:i}},U=(t,e)=>{const n=_(t),r=R(n,e),[s,o,i]=C(t),{tenant:a,implementation:c,widget:u}=r,m=G(e),y=b({days:-1});I(s,a,h(a)?m:y),I(o,c,h(c)?m:y),I(i,u,h(u)?m:y)},k=(t,e)=>{const[n,r,s]=C(t),o=e.getItem(n)||"{}",i=e.getItem(r)||"{}",a=e.getItem(s)||"{}";return{tenant:JSON.parse(o),implementation:JSON.parse(i),widget:JSON.parse(a)}},D=(t,e,n)=>{const r=k(t,e),s=R(r,n),[o,i,a]=C(t),{tenant:c,implementation:u,widget:m}=s;h(c)?e.setItem(o,JSON.stringify(c)):e.removeItem(o),h(u)?e.setItem(i,JSON.stringify(u)):e.removeItem(i),h(m)?e.setItem(a,JSON.stringify(m)):e.removeItem(a)},H=()=>({tenant:{},implementation:{},widget:{}}),X=t=>t?!!t&&new Date>new Date(t):!1,P=(t,e)=>{const n=t.widget[e]||t.implementation[e]||t.tenant[e];return n==null?void 0:n.value},K=(t,e,n)=>n?{value:t,category:e,expiration:typeof n=="object"?b(n):n}:{value:t,category:e},O=(t,e)=>{const n=M(t);return Object.entries(n).forEach(([r,s])=>{Object.entries(s).forEach(([o,i])=>{const{expiration:a,category:c}=i;(X(a)||Y(e,c))&&(s[o]=K(void 0,c,a))})}),n},j=(t,e)=>z(t,"storagePolicy",d.Cookie).then((n=[l.Necessary])=>!!e&&n.indexOf(e)===-1),Y=(t=[l.Necessary],e)=>!!e&&t.indexOf(e)===-1,W=t=>{const e=_(t),n=k(t,window.localStorage),r=k(t,sessionStorage),s=P(e,"storagePolicy"),[o,i,a]=[e,n,r].map(c=>O(c,s));U(t,o),D(t,window.localStorage,i),D(t,window.sessionStorage,a)},b=(t={days:30})=>{const{days:e=0,hours:n=0,minutes:r=0,seconds:s=0}=t,o=new Date;return o.setTime(o.getTime()+n*60*60*1e3),o.setTime(o.getTime()+e*24*60*60*1e3),o.setTime(o.getTime()+r*60*1e3),o.setTime(o.getTime()+s*1e3),o.toISOString()},Z=t=>f(document)(()=>_(t)),ee=(t,e)=>f(document)(()=>U(t,e)),te=(t,e)=>{const n=e===d.Local?window.localStorage:window.sessionStorage;return f(n)(()=>k(t,n))},ne=(t,e,n)=>{const r=e===d.Local?window.localStorage:window.sessionStorage;return f(r)(()=>D(t,r,n))};class ${constructor(){this.memory={tenant:{},implementation:{},widget:{}}}async setItem(e,n,r={}){return f(this)(()=>{const s=O(this.memory,[l.Necessary]),{scope:o=S.Tenant,expiration:i}=r;s[o][e]=K(n,l.Necessary,(i==null?void 0:i.toISOString())||b()),this.memory=s,process.env.NODE_ENV!=="production"&&g.warn(`StorageProvider: StorageProvider is deprecated, use createStorageWriter and readStorage instead, value stored temporarily in memory.
9
- Key: ${e}
8
+ Options: ${JSON.stringify(r)}`);return}const{scope:g=p.Widget,medium:a=l.Session,duration:u}=r,m=T();return m[g][t]=J(o,n,u),a===l.Cookie?M(e,m):q(e,a,m)})))),b=(e,t,n=l.Session)=>(D(e),typeof t>"u"?(process.env.NODE_ENV!=="production"&&c.Logger.warn("readStorage: Undefined key passed when reading storage. ",t,n),Promise.resolve(void 0)):n===l.Cookie?j(e).then(r=>N(r,t)):U(e,n).then(r=>N(r,t))),y=e=>!!Object.entries(e).filter(([t,n])=>typeof n<"u").length,$=e=>Object.entries(e).filter(([t,n])=>typeof n<"u").forEach(([t,{value:n}])=>{typeof n>"u"&&delete e[t]}),_=(e,t)=>{const n={tenant:{...e.tenant,...t.tenant},implementation:{...e.implementation,...t.implementation},widget:{...e.widget,...t.widget}};return $(n.tenant),$(n.implementation),$(n.widget),n},x=e=>Object.entries(e).reduce((n,r)=>{const[s,o]=r;return Object.entries(o).forEach(i=>{const[g,{expiration:a}]=i;a&&n.push(a)}),n},[]).slice().sort((n,r)=>new Date(r).valueOf()-new Date(n).valueOf()).shift()||O(),h=e=>{const{name:t,implementation:{name:n,tenant:r}}=e.get("$widget");return[`humany_${r}`,`humany_${c.hash(r+n)}`,`humany_${c.hash(r+n+t)}`]},E=e=>{const t=new RegExp(`(?:^|;)\\s?${e}=(.*?)(?:;|$)`,"i"),n=document.cookie.match(t);return n&&n[1]&&JSON.parse(n[1])||void 0},A=(e,t,n)=>{const r=`${e}=${JSON.stringify(t).trim()}`,s=`expires=${new Date(n).toUTCString()}`,o="path=/",i="SameSite=None;Secure";return document.cookie=`${r}; ${s}; ${o}; ${i}`},P=e=>{const[t,n,r]=h(e),s=E(t)||{},o=E(n)||{},i=E(r)||{};return{tenant:s,implementation:o,widget:i}},I=(e,t)=>{const n=P(e),r=_(n,t),[s,o,i]=h(e),{tenant:g,implementation:a,widget:u}=r,m=x(t),v=O({days:-1});A(s,g,y(g)?m:v),A(o,a,y(a)?m:v),A(i,u,y(u)?m:v)},w=(e,t)=>{const[n,r,s]=h(e),o=t.getItem(n)||"{}",i=t.getItem(r)||"{}",g=t.getItem(s)||"{}";return{tenant:JSON.parse(o),implementation:JSON.parse(i),widget:JSON.parse(g)}},C=(e,t,n)=>{const r=w(e,t),s=_(r,n),[o,i,g]=h(e),{tenant:a,implementation:u,widget:m}=s;y(a)?t.setItem(o,JSON.stringify(a)):t.removeItem(o),y(u)?t.setItem(i,JSON.stringify(u)):t.removeItem(i),y(m)?t.setItem(g,JSON.stringify(m)):t.removeItem(g)},T=()=>({tenant:{},implementation:{},widget:{}}),V=e=>e?!!e&&new Date>new Date(e):!1,N=(e,t)=>{const n=e.widget[t]||e.implementation[t]||e.tenant[t];return n==null?void 0:n.value},J=(e,t,n)=>n?{value:e,category:t,expiration:typeof n=="object"?O(n):n}:{value:e,category:t},f=(e,t)=>{const n=c.deepClone(e);return Object.entries(n).forEach(([r,s])=>{Object.entries(s).forEach(([o,i])=>{const{expiration:g,category:a}=i;(V(g)||W(t,a))&&(s[o]=J(void 0,a,g))})}),n},k=(e,t)=>b(e,"storagePolicy",l.Cookie).then((n=[d.Necessary])=>!!t&&n.indexOf(t)===-1),W=(e=[d.Necessary],t)=>!!t&&e.indexOf(t)===-1,D=e=>{const t=P(e),n=w(e,window.localStorage),r=w(e,sessionStorage),s=N(t,"storagePolicy"),[o,i,g]=[t,n,r].map(a=>f(a,s));I(e,o),C(e,window.localStorage,i),C(e,window.sessionStorage,g)},O=(e={days:30})=>{const{days:t=0,hours:n=0,minutes:r=0,seconds:s=0}=e,o=new Date;return o.setTime(o.getTime()+n*60*60*1e3),o.setTime(o.getTime()+t*24*60*60*1e3),o.setTime(o.getTime()+r*60*1e3),o.setTime(o.getTime()+s*1e3),o.toISOString()},j=e=>c.lock(document)(()=>P(e)),M=(e,t)=>c.lock(document)(()=>I(e,t)),U=(e,t)=>{const n=t===l.Local?window.localStorage:window.sessionStorage;return c.lock(n)(()=>w(e,n))},q=(e,t,n)=>{const r=t===l.Local?window.localStorage:window.sessionStorage;return c.lock(r)(()=>C(e,r,n))};class S{constructor(){this.memory={tenant:{},implementation:{},widget:{}}}async setItem(t,n,r={}){return c.lock(this)(()=>{const s=f(this.memory,[d.Necessary]),{scope:o=p.Tenant,expiration:i}=r;s[o][t]=J(n,d.Necessary,(i==null?void 0:i.toISOString())||O()),this.memory=s,process.env.NODE_ENV!=="production"&&c.Logger.warn(`StorageProvider: StorageProvider is deprecated, use createStorageWriter and readStorage instead, value stored temporarily in memory.
9
+ Key: ${t}
10
10
  Value: ${JSON.stringify(n)}
11
11
  Options: ${JSON.stringify(r)}
12
- Memory: ${JSON.stringify(s)}`)})}async getItem(e){return f(this)(()=>{const n=O(this.memory,[l.Necessary]);process.env.NODE_ENV!=="production"&&g.warn(`StorageProvider: StorageProvider is deprecated, use createStorageWriter and readStorage instead, value fetched from legacy memory storage.
13
- Key: ${e}
14
- Memory: ${JSON.stringify(n)}`);const r=P(n,e);return this.memory=n,r})}async removeItem(e){return f(this)(()=>{const n=O(this.memory,[l.Necessary]);delete n.tenant[e],delete n.implementation[e],delete n.widget[e],this.memory=n,process.env.NODE_ENV!=="production"&&g.warn(`StorageProvider: StorageProvider is deprecated, use createStorageWriter and readStorage instead, value removed from memory.
15
- Key: ${e}
16
- Memory: ${JSON.stringify(n)}`)})}async clear(){return Promise.resolve()}}class re{constructor(){this.cookies=new $,this.session=new $,this.local=new $}}const J=(t,e,n,...r)=>{const s=`[${t.get("$environment").name||"webprovisions"}] ${n}`;switch(e){case"info":console.info(s,...r);break;case"warning":console.warn(s,...r);break;case"error":console.error(s,...r);break}},oe=t=>{const e=t.container||t;return{info:(n,...r)=>J(e,"info",n,...r),warn:(n,...r)=>J(e,"warning",n,...r),error:(n,...r)=>J(e,"error",n,...r)}};var A=(t=>(t.Implementation="implementation",t.Widget="widget",t))(A||{}),p=(t=>(t.Pre="pre",t.Post="post",t))(p||{});const se=(t,e,n,r)=>{try{const s=new e(n,r);return{name:t,invoke:(o,i)=>{let a;return s[o]&&(a=s[o].call(s,i)),Promise.resolve(a)},getInstance:()=>s}}catch(s){if(s.message&&s.message.indexOf("is not a constructor")>=0)return{name:t,invoke:o=>{let i;return o==="initialize"&&(i=e(n,r)),Promise.resolve(i)},getInstance:()=>e};throw s}};function L(t,e){return typeof t>"u"?e:t}class ie{constructor(e={}){this.part=e}createCommand(e,n,r){let s;typeof n=="function"?s={scope:A.Widget,stage:p.Post,defaultArgs:void 0,handlerResolver:n}:s={scope:L(n.scope,A.Widget),stage:L(n.stage,p.Post),defaultArgs:n.defaultArgs,handlerResolver:r};let o=this.part;const i=e.split(".");return i.forEach((a,c)=>{c===i.length-1?o[a]||(o[a]=()=>s):o=this.part[a]=this.part[a]||{}}),this}get(){return this.part}}const q=t=>{const e=new ie({});return t(e),e.get()};q(t=>{t.createCommand("types.register",{scope:A.Implementation,stage:p.Pre},e=>(n,r)=>{e.container.get("$types")[n]=r}).createCommand("type",{stage:p.Pre},e=>n=>{e.container.register("$type",n)}).createCommand("settings",{stage:p.Pre,defaultArgs:[null]},e=>n=>{e.events.dispatch("settings:change",n,{bubbles:!0}),e.container.register("$settings",n)}).createCommand("plugin",{stage:p.Pre},e=>(n,r,s)=>{const{container:o}=e;let i=null,a=n,c=r;typeof n=="string"&&(i=n,a=r,c=s);const u=m=>{const{transformPluginSettings:y}=e.container.get("$environmentOptions"),Q=y?y(c||{},i,e.container,a):r;try{const v=se(i,a,o,Q);o.get("$plugins").push(v),m&&v.invoke("initialize",null)}catch(v){oe(e).warn("Error when initializing plugin",v)}};e.container.get("$instance")?u(!0):e.events.subscribeOnce("widget:instance-created",()=>u(!1))}).createCommand("container.register",e=>(n,r)=>{e.container.register(n,r)}).createCommand("container.registerAsync",e=>(n,r)=>{e.container.registerAsync(n,r)}).createCommand("container.registerFactory",e=>(n,r)=>{e.container.registerFactory(n,r)}).createCommand("container.touch",e=>(n,r)=>{e.container.touch(n,r)}).createCommand("csp",{},e=>n=>{e.container.register("csp",n)})});const ae=q(t=>{t.createCommand("storage",e=>(n={})=>{const{consent:r}=n;if(typeof r<"u"){if(typeof r!="number"&&typeof r!="string"&&!Array.isArray(r)){process.env.NODE_ENV!=="production"&&g.warn(`storagePolicyConfigurationApi: passed consent is not valid. Consent either has to be a number, a string, an array of strings or an array of numbers.
17
- Passed consent: ${JSON.stringify(r)}`);return}if(Array.isArray(r)&&!r.every(o=>typeof o=="number"||typeof o=="string")){process.env.NODE_ENV!=="production"&&g.warn(`storagePolicyConfigurationApi: passed consent is not valid. Consent either has to be a number, a string, an array of strings or an array of numbers.
18
- Passed consent: ${JSON.stringify(r)}`);return}const s=[l.Necessary,l.Functional,l.Analytical,l.Marketing].filter((o,i,a)=>typeof r=="number"?r>i:typeof r=="string"?a.indexOf(r)+1>i:Array.isArray(r)?r.findIndex(c=>c===i+1||c===o)>-1:!0);return s.indexOf(l.Necessary)===-1&&(process.env.NODE_ENV!=="production"&&g.warn(`storagePolicyConfigurationApi: passed consent does not include category: '${l.Necessary}'. Consent has to atleast include the '${l.Necessary}' category.
19
- Passed consent: ${JSON.stringify(r)}`),s.unshift(l.Necessary)),F(e.container,"storagePolicy",l.Necessary,{medium:d.Cookie,scope:S.Tenant,duration:{days:365}}).then(o=>o(s)).then(()=>{W(e.container),e.events.dispatch("storage:policy-changed",s)})}})});exports.StorageCategory=l;exports.StorageMedium=d;exports.StorageProvider=re;exports.StorageScope=S;exports.StorageService=$;exports.createStorageWriter=F;exports.readStorage=z;exports.storagePolicyConfigurationApi=ae;
12
+ Memory: ${JSON.stringify(s)}`)})}async getItem(t){return c.lock(this)(()=>{const n=f(this.memory,[d.Necessary]);process.env.NODE_ENV!=="production"&&c.Logger.warn(`StorageProvider: StorageProvider is deprecated, use createStorageWriter and readStorage instead, value fetched from legacy memory storage.
13
+ Key: ${t}
14
+ Memory: ${JSON.stringify(n)}`);const r=N(n,t);return this.memory=n,r})}async removeItem(t){return c.lock(this)(()=>{const n=f(this.memory,[d.Necessary]);delete n.tenant[t],delete n.implementation[t],delete n.widget[t],this.memory=n,process.env.NODE_ENV!=="production"&&c.Logger.warn(`StorageProvider: StorageProvider is deprecated, use createStorageWriter and readStorage instead, value removed from memory.
15
+ Key: ${t}
16
+ Memory: ${JSON.stringify(n)}`)})}async clear(){return Promise.resolve()}}class F{constructor(){this.cookies=new S,this.session=new S,this.local=new S}}const R=L.createConfigurationApi(e=>{e.createCommand("storage",t=>(n={})=>{const{consent:r}=n;if(typeof r<"u"){if(typeof r!="number"&&typeof r!="string"&&!Array.isArray(r)){process.env.NODE_ENV!=="production"&&c.Logger.warn(`storagePolicyConfigurationApi: passed consent is not valid. Consent either has to be a number, a string, an array of strings or an array of numbers.
17
+ Passed consent: ${JSON.stringify(r)}`);return}if(Array.isArray(r)&&!r.every(o=>typeof o=="number"||typeof o=="string")){process.env.NODE_ENV!=="production"&&c.Logger.warn(`storagePolicyConfigurationApi: passed consent is not valid. Consent either has to be a number, a string, an array of strings or an array of numbers.
18
+ Passed consent: ${JSON.stringify(r)}`);return}const s=[d.Necessary,d.Functional,d.Analytical,d.Marketing].filter((o,i,g)=>typeof r=="number"?r>i:typeof r=="string"?g.indexOf(r)+1>i:Array.isArray(r)?r.findIndex(a=>a===i+1||a===o)>-1:!0);return s.indexOf(d.Necessary)===-1&&(process.env.NODE_ENV!=="production"&&c.Logger.warn(`storagePolicyConfigurationApi: passed consent does not include category: '${d.Necessary}'. Consent has to atleast include the '${d.Necessary}' category.
19
+ Passed consent: ${JSON.stringify(r)}`),s.unshift(d.Necessary)),K(t.container,"storagePolicy",d.Necessary,{medium:l.Cookie,scope:p.Tenant,duration:{days:365}}).then(o=>o(s)).then(()=>{D(t.container),t.events.dispatch("storage:policy-changed",s)})}})});exports.StorageCategory=d;exports.StorageMedium=l;exports.StorageProvider=F;exports.StorageScope=p;exports.StorageService=S;exports.createStorageWriter=K;exports.readStorage=b;exports.storagePolicyConfigurationApi=R;
package/index.mjs CHANGED
@@ -1,85 +1,16 @@
1
- const P = (t, e, ...n) => typeof e == "string" ? t(`[humany] ${e}`, ...n) : t(e, ...n), w = class {
2
- constructor() {
3
- this.keys = [], this.log = (t, ...e) => this.lookup(t, () => w.log(...e)), this.warn = (t, ...e) => this.lookup(t, () => w.warn(...e)), this.error = (t, ...e) => this.lookup(t, () => w.error(...e)), this.info = (t, ...e) => this.lookup(t, () => w.info(...e));
4
- }
5
- lookup(t, e) {
6
- this.keys.indexOf(t) === -1 && (this.keys.push(t), e());
7
- }
8
- };
9
- let m = w;
10
- m.log = (...t) => P(console.log, ...t);
11
- m.warn = (...t) => P(console.warn, ...t);
12
- m.error = (...t) => P(console.error, ...t);
13
- m.info = (...t) => P(console.info, ...t);
14
- const F = (t) => {
15
- let e = {}, n, r;
16
- if (typeof t != "object" || t === null)
17
- return t;
18
- e = Array.isArray(t) ? [] : {};
19
- for (r in t)
20
- n = t[r], e[r] = typeof n == "object" && n !== null ? F(n) : n;
21
- return e;
22
- };
23
- function V(t) {
24
- let e = 0;
25
- if (t.length === 0)
26
- return e.toString();
27
- for (let n = 0; n < t.length; n++) {
28
- const r = t.charCodeAt(n);
29
- e = (e << 5) - e + r, e = e & e;
30
- }
31
- return e.toString();
32
- }
33
- class q {
34
- constructor(e, n) {
35
- this.lockWarningTime = e, this.lockErrorTime = n, this.tasks = [], this.current = Promise.resolve(), this.next = this.next.bind(this);
36
- }
37
- add(e, n, r, s) {
38
- this.tasks.push({ task: e, resolve: n, reject: r, done: s }), this.next();
39
- }
40
- next() {
41
- this.current = this.current.then(() => {
42
- const e = this.tasks.shift();
43
- if (e) {
44
- let n;
45
- const r = setTimeout(() => {
46
- process.env.NODE_ENV !== "production" && m.warn(
47
- `A lock has exceeded ${this.lockWarningTime} ms. Waiting additional ${this.lockErrorTime} ms before rejecting the task.`,
48
- e
49
- ), n = setTimeout(() => {
50
- e.reject("lock timeout exceeded");
51
- }, this.lockErrorTime);
52
- }, this.lockWarningTime), s = Promise.resolve(e.task()).then((o) => (clearTimeout(r), clearTimeout(n), o));
53
- return Promise.resolve(s).then(this.next).then(
54
- () => s.then((o) => {
55
- e.done(), e.resolve(o);
56
- })
57
- ).catch((o) => (e.done(), e.reject(o), this.next()));
58
- }
59
- return Promise.resolve();
60
- });
61
- }
62
- }
63
- const v = /* @__PURE__ */ new WeakMap();
64
- function f(t, e = 5e3, n = 1e3) {
65
- return v.has(t) || v.set(t, new q(e, n)), (r) => new Promise((s, o) => {
66
- const i = v.get(t);
67
- i.add(r, s, o, () => {
68
- i.tasks.length || v.delete(t);
69
- });
70
- });
71
- }
72
- var d = /* @__PURE__ */ ((t) => (t.Cookie = "cookie", t.Local = "local", t.Session = "session", t))(d || {}), A = /* @__PURE__ */ ((t) => (t.Tenant = "tenant", t.Implementation = "implementation", t.Widget = "widget", t))(A || {}), l = /* @__PURE__ */ ((t) => (t.Necessary = "necessary", t.Functional = "functional", t.Analytical = "analytical", t.Marketing = "marketing", t))(l || {});
73
- const Q = (t, e, n, r = {}) => j(t, n).then((s) => (process.env.NODE_ENV !== "production" && s && m.warn(
1
+ import { Logger as g, lock as y, deepClone as k, hash as _ } from "@telia-ace/widget-utilities";
2
+ import { createConfigurationApi as T } from "@webprovisions/platform";
3
+ var l = /* @__PURE__ */ ((e) => (e.Cookie = "cookie", e.Local = "local", e.Session = "session", e))(l || {}), N = /* @__PURE__ */ ((e) => (e.Tenant = "tenant", e.Implementation = "implementation", e.Widget = "widget", e))(N || {}), d = /* @__PURE__ */ ((e) => (e.Necessary = "necessary", e.Functional = "functional", e.Analytical = "analytical", e.Marketing = "marketing", e))(d || {});
4
+ const V = (e, t, n, r = {}) => I(e, n).then((s) => (process.env.NODE_ENV !== "production" && s && g.warn(
74
5
  `createStorageWriter: Attempted to create storage writer using unallowed category.
75
- Key: ${e}
6
+ Key: ${t}
76
7
  Category: ${JSON.stringify(n)}
77
8
  Options: ${JSON.stringify(r)}`
78
- ), (o) => (W(t), j(t, n).then((i) => {
9
+ ), (o) => (K(e), I(e, n).then((i) => {
79
10
  if (i) {
80
- process.env.NODE_ENV !== "production" && m.warn(
11
+ process.env.NODE_ENV !== "production" && g.warn(
81
12
  `storageWriter: Attempted to write to storage using unallowed category.
82
- Key: ${e}
13
+ Key: ${t}
83
14
  Category: ${JSON.stringify(n)}
84
15
  Value: ${JSON.stringify(o)}
85
16
  Options: ${JSON.stringify(r)}`
@@ -87,104 +18,104 @@ const Q = (t, e, n, r = {}) => j(t, n).then((s) => (process.env.NODE_ENV !== "pr
87
18
  return;
88
19
  }
89
20
  const {
90
- scope: a = A.Widget,
91
- medium: c = d.Session,
21
+ scope: c = N.Widget,
22
+ medium: a = l.Session,
92
23
  duration: u
93
- } = r, g = H();
94
- return g[a][e] = K(o, n, u), c === d.Cookie ? ee(t, g) : ne(t, c, g);
95
- })))), B = (t, e, n = d.Session) => (W(t), typeof e > "u" ? (process.env.NODE_ENV !== "production" && m.warn("readStorage: Undefined key passed when reading storage. ", e, n), Promise.resolve(void 0)) : n === d.Cookie ? Z(t).then((r) => $(r, e)) : te(t, n).then((r) => $(r, e))), h = (t) => !!Object.entries(t).filter(([e, n]) => typeof n < "u").length, b = (t) => Object.entries(t).filter(([e, n]) => typeof n < "u").forEach(([e, { value: n }]) => {
96
- typeof n > "u" && delete t[e];
97
- }), M = (t, e) => {
24
+ } = r, m = j();
25
+ return m[c][t] = D(o, n, u), a === l.Cookie ? R(e, m) : z(e, a, m);
26
+ })))), L = (e, t, n = l.Session) => (K(e), typeof t > "u" ? (process.env.NODE_ENV !== "production" && g.warn("readStorage: Undefined key passed when reading storage. ", t, n), Promise.resolve(void 0)) : n === l.Cookie ? F(e).then((r) => w(r, t)) : q(e, n).then((r) => w(r, t))), p = (e) => !!Object.entries(e).filter(([t, n]) => typeof n < "u").length, $ = (e) => Object.entries(e).filter(([t, n]) => typeof n < "u").forEach(([t, { value: n }]) => {
27
+ typeof n > "u" && delete e[t];
28
+ }), b = (e, t) => {
98
29
  const n = {
99
- tenant: { ...t.tenant, ...e.tenant },
100
- implementation: { ...t.implementation, ...e.implementation },
101
- widget: { ...t.widget, ...e.widget }
30
+ tenant: { ...e.tenant, ...t.tenant },
31
+ implementation: { ...e.implementation, ...t.implementation },
32
+ widget: { ...e.widget, ...t.widget }
102
33
  };
103
- return b(n.tenant), b(n.implementation), b(n.widget), n;
104
- }, G = (t) => Object.entries(t).reduce((n, r) => {
34
+ return $(n.tenant), $(n.implementation), $(n.widget), n;
35
+ }, W = (e) => Object.entries(e).reduce((n, r) => {
105
36
  const [s, o] = r;
106
37
  return Object.entries(o).forEach((i) => {
107
- const [a, { expiration: c }] = i;
108
- c && n.push(c);
38
+ const [c, { expiration: a }] = i;
39
+ a && n.push(a);
109
40
  }), n;
110
- }, []).slice().sort((n, r) => new Date(r).valueOf() - new Date(n).valueOf()).shift() || C(), E = (t) => {
41
+ }, []).slice().sort((n, r) => new Date(r).valueOf() - new Date(n).valueOf()).shift() || O(), h = (e) => {
111
42
  const {
112
- name: e,
43
+ name: t,
113
44
  implementation: { name: n, tenant: r }
114
- } = t.get("$widget");
45
+ } = e.get("$widget");
115
46
  return [
116
47
  `humany_${r}`,
117
- `humany_${V(r + n)}`,
118
- `humany_${V(r + n + e)}`
48
+ `humany_${_(r + n)}`,
49
+ `humany_${_(r + n + t)}`
119
50
  ];
120
- }, x = (t) => {
121
- const e = new RegExp(`(?:^|;)\\s?${t}=(.*?)(?:;|$)`, "i"), n = document.cookie.match(e);
51
+ }, E = (e) => {
52
+ const t = new RegExp(`(?:^|;)\\s?${e}=(.*?)(?:;|$)`, "i"), n = document.cookie.match(t);
122
53
  return n && n[1] && JSON.parse(n[1]) || void 0;
123
- }, T = (t, e, n) => {
124
- const r = `${t}=${JSON.stringify(e).trim()}`, s = `expires=${new Date(n).toUTCString()}`, o = "path=/", i = "SameSite=None;Secure";
54
+ }, A = (e, t, n) => {
55
+ const r = `${e}=${JSON.stringify(t).trim()}`, s = `expires=${new Date(n).toUTCString()}`, o = "path=/", i = "SameSite=None;Secure";
125
56
  return document.cookie = `${r}; ${s}; ${o}; ${i}`;
126
- }, _ = (t) => {
127
- const [e, n, r] = E(t), s = x(e) || {}, o = x(n) || {}, i = x(r) || {};
57
+ }, P = (e) => {
58
+ const [t, n, r] = h(e), s = E(t) || {}, o = E(n) || {}, i = E(r) || {};
128
59
  return {
129
60
  tenant: s,
130
61
  implementation: o,
131
62
  widget: i
132
63
  };
133
- }, z = (t, e) => {
134
- const n = _(t), r = M(n, e), [s, o, i] = E(t), { tenant: a, implementation: c, widget: u } = r, g = G(e), y = C({ days: -1 });
135
- T(s, a, h(a) ? g : y), T(
64
+ }, x = (e, t) => {
65
+ const n = P(e), r = b(n, t), [s, o, i] = h(e), { tenant: c, implementation: a, widget: u } = r, m = W(t), v = O({ days: -1 });
66
+ A(s, c, p(c) ? m : v), A(
136
67
  o,
137
- c,
138
- h(c) ? g : y
139
- ), T(i, u, h(u) ? g : y);
140
- }, O = (t, e) => {
141
- const [n, r, s] = E(t), o = e.getItem(n) || "{}", i = e.getItem(r) || "{}", a = e.getItem(s) || "{}";
68
+ a,
69
+ p(a) ? m : v
70
+ ), A(i, u, p(u) ? m : v);
71
+ }, S = (e, t) => {
72
+ const [n, r, s] = h(e), o = t.getItem(n) || "{}", i = t.getItem(r) || "{}", c = t.getItem(s) || "{}";
142
73
  return {
143
74
  tenant: JSON.parse(o),
144
75
  implementation: JSON.parse(i),
145
- widget: JSON.parse(a)
76
+ widget: JSON.parse(c)
146
77
  };
147
- }, D = (t, e, n) => {
148
- const r = O(t, e), s = M(r, n), [o, i, a] = E(t), { tenant: c, implementation: u, widget: g } = s;
149
- h(c) ? e.setItem(o, JSON.stringify(c)) : e.removeItem(o), h(u) ? e.setItem(i, JSON.stringify(u)) : e.removeItem(i), h(g) ? e.setItem(a, JSON.stringify(g)) : e.removeItem(a);
150
- }, H = () => ({ tenant: {}, implementation: {}, widget: {} }), X = (t) => t ? !!t && /* @__PURE__ */ new Date() > new Date(t) : !1, $ = (t, e) => {
151
- const n = t.widget[e] || t.implementation[e] || t.tenant[e];
78
+ }, J = (e, t, n) => {
79
+ const r = S(e, t), s = b(r, n), [o, i, c] = h(e), { tenant: a, implementation: u, widget: m } = s;
80
+ p(a) ? t.setItem(o, JSON.stringify(a)) : t.removeItem(o), p(u) ? t.setItem(i, JSON.stringify(u)) : t.removeItem(i), p(m) ? t.setItem(c, JSON.stringify(m)) : t.removeItem(c);
81
+ }, j = () => ({ tenant: {}, implementation: {}, widget: {} }), M = (e) => e ? !!e && /* @__PURE__ */ new Date() > new Date(e) : !1, w = (e, t) => {
82
+ const n = e.widget[t] || e.implementation[t] || e.tenant[t];
152
83
  return n == null ? void 0 : n.value;
153
- }, K = (t, e, n) => n ? {
154
- value: t,
155
- category: e,
156
- expiration: typeof n == "object" ? C(n) : n
84
+ }, D = (e, t, n) => n ? {
85
+ value: e,
86
+ category: t,
87
+ expiration: typeof n == "object" ? O(n) : n
157
88
  } : {
158
- value: t,
159
- category: e
160
- }, N = (t, e) => {
161
- const n = F(t);
89
+ value: e,
90
+ category: t
91
+ }, f = (e, t) => {
92
+ const n = k(e);
162
93
  return Object.entries(n).forEach(([r, s]) => {
163
94
  Object.entries(s).forEach(([o, i]) => {
164
- const { expiration: a, category: c } = i;
165
- (X(a) || Y(e, c)) && (s[o] = K(void 0, c, a));
95
+ const { expiration: c, category: a } = i;
96
+ (M(c) || U(t, a)) && (s[o] = D(void 0, a, c));
166
97
  });
167
98
  }), n;
168
- }, j = (t, e) => B(t, "storagePolicy", d.Cookie).then(
169
- (n = [l.Necessary]) => !!e && n.indexOf(e) === -1
170
- ), Y = (t = [l.Necessary], e) => !!e && t.indexOf(e) === -1, W = (t) => {
171
- const e = _(t), n = O(t, window.localStorage), r = O(t, sessionStorage), s = $(e, "storagePolicy"), [o, i, a] = [
172
- e,
99
+ }, I = (e, t) => L(e, "storagePolicy", l.Cookie).then(
100
+ (n = [d.Necessary]) => !!t && n.indexOf(t) === -1
101
+ ), U = (e = [d.Necessary], t) => !!t && e.indexOf(t) === -1, K = (e) => {
102
+ const t = P(e), n = S(e, window.localStorage), r = S(e, sessionStorage), s = w(t, "storagePolicy"), [o, i, c] = [
103
+ t,
173
104
  n,
174
105
  r
175
- ].map((c) => N(c, s));
176
- z(t, o), D(t, window.localStorage, i), D(t, window.sessionStorage, a);
177
- }, C = (t = { days: 30 }) => {
178
- const { days: e = 0, hours: n = 0, minutes: r = 0, seconds: s = 0 } = t, o = /* @__PURE__ */ new Date();
179
- return o.setTime(o.getTime() + n * 60 * 60 * 1e3), o.setTime(o.getTime() + e * 24 * 60 * 60 * 1e3), o.setTime(o.getTime() + r * 60 * 1e3), o.setTime(o.getTime() + s * 1e3), o.toISOString();
180
- }, Z = (t) => f(document)(() => _(t)), ee = (t, e) => f(document)(() => z(t, e)), te = (t, e) => {
181
- const n = e === d.Local ? window.localStorage : window.sessionStorage;
182
- return f(n)(() => O(t, n));
183
- }, ne = (t, e, n) => {
184
- const r = e === d.Local ? window.localStorage : window.sessionStorage;
185
- return f(r)(() => D(t, r, n));
106
+ ].map((a) => f(a, s));
107
+ x(e, o), J(e, window.localStorage, i), J(e, window.sessionStorage, c);
108
+ }, O = (e = { days: 30 }) => {
109
+ const { days: t = 0, hours: n = 0, minutes: r = 0, seconds: s = 0 } = e, o = /* @__PURE__ */ new Date();
110
+ return o.setTime(o.getTime() + n * 60 * 60 * 1e3), o.setTime(o.getTime() + t * 24 * 60 * 60 * 1e3), o.setTime(o.getTime() + r * 60 * 1e3), o.setTime(o.getTime() + s * 1e3), o.toISOString();
111
+ }, F = (e) => y(document)(() => P(e)), R = (e, t) => y(document)(() => x(e, t)), q = (e, t) => {
112
+ const n = t === l.Local ? window.localStorage : window.sessionStorage;
113
+ return y(n)(() => S(e, n));
114
+ }, z = (e, t, n) => {
115
+ const r = t === l.Local ? window.localStorage : window.sessionStorage;
116
+ return y(r)(() => J(e, r, n));
186
117
  };
187
- class I {
118
+ class C {
188
119
  constructor() {
189
120
  this.memory = {
190
121
  tenant: {},
@@ -192,40 +123,40 @@ class I {
192
123
  widget: {}
193
124
  };
194
125
  }
195
- async setItem(e, n, r = {}) {
196
- return f(this)(() => {
197
- const s = N(this.memory, [l.Necessary]), { scope: o = A.Tenant, expiration: i } = r;
198
- s[o][e] = K(
126
+ async setItem(t, n, r = {}) {
127
+ return y(this)(() => {
128
+ const s = f(this.memory, [d.Necessary]), { scope: o = N.Tenant, expiration: i } = r;
129
+ s[o][t] = D(
199
130
  n,
200
- l.Necessary,
201
- (i == null ? void 0 : i.toISOString()) || C()
202
- ), this.memory = s, process.env.NODE_ENV !== "production" && m.warn(
131
+ d.Necessary,
132
+ (i == null ? void 0 : i.toISOString()) || O()
133
+ ), this.memory = s, process.env.NODE_ENV !== "production" && g.warn(
203
134
  `StorageProvider: StorageProvider is deprecated, use createStorageWriter and readStorage instead, value stored temporarily in memory.
204
- Key: ${e}
135
+ Key: ${t}
205
136
  Value: ${JSON.stringify(n)}
206
137
  Options: ${JSON.stringify(r)}
207
138
  Memory: ${JSON.stringify(s)}`
208
139
  );
209
140
  });
210
141
  }
211
- async getItem(e) {
212
- return f(this)(() => {
213
- const n = N(this.memory, [l.Necessary]);
214
- process.env.NODE_ENV !== "production" && m.warn(
142
+ async getItem(t) {
143
+ return y(this)(() => {
144
+ const n = f(this.memory, [d.Necessary]);
145
+ process.env.NODE_ENV !== "production" && g.warn(
215
146
  `StorageProvider: StorageProvider is deprecated, use createStorageWriter and readStorage instead, value fetched from legacy memory storage.
216
- Key: ${e}
147
+ Key: ${t}
217
148
  Memory: ${JSON.stringify(n)}`
218
149
  );
219
- const r = $(n, e);
150
+ const r = w(n, t);
220
151
  return this.memory = n, r;
221
152
  });
222
153
  }
223
- async removeItem(e) {
224
- return f(this)(() => {
225
- const n = N(this.memory, [l.Necessary]);
226
- delete n.tenant[e], delete n.implementation[e], delete n.widget[e], this.memory = n, process.env.NODE_ENV !== "production" && m.warn(
154
+ async removeItem(t) {
155
+ return y(this)(() => {
156
+ const n = f(this.memory, [d.Necessary]);
157
+ delete n.tenant[t], delete n.implementation[t], delete n.widget[t], this.memory = n, process.env.NODE_ENV !== "production" && g.warn(
227
158
  `StorageProvider: StorageProvider is deprecated, use createStorageWriter and readStorage instead, value removed from memory.
228
- Key: ${e}
159
+ Key: ${t}
229
160
  Memory: ${JSON.stringify(n)}`
230
161
  );
231
162
  });
@@ -234,176 +165,17 @@ class I {
234
165
  return Promise.resolve();
235
166
  }
236
167
  }
237
- class ie {
168
+ class H {
238
169
  constructor() {
239
- this.cookies = new I(), this.session = new I(), this.local = new I();
240
- }
241
- }
242
- const J = (t, e, n, ...r) => {
243
- const s = `[${t.get("$environment").name || "webprovisions"}] ${n}`;
244
- switch (e) {
245
- case "info":
246
- console.info(s, ...r);
247
- break;
248
- case "warning":
249
- console.warn(s, ...r);
250
- break;
251
- case "error":
252
- console.error(s, ...r);
253
- break;
254
- }
255
- }, re = (t) => {
256
- const e = t.container || t;
257
- return {
258
- info: (n, ...r) => J(e, "info", n, ...r),
259
- warn: (n, ...r) => J(e, "warning", n, ...r),
260
- error: (n, ...r) => J(e, "error", n, ...r)
261
- };
262
- };
263
- var k = /* @__PURE__ */ ((t) => (t.Implementation = "implementation", t.Widget = "widget", t))(k || {}), p = /* @__PURE__ */ ((t) => (t.Pre = "pre", t.Post = "post", t))(p || {});
264
- const oe = (t, e, n, r) => {
265
- try {
266
- const s = new e(n, r);
267
- return {
268
- name: t,
269
- invoke: (o, i) => {
270
- let a;
271
- return s[o] && (a = s[o].call(s, i)), Promise.resolve(a);
272
- },
273
- getInstance: () => s
274
- };
275
- } catch (s) {
276
- if (s.message && s.message.indexOf("is not a constructor") >= 0)
277
- return {
278
- name: t,
279
- invoke: (o) => {
280
- let i;
281
- return o === "initialize" && (i = e(n, r)), Promise.resolve(i);
282
- },
283
- getInstance: () => e
284
- };
285
- throw s;
170
+ this.cookies = new C(), this.session = new C(), this.local = new C();
286
171
  }
287
- };
288
- function L(t, e) {
289
- return typeof t > "u" ? e : t;
290
172
  }
291
- class se {
292
- constructor(e = {}) {
293
- this.part = e;
294
- }
295
- createCommand(e, n, r) {
296
- let s;
297
- typeof n == "function" ? s = {
298
- scope: k.Widget,
299
- stage: p.Post,
300
- defaultArgs: void 0,
301
- handlerResolver: n
302
- } : s = {
303
- scope: L(n.scope, k.Widget),
304
- stage: L(n.stage, p.Post),
305
- defaultArgs: n.defaultArgs,
306
- handlerResolver: r
307
- };
308
- let o = this.part;
309
- const i = e.split(".");
310
- return i.forEach((a, c) => {
311
- c === i.length - 1 ? o[a] || (o[a] = () => s) : o = this.part[a] = this.part[a] || {};
312
- }), this;
313
- }
314
- get() {
315
- return this.part;
316
- }
317
- }
318
- const R = (t) => {
319
- const e = new se({});
320
- return t(e), e.get();
321
- };
322
- R((t) => {
323
- t.createCommand(
324
- "types.register",
325
- { scope: k.Implementation, stage: p.Pre },
326
- (e) => (n, r) => {
327
- e.container.get("$types")[n] = r;
328
- }
329
- ).createCommand(
330
- "type",
331
- { stage: p.Pre },
332
- (e) => (n) => {
333
- e.container.register("$type", n);
334
- }
335
- ).createCommand(
336
- "settings",
337
- { stage: p.Pre, defaultArgs: [null] },
338
- (e) => (n) => {
339
- e.events.dispatch(
340
- "settings:change",
341
- n,
342
- { bubbles: !0 }
343
- ), e.container.register("$settings", n);
344
- }
345
- ).createCommand(
346
- "plugin",
347
- { stage: p.Pre },
348
- (e) => (n, r, s) => {
349
- const { container: o } = e;
350
- let i = null, a = n, c = r;
351
- typeof n == "string" && (i = n, a = r, c = s);
352
- const u = (g) => {
353
- const { transformPluginSettings: y } = e.container.get("$environmentOptions"), U = y ? y(
354
- c || {},
355
- i,
356
- e.container,
357
- a
358
- ) : r;
359
- try {
360
- const S = oe(
361
- i,
362
- a,
363
- o,
364
- U
365
- );
366
- o.get("$plugins").push(S), g && S.invoke("initialize", null);
367
- } catch (S) {
368
- re(e).warn("Error when initializing plugin", S);
369
- }
370
- };
371
- e.container.get("$instance") ? u(!0) : e.events.subscribeOnce("widget:instance-created", () => u(!1));
372
- }
373
- ).createCommand(
374
- "container.register",
375
- (e) => (n, r) => {
376
- e.container.register(n, r);
377
- }
378
- ).createCommand(
379
- "container.registerAsync",
380
- (e) => (n, r) => {
381
- e.container.registerAsync(n, r);
382
- }
383
- ).createCommand(
384
- "container.registerFactory",
385
- (e) => (n, r) => {
386
- e.container.registerFactory(n, r);
387
- }
388
- ).createCommand(
389
- "container.touch",
390
- (e) => (n, r) => {
391
- e.container.touch(n, r);
392
- }
393
- ).createCommand(
394
- "csp",
395
- {},
396
- (e) => (n) => {
397
- e.container.register("csp", n);
398
- }
399
- );
400
- });
401
- const ae = R((t) => {
402
- t.createCommand("storage", (e) => (n = {}) => {
173
+ const Q = T((e) => {
174
+ e.createCommand("storage", (t) => (n = {}) => {
403
175
  const { consent: r } = n;
404
176
  if (typeof r < "u") {
405
177
  if (typeof r != "number" && typeof r != "string" && !Array.isArray(r)) {
406
- process.env.NODE_ENV !== "production" && m.warn(
178
+ process.env.NODE_ENV !== "production" && g.warn(
407
179
  `storagePolicyConfigurationApi: passed consent is not valid. Consent either has to be a number, a string, an array of strings or an array of numbers.
408
180
  Passed consent: ${JSON.stringify(r)}`
409
181
  );
@@ -412,43 +184,43 @@ const ae = R((t) => {
412
184
  if (Array.isArray(r) && !r.every(
413
185
  (o) => typeof o == "number" || typeof o == "string"
414
186
  )) {
415
- process.env.NODE_ENV !== "production" && m.warn(
187
+ process.env.NODE_ENV !== "production" && g.warn(
416
188
  `storagePolicyConfigurationApi: passed consent is not valid. Consent either has to be a number, a string, an array of strings or an array of numbers.
417
189
  Passed consent: ${JSON.stringify(r)}`
418
190
  );
419
191
  return;
420
192
  }
421
193
  const s = [
422
- l.Necessary,
423
- l.Functional,
424
- l.Analytical,
425
- l.Marketing
426
- ].filter((o, i, a) => typeof r == "number" ? r > i : typeof r == "string" ? a.indexOf(r) + 1 > i : Array.isArray(r) ? r.findIndex((c) => c === i + 1 || c === o) > -1 : !0);
427
- return s.indexOf(l.Necessary) === -1 && (process.env.NODE_ENV !== "production" && m.warn(
428
- `storagePolicyConfigurationApi: passed consent does not include category: '${l.Necessary}'. Consent has to atleast include the '${l.Necessary}' category.
194
+ d.Necessary,
195
+ d.Functional,
196
+ d.Analytical,
197
+ d.Marketing
198
+ ].filter((o, i, c) => typeof r == "number" ? r > i : typeof r == "string" ? c.indexOf(r) + 1 > i : Array.isArray(r) ? r.findIndex((a) => a === i + 1 || a === o) > -1 : !0);
199
+ return s.indexOf(d.Necessary) === -1 && (process.env.NODE_ENV !== "production" && g.warn(
200
+ `storagePolicyConfigurationApi: passed consent does not include category: '${d.Necessary}'. Consent has to atleast include the '${d.Necessary}' category.
429
201
  Passed consent: ${JSON.stringify(r)}`
430
- ), s.unshift(l.Necessary)), Q(
431
- e.container,
202
+ ), s.unshift(d.Necessary)), V(
203
+ t.container,
432
204
  "storagePolicy",
433
- l.Necessary,
205
+ d.Necessary,
434
206
  {
435
- medium: d.Cookie,
436
- scope: A.Tenant,
207
+ medium: l.Cookie,
208
+ scope: N.Tenant,
437
209
  duration: { days: 365 }
438
210
  }
439
211
  ).then((o) => o(s)).then(() => {
440
- W(e.container), e.events.dispatch("storage:policy-changed", s);
212
+ K(t.container), t.events.dispatch("storage:policy-changed", s);
441
213
  });
442
214
  }
443
215
  });
444
216
  });
445
217
  export {
446
- l as StorageCategory,
447
- d as StorageMedium,
448
- ie as StorageProvider,
449
- A as StorageScope,
450
- I as StorageService,
451
- Q as createStorageWriter,
452
- B as readStorage,
453
- ae as storagePolicyConfigurationApi
218
+ d as StorageCategory,
219
+ l as StorageMedium,
220
+ H as StorageProvider,
221
+ N as StorageScope,
222
+ C as StorageService,
223
+ V as createStorageWriter,
224
+ L as readStorage,
225
+ Q as storagePolicyConfigurationApi
454
226
  };
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@telia-ace/widget-services",
3
- "version": "1.1.1-rc.1",
3
+ "version": "1.1.1-rc.3",
4
4
  "dependencies": {
5
- "@telia-ace/widget-utilities": "^1.1.1-rc.1",
5
+ "@telia-ace/widget-utilities": "^1.1.1-rc.3",
6
6
  "@webprovisions/platform": "^1.1.4"
7
7
  },
8
8
  "main": "./index.js",