@nomba/node-sdk 0.1.0 → 0.4.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 (82) hide show
  1. package/README.md +77 -16
  2. package/dist/index.d.ts +1 -1
  3. package/dist/index.js +1 -1
  4. package/dist/interfaces/v1/accounts/IAccountsService.d.ts +46 -8
  5. package/dist/interfaces/v1/betting/IBettingService.d.ts +11 -2
  6. package/dist/interfaces/v1/cable/ICableService.d.ts +12 -2
  7. package/dist/interfaces/v1/charge/IChargeService.d.ts +80 -19
  8. package/dist/interfaces/v1/checkout/ICheckoutService.d.ts +64 -15
  9. package/dist/interfaces/v1/data/IDataService.d.ts +6 -1
  10. package/dist/interfaces/v1/direct-debits/IDirectDebitsService.d.ts +37 -14
  11. package/dist/interfaces/v1/electricity/IElectricityService.d.ts +11 -2
  12. package/dist/interfaces/v1/globals/collections/IGlobalCollectionsService.d.ts +22 -5
  13. package/dist/interfaces/v1/globals/payouts/IGlobalPayoutService.d.ts +76 -13
  14. package/dist/interfaces/v1/requery/IRequeryService.d.ts +19 -5
  15. package/dist/interfaces/v1/terminals/ITerminalsService.d.ts +43 -10
  16. package/dist/interfaces/v1/transactions/ITransactionsService.d.ts +71 -12
  17. package/dist/interfaces/v1/virtual-accounts/IVirtualAccountsService.d.ts +50 -12
  18. package/dist/interfaces/v1/webhooks/IWebhooksService.d.ts +29 -10
  19. package/dist/interfaces/v2/airtime/IAirtimeV2Service.d.ts +21 -2
  20. package/dist/interfaces/v2/betting/IBettingV2Service.d.ts +21 -2
  21. package/dist/interfaces/v2/cable/ICableV2Service.d.ts +21 -2
  22. package/dist/interfaces/v2/data/IDataV2Service.d.ts +21 -2
  23. package/dist/interfaces/v2/electricity/IElectricityV2Service.d.ts +22 -2
  24. package/dist/interfaces/v2/transfers/ITransfersService.d.ts +57 -6
  25. package/dist/lib/errors.d.ts +19 -0
  26. package/dist/lib/errors.js +23 -0
  27. package/dist/lib/outcome.d.ts +30 -5
  28. package/dist/lib/outcome.js +31 -6
  29. package/dist/lib/sdk-version.generated.d.ts +1 -1
  30. package/dist/lib/sdk-version.generated.js +1 -1
  31. package/dist/lib/util.d.ts +0 -1
  32. package/dist/lib/util.js +0 -6
  33. package/dist/nomba.d.ts +38 -5
  34. package/dist/nomba.js +38 -5
  35. package/dist/services/http/http-client.service.d.ts +40 -6
  36. package/dist/services/http/http-client.service.js +44 -9
  37. package/dist/services/v1/accounts/accounts.service.d.ts +46 -8
  38. package/dist/services/v1/accounts/accounts.service.js +46 -8
  39. package/dist/services/v1/betting/betting.service.d.ts +12 -2
  40. package/dist/services/v1/betting/betting.service.js +12 -2
  41. package/dist/services/v1/cable/cable.service.d.ts +13 -2
  42. package/dist/services/v1/cable/cable.service.js +13 -2
  43. package/dist/services/v1/charge/charge.service.d.ts +80 -19
  44. package/dist/services/v1/charge/charge.service.js +88 -26
  45. package/dist/services/v1/checkout/checkout.service.d.ts +63 -15
  46. package/dist/services/v1/checkout/checkout.service.js +70 -24
  47. package/dist/services/v1/data/data.service.d.ts +7 -1
  48. package/dist/services/v1/data/data.service.js +7 -1
  49. package/dist/services/v1/direct-debits/direct-debits.service.d.ts +38 -14
  50. package/dist/services/v1/direct-debits/direct-debits.service.js +39 -17
  51. package/dist/services/v1/electricity/electricity.service.d.ts +12 -2
  52. package/dist/services/v1/electricity/electricity.service.js +12 -2
  53. package/dist/services/v1/globals/collections.service.d.ts +23 -5
  54. package/dist/services/v1/globals/collections.service.js +29 -7
  55. package/dist/services/v1/globals/payout.service.d.ts +77 -13
  56. package/dist/services/v1/globals/payout.service.js +83 -17
  57. package/dist/services/v1/requery/requery.service.d.ts +23 -5
  58. package/dist/services/v1/requery/requery.service.js +23 -5
  59. package/dist/services/v1/terminals/terminals.service.d.ts +42 -14
  60. package/dist/services/v1/terminals/terminals.service.js +44 -27
  61. package/dist/services/v1/transactions/transactions.service.d.ts +70 -12
  62. package/dist/services/v1/transactions/transactions.service.js +70 -12
  63. package/dist/services/v1/virtual-accounts/virtual-accounts.service.d.ts +52 -12
  64. package/dist/services/v1/virtual-accounts/virtual-accounts.service.js +55 -15
  65. package/dist/services/v1/webhooks/webhooks.service.d.ts +31 -10
  66. package/dist/services/v1/webhooks/webhooks.service.js +35 -14
  67. package/dist/services/v2/airtime/airtime.service.d.ts +26 -2
  68. package/dist/services/v2/airtime/airtime.service.js +27 -7
  69. package/dist/services/v2/betting/betting.service.d.ts +27 -3
  70. package/dist/services/v2/betting/betting.service.js +28 -8
  71. package/dist/services/v2/cable/cable.service.d.ts +27 -3
  72. package/dist/services/v2/cable/cable.service.js +28 -8
  73. package/dist/services/v2/data/data.service.d.ts +26 -2
  74. package/dist/services/v2/data/data.service.js +27 -7
  75. package/dist/services/v2/electricity/electricity.service.d.ts +28 -3
  76. package/dist/services/v2/electricity/electricity.service.js +29 -8
  77. package/dist/services/v2/transfers/transfers.service.d.ts +51 -6
  78. package/dist/services/v2/transfers/transfers.service.js +55 -25
  79. package/dist/types/common/common.types.d.ts +10 -13
  80. package/dist/types/v1/globals/collections.types.d.ts +3 -3
  81. package/dist/types/v1/globals/payout.types.d.ts +3 -3
  82. package/package.json +1 -1
