@capxul/sdk 0.1.0-alpha.2 → 0.1.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
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-CXRKtbfn.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-CXRKtbfn.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';
@@ -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,5 +1,5 @@
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-CcCtq5XO.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 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-CcCtq5XO.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';
@@ -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
@@ -71,9 +71,79 @@ function fromConvexError(error) {
71
71
  // src/core/accounts.ts
72
72
  function createAccountsClient(config = {}) {
73
73
  return {
74
- retrieve: async () => stub("accounts.retrieve"),
74
+ retrieve: async (accountId) => {
75
+ if (!config.data) {
76
+ return stub("accounts.retrieve");
77
+ }
78
+ try {
79
+ const account = await config.data.query(
80
+ api.openfort.queries.getMyAccount,
81
+ {}
82
+ );
83
+ if (account.id !== accountId) {
84
+ return [
85
+ new CapxulError({
86
+ code: "PERMISSION_DENIED",
87
+ message: "accounts.retrieve currently supports the authenticated caller's own account only.",
88
+ details: {
89
+ requestedAccountId: accountId,
90
+ authenticatedAccountId: account.id
91
+ }
92
+ }),
93
+ null
94
+ ];
95
+ }
96
+ return [null, account];
97
+ } catch (cause) {
98
+ return [fromConvexError(cause), null];
99
+ }
100
+ },
75
101
  lookup: async () => stub("accounts.lookup"),
76
- update: async () => stub("accounts.update"),
102
+ update: async (input) => {
103
+ if (!config.data) {
104
+ return stub("accounts.update");
105
+ }
106
+ if (input.countryCode !== void 0) {
107
+ return [
108
+ new CapxulError({
109
+ code: "INVALID_INPUT",
110
+ message: "accounts.update does not support countryCode yet \u2014 backend mutation only patches displayName and username.",
111
+ details: { field: "countryCode" }
112
+ }),
113
+ null
114
+ ];
115
+ }
116
+ try {
117
+ const current = await config.data.query(
118
+ api.openfort.queries.getMyAccount,
119
+ {}
120
+ );
121
+ if (current.id !== input.accountId) {
122
+ return [
123
+ new CapxulError({
124
+ code: "PERMISSION_DENIED",
125
+ message: "accounts.update currently supports the authenticated caller's own account only.",
126
+ details: {
127
+ requestedAccountId: input.accountId,
128
+ authenticatedAccountId: current.id
129
+ }
130
+ }),
131
+ null
132
+ ];
133
+ }
134
+ await config.data.mutation(api.openfort.mutations.updateProfile, {
135
+ displayName: input.name,
136
+ username: input.username
137
+ });
138
+ const updated = await config.data.query(
139
+ api.openfort.queries.getMyAccount,
140
+ {}
141
+ );
142
+ return [null, updated];
143
+ } catch (cause) {
144
+ return [fromConvexError(cause), null];
145
+ }
146
+ },
77
147
  provisionPersonal: async (input) => {
78
148
  if (!config.data) {
79
149
  return stub(
@@ -697,7 +767,34 @@ function createMeClient(config = {}) {
697
767
  return [fromConvexError(cause), null];
698
768
  }
699
769
  },
700
- update: async () => stub("me.update")
770
+ update: async (input) => {
771
+ if (!config.data) {
772
+ return stub("me.update");
773
+ }
774
+ if (input.countryCode !== void 0) {
775
+ return [
776
+ new CapxulError({
777
+ code: "INVALID_INPUT",
778
+ message: "me.update does not support countryCode yet \u2014 backend mutation only patches displayName and username.",
779
+ details: { field: "countryCode" }
780
+ }),
781
+ null
782
+ ];
783
+ }
784
+ try {
785
+ await config.data.mutation(api.openfort.mutations.updateProfile, {
786
+ displayName: input.name,
787
+ username: input.username
788
+ });
789
+ const account = await config.data.query(
790
+ api.openfort.queries.getMyAccount,
791
+ {}
792
+ );
793
+ return [null, account];
794
+ } catch (cause) {
795
+ return [fromConvexError(cause), null];
796
+ }
797
+ }
701
798
  };
702
799
  }
703
800
 
@@ -1506,6 +1603,96 @@ function createSubAccountsClient() {
1506
1603
  };
1507
1604
  }
1508
1605
 
1606
+ // src/core/token-transfers.ts
1607
+ var toTokenTransferId = (raw) => {
1608
+ if (typeof raw !== "string" || raw.length === 0) {
1609
+ throw new Error(
1610
+ `Invalid tokenTransferId: expected non-empty string, got ${String(raw)}`
1611
+ );
1612
+ }
1613
+ return raw;
1614
+ };
1615
+ function brandRow(row) {
1616
+ return {
1617
+ ...row,
1618
+ id: toTokenTransferId(row.id)
1619
+ };
1620
+ }
1621
+ function createTokenTransfersClient(config = {}) {
1622
+ return {
1623
+ list: async (input) => {
1624
+ if (!config.data) {
1625
+ return stub("tokenTransfers.list");
1626
+ }
1627
+ try {
1628
+ const raw = await config.data.query(
1629
+ api.tokenTransfers.queries.list,
1630
+ {
1631
+ limit: input?.limit,
1632
+ cursor: input?.cursor,
1633
+ direction: input?.direction
1634
+ }
1635
+ );
1636
+ if (!raw) {
1637
+ return [
1638
+ new CapxulError({
1639
+ code: "NOT_AUTHENTICATED",
1640
+ message: "tokenTransfers.list requires an authenticated session."
1641
+ }),
1642
+ null
1643
+ ];
1644
+ }
1645
+ return [
1646
+ null,
1647
+ {
1648
+ object: "list",
1649
+ data: raw.items.map(brandRow),
1650
+ page: {
1651
+ hasMore: raw.hasMore,
1652
+ nextCursor: raw.nextCursor
1653
+ },
1654
+ displayCurrency: raw.displayCurrency
1655
+ }
1656
+ ];
1657
+ } catch (cause) {
1658
+ return [fromConvexError(cause), null];
1659
+ }
1660
+ },
1661
+ retrieve: async (input) => {
1662
+ if (!config.data) {
1663
+ return stub("tokenTransfers.retrieve");
1664
+ }
1665
+ try {
1666
+ const raw = await config.data.query(
1667
+ api.tokenTransfers.queries.getByTxLogIndex,
1668
+ {
1669
+ txHash: input.txHash,
1670
+ logIndex: input.logIndex,
1671
+ chainId: input.chainId
1672
+ }
1673
+ );
1674
+ if (!raw) {
1675
+ return [
1676
+ new CapxulError({
1677
+ code: "NOT_FOUND",
1678
+ message: `tokenTransfer (txHash=${input.txHash}, logIndex=${input.logIndex}) not found or not visible to caller.`,
1679
+ details: {
1680
+ txHash: input.txHash,
1681
+ logIndex: input.logIndex,
1682
+ chainId: input.chainId
1683
+ }
1684
+ }),
1685
+ null
1686
+ ];
1687
+ }
1688
+ return [null, brandRow(raw)];
1689
+ } catch (cause) {
1690
+ return [fromConvexError(cause), null];
1691
+ }
1692
+ }
1693
+ };
1694
+ }
1695
+
1509
1696
  // src/core/virtual-accounts.ts
1510
1697
  function createVirtualAccountsClient() {
1511
1698
  return {
@@ -1528,6 +1715,15 @@ function createVirtualCardsClient() {
1528
1715
  };
1529
1716
  }
1530
1717
 
1718
+ // ../observability/src/try-catch.ts
1719
+ async function tryCatch(promise) {
1720
+ try {
1721
+ return [null, await promise];
1722
+ } catch (e) {
1723
+ return [e instanceof Error ? e : new Error(String(e)), null];
1724
+ }
1725
+ }
1726
+
1531
1727
  // ../observability/src/debug-log.ts
1532
1728
  function isDevelopmentBuild() {
1533
1729
  if (typeof process === "undefined") {
@@ -2348,6 +2544,7 @@ function createCapxulClient(config = {}) {
2348
2544
  organizations: createOrganizationsClient(config),
2349
2545
  payments: createPaymentsClient(config),
2350
2546
  transfers: createTransfersClient(),
2547
+ tokenTransfers: createTokenTransfersClient(config),
2351
2548
  withdrawals: createWithdrawalsClient(config),
2352
2549
  documents: createDocumentsClient(),
2353
2550
  subAccounts: createSubAccountsClient(),
@@ -2466,4 +2663,4 @@ function isWebhookEvent(value) {
2466
2663
  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
2664
  }
2468
2665
 
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 };
2666
+ 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, toTokenTransferId, toTransferId, toTreasuryId, toUsername, toVirtualAccountId, toVirtualCardId, toWebhookEndpointId, toWebhookEventId, toWithdrawalId, tryCatch, verifyWebhook };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capxul/sdk",
3
- "version": "0.1.0-alpha.2",
3
+ "version": "0.1.0-alpha.4",
4
4
  "description": "Headless TypeScript client for Capxul's /v1/* HTTP contract.",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,