@nomba/node-sdk 0.0.0-stage → 0.3.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/LICENSE +21 -0
- package/README.md +577 -2
- package/dist/index.d.ts +86 -0
- package/dist/index.js +53 -0
- package/dist/interfaces/http/IHttpClient.d.ts +17 -0
- package/dist/interfaces/http/IHttpClient.js +5 -0
- package/dist/interfaces/http/index.d.ts +1 -0
- package/dist/interfaces/http/index.js +1 -0
- package/dist/interfaces/v1/accounts/IAccountsService.d.ts +62 -0
- package/dist/interfaces/v1/accounts/IAccountsService.js +5 -0
- package/dist/interfaces/v1/accounts/index.d.ts +1 -0
- package/dist/interfaces/v1/accounts/index.js +1 -0
- package/dist/interfaces/v1/betting/IBettingService.d.ts +20 -0
- package/dist/interfaces/v1/betting/IBettingService.js +5 -0
- package/dist/interfaces/v1/betting/index.d.ts +1 -0
- package/dist/interfaces/v1/betting/index.js +1 -0
- package/dist/interfaces/v1/cable/ICableService.d.ts +21 -0
- package/dist/interfaces/v1/cable/ICableService.js +5 -0
- package/dist/interfaces/v1/cable/index.d.ts +1 -0
- package/dist/interfaces/v1/cable/index.js +1 -0
- package/dist/interfaces/v1/charge/IChargeService.d.ts +94 -0
- package/dist/interfaces/v1/charge/IChargeService.js +5 -0
- package/dist/interfaces/v1/charge/index.d.ts +1 -0
- package/dist/interfaces/v1/charge/index.js +1 -0
- package/dist/interfaces/v1/checkout/ICheckoutService.d.ts +79 -0
- package/dist/interfaces/v1/checkout/ICheckoutService.js +5 -0
- package/dist/interfaces/v1/checkout/index.d.ts +1 -0
- package/dist/interfaces/v1/checkout/index.js +1 -0
- package/dist/interfaces/v1/data/IDataService.d.ts +14 -0
- package/dist/interfaces/v1/data/IDataService.js +5 -0
- package/dist/interfaces/v1/data/index.d.ts +1 -0
- package/dist/interfaces/v1/data/index.js +1 -0
- package/dist/interfaces/v1/direct-debits/IDirectDebitsService.d.ts +54 -0
- package/dist/interfaces/v1/direct-debits/IDirectDebitsService.js +5 -0
- package/dist/interfaces/v1/direct-debits/index.d.ts +1 -0
- package/dist/interfaces/v1/direct-debits/index.js +1 -0
- package/dist/interfaces/v1/electricity/IElectricityService.d.ts +20 -0
- package/dist/interfaces/v1/electricity/IElectricityService.js +5 -0
- package/dist/interfaces/v1/electricity/index.d.ts +1 -0
- package/dist/interfaces/v1/electricity/index.js +1 -0
- package/dist/interfaces/v1/globals/collections/IGlobalCollectionsService.d.ts +29 -0
- package/dist/interfaces/v1/globals/collections/IGlobalCollectionsService.js +5 -0
- package/dist/interfaces/v1/globals/collections/index.d.ts +1 -0
- package/dist/interfaces/v1/globals/collections/index.js +1 -0
- package/dist/interfaces/v1/globals/payouts/IGlobalPayoutService.d.ts +91 -0
- package/dist/interfaces/v1/globals/payouts/IGlobalPayoutService.js +5 -0
- package/dist/interfaces/v1/globals/payouts/index.d.ts +1 -0
- package/dist/interfaces/v1/globals/payouts/index.js +1 -0
- package/dist/interfaces/v1/requery/IRequeryService.d.ts +31 -0
- package/dist/interfaces/v1/requery/IRequeryService.js +5 -0
- package/dist/interfaces/v1/requery/index.d.ts +1 -0
- package/dist/interfaces/v1/requery/index.js +1 -0
- package/dist/interfaces/v1/terminals/ITerminalsService.d.ts +51 -0
- package/dist/interfaces/v1/terminals/ITerminalsService.js +5 -0
- package/dist/interfaces/v1/terminals/index.d.ts +1 -0
- package/dist/interfaces/v1/terminals/index.js +1 -0
- package/dist/interfaces/v1/transactions/ITransactionsService.d.ts +93 -0
- package/dist/interfaces/v1/transactions/ITransactionsService.js +5 -0
- package/dist/interfaces/v1/transactions/index.d.ts +1 -0
- package/dist/interfaces/v1/transactions/index.js +1 -0
- package/dist/interfaces/v1/virtual-accounts/IVirtualAccountsService.d.ts +65 -0
- package/dist/interfaces/v1/virtual-accounts/IVirtualAccountsService.js +5 -0
- package/dist/interfaces/v1/virtual-accounts/index.d.ts +1 -0
- package/dist/interfaces/v1/virtual-accounts/index.js +1 -0
- package/dist/interfaces/v1/webhooks/IWebhooksService.d.ts +40 -0
- package/dist/interfaces/v1/webhooks/IWebhooksService.js +5 -0
- package/dist/interfaces/v1/webhooks/index.d.ts +1 -0
- package/dist/interfaces/v1/webhooks/index.js +1 -0
- package/dist/interfaces/v2/airtime/IAirtimeV2Service.d.ts +31 -0
- package/dist/interfaces/v2/airtime/IAirtimeV2Service.js +5 -0
- package/dist/interfaces/v2/airtime/index.d.ts +1 -0
- package/dist/interfaces/v2/airtime/index.js +1 -0
- package/dist/interfaces/v2/betting/IBettingV2Service.d.ts +31 -0
- package/dist/interfaces/v2/betting/IBettingV2Service.js +5 -0
- package/dist/interfaces/v2/betting/index.d.ts +1 -0
- package/dist/interfaces/v2/betting/index.js +1 -0
- package/dist/interfaces/v2/cable/ICableV2Service.d.ts +31 -0
- package/dist/interfaces/v2/cable/ICableV2Service.js +5 -0
- package/dist/interfaces/v2/cable/index.d.ts +1 -0
- package/dist/interfaces/v2/cable/index.js +1 -0
- package/dist/interfaces/v2/data/IDataV2Service.d.ts +31 -0
- package/dist/interfaces/v2/data/IDataV2Service.js +5 -0
- package/dist/interfaces/v2/data/index.d.ts +1 -0
- package/dist/interfaces/v2/data/index.js +1 -0
- package/dist/interfaces/v2/electricity/IElectricityV2Service.d.ts +32 -0
- package/dist/interfaces/v2/electricity/IElectricityV2Service.js +5 -0
- package/dist/interfaces/v2/electricity/index.d.ts +1 -0
- package/dist/interfaces/v2/electricity/index.js +1 -0
- package/dist/interfaces/v2/transfers/ITransfersService.d.ts +71 -0
- package/dist/interfaces/v2/transfers/ITransfersService.js +5 -0
- package/dist/interfaces/v2/transfers/index.d.ts +1 -0
- package/dist/interfaces/v2/transfers/index.js +1 -0
- package/dist/lib/errors.d.ts +62 -0
- package/dist/lib/errors.js +92 -0
- package/dist/lib/outcome.d.ts +37 -0
- package/dist/lib/outcome.js +126 -0
- package/dist/lib/paginate.d.ts +21 -0
- package/dist/lib/paginate.js +25 -0
- package/dist/lib/sdk-version.d.ts +5 -0
- package/dist/lib/sdk-version.generated.d.ts +1 -0
- package/dist/lib/sdk-version.generated.js +1 -0
- package/dist/lib/sdk-version.js +5 -0
- package/dist/lib/token-store.d.ts +49 -0
- package/dist/lib/token-store.js +26 -0
- package/dist/lib/util.d.ts +31 -0
- package/dist/lib/util.js +31 -0
- package/dist/lib/webhooks.d.ts +43 -0
- package/dist/lib/webhooks.js +64 -0
- package/dist/nomba.d.ts +96 -0
- package/dist/nomba.js +130 -0
- package/dist/services/http/http-client.service.d.ts +61 -0
- package/dist/services/http/http-client.service.js +351 -0
- package/dist/services/v1/accounts/accounts.service.d.ts +76 -0
- package/dist/services/v1/accounts/accounts.service.js +96 -0
- package/dist/services/v1/betting/betting.service.d.ts +25 -0
- package/dist/services/v1/betting/betting.service.js +30 -0
- package/dist/services/v1/cable/cable.service.d.ts +26 -0
- package/dist/services/v1/cable/cable.service.js +33 -0
- package/dist/services/v1/charge/charge.service.d.ts +113 -0
- package/dist/services/v1/charge/charge.service.js +161 -0
- package/dist/services/v1/checkout/checkout.service.d.ts +92 -0
- package/dist/services/v1/checkout/checkout.service.js +146 -0
- package/dist/services/v1/data/data.service.d.ts +20 -0
- package/dist/services/v1/data/data.service.js +22 -0
- package/dist/services/v1/direct-debits/direct-debits.service.d.ts +69 -0
- package/dist/services/v1/direct-debits/direct-debits.service.js +91 -0
- package/dist/services/v1/electricity/electricity.service.d.ts +26 -0
- package/dist/services/v1/electricity/electricity.service.js +31 -0
- package/dist/services/v1/globals/collections.service.d.ts +44 -0
- package/dist/services/v1/globals/collections.service.js +55 -0
- package/dist/services/v1/globals/payout.service.d.ts +105 -0
- package/dist/services/v1/globals/payout.service.js +154 -0
- package/dist/services/v1/requery/requery.service.d.ts +31 -0
- package/dist/services/v1/requery/requery.service.js +41 -0
- package/dist/services/v1/terminals/terminals.service.d.ts +38 -0
- package/dist/services/v1/terminals/terminals.service.js +58 -0
- package/dist/services/v1/transactions/transactions.service.d.ts +48 -0
- package/dist/services/v1/transactions/transactions.service.js +98 -0
- package/dist/services/v1/virtual-accounts/virtual-accounts.service.d.ts +40 -0
- package/dist/services/v1/virtual-accounts/virtual-accounts.service.js +55 -0
- package/dist/services/v1/webhooks/webhooks.service.d.ts +35 -0
- package/dist/services/v1/webhooks/webhooks.service.js +59 -0
- package/dist/services/v2/airtime/airtime.service.d.ts +42 -0
- package/dist/services/v2/airtime/airtime.service.js +55 -0
- package/dist/services/v2/betting/betting.service.d.ts +43 -0
- package/dist/services/v2/betting/betting.service.js +56 -0
- package/dist/services/v2/cable/cable.service.d.ts +43 -0
- package/dist/services/v2/cable/cable.service.js +56 -0
- package/dist/services/v2/data/data.service.d.ts +42 -0
- package/dist/services/v2/data/data.service.js +55 -0
- package/dist/services/v2/electricity/electricity.service.d.ts +44 -0
- package/dist/services/v2/electricity/electricity.service.js +57 -0
- package/dist/services/v2/transfers/transfers.service.d.ts +75 -0
- package/dist/services/v2/transfers/transfers.service.js +97 -0
- package/dist/types/common/common.types.d.ts +74 -0
- package/dist/types/common/common.types.js +5 -0
- package/dist/types/common/outcome.types.d.ts +53 -0
- package/dist/types/common/outcome.types.js +5 -0
- package/dist/types/v1/accounts/accounts.types.d.ts +37 -0
- package/dist/types/v1/accounts/accounts.types.js +8 -0
- package/dist/types/v1/betting/betting.types.d.ts +26 -0
- package/dist/types/v1/betting/betting.types.js +5 -0
- package/dist/types/v1/cable/cable.types.d.ts +24 -0
- package/dist/types/v1/cable/cable.types.js +5 -0
- package/dist/types/v1/charge/charge.types.d.ts +102 -0
- package/dist/types/v1/charge/charge.types.js +5 -0
- package/dist/types/v1/checkout/checkout.types.d.ts +139 -0
- package/dist/types/v1/checkout/checkout.types.js +5 -0
- package/dist/types/v1/data/data.types.d.ts +14 -0
- package/dist/types/v1/data/data.types.js +5 -0
- package/dist/types/v1/direct-debits/direct-debits.types.d.ts +104 -0
- package/dist/types/v1/direct-debits/direct-debits.types.js +5 -0
- package/dist/types/v1/electricity/electricity.types.d.ts +21 -0
- package/dist/types/v1/electricity/electricity.types.js +5 -0
- package/dist/types/v1/globals/collections.types.d.ts +49 -0
- package/dist/types/v1/globals/collections.types.js +5 -0
- package/dist/types/v1/globals/payout.types.d.ts +183 -0
- package/dist/types/v1/globals/payout.types.js +5 -0
- package/dist/types/v1/requery/requery.types.d.ts +49 -0
- package/dist/types/v1/requery/requery.types.js +5 -0
- package/dist/types/v1/terminals/terminals.types.d.ts +44 -0
- package/dist/types/v1/terminals/terminals.types.js +5 -0
- package/dist/types/v1/transactions/transactions.types.d.ts +87 -0
- package/dist/types/v1/transactions/transactions.types.js +5 -0
- package/dist/types/v1/virtual-accounts/virtual-accounts.types.d.ts +64 -0
- package/dist/types/v1/virtual-accounts/virtual-accounts.types.js +5 -0
- package/dist/types/v1/webhooks/webhooks.types.d.ts +54 -0
- package/dist/types/v1/webhooks/webhooks.types.js +5 -0
- package/dist/types/v2/airtime/airtime.types.d.ts +31 -0
- package/dist/types/v2/airtime/airtime.types.js +5 -0
- package/dist/types/v2/betting/betting.types.d.ts +33 -0
- package/dist/types/v2/betting/betting.types.js +5 -0
- package/dist/types/v2/cable/cable.types.d.ts +32 -0
- package/dist/types/v2/cable/cable.types.js +5 -0
- package/dist/types/v2/data/data.types.d.ts +32 -0
- package/dist/types/v2/data/data.types.js +5 -0
- package/dist/types/v2/electricity/electricity.types.d.ts +34 -0
- package/dist/types/v2/electricity/electricity.types.js +5 -0
- package/dist/types/v2/transfers/transfers.types.d.ts +99 -0
- package/dist/types/v2/transfers/transfers.types.js +5 -0
- package/package.json +42 -5
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module nomba/interfaces/v2/cable
|
|
3
|
+
* @description Cable TV v2 service contract. v2 has purchase endpoints only.
|
|
4
|
+
*/
|
|
5
|
+
import type { CallOptions } from "../../../types/common/common.types.js";
|
|
6
|
+
import type { CablePaymentV2Result, CableTvSubscriptionParams } from "../../../types/v2/cable/cable.types.js";
|
|
7
|
+
export interface ICableV2Service {
|
|
8
|
+
/**
|
|
9
|
+
* `POST /v2/bill/cabletv`. Pays a cable TV subscription from the parent account.
|
|
10
|
+
* @param params The provider, smartcard/customer id and plan, and the `merchantTxRef` used for idempotency.
|
|
11
|
+
* @param options Outcome closures and per-call overrides; without them, success resolves the result and
|
|
12
|
+
* a rejection or pending outcome throws.
|
|
13
|
+
* @returns The payment result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
|
|
14
|
+
* @throws {NombaError} The payment was rejected (4xx).
|
|
15
|
+
* @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
|
|
16
|
+
* @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
|
|
17
|
+
*/
|
|
18
|
+
subscribeCableTv<R = CablePaymentV2Result>(params: CableTvSubscriptionParams, options?: CallOptions<CablePaymentV2Result, R>): Promise<CablePaymentV2Result | R>;
|
|
19
|
+
/**
|
|
20
|
+
* `POST /v2/bill/cabletv/{subAccountId}`. Pays from a sub account.
|
|
21
|
+
* @param subAccountId The sub account to pay from.
|
|
22
|
+
* @param params The provider, smartcard/customer id and plan, and the `merchantTxRef` used for idempotency.
|
|
23
|
+
* @param options Outcome closures and per-call overrides; without them, success resolves the result and
|
|
24
|
+
* a rejection or pending outcome throws.
|
|
25
|
+
* @returns The payment result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
|
|
26
|
+
* @throws {NombaError} The payment was rejected (4xx).
|
|
27
|
+
* @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
|
|
28
|
+
* @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
|
|
29
|
+
*/
|
|
30
|
+
subscribeCableTvFromSubAccount<R = CablePaymentV2Result>(subAccountId: string, params: CableTvSubscriptionParams, options?: CallOptions<CablePaymentV2Result, R>): Promise<CablePaymentV2Result | R>;
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type * from "./ICableV2Service.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module nomba/interfaces/v2/data
|
|
3
|
+
* @description Data v2 service contract
|
|
4
|
+
*/
|
|
5
|
+
import type { CallOptions } from "../../../types/common/common.types.js";
|
|
6
|
+
import type { DataPurchaseParams, DataPurchaseV2Result } from "../../../types/v2/data/data.types.js";
|
|
7
|
+
export interface IDataV2Service {
|
|
8
|
+
/**
|
|
9
|
+
* `POST /v2/bill/data`. Buys a data bundle from the parent account.
|
|
10
|
+
* @param params The phone number, network and data plan, and the `merchantTxRef` used for idempotency.
|
|
11
|
+
* @param options Outcome closures and per-call overrides; without them, success resolves the result and
|
|
12
|
+
* a rejection or pending outcome throws.
|
|
13
|
+
* @returns The purchase result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
|
|
14
|
+
* @throws {NombaError} The purchase was rejected (4xx).
|
|
15
|
+
* @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
|
|
16
|
+
* @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
|
|
17
|
+
*/
|
|
18
|
+
buyData<R = DataPurchaseV2Result>(params: DataPurchaseParams, options?: CallOptions<DataPurchaseV2Result, R>): Promise<DataPurchaseV2Result | R>;
|
|
19
|
+
/**
|
|
20
|
+
* `POST /v2/bill/data/{subAccountId}`. Buys a data bundle from a sub account.
|
|
21
|
+
* @param subAccountId The sub account to buy from.
|
|
22
|
+
* @param params The phone number, network and data plan, and the `merchantTxRef` used for idempotency.
|
|
23
|
+
* @param options Outcome closures and per-call overrides; without them, success resolves the result and
|
|
24
|
+
* a rejection or pending outcome throws.
|
|
25
|
+
* @returns The purchase result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
|
|
26
|
+
* @throws {NombaError} The purchase was rejected (4xx).
|
|
27
|
+
* @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
|
|
28
|
+
* @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
|
|
29
|
+
*/
|
|
30
|
+
buyDataFromSubAccount<R = DataPurchaseV2Result>(subAccountId: string, params: DataPurchaseParams, options?: CallOptions<DataPurchaseV2Result, R>): Promise<DataPurchaseV2Result | R>;
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type * from "./IDataV2Service.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module nomba/interfaces/v2/electricity
|
|
3
|
+
* @description Electricity v2 service contract. v2 has purchase endpoints only.
|
|
4
|
+
*/
|
|
5
|
+
import type { CallOptions } from "../../../types/common/common.types.js";
|
|
6
|
+
import type { ElectricityPaymentParams, ElectricityPaymentV2Result } from "../../../types/v2/electricity/electricity.types.js";
|
|
7
|
+
export interface IElectricityV2Service {
|
|
8
|
+
/**
|
|
9
|
+
* `POST /v2/bill/electricity`. Pays an electricity bill from the parent account. Prepaid meters get the
|
|
10
|
+
* token in `meta.phcnToken`.
|
|
11
|
+
* @param params The disco, meter number and amount, and the `merchantTxRef` used for idempotency.
|
|
12
|
+
* @param options Outcome closures and per-call overrides; without them, success resolves the result and
|
|
13
|
+
* a rejection or pending outcome throws.
|
|
14
|
+
* @returns The payment result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
|
|
15
|
+
* @throws {NombaError} The payment was rejected (4xx).
|
|
16
|
+
* @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
|
|
17
|
+
* @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
|
|
18
|
+
*/
|
|
19
|
+
payElectricity<R = ElectricityPaymentV2Result>(params: ElectricityPaymentParams, options?: CallOptions<ElectricityPaymentV2Result, R>): Promise<ElectricityPaymentV2Result | R>;
|
|
20
|
+
/**
|
|
21
|
+
* `POST /v2/bill/electricity/{subAccountId}`. Pays from a sub account.
|
|
22
|
+
* @param subAccountId The sub account to pay from.
|
|
23
|
+
* @param params The disco, meter number and amount, and the `merchantTxRef` used for idempotency.
|
|
24
|
+
* @param options Outcome closures and per-call overrides; without them, success resolves the result and
|
|
25
|
+
* a rejection or pending outcome throws.
|
|
26
|
+
* @returns The payment result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
|
|
27
|
+
* @throws {NombaError} The payment was rejected (4xx).
|
|
28
|
+
* @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
|
|
29
|
+
* @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
|
|
30
|
+
*/
|
|
31
|
+
payElectricityFromSubAccount<R = ElectricityPaymentV2Result>(subAccountId: string, params: ElectricityPaymentParams, options?: CallOptions<ElectricityPaymentV2Result, R>): Promise<ElectricityPaymentV2Result | R>;
|
|
32
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type * from "./IElectricityV2Service.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module nomba/interfaces/transfers
|
|
3
|
+
* @description Transfers service contract
|
|
4
|
+
*/
|
|
5
|
+
import type { CallOptions } from "../../../types/common/common.types.js";
|
|
6
|
+
import type { Bank, BankAccountLookupParams, BankAccountLookupResult, BankTransferParams, BankTransferResult, WalletTransferParams, WalletTransferResult } from "../../../types/v2/transfers/transfers.types.js";
|
|
7
|
+
export interface ITransfersService {
|
|
8
|
+
/**
|
|
9
|
+
* `GET /v1/transfers/banks`. Lists the banks usable as a transfer destination.
|
|
10
|
+
* @returns The supported banks, each with its name and code.
|
|
11
|
+
* @throws {NombaError} A non-2xx response.
|
|
12
|
+
*/
|
|
13
|
+
listBanks(): Promise<Bank[]>;
|
|
14
|
+
/**
|
|
15
|
+
* `POST /v1/transfers/bank/lookup`. Resolves a bank account number to its account name.
|
|
16
|
+
* @param params The bank code and account number to look up.
|
|
17
|
+
* @returns The resolved account name.
|
|
18
|
+
* @throws {NombaError} The lookup was rejected, e.g. an invalid account number.
|
|
19
|
+
*/
|
|
20
|
+
lookupBankAccount(params: BankAccountLookupParams): Promise<BankAccountLookupResult>;
|
|
21
|
+
/**
|
|
22
|
+
* `POST /v2/transfers/bank`. Sends a bank transfer from the parent account.
|
|
23
|
+
* @param params The destination bank, account number and amount, and the `merchantTxRef` used for
|
|
24
|
+
* idempotency.
|
|
25
|
+
* @param options Outcome closures and per-call overrides; without them, success resolves the result and
|
|
26
|
+
* a rejection or pending outcome throws.
|
|
27
|
+
* @returns The transfer result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
|
|
28
|
+
* @throws {NombaError} The transfer was rejected (4xx) and never happened.
|
|
29
|
+
* @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
|
|
30
|
+
* @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
|
|
31
|
+
*/
|
|
32
|
+
bankTransfer<R = BankTransferResult>(params: BankTransferParams, options?: CallOptions<BankTransferResult, R>): Promise<BankTransferResult | R>;
|
|
33
|
+
/**
|
|
34
|
+
* `POST /v2/transfers/bank/{subAccountId}`. Sends a bank transfer from a sub account. You must ask
|
|
35
|
+
* Nomba to profile you for sub account transfers.
|
|
36
|
+
* @param subAccountId The sub account to transfer from.
|
|
37
|
+
* @param params The destination bank, account number and amount, and the `merchantTxRef` used for
|
|
38
|
+
* idempotency.
|
|
39
|
+
* @param options Outcome closures and per-call overrides; without them, success resolves the result and
|
|
40
|
+
* a rejection or pending outcome throws.
|
|
41
|
+
* @returns The transfer result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
|
|
42
|
+
* @throws {NombaError} The transfer was rejected (4xx) and never happened.
|
|
43
|
+
* @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
|
|
44
|
+
* @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
|
|
45
|
+
*/
|
|
46
|
+
bankTransferFromSubAccount<R = BankTransferResult>(subAccountId: string, params: BankTransferParams, options?: CallOptions<BankTransferResult, R>): Promise<BankTransferResult | R>;
|
|
47
|
+
/**
|
|
48
|
+
* `POST /v2/transfers/wallet`. Sends a wallet-to-wallet transfer from the parent account to another
|
|
49
|
+
* Nomba account.
|
|
50
|
+
* @param params The destination wallet and amount, and the `merchantTxRef` used for idempotency.
|
|
51
|
+
* @param options Outcome closures and per-call overrides; without them, success resolves the result and
|
|
52
|
+
* a rejection or pending outcome throws.
|
|
53
|
+
* @returns The transfer result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
|
|
54
|
+
* @throws {NombaError} The transfer was rejected (4xx) and never happened.
|
|
55
|
+
* @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
|
|
56
|
+
* @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
|
|
57
|
+
*/
|
|
58
|
+
walletTransfer<R = WalletTransferResult>(params: WalletTransferParams, options?: CallOptions<WalletTransferResult, R>): Promise<WalletTransferResult | R>;
|
|
59
|
+
/**
|
|
60
|
+
* `POST /v2/transfers/wallet/{subAccountId}`. Sends a wallet-to-wallet transfer from a sub account.
|
|
61
|
+
* @param subAccountId The sub account to transfer from.
|
|
62
|
+
* @param params The destination wallet and amount, and the `merchantTxRef` used for idempotency.
|
|
63
|
+
* @param options Outcome closures and per-call overrides; without them, success resolves the result and
|
|
64
|
+
* a rejection or pending outcome throws.
|
|
65
|
+
* @returns The transfer result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
|
|
66
|
+
* @throws {NombaError} The transfer was rejected (4xx) and never happened.
|
|
67
|
+
* @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
|
|
68
|
+
* @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
|
|
69
|
+
*/
|
|
70
|
+
walletTransferFromSubAccount<R = WalletTransferResult>(subAccountId: string, params: WalletTransferParams, options?: CallOptions<WalletTransferResult, R>): Promise<WalletTransferResult | R>;
|
|
71
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type * from "./ITransfersService.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module nomba/lib/errors
|
|
3
|
+
* @description Nomba SDK for Node.js
|
|
4
|
+
* @description Error classes
|
|
5
|
+
* @author Nomba Financial Services
|
|
6
|
+
* @version 1.0.0
|
|
7
|
+
* @license MIT
|
|
8
|
+
* @copyright 2026 Nomba
|
|
9
|
+
* @homepage https://nomba.com
|
|
10
|
+
* @support https://nomba.com/support
|
|
11
|
+
* @repository https://github.com/kudi-inc/nomba-sdk-node
|
|
12
|
+
* @docs https://developer.nomba.com
|
|
13
|
+
*/
|
|
14
|
+
/** Thrown for any non-2xx response, or a 2xx whose body `code` is not "00". */
|
|
15
|
+
export declare class NombaError extends Error {
|
|
16
|
+
readonly status: number;
|
|
17
|
+
readonly code: string;
|
|
18
|
+
readonly description: string;
|
|
19
|
+
constructor(status: number, code: string, description: string);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A mutating request failed in a way that does not say whether it was processed (timeout, network error,
|
|
23
|
+
* 5xx, or a 409). The SDK makes one attempt at a mutating call and does not retry automatically: Nomba
|
|
24
|
+
* uses merchantTxRef (in the request body) for idempotency, so an automatic retry with a different reference
|
|
25
|
+
* could double-execute a payment. It may already have gone through. Do not send it again as a new request:
|
|
26
|
+
* check its status (webhook or requery) before deciding whether to retry it yourself, with the same
|
|
27
|
+
* `idempotencyKey` (typically merchantTxRef).
|
|
28
|
+
*/
|
|
29
|
+
export declare class OutcomeUnknownError extends Error {
|
|
30
|
+
readonly method: string;
|
|
31
|
+
readonly path: string;
|
|
32
|
+
readonly idempotencyKey: string;
|
|
33
|
+
readonly attempts: number;
|
|
34
|
+
constructor(method: string, path: string, idempotencyKey: string, attempts: number, cause: unknown);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A money-moving call got a readable answer whose body `code` or `data.status` is not one the docs list for
|
|
38
|
+
* that endpoint. The docs say never to act on an undocumented value: the transfer, bill or top-up may still
|
|
39
|
+
* complete. Wait for the webhook or requery the transaction before refunding or retrying.
|
|
40
|
+
*/
|
|
41
|
+
export declare class UnconfirmedOutcomeError extends Error {
|
|
42
|
+
readonly method: string;
|
|
43
|
+
readonly path: string;
|
|
44
|
+
/** Which value the docs don't list: the body `code`, or `data.status` (including a missing one). */
|
|
45
|
+
readonly reason: "code" | "status";
|
|
46
|
+
readonly code: string | undefined;
|
|
47
|
+
readonly status: string | undefined;
|
|
48
|
+
readonly data: unknown;
|
|
49
|
+
readonly idempotencyKey: string | undefined;
|
|
50
|
+
constructor(method: string, path: string,
|
|
51
|
+
/** Which value the docs don't list: the body `code`, or `data.status` (including a missing one). */
|
|
52
|
+
reason: "code" | "status", code: string | undefined, status: string | undefined, data: unknown, idempotencyKey: string | undefined, cause?: unknown);
|
|
53
|
+
}
|
|
54
|
+
/** True when a call's result is not final: wait for the webhook or requery, never refund or resend. */
|
|
55
|
+
export declare const isPending: (e: unknown) => e is OutcomeUnknownError | UnconfirmedOutcomeError;
|
|
56
|
+
/**
|
|
57
|
+
* Getting or renewing the access token failed, so the request itself was never sent. Nothing happened on
|
|
58
|
+
* Nomba's side: fix the credentials or retry later. `cause` holds the underlying error (often a NombaError).
|
|
59
|
+
*/
|
|
60
|
+
export declare class TokenError extends Error {
|
|
61
|
+
constructor(cause: unknown);
|
|
62
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module nomba/lib/errors
|
|
3
|
+
* @description Nomba SDK for Node.js
|
|
4
|
+
* @description Error classes
|
|
5
|
+
* @author Nomba Financial Services
|
|
6
|
+
* @version 1.0.0
|
|
7
|
+
* @license MIT
|
|
8
|
+
* @copyright 2026 Nomba
|
|
9
|
+
* @homepage https://nomba.com
|
|
10
|
+
* @support https://nomba.com/support
|
|
11
|
+
* @repository https://github.com/kudi-inc/nomba-sdk-node
|
|
12
|
+
* @docs https://developer.nomba.com
|
|
13
|
+
*/
|
|
14
|
+
/** Thrown for any non-2xx response, or a 2xx whose body `code` is not "00". */
|
|
15
|
+
export class NombaError extends Error {
|
|
16
|
+
status;
|
|
17
|
+
code;
|
|
18
|
+
description;
|
|
19
|
+
constructor(status, code, description) {
|
|
20
|
+
super(`[${code}] ${description}`);
|
|
21
|
+
this.status = status;
|
|
22
|
+
this.code = code;
|
|
23
|
+
this.description = description;
|
|
24
|
+
this.name = "NombaError";
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A mutating request failed in a way that does not say whether it was processed (timeout, network error,
|
|
29
|
+
* 5xx, or a 409). The SDK makes one attempt at a mutating call and does not retry automatically: Nomba
|
|
30
|
+
* uses merchantTxRef (in the request body) for idempotency, so an automatic retry with a different reference
|
|
31
|
+
* could double-execute a payment. It may already have gone through. Do not send it again as a new request:
|
|
32
|
+
* check its status (webhook or requery) before deciding whether to retry it yourself, with the same
|
|
33
|
+
* `idempotencyKey` (typically merchantTxRef).
|
|
34
|
+
*/
|
|
35
|
+
export class OutcomeUnknownError extends Error {
|
|
36
|
+
method;
|
|
37
|
+
path;
|
|
38
|
+
idempotencyKey;
|
|
39
|
+
attempts;
|
|
40
|
+
constructor(method, path, idempotencyKey, attempts, cause) {
|
|
41
|
+
super(`Outcome unknown for ${method} ${path} (idempotencyKey "${idempotencyKey}"); it may have been processed. Check its status (webhook or requery) before retrying it yourself. Do not send it as a new request with a different reference.`, { cause });
|
|
42
|
+
this.method = method;
|
|
43
|
+
this.path = path;
|
|
44
|
+
this.idempotencyKey = idempotencyKey;
|
|
45
|
+
this.attempts = attempts;
|
|
46
|
+
this.name = "OutcomeUnknownError";
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* A money-moving call got a readable answer whose body `code` or `data.status` is not one the docs list for
|
|
51
|
+
* that endpoint. The docs say never to act on an undocumented value: the transfer, bill or top-up may still
|
|
52
|
+
* complete. Wait for the webhook or requery the transaction before refunding or retrying.
|
|
53
|
+
*/
|
|
54
|
+
export class UnconfirmedOutcomeError extends Error {
|
|
55
|
+
method;
|
|
56
|
+
path;
|
|
57
|
+
reason;
|
|
58
|
+
code;
|
|
59
|
+
status;
|
|
60
|
+
data;
|
|
61
|
+
idempotencyKey;
|
|
62
|
+
constructor(method, path,
|
|
63
|
+
/** Which value the docs don't list: the body `code`, or `data.status` (including a missing one). */
|
|
64
|
+
reason, code, status, data, idempotencyKey, cause) {
|
|
65
|
+
const what = reason === "code"
|
|
66
|
+
? `code "${code}"`
|
|
67
|
+
: status === undefined
|
|
68
|
+
? "missing data.status"
|
|
69
|
+
: `status "${status}"`;
|
|
70
|
+
super(`Unconfirmed outcome for ${method} ${path}: undocumented ${what}. It may still complete; wait for the webhook or requery before acting.`, { cause });
|
|
71
|
+
this.method = method;
|
|
72
|
+
this.path = path;
|
|
73
|
+
this.reason = reason;
|
|
74
|
+
this.code = code;
|
|
75
|
+
this.status = status;
|
|
76
|
+
this.data = data;
|
|
77
|
+
this.idempotencyKey = idempotencyKey;
|
|
78
|
+
this.name = "UnconfirmedOutcomeError";
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/** True when a call's result is not final: wait for the webhook or requery, never refund or resend. */
|
|
82
|
+
export const isPending = (e) => e instanceof OutcomeUnknownError || e instanceof UnconfirmedOutcomeError;
|
|
83
|
+
/**
|
|
84
|
+
* Getting or renewing the access token failed, so the request itself was never sent. Nothing happened on
|
|
85
|
+
* Nomba's side: fix the credentials or retry later. `cause` holds the underlying error (often a NombaError).
|
|
86
|
+
*/
|
|
87
|
+
export class TokenError extends Error {
|
|
88
|
+
constructor(cause) {
|
|
89
|
+
super(`Could not get an access token, so the request was not sent: ${cause instanceof Error ? cause.message : String(cause)}`, { cause });
|
|
90
|
+
this.name = "TokenError";
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module nomba/lib/outcome
|
|
3
|
+
* @description Classifies a money-moving call as success, pending or failed, using only documented values
|
|
4
|
+
*/
|
|
5
|
+
import type { IHttpClient } from "../interfaces/http/IHttpClient.js";
|
|
6
|
+
import type { HttpMethod, HttpRequestOptions } from "../types/common/common.types.js";
|
|
7
|
+
import type { Outcome, OutcomeHandlers, OutcomeTable } from "../types/common/outcome.types.js";
|
|
8
|
+
/** Documented 4xx body codes (docs/api-basics/response-codes): definite rejections, safe to report as failed. */
|
|
9
|
+
export declare const REJECTED: Readonly<Record<string, "failed">>;
|
|
10
|
+
/** Anything the table does not list is pending: an undocumented value is never acted on. */
|
|
11
|
+
export declare const classify: (table: OutcomeTable, code: string, status: string | undefined) => Outcome;
|
|
12
|
+
/**
|
|
13
|
+
* Makes one money-moving call and settles it into exactly one outcome: success, pending, or failed.
|
|
14
|
+
*
|
|
15
|
+
* With a closure for that outcome, resolves to what the closure returns. Without one:
|
|
16
|
+
* - **success**: resolves `data`
|
|
17
|
+
* - **pending**: throws `UnconfirmedOutcomeError` (undocumented code/status, or documented pending)
|
|
18
|
+
* - **failed**: throws `NombaError` (documented rejection)
|
|
19
|
+
*
|
|
20
|
+
* Transport failures (timeout, network error, 5xx) throw `OutcomeUnknownError`.
|
|
21
|
+
*
|
|
22
|
+
* @template T The response data type.
|
|
23
|
+
* @template R The return type when closures transform the result.
|
|
24
|
+
* @param http The HTTP client to use.
|
|
25
|
+
* @param method The HTTP method (`POST` for money-moving calls).
|
|
26
|
+
* @param path The API endpoint path.
|
|
27
|
+
* @param request The request body and query; `okCodes`, `envelope`, and `idempotencyKey` are set internally.
|
|
28
|
+
* @param table Maps body codes and `data.status` values to outcomes; unlisted values are pending.
|
|
29
|
+
* @param idempotencyKey Derived from params (e.g., `merchantTxRef`). Tracked in errors so callers know
|
|
30
|
+
* which transaction to requery; not sent in headers.
|
|
31
|
+
* @param options Outcome closures: `onSuccess`, `onPending`, `onFailed`. Each transforms the result or error.
|
|
32
|
+
* @returns The response `data`, or what the matching closure returns.
|
|
33
|
+
* @throws {NombaError} A documented rejection (4xx body code).
|
|
34
|
+
* @throws {OutcomeUnknownError} Transport failure — outcome unknown; requery before retrying.
|
|
35
|
+
* @throws {UnconfirmedOutcomeError} Pending or undocumented response — do not retry without requerying.
|
|
36
|
+
*/
|
|
37
|
+
export declare function settle<T, R = T>(http: IHttpClient, method: HttpMethod, path: string, request: Omit<HttpRequestOptions, "okCodes" | "envelope" | "idempotencyKey">, table: OutcomeTable, idempotencyKey: string, options?: OutcomeHandlers<T, R>): Promise<T | R>;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module nomba/lib/outcome
|
|
3
|
+
* @description Classifies a money-moving call as success, pending or failed, using only documented values
|
|
4
|
+
*/
|
|
5
|
+
import { isPending, NombaError, OutcomeUnknownError, UnconfirmedOutcomeError, } from "./errors.js";
|
|
6
|
+
/** Documented 4xx body codes (docs/api-basics/response-codes): definite rejections, safe to report as failed. */
|
|
7
|
+
export const REJECTED = {
|
|
8
|
+
"400": "failed",
|
|
9
|
+
"401": "failed",
|
|
10
|
+
"403": "failed",
|
|
11
|
+
"404": "failed",
|
|
12
|
+
"422": "failed",
|
|
13
|
+
"429": "failed",
|
|
14
|
+
};
|
|
15
|
+
// Own keys only: a status like "constructor" must not match Object.prototype.
|
|
16
|
+
const lookup = (record, key) => record && key !== undefined && Object.hasOwn(record, key)
|
|
17
|
+
? record[key]
|
|
18
|
+
: undefined;
|
|
19
|
+
/** Anything the table does not list is pending: an undocumented value is never acted on. */
|
|
20
|
+
export const classify = (table, code, status) => {
|
|
21
|
+
const byCode = lookup(table.codes, code) ?? "pending";
|
|
22
|
+
if (byCode !== "success" || !table.statuses)
|
|
23
|
+
return byCode;
|
|
24
|
+
return lookup(table.statuses, status) ?? "pending";
|
|
25
|
+
};
|
|
26
|
+
const defaultStatusOf = (data) => {
|
|
27
|
+
const s = data?.status;
|
|
28
|
+
return typeof s === "string" ? s : undefined;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Makes one money-moving call and settles it into exactly one outcome: success, pending, or failed.
|
|
32
|
+
*
|
|
33
|
+
* With a closure for that outcome, resolves to what the closure returns. Without one:
|
|
34
|
+
* - **success**: resolves `data`
|
|
35
|
+
* - **pending**: throws `UnconfirmedOutcomeError` (undocumented code/status, or documented pending)
|
|
36
|
+
* - **failed**: throws `NombaError` (documented rejection)
|
|
37
|
+
*
|
|
38
|
+
* Transport failures (timeout, network error, 5xx) throw `OutcomeUnknownError`.
|
|
39
|
+
*
|
|
40
|
+
* @template T The response data type.
|
|
41
|
+
* @template R The return type when closures transform the result.
|
|
42
|
+
* @param http The HTTP client to use.
|
|
43
|
+
* @param method The HTTP method (`POST` for money-moving calls).
|
|
44
|
+
* @param path The API endpoint path.
|
|
45
|
+
* @param request The request body and query; `okCodes`, `envelope`, and `idempotencyKey` are set internally.
|
|
46
|
+
* @param table Maps body codes and `data.status` values to outcomes; unlisted values are pending.
|
|
47
|
+
* @param idempotencyKey Derived from params (e.g., `merchantTxRef`). Tracked in errors so callers know
|
|
48
|
+
* which transaction to requery; not sent in headers.
|
|
49
|
+
* @param options Outcome closures: `onSuccess`, `onPending`, `onFailed`. Each transforms the result or error.
|
|
50
|
+
* @returns The response `data`, or what the matching closure returns.
|
|
51
|
+
* @throws {NombaError} A documented rejection (4xx body code).
|
|
52
|
+
* @throws {OutcomeUnknownError} Transport failure — outcome unknown; requery before retrying.
|
|
53
|
+
* @throws {UnconfirmedOutcomeError} Pending or undocumented response — do not retry without requerying.
|
|
54
|
+
*/
|
|
55
|
+
export async function settle(http, method, path, request, table, idempotencyKey, options = {}) {
|
|
56
|
+
const { onSuccess, onPending, onFailed } = options;
|
|
57
|
+
const report = (outcome, code, status, key = idempotencyKey) => http.reportOutcome({
|
|
58
|
+
method,
|
|
59
|
+
path,
|
|
60
|
+
outcome,
|
|
61
|
+
...(code === undefined ? {} : { code }),
|
|
62
|
+
...(status === undefined ? {} : { status }),
|
|
63
|
+
...(key === undefined ? {} : { idempotencyKey: key }),
|
|
64
|
+
});
|
|
65
|
+
let res;
|
|
66
|
+
try {
|
|
67
|
+
res = await http.request(method, path, {
|
|
68
|
+
...request,
|
|
69
|
+
...(idempotencyKey === undefined ? {} : { idempotencyKey }),
|
|
70
|
+
// Only documented non-failure codes come back as data; the rest arrive as NombaError below.
|
|
71
|
+
okCodes: Object.keys(table.codes).filter((c) => lookup(table.codes, c) !== "failed"),
|
|
72
|
+
envelope: true,
|
|
73
|
+
...(idempotencyKey === undefined ? {} : { idempotencyKey }),
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
catch (caught) {
|
|
77
|
+
let e = caught;
|
|
78
|
+
// Only a documented rejection (by HTTP status or body code) is a failure. Anything else (a 2xx with an
|
|
79
|
+
// unlisted body code, a 409 key conflict, a 408) may mean the payment went through: unconfirmed, never failed.
|
|
80
|
+
if (e instanceof NombaError &&
|
|
81
|
+
lookup(table.codes, String(e.status)) !== "failed" &&
|
|
82
|
+
lookup(table.codes, e.code) !== "failed")
|
|
83
|
+
e = new UnconfirmedOutcomeError(method, path, "code", e.code, undefined, undefined, idempotencyKey, e);
|
|
84
|
+
if (isPending(e)) {
|
|
85
|
+
const key = e instanceof OutcomeUnknownError ? e.idempotencyKey : idempotencyKey;
|
|
86
|
+
const code = e instanceof UnconfirmedOutcomeError ? e.code : undefined;
|
|
87
|
+
report("pending", code, undefined, key);
|
|
88
|
+
if (!onPending)
|
|
89
|
+
throw e;
|
|
90
|
+
return onPending({
|
|
91
|
+
cause: e,
|
|
92
|
+
...(code === undefined ? {} : { code }),
|
|
93
|
+
...(key === undefined ? {} : { idempotencyKey: key }),
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
if (e instanceof NombaError) {
|
|
97
|
+
report("failed", e.code);
|
|
98
|
+
if (!onFailed)
|
|
99
|
+
throw e;
|
|
100
|
+
return onFailed({ error: e, code: e.code });
|
|
101
|
+
}
|
|
102
|
+
throw e;
|
|
103
|
+
}
|
|
104
|
+
const status = (table.statusOf ?? defaultStatusOf)(res.data);
|
|
105
|
+
const outcome = classify(table, res.code, status);
|
|
106
|
+
report(outcome, res.code, status);
|
|
107
|
+
if (outcome === "success")
|
|
108
|
+
return onSuccess ? onSuccess(res.data) : res.data;
|
|
109
|
+
if (onPending)
|
|
110
|
+
return onPending({
|
|
111
|
+
data: res.data,
|
|
112
|
+
code: res.code,
|
|
113
|
+
...(status === undefined ? {} : { status }),
|
|
114
|
+
...(idempotencyKey === undefined ? {} : { idempotencyKey }),
|
|
115
|
+
});
|
|
116
|
+
// No onPending: documented or not, pending always throws so it can never be mistaken for success.
|
|
117
|
+
// reason tells what to check when debugging: an unlisted code, or an unlisted status when the code is listed.
|
|
118
|
+
const reason = lookup(table.codes, res.code) === undefined
|
|
119
|
+
? "code"
|
|
120
|
+
: status !== undefined && lookup(table.statuses, status) === undefined
|
|
121
|
+
? "status"
|
|
122
|
+
: lookup(table.codes, res.code) === "pending"
|
|
123
|
+
? "code"
|
|
124
|
+
: "status";
|
|
125
|
+
throw new UnconfirmedOutcomeError(method, path, reason, res.code, status, res.data, idempotencyKey);
|
|
126
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module nomba/lib/paginate
|
|
3
|
+
* @description Nomba SDK for Node.js
|
|
4
|
+
* @description Pagination helper
|
|
5
|
+
* @author Nomba Financial Services
|
|
6
|
+
* @version 1.0.0
|
|
7
|
+
* @license MIT
|
|
8
|
+
* @copyright 2026 Nomba
|
|
9
|
+
* @homepage https://nomba.com
|
|
10
|
+
* @support https://nomba.com/support
|
|
11
|
+
* @repository https://github.com/kudi-inc/nomba-sdk-node
|
|
12
|
+
* @docs https://developer.nomba.com
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Yields every item across pages. Per the docs, keep requesting with the returned `cursor`
|
|
16
|
+
* until the API returns none. Lazy: a page is fetched only when the previous one is consumed.
|
|
17
|
+
*/
|
|
18
|
+
export declare function paginate<T>(fetchPage: (cursor: string | undefined) => Promise<{
|
|
19
|
+
results: T[];
|
|
20
|
+
cursor: string;
|
|
21
|
+
}>): AsyncGenerator<T>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module nomba/lib/paginate
|
|
3
|
+
* @description Nomba SDK for Node.js
|
|
4
|
+
* @description Pagination helper
|
|
5
|
+
* @author Nomba Financial Services
|
|
6
|
+
* @version 1.0.0
|
|
7
|
+
* @license MIT
|
|
8
|
+
* @copyright 2026 Nomba
|
|
9
|
+
* @homepage https://nomba.com
|
|
10
|
+
* @support https://nomba.com/support
|
|
11
|
+
* @repository https://github.com/kudi-inc/nomba-sdk-node
|
|
12
|
+
* @docs https://developer.nomba.com
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Yields every item across pages. Per the docs, keep requesting with the returned `cursor`
|
|
16
|
+
* until the API returns none. Lazy: a page is fetched only when the previous one is consumed.
|
|
17
|
+
*/
|
|
18
|
+
export async function* paginate(fetchPage) {
|
|
19
|
+
let cursor;
|
|
20
|
+
do {
|
|
21
|
+
const page = await fetchPage(cursor);
|
|
22
|
+
yield* page.results;
|
|
23
|
+
cursor = page.cursor;
|
|
24
|
+
} while (cursor);
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const SDK_VERSION = "0.3.0";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const SDK_VERSION = "0.3.0";
|