@nomba/node-sdk 0.1.0 → 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/README.md +31 -4
- package/dist/interfaces/v1/accounts/IAccountsService.d.ts +46 -8
- package/dist/interfaces/v1/betting/IBettingService.d.ts +11 -2
- package/dist/interfaces/v1/cable/ICableService.d.ts +12 -2
- package/dist/interfaces/v1/charge/IChargeService.d.ts +80 -19
- package/dist/interfaces/v1/checkout/ICheckoutService.d.ts +64 -15
- package/dist/interfaces/v1/data/IDataService.d.ts +6 -1
- package/dist/interfaces/v1/direct-debits/IDirectDebitsService.d.ts +37 -14
- package/dist/interfaces/v1/electricity/IElectricityService.d.ts +11 -2
- package/dist/interfaces/v1/globals/collections/IGlobalCollectionsService.d.ts +20 -5
- package/dist/interfaces/v1/globals/payouts/IGlobalPayoutService.d.ts +74 -13
- package/dist/interfaces/v1/requery/IRequeryService.d.ts +19 -5
- package/dist/interfaces/v1/terminals/ITerminalsService.d.ts +43 -10
- package/dist/interfaces/v1/transactions/ITransactionsService.d.ts +71 -12
- package/dist/interfaces/v1/virtual-accounts/IVirtualAccountsService.d.ts +50 -12
- package/dist/interfaces/v1/webhooks/IWebhooksService.d.ts +29 -10
- package/dist/interfaces/v2/airtime/IAirtimeV2Service.d.ts +21 -2
- package/dist/interfaces/v2/betting/IBettingV2Service.d.ts +21 -2
- package/dist/interfaces/v2/cable/ICableV2Service.d.ts +21 -2
- package/dist/interfaces/v2/data/IDataV2Service.d.ts +21 -2
- package/dist/interfaces/v2/electricity/IElectricityV2Service.d.ts +22 -2
- package/dist/interfaces/v2/transfers/ITransfersService.d.ts +57 -6
- package/dist/lib/outcome.d.ts +24 -5
- package/dist/lib/outcome.js +24 -5
- package/dist/lib/sdk-version.generated.d.ts +1 -1
- package/dist/lib/sdk-version.generated.js +1 -1
- package/dist/nomba.d.ts +38 -5
- package/dist/nomba.js +38 -5
- package/dist/services/http/http-client.service.d.ts +40 -6
- package/dist/services/http/http-client.service.js +40 -6
- package/dist/services/v1/accounts/accounts.service.d.ts +46 -8
- package/dist/services/v1/accounts/accounts.service.js +46 -8
- package/dist/services/v1/betting/betting.service.d.ts +11 -2
- package/dist/services/v1/betting/betting.service.js +11 -2
- package/dist/services/v1/cable/cable.service.d.ts +12 -2
- package/dist/services/v1/cable/cable.service.js +12 -2
- package/dist/services/v1/charge/charge.service.d.ts +80 -19
- package/dist/services/v1/charge/charge.service.js +88 -26
- package/dist/services/v1/checkout/checkout.service.d.ts +63 -15
- package/dist/services/v1/checkout/checkout.service.js +70 -24
- package/dist/services/v1/data/data.service.d.ts +7 -1
- package/dist/services/v1/data/data.service.js +7 -1
- package/dist/services/v1/direct-debits/direct-debits.service.d.ts +38 -14
- package/dist/services/v1/direct-debits/direct-debits.service.js +39 -17
- package/dist/services/v1/electricity/electricity.service.d.ts +12 -2
- package/dist/services/v1/electricity/electricity.service.js +12 -2
- package/dist/services/v1/globals/collections.service.d.ts +21 -5
- package/dist/services/v1/globals/collections.service.js +22 -5
- package/dist/services/v1/globals/payout.service.d.ts +73 -13
- package/dist/services/v1/globals/payout.service.js +74 -15
- package/dist/services/v1/terminals/terminals.service.d.ts +5 -5
- package/dist/services/v1/terminals/terminals.service.js +7 -18
- package/dist/services/v1/virtual-accounts/virtual-accounts.service.d.ts +4 -5
- package/dist/services/v1/virtual-accounts/virtual-accounts.service.js +7 -8
- package/dist/services/v1/webhooks/webhooks.service.d.ts +3 -4
- package/dist/services/v1/webhooks/webhooks.service.js +7 -8
- package/dist/services/v2/airtime/airtime.service.d.ts +26 -2
- package/dist/services/v2/airtime/airtime.service.js +27 -7
- package/dist/services/v2/betting/betting.service.d.ts +27 -3
- package/dist/services/v2/betting/betting.service.js +28 -8
- package/dist/services/v2/cable/cable.service.d.ts +27 -3
- package/dist/services/v2/cable/cable.service.js +28 -8
- package/dist/services/v2/data/data.service.d.ts +26 -2
- package/dist/services/v2/data/data.service.js +27 -7
- package/dist/services/v2/electricity/electricity.service.d.ts +28 -3
- package/dist/services/v2/electricity/electricity.service.js +29 -8
- package/dist/services/v2/transfers/transfers.service.d.ts +51 -6
- package/dist/services/v2/transfers/transfers.service.js +55 -25
- package/dist/types/common/common.types.d.ts +9 -13
- package/package.json +1 -1
package/dist/lib/outcome.js
CHANGED
|
@@ -28,13 +28,32 @@ const defaultStatusOf = (data) => {
|
|
|
28
28
|
return typeof s === "string" ? s : undefined;
|
|
29
29
|
};
|
|
30
30
|
/**
|
|
31
|
-
* Makes one money-moving call and settles it into exactly one outcome.
|
|
31
|
+
* Makes one money-moving call and settles it into exactly one outcome: success, pending, or failed.
|
|
32
|
+
*
|
|
32
33
|
* With a closure for that outcome, resolves to what the closure returns. Without one:
|
|
33
|
-
* success resolves `data
|
|
34
|
-
*
|
|
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.
|
|
35
54
|
*/
|
|
36
|
-
export async function settle(http, method, path, request, table, options = {}) {
|
|
37
|
-
const { onSuccess, onPending, onFailed
|
|
55
|
+
export async function settle(http, method, path, request, table, idempotencyKey, options = {}) {
|
|
56
|
+
const { onSuccess, onPending, onFailed } = options;
|
|
38
57
|
const report = (outcome, code, status, key = idempotencyKey) => http.reportOutcome({
|
|
39
58
|
method,
|
|
40
59
|
path,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "0.
|
|
1
|
+
export declare const SDK_VERSION = "0.3.0";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "0.
|
|
1
|
+
export const SDK_VERSION = "0.3.0";
|
package/dist/nomba.d.ts
CHANGED
|
@@ -26,6 +26,10 @@ import type { IElectricityV2Service } from "./interfaces/v2/electricity/index.js
|
|
|
26
26
|
import type { ITransfersService } from "./interfaces/v2/transfers/index.js";
|
|
27
27
|
import type { TokenData } from "./lib/token-store.js";
|
|
28
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
|
+
*/
|
|
29
33
|
export declare class Nomba {
|
|
30
34
|
#private;
|
|
31
35
|
readonly accounts: IAccountsService;
|
|
@@ -49,15 +53,44 @@ export declare class Nomba {
|
|
|
49
53
|
readonly globalCollections: IGlobalCollectionsService;
|
|
50
54
|
readonly globalPayout: IGlobalPayoutService;
|
|
51
55
|
readonly webhooks: IWebhooksService;
|
|
52
|
-
/**
|
|
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
|
+
*/
|
|
53
60
|
constructor(options: NombaOptions, http?: IHttpClient);
|
|
61
|
+
/** `"production"` or `"sandbox"`, as passed to the constructor (defaults to `"production"`). */
|
|
54
62
|
get environment(): Environment;
|
|
55
|
-
/**
|
|
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
|
+
*/
|
|
56
69
|
issueToken(): Promise<TokenData>;
|
|
57
|
-
/**
|
|
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
|
+
*/
|
|
58
77
|
refreshToken(): Promise<TokenData>;
|
|
59
|
-
/**
|
|
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
|
+
*/
|
|
60
82
|
revokeToken(): Promise<void>;
|
|
61
|
-
/**
|
|
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
|
+
*/
|
|
62
95
|
request<T>(method: HttpMethod, path: string, options?: HttpRequestOptions): Promise<T>;
|
|
63
96
|
}
|
package/dist/nomba.js
CHANGED
|
@@ -24,6 +24,10 @@ import { CableV2Service } from "./services/v2/cable/cable.service.js";
|
|
|
24
24
|
import { DataV2Service } from "./services/v2/data/data.service.js";
|
|
25
25
|
import { ElectricityV2Service } from "./services/v2/electricity/electricity.service.js";
|
|
26
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
|
+
*/
|
|
27
31
|
export class Nomba {
|
|
28
32
|
accounts;
|
|
29
33
|
virtualAccounts;
|
|
@@ -48,7 +52,10 @@ export class Nomba {
|
|
|
48
52
|
globalPayout;
|
|
49
53
|
webhooks;
|
|
50
54
|
#http;
|
|
51
|
-
/**
|
|
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
|
+
*/
|
|
52
59
|
constructor(options, http = new HttpClient(options)) {
|
|
53
60
|
this.#http = http;
|
|
54
61
|
this.accounts = new AccountsService(http);
|
|
@@ -75,22 +82,48 @@ export class Nomba {
|
|
|
75
82
|
this.globalPayout = new GlobalPayoutService(http);
|
|
76
83
|
this.webhooks = new WebhooksService(http);
|
|
77
84
|
}
|
|
85
|
+
/** `"production"` or `"sandbox"`, as passed to the constructor (defaults to `"production"`). */
|
|
78
86
|
get environment() {
|
|
79
87
|
return this.#http.environment;
|
|
80
88
|
}
|
|
81
|
-
/**
|
|
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
|
+
*/
|
|
82
95
|
issueToken() {
|
|
83
96
|
return this.#http.issueToken();
|
|
84
97
|
}
|
|
85
|
-
/**
|
|
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
|
+
*/
|
|
86
105
|
refreshToken() {
|
|
87
106
|
return this.#http.refreshToken();
|
|
88
107
|
}
|
|
89
|
-
/**
|
|
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
|
+
*/
|
|
90
112
|
revokeToken() {
|
|
91
113
|
return this.#http.revokeToken();
|
|
92
114
|
}
|
|
93
|
-
/**
|
|
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
|
+
*/
|
|
94
127
|
request(method, path, options) {
|
|
95
128
|
return this.#http.request(method, path, options);
|
|
96
129
|
}
|
|
@@ -6,22 +6,56 @@ import type { IHttpClient } from "../../interfaces/http/IHttpClient.js";
|
|
|
6
6
|
import { type TokenData } from "../../lib/token-store.js";
|
|
7
7
|
import type { Environment, HttpMethod, HttpRequestOptions, NombaOptions } from "../../types/common/common.types.js";
|
|
8
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
|
+
*/
|
|
9
13
|
export declare class HttpClient implements IHttpClient {
|
|
10
14
|
#private;
|
|
11
15
|
readonly environment: Environment;
|
|
12
16
|
constructor(options: NombaOptions);
|
|
13
|
-
/**
|
|
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
|
+
*/
|
|
14
22
|
issueToken(): Promise<TokenData>;
|
|
15
|
-
/**
|
|
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
|
+
*/
|
|
16
29
|
refreshToken(): Promise<TokenData>;
|
|
17
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* `POST /v1/auth/token/revoke`. A no-op if no token is held.
|
|
32
|
+
* @throws {NombaError} Nomba rejected the revoke call.
|
|
33
|
+
*/
|
|
18
34
|
revokeToken(): Promise<void>;
|
|
19
35
|
/**
|
|
20
|
-
* Authenticated call. Issues or refreshes the token as needed
|
|
21
|
-
* `okCodes` lists the body codes that are not errors; the default is ["00"].
|
|
36
|
+
* Authenticated call. Issues or refreshes the token as needed.
|
|
22
37
|
* Every non-GET call carries an idempotency key, so failures that leave the outcome unknown are retried
|
|
23
|
-
* safely, and surface as OutcomeUnknownError once retries run out.
|
|
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.
|
|
24
57
|
*/
|
|
25
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. */
|
|
26
60
|
reportOutcome(event: OutcomeEvent): void;
|
|
27
61
|
}
|
|
@@ -15,6 +15,10 @@ const BASE_URLS = {
|
|
|
15
15
|
const REFRESH_MARGIN_MS = 5 * 60_000;
|
|
16
16
|
// A failed store.set() is retried this many times (100ms, 200ms apart) before giving up on the shared copy.
|
|
17
17
|
const SET_RETRIES = 2;
|
|
18
|
+
/**
|
|
19
|
+
* Authenticated HTTP transport for the Nomba API: owns the token lifecycle (issue, refresh, revoke,
|
|
20
|
+
* sharing via `TokenStore`) and the retry/idempotency rules for `request`.
|
|
21
|
+
*/
|
|
18
22
|
export class HttpClient {
|
|
19
23
|
environment;
|
|
20
24
|
#options;
|
|
@@ -34,11 +38,20 @@ export class HttpClient {
|
|
|
34
38
|
this.environment = env;
|
|
35
39
|
this.#baseUrl = BASE_URLS[env];
|
|
36
40
|
}
|
|
37
|
-
/**
|
|
41
|
+
/**
|
|
42
|
+
* `POST /v1/auth/token/issue`.
|
|
43
|
+
* @returns The issued token data, saved to the configured `TokenStore`.
|
|
44
|
+
* @throws {NombaError} The credentials were rejected.
|
|
45
|
+
*/
|
|
38
46
|
issueToken() {
|
|
39
47
|
return this.#locked(() => this.#issue());
|
|
40
48
|
}
|
|
41
|
-
/**
|
|
49
|
+
/**
|
|
50
|
+
* `POST /v1/auth/token/refresh`.
|
|
51
|
+
* @returns The refreshed token data, saved to the configured `TokenStore`.
|
|
52
|
+
* @throws {Error} No token is held yet; call `issueToken()` first.
|
|
53
|
+
* @throws {NombaError} The refresh token was rejected.
|
|
54
|
+
*/
|
|
42
55
|
refreshToken() {
|
|
43
56
|
return this.#locked(async () => {
|
|
44
57
|
const t = await this.#read();
|
|
@@ -47,7 +60,10 @@ export class HttpClient {
|
|
|
47
60
|
return this.#refresh(t);
|
|
48
61
|
});
|
|
49
62
|
}
|
|
50
|
-
/**
|
|
63
|
+
/**
|
|
64
|
+
* `POST /v1/auth/token/revoke`. A no-op if no token is held.
|
|
65
|
+
* @throws {NombaError} Nomba rejected the revoke call.
|
|
66
|
+
*/
|
|
51
67
|
revokeToken() {
|
|
52
68
|
return this.#locked(async () => {
|
|
53
69
|
const t = await this.#read();
|
|
@@ -70,10 +86,27 @@ export class HttpClient {
|
|
|
70
86
|
});
|
|
71
87
|
}
|
|
72
88
|
/**
|
|
73
|
-
* Authenticated call. Issues or refreshes the token as needed
|
|
74
|
-
* `okCodes` lists the body codes that are not errors; the default is ["00"].
|
|
89
|
+
* Authenticated call. Issues or refreshes the token as needed.
|
|
75
90
|
* Every non-GET call carries an idempotency key, so failures that leave the outcome unknown are retried
|
|
76
|
-
* safely, and surface as OutcomeUnknownError once retries run out.
|
|
91
|
+
* safely, and surface as `OutcomeUnknownError` once retries run out.
|
|
92
|
+
* @param method The HTTP method.
|
|
93
|
+
* @param path The endpoint path, starting with `/`.
|
|
94
|
+
* @param options.body The JSON request body.
|
|
95
|
+
* @param options.query Query string parameters; entries with a `undefined` value are omitted.
|
|
96
|
+
* @param options.okCodes Body codes that are not errors. Defaults to `["00"]`.
|
|
97
|
+
* @param options.idempotencyKey Tracked in `OutcomeUnknownError` for non-GET calls; this generic
|
|
98
|
+
* transport does not send it to Nomba. Put the endpoint's actual idempotency field (for example
|
|
99
|
+
* `merchantTxRef`) in `options.body`. A random UUID is generated if omitted.
|
|
100
|
+
* @param options.codeField The response field holding the result code. Defaults to `"code"`.
|
|
101
|
+
* @param options.descriptionField The response field holding the error description. Defaults to
|
|
102
|
+
* `"description"`.
|
|
103
|
+
* @param options.envelope When true, resolves to `{ code, data }` instead of just `data`.
|
|
104
|
+
* @returns The response body's `data` field (or `{ code, data }` with `envelope: true`).
|
|
105
|
+
* @throws {TypeError} `path` does not start with `/`.
|
|
106
|
+
* @throws {TokenError} Getting or refreshing the access token failed; the request was never sent.
|
|
107
|
+
* @throws {NombaError} A non-2xx response, or a 2xx whose body code is not in `okCodes`.
|
|
108
|
+
* @throws {OutcomeUnknownError} A non-GET call failed in a way that does not say whether it was
|
|
109
|
+
* processed (timeout, network error, 5xx, or a 409); check its status before retrying.
|
|
77
110
|
*/
|
|
78
111
|
async request(method, path, { body, query, okCodes, idempotencyKey, codeField, descriptionField, envelope, } = {}) {
|
|
79
112
|
// The URL is base + path, so a path not starting with "/" (".evil.com", "@evil.com") would change the host
|
|
@@ -113,6 +146,7 @@ export class HttpClient {
|
|
|
113
146
|
});
|
|
114
147
|
}
|
|
115
148
|
}
|
|
149
|
+
/** Invokes the configured `onOutcome` hook, if any, swallowing any error it throws. */
|
|
116
150
|
reportOutcome(event) {
|
|
117
151
|
this.#hook(() => this.#options.onOutcome?.(event));
|
|
118
152
|
}
|
|
@@ -19,20 +19,58 @@ import type { Terminal, TerminalList, TerminalListParams } from "../../../types/
|
|
|
19
19
|
export declare class AccountsService implements IAccountsService {
|
|
20
20
|
private readonly http;
|
|
21
21
|
constructor(http: IHttpClient);
|
|
22
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* `GET /v1/accounts/parent`.
|
|
24
|
+
* @returns The parent account's details.
|
|
25
|
+
* @throws {NombaError} The call failed.
|
|
26
|
+
*/
|
|
23
27
|
getParentAccount(): Promise<AccountDetails>;
|
|
24
|
-
/**
|
|
28
|
+
/**
|
|
29
|
+
* `GET /v1/accounts/balance`.
|
|
30
|
+
* @returns The parent account's balance.
|
|
31
|
+
* @throws {NombaError} The call failed.
|
|
32
|
+
*/
|
|
25
33
|
getParentBalance(): Promise<AccountBalance>;
|
|
26
|
-
/**
|
|
34
|
+
/**
|
|
35
|
+
* `GET /v1/accounts/sub-account-details`.
|
|
36
|
+
* @param lookup Which sub account to fetch, by account ID or account number.
|
|
37
|
+
* @returns The sub account's details.
|
|
38
|
+
* @throws {NombaError} The call failed, e.g. no sub account matches `lookup`.
|
|
39
|
+
*/
|
|
27
40
|
getSubAccount(lookup?: SubAccountLookup): Promise<AccountDetails>;
|
|
28
|
-
/**
|
|
41
|
+
/**
|
|
42
|
+
* `GET /v1/accounts/{subAccountId}/balance`.
|
|
43
|
+
* @param subAccountId The sub account's ID.
|
|
44
|
+
* @returns The sub account's balance.
|
|
45
|
+
* @throws {NombaError} The call failed, e.g. `subAccountId` does not exist.
|
|
46
|
+
*/
|
|
29
47
|
getSubAccountBalance(subAccountId: string): Promise<AccountBalance>;
|
|
30
|
-
/**
|
|
48
|
+
/**
|
|
49
|
+
* `GET /v1/accounts/terminals`.
|
|
50
|
+
* @param params Pagination (`cursor`, `size`) and other list filters.
|
|
51
|
+
* @returns One page of the parent account's terminals.
|
|
52
|
+
* @throws {NombaError} The call failed.
|
|
53
|
+
*/
|
|
31
54
|
listParentTerminals(params?: TerminalListParams): Promise<TerminalList>;
|
|
32
|
-
/**
|
|
55
|
+
/**
|
|
56
|
+
* `GET /v1/accounts/{accountId}/terminals`.
|
|
57
|
+
* @param accountId The sub account's ID.
|
|
58
|
+
* @param params Pagination (`cursor`, `size`) and other list filters.
|
|
59
|
+
* @returns One page of the sub account's terminals.
|
|
60
|
+
* @throws {NombaError} The call failed, e.g. `accountId` does not exist.
|
|
61
|
+
*/
|
|
33
62
|
listSubAccountTerminals(accountId: string, params?: TerminalListParams): Promise<TerminalList>;
|
|
34
|
-
/**
|
|
63
|
+
/**
|
|
64
|
+
* Every terminal of the parent account, across all pages. Starts at `params.cursor` if given.
|
|
65
|
+
* @param params Starting cursor and other list filters.
|
|
66
|
+
* @throws {NombaError} A page request failed.
|
|
67
|
+
*/
|
|
35
68
|
iterateParentTerminals(params?: TerminalListParams): AsyncGenerator<Terminal>;
|
|
36
|
-
/**
|
|
69
|
+
/**
|
|
70
|
+
* Every terminal of a sub account, across all pages. Starts at `params.cursor` if given.
|
|
71
|
+
* @param accountId The sub account's ID.
|
|
72
|
+
* @param params Starting cursor and other list filters.
|
|
73
|
+
* @throws {NombaError} A page request failed, e.g. `accountId` does not exist.
|
|
74
|
+
*/
|
|
37
75
|
iterateSubAccountTerminals(accountId: string, params?: TerminalListParams): AsyncGenerator<Terminal>;
|
|
38
76
|
}
|
|
@@ -19,39 +19,77 @@ export class AccountsService {
|
|
|
19
19
|
constructor(http) {
|
|
20
20
|
this.http = http;
|
|
21
21
|
}
|
|
22
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* `GET /v1/accounts/parent`.
|
|
24
|
+
* @returns The parent account's details.
|
|
25
|
+
* @throws {NombaError} The call failed.
|
|
26
|
+
*/
|
|
23
27
|
getParentAccount() {
|
|
24
28
|
return this.http.request("GET", "/v1/accounts/parent");
|
|
25
29
|
}
|
|
26
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* `GET /v1/accounts/balance`.
|
|
32
|
+
* @returns The parent account's balance.
|
|
33
|
+
* @throws {NombaError} The call failed.
|
|
34
|
+
*/
|
|
27
35
|
getParentBalance() {
|
|
28
36
|
return this.http.request("GET", "/v1/accounts/balance");
|
|
29
37
|
}
|
|
30
|
-
/**
|
|
38
|
+
/**
|
|
39
|
+
* `GET /v1/accounts/sub-account-details`.
|
|
40
|
+
* @param lookup Which sub account to fetch, by account ID or account number.
|
|
41
|
+
* @returns The sub account's details.
|
|
42
|
+
* @throws {NombaError} The call failed, e.g. no sub account matches `lookup`.
|
|
43
|
+
*/
|
|
31
44
|
getSubAccount(lookup = {}) {
|
|
32
45
|
return this.http.request("GET", "/v1/accounts/sub-account-details", {
|
|
33
46
|
query: lookup,
|
|
34
47
|
});
|
|
35
48
|
}
|
|
36
|
-
/**
|
|
49
|
+
/**
|
|
50
|
+
* `GET /v1/accounts/{subAccountId}/balance`.
|
|
51
|
+
* @param subAccountId The sub account's ID.
|
|
52
|
+
* @returns The sub account's balance.
|
|
53
|
+
* @throws {NombaError} The call failed, e.g. `subAccountId` does not exist.
|
|
54
|
+
*/
|
|
37
55
|
async getSubAccountBalance(subAccountId) {
|
|
38
56
|
return this.http.request("GET", `/v1/accounts/${pathId(subAccountId)}/balance`);
|
|
39
57
|
}
|
|
40
|
-
/**
|
|
58
|
+
/**
|
|
59
|
+
* `GET /v1/accounts/terminals`.
|
|
60
|
+
* @param params Pagination (`cursor`, `size`) and other list filters.
|
|
61
|
+
* @returns One page of the parent account's terminals.
|
|
62
|
+
* @throws {NombaError} The call failed.
|
|
63
|
+
*/
|
|
41
64
|
listParentTerminals(params = {}) {
|
|
42
65
|
return this.http.request("GET", "/v1/accounts/terminals", {
|
|
43
66
|
query: pageQuery(params),
|
|
44
67
|
});
|
|
45
68
|
}
|
|
46
|
-
/**
|
|
69
|
+
/**
|
|
70
|
+
* `GET /v1/accounts/{accountId}/terminals`.
|
|
71
|
+
* @param accountId The sub account's ID.
|
|
72
|
+
* @param params Pagination (`cursor`, `size`) and other list filters.
|
|
73
|
+
* @returns One page of the sub account's terminals.
|
|
74
|
+
* @throws {NombaError} The call failed, e.g. `accountId` does not exist.
|
|
75
|
+
*/
|
|
47
76
|
async listSubAccountTerminals(accountId, params = {}) {
|
|
48
77
|
return this.http.request("GET", `/v1/accounts/${pathId(accountId)}/terminals`, { query: pageQuery(params) });
|
|
49
78
|
}
|
|
50
|
-
/**
|
|
79
|
+
/**
|
|
80
|
+
* Every terminal of the parent account, across all pages. Starts at `params.cursor` if given.
|
|
81
|
+
* @param params Starting cursor and other list filters.
|
|
82
|
+
* @throws {NombaError} A page request failed.
|
|
83
|
+
*/
|
|
51
84
|
iterateParentTerminals(params = {}) {
|
|
52
85
|
return paginate((cursor) => this.listParentTerminals(cursor ? { ...params, cursor } : params));
|
|
53
86
|
}
|
|
54
|
-
/**
|
|
87
|
+
/**
|
|
88
|
+
* Every terminal of a sub account, across all pages. Starts at `params.cursor` if given.
|
|
89
|
+
* @param accountId The sub account's ID.
|
|
90
|
+
* @param params Starting cursor and other list filters.
|
|
91
|
+
* @throws {NombaError} A page request failed, e.g. `accountId` does not exist.
|
|
92
|
+
*/
|
|
55
93
|
iterateSubAccountTerminals(accountId, params = {}) {
|
|
56
94
|
return paginate((cursor) => this.listSubAccountTerminals(accountId, cursor ? { ...params, cursor } : params));
|
|
57
95
|
}
|
|
@@ -9,8 +9,17 @@ import type { BettingCustomerLookupParams, BettingCustomerLookupResult, BettingP
|
|
|
9
9
|
export declare class BettingService implements IBettingService {
|
|
10
10
|
private readonly http;
|
|
11
11
|
constructor(http: IHttpClient);
|
|
12
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* `GET /v1/bill/betting/providers`.
|
|
14
|
+
* @returns The supported betting providers.
|
|
15
|
+
* @throws {NombaError} The call failed.
|
|
16
|
+
*/
|
|
13
17
|
getBettingProviders(): Promise<BettingProvidersResult>;
|
|
14
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* `GET /v1/bill/betting/lookup`. Validates a customer ID and returns the account name.
|
|
20
|
+
* @param params The provider and customer ID to look up.
|
|
21
|
+
* @returns The customer's account name.
|
|
22
|
+
* @throws {NombaError} The call failed, e.g. the customer ID is invalid.
|
|
23
|
+
*/
|
|
15
24
|
lookupCustomer(params: BettingCustomerLookupParams): Promise<BettingCustomerLookupResult>;
|
|
16
25
|
}
|
|
@@ -8,11 +8,20 @@ export class BettingService {
|
|
|
8
8
|
constructor(http) {
|
|
9
9
|
this.http = http;
|
|
10
10
|
}
|
|
11
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* `GET /v1/bill/betting/providers`.
|
|
13
|
+
* @returns The supported betting providers.
|
|
14
|
+
* @throws {NombaError} The call failed.
|
|
15
|
+
*/
|
|
12
16
|
getBettingProviders() {
|
|
13
17
|
return this.http.request("GET", "/v1/bill/betting/providers");
|
|
14
18
|
}
|
|
15
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* `GET /v1/bill/betting/lookup`. Validates a customer ID and returns the account name.
|
|
21
|
+
* @param params The provider and customer ID to look up.
|
|
22
|
+
* @returns The customer's account name.
|
|
23
|
+
* @throws {NombaError} The call failed, e.g. the customer ID is invalid.
|
|
24
|
+
*/
|
|
16
25
|
lookupCustomer(params) {
|
|
17
26
|
return this.http.request("GET", "/v1/bill/betting/lookup", {
|
|
18
27
|
query: params,
|
|
@@ -9,8 +9,18 @@ import type { CableCustomerLookupParams, CableCustomerLookupResult, CablePlansPa
|
|
|
9
9
|
export declare class CableService implements ICableService {
|
|
10
10
|
private readonly http;
|
|
11
11
|
constructor(http: IHttpClient);
|
|
12
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* `GET /v1/bill/cableTvProduct`.
|
|
14
|
+
* @param params The provider whose plans to fetch.
|
|
15
|
+
* @returns The provider's cable TV plans.
|
|
16
|
+
* @throws {NombaError} The call failed.
|
|
17
|
+
*/
|
|
13
18
|
getCablePlans(params: CablePlansParams): Promise<CablePlansResult>;
|
|
14
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* `GET /v1/bill/cable/lookup`. Validates a smartcard number and returns the account name.
|
|
21
|
+
* @param params The provider and smartcard number to look up.
|
|
22
|
+
* @returns The customer's account name.
|
|
23
|
+
* @throws {NombaError} The call failed, e.g. the smartcard number is invalid.
|
|
24
|
+
*/
|
|
15
25
|
lookupCustomer(params: CableCustomerLookupParams): Promise<CableCustomerLookupResult>;
|
|
16
26
|
}
|
|
@@ -8,13 +8,23 @@ export class CableService {
|
|
|
8
8
|
constructor(http) {
|
|
9
9
|
this.http = http;
|
|
10
10
|
}
|
|
11
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* `GET /v1/bill/cableTvProduct`.
|
|
13
|
+
* @param params The provider whose plans to fetch.
|
|
14
|
+
* @returns The provider's cable TV plans.
|
|
15
|
+
* @throws {NombaError} The call failed.
|
|
16
|
+
*/
|
|
12
17
|
getCablePlans(params) {
|
|
13
18
|
return this.http.request("GET", "/v1/bill/cableTvProduct", {
|
|
14
19
|
query: params,
|
|
15
20
|
});
|
|
16
21
|
}
|
|
17
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* `GET /v1/bill/cable/lookup`. Validates a smartcard number and returns the account name.
|
|
24
|
+
* @param params The provider and smartcard number to look up.
|
|
25
|
+
* @returns The customer's account name.
|
|
26
|
+
* @throws {NombaError} The call failed, e.g. the smartcard number is invalid.
|
|
27
|
+
*/
|
|
18
28
|
lookupCustomer(params) {
|
|
19
29
|
return this.http.request("GET", "/v1/bill/cable/lookup", {
|
|
20
30
|
query: params,
|