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

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,12 +1,12 @@
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 CapxulClient, A as AccountProvisionPersonalInput } from './client-CwcnMbGv.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-CwcnMbGv.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
6
  import { C as CapxulError$1, a as CapxulErrorCode$1 } 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-z4VLz9rS.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-z4VLz9rS.cjs';
10
10
  import { Account as Account$1 } from 'viem';
11
11
  export { WebhookVerificationOptions, WebhookVerificationResult, verifyWebhook } from './webhooks.cjs';
12
12
  import '@repo/api-contract/gen/types';
@@ -119,7 +119,7 @@ declare function createAuthFlowMachine(client: CapxulClient): xstate.StateMachin
119
119
  } | {
120
120
  type: "trackSignedOut";
121
121
  params: unknown;
122
- }, never, never, "error" | "idle" | "sending_otp" | "otp_requested" | "verifying" | "authenticated" | "signing_out", string, xstate.NonReducibleUnknown, xstate.NonReducibleUnknown, xstate.EventObject, xstate.MetaObject, {
122
+ }, never, never, "idle" | "authenticated" | "error" | "sending_otp" | "otp_requested" | "verifying" | "signing_out", string, xstate.NonReducibleUnknown, xstate.NonReducibleUnknown, xstate.EventObject, xstate.MetaObject, {
123
123
  id: "auth";
124
124
  states: {
125
125
  readonly idle: {};
@@ -219,7 +219,7 @@ declare function createProvisioningMachine(client: CapxulClient): xstate.StateMa
219
219
  }, {
220
220
  type: "hasInput";
221
221
  params: unknown;
222
- }, never, "done" | "error" | "idle" | "starting" | "running", string, {
222
+ }, never, "idle" | "error" | "done" | "starting" | "running", string, {
223
223
  readonly input: AccountProvisionPersonalInput;
224
224
  }, {
225
225
  readonly account: Account;
@@ -327,7 +327,7 @@ declare function createOnboardingFlowMachine(client: CapxulClient): xstate.State
327
327
  }, {
328
328
  type: "hasInput";
329
329
  params: unknown;
330
- }, never, "done" | "error" | "idle" | "starting" | "running", string, {
330
+ }, never, "idle" | "error" | "done" | "starting" | "running", string, {
331
331
  readonly input: AccountProvisionPersonalInput;
332
332
  }, {
333
333
  readonly account: Account;
@@ -369,7 +369,7 @@ declare function createOnboardingFlowMachine(client: CapxulClient): xstate.State
369
369
  }, {
370
370
  type: "hasInput";
371
371
  params: unknown;
372
- }, never, "done" | "error" | "idle" | "starting" | "running", string, {
372
+ }, never, "idle" | "error" | "done" | "starting" | "running", string, {
373
373
  readonly input: AccountProvisionPersonalInput;
374
374
  }, {
375
375
  readonly account: Account;
@@ -439,7 +439,7 @@ declare function createOnboardingFlowMachine(client: CapxulClient): xstate.State
439
439
  } | {
440
440
  type: "childReportedError";
441
441
  params: unknown;
442
- }, never, "error" | "provisioning" | "profile" | "complete" | "action_required", string, xstate.NonReducibleUnknown, xstate.NonReducibleUnknown, xstate.EventObject, xstate.MetaObject, {
442
+ }, never, "action_required" | "provisioning" | "error" | "profile" | "complete", string, xstate.NonReducibleUnknown, xstate.NonReducibleUnknown, xstate.EventObject, xstate.MetaObject, {
443
443
  id: "onboarding";
444
444
  states: {
445
445
  readonly profile: {};
@@ -500,6 +500,13 @@ declare function matchAction<A extends NextAction, R>(action: A, handlers: {
500
500
  }>) => R;
501
501
  }): R;
502
502
 
503
+ /**
504
+ * Go-style error handling for async calls.
505
+ * Returns [error, null] on failure, [null, value] on success.
506
+ * Pure utility — no side effects, no reporter.
507
+ */
508
+ declare function tryCatch<T>(promise: Promise<T>): Promise<[Error, null] | [null, T]>;
509
+
503
510
  /**
504
511
  * Convenience constructor for a viem `Account` backed by a raw private
505
512
  * key — the CLI / server-side signer per CANON.md §4.28.
@@ -512,4 +519,4 @@ declare function matchAction<A extends NextAction, R>(action: A, handlers: {
512
519
  */
513
520
  declare function createLocalSigner(privateKey: `0x${string}`): Account$1;
514
521
 
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 };
522
+ 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 };
package/dist/index.d.ts CHANGED
@@ -1,12 +1,12 @@
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 CapxulClient, A as AccountProvisionPersonalInput } from './client-BI863O0y.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-BI863O0y.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
6
  import { C as CapxulError$1, a as CapxulErrorCode$1 } 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-BE3tVIOI.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-BE3tVIOI.js';
