@tomassabol/aws-services 1.8.0 → 1.8.2
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/appconfig.d.ts +3 -0
- package/appconfig.js +18 -0
- package/dynamodb.d.ts +4 -0
- package/dynamodb.js +7 -0
- package/dynamodb.mock.d.ts +8 -0
- package/dynamodb.mock.js +12 -0
- package/eventbridge.d.ts +8 -0
- package/eventbridge.js +37 -0
- package/eventbridge.mock.d.ts +3 -0
- package/eventbridge.mock.js +7 -0
- package/logger.d.ts +2 -0
- package/logger.js +14 -0
- package/package.json +8 -9
- package/s3.d.ts +13 -0
- package/s3.js +46 -0
- package/secrets-manager.d.ts +4 -0
- package/secrets-manager.js +37 -0
- package/secrets-manager.mock.d.ts +4 -0
- package/secrets-manager.mock.js +8 -0
- package/sns.d.ts +7 -0
- package/sns.js +21 -0
- package/sqs.d.ts +6 -0
- package/sqs.js +24 -0
- package/sqs.mock.d.ts +3 -0
- package/sqs.mock.js +7 -0
- package/ssm.d.ts +19 -0
- package/ssm.js +48 -0
- package/ssm.mock.d.ts +3 -0
- package/ssm.mock.js +7 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/.eslintignore +0 -1
- package/.eslintrc.json +0 -75
- package/.husky/pre-commit +0 -4
- package/.lintstagedrc.json +0 -9
- package/.nvmrc +0 -1
- package/.prettierignore +0 -2
- package/.prettierrc.json +0 -3
- package/.vscode/settings.json +0 -6
- package/CHANGELOG.md +0 -96
- package/bitbucket-pipelines.yml +0 -65
- package/jest.config.js +0 -62
- package/sonar-project.properties +0 -8
- package/src/appconfig.ts +0 -20
- package/src/dynamodb.mock.ts +0 -10
- package/src/dynamodb.ts +0 -7
- package/src/eventbridge.mock.ts +0 -5
- package/src/eventbridge.ts +0 -47
- package/src/logger.ts +0 -14
- package/src/s3.ts +0 -56
- package/src/secrets-manager.mock.ts +0 -9
- package/src/secrets-manager.ts +0 -37
- package/src/sns.ts +0 -24
- package/src/sqs.mock.ts +0 -5
- package/src/sqs.ts +0 -32
- package/src/ssm.mock.ts +0 -5
- package/src/ssm.ts +0 -70
- package/test/appconfig.test.ts +0 -45
- package/test/dynamodb.test.ts +0 -13
- package/test/eventbridge.test.ts +0 -35
- package/test/s3.test.ts +0 -78
- package/test/secrets-manager.test.ts +0 -55
- package/test/sns.test.ts +0 -59
- package/test/sqs.test.ts +0 -46
- package/test/ssm.test.ts +0 -85
- package/tsconfig.build.json +0 -4
- package/tsconfig.json +0 -9
- package/typedoc.json +0 -4
package/test/s3.test.ts
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import { mockClient } from "aws-sdk-client-mock"
|
|
3
|
-
import { GetObjectCommand, PutObjectCommand } from "@aws-sdk/client-s3"
|
|
4
|
-
import { Readable } from "stream"
|
|
5
|
-
import { sdkStreamMixin } from "@aws-sdk/util-stream-node"
|
|
6
|
-
import { client, getObjectFromS3, putObjectToS3 } from "../src/s3"
|
|
7
|
-
|
|
8
|
-
const s3Mock = mockClient(client)
|
|
9
|
-
|
|
10
|
-
describe("S3", () => {
|
|
11
|
-
describe("putObjectToS3()", () => {
|
|
12
|
-
test("should put object to S3", async () => {
|
|
13
|
-
s3Mock.on(PutObjectCommand).resolves({
|
|
14
|
-
ETag: "etag",
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
const params = {
|
|
18
|
-
bucket: "bucket",
|
|
19
|
-
key: "key",
|
|
20
|
-
body: "body",
|
|
21
|
-
contentEncoding: "content-encoding",
|
|
22
|
-
contentType: "content-type",
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
await expect(putObjectToS3(params)).resolves.toEqual({ ETag: "etag" })
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
test("should fail when put object to S3 fails", async () => {
|
|
29
|
-
s3Mock.on(PutObjectCommand).rejects(new Error("fail"))
|
|
30
|
-
|
|
31
|
-
await expect(putObjectToS3({} as any)).rejects.toThrowError("fail")
|
|
32
|
-
})
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
describe("getObjectFromS3()", () => {
|
|
36
|
-
test("should get object from S3", async () => {
|
|
37
|
-
s3Mock.on(GetObjectCommand).resolves({
|
|
38
|
-
ETag: "etag",
|
|
39
|
-
Body: sdkStreamMixin(Readable.from("object")),
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
const params = {
|
|
43
|
-
bucket: "bucket",
|
|
44
|
-
key: "key",
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const data = (await getObjectFromS3(params)) as any
|
|
48
|
-
|
|
49
|
-
expect(data).toMatchInlineSnapshot(`
|
|
50
|
-
Uint8Array [
|
|
51
|
-
111,
|
|
52
|
-
98,
|
|
53
|
-
106,
|
|
54
|
-
101,
|
|
55
|
-
99,
|
|
56
|
-
116,
|
|
57
|
-
]
|
|
58
|
-
`)
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
test("should fail when get object body is undefined", async () => {
|
|
62
|
-
s3Mock.on(GetObjectCommand).resolves({
|
|
63
|
-
ETag: "etag",
|
|
64
|
-
Body: undefined,
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
await expect(getObjectFromS3({} as any)).rejects.toThrowError(
|
|
68
|
-
"Body not found"
|
|
69
|
-
)
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
test("should fail when get object from S3 fails", async () => {
|
|
73
|
-
s3Mock.on(GetObjectCommand).rejects(new Error("fail"))
|
|
74
|
-
|
|
75
|
-
await expect(getObjectFromS3({} as any)).rejects.toThrowError("fail")
|
|
76
|
-
})
|
|
77
|
-
})
|
|
78
|
-
})
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { mockClient } from "aws-sdk-client-mock"
|
|
2
|
-
import { GetSecretValueCommand } from "@aws-sdk/client-secrets-manager"
|
|
3
|
-
import { client, getSecret, getSecretAsObject } from "../src/secrets-manager"
|
|
4
|
-
|
|
5
|
-
const secretsManagerMock = mockClient(client)
|
|
6
|
-
|
|
7
|
-
describe("secrets-manager", () => {
|
|
8
|
-
describe("getSecret()", () => {
|
|
9
|
-
test("should retrieve secret string", async () => {
|
|
10
|
-
secretsManagerMock.on(GetSecretValueCommand).resolves({
|
|
11
|
-
SecretString: "secret-string",
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
await expect(getSecret("secret-name")).resolves.toBe("secret-string")
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
test("should fail when string empty", async () => {
|
|
18
|
-
secretsManagerMock.on(GetSecretValueCommand).resolves({
|
|
19
|
-
SecretString: "",
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
await expect(getSecret("secret-name")).rejects.toThrow(
|
|
23
|
-
"SecretString value not found"
|
|
24
|
-
)
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
test("should fail", async () => {
|
|
28
|
-
secretsManagerMock.on(GetSecretValueCommand).rejects(new Error("fail"))
|
|
29
|
-
|
|
30
|
-
await expect(getSecret("secret-name")).rejects.toThrowError("fail")
|
|
31
|
-
})
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
describe("getSecretAsObject()", () => {
|
|
35
|
-
test("should return secret object", async () => {
|
|
36
|
-
secretsManagerMock.on(GetSecretValueCommand).resolves({
|
|
37
|
-
SecretString: JSON.stringify({ foo: "bar" }),
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
await expect(getSecretAsObject("secret-name")).resolves.toEqual({
|
|
41
|
-
foo: "bar",
|
|
42
|
-
})
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
test("should fail when invalid object", async () => {
|
|
46
|
-
secretsManagerMock.on(GetSecretValueCommand).resolves({
|
|
47
|
-
SecretString: "invalid-object",
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
await expect(getSecretAsObject("secret-name")).rejects.toThrowError(
|
|
51
|
-
"Cannot parse secret secret-name. Expected JSON."
|
|
52
|
-
)
|
|
53
|
-
})
|
|
54
|
-
})
|
|
55
|
-
})
|
package/test/sns.test.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { SNSClient, PublishCommand } from "@aws-sdk/client-sns"
|
|
2
|
-
import { publishMessageToSNS, snsClient } from "../src/sns"
|
|
3
|
-
|
|
4
|
-
jest.mock("@aws-sdk/client-sns", () => {
|
|
5
|
-
return {
|
|
6
|
-
SNSClient: jest.fn(() => {
|
|
7
|
-
return {
|
|
8
|
-
send: jest.fn(),
|
|
9
|
-
}
|
|
10
|
-
}),
|
|
11
|
-
PublishCommand: jest.fn(),
|
|
12
|
-
}
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
describe("SNS", () => {
|
|
16
|
-
beforeEach(() => {
|
|
17
|
-
;(SNSClient as jest.Mock).mockClear()
|
|
18
|
-
;(PublishCommand as unknown as jest.Mock).mockClear()
|
|
19
|
-
;(snsClient.send as jest.Mock).mockClear()
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
it("should create instance of SNSClient", () => {
|
|
23
|
-
expect(snsClient).toBeDefined()
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
it("should call publishSNSMessage successfully", async () => {
|
|
27
|
-
const sendMock = jest.fn()
|
|
28
|
-
;(snsClient.send as jest.Mock) = sendMock
|
|
29
|
-
|
|
30
|
-
const params = {
|
|
31
|
-
topicArn: "arn:aws:sns:eu-central-1:123456789012:MyTopic",
|
|
32
|
-
message: "Test message",
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
await publishMessageToSNS(params)
|
|
36
|
-
expect(sendMock).toBeCalledTimes(1)
|
|
37
|
-
expect(PublishCommand).toHaveBeenCalledWith({
|
|
38
|
-
TopicArn: params.topicArn,
|
|
39
|
-
Message: params.message,
|
|
40
|
-
})
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
it("should throw an error if publishSNSMessage fails", async () => {
|
|
44
|
-
const sendMock = jest
|
|
45
|
-
.fn()
|
|
46
|
-
.mockRejectedValue(new Error("Failed to send message"))
|
|
47
|
-
;(snsClient.send as jest.Mock) = sendMock
|
|
48
|
-
|
|
49
|
-
const params = {
|
|
50
|
-
topicArn: "arn:aws:sns:euj-central-1:123456789012:MyTopic",
|
|
51
|
-
message: "Test message",
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
await expect(publishMessageToSNS(params)).rejects.toThrow(
|
|
55
|
-
"Failed to send message"
|
|
56
|
-
)
|
|
57
|
-
expect(sendMock).toBeCalledTimes(1)
|
|
58
|
-
})
|
|
59
|
-
})
|
package/test/sqs.test.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { mockClient } from "aws-sdk-client-mock"
|
|
2
|
-
import { SendMessageCommand } from "@aws-sdk/client-sqs"
|
|
3
|
-
import { client, sendSqsMessage } from "../src/sqs"
|
|
4
|
-
|
|
5
|
-
const sqsMock = mockClient(client)
|
|
6
|
-
|
|
7
|
-
describe("sqs", () => {
|
|
8
|
-
describe("sendSqsMessage()", () => {
|
|
9
|
-
test("should send string as message to SQS", async () => {
|
|
10
|
-
sqsMock.on(SendMessageCommand).resolves({
|
|
11
|
-
MessageId: "message-id",
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
const params = {
|
|
15
|
-
queueUrl: "queue-url",
|
|
16
|
-
message: "message",
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
await expect(sendSqsMessage(params)).resolves.toBe("message-id")
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
test("should send stringified object as message to SQS", async () => {
|
|
23
|
-
sqsMock.on(SendMessageCommand).resolves({
|
|
24
|
-
MessageId: "message-id",
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
const params = {
|
|
28
|
-
queueUrl: "queue-url",
|
|
29
|
-
message: { foo: "bar" },
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
await expect(sendSqsMessage(params)).resolves.toBe("message-id")
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
test("should fail", async () => {
|
|
36
|
-
sqsMock.on(SendMessageCommand).rejects(new Error("fail"))
|
|
37
|
-
|
|
38
|
-
const params = {
|
|
39
|
-
queueUrl: "queue-url",
|
|
40
|
-
message: "message",
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
await expect(sendSqsMessage(params)).rejects.toThrowError("fail")
|
|
44
|
-
})
|
|
45
|
-
})
|
|
46
|
-
})
|
package/test/ssm.test.ts
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import { mockClient } from "aws-sdk-client-mock"
|
|
3
|
-
import { GetParametersCommand } from "@aws-sdk/client-ssm"
|
|
4
|
-
import { client, getSsmParameters } from "../src/ssm"
|
|
5
|
-
|
|
6
|
-
const ssmMock = mockClient(client)
|
|
7
|
-
|
|
8
|
-
describe("ssm", () => {
|
|
9
|
-
describe("getSsmParameters()", () => {
|
|
10
|
-
test("should return paramaters", async () => {
|
|
11
|
-
ssmMock.on(GetParametersCommand).resolves({
|
|
12
|
-
Parameters: [
|
|
13
|
-
{ Name: "/my-params/foo", Value: "bar" },
|
|
14
|
-
{ Name: "/my-params/baz", Value: "qux" },
|
|
15
|
-
],
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
const params = {
|
|
19
|
-
foo: "/my-params/foo",
|
|
20
|
-
baz: "/my-params/baz",
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
await expect(getSsmParameters(params)).resolves.toEqual({
|
|
24
|
-
foo: "bar",
|
|
25
|
-
baz: "qux",
|
|
26
|
-
})
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
test("should fail when SSM parameter name is not string", async () => {
|
|
30
|
-
ssmMock.on(GetParametersCommand).resolves({
|
|
31
|
-
Parameters: [{ Name: 42 as any, Value: "bar" }],
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
const params = {
|
|
35
|
-
foo: "/my-params/foo",
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
await expect(getSsmParameters(params)).rejects.toThrow(
|
|
39
|
-
"Received invalid SSM parameter 42"
|
|
40
|
-
)
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
test("should fail when SSM parameter does not contain Parameters", async () => {
|
|
44
|
-
ssmMock.on(GetParametersCommand).resolves({})
|
|
45
|
-
|
|
46
|
-
const params = {
|
|
47
|
-
foo: "/my-params/foo",
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
await expect(getSsmParameters(params)).rejects.toThrow(
|
|
51
|
-
"Cannot obtain SSM parameters: foo"
|
|
52
|
-
)
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
test("should fail when SSM parameter value is not string", async () => {
|
|
56
|
-
ssmMock.on(GetParametersCommand).resolves({
|
|
57
|
-
Parameters: [{ Name: "/my-params/foo", Value: 42 as any }],
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
const params = {
|
|
61
|
-
foo: "/my-params/foo",
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
await expect(getSsmParameters(params)).rejects.toThrow(
|
|
65
|
-
"Received invalid value of SSM parameter /my-params/foo"
|
|
66
|
-
)
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
test("should fail when not all parameters are found", async () => {
|
|
70
|
-
ssmMock.on(GetParametersCommand).resolves({
|
|
71
|
-
Parameters: [{ Name: "/my-params/foo", Value: "bar" }],
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
const params = {
|
|
75
|
-
foo: "/my-params/foo",
|
|
76
|
-
baz: "/my-params/baz",
|
|
77
|
-
quux: "/my-params/quux",
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
await expect(getSsmParameters(params)).rejects.toThrow(
|
|
81
|
-
"Cannot obtain SSM parameters: baz, quux"
|
|
82
|
-
)
|
|
83
|
-
})
|
|
84
|
-
})
|
|
85
|
-
})
|
package/tsconfig.build.json
DELETED
package/tsconfig.json
DELETED
package/typedoc.json
DELETED