@klappay/types 5.1.0 → 5.1.1
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/dist/{chunk-UEXXRQL3.mjs → chunk-VL7W6KNP.mjs} +2 -5
- package/dist/chunk-VL7W6KNP.mjs.map +1 -0
- package/dist/{constants-Cs8wjvTI.d.mts → constants-DpqgXUf_.d.mts} +1 -2
- package/dist/{constants-Cs8wjvTI.d.ts → constants-DpqgXUf_.d.ts} +1 -2
- package/dist/constants.d.mts +1 -1
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +1 -10
- package/dist/constants.js.map +1 -1
- package/dist/constants.mjs +1 -1
- package/dist/index.d.mts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +304 -301
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-UEXXRQL3.mjs.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
NETWORK_FAMILIES,
|
|
8
8
|
NETWORK_LABELS,
|
|
9
9
|
OPERATIONAL_NETWORKS,
|
|
10
|
-
SplitAddressSchema,
|
|
11
10
|
TOKEN_ADDRESSES,
|
|
12
11
|
TOKEN_DECIMALS,
|
|
13
12
|
TOKEN_DEPLOYMENTS,
|
|
@@ -18,31 +17,35 @@ import {
|
|
|
18
17
|
isSplitAddress,
|
|
19
18
|
isTronAddress,
|
|
20
19
|
tronAddress
|
|
21
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-VL7W6KNP.mjs";
|
|
22
21
|
|
|
23
|
-
// src/
|
|
22
|
+
// src/addresses.ts
|
|
24
23
|
import { z } from "zod";
|
|
25
|
-
var
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
var SplitAddressSchema = z.string().refine(isSplitAddress, "must be a valid EVM (0x...) or TRON (T...) address");
|
|
25
|
+
|
|
26
|
+
// src/errors.ts
|
|
27
|
+
import { z as z2 } from "zod";
|
|
28
|
+
var ErrorPayloadSchema = z2.object({
|
|
29
|
+
error: z2.object({
|
|
30
|
+
code: z2.string().describe(
|
|
28
31
|
"A stable, machine-readable error identifier (e.g. `validation_error`, `charge_not_found`)."
|
|
29
32
|
),
|
|
30
|
-
message:
|
|
33
|
+
message: z2.string().describe(
|
|
31
34
|
"Human-readable explanation, safe to log or show a developer \u2014 not meant for end users."
|
|
32
35
|
),
|
|
33
|
-
param:
|
|
36
|
+
param: z2.string().optional().describe("Which request field the error refers to, when applicable.")
|
|
34
37
|
})
|
|
35
38
|
});
|
|
36
39
|
|
|
37
40
|
// src/environment.ts
|
|
38
|
-
import { z as
|
|
39
|
-
var EnvironmentSchema =
|
|
41
|
+
import { z as z3 } from "zod";
|
|
42
|
+
var EnvironmentSchema = z3.enum(["live", "test"]).describe(
|
|
40
43
|
"`live` or `test`, matching the `klap_live_.../klap_test_...` prefix of the API key that created or is scoped to this resource. `live` uses the selected network's mainnet with real funds; `test` uses its separately configured testnet. Token contracts and availability are resolved per network/environment; a missing test deployment never falls back to live."
|
|
41
44
|
);
|
|
42
45
|
|
|
43
46
|
// src/api-key-scopes.ts
|
|
44
|
-
import { z as
|
|
45
|
-
var ApiKeyScopeSchema =
|
|
47
|
+
import { z as z4 } from "zod";
|
|
48
|
+
var ApiKeyScopeSchema = z4.enum([
|
|
46
49
|
"charges:read",
|
|
47
50
|
"charges:write",
|
|
48
51
|
"webhooks:read",
|
|
@@ -74,42 +77,42 @@ function findConflictingScopes(scopes) {
|
|
|
74
77
|
}
|
|
75
78
|
|
|
76
79
|
// src/networks.ts
|
|
77
|
-
import { z as
|
|
78
|
-
var NetworkSchema =
|
|
80
|
+
import { z as z5 } from "zod";
|
|
81
|
+
var NetworkSchema = z5.enum(["base", "optimism", "polygon", "ethereum", "arbitrum", "avalanche", "bnb", "tron", "arc"]).describe("The blockchain a charge/payment is on.");
|
|
79
82
|
|
|
80
83
|
// src/pagination.ts
|
|
81
|
-
import { z as
|
|
84
|
+
import { z as z6 } from "zod";
|
|
82
85
|
var PAGINATION_LIMIT_MIN = 1;
|
|
83
86
|
var PAGINATION_LIMIT_MAX = 100;
|
|
84
87
|
var PAGINATION_LIMIT_DEFAULT = 20;
|
|
85
|
-
var PaginationQuerySchema =
|
|
86
|
-
limit:
|
|
88
|
+
var PaginationQuerySchema = z6.object({
|
|
89
|
+
limit: z6.coerce.number().min(PAGINATION_LIMIT_MIN).max(PAGINATION_LIMIT_MAX).default(PAGINATION_LIMIT_DEFAULT).describe(
|
|
87
90
|
`Max items to return per page (${PAGINATION_LIMIT_MIN}\u2013${PAGINATION_LIMIT_MAX}, default ${PAGINATION_LIMIT_DEFAULT}).`
|
|
88
91
|
),
|
|
89
|
-
cursor:
|
|
92
|
+
cursor: z6.string().max(500).optional().describe(
|
|
90
93
|
"Opaque \u2014 pass the previous response's `nextCursor` verbatim to fetch the next page. Never construct or parse this value yourself; its shape is not part of the public contract and may change."
|
|
91
94
|
)
|
|
92
95
|
});
|
|
93
96
|
function paginatedSchema(itemSchema) {
|
|
94
|
-
return
|
|
95
|
-
data:
|
|
96
|
-
nextCursor:
|
|
97
|
-
hasMore:
|
|
97
|
+
return z6.object({
|
|
98
|
+
data: z6.array(itemSchema),
|
|
99
|
+
nextCursor: z6.string().nullable().describe("Pass as `cursor` to fetch the next page. `null` when there are no more results."),
|
|
100
|
+
hasMore: z6.boolean()
|
|
98
101
|
});
|
|
99
102
|
}
|
|
100
103
|
|
|
101
104
|
// src/tokens.ts
|
|
102
|
-
import { z as
|
|
103
|
-
var TokenSchema =
|
|
105
|
+
import { z as z7 } from "zod";
|
|
106
|
+
var TokenSchema = z7.enum(["USDC", "USDT"]).describe(
|
|
104
107
|
"Which stablecoin the payer will send. Availability depends on `network` and `environment`; check `GET /v1/networks` before creating a charge. Unconfigured or disabled pairs are rejected with `422 token_not_supported`. Base, Optimism, and Ethereum have USDC test deployments; no test USDT is configured. The catalog includes both BNB Chain tokens for historical interpretation, but payments with either are currently disabled. Both configured BNB contracts are Binance-Peg tokens with 18 decimals; the other configured deployments use 6. Binance-Peg tokens carry Binance custody/backing risk and must not be represented as direct Circle/Tether issuance. Resolve address and decimals together with `getTokenDeployment`; a catalog entry alone does not imply payment availability."
|
|
105
108
|
);
|
|
106
109
|
|
|
107
110
|
// src/alt-tokens.ts
|
|
108
|
-
import { z as
|
|
109
|
-
var AltTokenSchema =
|
|
111
|
+
import { z as z8 } from "zod";
|
|
112
|
+
var AltTokenSchema = z8.enum(["ETH", "BNB", "POL", "AVAX", "BTC", "LINK", "ARB", "OP", "CBETH"]).describe(
|
|
110
113
|
"A non-stablecoin cryptocurrency Klappay trusts as swap input for a charge, via the 0x Swap API \u2014 swapped to one of the charge's `acceptedPayments` tokens before it ever reaches the merchant, so the merchant always receives USDC/USDT regardless of what the payer sent. Trusted on a given network only when it has deep, reputably-issued/custodied liquidity there: each network's own native currency, `BTC` (wrapped) on the networks with a trusted deployment, `LINK` (Chainlink's own official per-chain deployment, except Avalanche's bridged `LINK.e`), and a small set of chain-specific blue chips (`ARB` on Arbitrum, `OP` on Optimism, `CBETH` on Base) \u2014 see `ALT_TOKEN_ADDRESSES` for the authoritative per-network list, never assume every value here is available on every network. `POL` replaced `MATIC` as Polygon's native currency name (Polygon's own token migration, 2024) \u2014 this schema tracks the network's current native asset, not the deprecated ticker."
|
|
111
114
|
);
|
|
112
|
-
var SwapAlternativeSchema =
|
|
115
|
+
var SwapAlternativeSchema = z8.object({
|
|
113
116
|
token: AltTokenSchema,
|
|
114
117
|
network: NetworkSchema.describe(
|
|
115
118
|
"Which network to send `token` on \u2014 pass both as `inputToken`/`inputNetwork` to `POST /v1/charges/{id}/quote`. The same token can appear more than once here, once per network that trusts it and that this charge accepts payment on."
|
|
@@ -126,77 +129,77 @@ function listSwapAlternatives(networks) {
|
|
|
126
129
|
}
|
|
127
130
|
|
|
128
131
|
// src/charges.ts
|
|
129
|
-
import { z as
|
|
132
|
+
import { z as z12 } from "zod";
|
|
130
133
|
|
|
131
134
|
// src/checkout-metadata.ts
|
|
132
|
-
import { z as
|
|
135
|
+
import { z as z9 } from "zod";
|
|
133
136
|
var CHECKOUT_PRODUCTS_MAX = 20;
|
|
134
|
-
var CheckoutProductSchema =
|
|
135
|
-
name:
|
|
136
|
-
quantity:
|
|
137
|
-
imageUrl:
|
|
137
|
+
var CheckoutProductSchema = z9.object({
|
|
138
|
+
name: z9.string().min(1).max(200).describe("What the payer is buying, shown as-is on the hosted checkout page."),
|
|
139
|
+
quantity: z9.number().int().positive().max(9999).optional().describe("How many of this item. Omit for a single, unquantified item."),
|
|
140
|
+
imageUrl: z9.string().url().max(2048).refine((value) => /^https?:\/\//.test(value), "must use http or https").optional().describe(
|
|
138
141
|
"Product image, fetched only by the payer's own browser \u2014 Klappay never fetches it server-side. Must be `http(s)`."
|
|
139
142
|
)
|
|
140
143
|
});
|
|
141
|
-
var KlappayCheckoutMetadataSchema =
|
|
142
|
-
products:
|
|
144
|
+
var KlappayCheckoutMetadataSchema = z9.object({
|
|
145
|
+
products: z9.array(CheckoutProductSchema).max(CHECKOUT_PRODUCTS_MAX).optional().describe(
|
|
143
146
|
`What the payer is buying, shown on the hosted checkout page \u2014 up to ${CHECKOUT_PRODUCTS_MAX} items. Purely informational: never validated against \`amount\`, never used by any payment or distribution logic.`
|
|
144
147
|
)
|
|
145
148
|
}).describe(
|
|
146
149
|
"Reserved for Klappay \u2014 the one namespace inside `metadata` whose format is defined and enforced by Klappay, not by you. A `metadata.klappay` that does not match this shape is rejected outright (`400 validation_error`), unlike every other key in `metadata`, which accepts absolutely anything and never fails validation."
|
|
147
150
|
);
|
|
148
|
-
var MetadataWithKlappaySchema =
|
|
151
|
+
var MetadataWithKlappaySchema = z9.object({ klappay: KlappayCheckoutMetadataSchema.optional() }).catchall(z9.unknown()).describe(
|
|
149
152
|
"Arbitrary key/value data, returned as-is on every read. Put whatever you want in here \u2014 none of it is validated, except the `klappay` key, which is reserved for Klappay: if present, it must match `KlappayCheckoutMetadataSchema` exactly, or the whole request is rejected with `400 validation_error`."
|
|
150
153
|
);
|
|
151
154
|
|
|
152
155
|
// src/escrow.ts
|
|
153
|
-
import { z as
|
|
154
|
-
var EscrowConfigSchema =
|
|
155
|
-
releaserAddress:
|
|
156
|
+
import { z as z10 } from "zod";
|
|
157
|
+
var EscrowConfigSchema = z10.object({
|
|
158
|
+
releaserAddress: z10.string().regex(/^0x[0-9a-fA-F]{40}$/, "must be a 20-byte hex address").optional().describe(
|
|
156
159
|
"The only address ever authorized to release this charge's escrowed funds \u2014 set once at creation, immutable after. Klappay never holds a key with any release authority of its own; every release requires a signature from this address, verified on-chain, never taken on faith. Omit to default to the API key's own `payoutAddress` \u2014 the common case where the merchant releasing their own charge is the same wallet they already get paid to. Pass an explicit address only when the releaser is a different party (e.g. an operational key distinct from the payout wallet). Not validated against anything else \u2014 any well-formed address is accepted, since Klappay never custodies these funds."
|
|
157
160
|
)
|
|
158
161
|
});
|
|
159
|
-
var ReleaseEscrowRequestSchema =
|
|
160
|
-
signature:
|
|
162
|
+
var ReleaseEscrowRequestSchema = z10.object({
|
|
163
|
+
signature: z10.string().regex(/^0x[0-9a-fA-F]+$/, "must be hex-encoded signature bytes").describe(
|
|
161
164
|
"The Safe transaction signature authorizing this release, produced by signing a transfer of the escrow's entire current token balance to the charge's already-frozen split address (the same split that would have received the payment on a normal, non-escrow charge) with the private key behind this charge's `escrowReleaserAddress` \u2014 never anything Klappay can produce itself. The destination is fixed by the charge's `splitConfig` (frozen at creation); the amount is read live on-chain at release time, not fixed in advance, so it always matches whatever actually arrived \u2014 reconstruct the exact transaction server-side computes (ERC-20 `transfer(splitAddress, balance)` from the escrow Safe, nonce 0) before signing. Independently verified on-chain before anything moves \u2014 the Safe contract itself rejects a signature that isn't from `escrowReleaserAddress`, never trusted at face value by Klappay."
|
|
162
165
|
)
|
|
163
166
|
});
|
|
164
|
-
var RefundEscrowRequestSchema =
|
|
165
|
-
signature:
|
|
167
|
+
var RefundEscrowRequestSchema = z10.object({
|
|
168
|
+
signature: z10.string().regex(/^0x[0-9a-fA-F]+$/, "must be hex-encoded signature bytes").describe(
|
|
166
169
|
"The Safe transaction signature authorizing this refund, produced by signing a transfer of the escrow's entire current token balance back to the address that funded this charge (`Charge.payerAddress`, captured from the credited transfer) with the private key behind this charge's `escrowReleaserAddress` \u2014 never anything Klappay can produce itself. The amount is read live on-chain at refund time, not fixed in advance, so it always matches whatever actually arrived \u2014 reconstruct the exact transaction Klappay computes server-side (ERC-20 `transfer(payerAddress, balance)` from the escrow Safe, nonce 0) before signing. Independently verified on-chain before anything moves \u2014 the Safe contract itself rejects a signature that isn't from `escrowReleaserAddress`, never trusted at face value by Klappay."
|
|
167
170
|
)
|
|
168
171
|
});
|
|
169
172
|
|
|
170
173
|
// src/exact-amount.ts
|
|
171
|
-
import { z as
|
|
172
|
-
var ExactAmountSchema =
|
|
174
|
+
import { z as z11 } from "zod";
|
|
175
|
+
var ExactAmountSchema = z11.string().regex(/^(0|[1-9]\d*)(?:\.\d{1,18})?$(?!\s)/).describe(
|
|
173
176
|
"Nonnegative amount in whole currency/token units, as a decimal string with at most 18 fractional digits and no scientific notation."
|
|
174
177
|
);
|
|
175
178
|
|
|
176
179
|
// src/charges.ts
|
|
177
|
-
var ChargeStatusSchema =
|
|
180
|
+
var ChargeStatusSchema = z12.enum(["pending", "partially_paid", "confirmed", "expired", "underpaid"]).describe(
|
|
178
181
|
"Payment progress, from the payer side. `pending`: created, nothing received yet. `partially_paid`: some funds received, less than `amount`. `confirmed`: full amount received (or more \u2014 see `isOverpaid`). `expired`: `expiresAt` passed with zero funds received. `underpaid`: `expiresAt` passed while `partially_paid`. Every status is reached automatically, on its own timeline \u2014 there is no merchant-initiated cancellation. This never reflects whether funds actually reached the merchant \u2014 see `settlementStatus` for that."
|
|
179
182
|
);
|
|
180
|
-
var SettlementStatusSchema =
|
|
183
|
+
var SettlementStatusSchema = z12.enum(["pending", "completed", "failed"]).describe(
|
|
181
184
|
"Progress of the payout to the merchant's wallet, a separate step from `status` \u2014 `status: confirmed` only means the payment was detected on-chain, not that the merchant has been paid yet. `pending`: payment detected, payout not yet attempted. `completed`: the merchant's wallet has the funds. `failed`: the payout attempt failed and retries were exhausted (rare; contact support). `null` on the parent `Charge` means no payout has been attempted yet \u2014 nothing has been received, or the charge is still in progress."
|
|
182
185
|
);
|
|
183
|
-
var ChargeFeePayerSchema =
|
|
186
|
+
var ChargeFeePayerSchema = z12.enum(["merchant", "payer"]).describe(
|
|
184
187
|
"Who ends up covering Klappay's `feePercent`. `merchant` (default): `amount` is exactly what you asked for, and Klappay's fee is deducted from your own payout \u2014 you net `amount * (1 - feePercent / 100)`. `payer` : `amount` is grossed up at creation time so that, after the same fee deduction, you still net the amount you originally requested \u2014 the payer sees and sends the larger, fee-inclusive total. Frozen at creation like every other fee input; does not change how `feeAmount`/`merchantAmount` are computed on read, only what `amount` was set to in the first place."
|
|
185
188
|
);
|
|
186
189
|
var CHARGE_EXPIRES_IN_MIN_SECONDS = 60;
|
|
187
190
|
var CHARGE_EXPIRES_IN_MAX_SECONDS = 3600;
|
|
188
191
|
var CHARGE_ACCEPTED_PAYMENTS_MAX = 18;
|
|
189
|
-
var AcceptedPaymentSchema =
|
|
192
|
+
var AcceptedPaymentSchema = z12.object({
|
|
190
193
|
token: TokenSchema,
|
|
191
194
|
network: NetworkSchema
|
|
192
195
|
});
|
|
193
|
-
var AcceptedPaymentsSchema =
|
|
196
|
+
var AcceptedPaymentsSchema = z12.array(AcceptedPaymentSchema).min(1, "At least one accepted payment is required.").max(CHARGE_ACCEPTED_PAYMENTS_MAX).superRefine((pairs, ctx) => {
|
|
194
197
|
const seen = /* @__PURE__ */ new Set();
|
|
195
198
|
pairs.forEach((pair, index) => {
|
|
196
199
|
const key = `${pair.token}:${pair.network}`;
|
|
197
200
|
if (seen.has(key)) {
|
|
198
201
|
ctx.addIssue({
|
|
199
|
-
code:
|
|
202
|
+
code: z12.ZodIssueCode.custom,
|
|
200
203
|
message: `Duplicate accepted payment: ${pair.token} on ${pair.network}.`,
|
|
201
204
|
path: [index]
|
|
202
205
|
});
|
|
@@ -204,7 +207,7 @@ var AcceptedPaymentsSchema = z11.array(AcceptedPaymentSchema).min(1, "At least o
|
|
|
204
207
|
seen.add(key);
|
|
205
208
|
if (!OPERATIONAL_NETWORKS.some((network) => network === pair.network)) {
|
|
206
209
|
ctx.addIssue({
|
|
207
|
-
code:
|
|
210
|
+
code: z12.ZodIssueCode.custom,
|
|
208
211
|
message: `Network "${pair.network}" isn't live yet \u2014 only ${OPERATIONAL_NETWORKS.join(", ")} today.`,
|
|
209
212
|
path: [index, "network"]
|
|
210
213
|
});
|
|
@@ -213,7 +216,7 @@ var AcceptedPaymentsSchema = z11.array(AcceptedPaymentSchema).min(1, "At least o
|
|
|
213
216
|
const families = new Set(pairs.map((pair) => NETWORK_FAMILIES[pair.network]));
|
|
214
217
|
if (families.size > 1) {
|
|
215
218
|
ctx.addIssue({
|
|
216
|
-
code:
|
|
219
|
+
code: z12.ZodIssueCode.custom,
|
|
217
220
|
message: `acceptedPayments mixes networks from different split families (${[...families].sort().join(", ")}) \u2014 every network in this list must share the same underlying split factory, so a charge can only ever accept networks from one family at a time.`
|
|
218
221
|
});
|
|
219
222
|
}
|
|
@@ -221,34 +224,34 @@ var AcceptedPaymentsSchema = z11.array(AcceptedPaymentSchema).min(1, "At least o
|
|
|
221
224
|
`Every \`(token, network)\` pair the payer is allowed to pay with \u2014 at least one, up to ${CHARGE_ACCEPTED_PAYMENTS_MAX}. This list is also the only restriction knob: the payer can use any combination of the pairs listed here, and every transfer on one of them is credited and sums toward the charge total (see \`paidWith\`) \u2014 e.g. a charge accepting USDC and USDT can be confirmed by $9 in USDC plus $1 in USDT, or by USDC arriving on two different accepted networks. To require payment in one specific token on one specific network, list only that single pair \u2014 a transfer on any pair not in this list is still recorded (for audit) but never credited. Each network must be live (see \`GET /v1/networks\` for the current matrix) \u2014 an unconfigured \`(token, network)\` combination for your environment is rejected with \`422 token_not_supported\`. Every network listed must also share the same split family (which networks are grouped together is an implementation detail, not part of this API's contract) \u2014 a charge predicts one split address up front and reuses it across every accepted network, which is only safe within one family; mixing families is rejected with \`400 validation_error\`.`
|
|
222
225
|
);
|
|
223
226
|
var CHARGE_SPLIT_RECIPIENTS_MAX = 5;
|
|
224
|
-
var SplitRecipientSchema =
|
|
227
|
+
var SplitRecipientSchema = z12.object({
|
|
225
228
|
address: SplitAddressSchema.describe(
|
|
226
229
|
"Address to send a slice of this charge to \u2014 an EVM 0x... address or a TRON T... address, matching whichever network family the charge accepts (acceptedPayments can only ever list networks from one split family at a time, so this always matches that same family)."
|
|
227
230
|
),
|
|
228
|
-
percent:
|
|
231
|
+
percent: z12.number().positive().max(100).describe(
|
|
229
232
|
"Percent of *your own* net share (i.e. of `100 - feePercent`, not of the charge's gross `amount`) to route to this address instead of your own payout wallet. Klappay's fee is computed on the gross amount first and is never diluted by how you choose to split what's left \u2014 see `docs/payments.md`'s \"Settling the payout\" section for the exact math."
|
|
230
233
|
),
|
|
231
|
-
label:
|
|
234
|
+
label: z12.string().min(1).max(64).optional().describe(
|
|
232
235
|
'Free-form label for your own bookkeeping (e.g. `"supplier"`, `"sales rep"`) \u2014 echoed back unchanged, never interpreted by Klappay.'
|
|
233
236
|
)
|
|
234
237
|
});
|
|
235
|
-
var SplitRecipientInputSchema =
|
|
236
|
-
recipientId:
|
|
238
|
+
var SplitRecipientInputSchema = z12.object({
|
|
239
|
+
recipientId: z12.string().describe(
|
|
237
240
|
"id of a `Recipient` you already registered via `POST /v1/recipients` (not a raw address) \u2014 see `recipients:write`/`charges:split_write` scopes. A leaked `charges:write`-only key can never redirect payout to a brand new address this way, only reference one already trusted."
|
|
238
241
|
),
|
|
239
|
-
percent:
|
|
242
|
+
percent: z12.number().positive().max(100).describe(
|
|
240
243
|
"Percent of *your own* net share (i.e. of `100 - feePercent`, not of the charge's gross `amount`) to route to this recipient instead of your own payout wallet. Klappay's fee is computed on the gross amount first and is never diluted by how you choose to split what's left \u2014 see `docs/payments.md`'s \"Settling the payout\" section for the exact math."
|
|
241
244
|
),
|
|
242
|
-
label:
|
|
245
|
+
label: z12.string().min(1).max(64).optional().describe(
|
|
243
246
|
'Free-form label for your own bookkeeping (e.g. `"supplier"`, `"sales rep"`) \u2014 echoed back unchanged, never interpreted by Klappay. Independent of the label the recipient was registered with.'
|
|
244
247
|
)
|
|
245
248
|
});
|
|
246
|
-
var SplitRecipientsInputSchema =
|
|
249
|
+
var SplitRecipientsInputSchema = z12.array(SplitRecipientInputSchema).max(CHARGE_SPLIT_RECIPIENTS_MAX).superRefine((recipients, ctx) => {
|
|
247
250
|
const seen = /* @__PURE__ */ new Set();
|
|
248
251
|
recipients.forEach((recipient, index) => {
|
|
249
252
|
if (seen.has(recipient.recipientId)) {
|
|
250
253
|
ctx.addIssue({
|
|
251
|
-
code:
|
|
254
|
+
code: z12.ZodIssueCode.custom,
|
|
252
255
|
message: `Duplicate split recipientId: ${recipient.recipientId}.`,
|
|
253
256
|
path: [index, "recipientId"]
|
|
254
257
|
});
|
|
@@ -259,27 +262,27 @@ var SplitRecipientsInputSchema = z11.array(SplitRecipientInputSchema).max(CHARGE
|
|
|
259
262
|
`Optional extra recipients for this charge's split \u2014 e.g. a supplier or the sales rep who closed the deal \u2014 up to ${CHARGE_SPLIT_RECIPIENTS_MAX}, each referenced by \`recipientId\` (see \`POST /v1/recipients\`), never a raw address. Requires the \`charges:split_write\` scope in addition to \`charges:write\`. Frozen at creation exactly like everything else that shapes the split address; cannot be changed afterward. The sum of every \`percent\` here must fit within \`100 - feePercent\` (your own net share) \u2014 a request that doesn't is rejected with \`422 split_recipients_exceed_available_percent\`.`
|
|
260
263
|
);
|
|
261
264
|
var CHARGE_AMOUNT_MAX = 999999999999;
|
|
262
|
-
var CreateChargeSchema =
|
|
263
|
-
amount:
|
|
265
|
+
var CreateChargeSchema = z12.object({
|
|
266
|
+
amount: z12.number().positive().max(CHARGE_AMOUNT_MAX).describe(
|
|
264
267
|
"Amount to charge, in `currency` units (e.g. `49.9` = $49.90) \u2014 up to 6 decimal places; anything more precise is silently truncated. Required \u2014 every charge has a target amount, the first credited transfer that reaches it confirms the charge. With `feePayer: 'payer'` (see below), this is your own desired net amount, not the total the payer ends up sending \u2014 the response's `amount` is grossed up to cover `feePercent`, while `merchantAmount` on the response echoes back this exact value."
|
|
265
268
|
),
|
|
266
269
|
feePayer: ChargeFeePayerSchema.optional().default("merchant"),
|
|
267
|
-
currency:
|
|
270
|
+
currency: z12.literal("USD").default("USD").describe("Always `USD` today \u2014 the only supported currency."),
|
|
268
271
|
acceptedPayments: AcceptedPaymentsSchema,
|
|
269
|
-
expiresIn:
|
|
272
|
+
expiresIn: z12.number().int().min(CHARGE_EXPIRES_IN_MIN_SECONDS).max(CHARGE_EXPIRES_IN_MAX_SECONDS).describe(
|
|
270
273
|
"Seconds, not minutes or milliseconds \u2014 how long the charge stays open before it expires. Required, min 60, max 3600 (60 minutes) \u2014 sized off the slowest chain Klappay supports today (Ethereum mainnet, where a safely-confirmed transfer takes up to ~15 minutes), leaving real margin for payer-side delay (gas spikes, wallet friction) on top of that. Cannot be extended or shortened after creation."
|
|
271
274
|
),
|
|
272
|
-
idempotencyKey:
|
|
275
|
+
idempotencyKey: z12.string().min(1).max(255).optional().describe(
|
|
273
276
|
"Scoped to your tenant. Replaying the same key with the exact same request body returns the original charge unchanged instead of creating a duplicate \u2014 safe to retry a request after a timeout without double-charging. Reusing the same key with a different body (including a different `escrow` config) is rejected with `409 idempotency_key_reused`, never silently returned as the original charge."
|
|
274
277
|
),
|
|
275
|
-
externalRef:
|
|
278
|
+
externalRef: z12.string().min(1).max(255).optional().describe(
|
|
276
279
|
"An opaque correlation id from your own system (e.g. an order id) \u2014 echoed back on the charge and in every webhook payload. Not interpreted or validated by Klappay."
|
|
277
280
|
),
|
|
278
|
-
source:
|
|
281
|
+
source: z12.string().min(1).max(64).optional().describe(
|
|
279
282
|
'Free-form label for what created this charge (e.g. `"checkout"`, `"invoice"`) \u2014 useful if you create charges from more than one flow and want to tell them apart later. Not a fixed enum; use whatever values make sense to you.'
|
|
280
283
|
),
|
|
281
284
|
metadata: MetadataWithKlappaySchema.optional(),
|
|
282
|
-
redirectUrl:
|
|
285
|
+
redirectUrl: z12.string().url().refine((value) => /^https?:\/\//.test(value), "must use http or https").optional().describe(
|
|
283
286
|
"Where to send the payer once this charge resolves, if you use Klappay's hosted checkout page (see `checkoutUrl` on the read shape) \u2014 ignored otherwise. Must be `http(s)` \u2014 a browser will navigate here, so `javascript:`/`data:` and other non-navigational schemes are rejected. Otherwise not validated beyond being well-formed; what happens at that destination is yours to build."
|
|
284
287
|
),
|
|
285
288
|
splitRecipients: SplitRecipientsInputSchema.optional(),
|
|
@@ -294,92 +297,92 @@ var CreateChargeSchema = z11.object({
|
|
|
294
297
|
);
|
|
295
298
|
if (hasUnsupportedNetwork) {
|
|
296
299
|
ctx.addIssue({
|
|
297
|
-
code:
|
|
300
|
+
code: z12.ZodIssueCode.custom,
|
|
298
301
|
message: "Escrow is not supported for this charge's network \u2014 Safe (the underlying custody contract) isn't an EVM chain there. Remove `escrow`, or accept payment on an EVM network instead.",
|
|
299
302
|
path: ["escrow"]
|
|
300
303
|
});
|
|
301
304
|
}
|
|
302
305
|
});
|
|
303
|
-
var ChargeSchema =
|
|
304
|
-
id:
|
|
305
|
-
amount:
|
|
306
|
+
var ChargeSchema = z12.object({
|
|
307
|
+
id: z12.string().describe("Klappay-generated id, e.g. `ch_...`. Use this to look up the charge later."),
|
|
308
|
+
amount: z12.number().describe(
|
|
306
309
|
"The total the payer must send, in `currency` units (up to 6 decimal places). This legacy JSON number can lose precision; use `amountExact` for calculations and payment preparation. With `feePayer: 'merchant'` (the default) this is what you requested at creation. With `feePayer: 'payer'` this is grossed up to cover `feePercent` \u2014 see `merchantAmount` for what you requested/will actually net."
|
|
307
310
|
),
|
|
308
311
|
amountExact: ExactAmountSchema.regex(/^(0|[1-9]\d*)(?:\.\d{1,6})?$/).optional().describe(
|
|
309
312
|
'Exact total the payer must send, in `currency` units, as a nonnegative decimal string with at most 6 fractional digits and no scientific notation (e.g. `"100.000001"`). Use this instead of `amount` for arithmetic. Optional for compatibility with older API responses.'
|
|
310
313
|
),
|
|
311
314
|
feePayer: ChargeFeePayerSchema,
|
|
312
|
-
feePercent:
|
|
315
|
+
feePercent: z12.number().describe(
|
|
313
316
|
"Klappay's fee for this charge, as a percent of `amount` (e.g. `2` = 2%) \u2014 includes any escrow surcharge if this charge is an escrow. Frozen at creation; see `feeAmount`/`merchantAmount` for the actual amounts this works out to."
|
|
314
317
|
),
|
|
315
|
-
feeAmount:
|
|
316
|
-
merchantAmount:
|
|
318
|
+
feeAmount: z12.number().describe("`amount * feePercent / 100`, in `currency` units \u2014 Klappay's cut of this charge."),
|
|
319
|
+
merchantAmount: z12.number().describe(
|
|
317
320
|
"`amount - feeAmount`, in `currency` units \u2014 what you actually net once the payout settles, regardless of `feePayer` (this is always what the split delivers to you; `feePayer` only affects what `amount` was set to at creation)."
|
|
318
321
|
),
|
|
319
|
-
amountReceived:
|
|
322
|
+
amountReceived: z12.number().nullable().describe(
|
|
320
323
|
"Cumulative amount received on-chain so far, in `currency` units. This legacy JSON number can lose precision; use `amountReceivedExact` for arithmetic with up to 18 fractional digits. `null` until the first transfer arrives. Can exceed `amount` \u2014 see `isOverpaid`."
|
|
321
324
|
),
|
|
322
325
|
amountReceivedExact: ExactAmountSchema.nullable().optional().describe(
|
|
323
326
|
'Exact cumulative amount received on-chain, in `currency` units, as a nonnegative decimal string with at most 18 fractional digits and no scientific notation (e.g. `"0.0000000001"`). `null` until the first transfer arrives. Can exceed `amountExact`. Optional for compatibility with older API responses.'
|
|
324
327
|
),
|
|
325
|
-
paymentUnavailable:
|
|
328
|
+
paymentUnavailable: z12.boolean().optional().describe(
|
|
326
329
|
"When `true`, payment processing for this charge is temporarily unavailable. Do not offer payment instructions, request another transfer, or fulfill from its monetary/status fields until availability is restored. The charge retains its existing business status. Optional for compatibility with older API responses."
|
|
327
330
|
),
|
|
328
|
-
isOverpaid:
|
|
331
|
+
isOverpaid: z12.boolean().describe(
|
|
329
332
|
"`true` if `amountReceived` ended up greater than `amount`. Klappay never refunds the difference automatically \u2014 see the docs for why."
|
|
330
333
|
),
|
|
331
|
-
currency:
|
|
332
|
-
acceptedPayments:
|
|
334
|
+
currency: z12.string().describe("Always `USD` today \u2014 the only supported currency."),
|
|
335
|
+
acceptedPayments: z12.array(AcceptedPaymentSchema).describe(
|
|
333
336
|
"Every `(token, network)` pair this charge was configured to accept, unchanged after creation."
|
|
334
337
|
),
|
|
335
|
-
paidWith:
|
|
338
|
+
paidWith: z12.array(AcceptedPaymentSchema).describe(
|
|
336
339
|
"Every distinct `(token, network)` pair that has actually contributed a credited transfer so far \u2014 empty until the first one arrives. Can hold more than one entry: a charge accepting several pairs can be paid across a combination of them, and every entry here sums toward `amountReceived`."
|
|
337
340
|
),
|
|
338
|
-
swapAlternatives:
|
|
341
|
+
swapAlternatives: z12.array(SwapAlternativeSchema).describe(
|
|
339
342
|
"Every `(token, network)` pair the payer can pay with instead, via `POST /v1/charges/{id}/quote` \u2014 derived from the networks in `acceptedPayments` (e.g. a charge accepting USDC on both Base and Optimism lists `ETH` on Base and `ETH` on Optimism separately, since they're different networks the payer has to choose between, not one merged option). Pass an entry's `token`/`network` straight through as `inputToken`/`inputNetwork`. Recomputed on every read against Klappay's current trusted list, not frozen at creation \u2014 empty if this charge's networks have no trusted alt-token, if swap-to-pay isn't configured on this deployment, or if `environment` is `test` (0x, who powers the swap, has no testnet support at all \u2014 `POST /v1/charges/{id}/quote` always rejects a test-environment charge with `422 swap_test_environment_unsupported`)."
|
|
340
343
|
),
|
|
341
|
-
address:
|
|
344
|
+
address: z12.string().describe(
|
|
342
345
|
"The on-chain address the payer must send funds to \u2014 identical across every accepted network (0xSplits addresses are chain-agnostic). Unique per charge, predicted at creation time \u2014 funds sent here go directly to the merchant, Klappay never custodies them."
|
|
343
346
|
),
|
|
344
347
|
status: ChargeStatusSchema,
|
|
345
348
|
settlementStatus: SettlementStatusSchema.nullable(),
|
|
346
349
|
environment: EnvironmentSchema,
|
|
347
|
-
apiKeyId:
|
|
350
|
+
apiKeyId: z12.string().nullable().describe(
|
|
348
351
|
"Which of your API keys created this charge. `null` for a charge created before this field existed."
|
|
349
352
|
),
|
|
350
|
-
txHash:
|
|
353
|
+
txHash: z12.string().nullable().describe(
|
|
351
354
|
"Transaction hash of the most recent transfer detected for this charge. `null` until a payment is detected."
|
|
352
355
|
),
|
|
353
|
-
externalRef:
|
|
354
|
-
source:
|
|
356
|
+
externalRef: z12.string().nullable(),
|
|
357
|
+
source: z12.string().nullable(),
|
|
355
358
|
metadata: MetadataWithKlappaySchema.nullable(),
|
|
356
|
-
redirectUrl:
|
|
357
|
-
checkoutUrl:
|
|
359
|
+
redirectUrl: z12.string().nullable().describe("Echoes the `redirectUrl` set at creation, if any. `null` if none was set."),
|
|
360
|
+
checkoutUrl: z12.string().nullable().describe(
|
|
358
361
|
"Link to Klappay's hosted checkout page for this charge. `null` if this deployment has no hosted checkout configured \u2014 build your own payment UI from `address`/`acceptedPayments` instead."
|
|
359
362
|
),
|
|
360
|
-
splitRecipients:
|
|
361
|
-
createdAt:
|
|
362
|
-
expiresAt:
|
|
363
|
+
splitRecipients: z12.array(SplitRecipientSchema).describe("Echoes whatever extra split recipients were set at creation \u2014 empty array if none."),
|
|
364
|
+
createdAt: z12.string().datetime(),
|
|
365
|
+
expiresAt: z12.string().datetime().describe(
|
|
363
366
|
"When this charge stops accepting payment, if still `pending`/`partially_paid` by then."
|
|
364
367
|
),
|
|
365
|
-
confirmedAt:
|
|
366
|
-
settledAt:
|
|
368
|
+
confirmedAt: z12.string().datetime().nullable().describe("When `status` first reached `confirmed`. `null` until then."),
|
|
369
|
+
settledAt: z12.string().datetime().nullable().describe(
|
|
367
370
|
"When `settlementStatus` first reached `completed` \u2014 the merchant's wallet actually has the funds. `null` until then, including while `settlementStatus` is `pending`/`failed`."
|
|
368
371
|
),
|
|
369
|
-
lastActivityAt:
|
|
372
|
+
lastActivityAt: z12.string().datetime().describe(
|
|
370
373
|
"When a transfer was last credited toward this charge, or `createdAt` if none has arrived yet."
|
|
371
374
|
),
|
|
372
|
-
escrow:
|
|
373
|
-
releaserAddress:
|
|
374
|
-
releasedAt:
|
|
375
|
-
refundedAt:
|
|
375
|
+
escrow: z12.object({
|
|
376
|
+
releaserAddress: z12.string().describe("The only address that can ever release this escrow \u2014 never Klappay."),
|
|
377
|
+
releasedAt: z12.string().datetime().nullable().describe("When the release actually executed on-chain. `null` until then."),
|
|
378
|
+
refundedAt: z12.string().datetime().nullable().describe(
|
|
376
379
|
"When the refund actually executed on-chain. `null` until then. Mutually exclusive with `releasedAt` \u2014 an escrow can only ever be released or refunded once, never both."
|
|
377
380
|
)
|
|
378
381
|
}).nullable().describe(
|
|
379
382
|
"Present only when this charge was created as an escrow (see `escrow` on the create request) \u2014 `null` for a normal charge."
|
|
380
383
|
)
|
|
381
384
|
});
|
|
382
|
-
var ListChargesSchema =
|
|
385
|
+
var ListChargesSchema = z12.object({
|
|
383
386
|
status: ChargeStatusSchema.optional(),
|
|
384
387
|
token: TokenSchema.optional().describe(
|
|
385
388
|
"Filters on `paidWith.token` \u2014 the pair actually paid, not accepted."
|
|
@@ -388,13 +391,13 @@ var ListChargesSchema = z11.object({
|
|
|
388
391
|
"Filters on `paidWith.network` \u2014 the pair actually paid, not accepted."
|
|
389
392
|
),
|
|
390
393
|
environment: EnvironmentSchema.optional(),
|
|
391
|
-
since:
|
|
394
|
+
since: z12.string().datetime().optional().describe(
|
|
392
395
|
"Only return charges created at or after this timestamp (filters on `createdAt`, not on when the status last changed). If polling as a fallback for missed webhooks, use a window at least as wide as the longest `expiresIn` your charges use, or you can miss a long-lived charge that changed status outside a narrower window."
|
|
393
396
|
),
|
|
394
|
-
isOverpaid:
|
|
397
|
+
isOverpaid: z12.enum(["true", "false"]).transform((v) => v === "true").optional()
|
|
395
398
|
}).extend(PaginationQuerySchema.shape);
|
|
396
399
|
var PaginatedChargesSchema = paginatedSchema(ChargeSchema);
|
|
397
|
-
var GetChargeQrCodeQuerySchema =
|
|
400
|
+
var GetChargeQrCodeQuerySchema = z12.object({
|
|
398
401
|
token: TokenSchema.optional().describe(
|
|
399
402
|
"Which accepted `(token, network)` pair to encode in the QR \u2014 required if `acceptedPayments` has more than one pair, since there is no single unambiguous default to fall back to. Ignored (and unnecessary) when the charge accepts exactly one pair."
|
|
400
403
|
),
|
|
@@ -402,19 +405,19 @@ var GetChargeQrCodeQuerySchema = z11.object({
|
|
|
402
405
|
});
|
|
403
406
|
|
|
404
407
|
// src/charge-check.ts
|
|
405
|
-
import { z as
|
|
408
|
+
import { z as z14 } from "zod";
|
|
406
409
|
|
|
407
410
|
// src/confirmation-progress.ts
|
|
408
|
-
import { z as
|
|
409
|
-
var ConfirmationProgressSchema =
|
|
411
|
+
import { z as z13 } from "zod";
|
|
412
|
+
var ConfirmationProgressSchema = z13.object({
|
|
410
413
|
network: NetworkSchema.describe("Which network the transfer was seen on."),
|
|
411
|
-
blocksSeen:
|
|
414
|
+
blocksSeen: z13.number().int().min(0).describe(
|
|
412
415
|
"How many blocks have passed since the transfer's own block, as of this update \u2014 a raw block count, not seconds. Grows toward `blocksRequired` as the network's blocks keep arriving."
|
|
413
416
|
),
|
|
414
|
-
blocksRequired:
|
|
417
|
+
blocksRequired: z13.number().int().min(1).describe(
|
|
415
418
|
"This network's minimum confirmation depth (a fixed, per-network constant) \u2014 the transfer is only credited once `blocksSeen` reaches this value."
|
|
416
419
|
),
|
|
417
|
-
percent:
|
|
420
|
+
percent: z13.number().int().min(0).max(99).describe(
|
|
418
421
|
'`blocksSeen`/`blocksRequired` as a rounded-down 0-99 percentage, for a progress bar. Never reaches 100 by construction \u2014 once a transfer is deep enough it is credited immediately and this stops being reported at all (the charge event itself is the "done" signal).'
|
|
419
422
|
)
|
|
420
423
|
}).describe(
|
|
@@ -422,8 +425,8 @@ var ConfirmationProgressSchema = z12.object({
|
|
|
422
425
|
);
|
|
423
426
|
|
|
424
427
|
// src/charge-check.ts
|
|
425
|
-
var CheckChargeRequestSchema =
|
|
426
|
-
txHash:
|
|
428
|
+
var CheckChargeRequestSchema = z14.object({
|
|
429
|
+
txHash: z14.string().regex(/^0x[0-9a-fA-F]{64}$/, "must be a 32-byte transaction hash").optional().describe(
|
|
427
430
|
"The on-chain transaction hash to verify directly, if you already have it \u2014 e.g. right after a swap-to-pay or wallet-connect transaction is sent. Costs a single RPC call instead of scanning a block range, so the check resolves faster and cheaper. Omit to fall back to scanning recent transfers to this charge's address, the same lookup the background reconciliation pass runs. Never trusted at face value \u2014 whatever this transaction actually contains on-chain is what gets credited, regardless of any amount/token implied elsewhere."
|
|
428
431
|
),
|
|
429
432
|
network: NetworkSchema.optional().describe(
|
|
@@ -433,7 +436,7 @@ var CheckChargeRequestSchema = z13.object({
|
|
|
433
436
|
message: "`txHash` and `network` must be provided together, or both omitted"
|
|
434
437
|
});
|
|
435
438
|
var CheckChargeResponseSchema = ChargeSchema.extend({
|
|
436
|
-
transactionSender:
|
|
439
|
+
transactionSender: z14.string().nullable().describe(
|
|
437
440
|
"The `txHash` transaction's own sender (`from`) \u2014 who actually signed and submitted it on-chain, which stays the payer's own wallet even when the transaction swaps through a router/aggregator on the way to paying, unlike the credited transfer's `from` (which can be the router/pool contract, not the payer). `null` unless `txHash`/`network` was passed in the request and a successful receipt was found for it \u2014 a hint-less background scan, an unaccepted network, or a not-found/reverted transaction all leave this `null`."
|
|
438
441
|
),
|
|
439
442
|
confirmationProgress: ConfirmationProgressSchema.nullable().describe(
|
|
@@ -442,61 +445,61 @@ var CheckChargeResponseSchema = ChargeSchema.extend({
|
|
|
442
445
|
});
|
|
443
446
|
|
|
444
447
|
// src/distributions.ts
|
|
445
|
-
import { z as
|
|
446
|
-
var SplitDistributionStatusSchema =
|
|
448
|
+
import { z as z15 } from "zod";
|
|
449
|
+
var SplitDistributionStatusSchema = z15.enum(["pending", "processing", "completed", "failed"]).describe(
|
|
447
450
|
"Status of one payout attempt to the merchant, for a single `(token, network)` pair \u2014 a charge that settles across more than one pair has one of these per pair. `pending`: queued, not yet claimed by a distributor. `processing`: a distributor (Klappay's own worker, or anyone racing to call `distribute()` first, see `PendingDistributionSchema`) has claimed it and is submitting the on-chain transaction. `completed`: the merchant's wallet has the funds. `failed`: every automatic retry was exhausted."
|
|
448
451
|
);
|
|
449
|
-
var PendingDistributionRecipientSchema =
|
|
450
|
-
address:
|
|
451
|
-
percentAllocation:
|
|
452
|
+
var PendingDistributionRecipientSchema = z15.object({
|
|
453
|
+
address: z15.string().describe("On-chain recipient address."),
|
|
454
|
+
percentAllocation: z15.number().describe("This recipient's share of the split, as a percentage (e.g. `99.0991` = 99.0991%).")
|
|
452
455
|
});
|
|
453
|
-
var PendingDistributionSchema =
|
|
454
|
-
splitAddress:
|
|
456
|
+
var PendingDistributionSchema = z15.object({
|
|
457
|
+
splitAddress: z15.string().describe("The on-chain 0xSplits address to call `distribute()` on."),
|
|
455
458
|
network: NetworkSchema,
|
|
456
459
|
token: TokenSchema,
|
|
457
|
-
recipients:
|
|
460
|
+
recipients: z15.array(PendingDistributionRecipientSchema).describe(
|
|
458
461
|
"The exact recipient list to pass to `distribute()` \u2014 the split contract only stores a hash of this config, so the caller must supply the identical array to prove it matches. Always present, never reconstructed from partial data."
|
|
459
462
|
),
|
|
460
|
-
distributorFeePercent:
|
|
463
|
+
distributorFeePercent: z15.number().describe(
|
|
461
464
|
"Percentage of the split balance paid to whoever calls `distribute()` first (e.g. `0.1` = 0.1%). Frozen at charge creation, same for every distribution today."
|
|
462
465
|
),
|
|
463
|
-
estimatedRewardAmount:
|
|
466
|
+
estimatedRewardAmount: z15.number().describe(
|
|
464
467
|
"Estimate only, in the charge's `currency` units, based on the amount Klappay detected on-chain \u2014 not a live read of the split's current balance. Read the balance yourself before submitting a transaction; a stale estimate is harmless (see the docs), never a reason to skip that check."
|
|
465
468
|
),
|
|
466
|
-
availableSince:
|
|
467
|
-
graceEndsAt:
|
|
469
|
+
availableSince: z15.string().datetime().describe("When this distribution entered its grace period."),
|
|
470
|
+
graceEndsAt: z15.string().datetime().describe(
|
|
468
471
|
"When Klappay's own worker may claim this distribution. Racing to call `distribute()` after this timestamp is possible but increasingly likely to lose to the worker."
|
|
469
472
|
)
|
|
470
473
|
});
|
|
471
474
|
var PaginatedPendingDistributionsSchema = paginatedSchema(PendingDistributionSchema);
|
|
472
|
-
var ListenPendingDistributionsQuerySchema =
|
|
473
|
-
limit:
|
|
475
|
+
var ListenPendingDistributionsQuerySchema = z15.object({
|
|
476
|
+
limit: z15.coerce.number().int().min(0).max(PAGINATION_LIMIT_MAX).default(0).describe(
|
|
474
477
|
"How many currently-claimable distributions to emit as an initial snapshot right after connecting \u2014 each as a synthetic `distribution.available` event \u2014 before continuing with real-time deltas. `0` (the default, same as omitting it) sends no snapshot at all, matching this endpoint's original behavior: connect first, then call `GET /v1/distributions/pending` yourself to bootstrap. Not a page \u2014 there is no cursor for this snapshot, so if more than `limit` are claimable at connect time, the excess is simply not sent; call `GET /v1/distributions/pending` directly for a complete, paginated listing."
|
|
475
478
|
)
|
|
476
479
|
});
|
|
477
|
-
var PendingDistributionEventSchema =
|
|
478
|
-
|
|
479
|
-
type:
|
|
480
|
+
var PendingDistributionEventSchema = z15.discriminatedUnion("type", [
|
|
481
|
+
z15.object({
|
|
482
|
+
type: z15.literal("distribution.available"),
|
|
480
483
|
distribution: PendingDistributionSchema
|
|
481
484
|
}),
|
|
482
|
-
|
|
483
|
-
type:
|
|
484
|
-
splitAddress:
|
|
485
|
+
z15.object({
|
|
486
|
+
type: z15.literal("distribution.claimed"),
|
|
487
|
+
splitAddress: z15.string().describe("No longer claimable \u2014 either settled by someone, or picked up by the worker.")
|
|
485
488
|
})
|
|
486
489
|
]);
|
|
487
490
|
|
|
488
491
|
// src/metrics.ts
|
|
489
|
-
import { z as
|
|
490
|
-
var MetricsResourceSchema =
|
|
492
|
+
import { z as z16 } from "zod";
|
|
493
|
+
var MetricsResourceSchema = z16.enum(["charges", "transactions", "distributions"]).describe(
|
|
491
494
|
"Which underlying dataset to query. `charges`: one row per charge. `transactions`: one row per detected on-chain transfer \u2014 a charge paid in installments has more than one. `distributions`: one row per payout attempt to the merchant, one per `(token, network)` pair a charge settled across."
|
|
492
495
|
);
|
|
493
|
-
var MetricsAggregationSchema =
|
|
496
|
+
var MetricsAggregationSchema = z16.enum(["count", "sum", "avg", "min", "max"]).describe(
|
|
494
497
|
"`count` counts matching rows and never takes `field`. `sum`/`avg`/`min`/`max` require `field` to be set to one of the resource\u2019s numeric fields."
|
|
495
498
|
);
|
|
496
|
-
var MetricsFilterOperatorSchema =
|
|
499
|
+
var MetricsFilterOperatorSchema = z16.enum(["eq", "neq", "in", "gt", "gte", "lt", "lte"]).describe(
|
|
497
500
|
"`in` expects an array value (max 50 entries); every other operator expects a single scalar."
|
|
498
501
|
);
|
|
499
|
-
var MetricsDateGranularitySchema =
|
|
502
|
+
var MetricsDateGranularitySchema = z16.enum(["day", "week", "month", "year"]).describe(
|
|
500
503
|
"Bucket width for a `date_bucket` `groupBy` entry \u2014 Postgres `date_trunc` semantics (UTC)."
|
|
501
504
|
);
|
|
502
505
|
var metricsQueryEnvironmentSchema = EnvironmentSchema.describe(
|
|
@@ -509,32 +512,32 @@ var METRICS_QUERY_MAX_GROUP_BY = 3;
|
|
|
509
512
|
var METRICS_QUERY_MAX_FILTERS = 20;
|
|
510
513
|
var METRICS_QUERY_MAX_METRICS = 10;
|
|
511
514
|
var METRIC_ALIAS_PATTERN = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
|
|
512
|
-
var metricAliasSchema =
|
|
515
|
+
var metricAliasSchema = z16.string().min(1).max(64).regex(
|
|
513
516
|
METRIC_ALIAS_PATTERN,
|
|
514
517
|
"Must start with a letter or underscore, and contain only letters, digits, and underscores \u2014 this becomes a SQL column alias."
|
|
515
518
|
).optional();
|
|
516
|
-
var MetricsFilterValueSchema =
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
519
|
+
var MetricsFilterValueSchema = z16.union([
|
|
520
|
+
z16.string().max(255),
|
|
521
|
+
z16.number(),
|
|
522
|
+
z16.boolean(),
|
|
523
|
+
z16.null(),
|
|
524
|
+
z16.array(z16.union([z16.string().max(255), z16.number()])).min(1).max(50)
|
|
522
525
|
]);
|
|
523
|
-
var orderBySchema =
|
|
524
|
-
key:
|
|
526
|
+
var orderBySchema = z16.object({
|
|
527
|
+
key: z16.string().min(1).max(64).regex(
|
|
525
528
|
METRIC_ALIAS_PATTERN,
|
|
526
529
|
"Must start with a letter or underscore, and contain only letters, digits, and underscores \u2014 every valid output column name already looks like this."
|
|
527
530
|
).describe(
|
|
528
531
|
"An output column name from this same query \u2014 either a `groupBy` field name, or a metric\u2019s `alias` (or its default name: `${aggregation}` for `count`, `${aggregation}_${field}` otherwise, e.g. `sum_amount`). Must match `^[a-zA-Z_][a-zA-Z0-9_]*$` \u2014 every real output column name already does, so this only ever rejects a value that could never have been one."
|
|
529
532
|
),
|
|
530
|
-
direction:
|
|
533
|
+
direction: z16.enum(["asc", "desc"])
|
|
531
534
|
}).describe(
|
|
532
535
|
"Sort the result rows by any output column \u2014 including the bucket field itself for a `date_bucket` query (e.g. `createdAt`). Omit to get ascending-by-bucket order for a date-bucketed query, or implementation-defined (not guaranteed stable) order otherwise."
|
|
533
536
|
);
|
|
534
|
-
var limitSchema =
|
|
537
|
+
var limitSchema = z16.number().int().min(1).max(METRICS_QUERY_MAX_ROW_LIMIT).default(METRICS_QUERY_DEFAULT_ROW_LIMIT).describe(
|
|
535
538
|
`Max rows to return, ${1}\u2013${METRICS_QUERY_MAX_ROW_LIMIT}, default ${METRICS_QUERY_DEFAULT_ROW_LIMIT}. If more rows matched, \`meta.truncated\` is \`true\` on the response \u2014 narrow the query instead of just raising this.`
|
|
536
539
|
);
|
|
537
|
-
var ChargesQueryFieldSchema =
|
|
540
|
+
var ChargesQueryFieldSchema = z16.enum([
|
|
538
541
|
"status",
|
|
539
542
|
"source",
|
|
540
543
|
"apiKeyId",
|
|
@@ -545,124 +548,124 @@ var ChargesQueryFieldSchema = z15.enum([
|
|
|
545
548
|
]).describe(
|
|
546
549
|
"A `Charge` field to filter or group by \u2014 see `ChargeStatusSchema` for `status`'s own possible values (charges.md). `source`/`externalRef` are free-form strings your own integration set at creation, not a fixed enum. `escrowReleaserAddress` is `null` for a normal charge \u2014 filter `escrowReleaserAddress` with operator `neq`/value `null` to isolate escrow-configured charges (see `escrow` in charges.md)."
|
|
547
550
|
);
|
|
548
|
-
var ChargesMetricFieldSchema =
|
|
551
|
+
var ChargesMetricFieldSchema = z16.enum(["amount", "amountReceived", "feePercent", "escrowFeePercent"]).describe(
|
|
549
552
|
"A `Charge` numeric field to aggregate. `amount`/`amountReceived` are decimal currency amounts (requested vs. actually received \u2014 see `charges.md`). `feePercent` is the platform fee frozen on the charge at creation, e.g. `1.5` means 1.5%. `escrowFeePercent` is the additional escrow-specific fee component, only present on escrow-configured charges \u2014 see `docs/payments.md`."
|
|
550
553
|
);
|
|
551
|
-
var ChargesDateFieldSchema =
|
|
554
|
+
var ChargesDateFieldSchema = z16.enum(["createdAt", "confirmedAt", "lastActivityAt", "expiresAt", "escrowReleasedAt"]).describe(
|
|
552
555
|
"A `Charge` timestamp to filter/bucket by. `confirmedAt` is `null` until the charge reaches `confirmed` \u2014 a `dateRange`/`date_bucket` on it implicitly excludes every charge that never confirmed. `expiresAt` is always present (set at creation), useful for e.g. finding charges expiring soon or measuring how close to expiry charges typically resolve. `escrowReleasedAt` is `null` until an escrow-configured charge is actually released \u2014 same implicit-exclusion behavior as `confirmedAt`, scoped to escrow charges only."
|
|
553
556
|
);
|
|
554
|
-
var ChargesFilterSchema =
|
|
557
|
+
var ChargesFilterSchema = z16.object({
|
|
555
558
|
field: ChargesQueryFieldSchema,
|
|
556
559
|
operator: MetricsFilterOperatorSchema,
|
|
557
560
|
value: MetricsFilterValueSchema
|
|
558
561
|
});
|
|
559
|
-
var ChargesGroupBySchema =
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
type:
|
|
562
|
+
var ChargesGroupBySchema = z16.union([
|
|
563
|
+
z16.object({ type: z16.literal("field"), field: ChargesQueryFieldSchema }),
|
|
564
|
+
z16.object({
|
|
565
|
+
type: z16.literal("date_bucket"),
|
|
563
566
|
field: ChargesDateFieldSchema,
|
|
564
567
|
granularity: MetricsDateGranularitySchema
|
|
565
568
|
})
|
|
566
569
|
]);
|
|
567
|
-
var ChargesMetricSchema =
|
|
570
|
+
var ChargesMetricSchema = z16.object({
|
|
568
571
|
aggregation: MetricsAggregationSchema,
|
|
569
572
|
field: ChargesMetricFieldSchema.optional(),
|
|
570
573
|
alias: metricAliasSchema
|
|
571
574
|
});
|
|
572
|
-
var ChargesMetricsQuerySchema =
|
|
573
|
-
resource:
|
|
575
|
+
var ChargesMetricsQuerySchema = z16.object({
|
|
576
|
+
resource: z16.literal("charges"),
|
|
574
577
|
environment: metricsQueryEnvironmentSchema,
|
|
575
|
-
dateRange:
|
|
578
|
+
dateRange: z16.object({
|
|
576
579
|
field: ChargesDateFieldSchema,
|
|
577
|
-
from:
|
|
578
|
-
to:
|
|
580
|
+
from: z16.string().max(64).datetime(),
|
|
581
|
+
to: z16.string().max(64).datetime()
|
|
579
582
|
}),
|
|
580
|
-
groupBy:
|
|
581
|
-
metrics:
|
|
582
|
-
filters:
|
|
583
|
+
groupBy: z16.array(ChargesGroupBySchema).max(METRICS_QUERY_MAX_GROUP_BY).default([]),
|
|
584
|
+
metrics: z16.array(ChargesMetricSchema).min(1).max(METRICS_QUERY_MAX_METRICS),
|
|
585
|
+
filters: z16.array(ChargesFilterSchema).max(METRICS_QUERY_MAX_FILTERS).default([]),
|
|
583
586
|
orderBy: orderBySchema.optional(),
|
|
584
587
|
limit: limitSchema
|
|
585
588
|
});
|
|
586
|
-
var TransactionsQueryFieldSchema =
|
|
589
|
+
var TransactionsQueryFieldSchema = z16.enum(["network", "token", "source", "causedTransition"]).describe(
|
|
587
590
|
"A `Transaction` field to filter or group by \u2014 see `NetworkSchema`/`TokenSchema`/`TransactionSourceSchema` for their possible values. `causedTransition` is `true` only for the transfer(s) that actually flipped the charge's `status` \u2014 a charge paid in installments can have more than one; filtering/grouping on it excludes no-op duplicate transfers (see `TimelineEvent.causedTransition` in charges.md for the full explanation)."
|
|
588
591
|
);
|
|
589
|
-
var TransactionsMetricFieldSchema =
|
|
590
|
-
var TransactionsDateFieldSchema =
|
|
591
|
-
var TransactionsFilterSchema =
|
|
592
|
+
var TransactionsMetricFieldSchema = z16.enum(["amount"]).describe("The transfer amount, in the charge's `currency` units.");
|
|
593
|
+
var TransactionsDateFieldSchema = z16.enum(["detectedAt"]).describe("When Klappay detected this transfer on-chain (not when it was mined).");
|
|
594
|
+
var TransactionsFilterSchema = z16.object({
|
|
592
595
|
field: TransactionsQueryFieldSchema,
|
|
593
596
|
operator: MetricsFilterOperatorSchema,
|
|
594
597
|
value: MetricsFilterValueSchema
|
|
595
598
|
});
|
|
596
|
-
var TransactionsGroupBySchema =
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
type:
|
|
599
|
+
var TransactionsGroupBySchema = z16.union([
|
|
600
|
+
z16.object({ type: z16.literal("field"), field: TransactionsQueryFieldSchema }),
|
|
601
|
+
z16.object({
|
|
602
|
+
type: z16.literal("date_bucket"),
|
|
600
603
|
field: TransactionsDateFieldSchema,
|
|
601
604
|
granularity: MetricsDateGranularitySchema
|
|
602
605
|
})
|
|
603
606
|
]);
|
|
604
|
-
var TransactionsMetricSchema =
|
|
607
|
+
var TransactionsMetricSchema = z16.object({
|
|
605
608
|
aggregation: MetricsAggregationSchema,
|
|
606
609
|
field: TransactionsMetricFieldSchema.optional(),
|
|
607
610
|
alias: metricAliasSchema
|
|
608
611
|
});
|
|
609
|
-
var TransactionsMetricsQuerySchema =
|
|
610
|
-
resource:
|
|
612
|
+
var TransactionsMetricsQuerySchema = z16.object({
|
|
613
|
+
resource: z16.literal("transactions"),
|
|
611
614
|
environment: metricsQueryEnvironmentSchema,
|
|
612
|
-
dateRange:
|
|
615
|
+
dateRange: z16.object({
|
|
613
616
|
field: TransactionsDateFieldSchema,
|
|
614
|
-
from:
|
|
615
|
-
to:
|
|
617
|
+
from: z16.string().max(64).datetime(),
|
|
618
|
+
to: z16.string().max(64).datetime()
|
|
616
619
|
}),
|
|
617
|
-
groupBy:
|
|
618
|
-
metrics:
|
|
619
|
-
filters:
|
|
620
|
+
groupBy: z16.array(TransactionsGroupBySchema).max(METRICS_QUERY_MAX_GROUP_BY).default([]),
|
|
621
|
+
metrics: z16.array(TransactionsMetricSchema).min(1).max(METRICS_QUERY_MAX_METRICS),
|
|
622
|
+
filters: z16.array(TransactionsFilterSchema).max(METRICS_QUERY_MAX_FILTERS).default([]),
|
|
620
623
|
orderBy: orderBySchema.optional(),
|
|
621
624
|
limit: limitSchema
|
|
622
625
|
});
|
|
623
|
-
var DistributionsQueryFieldSchema =
|
|
626
|
+
var DistributionsQueryFieldSchema = z16.enum(["status", "network", "token", "distributorAddress"]).describe(
|
|
624
627
|
"A `SplitDistribution` field to filter or group by \u2014 see `SplitDistributionStatusSchema`/`NetworkSchema`/`TokenSchema` for their possible values. `distributorAddress` is the public on-chain address that actually called `distribute()` for a `completed` distribution \u2014 Klappay's own operator address if settled by Klappay's own worker, a community keeper's address if settled externally (or `null` on the rare case that lookup failed), `null` for every non-`completed` status."
|
|
625
628
|
);
|
|
626
|
-
var DistributionsMetricFieldSchema =
|
|
629
|
+
var DistributionsMetricFieldSchema = z16.enum(["attempts"]).describe(
|
|
627
630
|
"How many times a payout was attempted for this settlement so far \u2014 incremented on every attempt, whether it succeeded or is being retried after failing. A high `attempts` alongside `status: 'failed'` means every automatic retry was exhausted."
|
|
628
631
|
);
|
|
629
|
-
var DistributionsDateFieldSchema =
|
|
632
|
+
var DistributionsDateFieldSchema = z16.enum(["createdAt", "processingStartedAt", "completedAt"]).describe(
|
|
630
633
|
"`createdAt`: when this settlement was queued. `processingStartedAt`: when a worker began its most recent attempt at the payout \u2014 `null` until the first attempt, then overwritten on every subsequent retry, so it reflects the *latest* attempt's start, not the first. `completedAt`: when it actually paid out \u2014 `null` until `status` reaches `completed`, so a `dateRange`/`date_bucket` on it implicitly excludes every distribution still pending/processing/failed."
|
|
631
634
|
);
|
|
632
|
-
var DistributionsFilterSchema =
|
|
635
|
+
var DistributionsFilterSchema = z16.object({
|
|
633
636
|
field: DistributionsQueryFieldSchema,
|
|
634
637
|
operator: MetricsFilterOperatorSchema,
|
|
635
638
|
value: MetricsFilterValueSchema
|
|
636
639
|
});
|
|
637
|
-
var DistributionsGroupBySchema =
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
type:
|
|
640
|
+
var DistributionsGroupBySchema = z16.union([
|
|
641
|
+
z16.object({ type: z16.literal("field"), field: DistributionsQueryFieldSchema }),
|
|
642
|
+
z16.object({
|
|
643
|
+
type: z16.literal("date_bucket"),
|
|
641
644
|
field: DistributionsDateFieldSchema,
|
|
642
645
|
granularity: MetricsDateGranularitySchema
|
|
643
646
|
})
|
|
644
647
|
]);
|
|
645
|
-
var DistributionsMetricSchema =
|
|
648
|
+
var DistributionsMetricSchema = z16.object({
|
|
646
649
|
aggregation: MetricsAggregationSchema,
|
|
647
650
|
field: DistributionsMetricFieldSchema.optional(),
|
|
648
651
|
alias: metricAliasSchema
|
|
649
652
|
});
|
|
650
|
-
var DistributionsMetricsQuerySchema =
|
|
651
|
-
resource:
|
|
653
|
+
var DistributionsMetricsQuerySchema = z16.object({
|
|
654
|
+
resource: z16.literal("distributions"),
|
|
652
655
|
environment: metricsQueryEnvironmentSchema,
|
|
653
|
-
dateRange:
|
|
656
|
+
dateRange: z16.object({
|
|
654
657
|
field: DistributionsDateFieldSchema,
|
|
655
|
-
from:
|
|
656
|
-
to:
|
|
658
|
+
from: z16.string().max(64).datetime(),
|
|
659
|
+
to: z16.string().max(64).datetime()
|
|
657
660
|
}),
|
|
658
|
-
groupBy:
|
|
659
|
-
metrics:
|
|
660
|
-
filters:
|
|
661
|
+
groupBy: z16.array(DistributionsGroupBySchema).max(METRICS_QUERY_MAX_GROUP_BY).default([]),
|
|
662
|
+
metrics: z16.array(DistributionsMetricSchema).min(1).max(METRICS_QUERY_MAX_METRICS),
|
|
663
|
+
filters: z16.array(DistributionsFilterSchema).max(METRICS_QUERY_MAX_FILTERS).default([]),
|
|
661
664
|
orderBy: orderBySchema.optional(),
|
|
662
665
|
limit: limitSchema
|
|
663
666
|
});
|
|
664
667
|
var ONE_DAY_MS = 24 * 60 * 60 * 1e3;
|
|
665
|
-
var MetricsQuerySchema =
|
|
668
|
+
var MetricsQuerySchema = z16.discriminatedUnion("resource", [
|
|
666
669
|
ChargesMetricsQuerySchema,
|
|
667
670
|
TransactionsMetricsQuerySchema,
|
|
668
671
|
DistributionsMetricsQuerySchema
|
|
@@ -671,7 +674,7 @@ var MetricsQuerySchema = z15.discriminatedUnion("resource", [
|
|
|
671
674
|
const to = new Date(input.dateRange.to);
|
|
672
675
|
if (from >= to) {
|
|
673
676
|
ctx.addIssue({
|
|
674
|
-
code:
|
|
677
|
+
code: z16.ZodIssueCode.custom,
|
|
675
678
|
message: "`dateRange.from` must be before `dateRange.to`.",
|
|
676
679
|
path: ["dateRange", "from"]
|
|
677
680
|
});
|
|
@@ -679,7 +682,7 @@ var MetricsQuerySchema = z15.discriminatedUnion("resource", [
|
|
|
679
682
|
const spanDays = (to.getTime() - from.getTime()) / ONE_DAY_MS;
|
|
680
683
|
if (spanDays > MAX_METRICS_QUERY_DATE_RANGE_DAYS) {
|
|
681
684
|
ctx.addIssue({
|
|
682
|
-
code:
|
|
685
|
+
code: z16.ZodIssueCode.custom,
|
|
683
686
|
message: `\`dateRange\` cannot span more than ${MAX_METRICS_QUERY_DATE_RANGE_DAYS} days.`,
|
|
684
687
|
path: ["dateRange", "to"]
|
|
685
688
|
});
|
|
@@ -687,7 +690,7 @@ var MetricsQuerySchema = z15.discriminatedUnion("resource", [
|
|
|
687
690
|
const dateBucketCount = input.groupBy.filter((entry) => entry.type === "date_bucket").length;
|
|
688
691
|
if (dateBucketCount > 1) {
|
|
689
692
|
ctx.addIssue({
|
|
690
|
-
code:
|
|
693
|
+
code: z16.ZodIssueCode.custom,
|
|
691
694
|
message: "At most one `date_bucket` entry is allowed in `groupBy`.",
|
|
692
695
|
path: ["groupBy"]
|
|
693
696
|
});
|
|
@@ -695,7 +698,7 @@ var MetricsQuerySchema = z15.discriminatedUnion("resource", [
|
|
|
695
698
|
input.metrics.forEach((metric, index) => {
|
|
696
699
|
if (metric.aggregation !== "count" && metric.field === void 0) {
|
|
697
700
|
ctx.addIssue({
|
|
698
|
-
code:
|
|
701
|
+
code: z16.ZodIssueCode.custom,
|
|
699
702
|
message: "`field` is required unless `aggregation` is `count`.",
|
|
700
703
|
path: ["metrics", index, "field"]
|
|
701
704
|
});
|
|
@@ -704,7 +707,7 @@ var MetricsQuerySchema = z15.discriminatedUnion("resource", [
|
|
|
704
707
|
const aliases = input.metrics.map((metric) => metric.alias).filter((alias) => alias !== void 0);
|
|
705
708
|
if (new Set(aliases).size !== aliases.length) {
|
|
706
709
|
ctx.addIssue({
|
|
707
|
-
code:
|
|
710
|
+
code: z16.ZodIssueCode.custom,
|
|
708
711
|
message: "Every `metrics[].alias` must be unique.",
|
|
709
712
|
path: ["metrics"]
|
|
710
713
|
});
|
|
@@ -713,32 +716,32 @@ var MetricsQuerySchema = z15.discriminatedUnion("resource", [
|
|
|
713
716
|
input.metrics.forEach((metric, index) => {
|
|
714
717
|
if (metric.alias !== void 0 && reservedNames.has(metric.alias)) {
|
|
715
718
|
ctx.addIssue({
|
|
716
|
-
code:
|
|
719
|
+
code: z16.ZodIssueCode.custom,
|
|
717
720
|
message: `\`alias\` "${metric.alias}" collides with a \`groupBy\` field name (or the reserved word "bucket") \u2014 choose a different alias.`,
|
|
718
721
|
path: ["metrics", index, "alias"]
|
|
719
722
|
});
|
|
720
723
|
}
|
|
721
724
|
});
|
|
722
725
|
});
|
|
723
|
-
var MetricsQueryResultRowSchema =
|
|
724
|
-
|
|
725
|
-
|
|
726
|
+
var MetricsQueryResultRowSchema = z16.record(
|
|
727
|
+
z16.string(),
|
|
728
|
+
z16.union([z16.string(), z16.number(), z16.boolean(), z16.null()])
|
|
726
729
|
);
|
|
727
|
-
var MetricsQueryResultSchema =
|
|
728
|
-
data:
|
|
729
|
-
meta:
|
|
730
|
+
var MetricsQueryResultSchema = z16.object({
|
|
731
|
+
data: z16.array(MetricsQueryResultRowSchema),
|
|
732
|
+
meta: z16.object({
|
|
730
733
|
resource: MetricsResourceSchema,
|
|
731
734
|
environment: EnvironmentSchema,
|
|
732
|
-
rowCount:
|
|
733
|
-
truncated:
|
|
735
|
+
rowCount: z16.number().int().describe("Number of rows in `data`."),
|
|
736
|
+
truncated: z16.boolean().describe(
|
|
734
737
|
"`true` if more rows matched than `limit` allowed \u2014 `data` holds only the first `limit`."
|
|
735
738
|
)
|
|
736
739
|
})
|
|
737
740
|
});
|
|
738
741
|
|
|
739
742
|
// src/webhook-events.ts
|
|
740
|
-
import { z as
|
|
741
|
-
var ChargeWebhookEventTypeSchema =
|
|
743
|
+
import { z as z17 } from "zod";
|
|
744
|
+
var ChargeWebhookEventTypeSchema = z17.enum([
|
|
742
745
|
"charge.created",
|
|
743
746
|
"charge.partially_paid",
|
|
744
747
|
"charge.confirmed",
|
|
@@ -752,14 +755,14 @@ var ChargeWebhookEventTypeSchema = z16.enum([
|
|
|
752
755
|
]).describe(
|
|
753
756
|
'Note the distinction between `charge.confirmed` and `charge.settled`: `confirmed` means the payment was detected on-chain; `settled` means the merchant\'s wallet actually received the funds \u2014 a separate, later step. Subscribe to `confirmed` if you only need "will I get paid," or `settled` if you need "has the money actually arrived." `charge.overpaid` fires alongside `charge.confirmed`/`charge.partially_paid` whenever the cumulative amount received ends up above `amount` (see `Charge.isOverpaid`). `charge.escrow_released` fires once an escrow-configured charge\'s funds have been moved out of its Safe to the split address by `POST /v1/charges/{id}/release` \u2014 a normal `charge.settled` still follows once the split itself finishes distributing. `charge.escrow_refunded` fires once an escrow-configured charge\'s funds have been moved out of its Safe back to the payer by `POST /v1/charges/{id}/refund` \u2014 mutually exclusive with `charge.escrow_released`, an escrow charge only ever emits one of the two. Every event in this category carries the full `Charge` object as `data`.'
|
|
754
757
|
);
|
|
755
|
-
var WebhookDeliveryEventTypeSchema =
|
|
758
|
+
var WebhookDeliveryEventTypeSchema = z17.enum(["webhook.delivery_failed", "webhook.delivery_recovered", "webhook.endpoint_unhealthy"]).describe(
|
|
756
759
|
"Meta-events about the health of your own webhook endpoints \u2014 useful for monitoring without polling `GET /v1/webhooks/{id}/deliveries`. `webhook.endpoint_unhealthy` fires once when a webhook's failure rate over the trailing 24h crosses 20%, and `webhook.delivery_recovered` fires once when a delivery to that webhook next succeeds. `data` for every event in this category: `{ webhookId, url, failureRatio? }` (`failureRatio` only present on `webhook.endpoint_unhealthy`)."
|
|
757
760
|
);
|
|
758
|
-
var WebhookEventTypeSchema =
|
|
761
|
+
var WebhookEventTypeSchema = z17.union([
|
|
759
762
|
ChargeWebhookEventTypeSchema,
|
|
760
763
|
WebhookDeliveryEventTypeSchema
|
|
761
764
|
]);
|
|
762
|
-
var WebhookCategorySchema =
|
|
765
|
+
var WebhookCategorySchema = z17.enum(["payments", "webhooks"]).describe(
|
|
763
766
|
"Subscribe to every event in a category via `eventCategories` instead of listing events one by one \u2014 new events added to a category later arrive automatically, no subscription update needed."
|
|
764
767
|
);
|
|
765
768
|
function buildCategoryMap() {
|
|
@@ -789,103 +792,103 @@ var TriggerableChargeEventSchema = ChargeWebhookEventTypeSchema.exclude([
|
|
|
789
792
|
);
|
|
790
793
|
|
|
791
794
|
// src/webhooks.ts
|
|
792
|
-
import { z as
|
|
795
|
+
import { z as z18 } from "zod";
|
|
793
796
|
var WEBHOOK_EVENTS_WILDCARD = "*";
|
|
794
|
-
var CreateWebhookSchema =
|
|
795
|
-
url:
|
|
797
|
+
var CreateWebhookSchema = z18.object({
|
|
798
|
+
url: z18.string().max(2048).url().describe(
|
|
796
799
|
"Must be HTTPS and resolve to a public address \u2014 private/internal IPs are rejected."
|
|
797
800
|
),
|
|
798
|
-
events:
|
|
801
|
+
events: z18.array(z18.union([WebhookEventTypeSchema, z18.literal(WEBHOOK_EVENTS_WILDCARD)])).max(Object.keys(EVENT_CATEGORY_MAP).length + 1).default([]).describe(
|
|
799
802
|
'Individual event types to receive, or `"*"` for every event (combine with `excludeEvents` to opt back out of specific ones). Omit in favor of `eventCategories` if you want whole categories instead.'
|
|
800
803
|
),
|
|
801
|
-
eventCategories:
|
|
804
|
+
eventCategories: z18.array(WebhookCategorySchema).max(WebhookCategorySchema.options.length).default([]).describe(
|
|
802
805
|
"Subscribe to every event in these categories. At least one of `events` or `eventCategories` is required."
|
|
803
806
|
),
|
|
804
|
-
excludeEvents:
|
|
807
|
+
excludeEvents: z18.array(WebhookEventTypeSchema).max(Object.keys(EVENT_CATEGORY_MAP).length).default([]).describe(
|
|
805
808
|
'Event types to exclude even if selected via `events: ["*"]` or `eventCategories`.'
|
|
806
809
|
)
|
|
807
810
|
}).refine((v) => v.events.length > 0 || v.eventCategories.length > 0, {
|
|
808
811
|
message: "must select at least one event via `events` or `eventCategories`",
|
|
809
812
|
path: ["events"]
|
|
810
813
|
});
|
|
811
|
-
var WebhookSchema =
|
|
812
|
-
id:
|
|
814
|
+
var WebhookSchema = z18.object({
|
|
815
|
+
id: z18.string(),
|
|
813
816
|
environment: EnvironmentSchema.nullable().describe(
|
|
814
817
|
"Which environment's API key created this webhook \u2014 `live` or `test`. Every event is only ever delivered to a webhook whose `environment` matches the event's own (or to a webhook with `environment: null`, which receives every environment \u2014 the case for every webhook created before this field existed)."
|
|
815
818
|
),
|
|
816
|
-
url:
|
|
817
|
-
events:
|
|
818
|
-
eventCategories:
|
|
819
|
-
excludeEvents:
|
|
820
|
-
isWildcard:
|
|
821
|
-
secret:
|
|
819
|
+
url: z18.string(),
|
|
820
|
+
events: z18.array(WebhookEventTypeSchema),
|
|
821
|
+
eventCategories: z18.array(WebhookCategorySchema),
|
|
822
|
+
excludeEvents: z18.array(WebhookEventTypeSchema),
|
|
823
|
+
isWildcard: z18.boolean(),
|
|
824
|
+
secret: z18.string().describe(
|
|
822
825
|
"The signing secret, used to verify the `X-Klappay-Signature` header on every delivery. Returned in full only this once \u2014 store it now, it is not recoverable afterward. Header format: `t=<unix-seconds>,v1=<hex-encoded HMAC-SHA256>`. Compute the expected signature as `HMAC-SHA256(secret, \"${t}.${raw request body}\")` (hex-encoded) and compare it to `v1` using a constant-time comparison; as a replay-protection measure, also reject if `t` is too far from the current time \u2014 Klappay does not enforce or check any particular tolerance server-side, so the exact threshold is entirely the receiver's own policy call. An official SDK's `constructEvent()`/`verifySignature()` do this for you, defaulting to a 300-second tolerance, overridable via `constructEvent`'s `toleranceSeconds` option \u2014 see github.com/klappay for available SDKs."
|
|
823
826
|
),
|
|
824
|
-
createdAt:
|
|
827
|
+
createdAt: z18.string().datetime()
|
|
825
828
|
});
|
|
826
829
|
var WebhookListItemSchema = WebhookSchema.omit({ secret: true }).extend({
|
|
827
|
-
hint:
|
|
830
|
+
hint: z18.string().describe("A truncated, safe-to-display form of the secret (e.g. `whsec_...ab12`).")
|
|
828
831
|
});
|
|
829
|
-
var WebhookPayloadSchema =
|
|
830
|
-
id:
|
|
832
|
+
var WebhookPayloadSchema = z18.object({
|
|
833
|
+
id: z18.string().describe(
|
|
831
834
|
"Unique id for this specific delivery \u2014 also sent as the `X-Klappay-Delivery` header."
|
|
832
835
|
),
|
|
833
836
|
event: WebhookEventTypeSchema,
|
|
834
|
-
createdAt:
|
|
835
|
-
data:
|
|
837
|
+
createdAt: z18.string().datetime(),
|
|
838
|
+
data: z18.unknown().describe(
|
|
836
839
|
"Event-specific data. Charge events (`charge.*`) carry the full `Charge` object; webhook-delivery events carry a smaller, event-specific object \u2014 see `WebhookEventDataMap`/`TypedWebhookPayload` for the exact shape per event, or docs/webhooks.md."
|
|
837
840
|
)
|
|
838
841
|
});
|
|
839
|
-
var WebhookDeliveryStatusSchema =
|
|
840
|
-
var WebhookDeliverySchema =
|
|
841
|
-
id:
|
|
842
|
-
webhookId:
|
|
842
|
+
var WebhookDeliveryStatusSchema = z18.enum(["pending", "delivered", "failed"]);
|
|
843
|
+
var WebhookDeliverySchema = z18.object({
|
|
844
|
+
id: z18.string(),
|
|
845
|
+
webhookId: z18.string(),
|
|
843
846
|
event: WebhookEventTypeSchema,
|
|
844
847
|
status: WebhookDeliveryStatusSchema.describe(
|
|
845
848
|
"`pending`: still retrying. `delivered`: got a 2xx response. `failed`: retries exhausted (5 attempts over ~24h) \u2014 use `POST /v1/webhooks/{id}/deliveries/{deliveryId}/retry` to try again manually."
|
|
846
849
|
),
|
|
847
|
-
attempts:
|
|
848
|
-
responseCode:
|
|
850
|
+
attempts: z18.number(),
|
|
851
|
+
responseCode: z18.number().nullable().describe(
|
|
849
852
|
"HTTP status your endpoint returned on the most recent attempt. `null` if every attempt failed to connect at all."
|
|
850
853
|
),
|
|
851
|
-
nextRetryAt:
|
|
852
|
-
deliveredAt:
|
|
853
|
-
createdAt:
|
|
854
|
+
nextRetryAt: z18.string().datetime().nullable(),
|
|
855
|
+
deliveredAt: z18.string().datetime().nullable(),
|
|
856
|
+
createdAt: z18.string().datetime()
|
|
854
857
|
});
|
|
855
858
|
var ListWebhookDeliveriesSchema = PaginationQuerySchema;
|
|
856
859
|
var PaginatedWebhookDeliveriesSchema = paginatedSchema(WebhookDeliverySchema);
|
|
857
860
|
|
|
858
861
|
// src/recipients.ts
|
|
859
|
-
import { z as
|
|
860
|
-
var CreateRecipientSchema =
|
|
862
|
+
import { z as z19 } from "zod";
|
|
863
|
+
var CreateRecipientSchema = z19.object({
|
|
861
864
|
address: SplitAddressSchema.describe(
|
|
862
865
|
"Address to register as a trusted split recipient for your organization \u2014 an EVM 0x... address or a TRON T... address."
|
|
863
866
|
),
|
|
864
|
-
label:
|
|
867
|
+
label: z19.string().min(1).max(64).optional().describe('Free-form label for your own bookkeeping (e.g. `"supplier"`) \u2014 never interpreted.')
|
|
865
868
|
});
|
|
866
|
-
var RecipientSchema =
|
|
867
|
-
id:
|
|
869
|
+
var RecipientSchema = z19.object({
|
|
870
|
+
id: z19.string().describe(
|
|
868
871
|
"Klappay-generated id, e.g. `rc_...` \u2014 this, not the raw address, is what a charge's `splitRecipients[].recipientId` references."
|
|
869
872
|
),
|
|
870
873
|
environment: EnvironmentSchema,
|
|
871
|
-
address:
|
|
872
|
-
label:
|
|
873
|
-
payout:
|
|
874
|
+
address: z19.string(),
|
|
875
|
+
label: z19.string().nullable(),
|
|
876
|
+
payout: z19.boolean().describe(
|
|
874
877
|
"Whether this recipient is eligible to be used as an API key's `payoutAddress` (in addition to being referenceable in a split, which every non-revoked recipient already is). Set via `PATCH /v1/recipients/{id}` \u2014 requires the `recipients:manage_payout` scope, deliberately separate from `recipients:write`."
|
|
875
878
|
),
|
|
876
|
-
createdAt:
|
|
879
|
+
createdAt: z19.string().datetime()
|
|
877
880
|
});
|
|
878
881
|
var PaginatedRecipientsSchema = paginatedSchema(RecipientSchema);
|
|
879
|
-
var SetRecipientPayoutSchema =
|
|
880
|
-
payout:
|
|
882
|
+
var SetRecipientPayoutSchema = z19.object({
|
|
883
|
+
payout: z19.boolean().describe("New payout-eligibility value for this recipient.")
|
|
881
884
|
});
|
|
882
885
|
|
|
883
886
|
// src/timeline.ts
|
|
884
|
-
import { z as
|
|
885
|
-
var TransactionSourceSchema =
|
|
887
|
+
import { z as z20 } from "zod";
|
|
888
|
+
var TransactionSourceSchema = z20.enum(["contract_watcher", "reconciliation_job", "sandbox", "tron_watcher"]).describe(
|
|
886
889
|
"How this transfer was detected: `contract_watcher` (the normal path for EVM networks \u2014 a real-time WebSocket log subscription), `tron_watcher` (the TRON equivalent \u2014 a real-time ZeroMQ event subscription against a self-hosted node, a different underlying mechanism since TRON has no WebSocket log subscription), `reconciliation_job` (a fallback poller caught it after the watcher missed or delayed it), or `sandbox` (simulated via `POST /v1/sandbox/charges/{id}/trigger`, no real on-chain transfer)."
|
|
887
890
|
);
|
|
888
|
-
var TimelineEventTypeSchema =
|
|
891
|
+
var TimelineEventTypeSchema = z20.enum([
|
|
889
892
|
"charge.created",
|
|
890
893
|
"charge.expired",
|
|
891
894
|
"transaction.detected",
|
|
@@ -897,13 +900,13 @@ var TimelineEventTypeSchema = z19.enum([
|
|
|
897
900
|
]).describe(
|
|
898
901
|
"`charge.created`: the charge was created. `charge.expired`: `expiresAt` passed with no full payment. `transaction.detected`: a raw on-chain transfer was seen (see the `event`-shaped fields below for details \u2014 a charge can have more than one, e.g. a partial payment followed by the rest). `split.distributed`: a payout to the merchant completed on-chain, for one contributing `(token, network)` pair \u2014 a charge settled across more than one pair emits one of these per pair (see the `token`/`network` fields below). `webhook.dispatched`/`webhook.delivered`/`webhook.failed`: one specific delivery *attempt* for one webhook subscription \u2014 `failed` here means this single attempt failed, not that all retries were exhausted (see `WebhookDeliveryStatusSchema` for the exhausted-all-retries state). `transfer.reclaimed`: an on-chain transfer was detected but never reached its network's required confirmation depth before vanishing (reverted, or dropped from the canonical chain) \u2014 see `txHash` below for which transfer."
|
|
899
902
|
);
|
|
900
|
-
var TimelineEventSchema =
|
|
903
|
+
var TimelineEventSchema = z20.object({
|
|
901
904
|
type: TimelineEventTypeSchema,
|
|
902
|
-
at:
|
|
903
|
-
txHash:
|
|
905
|
+
at: z20.string().datetime(),
|
|
906
|
+
txHash: z20.string().optional().describe(
|
|
904
907
|
"Present for `transaction.detected`, `split.distributed`, and `transfer.reclaimed` events only."
|
|
905
908
|
),
|
|
906
|
-
amount:
|
|
909
|
+
amount: z20.number().optional().describe(
|
|
907
910
|
"Present for `transaction.detected` events only \u2014 the amount that specific transfer carried."
|
|
908
911
|
),
|
|
909
912
|
source: TransactionSourceSchema.optional().describe(
|
|
@@ -915,70 +918,70 @@ var TimelineEventSchema = z19.object({
|
|
|
915
918
|
network: NetworkSchema.optional().describe(
|
|
916
919
|
"Present for `transaction.detected` and `split.distributed` events \u2014 which network this specific transfer, or settlement, used."
|
|
917
920
|
),
|
|
918
|
-
causedTransition:
|
|
921
|
+
causedTransition: z20.boolean().optional().describe(
|
|
919
922
|
"Present for `transaction.detected` events only. `true` if this specific transfer changed the charge's status (e.g. PENDING\u2192CONFIRMED) \u2014 a charge paid in installments can have more than one such event."
|
|
920
923
|
),
|
|
921
924
|
event: WebhookEventTypeSchema.optional().describe(
|
|
922
925
|
"Present for `webhook.*` events only \u2014 which event type this delivery was for."
|
|
923
926
|
),
|
|
924
|
-
responseCode:
|
|
927
|
+
responseCode: z20.number().nullable().optional().describe(
|
|
925
928
|
"Present for `webhook.*` events only \u2014 HTTP status your endpoint returned, or `null` if the request never connected."
|
|
926
929
|
),
|
|
927
|
-
attempts:
|
|
930
|
+
attempts: z20.number().optional().describe(
|
|
928
931
|
"Present for `webhook.*` events only \u2014 how many delivery attempts have been made so far."
|
|
929
932
|
)
|
|
930
933
|
});
|
|
931
934
|
|
|
932
935
|
// src/health.ts
|
|
933
|
-
import { z as
|
|
934
|
-
var HealthSchema =
|
|
935
|
-
status:
|
|
936
|
+
import { z as z21 } from "zod";
|
|
937
|
+
var HealthSchema = z21.object({
|
|
938
|
+
status: z21.enum(["ok", "error"]).describe(
|
|
936
939
|
"`error` when the database connectivity check fails \u2014 the HTTP status code mirrors this (503 instead of 200), so a plain uptime check (not just a JSON-aware one) still catches a DB outage."
|
|
937
940
|
),
|
|
938
|
-
version:
|
|
939
|
-
timestamp:
|
|
940
|
-
db:
|
|
941
|
-
pendingWebhooks:
|
|
942
|
-
oldestPendingChargeAgeSeconds:
|
|
943
|
-
lastContractWatcherEventAgeSeconds:
|
|
941
|
+
version: z21.string(),
|
|
942
|
+
timestamp: z21.string().datetime(),
|
|
943
|
+
db: z21.enum(["ok", "error"]).describe("Result of a real database connectivity check, not just a process-alive check."),
|
|
944
|
+
pendingWebhooks: z21.number().describe("Count of webhook deliveries still awaiting a successful attempt."),
|
|
945
|
+
oldestPendingChargeAgeSeconds: z21.number().nullable().describe("Age of the oldest still-unpaid charge, in seconds. `null` if there are none."),
|
|
946
|
+
lastContractWatcherEventAgeSeconds: z21.number().nullable().describe(
|
|
944
947
|
"Seconds since the last on-chain payment notification was received \u2014 a cheap signal for whether payment detection is currently working. `null` if none have ever been received."
|
|
945
948
|
)
|
|
946
949
|
});
|
|
947
950
|
|
|
948
951
|
// src/sandbox.ts
|
|
949
|
-
import { z as
|
|
950
|
-
var SandboxTriggerSchema =
|
|
952
|
+
import { z as z22 } from "zod";
|
|
953
|
+
var SandboxTriggerSchema = z22.object({
|
|
951
954
|
event: TriggerableChargeEventSchema,
|
|
952
|
-
amount:
|
|
955
|
+
amount: z22.number().positive().max(CHARGE_AMOUNT_MAX).optional().describe(
|
|
953
956
|
"Used with `charge.partially_paid` (amount to simulate as received so far \u2014 must be less than the charge amount, defaults to half of it if omitted) and with `charge.overpaid` (amount received \u2014 must be greater than the charge amount, defaults to 1.5x it if omitted). Ignored for every other event."
|
|
954
957
|
)
|
|
955
958
|
});
|
|
956
959
|
|
|
957
960
|
// src/capabilities.ts
|
|
958
|
-
import { z as
|
|
959
|
-
var CapabilitiesSchema =
|
|
960
|
-
acceptedPayments:
|
|
961
|
+
import { z as z23 } from "zod";
|
|
962
|
+
var CapabilitiesSchema = z23.object({
|
|
963
|
+
acceptedPayments: z23.array(AcceptedPaymentSchema).describe(
|
|
961
964
|
"Every `(token, network)` pair enabled for your environment right now, using the same deployment metadata and availability policy as `POST /v1/charges`. Cataloged but disabled pairs are omitted. Availability can change between requests, so handle `422 token_not_supported` when creating a charge. Use this to build a picker UI instead of hardcoding the matrix client-side."
|
|
962
965
|
)
|
|
963
966
|
});
|
|
964
967
|
|
|
965
968
|
// src/swap.ts
|
|
966
|
-
import { z as
|
|
967
|
-
var CreateSwapQuoteSchema =
|
|
969
|
+
import { z as z24 } from "zod";
|
|
970
|
+
var CreateSwapQuoteSchema = z24.object({
|
|
968
971
|
inputToken: AltTokenSchema.describe(
|
|
969
972
|
"Which alt-cryptocurrency the payer wants to send \u2014 must be one of this charge's `swapAlternatives`, or `422 token_not_supported`."
|
|
970
973
|
),
|
|
971
974
|
inputNetwork: NetworkSchema.describe(
|
|
972
975
|
"Which network the payer will send `inputToken` on. Also picks which of this charge's `acceptedPayments` pairs the swap resolves to \u2014 a charge accepting USDC on both Base and Optimism resolves to whichever `inputNetwork` you pass. If the charge accepts more than one token on that same network, Klappay applies its token preference among enabled pairs the charge accepts. BNB Chain payments are currently disabled for both cataloged Binance-Peg tokens."
|
|
973
976
|
),
|
|
974
|
-
takerAddress:
|
|
977
|
+
takerAddress: z24.string().regex(/^0x[0-9a-fA-F]{40}$/, "must be a 20-byte hex address").describe(
|
|
975
978
|
"The payer's own wallet address \u2014 the account that will sign and submit the swap transaction. Not validated against anything else; any well-formed address is accepted, since Klappay never custodies these funds."
|
|
976
979
|
)
|
|
977
980
|
});
|
|
978
|
-
var SwapQuoteSchema =
|
|
981
|
+
var SwapQuoteSchema = z24.object({
|
|
979
982
|
inputToken: AltTokenSchema,
|
|
980
983
|
inputNetwork: NetworkSchema,
|
|
981
|
-
inputAmount:
|
|
984
|
+
inputAmount: z24.number().describe(
|
|
982
985
|
"The ceiling of `inputToken` the payer needs available to sign for, in whole units (not wei/base units) \u2014 not necessarily the exact final cost. Any `inputToken` beyond what the swap actually needs (price moved favorably, less slippage than budgeted) is swapped back and refunded to the payer automatically, in the same transaction \u2014 never a separate step or a Klappay-side refund."
|
|
983
986
|
),
|
|
984
987
|
inputAmountExact: ExactAmountSchema.optional().describe(
|
|
@@ -988,20 +991,20 @@ var SwapQuoteSchema = z23.object({
|
|
|
988
991
|
"Which of this charge's `acceptedPayments` tokens the swap resolves to."
|
|
989
992
|
),
|
|
990
993
|
outputNetwork: NetworkSchema,
|
|
991
|
-
outputAmount:
|
|
994
|
+
outputAmount: z24.number().describe(
|
|
992
995
|
"The stablecoin amount requested by this quote, in whole `outputToken` units. Covers the remaining balance, rounded up only if the selected token cannot represent it exactly. This legacy JSON number can lose precision; use `outputAmountExact` for arithmetic. The actual transfer is verified on-chain before crediting the charge."
|
|
993
996
|
),
|
|
994
997
|
outputAmountExact: ExactAmountSchema.optional().describe(
|
|
995
998
|
"Exact stablecoin amount requested by this quote, in whole `outputToken` units as a nonnegative decimal string with no scientific notation. Covers the remaining charge balance and rounds upward only to the smallest representable token unit when needed. Optional for compatibility with older API responses."
|
|
996
999
|
),
|
|
997
|
-
fees:
|
|
998
|
-
klappayFee:
|
|
1000
|
+
fees: z24.object({
|
|
1001
|
+
klappayFee: z24.number().describe(
|
|
999
1002
|
"Klappay's own swap fee (1% today), in `outputToken` units \u2014 paid by the payer and already reflected in `inputAmount`, separate from the merchant's own `feePercent`. Never subtracted from `outputAmount`."
|
|
1000
1003
|
),
|
|
1001
1004
|
klappayFeeExact: ExactAmountSchema.optional().describe(
|
|
1002
1005
|
"Exact Klappay swap fee in whole `outputToken` units as a nonnegative decimal string with at most 18 fractional digits and no scientific notation. Already reflected in the input ceiling. Optional for compatibility with older API responses."
|
|
1003
1006
|
),
|
|
1004
|
-
zeroExFee:
|
|
1007
|
+
zeroExFee: z24.number().nullable().describe(
|
|
1005
1008
|
"0x's own protocol fee for this specific token pair, in `outputToken` units, or `null` when this pair isn't currently one 0x charges on. Paid by the payer and already reflected in `inputAmount`, never subtracted from `outputAmount` \u2014 Klappay never sees this fee, it goes straight to 0x."
|
|
1006
1009
|
),
|
|
1007
1010
|
zeroExFeeExact: ExactAmountSchema.nullable().optional().describe(
|
|
@@ -1010,19 +1013,19 @@ var SwapQuoteSchema = z23.object({
|
|
|
1010
1013
|
}).describe(
|
|
1011
1014
|
"Every fee the payer is charged for using swap-to-pay, broken out by who collects it \u2014 both already reflected in `inputAmount`, shown here separately for transparency. Neither ever reduces `outputAmount`."
|
|
1012
1015
|
),
|
|
1013
|
-
expiresAt:
|
|
1016
|
+
expiresAt: z24.string().datetime().describe(
|
|
1014
1017
|
"When this quote's price is no longer safely valid \u2014 a rough guide for the payer's UI countdown only. The actual price guarantee is enforced on-chain by the swap transaction itself (a signed Permit2 deadline, or a minimum-output check for a native-currency sell), not by this timestamp \u2014 submitting after it expires either reverts on-chain or simply gets re-quoted at the current price, never silently executes at a stale rate."
|
|
1015
1018
|
),
|
|
1016
|
-
transaction:
|
|
1017
|
-
to:
|
|
1018
|
-
data:
|
|
1019
|
-
value:
|
|
1019
|
+
transaction: z24.object({
|
|
1020
|
+
to: z24.string().describe("Contract address the payer's wallet must send this transaction to."),
|
|
1021
|
+
data: z24.string().describe("Calldata \u2014 opaque, must be sent unmodified."),
|
|
1022
|
+
value: z24.string().describe(
|
|
1020
1023
|
"Native currency (ETH/BNB/POL/AVAX) to attach, in wei \u2014 `\"0\"` when `inputToken` isn't this network's native currency."
|
|
1021
1024
|
)
|
|
1022
1025
|
}).describe(
|
|
1023
1026
|
"Pass this directly to the payer's wallet (e.g. viem/ethers `sendTransaction`) \u2014 Klappay never touches the payer's private key or submits anything on their behalf. If `permit2` is present on this response, sign that first and append the signature to this `data` before sending; if `permit2` is absent, send `transaction` as-is with no extra step."
|
|
1024
1027
|
),
|
|
1025
|
-
permit2:
|
|
1028
|
+
permit2: z24.object({ eip712: z24.record(z24.unknown()) }).nullish().describe(
|
|
1026
1029
|
"Present only when `inputToken` is an ERC-20 (BTC, LINK, or a chain-specific blue chip like ARB/OP/CBETH) \u2014 the payer's wallet must sign this EIP-712 message and append the signature to `transaction.data` before sending, since an ERC-20 sell needs a Permit2 allowance signature that a native-currency sell doesn't. `null` (never omitted, in a genuine 0x-backed quote) when `inputToken` is a network's own native currency (ETH/BNB/POL/AVAX) \u2014 `transaction` is then ready to sign and send directly, no extra step."
|
|
1027
1030
|
)
|
|
1028
1031
|
});
|