10
10
  import { Account as Account$1 } from 'viem';
11
11
  export { WebhookVerificationOptions, WebhookVerificationResult, verifyWebhook } from './webhooks.js';
12
12
  import '@repo/api-contract/gen/types';
@@ -119,7 +119,7 @@ declare function createAuthFlowMachine(client: CapxulClient): xstate.StateMachin
119
119
  } | {
120
120
  type: "trackSignedOut";
121
121
  params: unknown;
122
- }, never, never, "error" | "idle" | "sending_otp" | "otp_requested" | "verifying" | "authenticated" | "signing_out", string, xstate.NonReducibleUnknown, xstate.NonReducibleUnknown, xstate.EventObject, xstate.MetaObject, {
122
+ }, never, never, "idle" | "authenticated" | "error" | "sending_otp" | "otp_requested" | "verifying" | "signing_out", string, xstate.NonReducibleUnknown, xstate.NonReducibleUnknown, xstate.EventObject, xstate.MetaObject, {
123
123
  id: "auth";
124
124
  states: {
125
125
  readonly idle: {};
@@ -219,7 +219,7 @@ declare function createProvisioningMachine(client: CapxulClient): xstate.StateMa
219
219
  }, {
220
220
  type: "hasInput";
221
221
  params: unknown;
222
- }, never, "done" | "error" | "idle" | "starting" | "running", string, {
222
+ }, never, "idle" | "error" | "done" | "starting" | "running", string, {
223
223
  readonly input: AccountProvisionPersonalInput;
224
224
  }, {
225
225
  readonly account: Account;
@@ -327,7 +327,7 @@ declare function createOnboardingFlowMachine(client: CapxulClient): xstate.State
327
327
  }, {
328
328
  type: "hasInput";
329
329
  params: unknown;
330
- }, never, "done" | "error" | "idle" | "starting" | "running", string, {
330
+ }, never, "idle" | "error" | "done" | "starting" | "running", string, {
331
331
  readonly input: AccountProvisionPersonalInput;
332
332
  }, {
333
333
  readonly account: Account;
@@ -369,7 +369,7 @@ declare function createOnboardingFlowMachine(client: CapxulClient): xstate.State
369
369
  }, {
370
370
  type: "hasInput";
371
371
  params: unknown;
372
- }, never, "done" | "error" | "idle" | "starting" | "running", string, {
372
+ }, never, "idle" | "error" | "done" | "starting" | "running", string, {
373
373
  readonly input: AccountProvisionPersonalInput;
374
374
  }, {
375
375
  readonly account: Account;
@@ -439,7 +439,7 @@ declare function createOnboardingFlowMachine(client: CapxulClient): xstate.State
439
439
  } | {
440
440
  type: "childReportedError";
441
441
  params: unknown;
442
- }, never, "error" | "provisioning" | "profile" | "complete" | "action_required", string, xstate.NonReducibleUnknown, xstate.NonReducibleUnknown, xstate.EventObject, xstate.MetaObject, {
442
+ }, never, "action_required" | "provisioning" | "error" | "profile" | "complete", string, xstate.NonReducibleUnknown, xstate.NonReducibleUnknown, xstate.EventObject, xstate.MetaObject, {
443
443
  id: "onboarding";
444
444
  states: {
445
445
  readonly profile: {};
@@ -500,6 +500,13 @@ declare function matchAction<A extends NextAction, R>(action: A, handlers: {
500
500
  }>) => R;
501
501
  }): R;
502
502
 
503
+ /**
504
+ * Go-style error handling for async calls.
505
+ * Returns [error, null] on failure, [null, value] on success.
506
+ * Pure utility — no side effects, no reporter.
507
+ */
508
+ declare function tryCatch<T>(promise: Promise<T>): Promise<[Error, null] | [null, T]>;
509
+
503
510
  /**
504
511
  * Convenience constructor for a viem `Account` backed by a raw private
505
512
  * key — the CLI / server-side signer per CANON.md §4.28.
@@ -512,4 +519,4 @@ declare function matchAction<A extends NextAction, R>(action: A, handlers: {
512
519
  */
513
520
  declare function createLocalSigner(privateKey: `0x${string}`): Account$1;
514
521
 
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 };
522
+ 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 };
package/dist/index.js CHANGED
@@ -1100,298 +1100,24 @@ function createOrgTransfersClient() {
1100
1100
  cancel: async () => stub("organizations.transfers.cancel")
1101
1101
  };
