monime-package 1.0.4 → 1.0.5

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.js CHANGED
@@ -36,10 +36,10 @@ __export(index_exports, {
36
36
  module.exports = __toCommonJS(index_exports);
37
37
 
38
38
  // src/modules/financialAccount/financialAccount.ts
39
+ var import_node_crypto = require("crypto");
39
40
  var import_axios = __toESM(require("axios"));
40
- var import_crypto = require("crypto");
41
41
  var URL = "https://api.monime.io/v1/financial-accounts";
42
- var value = (0, import_crypto.randomBytes)(20).toString("hex");
42
+ var value = (0, import_node_crypto.randomBytes)(20).toString("hex");
43
43
  async function createFinancialAccount(accountName, client) {
44
44
  if (accountName.trim() === "") {
45
45
  return { success: false, error: new Error("accountName is required") };
@@ -71,7 +71,10 @@ async function createFinancialAccount(accountName, client) {
71
71
  }
72
72
  async function getFinancialAccount(financialAccountId, client) {
73
73
  if (financialAccountId.trim() === "") {
74
- return { success: false, error: new Error("financialAccountId is required") };
74
+ return {
75
+ success: false,
76
+ error: new Error("financialAccountId is required")
77
+ };
75
78
  }
76
79
  const { monimeSpaceId, accessToken } = client._getConfig();
77
80
  try {
@@ -90,23 +93,110 @@ async function getFinancialAccount(financialAccountId, client) {
90
93
  return { error: new Error("unknown error"), success: false };
91
94
  }
92
95
  }
96
+ async function getAllFinancialAccount(client) {
97
+ const { monimeSpaceId, accessToken } = client._getConfig();
98
+ try {
99
+ const res = await import_axios.default.get(URL, {
100
+ headers: {
101
+ "Monime-Space-Id": `${monimeSpaceId}`,
102
+ Authorization: `Bearer ${accessToken}`
103
+ }
104
+ });
105
+ const data = res.data;
106
+ return { success: true, data };
107
+ } catch (error) {
108
+ if (import_axios.default.isAxiosError(error)) {
109
+ return { error, success: false };
110
+ }
111
+ return { error: new Error("unknown error"), success: false };
112
+ }
113
+ }
93
114
 
94
- // src/modules/internalTransfer/internalTransfer.ts
115
+ // src/modules/financialAccount/index.ts
116
+ function FinancialAccountAPI(client) {
117
+ return {
118
+ create: (name) => createFinancialAccount(name, client),
119
+ get: (financialAccountId) => getFinancialAccount(financialAccountId, client),
120
+ getAll: () => getAllFinancialAccount(client)
121
+ };
122
+ }
123
+
124
+ // src/modules/financialTransaction/financialTransaction.ts
95
125
  var import_axios2 = __toESM(require("axios"));
96
- var import_crypto2 = require("crypto");
97
- var URL2 = "https://api.monime.io/v1/internal-transfers";
98
- var value2 = (0, import_crypto2.randomBytes)(20).toString("hex");
99
- async function createInternalTransfer(sourceAccount, destinationAccount, client, value5) {
100
- if (value5 <= 0) {
101
- return { success: false, error: new Error("value must be larger that zero") };
126
+ var URL2 = "https://api.monime.io/v1/financial-transactions";
127
+ async function getAllTransaction(client) {
128
+ const { monimeSpaceId, accessToken } = client._getConfig();
129
+ try {
130
+ const res = await import_axios2.default.get(URL2, {
131
+ headers: {
132
+ Authorization: `Bearer ${accessToken}`,
133
+ "Monime-Space-Id": `${monimeSpaceId}`
134
+ }
135
+ });
136
+ const data = res.data;
137
+ return { success: true, data };
138
+ } catch (error) {
139
+ if (import_axios2.default.isAxiosError(error)) {
140
+ return { error, success: false };
141
+ }
142
+ return { error: new Error("unknown error"), success: false };
143
+ }
144
+ }
145
+ async function getTransaction(client, transactionId) {
146
+ const { accessToken, monimeSpaceId } = client._getConfig();
147
+ if (transactionId.trim() === "") {
148
+ return {
149
+ error: new Error("transactionId must not be empty"),
150
+ success: false
151
+ };
152
+ }
153
+ try {
154
+ const res = await import_axios2.default.get(`${URL2}/${transactionId}`, {
155
+ headers: {
156
+ Authorization: `Bearer ${accessToken}`,
157
+ "Monime-Space-Id": `${monimeSpaceId}`
158
+ }
159
+ });
160
+ const data = res.data;
161
+ return { success: true, data };
162
+ } catch (error) {
163
+ if (import_axios2.default.isAxiosError(error)) {
164
+ return { error, success: false };
165
+ }
166
+ return { error: new Error("unknown error"), success: false };
167
+ }
168
+ }
169
+
170
+ // src/modules/financialTransaction/index.ts
171
+ function FinancialTransactionAPI(client) {
172
+ return {
173
+ get: (transactionId) => getTransaction(client, transactionId),
174
+ getAll: () => getAllTransaction(client)
175
+ };
176
+ }
177
+
178
+ // src/modules/internalTransfer/internalTransfer.ts
179
+ var import_node_crypto2 = require("crypto");
180
+ var import_axios3 = __toESM(require("axios"));
181
+ var URL3 = "https://api.monime.io/v1/internal-transfers";
182
+ var value2 = (0, import_node_crypto2.randomBytes)(20).toString("hex");
183
+ async function createInternalTransfer(sourceAccount, destinationAccount, client, amount) {
184
+ if (amount <= 0) {
185
+ return {
186
+ success: false,
187
+ error: new Error("amount must be larger that zero")
188
+ };
102
189
  }
103
190
  if (sourceAccount.trim() === "" || destinationAccount.trim() === "") {
104
- return { success: false, error: new Error("sourceAccount or destinationAccount is missing") };
191
+ return {
192
+ success: false,
193
+ error: new Error("sourceAccount or destinationAccount is missing")
194
+ };
105
195
  }
106
196
  const body = {
107
197
  amount: {
108
198
  currency: "SLE",
109
- value: value5
199
+ value: amount
110
200
  },
111
201
  sourceFinancialAccount: {
112
202
  id: sourceAccount
@@ -118,9 +208,9 @@ async function createInternalTransfer(sourceAccount, destinationAccount, client,
118
208
  };
119
209
  const { accessToken, monimeSpaceId } = client._getConfig();
120
210
  try {
121
- const res = await import_axios2.default.post(URL2, body, {
211
+ const res = await import_axios3.default.post(URL3, body, {
122
212
  headers: {
123
- "Idempotency-Key": `${value5}`,
213
+ "Idempotency-Key": `${value2}`,
124
214
  "Monime-Space-Id": `${monimeSpaceId}`,
125
215
  Authorization: `Bearer ${accessToken}`,
126
216
  "Content-Type": "application/json"
@@ -129,28 +219,102 @@ async function createInternalTransfer(sourceAccount, destinationAccount, client,
129
219
  const data = res.data;
130
220
  return { success: true, data };
131
221
  } catch (error) {
132
- if (import_axios2.default.isAxiosError(error)) {
222
+ if (import_axios3.default.isAxiosError(error)) {
133
223
  return { error, success: false };
134
224
  }
135
225
  return { error: new Error("unkknown error"), success: false };
136
226
  }
137
227
  }
228
+ async function getAllInternalTransfers(client) {
229
+ const { monimeSpaceId, accessToken } = client._getConfig();
230
+ try {
231
+ const res = await import_axios3.default.get(URL3, {
232
+ headers: {
233
+ "Monime-Space-Id": `${monimeSpaceId}`,
234
+ Authorization: `Bearer ${accessToken}`
235
+ }
236
+ });
237
+ const data = res.data;
238
+ return { success: true, data };
239
+ } catch (error) {
240
+ if (import_axios3.default.isAxiosError(error)) {
241
+ return { success: false, error };
242
+ }
243
+ return { error: new Error("unkknown error"), success: false };
244
+ }
245
+ }
246
+ async function getInternalTransfer(client, internalTransferId) {
247
+ const { accessToken, monimeSpaceId } = client._getConfig();
248
+ try {
249
+ const res = await import_axios3.default.get(`${URL3}/${internalTransferId}`, {
250
+ headers: {
251
+ "Monime-Space-Id": `${monimeSpaceId}`,
252
+ Authorization: `Bearer ${accessToken}`
253
+ }
254
+ });
255
+ const data = res.data;
256
+ return { success: true, data };
257
+ } catch (error) {
258
+ if (import_axios3.default.isAxiosError(error)) {
259
+ return { success: false, error };
260
+ }
261
+ return { error: new Error("unkknown error"), success: false };
262
+ }
263
+ }
264
+ async function deleteInternalTransfer(client, internalTransferId) {
265
+ const { monimeSpaceId, accessToken } = client._getConfig();
266
+ try {
267
+ await import_axios3.default.delete(`${URL3}/${internalTransferId}`, {
268
+ headers: {
269
+ "Monime-Space-Id": `${monimeSpaceId}`,
270
+ Authorization: `Bearer ${accessToken}`
271
+ }
272
+ });
273
+ return { success: true };
274
+ } catch (error) {
275
+ if (import_axios3.default.isAxiosError(error)) {
276
+ return { success: false, error };
277
+ }
278
+ return { success: false, error: new Error("unknown error") };
279
+ }
280
+ }
281
+
282
+ // src/modules/internalTransfer/index.ts
283
+ function InternalTransferAPI(client) {
284
+ return {
285
+ create: (sourceAccount, destinationAccount, amount) => createInternalTransfer(
286
+ sourceAccount,
287
+ destinationAccount,
288
+ client,
289
+ amount
290
+ ),
291
+ get: (internalTransferId) => getInternalTransfer(client, internalTransferId),
292
+ getAll: () => getAllInternalTransfers(client),
293
+ delete: (internalTransferId) => deleteInternalTransfer(client, internalTransferId)
294
+ };
295
+ }
138
296
 
139
297
  // src/modules/paymentCode/paymentCode.ts
140
- var import_axios3 = __toESM(require("axios"));
141
- var import_crypto3 = require("crypto");
142
- var value3 = (0, import_crypto3.randomBytes)(20).toString("hex");
143
- var URL3 = "https://api.monime.io/v1/payment-codes";
298
+ var import_node_crypto3 = require("crypto");
299
+ var import_axios4 = __toESM(require("axios"));
300
+ var value3 = (0, import_node_crypto3.randomBytes)(20).toString("hex");
301
+ var URL4 = "https://api.monime.io/v1/payment-codes";
144
302
  async function createPaymentCode(paymentName, amount, financialAccountId, name, phoneNumber, client) {
145
303
  let financialAccount = null;
146
304
  if (financialAccountId !== "") {
147
305
  financialAccount = financialAccountId;
148
306
  }
149
307
  if (paymentName.trim() === "" || name.trim() === "" || phoneNumber.trim() === "") {
150
- return { success: false, error: new Error("paymentName, name, or phoneNumber is missing") };
308
+ return {
309
+ success: false,
310
+ error: new Error("paymentName, name, or phoneNumber is missing")
311
+ };
151
312
  }
152
313
  if (amount <= 0) {
153
- return { success: false, error: new Error("amonut number be greater than zero") };
314
+ return {
315
+ success: false,
316
+ error: new Error("amonut number be greater than zero")
317
+ };
154
318
  }
155
319
  const { accessToken, monimeSpaceId } = client._getConfig();
156
320
  const bodyData = {
@@ -179,7 +343,7 @@ async function createPaymentCode(paymentName, amount, financialAccountId, name,
179
343
  metadata: {}
180
344
  };
181
345
  try {
182
- const res = await import_axios3.default.post(URL3, bodyData, {
346
+ const res = await import_axios4.default.post(URL4, bodyData, {
183
347
  headers: {
184
348
  "Idempotency-Key": `${value3}`,
185
349
  "Monime-Space-Id": `${monimeSpaceId}`,
@@ -190,7 +354,7 @@ async function createPaymentCode(paymentName, amount, financialAccountId, name,
190
354
  const data = res.data;
191
355
  return { data, success: true };
192
356
  } catch (error) {
193
- if (import_axios3.default.isAxiosError(error)) {
357
+ if (import_axios4.default.isAxiosError(error)) {
194
358
  return { error: error.response?.data, success: false };
195
359
  }
196
360
  return { error: new Error("unknown error"), success: false };
@@ -202,7 +366,7 @@ async function deletePaymentCode(paymentCodeId, client) {
202
366
  return { success: false, error: new Error("paymentCodeId is required") };
203
367
  }
204
368
  try {
205
- const res = await import_axios3.default.delete(`${URL3}/${paymentCodeId}`, {
369
+ await import_axios4.default.delete(`${URL4}/${paymentCodeId}`, {
206
370
  headers: {
207
371
  "Idempotency-Key": `${value3}`,
208
372
  "Monime-Space-Id": `${monimeSpaceId}`,
@@ -210,38 +374,85 @@ async function deletePaymentCode(paymentCodeId, client) {
210
374
  "Content-Type": "application/json"
211
375
  }
212
376
  });
377
+ return { success: true };
378
+ } catch (error) {
379
+ if (import_axios4.default.isAxiosError(error)) {
380
+ return { error, success: false };
381
+ }
382
+ return { error: new Error("unknown error"), success: false };
383
+ }
384
+ }
385
+ async function getAllPaymentCode(client) {
386
+ const { monimeSpaceId, accessToken } = client._getConfig();
387
+ try {
388
+ const res = await import_axios4.default.get(URL4, {
389
+ headers: {
390
+ "Monime-Space-Id": `${monimeSpaceId}`,
391
+ Authorization: `Bearer ${accessToken}`
392
+ }
393
+ });
213
394
  const data = res.data;
214
- if (!data.success) {
215
- return { error: new Error("delete failed"), success: false };
395
+ return { success: true, data };
396
+ } catch (error) {
397
+ if (import_axios4.default.isAxiosError(error)) {
398
+ return { error, success: false };
216
399
  }
217
- return { success: true };
400
+ return { error: new Error("unknown error"), success: false };
401
+ }
402
+ }
403
+ async function getPaymentCode(paymentCodeId, client) {
404
+ const { monimeSpaceId, accessToken } = client._getConfig();
405
+ try {
406
+ const res = await import_axios4.default.get(`${URL4}/${paymentCodeId}`, {
407
+ headers: {
408
+ "Monime-Space-Id": `${monimeSpaceId}`,
409
+ Authorization: `Bearer ${accessToken}`
410
+ }
411
+ });
412
+ const data = res.data;
413
+ return { success: true, data };
218
414
  } catch (error) {
219
- if (import_axios3.default.isAxiosError(error)) {
415
+ if (import_axios4.default.isAxiosError(error)) {
220
416
  return { error, success: false };
221
417
  }
222
418
  return { error: new Error("unknown error"), success: false };
223
419
  }
224
420
  }
225
421
 
422
+ // src/modules/paymentCode/index.ts
423
+ function PaymentCodeAPI(client) {
424
+ return {
425
+ create: (paymentName, amount, financialAccount, username, phoneNumber) => createPaymentCode(
426
+ paymentName,
427
+ amount,
428
+ financialAccount,
429
+ username,
430
+ phoneNumber,
431
+ client
432
+ ),
433
+ delete: (paymentCodeId) => deletePaymentCode(paymentCodeId, client),
434
+ getAll: () => getAllPaymentCode(client),
435
+ get: (paymentCodeId) => getPaymentCode(paymentCodeId, client)
436
+ };
437
+ }
438
+
226
439
  // src/modules/payout/payout.ts
227
- var import_axios4 = __toESM(require("axios"));
228
- var import_crypto4 = require("crypto");
229
- var URL4 = "https://api.monime.io/v1/payouts";
230
- var value4 = (0, import_crypto4.randomBytes)(20).toString("hex");
231
- async function CreatePayoutMobileMoney(amount, phoneNumber, sourceAccount, client) {
232
- if (phoneNumber.trim() === "") {
233
- return { success: false, error: new Error("phoneNumber is required") };
234
- }
235
- let provider = "m17";
236
- const africell = ["077", "033", "088", "080", "090", "030"];
237
- for (let value5 of africell) {
238
- if (phoneNumber.startsWith(value5)) {
239
- provider = "m18";
240
- break;
241
- }
440
+ var import_node_crypto4 = require("crypto");
441
+ var import_axios5 = __toESM(require("axios"));
442
+ var URL5 = "https://api.monime.io/v1/payouts";
443
+ var value4 = (0, import_node_crypto4.randomBytes)(20).toString("hex");
444
+ async function createPayout(amount, sourceAccount, destination, client) {
445
+ if (sourceAccount.trim() === "") {
446
+ return {
447
+ success: false,
448
+ error: new Error("sourceAccount cannot be empty")
449
+ };
242
450
  }
243
451
  if (amount <= 0) {
244
- return { error: new Error("amount must be greater than 0"), success: false };
452
+ return {
453
+ error: new Error("amount must be greater than 0"),
454
+ success: false
455
+ };
245
456
  }
246
457
  const { accessToken, monimeSpaceId } = client._getConfig();
247
458
  const body = {
@@ -252,15 +463,11 @@ async function CreatePayoutMobileMoney(amount, phoneNumber, sourceAccount, clien
252
463
  source: {
253
464
  financialAccountId: sourceAccount
254
465
  },
255
- destination: {
256
- type: "momo",
257
- provider,
258
- phoneNumber
259
- },
466
+ destination,
260
467
  metadata: {}
261
468
  };
262
469
  try {
263
- const res = await import_axios4.default.post(URL4, body, {
470
+ const res = await import_axios5.default.post(URL5, body, {
264
471
  headers: {
265
472
  "Idempotency-Key": `${value4}`,
266
473
  "Monime-Space-Id": `${monimeSpaceId}`,
@@ -271,37 +478,93 @@ async function CreatePayoutMobileMoney(amount, phoneNumber, sourceAccount, clien
271
478
  const data = res.data;
272
479
  return { success: true, data };
273
480
  } catch (error) {
274
- if (import_axios4.default.isAxiosError(error)) {
481
+ if (import_axios5.default.isAxiosError(error)) {
482
+ return { success: false, error };
483
+ }
484
+ return { success: false, error: new Error("unknown error") };
485
+ }
486
+ }
487
+ async function getAllPayout(client) {
488
+ const { accessToken, monimeSpaceId } = client._getConfig();
489
+ try {
490
+ const res = await import_axios5.default.get(URL5, {
491
+ headers: {
492
+ "Monime-Space-Id": `${monimeSpaceId}`,
493
+ Authorization: `Bearer ${accessToken}`
494
+ }
495
+ });
496
+ const data = res.data;
497
+ return { success: true, data };
498
+ } catch (error) {
499
+ if (import_axios5.default.isAxiosError(error)) {
275
500
  return { success: false, error };
276
501
  }
277
502
  return { success: false, error: new Error("unknown error") };
278
503
  }
279
504
  }
505
+ async function getPayout(payoutId, client) {
506
+ const { accessToken, monimeSpaceId } = client._getConfig();
507
+ try {
508
+ const res = await import_axios5.default.get(`${URL5}/${payoutId}`, {
509
+ headers: {
510
+ "Monime-Space-Id": `${monimeSpaceId}`,
511
+ Authorization: `Bearer ${accessToken}`
512
+ }
513
+ });
514
+ const data = res.data;
515
+ return { success: true, data };
516
+ } catch (error) {
517
+ if (import_axios5.default.isAxiosError(error)) {
518
+ return { success: false, error };
519
+ }
520
+ return { success: false, error: new Error("unknown error") };
521
+ }
522
+ }
523
+ async function deletePayout(payoutId, client) {
524
+ const { accessToken, monimeSpaceId } = client._getConfig();
525
+ try {
526
+ await import_axios5.default.delete(`${URL5}/${payoutId}`, {
527
+ headers: {
528
+ "Monime-Space-Id": `${monimeSpaceId}`,
529
+ Authorization: `Bearer ${accessToken}`
530
+ }
531
+ });
532
+ return { success: true };
533
+ } catch (error) {
534
+ if (import_axios5.default.isAxiosError(error)) {
535
+ return { success: false, error };
536
+ }
537
+ return { success: false, error: new Error("unknown error") };
538
+ }
539
+ }
540
+
541
+ // src/modules/payout/index.ts
542
+ function PayoutAPI(client) {
543
+ return {
544
+ create: (amount, destination, sourceAccount) => createPayout(amount, sourceAccount, destination, client),
545
+ get: () => getAllPayout(client),
546
+ getOne: (payoutId) => getPayout(payoutId, client),
547
+ delete: (payoutId) => deletePayout(payoutId, client)
548
+ };
549
+ }
280
550
 
281
551
  // src/client.ts
282
552
  var MonimeClient = class {
283
553
  monimeSpaceId;
284
554
  accessToken;
285
- /* Methods */
286
- //method for financial accounts
287
- createFinancialAccount;
288
- getFinancialAccount;
289
- //method for internal transfer
290
- createInternalTransfer;
291
- //method for payment code
292
- createPaymentCode;
293
- deletePaymentCode;
294
- //method for payout
295
- createPayout;
555
+ financialAccount;
556
+ internalTransfer;
557
+ paymentCode;
558
+ payout;
559
+ financialTransaction;
296
560
  constructor(options) {
297
561
  this.accessToken = options.accessToken;
298
- this.monimeSpaceId = options.monimeSpaceeId;
299
- this.createFinancialAccount = (name) => createFinancialAccount(name, this);
300
- this.getFinancialAccount = (financialAccountId) => getFinancialAccount(financialAccountId, this);
301
- this.createInternalTransfer = (sourceAccount, destinationAccount, amount) => createInternalTransfer(sourceAccount, destinationAccount, this, amount);
302
- this.createPaymentCode = (paymentName, amount, financialAccount, username, phoneNumber) => createPaymentCode(paymentName, amount, financialAccount, username, phoneNumber, this);
303
- this.deletePaymentCode = (paymentCodeId) => deletePaymentCode(paymentCodeId, this);
304
- this.createPayout = (amount, phoneNumber, sourceAccount) => CreatePayoutMobileMoney(amount, phoneNumber, sourceAccount, this);
562
+ this.monimeSpaceId = options.monimeSpaceId;
563
+ this.financialAccount = FinancialAccountAPI(this);
564
+ this.internalTransfer = InternalTransferAPI(this);
565
+ this.paymentCode = PaymentCodeAPI(this);
566
+ this.payout = PayoutAPI(this);
567
+ this.financialTransaction = FinancialTransactionAPI(this);
305
568
  }
306
569
  /** @internal */
307
570
  _getConfig() {