@capxul/sdk 0.1.0-alpha.8 → 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.
package/dist/index.cjs CHANGED
@@ -1127,7 +1127,68 @@ function createAuthClient(config = {}) {
1127
1127
  ];
1128
1128
  }
1129
1129
  }
1130
- return [null, session];
1130
+ if (!dataClient) {
1131
+ return [
1132
+ new CapxulError({
1133
+ code: "NOT_AUTHENTICATED",
1134
+ message: "Auth bootstrap requires an authenticated Convex data client."
1135
+ }),
1136
+ null
1137
+ ];
1138
+ }
1139
+ try {
1140
+ const resolution = await dataClient.mutation(
1141
+ api.authBootstrap.resolveAfterOtp,
1142
+ {
1143
+ email: session.email,
1144
+ sessionToken: session.token
1145
+ }
1146
+ );
1147
+ if (resolution.kind === "existing_member") {
1148
+ return [null, { ...resolution, session }];
1149
+ }
1150
+ return [null, { ...resolution, session }];
1151
+ } catch (cause) {
1152
+ return [fromConvexError(cause), null];
1153
+ }
1154
+ },
1155
+ completeBootstrap: async (input) => {
1156
+ const session = sessionStore.get();
1157
+ const data = dataClient ?? config.data;
1158
+ if (!session || !data) {
1159
+ return [
1160
+ new CapxulError({
1161
+ code: "INVALID_INPUT",
1162
+ message: "completeBootstrap requires the OTP-verified session that issued the bootstrap token."
1163
+ }),
1164
+ null
1165
+ ];
1166
+ }
1167
+ if (input.signerProvider.kind !== "local-private-key") {
1168
+ return [
1169
+ new CapxulError({
1170
+ code: "INVALID_INPUT",
1171
+ message: "completeBootstrap currently supports local-private-key signer providers only."
1172
+ }),
1173
+ null
1174
+ ];
1175
+ }
1176
+ try {
1177
+ const result = await data.mutation(api.authBootstrap.completeBootstrap, {
1178
+ bootstrapToken: input.bootstrapToken,
1179
+ sessionToken: session.token,
1180
+ username: input.username,
1181
+ displayName: input.displayName,
1182
+ countryCode: input.countryCode,
1183
+ signerProvider: input.signerProvider
1184
+ });
1185
+ return [null, { kind: "authenticated", session, ...result }];
1186
+ } catch (cause) {
1187
+ return [
1188
+ fromConvexError(cause),
1189
+ null
1190
+ ];
1191
+ }
1131
1192
  },
1132
1193
  getSession: async () => [null, sessionStore.get()],
1133
1194
  signOut: async () => {
@@ -2486,7 +2547,7 @@ function createAuthFlowMachine(client) {
2486
2547
  }),
