@klappay/types 2.0.4 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +179 -10
- package/dist/index.d.ts +179 -10
- package/dist/index.js +382 -223
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +370 -223
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -1
package/dist/index.js
CHANGED
|
@@ -20,8 +20,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
+
ALT_TOKEN_ADDRESSES: () => ALT_TOKEN_ADDRESSES,
|
|
24
|
+
ALT_TOKEN_DECIMALS: () => ALT_TOKEN_DECIMALS,
|
|
23
25
|
API_KEY_SCOPES: () => API_KEY_SCOPES,
|
|
24
26
|
AcceptedPaymentSchema: () => AcceptedPaymentSchema,
|
|
27
|
+
AltTokenSchema: () => AltTokenSchema,
|
|
25
28
|
ApiKeyScopeSchema: () => ApiKeyScopeSchema,
|
|
26
29
|
CHARGE_ACCEPTED_PAYMENTS_MAX: () => CHARGE_ACCEPTED_PAYMENTS_MAX,
|
|
27
30
|
CHARGE_AMOUNT_MAX: () => CHARGE_AMOUNT_MAX,
|
|
@@ -29,6 +32,7 @@ __export(index_exports, {
|
|
|
29
32
|
CHARGE_EXPIRES_IN_MIN_SECONDS: () => CHARGE_EXPIRES_IN_MIN_SECONDS,
|
|
30
33
|
CHARGE_SPLIT_RECIPIENTS_MAX: () => CHARGE_SPLIT_RECIPIENTS_MAX,
|
|
31
34
|
CHECKOUT_PRODUCTS_MAX: () => CHECKOUT_PRODUCTS_MAX,
|
|
35
|
+
CONFLICTING_SCOPE_PAIRS: () => CONFLICTING_SCOPE_PAIRS,
|
|
32
36
|
CapabilitiesSchema: () => CapabilitiesSchema,
|
|
33
37
|
ChargeSchema: () => ChargeSchema,
|
|
34
38
|
ChargeStatusSchema: () => ChargeStatusSchema,
|
|
@@ -38,6 +42,8 @@ __export(index_exports, {
|
|
|
38
42
|
ChargesQueryFieldSchema: () => ChargesQueryFieldSchema,
|
|
39
43
|
CheckoutProductSchema: () => CheckoutProductSchema,
|
|
40
44
|
CreateChargeSchema: () => CreateChargeSchema,
|
|
45
|
+
CreateRecipientSchema: () => CreateRecipientSchema,
|
|
46
|
+
CreateSwapQuoteSchema: () => CreateSwapQuoteSchema,
|
|
41
47
|
CreateWebhookSchema: () => CreateWebhookSchema,
|
|
42
48
|
DistributionsDateFieldSchema: () => DistributionsDateFieldSchema,
|
|
43
49
|
DistributionsMetricFieldSchema: () => DistributionsMetricFieldSchema,
|
|
@@ -80,10 +86,14 @@ __export(index_exports, {
|
|
|
80
86
|
PendingDistributionEventSchema: () => PendingDistributionEventSchema,
|
|
81
87
|
PendingDistributionRecipientSchema: () => PendingDistributionRecipientSchema,
|
|
82
88
|
PendingDistributionSchema: () => PendingDistributionSchema,
|
|
89
|
+
RecipientSchema: () => RecipientSchema,
|
|
83
90
|
SandboxTriggerSchema: () => SandboxTriggerSchema,
|
|
91
|
+
SetRecipientPayoutSchema: () => SetRecipientPayoutSchema,
|
|
84
92
|
SettlementStatusSchema: () => SettlementStatusSchema,
|
|
85
93
|
SplitDistributionStatusSchema: () => SplitDistributionStatusSchema,
|
|
94
|
+
SplitRecipientInputSchema: () => SplitRecipientInputSchema,
|
|
86
95
|
SplitRecipientSchema: () => SplitRecipientSchema,
|
|
96
|
+
SwapQuoteSchema: () => SwapQuoteSchema,
|
|
87
97
|
TOKEN_ADDRESSES: () => TOKEN_ADDRESSES,
|
|
88
98
|
TOKEN_DECIMALS: () => TOKEN_DECIMALS,
|
|
89
99
|
TimelineEventSchema: () => TimelineEventSchema,
|
|
@@ -104,6 +114,8 @@ __export(index_exports, {
|
|
|
104
114
|
WebhookListItemSchema: () => WebhookListItemSchema,
|
|
105
115
|
WebhookPayloadSchema: () => WebhookPayloadSchema,
|
|
106
116
|
WebhookSchema: () => WebhookSchema,
|
|
117
|
+
findConflictingScopes: () => findConflictingScopes,
|
|
118
|
+
listAltTokensForNetworks: () => listAltTokensForNetworks,
|
|
107
119
|
paginatedSchema: () => paginatedSchema
|
|
108
120
|
});
|
|
109
121
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -140,11 +152,26 @@ var ApiKeyScopeSchema = import_zod3.z.enum([
|
|
|
140
152
|
"metrics:charges:read",
|
|
141
153
|
"metrics:transactions:read",
|
|
142
154
|
"metrics:distributions:read",
|
|
143
|
-
"sandbox:trigger"
|
|
155
|
+
"sandbox:trigger",
|
|
156
|
+
"charges:split_write",
|
|
157
|
+
"recipients:read",
|
|
158
|
+
"recipients:write",
|
|
159
|
+
"recipients:manage_payout"
|
|
144
160
|
]).describe(
|
|
145
|
-
"What an API key is allowed to do, independent of `tenantId`/`environment` (which scope *whose* data, not *what actions*). A key with none of these can still authenticate but every scoped route rejects it with `403 insufficient_scope`. `metrics:read` alone grants every metrics resource; `metrics:{resource}:read` grants only that one \u2014 a key can hold either or both."
|
|
161
|
+
"What an API key is allowed to do, independent of `tenantId`/`environment` (which scope *whose* data, not *what actions*). A key with none of these can still authenticate but every scoped route rejects it with `403 insufficient_scope`. `metrics:read` alone grants every metrics resource; `metrics:{resource}:read` grants only that one \u2014 a key can hold either or both. `charges:split_write` is required on top of `charges:write` whenever a charge request includes `splitRecipients` \u2014 a key without it can create ordinary charges but never redirect part of the payout. `recipients:write` registers/revokes recipients (addresses eligible to be *referenced* in a split); `recipients:manage_payout` is separate and strictly more sensitive \u2014 it is what lets a recipient actually become an API key's `payoutAddress`, and should be granted only to a key that already went through out-of-band approval for that (Dashboard's own internal key, never a merchant-facing or third-party integration key like a marketplace's). `charges:split_write` can never be combined with `recipients:write`/`recipients:manage_payout` on the same key (see `CONFLICTING_SCOPE_PAIRS`) \u2014 Core rejects such a key outright, before any route runs."
|
|
146
162
|
);
|
|
147
163
|
var API_KEY_SCOPES = ApiKeyScopeSchema.options;
|
|
164
|
+
var CONFLICTING_SCOPE_PAIRS = [
|
|
165
|
+
["charges:split_write", "recipients:write"],
|
|
166
|
+
["charges:split_write", "recipients:manage_payout"]
|
|
167
|
+
];
|
|
168
|
+
function findConflictingScopes(scopes) {
|
|
169
|
+
const held = new Set(scopes);
|
|
170
|
+
for (const [a, b] of CONFLICTING_SCOPE_PAIRS) {
|
|
171
|
+
if (held.has(a) && held.has(b)) return [a, b];
|
|
172
|
+
}
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
148
175
|
|
|
149
176
|
// src/networks.ts
|
|
150
177
|
var import_zod4 = require("zod");
|
|
@@ -243,51 +270,82 @@ var TOKEN_ADDRESSES = {
|
|
|
243
270
|
}
|
|
244
271
|
};
|
|
245
272
|
|
|
273
|
+
// src/alt-tokens.ts
|
|
274
|
+
var import_zod7 = require("zod");
|
|
275
|
+
var AltTokenSchema = import_zod7.z.enum(["ETH", "BNB", "MATIC", "AVAX", "BTC"]).describe(
|
|
276
|
+
"A non-stablecoin cryptocurrency Klappay trusts as swap input for a charge, via the 0x Swap API \u2014 swapped to one of the charge's `acceptedPayments` tokens before it ever reaches the merchant, so the merchant always receives USDC/USDT regardless of what the payer sent. Only a network's own native currency, plus `BTC` (wrapped) on the networks with deep, reputably-custodied liquidity, is trusted today (see `ALT_TOKEN_ADDRESSES`) \u2014 never assume every value here is available on every network."
|
|
277
|
+
);
|
|
278
|
+
var ALT_TOKEN_DECIMALS = {
|
|
279
|
+
ETH: 18,
|
|
280
|
+
BNB: 18,
|
|
281
|
+
MATIC: 18,
|
|
282
|
+
AVAX: 18,
|
|
283
|
+
BTC: 8
|
|
284
|
+
};
|
|
285
|
+
var ALT_TOKEN_ADDRESSES = {
|
|
286
|
+
base: { ETH: "native", BTC: "0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf" },
|
|
287
|
+
optimism: { ETH: "native", BTC: "0x68f180fcCe6836688e9084f035309E29Bf0A2095" },
|
|
288
|
+
ethereum: { ETH: "native", BTC: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599" },
|
|
289
|
+
arbitrum: { ETH: "native", BTC: "0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f" },
|
|
290
|
+
polygon: { MATIC: "native", BTC: "0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6" },
|
|
291
|
+
avalanche: { AVAX: "native" },
|
|
292
|
+
bnb: { BNB: "native" }
|
|
293
|
+
};
|
|
294
|
+
function listAltTokensForNetworks(networks) {
|
|
295
|
+
const found = /* @__PURE__ */ new Set();
|
|
296
|
+
for (const network of networks) {
|
|
297
|
+
for (const token of Object.keys(ALT_TOKEN_ADDRESSES[network] ?? {})) {
|
|
298
|
+
found.add(token);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return [...found];
|
|
302
|
+
}
|
|
303
|
+
|
|
246
304
|
// src/charges.ts
|
|
247
|
-
var
|
|
305
|
+
var import_zod9 = require("zod");
|
|
248
306
|
|
|
249
307
|
// src/checkout-metadata.ts
|
|
250
|
-
var
|
|
308
|
+
var import_zod8 = require("zod");
|
|
251
309
|
var CHECKOUT_PRODUCTS_MAX = 20;
|
|
252
|
-
var CheckoutProductSchema =
|
|
253
|
-
name:
|
|
254
|
-
quantity:
|
|
255
|
-
imageUrl:
|
|
310
|
+
var CheckoutProductSchema = import_zod8.z.object({
|
|
311
|
+
name: import_zod8.z.string().min(1).max(200).describe("What the payer is buying, shown as-is on the hosted checkout page."),
|
|
312
|
+
quantity: import_zod8.z.number().int().positive().max(9999).optional().describe("How many of this item. Omit for a single, unquantified item."),
|
|
313
|
+
imageUrl: import_zod8.z.string().url().max(2048).refine((value) => /^https?:\/\//.test(value), "must use http or https").optional().describe(
|
|
256
314
|
"Product image, fetched only by the payer's own browser \u2014 Klappay never fetches it server-side. Must be `http(s)`."
|
|
257
315
|
)
|
|
258
316
|
});
|
|
259
|
-
var KlappayCheckoutMetadataSchema =
|
|
260
|
-
products:
|
|
317
|
+
var KlappayCheckoutMetadataSchema = import_zod8.z.object({
|
|
318
|
+
products: import_zod8.z.array(CheckoutProductSchema).max(CHECKOUT_PRODUCTS_MAX).optional().describe(
|
|
261
319
|
`What the payer is buying, shown on the hosted checkout page \u2014 up to ${CHECKOUT_PRODUCTS_MAX} items. Purely informational: never validated against \`amount\`, never used by any payment or distribution logic.`
|
|
262
320
|
)
|
|
263
321
|
}).describe(
|
|
264
322
|
"Reserved for Klappay \u2014 the one namespace inside `metadata` whose format is defined and enforced by Klappay, not by you. A `metadata.klappay` that does not match this shape is rejected outright (`400 validation_error`), unlike every other key in `metadata`, which accepts absolutely anything and never fails validation."
|
|
265
323
|
);
|
|
266
|
-
var MetadataWithKlappaySchema =
|
|
324
|
+
var MetadataWithKlappaySchema = import_zod8.z.object({ klappay: KlappayCheckoutMetadataSchema.optional() }).catchall(import_zod8.z.unknown()).describe(
|
|
267
325
|
"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`."
|
|
268
326
|
);
|
|
269
327
|
|
|
270
328
|
// src/charges.ts
|
|
271
|
-
var ChargeStatusSchema =
|
|
329
|
+
var ChargeStatusSchema = import_zod9.z.enum(["pending", "partially_paid", "confirmed", "expired", "underpaid"]).describe(
|
|
272
330
|
"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."
|
|
273
331
|
);
|
|
274
|
-
var SettlementStatusSchema =
|
|
332
|
+
var SettlementStatusSchema = import_zod9.z.enum(["pending", "completed", "failed"]).describe(
|
|
275
333
|
"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."
|
|
276
334
|
);
|
|
277
335
|
var CHARGE_EXPIRES_IN_MIN_SECONDS = 60;
|
|
278
336
|
var CHARGE_EXPIRES_IN_MAX_SECONDS = 3600;
|
|
279
337
|
var CHARGE_ACCEPTED_PAYMENTS_MAX = 14;
|
|
280
|
-
var AcceptedPaymentSchema =
|
|
338
|
+
var AcceptedPaymentSchema = import_zod9.z.object({
|
|
281
339
|
token: TokenSchema,
|
|
282
340
|
network: NetworkSchema
|
|
283
341
|
});
|
|
284
|
-
var AcceptedPaymentsSchema =
|
|
342
|
+
var AcceptedPaymentsSchema = import_zod9.z.array(AcceptedPaymentSchema).min(1, "At least one accepted payment is required.").max(CHARGE_ACCEPTED_PAYMENTS_MAX).superRefine((pairs, ctx) => {
|
|
285
343
|
const seen = /* @__PURE__ */ new Set();
|
|
286
344
|
pairs.forEach((pair, index) => {
|
|
287
345
|
const key = `${pair.token}:${pair.network}`;
|
|
288
346
|
if (seen.has(key)) {
|
|
289
347
|
ctx.addIssue({
|
|
290
|
-
code:
|
|
348
|
+
code: import_zod9.z.ZodIssueCode.custom,
|
|
291
349
|
message: `Duplicate accepted payment: ${pair.token} on ${pair.network}.`,
|
|
292
350
|
path: [index]
|
|
293
351
|
});
|
|
@@ -295,7 +353,7 @@ var AcceptedPaymentsSchema = import_zod8.z.array(AcceptedPaymentSchema).min(1, "
|
|
|
295
353
|
seen.add(key);
|
|
296
354
|
if (!OPERATIONAL_NETWORKS.includes(pair.network)) {
|
|
297
355
|
ctx.addIssue({
|
|
298
|
-
code:
|
|
356
|
+
code: import_zod9.z.ZodIssueCode.custom,
|
|
299
357
|
message: `Network "${pair.network}" isn't live yet \u2014 only ${OPERATIONAL_NETWORKS.join(", ")} today.`,
|
|
300
358
|
path: [index, "network"]
|
|
301
359
|
});
|
|
@@ -305,105 +363,118 @@ var AcceptedPaymentsSchema = import_zod8.z.array(AcceptedPaymentSchema).min(1, "
|
|
|
305
363
|
`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\`.`
|
|
306
364
|
);
|
|
307
365
|
var CHARGE_SPLIT_RECIPIENTS_MAX = 5;
|
|
308
|
-
var SplitRecipientSchema =
|
|
309
|
-
address:
|
|
310
|
-
percent:
|
|
366
|
+
var SplitRecipientSchema = import_zod9.z.object({
|
|
367
|
+
address: import_zod9.z.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."),
|
|
368
|
+
percent: import_zod9.z.number().positive().max(100).describe(
|
|
311
369
|
"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."
|
|
312
370
|
),
|
|
313
|
-
label:
|
|
371
|
+
label: import_zod9.z.string().min(1).max(64).optional().describe(
|
|
314
372
|
'Free-form label for your own bookkeeping (e.g. `"supplier"`, `"sales rep"`) \u2014 echoed back unchanged, never interpreted by Klappay.'
|
|
315
373
|
)
|
|
316
374
|
});
|
|
317
|
-
var
|
|
375
|
+
var SplitRecipientInputSchema = import_zod9.z.object({
|
|
376
|
+
recipientId: import_zod9.z.string().describe(
|
|
377
|
+
"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."
|
|
378
|
+
),
|
|
379
|
+
percent: import_zod9.z.number().positive().max(100).describe(
|
|
380
|
+
"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."
|
|
381
|
+
),
|
|
382
|
+
label: import_zod9.z.string().min(1).max(64).optional().describe(
|
|
383
|
+
'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.'
|
|
384
|
+
)
|
|
385
|
+
});
|
|
386
|
+
var SplitRecipientsInputSchema = import_zod9.z.array(SplitRecipientInputSchema).max(CHARGE_SPLIT_RECIPIENTS_MAX).superRefine((recipients, ctx) => {
|
|
318
387
|
const seen = /* @__PURE__ */ new Set();
|
|
319
388
|
recipients.forEach((recipient, index) => {
|
|
320
|
-
|
|
321
|
-
if (seen.has(key)) {
|
|
389
|
+
if (seen.has(recipient.recipientId)) {
|
|
322
390
|
ctx.addIssue({
|
|
323
|
-
code:
|
|
324
|
-
message: `Duplicate split
|
|
325
|
-
path: [index, "
|
|
391
|
+
code: import_zod9.z.ZodIssueCode.custom,
|
|
392
|
+
message: `Duplicate split recipientId: ${recipient.recipientId}.`,
|
|
393
|
+
path: [index, "recipientId"]
|
|
326
394
|
});
|
|
327
395
|
}
|
|
328
|
-
seen.add(
|
|
396
|
+
seen.add(recipient.recipientId);
|
|
329
397
|
});
|
|
330
398
|
}).describe(
|
|
331
|
-
`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}. 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\`.`
|
|
399
|
+
`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\`.`
|
|
332
400
|
);
|
|
333
401
|
var CHARGE_AMOUNT_MAX = 999999999999;
|
|
334
|
-
var CreateChargeSchema =
|
|
335
|
-
amount:
|
|
402
|
+
var CreateChargeSchema = import_zod9.z.object({
|
|
403
|
+
amount: import_zod9.z.number().positive().max(CHARGE_AMOUNT_MAX).describe(
|
|
336
404
|
"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."
|
|
337
405
|
),
|
|
338
|
-
currency:
|
|
406
|
+
currency: import_zod9.z.literal("USD").default("USD").describe("Always `USD` today \u2014 the only supported currency."),
|
|
339
407
|
acceptedPayments: AcceptedPaymentsSchema,
|
|
340
|
-
expiresIn:
|
|
408
|
+
expiresIn: import_zod9.z.number().int().min(CHARGE_EXPIRES_IN_MIN_SECONDS).max(CHARGE_EXPIRES_IN_MAX_SECONDS).describe(
|
|
341
409
|
"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."
|
|
342
410
|
),
|
|
343
|
-
idempotencyKey:
|
|
411
|
+
idempotencyKey: import_zod9.z.string().min(1).max(255).optional().describe(
|
|
344
412
|
"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."
|
|
345
413
|
),
|
|
346
|
-
externalRef:
|
|
414
|
+
externalRef: import_zod9.z.string().min(1).max(255).optional().describe(
|
|
347
415
|
"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."
|
|
348
416
|
),
|
|
349
|
-
source:
|
|
417
|
+
source: import_zod9.z.string().min(1).max(64).optional().describe(
|
|
350
418
|
'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.'
|
|
351
419
|
),
|
|
352
420
|
metadata: MetadataWithKlappaySchema.optional(),
|
|
353
|
-
redirectUrl:
|
|
421
|
+
redirectUrl: import_zod9.z.string().url().refine((value) => /^https?:\/\//.test(value), "must use http or https").optional().describe(
|
|
354
422
|
"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."
|
|
355
423
|
),
|
|
356
|
-
splitRecipients:
|
|
424
|
+
splitRecipients: SplitRecipientsInputSchema.optional()
|
|
357
425
|
});
|
|
358
|
-
var ChargeSchema =
|
|
359
|
-
id:
|
|
360
|
-
amount:
|
|
361
|
-
amountReceived:
|
|
426
|
+
var ChargeSchema = import_zod9.z.object({
|
|
427
|
+
id: import_zod9.z.string().describe("Klappay-generated id, e.g. `ch_...`. Use this to look up the charge later."),
|
|
428
|
+
amount: import_zod9.z.number().describe("The amount originally requested, in `currency` units (up to 6 decimal places)."),
|
|
429
|
+
amountReceived: import_zod9.z.number().nullable().describe(
|
|
362
430
|
"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`."
|
|
363
431
|
),
|
|
364
|
-
isOverpaid:
|
|
432
|
+
isOverpaid: import_zod9.z.boolean().describe(
|
|
365
433
|
"`true` if `amountReceived` ended up greater than `amount`. Klappay never refunds the difference automatically \u2014 see the docs for why."
|
|
366
434
|
),
|
|
367
|
-
currency:
|
|
368
|
-
acceptedPayments:
|
|
435
|
+
currency: import_zod9.z.string().describe("Always `USD` today \u2014 the only supported currency."),
|
|
436
|
+
acceptedPayments: import_zod9.z.array(AcceptedPaymentSchema).describe(
|
|
369
437
|
"Every `(token, network)` pair this charge was configured to accept, unchanged after creation."
|
|
370
438
|
),
|
|
371
|
-
paidWith:
|
|
439
|
+
paidWith: import_zod9.z.array(AcceptedPaymentSchema).describe(
|
|
372
440
|
"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`."
|
|
373
441
|
),
|
|
374
|
-
|
|
442
|
+
swapAlternatives: import_zod9.z.array(AltTokenSchema).describe(
|
|
443
|
+
"Non-stablecoin cryptocurrencies 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 Base lists `ETH` here, since Base's native currency is trusted as swap input). 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, or if swap-to-pay isn't configured on this deployment."
|
|
444
|
+
),
|
|
445
|
+
address: import_zod9.z.string().describe(
|
|
375
446
|
"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."
|
|
376
447
|
),
|
|
377
448
|
status: ChargeStatusSchema,
|
|
378
449
|
settlementStatus: SettlementStatusSchema.nullable(),
|
|
379
450
|
environment: EnvironmentSchema,
|
|
380
|
-
apiKeyId:
|
|
451
|
+
apiKeyId: import_zod9.z.string().nullable().describe(
|
|
381
452
|
"Which of your API keys created this charge. `null` for a charge created before this field existed."
|
|
382
453
|
),
|
|
383
|
-
txHash:
|
|
454
|
+
txHash: import_zod9.z.string().nullable().describe(
|
|
384
455
|
"Transaction hash of the most recent transfer detected for this charge. `null` until a payment is detected."
|
|
385
456
|
),
|
|
386
|
-
externalRef:
|
|
387
|
-
source:
|
|
457
|
+
externalRef: import_zod9.z.string().nullable(),
|
|
458
|
+
source: import_zod9.z.string().nullable(),
|
|
388
459
|
metadata: MetadataWithKlappaySchema.nullable(),
|
|
389
|
-
redirectUrl:
|
|
390
|
-
checkoutUrl:
|
|
460
|
+
redirectUrl: import_zod9.z.string().nullable().describe("Echoes the `redirectUrl` set at creation, if any. `null` if none was set."),
|
|
461
|
+
checkoutUrl: import_zod9.z.string().nullable().describe(
|
|
391
462
|
"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."
|
|
392
463
|
),
|
|
393
|
-
splitRecipients:
|
|
394
|
-
createdAt:
|
|
395
|
-
expiresAt:
|
|
464
|
+
splitRecipients: import_zod9.z.array(SplitRecipientSchema).describe("Echoes whatever extra split recipients were set at creation \u2014 empty array if none."),
|
|
465
|
+
createdAt: import_zod9.z.string().datetime(),
|
|
466
|
+
expiresAt: import_zod9.z.string().datetime().describe(
|
|
396
467
|
"When this charge stops accepting payment, if still `pending`/`partially_paid` by then."
|
|
397
468
|
),
|
|
398
|
-
confirmedAt:
|
|
399
|
-
settledAt:
|
|
469
|
+
confirmedAt: import_zod9.z.string().datetime().nullable().describe("When `status` first reached `confirmed`. `null` until then."),
|
|
470
|
+
settledAt: import_zod9.z.string().datetime().nullable().describe(
|
|
400
471
|
"When `settlementStatus` first reached `completed` \u2014 the merchant's wallet actually has the funds. `null` until then, including while `settlementStatus` is `pending`/`failed`."
|
|
401
472
|
),
|
|
402
|
-
lastActivityAt:
|
|
473
|
+
lastActivityAt: import_zod9.z.string().datetime().describe(
|
|
403
474
|
"When a transfer was last credited toward this charge, or `createdAt` if none has arrived yet."
|
|
404
475
|
)
|
|
405
476
|
});
|
|
406
|
-
var ListChargesSchema =
|
|
477
|
+
var ListChargesSchema = import_zod9.z.object({
|
|
407
478
|
status: ChargeStatusSchema.optional(),
|
|
408
479
|
token: TokenSchema.optional().describe(
|
|
409
480
|
"Filters on `paidWith.token` \u2014 the pair actually paid, not accepted."
|
|
@@ -412,13 +483,13 @@ var ListChargesSchema = import_zod8.z.object({
|
|
|
412
483
|
"Filters on `paidWith.network` \u2014 the pair actually paid, not accepted."
|
|
413
484
|
),
|
|
414
485
|
environment: EnvironmentSchema.optional(),
|
|
415
|
-
since:
|
|
486
|
+
since: import_zod9.z.string().datetime().optional().describe(
|
|
416
487
|
"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."
|
|
417
488
|
),
|
|
418
|
-
isOverpaid:
|
|
489
|
+
isOverpaid: import_zod9.z.enum(["true", "false"]).transform((v) => v === "true").optional()
|
|
419
490
|
}).extend(PaginationQuerySchema.shape);
|
|
420
491
|
var PaginatedChargesSchema = paginatedSchema(ChargeSchema);
|
|
421
|
-
var GetChargeQrCodeQuerySchema =
|
|
492
|
+
var GetChargeQrCodeQuerySchema = import_zod9.z.object({
|
|
422
493
|
token: TokenSchema.optional().describe(
|
|
423
494
|
"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."
|
|
424
495
|
),
|
|
@@ -426,61 +497,61 @@ var GetChargeQrCodeQuerySchema = import_zod8.z.object({
|
|
|
426
497
|
});
|
|
427
498
|
|
|
428
499
|
// src/distributions.ts
|
|
429
|
-
var
|
|
430
|
-
var SplitDistributionStatusSchema =
|
|
500
|
+
var import_zod10 = require("zod");
|
|
501
|
+
var SplitDistributionStatusSchema = import_zod10.z.enum(["pending", "processing", "completed", "failed"]).describe(
|
|
431
502
|
"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."
|
|
432
503
|
);
|
|
433
|
-
var PendingDistributionRecipientSchema =
|
|
434
|
-
address:
|
|
435
|
-
percentAllocation:
|
|
504
|
+
var PendingDistributionRecipientSchema = import_zod10.z.object({
|
|
505
|
+
address: import_zod10.z.string().describe("On-chain recipient address."),
|
|
506
|
+
percentAllocation: import_zod10.z.number().describe("This recipient's share of the split, as a percentage (e.g. `99.0991` = 99.0991%).")
|
|
436
507
|
});
|
|
437
|
-
var PendingDistributionSchema =
|
|
438
|
-
splitAddress:
|
|
508
|
+
var PendingDistributionSchema = import_zod10.z.object({
|
|
509
|
+
splitAddress: import_zod10.z.string().describe("The on-chain 0xSplits address to call `distribute()` on."),
|
|
439
510
|
network: NetworkSchema,
|
|
440
511
|
token: TokenSchema,
|
|
441
|
-
recipients:
|
|
512
|
+
recipients: import_zod10.z.array(PendingDistributionRecipientSchema).describe(
|
|
442
513
|
"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."
|
|
443
514
|
),
|
|
444
|
-
distributorFeePercent:
|
|
515
|
+
distributorFeePercent: import_zod10.z.number().describe(
|
|
445
516
|
"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."
|
|
446
517
|
),
|
|
447
|
-
estimatedRewardAmount:
|
|
518
|
+
estimatedRewardAmount: import_zod10.z.number().describe(
|
|
448
519
|
"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."
|
|
449
520
|
),
|
|
450
|
-
availableSince:
|
|
451
|
-
graceEndsAt:
|
|
521
|
+
availableSince: import_zod10.z.string().datetime().describe("When this distribution entered its grace period."),
|
|
522
|
+
graceEndsAt: import_zod10.z.string().datetime().describe(
|
|
452
523
|
"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."
|
|
453
524
|
)
|
|
454
525
|
});
|
|
455
526
|
var PaginatedPendingDistributionsSchema = paginatedSchema(PendingDistributionSchema);
|
|
456
|
-
var ListenPendingDistributionsQuerySchema =
|
|
457
|
-
limit:
|
|
527
|
+
var ListenPendingDistributionsQuerySchema = import_zod10.z.object({
|
|
528
|
+
limit: import_zod10.z.coerce.number().int().min(0).max(PAGINATION_LIMIT_MAX).default(0).describe(
|
|
458
529
|
"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."
|
|
459
530
|
)
|
|
460
531
|
});
|
|
461
|
-
var PendingDistributionEventSchema =
|
|
462
|
-
|
|
463
|
-
type:
|
|
532
|
+
var PendingDistributionEventSchema = import_zod10.z.discriminatedUnion("type", [
|
|
533
|
+
import_zod10.z.object({
|
|
534
|
+
type: import_zod10.z.literal("distribution.available"),
|
|
464
535
|
distribution: PendingDistributionSchema
|
|
465
536
|
}),
|
|
466
|
-
|
|
467
|
-
type:
|
|
468
|
-
splitAddress:
|
|
537
|
+
import_zod10.z.object({
|
|
538
|
+
type: import_zod10.z.literal("distribution.claimed"),
|
|
539
|
+
splitAddress: import_zod10.z.string().describe("No longer claimable \u2014 either settled by someone, or picked up by the worker.")
|
|
469
540
|
})
|
|
470
541
|
]);
|
|
471
542
|
|
|
472
543
|
// src/metrics.ts
|
|
473
|
-
var
|
|
474
|
-
var MetricsResourceSchema =
|
|
544
|
+
var import_zod11 = require("zod");
|
|
545
|
+
var MetricsResourceSchema = import_zod11.z.enum(["charges", "transactions", "distributions"]).describe(
|
|
475
546
|
"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."
|
|
476
547
|
);
|
|
477
|
-
var MetricsAggregationSchema =
|
|
548
|
+
var MetricsAggregationSchema = import_zod11.z.enum(["count", "sum", "avg", "min", "max"]).describe(
|
|
478
549
|
"`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."
|
|
479
550
|
);
|
|
480
|
-
var MetricsFilterOperatorSchema =
|
|
551
|
+
var MetricsFilterOperatorSchema = import_zod11.z.enum(["eq", "neq", "in", "gt", "gte", "lt", "lte"]).describe(
|
|
481
552
|
"`in` expects an array value (max 50 entries); every other operator expects a single scalar."
|
|
482
553
|
);
|
|
483
|
-
var MetricsDateGranularitySchema =
|
|
554
|
+
var MetricsDateGranularitySchema = import_zod11.z.enum(["day", "week", "month", "year"]).describe(
|
|
484
555
|
"Bucket width for a `date_bucket` `groupBy` entry \u2014 Postgres `date_trunc` semantics (UTC)."
|
|
485
556
|
);
|
|
486
557
|
var metricsQueryEnvironmentSchema = EnvironmentSchema.describe(
|
|
@@ -493,151 +564,151 @@ var METRICS_QUERY_MAX_GROUP_BY = 3;
|
|
|
493
564
|
var METRICS_QUERY_MAX_FILTERS = 20;
|
|
494
565
|
var METRICS_QUERY_MAX_METRICS = 10;
|
|
495
566
|
var METRIC_ALIAS_PATTERN = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
|
|
496
|
-
var metricAliasSchema =
|
|
567
|
+
var metricAliasSchema = import_zod11.z.string().min(1).max(64).regex(
|
|
497
568
|
METRIC_ALIAS_PATTERN,
|
|
498
569
|
"Must start with a letter or underscore, and contain only letters, digits, and underscores \u2014 this becomes a SQL column alias."
|
|
499
570
|
).optional();
|
|
500
|
-
var MetricsFilterValueSchema =
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
571
|
+
var MetricsFilterValueSchema = import_zod11.z.union([
|
|
572
|
+
import_zod11.z.string().max(255),
|
|
573
|
+
import_zod11.z.number(),
|
|
574
|
+
import_zod11.z.boolean(),
|
|
575
|
+
import_zod11.z.array(import_zod11.z.union([import_zod11.z.string().max(255), import_zod11.z.number()])).min(1).max(50)
|
|
505
576
|
]);
|
|
506
|
-
var orderBySchema =
|
|
507
|
-
key:
|
|
577
|
+
var orderBySchema = import_zod11.z.object({
|
|
578
|
+
key: import_zod11.z.string().min(1).max(64).regex(
|
|
508
579
|
METRIC_ALIAS_PATTERN,
|
|
509
580
|
"Must start with a letter or underscore, and contain only letters, digits, and underscores \u2014 every valid output column name already looks like this."
|
|
510
581
|
).describe(
|
|
511
582
|
"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."
|
|
512
583
|
),
|
|
513
|
-
direction:
|
|
584
|
+
direction: import_zod11.z.enum(["asc", "desc"])
|
|
514
585
|
}).describe(
|
|
515
586
|
"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."
|
|
516
587
|
);
|
|
517
|
-
var limitSchema =
|
|
588
|
+
var limitSchema = import_zod11.z.number().int().min(1).max(METRICS_QUERY_MAX_ROW_LIMIT).default(METRICS_QUERY_DEFAULT_ROW_LIMIT).describe(
|
|
518
589
|
`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.`
|
|
519
590
|
);
|
|
520
|
-
var ChargesQueryFieldSchema =
|
|
591
|
+
var ChargesQueryFieldSchema = import_zod11.z.enum(["status", "source", "apiKeyId", "currency", "isOverpaid", "externalRef"]).describe(
|
|
521
592
|
"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."
|
|
522
593
|
);
|
|
523
|
-
var ChargesMetricFieldSchema =
|
|
594
|
+
var ChargesMetricFieldSchema = import_zod11.z.enum(["amount", "amountReceived", "feePercent"]).describe(
|
|
524
595
|
"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%."
|
|
525
596
|
);
|
|
526
|
-
var ChargesDateFieldSchema =
|
|
597
|
+
var ChargesDateFieldSchema = import_zod11.z.enum(["createdAt", "confirmedAt", "lastActivityAt", "expiresAt"]).describe(
|
|
527
598
|
"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."
|
|
528
599
|
);
|
|
529
|
-
var ChargesFilterSchema =
|
|
600
|
+
var ChargesFilterSchema = import_zod11.z.object({
|
|
530
601
|
field: ChargesQueryFieldSchema,
|
|
531
602
|
operator: MetricsFilterOperatorSchema,
|
|
532
603
|
value: MetricsFilterValueSchema
|
|
533
604
|
});
|
|
534
|
-
var ChargesGroupBySchema =
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
type:
|
|
605
|
+
var ChargesGroupBySchema = import_zod11.z.union([
|
|
606
|
+
import_zod11.z.object({ type: import_zod11.z.literal("field"), field: ChargesQueryFieldSchema }),
|
|
607
|
+
import_zod11.z.object({
|
|
608
|
+
type: import_zod11.z.literal("date_bucket"),
|
|
538
609
|
field: ChargesDateFieldSchema,
|
|
539
610
|
granularity: MetricsDateGranularitySchema
|
|
540
611
|
})
|
|
541
612
|
]);
|
|
542
|
-
var ChargesMetricSchema =
|
|
613
|
+
var ChargesMetricSchema = import_zod11.z.object({
|
|
543
614
|
aggregation: MetricsAggregationSchema,
|
|
544
615
|
field: ChargesMetricFieldSchema.optional(),
|
|
545
616
|
alias: metricAliasSchema
|
|
546
617
|
});
|
|
547
|
-
var ChargesMetricsQuerySchema =
|
|
548
|
-
resource:
|
|
618
|
+
var ChargesMetricsQuerySchema = import_zod11.z.object({
|
|
619
|
+
resource: import_zod11.z.literal("charges"),
|
|
549
620
|
environment: metricsQueryEnvironmentSchema,
|
|
550
|
-
dateRange:
|
|
621
|
+
dateRange: import_zod11.z.object({
|
|
551
622
|
field: ChargesDateFieldSchema,
|
|
552
|
-
from:
|
|
553
|
-
to:
|
|
623
|
+
from: import_zod11.z.string().max(64).datetime(),
|
|
624
|
+
to: import_zod11.z.string().max(64).datetime()
|
|
554
625
|
}),
|
|
555
|
-
groupBy:
|
|
556
|
-
metrics:
|
|
557
|
-
filters:
|
|
626
|
+
groupBy: import_zod11.z.array(ChargesGroupBySchema).max(METRICS_QUERY_MAX_GROUP_BY).default([]),
|
|
627
|
+
metrics: import_zod11.z.array(ChargesMetricSchema).min(1).max(METRICS_QUERY_MAX_METRICS),
|
|
628
|
+
filters: import_zod11.z.array(ChargesFilterSchema).max(METRICS_QUERY_MAX_FILTERS).default([]),
|
|
558
629
|
orderBy: orderBySchema.optional(),
|
|
559
630
|
limit: limitSchema
|
|
560
631
|
});
|
|
561
|
-
var TransactionsQueryFieldSchema =
|
|
632
|
+
var TransactionsQueryFieldSchema = import_zod11.z.enum(["network", "token", "source", "causedTransition"]).describe(
|
|
562
633
|
"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)."
|
|
563
634
|
);
|
|
564
|
-
var TransactionsMetricFieldSchema =
|
|
565
|
-
var TransactionsDateFieldSchema =
|
|
566
|
-
var TransactionsFilterSchema =
|
|
635
|
+
var TransactionsMetricFieldSchema = import_zod11.z.enum(["amount"]).describe("The transfer amount, in the charge's `currency` units.");
|
|
636
|
+
var TransactionsDateFieldSchema = import_zod11.z.enum(["detectedAt"]).describe("When Klappay detected this transfer on-chain (not when it was mined).");
|
|
637
|
+
var TransactionsFilterSchema = import_zod11.z.object({
|
|
567
638
|
field: TransactionsQueryFieldSchema,
|
|
568
639
|
operator: MetricsFilterOperatorSchema,
|
|
569
640
|
value: MetricsFilterValueSchema
|
|
570
641
|
});
|
|
571
|
-
var TransactionsGroupBySchema =
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
type:
|
|
642
|
+
var TransactionsGroupBySchema = import_zod11.z.union([
|
|
643
|
+
import_zod11.z.object({ type: import_zod11.z.literal("field"), field: TransactionsQueryFieldSchema }),
|
|
644
|
+
import_zod11.z.object({
|
|
645
|
+
type: import_zod11.z.literal("date_bucket"),
|
|
575
646
|
field: TransactionsDateFieldSchema,
|
|
576
647
|
granularity: MetricsDateGranularitySchema
|
|
577
648
|
})
|
|
578
649
|
]);
|
|
579
|
-
var TransactionsMetricSchema =
|
|
650
|
+
var TransactionsMetricSchema = import_zod11.z.object({
|
|
580
651
|
aggregation: MetricsAggregationSchema,
|
|
581
652
|
field: TransactionsMetricFieldSchema.optional(),
|
|
582
653
|
alias: metricAliasSchema
|
|
583
654
|
});
|
|
584
|
-
var TransactionsMetricsQuerySchema =
|
|
585
|
-
resource:
|
|
655
|
+
var TransactionsMetricsQuerySchema = import_zod11.z.object({
|
|
656
|
+
resource: import_zod11.z.literal("transactions"),
|
|
586
657
|
environment: metricsQueryEnvironmentSchema,
|
|
587
|
-
dateRange:
|
|
658
|
+
dateRange: import_zod11.z.object({
|
|
588
659
|
field: TransactionsDateFieldSchema,
|
|
589
|
-
from:
|
|
590
|
-
to:
|
|
660
|
+
from: import_zod11.z.string().max(64).datetime(),
|
|
661
|
+
to: import_zod11.z.string().max(64).datetime()
|
|
591
662
|
}),
|
|
592
|
-
groupBy:
|
|
593
|
-
metrics:
|
|
594
|
-
filters:
|
|
663
|
+
groupBy: import_zod11.z.array(TransactionsGroupBySchema).max(METRICS_QUERY_MAX_GROUP_BY).default([]),
|
|
664
|
+
metrics: import_zod11.z.array(TransactionsMetricSchema).min(1).max(METRICS_QUERY_MAX_METRICS),
|
|
665
|
+
filters: import_zod11.z.array(TransactionsFilterSchema).max(METRICS_QUERY_MAX_FILTERS).default([]),
|
|
595
666
|
orderBy: orderBySchema.optional(),
|
|
596
667
|
limit: limitSchema
|
|
597
668
|
});
|
|
598
|
-
var DistributionsQueryFieldSchema =
|
|
669
|
+
var DistributionsQueryFieldSchema = import_zod11.z.enum(["status", "network", "token", "distributorAddress"]).describe(
|
|
599
670
|
"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."
|
|
600
671
|
);
|
|
601
|
-
var DistributionsMetricFieldSchema =
|
|
672
|
+
var DistributionsMetricFieldSchema = import_zod11.z.enum(["attempts"]).describe(
|
|
602
673
|
"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."
|
|
603
674
|
);
|
|
604
|
-
var DistributionsDateFieldSchema =
|
|
675
|
+
var DistributionsDateFieldSchema = import_zod11.z.enum(["createdAt", "processingStartedAt", "completedAt"]).describe(
|
|
605
676
|
"`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."
|
|
606
677
|
);
|
|
607
|
-
var DistributionsFilterSchema =
|
|
678
|
+
var DistributionsFilterSchema = import_zod11.z.object({
|
|
608
679
|
field: DistributionsQueryFieldSchema,
|
|
609
680
|
operator: MetricsFilterOperatorSchema,
|
|
610
681
|
value: MetricsFilterValueSchema
|
|
611
682
|
});
|
|
612
|
-
var DistributionsGroupBySchema =
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
type:
|
|
683
|
+
var DistributionsGroupBySchema = import_zod11.z.union([
|
|
684
|
+
import_zod11.z.object({ type: import_zod11.z.literal("field"), field: DistributionsQueryFieldSchema }),
|
|
685
|
+
import_zod11.z.object({
|
|
686
|
+
type: import_zod11.z.literal("date_bucket"),
|
|
616
687
|
field: DistributionsDateFieldSchema,
|
|
617
688
|
granularity: MetricsDateGranularitySchema
|
|
618
689
|
})
|
|
619
690
|
]);
|
|
620
|
-
var DistributionsMetricSchema =
|
|
691
|
+
var DistributionsMetricSchema = import_zod11.z.object({
|
|
621
692
|
aggregation: MetricsAggregationSchema,
|
|
622
693
|
field: DistributionsMetricFieldSchema.optional(),
|
|
623
694
|
alias: metricAliasSchema
|
|
624
695
|
});
|
|
625
|
-
var DistributionsMetricsQuerySchema =
|
|
626
|
-
resource:
|
|
696
|
+
var DistributionsMetricsQuerySchema = import_zod11.z.object({
|
|
697
|
+
resource: import_zod11.z.literal("distributions"),
|
|
627
698
|
environment: metricsQueryEnvironmentSchema,
|
|
628
|
-
dateRange:
|
|
699
|
+
dateRange: import_zod11.z.object({
|
|
629
700
|
field: DistributionsDateFieldSchema,
|
|
630
|
-
from:
|
|
631
|
-
to:
|
|
701
|
+
from: import_zod11.z.string().max(64).datetime(),
|
|
702
|
+
to: import_zod11.z.string().max(64).datetime()
|
|
632
703
|
}),
|
|
633
|
-
groupBy:
|
|
634
|
-
metrics:
|
|
635
|
-
filters:
|
|
704
|
+
groupBy: import_zod11.z.array(DistributionsGroupBySchema).max(METRICS_QUERY_MAX_GROUP_BY).default([]),
|
|
705
|
+
metrics: import_zod11.z.array(DistributionsMetricSchema).min(1).max(METRICS_QUERY_MAX_METRICS),
|
|
706
|
+
filters: import_zod11.z.array(DistributionsFilterSchema).max(METRICS_QUERY_MAX_FILTERS).default([]),
|
|
636
707
|
orderBy: orderBySchema.optional(),
|
|
637
708
|
limit: limitSchema
|
|
638
709
|
});
|
|
639
710
|
var ONE_DAY_MS = 24 * 60 * 60 * 1e3;
|
|
640
|
-
var MetricsQuerySchema =
|
|
711
|
+
var MetricsQuerySchema = import_zod11.z.discriminatedUnion("resource", [
|
|
641
712
|
ChargesMetricsQuerySchema,
|
|
642
713
|
TransactionsMetricsQuerySchema,
|
|
643
714
|
DistributionsMetricsQuerySchema
|
|
@@ -646,7 +717,7 @@ var MetricsQuerySchema = import_zod10.z.discriminatedUnion("resource", [
|
|
|
646
717
|
const to = new Date(input.dateRange.to);
|
|
647
718
|
if (from >= to) {
|
|
648
719
|
ctx.addIssue({
|
|
649
|
-
code:
|
|
720
|
+
code: import_zod11.z.ZodIssueCode.custom,
|
|
650
721
|
message: "`dateRange.from` must be before `dateRange.to`.",
|
|
651
722
|
path: ["dateRange", "from"]
|
|
652
723
|
});
|
|
@@ -654,7 +725,7 @@ var MetricsQuerySchema = import_zod10.z.discriminatedUnion("resource", [
|
|
|
654
725
|
const spanDays = (to.getTime() - from.getTime()) / ONE_DAY_MS;
|
|
655
726
|
if (spanDays > MAX_METRICS_QUERY_DATE_RANGE_DAYS) {
|
|
656
727
|
ctx.addIssue({
|
|
657
|
-
code:
|
|
728
|
+
code: import_zod11.z.ZodIssueCode.custom,
|
|
658
729
|
message: `\`dateRange\` cannot span more than ${MAX_METRICS_QUERY_DATE_RANGE_DAYS} days.`,
|
|
659
730
|
path: ["dateRange", "to"]
|
|
660
731
|
});
|
|
@@ -662,7 +733,7 @@ var MetricsQuerySchema = import_zod10.z.discriminatedUnion("resource", [
|
|
|
662
733
|
const dateBucketCount = input.groupBy.filter((entry) => entry.type === "date_bucket").length;
|
|
663
734
|
if (dateBucketCount > 1) {
|
|
664
735
|
ctx.addIssue({
|
|
665
|
-
code:
|
|
736
|
+
code: import_zod11.z.ZodIssueCode.custom,
|
|
666
737
|
message: "At most one `date_bucket` entry is allowed in `groupBy`.",
|
|
667
738
|
path: ["groupBy"]
|
|
668
739
|
});
|
|
@@ -670,7 +741,7 @@ var MetricsQuerySchema = import_zod10.z.discriminatedUnion("resource", [
|
|
|
670
741
|
input.metrics.forEach((metric, index) => {
|
|
671
742
|
if (metric.aggregation !== "count" && metric.field === void 0) {
|
|
672
743
|
ctx.addIssue({
|
|
673
|
-
code:
|
|
744
|
+
code: import_zod11.z.ZodIssueCode.custom,
|
|
674
745
|
message: "`field` is required unless `aggregation` is `count`.",
|
|
675
746
|
path: ["metrics", index, "field"]
|
|
676
747
|
});
|
|
@@ -679,7 +750,7 @@ var MetricsQuerySchema = import_zod10.z.discriminatedUnion("resource", [
|
|
|
679
750
|
const aliases = input.metrics.map((metric) => metric.alias).filter((alias) => alias !== void 0);
|
|
680
751
|
if (new Set(aliases).size !== aliases.length) {
|
|
681
752
|
ctx.addIssue({
|
|
682
|
-
code:
|
|
753
|
+
code: import_zod11.z.ZodIssueCode.custom,
|
|
683
754
|
message: "Every `metrics[].alias` must be unique.",
|
|
684
755
|
path: ["metrics"]
|
|
685
756
|
});
|
|
@@ -688,32 +759,32 @@ var MetricsQuerySchema = import_zod10.z.discriminatedUnion("resource", [
|
|
|
688
759
|
input.metrics.forEach((metric, index) => {
|
|
689
760
|
if (metric.alias !== void 0 && reservedNames.has(metric.alias)) {
|
|
690
761
|
ctx.addIssue({
|
|
691
|
-
code:
|
|
762
|
+
code: import_zod11.z.ZodIssueCode.custom,
|
|
692
763
|
message: `\`alias\` "${metric.alias}" collides with a \`groupBy\` field name (or the reserved word "bucket") \u2014 choose a different alias.`,
|
|
693
764
|
path: ["metrics", index, "alias"]
|
|
694
765
|
});
|
|
695
766
|
}
|
|
696
767
|
});
|
|
697
768
|
});
|
|
698
|
-
var MetricsQueryResultRowSchema =
|
|
699
|
-
|
|
700
|
-
|
|
769
|
+
var MetricsQueryResultRowSchema = import_zod11.z.record(
|
|
770
|
+
import_zod11.z.string(),
|
|
771
|
+
import_zod11.z.union([import_zod11.z.string(), import_zod11.z.number(), import_zod11.z.boolean(), import_zod11.z.null()])
|
|
701
772
|
);
|
|
702
|
-
var MetricsQueryResultSchema =
|
|
703
|
-
data:
|
|
704
|
-
meta:
|
|
773
|
+
var MetricsQueryResultSchema = import_zod11.z.object({
|
|
774
|
+
data: import_zod11.z.array(MetricsQueryResultRowSchema),
|
|
775
|
+
meta: import_zod11.z.object({
|
|
705
776
|
resource: MetricsResourceSchema,
|
|
706
777
|
environment: EnvironmentSchema,
|
|
707
|
-
rowCount:
|
|
708
|
-
truncated:
|
|
778
|
+
rowCount: import_zod11.z.number().int().describe("Number of rows in `data`."),
|
|
779
|
+
truncated: import_zod11.z.boolean().describe(
|
|
709
780
|
"`true` if more rows matched than `limit` allowed \u2014 `data` holds only the first `limit`."
|
|
710
781
|
)
|
|
711
782
|
})
|
|
712
783
|
});
|
|
713
784
|
|
|
714
785
|
// src/webhook-events.ts
|
|
715
|
-
var
|
|
716
|
-
var ChargeWebhookEventTypeSchema =
|
|
786
|
+
var import_zod12 = require("zod");
|
|
787
|
+
var ChargeWebhookEventTypeSchema = import_zod12.z.enum([
|
|
717
788
|
"charge.created",
|
|
718
789
|
"charge.partially_paid",
|
|
719
790
|
"charge.confirmed",
|
|
@@ -725,14 +796,14 @@ var ChargeWebhookEventTypeSchema = import_zod11.z.enum([
|
|
|
725
796
|
]).describe(
|
|
726
797
|
'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`.'
|
|
727
798
|
);
|
|
728
|
-
var WebhookDeliveryEventTypeSchema =
|
|
799
|
+
var WebhookDeliveryEventTypeSchema = import_zod12.z.enum(["webhook.delivery_failed", "webhook.delivery_recovered", "webhook.endpoint_unhealthy"]).describe(
|
|
729
800
|
"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`)."
|
|
730
801
|
);
|
|
731
|
-
var WebhookEventTypeSchema =
|
|
802
|
+
var WebhookEventTypeSchema = import_zod12.z.union([
|
|
732
803
|
ChargeWebhookEventTypeSchema,
|
|
733
804
|
WebhookDeliveryEventTypeSchema
|
|
734
805
|
]);
|
|
735
|
-
var WebhookCategorySchema =
|
|
806
|
+
var WebhookCategorySchema = import_zod12.z.enum(["payments", "webhooks"]).describe(
|
|
736
807
|
"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."
|
|
737
808
|
);
|
|
738
809
|
function buildCategoryMap() {
|
|
@@ -760,78 +831,101 @@ var TriggerableChargeEventSchema = ChargeWebhookEventTypeSchema.exclude([
|
|
|
760
831
|
);
|
|
761
832
|
|
|
762
833
|
// src/webhooks.ts
|
|
763
|
-
var
|
|
834
|
+
var import_zod13 = require("zod");
|
|
764
835
|
var WEBHOOK_EVENTS_WILDCARD = "*";
|
|
765
|
-
var CreateWebhookSchema =
|
|
766
|
-
url:
|
|
836
|
+
var CreateWebhookSchema = import_zod13.z.object({
|
|
837
|
+
url: import_zod13.z.string().max(2048).url().describe(
|
|
767
838
|
"Must be HTTPS and resolve to a public address \u2014 private/internal IPs are rejected."
|
|
768
839
|
),
|
|
769
|
-
events:
|
|
840
|
+
events: import_zod13.z.array(import_zod13.z.union([WebhookEventTypeSchema, import_zod13.z.literal(WEBHOOK_EVENTS_WILDCARD)])).max(Object.keys(EVENT_CATEGORY_MAP).length + 1).default([]).describe(
|
|
770
841
|
'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.'
|
|
771
842
|
),
|
|
772
|
-
eventCategories:
|
|
843
|
+
eventCategories: import_zod13.z.array(WebhookCategorySchema).max(WebhookCategorySchema.options.length).default([]).describe(
|
|
773
844
|
"Subscribe to every event in these categories. At least one of `events` or `eventCategories` is required."
|
|
774
845
|
),
|
|
775
|
-
excludeEvents:
|
|
846
|
+
excludeEvents: import_zod13.z.array(WebhookEventTypeSchema).max(Object.keys(EVENT_CATEGORY_MAP).length).default([]).describe(
|
|
776
847
|
'Event types to exclude even if selected via `events: ["*"]` or `eventCategories`.'
|
|
777
848
|
)
|
|
778
849
|
}).refine((v) => v.events.length > 0 || v.eventCategories.length > 0, {
|
|
779
850
|
message: "must select at least one event via `events` or `eventCategories`",
|
|
780
851
|
path: ["events"]
|
|
781
852
|
});
|
|
782
|
-
var WebhookSchema =
|
|
783
|
-
id:
|
|
853
|
+
var WebhookSchema = import_zod13.z.object({
|
|
854
|
+
id: import_zod13.z.string(),
|
|
784
855
|
environment: EnvironmentSchema.nullable().describe(
|
|
785
856
|
"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)."
|
|
786
857
|
),
|
|
787
|
-
url:
|
|
788
|
-
events:
|
|
789
|
-
eventCategories:
|
|
790
|
-
excludeEvents:
|
|
791
|
-
isWildcard:
|
|
792
|
-
secret:
|
|
858
|
+
url: import_zod13.z.string(),
|
|
859
|
+
events: import_zod13.z.array(WebhookEventTypeSchema),
|
|
860
|
+
eventCategories: import_zod13.z.array(WebhookCategorySchema),
|
|
861
|
+
excludeEvents: import_zod13.z.array(WebhookEventTypeSchema),
|
|
862
|
+
isWildcard: import_zod13.z.boolean(),
|
|
863
|
+
secret: import_zod13.z.string().describe(
|
|
793
864
|
"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."
|
|
794
865
|
),
|
|
795
|
-
createdAt:
|
|
866
|
+
createdAt: import_zod13.z.string().datetime()
|
|
796
867
|
});
|
|
797
868
|
var WebhookListItemSchema = WebhookSchema.omit({ secret: true }).extend({
|
|
798
|
-
hint:
|
|
869
|
+
hint: import_zod13.z.string().describe("A truncated, safe-to-display form of the secret (e.g. `whsec_...ab12`).")
|
|
799
870
|
});
|
|
800
|
-
var WebhookPayloadSchema =
|
|
801
|
-
id:
|
|
871
|
+
var WebhookPayloadSchema = import_zod13.z.object({
|
|
872
|
+
id: import_zod13.z.string().describe(
|
|
802
873
|
"Unique id for this specific delivery \u2014 also sent as the `X-Klappay-Delivery` header."
|
|
803
874
|
),
|
|
804
875
|
event: WebhookEventTypeSchema,
|
|
805
|
-
createdAt:
|
|
806
|
-
data:
|
|
876
|
+
createdAt: import_zod13.z.string().datetime(),
|
|
877
|
+
data: import_zod13.z.unknown().describe(
|
|
807
878
|
"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."
|
|
808
879
|
)
|
|
809
880
|
});
|
|
810
|
-
var WebhookDeliveryStatusSchema =
|
|
811
|
-
var WebhookDeliverySchema =
|
|
812
|
-
id:
|
|
813
|
-
webhookId:
|
|
881
|
+
var WebhookDeliveryStatusSchema = import_zod13.z.enum(["pending", "delivered", "failed"]);
|
|
882
|
+
var WebhookDeliverySchema = import_zod13.z.object({
|
|
883
|
+
id: import_zod13.z.string(),
|
|
884
|
+
webhookId: import_zod13.z.string(),
|
|
814
885
|
event: WebhookEventTypeSchema,
|
|
815
886
|
status: WebhookDeliveryStatusSchema.describe(
|
|
816
887
|
"`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."
|
|
817
888
|
),
|
|
818
|
-
attempts:
|
|
819
|
-
responseCode:
|
|
889
|
+
attempts: import_zod13.z.number(),
|
|
890
|
+
responseCode: import_zod13.z.number().nullable().describe(
|
|
820
891
|
"HTTP status your endpoint returned on the most recent attempt. `null` if every attempt failed to connect at all."
|
|
821
892
|
),
|
|
822
|
-
nextRetryAt:
|
|
823
|
-
deliveredAt:
|
|
824
|
-
createdAt:
|
|
893
|
+
nextRetryAt: import_zod13.z.string().datetime().nullable(),
|
|
894
|
+
deliveredAt: import_zod13.z.string().datetime().nullable(),
|
|
895
|
+
createdAt: import_zod13.z.string().datetime()
|
|
825
896
|
});
|
|
826
897
|
var ListWebhookDeliveriesSchema = PaginationQuerySchema;
|
|
827
898
|
var PaginatedWebhookDeliveriesSchema = paginatedSchema(WebhookDeliverySchema);
|
|
828
899
|
|
|
900
|
+
// src/recipients.ts
|
|
901
|
+
var import_zod14 = require("zod");
|
|
902
|
+
var EVM_ADDRESS_REGEX = /^0x[0-9a-fA-F]{40}$/;
|
|
903
|
+
var CreateRecipientSchema = import_zod14.z.object({
|
|
904
|
+
address: import_zod14.z.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."),
|
|
905
|
+
label: import_zod14.z.string().min(1).max(64).optional().describe('Free-form label for your own bookkeeping (e.g. `"supplier"`) \u2014 never interpreted.')
|
|
906
|
+
});
|
|
907
|
+
var RecipientSchema = import_zod14.z.object({
|
|
908
|
+
id: import_zod14.z.string().describe(
|
|
909
|
+
"Klappay-generated id, e.g. `rc_...` \u2014 this, not the raw address, is what a charge's `splitRecipients[].recipientId` references."
|
|
910
|
+
),
|
|
911
|
+
environment: EnvironmentSchema,
|
|
912
|
+
address: import_zod14.z.string(),
|
|
913
|
+
label: import_zod14.z.string().nullable(),
|
|
914
|
+
payout: import_zod14.z.boolean().describe(
|
|
915
|
+
"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`."
|
|
916
|
+
),
|
|
917
|
+
createdAt: import_zod14.z.string().datetime()
|
|
918
|
+
});
|
|
919
|
+
var SetRecipientPayoutSchema = import_zod14.z.object({
|
|
920
|
+
payout: import_zod14.z.boolean().describe("New payout-eligibility value for this recipient.")
|
|
921
|
+
});
|
|
922
|
+
|
|
829
923
|
// src/timeline.ts
|
|
830
|
-
var
|
|
831
|
-
var TransactionSourceSchema =
|
|
924
|
+
var import_zod15 = require("zod");
|
|
925
|
+
var TransactionSourceSchema = import_zod15.z.enum(["moralis_webhook", "reconciliation_job", "sandbox"]).describe(
|
|
832
926
|
"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)."
|
|
833
927
|
);
|
|
834
|
-
var TimelineEventTypeSchema =
|
|
928
|
+
var TimelineEventTypeSchema = import_zod15.z.enum([
|
|
835
929
|
"charge.created",
|
|
836
930
|
"charge.expired",
|
|
837
931
|
"transaction.detected",
|
|
@@ -842,11 +936,11 @@ var TimelineEventTypeSchema = import_zod13.z.enum([
|
|
|
842
936
|
]).describe(
|
|
843
937
|
"`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)."
|
|
844
938
|
);
|
|
845
|
-
var TimelineEventSchema =
|
|
939
|
+
var TimelineEventSchema = import_zod15.z.object({
|
|
846
940
|
type: TimelineEventTypeSchema,
|
|
847
|
-
at:
|
|
848
|
-
txHash:
|
|
849
|
-
amount:
|
|
941
|
+
at: import_zod15.z.string().datetime(),
|
|
942
|
+
txHash: import_zod15.z.string().optional().describe("Present for `transaction.detected` and `split.distributed` events only."),
|
|
943
|
+
amount: import_zod15.z.number().optional().describe(
|
|
850
944
|
"Present for `transaction.detected` events only \u2014 the amount that specific transfer carried."
|
|
851
945
|
),
|
|
852
946
|
source: TransactionSourceSchema.optional().describe(
|
|
@@ -858,56 +952,112 @@ var TimelineEventSchema = import_zod13.z.object({
|
|
|
858
952
|
network: NetworkSchema.optional().describe(
|
|
859
953
|
"Present for `transaction.detected` and `split.distributed` events \u2014 which network this specific transfer, or settlement, used."
|
|
860
954
|
),
|
|
861
|
-
causedTransition:
|
|
955
|
+
causedTransition: import_zod15.z.boolean().optional().describe(
|
|
862
956
|
"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."
|
|
863
957
|
),
|
|
864
958
|
event: WebhookEventTypeSchema.optional().describe(
|
|
865
959
|
"Present for `webhook.*` events only \u2014 which event type this delivery was for."
|
|
866
960
|
),
|
|
867
|
-
responseCode:
|
|
961
|
+
responseCode: import_zod15.z.number().nullable().optional().describe(
|
|
868
962
|
"Present for `webhook.*` events only \u2014 HTTP status your endpoint returned, or `null` if the request never connected."
|
|
869
963
|
),
|
|
870
|
-
attempts:
|
|
964
|
+
attempts: import_zod15.z.number().optional().describe(
|
|
871
965
|
"Present for `webhook.*` events only \u2014 how many delivery attempts have been made so far."
|
|
872
966
|
)
|
|
873
967
|
});
|
|
874
968
|
|
|
875
969
|
// src/health.ts
|
|
876
|
-
var
|
|
877
|
-
var HealthSchema =
|
|
878
|
-
status:
|
|
970
|
+
var import_zod16 = require("zod");
|
|
971
|
+
var HealthSchema = import_zod16.z.object({
|
|
972
|
+
status: import_zod16.z.enum(["ok", "error"]).describe(
|
|
879
973
|
"`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."
|
|
880
974
|
),
|
|
881
|
-
version:
|
|
882
|
-
timestamp:
|
|
883
|
-
db:
|
|
884
|
-
pendingWebhooks:
|
|
885
|
-
oldestPendingChargeAgeSeconds:
|
|
886
|
-
lastMoralisEventAgeSeconds:
|
|
975
|
+
version: import_zod16.z.string(),
|
|
976
|
+
timestamp: import_zod16.z.string().datetime(),
|
|
977
|
+
db: import_zod16.z.enum(["ok", "error"]).describe("Result of a real database connectivity check, not just a process-alive check."),
|
|
978
|
+
pendingWebhooks: import_zod16.z.number().describe("Count of webhook deliveries still awaiting a successful attempt."),
|
|
979
|
+
oldestPendingChargeAgeSeconds: import_zod16.z.number().nullable().describe("Age of the oldest still-unpaid charge, in seconds. `null` if there are none."),
|
|
980
|
+
lastMoralisEventAgeSeconds: import_zod16.z.number().nullable().describe(
|
|
887
981
|
"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."
|
|
888
982
|
)
|
|
889
983
|
});
|
|
890
984
|
|
|
891
985
|
// src/sandbox.ts
|
|
892
|
-
var
|
|
893
|
-
var SandboxTriggerSchema =
|
|
986
|
+
var import_zod17 = require("zod");
|
|
987
|
+
var SandboxTriggerSchema = import_zod17.z.object({
|
|
894
988
|
event: TriggerableChargeEventSchema,
|
|
895
|
-
amount:
|
|
989
|
+
amount: import_zod17.z.number().positive().max(CHARGE_AMOUNT_MAX).optional().describe(
|
|
896
990
|
"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."
|
|
897
991
|
)
|
|
898
992
|
});
|
|
899
993
|
|
|
900
994
|
// src/capabilities.ts
|
|
901
|
-
var
|
|
902
|
-
var CapabilitiesSchema =
|
|
903
|
-
acceptedPayments:
|
|
995
|
+
var import_zod18 = require("zod");
|
|
996
|
+
var CapabilitiesSchema = import_zod18.z.object({
|
|
997
|
+
acceptedPayments: import_zod18.z.array(AcceptedPaymentSchema).describe(
|
|
904
998
|
"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."
|
|
905
999
|
)
|
|
906
1000
|
});
|
|
1001
|
+
|
|
1002
|
+
// src/swap.ts
|
|
1003
|
+
var import_zod19 = require("zod");
|
|
1004
|
+
var CreateSwapQuoteSchema = import_zod19.z.object({
|
|
1005
|
+
inputToken: AltTokenSchema.describe(
|
|
1006
|
+
"Which alt-cryptocurrency the payer wants to send \u2014 must be one of this charge's `swapAlternatives`, or `422 token_not_supported`."
|
|
1007
|
+
),
|
|
1008
|
+
inputNetwork: NetworkSchema.describe(
|
|
1009
|
+
"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."
|
|
1010
|
+
),
|
|
1011
|
+
takerAddress: import_zod19.z.string().regex(/^0x[0-9a-fA-F]{40}$/, "must be a 20-byte hex address").describe(
|
|
1012
|
+
"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."
|
|
1013
|
+
)
|
|
1014
|
+
});
|
|
1015
|
+
var SwapQuoteSchema = import_zod19.z.object({
|
|
1016
|
+
inputToken: AltTokenSchema,
|
|
1017
|
+
inputNetwork: NetworkSchema,
|
|
1018
|
+
inputAmount: import_zod19.z.number().describe(
|
|
1019
|
+
"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."
|
|
1020
|
+
),
|
|
1021
|
+
outputToken: TokenSchema.describe(
|
|
1022
|
+
"Which of this charge's `acceptedPayments` tokens the swap resolves to."
|
|
1023
|
+
),
|
|
1024
|
+
outputNetwork: NetworkSchema,
|
|
1025
|
+
outputAmount: import_zod19.z.number().describe(
|
|
1026
|
+
"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`."
|
|
1027
|
+
),
|
|
1028
|
+
fees: import_zod19.z.object({
|
|
1029
|
+
klappayFee: import_zod19.z.number().describe(
|
|
1030
|
+
"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`."
|
|
1031
|
+
),
|
|
1032
|
+
zeroExFee: import_zod19.z.number().nullable().describe(
|
|
1033
|
+
"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."
|
|
1034
|
+
)
|
|
1035
|
+
}).describe(
|
|
1036
|
+
"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`."
|
|
1037
|
+
),
|
|
1038
|
+
expiresAt: import_zod19.z.string().datetime().describe(
|
|
1039
|
+
"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."
|
|
1040
|
+
),
|
|
1041
|
+
transaction: import_zod19.z.object({
|
|
1042
|
+
to: import_zod19.z.string().describe("Contract address the payer's wallet must send this transaction to."),
|
|
1043
|
+
data: import_zod19.z.string().describe("Calldata \u2014 opaque, must be sent unmodified."),
|
|
1044
|
+
value: import_zod19.z.string().describe(
|
|
1045
|
+
"Native currency (ETH/BNB/MATIC/AVAX) to attach, in wei \u2014 `\"0\"` when `inputToken` isn't this network's native currency."
|
|
1046
|
+
)
|
|
1047
|
+
}).describe(
|
|
1048
|
+
"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."
|
|
1049
|
+
),
|
|
1050
|
+
permit2: import_zod19.z.object({ eip712: import_zod19.z.record(import_zod19.z.unknown()) }).optional().describe(
|
|
1051
|
+
"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. Absent 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."
|
|
1052
|
+
)
|
|
1053
|
+
});
|
|
907
1054
|
// Annotate the CommonJS export names for ESM import in node:
|
|
908
1055
|
0 && (module.exports = {
|
|
1056
|
+
ALT_TOKEN_ADDRESSES,
|
|
1057
|
+
ALT_TOKEN_DECIMALS,
|
|
909
1058
|
API_KEY_SCOPES,
|
|
910
1059
|
AcceptedPaymentSchema,
|
|
1060
|
+
AltTokenSchema,
|
|
911
1061
|
ApiKeyScopeSchema,
|
|
912
1062
|
CHARGE_ACCEPTED_PAYMENTS_MAX,
|
|
913
1063
|
CHARGE_AMOUNT_MAX,
|
|
@@ -915,6 +1065,7 @@ var CapabilitiesSchema = import_zod16.z.object({
|
|
|
915
1065
|
CHARGE_EXPIRES_IN_MIN_SECONDS,
|
|
916
1066
|
CHARGE_SPLIT_RECIPIENTS_MAX,
|
|
917
1067
|
CHECKOUT_PRODUCTS_MAX,
|
|
1068
|
+
CONFLICTING_SCOPE_PAIRS,
|
|
918
1069
|
CapabilitiesSchema,
|
|
919
1070
|
ChargeSchema,
|
|
920
1071
|
ChargeStatusSchema,
|
|
@@ -924,6 +1075,8 @@ var CapabilitiesSchema = import_zod16.z.object({
|
|
|
924
1075
|
ChargesQueryFieldSchema,
|
|
925
1076
|
CheckoutProductSchema,
|
|
926
1077
|
CreateChargeSchema,
|
|
1078
|
+
CreateRecipientSchema,
|
|
1079
|
+
CreateSwapQuoteSchema,
|
|
927
1080
|
CreateWebhookSchema,
|
|
928
1081
|
DistributionsDateFieldSchema,
|
|
929
1082
|
DistributionsMetricFieldSchema,
|
|
@@ -966,10 +1119,14 @@ var CapabilitiesSchema = import_zod16.z.object({
|
|
|
966
1119
|
PendingDistributionEventSchema,
|
|
967
1120
|
PendingDistributionRecipientSchema,
|
|
968
1121
|
PendingDistributionSchema,
|
|
1122
|
+
RecipientSchema,
|
|
969
1123
|
SandboxTriggerSchema,
|
|
1124
|
+
SetRecipientPayoutSchema,
|
|
970
1125
|
SettlementStatusSchema,
|
|
971
1126
|
SplitDistributionStatusSchema,
|
|
1127
|
+
SplitRecipientInputSchema,
|
|
972
1128
|
SplitRecipientSchema,
|
|
1129
|
+
SwapQuoteSchema,
|
|
973
1130
|
TOKEN_ADDRESSES,
|
|
974
1131
|
TOKEN_DECIMALS,
|
|
975
1132
|
TimelineEventSchema,
|
|
@@ -990,6 +1147,8 @@ var CapabilitiesSchema = import_zod16.z.object({
|
|
|
990
1147
|
WebhookListItemSchema,
|
|
991
1148
|
WebhookPayloadSchema,
|
|
992
1149
|
WebhookSchema,
|
|
1150
|
+
findConflictingScopes,
|
|
1151
|
+
listAltTokensForNetworks,
|
|
993
1152
|
paginatedSchema
|
|
994
1153
|
});
|
|
995
1154
|
//# sourceMappingURL=index.js.map
|