Skip to content

Commit

Permalink
chore: eslint issues and size limit fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
MoumitaM committed Oct 21, 2024
1 parent 03b4dcb commit df7faf7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 31 deletions.
58 changes: 30 additions & 28 deletions packages/analytics-js-plugins/src/iubendaConsentManager/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,37 @@ import type { ILogger } from '@rudderstack/analytics-js-common/types/Logger';
import type { ApplicationState } from '@rudderstack/analytics-js-common/types/ApplicationState';
import type { ConsentsInfo } from '@rudderstack/analytics-js-common/types/Consent';
import { isDefined } from '@rudderstack/analytics-js-common/utilities/checks';
import { checks, storages, string } from '../shared-chunks/common';
import { IUBENDA_CONSENT_COOKIE_READ_ERROR, IUBENDA_CONSENT_COOKIE_PARSE_ERROR } from './logMessages';
import { checks, storages } from '../shared-chunks/common';
import {
IUBENDA_CONSENT_COOKIE_READ_ERROR,
IUBENDA_CONSENT_COOKIE_PARSE_ERROR,
} from './logMessages';
import { IUBENDA_CONSENT_MANAGER_PLUGIN, IUBENDA_CONSENT_COOKIE_NAME_PATTERN } from './constants';
import type { IubendaConsentData, IubendaConsentCookieData} from './types'
import type { IubendaConsentData, IubendaConsentCookieData } from './types';

const getIubendaCookieName = (logger?: ILogger): string => {
try {
// Retrieve cookies as a string and split them into an array
const cookies = document.cookie.split('; ');

// Find the cookie that matches the iubenda cookie pattern
const matchedCookie = cookies.find(cookie => {
const [name] = cookie.split('=');
return IUBENDA_CONSENT_COOKIE_NAME_PATTERN.test((name || '').trim());
});

if (!matchedCookie) {
throw new Error('Iubenda Cookie not found with the specified pattern.');
}

// Extract and return the cookie name
const [name] = matchedCookie.split('=');
return name || '';
} catch (err) {
logger?.error(IUBENDA_CONSENT_COOKIE_READ_ERROR(IUBENDA_CONSENT_MANAGER_PLUGIN), err);
return '';
}
};

/**
* Gets the consent data from the Iubenda's consent cookie
Expand All @@ -21,14 +48,12 @@ const getIubendaConsentData = (
): IubendaConsentData | undefined => {
let rawConsentCookieData = null;
try {

const dataStore = storeManager?.setStore({
id: IUBENDA_CONSENT_MANAGER_PLUGIN,
name: IUBENDA_CONSENT_MANAGER_PLUGIN,
type: storages.COOKIE_STORAGE,
});
rawConsentCookieData = dataStore?.engine.getItem(getIubendaCookieName(logger));

} catch (err) {
logger?.error(IUBENDA_CONSENT_COOKIE_READ_ERROR(IUBENDA_CONSENT_MANAGER_PLUGIN), err);
return undefined;
Expand Down Expand Up @@ -87,28 +112,5 @@ const updateConsentStateFromData = (
state.consents.initialized.value = isDefined(iubendaConsentData);
state.consents.data.value = consentData;
};
const getIubendaCookieName = ( logger?: ILogger ): string => {
try {
// Retrieve cookies as a string and split them into an array
const cookies = document.cookie.split('; ');

// Find the cookie that matches the iubenda cookie pattern
const matchedCookie = cookies.find(cookie => {
const [name] = cookie.split('=');
return IUBENDA_CONSENT_COOKIE_NAME_PATTERN.test((name || "").trim());
});

if (!matchedCookie) {
throw new Error('Iubenda Cookie not found with the specified pattern.');
}

// Extract and return the cookie name
const [name] = matchedCookie.split('=');
return name || "";
} catch (err) {
logger?.error(IUBENDA_CONSENT_COOKIE_READ_ERROR(IUBENDA_CONSENT_MANAGER_PLUGIN), err);
return "";
}
};

export { getIubendaConsentData, getConsentData, updateConsentStateFromData, getIubendaCookieName };
6 changes: 3 additions & 3 deletions packages/analytics-js/.size-limit.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default [
name: 'Core (Bundled) - Legacy - NPM (CJS)',
path: 'dist/npm/legacy/bundled/cjs/index.cjs',
import: '*',
limit: '48 KiB',
limit: '48.5 KiB',
},
{
name: 'Core (Bundled) - Legacy - NPM (UMD)',
Expand All @@ -83,7 +83,7 @@ export default [
name: 'Core (Bundled) - Modern - NPM (UMD)',
path: 'dist/npm/modern/bundled/umd/index.js',
import: '*',
limit: '39 KiB',
limit: '39.5 KiB',
},
{
name: 'Core (Content Script) - Legacy - NPM (ESM)',
Expand All @@ -95,7 +95,7 @@ export default [
name: 'Core (Content Script) - Legacy - NPM (CJS)',
path: 'dist/npm/legacy/content-script/cjs/index.cjs',
import: '*',
limit: '47.5 KiB',
limit: '48 KiB',
},
{
name: 'Core (Content Script) - Legacy - NPM (UMD)',
Expand Down

0 comments on commit df7faf7

Please sign in to comment.