@blotoutio/edgetag-sdk-browser 0.5.0 → 0.5.2

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 (2) hide show
  1. package/index.cjs +1 -1
  2. package/package.json +1 -1
package/index.cjs CHANGED
@@ -1 +1 @@
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)}()}();
1
+ !function(){"use strict";function e(e,t,n,s){return new(n||(n=Promise))((function(o,r){function a(e){try{i(s.next(e))}catch(e){r(e)}}function c(e){try{i(s.throw(e))}catch(e){r(e)}}function i(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,c)}i((s=s.apply(e,t||[])).next())}))}const t="edgeTag",n="consent",s="providers",o="_workerStore",r=(e,t,n,s)=>{const o=l(e);o.data||(o.data={}),o.data[t]||(o.data[t]={}),o.data[t][s]=n,i(e,o)},a=(e,t,n,s)=>{const o=l(e);o[t]||(o[t]={}),o[t][s]=n,i(e,o)},c=(e,t,n)=>{const s=l(e);if(s[t])return s[t][n]},i=(e,t,n=o)=>{"session"!==e?d(t,n):f(t,n)},l=(e,t=o)=>"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 o=c("local",t,n);if(b)return!0;if(!o)return!1;if(o.all)return!0;if(!e)return Object.values(o).find((e=>e))||!1;const r=c("local",t,s)||[];for(const t of r){const n=e[t];if((n||!0===e.all&&void 0===n||!1===e.all&&!0===n)&&o[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,s)=>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(s),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 P(t,n,s){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 s=l("session");s&&(n=Object.assign(Object.assign({},n),s));const o=l("local");return o&&(n=Object.assign(Object.assign({},n),o)),t.storage=n,t})(n);return s&&"beacon"===s.method?Promise.resolve(j(t,e)):yield O("POST",t,e)}))}function S(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=>{},U=e=>{a("local",t,e,n)},E=e=>{const t={consentString:e};U(e),P(y("/consent"),t).catch(I)},R=(e,t,n,s)=>{const o={eventName:e};t&&(o.data=t),n&&(o.providers=n),k(n)?P(y("/tag"),o,s).catch(I):console.log("No consent")},A=(e,t,n,s)=>{let o;switch(s){case"cookie":o=(e=>{const t=`${e}=`,n=decodeURIComponent(document.cookie).split(";");for(let e=0;e<n.length;e++){let s=n[e];for(;" "===s.charAt(0);)s=s.substring(1);if(0===s.indexOf(t))return s.substring(t.length,s.length)}return""})(t);break;case"local":o=sessionStorage.getItem(t);break;case"session":o=localStorage.getItem(t)}o&&r(n,e,o,t)},N=(e,t)=>{t.forEach((t=>{switch(t.type){case"query":((e,t,n)=>{const s=new URLSearchParams(window.location.search);s&&s.get(t)&&r(n,e,s.get(t),t)})(e,t.key,t.persist);break;case"storage":A(e,t.key,t.persist,t.location)}}))},L=e=>{if(!m(e))return;const n=new URL(y("/init"));e.disableConsentCheck&&(n.searchParams.set("consentDisabled","true"),U({all:!0})),e.userId&&n.searchParams.set("userId",e.userId),S(n.href).then((e=>{e?(e=>{const n=[];e.forEach((e=>{n.push(e.package),e.rules&&Object.entries(e.rules).forEach((([t,n])=>{"capture"!==t||N(e.package,n)}))})),a("local",t,n,s)})(e.result):console.log("init failed")})).catch(I)},C=(e,t,n)=>{e&&t?(u({[e]:t}),P(y("/user"),{key:e,value:t},n).catch(I)):console.error("Key or Value is missing in user API.")},J=(e,t)=>{e&&0!==Object.keys(e).length?(u(e),P(y("/data"),{data:e},t).catch(I)):console.error("Provide data for data API.")},$=(e,t)=>{e&&0!==e.length?S((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=>{S(y("/keys")).then((t=>{e((null==t?void 0:t.result)||[])})).catch(I)};var x=new class{init(e){(e=>{L(e)})(e)}tag(e,t,n,s){((e,t,n,s)=>{R(e,t,n,s)})(e,t,n,s)}consent(e){(e=>{E(e)})(e)}user(e,t,n){((e,t,n)=>{C(e,t,n)})(e,t,n)}data(e,t){((e,t)=>{J(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.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "Browser SDK for EdgeTag",
5
5
  "author": "Blotout",
6
6
  "license": "MIT",