@capxul/sdk 0.2.0-alpha.3 → 0.2.0-alpha.4

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,8 @@
1
1
  import { Account as Account$1 } from 'viem';
2
- import * as xstate from 'xstate';
3
2
  import { AnyStateMachine } from 'xstate';
4
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, 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';
4
+ import { d as CapxulResult, C as CapxulError } from './errors-rqxuUhQP.cjs';
5
+ 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-HlwCIjgQ.cjs';
7
6
 
8
7
  /**
9
8
  * Accounts domain — individual user accounts per sdk-surface.md §1a.
@@ -184,13 +183,6 @@ type AuthSessionStore = {
184
183
  set(session: Session): void;
185
184
  clear(): void;
186
185
  };
187
- type AuthSendOtpInput = {
188
- readonly email: string;
189
- };
190
- type AuthVerifyOtpInput = {
191
- readonly email: string;
192
- readonly otp: string;
193
- };
194
186
  type AuthBootstrapToken = string & {
195
187
  readonly __capxulAuthBootstrapTokenBrand: "AuthBootstrapToken";
196
188
  };
@@ -222,10 +214,6 @@ type CompleteBootstrapResult = {
222
214
  readonly username: Username;
223
215
  readonly safe: Safe;
224
216
  };
225
- type AuthServiceTokenMintInput = {
226
- readonly apiKey: string;
227
- readonly audience?: string;
228
- };
229
217
  /**
230
218
  * Options bag for auth methods that perform outbound `fetch` work.
231
219
  *
@@ -239,26 +227,37 @@ type AuthServiceTokenMintInput = {
239
227
  type AuthMethodOptions = {
240
228
  readonly signal?: AbortSignal;
241
229
  };
242
- type ServiceToken = {
243
- readonly token: string;
244
- readonly expiresAt: TimestampIso;
245
- };
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";
249
- type GetSessionCodes = "NETWORK_ERROR";
250
- type SignOutCodes = "NOT_AUTHENTICATED" | "NETWORK_ERROR";
251
- type ServiceTokenMintCodes = "API_KEY_INVALID" | "API_KEY_EXPIRED" | "INVALID_INPUT" | "RATE_LIMITED" | "NETWORK_ERROR";
252
- type AuthClient = {
253
- readonly sendOtp: (input: AuthSendOtpInput, options?: AuthMethodOptions) => Promise<CapxulResult<void, SendOtpCodes>>;
254
- readonly verifyOtp: (input: AuthVerifyOtpInput, options?: AuthMethodOptions) => Promise<CapxulResult<VerifyOtpResult, VerifyOtpCodes>>;
255
- readonly completeBootstrap: (input: CompleteBootstrapInput) => Promise<CapxulResult<CompleteBootstrapResult, CompleteBootstrapCodes>>;
256
- readonly getSession: () => Promise<CapxulResult<Session | null, GetSessionCodes>>;
257
- readonly signOut: () => Promise<CapxulResult<void, SignOutCodes>>;
258
- readonly serviceTokenMint: (input: AuthServiceTokenMintInput) => Promise<CapxulResult<ServiceToken, ServiceTokenMintCodes>>;
259
- /** Internal bridge for flow hooks that need the authenticated Convex data client. */
260
- readonly getDataClient: () => CapxulDataClient | null;
261
- };
230
+
231
+ /**
232
+ * AuthService — unified promise-based auth surface.
233
+ *
234
+ * Wraps the imperative `AuthClient` tuple API with a class-based,
235
+ * promise-based interface. `signOut` preserves the data-client
236
+ * reference so provider-owned singletons survive sign-in/sign-out
237
+ * cycles.
238
+ */
239
+
240
+ declare class AuthService {
241
+ private authClient;
242
+ private sessionStore;
243
+ private config;
244
+ constructor(config?: CapxulConfig);
245
+ sendOtp(email: string, options?: AuthMethodOptions): Promise<void>;
246
+ verifyOtp(email: string, otp: string, options?: AuthMethodOptions): Promise<VerifyOtpResult>;
247
+ completeBootstrap(params: CompleteBootstrapInput, signer?: Account$1): Promise<CompleteBootstrapResult>;
248
+ /**
249
+ * Clears the persisted session and, when a transport was pre-injected,
250
+ * drops the cached auth header.
251
+ *
252
+ * **Transport safety note:** `clearAuth()` is only invoked when
253
+ * `config._transport` was supplied at construction (e.g. by the React
254
+ * provider). If `AuthService` is instantiated directly in a Node/CLI
255
+ * context without an injected transport, the transport-side auth cache
256
+ * is the caller's responsibility.
257
+ */
258
+ signOut(): Promise<void>;
259
+ getSession(): Promise<Session | null>;
260
+ }
262
261
 
