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