@capxul/sdk 0.1.0-alpha.1 → 0.1.0-alpha.11

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.
@@ -1,9 +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, 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, Y as WebhookEndpoint, Z as WebhookEvent, n as Organization, J as Treasury, M as Member, K as KybProfile, V as VirtualAccount, Q as VirtualCard } from './types-DVWojoy4.cjs';
6
- import * as types from '@repo/api-contract/gen/types';
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, K as KybProfileId, V as VirtualAccountId, i as VirtualCardId } from './next-action-DkrwXYay.cjs';
5
+ import { d as CapxulResult, C as CapxulError$1 } from './errors-GgKrSUKp.cjs';
6
+ 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';
7
7
 
8
8
  /**
9
9
  * Accounts domain — individual user accounts per sdk-surface.md §1a.
@@ -40,6 +40,7 @@ type AccountListInput = {
40
40
  type AccountCreateSubAccountInput = {
41
41
  readonly accountId: AccountId;
42
42
  readonly name: string;
43
+ readonly purpose?: string;
43
44
  };
44
45
  type AccountCreateExternalAccountInput = {
45
46
  readonly accountId: AccountId;
@@ -53,43 +54,44 @@ type AccountCreateExternalAccountInput = {
53
54
  readonly panToken?: string;
54
55
  readonly last4?: string;
55
56
  };
56
- type RetrieveCodes$d = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND";
57
+ type RetrieveCodes$e = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND";
57
58
  type LookupCodes = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "INVALID_INPUT";
58
59
  type UpdateCodes$1 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND" | "INVALID_INPUT";
59
- type ListCodes$a = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "INVALID_INPUT";
60
+ type ListCodes$b = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "INVALID_INPUT";
60
61
  type SafeRetrieveCodes$1 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND" | "SAFE_NOT_READY";
61
62
  type RemoveCodes$5 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND";
63
+ type SubAccountRemoveCodes$1 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND" | "INVALID_INPUT";
62
64
  type AccountSafesClient = {
63
65
  readonly retrieve: (safeId: SafeId) => Promise<CapxulResult<Safe, SafeRetrieveCodes$1>>;
64
66
  };
65
67
  type AccountKycProfilesClient = {
66
68
  readonly create: (input: AccountCreateKycProfileInput) => Promise<CapxulResult<KycProfile, UpdateCodes$1>>;
67
- readonly retrieve: (kycProfileId: KycProfileId) => Promise<CapxulResult<KycProfile, RetrieveCodes$d>>;
69
+ readonly retrieve: (kycProfileId: KycProfileId) => Promise<CapxulResult<KycProfile, RetrieveCodes$e>>;
68
70
  };
69
71
  type AccountExternalAccountsClient = {
70
72
  readonly create: (input: AccountCreateExternalAccountInput) => Promise<CapxulResult<ExternalAccount, UpdateCodes$1>>;
71
73
  readonly list: (input: {
72
74
  readonly accountId: AccountId;
73
- } & AccountListInput) => Promise<CapxulResult<List<ExternalAccount>, ListCodes$a>>;
74
- readonly retrieve: (externalAccountId: ExternalAccountId) => Promise<CapxulResult<ExternalAccount, RetrieveCodes$d>>;
75
+ } & AccountListInput) => Promise<CapxulResult<List<ExternalAccount>, ListCodes$b>>;
76
+ readonly retrieve: (externalAccountId: ExternalAccountId) => Promise<CapxulResult<ExternalAccount, RetrieveCodes$e>>;
75
77
  readonly remove: (externalAccountId: ExternalAccountId) => Promise<CapxulResult<void, RemoveCodes$5>>;
76
78
  };
77
79
  type AccountSubAccountsClient = {
78
- readonly create: (input: AccountCreateSubAccountInput) => Promise<CapxulResult<SubAccount, UpdateCodes$1>>;
80
+ readonly create: (input: AccountCreateSubAccountInput) => Promise<CapxulResult<SubAccount, UpdateCodes$1 | "PROVIDER_ERROR">>;
79
81
  readonly list: (input: {
80
82
  readonly accountId: AccountId;
81
- } & AccountListInput) => Promise<CapxulResult<List<SubAccount>, ListCodes$a>>;
82
- readonly retrieve: (subAccountId: SubAccountId) => Promise<CapxulResult<SubAccount, RetrieveCodes$d>>;
83
- readonly remove: (subAccountId: SubAccountId) => Promise<CapxulResult<void, RemoveCodes$5>>;
83
+ } & AccountListInput) => Promise<CapxulResult<List<SubAccount>, ListCodes$b | "PROVIDER_ERROR">>;
84
+ readonly retrieve: (subAccountId: SubAccountId) => Promise<CapxulResult<SubAccount, RetrieveCodes$e | "PROVIDER_ERROR">>;
85
+ readonly remove: (subAccountId: SubAccountId) => Promise<CapxulResult<SubAccount, SubAccountRemoveCodes$1 | "PROVIDER_ERROR">>;
84
86
  };
85
87
  type AccountBalanceLedgerClient = {
86
88
  readonly list: (input: {
87
89
  readonly accountId: AccountId;
88
- } & AccountListInput) => Promise<CapxulResult<List<BalanceLedgerEntry>, ListCodes$a>>;
89
- readonly retrieve: (entryId: string) => Promise<CapxulResult<BalanceLedgerEntry, RetrieveCodes$d>>;
90
+ } & AccountListInput) => Promise<CapxulResult<List<BalanceLedgerEntry>, ListCodes$b>>;
91
+ readonly retrieve: (entryId: string) => Promise<CapxulResult<BalanceLedgerEntry, RetrieveCodes$e>>;
90
92
  };
91
93
  type AccountsClient = {
92
- readonly retrieve: (accountId: AccountId) => Promise<CapxulResult<Account, RetrieveCodes$d>>;
94
+ readonly retrieve: (accountId: AccountId) => Promise<CapxulResult<Account, RetrieveCodes$e>>;
93
95
  readonly lookup: (input: AccountLookupInput) => Promise<CapxulResult<AccountLookupResult, LookupCodes>>;
94
96
  readonly update: (input: {
95
97
  readonly accountId: AccountId;
@@ -111,7 +113,7 @@ type AccountsClient = {
111
113
  * on `create` only; subsequent reads omit it.
112
114
  */
113
115
 
