@verii/fineract-client 1.1.0-pre.1757918680 → 1.1.0-pre.1758002630

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.
Files changed (2) hide show
  1. package/package.json +5 -5
  2. package/src/fetchers.js +59 -60
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verii/fineract-client",
3
- "version": "1.1.0-pre.1757918680",
3
+ "version": "1.1.0-pre.1758002630",
4
4
  "description": "Package containing the functions that interact with the fineract system",
5
5
  "repository": "https://github.com/LFDT-Verii/core",
6
6
  "main": "index.js",
@@ -16,13 +16,13 @@
16
16
  "lint:fix": "eslint --fix --ext .js ."
17
17
  },
18
18
  "dependencies": {
19
- "@verii/common-functions": "1.1.0-pre.1757918680",
19
+ "@verii/common-functions": "1.1.0-pre.1758002630",
20
20
  "http-errors": "2.0.0",
21
21
  "lodash": "^4.17.21"
22
22
  },
23
23
  "devDependencies": {
24
- "@verii/request": "1.1.0-pre.1757918680",
25
- "@verii/test-regexes": "1.1.0-pre.1757918680",
24
+ "@verii/http-client": "1.1.0-pre.1758002630",
25
+ "@verii/test-regexes": "1.1.0-pre.1758002630",
26
26
  "date-fns": "3.6.0",
27
27
  "eslint": "8.57.1",
28
28
  "eslint-config-airbnb-base": "14.2.1",
@@ -42,5 +42,5 @@
42
42
  "lib"
43
43
  ]
44
44
  },
45
- "gitHead": "f0bb52fc63b22fadfe65a820a5a4425580a3c8a7"
45
+ "gitHead": "b961d761dc0f0710df506d90222145afe3c35cf6"
46
46
  }
package/src/fetchers.js CHANGED
@@ -86,25 +86,25 @@ const batchOperations = async (
86
86
  if (transactionalBatch) {
87
87
  queryParams.set('enclosingTransaction', 'true');
88
88
  }
89
- const response = await fineractFetch
90
- .post(`fineract-provider/api/v1/batches?${queryParams}`, {
91
- json: [
92
- ...batchedTransfers,
93
- ...batchedClientsToCreate,
94
- ...batchedCreditAccountsToCreate,
95
- ...batchedClientBurnVouchers,
96
- ],
97
- })
98
- .json();
99
- if (transactionalBatch && firstStatusCode(response) >= 400) {
100
- throw newError(firstStatusCode(response), first(response).body);
89
+ const response = await fineractFetch.post(
90
+ `fineract-provider/api/v1/batches?${queryParams}`,
91
+ [
92
+ ...batchedTransfers,
93
+ ...batchedClientsToCreate,
94
+ ...batchedCreditAccountsToCreate,
95
+ ...batchedClientBurnVouchers,
96
+ ]
97
+ );
98
+ const result = await response.json();
99
+ if (transactionalBatch && firstStatusCode(result) >= 400) {
100
+ throw newError(firstStatusCode(result), first(result).body);
101
101
  }
102
102
  return map((responseItem) => {
103
103
  return {
104
104
  ...responseItem,
105
105
  ...handleBatchResponseItemBody(responseItem),
106
106
  };
107
- }, response);
107
+ }, result);
108
108
  };
109
109
 
110
110
  const firstStatusCode = (response) => first(response).statusCode;
@@ -146,11 +146,11 @@ const createClient = async (
146
146
  activationDate,
147
147
  submittedOnDate,
148
148
  });
149
- const { clientId } = await fineractFetch
150
- .post('fineract-provider/api/v1/clients', {
151
- json: payload,
152
- })
153
- .json();
149
+ const response = await fineractFetch.post(
150
+ 'fineract-provider/api/v1/clients',
151
+ payload
152
+ );
153
+ const { clientId } = await response.json();
154
154
  return { clientId: `${clientId}` };
155
155
  };
156
156
 
@@ -165,11 +165,11 @@ const createCreditsAccount = async (
165
165
  productId,
166
166
  autoApproveAndActivate,
167
167
  });
168
- const { savingsId } = await fineractFetch
169
- .post('fineract-provider/api/v1/savingsaccounts', {
170
- json: payload,
171
- })
172
- .json();
168
+ const response = await fineractFetch.post(
169
+ 'fineract-provider/api/v1/savingsaccounts',
170
+ payload
171
+ );
172
+ const { savingsId } = await response.json();
173
173
  return { tokenAccountId: `${savingsId}` };
