@defra/grants-reporting-publisher 0.1.0 → 0.1.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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @defra/grants-reporting-publisher
2
2
 
3
+ ## 0.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - f8be355: Update readme with examples
8
+
3
9
  ## 0.1.0
4
10
 
5
11
  ### Minor Changes
package/EXAMPLES.md ADDED
@@ -0,0 +1,127 @@
1
+ # Usage Examples
2
+
3
+ This page provides examples of how to use the `@defra/grants-reporting-publisher` library to publish reporting events.
4
+
5
+ ## Configuration
6
+
7
+ To publish events, you need to provide a configuration object that includes an AWS SNS client and the target topic ARN.
8
+
9
+ ```javascript
10
+ import { SNSClient } from "@aws-sdk/client-sns";
11
+ import {
12
+ publishReportingEvent,
13
+ AGREEMENT_CREATED,
14
+ AGREEMENT_STATUS_CHANGED,
15
+ } from "@defra/grants-reporting-publisher";
16
+
17
+ const snsClient = new SNSClient({ region: "eu-west-2" });
18
+
19
+ const config = {
20
+ snsClient,
21
+ sns: {
22
+ topicArn: "arn:aws:sns:eu-west-2:123456789012:your-topic-name",
23
+ },
24
+ application: "YOUR_APPLICATION_CODE", // e.g., "GAS or grants-payments-service"
25
+ service: "your-service-name", // optional, defaults to "grants", just omit this for now
26
+ generateCorrelationId: true, // automatically generate a UUID for each event
27
+ };
28
+ ```
29
+
30
+ ## Event Types
31
+
32
+ ### Agreement Created (`AGREEMENT_CREATED`)
33
+
34
+ Use this event type when a new agreement is created.
35
+
36
+ ```javascript
37
+ const agreementCreatedEvent = {
38
+ eventData: {
39
+ eventType: AGREEMENT_CREATED,
40
+ agreementId: "AG-123456",
41
+ agreementType: "WOODLAND",
42
+ agreementStatus: "ACCEPTED",
43
+ agreementStartDate: "2026-01-01",
44
+ agreementEndDate: "2031-12-31",
45
+ agreementValue: 50000.0,
46
+ sbi: "200000001",
47
+ options: [
48
+ {
49
+ parcelReference: "SD8545-9935",
50
+ parcelSizeUnderAgreement: 10.5,
51
+ optionCode: "WD1",
52
+ optionYear: 1,
53
+ optionStartDate: "2026-01-01",
54
+ optionEndDate: "2026-12-31",
55
+ optionQuantity: 10.5,
56
+ optionValue: 10500.0,
57
+ },
58
+ ],
59
+ },
60
+ };
61
+
62
+ try {
63
+ const { messageId } = await publishReportingEvent(
64
+ agreementCreatedEvent,
65
+ config,
66
+ );
67
+ console.log(`Event published with Message ID: ${messageId}`);
68
+ } catch (error) {
69
+ console.error("Failed to publish event:", error.message);
70
+ }
71
+ ```
72
+
73
+ ### Agreement Status Changed (`AGREEMENT_STATUS_CHANGED`)
74
+
75
+ Use this event type when the status of an existing agreement changes.
76
+
77
+ ```javascript
78
+ const statusChangedEvent = {
79
+ eventData: {
80
+ eventType: AGREEMENT_STATUS_CHANGED,
81
+ agreementId: "AG-123456",
82
+ agreementStatus: "COMPLETED",
83
+ statusDate: new Date().toISOString(),
84
+ agreementStartDate: "2026-01-01",
85
+ agreementEndDate: "2031-12-31",
86
+ agreementValue: 50000.0,
87
+ userId: "user-uuid-123", // optional
88
+ },
89
+ };
90
+
91
+ try {
92
+ const { messageId } = await publishReportingEvent(statusChangedEvent, config);
93
+ console.log(`Event published with Message ID: ${messageId}`);
94
+ } catch (error) {
95
+ console.error("Failed to publish event:", error.message);
96
+ }
97
+ ```
98
+
99
+ ## Validation Only
100
+
101
+ If you only want to validate an event without publishing it:
102
+
103
+ ```javascript
104
+ import { validateReportingEvent } from "@defra/grants-reporting-publisher";
105
+
106
+ const event = {
107
+ correlationId: "your-correlation-id",
108
+ datetime: new Date().toISOString(),
109
+ version: "1.0.0",
110
+ application: "FCP",
111
+ service: "grants",
112
+ eventData: {
113
+ eventType: AGREEMENT_STATUS_CHANGED,
114
+ agreementId: "AG-123",
115
+ agreementStatus: "ACTIVE",
116
+ statusDate: new Date().toISOString(),
117
+ },
118
+ };
119
+
120
+ const { valid, errors, value } = validateReportingEvent(event);
121
+
122
+ if (!valid) {
123
+ console.error("Validation errors:", errors);
124
+ } else {
125
+ console.log("Event is valid:", value);
126
+ }
127
+ ```
package/README.md CHANGED
@@ -4,6 +4,8 @@ NPM module for providing validation and publishing capability for grants reporti
4
4
 
5
5
  ## Usage
6
6
 
7
+ Refer to the [Usage Examples](EXAMPLES.md) for detailed examples of how to publish reporting events.
8
+
7
9
  ### Installation
8
10
 
9
11
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defra/grants-reporting-publisher",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "NPM module for publishing grants reporting events",
5
5
  "engines": {
6
6
  "node": ">=24",