@squiz/dx-common-lib 1.71.1 → 1.72.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 (32) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/lib/cache/applyDefaultRulesToCacheControlObject.d.ts +1 -1
  3. package/lib/index.d.ts +3 -0
  4. package/lib/index.js +3 -0
  5. package/lib/index.js.map +1 -1
  6. package/lib/secret-api-key-service/DevSecretApiKeyService.d.ts +25 -0
  7. package/lib/secret-api-key-service/DevSecretApiKeyService.js +35 -0
  8. package/lib/secret-api-key-service/DevSecretApiKeyService.js.map +1 -0
  9. package/lib/secret-api-key-service/DevSecretApiKeyService.spec.d.ts +1 -0
  10. package/lib/secret-api-key-service/DevSecretApiKeyService.spec.js +157 -0
  11. package/lib/secret-api-key-service/DevSecretApiKeyService.spec.js.map +1 -0
  12. package/lib/secret-api-key-service/SecretApiKeyService.d.ts +43 -0
  13. package/lib/secret-api-key-service/SecretApiKeyService.js +85 -0
  14. package/lib/secret-api-key-service/SecretApiKeyService.js.map +1 -0
  15. package/lib/secret-api-key-service/SecretApiKeyService.spec.d.ts +1 -0
  16. package/lib/secret-api-key-service/SecretApiKeyService.spec.js +280 -0
  17. package/lib/secret-api-key-service/SecretApiKeyService.spec.js.map +1 -0
  18. package/lib/secret-api-key-service/getSecretApiKeyService.d.ts +20 -0
  19. package/lib/secret-api-key-service/getSecretApiKeyService.js +41 -0
  20. package/lib/secret-api-key-service/getSecretApiKeyService.js.map +1 -0
  21. package/lib/secret-api-key-service/getSecretApiKeyService.spec.d.ts +1 -0
  22. package/lib/secret-api-key-service/getSecretApiKeyService.spec.js +313 -0
  23. package/lib/secret-api-key-service/getSecretApiKeyService.spec.js.map +1 -0
  24. package/package.json +4 -4
  25. package/src/index.ts +3 -0
  26. package/src/secret-api-key-service/DevSecretApiKeyService.spec.ts +211 -0
  27. package/src/secret-api-key-service/DevSecretApiKeyService.ts +36 -0
  28. package/src/secret-api-key-service/SecretApiKeyService.spec.ts +367 -0
  29. package/src/secret-api-key-service/SecretApiKeyService.ts +108 -0
  30. package/src/secret-api-key-service/getSecretApiKeyService.spec.ts +405 -0
  31. package/src/secret-api-key-service/getSecretApiKeyService.ts +45 -0
  32. package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Change Log
2
2
 
3
+ ## 1.72.1
4
+
5
+ ### Patch Changes
6
+
7
+ - fabc58b: Added EnvApiKeyService fallback
8
+
9
+ ## 1.72.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 480cbf0: Added SecretApiKeyService
14
+
3
15
  ## 1.71.1
4
16
 
5
17
  ### Patch Changes
@@ -1,6 +1,6 @@
1
1
  import { CacheControl } from './parseCacheControl';
