@capxul/sdk 0.1.0-alpha.6 → 0.1.0-alpha.9

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-X02RbQ2u.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.
@@ -111,7 +111,7 @@ type AccountsClient = {
111
111
  * on `create` only; subsequent reads omit it.
112
112
  */
113
113
 
114
- type ApiKeysCreateInput = types.CreateApiKeyRequest & {
114
+ type ApiKeysCreateInput = CreateApiKeyRequest & {
115
115
  readonly organizationId: OrganizationId;
116
116
  };
117
117
  type ApiKeysRetrieveInput = {
@@ -190,6 +190,38 @@ type AuthVerifyOtpInput = {
190
190
  readonly email: string;
191
191
  readonly otp: string;
192
192
  };
193
+ type AuthBootstrapToken = string & {
194
+ readonly __capxulAuthBootstrapTokenBrand: "AuthBootstrapToken";
195
+ };
196
+ type AuthBootstrapReason = "new_member" | "missing_profile" | "missing_account" | "missing_safe" | "missing_signer_grant";
197
+ type VerifyOtpResult = {
198
+ readonly kind: "existing_member";
199
+ readonly session: Session;
200
+ readonly account: Account;
201
+ readonly username: Username;
202
+ readonly safe: Safe;
203
+ } | {
204
+ readonly kind: "bootstrap_required";
205
+ readonly session: Session;
206
+ readonly bootstrapToken: AuthBootstrapToken;
207
+ readonly email: Email;
208
+ readonly reason: AuthBootstrapReason;
209
+ readonly username?: Username;
210
+ };
211
+ type CompleteBootstrapInput = {
212
+ readonly bootstrapToken: AuthBootstrapToken;
213
+ readonly username: Username;
214
+ readonly signerProvider: LocalPrivateKeySignerProvider;
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
+ };
193
225
  type AuthServiceTokenMintInput = {
194
226
  readonly apiKey: string;
195
227
  readonly audience?: string;
@@ -212,13 +244,15 @@ type ServiceToken = {
212
244
  readonly expiresAt: TimestampIso;
213
245
  };
214
246
  type SendOtpCodes = "EMAIL_DELIVERY_FAILED" | "INVALID_INPUT" | "RATE_LIMITED" | "NETWORK_ERROR";
215
- type VerifyOtpCodes = "INVALID_INPUT" | "NOT_AUTHENTICATED" | "RATE_LIMITED" | "NETWORK_ERROR";
247
+ type VerifyOtpCodes = "INVALID_INPUT" | "NOT_AUTHENTICATED" | "RATE_LIMITED" | "OPERATION_TIMEOUT" | "NETWORK_ERROR";
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";
216
249
  type GetSessionCodes = "NETWORK_ERROR";
217
250
  type SignOutCodes = "NOT_AUTHENTICATED" | "NETWORK_ERROR";
218
251
  type ServiceTokenMintCodes = "API_KEY_INVALID" | "API_KEY_EXPIRED" | "INVALID_INPUT" | "RATE_LIMITED" | "NETWORK_ERROR";
219
252
  type AuthClient = {
220
253
  readonly sendOtp: (input: AuthSendOtpInput, options?: AuthMethodOptions) => Promise<CapxulResult<void, SendOtpCodes>>;
221
- 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>>;
222
256
  readonly getSession: () => Promise<CapxulResult<Session | null, GetSessionCodes>>;
223
257
  readonly signOut: () => Promise<CapxulResult<void, SignOutCodes>>;
224
258
  readonly serviceTokenMint: (input: AuthServiceTokenMintInput) => Promise<CapxulResult<ServiceToken, ServiceTokenMintCodes>>;
@@ -236,7 +270,7 @@ type AuthClient = {
236
270
  * bank_statement | tax_form`.
237
271
  */
238
272
 
239
- type DocumentsCreateInput = types.CreateDocumentRequest;
273
+ type DocumentsCreateInput = CreateDocumentRequest;
240
274
  type DocumentsListInput = {
241
275
  readonly limit?: number;
242
276
  readonly cursor?: string;
@@ -589,7 +623,7 @@ type OrgWithdrawalsClient = {
589
623
  * variant at call time and require `organizationId` explicitly.
590
624
  */
591
625
 
592
- type WebhookEndpointsCreateInput = types.CreateWebhookEndpointRequest & {
626
+ type WebhookEndpointsCreateInput = CreateWebhookEndpointRequest & {
593
627
  readonly organizationId: OrganizationId;
594
628
  };
595
629
  type WebhookEndpointsRetrieveInput = {
@@ -884,7 +918,7 @@ type TransportState = {
884
918
  readonly runtime: TransportRuntime;
885
919
  } | {
886
920
  readonly status: "error";
887
- readonly error: CapxulError;
921
+ readonly error: CapxulError$1;
888
922
  };
889
923
  type TransportRuntime = {
890
924
  readonly authBaseUrl: string;
@@ -911,6 +945,7 @@ type TransportRuntime = {
911
945
  */
912
946
  type HttpTransport = {
913
947
  readonly fetch: (path: string, init?: RequestInit) => Promise<Response>;
948
+ readonly ensureRuntime: () => Promise<TransportRuntime>;
914
949
  readonly authBaseUrl: string;
915
950
  readonly convexUrl: string;
916
951
  readonly getState: () => TransportState;
@@ -924,8 +959,11 @@ type HttpTransport = {
924
959
  /**
925
960
  * Build an `HttpTransport` from a `BrowserCapxulConfig`.
926
961
  *
927
- * Throws `Errors.invalidInput("authBaseUrl" | "convexUrl", reason)`
928
- * when the build-time-urls variant is missing required URLs.
962
+ * Throws `CapxulError<"INVALID_INPUT">` with
963
+ * `details.source === "sdk-config"` when local transport config is
964
+ * malformed. Backend bootstrap failures also throw `CapxulError`, but
965
+ * carry `details.source === "backend-bootstrap"` so consumers can
966
+ * distinguish setup mistakes from server-side bootstrap refusals.
929
967
  */
930
968
  declare function makeHttpTransport(config: BrowserCapxulConfig): HttpTransport;
931
969
 
@@ -1055,7 +1093,7 @@ type TokenTransfersClient = {
1055
1093
  * in the create payload rather than nesting the route under the owner.
1056
1094
  */
1057
1095
 
1058
- type VirtualAccountsCreateInput = types.CreateVirtualAccountRequest;
1096
+ type VirtualAccountsCreateInput = CreateVirtualAccountRequest;
1059
1097
  type VirtualAccountsListInput = {
1060
1098
  readonly limit?: number;
1061
1099
  readonly cursor?: string;
@@ -1080,7 +1118,7 @@ type VirtualAccountsClient = {
1080
1118
  * Uses Pattern C (ownerKind in body).
1081
1119
  */
1082
1120
 
1083
- type VirtualCardsCreateInput = types.CreateVirtualCardRequest;
1121
+ type VirtualCardsCreateInput = CreateVirtualCardRequest;
1084
1122
  type VirtualCardsListInput = {
1085
1123
  readonly limit?: number;
1086
1124
  readonly cursor?: string;
@@ -1100,6 +1138,161 @@ type VirtualCardsClient = {
1100
1138
  readonly cancel: (virtualCardId: VirtualCardId) => Promise<CapxulResult<VirtualCard, MutateCodes>>;
1101
1139
  };
1102
1140
 
1141
+ /**
1142
+ * Unified error type used across the entire stack: backend, SDK, and frontend.
1143
+ * One class, one set of codes, one language.
1144
+ *
1145
+ * Backend throws CapxulError → withErrorBoundary serializes to ConvexError →
1146
+ * SDK deserializes back to CapxulError → frontend routes on err.code.
1147
+ */
1148
+ 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";
1149
+ declare class CapxulError extends Error {
1150
+ readonly code: CapxulErrorCode;
1151
+ readonly details?: Record<string, unknown>;
1152
+ readonly correlationId?: string;
1153
+ readonly layer?: string;
1154
+ constructor(code: CapxulErrorCode, message: string, options?: {
1155
+ cause?: unknown;
1156
+ details?: Record<string, unknown>;
1157
+ correlationId?: string;
1158
+ layer?: string;
1159
+ });
1160
+ }
1161
+
1162
+ type AuthBootstrapFlowError = CapxulError$1 | CapxulError;
1163
+ type AuthBootstrapFlowContext = {
1164
+ readonly email: Email | null;
1165
+ readonly code: string | null;
1166
+ readonly username: Username | null;
1167
+ readonly signerProvider: LocalPrivateKeySignerProvider | null;
1168
+ readonly bootstrapToken: AuthBootstrapToken | null;
1169
+ readonly bootstrapReason: AuthBootstrapReason | null;
1170
+ readonly session: Session | null;
1171
+ readonly account: Account | null;
1172
+ readonly safe: Safe | null;
1173
+ readonly error: AuthBootstrapFlowError | null;
1174
+ };
1175
+ type AuthBootstrapFlowEvent = {
1176
+ readonly type: "ENTER_EMAIL";
1177
+ readonly email: Email;
1178
+ } | {
1179
+ readonly type: "REQUEST_OTP";
1180
+ } | {
1181
+ readonly type: "ENTER_OTP";
1182
+ readonly code: string;
1183
+ } | {
1184
+ readonly type: "VERIFY_OTP";
1185
+ } | {
1186
+ readonly type: "ENTER_USERNAME";
1187
+ readonly username: Username;
1188
+ } | {
1189
+ readonly type: "ENTER_SIGNER_PROVIDER";
1190
+ readonly signerProvider: LocalPrivateKeySignerProvider;
1191
+ } | {
1192
+ readonly type: "COMPLETE_BOOTSTRAP";
1193
+ } | {
1194
+ readonly type: "BACK";
1195
+ } | {
1196
+ readonly type: "RESET";
1197
+ } | {
1198
+ readonly type: "SIGN_OUT";
1199
+ };
1200
+ declare function createAuthBootstrapFlowMachine(client: CapxulClient): xstate.StateMachine<AuthBootstrapFlowContext, {
1201
+ readonly type: "ENTER_EMAIL";
1202
+ readonly email: Email;
1203
+ } | {
1204
+ readonly type: "REQUEST_OTP";
1205
+ } | {
1206
+ readonly type: "ENTER_OTP";
1207
+ readonly code: string;
1208
+ } | {
1209
+ readonly type: "VERIFY_OTP";
1210
+ } | {
1211
+ readonly type: "ENTER_USERNAME";
1212
+ readonly username: Username;
1213
+ } | {
1214
+ readonly type: "ENTER_SIGNER_PROVIDER";
1215
+ readonly signerProvider: LocalPrivateKeySignerProvider;
1216
+ } | {
1217
+ readonly type: "COMPLETE_BOOTSTRAP";
1218
+ } | {
1219
+ readonly type: "BACK";
1220
+ } | {
1221
+ readonly type: "RESET";
1222
+ } | {
1223
+ readonly type: "SIGN_OUT";
1224
+ }, {
1225
+ [x: string]: xstate.ActorRefFromLogic<xstate.PromiseActorLogic<void, void, xstate.EventObject>> | xstate.ActorRefFromLogic<xstate.PromiseActorLogic<void, {
1226
+ email: Email;
1227
+ }, xstate.EventObject>> | xstate.ActorRefFromLogic<xstate.PromiseActorLogic<VerifyOtpResult, {
1228
+ email: Email;
1229
+ code: string;
1230
+ }, xstate.EventObject>> | xstate.ActorRefFromLogic<xstate.PromiseActorLogic<CompleteBootstrapResult, {
1231
+ bootstrapToken: AuthBootstrapToken;
1232
+ username: Username;
1233
+ signerProvider: LocalPrivateKeySignerProvider;
1234
+ }, xstate.EventObject>> | undefined;
1235
+ }, {
1236
+ src: "sendOtp";
1237
+ logic: xstate.PromiseActorLogic<void, {
1238
+ email: Email;
1239
+ }, xstate.EventObject>;
1240
+ id: string | undefined;
1241
+ } | {
1242
+ src: "verifyOtp";
1243
+ logic: xstate.PromiseActorLogic<VerifyOtpResult, {
1244
+ email: Email;
1245
+ code: string;
1246
+ }, xstate.EventObject>;
1247
+ id: string | undefined;
1248
+ } | {
1249
+ src: "signOut";
1250
+ logic: xstate.PromiseActorLogic<void, void, xstate.EventObject>;
1251
+ id: string | undefined;
1252
+ } | {
1253
+ src: "completeBootstrap";
1254
+ logic: xstate.PromiseActorLogic<CompleteBootstrapResult, {
1255
+ bootstrapToken: AuthBootstrapToken;
1256
+ username: Username;
1257
+ signerProvider: LocalPrivateKeySignerProvider;
1258
+ }, xstate.EventObject>;
1259
+ id: string | undefined;
1260
+ }, {
1261
+ type: "trackOtpRequested";
1262
+ params: unknown;
1263
+ } | {
1264
+ type: "trackTimeoutFailed";
1265
+ params: unknown;
1266
+ } | {
1267
+ type: "trackVerified";
1268
+ params: unknown;
1269
+ } | {
1270
+ type: "identifyAndTrack";
1271
+ params: unknown;
1272
+ } | {
1273
+ type: "trackSignedOut";
1274
+ params: unknown;
1275
+ } | {
1276
+ type: "trackFailed";
1277
+ params: unknown;
1278
+ } | {
1279
+ type: "trackBootstrapRequired";
1280
+ params: unknown;
1281
+ }, 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, {
1282
+ id: "authBootstrap";
1283
+ states: {
1284
+ readonly email: {};
1285
+ readonly sending_otp: {};
1286
+ readonly otp_requested: {};
1287
+ readonly verifying_otp: {};
1288
+ readonly bootstrap_required: {};
1289
+ readonly completing_bootstrap: {};
1290
+ readonly authenticated: {};
1291
+ readonly signing_out: {};
1292
+ readonly error: {};
1293
+ };
1294
+ }>;
1295
+
1103
1296
  /**
1104
1297
  * Root `@capxul/sdk` client factory.
1105
1298
  *
@@ -1227,6 +1420,7 @@ type CapxulConfig = {
1227
1420
  */
1228
1421
  type CapxulFlowFactories = {
1229
1422
  readonly auth: () => AnyStateMachine;
1423
+ readonly authBootstrap: () => ReturnType<typeof createAuthBootstrapFlowMachine>;
1230
1424
  readonly onboarding: () => AnyStateMachine;
1231
1425
  readonly provisioning: () => AnyStateMachine;
1232
1426
  };
@@ -1289,4 +1483,4 @@ type CapxulClient = {
1289
1483
  */
1290
1484
  declare function createCapxulClient(config?: CapxulConfig): CapxulClient;
1291
1485
 
1292
- 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 };
1486
+ 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 };