@@ -12,25 +12,45 @@ const OUTCOMES = {
12
12
  codes: { "00": "success", "200": "success", "201": "pending", ...REJECTED },
13
13
  statuses: { SUCCESS: "success", PENDING_BILLING: "pending" },
14
14
  };
15
- /** v2 has purchase endpoints only. */
15
+ /**
16
+ * Betting wallet funding (v2 has purchase endpoints only). A call that throws a NombaError with a 4xx
17
+ * status was rejected and did nothing. Any other failure (5xx, network error, timeout) leaves the outcome
18
+ * unknown: keep the same `merchantTxRef`, wait for the webhook or requery, and never retry under a new
19
+ * reference.
20
+ */
16
21
  export class BettingV2Service {
17
22
  http;
18
23
  constructor(http) {
19
24
  this.http = http;
20
25
  }
21
- /** POST /v2/bill/betting, from the parent account. */
26
+ /**
27
+ * `POST /v2/bill/betting`. Funds a betting wallet from the parent account.
28
+ * @param params The betting provider, customer id and amount, and the `merchantTxRef` used for idempotency.
29
+ * @param options Outcome closures and per-call overrides; without them, success resolves the result and
30
+ * a rejection or pending outcome throws.
31
+ * @returns The payment result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
32
+ * @throws {NombaError} The payment was rejected (4xx).
33
+ * @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
34
+ * @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
35
+ */
22
36
  async payBetting(params, options = {}) {
23
37
  return this.#pay("/v2/bill/betting", params, options);
24
38
  }
25
- /** POST /v2/bill/betting/{subAccountId}. Pays from a sub account. */
39
+ /**
40
+ * `POST /v2/bill/betting/{subAccountId}`. Pays from a sub account.
41
+ * @param subAccountId The sub account to pay from.
42
+ * @param params The betting provider, customer id and amount, and the `merchantTxRef` used for idempotency.
43
+ * @param options Outcome closures and per-call overrides; without them, success resolves the result and
44
+ * a rejection or pending outcome throws.
45
+ * @returns The payment result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
46
+ * @throws {NombaError} The payment was rejected (4xx).
47
+ * @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
48
+ * @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
49
+ */
26
50
  async payBettingFromSubAccount(subAccountId, params, options = {}) {
27
51
  return this.#pay(`/v2/bill/betting/${pathId(subAccountId)}`, params, options);
28
52
  }
29
- // merchantTxRef is the default idempotency key, as for every bill payment.
30
53
  #pay(path, params, options) {
31
- return settle(this.http, "POST", path, { body: params }, OUTCOMES, {
32
- ...options,
33
- idempotencyKey: options.idempotencyKey ?? params.merchantTxRef,
34
- });
54
+ return settle(this.http, "POST", path, { body: params }, OUTCOMES, { field: "merchantTxRef", value: params.merchantTxRef }, options);
35
55
  }
