@gov-cy/govcy-express-services 1.0.0-alpha.1 → 1.0.0-alpha.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.
Files changed (2) hide show
  1. package/README.md +134 -7
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1419,8 +1419,8 @@ Explanation:
1419
1419
  The **temporary save** feature allows user progress to be stored in an external API and automatically reloaded on the next visit.
1420
1420
  This is useful for long forms or cases where users may leave and return later.
1421
1421
 
1422
- #### 1. Configure the endpoints in your service JSON
1423
- In your service’s `site` object, add both a `submissionGetAPIEndpoint` and `submissionPutAPIEndpoint` entry:
1422
+ #### How to configure temporary save
1423
+ To use this feature, configure the config JSON file. In your service’s `site` object, add both a `submissionGetAPIEndpoint` and `submissionPutAPIEndpoint` entry:
1424
1424
 
1425
1425
  ```json
1426
1426
  "submissionGetAPIEndpoint": {
@@ -1439,7 +1439,6 @@ In your service’s `site` object, add both a `submissionGetAPIEndpoint` and `su
1439
1439
 
1440
1440
  These values should point to environment variables that hold your real endpoint URLs and credentials.
1441
1441
 
1442
- #### 2. Add environment variables
1443
1442
  In your `secrets/.env` file (and staging/production configs), define the variables referenced above:
1444
1443
 
1445
1444
  ```dotenv
@@ -1449,17 +1448,145 @@ TEST_SUBMISSION_API_CLIENT_KEY=12345678901234567890123456789000
1449
1448
  TEST_SUBMISSION_API_SERVICE_ID=123
1450
1449
  ```
1451
1450
 
1452
- #### 3. How it works
1451
+ #### How temporary save works
1453
1452
 
1454
- - **On first page load** for a site, `govcyLoadSubmissionData` will:
1453
+ - **On first page load** for a site, using the `submissionGetAPIEndpoint` the system will:
1455
1454
  1. Call the GET endpoint to retrieve any saved submission.
1456
1455
  2. If found, populate the session’s `inputData` so fields are pre-filled.
1457
1456
  3. If not found, call the PUT endpoint to create a new temporary record.
1458
1457
  - **On every form POST**, after successful validation:
1459
- - The `govcyFormsPostHandler` will fire-and-forget a `PUT` request to update the saved submission with the latest form data.
1458
+ - The `submissionPutAPIEndpoint` will fire-and-forget a `PUT` request to update the saved submission with the latest form data.
1460
1459
  - The payload includes all required submission fields with `submission_data` JSON-stringified.
1461
1460
 
