@klappay/types 3.7.0 → 4.0.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/dist/index.d.mts +113 -18
- package/dist/index.d.ts +113 -18
- package/dist/index.js +238 -195
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +236 -195
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -164,6 +164,9 @@ var ChargeStatusSchema = z10.enum(["pending", "partially_paid", "confirmed", "ex
|
|
|
164
164
|
var SettlementStatusSchema = z10.enum(["pending", "completed", "failed"]).describe(
|
|
165
165
|
"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."
|
|
166
166
|
);
|
|
167
|
+
var ChargeFeePayerSchema = z10.enum(["merchant", "payer"]).describe(
|
|
168
|
+
"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."
|
|
169
|
+
);
|
|
167
170
|
var CHARGE_EXPIRES_IN_MIN_SECONDS = 60;
|
|
168
171
|
var CHARGE_EXPIRES_IN_MAX_SECONDS = 3600;
|
|
169
172
|
var CHARGE_ACCEPTED_PAYMENTS_MAX = 14;
|
|
@@ -233,8 +236,9 @@ var SplitRecipientsInputSchema = z10.array(SplitRecipientInputSchema).max(CHARGE
|
|
|
233
236
|
var CHARGE_AMOUNT_MAX = 999999999999;
|
|
234
237
|
var CreateChargeSchema = z10.object({
|
|
235
238
|
amount: z10.number().positive().max(CHARGE_AMOUNT_MAX).describe(
|
|
236
|
-
"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."
|
|
239
|
+
"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."
|
|
237
240
|
),
|
|
241
|
+
feePayer: ChargeFeePayerSchema.optional().default("merchant"),
|
|
238
242
|
currency: z10.literal("USD").default("USD").describe("Always `USD` today \u2014 the only supported currency."),
|
|
239
243
|
acceptedPayments: AcceptedPaymentsSchema,
|
|
240
244
|
expiresIn: z10.number().int().min(CHARGE_EXPIRES_IN_MIN_SECONDS).max(CHARGE_EXPIRES_IN_MAX_SECONDS).describe(
|
|
@@ -260,7 +264,17 @@ var CreateChargeSchema = z10.object({
|
|
|
260
264
|
});
|
|
261
265
|
var ChargeSchema = z10.object({
|
|
262
266
|
id: z10.string().describe("Klappay-generated id, e.g. `ch_...`. Use this to look up the charge later."),
|
|
263
|
-
amount: z10.number().describe(
|
|
267
|
+
amount: z10.number().describe(
|
|
268
|
+
"The exact total the payer must send, in `currency` units (up to 6 decimal places). With `feePayer: 'merchant'` (the default) this is exactly 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."
|
|
269
|
+
),
|
|
270
|
+
feePayer: ChargeFeePayerSchema,
|
|
271
|
+
feePercent: z10.number().describe(
|
|
272
|
+
"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."
|
|
273
|
+
),
|
|
274
|
+
feeAmount: z10.number().describe("`amount * feePercent / 100`, in `currency` units \u2014 Klappay's cut of this charge."),
|
|
275
|
+
merchantAmount: z10.number().describe(
|
|
276
|
+
"`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)."
|
|
277
|
+
),
|
|
264
278
|
amountReceived: z10.number().nullable().describe(
|
|
265
279
|
"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`."
|
|
266
280
|
),
|
|
@@ -341,9 +355,28 @@ var GetChargeQrCodeQuerySchema = z10.object({
|
|
|
341
355
|
});
|
|
342
356
|
|
|
343
357
|
// src/charge-check.ts
|
|
358
|
+
import { z as z12 } from "zod";
|
|
359
|
+
|
|
360
|
+
// src/confirmation-progress.ts
|
|
344
361
|
import { z as z11 } from "zod";
|
|
345
|
-
var
|
|
346
|
-
|
|
362
|
+
var ConfirmationProgressSchema = z11.object({
|
|
363
|
+
network: NetworkSchema.describe("Which network the transfer was seen on."),
|
|
364
|
+
blocksSeen: z11.number().int().min(0).describe(
|
|
365
|
+
"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."
|
|
366
|
+
),
|
|
367
|
+
blocksRequired: z11.number().int().min(1).describe(
|
|
368
|
+
"This network's minimum confirmation depth (a fixed, per-network constant) \u2014 the transfer is only credited once `blocksSeen` reaches this value."
|
|
369
|
+
),
|
|
370
|
+
percent: z11.number().int().min(0).max(99).describe(
|
|
371
|
+
'`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).'
|
|
372
|
+
)
|
|
373
|
+
}).describe(
|
|
374
|
+
"How close an already-detected transfer is to being trusted as final and credited, before its network's minimum confirmation depth is reached (see `docs/payments.md`'s \"Confirmation depth\" section). Only ever present for a transfer that's been seen on-chain but isn't deep enough yet \u2014 absent/null once it's credited (the charge's own status change is what signals that) or if nothing has been detected at all."
|
|
375
|
+
);
|
|
376
|
+
|
|
377
|
+
// src/charge-check.ts
|
|
378
|
+
var CheckChargeRequestSchema = z12.object({
|
|
379
|
+
txHash: z12.string().regex(/^0x[0-9a-fA-F]{64}$/, "must be a 32-byte transaction hash").optional().describe(
|
|
347
380
|
"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."
|
|
348
381
|
),
|
|
349
382
|
network: NetworkSchema.optional().describe(
|
|
@@ -353,67 +386,70 @@ var CheckChargeRequestSchema = z11.object({
|
|
|
353
386
|
message: "`txHash` and `network` must be provided together, or both omitted"
|
|
354
387
|
});
|
|
355
388
|
var CheckChargeResponseSchema = ChargeSchema.extend({
|
|
356
|
-
transactionSender:
|
|
389
|
+
transactionSender: z12.string().nullable().describe(
|
|
357
390
|
"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`."
|
|
391
|
+
),
|
|
392
|
+
confirmationProgress: ConfirmationProgressSchema.nullable().describe(
|
|
393
|
+
"Present when this check found a real matching transfer on-chain that has not yet reached its network's required confirmation depth \u2014 use it to render a progress bar while waiting. `null` when nothing new was found, when the charge is already terminal (this check short-circuits with no RPC call), or once the transfer is deep enough to have already been credited (the charge's own `status` field is the signal for that, not this one)."
|
|
358
394
|
)
|
|
359
395
|
});
|
|
360
396
|
|
|
361
397
|
// src/distributions.ts
|
|
362
|
-
import { z as
|
|
363
|
-
var SplitDistributionStatusSchema =
|
|
398
|
+
import { z as z13 } from "zod";
|
|
399
|
+
var SplitDistributionStatusSchema = z13.enum(["pending", "processing", "completed", "failed"]).describe(
|
|
364
400
|
"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."
|
|
365
401
|
);
|
|
366
|
-
var PendingDistributionRecipientSchema =
|
|
367
|
-
address:
|
|
368
|
-
percentAllocation:
|
|
402
|
+
var PendingDistributionRecipientSchema = z13.object({
|
|
403
|
+
address: z13.string().describe("On-chain recipient address."),
|
|
404
|
+
percentAllocation: z13.number().describe("This recipient's share of the split, as a percentage (e.g. `99.0991` = 99.0991%).")
|
|
369
405
|
});
|
|
370
|
-
var PendingDistributionSchema =
|
|
371
|
-
splitAddress:
|
|
406
|
+
var PendingDistributionSchema = z13.object({
|
|
407
|
+
splitAddress: z13.string().describe("The on-chain 0xSplits address to call `distribute()` on."),
|
|
372
408
|
network: NetworkSchema,
|
|
373
409
|
token: TokenSchema,
|
|
374
|
-
recipients:
|
|
410
|
+
recipients: z13.array(PendingDistributionRecipientSchema).describe(
|
|
375
411
|
"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."
|
|
376
412
|
),
|
|
377
|
-
distributorFeePercent:
|
|
413
|
+
distributorFeePercent: z13.number().describe(
|
|
378
414
|
"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."
|
|
379
415
|
),
|
|
380
|
-
estimatedRewardAmount:
|
|
416
|
+
estimatedRewardAmount: z13.number().describe(
|
|
381
417
|
"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."
|
|
382
418
|
),
|
|
383
|
-
availableSince:
|
|
384
|
-
graceEndsAt:
|
|
419
|
+
availableSince: z13.string().datetime().describe("When this distribution entered its grace period."),
|
|
420
|
+
graceEndsAt: z13.string().datetime().describe(
|
|
385
421
|
"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."
|
|
386
422
|
)
|
|
387
423
|
});
|
|
388
424
|
var PaginatedPendingDistributionsSchema = paginatedSchema(PendingDistributionSchema);
|
|
389
|
-
var ListenPendingDistributionsQuerySchema =
|
|
390
|
-
limit:
|
|
425
|
+
var ListenPendingDistributionsQuerySchema = z13.object({
|
|
426
|
+
limit: z13.coerce.number().int().min(0).max(PAGINATION_LIMIT_MAX).default(0).describe(
|
|
391
427
|
"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."
|
|
392
428
|
)
|
|
393
429
|
});
|
|
394
|
-
var PendingDistributionEventSchema =
|
|
395
|
-
|
|
396
|
-
type:
|
|
430
|
+
var PendingDistributionEventSchema = z13.discriminatedUnion("type", [
|
|
431
|
+
z13.object({
|
|
432
|
+
type: z13.literal("distribution.available"),
|
|
397
433
|
distribution: PendingDistributionSchema
|
|
398
434
|
}),
|
|
399
|
-
|
|
400
|
-
type:
|
|
401
|
-
splitAddress:
|
|
435
|
+
z13.object({
|
|
436
|
+
type: z13.literal("distribution.claimed"),
|
|
437
|
+
splitAddress: z13.string().describe("No longer claimable \u2014 either settled by someone, or picked up by the worker.")
|
|
402
438
|
})
|
|
403
439
|
]);
|
|
404
440
|
|
|
405
441
|
// src/metrics.ts
|
|
406
|
-
import { z as
|
|
407
|
-
var MetricsResourceSchema =
|
|
442
|
+
import { z as z14 } from "zod";
|
|
443
|
+
var MetricsResourceSchema = z14.enum(["charges", "transactions", "distributions"]).describe(
|
|
408
444
|
"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."
|
|
409
445
|
);
|
|
410
|
-
var MetricsAggregationSchema =
|
|
446
|
+
var MetricsAggregationSchema = z14.enum(["count", "sum", "avg", "min", "max"]).describe(
|
|
411
447
|
"`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."
|
|
412
448
|
);
|
|
413
|
-
var MetricsFilterOperatorSchema =
|
|
449
|
+
var MetricsFilterOperatorSchema = z14.enum(["eq", "neq", "in", "gt", "gte", "lt", "lte"]).describe(
|
|
414
450
|
"`in` expects an array value (max 50 entries); every other operator expects a single scalar."
|
|
415
451
|
);
|
|
416
|
-
var MetricsDateGranularitySchema =
|
|
452
|
+
var MetricsDateGranularitySchema = z14.enum(["day", "week", "month", "year"]).describe(
|
|
417
453
|
"Bucket width for a `date_bucket` `groupBy` entry \u2014 Postgres `date_trunc` semantics (UTC)."
|
|
418
454
|
);
|
|
419
455
|
var metricsQueryEnvironmentSchema = EnvironmentSchema.describe(
|
|
@@ -426,31 +462,31 @@ var METRICS_QUERY_MAX_GROUP_BY = 3;
|
|
|
426
462
|
var METRICS_QUERY_MAX_FILTERS = 20;
|
|
427
463
|
var METRICS_QUERY_MAX_METRICS = 10;
|
|
428
464
|
var METRIC_ALIAS_PATTERN = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
|
|
429
|
-
var metricAliasSchema =
|
|
465
|
+
var metricAliasSchema = z14.string().min(1).max(64).regex(
|
|
430
466
|
METRIC_ALIAS_PATTERN,
|
|
431
467
|
"Must start with a letter or underscore, and contain only letters, digits, and underscores \u2014 this becomes a SQL column alias."
|
|
432
468
|
).optional();
|
|
433
|
-
var MetricsFilterValueSchema =
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
469
|
+
var MetricsFilterValueSchema = z14.union([
|
|
470
|
+
z14.string().max(255),
|
|
471
|
+
z14.number(),
|
|
472
|
+
z14.boolean(),
|
|
473
|
+
z14.array(z14.union([z14.string().max(255), z14.number()])).min(1).max(50)
|
|
438
474
|
]);
|
|
439
|
-
var orderBySchema =
|
|
440
|
-
key:
|
|
475
|
+
var orderBySchema = z14.object({
|
|
476
|
+
key: z14.string().min(1).max(64).regex(
|
|
441
477
|
METRIC_ALIAS_PATTERN,
|
|
442
478
|
"Must start with a letter or underscore, and contain only letters, digits, and underscores \u2014 every valid output column name already looks like this."
|
|
443
479
|
).describe(
|
|
444
480
|
"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."
|
|
445
481
|
),
|
|
446
|
-
direction:
|
|
482
|
+
direction: z14.enum(["asc", "desc"])
|
|
447
483
|
}).describe(
|
|
448
484
|
"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."
|
|
449
485
|
);
|
|
450
|
-
var limitSchema =
|
|
486
|
+
var limitSchema = z14.number().int().min(1).max(METRICS_QUERY_MAX_ROW_LIMIT).default(METRICS_QUERY_DEFAULT_ROW_LIMIT).describe(
|
|
451
487
|
`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.`
|
|
452
488
|
);
|
|
453
|
-
var ChargesQueryFieldSchema =
|
|
489
|
+
var ChargesQueryFieldSchema = z14.enum([
|
|
454
490
|
"status",
|
|
455
491
|
"source",
|
|
456
492
|
"apiKeyId",
|
|
@@ -461,124 +497,124 @@ var ChargesQueryFieldSchema = z13.enum([
|
|
|
461
497
|
]).describe(
|
|
462
498
|
"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)."
|
|
463
499
|
);
|
|
464
|
-
var ChargesMetricFieldSchema =
|
|
500
|
+
var ChargesMetricFieldSchema = z14.enum(["amount", "amountReceived", "feePercent", "escrowFeePercent"]).describe(
|
|
465
501
|
"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`."
|
|
466
502
|
);
|
|
467
|
-
var ChargesDateFieldSchema =
|
|
503
|
+
var ChargesDateFieldSchema = z14.enum(["createdAt", "confirmedAt", "lastActivityAt", "expiresAt", "escrowReleasedAt"]).describe(
|
|
468
504
|
"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."
|
|
469
505
|
);
|
|
470
|
-
var ChargesFilterSchema =
|
|
506
|
+
var ChargesFilterSchema = z14.object({
|
|
471
507
|
field: ChargesQueryFieldSchema,
|
|
472
508
|
operator: MetricsFilterOperatorSchema,
|
|
473
509
|
value: MetricsFilterValueSchema
|
|
474
510
|
});
|
|
475
|
-
var ChargesGroupBySchema =
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
type:
|
|
511
|
+
var ChargesGroupBySchema = z14.union([
|
|
512
|
+
z14.object({ type: z14.literal("field"), field: ChargesQueryFieldSchema }),
|
|
513
|
+
z14.object({
|
|
514
|
+
type: z14.literal("date_bucket"),
|
|
479
515
|
field: ChargesDateFieldSchema,
|
|
480
516
|
granularity: MetricsDateGranularitySchema
|
|
481
517
|
})
|
|
482
518
|
]);
|
|
483
|
-
var ChargesMetricSchema =
|
|
519
|
+
var ChargesMetricSchema = z14.object({
|
|
484
520
|
aggregation: MetricsAggregationSchema,
|
|
485
521
|
field: ChargesMetricFieldSchema.optional(),
|
|
486
522
|
alias: metricAliasSchema
|
|
487
523
|
});
|
|
488
|
-
var ChargesMetricsQuerySchema =
|
|
489
|
-
resource:
|
|
524
|
+
var ChargesMetricsQuerySchema = z14.object({
|
|
525
|
+
resource: z14.literal("charges"),
|
|
490
526
|
environment: metricsQueryEnvironmentSchema,
|
|
491
|
-
dateRange:
|
|
527
|
+
dateRange: z14.object({
|
|
492
528
|
field: ChargesDateFieldSchema,
|
|
493
|
-
from:
|
|
494
|
-
to:
|
|
529
|
+
from: z14.string().max(64).datetime(),
|
|
530
|
+
to: z14.string().max(64).datetime()
|
|
495
531
|
}),
|
|
496
|
-
groupBy:
|
|
497
|
-
metrics:
|
|
498
|
-
filters:
|
|
532
|
+
groupBy: z14.array(ChargesGroupBySchema).max(METRICS_QUERY_MAX_GROUP_BY).default([]),
|
|
533
|
+
metrics: z14.array(ChargesMetricSchema).min(1).max(METRICS_QUERY_MAX_METRICS),
|
|
534
|
+
filters: z14.array(ChargesFilterSchema).max(METRICS_QUERY_MAX_FILTERS).default([]),
|
|
499
535
|
orderBy: orderBySchema.optional(),
|
|
500
536
|
limit: limitSchema
|
|
501
537
|
});
|
|
502
|
-
var TransactionsQueryFieldSchema =
|
|
538
|
+
var TransactionsQueryFieldSchema = z14.enum(["network", "token", "source", "causedTransition"]).describe(
|
|
503
539
|
"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)."
|
|
504
540
|
);
|
|
505
|
-
var TransactionsMetricFieldSchema =
|
|
506
|
-
var TransactionsDateFieldSchema =
|
|
507
|
-
var TransactionsFilterSchema =
|
|
541
|
+
var TransactionsMetricFieldSchema = z14.enum(["amount"]).describe("The transfer amount, in the charge's `currency` units.");
|
|
542
|
+
var TransactionsDateFieldSchema = z14.enum(["detectedAt"]).describe("When Klappay detected this transfer on-chain (not when it was mined).");
|
|
543
|
+
var TransactionsFilterSchema = z14.object({
|
|
508
544
|
field: TransactionsQueryFieldSchema,
|
|
509
545
|
operator: MetricsFilterOperatorSchema,
|
|
510
546
|
value: MetricsFilterValueSchema
|
|
511
547
|
});
|
|
512
|
-
var TransactionsGroupBySchema =
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
type:
|
|
548
|
+
var TransactionsGroupBySchema = z14.union([
|
|
549
|
+
z14.object({ type: z14.literal("field"), field: TransactionsQueryFieldSchema }),
|
|
550
|
+
z14.object({
|
|
551
|
+
type: z14.literal("date_bucket"),
|
|
516
552
|
field: TransactionsDateFieldSchema,
|
|
517
553
|
granularity: MetricsDateGranularitySchema
|
|
518
554
|
})
|
|
519
555
|
]);
|
|
520
|
-
var TransactionsMetricSchema =
|
|
556
|
+
var TransactionsMetricSchema = z14.object({
|
|
521
557
|
aggregation: MetricsAggregationSchema,
|
|
522
558
|
field: TransactionsMetricFieldSchema.optional(),
|
|
523
559
|
alias: metricAliasSchema
|
|
524
560
|
});
|
|
525
|
-
var TransactionsMetricsQuerySchema =
|
|
526
|
-
resource:
|
|
561
|
+
var TransactionsMetricsQuerySchema = z14.object({
|
|
562
|
+
resource: z14.literal("transactions"),
|
|
527
563
|
environment: metricsQueryEnvironmentSchema,
|
|
528
|
-
dateRange:
|
|
564
|
+
dateRange: z14.object({
|
|
529
565
|
field: TransactionsDateFieldSchema,
|
|
530
|
-
from:
|
|
531
|
-
to:
|
|
566
|
+
from: z14.string().max(64).datetime(),
|
|
567
|
+
to: z14.string().max(64).datetime()
|
|
532
568
|
}),
|
|
533
|
-
groupBy:
|
|
534
|
-
metrics:
|
|
535
|
-
filters:
|
|
569
|
+
groupBy: z14.array(TransactionsGroupBySchema).max(METRICS_QUERY_MAX_GROUP_BY).default([]),
|
|
570
|
+
metrics: z14.array(TransactionsMetricSchema).min(1).max(METRICS_QUERY_MAX_METRICS),
|
|
571
|
+
filters: z14.array(TransactionsFilterSchema).max(METRICS_QUERY_MAX_FILTERS).default([]),
|
|
536
572
|
orderBy: orderBySchema.optional(),
|
|
537
573
|
limit: limitSchema
|
|
538
574
|
});
|
|
539
|
-
var DistributionsQueryFieldSchema =
|
|
575
|
+
var DistributionsQueryFieldSchema = z14.enum(["status", "network", "token", "distributorAddress"]).describe(
|
|
540
576
|
"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."
|
|
541
577
|
);
|
|
542
|
-
var DistributionsMetricFieldSchema =
|
|
578
|
+
var DistributionsMetricFieldSchema = z14.enum(["attempts"]).describe(
|
|
543
579
|
"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."
|
|
544
580
|
);
|
|
545
|
-
var DistributionsDateFieldSchema =
|
|
581
|
+
var DistributionsDateFieldSchema = z14.enum(["createdAt", "processingStartedAt", "completedAt"]).describe(
|
|
546
582
|
"`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."
|
|
547
583
|
);
|
|
548
|
-
var DistributionsFilterSchema =
|
|
584
|
+
var DistributionsFilterSchema = z14.object({
|
|
549
585
|
field: DistributionsQueryFieldSchema,
|
|
550
586
|
operator: MetricsFilterOperatorSchema,
|
|
551
587
|
value: MetricsFilterValueSchema
|
|
552
588
|
});
|
|
553
|
-
var DistributionsGroupBySchema =
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
type:
|
|
589
|
+
var DistributionsGroupBySchema = z14.union([
|
|
590
|
+
z14.object({ type: z14.literal("field"), field: DistributionsQueryFieldSchema }),
|
|
591
|
+
z14.object({
|
|
592
|
+
type: z14.literal("date_bucket"),
|
|
557
593
|
field: DistributionsDateFieldSchema,
|
|
558
594
|
granularity: MetricsDateGranularitySchema
|
|
559
595
|
})
|
|
560
596
|
]);
|
|
561
|
-
var DistributionsMetricSchema =
|
|
597
|
+
var DistributionsMetricSchema = z14.object({
|
|
562
598
|
aggregation: MetricsAggregationSchema,
|
|
563
599
|
field: DistributionsMetricFieldSchema.optional(),
|
|
564
600
|
alias: metricAliasSchema
|
|
565
601
|
});
|
|
566
|
-
var DistributionsMetricsQuerySchema =
|
|
567
|
-
resource:
|
|
602
|
+
var DistributionsMetricsQuerySchema = z14.object({
|
|
603
|
+
resource: z14.literal("distributions"),
|
|
568
604
|
environment: metricsQueryEnvironmentSchema,
|
|
569
|
-
dateRange:
|
|
605
|
+
dateRange: z14.object({
|
|
570
606
|
field: DistributionsDateFieldSchema,
|
|
571
|
-
from:
|
|
572
|
-
to:
|
|
607
|
+
from: z14.string().max(64).datetime(),
|
|
608
|
+
to: z14.string().max(64).datetime()
|
|
573
609
|
}),
|
|
574
|
-
groupBy:
|
|
575
|
-
metrics:
|
|
576
|
-
filters:
|
|
610
|
+
groupBy: z14.array(DistributionsGroupBySchema).max(METRICS_QUERY_MAX_GROUP_BY).default([]),
|
|
611
|
+
metrics: z14.array(DistributionsMetricSchema).min(1).max(METRICS_QUERY_MAX_METRICS),
|
|
612
|
+
filters: z14.array(DistributionsFilterSchema).max(METRICS_QUERY_MAX_FILTERS).default([]),
|
|
577
613
|
orderBy: orderBySchema.optional(),
|
|
578
614
|
limit: limitSchema
|
|
579
615
|
});
|
|
580
616
|
var ONE_DAY_MS = 24 * 60 * 60 * 1e3;
|
|
581
|
-
var MetricsQuerySchema =
|
|
617
|
+
var MetricsQuerySchema = z14.discriminatedUnion("resource", [
|
|
582
618
|
ChargesMetricsQuerySchema,
|
|
583
619
|
TransactionsMetricsQuerySchema,
|
|
584
620
|
DistributionsMetricsQuerySchema
|
|
@@ -587,7 +623,7 @@ var MetricsQuerySchema = z13.discriminatedUnion("resource", [
|
|
|
587
623
|
const to = new Date(input.dateRange.to);
|
|
588
624
|
if (from >= to) {
|
|
589
625
|
ctx.addIssue({
|
|
590
|
-
code:
|
|
626
|
+
code: z14.ZodIssueCode.custom,
|
|
591
627
|
message: "`dateRange.from` must be before `dateRange.to`.",
|
|
592
628
|
path: ["dateRange", "from"]
|
|
593
629
|
});
|
|
@@ -595,7 +631,7 @@ var MetricsQuerySchema = z13.discriminatedUnion("resource", [
|
|
|
595
631
|
const spanDays = (to.getTime() - from.getTime()) / ONE_DAY_MS;
|
|
596
632
|
if (spanDays > MAX_METRICS_QUERY_DATE_RANGE_DAYS) {
|
|
597
633
|
ctx.addIssue({
|
|
598
|
-
code:
|
|
634
|
+
code: z14.ZodIssueCode.custom,
|
|
599
635
|
message: `\`dateRange\` cannot span more than ${MAX_METRICS_QUERY_DATE_RANGE_DAYS} days.`,
|
|
600
636
|
path: ["dateRange", "to"]
|
|
601
637
|
});
|
|
@@ -603,7 +639,7 @@ var MetricsQuerySchema = z13.discriminatedUnion("resource", [
|
|
|
603
639
|
const dateBucketCount = input.groupBy.filter((entry) => entry.type === "date_bucket").length;
|
|
604
640
|
if (dateBucketCount > 1) {
|
|
605
641
|
ctx.addIssue({
|
|
606
|
-
code:
|
|
642
|
+
code: z14.ZodIssueCode.custom,
|
|
607
643
|
message: "At most one `date_bucket` entry is allowed in `groupBy`.",
|
|
608
644
|
path: ["groupBy"]
|
|
609
645
|
});
|
|
@@ -611,7 +647,7 @@ var MetricsQuerySchema = z13.discriminatedUnion("resource", [
|
|
|
611
647
|
input.metrics.forEach((metric, index) => {
|
|
612
648
|
if (metric.aggregation !== "count" && metric.field === void 0) {
|
|
613
649
|
ctx.addIssue({
|
|
614
|
-
code:
|
|
650
|
+
code: z14.ZodIssueCode.custom,
|
|
615
651
|
message: "`field` is required unless `aggregation` is `count`.",
|
|
616
652
|
path: ["metrics", index, "field"]
|
|
617
653
|
});
|
|
@@ -620,7 +656,7 @@ var MetricsQuerySchema = z13.discriminatedUnion("resource", [
|
|
|
620
656
|
const aliases = input.metrics.map((metric) => metric.alias).filter((alias) => alias !== void 0);
|
|
621
657
|
if (new Set(aliases).size !== aliases.length) {
|
|
622
658
|
ctx.addIssue({
|
|
623
|
-
code:
|
|
659
|
+
code: z14.ZodIssueCode.custom,
|
|
624
660
|
message: "Every `metrics[].alias` must be unique.",
|
|
625
661
|
path: ["metrics"]
|
|
626
662
|
});
|
|
@@ -629,32 +665,32 @@ var MetricsQuerySchema = z13.discriminatedUnion("resource", [
|
|
|
629
665
|
input.metrics.forEach((metric, index) => {
|
|
630
666
|
if (metric.alias !== void 0 && reservedNames.has(metric.alias)) {
|
|
631
667
|
ctx.addIssue({
|
|
632
|
-
code:
|
|
668
|
+
code: z14.ZodIssueCode.custom,
|
|
633
669
|
message: `\`alias\` "${metric.alias}" collides with a \`groupBy\` field name (or the reserved word "bucket") \u2014 choose a different alias.`,
|
|
634
670
|
path: ["metrics", index, "alias"]
|
|
635
671
|
});
|
|
636
672
|
}
|
|
637
673
|
});
|
|
638
674
|
});
|
|
639
|
-
var MetricsQueryResultRowSchema =
|
|
640
|
-
|
|
641
|
-
|
|
675
|
+
var MetricsQueryResultRowSchema = z14.record(
|
|
676
|
+
z14.string(),
|
|
677
|
+
z14.union([z14.string(), z14.number(), z14.boolean(), z14.null()])
|
|
642
678
|
);
|
|
643
|
-
var MetricsQueryResultSchema =
|
|
644
|
-
data:
|
|
645
|
-
meta:
|
|
679
|
+
var MetricsQueryResultSchema = z14.object({
|
|
680
|
+
data: z14.array(MetricsQueryResultRowSchema),
|
|
681
|
+
meta: z14.object({
|
|
646
682
|
resource: MetricsResourceSchema,
|
|
647
683
|
environment: EnvironmentSchema,
|
|
648
|
-
rowCount:
|
|
649
|
-
truncated:
|
|
684
|
+
rowCount: z14.number().int().describe("Number of rows in `data`."),
|
|
685
|
+
truncated: z14.boolean().describe(
|
|
650
686
|
"`true` if more rows matched than `limit` allowed \u2014 `data` holds only the first `limit`."
|
|
651
687
|
)
|
|
652
688
|
})
|
|
653
689
|
});
|
|
654
690
|
|
|
655
691
|
// src/webhook-events.ts
|
|
656
|
-
import { z as
|
|
657
|
-
var ChargeWebhookEventTypeSchema =
|
|
692
|
+
import { z as z15 } from "zod";
|
|
693
|
+
var ChargeWebhookEventTypeSchema = z15.enum([
|
|
658
694
|
"charge.created",
|
|
659
695
|
"charge.partially_paid",
|
|
660
696
|
"charge.confirmed",
|
|
@@ -668,14 +704,14 @@ var ChargeWebhookEventTypeSchema = z14.enum([
|
|
|
668
704
|
]).describe(
|
|
669
705
|
'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`.'
|
|
670
706
|
);
|
|
671
|
-
var WebhookDeliveryEventTypeSchema =
|
|
707
|
+
var WebhookDeliveryEventTypeSchema = z15.enum(["webhook.delivery_failed", "webhook.delivery_recovered", "webhook.endpoint_unhealthy"]).describe(
|
|
672
708
|
"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`)."
|
|
673
709
|
);
|
|
674
|
-
var WebhookEventTypeSchema =
|
|
710
|
+
var WebhookEventTypeSchema = z15.union([
|
|
675
711
|
ChargeWebhookEventTypeSchema,
|
|
676
712
|
WebhookDeliveryEventTypeSchema
|
|
677
713
|
]);
|
|
678
|
-
var WebhookCategorySchema =
|
|
714
|
+
var WebhookCategorySchema = z15.enum(["payments", "webhooks"]).describe(
|
|
679
715
|
"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."
|
|
680
716
|
);
|
|
681
717
|
function buildCategoryMap() {
|
|
@@ -705,116 +741,119 @@ var TriggerableChargeEventSchema = ChargeWebhookEventTypeSchema.exclude([
|
|
|
705
741
|
);
|
|
706
742
|
|
|
707
743
|
// src/webhooks.ts
|
|
708
|
-
import { z as
|
|
744
|
+
import { z as z16 } from "zod";
|
|
709
745
|
var WEBHOOK_EVENTS_WILDCARD = "*";
|
|
710
|
-
var CreateWebhookSchema =
|
|
711
|
-
url:
|
|
746
|
+
var CreateWebhookSchema = z16.object({
|
|
747
|
+
url: z16.string().max(2048).url().describe(
|
|
712
748
|
"Must be HTTPS and resolve to a public address \u2014 private/internal IPs are rejected."
|
|
713
749
|
),
|
|
714
|
-
events:
|
|
750
|
+
events: z16.array(z16.union([WebhookEventTypeSchema, z16.literal(WEBHOOK_EVENTS_WILDCARD)])).max(Object.keys(EVENT_CATEGORY_MAP).length + 1).default([]).describe(
|
|
715
751
|
'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.'
|
|
716
752
|
),
|
|
717
|
-
eventCategories:
|
|
753
|
+
eventCategories: z16.array(WebhookCategorySchema).max(WebhookCategorySchema.options.length).default([]).describe(
|
|
718
754
|
"Subscribe to every event in these categories. At least one of `events` or `eventCategories` is required."
|
|
719
755
|
),
|
|
720
|
-
excludeEvents:
|
|
756
|
+
excludeEvents: z16.array(WebhookEventTypeSchema).max(Object.keys(EVENT_CATEGORY_MAP).length).default([]).describe(
|
|
721
757
|
'Event types to exclude even if selected via `events: ["*"]` or `eventCategories`.'
|
|
722
758
|
)
|
|
723
759
|
}).refine((v) => v.events.length > 0 || v.eventCategories.length > 0, {
|
|
724
760
|
message: "must select at least one event via `events` or `eventCategories`",
|
|
725
761
|
path: ["events"]
|
|
726
762
|
});
|
|
727
|
-
var WebhookSchema =
|
|
728
|
-
id:
|
|
763
|
+
var WebhookSchema = z16.object({
|
|
764
|
+
id: z16.string(),
|
|
729
765
|
environment: EnvironmentSchema.nullable().describe(
|
|
730
766
|
"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)."
|
|
731
767
|
),
|
|
732
|
-
url:
|
|
733
|
-
events:
|
|
734
|
-
eventCategories:
|
|
735
|
-
excludeEvents:
|
|
736
|
-
isWildcard:
|
|
737
|
-
secret:
|
|
768
|
+
url: z16.string(),
|
|
769
|
+
events: z16.array(WebhookEventTypeSchema),
|
|
770
|
+
eventCategories: z16.array(WebhookCategorySchema),
|
|
771
|
+
excludeEvents: z16.array(WebhookEventTypeSchema),
|
|
772
|
+
isWildcard: z16.boolean(),
|
|
773
|
+
secret: z16.string().describe(
|
|
738
774
|
"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."
|
|
739
775
|
),
|
|
740
|
-
createdAt:
|
|
776
|
+
createdAt: z16.string().datetime()
|
|
741
777
|
});
|
|
742
778
|
var WebhookListItemSchema = WebhookSchema.omit({ secret: true }).extend({
|
|
743
|
-
hint:
|
|
779
|
+
hint: z16.string().describe("A truncated, safe-to-display form of the secret (e.g. `whsec_...ab12`).")
|
|
744
780
|
});
|
|
745
|
-
var WebhookPayloadSchema =
|
|
746
|
-
id:
|
|
781
|
+
var WebhookPayloadSchema = z16.object({
|
|
782
|
+
id: z16.string().describe(
|
|
747
783
|
"Unique id for this specific delivery \u2014 also sent as the `X-Klappay-Delivery` header."
|
|
748
784
|
),
|
|
749
785
|
event: WebhookEventTypeSchema,
|
|
750
|
-
createdAt:
|
|
751
|
-
data:
|
|
786
|
+
createdAt: z16.string().datetime(),
|
|
787
|
+
data: z16.unknown().describe(
|
|
752
788
|
"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."
|
|
753
789
|
)
|
|
754
790
|
});
|
|
755
|
-
var WebhookDeliveryStatusSchema =
|
|
756
|
-
var WebhookDeliverySchema =
|
|
757
|
-
id:
|
|
758
|
-
webhookId:
|
|
791
|
+
var WebhookDeliveryStatusSchema = z16.enum(["pending", "delivered", "failed"]);
|
|
792
|
+
var WebhookDeliverySchema = z16.object({
|
|
793
|
+
id: z16.string(),
|
|
794
|
+
webhookId: z16.string(),
|
|
759
795
|
event: WebhookEventTypeSchema,
|
|
760
796
|
status: WebhookDeliveryStatusSchema.describe(
|
|
761
797
|
"`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."
|
|
762
798
|
),
|
|
763
|
-
attempts:
|
|
764
|
-
responseCode:
|
|
799
|
+
attempts: z16.number(),
|
|
800
|
+
responseCode: z16.number().nullable().describe(
|
|
765
801
|
"HTTP status your endpoint returned on the most recent attempt. `null` if every attempt failed to connect at all."
|
|
766
802
|
),
|
|
767
|
-
nextRetryAt:
|
|
768
|
-
deliveredAt:
|
|
769
|
-
createdAt:
|
|
803
|
+
nextRetryAt: z16.string().datetime().nullable(),
|
|
804
|
+
deliveredAt: z16.string().datetime().nullable(),
|
|
805
|
+
createdAt: z16.string().datetime()
|
|
770
806
|
});
|
|
771
807
|
var ListWebhookDeliveriesSchema = PaginationQuerySchema;
|
|
772
808
|
var PaginatedWebhookDeliveriesSchema = paginatedSchema(WebhookDeliverySchema);
|
|
773
809
|
|
|
774
810
|
// src/recipients.ts
|
|
775
|
-
import { z as
|
|
811
|
+
import { z as z17 } from "zod";
|
|
776
812
|
var EVM_ADDRESS_REGEX = /^0x[0-9a-fA-F]{40}$/;
|
|
777
|
-
var CreateRecipientSchema =
|
|
778
|
-
address:
|
|
779
|
-
label:
|
|
813
|
+
var CreateRecipientSchema = z17.object({
|
|
814
|
+
address: z17.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."),
|
|
815
|
+
label: z17.string().min(1).max(64).optional().describe('Free-form label for your own bookkeeping (e.g. `"supplier"`) \u2014 never interpreted.')
|
|
780
816
|
});
|
|
781
|
-
var RecipientSchema =
|
|
782
|
-
id:
|
|
817
|
+
var RecipientSchema = z17.object({
|
|
818
|
+
id: z17.string().describe(
|
|
783
819
|
"Klappay-generated id, e.g. `rc_...` \u2014 this, not the raw address, is what a charge's `splitRecipients[].recipientId` references."
|
|
784
820
|
),
|
|
785
821
|
environment: EnvironmentSchema,
|
|
786
|
-
address:
|
|
787
|
-
label:
|
|
788
|
-
payout:
|
|
822
|
+
address: z17.string(),
|
|
823
|
+
label: z17.string().nullable(),
|
|
824
|
+
payout: z17.boolean().describe(
|
|
789
825
|
"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`."
|
|
790
826
|
),
|
|
791
|
-
createdAt:
|
|
827
|
+
createdAt: z17.string().datetime()
|
|
792
828
|
});
|
|
793
|
-
var SetRecipientPayoutSchema =
|
|
794
|
-
payout:
|
|
829
|
+
var SetRecipientPayoutSchema = z17.object({
|
|
830
|
+
payout: z17.boolean().describe("New payout-eligibility value for this recipient.")
|
|
795
831
|
});
|
|
796
832
|
|
|
797
833
|
// src/timeline.ts
|
|
798
|
-
import { z as
|
|
799
|
-
var TransactionSourceSchema =
|
|
800
|
-
"How this transfer was detected: `
|
|
834
|
+
import { z as z18 } from "zod";
|
|
835
|
+
var TransactionSourceSchema = z18.enum(["contract_watcher", "reconciliation_job", "sandbox"]).describe(
|
|
836
|
+
"How this transfer was detected: `contract_watcher` (the normal path \u2014 a real-time on-chain event 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)."
|
|
801
837
|
);
|
|
802
|
-
var TimelineEventTypeSchema =
|
|
838
|
+
var TimelineEventTypeSchema = z18.enum([
|
|
803
839
|
"charge.created",
|
|
804
840
|
"charge.expired",
|
|
805
841
|
"transaction.detected",
|
|
806
842
|
"split.distributed",
|
|
807
843
|
"webhook.dispatched",
|
|
808
844
|
"webhook.delivered",
|
|
809
|
-
"webhook.failed"
|
|
845
|
+
"webhook.failed",
|
|
846
|
+
"transfer.reclaimed"
|
|
810
847
|
]).describe(
|
|
811
|
-
"`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)."
|
|
848
|
+
"`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."
|
|
812
849
|
);
|
|
813
|
-
var TimelineEventSchema =
|
|
850
|
+
var TimelineEventSchema = z18.object({
|
|
814
851
|
type: TimelineEventTypeSchema,
|
|
815
|
-
at:
|
|
816
|
-
txHash:
|
|
817
|
-
|
|
852
|
+
at: z18.string().datetime(),
|
|
853
|
+
txHash: z18.string().optional().describe(
|
|
854
|
+
"Present for `transaction.detected`, `split.distributed`, and `transfer.reclaimed` events only."
|
|
855
|
+
),
|
|
856
|
+
amount: z18.number().optional().describe(
|
|
818
857
|
"Present for `transaction.detected` events only \u2014 the amount that specific transfer carried."
|
|
819
858
|
),
|
|
820
859
|
source: TransactionSourceSchema.optional().describe(
|
|
@@ -826,102 +865,102 @@ var TimelineEventSchema = z17.object({
|
|
|
826
865
|
network: NetworkSchema.optional().describe(
|
|
827
866
|
"Present for `transaction.detected` and `split.distributed` events \u2014 which network this specific transfer, or settlement, used."
|
|
828
867
|
),
|
|
829
|
-
causedTransition:
|
|
868
|
+
causedTransition: z18.boolean().optional().describe(
|
|
830
869
|
"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."
|
|
831
870
|
),
|
|
832
871
|
event: WebhookEventTypeSchema.optional().describe(
|
|
833
872
|
"Present for `webhook.*` events only \u2014 which event type this delivery was for."
|
|
834
873
|
),
|
|
835
|
-
responseCode:
|
|
874
|
+
responseCode: z18.number().nullable().optional().describe(
|
|
836
875
|
"Present for `webhook.*` events only \u2014 HTTP status your endpoint returned, or `null` if the request never connected."
|
|
837
876
|
),
|
|
838
|
-
attempts:
|
|
877
|
+
attempts: z18.number().optional().describe(
|
|
839
878
|
"Present for `webhook.*` events only \u2014 how many delivery attempts have been made so far."
|
|
840
879
|
)
|
|
841
880
|
});
|
|
842
881
|
|
|
843
882
|
// src/health.ts
|
|
844
|
-
import { z as
|
|
845
|
-
var HealthSchema =
|
|
846
|
-
status:
|
|
883
|
+
import { z as z19 } from "zod";
|
|
884
|
+
var HealthSchema = z19.object({
|
|
885
|
+
status: z19.enum(["ok", "error"]).describe(
|
|
847
886
|
"`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."
|
|
848
887
|
),
|
|
849
|
-
version:
|
|
850
|
-
timestamp:
|
|
851
|
-
db:
|
|
852
|
-
pendingWebhooks:
|
|
853
|
-
oldestPendingChargeAgeSeconds:
|
|
854
|
-
|
|
888
|
+
version: z19.string(),
|
|
889
|
+
timestamp: z19.string().datetime(),
|
|
890
|
+
db: z19.enum(["ok", "error"]).describe("Result of a real database connectivity check, not just a process-alive check."),
|
|
891
|
+
pendingWebhooks: z19.number().describe("Count of webhook deliveries still awaiting a successful attempt."),
|
|
892
|
+
oldestPendingChargeAgeSeconds: z19.number().nullable().describe("Age of the oldest still-unpaid charge, in seconds. `null` if there are none."),
|
|
893
|
+
lastContractWatcherEventAgeSeconds: z19.number().nullable().describe(
|
|
855
894
|
"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."
|
|
856
895
|
)
|
|
857
896
|
});
|
|
858
897
|
|
|
859
898
|
// src/sandbox.ts
|
|
860
|
-
import { z as
|
|
861
|
-
var SandboxTriggerSchema =
|
|
899
|
+
import { z as z20 } from "zod";
|
|
900
|
+
var SandboxTriggerSchema = z20.object({
|
|
862
901
|
event: TriggerableChargeEventSchema,
|
|
863
|
-
amount:
|
|
902
|
+
amount: z20.number().positive().max(CHARGE_AMOUNT_MAX).optional().describe(
|
|
864
903
|
"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."
|
|
865
904
|
)
|
|
866
905
|
});
|
|
867
906
|
|
|
868
907
|
// src/capabilities.ts
|
|
869
|
-
import { z as
|
|
870
|
-
var CapabilitiesSchema =
|
|
871
|
-
acceptedPayments:
|
|
908
|
+
import { z as z21 } from "zod";
|
|
909
|
+
var CapabilitiesSchema = z21.object({
|
|
910
|
+
acceptedPayments: z21.array(AcceptedPaymentSchema).describe(
|
|
872
911
|
"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."
|
|
873
912
|
)
|
|
874
913
|
});
|
|
875
914
|
|
|
876
915
|
// src/swap.ts
|
|
877
|
-
import { z as
|
|
878
|
-
var CreateSwapQuoteSchema =
|
|
916
|
+
import { z as z22 } from "zod";
|
|
917
|
+
var CreateSwapQuoteSchema = z22.object({
|
|
879
918
|
inputToken: AltTokenSchema.describe(
|
|
880
919
|
"Which alt-cryptocurrency the payer wants to send \u2014 must be one of this charge's `swapAlternatives`, or `422 token_not_supported`."
|
|
881
920
|
),
|
|
882
921
|
inputNetwork: NetworkSchema.describe(
|
|
883
922
|
"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."
|
|
884
923
|
),
|
|
885
|
-
takerAddress:
|
|
924
|
+
takerAddress: z22.string().regex(/^0x[0-9a-fA-F]{40}$/, "must be a 20-byte hex address").describe(
|
|
886
925
|
"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."
|
|
887
926
|
)
|
|
888
927
|
});
|
|
889
|
-
var SwapQuoteSchema =
|
|
928
|
+
var SwapQuoteSchema = z22.object({
|
|
890
929
|
inputToken: AltTokenSchema,
|
|
891
930
|
inputNetwork: NetworkSchema,
|
|
892
|
-
inputAmount:
|
|
931
|
+
inputAmount: z22.number().describe(
|
|
893
932
|
"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."
|
|
894
933
|
),
|
|
895
934
|
outputToken: TokenSchema.describe(
|
|
896
935
|
"Which of this charge's `acceptedPayments` tokens the swap resolves to."
|
|
897
936
|
),
|
|
898
937
|
outputNetwork: NetworkSchema,
|
|
899
|
-
outputAmount:
|
|
938
|
+
outputAmount: z22.number().describe(
|
|
900
939
|
"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`."
|
|
901
940
|
),
|
|
902
|
-
fees:
|
|
903
|
-
klappayFee:
|
|
941
|
+
fees: z22.object({
|
|
942
|
+
klappayFee: z22.number().describe(
|
|
904
943
|
"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`."
|
|
905
944
|
),
|
|
906
|
-
zeroExFee:
|
|
945
|
+
zeroExFee: z22.number().nullable().describe(
|
|
907
946
|
"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."
|
|
908
947
|
)
|
|
909
948
|
}).describe(
|
|
910
949
|
"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`."
|
|
911
950
|
),
|
|
912
|
-
expiresAt:
|
|
951
|
+
expiresAt: z22.string().datetime().describe(
|
|
913
952
|
"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."
|
|
914
953
|
),
|
|
915
|
-
transaction:
|
|
916
|
-
to:
|
|
917
|
-
data:
|
|
918
|
-
value:
|
|
954
|
+
transaction: z22.object({
|
|
955
|
+
to: z22.string().describe("Contract address the payer's wallet must send this transaction to."),
|
|
956
|
+
data: z22.string().describe("Calldata \u2014 opaque, must be sent unmodified."),
|
|
957
|
+
value: z22.string().describe(
|
|
919
958
|
"Native currency (ETH/BNB/MATIC/AVAX) to attach, in wei \u2014 `\"0\"` when `inputToken` isn't this network's native currency."
|
|
920
959
|
)
|
|
921
960
|
}).describe(
|
|
922
961
|
"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."
|
|
923
962
|
),
|
|
924
|
-
permit2:
|
|
963
|
+
permit2: z22.object({ eip712: z22.record(z22.unknown()) }).nullish().describe(
|
|
925
964
|
"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."
|
|
926
965
|
)
|
|
927
966
|
});
|
|
@@ -941,6 +980,7 @@ export {
|
|
|
941
980
|
CHECKOUT_PRODUCTS_MAX,
|
|
942
981
|
CONFLICTING_SCOPE_PAIRS,
|
|
943
982
|
CapabilitiesSchema,
|
|
983
|
+
ChargeFeePayerSchema,
|
|
944
984
|
ChargeSchema,
|
|
945
985
|
ChargeStatusSchema,
|
|
946
986
|
ChargeWebhookEventTypeSchema,
|
|
@@ -950,6 +990,7 @@ export {
|
|
|
950
990
|
CheckChargeRequestSchema,
|
|
951
991
|
CheckChargeResponseSchema,
|
|
952
992
|
CheckoutProductSchema,
|
|
993
|
+
ConfirmationProgressSchema,
|
|
953
994
|
CreateChargeSchema,
|
|
954
995
|
CreateRecipientSchema,
|
|
955
996
|
CreateSwapQuoteSchema,
|