@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.
Files changed (70) hide show
  1. package/README.md +31 -4
  2. package/dist/interfaces/v1/accounts/IAccountsService.d.ts +46 -8
  3. package/dist/interfaces/v1/betting/IBettingService.d.ts +11 -2
  4. package/dist/interfaces/v1/cable/ICableService.d.ts +12 -2
  5. package/dist/interfaces/v1/charge/IChargeService.d.ts +80 -19
  6. package/dist/interfaces/v1/checkout/ICheckoutService.d.ts +64 -15
  7. package/dist/interfaces/v1/data/IDataService.d.ts +6 -1
  8. package/dist/interfaces/v1/direct-debits/IDirectDebitsService.d.ts +37 -14
  9. package/dist/interfaces/v1/electricity/IElectricityService.d.ts +11 -2
  10. package/dist/interfaces/v1/globals/collections/IGlobalCollectionsService.d.ts +20 -5
  11. package/dist/interfaces/v1/globals/payouts/IGlobalPayoutService.d.ts +74 -13
  12. package/dist/interfaces/v1/requery/IRequeryService.d.ts +19 -5
  13. package/dist/interfaces/v1/terminals/ITerminalsService.d.ts +43 -10
  14. package/dist/interfaces/v1/transactions/ITransactionsService.d.ts +71 -12
  15. package/dist/interfaces/v1/virtual-accounts/IVirtualAccountsService.d.ts +50 -12
  16. package/dist/interfaces/v1/webhooks/IWebhooksService.d.ts +29 -10
  17. package/dist/interfaces/v2/airtime/IAirtimeV2Service.d.ts +21 -2
  18. package/dist/interfaces/v2/betting/IBettingV2Service.d.ts +21 -2
  19. package/dist/interfaces/v2/cable/ICableV2Service.d.ts +21 -2
  20. package/dist/interfaces/v2/data/IDataV2Service.d.ts +21 -2
  21. package/dist/interfaces/v2/electricity/IElectricityV2Service.d.ts +22 -2
  22. package/dist/interfaces/v2/transfers/ITransfersService.d.ts +57 -6
  23. package/dist/lib/outcome.d.ts +24 -5
  24. package/dist/lib/outcome.js +24 -5
  25. package/dist/lib/sdk-version.generated.d.ts +1 -1
  26. package/dist/lib/sdk-version.generated.js +1 -1
  27. package/dist/nomba.d.ts +38 -5
  28. package/dist/nomba.js +38 -5
  29. package/dist/services/http/http-client.service.d.ts +40 -6
  30. package/dist/services/http/http-client.service.js +40 -6
  31. package/dist/services/v1/accounts/accounts.service.d.ts +46 -8
  32. package/dist/services/v1/accounts/accounts.service.js +46 -8
  33. package/dist/services/v1/betting/betting.service.d.ts +11 -2
  34. package/dist/services/v1/betting/betting.service.js +11 -2
  35. package/dist/services/v1/cable/cable.service.d.ts +12 -2
  36. package/dist/services/v1/cable/cable.service.js +12 -2
  37. package/dist/services/v1/charge/charge.service.d.ts +80 -19
  38. package/dist/services/v1/charge/charge.service.js +88 -26
  39. package/dist/services/v1/checkout/checkout.service.d.ts +63 -15
  40. package/dist/services/v1/checkout/checkout.service.js +70 -24
  41. package/dist/services/v1/data/data.service.d.ts +7 -1
  42. package/dist/services/v1/data/data.service.js +7 -1
  43. package/dist/services/v1/direct-debits/direct-debits.service.d.ts +38 -14
  44. package/dist/services/v1/direct-debits/direct-debits.service.js +39 -17
  45. package/dist/services/v1/electricity/electricity.service.d.ts +12 -2
  46. package/dist/services/v1/electricity/electricity.service.js +12 -2
  47. package/dist/services/v1/globals/collections.service.d.ts +21 -5
  48. package/dist/services/v1/globals/collections.service.js +22 -5
  49. package/dist/services/v1/globals/payout.service.d.ts +73 -13
  50. package/dist/services/v1/globals/payout.service.js +74 -15
  51. package/dist/services/v1/terminals/terminals.service.d.ts +5 -5
  52. package/dist/services/v1/terminals/terminals.service.js +7 -18
  53. package/dist/services/v1/virtual-accounts/virtual-accounts.service.d.ts +4 -5
  54. package/dist/services/v1/virtual-accounts/virtual-accounts.service.js +7 -8
  55. package/dist/services/v1/webhooks/webhooks.service.d.ts +3 -4
  56. package/dist/services/v1/webhooks/webhooks.service.js +7 -8
  57. package/dist/services/v2/airtime/airtime.service.d.ts +26 -2
  58. package/dist/services/v2/airtime/airtime.service.js +27 -7
  59. package/dist/services/v2/betting/betting.service.d.ts +27 -3
  60. package/dist/services/v2/betting/betting.service.js +28 -8
  61. package/dist/services/v2/cable/cable.service.d.ts +27 -3
  62. package/dist/services/v2/cable/cable.service.js +28 -8
  63. package/dist/services/v2/data/data.service.d.ts +26 -2
  64. package/dist/services/v2/data/data.service.js +27 -7
  65. package/dist/services/v2/electricity/electricity.service.d.ts +28 -3
  66. package/dist/services/v2/electricity/electricity.service.js +29 -8
  67. package/dist/services/v2/transfers/transfers.service.d.ts +51 -6
  68. package/dist/services/v2/transfers/transfers.service.js +55 -25
  69. package/dist/types/common/common.types.d.ts +9 -13
  70. package/package.json +1 -1