36
56
  }
@@ -7,13 +7,37 @@ import type { IHttpClient } from "../../../interfaces/http/IHttpClient.js";
7
7
  import type { ICableV2Service } from "../../../interfaces/v2/cable/index.js";
8
8
  import type { CallOptions } from "../../../types/common/common.types.js";
9
9
  import type { CablePaymentV2Result, CableTvSubscriptionParams } from "../../../types/v2/cable/cable.types.js";
10
- /** v2 has purchase endpoints only. */
10
+ /**
11
+ * Cable TV subscription payments (v2 has purchase endpoints only). A call that throws a NombaError with a
12
+ * 4xx status was rejected and did nothing. Any other failure (5xx, network error, timeout) leaves the
13
+ * outcome unknown: keep the same `merchantTxRef`, wait for the webhook or requery, and never retry under a
14
+ * new reference.
15
+ */
11
16
  export declare class CableV2Service implements ICableV2Service {
12
17
  #private;
13
18
  private readonly http;
14
19
  constructor(http: IHttpClient);
15
- /** POST /v2/bill/cabletv, from the parent account. */
20
+ /**
21
+ * `POST /v2/bill/cabletv`. Pays a cable TV subscription from the parent account.
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
+ */
16
30
  subscribeCableTv<R = CablePaymentV2Result>(params: CableTvSubscriptionParams, options?: CallOptions<CablePaymentV2Result, R>): Promise<CablePaymentV2Result | R>;
17
- /** POST /v2/bill/cabletv/{subAccountId}. Pays from a sub account. */
31
+ /**
32
+ * `POST /v2/bill/cabletv/{subAccountId}`. Pays from a sub account.
33
+ * @param subAccountId The sub account to pay from.
34
+ * @param params The provider, smartcard/customer id and plan, and the `merchantTxRef` used for idempotency.
35
+ * @param options Outcome closures and per-call overrides; without them, success resolves the result and
36
+ * a rejection or pending outcome throws.
37
+ * @returns The payment result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
38
+ * @throws {NombaError} The payment was rejected (4xx).
39
+ * @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
40
+ * @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
41
+ */
18
42
  subscribeCableTvFromSubAccount<R = CablePaymentV2Result>(subAccountId: string, params: CableTvSubscriptionParams, options?: CallOptions<CablePaymentV2Result, R>): Promise<CablePaymentV2Result | R>;
19
43
  }
@@ -12,25 +12,45 @@ const OUTCOMES = {
12
12
  codes: { "00": "success", "200": "success", "201": "pending", ...REJECTED },
13
13
  statuses: { SUCCESS: "success", PENDING_BILLING: "pending" },
14
14
  };
