@monigo/sdk 0.1.7 → 0.1.8
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.d.ts +235 -0
- package/dist/monigo.cjs +144 -0
- package/dist/monigo.cjs.map +1 -1
- package/dist/monigo.js +145 -1
- package/dist/monigo.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -109,6 +109,28 @@ export declare interface CreateSubscriptionRequest {
|
|
|
109
109
|
plan_id: string;
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
+
/** Request body for `wallets.createVirtualAccount()`. */
|
|
113
|
+
export declare interface CreateVirtualAccountRequest {
|
|
114
|
+
/** Use `VirtualAccountProvider` constants. */
|
|
115
|
+
provider: VirtualAccountProviderValue;
|
|
116
|
+
currency: string;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Request body for `wallets.credit()`. */
|
|
120
|
+
export declare interface CreditWalletRequest {
|
|
121
|
+
/** Amount as a decimal string, e.g. `"100.50"`. */
|
|
122
|
+
amount: string;
|
|
123
|
+
currency: string;
|
|
124
|
+
description: string;
|
|
125
|
+
/** Use `WalletEntryType` constants. */
|
|
126
|
+
entry_type: WalletEntryTypeValue;
|
|
127
|
+
reference_type: string;
|
|
128
|
+
reference_id: string;
|
|
129
|
+
idempotency_key: string;
|
|
130
|
+
/** Optional provider account UUID for the other side of double entry. */
|
|
131
|
+
provider_id?: string;
|
|
132
|
+
}
|
|
133
|
+
|
|
112
134
|
/** An end-customer record in your Monigo organisation. */
|
|
113
135
|
export declare interface Customer {
|
|
114
136
|
id: string;
|
|
@@ -179,6 +201,33 @@ export declare class CustomersResource {
|
|
|
179
201
|
delete(customerId: string): Promise<void>;
|
|
180
202
|
}
|
|
181
203
|
|
|
204
|
+
/** A prepaid balance belonging to a single customer. All monetary values are decimal strings. */
|
|
205
|
+
export declare interface CustomerWallet {
|
|
206
|
+
id: string;
|
|
207
|
+
customer_id: string;
|
|
208
|
+
org_id: string;
|
|
209
|
+
currency: string;
|
|
210
|
+
/** Current available balance as a decimal string, e.g. `"500.000000"`. */
|
|
211
|
+
balance: string;
|
|
212
|
+
/** Balance reserved for pending operations. */
|
|
213
|
+
reserved_balance: string;
|
|
214
|
+
created_at: string;
|
|
215
|
+
updated_at: string;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** Request body for `wallets.debit()`. */
|
|
219
|
+
export declare interface DebitWalletRequest {
|
|
220
|
+
/** Amount as a decimal string, e.g. `"50.25"`. */
|
|
221
|
+
amount: string;
|
|
222
|
+
currency: string;
|
|
223
|
+
description: string;
|
|
224
|
+
/** Use `WalletEntryType` constants. */
|
|
225
|
+
entry_type: WalletEntryTypeValue;
|
|
226
|
+
reference_type: string;
|
|
227
|
+
reference_id: string;
|
|
228
|
+
idempotency_key: string;
|
|
229
|
+
}
|
|
230
|
+
|
|
182
231
|
/** Tracks the progress of an asynchronous event replay job. */
|
|
183
232
|
export declare interface EventReplayJob {
|
|
184
233
|
id: string;
|
|
@@ -263,6 +312,13 @@ export declare class EventsResource {
|
|
|
263
312
|
getReplay(jobId: string): Promise<EventReplayJob>;
|
|
264
313
|
}
|
|
265
314
|
|
|
315
|
+
/** Request body for `wallets.getOrCreate()`. */
|
|
316
|
+
export declare interface GetOrCreateWalletRequest {
|
|
317
|
+
org_id: string;
|
|
318
|
+
customer_id: string;
|
|
319
|
+
currency: string;
|
|
320
|
+
}
|
|
321
|
+
|
|
266
322
|
/** A single usage event sent to the Monigo ingestion pipeline. */
|
|
267
323
|
export declare interface IngestEvent {
|
|
268
324
|
/**
|
|
@@ -406,6 +462,32 @@ export declare const InvoiceStatus: {
|
|
|
406
462
|
|
|
407
463
|
export declare type InvoiceStatusValue = (typeof InvoiceStatus)[keyof typeof InvoiceStatus];
|
|
408
464
|
|
|
465
|
+
/** One side of a double-entry accounting record. */
|
|
466
|
+
export declare interface LedgerEntry {
|
|
467
|
+
id: string;
|
|
468
|
+
org_id: string;
|
|
469
|
+
transaction_id: string;
|
|
470
|
+
wallet_id: string | null;
|
|
471
|
+
/** `customer_wallet`, `provider`, or `revenue`. */
|
|
472
|
+
account_type: string;
|
|
473
|
+
account_id: string;
|
|
474
|
+
/** Use `WalletDirection` constants. */
|
|
475
|
+
direction: WalletDirectionValue;
|
|
476
|
+
/** Amount as a decimal string. */
|
|
477
|
+
amount: string;
|
|
478
|
+
currency: string;
|
|
479
|
+
balance_before: string;
|
|
480
|
+
balance_after: string;
|
|
481
|
+
description: string;
|
|
482
|
+
/** Use `WalletEntryType` constants. */
|
|
483
|
+
entry_type: WalletEntryTypeValue;
|
|
484
|
+
reference_type: string;
|
|
485
|
+
reference_id: string;
|
|
486
|
+
idempotency_key: string;
|
|
487
|
+
metadata: Record<string, unknown> | null;
|
|
488
|
+
created_at: string;
|
|
489
|
+
}
|
|
490
|
+
|
|
409
491
|
export declare interface ListCustomersResponse {
|
|
410
492
|
customers: Customer[];
|
|
411
493
|
count: number;
|
|
@@ -457,6 +539,34 @@ export declare interface ListSubscriptionsResponse {
|
|
|
457
539
|
count: number;
|
|
458
540
|
}
|
|
459
541
|
|
|
542
|
+
export declare interface ListTransactionsParams {
|
|
543
|
+
/** Number of entries to return (1–100). Defaults to 25. */
|
|
544
|
+
limit?: number;
|
|
545
|
+
/** Number of entries to skip. Defaults to 0. */
|
|
546
|
+
offset?: number;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
export declare interface ListTransactionsResponse {
|
|
550
|
+
transactions: LedgerEntry[];
|
|
551
|
+
total: number;
|
|
552
|
+
limit: number;
|
|
553
|
+
offset: number;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
export declare interface ListVirtualAccountsResponse {
|
|
557
|
+
virtual_accounts: VirtualAccount[];
|
|
558
|
+
count: number;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
export declare interface ListWalletsParams {
|
|
562
|
+
org_id: string;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
export declare interface ListWalletsResponse {
|
|
566
|
+
wallets: CustomerWallet[];
|
|
567
|
+
count: number;
|
|
568
|
+
}
|
|
569
|
+
|
|
460
570
|
/** Defines what usage is counted and how. */
|
|
461
571
|
export declare interface Metric {
|
|
462
572
|
id: string;
|
|
@@ -599,6 +709,8 @@ export declare class MonigoClient {
|
|
|
599
709
|
readonly usage: UsageResource;
|
|
600
710
|
/** Manage customer portal access links. Requires `read` / `write` scope. */
|
|
601
711
|
readonly portalTokens: PortalTokensResource;
|
|
712
|
+
/** Manage customer wallets, balance operations, and virtual accounts. Requires `read` / `write` scope. */
|
|
713
|
+
readonly wallets: WalletsResource;
|
|
602
714
|
constructor(options: MonigoClientOptions);
|
|
603
715
|
/* Excluded from this release type: _request */
|
|
604
716
|
/** Normalise a `Date | string` value to an ISO 8601 string. */
|
|
@@ -1142,4 +1254,127 @@ export declare interface UsageRollup {
|
|
|
1142
1254
|
updated_at: string;
|
|
1143
1255
|
}
|
|
1144
1256
|
|
|
1257
|
+
/** A dedicated virtual bank account that funds a customer wallet. */
|
|
1258
|
+
export declare interface VirtualAccount {
|
|
1259
|
+
id: string;
|
|
1260
|
+
customer_id: string;
|
|
1261
|
+
wallet_id: string;
|
|
1262
|
+
org_id: string;
|
|
1263
|
+
/** Payment provider. Use `VirtualAccountProvider` constants. */
|
|
1264
|
+
provider: VirtualAccountProviderValue;
|
|
1265
|
+
account_number: string;
|
|
1266
|
+
account_name: string;
|
|
1267
|
+
bank_name: string;
|
|
1268
|
+
bank_code: string;
|
|
1269
|
+
currency: string;
|
|
1270
|
+
provider_ref: string;
|
|
1271
|
+
is_active: boolean;
|
|
1272
|
+
metadata: Record<string, unknown> | null;
|
|
1273
|
+
created_at: string;
|
|
1274
|
+
updated_at: string;
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
export declare const VirtualAccountProvider: {
|
|
1278
|
+
readonly Paystack: "paystack";
|
|
1279
|
+
readonly Flutterwave: "flutterwave";
|
|
1280
|
+
readonly Monnify: "monnify";
|
|
1281
|
+
};
|
|
1282
|
+
|
|
1283
|
+
export declare type VirtualAccountProviderValue = (typeof VirtualAccountProvider)[keyof typeof VirtualAccountProvider];
|
|
1284
|
+
|
|
1285
|
+
export declare const WalletDirection: {
|
|
1286
|
+
/** Reduces the wallet balance. */
|
|
1287
|
+
readonly Debit: "debit";
|
|
1288
|
+
/** Increases the wallet balance. */
|
|
1289
|
+
readonly Credit: "credit";
|
|
1290
|
+
};
|
|
1291
|
+
|
|
1292
|
+
export declare type WalletDirectionValue = (typeof WalletDirection)[keyof typeof WalletDirection];
|
|
1293
|
+
|
|
1294
|
+
export declare const WalletEntryType: {
|
|
1295
|
+
/** Credit from an external funding source. */
|
|
1296
|
+
readonly Deposit: "deposit";
|
|
1297
|
+
/** Debit to an external destination. */
|
|
1298
|
+
readonly Withdrawal: "withdrawal";
|
|
1299
|
+
/** Automatic debit for metered usage charges. */
|
|
1300
|
+
readonly Usage: "usage";
|
|
1301
|
+
/** Credit reversing a previous charge. */
|
|
1302
|
+
readonly Refund: "refund";
|
|
1303
|
+
/** Manual balance correction. */
|
|
1304
|
+
readonly Adjustment: "adjustment";
|
|
1305
|
+
};
|
|
1306
|
+
|
|
1307
|
+
export declare type WalletEntryTypeValue = (typeof WalletEntryType)[keyof typeof WalletEntryType];
|
|
1308
|
+
|
|
1309
|
+
export declare interface WalletOperationResponse {
|
|
1310
|
+
wallet: CustomerWallet;
|
|
1311
|
+
ledger_entries: LedgerEntry[];
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
/** Manage customer wallets, balance operations, and virtual accounts. */
|
|
1315
|
+
export declare class WalletsResource {
|
|
1316
|
+
private readonly client;
|
|
1317
|
+
constructor(client: MonigoClient);
|
|
1318
|
+
/**
|
|
1319
|
+
* Get an existing wallet or create a new one for the given customer and currency.
|
|
1320
|
+
*
|
|
1321
|
+
* **Requires `write` scope.**
|
|
1322
|
+
*/
|
|
1323
|
+
getOrCreate(request: GetOrCreateWalletRequest, options?: MutationOptions): Promise<CustomerWallet>;
|
|
1324
|
+
/**
|
|
1325
|
+
* List all wallets for an organisation.
|
|
1326
|
+
*
|
|
1327
|
+
* **Requires `read` scope.**
|
|
1328
|
+
*/
|
|
1329
|
+
list(params: ListWalletsParams): Promise<ListWalletsResponse>;
|
|
1330
|
+
/**
|
|
1331
|
+
* List all wallets belonging to a specific customer.
|
|
1332
|
+
*
|
|
1333
|
+
* **Requires `read` scope.**
|
|
1334
|
+
*/
|
|
1335
|
+
listByCustomer(customerId: string): Promise<ListWalletsResponse>;
|
|
1336
|
+
/**
|
|
1337
|
+
* Fetch a single wallet by UUID, including its virtual accounts.
|
|
1338
|
+
*
|
|
1339
|
+
* **Requires `read` scope.**
|
|
1340
|
+
*/
|
|
1341
|
+
get(walletId: string): Promise<WalletWithVirtualAccountsResponse>;
|
|
1342
|
+
/**
|
|
1343
|
+
* Credit (add funds to) a wallet. Returns the updated wallet and ledger entries.
|
|
1344
|
+
*
|
|
1345
|
+
* **Requires `write` scope.**
|
|
1346
|
+
*/
|
|
1347
|
+
credit(walletId: string, request: CreditWalletRequest, options?: MutationOptions): Promise<WalletOperationResponse>;
|
|
1348
|
+
/**
|
|
1349
|
+
* Debit (remove funds from) a wallet. Returns the updated wallet and ledger entries.
|
|
1350
|
+
* Throws a 402 error if the wallet has insufficient balance.
|
|
1351
|
+
*
|
|
1352
|
+
* **Requires `write` scope.**
|
|
1353
|
+
*/
|
|
1354
|
+
debit(walletId: string, request: DebitWalletRequest, options?: MutationOptions): Promise<WalletOperationResponse>;
|
|
1355
|
+
/**
|
|
1356
|
+
* List paginated ledger entries (transactions) for a wallet.
|
|
1357
|
+
*
|
|
1358
|
+
* **Requires `read` scope.**
|
|
1359
|
+
*/
|
|
1360
|
+
listTransactions(walletId: string, params?: ListTransactionsParams): Promise<ListTransactionsResponse>;
|
|
1361
|
+
/**
|
|
1362
|
+
* Create a dedicated virtual bank account that automatically funds the wallet on deposit.
|
|
1363
|
+
*
|
|
1364
|
+
* **Requires `write` scope.**
|
|
1365
|
+
*/
|
|
1366
|
+
createVirtualAccount(walletId: string, request: CreateVirtualAccountRequest, options?: MutationOptions): Promise<VirtualAccount>;
|
|
1367
|
+
/**
|
|
1368
|
+
* List all virtual accounts linked to a wallet.
|
|
1369
|
+
*
|
|
1370
|
+
* **Requires `read` scope.**
|
|
1371
|
+
*/
|
|
1372
|
+
listVirtualAccounts(walletId: string): Promise<ListVirtualAccountsResponse>;
|
|
1373
|
+
}
|
|
1374
|
+
|
|
1375
|
+
export declare interface WalletWithVirtualAccountsResponse {
|
|
1376
|
+
wallet: CustomerWallet;
|
|
1377
|
+
virtual_accounts: VirtualAccount[];
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1145
1380
|
export { }
|
package/dist/monigo.cjs
CHANGED
|
@@ -724,6 +724,122 @@ class PortalTokensResource {
|
|
|
724
724
|
);
|
|
725
725
|
}
|
|
726
726
|
}
|
|
727
|
+
class WalletsResource {
|
|
728
|
+
constructor(client) {
|
|
729
|
+
this.client = client;
|
|
730
|
+
}
|
|
731
|
+
/**
|
|
732
|
+
* Get an existing wallet or create a new one for the given customer and currency.
|
|
733
|
+
*
|
|
734
|
+
* **Requires `write` scope.**
|
|
735
|
+
*/
|
|
736
|
+
async getOrCreate(request, options) {
|
|
737
|
+
const wrapper = await this.client._request(
|
|
738
|
+
"POST",
|
|
739
|
+
"/v1/wallets",
|
|
740
|
+
{ body: request, idempotencyKey: options?.idempotencyKey }
|
|
741
|
+
);
|
|
742
|
+
return wrapper.wallet;
|
|
743
|
+
}
|
|
744
|
+
/**
|
|
745
|
+
* List all wallets for an organisation.
|
|
746
|
+
*
|
|
747
|
+
* **Requires `read` scope.**
|
|
748
|
+
*/
|
|
749
|
+
async list(params) {
|
|
750
|
+
return this.client._request("GET", "/v1/wallets", {
|
|
751
|
+
query: { org_id: params.org_id }
|
|
752
|
+
});
|
|
753
|
+
}
|
|
754
|
+
/**
|
|
755
|
+
* List all wallets belonging to a specific customer.
|
|
756
|
+
*
|
|
757
|
+
* **Requires `read` scope.**
|
|
758
|
+
*/
|
|
759
|
+
async listByCustomer(customerId) {
|
|
760
|
+
return this.client._request(
|
|
761
|
+
"GET",
|
|
762
|
+
`/v1/customers/${customerId}/wallets`
|
|
763
|
+
);
|
|
764
|
+
}
|
|
765
|
+
/**
|
|
766
|
+
* Fetch a single wallet by UUID, including its virtual accounts.
|
|
767
|
+
*
|
|
768
|
+
* **Requires `read` scope.**
|
|
769
|
+
*/
|
|
770
|
+
async get(walletId) {
|
|
771
|
+
return this.client._request(
|
|
772
|
+
"GET",
|
|
773
|
+
`/v1/wallets/${walletId}`
|
|
774
|
+
);
|
|
775
|
+
}
|
|
776
|
+
/**
|
|
777
|
+
* Credit (add funds to) a wallet. Returns the updated wallet and ledger entries.
|
|
778
|
+
*
|
|
779
|
+
* **Requires `write` scope.**
|
|
780
|
+
*/
|
|
781
|
+
async credit(walletId, request, options) {
|
|
782
|
+
return this.client._request(
|
|
783
|
+
"POST",
|
|
784
|
+
`/v1/wallets/${walletId}/credit`,
|
|
785
|
+
{ body: request, idempotencyKey: options?.idempotencyKey }
|
|
786
|
+
);
|
|
787
|
+
}
|
|
788
|
+
/**
|
|
789
|
+
* Debit (remove funds from) a wallet. Returns the updated wallet and ledger entries.
|
|
790
|
+
* Throws a 402 error if the wallet has insufficient balance.
|
|
791
|
+
*
|
|
792
|
+
* **Requires `write` scope.**
|
|
793
|
+
*/
|
|
794
|
+
async debit(walletId, request, options) {
|
|
795
|
+
return this.client._request(
|
|
796
|
+
"POST",
|
|
797
|
+
`/v1/wallets/${walletId}/debit`,
|
|
798
|
+
{ body: request, idempotencyKey: options?.idempotencyKey }
|
|
799
|
+
);
|
|
800
|
+
}
|
|
801
|
+
/**
|
|
802
|
+
* List paginated ledger entries (transactions) for a wallet.
|
|
803
|
+
*
|
|
804
|
+
* **Requires `read` scope.**
|
|
805
|
+
*/
|
|
806
|
+
async listTransactions(walletId, params) {
|
|
807
|
+
return this.client._request(
|
|
808
|
+
"GET",
|
|
809
|
+
`/v1/wallets/${walletId}/transactions`,
|
|
810
|
+
{
|
|
811
|
+
query: {
|
|
812
|
+
limit: params?.limit?.toString(),
|
|
813
|
+
offset: params?.offset?.toString()
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
);
|
|
817
|
+
}
|
|
818
|
+
/**
|
|
819
|
+
* Create a dedicated virtual bank account that automatically funds the wallet on deposit.
|
|
820
|
+
*
|
|
821
|
+
* **Requires `write` scope.**
|
|
822
|
+
*/
|
|
823
|
+
async createVirtualAccount(walletId, request, options) {
|
|
824
|
+
const wrapper = await this.client._request(
|
|
825
|
+
"POST",
|
|
826
|
+
`/v1/wallets/${walletId}/virtual-accounts`,
|
|
827
|
+
{ body: request, idempotencyKey: options?.idempotencyKey }
|
|
828
|
+
);
|
|
829
|
+
return wrapper.virtual_account;
|
|
830
|
+
}
|
|
831
|
+
/**
|
|
832
|
+
* List all virtual accounts linked to a wallet.
|
|
833
|
+
*
|
|
834
|
+
* **Requires `read` scope.**
|
|
835
|
+
*/
|
|
836
|
+
async listVirtualAccounts(walletId) {
|
|
837
|
+
return this.client._request(
|
|
838
|
+
"GET",
|
|
839
|
+
`/v1/wallets/${walletId}/virtual-accounts`
|
|
840
|
+
);
|
|
841
|
+
}
|
|
842
|
+
}
|
|
727
843
|
const DEFAULT_BASE_URL = "https://api.monigo.co";
|
|
728
844
|
const DEFAULT_TIMEOUT_MS = 3e4;
|
|
729
845
|
class MonigoClient {
|
|
@@ -750,6 +866,7 @@ class MonigoClient {
|
|
|
750
866
|
this.invoices = new InvoicesResource(this);
|
|
751
867
|
this.usage = new UsageResource(this);
|
|
752
868
|
this.portalTokens = new PortalTokensResource(this);
|
|
869
|
+
this.wallets = new WalletsResource(this);
|
|
753
870
|
}
|
|
754
871
|
/**
|
|
755
872
|
* Execute an authenticated HTTP request against the Monigo API.
|
|
@@ -863,6 +980,29 @@ const PayoutMethod = {
|
|
|
863
980
|
BankTransfer: "bank_transfer",
|
|
864
981
|
MobileMoney: "mobile_money"
|
|
865
982
|
};
|
|
983
|
+
const WalletEntryType = {
|
|
984
|
+
/** Credit from an external funding source. */
|
|
985
|
+
Deposit: "deposit",
|
|
986
|
+
/** Debit to an external destination. */
|
|
987
|
+
Withdrawal: "withdrawal",
|
|
988
|
+
/** Automatic debit for metered usage charges. */
|
|
989
|
+
Usage: "usage",
|
|
990
|
+
/** Credit reversing a previous charge. */
|
|
991
|
+
Refund: "refund",
|
|
992
|
+
/** Manual balance correction. */
|
|
993
|
+
Adjustment: "adjustment"
|
|
994
|
+
};
|
|
995
|
+
const WalletDirection = {
|
|
996
|
+
/** Reduces the wallet balance. */
|
|
997
|
+
Debit: "debit",
|
|
998
|
+
/** Increases the wallet balance. */
|
|
999
|
+
Credit: "credit"
|
|
1000
|
+
};
|
|
1001
|
+
const VirtualAccountProvider = {
|
|
1002
|
+
Paystack: "paystack",
|
|
1003
|
+
Flutterwave: "flutterwave",
|
|
1004
|
+
Monnify: "monnify"
|
|
1005
|
+
};
|
|
866
1006
|
exports.Aggregation = Aggregation;
|
|
867
1007
|
exports.BillingPeriod = BillingPeriod;
|
|
868
1008
|
exports.CustomersResource = CustomersResource;
|
|
@@ -881,4 +1021,8 @@ exports.PricingModel = PricingModel;
|
|
|
881
1021
|
exports.SubscriptionStatus = SubscriptionStatus;
|
|
882
1022
|
exports.SubscriptionsResource = SubscriptionsResource;
|
|
883
1023
|
exports.UsageResource = UsageResource;
|
|
1024
|
+
exports.VirtualAccountProvider = VirtualAccountProvider;
|
|
1025
|
+
exports.WalletDirection = WalletDirection;
|
|
1026
|
+
exports.WalletEntryType = WalletEntryType;
|
|
1027
|
+
exports.WalletsResource = WalletsResource;
|
|
884
1028
|
//# sourceMappingURL=monigo.cjs.map
|