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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,36 +1,14 @@
1
- import { S as Session, C as CapxulClient, A as AccountProvisionPersonalInput } from './client-D-0KTn8D.cjs';
2
- export { a as AccountsClient, b as ApiKeyCreateResult, c as ApiKeysClient, d as AuthClient, e as AuthSessionStore, B as BrowserCapxulConfig, f as CapxulAuthConfig, g as CapxulConfig, h as CapxulDataClient, i as CapxulFlowFactories, j as CapxulSigningConfig, D as DocumentsClient, E as ExternalAccountsClient, H as HttpTransport, L as LocalPrivateKeySignerProvider, M as MeClient, O as OperationsClient, k as OrgDocumentsClient, l as OrgPaymentsClient, m as OrgSafesClient, n as OrgTransfersClient, o as OrgTreasuryClient, p as OrgWithdrawalsClient, q as OrganizationsClient, P as PaymentsClient, r as SubAccountsClient, T as TransfersClient, s as TransportRuntime, t as TransportState, V as VirtualAccountsClient, u as VirtualCardsClient, W as WebhookEndpointCreateResult, v as WebhookEndpointsClient, w as WebhookEventsClient, x as WithdrawalsClient, y as createCapxulClient, z as makeHttpTransport } from './client-D-0KTn8D.cjs';
1
+ import { S as Session, C as CapxulError$1, a as CapxulClient, A as AccountProvisionPersonalInput } from './client-rd1rVa5g.cjs';
2
+ export { b as AccountsClient, c as ApiKeyCreateResult, d as ApiKeysClient, e as AuthBootstrapFlowContext, f as AuthBootstrapFlowError, g as AuthBootstrapFlowEvent, h as AuthBootstrapReason, i as AuthBootstrapToken, j as AuthClient, k as AuthSessionStore, B as BrowserCapxulConfig, l as CapxulAuthConfig, m as CapxulConfig, n as CapxulDataClient, o as CapxulFlowFactories, p as CapxulSigningConfig, q as CompleteBootstrapInput, r as CompleteBootstrapResult, D as DocumentsClient, E as ExternalAccountsClient, H as HttpTransport, L as LocalPrivateKeySignerProvider, M as MeClient, O as OperationsClient, s as OrgDocumentsClient, t as OrgPaymentsClient, u as OrgSafesClient, v as OrgTransfersClient, w as OrgTreasuryClient, x as OrgWithdrawalsClient, y as OrganizationsClient, P as PaymentsClient, z as SubAccountsClient, T as TokenTransfer, F as TokenTransferId, G as TokenTransfersClient, I as TokenTransfersListInput, J as TokenTransfersListPage, K as TokenTransfersRetrieveInput, N as TransfersClient, Q as TransportRuntime, R as TransportState, V as VerifyOtpResult, U as VirtualAccountsClient, W as VirtualCardsClient, X as WebhookEndpointCreateResult, Y as WebhookEndpointsClient, Z as WebhookEventsClient, _ as WithdrawalsClient, $ as createAuthBootstrapFlowMachine, a0 as createCapxulClient, a1 as makeHttpTransport, a2 as toTokenTransferId } from './client-rd1rVa5g.cjs';
3
3
  import * as xstate from 'xstate';
4
4
  import { E as Email, U as Username, O as OperationId, N as NextAction } from './next-action-DkrwXYay.cjs';
5
5
  export { A as AccountId, a as ApiKeyId, B as BalanceLedgerEntryId, C as CorrelationId, D as DocumentId, b as ExternalAccountId, K as KybProfileId, c as KycProfileId, M as MemberId, d as OrganizationId, P as PaymentId, e as PhoneNumber, S as SafeId, f as SubAccountId, T as TransactionIntentId, g as TransferId, h as TreasuryId, V as VirtualAccountId, i as VirtualCardId, W as WebhookEndpointId, j as WebhookEventId, k as WithdrawalId, t as toAccountId, l as toApiKeyId, m as toBalanceLedgerEntryId, n as toDocumentId, o as toEmail, p as toExternalAccountId, q as toKybProfileId, r as toKycProfileId, s as toMemberId, u as toOperationId, v as toOrganizationId, w as toPaymentId, x as toPhoneNumber, y as toSafeId, z as toSubAccountId, F as toTransferId, G as toTreasuryId, H as toUsername, I as toVirtualAccountId, J as toVirtualCardId, L as toWebhookEndpointId, Q as toWebhookEventId, R as toWithdrawalId } from './next-action-DkrwXYay.cjs';