15
- /** v2 has purchase endpoints only. */
15
+ /**
16
+ * Cable TV subscription payments (v2 has purchase endpoints only). A call that throws a NombaError with a
17
+ * 4xx status was rejected and did nothing. Any other failure (5xx, network error, timeout) leaves the
18
+ * outcome unknown: keep the same `merchantTxRef`, wait for the webhook or requery, and never retry under a
19
+ * new reference.
20
+ */
16
21
  export class CableV2Service {
17
22
  http;
18
23
  constructor(http) {
19
24
  this.http = http;
20
25
  }
21
- /** POST /v2/bill/cabletv, from the parent account. */
26
+ /**
27
+ * `POST /v2/bill/cabletv`. Pays a cable TV subscription from the parent account.
28
+ * @param params The provider, smartcard/customer id and plan, and the `merchantTxRef` used for idempotency.
29
+ * @param options Outcome closures and per-call overrides; without them, success resolves the result and
30
+ * a rejection or pending outcome throws.
31
+ * @returns The payment result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
32
+ * @throws {NombaError} The payment was rejected (4xx).
33
+ * @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
34
+ * @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
35
+ */
22
36
  async subscribeCableTv(params, options = {}) {
23
37
  return this.#pay("/v2/bill/cabletv", params, options);
24
38
  }
25
- /** POST /v2/bill/cabletv/{subAccountId}. Pays from a sub account. */
39
+ /**
40
+ * `POST /v2/bill/cabletv/{subAccountId}`. Pays from a sub account.
41
+ * @param subAccountId The sub account to pay from.
42
+ * @param params The provider, smartcard/customer id and plan, and the `merchantTxRef` used for idempotency.
43
+ * @param options Outcome closures and per-call overrides; without them, success resolves the result and
44
+ * a rejection or pending outcome throws.
45
+ * @returns The payment result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
46
+ * @throws {NombaError} The payment was rejected (4xx).
47
+ * @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
48
+ * @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
49
+ */
26
50
  async subscribeCableTvFromSubAccount(subAccountId, params, options = {}) {
27
51
  return this.#pay(`/v2/bill/cabletv/${pathId(subAccountId)}`, params, options);
28
52
  }
29
- // merchantTxRef is the default idempotency key, as for every bill payment.
30
53
  #pay(path, params, options) {
31
- return settle(this.http, "POST", path, { body: params }, OUTCOMES, {
32
- ...options,
33
- idempotencyKey: options.idempotencyKey ?? params.merchantTxRef,
34
- });
54
+ return settle(this.http, "POST", path, { body: params }, OUTCOMES, { field: "merchantTxRef", value: params.merchantTxRef }, options);
35
55
  }
36
56
  }
@@ -7,12 +7,36 @@ import type { IHttpClient } from "../../../interfaces/http/IHttpClient.js";
7
7
  import type { IDataV2Service } from "../../../interfaces/v2/data/index.js";
8
8
  import type { CallOptions } from "../../../types/common/common.types.js";
9
9
  import type { DataPurchaseParams, DataPurchaseV2Result } from "../../../types/v2/data/data.types.js";
10
+ /**
11
+ * Data bundle purchases (v2). A call that throws a NombaError with a 4xx status was rejected and did
12
+ * nothing. Any other failure (5xx, network error, timeout) leaves the outcome unknown: keep the same
13
+ * `merchantTxRef`, wait for the webhook or requery, and never retry under a new reference.
14
+ */
10
15
  export declare class DataV2Service implements IDataV2Service {
11
16
  #private;
12
17
  private readonly http;
13
18
  constructor(http: IHttpClient);
14
- /** POST /v2/bill/data, from the parent account. */
19
+ /**
20
+ * `POST /v2/bill/data`. Buys a data bundle from the parent account.
21
+ * @param params The phone number, network and data plan, and the `merchantTxRef` used for idempotency.
22
+ * @param options Outcome closures and per-call overrides; without them, success resolves the result and
23
+ * a rejection or pending outcome throws.
24
+ * @returns The purchase result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
25
+ * @throws {NombaError} The purchase was rejected (4xx).
26
+ * @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
27
+ * @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
28
+ */
15
29
  buyData<R = DataPurchaseV2Result>(params: DataPurchaseParams, options?: CallOptions<DataPurchaseV2Result, R>): Promise<DataPurchaseV2Result | R>;
16
- /** POST /v2/bill/data/{subAccountId}. Buys a data bundle from a sub account. */
30
+ /**
31
+ * `POST /v2/bill/data/{subAccountId}`. Buys a data bundle from a sub account.
32
+ * @param subAccountId The sub account to buy from.
33
+ * @param params The phone number, network and data plan, and the `merchantTxRef` used for idempotency.
34
+ * @param options Outcome closures and per-call overrides; without them, success resolves the result and
35
+ * a rejection or pending outcome throws.
36
+ * @returns The purchase result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
37
+ * @throws {NombaError} The purchase was rejected (4xx).
38
+ * @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
39
+ * @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
40
+ */
17
41
  buyDataFromSubAccount<R = DataPurchaseV2Result>(subAccountId: string, params: DataPurchaseParams, options?: CallOptions<DataPurchaseV2Result, R>): Promise<DataPurchaseV2Result | R>;
18
42
  }
