@opencrvs/mosip 2.0.0 → 2.1.0-rc.65b5bdf
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/README.md +9 -1
- package/build/api.d.ts +3 -3
- package/build/api.js +25 -25
- package/build/index.d.ts +1 -1
- package/build/index.js +10 -0
- package/opencrvs-mosip-2.1.0-rc.65b5bdf.tgz +0 -0
- package/package.json +22 -7
- package/src/api.ts +92 -81
- package/src/index.ts +11 -1
- package/tsconfig.json +5 -3
package/README.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
1
|
# @opencrvs/mosip
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Helpers for wiring an OpenCRVS country configuration to the MOSIP integration
|
|
4
|
+
API. Published to npm at core's version, and consumed by country configs as
|
|
5
|
+
`@opencrvs/mosip` — see `packages/testland` for a worked example.
|
|
6
|
+
|
|
7
|
+
The service these helpers talk to is [`packages/mosip-api`](../mosip-api), and
|
|
8
|
+
the mock MOSIP and e-Signet servers used in development and e2e are
|
|
9
|
+
[`packages/mosip-mock`](../mosip-mock) and
|
|
10
|
+
[`packages/esignet-mock`](../esignet-mock). All three are deployed by the
|
|
11
|
+
`charts/opencrvs-mosip` Helm chart.
|
package/build/api.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { FieldValue } from
|
|
2
|
-
import { z } from
|
|
1
|
+
import type { FieldValue } from '@opencrvs/toolkit/events';
|
|
2
|
+
import { z } from 'zod';
|
|
3
3
|
export declare const BirthRequestFieldsSchema: z.ZodObject<{
|
|
4
4
|
birthCertificateNumber: z.ZodString;
|
|
5
5
|
deathCertificateNumber: z.ZodOptional<z.ZodUndefined>;
|
|
@@ -92,5 +92,5 @@ export interface VerificationStatus {
|
|
|
92
92
|
export declare const createMosipInteropClient: (url: string, authorizationHeader: string) => {
|
|
93
93
|
register: (payload: MosipInteropPayload) => Promise<Record<string, unknown>>;
|
|
94
94
|
updateBiographics: (payload: MosipCorrectionPayload) => Promise<Record<string, unknown>>;
|
|
95
|
-
verifyNid: (payload: VerifyNidPayload) => Promise<"
|
|
95
|
+
verifyNid: (payload: VerifyNidPayload) => Promise<"failed" | "verified">;
|
|
96
96
|
};
|
package/build/api.js
CHANGED
|
@@ -4,11 +4,11 @@ exports.createMosipInteropClient = exports.RegistrationEventResponseSchema = exp
|
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
exports.BirthRequestFieldsSchema = zod_1.z.looseObject({
|
|
6
6
|
birthCertificateNumber: zod_1.z.string(),
|
|
7
|
-
deathCertificateNumber: zod_1.z.undefined().optional()
|
|
7
|
+
deathCertificateNumber: zod_1.z.undefined().optional()
|
|
8
8
|
});
|
|
9
9
|
exports.DeathRequestFieldsSchema = zod_1.z.looseObject({
|
|
10
10
|
deathCertificateNumber: zod_1.z.string(),
|
|
11
|
-
birthCertificateNumber: zod_1.z.undefined().optional()
|
|
11
|
+
birthCertificateNumber: zod_1.z.undefined().optional()
|
|
12
12
|
});
|
|
13
13
|
exports.CorrectionRequestFieldsSchema = zod_1.z.looseObject({
|
|
14
14
|
VID: zod_1.z.string(),
|
|
@@ -17,12 +17,12 @@ exports.CorrectionRequestFieldsSchema = zod_1.z.looseObject({
|
|
|
17
17
|
gender: zod_1.z.string().optional(),
|
|
18
18
|
introducerInfoToken: zod_1.z.string().optional(),
|
|
19
19
|
birthCertificateNumber: zod_1.z.undefined().optional(),
|
|
20
|
-
deathCertificateNumber: zod_1.z.undefined().optional()
|
|
20
|
+
deathCertificateNumber: zod_1.z.undefined().optional()
|
|
21
21
|
});
|
|
22
22
|
exports.MosipNotificationSchema = zod_1.z.object({
|
|
23
23
|
recipientFullName: zod_1.z.string(),
|
|
24
24
|
recipientEmail: zod_1.z.string(),
|
|
25
|
-
recipientPhone: zod_1.z.string()
|
|
25
|
+
recipientPhone: zod_1.z.string()
|
|
26
26
|
});
|
|
27
27
|
exports.MosipInteropPayloadSchema = zod_1.z.object({
|
|
28
28
|
trackingId: zod_1.z.string(),
|
|
@@ -30,11 +30,11 @@ exports.MosipInteropPayloadSchema = zod_1.z.object({
|
|
|
30
30
|
requestFields: zod_1.z.union([
|
|
31
31
|
exports.BirthRequestFieldsSchema,
|
|
32
32
|
exports.DeathRequestFieldsSchema,
|
|
33
|
-
exports.CorrectionRequestFieldsSchema
|
|
33
|
+
exports.CorrectionRequestFieldsSchema
|
|
34
34
|
]),
|
|
35
35
|
schemaJson: zod_1.z.string().optional(),
|
|
36
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())
|
|
37
|
+
audit: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown())
|
|
38
38
|
});
|
|
39
39
|
exports.MosipCorrectionPayloadSchema = zod_1.z.object({
|
|
40
40
|
trackingId: zod_1.z.string(),
|
|
@@ -44,11 +44,11 @@ exports.MosipCorrectionPayloadSchema = zod_1.z.object({
|
|
|
44
44
|
fullName: zod_1.z.string().optional(),
|
|
45
45
|
dateOfBirth: zod_1.z.string().optional(),
|
|
46
46
|
gender: zod_1.z.string().optional(),
|
|
47
|
-
introducerInfoToken: zod_1.z.string().optional()
|
|
47
|
+
introducerInfoToken: zod_1.z.string().optional()
|
|
48
48
|
}),
|
|
49
49
|
schemaJson: zod_1.z.string().optional(),
|
|
50
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())
|
|
51
|
+
audit: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown())
|
|
52
52
|
});
|
|
53
53
|
const FieldValueSchema = zod_1.z.custom(() => true);
|
|
54
54
|
exports.VerifyNidPayloadSchema = zod_1.z.object({
|
|
@@ -56,11 +56,11 @@ exports.VerifyNidPayloadSchema = zod_1.z.object({
|
|
|
56
56
|
gender: FieldValueSchema.optional(),
|
|
57
57
|
dob: FieldValueSchema,
|
|
58
58
|
name: FieldValueSchema,
|
|
59
|
-
transactionId: zod_1.z.string().optional()
|
|
59
|
+
transactionId: zod_1.z.string().optional()
|
|
60
60
|
});
|
|
61
61
|
exports.VerifyNidResponseSchema = zod_1.z.union([
|
|
62
|
-
zod_1.z.literal(
|
|
63
|
-
zod_1.z.literal(
|
|
62
|
+
zod_1.z.literal('verified'),
|
|
63
|
+
zod_1.z.literal('failed')
|
|
64
64
|
]);
|
|
65
65
|
exports.RegistrationEventResponseSchema = zod_1.z.record(zod_1.z.string(), zod_1.z.unknown());
|
|
66
66
|
async function fetchWithTimeout(input, init = {}, timeoutMs = 15000) {
|
|
@@ -69,7 +69,7 @@ async function fetchWithTimeout(input, init = {}, timeoutMs = 15000) {
|
|
|
69
69
|
try {
|
|
70
70
|
const response = await fetch(input, {
|
|
71
71
|
...init,
|
|
72
|
-
signal: controller.signal
|
|
72
|
+
signal: controller.signal
|
|
73
73
|
});
|
|
74
74
|
return response;
|
|
75
75
|
}
|
|
@@ -81,14 +81,14 @@ const createMosipInteropClient = (url, authorizationHeader) => {
|
|
|
81
81
|
return {
|
|
82
82
|
register: async (payload) => {
|
|
83
83
|
const parsedPayload = exports.MosipInteropPayloadSchema.parse(payload);
|
|
84
|
-
const MOSIP_API_REGISTRATION_EVENT_URL = new URL(
|
|
84
|
+
const MOSIP_API_REGISTRATION_EVENT_URL = new URL('./events/registration', url).href;
|
|
85
85
|
const response = await fetchWithTimeout(MOSIP_API_REGISTRATION_EVENT_URL, {
|
|
86
|
-
method:
|
|
86
|
+
method: 'POST',
|
|
87
87
|
body: JSON.stringify(parsedPayload),
|
|
88
88
|
headers: {
|
|
89
89
|
Authorization: authorizationHeader,
|
|
90
|
-
|
|
91
|
-
}
|
|
90
|
+
'content-type': 'application/json'
|
|
91
|
+
}
|
|
92
92
|
});
|
|
93
93
|
if (!response.ok) {
|
|
94
94
|
throw new Error(`Failed to register event: ${await response.text()}`);
|
|
@@ -97,14 +97,14 @@ const createMosipInteropClient = (url, authorizationHeader) => {
|
|
|
97
97
|
},
|
|
98
98
|
updateBiographics: async (payload) => {
|
|
99
99
|
const parsedPayload = exports.MosipCorrectionPayloadSchema.parse(payload);
|
|
100
|
-
const MOSIP_API_CORRECTION_EVENT_URL = new URL(
|
|
100
|
+
const MOSIP_API_CORRECTION_EVENT_URL = new URL('./events/update-biographics', url).href;
|
|
101
101
|
const response = await fetchWithTimeout(MOSIP_API_CORRECTION_EVENT_URL, {
|
|
102
|
-
method:
|
|
102
|
+
method: 'POST',
|
|
103
103
|
body: JSON.stringify(parsedPayload),
|
|
104
104
|
headers: {
|
|
105
105
|
Authorization: authorizationHeader,
|
|
106
|
-
|
|
107
|
-
}
|
|
106
|
+
'content-type': 'application/json'
|
|
107
|
+
}
|
|
108
108
|
});
|
|
109
109
|
if (!response.ok) {
|
|
110
110
|
throw new Error(`Failed to update biographics: ${await response.text()}`);
|
|
@@ -113,20 +113,20 @@ const createMosipInteropClient = (url, authorizationHeader) => {
|
|
|
113
113
|
},
|
|
114
114
|
verifyNid: async (payload) => {
|
|
115
115
|
const parsedPayload = exports.VerifyNidPayloadSchema.parse(payload);
|
|
116
|
-
const MOSIP_API_VERIFY_URL = new URL(
|
|
116
|
+
const MOSIP_API_VERIFY_URL = new URL('./verify', url).href;
|
|
117
117
|
const response = await fetchWithTimeout(MOSIP_API_VERIFY_URL, {
|
|
118
|
-
method:
|
|
118
|
+
method: 'POST',
|
|
119
119
|
body: JSON.stringify(parsedPayload),
|
|
120
120
|
headers: {
|
|
121
121
|
Authorization: authorizationHeader,
|
|
122
|
-
|
|
123
|
-
}
|
|
122
|
+
'content-type': 'application/json'
|
|
123
|
+
}
|
|
124
124
|
});
|
|
125
125
|
if (!response.ok) {
|
|
126
126
|
throw new Error(`Failed to verify: ${await response.text()}`);
|
|
127
127
|
}
|
|
128
128
|
return exports.VerifyNidResponseSchema.parse(await response.text());
|
|
129
|
-
}
|
|
129
|
+
}
|
|
130
130
|
};
|
|
131
131
|
};
|
|
132
132
|
exports.createMosipInteropClient = createMosipInteropClient;
|
package/build/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from './api';
|
package/build/index.js
CHANGED
|
@@ -14,4 +14,14 @@ 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
|
+
/*
|
|
18
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
19
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
20
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
21
|
+
*
|
|
22
|
+
* OpenCRVS is also distributed under the terms of the Civil Registration
|
|
23
|
+
* & Healthcare Disclaimer located at http://opencrvs.org/license.
|
|
24
|
+
*
|
|
25
|
+
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
|
|
26
|
+
*/
|
|
17
27
|
__exportStar(require("./api"), exports);
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opencrvs/mosip",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.1.0-rc.65b5bdf",
|
|
4
|
+
"description": "Helpers for wiring an OpenCRVS country configuration to the MOSIP integration API",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/opencrvs/opencrvs-core.git"
|
|
8
|
+
},
|
|
4
9
|
"license": "MPL-2.0",
|
|
5
10
|
"main": "./build/index.js",
|
|
6
11
|
"exports": {
|
|
@@ -8,20 +13,30 @@
|
|
|
8
13
|
"./api": "./build/api.js"
|
|
9
14
|
},
|
|
10
15
|
"typings": "build/index.d.ts",
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": "22.x.x"
|
|
18
|
+
},
|
|
11
19
|
"scripts": {
|
|
12
|
-
"build": "tsc"
|
|
20
|
+
"build": "tsc",
|
|
21
|
+
"test:compilation": "tsc --noEmit"
|
|
13
22
|
},
|
|
14
23
|
"dependencies": {
|
|
15
|
-
"zod": "^4.
|
|
24
|
+
"zod": "^4.4.3"
|
|
16
25
|
},
|
|
17
26
|
"devDependencies": {
|
|
18
|
-
"@opencrvs/toolkit": "
|
|
27
|
+
"@opencrvs/toolkit": "workspace:*",
|
|
19
28
|
"@types/hapi__hapi": "^20.0.0",
|
|
20
29
|
"@types/node-fetch": "^2.6.11",
|
|
21
|
-
"node-fetch": "2.6.7"
|
|
22
|
-
"typescript": "^5.6.3"
|
|
30
|
+
"node-fetch": "2.6.7"
|
|
23
31
|
},
|
|
24
32
|
"peerDependencies": {
|
|
25
33
|
"node-fetch": "2.6.7"
|
|
26
|
-
}
|
|
34
|
+
},
|
|
35
|
+
"keywords": [],
|
|
36
|
+
"author": "",
|
|
37
|
+
"type": "commonjs",
|
|
38
|
+
"bugs": {
|
|
39
|
+
"url": "https://github.com/opencrvs/opencrvs-core/issues"
|
|
40
|
+
},
|
|
41
|
+
"homepage": "https://github.com/opencrvs/opencrvs-core#readme"
|
|
27
42
|
}
|
package/src/api.ts
CHANGED
|
@@ -1,15 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/*
|
|
2
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
3
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
4
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
5
|
+
*
|
|
6
|
+
* OpenCRVS is also distributed under the terms of the Civil Registration
|
|
7
|
+
* & Healthcare Disclaimer located at http://opencrvs.org/license.
|
|
8
|
+
*
|
|
9
|
+
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
|
|
10
|
+
*/
|
|
11
|
+
import type { FieldValue } from '@opencrvs/toolkit/events'
|
|
12
|
+
import { z } from 'zod'
|
|
3
13
|
|
|
4
14
|
export const BirthRequestFieldsSchema = z.looseObject({
|
|
5
15
|
birthCertificateNumber: z.string(),
|
|
6
|
-
deathCertificateNumber: z.undefined().optional()
|
|
7
|
-
})
|
|
16
|
+
deathCertificateNumber: z.undefined().optional()
|
|
17
|
+
})
|
|
8
18
|
|
|
9
19
|
export const DeathRequestFieldsSchema = z.looseObject({
|
|
10
20
|
deathCertificateNumber: z.string(),
|
|
11
|
-
birthCertificateNumber: z.undefined().optional()
|
|
12
|
-
})
|
|
21
|
+
birthCertificateNumber: z.undefined().optional()
|
|
22
|
+
})
|
|
13
23
|
|
|
14
24
|
export const CorrectionRequestFieldsSchema = z.looseObject({
|
|
15
25
|
VID: z.string(),
|
|
@@ -18,14 +28,14 @@ export const CorrectionRequestFieldsSchema = z.looseObject({
|
|
|
18
28
|
gender: z.string().optional(),
|
|
19
29
|
introducerInfoToken: z.string().optional(),
|
|
20
30
|
birthCertificateNumber: z.undefined().optional(),
|
|
21
|
-
deathCertificateNumber: z.undefined().optional()
|
|
22
|
-
})
|
|
31
|
+
deathCertificateNumber: z.undefined().optional()
|
|
32
|
+
})
|
|
23
33
|
|
|
24
34
|
export const MosipNotificationSchema = z.object({
|
|
25
35
|
recipientFullName: z.string(),
|
|
26
36
|
recipientEmail: z.string(),
|
|
27
|
-
recipientPhone: z.string()
|
|
28
|
-
})
|
|
37
|
+
recipientPhone: z.string()
|
|
38
|
+
})
|
|
29
39
|
|
|
30
40
|
export const MosipInteropPayloadSchema = z.object({
|
|
31
41
|
trackingId: z.string(),
|
|
@@ -33,12 +43,12 @@ export const MosipInteropPayloadSchema = z.object({
|
|
|
33
43
|
requestFields: z.union([
|
|
34
44
|
BirthRequestFieldsSchema,
|
|
35
45
|
DeathRequestFieldsSchema,
|
|
36
|
-
CorrectionRequestFieldsSchema
|
|
46
|
+
CorrectionRequestFieldsSchema
|
|
37
47
|
]),
|
|
38
48
|
schemaJson: z.string().optional(),
|
|
39
49
|
metaInfo: z.record(z.string(), z.unknown()),
|
|
40
|
-
audit: z.record(z.string(), z.unknown())
|
|
41
|
-
})
|
|
50
|
+
audit: z.record(z.string(), z.unknown())
|
|
51
|
+
})
|
|
42
52
|
|
|
43
53
|
export const MosipCorrectionPayloadSchema = z.object({
|
|
44
54
|
trackingId: z.string(),
|
|
@@ -48,140 +58,141 @@ export const MosipCorrectionPayloadSchema = z.object({
|
|
|
48
58
|
fullName: z.string().optional(),
|
|
49
59
|
dateOfBirth: z.string().optional(),
|
|
50
60
|
gender: z.string().optional(),
|
|
51
|
-
introducerInfoToken: z.string().optional()
|
|
61
|
+
introducerInfoToken: z.string().optional()
|
|
52
62
|
}),
|
|
53
63
|
schemaJson: z.string().optional(),
|
|
54
64
|
metaInfo: z.record(z.string(), z.unknown()),
|
|
55
|
-
audit: z.record(z.string(), z.unknown())
|
|
56
|
-
})
|
|
65
|
+
audit: z.record(z.string(), z.unknown())
|
|
66
|
+
})
|
|
57
67
|
|
|
58
|
-
const FieldValueSchema = z.custom<FieldValue>(() => true)
|
|
68
|
+
const FieldValueSchema = z.custom<FieldValue>(() => true)
|
|
59
69
|
|
|
60
70
|
export const VerifyNidPayloadSchema = z.object({
|
|
61
71
|
nid: FieldValueSchema,
|
|
62
72
|
gender: FieldValueSchema.optional(),
|
|
63
73
|
dob: FieldValueSchema,
|
|
64
74
|
name: FieldValueSchema,
|
|
65
|
-
transactionId: z.string().optional()
|
|
66
|
-
})
|
|
75
|
+
transactionId: z.string().optional()
|
|
76
|
+
})
|
|
67
77
|
|
|
68
78
|
export const VerifyNidResponseSchema = z.union([
|
|
69
|
-
z.literal(
|
|
70
|
-
z.literal(
|
|
71
|
-
])
|
|
72
|
-
|
|
73
|
-
export const RegistrationEventResponseSchema = z.record(
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
export type
|
|
81
|
-
export type
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
export type
|
|
79
|
+
z.literal('verified'),
|
|
80
|
+
z.literal('failed')
|
|
81
|
+
])
|
|
82
|
+
|
|
83
|
+
export const RegistrationEventResponseSchema = z.record(z.string(), z.unknown())
|
|
84
|
+
|
|
85
|
+
export type BirthRequestFields = z.infer<typeof BirthRequestFieldsSchema>
|
|
86
|
+
export type DeathRequestFields = z.infer<typeof DeathRequestFieldsSchema>
|
|
87
|
+
export type CorrectionRequestFields = z.infer<
|
|
88
|
+
typeof CorrectionRequestFieldsSchema
|
|
89
|
+
>
|
|
90
|
+
export type MosipInteropPayload = z.infer<typeof MosipInteropPayloadSchema>
|
|
91
|
+
export type MosipCorrectionPayload = z.infer<
|
|
92
|
+
typeof MosipCorrectionPayloadSchema
|
|
93
|
+
>
|
|
94
|
+
export type VerifyNidPayload = z.infer<typeof VerifyNidPayloadSchema>
|
|
95
|
+
export type VerifyNidResponse = z.infer<typeof VerifyNidResponseSchema>
|
|
85
96
|
|
|
86
97
|
export interface VerificationStatus {
|
|
87
|
-
father: boolean
|
|
88
|
-
mother: boolean
|
|
89
|
-
informant: boolean
|
|
90
|
-
deceased: boolean
|
|
91
|
-
spouse: boolean
|
|
98
|
+
father: boolean
|
|
99
|
+
mother: boolean
|
|
100
|
+
informant: boolean
|
|
101
|
+
deceased: boolean
|
|
102
|
+
spouse: boolean
|
|
92
103
|
}
|
|
93
104
|
|
|
94
105
|
async function fetchWithTimeout(
|
|
95
106
|
input: RequestInfo,
|
|
96
107
|
init: RequestInit = {},
|
|
97
|
-
timeoutMs = 15000
|
|
108
|
+
timeoutMs = 15000
|
|
98
109
|
): Promise<Response> {
|
|
99
|
-
const controller = new AbortController()
|
|
100
|
-
const timeout = setTimeout(() => controller.abort(), timeoutMs)
|
|
110
|
+
const controller = new AbortController()
|
|
111
|
+
const timeout = setTimeout(() => controller.abort(), timeoutMs)
|
|
101
112
|
|
|
102
113
|
try {
|
|
103
114
|
const response = await fetch(input, {
|
|
104
115
|
...init,
|
|
105
|
-
signal: controller.signal
|
|
106
|
-
})
|
|
107
|
-
return response
|
|
116
|
+
signal: controller.signal
|
|
117
|
+
})
|
|
118
|
+
return response
|
|
108
119
|
} finally {
|
|
109
|
-
clearTimeout(timeout)
|
|
120
|
+
clearTimeout(timeout)
|
|
110
121
|
}
|
|
111
122
|
}
|
|
112
123
|
|
|
113
124
|
export const createMosipInteropClient = (
|
|
114
125
|
url: string,
|
|
115
|
-
authorizationHeader: string
|
|
126
|
+
authorizationHeader: string
|
|
116
127
|
) => {
|
|
117
128
|
return {
|
|
118
129
|
register: async (payload: MosipInteropPayload) => {
|
|
119
|
-
const parsedPayload = MosipInteropPayloadSchema.parse(payload)
|
|
130
|
+
const parsedPayload = MosipInteropPayloadSchema.parse(payload)
|
|
120
131
|
const MOSIP_API_REGISTRATION_EVENT_URL = new URL(
|
|
121
|
-
|
|
122
|
-
url
|
|
123
|
-
).href
|
|
132
|
+
'./events/registration',
|
|
133
|
+
url
|
|
134
|
+
).href
|
|
124
135
|
|
|
125
136
|
const response = await fetchWithTimeout(
|
|
126
137
|
MOSIP_API_REGISTRATION_EVENT_URL,
|
|
127
138
|
{
|
|
128
|
-
method:
|
|
139
|
+
method: 'POST',
|
|
129
140
|
body: JSON.stringify(parsedPayload),
|
|
130
141
|
headers: {
|
|
131
142
|
Authorization: authorizationHeader,
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
)
|
|
143
|
+
'content-type': 'application/json'
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
)
|
|
136
147
|
|
|
137
148
|
if (!response.ok) {
|
|
138
|
-
throw new Error(`Failed to register event: ${await response.text()}`)
|
|
149
|
+
throw new Error(`Failed to register event: ${await response.text()}`)
|
|
139
150
|
}
|
|
140
151
|
|
|
141
|
-
return RegistrationEventResponseSchema.parse(await response.json())
|
|
152
|
+
return RegistrationEventResponseSchema.parse(await response.json())
|
|
142
153
|
},
|
|
143
154
|
updateBiographics: async (payload: MosipCorrectionPayload) => {
|
|
144
|
-
const parsedPayload = MosipCorrectionPayloadSchema.parse(payload)
|
|
155
|
+
const parsedPayload = MosipCorrectionPayloadSchema.parse(payload)
|
|
145
156
|
const MOSIP_API_CORRECTION_EVENT_URL = new URL(
|
|
146
|
-
|
|
147
|
-
url
|
|
148
|
-
).href
|
|
157
|
+
'./events/update-biographics',
|
|
158
|
+
url
|
|
159
|
+
).href
|
|
149
160
|
|
|
150
161
|
const response = await fetchWithTimeout(MOSIP_API_CORRECTION_EVENT_URL, {
|
|
151
|
-
method:
|
|
162
|
+
method: 'POST',
|
|
152
163
|
body: JSON.stringify(parsedPayload),
|
|
153
164
|
headers: {
|
|
154
165
|
Authorization: authorizationHeader,
|
|
155
|
-
|
|
156
|
-
}
|
|
157
|
-
})
|
|
166
|
+
'content-type': 'application/json'
|
|
167
|
+
}
|
|
168
|
+
})
|
|
158
169
|
|
|
159
170
|
if (!response.ok) {
|
|
160
171
|
throw new Error(
|
|
161
|
-
`Failed to update biographics: ${await response.text()}
|
|
162
|
-
)
|
|
172
|
+
`Failed to update biographics: ${await response.text()}`
|
|
173
|
+
)
|
|
163
174
|
}
|
|
164
175
|
|
|
165
|
-
return RegistrationEventResponseSchema.parse(await response.json())
|
|
176
|
+
return RegistrationEventResponseSchema.parse(await response.json())
|
|
166
177
|
},
|
|
167
178
|
verifyNid: async (payload: VerifyNidPayload) => {
|
|
168
|
-
const parsedPayload = VerifyNidPayloadSchema.parse(payload)
|
|
169
|
-
const MOSIP_API_VERIFY_URL = new URL(
|
|
179
|
+
const parsedPayload = VerifyNidPayloadSchema.parse(payload)
|
|
180
|
+
const MOSIP_API_VERIFY_URL = new URL('./verify', url).href
|
|
170
181
|
|
|
171
182
|
const response = await fetchWithTimeout(MOSIP_API_VERIFY_URL, {
|
|
172
|
-
method:
|
|
183
|
+
method: 'POST',
|
|
173
184
|
body: JSON.stringify(parsedPayload),
|
|
174
185
|
headers: {
|
|
175
186
|
Authorization: authorizationHeader,
|
|
176
|
-
|
|
177
|
-
}
|
|
178
|
-
})
|
|
187
|
+
'content-type': 'application/json'
|
|
188
|
+
}
|
|
189
|
+
})
|
|
179
190
|
|
|
180
191
|
if (!response.ok) {
|
|
181
|
-
throw new Error(`Failed to verify: ${await response.text()}`)
|
|
192
|
+
throw new Error(`Failed to verify: ${await response.text()}`)
|
|
182
193
|
}
|
|
183
194
|
|
|
184
|
-
return VerifyNidResponseSchema.parse(await response.text())
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
195
|
+
return VerifyNidResponseSchema.parse(await response.text())
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
/*
|
|
2
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
3
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
4
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
5
|
+
*
|
|
6
|
+
* OpenCRVS is also distributed under the terms of the Civil Registration
|
|
7
|
+
* & Healthcare Disclaimer located at http://opencrvs.org/license.
|
|
8
|
+
*
|
|
9
|
+
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
|
|
10
|
+
*/
|
|
11
|
+
export * from './api'
|