@@ -13,9 +13,6 @@ const TRANSFER_OUTCOMES = {
13
13
  codes: { "00": "success", "200": "success", "201": "pending", ...REJECTED },
14
14
  statuses: { SUCCESS: "success", PENDING_BILLING: "pending" },
15
15
  };
16
- // The idempotency key tracked for error reporting. Nomba uses merchantTxRef (in the request body) for actual
17
- // deduplication, and it is stable across your own retries, so it is the default. Callers can override it per call.
18
- const idempotencyKeyFor = (params) => params.merchantTxRef;
19
16
  /**
20
17
  * Money movement. A call that throws a NombaError with a 4xx status was rejected and did nothing. Any other
21
18
  * failure (5xx, network error, timeout) leaves the outcome unknown: keep the same `merchantTxRef`, wait for the
@@ -26,42 +23,75 @@ export class TransfersService {
26
23
  constructor(http) {
27
24
  this.http = http;
28
25
  }
29
- /** GET /v1/transfers/banks */
26
+ /**
27
+ * `GET /v1/transfers/banks`. Lists the banks usable as a transfer destination.
28
+ * @returns The supported banks, each with its name and code.
29
+ * @throws {NombaError} A non-2xx response.
30
+ */
30
31
  listBanks() {
31
32
  return this.http.request("GET", "/v1/transfers/banks");
32
33
  }
33
- /** POST /v1/transfers/bank/lookup */
34
+ /**
35
+ * `POST /v1/transfers/bank/lookup`. Resolves a bank account number to its account name.
36
+ * @param params The bank code and account number to look up.
37
+ * @returns The resolved account name.
38
+ * @throws {NombaError} The lookup was rejected, e.g. an invalid account number.
39
+ */
34
40
  lookupBankAccount(params) {
35
41
  return this.http.request("POST", "/v1/transfers/bank/lookup", {
36
42
  body: params,
37
43
  });
38
44
  }
39
- /** POST /v2/transfers/bank, from the parent account. */
45
+ /**
46
+ * `POST /v2/transfers/bank`. Sends a bank transfer from the parent account.
47
+ * @param params The destination bank, account number and amount; `merchantTxRef` is the idempotency key.
48
+ * @param options Outcome closures; without them, success resolves the result and pending/failure throws.
49
+ * @returns The transfer result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
50
+ * @throws {NombaError} The transfer was rejected (4xx) and never happened.
51
+ * @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
52
+ * @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
53
+ */
40
54
  async bankTransfer(params, options = {}) {
41
- return settle(this.http, "POST", "/v2/transfers/bank", { body: params }, TRANSFER_OUTCOMES, {
42
- ...options,
43
- idempotencyKey: options.idempotencyKey ?? idempotencyKeyFor(params),
44
- });
55
+ return settle(this.http, "POST", "/v2/transfers/bank", { body: params }, TRANSFER_OUTCOMES, params.merchantTxRef, options);
45
56
  }
46
- /** POST /v2/transfers/bank/{subAccountId}. You must ask Nomba to profile you for sub account transfers. */
57
+ /**
58
+ * `POST /v2/transfers/bank/{subAccountId}`. Sends a bank transfer from a sub account. You must ask
59
+ * Nomba to profile you for sub account transfers.
60
+ * @param subAccountId The sub account to transfer from.
61
+ * @param params The destination bank, account number and amount; `merchantTxRef` is the idempotency key.
62
+ * @param options Outcome closures; without them, success resolves the result and pending/failure throws.
63
+ * @returns The transfer result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
64
+ * @throws {NombaError} The transfer was rejected (4xx) and never happened.
65
+ * @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
66
+ * @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
67
+ */
47
68
  async bankTransferFromSubAccount(subAccountId, params, options = {}) {
48
- return settle(this.http, "POST", `/v2/transfers/bank/${pathId(subAccountId)}`, { body: params }, TRANSFER_OUTCOMES, {
49
- ...options,
50
- idempotencyKey: options.idempotencyKey ?? idempotencyKeyFor(params),
51
- });
69
+ return settle(this.http, "POST", `/v2/transfers/bank/${pathId(subAccountId)}`, { body: params }, TRANSFER_OUTCOMES, params.merchantTxRef, options);
52
70
  }
