@blotoutio/edgetag-sdk-browser 0.2.0 → 0.3.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.esm.js ADDED
@@ -0,0 +1 @@
1
+ function e(e,t,n,o){return new(n||(n=Promise))((function(r,s){function a(e){try{i(o.next(e))}catch(e){s(e)}}function c(e){try{i(o.throw(e))}catch(e){s(e)}}function i(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,c)}i((o=o.apply(e,t||[])).next())}))}const t=(e,t,n,o)=>{const a=s(e);a.data||(a.data={}),a.data[t]||(a.data[t]={}),a.data[t][o]=n,r(e,a)},n=(e,t,n,o)=>{const a=s(e);a[t]||(a[t]={}),a[t][o]=n,r(e,a)},o=(e,t,n)=>{const o=s(e);if(o[t])return o[t][n]},r=(e,t,n="_workerStore")=>{"session"!==e?a(t,n):i(t,n)},s=(e,t="_workerStore")=>"session"===e?l(t):c(t),a=(e,t)=>{localStorage.setItem(t,JSON.stringify(e))},c=e=>{const t=localStorage.getItem(e);return t&&JSON.parse(t)||{}},i=(e,t)=>{sessionStorage.setItem(t,JSON.stringify(e))},l=e=>{const t=sessionStorage.getItem(e);return t&&JSON.parse(t)||{}};let u="";const g=e=>{const t=d();return t?`${t}${e}`:(console.log("URL is not valid"),"")},d=()=>u;let f=!1;const h=e=>{return!!e&&(e.edgeURL?(f=!!e.disableConsentCheck,null!=(t=e.edgeURL)&&(u=t),!0):(console.error("Please provide URL for EdgeTag"),!1));var t},v=()=>{const e=navigator;let t=e.userAgent;return t+=e.brave?`${t} Brave`:"",t},p=e=>{const t=o("local","edgeTag","consent");if(f)return!0;if(!t)return!1;if(t.all)return!0;if(!e)return Object.values(t).find((e=>e))||!1;const n=o("local","edgeTag","providers")||[];for(const o of n){const n=e[o];if((n||!0===e.all&&void 0===n||!1===e.all&&!0===n)&&t[o])return!0}return!1},y=(e,t)=>{let n;return t&&(n=new Blob([JSON.stringify(t)],{type:"application/json"})),navigator.sendBeacon(e,n)},b=(t,n,o)=>e(void 0,void 0,void 0,(function*(){return yield fetch(n,{method:t,headers:{"Content-type":"application/json; charset=utf-8",Accept:"application/json; charset=utf-8"},body:JSON.stringify(o),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))))}));function m(t,n,o){return e(this,void 0,void 0,(function*(){if(!t)return Promise.reject(new Error("URL is empty"));const e=(e=>{const t=Object.assign({pageUrl:window.location.href,userAgent:v()},e||{});let n={};const o=s("session");o&&(n=Object.assign(Object.assign({},n),o));const r=s("local");return r&&(n=Object.assign(Object.assign({},n),r)),t.storage=n,t})(n);return o&&"beacon"===o.method&&navigator.sendBeacon?Promise.resolve(y(t,e)):yield b("POST",t,e)}))}const w=e=>{},S=e=>{n("local","edgeTag",e,"consent")},O=e=>{const t={consentString:e};S(e),m(g("/consent"),t).catch(w)},j=(e,t,n)=>{const o={eventName:e};t&&(o.data=t),n&&(o.providers=n),p(n)?m(g("/tag"),o).catch(w):console.log("No consent")},k=(e,n,o,r)=>{let s;switch(r){case"cookie":s=(e=>{const 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&&t(o,e,s,n)},P=(e,n)=>{n.forEach((n=>{switch(n.type){case"query":((e,n,o)=>{const r=new URLSearchParams(window.location.search);r&&r.get(n)&&t(o,e,r.get(n),n)})(e,n.key,n.persist);break;case"storage":k(e,n.key,n.persist,n.location)}}))},E=t=>{if(!h(t))return;let o=`${g("/init")}`;t.disableConsentCheck&&(o=`${o}?consentDisabled=true`,S({all:!0})),function(t,n){return e(this,void 0,void 0,(function*(){return t?n&&"beacon"===n.method&&navigator.sendBeacon?{result:Promise.resolve(y(t))}:yield b("GET",t):Promise.reject(new Error("URL is empty"))}))}(o).then((e=>{e?(e=>{const t=[];e.forEach((e=>{t.push(e.package),Object.entries(e.rules).forEach((([t,n])=>{"capture"!==t||P(e.package,n)}))})),n("local","edgeTag",t,"providers")})(e.result):console.log("init failed")})).catch(w)},N=(e,t)=>{if(!e||!t)return void console.error("Key or Value is missing in user api.");const n={key:e,value:t};m(g("/user"),n).catch(w)};var U=new class{init(e){(e=>{E(e)})(e)}tag(e,t,n){((e,t,n)=>{j(e,t,n)})(e,t,n)}consent(e){(e=>{O(e)})(e)}user(e,t){((e,t)=>{N(e,t)})(e,t)}};!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=U;let n=[];window.edgetag&&(n=window.edgetag.stubs||[]),window.edgetag=function(){return e(arguments)},n.forEach(e)}();
package/index.umd.js ADDED
@@ -0,0 +1 @@
1
+ !function(e){"function"==typeof define&&define.amd?define(e):e()}((function(){"use strict";function e(e,t,n,o){return new(n||(n=Promise))((function(r,s){function c(e){try{a(o.next(e))}catch(e){s(e)}}function i(e){try{a(o.throw(e))}catch(e){s(e)}}function a(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,i)}a((o=o.apply(e,t||[])).next())}))}const t="edgeTag",n="consent",o="providers",r="_workerStore",s=(e,t,n,o)=>{const r=l(e);r.data||(r.data={}),r.data[t]||(r.data[t]={}),r.data[t][o]=n,a(e,r)},c=(e,t,n,o)=>{const r=l(e);r[t]||(r[t]={}),r[t][o]=n,a(e,r)},i=(e,t,n)=>{const o=l(e);if(o[t])return o[t][n]},a=(e,t,n=r)=>{"session"!==e?u(t,n):g(t,n)},l=(e,t=r)=>"session"===e?f(t):d(t),u=(e,t)=>{localStorage.setItem(t,JSON.stringify(e))},d=e=>{const t=localStorage.getItem(e);return t&&JSON.parse(t)||{}},g=(e,t)=>{sessionStorage.setItem(t,JSON.stringify(e))},f=e=>{const t=sessionStorage.getItem(e);return t&&JSON.parse(t)||{}};let h="";const p=e=>{const t=v();return t?`${t}${e}`:(console.log("URL is not valid"),"")},v=()=>h;let y=!1;const m=e=>{return!!e&&(e.edgeURL?(y=!!e.disableConsentCheck,null!=(t=e.edgeURL)&&(h=t),!0):(console.error("Please provide URL for EdgeTag"),!1));var t},b=()=>{const e=navigator;let t=e.userAgent;return t+=e.brave?`${t} Brave`:"",t},w=e=>{const r=i("local",t,n);if(y)return!0;if(!r)return!1;if(r.all)return!0;if(!e)return Object.values(r).find((e=>e))||!1;const s=i("local",t,o)||[];for(const t of s){const n=e[t];if((n||!0===e.all&&void 0===n||!1===e.all&&!0===n)&&r[t])return!0}return!1},S=(e,t)=>{let n;return t&&(n=new Blob([JSON.stringify(t)],{type:"application/json"})),navigator.sendBeacon(e,n)},O=(t,n,o)=>e(void 0,void 0,void 0,(function*(){return yield fetch(n,{method:t,headers:{"Content-type":"application/json; charset=utf-8",Accept:"application/json; charset=utf-8"},body:JSON.stringify(o),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))))}));function j(t,n,o){return e(this,void 0,void 0,(function*(){if(!t)return Promise.reject(new Error("URL is empty"));const e=(e=>{const t=Object.assign({pageUrl:window.location.href,userAgent:b()},e||{});let n={};const o=l("session");o&&(n=Object.assign(Object.assign({},n),o));const r=l("local");return r&&(n=Object.assign(Object.assign({},n),r)),t.storage=n,t})(n);return o&&"beacon"===o.method&&navigator.sendBeacon?Promise.resolve(S(t,e)):yield O("POST",t,e)}))}const k=e=>{},P=e=>{c("local",t,e,n)},E=e=>{const t={consentString:e};P(e),j(p("/consent"),t).catch(k)},N=(e,t,n)=>{const o={eventName:e};t&&(o.data=t),n&&(o.providers=n),w(n)?j(p("/tag"),o).catch(k):console.log("No consent")},U=(e,t,n,o)=>{let r;switch(o){case"cookie":r=(e=>{const 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""})(t);break;case"local":r=sessionStorage.getItem(t);break;case"session":r=localStorage.getItem(t)}r&&s(n,e,r,t)},R=(e,t)=>{t.forEach((t=>{switch(t.type){case"query":((e,t,n)=>{const o=new URLSearchParams(window.location.search);o&&o.get(t)&&s(n,e,o.get(t),t)})(e,t.key,t.persist);break;case"storage":U(e,t.key,t.persist,t.location)}}))},I=n=>{if(!m(n))return;let r=`${p("/init")}`;n.disableConsentCheck&&(r=`${r}?consentDisabled=true`,P({all:!0})),function(t,n){return e(this,void 0,void 0,(function*(){return t?n&&"beacon"===n.method&&navigator.sendBeacon?{result:Promise.resolve(S(t))}:yield O("GET",t):Promise.reject(new Error("URL is empty"))}))}(r).then((e=>{e?(e=>{const n=[];e.forEach((e=>{n.push(e.package),Object.entries(e.rules).forEach((([t,n])=>{"capture"!==t||R(e.package,n)}))})),c("local",t,n,o)})(e.result):console.log("init failed")})).catch(k)},J=(e,t)=>{if(!e||!t)return void console.error("Key or Value is missing in user api.");const n={key:e,value:t};j(p("/user"),n).catch(k)};var L=new class{init(e){(e=>{I(e)})(e)}tag(e,t,n){((e,t,n)=>{N(e,t,n)})(e,t,n)}consent(e){(e=>{E(e)})(e)}user(e,t){((e,t)=>{J(e,t)})(e,t)}};!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=L;let n=[];window.edgetag&&(n=window.edgetag.stubs||[]),window.edgetag=function(){return e(arguments)},n.forEach(e)}()}));
package/package.json CHANGED
@@ -1,33 +1,24 @@
1
1
  {
2
2
  "name": "@blotoutio/edgetag-sdk-browser",
3
- "version": "0.2.0",
4
- "description": "Browser package for EdgeTag sdk",
3
+ "version": "0.3.0",
4
+ "description": "Browser SDK for EdgeTag",
5
5
  "author": "Blotout",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/blotoutio/edgetag-sdk",
8
+ "publishConfig": {
9
+ "access": "public"
10
+ },
8
11
  "repository": {
9
12
  "type": "git",
10
13
  "url": "git+https://github.com/blotoutio/edgetag-sdk.git"
11
14
  },
12
15
  "files": [
13
- "index.js",
14
- "index.min.js",
15
- "index.min.js.gz",
16
+ "index.esm.js",
17
+ "index.umd.js",
16
18
  "package.json",
17
19
  "README.md"
18
20
  ],
19
- "scripts": {
20
- "prepublish": "npm run build",
21
- "build": "rollup --config",
22
- "build:web": "rollup --config --configDev",
23
- "lint": "prettier --check .",
24
- "start": "rollup --config --w",
25
- "start:web": "rollup --config --configDev --w"
26
- },
27
- "devDependencies": {
28
- "@blotoutio/edgetag-sdk-js": "^0.1.0"
29
- },
30
- "publishConfig": {
31
- "access": "public"
32
- }
21
+ "main": "./index.umd.js",
22
+ "module": "./index.esm.js",
23
+ "typings": "./index.d.ts"
33
24
  }
