@dyanet/nextjs-config-aws 1.0.0-beta.1

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.
Files changed (50) hide show
  1. package/README.md +458 -0
  2. package/dist/cjs/client/env.js +104 -0
  3. package/dist/cjs/client/env.js.map +1 -0
  4. package/dist/cjs/client/index.js +15 -0
  5. package/dist/cjs/client/index.js.map +1 -0
  6. package/dist/cjs/components/index.js +11 -0
  7. package/dist/cjs/components/index.js.map +1 -0
  8. package/dist/cjs/components/public-env-script.js +145 -0
  9. package/dist/cjs/components/public-env-script.js.map +1 -0
  10. package/dist/cjs/index.js +46 -0
  11. package/dist/cjs/index.js.map +1 -0
  12. package/dist/cjs/server/config-provider.js +99 -0
  13. package/dist/cjs/server/config-provider.js.map +1 -0
  14. package/dist/cjs/server/get-config.js +153 -0
  15. package/dist/cjs/server/get-config.js.map +1 -0
  16. package/dist/cjs/server/index.js +17 -0
  17. package/dist/cjs/server/index.js.map +1 -0
  18. package/dist/esm/client/env.js +98 -0
  19. package/dist/esm/client/env.js.map +1 -0
  20. package/dist/esm/client/index.js +8 -0
  21. package/dist/esm/client/index.js.map +1 -0
  22. package/dist/esm/components/index.js +5 -0
  23. package/dist/esm/components/index.js.map +1 -0
  24. package/dist/esm/components/public-env-script.js +107 -0
  25. package/dist/esm/components/public-env-script.js.map +1 -0
  26. package/dist/esm/index.js +15 -0
  27. package/dist/esm/index.js.map +1 -0
  28. package/dist/esm/server/config-provider.js +95 -0
  29. package/dist/esm/server/config-provider.js.map +1 -0
  30. package/dist/esm/server/get-config.js +145 -0
  31. package/dist/esm/server/get-config.js.map +1 -0
  32. package/dist/esm/server/index.js +6 -0
  33. package/dist/esm/server/index.js.map +1 -0
  34. package/dist/types/client/env.d.ts +116 -0
  35. package/dist/types/client/env.d.ts.map +1 -0
  36. package/dist/types/client/index.d.ts +8 -0
  37. package/dist/types/client/index.d.ts.map +1 -0
  38. package/dist/types/components/index.d.ts +5 -0
  39. package/dist/types/components/index.d.ts.map +1 -0
  40. package/dist/types/components/public-env-script.d.ts +91 -0
  41. package/dist/types/components/public-env-script.d.ts.map +1 -0
  42. package/dist/types/index.d.ts +13 -0
  43. package/dist/types/index.d.ts.map +1 -0
  44. package/dist/types/server/config-provider.d.ts +80 -0
  45. package/dist/types/server/config-provider.d.ts.map +1 -0
  46. package/dist/types/server/get-config.d.ts +86 -0
  47. package/dist/types/server/get-config.d.ts.map +1 -0
  48. package/dist/types/server/index.d.ts +6 -0
  49. package/dist/types/server/index.d.ts.map +1 -0
  50. package/package.json +90 -0
