@digitraffic/common 2024.3.13-1 → 2024.3.14-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.
@@ -75,10 +75,6 @@ test('httpserver import ok?', () => {
75
75
  const httpserver = import("../test/httpserver.mjs");
76
76
  return expect(httpserver).resolves.toBeDefined();
77
77
  });
78
- test('secretsManager import ok?', () => {
79
- const secretsManager = import("../test/secrets-manager.mjs");
80
- return expect(secretsManager).resolves.toBeDefined();
81
- });
82
78
  test('asserter import ok?', () => {
83
79
  const asserter = import("../test/asserter.mjs");
84
80
  return expect(asserter).resolves.toBeDefined();
@@ -311,10 +307,12 @@ test('messaging import ok?', () => {
311
307
  const messaging = import("../aws/runtime/messaging.mjs");
312
308
  return expect(messaging).resolves.toBeDefined();
313
309
  });
310
+ /*
311
+ temporary disable, enable after sdk v2 is kicked out
314
312
  test('apikey import ok?', () => {
315
- const apikey = import("../aws/runtime/apikey.mjs");
316
- return expect(apikey).resolves.toBeDefined();
317
- });
313
+ const apikey = import("../aws/runtime/apikey.mjs");
314
+ return expect(apikey).resolves.toBeDefined();
315
+ });*/
318
316
  test('environment import ok?', () => {
319
317
  const environment = import("../aws/runtime/environment.mjs");
320
318
  return expect(environment).resolves.toBeDefined();
@@ -1,19 +1,29 @@
1
- import { mockSecret, stubSecretsManager } from "../../test/secrets-manager.mjs";
1
+ import { SecretsManager } from "@aws-sdk/client-secrets-manager";
2
+ import { jest } from "@jest/globals";
2
3
  const SECRET_WITH_PREFIX = {
3
4
  "prefix.value": "value",
4
5
  "prefix.name": "name",
5
6
  "wrong.value": "value",
6
7
  username: "DB_USER",
7
8
  };
8
- const SECRET_EMPTY = {};
9
- const stubSM = stubSecretsManager();
10
- const secretHolder = await import("../../aws/runtime/secrets/secret-holder.mjs");
11
- const database = await import("../../database/database.mjs");
12
- const { SecretHolder } = secretHolder;
13
- const { DatabaseEnvironmentKeys } = database;
9
+ const emptySecret = { $metadata: {} };
10
+ const getSecretValueMock = jest.fn();
11
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
12
+ jest.spyOn(SecretsManager.prototype, "getSecretValue").mockImplementation(getSecretValueMock);
13
+ const { SecretHolder } = await import("../../aws/runtime/secrets/secret-holder.mjs");
14
+ const { DatabaseEnvironmentKeys } = await import("../../database/database.mjs");
15
+ function mockSecret(secret) {
16
+ if (!secret) {
17
+ getSecretValueMock.mockImplementation(() => Promise.resolve(emptySecret));
18
+ }
19
+ else {
20
+ getSecretValueMock.mockImplementation(() => Promise.resolve({ ...emptySecret, ...{ SecretString: JSON.stringify(secret) } }));
21
+ }
22
+ }
14
23
  describe("SecretHolder - tests", () => {
15
24
  beforeEach(() => {
16
25
  process.env["SECRET_ID"] = "test-id";
26
+ process.env["AWS_REGION"] = "eu-west-1";
17
27
  });
18
28
  afterEach(() => {
19
29
  // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
@@ -26,10 +36,10 @@ describe("SecretHolder - tests", () => {
26
36
  return expect(secret).rejects.toThrow("No secret found!");
27
37
  }, 10000);
28
38
  test("get - empty secret", () => {
29
- mockSecret(SECRET_EMPTY);
39
+ mockSecret({});
30
40
  const holder = SecretHolder.create();
31
41
  const secret = holder.get();
32
- return expect(secret).resolves.toEqual(SECRET_EMPTY);
42
+ return expect(secret).resolves.toEqual({});
33
43
  });
34
44
  test("get - no prefix", () => {
35
45
  mockSecret(SECRET_WITH_PREFIX);
@@ -60,27 +70,27 @@ describe("SecretHolder - tests", () => {
60
70
  test("get - ttl - do not fetch", async () => {
61
71
  mockSecret(SECRET_WITH_PREFIX);
62
72
  const holder = SecretHolder.create();
63
- const callCount = stubSM.getSecretValue.callCount;
73
+ const callCount = getSecretValueMock.mock.calls.length;
64
74
  await holder.get();
65
- expect(stubSM.getSecretValue.callCount).toEqual(callCount + 1);
75
+ expect(getSecretValueMock).toHaveBeenCalledTimes(callCount + 1);
66
76
  // gets cached secret
67
77
  await holder.get();
68
- expect(stubSM.getSecretValue.callCount).toEqual(callCount + 1);
78
+ expect(getSecretValueMock).toHaveBeenCalledTimes(callCount + 1);
69
79
  });
70
80
  test("get - ttl - fetch", async () => {
71
81
  mockSecret(SECRET_WITH_PREFIX);
72
82
  const holder = new SecretHolder("", "", [], {
73
83
  ttl: 1,
74
84
  });
75
- const callCount = stubSM.getSecretValue.callCount;
85
+ const callCount = getSecretValueMock.mock.calls.length;
76
86
  await holder.get();
77
- expect(stubSM.getSecretValue.callCount).toEqual(callCount + 1);
87
+ expect(getSecretValueMock).toHaveBeenCalledTimes(callCount + 1);
78
88
  // cache expires, fetches secret again
79
89
  const start = Date.now();
80
90
  while (Date.now() < start + 2000)
81
91
  ;
82
92
  await holder.get();
83
- expect(stubSM.getSecretValue.callCount).toEqual(callCount + 2);
93
+ expect(getSecretValueMock).toHaveBeenCalledTimes(callCount + 2);
84
94
  });
85
95
  });
86
96
  //# sourceMappingURL=secret-holder.test.mjs.map
@@ -1,12 +1,24 @@
1
- import { mockSecret, stubSecretsManager } from "../../test/secrets-manager.mjs";
1
+ import { SecretsManager } from "@aws-sdk/client-secrets-manager";
2
+ import { jest } from "@jest/globals";
2
3
  const SECRET_ID = "test_secret";
3
4
  const SECRET_WITH_PREFIX = {
4
5
  "prefix.value": "value",
5
6
  "prefix.name": "name",
6
7
  "wrong.value": "value",
7
8
  };
8
- const SECRET_EMPTY = {};
9
- stubSecretsManager();
9
+ const emptySecret = { $metadata: {} };
10
+ const getSecretValueMock = jest.fn();
11
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
12
+ jest.spyOn(SecretsManager.prototype, "getSecretValue").mockImplementation(getSecretValueMock);
13
+ function mockSecret(secret) {
14
+ if (!secret) {
15
+ getSecretValueMock.mockImplementation(() => Promise.resolve(emptySecret));
16
+ }
17
+ else {
18
+ getSecretValueMock.mockImplementation(() => Promise.resolve({ ...emptySecret, ...{ SecretString: JSON.stringify(secret) } }));
19
+ }
20
+ }
21
+ process.env["AWS_REGION"] = "eu-west-1";
10
22
  const secret = await import("../../aws/runtime/secrets/secret.mjs");
11
23
  const { getSecret } = secret;
12
24
  describe("secret - test", () => {
@@ -17,9 +29,9 @@ describe("secret - test", () => {
17
29
  }).rejects.toThrow("No secret found!");
18
30
  });
19
31
  test("getSecret - empty secret", async () => {
20
- mockSecret(SECRET_EMPTY);
32
+ mockSecret({});
21
33
  const secret = await getSecret(SECRET_ID, "");
22
- expect(secret).toEqual(SECRET_EMPTY);
34
+ expect(secret).toEqual({});
23
35
  });
24
36
  test("getSecret - no prefix", async () => {
25
37
  mockSecret(SECRET_WITH_PREFIX);
@@ -38,10 +38,9 @@ export class UrlChecker {
38
38
  .withIncludeResponseHeaders(false)
39
39
  .withFailedCanaryMetric(true);
40
40
  }
41
- static create(hostname, apiKeyId) {
42
- return getApiKeyFromAPIGateway(apiKeyId).then((apiKey) => {
43
- return new UrlChecker(hostname, apiKey.value);
44
- });
41
+ static async create(hostname, apiKeyId) {
42
+ const apiKey = await getApiKeyFromAPIGateway(apiKeyId);
43
+ return new UrlChecker(hostname, apiKey.value);
45
44
  }
46
45
  static createV2() {
47
46
  return this.create(getEnvVariable(ENV_HOSTNAME), getEnvVariable(ENV_API_KEY));
@@ -1,2 +1,2 @@
1
- import type { UpdateApiKeyCommandOutput } from "@aws-sdk/client-api-gateway";
2
- export declare function getApiKeyFromAPIGateway(keyId: string): Promise<UpdateApiKeyCommandOutput>;
1
+ import type { ApiKey } from "aws-sdk/clients/apigateway.js";
2
+ export declare function getApiKeyFromAPIGateway(keyId: string): Promise<ApiKey>;
@@ -1,9 +1,19 @@
1
- import { APIGateway } from "@aws-sdk/client-api-gateway";
2
- export function getApiKeyFromAPIGateway(keyId) {
3
- const agw = new APIGateway();
4
- return agw.getApiKey({
1
+ //import { APIGatewayClient, GetApiKeyCommand } from "@aws-sdk/client-api-gateway";
2
+ //import type { GetApiKeyCommandOutput } from "@aws-sdk/client-api-gateway";
3
+ import { APIGateway } from "aws-sdk";
4
+ export async function getApiKeyFromAPIGateway(keyId) {
5
+ const ag = new APIGateway();
6
+ return ag.getApiKey({
7
+ apiKey: keyId,
8
+ includeValue: true
9
+ }).promise();
10
+ /*
11
+ const client = new APIGatewayClient();
12
+ const command = new GetApiKeyCommand({
5
13
  apiKey: keyId,
6
14
  includeValue: true,
7
15
  });
16
+
17
+ return client.send(command);*/
8
18
  }
9
19
  //# sourceMappingURL=apikey.mjs.map
@@ -1,6 +1,6 @@
1
+ import { SecretsManager } from "@aws-sdk/client-secrets-manager";
1
2
  import { getEnvVariable, getEnvVariableOrElse } from "../../../utils/utils.mjs";
2
3
  import { EnvKeys } from "../environment.mjs";
3
- const { SecretsManager } = await import("@aws-sdk/client-secrets-manager");
4
4
  // SECRET_OVERRIDE_AWS_REGION might not have been set before import of
5
5
  // secret, so we need to lazy initialize SecretsManager
6
6
  let smClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitraffic/common",
3
- "version": "2024.3.13-1",
3
+ "version": "2024.3.14-1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "repository": {
@@ -36,7 +36,6 @@
36
36
  "./dist/test/testutils": "./dist/test/testutils.mjs",
37
37
  "./dist/test/db-testutils": "./dist/test/db-testutils.mjs",
38
38
  "./dist/test/httpserver": "./dist/test/httpserver.mjs",
39
- "./dist/test/secrets-manager": "./dist/test/secrets-manager.mjs",
40
39
  "./dist/test/asserter": "./dist/test/asserter.mjs",
41
40
  "./dist/test/mock-ky": "./dist/test/mock-ky.mjs",
42
41
  "./dist/marine/rtz": "./dist/marine/rtz.mjs",
@@ -104,12 +103,12 @@
104
103
  "./dist/aws/runtime/digitraffic-integration-response": "./dist/aws/runtime/digitraffic-integration-response.mjs"
105
104
  },
106
105
  "peerDependencies": {
107
- "@aws-sdk/client-s3": "^3.496.0",
108
- "@aws-sdk/lib-storage": "^3.496.0",
109
- "@aws-sdk/client-secrets-manager": "^3.496.0",
110
- "@aws-sdk/client-api-gateway": "^3.496.0",
111
- "@aws-sdk/client-sns": "^3.496.0",
112
- "@types/geojson": "^7946.0.12",
106
+ "@aws-sdk/client-s3": "^3.533.0",
107
+ "@aws-sdk/lib-storage": "^3.533.0",
108
+ "@aws-sdk/client-secrets-manager": "^3.533.0",
109
+ "@aws-sdk/client-api-gateway": "^3.533.0",
110
+ "@aws-sdk/client-sns": "^3.533.0",
111
+ "@types/geojson": "^7946.0.14",
113
112
  "aws-cdk-lib": "^2.132.1",
114
113
  "change-case": "5.0.0",
115
114
  "constructs": "^10.3.0",
@@ -117,51 +116,52 @@
117
116
  "date-fns-tz": "~2.0.0",
118
117
  "etag": "^1.8.1",
119
118
  "geojson-validation": "^1.0.2",
120
- "ky": "^1.2.0",
119
+ "ky": "^1.2.2",
121
120
  "lodash": "~4.17.21",
122
121
  "node-ttl": "^0.2.0",
123
122
  "pg-native": "^3.0.1",
124
123
  "pg-promise": "^11.5.4"
125
124
  },
126
125
  "devDependencies": {
127
- "@aws-sdk/client-s3": "3.496.0",
128
- "@aws-sdk/lib-storage": "3.496.0",
129
- "@aws-sdk/client-secrets-manager": "3.496.0",
130
- "@aws-sdk/client-api-gateway": "3.496.0",
131
- "@aws-sdk/client-sns": "3.496.0",
126
+ "aws-sdk": "2.1577.0",
127
+ "@aws-sdk/client-s3": "3.533.0",
128
+ "@aws-sdk/lib-storage": "3.533.0",
129
+ "@aws-sdk/client-secrets-manager": "3.533.0",
130
+ "@aws-sdk/client-api-gateway": "3.533.0",
131
+ "@aws-sdk/client-sns": "3.533.0",
132
132
  "@jest/globals": "^29.7.0",
133
- "@rushstack/eslint-config": "^3.6.2",
134
- "@rushstack/heft": "^0.64.3",
135
- "@rushstack/heft-jest-plugin": "^0.11.3",
136
- "@rushstack/heft-lint-plugin": "^0.3.3",
137
- "@rushstack/heft-typescript-plugin": "^0.3.3",
138
- "@types/aws-lambda": "8.10.131",
133
+ "@rushstack/eslint-config": "^3.6.4",
134
+ "@rushstack/heft": "^0.66.0",
135
+ "@rushstack/heft-jest-plugin": "^0.11.21",
136
+ "@rushstack/heft-lint-plugin": "^0.3.20",
137
+ "@rushstack/heft-typescript-plugin": "^0.3.20",
138
+ "@types/aws-lambda": "8.10.136",
139
139
  "@types/etag": "1.8.3",
140
- "@types/geojson": "7946.0.13",
141
- "@types/geojson-validation": "^1.0.2",
142
- "@types/jest": "29.5.11",
140
+ "@types/geojson": "7946.0.14",
141
+ "@types/geojson-validation": "^1.0.3",
142
+ "@types/jest": "29.5.12",
143
143
  "@types/lodash": "4.14.202",
144
- "@types/node": "20.10.7",
145
- "@types/sinon": "17.0.2",
144
+ "@types/node": "20.11.27",
145
+ "@types/sinon": "17.0.3",
146
146
  "@typescript-eslint/eslint-plugin": "~6.18.1",
147
147
  "@typescript-eslint/parser": "^6.20.0",
148
148
  "aws-cdk-lib": "~2.132.1",
149
149
  "change-case": "5.3.0",
150
150
  "constructs": "10.3.0",
151
151
  "date-fns": "~2.30.0",
152
- "date-fns-tz": "~2.0.0",
153
- "eslint": "~8.56.0",
152
+ "date-fns-tz": "~2.0.1",
153
+ "eslint": "~8.57.0",
154
154
  "eslint-config-prettier": "^9.1.0",
155
155
  "eslint-plugin-deprecation": "~2.0.0",
156
156
  "etag": "^1.8.1",
157
157
  "geojson-validation": "^1.0.2",
158
158
  "jest": "^29.7.0",
159
159
  "jest-junit": "^16.0.0",
160
- "ky": "^1.2.0",
160
+ "ky": "^1.2.2",
161
161
  "lodash": "~4.17.21",
162
162
  "node-ttl": "^0.2.0",
163
163
  "pg-promise": "^11.5.4",
164
- "prettier": "^3.2.4",
164
+ "prettier": "^3.2.5",
165
165
  "rimraf": "^5.0.5",
166
166
  "sinon": "17.0.1",
167
167
  "ts-jest": "^29.1.2",
@@ -1,10 +0,0 @@
1
- import { SecretsManager } from "@aws-sdk/client-secrets-manager";
2
- import sinon from "sinon";
3
- /**
4
- * Stub Secrets Manager for tests. You must call this
5
- * before you instantiate Secrets Manager(this might happen when you import the function that uses Secrets Manager).
6
- *
7
- * To mock the actual secret, call mockSecret()
8
- */
9
- export declare function stubSecretsManager(): sinon.SinonStubbedInstance<SecretsManager>;
10
- export declare function mockSecret<Secret>(secret: Secret): void;
@@ -1,32 +0,0 @@
1
- import { SecretsManager } from "@aws-sdk/client-secrets-manager";
2
- import sinon from "sinon";
3
- import { EnvKeys } from "../aws/runtime/environment.mjs";
4
- import { setEnvVariable } from "../utils/utils.mjs";
5
- import { jest } from '@jest/globals';
6
- setEnvVariable(EnvKeys.AWS_REGION, "eu-west-1");
7
- const emptySecret = { $metadata: {} };
8
- const SecretsManagerStubInstance = sinon.createStubInstance(SecretsManager);
9
- SecretsManagerStubInstance.getSecretValue.resolves(emptySecret);
10
- /**
11
- * Stub Secrets Manager for tests. You must call this
12
- * before you instantiate Secrets Manager(this might happen when you import the function that uses Secrets Manager).
13
- *
14
- * To mock the actual secret, call mockSecret()
15
- */
16
- export function stubSecretsManager() {
17
- jest.unstable_mockModule("@aws-sdk/client-secrets-manager", function () {
18
- return {
19
- SecretsManager: sinon.stub().returns(SecretsManagerStubInstance)
20
- };
21
- });
22
- return SecretsManagerStubInstance;
23
- }
24
- export function mockSecret(secret) {
25
- if (!secret) {
26
- SecretsManagerStubInstance.getSecretValue.resolves({ ...emptySecret });
27
- }
28
- else {
29
- SecretsManagerStubInstance.getSecretValue.resolves({ SecretString: JSON.stringify(secret) });
30
- }
31
- }
32
- //# sourceMappingURL=secrets-manager.mjs.map