@capxul/sdk 0.1.0-alpha.8 → 0.2.0-alpha.3

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 CHANGED
@@ -1,5 +1,127 @@
1
1
  # @capxul/sdk
2
2
 
3
+ ## 0.2.0-alpha.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 5b99a9b: **Publishable-key path + error classification (#675).** Two tangled bugs landed in the consumer-path proof.
8
+
9
+ **Reference-cli was on the wrong path.** `build-browser-config.ts` had a `build-time-urls` fallback that fired silently whenever `CAPXUL_REF_PUBLISHABLE_KEY` was unset, so the CLI routed direct to Convex URLs and bypassed `/v1/client/bootstrap` entirely. It "worked" through a code path no external SDK consumer will ever run, masking publishable-key path breakage.
10
+
11
+ Reference-cli now:
12
+ - Requires `CAPXUL_REF_PUBLISHABLE_KEY`. The repo ships a long-lived shared sandbox key at `apps/reference-cli/.env.example` so `git clone && export $(...)` works; the key targets `elated-oyster-269`, is environment `test` (`cap_pk_test_*`), and is intentionally shareable.
13
+ - Strips the `build-time-urls` arm entirely. There is no silent fallback — missing env produces a structured `ENV_MISSING` envelope with an actionable message.
14
+ - Keeps `bootstrap probe --mock` working env-less (the mock factory bypasses `buildBrowserInputs()`).
15
+
16
+ **Error classification.** The SDK's auth-layer catch was swallowing typed bootstrap errors. A bad publishable key produced HTTP 401 + `NOT_AUTHENTICATED: "Publishable key is invalid or revoked."` from the bootstrap endpoint, but `postBetterAuth`'s `catch (cause)` wrapped any throw from `transport.fetch()` as `NETWORK_ERROR: "BetterAuth … network failure."`, burying the real diagnosis on `cause`. Reference-cli then flattened further to `AUTH_ERROR`.
17
+
18
+ The SDK now:
19
+ - Preserves `CapxulError` verbatim in `postBetterAuth` and `exchangeConvexToken` catches. Genuine non-`CapxulError` throws still fall back to `NETWORK_ERROR`.
20
+ - Widens `SendOtpCodes` + `VerifyOtpCodes` to include `NOT_AUTHENTICATED` and `PERMISSION_DENIED` so consumers can exhaustively narrow bootstrap-layer errors.
21
+
22
+ **Consumer impact:** SDK consumers that switch on `err.code` from `auth.sendOtp` / `auth.verifyOtp` should now expect `NOT_AUTHENTICATED` (bad/revoked publishable key) and `PERMISSION_DENIED` (origin not on the key's allow-list) as additional possible codes alongside the existing BetterAuth + rate-limit codes. No type-narrowing regressions — the unions only widened.
23
+
24
+ ## 0.2.0-alpha.2
25
+
26
+ ### Minor Changes
27
+
28
+ - 995383f: Epic 660: Unified auth surface
29
+ - Introduces AuthService promise-based auth API replacing the imperative capxul.auth.\* tuple interface
30
+ - Adds SignerProvisioner for deterministic Safe v1.4.1 address derivation from viem signers
31
+ - Adds useAuth() React hook with reactive state + promise-based methods
32
+ - Deprecates useAuthFlow and useAuthBootstrapFlow in favor of useAuth()
33
+ - Migrates reference CLI auth commands (send-otp, verify-otp, signout) to useAuth()
34
+ - Migrates test surfaces: walkthroughs, type tests, e2e harness signup, lazy-dx provider
35
+ - Adds @repo/safe-derive workspace package for Safe address derivation utilities
36
+ - Aligns CapxulConfig.data to \_data with internal SDK transport ownership (Epic 652)
37
+ - Pins esbuild to 0.25.12 to fix binary-version skew in fresh worktrees
38
+
39
+ - 2ef4ee3: Reshape the organizations members surface around a single Membership entity
40
+ with a status lifecycle (`pending | active | revoked | expired`).
41
+ - Replaces the prior invitation/membership split (which produced a phantom
42
+ `MemberInvitation` type that never compiled) with a single `Member` type
43
+ exposing `status`, `email`, `acceptedAt`, `expiresAt`, and `resentCount`.
44
+ - New methods on `organizations.members.*`: `accept(token)`, `revoke(memberId)`,
45
+ `resend(memberId)`. `invite()` now returns a `MemberInviteResponse`
46
+ containing the raw invite token (returned once).
47
+ - Auto-accepts pending invitations on first sign-in for the matching email
48
+ via a BetterAuth post-signup hook.
49
+ - Nightly Convex cron expires overdue pending invitations.
50
+
51
+ Public type changes:
52
+ - Removed: `MemberInvitation` (was never exported; type didn't compile).
53
+ - Added: `MembershipStatus`, `MemberInviteResponse`.
54
+ - Updated: `Member` shape — see SDK reference for the full delta.
55
+
56
+ React hooks:
57
+ - New: `useAcceptInvitation`, `useRevokeMember`, `useResendInvitation`.
58
+ - Updated: `useInviteMember` returns `MemberInviteResponse` (was returning a
59
+ type that didn't exist).
60
+
61
+ Reference CLI:
62
+ - New commands: `org members invite`, `org members list`, `org members retrieve`,
63
+ `org members accept`, `org members updateRole`, `org members revoke`,
64
+ `org members remove`, `org members resend`.
65
+
66
+ - c7146bf: **Transport ownership (#656):** The SDK now owns construction of the
67
+ authenticated `ConvexHttpClient`. Consumers no longer wire `data` manually
68
+ or provide `auth.createDataClient`. After `verifyOtp` exchanges a Convex
69
+ JWT, the SDK builds the default data client internally via
70
+ `createDefaultDataClient` and stores it on `config._data`.
71
+ - `CapxulConfig.data` renamed to `_data` (internal test seam).
72
+ - `CapxulAuthConfig.createDataClient` removed from public types.
73
+ - `convex` moved from `peerDependencies` to `dependencies`.
74
+
75
+ ### Patch Changes
76
+
77
+ - Updated dependencies [995383f]
78
+ - @repo/safe-derive@0.0.1-alpha.0
79
+
80
+ ## 0.2.0-alpha.1
81
+
82
+ ### Minor Changes
83
+
84
+ - **Transport ownership (#656):** The SDK now owns construction of the
85
+ authenticated `ConvexHttpClient`. Consumers no longer wire `data` manually
86
+ or provide `auth.createDataClient`. After `verifyOtp` exchanges a Convex
87
+ JWT, the SDK builds the default data client internally via
88
+ `createDefaultDataClient` and stores it on `config._data`.
89
+ - `CapxulConfig.data` renamed to `_data` (internal test seam).
90
+ - `CapxulAuthConfig.createDataClient` removed from public types.
91
+ - `convex` moved from `peerDependencies` to `dependencies`.
92
+
93
+ ### Patch Changes
94
+
95
+ - Bundle `@repo/safe-derive` into the published artifact so the new
96
+ `SignerProvisioner` class works for external consumers.
97
+
98
+ ## 0.1.0-alpha.12
99
+
100
+ ### Minor Changes
101
+
102
+ - Publish the post-alpha.11 SDK and React SDK surface: funds v1 sub-account
103
+ runtime coverage, React hook wiring, payments list support, and the latest
104
+ generated Convex API snapshots used by current alpha consumers.
105
+
106
+ Note: alpha.10 and alpha.11 were intermediate runner artifacts from the
107
+ prior release pipeline (manual `package.json` bumps that were never folded
108
+ back into the repo). alpha.12 reconciles `package.json`, the changesets
109
+ state, and npm to a single consistent version.
110
+
111
+ ## 0.1.0-alpha.9
112
+
113
+ ### Minor Changes
114
+
115
+ - Add the canonical auth bootstrap flow.
116
+
117
+ `verifyOtp()` now resolves a verified email session into either an
118
+ `existing_member` identity or a `bootstrap_required` continuation. New and
119
+ incomplete members continue through `completeBootstrap()`, which validates a
120
+ server-issued bootstrap token, claims the username, provisions the account/Safe
121
+ through the backend bootstrap path, and returns the authenticated product
122
+ identity. The React SDK adds `useAuthBootstrapFlow()` as the typed first-run
123
+ flow wrapper.
124
+
3
125
  ## 0.1.0-alpha.8
4
126
 
5
127
  ### Minor Changes
package/README.md CHANGED
@@ -186,6 +186,51 @@ Helpers:
186
186
  - Branded type constructors — `toEmail`, `toAccountId`,
187
187
  `toOrganizationId`, … — never cast raw strings
188
188
 
189
+ ## Organizations
190
+
191
+ Create an organization, manage its treasury, and invite members with
192
+ role-based access:
193
+
194
+ ```ts
195
+ // Create
196
+ const [err, org] = await capxul.organizations.create({ name: "Acme" });
197
+
198
+ // Invite a member — returns the raw token once
199
+ const [err, { member, inviteToken }] = await capxul.organizations.members.invite({
200
+ organizationId: org.id,
201
+ email: "alice@example.com",
202
+ role: "finance_manager",
203
+ });
204
+
205
+ // List members — defaults to active; pass status to filter
206
+ const [err, list] = await capxul.organizations.members.list({
207
+ organizationId: org.id,
208
+ status: "pending", // "pending" | "active" | "revoked" | "expired" | "all"
209
+ });
210
+
211
+ // Accept an invitation (called by the invitee)
212
+ const [err, member] = await capxul.organizations.members.accept({ token: inviteToken });
213
+
214
+ // Revoke a pending invitation
215
+ const [err] = await capxul.organizations.members.revoke({
216
+ organizationId: org.id,
217
+ memberId: member.id,
218
+ });
219
+
220
+ // Remove an active member
221
+ const [err] = await capxul.organizations.members.remove({
222
+ organizationId: org.id,
223
+ memberId: member.id,
224
+ });
225
+ ```
226
+
227
+ Member roles: `owner`, `finance_manager`, `payments_operator`,
228
+ `org_admin`, `viewer`, `accountant`. Only `owner` and `org_admin` can
229
+ invite, revoke, remove, or change roles.
230
+
231
+ Pending invitations auto-accept on first sign-in when the user's email
232
+ matches. Overdue pending invitations expire via a nightly cron.
233
+
189
234
  ## Error model
190
235
 
191
236
  Every method returns a `CapxulResult<T, Codes>` tuple. Errors are
@@ -1,8 +1,9 @@
1
1
  import { Account as Account$1 } from 'viem';
2
+ import * as xstate from 'xstate';
2
3
  import { AnyStateMachine } from 'xstate';
3
- import { A as AccountId, S as SafeId, c as KycProfileId, b as ExternalAccountId, f as SubAccountId, d as OrganizationId, a as ApiKeyId, X as TimestampIso, D as DocumentId, O as OperationId, P as PaymentId, g as TransferId, k as WithdrawalId, W as WebhookEndpointId, j as WebhookEventId, M as MemberId, K as KybProfileId, V as VirtualAccountId, i as VirtualCardId } from './next-action-DkrwXYay.cjs';
4
- import { d as CapxulResult, C as CapxulError } from './errors-GgKrSUKp.cjs';
5
- import { A as Account, U as UserIdentifier, a as AccountLookupResult, S as Safe, i as KycProfile, E as ExternalAccount, L as List, v as SubAccount, B as BalanceLedgerEntry, b as ApiKey, a0 as CreateApiKeyRequest, a1 as CreateDocumentRequest, D as Document, O as Operation, l as OperationStatus, k as Money, C as CreatePaymentResult, o as Payment, F as TransferEndpoint, f as CreateTransferResult, y as Transfer, g as CreateWithdrawalResult, _ as Withdrawal, a2 as CreateWebhookEndpointRequest, Y as WebhookEndpoint, Z as WebhookEvent, n as Organization, J as Treasury, M as Member, K as KybProfile, a3 as CreateVirtualAccountRequest, V as VirtualAccount, a4 as CreateVirtualCardRequest, Q as VirtualCard } from './types-hfcOE7Oi.cjs';
4
+ import { A as AccountId, S as SafeId, c as KycProfileId, b as ExternalAccountId, f as SubAccountId, d as OrganizationId, a as ApiKeyId, X as TimestampIso, U as Username, E as Email, D as DocumentId, O as OperationId, P as PaymentId, g as TransferId, k as WithdrawalId, W as WebhookEndpointId, j as WebhookEventId, M as MemberId, V as VirtualAccountId, i as VirtualCardId } from './next-action-CTGl8wpy.cjs';
5
+ import { d as CapxulResult, C as CapxulError$1 } from './errors-rqxuUhQP.cjs';
6
+ import { A as Account, X as UserIdentifier, a as AccountLookupResult, S as Safe, k as KycProfile, E as ExternalAccount, L as List, F as SubAccount, B as BalanceLedgerEntry, b as ApiKey, a5 as CreateApiKeyRequest, a6 as CreateDocumentRequest, D as Document, O as Operation, q as OperationStatus, p as Money, C as CreatePaymentResult, t as Payment, Q as TransferEndpoint, f as CreateTransferResult, J as Transfer, g as CreateWithdrawalResult, a3 as Withdrawal, a7 as CreateWebhookEndpointRequest, a1 as WebhookEndpoint, a2 as WebhookEvent, s as Organization, W as Treasury, o as MembershipStatus, M as Member, n as MemberInviteResponse, a8 as CreateVirtualAccountRequest, Y as VirtualAccount, a9 as CreateVirtualCardRequest, _ as VirtualCard } from './types-Brucpq0Z.cjs';
6
7
 
7
8
  /**
8
9
  * Accounts domain — individual user accounts per sdk-surface.md §1a.
@@ -21,7 +22,6 @@ type AccountUpdateInput = Partial<{
21
22
  type LocalPrivateKeySignerProvider = {
22
23
  readonly kind: "local-private-key";
23
24
  readonly signerAddress: string;
24
- readonly safeAddress: string;
25
25
  };
26
26
  type AccountProvisionPersonalInput = {
27
27
  readonly displayName?: string;
@@ -39,6 +39,7 @@ type AccountListInput = {
39
39
  type AccountCreateSubAccountInput = {
40
40
  readonly accountId: AccountId;
41
41
  readonly name: string;
42
+ readonly purpose?: string;
42
43
  };
43
44
  type AccountCreateExternalAccountInput = {
44
45
  readonly accountId: AccountId;
@@ -58,6 +59,7 @@ type UpdateCodes$1 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND" | "
58
59
  type ListCodes$b = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "INVALID_INPUT";
59
60
  type SafeRetrieveCodes$1 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND" | "SAFE_NOT_READY";
60
61
  type RemoveCodes$5 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND";
62
+ type SubAccountRemoveCodes$1 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND" | "INVALID_INPUT";
61
63
  type AccountSafesClient = {
62
64
  readonly retrieve: (safeId: SafeId) => Promise<CapxulResult<Safe, SafeRetrieveCodes$1>>;
63
65
  };
@@ -74,12 +76,12 @@ type AccountExternalAccountsClient = {
74
76
  readonly remove: (externalAccountId: ExternalAccountId) => Promise<CapxulResult<void, RemoveCodes$5>>;
75
77
  };
76
78
  type AccountSubAccountsClient = {
77
- readonly create: (input: AccountCreateSubAccountInput) => Promise<CapxulResult<SubAccount, UpdateCodes$1>>;
79
+ readonly create: (input: AccountCreateSubAccountInput) => Promise<CapxulResult<SubAccount, UpdateCodes$1 | "PROVIDER_ERROR">>;
78
80
  readonly list: (input: {
79
81
  readonly accountId: AccountId;
80
- } & AccountListInput) => Promise<CapxulResult<List<SubAccount>, ListCodes$b>>;
81
- readonly retrieve: (subAccountId: SubAccountId) => Promise<CapxulResult<SubAccount, RetrieveCodes$e>>;
82
- readonly remove: (subAccountId: SubAccountId) => Promise<CapxulResult<void, RemoveCodes$5>>;
82
+ } & AccountListInput) => Promise<CapxulResult<List<SubAccount>, ListCodes$b | "PROVIDER_ERROR">>;
83
+ readonly retrieve: (subAccountId: SubAccountId) => Promise<CapxulResult<SubAccount, RetrieveCodes$e | "PROVIDER_ERROR">>;
84
+ readonly remove: (subAccountId: SubAccountId) => Promise<CapxulResult<SubAccount, SubAccountRemoveCodes$1 | "PROVIDER_ERROR">>;
83
85
  };
84
86
  type AccountBalanceLedgerClient = {
85
87
  readonly list: (input: {
@@ -189,6 +191,37 @@ type AuthVerifyOtpInput = {
189
191
  readonly email: string;
190
192
  readonly otp: string;
191
193
  };
194
+ type AuthBootstrapToken = string & {
195
+ readonly __capxulAuthBootstrapTokenBrand: "AuthBootstrapToken";
196
+ };
197
+ type AuthBootstrapReason = "new_member" | "missing_profile" | "missing_account" | "missing_safe" | "missing_signer_grant";
198
+ type VerifyOtpResult = {
199
+ readonly kind: "existing_member";
200
+ readonly session: Session;
201
+ readonly account: Account;
202
+ readonly username: Username;
203
+ readonly safe: Safe;
204
+ } | {
205
+ readonly kind: "bootstrap_required";
206
+ readonly session: Session;
207
+ readonly bootstrapToken: AuthBootstrapToken;
208
+ readonly email: Email;
209
+ readonly reason: AuthBootstrapReason;
210
+ readonly username?: Username;
211
+ };
212
+ type CompleteBootstrapInput = {
213
+ readonly bootstrapToken: AuthBootstrapToken;
214
+ readonly username: Username;
215
+ readonly displayName?: string;
216
+ readonly countryCode?: string;
217
+ };
218
+ type CompleteBootstrapResult = {
219
+ readonly kind: "authenticated";
220
+ readonly session: Session;
221
+ readonly account: Account;
222
+ readonly username: Username;
223
+ readonly safe: Safe;
224
+ };
192
225
  type AuthServiceTokenMintInput = {
193
226
  readonly apiKey: string;
194
227
  readonly audience?: string;
@@ -210,14 +243,16 @@ type ServiceToken = {
210
243
  readonly token: string;
211
244
  readonly expiresAt: TimestampIso;
212
245
  };
213
- type SendOtpCodes = "EMAIL_DELIVERY_FAILED" | "INVALID_INPUT" | "RATE_LIMITED" | "NETWORK_ERROR";
214
- type VerifyOtpCodes = "INVALID_INPUT" | "NOT_AUTHENTICATED" | "RATE_LIMITED" | "NETWORK_ERROR";
246
+ type SendOtpCodes = "EMAIL_DELIVERY_FAILED" | "INVALID_INPUT" | "RATE_LIMITED" | "NETWORK_ERROR" | "PROVIDER_ERROR" | "INTERNAL_ERROR" | "ENV_MISSING" | "UNKNOWN" | "NOT_AUTHENTICATED" | "PERMISSION_DENIED";
247
+ type VerifyOtpCodes = "INVALID_INPUT" | "NOT_AUTHENTICATED" | "RATE_LIMITED" | "OPERATION_TIMEOUT" | "NETWORK_ERROR" | "PROVIDER_ERROR" | "INTERNAL_ERROR" | "ENV_MISSING" | "UNKNOWN" | "PERMISSION_DENIED";
248
+ type CompleteBootstrapCodes = "INVALID_INPUT" | "IDEMPOTENCY_CONFLICT" | "RATE_LIMITED" | "PROFILE_NOT_FOUND" | "SMART_ACCOUNT_MISSING" | "PROVIDER_UNAVAILABLE" | "PROVIDER_REJECTED" | "OPERATION_TIMEOUT" | "NETWORK_ERROR" | "INTERNAL_ERROR";
215
249
  type GetSessionCodes = "NETWORK_ERROR";
216
250
  type SignOutCodes = "NOT_AUTHENTICATED" | "NETWORK_ERROR";
217
251
  type ServiceTokenMintCodes = "API_KEY_INVALID" | "API_KEY_EXPIRED" | "INVALID_INPUT" | "RATE_LIMITED" | "NETWORK_ERROR";
218
252
  type AuthClient = {
219
253
  readonly sendOtp: (input: AuthSendOtpInput, options?: AuthMethodOptions) => Promise<CapxulResult<void, SendOtpCodes>>;
220
- readonly verifyOtp: (input: AuthVerifyOtpInput, options?: AuthMethodOptions) => Promise<CapxulResult<Session, VerifyOtpCodes>>;
254
+ readonly verifyOtp: (input: AuthVerifyOtpInput, options?: AuthMethodOptions) => Promise<CapxulResult<VerifyOtpResult, VerifyOtpCodes>>;
255
+ readonly completeBootstrap: (input: CompleteBootstrapInput) => Promise<CapxulResult<CompleteBootstrapResult, CompleteBootstrapCodes>>;
221
256
  readonly getSession: () => Promise<CapxulResult<Session | null, GetSessionCodes>>;
222
257
  readonly signOut: () => Promise<CapxulResult<void, SignOutCodes>>;
223
258
  readonly serviceTokenMint: (input: AuthServiceTokenMintInput) => Promise<CapxulResult<ServiceToken, ServiceTokenMintCodes>>;
@@ -656,7 +691,7 @@ type WebhookEventsClient = {
656
691
 
657
692
  type OrganizationsCreateInput = {
658
693
  readonly name: string;
659
- readonly country: string;
694
+ readonly country?: string;
660
695
  };
661
696
  type OrganizationsListInput = {
662
697
  readonly limit?: number;
@@ -675,6 +710,9 @@ type OrgMemberInviteInput = {
675
710
  readonly email: string;
676
711
  readonly role: Member["role"];
677
712
  };
713
+ type OrgMemberAcceptInput = {
714
+ readonly token: string;
715
+ };
678
716
  type OrgMemberUpdateRoleInput = {
679
717
  readonly organizationId: OrganizationId;
680
718
  readonly memberId: MemberId;
@@ -685,21 +723,23 @@ type OrgMemberRemoveInput = {
685
723
  readonly memberId: MemberId;
686
724
  };
687
725
  type OrgMemberRetrieveInput = OrgMemberRemoveInput;
726
+ type OrgMemberRevokeInput = OrgMemberRemoveInput;
727
+ type OrgMemberResendInput = OrgMemberRemoveInput;
688
728
  type OrgListInput = {
689
729
  readonly organizationId: OrganizationId;
690
730
  readonly limit?: number;
691
731
  readonly cursor?: string;
692
732
  };
693
- type OrgKybProfileStartInput = {
694
- readonly organizationId: OrganizationId;
695
- };
696
- type OrgKybProfileRetrieveInput = {
733
+ type OrgMemberListInput = {
697
734
  readonly organizationId: OrganizationId;
698
- readonly kybProfileId: KybProfileId;
735
+ readonly status?: MembershipStatus | "all";
736
+ readonly limit?: number;
737
+ readonly cursor?: string;
699
738
  };
700
739
  type OrgCreateSubAccountInput = {
701
740
  readonly organizationId: OrganizationId;
702
741
  readonly name: string;
742
+ readonly purpose?: string;
703
743
  };
704
744
  type OrgCreateExternalAccountInput = {
705
745
  readonly organizationId: OrganizationId;
@@ -731,6 +771,7 @@ type UpdateCodes = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND" | "IN
731
771
  type SafeRetrieveCodes = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND";
732
772
  type TreasuryRetrieveCodes = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND" | "SAFE_NOT_READY";
733
773
  type RemoveCodes$2 = RetrieveCodes$4;
774
+ type SubAccountRemoveCodes = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND" | "INVALID_INPUT";
734
775
  type OrgSafesClient = {
735
776
  readonly retrieve: (input: OrgSafeRetrieveInput) => Promise<CapxulResult<Safe, SafeRetrieveCodes>>;
736
777
  };
@@ -738,27 +779,26 @@ type OrgTreasuryClient = {
738
779
  readonly retrieve: (organizationId: OrganizationId) => Promise<CapxulResult<Treasury, TreasuryRetrieveCodes>>;
739
780
  };
740
781
  type OrgMembersClient = {
741
- readonly list: (input: OrgListInput) => Promise<CapxulResult<List<Member>, ListCodes$3>>;
782
+ readonly list: (input: OrgMemberListInput) => Promise<CapxulResult<List<Member>, ListCodes$3>>;
742
783
  readonly retrieve: (input: OrgMemberRetrieveInput) => Promise<CapxulResult<Member, RetrieveCodes$4>>;
743
- readonly invite: (input: OrgMemberInviteInput) => Promise<CapxulResult<Member, UpdateCodes>>;
784
+ readonly invite: (input: OrgMemberInviteInput) => Promise<CapxulResult<MemberInviteResponse, UpdateCodes>>;
785
+ readonly accept: (input: OrgMemberAcceptInput) => Promise<CapxulResult<Member, UpdateCodes>>;
744
786
  readonly updateRole: (input: OrgMemberUpdateRoleInput) => Promise<CapxulResult<Member, UpdateCodes>>;
787
+ readonly revoke: (input: OrgMemberRevokeInput) => Promise<CapxulResult<Member, UpdateCodes>>;
745
788
  readonly remove: (input: OrgMemberRemoveInput) => Promise<CapxulResult<void, RemoveCodes$2>>;
746
- };
747
- type OrgKybProfileClient = {
748
- readonly start: (input: OrgKybProfileStartInput) => Promise<CapxulResult<KybProfile, CreateCodes$2>>;
749
- readonly retrieve: (input: OrgKybProfileRetrieveInput) => Promise<CapxulResult<KybProfile, RetrieveCodes$4>>;
789
+ readonly resend: (input: OrgMemberResendInput) => Promise<CapxulResult<MemberInviteResponse, UpdateCodes>>;
750
790
  };
751
791
  type OrgSubAccountsClient = {
752
- readonly create: (input: OrgCreateSubAccountInput) => Promise<CapxulResult<SubAccount, UpdateCodes>>;
753
- readonly list: (input: OrgListInput) => Promise<CapxulResult<List<SubAccount>, ListCodes$3>>;
792
+ readonly create: (input: OrgCreateSubAccountInput) => Promise<CapxulResult<SubAccount, UpdateCodes | "PROVIDER_ERROR">>;
793
+ readonly list: (input: OrgListInput) => Promise<CapxulResult<List<SubAccount>, ListCodes$3 | "PROVIDER_ERROR">>;
754
794
  readonly retrieve: (input: {
755
795
  readonly organizationId: OrganizationId;
756
796
  readonly subAccountId: SubAccountId;
757
- }) => Promise<CapxulResult<SubAccount, RetrieveCodes$4>>;
797
+ }) => Promise<CapxulResult<SubAccount, RetrieveCodes$4 | "PROVIDER_ERROR">>;
758
798
  readonly remove: (input: {
759
799
  readonly organizationId: OrganizationId;
760
800
  readonly subAccountId: SubAccountId;
761
- }) => Promise<CapxulResult<void, RemoveCodes$2>>;
801
+ }) => Promise<CapxulResult<SubAccount, SubAccountRemoveCodes | "PROVIDER_ERROR">>;
762
802
  };
763
803
  type OrgExternalAccountsClient = {
764
804
  readonly create: (input: OrgCreateExternalAccountInput) => Promise<CapxulResult<ExternalAccount, UpdateCodes>>;
@@ -789,7 +829,6 @@ type OrganizationsClient = {
789
829
  readonly treasury: OrgTreasuryClient;
790
830
  readonly members: OrgMembersClient;
791
831
  readonly apiKeys: OrgApiKeysClient;
792
- readonly kybProfile: OrgKybProfileClient;
793
832
  readonly subAccounts: OrgSubAccountsClient;
794
833
  readonly externalAccounts: OrgExternalAccountsClient;
795
834
  readonly balanceLedger: OrgBalanceLedgerClient;
@@ -883,7 +922,7 @@ type TransportState = {
883
922
  readonly runtime: TransportRuntime;
884
923
  } | {
885
924
  readonly status: "error";
886
- readonly error: CapxulError;
925
+ readonly error: CapxulError$1;
887
926
  };
888
927
  type TransportRuntime = {
889
928
  readonly authBaseUrl: string;
@@ -942,13 +981,20 @@ declare function makeHttpTransport(config: BrowserCapxulConfig): HttpTransport;
942
981
  * `accounts.subAccounts.create(...)` or
943
982
  * `organizations.subAccounts.create(...)`), so only `retrieve` and
944
983
  * `remove` live at the top level.
984
+ *
985
+ * Wired in PR-2a of the funds-v1 balance-closure stack: the backend
986
+ * always returns truthful `balance: Money` per canon §sub_account
987
+ * (PR-1 made `toCanonShape` populate it from `computeSubAccountBalance`).
988
+ * The SDK brands the wire shape and passes the balance through as-is.
989
+ * NO zero-balance fallback exists at the SDK layer — if the backend
990
+ * ever omits `balance`, that is a bug to surface, not paper over.
945
991
  */
946
992
 
947
- type RetrieveCodes$3 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND";
948
- type RemoveCodes$1 = RetrieveCodes$3;
993
+ type RetrieveCodes$3 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND" | "PROVIDER_ERROR";
994
+ type RemoveCodes$1 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND" | "INVALID_INPUT" | "PROVIDER_ERROR";
949
995
  type SubAccountsClient = {
950
996
  readonly retrieve: (subAccountId: SubAccountId) => Promise<CapxulResult<SubAccount, RetrieveCodes$3>>;
951
- readonly remove: (subAccountId: SubAccountId) => Promise<CapxulResult<void, RemoveCodes$1>>;
997
+ readonly remove: (subAccountId: SubAccountId) => Promise<CapxulResult<SubAccount, RemoveCodes$1>>;
952
998
  };
953
999
 
954
1000
  /**
@@ -1103,6 +1149,152 @@ type VirtualCardsClient = {
1103
1149
  readonly cancel: (virtualCardId: VirtualCardId) => Promise<CapxulResult<VirtualCard, MutateCodes>>;
1104
1150
  };
1105
1151
 
1152
+ /**
1153
+ * Unified error type used across the entire stack: backend, SDK, and frontend.
1154
+ * One class, one set of codes, one language.
1155
+ *
1156
+ * Backend throws CapxulError → withErrorBoundary serializes to ConvexError →
1157
+ * SDK deserializes back to CapxulError → frontend routes on err.code.
1158
+ */
1159
+ type CapxulErrorCode = "NOT_AUTHENTICATED" | "EMAIL_DELIVERY_FAILED" | "API_KEY_INVALID" | "API_KEY_EXPIRED" | "PROFILE_NOT_FOUND" | "SMART_ACCOUNT_MISSING" | "PLAYER_NOT_FOUND" | "ACCOUNT_NOT_FOUND" | "PROVIDER_ERROR" | "INVALID_INPUT" | "ENV_MISSING" | "NOT_IMPLEMENTED" | "VERIFICATION_REQUIRED" | "INSUFFICIENT_BALANCE" | "INVALID_RECIPIENT" | "TRANSACTION_FAILED" | "RATE_LIMITED" | "NETWORK_ERROR" | "PERMISSION_DENIED" | "IDEMPOTENCY_CONFLICT" | "NOT_FOUND" | "OPERATION_CANCELED" | "OPERATION_TIMEOUT" | "ACTION_REQUIRED" | "KYC_REQUIRED" | "POLICY_DENIED" | "SAFE_NOT_READY" | "PROVIDER_UNAVAILABLE" | "PROVIDER_REJECTED" | "RECONCILIATION_FAILED" | "INTERNAL_ERROR" | "QUOTE_EXPIRED" | "QUOTE_NOT_FOUND" | "INDEXER_DELIVERY_TIMEOUT" | "UNKNOWN";
1160
+ declare class CapxulError extends Error {
1161
+ readonly code: CapxulErrorCode;
1162
+ readonly details?: Record<string, unknown>;
1163
+ readonly correlationId?: string;
1164
+ readonly layer?: string;
1165
+ constructor(code: CapxulErrorCode, message: string, options?: {
1166
+ cause?: unknown;
1167
+ details?: Record<string, unknown>;
1168
+ correlationId?: string;
1169
+ layer?: string;
1170
+ });
1171
+ }
1172
+
1173
+ type AuthBootstrapFlowError = CapxulError$1 | CapxulError;
1174
+ type AuthBootstrapFlowContext = {
1175
+ readonly email: Email | null;
1176
+ readonly code: string | null;
1177
+ readonly username: Username | null;
1178
+ readonly bootstrapToken: AuthBootstrapToken | null;
1179
+ readonly bootstrapReason: AuthBootstrapReason | null;
1180
+ readonly session: Session | null;
1181
+ readonly account: Account | null;
1182
+ readonly safe: Safe | null;
1183
+ readonly error: AuthBootstrapFlowError | null;
1184
+ };
1185
+ type AuthBootstrapFlowEvent = {
1186
+ readonly type: "ENTER_EMAIL";
1187
+ readonly email: Email;
1188
+ } | {
1189
+ readonly type: "REQUEST_OTP";
1190
+ } | {
1191
+ readonly type: "ENTER_OTP";
1192
+ readonly code: string;
1193
+ } | {
1194
+ readonly type: "VERIFY_OTP";
1195
+ } | {
1196
+ readonly type: "ENTER_USERNAME";
1197
+ readonly username: Username;
1198
+ } | {
1199
+ readonly type: "COMPLETE_BOOTSTRAP";
1200
+ } | {
1201
+ readonly type: "BACK";
1202
+ } | {
1203
+ readonly type: "RESET";
1204
+ } | {
1205
+ readonly type: "SIGN_OUT";
1206
+ };
1207
+ declare function createAuthBootstrapFlowMachine(client: CapxulClient): xstate.StateMachine<AuthBootstrapFlowContext, {
1208
+ readonly type: "ENTER_EMAIL";
1209
+ readonly email: Email;
1210
+ } | {
1211
+ readonly type: "REQUEST_OTP";
1212
+ } | {
1213
+ readonly type: "ENTER_OTP";
1214
+ readonly code: string;
1215
+ } | {
1216
+ readonly type: "VERIFY_OTP";
1217
+ } | {
1218
+ readonly type: "ENTER_USERNAME";
1219
+ readonly username: Username;
1220
+ } | {
1221
+ readonly type: "COMPLETE_BOOTSTRAP";
1222
+ } | {
1223
+ readonly type: "BACK";
1224
+ } | {
1225
+ readonly type: "RESET";
1226
+ } | {
1227
+ readonly type: "SIGN_OUT";
1228
+ }, {
1229
+ [x: string]: xstate.ActorRefFromLogic<xstate.PromiseActorLogic<void, void, xstate.EventObject>> | xstate.ActorRefFromLogic<xstate.PromiseActorLogic<void, {
1230
+ email: Email;
1231
+ }, xstate.EventObject>> | xstate.ActorRefFromLogic<xstate.PromiseActorLogic<VerifyOtpResult, {
1232
+ email: Email;
1233
+ code: string;
1234
+ }, xstate.EventObject>> | xstate.ActorRefFromLogic<xstate.PromiseActorLogic<CompleteBootstrapResult, {
1235
+ bootstrapToken: AuthBootstrapToken;
1236
+ username: Username;
1237
+ }, xstate.EventObject>> | undefined;
1238
+ }, {
1239
+ src: "sendOtp";
1240
+ logic: xstate.PromiseActorLogic<void, {
1241
+ email: Email;
1242
+ }, xstate.EventObject>;
1243
+ id: string | undefined;
1244
+ } | {
1245
+ src: "verifyOtp";
1246
+ logic: xstate.PromiseActorLogic<VerifyOtpResult, {
1247
+ email: Email;
1248
+ code: string;
1249
+ }, xstate.EventObject>;
1250
+ id: string | undefined;
1251
+ } | {
1252
+ src: "signOut";
1253
+ logic: xstate.PromiseActorLogic<void, void, xstate.EventObject>;
1254
+ id: string | undefined;
1255
+ } | {
1256
+ src: "completeBootstrap";
1257
+ logic: xstate.PromiseActorLogic<CompleteBootstrapResult, {
1258
+ bootstrapToken: AuthBootstrapToken;
1259
+ username: Username;
1260
+ }, xstate.EventObject>;
1261
+ id: string | undefined;
1262
+ }, {
1263
+ type: "trackOtpRequested";
1264
+ params: unknown;
1265
+ } | {
1266
+ type: "trackTimeoutFailed";
1267
+ params: unknown;
1268
+ } | {
1269
+ type: "trackVerified";
1270
+ params: unknown;
1271
+ } | {
1272
+ type: "identifyAndTrack";
1273
+ params: unknown;
1274
+ } | {
1275
+ type: "trackSignedOut";
1276
+ params: unknown;
1277
+ } | {
1278
+ type: "trackFailed";
1279
+ params: unknown;
1280
+ } | {
1281
+ type: "trackBootstrapRequired";
1282
+ params: unknown;
1283
+ }, never, never, "email" | "authenticated" | "error" | "bootstrap_required" | "sending_otp" | "otp_requested" | "signing_out" | "verifying_otp" | "completing_bootstrap", string, xstate.NonReducibleUnknown, xstate.NonReducibleUnknown, xstate.EventObject, xstate.MetaObject, {
1284
+ id: "authBootstrap";
1285
+ states: {
1286
+ readonly email: {};
1287
+ readonly sending_otp: {};
1288
+ readonly otp_requested: {};
1289
+ readonly verifying_otp: {};
1290
+ readonly bootstrap_required: {};
1291
+ readonly completing_bootstrap: {};
1292
+ readonly authenticated: {};
1293
+ readonly signing_out: {};
1294
+ readonly error: {};
1295
+ };
1296
+ }>;
1297
+
1106
1298
  /**
1107
1299
  * Root `@capxul/sdk` client factory.
1108
1300
  *
@@ -1150,11 +1342,6 @@ type CapxulAuthConfig = {
1150
1342
  readonly convexTokenUrl?: string;
1151
1343
  /** Scenario/browser-local session store shared by auth + onboarding hooks. */
1152
1344
  readonly sessionStore?: AuthSessionStore;
1153
- /**
1154
- * Optional bridge for environments that can build an authenticated data
1155
- * client after BetterAuth returns a session.
1156
- */
1157
- readonly createDataClient?: (session: Session) => Promise<CapxulDataClient>;
1158
1345
  };
1159
1346
  type CapxulConfig = {
1160
1347
  /** Server-to-server partner key. Mutually exclusive with `publishableKey`. */
@@ -1170,12 +1357,13 @@ type CapxulConfig = {
1170
1357
  */
1171
1358
  readonly signer?: Account$1;
1172
1359
  /**
1173
- * Inject an authenticated Convex data client.
1360
+ * @internal
1174
1361
  *
1175
- * Slice F.2 uses this for the restart payment + operation runtime
1176
- * path while the `/v1/*` service-token bridge remains unfinished.
1362
+ * Test-only override seam for injecting an authenticated Convex data client.
1363
+ * The SDK now owns runtime construction of the data client; this field is
1364
+ * reserved for tests and the React provider's singleton lifecycle.
1177
1365
  */
1178
- readonly data?: CapxulDataClient;
1366
+ readonly _data?: CapxulDataClient;
1179
1367
  /**
1180
1368
  * Chain + bundler configuration for on-chain submission.
1181
1369
  *
@@ -1230,6 +1418,7 @@ type CapxulConfig = {
1230
1418
  */
1231
1419
  type CapxulFlowFactories = {
1232
1420
  readonly auth: () => AnyStateMachine;
1421
+ readonly authBootstrap: () => ReturnType<typeof createAuthBootstrapFlowMachine>;
1233
1422
  readonly onboarding: () => AnyStateMachine;
1234
1423
  readonly provisioning: () => AnyStateMachine;
1235
1424
  };
@@ -1292,4 +1481,4 @@ type CapxulClient = {
1292
1481
  */
1293
1482
  declare function createCapxulClient(config?: CapxulConfig): CapxulClient;
1294
1483
 
1295
- export { type AccountProvisionPersonalInput as A, type BrowserCapxulConfig as B, type CapxulClient as C, type DocumentsClient as D, type ExternalAccountsClient as E, type VirtualCardsClient as F, type WebhookEndpointsClient as G, type HttpTransport as H, type WebhookEventsClient as I, type WithdrawalsClient as J, createCapxulClient as K, type LocalPrivateKeySignerProvider as L, type MeClient as M, makeHttpTransport as N, type OperationsClient as O, type PaymentsClient as P, toTokenTransferId as Q, type Session as S, type TokenTransfer as T, type VirtualAccountsClient as V, type WebhookEndpointCreateResult as W, type AccountsClient as a, type ApiKeyCreateResult as b, type ApiKeysClient as c, type AuthClient as d, type AuthSessionStore as e, type CapxulAuthConfig as f, type CapxulConfig as g, type CapxulDataClient as h, type CapxulFlowFactories as i, type CapxulSigningConfig as j, type OrgDocumentsClient as k, type OrgPaymentsClient as l, type OrgSafesClient as m, type OrgTransfersClient as n, type OrgTreasuryClient as o, type OrgWithdrawalsClient as p, type OrganizationsClient as q, type SubAccountsClient as r, type TokenTransferId as s, type TokenTransfersClient as t, type TokenTransfersListInput as u, type TokenTransfersListPage as v, type TokenTransfersRetrieveInput as w, type TransfersClient as x, type TransportRuntime as y, type TransportState as z };
1484
+ export { type WithdrawalsClient as $, type AccountProvisionPersonalInput as A, type BrowserCapxulConfig as B, CapxulError as C, type DocumentsClient as D, type ExternalAccountsClient as E, type SubAccountsClient as F, type TokenTransferId as G, type HttpTransport as H, type TokenTransfersClient as I, type TokenTransfersListInput as J, type TokenTransfersListPage as K, type LocalPrivateKeySignerProvider as L, type MeClient as M, type TokenTransfersRetrieveInput as N, type OperationsClient as O, type PaymentsClient as P, type TransfersClient as Q, type TransportRuntime as R, type Session as S, type TokenTransfer as T, type TransportState as U, type VerifyOtpResult as V, type VirtualAccountsClient as W, type VirtualCardsClient as X, type WebhookEndpointCreateResult as Y, type WebhookEndpointsClient as Z, type WebhookEventsClient as _, type CapxulClient as a, createAuthBootstrapFlowMachine as a0, createCapxulClient as a1, makeHttpTransport as a2, toTokenTransferId as a3, type CapxulConfig as b, type CompleteBootstrapInput as c, type CompleteBootstrapResult as d, type AccountsClient as e, type ApiKeyCreateResult as f, type ApiKeysClient as g, type AuthBootstrapFlowContext as h, type AuthBootstrapFlowError as i, type AuthBootstrapFlowEvent as j, type AuthBootstrapReason as k, type AuthBootstrapToken as l, type AuthClient as m, type AuthSessionStore as n, type CapxulAuthConfig as o, type CapxulDataClient as p, type CapxulFlowFactories as q, type CapxulSigningConfig as r, type OrgDocumentsClient as s, type OrgMembersClient as t, type OrgPaymentsClient as u, type OrgSafesClient as v, type OrgTransfersClient as w, type OrgTreasuryClient as x, type OrgWithdrawalsClient as y, type OrganizationsClient as z };