@opencrvs/mosip 1.8.0 → 1.9.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.
package/build/api.d.ts ADDED
@@ -0,0 +1,39 @@
1
+ import type { FieldValue } from "@opencrvs/toolkit/events";
2
+ export interface BirthRequestFields extends Record<string, unknown> {
3
+ birthCertificateNumber: string;
4
+ deathCertificateNumber?: undefined;
5
+ }
6
+ export interface DeathRequestFields extends Record<string, unknown> {
7
+ deathCertificateNumber: string;
8
+ birthCertificateNumber?: undefined;
9
+ }
10
+ export interface MosipInteropPayload {
11
+ trackingId: string;
12
+ notification: {
13
+ recipientFullName: string;
14
+ recipientEmail: string;
15
+ recipientPhone: string;
16
+ };
17
+ requestFields: BirthRequestFields | DeathRequestFields;
18
+ metaInfo: Record<string, unknown>;
19
+ audit: Record<string, unknown>;
20
+ }
21
+ export interface VerifyNidPayload {
22
+ nid: FieldValue;
23
+ gender?: FieldValue;
24
+ dob: FieldValue;
25
+ name: FieldValue;
26
+ /** Adds logging of the auth status using this id to mosip-api */
27
+ transactionId?: string;
28
+ }
29
+ export interface VerificationStatus {
30
+ father: boolean;
31
+ mother: boolean;
32
+ informant: boolean;
33
+ deceased: boolean;
34
+ spouse: boolean;
35
+ }
36
+ export declare const createMosipInteropClient: (url: string, authorizationHeader: string) => {
37
+ register: (payload: MosipInteropPayload) => Promise<any>;
38
+ verifyNid: (payload: VerifyNidPayload) => Promise<"verified" | "failed">;
39
+ };
package/build/api.js ADDED
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createMosipInteropClient = void 0;
4
+ async function fetchWithTimeout(input, init = {}, timeoutMs = 15000) {
5
+ const controller = new AbortController();
6
+ const timeout = setTimeout(() => controller.abort(), timeoutMs);
7
+ try {
8
+ const response = await fetch(input, {
9
+ ...init,
10
+ signal: controller.signal,
11
+ });
12
+ return response;
13
+ }
14
+ finally {
15
+ clearTimeout(timeout);
16
+ }
17
+ }
18
+ const createMosipInteropClient = (url, authorizationHeader) => {
19
+ return {
20
+ register: async (payload) => {
21
+ const MOSIP_API_REGISTRATION_EVENT_URL = new URL("./events/registration", url).href;
22
+ const response = await fetchWithTimeout(MOSIP_API_REGISTRATION_EVENT_URL, {
23
+ method: "POST",
24
+ body: JSON.stringify(payload),
25
+ headers: {
26
+ Authorization: authorizationHeader,
27
+ "content-type": "application/json",
28
+ },
29
+ });
30
+ if (!response.ok) {
31
+ throw new Error(`Failed to register event: ${await response.text()}`);
32
+ }
33
+ return response.json();
34
+ },
35
+ verifyNid: async (payload) => {
36
+ const MOSIP_API_VERIFY_URL = new URL("./verify", url).href;
37
+ const response = await fetchWithTimeout(MOSIP_API_VERIFY_URL, {
38
+ method: "POST",
39
+ body: JSON.stringify(payload),
40
+ headers: {
41
+ Authorization: authorizationHeader,
42
+ "content-type": "application/json",
43
+ },
44
+ });
45
+ if (!response.ok) {
46
+ throw new Error(`Failed to register event: ${await response.text()}`);
47
+ }
48
+ return response.text();
49
+ },
50
+ };
51
+ };
52
+ exports.createMosipInteropClient = createMosipInteropClient;
package/build/events.d.ts CHANGED
@@ -1,11 +1,8 @@
1
1
  import type * as Hapi from "@hapi/hapi";
2
2
  import { MOSIPPayload } from "./transform";
3
- interface VerificationStatus {
4
- father: boolean;
5
- mother: boolean;
6
- informant: boolean;
7
- }
3
+ import { VerificationStatus } from "./api";
8
4
  /**
5
+ * @deprecated
9
6
  * Replaces event registration handler in country config
10
7
  */
