@defra/grants-config-utils 0.4.0 → 0.5.0
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/.github/dependabot.yml +2 -0
- package/.github/workflows/check-pull-request.yml +2 -2
- package/.github/workflows/release.yml +2 -2
- package/AGENTS.md +29 -0
- package/CHANGELOG.md +6 -0
- package/CONTEXT.md +33 -0
- package/package.json +9 -9
- package/src/sns/sns-client.js +31 -0
- package/src/sns/sns-client.test.js +73 -1
package/.github/dependabot.yml
CHANGED
|
@@ -18,7 +18,7 @@ jobs:
|
|
|
18
18
|
name: Run Pull Request Checks
|
|
19
19
|
runs-on: ubuntu-latest
|
|
20
20
|
steps:
|
|
21
|
-
- uses: actions/checkout@
|
|
21
|
+
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 #v7.0.0
|
|
22
22
|
with:
|
|
23
23
|
fetch-depth: 0
|
|
24
24
|
|
|
@@ -46,7 +46,7 @@ jobs:
|
|
|
46
46
|
- name: SonarCloud Scan
|
|
47
47
|
if: github.actor != 'dependabot[bot]' &&
|
|
48
48
|
!startsWith(github.head_ref, 'changeset-release/')
|
|
49
|
-
uses: SonarSource/sonarqube-scan-action@
|
|
49
|
+
uses: SonarSource/sonarqube-scan-action@713881670b6b3676cda39549040e2d88c70d582e #8.2.0
|
|
50
50
|
env:
|
|
51
51
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
52
52
|
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
|
@@ -25,7 +25,7 @@ jobs:
|
|
|
25
25
|
|
|
26
26
|
steps:
|
|
27
27
|
- name: Checkout repository
|
|
28
|
-
uses: actions/checkout@
|
|
28
|
+
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 #v7.0.0
|
|
29
29
|
with:
|
|
30
30
|
fetch-depth: 0
|
|
31
31
|
fetch-tags: true
|
|
@@ -44,7 +44,7 @@ jobs:
|
|
|
44
44
|
|
|
45
45
|
- name: SonarCloud Scan
|
|
46
46
|
if: github.actor != 'dependabot[bot]' && github.actor != 'github-actions[bot]' && !contains(github.event.head_commit.message, 'Create new config version')
|
|
47
|
-
uses: SonarSource/sonarqube-scan-action@
|
|
47
|
+
uses: SonarSource/sonarqube-scan-action@713881670b6b3676cda39549040e2d88c70d582e #8.2.0
|
|
48
48
|
env:
|
|
49
49
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
50
50
|
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
package/AGENTS.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Repository Guidelines
|
|
2
|
+
|
|
3
|
+
## Project Structure & Module Organization
|
|
4
|
+
|
|
5
|
+
Shared grants configuration utility code lives in `src/`. Tests are colocated as `*.test.js`. Release notes are managed through `.changeset/`.
|
|
6
|
+
|
|
7
|
+
## Build, Test, and Development Commands
|
|
8
|
+
|
|
9
|
+
- `npm install`: install dependencies and set up Husky.
|
|
10
|
+
- `npm test`: run Vitest with coverage.
|
|
11
|
+
- `npm run lint` / `npm run lint:fix`: check or fix linting.
|
|
12
|
+
- `npm run format:check` / `npm run format`: check or apply formatting.
|
|
13
|
+
- `npm run version`: create a Changeset when changing the published package contract.
|
|
14
|
+
|
|
15
|
+
## Coding Style & Naming Conventions
|
|
16
|
+
|
|
17
|
+
Use ES modules and the local Prettier/ESLint settings. Keep utilities small, named after the configuration concept they operate on, and avoid service-specific behaviour in shared helpers.
|
|
18
|
+
|
|
19
|
+
## Domain Language
|
|
20
|
+
|
|
21
|
+
Use `CONTEXT.md` as the source of truth for shared grants configuration utility language. Prefer those terms in APIs, tests, docs, and generated changes.
|
|
22
|
+
|
|
23
|
+
## Developer Addenda
|
|
24
|
+
|
|
25
|
+
Developers can add their own `AGENTS.local.md` and should be read as an addendum to this file. Keep that file local to your machine and do not commit it.
|
|
26
|
+
|
|
27
|
+
## Testing Guidelines
|
|
28
|
+
|
|
29
|
+
Add or update focused unit tests with shared utility changes. Run the relevant Vitest file, then `npm test`, `npm run lint`, and `npm run format:check`.
|
package/CHANGELOG.md
CHANGED
package/CONTEXT.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# grants-config-utils
|
|
2
|
+
|
|
3
|
+
Shared utilities for validating, reading, transforming, and publishing grants configuration.
|
|
4
|
+
|
|
5
|
+
## Language
|
|
6
|
+
|
|
7
|
+
**Grant configuration**
|
|
8
|
+
The files that define a grant journey, release metadata, or integration payload.
|
|
9
|
+
_Avoid_: Application state, User answers, Runtime settings
|
|
10
|
+
|
|
11
|
+
**Configuration utility**
|
|
12
|
+
A reusable helper for configuration repositories or the config broker.
|
|
13
|
+
_Avoid_: Service feature, CLI command unless it is directly executable
|
|
14
|
+
|
|
15
|
+
**Manifest**
|
|
16
|
+
The list of configuration file paths that make up a release.
|
|
17
|
+
_Avoid_: Sitemap, Package lock, Index page
|
|
18
|
+
|
|
19
|
+
**Version**
|
|
20
|
+
The release identifier for a configuration package or grant configuration.
|
|
21
|
+
_Avoid_: Build number, Commit SHA, Timestamp
|
|
22
|
+
|
|
23
|
+
**Status**
|
|
24
|
+
The release state for a version, such as `draft` or `active`.
|
|
25
|
+
_Avoid_: Application status, HTTP status, Test status
|
|
26
|
+
|
|
27
|
+
**Validation**
|
|
28
|
+
Checks that configuration is structurally correct before it is published or consumed.
|
|
29
|
+
_Avoid_: User input validation, Browser validation, Linting unless referring to code style
|
|
30
|
+
|
|
31
|
+
**Changeset**
|
|
32
|
+
The release note/version marker required when changing the published package contract.
|
|
33
|
+
_Avoid_: Changelog entry when the `.changeset` file is meant, Commit message
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defra/grants-config-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "NPM module for providing utils for publishing grants config",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=24",
|
|
@@ -41,24 +41,24 @@
|
|
|
41
41
|
},
|
|
42
42
|
"homepage": "https://github.com/DEFRA/grants-config-utils#readme",
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@aws-sdk/client-s3": "3.
|
|
45
|
-
"@aws-sdk/client-sns": "3.
|
|
44
|
+
"@aws-sdk/client-s3": "3.1078.0",
|
|
45
|
+
"@aws-sdk/client-sns": "3.1078.0",
|
|
46
46
|
"convict": "6.2.5",
|
|
47
47
|
"convict-format-with-validator": "6.2.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@babel/core": "7.29.
|
|
51
|
-
"@babel/preset-env": "7.29.
|
|
50
|
+
"@babel/core": "7.29.7",
|
|
51
|
+
"@babel/preset-env": "7.29.7",
|
|
52
52
|
"@changesets/changelog-github": "0.7.0",
|
|
53
53
|
"@changesets/cli": "2.31.0",
|
|
54
|
-
"@vitest/coverage-v8": "4.1.
|
|
54
|
+
"@vitest/coverage-v8": "4.1.9",
|
|
55
55
|
"eslint": "9.39.4",
|
|
56
56
|
"eslint-config-prettier": "10.1.1",
|
|
57
57
|
"husky": "9.1.7",
|
|
58
|
-
"lint-staged": "17.0.
|
|
58
|
+
"lint-staged": "17.0.8",
|
|
59
59
|
"neostandard": "0.13.0",
|
|
60
|
-
"prettier": "3.8.
|
|
61
|
-
"vitest": "4.1.
|
|
60
|
+
"prettier": "3.8.4",
|
|
61
|
+
"vitest": "4.1.9",
|
|
62
62
|
"vitest-fetch-mock": "0.4.5"
|
|
63
63
|
},
|
|
64
64
|
"release-it": {
|
package/src/sns/sns-client.js
CHANGED
|
@@ -46,6 +46,37 @@ export const publishMessage = async (
|
|
|
46
46
|
);
|
|
47
47
|
};
|
|
48
48
|
|
|
49
|
+
export const publishFIFOMessage = async (
|
|
50
|
+
data,
|
|
51
|
+
groupId,
|
|
52
|
+
groupDeduplicationId,
|
|
53
|
+
messageAttributes = {},
|
|
54
|
+
topic = defaultTopic,
|
|
55
|
+
) => {
|
|
56
|
+
if (!clientSetup) {
|
|
57
|
+
throw new Error(
|
|
58
|
+
"SNS client not setup. Call setupClient() before publishing messages.",
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
if (!groupId || !groupDeduplicationId) {
|
|
62
|
+
throw new Error(
|
|
63
|
+
"SNS client cannot be used to send FIFO messages without both groupId and groupDeduplicationId.",
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
loggerInstance.info(
|
|
67
|
+
`Publish FIFO notification to ${topic} for groupId ${groupId} and groupDeduplicationId ${groupDeduplicationId}`,
|
|
68
|
+
);
|
|
69
|
+
await snsClient.send(
|
|
70
|
+
new PublishCommand({
|
|
71
|
+
TopicArn: topic,
|
|
72
|
+
Message: JSON.stringify(data),
|
|
73
|
+
MessageAttributes: convertMessageAttributes(messageAttributes),
|
|
74
|
+
MessageGroupId: groupId,
|
|
75
|
+
MessageDeduplicationId: groupDeduplicationId,
|
|
76
|
+
}),
|
|
77
|
+
);
|
|
78
|
+
};
|
|
79
|
+
|
|
49
80
|
/* Converts a simple key-value object into the format required by SNS for message attributes.
|
|
50
81
|
Note only supports string values currently
|
|
51
82
|
Example input: { key1: "value1", key2: "value2" }
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { PublishCommand, SNSClient } from "@aws-sdk/client-sns";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
isClientSetup,
|
|
4
|
+
publishFIFOMessage,
|
|
5
|
+
publishMessage,
|
|
6
|
+
setupClient,
|
|
7
|
+
} from "./sns-client.js";
|
|
3
8
|
import { config } from "../config/config.js";
|
|
4
9
|
|
|
5
10
|
vi.mock("./metrics.js");
|
|
@@ -75,6 +80,73 @@ describe("publish", () => {
|
|
|
75
80
|
});
|
|
76
81
|
});
|
|
77
82
|
|
|
83
|
+
it("publishes a FIFO message to a topic", async () => {
|
|
84
|
+
const message = {
|
|
85
|
+
key: "value",
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const send = vi.fn();
|
|
89
|
+
|
|
90
|
+
SNSClient.mockImplementation(function () {
|
|
91
|
+
return { send };
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
PublishCommand.mockImplementation(function (params) {
|
|
95
|
+
return params;
|
|
96
|
+
});
|
|
97
|
+
setupClient(mockLogger, {
|
|
98
|
+
region: "us-east-1",
|
|
99
|
+
awsEndpointUrl: "http://localhost:4566",
|
|
100
|
+
publishToTopic: topicArn,
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
expect(isClientSetup()).toBe(true);
|
|
104
|
+
|
|
105
|
+
await publishFIFOMessage(message, "MY_GROUP", "MY_DEDUPLICATION_ID");
|
|
106
|
+
|
|
107
|
+
expect(PublishCommand).toHaveBeenCalledWith({
|
|
108
|
+
TopicArn: topicArn,
|
|
109
|
+
Message: '{"key":"value"}',
|
|
110
|
+
MessageAttributes: {},
|
|
111
|
+
MessageGroupId: "MY_GROUP",
|
|
112
|
+
MessageDeduplicationId: "MY_DEDUPLICATION_ID",
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
expect(send).toHaveBeenCalledWith({
|
|
116
|
+
TopicArn: topicArn,
|
|
117
|
+
Message: '{"key":"value"}',
|
|
118
|
+
MessageAttributes: {},
|
|
119
|
+
MessageGroupId: "MY_GROUP",
|
|
120
|
+
MessageDeduplicationId: "MY_DEDUPLICATION_ID",
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("error thrown if missing FIFO attributes when sending FIFO message", async () => {
|
|
125
|
+
const message = {
|
|
126
|
+
key: "value",
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const send = vi.fn();
|
|
130
|
+
|
|
131
|
+
SNSClient.mockImplementation(function () {
|
|
132
|
+
return { send };
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
setupClient(mockLogger, {
|
|
136
|
+
region: "us-east-1",
|
|
137
|
+
awsEndpointUrl: "http://localhost:4566",
|
|
138
|
+
publishToTopic: topicArn,
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
await expect(publishFIFOMessage(message)).rejects.toThrow(
|
|
142
|
+
"SNS client cannot be used to send FIFO messages without both groupId and groupDeduplicationId.",
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
expect(PublishCommand).toHaveBeenCalledTimes(0);
|
|
146
|
+
|
|
147
|
+
expect(send).toHaveBeenCalledTimes(0);
|
|
148
|
+
});
|
|
149
|
+
|
|
78
150
|
it("publishes a message including custom message attribute", async () => {
|
|
79
151
|
const message = {
|
|
80
152
|
key: "value",
|