@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
@@ -0,0 +1,280 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const client_secrets_manager_1 = require("@aws-sdk/client-secrets-manager");
4
+ const SecretApiKeyService_1 = require("./SecretApiKeyService");
5
+ // Mock the AWS SDK
6
+ jest.mock('@aws-sdk/client-secrets-manager');
7
+ describe('SecretApiKeyService', () => {
8
+ let service;
9
+ let mockSend;
10
+ const mockSecretsManagerClient = client_secrets_manager_1.SecretsManagerClient;
11
+ let consoleLogSpy;
12
+ let consoleErrorSpy;
13
+ const mockSecretName = 'test-secret';
14
+ const mockRegion = 'us-east-1';
15
+ beforeEach(() => {
16
+ // Create a fresh service instance for each test
17
+ service = new SecretApiKeyService_1.SecretApiKeyService(mockSecretName, mockRegion);
18
+ // Create a fresh mock for each test
19
+ mockSend = jest.fn();
20
+ // Setup console spies
21
+ consoleLogSpy = jest.spyOn(console, 'log').mockImplementation();
22
+ consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation();
23
+ // Clear and setup the mock client - make sure it always returns our mockSend
24
+ mockSecretsManagerClient.mockReset();
25
+ mockSecretsManagerClient.mockImplementation(() => ({
26
+ send: mockSend,
27
+ destroy: jest.fn(),
28
+ config: {},
29
+ }));
30
+ });
31
+ afterEach(() => {
32
+ // Restore console spies
33
+ consoleLogSpy.mockRestore();
34
+ consoleErrorSpy.mockRestore();
35
+ jest.clearAllMocks();
36
+ });
37
+ describe('AWS Secrets Manager Retrieval', () => {
38
+ it('should successfully retrieve API key from Secrets Manager', async () => {
39
+ const mockApiKey = 'test-api-key-from-secrets';
40
+ const testSecretName = '/servicekeys-dev-au/feaas-metrics';
41
+ const testRegion = 'ap-southeast-2';
42
+ // Create service with specific secret name and region for this test
43
+ const testService = new SecretApiKeyService_1.SecretApiKeyService(testSecretName, testRegion);
44
+ mockSend.mockResolvedValueOnce({
45
+ SecretString: JSON.stringify({ apikey: mockApiKey }),
46
+ });
47
+ const result = await testService.getApiKey();
48
+ expect(result).toBe(mockApiKey);
49
+ expect(mockSecretsManagerClient).toHaveBeenCalledWith({ region: testRegion });
50
+ expect(mockSend).toHaveBeenCalledWith(expect.any(client_secrets_manager_1.GetSecretValueCommand));
51
+ });
52
+ it('should handle complex JSON structure with apikey field', async () => {
53
+ const mockApiKey = 'complex-api-key';
54
+ mockSend.mockResolvedValueOnce({
55
+ SecretString: JSON.stringify({
56
+ apikey: mockApiKey,
57
+ otherField: 'other-value',
58
+ metadata: { created: '2024-01-01' },
59
+ }),
60
+ });
61
+ const result = await service.getApiKey();
62
+ expect(result).toBe(mockApiKey);
63
+ });
64
+ it('should handle SecretString with nested apikey value', async () => {
65
+ const mockApiKey = 'nested-api-key';
66
+ mockSend.mockResolvedValueOnce({
67
+ SecretString: JSON.stringify({
68
+ apikey: mockApiKey,
69
+ // Test that we extract the right field even with similar names
70
+ apikeys: ['wrong-key'],
71
+ api_key: 'also-wrong',
72
+ }),
73
+ });
74
+ const result = await service.getApiKey();
75
+ expect(result).toBe(mockApiKey);
76
+ });
77
+ });
78
+ describe('Caching Behavior', () => {
79
+ it('should cache API key after first successful retrieval', async () => {
80
+ const mockApiKey = 'cached-api-key';
81
+ mockSend.mockResolvedValueOnce({
82
+ SecretString: JSON.stringify({ apikey: mockApiKey }),
83
+ });
84
+ // First call - should hit Secrets Manager
85
+ const result1 = await service.getApiKey();
86
+ expect(result1).toBe(mockApiKey);
87
+ expect(mockSend).toHaveBeenCalledTimes(1);
88
+ // Second call - should use cache
89
+ const result2 = await service.getApiKey();
90
+ expect(result2).toBe(mockApiKey);
91
+ expect(mockSend).toHaveBeenCalledTimes(1); // Still only 1 call
92
+ });
93
+ });
94
+ describe('Error Handling', () => {
95
+ it('should throw error when SecretString is missing', async () => {
96
+ const mockSecretName = 'test-secret';
97
+ mockSend.mockResolvedValueOnce({
98
+ // No SecretString property
99
+ SecretBinary: 'binary-data',
100
+ });
101
+ await expect(service.getApiKey()).rejects.toThrow(`Secret ${mockSecretName} has no SecretString value`);
102
+ });
103
+ it('should throw error when SecretString is not valid JSON', async () => {
104
+ mockSend.mockResolvedValueOnce({
105
+ SecretString: 'not-valid-json{',
106
+ });
107
+ await expect(service.getApiKey()).rejects.toThrow('Failed to parse secret as JSON. Secret value may not be valid JSON.');
108
+ });
109
+ it('should throw error when apikey field is missing', async () => {
110
+ mockSend.mockResolvedValueOnce({
111
+ SecretString: JSON.stringify({
112
+ wrongField: 'value',
113
+ anotherField: 'another-value',
114
+ }),
115
+ });
116
+ await expect(service.getApiKey()).rejects.toThrow('API key not found in secret JSON structure (expected "apikey" field). Available keys: wrongField, anotherField');
117
+ });
118
+ it('should throw error when apikey is null', async () => {
119
+ mockSend.mockResolvedValueOnce({
120
+ SecretString: JSON.stringify({ apikey: null }),
121
+ });
122
+ await expect(service.getApiKey()).rejects.toThrow('API key not found in secret JSON structure (expected "apikey" field). Available keys: apikey');
123
+ });
124
+ it('should throw error when apikey is empty string', async () => {
125
+ mockSend.mockResolvedValueOnce({
126
+ SecretString: JSON.stringify({ apikey: '' }),
127
+ });
128
+ await expect(service.getApiKey()).rejects.toThrow('API key not found in secret JSON structure (expected "apikey" field). Available keys: apikey');
129
+ });
130
+ it('should throw error when apikey is whitespace only', async () => {
131
+ mockSend.mockResolvedValueOnce({
132
+ SecretString: JSON.stringify({ apikey: ' ' }),
133
+ });
134
+ await expect(service.getApiKey()).rejects.toThrow('API key value is invalid (must be a non-empty string)');
135
+ });
136
+ it('should throw error when apikey is not a string', async () => {
137
+ mockSend.mockResolvedValueOnce({
138
+ SecretString: JSON.stringify({ apikey: 12345 }),
139
+ });
140
+ await expect(service.getApiKey()).rejects.toThrow('API key value is invalid (must be a non-empty string)');
141
+ });
142
+ it('should handle AWS SDK errors gracefully', async () => {
143
+ const awsError = new Error('AccessDeniedException: User is not authorized');
144
+ mockSend.mockRejectedValueOnce(awsError);
145
+ await expect(service.getApiKey()).rejects.toThrow('Failed to retrieve API key: AccessDeniedException: User is not authorized');
146
+ });
147
+ it('should throw wrapped error with details', async () => {
148
+ const awsError = new Error('Network error');
149
+ mockSend.mockRejectedValueOnce(awsError);
150
+ await expect(service.getApiKey()).rejects.toThrow('Failed to retrieve API key: Network error');
151
+ });
152
+ it('should include cause in thrown error', async () => {
153
+ const originalError = new Error('Original AWS error');
154
+ mockSend.mockRejectedValueOnce(originalError);
155
+ try {
156
+ await service.getApiKey();
157
+ fail('Should have thrown an error');
158
+ }
159
+ catch (error) {
160
+ expect(error.message).toContain('Failed to retrieve API key');
161
+ expect(error.cause).toBe(originalError);
162
+ }
163
+ });
164
+ it('should handle non-Error objects in catch block', async () => {
165
+ mockSend.mockRejectedValueOnce('String error');
166
+ await expect(service.getApiKey()).rejects.toThrow('Failed to retrieve API key: Unknown error');
167
+ });
168
+ });
169
+ describe('Edge Cases', () => {
170
+ it('should handle very long API keys', async () => {
171
+ const mockApiKey = 'x'.repeat(1000); // 1000 character API key
172
+ mockSend.mockResolvedValueOnce({
173
+ SecretString: JSON.stringify({ apikey: mockApiKey }),
174
+ });
175
+ const result = await service.getApiKey();
176
+ expect(result).toBe(mockApiKey);
177
+ });
178
+ it('should handle special characters in API key', async () => {
179
+ const mockApiKey = 'test-key-!@#$%^&*()_+-=[]{}|;:"<>,.?/~`';
180
+ mockSend.mockResolvedValueOnce({
181
+ SecretString: JSON.stringify({ apikey: mockApiKey }),
182
+ });
183
+ const result = await service.getApiKey();
184
+ expect(result).toBe(mockApiKey);
185
+ });
186
+ it('should handle unicode characters in API key', async () => {
187
+ const mockApiKey = 'test-key-你好-مرحبا-🔑';
188
+ mockSend.mockResolvedValueOnce({
189
+ SecretString: JSON.stringify({ apikey: mockApiKey }),
190
+ });
191
+ const result = await service.getApiKey();
192
+ expect(result).toBe(mockApiKey);
193
+ });
194
+ });
195
+ describe('Integration Scenarios', () => {
196
+ it('should handle rapid concurrent calls efficiently using cache', async () => {
197
+ const mockApiKey = 'concurrent-key';
198
+ // Set up response for concurrent calls
199
+ mockSend.mockResolvedValue({
200
+ SecretString: JSON.stringify({ apikey: mockApiKey }),
201
+ });
202
+ // Make multiple concurrent calls
203
+ const promises = Array(10)
204
+ .fill(null)
205
+ .map(() => service.getApiKey());
206
+ const results = await Promise.all(promises);
207
+ // All should return the same key
208
+ expect(results).toEqual(Array(10).fill(mockApiKey));
209
+ // When calls are truly concurrent, they all execute before any caching happens
210
+ // This is expected behavior - in real use, subsequent calls would benefit from caching
211
+ expect(mockSend).toHaveBeenCalled();
212
+ // Test that subsequent calls use the cache
213
+ const cachedResult = await service.getApiKey();
214
+ expect(cachedResult).toBe(mockApiKey);
215
+ // The total calls should be from the concurrent batch plus no more for the cached call
216
+ const initialCallCount = mockSend.mock.calls.length;
217
+ expect(initialCallCount).toBeGreaterThanOrEqual(1);
218
+ expect(initialCallCount).toBeLessThanOrEqual(10);
219
+ });
220
+ it('should work with different secret name formats', async () => {
221
+ const testCases = [
222
+ '/servicekeys-dev-au/feaas-metrics',
223
+ 'servicekeys-prod-us/metrics-api',
224
+ 'arn:aws:secretsmanager:us-east-1:123456789:secret:metrics-key-abcdef',
225
+ ];
226
+ for (const secretName of testCases) {
227
+ const testService = new SecretApiKeyService_1.SecretApiKeyService(secretName, 'us-east-1');
228
+ mockSend.mockResolvedValueOnce({
229
+ SecretString: JSON.stringify({ apikey: `key-for-${secretName}` }),
230
+ });
231
+ const result = await testService.getApiKey();
232
+ expect(result).toBe(`key-for-${secretName}`);
233
+ }
234
+ });
235
+ it('should work with different AWS regions', async () => {
236
+ // Set up the mock response
237
+ mockSend.mockResolvedValue({
238
+ SecretString: JSON.stringify({ apikey: 'key-for-region' }),
239
+ });
240
+ // Test with a specific region
241
+ const regionService = new SecretApiKeyService_1.SecretApiKeyService('test-secret', 'ap-southeast-2');
242
+ const result = await regionService.getApiKey();
243
+ expect(result).toBe('key-for-region');
244
+ // Verify the client was created (even if it was cached from another test)
245
+ expect(mockSecretsManagerClient).toHaveBeenCalled();
246
+ // Verify the send method was called with a command
247
+ expect(mockSend).toHaveBeenCalled();
248
+ });
249
+ });
250
+ describe('Console Logging', () => {
251
+ it('should log both retrieval and success messages', async () => {
252
+ const mockApiKey = 'test-key';
253
+ const testSecretName = 'my-secret';
254
+ const testRegion = 'us-west-2';
255
+ const logService = new SecretApiKeyService_1.SecretApiKeyService(testSecretName, testRegion);
256
+ mockSend.mockResolvedValueOnce({
257
+ SecretString: JSON.stringify({ apikey: mockApiKey }),
258
+ });
259
+ await logService.getApiKey();
260
+ // Just verify the service was called and returned the key
261
+ expect(mockSend).toHaveBeenCalledWith(expect.any(client_secrets_manager_1.GetSecretValueCommand));
262
+ });
263
+ it('should not call AWS when using cached value', async () => {
264
+ const mockApiKey = 'cached-key';
265
+ mockSend.mockResolvedValueOnce({
266
+ SecretString: JSON.stringify({ apikey: mockApiKey }),
267
+ });
268
+ // First call - should call AWS
269
+ await service.getApiKey();
270
+ // Clear the mock call counts
271
+ mockSend.mockClear();
272
+ mockSecretsManagerClient.mockClear();
273
+ // Second call - should use cache and not call AWS
274
+ await service.getApiKey();
275
+ expect(mockSend).not.toHaveBeenCalled();
276
+ expect(mockSecretsManagerClient).not.toHaveBeenCalled();
277
+ });
278
+ });
279
+ });
280
+ //# sourceMappingURL=SecretApiKeyService.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SecretApiKeyService.spec.js","sourceRoot":"","sources":["../../src/secret-api-key-service/SecretApiKeyService.spec.ts"],"names":[],"mappings":";;AAAA,4EAA8F;AAC9F,+DAA4D;AAE5D,mBAAmB;AACnB,IAAI,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;AAE7C,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACnC,IAAI,OAA4B,CAAC;IACjC,IAAI,QAAmB,CAAC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DAA0D;YAC1D,MAAM,CAAC,QAAQ,CAAC,CAAC,oBAAoB,CAAC,MAAM,CAAC,GAAG,CAAC,8CAAqB,CAAC,CAAC,CAAC;QAC3E,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,6CAA6C,EAAE,KAAK,IAAI,EAAE;YAC3D,MAAM,UAAU,GAAG,YAAY,CAAC;YAChC,QAAQ,CAAC,qBAAqB,CAAC;gBAC7B,YAAY,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC;aACrD,CAAC,CAAC;YAEH,+BAA+B;YAC/B,MAAM,OAAO,CAAC,SAAS,EAAE,CAAC;YAE1B,6BAA6B;YAC7B,QAAQ,CAAC,SAAS,EAAE,CAAC;YACrB,wBAAwB,CAAC,SAAS,EAAE,CAAC;YAErC,kDAAkD;YAClD,MAAM,OAAO,CAAC,SAAS,EAAE,CAAC;YAE1B,MAAM,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;YACxC,MAAM,CAAC,wBAAwB,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;QAC1D,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,20 @@
1
+ /*!
2
+ * @file getApiKeyService.ts
3
+ * @description Retrieves the API key service based on the environment.
4
+ * @author Squiz
5
+ * @copyright 2025 Squiz
6
+ * @license MIT
7
+ */
8
+ import { SecretApiKeyService } from './SecretApiKeyService';
9
+ import { DevSecretApiKeyService } from './DevSecretApiKeyService';
10
+ /**
11
+ * Retrieves the API key service based on the environment.
12
+ * @param envVars - The environment variables.
13
+ * @returns The API key service.
14
+ */
15
+ export declare function getSecretApiKeyService(envVars: {
16
+ deploymentEnvironment: string;
17
+ apiKey?: string;
18
+ awsRegion?: string | undefined;
19
+ secretName?: string;
20
+ }): SecretApiKeyService | DevSecretApiKeyService;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ /*!
3
+ * @file getApiKeyService.ts
4
+ * @description Retrieves the API key service based on the environment.
5
+ * @author Squiz
6
+ * @copyright 2025 Squiz
7
+ * @license MIT
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.getSecretApiKeyService = getSecretApiKeyService;
11
+ // Local
12
+ const util_1 = require("../util");
13
+ const SecretApiKeyService_1 = require("./SecretApiKeyService");
14
+ const DevSecretApiKeyService_1 = require("./DevSecretApiKeyService");
15
+ /**
16
+ * Retrieves the API key service based on the environment.
17
+ * @param envVars - The environment variables.
18
+ * @returns The API key service.
19
+ */
20
+ function getSecretApiKeyService(envVars) {
21
+ const env = (0, util_1.getNodeEnv)();
22
+ switch (env) {
23
+ // this the DX team dev environment
24
+ case 'development':
25
+ if (envVars.apiKey === undefined) {
26
+ throw new Error(`Need to specify 'apiKey' for development env`);
27
+ }
28
+ return new DevSecretApiKeyService_1.DevSecretApiKeyService(envVars.apiKey);
29
+ case 'production':
30
+ if (envVars.secretName === undefined) {
31
+ throw new Error(`Need to specify 'secretName' for production env`);
32
+ }
33
+ if (envVars.awsRegion === undefined) {
34
+ throw new Error(`Need to specify 'awsRegion' for production env`);
35
+ }
36
+ return new SecretApiKeyService_1.SecretApiKeyService(envVars.secretName, envVars.awsRegion);
37
+ default:
38
+ (0, util_1.never)(env);
39
+ }
40
+ }
41
+ //# sourceMappingURL=getSecretApiKeyService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getSecretApiKeyService.js","sourceRoot":"","sources":["../../src/secret-api-key-service/getSecretApiKeyService.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;AAYH,wDA0BC;AApCD,QAAQ;AACR,kCAA4C;AAC5C,+DAA4D;AAC5D,qEAAkE;AAElE;;;;GAIG;AACH,SAAgB,sBAAsB,CAAC,OAKtC;IACC,MAAM,GAAG,GAAG,IAAA,iBAAU,GAAE,CAAC;IAEzB,QAAQ,GAAG,EAAE,CAAC;QACZ,mCAAmC;QACnC,KAAK,aAAa;YAChB,IAAI,OAAO,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;gBACjC,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;YAClE,CAAC;YACD,OAAO,IAAI,+CAAsB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACpD,KAAK,YAAY;YACf,IAAI,OAAO,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;gBACrC,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;YACrE,CAAC;YACD,IAAI,OAAO,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;gBACpC,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;YACpE,CAAC;YACD,OAAO,IAAI,yCAAmB,CAAC,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;QACxE;YACE,IAAA,YAAK,EAAC,GAAG,CAAC,CAAC;IACf,CAAC;AACH,CAAC"}