@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,80 @@
1
+ /**
2
+ * React context provider for server-side configuration in Next.js applications.
3
+ * Provides a way to access configuration values in server components.
4
+ */
5
+ import React, { type ReactNode } from 'react';
6
+ /**
7
+ * Configuration context type
8
+ */
9
+ interface ConfigContextValue<T> {
10
+ config: T;
11
+ }
12
+ /**
13
+ * Props for the ConfigProvider component
14
+ */
15
+ interface ConfigProviderProps<T> {
16
+ children: ReactNode;
17
+ config: T;
18
+ }
19
+ /**
20
+ * Creates a typed configuration provider and hook for accessing configuration
21
+ * in React server components.
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * import { createConfigProvider, getConfig } from '@dyanet/nextjs-config-aws';
26
+ * import { z } from 'zod';
27
+ *
28
+ * const schema = z.object({
29
+ * DATABASE_URL: z.string(),
30
+ * API_KEY: z.string(),
31
+ * });
32
+ *
33
+ * type AppConfig = z.infer<typeof schema>;
34
+ *
35
+ * // Create the provider and hook
36
+ * const { ConfigProvider, useConfig } = createConfigProvider<AppConfig>();
37
+ *
38
+ * // In your layout.tsx (Server Component)
39
+ * export default async function RootLayout({ children }) {
40
+ * const config = await getConfig({ schema });
41
+ *
42
+ * return (
43
+ * <html>
44
+ * <body>
45
+ * <ConfigProvider config={config}>
46
+ * {children}
47
+ * </ConfigProvider>
48
+ * </body>
49
+ * </html>
50
+ * );
51
+ * }
52
+ *
53
+ * // In a child component
54
+ * function MyComponent() {
55
+ * const config = useConfig();
56
+ * return <div>API Key: {config.API_KEY}</div>;
57
+ * }
58
+ * ```
59
+ *
60
+ * @returns An object containing the ConfigProvider component and useConfig hook
61
+ */
62
+ export declare function createConfigProvider<T = Record<string, unknown>>(): {
63
+ ConfigProvider: React.FC<ConfigProviderProps<T>>;
64
+ useConfig: () => T;
65
+ ConfigContext: React.Context<ConfigContextValue<T> | null>;
66
+ };
67
+ /**
68
+ * Default ConfigProvider for untyped configuration
69
+ */
70
+ export declare const ConfigProvider: React.FC<ConfigProviderProps<Record<string, unknown>>>;
71
+ /**
72
+ * Default useConfig hook for untyped configuration
73
+ */
74
+ export declare const useConfig: () => Record<string, unknown>;
75
+ /**
76
+ * Default ConfigContext for untyped configuration
77
+ */
78
+ export declare const ConfigContext: React.Context<ConfigContextValue<Record<string, unknown>> | null>;
79
+ export {};
80
+ //# sourceMappingURL=config-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-provider.d.ts","sourceRoot":"","sources":["../../../src/server/config-provider.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,EAA6B,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAEzE;;GAEG;AACH,UAAU,kBAAkB,CAAC,CAAC;IAC5B,MAAM,EAAE,CAAC,CAAC;CACX;AAED;;GAEG;AACH,UAAU,mBAAmB,CAAC,CAAC;IAC7B,QAAQ,EAAE,SAAS,CAAC;IACpB,MAAM,EAAE,CAAC,CAAC;CACX;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK;IACnE,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC;IACjD,SAAS,EAAE,MAAM,CAAC,CAAC;IACnB,aAAa,EAAE,KAAK,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;CAC5D,CAuCA;AAQD;;GAEG;AACH,eAAO,MAAM,cAAc,wDAAiC,CAAC;AAE7D;;GAEG;AACH,eAAO,MAAM,SAAS,+BAA4B,CAAC;AAEnD;;GAEG;AACH,eAAO,MAAM,aAAa,mEAAgC,CAAC"}
@@ -0,0 +1,86 @@
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 type { ZodType } from 'zod';
6
+ import { ConfigLoader, PrecedenceStrategy } from '@dyanet/config-aws';
7
+ /**
8
+ * Options for Next.js configuration loading
9
+ */
10
+ export interface NextConfigOptions<T = Record<string, unknown>> {
11
+ /** Zod schema for validation */
12
+ schema?: ZodType<T>;
13
+ /** Array of loaders to use */
14
+ loaders?: ConfigLoader[];
15
+ /** Precedence strategy for merging configurations */
16
+ precedence?: PrecedenceStrategy;
17
+ /** Enable caching. Default: true */
18
+ cache?: boolean;
19
+ /** Cache TTL in milliseconds. Default: 60000 (1 minute) */
20
+ cacheTTL?: number;
21
+ /** Enable logging. Default: false */
22
+ enableLogging?: boolean;
23
+ }
24
+ /**
25
+ * Load configuration for Next.js server-side use.
26
+ *
27
+ * This function provides caching to avoid repeated AWS API calls during request handling.
28
+ * Configuration is cached based on the loader configuration and precedence strategy.
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * import { getConfig, EnvironmentLoader, SecretsManagerLoader } from '@dyanet/nextjs-config-aws';
33
+ * import { z } from 'zod';
34
+ *
35
+ * const schema = z.object({
36
+ * DATABASE_URL: z.string(),
37
+ * API_KEY: z.string(),
38
+ * });
39
+ *
40
+ * // In a Server Component or API route
41
+ * export default async function Page() {
42
+ * const config = await getConfig({
43
+ * schema,
44
+ * loaders: [
45
+ * new EnvironmentLoader(),
46
+ * new SecretsManagerLoader({ secretName: '/my-app/config' }),
47
+ * ],
48
+ * precedence: 'aws-first',
49
+ * });
50
+ *
51
+ * return <div>DB: {config.DATABASE_URL}</div>;
52
+ * }
53
+ * ```
54
+ *
55
+ * @param options Configuration options
56
+ * @returns Promise resolving to the validated configuration object
57
+ */
58
+ export declare function getConfig<T = Record<string, unknown>>(options?: NextConfigOptions<T>): Promise<T>;
59
+ /**
60
+ * Clear the configuration cache.
61
+ * Useful for testing or when configuration needs to be reloaded.
62
+ */
63
+ export declare function clearConfigCache(): void;
64
+ /**
65
+ * Get the current cache size.
66
+ * @returns Number of cached configurations
67
+ */
68
+ export declare function getConfigCacheSize(): number;
69
+ /**
70
+ * Get the AWS API call count.
71
+ * This is primarily for testing the caching behavior.
72
+ * @internal
73
+ */
74
+ export declare function getAwsApiCallCount(): number;
75
+ /**
76
+ * Reset the AWS API call count.
77
+ * This is primarily for testing the caching behavior.
78
+ * @internal
79
+ */
80
+ export declare function resetAwsApiCallCount(): void;
81
+ /**
82
+ * Invalidate a specific cache entry by regenerating with the same options.
83
+ * @param options The options used to create the cache entry
84
+ */
85
+ export declare function invalidateConfig<T>(options: NextConfigOptions<T>): void;
86
+ //# sourceMappingURL=get-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-config.d.ts","sourceRoot":"","sources":["../../../src/server/get-config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AACnC,OAAO,EAEL,YAAY,EAEZ,kBAAkB,EAEnB,MAAM,oBAAoB,CAAC;AAE5B;;GAEG;AACH,MAAM,WAAW,iBAAiB,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC5D,gCAAgC;IAChC,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IACpB,8BAA8B;IAC9B,OAAO,CAAC,EAAE,YAAY,EAAE,CAAC;IACzB,qDAAqD;IACrD,UAAU,CAAC,EAAE,kBAAkB,CAAC;IAChC,oCAAoC;IACpC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,2DAA2D;IAC3D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,qCAAqC;IACrC,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AA4CD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAsB,SAAS,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACzD,OAAO,GAAE,iBAAiB,CAAC,CAAC,CAAM,GACjC,OAAO,CAAC,CAAC,CAAC,CAkDZ;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAEvC;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAE3C;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAE3C;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,IAAI,IAAI,CAE3C;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,IAAI,CAGvE"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Server-side exports for Next.js configuration management.
3
+ */
4
+ export { getConfig, clearConfigCache, getConfigCacheSize, invalidateConfig, type NextConfigOptions, } from './get-config';
5
+ export { createConfigProvider, ConfigProvider, useConfig, ConfigContext, } from './config-provider';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,SAAS,EACT,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAChB,KAAK,iBAAiB,GACvB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,oBAAoB,EACpB,cAAc,EACd,SAAS,EACT,aAAa,GACd,MAAM,mBAAmB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,90 @@
1
+ {
2
+ "name": "@dyanet/nextjs-config-aws",
3
+ "version": "1.0.0-beta.1",
4
+ "description": "Next.js adapter for AWS configuration management with support for server components, runtime environment variables, and AWS services integration",
5
+ "main": "dist/cjs/index.js",
6
+ "module": "dist/esm/index.js",
7
+ "types": "dist/types/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/esm/index.js",
11
+ "require": "./dist/cjs/index.js",
12
+ "types": "./dist/types/index.d.ts"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md",
18
+ "LICENSE"
19
+ ],
20
+ "scripts": {
21
+ "build": "npm run clean && npm run build:types && npm run build:esm && npm run build:cjs",
22
+ "build:types": "tsc --project tsconfig.types.json",
23
+ "build:esm": "tsc --project tsconfig.esm.json",
24
+ "build:cjs": "tsc --project tsconfig.cjs.json",
25
+ "clean": "rimraf dist",
26
+ "test": "jest",
27
+ "test:watch": "jest --watch",
28
+ "test:coverage": "jest --coverage",
29
+ "lint": "eslint src/**/*.ts src/**/*.tsx",
30
+ "lint:fix": "eslint src/**/*.ts src/**/*.tsx --fix",
31
+ "typecheck": "tsc --noEmit"
32
+ },
33
+ "keywords": [
34
+ "nextjs",
35
+ "next.js",
36
+ "configuration",
37
+ "aws",
38
+ "secrets-manager",
39
+ "ssm",
40
+ "parameter-store",
41
+ "s3",
42
+ "typescript",
43
+ "zod",
44
+ "server-components",
45
+ "app-router",
46
+ "runtime-env",
47
+ "environment-variables"
48
+ ],
49
+ "author": "Dyanet",
50
+ "license": "MIT",
51
+ "engines": {
52
+ "node": ">=18.0.0",
53
+ "npm": ">=8.0.0"
54
+ },
55
+ "publishConfig": {
56
+ "access": "public",
57
+ "registry": "https://registry.npmjs.org/"
58
+ },
59
+ "dependencies": {
60
+ "@dyanet/config-aws": "^1.0.0"
61
+ },
62
+ "peerDependencies": {
63
+ "next": "^16.0.0",
64
+ "react": "^19.0.0"
65
+ },
66
+ "devDependencies": {
67
+ "@aws-sdk/client-secrets-manager": "^3.0.0",
68
+ "@aws-sdk/client-ssm": "^3.0.0",
69
+ "@aws-sdk/client-s3": "^3.0.0",
70
+ "@types/jest": "^29.5.0",
71
+ "@types/node": "^20.0.0",
72
+ "@types/react": "^19.0.0",
73
+ "fast-check": "^3.15.0",
74
+ "jest": "^29.5.0",
75
+ "next": "^16.0.0",
76
+ "react": "^19.0.0",
77
+ "rimraf": "^5.0.0",
78
+ "ts-jest": "^29.1.0",
79
+ "typescript": "^5.9.2",
80
+ "zod": "^3.22.0"
81
+ },
82
+ "repository": {
83
+ "type": "git",
84
+ "url": "https://github.com/dyanet/config-aws.git"
85
+ },
86
+ "bugs": {
87
+ "url": "https://github.com/dyanet/config-aws/issues"
88
+ },
89
+ "homepage": "https://github.com/dyanet/config-aws/tree/main/packages/nextjs-config-aws"
90
+ }