Skip to content

Commit 79277d6

Browse files
committed
Fix ESLint warnings
1 parent cdf6ddc commit 79277d6

File tree

1 file changed

+22
-25
lines changed

1 file changed

+22
-25
lines changed

scripts/configs.js

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const ALLOWED_CONFIGS = ["prod", "stage", "dev"];
1+
const ALLOWED_CONFIGS = ['prod', 'stage', 'dev'];
22

33
/**
44
* This function calculates the environment in which the site is running based on the URL.
@@ -9,19 +9,19 @@ const ALLOWED_CONFIGS = ["prod", "stage", "dev"];
99
*/
1010
export const calcEnvironment = () => {
1111
const { host, href } = window.location;
12-
let environment = "prod";
13-
if (href.includes(".aem.page") || host.includes("staging")) {
14-
environment = "stage";
12+
let environment = 'prod';
13+
if (href.includes('.aem.page') || host.includes('staging')) {
14+
environment = 'stage';
1515
}
16-
if (href.includes("localhost")) {
17-
environment = "dev";
16+
if (href.includes('localhost')) {
17+
environment = 'dev';
1818
}
1919

20-
const environmentFromConfig = window.sessionStorage.getItem("environment");
20+
const environmentFromConfig = window.sessionStorage.getItem('environment');
2121
if (
22-
environmentFromConfig &&
23-
ALLOWED_CONFIGS.includes(environmentFromConfig) &&
24-
environment !== "prod"
22+
environmentFromConfig
23+
&& ALLOWED_CONFIGS.includes(environmentFromConfig)
24+
&& environment !== 'prod'
2525
) {
2626
return environmentFromConfig;
2727
}
@@ -31,8 +31,8 @@ export const calcEnvironment = () => {
3131

3232
function buildConfigURL(environment) {
3333
const env = environment || calcEnvironment();
34-
let fileName = "configs.json";
35-
if (env !== "prod") {
34+
let fileName = 'configs.json';
35+
if (env !== 'prod') {
3636
fileName = `configs-${env}.json`;
3737
}
3838
const configURL = new URL(`${window.location.origin}/${fileName}`);
@@ -45,15 +45,15 @@ const getConfigForEnvironment = async (environment) => {
4545
try {
4646
const configJSON = window.sessionStorage.getItem(`config:${env}`);
4747
if (!configJSON) {
48-
throw new Error("No config in session storage");
48+
throw new Error('No config in session storage');
4949
}
5050

5151
const parsedConfig = JSON.parse(configJSON);
5252
if (
53-
!parsedConfig[":expiry"] ||
54-
parsedConfig[":expiry"] < Math.round(Date.now() / 1000)
53+
!parsedConfig[':expiry']
54+
|| parsedConfig[':expiry'] < Math.round(Date.now() / 1000)
5555
) {
56-
throw new Error("Config expired");
56+
throw new Error('Config expired');
5757
}
5858

5959
return parsedConfig;
@@ -63,7 +63,7 @@ const getConfigForEnvironment = async (environment) => {
6363
throw new Error(`Failed to fetch config for ${env}`);
6464
}
6565
configJSON = await configJSON.json();
66-
configJSON[":expiry"] = Math.round(Date.now() / 1000) + 7200;
66+
configJSON[':expiry'] = Math.round(Date.now() / 1000) + 7200;
6767
window.sessionStorage.setItem(`config:${env}`, JSON.stringify(configJSON));
6868
return configJSON;
6969
}
@@ -94,25 +94,23 @@ export const getConfigValue = async (configParam, environment) => {
9494
export const getHeaders = async (scope, environment) => {
9595
const env = environment || calcEnvironment();
9696
const config = await getConfigForEnvironment(env);
97-
const configElements = config.data.filter((el) =>
98-
el?.key.includes(`headers.${scope}`)
99-
);
97+
const configElements = config.data.filter((el) => el?.key.includes(`headers.${scope}`));
10098

10199
return configElements.reduce((obj, item) => {
102100
let { key } = item;
103101
if (key.includes(`commerce.headers.${scope}.`)) {
104-
key = key.replace(`commerce.headers.${scope}.`, "");
102+
key = key.replace(`commerce.headers.${scope}.`, '');
105103
}
106104
return { ...obj, [key]: item.value };
107105
}, {});
108106
};
109107

110108
export const getCookie = (cookieName) => {
111-
const cookies = document.cookie.split(";");
109+
const cookies = document.cookie.split(';');
112110
let foundValue;
113111

114112
cookies.forEach((cookie) => {
115-
const [name, value] = cookie.trim().split("=");
113+
const [name, value] = cookie.trim().split('=');
116114
if (name === cookieName) {
117115
foundValue = decodeURIComponent(value);
118116
}
@@ -121,5 +119,4 @@ export const getCookie = (cookieName) => {
121119
return foundValue;
122120
};
123121

124-
export const checkIsAuthenticated = () =>
125-
!!getCookie("auth_dropin_user_token") ?? false;
122+
export const checkIsAuthenticated = () => !!getCookie('auth_dropin_user_token') ?? false;

0 commit comments

Comments
 (0)