@openfn/language-ghana-nia 0.1.1 → 0.1.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/dist/index.cjs +77 -10
- package/dist/index.js +77 -10
- package/package.json +2 -1
- package/types/util.d.ts +1 -0
package/dist/index.cjs
CHANGED
|
@@ -80,6 +80,27 @@ var getClient = (baseUrl) => {
|
|
|
80
80
|
}
|
|
81
81
|
return client;
|
|
82
82
|
};
|
|
83
|
+
var validateRequestBody = (request2, sample) => {
|
|
84
|
+
const sampleKeys = Object.keys(sample);
|
|
85
|
+
const requestKeys = Object.keys(request2);
|
|
86
|
+
for (const key of sampleKeys) {
|
|
87
|
+
if (!requestKeys.includes(key)) {
|
|
88
|
+
console.log("Key missing:", key);
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
if (typeof sample[key] != typeof request2[key]) {
|
|
92
|
+
console.log("Key with wrong value type:", key);
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
if (typeof sample[key] === "object" && sample[key] !== null) {
|
|
96
|
+
if (!validateRequestBody(request2[key], sample[key])) {
|
|
97
|
+
console.log("Failed check at:", key);
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return true;
|
|
103
|
+
};
|
|
83
104
|
var setMockClient = (mockClient) => {
|
|
84
105
|
client = mockClient;
|
|
85
106
|
};
|
|
@@ -144,23 +165,69 @@ var request = (path, options) => {
|
|
|
144
165
|
|
|
145
166
|
// src/mock.js
|
|
146
167
|
var import_undici2 = require("undici");
|
|
147
|
-
var
|
|
148
|
-
|
|
149
|
-
|
|
168
|
+
var sampleRequestBody = {
|
|
169
|
+
merchantKey: "89487284-9083-4015-9128-91d8db7e023e",
|
|
170
|
+
babyData: {
|
|
171
|
+
dateOfBirth: "2024-03-05",
|
|
172
|
+
fatherName: "Nyarkoa Osei-Akoto",
|
|
173
|
+
forenames: "Kharis",
|
|
174
|
+
gender: "Female",
|
|
175
|
+
lightwaveETrackerID: "00313180/24-03",
|
|
176
|
+
motherName: "Gifty Osei-Akoto",
|
|
177
|
+
noSiblingsInDelivery: "0",
|
|
178
|
+
placeOfBirth: "New Market Health Centre",
|
|
179
|
+
surname: "Osei",
|
|
180
|
+
timeOfbirth: "09:34",
|
|
181
|
+
weightAtBirth: "2.7",
|
|
182
|
+
birthCertificateNumber: "011803-48-2024",
|
|
183
|
+
babyPicture: "...base64 encoded image goes here..."
|
|
184
|
+
},
|
|
185
|
+
personVouching: {
|
|
186
|
+
etrackerLightwaveID: "00313180/24-03",
|
|
187
|
+
ghanaCardPIN: "GHA-001097272-4",
|
|
188
|
+
relationToBaby: "Mother",
|
|
189
|
+
relativePhone: "0248403076",
|
|
190
|
+
relativePicture: "...base64 encoded image goes here..."
|
|
150
191
|
}
|
|
151
192
|
};
|
|
193
|
+
var nationalIdSampleResponse = {
|
|
194
|
+
data: {
|
|
195
|
+
babyPin: "GHA-000000000-1",
|
|
196
|
+
voucherPin: "GHA-000000000-4",
|
|
197
|
+
etrackerLightwaveId: "00000000/24-03",
|
|
198
|
+
lightwaveEtrackerId: null
|
|
199
|
+
},
|
|
200
|
+
success: true,
|
|
201
|
+
code: "00",
|
|
202
|
+
msg: "Saved Successfully"
|
|
203
|
+
};
|
|
152
204
|
function createServer(url = "https://selfie.imsgh.org:2035") {
|
|
153
205
|
const agent = new import_undici2.MockAgent();
|
|
154
206
|
agent.disableNetConnect();
|
|
155
207
|
const mockPool = agent.get(url);
|
|
156
208
|
const sendNiaData = (req) => {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
209
|
+
if (validateRequestBody(JSON.parse(req.body), sampleRequestBody)) {
|
|
210
|
+
return {
|
|
211
|
+
statusCode: 200,
|
|
212
|
+
responseOptions: {
|
|
213
|
+
headers: { "Content-Type": "application/json" }
|
|
214
|
+
},
|
|
215
|
+
data: JSON.stringify(nationalIdSampleResponse)
|
|
216
|
+
};
|
|
217
|
+
} else {
|
|
218
|
+
return {
|
|
219
|
+
statusCode: 404,
|
|
220
|
+
responseOptions: {
|
|
221
|
+
headers: { "Content-Type": "application/json" }
|
|
222
|
+
},
|
|
223
|
+
data: {
|
|
224
|
+
success: false,
|
|
225
|
+
code: "05",
|
|
226
|
+
data: null,
|
|
227
|
+
msg: "Error in Verifiation Process"
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
}
|
|
164
231
|
};
|
|
165
232
|
mockPool.intercept({ method: "post", path: /awopa\/api\/v1\/baby\/registration/ }).reply(sendNiaData).persist();
|
|
166
233
|
return {
|
package/dist/index.js
CHANGED
|
@@ -43,6 +43,27 @@ var getClient = (baseUrl) => {
|
|
|
43
43
|
}
|
|
44
44
|
return client;
|
|
45
45
|
};
|
|
46
|
+
var validateRequestBody = (request2, sample) => {
|
|
47
|
+
const sampleKeys = Object.keys(sample);
|
|
48
|
+
const requestKeys = Object.keys(request2);
|
|
49
|
+
for (const key of sampleKeys) {
|
|
50
|
+
if (!requestKeys.includes(key)) {
|
|
51
|
+
console.log("Key missing:", key);
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
if (typeof sample[key] != typeof request2[key]) {
|
|
55
|
+
console.log("Key with wrong value type:", key);
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
if (typeof sample[key] === "object" && sample[key] !== null) {
|
|
59
|
+
if (!validateRequestBody(request2[key], sample[key])) {
|
|
60
|
+
console.log("Failed check at:", key);
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return true;
|
|
66
|
+
};
|
|
46
67
|
var setMockClient = (mockClient) => {
|
|
47
68
|
client = mockClient;
|
|
48
69
|
};
|
|
@@ -107,23 +128,69 @@ var request = (path, options) => {
|
|
|
107
128
|
|
|
108
129
|
// src/mock.js
|
|
109
130
|
import { MockAgent } from "undici";
|
|
110
|
-
var
|
|
111
|
-
|
|
112
|
-
|
|
131
|
+
var sampleRequestBody = {
|
|
132
|
+
merchantKey: "89487284-9083-4015-9128-91d8db7e023e",
|
|
133
|
+
babyData: {
|
|
134
|
+
dateOfBirth: "2024-03-05",
|
|
135
|
+
fatherName: "Nyarkoa Osei-Akoto",
|
|
136
|
+
forenames: "Kharis",
|
|
137
|
+
gender: "Female",
|
|
138
|
+
lightwaveETrackerID: "00313180/24-03",
|
|
139
|
+
motherName: "Gifty Osei-Akoto",
|
|
140
|
+
noSiblingsInDelivery: "0",
|
|
141
|
+
placeOfBirth: "New Market Health Centre",
|
|
142
|
+
surname: "Osei",
|
|
143
|
+
timeOfbirth: "09:34",
|
|
144
|
+
weightAtBirth: "2.7",
|
|
145
|
+
birthCertificateNumber: "011803-48-2024",
|
|
146
|
+
babyPicture: "...base64 encoded image goes here..."
|
|
147
|
+
},
|
|
148
|
+
personVouching: {
|
|
149
|
+
etrackerLightwaveID: "00313180/24-03",
|
|
150
|
+
ghanaCardPIN: "GHA-001097272-4",
|
|
151
|
+
relationToBaby: "Mother",
|
|
152
|
+
relativePhone: "0248403076",
|
|
153
|
+
relativePicture: "...base64 encoded image goes here..."
|
|
113
154
|
}
|
|
114
155
|
};
|
|
156
|
+
var nationalIdSampleResponse = {
|
|
157
|
+
data: {
|
|
158
|
+
babyPin: "GHA-000000000-1",
|
|
159
|
+
voucherPin: "GHA-000000000-4",
|
|
160
|
+
etrackerLightwaveId: "00000000/24-03",
|
|
161
|
+
lightwaveEtrackerId: null
|
|
162
|
+
},
|
|
163
|
+
success: true,
|
|
164
|
+
code: "00",
|
|
165
|
+
msg: "Saved Successfully"
|
|
166
|
+
};
|
|
115
167
|
function createServer(url = "https://selfie.imsgh.org:2035") {
|
|
116
168
|
const agent = new MockAgent();
|
|
117
169
|
agent.disableNetConnect();
|
|
118
170
|
const mockPool = agent.get(url);
|
|
119
171
|
const sendNiaData = (req) => {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
172
|
+
if (validateRequestBody(JSON.parse(req.body), sampleRequestBody)) {
|
|
173
|
+
return {
|
|
174
|
+
statusCode: 200,
|
|
175
|
+
responseOptions: {
|
|
176
|
+
headers: { "Content-Type": "application/json" }
|
|
177
|
+
},
|
|
178
|
+
data: JSON.stringify(nationalIdSampleResponse)
|
|
179
|
+
};
|
|
180
|
+
} else {
|
|
181
|
+
return {
|
|
182
|
+
statusCode: 404,
|
|
183
|
+
responseOptions: {
|
|
184
|
+
headers: { "Content-Type": "application/json" }
|
|
185
|
+
},
|
|
186
|
+
data: {
|
|
187
|
+
success: false,
|
|
188
|
+
code: "05",
|
|
189
|
+
data: null,
|
|
190
|
+
msg: "Error in Verifiation Process"
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
}
|
|
127
194
|
};
|
|
128
195
|
mockPool.intercept({ method: "post", path: /awopa\/api\/v1\/baby\/registration/ }).reply(sendNiaData).persist();
|
|
129
196
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfn/language-ghana-nia",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "OpenFn ghana-nia adaptor",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"configuration-schema.json"
|
|
21
21
|
],
|
|
22
22
|
"dependencies": {
|
|
23
|
+
"ajv": "6",
|
|
23
24
|
"undici": "^5.22.1",
|
|
24
25
|
"@openfn/language-common": "2.3.0"
|
|
25
26
|
},
|
package/types/util.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export function validateRequestBody(request: any, sample: any): boolean;
|
|
1
2
|
export function setMockClient(mockClient: any): void;
|
|
2
3
|
export function prepareNextState(state: any, response: any): Promise<any>;
|
|
3
4
|
export function request(path: any, options: any): (state: any) => Promise<any>;
|