174
174
  };
175
175
 
@@ -186,32 +186,29 @@ const createVouchers = async (
186
186
  dateFormat: 'yyyy-MM-dd',
187
187
  expiry: formatAsDate(expiry),
188
188
  };
189
- return fineractFetch
190
- .post(
191
- `fineract-provider/api/v1/datatables/Voucher/${clientId}?genericResultSet=true`,
192
- {
193
- json: payload,
194
- }
195
- )
196
- .json();
189
+ const response = await fineractFetch.post(
190
+ `fineract-provider/api/v1/datatables/Voucher/${clientId}?genericResultSet=true`,
191
+ payload
192
+ );
193
+ return response.text();
197
194
  };
198
195
 
199
196
  const getClientVoucherBalance = async ({ clientId }, { fineractFetch }) => {
200
- const response = await fineractFetch
201
- .get(`fineract-provider/api/v1/vouchers/${clientId}/balance`)
202
- .json();
197
+ const response = await fineractFetch.get(
198
+ `fineract-provider/api/v1/vouchers/${clientId}/balance`
199
+ );
200
+ const result = await response.json();
203
201
  return {
204
- ...response,
202
+ ...result,
205
203
  clientId: `${clientId}`,
206
204
  };
207
205
  };
208
206
 
209
207
  const getCreditsAccount = async ({ accountId }, { fineractFetch }) => {
210
- return fineractFetch
211
- .get(
212
- `fineract-provider/api/v1/savingsaccounts/${accountId}?associations=all`
213
- )
214
- .json();
208
+ const response = await fineractFetch.get(
209
+ `fineract-provider/api/v1/savingsaccounts/${accountId}?associations=all`
210
+ );
211
+ return response.json();
215
212
  };
216
213
 
217
214
  const getCreditsAccountTransactions = async (
@@ -250,17 +247,16 @@ const getCreditsAccountTransactions = async (
250
247
  descriptions
251
248
  );
252
249
 
253
- const response = await fineractFetch
254
- .get(
255
- `fineract-provider/api/v1/savingsaccounts/${accountId}/transactions?${searchParams.toString()}`
256
- )
257
- .json();
250
+ const response = await fineractFetch.get(
251
+ `fineract-provider/api/v1/savingsaccounts/${accountId}/transactions?${searchParams.toString()}`
252
+ );
253
+ const result = await response.json();
258
254
  return {
259
- ...response,
255
+ ...result,
260
256
  ...getPaginatedResponse({
261
257
  pageNumber,
262
258
  pageSize,
263
- totalFilteredRecords: response?.totalFilteredRecords,
259
+ totalFilteredRecords: result?.totalFilteredRecords,
264
260
  }),
265
261
  };
266
262
  };
@@ -283,11 +279,11 @@ const transferCredits = async (
283
279
  transferDescription: description,
284
280
  locale: 'en',
285
281
  };
286
- await fineractFetch
287
- .post('fineract-provider/api/v1/accounttransfers', {
288
- json: payload,
289
- })
290
- .json();
282
+ const response = await fineractFetch.post(
283
+ 'fineract-provider/api/v1/accounttransfers',
284
+ payload
285
+ );
286
+ await response.json();
291
287
  return {};
292
288
  };
293
289
 
@@ -299,17 +295,20 @@ const mapVoucher = ({ expiry, ...voucher }) => ({
299
295
  });
300
296
 
301
297
  const getVouchers = async ({ clientId }, { fineractFetch }) => {
302
- const response = await fineractFetch
303
- .get(`fineract-provider/api/v1/datatables/Voucher/${clientId}`)
304
- .json();
298
+ const response = await fineractFetch.get(
299
+ `fineract-provider/api/v1/datatables/Voucher/${clientId}`
300
+ );
301
+ const result = await response.json();
305
302
 
306
- return map(mapVoucher, response);
303
+ return map(mapVoucher, result);
307
304
  };
308
305
 
309
- const getExpiringVouchers = async ({ clientId, days }, { fineractFetch }) =>
310
- fineractFetch
311
- .get(`fineract-provider/api/v1/vouchers/${clientId}/expiring/${days}`)
312
- .json();
306
+ const getExpiringVouchers = async ({ clientId, days }, { fineractFetch }) => {
307
+ const response = await fineractFetch.get(
308
+ `fineract-provider/api/v1/vouchers/${clientId}/expiring/${days}`
309
+ );
310
+ return response.json();
311
+ };
313
312
 
314
313
  module.exports = {
315
314
  batchOperations,