263
262
  /**
264
263
  * Documents domain — unified artifact primitive per sdk-surface.md §1a
@@ -294,9 +293,9 @@ type OrgDocumentsCancelInput = {
294
293
  readonly documentId: DocumentId;
295
294
  };
296
295
  type CreateCodes$7 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "INVALID_INPUT" | "IDEMPOTENCY_CONFLICT" | "RATE_LIMITED" | "NETWORK_ERROR";
297
- type RetrieveCodes$c = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND";
296
+ type RetrieveCodes$c = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND" | "INVALID_INPUT";
298
297
  type ListCodes$9 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "INVALID_INPUT";
299
- type CancelCodes$1 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND" | "OPERATION_CANCELED";
298
+ type CancelCodes$1 = "NOT_AUTHENTICATED" | "PERMISSION_DENIED" | "NOT_FOUND" | "INVALID_INPUT" | "OPERATION_CANCELED";
300
299
  type DocumentsClient = {
301
300
  readonly create: (input: DocumentsCreateInput) => Promise<CapxulResult<Document, CreateCodes$7>>;
302
301
  readonly retrieve: (documentId: DocumentId) => Promise<CapxulResult<Document, RetrieveCodes$c>>;
@@ -922,7 +921,7 @@ type TransportState = {
922
921
  readonly runtime: TransportRuntime;
923
922
  } | {
924
923
  readonly status: "error";
925
- readonly error: CapxulError$1;
924
+ readonly error: CapxulError;
926
925
  };
927
926
  type TransportRuntime = {
928
927
  readonly authBaseUrl: string;
@@ -1149,152 +1148,6 @@ type VirtualCardsClient = {
1149
1148
  readonly cancel: (virtualCardId: VirtualCardId) => Promise<CapxulResult<VirtualCard, MutateCodes>>;
1150
1149
  };
1151
1150
 
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
-
1298
1151
  /**
1299
1152
  * Root `@capxul/sdk` client factory.
1300
1153
  *
@@ -1401,7 +1254,7 @@ type CapxulConfig = {
1401
1254
  readonly _transport?: HttpTransport;
1402
1255
  };
1403
1256
  /**
1404
- * Per-call factories for the three Stack-1 XState v5 flow machines.
1257
+ * Per-call factories for XState v5 flow machines.
1405
1258
  *
1406
1259
  * Each factory returns a fresh machine instance bound to this
1407
1260
  * `CapxulClient`. The consumer is responsible for creating a single
@@ -1417,8 +1270,6 @@ type CapxulConfig = {
1417
1270
  * `./flows/*` when they need them.
1418
1271
  */
1419
1272
  type CapxulFlowFactories = {
1420
- readonly auth: () => AnyStateMachine;
1421
- readonly authBootstrap: () => ReturnType<typeof createAuthBootstrapFlowMachine>;
1422
1273
  readonly onboarding: () => AnyStateMachine;
1423
1274
  readonly provisioning: () => AnyStateMachine;
1424
1275
  };
@@ -1439,7 +1290,7 @@ type CapxulClient = {
1439
1290
  * `createCapxulClient()` call. See Codex P1 finding on PR #406.
1440
1291
  */
1441
1292
  readonly id: string;
1442
- readonly auth: AuthClient;
1293
+ readonly auth: AuthService;
1443
1294
  readonly me: MeClient;
1444
1295
  readonly accounts: AccountsClient;
1445
1296
  readonly organizations: OrganizationsClient;
@@ -1474,11 +1325,11 @@ type CapxulClient = {
1474
1325
  * Two-pass construction: the per-domain clients (`auth`, `me`, …) are
1475
1326
  * built first, then `flows` is assigned with factories that close over
1476
1327
  * the fully-built `client` so the spawned XState machines can call
1477
- * back into `client.auth.sendOtp`, `client.accounts.provisionPersonal`,
1478
- * etc. The intermediate `clientWithoutFlows` value is typed without
1328
+ * back into `client.accounts.provisionPersonal`, etc. The intermediate
1329
+ * `clientWithoutFlows` value is typed without
1479
1330
  * `flows`; `Object.assign` mutates a single `flows` field on it before
1480
1331
  * the returned `CapxulClient` cast — minimal and contained.
1481
1332
  */
1482
1333
  declare function createCapxulClient(config?: CapxulConfig): CapxulClient;
1483
1334
 
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 };
1335
+ export { type AccountProvisionPersonalInput as A, type BrowserCapxulConfig as B, type CapxulClient as C, type DocumentsClient as D, type ExternalAccountsClient as E, type TokenTransfersListPage as F, type TokenTransfersRetrieveInput as G, type HttpTransport as H, type TransfersClient as I, type TransportRuntime as J, type TransportState as K, type LocalPrivateKeySignerProvider as L, type MeClient as M, type VirtualAccountsClient as N, type OperationsClient as O, type PaymentsClient as P, type VirtualCardsClient as Q, type WebhookEndpointsClient as R, type Session as S, type TokenTransfer as T, type WebhookEventsClient as U, type VerifyOtpResult as V, type WebhookEndpointCreateResult as W, type WithdrawalsClient as X, createCapxulClient as Y, makeHttpTransport as Z, toTokenTransferId as _, type AccountsClient as a, type ApiKeyCreateResult as b, type ApiKeysClient as c, type AuthBootstrapReason as d, type AuthBootstrapToken as e, AuthService as f, type AuthSessionStore as g, type CapxulAuthConfig as h, type CapxulConfig as i, type CapxulDataClient as j, type CapxulFlowFactories as k, type CapxulSigningConfig as l, type CompleteBootstrapInput as m, type CompleteBootstrapResult as n, type OrgDocumentsClient as o, type OrgMembersClient as p, type OrgPaymentsClient as q, type OrgSafesClient as r, type OrgTransfersClient as s, type OrgTreasuryClient as t, type OrgWithdrawalsClient as u, type OrganizationsClient as v, type SubAccountsClient as w, type TokenTransferId as x, type TokenTransfersClient as y, type TokenTransfersListInput as z };