1102
1102
  }
1103
- var EVM_ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;
1104
- function createWithdrawalsClient(config = {}) {
1103
+
1104
+ // src/core/withdrawals.ts
1105
+ function createWithdrawalsClient() {
1105
1106
  return {
1106
- create: async (input) => {
1107
- if (!config.data) {
1108
- return stub("withdrawals.create");
1109
- }
1110
- let created = null;
1111
- let submitted = null;
1112
- try {
1113
- created = await config.data.mutation(
1114
- api.withdrawals.mutations.create,
1115
- {
1116
- amount: input.amount,
1117
- destination: {
1118
- externalAccountId: input.destination.externalAccountId,
1119
- kind: input.destination.kind
1120
- },
1121
- source: input.source,
1122
- reference: input.reference,
1123
- idempotencyKey: input.idempotencyKey
1124
- }
1125
- );
1126
- if (!created) {
1127
- return [
1128
- new CapxulError({
1129
- code: "NETWORK_ERROR",
1130
- message: "withdrawals.create returned no withdrawal resource"
1131
- }),
1132
- null
1133
- ];
1134
- }
1135
- if (created.status !== "processing" || created.operation.status !== "processing") {
1136
- return [null, created];
1137
- }
1138
- if (input.destination.kind !== "evm") {
1139
- return [null, created];
1140
- }
1141
- if (!config.signer || !config.signing) {
1142
- return [null, created];
1143
- }
1144
- if (!EVM_ADDRESS_RE.test(input.destination.externalAccountId)) {
1145
- throw new CapxulError({
1146
- code: "INVALID_INPUT",
1147
- message: "destination.externalAccountId must be a 0x-prefixed EVM address while external_accounts resolution is pending (slice 1).",
1148
- details: { field: "destination.externalAccountId" }
1149
- });
1150
- }
1151
- const currentSigner = await config.data.query(
1152
- api.safe.queries.getMySignerAddress,
1153
- {}
1154
- );
1155
- if (!currentSigner?.address) {
1156
- throw new CapxulError({
1157
- code: "PERMISSION_DENIED",
1158
- message: "No signer is registered for the authenticated account.",
1159
- details: { withdrawalId: created.id }
1160
- });
1161
- }
1162
- if (getAddress(currentSigner.address) !== getAddress(config.signer.address)) {
1163
- throw new CapxulError({
1164
- code: "PERMISSION_DENIED",
1165
- message: "Configured signer does not match the authenticated account signer.",
1166
- details: {
1167
- withdrawalId: created.id,
1168
- expectedSignerAddress: currentSigner.address,
1169
- actualSignerAddress: config.signer.address
1170
- }
1171
- });
1172
- }
1173
- const submission = await config.data.query(
1174
- api.withdrawals.queries.prepareSubmission,
1175
- { withdrawalId: created.id }
1176
- );
1177
- if (!submission?.externalAccountId) {
1178
- throw new CapxulError({
1179
- code: "NETWORK_ERROR",
1180
- message: "withdrawals.prepareSubmission returned no destination.",
1181
- details: { withdrawalId: created.id }
1182
- });
1183
- }
1184
- const transfer = await transferAsOwner(
1185
- {
1186
- signer: config.signer,
1187
- signing: config.signing
1188
- },
1189
- {
1190
- tokenAddress: resolvePaymentTokenAddress(submission.amount.currency),
1191
- recipientAddress: submission.externalAccountId,
1192
- amount: toTokenUnits(submission.amount.value, 6)
1193
- }
1194
- );
1195
- if (!transfer.success) {
1196
- throw new CapxulError({
1197
- code: "NETWORK_ERROR",
1198
- message: "Bundler submission did not succeed.",
1199
- details: {
1200
- withdrawalId: created.id,
1201
- txHash: transfer.txHash,
1202
- userOpHash: transfer.userOpHash
1203
- }
1204
- });
1205
- }
1206
- submitted = {
1207
- txHash: transfer.txHash,
1208
- userOpHash: transfer.userOpHash
1209
- };
1210
- await config.data.mutation(
1211
- api.withdrawals.mutations.recordSubmitted,
1212
- {
1213
- withdrawalId: created.id,
1214
- txHash: transfer.txHash,
1215
- userOpHash: transfer.userOpHash
1216
- }
1217
- );
1218
- return [null, created];
1219
- } catch (cause) {
1220
- const error = mapCreateError2(fromConvexError(cause));
1221
- if (created?.id && created.status === "processing" && !submitted) {
1222
- await bestEffortMarkFailed2({ data: config.data }, created.id, error);
1223
- }
1224
- if (submitted && created?.id) {
1225
- return [
1226
- new CapxulError({
1227
- code: "NETWORK_ERROR",
1228
- message: "Withdrawal was submitted on-chain, but backend submission tracking failed.",
1229
- cause,
1230
- details: {
1231
- withdrawalId: created.id,
1232
- txHash: submitted.txHash,
1233
- userOpHash: submitted.userOpHash
1234
- }
1235
- }),
1236
- null
1237
- ];
1238
- }
1239
- return [error, null];
1240
- }
1241
- },
1242
- retrieve: async (withdrawalId) => {
1243
- if (!config.data) {
1244
- return stub("withdrawals.retrieve");
1245
- }
1246
- try {
1247
- const withdrawal = await config.data.query(
1248
- api.withdrawals.queries.retrieve,
1249
- { withdrawalId }
1250
- );
1251
- if (!withdrawal) {
1252
- return [
1253
- new CapxulError({
1254
- code: "NOT_FOUND",
1255
- message: `withdrawal ${withdrawalId} not found`
1256
- }),
1257
- null
1258
- ];
1259
- }
1260
- return [null, withdrawal];
1261
- } catch (cause) {
1262
- return [
1263
- fromConvexError(cause),
1264
- null
1265
- ];
1266
- }
1267
- },
1268
- list: async (input) => {
1269
- if (!config.data) {
1270
- return stub("withdrawals.list");
1271
- }
1272
- try {
1273
- const result = await config.data.query(
1274
- api.withdrawals.queries.list,
1275
- {
1276
- limit: input?.limit,
1277
- cursor: input?.cursor
1278
- }
1279
- );
1280
- return [null, result];
1281
- } catch (cause) {
1282
- return [
1283
- fromConvexError(cause),
1284
- null
1285
- ];
1286
- }
1287
- }
1107
+ create: async () => stub("withdrawals.create"),
1108
+ retrieve: async () => stub("withdrawals.retrieve"),
1109
+ list: async () => stub("withdrawals.list")
1288
1110
  };
1289
1111
  }
1290
- function createOrgWithdrawalsClient(config = {}) {
1112
+ function createOrgWithdrawalsClient() {
1291
1113
  return {
1292
- // Slice 1 ships personal-scope only end-to-end; org-scope create
1293
- // remains stubbed pending org-scoped backend mutation. List + retrieve
1294
- // are wired through the org-aware query.
1295
1114
  create: async () => stub(
1296
1115
  "organizations.withdrawals.create"
1297
1116
  ),
1298
- retrieve: async (input) => {
1299
- if (!config.data) {
1300
- return stub(
1301
- "organizations.withdrawals.retrieve"
1302
- );
1303
- }
1304
- try {
1305
- const withdrawal = await config.data.query(
1306
- api.withdrawals.queries.retrieve,
1307
- { withdrawalId: input.withdrawalId }
1308
- );
1309
- if (!withdrawal) {
1310
- return [
1311
- new CapxulError({
1312
- code: "NOT_FOUND",
1313
- message: `withdrawal ${input.withdrawalId} not found`
1314
- }),
1315
- null
1316
- ];
1317
- }
1318
- const ownerCheck = withdrawal.owner;
1319
- if (ownerCheck?.type !== "organization" || ownerCheck.id !== input.organizationId) {
1320
- return [
1321
- new CapxulError({
1322
- code: "NOT_FOUND",
1323
- message: `withdrawal ${input.withdrawalId} does not belong to organization ${input.organizationId}`
1324
- }),
1325
- null
1326
- ];
1327
- }
1328
- return [null, withdrawal];
1329
- } catch (cause) {
1330
- return [
1331
- fromConvexError(cause),
1332
- null
1333
- ];
1334
- }
1335
- },
1336
- list: async (input) => {
1337
- if (!config.data) {
1338
- return stub(
1339
- "organizations.withdrawals.list"
1340
- );
1341
- }
1342
- try {
1343
- const result = await config.data.query(
1344
- api.withdrawals.queries.listOrg,
1345
- {
1346
- organizationId: input.organizationId,
1347
- limit: input.limit,
1348
- cursor: input.cursor
1349
- }
1350
- );
1351
- return [null, result];
1352
- } catch (cause) {
1353
- return [
1354
- fromConvexError(cause),
1355
- null
1356
- ];
1357
- }
1358
- }
1117
+ retrieve: async () => stub("organizations.withdrawals.retrieve"),
1118
+ list: async () => stub("organizations.withdrawals.list")
1359
1119
  };
1360
1120
  }
1361
- async function bestEffortMarkFailed2(config, withdrawalId, error) {
1362
- try {
1363
- await config.data.mutation(api.withdrawals.mutations.markFailed, {
1364
- withdrawalId,
1365
- errorCode: error.code,
1366
- errorMessage: error.message
1367
- });
1368
- } catch {
1369
- }
1370
- }
1371
- function mapCreateError2(error) {
1372
- switch (error.code) {
1373
- case "NOT_AUTHENTICATED":
1374
- case "PERMISSION_DENIED":
1375
- case "INVALID_INPUT":
1376
- case "INSUFFICIENT_BALANCE":
1377
- case "IDEMPOTENCY_CONFLICT":
1378
- case "KYC_REQUIRED":
1379
- case "POLICY_DENIED":
1380
- case "RATE_LIMITED":
1381
- case "NETWORK_ERROR":
1382
- return error;
1383
- default:
1384
- return new CapxulError({
1385
- code: "NETWORK_ERROR",
1386
- message: error.message,
1387
- cause: error,
1388
- details: error.details,
1389
- operationId: error.operationId,
1390
- correlationId: error.correlationId,
1391
- retryable: error.retryable
1392
- });
1393
- }
1394
- }
1395
1121
 
1396
1122
  // src/core/webhook-endpoints.ts
1397
1123
  function createWebhookEndpointsClient() {
@@ -1491,7 +1217,7 @@ function createOrganizationsClient(config = {}) {
1491
1217
  },
1492
1218
  payments: createOrgPaymentsClient(),
1493
1219
  transfers: createOrgTransfersClient(),
1494
- withdrawals: createOrgWithdrawalsClient(config),
1220
+ withdrawals: createOrgWithdrawalsClient(),
1495
1221
  documents: createOrgDocumentsClient(),
1496
1222
  webhookEndpoints: createWebhookEndpointsClient(),
1497
1223
  webhookEvents: createWebhookEventsClient()
@@ -1528,6 +1254,15 @@ function createVirtualCardsClient() {
1528
1254
  };
1529
1255
  }
1530
1256
 
1257
+ // ../observability/src/try-catch.ts
1258
+ async function tryCatch(promise) {
1259
+ try {
1260
+ return [null, await promise];
1261
+ } catch (e) {
1262
+ return [e instanceof Error ? e : new Error(String(e)), null];
1263
+ }
1264
+ }
1265
+
1531
1266
  // ../observability/src/debug-log.ts
1532
1267
  function isDevelopmentBuild() {
1533
1268
  if (typeof process === "undefined") {
@@ -2348,7 +2083,7 @@ function createCapxulClient(config = {}) {
2348
2083
  organizations: createOrganizationsClient(config),
2349
2084
  payments: createPaymentsClient(config),
2350
2085
  transfers: createTransfersClient(),
2351
- withdrawals: createWithdrawalsClient(config),
2086
+ withdrawals: createWithdrawalsClient(),
2352
2087
  documents: createDocumentsClient(),
2353
2088
  subAccounts: createSubAccountsClient(),
2354
2089
  virtualAccounts: createVirtualAccountsClient(),
@@ -2466,4 +2201,4 @@ function isWebhookEvent(value) {
2466
2201
  return typeof candidate.id === "string" && typeof candidate.type === "string" && typeof candidate.createdAt === "string" && (candidate.operationId === void 0 || typeof candidate.operationId === "string") && (candidate.correlationId === void 0 || typeof candidate.correlationId === "string") && !!candidate.data && typeof candidate.data === "object" && !Array.isArray(candidate.data);
2467
2202
  }
2468
2203
 
2469
- export { CapxulError, createAuthFlowMachine, createCapxulClient, createLocalSigner, createOnboardingFlowMachine, createProvisioningMachine as createProvisioningFlowMachine, makeHttpTransport, matchAction, matchError, matchStatus, toAccountId, toApiKeyId, toBalanceLedgerEntryId, toDocumentId, toEmail, toExternalAccountId, toKybProfileId, toKycProfileId, toMemberId, toOperationId, toOrganizationId, toPaymentId, toPhoneNumber, toSafeId, toSubAccountId, toTransferId, toTreasuryId, toUsername, toVirtualAccountId, toVirtualCardId, toWebhookEndpointId, toWebhookEventId, toWithdrawalId, verifyWebhook };
2204
+ export { CapxulError, createAuthFlowMachine, createCapxulClient, createLocalSigner, createOnboardingFlowMachine, createProvisioningMachine as createProvisioningFlowMachine, makeHttpTransport, matchAction, matchError, matchStatus, toAccountId, toApiKeyId, toBalanceLedgerEntryId, toDocumentId, toEmail, toExternalAccountId, toKybProfileId, toKycProfileId, toMemberId, toOperationId, toOrganizationId, toPaymentId, toPhoneNumber, toSafeId, toSubAccountId, toTransferId, toTreasuryId, toUsername, toVirtualAccountId, toVirtualCardId, toWebhookEndpointId, toWebhookEventId, toWithdrawalId, tryCatch, verifyWebhook };
@@ -155,15 +155,7 @@ type Payment = WithStatus<WirePaymentWithBrand, PaymentStatus>;
155
155
  type CreatePaymentResult = WithStatus<WirePaymentWithBrand, "processing" | "action_required" | "failed">;
156
156
  type PaymentParty = types.PaymentParty;
157
157
  type WireWithdrawalWithBrand = Rebrand<types.Withdrawal, WithdrawalId>;
158
- /**
159
- * Canon-aligned superset (resources.mdx §withdrawal lifecycle note).
160
- * Wider than `OperationStatus` because `submitted → completed` is a
161
- * withdrawal-specific transition driven by external reconciliation
162
- * the operation envelope cannot witness directly. Slice 1 of
163
- * Withdrawals v1 (#440) widened this from `PaymentStatus` to match
164
- * canon.
165
- */
166
- type WithdrawalStatus = "draft" | "action_required" | "processing" | "submitted" | "completed" | "failed" | "canceled";
158
+ type WithdrawalStatus = PaymentStatus;
167
159
  type Withdrawal = WithStatus<WireWithdrawalWithBrand, WithdrawalStatus>;
168
160
  type CreateWithdrawalResult = WithStatus<WireWithdrawalWithBrand, "processing" | "action_required" | "failed">;
169
161
  type WireTransferWithBrand = Rebrand<types.Transfer, TransferId>;
@@ -155,15 +155,7 @@ type Payment = WithStatus<WirePaymentWithBrand, PaymentStatus>;
155
155
  type CreatePaymentResult = WithStatus<WirePaymentWithBrand, "processing" | "action_required" | "failed">;
156
156
  type PaymentParty = types.PaymentParty;
157
157
  type WireWithdrawalWithBrand = Rebrand<types.Withdrawal, WithdrawalId>;
158
- /**
159
- * Canon-aligned superset (resources.mdx §withdrawal lifecycle note).
160
- * Wider than `OperationStatus` because `submitted → completed` is a
161
- * withdrawal-specific transition driven by external reconciliation
162
- * the operation envelope cannot witness directly. Slice 1 of
163
- * Withdrawals v1 (#440) widened this from `PaymentStatus` to match
164
- * canon.
165
- */
166
- type WithdrawalStatus = "draft" | "action_required" | "processing" | "submitted" | "completed" | "failed" | "canceled";
158
+ type WithdrawalStatus = PaymentStatus;
167
159
  type Withdrawal = WithStatus<WireWithdrawalWithBrand, WithdrawalStatus>;
168
160
  type CreateWithdrawalResult = WithStatus<WireWithdrawalWithBrand, "processing" | "action_required" | "failed">;
169
161
  type WireTransferWithBrand = Rebrand<types.Transfer, TransferId>;
@@ -1,4 +1,4 @@
1
- import { Z as WebhookEvent } from './types-DVWojoy4.cjs';
1
+ import { Z as WebhookEvent } from './types-z4VLz9rS.cjs';
2
2
  import '@repo/api-contract/gen/types';
3
3
  import './next-action-DkrwXYay.cjs';
4
4
 
@@ -1,4 +1,4 @@
1
- import { Z as WebhookEvent } from './types-75UokagF.js';
1
+ import { Z as WebhookEvent } from './types-BE3tVIOI.js';
2
2
  import '@repo/api-contract/gen/types';
3
3
  import './next-action-DkrwXYay.js';
4
4
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capxul/sdk",
3
- "version": "0.1.0-alpha.1",
3
+ "version": "0.1.0-alpha.3",
4
4
  "description": "Headless TypeScript client for Capxul's /v1/* HTTP contract.",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,
@@ -58,6 +58,7 @@
58
58
  "xstate": "^5"
59
59
  },
60
60
  "peerDependencies": {
61
+ "convex": ">=1.0.0",
61
62
  "permissionless": ">=0.3.4 <0.4.0",
62
63
  "viem": ">=2.0.0"
63
64
  },
@@ -70,8 +71,8 @@
70
71
  "vitest": "^4.1.2",
71
72
  "zod": "^4.3.6",
72
73
  "@repo/api-contract": "0.0.0",
73
- "@repo/backend": "0.0.0",
74
74
  "@repo/config": "0.0.0",
75
+ "@repo/backend": "0.0.0",
75
76
  "@repo/observability": "0.0.0",
76
77
  "@repo/platform-kernel": "0.0.0",
77
78
  "@repo/typescript-config": "0.0.0"