2
2
  export declare function applyDefaultRulesToCacheControlObject(cacheControlInput: CacheControl): {
3
- [x: string]: string | number | boolean | undefined;
3
+ [key: string]: string | number | boolean | undefined;
4
4
  'max-age'?: number;
5
5
  's-maxage'?: number;
6
6
  'min-fresh'?: number;
package/lib/index.d.ts CHANGED
@@ -15,3 +15,6 @@ export * from './edge-components-secret-key-service/ProductionEdgeComponentsSecr
15
15
  export * from './edge-components-secret-key-service/EdgeComponentsSecretKeyService';
16
16
  export * from './edge-components-secret-key-service/getEdgeComponentsSecretService';
17
17
  export * from './esi-mac-token-generator/EsiMacTokenGenerator';
18
+ export * from './secret-api-key-service/SecretApiKeyService';
19
+ export * from './secret-api-key-service/DevSecretApiKeyService';
20
+ export * from './secret-api-key-service/getSecretApiKeyService';
package/lib/index.js CHANGED
@@ -31,4 +31,7 @@ __exportStar(require("./edge-components-secret-key-service/ProductionEdgeCompone
31
31
  __exportStar(require("./edge-components-secret-key-service/EdgeComponentsSecretKeyService"), exports);
32
32
  __exportStar(require("./edge-components-secret-key-service/getEdgeComponentsSecretService"), exports);
33
33
  __exportStar(require("./esi-mac-token-generator/EsiMacTokenGenerator"), exports);
34
+ __exportStar(require("./secret-api-key-service/SecretApiKeyService"), exports);
35
+ __exportStar(require("./secret-api-key-service/DevSecretApiKeyService"), exports);
36
+ __exportStar(require("./secret-api-key-service/getSecretApiKeyService"), exports);
34
37
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,0CAAwB;AACxB,yCAAuB;AACvB,qDAAmC;AACnC,iEAA+C;AAC/C,+DAA6C;AAC7C,+EAA6D;AAC7D,+EAA6D;AAC7D,gFAA8D;AAC9D,wEAAsD;AACtD,0CAAwB;AACxB,+CAA6B;AAC7B,iHAA+F;AAC/F,gHAA8F;AAC9F,sGAAoF;AACpF,sGAAoF;AACpF,iFAA+D"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,0CAAwB;AACxB,yCAAuB;AACvB,qDAAmC;AACnC,iEAA+C;AAC/C,+DAA6C;AAC7C,+EAA6D;AAC7D,+EAA6D;AAC7D,gFAA8D;AAC9D,wEAAsD;AACtD,0CAAwB;AACxB,+CAA6B;AAC7B,iHAA+F;AAC/F,gHAA8F;AAC9F,sGAAoF;AACpF,sGAAoF;AACpF,iFAA+D;AAC/D,+EAA6D;AAC7D,kFAAgE;AAChE,kFAAgE"}
@@ -0,0 +1,25 @@
1
+ /*!
2
+ * @file EnvApiKeyService.ts
3
+ * @description Retrieves API key from environment variable (for local development).
4
+ * @author Squiz
5
+ * @copyright 2025 Squiz
6
+ * @license MIT
7
+ */
8
+ import { SecretApiKeyServiceInterface } from './SecretApiKeyService';
9
+ /**
10
+ * Service for retrieving API keys from environment variables.
11
+ * Used for local development as an alternative to AWS Secrets Manager.
12
+ */
13
+ export declare class DevSecretApiKeyService implements SecretApiKeyServiceInterface {
14
+ private readonly apiKey;
15
+ /**
16
+ * Constructor for EnvApiKeyService
17
+ * @param apiKey The API key value from environment variable
18
+ */
19
+ constructor(apiKey: string);
20
+ /**
21
+ * Returns the API key.
22
+ * @returns The API key string
23
+ */
24
+ getApiKey(): Promise<string>;
25
+ }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ /*!
3
+ * @file EnvApiKeyService.ts
4
+ * @description Retrieves API key from environment variable (for local development).
5
+ * @author Squiz
6
+ * @copyright 2025 Squiz
7
+ * @license MIT
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.DevSecretApiKeyService = void 0;
11
+ /**
12
+ * Service for retrieving API keys from environment variables.
13
+ * Used for local development as an alternative to AWS Secrets Manager.
14
+ */
15
+ class DevSecretApiKeyService {
16
+ /**
17
+ * Constructor for EnvApiKeyService
18
+ * @param apiKey The API key value from environment variable
19
+ */
20
+ constructor(apiKey) {
21
+ if (!apiKey || apiKey.trim().length === 0) {
22
+ throw new Error('API key must be a non-empty string');
23
+ }
24
+ this.apiKey = apiKey;
25
+ }
26
+ /**
27
+ * Returns the API key.
28
+ * @returns The API key string
29
+ */
30
+ async getApiKey() {
31
+ return this.apiKey;
32
+ }
33
+ }
34
+ exports.DevSecretApiKeyService = DevSecretApiKeyService;
35
+ //# sourceMappingURL=DevSecretApiKeyService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DevSecretApiKeyService.js","sourceRoot":"","sources":["../../src/secret-api-key-service/DevSecretApiKeyService.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAIH;;;GAGG;AACH,MAAa,sBAAsB;IAGjC;;;OAGG;IACH,YAAY,MAAc;QACxB,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC1C,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;QACxD,CAAC;QACD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,SAAS;QACpB,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF;AArBD,wDAqBC"}
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const DevSecretApiKeyService_1 = require("./DevSecretApiKeyService");
4
+ describe('DevSecretApiKeyService', () => {
5
+ describe('Constructor', () => {
6
+ it('should successfully create service with valid API key', () => {
7
+ const apiKey = 'test-api-key-12345';
8
+ const service = new DevSecretApiKeyService_1.DevSecretApiKeyService(apiKey);
9
+ expect(service).toBeInstanceOf(DevSecretApiKeyService_1.DevSecretApiKeyService);
10
+ });
11
+ it('should throw error when API key is empty string', () => {
12
+ expect(() => new DevSecretApiKeyService_1.DevSecretApiKeyService('')).toThrow('API key must be a non-empty string');
13
+ });
14
+ it('should throw error when API key is whitespace only', () => {
15
+ expect(() => new DevSecretApiKeyService_1.DevSecretApiKeyService(' ')).toThrow('API key must be a non-empty string');
16
+ });
17
+ it('should throw error when API key is only tabs', () => {
18
+ expect(() => new DevSecretApiKeyService_1.DevSecretApiKeyService('\t\t')).toThrow('API key must be a non-empty string');
19
+ });
20
+ it('should throw error when API key is only newlines', () => {
21
+ expect(() => new DevSecretApiKeyService_1.DevSecretApiKeyService('\n\n')).toThrow('API key must be a non-empty string');
22
+ });
23
+ it('should accept API key with surrounding whitespace', () => {
24
+ // Note: The constructor checks trimmed length, but stores the original value
25
+ const apiKey = ' valid-key ';
26
+ expect(() => new DevSecretApiKeyService_1.DevSecretApiKeyService(apiKey)).not.toThrow();
27
+ });
28
+ });
29
+ describe('getApiKey', () => {
30
+ it('should return the API key provided in constructor', async () => {
31
+ const apiKey = 'test-api-key-xyz';
32
+ const service = new DevSecretApiKeyService_1.DevSecretApiKeyService(apiKey);
33
+ const result = await service.getApiKey();
34
+ expect(result).toBe(apiKey);
35
+ });
36
+ it('should return same API key on multiple calls', async () => {
37
+ const apiKey = 'consistent-api-key';
38
+ const service = new DevSecretApiKeyService_1.DevSecretApiKeyService(apiKey);
39
+ const result1 = await service.getApiKey();
40
+ const result2 = await service.getApiKey();
41
+ const result3 = await service.getApiKey();
42
+ expect(result1).toBe(apiKey);
43
+ expect(result2).toBe(apiKey);
44
+ expect(result3).toBe(apiKey);
45
+ });
46
+ it('should handle concurrent calls efficiently', async () => {
47
+ const apiKey = 'concurrent-test-key';
48
+ const service = new DevSecretApiKeyService_1.DevSecretApiKeyService(apiKey);
49
+ // Make multiple concurrent calls
50
+ const promises = Array(10)
51
+ .fill(null)
52
+ .map(() => service.getApiKey());
53
+ const results = await Promise.all(promises);
54
+ // All should return the same key
55
+ expect(results).toEqual(Array(10).fill(apiKey));
56
+ });
57
+ });
58
+ describe('Edge Cases', () => {
59
+ it('should handle very long API keys', async () => {
60
+ const apiKey = 'x'.repeat(1000); // 1000 character API key
61
+ const service = new DevSecretApiKeyService_1.DevSecretApiKeyService(apiKey);
62
+ const result = await service.getApiKey();
63
+ expect(result).toBe(apiKey);
64
+ });
65
+ it('should handle special characters in API key', async () => {
66
+ const apiKey = 'test-key-!@#$%^&*()_+-=[]{}|;:"<>,.?/~`';
67
+ const service = new DevSecretApiKeyService_1.DevSecretApiKeyService(apiKey);
68
+ const result = await service.getApiKey();
69
+ expect(result).toBe(apiKey);
70
+ });
71
+ it('should handle unicode characters in API key', async () => {
72
+ const apiKey = 'test-key-你好-مرحبا-🔑';
73
+ const service = new DevSecretApiKeyService_1.DevSecretApiKeyService(apiKey);
74
+ const result = await service.getApiKey();
75
+ expect(result).toBe(apiKey);
76
+ });
77
+ it('should handle API key with line breaks', async () => {
78
+ const apiKey = 'key-with\nline\nbreaks';
79
+ const service = new DevSecretApiKeyService_1.DevSecretApiKeyService(apiKey);
80
+ const result = await service.getApiKey();
81
+ expect(result).toBe(apiKey);
82
+ });
83
+ it('should handle base64-like API keys', async () => {
84
+ const apiKey = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c';
85
+ const service = new DevSecretApiKeyService_1.DevSecretApiKeyService(apiKey);
86
+ const result = await service.getApiKey();
87
+ expect(result).toBe(apiKey);
88
+ });
89
+ it('should handle UUID-format API keys', async () => {
90
+ const apiKey = '550e8400-e29b-41d4-a716-446655440000';
91
+ const service = new DevSecretApiKeyService_1.DevSecretApiKeyService(apiKey);
92
+ const result = await service.getApiKey();
93
+ expect(result).toBe(apiKey);
94
+ });
95
+ it('should handle hexadecimal API keys', async () => {
96
+ const apiKey = 'a1b2c3d4e5f6789012345678901234567890abcdef';
97
+ const service = new DevSecretApiKeyService_1.DevSecretApiKeyService(apiKey);
98
+ const result = await service.getApiKey();
99
+ expect(result).toBe(apiKey);
100
+ });
101
+ });
102
+ describe('Interface Compliance', () => {
103
+ it('should implement SecretApiKeyServiceInterface', async () => {
104
+ const service = new DevSecretApiKeyService_1.DevSecretApiKeyService('test-key');
105
+ // Check that the required methods exist
106
+ expect(typeof service.getApiKey).toBe('function');
107
+ });
108
+ it('should return a Promise from getApiKey', () => {
109
+ const service = new DevSecretApiKeyService_1.DevSecretApiKeyService('test-key');
110
+ const result = service.getApiKey();
111
+ expect(result).toBeInstanceOf(Promise);
112
+ });
113
+ });
114
+ describe('Memory and Performance', () => {
115
+ it('should not modify the API key after construction', async () => {
116
+ const originalKey = 'immutable-key-123';
117
+ const service = new DevSecretApiKeyService_1.DevSecretApiKeyService(originalKey);
118
+ // Get the key multiple times
119
+ await service.getApiKey();
120
+ await service.getApiKey();
121
+ await service.getApiKey();
122
+ // Key should still be the same
123
+ const result = await service.getApiKey();
124
+ expect(result).toBe(originalKey);
125
+ });
126
+ it('should handle rapid sequential calls', async () => {
127
+ const apiKey = 'rapid-call-key';
128
+ const service = new DevSecretApiKeyService_1.DevSecretApiKeyService(apiKey);
129
+ // Make rapid sequential calls
130
+ for (let i = 0; i < 100; i++) {
131
+ const result = await service.getApiKey();
132
+ expect(result).toBe(apiKey);
133
+ }
134
+ });
135
+ });
136
+ describe('Real-world Scenarios', () => {
137
+ it('should work with typical metrics service API key format', async () => {
138
+ const apiKey = 'metrics-api-key-prod-abc123def456';
139
+ const service = new DevSecretApiKeyService_1.DevSecretApiKeyService(apiKey);
140
+ const result = await service.getApiKey();
141
+ expect(result).toBe(apiKey);
142
+ });
143
+ it('should work with AWS-style secret format', async () => {
144
+ const apiKey = 'aws-secret-key-AKIAIOSFODNN7EXAMPLE';
145
+ const service = new DevSecretApiKeyService_1.DevSecretApiKeyService(apiKey);
146
+ const result = await service.getApiKey();
147
+ expect(result).toBe(apiKey);
148
+ });
149
+ it('should work with Bearer token format', async () => {
150
+ const apiKey = 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9';
151
+ const service = new DevSecretApiKeyService_1.DevSecretApiKeyService(apiKey);
152
+ const result = await service.getApiKey();
153
+ expect(result).toBe(apiKey);
154
+ });
155
+ });
156
+ });
157
+ //# sourceMappingURL=DevSecretApiKeyService.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DevSecretApiKeyService.spec.js","sourceRoot":"","sources":["../../src/secret-api-key-service/DevSecretApiKeyService.spec.ts"],"names":[],"mappings":";;AAAA,qEAAkE;AAElE,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;IACtC,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;QAC3B,EAAE,CAAC,uDAAuD,EAAE,GAAG,EAAE;YAC/D,MAAM,MAAM,GAAG,oBAAoB,CAAC;YACpC,MAAM,OAAO,GAAG,IAAI,+CAAsB,CAAC,MAAM,CAAC,CAAC;YAEnD,MAAM,CAAC,OAAO,CAAC,CAAC,cAAc,CAAC,+CAAsB,CAAC,CAAC;QACzD,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,iDAAiD,EAAE,GAAG,EAAE;YACzD,MAAM,CAAC,GAAG,EAAE,CAAC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IAEH,QAAQ,CAAC,sBAAsB,EAAE,GAAG,EAAE;QACpC,EAAE,CAAC,yDAAyD,EAAE,KAAK,IAAI,EAAE;YACvE,MAAM,MAAM,GAAG,mCAAmC,CAAC;YACnD,MAAM,OAAO,GAAG,IAAI,+CAAsB,CAAC,MAAM,CAAC,CAAC;YAEnD,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,SAAS,EAAE,CAAC;YAEzC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC9B,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,0CAA0C,EAAE,KAAK,IAAI,EAAE;YACxD,MAAM,MAAM,GAAG,qCAAqC,CAAC;YACrD,MAAM,OAAO,GAAG,IAAI,+CAAsB,CAAC,MAAM,CAAC,CAAC;YAEnD,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,SAAS,EAAE,CAAC;YAEzC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC9B,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,sCAAsC,EAAE,KAAK,IAAI,EAAE;YACpD,MAAM,MAAM,GAAG,6CAA6C,CAAC;YAC7D,MAAM,OAAO,GAAG,IAAI,+CAAsB,CAAC,MAAM,CAAC,CAAC;YAEnD,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,SAAS,EAAE,CAAC;YAEzC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC9B,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,43 @@
1
+ /*!
2
+ * @file SecretApiKeyService.ts
3
+ * @description Retrieves API keys from AWS Secrets Manager.
4
+ * @author Squiz
5
+ * @copyright 2025 Squiz
6
+ * @license MIT
7
+ */
8
+ /**
9
+ * Interface for the SecretApiKeyService
10
+ */
11
+ export interface SecretApiKeyServiceInterface {
12
+ /**
13
+ * Retrieves the API key from AWS Secrets Manager.
14
+ * Expects the secret to be stored as JSON with an 'apikey' field.
15
+ *
16
+ * @returns The API key string
17
+ */
18
+ getApiKey(): Promise<string>;
19
+ }
20
+ /**
21
+ * Service for retrieving API keys from AWS Secrets Manager.
22
+ * Expects the secret to be stored as JSON with an 'apikey' field.
23
+ *
24
+ * @see https://squizgroup.atlassian.net/wiki/spaces/PRODUCT/pages/3029827767/Service+Keys
25
+ */
26
+ export declare class SecretApiKeyService implements SecretApiKeyServiceInterface {
27
+ private readonly secretName;
28
+ private readonly region;
29
+ private cachedApiKey;
30
+ /**
31
+ * Constructor for SecretApiKeyService
32
+ * @param secretName The name/ARN of the secret in AWS Secrets Manager
33
+ * @param region AWS region
34
+ */
35
+ constructor(secretName: string, region: string);
36
+ /**
37
+ * Retrieves the API key from AWS Secrets Manager.
38
+ * Expects the secret to be stored as JSON with an 'apikey' field.
39
+ *
40
+ * @returns The API key string
41
+ */
42
+ getApiKey(): Promise<string>;
43
+ }
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ /*!
3
+ * @file SecretApiKeyService.ts
4
+ * @description Retrieves API keys from AWS Secrets Manager.
5
+ * @author Squiz
6
+ * @copyright 2025 Squiz
7
+ * @license MIT
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.SecretApiKeyService = void 0;
11
+ // External
12
+ const client_secrets_manager_1 = require("@aws-sdk/client-secrets-manager");
13
+ /**
14
+ * Service for retrieving API keys from AWS Secrets Manager.
15
+ * Expects the secret to be stored as JSON with an 'apikey' field.
16
+ *
17
+ * @see https://squizgroup.atlassian.net/wiki/spaces/PRODUCT/pages/3029827767/Service+Keys
18
+ */
19
+ class SecretApiKeyService {
20
+ /**
21
+ * Constructor for SecretApiKeyService
22
+ * @param secretName The name/ARN of the secret in AWS Secrets Manager
23
+ * @param region AWS region
24
+ */
25
+ constructor(secretName, region) {
26
+ this.secretName = secretName;
27
+ this.region = region;
28
+ this.cachedApiKey = undefined;
29
+ }
30
+ /**
31
+ * Retrieves the API key from AWS Secrets Manager.
32
+ * Expects the secret to be stored as JSON with an 'apikey' field.
33
+ *
34
+ * @returns The API key string
35
+ */
36
+ async getApiKey() {
37
+ // Return cached value if available
38
+ if (this.cachedApiKey) {
39
+ return this.cachedApiKey;
40
+ }
41
+ const secretClient = new client_secrets_manager_1.SecretsManagerClient({ region: this.region });
42
+ try {
43
+ // Retrieve the secret from AWS Secrets Manager
44
+ const command = new client_secrets_manager_1.GetSecretValueCommand({ SecretId: this.secretName });
45
+ const response = await secretClient.send(command);
46
+ // Check if the secret has a SecretString value
47
+ if (!response.SecretString) {
48
+ throw new Error(`Secret ${this.secretName} has no SecretString value`);
49
+ }
50
+ // Parse the secret JSON to extract the apikey field
51
+ let parsedSecret;
52
+ try {
53
+ parsedSecret = JSON.parse(response.SecretString);
54
+ }
55
+ catch (parseError) {
56
+ throw new Error(`Failed to parse secret as JSON. Secret value may not be valid JSON.`);
57
+ }
58
+ // Extract the apikey field from the parsed secret
59
+ const { apikey } = parsedSecret;
60
+ // Check if the apikey field is present
61
+ if (!apikey) {
62
+ const availableKeys = Object.keys(parsedSecret).join(', ');
63
+ throw new Error(`API key not found in secret JSON structure (expected "apikey" field). Available keys: ${availableKeys}`);
64
+ }
65
+ // Check if the apikey field is a non-empty string
66
+ if (typeof apikey !== 'string' || apikey.trim().length === 0) {
67
+ throw new Error('API key value is invalid (must be a non-empty string)');
68
+ }
69
+ // Cache the apikey
70
+ this.cachedApiKey = apikey;
71
+ // Return the apikey
72
+ return apikey;
73
+ }
74
+ catch (error) {
75
+ // Log the error
76
+ const errorMessage = `Failed to retrieve API key: ${error instanceof Error ? error.message : 'Unknown error'}`;
77
+ const wrappedError = new Error(errorMessage);
78
+ // @ts-expect-error - cause property is not standard in all TypeScript versions
79
+ wrappedError.cause = error;
80
+ throw wrappedError;
81
+ }
82
+ }
83
+ }
84
+ exports.SecretApiKeyService = SecretApiKeyService;
85
+ //# sourceMappingURL=SecretApiKeyService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SecretApiKeyService.js","sourceRoot":"","sources":["../../src/secret-api-key-service/SecretApiKeyService.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,WAAW;AACX,4EAA8F;AAe9F;;;;;GAKG;AACH,MAAa,mBAAmB;IAK9B;;;;OAIG;IACH,YAAY,UAAkB,EAAE,MAAc;QAC5C,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,YAAY,GAAG,SAAS,CAAC;IAChC,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,SAAS;QACpB,mCAAmC;QACnC,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACtB,OAAO,IAAI,CAAC,YAAY,CAAC;QAC3B,CAAC;QAED,MAAM,YAAY,GAAG,IAAI,6CAAoB,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;QAEvE,IAAI,CAAC;YACH,+CAA+C;YAC/C,MAAM,OAAO,GAAG,IAAI,8CAAqB,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;YACzE,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAElD,+CAA+C;YAC/C,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE,CAAC;gBAC3B,MAAM,IAAI,KAAK,CAAC,UAAU,IAAI,CAAC,UAAU,4BAA4B,CAAC,CAAC;YACzE,CAAC;YAED,oDAAoD;YACpD,IAAI,YAAY,CAAC;YACjB,IAAI,CAAC;gBACH,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;YACnD,CAAC;YAAC,OAAO,UAAU,EAAE,CAAC;gBACpB,MAAM,IAAI,KAAK,CAAC,qEAAqE,CAAC,CAAC;YACzF,CAAC;YAED,k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