6
- import { C as CapxulError$1, a as CapxulErrorCode$1 } from './errors-GgKrSUKp.cjs';
6
+ import { C as CapxulError, a as CapxulErrorCode } from './errors-GgKrSUKp.cjs';
7
7
  export { b as CapxulErrorDetails, c as CapxulErrorEnvelope, d as CapxulResult } from './errors-GgKrSUKp.cjs';
8
- import { A as Account } from './types-DVWojoy4.cjs';
9
- export { a as AccountLookupResult, b as ApiKey, c as ApiKeyEnvironment, d as ApiKeyType, B as BalanceLedgerEntry, e as BankStatementDocument, C as CreatePaymentResult, f as CreateTransferResult, g as CreateWithdrawalResult, D as Document, E as ExternalAccount, h as ExternalAccountKind, I as InvoiceDocument, K as KybProfile, i as KycProfile, j as KycUploadDocument, L as List, M as Member, k as Money, O as Operation, l as OperationStatus, m as OperationSummary, n as Organization, P as PageInfo, o as Payment, p as PaymentParty, q as PaymentStatus, r as PayrollRunDocument, s as PayrollScheduleDocument, R as ReceiptDocument, S as Safe, t as Scope, u as Settlement, v as SubAccount, w as SubAccountOwnerKind, T as TaxFormDocument, x as TimestampIso, y as Transfer, z as TransferCustody, F as TransferEndpoint, G as TransferFx, H as TransferStatus, J as Treasury, U as UserIdentifier, V as VirtualAccount, N as VirtualAccountOwnerKind, Q as VirtualCard, W as VirtualCardLimits, X as VirtualCardOwnerKind, Y as WebhookEndpoint, Z as WebhookEvent, _ as Withdrawal, $ as WithdrawalStatus } from './types-DVWojoy4.cjs';
8
+ import { A as Account } from './types-hfcOE7Oi.cjs';
9
+ export { a as AccountLookupResult, b as ApiKey, c as ApiKeyEnvironment, d as ApiKeyType, B as BalanceLedgerEntry, e as BankStatementDocument, C as CreatePaymentResult, f as CreateTransferResult, g as CreateWithdrawalResult, D as Document, E as ExternalAccount, h as ExternalAccountKind, I as InvoiceDocument, K as KybProfile, i as KycProfile, j as KycUploadDocument, L as List, M as Member, k as Money, O as Operation, l as OperationStatus, m as OperationSummary, n as Organization, P as PageInfo, o as Payment, p as PaymentParty, q as PaymentStatus, r as PayrollRunDocument, s as PayrollScheduleDocument, R as ReceiptDocument, S as Safe, t as Scope, u as Settlement, v as SubAccount, w as SubAccountOwnerKind, T as TaxFormDocument, x as TimestampIso, y as Transfer, z as TransferCustody, F as TransferEndpoint, G as TransferFx, H as TransferStatus, J as Treasury, U as UserIdentifier, V as VirtualAccount, N as VirtualAccountOwnerKind, Q as VirtualCard, W as VirtualCardLimits, X as VirtualCardOwnerKind, Y as WebhookEndpoint, Z as WebhookEvent, _ as Withdrawal, $ as WithdrawalStatus } from './types-hfcOE7Oi.cjs';
10
10
  import { Account as Account$1 } from 'viem';
11
11
  export { WebhookVerificationOptions, WebhookVerificationResult, verifyWebhook } from './webhooks.cjs';
