@openfn/language-ghana-nia 0.1.1 → 0.1.3

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 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})"
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})"
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
  };
@@ -126,8 +147,14 @@ var request = (path, options) => {
126
147
  query,
127
148
  ...otherOptions
128
149
  };
150
+ if (data.merchantKey) {
151
+ (0, import_util.throwError)(
152
+ "Please don't supply `merchantKey` in your request body. The adaptor will append it automatically."
153
+ );
154
+ }
129
155
  if (data) {
130
- args.body = JSON.stringify(data);
156
+ args.body = JSON.stringify({ ...data, merchantKey });
157
+ args.data = { ...data, merchantKey };
131
158
  }
132
159
  const response = await client.request(args);
133
160
  if (response.statusCode >= 400) {
@@ -144,23 +171,69 @@ var request = (path, options) => {
144
171
 
145
172
  // src/mock.js
146
173
  var import_undici2 = require("undici");
147
- var niaResponseSample = {
148
- data: {
149
- babyPin: "GH-6326223626-3"
174
+ var sampleRequestBody = {
175
+ babyData: {
176
+ dateOfBirth: "2024-03-05",
177
+ fatherName: "Nyarkoa Osei-Akoto",
178
+ forenames: "Kharis",
179
+ gender: "Female",
180
+ lightwaveETrackerID: "00313180/24-03",
181
+ motherName: "Gifty Osei-Akoto",
182
+ noSiblingsInDelivery: "0",
183
+ placeOfBirth: "New Market Health Centre",
184
+ surname: "Osei",
185
+ timeOfbirth: "09:34",
186
+ weightAtBirth: "2.7",
187
+ birthCertificateNumber: "011803-48-2024",
188
+ babyPicture: "...base64 encoded image goes here..."
189
+ },
190
+ personVouching: {
191
+ etrackerLightwaveID: "00313180/24-03",
192
+ ghanaCardPIN: "GHA-001097272-4",
193
+ relationToBaby: "Mother",
194
+ relativePhone: "0248403076",
195
+ relativePicture: "...base64 encoded image goes here..."
150
196
  }
151
197
  };
198
+ var nationalIdSampleResponse = {
199
+ data: {
200
+ babyPin: "GHA-000000000-1",
201
+ voucherPin: "GHA-000000000-4",
202
+ etrackerLightwaveId: "00000000/24-03",
203
+ lightwaveEtrackerId: null
204
+ },
205
+ success: true,
206
+ code: "00",
207
+ msg: "Saved Successfully"
208
+ };
152
209
  function createServer(url = "https://selfie.imsgh.org:2035") {
153
210
  const agent = new import_undici2.MockAgent();
154
211
  agent.disableNetConnect();
155
212
  const mockPool = agent.get(url);
156
213
  const sendNiaData = (req) => {
157
- return {
158
- statusCode: 200,
159
- responseOptions: {
160
- headers: { "Content-Type": "application/json" }
161
- },
162
- data: JSON.stringify(niaResponseSample)
163
- };
214
+ const body = JSON.parse(req.body);
215
+ if (validateRequestBody(body, sampleRequestBody)) {
216
+ return {
217
+ statusCode: 200,
218
+ responseOptions: {
219
+ headers: { "Content-Type": "application/json" }
220
+ },
221
+ data: JSON.stringify(nationalIdSampleResponse)
222
+ };
223
+ } else {
224
+ return {
225
+ statusCode: 404,
226
+ responseOptions: {
227
+ headers: { "Content-Type": "application/json" }
228
+ },
229
+ data: {
230
+ success: false,
231
+ code: "05",
232
+ data: null,
233
+ msg: "Error in Verifiation Process"
234
+ }
235
+ };
236
+ }
164
237
  };
165
238
  mockPool.intercept({ method: "post", path: /awopa\/api\/v1\/baby\/registration/ }).reply(sendNiaData).persist();
166
239
  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
  };
@@ -89,8 +110,14 @@ var request = (path, options) => {
89
110
  query,
90
111
  ...otherOptions
91
112
  };
113
+ if (data.merchantKey) {
114
+ throwError(
115
+ "Please don't supply `merchantKey` in your request body. The adaptor will append it automatically."
116
+ );
117
+ }
92
118
  if (data) {
93
- args.body = JSON.stringify(data);
119
+ args.body = JSON.stringify({ ...data, merchantKey });
120
+ args.data = { ...data, merchantKey };
94
121
  }
95
122
  const response = await client.request(args);
96
123
  if (response.statusCode >= 400) {
@@ -107,23 +134,69 @@ var request = (path, options) => {
107
134
 
108
135
  // src/mock.js
109
136
  import { MockAgent } from "undici";
110
- var niaResponseSample = {
111
- data: {
112
- babyPin: "GH-6326223626-3"
137
+ var sampleRequestBody = {
138
+ babyData: {
139
+ dateOfBirth: "2024-03-05",
140
+ fatherName: "Nyarkoa Osei-Akoto",
141
+ forenames: "Kharis",
142
+ gender: "Female",
143
+ lightwaveETrackerID: "00313180/24-03",
144
+ motherName: "Gifty Osei-Akoto",
145
+ noSiblingsInDelivery: "0",
146
+ placeOfBirth: "New Market Health Centre",
147
+ surname: "Osei",
148
+ timeOfbirth: "09:34",
149
+ weightAtBirth: "2.7",
150
+ birthCertificateNumber: "011803-48-2024",
151
+ babyPicture: "...base64 encoded image goes here..."
152
+ },
153
+ personVouching: {
154
+ etrackerLightwaveID: "00313180/24-03",
155
+ ghanaCardPIN: "GHA-001097272-4",
156
+ relationToBaby: "Mother",
157
+ relativePhone: "0248403076",
158
+ relativePicture: "...base64 encoded image goes here..."
113
159
  }
114
160
  };
161
+ var nationalIdSampleResponse = {
162
+ data: {
163
+ babyPin: "GHA-000000000-1",
164
+ voucherPin: "GHA-000000000-4",
165
+ etrackerLightwaveId: "00000000/24-03",
166
+ lightwaveEtrackerId: null
167
+ },
168
+ success: true,
169
+ code: "00",
170
+ msg: "Saved Successfully"
171
+ };
115
172
  function createServer(url = "https://selfie.imsgh.org:2035") {
116
173
  const agent = new MockAgent();
117
174
  agent.disableNetConnect();
118
175
  const mockPool = agent.get(url);
119
176
  const sendNiaData = (req) => {
120
- return {
121
- statusCode: 200,
122
- responseOptions: {
123
- headers: { "Content-Type": "application/json" }
124
- },
125
- data: JSON.stringify(niaResponseSample)
126
- };
177
+ const body = JSON.parse(req.body);
178
+ if (validateRequestBody(body, sampleRequestBody)) {
179
+ return {
180
+ statusCode: 200,
181
+ responseOptions: {
182
+ headers: { "Content-Type": "application/json" }
183
+ },
184
+ data: JSON.stringify(nationalIdSampleResponse)
185
+ };
186
+ } else {
187
+ return {
188
+ statusCode: 404,
189
+ responseOptions: {
190
+ headers: { "Content-Type": "application/json" }
191
+ },
192
+ data: {
193
+ success: false,
194
+ code: "05",
195
+ data: null,
196
+ msg: "Error in Verifiation Process"
197
+ }
198
+ };
199
+ }
127
200
  };
128
201
  mockPool.intercept({ method: "post", path: /awopa\/api\/v1\/baby\/registration/ }).reply(sendNiaData).persist();
129
202
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfn/language-ghana-nia",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
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
  },
@@ -62,8 +62,7 @@ export function post(path: string, data: object): Operation;
62
62
  * relationToBaby: "string",
63
63
  * relativePhone: "string",
64
64
  * relativePicture: "string"
65
- * },
66
- * merchantKey: "XXXXXXXXXXXXXXXXXXXXXX"
65
+ * }
67
66
  * })
68
67
  * @function
69
68
  * @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>;