@lukadriel/wave-sdk 0.0.0-stage → 0.1.2
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/CHANGELOG.md +30 -0
- package/LICENSE +201 -0
- package/NOTICE +2 -0
- package/README.md +523 -2
- package/dist/client/wave-client-options.d.ts +29 -0
- package/dist/client/wave-client-options.d.ts.map +1 -0
- package/dist/client/wave-client-options.js +58 -0
- package/dist/client/wave-client-options.js.map +1 -0
- package/dist/client/wave-client.d.ts +47 -0
- package/dist/client/wave-client.d.ts.map +1 -0
- package/dist/client/wave-client.js +66 -0
- package/dist/client/wave-client.js.map +1 -0
- package/dist/core/auth/authentication.d.ts +8 -0
- package/dist/core/auth/authentication.d.ts.map +1 -0
- package/dist/core/auth/authentication.js +10 -0
- package/dist/core/auth/authentication.js.map +1 -0
- package/dist/core/auth/request-signer.d.ts +26 -0
- package/dist/core/auth/request-signer.d.ts.map +1 -0
- package/dist/core/auth/request-signer.js +39 -0
- package/dist/core/auth/request-signer.js.map +1 -0
- package/dist/core/errors/error-parser.d.ts +25 -0
- package/dist/core/errors/error-parser.d.ts.map +1 -0
- package/dist/core/errors/error-parser.js +198 -0
- package/dist/core/errors/error-parser.js.map +1 -0
- package/dist/core/errors/redact.d.ts +11 -0
- package/dist/core/errors/redact.d.ts.map +1 -0
- package/dist/core/errors/redact.js +20 -0
- package/dist/core/errors/redact.js.map +1 -0
- package/dist/core/errors/wave-api-error.d.ts +116 -0
- package/dist/core/errors/wave-api-error.d.ts.map +1 -0
- package/dist/core/errors/wave-api-error.js +114 -0
- package/dist/core/errors/wave-api-error.js.map +1 -0
- package/dist/core/errors/wave-error.d.ts +27 -0
- package/dist/core/errors/wave-error.d.ts.map +1 -0
- package/dist/core/errors/wave-error.js +22 -0
- package/dist/core/errors/wave-error.js.map +1 -0
- package/dist/core/errors/wave-network-error.d.ts +24 -0
- package/dist/core/errors/wave-network-error.d.ts.map +1 -0
- package/dist/core/errors/wave-network-error.js +24 -0
- package/dist/core/errors/wave-network-error.js.map +1 -0
- package/dist/core/errors/wave-webhook-verification-error.d.ts +18 -0
- package/dist/core/errors/wave-webhook-verification-error.d.ts.map +1 -0
- package/dist/core/errors/wave-webhook-verification-error.js +17 -0
- package/dist/core/errors/wave-webhook-verification-error.js.map +1 -0
- package/dist/core/http/fetch-transport.d.ts +23 -0
- package/dist/core/http/fetch-transport.d.ts.map +1 -0
- package/dist/core/http/fetch-transport.js +34 -0
- package/dist/core/http/fetch-transport.js.map +1 -0
- package/dist/core/http/http-client.d.ts +57 -0
- package/dist/core/http/http-client.d.ts.map +1 -0
- package/dist/core/http/http-client.js +254 -0
- package/dist/core/http/http-client.js.map +1 -0
- package/dist/core/http/http-request.d.ts +35 -0
- package/dist/core/http/http-request.d.ts.map +1 -0
- package/dist/core/http/http-request.js +2 -0
- package/dist/core/http/http-request.js.map +1 -0
- package/dist/core/http/http-response.d.ts +26 -0
- package/dist/core/http/http-response.d.ts.map +1 -0
- package/dist/core/http/http-response.js +23 -0
- package/dist/core/http/http-response.js.map +1 -0
- package/dist/core/http/query.d.ts +14 -0
- package/dist/core/http/query.d.ts.map +1 -0
- package/dist/core/http/query.js +23 -0
- package/dist/core/http/query.js.map +1 -0
- package/dist/core/http/transport.d.ts +44 -0
- package/dist/core/http/transport.d.ts.map +1 -0
- package/dist/core/http/transport.js +2 -0
- package/dist/core/http/transport.js.map +1 -0
- package/dist/core/idempotency/idempotency.d.ts +16 -0
- package/dist/core/idempotency/idempotency.d.ts.map +1 -0
- package/dist/core/idempotency/idempotency.js +27 -0
- package/dist/core/idempotency/idempotency.js.map +1 -0
- package/dist/core/retry/backoff.d.ts +18 -0
- package/dist/core/retry/backoff.d.ts.map +1 -0
- package/dist/core/retry/backoff.js +46 -0
- package/dist/core/retry/backoff.js.map +1 -0
- package/dist/core/retry/retry-policy.d.ts +43 -0
- package/dist/core/retry/retry-policy.d.ts.map +1 -0
- package/dist/core/retry/retry-policy.js +90 -0
- package/dist/core/retry/retry-policy.js.map +1 -0
- package/dist/core/types/common.d.ts +59 -0
- package/dist/core/types/common.d.ts.map +1 -0
- package/dist/core/types/common.js +2 -0
- package/dist/core/types/common.js.map +1 -0
- package/dist/core/types/configuration.d.ts +82 -0
- package/dist/core/types/configuration.d.ts.map +1 -0
- package/dist/core/types/configuration.js +2 -0
- package/dist/core/types/configuration.js.map +1 -0
- package/dist/core/types/json.d.ts +15 -0
- package/dist/core/types/json.d.ts.map +1 -0
- package/dist/core/types/json.js +2 -0
- package/dist/core/types/json.js.map +1 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/resources/aggregated-merchants/aggregated-merchant-types.d.ts +82 -0
- package/dist/resources/aggregated-merchants/aggregated-merchant-types.d.ts.map +1 -0
- package/dist/resources/aggregated-merchants/aggregated-merchant-types.js +2 -0
- package/dist/resources/aggregated-merchants/aggregated-merchant-types.js.map +1 -0
- package/dist/resources/aggregated-merchants/aggregated-merchants.d.ts +67 -0
- package/dist/resources/aggregated-merchants/aggregated-merchants.d.ts.map +1 -0
- package/dist/resources/aggregated-merchants/aggregated-merchants.js +111 -0
- package/dist/resources/aggregated-merchants/aggregated-merchants.js.map +1 -0
- package/dist/resources/balance/balance-types.d.ts +18 -0
- package/dist/resources/balance/balance-types.d.ts.map +1 -0
- package/dist/resources/balance/balance-types.js +2 -0
- package/dist/resources/balance/balance-types.js.map +1 -0
- package/dist/resources/balance/balance.d.ts +20 -0
- package/dist/resources/balance/balance.d.ts.map +1 -0
- package/dist/resources/balance/balance.js +28 -0
- package/dist/resources/balance/balance.js.map +1 -0
- package/dist/resources/checkout/checkout-types.d.ts +96 -0
- package/dist/resources/checkout/checkout-types.d.ts.map +1 -0
- package/dist/resources/checkout/checkout-types.js +2 -0
- package/dist/resources/checkout/checkout-types.js.map +1 -0
- package/dist/resources/checkout/checkout.d.ts +66 -0
- package/dist/resources/checkout/checkout.d.ts.map +1 -0
- package/dist/resources/checkout/checkout.js +95 -0
- package/dist/resources/checkout/checkout.js.map +1 -0
- package/dist/resources/payout-batches/payout-batches.d.ts +31 -0
- package/dist/resources/payout-batches/payout-batches.d.ts.map +1 -0
- package/dist/resources/payout-batches/payout-batches.js +36 -0
- package/dist/resources/payout-batches/payout-batches.js.map +1 -0
- package/dist/resources/payouts/payout-types.d.ts +158 -0
- package/dist/resources/payouts/payout-types.d.ts.map +1 -0
- package/dist/resources/payouts/payout-types.js +2 -0
- package/dist/resources/payouts/payout-types.js.map +1 -0
- package/dist/resources/payouts/payouts.d.ts +63 -0
- package/dist/resources/payouts/payouts.d.ts.map +1 -0
- package/dist/resources/payouts/payouts.js +80 -0
- package/dist/resources/payouts/payouts.js.map +1 -0
- package/dist/resources/reconciliation/reconciliation-types.d.ts +86 -0
- package/dist/resources/reconciliation/reconciliation-types.d.ts.map +1 -0
- package/dist/resources/reconciliation/reconciliation-types.js +2 -0
- package/dist/resources/reconciliation/reconciliation-types.js.map +1 -0
- package/dist/resources/reconciliation/reconciliation.d.ts +41 -0
- package/dist/resources/reconciliation/reconciliation.d.ts.map +1 -0
- package/dist/resources/reconciliation/reconciliation.js +81 -0
- package/dist/resources/reconciliation/reconciliation.js.map +1 -0
- package/dist/resources/webhooks/webhook-types.d.ts +159 -0
- package/dist/resources/webhooks/webhook-types.d.ts.map +1 -0
- package/dist/resources/webhooks/webhook-types.js +36 -0
- package/dist/resources/webhooks/webhook-types.js.map +1 -0
- package/dist/resources/webhooks/webhook-verifier.d.ts +104 -0
- package/dist/resources/webhooks/webhook-verifier.d.ts.map +1 -0
- package/dist/resources/webhooks/webhook-verifier.js +188 -0
- package/dist/resources/webhooks/webhook-verifier.js.map +1 -0
- package/package.json +70 -4
- package/src/client/wave-client-options.ts +91 -0
- package/src/client/wave-client.ts +70 -0
- package/src/core/auth/authentication.ts +9 -0
- package/src/core/auth/request-signer.ts +42 -0
- package/src/core/errors/error-parser.ts +258 -0
- package/src/core/errors/redact.ts +20 -0
- package/src/core/errors/wave-api-error.ts +148 -0
- package/src/core/errors/wave-error.ts +32 -0
- package/src/core/errors/wave-network-error.ts +24 -0
- package/src/core/errors/wave-webhook-verification-error.ts +28 -0
- package/src/core/http/fetch-transport.ts +48 -0
- package/src/core/http/http-client.ts +352 -0
- package/src/core/http/http-request.ts +37 -0
- package/src/core/http/http-response.ts +37 -0
- package/src/core/http/query.ts +31 -0
- package/src/core/http/transport.ts +45 -0
- package/src/core/idempotency/idempotency.ts +31 -0
- package/src/core/retry/backoff.ts +61 -0
- package/src/core/retry/retry-policy.ts +106 -0
- package/src/core/types/common.ts +65 -0
- package/src/core/types/configuration.ts +85 -0
- package/src/core/types/json.ts +16 -0
- package/src/index.ts +146 -0
- package/src/resources/aggregated-merchants/aggregated-merchant-types.ts +87 -0
- package/src/resources/aggregated-merchants/aggregated-merchants.ts +171 -0
- package/src/resources/balance/balance-types.ts +19 -0
- package/src/resources/balance/balance.ts +39 -0
- package/src/resources/checkout/checkout-types.ts +102 -0
- package/src/resources/checkout/checkout.ts +144 -0
- package/src/resources/payout-batches/payout-batches.ts +58 -0
- package/src/resources/payouts/payout-types.ts +171 -0
- package/src/resources/payouts/payouts.ts +120 -0
- package/src/resources/reconciliation/reconciliation-types.ts +102 -0
- package/src/resources/reconciliation/reconciliation.ts +116 -0
- package/src/resources/webhooks/webhook-types.ts +222 -0
- package/src/resources/webhooks/webhook-verifier.ts +297 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { WaveConfigurationError } from '../errors/wave-error.js';
|
|
2
|
+
import type { RetryOptions } from '../types/configuration.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Default retry policy.
|
|
6
|
+
*
|
|
7
|
+
* Two retries with a one-second base delay and full jitter follow Wave's own guidance to wait a
|
|
8
|
+
* few seconds between retries of idempotent operations.
|
|
9
|
+
*/
|
|
10
|
+
export const DEFAULT_RETRY_OPTIONS: RetryOptions = Object.freeze({
|
|
11
|
+
maxRetries: 2,
|
|
12
|
+
baseDelayMs: 1000,
|
|
13
|
+
maxDelayMs: 30000,
|
|
14
|
+
jitter: true,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Validates and fills a partial retry configuration.
|
|
19
|
+
*
|
|
20
|
+
* @param options - Partial retry configuration.
|
|
21
|
+
* @returns A complete, validated retry policy.
|
|
22
|
+
*/
|
|
23
|
+
export function normalizeRetryOptions(options: Partial<RetryOptions>): RetryOptions {
|
|
24
|
+
const merged: RetryOptions = { ...DEFAULT_RETRY_OPTIONS, ...options };
|
|
25
|
+
|
|
26
|
+
if (!Number.isInteger(merged.maxRetries) || merged.maxRetries < 0) {
|
|
27
|
+
throw new WaveConfigurationError('retry.maxRetries must be a non-negative integer.');
|
|
28
|
+
}
|
|
29
|
+
if (!Number.isFinite(merged.baseDelayMs) || merged.baseDelayMs < 0) {
|
|
30
|
+
throw new WaveConfigurationError('retry.baseDelayMs must be a non-negative finite number.');
|
|
31
|
+
}
|
|
32
|
+
if (!Number.isFinite(merged.maxDelayMs) || merged.maxDelayMs < 0) {
|
|
33
|
+
throw new WaveConfigurationError('retry.maxDelayMs must be a non-negative finite number.');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return merged;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Resolves the retry policy for one request.
|
|
41
|
+
*
|
|
42
|
+
* @param base - Client-level retry policy.
|
|
43
|
+
* @param override - Per-request override.
|
|
44
|
+
* @returns The effective policy, or `false` when retries are disabled.
|
|
45
|
+
*/
|
|
46
|
+
export function resolveRetryOptions(
|
|
47
|
+
base: RetryOptions | false,
|
|
48
|
+
override: Partial<RetryOptions> | false | undefined,
|
|
49
|
+
): RetryOptions | false {
|
|
50
|
+
if (override === false) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
if (override === undefined) {
|
|
54
|
+
return base;
|
|
55
|
+
}
|
|
56
|
+
if (base === false) {
|
|
57
|
+
return normalizeRetryOptions(override);
|
|
58
|
+
}
|
|
59
|
+
return normalizeRetryOptions({ ...base, ...override });
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Whether a status code is safe to retry at the transport level.
|
|
64
|
+
*
|
|
65
|
+
* Wave documents retries for 408, 429 and 5xx responses; other 4xx responses are final.
|
|
66
|
+
*
|
|
67
|
+
* @param status - HTTP status code.
|
|
68
|
+
*/
|
|
69
|
+
export function isRetryableStatus(status: number): boolean {
|
|
70
|
+
return status === 408 || status === 429 || status >= 500;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Parses a `Retry-After` header value.
|
|
75
|
+
*
|
|
76
|
+
* Wave's documentation does not currently describe this header, so it is honoured only when
|
|
77
|
+
* present.
|
|
78
|
+
*
|
|
79
|
+
* @param value - Header value, either delay seconds or an HTTP date.
|
|
80
|
+
* @param nowMs - Current time in milliseconds; injectable for tests.
|
|
81
|
+
* @returns Delay in seconds, or `undefined` when missing or invalid.
|
|
82
|
+
*/
|
|
83
|
+
export function parseRetryAfter(
|
|
84
|
+
value: string | undefined,
|
|
85
|
+
nowMs: number = Date.now(),
|
|
86
|
+
): number | undefined {
|
|
87
|
+
if (value === undefined) {
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const trimmed = value.trim();
|
|
92
|
+
if (trimmed.length === 0) {
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const seconds = Number(trimmed);
|
|
97
|
+
if (Number.isFinite(seconds)) {
|
|
98
|
+
return seconds >= 0 ? Math.ceil(seconds) : undefined;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const dateMs = Date.parse(trimmed);
|
|
102
|
+
if (Number.isNaN(dateMs)) {
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
return Math.max(0, Math.ceil((dateMs - nowMs) / 1000));
|
|
106
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { JsonObject } from './json.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A monetary amount.
|
|
5
|
+
*
|
|
6
|
+
* Wave serializes amounts as strings to preserve precision; the SDK keeps that representation
|
|
7
|
+
* unchanged. The Payout API requires whole numbers, while the Balance and Checkout APIs allow up to
|
|
8
|
+
* two decimal places depending on the currency (XOF does not allow decimals).
|
|
9
|
+
*/
|
|
10
|
+
export type Amount = string;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A currency identifier.
|
|
14
|
+
*
|
|
15
|
+
* Wave uses ISO 4217 three-letter uppercase codes, for example `XOF` for the West African Franc.
|
|
16
|
+
*/
|
|
17
|
+
export type CurrencyCode = string;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A timestamp.
|
|
21
|
+
*
|
|
22
|
+
* Wave returns ISO 8601 UTC timestamps with second precision, for example `2022-06-20T17:17:11Z`.
|
|
23
|
+
*/
|
|
24
|
+
export type Timestamp = string;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* A phone number in E.164 format, including the leading `+` country code.
|
|
28
|
+
*/
|
|
29
|
+
export type PhoneNumber = string;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Pagination information returned by cursor-paginated Wave endpoints.
|
|
33
|
+
*/
|
|
34
|
+
export interface PageInfo {
|
|
35
|
+
/** Whether another page of results exists after the current one. */
|
|
36
|
+
readonly has_next_page: boolean;
|
|
37
|
+
/** Opaque cursor to pass as `after` on the next request, or `null` when unavailable. */
|
|
38
|
+
readonly end_cursor: string | null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* A cursor-paginated Wave response.
|
|
43
|
+
*
|
|
44
|
+
* @typeParam TItem - The item type returned by the endpoint; this varies per API.
|
|
45
|
+
*/
|
|
46
|
+
export interface PaginatedResponse<TItem> {
|
|
47
|
+
/** Pagination state for the current page. */
|
|
48
|
+
readonly page_info: PageInfo;
|
|
49
|
+
/** Items in the current page. */
|
|
50
|
+
readonly items: readonly TItem[];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* A single field-level validation error returned in a documented error envelope.
|
|
55
|
+
*/
|
|
56
|
+
export interface ValidationErrorDetail {
|
|
57
|
+
/** Location of the offending value, for example `['currency']` or `['payments', 1, 'mobile']`. */
|
|
58
|
+
readonly loc: readonly (string | number)[];
|
|
59
|
+
/** Human-readable description of the validation problem. */
|
|
60
|
+
readonly msg: string;
|
|
61
|
+
/** Machine-readable validation error type, when provided. */
|
|
62
|
+
readonly type?: string;
|
|
63
|
+
/** Additional validation context, when provided. */
|
|
64
|
+
readonly ctx?: JsonObject;
|
|
65
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { WaveTransport } from '../http/transport.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Retry policy configuration.
|
|
5
|
+
*/
|
|
6
|
+
export interface RetryOptions {
|
|
7
|
+
/** Maximum number of retries after the initial attempt. */
|
|
8
|
+
readonly maxRetries: number;
|
|
9
|
+
/** Base delay before the first retry, in milliseconds. */
|
|
10
|
+
readonly baseDelayMs: number;
|
|
11
|
+
/** Upper bound for any single backoff delay, in milliseconds. */
|
|
12
|
+
readonly maxDelayMs: number;
|
|
13
|
+
/** Whether to apply full jitter to computed delays. */
|
|
14
|
+
readonly jitter: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Structured logger used for request diagnostics.
|
|
19
|
+
*
|
|
20
|
+
* The SDK only passes request metadata (method, path, status, attempt, duration). It never passes
|
|
21
|
+
* headers, bodies, API keys, signing secrets or webhook secrets.
|
|
22
|
+
*/
|
|
23
|
+
export interface WaveLogger {
|
|
24
|
+
/** Diagnostic detail useful while integrating. */
|
|
25
|
+
debug?(message: string, meta?: Readonly<Record<string, unknown>>): void;
|
|
26
|
+
/** Non-fatal information, such as a scheduled retry. */
|
|
27
|
+
info?(message: string, meta?: Readonly<Record<string, unknown>>): void;
|
|
28
|
+
/** Recoverable problem, such as a retry after a server error. */
|
|
29
|
+
warn?(message: string, meta?: Readonly<Record<string, unknown>>): void;
|
|
30
|
+
/** Fatal problem for a single request. */
|
|
31
|
+
error?(message: string, meta?: Readonly<Record<string, unknown>>): void;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Configuration for {@link WaveClient}.
|
|
36
|
+
*/
|
|
37
|
+
export interface WaveClientOptions {
|
|
38
|
+
/**
|
|
39
|
+
* Wave Business API key, sent as `Authorization: Bearer <apiKey>`.
|
|
40
|
+
*
|
|
41
|
+
* The SDK is intended for trusted server-side environments; never expose this key in browser or
|
|
42
|
+
* mobile bundles.
|
|
43
|
+
*/
|
|
44
|
+
readonly apiKey: string;
|
|
45
|
+
/**
|
|
46
|
+
* Signing secret configured on the API key, used to send `Wave-Signature` on every request.
|
|
47
|
+
*
|
|
48
|
+
* When omitted, no signature header is generated.
|
|
49
|
+
*/
|
|
50
|
+
readonly signingSecret?: string;
|
|
51
|
+
/** Base URL of the API; defaults to `https://api.wave.com`. */
|
|
52
|
+
readonly baseUrl?: string;
|
|
53
|
+
/** Per-request timeout in milliseconds; defaults to 30000. */
|
|
54
|
+
readonly timeoutMs?: number;
|
|
55
|
+
/** Retry policy, or `false` to disable retries. Defaults to two retries. */
|
|
56
|
+
readonly retry?: Partial<RetryOptions> | false;
|
|
57
|
+
/** Custom transport; defaults to a global-fetch transport. */
|
|
58
|
+
readonly transport?: WaveTransport;
|
|
59
|
+
/** Optional diagnostics logger that never receives secrets. */
|
|
60
|
+
readonly logger?: WaveLogger;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Per-request overrides.
|
|
65
|
+
*/
|
|
66
|
+
export interface RequestOptions {
|
|
67
|
+
/** Timeout for this request in milliseconds. */
|
|
68
|
+
readonly timeoutMs?: number;
|
|
69
|
+
/** Caller abort signal; aborting rejects with `WaveAbortError`. */
|
|
70
|
+
readonly signal?: AbortSignal;
|
|
71
|
+
/**
|
|
72
|
+
* Idempotency key for this logical operation.
|
|
73
|
+
*
|
|
74
|
+
* When omitted, the SDK generates a random UUID for operations that require one and reuses that
|
|
75
|
+
* key for every retry of the same call.
|
|
76
|
+
*/
|
|
77
|
+
readonly idempotencyKey?: string;
|
|
78
|
+
/**
|
|
79
|
+
* Retry overrides for this request.
|
|
80
|
+
*
|
|
81
|
+
* Passing a value for a non-idempotent operation asserts that retrying is safe; the SDK does not
|
|
82
|
+
* make that judgement for you.
|
|
83
|
+
*/
|
|
84
|
+
readonly retry?: Partial<RetryOptions> | false;
|
|
85
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A JSON primitive value.
|
|
3
|
+
*/
|
|
4
|
+
export type JsonPrimitive = string | number | boolean | null;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Any value representable in JSON.
|
|
8
|
+
*/
|
|
9
|
+
export type JsonValue = JsonPrimitive | JsonObject | JsonValue[];
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A JSON object with string keys.
|
|
13
|
+
*/
|
|
14
|
+
export interface JsonObject {
|
|
15
|
+
readonly [key: string]: JsonValue;
|
|
16
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified, strongly typed SDK for the Wave Business APIs.
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export { WaveClient } from './client/wave-client.js';
|
|
8
|
+
|
|
9
|
+
export type {
|
|
10
|
+
RetryOptions,
|
|
11
|
+
RequestOptions,
|
|
12
|
+
WaveClientOptions,
|
|
13
|
+
WaveLogger,
|
|
14
|
+
} from './core/types/configuration.js';
|
|
15
|
+
export type {
|
|
16
|
+
Amount,
|
|
17
|
+
CurrencyCode,
|
|
18
|
+
PageInfo,
|
|
19
|
+
PaginatedResponse,
|
|
20
|
+
PhoneNumber,
|
|
21
|
+
Timestamp,
|
|
22
|
+
ValidationErrorDetail,
|
|
23
|
+
} from './core/types/common.js';
|
|
24
|
+
export type { JsonObject, JsonPrimitive, JsonValue } from './core/types/json.js';
|
|
25
|
+
|
|
26
|
+
export type { FetchLike } from './core/http/fetch-transport.js';
|
|
27
|
+
export { FetchTransport } from './core/http/fetch-transport.js';
|
|
28
|
+
export type { TransportRequest, TransportResponse, WaveTransport } from './core/http/transport.js';
|
|
29
|
+
export { DEFAULT_BASE_URL, DEFAULT_TIMEOUT_MS } from './core/http/http-client.js';
|
|
30
|
+
|
|
31
|
+
export { WaveConfigurationError, WaveError } from './core/errors/wave-error.js';
|
|
32
|
+
export type { WaveErrorOptions } from './core/errors/wave-error.js';
|
|
33
|
+
export {
|
|
34
|
+
WaveApiError,
|
|
35
|
+
WaveAuthenticationError,
|
|
36
|
+
WaveAuthorizationError,
|
|
37
|
+
WaveConflictError,
|
|
38
|
+
WaveNotFoundError,
|
|
39
|
+
WaveRateLimitError,
|
|
40
|
+
WaveServerError,
|
|
41
|
+
WaveValidationError,
|
|
42
|
+
} from './core/errors/wave-api-error.js';
|
|
43
|
+
export type {
|
|
44
|
+
WaveApiErrorOptions,
|
|
45
|
+
WaveRateLimitErrorOptions,
|
|
46
|
+
} from './core/errors/wave-api-error.js';
|
|
47
|
+
export {
|
|
48
|
+
WaveAbortError,
|
|
49
|
+
WaveNetworkError,
|
|
50
|
+
WaveTimeoutError,
|
|
51
|
+
} from './core/errors/wave-network-error.js';
|
|
52
|
+
export { WaveWebhookVerificationError } from './core/errors/wave-webhook-verification-error.js';
|
|
53
|
+
export type { WebhookVerificationFailureReason } from './core/errors/wave-webhook-verification-error.js';
|
|
54
|
+
export { REDACTED, redactSecrets } from './core/errors/redact.js';
|
|
55
|
+
|
|
56
|
+
export { DEFAULT_RETRY_OPTIONS } from './core/retry/retry-policy.js';
|
|
57
|
+
export {
|
|
58
|
+
MAX_IDEMPOTENCY_KEY_LENGTH,
|
|
59
|
+
generateIdempotencyKey,
|
|
60
|
+
} from './core/idempotency/idempotency.js';
|
|
61
|
+
|
|
62
|
+
export { PayoutsResource } from './resources/payouts/payouts.js';
|
|
63
|
+
export type {
|
|
64
|
+
CreatePayoutBatchRequest,
|
|
65
|
+
CreatePayoutBatchResponse,
|
|
66
|
+
CreatePayoutRequest,
|
|
67
|
+
NameMatch,
|
|
68
|
+
NationalIdMatch,
|
|
69
|
+
Payout,
|
|
70
|
+
PayoutBatch,
|
|
71
|
+
PayoutBatchStatus,
|
|
72
|
+
PayoutError,
|
|
73
|
+
PayoutStatus,
|
|
74
|
+
RecipientVerification,
|
|
75
|
+
SearchPayoutsQuery,
|
|
76
|
+
SearchPayoutsResponse,
|
|
77
|
+
VerifyRecipientRequest,
|
|
78
|
+
} from './resources/payouts/payout-types.js';
|
|
79
|
+
export { PayoutBatchesResource } from './resources/payout-batches/payout-batches.js';
|
|
80
|
+
|
|
81
|
+
export { BalanceResource } from './resources/balance/balance.js';
|
|
82
|
+
export type { Balance, RetrieveBalanceQuery } from './resources/balance/balance-types.js';
|
|
83
|
+
|
|
84
|
+
export { ReconciliationResource } from './resources/reconciliation/reconciliation.js';
|
|
85
|
+
export type {
|
|
86
|
+
ListTransactionsQuery,
|
|
87
|
+
Transaction,
|
|
88
|
+
TransactionPage,
|
|
89
|
+
TransactionType,
|
|
90
|
+
} from './resources/reconciliation/reconciliation-types.js';
|
|
91
|
+
|
|
92
|
+
export { CheckoutResource } from './resources/checkout/checkout.js';
|
|
93
|
+
export type {
|
|
94
|
+
CheckoutPaymentError,
|
|
95
|
+
CheckoutSession,
|
|
96
|
+
CheckoutStatus,
|
|
97
|
+
CreateCheckoutSessionRequest,
|
|
98
|
+
PaymentStatus,
|
|
99
|
+
SearchCheckoutSessionsQuery,
|
|
100
|
+
SearchCheckoutSessionsResponse,
|
|
101
|
+
} from './resources/checkout/checkout-types.js';
|
|
102
|
+
|
|
103
|
+
export { AggregatedMerchantsResource } from './resources/aggregated-merchants/aggregated-merchants.js';
|
|
104
|
+
export type {
|
|
105
|
+
AggregatedMerchant,
|
|
106
|
+
AggregatedMerchantRequest,
|
|
107
|
+
AggregatedMerchantsPage,
|
|
108
|
+
BusinessType,
|
|
109
|
+
FeeStructure,
|
|
110
|
+
ListAggregatedMerchantsQuery,
|
|
111
|
+
} from './resources/aggregated-merchants/aggregated-merchant-types.js';
|
|
112
|
+
|
|
113
|
+
export {
|
|
114
|
+
DEFAULT_WEBHOOK_TOLERANCE_SECONDS,
|
|
115
|
+
WaveWebhooks,
|
|
116
|
+
computeWebhookSignature,
|
|
117
|
+
constructWaveWebhookEvent,
|
|
118
|
+
parseWebhookSignatureHeader,
|
|
119
|
+
verifyWaveWebhookSharedSecret,
|
|
120
|
+
verifyWaveWebhookSignature,
|
|
121
|
+
} from './resources/webhooks/webhook-verifier.js';
|
|
122
|
+
export type {
|
|
123
|
+
VerifySharedSecretInput,
|
|
124
|
+
VerifyWebhookSignatureInput,
|
|
125
|
+
} from './resources/webhooks/webhook-verifier.js';
|
|
126
|
+
export {
|
|
127
|
+
isKnownWebhookEventType,
|
|
128
|
+
toKnownWebhookEvent,
|
|
129
|
+
} from './resources/webhooks/webhook-types.js';
|
|
130
|
+
export type {
|
|
131
|
+
B2BPaymentFailedEvent,
|
|
132
|
+
B2BPaymentReceivedEvent,
|
|
133
|
+
B2BPaymentReceivedEventData,
|
|
134
|
+
CheckoutSessionCompletedEvent,
|
|
135
|
+
CheckoutSessionCompletedEventData,
|
|
136
|
+
CheckoutSessionPaymentFailedEvent,
|
|
137
|
+
CheckoutSessionPaymentFailedEventData,
|
|
138
|
+
KnownWebhookEvent,
|
|
139
|
+
KnownWebhookEventType,
|
|
140
|
+
MerchantPaymentReceivedEvent,
|
|
141
|
+
MerchantPaymentReceivedEventData,
|
|
142
|
+
RemittanceDeliveredEvent,
|
|
143
|
+
RemittanceReversedEvent,
|
|
144
|
+
TestWebhookEvent,
|
|
145
|
+
WebhookEvent,
|
|
146
|
+
} from './resources/webhooks/webhook-types.js';
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { PaginatedResponse, Timestamp } from '../../core/types/common.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Documented aggregated merchant business types.
|
|
5
|
+
*/
|
|
6
|
+
export type BusinessType = 'fintech' | 'other';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Documented aggregated merchant fee structures.
|
|
10
|
+
*/
|
|
11
|
+
export type FeeStructure = 'one_percent' | 'one_fifty_bps' | 'two_percent';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Request body for creating or updating an aggregated merchant.
|
|
15
|
+
*/
|
|
16
|
+
export interface AggregatedMerchantRequest {
|
|
17
|
+
/** Unique merchant name, up to 255 characters. */
|
|
18
|
+
readonly name: string;
|
|
19
|
+
/** Asserted business type. */
|
|
20
|
+
readonly business_type: BusinessType;
|
|
21
|
+
/** Description of the business. */
|
|
22
|
+
readonly business_description: string;
|
|
23
|
+
/** Business registration information, up to 255 characters. */
|
|
24
|
+
readonly business_registration_identifier?: string;
|
|
25
|
+
/** Free-form business sector, up to 255 characters. */
|
|
26
|
+
readonly business_sector?: string;
|
|
27
|
+
/** Website URL, up to 2083 characters. */
|
|
28
|
+
readonly website_url?: string;
|
|
29
|
+
/** Name of the business manager. */
|
|
30
|
+
readonly manager_name?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* An aggregated merchant returned by the API.
|
|
35
|
+
*/
|
|
36
|
+
export interface AggregatedMerchant {
|
|
37
|
+
/** Unique identifier, up to 20 characters. */
|
|
38
|
+
readonly id: string;
|
|
39
|
+
/** Merchant name. */
|
|
40
|
+
readonly name: string;
|
|
41
|
+
/** Asserted business type. */
|
|
42
|
+
readonly business_type: BusinessType;
|
|
43
|
+
/** Description of the business. */
|
|
44
|
+
readonly business_description: string;
|
|
45
|
+
/** Fee structure used for payouts. */
|
|
46
|
+
readonly payout_fee_structure_name: FeeStructure;
|
|
47
|
+
/** Fee structure used for checkouts. */
|
|
48
|
+
readonly checkout_fee_structure_name: FeeStructure;
|
|
49
|
+
/** Whether Wave locked further updates to this merchant. */
|
|
50
|
+
readonly is_locked: boolean;
|
|
51
|
+
/** When the merchant was created. */
|
|
52
|
+
readonly when_created: Timestamp;
|
|
53
|
+
/**
|
|
54
|
+
* Business registration identifier.
|
|
55
|
+
*
|
|
56
|
+
* Wave's response table names this field `business_registration_id`, while its examples return
|
|
57
|
+
* `business_registration_identifier`. Both are typed as optional so either shape is accepted.
|
|
58
|
+
*/
|
|
59
|
+
readonly business_registration_id?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Business registration identifier as returned by Wave's examples.
|
|
62
|
+
*
|
|
63
|
+
* @see business_registration_id
|
|
64
|
+
*/
|
|
65
|
+
readonly business_registration_identifier?: string;
|
|
66
|
+
/** Free-form business sector; can be `null` when not provided. */
|
|
67
|
+
readonly business_sector?: string | null;
|
|
68
|
+
/** Website URL, when provided. */
|
|
69
|
+
readonly website_url?: string;
|
|
70
|
+
/** Business manager name, when provided. */
|
|
71
|
+
readonly manager_name?: string;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Cursor-paginated aggregated merchant response.
|
|
76
|
+
*/
|
|
77
|
+
export type AggregatedMerchantsPage = PaginatedResponse<AggregatedMerchant>;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Query parameters for `GET /v1/aggregated_merchants`.
|
|
81
|
+
*/
|
|
82
|
+
export interface ListAggregatedMerchantsQuery {
|
|
83
|
+
/** Maximum number of items to retrieve. */
|
|
84
|
+
readonly first?: number;
|
|
85
|
+
/** Opaque cursor from the previous page. */
|
|
86
|
+
readonly after?: string;
|
|
87
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import type { HttpClient } from '../../core/http/http-client.js';
|
|
2
|
+
import type { QueryParameterValue } from '../../core/http/query.js';
|
|
3
|
+
import type { RequestOptions } from '../../core/types/configuration.js';
|
|
4
|
+
import type {
|
|
5
|
+
AggregatedMerchant,
|
|
6
|
+
AggregatedMerchantRequest,
|
|
7
|
+
AggregatedMerchantsPage,
|
|
8
|
+
ListAggregatedMerchantsQuery,
|
|
9
|
+
} from './aggregated-merchant-types.js';
|
|
10
|
+
|
|
11
|
+
const LIST_MERCHANTS = { idempotent: true, requiresIdempotencyKey: false } as const;
|
|
12
|
+
const CREATE_MERCHANT = { idempotent: false, requiresIdempotencyKey: false } as const;
|
|
13
|
+
const GET_MERCHANT = { idempotent: true, requiresIdempotencyKey: false } as const;
|
|
14
|
+
const UPDATE_MERCHANT = { idempotent: true, requiresIdempotencyKey: false } as const;
|
|
15
|
+
const DELETE_MERCHANT = { idempotent: true, requiresIdempotencyKey: false } as const;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Aggregated Merchants API operations.
|
|
19
|
+
*/
|
|
20
|
+
export class AggregatedMerchantsResource {
|
|
21
|
+
readonly #http: HttpClient;
|
|
22
|
+
|
|
23
|
+
/** @param http - Shared HTTP pipeline. */
|
|
24
|
+
constructor(http: HttpClient) {
|
|
25
|
+
this.#http = http;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Retrieves a page of aggregated merchants available to the account.
|
|
30
|
+
*
|
|
31
|
+
* @param query - Cursor pagination parameters.
|
|
32
|
+
* @param options - Per-request overrides.
|
|
33
|
+
* @returns One page of aggregated merchants.
|
|
34
|
+
*/
|
|
35
|
+
list(
|
|
36
|
+
query: ListAggregatedMerchantsQuery = {},
|
|
37
|
+
options: RequestOptions = {},
|
|
38
|
+
): Promise<AggregatedMerchantsPage> {
|
|
39
|
+
return this.#http.request<AggregatedMerchantsPage>(
|
|
40
|
+
LIST_MERCHANTS,
|
|
41
|
+
{ method: 'GET', path: '/v1/aggregated_merchants', query: toQuery(query) },
|
|
42
|
+
options,
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Iterates every aggregated merchant, following pagination cursors.
|
|
48
|
+
*
|
|
49
|
+
* @param query - Cursor and page-size options; `after` is managed automatically.
|
|
50
|
+
* @param options - Per-request overrides applied to every page request.
|
|
51
|
+
* @yields Each aggregated merchant.
|
|
52
|
+
*/
|
|
53
|
+
async *iterate(
|
|
54
|
+
query: ListAggregatedMerchantsQuery = {},
|
|
55
|
+
options: RequestOptions = {},
|
|
56
|
+
): AsyncGenerator<AggregatedMerchant, void, undefined> {
|
|
57
|
+
let after = query.after;
|
|
58
|
+
|
|
59
|
+
for (;;) {
|
|
60
|
+
const page = await this.list(
|
|
61
|
+
{ ...query, ...(after === undefined ? {} : { after }) },
|
|
62
|
+
options,
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
for (const merchant of page.items) {
|
|
66
|
+
yield merchant;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (!page.page_info.has_next_page) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const nextCursor = page.page_info.end_cursor;
|
|
74
|
+
if (nextCursor === null || nextCursor === after) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
after = nextCursor;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Creates an aggregated merchant.
|
|
83
|
+
*
|
|
84
|
+
* Merchant names must be unique. Wave does not document an idempotency mechanism for this
|
|
85
|
+
* endpoint, so the SDK never retries it automatically.
|
|
86
|
+
*
|
|
87
|
+
* @param request - Merchant details.
|
|
88
|
+
* @param options - Per-request overrides.
|
|
89
|
+
* @returns The created merchant.
|
|
90
|
+
*/
|
|
91
|
+
create(
|
|
92
|
+
request: AggregatedMerchantRequest,
|
|
93
|
+
options: RequestOptions = {},
|
|
94
|
+
): Promise<AggregatedMerchant> {
|
|
95
|
+
return this.#http.request<AggregatedMerchant>(
|
|
96
|
+
CREATE_MERCHANT,
|
|
97
|
+
{ method: 'POST', path: '/v1/aggregated_merchants', body: request },
|
|
98
|
+
options,
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Retrieves a single aggregated merchant.
|
|
104
|
+
*
|
|
105
|
+
* @param merchantId - Merchant identifier starting with `am-`.
|
|
106
|
+
* @param options - Per-request overrides.
|
|
107
|
+
* @returns The aggregated merchant.
|
|
108
|
+
*/
|
|
109
|
+
retrieve(merchantId: string, options: RequestOptions = {}): Promise<AggregatedMerchant> {
|
|
110
|
+
return this.#http.request<AggregatedMerchant>(
|
|
111
|
+
GET_MERCHANT,
|
|
112
|
+
{ method: 'GET', path: `/v1/aggregated_merchants/${encodeURIComponent(merchantId)}` },
|
|
113
|
+
options,
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Updates an aggregated merchant.
|
|
119
|
+
*
|
|
120
|
+
* Wave returns HTTP 403 with `record-locked` once the merchant is locked after review.
|
|
121
|
+
*
|
|
122
|
+
* @param merchantId - Merchant identifier starting with `am-`.
|
|
123
|
+
* @param request - Replacement merchant details.
|
|
124
|
+
* @param options - Per-request overrides.
|
|
125
|
+
* @returns The updated merchant.
|
|
126
|
+
*/
|
|
127
|
+
update(
|
|
128
|
+
merchantId: string,
|
|
129
|
+
request: AggregatedMerchantRequest,
|
|
130
|
+
options: RequestOptions = {},
|
|
131
|
+
): Promise<AggregatedMerchant> {
|
|
132
|
+
return this.#http.request<AggregatedMerchant>(
|
|
133
|
+
UPDATE_MERCHANT,
|
|
134
|
+
{
|
|
135
|
+
method: 'PUT',
|
|
136
|
+
path: `/v1/aggregated_merchants/${encodeURIComponent(merchantId)}`,
|
|
137
|
+
body: request,
|
|
138
|
+
},
|
|
139
|
+
options,
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Deletes an aggregated merchant.
|
|
145
|
+
*
|
|
146
|
+
* Wave returns HTTP 204 with no body on success.
|
|
147
|
+
*
|
|
148
|
+
* @param merchantId - Merchant identifier starting with `am-`.
|
|
149
|
+
* @param options - Per-request overrides.
|
|
150
|
+
*/
|
|
151
|
+
delete(merchantId: string, options: RequestOptions = {}): Promise<void> {
|
|
152
|
+
return this.#http.requestVoid(
|
|
153
|
+
DELETE_MERCHANT,
|
|
154
|
+
{ method: 'DELETE', path: `/v1/aggregated_merchants/${encodeURIComponent(merchantId)}` },
|
|
155
|
+
options,
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function toQuery(
|
|
161
|
+
query: ListAggregatedMerchantsQuery,
|
|
162
|
+
): Readonly<Record<string, QueryParameterValue>> {
|
|
163
|
+
const result: Record<string, QueryParameterValue> = {};
|
|
164
|
+
if (query.first !== undefined) {
|
|
165
|
+
result['first'] = query.first;
|
|
166
|
+
}
|
|
167
|
+
if (query.after !== undefined) {
|
|
168
|
+
result['after'] = query.after;
|
|
169
|
+
}
|
|
170
|
+
return result;
|
|
171
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Amount, CurrencyCode } from '../../core/types/common.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The Balance object.
|
|
5
|
+
*/
|
|
6
|
+
export interface Balance {
|
|
7
|
+
/** Balance amount. */
|
|
8
|
+
readonly amount: Amount;
|
|
9
|
+
/** Three-letter ISO 4217 currency code. */
|
|
10
|
+
readonly currency: CurrencyCode;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Query parameters for `GET /v1/balance`.
|
|
15
|
+
*/
|
|
16
|
+
export interface RetrieveBalanceQuery {
|
|
17
|
+
/** Include readable subaccount balances in the total. */
|
|
18
|
+
readonly include_subaccounts?: boolean;
|
|
19
|
+
}
|