@digitraffic/common 2024.3.13-1 → 2024.3.22-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.
- package/dist/__test__/imports.test.mjs +5 -7
- package/dist/__test__/secrets/secret-holder.test.mjs +25 -15
- package/dist/__test__/secrets/secret.test.mjs +17 -5
- package/dist/aws/infra/canaries/url-checker.mjs +3 -4
- package/dist/aws/infra/stack/rest_apis.d.mts +3 -1
- package/dist/aws/infra/stack/rest_apis.mjs +16 -27
- package/dist/aws/runtime/apikey.d.mts +2 -2
- package/dist/aws/runtime/apikey.mjs +14 -4
- package/dist/aws/runtime/secrets/secret.mjs +1 -1
- package/dist/utils/utils.d.mts +6 -0
- package/dist/utils/utils.mjs +18 -0
- package/package.json +31 -31
- package/dist/test/secrets-manager.d.mts +0 -10
- package/dist/test/secrets-manager.mjs +0 -32
@@ -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
|
-
|
316
|
-
|
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 {
|
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
|
9
|
-
const
|
10
|
-
|
11
|
-
|
12
|
-
const { 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(
|
39
|
+
mockSecret({});
|
30
40
|
const holder = SecretHolder.create();
|
31
41
|
const secret = holder.get();
|
32
|
-
return expect(secret).resolves.toEqual(
|
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 =
|
73
|
+
const callCount = getSecretValueMock.mock.calls.length;
|
64
74
|
await holder.get();
|
65
|
-
expect(
|
75
|
+
expect(getSecretValueMock).toHaveBeenCalledTimes(callCount + 1);
|
66
76
|
// gets cached secret
|
67
77
|
await holder.get();
|
68
|
-
expect(
|
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 =
|
85
|
+
const callCount = getSecretValueMock.mock.calls.length;
|
76
86
|
await holder.get();
|
77
|
-
expect(
|
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(
|
93
|
+
expect(getSecretValueMock).toHaveBeenCalledTimes(callCount + 2);
|
84
94
|
});
|
85
95
|
});
|
86
96
|
//# sourceMappingURL=secret-holder.test.mjs.map
|
@@ -1,12 +1,24 @@
|
|
1
|
-
import {
|
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
|
9
|
-
|
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(
|
32
|
+
mockSecret({});
|
21
33
|
const secret = await getSecret(SECRET_ID, "");
|
22
|
-
expect(secret).toEqual(
|
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
|
-
|
43
|
-
|
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,4 +1,4 @@
|
|
1
|
-
import { type IResource, type JsonSchema, Resource, RestApi, type RestApiProps } from "aws-cdk-lib/aws-apigateway";
|
1
|
+
import { type IResource, type JsonSchema, Resource, type ResourceOptions, RestApi, type RestApiProps } from "aws-cdk-lib/aws-apigateway";
|
2
2
|
import { PolicyDocument } from "aws-cdk-lib/aws-iam";
|
3
3
|
import { Construct } from "constructs";
|
4
4
|
import type { ModelWithReference } from "../../types/model-with-reference.mjs";
|
@@ -16,6 +16,7 @@ export declare class DigitrafficRestApi extends RestApi {
|
|
16
16
|
private getModelWithReference;
|
17
17
|
private addDocumentationPart;
|
18
18
|
documentResource(resource: Resource, ...documentationPart: DocumentationPart[]): void;
|
19
|
+
addResourceWithCorsOptionsSubTree(resource: Resource, pathPart: string, config?: ResourceOptions): Resource;
|
19
20
|
/**
|
20
21
|
* Add support for HTTP OPTIONS to an API GW resource,
|
21
22
|
* this is required for preflight CORS requests made by browsers.
|
@@ -45,3 +46,4 @@ export declare function setReturnCodeForMissingAuthenticationToken(returnCode: n
|
|
45
46
|
export declare function createRestApi(stack: Construct, apiId: string, apiName: string, allowFromIpAddresses?: string[] | undefined): RestApi;
|
46
47
|
export declare function createDefaultPolicyDocument(): PolicyDocument;
|
47
48
|
export declare function createIpRestrictionPolicyDocument(allowFromIpAddresses: string[]): PolicyDocument;
|
49
|
+
export declare const PUBLIC_REST_API_CORS_CONFIG: Partial<ResourceOptions>;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { CfnDocumentationPart, EndpointType, GatewayResponse, MethodLoggingLevel,
|
1
|
+
import { CfnDocumentationPart, Cors, EndpointType, GatewayResponse, MethodLoggingLevel, Model, Resource, ResponseType, RestApi, } from "aws-cdk-lib/aws-apigateway";
|
2
2
|
import { AnyPrincipal, Effect, PolicyDocument, PolicyStatement, } from "aws-cdk-lib/aws-iam";
|
3
3
|
import { Construct } from "constructs";
|
4
4
|
import { getModelReference } from "../../../utils/api-model.mjs";
|
@@ -82,38 +82,20 @@ export class DigitrafficRestApi extends RestApi {
|
|
82
82
|
console.info("Skipping documentation for %s", resource.path);
|
83
83
|
}
|
84
84
|
}
|
85
|
+
addResourceWithCorsOptionsSubTree(resource, pathPart, config) {
|
86
|
+
const mergedConfig = {
|
87
|
+
...PUBLIC_REST_API_CORS_CONFIG,
|
88
|
+
...config
|
89
|
+
};
|
90
|
+
return resource.addResource(pathPart, mergedConfig);
|
91
|
+
}
|
85
92
|
/**
|
86
93
|
* Add support for HTTP OPTIONS to an API GW resource,
|
87
94
|
* this is required for preflight CORS requests made by browsers.
|
88
95
|
* @param apiResource
|
89
96
|
*/
|
90
97
|
addCorsOptions(apiResource) {
|
91
|
-
apiResource.
|
92
|
-
integrationResponses: [
|
93
|
-
{
|
94
|
-
statusCode: "200",
|
95
|
-
responseParameters: {
|
96
|
-
"method.response.header.Access-Control-Allow-Headers": "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token,Digitraffic-User'",
|
97
|
-
"method.response.header.Access-Control-Allow-Origin": "'*'",
|
98
|
-
"method.response.header.Access-Control-Allow-Methods": "'OPTIONS,GET,HEAD'",
|
99
|
-
},
|
100
|
-
},
|
101
|
-
],
|
102
|
-
requestTemplates: {
|
103
|
-
"application/json": '{"statusCode": 200}',
|
104
|
-
},
|
105
|
-
}), {
|
106
|
-
methodResponses: [
|
107
|
-
{
|
108
|
-
statusCode: "200",
|
109
|
-
responseParameters: {
|
110
|
-
"method.response.header.Access-Control-Allow-Headers": true,
|
111
|
-
"method.response.header.Access-Control-Allow-Methods": true,
|
112
|
-
"method.response.header.Access-Control-Allow-Origin": true,
|
113
|
-
},
|
114
|
-
},
|
115
|
-
],
|
116
|
-
});
|
98
|
+
apiResource.addCorsPreflight(PUBLIC_REST_API_CORS_CONFIG.defaultCorsPreflightOptions);
|
117
99
|
}
|
118
100
|
}
|
119
101
|
/**
|
@@ -206,4 +188,11 @@ export function createIpRestrictionPolicyDocument(allowFromIpAddresses) {
|
|
206
188
|
],
|
207
189
|
});
|
208
190
|
}
|
191
|
+
export const PUBLIC_REST_API_CORS_CONFIG = {
|
192
|
+
defaultCorsPreflightOptions: {
|
193
|
+
allowOrigins: Cors.ALL_ORIGINS,
|
194
|
+
allowHeaders: ["Content-Type", "X-Amz-Date", "Authorization", "X-Api-Key", "X-Amz-Security-Token", "Digitraffic-User"],
|
195
|
+
allowMethods: ["OPTIONS", "GET", "HEAD"]
|
196
|
+
}
|
197
|
+
};
|
209
198
|
//# sourceMappingURL=rest_apis.mjs.map
|
@@ -1,2 +1,2 @@
|
|
1
|
-
import type {
|
2
|
-
export declare function getApiKeyFromAPIGateway(keyId: string): Promise<
|
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 {
|
2
|
-
|
3
|
-
|
4
|
-
|
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/dist/utils/utils.d.mts
CHANGED
@@ -75,6 +75,12 @@ export declare function getEnvVariableOr<T>(key: string, fn: () => T): string |
|
|
75
75
|
* @param orElse Alternative value
|
76
76
|
*/
|
77
77
|
export declare function getEnvVariableOrElse<T>(key: string, orElse: T): string | T;
|
78
|
+
/**
|
79
|
+
* Gets variable from environment or from an AWS Secrets Manager secret if not found in the environment.
|
80
|
+
* @param Environment key
|
81
|
+
* @param Secret id in Secrets Manager
|
82
|
+
*/
|
83
|
+
export declare function getFromEnvOrSecret(key: string, secretId: string): Promise<string>;
|
78
84
|
export declare function setSecretOverideAwsRegionEnv(region: string): void;
|
79
85
|
/**
|
80
86
|
* ESLint won't allow to call Object.prototype builtin methods.
|
package/dist/utils/utils.mjs
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import { EnvKeys } from "../aws/runtime/environment.mjs";
|
2
|
+
import { getSecret, } from "../aws/runtime/secrets/secret.mjs";
|
2
3
|
/**
|
3
4
|
* Check if arrays have only elements that also exists also in other array.
|
4
5
|
* Individual element count doesn't matter.
|
@@ -130,6 +131,23 @@ export function getEnvVariableOr(key, fn) {
|
|
130
131
|
export function getEnvVariableOrElse(key, orElse) {
|
131
132
|
return getEnvVariableOr(key, () => orElse);
|
132
133
|
}
|
134
|
+
/**
|
135
|
+
* Gets variable from environment or from an AWS Secrets Manager secret if not found in the environment.
|
136
|
+
* @param Environment key
|
137
|
+
* @param Secret id in Secrets Manager
|
138
|
+
*/
|
139
|
+
export async function getFromEnvOrSecret(key, secretId) {
|
140
|
+
const envValue = getEnvVariableSafe(key);
|
141
|
+
if (envValue.result === "ok") {
|
142
|
+
return envValue.value;
|
143
|
+
}
|
144
|
+
const secret = await getSecret(secretId);
|
145
|
+
const secretValue = secret[key];
|
146
|
+
if (secretValue !== undefined) {
|
147
|
+
return secretValue;
|
148
|
+
}
|
149
|
+
throw new Error(`Cannot get value with key ${key} from env or secret`);
|
150
|
+
}
|
133
151
|
export function setSecretOverideAwsRegionEnv(region) {
|
134
152
|
setEnvVariable(EnvKeys.SECRET_OVERRIDE_AWS_REGION, region);
|
135
153
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@digitraffic/common",
|
3
|
-
"version": "2024.3.
|
3
|
+
"version": "2024.3.22-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,64 +103,65 @@
|
|
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.
|
108
|
-
"@aws-sdk/lib-storage": "^3.
|
109
|
-
"@aws-sdk/client-secrets-manager": "^3.
|
110
|
-
"@aws-sdk/client-api-gateway": "^3.
|
111
|
-
"@aws-sdk/client-sns": "^3.
|
112
|
-
"@types/geojson": "^7946.0.
|
113
|
-
"aws-cdk-lib": "^2.
|
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",
|
112
|
+
"aws-cdk-lib": "^2.133.0",
|
114
113
|
"change-case": "5.0.0",
|
115
114
|
"constructs": "^10.3.0",
|
116
115
|
"date-fns": "~2.30.0",
|
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.
|
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
|
-
"
|
128
|
-
"@aws-sdk/
|
129
|
-
"@aws-sdk/
|
130
|
-
"@aws-sdk/client-
|
131
|
-
"@aws-sdk/client-
|
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.
|
134
|
-
"@rushstack/heft": "^0.
|
135
|
-
"@rushstack/heft-jest-plugin": "^0.11.
|
136
|
-
"@rushstack/heft-lint-plugin": "^0.3.
|
137
|
-
"@rushstack/heft-typescript-plugin": "^0.3.
|
138
|
-
"@types/aws-lambda": "8.10.
|
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.
|
141
|
-
"@types/geojson-validation": "^1.0.
|
142
|
-
"@types/jest": "29.5.
|
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.
|
145
|
-
"@types/sinon": "17.0.
|
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
|
-
"aws-cdk-lib": "
|
148
|
+
"aws-cdk-lib": "^2.133.0",
|
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.
|
153
|
-
"eslint": "~8.
|
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.
|
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.
|
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
|