@gov-cy/govcy-express-services 1.0.0-alpha.2 → 1.0.0-alpha.5
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/README.md
CHANGED
|
@@ -494,7 +494,9 @@ Content-Type: application/json
|
|
|
494
494
|
The API is expected to return a JSON response with the following structure (see [govcyApiRequest.mjs](src/utils/govcyApiRequest.mjs) for normalization):
|
|
495
495
|
|
|
496
496
|
**On Success:**
|
|
497
|
-
```
|
|
497
|
+
```http
|
|
498
|
+
HTTP/1.1 200 OK
|
|
499
|
+
|
|
498
500
|
{
|
|
499
501
|
"Succeeded": true,
|
|
500
502
|
"ErrorCode": 0,
|
|
@@ -503,7 +505,9 @@ The API is expected to return a JSON response with the following structure (see
|
|
|
503
505
|
```
|
|
504
506
|
|
|
505
507
|
**On Failure:**
|
|
506
|
-
```
|
|
508
|
+
```http
|
|
509
|
+
HTTP/1.1 200 OK
|
|
510
|
+
|
|
507
511
|
{
|
|
508
512
|
"Succeeded": false,
|
|
509
513
|
"ErrorCode": 102,
|
|
@@ -637,7 +641,9 @@ Content-Type: application/json
|
|
|
637
641
|
The API is expected to return a JSON response with the following structure (see [govcyApiRequest.mjs](src/utils/govcyApiRequest.mjs) for normalization):
|
|
638
642
|
|
|
639
643
|
**On Success:**
|
|
640
|
-
```
|
|
644
|
+
```http
|
|
645
|
+
HTTP/1.1 200 OK
|
|
646
|
+
|
|
641
647
|
{
|
|
642
648
|
"Succeeded": true,
|
|
643
649
|
"ErrorCode": 0,
|
|
@@ -649,7 +655,9 @@ The API is expected to return a JSON response with the following structure (see
|
|
|
649
655
|
```
|
|
650
656
|
|
|
651
657
|
**On Failure:**
|
|
652
|
-
```
|
|
658
|
+
```http
|
|
659
|
+
HTTP/1.1 200 OK
|
|
660
|
+
|
|
653
661
|
{
|
|
654
662
|
"Succeeded": false,
|
|
655
663
|
"ErrorCode": 102,
|
|
@@ -1492,7 +1500,9 @@ The API is expected to return a JSON response with the following structure:
|
|
|
1492
1500
|
|
|
1493
1501
|
**When temporary submission data are found:**
|
|
1494
1502
|
|
|
1495
|
-
```
|
|
1503
|
+
```http
|
|
1504
|
+
HTTP/1.1 200 OK
|
|
1505
|
+
|
|
1496
1506
|
{
|
|
1497
1507
|
"Succeeded": true,
|
|
1498
1508
|
"ErrorCode": 0,
|
|
@@ -1505,7 +1515,9 @@ The API is expected to return a JSON response with the following structure:
|
|
|
1505
1515
|
|
|
1506
1516
|
**When temporary submission data are NOT found:**
|
|
1507
1517
|
|
|
1508
|
-
```
|
|
1518
|
+
```http
|
|
1519
|
+
HTTP/1.1 404 Not Found
|
|
1520
|
+
|
|
1509
1521
|
{
|
|
1510
1522
|
"Succeeded": true,
|
|
1511
1523
|
"ErrorCode": 0,
|
|
@@ -1516,7 +1528,9 @@ The API is expected to return a JSON response with the following structure:
|
|
|
1516
1528
|
|
|
1517
1529
|
**When temporary submission retreival fails:**
|
|
1518
1530
|
|
|
1519
|
-
```
|
|
1531
|
+
```http
|
|
1532
|
+
HTTP/1.1 200 OK
|
|
1533
|
+
|
|
1520
1534
|
{
|
|
1521
1535
|
"Succeeded": false,
|
|
1522
1536
|
"ErrorCode": 401,
|
|
@@ -1561,7 +1575,9 @@ The API is expected to return a JSON response with the following structure:
|
|
|
1561
1575
|
|
|
1562
1576
|
**On success:**
|
|
1563
1577
|
|
|
1564
|
-
```
|
|
1578
|
+
```http
|
|
1579
|
+
HTTP/1.1 200 OK
|
|
1580
|
+
|
|
1565
1581
|
{
|
|
1566
1582
|
"Succeeded": true,
|
|
1567
1583
|
"ErrorCode": 0,
|
|
@@ -1574,7 +1590,9 @@ The API is expected to return a JSON response with the following structure:
|
|
|
1574
1590
|
|
|
1575
1591
|
**On failure:**
|
|
1576
1592
|
|
|
1577
|
-
```
|
|
1593
|
+
```http
|
|
1594
|
+
HTTP/1.1 401 Unauthorized
|
|
1595
|
+
|
|
1578
1596
|
{
|
|
1579
1597
|
"Succeeded": false,
|
|
1580
1598
|
"ErrorCode": 401,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gov-cy/govcy-express-services",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.5",
|
|
4
4
|
"description": "An Express-based system that dynamically renders services using @gov-cy/govcy-frontend-renderer and posts data to a submission API.",
|
|
5
5
|
"author": "DMRID - DSF Team",
|
|
6
6
|
"license": "MIT",
|
|
@@ -11,6 +11,7 @@ import { logger } from "./govcyLogger.mjs";
|
|
|
11
11
|
* @param {object} headers - Custom headers (optional)
|
|
12
12
|
* @param {number} retries - Number of retry attempts (default: 3)
|
|
13
13
|
* @param {boolean} allowSelfSignedCerts - Whether to allow self-signed certificates (default: false)
|
|
14
|
+
* @param {array} allowedHTTPStatusCodes - Array of allowed HTTP status codes (default: [200])
|
|
14
15
|
* @returns {Promise<object>} - API response
|
|
15
16
|
*/
|
|
16
17
|
export async function govcyApiRequest(
|
|
@@ -21,7 +22,8 @@ export async function govcyApiRequest(
|
|
|
21
22
|
user = null,
|
|
22
23
|
headers = {},
|
|
23
24
|
retries = 3,
|
|
24
|
-
allowSelfSignedCerts = false
|
|
25
|
+
allowSelfSignedCerts = false,
|
|
26
|
+
allowedHTTPStatusCodes = [200]
|
|
25
27
|
) {
|
|
26
28
|
let attempt = 0;
|
|
27
29
|
|
|
@@ -48,6 +50,8 @@ export async function govcyApiRequest(
|
|
|
48
50
|
[method?.toLowerCase() === 'get' ? 'params' : 'data']: inputData,
|
|
49
51
|
headers: requestHeaders,
|
|
50
52
|
timeout: 10000, // 10 seconds timeout
|
|
53
|
+
// ✅ Treat only these statuses as "resolved" (no throw)
|
|
54
|
+
validateStatus: (status) => allowedHTTPStatusCodes.includes(status),
|
|
51
55
|
};
|
|
52
56
|
|
|
53
57
|
// Add httpsAgent if NOT production to allow self-signed certificates
|
|
@@ -60,9 +64,13 @@ export async function govcyApiRequest(
|
|
|
60
64
|
|
|
61
65
|
logger.debug(`📥 Received API response`, { status: response.status, data: response.data });
|
|
62
66
|
|
|
63
|
-
|
|
67
|
+
// Validate HTTP status
|
|
68
|
+
if (!allowedHTTPStatusCodes.includes(response.status)) {
|
|
64
69
|
throw new Error(`Unexpected HTTP status: ${response.status}`);
|
|
65
70
|
}
|
|
71
|
+
// if (response.status !== 200) {
|
|
72
|
+
// throw new Error(`Unexpected HTTP status: ${response.status}`);
|
|
73
|
+
// }
|
|
66
74
|
|
|
67
75
|
// const { Succeeded, ErrorCode, ErrorMessage } = response.data;
|
|
68
76
|
// Normalize to PascalCase regardless of input case
|
|
@@ -77,7 +85,7 @@ export async function govcyApiRequest(
|
|
|
77
85
|
ErrorMessage,
|
|
78
86
|
Data,
|
|
79
87
|
InformationMessage
|
|
80
|
-
} = response.data;
|
|
88
|
+
} = response.data ?? {};
|
|
81
89
|
|
|
82
90
|
const normalized = {
|
|
83
91
|
Succeeded: Succeeded !== undefined ? Succeeded : succeeded,
|
|
@@ -73,7 +73,8 @@ export async function govcyLoadSubmissionDataAPIs(store, service, siteId, next)
|
|
|
73
73
|
...(getCfgDsfGtwApiKey !== '' && { "dsfgtw-api-key": getCfgDsfGtwApiKey }) // Use the DSF API GTW secret from environment variables
|
|
74
74
|
},
|
|
75
75
|
3,
|
|
76
|
-
allowSelfSignedCerts
|
|
76
|
+
allowSelfSignedCerts,
|
|
77
|
+
[200, 404] // Allowed HTTP status codes
|
|
77
78
|
);
|
|
78
79
|
|
|
79
80
|
// If not succeeded, handle error
|
|
@@ -88,7 +89,9 @@ export async function govcyLoadSubmissionDataAPIs(store, service, siteId, next)
|
|
|
88
89
|
dataLayer.storeSiteLoadData(store, siteId, getResponse.Data);
|
|
89
90
|
|
|
90
91
|
try {
|
|
91
|
-
const parsed = JSON.parse(getResponse.Data.submissionData
|
|
92
|
+
const parsed = JSON.parse(getResponse.Data.submissionData
|
|
93
|
+
|| getResponse.Data.submission_data
|
|
94
|
+
|| "{}");
|
|
92
95
|
if (parsed && typeof parsed === "object") {
|
|
93
96
|
dataLayer.storeSiteInputData(store, siteId, parsed);
|
|
94
97
|
logger.debug(`💾 Input data restored from saved submission for siteId: ${siteId}`);
|
|
@@ -99,11 +102,15 @@ export async function govcyLoadSubmissionDataAPIs(store, service, siteId, next)
|
|
|
99
102
|
|
|
100
103
|
// if not call the PUT submission API
|
|
101
104
|
} else {
|
|
105
|
+
const tempPutPayload = {
|
|
106
|
+
// submission_data: JSON.stringify({}),
|
|
107
|
+
submissionData: JSON.stringify({})
|
|
108
|
+
};
|
|
102
109
|
// If no data, call the PUT submission API to create it
|
|
103
110
|
const putResponse = await govcyApiRequest(
|
|
104
111
|
putCfgMethod,
|
|
105
112
|
putCfgUrl,
|
|
106
|
-
|
|
113
|
+
tempPutPayload,
|
|
107
114
|
true, // use access token auth
|
|
108
115
|
user,
|
|
109
116
|
{
|
|
@@ -27,7 +27,8 @@ export async function tempSaveIfConfigured(store, service, siteId) {
|
|
|
27
27
|
const inputData = dataLayer.getSiteInputData(store, siteId) || {};
|
|
28
28
|
const tempPayload = {
|
|
29
29
|
// mirror final submission format: send stringified JSON
|
|
30
|
-
submission_data: JSON.stringify(inputData)
|
|
30
|
+
// submission_data: JSON.stringify(inputData),
|
|
31
|
+
submissionData: JSON.stringify(inputData)
|
|
31
32
|
};
|
|
32
33
|
|
|
33
34
|
if (!url || !clientKey) {
|