monime-package 1.0.5 → 1.0.6

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
@@ -35,10 +35,153 @@ __export(index_exports, {
35
35
  });
36
36
  module.exports = __toCommonJS(index_exports);
37
37
 
38
+ // src/modules/checkout session/checkoutSession.ts
39
+ var import_axios = __toESM(require("axios"));
40
+ var URL = "https://api.monime.io/v1/checkout-sessions";
41
+ async function createCheckout(client, name, amount, quantity, successUrl, cancelUrl, description, financialAccountId, primaryColor, images) {
42
+ const { monimeSpaceId, accessToken } = client._getConfig();
43
+ const body = {
44
+ name,
45
+ description,
46
+ cancelUrl,
47
+ successUrl,
48
+ callbackState: null,
49
+ reference: null,
50
+ financialAccountId,
51
+ lineItems: [
52
+ {
53
+ type: "custom",
54
+ name,
55
+ price: {
56
+ currency: "SLE",
57
+ value: amount
58
+ },
59
+ quantity,
60
+ reference: null,
61
+ description,
62
+ images
63
+ }
64
+ ],
65
+ paymentOptions: {
66
+ card: {
67
+ disable: false
68
+ },
69
+ bank: {
70
+ disable: false,
71
+ enabledProviders: ["slb001", "slb004", "slb007"]
72
+ // disabledProviders: ["slb001"],
73
+ },
74
+ momo: {
75
+ disable: false,
76
+ enabledProviders: ["m17", "m18"]
77
+ // disabledProviders: ["m17"],
78
+ },
79
+ wallet: {
80
+ disable: false,
81
+ enabledProviders: ["dw001"]
82
+ // disabledProviders: ["dw001"],
83
+ }
84
+ },
85
+ brandingOptions: {
86
+ primaryColor
87
+ },
88
+ metadata: {}
89
+ };
90
+ try {
91
+ const res = await import_axios.default.patch(URL, body, {
92
+ headers: {
93
+ "Monime-Space-Id": monimeSpaceId,
94
+ Authorization: `Bearer ${accessToken}`
95
+ }
96
+ });
97
+ const data = res.data;
98
+ return { success: true, data };
99
+ } catch (error) {
100
+ if (import_axios.default.isAxiosError(error)) {
101
+ return { error, success: false };
102
+ }
103
+ return { error: new Error("unknown error"), success: false };
104
+ }
105
+ }
106
+ async function getAllCheckout(client) {
107
+ const { accessToken, monimeSpaceId } = client._getConfig();
108
+ try {
109
+ const res = await import_axios.default.get(URL, {
110
+ headers: {
111
+ "Monime-Space-Id": monimeSpaceId,
112
+ Authorization: `Bearer ${accessToken}`
113
+ }
114
+ });
115
+ const data = res.data;
116
+ return { success: true, data };
117
+ } catch (error) {
118
+ if (import_axios.default.isAxiosError(error)) {
119
+ return { error, success: false };
120
+ }
121
+ return { error: new Error("unknown error"), success: false };
122
+ }
123
+ }
124
+ async function getOnecheckout(client, checkoutId) {
125
+ const { accessToken, monimeSpaceId } = client._getConfig();
126
+ try {
127
+ const res = await import_axios.default.get(`${URL}/${checkoutId}`, {
128
+ headers: {
129
+ "Monime-Space-Id": monimeSpaceId,
130
+ Authorization: `Bearer ${accessToken}`
131
+ }
132
+ });
133
+ const data = res.data;
134
+ return { success: true, data };
135
+ } catch (error) {
136
+ if (import_axios.default.isAxiosError(error)) {
137
+ return { error, success: false };
138
+ }
139
+ return { error: new Error("unknown error"), success: false };
140
+ }
141
+ }
142
+ async function deleteCheckout(client, checkoutId) {
143
+ const { accessToken, monimeSpaceId } = client._getConfig();
144
+ try {
145
+ await import_axios.default.delete(`${URL}/${checkoutId}`, {
146
+ headers: {
147
+ "Monime-Space-Id": monimeSpaceId,
148
+ Authorization: `Bearer ${accessToken}`
149
+ }
150
+ });
151
+ return { success: true };
152
+ } catch (error) {
153
+ if (import_axios.default.isAxiosError(error)) {
154
+ return { error, success: false };
155
+ }
156
+ return { error: new Error("unknown error"), success: false };
157
+ }
158
+ }
159
+
160
+ // src/modules/checkout session/index.ts
161
+ function CheckoutSessionAPI(client) {
162
+ return {
163
+ create: (name, amount, quantity, successUrl, cancelUrl, description, financialAccountId, primaryColor, images) => createCheckout(
164
+ client,
165
+ name,
166
+ amount,
167
+ quantity,
168
+ successUrl,
169
+ cancelUrl,
170
+ description,
171
+ financialAccountId,
172
+ primaryColor,
173
+ images
174
+ ),
175
+ get: () => getAllCheckout(client),
176
+ getOne: (checkoutId) => getOnecheckout(client, checkoutId),
177
+ delete: (checkoutId) => deleteCheckout(client, checkoutId)
178
+ };
179
+ }
180
+
38
181
  // src/modules/financialAccount/financialAccount.ts
