monime-package 1.0.8 → 1.1.0
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/README.md +69 -0
- package/dist/index.d.mts +251 -11
- package/dist/index.d.ts +251 -11
- package/dist/index.js +1 -737
- package/dist/index.mjs +1 -699
- package/package.json +1 -1
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,699 +1 @@
|
|
|
1
|
-
// src/modules/checkout session/checkoutSession.ts
|
|
2
|
-
import { randomBytes } from "crypto";
|
|
3
|
-
import axios from "axios";
|
|
4
|
-
var value = randomBytes(20).toString("hex");
|
|
5
|
-
var URL = "https://api.monime.io/v1/checkout-sessions";
|
|
6
|
-
async function createCheckout(client, name, amount, quantity, successUrl, cancelUrl, description, financialAccountId, primaryColor, images) {
|
|
7
|
-
const { monimeSpaceId, accessToken } = client._getConfig();
|
|
8
|
-
const body = {
|
|
9
|
-
name,
|
|
10
|
-
description,
|
|
11
|
-
cancelUrl,
|
|
12
|
-
successUrl,
|
|
13
|
-
callbackState: null,
|
|
14
|
-
reference: null,
|
|
15
|
-
financialAccountId,
|
|
16
|
-
lineItems: [
|
|
17
|
-
{
|
|
18
|
-
type: "custom",
|
|
19
|
-
name,
|
|
20
|
-
price: {
|
|
21
|
-
currency: "SLE",
|
|
22
|
-
value: amount
|
|
23
|
-
},
|
|
24
|
-
quantity,
|
|
25
|
-
reference: null,
|
|
26
|
-
description,
|
|
27
|
-
images
|
|
28
|
-
}
|
|
29
|
-
],
|
|
30
|
-
paymentOptions: {
|
|
31
|
-
card: {
|
|
32
|
-
disable: false
|
|
33
|
-
},
|
|
34
|
-
bank: {
|
|
35
|
-
disable: false,
|
|
36
|
-
enabledProviders: ["slb001", "slb004", "slb007"]
|
|
37
|
-
// disabledProviders: ["slb001"],
|
|
38
|
-
},
|
|
39
|
-
momo: {
|
|
40
|
-
disable: false,
|
|
41
|
-
enabledProviders: ["m17", "m18"]
|
|
42
|
-
// disabledProviders: ["m17"],
|
|
43
|
-
},
|
|
44
|
-
wallet: {
|
|
45
|
-
disable: false,
|
|
46
|
-
enabledProviders: ["dw001"]
|
|
47
|
-
// disabledProviders: ["dw001"],
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
brandingOptions: {
|
|
51
|
-
primaryColor
|
|
52
|
-
},
|
|
53
|
-
metadata: {}
|
|
54
|
-
};
|
|
55
|
-
try {
|
|
56
|
-
const res = await axios.post(URL, body, {
|
|
57
|
-
headers: {
|
|
58
|
-
"Monime-Space-Id": monimeSpaceId,
|
|
59
|
-
Authorization: `Bearer ${accessToken}`,
|
|
60
|
-
"Content-Type": "application/json",
|
|
61
|
-
"Idempotency-Key": value,
|
|
62
|
-
"Monime-Version": "caph.2025-08-23"
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
const data = res.data;
|
|
66
|
-
return { success: true, data };
|
|
67
|
-
} catch (error) {
|
|
68
|
-
if (axios.isAxiosError(error)) {
|
|
69
|
-
return { error, success: false };
|
|
70
|
-
}
|
|
71
|
-
return { error: new Error("unknown error"), success: false };
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
async function getAllCheckout(client) {
|
|
75
|
-
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
76
|
-
try {
|
|
77
|
-
const res = await axios.get(URL, {
|
|
78
|
-
headers: {
|
|
79
|
-
"Monime-Space-Id": monimeSpaceId,
|
|
80
|
-
Authorization: `Bearer ${accessToken}`
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
const data = res.data;
|
|
84
|
-
return { success: true, data };
|
|
85
|
-
} catch (error) {
|
|
86
|
-
if (axios.isAxiosError(error)) {
|
|
87
|
-
return { error, success: false };
|
|
88
|
-
}
|
|
89
|
-
return { error: new Error("unknown error"), success: false };
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
async function getOnecheckout(client, checkoutId) {
|
|
93
|
-
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
94
|
-
try {
|
|
95
|
-
const res = await axios.get(`${URL}/${checkoutId}`, {
|
|
96
|
-
headers: {
|
|
97
|
-
"Monime-Space-Id": monimeSpaceId,
|
|
98
|
-
Authorization: `Bearer ${accessToken}`
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
const data = res.data;
|
|
102
|
-
return { success: true, data };
|
|
103
|
-
} catch (error) {
|
|
104
|
-
if (axios.isAxiosError(error)) {
|
|
105
|
-
return { error, success: false };
|
|
106
|
-
}
|
|
107
|
-
return { error: new Error("unknown error"), success: false };
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
async function deleteCheckout(client, checkoutId) {
|
|
111
|
-
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
112
|
-
try {
|
|
113
|
-
await axios.delete(`${URL}/${checkoutId}`, {
|
|
114
|
-
headers: {
|
|
115
|
-
"Monime-Space-Id": monimeSpaceId,
|
|
116
|
-
Authorization: `Bearer ${accessToken}`
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
return { success: true };
|
|
120
|
-
} catch (error) {
|
|
121
|
-
if (axios.isAxiosError(error)) {
|
|
122
|
-
return { error, success: false };
|
|
123
|
-
}
|
|
124
|
-
return { error: new Error("unknown error"), success: false };
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// src/modules/checkout session/index.ts
|
|
129
|
-
function CheckoutSessionAPI(client) {
|
|
130
|
-
return {
|
|
131
|
-
create: (name, amount, quantity, successUrl, cancelUrl, description, financialAccountId, primaryColor, images) => createCheckout(
|
|
132
|
-
client,
|
|
133
|
-
name,
|
|
134
|
-
amount,
|
|
135
|
-
quantity,
|
|
136
|
-
successUrl,
|
|
137
|
-
cancelUrl,
|
|
138
|
-
description,
|
|
139
|
-
financialAccountId,
|
|
140
|
-
primaryColor,
|
|
141
|
-
images
|
|
142
|
-
),
|
|
143
|
-
get: () => getAllCheckout(client),
|
|
144
|
-
getOne: (checkoutId) => getOnecheckout(client, checkoutId),
|
|
145
|
-
delete: (checkoutId) => deleteCheckout(client, checkoutId)
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// src/modules/financialAccount/financialAccount.ts
|
|
150
|
-
import { randomBytes as randomBytes2 } from "crypto";
|
|
151
|
-
import axios2 from "axios";
|
|
152
|
-
var URL2 = "https://api.monime.io/v1/financial-accounts";
|
|
153
|
-
var value2 = randomBytes2(20).toString("hex");
|
|
154
|
-
async function createFinancialAccount(accountName, currency, client) {
|
|
155
|
-
if (accountName.trim() === "") {
|
|
156
|
-
return { success: false, error: new Error("accountName is required") };
|
|
157
|
-
}
|
|
158
|
-
const body = {
|
|
159
|
-
name: accountName,
|
|
160
|
-
currency,
|
|
161
|
-
description: "",
|
|
162
|
-
metadata: {}
|
|
163
|
-
};
|
|
164
|
-
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
165
|
-
try {
|
|
166
|
-
const res = await axios2.post(URL2, body, {
|
|
167
|
-
headers: {
|
|
168
|
-
"Idempotency-Key": `${value2}`,
|
|
169
|
-
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
170
|
-
Authorization: `Bearer ${accessToken}`,
|
|
171
|
-
"Content-Type": "application/json"
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
const data = res.data;
|
|
175
|
-
return { success: true, data };
|
|
176
|
-
} catch (error) {
|
|
177
|
-
if (axios2.isAxiosError(error)) {
|
|
178
|
-
return { error, success: false };
|
|
179
|
-
}
|
|
180
|
-
return { error: new Error("unknown error"), success: false };
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
async function getFinancialAccount(financialAccountId, client) {
|
|
184
|
-
if (financialAccountId.trim() === "") {
|
|
185
|
-
return {
|
|
186
|
-
success: false,
|
|
187
|
-
error: new Error("financialAccountId is required")
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
const { monimeSpaceId, accessToken } = client._getConfig();
|
|
191
|
-
try {
|
|
192
|
-
const res = await axios2.get(`${URL2}/${financialAccountId}`, {
|
|
193
|
-
headers: {
|
|
194
|
-
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
195
|
-
Authorization: `Bearer ${accessToken}`
|
|
196
|
-
}
|
|
197
|
-
});
|
|
198
|
-
const data = res.data;
|
|
199
|
-
return { success: true, data };
|
|
200
|
-
} catch (error) {
|
|
201
|
-
if (axios2.isAxiosError(error)) {
|
|
202
|
-
return { error, success: false };
|
|
203
|
-
}
|
|
204
|
-
return { error: new Error("unknown error"), success: false };
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
async function getAllFinancialAccount(client) {
|
|
208
|
-
const { monimeSpaceId, accessToken } = client._getConfig();
|
|
209
|
-
try {
|
|
210
|
-
const res = await axios2.get(URL2, {
|
|
211
|
-
headers: {
|
|
212
|
-
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
213
|
-
Authorization: `Bearer ${accessToken}`
|
|
214
|
-
}
|
|
215
|
-
});
|
|
216
|
-
const data = res.data;
|
|
217
|
-
return { success: true, data };
|
|
218
|
-
} catch (error) {
|
|
219
|
-
if (axios2.isAxiosError(error)) {
|
|
220
|
-
return { error, success: false };
|
|
221
|
-
}
|
|
222
|
-
return { error: new Error("unknown error"), success: false };
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
// src/modules/financialAccount/index.ts
|
|
227
|
-
function FinancialAccountAPI(client) {
|
|
228
|
-
return {
|
|
229
|
-
create: (name, currency) => createFinancialAccount(name, currency, client),
|
|
230
|
-
get: (financialAccountId) => getFinancialAccount(financialAccountId, client),
|
|
231
|
-
getAll: () => getAllFinancialAccount(client)
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
// src/modules/financialTransaction/financialTransaction.ts
|
|
236
|
-
import axios3 from "axios";
|
|
237
|
-
var URL3 = "https://api.monime.io/v1/financial-transactions";
|
|
238
|
-
async function getAllTransaction(client) {
|
|
239
|
-
const { monimeSpaceId, accessToken } = client._getConfig();
|
|
240
|
-
try {
|
|
241
|
-
const res = await axios3.get(URL3, {
|
|
242
|
-
headers: {
|
|
243
|
-
Authorization: `Bearer ${accessToken}`,
|
|
244
|
-
"Monime-Space-Id": `${monimeSpaceId}`
|
|
245
|
-
}
|
|
246
|
-
});
|
|
247
|
-
const data = res.data;
|
|
248
|
-
return { success: true, data };
|
|
249
|
-
} catch (error) {
|
|
250
|
-
if (axios3.isAxiosError(error)) {
|
|
251
|
-
return { error, success: false };
|
|
252
|
-
}
|
|
253
|
-
return { error: new Error("unknown error"), success: false };
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
async function getTransaction(client, transactionId) {
|
|
257
|
-
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
258
|
-
if (transactionId.trim() === "") {
|
|
259
|
-
return {
|
|
260
|
-
error: new Error("transactionId must not be empty"),
|
|
261
|
-
success: false
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
try {
|
|
265
|
-
const res = await axios3.get(`${URL3}/${transactionId}`, {
|
|
266
|
-
headers: {
|
|
267
|
-
Authorization: `Bearer ${accessToken}`,
|
|
268
|
-
"Monime-Space-Id": `${monimeSpaceId}`
|
|
269
|
-
}
|
|
270
|
-
});
|
|
271
|
-
const data = res.data;
|
|
272
|
-
return { success: true, data };
|
|
273
|
-
} catch (error) {
|
|
274
|
-
if (axios3.isAxiosError(error)) {
|
|
275
|
-
return { error, success: false };
|
|
276
|
-
}
|
|
277
|
-
return { error: new Error("unknown error"), success: false };
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
// src/modules/financialTransaction/index.ts
|
|
282
|
-
function FinancialTransactionAPI(client) {
|
|
283
|
-
return {
|
|
284
|
-
get: (transactionId) => getTransaction(client, transactionId),
|
|
285
|
-
getAll: () => getAllTransaction(client)
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
// src/modules/internalTransfer/internalTransfer.ts
|
|
290
|
-
import { randomBytes as randomBytes3 } from "crypto";
|
|
291
|
-
import axios4 from "axios";
|
|
292
|
-
var URL4 = "https://api.monime.io/v1/internal-transfers";
|
|
293
|
-
var value3 = randomBytes3(20).toString("hex");
|
|
294
|
-
async function createInternalTransfer(sourceAccount, destinationAccount, client, amount) {
|
|
295
|
-
if (amount <= 0) {
|
|
296
|
-
return {
|
|
297
|
-
success: false,
|
|
298
|
-
error: new Error("amount must be larger that zero")
|
|
299
|
-
};
|
|
300
|
-
}
|
|
301
|
-
if (sourceAccount.trim() === "" || destinationAccount.trim() === "") {
|
|
302
|
-
return {
|
|
303
|
-
success: false,
|
|
304
|
-
error: new Error("sourceAccount or destinationAccount is missing")
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
|
-
const body = {
|
|
308
|
-
amount: {
|
|
309
|
-
currency: "SLE",
|
|
310
|
-
value: amount
|
|
311
|
-
},
|
|
312
|
-
sourceFinancialAccount: {
|
|
313
|
-
id: sourceAccount
|
|
314
|
-
},
|
|
315
|
-
destinationFinancialAccount: {
|
|
316
|
-
id: destinationAccount
|
|
317
|
-
},
|
|
318
|
-
metadata: {}
|
|
319
|
-
};
|
|
320
|
-
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
321
|
-
try {
|
|
322
|
-
const res = await axios4.post(URL4, body, {
|
|
323
|
-
headers: {
|
|
324
|
-
"Idempotency-Key": `${value3}`,
|
|
325
|
-
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
326
|
-
Authorization: `Bearer ${accessToken}`,
|
|
327
|
-
"Content-Type": "application/json"
|
|
328
|
-
}
|
|
329
|
-
});
|
|
330
|
-
const data = res.data;
|
|
331
|
-
return { success: true, data };
|
|
332
|
-
} catch (error) {
|
|
333
|
-
if (axios4.isAxiosError(error)) {
|
|
334
|
-
return { error, success: false };
|
|
335
|
-
}
|
|
336
|
-
return { error: new Error("unkknown error"), success: false };
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
async function getAllInternalTransfers(client) {
|
|
340
|
-
const { monimeSpaceId, accessToken } = client._getConfig();
|
|
341
|
-
try {
|
|
342
|
-
const res = await axios4.get(URL4, {
|
|
343
|
-
headers: {
|
|
344
|
-
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
345
|
-
Authorization: `Bearer ${accessToken}`
|
|
346
|
-
}
|
|
347
|
-
});
|
|
348
|
-
const data = res.data;
|
|
349
|
-
return { success: true, data };
|
|
350
|
-
} catch (error) {
|
|
351
|
-
if (axios4.isAxiosError(error)) {
|
|
352
|
-
return { success: false, error };
|
|
353
|
-
}
|
|
354
|
-
return { error: new Error("unkknown error"), success: false };
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
async function getInternalTransfer(client, internalTransferId) {
|
|
358
|
-
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
359
|
-
try {
|
|
360
|
-
const res = await axios4.get(`${URL4}/${internalTransferId}`, {
|
|
361
|
-
headers: {
|
|
362
|
-
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
363
|
-
Authorization: `Bearer ${accessToken}`
|
|
364
|
-
}
|
|
365
|
-
});
|
|
366
|
-
const data = res.data;
|
|
367
|
-
return { success: true, data };
|
|
368
|
-
} catch (error) {
|
|
369
|
-
if (axios4.isAxiosError(error)) {
|
|
370
|
-
return { success: false, error };
|
|
371
|
-
}
|
|
372
|
-
return { error: new Error("unkknown error"), success: false };
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
async function deleteInternalTransfer(client, internalTransferId) {
|
|
376
|
-
const { monimeSpaceId, accessToken } = client._getConfig();
|
|
377
|
-
try {
|
|
378
|
-
await axios4.delete(`${URL4}/${internalTransferId}`, {
|
|
379
|
-
headers: {
|
|
380
|
-
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
381
|
-
Authorization: `Bearer ${accessToken}`
|
|
382
|
-
}
|
|
383
|
-
});
|
|
384
|
-
return { success: true };
|
|
385
|
-
} catch (error) {
|
|
386
|
-
if (axios4.isAxiosError(error)) {
|
|
387
|
-
return { success: false, error };
|
|
388
|
-
}
|
|
389
|
-
return { success: false, error: new Error("unknown error") };
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
// src/modules/internalTransfer/index.ts
|
|
394
|
-
function InternalTransferAPI(client) {
|
|
395
|
-
return {
|
|
396
|
-
create: (sourceAccount, destinationAccount, amount) => createInternalTransfer(
|
|
397
|
-
sourceAccount,
|
|
398
|
-
destinationAccount,
|
|
399
|
-
client,
|
|
400
|
-
amount
|
|
401
|
-
),
|
|
402
|
-
get: (internalTransferId) => getInternalTransfer(client, internalTransferId),
|
|
403
|
-
getAll: () => getAllInternalTransfers(client),
|
|
404
|
-
delete: (internalTransferId) => deleteInternalTransfer(client, internalTransferId)
|
|
405
|
-
};
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
// src/modules/paymentCode/paymentCode.ts
|
|
409
|
-
import { randomBytes as randomBytes4 } from "crypto";
|
|
410
|
-
import axios5 from "axios";
|
|
411
|
-
var value4 = randomBytes4(20).toString("hex");
|
|
412
|
-
var URL5 = "https://api.monime.io/v1/payment-codes";
|
|
413
|
-
async function createPaymentCode(paymentName, amount, financialAccountId, name, phoneNumber, client) {
|
|
414
|
-
let financialAccount = null;
|
|
415
|
-
if (financialAccountId !== "") {
|
|
416
|
-
financialAccount = financialAccountId;
|
|
417
|
-
}
|
|
418
|
-
if (paymentName.trim() === "" || name.trim() === "" || phoneNumber.trim() === "") {
|
|
419
|
-
return {
|
|
420
|
-
success: false,
|
|
421
|
-
error: new Error("paymentName, name, or phoneNumber is missing")
|
|
422
|
-
};
|
|
423
|
-
}
|
|
424
|
-
if (amount <= 0) {
|
|
425
|
-
return {
|
|
426
|
-
success: false,
|
|
427
|
-
error: new Error("amonut number be greater than zero")
|
|
428
|
-
};
|
|
429
|
-
}
|
|
430
|
-
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
431
|
-
const bodyData = {
|
|
432
|
-
name: `${paymentName}`,
|
|
433
|
-
mode: "recurrent",
|
|
434
|
-
enable: true,
|
|
435
|
-
amount: {
|
|
436
|
-
currency: "SLE",
|
|
437
|
-
value: amount * 100
|
|
438
|
-
},
|
|
439
|
-
duration: "1h30m",
|
|
440
|
-
customer: {
|
|
441
|
-
name: `${name}`
|
|
442
|
-
},
|
|
443
|
-
reference: "",
|
|
444
|
-
authorizedPhoneNumber: phoneNumber,
|
|
445
|
-
// authorizedProviders: ["m17", "m18"],
|
|
446
|
-
recurrentPaymentTarget: {
|
|
447
|
-
expectedPaymentCount: 1,
|
|
448
|
-
expectedPaymentTotal: {
|
|
449
|
-
currency: "SLE",
|
|
450
|
-
value: amount * 100
|
|
451
|
-
}
|
|
452
|
-
},
|
|
453
|
-
financialAccountId: financialAccount,
|
|
454
|
-
metadata: {}
|
|
455
|
-
};
|
|
456
|
-
try {
|
|
457
|
-
const res = await axios5.post(URL5, bodyData, {
|
|
458
|
-
headers: {
|
|
459
|
-
"Idempotency-Key": `${value4}`,
|
|
460
|
-
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
461
|
-
Authorization: `Bearer ${accessToken}`,
|
|
462
|
-
"Content-Type": "application/json"
|
|
463
|
-
}
|
|
464
|
-
});
|
|
465
|
-
const data = res.data;
|
|
466
|
-
return { data, success: true };
|
|
467
|
-
} catch (error) {
|
|
468
|
-
if (axios5.isAxiosError(error)) {
|
|
469
|
-
return { error: error.response?.data, success: false };
|
|
470
|
-
}
|
|
471
|
-
return { error: new Error("unknown error"), success: false };
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
async function deletePaymentCode(paymentCodeId, client) {
|
|
475
|
-
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
476
|
-
if (paymentCodeId.trim() === "") {
|
|
477
|
-
return { success: false, error: new Error("paymentCodeId is required") };
|
|
478
|
-
}
|
|
479
|
-
try {
|
|
480
|
-
await axios5.delete(`${URL5}/${paymentCodeId}`, {
|
|
481
|
-
headers: {
|
|
482
|
-
"Idempotency-Key": `${value4}`,
|
|
483
|
-
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
484
|
-
Authorization: `Bearer ${accessToken}`,
|
|
485
|
-
"Content-Type": "application/json"
|
|
486
|
-
}
|
|
487
|
-
});
|
|
488
|
-
return { success: true };
|
|
489
|
-
} catch (error) {
|
|
490
|
-
if (axios5.isAxiosError(error)) {
|
|
491
|
-
return { error, success: false };
|
|
492
|
-
}
|
|
493
|
-
return { error: new Error("unknown error"), success: false };
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
async function getAllPaymentCode(client) {
|
|
497
|
-
const { monimeSpaceId, accessToken } = client._getConfig();
|
|
498
|
-
try {
|
|
499
|
-
const res = await axios5.get(URL5, {
|
|
500
|
-
headers: {
|
|
501
|
-
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
502
|
-
Authorization: `Bearer ${accessToken}`
|
|
503
|
-
}
|
|
504
|
-
});
|
|
505
|
-
const data = res.data;
|
|
506
|
-
return { success: true, data };
|
|
507
|
-
} catch (error) {
|
|
508
|
-
if (axios5.isAxiosError(error)) {
|
|
509
|
-
return { error, success: false };
|
|
510
|
-
}
|
|
511
|
-
return { error: new Error("unknown error"), success: false };
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
async function getPaymentCode(paymentCodeId, client) {
|
|
515
|
-
const { monimeSpaceId, accessToken } = client._getConfig();
|
|
516
|
-
try {
|
|
517
|
-
const res = await axios5.get(`${URL5}/${paymentCodeId}`, {
|
|
518
|
-
headers: {
|
|
519
|
-
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
520
|
-
Authorization: `Bearer ${accessToken}`
|
|
521
|
-
}
|
|
522
|
-
});
|
|
523
|
-
const data = res.data;
|
|
524
|
-
return { success: true, data };
|
|
525
|
-
} catch (error) {
|
|
526
|
-
if (axios5.isAxiosError(error)) {
|
|
527
|
-
return { error, success: false };
|
|
528
|
-
}
|
|
529
|
-
return { error: new Error("unknown error"), success: false };
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
// src/modules/paymentCode/index.ts
|
|
534
|
-
function PaymentCodeAPI(client) {
|
|
535
|
-
return {
|
|
536
|
-
create: (paymentName, amount, financialAccount, username, phoneNumber) => createPaymentCode(
|
|
537
|
-
paymentName,
|
|
538
|
-
amount,
|
|
539
|
-
financialAccount,
|
|
540
|
-
username,
|
|
541
|
-
phoneNumber,
|
|
542
|
-
client
|
|
543
|
-
),
|
|
544
|
-
delete: (paymentCodeId) => deletePaymentCode(paymentCodeId, client),
|
|
545
|
-
getAll: () => getAllPaymentCode(client),
|
|
546
|
-
get: (paymentCodeId) => getPaymentCode(paymentCodeId, client)
|
|
547
|
-
};
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
// src/modules/payout/payout.ts
|
|
551
|
-
import { randomBytes as randomBytes5 } from "crypto";
|
|
552
|
-
import axios6 from "axios";
|
|
553
|
-
var URL6 = "https://api.monime.io/v1/payouts";
|
|
554
|
-
var value5 = randomBytes5(20).toString("hex");
|
|
555
|
-
async function createPayout(amount, sourceAccount, destination, client) {
|
|
556
|
-
if (sourceAccount.trim() === "") {
|
|
557
|
-
return {
|
|
558
|
-
success: false,
|
|
559
|
-
error: new Error("sourceAccount cannot be empty")
|
|
560
|
-
};
|
|
561
|
-
}
|
|
562
|
-
if (amount <= 0) {
|
|
563
|
-
return {
|
|
564
|
-
error: new Error("amount must be greater than 0"),
|
|
565
|
-
success: false
|
|
566
|
-
};
|
|
567
|
-
}
|
|
568
|
-
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
569
|
-
const body = {
|
|
570
|
-
amount: {
|
|
571
|
-
currency: "SLE",
|
|
572
|
-
value: amount
|
|
573
|
-
},
|
|
574
|
-
source: {
|
|
575
|
-
financialAccountId: sourceAccount
|
|
576
|
-
},
|
|
577
|
-
destination,
|
|
578
|
-
metadata: {}
|
|
579
|
-
};
|
|
580
|
-
try {
|
|
581
|
-
const res = await axios6.post(URL6, body, {
|
|
582
|
-
headers: {
|
|
583
|
-
"Idempotency-Key": `${value5}`,
|
|
584
|
-
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
585
|
-
Authorization: `Bearer ${accessToken}`,
|
|
586
|
-
"Content-Type": "application/json"
|
|
587
|
-
}
|
|
588
|
-
});
|
|
589
|
-
const data = res.data;
|
|
590
|
-
return { success: true, data };
|
|
591
|
-
} catch (error) {
|
|
592
|
-
if (axios6.isAxiosError(error)) {
|
|
593
|
-
return { success: false, error };
|
|
594
|
-
}
|
|
595
|
-
return { success: false, error: new Error("unknown error") };
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
async function getAllPayout(client) {
|
|
599
|
-
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
600
|
-
try {
|
|
601
|
-
const res = await axios6.get(URL6, {
|
|
602
|
-
headers: {
|
|
603
|
-
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
604
|
-
Authorization: `Bearer ${accessToken}`
|
|
605
|
-
}
|
|
606
|
-
});
|
|
607
|
-
const data = res.data;
|
|
608
|
-
return { success: true, data };
|
|
609
|
-
} catch (error) {
|
|
610
|
-
if (axios6.isAxiosError(error)) {
|
|
611
|
-
return { success: false, error };
|
|
612
|
-
}
|
|
613
|
-
return { success: false, error: new Error("unknown error") };
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
async function getPayout(payoutId, client) {
|
|
617
|
-
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
618
|
-
try {
|
|
619
|
-
const res = await axios6.get(`${URL6}/${payoutId}`, {
|
|
620
|
-
headers: {
|
|
621
|
-
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
622
|
-
Authorization: `Bearer ${accessToken}`
|
|
623
|
-
}
|
|
624
|
-
});
|
|
625
|
-
const data = res.data;
|
|
626
|
-
return { success: true, data };
|
|
627
|
-
} catch (error) {
|
|
628
|
-
if (axios6.isAxiosError(error)) {
|
|
629
|
-
return { success: false, error };
|
|
630
|
-
}
|
|
631
|
-
return { success: false, error: new Error("unknown error") };
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
async function deletePayout(payoutId, client) {
|
|
635
|
-
const { accessToken, monimeSpaceId } = client._getConfig();
|
|
636
|
-
try {
|
|
637
|
-
await axios6.delete(`${URL6}/${payoutId}`, {
|
|
638
|
-
headers: {
|
|
639
|
-
"Monime-Space-Id": `${monimeSpaceId}`,
|
|
640
|
-
Authorization: `Bearer ${accessToken}`
|
|
641
|
-
}
|
|
642
|
-
});
|
|
643
|
-
return { success: true };
|
|
644
|
-
} catch (error) {
|
|
645
|
-
if (axios6.isAxiosError(error)) {
|
|
646
|
-
return { success: false, error };
|
|
647
|
-
}
|
|
648
|
-
return { success: false, error: new Error("unknown error") };
|
|
649
|
-
}
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
// src/modules/payout/index.ts
|
|
653
|
-
function PayoutAPI(client) {
|
|
654
|
-
return {
|
|
655
|
-
create: (amount, destination, sourceAccount) => createPayout(amount, sourceAccount, destination, client),
|
|
656
|
-
get: () => getAllPayout(client),
|
|
657
|
-
getOne: (payoutId) => getPayout(payoutId, client),
|
|
658
|
-
delete: (payoutId) => deletePayout(payoutId, client)
|
|
659
|
-
};
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
// src/client.ts
|
|
663
|
-
var MonimeClient = class {
|
|
664
|
-
monimeSpaceId;
|
|
665
|
-
accessToken;
|
|
666
|
-
financialAccount;
|
|
667
|
-
internalTransfer;
|
|
668
|
-
paymentCode;
|
|
669
|
-
payout;
|
|
670
|
-
financialTransaction;
|
|
671
|
-
checkoutSession;
|
|
672
|
-
constructor(options) {
|
|
673
|
-
this.accessToken = options.accessToken;
|
|
674
|
-
this.monimeSpaceId = options.monimeSpaceId;
|
|
675
|
-
this.financialAccount = FinancialAccountAPI(this);
|
|
676
|
-
this.internalTransfer = InternalTransferAPI(this);
|
|
677
|
-
this.paymentCode = PaymentCodeAPI(this);
|
|
678
|
-
this.payout = PayoutAPI(this);
|
|
679
|
-
this.financialTransaction = FinancialTransactionAPI(this);
|
|
680
|
-
this.checkoutSession = CheckoutSessionAPI(this);
|
|
681
|
-
}
|
|
682
|
-
/** @internal */
|
|
683
|
-
_getConfig() {
|
|
684
|
-
return {
|
|
685
|
-
monimeSpaceId: this.monimeSpaceId,
|
|
686
|
-
accessToken: this.accessToken
|
|
687
|
-
};
|
|
688
|
-
}
|
|
689
|
-
};
|
|
690
|
-
|
|
691
|
-
// src/index.ts
|
|
692
|
-
function createClient(options) {
|
|
693
|
-
return new MonimeClient(options);
|
|
694
|
-
}
|
|
695
|
-
export {
|
|
696
|
-
MonimeClient,
|
|
697
|
-
createClient
|
|
698
|
-
};
|
|
699
|
-
//# sourceMappingURL=index.mjs.map
|
|
1
|
+
import{randomBytes as Oe}from"crypto";import d from"axios";var Ge=Oe(20).toString("hex"),P="https://api.monime.io/v1/checkout-sessions";async function v(r,e,n,o,t,s,a,u,m,p){let{monimeSpaceId:E,accessToken:A,monimeVersion:S}=r,Se={name:e,description:a,cancelUrl:s,successUrl:t,callbackState:null,reference:null,financialAccountId:u,lineItems:[{type:"custom",name:e,price:{currency:"SLE",value:n},quantity:o,reference:null,description:a,images:p}],paymentOptions:{card:{disable:!1},bank:{disable:!1,enabledProviders:["slb001","slb004","slb007"]},momo:{disable:!1,enabledProviders:["m17","m18"]},wallet:{disable:!1,enabledProviders:["dw001"]}},brandingOptions:{primaryColor:m},metadata:{}};try{return{success:!0,data:(await d.post(P,Se,{headers:{"Monime-Space-Id":E,Authorization:`Bearer ${A}`,"Content-Type":"application/json","Idempotency-Key":Ge,...S?{"Monime-Version":S}:{}}})).data}}catch(O){return d.isAxiosError(O)?{error:O,success:!1}:{error:new Error("unknown error"),success:!1}}}async function V(r){let{accessToken:e,monimeSpaceId:n,monimeVersion:o}=r;try{return{success:!0,data:(await d.get(P,{headers:{"Monime-Space-Id":n,Authorization:`Bearer ${e}`,...o?{"Monime-Version":o}:{}}})).data}}catch(t){return d.isAxiosError(t)?{error:t,success:!1}:{error:new Error("unknown error"),success:!1}}}async function M(r,e){let{accessToken:n,monimeSpaceId:o,monimeVersion:t}=r;try{return{success:!0,data:(await d.get(`${P}/${e}`,{headers:{"Monime-Space-Id":o,Authorization:`Bearer ${n}`,...t?{"Monime-Version":t}:{}}})).data}}catch(s){return d.isAxiosError(s)?{error:s,success:!1}:{error:new Error("unknown error"),success:!1}}}async function F(r,e){let{accessToken:n,monimeSpaceId:o,monimeVersion:t}=r;try{return await d.delete(`${P}/${e}`,{headers:{"Monime-Space-Id":o,Authorization:`Bearer ${n}`,...t?{"Monime-Version":t}:{}}}),{success:!0}}catch(s){return d.isAxiosError(s)?{error:s,success:!1}:{error:new Error("unknown error"),success:!1}}}function D(r){return{create:(e,n,o,t,s,a,u,m,p)=>v(r,e,n,o,t,s,a,u,m,p),get:()=>V(r),getOne:e=>M(r,e),delete:e=>F(r,e)}}import{randomBytes as $e}from"crypto";import h from"axios";var G="https://api.monime.io/v1/financial-accounts",ve=$e(20).toString("hex");async function B(r,e,n){if(r.trim()==="")return{success:!1,error:new Error("accountName is required")};let o={name:r,currency:e,description:"",metadata:{}},{accessToken:t,monimeSpaceId:s,monimeVersion:a}=n;try{return{success:!0,data:(await h.post(G,o,{headers:{"Idempotency-Key":`${ve}`,"Monime-Space-Id":`${s}`,Authorization:`Bearer ${t}`,"Content-Type":"application/json",...a?{"Monime-Version":a}:{}}})).data}}catch(u){return h.isAxiosError(u)?{error:u,success:!1}:{error:new Error("unknown error"),success:!1}}}async function U(r,e){if(r.trim()==="")return{success:!1,error:new Error("financialAccountId is required")};let{monimeSpaceId:n,accessToken:o,monimeVersion:t}=e;try{return{success:!0,data:(await h.get(`${G}/${r}`,{headers:{"Monime-Space-Id":`${n}`,Authorization:`Bearer ${o}`,...t?{"Monime-Version":t}:{}}})).data}}catch(s){return h.isAxiosError(s)?{error:s,success:!1}:{error:new Error("unknown error"),success:!1}}}async function W(r){let{monimeSpaceId:e,accessToken:n,monimeVersion:o}=r;try{return{success:!0,data:(await h.get(G,{headers:{"Monime-Space-Id":`${e}`,Authorization:`Bearer ${n}`}})).data}}catch(t){return h.isAxiosError(t)?{error:t,success:!1}:{error:new Error("unknown error"),success:!1}}}function z(r){return{create:(e,n)=>B(e,n,r),get:e=>U(e,r),getAll:()=>W(r)}}import w from"axios";var K="https://api.monime.io/v1/financial-transactions";async function L(r){let{monimeSpaceId:e,accessToken:n,monimeVersion:o}=r;try{return{success:!0,data:(await w.get(K,{headers:{Authorization:`Bearer ${n}`,"Monime-Space-Id":`${e}`,...o?{"Monime-Version":o}:{}}})).data}}catch(t){return w.isAxiosError(t)?{error:t,success:!1}:{error:new Error("unknown error"),success:!1}}}async function q(r,e){let{accessToken:n,monimeSpaceId:o,monimeVersion:t}=r;if(e.trim()==="")return{error:new Error("transactionId must not be empty"),success:!1};try{return{success:!0,data:(await w.get(`${K}/${e}`,{headers:{Authorization:`Bearer ${n}`,"Monime-Space-Id":`${o}`,...t?{"Monime-Version":t}:{}}})).data}}catch(s){return w.isAxiosError(s)?{error:s,success:!1}:{error:new Error("unknown error"),success:!1}}}function N(r){return{get:e=>q(r,e),getAll:()=>L(r)}}import{randomBytes as Ve}from"crypto";import f from"axios";var T="https://api.monime.io/v1/internal-transfers",Me=Ve(20).toString("hex");async function j(r,e,n,o){if(o<=0)return{success:!1,error:new Error("amount must be larger that zero")};if(r.trim()===""||e.trim()==="")return{success:!1,error:new Error("sourceAccount or destinationAccount is missing")};let t={amount:{currency:"SLE",value:o},sourceFinancialAccount:{id:r},destinationFinancialAccount:{id:e},metadata:{}},{accessToken:s,monimeSpaceId:a,monimeVersion:u}=n;try{return{success:!0,data:(await f.post(T,t,{headers:{"Idempotency-Key":`${Me}`,"Monime-Space-Id":`${a}`,Authorization:`Bearer ${s}`,"Content-Type":"application/json",...u?{"Monime-Version":u}:{}}})).data}}catch(m){return f.isAxiosError(m)?{error:m,success:!1}:{error:new Error("unkknown error"),success:!1}}}async function H(r){let{monimeSpaceId:e,accessToken:n,monimeVersion:o}=r;try{return{success:!0,data:(await f.get(T,{headers:{"Monime-Space-Id":`${e}`,Authorization:`Bearer ${n}`,...o?{"Monime-Version":o}:{}}})).data}}catch(t){return f.isAxiosError(t)?{success:!1,error:t}:{error:new Error("unkknown error"),success:!1}}}async function J(r,e){let{accessToken:n,monimeSpaceId:o,monimeVersion:t}=r;try{return{success:!0,data:(await f.get(`${T}/${e}`,{headers:{"Monime-Space-Id":`${o}`,Authorization:`Bearer ${n}`,...t?{"Monime-Version":t}:{}}})).data}}catch(s){return f.isAxiosError(s)?{success:!1,error:s}:{error:new Error("unkknown error"),success:!1}}}async function Q(r,e){let{monimeSpaceId:n,accessToken:o,monimeVersion:t}=r;try{return await f.delete(`${T}/${e}`,{headers:{"Monime-Space-Id":`${n}`,Authorization:`Bearer ${o}`,...t?{"Monime-Version":t}:{}}}),{success:!0}}catch(s){return f.isAxiosError(s)?{success:!1,error:s}:{success:!1,error:new Error("unknown error")}}}function X(r){return{create:(e,n,o)=>j(e,n,r,o),get:e=>J(r,e),getAll:()=>H(r),delete:e=>Q(r,e)}}import{randomBytes as Fe}from"crypto";import C from"axios";var $="https://api.monime.io/v1/payments";async function Y(r,e){if(!r)return{success:!1,error:new Error("paymentId is required")};let{monimeSpaceId:n,accessToken:o,monimeVersion:t}=e;try{return{success:!0,data:(await C.get(`${$}/${r}`,{headers:{"Monime-Space-Id":n,Authorization:`Bearer ${o}`,...t?{"Monime-Version":t}:{}}})).data}}catch(s){return C.isAxiosError(s)?{success:!1,error:s}:{success:!1,error:new Error("Unknown error")}}}async function Z(r,e){let{monimeSpaceId:n,accessToken:o,monimeVersion:t}=r;try{return{success:!0,data:(await C.get($,{headers:{"Monime-Space-Id":n,Authorization:`Bearer ${o}`,...t?{"Monime-Version":t}:{}},params:e})).data}}catch(s){return C.isAxiosError(s)?{success:!1,error:s}:{success:!1,error:new Error("Unknown error")}}}async function _(r,e,n){if(!r)return{success:!1,error:new Error("paymentId is required")};let{monimeSpaceId:o,accessToken:t,monimeVersion:s}=n,a=Fe(20).toString("hex");try{return{success:!0,data:(await C.patch(`${$}/${r}`,e,{headers:{"Idempotency-Key":a,"Monime-Space-Id":o,Authorization:`Bearer ${t}`,"Content-Type":"application/json",...s?{"Monime-Version":s}:{}}})).data}}catch(u){return C.isAxiosError(u)?{success:!1,error:u}:{success:!1,error:new Error("Unknown error")}}}function ee(r){return{get:e=>Y(e,r),getAll:e=>Z(r,e),patch:(e,n)=>_(e,n,r)}}import{randomBytes as De}from"crypto";import g from"axios";var re=De(20).toString("hex"),I="https://api.monime.io/v1/payment-codes";async function te(r,e,n,o,t,s){let a=null;if(n!==""&&(a=n),r.trim()===""||o.trim()===""||t.trim()==="")return{success:!1,error:new Error("paymentName, name, or phoneNumber is missing")};if(e<=0)return{success:!1,error:new Error("amonut number be greater than zero")};let{accessToken:u,monimeSpaceId:m,monimeVersion:p}=s,E={name:`${r}`,mode:"recurrent",enable:!0,amount:{currency:"SLE",value:e*100},duration:"1h30m",customer:{name:`${o}`},reference:"",authorizedPhoneNumber:t,recurrentPaymentTarget:{expectedPaymentCount:1,expectedPaymentTotal:{currency:"SLE",value:e*100}},financialAccountId:a,metadata:{}};try{return{data:(await g.post(I,E,{headers:{"Idempotency-Key":`${re}`,"Monime-Space-Id":`${m}`,Authorization:`Bearer ${u}`,"Content-Type":"application/json",...p?{"Monime-Version":p}:{}}})).data,success:!0}}catch(A){return g.isAxiosError(A)?{error:A.response?.data,success:!1}:{error:new Error("unknown error"),success:!1}}}async function ne(r,e){let{accessToken:n,monimeSpaceId:o,monimeVersion:t}=e;if(r.trim()==="")return{success:!1,error:new Error("paymentCodeId is required")};try{return await g.delete(`${I}/${r}`,{headers:{"Idempotency-Key":`${re}`,"Monime-Space-Id":`${o}`,Authorization:`Bearer ${n}`,"Content-Type":"application/json",...t?{"Monime-Version":t}:{}}}),{success:!0}}catch(s){return g.isAxiosError(s)?{error:s,success:!1}:{error:new Error("unknown error"),success:!1}}}async function se(r){let{monimeSpaceId:e,accessToken:n,monimeVersion:o}=r;try{return{success:!0,data:(await g.get(I,{headers:{"Monime-Space-Id":`${e}`,Authorization:`Bearer ${n}`,...o?{"Monime-Version":o}:{}}})).data}}catch(t){return g.isAxiosError(t)?{error:t,success:!1}:{error:new Error("unknown error"),success:!1}}}async function oe(r,e){let{monimeSpaceId:n,accessToken:o,monimeVersion:t}=e;try{return{success:!0,data:(await g.get(`${I}/${r}`,{headers:{"Monime-Space-Id":`${n}`,Authorization:`Bearer ${o}`,...t?{"Monime-Version":t}:{}}})).data}}catch(s){return g.isAxiosError(s)?{error:s,success:!1}:{error:new Error("unknown error"),success:!1}}}function ae(r){return{create:(e,n,o,t,s)=>te(e,n,o,t,s,r),delete:e=>ne(e,r),getAll:()=>se(r),get:e=>oe(e,r)}}import{randomBytes as Be}from"crypto";import y from"axios";var R="https://api.monime.io/v1/payouts",Ue=Be(20).toString("hex");async function ie(r,e,n,o){if(e.trim()==="")return{success:!1,error:new Error("sourceAccount cannot be empty")};if(r<=0)return{error:new Error("amount must be greater than 0"),success:!1};let{accessToken:t,monimeSpaceId:s,monimeVersion:a}=o,u={amount:{currency:"SLE",value:r},source:{financialAccountId:e},destination:n,metadata:{}};try{return{success:!0,data:(await y.post(R,u,{headers:{"Idempotency-Key":`${Ue}`,"Monime-Space-Id":`${s}`,Authorization:`Bearer ${t}`,"Content-Type":"application/json",...a?{"Monime-Version":a}:{}}})).data}}catch(m){return y.isAxiosError(m)?{success:!1,error:m}:{success:!1,error:new Error("unknown error")}}}async function ce(r){let{accessToken:e,monimeSpaceId:n,monimeVersion:o}=r;try{return{success:!0,data:(await y.get(R,{headers:{"Monime-Space-Id":`${n}`,Authorization:`Bearer ${e}`,...o?{"Monime-Version":o}:{}}})).data}}catch(t){return y.isAxiosError(t)?{success:!1,error:t}:{success:!1,error:new Error("unknown error")}}}async function ue(r,e){let{accessToken:n,monimeSpaceId:o,monimeVersion:t}=e;try{return{success:!0,data:(await y.get(`${R}/${r}`,{headers:{"Monime-Space-Id":`${o}`,Authorization:`Bearer ${n}`,...t?{"Monime-Version":t}:{}}})).data}}catch(s){return y.isAxiosError(s)?{success:!1,error:s}:{success:!1,error:new Error("unknown error")}}}async function me(r,e){let{accessToken:n,monimeSpaceId:o,monimeVersion:t}=e;try{return await y.delete(`${R}/${r}`,{headers:{"Monime-Space-Id":`${o}`,Authorization:`Bearer ${n}`,...t?{"Monime-Version":t}:{}}}),{success:!0}}catch(s){return y.isAxiosError(s)?{success:!1,error:s}:{success:!1,error:new Error("unknown error")}}}function le(r){return{create:(e,n,o)=>ie(e,o,n,r),get:()=>ce(r),getOne:e=>ue(e,r),delete:e=>me(e,r)}}import pe from"axios";var We="https://api.monime.io/v1/provider-kyc";async function de(r,e){let{monimeSpaceId:n,accessToken:o,monimeVersion:t}=e;try{return{success:!0,data:(await pe.get(`${We}/${r}`,{headers:{"Monime-Space-Id":n,Authorization:`Bearer ${o}`,...t?{"Monime-Version":t}:{}}})).data}}catch(s){return pe.isAxiosError(s)?{success:!1,error:s}:{success:!1,error:new Error("Unknown error")}}}function fe(r){return{get:e=>de(e,r)}}import{randomBytes as ze}from"crypto";import k from"axios";var ge="https://api.monime.io/v1/receipts";async function ye(r,e){let{monimeSpaceId:n,accessToken:o,monimeVersion:t}=e;try{return{success:!0,data:(await k.get(`${ge}/${r}`,{headers:{"Monime-Space-Id":n,Authorization:`Bearer ${o}`,...t?{"Monime-Version":t}:{}}})).data}}catch(s){return k.isAxiosError(s)?{success:!1,error:s}:{success:!1,error:new Error("Unknown error")}}}async function he(r,e,n){let{monimeSpaceId:o,accessToken:t,monimeVersion:s}=n,a=ze(20).toString("hex");try{return{success:!0,data:(await k.post(`${ge}/${r}/redeem`,e,{headers:{"Idempotency-Key":a,"Monime-Space-Id":o,Authorization:`Bearer ${t}`,"Content-Type":"application/json",...s?{"Monime-Version":s}:{}}})).data}}catch(u){return k.isAxiosError(u)?{success:!1,error:u}:{success:!1,error:new Error("Unknown error")}}}function Ce(r){return{get:e=>ye(e,r),redeem:(e,n={})=>he(e,n,r)}}import{randomBytes as Ke}from"crypto";import Ae from"axios";var Le="https://api.monime.io/v1/ussd-otps";async function be(r,e){let{monimeSpaceId:n,accessToken:o,monimeVersion:t}=e,s=Ke(20).toString("hex");try{return{success:!0,data:(await Ae.post(Le,r,{headers:{"Idempotency-Key":s,"Monime-Space-Id":n,Authorization:`Bearer ${o}`,"Content-Type":"application/json",...t?{"Monime-Version":t}:{}}})).data}}catch(a){return Ae.isAxiosError(a)?{success:!1,error:a}:{success:!1,error:new Error("Unknown error")}}}function Pe(r){return{create:e=>be(e,r)}}import{randomBytes as we}from"crypto";import l from"axios";var b="https://api.monime.io/v1/webhooks";async function Te(r,e){let{monimeSpaceId:n,accessToken:o,monimeVersion:t}=e,s=we(20).toString("hex");try{return{success:!0,data:(await l.post(b,r,{headers:{"Idempotency-Key":s,"Monime-Space-Id":n,Authorization:`Bearer ${o}`,"Content-Type":"application/json",...t?{"Monime-Version":t}:{}}})).data}}catch(a){return l.isAxiosError(a)?{success:!1,error:a}:{success:!1,error:new Error("Unknown error")}}}async function Ie(r,e){let{monimeSpaceId:n,accessToken:o,monimeVersion:t}=e;try{return{success:!0,data:(await l.get(`${b}/${r}`,{headers:{"Monime-Space-Id":n,Authorization:`Bearer ${o}`,...t?{"Monime-Version":t}:{}}})).data}}catch(s){return l.isAxiosError(s)?{success:!1,error:s}:{success:!1,error:new Error("Unknown error")}}}async function Re(r){let{monimeSpaceId:e,accessToken:n,monimeVersion:o}=r;try{return{success:!0,data:(await l.get(b,{headers:{"Monime-Space-Id":e,Authorization:`Bearer ${n}`,...o?{"Monime-Version":o}:{}}})).data}}catch(t){return l.isAxiosError(t)?{success:!1,error:t}:{success:!1,error:new Error("Unknown error")}}}async function ke(r,e,n){let{monimeSpaceId:o,accessToken:t,monimeVersion:s}=n,a=we(20).toString("hex");try{return{success:!0,data:(await l.patch(`${b}/${r}`,e,{headers:{"Idempotency-Key":a,"Monime-Space-Id":o,Authorization:`Bearer ${t}`,"Content-Type":"application/json",...s?{"Monime-Version":s}:{}}})).data}}catch(u){return l.isAxiosError(u)?{success:!1,error:u}:{success:!1,error:new Error("Unknown error")}}}async function xe(r,e){let{monimeSpaceId:n,accessToken:o,monimeVersion:t}=e;try{return await l.delete(`${b}/${r}`,{headers:{"Monime-Space-Id":n,Authorization:`Bearer ${o}`,...t?{"Monime-Version":t}:{}}}),{success:!0}}catch(s){return l.isAxiosError(s)?{success:!1,error:s}:{success:!1,error:new Error("Unknown error")}}}function Ee(r){return{create:e=>Te(e,r),get:e=>Ie(e,r),getAll:()=>Re(r),update:(e,n)=>ke(e,n,r),delete:e=>xe(e,r)}}var x=class{monimeSpaceId;accessToken;monimeVersion;financialAccount;internalTransfer;paymentCode;payment;payout;providerKyc;receipt;ussdOtp;webhook;financialTransaction;checkoutSession;constructor(e){this.accessToken=e.accessToken,this.monimeSpaceId=e.monimeSpaceId,this.monimeVersion=e.monimeVersion;let n={monimeSpaceId:this.monimeSpaceId,accessToken:this.accessToken,monimeVersion:this.monimeVersion};this.financialAccount=z(n),this.internalTransfer=X(n),this.paymentCode=ae(n),this.payment=ee(n),this.payout=le(n),this.providerKyc=fe(n),this.receipt=Ce(n),this.ussdOtp=Pe(n),this.webhook=Ee(n),this.financialTransaction=N(n),this.checkoutSession=D(n)}};function Nt(r){return new x(r)}export{x as MonimeClient,Nt as createClient};
|