Files
ipal-kit/dist/modules/env/ipalEnvRules.js
T

106 lines
4.0 KiB
JavaScript

/**
* The env schema for a standard ipal-kit deploy, assembled from the features the
* project actually uses — so a site on local-disk storage isn't forced to set
* R2_*, and a site with no forms isn't forced to set Turnstile. Opt-in, not a
* fixed required set (A0: the plugin never demands config a project doesn't use).
*
* Variable names match what the plugin's own modules read (R2_*, GRAPH_*,
* NEXT_PUBLIC_SERVER_URL). DATABASE_URI and PAYLOAD_SECRET are Payload-core.
* Override any name via the options if your project names them differently.
*
* assertEnv(ipalEnvRules({ storage: true, emailGraph: true, turnstile: true }))
*
* Extend with project-specific vars by spreading:
*
* assertEnv([
* ...ipalEnvRules({ storage: true }),
* { name: 'MY_API_KEY', description: 'Third-party integration key' },
* ])
*/ export function ipalEnvRules(features = {}) {
const { databaseVar = 'DATABASE_URI', emailGraph = false, secretVar = 'PAYLOAD_SECRET', serverUrlVar = 'NEXT_PUBLIC_SERVER_URL', storage = false, turnstile = false } = features;
const rules = [
{
name: databaseVar,
description: 'Database connection string (e.g. MongoDB URI)'
},
{
name: secretVar,
description: 'Payload secret used to sign tokens'
},
{
name: serverUrlVar,
description: 'Public site origin, e.g. https://example.com',
kind: 'url'
},
{
name: 'NODE_ENV',
description: 'Node environment',
oneOf: [
'development',
'production',
'test'
],
required: false
}
];
if (storage) {
rules.push({
name: 'R2_BUCKET',
description: 'R2 bucket name'
}, {
name: 'R2_ACCESS_KEY_ID',
description: 'R2 access key id'
}, {
name: 'R2_SECRET_ACCESS_KEY',
description: 'R2 secret access key'
}, {
name: 'R2_ENDPOINT',
description: 'R2 S3 API endpoint URL',
kind: 'url'
}, {
name: 'R2_PUBLIC_URL',
description: 'Public base URL media is served from (custom domain of the bucket)',
// Production: absolute URL (https://media.example.com). Outside production a
// site-relative path ('/media') is accepted — buildR2Storage prefixes it with
// NEXT_PUBLIC_SERVER_URL (e.g. a dev rewrite /media → bucket).
validate: (v)=>{
if (/^https?:\/\/[^/\s]+/i.test(v)) {
return true;
}
if (v.startsWith('/') && process.env.NODE_ENV !== 'production') {
return true;
}
return v.startsWith('/') ? `R2_PUBLIC_URL must be an absolute URL in production (got "${v}") — e.g. https://media.example.com` : `R2_PUBLIC_URL must be an absolute URL (https://…) or, outside production, a path starting with "/" (got "${v}")`;
}
});
}
if (emailGraph) {
rules.push({
name: 'GRAPH_TENANT_ID',
description: 'Microsoft Graph tenant id'
}, {
name: 'GRAPH_CLIENT_ID',
description: 'Microsoft Graph client id'
}, {
name: 'GRAPH_CLIENT_SECRET',
description: 'Microsoft Graph client secret'
}, {
name: 'GRAPH_SENDER',
description: 'From-address mail is sent as',
kind: 'email'
});
}
if (turnstile) {
const names = typeof turnstile === 'object' ? turnstile : {};
rules.push({
name: names.siteKeyVar ?? 'NEXT_PUBLIC_TURNSTILE_SITE_KEY',
description: 'Cloudflare Turnstile public site key'
}, {
name: names.secretVar ?? 'TURNSTILE_SECRET_KEY',
description: 'Cloudflare Turnstile secret key'
});
}
return rules;
}
//# sourceMappingURL=ipalEnvRules.js.map