@@ -0,0 +1,107 @@
1
+ /**
2
+ * PublicEnvScript - Server component for exposing environment variables to the client.
3
+ *
4
+ * This component renders a script tag that injects server-side environment variables
5
+ * into the client-side JavaScript context, enabling runtime environment variable access
6
+ * without requiring NEXT_PUBLIC_ prefixes at build time.
7
+ *
8
+ * @example
9
+ * ```tsx
10
+ * // In your root layout.tsx
11
+ * import { PublicEnvScript } from '@dyanet/nextjs-config-aws';
12
+ *
13
+ * export default function RootLayout({ children }) {
14
+ * return (
15
+ * <html>
16
+ * <head>
17
+ * <PublicEnvScript
18
+ * publicVars={['API_URL', 'APP_NAME']}
19
+ * variableName="__ENV"
20
+ * />
21
+ * </head>
22
+ * <body>{children}</body>
23
+ * </html>
24
+ * );
25
+ * }
26
+ * ```
27
+ */
28
+ import * as React from 'react';
29
+ /**
30
+ * Filters environment variables based on allowlist or prefix.
31
+ *
32
+ * @param env - The environment variables object (typically process.env)
33
+ * @param publicVars - Optional explicit list of variable names to include
34
+ * @param publicPrefix - Optional prefix to filter variables
35
+ * @returns Filtered environment variables object
36
+ */
37
+ export function filterEnvVars(env, publicVars, publicPrefix) {
38
+ const result = {};
39
+ // If explicit allowlist is provided, use it
40
+ if (publicVars && publicVars.length > 0) {
41
+ for (const key of publicVars) {
42
+ const value = env[key];
43
+ if (value !== undefined) {
44
+ result[key] = value;
45
+ }
46
+ }
47
+ return result;
48
+ }
49
+ // If prefix is provided, filter by prefix
50
+ if (publicPrefix) {
51
+ for (const [key, value] of Object.entries(env)) {
52
+ if (key.startsWith(publicPrefix) && value !== undefined) {
53
+ result[key] = value;
54
+ }
55
+ }
56
+ return result;
57
+ }
58
+ // If neither is provided, return empty object (safe default)
59
+ return result;
60
+ }
61
+ /**
62
+ * Generates the script content for injecting environment variables.
63
+ *
64
+ * @param filteredEnv - The filtered environment variables to expose
65
+ * @param variableName - The global variable name to use
66
+ * @returns The script content as a string
67
+ */
68
+ export function generateScriptContent(filteredEnv, variableName) {
69
+ const jsonString = JSON.stringify(filteredEnv);
70
+ return `window.${variableName}=${jsonString};`;
71
+ }
72
+ /**
73
+ * Server component that renders a script tag exposing environment variables to the client.
74
+ *
75
+ * This enables runtime environment variable access in Next.js applications without
76
+ * requiring NEXT_PUBLIC_ prefixes at build time. The same build artifact can be
77
+ * deployed to different environments with different configuration.
78
+ *
79
+ * Security considerations:
80
+ * - Only expose variables that are safe for public access
81
+ * - Use the publicVars allowlist for explicit control
82
+ * - Never expose secrets, API keys, or sensitive data
83
+ *
84
+ * @param props - Component props
85
+ * @returns A script element with environment variables, or null if no variables to expose
86
+ */
87
+ export function PublicEnvScript({ publicVars, publicPrefix, variableName = '__ENV', nonce, }) {
88
+ // Filter environment variables based on allowlist or prefix
89
+ const filteredEnv = filterEnvVars(process.env, publicVars, publicPrefix);
90
+ // If no variables to expose, render nothing
91
+ if (Object.keys(filteredEnv).length === 0) {
92
+ return null;
93
+ }
94
+ // Generate the script content
95
+ const scriptContent = generateScriptContent(filteredEnv, variableName);
96
+ // Build script props
97
+ const scriptProps = {
98
+ dangerouslySetInnerHTML: { __html: scriptContent },
99
+ };
100
+ // Add nonce if provided for CSP compliance
101
+ if (nonce) {
102
+ scriptProps.nonce = nonce;
103
+ }
104
+ return React.createElement('script', scriptProps);
105
+ }
106
+ export default PublicEnvScript;
107
+ //# sourceMappingURL=public-env-script.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"public-env-script.js","sour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C,EAC9B,UAAU,EACV,YAAY,EACZ,YAAY,GAAG,OAAO,EACtB,KAAK,GACgB;IACrB,4DAA4D;IAC5D,MAAM,WAAW,GAAG,aAAa,CAAC,OAAO,CAAC,GAAyC,EAAE,UAAU,EAAE,YAAY,CAAC,CAAC;IAE/G,4CAA4C;IAC5C,IAAI,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1C,OAAO,IAAI,CAAC;IACd,CAAC;IAED,8BAA8B;IAC9B,MAAM,aAAa,GAAG,qBAAqB,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;IAEvE,qBAAqB;IACrB,MAAM,WAAW,GAAkD;QACjE,uBAAuB,EAAE,EAAE,MAAM,EAAE,aAAa,EAAE;KACnD,CAAC;IAEF,2CAA2C;IAC3C,IAAI,KAAK,EAAE,CAAC;QACV,WAAW,CAAC,KAAK,GAAG,KAAK,CAAC;IAC5B,CAAC;IAED,OAAO,KAAK,CAAC,aAAa,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;AACpD,CAAC;AAED,eAAe,eAAe,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @dyanet/nextjs-config-aws
3
+ *
4
+ * Next.js adapter for AWS configuration management.
5
+ * Provides server-side configuration loading, React context providers,
6
+ * and runtime environment variable support for Next.js applications.
7
+ */
8
+ export { ConfigurationError, ValidationError, AWSServiceError, ConfigurationLoadError, MissingConfigurationError, EnvironmentLoader, EnvFileLoader, S3Loader, SecretsManagerLoader, SSMParameterStoreLoader, ConfigManager, ConfigValidationUtil, EnvFileParser, } from '@dyanet/config-aws';
9
+ // Server-side exports
10
+ export { getConfig, clearConfigCache, getConfigCacheSize, invalidateConfig, createConfigProvider, ConfigProvider, useConfig, ConfigContext, } from './server';
11
+ // Components for runtime environment variables
12
+ export { PublicEnvScript, filterEnvVars, generateScriptContent, } from './components';
13
+ // Client-side environment variable access
14
+ export { env, envFrom, getAllEnv, hasEnv } from './client';
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAoBH,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,sBAAsB,EACtB,yBAAyB,EACzB,iBAAiB,EACjB,aAAa,EACb,QAAQ,EACR,oBAAoB,EACpB,uBAAuB,EACvB,aAAa,EACb,oBAAoB,EACpB,aAAa,GACd,MAAM,oBAAoB,CAAC;AAE5B,sBAAsB;AACtB,OAAO,EACL,SAAS,EACT,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAEhB,oBAAoB,EACpB,cAAc,EACd,SAAS,EACT,aAAa,GACd,MAAM,UAAU,CAAC;AAElB,+CAA+C;AAC/C,OAAO,EACL,eAAe,EACf,aAAa,EACb,qBAAqB,GAEtB,MAAM,cAAc,CAAC;AAEtB,0CAA0C;AAC1C,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC"}
@@ -0,0 +1,95 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * React context provider for server-side configuration in Next.js applications.
4
+ * Provides a way to access configuration values in server components.
5
+ */
6
+ import { createContext, useContext } from 'react';
7
+ /**
8
+ * Creates a typed configuration provider and hook for accessing configuration
9
+ * in React server components.
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * import { createConfigProvider, getConfig } from '@dyanet/nextjs-config-aws';
14
+ * import { z } from 'zod';
15
+ *
16
+ * const schema = z.object({
17
+ * DATABASE_URL: z.string(),
18
+ * API_KEY: z.string(),
19
+ * });
20
+ *
21
+ * type AppConfig = z.infer<typeof schema>;
22
+ *
23
+ * // Create the provider and hook
24
+ * const { ConfigProvider, useConfig } = createConfigProvider<AppConfig>();
25
+ *
26
+ * // In your layout.tsx (Server Component)
27
+ * export default async function RootLayout({ children }) {
28
+ * const config = await getConfig({ schema });
29
+ *
30
+ * return (
31
+ * <html>
32
+ * <body>
33
+ * <ConfigProvider config={config}>
34
+ * {children}
35
+ * </ConfigProvider>
36
+ * </body>
37
+ * </html>
38
+ * );
39
+ * }
40
+ *
41
+ * // In a child component
42
+ * function MyComponent() {
43
+ * const config = useConfig();
44
+ * return <div>API Key: {config.API_KEY}</div>;
45
+ * }
46
+ * ```
47
+ *
48
+ * @returns An object containing the ConfigProvider component and useConfig hook
49
+ */
50
+ export function createConfigProvider() {
51
+ // Create a context with null as default (will be provided by ConfigProvider)
52
+ const ConfigContext = createContext(null);
53
+ /**
54
+ * Provider component that wraps children with configuration context
55
+ */
56
+ function ConfigProvider({ children, config }) {
57
+ const value = { config };
58
+ return (_jsx(ConfigContext.Provider, { value: value, children: children }));
59
+ }
60
+ /**
61
+ * Hook to access configuration from the context
62
+ * @throws Error if used outside of ConfigProvider
63
+ */
64
+ function useConfig() {
65
+ const context = useContext(ConfigContext);
66
+ if (context === null) {
67
+ throw new Error('useConfig must be used within a ConfigProvider. ' +
68
+ 'Make sure to wrap your component tree with ConfigProvider.');
69
+ }
70
+ return context.config;
71
+ }
72
+ return {
73
+ ConfigProvider,
74
+ useConfig,
75
+ ConfigContext,
76
+ };
77
+ }
78
+ /**
79
+ * Default configuration context and provider for simple use cases.
80
+ * For typed configuration, use createConfigProvider<T>() instead.
81
+ */
82
+ const defaultProvider = createConfigProvider();
83
+ /**
84
+ * Default ConfigProvider for untyped configuration
85
+ */
86
+ export const ConfigProvider = defaultProvider.ConfigProvider;
87
+ /**
88
+ * Default useConfig hook for untyped configuration
89
+ */
90
+ export const useConfig = defaultProvider.useConfig;
91
+ /**
92
+ * Default ConfigContext for untyped configuration
93
+ */
94
+ export const ConfigContext = defaultProvider.ConfigContext;
95
+ //# sourceMappingURL=config-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-provider.js","sourceRoot":"","sources":["../../../src/server/config-provider.tsx"],"names":[],"mappings":";AAAA;;;GAGG;AAEH,OAAc,EAAE,aAAa,EAAE,UAAU,EAAkB,MAAM,OAAO,CAAC;AAiBzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,MAAM,UAAU,oBAAoB;IAKlC,6EAA6E;IAC7E,MAAM,aAAa,GAAG,aAAa,CAA+B,IAAI,CAAC,CAAC;IAExE;;OAEG;IACH,SAAS,cAAc,CAAC,EAAE,QAAQ,EAAE,MAAM,EAA0B;QAClE,MAAM,KAAK,GAA0B,EAAE,MAAM,EAAE,CAAC;QAEhD,OAAO,CACL,KAAC,aAAa,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YACjC,QAAQ,GACc,CAC1B,CAAC;IACJ,CAAC;IAED;;;OAGG;IACH,SAAS,SAAS;QAChB,MAAM,OAAO,GAAG,UAAU,CAAC,aAAa,CAAC,CAAC;QAE1C,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CACb,kDAAkD;gBAClD,4DAA4D,CAC7D,CAAC;QACJ,CAAC;QAED,OAAO,OAAO,CAAC,MAAM,CAAC;IACxB,CAAC;IAED,OAAO;QACL,cAAc;QACd,SAAS;QACT,aAAa;KACd,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,eAAe,GAAG,oBAAoB,EAA2B,CAAC;AAExE;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,eAAe,CAAC,cAAc,CAAC;AAE7D;;GAEG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,eAAe,CAAC,SAAS,CAAC;AAEnD;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,eAAe,CAAC,aAAa,CAAC"}
@@ -0,0 +1,145 @@
1
+ /**
2
+ * Server-side configuration loading for Next.js applications.
3
+ * Provides a cached getConfig() function that uses ConfigManager from @dyanet/config-aws.
4
+ */
5
+ import { ConfigManager, } from '@dyanet/config-aws';
6
+ /**
7
+ * Cache storage for configuration
8
+ * Uses a Map to support multiple cache keys (for different option combinations)
9
+ */
10
+ const configCache = new Map();
11
+ /**
12
+ * Track AWS API call counts for testing purposes
13
+ * @internal
14
+ */
15
+ let awsApiCallCount = 0;
16
+ /**
17
+ * Generate a cache key from options
18
+ * @internal
19
+ */
20
+ function generateCacheKey(options) {
21
+ const loaderNames = options.loaders?.map((l) => l.getName()).join(',') ?? '';
22
+ const precedence = Array.isArray(options.precedence)
23
+ ? options.precedence.map((p) => `${p.loader}:${p.priority}`).join(',')
24
+ : options.precedence ?? 'aws-first';
25
+ return `${loaderNames}|${precedence}`;
26
+ }
27
+ /**
28
+ * Check if a cache entry is still valid
29
+ * @internal
30
+ */
31
+ function isCacheValid(entry) {
32
+ if (!entry)
33
+ return false;
34
+ return Date.now() < entry.expiresAt;
35
+ }
36
+ /**
37
+ * Load configuration for Next.js server-side use.
38
+ *
39
+ * This function provides caching to avoid repeated AWS API calls during request handling.
40
+ * Configuration is cached based on the loader configuration and precedence strategy.
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * import { getConfig, EnvironmentLoader, SecretsManagerLoader } from '@dyanet/nextjs-config-aws';
45
+ * import { z } from 'zod';
46
+ *
47
+ * const schema = z.object({
48
+ * DATABASE_URL: z.string(),
49
+ * API_KEY: z.string(),
50
+ * });
51
+ *
52
+ * // In a Server Component or API route
53
+ * export default async function Page() {
54
+ * const config = await getConfig({
55
+ * schema,
56
+ * loaders: [
57
+ * new EnvironmentLoader(),
58
+ * new SecretsManagerLoader({ secretName: '/my-app/config' }),
59
+ * ],
60
+ * precedence: 'aws-first',
61
+ * });
62
+ *
63
+ * return <div>DB: {config.DATABASE_URL}</div>;
64
+ * }
65
+ * ```
66
+ *
67
+ * @param options Configuration options
68
+ * @returns Promise resolving to the validated configuration object
69
+ */
70
+ export async function getConfig(options = {}) {
71
+ const { schema, loaders = [], precedence = 'aws-first', cache = true, cacheTTL = 60000, // 1 minute default
72
+ enableLogging = false, } = options;
73
+ // Generate cache key
74
+ const cacheKey = generateCacheKey(options);
75
+ // Check cache if enabled
76
+ if (cache) {
77
+ const cached = configCache.get(cacheKey);
78
+ if (isCacheValid(cached)) {
79
+ return cached.config;
80
+ }
81
+ }
82
+ // Increment API call counter (for testing)
83
+ awsApiCallCount++;
84
+ // Create ConfigManager with provided options
85
+ const managerOptions = {
86
+ loaders,
87
+ schema,
88
+ precedence,
89
+ validateOnLoad: true,
90
+ enableLogging,
91
+ };
92
+ const manager = new ConfigManager(managerOptions);
93
+ await manager.load();
94
+ const config = manager.getAll();
95
+ const loadResult = manager.getLoadResult();
96
+ // Store in cache if enabled
97
+ if (cache && loadResult) {
98
+ const entry = {
99
+ config,
100
+ loadResult,
101
+ expiresAt: Date.now() + cacheTTL,
102
+ };
103
+ configCache.set(cacheKey, entry);
104
+ }
105
+ return config;
106
+ }
107
+ /**
108
+ * Clear the configuration cache.
109
+ * Useful for testing or when configuration needs to be reloaded.
110
+ */
111
+ export function clearConfigCache() {
112
+ configCache.clear();
113
+ }
114
+ /**
115
+ * Get the current cache size.
116
+ * @returns Number of cached configurations
117
+ */
118
+ export function getConfigCacheSize() {
119
+ return configCache.size;
120
+ }
121
+ /**
122
+ * Get the AWS API call count.
123
+ * This is primarily for testing the caching behavior.
124
+ * @internal
125
+ */
126
+ export function getAwsApiCallCount() {
127
+ return awsApiCallCount;
128
+ }
129
+ /**
130
+ * Reset the AWS API call count.
131
+ * This is primarily for testing the caching behavior.
132
+ * @internal
133
+ */
134
+ export function resetAwsApiCallCount() {
135
+ awsApiCallCount = 0;
136
+ }
137
+ /**
138
+ * Invalidate a specific cache entry by regenerating with the same options.
139
+ * @param options The options used to create the cache entry
140
+ */
141
+ export function invalidateConfig(options) {
142
+ const cacheKey = generateCacheKey(options);
143
+ configCache.delete(cacheKey);
144
+ }
145
+ //# sourceMappingURL=get-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-config.js","sourceRoot":"","sources":["../../../src/server/get-config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO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B,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAI,OAA6B;IAC/D,MAAM,QAAQ,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAC3C,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AAC/B,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Server-side exports for Next.js configuration management.
3
+ */
4
+ export { getConfig, clearConfigCache, getConfigCacheSize, invalidateConfig, } from './get-config';
5
+ export { createConfigProvider, ConfigProvider, useConfig, ConfigContext, } from './config-provider';
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,SAAS,EACT,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,GAEjB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,oBAAoB,EACpB,cAAc,EACd,SAAS,EACT,aAAa,GACd,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,116 @@
1
+ /**
2
+ * Client-side environment variable access for Next.js applications.
3
+ *
4
+ * This module provides a function to read runtime environment variables
5
+ * that were injected by the PublicEnvScript server component.
6
+ *
7
+ * @example
8
+ * ```tsx
9
+ * 'use client';
10
+ *
11
+ * import { env } from '@dyanet/nextjs-config-aws/client';
12
+ *
13
+ * function MyComponent() {
14
+ * const apiUrl = env('API_URL');
15
+ * const appName = env('APP_NAME', 'Default App');
16
+ *
17
+ * return <div>API: {apiUrl}, App: {appName}</div>;
18
+ * }
19
+ * ```
20
+ */
21
+ /**
22
+ * Type declaration for the global window object with environment variables.
23
+ */
24
+ declare global {
25
+ interface Window {
26
+ __ENV?: Record<string, string>;
27
+ [key: string]: unknown;
28
+ }
29
+ }
30
+ /**
31
+ * Retrieves a runtime environment variable value.
32
+ *
33
+ * This function reads from the global window object where environment
34
+ * variables were injected by the PublicEnvScript component.
35
+ *
36
+ * @param key - The environment variable name
37
+ * @returns The value of the environment variable, or undefined if not found
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * const apiUrl = env('API_URL');
42
+ * if (apiUrl) {
43
+ * // Use the API URL
44
+ * }
45
+ * ```
46
+ */
47
+ export declare function env(key: string): string | undefined;
48
+ /**
49
+ * Retrieves a runtime environment variable value with a default.
50
+ *
51
+ * @param key - The environment variable name
52
+ * @param defaultValue - The default value to return if the variable is not found
53
+ * @returns The value of the environment variable, or the default value
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * const apiUrl = env('API_URL', 'http://localhost:3000');
58
+ * // apiUrl is guaranteed to be a string
59
+ * ```
60
+ */
61
+ export declare function env<T>(key: string, defaultValue: T): string | T;
62
+ /**
63
+ * Retrieves a runtime environment variable from a custom variable name.
64
+ *
65
+ * Use this when you've configured PublicEnvScript with a custom variableName.
66
+ *
67
+ * @param variableName - The global variable name to read from
68
+ * @param key - The environment variable name
69
+ * @returns The value of the environment variable, or undefined if not found
70
+ *
71
+ * @example
72
+ * ```ts
73
+ * // If PublicEnvScript was configured with variableName="__MY_ENV"
74
+ * const apiUrl = envFrom('__MY_ENV', 'API_URL');
75
+ * ```
76
+ */
77
+ export declare function envFrom(variableName: string, key: string): string | undefined;
78
+ /**
79
+ * Retrieves a runtime environment variable from a custom variable name with a default.
80
+ *
81
+ * @param variableName - The global variable name to read from
82
+ * @param key - The environment variable name
83
+ * @param defaultValue - The default value to return if the variable is not found
84
+ * @returns The value of the environment variable, or the default value
85
+ */
86
+ export declare function envFrom<T>(variableName: string, key: string, defaultValue: T): string | T;
87
+ /**
88
+ * Gets all runtime environment variables.
89
+ *
90
+ * @param variableName - The global variable name to read from (default: '__ENV')
91
+ * @returns A copy of all environment variables
92
+ *
93
+ * @example
94
+ * ```ts
95
+ * const allEnv = getAllEnv();
96
+ * console.log(allEnv); // { API_URL: '...', APP_NAME: '...' }
97
+ * ```
98
+ */
99
+ export declare function getAllEnv(variableName?: string): Record<string, string>;
100
+ /**
101
+ * Checks if a runtime environment variable exists.
102
+ *
103
+ * @param key - The environment variable name
104
+ * @param variableName - The global variable name to read from (default: '__ENV')
105
+ * @returns True if the variable exists, false otherwise
106
+ *
107
+ * @example
108
+ * ```ts
109
+ * if (hasEnv('FEATURE_FLAG')) {
110
+ * // Feature is enabled
111
+ * }
112
+ * ```
113
+ */
114
+ export declare function hasEnv(key: string, variableName?: string): boolean;
115
+ export default env;
116
+ //# sourceMappingURL=env.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../../src/client/env.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH;;GAEG;AACH,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC/B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACxB;CACF;AA2BD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;AAErD;;;;;;;;;;;;GAYG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,GAAG,MAAM,GAAG,CAAC,CAAC;AAgBjE;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,OAAO,CAAC,YAAY,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;AAE/E;;;;;;;GAOG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,GAAG,MAAM,GAAG,CAAC,CAAC;AAgB3F;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAC,YAAY,GAAE,MAA8B,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAE9F;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,GAAE,MAA8B,GAAG,OAAO,CAGzF;AAED,eAAe,GAAG,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Client-side exports for Next.js configuration management.
3
+ *
4
+ * These utilities are designed for use in client components ('use client')
5
+ * to access runtime environment variables injected by PublicEnvScript.
6
+ */
7
+ export { env, envFrom, getAllEnv, hasEnv } from './env';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Client-side components for Next.js configuration management.
3
+ */
4
+ export { PublicEnvScript, filterEnvVars, generateScriptContent, type PublicEnvScriptProps, } from './public-env-script';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,eAAe,EACf,aAAa,EACb,qBAAqB,EACrB,KAAK,oBAAoB,GAC1B,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,91 @@
1
+ /**
2
+ * PublicEnvScript - Server component for exposing environment variables to the client.
3
+ *
4
+ * This component renders a script tag that injects server-side environment variables
5
+ * into the client-side JavaScript context, enabling runtime environment variable access
6
+ * without requiring NEXT_PUBLIC_ prefixes at build time.
7
+ *
8
+ * @example
9
+ * ```tsx
10
+ * // In your root layout.tsx
11
+ * import { PublicEnvScript } from '@dyanet/nextjs-config-aws';
12
+ *
13
+ * export default function RootLayout({ children }) {
14
+ * return (
15
+ * <html>
16
+ * <head>
17
+ * <PublicEnvScript
18
+ * publicVars={['API_URL', 'APP_NAME']}
19
+ * variableName="__ENV"
20
+ * />
21
+ * </head>
22
+ * <body>{children}</body>
23
+ * </html>
24
+ * );
25
+ * }
26
+ * ```
27
+ */
28
+ import * as React from 'react';
29
+ /**
30
+ * Props for the PublicEnvScript component.
31
+ */
32
+ export interface PublicEnvScriptProps {
33
+ /**
34
+ * Explicit list of environment variable names to expose to the client.
35
+ * Only variables in this list will be included in the output.
36
+ * Takes precedence over publicPrefix if both are provided.
37
+ */
38
+ publicVars?: string[];
39
+ /**
40
+ * Prefix to filter environment variables.
41
+ * Only variables starting with this prefix will be included.
42
+ * The prefix is NOT stripped from the variable names in the output.
43
+ * @example 'PUBLIC_' will include PUBLIC_API_URL, PUBLIC_APP_NAME, etc.
44
+ */
45
+ publicPrefix?: string;
46
+ /**
47
+ * The global variable name used to expose environment variables on the client.
48
+ * @default '__ENV'
49
+ */
50
+ variableName?: string;
51
+ /**
52
+ * CSP nonce for script tag compliance with Content Security Policy.
53
+ * If provided, adds a nonce attribute to the script tag.
54
+ */
55
+ nonce?: string;
56
+ }
57
+ /**
58
+ * Filters environment variables based on allowlist or prefix.
59
+ *
60
+ * @param env - The environment variables object (typically process.env)
61
+ * @param publicVars - Optional explicit list of variable names to include
62
+ * @param publicPrefix - Optional prefix to filter variables
63
+ * @returns Filtered environment variables object
64
+ */
65
+ export declare function filterEnvVars(env: Record<string, string | undefined>, publicVars?: string[], publicPrefix?: string): Record<string, string>;
66
+ /**
67
+ * Generates the script content for injecting environment variables.
68
+ *
69
+ * @param filteredEnv - The filtered environment variables to expose
70
+ * @param variableName - The global variable name to use
71
+ * @returns The script content as a string
72
+ */
73
+ export declare function generateScriptContent(filteredEnv: Record<string, string>, variableName: string): string;
74
+ /**
75
+ * Server component that renders a script tag exposing environment variables to the client.
76
+ *
77
+ * This enables runtime environment variable access in Next.js applications without
78
+ * requiring NEXT_PUBLIC_ prefixes at build time. The same build artifact can be
79
+ * deployed to different environments with different configuration.
80
+ *
81
+ * Security considerations:
82
+ * - Only expose variables that are safe for public access
83
+ * - Use the publicVars allowlist for explicit control
84
+ * - Never expose secrets, API keys, or sensitive data
85
+ *
86
+ * @param props - Component props
87
+ * @returns A script element with environment variables, or null if no variables to expose
88
+ */
89
+ export declare function PublicEnvScript({ publicVars, publicPrefix, variableName, nonce, }: PublicEnvScriptProps): React.ReactElement | null;
90
+ export default PublicEnvScript;
91
+ //# sourceMappingURL=public-env-script.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"public-env-script.d.ts","sourceRoot":"","sources":["../../../src/components/public-env-script.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IAEtB;;;;;OAKG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAC3B,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,EACvC,UAAU,CAAC,EAAE,MAAM,EAAE,EACrB,YAAY,CAAC,EAAE,MAAM,GACpB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CA0BxB;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACnC,YAAY,EAAE,MAAM,GACnB,MAAM,CAGR;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,eAAe,CAAC,EAC9B,UAAU,EACV,YAAY,EACZ,YAAsB,EACtB,KAAK,GACN,EAAE,oBAAoB,GAAG,KAAK,CAAC,YAAY,GAAG,IAAI,CAuBlD;AAED,eAAe,eAAe,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @dyanet/nextjs-config-aws
3
+ *
4
+ * Next.js adapter for AWS configuration management.
5
+ * Provides server-side configuration loading, React context providers,
6
+ * and runtime environment variable support for Next.js applications.
7
+ */
8
+ export type { ConfigLoader, ConfigLoaderResult, ConfigManagerOptions, LoaderPrecedence, VerboseOptions, PrecedenceStrategy, ConfigLoadResult, ConfigSourceInfo, Logger, EnvironmentLoaderConfig, EnvFileLoaderConfig, S3LoaderConfig, SecretsManagerLoaderConfig, SSMParameterStoreLoaderConfig, } from '@dyanet/config-aws';
9
+ export { ConfigurationError, ValidationError, AWSServiceError, ConfigurationLoadError, MissingConfigurationError, EnvironmentLoader, EnvFileLoader, S3Loader, SecretsManagerLoader, SSMParameterStoreLoader, ConfigManager, ConfigValidationUtil, EnvFileParser, } from '@dyanet/config-aws';
10
+ export { getConfig, clearConfigCache, getConfigCacheSize, invalidateConfig, type NextConfigOptions, createConfigProvider, ConfigProvider, useConfig, ConfigContext, } from './server';
11
+ export { PublicEnvScript, filterEnvVars, generateScriptContent, type PublicEnvScriptProps, } from './components';
12
+ export { env, envFrom, getAllEnv, hasEnv } from './client';
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,YAAY,EACV,YAAY,EACZ,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAChB,cAAc,EACd,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,MAAM,EACN,uBAAuB,EACvB,mBAAmB,EACnB,cAAc,EACd,0BAA0B,EAC1B,6BAA6B,GAC9B,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,sBAAsB,EACtB,yBAAyB,EACzB,iBAAiB,EACjB,aAAa,EACb,QAAQ,EACR,oBAAoB,EACpB,uBAAuB,EACvB,aAAa,EACb,oBAAoB,EACpB,aAAa,GACd,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EACL,SAAS,EACT,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAChB,KAAK,iBAAiB,EACtB,oBAAoB,EACpB,cAAc,EACd,SAAS,EACT,aAAa,GACd,MAAM,UAAU,CAAC;AAGlB,OAAO,EACL,eAAe,EACf,aAAa,EACb,qBAAqB,EACrB,KAAK,oBAAoB,GAC1B,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC"}