@acmekit/secrets-aws 2.13.53

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.
@@ -0,0 +1,18 @@
1
+ import { ModuleExports } from "@acmekit/framework/types";
2
+ import type { Logger } from "@acmekit/framework/types";
3
+ import type { ContainerLike } from "@acmekit/framework/types";
4
+ import { AwsSecretsModuleOptions } from "./types";
5
+ declare const moduleDefinition: ModuleExports;
6
+ export default moduleDefinition;
7
+ export * from "./initialize";
8
+ export * from "./types";
9
+ /**
10
+ * Bootstrap injection hook called by `secretsBootstrapLoader` before modules initialize.
11
+ *
12
+ * Fetches secrets configured under `inject` and writes them to `process.env`.
13
+ * Runs before `pgConnectionLoader` so database credentials can come from AWS Secrets Manager.
14
+ *
15
+ * Values are NEVER logged.
16
+ */
17
+ export declare function bootstrapInject(options: AwsSecretsModuleOptions, container: ContainerLike, logger?: Logger): Promise<void>;
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AACxD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAA;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAG7D,OAAO,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAA;AAOjD,QAAA,MAAM,gBAAgB,EAAE,aAGvB,CAAA;AAED,eAAe,gBAAgB,CAAA;AAC/B,cAAc,cAAc,CAAA;AAC5B,cAAc,SAAS,CAAA;AAEvB;;;;;;;GAOG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,uBAAuB,EAChC,SAAS,EAAE,aAAa,EACxB,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,IAAI,CAAC,CA6Df"}
package/dist/index.js ADDED
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
36
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.bootstrapInject = bootstrapInject;
43
+ const client_secrets_manager_1 = require("@aws-sdk/client-secrets-manager");
44
+ const awilix_1 = require("@acmekit/framework/awilix");
45
+ const loaders_1 = __importStar(require("./loaders"));
46
+ const aws_secrets_1 = __importDefault(require("./services/aws-secrets"));
47
+ const CONTAINER_KEY = "secretsManagerClient";
48
+ const service = aws_secrets_1.default;
49
+ const loaders = [loaders_1.default];
50
+ const moduleDefinition = {
51
+ service,
52
+ loaders,
53
+ };
54
+ exports.default = moduleDefinition;
55
+ __exportStar(require("./initialize"), exports);
56
+ __exportStar(require("./types"), exports);
57
+ /**
58
+ * Bootstrap injection hook called by `secretsBootstrapLoader` before modules initialize.
59
+ *
60
+ * Fetches secrets configured under `inject` and writes them to `process.env`.
61
+ * Runs before `pgConnectionLoader` so database credentials can come from AWS Secrets Manager.
62
+ *
63
+ * Values are NEVER logged.
64
+ */
65
+ async function bootstrapInject(options, container, logger) {
66
+ const inject = options.inject ?? [];
67
+ if (!inject.length) {
68
+ return;
69
+ }
70
+ let client;
71
+ // Idempotent: reuse client if the module loader already ran (unlikely at bootstrap, but safe)
72
+ if (container.hasRegistration?.(CONTAINER_KEY)) {
73
+ client = container.resolve(CONTAINER_KEY);
74
+ }
75
+ else {
76
+ client = (0, loaders_1.createSecretsManagerClient)(options);
77
+ container.register?.({
78
+ [CONTAINER_KEY]: (0, awilix_1.asValue)(client),
79
+ });
80
+ }
81
+ for (const secretConfig of inject) {
82
+ try {
83
+ const response = await client.send(new client_secrets_manager_1.GetSecretValueCommand({
84
+ SecretId: secretConfig.secretId,
85
+ VersionStage: secretConfig.versionStage,
86
+ }));
87
+ const raw = response.SecretString;
88
+ if (!raw) {
89
+ continue;
90
+ }
91
+ let parsed;
92
+ try {
93
+ parsed = JSON.parse(raw);
94
+ }
95
+ catch {
96
+ // Secret is a plain string — inject under the secretId key itself
97
+ parsed = { [secretConfig.secretId]: raw };
98
+ }
99
+ for (const [secretKey, secretValue] of Object.entries(parsed)) {
100
+ const envKey = secretConfig.mapping
101
+ ? (secretConfig.mapping[secretKey] ?? secretKey)
102
+ : secretKey;
103
+ if (!secretConfig.override && process.env[envKey] !== undefined) {
104
+ continue;
105
+ }
106
+ // Write to process.env — never log the value
107
+ process.env[envKey] = String(secretValue);
108
+ }
109
+ }
110
+ catch (err) {
111
+ const message = `Failed to bootstrap secret "${secretConfig.secretId}": ` + err.message;
112
+ if (options.fallback === false) {
113
+ throw new Error(message);
114
+ }
115
+ logger?.warn(message);
116
+ }
117
+ }
118
+ }
119
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,0CAiEC;AAnGD,4EAGwC;AACxC,sDAAmD;AAInD,qDAA8D;AAC9D,yEAAsD;AAGtD,MAAM,aAAa,GAAG,sBAAsB,CAAA;AAE5C,MAAM,OAAO,GAAG,qBAAiB,CAAA;AACjC,MAAM,OAAO,GAAG,CAAC,iBAAM,CAAC,CAAA;AAExB,MAAM,gBAAgB,GAAkB;IACtC,OAAO;IACP,OAAO;CACR,CAAA;AAED,kBAAe,gBAAgB,CAAA;AAC/B,+CAA4B;AAC5B,0CAAuB;AAEvB;;;;;;;GAOG;AACI,KAAK,UAAU,eAAe,CACnC,OAAgC,EAChC,SAAwB,EACxB,MAAe;IAEf,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,EAAE,CAAA;IACnC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;QACnB,OAAM;IACR,CAAC;IAED,IAAI,MAA4B,CAAA;IAEhC,8FAA8F;IAC9F,IAAK,SAAiB,CAAC,eAAe,EAAE,CAAC,aAAa,CAAC,EAAE,CAAC;QACxD,MAAM,GAAI,SAAiB,CAAC,OAAO,CAAC,aAAa,CAAyB,CAAA;IAC5E,CAAC;SAAM,CAAC;QACN,MAAM,GAAG,IAAA,oCAA0B,EAAC,OAAO,CAAC,CAC3C;QAAC,SAAiB,CAAC,QAAQ,EAAE,CAAC;YAC7B,CAAC,aAAa,CAAC,EAAE,IAAA,gBAAO,EAAC,MAAM,CAAC;SACjC,CAAC,CAAA;IACJ,CAAC;IAED,K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,QAAQ,KAAK,KAAK,EAAE,CAAC;gBAC/B,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAA;YAC1B,CAAC;YACD,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAA;QACvB,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { ExternalModuleDeclaration, ISecretsModuleService } from "@acmekit/framework/types";
2
+ import { AwsSecretsModuleOptions } from "../types";
3
+ export declare const initialize: (options?: AwsSecretsModuleOptions | ExternalModuleDeclaration) => Promise<ISecretsModuleService>;
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/initialize/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,yBAAyB,EACzB,qBAAqB,EAEtB,MAAM,0BAA0B,CAAA;AAEjC,OAAO,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAA;AAElD,eAAO,MAAM,UAAU,GACrB,UAAU,uBAAuB,GAAG,yBAAyB,KAC5D,OAAO,CAAC,qBAAqB,CAW/B,CAAA"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.initialize = void 0;
4
+ const modules_sdk_1 = require("@acmekit/framework/modules-sdk");
5
+ const utils_1 = require("@acmekit/framework/utils");
6
+ const initialize = async (options) => {
7
+ const serviceKey = utils_1.Modules.SECRETS;
8
+ const loaded = await modules_sdk_1.AcmeKitModule.bootstrap({
9
+ moduleKey: serviceKey,
10
+ defaultPath: "@acmekit/secrets-aws",
11
+ declaration: options,
12
+ });
13
+ return loaded[serviceKey];
14
+ };
15
+ exports.initialize = initialize;
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/initialize/index.ts"],"names":[],"mappings":";;;AAAA,gEAA8D;AAM9D,oDAAkD;AAG3C,MAAM,UAAU,GAAG,KAAK,EAC7B,OAA6D,EAC7B,EAAE;IAClC,MAAM,UAAU,GAAG,eAAO,CAAC,OAAO,CAAA;IAClC,MAAM,MAAM,GAAG,MAAM,2BAAa,CAAC,SAAS,CAAwB;QAClE,SAAS,EAAE,UAAU;QACrB,WAAW,EAAE,sBAAsB;QACnC,WAAW,EAAE,OAEgB;KAC9B,CAAC,CAAA;IAEF,OAAO,MAAM,CAAC,UAAU,CAAC,CAAA;AAC3B,CAAC,CAAA;AAbY,QAAA,UAAU,cAatB"}
@@ -0,0 +1,14 @@
1
+ import { SecretsManagerClient } from "@aws-sdk/client-secrets-manager";
2
+ import { LoaderOptions } from "@acmekit/framework/types";
3
+ import { AwsSecretsModuleOptions } from "../types";
4
+ /**
5
+ * Creates a configured SecretsManagerClient from module options.
6
+ */
7
+ export declare function createSecretsManagerClient(options: AwsSecretsModuleOptions): SecretsManagerClient;
8
+ /**
9
+ * Module loader — runs during the parallel module initialization phase.
10
+ * Idempotent: skips client creation if `secretsBootstrapLoader` already ran.
11
+ */
12
+ declare const _default: ({ container, logger, options, }: LoaderOptions) => Promise<void>;
13
+ export default _default;
14
+ //# 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,EAEL,oBAAoB,EACrB,MAAM,iCAAiC,CAAA;AAGxC,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AACxD,OAAO,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAA;AAIlD;;GAEG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,uBAAuB,GAC/B,oBAAoB,CActB;AAED;;;GAGG;yBACmB,iCAInB,aAAa,KAAG,OAAO,CAAC,IAAI,CAAC;AAJhC,wBA4CC"}
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createSecretsManagerClient = createSecretsManagerClient;
4
+ const client_secrets_manager_1 = require("@aws-sdk/client-secrets-manager");
5
+ const credential_providers_1 = require("@aws-sdk/credential-providers");
6
+ const awilix_1 = require("@acmekit/framework/awilix");
7
+ const CONTAINER_KEY = "secretsManagerClient";
8
+ /**
9
+ * Creates a configured SecretsManagerClient from module options.
10
+ */
11
+ function createSecretsManagerClient(options) {
12
+ const { region, endpoint, roleArn } = options;
13
+ const credentials = roleArn
14
+ ? (0, credential_providers_1.fromTemporaryCredentials)({
15
+ params: { RoleArn: roleArn, RoleSessionName: "acmekit-secrets" },
16
+ })
17
+ : undefined;
18
+ return new client_secrets_manager_1.SecretsManagerClient({
19
+ region,
20
+ endpoint,
21
+ credentials,
22
+ });
23
+ }
24
+ /**
25
+ * Module loader — runs during the parallel module initialization phase.
26
+ * Idempotent: skips client creation if `secretsBootstrapLoader` already ran.
27
+ */
28
+ exports.default = async ({ container, logger, options, }) => {
29
+ if (container.hasRegistration(CONTAINER_KEY)) {
30
+ return;
31
+ }
32
+ const moduleOptions = options;
33
+ if (!moduleOptions?.region && !process.env.AWS_REGION) {
34
+ logger?.warn("No AWS region configured for the Secrets module. " +
35
+ "Set `region` in module options or the AWS_REGION environment variable.");
36
+ }
37
+ const client = createSecretsManagerClient(moduleOptions ?? {});
38
+ if (moduleOptions?.verifyOnStartup !== false) {
39
+ const inject = moduleOptions?.inject ?? [];
40
+ for (const secretConfig of inject) {
41
+ try {
42
+ await client.send(new client_secrets_manager_1.DescribeSecretCommand({ SecretId: secretConfig.secretId }));
43
+ }
44
+ catch (err) {
45
+ const message = `Secrets module startup verification failed for "${secretConfig.secretId}": ` +
46
+ err.message;
47
+ if (moduleOptions?.fallback === false) {
48
+ throw new Error(message);
49
+ }
50
+ logger?.warn(message);
51
+ }
52
+ }
53
+ }
54
+ logger?.info("Secrets module 'secrets-aws': AWS Secrets Manager client ready");
55
+ container.register({
56
+ [CONTAINER_KEY]: (0, awilix_1.asValue)(client),
57
+ });
58
+ };
59
+ //# sourceMappingURL=index.js.map
@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M,CAAC,IAAI,CACf,IAAI,8CAAqB,CAAC,EAAE,QAAQ,EAAE,YAAY,CAAC,QAAQ,EAAE,CAAC,CAC/D,CAAA;YACH,CAAC;YAAC,OAAO,GAAQ,EAAE,CAAC;gBAClB,MAAM,OAAO,GACX,mDAAmD,YAAY,CAAC,QAAQ,KAAK;oBAC7E,GAAG,CAAC,OAAO,CAAA;gBACb,IAAI,aAAa,EAAE,QAAQ,KAAK,KAAK,EAAE,CAAC;oBACtC,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAA;gBAC1B,CAAC;gBACD,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAA;YACvB,CAAC;QACH,CAAC;IACH,CAAC;IAED,MAAM,EAAE,IAAI,CAAC,gEAAgE,CAAC,CAAA;IAE9E,SAAS,CAAC,QAAQ,CAAC;QACjB,CAAC,aAAa,CAAC,EAAE,IAAA,gBAAO,EAAC,MAAM,CAAC;KACjC,CAAC,CAAA;AACJ,CAAC,CAAA"}
@@ -0,0 +1,28 @@
1
+ import { SecretsManagerClient } from "@aws-sdk/client-secrets-manager";
2
+ import { ISecretsModuleService, SecretGetOptions } from "@acmekit/framework/types";
3
+ import { AwsSecretsModuleOptions } from "../types";
4
+ type InjectedDependencies = {
5
+ secretsManagerClient: SecretsManagerClient;
6
+ };
7
+ /**
8
+ * AWS Secrets Manager provider for `ISecretsModuleService`.
9
+ *
10
+ * Supports two access patterns:
11
+ * - Bootstrap injection: fetched by `secretsBootstrapLoader` at startup, written to `process.env`
12
+ * - Runtime access: `get()`, `getJSON()`, `getKey()` — use `cache: false` for audit-trail-per-call
13
+ *
14
+ * Secret values are NEVER logged.
15
+ */
16
+ declare class AwsSecretsService implements ISecretsModuleService {
17
+ #private;
18
+ constructor({ secretsManagerClient }: InjectedDependencies, options?: AwsSecretsModuleOptions);
19
+ __hooks: {
20
+ onApplicationShutdown: () => Promise<void>;
21
+ };
22
+ get(secretId: string, options?: SecretGetOptions): Promise<string | null>;
23
+ getJSON<T>(secretId: string, options?: SecretGetOptions): Promise<T | null>;
24
+ getKey(secretId: string, key: string, options?: SecretGetOptions): Promise<string | null>;
25
+ invalidate(secretId: string): void;
26
+ }
27
+ export default AwsSecretsService;
28
+ //# sourceMappingURL=aws-secrets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aws-secrets.d.ts","sourceRoot":"","sources":["../../src/services/aws-secrets.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,oBAAoB,EACrB,MAAM,iCAAiC,CAAA;AACxC,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EACjB,MAAM,0BAA0B,CAAA;AAEjC,OAAO,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAA;AAElD,KAAK,oBAAoB,GAAG;IAC1B,oBAAoB,EAAE,oBAAoB,CAAA;CAC3C,CAAA;AASD;;;;;;;;GAQG;AACH,cAAM,iBAAkB,YAAW,qBAAqB;;gBAMpD,EAAE,oBAAoB,EAAE,EAAE,oBAAoB,EAC9C,OAAO,GAAE,uBAA4B;IAMvC,OAAO;;MAIN;IAEK,GAAG,CACP,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,gBAAqB,GAC7B,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAkCnB,OAAO,CAAC,CAAC,EACb,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,gBAAgB,GACzB,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IAYd,MAAM,CACV,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,gBAAgB,GACzB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAKzB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;CAuCnC;AAED,eAAe,iBAAiB,CAAA"}
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _AwsSecretsService_instances, _AwsSecretsService_client, _AwsSecretsService_defaultCacheTtl, _AwsSecretsService_cache, _AwsSecretsService_fromCache, _AwsSecretsService_toCache, _AwsSecretsService_fetchRaw;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const client_secrets_manager_1 = require("@aws-sdk/client-secrets-manager");
16
+ const utils_1 = require("@acmekit/framework/utils");
17
+ const DEFAULT_CACHE_TTL = 300; // seconds
18
+ /**
19
+ * AWS Secrets Manager provider for `ISecretsModuleService`.
20
+ *
21
+ * Supports two access patterns:
22
+ * - Bootstrap injection: fetched by `secretsBootstrapLoader` at startup, written to `process.env`
23
+ * - Runtime access: `get()`, `getJSON()`, `getKey()` — use `cache: false` for audit-trail-per-call
24
+ *
25
+ * Secret values are NEVER logged.
26
+ */
27
+ class AwsSecretsService {
28
+ constructor({ secretsManagerClient }, options = {}) {
29
+ _AwsSecretsService_instances.add(this);
30
+ _AwsSecretsService_client.set(this, void 0);
31
+ _AwsSecretsService_defaultCacheTtl.set(this, void 0);
32
+ _AwsSecretsService_cache.set(this, new Map());
33
+ this.__hooks = {
34
+ onApplicationShutdown: async () => {
35
+ __classPrivateFieldGet(this, _AwsSecretsService_cache, "f").clear();
36
+ },
37
+ };
38
+ __classPrivateFieldSet(this, _AwsSecretsService_client, secretsManagerClient, "f");
39
+ __classPrivateFieldSet(this, _AwsSecretsService_defaultCacheTtl, options.defaultCache ?? DEFAULT_CACHE_TTL, "f");
40
+ }
41
+ async get(secretId, options = {}) {
42
+ const { cache, validate, versionStage, versionId } = options;
43
+ if (cache !== false) {
44
+ const cached = __classPrivateFieldGet(this, _AwsSecretsService_instances, "m", _AwsSecretsService_fromCache).call(this, secretId);
45
+ if (cached !== null) {
46
+ return cached;
47
+ }
48
+ }
49
+ const value = await __classPrivateFieldGet(this, _AwsSecretsService_instances, "m", _AwsSecretsService_fetchRaw).call(this, secretId, { versionStage, versionId });
50
+ if (value === null) {
51
+ return null;
52
+ }
53
+ if (validate) {
54
+ const result = validate(value);
55
+ if (result !== true) {
56
+ const reason = typeof result === "string" ? result : "Validation failed";
57
+ throw new utils_1.AcmeKitError(utils_1.AcmeKitError.Types.INVALID_DATA, `Secret validation failed for "${secretId}": ${reason}`);
58
+ }
59
+ }
60
+ if (cache !== false) {
61
+ const ttl = typeof cache === "number" ? cache : __classPrivateFieldGet(this, _AwsSecretsService_defaultCacheTtl, "f");
62
+ __classPrivateFieldGet(this, _AwsSecretsService_instances, "m", _AwsSecretsService_toCache).call(this, secretId, value, ttl);
63
+ }
64
+ return value;
65
+ }
66
+ async getJSON(secretId, options) {
67
+ const raw = await this.get(secretId, options);
68
+ if (raw === null) {
69
+ return null;
70
+ }
71
+ try {
72
+ return JSON.parse(raw);
73
+ }
74
+ catch {
75
+ return null;
76
+ }
77
+ }
78
+ async getKey(secretId, key, options) {
79
+ const json = await this.getJSON(secretId, options);
80
+ return json?.[key] ?? null;
81
+ }
82
+ invalidate(secretId) {
83
+ __classPrivateFieldGet(this, _AwsSecretsService_cache, "f").delete(secretId);
84
+ }
85
+ }
86
+ _AwsSecretsService_client = new WeakMap(), _AwsSecretsService_defaultCacheTtl = new WeakMap(), _AwsSecretsService_cache = new WeakMap(), _AwsSecretsService_instances = new WeakSet(), _AwsSecretsService_fromCache = function _AwsSecretsService_fromCache(secretId) {
87
+ const entry = __classPrivateFieldGet(this, _AwsSecretsService_cache, "f").get(secretId);
88
+ if (!entry) {
89
+ return null;
90
+ }
91
+ if (entry.expiresAt !== Infinity && Date.now() >= entry.expiresAt) {
92
+ __classPrivateFieldGet(this, _AwsSecretsService_cache, "f").delete(secretId);
93
+ return null;
94
+ }
95
+ return entry.value;
96
+ }, _AwsSecretsService_toCache = function _AwsSecretsService_toCache(secretId, value, ttl) {
97
+ if (ttl === 0) {
98
+ return;
99
+ }
100
+ __classPrivateFieldGet(this, _AwsSecretsService_cache, "f").set(secretId, {
101
+ value,
102
+ expiresAt: ttl === Infinity ? Infinity : Date.now() + ttl * 1000,
103
+ });
104
+ }, _AwsSecretsService_fetchRaw = async function _AwsSecretsService_fetchRaw(secretId, opts) {
105
+ const response = await __classPrivateFieldGet(this, _AwsSecretsService_client, "f").send(new client_secrets_manager_1.GetSecretValueCommand({
106
+ SecretId: secretId,
107
+ VersionStage: opts.versionStage,
108
+ VersionId: opts.versionId,
109
+ }));
110
+ return response.SecretString ?? null;
111
+ };
112
+ exports.default = AwsSecretsService;
113
+ //# sourceMappingURL=aws-secrets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aws-secrets.js","sourceRoot":"","sources":["../../src/services/aws-secrets.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,4EAGwC;AAKxC,oDAAuD;AAYvD,MAAM,iBAAiB,GAAG,GAAG,CAAA,CAAC,UAAU;AAExC;;;;;;;;GAQG;AACH,MAAM,iBAAiB;IAKrB,YACE,EAAE,oBAAoB,EAAwB,EAC9C,UAAmC,EAAE;;QAN9B,4CAA6B;QAC7B,qDAAwB;QACxB,mCAAkC,IAAI,GAAG,EAAE,EAAA;QAUpD,YAAO,GAAG;YACR,qBAAqB,EAAE,KAAK,IAAI,EAAE;gBAChC,uBAAA,IAAI,gCAAO,CAAC,KAAK,EAAE,CAAA;YACrB,CAAC;SACF,CAAA;QARC,uBAAA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gB,EAAE,KAAa,EAAE,GAAW;IACnD,IAAI,GAAG,KAAK,CAAC,EAAE,CAAC;QACd,OAAM;IACR,CAAC;IACD,uBAAA,IAAI,gCAAO,CAAC,GAAG,CAAC,QAAQ,EAAE;QACxB,KAAK;QACL,SAAS,EAAE,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI;KACjE,CAAC,CAAA;AACJ,CAAC,gCAED,KAAK,sCACH,QAAgB,EAChB,IAAmD;IAEnD,MAAM,QAAQ,GAAG,MAAM,uBAAA,IAAI,iCAAQ,CAAC,IAAI,CACtC,IAAI,8CAAqB,CAAC;QACxB,QAAQ,EAAE,QAAQ;QAClB,YAAY,EAAE,IAAI,CAAC,YAAY;QAC/B,SAAS,EAAE,IAAI,CAAC,SAAS;KAC1B,CAAC,CACH,CAAA;IACD,OAAO,QAAQ,CAAC,YAAY,IAAI,IAAI,CAAA;AACtC,CAAC;AAGH,kBAAe,iBAAiB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export { default as AwsSecretsService } from "./aws-secrets";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,eAAe,CAAA"}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.AwsSecretsService = void 0;
7
+ var aws_secrets_1 = require("./aws-secrets");
8
+ Object.defineProperty(exports, "AwsSecretsService", { enumerable: true, get: function () { return __importDefault(aws_secrets_1).default; } });
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":";;;;;;AAAA,6CAA4D;AAAnD,iIAAA,OAAO,OAAqB"}
@@ -0,0 +1 @@
1
+ {"root":["../src/index.ts","../src/initialize/index.ts","../src/loaders/index.ts","../src/services/aws-secrets.ts","../src/services/index.ts","../src/services/__tests__/aws-secrets.spec.ts","../src/types/index.ts"],"version":"5.9.3"}
@@ -0,0 +1,49 @@
1
+ import { SecretInjectConfig } from "@acmekit/framework/types";
2
+ export type AwsSecretsModuleOptions = {
3
+ /**
4
+ * AWS region for Secrets Manager (e.g. "us-east-1").
5
+ * Falls back to AWS SDK default credential chain if omitted.
6
+ */
7
+ region?: string;
8
+ /**
9
+ * Custom endpoint URL. Use for VPC interface endpoints (no public internet required).
10
+ * @example "https://vpce-xxx.secretsmanager.us-east-1.vpce.amazonaws.com"
11
+ */
12
+ endpoint?: string;
13
+ /**
14
+ * IAM Role ARN to assume before accessing Secrets Manager.
15
+ * Enables per-service isolation: each service uses its own narrowly-scoped role.
16
+ * @example "arn:aws:iam::123456789012:role/SweepServiceSecretsRole"
17
+ */
18
+ roleArn?: string;
19
+ /**
20
+ * Verify access to all `inject` secrets at startup using DescribeSecret.
21
+ * Fails fast if IAM permissions or network connectivity are misconfigured.
22
+ * @default true
23
+ */
24
+ verifyOnStartup?: boolean;
25
+ /**
26
+ * Default TTL (seconds) for runtime secret caching.
27
+ * Individual calls can override via `SecretGetOptions.cache`.
28
+ * @default 300
29
+ */
30
+ defaultCache?: number;
31
+ /**
32
+ * When `true`, log a warning and continue if a secret cannot be fetched.
33
+ * When `false`, throw an error and halt startup.
34
+ * @default true
35
+ */
36
+ fallback?: boolean;
37
+ /**
38
+ * Secrets to fetch at startup and inject into `process.env`.
39
+ * Processed by `secretsBootstrapLoader` before other modules initialize.
40
+ */
41
+ inject?: SecretInjectConfig[];
42
+ };
43
+ declare module "@acmekit/types" {
44
+ interface ModuleOptions {
45
+ "@acmekit/secrets-aws": AwsSecretsModuleOptions;
46
+ "@acmekit/acmekit/secrets-aws": AwsSecretsModuleOptions;
47
+ }
48
+ }
49
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAE7D,MAAM,MAAM,uBAAuB,GAAG;IACpC;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IAEf;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IAEjB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB;;;;OAIG;IACH,eAAe,CAAC,EAAE,OAAO,CAAA;IAEzB;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IAErB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAElB;;;OAGG;IACH,MAAM,CAAC,EAAE,kBAAkB,EAAE,CAAA;CAC9B,CAAA;AAED,OAAO,QAAQ,gBAAgB,CAAC;IAC9B,UAAU,aAAa;QACrB,sBAAsB,EAAE,uBAAuB,CAAA;QAC/C,8BAA8B,EAAE,uBAAuB,CAAA;KACxD;CACF"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@acmekit/secrets-aws",
3
+ "version": "2.13.53",
4
+ "description": "AWS Secrets Manager provider for AcmeKit — production secrets management",
5
+ "main": "dist/index.js",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/acmekit/acmekit",
9
+ "directory": "packages/modules/secrets-aws"
10
+ },
11
+ "engines": {
12
+ "node": ">=20"
13
+ },
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "!dist/**/__tests__",
20
+ "!dist/**/__mocks__",
21
+ "!dist/**/__fixtures__"
22
+ ],
23
+ "author": "AcmeKit",
24
+ "license": "MIT",
25
+ "scripts": {
26
+ "watch": "yarn run -T tsc --build --watch",
27
+ "build": "yarn run -T rimraf dist && yarn run -T tsc --build",
28
+ "test": "../../../node_modules/.bin/jest --passWithNoTests"
29
+ },
30
+ "dependencies": {
31
+ "@aws-sdk/client-secrets-manager": "^3.0.0",
32
+ "@aws-sdk/credential-providers": "^3.0.0"
33
+ },
34
+ "devDependencies": {
35
+ "@acmekit/framework": "2.13.53"
36
+ },
37
+ "peerDependencies": {
38
+ "@acmekit/framework": "2.13.53"
39
+ }
40
+ }