@@ -12,24 +12,44 @@ const OUTCOMES = {
12
12
  codes: { "00": "success", "200": "success", "201": "pending", ...REJECTED },
13
13
  statuses: { SUCCESS: "success", PENDING_BILLING: "pending" },
14
14
  };
15
+ /**
16
+ * Data bundle purchases (v2). A call that throws a NombaError with a 4xx status was rejected and did
17
+ * nothing. Any other failure (5xx, network error, timeout) leaves the outcome unknown: keep the same
18
+ * `merchantTxRef`, wait for the webhook or requery, and never retry under a new reference.
19
+ */
15
20
  export class DataV2Service {
16
21
  http;
17
22
  constructor(http) {
18
23
  this.http = http;
19
24
  }
20
- /** POST /v2/bill/data, from the parent account. */
25
+ /**
26
+ * `POST /v2/bill/data`. Buys a data bundle from the parent account.
27
+ * @param params The phone number, network and data plan, and the `merchantTxRef` used for idempotency.
28
+ * @param options Outcome closures and per-call overrides; without them, success resolves the result and
29
+ * a rejection or pending outcome throws.
30
+ * @returns The purchase result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
31
+ * @throws {NombaError} The purchase was rejected (4xx).
32
+ * @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
33
+ * @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
34
+ */
21
35
  async buyData(params, options = {}) {
22
36
  return this.#buy("/v2/bill/data", params, options);
23
37
  }
24
- /** POST /v2/bill/data/{subAccountId}. Buys a data bundle from a sub account. */
38
+ /**
39
+ * `POST /v2/bill/data/{subAccountId}`. Buys a data bundle from a sub account.
40
+ * @param subAccountId The sub account to buy from.
41
+ * @param params The phone number, network and data plan, and the `merchantTxRef` used for idempotency.
42
+ * @param options Outcome closures and per-call overrides; without them, success resolves the result and
43
+ * a rejection or pending outcome throws.
44
+ * @returns The purchase result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
45
+ * @throws {NombaError} The purchase was rejected (4xx).
46
+ * @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
47
+ * @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
48
+ */
25
49
  async buyDataFromSubAccount(subAccountId, params, options = {}) {
26
50
  return this.#buy(`/v2/bill/data/${pathId(subAccountId)}`, params, options);
27
51
  }
28
- // merchantTxRef is the default idempotency key, as for every bill payment.
29
52
  #buy(path, params, options) {
30
- return settle(this.http, "POST", path, { body: params }, OUTCOMES, {
31
- ...options,
32
- idempotencyKey: options.idempotencyKey ?? params.merchantTxRef,
33
- });
53
+ return settle(this.http, "POST", path, { body: params }, OUTCOMES, { field: "merchantTxRef", value: params.merchantTxRef }, options);
34
54
  }
35
55
  }
@@ -7,13 +7,38 @@ import type { IHttpClient } from "../../../interfaces/http/IHttpClient.js";
7
7
  import type { IElectricityV2Service } from "../../../interfaces/v2/electricity/index.js";
8
8
  import type { CallOptions } from "../../../types/common/common.types.js";
9
9
  import type { ElectricityPaymentParams, ElectricityPaymentV2Result } from "../../../types/v2/electricity/electricity.types.js";