114
- type ApiKeysCreateInput = types.CreateApiKeyRequest & {
116
+ type ApiKeysCreateInput = CreateApiKeyRequest & {
115
117
  readonly organizationId: OrganizationId;
116
118
  };
117
119
  type ApiKeysRetrieveInput = {
@@ -125,9 +127,9 @@ type ApiKeysListInput = {
125
127
  };
126
128
  type ApiKeysRevokeInput = ApiKeysRetrieveInput;
127
129
  type CreateCodes$8 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "INVALID_INPUT" | "RATE_LIMITED" | "NETWORK_ERROR";
128
- type RetrieveCodes$c = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND";
129
- type ListCodes$9 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "INVALID_INPUT";
130
- type RevokeCodes = RetrieveCodes$c;
130
+ type RetrieveCodes$d = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND";
131
+ type ListCodes$a = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "INVALID_INPUT";
132
+ type RevokeCodes = RetrieveCodes$d;
131
133
  /**
132
134
  * Shape returned by `organizations.apiKeys.create` — the one-time
133
135
  * secret `value` is included here and omitted from every subsequent
@@ -138,8 +140,8 @@ type ApiKeyCreateResult = ApiKey & {
138
140
  };
139
141
  type ApiKeysClient = {
140
142
  readonly create: (input: ApiKeysCreateInput) => Promise<CapxulResult<ApiKeyCreateResult, CreateCodes$8>>;
141
- readonly retrieve: (input: ApiKeysRetrieveInput) => Promise<CapxulResult<ApiKey, RetrieveCodes$c>>;
142
- readonly list: (input: ApiKeysListInput) => Promise<CapxulResult<List<ApiKey>, ListCodes$9>>;
143
+ readonly retrieve: (input: ApiKeysRetrieveInput) => Promise<CapxulResult<ApiKey, RetrieveCodes$d>>;
144
+ readonly list: (input: ApiKeysListInput) => Promise<CapxulResult<List<ApiKey>, ListCodes$a>>;
143
145
  readonly revoke: (input: ApiKeysRevokeInput) => Promise<CapxulResult<ApiKey, RevokeCodes>>;
144
146
  };
145
147
 
@@ -190,6 +192,38 @@ type AuthVerifyOtpInput = {
190
192
  readonly email: string;
191
193
  readonly otp: string;
192
194
  };
195
+ type AuthBootstrapToken = string & {
196
+ readonly __capxulAuthBootstrapTokenBrand: "AuthBootstrapToken";
197
+ };
198
+ type AuthBootstrapReason = "new_member" | "missing_profile" | "missing_account" | "missing_safe" | "missing_signer_grant";
199
+ type VerifyOtpResult = {
200
+ readonly kind: "existing_member";
201
+ readonly session: Session;
202
+ readonly account: Account;
203
+ readonly username: Username;
204
+ readonly safe: Safe;
205
+ } | {
206
+ readonly kind: "bootstrap_required";
207
+ readonly session: Session;
208
+ readonly bootstrapToken: AuthBootstrapToken;
209
+ readonly email: Email;
210
+ readonly reason: AuthBootstrapReason;
211
+ readonly username?: Username;
212
+ };
213
+ type CompleteBootstrapInput = {
214
+ readonly bootstrapToken: AuthBootstrapToken;
215
+ readonly username: Username;
216
+ readonly signerProvider: LocalPrivateKeySignerProvider;
217
+ readonly displayName?: string;
218
+ readonly countryCode?: string;
219
+ };
220
+ type CompleteBootstrapResult = {
221
+ readonly kind: "authenticated";
222
+ readonly session: Session;
223
+ readonly account: Account;
224
+ readonly username: Username;
225
+ readonly safe: Safe;
226
+ };
193
227
  type AuthServiceTokenMintInput = {
194
228
  readonly apiKey: string;
195
229
  readonly audience?: string;
@@ -211,14 +245,16 @@ type ServiceToken = {
211
245
  readonly token: string;
212
246
  readonly expiresAt: TimestampIso;
213
247
  };
214
- type SendOtpCodes = "EMAIL_DELIVERY_FAILED" | "INVALID_INPUT" | "RATE_LIMITED" | "NETWORK_ERROR";
215
- type VerifyOtpCodes = "INVALID_INPUT" | "NOT_AUTHENTICATED" | "RATE_LIMITED" | "NETWORK_ERROR";
248
+ type SendOtpCodes = "EMAIL_DELIVERY_FAILED" | "INVALID_INPUT" | "RATE_LIMITED" | "NETWORK_ERROR" | "PROVIDER_ERROR" | "INTERNAL_ERROR" | "ENV_MISSING" | "UNKNOWN";
249
+ type VerifyOtpCodes = "INVALID_INPUT" | "NOT_AUTHENTICATED" | "RATE_LIMITED" | "OPERATION_TIMEOUT" | "NETWORK_ERROR" | "PROVIDER_ERROR" | "INTERNAL_ERROR" | "ENV_MISSING" | "UNKNOWN";
250
+ type CompleteBootstrapCodes = "INVALID_INPUT" | "IDEMPOTENCY_CONFLICT" | "RATE_LIMITED" | "PROFILE_NOT_FOUND" | "SMART_ACCOUNT_MISSING" | "PROVIDER_UNAVAILABLE" | "PROVIDER_REJECTED" | "OPERATION_TIMEOUT" | "NETWORK_ERROR" | "INTERNAL_ERROR";
216
251
  type GetSessionCodes = "NETWORK_ERROR";
217
252
  type SignOutCodes = "NOT_AUTHENTICATED" | "NETWORK_ERROR";
218
253
  type ServiceTokenMintCodes = "API_KEY_INVALID" | "API_KEY_EXPIRED" | "INVALID_INPUT" | "RATE_LIMITED" | "NETWORK_ERROR";
219
254
  type AuthClient = {
220
255
  readonly sendOtp: (input: AuthSendOtpInput, options?: AuthMethodOptions) => Promise<CapxulResult<void, SendOtpCodes>>;
221
- readonly verifyOtp: (input: AuthVerifyOtpInput, options?: AuthMethodOptions) => Promise<CapxulResult<Session, VerifyOtpCodes>>;
256
+ readonly verifyOtp: (input: AuthVerifyOtpInput, options?: AuthMethodOptions) => Promise<CapxulResult<VerifyOtpResult, VerifyOtpCodes>>;
257
+ readonly completeBootstrap: (input: CompleteBootstrapInput) => Promise<CapxulResult<CompleteBootstrapResult, CompleteBootstrapCodes>>;
222
258
  readonly getSession: () => Promise<CapxulResult<Session | null, GetSessionCodes>>;
223
259
  readonly signOut: () => Promise<CapxulResult<void, SignOutCodes>>;
224
260
  readonly serviceTokenMint: (input: AuthServiceTokenMintInput) => Promise<CapxulResult<ServiceToken, ServiceTokenMintCodes>>;
@@ -236,7 +272,7 @@ type AuthClient = {
236
272
  * bank_statement | tax_form`.
237
273
  */
238
274
 
239
- type DocumentsCreateInput = types.CreateDocumentRequest;
275
+ type DocumentsCreateInput = CreateDocumentRequest;
240
276
  type DocumentsListInput = {
241
277
  readonly limit?: number;
242
278
  readonly cursor?: string;
@@ -260,19 +296,19 @@ type OrgDocumentsCancelInput = {
260
296
  readonly documentId: DocumentId;
261
297
  };
262
298
  type CreateCodes$7 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "INVALID_INPUT" | "IDEMPOTENCY_CONFLICT" | "RATE_LIMITED" | "NETWORK_ERROR";
263
- type RetrieveCodes$b = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND";
264
- type ListCodes$8 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "INVALID_INPUT";
299
+ type RetrieveCodes$c = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND";
300
+ type ListCodes$9 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "INVALID_INPUT";
265
301
  type CancelCodes$1 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND" | "OPERATION_CANCELED";
266
302
  type DocumentsClient = {
267
303
  readonly create: (input: DocumentsCreateInput) => Promise<CapxulResult<Document, CreateCodes$7>>;
268
- readonly retrieve: (documentId: DocumentId) => Promise<CapxulResult<Document, RetrieveCodes$b>>;
269
- readonly list: (input?: DocumentsListInput) => Promise<CapxulResult<List<Document>, ListCodes$8>>;
304
+ readonly retrieve: (documentId: DocumentId) => Promise<CapxulResult<Document, RetrieveCodes$c>>;
305
+ readonly list: (input?: DocumentsListInput) => Promise<CapxulResult<List<Document>, ListCodes$9>>;
270
306
  readonly cancel: (documentId: DocumentId) => Promise<CapxulResult<Document, CancelCodes$1>>;
271
307
  };
272
308
  type OrgDocumentsClient = {
273
309
  readonly create: (input: OrgDocumentsCreateInput) => Promise<CapxulResult<Document, CreateCodes$7>>;
274
- readonly retrieve: (input: OrgDocumentsRetrieveInput) => Promise<CapxulResult<Document, RetrieveCodes$b>>;
275
- readonly list: (input: OrgDocumentsListInput) => Promise<CapxulResult<List<Document>, ListCodes$8>>;
310
+ readonly retrieve: (input: OrgDocumentsRetrieveInput) => Promise<CapxulResult<Document, RetrieveCodes$c>>;
311
+ readonly list: (input: OrgDocumentsListInput) => Promise<CapxulResult<List<Document>, ListCodes$9>>;
276
312
  readonly cancel: (input: OrgDocumentsCancelInput) => Promise<CapxulResult<Document, CancelCodes$1>>;
277
313
  };
278
314
 
@@ -282,14 +318,26 @@ type OrgDocumentsClient = {
282
318
  * Per sdk-surface.md §1a, `external_account` is a reusable withdrawal
283
319
  * destination. `create` + `list` live under the owner's nested
284
320
  * namespace (Pattern A — `accounts.externalAccounts.*` or
285
- * `organizations.externalAccounts.*`). `retrieve` and `remove` work by
286
- * ID without scoping.
321
+ * `organizations.externalAccounts.*`). The top-level `retrieve` and
322
+ * `remove` keep PERSONAL-scope semantics — for org rows route via
323
+ * the `organizations.externalAccounts.*` namespace which carries
324
+ * `organizationId` end-to-end and pins the row's owner pair to
325
+ * prevent cross-org IDOR (revision 1, #464).
326
+ *
327
+ * Withdrawals v1 W1 (#464) wires these stubs through the
328
+ * `externalAccounts/{queries,mutations}` Convex domain. The wire shape
329
+ * matches OpenAPI: `{ object: "external_account", id, kind, status,
330
+ * ..., operation: { id, status, correlationId } }` — the trust-chain
331
+ * ids live under the canonical nested `operation: OperationSummary`
332
+ * envelope (revision 3, #464), matching Withdrawal / Payment /
333
+ * Transfer / Organization. The SDK rebrands `id` + the nested
334
+ * `operation` sub-ids at the read edge.
287
335
  */
288
336
 
289
- type RetrieveCodes$a = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND";
290
- type RemoveCodes$4 = RetrieveCodes$a;
337
+ type RetrieveCodes$b = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND";
338
+ type RemoveCodes$4 = RetrieveCodes$b;
291
339
  type ExternalAccountsClient = {
292
- readonly retrieve: (externalAccountId: ExternalAccountId) => Promise<CapxulResult<ExternalAccount, RetrieveCodes$a>>;
340
+ readonly retrieve: (externalAccountId: ExternalAccountId) => Promise<CapxulResult<ExternalAccount, RetrieveCodes$b>>;
293
341
  readonly remove: (externalAccountId: ExternalAccountId) => Promise<CapxulResult<void, RemoveCodes$4>>;
294
342
  };
295
343
 
@@ -329,10 +377,10 @@ type OperationsWaitInput = {
329
377
  readonly timeoutSeconds?: number;
330
378
  readonly pollIntervalMs?: number;
331
379
  };
332
- type RetrieveCodes$9 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND";
333
- type WaitCodes = RetrieveCodes$9 | "OPERATION_TIMEOUT";
380
+ type RetrieveCodes$a = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND";
381
+ type WaitCodes = RetrieveCodes$a | "OPERATION_TIMEOUT";
334
382
  type OperationsClient = {
335
- readonly retrieve: (operationId: OperationId) => Promise<CapxulResult<Operation, RetrieveCodes$9>>;
383
+ readonly retrieve: (operationId: OperationId) => Promise<CapxulResult<Operation, RetrieveCodes$a>>;
336
384
  readonly wait: (operationId: OperationId, input?: OperationsWaitInput) => Promise<CapxulResult<Operation, WaitCodes>>;
337
385
  };
338
386
 
@@ -393,17 +441,17 @@ type OrgPaymentsListInput = {
393
441
  };
394
442
  type CreateCodes$6 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "INVALID_INPUT" | "INVALID_RECIPIENT" | "INSUFFICIENT_BALANCE" | "IDEMPOTENCY_CONFLICT" | "RATE_LIMITED" | "NETWORK_ERROR";
395
443
  type OrgCreateCodes = CreateCodes$6 | "POLICY_DENIED" | "SAFE_NOT_READY";
396
- type RetrieveCodes$8 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND";
397
- type ListCodes$7 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "INVALID_INPUT";
444
+ type RetrieveCodes$9 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND";
445
+ type ListCodes$8 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "INVALID_INPUT";
398
446
  type PaymentsClient = {
399
447
  readonly create: (input: PaymentsCreateInput) => Promise<CapxulResult<CreatePaymentResult, CreateCodes$6>>;
400
- readonly retrieve: (paymentId: PaymentId) => Promise<CapxulResult<Payment, RetrieveCodes$8>>;
401
- readonly list: (input?: PaymentsListInput) => Promise<CapxulResult<List<Payment>, ListCodes$7>>;
448
+ readonly retrieve: (paymentId: PaymentId) => Promise<CapxulResult<Payment, RetrieveCodes$9>>;
449
+ readonly list: (input?: PaymentsListInput) => Promise<CapxulResult<List<Payment>, ListCodes$8>>;
402
450
  };
403
451
  type OrgPaymentsClient = {
404
452
  readonly create: (input: OrgPaymentsCreateInput) => Promise<CapxulResult<CreatePaymentResult, OrgCreateCodes>>;
405
- readonly retrieve: (input: OrgPaymentsRetrieveInput) => Promise<CapxulResult<Payment, RetrieveCodes$8>>;
406
- readonly list: (input: OrgPaymentsListInput) => Promise<CapxulResult<List<Payment>, ListCodes$7>>;
453
+ readonly retrieve: (input: OrgPaymentsRetrieveInput) => Promise<CapxulResult<Payment, RetrieveCodes$9>>;
454
+ readonly list: (input: OrgPaymentsListInput) => Promise<CapxulResult<List<Payment>, ListCodes$8>>;
407
455
  };
408
456
 
409
457
  /**
@@ -452,56 +500,46 @@ type OrgTransfersCancelInput = {
452
500
  readonly transferId: TransferId;
453
501
  };
454
502
  type CreateCodes$5 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "INVALID_INPUT" | "INSUFFICIENT_BALANCE" | "IDEMPOTENCY_CONFLICT" | "RATE_LIMITED" | "NETWORK_ERROR";
455
- type RetrieveCodes$7 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND";
456
- type ListCodes$6 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "INVALID_INPUT";
503
+ type RetrieveCodes$8 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND";
504
+ type ListCodes$7 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "INVALID_INPUT";
457
505
  type ConfirmCodes = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND" | "QUOTE_EXPIRED" | "QUOTE_NOT_FOUND";
458
506
  type CancelCodes = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND" | "OPERATION_CANCELED";
459
507
  type TransfersClient = {
460
508
  readonly create: (input: TransfersCreateInput) => Promise<CapxulResult<CreateTransferResult, CreateCodes$5>>;
461
- readonly retrieve: (transferId: TransferId) => Promise<CapxulResult<Transfer, RetrieveCodes$7>>;
462
- readonly list: (input?: TransfersListInput) => Promise<CapxulResult<List<Transfer>, ListCodes$6>>;
509
+ readonly retrieve: (transferId: TransferId) => Promise<CapxulResult<Transfer, RetrieveCodes$8>>;
510
+ readonly list: (input?: TransfersListInput) => Promise<CapxulResult<List<Transfer>, ListCodes$7>>;
463
511
  readonly confirm: (input: TransfersConfirmInput) => Promise<CapxulResult<Transfer, ConfirmCodes>>;
464
512
  readonly cancel: (transferId: TransferId) => Promise<CapxulResult<Transfer, CancelCodes>>;
465
513
  };
466
514
  type OrgTransfersClient = {
467
515
  readonly create: (input: OrgTransfersCreateInput) => Promise<CapxulResult<CreateTransferResult, CreateCodes$5>>;
468
- readonly retrieve: (input: OrgTransfersRetrieveInput) => Promise<CapxulResult<Transfer, RetrieveCodes$7>>;
469
- readonly list: (input: OrgTransfersListInput) => Promise<CapxulResult<List<Transfer>, ListCodes$6>>;
516
+ readonly retrieve: (input: OrgTransfersRetrieveInput) => Promise<CapxulResult<Transfer, RetrieveCodes$8>>;
517
+ readonly list: (input: OrgTransfersListInput) => Promise<CapxulResult<List<Transfer>, ListCodes$7>>;
470
518
  readonly confirm: (input: OrgTransfersConfirmInput) => Promise<CapxulResult<Transfer, ConfirmCodes>>;
471
519
  readonly cancel: (input: OrgTransfersCancelInput) => Promise<CapxulResult<Transfer, CancelCodes>>;
472
520
  };
473
521
 
474
522
  /**
475
523
  * Withdrawals domain — funds exit Capxul via an `external_account` per
476
- * sdk-surface.md §1a + §4.52 + withdrawal-orchestration.mdx (slice 1
477
- * of Withdrawals v1, #440).
478
- *
479
- * Slice 1 NOTE — transitional input shape:
480
- * Until the `external_accounts` resource lands (slice 1.x or v2), the
481
- * destination input includes a `kind` field so the backend + SDK can
482
- * route to the chain_wallet rail without a real external_accounts
483
- * lookup. When the resource lands, `kind` becomes optional / ignored
484
- * and the kind is inferred from the resolved row.
524
+ * sdk-surface.md §1a + §4.52 + withdrawal-orchestration.mdx.
485
525
  *
486
- * Slice 1 NOTE chain_wallet rail integration:
487
- * For evm destinations, the `externalAccountId` is treated as the
488
- * destination address (must start with `0x`) so the chain_wallet rail
489
- * can call `transferAsOwner` directly. For solana / starknet the SDK
490
- * accepts the create call but does NOT execute the rail submission
491
- * the row stays in `processing` until external_accounts lands. The
492
- * caller can transition it via `markFailed` if needed.
526
+ * Withdrawals v1 W2 (#465) refactor:
527
+ * - The `kind` shim on `destination` is GONE. The backend now resolves
528
+ * the destination row by FK and infers kind + rail. Anything that
529
+ * doesn't route to `chain_wallet` returns `VERIFICATION_REQUIRED`.
530
+ * - Org-scope `create` is now a real mutation (no longer a stub).
531
+ * Personal-scope keeps the on-chain submission tail; org-scope
532
+ * returns the `processing` row only Safe + Zodiac orchestration
533
+ * ships in W3+ (D6).
534
+ * - All raw `try/catch` blocks have been replaced with `tryCatch` from
535
+ * `@repo/observability`, mirroring `core/external-accounts.ts`
536
+ * (precedent D2).
493
537
  */
494
538
 
495
539
  type WithdrawalsCreateInput = {
496
540
  readonly amount: Money;
497
541
  readonly destination: {
498
542
  readonly externalAccountId: ExternalAccountId;
499
- /**
500
- * Slice 1 transitional field. Required until the
501
- * `external_accounts` resource lands; will become optional / ignored
502
- * when the resource is the source of truth for kind.
503
- */
504
- readonly kind: "evm" | "solana" | "starknet" | "bank" | "momo" | "card_payout";
505
543
  };
506
544
  readonly source?: {
507
545
  readonly subAccountId: SubAccountId;
@@ -514,6 +552,22 @@ type WithdrawalsListInput = {
514
552
  readonly limit?: number;
515
553
  readonly cursor?: string;
516
554
  };
555
+ /**
556
+ * Withdrawals v1 W4 (#467) — input for the reconciliation pipe.
557
+ * Caller passes the same `txHash` that `recordSubmitted` wrote; the
558
+ * backend cross-checks the value against the persisted operation row.
559
+ *
560
+ * `withdrawalId` accepts either the branded `WithdrawalId` or a raw
561
+ * string. `txHash` is a raw string at the SDK boundary — the backend
562
+ * re-validates the shape via `toTxHash` at the mutation handler (the
563
+ * SDK package is no longer coupled to `@repo/types`'s brand surface
564
+ * post the alpha-epic decoupling; see
565
+ * `packages/sdk/docs/internal/decoupling-prep.md`).
566
+ */
567
+ type WithdrawalsRecordCompletedInput = {
568
+ readonly withdrawalId: WithdrawalId | string;
569
+ readonly txHash: string;
570
+ };
517
571
  type OrgWithdrawalsCreateInput = WithdrawalsCreateInput & {
518
572
  readonly organizationId: OrganizationId;
519
573
  };
@@ -526,18 +580,40 @@ type OrgWithdrawalsListInput = {
526
580
  readonly limit?: number;
527
581
  readonly cursor?: string;
528
582
  };
529
- type CreateCodes$4 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "INVALID_INPUT" | "INSUFFICIENT_BALANCE" | "IDEMPOTENCY_CONFLICT" | "KYC_REQUIRED" | "POLICY_DENIED" | "RATE_LIMITED" | "NETWORK_ERROR";
530
- type RetrieveCodes$6 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND";
531
- type ListCodes$5 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "INVALID_INPUT";
583
+ type CreateCodes$4 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "INVALID_INPUT" | "INSUFFICIENT_BALANCE" | "IDEMPOTENCY_CONFLICT" | "KYC_REQUIRED" | "POLICY_DENIED" | "RATE_LIMITED" | "NETWORK_ERROR" | "NOT_FOUND" | "VERIFICATION_REQUIRED";
584
+ type RetrieveCodes$7 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND";
585
+ type ListCodes$6 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "INVALID_INPUT";
586
+ /**
587
+ * Narrow code set for `recordCompleted`. Mirror of `recordSubmitted`'s
588
+ * code surface — the SDK does NOT export `recordSubmitted` publicly
589
+ * (the create signing tail invokes it), but the call shape is the
590
+ * reference. Per ADR 9, `recordCompleted` is exposed on personal-scope
591
+ * `WithdrawalsClient` ONLY.
592
+ */
593
+ type RecordCompletedCodes = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "INVALID_INPUT" | "NOT_FOUND" | "NETWORK_ERROR" | "INTERNAL_ERROR";
532
594
  type WithdrawalsClient = {
533
595
  readonly create: (input: WithdrawalsCreateInput) => Promise<CapxulResult<CreateWithdrawalResult, CreateCodes$4>>;
534
- readonly retrieve: (withdrawalId: WithdrawalId) => Promise<CapxulResult<Withdrawal, RetrieveCodes$6>>;
535
- readonly list: (input?: WithdrawalsListInput) => Promise<CapxulResult<List<Withdrawal>, ListCodes$5>>;
596
+ readonly retrieve: (withdrawalId: WithdrawalId) => Promise<CapxulResult<Withdrawal, RetrieveCodes$7>>;
597
+ readonly list: (input?: WithdrawalsListInput) => Promise<CapxulResult<List<Withdrawal>, ListCodes$6>>;
598
+ /**
599
+ * Withdrawals v1 W4 (#467) — reconciliation pipe.
600
+ *
601
+ * Caller invokes this AFTER `withdrawals.create` resolves AND after
602
+ * the on-chain receipt confirms (e.g., via the harness's
603
+ * `chain.waitReceipt`). The mutation patches the withdrawal +
604
+ * execution + attempt + operation rows to terminal happy state and
605
+ * emits a single `operation.succeeded` outbox event joined to the
606
+ * original correlationId. Idempotent on already-`completed` rows.
607
+ *
608
+ * Personal-scope only — the org-scope client does NOT expose this
609
+ * method (mirror of `recordSubmitted`; see ADR 9 in #467).
610
+ */
611
+ readonly recordCompleted: (input: WithdrawalsRecordCompletedInput) => Promise<CapxulResult<null, RecordCompletedCodes>>;
536
612
  };
537
613
  type OrgWithdrawalsClient = {
538
614
  readonly create: (input: OrgWithdrawalsCreateInput) => Promise<CapxulResult<CreateWithdrawalResult, CreateCodes$4>>;
539
- readonly retrieve: (input: OrgWithdrawalsRetrieveInput) => Promise<CapxulResult<Withdrawal, RetrieveCodes$6>>;
540
- readonly list: (input: OrgWithdrawalsListInput) => Promise<CapxulResult<List<Withdrawal>, ListCodes$5>>;
615
+ readonly retrieve: (input: OrgWithdrawalsRetrieveInput) => Promise<CapxulResult<Withdrawal, RetrieveCodes$7>>;
616
+ readonly list: (input: OrgWithdrawalsListInput) => Promise<CapxulResult<List<Withdrawal>, ListCodes$6>>;
541
617
  };
542
618
 
543
619
  /**
@@ -549,7 +625,7 @@ type OrgWithdrawalsClient = {
549
625
  * variant at call time and require `organizationId` explicitly.
550
626
  */
551
627
 
552
- type WebhookEndpointsCreateInput = types.CreateWebhookEndpointRequest & {
628
+ type WebhookEndpointsCreateInput = CreateWebhookEndpointRequest & {
553
629
  readonly organizationId: OrganizationId;
554
630
  };
555
631
  type WebhookEndpointsRetrieveInput = {
@@ -563,9 +639,9 @@ type WebhookEndpointsListInput = {
563
639
  };
564
640
  type WebhookEndpointsRemoveInput = WebhookEndpointsRetrieveInput;
565
641
  type CreateCodes$3 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "INVALID_INPUT" | "RATE_LIMITED" | "NETWORK_ERROR";
566
- type RetrieveCodes$5 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND";
567
- type ListCodes$4 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "INVALID_INPUT";
568
- type RemoveCodes$3 = RetrieveCodes$5;
642
+ type RetrieveCodes$6 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND";
643
+ type ListCodes$5 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "INVALID_INPUT";
644
+ type RemoveCodes$3 = RetrieveCodes$6;
569
645
  /**
570
646
  * Shape returned by `organizations.webhookEndpoints.create` — the
571
647
  * one-time `signingSecret` is included here and omitted from every
@@ -576,8 +652,8 @@ type WebhookEndpointCreateResult = WebhookEndpoint & {
576
652
  };
577
653
  type WebhookEndpointsClient = {
578
654
  readonly create: (input: WebhookEndpointsCreateInput) => Promise<CapxulResult<WebhookEndpointCreateResult, CreateCodes$3>>;
579
- readonly retrieve: (input: WebhookEndpointsRetrieveInput) => Promise<CapxulResult<WebhookEndpoint, RetrieveCodes$5>>;
580
- readonly list: (input: WebhookEndpointsListInput) => Promise<CapxulResult<List<WebhookEndpoint>, ListCodes$4>>;
655
+ readonly retrieve: (input: WebhookEndpointsRetrieveInput) => Promise<CapxulResult<WebhookEndpoint, RetrieveCodes$6>>;
656
+ readonly list: (input: WebhookEndpointsListInput) => Promise<CapxulResult<List<WebhookEndpoint>, ListCodes$5>>;
581
657
  readonly remove: (input: WebhookEndpointsRemoveInput) => Promise<CapxulResult<void, RemoveCodes$3>>;
582
658
  };
583
659
 
@@ -598,11 +674,11 @@ type WebhookEventsListInput = {
598
674
  readonly endpointId?: string;
599
675
  readonly type?: string;
600
676
  };
601
- type RetrieveCodes$4 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND";
602
- type ListCodes$3 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "INVALID_INPUT";
677
+ type RetrieveCodes$5 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND";
678
+ type ListCodes$4 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "INVALID_INPUT";
603
679
  type WebhookEventsClient = {
604
- readonly retrieve: (input: WebhookEventsRetrieveInput) => Promise<CapxulResult<WebhookEvent, RetrieveCodes$4>>;
605
- readonly list: (input: WebhookEventsListInput) => Promise<CapxulResult<List<WebhookEvent>, ListCodes$3>>;
680
+ readonly retrieve: (input: WebhookEventsRetrieveInput) => Promise<CapxulResult<WebhookEvent, RetrieveCodes$5>>;
681
+ readonly list: (input: WebhookEventsListInput) => Promise<CapxulResult<List<WebhookEvent>, ListCodes$4>>;
606
682
  };
607
683
 
608
684
  /**
@@ -661,6 +737,7 @@ type OrgKybProfileRetrieveInput = {
661
737
  type OrgCreateSubAccountInput = {
662
738
  readonly organizationId: OrganizationId;
663
739
  readonly name: string;
740
+ readonly purpose?: string;
664
741
  };
665
742
  type OrgCreateExternalAccountInput = {
666
743
  readonly organizationId: OrganizationId;
@@ -675,8 +752,8 @@ type OrgCreateExternalAccountInput = {
675
752
  readonly last4?: string;
676
753
  };
677
754
  type CreateCodes$2 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "INVALID_INPUT" | "RATE_LIMITED" | "NETWORK_ERROR";
678
- type RetrieveCodes$3 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND";
679
- type ListCodes$2 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "INVALID_INPUT";
755
+ type RetrieveCodes$4 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND";
756
+ type ListCodes$3 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "INVALID_INPUT";
680
757
  type UpdateCodes = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND" | "INVALID_INPUT";
681
758
  /**
682
759
  * Org safe retrieve does NOT surface `SAFE_NOT_READY` — a co-member
@@ -691,7 +768,8 @@ type UpdateCodes = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND" | "IN
691
768
  */
692
769
  type SafeRetrieveCodes = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND";
693
770
  type TreasuryRetrieveCodes = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND" | "SAFE_NOT_READY";
694
- type RemoveCodes$2 = RetrieveCodes$3;
771
+ type RemoveCodes$2 = RetrieveCodes$4;
772
+ type SubAccountRemoveCodes = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND" | "INVALID_INPUT";
695
773
  type OrgSafesClient = {
696
774
  readonly retrieve: (input: OrgSafeRetrieveInput) => Promise<CapxulResult<Safe, SafeRetrieveCodes>>;
697
775
  };
@@ -699,52 +777,52 @@ type OrgTreasuryClient = {
699
777
  readonly retrieve: (organizationId: OrganizationId) => Promise<CapxulResult<Treasury, TreasuryRetrieveCodes>>;
700
778
  };
701
779
  type OrgMembersClient = {
702
- readonly list: (input: OrgListInput) => Promise<CapxulResult<List<Member>, ListCodes$2>>;
703
- readonly retrieve: (input: OrgMemberRetrieveInput) => Promise<CapxulResult<Member, RetrieveCodes$3>>;
780
+ readonly list: (input: OrgListInput) => Promise<CapxulResult<List<Member>, ListCodes$3>>;
781
+ readonly retrieve: (input: OrgMemberRetrieveInput) => Promise<CapxulResult<Member, RetrieveCodes$4>>;
704
782
  readonly invite: (input: OrgMemberInviteInput) => Promise<CapxulResult<Member, UpdateCodes>>;
705
783
  readonly updateRole: (input: OrgMemberUpdateRoleInput) => Promise<CapxulResult<Member, UpdateCodes>>;
706
784
  readonly remove: (input: OrgMemberRemoveInput) => Promise<CapxulResult<void, RemoveCodes$2>>;
707
785
  };
708
786
  type OrgKybProfileClient = {
709
787
  readonly start: (input: OrgKybProfileStartInput) => Promise<CapxulResult<KybProfile, CreateCodes$2>>;
710
- readonly retrieve: (input: OrgKybProfileRetrieveInput) => Promise<CapxulResult<KybProfile, RetrieveCodes$3>>;
788
+ readonly retrieve: (input: OrgKybProfileRetrieveInput) => Promise<CapxulResult<KybProfile, RetrieveCodes$4>>;
711
789
  };
712
790
  type OrgSubAccountsClient = {
713
- readonly create: (input: OrgCreateSubAccountInput) => Promise<CapxulResult<SubAccount, UpdateCodes>>;
714
- readonly list: (input: OrgListInput) => Promise<CapxulResult<List<SubAccount>, ListCodes$2>>;
791
+ readonly create: (input: OrgCreateSubAccountInput) => Promise<CapxulResult<SubAccount, UpdateCodes | "PROVIDER_ERROR">>;
792
+ readonly list: (input: OrgListInput) => Promise<CapxulResult<List<SubAccount>, ListCodes$3 | "PROVIDER_ERROR">>;
715
793
  readonly retrieve: (input: {
716
794
  readonly organizationId: OrganizationId;
717
795
  readonly subAccountId: SubAccountId;
718
- }) => Promise<CapxulResult<SubAccount, RetrieveCodes$3>>;
796
+ }) => Promise<CapxulResult<SubAccount, RetrieveCodes$4 | "PROVIDER_ERROR">>;
719
797
  readonly remove: (input: {
720
798
  readonly organizationId: OrganizationId;
721
799
  readonly subAccountId: SubAccountId;
722
- }) => Promise<CapxulResult<void, RemoveCodes$2>>;
800
+ }) => Promise<CapxulResult<SubAccount, SubAccountRemoveCodes | "PROVIDER_ERROR">>;
723
801
  };
724
802
  type OrgExternalAccountsClient = {
725
803
  readonly create: (input: OrgCreateExternalAccountInput) => Promise<CapxulResult<ExternalAccount, UpdateCodes>>;
726
- readonly list: (input: OrgListInput) => Promise<CapxulResult<List<ExternalAccount>, ListCodes$2>>;
804
+ readonly list: (input: OrgListInput) => Promise<CapxulResult<List<ExternalAccount>, ListCodes$3>>;
727
805
  readonly retrieve: (input: {
728
806
  readonly organizationId: OrganizationId;
729
807
  readonly externalAccountId: ExternalAccountId;
730
- }) => Promise<CapxulResult<ExternalAccount, RetrieveCodes$3>>;
808
+ }) => Promise<CapxulResult<ExternalAccount, RetrieveCodes$4>>;
731
809
  readonly remove: (input: {
732
810
  readonly organizationId: OrganizationId;
733
811
  readonly externalAccountId: ExternalAccountId;
734
812
  }) => Promise<CapxulResult<void, RemoveCodes$2>>;
735
813
  };
736
814
  type OrgBalanceLedgerClient = {
737
- readonly list: (input: OrgListInput) => Promise<CapxulResult<List<BalanceLedgerEntry>, ListCodes$2>>;
815
+ readonly list: (input: OrgListInput) => Promise<CapxulResult<List<BalanceLedgerEntry>, ListCodes$3>>;
738
816
  readonly retrieve: (input: {
739
817
  readonly organizationId: OrganizationId;
740
818
  readonly entryId: string;
741
- }) => Promise<CapxulResult<BalanceLedgerEntry, RetrieveCodes$3>>;
819
+ }) => Promise<CapxulResult<BalanceLedgerEntry, RetrieveCodes$4>>;
742
820
  };
743
821
  type OrgApiKeysClient = ApiKeysClient;
744
822
  type OrganizationsClient = {
745
823
  readonly create: (input: OrganizationsCreateInput) => Promise<CapxulResult<Organization, CreateCodes$2>>;
746
- readonly retrieve: (organizationId: OrganizationId) => Promise<CapxulResult<Organization, RetrieveCodes$3>>;
747
- readonly list: (input?: OrganizationsListInput) => Promise<CapxulResult<List<Organization>, ListCodes$2>>;
824
+ readonly retrieve: (organizationId: OrganizationId) => Promise<CapxulResult<Organization, RetrieveCodes$4>>;
825
+ readonly list: (input?: OrganizationsListInput) => Promise<CapxulResult<List<Organization>, ListCodes$3>>;
748
826
  readonly update: (input: OrganizationsUpdateInput) => Promise<CapxulResult<Organization, UpdateCodes>>;
749
827
  readonly safes: OrgSafesClient;
750
828
  readonly treasury: OrgTreasuryClient;
@@ -844,7 +922,7 @@ type TransportState = {
844
922
  readonly runtime: TransportRuntime;
845
923
  } | {
846
924
  readonly status: "error";
847
- readonly error: CapxulError;
925
+ readonly error: CapxulError$1;
848
926
  };
849
927
  type TransportRuntime = {
850
928
  readonly authBaseUrl: string;
@@ -871,6 +949,7 @@ type TransportRuntime = {
871
949
  */
872
950
  type HttpTransport = {
873
951
  readonly fetch: (path: string, init?: RequestInit) => Promise<Response>;
952
+ readonly ensureRuntime: () => Promise<TransportRuntime>;
874
953
  readonly authBaseUrl: string;
875
954
  readonly convexUrl: string;
876
955
  readonly getState: () => TransportState;
@@ -884,8 +963,11 @@ type HttpTransport = {
884
963
  /**
885
964
  * Build an `HttpTransport` from a `BrowserCapxulConfig`.
886
965
  *
887
- * Throws `Errors.invalidInput("authBaseUrl" | "convexUrl", reason)`
888
- * when the build-time-urls variant is missing required URLs.
966
+ * Throws `CapxulError<"INVALID_INPUT">` with
967
+ * `details.source === "sdk-config"` when local transport config is
968
+ * malformed. Backend bootstrap failures also throw `CapxulError`, but
969
+ * carry `details.source === "backend-bootstrap"` so consumers can
970
+ * distinguish setup mistakes from server-side bootstrap refusals.
889
971
  */
890
972
  declare function makeHttpTransport(config: BrowserCapxulConfig): HttpTransport;
891
973
 
@@ -899,13 +981,118 @@ declare function makeHttpTransport(config: BrowserCapxulConfig): HttpTransport;
899
981
  * `accounts.subAccounts.create(...)` or
900
982
  * `organizations.subAccounts.create(...)`), so only `retrieve` and
901
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.
902
991
  */
903
992
 
904
- type RetrieveCodes$2 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND";
905
- type RemoveCodes$1 = RetrieveCodes$2;
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";
906
995
  type SubAccountsClient = {
907
- readonly retrieve: (subAccountId: SubAccountId) => Promise<CapxulResult<SubAccount, RetrieveCodes$2>>;
908
- readonly remove: (subAccountId: SubAccountId) => Promise<CapxulResult<void, RemoveCodes$1>>;
996
+ readonly retrieve: (subAccountId: SubAccountId) => Promise<CapxulResult<SubAccount, RetrieveCodes$3>>;
997
+ readonly remove: (subAccountId: SubAccountId) => Promise<CapxulResult<SubAccount, RemoveCodes$1>>;
998
+ };
999
+
1000
+ /**
1001
+ * **NON-CANONICAL surface.**
1002
+ *
1003
+ * `capxul.tokenTransfers.*` exposes the indexer's raw on-chain ERC-20
1004
+ * transfer rows directly to consumers, backed by
1005
+ * `packages/backend/convex/tokenTransfers/queries.ts`. Authorized at
1006
+ * `slice/02-story2-balance` per the conductor's Option-A verdict —
1007
+ * the canonical SDK `transfers.*` namespace assumes a cross-custody
1008
+ * internal-move shape (`Transfer = { source, destination, fx,
1009
+ * operation, ... }`) that has no canon-aligned backing query yet.
1010
+ * Surfacing the on-chain feed under a separate, clearly-marked
1011
+ * non-canonical namespace lets the Ink CLI's activity dashboard
1012
+ * progress without forcing canon synthesis.
1013
+ *
1014
+ * **NOT in `packages/api-contract`.** Do NOT use this surface as the
1015
+ * basis for new canon. When `transfers.*` shape alignment lands
1016
+ * (post-alpha.4 follow-up issue), the canonical `transfers.*` will
1017
+ * subsume this and `tokenTransfers.*` becomes a deprecation alias.
1018
+ *
1019
+ * Stub families that REMAIN deferred at this slice
1020
+ * (per `[DEFERRED-CANON]` markers in
1021
+ * `.claude/worktrees/post-alpha-wire2/.progress.txt`):
1022
+ * - `transfers.{create,retrieve,list,confirm,cancel}` — canon shape mismatch
1023
+ * - `accounts.balanceLedger.{list,retrieve}` — no canon backing query
1024
+ * - `organizations.balanceLedger.*` — no canon backing query
1025
+ * - `organizations.transfers.*` — canon shape mismatch
1026
+ * - `organizations.treasury.retrieve` — backing query has different shape
1027
+ */
1028
+
1029
+ /**
1030
+ * Branded id for an on-chain `tokenTransfer` row. Backed by the
1031
+ * Convex document id; the brand prevents accidental swaps with other
1032
+ * SDK ids without leaking the document-id constraint into call sites.
1033
+ *
1034
+ * Returned in `TokenTransfer.id` for clients that want a stable
1035
+ * back-reference; the canonical lookup key is the
1036
+ * `(txHash, logIndex)` composite used by `retrieve`.
1037
+ */
1038
+ type TokenTransferId = string & {
1039
+ readonly __capxulTokenTransferIdBrand: "TokenTransferId";
1040
+ };
1041
+ declare const toTokenTransferId: (raw: string) => TokenTransferId;
1042
+ /**
1043
+ * Raw on-chain ERC-20 transfer row. Shape mirrors
1044
+ * `tokenTransfers/queries.ts` `list` / `getByTxLogIndex` output. The
1045
+ * primitive fields (`txHash`, `tokenAddress`, etc.) match
1046
+ * `@repo/api-contract` conventions — `string` for hashes/addresses,
1047
+ * `number` for block + chain ids — so consumers don't need to import
1048
+ * a brand surface that isn't in the SDK's published deps.
1049
+ */
1050
+ type TokenTransfer = {
1051
+ readonly id: TokenTransferId;
1052
+ readonly object: "token_transfer";
1053
+ readonly direction: "in" | "out";
1054
+ /** Token-units string ("123456" not "1.23456"). Decimals carried in `tokenDecimals`. */
1055
+ readonly amount: string;
1056
+ readonly tokenSymbol: string;
1057
+ readonly tokenDecimals: number;
1058
+ readonly tokenAddress: string;
1059
+ readonly counterpartyName: string | null;
1060
+ readonly counterpartyAddress: string;
1061
+ readonly description: string;
1062
+ /** Block timestamp in epoch milliseconds. */
1063
+ readonly createdAt: number;
1064
+ readonly txHash: string;
1065
+ readonly blockNumber: number;
1066
+ readonly chainId: number;
1067
+ };
1068
+ type TokenTransfersListPage = {
1069
+ readonly object: "list";
1070
+ readonly data: readonly TokenTransfer[];
1071
+ readonly page: {
1072
+ readonly hasMore: boolean;
1073
+ /** Block-timestamp cursor (epoch ms) for the next page; null when exhausted. */
1074
+ readonly nextCursor: number | null;
1075
+ };
1076
+ /** Caller's display currency. The backend echoes it so renderers don't need a second round-trip. */
1077
+ readonly displayCurrency: string;
1078
+ };
1079
+ type TokenTransfersListInput = {
1080
+ readonly limit?: number;
1081
+ /** Block-timestamp cursor (epoch ms) returned in the previous page's `page.nextCursor`. */
1082
+ readonly cursor?: number;
1083
+ readonly direction?: "in" | "out";
1084
+ };
1085
+ type TokenTransfersRetrieveInput = {
1086
+ readonly txHash: string;
1087
+ readonly logIndex: number;
1088
+ /** Optional chain filter. When omitted, the first index hit wins (single-chain default). */
1089
+ readonly chainId?: number;
1090
+ };
1091
+ type ListCodes$2 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "INVALID_INPUT";
1092
+ type RetrieveCodes$2 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND";
1093
+ type TokenTransfersClient = {
1094
+ readonly list: (input?: TokenTransfersListInput) => Promise<CapxulResult<TokenTransfersListPage, ListCodes$2>>;
1095
+ readonly retrieve: (input: TokenTransfersRetrieveInput) => Promise<CapxulResult<TokenTransfer, RetrieveCodes$2>>;
909
1096
  };
910
1097
 
911
1098
  /**
@@ -917,7 +1104,7 @@ type SubAccountsClient = {
917
1104
  * in the create payload rather than nesting the route under the owner.
918
1105
  */
919
1106
 
920
- type VirtualAccountsCreateInput = types.CreateVirtualAccountRequest;
1107
+ type VirtualAccountsCreateInput = CreateVirtualAccountRequest;
921
1108
  type VirtualAccountsListInput = {
922
1109
  readonly limit?: number;
923
1110
  readonly cursor?: string;
@@ -942,7 +1129,7 @@ type VirtualAccountsClient = {
942
1129
  * Uses Pattern C (ownerKind in body).
943
1130
  */
944
1131
 
945
- type VirtualCardsCreateInput = types.CreateVirtualCardRequest;
1132
+ type VirtualCardsCreateInput = CreateVirtualCardRequest;
946
1133
  type VirtualCardsListInput = {
947
1134
  readonly limit?: number;
948
1135
  readonly cursor?: string;
@@ -962,6 +1149,161 @@ type VirtualCardsClient = {
962
1149
  readonly cancel: (virtualCardId: VirtualCardId) => Promise<CapxulResult<VirtualCard, MutateCodes>>;
963
1150
  };
964
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" | "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 signerProvider: LocalPrivateKeySignerProvider | null;
1179
+ readonly bootstrapToken: AuthBootstrapToken | null;
1180
+ readonly bootstrapReason: AuthBootstrapReason | null;
1181
+ readonly session: Session | null;
1182
+ readonly account: Account | null;
1183
+ readonly safe: Safe | null;
1184
+ readonly error: AuthBootstrapFlowError | null;
1185
+ };
1186
+ type AuthBootstrapFlowEvent = {
1187
+ readonly type: "ENTER_EMAIL";
1188
+ readonly email: Email;
1189
+ } | {
1190
+ readonly type: "REQUEST_OTP";
1191
+ } | {
1192
+ readonly type: "ENTER_OTP";
1193
+ readonly code: string;
1194
+ } | {
1195
+ readonly type: "VERIFY_OTP";
1196
+ } | {
1197
+ readonly type: "ENTER_USERNAME";
1198
+ readonly username: Username;
1199
+ } | {
1200
+ readonly type: "ENTER_SIGNER_PROVIDER";
1201
+ readonly signerProvider: LocalPrivateKeySignerProvider;
1202
+ } | {
1203
+ readonly type: "COMPLETE_BOOTSTRAP";
1204
+ } | {
1205
+ readonly type: "BACK";
1206
+ } | {
1207
+ readonly type: "RESET";
1208
+ } | {
1209
+ readonly type: "SIGN_OUT";
1210
+ };
1211
+ declare function createAuthBootstrapFlowMachine(client: CapxulClient): xstate.StateMachine<AuthBootstrapFlowContext, {
1212
+ readonly type: "ENTER_EMAIL";
1213
+ readonly email: Email;
1214
+ } | {
1215
+ readonly type: "REQUEST_OTP";
1216
+ } | {
1217
+ readonly type: "ENTER_OTP";
1218
+ readonly code: string;
1219
+ } | {
1220
+ readonly type: "VERIFY_OTP";
1221
+ } | {
1222
+ readonly type: "ENTER_USERNAME";
1223
+ readonly username: Username;
1224
+ } | {
1225
+ readonly type: "ENTER_SIGNER_PROVIDER";
1226
+ readonly signerProvider: LocalPrivateKeySignerProvider;
1227
+ } | {
1228
+ readonly type: "COMPLETE_BOOTSTRAP";
1229
+ } | {
1230
+ readonly type: "BACK";
1231
+ } | {
1232
+ readonly type: "RESET";
1233
+ } | {
1234
+ readonly type: "SIGN_OUT";
1235
+ }, {
1236
+ [x: string]: xstate.ActorRefFromLogic<xstate.PromiseActorLogic<void, void, xstate.EventObject>> | xstate.ActorRefFromLogic<xstate.PromiseActorLogic<void, {
1237
+ email: Email;
1238
+ }, xstate.EventObject>> | xstate.ActorRefFromLogic<xstate.PromiseActorLogic<VerifyOtpResult, {
1239
+ email: Email;
1240
+ code: string;
1241
+ }, xstate.EventObject>> | xstate.ActorRefFromLogic<xstate.PromiseActorLogic<CompleteBootstrapResult, {
1242
+ bootstrapToken: AuthBootstrapToken;
1243
+ username: Username;
1244
+ signerProvider: LocalPrivateKeySignerProvider;
1245
+ }, xstate.EventObject>> | undefined;
1246
+ }, {
1247
+ src: "sendOtp";
1248
+ logic: xstate.PromiseActorLogic<void, {
1249
+ email: Email;
1250
+ }, xstate.EventObject>;
1251
+ id: string | undefined;
1252
+ } | {
1253
+ src: "verifyOtp";
1254
+ logic: xstate.PromiseActorLogic<VerifyOtpResult, {
1255
+ email: Email;
1256
+ code: string;
1257
+ }, xstate.EventObject>;
1258
+ id: string | undefined;
1259
+ } | {
1260
+ src: "signOut";
1261
+ logic: xstate.PromiseActorLogic<void, void, xstate.EventObject>;
1262
+ id: string | undefined;
1263
+ } | {
1264
+ src: "completeBootstrap";
1265
+ logic: xstate.PromiseActorLogic<CompleteBootstrapResult, {
1266
+ bootstrapToken: AuthBootstrapToken;
1267
+ username: Username;
1268
+ signerProvider: LocalPrivateKeySignerProvider;
1269
+ }, xstate.EventObject>;
1270
+ id: string | undefined;
1271
+ }, {
1272
+ type: "trackOtpRequested";
1273
+ params: unknown;
1274
+ } | {
1275
+ type: "trackTimeoutFailed";
1276
+ params: unknown;
1277
+ } | {
1278
+ type: "trackVerified";
1279
+ params: unknown;
1280
+ } | {
1281
+ type: "identifyAndTrack";
1282
+ params: unknown;
1283
+ } | {
1284
+ type: "trackSignedOut";
1285
+ params: unknown;
1286
+ } | {
1287
+ type: "trackFailed";
1288
+ params: unknown;
1289
+ } | {
1290
+ type: "trackBootstrapRequired";
1291
+ params: unknown;
1292
+ }, 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, {
1293
+ id: "authBootstrap";
1294
+ states: {
1295
+ readonly email: {};
1296
+ readonly sending_otp: {};
1297
+ readonly otp_requested: {};
1298
+ readonly verifying_otp: {};
1299
+ readonly bootstrap_required: {};
1300
+ readonly completing_bootstrap: {};
1301
+ readonly authenticated: {};
1302
+ readonly signing_out: {};
1303
+ readonly error: {};
1304
+ };
1305
+ }>;
1306
+
965
1307
  /**
966
1308
  * Root `@capxul/sdk` client factory.
967
1309
  *
@@ -1089,6 +1431,7 @@ type CapxulConfig = {
1089
1431
  */
1090
1432
  type CapxulFlowFactories = {
1091
1433
  readonly auth: () => AnyStateMachine;
1434
+ readonly authBootstrap: () => ReturnType<typeof createAuthBootstrapFlowMachine>;
1092
1435
  readonly onboarding: () => AnyStateMachine;
1093
1436
  readonly provisioning: () => AnyStateMachine;
1094
1437
  };
@@ -1115,6 +1458,13 @@ type CapxulClient = {
1115
1458
  readonly organizations: OrganizationsClient;
1116
1459
  readonly payments: PaymentsClient;
1117
1460
  readonly transfers: TransfersClient;
1461
+ /**
1462
+ * **NON-CANONICAL.** On-chain ERC-20 transfer feed (raw indexer
1463
+ * rows). NOT part of `packages/api-contract`. Slated for
1464
+ * deprecation when canonical `transfers.*` shape alignment lands.
1465
+ * See `core/token-transfers.ts` for the doc-comment contract.
1466
+ */
1467
+ readonly tokenTransfers: TokenTransfersClient;
1118
1468
  readonly withdrawals: WithdrawalsClient;
1119
1469
  readonly documents: DocumentsClient;
1120
1470
  readonly subAccounts: SubAccountsClient;
@@ -1144,4 +1494,4 @@ type CapxulClient = {
1144
1494
  */
1145
1495
  declare function createCapxulClient(config?: CapxulConfig): CapxulClient;
1146
1496
 
1147
- export { type AccountProvisionPersonalInput as A, type BrowserCapxulConfig as B, type CapxulClient as C, type DocumentsClient as D, type ExternalAccountsClient as E, type HttpTransport as H, type LocalPrivateKeySignerProvider as L, type MeClient as M, type OperationsClient as O, type PaymentsClient as P, type Session as S, type TransfersClient 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 TransportRuntime as s, type TransportState as t, type VirtualCardsClient as u, type WebhookEndpointsClient as v, type WebhookEventsClient as w, type WithdrawalsClient as x, createCapxulClient as y, makeHttpTransport as z };
1497
+ export { createAuthBootstrapFlowMachine as $, type AccountProvisionPersonalInput as A, type BrowserCapxulConfig as B, CapxulError as C, type DocumentsClient as D, type ExternalAccountsClient as E, type TokenTransferId as F, type TokenTransfersClient as G, type HttpTransport as H, type TokenTransfersListInput as I, type TokenTransfersListPage as J, type TokenTransfersRetrieveInput as K, type LocalPrivateKeySignerProvider as L, type MeClient as M, type TransfersClient as N, type OperationsClient as O, type PaymentsClient as P, type TransportRuntime as Q, type TransportState as R, type Session as S, type TokenTransfer as T, type VirtualAccountsClient as U, type VerifyOtpResult as V, type VirtualCardsClient as W, type WebhookEndpointCreateResult as X, type WebhookEndpointsClient as Y, type WebhookEventsClient as Z, type WithdrawalsClient as _, type CapxulClient as a, createCapxulClient as a0, makeHttpTransport as a1, toTokenTransferId as a2, type AccountsClient as b, type ApiKeyCreateResult as c, type ApiKeysClient as d, type AuthBootstrapFlowContext as e, type AuthBootstrapFlowError as f, type AuthBootstrapFlowEvent as g, type AuthBootstrapReason as h, type AuthBootstrapToken as i, type AuthClient as j, type AuthSessionStore as k, type CapxulAuthConfig as l, type CapxulConfig as m, type CapxulDataClient as n, type CapxulFlowFactories as o, type CapxulSigningConfig as p, type CompleteBootstrapInput as q, type CompleteBootstrapResult as r, type OrgDocumentsClient as s, type OrgPaymentsClient as t, type OrgSafesClient as u, type OrgTransfersClient as v, type OrgTreasuryClient as w, type OrgWithdrawalsClient as x, type OrganizationsClient as y, type SubAccountsClient as z };