package/index.js DELETED
@@ -1,408 +0,0 @@
1
- (function (factory) {
2
- typeof define === 'function' && define.amd ? define(factory) :
3
- factory();
4
- })((function () { 'use strict';
5
-
6
- const tagStorage = 'edgeTag';
7
- const consentKey = 'consent';
8
- const providersKey = 'providers';
9
- const keyPrefix = `_worker`;
10
-
11
- const initKey = `${keyPrefix}Store`;
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) => {
28
- const storage = getData(persistType);
29
- if (!storage[provider]) {
30
- storage[provider] = {};
31
- }
32
- storage[provider][key] = value;
33
- saveData(persistType, storage);
34
- };
35
- const getDataPerKey = (persistType, provider, key) => {
36
- const storage = getData(persistType);
37
- if (!storage[provider]) {
38
- return undefined;
39
- }
40
- return storage[provider][key];
41
- };
42
- const saveData = (persistType, value, key = initKey) => {
43
- if (persistType === 'session') {
44
- saveSession(value, key);
45
- return;
46
- }
47
- saveLocal(value, key);
48
- };
49
- const getData = (persistType, key = initKey) => {
50
- if (persistType === 'session') {
51
- return getSession(key);
52
- }
53
- return getLocal(key);
54
- };
55
- const saveLocal = (value, key) => {
56
- localStorage.setItem(key, JSON.stringify(value));
57
- };
58
- const getLocal = (key) => {
59
- return JSON.parse(localStorage.getItem(key)) || {};
60
- };
61
- const saveSession = (value, key) => {
62
- sessionStorage.setItem(key, JSON.stringify(value));
63
- };
64
- const getSession = (key) => {
65
- return JSON.parse(sessionStorage.getItem(key)) || {};
66
- };
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
-
111
- const getUserAgent = () => {
112
- const nav = navigator;
113
- let ua = nav.userAgent;
114
- ua += nav.brave ? `${ua} Brave` : '';
115
- return ua;
116
- };
117
- const allowTag = (providers) => {
118
- const consent = getDataPerKey('local', tagStorage, consentKey);
119
- if (isConsentDisabled()) {
120
- return true;
121
- }
122
- if (!consent) {
123
- return false;
124
- }
125
- if (consent.all === true) {
126
- return true;
127
- }
128
- if (!providers) {
129
- return Object.values(consent).find((isAllowed) => isAllowed);
130
- }
131
- const allProviders = getDataPerKey('local', tagStorage, providersKey) || [];
132
- for (const provider of allProviders) {
133
- const tagProviderSetting = providers[provider];
134
- if (tagProviderSetting ||
135
- (providers.all === true && tagProviderSetting == undefined) ||
136
- (providers.all === false && tagProviderSetting === true)) {
137
- if (consent[provider]) {
138
- return true;
139
- }
140
- }
141
- }
142
- return false;
143
- };
144
-
145
- const beacon = (url, payload) => {
146
- let blob;
147
- if (payload) {
148
- blob = new Blob([JSON.stringify(payload)], { type: 'application/json' });
149
- }
150
- return navigator.sendBeacon(url, blob);
151
- };
152
- const ajax = async (method, url, payload) => {
153
- return await fetch(url, {
154
- method,
155
- headers: {
156
- 'Content-type': 'application/json; charset=utf-8',
157
- Accept: 'application/json; charset=utf-8',
158
- },
159
- body: JSON.stringify(payload),
160
- credentials: 'include',
161
- })
162
- .then((response) => response.json().then((data) => ({ status: response.status, body: data })))
163
- .then((data) => {
164
- if (data.status < 200 || data.status >= 300) {
165
- // Q: do we need to retry?
166
- return Promise.reject(new Error(JSON.stringify(data.body)));
167
- }
168
- return Promise.resolve(data.body);
169
- })
170
- .catch((error) => {
171
- // Q: do we need to retry?
172
- return Promise.reject(new Error(error));
173
- });
174
- };
175
- const getStandardPayload = (payload) => {
176
- const data = {
177
- pageUrl: window.location.href,
178
- userAgent: getUserAgent(),
179
- ...payload,
180
- };
181
- let storage = {};
182
- const session = getData('session');
183
- if (session) {
184
- storage = {
185
- ...storage,
186
- ...session,
187
- };
188
- }
189
- const local = getData('local');
190
- if (local) {
191
- storage = {
192
- ...storage,
193
- ...local,
194
- };
195
- }
196
- data.storage = storage;
197
- return data;
198
- };
199
- async function postRequest(url, data, options) {
200
- if (!url) {
201
- return Promise.reject(new Error('URL is empty'));
202
- }
203
- const payload = getStandardPayload(data);
204
- if (options && options.method === 'beacon' && navigator.sendBeacon) {
205
- return Promise.resolve(beacon(url, payload));
206
- }
207
- return await ajax('POST', url, payload);
208
- }
209
- async function getRequest(url, options) {
210
- if (!url) {
211
- return Promise.reject(new Error('URL is empty'));
212
- }
213
- if (options && options.method === 'beacon' && navigator.sendBeacon) {
214
- return Promise.resolve(beacon(url));
215
- }
216
- return await ajax('GET', url);
217
- }
218
-
219
- const info = (data) => {
220
- {
221
- console.info(data);
222
- }
223
- };
224
-
225
- const saveConsent = (consent) => {
226
- savePerKey('local', tagStorage, consent, consentKey);
227
- };
228
- const handleConsent = (consent) => {
229
- const payload = {
230
- consentString: consent,
231
- };
232
- saveConsent(consent);
233
- postRequest(getConsentURL(), payload).catch(info);
234
- };
235
-
236
- const handleTag = (name, data, providers) => {
237
- let payload = {
238
- eventName: name,
239
- };
240
- if (data) {
241
- payload.data = data;
242
- }
243
- if (providers) {
244
- payload.providers = providers;
245
- }
246
- if (!allowTag(providers)) {
247
- console.log('No consent');
248
- return;
249
- }
250
- postRequest(getTagURL(), payload).catch(info);
251
- };
252
-
253
- const getCookieValue = (key) => {
254
- let name = `${key}=`;
255
- let decodedCookie = decodeURIComponent(document.cookie);
256
- let ca = decodedCookie.split(';');
257
- for (let i = 0; i < ca.length; i++) {
258
- let c = ca[i];
259
- while (c.charAt(0) == ' ') {
260
- c = c.substring(1);
261
- }
262
- if (c.indexOf(name) == 0) {
263
- return c.substring(name.length, c.length);
264
- }
265
- }
266
- return '';
267
- };
268
- const handleCaptureQuery = (provider, key, persistType) => {
269
- const params = new URLSearchParams(window.location.search);
270
- if (!params || !params.get(key)) {
271
- return;
272
- }
273
- saveDataPerKey(persistType, provider, params.get(key), key);
274
- };
275
- const handleCaptureStorage = (provider, location, key, persistType) => {
276
- let data;
277
- switch (location) {
278
- case 'cookie': {
279
- data = getCookieValue(key);
280
- break;
281
- }
282
- case 'local': {
283
- data = sessionStorage.getItem(key);
284
- break;
285
- }
286
- case 'session': {
287
- data = localStorage.getItem(key);
288
- break;
289
- }
290
- }
291
- if (!data) {
292
- return;
293
- }
294
- saveDataPerKey(persistType, provider, data, key);
295
- };
296
- const handleCapture = (provider, params) => {
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
- }
307
- }
308
- });
309
- };
310
-
311
- const handleManifest = (manifest) => {
312
- const providers = [];
313
- manifest.forEach((provider) => {
314
- providers.push(provider.package);
315
- Object.entries(provider.rules).forEach(([name, recipe]) => {
316
- switch (name) {
317
- case 'capture': {
318
- handleCapture(provider.package, recipe);
319
- return;
320
- }
321
- }
322
- });
323
- });
324
- savePerKey('local', tagStorage, providers, providersKey);
325
- };
326
-
327
- const handleInit = (preferences) => {
328
- const success = setPreferences(preferences);
329
- if (!success) {
330
- return;
331
- }
332
- let url = `${getInitURL()}`;
333
- if (preferences.disableConsentCheck) {
334
- url = `${url}?consentDisabled=true`;
335
- saveConsent({ all: true });
336
- }
337
- getRequest(url)
338
- .then((result) => {
339
- if (!result) {
340
- console.log('init failed');
341
- return;
342
- }
343
- handleManifest(result.result);
344
- })
345
- .catch(info);
346
- };
347
-
348
- const init = (preferences) => {
349
- handleInit(preferences);
350
- };
351
- const tag = (name, data, providers) => {
352
- handleTag(name, data, providers);
353
- };
354
- const consent = (consent) => {
355
- handleConsent(consent);
356
- };
357
-
358
- class API {
359
- init(preferences) {
360
- init(preferences);
361
- }
362
-
363
- tag(name, data, providers) {
364
- tag(name, data, providers);
365
- }
366
-
367
- consent(consentString) {
368
- consent(consentString);
369
- }
370
- }
371
-
372
- var api = new API();
373
-
374
- (function () {
375
- const handleFunction = (arg) => {
376
- const sliced = [].slice.call(arg);
377
- if (!Array.isArray(sliced)) {
378
- return
379
- }
380
-
381
- try {
382
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
383
- // @ts-ignore
384
- return library[sliced[0]](...sliced.slice(1))
385
- } catch (e) {
386
- console.error(e);
387
- }
388
- };
389
-
390
- const library = api;
391
- let stubs = [];
392
- if (window.edgetag) {
393
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
394
- // @ts-ignore
395
- stubs = window.edgetag.stubs || [];
396
- }
397
-
398
- // this needs to be regular function for arguments to work
399
- window.edgetag = function () {
400
- // eslint-disable-next-line prefer-rest-params
401
- return handleFunction(arguments)
402
- };
403
-
404
- // restore calls that were triggered before lib was ready
405
- stubs.forEach(handleFunction);
406
- })();
407
-
408
- }));
package/index.min.js DELETED
@@ -1 +0,0 @@
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 DELETED
Binary file