2487
2548
  verifyOtp: xstate.fromPromise(
2488
2549
  async ({ input, signal }) => {
2489
- const [error, session] = await client.auth.verifyOtp(
2550
+ const [error, result] = await client.auth.verifyOtp(
2490
2551
  {
2491
2552
  email: input.email,
2492
2553
  otp: input.code
@@ -2494,7 +2555,14 @@ function createAuthFlowMachine(client) {
2494
2555
  { signal }
2495
2556
  );
2496
2557
  if (error) throw error;
2497
- return session;
2558
+ if (result.kind === "bootstrap_required") {
2559
+ throw new CapxulError({
2560
+ code: "ACTION_REQUIRED",
2561
+ message: "OTP verified but auth bootstrap is required. Use createAuthBootstrapFlowMachine for product sign-up.",
2562
+ details: { reason: result.reason }
2563
+ });
2564
+ }
2565
+ return result.session;
2498
2566
  }
2499
2567
  ),
2500
2568
  signOut: xstate.fromPromise(async () => {
@@ -2742,6 +2810,345 @@ function emailDomain(email) {
2742
2810
  const domain = email.split("@")[1]?.trim().toLowerCase();
2743
2811
  return domain || "unknown";
2744
2812
  }
2813
+ var initialContext = {
2814
+ email: null,
2815
+ code: null,
2816
+ username: null,
2817
+ signerProvider: null,
2818
+ bootstrapToken: null,
2819
+ bootstrapReason: null,
2820
+ session: null,
2821
+ account: null,
2822
+ safe: null,
2823
+ error: null
2824
+ };
2825
+ function createAuthBootstrapFlowMachine(client) {
2826
+ return xstate.setup({
2827
+ types: {},
2828
+ actors: {
2829
+ sendOtp: xstate.fromPromise(async ({ input, signal }) => {
2830
+ const [error] = await client.auth.sendOtp(
2831
+ { email: input.email },
2832
+ { signal }
2833
+ );
2834
+ if (error) throw error;
2835
+ }),
2836
+ verifyOtp: xstate.fromPromise(
2837
+ async ({ input, signal }) => {
2838
+ const [error, result] = await client.auth.verifyOtp(
2839
+ { email: input.email, otp: input.code },
2840
+ { signal }
2841
+ );
2842
+ if (error) throw error;
2843
+ return result;
2844
+ }
2845
+ ),
2846
+ completeBootstrap: xstate.fromPromise(async ({ input }) => {
2847
+ const [error, result] = await client.auth.completeBootstrap(input);
2848
+ if (error) throw error;
2849
+ return result;
2850
+ }),
2851
+ signOut: xstate.fromPromise(async () => {
2852
+ const [error] = await client.auth.signOut();
2853
+ if (error) throw error;
2854
+ })
2855
+ },
2856
+ actions: {
2857
+ trackOtpRequested: ({ context }) => {
2858
+ if (!context.email) return;
2859
+ track("auth_otp_requested", {
2860
+ email_domain: emailDomain2(context.email)
2861
+ });
2862
+ },
2863
+ trackFailed: ({ event }) => {
2864
+ track("auth_failed", {
2865
+ auth_type: "email_otp",
2866
+ reason: errorFromEvent2(event).code
2867
+ });
2868
+ },
2869
+ trackTimeoutFailed: () => {
2870
+ track("auth_failed", {
2871
+ auth_type: "email_otp",
2872
+ reason: "timeout"
2873
+ });
2874
+ },
2875
+ trackVerified: () => {
2876
+ track("auth_verified", { auth_type: "email_otp" });
2877
+ },
2878
+ trackBootstrapRequired: ({ context }) => {
2879
+ track("auth_verified", {
2880
+ auth_type: "email_otp",
2881
+ auth_mode: context.bootstrapReason ?? "bootstrap_required"
2882
+ });
2883
+ },
2884
+ identifyAndTrack: ({ context }) => {
2885
+ if (!context.session) return;
2886
+ identify(context.session.authUserId, {
2887
+ email_domain: emailDomain2(context.session.email)
2888
+ });
2889
+ track("auth_identified", {
2890
+ email_domain: emailDomain2(context.session.email)
2891
+ });
2892
+ },
2893
+ trackSignedOut: () => {
2894
+ track("auth_signed_out");
2895
+ }
2896
+ }
2897
+ }).createMachine({
2898
+ id: "authBootstrap",
2899
+ initial: "email",
2900
+ context: initialContext,
2901
+ states: {
2902
+ email: {
2903
+ on: {
2904
+ ENTER_EMAIL: {
2905
+ actions: xstate.assign({
2906
+ email: ({ event }) => event.email,
2907
+ error: () => null
2908
+ })
2909
+ },
2910
+ REQUEST_OTP: { target: "sending_otp" }
2911
+ }
2912
+ },
2913
+ sending_otp: {
2914
+ invoke: {
2915
+ src: "sendOtp",
2916
+ input: ({ context }) => ({ email: requireEmail2(context) }),
2917
+ onDone: { target: "otp_requested", actions: "trackOtpRequested" },
2918
+ onError: {
2919
+ target: "otp_requested",
2920
+ actions: [
2921
+ xstate.assign({ error: ({ event }) => errorFromEvent2(event) }),
2922
+ "trackFailed"
2923
+ ]
2924
+ }
2925
+ },
2926
+ after: {
2927
+ [FLOW_INVOKE_TIMEOUT_MS]: {
2928
+ target: "otp_requested",
2929
+ actions: [
2930
+ xstate.assign({ error: () => timeoutError2("sending_otp") }),
2931
+ "trackTimeoutFailed"
2932
+ ]
2933
+ }
2934
+ }
2935
+ },
2936
+ otp_requested: {
2937
+ on: {
2938
+ ENTER_OTP: {
2939
+ actions: xstate.assign({
2940
+ code: ({ event }) => event.code,
2941
+ error: () => null
2942
+ })
2943
+ },
2944
+ VERIFY_OTP: { target: "verifying_otp" },
2945
+ BACK: { target: "email" },
2946
+ RESET: { target: "email", actions: xstate.assign(() => initialContext) }
2947
+ }
2948
+ },
2949
+ verifying_otp: {
2950
+ invoke: {
2951
+ src: "verifyOtp",
2952
+ input: ({ context }) => ({
2953
+ email: requireEmail2(context),
2954
+ code: requireCode(context)
2955
+ }),
2956
+ onDone: [
2957
+ {
2958
+ guard: ({ event }) => event.output.kind === "existing_member",
2959
+ target: "authenticated",
2960
+ actions: [
2961
+ xstate.assign({
2962
+ session: ({ event }) => event.output.session,
2963
+ account: ({ event }) => event.output.kind === "existing_member" ? event.output.account : null,
2964
+ username: ({ event }) => event.output.kind === "existing_member" ? event.output.username : null,
2965
+ safe: ({ event }) => event.output.kind === "existing_member" ? event.output.safe : null,
2966
+ email: () => null,
2967
+ error: () => null
2968
+ }),
2969
+ "trackVerified",
2970
+ "identifyAndTrack"
2971
+ ]
2972
+ },
2973
+ {
2974
+ target: "bootstrap_required",
2975
+ actions: [
2976
+ xstate.assign({
2977
+ session: ({ event }) => event.output.session,
2978
+ bootstrapToken: ({ event }) => event.output.kind === "bootstrap_required" ? event.output.bootstrapToken : null,
2979
+ bootstrapReason: ({ event }) => event.output.kind === "bootstrap_required" ? event.output.reason : null,
2980
+ username: ({ event }) => event.output.kind === "bootstrap_required" ? event.output.username ?? null : null,
2981
+ email: ({ event }) => event.output.kind === "bootstrap_required" ? event.output.email : null,
2982
+ error: () => null
2983
+ }),
2984
+ "trackVerified",
2985
+ "trackBootstrapRequired"
2986
+ ]
2987
+ }
2988
+ ],
2989
+ onError: {
2990
+ target: "otp_requested",
2991
+ actions: [
2992
+ xstate.assign({ error: ({ event }) => errorFromEvent2(event) }),
2993
+ "trackFailed"
2994
+ ]
2995
+ }
2996
+ },
2997
+ after: {
2998
+ [FLOW_INVOKE_TIMEOUT_MS]: {
2999
+ target: "otp_requested",
3000
+ actions: [
3001
+ xstate.assign({ error: () => timeoutError2("verifying_otp") }),
3002
+ "trackTimeoutFailed"
3003
+ ]
3004
+ }
3005
+ }
3006
+ },
3007
+ bootstrap_required: {
3008
+ on: {
3009
+ ENTER_USERNAME: {
3010
+ actions: xstate.assign({
3011
+ username: ({ event }) => event.username,
3012
+ error: () => null
3013
+ })
3014
+ },
3015
+ ENTER_SIGNER_PROVIDER: {
3016
+ actions: xstate.assign({
3017
+ signerProvider: ({ event }) => event.signerProvider,
3018
+ error: () => null
3019
+ })
3020
+ },
3021
+ COMPLETE_BOOTSTRAP: { target: "completing_bootstrap" },
3022
+ BACK: { target: "otp_requested" },
3023
+ RESET: { target: "email", actions: xstate.assign(() => initialContext) }
3024
+ }
3025
+ },
3026
+ completing_bootstrap: {
3027
+ invoke: {
3028
+ src: "completeBootstrap",
3029
+ input: ({ context }) => ({
3030
+ bootstrapToken: requireBootstrapToken(context),
3031
+ username: requireUsername(context),
3032
+ signerProvider: requireSignerProvider(context)
3033
+ }),
3034
+ onDone: {
3035
+ target: "authenticated",
3036
+ actions: [
3037
+ xstate.assign({
3038
+ session: ({ event }) => event.output.session,
3039
+ account: ({ event }) => event.output.account,
3040
+ username: ({ event }) => event.output.username,
3041
+ safe: ({ event }) => event.output.safe,
3042
+ bootstrapToken: () => null,
3043
+ bootstrapReason: () => null,
3044
+ signerProvider: () => null,
3045
+ email: () => null,
3046
+ error: () => null
3047
+ }),
3048
+ "identifyAndTrack"
3049
+ ]
3050
+ },
3051
+ onError: {
3052
+ target: "bootstrap_required",
3053
+ actions: [
3054
+ xstate.assign({ error: ({ event }) => errorFromEvent2(event) }),
3055
+ "trackFailed"
3056
+ ]
3057
+ }
3058
+ },
3059
+ after: {
3060
+ [FLOW_INVOKE_TIMEOUT_MS]: {
3061
+ target: "bootstrap_required",
3062
+ actions: [
3063
+ xstate.assign({ error: () => timeoutError2("completing_bootstrap") }),
3064
+ "trackTimeoutFailed"
3065
+ ]
3066
+ }
3067
+ }
3068
+ },
3069
+ authenticated: {
3070
+ on: {
3071
+ SIGN_OUT: { target: "signing_out" }
3072
+ }
3073
+ },
3074
+ signing_out: {
3075
+ invoke: {
3076
+ src: "signOut",
3077
+ onDone: {
3078
+ target: "email",
3079
+ actions: [
3080
+ xstate.assign(() => initialContext),
3081
+ "trackSignedOut"
3082
+ ]
3083
+ },
3084
+ onError: {
3085
+ target: "error",
3086
+ actions: xstate.assign({ error: ({ event }) => errorFromEvent2(event) })
3087
+ }
3088
+ }
3089
+ },
3090
+ error: {
3091
+ on: {
3092
+ RESET: { target: "email", actions: xstate.assign(() => initialContext) }
3093
+ }
3094
+ }
3095
+ }
3096
+ });
3097
+ }
3098
+ function requireEmail2(context) {
3099
+ if (!context.email) {
3100
+ throw Errors.invalidInput("email", "Auth bootstrap requires an email.");
3101
+ }
3102
+ return context.email;
3103
+ }
3104
+ function requireCode(context) {
3105
+ if (!context.code) {
3106
+ throw Errors.invalidInput("code", "Auth bootstrap requires an OTP code.");
3107
+ }
3108
+ return context.code;
3109
+ }
3110
+ function requireBootstrapToken(context) {
3111
+ if (!context.bootstrapToken) {
3112
+ throw Errors.invalidInput(
3113
+ "bootstrapToken",
3114
+ "Auth bootstrap requires a continuation token."
3115
+ );
3116
+ }
3117
+ return context.bootstrapToken;
3118
+ }
3119
+ function requireUsername(context) {
3120
+ if (!context.username) {
3121
+ throw Errors.invalidInput("username", "Auth bootstrap requires a username.");
3122
+ }
3123
+ return context.username;
3124
+ }
3125
+ function requireSignerProvider(context) {
3126
+ if (!context.signerProvider) {
3127
+ throw Errors.invalidInput(
3128
+ "signerProvider",
3129
+ "Auth bootstrap requires a signer provider."
3130
+ );
3131
+ }
3132
+ return context.signerProvider;
3133
+ }
3134
+ function errorFromEvent2(event) {
3135
+ const cause = typeof event === "object" && event !== null && "error" in event ? event.error : event;
3136
+ if (cause instanceof CapxulError || cause instanceof CapxulError2) {
3137
+ return cause;
3138
+ }
3139
+ return Errors.providerError("auth", "bootstrap", cause);
3140
+ }
3141
+ function timeoutError2(state) {
3142
+ return Errors.providerError(
3143
+ "auth",
3144
+ "bootstrap",
3145
+ new Error(`timeout: ${state} exceeded ${FLOW_INVOKE_TIMEOUT_MS}ms`)
3146
+ );
3147
+ }
3148
+ function emailDomain2(email) {
3149
+ const domain = email.split("@")[1]?.trim().toLowerCase();
3150
+ return domain || "unknown";
3151
+ }
2745
3152
  function createProvisioningMachine(client) {
2746
3153
  return xstate.setup({
2747
3154
  types: {},
@@ -2814,13 +3221,13 @@ function createProvisioningMachine(client) {
2814
3221
  },
2815
3222
  onError: {
2816
3223
  target: "error",
2817
- actions: xstate.assign({ error: ({ event }) => errorFromEvent2(event) })
3224
+ actions: xstate.assign({ error: ({ event }) => errorFromEvent3(event) })
2818
3225
  }
2819
3226
  },
2820
3227
  after: {
2821
3228
  [FLOW_INVOKE_TIMEOUT_MS]: {
2822
3229
  target: "error",
2823
- actions: xstate.assign({ error: () => timeoutError2() })
3230
+ actions: xstate.assign({ error: () => timeoutError3() })
2824
3231
  }
2825
3232
  }
2826
3233
  },
@@ -2838,7 +3245,7 @@ function createProvisioningMachine(client) {
2838
3245
  * this payload on its `onDone` transition and branches via guards
2839
3246
  * on `event.output.error`.
2840
3247
  */
2841
- output: ({ context }) => context.error ? { error: context.error } : context.account ? { account: context.account } : { error: timeoutError2() }
3248
+ output: ({ context }) => context.error ? { error: context.error } : context.account ? { account: context.account } : { error: timeoutError3() }
2842
3249
  });
2843
3250
  }
2844
3251
  function requireProvisionInput(context) {
@@ -2850,13 +3257,13 @@ function requireProvisionInput(context) {
2850
3257
  }
2851
3258
  return context.input;
2852
3259
  }
2853
- function errorFromEvent2(event) {
3260
+ function errorFromEvent3(event) {
2854
3261
  const cause = typeof event === "object" && event !== null && "error" in event ? event.error : event;
2855
3262
  if (cause instanceof CapxulError) return cause;
2856
3263
  if (cause instanceof CapxulError2) return cause;
2857
3264
  return Errors.providerError("provisioning", "flow", cause);
2858
3265
  }
2859
- function timeoutError2() {
3266
+ function timeoutError3() {
2860
3267
  return Errors.providerError(
2861
3268
  "provisioning",
2862
3269
  "flow",
@@ -2949,7 +3356,7 @@ function createOnboardingFlowMachine(client) {
2949
3356
  error: ({ event }) => extractChildErrorOrFallback(event)
2950
3357
  }),
2951
3358
  assignChildThrown: xstate.assign({
2952
- error: ({ event }) => errorFromEvent3(event)
3359
+ error: ({ event }) => errorFromEvent4(event)
2953
3360
  }),
2954
3361
  assignAccountFromChild: xstate.assign({
2955
3362
  account: ({ event }) => extractChildAccountOrNull(event)
@@ -3111,7 +3518,7 @@ function extractChildAccountOrNull(event) {
3111
3518
  if (output && "account" in output && output.account) return output.account;
3112
3519
  return null;
3113
3520
  }
3114
- function errorFromEvent3(event) {
3521
+ function errorFromEvent4(event) {
3115
3522
  const cause = typeof event === "object" && event !== null && "error" in event ? event.error : event;
3116
3523
  if (cause instanceof CapxulError) return cause;
3117
3524
  if (cause instanceof CapxulError2) return cause;
@@ -3143,6 +3550,7 @@ function createCapxulClient(config = {}) {
3143
3550
  const client = clientWithoutFlows;
3144
3551
  client.flows = {
3145
3552
  auth: () => createAuthFlowMachine(client),
3553
+ authBootstrap: () => createAuthBootstrapFlowMachine(client),
3146
3554
  onboarding: () => createOnboardingFlowMachine(client),
3147
3555
  provisioning: () => createProvisioningMachine(client)
3148
3556
  };
@@ -3248,6 +3656,7 @@ function isWebhookEvent(value) {
3248
3656
  }
3249
3657
 
3250
3658
  exports.CapxulError = CapxulError;
3659
+ exports.createAuthBootstrapFlowMachine = createAuthBootstrapFlowMachine;
3251
3660
  exports.createAuthFlowMachine = createAuthFlowMachine;
3252
3661
  exports.createCapxulClient = createCapxulClient;
3253
3662
  exports.createLocalSigner = createLocalSigner;
package/dist/index.d.cts CHANGED
@@ -1,36 +1,15 @@
1
- import { S as Session, C as CapxulClient, A as AccountProvisionPersonalInput } from './client-DDAVWtzJ.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 TokenTransfer, s as TokenTransferId, t as TokenTransfersClient, u as TokenTransfersListInput, v as TokenTransfersListPage, w as TokenTransfersRetrieveInput, x as TransfersClient, y as TransportRuntime, z as TransportState, V as VirtualAccountsClient, F as VirtualCardsClient, W as WebhookEndpointCreateResult, G as WebhookEndpointsClient, I as WebhookEventsClient, J as WithdrawalsClient, K as createCapxulClient, N as makeHttpTransport, Q as toTokenTransferId } from './client-DDAVWtzJ.cjs';
1
+ import { S as Session, C as CapxulError$1, a as CapxulClient, A as AccountProvisionPersonalInput } from './client-DG6ODWu6.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-DG6ODWu6.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
8
  import { A as Account } from './types-hfcOE7Oi.cjs';
9
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
12
 
13
- /**
14
- * Unified error type used across the entire stack: backend, SDK, and frontend.
15
- * One class, one set of codes, one language.
16
- *
17
- * Backend throws CapxulError → withErrorBoundary serializes to ConvexError →
18
- * SDK deserializes back to CapxulError → frontend routes on err.code.
19
- */
20
- 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";
21
- declare class CapxulError extends Error {
22
- readonly code: CapxulErrorCode;
23
- readonly details?: Record<string, unknown>;
24
- readonly correlationId?: string;
25
- readonly layer?: string;
26
- constructor(code: CapxulErrorCode, message: string, options?: {
27
- cause?: unknown;
28
- details?: Record<string, unknown>;
29
- correlationId?: string;
30
- layer?: string;
31
- });
32
- }
33
-
34
13
  /**
35
14
  * Auth flow errors may originate from two CapxulError surfaces:
36
15
  * - the SDK-local generic `CapxulError<Codes>` returned by
@@ -42,7 +21,7 @@ declare class CapxulError extends Error {
42
21
  * union keeps either origin assignable to `context.error` without an
43
22
  * `as` cast at the call site.
44
23
  */
45
- type AuthFlowError = CapxulError$1 | CapxulError;
24
+ type AuthFlowError = CapxulError | CapxulError$1;
46
25
  type AuthFlowContext = {
47
26
  readonly email: Email | null;
48
27
  readonly session: Session | null;
@@ -118,7 +97,7 @@ declare function createAuthFlowMachine(client: CapxulClient): xstate.StateMachin
118
97
  } | {
119
98
  type: "trackSignedOut";
120
99
  params: unknown;
121
- }, 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, {
122
101
  id: "auth";
123
102
  states: {
124
103
  readonly idle: {};
@@ -141,7 +120,7 @@ declare function createAuthFlowMachine(client: CapxulClient): xstate.StateMachin
141
120
  *
142
121
  * Both share `.code`, `.message`, `.details`, and extend `Error`.
143
122
  */
144
- type ProvisioningFlowError = CapxulError$1 | CapxulError;
123
+ type ProvisioningFlowError = CapxulError | CapxulError$1;
145
124
  type ProvisioningFlowContext = {
146
125
  readonly input: AccountProvisionPersonalInput | null;
147
126
  readonly account: Account | null;
@@ -218,7 +197,7 @@ declare function createProvisioningMachine(client: CapxulClient): xstate.StateMa
218
197
  }, {
219
198
  type: "hasInput";
220
199
  params: unknown;
221
- }, never, "done" | "error" | "idle" | "starting" | "running", string, {
200
+ }, never, "idle" | "error" | "done" | "starting" | "running", string, {
222
201
  readonly input: AccountProvisionPersonalInput;
223
202
  }, {
224
203
  readonly account: Account;
@@ -248,7 +227,7 @@ declare function createProvisioningMachine(client: CapxulClient): xstate.StateMa
248
227
  *
249
228
  * Both share `.code`, `.message`, `.details`, and extend `Error`.
250
229
  */
251
- type OnboardingFlowError = CapxulError$1 | CapxulError;
230
+ type OnboardingFlowError = CapxulError | CapxulError$1;
252
231
  /** Subjects supported by the onboarding flow. */
253
232
  type OnboardingSubjectKind = "account" | "organization";
254
233
  /**
@@ -326,7 +305,7 @@ declare function createOnboardingFlowMachine(client: CapxulClient): xstate.State
326
305
  }, {
327
306
  type: "hasInput";
328
307
  params: unknown;
329
- }, never, "done" | "error" | "idle" | "starting" | "running", string, {
308
+ }, never, "idle" | "error" | "done" | "starting" | "running", string, {
330
309
  readonly input: AccountProvisionPersonalInput;
331
310
  }, {
332
311
  readonly account: Account;
@@ -368,7 +347,7 @@ declare function createOnboardingFlowMachine(client: CapxulClient): xstate.State
368
347
  }, {
369
348
  type: "hasInput";
370
349
  params: unknown;
371
- }, never, "done" | "error" | "idle" | "starting" | "running", string, {
350
+ }, never, "idle" | "error" | "done" | "starting" | "running", string, {
372
351
  readonly input: AccountProvisionPersonalInput;
373
352
  }, {
374
353
  readonly account: Account;
@@ -438,7 +417,7 @@ declare function createOnboardingFlowMachine(client: CapxulClient): xstate.State
438
417
  } | {
439
418
  type: "childReportedError";
440
419
  params: unknown;
441
- }, 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, {
442
421
  id: "onboarding";
443
422
  states: {
444
423
  readonly profile: {};
@@ -461,8 +440,8 @@ declare function createOnboardingFlowMachine(client: CapxulClient): xstate.State
461
440
  * No `default:` arm needed — the compile-time exhaustiveness check is
462
441
  * the contract.
463
442
  */
464
- declare function matchError<Codes extends CapxulErrorCode$1, R>(err: CapxulError$1<Codes>, handlers: {
465
- [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;
466
445
  }): R;
467
446
  /**
468
447
  * Exhaustive resource-status dispatch per CANON.md §4.44.
@@ -518,4 +497,4 @@ declare function tryCatch<T>(promise: Promise<T>): Promise<[Error, null] | [null
518
497
  */
519
498
  declare function createLocalSigner(privateKey: `0x${string}`): Account$1;
520
499
 
521
- 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, tryCatch };
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 };