@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.
- package/index.js +14 -14
- package/index.mjs +120 -348
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
2
|
-
Key: ${
|
|
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=>(
|
|
5
|
-
Key: ${
|
|
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:
|
|
9
|
-
Key: ${
|
|
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(
|
|
13
|
-
Key: ${
|
|
14
|
-
Memory: ${JSON.stringify(n)}`);const r=
|
|
15
|
-
Key: ${
|
|
16
|
-
Memory: ${JSON.stringify(n)}`)})}async clear(){return Promise.resolve()}}class
|
|
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"&&
|
|
18
|
-
Passed consent: ${JSON.stringify(r)}`);return}const s=[
|
|
19
|
-
Passed consent: ${JSON.stringify(r)}`),s.unshift(
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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: ${
|
|
6
|
+
Key: ${t}
|
|
76
7
|
Category: ${JSON.stringify(n)}
|
|
77
8
|
Options: ${JSON.stringify(r)}`
|
|
78
|
-
), (o) => (
|
|
9
|
+
), (o) => (K(e), I(e, n).then((i) => {
|
|
79
10
|
if (i) {
|
|
80
|
-
process.env.NODE_ENV !== "production" &&
|
|
11
|
+
process.env.NODE_ENV !== "production" && g.warn(
|
|
81
12
|
`storageWriter: Attempted to write to storage using unallowed category.
|
|
82
|
-
Key: ${
|
|
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:
|
|
91
|
-
medium:
|
|
21
|
+
scope: c = N.Widget,
|
|
22
|
+
medium: a = l.Session,
|
|
92
23
|
duration: u
|
|
93
|
-
} = r,
|
|
94
|
-
return
|
|
95
|
-
})))),
|
|
96
|
-
typeof n > "u" && delete t
|
|
97
|
-
}),
|
|
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: { ...
|
|
100
|
-
implementation: { ...
|
|
101
|
-
widget: { ...
|
|
30
|
+
tenant: { ...e.tenant, ...t.tenant },
|
|
31
|
+
implementation: { ...e.implementation, ...t.implementation },
|
|
32
|
+
widget: { ...e.widget, ...t.widget }
|
|
102
33
|
};
|
|
103
|
-
return
|
|
104
|
-
},
|
|
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 [
|
|
108
|
-
|
|
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() ||
|
|
41
|
+
}, []).slice().sort((n, r) => new Date(r).valueOf() - new Date(n).valueOf()).shift() || O(), h = (e) => {
|
|
111
42
|
const {
|
|
112
|
-
name:
|
|
43
|
+
name: t,
|
|
113
44
|
implementation: { name: n, tenant: r }
|
|
114
|
-
} =
|
|
45
|
+
} = e.get("$widget");
|
|
115
46
|
return [
|
|
116
47
|
`humany_${r}`,
|
|
117
|
-
`humany_${
|
|
118
|
-
`humany_${
|
|
48
|
+
`humany_${_(r + n)}`,
|
|
49
|
+
`humany_${_(r + n + t)}`
|
|
119
50
|
];
|
|
120
|
-
},
|
|
121
|
-
const
|
|
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
|
-
},
|
|
124
|
-
const r = `${
|
|
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
|
-
},
|
|
127
|
-
const [
|
|
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
|
-
},
|
|
134
|
-
const n =
|
|
135
|
-
|
|
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
|
-
|
|
138
|
-
|
|
139
|
-
),
|
|
140
|
-
},
|
|
141
|
-
const [n, r, 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(
|
|
76
|
+
widget: JSON.parse(c)
|
|
146
77
|
};
|
|
147
|
-
},
|
|
148
|
-
const r =
|
|
149
|
-
|
|
150
|
-
},
|
|
151
|
-
const n =
|
|
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
|
-
},
|
|
154
|
-
value:
|
|
155
|
-
category:
|
|
156
|
-
expiration: typeof n == "object" ?
|
|
84
|
+
}, D = (e, t, n) => n ? {
|
|
85
|
+
value: e,
|
|
86
|
+
category: t,
|
|
87
|
+
expiration: typeof n == "object" ? O(n) : n
|
|
157
88
|
} : {
|
|
158
|
-
value:
|
|
159
|
-
category:
|
|
160
|
-
},
|
|
161
|
-
const n =
|
|
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:
|
|
165
|
-
(
|
|
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
|
-
},
|
|
169
|
-
(n = [
|
|
170
|
-
),
|
|
171
|
-
const
|
|
172
|
-
|
|
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((
|
|
176
|
-
|
|
177
|
-
},
|
|
178
|
-
const { days:
|
|
179
|
-
return o.setTime(o.getTime() + n * 60 * 60 * 1e3), o.setTime(o.getTime() +
|
|
180
|
-
},
|
|
181
|
-
const n =
|
|
182
|
-
return
|
|
183
|
-
},
|
|
184
|
-
const r =
|
|
185
|
-
return
|
|
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
|
|
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(
|
|
196
|
-
return
|
|
197
|
-
const s =
|
|
198
|
-
s[o][
|
|
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
|
-
|
|
201
|
-
(i == null ? void 0 : i.toISOString()) ||
|
|
202
|
-
), this.memory = s, process.env.NODE_ENV !== "production" &&
|
|
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: ${
|
|
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(
|
|
212
|
-
return
|
|
213
|
-
const n =
|
|
214
|
-
process.env.NODE_ENV !== "production" &&
|
|
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: ${
|
|
147
|
+
Key: ${t}
|
|
217
148
|
Memory: ${JSON.stringify(n)}`
|
|
218
149
|
);
|
|
219
|
-
const r =
|
|
150
|
+
const r = w(n, t);
|
|
220
151
|
return this.memory = n, r;
|
|
221
152
|
});
|
|
222
153
|
}
|
|
223
|
-
async removeItem(
|
|
224
|
-
return
|
|
225
|
-
const n =
|
|
226
|
-
delete n.tenant[
|
|
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: ${
|
|
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
|
|
168
|
+
class H {
|
|
238
169
|
constructor() {
|
|
239
|
-
this.cookies = new
|
|
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
|
-
|
|
292
|
-
|
|
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" &&
|
|
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" &&
|
|
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
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
].filter((o, i,
|
|
427
|
-
return s.indexOf(
|
|
428
|
-
`storagePolicyConfigurationApi: passed consent does not include 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(
|
|
431
|
-
|
|
202
|
+
), s.unshift(d.Necessary)), V(
|
|
203
|
+
t.container,
|
|
432
204
|
"storagePolicy",
|
|
433
|
-
|
|
205
|
+
d.Necessary,
|
|
434
206
|
{
|
|
435
|
-
medium:
|
|
436
|
-
scope:
|
|
207
|
+
medium: l.Cookie,
|
|
208
|
+
scope: N.Tenant,
|
|
437
209
|
duration: { days: 365 }
|
|
438
210
|
}
|
|
439
211
|
).then((o) => o(s)).then(() => {
|
|
440
|
-
|
|
212
|
+
K(t.container), t.events.dispatch("storage:policy-changed", s);
|
|
441
213
|
});
|
|
442
214
|
}
|
|
443
215
|
});
|
|
444
216
|
});
|
|
445
217
|
export {
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
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.
|
|
3
|
+
"version": "1.1.1-rc.3",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@telia-ace/widget-utilities": "^1.1.1-rc.
|
|
5
|
+
"@telia-ace/widget-utilities": "^1.1.1-rc.3",
|
|
6
6
|
"@webprovisions/platform": "^1.1.4"
|
|
7
7
|
},
|
|
8
8
|
"main": "./index.js",
|