@klappay/types 1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Klappay
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,120 @@
1
+ <img src="./logo.png" alt="Klap" width="80" />
2
+
3
+ # @klappay/types
4
+
5
+ TypeScript types and [Zod](https://zod.dev) schemas for the Klap Core
6
+ API — the request/response contracts for creating charges, managing
7
+ webhooks, and everything else the API exposes. Published separately from
8
+ the API implementation itself (which is closed-source) so integrators get
9
+ accurate, versioned types without needing access to Klap's own codebase.
10
+
11
+ Klap is a non-custodial crypto payments API — a merchant creates a
12
+ charge, Klap predicts a deterministic on-chain address for it, the payer
13
+ sends funds directly to that address, and Klap detects and distributes the
14
+ payment without ever holding the funds itself.
15
+
16
+ ## Install
17
+
18
+ ```bash
19
+ npm install @klappay/types zod
20
+ ```
21
+
22
+ `zod` is a peer expectation — every schema here is a `zod` schema, so you
23
+ already have it if you use any of them directly.
24
+
25
+ ## What's in here
26
+
27
+ - **Zod schemas** for every request/response body (e.g. `ChargeSchema`,
28
+ `CreateChargeSchema`, `WebhookPayloadSchema`) — use these to validate
29
+ data at runtime, not just for compile-time types.
30
+ - **Inferred TypeScript types** for the same shapes (e.g. `Charge`,
31
+ `CreateChargeInput`), exported alongside each schema.
32
+ - **Shared enums** used across multiple endpoints (`Network`, `Token`,
33
+ `ChargeStatus`, `SettlementStatus`, `WebhookEventType`, ...) —
34
+ including `WebhookCategory`/`EVENT_CATEGORY_MAP` (every event's
35
+ `payments`/`account`/`webhooks`/`security` grouping), and
36
+ `TriggerableChargeEvent`, the subset of charge events that
37
+ `POST /v1/sandbox/charges/{id}/trigger` (and an official SDK's
38
+ `charge.waitFor()`) accepts — every charge event except
39
+ `charge.created`. `TypedWebhookPayload`/`WebhookEventDataMap` give the
40
+ exact `data` shape per event, keyed by `event` (a discriminated union —
41
+ see the webhook example below).
42
+ - A handful of small constants (`TOKEN_ADDRESSES`, `NETWORK_EXPLORERS`,
43
+ `EVM_NETWORKS`, `OPERATIONAL_NETWORKS`, `CHARGE_ACCEPTED_PAYMENTS_MAX`)
44
+ that mirror values the API itself uses.
45
+ - `AcceptedPaymentSchema`/`AcceptedPayment` (`{ token, network }`) — a
46
+ charge accepts a *list* of these, not a single `token`/`network` pair;
47
+ `CapabilitiesSchema`/`Capabilities` is the response shape of
48
+ `GET /v1/networks`, the live matrix of pairs your key's environment
49
+ can currently accept.
50
+
51
+ Every schema field carries a `.describe()` — read them in your editor's
52
+ hover tooltips, or via the full interactive API reference served by the
53
+ API itself (open the API's base URL in a browser once you have access).
54
+
55
+ ## Documentation
56
+
57
+ | Doc | Covers |
58
+ |---|---|
59
+ | [`docs/getting-started.md`](./docs/getting-started.md) | Install, what's in this package, typing vs. runtime validation |
60
+ | [`docs/charges.md`](./docs/charges.md) | `Charge`, `CreateChargeInput`, `AcceptedPayment`, `Capabilities` (`GET /v1/networks`), listing/pagination, `VerifyCharge`, `TimelineEvent` |
61
+ | [`docs/webhooks.md`](./docs/webhooks.md) | Every `WebhookEventType`, categories, `Webhook`, `WebhookPayload`, `TypedWebhookPayload` |
62
+ | [`docs/sandbox.md`](./docs/sandbox.md) | `SandboxTriggerInput`, `SandboxEventTriggerInput`, `TriggerableChargeEvent` |
63
+ | [`docs/distributions.md`](./docs/distributions.md) | `PendingDistribution`, `PendingDistributionEvent` — the 0xSplits keeper feed |
64
+ | [`docs/auth-and-accounts.md`](./docs/auth-and-accounts.md) | Signup/login, email verification, password reset, `ApiKey`, `User`/`UserRole`, `Organization` |
65
+ | [`docs/tokens-and-networks.md`](./docs/tokens-and-networks.md) | `Token`, `Network`, and every chain/token constant |
66
+ | [`docs/errors-and-health.md`](./docs/errors-and-health.md) | `ErrorPayload` (every non-2xx response shape), `Health` |
67
+
68
+ ## Usage
69
+
70
+ Typing an API response:
71
+
72
+ ```ts
73
+ import type { Charge } from '@klappay/types'
74
+
75
+ async function getCharge(id: string): Promise<Charge> {
76
+ const res = await fetch(`${API_BASE_URL}/v1/charges/${id}`, {
77
+ headers: { Authorization: `Bearer ${process.env.KLAP_API_KEY}` },
78
+ })
79
+ return res.json()
80
+ }
81
+ ```
82
+
83
+ Validating an inbound webhook payload (recommended — don't just trust the
84
+ shape of what you receive):
85
+
86
+ ```ts
87
+ import { WebhookPayloadSchema } from '@klappay/types'
88
+
89
+ app.post('/webhooks/klap', (req, res) => {
90
+ const payload = WebhookPayloadSchema.parse(req.body)
91
+ // payload.data is `unknown` here — this schema only validates the
92
+ // envelope (id/event/createdAt), since `data`'s shape depends on
93
+ // `event` (see WebhookEventDataMap/TypedWebhookPayload above).
94
+
95
+ res.sendStatus(200)
96
+ })
97
+ ```
98
+
99
+ Note: this package only validates the *shape* of a webhook payload — it
100
+ does not verify the `X-Klap-Signature` HMAC header, which you must still
101
+ check yourself against the signing secret returned when you created the
102
+ webhook. Validating shape without verifying the signature means anyone
103
+ who can reach your endpoint can send you a structurally-valid payload.
104
+ If you'd rather not hand-roll HTTP calls and signature verification, an
105
+ official SDK ([github.com/klappay](https://github.com/klappay)) wraps
106
+ this package with a full client, typed errors, and a `constructEvent()`
107
+ helper that verifies the signature and returns a `TypedWebhookPayload`
108
+ — `data` narrows automatically from `event` in a `switch`/`if`, no cast
109
+ needed. See the live API reference for details.
110
+
111
+ ## Versioning
112
+
113
+ This package follows the API's own versioning. A breaking change to a
114
+ schema here means a breaking change to the corresponding API contract —
115
+ check the changelog before upgrading across a major version.
116
+
117
+ ## License
118
+
119
+ MIT — see [`LICENSE`](./LICENSE). This applies to this package only; the
120
+ Klap Core API implementation itself is closed-source.