@dyanet/config-aws 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.
Files changed (122) hide show
  1. package/README.md +195 -0
  2. package/dist/cjs/config-manager.js +360 -0
  3. package/dist/cjs/config-manager.js.map +1 -0
  4. package/dist/cjs/errors/index.js +65 -0
  5. package/dist/cjs/errors/index.js.map +1 -0
  6. package/dist/cjs/index.js +37 -0
  7. package/dist/cjs/index.js.map +1 -0
  8. package/dist/cjs/interfaces/config-loader.interface.js +3 -0
  9. package/dist/cjs/interfaces/config-loader.interface.js.map +1 -0
  10. package/dist/cjs/interfaces/config-manager.interface.js +3 -0
  11. package/dist/cjs/interfaces/config-manager.interface.js.map +1 -0
  12. package/dist/cjs/interfaces/env-file-loader.interface.js +3 -0
  13. package/dist/cjs/interfaces/env-file-loader.interface.js.map +1 -0
  14. package/dist/cjs/interfaces/environment-loader.interface.js +3 -0
  15. package/dist/cjs/interfaces/environment-loader.interface.js.map +1 -0
  16. package/dist/cjs/interfaces/index.js +3 -0
  17. package/dist/cjs/interfaces/index.js.map +1 -0
  18. package/dist/cjs/interfaces/s3-loader.interface.js +3 -0
  19. package/dist/cjs/interfaces/s3-loader.interface.js.map +1 -0
  20. package/dist/cjs/interfaces/secrets-manager-loader.interface.js +3 -0
  21. package/dist/cjs/interfaces/secrets-manager-loader.interface.js.map +1 -0
  22. package/dist/cjs/interfaces/ssm-parameter-store-loader.interface.js +3 -0
  23. package/dist/cjs/interfaces/ssm-parameter-store-loader.interface.js.map +1 -0
  24. package/dist/cjs/loaders/env-file.loader.js +167 -0
  25. package/dist/cjs/loaders/env-file.loader.js.map +1 -0
  26. package/dist/cjs/loaders/environment.loader.js +83 -0
  27. package/dist/cjs/loaders/environment.loader.js.map +1 -0
  28. package/dist/cjs/loaders/index.js +14 -0
  29. package/dist/cjs/loaders/index.js.map +1 -0
  30. package/dist/cjs/loaders/s3.loader.js +141 -0
  31. package/dist/cjs/loaders/s3.loader.js.map +1 -0
  32. package/dist/cjs/loaders/secrets-manager.loader.js +156 -0
  33. package/dist/cjs/loaders/secrets-manager.loader.js.map +1 -0
  34. package/dist/cjs/loaders/ssm-parameter-store.loader.js +193 -0
  35. package/dist/cjs/loaders/ssm-parameter-store.loader.js.map +1 -0
  36. package/dist/cjs/utils/env-file-parser.util.js +98 -0
  37. package/dist/cjs/utils/env-file-parser.util.js.map +1 -0
  38. package/dist/cjs/utils/index.js +8 -0
  39. package/dist/cjs/utils/index.js.map +1 -0
  40. package/dist/cjs/utils/validation.util.js +116 -0
  41. package/dist/cjs/utils/validation.util.js.map +1 -0
  42. package/dist/esm/config-manager.js +356 -0
  43. package/dist/esm/config-manager.js.map +1 -0
  44. package/dist/esm/errors/index.js +57 -0
  45. package/dist/esm/errors/index.js.map +1 -0
  46. package/dist/esm/index.js +21 -0
  47. package/dist/esm/index.js.map +1 -0
  48. package/dist/esm/interfaces/config-loader.interface.js +2 -0
  49. package/dist/esm/interfaces/config-loader.interface.js.map +1 -0
  50. package/dist/esm/interfaces/config-manager.interface.js +2 -0
  51. package/dist/esm/interfaces/config-manager.interface.js.map +1 -0
  52. package/dist/esm/interfaces/env-file-loader.interface.js +2 -0
  53. package/dist/esm/interfaces/env-file-loader.interface.js.map +1 -0
  54. package/dist/esm/interfaces/environment-loader.interface.js +2 -0
  55. package/dist/esm/interfaces/environment-loader.interface.js.map +1 -0
  56. package/dist/esm/interfaces/index.js +2 -0
  57. package/dist/esm/interfaces/index.js.map +1 -0
  58. package/dist/esm/interfaces/s3-loader.interface.js +2 -0
  59. package/dist/esm/interfaces/s3-loader.interface.js.map +1 -0
  60. package/dist/esm/interfaces/secrets-manager-loader.interface.js +2 -0
  61. package/dist/esm/interfaces/secrets-manager-loader.interface.js.map +1 -0
  62. package/dist/esm/interfaces/ssm-parameter-store-loader.interface.js +2 -0
  63. package/dist/esm/interfaces/ssm-parameter-store-loader.interface.js.map +1 -0
  64. package/dist/esm/loaders/env-file.loader.js +130 -0
  65. package/dist/esm/loaders/env-file.loader.js.map +1 -0
  66. package/dist/esm/loaders/environment.loader.js +79 -0
  67. package/dist/esm/loaders/environment.loader.js.map +1 -0
  68. package/dist/esm/loaders/index.js +6 -0
  69. package/dist/esm/loaders/index.js.map +1 -0
  70. package/dist/esm/loaders/s3.loader.js +137 -0
  71. package/dist/esm/loaders/s3.loader.js.map +1 -0
  72. package/dist/esm/loaders/secrets-manager.loader.js +152 -0
  73. package/dist/esm/loaders/secrets-manager.loader.js.map +1 -0
  74. package/dist/esm/loaders/ssm-parameter-store.loader.js +189 -0
  75. package/dist/esm/loaders/ssm-parameter-store.loader.js.map +1 -0
  76. package/dist/esm/utils/env-file-parser.util.js +94 -0
  77. package/dist/esm/utils/env-file-parser.util.js.map +1 -0
  78. package/dist/esm/utils/index.js +3 -0
  79. package/dist/esm/utils/index.js.map +1 -0
  80. package/dist/esm/utils/validation.util.js +112 -0
  81. package/dist/esm/utils/validation.util.js.map +1 -0
  82. package/dist/types/config-manager.d.ts +119 -0
  83. package/dist/types/config-manager.d.ts.map +1 -0
  84. package/dist/types/errors/index.d.ts +43 -0
  85. package/dist/types/errors/index.d.ts.map +1 -0
  86. package/dist/types/index.d.ts +24 -0
  87. package/dist/types/index.d.ts.map +1 -0
  88. package/dist/types/interfaces/config-loader.interface.d.ts +33 -0
  89. package/dist/types/interfaces/config-loader.interface.d.ts.map +1 -0
  90. package/dist/types/interfaces/config-manager.interface.d.ts +86 -0
  91. package/dist/types/interfaces/config-manager.interface.d.ts.map +1 -0
  92. package/dist/types/interfaces/env-file-loader.interface.d.ts +12 -0
  93. package/dist/types/interfaces/env-file-loader.interface.d.ts.map +1 -0
  94. package/dist/types/interfaces/environment-loader.interface.d.ts +10 -0
  95. package/dist/types/interfaces/environment-loader.interface.d.ts.map +1 -0
  96. package/dist/types/interfaces/index.d.ts +8 -0
  97. package/dist/types/interfaces/index.d.ts.map +1 -0
  98. package/dist/types/interfaces/s3-loader.interface.d.ts +14 -0
  99. package/dist/types/interfaces/s3-loader.interface.d.ts.map +1 -0
  100. package/dist/types/interfaces/secrets-manager-loader.interface.d.ts +12 -0
  101. package/dist/types/interfaces/secrets-manager-loader.interface.d.ts.map +1 -0
  102. package/dist/types/interfaces/ssm-parameter-store-loader.interface.d.ts +14 -0
  103. package/dist/types/interfaces/ssm-parameter-store-loader.interface.d.ts.map +1 -0
  104. package/dist/types/loaders/env-file.loader.d.ts +69 -0
  105. package/dist/types/loaders/env-file.loader.d.ts.map +1 -0
  106. package/dist/types/loaders/environment.loader.d.ts +46 -0
  107. package/dist/types/loaders/environment.loader.d.ts.map +1 -0
  108. package/dist/types/loaders/index.d.ts +6 -0
  109. package/dist/types/loaders/index.d.ts.map +1 -0
  110. package/dist/types/loaders/s3.loader.d.ts +62 -0
  111. package/dist/types/loaders/s3.loader.d.ts.map +1 -0
  112. package/dist/types/loaders/secrets-manager.loader.d.ts +68 -0
  113. package/dist/types/loaders/secrets-manager.loader.d.ts.map +1 -0
  114. package/dist/types/loaders/ssm-parameter-store.loader.d.ts +78 -0
  115. package/dist/types/loaders/ssm-parameter-store.loader.d.ts.map +1 -0
  116. package/dist/types/utils/env-file-parser.util.d.ts +45 -0
  117. package/dist/types/utils/env-file-parser.util.d.ts.map +1 -0
  118. package/dist/types/utils/index.d.ts +3 -0
  119. package/dist/types/utils/index.d.ts.map +1 -0
  120. package/dist/types/utils/validation.util.d.ts +53 -0
  121. package/dist/types/utils/validation.util.d.ts.map +1 -0
  122. package/package.json +97 -0
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Configuration options for SSMParameterStoreLoader
3
+ */
4
+ export interface SSMParameterStoreLoaderConfig {
5
+ /** Path prefix for parameters to load */
6
+ parameterPath?: string;
7
+ /** AWS region. If not specified, uses default region from environment */
8
+ region?: string;
9
+ /** Mapping of environment names to path prefixes */
10
+ environmentMapping?: Record<string, string>;
11
+ /** Whether to decrypt SecureString parameters. Default: true */
12
+ withDecryption?: boolean;
13
+ }
14
+ //# sourceMappingURL=ssm-parameter-store-loader.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ssm-parameter-store-loader.interface.d.ts","sourceRoot":"","sources":["../../../src/interfaces/ssm-parameter-store-loader.interface.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,6BAA6B;IAC5C,yCAAyC;IACzC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,yEAAyE;IACzE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oDAAoD;IACpD,kBAAkB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5C,gEAAgE;IAChE,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B"}
@@ -0,0 +1,69 @@
1
+ import type { ConfigLoader } from '../interfaces/config-loader.interface';
2
+ import type { EnvFileLoaderConfig } from '../interfaces/env-file-loader.interface';
3
+ /**
4
+ * Loader that reads configuration from .env files on the filesystem.
5
+ * Uses AWS ECS-compatible format for parsing.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * // Load from default paths (.env, .env.local)
10
+ * const loader = new EnvFileLoader();
11
+ *
12
+ * // Load from specific paths
13
+ * const loader = new EnvFileLoader({
14
+ * paths: ['.env', '.env.production']
15
+ * });
16
+ *
17
+ * // Disable override (first file wins)
18
+ * const loader = new EnvFileLoader({
19
+ * paths: ['.env', '.env.local'],
20
+ * override: false
21
+ * });
22
+ * ```
23
+ *
24
+ * @see https://docs.aws.amazon.com/AmazonECS/latest/developerguide/use-environment-file.html
25
+ */
26
+ export declare class EnvFileLoader implements ConfigLoader {
27
+ /** @internal */
28
+ protected readonly _config: Required<EnvFileLoaderConfig>;
29
+ /** Default paths to search for .env files */
30
+ private static readonly DEFAULT_PATHS;
31
+ /** Default file encoding */
32
+ private static readonly DEFAULT_ENCODING;
33
+ constructor(config?: EnvFileLoaderConfig);
34
+ getName(): string;
35
+ /**
36
+ * Check if at least one of the configured .env files exists.
37
+ * @returns Promise resolving to true if any file exists
38
+ */
39
+ isAvailable(): Promise<boolean>;
40
+ /**
41
+ * Load configuration from .env files.
42
+ *
43
+ * Files are processed in order. When override is true (default),
44
+ * later files override earlier ones. When override is false,
45
+ * earlier files take precedence.
46
+ *
47
+ * Missing files are silently skipped.
48
+ *
49
+ * @returns Promise resolving to the merged configuration
50
+ * @throws ConfigurationLoadError if a file exists but cannot be read
51
+ */
52
+ load(): Promise<Record<string, unknown>>;
53
+ /**
54
+ * Resolve a file path relative to the current working directory.
55
+ * @internal
56
+ */
57
+ protected resolvePath(filePath: string): string;
58
+ /**
59
+ * Check if a file exists.
60
+ * @internal
61
+ */
62
+ protected fileExists(filePath: string): Promise<boolean>;
63
+ /**
64
+ * Read a file's contents.
65
+ * @internal
66
+ */
67
+ protected readFile(filePath: string): Promise<string>;
68
+ }
69
+ //# sourceMappingURL=env-file.loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env-file.loader.d.ts","sourceRoot":"","sources":["../../../src/loaders/env-file.loader.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAC;AAC1E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAInF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,aAAc,YAAW,YAAY;IAChD,gBAAgB;IAChB,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,mBAAmB,CAAC,CAAC;IAE1D,6CAA6C;IAC7C,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAA0B;IAE/D,4BAA4B;IAC5B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAA2B;gBAEvD,MAAM,GAAE,mBAAwB;IAQ5C,OAAO,IAAI,MAAM;IAKjB;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAUrC;;;;;;;;;;;OAWG;IACG,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAuC9C;;;OAGG;IACH,SAAS,CAAC,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM;IAO/C;;;OAGG;cACa,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAS9D;;;OAGG;cACa,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAG5D"}
@@ -0,0 +1,46 @@
1
+ import type { ConfigLoader } from '../interfaces/config-loader.interface';
2
+ import type { EnvironmentLoaderConfig } from '../interfaces/environment-loader.interface';
3
+ /**
4
+ * Loader that reads configuration from process.env.
5
+ * Supports prefix filtering and exclusion lists.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * // Load all environment variables
10
+ * const loader = new EnvironmentLoader();
11
+ *
12
+ * // Load only variables starting with 'APP_', stripping the prefix
13
+ * const loader = new EnvironmentLoader({ prefix: 'APP_' });
14
+ *
15
+ * // Load all except specific variables
16
+ * const loader = new EnvironmentLoader({ exclude: ['PATH', 'HOME'] });
17
+ *
18
+ * // Combine prefix and exclusion
19
+ * const loader = new EnvironmentLoader({
20
+ * prefix: 'APP_',
21
+ * exclude: ['APP_DEBUG']
22
+ * });
23
+ * ```
24
+ */
25
+ export declare class EnvironmentLoader implements ConfigLoader {
26
+ /** @internal */
27
+ protected readonly _config: EnvironmentLoaderConfig;
28
+ constructor(config?: EnvironmentLoaderConfig);
29
+ getName(): string;
30
+ isAvailable(): Promise<boolean>;
31
+ /**
32
+ * Load configuration from process.env.
33
+ *
34
+ * When a prefix is specified:
35
+ * - Only variables starting with the prefix are included
36
+ * - The prefix is stripped from the resulting key names
37
+ *
38
+ * When an exclusion list is specified:
39
+ * - Variables in the list are excluded from the result
40
+ * - Exclusion is checked against the original key (before prefix stripping)
41
+ *
42
+ * @returns Promise resolving to the loaded configuration
43
+ */
44
+ load(): Promise<Record<string, unknown>>;
45
+ }
46
+ //# sourceMappingURL=environment.loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"environment.loader.d.ts","sourceRoot":"","sources":["../../../src/loaders/environment.loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAC;AAC1E,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,4CAA4C,CAAC;AAE1F;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,iBAAkB,YAAW,YAAY;IACpD,gBAAgB;IAChB,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,uBAAuB,CAAC;gBAExC,MAAM,GAAE,uBAA4B;IAIhD,OAAO,IAAI,MAAM;IAIX,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAIrC;;;;;;;;;;;;OAYG;IACG,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAmC/C"}
@@ -0,0 +1,6 @@
1
+ export { EnvironmentLoader } from './environment.loader';
2
+ export { EnvFileLoader } from './env-file.loader';
3
+ export { S3Loader } from './s3.loader';
4
+ export { SecretsManagerLoader } from './secrets-manager.loader';
5
+ export { SSMParameterStoreLoader } from './ssm-parameter-store.loader';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/loaders/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC"}
@@ -0,0 +1,62 @@
1
+ import { S3Client } from '@aws-sdk/client-s3';
2
+ import type { ConfigLoader } from '../interfaces/config-loader.interface';
3
+ import type { S3LoaderConfig } from '../interfaces/s3-loader.interface';
4
+ /**
5
+ * Loader that reads configuration from S3 buckets.
6
+ * Supports JSON and .env file formats with auto-detection.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * // Load JSON config from S3
11
+ * const loader = new S3Loader({
12
+ * bucket: 'my-config-bucket',
13
+ * key: 'config/app.json',
14
+ * format: 'json'
15
+ * });
16
+ *
17
+ * // Load .env file from S3 with auto-detection
18
+ * const loader = new S3Loader({
19
+ * bucket: 'my-config-bucket',
20
+ * key: 'config/.env'
21
+ * });
22
+ * ```
23
+ *
24
+ * @see https://docs.aws.amazon.com/AmazonECS/latest/developerguide/use-environment-file.html
25
+ */
26
+ export declare class S3Loader implements ConfigLoader {
27
+ /** @internal */
28
+ protected readonly _config: Required<S3LoaderConfig>;
29
+ /** @internal */
30
+ protected readonly _client: S3Client;
31
+ constructor(config: S3LoaderConfig);
32
+ getName(): string;
33
+ /**
34
+ * Check if this loader is available by verifying AWS credentials.
35
+ * @returns Promise resolving to true if AWS credentials are available
36
+ */
37
+ isAvailable(): Promise<boolean>;
38
+ /**
39
+ * Load configuration from S3.
40
+ * @returns Promise resolving to configuration key-value pairs
41
+ * @throws AWSServiceError if S3 operation fails
42
+ * @throws ConfigurationLoadError if content cannot be parsed
43
+ */
44
+ load(): Promise<Record<string, unknown>>;
45
+ /**
46
+ * Parse content based on format setting or auto-detection.
47
+ * @internal
48
+ */
49
+ protected parseContent(content: string): Record<string, unknown>;
50
+ /**
51
+ * Detect content format based on structure.
52
+ * JSON content starts with '{' after trimming whitespace.
53
+ * @internal
54
+ */
55
+ protected detectFormat(content: string): 'json' | 'env';
56
+ /**
57
+ * Parse JSON content.
58
+ * @internal
59
+ */
60
+ protected parseJson(content: string): Record<string, unknown>;
61
+ }
62
+ //# sourceMappingURL=s3.loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"s3.loader.d.ts","sourceRoot":"","sources":["../../../src/loaders/s3.loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAEhE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAC;AAC1E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAIxE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,QAAS,YAAW,YAAY;IAC3C,gBAAgB;IAChB,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,cAAc,CAAC,CAAC;IACrD,gBAAgB;IAChB,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC;gBAEzB,MAAM,EAAE,cAAc;IAclC,OAAO,IAAI,MAAM;IAKjB;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IASrC;;;;;OAKG;IACG,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAkD9C;;;OAGG;IACH,SAAS,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAUhE;;;;OAIG;IACH,SAAS,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,KAAK;IAQvD;;;OAGG;IACH,SAAS,CAAC,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAkB9D"}
@@ -0,0 +1,68 @@
1
+ import { SecretsManagerClient } from '@aws-sdk/client-secrets-manager';
2
+ import type { ConfigLoader } from '../interfaces/config-loader.interface';
3
+ import type { SecretsManagerLoaderConfig } from '../interfaces/secrets-manager-loader.interface';
4
+ /**
5
+ * Loader that reads configuration from AWS Secrets Manager.
6
+ * Supports environment-aware path construction.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * // Basic usage
11
+ * const loader = new SecretsManagerLoader({
12
+ * secretName: '/my-app/config',
13
+ * region: 'us-east-1'
14
+ * });
15
+ *
16
+ * // With environment mapping
17
+ * const loader = new SecretsManagerLoader({
18
+ * secretName: '/my-app/config',
19
+ * environmentMapping: {
20
+ * development: 'dev',
21
+ * staging: 'stg',
22
+ * production: 'prod'
23
+ * }
24
+ * });
25
+ * ```
26
+ */
27
+ export declare class SecretsManagerLoader implements ConfigLoader {
28
+ /** @internal */
29
+ protected readonly _client: SecretsManagerClient;
30
+ /** @internal */
31
+ protected readonly _config: Required<SecretsManagerLoaderConfig>;
32
+ /** @internal */
33
+ protected readonly _appEnv: string;
34
+ constructor(config?: SecretsManagerLoaderConfig);
35
+ /**
36
+ * Get the name of this loader for logging and debugging.
37
+ * @returns The loader name with secret path
38
+ */
39
+ getName(): string;
40
+ /**
41
+ * Check if this loader is available in the current environment.
42
+ * @returns Promise resolving to true if not in local environment and AWS credentials are available
43
+ */
44
+ isAvailable(): Promise<boolean>;
45
+ /**
46
+ * Load configuration from AWS Secrets Manager.
47
+ * @returns Promise resolving to configuration key-value pairs from the secret
48
+ * @throws AWSServiceError if AWS operation fails
49
+ * @throws ConfigurationLoadError if secret cannot be parsed
50
+ */
51
+ load(): Promise<Record<string, unknown>>;
52
+ /**
53
+ * Build the environment-aware secret name/path.
54
+ * @returns The full secret name with environment prefix
55
+ */
56
+ buildSecretName(): string;
57
+ /**
58
+ * Get the current app environment.
59
+ * @returns The current APP_ENV or NODE_ENV value
60
+ */
61
+ getAppEnv(): string;
62
+ /**
63
+ * Get the environment mapping configuration.
64
+ * @returns The environment mapping record
65
+ */
66
+ getEnvironmentMapping(): Record<string, string>;
67
+ }
68
+ //# sourceMappingURL=secrets-manager.loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secrets-manager.loader.d.ts","sourceRoot":"","sources":["../../../src/loaders/secrets-manager.loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAG9F,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAC;AAC1E,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,gDAAgD,CAAC;AAGjG;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,oBAAqB,YAAW,YAAY;IACvD,gBAAgB;IAChB,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,oBAAoB,CAAC;IACjD,gBAAgB;IAChB,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,0BAA0B,CAAC,CAAC;IACjE,gBAAgB;IAChB,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;gBAEvB,MAAM,GAAE,0BAA+B;IAsBnD;;;OAGG;IACH,OAAO,IAAI,MAAM;IAKjB;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAerC;;;;;OAKG;IACG,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAoE9C;;;OAGG;IACH,eAAe,IAAI,MAAM;IAczB;;;OAGG;IACH,SAAS,IAAI,MAAM;IAInB;;;OAGG;IACH,qBAAqB,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;CAGhD"}
@@ -0,0 +1,78 @@
1
+ import { SSMClient } from '@aws-sdk/client-ssm';
2
+ import type { ConfigLoader } from '../interfaces/config-loader.interface';
3
+ import type { SSMParameterStoreLoaderConfig } from '../interfaces/ssm-parameter-store-loader.interface';
4
+ /**
5
+ * Loader that reads configuration from AWS SSM Parameter Store.
6
+ * Supports environment-aware path construction, pagination, and decryption options.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * // Basic usage
11
+ * const loader = new SSMParameterStoreLoader({
12
+ * parameterPath: '/my-app/config',
13
+ * region: 'us-east-1'
14
+ * });
15
+ *
16
+ * // With environment mapping
17
+ * const loader = new SSMParameterStoreLoader({
18
+ * parameterPath: '/my-app/config',
19
+ * environmentMapping: {
20
+ * development: 'dev',
21
+ * staging: 'stg',
22
+ * production: 'prod'
23
+ * }
24
+ * });
25
+ * ```
26
+ */
27
+ export declare class SSMParameterStoreLoader implements ConfigLoader {
28
+ /** @internal */
29
+ protected readonly _client: SSMClient;
30
+ /** @internal */
31
+ protected readonly _config: Required<SSMParameterStoreLoaderConfig>;
32
+ /** @internal */
33
+ protected readonly _appEnv: string;
34
+ constructor(config?: SSMParameterStoreLoaderConfig);
35
+ /**
36
+ * Get the name of this loader for logging and debugging.
37
+ * @returns The loader name with parameter path
38
+ */
39
+ getName(): string;
40
+ /**
41
+ * Check if this loader is available in the current environment.
42
+ * @returns Promise resolving to true if not in local environment and AWS credentials are available
43
+ */
44
+ isAvailable(): Promise<boolean>;
45
+ /**
46
+ * Load configuration from AWS SSM Parameter Store.
47
+ * Implements recursive parameter fetching with NextToken handling for pagination.
48
+ * @returns Promise resolving to configuration key-value pairs from parameters
49
+ * @throws AWSServiceError if AWS operation fails
50
+ * @throws ConfigurationLoadError if parameter path cannot be constructed
51
+ */
52
+ load(): Promise<Record<string, unknown>>;
53
+ /**
54
+ * Build the environment-aware parameter path.
55
+ * @returns The full parameter path with environment prefix
56
+ * @throws ConfigurationLoadError if no environment mapping found
57
+ */
58
+ buildParameterPath(): string;
59
+ /**
60
+ * Transform parameter name by removing the prefix and converting to uppercase.
61
+ * Example: '/dev/config-aws/database/host' -> 'DATABASE_HOST'
62
+ * @param parameterName The full parameter name from AWS
63
+ * @param pathPrefix The path prefix to remove
64
+ * @returns The transformed parameter name or null if invalid
65
+ */
66
+ private transformParameterName;
67
+ /**
68
+ * Get the current app environment.
69
+ * @returns The current APP_ENV or NODE_ENV value
70
+ */
71
+ getAppEnv(): string;
72
+ /**
73
+ * Get the environment mapping configuration.
74
+ * @returns The environment mapping record
75
+ */
76
+ getEnvironmentMapping(): Record<string, string>;
77
+ }
78
+ //# sourceMappingURL=ssm-parameter-store.loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ssm-parameter-store.loader.d.ts","sourceRoot":"","sources":["../../../src/loaders/ssm-parameter-store.loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAG5E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAC;AAC1E,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAC;AAGxG;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,uBAAwB,YAAW,YAAY;IAC1D,gBAAgB;IAChB,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAC;IACtC,gBAAgB;IAChB,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,6BAA6B,CAAC,CAAC;IACpE,gBAAgB;IAChB,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;gBAEvB,MAAM,GAAE,6BAAkC;IAuBtD;;;OAGG;IACH,OAAO,IAAI,MAAM;IAUjB;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAerC;;;;;;OAMG;IACG,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IA6E9C;;;;OAIG;IACH,kBAAkB,IAAI,MAAM;IAc5B;;;;;;OAMG;IACH,OAAO,CAAC,sBAAsB;IAuB9B;;;OAGG;IACH,SAAS,IAAI,MAAM;IAInB;;;OAGG;IACH,qBAAqB,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;CAGhD"}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Parser for AWS ECS-compatible environment files.
3
+ *
4
+ * Format rules (per AWS ECS documentation):
5
+ * - Lines beginning with # are comments and ignored
6
+ * - Blank lines are ignored
7
+ * - Format: VARIABLE=VALUE (no spaces around =)
8
+ * - Variable names must match /^[a-zA-Z_][a-zA-Z0-9_]*$/
9
+ * - Values are literal (no quote processing, no interpolation)
10
+ * - One variable per line
11
+ * - Lines without = are ignored
12
+ * - Maximum line length: 32KB
13
+ *
14
+ * @see https://docs.aws.amazon.com/AmazonECS/latest/developerguide/use-environment-file.html
15
+ */
16
+ export declare class EnvFileParser {
17
+ /** Maximum line length per AWS ECS specification */
18
+ private static readonly MAX_LINE_LENGTH;
19
+ /** Valid variable name pattern: alphanumeric + underscore, cannot start with digit */
20
+ private static readonly VARIABLE_NAME_PATTERN;
21
+ /**
22
+ * Parse environment file content into key-value pairs.
23
+ * @param content The raw content of the environment file
24
+ * @returns Record of environment variable names to values
25
+ */
26
+ static parse(content: string): Record<string, string>;
27
+ /**
28
+ * Check if a variable name is valid per AWS ECS format.
29
+ * Variable names must:
30
+ * - Start with a letter (a-z, A-Z) or underscore (_)
31
+ * - Contain only alphanumeric characters and underscores
32
+ * - Not be empty
33
+ *
34
+ * @param name The variable name to check
35
+ * @returns true if the name is valid
36
+ */
37
+ static isValidVariableName(name: string): boolean;
38
+ /**
39
+ * Serialize a configuration object to AWS ECS-compatible env file format.
40
+ * @param config The configuration object to serialize
41
+ * @returns The serialized env file content
42
+ */
43
+ static serialize(config: Record<string, string>): string;
44
+ }
45
+ //# sourceMappingURL=env-file-parser.util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env-file-parser.util.d.ts","sourceRoot":"","sources":["../../../src/utils/env-file-parser.util.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,qBAAa,aAAa;IACxB,oDAAoD;IACpD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAa;IAEpD,sFAAsF;IACtF,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,qBAAqB,CAA8B;IAE3E;;;;OAIG;IACH,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IA+CrD;;;;;;;;;OASG;IACH,MAAM,CAAC,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAOjD;;;;OAIG;IACH,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM;CAYzD"}
@@ -0,0 +1,3 @@
1
+ export { ConfigValidationUtil } from './validation.util';
2
+ export { EnvFileParser } from './env-file-parser.util';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC"}
@@ -0,0 +1,53 @@
1
+ import type { ZodType, ZodError, TypeOf } from 'zod';
2
+ import { ValidationError } from '../errors';
3
+ /**
4
+ * Framework-agnostic validation utility for configuration values.
5
+ * Provides methods for validating configuration objects against Zod schemas.
6
+ */
7
+ export declare class ConfigValidationUtil {
8
+ /**
9
+ * Validates a value against a Zod schema.
10
+ * @param schema The Zod schema to validate against
11
+ * @param value The value to validate
12
+ * @param context Optional context for error messages
13
+ * @returns The validated and transformed value
14
+ * @throws ValidationError if validation fails
15
+ */
16
+ static validate<T extends ZodType>(schema: T, value: unknown, context?: string): TypeOf<T>;
17
+ /**
18
+ * Safely validates a value against a Zod schema without throwing.
19
+ * @param schema The Zod schema to validate against
20
+ * @param value The value to validate
21
+ * @returns Object with success flag and either data or error
22
+ */
23
+ static safeValidate<T extends ZodType>(schema: T, value: unknown): {
24
+ success: true;
25
+ data: TypeOf<T>;
26
+ } | {
27
+ success: false;
28
+ error: ValidationError;
29
+ };
30
+ /**
31
+ * Formats Zod validation errors into a structured format.
32
+ * @param error The ZodError to format
33
+ * @returns Formatted error object or string
34
+ */
35
+ static formatValidationErrors(error: ZodError): unknown;
36
+ /**
37
+ * Creates a detailed error message for configuration validation failures.
38
+ * @param error The ZodError to create a message for
39
+ * @param context Optional context for the error
40
+ * @returns Detailed error message string
41
+ */
42
+ static createDetailedErrorMessage(error: ZodError, context?: string): string;
43
+ /**
44
+ * Validates configuration with enhanced error context.
45
+ * @param schema The Zod schema to validate against
46
+ * @param value The configuration object to validate
47
+ * @param source The source of the configuration (e.g., 'environment', 'secrets-manager')
48
+ * @returns The validated configuration
49
+ * @throws ValidationError with enhanced context
50
+ */
51
+ static validateConfiguration<T extends ZodType>(schema: T, value: unknown, source: string): TypeOf<T>;
52
+ }
53
+ //# sourceMappingURL=validation.util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.util.d.ts","sourceRoot":"","sources":["../../../src/utils/validation.util.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAE5C;;;GAGG;AACH,qBAAa,oBAAoB;IAC/B;;;;;;;OAOG;IACH,MAAM,CAAC,QAAQ,CAAC,CAAC,SAAS,OAAO,EAC/B,MAAM,EAAE,CAAC,EACT,KAAK,EAAE,OAAO,EACd,OAAO,CAAC,EAAE,MAAM,GACf,MAAM,CAAC,CAAC,CAAC;IAeZ;;;;;OAKG;IACH,MAAM,CAAC,YAAY,CAAC,CAAC,SAAS,OAAO,EACnC,MAAM,EAAE,CAAC,EACT,KAAK,EAAE,OAAO,GACb;QAAE,OAAO,EAAE,IAAI,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,CAAA;KAAE,GAAG;QAAE,OAAO,EAAE,KAAK,CAAC;QAAC,KAAK,EAAE,eAAe,CAAA;KAAE;IAalF;;;;OAIG;IACH,MAAM,CAAC,sBAAsB,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO;IA+BvD;;;;;OAKG;IACH,MAAM,CAAC,0BAA0B,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM;IAmB5E;;;;;;;OAOG;IACH,MAAM,CAAC,qBAAqB,CAAC,CAAC,SAAS,OAAO,EAC5C,MAAM,EAAE,CAAC,EACT,KAAK,EAAE,OAAO,EACd,MAAM,EAAE,MAAM,GACb,MAAM,CAAC,CAAC,CAAC;CAYb"}
package/package.json ADDED
@@ -0,0 +1,97 @@
1
+ {
2
+ "name": "@dyanet/config-aws",
3
+ "version": "1.0.0",
4
+ "description": "Framework-agnostic AWS configuration management with support for environment variables, AWS Secrets Manager, SSM Parameter Store, S3, and .env files",
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",
30
+ "lint:fix": "eslint src/**/*.ts --fix",
31
+ "typecheck": "tsc --noEmit"
32
+ },
33
+ "keywords": [
34
+ "configuration",
35
+ "aws",
36
+ "secrets-manager",
37
+ "ssm",
38
+ "parameter-store",
39
+ "s3",
40
+ "env-file",
41
+ "typescript",
42
+ "zod",
43
+ "framework-agnostic"
44
+ ],
45
+ "author": "Dyanet",
46
+ "license": "MIT",
47
+ "engines": {
48
+ "node": ">=18.0.0",
49
+ "npm": ">=8.0.0"
50
+ },
51
+ "publishConfig": {
52
+ "access": "public",
53
+ "registry": "https://registry.npmjs.org/"
54
+ },
55
+ "peerDependencies": {
56
+ "@aws-sdk/client-secrets-manager": "^3.0.0",
57
+ "@aws-sdk/client-ssm": "^3.0.0",
58
+ "@aws-sdk/client-s3": "^3.0.0",
59
+ "zod": "^3.22.0"
60
+ },
61
+ "peerDependenciesMeta": {
62
+ "@aws-sdk/client-secrets-manager": {
63
+ "optional": true
64
+ },
65
+ "@aws-sdk/client-ssm": {
66
+ "optional": true
67
+ },
68
+ "@aws-sdk/client-s3": {
69
+ "optional": true
70
+ }
71
+ },
72
+ "devDependencies": {
73
+ "@aws-sdk/client-secrets-manager": "^3.0.0",
74
+ "@aws-sdk/client-ssm": "^3.0.0",
75
+ "@aws-sdk/client-s3": "^3.0.0",
76
+ "@types/jest": "^29.5.0",
77
+ "@types/node": "^20.0.0",
78
+ "@typescript-eslint/eslint-plugin": "^6.21.0",
79
+ "@typescript-eslint/parser": "^6.21.0",
80
+ "aws-sdk-client-mock": "^4.0.0",
81
+ "eslint": "^8.0.0",
82
+ "fast-check": "^3.15.0",
83
+ "jest": "^29.5.0",
84
+ "rimraf": "^5.0.0",
85
+ "ts-jest": "^29.1.0",
86
+ "typescript": "^5.9.2",
87
+ "zod": "^3.22.0"
88
+ },
89
+ "repository": {
90
+ "type": "git",
91
+ "url": "https://github.com/dyanet/nestjs-config-aws.git"
92
+ },
93
+ "bugs": {
94
+ "url": "https://github.com/dyanet/nestjs-config-aws/issues"
95
+ },
96
+ "homepage": "https://github.com/dyanet/nestjs-config-aws/tree/main/packages/config-aws"
97
+ }