@openfn/language-ghana-nia 0.1.0 → 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/ast.json CHANGED
@@ -67,7 +67,7 @@
67
67
  "tags": [
68
68
  {
69
69
  "title": "example",
70
- "description": "registerChild({\n child: {},\n mother: {},\n father: {},\n health_facility: {},\n birth_informant: {}\n})"
70
+ "description": "registerChild({\n babyData: {\n dateOfBirth: \"string\",\n fatherName: \"string\",\n forenames: \"string\",\n gender: \"string\",\n lightwaveETrackerID: \"string\",\n motherName: \"string\",\n noSiblingsInDelivery: \"string\",\n placeOfBirth: \"string\",\n surname: \"string\",\n timeOfbirth: \"string\",\n weightAtBirth: \"string\",\n babyPicture: \"string\"\n },\n personVouching: {\n etrackerLightwaveID: \"string\",\n ghanaCardPIN: \"string\",\n relationToBaby: \"string\",\n relativePhone: \"string\",\n relativePicture: \"string\"\n },\n merchantKey: \"XXXXXXXXXXXXXXXXXXXXXX\"\n})"
71
71
  },
72
72
  {
73
73
  "title": "function",
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 niaResponseSample = {
148
- data: {
149
- babyPin: "GH-6326223626-3"
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
- return {
158
- statusCode: 200,
159
- responseOptions: {
160
- headers: { "Content-Type": "application/json" }
161
- },
162
- data: JSON.stringify(niaResponseSample)
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 niaResponseSample = {
111
- data: {
112
- babyPin: "GH-6326223626-3"
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
- return {
121
- statusCode: 200,
122
- responseOptions: {
123
- headers: { "Content-Type": "application/json" }
124
- },
125
- data: JSON.stringify(niaResponseSample)
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.0",
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
  },
@@ -42,11 +42,28 @@ export function post(path: string, data: object): Operation;
42
42
  * Generate a national ID
43
43
  * @example
44
44
  * registerChild({
45
- * child: {},
46
- * mother: {},
47
- * father: {},
48
- * health_facility: {},
49
- * birth_informant: {}
45
+ * babyData: {
46
+ * dateOfBirth: "string",
47
+ * fatherName: "string",
48
+ * forenames: "string",
49
+ * gender: "string",
50
+ * lightwaveETrackerID: "string",
51
+ * motherName: "string",
52
+ * noSiblingsInDelivery: "string",
53
+ * placeOfBirth: "string",
54
+ * surname: "string",
55
+ * timeOfbirth: "string",
56
+ * weightAtBirth: "string",
57
+ * babyPicture: "string"
58
+ * },
59
+ * personVouching: {
60
+ * etrackerLightwaveID: "string",
61
+ * ghanaCardPIN: "string",
62
+ * relationToBaby: "string",
63
+ * relativePhone: "string",
64
+ * relativePicture: "string"
65
+ * },
66
+ * merchantKey: "XXXXXXXXXXXXXXXXXXXXXX"
50
67
  * })
51
68
  * @function
52
69
  * @public
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>;