@capxul/sdk 0.1.0-alpha.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/CHANGELOG.md +26 -0
- package/LICENSE +44 -0
- package/README.md +143 -0
- package/dist/client-BNGGubL2.d.cts +1147 -0
- package/dist/client-o4R-ZFh2.d.ts +1147 -0
- package/dist/client.cjs +2272 -0
- package/dist/client.d.cts +7 -0
- package/dist/client.d.ts +7 -0
- package/dist/client.js +2270 -0
- package/dist/errors.cjs +35 -0
- package/dist/errors.d.cts +55 -0
- package/dist/errors.d.ts +55 -0
- package/dist/errors.js +31 -0
- package/dist/index.cjs +2504 -0
- package/dist/index.d.cts +495 -0
- package/dist/index.d.ts +495 -0
- package/dist/index.js +2469 -0
- package/dist/types-Cokyqgwm.d.cts +202 -0
- package/dist/types-Cokyqgwm.d.ts +202 -0
- package/dist/webhooks.cjs +118 -0
- package/dist/webhooks.d.cts +34 -0
- package/dist/webhooks.d.ts +34 -0
- package/dist/webhooks.js +116 -0
- package/package.json +89 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# @capxul/sdk
|
|
2
|
+
|
|
3
|
+
Changelog managed by [changesets](https://github.com/changesets/changesets) —
|
|
4
|
+
see `.changeset/README.md` for the operator workflow.
|
|
5
|
+
|
|
6
|
+
## 0.1.0-alpha.0
|
|
7
|
+
|
|
8
|
+
### Minor Changes
|
|
9
|
+
|
|
10
|
+
- Initial alpha publish.
|
|
11
|
+
|
|
12
|
+
`@capxul/sdk` ships the headless TypeScript client for Capxul's
|
|
13
|
+
`/v1/*` HTTP contract — auth, me, accounts, payments, organizations,
|
|
14
|
+
withdrawals, documents, and three XState v5 flow machines. Errors
|
|
15
|
+
are typed `CapxulError` instances with narrowed `code` unions per
|
|
16
|
+
method; `tryCatch` returns the canonical `[error, data]` tuple.
|
|
17
|
+
|
|
18
|
+
`@capxul/sdk-react` ships the React provider and hooks. The lazy-DX
|
|
19
|
+
`<CapxulProvider publishableKey="cap_pk_…">` mounts synchronously
|
|
20
|
+
and bootstraps runtime URLs through `/v1/client/bootstrap` on the
|
|
21
|
+
first SDK call. `useCapxulStatus()` exposes the canonical 5-state
|
|
22
|
+
transport lifecycle through `useSyncExternalStore`. Read hooks
|
|
23
|
+
return the canonical `QueryResult<T>` three-state discriminated
|
|
24
|
+
union (loading / data / error) — never throws on "still loading".
|
|
25
|
+
|
|
26
|
+
See each package's `README.md` for the public surface.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
Copyright (c) 2026 Xelmar Tech Ltd. ("Capxul"). All rights reserved.
|
|
2
|
+
|
|
3
|
+
This software ("@capxul/sdk", the "Software") is proprietary to Capxul.
|
|
4
|
+
The Software is licensed, not sold, and is made available solely to
|
|
5
|
+
registered Capxul customers under the Capxul Terms of Service or a
|
|
6
|
+
separate written commercial agreement between Capxul and the licensee.
|
|
7
|
+
|
|
8
|
+
Two-layer trust
|
|
9
|
+
---------------
|
|
10
|
+
Capxul's value-bearing on-chain logic — Safe v1.4.1, ERC-4337 modules,
|
|
11
|
+
and any contract that custodies, transfers, or signs over user funds —
|
|
12
|
+
is open source under permissive licenses and is published in a
|
|
13
|
+
separate, auditable repository. See:
|
|
14
|
+
|
|
15
|
+
https://github.com/Xelmar-tech/Capxul
|
|
16
|
+
|
|
17
|
+
The orchestration layer in this package — workflow logic, business
|
|
18
|
+
rules, integration glue, the contents of /v1/* clients, and any code
|
|
19
|
+
that translates customer intent into transactions or routes data
|
|
20
|
+
between subsystems — is the proprietary product of Capxul and is
|
|
21
|
+
governed by this license.
|
|
22
|
+
|
|
23
|
+
Customers of the Capxul platform may use this Software solely:
|
|
24
|
+
(a) to access Capxul's hosted services they have contracted for,
|
|
25
|
+
(b) within the scope of their active subscription or trial, and
|
|
26
|
+
(c) in accordance with the Capxul Terms of Service.
|
|
27
|
+
|
|
28
|
+
Without limiting the foregoing, you may NOT:
|
|
29
|
+
(i) redistribute, sublicense, sell, lease, or rent the Software,
|
|
30
|
+
(ii) reverse-engineer, decompile, or disassemble the Software,
|
|
31
|
+
except to the limited extent applicable mandatory law
|
|
32
|
+
permits, and
|
|
33
|
+
(iii) remove or alter copyright, trademark, or other proprietary
|
|
34
|
+
notices in the Software.
|
|
35
|
+
|
|
36
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
37
|
+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY,
|
|
38
|
+
FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT. IN NO EVENT
|
|
39
|
+
SHALL CAPXUL OR ITS AFFILIATES BE LIABLE FOR ANY CLAIM, DAMAGES, OR
|
|
40
|
+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE,
|
|
41
|
+
ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
42
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
|
43
|
+
|
|
44
|
+
Contact: legal@capxul.com
|
package/README.md
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# @capxul/sdk
|
|
2
|
+
|
|
3
|
+
Headless TypeScript client for Capxul — issue and accept stablecoin
|
|
4
|
+
payments, manage organization treasuries, and orchestrate on-chain
|
|
5
|
+
flows backed by audited custody contracts.
|
|
6
|
+
|
|
7
|
+
> **Alpha — `0.x` is pre-release.** APIs can change between alpha
|
|
8
|
+
> versions. Pin to an exact version (`@capxul/sdk@0.1.0-alpha.0`) and
|
|
9
|
+
> read the changelog before upgrading.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pnpm add @capxul/sdk @capxul/sdk-react
|
|
15
|
+
# or: npm install @capxul/sdk @capxul/sdk-react
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
`@capxul/sdk` is the headless contract — flows, types, errors. The
|
|
19
|
+
React-flavored entry point lives in `@capxul/sdk-react`. Pick:
|
|
20
|
+
|
|
21
|
+
- **Browser apps (recommended).** Install both. Use
|
|
22
|
+
`<CapxulProvider publishableKey="cap_pk_…">` from `@capxul/sdk-react`
|
|
23
|
+
and the `useMe` / `useCapxulStatus` hooks. See that package's
|
|
24
|
+
README for the lazy-DX example.
|
|
25
|
+
- **Server / CLI / scripts.** Install only `@capxul/sdk`. Build a
|
|
26
|
+
`CapxulClient` directly with your own auth and Convex adapters
|
|
27
|
+
(see "Server-side construction" below).
|
|
28
|
+
|
|
29
|
+
## Two-layer trust
|
|
30
|
+
|
|
31
|
+
Capxul splits the platform into two layers with different licenses:
|
|
32
|
+
|
|
33
|
+
| Layer | What it does | License |
|
|
34
|
+
|---|---|---|
|
|
35
|
+
| Custody (on-chain) | Safe v1.4.1 + ERC-4337 modules — every contract that holds, transfers, or signs over user funds | Open source, audited, in the [Capxul GitHub repo](https://github.com/Xelmar-tech/Capxul/tree/main/packages/contracts) |
|
|
36
|
+
| Orchestration (this package) | Workflow logic, business rules, integration glue, the `/v1/*` HTTP client | Proprietary — see `LICENSE` |
|
|
37
|
+
|
|
38
|
+
You don't have to take our word for the parts that hold money — those
|
|
39
|
+
contracts are open and auditable. The parts that orchestrate workflows
|
|
40
|
+
on top are our product.
|
|
41
|
+
|
|
42
|
+
## Quickstart (server / CLI)
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import { createCapxulClient, createLocalSigner, tryCatch } from "@capxul/sdk";
|
|
46
|
+
|
|
47
|
+
const signer = createLocalSigner(process.env.CAPXUL_PRIVATE_KEY!);
|
|
48
|
+
const capxul = createCapxulClient({
|
|
49
|
+
apiKey: process.env.CAPXUL_API_KEY!, // server-to-server partner key
|
|
50
|
+
signer,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const [err, payment] = await tryCatch(
|
|
54
|
+
capxul.payments.create({
|
|
55
|
+
to: { email: "vendor@example.com" },
|
|
56
|
+
amount: { value: "100", currency: "USD" },
|
|
57
|
+
}),
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
if (err) {
|
|
61
|
+
if (err.code === "INSUFFICIENT_BALANCE") {
|
|
62
|
+
// narrow `err.code` to route the UI / reply
|
|
63
|
+
}
|
|
64
|
+
throw err;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
console.log(payment.id);
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Quickstart (browser via React)
|
|
71
|
+
|
|
72
|
+
See [`@capxul/sdk-react`](https://www.npmjs.com/package/@capxul/sdk-react).
|
|
73
|
+
The browser path uses a publishable key (`cap_pk_…`) and bootstraps
|
|
74
|
+
runtime URLs lazily — no need to ship secrets to the client:
|
|
75
|
+
|
|
76
|
+
```tsx
|
|
77
|
+
import { CapxulProvider, useMe, useCapxulStatus } from "@capxul/sdk-react";
|
|
78
|
+
|
|
79
|
+
<CapxulProvider publishableKey="cap_pk_live_…">
|
|
80
|
+
<App />
|
|
81
|
+
</CapxulProvider>;
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Public surface (alpha)
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
capxul.auth // sendOtp, verifyOtp, signOut, serviceTokenMint
|
|
88
|
+
capxul.me // get, update — first-party caller identity
|
|
89
|
+
capxul.accounts // create, retrieve, list
|
|
90
|
+
capxul.organizations // CRUD + members + payments + treasury
|
|
91
|
+
capxul.payments // create, retrieve, list
|
|
92
|
+
capxul.invoices // create, retrieve, list
|
|
93
|
+
capxul.withdrawals // request, retrieve, list
|
|
94
|
+
capxul.documents // KYC uploads, invoices, receipts, tax forms
|
|
95
|
+
capxul.flows.{auth, onboarding, provisioning} // XState v5 flows
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Helpers:
|
|
99
|
+
|
|
100
|
+
- `tryCatch(promise)` — error tuple `[error, data]`; routes on
|
|
101
|
+
`error.code` (typed `CapxulErrorCode` union)
|
|
102
|
+
- `matchError`, `matchStatus`, `matchAction` — exhaustive pattern
|
|
103
|
+
matchers per CANON.md §4.44
|
|
104
|
+
- Branded type constructors — `toEmail`, `toAccountId`,
|
|
105
|
+
`toOrganizationId`, … — never cast raw strings
|
|
106
|
+
|
|
107
|
+
## Error model
|
|
108
|
+
|
|
109
|
+
Every method returns a `CapxulResult<T, Codes>` tuple. Errors are
|
|
110
|
+
instances of `CapxulError` with a typed `code` (narrowed per method).
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
const [err, account] = await tryCatch(capxul.me.get());
|
|
114
|
+
|
|
115
|
+
if (err) {
|
|
116
|
+
switch (err.code) {
|
|
117
|
+
case "PROFILE_NOT_FOUND": return router.push("/onboarding");
|
|
118
|
+
case "NOT_AUTHENTICATED": return router.push("/login");
|
|
119
|
+
default: throw err; // unhandled — bubble to the error boundary
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
There is no second error type. Backend `CapxulError` → Convex
|
|
125
|
+
serialization → SDK deserialization → frontend `CapxulError` — one
|
|
126
|
+
class, 34 codes, end-to-end.
|
|
127
|
+
|
|
128
|
+
## Telemetry (opt-out)
|
|
129
|
+
|
|
130
|
+
The SDK reports operational telemetry (operation IDs, latencies,
|
|
131
|
+
correlation IDs, error codes) to Capxul. **PII is never sent** — events
|
|
132
|
+
are scrubbed at the source. Disable by passing
|
|
133
|
+
`{ telemetry: { enabled: false } }` (coming in `0.2.0`); current alpha
|
|
134
|
+
sends only operational signals which Capxul Terms disclose explicitly.
|
|
135
|
+
|
|
136
|
+
## License
|
|
137
|
+
|
|
138
|
+
Proprietary — see [`LICENSE`](./LICENSE). The orchestration code in
|
|
139
|
+
this package is governed by the Capxul Terms of Service. The
|
|
140
|
+
value-bearing custody contracts are open source — see "Two-layer trust"
|
|
141
|
+
above.
|
|
142
|
+
|
|
143
|
+
Contact: [legal@capxul.com](mailto:legal@capxul.com)
|