@dyanet/nextjs-config-aws 1.0.0-beta.1 → 1.0.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.
- package/README.md +147 -173
- package/dist/cjs/client/env.js +9 -1
- package/dist/cjs/client/env.js.map +1 -1
- package/dist/cjs/components/public-env-script.js +4 -0
- package/dist/cjs/components/public-env-script.js.map +1 -1
- package/dist/cjs/index.js +46 -28
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/server/get-config.js +74 -28
- package/dist/cjs/server/get-config.js.map +1 -1
- package/dist/cjs/server/internal/environment.js +38 -0
- package/dist/cjs/server/internal/environment.js.map +1 -0
- package/dist/cjs/server/internal/index.js +13 -0
- package/dist/cjs/server/internal/index.js.map +1 -0
- package/dist/cjs/server/internal/loader-factory.js +61 -0
- package/dist/cjs/server/internal/loader-factory.js.map +1 -0
- package/dist/esm/client/env.js +9 -1
- package/dist/esm/client/env.js.map +1 -1
- package/dist/esm/components/public-env-script.js +4 -0
- package/dist/esm/components/public-env-script.js.map +1 -1
- package/dist/esm/index.js +49 -8
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/server/get-config.js +74 -28
- package/dist/esm/server/get-config.js.map +1 -1
- package/dist/esm/server/internal/environment.js +35 -0
- package/dist/esm/server/internal/environment.js.map +1 -0
- package/dist/esm/server/internal/index.js +8 -0
- package/dist/esm/server/internal/index.js.map +1 -0
- package/dist/esm/server/internal/loader-factory.js +58 -0
- package/dist/esm/server/internal/loader-factory.js.map +1 -0
- package/dist/types/client/env.d.ts +9 -1
- package/dist/types/client/env.d.ts.map +1 -1
- package/dist/types/components/public-env-script.d.ts +4 -0
- package/dist/types/components/public-env-script.d.ts.map +1 -1
- package/dist/types/index.d.ts +46 -7
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/server/get-config.d.ts +102 -24
- package/dist/types/server/get-config.d.ts.map +1 -1
- package/dist/types/server/index.d.ts +2 -0
- package/dist/types/server/index.d.ts.map +1 -1
- package/dist/types/server/internal/environment.d.ts +30 -0
- package/dist/types/server/internal/environment.d.ts.map +1 -0
- package/dist/types/server/internal/index.d.ts +8 -0
- package/dist/types/server/internal/index.d.ts.map +1 -0
- package/dist/types/server/internal/loader-factory.d.ts +51 -0
- package/dist/types/server/internal/loader-factory.d.ts.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
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,
|
|
3
|
+
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
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
- **
|
|
7
|
+
- **Simplified API** - Just `getConfig()`, `PublicEnvScript`, and `env()` - no loader complexity
|
|
8
|
+
- **Automatic Environment Detection** - Configures itself based on NODE_ENV
|
|
8
9
|
- **Runtime Environment Variables** - Deploy the same build to different environments
|
|
9
10
|
- **Caching** - Avoid repeated AWS API calls during request handling
|
|
10
|
-
- **React Context** - Share configuration across your component tree
|
|
11
11
|
- **Type Safety** - Full TypeScript support with Zod schema validation
|
|
12
|
-
- **AWS Services** - Load configuration from Secrets Manager
|
|
12
|
+
- **AWS Services** - Load configuration from Secrets Manager and SSM Parameter Store
|
|
13
13
|
|
|
14
14
|
## Installation
|
|
15
15
|
|
|
@@ -32,9 +32,6 @@ npm install @aws-sdk/client-secrets-manager
|
|
|
32
32
|
# For SSM Parameter Store
|
|
33
33
|
npm install @aws-sdk/client-ssm
|
|
34
34
|
|
|
35
|
-
# For S3
|
|
36
|
-
npm install @aws-sdk/client-s3
|
|
37
|
-
|
|
38
35
|
# For schema validation
|
|
39
36
|
npm install zod
|
|
40
37
|
```
|
|
@@ -45,7 +42,27 @@ npm install zod
|
|
|
45
42
|
|
|
46
43
|
```typescript
|
|
47
44
|
// app/page.tsx (Server Component)
|
|
48
|
-
import { getConfig
|
|
45
|
+
import { getConfig } from '@dyanet/nextjs-config-aws';
|
|
46
|
+
import { z } from 'zod';
|
|
47
|
+
|
|
48
|
+
const schema = z.object({
|
|
49
|
+
DATABASE_URL: z.string(),
|
|
50
|
+
API_KEY: z.string(),
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
export default async function Page() {
|
|
54
|
+
// Minimal usage - auto-detects environment
|
|
55
|
+
const config = await getConfig({ schema });
|
|
56
|
+
|
|
57
|
+
return <div>Connected to: {config.DATABASE_URL}</div>;
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### With AWS Secrets Manager
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
// app/page.tsx
|
|
65
|
+
import { getConfig } from '@dyanet/nextjs-config-aws';
|
|
49
66
|
import { z } from 'zod';
|
|
50
67
|
|
|
51
68
|
const schema = z.object({
|
|
@@ -56,11 +73,10 @@ const schema = z.object({
|
|
|
56
73
|
export default async function Page() {
|
|
57
74
|
const config = await getConfig({
|
|
58
75
|
schema,
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
precedence: 'aws-first',
|
|
76
|
+
aws: {
|
|
77
|
+
secretName: '/my-app/config',
|
|
78
|
+
region: 'us-east-1' // Optional, defaults to AWS_REGION env var
|
|
79
|
+
},
|
|
64
80
|
});
|
|
65
81
|
|
|
66
82
|
return <div>Connected to: {config.DATABASE_URL}</div>;
|
|
@@ -101,37 +117,43 @@ export function ClientComponent() {
|
|
|
101
117
|
}
|
|
102
118
|
```
|
|
103
119
|
|
|
104
|
-
##
|
|
120
|
+
## Environment Detection
|
|
105
121
|
|
|
106
|
-
|
|
122
|
+
The library automatically configures itself based on `NODE_ENV`:
|
|
123
|
+
|
|
124
|
+
| Environment | Env Vars | .env Files | AWS Sources |
|
|
125
|
+
|-------------|----------|------------|-------------|
|
|
126
|
+
| development | ✓ | .env.local, .env | Only if `forceAwsInDev: true` |
|
|
127
|
+
| production | ✓ | .env | ✓ (if configured) |
|
|
128
|
+
| test | ✓ | ✗ | ✗ |
|
|
107
129
|
|
|
108
|
-
|
|
130
|
+
### Override Environment Detection
|
|
109
131
|
|
|
110
132
|
```typescript
|
|
111
|
-
|
|
112
|
-
|
|
133
|
+
const config = await getConfig({
|
|
134
|
+
schema,
|
|
135
|
+
environment: 'production', // Force production behavior
|
|
136
|
+
});
|
|
137
|
+
```
|
|
113
138
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
139
|
+
### Force AWS in Development
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
const config = await getConfig({
|
|
143
|
+
schema,
|
|
144
|
+
aws: { secretName: '/my-app/config' },
|
|
145
|
+
forceAwsInDev: true, // Load from AWS even in development
|
|
118
146
|
});
|
|
147
|
+
```
|
|
119
148
|
|
|
120
|
-
|
|
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
|
-
});
|
|
149
|
+
## API Reference
|
|
132
150
|
|
|
133
|
-
|
|
134
|
-
|
|
151
|
+
### getConfig()
|
|
152
|
+
|
|
153
|
+
Load configuration in Server Components, API routes, or server actions.
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
import { getConfig } from '@dyanet/nextjs-config-aws';
|
|
135
157
|
```
|
|
136
158
|
|
|
137
159
|
#### Options
|
|
@@ -139,103 +161,55 @@ export default async function Page() {
|
|
|
139
161
|
| Option | Type | Default | Description |
|
|
140
162
|
|--------|------|---------|-------------|
|
|
141
163
|
| `schema` | `ZodType<T>` | `undefined` | Zod schema for validation |
|
|
142
|
-
| `
|
|
143
|
-
| `
|
|
164
|
+
| `aws.secretName` | `string` | `undefined` | AWS Secrets Manager secret name |
|
|
165
|
+
| `aws.ssmPrefix` | `string` | `undefined` | AWS SSM Parameter Store path prefix |
|
|
166
|
+
| `aws.region` | `string` | `AWS_REGION` | AWS region for all service calls |
|
|
167
|
+
| `environment` | `'development' \| 'production' \| 'test'` | auto-detect | Override environment detection |
|
|
168
|
+
| `forceAwsInDev` | `boolean` | `false` | Load from AWS in development mode |
|
|
144
169
|
| `cache` | `boolean` | `true` | Enable caching |
|
|
145
170
|
| `cacheTTL` | `number` | `60000` | Cache TTL in milliseconds |
|
|
146
|
-
| `enableLogging` | `boolean` | `false` | Enable logging |
|
|
147
171
|
|
|
148
|
-
|
|
172
|
+
#### Examples
|
|
149
173
|
|
|
150
174
|
```typescript
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
// Clear all cached configurations
|
|
154
|
-
clearConfigCache();
|
|
155
|
-
|
|
156
|
-
// Get number of cached configurations
|
|
157
|
-
const size = getConfigCacheSize();
|
|
175
|
+
// Minimal - just schema
|
|
176
|
+
const config = await getConfig({ schema });
|
|
158
177
|
|
|
159
|
-
//
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
### createConfigProvider()
|
|
164
|
-
|
|
165
|
-
Create a typed React context provider for sharing configuration:
|
|
166
|
-
|
|
167
|
-
```typescript
|
|
168
|
-
// lib/config.ts
|
|
169
|
-
import { createConfigProvider, getConfig } from '@dyanet/nextjs-config-aws';
|
|
170
|
-
import { z } from 'zod';
|
|
171
|
-
|
|
172
|
-
const schema = z.object({
|
|
173
|
-
DATABASE_URL: z.string(),
|
|
174
|
-
API_KEY: z.string(),
|
|
178
|
+
// With AWS Secrets Manager
|
|
179
|
+
const config = await getConfig({
|
|
180
|
+
schema,
|
|
181
|
+
aws: { secretName: '/my-app/secrets' }
|
|
175
182
|
});
|
|
176
183
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
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';
|
|
184
|
+
// With SSM Parameter Store
|
|
185
|
+
const config = await getConfig({
|
|
186
|
+
schema,
|
|
187
|
+
aws: { ssmPrefix: '/my-app/config' }
|
|
188
|
+
});
|
|
210
189
|
|
|
211
|
-
|
|
190
|
+
// Both AWS sources
|
|
191
|
+
const config = await getConfig({
|
|
192
|
+
schema,
|
|
193
|
+
aws: {
|
|
194
|
+
secretName: '/my-app/secrets',
|
|
195
|
+
ssmPrefix: '/my-app/config',
|
|
196
|
+
region: 'us-west-2'
|
|
197
|
+
}
|
|
198
|
+
});
|
|
212
199
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
200
|
+
// Disable caching
|
|
201
|
+
const config = await getConfig({
|
|
202
|
+
schema,
|
|
203
|
+
cache: false
|
|
204
|
+
});
|
|
217
205
|
```
|
|
218
206
|
|
|
219
|
-
## Runtime Environment Variables
|
|
220
|
-
|
|
221
207
|
### PublicEnvScript
|
|
222
208
|
|
|
223
|
-
Server component that injects environment variables into the client
|
|
209
|
+
Server component that injects environment variables into the client.
|
|
224
210
|
|
|
225
211
|
```tsx
|
|
226
212
|
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
213
|
```
|
|
240
214
|
|
|
241
215
|
#### Props
|
|
@@ -249,28 +223,47 @@ import { PublicEnvScript } from '@dyanet/nextjs-config-aws';
|
|
|
249
223
|
|
|
250
224
|
**Security Note:** Only expose variables that are safe for public access. Never expose secrets, API keys, or sensitive data.
|
|
251
225
|
|
|
252
|
-
|
|
226
|
+
```tsx
|
|
227
|
+
// Explicit allowlist
|
|
228
|
+
<PublicEnvScript publicVars={['API_URL', 'APP_NAME']} />
|
|
229
|
+
|
|
230
|
+
// Prefix filtering
|
|
231
|
+
<PublicEnvScript publicPrefix="PUBLIC_" />
|
|
232
|
+
|
|
233
|
+
// With CSP nonce
|
|
234
|
+
<PublicEnvScript publicVars={['API_URL']} nonce={cspNonce} />
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### env()
|
|
238
|
+
|
|
239
|
+
Access runtime environment variables on the client.
|
|
253
240
|
|
|
254
241
|
```typescript
|
|
255
242
|
'use client';
|
|
256
243
|
|
|
257
|
-
import { env
|
|
244
|
+
import { env } from '@dyanet/nextjs-config-aws';
|
|
245
|
+
```
|
|
258
246
|
|
|
247
|
+
```typescript
|
|
259
248
|
// Get a variable (returns undefined if not found)
|
|
260
249
|
const apiUrl = env('API_URL');
|
|
261
250
|
|
|
262
251
|
// Get with default value
|
|
263
252
|
const appName = env('APP_NAME', 'My App');
|
|
253
|
+
```
|
|
264
254
|
|
|
265
|
-
|
|
266
|
-
const customVar = envFrom('__MY_ENV', 'API_URL');
|
|
267
|
-
|
|
268
|
-
// Get all variables
|
|
269
|
-
const allEnv = getAllEnv();
|
|
255
|
+
### Error Handling
|
|
270
256
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
257
|
+
```typescript
|
|
258
|
+
import { ConfigurationError, ValidationError } from '@dyanet/nextjs-config-aws';
|
|
259
|
+
|
|
260
|
+
try {
|
|
261
|
+
const config = await getConfig({ schema });
|
|
262
|
+
} catch (error) {
|
|
263
|
+
if (error instanceof ValidationError) {
|
|
264
|
+
console.error('Validation failed:', error.message);
|
|
265
|
+
// error.message includes the invalid/missing key names
|
|
266
|
+
}
|
|
274
267
|
}
|
|
275
268
|
```
|
|
276
269
|
|
|
@@ -280,7 +273,7 @@ if (hasEnv('FEATURE_FLAG')) {
|
|
|
280
273
|
|
|
281
274
|
```tsx
|
|
282
275
|
// app/dashboard/page.tsx
|
|
283
|
-
import { getConfig
|
|
276
|
+
import { getConfig } from '@dyanet/nextjs-config-aws';
|
|
284
277
|
import { z } from 'zod';
|
|
285
278
|
|
|
286
279
|
const schema = z.object({
|
|
@@ -291,10 +284,7 @@ const schema = z.object({
|
|
|
291
284
|
export default async function DashboardPage() {
|
|
292
285
|
const config = await getConfig({
|
|
293
286
|
schema,
|
|
294
|
-
|
|
295
|
-
new EnvironmentLoader(),
|
|
296
|
-
new SSMParameterStoreLoader({ parameterPath: '/app/config' }),
|
|
297
|
-
],
|
|
287
|
+
aws: { ssmPrefix: '/app/config' },
|
|
298
288
|
});
|
|
299
289
|
|
|
300
290
|
return (
|
|
@@ -311,7 +301,7 @@ export default async function DashboardPage() {
|
|
|
311
301
|
```typescript
|
|
312
302
|
// app/api/config/route.ts
|
|
313
303
|
import { NextResponse } from 'next/server';
|
|
314
|
-
import { getConfig
|
|
304
|
+
import { getConfig } from '@dyanet/nextjs-config-aws';
|
|
315
305
|
import { z } from 'zod';
|
|
316
306
|
|
|
317
307
|
const schema = z.object({
|
|
@@ -320,10 +310,7 @@ const schema = z.object({
|
|
|
320
310
|
});
|
|
321
311
|
|
|
322
312
|
export async function GET() {
|
|
323
|
-
const config = await getConfig({
|
|
324
|
-
schema,
|
|
325
|
-
loaders: [new EnvironmentLoader()],
|
|
326
|
-
});
|
|
313
|
+
const config = await getConfig({ schema });
|
|
327
314
|
|
|
328
315
|
return NextResponse.json({
|
|
329
316
|
version: config.API_VERSION,
|
|
@@ -338,7 +325,7 @@ export async function GET() {
|
|
|
338
325
|
// app/actions.ts
|
|
339
326
|
'use server';
|
|
340
327
|
|
|
341
|
-
import { getConfig
|
|
328
|
+
import { getConfig } from '@dyanet/nextjs-config-aws';
|
|
342
329
|
import { z } from 'zod';
|
|
343
330
|
|
|
344
331
|
const schema = z.object({
|
|
@@ -348,7 +335,7 @@ const schema = z.object({
|
|
|
348
335
|
export async function fetchData() {
|
|
349
336
|
const config = await getConfig({
|
|
350
337
|
schema,
|
|
351
|
-
|
|
338
|
+
aws: { secretName: '/app/secrets' },
|
|
352
339
|
});
|
|
353
340
|
|
|
354
341
|
const response = await fetch('https://api.example.com/data', {
|
|
@@ -365,7 +352,7 @@ export async function fetchData() {
|
|
|
365
352
|
|
|
366
353
|
```typescript
|
|
367
354
|
// pages/dashboard.tsx
|
|
368
|
-
import { getConfig
|
|
355
|
+
import { getConfig } from '@dyanet/nextjs-config-aws';
|
|
369
356
|
import { z } from 'zod';
|
|
370
357
|
import type { GetServerSideProps } from 'next';
|
|
371
358
|
|
|
@@ -374,10 +361,7 @@ const schema = z.object({
|
|
|
374
361
|
});
|
|
375
362
|
|
|
376
363
|
export const getServerSideProps: GetServerSideProps = async () => {
|
|
377
|
-
const config = await getConfig({
|
|
378
|
-
schema,
|
|
379
|
-
loaders: [new EnvironmentLoader()],
|
|
380
|
-
});
|
|
364
|
+
const config = await getConfig({ schema });
|
|
381
365
|
|
|
382
366
|
return {
|
|
383
367
|
props: {
|
|
@@ -396,7 +380,7 @@ export default function Dashboard({ apiUrl }: { apiUrl: string }) {
|
|
|
396
380
|
```typescript
|
|
397
381
|
// pages/api/config.ts
|
|
398
382
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
399
|
-
import { getConfig
|
|
383
|
+
import { getConfig } from '@dyanet/nextjs-config-aws';
|
|
400
384
|
import { z } from 'zod';
|
|
401
385
|
|
|
402
386
|
const schema = z.object({
|
|
@@ -404,48 +388,38 @@ const schema = z.object({
|
|
|
404
388
|
});
|
|
405
389
|
|
|
406
390
|
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
|
407
|
-
const config = await getConfig({
|
|
408
|
-
schema,
|
|
409
|
-
loaders: [new EnvironmentLoader()],
|
|
410
|
-
});
|
|
391
|
+
const config = await getConfig({ schema });
|
|
411
392
|
|
|
412
393
|
res.json({ version: config.APP_VERSION });
|
|
413
394
|
}
|
|
414
395
|
```
|
|
415
396
|
|
|
416
|
-
##
|
|
397
|
+
## Advanced Usage
|
|
417
398
|
|
|
418
|
-
|
|
399
|
+
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
400
|
|
|
420
401
|
```typescript
|
|
421
402
|
import {
|
|
422
|
-
|
|
403
|
+
ConfigManager,
|
|
423
404
|
EnvironmentLoader,
|
|
424
405
|
EnvFileLoader,
|
|
425
|
-
S3Loader,
|
|
426
406
|
SecretsManagerLoader,
|
|
427
407
|
SSMParameterStoreLoader,
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
// Types
|
|
444
|
-
ConfigLoader,
|
|
445
|
-
ConfigManagerOptions,
|
|
446
|
-
LoaderPrecedence,
|
|
447
|
-
VerboseOptions,
|
|
448
|
-
} from '@dyanet/nextjs-config-aws';
|
|
408
|
+
S3Loader,
|
|
409
|
+
} from '@dyanet/config-aws';
|
|
410
|
+
|
|
411
|
+
const manager = new ConfigManager({
|
|
412
|
+
loaders: [
|
|
413
|
+
new EnvironmentLoader({ prefix: 'APP_' }),
|
|
414
|
+
new EnvFileLoader({ paths: ['.env.local', '.env'] }),
|
|
415
|
+
new SecretsManagerLoader({ secretName: '/my-app/config' }),
|
|
416
|
+
],
|
|
417
|
+
schema: mySchema,
|
|
418
|
+
precedence: 'aws-first',
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
await manager.load();
|
|
422
|
+
const config = manager.getAll();
|
|
449
423
|
```
|
|
450
424
|
|
|
451
425
|
## Related Packages
|
package/dist/cjs/client/env.js
CHANGED
|
@@ -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
|
|
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":[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S,CAAC,eAAuB,qBAAqB;IACpE,OAAO,EAAE,GAAG,YAAY,CAAC,YAAY,CAAC,EAAE,CAAC;AAC3C,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,SAAgB,MAAM,CAAC,GAAW,EAAE,eAAuB,qBAAqB;IAC9E,MAAM,MAAM,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC;IAC1C,OAAO,GAAG,IAAI,MAAM,CAAC;AACvB,CAAC;AAED,kBAAe,GAAG,CAAC"}
|
|
@@ -6,6 +6,10 @@
|
|
|
6
6
|
* into the client-side JavaScript context, enabling runtime environment 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
|
|
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;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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B;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"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -3,44 +3,62 @@
|
|
|
3
3
|
* @dyanet/nextjs-config-aws
|
|
4
4
|
*
|
|
5
5
|
* Next.js adapter for AWS configuration management.
|
|
6
|
-
* Provides
|
|
7
|
-
*
|
|
6
|
+
* Provides a simplified, opinionated API for loading configuration
|
|
7
|
+
* with automatic environment detection and AWS integration.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* // Server-side configuration loading
|
|
12
|
+
* import { getConfig } from '@dyanet/nextjs-config-aws';
|
|
13
|
+
*
|
|
14
|
+
* const config = await getConfig({
|
|
15
|
+
* schema: mySchema,
|
|
16
|
+
* aws: { secretName: '/myapp/config' }
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* // Runtime environment variables for client
|
|
23
|
+
* // In layout.tsx (server component)
|
|
24
|
+
* import { PublicEnvScript } from '@dyanet/nextjs-config-aws';
|
|
25
|
+
*
|
|
26
|
+
* <PublicEnvScript publicVars={['API_URL', 'APP_NAME']} />
|
|
27
|
+
*
|
|
28
|
+
* // In client component
|
|
29
|
+
* import { env } from '@dyanet/nextjs-config-aws';
|
|
30
|
+
*
|
|
31
|
+
* const apiUrl = env('API_URL');
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @remarks
|
|
35
|
+
* For advanced loader access, custom loaders, or direct AWS SDK integration,
|
|
36
|
+
* import from `@dyanet/config-aws` directly:
|
|
37
|
+
*
|
|
38
|
+
* ```typescript
|
|
39
|
+
* import {
|
|
40
|
+
* ConfigManager,
|
|
41
|
+
* EnvironmentLoader,
|
|
42
|
+
* SecretsManagerLoader,
|
|
43
|
+
* SSMParameterStoreLoader,
|
|
44
|
+
* } from '@dyanet/config-aws';
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @packageDocumentation
|
|
8
48
|
*/
|
|
9
49
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.
|
|
50
|
+
exports.env = exports.PublicEnvScript = exports.getConfig = exports.ValidationError = exports.ConfigurationError = void 0;
|
|
51
|
+
// Error classes for error handling
|
|
11
52
|
var config_aws_1 = require("@dyanet/config-aws");
|
|
12
53
|
Object.defineProperty(exports, "ConfigurationError", { enumerable: true, get: function () { return config_aws_1.ConfigurationError; } });
|
|
13
54
|
Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return config_aws_1.ValidationError; } });
|
|
14
|
-
|
|
15
|
-
Object.defineProperty(exports, "ConfigurationLoadError", { enumerable: true, get: function () { return config_aws_1.ConfigurationLoadError; } });
|
|
16
|
-
Object.defineProperty(exports, "MissingConfigurationError", { enumerable: true, get: function () { return config_aws_1.MissingConfigurationError; } });
|
|
17
|
-
Object.defineProperty(exports, "EnvironmentLoader", { enumerable: true, get: function () { return config_aws_1.EnvironmentLoader; } });
|
|
18
|
-
Object.defineProperty(exports, "EnvFileLoader", { enumerable: true, get: function () { return config_aws_1.EnvFileLoader; } });
|
|
19
|
-
Object.defineProperty(exports, "S3Loader", { enumerable: true, get: function () { return config_aws_1.S3Loader; } });
|
|
20
|
-
Object.defineProperty(exports, "SecretsManagerLoader", { enumerable: true, get: function () { return config_aws_1.SecretsManagerLoader; } });
|
|
21
|
-
Object.defineProperty(exports, "SSMParameterStoreLoader", { enumerable: true, get: function () { return config_aws_1.SSMParameterStoreLoader; } });
|
|
22
|
-
Object.defineProperty(exports, "ConfigManager", { enumerable: true, get: function () { return config_aws_1.ConfigManager; } });
|
|
23
|
-
Object.defineProperty(exports, "ConfigValidationUtil", { enumerable: true, get: function () { return config_aws_1.ConfigValidationUtil; } });
|
|
24
|
-
Object.defineProperty(exports, "EnvFileParser", { enumerable: true, get: function () { return config_aws_1.EnvFileParser; } });
|
|
25
|
-
// Server-side exports
|
|
55
|
+
// Server-side configuration loading
|
|
26
56
|
var server_1 = require("./server");
|
|
27
57
|
Object.defineProperty(exports, "getConfig", { enumerable: true, get: function () { return server_1.getConfig; } });
|
|
28
|
-
|
|
29
|
-
Object.defineProperty(exports, "getConfigCacheSize", { enumerable: true, get: function () { return server_1.getConfigCacheSize; } });
|
|
30
|
-
Object.defineProperty(exports, "invalidateConfig", { enumerable: true, get: function () { return server_1.invalidateConfig; } });
|
|
31
|
-
Object.defineProperty(exports, "createConfigProvider", { enumerable: true, get: function () { return server_1.createConfigProvider; } });
|
|
32
|
-
Object.defineProperty(exports, "ConfigProvider", { enumerable: true, get: function () { return server_1.ConfigProvider; } });
|
|
33
|
-
Object.defineProperty(exports, "useConfig", { enumerable: true, get: function () { return server_1.useConfig; } });
|
|
34
|
-
Object.defineProperty(exports, "ConfigContext", { enumerable: true, get: function () { return server_1.ConfigContext; } });
|
|
35
|
-
// Components for runtime environment variables
|
|
58
|
+
// Component for runtime environment variables
|
|
36
59
|
var components_1 = require("./components");
|
|
37
60
|
Object.defineProperty(exports, "PublicEnvScript", { enumerable: true, get: function () { return components_1.PublicEnvScript; } });
|
|
38
|
-
Object.defineProperty(exports, "filterEnvVars", { enumerable: true, get: function () { return components_1.filterEnvVars; } });
|
|
39
|
-
Object.defineProperty(exports, "generateScriptContent", { enumerable: true, get: function () { return components_1.generateScriptContent; } });
|
|
40
61
|
// Client-side environment variable access
|
|
41
62
|
var client_1 = require("./client");
|
|
42
63
|
Object.defineProperty(exports, "env", { enumerable: true, get: function () { return client_1.env; } });
|
|
43
|
-
Object.defineProperty(exports, "envFrom", { enumerable: true, get: function () { return client_1.envFrom; } });
|
|
44
|
-
Object.defineProperty(exports, "getAllEnv", { enumerable: true, get: function () { return client_1.getAllEnv; } });
|
|
45
|
-
Object.defineProperty(exports, "hasEnv", { enumerable: true, get: function () { return client_1.hasEnv; } });
|
|
46
64
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;;;AAEH,mCAAmC;AACnC,iDAAyE;AAAhE,gHAAA,kBAAkB,OAAA;AAAE,6GAAA,eAAe,OAAA;AAE5C,oCAAoC;AACpC,mCAA6D;AAApD,mGAAA,SAAS,OAAA;AAElB,8CAA8C;AAC9C,2CAA0E;AAAjE,6GAAA,eAAe,OAAA;AAExB,0CAA0C;AAC1C,mCAA+B;AAAtB,6FAAA,GAAG,OAAA"}
|