@telia-ace/widget-services 1.3.8 → 1.3.10-rc.0

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 +11 -11
  2. package/index.mjs +30 -28
  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 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.
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||{}),f=(e=>(e.Tenant="tenant",e.Implementation="implementation",e.Widget="widget",e))(f||{}),d=(e=>(e.Necessary="necessary",e.Functional="functional",e.Analytical="analytical",e.Marketing="marketing",e))(d||{});const K=(e,t,n,o={})=>k(e,n).then(s=>(process.env.NODE_ENV!=="production"&&s&&c.Logger.warn(`createStorageWriter: Attempted to create storage writer using unallowed category.
2
2
  Key: ${t}
3
3
  Category: ${JSON.stringify(n)}
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.
4
+ Options: ${JSON.stringify(o)}`),r=>(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
5
  Key: ${t}
6
6
  Category: ${JSON.stringify(n)}
7
- Value: ${JSON.stringify(o)}
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.
7
+ Value: ${JSON.stringify(r)}
8
+ Options: ${JSON.stringify(o)}`);return}const{scope:g=f.Widget,medium:a=l.Session,duration:u}=o,m=T();return m[g][t]=J(r,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(o=>h(o,t)):U(e,n).then(o=>h(o,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,o)=>{const[s,r]=o;return Object.entries(r).forEach(i=>{const[g,{expiration:a}]=i;a&&n.push(a)}),n},[]).slice().sort((n,o)=>new Date(o).valueOf()-new Date(n).valueOf()).shift()||v(),O=e=>{const{name:t,implementation:{name:n,tenant:o}}=e.get("$widget");return[`humany_${o}`,`humany_${c.hash(o+n)}`,`humany_${c.hash(o+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 o=`${e}=${JSON.stringify(t).trim()}`,s=`expires=${new Date(n).toUTCString()}`,r="path=/",i="SameSite=None;Secure";return document.cookie=`${o}; ${s}; ${r}; ${i}`},P=e=>{const[t,n,o]=O(e),s=E(t)||{},r=E(n)||{},i=E(o)||{};return{tenant:s,implementation:r,widget:i}},I=(e,t)=>{const n=P(e),o=_(n,t),[s,r,i]=O(e),{tenant:g,implementation:a,widget:u}=o,m=x(t),p=v({days:-1});A(s,g,y(g)?m:p),A(r,a,y(a)?m:p),A(i,u,y(u)?m:p)},N=(e,t)=>{const[n,o,s]=O(e),r=t.getItem(n)||"{}",i=t.getItem(o)||"{}",g=t.getItem(s)||"{}";return{tenant:JSON.parse(r),implementation:JSON.parse(i),widget:JSON.parse(g)}},C=(e,t,n)=>{const o=N(e,t),s=_(o,n),[r,i,g]=O(e),{tenant:a,implementation:u,widget:m}=s;y(a)?t.setItem(r,JSON.stringify(a)):t.removeItem(r),y(u)?t.setItem(i,JSON.stringify(u)):t.removeItem(i),y(m)?t.setItem(g,JSON.stringify(m)):t.removeItem(g);const{events:p}=e.get("$widget");p.dispatch("storage:changed",{})},T=()=>({tenant:{},implementation:{},widget:{}}),V=e=>e?!!e&&new Date>new Date(e):!1,h=(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"?v(n):n}:{value:e,category:t},S=(e,t)=>{const n=c.deepClone(e);return Object.entries(n).forEach(([o,s])=>{Object.entries(s).forEach(([r,i])=>{const{expiration:g,category:a}=i;(V(g)||W(t,a))&&(s[r]=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=N(e,window.localStorage),o=N(e,sessionStorage),s=h(t,"storagePolicy"),[r,i,g]=[t,n,o].map(a=>S(a,s));I(e,r),C(e,window.localStorage,i),C(e,window.sessionStorage,g)},v=(e={days:30})=>{const{days:t=0,hours:n=0,minutes:o=0,seconds:s=0}=e,r=new Date;return r.setTime(r.getTime()+n*60*60*1e3),r.setTime(r.getTime()+t*24*60*60*1e3),r.setTime(r.getTime()+o*60*1e3),r.setTime(r.getTime()+s*1e3),r.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)(()=>N(e,n))},q=(e,t,n)=>{const o=t===l.Local?window.localStorage:window.sessionStorage;return c.lock(o)(()=>C(e,o,n))};class w{constructor(){this.memory={tenant:{},implementation:{},widget:{}}}async setItem(t,n,o={}){return c.lock(this)(()=>{const s=S(this.memory,[d.Necessary]),{scope:r=f.Tenant,expiration:i}=o;s[r][t]=J(n,d.Necessary,(i==null?void 0:i.toISOString())||v()),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
9
  Key: ${t}
10
10
  Value: ${JSON.stringify(n)}
11
- Options: ${JSON.stringify(r)}
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.
11
+ Options: ${JSON.stringify(o)}
12
+ Memory: ${JSON.stringify(s)}`)})}async getItem(t){return c.lock(this)(()=>{const n=S(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
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.
14
+ Memory: ${JSON.stringify(n)}`);const o=h(n,t);return this.memory=n,o})}async removeItem(t){return c.lock(this)(()=>{const n=S(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
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;
16
+ Memory: ${JSON.stringify(n)}`)})}async clear(){return Promise.resolve()}}class F{constructor(){this.cookies=new w,this.session=new w,this.local=new w}}const R=L.createConfigurationApi(e=>{e.createCommand("storage",t=>(n={})=>{const{consent:o}=n;if(typeof o<"u"){if(typeof o!="number"&&typeof o!="string"&&!Array.isArray(o)){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(o)}`);return}if(Array.isArray(o)&&!o.every(r=>typeof r=="number"||typeof r=="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(o)}`);return}const s=[d.Necessary,d.Functional,d.Analytical,d.Marketing].filter((r,i,g)=>typeof o=="number"?o>i:typeof o=="string"?g.indexOf(o)+1>i:Array.isArray(o)?o.findIndex(a=>a===i+1||a===r)>-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(o)}`),s.unshift(d.Necessary)),K(t.container,"storagePolicy",d.Necessary,{medium:l.Cookie,scope:f.Tenant,duration:{days:365}}).then(r=>r(s)).then(()=>{D(t.container),t.events.dispatch("storage:policy-changed",s)})}})});exports.StorageCategory=d;exports.StorageMedium=l;exports.StorageProvider=F;exports.StorageScope=f;exports.StorageService=w;exports.createStorageWriter=K;exports.readStorage=b;exports.storagePolicyConfigurationApi=R;
package/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Logger as g, lock as y, deepClone as k, hash as _ } from "@telia-ace/widget-utilities";
2
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 || {});
3
+ var l = /* @__PURE__ */ ((e) => (e.Cookie = "cookie", e.Local = "local", e.Session = "session", e))(l || {}), h = /* @__PURE__ */ ((e) => (e.Tenant = "tenant", e.Implementation = "implementation", e.Widget = "widget", e))(h || {}), d = /* @__PURE__ */ ((e) => (e.Necessary = "necessary", e.Functional = "functional", e.Analytical = "analytical", e.Marketing = "marketing", e))(d || {});
4
4
  const V = (e, t, n, r = {}) => I(e, n).then((s) => (process.env.NODE_ENV !== "production" && s && g.warn(
5
5
  `createStorageWriter: Attempted to create storage writer using unallowed category.
6
6
  Key: ${t}
@@ -18,7 +18,7 @@ const V = (e, t, n, r = {}) => I(e, n).then((s) => (process.env.NODE_ENV !== "pr
18
18
  return;
19
19
  }
20
20
  const {
21
- scope: c = N.Widget,
21
+ scope: c = h.Widget,
22
22
  medium: a = l.Session,
23
23
  duration: u
24
24
  } = r, m = j();
@@ -27,8 +27,8 @@ const V = (e, t, n, r = {}) => I(e, n).then((s) => (process.env.NODE_ENV !== "pr
27
27
  "readStorage: Undefined key passed when reading storage. ",
28
28
  t,
29
29
  n
30
- ), Promise.resolve(void 0)) : n === l.Cookie ? F(e).then((r) => w(r, t)) : q(e, n).then(
31
- (r) => w(r, t)
30
+ ), Promise.resolve(void 0)) : n === l.Cookie ? F(e).then((r) => N(r, t)) : q(e, n).then(
31
+ (r) => N(r, t)
32
32
  )), 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 }]) => {
33
33
  typeof n > "u" && delete e[t];
34
34
  }), b = (e, t) => {
@@ -47,7 +47,7 @@ const V = (e, t, n, r = {}) => I(e, n).then((s) => (process.env.NODE_ENV !== "pr
47
47
  }), n;
48
48
  },
49
49
  []
50
- ).slice().sort((n, r) => new Date(r).valueOf() - new Date(n).valueOf()).shift() || O(), h = (e) => {
50
+ ).slice().sort((n, r) => new Date(r).valueOf() - new Date(n).valueOf()).shift() || v(), O = (e) => {
51
51
  const {
52
52
  name: t,
53
53
  implementation: { name: n, tenant: r }
@@ -64,55 +64,57 @@ const V = (e, t, n, r = {}) => I(e, n).then((s) => (process.env.NODE_ENV !== "pr
64
64
  const r = `${e}=${JSON.stringify(t).trim()}`, s = `expires=${new Date(n).toUTCString()}`, o = "path=/", i = "SameSite=None;Secure";
65
65
  return document.cookie = `${r}; ${s}; ${o}; ${i}`;
66
66
  }, P = (e) => {
67
- const [t, n, r] = h(e), s = E(t) || {}, o = E(n) || {}, i = E(r) || {};
67
+ const [t, n, r] = O(e), s = E(t) || {}, o = E(n) || {}, i = E(r) || {};
68
68
  return {
69
69
  tenant: s,
70
70
  implementation: o,
71
71
  widget: i
72
72
  };
73
73
  }, x = (e, t) => {
74
- 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 });
74
+ const n = P(e), r = b(n, t), [s, o, i] = O(e), { tenant: c, implementation: a, widget: u } = r, m = W(t), f = v({ days: -1 });
75
75
  A(
76
76
  s,
77
77
  c,
78
- p(c) ? m : v
78
+ p(c) ? m : f
79
79
  ), A(
80
80
  o,
81
81
  a,
82
- p(a) ? m : v
82
+ p(a) ? m : f
83
83
  ), A(
84
84
  i,
85
85
  u,
86
- p(u) ? m : v
86
+ p(u) ? m : f
87
87
  );
88
- }, S = (e, t) => {
89
- const [n, r, s] = h(e), o = t.getItem(n) || "{}", i = t.getItem(r) || "{}", c = t.getItem(s) || "{}";
88
+ }, w = (e, t) => {
89
+ const [n, r, s] = O(e), o = t.getItem(n) || "{}", i = t.getItem(r) || "{}", c = t.getItem(s) || "{}";
90
90
  return {
91
91
  tenant: JSON.parse(o),
92
92
  implementation: JSON.parse(i),
93
93
  widget: JSON.parse(c)
94
94
  };
95
95
  }, J = (e, t, n) => {
96
- const r = S(e, t), s = b(r, n), [o, i, c] = h(e), { tenant: a, implementation: u, widget: m } = s;
96
+ const r = w(e, t), s = b(r, n), [o, i, c] = O(e), { tenant: a, implementation: u, widget: m } = s;
97
97
  p(a) ? t.setItem(o, JSON.stringify(a)) : t.removeItem(o), p(u) ? t.setItem(
98
98
  i,
99
99
  JSON.stringify(u)
100
100
  ) : t.removeItem(i), p(m) ? t.setItem(c, JSON.stringify(m)) : t.removeItem(c);
101
+ const { events: f } = e.get("$widget");
102
+ f.dispatch("storage:changed", {});
101
103
  }, j = () => ({
102
104
  tenant: {},
103
105
  implementation: {},
104
106
  widget: {}
105
- }), M = (e) => e ? !!e && /* @__PURE__ */ new Date() > new Date(e) : !1, w = (e, t) => {
107
+ }), M = (e) => e ? !!e && /* @__PURE__ */ new Date() > new Date(e) : !1, N = (e, t) => {
106
108
  const n = e.widget[t] || e.implementation[t] || e.tenant[t];
107
109
  return n == null ? void 0 : n.value;
108
110
  }, D = (e, t, n) => n ? {
109
111
  value: e,
110
112
  category: t,
111
- expiration: typeof n == "object" ? O(n) : n
113
+ expiration: typeof n == "object" ? v(n) : n
112
114
  } : {
113
115
  value: e,
114
116
  category: t
115
- }, f = (e, t) => {
117
+ }, S = (e, t) => {
116
118
  const n = k(e);
117
119
  return Object.entries(n).forEach(([r, s]) => {
118
120
  Object.entries(s).forEach(([o, i]) => {
@@ -127,18 +129,18 @@ const V = (e, t, n, r = {}) => I(e, n).then((s) => (process.env.NODE_ENV !== "pr
127
129
  ).then(
128
130
  (n = [d.Necessary]) => !!t && n.indexOf(t) === -1
129
131
  ), U = (e = [d.Necessary], t) => !!t && e.indexOf(t) === -1, K = (e) => {
130
- const t = P(e), n = S(e, window.localStorage), r = S(e, sessionStorage), s = w(t, "storagePolicy"), [o, i, c] = [
132
+ const t = P(e), n = w(e, window.localStorage), r = w(e, sessionStorage), s = N(t, "storagePolicy"), [o, i, c] = [
131
133
  t,
132
134
  n,
133
135
  r
134
- ].map((a) => f(a, s));
136
+ ].map((a) => S(a, s));
135
137
  x(e, o), J(e, window.localStorage, i), J(e, window.sessionStorage, c);
136
- }, O = (e = { days: 30 }) => {
138
+ }, v = (e = { days: 30 }) => {
137
139
  const { days: t = 0, hours: n = 0, minutes: r = 0, seconds: s = 0 } = e, o = /* @__PURE__ */ new Date();
138
140
  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();
139
141
  }, F = (e) => y(document)(() => P(e)), R = (e, t) => y(document)(() => x(e, t)), q = (e, t) => {
140
142
  const n = t === l.Local ? window.localStorage : window.sessionStorage;
141
- return y(n)(() => S(e, n));
143
+ return y(n)(() => w(e, n));
142
144
  }, z = (e, t, n) => {
143
145
  const r = t === l.Local ? window.localStorage : window.sessionStorage;
144
146
  return y(r)(() => J(e, r, n));
@@ -153,13 +155,13 @@ class C {
153
155
  }
154
156
  async setItem(t, n, r = {}) {
155
157
  return y(this)(() => {
156
- const s = f(this.memory, [
158
+ const s = S(this.memory, [
157
159
  d.Necessary
158
- ]), { scope: o = N.Tenant, expiration: i } = r;
160
+ ]), { scope: o = h.Tenant, expiration: i } = r;
159
161
  s[o][t] = D(
160
162
  n,
161
163
  d.Necessary,
162
- (i == null ? void 0 : i.toISOString()) || O()
164
+ (i == null ? void 0 : i.toISOString()) || v()
163
165
  ), this.memory = s, process.env.NODE_ENV !== "production" && g.warn(
164
166
  `StorageProvider: StorageProvider is deprecated, use createStorageWriter and readStorage instead, value stored temporarily in memory.
165
167
  Key: ${t}
@@ -171,7 +173,7 @@ class C {
171
173
  }
172
174
  async getItem(t) {
173
175
  return y(this)(() => {
174
- const n = f(this.memory, [
176
+ const n = S(this.memory, [
175
177
  d.Necessary
176
178
  ]);
177
179
  process.env.NODE_ENV !== "production" && g.warn(
@@ -179,13 +181,13 @@ class C {
179
181
  Key: ${t}
180
182
  Memory: ${JSON.stringify(n)}`
181
183
  );
182
- const r = w(n, t);
184
+ const r = N(n, t);
183
185
  return this.memory = n, r;
184
186
  });
185
187
  }
186
188
  async removeItem(t) {
187
189
  return y(this)(() => {
188
- const n = f(this.memory, [
190
+ const n = S(this.memory, [
189
191
  d.Necessary
190
192
  ]);
191
193
  delete n.tenant[t], delete n.implementation[t], delete n.widget[t], this.memory = n, process.env.NODE_ENV !== "production" && g.warn(
@@ -241,7 +243,7 @@ const Q = T((e) => {
241
243
  d.Necessary,
242
244
  {
243
245
  medium: l.Cookie,
244
- scope: N.Tenant,
246
+ scope: h.Tenant,
245
247
  duration: { days: 365 }
246
248
  }
247
249
  ).then((o) => o(s)).then(() => {
@@ -255,7 +257,7 @@ export {
255
257
  d as StorageCategory,
256
258
  l as StorageMedium,
257
259
  H as StorageProvider,
258
- N as StorageScope,
260
+ h as StorageScope,
259
261
  C as StorageService,
260
262
  V as createStorageWriter,
261
263
  L as readStorage,
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@telia-ace/widget-services",
3
- "version": "1.3.8",
3
+ "version": "1.3.10-rc.0",
4
4
  "dependencies": {
5
- "@telia-ace/widget-utilities": "^1.3.8",
5
+ "@telia-ace/widget-utilities": "^1.3.10-rc.0",
6
6
  "@webprovisions/platform": "^1.1.4"
7
7
  },
8
8
  "main": "./index.js",