mirror of
https://github.com/vercel/commerce.git
synced 2025-05-12 12:47:50 +00:00
resolve build errors
This commit is contained in:
parent
3cf2f61e0b
commit
cc9def4035
@ -1,89 +0,0 @@
|
|||||||
import clsx, { ClassValue } from 'clsx';
|
|
||||||
import { ReadonlyURLSearchParams } from 'next/navigation';
|
|
||||||
import { twMerge } from 'tailwind-merge';
|
|
||||||
import { Menu } from './types';
|
|
||||||
|
|
||||||
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 = [
|
|
||||||
'SHOPIFY_STORE_DOMAIN',
|
|
||||||
'SHOPIFY_STOREFRONT_ACCESS_TOKEN',
|
|
||||||
'SHOPIFY_CUSTOMER_ACCOUNT_API_CLIENT_ID',
|
|
||||||
'SHOPIFY_CUSTOMER_ACCOUNT_API_URL',
|
|
||||||
'SHOPIFY_CUSTOMER_API_VERSION',
|
|
||||||
'SHOPIFY_ORIGIN_URL'
|
|
||||||
];
|
|
||||||
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/shopify#configure-environment-variables\n\n${missingEnvironmentVariables.join(
|
|
||||||
'\n'
|
|
||||||
)}\n`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
process.env.SHOPIFY_STORE_DOMAIN?.includes('[') ||
|
|
||||||
process.env.SHOPIFY_STORE_DOMAIN?.includes(']')
|
|
||||||
) {
|
|
||||||
throw new Error(
|
|
||||||
'Your `SHOPIFY_STORE_DOMAIN` environment variable includes brackets (ie. `[` and / or `]`). Your site will not work with them there. Please remove them.'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export function cn(...inputs: ClassValue[]) {
|
|
||||||
return twMerge(clsx(inputs));
|
|
||||||
}
|
|
||||||
|
|
||||||
export function normalizeUrl(domain: string, url: string) {
|
|
||||||
return url.replace(domain, '').replace('/collections', '/search').replace('/pages', '');
|
|
||||||
}
|
|
||||||
|
|
||||||
export const parseMetaFieldValue = <T>(field: { value: string } | null): T | null => {
|
|
||||||
try {
|
|
||||||
return field?.value ? JSON.parse(field.value) : null;
|
|
||||||
} catch (error) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const findParentCollection = (menu: Menu[], collection: string): Menu | null => {
|
|
||||||
let parentCollection: Menu | null = null;
|
|
||||||
for (const item of menu) {
|
|
||||||
if (item.items.length) {
|
|
||||||
const hasParent = item.items.some((subItem) => subItem.path.includes(collection));
|
|
||||||
if (hasParent) {
|
|
||||||
return item;
|
|
||||||
} else {
|
|
||||||
parentCollection = findParentCollection(item.items, collection);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return parentCollection;
|
|
||||||
};
|
|
||||||
|
|
||||||
export function parseJSON(json: any) {
|
|
||||||
if (String(json).includes('__proto__')) return JSON.parse(json, noproto);
|
|
||||||
return JSON.parse(json);
|
|
||||||
}
|
|
||||||
|
|
||||||
function noproto(k: string, v: string) {
|
|
||||||
if (k !== '__proto__') return v;
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
const uploadFile = async (req: Request, res: Response) => {
|
|
||||||
const { file } = req.files as { file: UploadedFile[] };
|
|
||||||
const { name, type, size } = file;
|
|
||||||
|
|
||||||
if (size > 1000000) {
|
|
||||||
return res.status(400).json({ message: 'File size must be less than 1MB' });
|
|
||||||
}
|
|
||||||
|
|
||||||
const uploadPath = path.join(__dirname, 'uploads', name);
|
|
||||||
|
|
||||||
try {
|
|
||||||
await file.mv(uploadPath);
|
|
||||||
res.json({ message: 'File uploaded' });
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
res.status(500).json({ message: 'Error uploading file' });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export default uploadFile;
|
|
@ -1,7 +1,7 @@
|
|||||||
import clsx, { ClassValue } from 'clsx';
|
import clsx, { ClassValue } from 'clsx';
|
||||||
import { ReadonlyURLSearchParams } from 'next/navigation';
|
import { ReadonlyURLSearchParams } from 'next/navigation';
|
||||||
import { twMerge } from 'tailwind-merge';
|
import { twMerge } from 'tailwind-merge';
|
||||||
import { Menu } from './types';
|
import { Menu } from './shopify/types';
|
||||||
|
|
||||||
export const createUrl = (pathname: string, params: URLSearchParams | ReadonlyURLSearchParams) => {
|
export const createUrl = (pathname: string, params: URLSearchParams | ReadonlyURLSearchParams) => {
|
||||||
const paramsString = params.toString();
|
const paramsString = params.toString();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user