53
- /** POST /v2/transfers/wallet, from the parent account to another Nomba account. */
71
+ /**
72
+ * `POST /v2/transfers/wallet`. Sends a wallet-to-wallet transfer from the parent account to another
73
+ * Nomba account.
74
+ * @param params The destination wallet and amount; `merchantTxRef` is the idempotency key.
75
+ * @param options Outcome closures; without them, success resolves the result and pending/failure throws.
76
+ * @returns The transfer result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
77
+ * @throws {NombaError} The transfer was rejected (4xx) and never happened.
78
+ * @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
79
+ * @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
80
+ */
54
81
  async walletTransfer(params, options = {}) {
55
- return settle(this.http, "POST", "/v2/transfers/wallet", { body: params }, TRANSFER_OUTCOMES, {
56
- ...options,
57
- idempotencyKey: options.idempotencyKey ?? idempotencyKeyFor(params),
58
- });
82
+ return settle(this.http, "POST", "/v2/transfers/wallet", { body: params }, TRANSFER_OUTCOMES, params.merchantTxRef, options);
59
83
  }
60
- /** POST /v2/transfers/wallet/{subAccountId} */
84
+ /**
85
+ * `POST /v2/transfers/wallet/{subAccountId}`. Sends a wallet-to-wallet transfer from a sub account.
86
+ * @param subAccountId The sub account to transfer from.
87
+ * @param params The destination wallet and amount; `merchantTxRef` is the idempotency key.
88
+ * @param options Outcome closures; without them, success resolves the result and pending/failure throws.
89
+ * @returns The transfer result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
90
+ * @throws {NombaError} The transfer was rejected (4xx) and never happened.
91
+ * @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
92
+ * @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
93
+ */
61
94
  async walletTransferFromSubAccount(subAccountId, params, options = {}) {
62
- return settle(this.http, "POST", `/v2/transfers/wallet/${pathId(subAccountId)}`, { body: params }, TRANSFER_OUTCOMES, {
63
- ...options,
64
- idempotencyKey: options.idempotencyKey ?? idempotencyKeyFor(params),
65
- });
95
+ return settle(this.http, "POST", `/v2/transfers/wallet/${pathId(subAccountId)}`, { body: params }, TRANSFER_OUTCOMES, params.merchantTxRef, options);
66
96
  }
67
97
  }
@@ -23,7 +23,7 @@ export interface NombaOptions {
23
23
  onStoreError?: (error: unknown) => void;
24
24
  /** Per-request timeout in milliseconds. Defaults to 30000. */
25
25
  timeoutMs?: number;
26
- /** Total tries per GET request (or any request hitting 429), including the first. Defaults to 3; 1 turns retries off. Mutating calls always make one attempt; see RequestOptions and OutcomeUnknownError. */
26
+ /** Total tries per GET request (or any request hitting 429), including the first. Defaults to 3; 1 turns retries off. Mutating calls always make one attempt; see OutcomeUnknownError. */
27
27
  maxAttempts?: number;
28
28
  /** Delay before the first retry in milliseconds; it doubles each time. Defaults to 500. */
29
29
  retryDelayMs?: number;
@@ -46,15 +46,6 @@ export type ResponseInfo = RequestInfo & {
46
46
  code?: string;
47
47
  durationMs: number;
48
48
  };
49
- /** Options for a single mutating call. */
50
- export type RequestOptions = {
51
- /**
52
- * Tracked for error reporting and onOutcome events. For transfers and bill payments, defaults to merchantTxRef
53
- * (the actual idempotency key in the request body). For Global Payout/Collections, sent in the request body
54
- * where Nomba deduplicates on it. The SDK generates a UUID when you omit it.
55
- */
56
- idempotencyKey?: string;
57
- };
58
49
  /** Options for one authenticated call made through IHttpClient.request. */
59
50
  export type HttpRequestOptions = {
60
51
  body?: unknown;
@@ -65,7 +56,12 @@ export type HttpRequestOptions = {
65
56
  descriptionField?: string;
66
57
  /** Resolve `{ code, data }` instead of `data`, so the caller can classify the body code. */
67
58
  envelope?: boolean;
68
- } & RequestOptions;
59
+ /**
60
+ * Tracked in `OutcomeUnknownError` so callers know which transaction to requery. Services derive
61
+ * this from params (e.g., `merchantTxRef`). A random UUID is generated if omitted.
62
+ */
63
+ idempotencyKey?: string;
64
+ };
69
65
  /** What request() resolves with `envelope: true`. */
70
66
  export type ResponseEnvelope<T> = {
71
67
  code: string;
@@ -74,5 +70,5 @@ export type ResponseEnvelope<T> = {
74
70
  /** The API also accepts lowercase values (glo, mtn, ...). */
75
71
  export type Upper = "GLO" | "MTN" | "9MOBILE" | "AIRTEL";
76
72
  export type Network = Upper | Lowercase<Upper>;
77
- /** Options for a money-moving call: an idempotency key plus closures for each outcome. */
78
- export type CallOptions<T, R = T> = RequestOptions & OutcomeHandlers<T, R>;
73
+ /** Options for a money-moving call: outcome closures (`onSuccess`, `onPending`, `onFailed`). */
74
+ export type CallOptions<T, R = T> = OutcomeHandlers<T, R>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nomba/node-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "Node.js SDK for Nomba's APIs",
5
5
  "license": "MIT",
6
6
  "type": "module",