@opencrvs/mosip 1.9.2-mock.1 → 2.0.0-rc.10

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,87 @@
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 CorrectionRequestFieldsSchema: z.ZodObject<{
12
+ VID: z.ZodString;
13
+ fullName: z.ZodOptional<z.ZodString>;
14
+ dateOfBirth: z.ZodOptional<z.ZodString>;
15
+ gender: z.ZodOptional<z.ZodString>;
16
+ introducerInfoToken: z.ZodOptional<z.ZodString>;
17
+ birthCertificateNumber: z.ZodOptional<z.ZodUndefined>;
18
+ deathCertificateNumber: z.ZodOptional<z.ZodUndefined>;
19
+ }, z.core.$loose>;
20
+ export declare const MosipNotificationSchema: z.ZodObject<{
21
+ recipientFullName: z.ZodString;
22
+ recipientEmail: z.ZodString;
23
+ recipientPhone: z.ZodString;
24
+ }, z.core.$strip>;
25
+ export declare const MosipInteropPayloadSchema: z.ZodObject<{
26
+ trackingId: z.ZodString;
27
+ notification: z.ZodObject<{
28
+ recipientFullName: z.ZodString;
29
+ recipientEmail: z.ZodString;
30
+ recipientPhone: z.ZodString;
31
+ }, z.core.$strip>;
32
+ requestFields: z.ZodUnion<readonly [z.ZodObject<{
33
+ birthCertificateNumber: z.ZodString;
34
+ deathCertificateNumber: z.ZodOptional<z.ZodUndefined>;
35
+ }, z.core.$loose>, z.ZodObject<{
36
+ deathCertificateNumber: z.ZodString;
37
+ birthCertificateNumber: z.ZodOptional<z.ZodUndefined>;
38
+ }, z.core.$loose>, z.ZodObject<{
39
+ VID: z.ZodString;
40
+ fullName: z.ZodOptional<z.ZodString>;
41
+ dateOfBirth: z.ZodOptional<z.ZodString>;
42
+ gender: z.ZodOptional<z.ZodString>;
43
+ introducerInfoToken: z.ZodOptional<z.ZodString>;
44
+ birthCertificateNumber: z.ZodOptional<z.ZodUndefined>;
45
+ deathCertificateNumber: z.ZodOptional<z.ZodUndefined>;
46
+ }, z.core.$loose>]>;
47
+ schemaJson: z.ZodOptional<z.ZodString>;
48
+ metaInfo: z.ZodRecord<z.ZodString, z.ZodUnknown>;
49
+ audit: z.ZodRecord<z.ZodString, z.ZodUnknown>;
50
+ }, z.core.$strip>;
51
+ export declare const MosipCorrectionPayloadSchema: z.ZodObject<{
52
+ trackingId: z.ZodString;
53
+ notification: z.ZodObject<{
54
+ recipientFullName: z.ZodString;
55
+ recipientEmail: z.ZodString;
56
+ recipientPhone: z.ZodString;
57
+ }, z.core.$strip>;
58
+ requestFields: z.ZodObject<{
59
+ VID: z.ZodString;
60
+ fullName: z.ZodOptional<z.ZodString>;
61
+ dateOfBirth: z.ZodOptional<z.ZodString>;
62
+ gender: z.ZodOptional<z.ZodString>;
63
+ introducerInfoToken: z.ZodOptional<z.ZodString>;
64
+ }, z.core.$strip>;
65
+ schemaJson: z.ZodOptional<z.ZodString>;
66
+ metaInfo: z.ZodRecord<z.ZodString, z.ZodUnknown>;
67
+ audit: z.ZodRecord<z.ZodString, z.ZodUnknown>;
68
+ }, z.core.$strip>;
69
+ export declare const VerifyNidPayloadSchema: z.ZodObject<{
70
+ nid: z.ZodCustom<FieldValue, FieldValue>;
71
+ gender: z.ZodOptional<z.ZodCustom<FieldValue, FieldValue>>;
72
+ dob: z.ZodCustom<FieldValue, FieldValue>;
73
+ name: z.ZodCustom<FieldValue, FieldValue>;
74
+ transactionId: z.ZodOptional<z.ZodString>;
75
+ }, z.core.$strip>;
76
+ export declare const VerifyNidResponseSchema: z.ZodUnion<readonly [z.ZodLiteral<"verified">, z.ZodLiteral<"failed">]>;
77
+ export declare const RegistrationEventResponseSchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
78
+ export type BirthRequestFields = z.infer<typeof BirthRequestFieldsSchema>;
79
+ export type DeathRequestFields = z.infer<typeof DeathRequestFieldsSchema>;
80
+ export type CorrectionRequestFields = z.infer<typeof CorrectionRequestFieldsSchema>;
81
+ export type MosipInteropPayload = z.infer<typeof MosipInteropPayloadSchema>;
82
+ export type MosipCorrectionPayload = z.infer<typeof MosipCorrectionPayloadSchema>;
83
+ export type VerifyNidPayload = z.infer<typeof VerifyNidPayloadSchema>;
84
+ export type VerifyNidResponse = z.infer<typeof VerifyNidResponseSchema>;
29
85
  export interface VerificationStatus {
30
86
  father: boolean;
31
87
  mother: boolean;
@@ -34,6 +90,7 @@ export interface VerificationStatus {
34
90
  spouse: boolean;
35
91
  }
36
92
  export declare const createMosipInteropClient: (url: string, authorizationHeader: string) => {
37
- register: (payload: MosipInteropPayload) => Promise<any>;
93
+ register: (payload: MosipInteropPayload) => Promise<Record<string, unknown>>;
94
+ updateBiographics: (payload: MosipCorrectionPayload) => Promise<Record<string, unknown>>;
38
95
  verifyNid: (payload: VerifyNidPayload) => Promise<"verified" | "failed">;
39
96
  };
package/build/api.js CHANGED
@@ -1,6 +1,68 @@
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.MosipCorrectionPayloadSchema = exports.MosipInteropPayloadSchema = exports.MosipNotificationSchema = exports.CorrectionRequestFieldsSchema = 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.CorrectionRequestFieldsSchema = zod_1.z.looseObject({
14
+ VID: zod_1.z.string(),
15
+ fullName: zod_1.z.string().optional(),
16
+ dateOfBirth: zod_1.z.string().optional(),
17
+ gender: zod_1.z.string().optional(),
18
+ introducerInfoToken: zod_1.z.string().optional(),
19
+ birthCertificateNumber: zod_1.z.undefined().optional(),
20
+ deathCertificateNumber: zod_1.z.undefined().optional(),
21
+ });
22
+ exports.MosipNotificationSchema = zod_1.z.object({
23
+ recipientFullName: zod_1.z.string(),
24
+ recipientEmail: zod_1.z.string(),
25
+ recipientPhone: zod_1.z.string(),
26
+ });
27
+ exports.MosipInteropPayloadSchema = zod_1.z.object({
28
+ trackingId: zod_1.z.string(),
29
+ notification: exports.MosipNotificationSchema,
30
+ requestFields: zod_1.z.union([
31
+ exports.BirthRequestFieldsSchema,
32
+ exports.DeathRequestFieldsSchema,
33
+ exports.CorrectionRequestFieldsSchema,
34
+ ]),
35
+ schemaJson: zod_1.z.string().optional(),
36
+ metaInfo: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()),
37
+ audit: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()),
38
+ });
39
+ exports.MosipCorrectionPayloadSchema = zod_1.z.object({
40
+ trackingId: zod_1.z.string(),
41
+ notification: exports.MosipNotificationSchema,
42
+ requestFields: zod_1.z.object({
43
+ VID: zod_1.z.string(),
44
+ fullName: zod_1.z.string().optional(),
45
+ dateOfBirth: zod_1.z.string().optional(),
46
+ gender: zod_1.z.string().optional(),
47
+ introducerInfoToken: zod_1.z.string().optional(),
48
+ }),
49
+ schemaJson: zod_1.z.string().optional(),
50
+ metaInfo: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()),
51
+ audit: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()),
52
+ });
53
+ const FieldValueSchema = zod_1.z.custom(() => true);
54
+ exports.VerifyNidPayloadSchema = zod_1.z.object({
55
+ nid: FieldValueSchema,
56
+ gender: FieldValueSchema.optional(),
57
+ dob: FieldValueSchema,
58
+ name: FieldValueSchema,
59
+ transactionId: zod_1.z.string().optional(),
60
+ });
61
+ exports.VerifyNidResponseSchema = zod_1.z.union([
62
+ zod_1.z.literal("verified"),
63
+ zod_1.z.literal("failed"),
64
+ ]);
65
+ exports.RegistrationEventResponseSchema = zod_1.z.record(zod_1.z.string(), zod_1.z.unknown());
4
66
  async function fetchWithTimeout(input, init = {}, timeoutMs = 15000) {
5
67
  const controller = new AbortController();
6
68
  const timeout = setTimeout(() => controller.abort(), timeoutMs);
@@ -18,10 +80,11 @@ async function fetchWithTimeout(input, init = {}, timeoutMs = 15000) {
18
80
  const createMosipInteropClient = (url, authorizationHeader) => {
19
81
  return {
20
82
  register: async (payload) => {
83
+ const parsedPayload = exports.MosipInteropPayloadSchema.parse(payload);
21
84
  const MOSIP_API_REGISTRATION_EVENT_URL = new URL("./events/registration", url).href;
22
85
  const response = await fetchWithTimeout(MOSIP_API_REGISTRATION_EVENT_URL, {
23
86
  method: "POST",
24
- body: JSON.stringify(payload),
87
+ body: JSON.stringify(parsedPayload),
25
88
  headers: {
26
89
  Authorization: authorizationHeader,
27
90
  "content-type": "application/json",
@@ -30,13 +93,30 @@ const createMosipInteropClient = (url, authorizationHeader) => {
30
93
  if (!response.ok) {
31
94
  throw new Error(`Failed to register event: ${await response.text()}`);
32
95
  }
33
- return response.json();
96
+ return exports.RegistrationEventResponseSchema.parse(await response.json());
97
+ },
98
+ updateBiographics: async (payload) => {
99
+ const parsedPayload = exports.MosipCorrectionPayloadSchema.parse(payload);
100
+ const MOSIP_API_CORRECTION_EVENT_URL = new URL("./events/update-biographics", url).href;
101
+ const response = await fetchWithTimeout(MOSIP_API_CORRECTION_EVENT_URL, {
102
+ method: "POST",
103
+ body: JSON.stringify(parsedPayload),
104
+ headers: {
105
+ Authorization: authorizationHeader,
106
+ "content-type": "application/json",
107
+ },
108
+ });
109
+ if (!response.ok) {
110
+ throw new Error(`Failed to update biographics: ${await response.text()}`);
111
+ }
112
+ return exports.RegistrationEventResponseSchema.parse(await response.json());
34
113
  },
35
114
  verifyNid: async (payload) => {
115
+ const parsedPayload = exports.VerifyNidPayloadSchema.parse(payload);
36
116
  const MOSIP_API_VERIFY_URL = new URL("./verify", url).href;
37
117
  const response = await fetchWithTimeout(MOSIP_API_VERIFY_URL, {
38
118
  method: "POST",
39
- body: JSON.stringify(payload),
119
+ body: JSON.stringify(parsedPayload),
40
120
  headers: {
41
121
  Authorization: authorizationHeader,
42
122
  "content-type": "application/json",
@@ -45,7 +125,7 @@ const createMosipInteropClient = (url, authorizationHeader) => {
45
125
  if (!response.ok) {
46
126
  throw new Error(`Failed to verify: ${await response.text()}`);
47
127
  }
48
- return response.text();
128
+ return exports.VerifyNidResponseSchema.parse(await response.text());
49
129
  },
50
130
  };
51
131
  };
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.10",
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.12-rc.1b9bbf4",
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,87 @@
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 CorrectionRequestFieldsSchema = z.looseObject({
15
+ VID: z.string(),
16
+ fullName: z.string().optional(),
17
+ dateOfBirth: z.string().optional(),
18
+ gender: z.string().optional(),
19
+ introducerInfoToken: z.string().optional(),
20
+ birthCertificateNumber: z.undefined().optional(),
21
+ deathCertificateNumber: z.undefined().optional(),
22
+ });
24
23
 
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
- }
24
+ export const MosipNotificationSchema = z.object({
25
+ recipientFullName: z.string(),
26
+ recipientEmail: z.string(),
27
+ recipientPhone: z.string(),
28
+ });
29
+
30
+ export const MosipInteropPayloadSchema = z.object({
31
+ trackingId: z.string(),
32
+ notification: MosipNotificationSchema,
33
+ requestFields: z.union([
34
+ BirthRequestFieldsSchema,
35
+ DeathRequestFieldsSchema,
36
+ CorrectionRequestFieldsSchema,
37
+ ]),
38
+ schemaJson: z.string().optional(),
39
+ metaInfo: z.record(z.string(), z.unknown()),
40
+ audit: z.record(z.string(), z.unknown()),
41
+ });
42
+
43
+ export const MosipCorrectionPayloadSchema = z.object({
44
+ trackingId: z.string(),
45
+ notification: MosipNotificationSchema,
46
+ requestFields: z.object({
47
+ VID: z.string(),
48
+ fullName: z.string().optional(),
49
+ dateOfBirth: z.string().optional(),
50
+ gender: z.string().optional(),
51
+ introducerInfoToken: z.string().optional(),
52
+ }),
53
+ schemaJson: z.string().optional(),
54
+ metaInfo: z.record(z.string(), z.unknown()),
55
+ audit: z.record(z.string(), z.unknown()),
56
+ });
57
+
58
+ const FieldValueSchema = z.custom<FieldValue>(() => true);
59
+
60
+ export const VerifyNidPayloadSchema = z.object({
61
+ nid: FieldValueSchema,
62
+ gender: FieldValueSchema.optional(),
63
+ dob: FieldValueSchema,
64
+ name: FieldValueSchema,
65
+ transactionId: z.string().optional(),
66
+ });
67
+
68
+ export const VerifyNidResponseSchema = z.union([
69
+ z.literal("verified"),
70
+ z.literal("failed"),
71
+ ]);
72
+
73
+ export const RegistrationEventResponseSchema = z.record(
74
+ z.string(),
75
+ z.unknown(),
76
+ );
77
+
78
+ export type BirthRequestFields = z.infer<typeof BirthRequestFieldsSchema>;
79
+ export type DeathRequestFields = z.infer<typeof DeathRequestFieldsSchema>;
80
+ export type CorrectionRequestFields = z.infer<typeof CorrectionRequestFieldsSchema>;
81
+ export type MosipInteropPayload = z.infer<typeof MosipInteropPayloadSchema>;
82
+ export type MosipCorrectionPayload = z.infer<typeof MosipCorrectionPayloadSchema>;
83
+ export type VerifyNidPayload = z.infer<typeof VerifyNidPayloadSchema>;
84
+ export type VerifyNidResponse = z.infer<typeof VerifyNidResponseSchema>;
33
85
 
34
86
  export interface VerificationStatus {
35
87
  father: boolean;
@@ -64,6 +116,7 @@ export const createMosipInteropClient = (
64
116
  ) => {
65
117
  return {
66
118
  register: async (payload: MosipInteropPayload) => {
119
+ const parsedPayload = MosipInteropPayloadSchema.parse(payload);
67
120
  const MOSIP_API_REGISTRATION_EVENT_URL = new URL(
68
121
  "./events/registration",
69
122
  url,
@@ -73,7 +126,7 @@ export const createMosipInteropClient = (
73
126
  MOSIP_API_REGISTRATION_EVENT_URL,
74
127
  {
75
128
  method: "POST",
76
- body: JSON.stringify(payload),
129
+ body: JSON.stringify(parsedPayload),
77
130
  headers: {
78
131
  Authorization: authorizationHeader,
79
132
  "content-type": "application/json",
@@ -85,14 +138,39 @@ export const createMosipInteropClient = (
85
138
  throw new Error(`Failed to register event: ${await response.text()}`);
86
139
  }
87
140
 
88
- return response.json();
141
+ return RegistrationEventResponseSchema.parse(await response.json());
142
+ },
143
+ updateBiographics: async (payload: MosipCorrectionPayload) => {
144
+ const parsedPayload = MosipCorrectionPayloadSchema.parse(payload);
145
+ const MOSIP_API_CORRECTION_EVENT_URL = new URL(
146
+ "./events/update-biographics",
147
+ url,
148
+ ).href;
149
+
150
+ const response = await fetchWithTimeout(MOSIP_API_CORRECTION_EVENT_URL, {
151
+ method: "POST",
152
+ body: JSON.stringify(parsedPayload),
153
+ headers: {
154
+ Authorization: authorizationHeader,
155
+ "content-type": "application/json",
156
+ },
157
+ });
158
+
159
+ if (!response.ok) {
160
+ throw new Error(
161
+ `Failed to update biographics: ${await response.text()}`,
162
+ );
163
+ }
164
+
165
+ return RegistrationEventResponseSchema.parse(await response.json());
89
166
  },
90
167
  verifyNid: async (payload: VerifyNidPayload) => {
168
+ const parsedPayload = VerifyNidPayloadSchema.parse(payload);
91
169
  const MOSIP_API_VERIFY_URL = new URL("./verify", url).href;
92
170
 
93
171
  const response = await fetchWithTimeout(MOSIP_API_VERIFY_URL, {
94
172
  method: "POST",
95
- body: JSON.stringify(payload),
173
+ body: JSON.stringify(parsedPayload),
96
174
  headers: {
97
175
  Authorization: authorizationHeader,
98
176
  "content-type": "application/json",
@@ -103,7 +181,7 @@ export const createMosipInteropClient = (
103
181
  throw new Error(`Failed to verify: ${await response.text()}`);
104
182
  }
105
183
 
106
- return response.text() as Promise<"verified" | "failed">;
184
+ return VerifyNidResponseSchema.parse(await response.text());
107
185
  },
108
186
  };
109
187
  };
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;