fix(next-utils): use z.extend() for robust type inference in validateMintelEnv
Some checks failed
Monorepo Pipeline / 🧪 Quality Assurance (push) Successful in 2m33s
Monorepo Pipeline / 🐳 Build Directus (Base) (push) Successful in 33s
Monorepo Pipeline / 🐳 Build Build-Base (push) Has been cancelled
Monorepo Pipeline / 🐳 Build Production Runtime (push) Has been cancelled
Monorepo Pipeline / 🐳 Build Gatekeeper (Product) (push) Has been cancelled
Monorepo Pipeline / 🚀 Release (push) Has been cancelled

This commit is contained in:
2026-02-11 00:04:14 +01:00
parent 149123ef90
commit 858c7bbc39
2 changed files with 5 additions and 11 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "@mintel/next-utils",
"version": "1.7.2",
"version": "1.7.3",
"publishConfig": {
"access": "public",
"registry": "https://npm.infra.mintel.me"

View File

@@ -50,16 +50,10 @@ export const mintelEnvSchema = {
INTERNAL_DIRECTUS_URL: z.string().url().optional(),
};
export type MintelEnv<T extends z.ZodRawShape = Record<string, never>> =
z.infer<z.ZodObject<typeof mintelEnvSchema & T>>;
export function validateMintelEnv<
T extends z.ZodRawShape = Record<string, never>,
>(schemaExtension: T = {} as T): MintelEnv<T> {
const fullSchema = z.object({
...mintelEnvSchema,
...schemaExtension,
});
>(schemaExtension: T = {} as T) {
const fullSchema = z.object(mintelEnvSchema).extend(schemaExtension);
const isBuildTime =
process.env.NEXT_PHASE === "phase-production-build" ||
@@ -73,7 +67,7 @@ export function validateMintelEnv<
"⚠️ Some environment variables are missing during build, but skipping strict validation.",
);
// Return process.env casted to the full schema type to unblock builds
return process.env as unknown as MintelEnv<T>;
return process.env as unknown as z.infer<typeof fullSchema>;
}
console.error(
@@ -83,5 +77,5 @@ export function validateMintelEnv<
throw new Error("Invalid environment variables");
}
return result.data as MintelEnv<T>;
return result.data;
}