10
- /** v2 has purchase endpoints only. */
10
+ /**
11
+ * Electricity bill payments (v2 has purchase endpoints only). A call that throws a NombaError with a 4xx
12
+ * status was rejected and did nothing. Any other failure (5xx, network error, timeout) leaves the outcome
13
+ * unknown: keep the same `merchantTxRef`, wait for the webhook or requery, and never retry under a new
14
+ * reference.
15
+ */
11
16
  export declare class ElectricityV2Service implements IElectricityV2Service {
12
17
  #private;
13
18
  private readonly http;
14
19
  constructor(http: IHttpClient);
15
- /** POST /v2/bill/electricity, from the parent account. Prepaid meters get the token in `meta.phcnToken`. */
20
+ /**
21
+ * `POST /v2/bill/electricity`. Pays an electricity bill from the parent account. Prepaid meters get the
22
+ * token in `meta.phcnToken`.
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
+ */
16
31
  payElectricity<R = ElectricityPaymentV2Result>(params: ElectricityPaymentParams, options?: CallOptions<ElectricityPaymentV2Result, R>): Promise<ElectricityPaymentV2Result | R>;
17
- /** POST /v2/bill/electricity/{subAccountId}. Pays from a sub account. */
32
+ /**
33
+ * `POST /v2/bill/electricity/{subAccountId}`. Pays from a sub account.
34
+ * @param subAccountId The sub account to pay from.
35
+ * @param params The disco, meter number and amount, and the `merchantTxRef` used for idempotency.
36
+ * @param options Outcome closures and per-call overrides; without them, success resolves the result and
37
+ * a rejection or pending outcome throws.
38
+ * @returns The payment result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
39
+ * @throws {NombaError} The payment was rejected (4xx).
40
+ * @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
41
+ * @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
42
+ */
18
43
  payElectricityFromSubAccount<R = ElectricityPaymentV2Result>(subAccountId: string, params: ElectricityPaymentParams, options?: CallOptions<ElectricityPaymentV2Result, R>): Promise<ElectricityPaymentV2Result | R>;
19
44
  }
@@ -12,25 +12,46 @@ const OUTCOMES = {
12
12
  codes: { "00": "success", "200": "success", "201": "pending", ...REJECTED },
13
13
  statuses: { SUCCESS: "success", PENDING_BILLING: "pending" },
14
14
  };
15
- /** v2 has purchase endpoints only. */
15
+ /**
16
+ * Electricity bill payments (v2 has purchase endpoints only). A call that throws a NombaError with a 4xx
17
+ * status was rejected and did nothing. Any other failure (5xx, network error, timeout) leaves the outcome
18
+ * unknown: keep the same `merchantTxRef`, wait for the webhook or requery, and never retry under a new
19
+ * reference.
20
+ */
16
21
  export class ElectricityV2Service {
17
22
  http;
18
23
  constructor(http) {
19
24
  this.http = http;
20
25
  }
21
- /** POST /v2/bill/electricity, from the parent account. Prepaid meters get the token in `meta.phcnToken`. */
26
+ /**
27
+ * `POST /v2/bill/electricity`. Pays an electricity bill from the parent account. Prepaid meters get the
28
+ * token in `meta.phcnToken`.
29
+ * @param params The disco, meter number and amount, and the `merchantTxRef` used for idempotency.
30
+ * @param options Outcome closures and per-call overrides; without them, success resolves the result and
31
+ * a rejection or pending outcome throws.
32
+ * @returns The payment result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
33
+ * @throws {NombaError} The payment was rejected (4xx).
34
+ * @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
35
+ * @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
36
+ */
22
37
  async payElectricity(params, options = {}) {
23
38
  return this.#pay("/v2/bill/electricity", params, options);
24
39
  }
25
- /** POST /v2/bill/electricity/{subAccountId}. Pays from a sub account. */
40
+ /**
41
+ * `POST /v2/bill/electricity/{subAccountId}`. Pays from a sub account.
42
+ * @param subAccountId The sub account to pay from.
43
+ * @param params The disco, meter number and amount, and the `merchantTxRef` used for idempotency.
44
+ * @param options Outcome closures and per-call overrides; without them, success resolves the result and
45
+ * a rejection or pending outcome throws.
46
+ * @returns The payment result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
47
+ * @throws {NombaError} The payment was rejected (4xx).
48
+ * @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
49
+ * @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
50
+ */
26
51
  async payElectricityFromSubAccount(subAccountId, params, options = {}) {
27
52
  return this.#pay(`/v2/bill/electricity/${pathId(subAccountId)}`, params, options);
28
53
  }
29
- // merchantTxRef is the default idempotency key, as for every bill payment.
30
54
  #pay(path, params, options) {
31
- return settle(this.http, "POST", path, { body: params }, OUTCOMES, {
32
- ...options,
33
- idempotencyKey: options.idempotencyKey ?? params.merchantTxRef,
34
- });
55
+ return settle(this.http, "POST", path, { body: params }, OUTCOMES, { field: "merchantTxRef", value: params.merchantTxRef }, options);
35
56
  }
