@opencrvs/mosip 1.7.0-alpha.20 → 1.7.0-alpha.21

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/build/events.d.ts CHANGED
@@ -1,4 +1,9 @@
1
1
  import type * as Hapi from "@hapi/hapi";
2
+ interface VerificationStatus {
3
+ father: boolean;
4
+ mother: boolean;
5
+ informant: boolean;
6
+ }
2
7
  /**
3
8
  * Replaces event registration handler in country config
4
9
  */
@@ -18,3 +23,8 @@ export declare const mosipRegistrationForReviewHandler: ({ url }: {
18
23
  export declare const mosipRegistrationForApprovalHandler: ({ url }: {
19
24
  url: string;
20
25
  }) => (request: Hapi.Request, h: Hapi.ResponseToolkit) => Promise<Hapi.ResponseObject>;
26
+ export declare const verify: ({ url, request, }: {
27
+ url: string;
28
+ request: Hapi.Request;
29
+ }) => Promise<Partial<VerificationStatus>>;
30
+ export {};
package/build/events.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.mosipRegistrationForApprovalHandler = exports.mosipRegistrationForReviewHandler = exports.mosipRegistrationHandler = void 0;
6
+ exports.verify = exports.mosipRegistrationForApprovalHandler = exports.mosipRegistrationForReviewHandler = exports.mosipRegistrationHandler = void 0;
7
7
  const node_fetch_1 = __importDefault(require("node-fetch"));
8
8
  /**
9
9
  * Replaces event registration handler in country config
@@ -34,25 +34,19 @@ exports.mosipRegistrationHandler = mosipRegistrationHandler;
34
34
  */
35
35
  const mosipRegistrationForReviewHandler = ({ url }) => (async (request, h) => {
36
36
  // Corresponds to `packages/mosip-api` /events/review -route
37
- const MOSIP_API_REVIEW_EVENT_URL = new URL("./events/review", url);
38
- console.info(request.headers);
39
- const response = await (0, node_fetch_1.default)(MOSIP_API_REVIEW_EVENT_URL, {
40
- method: "POST",
41
- body: JSON.stringify(request.payload),
42
- headers: {
43
- ...request.headers,
44
- "content-type": "application/json",
45
- },
46
- });
47
- if (!response.ok) {
37
+ let response;
38
+ try {
39
+ response = await (0, exports.verify)({ url, request });
40
+ }
41
+ catch (error) {
48
42
  return h
49
43
  .response({
50
44
  error: "OpenCRVS-MOSIP event review route did not return a 200",
51
- response: await response.text(),
45
+ response: error instanceof Error ? error.message : "Unknown error",
52
46
  })
53
47
  .code(500);
54
48
  }
55
- return h.response({ success: true }).code(200);
49
+ return h.response(response).code(200);
56
50
  });
57
51
  exports.mosipRegistrationForReviewHandler = mosipRegistrationForReviewHandler;
58
52
  /**
@@ -60,3 +54,19 @@ exports.mosipRegistrationForReviewHandler = mosipRegistrationForReviewHandler;
60
54
  * Currently the same as `/events/{event}/actions/sent-notification-for-review`
61
55
  */
62
56
  exports.mosipRegistrationForApprovalHandler = exports.mosipRegistrationForReviewHandler;
57
+ const verify = async ({ url, request, }) => {
58
+ const MOSIP_API_REVIEW_EVENT_URL = new URL("./events/review", url);
59
+ const response = await (0, node_fetch_1.default)(MOSIP_API_REVIEW_EVENT_URL, {
60
+ method: "POST",
61
+ body: JSON.stringify(request.payload),
62
+ headers: {
63
+ ...request.headers,
64
+ "content-type": "application/json",
65
+ },
66
+ });
67
+ if (!response.ok) {
68
+ throw new Error(await response.text());
69
+ }
70
+ return (await response.json());
71
+ };
72
+ exports.verify = verify;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencrvs/mosip",
3
- "version": "1.7.0-alpha.20",
3
+ "version": "1.7.0-alpha.21",
4
4
  "license": "MPL-2.0",
5
5
  "main": "./build/index.js",
6
6
  "exports": {
@@ -16,9 +16,10 @@
16
16
  "devDependencies": {
17
17
  "@types/hapi__hapi": "^20.0.0",
18
18
  "@types/node-fetch": "^2.6.11",
19
+ "node-fetch": "2.6.7",
19
20
  "typescript": "^5.6.3"
20
21
  },
21
22
  "peerDependencies": {
22
- "node-fetch": "^3.3.2"
23
+ "node-fetch": "2.6.7"
23
24
  }
24
25
  }
package/src/events.ts CHANGED
@@ -1,6 +1,12 @@
1
1
  import type * as Hapi from "@hapi/hapi";
2
2
  import fetch from "node-fetch";
3
3
 
4
+ interface VerificationStatus {
5
+ father: boolean;
6
+ mother: boolean;
7
+ informant: boolean;
8
+ }
9
+
4
10
  /**
5
11
  * Replaces event registration handler in country config
6
12
  */
@@ -38,33 +44,49 @@ export const mosipRegistrationHandler = ({ url }: { url: string }) =>
38
44
  export const mosipRegistrationForReviewHandler = ({ url }: { url: string }) =>
39
45
  (async (request: Hapi.Request, h: Hapi.ResponseToolkit) => {
40
46
  // Corresponds to `packages/mosip-api` /events/review -route
41
- const MOSIP_API_REVIEW_EVENT_URL = new URL("./events/review", url);
42
-
43
- console.info(request.headers);
44
-
45
- const response = await fetch(MOSIP_API_REVIEW_EVENT_URL, {
46
- method: "POST",
47
- body: JSON.stringify(request.payload),
48
- headers: {
49
- ...request.headers,
50
- "content-type": "application/json",
51
- },
52
- });
53
-
54
- if (!response.ok) {
47
+ let response;
48
+ try {
49
+ response = await verify({ url, request });
50
+ } catch (error) {
55
51
  return h
56
52
  .response({
57
53
  error: "OpenCRVS-MOSIP event review route did not return a 200",
58
- response: await response.text(),
54
+ response: error instanceof Error ? error.message : "Unknown error",
59
55
  })
60
56
  .code(500);
61
57
  }
62
58
 
63
- return h.response({ success: true }).code(200);
59
+ return h.response(response).code(200);
64
60
  }) satisfies Hapi.ServerRoute["handler"];
65
61
 
66
62
  /**
67
63
  * Replaces `/events/{event}/actions/sent-for-approval` handler in country config
68
64
  * Currently the same as `/events/{event}/actions/sent-notification-for-review`
69
65
  */
70
- export const mosipRegistrationForApprovalHandler = mosipRegistrationForReviewHandler
66
+ export const mosipRegistrationForApprovalHandler =
67
+ mosipRegistrationForReviewHandler;
68
+
69
+ export const verify = async ({
70
+ url,
71
+ request,
72
+ }: {
73
+ url: string;
74
+ request: Hapi.Request;
75
+ }): Promise<Partial<VerificationStatus>> => {
76
+ const MOSIP_API_REVIEW_EVENT_URL = new URL("./events/review", url);
77
+
78
+ const response = await fetch(MOSIP_API_REVIEW_EVENT_URL, {
79
+ method: "POST",
80
+ body: JSON.stringify(request.payload),
81
+ headers: {
82
+ ...request.headers,
83
+ "content-type": "application/json",
84
+ },
85
+ });
86
+
87
+ if (!response.ok) {
88
+ throw new Error(await response.text());
89
+ }
90
+
91
+ return (await response.json()) satisfies Partial<VerificationStatus>;
92
+ };