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

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 (56) hide show
  1. package/README.md +208 -173
  2. package/dist/cjs/client/env.js +9 -1
  3. package/dist/cjs/client/env.js.map +1 -1
  4. package/dist/cjs/components/public-env-script.js +4 -0
  5. package/dist/cjs/components/public-env-script.js.map +1 -1
  6. package/dist/cjs/index.js +54 -28
  7. package/dist/cjs/index.js.map +1 -1
  8. package/dist/cjs/react.js +50 -0
  9. package/dist/cjs/react.js.map +1 -0
  10. package/dist/cjs/server/get-config.js +74 -28
  11. package/dist/cjs/server/get-config.js.map +1 -1
  12. package/dist/cjs/server/index.js +7 -6
  13. package/dist/cjs/server/index.js.map +1 -1
  14. package/dist/cjs/server/internal/environment.js +38 -0
  15. package/dist/cjs/server/internal/environment.js.map +1 -0
  16. package/dist/cjs/server/internal/index.js +13 -0
  17. package/dist/cjs/server/internal/index.js.map +1 -0
  18. package/dist/cjs/server/internal/loader-factory.js +61 -0
  19. package/dist/cjs/server/internal/loader-factory.js.map +1 -0
  20. package/dist/esm/client/env.js +9 -1
  21. package/dist/esm/client/env.js.map +1 -1
  22. package/dist/esm/components/public-env-script.js +4 -0
  23. package/dist/esm/components/public-env-script.js.map +1 -1
  24. package/dist/esm/index.js +57 -8
  25. package/dist/esm/index.js.map +1 -1
  26. package/dist/esm/react.js +43 -0
  27. package/dist/esm/react.js.map +1 -0
  28. package/dist/esm/server/get-config.js +74 -28
  29. package/dist/esm/server/get-config.js.map +1 -1
  30. package/dist/esm/server/index.js +6 -1
  31. package/dist/esm/server/index.js.map +1 -1
  32. package/dist/esm/server/internal/environment.js +35 -0
  33. package/dist/esm/server/internal/environment.js.map +1 -0
  34. package/dist/esm/server/internal/index.js +8 -0
  35. package/dist/esm/server/internal/index.js.map +1 -0
  36. package/dist/esm/server/internal/loader-factory.js +58 -0
  37. package/dist/esm/server/internal/loader-factory.js.map +1 -0
  38. package/dist/types/client/env.d.ts +9 -1
  39. package/dist/types/client/env.d.ts.map +1 -1
  40. package/dist/types/components/public-env-script.d.ts +4 -0
  41. package/dist/types/components/public-env-script.d.ts.map +1 -1
  42. package/dist/types/index.d.ts +54 -7
  43. package/dist/types/index.d.ts.map +1 -1
  44. package/dist/types/react.d.ts +43 -0
  45. package/dist/types/react.d.ts.map +1 -0
  46. package/dist/types/server/get-config.d.ts +102 -24
  47. package/dist/types/server/get-config.d.ts.map +1 -1
  48. package/dist/types/server/index.d.ts +8 -1
  49. package/dist/types/server/index.d.ts.map +1 -1
  50. package/dist/types/server/internal/environment.d.ts +30 -0
  51. package/dist/types/server/internal/environment.d.ts.map +1 -0
  52. package/dist/types/server/internal/index.d.ts +8 -0
  53. package/dist/types/server/internal/index.d.ts.map +1 -0
  54. package/dist/types/server/internal/loader-factory.d.ts +51 -0
  55. package/dist/types/server/internal/loader-factory.d.ts.map +1 -0
  56. package/package.json +9 -4
package/README.md CHANGED
@@ -1,15 +1,20 @@
1
1
  # @dyanet/nextjs-config-aws
2
2
 
