New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@blotoutio/edgetag-sdk-js

Package Overview
Dependencies
Maintainers
0
Versions
165
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@blotoutio/edgetag-sdk-js - npm Package Compare versions

Comparing version 0.51.1 to 0.52.0

1070

index.cjs.js

@@ -18,8 +18,171 @@ 'use strict';

const _config = {};
const setConfig$1 = (config) => {
Object.assign(_config, config);
const isBool = (v) => typeof v == 'boolean';
const isRecord = (v) => !!v && typeof v == 'object' && !Array.isArray(v);
/**
* This function validates user consent for a given provider and tag name.
* It should be used in conjunction with `UserConsent`, not `ProvidersConfig`.
*/
const hasUserConsent = (consent, provider, tagName) => {
if (!isRecord(consent)) {
return false;
}
let allowed = isBool(consent.all) ? consent.all : false;
if (provider in consent) {
const providerSpecific = consent[provider];
if (isBool(providerSpecific)) {
allowed = providerSpecific;
}
else if (isRecord(providerSpecific)) {
if ('all' in providerSpecific && isBool(providerSpecific.all)) {
allowed = providerSpecific.all;
}
if (tagName in providerSpecific && isBool(providerSpecific[tagName])) {
allowed = providerSpecific[tagName];
}
}
}
return allowed;
};
const getConfig = () => _config;
/**
* This function validates user consent for a given provider type, not based on tagName.
*/
const hasUserConsentForProvider = (consent, provider) => {
if (!isRecord(consent)) {
return false;
}
let allowed = isBool(consent.all) ? consent.all : false;
if (provider in consent) {
const providerSpecific = consent[provider];
if (isBool(providerSpecific)) {
allowed = providerSpecific;
}
else if (isRecord(providerSpecific)) {
return Object.keys(providerSpecific).some((instance) => providerSpecific[instance] === true);
}
}
return allowed;
};
/**
* This function validates provider allowance for a given provider and tag name.
* It should not be used to validate `UserConsent`.
*/
const isProviderInstanceAllowed = (providersConfig, provider, tagName) => {
if (!isRecord(providersConfig)) {
return true;
}
if (provider in providersConfig) {
const providerSpecific = providersConfig[provider];
if (isBool(providerSpecific)) {
return providerSpecific;
}
if (isRecord(providerSpecific)) {
const tagKeys = Object.keys(providerSpecific).filter((k) => k != 'all');
if (tagName in providerSpecific && isBool(providerSpecific[tagName])) {
return providerSpecific[tagName];
}
return isBool(providerSpecific.all)
? providerSpecific.all
: tagKeys.length == 0;
}
}
const providerKeys = Object.keys(providersConfig).filter((k) => k != 'all');
return isBool(providersConfig.all)
? providersConfig.all
: providerKeys.length == 0;
};
const upsert = (map, key, update, createDefault) => {
const currentValue = map.has(key)
? map.get(key)
: createDefault();
return map.set(key, update(currentValue));
};
const expand = (str) => str.split(',').flatMap((entry) => {
if (!entry.includes('-')) {
return entry;
}
const result = [];
const [start, end] = entry.split('-').map(Number);
for (let i = start; i <= end; i++) {
result.push(i.toString());
}
return result;
});
/**
* Exported from https://en.wikipedia.org/wiki/List_of_North_American_Numbering_Plan_area_codes
*
* In Dev Tools, select the `tbody` element containing the area codes and run the following code,
* replacing the emdash character with a simple endash:
*
* ```ts
* [...$0.querySelectorAll('td:first-child')]
* .filter(cell => cell.firstChild.nodeName != 'A')
* .map(cell => cell.textContent.trim()).join(',')
* ```
*/
new Set([
...expand('200,211,221,222,230,232,233,235,237-238,241,243,244,245,247,255,257,258-259,261,265,266,271,273,274,275,277,278,280,282,283,285-287,288,290-299'),
...expand('300,311,322,324,327,328,333,335,338,342,344,348-349,353,355,356,357-359,362,366,369,370-379,381,382,383-384,387,388,389,390-399'),
...expand('400,411,420,421-422,426-427,428,429,433,439,444,446,449,451-454,455,456,457,459,460,461-462,465,466,467,471,476,477,481-483,485-486,487,488,489,490-499'),
...expand('511,532,535,536,537,538,542-543,545-547,549-550,552-554,555,556,558,560,565,568,569,576,578,583,589,590-599'),
...expand('611,621,624,625,627,632,633,634-635,637-638,642-643,644,648,652-654,655,663,665,666,668,673-676,677,679,685,686,687,688,690-699'),
...expand('711,722,723,729,733,735-736,739,741,744,745-746,748,749-751,752,755,756,759,761,764,766,768,776,777,783,788,789,790-799'),
...expand('811,821,822,823-824,827,834,836,841-842,846,851,852-853,871,874-875,879,880-887,889,890-899'),
...expand('911,921,922,923,924,926,927,932,933,935,942,944,946,950,953,955,957-958,960-969,974,975,976,977,981-982,987,988,990-999'),
]);
// eslint-disable-next-line @nx/enforce-module-boundaries
let edgeTagSettings;
const initSettings = (destination, options) => {
if (!edgeTagSettings) {
edgeTagSettings = {};
}
edgeTagSettings[destination] = {
destination,
initialized: false,
stubs: [],
channels: new Map(),
...options,
};
};
const setSetting = (options, destination) => {
if (!edgeTagSettings) {
return;
}
if (!destination) {
Object.keys(edgeTagSettings).forEach((key) => {
edgeTagSettings[key] = {
...edgeTagSettings[key],
...options,
};
});
return;
}
edgeTagSettings[destination] = {
...edgeTagSettings[destination],
...options,
};
};
const getSetting = (destination, key) => {
var _a;
return (_a = edgeTagSettings === null || edgeTagSettings === void 0 ? void 0 : edgeTagSettings[destination]) === null || _a === void 0 ? void 0 : _a[key];
};
const getInstances = () => {
return Object.keys(edgeTagSettings || {});
};
const addChannel = (destination, pkg, tagName) => upsert(getSetting(destination, 'channels'), pkg, (names) => names.add(tagName), () => new Set());
const getProviderVariables = (destination, packageId) => {
const setting = getSetting(destination, 'packages');
if (!setting) {
return [];
}
return (setting
.filter((pkg) => pkg.package === packageId)
.map((pkg) => ({
tagName: pkg.tagName,
variableSet: pkg.variables || {},
})) || []);
};
const getUserAgent = () => {

@@ -34,7 +197,7 @@ try {

};
const getReferrer = () => {
const getReferrer = (destination) => {
let referrer = '';
try {
const referrerUrl = new URL(document.referrer);
const pageUrl = new URL(getPageUrl());
const pageUrl = new URL(getPageUrl(destination));
if (referrerUrl.host !== pageUrl.host) {

@@ -49,3 +212,3 @@ referrer = referrerUrl.href;

};
const getPageUrl = () => {
const getPageUrl = (destination) => {
try {

@@ -56,4 +219,4 @@ // we need to leave this one in for existing Custom pixel customers

}
const { pageUrl } = getConfig();
return pageUrl || window.location.href;
const config = getSetting(destination, 'config');
return (config === null || config === void 0 ? void 0 : config.pageUrl) || window.location.href;
}

@@ -64,5 +227,5 @@ catch {

};
const getSearch = () => {
const getSearch = (destination) => {
try {
return new URL(getPageUrl()).search;
return new URL(getPageUrl(destination)).search;
}

@@ -120,3 +283,2 @@ catch {

const keyPrefix = `_worker`;
const cookieKey = 'tag_user_id';

@@ -155,5 +317,5 @@ const getMessage = (error) => {

const initKey = `${keyPrefix}Store`;
const saveDataPerKey = (persistType, provider, value, key) => {
const storage = getData$1(persistType);
const initKey = `${keyPrefix}StoreMultiple`;
const saveDataPerKey = (destination, persistType, provider, value, key) => {
const storage = getData$1(destination, persistType);
if (!storage['data']) {

@@ -166,6 +328,17 @@ storage['data'] = {};

storage['data'][provider][key] = value;
saveData(persistType, storage);
saveData(destination, persistType, storage);
};
const savePerKey = (persistType, provider, value, key) => {
const storage = getData$1(persistType);
const saveKV = (destination, data) => {
const currentSession = getData$1(destination, 'session');
if (!currentSession['kv']) {
currentSession['kv'] = {};
}
currentSession['kv'] = {
...currentSession['kv'],
...data,
};
saveData(destination, 'session', currentSession);
};
const savePerKey = (destination, persistType, provider, value, key) => {
const storage = getData$1(destination, persistType);
if (!storage[provider]) {

@@ -175,6 +348,6 @@ storage[provider] = {};

storage[provider][key] = value;
saveData(persistType, storage);
saveData(destination, persistType, storage);
};
const getDataPerKey = (persistType, provider, key) => {
const storage = getData$1(persistType);
const getDataPerKey = (destination, persistType, provider, key) => {
const storage = getData$1(destination, persistType);
if (!storage[provider]) {

@@ -185,28 +358,22 @@ return undefined;

};
const saveData = (persistType, value, key = initKey) => {
const saveData = (destination, persistType, value, key = initKey) => {
if (persistType === 'session') {
saveSession(value, key);
const data = getSession(key);
data[destination] = value;
saveSession(data, key);
return;
}
saveLocal(value, key);
const data = getLocal(key);
data[destination] = value;
saveLocal(data, key);
};
const getData$1 = (persistType, key = initKey) => {
const getData$1 = (destination, persistType, key = initKey) => {
let data;
if (persistType === 'session') {
return getSession(key);
data = getSession(key);
}
return getLocal(key);
};
const saveKV = (data) => {
let currentSession = getData$1('session');
if (!currentSession) {
currentSession = {};
else {
data = getLocal(key);
}
if (!currentSession['kv']) {
currentSession['kv'] = {};
}
currentSession['kv'] = {
...currentSession['kv'],
...data,
};
saveData('session', currentSession);
return (data === null || data === void 0 ? void 0 : data[destination]) || {};
};

@@ -266,83 +433,17 @@ const saveLocal = (value, key) => {

const encodeString = (name) => {
if (typeof btoa === 'undefined') {
return Buffer.from(name).toString('base64');
}
return btoa(name);
const getUserId$1 = (destination) => {
return getSetting(destination, 'userId');
};
const getBasicRandomNumber = () => {
return parseInt((Math.random() * 10000000000).toString(), 10);
};
const generateUUID = () => {
let id = '';
try {
id = crypto.randomUUID();
if (!id) {
const array = new Uint32Array(20);
const numbers = crypto.getRandomValues(array);
for (let i = 0; i < 5; i++) {
const y = i * 3;
if (i !== 0) {
id += '-';
}
const sum = numbers[y + 1] + numbers[y + 2] + numbers[y + 3];
id += sum.toString();
}
}
const handleGetUserId = (options) => {
if (options === null || options === void 0 ? void 0 : options.destination) {
return getUserId$1(options.destination);
}
catch {
id = `${getBasicRandomNumber()}-${getBasicRandomNumber()}-${getBasicRandomNumber()}-${getBasicRandomNumber()}-${getBasicRandomNumber()}`;
console.log('[EdgeTag] Crypto module not found');
const instances = getInstances();
if (instances.length > 1) {
error('Multiple instances detected! Please provide a destination.');
return null;
}
return id;
return getUserId$1(instances[0]);
};
const generateEventId = (name) => {
let time = Date.now().toString();
if (typeof performance !== 'undefined' &&
typeof performance.now === 'function') {
const perf = performance.now();
if (perf) {
time = perf.toFixed(4);
}
}
return `${encodeString(name)}-${generateUUID()}-${time}`;
};
const getCookieValue = (key) => {
try {
if (!document || !document.cookie) {
return '';
}
const name = `${key}=`;
const decodedCookie = decodeURIComponent(document.cookie);
const ca = decodedCookie.split(';');
for (let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) === ' ') {
c = c.substring(1);
}
if (c.indexOf(name) === 0) {
return c.substring(name.length, c.length);
}
}
return '';
}
catch {
return '';
}
};
let initUserId = '';
const handleGetUserId = () => {
if (initUserId) {
return initUserId;
}
// leaving this for backward compatibility as worker was maybe not updated yet
// reference https://github.com/blotoutio/solutions/issues/1960
return getCookieValue(cookieKey);
};
const setUserId = (userId) => {
initUserId = userId;
};
const beacon = (url, payload) => {

@@ -360,3 +461,3 @@ try {

};
const ajax = (method, url, payload) => fetch(url, {
const ajax = (destination, method, url, payload) => fetch(url, {
method,

@@ -366,3 +467,3 @@ headers: {

Accept: 'application/json; charset=utf-8',
EdgeTagUserId: handleGetUserId(),
EdgeTagUserId: getUserId$1(destination),
},

@@ -381,15 +482,15 @@ body: JSON.stringify(payload),

});
const getStandardPayload = (payload) => {
const getStandardPayload = (destination, payload) => {
const data = {
pageUrl: getPageUrl(),
pageUrl: getPageUrl(destination),
pageTitle: getPageTitle(),
userAgent: getUserAgent(),
referrer: getReferrer(),
search: getSearch(),
referrer: getReferrer(destination),
search: getSearch(destination),
locale: getLocale(),
sdkVersion: "0.51.1" ,
sdkVersion: "0.52.0" ,
...(payload || {}),
};
let storage = {};
const session = getData$1('session');
const session = getData$1(destination, 'session');
if (session) {

@@ -401,3 +502,3 @@ storage = {

}
const local = getData$1('local');
const local = getData$1(destination, 'local');
if (local) {

@@ -416,7 +517,9 @@ storage = {

}
const payload = getStandardPayload(data);
const parsedUrl = new URL(url);
const destination = parsedUrl.origin;
const payload = getStandardPayload(destination, data);
if (options && options.method === 'beacon') {
return Promise.resolve(beacon(url, payload));
}
return await ajax('POST', url, payload);
return await ajax(destination, 'POST', url, payload);
}

@@ -432,166 +535,40 @@ async function getRequest(url, options) {

}
return await ajax('GET', url);
const parsedUrl = new URL(url);
const destination = parsedUrl.origin;
return await ajax(destination, 'GET', url);
}
let endpointUrl = '';
const generateUrl = (path) => {
const endpoint = getUrl();
if (!endpoint) {
const generateUrl = (destination, path) => {
if (!destination) {
log('URL is not valid');
return '';
}
return `${endpoint}${path}`;
return `${destination}${path}`;
};
const getUrl = () => {
return endpointUrl;
};
const setUrl = (url) => {
if (url == null) {
return;
}
endpointUrl = url;
};
const getTagURL = (options) => {
const url = new URL(generateUrl('/tag'));
const getTagURL = (destination, options) => {
const parsedUrl = new URL(generateUrl(destination, '/tag'));
if (options === null || options === void 0 ? void 0 : options.sync) {
url.searchParams.set('sync', 'true');
parsedUrl.searchParams.set('sync', 'true');
}
return url.toString();
return parsedUrl.toString();
};
const getInitURL = () => {
return generateUrl('/init');
const getInitURL = (destination) => {
return generateUrl(destination, '/init');
};
const getConsentURL = () => {
return generateUrl('/consent');
const getConsentURL = (destination) => {
return generateUrl(destination, '/consent');
};
const getUserURL = () => {
return generateUrl('/user');
const getUserURL = (destination) => {
return generateUrl(destination, '/user');
};
const getDataURL = () => {
return generateUrl(`/data`);
const getDataURL = (destination) => {
return generateUrl(destination, `/data`);
};
const getGetDataURL = (keys) => {
return generateUrl(`/data?keys=${encodeURIComponent(keys.join(','))}`);
const getGetDataURL = (destination, keys) => {
return generateUrl(destination, `/data?keys=${encodeURIComponent(keys.join(','))}`);
};
const getKeysURL = () => {
return generateUrl(`/keys`);
const getKeysURL = (destination) => {
return generateUrl(destination, `/keys`);
};
const isBool = (v) => typeof v == 'boolean';
const isRecord = (v) => !!v && typeof v == 'object' && !Array.isArray(v);
/**
* This function validates user consent for a given provider and tag name.
* It should be used in conjunction with `UserConsent`, not `ProvidersConfig`.
*/
const hasUserConsent = (consent, provider, tagName) => {
if (!isRecord(consent)) {
return false;
}
let allowed = isBool(consent.all) ? consent.all : false;
if (provider in consent) {
const providerSpecific = consent[provider];
if (isBool(providerSpecific)) {
allowed = providerSpecific;
}
else if (isRecord(providerSpecific)) {
if ('all' in providerSpecific && isBool(providerSpecific.all)) {
allowed = providerSpecific.all;
}
if (tagName in providerSpecific && isBool(providerSpecific[tagName])) {
allowed = providerSpecific[tagName];
}
}
}
return allowed;
};
/**
* This function validates user consent for a given provider type, not based on tagName.
*/
const hasUserConsentForProvider = (consent, provider) => {
if (!isRecord(consent)) {
return false;
}
let allowed = isBool(consent.all) ? consent.all : false;
if (provider in consent) {
const providerSpecific = consent[provider];
if (isBool(providerSpecific)) {
allowed = providerSpecific;
}
else if (isRecord(providerSpecific)) {
return Object.keys(providerSpecific).some((instance) => providerSpecific[instance] === true);
}
}
return allowed;
};
/**
* This function validates provider allowance for a given provider and tag name.
* It should not be used to validate `UserConsent`.
*/
const isProviderInstanceAllowed = (providersConfig, provider, tagName) => {
if (!isRecord(providersConfig)) {
return true;
}
if (provider in providersConfig) {
const providerSpecific = providersConfig[provider];
if (isBool(providerSpecific)) {
return providerSpecific;
}
if (isRecord(providerSpecific)) {
const tagKeys = Object.keys(providerSpecific).filter((k) => k != 'all');
if (tagName in providerSpecific && isBool(providerSpecific[tagName])) {
return providerSpecific[tagName];
}
return isBool(providerSpecific.all)
? providerSpecific.all
: tagKeys.length == 0;
}
}
const providerKeys = Object.keys(providersConfig).filter((k) => k != 'all');
return isBool(providersConfig.all)
? providersConfig.all
: providerKeys.length == 0;
};
const upsert = (map, key, update, createDefault) => {
const currentValue = map.has(key)
? map.get(key)
: createDefault();
return map.set(key, update(currentValue));
};
const expand = (str) => str.split(',').flatMap((entry) => {
if (!entry.includes('-')) {
return entry;
}
const result = [];
const [start, end] = entry.split('-').map(Number);
for (let i = start; i <= end; i++) {
result.push(i.toString());
}
return result;
});
/**
* Exported from https://en.wikipedia.org/wiki/List_of_North_American_Numbering_Plan_area_codes
*
* In Dev Tools, select the `tbody` element containing the area codes and run the following code,
* replacing the emdash character with a simple endash:
*
* ```ts
* [...$0.querySelectorAll('td:first-child')]
* .filter(cell => cell.firstChild.nodeName != 'A')
* .map(cell => cell.textContent.trim()).join(',')
* ```
*/
new Set([
...expand('200,211,221,222,230,232,233,235,237-238,241,243,244,245,247,255,257,258-259,261,265,266,271,273,274,275,277,278,280,282,283,285-287,288,290-299'),
...expand('300,311,322,324,327,328,333,335,338,342,344,348-349,353,355,356,357-359,362,366,369,370-379,381,382,383-384,387,388,389,390-399'),
...expand('400,411,420,421-422,426-427,428,429,433,439,444,446,449,451-454,455,456,457,459,460,461-462,465,466,467,471,476,477,481-483,485-486,487,488,489,490-499'),
...expand('511,532,535,536,537,538,542-543,545-547,549-550,552-554,555,556,558,560,565,568,569,576,578,583,589,590-599'),
...expand('611,621,624,625,627,632,633,634-635,637-638,642-643,644,648,652-654,655,663,665,666,668,673-676,677,679,685,686,687,688,690-699'),
...expand('711,722,723,729,733,735-736,739,741,744,745-746,748,749-751,752,755,756,759,761,764,766,768,776,777,783,788,789,790-799'),
...expand('811,821,822,823-824,827,834,836,841-842,846,851,852-853,871,874-875,879,880-887,889,890-899'),
...expand('911,921,922,923,924,926,927,932,933,935,942,944,946,950,953,955,957-958,960-969,974,975,976,977,981-982,987,988,990-999'),
]);
let initialized = false;
const providersPackages = {};

@@ -607,3 +584,2 @@ const setPreferences = (preferences) => {

}
!!preferences.disableConsentCheck;
(_a = preferences.providers) === null || _a === void 0 ? void 0 : _a.forEach((provider) => {

@@ -628,41 +604,105 @@ if (!provider.name) {

}
setUrl(preferences.edgeURL);
initSettings(preferences.edgeURL, {
disableConsent: !!preferences.disableConsentCheck,
});
return true;
};
const getProvidersPackage = () => providersPackages;
const isInitialized = () => initialized;
const setInitialized = () => {
initialized = true;
const getProvidersPackage = (destination) => {
const packages = getSetting(destination, 'packages');
const providers = [];
packages === null || packages === void 0 ? void 0 : packages.forEach((pkg) => {
const provider = providersPackages[pkg.package];
if (!provider) {
return;
}
providers.push(provider);
});
return providers;
};
const configuredTags = new Map();
const addConfiguredTag = (pkg, tagName) => upsert(configuredTags, pkg, (names) => names.add(tagName), () => new Set());
const getConfiguredTags = () => configuredTags;
const manifestVariables = {};
const addProviderVariable = (name, variables, tagName) => {
manifestVariables[name] = {
...manifestVariables[name],
[tagName]: variables || {},
};
const encodeString = (name) => {
if (typeof btoa === 'undefined') {
return Buffer.from(name).toString('base64');
}
return btoa(name);
};
const getProviderVariables = (name) => {
if (!name) {
return {};
const getBasicRandomNumber = () => {
return parseInt((Math.random() * 10000000000).toString(), 10);
};
const generateUUID = () => {
let id = '';
try {
id = crypto.randomUUID();
if (!id) {
const array = new Uint32Array(20);
const numbers = crypto.getRandomValues(array);
for (let i = 0; i < 5; i++) {
const y = i * 3;
if (i !== 0) {
id += '-';
}
const sum = numbers[y + 1] + numbers[y + 2] + numbers[y + 3];
id += sum.toString();
}
}
}
return manifestVariables[name] || {};
catch {
id = `${getBasicRandomNumber()}-${getBasicRandomNumber()}-${getBasicRandomNumber()}-${getBasicRandomNumber()}-${getBasicRandomNumber()}`;
console.log('[EdgeTag] Crypto module not found');
}
return id;
};
const generateEventId = (name) => {
let time = Date.now().toString();
if (typeof performance !== 'undefined' &&
typeof performance.now === 'function') {
const perf = performance.now();
if (perf) {
time = perf.toFixed(4);
}
}
return `${encodeString(name)}-${generateUUID()}-${time}`;
};
let stubs = [];
const addStubs = (newStubs) => {
stubs = [...stubs, ...newStubs];
const getCookieValue = (key) => {
try {
if (!document || !document.cookie) {
return '';
}
const name = `${key}=`;
const decodedCookie = decodeURIComponent(document.cookie);
const ca = decodedCookie.split(';');
for (let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) === ' ') {
c = c.substring(1);
}
if (c.indexOf(name) === 0) {
return c.substring(name.length, c.length);
}
}
return '';
}
catch {
return '';
}
};
const addStub = (stub) => {
stubs.push(stub);
const getConsent$1 = (destination) => {
const storageConsent = getDataPerKey(destination, 'local', tagStorage, consentKey);
if (storageConsent) {
return storageConsent;
}
return getSetting(destination, 'consent');
};
const processStubs = () => {
const processStubs = (destination) => {
try {
const stubs = getSetting(destination, 'stubs');
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
stubs.forEach((stub) => api[stub.name](...(stub.arguments || [])));
stubs = [];
setSetting({
stubs: [],
}, destination);
}

@@ -673,4 +713,10 @@ catch (e) {

};
const addStub = (destination, stub) => {
const otherStubs = getSetting(destination, 'stubs') || [];
setSetting({
stubs: [...otherStubs, stub],
}, destination);
};
const sendTag = ({ eventName, eventId, data, providerData, providers, options, }) => {
const sendTag = (destination, { eventName, eventId, data, providerData, providers, options }) => {
const payload = {

@@ -686,7 +732,7 @@ eventName,

}
postRequest(getTagURL(options), payload, options).catch(error);
postRequest(getTagURL(destination, options), payload, options).catch(error);
};
const handleTag = (eventName, data = {}, providers, options) => {
if (!isInitialized()) {
addStub({
const processTag = (destination, eventName, data = {}, providers, options) => {
if (!getSetting(destination, 'initialized')) {
addStub(destination, {
name: 'tag',

@@ -701,7 +747,7 @@ arguments: [eventName, data, providers, options],

}
const providerPackages = getProvidersPackage();
const configuredTags = getConfiguredTags();
const userId = handleGetUserId();
const providerPackages = getProvidersPackage(destination);
const configuredTags = getSetting(destination, 'channels');
const userId = getUserId$1(destination);
const providerData = {};
const consent = getConsent$1();
const consent = getConsent$1(destination);
for (const pkg of Object.values(providerPackages)) {

@@ -715,16 +761,15 @@ if (!pkg || !pkg.name || !pkg.tag) {

}
const variables = getProviderVariables(pkg.name);
const variables = getProviderVariables(destination, pkg.name);
const result = {};
const providerVariables = Object.entries(variables);
const executionContext = new Map();
for (const [tagName, variableSet] of providerVariables) {
if (!isProviderInstanceAllowed(providers, pkg.name, tagName)) {
log(`Provider instance is not allowed (${pkg.name}: ${tagName})`);
for (const variable of variables) {
if (!isProviderInstanceAllowed(providers, pkg.name, variable.tagName)) {
log(`Provider instance is not allowed (${pkg.name}: ${variable.tagName})`);
continue;
}
if (!hasUserConsent(consent, pkg.name, tagName)) {
log(`Consent is missing (${pkg.name}: ${tagName})`);
if (!hasUserConsent(consent, pkg.name, variable.tagName)) {
log(`Consent is missing (${pkg.name}: ${variable.tagName})`);
continue;
}
result[tagName] = pkg.tag({
result[variable.tagName] = pkg.tag({
userId,

@@ -734,4 +779,4 @@ eventName,

data: JSON.parse(JSON.stringify(data)),
sendTag,
manifestVariables: variableSet,
sendTag: sendTag.bind(null, destination),
manifestVariables: variable.variableSet,
executionContext,

@@ -745,3 +790,3 @@ });

}
sendTag({
sendTag(destination, {
eventName,

@@ -755,2 +800,11 @@ eventId,

};
const handleTag = (eventName, data = {}, providers, options) => {
if (options === null || options === void 0 ? void 0 : options.destination) {
processTag(options.destination, eventName, data, providers, options);
return;
}
getInstances().forEach((instance) => {
processTag(instance, eventName, data, providers, options);
});
};
const hasAllowedManifestTags = (tags, consent, providersConfig) => {

@@ -768,8 +822,4 @@ for (const [pkg, tagNames] of tags) {

const handleGetData = (keys, callback) => {
if (!keys || keys.length === 0) {
error('Provide keys for get data API.');
return;
}
getRequest(getGetDataURL(keys))
const processGetData = (destination, keys, callback) => {
getRequest(getGetDataURL(destination, keys))
.then((result) => {

@@ -780,13 +830,26 @@ callback((result === null || result === void 0 ? void 0 : result.result) || {});

};
const handleData = (data, providers, options) => {
if (!data || Object.keys(data).length === 0) {
error('Provide data for data API.');
const handleGetData = (keys, callback, options) => {
if (!keys || keys.length === 0) {
error('Provide keys for get data API.');
return;
}
saveKV(data);
const providerPackages = getProvidersPackage();
const configuredTags = getConfiguredTags();
const userId = handleGetUserId();
const consent = getConsent$1();
if (options === null || options === void 0 ? void 0 : options.destination) {
processGetData(options.destination, keys, callback);
return;
}
const instances = getInstances();
if (instances.length > 1) {
error('Multiple instances found! Please provide destination.');
callback({});
return;
}
processGetData(instances[0], keys, callback);
};
const processData = (destination, data, providers, options) => {
saveKV(destination, data);
const providerPackages = getProvidersPackage(destination);
const configuredTags = getSetting(destination, 'channels');
const userId = getUserId$1(destination);
const consent = getConsent$1(destination);
for (const pkg of Object.values(providerPackages)) {

@@ -800,10 +863,10 @@ if (!pkg || !pkg.user || !pkg.name) {

}
const variables = getProviderVariables(pkg.name);
for (const [tagName, variableSet] of Object.entries(variables)) {
if (!isProviderInstanceAllowed(providers, pkg.name, tagName)) {
log(`Data not allowed for ${pkg.name} (${tagName})`);
const variables = getProviderVariables(destination, pkg.name);
for (const variable of variables) {
if (!isProviderInstanceAllowed(providers, pkg.name, variable.tagName)) {
log(`Data not allowed for ${pkg.name} (${variable.tagName})`);
continue;
}
if (!hasUserConsent(consent, pkg.name, tagName)) {
log(`Consent is missing for ${pkg.name} (${tagName})`);
if (!hasUserConsent(consent, pkg.name, variable.tagName)) {
log(`Consent is missing for ${pkg.name} (${variable.tagName})`);
continue;

@@ -814,16 +877,39 @@ }

data,
manifestVariables: variableSet,
manifestVariables: variable.variableSet,
});
}
}
postRequest(getDataURL(), { data, providers }, options).catch(error);
postRequest(getDataURL(destination), { data, providers }, options).catch(error);
};
const handleData = (data, providers, options) => {
if (!data || Object.keys(data).length === 0) {
error('Provide data for data API.');
return;
}
if (options === null || options === void 0 ? void 0 : options.destination) {
processData(options.destination, data, providers, options);
return;
}
getInstances().forEach((destination) => {
processData(destination, data, providers, options);
});
};
let memoryConsent;
const saveConsent = (consent) => {
setConsent(consent);
savePerKey('local', tagStorage, consent, consentKey);
const handleConsent = (consent, options) => {
if (options === null || options === void 0 ? void 0 : options.destination) {
processConsent(options.destination, consent, options === null || options === void 0 ? void 0 : options.localSave);
return;
}
getInstances().forEach((destination) => {
processConsent(destination, consent, options === null || options === void 0 ? void 0 : options.localSave);
});
};
const handleConsent = (consent, options) => {
const existingConsent = getConsent$1();
const saveConsent = (destination, consent) => {
setSetting({
consent,
}, destination);
savePerKey(destination, 'local', tagStorage, consent, consentKey);
};
const processConsent = (destination, consent, localSave) => {
const existingConsent = getConsent$1(destination);
if (areEqual(existingConsent, consent)) {

@@ -835,8 +921,8 @@ return;

};
saveConsent(consent);
if (!(options === null || options === void 0 ? void 0 : options.localSave)) {
postRequest(getConsentURL(), payload).catch(error);
saveConsent(destination, consent);
if (!localSave) {
postRequest(getConsentURL(destination), payload).catch(error);
}
const userId = handleGetUserId();
const providerPackages = getProvidersPackage();
const userId = getUserId$1(destination);
const providerPackages = getProvidersPackage(destination);
const executionContext = new Map();

@@ -848,6 +934,5 @@ /* Calling Init for all provider instances based on consent check */

}
const variables = getProviderVariables(pkg.name);
const providerVariables = Object.entries(variables);
for (const [tagName, variablesSet] of providerVariables) {
const hasConsent = hasUserConsent(consent, pkg.name, tagName);
const variables = getProviderVariables(destination, pkg.name);
for (const variable of variables) {
const hasConsent = hasUserConsent(consent, pkg.name, variable.tagName);
if (!hasConsent) {

@@ -859,11 +944,11 @@ continue;

isNewUser: false,
baseUrl: getUrl(),
baseUrl: destination,
manifest: {
tagName,
variables: variablesSet,
tagName: variable.tagName,
variables: variable.variableSet,
package: pkg.name,
},
sendTag,
sendEdgeData: handleData,
getEdgeData: handleGetData,
sendTag: sendTag.bind(null, destination),
sendEdgeData: processData.bind(null, destination),
getEdgeData: processGetData.bind(null, destination),
keyName: `${keyPrefix}Store`,

@@ -878,2 +963,3 @@ executionContext,

detail: {
destination,
oldConsent: existingConsent,

@@ -897,16 +983,6 @@ newConsent: consent,

};
const setConsent = (newConsent) => {
memoryConsent = newConsent;
};
const getConsent$1 = () => {
const storageConsent = getDataPerKey('local', tagStorage, consentKey);
if (storageConsent) {
return storageConsent;
}
return memoryConsent;
};
const cacheKey = `${keyPrefix}Cache`;
const identity = (v) => v;
const saveDataToEdge = (key, value, provider) => {
const saveDataToEdge = (destination, key, value, provider) => {
if (!value) {

@@ -925,5 +1001,7 @@ return;

}
handleData({ [`${provider}::${key}`]: updatedValue });
handleData({ [`${provider}::${key}`]: updatedValue }, undefined, {
destination,
});
};
const handleCaptureQuery = (provider, key, persistType, map) => {
const handleCaptureQuery = (destination, provider, key, persistType, map) => {
try {

@@ -937,3 +1015,3 @@ if (!window) {

}
const params = new URLSearchParams(getSearch());
const params = new URLSearchParams(getSearch(destination));
if (!params || !params.get(key)) {

@@ -947,14 +1025,16 @@ return;

if (persistType === 'edge') {
saveDataToEdge(key, data, provider);
saveDataToEdge(destination, key, data, provider);
return;
}
saveDataPerKey(persistType, provider, data, key);
saveDataPerKey(destination, persistType, provider, data, key);
};
const getFromCache = (persistType, provider, key) => {
const getFromCache = (destination, persistType, provider, key) => {
var _a;
const cache = getData$1(persistType === 'edge' ? 'local' : persistType, cacheKey);
const type = persistType === 'edge' ? 'local' : persistType;
const cache = getData$1(destination, type, cacheKey);
return (_a = cache[provider]) === null || _a === void 0 ? void 0 : _a[key];
};
const saveToCache = (persistType, provider, key, value) => {
const cache = getData$1(persistType === 'edge' ? 'local' : persistType, cacheKey);
const saveToCache = (destination, persistType, provider, key, value) => {
const type = persistType === 'edge' ? 'local' : persistType;
const cache = getData$1(destination, type, cacheKey);
if (!cache[provider]) {

@@ -966,5 +1046,5 @@ cache[provider] = { [key]: value };

}
saveData(persistType === 'edge' ? 'local' : persistType, cache, cacheKey);
saveData(destination, type, cache, cacheKey);
};
const handleCaptureStorage = (provider, key, persistType, location, map) => {
const handleCaptureStorage = (destination, provider, key, persistType, location, map) => {
let data;

@@ -992,20 +1072,20 @@ try {

}
const cachedKey = `${handleGetUserId()}/${key}`;
const cachedValue = getFromCache(persistType, provider, cachedKey);
const cachedKey = `${getUserId$1(destination)}/${key}`;
const cachedValue = getFromCache(destination, persistType, provider, cachedKey);
if (persistType === 'edge' && cachedValue !== data) {
saveDataToEdge(key, data, provider);
saveToCache(persistType, provider, cachedKey, data);
saveDataToEdge(destination, key, data, provider);
saveToCache(destination, persistType, provider, cachedKey, data);
return;
}
saveDataPerKey(persistType, provider, data, key);
saveDataPerKey(destination, persistType, provider, data, key);
};
const handleCapture = (provider, params, capture) => {
const handleCapture = (destination, provider, params, capture) => {
params.forEach((param) => {
switch (param.type) {
case 'query': {
handleCaptureQuery(provider, param.key, param.persist, capture === null || capture === void 0 ? void 0 : capture.bind(null, param));
handleCaptureQuery(destination, provider, param.key, param.persist, capture === null || capture === void 0 ? void 0 : capture.bind(null, param));
break;
}
case 'storage': {
handleCaptureStorage(provider, param.key, param.persist, param.location, capture === null || capture === void 0 ? void 0 : capture.bind(null, param));
handleCaptureStorage(destination, provider, param.key, param.persist, param.location, capture === null || capture === void 0 ? void 0 : capture.bind(null, param));
break;

@@ -1017,10 +1097,9 @@ }

const handleManifest = (response, consent) => {
const providerPackages = getProvidersPackage();
const userId = handleGetUserId();
const handleManifest = (destination, response) => {
const providerPackages = getProvidersPackage(destination);
const userId = getUserId$1(destination);
const executionContext = new Map();
const manifest = response.result;
manifest.forEach((provider) => {
addConfiguredTag(provider.package, provider.tagName);
addProviderVariable(provider.package, provider.variables, provider.tagName);
addChannel(destination, provider.package, provider.tagName);
const pkg = providerPackages[provider.package];

@@ -1031,3 +1110,3 @@ if (provider.rules) {

case 'capture': {
handleCapture(provider.package, recipe, pkg === null || pkg === void 0 ? void 0 : pkg.capture);
handleCapture(destination, provider.package, recipe, pkg === null || pkg === void 0 ? void 0 : pkg.capture);
return;

@@ -1040,3 +1119,3 @@ }

/* this defines if the consent is given for a specific instance of a provider */
const hasConsent = hasUserConsent(consent, pkg.name, provider.tagName);
const hasConsent = hasUserConsent(getSetting(destination, 'consent'), pkg.name, provider.tagName);
if (hasConsent) {

@@ -1047,7 +1126,7 @@ pkg.init({

session: response.session,
baseUrl: getUrl(),
baseUrl: destination,
manifest: provider,
sendTag,
sendEdgeData: handleData,
getEdgeData: handleGetData,
sendTag: sendTag.bind(null, destination),
sendEdgeData: processData.bind(null, destination),
getEdgeData: processGetData.bind(null, destination),
keyName: `${keyPrefix}Store`,

@@ -1059,17 +1138,8 @@ executionContext,

});
setInitialized();
processStubs();
setSetting({
initialized: true,
}, destination);
processStubs(destination);
};
let initIsNewUser = undefined;
const handleIsNewUser = () => {
if (initIsNewUser !== undefined) {
return initIsNewUser;
}
return undefined;
};
const setIsNewUSer = (isNewUser) => {
initIsNewUser = isNewUser;
};
const handleInit = (preferences) => {

@@ -1081,11 +1151,13 @@ const success = setPreferences(preferences);

if (preferences.afterManifestEvents) {
addStubs(preferences.afterManifestEvents);
setSetting({
stubs: preferences.afterManifestEvents,
}, preferences.edgeURL);
}
const url = new URL(getInitURL());
const url = new URL(getInitURL(preferences.edgeURL));
if (preferences.disableConsentCheck) {
url.searchParams.set('consentDisabled', 'true');
saveConsent({ all: true });
saveConsent(preferences.edgeURL, { all: true });
}
if (preferences.userId) {
setUserId(preferences.userId);
setSetting({ userId: preferences.userId }, preferences.edgeURL);
url.searchParams.set('userId', preferences.userId);

@@ -1099,14 +1171,13 @@ }

}
if (result.userId) {
setUserId(result.userId);
}
const consent = getConsent$1();
if (result.consent && !consent) {
saveConsent(result.consent);
}
setIsNewUSer(result.isNewUser);
handleManifest(result, consent || result.consent);
setSetting({
isNewUser: result.isNewUser,
consent: getConsent$1(preferences.edgeURL) || result.consent,
userId: result.userId,
packages: result.result,
}, preferences.edgeURL);
handleManifest(preferences.edgeURL, result);
try {
window.dispatchEvent(new CustomEvent('edgetag-initialized', {
detail: {
destination: preferences.edgeURL,
userId: result.userId,

@@ -1127,14 +1198,10 @@ isNewUser: result.isNewUser,

const handleUser = (key, value, providers, options) => {
if (!key || !value) {
error('Key or Value is missing in user API.');
return;
}
saveKV({
const processUser = (destination, key, value, providers, options) => {
saveKV(destination, {
[key]: value,
});
const providerPackages = getProvidersPackage();
const configuredTags = getConfiguredTags();
const consent = getConsent$1();
const userId = handleGetUserId();
const providerPackages = getProvidersPackage(destination);
const configuredTags = getSetting(destination, 'channels');
const consent = getConsent$1(destination);
const userId = getUserId$1(destination);
for (const pkg of Object.values(providerPackages)) {

@@ -1148,10 +1215,10 @@ if (!pkg || !pkg.name || !pkg.user) {

}
const variables = getProviderVariables(pkg.name);
for (const [tagName, variableSet] of Object.entries(variables)) {
if (!isProviderInstanceAllowed(providers, pkg.name, tagName)) {
log(`User not allowed for ${pkg.name} (${tagName})`);
const variables = getProviderVariables(destination, pkg.name);
for (const variable of variables) {
if (!isProviderInstanceAllowed(providers, pkg.name, variable.tagName)) {
log(`User not allowed for ${pkg.name} (${variable.tagName})`);
continue;
}
if (!hasUserConsent(consent, pkg.name, tagName)) {
log(`User doesn't have consent for ${pkg.name} (${tagName})`);
if (!hasUserConsent(consent, pkg.name, variable.tagName)) {
log(`User doesn't have consent for ${pkg.name} (${variable.tagName})`);
continue;

@@ -1162,7 +1229,7 @@ }

data: { [key]: value },
manifestVariables: variableSet,
manifestVariables: variable.variableSet,
});
}
}
postRequest(getUserURL(), {
postRequest(getUserURL(destination), {
key,

@@ -1173,5 +1240,18 @@ value,

};
const handleUser = (key, value, providers, options) => {
if (!key || !value) {
error('Key or Value is missing in user API.');
return;
}
if (options === null || options === void 0 ? void 0 : options.destination) {
processUser(options.destination, key, value, providers, options);
return;
}
getInstances().forEach((destination) => {
processUser(destination, key, value, providers, options);
});
};
const handleKeys = (callback) => {
getRequest(getKeysURL())
const processKeys = (destination, callback) => {
getRequest(getKeysURL(destination))
.then((result) => {

@@ -1182,5 +1262,18 @@ callback((result === null || result === void 0 ? void 0 : result.result) || []);

};
const handleKeys = (callback, options) => {
if (options === null || options === void 0 ? void 0 : options.destination) {
processKeys(options.destination, callback);
return;
}
const instances = getInstances();
if (instances.length > 1) {
error('Multiple instances found! Please provide destination.');
callback([]);
return;
}
processKeys(instances[0], callback);
};
const handleGetConsent = (callback) => {
getRequest(getConsentURL())
const processGetConsent = (destination, callback) => {
getRequest(getConsentURL(destination))
.then((result) => {

@@ -1192,3 +1285,3 @@ // this will try to return the consent data stored in Edge

.then((result) => {
const consent = result !== null && result !== void 0 ? result : getConsent$1(); // this is a default value i.e. value from local storage and memory incase Edge doesn't have consent
const consent = result !== null && result !== void 0 ? result : getConsent$1(destination); // this is a default value i.e. value from local storage and memory incase Edge doesn't have consent
if (consent) {

@@ -1202,7 +1295,46 @@ callback(consent);

};
const handleGetConsent = (callback, options) => {
if (options === null || options === void 0 ? void 0 : options.destination) {
processGetConsent(options.destination, callback);
return;
}
const instances = getInstances();
if (instances.length > 1) {
callback(null, new Error('Multiple instances found! Please provide destination.'));
return;
}
processGetConsent(instances[0], callback);
};
const handleConfig = (config) => {
setConfig$1(config);
const handleIsNewUser = (options) => {
if (options === null || options === void 0 ? void 0 : options.destination) {
return getSetting(options.destination, 'isNewUser');
}
const instances = getInstances();
if (instances.length > 1) {
error('Multiple instances found! Please provide destination.');
return undefined;
}
return getSetting(instances[0], 'isNewUser');
};
const processConfig = (destination, config) => {
const existingConfig = getSetting(destination, 'config');
setSetting({
config: {
...existingConfig,
...config,
},
}, destination);
};
const handleConfig = (config, options) => {
if (options === null || options === void 0 ? void 0 : options.destination) {
processConfig(options.destination, config);
return;
}
getInstances().forEach((destination) => {
processConfig(destination, config);
});
};
const init = (preferences) => {

@@ -1223,19 +1355,19 @@ handleInit(preferences);

};
const getData = (keys, callback) => {
handleGetData(keys, callback);
const getData = (keys, callback, options) => {
handleGetData(keys, callback, options);
};
const keys = (callback) => {
handleKeys(callback);
const keys = (callback, options) => {
handleKeys(callback, options);
};
const getUserId = () => {
return handleGetUserId();
const getUserId = (options) => {
return handleGetUserId(options);
};
const getConsent = (callback) => {
handleGetConsent(callback);
const getConsent = (callback, options) => {
handleGetConsent(callback, options);
};
const isNewUser = () => {
return handleIsNewUser();
const isNewUser = (options) => {
return handleIsNewUser(options);
};
const setConfig = (config) => {
return handleConfig(config);
const setConfig = (config, options) => {
handleConfig(config, options);
};

@@ -1242,0 +1374,0 @@

@@ -15,2 +15,11 @@ import { ProvidersConfig } from '@blotoutio/cdn/types'

ConsentOptions,
KeysCallback,
KeysOptions,
GetDataCallback,
Configs,
GetConsentCallback,
GetConsentOptions,
GetDataOptions,
IsNewUserOptions,
GetUserIdOptions,
} from '@blotoutio/shared/utility-sdk'

@@ -56,3 +65,3 @@

providers?: ProvidersConfig,
options?: EventOptions
options?: UserOptions
) => void

@@ -68,13 +77,27 @@

keys: string[],
callback: (data: Record<string, string>) => void
callback: GetDataCallback,
options?: GetDataOptions
) => void
export declare const keys: (callback: (keys: string[]) => void) => void
export declare const keys: (
callback: KeysCallback,
options?: KeysOptions
) => void
export declare const getUserId: () => string
export declare const getUserId: (options?: GetUserIdOptions) => string
export declare const isNewUser: () => boolean | undefined
export declare const isNewUser: (
options?: IsNewUserOptions
) => boolean | undefined
export declare const setConfig: (config: ConfigOptions) => void
export declare const setConfig: (
config: Configs,
options?: ConfigOptions
) => void
export declare const getConsent: (
callback: GetConsentCallback,
options?: GetConsentOptions
) => void
export declare global {

@@ -81,0 +104,0 @@ interface Window {

{
"name": "@blotoutio/edgetag-sdk-js",
"version": "0.51.1",
"version": "0.52.0",
"description": "JS SDK for EdgeTag",

@@ -5,0 +5,0 @@ "author": "Blotout",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc