@opencrvs/mosip 1.9.2-mock.1 → 2.0.0-rc.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 CHANGED
@@ -1,31 +1,50 @@
1
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
- }
2
+ import { z } from "zod";
3
+ export declare const BirthRequestFieldsSchema: z.ZodObject<{
4
+ birthCertificateNumber: z.ZodString;
5
+ deathCertificateNumber: z.ZodOptional<z.ZodUndefined>;
6
+ }, z.core.$loose>;
7
+ export declare const DeathRequestFieldsSchema: z.ZodObject<{
8
+ deathCertificateNumber: z.ZodString;
9
+ birthCertificateNumber: z.ZodOptional<z.ZodUndefined>;
10
+ }, z.core.$loose>;
11
+ export declare const MosipNotificationSchema: z.ZodObject<{
12
+ recipientFullName: z.ZodString;
13
+ recipientEmail: z.ZodString;
14
+ recipientPhone: z.ZodString;
15
+ }, z.core.$strip>;
16
+ export declare const MosipInteropPayloadSchema: z.ZodObject<{
17
+ trackingId: z.ZodString;
18
+ notification: z.ZodObject<{
19
+ recipientFullName: z.ZodString;
20
+ recipientEmail: z.ZodString;
21
+ recipientPhone: z.ZodString;
22
+ }, z.core.$strip>;
23
+ requestFields: z.ZodUnion<readonly [z.ZodObject<{
24
+ birthCertificateNumber: z.ZodString;
25
+ deathCertificateNumber: z.ZodOptional<z.ZodUndefined>;
26
+ }, z.core.$loose>, z.ZodObject<{
27
+ deathCertificateNumber: z.ZodString;
28
+ birthCertificateNumber: z.ZodOptional<z.ZodUndefined>;
29
+ }, z.core.$loose>]>;
30
+ schemaJson: z.ZodOptional<z.ZodString>;
31
+ metaInfo: z.ZodRecord<z.ZodString, z.ZodUnknown>;
32
+ audit: z.ZodRecord<z.ZodString, z.ZodUnknown>;
33
+ }, z.core.$strip>;
34
+ export declare const VerifyNidPayloadSchema: z.ZodObject<{
35
+ nid: z.ZodCustom<FieldValue, FieldValue>;
36
+ gender: z.ZodOptional<z.ZodCustom<FieldValue, FieldValue>>;
37
+ dob: z.ZodCustom<FieldValue, FieldValue>;
38
+ name: z.ZodCustom<FieldValue, FieldValue>;
39
+ transactionId: z.ZodOptional<z.ZodString>;
40
+ }, z.core.$strip>;
41
+ export declare const VerifyNidResponseSchema: z.ZodUnion<readonly [z.ZodLiteral<"verified">, z.ZodLiteral<"failed">]>;
42
+ export declare const RegistrationEventResponseSchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
43
+ export type BirthRequestFields = z.infer<typeof BirthRequestFieldsSchema>;
44
+ export type DeathRequestFields = z.infer<typeof DeathRequestFieldsSchema>;
45
+ export type MosipInteropPayload = z.infer<typeof MosipInteropPayloadSchema>;
46
+ export type VerifyNidPayload = z.infer<typeof VerifyNidPayloadSchema>;
47
+ export type VerifyNidResponse = z.infer<typeof VerifyNidResponseSchema>;
29
48
  export interface VerificationStatus {
30
49
  father: boolean;
31
50
  mother: boolean;
@@ -34,6 +53,6 @@ export interface VerificationStatus {
34
53
  spouse: boolean;
35
54
  }
36
55
  export declare const createMosipInteropClient: (url: string, authorizationHeader: string) => {
37
- register: (payload: MosipInteropPayload) => Promise<any>;
38
- verifyNid: (payload: VerifyNidPayload) => Promise<"verified" | "failed">;
56
+ register: (payload: MosipInteropPayload) => Promise<Record<string, unknown>>;
57
+ verifyNid: (payload: VerifyNidPayload) => Promise<"failed" | "verified">;
39
58
  };
package/build/api.js CHANGED
@@ -1,6 +1,41 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createMosipInteropClient = void 0;
3
+ exports.createMosipInteropClient = exports.RegistrationEventResponseSchema = exports.VerifyNidResponseSchema = exports.VerifyNidPayloadSchema = exports.MosipInteropPayloadSchema = exports.MosipNotificationSchema = exports.DeathRequestFieldsSchema = exports.BirthRequestFieldsSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ exports.BirthRequestFieldsSchema = zod_1.z.looseObject({
6
+ birthCertificateNumber: zod_1.z.string(),
7
+ deathCertificateNumber: zod_1.z.undefined().optional(),
8
+ });
9
+ exports.DeathRequestFieldsSchema = zod_1.z.looseObject({
10
+ deathCertificateNumber: zod_1.z.string(),
11
+ birthCertificateNumber: zod_1.z.undefined().optional(),
12
+ });
13
+ exports.MosipNotificationSchema = zod_1.z.object({
14
+ recipientFullName: zod_1.z.string(),
15
+ recipientEmail: zod_1.z.string(),
16
+ recipientPhone: zod_1.z.string(),
17
+ });
18
+ exports.MosipInteropPayloadSchema = zod_1.z.object({
19
+ trackingId: zod_1.z.string(),
20
+ notification: exports.MosipNotificationSchema,
21
+ requestFields: zod_1.z.union([exports.BirthRequestFieldsSchema, exports.DeathRequestFieldsSchema]),
22
+ schemaJson: zod_1.z.string().optional(),
23
+ metaInfo: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()),
24
+ audit: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()),
25
+ });
26
+ const FieldValueSchema = zod_1.z.custom(() => true);
27
+ exports.VerifyNidPayloadSchema = zod_1.z.object({
28
+ nid: FieldValueSchema,
29
+ gender: FieldValueSchema.optional(),
30
+ dob: FieldValueSchema,
31
+ name: FieldValueSchema,
32
+ transactionId: zod_1.z.string().optional(),
33
+ });
34
+ exports.VerifyNidResponseSchema = zod_1.z.union([
35
+ zod_1.z.literal("verified"),
36
+ zod_1.z.literal("failed"),
37
+ ]);
38
+ exports.RegistrationEventResponseSchema = zod_1.z.record(zod_1.z.string(), zod_1.z.unknown());
4
39
  async function fetchWithTimeout(input, init = {}, timeoutMs = 15000) {
5
40
  const controller = new AbortController();
6
41
  const timeout = setTimeout(() => controller.abort(), timeoutMs);
@@ -18,10 +53,11 @@ async function fetchWithTimeout(input, init = {}, timeoutMs = 15000) {
18
53
  const createMosipInteropClient = (url, authorizationHeader) => {
19
54
  return {
20
55
  register: async (payload) => {
56
+ const parsedPayload = exports.MosipInteropPayloadSchema.parse(payload);
21
57
  const MOSIP_API_REGISTRATION_EVENT_URL = new URL("./events/registration", url).href;
22
58
  const response = await fetchWithTimeout(MOSIP_API_REGISTRATION_EVENT_URL, {
23
59
  method: "POST",
24
- body: JSON.stringify(payload),
60
+ body: JSON.stringify(parsedPayload),
25
61
  headers: {
26
62
  Authorization: authorizationHeader,
27
63
  "content-type": "application/json",
@@ -30,13 +66,14 @@ const createMosipInteropClient = (url, authorizationHeader) => {
30
66
  if (!response.ok) {
31
67
  throw new Error(`Failed to register event: ${await response.text()}`);
32
68
  }
33
- return response.json();
69
+ return exports.RegistrationEventResponseSchema.parse(await response.json());
34
70
  },
35
71
  verifyNid: async (payload) => {
72
+ const parsedPayload = exports.VerifyNidPayloadSchema.parse(payload);
36
73
  const MOSIP_API_VERIFY_URL = new URL("./verify", url).href;
37
74
  const response = await fetchWithTimeout(MOSIP_API_VERIFY_URL, {
38
75
  method: "POST",
39
- body: JSON.stringify(payload),
76
+ body: JSON.stringify(parsedPayload),
40
77
  headers: {
41
78
  Authorization: authorizationHeader,
42
79
  "content-type": "application/json",
@@ -45,7 +82,7 @@ const createMosipInteropClient = (url, authorizationHeader) => {
45
82
  if (!response.ok) {
46
83
  throw new Error(`Failed to verify: ${await response.text()}`);
47
84
  }
48
- return response.text();
85
+ return exports.VerifyNidResponseSchema.parse(await response.text());
49
86
  },
50
87
  };
51
88
  };
package/build/index.d.ts CHANGED
@@ -1,3 +1 @@
1
- export * from "./forms";
2
- export * from "./events";
3
- export * from "./transform";
1
+ export * from "./api";
package/build/index.js CHANGED
@@ -14,6 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./forms"), exports);
18
- __exportStar(require("./events"), exports);
19
- __exportStar(require("./transform"), exports);
17
+ __exportStar(require("./api"), exports);
package/package.json CHANGED
@@ -1,21 +1,21 @@
1
1
  {
2
2
  "name": "@opencrvs/mosip",
3
- "version": "1.9.2-mock.1",
3
+ "version": "2.0.0-rc.2",
4
4
  "license": "MPL-2.0",
5
5
  "main": "./build/index.js",
6
6
  "exports": {
7
7
  ".": "./build/index.js",
8
- "./forms": "./build/forms.js",
9
- "./events": "./build/events.js",
10
8
  "./api": "./build/api.js"
11
9
  },
12
10
  "typings": "build/index.d.ts",
13
11
  "scripts": {
14
12
  "build": "tsc"
15
13
  },
16
- "dependencies": {},
14
+ "dependencies": {
15
+ "zod": "^4.1.12"
16
+ },
17
17
  "devDependencies": {
18
- "@opencrvs/toolkit": "1.8.1-rc.62f6aec",
18
+ "@opencrvs/toolkit": "1.9.10-rc.9afdb31",
19
19
  "@types/hapi__hapi": "^20.0.0",
20
20
  "@types/node-fetch": "^2.6.11",
21
21
  "node-fetch": "2.6.7",
package/src/api.ts CHANGED
@@ -1,35 +1,56 @@
1
- import type { EventDocument, FieldValue } from "@opencrvs/toolkit/events";
1
+ import type { FieldValue } from "@opencrvs/toolkit/events";
2
+ import { z } from "zod";
2
3
 
3
- export interface BirthRequestFields extends Record<string, unknown> {
4
- birthCertificateNumber: string;
5
- deathCertificateNumber?: undefined;
6
- }
4
+ export const BirthRequestFieldsSchema = z.looseObject({
5
+ birthCertificateNumber: z.string(),
6
+ deathCertificateNumber: z.undefined().optional(),
7
+ });
7
8
 
8
- export interface DeathRequestFields extends Record<string, unknown> {
9
- deathCertificateNumber: string;
10
- birthCertificateNumber?: undefined;
11
- }
9
+ export const DeathRequestFieldsSchema = z.looseObject({
10
+ deathCertificateNumber: z.string(),
11
+ birthCertificateNumber: z.undefined().optional(),
12
+ });
12
13
 
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
- }
14
+ export const MosipNotificationSchema = z.object({
15
+ recipientFullName: z.string(),
16
+ recipientEmail: z.string(),
17
+ recipientPhone: z.string(),
18
+ });
24
19
 
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
- }
20
+ export const MosipInteropPayloadSchema = z.object({
21
+ trackingId: z.string(),
22
+ notification: MosipNotificationSchema,
23
+ requestFields: z.union([BirthRequestFieldsSchema, DeathRequestFieldsSchema]),
24
+ schemaJson: z.string().optional(),
25
+ metaInfo: z.record(z.string(), z.unknown()),
26
+ audit: z.record(z.string(), z.unknown()),
27
+ });
28
+
29
+ const FieldValueSchema = z.custom<FieldValue>(() => true);
30
+
31
+ export const VerifyNidPayloadSchema = z.object({
32
+ nid: FieldValueSchema,
33
+ gender: FieldValueSchema.optional(),
34
+ dob: FieldValueSchema,
35
+ name: FieldValueSchema,
36
+ transactionId: z.string().optional(),
37
+ });
38
+
39
+ export const VerifyNidResponseSchema = z.union([
40
+ z.literal("verified"),
41
+ z.literal("failed"),
42
+ ]);
43
+
44
+ export const RegistrationEventResponseSchema = z.record(
45
+ z.string(),
46
+ z.unknown(),
47
+ );
48
+
49
+ export type BirthRequestFields = z.infer<typeof BirthRequestFieldsSchema>;
50
+ export type DeathRequestFields = z.infer<typeof DeathRequestFieldsSchema>;
51
+ export type MosipInteropPayload = z.infer<typeof MosipInteropPayloadSchema>;
52
+ export type VerifyNidPayload = z.infer<typeof VerifyNidPayloadSchema>;
53
+ export type VerifyNidResponse = z.infer<typeof VerifyNidResponseSchema>;
33
54
 
34
55
  export interface VerificationStatus {
35
56
  father: boolean;
@@ -64,6 +85,7 @@ export const createMosipInteropClient = (
64
85
  ) => {
65
86
  return {
66
87
  register: async (payload: MosipInteropPayload) => {
88
+ const parsedPayload = MosipInteropPayloadSchema.parse(payload);
67
89
  const MOSIP_API_REGISTRATION_EVENT_URL = new URL(
68
90
  "./events/registration",
69
91
  url,
@@ -73,7 +95,7 @@ export const createMosipInteropClient = (
73
95
  MOSIP_API_REGISTRATION_EVENT_URL,
74
96
  {
75
97
  method: "POST",
76
- body: JSON.stringify(payload),
98
+ body: JSON.stringify(parsedPayload),
77
99
  headers: {
78
100
  Authorization: authorizationHeader,
79
101
  "content-type": "application/json",
@@ -85,14 +107,15 @@ export const createMosipInteropClient = (
85
107
  throw new Error(`Failed to register event: ${await response.text()}`);
86
108
  }
87
109
 
88
- return response.json();
110
+ return RegistrationEventResponseSchema.parse(await response.json());
89
111
  },
90
112
  verifyNid: async (payload: VerifyNidPayload) => {
113
+ const parsedPayload = VerifyNidPayloadSchema.parse(payload);
91
114
  const MOSIP_API_VERIFY_URL = new URL("./verify", url).href;
92
115
 
93
116
  const response = await fetchWithTimeout(MOSIP_API_VERIFY_URL, {
94
117
  method: "POST",
95
- body: JSON.stringify(payload),
118
+ body: JSON.stringify(parsedPayload),
96
119
  headers: {
97
120
  Authorization: authorizationHeader,
98
121
  "content-type": "application/json",
@@ -103,7 +126,7 @@ export const createMosipInteropClient = (
103
126
  throw new Error(`Failed to verify: ${await response.text()}`);
104
127
  }
105
128
 
106
- return response.text() as Promise<"verified" | "failed">;
129
+ return VerifyNidResponseSchema.parse(await response.text());
107
130
  },
108
131
  };
109
132
  };
package/src/index.ts CHANGED
@@ -1,3 +1 @@
1
- export * from "./forms";
2
- export * from "./events";
3
- export * from "./transform";
1
+ export * from "./api";
package/build/events.d.ts DELETED
@@ -1,30 +0,0 @@
1
- import type * as Hapi from "@hapi/hapi";
2
- import { MOSIPPayload } from "./transform";
3
- import { VerificationStatus } from "./api";
4
- /**
5
- * @deprecated
6
- * Replaces event registration handler in country config
7
- */
8
- export declare const mosipRegistrationHandler: ({ url, headers, payload, }: {
9
- url: string;
10
- headers: Record<string, string>;
11
- payload: MOSIPPayload;
12
- }) => (request: Hapi.Request, h: Hapi.ResponseToolkit) => Promise<Hapi.ResponseObject>;
13
- /**
14
- * @deprecated
15
- * Replaces `/events/{event}/actions/sent-notification-for-review` handler in country config
16
- */
17
- export declare const mosipRegistrationForReviewHandler: ({ url }: {
18
- url: string;
19
- }) => (request: Hapi.Request, h: Hapi.ResponseToolkit) => Promise<Hapi.ResponseObject>;
20
- /**
21
- * Replaces `/events/{event}/actions/sent-for-approval` handler in country config
22
- * Currently the same as `/events/{event}/actions/sent-notification-for-review`
23
- */
24
- export declare const mosipRegistrationForApprovalHandler: ({ url }: {
25
- url: string;
26
- }) => (request: Hapi.Request, h: Hapi.ResponseToolkit) => Promise<Hapi.ResponseObject>;
27
- export declare const verify: ({ url, request, }: {
28
- url: string;
29
- request: Hapi.Request;
30
- }) => Promise<Partial<VerificationStatus>>;
package/build/events.js DELETED
@@ -1,80 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.verify = exports.mosipRegistrationForApprovalHandler = exports.mosipRegistrationForReviewHandler = exports.mosipRegistrationHandler = void 0;
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
- */
14
- /**
15
- * @deprecated
16
- * Replaces event registration handler in country config
17
- */
18
- const mosipRegistrationHandler = ({ url, headers, payload, }) => (async (request, h) => {
19
- const MOSIP_API_REGISTRATION_EVENT_URL = new URL("./events/registration", url);
20
- const response = await (0, node_fetch_1.default)(MOSIP_API_REGISTRATION_EVENT_URL, {
21
- method: "POST",
22
- body: JSON.stringify(payload),
23
- headers: {
24
- ...headers,
25
- "content-type": "application/json",
26
- },
27
- });
28
- if (!response.ok) {
29
- return h
30
- .response({
31
- error: "OpenCRVS-MOSIP event registration route did not return a 200",
32
- response: await response.text(),
33
- })
34
- .code(500);
35
- }
36
- return h.response({ success: true }).code(200);
37
- });
38
- exports.mosipRegistrationHandler = mosipRegistrationHandler;
39
- /**
40
- * @deprecated
41
- * Replaces `/events/{event}/actions/sent-notification-for-review` handler in country config
42
- */
43
- const mosipRegistrationForReviewHandler = ({ url }) => (async (request, h) => {
44
- // Corresponds to `packages/mosip-api` /events/review -route
45
- let response;
46
- try {
47
- response = await (0, exports.verify)({ url, request });
48
- }
49
- catch (error) {
50
- return h
51
- .response({
52
- error: "OpenCRVS-MOSIP event review route did not return a 200",
53
- response: error instanceof Error ? error.message : "Unknown error",
54
- })
55
- .code(500);
56
- }
57
- return h.response(response).code(200);
58
- });
59
- exports.mosipRegistrationForReviewHandler = mosipRegistrationForReviewHandler;
60
- /**
61
- * Replaces `/events/{event}/actions/sent-for-approval` handler in country config
62
- * Currently the same as `/events/{event}/actions/sent-notification-for-review`
63
- */
64
- exports.mosipRegistrationForApprovalHandler = exports.mosipRegistrationForReviewHandler;
65
- const verify = async ({ url, request, }) => {
66
- const MOSIP_API_REVIEW_EVENT_URL = new URL("./events/review", url);
67
- const response = await (0, node_fetch_1.default)(MOSIP_API_REVIEW_EVENT_URL, {
68
- method: "POST",
69
- body: JSON.stringify(request.payload),
70
- headers: {
71
- ...request.headers,
72
- "content-type": "application/json",
73
- },
74
- });
75
- if (!response.ok) {
76
- throw new Error(await response.text());
77
- }
78
- return (await response.json());
79
- };
80
- exports.verify = verify;