Compare commits
5 Commits
feature/aq
...
v1.7.3
| Author | SHA1 | Date | |
|---|---|---|---|
| 858c7bbc39 | |||
| 149123ef90 | |||
| 6bc49d1c52 | |||
| 52ffe49019 | |||
| 73fa292528 |
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@mintel/next-utils",
|
"name": "@mintel/next-utils",
|
||||||
"version": "1.7.0",
|
"version": "1.7.3",
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public",
|
"access": "public",
|
||||||
"registry": "https://npm.infra.mintel.me"
|
"registry": "https://npm.infra.mintel.me"
|
||||||
|
|||||||
@@ -12,13 +12,35 @@ export type MintelDirectusClient = DirectusClient<any> &
|
|||||||
AuthenticationClient<any>;
|
AuthenticationClient<any>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a Directus client configured with Mintel standards
|
* Creates a Directus client configured with Mintel standards.
|
||||||
|
* Automatically handles internal vs. external URLs based on environment.
|
||||||
*/
|
*/
|
||||||
export function createMintelDirectusClient(url?: string): MintelDirectusClient {
|
export function createMintelDirectusClient(url?: string): MintelDirectusClient {
|
||||||
const directusUrl =
|
const isServer = typeof window === "undefined";
|
||||||
url || process.env.DIRECTUS_URL || "http://localhost:8055";
|
|
||||||
|
|
||||||
return createDirectus(directusUrl).with(rest()).with(authentication());
|
// 1. If an explicit URL is provided, use it.
|
||||||
|
if (url) {
|
||||||
|
return createDirectus(url).with(rest()).with(authentication());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. On server: Prioritize INTERNAL_DIRECTUS_URL, fallback to DIRECTUS_URL
|
||||||
|
if (isServer) {
|
||||||
|
const directusUrl =
|
||||||
|
process.env.INTERNAL_DIRECTUS_URL ||
|
||||||
|
process.env.DIRECTUS_URL ||
|
||||||
|
"http://localhost:8055";
|
||||||
|
return createDirectus(directusUrl).with(rest()).with(authentication());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. In browser: Use a proxy path if we are on a different origin,
|
||||||
|
// or use the current origin if no DIRECTUS_URL is set.
|
||||||
|
const proxyPath = "/api/directus"; // Standard Mintel proxy path
|
||||||
|
const browserUrl =
|
||||||
|
typeof window !== "undefined"
|
||||||
|
? `${window.location.origin}${proxyPath}`
|
||||||
|
: proxyPath;
|
||||||
|
|
||||||
|
return createDirectus(browserUrl).with(rest()).with(authentication());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -4,10 +4,17 @@ export const mintelEnvSchema = {
|
|||||||
NODE_ENV: z
|
NODE_ENV: z
|
||||||
.enum(["development", "production", "test"])
|
.enum(["development", "production", "test"])
|
||||||
.default("development"),
|
.default("development"),
|
||||||
NEXT_PUBLIC_BASE_URL: z.string().url(),
|
NEXT_PUBLIC_BASE_URL: z.string().url().optional(),
|
||||||
|
NEXT_PUBLIC_TARGET: z
|
||||||
|
.enum(["development", "testing", "staging", "production"])
|
||||||
|
.optional(),
|
||||||
|
TARGET: z
|
||||||
|
.enum(["development", "testing", "staging", "production"])
|
||||||
|
.optional(),
|
||||||
|
|
||||||
// Analytics (Proxy Pattern)
|
// Analytics (Proxy Pattern)
|
||||||
UMAMI_WEBSITE_ID: z.string().optional(),
|
UMAMI_WEBSITE_ID: z.string().optional(),
|
||||||
|
NEXT_PUBLIC_UMAMI_WEBSITE_ID: z.string().optional(),
|
||||||
UMAMI_API_ENDPOINT: z
|
UMAMI_API_ENDPOINT: z
|
||||||
.string()
|
.string()
|
||||||
.url()
|
.url()
|
||||||
@@ -23,6 +30,8 @@ export const mintelEnvSchema = {
|
|||||||
LOG_LEVEL: z
|
LOG_LEVEL: z
|
||||||
.enum(["trace", "debug", "info", "warn", "error", "fatal"])
|
.enum(["trace", "debug", "info", "warn", "error", "fatal"])
|
||||||
.default("info"),
|
.default("info"),
|
||||||
|
|
||||||
|
// Mail
|
||||||
MAIL_HOST: z.string().optional(),
|
MAIL_HOST: z.string().optional(),
|
||||||
MAIL_PORT: z.coerce.number().default(587),
|
MAIL_PORT: z.coerce.number().default(587),
|
||||||
MAIL_USERNAME: z.string().optional(),
|
MAIL_USERNAME: z.string().optional(),
|
||||||
@@ -32,13 +41,19 @@ export const mintelEnvSchema = {
|
|||||||
(val) => (typeof val === "string" ? val.split(",").filter(Boolean) : val),
|
(val) => (typeof val === "string" ? val.split(",").filter(Boolean) : val),
|
||||||
z.array(z.string()).default([]),
|
z.array(z.string()).default([]),
|
||||||
),
|
),
|
||||||
|
|
||||||
|
// Directus
|
||||||
|
DIRECTUS_URL: z.string().url().default("http://localhost:8055"),
|
||||||
|
DIRECTUS_ADMIN_EMAIL: z.string().optional(),
|
||||||
|
DIRECTUS_ADMIN_PASSWORD: z.string().optional(),
|
||||||
|
DIRECTUS_API_TOKEN: z.string().optional(),
|
||||||
|
INTERNAL_DIRECTUS_URL: z.string().url().optional(),
|
||||||
};
|
};
|
||||||
|
|
||||||
export function validateMintelEnv(schemaExtension = {}) {
|
export function validateMintelEnv<
|
||||||
const fullSchema = z.object({
|
T extends z.ZodRawShape = Record<string, never>,
|
||||||
...mintelEnvSchema,
|
>(schemaExtension: T = {} as T) {
|
||||||
...schemaExtension,
|
const fullSchema = z.object(mintelEnvSchema).extend(schemaExtension);
|
||||||
});
|
|
||||||
|
|
||||||
const isBuildTime =
|
const isBuildTime =
|
||||||
process.env.NEXT_PHASE === "phase-production-build" ||
|
process.env.NEXT_PHASE === "phase-production-build" ||
|
||||||
@@ -51,7 +66,7 @@ export function validateMintelEnv(schemaExtension = {}) {
|
|||||||
console.warn(
|
console.warn(
|
||||||
"⚠️ Some environment variables are missing during build, but skipping strict validation.",
|
"⚠️ Some environment variables are missing during build, but skipping strict validation.",
|
||||||
);
|
);
|
||||||
// Return partial data to allow build to continue
|
// Return process.env casted to the full schema type to unblock builds
|
||||||
return process.env as unknown as z.infer<typeof fullSchema>;
|
return process.env as unknown as z.infer<typeof fullSchema>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
packages:
|
packages:
|
||||||
- 'packages/*'
|
- 'packages/*'
|
||||||
- 'apps/*'
|
- 'apps/*'
|
||||||
- '../klz-2026'
|
|
||||||
|
|||||||
Reference in New Issue
Block a user