mirror of
https://github.com/vercel/commerce.git
synced 2025-05-08 18:57:51 +00:00
31 lines
1.2 KiB
TypeScript
31 lines
1.2 KiB
TypeScript
import { ReadonlyURLSearchParams } from 'next/navigation';
|
|
|
|
export const createUrl = (pathname: string, params: URLSearchParams | ReadonlyURLSearchParams) => {
|
|
const paramsString = params.toString();
|
|
const queryString = `${paramsString.length ? '?' : ''}${paramsString}`;
|
|
|
|
return `${pathname}${queryString}`;
|
|
};
|
|
|
|
export const ensureStartsWith = (stringToCheck: string, startsWith: string) =>
|
|
stringToCheck.startsWith(startsWith) ? stringToCheck : `${startsWith}${stringToCheck}`;
|
|
|
|
export const validateEnvironmentVariables = () => {
|
|
const requiredEnvironmentVariables = ['NEXT_PUBLIC_FW_API_URL', 'NEXT_PUBLIC_FW_PUBLIC_TOKEN', 'NEXT_PUBLIC_FW_COLLECTION', 'NEXT_PUBLIC_FW_CHECKOUT'];
|
|
const missingEnvironmentVariables = [] as string[];
|
|
|
|
requiredEnvironmentVariables.forEach((envVar) => {
|
|
if (!process.env[envVar]) {
|
|
missingEnvironmentVariables.push(envVar);
|
|
}
|
|
});
|
|
|
|
if (missingEnvironmentVariables.length) {
|
|
throw new Error(
|
|
`The following environment variables are missing. Your site will not work without them. Read more: https://vercel.com/docs/integrations/fourthwall#configure-environment-variables\n\n${missingEnvironmentVariables.join(
|
|
'\n'
|
|
)}\n`
|
|
);
|
|
}
|
|
};
|