@conto_finance/sdk 0.5.4 → 0.6.0-beta.1

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.ts CHANGED
@@ -989,6 +989,8 @@ interface ContoConfig {
989
989
  baseUrl?: string;
990
990
  /** Request timeout in milliseconds. Defaults to 30000 */
991
991
  timeout?: number;
992
+ /** Defaults for the configured live Link checkout pilot. These are IDs, never Link credentials. */
993
+ link?: LinkPaymentDefaults;
992
994
  }
993
995
  interface PaymentRequestInput {
994
996
  /** Amount in the wallet chain stablecoin */
@@ -1028,6 +1030,92 @@ interface PaymentRequestInput {
1028
1030
  /** Client-supplied key for idempotent retries */
1029
1031
  idempotencyKey?: string;
1030
1032
  }
1033
+ /** Whether a path works: `unknown` means Conto has no evidence either way. */
1034
+ type SetupCapabilityState = 'yes' | 'no' | 'unknown';
1035
+ /**
1036
+ * Stable setup issue codes. New codes can appear within a diagnostics version,
1037
+ * so handle an unrecognized code by its `severity` and `actor`.
1038
+ */
1039
+ type SetupDiagnosticIssueCode = 'AGENT_PAUSED' | 'AGENT_FROZEN' | 'AGENT_UNAVAILABLE' | 'SDK_KEY_EXPIRED' | 'SDK_KEY_REVOKED' | 'SCOPE_MISSING' | 'NO_WALLET' | 'WALLET_PAUSED' | 'WALLET_UNAVAILABLE' | 'WALLET_VIEW_ONLY' | 'WALLET_UNFUNDED' | 'MAINNET_REQUIRES_PROD_AGENT' | 'LIVE_PAYMENTS_PAUSED' | 'LIVE_PAYMENTS_UNAVAILABLE' | 'EXTERNAL_SIGNER_REQUIRED' | 'SANDBOX_UNCLAIMED' | 'SANDBOX_EXPIRED' | (string & {});
1040
+ /** A next step: a documented command, an API call, or a dashboard page for an owner. */
1041
+ type SetupDiagnosticAction = {
1042
+ type: 'command';
1043
+ command: string;
1044
+ description: string;
1045
+ } | {
1046
+ type: 'api';
1047
+ method: 'GET' | 'POST' | 'PATCH';
1048
+ /** Relative to the Conto base URL. Segments in braces are placeholders. */
1049
+ href: string;
1050
+ credential: 'sdk_key' | 'sandbox_api_key' | 'organization_api_key';
1051
+ requiredScope: string | null;
1052
+ description: string;
1053
+ } | {
1054
+ type: 'owner_url';
1055
+ /** A dashboard page, relative to the Conto base URL. */
1056
+ url: string;
1057
+ description: string;
1058
+ };
1059
+ interface SetupDiagnosticIssue {
1060
+ code: SetupDiagnosticIssueCode;
1061
+ /** `error` blocks a capability of the resource. `info` explains how a path works. */
1062
+ severity: 'error' | 'warning' | 'info';
1063
+ /** Who can resolve it: the agent with its own credentials, or an owner. */
1064
+ actor: 'agent' | 'owner';
1065
+ resource: {
1066
+ type: 'agent' | 'wallet' | 'sdk_key' | 'organization';
1067
+ id: string | null;
1068
+ };
1069
+ message: string;
1070
+ /** The missing scope for SCOPE_MISSING, otherwise null. */
1071
+ requiredScope: string | null;
1072
+ actions: SetupDiagnosticAction[];
1073
+ }
1074
+ interface SetupWalletDiagnostics {
1075
+ walletId: string;
1076
+ /** `simulated` sandbox, `managed` by Conto, `external` signer, or `unknown`. */
1077
+ executionMode: 'simulated' | 'managed' | 'external' | 'unknown';
1078
+ network: 'testnet' | 'mainnet';
1079
+ /** `not_checked`: Conto does not read this wallet's balance. */
1080
+ funding: 'not_required' | 'funded' | 'unfunded' | 'not_checked';
1081
+ walletLimits: boolean;
1082
+ canRequest: SetupCapabilityState;
1083
+ canExecute: SetupCapabilityState;
1084
+ issueCodes: SetupDiagnosticIssueCode[];
1085
+ }
1086
+ interface SetupCardDiagnostics {
1087
+ availability: 'available' | 'unavailable';
1088
+ reason: 'sandbox_organization' | 'disabled' | 'plan' | null;
1089
+ assignedCards: number;
1090
+ activeAuthorizations: number;
1091
+ canUse: 'yes' | 'no';
1092
+ }
1093
+ /** Versioned setup diagnostics from `GET /api/sdk/setup`. */
1094
+ interface SetupDiagnostics {
1095
+ version: 'conto.setup-diagnostics.v1';
1096
+ environment: {
1097
+ kind: 'anonymous_sandbox' | 'claimed_sandbox' | 'account';
1098
+ settlement: 'simulated' | 'per_wallet';
1099
+ agentEnvironment: 'DEV' | 'STAGING' | 'PROD';
1100
+ sandboxExpiresAt: string | null;
1101
+ } | null;
1102
+ status: {
1103
+ authenticated: boolean;
1104
+ canRequest: SetupCapabilityState;
1105
+ canExecute: SetupCapabilityState;
1106
+ ownerActionRequired: boolean;
1107
+ };
1108
+ wallets: SetupWalletDiagnostics[];
1109
+ /** Test and live cards, reported apart from wallets. */
1110
+ connectedCards: {
1111
+ test: SetupCardDiagnostics;
1112
+ live: SetupCardDiagnostics;
1113
+ } | null;
1114
+ controls: {
1115
+ effectivePolicies: number;
1116
+ } | null;
1117
+ issues: SetupDiagnosticIssue[];
1118
+ }
1031
1119
  interface AgentSetupResult {
1032
1120
  agent: {
1033
1121
  id: string;
@@ -1078,6 +1166,11 @@ interface AgentSetupResult {
1078
1166
  totalVolume: number;
1079
1167
  }>;
1080
1168
  scopes: string[];
1169
+ /**
1170
+ * What this key can do and what needs an owner. Null when the server could
1171
+ * not compute it for this request. Absent from servers that predate it.
1172
+ */
1173
+ diagnostics?: SetupDiagnostics | null;
1081
1174
  }
1082
1175
  interface ExternalWalletApprovalInput {
1083
1176
  amount: number;
@@ -1649,6 +1742,13 @@ type BeginConnectedLinkExecutionInput = BeginCommerceExecutionCommonInput & {
1649
1742
  paymentMethodId: string;
1650
1743
  };
1651
1744
  type BeginCommerceExecutionInput = (BeginConnectedLinkExecutionInput & {
1745
+ executionMethod: 'LINK_PAY_TOKEN';
1746
+ /** A server-configured digital-goods profile and its checkout URL. */
1747
+ counterparty: {
1748
+ canonicalId: string;
1749
+ checkoutUrl: string;
1750
+ };
1751
+ }) | (BeginConnectedLinkExecutionInput & {
1652
1752
  /** Primary path: the server resolves the immutable Stripe seller profile. */
1653
1753
  executionMethod: 'STRIPE_PAYMENT_INTENT';
1654
1754
  counterparty: {
@@ -1692,6 +1792,66 @@ type BeginCommerceExecutionInput = (BeginConnectedLinkExecutionInput & {
1692
1792
  checkoutUrl: string;
1693
1793
  };
1694
1794
  });
1795
+ /** Configuration inspection only: no policy evaluation, credential retrieval, or purchase. */
1796
+ interface LinkSetupInput {
1797
+ connectionId?: string;
1798
+ paymentMethodId?: string;
1799
+ merchantId?: string;
1800
+ }
1801
+ interface LinkSetupCheck {
1802
+ code: string;
1803
+ status: 'PASS' | 'BLOCKED' | 'WARNING';
1804
+ actor: 'developer' | 'owner' | 'operator';
1805
+ message: string;
1806
+ }
1807
+ interface LinkSetupResult {
1808
+ version: 'conto.link-setup.v1';
1809
+ mode: 'LIVE' | 'SIMULATED';
1810
+ configurationStatus: 'CONFIGURED' | 'INCOMPLETE';
1811
+ checks: LinkSetupCheck[];
1812
+ missingScopes: string[];
1813
+ checkout?: {
1814
+ merchantId: string;
1815
+ origin: string;
1816
+ currency: 'USD';
1817
+ maxAmountMinor: number;
1818
+ };
1819
+ paymentAuthorization: 'NOT_EVALUATED';
1820
+ providerVerified: false;
1821
+ settlementVerified: false;
1822
+ }
1823
+ /** Reusable owner-provisioned identifiers. Per-purchase values can override these defaults. */
1824
+ interface LinkPaymentDefaults {
1825
+ connectionId: string;
1826
+ paymentMethodId: string;
1827
+ }
1828
+ /** Exact purchase facts for a configured USD digital-goods checkout. */
1829
+ interface LinkPaymentInput {
1830
+ /** Persist this key before calling pay; reuse it for this exact purchase across restarts. */
1831
+ idempotencyKey: string;
1832
+ connectionId?: string;
1833
+ paymentMethodId?: string;
1834
+ /** Canonical ID of a checkout profile already configured by the deployment operator. */
1835
+ merchantId: string;
1836
+ checkoutUrl: string;
1837
+ amountMinor: number;
1838
+ currency?: 'USD';
1839
+ purpose: string;
1840
+ category?: string;
1841
+ lineItems: CommerceLineItemInput[];
1842
+ /** Required when the final amount differs from the line-item sum. Include the exact total breakdown. */
1843
+ totals?: CommerceTotalInput[];
1844
+ }
1845
+ type LinkPaymentNextAction = 'APPROVE_IN_LINK' | 'WAIT' | 'RESUME' | 'RECONCILE' | 'NONE';
1846
+ /** Safe payment state; submission and completion are not proof of settlement. */
1847
+ interface LinkPaymentResult extends CommerceExecutionResult {
1848
+ executionId: string;
1849
+ status: CommerceExecutionStatus;
1850
+ nextAction: LinkPaymentNextAction;
1851
+ /** Present only while Link approval is needed. Show it to the account owner. */
1852
+ approvalUrl?: string;
1853
+ checkout?: ExecuteCommerceExecutionResult['checkout'];
1854
+ }
1695
1855
  type CommerceExecutionStatus = 'DRAFT' | 'ACTION_REQUIRED' | 'AUTHORIZING' | 'AWAITING_APPROVAL' | 'READY' | 'PROCESSING' | 'SETTLED' | 'COMPLETED' | 'DENIED' | 'CANCELLED' | 'FAILED' | 'RETURNED' | 'EXPIRED' | 'NEEDS_RECONCILIATION';
1696
1856
  type CommerceExecutionProvider = 'STABLECOIN' | 'TOKENIZED_CARD' | 'STRIPE_LINK';
1697
1857
  type CommerceExecutionChannel = 'BROWSER' | 'MERCHANT_API' | 'CREDENTIAL_BROKER' | 'BANK_API' | 'WALLET_SIGNER';
@@ -2220,7 +2380,14 @@ declare class ContoError extends Error {
2220
2380
  readonly actionUrl?: string;
2221
2381
  readonly fieldErrors?: ApiErrorMetadata['fieldErrors'];
2222
2382
  readonly reasons?: string[];
2223
- constructor(message: string, metadata: ApiErrorMetadata);
2383
+ readonly diagnostics?: SetupDiagnostics;
2384
+ constructor(message: string, metadata: ApiErrorMetadata, diagnostics?: unknown);
2385
+ }
2386
+ /** Execution was attempted. Inspect this existing execution before any further payment action. */
2387
+ declare class LinkPaymentExecutionError extends ContoError {
2388
+ readonly executionId: string;
2389
+ readonly nextAction: "RECONCILE";
2390
+ constructor(executionId: string, error: unknown);
2224
2391
  }
2225
2392
  /**
2226
2393
  * The customer executor returned a receipt, but Conto did not acknowledge the
@@ -2259,6 +2426,7 @@ declare class Conto {
2259
2426
  #private;
2260
2427
  private baseUrl;
2261
2428
  private timeout;
2429
+ link: LinkClient;
2262
2430
  payments: PaymentsClient;
2263
2431
  cards: CardsClient;
2264
2432
  connectedCards: ConnectedCardsClient;
@@ -2271,7 +2439,11 @@ declare class Conto {
2271
2439
  * explicitly bound to this agent. No Link token or payment artifact is
2272
2440
  * returned through the agent SDK.
2273
2441
  */
2274
- listStripeLinkPaymentMethods(connectionId: string): Promise<ListStripeLinkPaymentMethodsResult>;
2442
+ listStripeLinkPaymentMethods(connectionId: string, options?: {
2443
+ mode?: 'TEST' | 'LIVE';
2444
+ }): Promise<ListStripeLinkPaymentMethodsResult>;
2445
+ /** Read live Link configuration diagnostics without retrieving credentials or authorizing payment. */
2446
+ getLinkSetup(input?: LinkSetupInput): Promise<LinkSetupResult>;
2275
2447
  /**
2276
2448
  * Normalize and durably revise a partial agent purchase proposal without
2277
2449
  * creating a payment side effect. Missing facts return as NEEDS_CONTEXT
@@ -2338,7 +2510,10 @@ declare class Conto {
2338
2510
  * reconciliation.
2339
2511
  */
2340
2512
  cancelCommerceExecution(executionId: string): Promise<CommerceExecutionResult>;
2341
- /** Read credentials, linked wallets, effective policies, and scopes without creating a payment. */
2513
+ /**
2514
+ * Read credentials, linked wallets, effective policies, scopes, and setup
2515
+ * diagnostics without creating a payment.
2516
+ */
2342
2517
  setup(): Promise<AgentSetupResult>;
2343
2518
  /** Make an authenticated request to the Conto API */
2344
2519
  request<T>(method: string, path: string, body?: Record<string, unknown>, options?: ContoRequestOptions): Promise<T>;
@@ -2608,4 +2783,34 @@ declare class MppClient {
2608
2783
  }): Promise<ProtocolServicesResult>;
2609
2784
  }
2610
2785
 
2611
- export { type AdminExternalCardOverlayEnforcement, type Agent, type AgentCheckoutAction, type AgentCheckoutActionKind, type AgentExternalCard, type AgentSetupResult, type AgentStatus, type AgentType, type AgentWalletLink, type ApprovedExternalCardExecution, type AssignExternalCardInput, type AssignedPolicy, type AuthorizeCheckoutActionResult, type BeginCommerceExecutionInput, type BrowserActionClaimResult, type BrowserActionDispatchObservationInput, BrowserActionFinalizationPendingError, type BrowserActionFinalizeResult, type BrowserCheckoutAction, type BrowserCheckoutTargetResolver, type BrowserCheckoutTargetSnapshot, type BrowserCheckoutTargetVerificationCode, BrowserCheckoutTargetVerificationError, type CanonicalBrowserCheckoutTargetSnapshot, CardsClient, type ChainType, type CheckoutActionAuthorization, type CommerceCheckoutMethod, type CommerceContextRequirement, type CommerceExecution, type CommerceExecutionAdapterKind, type CommerceExecutionArtifactKind, type CommerceExecutionChannel, type CommerceExecutionConstraint, type CommerceExecutionConstraintCoverage, type CommerceExecutionConstraintCoverageLevel, type CommerceExecutionDeliveryMode, type CommerceExecutionEvidence, type CommerceExecutionProvider, type CommerceExecutionResult, type CommerceExecutionSourceKind, type CommerceExecutionStatus, type CommerceFactConfidence, type CommerceFactProvenanceInput, type CommerceFactSource, type CommerceFulfillmentInput, type CommerceLineItemInput, type CommerceProposalFactKey, type CommerceProposalMissingFact, type CommerceProposalResolution, type CommerceProposalState, type CommerceSettlementRail, type CommerceTotalInput, type CommerceTotalType, type ComparePolicyVersionsResponse, type ConnectedCardBrief, type ConnectedCardCredential, type ConnectedCardDrawInput, type ConnectedCardDrawMerchant, type ConnectedCardDrawResult, type ConnectedCardDrawable, type ConnectedCardListResult, type ConnectedCardMandate, type ConnectedCardMandateMerchant, type ConnectedCardReference, ConnectedCardsClient, Conto, ContoAdmin, type ContoAdminConfig, ContoAdminError, type ContoConfig, ContoError, type ContoRequestOptions, type ControlledExternalCardPaymentResult, ControlledExternalCardPaymentTool, type CreateAgentInput, type CreatePolicyInput, type CreatePolicyRuleInput, type CreateSdkKeyInput, type CreateSdkKeyResult, type CreateWalletInput, type CustodyType, type CustomerCustodyMode, type CustomerWalletControlModel, type CustomerWalletKeyAccess, type DelegationType, type ExecuteCommerceExecutionResult, type ExternalCard, type ExternalCardApprovalInput, type ExternalCardApprovalResult, type ExternalCardConfirmationInput, ExternalCardConfirmationPendingError, type ExternalCardConfirmationResult, type ExternalCardExecutionClaimResult, type ExternalCardExecutionResult, type ExternalCardExecutor, type ExternalCardOverlayEnforcement, type ExternalCardRequestStatusResult, type ExternalWalletApprovalInput, type ExternalWalletApprovalResult, type ExternalWalletConfirmationInput, type ExternalWalletConfirmationResult, type FreezeAgentInput, Conto as Giro, type ContoConfig as GiroConfig, ContoError as GiroError, type GuardCheckoutResult, type GuardedBrowserDispatchResult, type GuardedCheckoutInput, type LinkWalletInput, type ListAgentsParams, type ListAgentsResponse, type ListPoliciesParams, type ListPoliciesResponse, type ListPolicyVersionsResponse, type ListStripeLinkPaymentMethodsResult, type ListWalletsParams, type ListWalletsResponse, type MppBudgetResult, type MppPreAuthorizeInput, type MppPreAuthorizeResult, type MppRecordInput, type MppRecordResult, type NormalizeCommerceProposalInput, type OrganizationMember, type PaginatedResponse, type PaginationParams, type PauseExternalCardAssignmentResult, type PaymentExecuteResult, type PaymentRequestInput, type PaymentRequestResult, type PaymentStatusResult, type Policy, type PolicyRule, type PolicyType, type PolicyVersionChangeType, type PolicyVersionDetail, type PolicyVersionDiff, type PolicyVersionFieldChange, type PolicyVersionSnapshot, type PolicyVersionSnapshotRule, type PolicyVersionSummary, type PrivilegedBrowserCheckoutDriver, type ProtocolBudgetResult, type ProtocolPreAuthorizeResult, type ProtocolRecordGrant, type ProtocolRecordGrantResult, type ProtocolServiceSummary, type ProtocolServicesResult, type ProvisionWalletResult, type RefreshBalanceResult, type RegisterExternalCardInput, type RollbackPolicyVersionResponse, type RuleAction, type RuleOperator, type RuleType, type RunGuardedCheckoutResult, type SdkKey, type SdkKeyType, type StripeLinkCheckoutReadiness, type StripeLinkCheckoutReadinessResult, type StripeLinkCheckoutReadinessStatus, type StripeLinkCheckoutVerification, type StripeLinkPaymentMethod, type TestCardCredential, type TestCardDrawResult, type TestCardDrawable, type TestCardListResult, type TestCardReceipt, TestCardsClient, type TestCheckoutInput, type TestCheckoutResult, type TestMerchant, type TestMerchantProduct, type UnfreezeAgentInput, type UpdateAgentInput, type UpdateExternalCardAssignmentInput, type UpdatePolicyInput, type UpdatePolicyRuleInput, type UpdateWalletInput, type VerifiedBrowserCheckoutTarget, type Wallet, type WalletChainBalanceSnapshot, type WalletStatus, type WalletType, type X402Authorization, type X402BudgetResult, type X402PayInput, type X402PayResult, type X402PaymentRequirements, type X402PreAuthorizeInput, type X402PreAuthorizeResult, type X402RecordInput, type X402RecordResult, canonicalizeBrowserCheckoutTarget, createVerifiedBrowserCheckoutDriver, Conto as default, fingerprintBrowserCheckoutTarget };
2786
+ /** Narrow transport contract used by the isolated, credential-free test client. */
2787
+ type LinkCommerceClient = Pick<Conto, 'getLinkSetup' | 'listStripeLinkPaymentMethods' | 'beginCommerceExecution' | 'getCommerceExecution' | 'refreshCommerceExecution' | 'executeCommerceExecution' | 'cancelCommerceExecution'>;
2788
+ /** High-level client for the configured Link Pay Token checkout pilot. */
2789
+ declare class LinkClient {
2790
+ #private;
2791
+ constructor(client: LinkCommerceClient, defaults?: LinkPaymentDefaults);
2792
+ /** Inspect the configured live path. This is not a payment authorization or provider connectivity test. */
2793
+ setup(input?: LinkSetupInput): Promise<LinkSetupResult>;
2794
+ /** Read masked LIVE funding sources; never selects a source or initiates payment. */
2795
+ paymentMethods(connectionId?: string): Promise<ListStripeLinkPaymentMethodsResult>;
2796
+ /**
2797
+ * Begin one exact intent and execute only if already READY. Otherwise return
2798
+ * the owner's approval action or existing state immediately, without polling.
2799
+ */
2800
+ pay(input: LinkPaymentInput): Promise<LinkPaymentResult>;
2801
+ /**
2802
+ * Continue the existing payment after approval. Reads before any mutation and
2803
+ * never submits an execution already processing or requiring reconciliation.
2804
+ */
2805
+ resume(executionId: string): Promise<LinkPaymentResult>;
2806
+ /** Observe and reconcile provider state. This method never submits a payment. */
2807
+ status(executionId: string): Promise<LinkPaymentResult>;
2808
+ /** Request cancellation of this existing Link payment; never retried automatically. */
2809
+ cancel(executionId: string): Promise<LinkPaymentResult>;
2810
+ private identifier;
2811
+ private assertLinkExecution;
2812
+ private executeIfReady;
2813
+ private result;
2814
+ }
2815
+
2816
+ export { type AdminExternalCardOverlayEnforcement, type Agent, type AgentCheckoutAction, type AgentCheckoutActionKind, type AgentExternalCard, type AgentSetupResult, type AgentStatus, type AgentType, type AgentWalletLink, type ApprovedExternalCardExecution, type AssignExternalCardInput, type AssignedPolicy, type AuthorizeCheckoutActionResult, type BeginCommerceExecutionInput, type BrowserActionClaimResult, type BrowserActionDispatchObservationInput, BrowserActionFinalizationPendingError, type BrowserActionFinalizeResult, type BrowserCheckoutAction, type BrowserCheckoutTargetResolver, type BrowserCheckoutTargetSnapshot, type BrowserCheckoutTargetVerificationCode, BrowserCheckoutTargetVerificationError, type CanonicalBrowserCheckoutTargetSnapshot, CardsClient, type ChainType, type CheckoutActionAuthorization, type CommerceCheckoutMethod, type CommerceContextRequirement, type CommerceExecution, type CommerceExecutionAdapterKind, type CommerceExecutionArtifactKind, type CommerceExecutionChannel, type CommerceExecutionConstraint, type CommerceExecutionConstraintCoverage, type CommerceExecutionConstraintCoverageLevel, type CommerceExecutionDeliveryMode, type CommerceExecutionEvidence, type CommerceExecutionProvider, type CommerceExecutionResult, type CommerceExecutionSourceKind, type CommerceExecutionStatus, type CommerceFactConfidence, type CommerceFactProvenanceInput, type CommerceFactSource, type CommerceFulfillmentInput, type CommerceLineItemInput, type CommerceProposalFactKey, type CommerceProposalMissingFact, type CommerceProposalResolution, type CommerceProposalState, type CommerceSettlementRail, type CommerceTotalInput, type CommerceTotalType, type ComparePolicyVersionsResponse, type ConnectedCardBrief, type ConnectedCardCredential, type ConnectedCardDrawInput, type ConnectedCardDrawMerchant, type ConnectedCardDrawResult, type ConnectedCardDrawable, type ConnectedCardListResult, type ConnectedCardMandate, type ConnectedCardMandateMerchant, type ConnectedCardReference, ConnectedCardsClient, Conto, ContoAdmin, type ContoAdminConfig, ContoAdminError, type ContoConfig, ContoError, type ContoRequestOptions, type ControlledExternalCardPaymentResult, ControlledExternalCardPaymentTool, type CreateAgentInput, type CreatePolicyInput, type CreatePolicyRuleInput, type CreateSdkKeyInput, type CreateSdkKeyResult, type CreateWalletInput, type CustodyType, type CustomerCustodyMode, type CustomerWalletControlModel, type CustomerWalletKeyAccess, type DelegationType, type ExecuteCommerceExecutionResult, type ExternalCard, type ExternalCardApprovalInput, type ExternalCardApprovalResult, type ExternalCardConfirmationInput, ExternalCardConfirmationPendingError, type ExternalCardConfirmationResult, type ExternalCardExecutionClaimResult, type ExternalCardExecutionResult, type ExternalCardExecutor, type ExternalCardOverlayEnforcement, type ExternalCardRequestStatusResult, type ExternalWalletApprovalInput, type ExternalWalletApprovalResult, type ExternalWalletConfirmationInput, type ExternalWalletConfirmationResult, type FreezeAgentInput, Conto as Giro, type ContoConfig as GiroConfig, ContoError as GiroError, type GuardCheckoutResult, type GuardedBrowserDispatchResult, type GuardedCheckoutInput, LinkClient, type LinkCommerceClient, type LinkPaymentDefaults, LinkPaymentExecutionError, type LinkPaymentInput, type LinkPaymentNextAction, type LinkPaymentResult, type LinkSetupCheck, type LinkSetupInput, type LinkSetupResult, type LinkWalletInput, type ListAgentsParams, type ListAgentsResponse, type ListPoliciesParams, type ListPoliciesResponse, type ListPolicyVersionsResponse, type ListStripeLinkPaymentMethodsResult, type ListWalletsParams, type ListWalletsResponse, type MppBudgetResult, type MppPreAuthorizeInput, type MppPreAuthorizeResult, type MppRecordInput, type MppRecordResult, type NormalizeCommerceProposalInput, type OrganizationMember, type PaginatedResponse, type PaginationParams, type PauseExternalCardAssignmentResult, type PaymentExecuteResult, type PaymentRequestInput, type PaymentRequestResult, type PaymentStatusResult, type Policy, type PolicyRule, type PolicyType, type PolicyVersionChangeType, type PolicyVersionDetail, type PolicyVersionDiff, type PolicyVersionFieldChange, type PolicyVersionSnapshot, type PolicyVersionSnapshotRule, type PolicyVersionSummary, type PrivilegedBrowserCheckoutDriver, type ProtocolBudgetResult, type ProtocolPreAuthorizeResult, type ProtocolRecordGrant, type ProtocolRecordGrantResult, type ProtocolServiceSummary, type ProtocolServicesResult, type ProvisionWalletResult, type RefreshBalanceResult, type RegisterExternalCardInput, type RollbackPolicyVersionResponse, type RuleAction, type RuleOperator, type RuleType, type RunGuardedCheckoutResult, type SdkKey, type SdkKeyType, type SetupCapabilityState, type SetupCardDiagnostics, type SetupDiagnosticAction, type SetupDiagnosticIssue, type SetupDiagnosticIssueCode, type SetupDiagnostics, type SetupWalletDiagnostics, type StripeLinkCheckoutReadiness, type StripeLinkCheckoutReadinessResult, type StripeLinkCheckoutReadinessStatus, type StripeLinkCheckoutVerification, type StripeLinkPaymentMethod, type TestCardCredential, type TestCardDrawResult, type TestCardDrawable, type TestCardListResult, type TestCardReceipt, TestCardsClient, type TestCheckoutInput, type TestCheckoutResult, type TestMerchant, type TestMerchantProduct, type UnfreezeAgentInput, type UpdateAgentInput, type UpdateExternalCardAssignmentInput, type UpdatePolicyInput, type UpdatePolicyRuleInput, type UpdateWalletInput, type VerifiedBrowserCheckoutTarget, type Wallet, type WalletChainBalanceSnapshot, type WalletStatus, type WalletType, type X402Authorization, type X402BudgetResult, type X402PayInput, type X402PayResult, type X402PaymentRequirements, type X402PreAuthorizeInput, type X402PreAuthorizeResult, type X402RecordInput, type X402RecordResult, canonicalizeBrowserCheckoutTarget, createVerifiedBrowserCheckoutDriver, Conto as default, fingerprintBrowserCheckoutTarget };
package/dist/index.js CHANGED
@@ -46,7 +46,7 @@ var require_package = __commonJS({
46
46
  "package.json"(exports2, module2) {
47
47
  module2.exports = {
48
48
  name: "@conto_finance/sdk",
49
- version: "0.5.4",
49
+ version: "0.6.0-beta.1",
50
50
  description: "Conto SDK for AI agent payment authorization",
51
51
  main: "./dist/index.js",
52
52
  module: "./dist/index.mjs",
@@ -71,10 +71,16 @@ var require_package = __commonJS({
71
71
  types: "./dist/checkout-verifier.d.ts",
72
72
  import: "./dist/checkout-verifier.mjs",
73
73
  require: "./dist/checkout-verifier.js"
74
+ },
75
+ "./link-testing": {
76
+ types: "./dist/link-testing.d.ts",
77
+ import: "./dist/link-testing.mjs",
78
+ require: "./dist/link-testing.js"
74
79
  }
75
80
  },
76
81
  publishConfig: {
77
- access: "public"
82
+ access: "public",
83
+ tag: "beta"
78
84
  },
79
85
  engines: {
80
86
  node: ">=20.19.0"
@@ -83,11 +89,11 @@ var require_package = __commonJS({
83
89
  "dist"
84
90
  ],
85
91
  scripts: {
86
- build: "tsup src/index.ts src/playwright.ts src/browserbase.ts src/checkout-verifier.ts --format cjs,esm --dts",
87
- dev: "tsup src/index.ts src/playwright.ts src/browserbase.ts src/checkout-verifier.ts --format cjs,esm --dts --watch",
92
+ build: "tsup",
93
+ dev: "tsup --watch",
88
94
  lint: "tsc --noEmit",
89
95
  test: "npm run lint && npm run test:contract && npm run test:consumer",
90
- "test:contract": "npm run build && node --test test/contract.test.mjs test/playwright.test.mjs test/browserbase.test.mjs test/checkout-verifier.test.mjs test/developer-experience.test.mjs",
96
+ "test:contract": "npm run build && node --test test/contract.test.mjs test/playwright.test.mjs test/browserbase.test.mjs test/checkout-verifier.test.mjs test/developer-experience.test.mjs test/link.test.mjs test/link-testing.test.mjs",
91
97
  "test:consumer": "npm run build && node --test test/consumer.test.mjs",
92
98
  "verify:release": "node scripts/verify-release.mjs",
93
99
  prepublishOnly: "npm run verify:release && npm run lint && npm run test:contract && npm run test:consumer"
@@ -161,6 +167,8 @@ __export(index_exports, {
161
167
  ControlledExternalCardPaymentTool: () => ControlledExternalCardPaymentTool,
162
168
  ExternalCardConfirmationPendingError: () => ExternalCardConfirmationPendingError,
163
169
  Giro: () => Conto,
170
+ LinkClient: () => LinkClient,
171
+ LinkPaymentExecutionError: () => LinkPaymentExecutionError,
164
172
  TestCardsClient: () => TestCardsClient,
165
173
  canonicalizeBrowserCheckoutTarget: () => canonicalizeBrowserCheckoutTarget,
166
174
  createVerifiedBrowserCheckoutDriver: () => createVerifiedBrowserCheckoutDriver,
@@ -1053,7 +1061,7 @@ function isValidBrowserActionObservation(value) {
1053
1061
  }
1054
1062
  }
1055
1063
  var ContoError = class extends Error {
1056
- constructor(message, metadata) {
1064
+ constructor(message, metadata, diagnostics) {
1057
1065
  super(message);
1058
1066
  this.name = "ContoError";
1059
1067
  this.code = metadata.code;
@@ -1064,6 +1072,30 @@ var ContoError = class extends Error {
1064
1072
  this.actionUrl = metadata.actionUrl;
1065
1073
  this.fieldErrors = metadata.fieldErrors;
1066
1074
  this.reasons = metadata.reasons;
1075
+ if (diagnostics !== null && typeof diagnostics === "object" && !Array.isArray(diagnostics) && "version" in diagnostics && diagnostics.version === "conto.setup-diagnostics.v1") {
1076
+ this.diagnostics = diagnostics;
1077
+ }
1078
+ }
1079
+ };
1080
+ var LinkPaymentExecutionError = class extends ContoError {
1081
+ constructor(executionId, error) {
1082
+ const original = error instanceof ContoError ? error : void 0;
1083
+ super(
1084
+ original?.message ?? "Link execution could not be confirmed",
1085
+ {
1086
+ code: original?.code ?? "LINK_EXECUTION_UNCONFIRMED",
1087
+ status: original?.status ?? 0,
1088
+ requestId: original?.requestId,
1089
+ retryAfter: original?.retryAfter,
1090
+ fieldErrors: original?.fieldErrors,
1091
+ reasons: original?.reasons,
1092
+ retryGuidance: "Call link.status(executionId) to reconcile. Do not create another purchase or retry execution blindly."
1093
+ },
1094
+ original?.diagnostics
1095
+ );
1096
+ this.nextAction = "RECONCILE";
1097
+ this.name = "LinkPaymentExecutionError";
1098
+ this.executionId = executionId;
1067
1099
  }
1068
1100
  };
1069
1101
  var ExternalCardConfirmationPendingError = class extends ContoError {
@@ -1155,6 +1187,7 @@ var Conto = class {
1155
1187
  this.baseUrl = (config.baseUrl || "https://conto.finance").replace(/\/$/, "");
1156
1188
  assertSecureBaseUrl(this.baseUrl);
1157
1189
  this.timeout = config.timeout || 3e4;
1190
+ this.link = new LinkClient(this, config.link);
1158
1191
  this.payments = new PaymentsClient(this);
1159
1192
  this.cards = new CardsClient(this);
1160
1193
  this.connectedCards = new ConnectedCardsClient(this);
@@ -1167,10 +1200,24 @@ var Conto = class {
1167
1200
  * explicitly bound to this agent. No Link token or payment artifact is
1168
1201
  * returned through the agent SDK.
1169
1202
  */
1170
- async listStripeLinkPaymentMethods(connectionId) {
1203
+ async listStripeLinkPaymentMethods(connectionId, options) {
1171
1204
  return this.request(
1172
1205
  "GET",
1173
- withQuery("/api/sdk/stripe-link/payment-methods", { connectionId })
1206
+ withQuery("/api/sdk/stripe-link/payment-methods", {
1207
+ connectionId,
1208
+ ...options?.mode ? { mode: options.mode } : {}
1209
+ })
1210
+ );
1211
+ }
1212
+ /** Read live Link configuration diagnostics without retrieving credentials or authorizing payment. */
1213
+ async getLinkSetup(input = {}) {
1214
+ return this.request(
1215
+ "GET",
1216
+ withQuery("/api/sdk/stripe-link/setup", {
1217
+ connectionId: input.connectionId,
1218
+ paymentMethodId: input.paymentMethodId,
1219
+ merchantId: input.merchantId
1220
+ })
1174
1221
  );
1175
1222
  }
1176
1223
  /**
@@ -1433,7 +1480,10 @@ var Conto = class {
1433
1480
  rethrowAmbiguousCommerceMutation(error, executionId, "cancel");
1434
1481
  }
1435
1482
  }
1436
- /** Read credentials, linked wallets, effective policies, and scopes without creating a payment. */
1483
+ /**
1484
+ * Read credentials, linked wallets, effective policies, scopes, and setup
1485
+ * diagnostics without creating a payment.
1486
+ */
1437
1487
  async setup() {
1438
1488
  return this.request("GET", "/api/sdk/setup");
1439
1489
  }
@@ -1463,7 +1513,8 @@ var Conto = class {
1463
1513
  if (!response.ok) {
1464
1514
  throw new ContoError(
1465
1515
  responseErrorMessage(data, response.status),
1466
- responseErrorMetadata(response, data)
1516
+ responseErrorMetadata(response, data),
1517
+ data !== null && typeof data === "object" && "diagnostics" in data ? data.diagnostics : void 0
1467
1518
  );
1468
1519
  }
1469
1520
  return data;
@@ -2096,6 +2147,176 @@ var MppClient = class {
2096
2147
  }
2097
2148
  };
2098
2149
  var index_default = Conto;
2150
+ var _client, _defaults;
2151
+ var LinkClient = class {
2152
+ constructor(client, defaults) {
2153
+ __privateAdd(this, _client);
2154
+ __privateAdd(this, _defaults);
2155
+ __privateSet(this, _client, client);
2156
+ __privateSet(this, _defaults, defaults ? { ...defaults } : void 0);
2157
+ }
2158
+ /** Inspect the configured live path. This is not a payment authorization or provider connectivity test. */
2159
+ async setup(input = {}) {
2160
+ return __privateGet(this, _client).getLinkSetup({
2161
+ connectionId: input.connectionId ?? __privateGet(this, _defaults)?.connectionId,
2162
+ paymentMethodId: input.paymentMethodId ?? __privateGet(this, _defaults)?.paymentMethodId,
2163
+ merchantId: input.merchantId
2164
+ });
2165
+ }
2166
+ /** Read masked LIVE funding sources; never selects a source or initiates payment. */
2167
+ async paymentMethods(connectionId) {
2168
+ return __privateGet(this, _client).listStripeLinkPaymentMethods(
2169
+ this.identifier(connectionId ?? __privateGet(this, _defaults)?.connectionId, "connectionId"),
2170
+ { mode: "LIVE" }
2171
+ );
2172
+ }
2173
+ /**
2174
+ * Begin one exact intent and execute only if already READY. Otherwise return
2175
+ * the owner's approval action or existing state immediately, without polling.
2176
+ */
2177
+ async pay(input) {
2178
+ const connectionId = this.identifier(
2179
+ input.connectionId ?? __privateGet(this, _defaults)?.connectionId,
2180
+ "connectionId"
2181
+ );
2182
+ const paymentMethodId = this.identifier(
2183
+ input.paymentMethodId ?? __privateGet(this, _defaults)?.paymentMethodId,
2184
+ "paymentMethodId"
2185
+ );
2186
+ if (!Number.isSafeInteger(input.amountMinor) || input.amountMinor <= 0 || input.currency !== void 0 && input.currency !== "USD" || !Array.isArray(input.lineItems) || input.lineItems.length === 0 || typeof input.purpose !== "string" || !input.purpose.trim()) {
2187
+ throw new ContoError("Supply a positive USD amount in cents, purpose, and line items", {
2188
+ code: "INVALID_LINK_PURCHASE",
2189
+ status: 0
2190
+ });
2191
+ }
2192
+ const itemTotal = input.lineItems.reduce((sum, item) => {
2193
+ if (!item || typeof item.name !== "string" || !item.name.trim() || !Number.isSafeInteger(item.quantity) || item.quantity <= 0 || !Number.isSafeInteger(item.unitAmountMinor) || item.unitAmountMinor < 0) {
2194
+ throw new ContoError(
2195
+ "Each line item needs a name, positive integer quantity, and price in cents",
2196
+ {
2197
+ code: "INVALID_LINK_PURCHASE",
2198
+ status: 0
2199
+ }
2200
+ );
2201
+ }
2202
+ return sum + item.quantity * item.unitAmountMinor;
2203
+ }, 0);
2204
+ if (!input.totals && (!Number.isSafeInteger(itemTotal) || itemTotal !== input.amountMinor)) {
2205
+ throw new ContoError(
2206
+ "Supply the exact totals breakdown when the amount differs from the line items",
2207
+ {
2208
+ code: "LINK_TOTALS_REQUIRED",
2209
+ status: 0
2210
+ }
2211
+ );
2212
+ }
2213
+ const result = await __privateGet(this, _client).beginCommerceExecution({
2214
+ executionMethod: "LINK_PAY_TOKEN",
2215
+ connectionId,
2216
+ paymentMethodId,
2217
+ idempotencyKey: input.idempotencyKey,
2218
+ amountMinor: input.amountMinor,
2219
+ currency: input.currency ?? "USD",
2220
+ purpose: input.purpose,
2221
+ category: input.category,
2222
+ counterparty: { canonicalId: input.merchantId, checkoutUrl: input.checkoutUrl },
2223
+ cart: {
2224
+ lineItems: input.lineItems,
2225
+ totals: input.totals ?? [{ type: "total", label: "Total", amountMinor: input.amountMinor }]
2226
+ },
2227
+ providerPresentation: {
2228
+ approvalSummary: input.purpose.trim().slice(0, 500),
2229
+ lineItemLabels: input.lineItems.map((item) => item.name.trim().slice(0, 120))
2230
+ }
2231
+ });
2232
+ return this.executeIfReady(result);
2233
+ }
2234
+ /**
2235
+ * Continue the existing payment after approval. Reads before any mutation and
2236
+ * never submits an execution already processing or requiring reconciliation.
2237
+ */
2238
+ async resume(executionId) {
2239
+ const id = this.identifier(executionId, "executionId");
2240
+ const current = await __privateGet(this, _client).getCommerceExecution(id);
2241
+ this.assertLinkExecution(current);
2242
+ if (["AUTHORIZING", "AWAITING_APPROVAL", "ACTION_REQUIRED"].includes(current.execution.status)) {
2243
+ return this.executeIfReady(await __privateGet(this, _client).refreshCommerceExecution(id));
2244
+ }
2245
+ return this.executeIfReady(current);
2246
+ }
2247
+ /** Observe and reconcile provider state. This method never submits a payment. */
2248
+ async status(executionId) {
2249
+ const id = this.identifier(executionId, "executionId");
2250
+ this.assertLinkExecution(await __privateGet(this, _client).getCommerceExecution(id));
2251
+ return this.result(await __privateGet(this, _client).refreshCommerceExecution(id));
2252
+ }
2253
+ /** Request cancellation of this existing Link payment; never retried automatically. */
2254
+ async cancel(executionId) {
2255
+ const id = this.identifier(executionId, "executionId");
2256
+ this.assertLinkExecution(await __privateGet(this, _client).getCommerceExecution(id));
2257
+ try {
2258
+ return this.result(await __privateGet(this, _client).cancelCommerceExecution(id));
2259
+ } catch (error) {
2260
+ throw new LinkPaymentExecutionError(id, error);
2261
+ }
2262
+ }
2263
+ identifier(value, field) {
2264
+ if (typeof value !== "string" || !value.trim() || value.length > 255) {
2265
+ throw new ContoError(
2266
+ field === "executionId" ? "executionId is required; use the existing ID returned by link.pay()" : `${field} is required; configure the owner-provisioned Link IDs or supply them explicitly`,
2267
+ {
2268
+ code: "LINK_CONFIGURATION_REQUIRED",
2269
+ status: 0
2270
+ }
2271
+ );
2272
+ }
2273
+ return value.trim();
2274
+ }
2275
+ assertLinkExecution(result) {
2276
+ const execution = result.execution;
2277
+ if (execution?.provider !== "STRIPE_LINK" || execution.executionAdapter !== "STRIPE_LINK" || execution.executionChannel !== "BROWSER" || execution.artifactKind !== void 0 && execution.artifactKind !== "LINK_PAY_TOKEN" || execution.deliveryMode !== void 0 && execution.deliveryMode !== "SERVER_ONLY_ARTIFACT") {
2278
+ throw new ContoError("This execution is not a Link Pay Token checkout", {
2279
+ code: "LINK_EXECUTION_MISMATCH",
2280
+ status: 0
2281
+ });
2282
+ }
2283
+ }
2284
+ async executeIfReady(result) {
2285
+ this.assertLinkExecution(result);
2286
+ if (result.execution.status !== "READY") return this.result(result);
2287
+ try {
2288
+ return this.result(await __privateGet(this, _client).executeCommerceExecution(result.execution.id));
2289
+ } catch (error) {
2290
+ throw new LinkPaymentExecutionError(result.execution.id, error);
2291
+ }
2292
+ }
2293
+ result(result) {
2294
+ this.assertLinkExecution(result);
2295
+ const { execution } = result;
2296
+ const awaitingApproval = ["AUTHORIZING", "AWAITING_APPROVAL", "ACTION_REQUIRED"].includes(
2297
+ execution.status
2298
+ );
2299
+ const nextAction = execution.status === "READY" ? "RESUME" : execution.status === "NEEDS_RECONCILIATION" ? "RECONCILE" : awaitingApproval && execution.approvalUrl ? "APPROVE_IN_LINK" : awaitingApproval || ["DRAFT", "PROCESSING"].includes(execution.status) ? "WAIT" : [
2300
+ "SETTLED",
2301
+ "COMPLETED",
2302
+ "DENIED",
2303
+ "CANCELLED",
2304
+ "FAILED",
2305
+ "RETURNED",
2306
+ "EXPIRED"
2307
+ ].includes(execution.status) ? "NONE" : "RECONCILE";
2308
+ return {
2309
+ executionId: execution.id,
2310
+ status: execution.status,
2311
+ nextAction,
2312
+ ...nextAction === "APPROVE_IN_LINK" ? { approvalUrl: execution.approvalUrl } : {},
2313
+ execution,
2314
+ ..."checkout" in result ? { checkout: result.checkout } : {}
2315
+ };
2316
+ }
2317
+ };
2318
+ _client = new WeakMap();
2319
+ _defaults = new WeakMap();
2099
2320
  // Annotate the CommonJS export names for ESM import in node:
2100
2321
  0 && (module.exports = {
2101
2322
  BrowserActionFinalizationPendingError,
@@ -2109,6 +2330,8 @@ var index_default = Conto;
2109
2330
  ControlledExternalCardPaymentTool,
2110
2331
  ExternalCardConfirmationPendingError,
2111
2332
  Giro,
2333
+ LinkClient,
2334
+ LinkPaymentExecutionError,
2112
2335
  TestCardsClient,
2113
2336
  canonicalizeBrowserCheckoutTarget,
2114
2337
  createVerifiedBrowserCheckoutDriver,