12
- import '@repo/api-contract/gen/types';
13
-
14
- /**
15
- * Unified error type used across the entire stack: backend, SDK, and frontend.
16
- * One class, one set of codes, one language.
17
- *
18
- * Backend throws CapxulError → withErrorBoundary serializes to ConvexError →
19
- * SDK deserializes back to CapxulError → frontend routes on err.code.
20
- */
21
- 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";
22
- declare class CapxulError extends Error {
23
- readonly code: CapxulErrorCode;
24
- readonly details?: Record<string, unknown>;
25
- readonly correlationId?: string;
26
- readonly layer?: string;
27
- constructor(code: CapxulErrorCode, message: string, options?: {
28
- cause?: unknown;
29
- details?: Record<string, unknown>;
30
- correlationId?: string;
31
- layer?: string;
32
- });
33
- }
34
12
 
35
13
  /**
36
14
  * Auth flow errors may originate from two CapxulError surfaces:
@@ -43,7 +21,7 @@ declare class CapxulError extends Error {
43
21
  * union keeps either origin assignable to `context.error` without an
44
22
  * `as` cast at the call site.
45
23
  */
46
- type AuthFlowError = CapxulError$1 | CapxulError;
24
+ type AuthFlowError = CapxulError | CapxulError$1;
47
25
  type AuthFlowContext = {
48
26
  readonly email: Email | null;
49
27
  readonly session: Session | null;
@@ -119,7 +97,7 @@ declare function createAuthFlowMachine(client: CapxulClient): xstate.StateMachin
119
97
  } | {
120
98
  type: "trackSignedOut";
121
99
  params: unknown;
122
- }, never, never, "error" | "idle" | "sending_otp" | "otp_requested" | "verifying" | "authenticated" | "signing_out", string, xstate.NonReducibleUnknown, xstate.NonReducibleUnknown, xstate.EventObject, xstate.MetaObject, {
100
+ }, never, never, "idle" | "authenticated" | "error" | "sending_otp" | "otp_requested" | "verifying" | "signing_out", string, xstate.NonReducibleUnknown, xstate.NonReducibleUnknown, xstate.EventObject, xstate.MetaObject, {
123
101
  id: "auth";
124
102
  states: {
125
103
  readonly idle: {};
@@ -142,7 +120,7 @@ declare function createAuthFlowMachine(client: CapxulClient): xstate.StateMachin
142
120
  *
143
121
  * Both share `.code`, `.message`, `.details`, and extend `Error`.
144
122
  */
145
- type ProvisioningFlowError = CapxulError$1 | CapxulError;
123
+ type ProvisioningFlowError = CapxulError | CapxulError$1;
146
124
  type ProvisioningFlowContext = {
147
125
  readonly input: AccountProvisionPersonalInput | null;
148
126
  readonly account: Account | null;
@@ -219,7 +197,7 @@ declare function createProvisioningMachine(client: CapxulClient): xstate.StateMa
219
197
  }, {
220
198
  type: "hasInput";
221
199
  params: unknown;
222
- }, never, "done" | "error" | "idle" | "starting" | "running", string, {
200
+ }, never, "idle" | "error" | "done" | "starting" | "running", string, {
223
201
  readonly input: AccountProvisionPersonalInput;
224
202
  }, {
225
203
  readonly account: Account;
@@ -249,7 +227,7 @@ declare function createProvisioningMachine(client: CapxulClient): xstate.StateMa
249
227
  *
250
228
  * Both share `.code`, `.message`, `.details`, and extend `Error`.
251
229
  */
252
- type OnboardingFlowError = CapxulError$1 | CapxulError;
230
+ type OnboardingFlowError = CapxulError | CapxulError$1;
253
231
  /** Subjects supported by the onboarding flow. */
254
232
  type OnboardingSubjectKind = "account" | "organization";
255
233
  /**
@@ -327,7 +305,7 @@ declare function createOnboardingFlowMachine(client: CapxulClient): xstate.State
327
305
  }, {
328
306
  type: "hasInput";
329
307
  params: unknown;
330
- }, never, "done" | "error" | "idle" | "starting" | "running", string, {
308
+ }, never, "idle" | "error" | "done" | "starting" | "running", string, {
331
309
  readonly input: AccountProvisionPersonalInput;
332
310
  }, {
333
311
  readonly account: Account;
@@ -369,7 +347,7 @@ declare function createOnboardingFlowMachine(client: CapxulClient): xstate.State
369
347
  }, {
370
348
  type: "hasInput";
371
349
  params: unknown;
372
- }, never, "done" | "error" | "idle" | "starting" | "running", string, {
350
+ }, never, "idle" | "error" | "done" | "starting" | "running", string, {
373
351
  readonly input: AccountProvisionPersonalInput;
374
352
  }, {
375
353
  readonly account: Account;
@@ -439,7 +417,7 @@ declare function createOnboardingFlowMachine(client: CapxulClient): xstate.State
439
417
  } | {
440
418
  type: "childReportedError";
441
419
  params: unknown;
442
- }, never, "error" | "provisioning" | "profile" | "complete" | "action_required", string, xstate.NonReducibleUnknown, xstate.NonReducibleUnknown, xstate.EventObject, xstate.MetaObject, {
420
+ }, never, "action_required" | "provisioning" | "error" | "profile" | "complete", string, xstate.NonReducibleUnknown, xstate.NonReducibleUnknown, xstate.EventObject, xstate.MetaObject, {
443
421
  id: "onboarding";
444
422
  states: {
445
423
  readonly profile: {};
@@ -462,8 +440,8 @@ declare function createOnboardingFlowMachine(client: CapxulClient): xstate.State
462
440
  * No `default:` arm needed — the compile-time exhaustiveness check is
463
441
  * the contract.
464
442
  */
465
- declare function matchError<Codes extends CapxulErrorCode$1, R>(err: CapxulError$1<Codes>, handlers: {
466
- [K in Codes]: (err: CapxulError$1<K>) => R;
443
+ declare function matchError<Codes extends CapxulErrorCode, R>(err: CapxulError<Codes>, handlers: {
444
+ [K in Codes]: (err: CapxulError<K>) => R;
467
445
  }): R;
468
446
  /**
469
447
  * Exhaustive resource-status dispatch per CANON.md §4.44.
@@ -500,6 +478,13 @@ declare function matchAction<A extends NextAction, R>(action: A, handlers: {
500
478
  }>) => R;
501
479
  }): R;
502
480
 
481
+ /**
482
+ * Go-style error handling for async calls.
483
+ * Returns [error, null] on failure, [null, value] on success.
484
+ * Pure utility — no side effects, no reporter.
485
+ */
486
+ declare function tryCatch<T>(promise: Promise<T>): Promise<[Error, null] | [null, T]>;
487
+
503
488
  /**
504
489
  * Convenience constructor for a viem `Account` backed by a raw private
505
490
  * key — the CLI / server-side signer per CANON.md §4.28.
@@ -512,4 +497,4 @@ declare function matchAction<A extends NextAction, R>(action: A, handlers: {
512
497
  */
513
498
  declare function createLocalSigner(privateKey: `0x${string}`): Account$1;
514
499
 
515
- export { Account, AccountProvisionPersonalInput, type AuthFlowContext, type AuthFlowError, type AuthFlowEvent, CapxulClient, CapxulError$1 as CapxulError, CapxulErrorCode$1 as CapxulErrorCode, Email, NextAction, type OnboardingFlowContext, type OnboardingFlowError, type OnboardingFlowEvent, type OnboardingProfileInput, type OnboardingSubjectKind, OperationId, type ProvisioningFlowContext, type ProvisioningFlowError, type ProvisioningFlowEvent, type ProvisioningFlowInput, type ProvisioningFlowOutput, Session, Username, createAuthFlowMachine, createLocalSigner, createOnboardingFlowMachine, createProvisioningMachine as createProvisioningFlowMachine, matchAction, matchError, matchStatus };
500
+ export { Account, AccountProvisionPersonalInput, type AuthFlowContext, type AuthFlowError, type AuthFlowEvent, CapxulClient, CapxulError, CapxulErrorCode, Email, NextAction, type OnboardingFlowContext, type OnboardingFlowError, type OnboardingFlowEvent, type OnboardingProfileInput, type OnboardingSubjectKind, OperationId, type ProvisioningFlowContext, type ProvisioningFlowError, type ProvisioningFlowEvent, type ProvisioningFlowInput, type ProvisioningFlowOutput, Session, Username, createAuthFlowMachine, createLocalSigner, createOnboardingFlowMachine, createProvisioningMachine as createProvisioningFlowMachine, matchAction, matchError, matchStatus, tryCatch };
package/dist/index.d.ts CHANGED
@@ -1,36 +1,14 @@
1
- import { S as Session, C as CapxulClient, A as AccountProvisionPersonalInput } from './client-CweJSkaY.js';
2
- export { a as AccountsClient, b as ApiKeyCreateResult, c as ApiKeysClient, d as AuthClient, e as AuthSessionStore, B as BrowserCapxulConfig, f as CapxulAuthConfig, g as CapxulConfig, h as CapxulDataClient, i as CapxulFlowFactories, j as CapxulSigningConfig, D as DocumentsClient, E as ExternalAccountsClient, H as HttpTransport, L as LocalPrivateKeySignerProvider, M as MeClient, O as OperationsClient, k as OrgDocumentsClient, l as OrgPaymentsClient, m as OrgSafesClient, n as OrgTransfersClient, o as OrgTreasuryClient, p as OrgWithdrawalsClient, q as OrganizationsClient, P as PaymentsClient, r as SubAccountsClient, T as TransfersClient, s as TransportRuntime, t as TransportState, V as VirtualAccountsClient, u as VirtualCardsClient, W as WebhookEndpointCreateResult, v as WebhookEndpointsClient, w as WebhookEventsClient, x as WithdrawalsClient, y as createCapxulClient, z as makeHttpTransport } from './client-CweJSkaY.js';
1
+ import { S as Session, C as CapxulError$1, a as CapxulClient, A as AccountProvisionPersonalInput } from './client-64FvYfKr.js';
2
+ export { b as AccountsClient, c as ApiKeyCreateResult, d as ApiKeysClient, e as AuthBootstrapFlowContext, f as AuthBootstrapFlowError, g as AuthBootstrapFlowEvent, h as AuthBootstrapReason, i as AuthBootstrapToken, j as AuthClient, k as AuthSessionStore, B as BrowserCapxulConfig, l as CapxulAuthConfig, m as CapxulConfig, n as CapxulDataClient, o as CapxulFlowFactories, p as CapxulSigningConfig, q as CompleteBootstrapInput, r as CompleteBootstrapResult, D as DocumentsClient, E as ExternalAccountsClient, H as HttpTransport, L as LocalPrivateKeySignerProvider, M as MeClient, O as OperationsClient, s as OrgDocumentsClient, t as OrgPaymentsClient, u as OrgSafesClient, v as OrgTransfersClient, w as OrgTreasuryClient, x as OrgWithdrawalsClient, y as OrganizationsClient, P as PaymentsClient, z as SubAccountsClient, T as TokenTransfer, F as TokenTransferId, G as TokenTransfersClient, I as TokenTransfersListInput, J as TokenTransfersListPage, K as TokenTransfersRetrieveInput, N as TransfersClient, Q as TransportRuntime, R as TransportState, V as VerifyOtpResult, U as VirtualAccountsClient, W as VirtualCardsClient, X as WebhookEndpointCreateResult, Y as WebhookEndpointsClient, Z as WebhookEventsClient, _ as WithdrawalsClient, $ as createAuthBootstrapFlowMachine, a0 as createCapxulClient, a1 as makeHttpTransport, a2 as toTokenTransferId } from './client-64FvYfKr.js';
3
3
  import * as xstate from 'xstate';
4
4
  import { E as Email, U as Username, O as OperationId, N as NextAction } from './next-action-DkrwXYay.js';
5
5
  export { A as AccountId, a as ApiKeyId, B as BalanceLedgerEntryId, C as CorrelationId, D as DocumentId, b as ExternalAccountId, K as KybProfileId, c as KycProfileId, M as MemberId, d as OrganizationId, P as PaymentId, e as PhoneNumber, S as SafeId, f as SubAccountId, T as TransactionIntentId, g as TransferId, h as TreasuryId, V as VirtualAccountId, i as VirtualCardId, W as WebhookEndpointId, j as WebhookEventId, k as WithdrawalId, t as toAccountId, l as toApiKeyId, m as toBalanceLedgerEntryId, n as toDocumentId, o as toEmail, p as toExternalAccountId, q as toKybProfileId, r as toKycProfileId, s as toMemberId, u as toOperationId, v as toOrganizationId, w as toPaymentId, x as toPhoneNumber, y as toSafeId, z as toSubAccountId, F as toTransferId, G as toTreasuryId, H as toUsername, I as toVirtualAccountId, J as toVirtualCardId, L as toWebhookEndpointId, Q as toWebhookEventId, R as toWithdrawalId } from './next-action-DkrwXYay.js';
6
- import { C as CapxulError$1, a as CapxulErrorCode$1 } from './errors-QHD5Tlok.js';
6
+ import { C as CapxulError, a as CapxulErrorCode } from './errors-QHD5Tlok.js';
7
7
  export { b as CapxulErrorDetails, c as CapxulErrorEnvelope, d as CapxulResult } from './errors-QHD5Tlok.js';
8
- import { A as Account } from './types-75UokagF.js';
9
- export { a as AccountLookupResult, b as ApiKey, c as ApiKeyEnvironment, d as ApiKeyType, B as BalanceLedgerEntry, e as BankStatementDocument, C as CreatePaymentResult, f as CreateTransferResult, g as CreateWithdrawalResult, D as Document, E as ExternalAccount, h as ExternalAccountKind, I as InvoiceDocument, K as KybProfile, i as KycProfile, j as KycUploadDocument, L as List, M as Member, k as Money, O as Operation, l as OperationStatus, m as OperationSummary, n as Organization, P as PageInfo, o as Payment, p as PaymentParty, q as PaymentStatus, r as PayrollRunDocument, s as PayrollScheduleDocument, R as ReceiptDocument, S as Safe, t as Scope, u as Settlement, v as SubAccount, w as SubAccountOwnerKind, T as TaxFormDocument, x as TimestampIso, y as Transfer, z as TransferCustody, F as TransferEndpoint, G as TransferFx, H as TransferStatus, J as Treasury, U as UserIdentifier, V as VirtualAccount, N as VirtualAccountOwnerKind, Q as VirtualCard, W as VirtualCardLimits, X as VirtualCardOwnerKind, Y as WebhookEndpoint, Z as WebhookEvent, _ as Withdrawal, $ as WithdrawalStatus } from './types-75UokagF.js';
8
+ import { A as Account } from './types-PM4AQRLP.js';
9
+ export { a as AccountLookupResult, b as ApiKey, c as ApiKeyEnvironment, d as ApiKeyType, B as BalanceLedgerEntry, e as BankStatementDocument, C as CreatePaymentResult, f as CreateTransferResult, g as CreateWithdrawalResult, D as Document, E as ExternalAccount, h as ExternalAccountKind, I as InvoiceDocument, K as KybProfile, i as KycProfile, j as KycUploadDocument, L as List, M as Member, k as Money, O as Operation, l as OperationStatus, m as OperationSummary, n as Organization, P as PageInfo, o as Payment, p as PaymentParty, q as PaymentStatus, r as PayrollRunDocument, s as PayrollScheduleDocument, R as ReceiptDocument, S as Safe, t as Scope, u as Settlement, v as SubAccount, w as SubAccountOwnerKind, T as TaxFormDocument, x as TimestampIso, y as Transfer, z as TransferCustody, F as TransferEndpoint, G as TransferFx, H as TransferStatus, J as Treasury, U as UserIdentifier, V as VirtualAccount, N as VirtualAccountOwnerKind, Q as VirtualCard, W as VirtualCardLimits, X as VirtualCardOwnerKind, Y as WebhookEndpoint, Z as WebhookEvent, _ as Withdrawal, $ as WithdrawalStatus } from './types-PM4AQRLP.js';
10
10
  import { Account as Account$1 } from 'viem';
11
11
  export { WebhookVerificationOptions, WebhookVerificationResult, verifyWebhook } from './webhooks.js';
12
- import '@repo/api-contract/gen/types';
13
-
14
- /**
15
- * Unified error type used across the entire stack: backend, SDK, and frontend.
16
- * One class, one set of codes, one language.
17
- *
18
- * Backend throws CapxulError → withErrorBoundary serializes to ConvexError →
19
- * SDK deserializes back to CapxulError → frontend routes on err.code.
20
- */
21
- 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";
22
- declare class CapxulError extends Error {
23
- readonly code: CapxulErrorCode;
24
- readonly details?: Record<string, unknown>;
25
- readonly correlationId?: string;
26
- readonly layer?: string;
27
- constructor(code: CapxulErrorCode, message: string, options?: {
28
- cause?: unknown;
29
- details?: Record<string, unknown>;
30
- correlationId?: string;
31
- layer?: string;
32
- });
33
- }
34
12
 
35
13
  /**
36
14
  * Auth flow errors may originate from two CapxulError surfaces:
@@ -43,7 +21,7 @@ declare class CapxulError extends Error {
43
21
  * union keeps either origin assignable to `context.error` without an
44
22
  * `as` cast at the call site.
45
23
  */
46
- type AuthFlowError = CapxulError$1 | CapxulError;
24
+ type AuthFlowError = CapxulError | CapxulError$1;
47
25
  type AuthFlowContext = {
48
26
  readonly email: Email | null;
49
27
  readonly session: Session | null;
@@ -119,7 +97,7 @@ declare function createAuthFlowMachine(client: CapxulClient): xstate.StateMachin
119
97
  } | {
120
98
  type: "trackSignedOut";
121
99
  params: unknown;
122
- }, never, never, "error" | "idle" | "sending_otp" | "otp_requested" | "verifying" | "authenticated" | "signing_out", string, xstate.NonReducibleUnknown, xstate.NonReducibleUnknown, xstate.EventObject, xstate.MetaObject, {
100
+ }, never, never, "idle" | "authenticated" | "error" | "sending_otp" | "otp_requested" | "verifying" | "signing_out", string, xstate.NonReducibleUnknown, xstate.NonReducibleUnknown, xstate.EventObject, xstate.MetaObject, {
123
101
  id: "auth";
124
102
  states: {
125
103
  readonly idle: {};
@@ -142,7 +120,7 @@ declare function createAuthFlowMachine(client: CapxulClient): xstate.StateMachin
142
120
  *
143
121
  * Both share `.code`, `.message`, `.details`, and extend `Error`.
144
122
  */
145
- type ProvisioningFlowError = CapxulError$1 | CapxulError;
123
+ type ProvisioningFlowError = CapxulError | CapxulError$1;
146
124
  type ProvisioningFlowContext = {
147
125
  readonly input: AccountProvisionPersonalInput | null;
148
126
  readonly account: Account | null;
@@ -219,7 +197,7 @@ declare function createProvisioningMachine(client: CapxulClient): xstate.StateMa
219
197
  }, {
220
198
  type: "hasInput";
221
199
  params: unknown;
222
- }, never, "done" | "error" | "idle" | "starting" | "running", string, {
200
+ }, never, "idle" | "error" | "done" | "starting" | "running", string, {
223
201
  readonly input: AccountProvisionPersonalInput;
224
202
  }, {
225
203
  readonly account: Account;
@@ -249,7 +227,7 @@ declare function createProvisioningMachine(client: CapxulClient): xstate.StateMa
249
227
  *
250
228
  * Both share `.code`, `.message`, `.details`, and extend `Error`.
251
229
  */
252
- type OnboardingFlowError = CapxulError$1 | CapxulError;
230
+ type OnboardingFlowError = CapxulError | CapxulError$1;
253
231
  /** Subjects supported by the onboarding flow. */
254
232
  type OnboardingSubjectKind = "account" | "organization";
255
233
  /**
@@ -327,7 +305,7 @@ declare function createOnboardingFlowMachine(client: CapxulClient): xstate.State
327
305
  }, {
328
306
  type: "hasInput";
329
307
  params: unknown;
330
- }, never, "done" | "error" | "idle" | "starting" | "running", string, {
308
+ }, never, "idle" | "error" | "done" | "starting" | "running", string, {
331
309
  readonly input: AccountProvisionPersonalInput;
332
310
  }, {
333
311
  readonly account: Account;
@@ -369,7 +347,7 @@ declare function createOnboardingFlowMachine(client: CapxulClient): xstate.State
369
347
  }, {
370
348
  type: "hasInput";
371
349
  params: unknown;
372
- }, never, "done" | "error" | "idle" | "starting" | "running", string, {
350
+ }, never, "idle" | "error" | "done" | "starting" | "running", string, {
373
351
  readonly input: AccountProvisionPersonalInput;
374
352
  }, {
375
353
  readonly account: Account;
@@ -439,7 +417,7 @@ declare function createOnboardingFlowMachine(client: CapxulClient): xstate.State
439
417
  } | {
440
418
  type: "childReportedError";
441
419
  params: unknown;
442
- }, never, "error" | "provisioning" | "profile" | "complete" | "action_required", string, xstate.NonReducibleUnknown, xstate.NonReducibleUnknown, xstate.EventObject, xstate.MetaObject, {
420
+ }, never, "action_required" | "provisioning" | "error" | "profile" | "complete", string, xstate.NonReducibleUnknown, xstate.NonReducibleUnknown, xstate.EventObject, xstate.MetaObject, {
443
421
  id: "onboarding";
444
422
  states: {
445
423
  readonly profile: {};
@@ -462,8 +440,8 @@ declare function createOnboardingFlowMachine(client: CapxulClient): xstate.State
462
440
  * No `default:` arm needed — the compile-time exhaustiveness check is
463
441
  * the contract.
464
442
  */
465
- declare function matchError<Codes extends CapxulErrorCode$1, R>(err: CapxulError$1<Codes>, handlers: {
466
- [K in Codes]: (err: CapxulError$1<K>) => R;
443
+ declare function matchError<Codes extends CapxulErrorCode, R>(err: CapxulError<Codes>, handlers: {
444
+ [K in Codes]: (err: CapxulError<K>) => R;
467
445
  }): R;
468
446
  /**
469
447
  * Exhaustive resource-status dispatch per CANON.md §4.44.
@@ -500,6 +478,13 @@ declare function matchAction<A extends NextAction, R>(action: A, handlers: {
500
478
  }>) => R;
501
479
  }): R;
502
480
 
481
+ /**
482
+ * Go-style error handling for async calls.
483
+ * Returns [error, null] on failure, [null, value] on success.
484
+ * Pure utility — no side effects, no reporter.
485
+ */
486
+ declare function tryCatch<T>(promise: Promise<T>): Promise<[Error, null] | [null, T]>;
487
+
503
488
  /**
504
489
  * Convenience constructor for a viem `Account` backed by a raw private
505
490
  * key — the CLI / server-side signer per CANON.md §4.28.
@@ -512,4 +497,4 @@ declare function matchAction<A extends NextAction, R>(action: A, handlers: {
512
497
  */
513
498
  declare function createLocalSigner(privateKey: `0x${string}`): Account$1;
514
499
 
515
- export { Account, AccountProvisionPersonalInput, type AuthFlowContext, type AuthFlowError, type AuthFlowEvent, CapxulClient, CapxulError$1 as CapxulError, CapxulErrorCode$1 as CapxulErrorCode, Email, NextAction, type OnboardingFlowContext, type OnboardingFlowError, type OnboardingFlowEvent, type OnboardingProfileInput, type OnboardingSubjectKind, OperationId, type ProvisioningFlowContext, type ProvisioningFlowError, type ProvisioningFlowEvent, type ProvisioningFlowInput, type ProvisioningFlowOutput, Session, Username, createAuthFlowMachine, createLocalSigner, createOnboardingFlowMachine, createProvisioningMachine as createProvisioningFlowMachine, matchAction, matchError, matchStatus };
500
+ export { Account, AccountProvisionPersonalInput, type AuthFlowContext, type AuthFlowError, type AuthFlowEvent, CapxulClient, CapxulError, CapxulErrorCode, Email, NextAction, type OnboardingFlowContext, type OnboardingFlowError, type OnboardingFlowEvent, type OnboardingProfileInput, type OnboardingSubjectKind, OperationId, type ProvisioningFlowContext, type ProvisioningFlowError, type ProvisioningFlowEvent, type ProvisioningFlowInput, type ProvisioningFlowOutput, Session, Username, createAuthFlowMachine, createLocalSigner, createOnboardingFlowMachine, createProvisioningMachine as createProvisioningFlowMachine, matchAction, matchError, matchStatus, tryCatch };