3
- Next.js adapter for AWS configuration management. A thin wrapper around [@dyanet/config-aws](../config-aws) that provides server-side configuration loading, React context providers, and runtime environment variable support.
3
+ [![npm version](https://img.shields.io/npm/v/@dyanet/nextjs-config-aws.svg)](https://www.npmjs.com/package/@dyanet/nextjs-config-aws)
4
+ [![CI](https://github.com/dyanet/config-aws/actions/workflows/ci.yml/badge.svg)](https://github.com/dyanet/config-aws/actions/workflows/ci.yml)
5
+ [![codecov](https://codecov.io/gh/dyanet/config-aws/flag/nextjs-config-aws/graph/badge.svg)](https://codecov.io/gh/dyanet/config-aws)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ Next.js adapter for AWS configuration management. A thin wrapper around [@dyanet/config-aws](../config-aws) that provides server-side configuration loading, runtime environment variables, and automatic environment detection.
4
9
 
5
10
  ## Features
6
11
 
7
- - **Server Components** - Load configuration in Server Components and API routes
12
+ - **Simplified API** - Just `getConfig()`, `PublicEnvScript`, and `env()` - no loader complexity
13
+ - **Automatic Environment Detection** - Configures itself based on NODE_ENV
8
14
  - **Runtime Environment Variables** - Deploy the same build to different environments
9
15
  - **Caching** - Avoid repeated AWS API calls during request handling
10
- - **React Context** - Share configuration across your component tree
11
16
  - **Type Safety** - Full TypeScript support with Zod schema validation
12
- - **AWS Services** - Load configuration from Secrets Manager, SSM Parameter Store, S3
17
+ - **AWS Services** - Load configuration from Secrets Manager and SSM Parameter Store
13
18
 
14
19
  ## Installation
15
20
 
@@ -32,9 +37,6 @@ npm install @aws-sdk/client-secrets-manager
32
37
  # For SSM Parameter Store
33
38
  npm install @aws-sdk/client-ssm
34
39
 
35
- # For S3
36
- npm install @aws-sdk/client-s3
37
-
38
40
  # For schema validation
39
41
  npm install zod
40
42
  ```
@@ -45,7 +47,27 @@ npm install zod
45
47
 
46
48
  ```typescript
47
49
  // app/page.tsx (Server Component)
48
- import { getConfig, EnvironmentLoader, SecretsManagerLoader } from '@dyanet/nextjs-config-aws';
50
+ import { getConfig } from '@dyanet/nextjs-config-aws';
51
+ import { z } from 'zod';
52
+
53
+ const schema = z.object({
54
+ DATABASE_URL: z.string(),
55
+ API_KEY: z.string(),
56
+ });
57
+
58
+ export default async function Page() {
59
+ // Minimal usage - auto-detects environment
60
+ const config = await getConfig({ schema });
61
+
62
+ return <div>Connected to: {config.DATABASE_URL}</div>;
63
+ }
64
+ ```
65
+
66
+ ### With AWS Secrets Manager
67
+
68
+ ```typescript
69
+ // app/page.tsx
70
+ import { getConfig } from '@dyanet/nextjs-config-aws';
49
71
  import { z } from 'zod';
50
72
 
51
73
  const schema = z.object({
@@ -56,11 +78,10 @@ const schema = z.object({
56
78
  export default async function Page() {
57
79
  const config = await getConfig({
58
80
  schema,
59
- loaders: [
60
- new EnvironmentLoader(),
61
- new SecretsManagerLoader({ secretName: '/my-app/config' }),
62
- ],
63
- precedence: 'aws-first',
81
+ aws: {
82
+ secretName: '/my-app/config',
83
+ region: 'us-east-1' // Optional, defaults to AWS_REGION env var
84
+ },
64
85
  });
65
86
 
66
87
  return <div>Connected to: {config.DATABASE_URL}</div>;
@@ -101,37 +122,43 @@ export function ClientComponent() {
101
122
  }
102
123
  ```
103
124
 
104
- ## Server-Side API
125
+ ## Environment Detection
105
126
 
106
- ### getConfig()
127
+ The library automatically configures itself based on `NODE_ENV`:
128
+
129
+ | Environment | Env Vars | .env Files | AWS Sources |
130
+ |-------------|----------|------------|-------------|
131
+ | development | ✓ | .env.local, .env | Only if `forceAwsInDev: true` |
132
+ | production | ✓ | .env | ✓ (if configured) |
133
+ | test | ✓ | ✗ | ✗ |
107
134
 
108
- Load configuration in Server Components, API routes, or server actions:
135
+ ### Override Environment Detection
109
136
 
110
137
  ```typescript
111
- import { getConfig, EnvironmentLoader, SecretsManagerLoader } from '@dyanet/nextjs-config-aws';
112
- import { z } from 'zod';
138
+ const config = await getConfig({
139
+ schema,
140
+ environment: 'production', // Force production behavior
141
+ });
142
+ ```
113
143
 
114
- const schema = z.object({
115
- DATABASE_URL: z.string(),
116
- API_KEY: z.string(),
117
- PORT: z.coerce.number().default(3000),
144
+ ### Force AWS in Development
145
+
146
+ ```typescript
147
+ const config = await getConfig({
148
+ schema,
149
+ aws: { secretName: '/my-app/config' },
150
+ forceAwsInDev: true, // Load from AWS even in development
118
151
  });
152
+ ```
119
153
 
120
- // In a Server Component
121
- export default async function Page() {
122
- const config = await getConfig({
123
- schema,
124
- loaders: [
125
- new EnvironmentLoader({ prefix: 'APP_' }),
126
- new SecretsManagerLoader({ secretName: '/my-app/secrets' }),
127
- ],
128
- precedence: 'aws-first',
129
- cache: true, // Enable caching (default: true)
130
- cacheTTL: 60000, // Cache for 1 minute (default)
131
- });
154
+ ## API Reference
132
155
 
133
- return <div>{config.DATABASE_URL}</div>;
134
- }
156
+ ### getConfig()
157
+
158
+ Load configuration in Server Components, API routes, or server actions.
159
+
160
+ ```typescript
161
+ import { getConfig } from '@dyanet/nextjs-config-aws';
135
162
  ```
136
163
 
137
164
  #### Options
@@ -139,103 +166,55 @@ export default async function Page() {
139
166
  | Option | Type | Default | Description |
140
167
  |--------|------|---------|-------------|
141
168
  | `schema` | `ZodType<T>` | `undefined` | Zod schema for validation |
142
- | `loaders` | `ConfigLoader[]` | `[]` | Array of configuration loaders |
143
- | `precedence` | `PrecedenceStrategy` | `'aws-first'` | Precedence strategy |
169
+ | `aws.secretName` | `string` | `undefined` | AWS Secrets Manager secret name |
170
+ | `aws.ssmPrefix` | `string` | `undefined` | AWS SSM Parameter Store path prefix |
171
+ | `aws.region` | `string` | `AWS_REGION` | AWS region for all service calls |
172
+ | `environment` | `'development' \| 'production' \| 'test'` | auto-detect | Override environment detection |
173
+ | `forceAwsInDev` | `boolean` | `false` | Load from AWS in development mode |
144
174
  | `cache` | `boolean` | `true` | Enable caching |
145
175
  | `cacheTTL` | `number` | `60000` | Cache TTL in milliseconds |
146
- | `enableLogging` | `boolean` | `false` | Enable logging |
147
-
148
- ### Cache Management
149
176
 
150
- ```typescript
151
- import { clearConfigCache, getConfigCacheSize, invalidateConfig } from '@dyanet/nextjs-config-aws';
152
-
153
- // Clear all cached configurations
154
- clearConfigCache();
155
-
156
- // Get number of cached configurations
157
- const size = getConfigCacheSize();
158
-
159
- // Invalidate a specific configuration
160
- invalidateConfig({ loaders: [...], precedence: 'aws-first' });
161
- ```
162
-
163
- ### createConfigProvider()
164
-
165
- Create a typed React context provider for sharing configuration:
177
+ #### Examples
166
178
 
167
179
  ```typescript
168
- // lib/config.ts
169
- import { createConfigProvider, getConfig } from '@dyanet/nextjs-config-aws';
170
- import { z } from 'zod';
180
+ // Minimal - just schema
181
+ const config = await getConfig({ schema });
171
182
 
172
- const schema = z.object({
173
- DATABASE_URL: z.string(),
174
- API_KEY: z.string(),
183
+ // With AWS Secrets Manager
184
+ const config = await getConfig({
185
+ schema,
186
+ aws: { secretName: '/my-app/secrets' }
175
187
  });
176
188
 
177
- export type AppConfig = z.infer<typeof schema>;
178
-
179
- // Create typed provider and hook
180
- export const { ConfigProvider, useConfig } = createConfigProvider<AppConfig>();
181
- export { schema };
182
- ```
183
-
184
- ```tsx
185
- // app/layout.tsx
186
- import { ConfigProvider, schema } from '@/lib/config';
187
- import { getConfig, EnvironmentLoader } from '@dyanet/nextjs-config-aws';
188
-
189
- export default async function RootLayout({ children }) {
190
- const config = await getConfig({
191
- schema,
192
- loaders: [new EnvironmentLoader()],
193
- });
194
-
195
- return (
196
- <html>
197
- <body>
198
- <ConfigProvider config={config}>
199
- {children}
200
- </ConfigProvider>
201
- </body>
202
- </html>
203
- );
204
- }
205
- ```
206
-
207
- ```tsx
208
- // app/components/my-component.tsx
209
- 'use client';
189
+ // With SSM Parameter Store
190
+ const config = await getConfig({
191
+ schema,
192
+ aws: { ssmPrefix: '/my-app/config' }
193
+ });
210
194
 
211
- import { useConfig } from '@/lib/config';
195
+ // Both AWS sources
196
+ const config = await getConfig({
197
+ schema,
198
+ aws: {
199
+ secretName: '/my-app/secrets',
200
+ ssmPrefix: '/my-app/config',
201
+ region: 'us-west-2'
202
+ }
203
+ });
212
204
 
213
- export function MyComponent() {
214
- const config = useConfig();
215
- return <div>API Key: {config.API_KEY}</div>;
216
- }
205
+ // Disable caching
206
+ const config = await getConfig({
207
+ schema,
208
+ cache: false
209
+ });
217
210
  ```
218
211
 
219
- ## Runtime Environment Variables
220
-
221
212
  ### PublicEnvScript
222
213
 
223
- Server component that injects environment variables into the client:
214
+ Server component that injects environment variables into the client.
224
215
 
225
216
  ```tsx
226
217
  import { PublicEnvScript } from '@dyanet/nextjs-config-aws';
227
-
228
- // In your root layout
229
- <PublicEnvScript
230
- publicVars={['API_URL', 'APP_NAME']} // Explicit allowlist
231
- variableName="__ENV" // Global variable name (default)
232
- nonce={cspNonce} // CSP nonce (optional)
233
- />
234
-
235
- // Or use prefix filtering
236
- <PublicEnvScript
237
- publicPrefix="PUBLIC_" // Include all PUBLIC_* vars
238
- />
239
218
  ```
240
219
 
241
220
  #### Props
@@ -249,28 +228,47 @@ import { PublicEnvScript } from '@dyanet/nextjs-config-aws';
249
228
 
250
229
  **Security Note:** Only expose variables that are safe for public access. Never expose secrets, API keys, or sensitive data.
251
230
 
252
- ### Client-Side Access
231
+ ```tsx
232
+ // Explicit allowlist
233
+ <PublicEnvScript publicVars={['API_URL', 'APP_NAME']} />
234
+
235
+ // Prefix filtering
236
+ <PublicEnvScript publicPrefix="PUBLIC_" />
237
+
238
+ // With CSP nonce
239
+ <PublicEnvScript publicVars={['API_URL']} nonce={cspNonce} />
240
+ ```
241
+
242
+ ### env()
243
+
244
+ Access runtime environment variables on the client.
253
245
 
254
246
  ```typescript
255
247
  'use client';
256
248
 
257
- import { env, envFrom, getAllEnv, hasEnv } from '@dyanet/nextjs-config-aws';
249
+ import { env } from '@dyanet/nextjs-config-aws';
250
+ ```
258
251
 
252
+ ```typescript
259
253
  // Get a variable (returns undefined if not found)
260
254
  const apiUrl = env('API_URL');
261
255
 
262
256
  // Get with default value
263
257
  const appName = env('APP_NAME', 'My App');
258
+ ```
264
259
 
265
- // Get from custom variable name
266
- const customVar = envFrom('__MY_ENV', 'API_URL');
267
-
268
- // Get all variables
269
- const allEnv = getAllEnv();
260
+ ### Error Handling
270
261
 
271
- // Check if variable exists
272
- if (hasEnv('FEATURE_FLAG')) {
273
- // Feature is enabled
262
+ ```typescript
263
+ import { ConfigurationError, ValidationError } from '@dyanet/nextjs-config-aws';
264
+
265
+ try {
266
+ const config = await getConfig({ schema });
267
+ } catch (error) {
268
+ if (error instanceof ValidationError) {
269
+ console.error('Validation failed:', error.message);
270
+ // error.message includes the invalid/missing key names
271
+ }
274
272
  }
275
273
  ```
276
274
 
@@ -280,7 +278,7 @@ if (hasEnv('FEATURE_FLAG')) {
280
278
 
281
279
  ```tsx
282
280
  // app/dashboard/page.tsx
283
- import { getConfig, EnvironmentLoader, SSMParameterStoreLoader } from '@dyanet/nextjs-config-aws';
281
+ import { getConfig } from '@dyanet/nextjs-config-aws';
284
282
  import { z } from 'zod';
285
283
 
286
284
  const schema = z.object({
@@ -291,10 +289,7 @@ const schema = z.object({
291
289
  export default async function DashboardPage() {
292
290
  const config = await getConfig({
293
291
  schema,
294
- loaders: [
295
- new EnvironmentLoader(),
296
- new SSMParameterStoreLoader({ parameterPath: '/app/config' }),
297
- ],
292
+ aws: { ssmPrefix: '/app/config' },
298
293
  });
299
294
 
300
295
  return (
@@ -311,7 +306,7 @@ export default async function DashboardPage() {
311
306
  ```typescript
312
307
  // app/api/config/route.ts
313
308
  import { NextResponse } from 'next/server';
314
- import { getConfig, EnvironmentLoader } from '@dyanet/nextjs-config-aws';
309
+ import { getConfig } from '@dyanet/nextjs-config-aws';
315
310
  import { z } from 'zod';
316
311
 
317
312
  const schema = z.object({
@@ -320,10 +315,7 @@ const schema = z.object({
320
315
  });
321
316
 
322
317
  export async function GET() {
323
- const config = await getConfig({
324
- schema,
325
- loaders: [new EnvironmentLoader()],
326
- });
318
+ const config = await getConfig({ schema });
327
319
 
328
320
  return NextResponse.json({
329
321
  version: config.API_VERSION,
@@ -332,13 +324,15 @@ export async function GET() {
332
324
  }
333
325
  ```
334
326
 
327
+ > **Note:** `getConfig()` works in API routes without any React dependencies. The React context providers (`ConfigProvider`, `useConfig`) are available via a separate import path - see [React Context Providers](#react-context-providers) below.
328
+
335
329
  ### Server Action
336
330
 
337
331
  ```typescript
338
332
  // app/actions.ts
339
333
  'use server';
340
334
 
341
- import { getConfig, SecretsManagerLoader } from '@dyanet/nextjs-config-aws';
335
+ import { getConfig } from '@dyanet/nextjs-config-aws';
342
336
  import { z } from 'zod';
343
337
 
344
338
  const schema = z.object({
@@ -348,7 +342,7 @@ const schema = z.object({
348
342
  export async function fetchData() {
349
343
  const config = await getConfig({
350
344
  schema,
351
- loaders: [new SecretsManagerLoader({ secretName: '/app/secrets' })],
345
+ aws: { secretName: '/app/secrets' },
352
346
  });
353
347
 
354
348
  const response = await fetch('https://api.example.com/data', {
@@ -365,7 +359,7 @@ export async function fetchData() {
365
359
 
366
360
  ```typescript
367
361
  // pages/dashboard.tsx
368
- import { getConfig, EnvironmentLoader } from '@dyanet/nextjs-config-aws';
362
+ import { getConfig } from '@dyanet/nextjs-config-aws';
369
363
  import { z } from 'zod';
370
364
  import type { GetServerSideProps } from 'next';
371
365
 
@@ -374,10 +368,7 @@ const schema = z.object({
374
368
  });
375
369
 
376
370
  export const getServerSideProps: GetServerSideProps = async () => {
377
- const config = await getConfig({
378
- schema,
379
- loaders: [new EnvironmentLoader()],
380
- });
371
+ const config = await getConfig({ schema });
381
372
 
382
373
  return {
383
374
  props: {
@@ -396,7 +387,7 @@ export default function Dashboard({ apiUrl }: { apiUrl: string }) {
396
387
  ```typescript
397
388
  // pages/api/config.ts
398
389
  import type { NextApiRequest, NextApiResponse } from 'next';
399
- import { getConfig, EnvironmentLoader } from '@dyanet/nextjs-config-aws';
390
+ import { getConfig } from '@dyanet/nextjs-config-aws';
400
391
  import { z } from 'zod';
401
392
 
402
393
  const schema = z.object({
@@ -404,48 +395,92 @@ const schema = z.object({
404
395
  });
405
396
 
406
397
  export default async function handler(req: NextApiRequest, res: NextApiResponse) {
407
- const config = await getConfig({
408
- schema,
409
- loaders: [new EnvironmentLoader()],
410
- });
398
+ const config = await getConfig({ schema });
411
399
 
412
400
  res.json({ version: config.APP_VERSION });
413
401
  }
414
402
  ```
415
403
 
416
- ## Re-exported Types
404
+ ## Advanced Usage
405
+
406
+ ### React Context Providers
417
407
 
418
- All types from `@dyanet/config-aws` are re-exported:
408
+ For sharing configuration across React server components via context, import from the `/react` subpath:
409
+
410
+ ```typescript
411
+ // app/layout.tsx
412
+ import { getConfig } from '@dyanet/nextjs-config-aws';
413
+ import { ConfigProvider } from '@dyanet/nextjs-config-aws/react';
414
+ import { z } from 'zod';
415
+
416
+ const schema = z.object({
417
+ DATABASE_URL: z.string(),
418
+ API_KEY: z.string(),
419
+ });
420
+
421
+ export default async function RootLayout({ children }) {
422
+ const config = await getConfig({ schema });
423
+
424
+ return (
425
+ <html>
426
+ <body>
427
+ <ConfigProvider config={config}>
428
+ {children}
429
+ </ConfigProvider>
430
+ </body>
431
+ </html>
432
+ );
433
+ }
434
+ ```
435
+
436
+ ```typescript
437
+ // app/components/my-component.tsx
438
+ import { useConfig } from '@dyanet/nextjs-config-aws/react';
439
+
440
+ export function MyComponent() {
441
+ const config = useConfig();
442
+ return <div>API Key: {config.API_KEY}</div>;
443
+ }
444
+ ```
445
+
446
+ For typed configuration, use `createConfigProvider`:
447
+
448
+ ```typescript
449
+ import { createConfigProvider } from '@dyanet/nextjs-config-aws/react';
450
+
451
+ type AppConfig = { DATABASE_URL: string; API_KEY: string };
452
+
453
+ const { ConfigProvider, useConfig } = createConfigProvider<AppConfig>();
454
+ ```
455
+
456
+ > **Why a separate import?** The React context providers use `React.createContext()` which requires React to be available. By separating them into `/react`, the main package exports work in all server contexts including API routes and middleware where React isn't loaded.
457
+
458
+ ### Custom Loaders
459
+
460
+ For advanced use cases such as custom loaders, direct AWS SDK integration, or fine-grained control over configuration loading, import from `@dyanet/config-aws` directly:
419
461
 
420
462
  ```typescript
421
463
  import {
422
- // Loaders
464
+ ConfigManager,
423
465
  EnvironmentLoader,
424
466
  EnvFileLoader,
425
- S3Loader,
426
467
  SecretsManagerLoader,
427
468
  SSMParameterStoreLoader,
428
-
429
- // ConfigManager
430
- ConfigManager,
431
-
432
- // Error classes
433
- ConfigurationError,
434
- ValidationError,
435
- AWSServiceError,
436
- ConfigurationLoadError,
437
- MissingConfigurationError,
438
-
439
- // Utilities
440
- ConfigValidationUtil,
441
- EnvFileParser,
442
-
443
- // Types
444
- ConfigLoader,
445
- ConfigManagerOptions,
446
- LoaderPrecedence,
447
- VerboseOptions,
448
- } from '@dyanet/nextjs-config-aws';
469
+ S3Loader,
470
+ } from '@dyanet/config-aws';
471
+
472
+ const manager = new ConfigManager({
473
+ loaders: [
474
+ new EnvironmentLoader({ prefix: 'APP_' }),
475
+ new EnvFileLoader({ paths: ['.env.local', '.env'] }),
476
+ new SecretsManagerLoader({ secretName: '/my-app/config' }),
477
+ ],
478
+ schema: mySchema,
479
+ precedence: 'aws-first',
480
+ });
481
+
482
+ await manager.load();
483
+ const config = manager.getAll();
449
484
  ```
450
485
 
451
486
  ## Related Packages
@@ -5,11 +5,19 @@
5
5
  * This module provides a function to read runtime environment variables
6
6
  * that were injected by the PublicEnvScript server component.
7
7
  *
8
+ * @remarks
9
+ * This is part of the simplified Next.js API. For advanced configuration loading
10
+ * with custom loaders or direct AWS SDK integration, import from `@dyanet/config-aws` directly:
11
+ *
12
+ * ```typescript
13
+ * import { ConfigManager, EnvironmentLoader } from '@dyanet/config-aws';
14
+ * ```
15
+ *
8
16
  * @example
9
17
  * ```tsx
10
18
  * 'use client';
11
19
  *
12
- * import { env } from '@dyanet/nextjs-config-aws/client';
20
+ * import { env } from '@dyanet/nextjs-config-aws';
13
21
  *
14
22
  * function MyComponent() {
15
23
  * const apiUrl = env('API_URL');
@@ -1 +1 @@
1
- {"version":3,"file":"env.js","sourceRoot":"","sources":["../../../src/client/env.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;;AA0EH,kBASC;AAgCD,0BASC;AAcD,8BAEC;AAgBD,wBAGC;AAnJD;;GAEG;AACH,MAAM,qBAAqB,GAAG,OAAO,CAAC;AAEtC;;;;;GAKG;AACH,SAAS,YAAY,CAAC,eAAuB,qBAAqB;IAChE,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QAClC,kDAAkD;QAClD,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC;IACpC,IAAI,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACnE,OAAO,MAAgC,CAAC;IAC1C,CAAC;IAED,OAAO,EAAE,CAAC;AACZ,CAAC;AAoCD;;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ment variable access
7
7
  * without requiring NEXT_PUBLIC_ prefixes at build time.
8
8
  *
9
+ * @remarks
10
+ * This is part of the simplified Next.js API. For advanced configuration loading
11
+ * with custom loaders or direct AWS SDK integration, import from `@dyanet/config-aws` directly.
12
+ *
9
13
  * @example
10
14
  * ```tsx
11
15
  * // In your root layout.tsx
@@ -1 +1 @@
1
- {"version":3,"file":"public-env-script.js","sourceRoot":"","sources":["../../../src/components/public-env-script.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CH,sCA8BC;AASD,sDAMC;AAiBD,0CA4BC;AApID,6CAA+B;AAkC/B;;;;;;;GAOG;AACH,SAAgB,aAAa,CAC3B,GAAuC,EACvC,UAAqB,EACrB,YAAqB;IAErB,MAAM,MAAM,GAA2B,EAAE,CAAC;IAE1C,4CAA4C;IAC5C,IAAI,UAAU,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxC,KAAK,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC;YAC7B,MAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;YACvB,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACxB,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;YACtB,CAAC;QACH,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,0CAA0C;IAC1C,IAAI,YAAY,EAAE,CAAC;QACjB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;YAC/C,IAAI,GAAG,CAAC,UAAU,CAAC,YAAY,CAAC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACxD,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;YACtB,CAAC;QACH,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,6DAA6D;IAC7D,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,qBAAqB,CACnC,WAAmC,EACnC,YAAoB;IAEpB,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAC/C,OAAO,UAAU,YAAY,IAAI,UAAU,GAAG,CAAC;AACjD,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,SAAgB,eAAe,CAAC,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,kBAAe,eAAe,CAAC"}
1
+ {"version":3,"file":"public-env-script.js","sourceRoot":"","sources":["../../../src/components/public-env-script.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CH,sCA8BC;AASD,sDAMC;AAiBD,0CA4BC;AApID,6CAA+B;AAkC/B;;;;;;;GAOG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