@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/dist/index.d.cts
ADDED
|
@@ -0,0 +1,473 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { HttpTransport, TransportState, CapxulConfig, BrowserCapxulConfig, AccountId, OrganizationId, ApiKeyId, BalanceLedgerEntryId, ExternalAccountId, MemberId, Account, ApiKey, BalanceLedgerEntry, DocumentId, Document, ExternalAccount, KybProfile, KycProfile, CapxulError as CapxulError$1, Member, OperationId, Operation, Organization, PaymentId, Payment, SafeId, Safe, SubAccountId, SubAccount, TransferId, Transfer, Treasury, VirtualAccountId, VirtualAccount, VirtualCardId, VirtualCard, WebhookEndpointId, WebhookEndpoint, WebhookEventId, WebhookEvent, WithdrawalId, Withdrawal, List, LocalPrivateKeySignerProvider } from '@capxul/sdk';
|
|
3
|
+
export { AuthFlowContext, AuthFlowEvent, BrowserCapxulConfig, OnboardingFlowContext, OnboardingFlowEvent, ProvisioningFlowContext, ProvisioningFlowEvent } from '@capxul/sdk';
|
|
4
|
+
import { QueryClient, UseQueryResult } from '@tanstack/react-query';
|
|
5
|
+
import { CapxulClient } from '@capxul/sdk/client';
|
|
6
|
+
import { CapxulError } from '@capxul/sdk/errors';
|
|
7
|
+
import * as xstate from 'xstate';
|
|
8
|
+
|
|
9
|
+
type CapxulClientProviderProps = {
|
|
10
|
+
readonly client: CapxulClient;
|
|
11
|
+
readonly children: ReactNode;
|
|
12
|
+
};
|
|
13
|
+
declare function CapxulClientProvider({ client, children, }: CapxulClientProviderProps): ReactNode;
|
|
14
|
+
/**
|
|
15
|
+
* Returns the `@capxul/sdk` client attached to the nearest provider.
|
|
16
|
+
*
|
|
17
|
+
* @throws `Error` if called outside a provider subtree. This is a
|
|
18
|
+
* developer error, not a `CapxulError`, because a missing provider
|
|
19
|
+
* cannot be recovered at runtime.
|
|
20
|
+
*/
|
|
21
|
+
declare function useCapxul(): CapxulClient;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* `CapxulTransportContext` — sibling context that exposes the
|
|
25
|
+
* `HttpTransport` lifecycle singleton built by the lazy-DX
|
|
26
|
+
* `CapxulProvider` path (ADR #14c).
|
|
27
|
+
*
|
|
28
|
+
* Separate from `CapxulClientContext` because the legacy `config`
|
|
29
|
+
* path doesn't build an externally-observable transport. When the
|
|
30
|
+
* provider runs the legacy path, this context's value stays `null`
|
|
31
|
+
* and `useCapxulStatus()` reports `"ready"` as a permissive default
|
|
32
|
+
* (the legacy path implies the host has already wired auth and data;
|
|
33
|
+
* there is nothing for the consumer to gate on).
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
type CapxulTransportProviderProps = {
|
|
37
|
+
readonly transport: HttpTransport;
|
|
38
|
+
readonly children: ReactNode;
|
|
39
|
+
};
|
|
40
|
+
declare function CapxulTransportProvider({ transport, children, }: CapxulTransportProviderProps): ReactNode;
|
|
41
|
+
/**
|
|
42
|
+
* Read the transport's current lifecycle state. Subscribes via
|
|
43
|
+
* `useSyncExternalStore` so the host re-renders only when the
|
|
44
|
+
* transport's state machine transitions, not when the provider tree
|
|
45
|
+
* re-renders. Returns the `TransportState` discriminated union with
|
|
46
|
+
* the contract-locked statuses:
|
|
47
|
+
* `"idle" | "bootstrapping" | "ready" | "authenticated" | "error"`.
|
|
48
|
+
*
|
|
49
|
+
* Outside a provider tree (or inside the legacy `config` path that
|
|
50
|
+
* does not build an externally-observable transport), the hook
|
|
51
|
+
* returns a synthetic `{ status: "ready" }` snapshot — the legacy
|
|
52
|
+
* path implies the host has already wired auth + data so there is
|
|
53
|
+
* nothing to gate on.
|
|
54
|
+
*/
|
|
55
|
+
declare function useCapxulStatus(): TransportState;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* `CapxulProvider` — React context provider that wires both the
|
|
59
|
+
* `@capxul/sdk` client AND a TanStack Query `QueryClient` for the
|
|
60
|
+
* subtree.
|
|
61
|
+
*
|
|
62
|
+
* Two construction paths:
|
|
63
|
+
*
|
|
64
|
+
* 1. **Legacy / harness path** — pass an already-assembled
|
|
65
|
+
* `config: CapxulConfig`. Used by the e2e harness and CLI-shaped
|
|
66
|
+
* integrations that build their own auth/data adapters.
|
|
67
|
+
*
|
|
68
|
+
* 2. **Lazy-DX path (ADR #14c)** — pass either `publishableKey` or
|
|
69
|
+
* `browserConfig`. The provider builds an `HttpTransport`
|
|
70
|
+
* synchronously, injects it into `createCapxulClient` via the
|
|
71
|
+
* internal `_transport` slot, and exposes the transport through
|
|
72
|
+
* `CapxulTransportContext` so `useCapxulStatus()` can subscribe
|
|
73
|
+
* to its lifecycle state machine.
|
|
74
|
+
*
|
|
75
|
+
* The lazy-DX provider mounts synchronously. There is no
|
|
76
|
+
* `useState` mutating config, no `useMemo` rebuilding config when
|
|
77
|
+
* state changes, and no Suspense gate at mount. State transitions
|
|
78
|
+
* happen on the transport (a stable singleton); React subscribes
|
|
79
|
+
* via `useSyncExternalStore` and re-renders only the components
|
|
80
|
+
* that actually depend on the transport state.
|
|
81
|
+
*
|
|
82
|
+
* Per ADR 4 in the API-first architecture stack PLAN, only
|
|
83
|
+
* `QueryClientProvider` is allowed to live OUTSIDE the single
|
|
84
|
+
* `CapxulContext`. The `QueryClientProvider` is the outermost wrap;
|
|
85
|
+
* the SDK client provider sits inside it; the optional transport
|
|
86
|
+
* provider sits between the two when the lazy-DX path is active.
|
|
87
|
+
*/
|
|
88
|
+
|
|
89
|
+
type CapxulProviderProps = {
|
|
90
|
+
/**
|
|
91
|
+
* Pre-assembled `CapxulConfig` for the legacy / harness path.
|
|
92
|
+
* Mutually exclusive with `publishableKey` / `browserConfig`.
|
|
93
|
+
*/
|
|
94
|
+
readonly config?: CapxulConfig;
|
|
95
|
+
/**
|
|
96
|
+
* Shorthand for the publishable-key arm of `BrowserCapxulConfig`.
|
|
97
|
+
* Provider builds the transport synchronously and injects it into
|
|
98
|
+
* the SDK client — the canonical lazy-DX entry point per ADR #14c.
|
|
99
|
+
*/
|
|
100
|
+
readonly publishableKey?: string;
|
|
101
|
+
/**
|
|
102
|
+
* Full `BrowserCapxulConfig` for callers that need
|
|
103
|
+
* `mode: "build-time-urls"` or a custom `fetchImpl` (e.g. tests).
|
|
104
|
+
* Mutually exclusive with `publishableKey` / `config`.
|
|
105
|
+
*/
|
|
106
|
+
readonly browserConfig?: BrowserCapxulConfig;
|
|
107
|
+
/**
|
|
108
|
+
* Optional TanStack Query `QueryClient`. Pass your app's existing
|
|
109
|
+
* client to share the cache across the SDK hooks and the host
|
|
110
|
+
* app's own queries; omit to receive a default instance scoped to
|
|
111
|
+
* this provider with a 30s `staleTime`.
|
|
112
|
+
*/
|
|
113
|
+
readonly queryClient?: QueryClient;
|
|
114
|
+
readonly children: ReactNode;
|
|
115
|
+
};
|
|
116
|
+
declare function CapxulProvider({ config, publishableKey, browserConfig, queryClient, children, }: CapxulProviderProps): ReactNode;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* `QueryResult<T>` — the canonical three-state return shape for every
|
|
120
|
+
* read hook in `@capxul/sdk-react`, locked per CANON.md §4.29 and
|
|
121
|
+
* reaffirmed by the ADR #14c lazy-DX contract (item 4).
|
|
122
|
+
*
|
|
123
|
+
* Three variants:
|
|
124
|
+
* - `loading` — no data yet; the subscription is in flight (matches
|
|
125
|
+
* the contract's `"loading"` status)
|
|
126
|
+
* - `data` — data is live; will update reactively on next tick
|
|
127
|
+
* (the contract calls this `"ready"` colloquially — same semantics,
|
|
128
|
+
* different name; the canon name is binding)
|
|
129
|
+
* - `error` — terminal failure; `error.code` is a narrowed
|
|
130
|
+
* `CapxulErrorCode` so consumers can route via `matchError`
|
|
131
|
+
*
|
|
132
|
+
* Hooks NEVER throw for a "still loading" condition — the lazy-DX
|
|
133
|
+
* contract collapses the multi-step lifecycle (not-bootstrapped,
|
|
134
|
+
* bootstrapping, no-session, no-data, live) into these three states.
|
|
135
|
+
* Consumers that want to surface the underlying transport state use
|
|
136
|
+
* `useCapxulStatus()` which returns the 5-state `TransportState`
|
|
137
|
+
* union.
|
|
138
|
+
*
|
|
139
|
+
* `useMe()` is the first live hook and maps the SDK tuple into this
|
|
140
|
+
* shape. Hooks whose verticals have not landed still use the
|
|
141
|
+
* `NOT_IMPLEMENTED` helper below.
|
|
142
|
+
*/
|
|
143
|
+
|
|
144
|
+
type QueryResult<T> = {
|
|
145
|
+
readonly status: "loading";
|
|
146
|
+
} | {
|
|
147
|
+
readonly status: "data";
|
|
148
|
+
readonly data: T;
|
|
149
|
+
} | {
|
|
150
|
+
readonly status: "error";
|
|
151
|
+
readonly error: CapxulError;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Per-resource singular read hooks — 21 total.
|
|
156
|
+
*
|
|
157
|
+
* Catalogued in the reset hook proof matrix. `useMe()` is the first
|
|
158
|
+
* hook migrated to TanStack Query (PLAN.md task 1.8); it returns
|
|
159
|
+
* `UseQueryResult<Account, CapxulError>` and routes through
|
|
160
|
+
* `@capxul/sdk` `me.get()` with query key `["capxul", "me"]` and a
|
|
161
|
+
* 30s `staleTime` matching the `CapxulProvider` default. The
|
|
162
|
+
* remaining 19 hooks plus `useOperation()` still return
|
|
163
|
+
* `QueryResult<T>` per the reset transport contract — per-hook
|
|
164
|
+
* migration is the rollout pattern; later tasks lift each in turn.
|
|
165
|
+
* `useOperation()` routes through `operations.retrieve()` so harness
|
|
166
|
+
* observers can read durable operation state.
|
|
167
|
+
*
|
|
168
|
+
* Argument shapes follow sdk-surface.md §3b:
|
|
169
|
+
* - Single-ID reads take the branded ID directly
|
|
170
|
+
* - Composite-key reads (member, api-key, external account,
|
|
171
|
+
* balance-ledger entry) take an options object
|
|
172
|
+
* - Owner-scoped composite keys use a discriminated `OwnerRef`
|
|
173
|
+
*/
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Discriminated owner reference for hooks whose resource can belong
|
|
177
|
+
* to either a personal account or an organization.
|
|
178
|
+
*/
|
|
179
|
+
type OwnerRef = {
|
|
180
|
+
readonly ownerKind: "account";
|
|
181
|
+
readonly ownerId: AccountId;
|
|
182
|
+
} | {
|
|
183
|
+
readonly ownerKind: "organization";
|
|
184
|
+
readonly ownerId: OrganizationId;
|
|
185
|
+
};
|
|
186
|
+
type UseMemberArgs = {
|
|
187
|
+
readonly organizationId: OrganizationId;
|
|
188
|
+
readonly memberId: MemberId;
|
|
189
|
+
};
|
|
190
|
+
type UseApiKeyArgs = {
|
|
191
|
+
readonly organizationId: OrganizationId;
|
|
192
|
+
readonly apiKeyId: ApiKeyId;
|
|
193
|
+
};
|
|
194
|
+
type UseExternalAccountArgs = OwnerRef & {
|
|
195
|
+
readonly externalAccountId: ExternalAccountId;
|
|
196
|
+
};
|
|
197
|
+
type UseBalanceLedgerEntryArgs = OwnerRef & {
|
|
198
|
+
readonly entryId: BalanceLedgerEntryId;
|
|
199
|
+
};
|
|
200
|
+
/**
|
|
201
|
+
* The authenticated caller's identity (first-party only per §4.2).
|
|
202
|
+
*
|
|
203
|
+
* First hook migrated to TanStack Query per PLAN.md task 1.8.
|
|
204
|
+
* Cache key `[capxul.id, "capxul", "me"]`; `staleTime` of 30s
|
|
205
|
+
* matches the `CapxulProvider` default `QueryClient`. The query
|
|
206
|
+
* function maps the SDK tuple into TanStack's throw-on-error
|
|
207
|
+
* contract: a non-null `error` tuple slot is rethrown so TanStack
|
|
208
|
+
* surfaces it on the result, and a non-`CapxulError` thrown by the
|
|
209
|
+
* SDK transport is normalized to `CapxulError({ code: "UNKNOWN",
|
|
210
|
+
* cause })` so the `UseQueryResult` `error` channel is always typed
|
|
211
|
+
* `CapxulError`.
|
|
212
|
+
*
|
|
213
|
+
* The `capxul.id` leading segment isolates cache state across
|
|
214
|
+
* `CapxulClient` swaps. Without it, swapping the client inside the
|
|
215
|
+
* same `QueryClient` (e.g. after a sign-out / sign-in) would return
|
|
216
|
+
* the previous account's cached data for up to the 30s stale window.
|
|
217
|
+
* See Codex P1 finding on PR #406.
|
|
218
|
+
*/
|
|
219
|
+
declare function useMe(): UseQueryResult<Account, CapxulError$1>;
|
|
220
|
+
/**
|
|
221
|
+
* Account by id. Omit `accountId` for the calling user (alias for
|
|
222
|
+
* `useMe()` from a developer-perspective lens).
|
|
223
|
+
*/
|
|
224
|
+
declare function useAccount(_accountId?: AccountId): QueryResult<Account>;
|
|
225
|
+
declare function useOrganization(_organizationId: OrganizationId): QueryResult<Organization>;
|
|
226
|
+
declare function useMember(_args: UseMemberArgs): QueryResult<Member>;
|
|
227
|
+
/**
|
|
228
|
+
* Live; status advances as the indexer reconciles the on-chain
|
|
229
|
+
* deployment. Consumers pattern-match on `data.status` via
|
|
230
|
+
* `matchStatus` (see `@capxul/sdk`).
|
|
231
|
+
*/
|
|
232
|
+
declare function useSafe(_safeId: SafeId): QueryResult<Safe>;
|
|
233
|
+
declare function useTreasury(_organizationId: OrganizationId): QueryResult<Treasury>;
|
|
234
|
+
/**
|
|
235
|
+
* Org-admin lens only — the hook NEVER returns `secret`.
|
|
236
|
+
*/
|
|
237
|
+
declare function useApiKey(_args: UseApiKeyArgs): QueryResult<ApiKey>;
|
|
238
|
+
declare function useKycProfile(_accountId: AccountId): QueryResult<KycProfile>;
|
|
239
|
+
declare function useKybProfile(_organizationId: OrganizationId): QueryResult<KybProfile>;
|
|
240
|
+
declare function useExternalAccount(_args: UseExternalAccountArgs): QueryResult<ExternalAccount>;
|
|
241
|
+
declare function useSubAccount(_subAccountId: SubAccountId): QueryResult<SubAccount>;
|
|
242
|
+
declare function useVirtualAccount(_virtualAccountId: VirtualAccountId): QueryResult<VirtualAccount>;
|
|
243
|
+
declare function useVirtualCard(_virtualCardId: VirtualCardId): QueryResult<VirtualCard>;
|
|
244
|
+
declare function usePayment(_paymentId: PaymentId): QueryResult<Payment>;
|
|
245
|
+
declare function useTransfer(_transferId: TransferId): QueryResult<Transfer>;
|
|
246
|
+
/**
|
|
247
|
+
* Immutable once written; `live` semantically only for late
|
|
248
|
+
* `paymentId` / `transferId` attachment per Doc 02 §"balance_ledger".
|
|
249
|
+
*/
|
|
250
|
+
declare function useBalanceLedgerEntry(_args: UseBalanceLedgerEntryArgs): QueryResult<BalanceLedgerEntry>;
|
|
251
|
+
declare function useDocument(_documentId: DocumentId): QueryResult<Document>;
|
|
252
|
+
/**
|
|
253
|
+
* Withdrawals v1 slice 1 (#440) — wired through `capxul.withdrawals.retrieve`.
|
|
254
|
+
* Mirrors `useOperation` (the canonical evidence subscription) since
|
|
255
|
+
* the withdrawal resource is operation-shaped at its core.
|
|
256
|
+
*/
|
|
257
|
+
declare function useWithdrawal(withdrawalId: WithdrawalId): QueryResult<Withdrawal>;
|
|
258
|
+
/**
|
|
259
|
+
* The canonical evidence subscription per CANON.md §3.3 —
|
|
260
|
+
* `operationId` + `correlationId` are the cross-layer join keys for
|
|
261
|
+
* debugging any mutation's end-to-end trail.
|
|
262
|
+
*/
|
|
263
|
+
declare function useOperation(operationId: OperationId): QueryResult<Operation>;
|
|
264
|
+
/**
|
|
265
|
+
* Org-admin lens only — the hook NEVER returns `signingSecret`.
|
|
266
|
+
*/
|
|
267
|
+
declare function useWebhookEndpoint(_endpointId: WebhookEndpointId): QueryResult<WebhookEndpoint>;
|
|
268
|
+
declare function useWebhookEvent(_eventId: WebhookEventId): QueryResult<WebhookEvent>;
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Per-resource list read hooks — 17 total.
|
|
272
|
+
*
|
|
273
|
+
* Catalogued in Doc 08 §3. Every hook returns
|
|
274
|
+
* `QueryResult<List<T>>` per CANON.md §4.29. Slice C.1 scaffold:
|
|
275
|
+
* every hook returns `NOT_IMPLEMENTED` until Slice F wires real
|
|
276
|
+
* Convex subscriptions.
|
|
277
|
+
*
|
|
278
|
+
* Argument shapes follow sdk-surface.md §3b:
|
|
279
|
+
* - Cursor-paginated lists take `{ limit?, cursor? }` filters per
|
|
280
|
+
* §4.16 (cursor pagination convention)
|
|
281
|
+
* - Org-scoped lists take `organizationId` explicitly per §4.30
|
|
282
|
+
* (Shape A — no ambient org context)
|
|
283
|
+
* - Owner-scoped lists use the discriminated `OwnerRef`
|
|
284
|
+
*/
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Cursor-pagination filters shared by list hooks. Mirrors the input
|
|
288
|
+
* shape used by the vanilla SDK's `<domain>.list(...)` methods.
|
|
289
|
+
*/
|
|
290
|
+
type PaginationFilters = {
|
|
291
|
+
readonly limit?: number;
|
|
292
|
+
readonly cursor?: string;
|
|
293
|
+
};
|
|
294
|
+
type OptionalOwnerFilter = {
|
|
295
|
+
readonly ownerKind?: undefined;
|
|
296
|
+
readonly ownerId?: undefined;
|
|
297
|
+
};
|
|
298
|
+
type AccountOwnerFilter = {
|
|
299
|
+
readonly ownerKind: "account";
|
|
300
|
+
readonly ownerId: AccountId;
|
|
301
|
+
};
|
|
302
|
+
type SubAccountOwnerFilter = {
|
|
303
|
+
readonly ownerKind: "sub_account";
|
|
304
|
+
readonly ownerId: SubAccountId;
|
|
305
|
+
};
|
|
306
|
+
type OrganizationOwnerFilter = {
|
|
307
|
+
readonly ownerKind: "organization";
|
|
308
|
+
readonly ownerId: OrganizationId;
|
|
309
|
+
};
|
|
310
|
+
/**
|
|
311
|
+
* Filters for virtual-account listing. Narrows by owner when both
|
|
312
|
+
* `ownerKind` and `ownerId` are supplied; otherwise returns every
|
|
313
|
+
* virtual account the caller can see across their scope.
|
|
314
|
+
*/
|
|
315
|
+
type VirtualAccountsFilters = PaginationFilters & (OptionalOwnerFilter | AccountOwnerFilter | SubAccountOwnerFilter | OrganizationOwnerFilter);
|
|
316
|
+
type VirtualCardsFilters = PaginationFilters & (OptionalOwnerFilter | AccountOwnerFilter | SubAccountOwnerFilter | OrganizationOwnerFilter);
|
|
317
|
+
type DocumentsFilters = PaginationFilters & {
|
|
318
|
+
readonly type?: "invoice" | "payroll_run" | "payroll_schedule" | "receipt" | "kyc_upload" | "bank_statement" | "tax_form";
|
|
319
|
+
};
|
|
320
|
+
type TransfersFilters = PaginationFilters;
|
|
321
|
+
type PaymentsFilters = PaginationFilters;
|
|
322
|
+
type WithdrawalsFilters = PaginationFilters;
|
|
323
|
+
type OwnerScopedFilters = OwnerRef & PaginationFilters;
|
|
324
|
+
type OrgScopedFilters = {
|
|
325
|
+
readonly organizationId: OrganizationId;
|
|
326
|
+
} & PaginationFilters;
|
|
327
|
+
type OrgDocumentsFilters = OrgScopedFilters & {
|
|
328
|
+
readonly type?: DocumentsFilters["type"];
|
|
329
|
+
};
|
|
330
|
+
/**
|
|
331
|
+
* "My orgs" — returns every organization the authenticated caller
|
|
332
|
+
* is a member of, with the co-member lens per row.
|
|
333
|
+
*/
|
|
334
|
+
declare function useOrganizations(): QueryResult<List<Organization>>;
|
|
335
|
+
declare function useMembers(_organizationId: OrganizationId): QueryResult<List<Member>>;
|
|
336
|
+
declare function useExternalAccounts(_args: OwnerRef): QueryResult<List<ExternalAccount>>;
|
|
337
|
+
declare function useSubAccounts(_args: OwnerRef): QueryResult<List<SubAccount>>;
|
|
338
|
+
declare function useVirtualAccounts(_filters?: VirtualAccountsFilters): QueryResult<List<VirtualAccount>>;
|
|
339
|
+
declare function useVirtualCards(_filters?: VirtualCardsFilters): QueryResult<List<VirtualCard>>;
|
|
340
|
+
/**
|
|
341
|
+
* Personal-scope payments feed (cursor-paginated per §4.16). Org-scope
|
|
342
|
+
* payments live on `useOrgPayments` per §4.30 (Shape A).
|
|
343
|
+
*/
|
|
344
|
+
declare function usePayments(_filters?: PaymentsFilters): QueryResult<List<Payment>>;
|
|
345
|
+
declare function useOrgPayments(_args: OrgScopedFilters): QueryResult<List<Payment>>;
|
|
346
|
+
declare function useTransfers(_filters?: TransfersFilters): QueryResult<List<Transfer>>;
|
|
347
|
+
declare function useOrgTransfers(_args: OrgScopedFilters): QueryResult<List<Transfer>>;
|
|
348
|
+
/**
|
|
349
|
+
* Append-only per-owner balance-delta feed. Live for late
|
|
350
|
+
* `paymentId` / `transferId` attachment per Doc 02.
|
|
351
|
+
*/
|
|
352
|
+
declare function useBalanceLedger(_args: OwnerScopedFilters): QueryResult<List<BalanceLedgerEntry>>;
|
|
353
|
+
/**
|
|
354
|
+
* Personal-scope documents. `filters.type` narrows the polymorphic
|
|
355
|
+
* `Document` union to a single variant (invoice, payroll_run,
|
|
356
|
+
* receipt, etc. per §4.50).
|
|
357
|
+
*/
|
|
358
|
+
declare function useDocuments(_filters?: DocumentsFilters): QueryResult<List<Document>>;
|
|
359
|
+
declare function useOrgDocuments(_args: OrgDocumentsFilters): QueryResult<List<Document>>;
|
|
360
|
+
/**
|
|
361
|
+
* Withdrawals v1 slice 1 (#440) — wired through `capxul.withdrawals.list`.
|
|
362
|
+
*/
|
|
363
|
+
declare function useWithdrawals(filters?: WithdrawalsFilters): QueryResult<List<Withdrawal>>;
|
|
364
|
+
/**
|
|
365
|
+
* Withdrawals v1 slice 1 (#440) — wired through
|
|
366
|
+
* `capxul.organizations.withdrawals.list`.
|
|
367
|
+
*/
|
|
368
|
+
declare function useOrgWithdrawals(args: OrgScopedFilters): QueryResult<List<Withdrawal>>;
|
|
369
|
+
/**
|
|
370
|
+
* Org-admin lens only — the hook NEVER returns `secret` for any row.
|
|
371
|
+
*/
|
|
372
|
+
declare function useApiKeys(_organizationId: OrganizationId): QueryResult<List<ApiKey>>;
|
|
373
|
+
/**
|
|
374
|
+
* Org-admin / service-key lens — org scope is inferred from the
|
|
375
|
+
* api-key claim, so no `organizationId` argument is needed.
|
|
376
|
+
*/
|
|
377
|
+
declare function useWebhookEndpoints(): QueryResult<List<WebhookEndpoint>>;
|
|
378
|
+
|
|
379
|
+
declare function useAuthFlow(): {
|
|
380
|
+
readonly snapshot: xstate.MachineSnapshot<any, any, any, any, any, any, any, any>;
|
|
381
|
+
readonly send: (event: any) => void;
|
|
382
|
+
};
|
|
383
|
+
declare function useOnboardingFlow(): {
|
|
384
|
+
readonly snapshot: xstate.MachineSnapshot<any, any, any, any, any, any, any, any>;
|
|
385
|
+
readonly send: (event: any) => void;
|
|
386
|
+
};
|
|
387
|
+
declare function useProvisioningFlow(): {
|
|
388
|
+
readonly snapshot: xstate.MachineSnapshot<any, any, any, any, any, any, any, any>;
|
|
389
|
+
readonly send: (event: any) => void;
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Browser-side Capxul SDK config — public ergonomics for `@capxul/sdk-react`
|
|
394
|
+
* consumers.
|
|
395
|
+
*
|
|
396
|
+
* The canonical type lives in `@capxul/sdk` (`transport.ts`); this file
|
|
397
|
+
* re-exports it so consumers can `import { BrowserCapxulConfig,
|
|
398
|
+
* createCapxulConfig } from "@capxul/sdk-react"` without crossing the
|
|
399
|
+
* package boundary themselves. The `BrowserCapxulConfig` discriminated
|
|
400
|
+
* union stays single-source-of-truth in `@capxul/sdk` so Stack 2 can
|
|
401
|
+
* extend it in-place when the `publishable-key` arm lands.
|
|
402
|
+
*
|
|
403
|
+
* `createCapxulConfig` is a runtime validator + freezer. It rejects
|
|
404
|
+
* secret/server-only fields (apiKey, data, signer, ...) per ADR 5 and
|
|
405
|
+
* PR #393's `assertBrowserCapxulConfig` precedent, but every error is
|
|
406
|
+
* a typed `CapxulError` produced by `Errors.invalidInput()` — never a
|
|
407
|
+
* raw `new Error(...)` (per `.claude/rules/error-handling.md`).
|
|
408
|
+
*/
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* Validate + freeze a `BrowserCapxulConfig`. The returned value is the
|
|
412
|
+
* same input object frozen via `Object.freeze` so callers cannot mutate
|
|
413
|
+
* it after handoff.
|
|
414
|
+
*
|
|
415
|
+
* Throws `Errors.invalidInput(...)` on:
|
|
416
|
+
* - any unknown key (rejects `apiKey`, `data`, `signer`, `fetch`, typos,
|
|
417
|
+
* Stack-2 server-only additions — the allow-list approach is
|
|
418
|
+
* secret-safe by default)
|
|
419
|
+
* - missing required field for the active `mode` arm
|
|
420
|
+
* - an unknown `mode` value (exhaustive guard via `Errors.internalError`)
|
|
421
|
+
*/
|
|
422
|
+
declare function createCapxulConfig(input: BrowserCapxulConfig): BrowserCapxulConfig;
|
|
423
|
+
|
|
424
|
+
type CapxulConnectorKind = "injected" | "local-private-key";
|
|
425
|
+
type CapxulConnectorSession = {
|
|
426
|
+
readonly connectorId: string;
|
|
427
|
+
readonly connectorKind: CapxulConnectorKind;
|
|
428
|
+
readonly signerAddress: string;
|
|
429
|
+
readonly safeAddress?: string;
|
|
430
|
+
readonly signerProvider?: LocalPrivateKeySignerProvider;
|
|
431
|
+
};
|
|
432
|
+
type CapxulConnector = {
|
|
433
|
+
readonly id: string;
|
|
434
|
+
readonly name: string;
|
|
435
|
+
readonly kind: CapxulConnectorKind;
|
|
436
|
+
readonly autoConnect?: boolean;
|
|
437
|
+
connect(): Promise<CapxulConnectorSession>;
|
|
438
|
+
disconnect?(): Promise<void>;
|
|
439
|
+
};
|
|
440
|
+
type InjectedConnectorOptions = {
|
|
441
|
+
readonly id?: string;
|
|
442
|
+
readonly name?: string;
|
|
443
|
+
};
|
|
444
|
+
type LocalPrivateKeyConnectorOptions = {
|
|
445
|
+
readonly privateKey: `0x${string}`;
|
|
446
|
+
readonly safeAddress: string;
|
|
447
|
+
readonly id?: string;
|
|
448
|
+
readonly name?: string;
|
|
449
|
+
};
|
|
450
|
+
/**
|
|
451
|
+
* Resolve a signer through an injected EIP-1193 provider (e.g.
|
|
452
|
+
* MetaMask via `window.ethereum`).
|
|
453
|
+
*
|
|
454
|
+
* Throws `Errors.providerError("connector", "injected", cause)` on
|
|
455
|
+
* provider absence or empty `eth_requestAccounts` response. Provider
|
|
456
|
+
* rejections (user closed the prompt) bubble up unchanged so callers
|
|
457
|
+
* can map them per UX requirements.
|
|
458
|
+
*/
|
|
459
|
+
declare function injectedConnector(options?: InjectedConnectorOptions): CapxulConnector;
|
|
460
|
+
/**
|
|
461
|
+
* Resolve a signer from a local private key (dev / e2e harness path).
|
|
462
|
+
*
|
|
463
|
+
* Validates the private key shape (`0x` + 64 hex chars) and the
|
|
464
|
+
* required `safeAddress` synchronously at factory time so misconfig
|
|
465
|
+
* surfaces before any UI flow advances. Per-call `connect()` is pure
|
|
466
|
+
* computation — `privateKeyToAccount` derives the address from the
|
|
467
|
+
* key with no I/O.
|
|
468
|
+
*
|
|
469
|
+
* Throws `Errors.invalidInput(...)` on bad inputs.
|
|
470
|
+
*/
|
|
471
|
+
declare function localPrivateKeyConnector(options: LocalPrivateKeyConnectorOptions): CapxulConnector;
|
|
472
|
+
|
|
473
|
+
export { 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 UseBalanceLedgerEntryArgs, type UseExternalAccountArgs, type UseMemberArgs, type VirtualAccountsFilters, type VirtualCardsFilters, type WithdrawalsFilters, createCapxulConfig, injectedConnector, localPrivateKeyConnector, useAccount, useApiKey, useApiKeys, useAuthFlow, useBalanceLedger, useBalanceLedgerEntry, useCapxul, useCapxulStatus, useDocument, useDocuments, useExternalAccount, useExternalAccounts, useKybProfile, useKycProfile, useMe, useMember, useMembers, useOnboardingFlow, useOperation, useOrgDocuments, useOrgPayments, useOrgTransfers, useOrgWithdrawals, useOrganization, useOrganizations, usePayment, usePayments, useProvisioningFlow, useSafe, useSubAccount, useSubAccounts, useTransfer, useTransfers, useTreasury, useVirtualAccount, useVirtualAccounts, useVirtualCard, useVirtualCards, useWebhookEndpoint, useWebhookEndpoints, useWebhookEvent, useWithdrawal, useWithdrawals };
|