11
8
  export declare const mosipRegistrationHandler: ({ url, headers, payload, }: {
@@ -14,6 +11,7 @@ export declare const mosipRegistrationHandler: ({ url, headers, payload, }: {
14
11
  payload: MOSIPPayload;
15
12
  }) => (request: Hapi.Request, h: Hapi.ResponseToolkit) => Promise<Hapi.ResponseObject>;
16
13
  /**
14
+ * @deprecated
17
15
  * Replaces `/events/{event}/actions/sent-notification-for-review` handler in country config
18
16
  */
19
17
  export declare const mosipRegistrationForReviewHandler: ({ url }: {
@@ -30,4 +28,3 @@ export declare const verify: ({ url, request, }: {
30
28
  url: string;
31
29
  request: Hapi.Request;
32
30
  }) => Promise<Partial<VerificationStatus>>;
33
- export {};
package/build/events.js CHANGED
@@ -5,7 +5,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.verify = exports.mosipRegistrationForApprovalHandler = exports.mosipRegistrationForReviewHandler = exports.mosipRegistrationHandler = void 0;
7
7
  const node_fetch_1 = __importDefault(require("node-fetch"));
8
+ /*
9
+ * NOTE!
10
+ *
11
+ * This file is used in OpenCRVS pre-1.9 country-configs and registrations. You are looking for `api.ts` which caters for OpenCRVS 1.9+.
12
+ * This file can be removed in future versions.
13
+ */
8
14
  /**
15
+ * @deprecated
9
16
  * Replaces event registration handler in country config
10
17
  */
11
18
  const mosipRegistrationHandler = ({ url, headers, payload, }) => (async (request, h) => {
@@ -30,6 +37,7 @@ const mosipRegistrationHandler = ({ url, headers, payload, }) => (async (request
30
37
  });
31
38
  exports.mosipRegistrationHandler = mosipRegistrationHandler;
32
39
  /**
40
+ * @deprecated
33
41
  * Replaces `/events/{event}/actions/sent-notification-for-review` handler in country config
34
42
  */
35
43
  const mosipRegistrationForReviewHandler = ({ url }) => (async (request, h) => {
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@opencrvs/mosip",
3
- "version": "1.8.0",
3
+ "version": "1.9.0-alpha.2",
4
4
  "license": "MPL-2.0",
5
5
  "main": "./build/index.js",
6
6
  "exports": {
7
7
  ".": "./build/index.js",
8
8
  "./forms": "./build/forms.js",
9
- "./events": "./build/events.js"
9
+ "./events": "./build/events.js",
10
+ "./api": "./build/api.js"
10
11
  },
11
12
  "typings": "build/index.d.ts",
12
13
  "scripts": {
@@ -14,6 +15,7 @@
14
15
  },
15
16
  "dependencies": {},
16
17
  "devDependencies": {
18
+ "@opencrvs/toolkit": "^1.8.1-rc.af15018",
17
19
  "@types/hapi__hapi": "^20.0.0",
18
20
  "@types/node-fetch": "^2.6.11",
19
21
  "node-fetch": "2.6.7",
package/src/api.ts ADDED
@@ -0,0 +1,109 @@
1
+ import type { EventDocument, FieldValue } from "@opencrvs/toolkit/events";
2
+
3
+ export interface BirthRequestFields extends Record<string, unknown> {
4
+ birthCertificateNumber: string;
5
+ deathCertificateNumber?: undefined;
6
+ }
7
+
8
+ export interface DeathRequestFields extends Record<string, unknown> {
9
+ deathCertificateNumber: string;
10
+ birthCertificateNumber?: undefined;
11
+ }
12
+
13
+ export interface MosipInteropPayload {
14
+ trackingId: string;
15
+ notification: {
16
+ recipientFullName: string;
17
+ recipientEmail: string;
18
+ recipientPhone: string;
19
+ };
20
+ requestFields: BirthRequestFields | DeathRequestFields;
21
+ metaInfo: Record<string, unknown>;
22
+ audit: Record<string, unknown>;
23
+ }
24
+
25
+ export interface VerifyNidPayload {
26
+ nid: FieldValue;
27
+ gender?: FieldValue;
28
+ dob: FieldValue;
29
+ name: FieldValue;
30
+ /** Adds logging of the auth status using this id to mosip-api */
31
+ transactionId?: string;
32
+ }
33
+
34
+ export interface VerificationStatus {
35
+ father: boolean;
36
+ mother: boolean;
37
+ informant: boolean;
38
+ deceased: boolean;
39
+ spouse: boolean;
40
+ }
41
+
42
+ async function fetchWithTimeout(
43
+ input: RequestInfo,
44
+ init: RequestInit = {},
45
+ timeoutMs = 15000,
46
+ ): Promise<Response> {
47
+ const controller = new AbortController();
48
+ const timeout = setTimeout(() => controller.abort(), timeoutMs);
49
+
50
+ try {
51
+ const response = await fetch(input, {
52
+ ...init,
53
+ signal: controller.signal,
54
+ });
55
+ return response;
56
+ } finally {
57
+ clearTimeout(timeout);
58
+ }
59
+ }
60
+
61
+ export const createMosipInteropClient = (
62
+ url: string,
63
+ authorizationHeader: string,
64
+ ) => {
65
+ return {
66
+ register: async (payload: MosipInteropPayload) => {
67
+ const MOSIP_API_REGISTRATION_EVENT_URL = new URL(
68
+ "./events/registration",
69
+ url,
70
+ ).href;
71
+
72
+ const response = await fetchWithTimeout(
73
+ MOSIP_API_REGISTRATION_EVENT_URL,
74
+ {
75
+ method: "POST",
76
+ body: JSON.stringify(payload),
77
+ headers: {
78
+ Authorization: authorizationHeader,
79
+ "content-type": "application/json",
80
+ },
81
+ },
82
+ );
83
+
84
+ if (!response.ok) {
85
+ throw new Error(`Failed to register event: ${await response.text()}`);
86
+ }
87
+
88
+ return response.json();
89
+ },
90
+ verifyNid: async (payload: VerifyNidPayload) => {
91
+ const MOSIP_API_VERIFY_URL = new URL("./verify", url).href;
92
+
93
+ const response = await fetchWithTimeout(MOSIP_API_VERIFY_URL, {
94
+ method: "POST",
95
+ body: JSON.stringify(payload),
96
+ headers: {
97
+ Authorization: authorizationHeader,
98
+ "content-type": "application/json",
99
+ },
100
+ });
101
+
102
+ if (!response.ok) {
103
+ throw new Error(`Failed to register event: ${await response.text()}`);
104
+ }
105
+
106
+ return response.text() as Promise<"verified" | "failed">;
107
+ },
108
+ };
109
+ };
package/src/events.ts CHANGED
@@ -1,14 +1,17 @@
1
1
  import type * as Hapi from "@hapi/hapi";
2
2
  import fetch from "node-fetch";
3
3
  import { MOSIPPayload } from "./transform";
4
+ import { VerificationStatus } from "./api";
4
5
 
5
- interface VerificationStatus {
6
- father: boolean;
7
- mother: boolean;
8
- informant: boolean;
9
- }
6
+ /*
7
+ * NOTE!
8
+ *
9
+ * This file is used in OpenCRVS pre-1.9 country-configs and registrations. You are looking for `api.ts` which caters for OpenCRVS 1.9+.
10
+ * This file can be removed in future versions.
11
+ */
10
12
 
11
13
  /**
14
+ * @deprecated
12
15
  * Replaces event registration handler in country config
13
16
  */
14
17
  export const mosipRegistrationHandler = ({
@@ -48,6 +51,7 @@ export const mosipRegistrationHandler = ({
48
51
  }) satisfies Hapi.ServerRoute["handler"];
49
52
 
50
53
  /**
54
+ * @deprecated
51
55
  * Replaces `/events/{event}/actions/sent-notification-for-review` handler in country config
52
56
  */
53
57
  export const mosipRegistrationForReviewHandler = ({ url }: { url: string }) =>
package/tsconfig.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "target": "ES2020",
4
- "module": "commonjs",
4
+ "module": "node16",
5
5
  "strict": true,
6
6
  "esModuleInterop": true,
7
7
  "skipLibCheck": true,
8
8
  "declaration": true,
9
9
  "outDir": "./build"
10
10
  }
11
- }
11
+ }