@blotoutio/edgetag-sdk-browser 0.1.9 → 0.2.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.
- package/index.js +83 -52
- package/index.min.js +1 -1
- package/index.min.js.gz +0 -0
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -10,6 +10,21 @@
|
|
|
10
10
|
|
|
11
11
|
const initKey = `${keyPrefix}Store`;
|
|
12
12
|
const saveDataPerKey = (persistType, provider, value, key) => {
|
|
13
|
+
const storage = getData(persistType);
|
|
14
|
+
if (!storage.data) {
|
|
15
|
+
storage.data = {};
|
|
16
|
+
}
|
|
17
|
+
if (!storage.data[provider]) {
|
|
18
|
+
storage.data[provider] = {};
|
|
19
|
+
}
|
|
20
|
+
// migration
|
|
21
|
+
if (storage[provider]) {
|
|
22
|
+
storage.data[provider] = storage[provider];
|
|
23
|
+
}
|
|
24
|
+
storage.data[provider][key] = value;
|
|
25
|
+
saveData(persistType, storage);
|
|
26
|
+
};
|
|
27
|
+
const savePerKey = (persistType, provider, value, key) => {
|
|
13
28
|
const storage = getData(persistType);
|
|
14
29
|
if (!storage[provider]) {
|
|
15
30
|
storage[provider] = {};
|
|
@@ -50,6 +65,49 @@
|
|
|
50
65
|
return JSON.parse(sessionStorage.getItem(key)) || {};
|
|
51
66
|
};
|
|
52
67
|
|
|
68
|
+
let endpointUrl = '';
|
|
69
|
+
const generateUrl = (path) => {
|
|
70
|
+
const endpoint = getUrl();
|
|
71
|
+
if (!endpoint) {
|
|
72
|
+
console.log('URL is not valid');
|
|
73
|
+
return '';
|
|
74
|
+
}
|
|
75
|
+
return `${endpoint}${path}`;
|
|
76
|
+
};
|
|
77
|
+
const getUrl = () => {
|
|
78
|
+
return endpointUrl;
|
|
79
|
+
};
|
|
80
|
+
const setUrl = (url) => {
|
|
81
|
+
if (url == null) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
endpointUrl = url;
|
|
85
|
+
};
|
|
86
|
+
const getTagURL = () => {
|
|
87
|
+
return generateUrl('/tag');
|
|
88
|
+
};
|
|
89
|
+
const getInitURL = () => {
|
|
90
|
+
return generateUrl('/init');
|
|
91
|
+
};
|
|
92
|
+
const getConsentURL = () => {
|
|
93
|
+
return generateUrl('/consent');
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
let consentDisabled = false;
|
|
97
|
+
const setPreferences = (preferences) => {
|
|
98
|
+
if (!preferences) {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
if (!preferences.edgeURL) {
|
|
102
|
+
console.error('Please provide URL for EdgeTag');
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
consentDisabled = !!preferences.disableConsentCheck;
|
|
106
|
+
setUrl(preferences.edgeURL);
|
|
107
|
+
return true;
|
|
108
|
+
};
|
|
109
|
+
const isConsentDisabled = () => consentDisabled;
|
|
110
|
+
|
|
53
111
|
const getUserAgent = () => {
|
|
54
112
|
const nav = navigator;
|
|
55
113
|
let ua = nav.userAgent;
|
|
@@ -58,6 +116,9 @@
|
|
|
58
116
|
};
|
|
59
117
|
const allowTag = (providers) => {
|
|
60
118
|
const consent = getDataPerKey('local', tagStorage, consentKey);
|
|
119
|
+
if (isConsentDisabled()) {
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
61
122
|
if (!consent) {
|
|
62
123
|
return false;
|
|
63
124
|
}
|
|
@@ -155,45 +216,20 @@
|
|
|
155
216
|
return await ajax('GET', url);
|
|
156
217
|
}
|
|
157
218
|
|
|
158
|
-
let endpointUrl = '';
|
|
159
|
-
const generateUrl = (path) => {
|
|
160
|
-
const endpoint = getUrl();
|
|
161
|
-
if (!endpoint) {
|
|
162
|
-
console.log('URL is not valid');
|
|
163
|
-
return '';
|
|
164
|
-
}
|
|
165
|
-
return `${endpoint}${path}`;
|
|
166
|
-
};
|
|
167
|
-
const getUrl = () => {
|
|
168
|
-
return endpointUrl;
|
|
169
|
-
};
|
|
170
|
-
const setUrl = (url) => {
|
|
171
|
-
if (url == null) {
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
endpointUrl = url;
|
|
175
|
-
};
|
|
176
|
-
const getTagURL = () => {
|
|
177
|
-
return generateUrl('/tag');
|
|
178
|
-
};
|
|
179
|
-
const getInitURL = () => {
|
|
180
|
-
return generateUrl('/init');
|
|
181
|
-
};
|
|
182
|
-
const getConsentURL = () => {
|
|
183
|
-
return generateUrl('/consent');
|
|
184
|
-
};
|
|
185
|
-
|
|
186
219
|
const info = (data) => {
|
|
187
220
|
{
|
|
188
221
|
console.info(data);
|
|
189
222
|
}
|
|
190
223
|
};
|
|
191
224
|
|
|
225
|
+
const saveConsent = (consent) => {
|
|
226
|
+
savePerKey('local', tagStorage, consent, consentKey);
|
|
227
|
+
};
|
|
192
228
|
const handleConsent = (consent) => {
|
|
193
229
|
const payload = {
|
|
194
230
|
consentString: consent,
|
|
195
231
|
};
|
|
196
|
-
|
|
232
|
+
saveConsent(consent);
|
|
197
233
|
postRequest(getConsentURL(), payload).catch(info);
|
|
198
234
|
};
|
|
199
235
|
|
|
@@ -214,18 +250,6 @@
|
|
|
214
250
|
postRequest(getTagURL(), payload).catch(info);
|
|
215
251
|
};
|
|
216
252
|
|
|
217
|
-
const setPreferences = (preferences) => {
|
|
218
|
-
if (!preferences) {
|
|
219
|
-
return false;
|
|
220
|
-
}
|
|
221
|
-
if (!preferences.edgeURL) {
|
|
222
|
-
console.info('Please provide URL for EdgeTag');
|
|
223
|
-
return false;
|
|
224
|
-
}
|
|
225
|
-
setUrl(preferences.edgeURL);
|
|
226
|
-
return true;
|
|
227
|
-
};
|
|
228
|
-
|
|
229
253
|
const getCookieValue = (key) => {
|
|
230
254
|
let name = `${key}=`;
|
|
231
255
|
let decodedCookie = decodeURIComponent(document.cookie);
|
|
@@ -270,16 +294,18 @@
|
|
|
270
294
|
saveDataPerKey(persistType, provider, data, key);
|
|
271
295
|
};
|
|
272
296
|
const handleCapture = (provider, params) => {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
297
|
+
params.forEach((param) => {
|
|
298
|
+
switch (param.type) {
|
|
299
|
+
case 'query': {
|
|
300
|
+
handleCaptureQuery(provider, param.key, param.persist);
|
|
301
|
+
break;
|
|
302
|
+
}
|
|
303
|
+
case 'storage': {
|
|
304
|
+
handleCaptureStorage(provider, param.location, param.key, param.persist);
|
|
305
|
+
break;
|
|
306
|
+
}
|
|
281
307
|
}
|
|
282
|
-
}
|
|
308
|
+
});
|
|
283
309
|
};
|
|
284
310
|
|
|
285
311
|
const handleManifest = (manifest) => {
|
|
@@ -295,7 +321,7 @@
|
|
|
295
321
|
}
|
|
296
322
|
});
|
|
297
323
|
});
|
|
298
|
-
|
|
324
|
+
savePerKey('local', tagStorage, providers, providersKey);
|
|
299
325
|
};
|
|
300
326
|
|
|
301
327
|
const handleInit = (preferences) => {
|
|
@@ -303,7 +329,12 @@
|
|
|
303
329
|
if (!success) {
|
|
304
330
|
return;
|
|
305
331
|
}
|
|
306
|
-
|
|
332
|
+
let url = `${getInitURL()}`;
|
|
333
|
+
if (preferences.disableConsentCheck) {
|
|
334
|
+
url = `${url}?consentDisabled=true`;
|
|
335
|
+
saveConsent({ all: true });
|
|
336
|
+
}
|
|
337
|
+
getRequest(url)
|
|
307
338
|
.then((result) => {
|
|
308
339
|
if (!result) {
|
|
309
340
|
console.log('init failed');
|
package/index.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e){"function"==typeof define&&define.amd?define(e):e()}((function(){"use strict";const e="edgeTag",t="consent",n="providers",o="_workerStore",r=(e,t,n,o)=>{const r=
|
|
1
|
+
!function(e){"function"==typeof define&&define.amd?define(e):e()}((function(){"use strict";const e="edgeTag",t="consent",n="providers",o="_workerStore",r=(e,t,n,o)=>{const r=i(e);r.data||(r.data={}),r.data[t]||(r.data[t]={}),r[t]&&(r.data[t]=r[t]),r.data[t][o]=n,c(e,r)},s=(e,t,n,o)=>{const r=i(e);r[t]||(r[t]={}),r[t][o]=n,c(e,r)},a=(e,t,n)=>{const o=i(e);if(o[t])return o[t][n]},c=(e,t,n=o)=>{"session"!==e?l(t,n):u(t,n)},i=(e,t=o)=>"session"===e?d(t):g(t),l=(e,t)=>{localStorage.setItem(t,JSON.stringify(e))},g=e=>JSON.parse(localStorage.getItem(e))||{},u=(e,t)=>{sessionStorage.setItem(t,JSON.stringify(e))},d=e=>JSON.parse(sessionStorage.getItem(e))||{};let f="";const h=e=>{const t=p();return t?`${t}${e}`:(console.log("URL is not valid"),"")},p=()=>f;let y=!1;const m=e=>{return!!e&&(e.edgeURL?(y=!!e.disableConsentCheck,null!=(t=e.edgeURL)&&(f=t),!0):(console.error("Please provide URL for EdgeTag"),!1));var t},w=()=>{const e=navigator;let t=e.userAgent;return t+=e.brave?`${t} Brave`:"",t},b=o=>{const r=a("local",e,t);if(y)return!0;if(!r)return!1;if(!0===r.all)return!0;if(!o)return Object.values(r).find((e=>e));const s=a("local",e,n)||[];for(const e of s){const t=o[e];if((t||!0===o.all&&null==t||!1===o.all&&!0===t)&&r[e])return!0}return!1},v=(e,t)=>{let n;return t&&(n=new Blob([JSON.stringify(t)],{type:"application/json"})),navigator.sendBeacon(e,n)},S=async(e,t,n)=>await fetch(t,{method:e,headers:{"Content-type":"application/json; charset=utf-8",Accept:"application/json; charset=utf-8"},body:JSON.stringify(n),credentials:"include"}).then((e=>e.json().then((t=>({status:e.status,body:t}))))).then((e=>e.status<200||e.status>=300?Promise.reject(new Error(JSON.stringify(e.body))):Promise.resolve(e.body))).catch((e=>Promise.reject(new Error(e))));async function k(e,t,n){if(!e)return Promise.reject(new Error("URL is empty"));const o=(e=>{const t={pageUrl:window.location.href,userAgent:w(),...e};let n={};const o=i("session");o&&(n={...n,...o});const r=i("local");return r&&(n={...n,...r}),t.storage=n,t})(t);return n&&"beacon"===n.method&&navigator.sendBeacon?Promise.resolve(v(e,o)):await S("POST",e,o)}const O=e=>{},j=n=>{s("local",e,n,t)},E=e=>{const t={consentString:e};j(e),k(h("/consent"),t).catch(O)},P=(e,t,n)=>{let o={eventName:e};t&&(o.data=t),n&&(o.providers=n),b(n)?k(h("/tag"),o).catch(O):console.log("No consent")},N=(e,t,n,o)=>{let s;switch(t){case"cookie":s=(e=>{let t=`${e}=`,n=decodeURIComponent(document.cookie).split(";");for(let e=0;e<n.length;e++){let o=n[e];for(;" "==o.charAt(0);)o=o.substring(1);if(0==o.indexOf(t))return o.substring(t.length,o.length)}return""})(n);break;case"local":s=sessionStorage.getItem(n);break;case"session":s=localStorage.getItem(n)}s&&r(o,e,s,n)},U=(e,t)=>{t.forEach((t=>{switch(t.type){case"query":((e,t,n)=>{const o=new URLSearchParams(window.location.search);o&&o.get(t)&&r(n,e,o.get(t),t)})(e,t.key,t.persist);break;case"storage":N(e,t.location,t.key,t.persist)}}))},R=t=>{if(!m(t))return;let o=`${h("/init")}`;t.disableConsentCheck&&(o=`${o}?consentDisabled=true`,j({all:!0})),async function(e,t){return e?t&&"beacon"===t.method&&navigator.sendBeacon?Promise.resolve(v(e)):await S("GET",e):Promise.reject(new Error("URL is empty"))}(o).then((t=>{t?(t=>{const o=[];t.forEach((e=>{o.push(e.package),Object.entries(e.rules).forEach((([t,n])=>{"capture"!==t||U(e.package,n)}))})),s("local",e,o,n)})(t.result):console.log("init failed")})).catch(O)};var I=new class{init(e){(e=>{R(e)})(e)}tag(e,t,n){((e,t,n)=>{P(e,t,n)})(e,t,n)}consent(e){(e=>{E(e)})(e)}};!function(){const e=e=>{const n=[].slice.call(e);if(Array.isArray(n))try{return t[n[0]](...n.slice(1))}catch(e){console.error(e)}},t=I;let n=[];window.edgetag&&(n=window.edgetag.stubs||[]),window.edgetag=function(){return e(arguments)},n.forEach(e)}()}));
|
package/index.min.js.gz
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blotoutio/edgetag-sdk-browser",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Browser package for
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Browser package for EdgeTag sdk",
|
|
5
5
|
"author": "Blotout",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/blotoutio/edgetag-sdk",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"start:web": "rollup --config --configDev --w"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@blotoutio/edgetag-sdk-
|
|
28
|
+
"@blotoutio/edgetag-sdk-js": "^0.1.0"
|
|
29
29
|
},
|
|
30
30
|
"publishConfig": {
|
|
31
31
|
"access": "public"
|