@klappay/types 3.1.1 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.d.mts +93 -1
- package/dist/index.d.ts +93 -1
- package/dist/index.js +280 -239
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +277 -239
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -116,7 +116,7 @@ function listSwapAlternatives(networks) {
|
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
// src/charges.ts
|
|
119
|
-
import { z as
|
|
119
|
+
import { z as z10 } from "zod";
|
|
120
120
|
|
|
121
121
|
// src/checkout-metadata.ts
|
|
122
122
|
import { z as z8 } from "zod";
|
|
@@ -139,27 +139,40 @@ var MetadataWithKlappaySchema = z8.object({ klappay: KlappayCheckoutMetadataSche
|
|
|
139
139
|
"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`."
|
|
140
140
|
);
|
|
141
141
|
|
|
142
|
+
// src/escrow.ts
|
|
143
|
+
import { z as z9 } from "zod";
|
|
144
|
+
var EscrowConfigSchema = z9.object({
|
|
145
|
+
releaserAddress: z9.string().regex(/^0x[0-9a-fA-F]{40}$/, "must be a 20-byte hex address").optional().describe(
|
|
146
|
+
"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."
|
|
147
|
+
)
|
|
148
|
+
});
|
|
149
|
+
var ReleaseEscrowRequestSchema = z9.object({
|
|
150
|
+
signature: z9.string().regex(/^0x[0-9a-fA-F]+$/, "must be hex-encoded signature bytes").describe(
|
|
151
|
+
"The Safe transaction signature authorizing this release, produced by signing the escrow's predetermined release transaction (destination and amount are fixed at escrow creation, never client-supplied here) with the private key behind this charge's `escrowReleaserAddress` \u2014 never anything Klappay can produce itself. Independently verified on-chain before anything moves; a mismatched, malformed, or missing signature is rejected, never trusted at face value."
|
|
152
|
+
)
|
|
153
|
+
});
|
|
154
|
+
|
|
142
155
|
// src/charges.ts
|
|
143
|
-
var ChargeStatusSchema =
|
|
156
|
+
var ChargeStatusSchema = z10.enum(["pending", "partially_paid", "confirmed", "expired", "underpaid"]).describe(
|
|
144
157
|
"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."
|
|
145
158
|
);
|
|
146
|
-
var SettlementStatusSchema =
|
|
159
|
+
var SettlementStatusSchema = z10.enum(["pending", "completed", "failed"]).describe(
|
|
147
160
|
"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."
|
|
148
161
|
);
|
|
149
162
|
var CHARGE_EXPIRES_IN_MIN_SECONDS = 60;
|
|
150
163
|
var CHARGE_EXPIRES_IN_MAX_SECONDS = 3600;
|
|
151
164
|
var CHARGE_ACCEPTED_PAYMENTS_MAX = 14;
|
|
152
|
-
var AcceptedPaymentSchema =
|
|
165
|
+
var AcceptedPaymentSchema = z10.object({
|
|
153
166
|
token: TokenSchema,
|
|
154
167
|
network: NetworkSchema
|
|
155
168
|
});
|
|
156
|
-
var AcceptedPaymentsSchema =
|
|
169
|
+
var AcceptedPaymentsSchema = z10.array(AcceptedPaymentSchema).min(1, "At least one accepted payment is required.").max(CHARGE_ACCEPTED_PAYMENTS_MAX).superRefine((pairs, ctx) => {
|
|
157
170
|
const seen = /* @__PURE__ */ new Set();
|
|
158
171
|
pairs.forEach((pair, index) => {
|
|
159
172
|
const key = `${pair.token}:${pair.network}`;
|
|
160
173
|
if (seen.has(key)) {
|
|
161
174
|
ctx.addIssue({
|
|
162
|
-
code:
|
|
175
|
+
code: z10.ZodIssueCode.custom,
|
|
163
176
|
message: `Duplicate accepted payment: ${pair.token} on ${pair.network}.`,
|
|
164
177
|
path: [index]
|
|
165
178
|
});
|
|
@@ -167,7 +180,7 @@ var AcceptedPaymentsSchema = z9.array(AcceptedPaymentSchema).min(1, "At least on
|
|
|
167
180
|
seen.add(key);
|
|
168
181
|
if (!OPERATIONAL_NETWORKS.includes(pair.network)) {
|
|
169
182
|
ctx.addIssue({
|
|
170
|
-
code:
|
|
183
|
+
code: z10.ZodIssueCode.custom,
|
|
171
184
|
message: `Network "${pair.network}" isn't live yet \u2014 only ${OPERATIONAL_NETWORKS.join(", ")} today.`,
|
|
172
185
|
path: [index, "network"]
|
|
173
186
|
});
|
|
@@ -177,32 +190,32 @@ var AcceptedPaymentsSchema = z9.array(AcceptedPaymentSchema).min(1, "At least on
|
|
|
177
190
|
`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\`.`
|
|
178
191
|
);
|
|
179
192
|
var CHARGE_SPLIT_RECIPIENTS_MAX = 5;
|
|
180
|
-
var SplitRecipientSchema =
|
|
181
|
-
address:
|
|
182
|
-
percent:
|
|
193
|
+
var SplitRecipientSchema = z10.object({
|
|
194
|
+
address: z10.string().regex(/^0x[0-9a-fA-F]{40}$/, "must be a 20-byte hex address").describe("EVM address to send a slice of this charge to."),
|
|
195
|
+
percent: z10.number().positive().max(100).describe(
|
|
183
196
|
"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."
|
|
184
197
|
),
|
|
185
|
-
label:
|
|
198
|
+
label: z10.string().min(1).max(64).optional().describe(
|
|
186
199
|
'Free-form label for your own bookkeeping (e.g. `"supplier"`, `"sales rep"`) \u2014 echoed back unchanged, never interpreted by Klappay.'
|
|
187
200
|
)
|
|
188
201
|
});
|
|
189
|
-
var SplitRecipientInputSchema =
|
|
190
|
-
recipientId:
|
|
202
|
+
var SplitRecipientInputSchema = z10.object({
|
|
203
|
+
recipientId: z10.string().describe(
|
|
191
204
|
"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."
|
|
192
205
|
),
|
|
193
|
-
percent:
|
|
206
|
+
percent: z10.number().positive().max(100).describe(
|
|
194
207
|
"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."
|
|
195
208
|
),
|
|
196
|
-
label:
|
|
209
|
+
label: z10.string().min(1).max(64).optional().describe(
|
|
197
210
|
'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.'
|
|
198
211
|
)
|
|
199
212
|
});
|
|
200
|
-
var SplitRecipientsInputSchema =
|
|
213
|
+
var SplitRecipientsInputSchema = z10.array(SplitRecipientInputSchema).max(CHARGE_SPLIT_RECIPIENTS_MAX).superRefine((recipients, ctx) => {
|
|
201
214
|
const seen = /* @__PURE__ */ new Set();
|
|
202
215
|
recipients.forEach((recipient, index) => {
|
|
203
216
|
if (seen.has(recipient.recipientId)) {
|
|
204
217
|
ctx.addIssue({
|
|
205
|
-
code:
|
|
218
|
+
code: z10.ZodIssueCode.custom,
|
|
206
219
|
message: `Duplicate split recipientId: ${recipient.recipientId}.`,
|
|
207
220
|
path: [index, "recipientId"]
|
|
208
221
|
});
|
|
@@ -213,82 +226,91 @@ var SplitRecipientsInputSchema = z9.array(SplitRecipientInputSchema).max(CHARGE_
|
|
|
213
226
|
`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\`.`
|
|
214
227
|
);
|
|
215
228
|
var CHARGE_AMOUNT_MAX = 999999999999;
|
|
216
|
-
var CreateChargeSchema =
|
|
217
|
-
amount:
|
|
229
|
+
var CreateChargeSchema = z10.object({
|
|
230
|
+
amount: z10.number().positive().max(CHARGE_AMOUNT_MAX).describe(
|
|
218
231
|
"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."
|
|
219
232
|
),
|
|
220
|
-
currency:
|
|
233
|
+
currency: z10.literal("USD").default("USD").describe("Always `USD` today \u2014 the only supported currency."),
|
|
221
234
|
acceptedPayments: AcceptedPaymentsSchema,
|
|
222
|
-
expiresIn:
|
|
235
|
+
expiresIn: z10.number().int().min(CHARGE_EXPIRES_IN_MIN_SECONDS).max(CHARGE_EXPIRES_IN_MAX_SECONDS).describe(
|
|
223
236
|
"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."
|
|
224
237
|
),
|
|
225
|
-
idempotencyKey:
|
|
238
|
+
idempotencyKey: z10.string().min(1).max(255).optional().describe(
|
|
226
239
|
"Scoped to your tenant. Replaying the same key returns the original charge unchanged instead of creating a duplicate \u2014 safe to retry a request after a timeout without double-charging."
|
|
227
240
|
),
|
|
228
|
-
externalRef:
|
|
241
|
+
externalRef: z10.string().min(1).max(255).optional().describe(
|
|
229
242
|
"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."
|
|
230
243
|
),
|
|
231
|
-
source:
|
|
244
|
+
source: z10.string().min(1).max(64).optional().describe(
|
|
232
245
|
'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.'
|
|
233
246
|
),
|
|
234
247
|
metadata: MetadataWithKlappaySchema.optional(),
|
|
235
|
-
redirectUrl:
|
|
248
|
+
redirectUrl: z10.string().url().refine((value) => /^https?:\/\//.test(value), "must use http or https").optional().describe(
|
|
236
249
|
"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."
|
|
237
250
|
),
|
|
238
|
-
splitRecipients: SplitRecipientsInputSchema.optional()
|
|
251
|
+
splitRecipients: SplitRecipientsInputSchema.optional(),
|
|
252
|
+
escrow: EscrowConfigSchema.optional().describe(
|
|
253
|
+
"Configure this charge as an escrow instead of a normal payment. Funds land in a dedicated, non-custodial Safe (not the usual split address) and only `releaserAddress` (or, if omitted, your API key's own `payoutAddress`) can ever release them \u2014 via `POST /v1/charges/{id}/release`, signed on their end, never something Klappay can trigger or redirect. Omit this field entirely for a normal charge."
|
|
254
|
+
)
|
|
239
255
|
});
|
|
240
|
-
var ChargeSchema =
|
|
241
|
-
id:
|
|
242
|
-
amount:
|
|
243
|
-
amountReceived:
|
|
256
|
+
var ChargeSchema = z10.object({
|
|
257
|
+
id: z10.string().describe("Klappay-generated id, e.g. `ch_...`. Use this to look up the charge later."),
|
|
258
|
+
amount: z10.number().describe("The amount originally requested, in `currency` units (up to 6 decimal places)."),
|
|
259
|
+
amountReceived: z10.number().nullable().describe(
|
|
244
260
|
"Cumulative amount actually received on-chain so far, in `currency` units (up to 6 decimal places). `null` until the first transfer arrives. Can exceed `amount` \u2014 see `isOverpaid`."
|
|
245
261
|
),
|
|
246
|
-
isOverpaid:
|
|
262
|
+
isOverpaid: z10.boolean().describe(
|
|
247
263
|
"`true` if `amountReceived` ended up greater than `amount`. Klappay never refunds the difference automatically \u2014 see the docs for why."
|
|
248
264
|
),
|
|
249
|
-
currency:
|
|
250
|
-
acceptedPayments:
|
|
265
|
+
currency: z10.string().describe("Always `USD` today \u2014 the only supported currency."),
|
|
266
|
+
acceptedPayments: z10.array(AcceptedPaymentSchema).describe(
|
|
251
267
|
"Every `(token, network)` pair this charge was configured to accept, unchanged after creation."
|
|
252
268
|
),
|
|
253
|
-
paidWith:
|
|
269
|
+
paidWith: z10.array(AcceptedPaymentSchema).describe(
|
|
254
270
|
"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`."
|
|
255
271
|
),
|
|
256
|
-
swapAlternatives:
|
|
272
|
+
swapAlternatives: z10.array(SwapAlternativeSchema).describe(
|
|
257
273
|
"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`)."
|
|
258
274
|
),
|
|
259
|
-
address:
|
|
275
|
+
address: z10.string().describe(
|
|
260
276
|
"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."
|
|
261
277
|
),
|
|
262
278
|
status: ChargeStatusSchema,
|
|
263
279
|
settlementStatus: SettlementStatusSchema.nullable(),
|
|
264
280
|
environment: EnvironmentSchema,
|
|
265
|
-
apiKeyId:
|
|
281
|
+
apiKeyId: z10.string().nullable().describe(
|
|
266
282
|
"Which of your API keys created this charge. `null` for a charge created before this field existed."
|
|
267
283
|
),
|
|
268
|
-
txHash:
|
|
284
|
+
txHash: z10.string().nullable().describe(
|
|
269
285
|
"Transaction hash of the most recent transfer detected for this charge. `null` until a payment is detected."
|
|
270
286
|
),
|
|
271
|
-
externalRef:
|
|
272
|
-
source:
|
|
287
|
+
externalRef: z10.string().nullable(),
|
|
288
|
+
source: z10.string().nullable(),
|
|
273
289
|
metadata: MetadataWithKlappaySchema.nullable(),
|
|
274
|
-
redirectUrl:
|
|
275
|
-
checkoutUrl:
|
|
290
|
+
redirectUrl: z10.string().nullable().describe("Echoes the `redirectUrl` set at creation, if any. `null` if none was set."),
|
|
291
|
+
checkoutUrl: z10.string().nullable().describe(
|
|
276
292
|
"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."
|
|
277
293
|
),
|
|
278
|
-
splitRecipients:
|
|
279
|
-
createdAt:
|
|
280
|
-
expiresAt:
|
|
294
|
+
splitRecipients: z10.array(SplitRecipientSchema).describe("Echoes whatever extra split recipients were set at creation \u2014 empty array if none."),
|
|
295
|
+
createdAt: z10.string().datetime(),
|
|
296
|
+
expiresAt: z10.string().datetime().describe(
|
|
281
297
|
"When this charge stops accepting payment, if still `pending`/`partially_paid` by then."
|
|
282
298
|
),
|
|
283
|
-
confirmedAt:
|
|
284
|
-
settledAt:
|
|
299
|
+
confirmedAt: z10.string().datetime().nullable().describe("When `status` first reached `confirmed`. `null` until then."),
|
|
300
|
+
settledAt: z10.string().datetime().nullable().describe(
|
|
285
301
|
"When `settlementStatus` first reached `completed` \u2014 the merchant's wallet actually has the funds. `null` until then, including while `settlementStatus` is `pending`/`failed`."
|
|
286
302
|
),
|
|
287
|
-
lastActivityAt:
|
|
303
|
+
lastActivityAt: z10.string().datetime().describe(
|
|
288
304
|
"When a transfer was last credited toward this charge, or `createdAt` if none has arrived yet."
|
|
305
|
+
),
|
|
306
|
+
escrow: z10.object({
|
|
307
|
+
releaserAddress: z10.string().describe("The only address that can ever release this escrow \u2014 never Klappay."),
|
|
308
|
+
releasedAt: z10.string().datetime().nullable().describe("When the release actually executed on-chain. `null` until then.")
|
|
309
|
+
}).nullable().describe(
|
|
310
|
+
"Present only when this charge was created as an escrow (see `escrow` on the create request) \u2014 `null` for a normal charge."
|
|
289
311
|
)
|
|
290
312
|
});
|
|
291
|
-
var ListChargesSchema =
|
|
313
|
+
var ListChargesSchema = z10.object({
|
|
292
314
|
status: ChargeStatusSchema.optional(),
|
|
293
315
|
token: TokenSchema.optional().describe(
|
|
294
316
|
"Filters on `paidWith.token` \u2014 the pair actually paid, not accepted."
|
|
@@ -297,75 +319,88 @@ var ListChargesSchema = z9.object({
|
|
|
297
319
|
"Filters on `paidWith.network` \u2014 the pair actually paid, not accepted."
|
|
298
320
|
),
|
|
299
321
|
environment: EnvironmentSchema.optional(),
|
|
300
|
-
since:
|
|
322
|
+
since: z10.string().datetime().optional().describe(
|
|
301
323
|
"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."
|
|
302
324
|
),
|
|
303
|
-
isOverpaid:
|
|
325
|
+
isOverpaid: z10.enum(["true", "false"]).transform((v) => v === "true").optional()
|
|
304
326
|
}).extend(PaginationQuerySchema.shape);
|
|
305
327
|
var PaginatedChargesSchema = paginatedSchema(ChargeSchema);
|
|
306
|
-
var GetChargeQrCodeQuerySchema =
|
|
328
|
+
var GetChargeQrCodeQuerySchema = z10.object({
|
|
307
329
|
token: TokenSchema.optional().describe(
|
|
308
330
|
"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."
|
|
309
331
|
),
|
|
310
332
|
network: NetworkSchema.optional()
|
|
311
333
|
});
|
|
312
334
|
|
|
335
|
+
// src/charge-check.ts
|
|
336
|
+
import { z as z11 } from "zod";
|
|
337
|
+
var CheckChargeRequestSchema = z11.object({
|
|
338
|
+
txHash: z11.string().regex(/^0x[0-9a-fA-F]{64}$/, "must be a 32-byte transaction hash").optional().describe(
|
|
339
|
+
"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."
|
|
340
|
+
),
|
|
341
|
+
network: NetworkSchema.optional().describe(
|
|
342
|
+
"Which network `txHash` is on \u2014 required together with `txHash`, since a transaction hash alone doesn't identify a chain. Must be one of the networks this charge actually accepts payment on, or `422 payment_pair_not_accepted`."
|
|
343
|
+
)
|
|
344
|
+
}).refine((data) => Boolean(data.txHash) === Boolean(data.network), {
|
|
345
|
+
message: "`txHash` and `network` must be provided together, or both omitted"
|
|
346
|
+
});
|
|
347
|
+
|
|
313
348
|
// src/distributions.ts
|
|
314
|
-
import { z as
|
|
315
|
-
var SplitDistributionStatusSchema =
|
|
349
|
+
import { z as z12 } from "zod";
|
|
350
|
+
var SplitDistributionStatusSchema = z12.enum(["pending", "processing", "completed", "failed"]).describe(
|
|
316
351
|
"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."
|
|
317
352
|
);
|
|
318
|
-
var PendingDistributionRecipientSchema =
|
|
319
|
-
address:
|
|
320
|
-
percentAllocation:
|
|
353
|
+
var PendingDistributionRecipientSchema = z12.object({
|
|
354
|
+
address: z12.string().describe("On-chain recipient address."),
|
|
355
|
+
percentAllocation: z12.number().describe("This recipient's share of the split, as a percentage (e.g. `99.0991` = 99.0991%).")
|
|
321
356
|
});
|
|
322
|
-
var PendingDistributionSchema =
|
|
323
|
-
splitAddress:
|
|
357
|
+
var PendingDistributionSchema = z12.object({
|
|
358
|
+
splitAddress: z12.string().describe("The on-chain 0xSplits address to call `distribute()` on."),
|
|
324
359
|
network: NetworkSchema,
|
|
325
360
|
token: TokenSchema,
|
|
326
|
-
recipients:
|
|
361
|
+
recipients: z12.array(PendingDistributionRecipientSchema).describe(
|
|
327
362
|
"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."
|
|
328
363
|
),
|
|
329
|
-
distributorFeePercent:
|
|
364
|
+
distributorFeePercent: z12.number().describe(
|
|
330
365
|
"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."
|
|
331
366
|
),
|
|
332
|
-
estimatedRewardAmount:
|
|
367
|
+
estimatedRewardAmount: z12.number().describe(
|
|
333
368
|
"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."
|
|
334
369
|
),
|
|
335
|
-
availableSince:
|
|
336
|
-
graceEndsAt:
|
|
370
|
+
availableSince: z12.string().datetime().describe("When this distribution entered its grace period."),
|
|
371
|
+
graceEndsAt: z12.string().datetime().describe(
|
|
337
372
|
"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."
|
|
338
373
|
)
|
|
339
374
|
});
|
|
340
375
|
var PaginatedPendingDistributionsSchema = paginatedSchema(PendingDistributionSchema);
|
|
341
|
-
var ListenPendingDistributionsQuerySchema =
|
|
342
|
-
limit:
|
|
376
|
+
var ListenPendingDistributionsQuerySchema = z12.object({
|
|
377
|
+
limit: z12.coerce.number().int().min(0).max(PAGINATION_LIMIT_MAX).default(0).describe(
|
|
343
378
|
"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."
|
|
344
379
|
)
|
|
345
380
|
});
|
|
346
|
-
var PendingDistributionEventSchema =
|
|
347
|
-
|
|
348
|
-
type:
|
|
381
|
+
var PendingDistributionEventSchema = z12.discriminatedUnion("type", [
|
|
382
|
+
z12.object({
|
|
383
|
+
type: z12.literal("distribution.available"),
|
|
349
384
|
distribution: PendingDistributionSchema
|
|
350
385
|
}),
|
|
351
|
-
|
|
352
|
-
type:
|
|
353
|
-
splitAddress:
|
|
386
|
+
z12.object({
|
|
387
|
+
type: z12.literal("distribution.claimed"),
|
|
388
|
+
splitAddress: z12.string().describe("No longer claimable \u2014 either settled by someone, or picked up by the worker.")
|
|
354
389
|
})
|
|
355
390
|
]);
|
|
356
391
|
|
|
357
392
|
// src/metrics.ts
|
|
358
|
-
import { z as
|
|
359
|
-
var MetricsResourceSchema =
|
|
393
|
+
import { z as z13 } from "zod";
|
|
394
|
+
var MetricsResourceSchema = z13.enum(["charges", "transactions", "distributions"]).describe(
|
|
360
395
|
"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."
|
|
361
396
|
);
|
|
362
|
-
var MetricsAggregationSchema =
|
|
397
|
+
var MetricsAggregationSchema = z13.enum(["count", "sum", "avg", "min", "max"]).describe(
|
|
363
398
|
"`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."
|
|
364
399
|
);
|
|
365
|
-
var MetricsFilterOperatorSchema =
|
|
400
|
+
var MetricsFilterOperatorSchema = z13.enum(["eq", "neq", "in", "gt", "gte", "lt", "lte"]).describe(
|
|
366
401
|
"`in` expects an array value (max 50 entries); every other operator expects a single scalar."
|
|
367
402
|
);
|
|
368
|
-
var MetricsDateGranularitySchema =
|
|
403
|
+
var MetricsDateGranularitySchema = z13.enum(["day", "week", "month", "year"]).describe(
|
|
369
404
|
"Bucket width for a `date_bucket` `groupBy` entry \u2014 Postgres `date_trunc` semantics (UTC)."
|
|
370
405
|
);
|
|
371
406
|
var metricsQueryEnvironmentSchema = EnvironmentSchema.describe(
|
|
@@ -378,151 +413,151 @@ var METRICS_QUERY_MAX_GROUP_BY = 3;
|
|
|
378
413
|
var METRICS_QUERY_MAX_FILTERS = 20;
|
|
379
414
|
var METRICS_QUERY_MAX_METRICS = 10;
|
|
380
415
|
var METRIC_ALIAS_PATTERN = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
|
|
381
|
-
var metricAliasSchema =
|
|
416
|
+
var metricAliasSchema = z13.string().min(1).max(64).regex(
|
|
382
417
|
METRIC_ALIAS_PATTERN,
|
|
383
418
|
"Must start with a letter or underscore, and contain only letters, digits, and underscores \u2014 this becomes a SQL column alias."
|
|
384
419
|
).optional();
|
|
385
|
-
var MetricsFilterValueSchema =
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
420
|
+
var MetricsFilterValueSchema = z13.union([
|
|
421
|
+
z13.string().max(255),
|
|
422
|
+
z13.number(),
|
|
423
|
+
z13.boolean(),
|
|
424
|
+
z13.array(z13.union([z13.string().max(255), z13.number()])).min(1).max(50)
|
|
390
425
|
]);
|
|
391
|
-
var orderBySchema =
|
|
392
|
-
key:
|
|
426
|
+
var orderBySchema = z13.object({
|
|
427
|
+
key: z13.string().min(1).max(64).regex(
|
|
393
428
|
METRIC_ALIAS_PATTERN,
|
|
394
429
|
"Must start with a letter or underscore, and contain only letters, digits, and underscores \u2014 every valid output column name already looks like this."
|
|
395
430
|
).describe(
|
|
396
431
|
"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."
|
|
397
432
|
),
|
|
398
|
-
direction:
|
|
433
|
+
direction: z13.enum(["asc", "desc"])
|
|
399
434
|
}).describe(
|
|
400
435
|
"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."
|
|
401
436
|
);
|
|
402
|
-
var limitSchema =
|
|
437
|
+
var limitSchema = z13.number().int().min(1).max(METRICS_QUERY_MAX_ROW_LIMIT).default(METRICS_QUERY_DEFAULT_ROW_LIMIT).describe(
|
|
403
438
|
`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.`
|
|
404
439
|
);
|
|
405
|
-
var ChargesQueryFieldSchema =
|
|
440
|
+
var ChargesQueryFieldSchema = z13.enum(["status", "source", "apiKeyId", "currency", "isOverpaid", "externalRef"]).describe(
|
|
406
441
|
"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."
|
|
407
442
|
);
|
|
408
|
-
var ChargesMetricFieldSchema =
|
|
443
|
+
var ChargesMetricFieldSchema = z13.enum(["amount", "amountReceived", "feePercent"]).describe(
|
|
409
444
|
"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%."
|
|
410
445
|
);
|
|
411
|
-
var ChargesDateFieldSchema =
|
|
446
|
+
var ChargesDateFieldSchema = z13.enum(["createdAt", "confirmedAt", "lastActivityAt", "expiresAt"]).describe(
|
|
412
447
|
"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."
|
|
413
448
|
);
|
|
414
|
-
var ChargesFilterSchema =
|
|
449
|
+
var ChargesFilterSchema = z13.object({
|
|
415
450
|
field: ChargesQueryFieldSchema,
|
|
416
451
|
operator: MetricsFilterOperatorSchema,
|
|
417
452
|
value: MetricsFilterValueSchema
|
|
418
453
|
});
|
|
419
|
-
var ChargesGroupBySchema =
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
type:
|
|
454
|
+
var ChargesGroupBySchema = z13.union([
|
|
455
|
+
z13.object({ type: z13.literal("field"), field: ChargesQueryFieldSchema }),
|
|
456
|
+
z13.object({
|
|
457
|
+
type: z13.literal("date_bucket"),
|
|
423
458
|
field: ChargesDateFieldSchema,
|
|
424
459
|
granularity: MetricsDateGranularitySchema
|
|
425
460
|
})
|
|
426
461
|
]);
|
|
427
|
-
var ChargesMetricSchema =
|
|
462
|
+
var ChargesMetricSchema = z13.object({
|
|
428
463
|
aggregation: MetricsAggregationSchema,
|
|
429
464
|
field: ChargesMetricFieldSchema.optional(),
|
|
430
465
|
alias: metricAliasSchema
|
|
431
466
|
});
|
|
432
|
-
var ChargesMetricsQuerySchema =
|
|
433
|
-
resource:
|
|
467
|
+
var ChargesMetricsQuerySchema = z13.object({
|
|
468
|
+
resource: z13.literal("charges"),
|
|
434
469
|
environment: metricsQueryEnvironmentSchema,
|
|
435
|
-
dateRange:
|
|
470
|
+
dateRange: z13.object({
|
|
436
471
|
field: ChargesDateFieldSchema,
|
|
437
|
-
from:
|
|
438
|
-
to:
|
|
472
|
+
from: z13.string().max(64).datetime(),
|
|
473
|
+
to: z13.string().max(64).datetime()
|
|
439
474
|
}),
|
|
440
|
-
groupBy:
|
|
441
|
-
metrics:
|
|
442
|
-
filters:
|
|
475
|
+
groupBy: z13.array(ChargesGroupBySchema).max(METRICS_QUERY_MAX_GROUP_BY).default([]),
|
|
476
|
+
metrics: z13.array(ChargesMetricSchema).min(1).max(METRICS_QUERY_MAX_METRICS),
|
|
477
|
+
filters: z13.array(ChargesFilterSchema).max(METRICS_QUERY_MAX_FILTERS).default([]),
|
|
443
478
|
orderBy: orderBySchema.optional(),
|
|
444
479
|
limit: limitSchema
|
|
445
480
|
});
|
|
446
|
-
var TransactionsQueryFieldSchema =
|
|
481
|
+
var TransactionsQueryFieldSchema = z13.enum(["network", "token", "source", "causedTransition"]).describe(
|
|
447
482
|
"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)."
|
|
448
483
|
);
|
|
449
|
-
var TransactionsMetricFieldSchema =
|
|
450
|
-
var TransactionsDateFieldSchema =
|
|
451
|
-
var TransactionsFilterSchema =
|
|
484
|
+
var TransactionsMetricFieldSchema = z13.enum(["amount"]).describe("The transfer amount, in the charge's `currency` units.");
|
|
485
|
+
var TransactionsDateFieldSchema = z13.enum(["detectedAt"]).describe("When Klappay detected this transfer on-chain (not when it was mined).");
|
|
486
|
+
var TransactionsFilterSchema = z13.object({
|
|
452
487
|
field: TransactionsQueryFieldSchema,
|
|
453
488
|
operator: MetricsFilterOperatorSchema,
|
|
454
489
|
value: MetricsFilterValueSchema
|
|
455
490
|
});
|
|
456
|
-
var TransactionsGroupBySchema =
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
type:
|
|
491
|
+
var TransactionsGroupBySchema = z13.union([
|
|
492
|
+
z13.object({ type: z13.literal("field"), field: TransactionsQueryFieldSchema }),
|
|
493
|
+
z13.object({
|
|
494
|
+
type: z13.literal("date_bucket"),
|
|
460
495
|
field: TransactionsDateFieldSchema,
|
|
461
496
|
granularity: MetricsDateGranularitySchema
|
|
462
497
|
})
|
|
463
498
|
]);
|
|
464
|
-
var TransactionsMetricSchema =
|
|
499
|
+
var TransactionsMetricSchema = z13.object({
|
|
465
500
|
aggregation: MetricsAggregationSchema,
|
|
466
501
|
field: TransactionsMetricFieldSchema.optional(),
|
|
467
502
|
alias: metricAliasSchema
|
|
468
503
|
});
|
|
469
|
-
var TransactionsMetricsQuerySchema =
|
|
470
|
-
resource:
|
|
504
|
+
var TransactionsMetricsQuerySchema = z13.object({
|
|
505
|
+
resource: z13.literal("transactions"),
|
|
471
506
|
environment: metricsQueryEnvironmentSchema,
|
|
472
|
-
dateRange:
|
|
507
|
+
dateRange: z13.object({
|
|
473
508
|
field: TransactionsDateFieldSchema,
|
|
474
|
-
from:
|
|
475
|
-
to:
|
|
509
|
+
from: z13.string().max(64).datetime(),
|
|
510
|
+
to: z13.string().max(64).datetime()
|
|
476
511
|
}),
|
|
477
|
-
groupBy:
|
|
478
|
-
metrics:
|
|
479
|
-
filters:
|
|
512
|
+
groupBy: z13.array(TransactionsGroupBySchema).max(METRICS_QUERY_MAX_GROUP_BY).default([]),
|
|
513
|
+
metrics: z13.array(TransactionsMetricSchema).min(1).max(METRICS_QUERY_MAX_METRICS),
|
|
514
|
+
filters: z13.array(TransactionsFilterSchema).max(METRICS_QUERY_MAX_FILTERS).default([]),
|
|
480
515
|
orderBy: orderBySchema.optional(),
|
|
481
516
|
limit: limitSchema
|
|
482
517
|
});
|
|
483
|
-
var DistributionsQueryFieldSchema =
|
|
518
|
+
var DistributionsQueryFieldSchema = z13.enum(["status", "network", "token", "distributorAddress"]).describe(
|
|
484
519
|
"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."
|
|
485
520
|
);
|
|
486
|
-
var DistributionsMetricFieldSchema =
|
|
521
|
+
var DistributionsMetricFieldSchema = z13.enum(["attempts"]).describe(
|
|
487
522
|
"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."
|
|
488
523
|
);
|
|
489
|
-
var DistributionsDateFieldSchema =
|
|
524
|
+
var DistributionsDateFieldSchema = z13.enum(["createdAt", "processingStartedAt", "completedAt"]).describe(
|
|
490
525
|
"`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."
|
|
491
526
|
);
|
|
492
|
-
var DistributionsFilterSchema =
|
|
527
|
+
var DistributionsFilterSchema = z13.object({
|
|
493
528
|
field: DistributionsQueryFieldSchema,
|
|
494
529
|
operator: MetricsFilterOperatorSchema,
|
|
495
530
|
value: MetricsFilterValueSchema
|
|
496
531
|
});
|
|
497
|
-
var DistributionsGroupBySchema =
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
type:
|
|
532
|
+
var DistributionsGroupBySchema = z13.union([
|
|
533
|
+
z13.object({ type: z13.literal("field"), field: DistributionsQueryFieldSchema }),
|
|
534
|
+
z13.object({
|
|
535
|
+
type: z13.literal("date_bucket"),
|
|
501
536
|
field: DistributionsDateFieldSchema,
|
|
502
537
|
granularity: MetricsDateGranularitySchema
|
|
503
538
|
})
|
|
504
539
|
]);
|
|
505
|
-
var DistributionsMetricSchema =
|
|
540
|
+
var DistributionsMetricSchema = z13.object({
|
|
506
541
|
aggregation: MetricsAggregationSchema,
|
|
507
542
|
field: DistributionsMetricFieldSchema.optional(),
|
|
508
543
|
alias: metricAliasSchema
|
|
509
544
|
});
|
|
510
|
-
var DistributionsMetricsQuerySchema =
|
|
511
|
-
resource:
|
|
545
|
+
var DistributionsMetricsQuerySchema = z13.object({
|
|
546
|
+
resource: z13.literal("distributions"),
|
|
512
547
|
environment: metricsQueryEnvironmentSchema,
|
|
513
|
-
dateRange:
|
|
548
|
+
dateRange: z13.object({
|
|
514
549
|
field: DistributionsDateFieldSchema,
|
|
515
|
-
from:
|
|
516
|
-
to:
|
|
550
|
+
from: z13.string().max(64).datetime(),
|
|
551
|
+
to: z13.string().max(64).datetime()
|
|
517
552
|
}),
|
|
518
|
-
groupBy:
|
|
519
|
-
metrics:
|
|
520
|
-
filters:
|
|
553
|
+
groupBy: z13.array(DistributionsGroupBySchema).max(METRICS_QUERY_MAX_GROUP_BY).default([]),
|
|
554
|
+
metrics: z13.array(DistributionsMetricSchema).min(1).max(METRICS_QUERY_MAX_METRICS),
|
|
555
|
+
filters: z13.array(DistributionsFilterSchema).max(METRICS_QUERY_MAX_FILTERS).default([]),
|
|
521
556
|
orderBy: orderBySchema.optional(),
|
|
522
557
|
limit: limitSchema
|
|
523
558
|
});
|
|
524
559
|
var ONE_DAY_MS = 24 * 60 * 60 * 1e3;
|
|
525
|
-
var MetricsQuerySchema =
|
|
560
|
+
var MetricsQuerySchema = z13.discriminatedUnion("resource", [
|
|
526
561
|
ChargesMetricsQuerySchema,
|
|
527
562
|
TransactionsMetricsQuerySchema,
|
|
528
563
|
DistributionsMetricsQuerySchema
|
|
@@ -531,7 +566,7 @@ var MetricsQuerySchema = z11.discriminatedUnion("resource", [
|
|
|
531
566
|
const to = new Date(input.dateRange.to);
|
|
532
567
|
if (from >= to) {
|
|
533
568
|
ctx.addIssue({
|
|
534
|
-
code:
|
|
569
|
+
code: z13.ZodIssueCode.custom,
|
|
535
570
|
message: "`dateRange.from` must be before `dateRange.to`.",
|
|
536
571
|
path: ["dateRange", "from"]
|
|
537
572
|
});
|
|
@@ -539,7 +574,7 @@ var MetricsQuerySchema = z11.discriminatedUnion("resource", [
|
|
|
539
574
|
const spanDays = (to.getTime() - from.getTime()) / ONE_DAY_MS;
|
|
540
575
|
if (spanDays > MAX_METRICS_QUERY_DATE_RANGE_DAYS) {
|
|
541
576
|
ctx.addIssue({
|
|
542
|
-
code:
|
|
577
|
+
code: z13.ZodIssueCode.custom,
|
|
543
578
|
message: `\`dateRange\` cannot span more than ${MAX_METRICS_QUERY_DATE_RANGE_DAYS} days.`,
|
|
544
579
|
path: ["dateRange", "to"]
|
|
545
580
|
});
|
|
@@ -547,7 +582,7 @@ var MetricsQuerySchema = z11.discriminatedUnion("resource", [
|
|
|
547
582
|
const dateBucketCount = input.groupBy.filter((entry) => entry.type === "date_bucket").length;
|
|
548
583
|
if (dateBucketCount > 1) {
|
|
549
584
|
ctx.addIssue({
|
|
550
|
-
code:
|
|
585
|
+
code: z13.ZodIssueCode.custom,
|
|
551
586
|
message: "At most one `date_bucket` entry is allowed in `groupBy`.",
|
|
552
587
|
path: ["groupBy"]
|
|
553
588
|
});
|
|
@@ -555,7 +590,7 @@ var MetricsQuerySchema = z11.discriminatedUnion("resource", [
|
|
|
555
590
|
input.metrics.forEach((metric, index) => {
|
|
556
591
|
if (metric.aggregation !== "count" && metric.field === void 0) {
|
|
557
592
|
ctx.addIssue({
|
|
558
|
-
code:
|
|
593
|
+
code: z13.ZodIssueCode.custom,
|
|
559
594
|
message: "`field` is required unless `aggregation` is `count`.",
|
|
560
595
|
path: ["metrics", index, "field"]
|
|
561
596
|
});
|
|
@@ -564,7 +599,7 @@ var MetricsQuerySchema = z11.discriminatedUnion("resource", [
|
|
|
564
599
|
const aliases = input.metrics.map((metric) => metric.alias).filter((alias) => alias !== void 0);
|
|
565
600
|
if (new Set(aliases).size !== aliases.length) {
|
|
566
601
|
ctx.addIssue({
|
|
567
|
-
code:
|
|
602
|
+
code: z13.ZodIssueCode.custom,
|
|
568
603
|
message: "Every `metrics[].alias` must be unique.",
|
|
569
604
|
path: ["metrics"]
|
|
570
605
|
});
|
|
@@ -573,32 +608,32 @@ var MetricsQuerySchema = z11.discriminatedUnion("resource", [
|
|
|
573
608
|
input.metrics.forEach((metric, index) => {
|
|
574
609
|
if (metric.alias !== void 0 && reservedNames.has(metric.alias)) {
|
|
575
610
|
ctx.addIssue({
|
|
576
|
-
code:
|
|
611
|
+
code: z13.ZodIssueCode.custom,
|
|
577
612
|
message: `\`alias\` "${metric.alias}" collides with a \`groupBy\` field name (or the reserved word "bucket") \u2014 choose a different alias.`,
|
|
578
613
|
path: ["metrics", index, "alias"]
|
|
579
614
|
});
|
|
580
615
|
}
|
|
581
616
|
});
|
|
582
617
|
});
|
|
583
|
-
var MetricsQueryResultRowSchema =
|
|
584
|
-
|
|
585
|
-
|
|
618
|
+
var MetricsQueryResultRowSchema = z13.record(
|
|
619
|
+
z13.string(),
|
|
620
|
+
z13.union([z13.string(), z13.number(), z13.boolean(), z13.null()])
|
|
586
621
|
);
|
|
587
|
-
var MetricsQueryResultSchema =
|
|
588
|
-
data:
|
|
589
|
-
meta:
|
|
622
|
+
var MetricsQueryResultSchema = z13.object({
|
|
623
|
+
data: z13.array(MetricsQueryResultRowSchema),
|
|
624
|
+
meta: z13.object({
|
|
590
625
|
resource: MetricsResourceSchema,
|
|
591
626
|
environment: EnvironmentSchema,
|
|
592
|
-
rowCount:
|
|
593
|
-
truncated:
|
|
627
|
+
rowCount: z13.number().int().describe("Number of rows in `data`."),
|
|
628
|
+
truncated: z13.boolean().describe(
|
|
594
629
|
"`true` if more rows matched than `limit` allowed \u2014 `data` holds only the first `limit`."
|
|
595
630
|
)
|
|
596
631
|
})
|
|
597
632
|
});
|
|
598
633
|
|
|
599
634
|
// src/webhook-events.ts
|
|
600
|
-
import { z as
|
|
601
|
-
var ChargeWebhookEventTypeSchema =
|
|
635
|
+
import { z as z14 } from "zod";
|
|
636
|
+
var ChargeWebhookEventTypeSchema = z14.enum([
|
|
602
637
|
"charge.created",
|
|
603
638
|
"charge.partially_paid",
|
|
604
639
|
"charge.confirmed",
|
|
@@ -610,14 +645,14 @@ var ChargeWebhookEventTypeSchema = z12.enum([
|
|
|
610
645
|
]).describe(
|
|
611
646
|
'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`). Every event in this category carries the full `Charge` object as `data`.'
|
|
612
647
|
);
|
|
613
|
-
var WebhookDeliveryEventTypeSchema =
|
|
648
|
+
var WebhookDeliveryEventTypeSchema = z14.enum(["webhook.delivery_failed", "webhook.delivery_recovered", "webhook.endpoint_unhealthy"]).describe(
|
|
614
649
|
"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`)."
|
|
615
650
|
);
|
|
616
|
-
var WebhookEventTypeSchema =
|
|
651
|
+
var WebhookEventTypeSchema = z14.union([
|
|
617
652
|
ChargeWebhookEventTypeSchema,
|
|
618
653
|
WebhookDeliveryEventTypeSchema
|
|
619
654
|
]);
|
|
620
|
-
var WebhookCategorySchema =
|
|
655
|
+
var WebhookCategorySchema = z14.enum(["payments", "webhooks"]).describe(
|
|
621
656
|
"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."
|
|
622
657
|
);
|
|
623
658
|
function buildCategoryMap() {
|
|
@@ -645,101 +680,101 @@ var TriggerableChargeEventSchema = ChargeWebhookEventTypeSchema.exclude([
|
|
|
645
680
|
);
|
|
646
681
|
|
|
647
682
|
// src/webhooks.ts
|
|
648
|
-
import { z as
|
|
683
|
+
import { z as z15 } from "zod";
|
|
649
684
|
var WEBHOOK_EVENTS_WILDCARD = "*";
|
|
650
|
-
var CreateWebhookSchema =
|
|
651
|
-
url:
|
|
685
|
+
var CreateWebhookSchema = z15.object({
|
|
686
|
+
url: z15.string().max(2048).url().describe(
|
|
652
687
|
"Must be HTTPS and resolve to a public address \u2014 private/internal IPs are rejected."
|
|
653
688
|
),
|
|
654
|
-
events:
|
|
689
|
+
events: z15.array(z15.union([WebhookEventTypeSchema, z15.literal(WEBHOOK_EVENTS_WILDCARD)])).max(Object.keys(EVENT_CATEGORY_MAP).length + 1).default([]).describe(
|
|
655
690
|
'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.'
|
|
656
691
|
),
|
|
657
|
-
eventCategories:
|
|
692
|
+
eventCategories: z15.array(WebhookCategorySchema).max(WebhookCategorySchema.options.length).default([]).describe(
|
|
658
693
|
"Subscribe to every event in these categories. At least one of `events` or `eventCategories` is required."
|
|
659
694
|
),
|
|
660
|
-
excludeEvents:
|
|
695
|
+
excludeEvents: z15.array(WebhookEventTypeSchema).max(Object.keys(EVENT_CATEGORY_MAP).length).default([]).describe(
|
|
661
696
|
'Event types to exclude even if selected via `events: ["*"]` or `eventCategories`.'
|
|
662
697
|
)
|
|
663
698
|
}).refine((v) => v.events.length > 0 || v.eventCategories.length > 0, {
|
|
664
699
|
message: "must select at least one event via `events` or `eventCategories`",
|
|
665
700
|
path: ["events"]
|
|
666
701
|
});
|
|
667
|
-
var WebhookSchema =
|
|
668
|
-
id:
|
|
702
|
+
var WebhookSchema = z15.object({
|
|
703
|
+
id: z15.string(),
|
|
669
704
|
environment: EnvironmentSchema.nullable().describe(
|
|
670
705
|
"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)."
|
|
671
706
|
),
|
|
672
|
-
url:
|
|
673
|
-
events:
|
|
674
|
-
eventCategories:
|
|
675
|
-
excludeEvents:
|
|
676
|
-
isWildcard:
|
|
677
|
-
secret:
|
|
707
|
+
url: z15.string(),
|
|
708
|
+
events: z15.array(WebhookEventTypeSchema),
|
|
709
|
+
eventCategories: z15.array(WebhookCategorySchema),
|
|
710
|
+
excludeEvents: z15.array(WebhookEventTypeSchema),
|
|
711
|
+
isWildcard: z15.boolean(),
|
|
712
|
+
secret: z15.string().describe(
|
|
678
713
|
"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."
|
|
679
714
|
),
|
|
680
|
-
createdAt:
|
|
715
|
+
createdAt: z15.string().datetime()
|
|
681
716
|
});
|
|
682
717
|
var WebhookListItemSchema = WebhookSchema.omit({ secret: true }).extend({
|
|
683
|
-
hint:
|
|
718
|
+
hint: z15.string().describe("A truncated, safe-to-display form of the secret (e.g. `whsec_...ab12`).")
|
|
684
719
|
});
|
|
685
|
-
var WebhookPayloadSchema =
|
|
686
|
-
id:
|
|
720
|
+
var WebhookPayloadSchema = z15.object({
|
|
721
|
+
id: z15.string().describe(
|
|
687
722
|
"Unique id for this specific delivery \u2014 also sent as the `X-Klappay-Delivery` header."
|
|
688
723
|
),
|
|
689
724
|
event: WebhookEventTypeSchema,
|
|
690
|
-
createdAt:
|
|
691
|
-
data:
|
|
725
|
+
createdAt: z15.string().datetime(),
|
|
726
|
+
data: z15.unknown().describe(
|
|
692
727
|
"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."
|
|
693
728
|
)
|
|
694
729
|
});
|
|
695
|
-
var WebhookDeliveryStatusSchema =
|
|
696
|
-
var WebhookDeliverySchema =
|
|
697
|
-
id:
|
|
698
|
-
webhookId:
|
|
730
|
+
var WebhookDeliveryStatusSchema = z15.enum(["pending", "delivered", "failed"]);
|
|
731
|
+
var WebhookDeliverySchema = z15.object({
|
|
732
|
+
id: z15.string(),
|
|
733
|
+
webhookId: z15.string(),
|
|
699
734
|
event: WebhookEventTypeSchema,
|
|
700
735
|
status: WebhookDeliveryStatusSchema.describe(
|
|
701
736
|
"`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."
|
|
702
737
|
),
|
|
703
|
-
attempts:
|
|
704
|
-
responseCode:
|
|
738
|
+
attempts: z15.number(),
|
|
739
|
+
responseCode: z15.number().nullable().describe(
|
|
705
740
|
"HTTP status your endpoint returned on the most recent attempt. `null` if every attempt failed to connect at all."
|
|
706
741
|
),
|
|
707
|
-
nextRetryAt:
|
|
708
|
-
deliveredAt:
|
|
709
|
-
createdAt:
|
|
742
|
+
nextRetryAt: z15.string().datetime().nullable(),
|
|
743
|
+
deliveredAt: z15.string().datetime().nullable(),
|
|
744
|
+
createdAt: z15.string().datetime()
|
|
710
745
|
});
|
|
711
746
|
var ListWebhookDeliveriesSchema = PaginationQuerySchema;
|
|
712
747
|
var PaginatedWebhookDeliveriesSchema = paginatedSchema(WebhookDeliverySchema);
|
|
713
748
|
|
|
714
749
|
// src/recipients.ts
|
|
715
|
-
import { z as
|
|
750
|
+
import { z as z16 } from "zod";
|
|
716
751
|
var EVM_ADDRESS_REGEX = /^0x[0-9a-fA-F]{40}$/;
|
|
717
|
-
var CreateRecipientSchema =
|
|
718
|
-
address:
|
|
719
|
-
label:
|
|
752
|
+
var CreateRecipientSchema = z16.object({
|
|
753
|
+
address: z16.string().regex(EVM_ADDRESS_REGEX, "must be a 20-byte hex address").describe("EVM address to register as a trusted split recipient for your organization."),
|
|
754
|
+
label: z16.string().min(1).max(64).optional().describe('Free-form label for your own bookkeeping (e.g. `"supplier"`) \u2014 never interpreted.')
|
|
720
755
|
});
|
|
721
|
-
var RecipientSchema =
|
|
722
|
-
id:
|
|
756
|
+
var RecipientSchema = z16.object({
|
|
757
|
+
id: z16.string().describe(
|
|
723
758
|
"Klappay-generated id, e.g. `rc_...` \u2014 this, not the raw address, is what a charge's `splitRecipients[].recipientId` references."
|
|
724
759
|
),
|
|
725
760
|
environment: EnvironmentSchema,
|
|
726
|
-
address:
|
|
727
|
-
label:
|
|
728
|
-
payout:
|
|
761
|
+
address: z16.string(),
|
|
762
|
+
label: z16.string().nullable(),
|
|
763
|
+
payout: z16.boolean().describe(
|
|
729
764
|
"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`."
|
|
730
765
|
),
|
|
731
|
-
createdAt:
|
|
766
|
+
createdAt: z16.string().datetime()
|
|
732
767
|
});
|
|
733
|
-
var SetRecipientPayoutSchema =
|
|
734
|
-
payout:
|
|
768
|
+
var SetRecipientPayoutSchema = z16.object({
|
|
769
|
+
payout: z16.boolean().describe("New payout-eligibility value for this recipient.")
|
|
735
770
|
});
|
|
736
771
|
|
|
737
772
|
// src/timeline.ts
|
|
738
|
-
import { z as
|
|
739
|
-
var TransactionSourceSchema =
|
|
773
|
+
import { z as z17 } from "zod";
|
|
774
|
+
var TransactionSourceSchema = z17.enum(["moralis_webhook", "reconciliation_job", "sandbox"]).describe(
|
|
740
775
|
"How this transfer was detected: `moralis_webhook` (the normal path), `reconciliation_job` (a fallback poller caught it after the webhook was missed or delayed), or `sandbox` (simulated via `POST /v1/sandbox/charges/{id}/trigger`, no real on-chain transfer)."
|
|
741
776
|
);
|
|
742
|
-
var TimelineEventTypeSchema =
|
|
777
|
+
var TimelineEventTypeSchema = z17.enum([
|
|
743
778
|
"charge.created",
|
|
744
779
|
"charge.expired",
|
|
745
780
|
"transaction.detected",
|
|
@@ -750,11 +785,11 @@ var TimelineEventTypeSchema = z15.enum([
|
|
|
750
785
|
]).describe(
|
|
751
786
|
"`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)."
|
|
752
787
|
);
|
|
753
|
-
var TimelineEventSchema =
|
|
788
|
+
var TimelineEventSchema = z17.object({
|
|
754
789
|
type: TimelineEventTypeSchema,
|
|
755
|
-
at:
|
|
756
|
-
txHash:
|
|
757
|
-
amount:
|
|
790
|
+
at: z17.string().datetime(),
|
|
791
|
+
txHash: z17.string().optional().describe("Present for `transaction.detected` and `split.distributed` events only."),
|
|
792
|
+
amount: z17.number().optional().describe(
|
|
758
793
|
"Present for `transaction.detected` events only \u2014 the amount that specific transfer carried."
|
|
759
794
|
),
|
|
760
795
|
source: TransactionSourceSchema.optional().describe(
|
|
@@ -766,102 +801,102 @@ var TimelineEventSchema = z15.object({
|
|
|
766
801
|
network: NetworkSchema.optional().describe(
|
|
767
802
|
"Present for `transaction.detected` and `split.distributed` events \u2014 which network this specific transfer, or settlement, used."
|
|
768
803
|
),
|
|
769
|
-
causedTransition:
|
|
804
|
+
causedTransition: z17.boolean().optional().describe(
|
|
770
805
|
"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."
|
|
771
806
|
),
|
|
772
807
|
event: WebhookEventTypeSchema.optional().describe(
|
|
773
808
|
"Present for `webhook.*` events only \u2014 which event type this delivery was for."
|
|
774
809
|
),
|
|
775
|
-
responseCode:
|
|
810
|
+
responseCode: z17.number().nullable().optional().describe(
|
|
776
811
|
"Present for `webhook.*` events only \u2014 HTTP status your endpoint returned, or `null` if the request never connected."
|
|
777
812
|
),
|
|
778
|
-
attempts:
|
|
813
|
+
attempts: z17.number().optional().describe(
|
|
779
814
|
"Present for `webhook.*` events only \u2014 how many delivery attempts have been made so far."
|
|
780
815
|
)
|
|
781
816
|
});
|
|
782
817
|
|
|
783
818
|
// src/health.ts
|
|
784
|
-
import { z as
|
|
785
|
-
var HealthSchema =
|
|
786
|
-
status:
|
|
819
|
+
import { z as z18 } from "zod";
|
|
820
|
+
var HealthSchema = z18.object({
|
|
821
|
+
status: z18.enum(["ok", "error"]).describe(
|
|
787
822
|
"`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."
|
|
788
823
|
),
|
|
789
|
-
version:
|
|
790
|
-
timestamp:
|
|
791
|
-
db:
|
|
792
|
-
pendingWebhooks:
|
|
793
|
-
oldestPendingChargeAgeSeconds:
|
|
794
|
-
lastMoralisEventAgeSeconds:
|
|
824
|
+
version: z18.string(),
|
|
825
|
+
timestamp: z18.string().datetime(),
|
|
826
|
+
db: z18.enum(["ok", "error"]).describe("Result of a real database connectivity check, not just a process-alive check."),
|
|
827
|
+
pendingWebhooks: z18.number().describe("Count of webhook deliveries still awaiting a successful attempt."),
|
|
828
|
+
oldestPendingChargeAgeSeconds: z18.number().nullable().describe("Age of the oldest still-unpaid charge, in seconds. `null` if there are none."),
|
|
829
|
+
lastMoralisEventAgeSeconds: z18.number().nullable().describe(
|
|
795
830
|
"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."
|
|
796
831
|
)
|
|
797
832
|
});
|
|
798
833
|
|
|
799
834
|
// src/sandbox.ts
|
|
800
|
-
import { z as
|
|
801
|
-
var SandboxTriggerSchema =
|
|
835
|
+
import { z as z19 } from "zod";
|
|
836
|
+
var SandboxTriggerSchema = z19.object({
|
|
802
837
|
event: TriggerableChargeEventSchema,
|
|
803
|
-
amount:
|
|
838
|
+
amount: z19.number().positive().max(CHARGE_AMOUNT_MAX).optional().describe(
|
|
804
839
|
"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."
|
|
805
840
|
)
|
|
806
841
|
});
|
|
807
842
|
|
|
808
843
|
// src/capabilities.ts
|
|
809
|
-
import { z as
|
|
810
|
-
var CapabilitiesSchema =
|
|
811
|
-
acceptedPayments:
|
|
844
|
+
import { z as z20 } from "zod";
|
|
845
|
+
var CapabilitiesSchema = z20.object({
|
|
846
|
+
acceptedPayments: z20.array(AcceptedPaymentSchema).describe(
|
|
812
847
|
"Every `(token, network)` pair actually configured for your environment right now \u2014 read straight from the same lookup `POST /v1/charges` validates `acceptedPayments` against, so it can never list a pair that charge creation would then reject. Use this to build a picker UI instead of hardcoding the matrix client-side."
|
|
813
848
|
)
|
|
814
849
|
});
|
|
815
850
|
|
|
816
851
|
// src/swap.ts
|
|
817
|
-
import { z as
|
|
818
|
-
var CreateSwapQuoteSchema =
|
|
852
|
+
import { z as z21 } from "zod";
|
|
853
|
+
var CreateSwapQuoteSchema = z21.object({
|
|
819
854
|
inputToken: AltTokenSchema.describe(
|
|
820
855
|
"Which alt-cryptocurrency the payer wants to send \u2014 must be one of this charge's `swapAlternatives`, or `422 token_not_supported`."
|
|
821
856
|
),
|
|
822
857
|
inputNetwork: NetworkSchema.describe(
|
|
823
858
|
"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 breaks the tie using its own trust ranking for that network (e.g. USDT over USDC on BNB Chain, where \"USDC\" is a third-party Binance-Peg token, not Circle's) \u2014 never a token the charge doesn't actually accept."
|
|
824
859
|
),
|
|
825
|
-
takerAddress:
|
|
860
|
+
takerAddress: z21.string().regex(/^0x[0-9a-fA-F]{40}$/, "must be a 20-byte hex address").describe(
|
|
826
861
|
"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."
|
|
827
862
|
)
|
|
828
863
|
});
|
|
829
|
-
var SwapQuoteSchema =
|
|
864
|
+
var SwapQuoteSchema = z21.object({
|
|
830
865
|
inputToken: AltTokenSchema,
|
|
831
866
|
inputNetwork: NetworkSchema,
|
|
832
|
-
inputAmount:
|
|
867
|
+
inputAmount: z21.number().describe(
|
|
833
868
|
"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."
|
|
834
869
|
),
|
|
835
870
|
outputToken: TokenSchema.describe(
|
|
836
871
|
"Which of this charge's `acceptedPayments` tokens the swap resolves to."
|
|
837
872
|
),
|
|
838
873
|
outputNetwork: NetworkSchema,
|
|
839
|
-
outputAmount:
|
|
874
|
+
outputAmount: z21.number().describe(
|
|
840
875
|
"The exact remaining amount owed on this charge (`amount - amountReceived`), in `currency` units \u2014 always what the merchant's split address receives, regardless of `inputAmount`."
|
|
841
876
|
),
|
|
842
|
-
fees:
|
|
843
|
-
klappayFee:
|
|
877
|
+
fees: z21.object({
|
|
878
|
+
klappayFee: z21.number().describe(
|
|
844
879
|
"Klappay's own swap fee (1% today), in `outputToken` units \u2014 paid by the payer, on top of `inputAmount`, separate from the merchant's own `feePercent`. Never subtracted from `outputAmount`."
|
|
845
880
|
),
|
|
846
|
-
zeroExFee:
|
|
881
|
+
zeroExFee: z21.number().nullable().describe(
|
|
847
882
|
"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. Also paid by the payer on top of `inputAmount`, also never subtracted from `outputAmount` \u2014 Klappay never sees this fee, it goes straight to 0x."
|
|
848
883
|
)
|
|
849
884
|
}).describe(
|
|
850
885
|
"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`."
|
|
851
886
|
),
|
|
852
|
-
expiresAt:
|
|
887
|
+
expiresAt: z21.string().datetime().describe(
|
|
853
888
|
"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."
|
|
854
889
|
),
|
|
855
|
-
transaction:
|
|
856
|
-
to:
|
|
857
|
-
data:
|
|
858
|
-
value:
|
|
890
|
+
transaction: z21.object({
|
|
891
|
+
to: z21.string().describe("Contract address the payer's wallet must send this transaction to."),
|
|
892
|
+
data: z21.string().describe("Calldata \u2014 opaque, must be sent unmodified."),
|
|
893
|
+
value: z21.string().describe(
|
|
859
894
|
"Native currency (ETH/BNB/MATIC/AVAX) to attach, in wei \u2014 `\"0\"` when `inputToken` isn't this network's native currency."
|
|
860
895
|
)
|
|
861
896
|
}).describe(
|
|
862
897
|
"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."
|
|
863
898
|
),
|
|
864
|
-
permit2:
|
|
899
|
+
permit2: z21.object({ eip712: z21.record(z21.unknown()) }).nullish().describe(
|
|
865
900
|
"Present only when `inputToken` is an ERC-20 (today, only `BTC`) \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/MATIC/AVAX) \u2014 `transaction` is then ready to sign and send directly, no extra step."
|
|
866
901
|
)
|
|
867
902
|
});
|
|
@@ -887,6 +922,7 @@ export {
|
|
|
887
922
|
ChargesDateFieldSchema,
|
|
888
923
|
ChargesMetricFieldSchema,
|
|
889
924
|
ChargesQueryFieldSchema,
|
|
925
|
+
CheckChargeRequestSchema,
|
|
890
926
|
CheckoutProductSchema,
|
|
891
927
|
CreateChargeSchema,
|
|
892
928
|
CreateRecipientSchema,
|
|
@@ -899,6 +935,7 @@ export {
|
|
|
899
935
|
EVM_NETWORKS,
|
|
900
936
|
EnvironmentSchema,
|
|
901
937
|
ErrorPayloadSchema,
|
|
938
|
+
EscrowConfigSchema,
|
|
902
939
|
GetChargeQrCodeQuerySchema,
|
|
903
940
|
HealthSchema,
|
|
904
941
|
KlappayCheckoutMetadataSchema,
|
|
@@ -934,6 +971,7 @@ export {
|
|
|
934
971
|
PendingDistributionRecipientSchema,
|
|
935
972
|
PendingDistributionSchema,
|
|
936
973
|
RecipientSchema,
|
|
974
|
+
ReleaseEscrowRequestSchema,
|
|
937
975
|
SandboxTriggerSchema,
|
|
938
976
|
SetRecipientPayoutSchema,
|
|
939
977
|
SettlementStatusSchema,
|