39
182
  var import_node_crypto = require("crypto");
40
- var import_axios = __toESM(require("axios"));
41
- var URL = "https://api.monime.io/v1/financial-accounts";
183
+ var import_axios2 = __toESM(require("axios"));
184
+ var URL2 = "https://api.monime.io/v1/financial-accounts";
42
185
  var value = (0, import_node_crypto.randomBytes)(20).toString("hex");
43
186
  async function createFinancialAccount(accountName, client) {
44
187
  if (accountName.trim() === "") {
@@ -52,7 +195,7 @@ async function createFinancialAccount(accountName, client) {
52
195
  };
53
196
  const { accessToken, monimeSpaceId } = client._getConfig();
54
197
  try {
55
- const res = await import_axios.default.post(URL, body, {
198
+ const res = await import_axios2.default.post(URL2, body, {
56
199
  headers: {
57
200
  "Idempotency-Key": `${value}`,
58
201
  "Monime-Space-Id": `${monimeSpaceId}`,
@@ -63,7 +206,7 @@ async function createFinancialAccount(accountName, client) {
63
206
  const data = res.data;
64
207
  return { success: true, data };
65
208
  } catch (error) {
66
- if (import_axios.default.isAxiosError(error)) {
209
+ if (import_axios2.default.isAxiosError(error)) {
67
210
  return { error, success: false };
68
211
  }
69
212
  return { error: new Error("unknown error"), success: false };
@@ -78,7 +221,7 @@ async function getFinancialAccount(financialAccountId, client) {
78
221
  }
79
222
  const { monimeSpaceId, accessToken } = client._getConfig();
80
223
  try {
81
- const res = await import_axios.default.get(`${URL}/${financialAccountId}`, {
224
+ const res = await import_axios2.default.get(`${URL2}/${financialAccountId}`, {
82
225
  headers: {
83
226
  "Monime-Space-Id": `${monimeSpaceId}`,
84
227
  Authorization: `Bearer ${accessToken}`
@@ -87,7 +230,7 @@ async function getFinancialAccount(financialAccountId, client) {
87
230
  const data = res.data;
88
231
  return { success: true, data };
89
232
  } catch (error) {
90
- if (import_axios.default.isAxiosError(error)) {
233
+ if (import_axios2.default.isAxiosError(error)) {
91
234
  return { error, success: false };
92
235
  }
93
236
  return { error: new Error("unknown error"), success: false };
@@ -96,7 +239,7 @@ async function getFinancialAccount(financialAccountId, client) {
96
239
  async function getAllFinancialAccount(client) {
97
240
  const { monimeSpaceId, accessToken } = client._getConfig();
98
241
  try {
99
- const res = await import_axios.default.get(URL, {
242
+ const res = await import_axios2.default.get(URL2, {
100
243
  headers: {
101
244
  "Monime-Space-Id": `${monimeSpaceId}`,
102
245
  Authorization: `Bearer ${accessToken}`
@@ -105,7 +248,7 @@ async function getAllFinancialAccount(client) {
105
248
  const data = res.data;
106
249
  return { success: true, data };
107
250
  } catch (error) {
108
- if (import_axios.default.isAxiosError(error)) {
251
+ if (import_axios2.default.isAxiosError(error)) {
109
252
  return { error, success: false };
110
253
  }
111
254
  return { error: new Error("unknown error"), success: false };
@@ -122,12 +265,12 @@ function FinancialAccountAPI(client) {
122
265
  }
123
266
 
124
267
  // src/modules/financialTransaction/financialTransaction.ts
125
- var import_axios2 = __toESM(require("axios"));
126
- var URL2 = "https://api.monime.io/v1/financial-transactions";
268
+ var import_axios3 = __toESM(require("axios"));
269
+ var URL3 = "https://api.monime.io/v1/financial-transactions";
127
270
  async function getAllTransaction(client) {
128
271
  const { monimeSpaceId, accessToken } = client._getConfig();
129
272
  try {
130
- const res = await import_axios2.default.get(URL2, {
273
+ const res = await import_axios3.default.get(URL3, {
131
274
  headers: {
132
275
  Authorization: `Bearer ${accessToken}`,
133
276
  "Monime-Space-Id": `${monimeSpaceId}`
@@ -136,7 +279,7 @@ async function getAllTransaction(client) {
136
279
  const data = res.data;
137
280
  return { success: true, data };
138
281
  } catch (error) {
139
- if (import_axios2.default.isAxiosError(error)) {
282
+ if (import_axios3.default.isAxiosError(error)) {
140
283
  return { error, success: false };
141
284
  }
142
285
  return { error: new Error("unknown error"), success: false };
@@ -151,7 +294,7 @@ async function getTransaction(client, transactionId) {
151
294
  };
152
295
  }
153
296
  try {
154
- const res = await import_axios2.default.get(`${URL2}/${transactionId}`, {
297
+ const res = await import_axios3.default.get(`${URL3}/${transactionId}`, {
155
298
  headers: {
156
299
  Authorization: `Bearer ${accessToken}`,
157
300
  "Monime-Space-Id": `${monimeSpaceId}`
@@ -160,7 +303,7 @@ async function getTransaction(client, transactionId) {
160
303
  const data = res.data;
161
304
  return { success: true, data };
162
305
  } catch (error) {
163
- if (import_axios2.default.isAxiosError(error)) {
306
+ if (import_axios3.default.isAxiosError(error)) {
164
307
  return { error, success: false };
165
308
  }
166
309
  return { error: new Error("unknown error"), success: false };
@@ -177,8 +320,8 @@ function FinancialTransactionAPI(client) {
177
320
 
178
321
  // src/modules/internalTransfer/internalTransfer.ts
179
322
  var import_node_crypto2 = require("crypto");
180
- var import_axios3 = __toESM(require("axios"));
181
- var URL3 = "https://api.monime.io/v1/internal-transfers";
323
+ var import_axios4 = __toESM(require("axios"));
324
+ var URL4 = "https://api.monime.io/v1/internal-transfers";
182
325
  var value2 = (0, import_node_crypto2.randomBytes)(20).toString("hex");
183
326
  async function createInternalTransfer(sourceAccount, destinationAccount, client, amount) {
184
327
  if (amount <= 0) {
@@ -208,7 +351,7 @@ async function createInternalTransfer(sourceAccount, destinationAccount, client,
208
351
  };
209
352
  const { accessToken, monimeSpaceId } = client._getConfig();
210
353
  try {
211
- const res = await import_axios3.default.post(URL3, body, {
354
+ const res = await import_axios4.default.post(URL4, body, {
212
355
  headers: {
213
356
  "Idempotency-Key": `${value2}`,
214
357
  "Monime-Space-Id": `${monimeSpaceId}`,
@@ -219,7 +362,7 @@ async function createInternalTransfer(sourceAccount, destinationAccount, client,
219
362
  const data = res.data;
220
363
  return { success: true, data };
221
364
  } catch (error) {
222
- if (import_axios3.default.isAxiosError(error)) {
365
+ if (import_axios4.default.isAxiosError(error)) {
223
366
  return { error, success: false };
224
367
  }
225
368
  return { error: new Error("unkknown error"), success: false };
@@ -228,7 +371,7 @@ async function createInternalTransfer(sourceAccount, destinationAccount, client,
228
371
  async function getAllInternalTransfers(client) {
229
372
  const { monimeSpaceId, accessToken } = client._getConfig();
230
373
  try {
231
- const res = await import_axios3.default.get(URL3, {
374
+ const res = await import_axios4.default.get(URL4, {
232
375
  headers: {
233
376
  "Monime-Space-Id": `${monimeSpaceId}`,
234
377
  Authorization: `Bearer ${accessToken}`
@@ -237,7 +380,7 @@ async function getAllInternalTransfers(client) {
237
380
  const data = res.data;
238
381
  return { success: true, data };
239
382
  } catch (error) {
240
- if (import_axios3.default.isAxiosError(error)) {
383
+ if (import_axios4.default.isAxiosError(error)) {
241
384
  return { success: false, error };
242
385
  }
243
386
  return { error: new Error("unkknown error"), success: false };
@@ -246,7 +389,7 @@ async function getAllInternalTransfers(client) {
246
389
  async function getInternalTransfer(client, internalTransferId) {
247
390
  const { accessToken, monimeSpaceId } = client._getConfig();
248
391
  try {
249
- const res = await import_axios3.default.get(`${URL3}/${internalTransferId}`, {
392
+ const res = await import_axios4.default.get(`${URL4}/${internalTransferId}`, {
250
393
  headers: {
251
394
  "Monime-Space-Id": `${monimeSpaceId}`,
252
395
  Authorization: `Bearer ${accessToken}`
@@ -255,7 +398,7 @@ async function getInternalTransfer(client, internalTransferId) {
255
398
  const data = res.data;
256
399
  return { success: true, data };
257
400
  } catch (error) {
258
- if (import_axios3.default.isAxiosError(error)) {
401
+ if (import_axios4.default.isAxiosError(error)) {
259
402
  return { success: false, error };
260
403
  }
261
404
  return { error: new Error("unkknown error"), success: false };
@@ -264,7 +407,7 @@ async function getInternalTransfer(client, internalTransferId) {
264
407
  async function deleteInternalTransfer(client, internalTransferId) {
265
408
  const { monimeSpaceId, accessToken } = client._getConfig();
266
409
  try {
267
- await import_axios3.default.delete(`${URL3}/${internalTransferId}`, {
410
+ await import_axios4.default.delete(`${URL4}/${internalTransferId}`, {
268
411
  headers: {
269
412
  "Monime-Space-Id": `${monimeSpaceId}`,
270
413
  Authorization: `Bearer ${accessToken}`
@@ -272,7 +415,7 @@ async function deleteInternalTransfer(client, internalTransferId) {
272
415
  });
273
416
  return { success: true };
274
417
  } catch (error) {
275
- if (import_axios3.default.isAxiosError(error)) {
418
+ if (import_axios4.default.isAxiosError(error)) {
276
419
  return { success: false, error };
277
420
  }
278
421
  return { success: false, error: new Error("unknown error") };
@@ -296,9 +439,9 @@ function InternalTransferAPI(client) {
296
439
 
297
440
  // src/modules/paymentCode/paymentCode.ts
298
441
  var import_node_crypto3 = require("crypto");
299
- var import_axios4 = __toESM(require("axios"));
442
+ var import_axios5 = __toESM(require("axios"));
300
443
  var value3 = (0, import_node_crypto3.randomBytes)(20).toString("hex");
301
- var URL4 = "https://api.monime.io/v1/payment-codes";
444
+ var URL5 = "https://api.monime.io/v1/payment-codes";
302
445
  async function createPaymentCode(paymentName, amount, financialAccountId, name, phoneNumber, client) {
303
446
  let financialAccount = null;
304
447
  if (financialAccountId !== "") {
@@ -343,7 +486,7 @@ async function createPaymentCode(paymentName, amount, financialAccountId, name,
343
486
  metadata: {}
344
487
  };
345
488
  try {
346
- const res = await import_axios4.default.post(URL4, bodyData, {
489
+ const res = await import_axios5.default.post(URL5, bodyData, {
347
490
  headers: {
348
491
  "Idempotency-Key": `${value3}`,
349
492
  "Monime-Space-Id": `${monimeSpaceId}`,
@@ -354,7 +497,7 @@ async function createPaymentCode(paymentName, amount, financialAccountId, name,
354
497
  const data = res.data;
355
498
  return { data, success: true };
356
499
  } catch (error) {
357
- if (import_axios4.default.isAxiosError(error)) {
500
+ if (import_axios5.default.isAxiosError(error)) {
358
501
  return { error: error.response?.data, success: false };
359
502
  }
360
503
  return { error: new Error("unknown error"), success: false };
@@ -366,7 +509,7 @@ async function deletePaymentCode(paymentCodeId, client) {
366
509
  return { success: false, error: new Error("paymentCodeId is required") };
367
510
  }
368
511
  try {
369
- await import_axios4.default.delete(`${URL4}/${paymentCodeId}`, {
512
+ await import_axios5.default.delete(`${URL5}/${paymentCodeId}`, {
370
513
  headers: {
371
514
  "Idempotency-Key": `${value3}`,
372
515
  "Monime-Space-Id": `${monimeSpaceId}`,
@@ -376,7 +519,7 @@ async function deletePaymentCode(paymentCodeId, client) {
376
519
  });
377
520
  return { success: true };
378
521
  } catch (error) {
379
- if (import_axios4.default.isAxiosError(error)) {
522
+ if (import_axios5.default.isAxiosError(error)) {
380
523
  return { error, success: false };
381
524
  }
382
525
  return { error: new Error("unknown error"), success: false };
@@ -385,7 +528,7 @@ async function deletePaymentCode(paymentCodeId, client) {
385
528
  async function getAllPaymentCode(client) {
386
529
  const { monimeSpaceId, accessToken } = client._getConfig();
387
530
  try {
388
- const res = await import_axios4.default.get(URL4, {
531
+ const res = await import_axios5.default.get(URL5, {
389
532
  headers: {
390
533
  "Monime-Space-Id": `${monimeSpaceId}`,
391
534
  Authorization: `Bearer ${accessToken}`
@@ -394,7 +537,7 @@ async function getAllPaymentCode(client) {
394
537
  const data = res.data;
395
538
  return { success: true, data };
396
539
  } catch (error) {
397
- if (import_axios4.default.isAxiosError(error)) {
540
+ if (import_axios5.default.isAxiosError(error)) {
398
541
  return { error, success: false };
399
542
  }
400
543
  return { error: new Error("unknown error"), success: false };
@@ -403,7 +546,7 @@ async function getAllPaymentCode(client) {
403
546
  async function getPaymentCode(paymentCodeId, client) {
404
547
  const { monimeSpaceId, accessToken } = client._getConfig();
405
548
  try {
406
- const res = await import_axios4.default.get(`${URL4}/${paymentCodeId}`, {
549
+ const res = await import_axios5.default.get(`${URL5}/${paymentCodeId}`, {
407
550
  headers: {
408
551
  "Monime-Space-Id": `${monimeSpaceId}`,
409
552
  Authorization: `Bearer ${accessToken}`
@@ -412,7 +555,7 @@ async function getPaymentCode(paymentCodeId, client) {
412
555
  const data = res.data;
413
556
  return { success: true, data };
414
557
  } catch (error) {
415
- if (import_axios4.default.isAxiosError(error)) {
558
+ if (import_axios5.default.isAxiosError(error)) {
416
559
  return { error, success: false };
417
560
  }
418
561
  return { error: new Error("unknown error"), success: false };
@@ -438,8 +581,8 @@ function PaymentCodeAPI(client) {
438
581
 
439
582
  // src/modules/payout/payout.ts
440
583
  var import_node_crypto4 = require("crypto");
441
- var import_axios5 = __toESM(require("axios"));
442
- var URL5 = "https://api.monime.io/v1/payouts";
584
+ var import_axios6 = __toESM(require("axios"));
585
+ var URL6 = "https://api.monime.io/v1/payouts";
443
586
  var value4 = (0, import_node_crypto4.randomBytes)(20).toString("hex");
444
587
  async function createPayout(amount, sourceAccount, destination, client) {
445
588
  if (sourceAccount.trim() === "") {
@@ -467,7 +610,7 @@ async function createPayout(amount, sourceAccount, destination, client) {
467
610
  metadata: {}
468
611
  };
469
612
  try {
470
- const res = await import_axios5.default.post(URL5, body, {
613
+ const res = await import_axios6.default.post(URL6, body, {
471
614
  headers: {
472
615
  "Idempotency-Key": `${value4}`,
473
616
  "Monime-Space-Id": `${monimeSpaceId}`,
@@ -478,7 +621,7 @@ async function createPayout(amount, sourceAccount, destination, client) {
478
621
  const data = res.data;
479
622
  return { success: true, data };
480
623
  } catch (error) {
481
- if (import_axios5.default.isAxiosError(error)) {
624
+ if (import_axios6.default.isAxiosError(error)) {
482
625
  return { success: false, error };
483
626
  }
484
627
  return { success: false, error: new Error("unknown error") };
@@ -487,7 +630,7 @@ async function createPayout(amount, sourceAccount, destination, client) {
487
630
  async function getAllPayout(client) {
488
631
  const { accessToken, monimeSpaceId } = client._getConfig();
489
632
  try {
490
- const res = await import_axios5.default.get(URL5, {
633
+ const res = await import_axios6.default.get(URL6, {
491
634
  headers: {
492
635
  "Monime-Space-Id": `${monimeSpaceId}`,
493
636
  Authorization: `Bearer ${accessToken}`
@@ -496,7 +639,7 @@ async function getAllPayout(client) {
496
639
  const data = res.data;
497
640
  return { success: true, data };
498
641
  } catch (error) {
499
- if (import_axios5.default.isAxiosError(error)) {
642
+ if (import_axios6.default.isAxiosError(error)) {
500
643
  return { success: false, error };
501
644
  }
502
645
  return { success: false, error: new Error("unknown error") };
@@ -505,7 +648,7 @@ async function getAllPayout(client) {
505
648
  async function getPayout(payoutId, client) {
506
649
  const { accessToken, monimeSpaceId } = client._getConfig();
507
650
  try {
508
- const res = await import_axios5.default.get(`${URL5}/${payoutId}`, {
651
+ const res = await import_axios6.default.get(`${URL6}/${payoutId}`, {
509
652
  headers: {
510
653
  "Monime-Space-Id": `${monimeSpaceId}`,
511
654
  Authorization: `Bearer ${accessToken}`
@@ -514,7 +657,7 @@ async function getPayout(payoutId, client) {
514
657
  const data = res.data;
515
658
  return { success: true, data };
516
659
  } catch (error) {
517
- if (import_axios5.default.isAxiosError(error)) {
660
+ if (import_axios6.default.isAxiosError(error)) {
518
661
  return { success: false, error };
519
662
  }
520
663
  return { success: false, error: new Error("unknown error") };
@@ -523,7 +666,7 @@ async function getPayout(payoutId, client) {
523
666
  async function deletePayout(payoutId, client) {
524
667
  const { accessToken, monimeSpaceId } = client._getConfig();
525
668
  try {
526
- await import_axios5.default.delete(`${URL5}/${payoutId}`, {
669
+ await import_axios6.default.delete(`${URL6}/${payoutId}`, {
527
670
  headers: {
528
671
  "Monime-Space-Id": `${monimeSpaceId}`,
529
672
  Authorization: `Bearer ${accessToken}`
@@ -531,7 +674,7 @@ async function deletePayout(payoutId, client) {
531
674
  });
532
675
  return { success: true };
533
676
  } catch (error) {
534
- if (import_axios5.default.isAxiosError(error)) {
677
+ if (import_axios6.default.isAxiosError(error)) {
535
678
  return { success: false, error };
536
679
  }
537
680
  return { success: false, error: new Error("unknown error") };
@@ -557,6 +700,7 @@ var MonimeClient = class {
557
700
  paymentCode;
558
701
  payout;
559
702
  financialTransaction;
703
+ checkoutSession;
560
704
  constructor(options) {
561
705
  this.accessToken = options.accessToken;
562
706
  this.monimeSpaceId = options.monimeSpaceId;
@@ -565,6 +709,7 @@ var MonimeClient = class {
565
709
  this.paymentCode = PaymentCodeAPI(this);
566
710
  this.payout = PayoutAPI(this);
567
711
  this.financialTransaction = FinancialTransactionAPI(this);
712
+ this.checkoutSession = CheckoutSessionAPI(this);
568
713
  }
569
714
  /** @internal */
570
715
  _getConfig() {