@blotoutio/edgetag-sdk-browser 0.4.1 → 0.5.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.cjs +1 -1
- package/package.json +2 -4
- package/index.js +0 -1
package/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";function e(e,t,n,o){return new(n||(n=Promise))((function(s,r){function a(e){try{i(o.next(e))}catch(e){r(e)}}function c(e){try{i(o.throw(e))}catch(e){r(e)}}function i(e){var t;e.done?s(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
|
|
1
|
+
!function(){"use strict";function e(e,t,n,o){return new(n||(n=Promise))((function(s,r){function a(e){try{i(o.next(e))}catch(e){r(e)}}function c(e){try{i(o.throw(e))}catch(e){r(e)}}function i(e){var t;e.done?s(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="edgeTag",n="consent",o="providers",s="_workerStore",r=(e,t,n,o)=>{const s=l(e);s.data||(s.data={}),s.data[t]||(s.data[t]={}),s.data[t][o]=n,i(e,s)},a=(e,t,n,o)=>{const s=l(e);s[t]||(s[t]={}),s[t][o]=n,i(e,s)},c=(e,t,n)=>{const o=l(e);if(o[t])return o[t][n]},i=(e,t,n=s)=>{"session"!==e?d(t,n):f(t,n)},l=(e,t=s)=>"session"===e?h(t):g(t),u=e=>{let t=l("session");t||(t={}),t.kv||(t.kv={}),t.kv=Object.assign(Object.assign({},t.kv),e),i("session",t)},d=(e,t)=>{localStorage.setItem(t,JSON.stringify(e))},g=e=>{const t=localStorage.getItem(e);return t&&JSON.parse(t)||{}},f=(e,t)=>{sessionStorage.setItem(t,JSON.stringify(e))},h=e=>{const t=sessionStorage.getItem(e);return t&&JSON.parse(t)||{}};let v="";const y=e=>{const t=p();return t?`${t}${e}`:(console.log("URL is not valid"),"")},p=()=>v;let b=!1;const m=e=>{return!!e&&(e.edgeURL?(b=!!e.disableConsentCheck,null!=(t=e.edgeURL)&&(v=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},k=e=>{const s=c("local",t,n);if(b)return!0;if(!s)return!1;if(s.all)return!0;if(!e)return Object.values(s).find((e=>e))||!1;const r=c("local",t,o)||[];for(const t of r){const n=e[t];if((n||!0===e.all&&void 0===n||!1===e.all&&!0===n)&&s[t])return!0}return!1},j=(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 S(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:w()},e||{});let n={};const o=l("session");o&&(n=Object.assign(Object.assign({},n),o));const s=l("local");return s&&(n=Object.assign(Object.assign({},n),s)),t.storage=n,t})(n);return o&&"beacon"===o.method?Promise.resolve(j(t,e)):yield O("POST",t,e)}))}function P(t,n){return e(this,void 0,void 0,(function*(){return t?n&&"beacon"===n.method?{result:Promise.resolve(j(t))}:yield O("GET",t):Promise.reject(new Error("URL is empty"))}))}const I=e=>{},E=e=>{a("local",t,e,n)},U=e=>{const t={consentString:e};E(e),S(y("/consent"),t).catch(I)},A=(e,t,n,o)=>{const s={eventName:e};t&&(s.data=t),n&&(s.providers=n),k(n)?S(y("/tag"),s,o).catch(I):console.log("No consent")},N=(e,t,n,o)=>{let s;switch(o){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""})(t);break;case"local":s=sessionStorage.getItem(t);break;case"session":s=localStorage.getItem(t)}s&&r(n,e,s,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)&&r(n,e,o.get(t),t)})(e,t.key,t.persist);break;case"storage":N(e,t.key,t.persist,t.location)}}))},C=e=>{if(!m(e))return;let n=`${y("/init")}`;e.disableConsentCheck&&(n=`${n}?consentDisabled=true`,E({all:!0})),P(n).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)}))})),a("local",t,n,o)})(e.result):console.log("init failed")})).catch(I)},J=(e,t,n)=>{e&&t?(u({[e]:t}),S(y("/user"),{key:e,value:t},n).catch(I)):console.error("Key or Value is missing in user API.")},L=(e,t)=>{e&&0!==Object.keys(e).length?(u(e),S(y("/data"),{data:e},t).catch(I)):console.error("Provide data for data API.")},$=(e,t)=>{e&&0!==e.length?P((e=>y(`/data?keys=${encodeURIComponent(e.join(","))}`))(e)).then((e=>{t((null==e?void 0:e.result)||{})})).catch(I):console.error("Provide keys for get data API.")},T=e=>{P(y("/keys")).then((t=>{e((null==t?void 0:t.result)||[])})).catch(I)};var x=new class{init(e){(e=>{C(e)})(e)}tag(e,t,n,o){((e,t,n,o)=>{A(e,t,n,o)})(e,t,n,o)}consent(e){(e=>{U(e)})(e)}user(e,t,n){((e,t,n)=>{J(e,t,n)})(e,t,n)}data(e,t){((e,t)=>{L(e,t)})(e,t)}getData(e,t){((e,t)=>{$(e,t)})(e,t)}keys(e){(e=>{T(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=x;let n=[];window.edgetag&&(n=window.edgetag.stubs||[]),window.edgetag=function(){return e(arguments)},n.forEach(e)}()}();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blotoutio/edgetag-sdk-browser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Browser SDK for EdgeTag",
|
|
5
5
|
"author": "Blotout",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,14 +18,12 @@
|
|
|
18
18
|
"package.json",
|
|
19
19
|
"README.md"
|
|
20
20
|
],
|
|
21
|
-
"module": "./index.js",
|
|
22
21
|
"main": "./index.cjs",
|
|
23
|
-
"type": "
|
|
22
|
+
"type": "commonjs",
|
|
24
23
|
"types": "./index.d.ts",
|
|
25
24
|
"exports": {
|
|
26
25
|
".": {
|
|
27
26
|
"types": "./index.d.ts",
|
|
28
|
-
"import": "./index.js",
|
|
29
27
|
"require": "./index.cjs"
|
|
30
28
|
}
|
|
31
29
|
}
|
package/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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?c(t,n):l(t,n)},s=(e,t="_workerStore")=>"session"===e?d(t):i(t),a=e=>{let t=s("session");t||(t={}),t.data||(t.data={}),t.data=Object.assign(Object.assign({},t.data),e),r("session",t)},c=(e,t)=>{localStorage.setItem(t,JSON.stringify(e))},i=e=>{const t=localStorage.getItem(e);return t&&JSON.parse(t)||{}},l=(e,t)=>{sessionStorage.setItem(t,JSON.stringify(e))},d=e=>{const t=sessionStorage.getItem(e);return t&&JSON.parse(t)||{}};let u="";const g=e=>{const t=f();return t?`${t}${e}`:(console.log("URL is not valid"),"")},f=()=>u;let h=!1;const y=e=>{return!!e&&(e.edgeURL?(h=!!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(h)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},b=(e,t)=>{let n;return t&&(n=new Blob([JSON.stringify(t)],{type:"application/json"})),navigator.sendBeacon(e,n)},m=(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 w(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?Promise.resolve(b(t,e)):yield m("POST",t,e)}))}function j(t,n){return e(this,void 0,void 0,(function*(){return t?n&&"beacon"===n.method?{result:Promise.resolve(b(t))}:yield m("GET",t):Promise.reject(new Error("URL is empty"))}))}const k=e=>{},O=e=>{n("local","edgeTag",e,"consent")},S=e=>{const t={consentString:e};O(e),w(g("/consent"),t).catch(k)},P=(e,t,n)=>{const o={eventName:e};t&&(o.data=t),n&&(o.providers=n),p(n)?w(g("/tag"),o).catch(k):console.log("No consent")},I=(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)},E=(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":I(e,n.key,n.persist,n.location)}}))},U=e=>{if(!y(e))return;let t=`${g("/init")}`;e.disableConsentCheck&&(t=`${t}?consentDisabled=true`,O({all:!0})),j(t).then((e=>{e?(e=>{const t=[];e.forEach((e=>{t.push(e.package),Object.entries(e.rules).forEach((([t,n])=>{"capture"!==t||E(e.package,n)}))})),n("local","edgeTag",t,"providers")})(e.result):console.log("init failed")})).catch(k)},A=(e,t)=>{e&&t?(a({[e]:t}),w(g("/user"),{key:e,value:t}).catch(k)):console.error("Key or Value is missing in user API.")},N=e=>{e&&0!==Object.keys(e).length?(a(e),w(g("/data"),{data:e}).catch(k)):console.error("Provide data for data API.")},R=(e,t)=>{e&&0!==e.length?j((e=>g(`/data?keys=${encodeURIComponent(e.join(","))}`))(e)).then((e=>{t((null==e?void 0:e.result)||{})})).catch(k):console.error("Provide keys for get data API.")},C=e=>{j(g("/keys")).then((t=>{e((null==t?void 0:t.result)||[])})).catch(k)};var J=new class{init(e){(e=>{U(e)})(e)}tag(e,t,n){((e,t,n)=>{P(e,t,n)})(e,t,n)}consent(e){(e=>{S(e)})(e)}user(e,t){((e,t)=>{A(e,t)})(e,t)}data(e){(e=>{N(e)})(e)}getData(e,t){((e,t)=>{R(e,t)})(e,t)}keys(e){(e=>{C(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=J;let n=[];window.edgetag&&(n=window.edgetag.stubs||[]),window.edgetag=function(){return e(arguments)},n.forEach(e)}();
|