@capxul/sdk-react 0.2.0-alpha.4 → 0.2.0-alpha.5
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 +259 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +524 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +37 -75
- package/CHANGELOG.md +0 -304
- package/LICENSE +0 -44
- package/README.md +0 -187
- package/dist/index.cjs +0 -1289
- package/dist/index.d.cts +0 -673
- package/dist/index.d.ts +0 -673
- package/dist/index.js +0 -1230
- package/dist/proof/index.cjs +0 -12785
- package/dist/proof/index.d.cts +0 -753
- package/dist/proof/index.d.ts +0 -753
- package/dist/proof/index.js +0 -12758
package/dist/index.d.cts
DELETED
|
@@ -1,673 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
import { HttpTransport, TransportState, BrowserCapxulConfig, AuthSessionStore, AccountId, OrganizationId, ApiKeyId, BalanceLedgerEntryId, ExternalAccountId, MemberId, Account, ApiKey, BalanceLedgerEntry, DocumentId, Document, ExternalAccount, KycProfile, CapxulError as CapxulError$1, Member, OperationId, Operation, Organization, PaymentId, Payment, SafeId, Safe, SubAccountId, SubAccount, TokenTransfer, TransferId, Transfer, Treasury, VirtualAccountId, VirtualAccount, VirtualCardId, VirtualCard, WebhookEndpointId, WebhookEndpoint, WebhookEventId, WebhookEvent, WithdrawalId, Withdrawal, List, MembershipStatus, TokenTransfersListInput, TokenTransfersListPage, MemberInviteResponse, Session, AuthBootstrapToken, AuthBootstrapReason } from '@capxul/sdk';
|
|
3
|
-
export { BrowserCapxulConfig, OnboardingFlowContext, OnboardingFlowEvent, ProvisioningFlowContext, ProvisioningFlowEvent } from '@capxul/sdk';
|
|
4
|
-
import { QueryClient, UseQueryResult, UseMutationResult } from '@tanstack/react-query';
|
|
5
|
-
import { CapxulClient } from '@capxul/sdk/client';
|
|
6
|
-
import { CapxulError } from '@capxul/sdk/errors';
|
|
7
|
-
import { Account as Account$1 } from 'viem';
|
|
8
|
-
import * as xstate from 'xstate';
|
|
9
|
-
|
|
10
|
-
type CapxulClientProviderProps = {
|
|
11
|
-
readonly client: CapxulClient;
|
|
12
|
-
readonly children: ReactNode;
|
|
13
|
-
};
|
|
14
|
-
declare function CapxulClientProvider({ client, children, }: CapxulClientProviderProps): ReactNode;
|
|
15
|
-
/**
|
|
16
|
-
* Returns the `@capxul/sdk` client attached to the nearest provider.
|
|
17
|
-
*
|
|
18
|
-
* @throws `Error` if called outside a provider subtree. This is a
|
|
19
|
-
* developer error, not a `CapxulError`, because a missing provider
|
|
20
|
-
* cannot be recovered at runtime.
|
|
21
|
-
*/
|
|
22
|
-
declare function useCapxul(): CapxulClient;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* `CapxulTransportContext` — sibling context that exposes the
|
|
26
|
-
* `HttpTransport` lifecycle singleton built by the lazy-DX
|
|
27
|
-
* `CapxulProvider` path (ADR #14c).
|
|
28
|
-
*
|
|
29
|
-
* Separate from `CapxulClientContext` because the legacy `config`
|
|
30
|
-
* path doesn't build an externally-observable transport. When the
|
|
31
|
-
* provider runs the legacy path, this context's value stays `null`
|
|
32
|
-
* and `useCapxulStatus()` reports `"ready"` as a permissive default
|
|
33
|
-
* (the legacy path implies the host has already wired auth and data;
|
|
34
|
-
* there is nothing for the consumer to gate on).
|
|
35
|
-
*/
|
|
36
|
-
|
|
37
|
-
type CapxulTransportProviderProps = {
|
|
38
|
-
readonly transport: HttpTransport;
|
|
39
|
-
readonly children: ReactNode;
|
|
40
|
-
};
|
|
41
|
-
declare function CapxulTransportProvider({ transport, children, }: CapxulTransportProviderProps): ReactNode;
|
|
42
|
-
/**
|
|
43
|
-
* Read the transport's current lifecycle state. Subscribes via
|
|
44
|
-
* `useSyncExternalStore` so the host re-renders only when the
|
|
45
|
-
* transport's state machine transitions, not when the provider tree
|
|
46
|
-
* re-renders. Returns the `TransportState` discriminated union with
|
|
47
|
-
* the contract-locked statuses:
|
|
48
|
-
* `"idle" | "bootstrapping" | "ready" | "authenticated" | "error"`.
|
|
49
|
-
*
|
|
50
|
-
* Outside a provider tree (or inside the legacy `config` path that
|
|
51
|
-
* does not build an externally-observable transport), the hook
|
|
52
|
-
* returns a synthetic `{ status: "ready" }` snapshot — the legacy
|
|
53
|
-
* path implies the host has already wired auth + data so there is
|
|
54
|
-
* nothing to gate on.
|
|
55
|
-
*/
|
|
56
|
-
declare function useCapxulStatus(): TransportState;
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* `CapxulProvider` — public React provider for `@capxul/sdk-react`.
|
|
60
|
-
*
|
|
61
|
-
* Single-input contract: accepts ONLY `{ config: BrowserCapxulConfig,
|
|
62
|
-
* sessionStore?, queryClient?, children }`. The browser config is the
|
|
63
|
-
* secret-safe discriminated union from `@capxul/sdk` — `apiKey`,
|
|
64
|
-
* `data`, `signer`, and other server-only fields are rejected at
|
|
65
|
-
* compile-time AND at runtime via `createCapxulConfig`'s allow-list
|
|
66
|
-
* validator.
|
|
67
|
-
*
|
|
68
|
-
* The provider builds an `HttpTransport` synchronously and injects it
|
|
69
|
-
* into `createCapxulClient` via the internal `_transport` slot. The
|
|
70
|
-
* transport is exposed through `CapxulTransportContext` so
|
|
71
|
-
* `useCapxulStatus()` can subscribe to its lifecycle state machine.
|
|
72
|
-
*
|
|
73
|
-
* The provider also builds a `ConvexReactClient`-backed data client
|
|
74
|
-
* for the `build-time-urls` arm and feeds it as `config._data` so the
|
|
75
|
-
* SDK domain methods (`me.get`, `accounts.retrieve`, ...) and the
|
|
76
|
-
* React hooks built on top can run authenticated reads against live
|
|
77
|
-
* Convex. The auth lifecycle threads through the optional
|
|
78
|
-
* `sessionStore` prop: `verifyOtp` writes a session to the store
|
|
79
|
-
* (which the SDK auth client persists), and the provider's data
|
|
80
|
-
* client re-reads the JWT on demand via `refreshAuth()`. Without a
|
|
81
|
-
* session store the provider falls back to an in-memory one, which
|
|
82
|
-
* is fine for browser apps that hold the page until next reload but
|
|
83
|
-
* inadequate for CLI / Node consumers that need cross-process
|
|
84
|
-
* persistence — those pass a file-backed store via the prop.
|
|
85
|
-
*
|
|
86
|
-
* Tests and the e2e harness need the server-augmented `CapxulConfig`
|
|
87
|
-
* shape (with `data`, `signer`, `signing`). Those callers use
|
|
88
|
-
* `CapxulTestProvider` from `@capxul/sdk-react/proof` instead.
|
|
89
|
-
*
|
|
90
|
-
* Per ADR 4 in the API-first architecture stack PLAN, only
|
|
91
|
-
* `QueryClientProvider` is allowed to live OUTSIDE the single
|
|
92
|
-
* `CapxulContext`. The `QueryClientProvider` is the outermost wrap;
|
|
93
|
-
* the SDK client provider sits inside it; the transport provider sits
|
|
94
|
-
* between the two.
|
|
95
|
-
*/
|
|
96
|
-
|
|
97
|
-
type CapxulProviderProps = {
|
|
98
|
-
/**
|
|
99
|
-
* Browser-safe Capxul config — the discriminated union from
|
|
100
|
-
* `@capxul/sdk`. Either the `build-time-urls` arm or the
|
|
101
|
-
* `publishable-key` arm. Server-only fields (`apiKey`, `data`,
|
|
102
|
-
* `signer`, `signing`) are rejected at compile-time and at runtime
|
|
103
|
-
* via `createCapxulConfig`'s allow-list validator.
|
|
104
|
-
*/
|
|
105
|
-
readonly config: BrowserCapxulConfig;
|
|
106
|
-
/**
|
|
107
|
-
* Auth session persistence adapter. The SDK auth client writes
|
|
108
|
-
* sessions here on `verifyOtp` and clears them on `signOut`. The
|
|
109
|
-
* provider's data client re-reads the JWT from this store on every
|
|
110
|
-
* `refreshAuth` call so reads carry the right auth header.
|
|
111
|
-
*
|
|
112
|
-
* Defaults to an in-memory store scoped to this provider. Pass a
|
|
113
|
-
* file-backed (Node CLI) or `localStorage`-backed (browser) store
|
|
114
|
-
* to persist sessions across process or page lifetimes.
|
|
115
|
-
*/
|
|
116
|
-
readonly sessionStore?: AuthSessionStore;
|
|
117
|
-
/**
|
|
118
|
-
* Optional TanStack Query `QueryClient`. Pass your app's existing
|
|
119
|
-
* client to share the cache across the SDK hooks and the host
|
|
120
|
-
* app's own queries; omit to receive a default instance scoped to
|
|
121
|
-
* this provider with a 30s `staleTime`.
|
|
122
|
-
*/
|
|
123
|
-
readonly queryClient?: QueryClient;
|
|
124
|
-
readonly children: ReactNode;
|
|
125
|
-
};
|
|
126
|
-
declare function CapxulProvider({ config, sessionStore, queryClient, children, }: CapxulProviderProps): ReactNode;
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* `QueryResult<T>` — the canonical three-state return shape for every
|
|
130
|
-
* read hook in `@capxul/sdk-react`, locked per CANON.md §4.29 and
|
|
131
|
-
* reaffirmed by the ADR #14c lazy-DX contract (item 4).
|
|
132
|
-
*
|
|
133
|
-
* Three variants:
|
|
134
|
-
* - `loading` — no data yet; the subscription is in flight (matches
|
|
135
|
-
* the contract's `"loading"` status)
|
|
136
|
-
* - `data` — data is live; will update reactively on next tick
|
|
137
|
-
* (the contract calls this `"ready"` colloquially — same semantics,
|
|
138
|
-
* different name; the canon name is binding)
|
|
139
|
-
* - `error` — terminal failure; `error.code` is a narrowed
|
|
140
|
-
* `CapxulErrorCode` so consumers can route via `matchError`
|
|
141
|
-
*
|
|
142
|
-
* Hooks NEVER throw for a "still loading" condition — the lazy-DX
|
|
143
|
-
* contract collapses the multi-step lifecycle (not-bootstrapped,
|
|
144
|
-
* bootstrapping, no-session, no-data, live) into these three states.
|
|
145
|
-
* Consumers that want to surface the underlying transport state use
|
|
146
|
-
* `useCapxulStatus()` which returns the 5-state `TransportState`
|
|
147
|
-
* union.
|
|
148
|
-
*
|
|
149
|
-
* `useMe()` is the first live hook and maps the SDK tuple into this
|
|
150
|
-
* shape. Hooks whose verticals have not landed still use the
|
|
151
|
-
* `NOT_IMPLEMENTED` helper below.
|
|
152
|
-
*/
|
|
153
|
-
|
|
154
|
-
type QueryResult<T> = {
|
|
155
|
-
readonly status: "loading";
|
|
156
|
-
} | {
|
|
157
|
-
readonly status: "data";
|
|
158
|
-
readonly data: T;
|
|
159
|
-
} | {
|
|
160
|
-
readonly status: "error";
|
|
161
|
-
readonly error: CapxulError;
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Per-resource singular read hooks — 21 total.
|
|
166
|
-
*
|
|
167
|
-
* Catalogued in the reset hook proof matrix. TanStack Query-backed
|
|
168
|
-
* hooks return `UseQueryResult<T, CapxulError>` and route through
|
|
169
|
-
* public `@capxul/sdk` reads with a 30s `staleTime` matching the
|
|
170
|
-
* `CapxulProvider` default. Hooks not yet migrated still return
|
|
171
|
-
* `QueryResult<T>` per the reset transport contract — per-hook
|
|
172
|
-
* migration is the rollout pattern; later tasks lift each in turn.
|
|
173
|
-
* `useOperation()` routes through `operations.retrieve()` so harness
|
|
174
|
-
* observers can read durable operation state.
|
|
175
|
-
*
|
|
176
|
-
* Argument shapes follow sdk-surface.md §3b:
|
|
177
|
-
* - Single-ID reads take the branded ID directly
|
|
178
|
-
* - Composite-key reads (member, api-key, external account,
|
|
179
|
-
* balance-ledger entry) take an options object
|
|
180
|
-
* - Owner-scoped composite keys use a discriminated `OwnerRef`
|
|
181
|
-
*/
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Discriminated owner reference for hooks whose resource can belong
|
|
185
|
-
* to either a personal account or an organization.
|
|
186
|
-
*/
|
|
187
|
-
type OwnerRef = {
|
|
188
|
-
readonly ownerKind: "account";
|
|
189
|
-
readonly ownerId: AccountId;
|
|
190
|
-
} | {
|
|
191
|
-
readonly ownerKind: "organization";
|
|
192
|
-
readonly ownerId: OrganizationId;
|
|
193
|
-
};
|
|
194
|
-
type UseMemberArgs = {
|
|
195
|
-
readonly organizationId: OrganizationId;
|
|
196
|
-
readonly memberId: MemberId;
|
|
197
|
-
};
|
|
198
|
-
type UseApiKeyArgs = {
|
|
199
|
-
readonly organizationId: OrganizationId;
|
|
200
|
-
readonly apiKeyId: ApiKeyId;
|
|
201
|
-
};
|
|
202
|
-
type UseExternalAccountArgs = OwnerRef & {
|
|
203
|
-
readonly externalAccountId: ExternalAccountId;
|
|
204
|
-
};
|
|
205
|
-
type UseBalanceLedgerEntryArgs = OwnerRef & {
|
|
206
|
-
readonly entryId: BalanceLedgerEntryId;
|
|
207
|
-
};
|
|
208
|
-
/**
|
|
209
|
-
* The authenticated caller's identity (first-party only per §4.2).
|
|
210
|
-
*
|
|
211
|
-
* First hook migrated to TanStack Query per PLAN.md task 1.8.
|
|
212
|
-
* Cache key `[capxul.id, "capxul", "me"]`; `staleTime` of 30s
|
|
213
|
-
* matches the `CapxulProvider` default `QueryClient`. The query
|
|
214
|
-
* function maps the SDK tuple into TanStack's throw-on-error
|
|
215
|
-
* contract: a non-null `error` tuple slot is rethrown so TanStack
|
|
216
|
-
* surfaces it on the result, and a non-`CapxulError` thrown by the
|
|
217
|
-
* SDK transport is normalized to `CapxulError({ code: "UNKNOWN",
|
|
218
|
-
* cause })` so the `UseQueryResult` `error` channel is always typed
|
|
219
|
-
* `CapxulError`.
|
|
220
|
-
*
|
|
221
|
-
* The `capxul.id` leading segment isolates cache state across
|
|
222
|
-
* `CapxulClient` swaps. Without it, swapping the client inside the
|
|
223
|
-
* same `QueryClient` (e.g. after a sign-out / sign-in) would return
|
|
224
|
-
* the previous account's cached data for up to the 30s stale window.
|
|
225
|
-
* See Codex P1 finding on PR #406.
|
|
226
|
-
*/
|
|
227
|
-
declare function useMe(): UseQueryResult<Account, CapxulError$1>;
|
|
228
|
-
/**
|
|
229
|
-
* Account by id. Omit `accountId` for the calling user (alias for
|
|
230
|
-
* `useMe()` from a developer-perspective lens).
|
|
231
|
-
*
|
|
232
|
-
* Slice 2 (#457 story 1): wired via `capxul.accounts.retrieve` for
|
|
233
|
-
* the id-bearing call and `capxul.me.get()` for the self-lens
|
|
234
|
-
* shortcut. Returns the legacy `QueryResult<Account>` shape because
|
|
235
|
-
* only `useMe` has migrated to TanStack Query so far (PLAN.md task
|
|
236
|
-
* 1.8) — per-hook migration is the rollout pattern.
|
|
237
|
-
*/
|
|
238
|
-
declare function useAccount(accountId?: AccountId): QueryResult<Account>;
|
|
239
|
-
declare function useOrganization(organizationId: OrganizationId): UseQueryResult<Organization, CapxulError$1>;
|
|
240
|
-
declare function useMember(args: UseMemberArgs): UseQueryResult<Member, CapxulError$1>;
|
|
241
|
-
/**
|
|
242
|
-
* Live; status advances as the indexer reconciles the on-chain
|
|
243
|
-
* deployment. Consumers pattern-match on `data.status` via
|
|
244
|
-
* `matchStatus` (see `@capxul/sdk`).
|
|
245
|
-
*
|
|
246
|
-
* Slice 2 (#457 story 1): wired via
|
|
247
|
-
* `capxul.accounts.safes.retrieve(safeId)`. The SDK method is real
|
|
248
|
-
* post-Withdrawals v1 slice 1; this hook closes the React-side
|
|
249
|
-
* stub so onboarding can subscribe to Safe deploy progress.
|
|
250
|
-
*/
|
|
251
|
-
declare function useSafe(safeId: SafeId): QueryResult<Safe>;
|
|
252
|
-
declare function useTreasury(organizationId: OrganizationId): UseQueryResult<Treasury, CapxulError$1>;
|
|
253
|
-
/**
|
|
254
|
-
* Org-admin lens only — the hook NEVER returns `secret`.
|
|
255
|
-
*/
|
|
256
|
-
declare function useApiKey(_args: UseApiKeyArgs): QueryResult<ApiKey>;
|
|
257
|
-
declare function useKycProfile(_accountId: AccountId): QueryResult<KycProfile>;
|
|
258
|
-
/**
|
|
259
|
-
* Withdrawals v1 W1 (#464) — wired through the SDK.
|
|
260
|
-
*
|
|
261
|
-
* Branches on `args.ownerKind` so `account` scope reads via the
|
|
262
|
-
* top-level `capxul.externalAccounts.retrieve(id)` (visibility-gated
|
|
263
|
-
* server-side by the caller's accountId), and `organization` scope
|
|
264
|
-
* reads via `capxul.organizations.externalAccounts.retrieve({ ... })`
|
|
265
|
-
* which adds an org-scope check for cross-org isolation. Both routes
|
|
266
|
-
* resolve to the same Convex query handler — the SDK ergonomics
|
|
267
|
-
* differ but the wire shape is identical.
|
|
268
|
-
*/
|
|
269
|
-
declare function useExternalAccount(args: UseExternalAccountArgs): QueryResult<ExternalAccount>;
|
|
270
|
-
/**
|
|
271
|
-
* Funds v1 PR-2b (#421) — wired through `capxul.subAccounts.retrieve`.
|
|
272
|
-
*
|
|
273
|
-
* The top-level `subAccounts.retrieve` resolves to the same Convex
|
|
274
|
-
* query handler as `accounts.subAccounts.retrieve` /
|
|
275
|
-
* `organizations.subAccounts.retrieve`; visibility is gated server-side
|
|
276
|
-
* (canon §sub_account read contract — cross-scope reads surface as
|
|
277
|
-
* `NOT_FOUND` rather than a distinct permission code). The SDK has
|
|
278
|
-
* already branded the wire shape via `tryBrandSubAccount`, so the hook
|
|
279
|
-
* receives a fully-branded `SubAccount` (`SubAccountId`, `Money`,
|
|
280
|
-
* `TimestampIso`).
|
|
281
|
-
*/
|
|
282
|
-
declare function useSubAccount(subAccountId: SubAccountId): QueryResult<SubAccount>;
|
|
283
|
-
declare function useVirtualAccount(_virtualAccountId: VirtualAccountId): QueryResult<VirtualAccount>;
|
|
284
|
-
declare function useVirtualCard(_virtualCardId: VirtualCardId): QueryResult<VirtualCard>;
|
|
285
|
-
declare function usePayment(paymentId: PaymentId): UseQueryResult<Payment, CapxulError$1>;
|
|
286
|
-
declare function useTransfer(_transferId: TransferId): QueryResult<Transfer>;
|
|
287
|
-
type UseTokenTransferArgs = {
|
|
288
|
-
readonly txHash: string;
|
|
289
|
-
readonly logIndex: number;
|
|
290
|
-
readonly chainId?: number;
|
|
291
|
-
};
|
|
292
|
-
/**
|
|
293
|
-
* **NON-CANONICAL** raw on-chain ERC-20 transfer detail. Wired through
|
|
294
|
-
* `capxul.tokenTransfers.retrieve` per slice/02-story2-balance
|
|
295
|
-
* Option-A verdict. Identifier is the canonical on-chain composite
|
|
296
|
-
* `(txHash, logIndex)` so consumers don't have to round-trip through
|
|
297
|
-
* the Convex doc id.
|
|
298
|
-
*
|
|
299
|
-
* Intentionally NOT in `packages/sdk-react/ops/proof/hook-manifest.ts`
|
|
300
|
-
* — the canonical proof manifest tracks canon-aligned hooks only.
|
|
301
|
-
*/
|
|
302
|
-
declare function useTokenTransfer(args: UseTokenTransferArgs): QueryResult<TokenTransfer>;
|
|
303
|
-
/**
|
|
304
|
-
* Immutable once written; `live` semantically only for late
|
|
305
|
-
* `paymentId` / `transferId` attachment per Doc 02 §"balance_ledger".
|
|
306
|
-
*/
|
|
307
|
-
declare function useBalanceLedgerEntry(args: UseBalanceLedgerEntryArgs): QueryResult<BalanceLedgerEntry>;
|
|
308
|
-
declare function useDocument(_documentId: DocumentId): QueryResult<Document>;
|
|
309
|
-
/**
|
|
310
|
-
* Withdrawals v1 slice 1 (#440) — wired through `capxul.withdrawals.retrieve`.
|
|
311
|
-
* Mirrors `useOperation` (the canonical evidence subscription) since
|
|
312
|
-
* the withdrawal resource is operation-shaped at its core.
|
|
313
|
-
*/
|
|
314
|
-
declare function useWithdrawal(withdrawalId: WithdrawalId): QueryResult<Withdrawal>;
|
|
315
|
-
/**
|
|
316
|
-
* The canonical evidence subscription per CANON.md §3.3 —
|
|
317
|
-
* `operationId` + `correlationId` are the cross-layer join keys for
|
|
318
|
-
* debugging any mutation's end-to-end trail.
|
|
319
|
-
*/
|
|
320
|
-
declare function useOperation(operationId: OperationId): QueryResult<Operation>;
|
|
321
|
-
/**
|
|
322
|
-
* Org-admin lens only — the hook NEVER returns `signingSecret`.
|
|
323
|
-
*/
|
|
324
|
-
declare function useWebhookEndpoint(_endpointId: WebhookEndpointId): QueryResult<WebhookEndpoint>;
|
|
325
|
-
declare function useWebhookEvent(_eventId: WebhookEventId): QueryResult<WebhookEvent>;
|
|
326
|
-
|
|
327
|
-
/**
|
|
328
|
-
* Per-resource list read hooks — 17 total.
|
|
329
|
-
*
|
|
330
|
-
* Catalogued in Doc 08 §3. TanStack Query-backed hooks return
|
|
331
|
-
* `UseQueryResult<List<T>, CapxulError>` and route through public
|
|
332
|
-
* `@capxul/sdk` reads. Hooks not yet migrated still return
|
|
333
|
-
* `QueryResult<List<T>>` per CANON.md §4.29.
|
|
334
|
-
*
|
|
335
|
-
* Argument shapes follow sdk-surface.md §3b:
|
|
336
|
-
* - Cursor-paginated lists take `{ limit?, cursor? }` filters per
|
|
337
|
-
* §4.16 (cursor pagination convention)
|
|
338
|
-
* - Org-scoped lists take `organizationId` explicitly per §4.30
|
|
339
|
-
* (Shape A — no ambient org context)
|
|
340
|
-
* - Owner-scoped lists use the discriminated `OwnerRef`
|
|
341
|
-
*/
|
|
342
|
-
|
|
343
|
-
/**
|
|
344
|
-
* Cursor-pagination filters shared by list hooks. Mirrors the input
|
|
345
|
-
* shape used by the vanilla SDK's `<domain>.list(...)` methods.
|
|
346
|
-
*/
|
|
347
|
-
type PaginationFilters = {
|
|
348
|
-
readonly limit?: number;
|
|
349
|
-
readonly cursor?: string;
|
|
350
|
-
};
|
|
351
|
-
type OptionalOwnerFilter = {
|
|
352
|
-
readonly ownerKind?: undefined;
|
|
353
|
-
readonly ownerId?: undefined;
|
|
354
|
-
};
|
|
355
|
-
type AccountOwnerFilter = {
|
|
356
|
-
readonly ownerKind: "account";
|
|
357
|
-
readonly ownerId: AccountId;
|
|
358
|
-
};
|
|
359
|
-
type SubAccountOwnerFilter = {
|
|
360
|
-
readonly ownerKind: "sub_account";
|
|
361
|
-
readonly ownerId: SubAccountId;
|
|
362
|
-
};
|
|
363
|
-
type OrganizationOwnerFilter = {
|
|
364
|
-
readonly ownerKind: "organization";
|
|
365
|
-
readonly ownerId: OrganizationId;
|
|
366
|
-
};
|
|
367
|
-
/**
|
|
368
|
-
* Filters for virtual-account listing. Narrows by owner when both
|
|
369
|
-
* `ownerKind` and `ownerId` are supplied; otherwise returns every
|
|
370
|
-
* virtual account the caller can see across their scope.
|
|
371
|
-
*/
|
|
372
|
-
type VirtualAccountsFilters = PaginationFilters & (OptionalOwnerFilter | AccountOwnerFilter | SubAccountOwnerFilter | OrganizationOwnerFilter);
|
|
373
|
-
type VirtualCardsFilters = PaginationFilters & (OptionalOwnerFilter | AccountOwnerFilter | SubAccountOwnerFilter | OrganizationOwnerFilter);
|
|
374
|
-
type DocumentsFilters = PaginationFilters & {
|
|
375
|
-
readonly type?: "invoice" | "payroll_run" | "payroll_schedule" | "receipt" | "kyc_upload" | "bank_statement" | "tax_form";
|
|
376
|
-
};
|
|
377
|
-
type TransfersFilters = PaginationFilters;
|
|
378
|
-
type PaymentsFilters = PaginationFilters;
|
|
379
|
-
type WithdrawalsFilters = PaginationFilters;
|
|
380
|
-
type OwnerScopedFilters = OwnerRef & PaginationFilters;
|
|
381
|
-
type OrgScopedFilters = {
|
|
382
|
-
readonly organizationId: OrganizationId;
|
|
383
|
-
} & PaginationFilters;
|
|
384
|
-
type OrgDocumentsFilters = OrgScopedFilters & {
|
|
385
|
-
readonly type?: DocumentsFilters["type"];
|
|
386
|
-
};
|
|
387
|
-
/**
|
|
388
|
-
* "My orgs" — returns every organization the authenticated caller
|
|
389
|
-
* is a member of, with the co-member lens per row.
|
|
390
|
-
*/
|
|
391
|
-
declare function useOrganizations(filters?: PaginationFilters): UseQueryResult<List<Organization>, CapxulError$1>;
|
|
392
|
-
type MembersFilters = {
|
|
393
|
-
readonly status?: MembershipStatus | "all";
|
|
394
|
-
};
|
|
395
|
-
declare function useMembers(organizationId: OrganizationId, filters?: MembersFilters): UseQueryResult<List<Member>, CapxulError$1>;
|
|
396
|
-
/**
|
|
397
|
-
* Withdrawals v1 W1 (#464) — wired through the SDK.
|
|
398
|
-
*
|
|
399
|
-
* Personal scope reads through `capxul.accounts.externalAccounts.list({
|
|
400
|
-
* accountId })` (Pattern A nested namespace); org scope reads through
|
|
401
|
-
* `capxul.organizations.externalAccounts.list({ organizationId })`.
|
|
402
|
-
* Both resolve to the same Convex query handler — the SDK ergonomics
|
|
403
|
-
* differ. Backend filters out `revoked` rows but keeps
|
|
404
|
-
* `pending_verification` rows visible (D5).
|
|
405
|
-
*/
|
|
406
|
-
declare function useExternalAccounts(args: OwnerRef): QueryResult<List<ExternalAccount>>;
|
|
407
|
-
/**
|
|
408
|
-
* Funds v1 PR-2b (#421) — wired through the SDK.
|
|
409
|
-
*
|
|
410
|
-
* Branches on `args.ownerKind`: `account` scope reads through
|
|
411
|
-
* `capxul.accounts.subAccounts.list({ accountId })`; `organization`
|
|
412
|
-
* scope reads through `capxul.organizations.subAccounts.list({
|
|
413
|
-
* organizationId })`. Both resolve to the same Convex domain (server
|
|
414
|
-
* derives the writer scope per Pattern A — see `sdk.md`). The SDK
|
|
415
|
-
* has already branded each row via `tryBrandSubAccount`, so consumers
|
|
416
|
-
* receive `List<SubAccount>` with `SubAccountId`, `Money`, and
|
|
417
|
-
* `TimestampIso` in place.
|
|
418
|
-
*
|
|
419
|
-
* Note: `OwnerRef` admits only `"account" | "organization"`. A
|
|
420
|
-
* `sub_account` owner is a type error at the call site — not a runtime
|
|
421
|
-
* not-supported branch — because there is no `listChildSubAccounts`
|
|
422
|
-
* backend endpoint.
|
|
423
|
-
*/
|
|
424
|
-
declare function useSubAccounts(args: OwnerRef): QueryResult<List<SubAccount>>;
|
|
425
|
-
declare function useVirtualAccounts(_filters?: VirtualAccountsFilters): QueryResult<List<VirtualAccount>>;
|
|
426
|
-
declare function useVirtualCards(_filters?: VirtualCardsFilters): QueryResult<List<VirtualCard>>;
|
|
427
|
-
/**
|
|
428
|
-
* Personal-scope payments feed (cursor-paginated per §4.16). Org-scope
|
|
429
|
-
* payments live on `useOrgPayments` per §4.30 (Shape A).
|
|
430
|
-
*/
|
|
431
|
-
declare function usePayments(filters?: PaymentsFilters): UseQueryResult<List<Payment>, CapxulError$1>;
|
|
432
|
-
declare function useOrgPayments(_args: OrgScopedFilters): QueryResult<List<Payment>>;
|
|
433
|
-
declare function useTransfers(_filters?: TransfersFilters): QueryResult<List<Transfer>>;
|
|
434
|
-
declare function useOrgTransfers(_args: OrgScopedFilters): QueryResult<List<Transfer>>;
|
|
435
|
-
/**
|
|
436
|
-
* **NON-CANONICAL** raw on-chain ERC-20 transfer feed. Wired through
|
|
437
|
-
* `capxul.tokenTransfers.list` per slice/02-story2-balance Option-A
|
|
438
|
-
* verdict. Will be subsumed by canonical `useTransfers` once the
|
|
439
|
-
* `transfers.*` shape alignment lands. See `core/token-transfers.ts`
|
|
440
|
-
* doc-comment for the full contract.
|
|
441
|
-
*
|
|
442
|
-
* Intentionally NOT in `packages/sdk-react/ops/proof/hook-manifest.ts`
|
|
443
|
-
* — the canonical proof manifest tracks canon-aligned hooks only.
|
|
444
|
-
*/
|
|
445
|
-
declare function useTokenTransfers(filters?: TokenTransfersListInput): QueryResult<TokenTransfersListPage>;
|
|
446
|
-
/**
|
|
447
|
-
* Append-only per-owner balance-delta feed. Live for late
|
|
448
|
-
* `paymentId` / `transferId` attachment per Doc 02.
|
|
449
|
-
*/
|
|
450
|
-
declare function useBalanceLedger(args: OwnerScopedFilters): QueryResult<List<BalanceLedgerEntry>>;
|
|
451
|
-
declare function useAccountBalanceLedger(accountId: AccountId, filters?: PaginationFilters): QueryResult<List<BalanceLedgerEntry>>;
|
|
452
|
-
declare function useOrgBalanceLedger(args: OrgScopedFilters): QueryResult<List<BalanceLedgerEntry>>;
|
|
453
|
-
/**
|
|
454
|
-
* Personal-scope documents. `filters.type` narrows the polymorphic
|
|
455
|
-
* `Document` union to a single variant (invoice, payroll_run,
|
|
456
|
-
* receipt, etc. per §4.50).
|
|
457
|
-
*/
|
|
458
|
-
declare function useDocuments(_filters?: DocumentsFilters): QueryResult<List<Document>>;
|
|
459
|
-
declare function useOrgDocuments(_args: OrgDocumentsFilters): QueryResult<List<Document>>;
|
|
460
|
-
/**
|
|
461
|
-
* Withdrawals v1 slice 1 (#440) — wired through `capxul.withdrawals.list`.
|
|
462
|
-
*/
|
|
463
|
-
declare function useWithdrawals(filters?: WithdrawalsFilters): QueryResult<List<Withdrawal>>;
|
|
464
|
-
/**
|
|
465
|
-
* Withdrawals v1 slice 1 (#440) — wired through
|
|
466
|
-
* `capxul.organizations.withdrawals.list`.
|
|
467
|
-
*/
|
|
468
|
-
declare function useOrgWithdrawals(args: OrgScopedFilters): QueryResult<List<Withdrawal>>;
|
|
469
|
-
/**
|
|
470
|
-
* Org-admin lens only — the hook NEVER returns `secret` for any row.
|
|
471
|
-
*/
|
|
472
|
-
declare function useApiKeys(_organizationId: OrganizationId): QueryResult<List<ApiKey>>;
|
|
473
|
-
/**
|
|
474
|
-
* Org-admin / service-key lens — org scope is inferred from the
|
|
475
|
-
* api-key claim, so no `organizationId` argument is needed.
|
|
476
|
-
*/
|
|
477
|
-
declare function useWebhookEndpoints(): QueryResult<List<WebhookEndpoint>>;
|
|
478
|
-
|
|
479
|
-
/**
|
|
480
|
-
* Org-scoped member mutation hooks — TanStack `useMutation` wrappers.
|
|
481
|
-
*
|
|
482
|
-
* Slice 5 (#627): invite, accept, updateRole, revoke, remove, resend.
|
|
483
|
-
* Each hook returns the standard `{ mutate, mutateAsync, isPending, error, data }`
|
|
484
|
-
* shape so consumers can fire-and-forget or await + handle errors.
|
|
485
|
-
*/
|
|
486
|
-
|
|
487
|
-
type InviteMemberArgs = {
|
|
488
|
-
readonly organizationId: OrganizationId;
|
|
489
|
-
readonly email: string;
|
|
490
|
-
readonly role: Member["role"];
|
|
491
|
-
};
|
|
492
|
-
type AcceptInvitationArgs = {
|
|
493
|
-
readonly token: string;
|
|
494
|
-
};
|
|
495
|
-
type UpdateMemberRoleArgs = {
|
|
496
|
-
readonly organizationId: OrganizationId;
|
|
497
|
-
readonly memberId: MemberId;
|
|
498
|
-
readonly role: Member["role"];
|
|
499
|
-
};
|
|
500
|
-
type RevokeMemberArgs = {
|
|
501
|
-
readonly organizationId: OrganizationId;
|
|
502
|
-
readonly memberId: MemberId;
|
|
503
|
-
};
|
|
504
|
-
type RemoveMemberArgs = {
|
|
505
|
-
readonly organizationId: OrganizationId;
|
|
506
|
-
readonly memberId: MemberId;
|
|
507
|
-
};
|
|
508
|
-
type ResendInvitationArgs = {
|
|
509
|
-
readonly organizationId: OrganizationId;
|
|
510
|
-
readonly memberId: MemberId;
|
|
511
|
-
};
|
|
512
|
-
declare function useInviteMember(): UseMutationResult<MemberInviteResponse, CapxulError$1, InviteMemberArgs>;
|
|
513
|
-
declare function useAcceptInvitation(): UseMutationResult<Member, CapxulError$1, AcceptInvitationArgs>;
|
|
514
|
-
declare function useUpdateMemberRole(): UseMutationResult<Member, CapxulError$1, UpdateMemberRoleArgs>;
|
|
515
|
-
declare function useRevokeMember(): UseMutationResult<Member, CapxulError$1, RevokeMemberArgs>;
|
|
516
|
-
declare function useRemoveMember(): UseMutationResult<void, CapxulError$1, RemoveMemberArgs>;
|
|
517
|
-
declare function useResendInvitation(): UseMutationResult<MemberInviteResponse, CapxulError$1, ResendInvitationArgs>;
|
|
518
|
-
|
|
519
|
-
/**
|
|
520
|
-
* Public Capxul username. 3–30 chars, letter-first, lowercased,
|
|
521
|
-
* remaining chars from `[a-z0-9_-]` (per `CANON.md` §4.54 and
|
|
522
|
-
* `sdk-surface.md` §5h). Constructor lowercases before validating so
|
|
523
|
-
* mixed-case input canonicalizes cleanly when the first char is a
|
|
524
|
-
* letter; purely invalid shapes (too short, illegal chars, digit-first)
|
|
525
|
-
* still throw.
|
|
526
|
-
*/
|
|
527
|
-
type Username = string & {
|
|
528
|
-
readonly __capxulUsernameBrand: "Username";
|
|
529
|
-
};
|
|
530
|
-
|
|
531
|
-
type User = {
|
|
532
|
-
readonly account: Account;
|
|
533
|
-
readonly username: Username;
|
|
534
|
-
readonly safe: Safe;
|
|
535
|
-
readonly session: Session;
|
|
536
|
-
};
|
|
537
|
-
type AuthState = "idle" | "sendingOtp" | "awaitingOtp" | "bootstrapRequired" | "provisioningSigner" | "bootstrapping" | "authenticated" | "error";
|
|
538
|
-
type BootstrapContinuation = {
|
|
539
|
-
readonly bootstrapToken: AuthBootstrapToken;
|
|
540
|
-
readonly email: string;
|
|
541
|
-
readonly reason: AuthBootstrapReason;
|
|
542
|
-
readonly username?: Username;
|
|
543
|
-
readonly session: Session;
|
|
544
|
-
};
|
|
545
|
-
type AuthVerifyResult = {
|
|
546
|
-
readonly kind: "existing_member";
|
|
547
|
-
readonly session: Session;
|
|
548
|
-
readonly user: User;
|
|
549
|
-
} | {
|
|
550
|
-
readonly kind: "bootstrap_required";
|
|
551
|
-
readonly session: Session;
|
|
552
|
-
readonly bootstrap: BootstrapContinuation;
|
|
553
|
-
};
|
|
554
|
-
type UseAuthResult = {
|
|
555
|
-
readonly state: AuthState;
|
|
556
|
-
readonly user: User | null;
|
|
557
|
-
readonly bootstrap: BootstrapContinuation | null;
|
|
558
|
-
readonly error: Error | null;
|
|
559
|
-
readonly signIn: (email: string) => Promise<void>;
|
|
560
|
-
readonly verifyOtp: (email: string, otp: string) => Promise<AuthVerifyResult>;
|
|
561
|
-
readonly completeBootstrap: (username: Username, signer?: Account$1) => Promise<User>;
|
|
562
|
-
readonly signOut: () => Promise<void>;
|
|
563
|
-
};
|
|
564
|
-
type UseAuthOptions = {
|
|
565
|
-
/** Optional external signer to use during bootstrap instead of auto-provisioning. */
|
|
566
|
-
readonly signer?: Account$1;
|
|
567
|
-
};
|
|
568
|
-
/**
|
|
569
|
-
* Canonical auth hook.
|
|
570
|
-
*
|
|
571
|
-
* Reactive state (`state`, `user`, `error`) is suitable for UI
|
|
572
|
-
* observers; `signIn`, `verifyOtp`, and `signOut` return promises so
|
|
573
|
-
* the reference CLI can drive the flow imperatively.
|
|
574
|
-
*
|
|
575
|
-
* OTP verification is intentionally branch-explicit: existing members
|
|
576
|
-
* authenticate immediately, while first-run or incomplete accounts stop
|
|
577
|
-
* at `bootstrapRequired` until the caller chooses a username and calls
|
|
578
|
-
* `completeBootstrap()`.
|
|
579
|
-
*
|
|
580
|
-
* `completeBootstrap()` auto-provisions a fresh local-private-key signer
|
|
581
|
-
* via `SignerProvisioner` unless the caller passes or configures an
|
|
582
|
-
* explicit signer. Test harnesses use that override to keep the actor's
|
|
583
|
-
* signer stable across later dogfooding operations.
|
|
584
|
-
*/
|
|
585
|
-
declare function useAuth(options?: UseAuthOptions): UseAuthResult;
|
|
586
|
-
|
|
587
|
-
declare function useOnboardingFlow(): {
|
|
588
|
-
readonly snapshot: xstate.MachineSnapshot<any, any, any, any, any, any, any, any>;
|
|
589
|
-
readonly send: (event: any) => void;
|
|
590
|
-
};
|
|
591
|
-
declare function useProvisioningFlow(): {
|
|
592
|
-
readonly snapshot: xstate.MachineSnapshot<any, any, any, any, any, any, any, any>;
|
|
593
|
-
readonly send: (event: any) => void;
|
|
594
|
-
};
|
|
595
|
-
|
|
596
|
-
/**
|
|
597
|
-
* Browser-side Capxul SDK config — public ergonomics for `@capxul/sdk-react`
|
|
598
|
-
* consumers.
|
|
599
|
-
*
|
|
600
|
-
* The canonical type lives in `@capxul/sdk` (`transport.ts`); this file
|
|
601
|
-
* re-exports it so consumers can `import { BrowserCapxulConfig,
|
|
602
|
-
* createCapxulConfig } from "@capxul/sdk-react"` without crossing the
|
|
603
|
-
* package boundary themselves. The `BrowserCapxulConfig` discriminated
|
|
604
|
-
* union stays single-source-of-truth in `@capxul/sdk` so Stack 2 can
|
|
605
|
-
* extend it in-place when the `publishable-key` arm lands.
|
|
606
|
-
*
|
|
607
|
-
* `createCapxulConfig` is a runtime validator + freezer. It rejects
|
|
608
|
-
* secret/server-only fields (apiKey, data, signer, ...) per ADR 5 and
|
|
609
|
-
* PR #393's `assertBrowserCapxulConfig` precedent, but every error is
|
|
610
|
-
* a typed `CapxulError` produced by `Errors.invalidInput()` — never a
|
|
611
|
-
* raw `new Error(...)` (per `.claude/rules/error-handling.md`).
|
|
612
|
-
*/
|
|
613
|
-
|
|
614
|
-
/**
|
|
615
|
-
* Validate + freeze a `BrowserCapxulConfig`. The returned value is the
|
|
616
|
-
* same input object frozen via `Object.freeze` so callers cannot mutate
|
|
617
|
-
* it after handoff.
|
|
618
|
-
*
|
|
619
|
-
* Throws `Errors.invalidInput(...)` on:
|
|
620
|
-
* - any unknown key (rejects `apiKey`, `data`, `signer`, `fetch`, typos,
|
|
621
|
-
* Stack-2 server-only additions — the allow-list approach is
|
|
622
|
-
* secret-safe by default)
|
|
623
|
-
* - missing required field for the active `mode` arm
|
|
624
|
-
* - an unknown `mode` value (exhaustive guard via `Errors.internalError`)
|
|
625
|
-
*/
|
|
626
|
-
declare function createCapxulConfig(input: BrowserCapxulConfig): BrowserCapxulConfig;
|
|
627
|
-
|
|
628
|
-
type CapxulConnectorKind = "injected" | "local-private-key";
|
|
629
|
-
type CapxulConnectorSession = {
|
|
630
|
-
readonly connectorId: string;
|
|
631
|
-
readonly connectorKind: CapxulConnectorKind;
|
|
632
|
-
readonly signerAddress: string;
|
|
633
|
-
};
|
|
634
|
-
type CapxulConnector = {
|
|
635
|
-
readonly id: string;
|
|
636
|
-
readonly name: string;
|
|
637
|
-
readonly kind: CapxulConnectorKind;
|
|
638
|
-
readonly autoConnect?: boolean;
|
|
639
|
-
connect(): Promise<CapxulConnectorSession>;
|
|
640
|
-
disconnect?(): Promise<void>;
|
|
641
|
-
};
|
|
642
|
-
type InjectedConnectorOptions = {
|
|
643
|
-
readonly id?: string;
|
|
644
|
-
readonly name?: string;
|
|
645
|
-
};
|
|
646
|
-
type LocalPrivateKeyConnectorOptions = {
|
|
647
|
-
readonly privateKey: `0x${string}`;
|
|
648
|
-
readonly id?: string;
|
|
649
|
-
readonly name?: string;
|
|
650
|
-
};
|
|
651
|
-
/**
|
|
652
|
-
* Resolve a signer through an injected EIP-1193 provider (e.g.
|
|
653
|
-
* MetaMask via `window.ethereum`).
|
|
654
|
-
*
|
|
655
|
-
* Throws `Errors.providerError("connector", "injected", cause)` on
|
|
656
|
-
* provider absence or empty `eth_requestAccounts` response. Provider
|
|
657
|
-
* rejections (user closed the prompt) bubble up unchanged so callers
|
|
658
|
-
* can map them per UX requirements.
|
|
659
|
-
*/
|
|
660
|
-
declare function injectedConnector(options?: InjectedConnectorOptions): CapxulConnector;
|
|
661
|
-
/**
|
|
662
|
-
* Resolve a signer from a local private key (dev / e2e harness path).
|
|
663
|
-
*
|
|
664
|
-
* Validates the private key shape (`0x` + 64 hex chars) synchronously
|
|
665
|
-
* at factory time so misconfig surfaces before any UI flow advances.
|
|
666
|
-
* Per-call `connect()` is pure computation — `privateKeyToAccount`
|
|
667
|
-
* derives the address from the key with no I/O.
|
|
668
|
-
*
|
|
669
|
-
* Throws `Errors.invalidInput(...)` on bad inputs.
|
|
670
|
-
*/
|
|
671
|
-
declare function localPrivateKeyConnector(options: LocalPrivateKeyConnectorOptions): CapxulConnector;
|
|
672
|
-
|
|
673
|
-
export { type AuthState, type AuthVerifyResult, type BootstrapContinuation, CapxulClientProvider, type CapxulClientProviderProps, type CapxulConnector, type CapxulConnectorKind, type CapxulConnectorSession, CapxulProvider, type CapxulProviderProps, CapxulTransportProvider, type CapxulTransportProviderProps, type DocumentsFilters, type InjectedConnectorOptions, type LocalPrivateKeyConnectorOptions, type OrgDocumentsFilters, type OrgScopedFilters, type OwnerRef, type OwnerScopedFilters, type PaginationFilters, type PaymentsFilters, type QueryResult, type TransfersFilters, type UseApiKeyArgs, type UseAuthOptions, type UseAuthResult, type UseBalanceLedgerEntryArgs, type UseExternalAccountArgs, type UseMemberArgs, type UseTokenTransferArgs, type User, type VirtualAccountsFilters, type VirtualCardsFilters, type WithdrawalsFilters, createCapxulConfig, injectedConnector, localPrivateKeyConnector, useAcceptInvitation, useAccount, useAccountBalanceLedger, useApiKey, useApiKeys, useAuth, useBalanceLedger, useBalanceLedgerEntry, useCapxul, useCapxulStatus, useDocument, useDocuments, useExternalAccount, useExternalAccounts, useInviteMember, useKycProfile, useMe, useMember, useMembers, useOnboardingFlow, useOperation, useOrgBalanceLedger, useOrgDocuments, useOrgPayments, useOrgTransfers, useOrgWithdrawals, useOrganization, useOrganizations, usePayment, usePayments, useProvisioningFlow, useRemoveMember, useResendInvitation, useRevokeMember, useSafe, useSubAccount, useSubAccounts, useTokenTransfer, useTokenTransfers, useTransfer, useTransfers, useTreasury, useUpdateMemberRole, useVirtualAccount, useVirtualAccounts, useVirtualCard, useVirtualCards, useWebhookEndpoint, useWebhookEndpoints, useWebhookEvent, useWithdrawal, useWithdrawals };
|