Files
medreport_mrb2b/packages/shared/src/config/app.config.ts
Helena 9122acc89f MED-151: add profile view and working smoking dashboard card (#71)
* MED-151: add profile view and working smoking dashboard card

* update zod

* move some components to shared

* move some components to shared

* remove console.logs

* remove unused password form components

* only check null for variant

* use pathsconfig
2025-09-04 12:17:54 +03:00

77 lines
2.5 KiB
TypeScript

import { z } from 'zod';
const production = process.env.NODE_ENV === 'production';
const AppConfigSchema = z
.object({
name: z
.string({
error: `Please provide the variable NEXT_PUBLIC_PRODUCT_NAME`,
})
.describe(`This is the name of your SaaS. Ex. "Makerkit"`)
.min(1),
title: z
.string({
error: `Please provide the variable NEXT_PUBLIC_SITE_TITLE`,
})
.describe(`This is the default title tag of your SaaS.`)
.min(1),
description: z.string({
error: `Please provide the variable NEXT_PUBLIC_SITE_DESCRIPTION`,
})
.describe(`This is the default description of your SaaS.`),
url: z.url({
error: (issue) => issue.input === undefined
? "Please provide the variable NEXT_PUBLIC_SITE_URL"
: `You are deploying a production build but have entered a NEXT_PUBLIC_SITE_URL variable using http instead of https. It is very likely that you have set the incorrect URL. The build will now fail to prevent you from from deploying a faulty configuration. Please provide the variable NEXT_PUBLIC_SITE_URL with a valid URL, such as: 'https://example.com'`
}),
locale: z
.string({
error: `Please provide the variable NEXT_PUBLIC_DEFAULT_LOCALE`,
})
.describe(`This is the default locale of your SaaS.`)
.default('en'),
theme: z.enum(['light', 'dark', 'system']),
production: z.boolean(),
themeColor: z.string(),
themeColorDark: z.string(),
})
.refine(
(schema) => {
const isCI = process.env.NEXT_PUBLIC_CI;
if (isCI ?? !schema.production) {
return true;
}
return !schema.url.startsWith('http:');
},
{
message: `Please provide a valid HTTPS URL. Set the variable NEXT_PUBLIC_SITE_URL with a valid URL, such as: 'https://example.com'`,
path: ['url'],
},
)
.refine(
(schema) => {
return schema.themeColor !== schema.themeColorDark;
},
{
message: `Please provide different theme colors for light and dark themes.`,
path: ['themeColor'],
},
);
const appConfig = AppConfigSchema.parse({
name: process.env.NEXT_PUBLIC_PRODUCT_NAME,
title: process.env.NEXT_PUBLIC_SITE_TITLE,
description: process.env.NEXT_PUBLIC_SITE_DESCRIPTION,
url: process.env.NEXT_PUBLIC_SITE_URL,
locale: process.env.NEXT_PUBLIC_DEFAULT_LOCALE,
theme: process.env.NEXT_PUBLIC_DEFAULT_THEME_MODE,
themeColor: process.env.NEXT_PUBLIC_THEME_COLOR,
themeColorDark: process.env.NEXT_PUBLIC_THEME_COLOR_DARK,
production,
});
export default appConfig;