1462
- #### 4. Backward compatibility
1461
+ #### `submissionGetAPIEndpoint` `GET` API Request and Response
1462
+ This API is used to retrieve the saved submission data.
1463
+
1464
+ **Request:**
1465
+
1466
+ - **HTTP Method**: GET
1467
+ - **URL**: Resolved from the url property in your config (from the environment variable).
1468
+ - **Headers**:
1469
+ - **Authorization**: `Bearer <access_token>` (form user's cyLogin access token)
1470
+ - **client-key**: `<clientKey>` (from config/env)
1471
+ - **service-id**: `<serviceId>` (from config/env)
1472
+ - **Accept**: `text/plain`
1473
+ - **Body**: The body contains the and either:
1474
+ - an a `null` which means no data was found for the user
1475
+ - a JSON object with all the form data collected from the user across all pages in previous sessions.
1476
+
1477
+ **Example Request:**
1478
+
1479
+ ```http
1480
+ GET /temp-save-get-endpoint?status=0 HTTP/1.1
1481
+ Host: localhost:3002
1482
+ Authorization: Bearer eyJhbGciOi...
1483
+ client-key: 12345678901234567890123456789000
1484
+ service-id: 123
1485
+ Accept: text/plain
1486
+ Content-Type: application/json
1487
+ ```
1488
+
1489
+ **Response:**
1490
+
1491
+ The API is expected to return a JSON response with the following structure:
1492
+
1493
+ **When temporary submission data are found:**
1494
+
1495
+ ```json
1496
+ {
1497
+ "Succeeded": true,
1498
+ "ErrorCode": 0,
1499
+ "ErrorMessage": null,
1500
+ "Data": {
1501
+ "submissionData": "{\"index\":{\"formData\":{\"certificate_select\":[\"birth\",\"permanent_residence\"]}},\"data-entry-radios\":{\"formData\":{\"mobile_select\":\"other\",\"mobileTxt\":\"+35799484967\"}}}"
1502
+ }
1503
+ }
1504
+ ```
1505
+
1506
+ **When temporary submission data are NOT found:**
1507
+
1508
+ ```json
1509
+ {
1510
+ "Succeeded": true,
1511
+ "ErrorCode": 0,
1512
+ "ErrorMessage": null,
1513
+ "Data": null
1514
+ }
1515
+ ```
1516
+
1517
+ **When temporary submission retreival fails:**
1518
+
1519
+ ```json
1520
+ {
1521
+ "Succeeded": false,
1522
+ "ErrorCode": 401,
1523
+ "ErrorMessage": "Not authorized",
1524
+ "Data": null
1525
+ }
1526
+ ```
1527
+
1528
+ #### `submissionPutAPIEndpoint` `PUT` API Request and Response
1529
+ This API is used to temporary save the submission data.
1530
+
1531
+ **Request:**
1532
+
1533
+ - **HTTP Method**: PUT
1534
+ - **URL**: Resolved from the url property in your config (from the environment variable).
1535
+ - **Headers**:
1536
+ - **Authorization**: `Bearer <access_token>` (form user's cyLogin access token)
1537
+ - **client-key**: `<clientKey>` (from config/env)
1538
+ - **service-id**: `<serviceId>` (from config/env)
1539
+ - **Accept**: `text/plain`
1540
+ - **Body**: The body contains the a JSON object with all the form data collected from the user across all pages.
1541
+
1542
+ **Example Request:**
1543
+
1544
+ ```http
1545
+ PUT /temp-save-endpoint HTTP/1.1
1546
+ Host: localhost:3002
1547
+ Authorization: Bearer eyJhbGciOi...
1548
+ client-key: 12345678901234567890123456789000
1549
+ service-id: 123
1550
+ Accept: text/plain
1551
+ Content-Type: application/json
1552
+
1553
+ {
1554
+ "submission_data" : "{\"index\":{\"formData\":{\"certificate_select\":[\"birth\",\"permanent_residence\"]}},\"data-entry-radios\":{\"formData\":{\"mobile_select\":\"other\",\"mobileTxt\":\"+35799484967\"}}}"
1555
+ }
1556
+ ```
1557
+
1558
+ **Response:**
1559
+
1560
+ The API is expected to return a JSON response with the following structure:
1561
+
1562
+ **On success:**
1563
+
1564
+ ```json
1565
+ {
1566
+ "Succeeded": true,
1567
+ "ErrorCode": 0,
1568
+ "ErrorMessage": null,
1569
+ "Data": {
1570
+ "submissionData": "{\"index\":{\"formData\":{\"certificate_select\":[\"birth\",\"permanent_residence\"]}},\"data-entry-radios\":{\"formData\":{\"mobile_select\":\"other\",\"mobileTxt\":\"+35799484967\"}}}"
1571
+ }
1572
+ }
1573
+ ```
1574
+
1575
+ **On failure:**
1576
+
1577
+ ```json
1578
+ {
1579
+ "Succeeded": false,
1580
+ "ErrorCode": 401,
1581
+ "ErrorMessage": "Not authorized",
1582
+ "Data": null
1583
+ }
1584
+ ```
1585
+
1586
+ **Notes**:
1587
+ - The response is normalized to always use PascalCase keys (`Succeeded`, `ErrorCode`, etc.), regardless of the backend’s casing.
1588
+
1589
+ #### Temporary save backward compatibility
1463
1590
  If these endpoints are not defined in the service JSON, the temporary save/load logic is skipped entirely.
1464
1591
  Existing services will continue to work without modification.
1465
1592
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gov-cy/govcy-express-services",
3
- "version": "1.0.0-alpha.1",
3
+ "version": "1.0.0-alpha.2",
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",