@platformatic/foundation 3.62.2 → 3.62.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -85,6 +85,7 @@ export type ConfigurationOptions<T = {}> = Partial<{
85
85
  replaceEnv: boolean
86
86
  replaceEnvIgnore: string[]
87
87
  onMissingEnv: (key: string) => string | undefined
88
+ strictEnv: boolean | 'warn'
88
89
  fixPaths: boolean
89
90
  logger: Logger
90
91
  root: string
@@ -181,6 +182,7 @@ export declare const SourceMissingError: FastifyError
181
182
  export declare const RootMissingError: FastifyError
182
183
  export declare const SchemaMustBeDefinedError: FastifyError
183
184
  export declare const ConfigurationDoesNotValidateAgainstSchemaError: FastifyError
185
+ export declare const MissingEnvVariablesError: FastifyError
184
186
 
185
187
  // Execution types
186
188
  export declare function executeWithTimeout<T> (promise: Promise<T>, timeout: number, timeoutValue?: any): Promise<T>
@@ -12,6 +12,7 @@ import {
12
12
  CannotParseConfigFileError,
13
13
  ConfigurationDoesNotValidateAgainstSchemaError,
14
14
  InvalidConfigFileExtensionError,
15
+ MissingEnvVariablesError,
15
16
  RootMissingError,
16
17
  SourceMissingError
17
18
  } from './errors.js'
@@ -442,6 +443,16 @@ export function replaceEnv (config, env, onMissingEnv, ignore) {
442
443
  return config
443
444
  }
444
445
 
446
+ function normalizeStrictEnv (value) {
447
+ if (value === 'warn') {
448
+ return 'warn'
449
+ } else if (value === 'false' || value === '') {
450
+ return false
451
+ }
452
+
453
+ return Boolean(value)
454
+ }
455
+
445
456
  export async function loadConfiguration (source, schema, options = {}) {
446
457
  const {
447
458
  validate: shouldValidate,
@@ -453,6 +464,7 @@ export async function loadConfiguration (source, schema, options = {}) {
453
464
  replaceEnv: shouldReplaceEnv,
454
465
  replaceEnvIgnore,
455
466
  onMissingEnv,
467
+ strictEnv: strictEnvOption,
456
468
  fixPaths,
457
469
  logger,
458
470
  skipMetadata,
@@ -487,7 +499,42 @@ export async function loadConfiguration (source, schema, options = {}) {
487
499
  env.PLT_ROOT = root
488
500
 
489
501
  if (shouldReplaceEnv) {
490
- config = replaceEnv(config, env, onMissingEnv, replaceEnvIgnore)
502
+ const missingEnv = new Set()
503
+
504
+ config = replaceEnv(
505
+ config,
506
+ env,
507
+ key => {
508
+ const value = onMissingEnv?.(key)
509
+
510
+ if (typeof value === 'undefined' || value === null) {
511
+ missingEnv.add(key)
512
+ }
513
+
514
+ return value
515
+ },
516
+ replaceEnvIgnore
517
+ )
518
+
519
+ // strictEnv can be set programmatically or in the configuration file itself, either at the top level
520
+ // (runtime configurations) or in the runtime property (capabilities configurations).
521
+ const strictEnv = normalizeStrictEnv(strictEnvOption ?? config.strictEnv ?? config.runtime?.strictEnv)
522
+
523
+ if (strictEnv && missingEnv.size > 0) {
524
+ const keys = Array.from(missingEnv).sort().join(', ')
525
+
526
+ if (strictEnv === 'warn') {
527
+ const message = `The configuration references the following environment variables which are not set: ${keys}`
528
+
529
+ if (logger) {
530
+ logger.warn(message)
531
+ } else {
532
+ process.emitWarning(message)
533
+ }
534
+ } else {
535
+ throw new MissingEnvVariablesError(keys)
536
+ }
537
+ }
491
538
  }
492
539
 
493
540
  const moduleInfo = extractModuleFromSchemaUrl(config)
package/lib/errors.js CHANGED
@@ -56,3 +56,7 @@ export const ConfigurationDoesNotValidateAgainstSchemaError = createError(
56
56
  `${ERROR_PREFIX}_CONFIGURATION_DOES_NOT_VALIDATE_AGAINST_SCHEMA`,
57
57
  'The configuration does not validate against the configuration schema'
58
58
  )
59
+ export const MissingEnvVariablesError = createError(
60
+ `${ERROR_PREFIX}_MISSING_ENV_VARIABLES`,
61
+ 'The configuration references the following environment variables which are not set: %s'
62
+ )
package/lib/module.js CHANGED
@@ -17,6 +17,11 @@ export const applicationTypes = [
17
17
  { name: '@platformatic/next', label: 'Next.js', dependencies: ['next'] },
18
18
  { name: '@platformatic/remix', label: 'Remix', dependencies: ['@remix-run/dev'] },
19
19
  { name: '@platformatic/astro', label: 'Astro', dependencies: ['astro'] },
20
+ { name: '@platformatic/react-router', label: 'React Router', dependencies: ['@react-router/dev'] },
21
+ { name: '@platformatic/nuxt', label: 'Nuxt', dependencies: ['nuxt'] },
22
+ { name: '@platformatic/tanstack', label: 'TanStack Start', dependencies: ['@tanstack/react-start'] },
23
+ // Nitro applications often use Vite, so Nitro must be checked first.
24
+ { name: '@platformatic/nitro', label: 'Nitro', dependencies: ['nitro', 'nitropack'] },
20
25
  // Since Vite is often used with other frameworks, we must check for Vite last amongst frontend frameworks
21
26
  { name: '@platformatic/vite', label: 'Vite', dependencies: ['vite'] },
22
27
  {
package/lib/schema.js CHANGED
@@ -1533,6 +1533,11 @@ export const runtimeProperties = {
1533
1533
  envfile: {
1534
1534
  type: 'string'
1535
1535
  },
1536
+ strictEnv: {
1537
+ anyOf: [{ type: 'boolean' }, { type: 'string' }],
1538
+ description:
1539
+ 'When set to true, the configuration loading fails if a {PLT_*} placeholder references an environment variable which is not set. When set to "warn", a warning listing the missing variables is logged but the placeholders are still replaced with an empty string. Defaults to false.'
1540
+ },
1536
1541
  sourceMaps: {
1537
1542
  type: 'boolean',
1538
1543
  default: false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/foundation",
3
- "version": "3.62.2",
3
+ "version": "3.62.4",
4
4
  "description": "Platformatic Foundation",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -37,7 +37,7 @@
37
37
  "c8": "^11.0.0",
38
38
  "cleaner-spec-reporter": "^0.5.0",
39
39
  "eslint": "9",
40
- "fastify": "^5.7.0",
40
+ "fastify": "^5.0.0",
41
41
  "neostandard": "^0.12.0",
42
42
  "pino": "^9.9.0",
43
43
  "pino-test": "^1.0.1",