36
57
  }
@@ -15,16 +15,61 @@ import type { Bank, BankAccountLookupParams, BankAccountLookupResult, BankTransf
15
15
  export declare class TransfersService implements ITransfersService {
16
16
  private readonly http;
17
17
  constructor(http: IHttpClient);
18
- /** GET /v1/transfers/banks */
18
+ /**
19
+ * `GET /v1/transfers/banks`. Lists the banks usable as a transfer destination.
20
+ * @returns The supported banks, each with its name and code.
21
+ * @throws {NombaError} A non-2xx response.
22
+ */
19
23
  listBanks(): Promise<Bank[]>;
20
- /** POST /v1/transfers/bank/lookup */
24
+ /**
25
+ * `POST /v1/transfers/bank/lookup`. Resolves a bank account number to its account name.
26
+ * @param params The bank code and account number to look up.
27
+ * @returns The resolved account name.
28
+ * @throws {NombaError} The lookup was rejected, e.g. an invalid account number.
29
+ */
21
30
  lookupBankAccount(params: BankAccountLookupParams): Promise<BankAccountLookupResult>;
22
- /** POST /v2/transfers/bank, from the parent account. */
31
+ /**
32
+ * `POST /v2/transfers/bank`. Sends a bank transfer from the parent account.
33
+ * @param params The destination bank, account number and amount; `merchantTxRef` is the idempotency key.
34
+ * @param options Outcome closures; without them, success resolves the result and pending/failure throws.
35
+ * @returns The transfer result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
36
+ * @throws {NombaError} The transfer was rejected (4xx) and never happened.
37
+ * @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
38
+ * @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
39
+ */
23
40
  bankTransfer<R = BankTransferResult>(params: BankTransferParams, options?: CallOptions<BankTransferResult, R>): Promise<BankTransferResult | R>;
24
- /** POST /v2/transfers/bank/{subAccountId}. You must ask Nomba to profile you for sub account transfers. */
41
+ /**
42
+ * `POST /v2/transfers/bank/{subAccountId}`. Sends a bank transfer from a sub account. You must ask
43
+ * Nomba to profile you for sub account transfers.
44
+ * @param subAccountId The sub account to transfer from.
45
+ * @param params The destination bank, account number and amount; `merchantTxRef` is the idempotency key.
46
+ * @param options Outcome closures; without them, success resolves the result and pending/failure throws.
47
+ * @returns The transfer result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
48
+ * @throws {NombaError} The transfer was rejected (4xx) and never happened.
49
+ * @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
50
+ * @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
51
+ */
25
52
  bankTransferFromSubAccount<R = BankTransferResult>(subAccountId: string, params: BankTransferParams, options?: CallOptions<BankTransferResult, R>): Promise<BankTransferResult | R>;
26
- /** POST /v2/transfers/wallet, from the parent account to another Nomba account. */
53
+ /**
54
+ * `POST /v2/transfers/wallet`. Sends a wallet-to-wallet transfer from the parent account to another
55
+ * Nomba account.
56
+ * @param params The destination wallet and amount; `merchantTxRef` is the idempotency key.
57
+ * @param options Outcome closures; without them, success resolves the result and pending/failure throws.
58
+ * @returns The transfer result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
59
+ * @throws {NombaError} The transfer was rejected (4xx) and never happened.
60
+ * @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
61
+ * @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
62
+ */
27
63
  walletTransfer<R = WalletTransferResult>(params: WalletTransferParams, options?: CallOptions<WalletTransferResult, R>): Promise<WalletTransferResult | R>;
28
- /** POST /v2/transfers/wallet/{subAccountId} */
64
+ /**
65
+ * `POST /v2/transfers/wallet/{subAccountId}`. Sends a wallet-to-wallet transfer from a sub account.
66
+ * @param subAccountId The sub account to transfer from.
67
+ * @param params The destination wallet and amount; `merchantTxRef` is the idempotency key.
68
+ * @param options Outcome closures; without them, success resolves the result and pending/failure throws.
69
+ * @returns The transfer result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
70
+ * @throws {NombaError} The transfer was rejected (4xx) and never happened.
71
+ * @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
72
+ * @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
73
+ */
29
74
  walletTransferFromSubAccount<R = WalletTransferResult>(subAccountId: string, params: WalletTransferParams, options?: CallOptions<WalletTransferResult, R>): Promise<WalletTransferResult | R>;
30
75
  }
@@ -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, { field: "merchantTxRef", value: 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, { field: "merchantTxRef", value: 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, { field: "merchantTxRef", value: 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, { field: "merchantTxRef", value: 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,13 @@ 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`). For non-money-moving operations, a random UUID is
62
+ * generated if omitted. Money-moving operations (settle) require a caller-provided key.
63
+ */
64
+ idempotencyKey?: string;
65
+ };
69
66
  /** What request() resolves with `envelope: true`. */
70
67
  export type ResponseEnvelope<T> = {
71
68
  code: string;
@@ -74,5 +71,5 @@ export type ResponseEnvelope<T> = {
74
71
  /** The API also accepts lowercase values (glo, mtn, ...). */
75
72
  export type Upper = "GLO" | "MTN" | "9MOBILE" | "AIRTEL";
76
73
  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>;
74
+ /** Options for a money-moving call: outcome closures (`onSuccess`, `onPending`, `onFailed`). */
75
+ export type CallOptions<T, R = T> = OutcomeHandlers<T, R>;
@@ -13,10 +13,10 @@ export type InitiateInflowParams = {
13
13
  /** A `code` from `inflowProviders`. */
14
14
  topupVendor: string;
15
15
  /**
16
- * Sent in the body; the API dedupes on it. The SDK generates a UUID when you omit it. After an
17
- * OutcomeUnknownError, retry with the error's `idempotencyKey`. After a definite rejection, use a new key.
16
+ * Sent in the body; the API dedupes on it. Required to prevent double disbursement. After an
17
+ * OutcomeUnknownError, retry with the same key. After a definite rejection, use a new key.
18
18
  */
19
- idempotencyKey?: string;
19
+ idempotencyKey: string;
20
20
  };
21
21
  export type InflowProvider = {
22
22
  /** Pass as `topupVendor`, e.g. MPESA, AIRTEL, ORANGE. */
@@ -19,11 +19,11 @@ export type ConvertMoneyParams = {
19
19
  };
20
20
  /**
21
21
  * Sent in the body; the API dedupes on it (same key and body replays the original, with `idempotentReplay`).
22
- * The SDK generates a UUID when you omit it. After an OutcomeUnknownError, retry with the error's
23
- * `idempotencyKey`; change anything about the payment and you must use a new key. At most 128 characters.
22
+ * Required to prevent double disbursement. After an OutcomeUnknownError, retry with the same key;
23
+ * change anything about the payment and you must use a new key. At most 128 characters.
24
24
  */
25
25
  export type BodyIdempotencyKey = {
26
- idempotencyKey?: string;
26
+ idempotencyKey: string;
27
27
  };
28
28
  export type AuthorizeExchangeParams = BodyIdempotencyKey & {
29
29
  amount: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nomba/node-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.4.0",
4
4
  "description": "Node.js SDK for Nomba's APIs",
5
5
  "license": "MIT",
6
6
  "type": "module",