104 lines
3.6 KiB
TypeScript
104 lines
3.6 KiB
TypeScript
import type { EnvRule } from './assertEnv.js'
|
|
|
|
type TurnstileNames = { secretVar?: string; siteKeyVar?: string }
|
|
|
|
export type IpalEnvFeatures = {
|
|
/** Override the database var. Default 'DATABASE_URI'. */
|
|
databaseVar?: string
|
|
/** Microsoft Graph e-mail (graphAdapter). Adds the GRAPH_* vars. */
|
|
emailGraph?: boolean
|
|
/** Override the Payload secret var. Default 'PAYLOAD_SECRET'. */
|
|
secretVar?: string
|
|
/** Override the site-URL var. Default 'NEXT_PUBLIC_SERVER_URL'. */
|
|
serverUrlVar?: string
|
|
/** R2 object storage (buildR2Storage). Adds the R2_* vars. */
|
|
storage?: boolean
|
|
/**
|
|
* Cloudflare Turnstile. true uses the common var names
|
|
* (NEXT_PUBLIC_TURNSTILE_SITE_KEY + TURNSTILE_SECRET_KEY); pass an object to
|
|
* override either name if your project differs.
|
|
*/
|
|
turnstile?: boolean | TurnstileNames
|
|
}
|
|
|
|
/**
|
|
* 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: IpalEnvFeatures = {}): EnvRule[] {
|
|
const {
|
|
databaseVar = 'DATABASE_URI',
|
|
emailGraph = false,
|
|
secretVar = 'PAYLOAD_SECRET',
|
|
serverUrlVar = 'NEXT_PUBLIC_SERVER_URL',
|
|
storage = false,
|
|
turnstile = false,
|
|
} = features
|
|
|
|
const rules: EnvRule[] = [
|
|
{ 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', kind: 'url' },
|
|
)
|
|
}
|
|
|
|
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
|
|
}
|