@capxul/sdk-react 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 +31 -0
- package/LICENSE +44 -0
- package/README.md +173 -0
- package/dist/index.cjs +618 -0
- package/dist/index.d.cts +473 -0
- package/dist/index.d.ts +473 -0
- package/dist/index.js +568 -0
- package/package.json +86 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# @capxul/sdk-react
|
|
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.
|
|
27
|
+
|
|
28
|
+
### Patch Changes
|
|
29
|
+
|
|
30
|
+
- Updated dependencies
|
|
31
|
+
- @capxul/sdk@0.1.0-alpha.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
Copyright (c) 2026 Xelmar Tech Ltd. ("Capxul"). All rights reserved.
|
|
2
|
+
|
|
3
|
+
This software ("@capxul/sdk-react", the "Software") is proprietary to
|
|
4
|
+
Capxul. The Software is licensed, not sold, and is made available
|
|
5
|
+
solely to registered Capxul customers under the Capxul Terms of
|
|
6
|
+
Service or a separate written commercial agreement between Capxul and
|
|
7
|
+
the licensee.
|
|
8
|
+
|
|
9
|
+
Two-layer trust
|
|
10
|
+
---------------
|
|
11
|
+
Capxul's value-bearing on-chain logic — Safe v1.4.1, ERC-4337 modules,
|
|
12
|
+
and any contract that custodies, transfers, or signs over user funds —
|
|
13
|
+
is open source under permissive licenses and is published in a
|
|
14
|
+
separate, auditable repository. See:
|
|
15
|
+
|
|
16
|
+
https://github.com/Xelmar-tech/Capxul
|
|
17
|
+
|
|
18
|
+
The orchestration layer in this package — React provider, hooks,
|
|
19
|
+
state-machine wiring, integration glue, and any code that translates
|
|
20
|
+
customer intent into transactions or routes data between subsystems —
|
|
21
|
+
is the proprietary product of Capxul and is 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,173 @@
|
|
|
1
|
+
# @capxul/sdk-react
|
|
2
|
+
|
|
3
|
+
React provider + hooks for Capxul. Wraps [`@capxul/sdk`](https://www.npmjs.com/package/@capxul/sdk)
|
|
4
|
+
in a synchronously-mounting provider with lazy bootstrap and a
|
|
5
|
+
discriminated-union return shape on every read hook.
|
|
6
|
+
|
|
7
|
+
> **Alpha — `0.x` is pre-release.** APIs can change between alpha
|
|
8
|
+
> versions. Pin to an exact version and read the changelog before
|
|
9
|
+
> upgrading.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pnpm add @capxul/sdk @capxul/sdk-react react @tanstack/react-query
|
|
15
|
+
# or: npm install @capxul/sdk @capxul/sdk-react react @tanstack/react-query
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Peer requirements:
|
|
19
|
+
|
|
20
|
+
- React `>= 19.0.0`
|
|
21
|
+
- `@tanstack/react-query` `^5`
|
|
22
|
+
- `@xstate/react` `^5` (only if you use the flow hooks)
|
|
23
|
+
|
|
24
|
+
## Two-layer trust
|
|
25
|
+
|
|
26
|
+
This package is the **orchestration** half of Capxul's two-layer
|
|
27
|
+
architecture. Funds are custodied by audited, open-source Safe v1.4.1
|
|
28
|
+
contracts published in the [Capxul GitHub repo](https://github.com/Xelmar-tech/Capxul/tree/main/packages/contracts).
|
|
29
|
+
The React glue here is proprietary — see [`LICENSE`](./LICENSE).
|
|
30
|
+
|
|
31
|
+
## Quickstart
|
|
32
|
+
|
|
33
|
+
Wrap your app once with `CapxulProvider`. Pass a publishable key
|
|
34
|
+
(`cap_pk_live_…` / `cap_pk_test_…`). The provider mounts synchronously
|
|
35
|
+
— no Suspense gate, no async-mount stall — and lazily bootstraps the
|
|
36
|
+
runtime URLs from `/v1/client/bootstrap` on the first SDK call:
|
|
37
|
+
|
|
38
|
+
```tsx
|
|
39
|
+
import { CapxulProvider } from "@capxul/sdk-react";
|
|
40
|
+
|
|
41
|
+
export default function RootLayout({ children }) {
|
|
42
|
+
return (
|
|
43
|
+
<CapxulProvider publishableKey={process.env.NEXT_PUBLIC_CAPXUL_KEY!}>
|
|
44
|
+
{children}
|
|
45
|
+
</CapxulProvider>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Inside the tree, read identity with `useMe()`. The hook collapses the
|
|
51
|
+
multi-step lifecycle (not-bootstrapped, bootstrapping, no-session,
|
|
52
|
+
no-data, live) into three states the consumer cares about:
|
|
53
|
+
|
|
54
|
+
```tsx
|
|
55
|
+
import { useMe } from "@capxul/sdk-react";
|
|
56
|
+
|
|
57
|
+
function Header() {
|
|
58
|
+
const me = useMe();
|
|
59
|
+
|
|
60
|
+
if (me.isPending) return <span>Loading…</span>;
|
|
61
|
+
if (me.isError) return <span>Couldn't load profile.</span>;
|
|
62
|
+
return <span>Hi, {me.data.username}</span>;
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Drive an OTP sign-in flow with `useAuthFlow()` — a
|
|
67
|
+
[`useActor`](https://stately.ai/docs/xstate-react#useactor) observer
|
|
68
|
+
over the canonical XState v5 machine in `@capxul/sdk`:
|
|
69
|
+
|
|
70
|
+
```tsx
|
|
71
|
+
import { useAuthFlow } from "@capxul/sdk-react";
|
|
72
|
+
import { toEmail } from "@capxul/sdk";
|
|
73
|
+
|
|
74
|
+
function SignIn() {
|
|
75
|
+
const { snapshot, send } = useAuthFlow();
|
|
76
|
+
|
|
77
|
+
if (snapshot.matches("idle")) {
|
|
78
|
+
return (
|
|
79
|
+
<button
|
|
80
|
+
onClick={() =>
|
|
81
|
+
send({ type: "REQUEST_OTP", email: toEmail("alice@example.com") })
|
|
82
|
+
}
|
|
83
|
+
>
|
|
84
|
+
Send code
|
|
85
|
+
</button>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
// … handle "sending_otp", "otp_requested", "verifying", "authenticated"
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Lifecycle observability — `useCapxulStatus()`
|
|
93
|
+
|
|
94
|
+
Need a status indicator or a gate UI? Subscribe to the underlying
|
|
95
|
+
transport state machine:
|
|
96
|
+
|
|
97
|
+
```tsx
|
|
98
|
+
import { useCapxulStatus } from "@capxul/sdk-react";
|
|
99
|
+
|
|
100
|
+
function Banner() {
|
|
101
|
+
const status = useCapxulStatus();
|
|
102
|
+
|
|
103
|
+
switch (status.status) {
|
|
104
|
+
case "idle": // no network call yet
|
|
105
|
+
case "bootstrapping": // /v1/client/bootstrap in flight
|
|
106
|
+
return <Spinner />;
|
|
107
|
+
case "ready": // bootstrapped, no session
|
|
108
|
+
case "authenticated": // bootstrapped + session live
|
|
109
|
+
return null;
|
|
110
|
+
case "error":
|
|
111
|
+
return <ErrorBanner error={status.error} />;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
`useCapxulStatus()` is a thin
|
|
117
|
+
[`useSyncExternalStore`](https://react.dev/reference/react/useSyncExternalStore)
|
|
118
|
+
subscription against the transport singleton — only the components
|
|
119
|
+
that actually call it re-render when state changes. The provider
|
|
120
|
+
itself never re-renders.
|
|
121
|
+
|
|
122
|
+
## Hooks catalogue
|
|
123
|
+
|
|
124
|
+
| Surface | Hook |
|
|
125
|
+
|---|---|
|
|
126
|
+
| Imperative client | `useCapxul()` |
|
|
127
|
+
| Identity | `useMe`, `useAccount` |
|
|
128
|
+
| Organizations | `useOrganization`, `useOrganizations`, `useMember`, `useMembers` |
|
|
129
|
+
| Payments | `usePayment`, `usePayments`, `useOrgPayments` |
|
|
130
|
+
| Transfers | `useTransfer`, `useTransfers`, `useOrgTransfers` |
|
|
131
|
+
| Withdrawals | `useWithdrawal`, `useWithdrawals`, `useOrgWithdrawals` |
|
|
132
|
+
| Documents | `useDocument`, `useDocuments`, `useOrgDocuments` |
|
|
133
|
+
| Sub-accounts / virtual | `useSubAccount`, `useSubAccounts`, `useVirtualAccount`, `useVirtualAccounts`, `useVirtualCard`, `useVirtualCards` |
|
|
134
|
+
| Settings | `useApiKey`, `useApiKeys`, `useWebhookEndpoint`, `useWebhookEndpoints`, `useWebhookEvent`, `useExternalAccount`, `useExternalAccounts`, `useBalanceLedgerEntry`, `useBalanceLedger` |
|
|
135
|
+
| KYC / KYB | `useKycProfile`, `useKybProfile` |
|
|
136
|
+
| Treasury | `useTreasury`, `useSafe` |
|
|
137
|
+
| Operations | `useOperation` (correlation join key per CANON.md §3.3) |
|
|
138
|
+
| Lifecycle | `useCapxulStatus` |
|
|
139
|
+
| Flows | `useAuthFlow`, `useOnboardingFlow`, `useProvisioningFlow` |
|
|
140
|
+
|
|
141
|
+
Most "not-yet-implemented" verticals return a `QueryResult<T>` in the
|
|
142
|
+
`error` state with `code: "NOT_IMPLEMENTED"` — they compile, render
|
|
143
|
+
without crashing, and surface a clear runtime signal.
|
|
144
|
+
|
|
145
|
+
## Three-state read shape (`QueryResult<T>`)
|
|
146
|
+
|
|
147
|
+
Read hooks return a discriminated union:
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
type QueryResult<T> =
|
|
151
|
+
| { readonly status: "loading" }
|
|
152
|
+
| { readonly status: "data"; readonly data: T }
|
|
153
|
+
| { readonly status: "error"; readonly error: CapxulError };
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Hooks **never throw** for a "still loading" condition. Pattern-match
|
|
157
|
+
on `status`. (`useMe()` is the first hook migrated to TanStack Query
|
|
158
|
+
— it returns `UseQueryResult<Account, CapxulError>` for now; the
|
|
159
|
+
remaining hooks lift to that shape over time.)
|
|
160
|
+
|
|
161
|
+
## Server / CLI consumers
|
|
162
|
+
|
|
163
|
+
`@capxul/sdk-react` is browser-only. For server, CLI, and harness
|
|
164
|
+
code, build a `CapxulClient` directly with `createCapxulClient` from
|
|
165
|
+
`@capxul/sdk` — no provider, no React. See that package's README.
|
|
166
|
+
|
|
167
|
+
## License
|
|
168
|
+
|
|
169
|
+
Proprietary — see [`LICENSE`](./LICENSE). The orchestration code in
|
|
170
|
+
this package is governed by the Capxul Terms of Service. The
|
|
171
|
+
value-bearing custody contracts are open source.
|
|
172
|
+
|
|
173
|
+
Contact: [legal@capxul.com](mailto:legal@capxul.com)
|