@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,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module nomba/lib/paginate
|
|
3
|
+
* @description Nomba SDK for Node.js
|
|
4
|
+
* @description Token store 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
|
+
export interface TokenData {
|
|
15
|
+
businessId: string;
|
|
16
|
+
access_token: string;
|
|
17
|
+
refresh_token: string;
|
|
18
|
+
/** ISO 8601 UTC, e.g. 2022-07-08T14:33:00Z */
|
|
19
|
+
expiresAt: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Where the SDK keeps the current token. Implement it over Redis, a database, etc. so
|
|
23
|
+
* several instances share one token. Nomba allows a single session per client, so
|
|
24
|
+
* instances that share a store should also implement `lock`.
|
|
25
|
+
*
|
|
26
|
+
* Contract for shared stores:
|
|
27
|
+
* - `get`, `set` and `clear` must be atomic and durable (a `set` that resolves must be readable
|
|
28
|
+
* by every instance).
|
|
29
|
+
* - `lock` must expire (a TTL) so a crashed instance cannot hold it forever.
|
|
30
|
+
* - Store errors never fail a request: the SDK retries `set` twice, then keeps the token in
|
|
31
|
+
* process memory and reports the error through the `onStoreError` option.
|
|
32
|
+
*/
|
|
33
|
+
export interface TokenStore {
|
|
34
|
+
get(): TokenData | undefined | Promise<TokenData | undefined>;
|
|
35
|
+
set(token: TokenData): void | Promise<void>;
|
|
36
|
+
clear(): void | Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Optional cross-instance lock. The SDK runs every issue/refresh inside `fn` so only
|
|
39
|
+
* one instance authenticates at a time (issue, refresh and revoke); others then pick up the stored token.
|
|
40
|
+
*/
|
|
41
|
+
lock?<T>(fn: () => Promise<T>): Promise<T>;
|
|
42
|
+
}
|
|
43
|
+
/** Default store: one token, this process only. */
|
|
44
|
+
export declare class MemoryTokenStore implements TokenStore {
|
|
45
|
+
#private;
|
|
46
|
+
get(): TokenData | undefined;
|
|
47
|
+
set(token: TokenData): void;
|
|
48
|
+
clear(): void;
|
|
49
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module nomba/lib/paginate
|
|
3
|
+
* @description Nomba SDK for Node.js
|
|
4
|
+
* @description Token store 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
|
+
/** Default store: one token, this process only. */
|
|
15
|
+
export class MemoryTokenStore {
|
|
16
|
+
#token;
|
|
17
|
+
get() {
|
|
18
|
+
return this.#token;
|
|
19
|
+
}
|
|
20
|
+
set(token) {
|
|
21
|
+
this.#token = token;
|
|
22
|
+
}
|
|
23
|
+
clear() {
|
|
24
|
+
this.#token = undefined;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module nomba/lib/paginate
|
|
3
|
+
* @description Nomba SDK for Node.js
|
|
4
|
+
* @description Utility types and 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
|
+
export type PageParams = {
|
|
15
|
+
/** Page size, at most 50 (see docs/api-basics/pagination). */
|
|
16
|
+
limit?: number;
|
|
17
|
+
cursor?: string;
|
|
18
|
+
};
|
|
19
|
+
export declare const pathId: (v: string) => string;
|
|
20
|
+
export declare const pageQuery: <T extends {
|
|
21
|
+
cursor?: string;
|
|
22
|
+
}>(p: T) => T & {
|
|
23
|
+
cursor: string | undefined;
|
|
24
|
+
};
|
|
25
|
+
export declare const sleep: (ms: number) => Promise<void>;
|
|
26
|
+
export declare const assertKey: (key: string) => void;
|
|
27
|
+
/** A cursor-paginated list response: `{ results, cursor }`, with `cursor` empty on the last page. */
|
|
28
|
+
export type Page<T> = {
|
|
29
|
+
results?: T[];
|
|
30
|
+
cursor?: string;
|
|
31
|
+
};
|
package/dist/lib/util.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module nomba/lib/paginate
|
|
3
|
+
* @description Nomba SDK for Node.js
|
|
4
|
+
* @description Utility types and 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
|
+
// Path ids come from callers; reject values that would change the endpoint ("", ".", "..").
|
|
15
|
+
export const pathId = (v) => {
|
|
16
|
+
if (!v || v === "." || v === "..")
|
|
17
|
+
throw new Error(`Invalid id "${v}"`);
|
|
18
|
+
return encodeURIComponent(v);
|
|
19
|
+
};
|
|
20
|
+
// The API returns cursor "" on the last page; the docs say to send a cursor only when given one.
|
|
21
|
+
export const pageQuery = (p) => ({
|
|
22
|
+
...p,
|
|
23
|
+
cursor: p.cursor || undefined,
|
|
24
|
+
});
|
|
25
|
+
export const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
26
|
+
// A header-safe idempotency key: printable ASCII, no spaces. Anything else would make fetch throw before
|
|
27
|
+
// sending, which would look like a network failure.
|
|
28
|
+
export const assertKey = (key) => {
|
|
29
|
+
if (!/^[\x21-\x7e]+$/.test(key))
|
|
30
|
+
throw new Error(`Invalid idempotency key "${key}": use printable ASCII without spaces`);
|
|
31
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module nomba/lib/webhooks
|
|
3
|
+
* @description Nomba SDK for Node.js
|
|
4
|
+
* @description Webhook signature verification
|
|
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
|
+
* @see https://developer.nomba.com/docs/api-basics/webhook
|
|
14
|
+
*/
|
|
15
|
+
/** The fields the signature covers. Everything else in the event is left as `unknown`. */
|
|
16
|
+
export interface WebhookEvent {
|
|
17
|
+
[key: string]: unknown;
|
|
18
|
+
/** e.g. payment_success, payment_failed, payout_success, payout_refund. */
|
|
19
|
+
event_type?: string;
|
|
20
|
+
requestId?: string;
|
|
21
|
+
data?: {
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
merchant?: {
|
|
24
|
+
[key: string]: unknown;
|
|
25
|
+
userId?: string;
|
|
26
|
+
walletId?: string;
|
|
27
|
+
};
|
|
28
|
+
transaction?: {
|
|
29
|
+
[key: string]: unknown;
|
|
30
|
+
transactionId?: string;
|
|
31
|
+
type?: string;
|
|
32
|
+
time?: string;
|
|
33
|
+
responseCode?: string;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* True when `signature` (the nomba-signature header) matches the event, signed with your dashboard's
|
|
39
|
+
* webhook signature key and the nomba-timestamp header. `body` is the raw request body (string or Buffer) or the parsed event.
|
|
40
|
+
* A missing or malformed signature or body returns false rather than throwing.
|
|
41
|
+
* The docs compare signatures case-insensitively, so this does too.
|
|
42
|
+
*/
|
|
43
|
+
export declare function verifyWebhook(body: string | Buffer | WebhookEvent, signature: string | undefined, timestamp: string, secret: string): boolean;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module nomba/lib/webhooks
|
|
3
|
+
* @description Nomba SDK for Node.js
|
|
4
|
+
* @description Webhook signature verification
|
|
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
|
+
* @see https://developer.nomba.com/docs/api-basics/webhook
|
|
14
|
+
*/
|
|
15
|
+
import { createHmac, timingSafeEqual } from "node:crypto";
|
|
16
|
+
/**
|
|
17
|
+
* The base64 HMAC-SHA256 of the signing string the docs define:
|
|
18
|
+
* event_type:requestId:userId:walletId:transactionId:type:time:responseCode:timestamp,
|
|
19
|
+
* with a missing field (or a responseCode of "null") as "".
|
|
20
|
+
*/
|
|
21
|
+
function webhookSignature(event, secret, timestamp) {
|
|
22
|
+
const merchant = event.data?.merchant ?? {};
|
|
23
|
+
const tx = event.data?.transaction ?? {};
|
|
24
|
+
const responseCode = tx.responseCode === "null" ? "" : tx.responseCode;
|
|
25
|
+
const signed = [
|
|
26
|
+
event.event_type,
|
|
27
|
+
event.requestId,
|
|
28
|
+
merchant.userId,
|
|
29
|
+
merchant.walletId,
|
|
30
|
+
tx.transactionId,
|
|
31
|
+
tx.type,
|
|
32
|
+
tx.time,
|
|
33
|
+
responseCode,
|
|
34
|
+
timestamp,
|
|
35
|
+
]
|
|
36
|
+
.map((v) => v || "")
|
|
37
|
+
.join(":");
|
|
38
|
+
return createHmac("sha256", secret).update(signed).digest("base64");
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* True when `signature` (the nomba-signature header) matches the event, signed with your dashboard's
|
|
42
|
+
* webhook signature key and the nomba-timestamp header. `body` is the raw request body (string or Buffer) or the parsed event.
|
|
43
|
+
* A missing or malformed signature or body returns false rather than throwing.
|
|
44
|
+
* The docs compare signatures case-insensitively, so this does too.
|
|
45
|
+
*/
|
|
46
|
+
export function verifyWebhook(body, signature, timestamp, secret) {
|
|
47
|
+
if (typeof signature !== "string")
|
|
48
|
+
return false;
|
|
49
|
+
let event;
|
|
50
|
+
try {
|
|
51
|
+
event =
|
|
52
|
+
typeof body === "string" || Buffer.isBuffer(body)
|
|
53
|
+
? JSON.parse(body.toString())
|
|
54
|
+
: body;
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
if (typeof event !== "object" || event === null)
|
|
60
|
+
return false;
|
|
61
|
+
const expected = Buffer.from(webhookSignature(event, secret, timestamp).toLowerCase());
|
|
62
|
+
const given = Buffer.from(signature.toLowerCase());
|
|
63
|
+
return expected.length === given.length && timingSafeEqual(expected, given);
|
|
64
|
+
}
|
package/dist/nomba.d.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module nomba
|
|
3
|
+
* @description Composition root: builds the HTTP client and injects it into every service
|
|
4
|
+
*/
|
|
5
|
+
import type { IHttpClient } from "./interfaces/http/IHttpClient.js";
|
|
6
|
+
import type { IAccountsService } from "./interfaces/v1/accounts/index.js";
|
|
7
|
+
import type { IBettingService } from "./interfaces/v1/betting/index.js";
|
|
8
|
+
import type { ICableService } from "./interfaces/v1/cable/index.js";
|
|
9
|
+
import type { IChargeService } from "./interfaces/v1/charge/index.js";
|
|
10
|
+
import type { ICheckoutService } from "./interfaces/v1/checkout/index.js";
|
|
11
|
+
import type { IDataService } from "./interfaces/v1/data/index.js";
|
|
12
|
+
import type { IDirectDebitsService } from "./interfaces/v1/direct-debits/index.js";
|
|
13
|
+
import type { IElectricityService } from "./interfaces/v1/electricity/index.js";
|
|
14
|
+
import type { IGlobalCollectionsService } from "./interfaces/v1/globals/collections/index.js";
|
|
15
|
+
import type { IGlobalPayoutService } from "./interfaces/v1/globals/payouts/index.js";
|
|
16
|
+
import type { IRequeryService } from "./interfaces/v1/requery/index.js";
|
|
17
|
+
import type { ITerminalsService } from "./interfaces/v1/terminals/index.js";
|
|
18
|
+
import type { ITransactionsService } from "./interfaces/v1/transactions/index.js";
|
|
19
|
+
import type { IVirtualAccountsService } from "./interfaces/v1/virtual-accounts/index.js";
|
|
20
|
+
import type { IWebhooksService } from "./interfaces/v1/webhooks/index.js";
|
|
21
|
+
import type { IAirtimeV2Service } from "./interfaces/v2/airtime/index.js";
|
|
22
|
+
import type { IBettingV2Service } from "./interfaces/v2/betting/index.js";
|
|
23
|
+
import type { ICableV2Service } from "./interfaces/v2/cable/index.js";
|
|
24
|
+
import type { IDataV2Service } from "./interfaces/v2/data/index.js";
|
|
25
|
+
import type { IElectricityV2Service } from "./interfaces/v2/electricity/index.js";
|
|
26
|
+
import type { ITransfersService } from "./interfaces/v2/transfers/index.js";
|
|
27
|
+
import type { TokenData } from "./lib/token-store.js";
|
|
28
|
+
import type { Environment, HttpMethod, HttpRequestOptions, NombaOptions } from "./types/common/common.types.js";
|
|
29
|
+
/**
|
|
30
|
+
* The Nomba SDK client. Exposes one property per product (`accounts`, `transfers`, `electricity`, ...),
|
|
31
|
+
* each backed by the shared, authenticated HTTP transport.
|
|
32
|
+
*/
|
|
33
|
+
export declare class Nomba {
|
|
34
|
+
#private;
|
|
35
|
+
readonly accounts: IAccountsService;
|
|
36
|
+
readonly virtualAccounts: IVirtualAccountsService;
|
|
37
|
+
readonly checkout: ICheckoutService;
|
|
38
|
+
readonly charge: IChargeService;
|
|
39
|
+
readonly transfers: ITransfersService;
|
|
40
|
+
readonly requery: IRequeryService;
|
|
41
|
+
readonly directDebits: IDirectDebitsService;
|
|
42
|
+
readonly transactions: ITransactionsService;
|
|
43
|
+
readonly terminals: ITerminalsService;
|
|
44
|
+
readonly electricity: IElectricityV2Service;
|
|
45
|
+
readonly cable: ICableV2Service;
|
|
46
|
+
readonly betting: IBettingV2Service;
|
|
47
|
+
readonly airtime: IAirtimeV2Service;
|
|
48
|
+
readonly data: IDataV2Service;
|
|
49
|
+
readonly billElectricity: IElectricityService;
|
|
50
|
+
readonly billCable: ICableService;
|
|
51
|
+
readonly billBetting: IBettingService;
|
|
52
|
+
readonly billData: IDataService;
|
|
53
|
+
readonly globalCollections: IGlobalCollectionsService;
|
|
54
|
+
readonly globalPayout: IGlobalPayoutService;
|
|
55
|
+
readonly webhooks: IWebhooksService;
|
|
56
|
+
/**
|
|
57
|
+
* @param options Client credentials and transport configuration.
|
|
58
|
+
* @param http Replace the transport, e.g. with a fake in tests. Defaults to the real `HttpClient`.
|
|
59
|
+
*/
|
|
60
|
+
constructor(options: NombaOptions, http?: IHttpClient);
|
|
61
|
+
/** `"production"` or `"sandbox"`, as passed to the constructor (defaults to `"production"`). */
|
|
62
|
+
get environment(): Environment;
|
|
63
|
+
/**
|
|
64
|
+
* `POST /v1/auth/token/issue`. Gets a new access token. Called for you automatically on first use,
|
|
65
|
+
* so you normally never need this directly.
|
|
66
|
+
* @returns The issued token data.
|
|
67
|
+
* @throws {NombaError} The credentials were rejected.
|
|
68
|
+
*/
|
|
69
|
+
issueToken(): Promise<TokenData>;
|
|
70
|
+
/**
|
|
71
|
+
* `POST /v1/auth/token/refresh`. Refreshes the stored token. Called for you automatically 5 minutes
|
|
72
|
+
* before expiry, so you normally never need this directly.
|
|
73
|
+
* @returns The refreshed token data.
|
|
74
|
+
* @throws {Error} No token has been issued yet.
|
|
75
|
+
* @throws {NombaError} The refresh token was rejected.
|
|
76
|
+
*/
|
|
77
|
+
refreshToken(): Promise<TokenData>;
|
|
78
|
+
/**
|
|
79
|
+
* `POST /v1/auth/token/revoke`. Ends the session, e.g. on shutdown. A no-op if no token is held.
|
|
80
|
+
* @throws {NombaError} Nomba rejected the revoke call.
|
|
81
|
+
*/
|
|
82
|
+
revokeToken(): Promise<void>;
|
|
83
|
+
/**
|
|
84
|
+
* Makes an authenticated call to any Nomba endpoint, including ones this SDK has no dedicated method
|
|
85
|
+
* for. Issues or refreshes the token as needed.
|
|
86
|
+
* @param method The HTTP method.
|
|
87
|
+
* @param path The endpoint path, starting with `/` (e.g. `/v1/accounts/parent`).
|
|
88
|
+
* @param options Query params, request body, idempotency key and related per-call overrides.
|
|
89
|
+
* @returns The response body's `data` field.
|
|
90
|
+
* @throws {TokenError} Getting or refreshing the access token failed; the request was never sent.
|
|
91
|
+
* @throws {NombaError} A non-2xx response, or a 2xx whose body `code` is not one of `options.okCodes`.
|
|
92
|
+
* @throws {OutcomeUnknownError} A mutating call failed in a way that does not say whether it was
|
|
93
|
+
* processed (timeout, network error, 5xx, or a 409); check its status before retrying.
|
|
94
|
+
*/
|
|
95
|
+
request<T>(method: HttpMethod, path: string, options?: HttpRequestOptions): Promise<T>;
|
|
96
|
+
}
|
package/dist/nomba.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module nomba
|
|
3
|
+
* @description Composition root: builds the HTTP client and injects it into every service
|
|
4
|
+
*/
|
|
5
|
+
import { HttpClient } from "./services/http/http-client.service.js";
|
|
6
|
+
import { AccountsService } from "./services/v1/accounts/accounts.service.js";
|
|
7
|
+
import { BettingService } from "./services/v1/betting/betting.service.js";
|
|
8
|
+
import { CableService } from "./services/v1/cable/cable.service.js";
|
|
9
|
+
import { ChargeService } from "./services/v1/charge/charge.service.js";
|
|
10
|
+
import { CheckoutService } from "./services/v1/checkout/checkout.service.js";
|
|
11
|
+
import { DataService } from "./services/v1/data/data.service.js";
|
|
12
|
+
import { DirectDebitsService } from "./services/v1/direct-debits/direct-debits.service.js";
|
|
13
|
+
import { ElectricityService } from "./services/v1/electricity/electricity.service.js";
|
|
14
|
+
import { GlobalCollectionsService } from "./services/v1/globals/collections.service.js";
|
|
15
|
+
import { GlobalPayoutService } from "./services/v1/globals/payout.service.js";
|
|
16
|
+
import { RequeryService } from "./services/v1/requery/requery.service.js";
|
|
17
|
+
import { TerminalsService } from "./services/v1/terminals/terminals.service.js";
|
|
18
|
+
import { TransactionsService } from "./services/v1/transactions/transactions.service.js";
|
|
19
|
+
import { VirtualAccountsService } from "./services/v1/virtual-accounts/virtual-accounts.service.js";
|
|
20
|
+
import { WebhooksService } from "./services/v1/webhooks/webhooks.service.js";
|
|
21
|
+
import { AirtimeV2Service } from "./services/v2/airtime/airtime.service.js";
|
|
22
|
+
import { BettingV2Service } from "./services/v2/betting/betting.service.js";
|
|
23
|
+
import { CableV2Service } from "./services/v2/cable/cable.service.js";
|
|
24
|
+
import { DataV2Service } from "./services/v2/data/data.service.js";
|
|
25
|
+
import { ElectricityV2Service } from "./services/v2/electricity/electricity.service.js";
|
|
26
|
+
import { TransfersService } from "./services/v2/transfers/transfers.service.js";
|
|
27
|
+
/**
|
|
28
|
+
* The Nomba SDK client. Exposes one property per product (`accounts`, `transfers`, `electricity`, ...),
|
|
29
|
+
* each backed by the shared, authenticated HTTP transport.
|
|
30
|
+
*/
|
|
31
|
+
export class Nomba {
|
|
32
|
+
accounts;
|
|
33
|
+
virtualAccounts;
|
|
34
|
+
checkout;
|
|
35
|
+
charge;
|
|
36
|
+
transfers;
|
|
37
|
+
requery;
|
|
38
|
+
directDebits;
|
|
39
|
+
transactions;
|
|
40
|
+
terminals;
|
|
41
|
+
electricity;
|
|
42
|
+
cable;
|
|
43
|
+
betting;
|
|
44
|
+
airtime;
|
|
45
|
+
data;
|
|
46
|
+
// v1 bill validation services
|
|
47
|
+
billElectricity;
|
|
48
|
+
billCable;
|
|
49
|
+
billBetting;
|
|
50
|
+
billData;
|
|
51
|
+
globalCollections;
|
|
52
|
+
globalPayout;
|
|
53
|
+
webhooks;
|
|
54
|
+
#http;
|
|
55
|
+
/**
|
|
56
|
+
* @param options Client credentials and transport configuration.
|
|
57
|
+
* @param http Replace the transport, e.g. with a fake in tests. Defaults to the real `HttpClient`.
|
|
58
|
+
*/
|
|
59
|
+
constructor(options, http = new HttpClient(options)) {
|
|
60
|
+
this.#http = http;
|
|
61
|
+
this.accounts = new AccountsService(http);
|
|
62
|
+
this.virtualAccounts = new VirtualAccountsService(http);
|
|
63
|
+
this.checkout = new CheckoutService(http);
|
|
64
|
+
this.charge = new ChargeService(http);
|
|
65
|
+
this.transfers = new TransfersService(http);
|
|
66
|
+
this.requery = new RequeryService(http);
|
|
67
|
+
this.directDebits = new DirectDebitsService(http);
|
|
68
|
+
this.transactions = new TransactionsService(http);
|
|
69
|
+
this.terminals = new TerminalsService(http);
|
|
70
|
+
// Electricity, cable, betting, airtime and data use v2 endpoints for payments
|
|
71
|
+
this.electricity = new ElectricityV2Service(http);
|
|
72
|
+
this.cable = new CableV2Service(http);
|
|
73
|
+
this.betting = new BettingV2Service(http);
|
|
74
|
+
this.airtime = new AirtimeV2Service(http);
|
|
75
|
+
this.data = new DataV2Service(http);
|
|
76
|
+
// v1 bill validation services (provider lists, lookups, plan fetching)
|
|
77
|
+
this.billElectricity = new ElectricityService(http);
|
|
78
|
+
this.billCable = new CableService(http);
|
|
79
|
+
this.billBetting = new BettingService(http);
|
|
80
|
+
this.billData = new DataService(http);
|
|
81
|
+
this.globalCollections = new GlobalCollectionsService(http);
|
|
82
|
+
this.globalPayout = new GlobalPayoutService(http);
|
|
83
|
+
this.webhooks = new WebhooksService(http);
|
|
84
|
+
}
|
|
85
|
+
/** `"production"` or `"sandbox"`, as passed to the constructor (defaults to `"production"`). */
|
|
86
|
+
get environment() {
|
|
87
|
+
return this.#http.environment;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* `POST /v1/auth/token/issue`. Gets a new access token. Called for you automatically on first use,
|
|
91
|
+
* so you normally never need this directly.
|
|
92
|
+
* @returns The issued token data.
|
|
93
|
+
* @throws {NombaError} The credentials were rejected.
|
|
94
|
+
*/
|
|
95
|
+
issueToken() {
|
|
96
|
+
return this.#http.issueToken();
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* `POST /v1/auth/token/refresh`. Refreshes the stored token. Called for you automatically 5 minutes
|
|
100
|
+
* before expiry, so you normally never need this directly.
|
|
101
|
+
* @returns The refreshed token data.
|
|
102
|
+
* @throws {Error} No token has been issued yet.
|
|
103
|
+
* @throws {NombaError} The refresh token was rejected.
|
|
104
|
+
*/
|
|
105
|
+
refreshToken() {
|
|
106
|
+
return this.#http.refreshToken();
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* `POST /v1/auth/token/revoke`. Ends the session, e.g. on shutdown. A no-op if no token is held.
|
|
110
|
+
* @throws {NombaError} Nomba rejected the revoke call.
|
|
111
|
+
*/
|
|
112
|
+
revokeToken() {
|
|
113
|
+
return this.#http.revokeToken();
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Makes an authenticated call to any Nomba endpoint, including ones this SDK has no dedicated method
|
|
117
|
+
* for. Issues or refreshes the token as needed.
|
|
118
|
+
* @param method The HTTP method.
|
|
119
|
+
* @param path The endpoint path, starting with `/` (e.g. `/v1/accounts/parent`).
|
|
120
|
+
* @param options Query params, request body, idempotency key and related per-call overrides.
|
|
121
|
+
* @returns The response body's `data` field.
|
|
122
|
+
* @throws {TokenError} Getting or refreshing the access token failed; the request was never sent.
|
|
123
|
+
* @throws {NombaError} A non-2xx response, or a 2xx whose body `code` is not one of `options.okCodes`.
|
|
124
|
+
* @throws {OutcomeUnknownError} A mutating call failed in a way that does not say whether it was
|
|
125
|
+
* processed (timeout, network error, 5xx, or a 409); check its status before retrying.
|
|
126
|
+
*/
|
|
127
|
+
request(method, path, options) {
|
|
128
|
+
return this.#http.request(method, path, options);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module nomba/services/http
|
|
3
|
+
* @description Authenticated HTTP transport: token lifecycle, retries, response envelope
|
|
4
|
+
*/
|
|
5
|
+
import type { IHttpClient } from "../../interfaces/http/IHttpClient.js";
|
|
6
|
+
import { type TokenData } from "../../lib/token-store.js";
|
|
7
|
+
import type { Environment, HttpMethod, HttpRequestOptions, NombaOptions } from "../../types/common/common.types.js";
|
|
8
|
+
import type { OutcomeEvent } from "../../types/common/outcome.types.js";
|
|
9
|
+
/**
|
|
10
|
+
* Authenticated HTTP transport for the Nomba API: owns the token lifecycle (issue, refresh, revoke,
|
|
11
|
+
* sharing via `TokenStore`) and the retry/idempotency rules for `request`.
|
|
12
|
+
*/
|
|
13
|
+
export declare class HttpClient implements IHttpClient {
|
|
14
|
+
#private;
|
|
15
|
+
readonly environment: Environment;
|
|
16
|
+
constructor(options: NombaOptions);
|
|
17
|
+
/**
|
|
18
|
+
* `POST /v1/auth/token/issue`.
|
|
19
|
+
* @returns The issued token data, saved to the configured `TokenStore`.
|
|
20
|
+
* @throws {NombaError} The credentials were rejected.
|
|
21
|
+
*/
|
|
22
|
+
issueToken(): Promise<TokenData>;
|
|
23
|
+
/**
|
|
24
|
+
* `POST /v1/auth/token/refresh`.
|
|
25
|
+
* @returns The refreshed token data, saved to the configured `TokenStore`.
|
|
26
|
+
* @throws {Error} No token is held yet; call `issueToken()` first.
|
|
27
|
+
* @throws {NombaError} The refresh token was rejected.
|
|
28
|
+
*/
|
|
29
|
+
refreshToken(): Promise<TokenData>;
|
|
30
|
+
/**
|
|
31
|
+
* `POST /v1/auth/token/revoke`. A no-op if no token is held.
|
|
32
|
+
* @throws {NombaError} Nomba rejected the revoke call.
|
|
33
|
+
*/
|
|
34
|
+
revokeToken(): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Authenticated call. Issues or refreshes the token as needed.
|
|
37
|
+
* Every non-GET call carries an idempotency key, so failures that leave the outcome unknown are retried
|
|
38
|
+
* safely, and surface as `OutcomeUnknownError` once retries run out.
|
|
39
|
+
* @param method The HTTP method.
|
|
40
|
+
* @param path The endpoint path, starting with `/`.
|
|
41
|
+
* @param options.body The JSON request body.
|
|
42
|
+
* @param options.query Query string parameters; entries with a `undefined` value are omitted.
|
|
43
|
+
* @param options.okCodes Body codes that are not errors. Defaults to `["00"]`.
|
|
44
|
+
* @param options.idempotencyKey Tracked in `OutcomeUnknownError` for non-GET calls; this generic
|
|
45
|
+
* transport does not send it to Nomba. Put the endpoint's actual idempotency field (for example
|
|
46
|
+
* `merchantTxRef`) in `options.body`. A random UUID is generated if omitted.
|
|
47
|
+
* @param options.codeField The response field holding the result code. Defaults to `"code"`.
|
|
48
|
+
* @param options.descriptionField The response field holding the error description. Defaults to
|
|
49
|
+
* `"description"`.
|
|
50
|
+
* @param options.envelope When true, resolves to `{ code, data }` instead of just `data`.
|
|
51
|
+
* @returns The response body's `data` field (or `{ code, data }` with `envelope: true`).
|
|
52
|
+
* @throws {TypeError} `path` does not start with `/`.
|
|
53
|
+
* @throws {TokenError} Getting or refreshing the access token failed; the request was never sent.
|
|
54
|
+
* @throws {NombaError} A non-2xx response, or a 2xx whose body code is not in `okCodes`.
|
|
55
|
+
* @throws {OutcomeUnknownError} A non-GET call failed in a way that does not say whether it was
|
|
56
|
+
* processed (timeout, network error, 5xx, or a 409); check its status before retrying.
|
|
57
|
+
*/
|
|
58
|
+
request<T>(method: HttpMethod, path: string, { body, query, okCodes, idempotencyKey, codeField, descriptionField, envelope, }?: HttpRequestOptions): Promise<T>;
|
|
59
|
+
/** Invokes the configured `onOutcome` hook, if any, swallowing any error it throws. */
|
|
60
|
+
reportOutcome(event: OutcomeEvent): void;
|
|
61
|
+
}
|