@conto_finance/sdk 0.5.3 → 0.5.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.
@@ -69,6 +69,7 @@ interface BrowserbaseGuardedPlaywrightCheckoutRuntimeHostConfig {
69
69
  maxSessions?: number;
70
70
  targetStore: EncryptedPlaywrightCheckoutTargetStoreConfig;
71
71
  dispatchAttemptFor: GuardedPlaywrightCheckoutRuntimeConfig['dispatchAttemptFor'];
72
+ claimDispatchAttempt?: GuardedPlaywrightCheckoutRuntimeConfig['claimDispatchAttempt'];
72
73
  /** Dedicated service credential. Conto and Browserbase API keys are rejected. */
73
74
  token: string;
74
75
  maxBodyBytes?: number;
@@ -69,6 +69,7 @@ interface BrowserbaseGuardedPlaywrightCheckoutRuntimeHostConfig {
69
69
  maxSessions?: number;
70
70
  targetStore: EncryptedPlaywrightCheckoutTargetStoreConfig;
71
71
  dispatchAttemptFor: GuardedPlaywrightCheckoutRuntimeConfig['dispatchAttemptFor'];
72
+ claimDispatchAttempt?: GuardedPlaywrightCheckoutRuntimeConfig['claimDispatchAttempt'];
72
73
  /** Dedicated service credential. Conto and Browserbase API keys are rejected. */
73
74
  token: string;
74
75
  maxBodyBytes?: number;
@@ -585,6 +585,12 @@ function createGuardedPlaywrightCheckoutRuntime(config) {
585
585
  "dispatchAttemptId",
586
586
  255
587
587
  );
588
+ if (config.claimDispatchAttempt && !await config.claimDispatchAttempt(dispatchAttemptId)) {
589
+ throw Object.assign(
590
+ new Error("This dispatch attempt has already started. Reconcile before another action."),
591
+ { code: "CONFLICT", status: 409 }
592
+ );
593
+ }
588
594
  return config.conto.runGuardedCheckoutWithDriver(input, {
589
595
  dispatchAttemptId,
590
596
  driver: adapter.driver
@@ -919,6 +925,7 @@ function createGuardedPlaywrightCheckoutRuntimeHost(config) {
919
925
  pageForSession: browserSessions.pageForSession,
920
926
  targetStore,
921
927
  dispatchAttemptFor: config.dispatchAttemptFor,
928
+ claimDispatchAttempt: config.claimDispatchAttempt,
922
929
  clickTimeoutMs: config.clickTimeoutMs,
923
930
  popupTimeoutMs: config.popupTimeoutMs,
924
931
  targetTtlMs: config.targetTtlMs,
@@ -1242,7 +1249,7 @@ function safeRuntimeError(error) {
1242
1249
  return httpJson(error.status, { code: error.code });
1243
1250
  }
1244
1251
  const record = error && typeof error === "object" ? error : void 0;
1245
- const candidateCode = record?.code;
1252
+ const candidateCode = record?.code === "POLICY_VIOLATION" ? "POLICY_DENIED" : record?.code === "APPROVAL_REQUIRED" ? "REQUIRES_APPROVAL" : record?.code;
1246
1253
  const code = typeof candidateCode === "string" && SAFE_RUNTIME_ERROR_CODES.has(candidateCode) ? candidateCode : "SERVER_ERROR";
1247
1254
  let status = typeof record?.status === "number" ? record.status : code.startsWith("BROWSER_") ? 409 : 500;
1248
1255
  if (!Number.isInteger(status) || status < 400 || status > 599) status = 409;
@@ -1928,6 +1935,7 @@ function createBrowserbaseGuardedPlaywrightCheckoutRuntimeHost(config) {
1928
1935
  },
1929
1936
  targetStore: config.targetStore,
1930
1937
  dispatchAttemptFor: config.dispatchAttemptFor,
1938
+ claimDispatchAttempt: config.claimDispatchAttempt,
1931
1939
  token: config.token,
1932
1940
  maxBodyBytes: config.maxBodyBytes,
1933
1941
  clickTimeoutMs: config.clickTimeoutMs,
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  createGuardedPlaywrightCheckoutRuntimeHost
3
- } from "./chunk-HM4EG5MH.mjs";
3
+ } from "./chunk-VSIO6PYA.mjs";
4
4
  import "./chunk-O5RAAB2U.mjs";
5
- import "./chunk-B7F5QLE5.mjs";
5
+ import "./chunk-WSIKPUZJ.mjs";
6
6
 
7
7
  // src/browserbase.ts
8
8
  import { createHmac, timingSafeEqual } from "crypto";
@@ -551,6 +551,7 @@ function createBrowserbaseGuardedPlaywrightCheckoutRuntimeHost(config) {
551
551
  },
552
552
  targetStore: config.targetStore,
553
553
  dispatchAttemptFor: config.dispatchAttemptFor,
554
+ claimDispatchAttempt: config.claimDispatchAttempt,
554
555
  token: config.token,
555
556
  maxBodyBytes: config.maxBodyBytes,
556
557
  clickTimeoutMs: config.clickTimeoutMs,
@@ -1,4 +1,4 @@
1
- import "./chunk-B7F5QLE5.mjs";
1
+ import "./chunk-WSIKPUZJ.mjs";
2
2
 
3
3
  // src/checkout-verifier.ts
4
4
  import { createHash, randomUUID } from "crypto";
@@ -447,6 +447,12 @@ function createGuardedPlaywrightCheckoutRuntime(config) {
447
447
  "dispatchAttemptId",
448
448
  255
449
449
  );
450
+ if (config.claimDispatchAttempt && !await config.claimDispatchAttempt(dispatchAttemptId)) {
451
+ throw Object.assign(
452
+ new Error("This dispatch attempt has already started. Reconcile before another action."),
453
+ { code: "CONFLICT", status: 409 }
454
+ );
455
+ }
450
456
  return config.conto.runGuardedCheckoutWithDriver(input, {
451
457
  dispatchAttemptId,
452
458
  driver: adapter.driver
@@ -781,6 +787,7 @@ function createGuardedPlaywrightCheckoutRuntimeHost(config) {
781
787
  pageForSession: browserSessions.pageForSession,
782
788
  targetStore,
783
789
  dispatchAttemptFor: config.dispatchAttemptFor,
790
+ claimDispatchAttempt: config.claimDispatchAttempt,
784
791
  clickTimeoutMs: config.clickTimeoutMs,
785
792
  popupTimeoutMs: config.popupTimeoutMs,
786
793
  targetTtlMs: config.targetTtlMs,
@@ -1104,7 +1111,7 @@ function safeRuntimeError(error) {
1104
1111
  return httpJson(error.status, { code: error.code });
1105
1112
  }
1106
1113
  const record = error && typeof error === "object" ? error : void 0;
1107
- const candidateCode = record?.code;
1114
+ const candidateCode = record?.code === "POLICY_VIOLATION" ? "POLICY_DENIED" : record?.code === "APPROVAL_REQUIRED" ? "REQUIRES_APPROVAL" : record?.code;
1108
1115
  const code = typeof candidateCode === "string" && SAFE_RUNTIME_ERROR_CODES.has(candidateCode) ? candidateCode : "SERVER_ERROR";
1109
1116
  let status = typeof record?.status === "number" ? record.status : code.startsWith("BROWSER_") ? 409 : 500;
1110
1117
  if (!Number.isInteger(status) || status < 400 || status > 599) status = 409;
@@ -4,6 +4,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __getProtoOf = Object.getPrototypeOf;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __typeError = (msg) => {
8
+ throw TypeError(msg);
9
+ };
7
10
  var __commonJS = (cb, mod) => function __require() {
8
11
  try {
9
12
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
@@ -27,8 +30,15 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
30
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
28
31
  mod
29
32
  ));
33
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
34
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
35
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
36
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
30
37
 
31
38
  export {
32
39
  __commonJS,
33
- __toESM
40
+ __toESM,
41
+ __privateGet,
42
+ __privateAdd,
43
+ __privateSet
34
44
  };
package/dist/index.d.mts CHANGED
@@ -673,7 +673,7 @@ interface StripeLinkCheckoutReadinessResult {
673
673
  readonly readiness: StripeLinkCheckoutReadiness;
674
674
  }
675
675
  declare class ContoAdmin {
676
- private orgApiKey;
676
+ #private;
677
677
  private baseUrl;
678
678
  private timeout;
679
679
  agents: AgentsClient;
@@ -1486,6 +1486,90 @@ interface ConnectedCardListResult {
1486
1486
  /** Masked drawable cards and their active mandates. No PAN or provider token. */
1487
1487
  cards: ConnectedCardDrawable[];
1488
1488
  }
1489
+ /**
1490
+ * The opaque single-use token a test-card draw returns once. Not card data, and
1491
+ * accepted only by {@link TestCardsClient.checkout}. Handle it the way you would
1492
+ * a live credential: keep it out of logs, errors, and model context.
1493
+ */
1494
+ interface TestCardCredential {
1495
+ token: string;
1496
+ format: 'test_token';
1497
+ }
1498
+ interface TestCardDrawResult {
1499
+ environment: 'test';
1500
+ requestId: string;
1501
+ minted: boolean;
1502
+ replayed: boolean;
1503
+ decision: 'APPROVED' | 'DENIED' | 'REQUIRES_APPROVAL';
1504
+ reasons: string[];
1505
+ reconciliationRequired?: boolean;
1506
+ /** Present only on the response that issues it. A replay never returns it again. */
1507
+ testCredential?: TestCardCredential;
1508
+ credentialExpiresAt?: string;
1509
+ notice?: string;
1510
+ }
1511
+ interface TestMerchantProduct {
1512
+ sku: string;
1513
+ name: string;
1514
+ unitAmountMinor: number;
1515
+ }
1516
+ interface TestMerchant {
1517
+ key: string;
1518
+ name: string;
1519
+ categoryCode: string;
1520
+ countryCode: string;
1521
+ products: TestMerchantProduct[];
1522
+ }
1523
+ interface TestCardDrawable extends ConnectedCardDrawable {
1524
+ environment: 'test';
1525
+ label: string;
1526
+ }
1527
+ interface TestCardListResult {
1528
+ environment: 'test';
1529
+ cards: TestCardDrawable[];
1530
+ merchants: TestMerchant[];
1531
+ }
1532
+ interface TestCheckoutInput {
1533
+ requestId: string;
1534
+ /** The `testCredential.token` from the draw. */
1535
+ credential: string;
1536
+ /** Items from the test merchant's catalog. Omit to buy one line for the authorized amount. */
1537
+ items?: Array<{
1538
+ sku: string;
1539
+ quantity: number;
1540
+ }>;
1541
+ }
1542
+ interface TestCardReceipt {
1543
+ environment: 'test';
1544
+ simulated: true;
1545
+ settlementMode: 'test';
1546
+ notice: string;
1547
+ orderId: string;
1548
+ orderNumber: string;
1549
+ requestId: string;
1550
+ transactionId: string;
1551
+ agentId: string;
1552
+ cardId: string;
1553
+ merchant: {
1554
+ key: string;
1555
+ name: string;
1556
+ };
1557
+ items: Array<{
1558
+ sku: string;
1559
+ name: string;
1560
+ quantity: number;
1561
+ unitAmountMinor: number;
1562
+ amountMinor: number;
1563
+ }>;
1564
+ amountMinor: number;
1565
+ currency: string;
1566
+ createdAt: string;
1567
+ }
1568
+ interface TestCheckoutResult extends TestCardReceipt {
1569
+ /** True when this credential already completed this checkout. Nothing new was recorded. */
1570
+ replayed: boolean;
1571
+ status: 'COMPLETED';
1572
+ }
1489
1573
  interface StripeLinkPaymentMethod {
1490
1574
  id: string;
1491
1575
  type: string;
@@ -2023,6 +2107,12 @@ interface MppPreAuthorizeResult extends ProtocolPreAuthorizeResult {
2023
2107
  };
2024
2108
  }
2025
2109
  interface MppRecordInput extends ProtocolRecordGrant {
2110
+ /**
2111
+ * Amount the service charged. Must be positive, except `0` on a session's
2112
+ * closing record (`closeSession: true`) when the session charged nothing
2113
+ * more. That close needs `grantId` and `grantSignature` and takes no
2114
+ * `txHash`, `paymentReceipt`, or `batchItems`.
2115
+ */
2026
2116
  amount: number;
2027
2117
  currency?: string;
2028
2118
  recipientAddress: string;
@@ -2049,7 +2139,9 @@ interface MppRecordInput extends ProtocolRecordGrant {
2049
2139
  }>;
2050
2140
  /**
2051
2141
  * Send true on the final record of a session (`intent: 'session'`). Conto
2052
- * closes the session and releases the unused part of its grant.
2142
+ * closes the session and releases the unused part of its grant. Send it
2143
+ * with `amount: 0` when the session has nothing more to charge. Repeating
2144
+ * that close returns the same result.
2053
2145
  */
2054
2146
  closeSession?: boolean;
2055
2147
  }
@@ -2058,6 +2150,8 @@ interface MppRecordResult extends ProtocolRecordGrantResult {
2058
2150
  txHash?: string;
2059
2151
  explorerUrl?: string;
2060
2152
  sessionId?: string;
2153
+ /** True when a record with `amount: 0` closed the session. No transaction was recorded. */
2154
+ sessionClosed?: true;
2061
2155
  }
2062
2156
  interface ProtocolBudgetResult {
2063
2157
  spend: {
@@ -2162,12 +2256,13 @@ interface ContoRequestOptions {
2162
2256
  maxRetries?: number;
2163
2257
  }
2164
2258
  declare class Conto {
2165
- private apiKey;
2259
+ #private;
2166
2260
  private baseUrl;
2167
2261
  private timeout;
2168
2262
  payments: PaymentsClient;
2169
2263
  cards: CardsClient;
2170
2264
  connectedCards: ConnectedCardsClient;
2265
+ testCards: TestCardsClient;
2171
2266
  x402: X402Client;
2172
2267
  mpp: MppClient;
2173
2268
  constructor(config: ContoConfig);
@@ -2345,6 +2440,37 @@ declare class ConnectedCardsClient {
2345
2440
  }>;
2346
2441
  list(): Promise<ConnectedCardListResult>;
2347
2442
  }
2443
+ /**
2444
+ * Test cards: try card controls with simulated purchases. See the section
2445
+ * comment above {@link TestCardCredential}.
2446
+ */
2447
+ declare class TestCardsClient {
2448
+ private client;
2449
+ constructor(client: Conto);
2450
+ /** The agent's test cards and active test authorizations, plus the test merchants. */
2451
+ list(): Promise<TestCardListResult>;
2452
+ /**
2453
+ * Request a single-use test credential. Same rules as
2454
+ * {@link ConnectedCardsClient.draw}: one stable idempotency key per purchase,
2455
+ * no automatic transport retry, and after a human approves a review, resend
2456
+ * the identical request with the same key.
2457
+ */
2458
+ draw(input: ConnectedCardDrawInput): Promise<TestCardDrawResult>;
2459
+ /** Record receipt of a test credential. Not a checkout and not a payment. */
2460
+ acknowledgeDelivery(requestId: string): Promise<{
2461
+ environment: 'test';
2462
+ acknowledged: boolean;
2463
+ settlementVerified: false;
2464
+ }>;
2465
+ /**
2466
+ * Complete a simulated purchase at the Conto test merchant with the test
2467
+ * credential. Retrying with the same draw and credential returns the same
2468
+ * receipt with `replayed: true`, so this call is safe to retry.
2469
+ */
2470
+ checkout(input: TestCheckoutInput): Promise<TestCheckoutResult>;
2471
+ /** Read back one of this agent's simulated receipts. */
2472
+ receipt(orderId: string): Promise<TestCardReceipt>;
2473
+ }
2348
2474
  /** Client for payment operations */
2349
2475
  declare class PaymentsClient {
2350
2476
  private client;
@@ -2482,4 +2608,4 @@ declare class MppClient {
2482
2608
  }): Promise<ProtocolServicesResult>;
2483
2609
  }
2484
2610
 
2485
- 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 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 };
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 };
package/dist/index.d.ts CHANGED
@@ -673,7 +673,7 @@ interface StripeLinkCheckoutReadinessResult {
673
673
  readonly readiness: StripeLinkCheckoutReadiness;
674
674
  }
675
675
  declare class ContoAdmin {
676
- private orgApiKey;
676
+ #private;
677
677
  private baseUrl;
678
678
  private timeout;
679
679
  agents: AgentsClient;
@@ -1486,6 +1486,90 @@ interface ConnectedCardListResult {
1486
1486
  /** Masked drawable cards and their active mandates. No PAN or provider token. */
1487
1487
  cards: ConnectedCardDrawable[];
1488
1488
  }
1489
+ /**
1490
+ * The opaque single-use token a test-card draw returns once. Not card data, and
1491
+ * accepted only by {@link TestCardsClient.checkout}. Handle it the way you would
1492
+ * a live credential: keep it out of logs, errors, and model context.
1493
+ */
1494
+ interface TestCardCredential {
1495
+ token: string;
1496
+ format: 'test_token';
1497
+ }
1498
+ interface TestCardDrawResult {
1499
+ environment: 'test';
1500
+ requestId: string;
1501
+ minted: boolean;
1502
+ replayed: boolean;
1503
+ decision: 'APPROVED' | 'DENIED' | 'REQUIRES_APPROVAL';
1504
+ reasons: string[];
1505
+ reconciliationRequired?: boolean;
1506
+ /** Present only on the response that issues it. A replay never returns it again. */
1507
+ testCredential?: TestCardCredential;
1508
+ credentialExpiresAt?: string;
1509
+ notice?: string;
1510
+ }
1511
+ interface TestMerchantProduct {
1512
+ sku: string;
1513
+ name: string;
1514
+ unitAmountMinor: number;
1515
+ }
1516
+ interface TestMerchant {
1517
+ key: string;
1518
+ name: string;
1519
+ categoryCode: string;
1520
+ countryCode: string;
1521
+ products: TestMerchantProduct[];
1522
+ }
1523
+ interface TestCardDrawable extends ConnectedCardDrawable {
1524
+ environment: 'test';
1525
+ label: string;
1526
+ }
1527
+ interface TestCardListResult {
1528
+ environment: 'test';
1529
+ cards: TestCardDrawable[];
1530
+ merchants: TestMerchant[];
1531
+ }
1532
+ interface TestCheckoutInput {
1533
+ requestId: string;
1534
+ /** The `testCredential.token` from the draw. */
1535
+ credential: string;
1536
+ /** Items from the test merchant's catalog. Omit to buy one line for the authorized amount. */
1537
+ items?: Array<{
1538
+ sku: string;
1539
+ quantity: number;
1540
+ }>;
1541
+ }
1542
+ interface TestCardReceipt {
1543
+ environment: 'test';
1544
+ simulated: true;
1545
+ settlementMode: 'test';
1546
+ notice: string;
1547
+ orderId: string;
1548
+ orderNumber: string;
1549
+ requestId: string;
1550
+ transactionId: string;
1551
+ agentId: string;
1552
+ cardId: string;
1553
+ merchant: {
1554
+ key: string;
1555
+ name: string;
1556
+ };
1557
+ items: Array<{
1558
+ sku: string;
1559
+ name: string;
1560
+ quantity: number;
1561
+ unitAmountMinor: number;
1562
+ amountMinor: number;
1563
+ }>;
1564
+ amountMinor: number;
1565
+ currency: string;
1566
+ createdAt: string;
1567
+ }
1568
+ interface TestCheckoutResult extends TestCardReceipt {
1569
+ /** True when this credential already completed this checkout. Nothing new was recorded. */
1570
+ replayed: boolean;
1571
+ status: 'COMPLETED';
1572
+ }
1489
1573
  interface StripeLinkPaymentMethod {
1490
1574
  id: string;
1491
1575
  type: string;
@@ -2023,6 +2107,12 @@ interface MppPreAuthorizeResult extends ProtocolPreAuthorizeResult {
2023
2107
  };
2024
2108
  }
2025
2109
  interface MppRecordInput extends ProtocolRecordGrant {
2110
+ /**
2111
+ * Amount the service charged. Must be positive, except `0` on a session's
2112
+ * closing record (`closeSession: true`) when the session charged nothing
2113
+ * more. That close needs `grantId` and `grantSignature` and takes no
2114
+ * `txHash`, `paymentReceipt`, or `batchItems`.
2115
+ */
2026
2116
  amount: number;
2027
2117
  currency?: string;
2028
2118
  recipientAddress: string;
@@ -2049,7 +2139,9 @@ interface MppRecordInput extends ProtocolRecordGrant {
2049
2139
  }>;
2050
2140
  /**
2051
2141
  * Send true on the final record of a session (`intent: 'session'`). Conto
2052
- * closes the session and releases the unused part of its grant.
2142
+ * closes the session and releases the unused part of its grant. Send it
2143
+ * with `amount: 0` when the session has nothing more to charge. Repeating
2144
+ * that close returns the same result.
2053
2145
  */
2054
2146
  closeSession?: boolean;
2055
2147
  }
@@ -2058,6 +2150,8 @@ interface MppRecordResult extends ProtocolRecordGrantResult {
2058
2150
  txHash?: string;
2059
2151
  explorerUrl?: string;
2060
2152
  sessionId?: string;
2153
+ /** True when a record with `amount: 0` closed the session. No transaction was recorded. */
2154
+ sessionClosed?: true;
2061
2155
  }
2062
2156
  interface ProtocolBudgetResult {
2063
2157
  spend: {
@@ -2162,12 +2256,13 @@ interface ContoRequestOptions {
2162
2256
  maxRetries?: number;
2163
2257
  }
2164
2258
  declare class Conto {
2165
- private apiKey;
2259
+ #private;
2166
2260
  private baseUrl;
2167
2261
  private timeout;
2168
2262
  payments: PaymentsClient;
2169
2263
  cards: CardsClient;
2170
2264
  connectedCards: ConnectedCardsClient;
2265
+ testCards: TestCardsClient;
2171
2266
  x402: X402Client;
2172
2267
  mpp: MppClient;
2173
2268
  constructor(config: ContoConfig);
@@ -2345,6 +2440,37 @@ declare class ConnectedCardsClient {
2345
2440
  }>;
2346
2441
  list(): Promise<ConnectedCardListResult>;
2347
2442
  }
2443
+ /**
2444
+ * Test cards: try card controls with simulated purchases. See the section
2445
+ * comment above {@link TestCardCredential}.
2446
+ */
2447
+ declare class TestCardsClient {
2448
+ private client;
2449
+ constructor(client: Conto);
2450
+ /** The agent's test cards and active test authorizations, plus the test merchants. */
2451
+ list(): Promise<TestCardListResult>;
2452
+ /**
2453
+ * Request a single-use test credential. Same rules as
2454
+ * {@link ConnectedCardsClient.draw}: one stable idempotency key per purchase,
2455
+ * no automatic transport retry, and after a human approves a review, resend
2456
+ * the identical request with the same key.
2457
+ */
2458
+ draw(input: ConnectedCardDrawInput): Promise<TestCardDrawResult>;
2459
+ /** Record receipt of a test credential. Not a checkout and not a payment. */
2460
+ acknowledgeDelivery(requestId: string): Promise<{
2461
+ environment: 'test';
2462
+ acknowledged: boolean;
2463
+ settlementVerified: false;
2464
+ }>;
2465
+ /**
2466
+ * Complete a simulated purchase at the Conto test merchant with the test
2467
+ * credential. Retrying with the same draw and credential returns the same
2468
+ * receipt with `replayed: true`, so this call is safe to retry.
2469
+ */
2470
+ checkout(input: TestCheckoutInput): Promise<TestCheckoutResult>;
2471
+ /** Read back one of this agent's simulated receipts. */
2472
+ receipt(orderId: string): Promise<TestCardReceipt>;
2473
+ }
2348
2474
  /** Client for payment operations */
2349
2475
  declare class PaymentsClient {
2350
2476
  private client;
@@ -2482,4 +2608,4 @@ declare class MppClient {
2482
2608
  }): Promise<ProtocolServicesResult>;
2483
2609
  }
2484
2610
 
2485
- 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 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 };
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 };
package/dist/index.js CHANGED
@@ -5,6 +5,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __typeError = (msg) => {
9
+ throw TypeError(msg);
10
+ };
8
11
  var __commonJS = (cb, mod) => function __require() {
9
12
  try {
10
13
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
@@ -33,13 +36,17 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
33
36
  mod
34
37
  ));
35
38
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
39
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
40
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
41
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
42
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
36
43
 
37
44
  // package.json
38
45
  var require_package = __commonJS({
39
46
  "package.json"(exports2, module2) {
40
47
  module2.exports = {
41
48
  name: "@conto_finance/sdk",
42
- version: "0.5.3",
49
+ version: "0.5.4",
43
50
  description: "Conto SDK for AI agent payment authorization",
44
51
  main: "./dist/index.js",
45
52
  module: "./dist/index.mjs",
@@ -154,6 +161,7 @@ __export(index_exports, {
154
161
  ControlledExternalCardPaymentTool: () => ControlledExternalCardPaymentTool,
155
162
  ExternalCardConfirmationPendingError: () => ExternalCardConfirmationPendingError,
156
163
  Giro: () => Conto,
164
+ TestCardsClient: () => TestCardsClient,
157
165
  canonicalizeBrowserCheckoutTarget: () => canonicalizeBrowserCheckoutTarget,
158
166
  createVerifiedBrowserCheckoutDriver: () => createVerifiedBrowserCheckoutDriver,
159
167
  default: () => index_default,
@@ -511,8 +519,11 @@ var ContoAdminError = class extends Error {
511
519
  this.retryGuidance = metadata.retryGuidance;
512
520
  }
513
521
  };
522
+ var _orgApiKey;
514
523
  var ContoAdmin = class {
515
524
  constructor(config) {
525
+ // An ECMAScript private field, so logging or serializing a client never prints the key.
526
+ __privateAdd(this, _orgApiKey);
516
527
  if (!config.orgApiKey) {
517
528
  throw new Error("Organization API key is required");
518
529
  }
@@ -526,7 +537,7 @@ var ContoAdmin = class {
526
537
  "Invalid API key format. Expected organization API key starting with conto_xxx..."
527
538
  );
528
539
  }
529
- this.orgApiKey = config.orgApiKey;
540
+ __privateSet(this, _orgApiKey, config.orgApiKey);
530
541
  this.baseUrl = (config.baseUrl || "https://conto.finance").replace(/\/$/, "");
531
542
  assertSecureBaseUrl(this.baseUrl);
532
543
  this.timeout = config.timeout || 3e4;
@@ -550,7 +561,7 @@ var ContoAdmin = class {
550
561
  {
551
562
  method: normalizedMethod,
552
563
  headers: {
553
- Authorization: `Bearer ${this.orgApiKey}`,
564
+ Authorization: `Bearer ${__privateGet(this, _orgApiKey)}`,
554
565
  "Content-Type": "application/json",
555
566
  "User-Agent": `@conto_finance/sdk-admin/${import_package_version.SDK_PACKAGE_VERSION}`
556
567
  },
@@ -590,6 +601,7 @@ var ContoAdmin = class {
590
601
  }
591
602
  }
592
603
  };
604
+ _orgApiKey = new WeakMap();
593
605
  var PaymentRailsClient = class {
594
606
  constructor(client) {
595
607
  this.client = client;
@@ -1027,14 +1039,6 @@ var TeamClient = class {
1027
1039
  };
1028
1040
 
1029
1041
  // src/index.ts
1030
- if (process.env.SENTRY_DSN) {
1031
- Sentry2.init({
1032
- dsn: process.env.SENTRY_DSN,
1033
- environment: process.env.NODE_ENV || "production",
1034
- tracesSampleRate: 0.05,
1035
- enableLogs: true
1036
- });
1037
- }
1038
1042
  function isValidBrowserActionObservation(value) {
1039
1043
  if (!value || typeof value !== "object") return false;
1040
1044
  const observation = value;
@@ -1136,21 +1140,25 @@ function rethrowAmbiguousCommerceMutation(error, executionId, action) {
1136
1140
  }
1137
1141
  throw error;
1138
1142
  }
1143
+ var _apiKey;
1139
1144
  var Conto = class {
1140
1145
  constructor(config) {
1146
+ // An ECMAScript private field, so logging or serializing a client never prints the key.
1147
+ __privateAdd(this, _apiKey);
1141
1148
  if (!config.apiKey) {
1142
1149
  throw new Error("API key is required");
1143
1150
  }
1144
1151
  if (!config.apiKey.startsWith("conto_agent_")) {
1145
1152
  throw new Error("Invalid API key format. Expected conto_agent_xxx...");
1146
1153
  }
1147
- this.apiKey = config.apiKey;
1154
+ __privateSet(this, _apiKey, config.apiKey);
1148
1155
  this.baseUrl = (config.baseUrl || "https://conto.finance").replace(/\/$/, "");
1149
1156
  assertSecureBaseUrl(this.baseUrl);
1150
1157
  this.timeout = config.timeout || 3e4;
1151
1158
  this.payments = new PaymentsClient(this);
1152
1159
  this.cards = new CardsClient(this);
1153
1160
  this.connectedCards = new ConnectedCardsClient(this);
1161
+ this.testCards = new TestCardsClient(this);
1154
1162
  this.x402 = new X402Client(this);
1155
1163
  this.mpp = new MppClient(this);
1156
1164
  }
@@ -1442,7 +1450,7 @@ var Conto = class {
1442
1450
  {
1443
1451
  method: normalizedMethod,
1444
1452
  headers: {
1445
- Authorization: `Bearer ${this.apiKey}`,
1453
+ Authorization: `Bearer ${__privateGet(this, _apiKey)}`,
1446
1454
  "Content-Type": "application/json",
1447
1455
  "User-Agent": `@conto_finance/sdk/${import_package_version2.SDK_PACKAGE_VERSION}`
1448
1456
  },
@@ -1482,6 +1490,7 @@ var Conto = class {
1482
1490
  }
1483
1491
  }
1484
1492
  };
1493
+ _apiKey = new WeakMap();
1485
1494
  var CardsClient = class {
1486
1495
  constructor(client) {
1487
1496
  this.client = client;
@@ -1718,6 +1727,65 @@ var ConnectedCardsClient = class {
1718
1727
  return this.client.request("GET", "/api/sdk/connected-cards");
1719
1728
  }
1720
1729
  };
1730
+ var TestCardsClient = class {
1731
+ constructor(client) {
1732
+ this.client = client;
1733
+ }
1734
+ /** The agent's test cards and active test authorizations, plus the test merchants. */
1735
+ async list() {
1736
+ return this.client.request("GET", "/api/sdk/connected-cards/test");
1737
+ }
1738
+ /**
1739
+ * Request a single-use test credential. Same rules as
1740
+ * {@link ConnectedCardsClient.draw}: one stable idempotency key per purchase,
1741
+ * no automatic transport retry, and after a human approves a review, resend
1742
+ * the identical request with the same key.
1743
+ */
1744
+ async draw(input) {
1745
+ const idempotencyKey = input.idempotencyKey?.trim();
1746
+ if (!idempotencyKey || idempotencyKey.length < 8 || idempotencyKey.length > 128) {
1747
+ throw new ContoError("idempotencyKey must contain 8 to 128 characters", {
1748
+ code: "INVALID_IDEMPOTENCY_KEY",
1749
+ status: 0,
1750
+ retryGuidance: "Generate one stable identifier per purchase and reuse it only to resume the same purchase."
1751
+ });
1752
+ }
1753
+ return this.client.request("POST", "/api/sdk/connected-cards/test/draws", {
1754
+ ...input,
1755
+ idempotencyKey,
1756
+ currency: input.currency ?? "USD"
1757
+ });
1758
+ }
1759
+ /** Record receipt of a test credential. Not a checkout and not a payment. */
1760
+ async acknowledgeDelivery(requestId) {
1761
+ return this.client.request(
1762
+ "POST",
1763
+ `/api/sdk/connected-cards/test/draws/${encodeURIComponent(requestId)}/acknowledge`,
1764
+ {},
1765
+ { idempotent: true }
1766
+ );
1767
+ }
1768
+ /**
1769
+ * Complete a simulated purchase at the Conto test merchant with the test
1770
+ * credential. Retrying with the same draw and credential returns the same
1771
+ * receipt with `replayed: true`, so this call is safe to retry.
1772
+ */
1773
+ async checkout(input) {
1774
+ return this.client.request(
1775
+ "POST",
1776
+ "/api/sdk/connected-cards/test/checkout",
1777
+ { ...input },
1778
+ { idempotent: true }
1779
+ );
1780
+ }
1781
+ /** Read back one of this agent's simulated receipts. */
1782
+ async receipt(orderId) {
1783
+ return this.client.request(
1784
+ "GET",
1785
+ `/api/sdk/connected-cards/test/orders/${encodeURIComponent(orderId)}`
1786
+ );
1787
+ }
1788
+ };
1721
1789
  function approvalRetryGuidance(requestId) {
1722
1790
  const id = JSON.stringify(requestId);
1723
1791
  return `An approver in Conto executes the payment when they approve it. After approval, call payments.execute(${id}) or payments.status(${id}) to get the receipt. Do not request the payment again.`;
@@ -2041,6 +2109,7 @@ var index_default = Conto;
2041
2109
  ControlledExternalCardPaymentTool,
2042
2110
  ExternalCardConfirmationPendingError,
2043
2111
  Giro,
2112
+ TestCardsClient,
2044
2113
  canonicalizeBrowserCheckoutTarget,
2045
2114
  createVerifiedBrowserCheckoutDriver,
2046
2115
  fingerprintBrowserCheckoutTarget
package/dist/index.mjs CHANGED
@@ -6,15 +6,18 @@ import {
6
6
  } from "./chunk-O5RAAB2U.mjs";
7
7
  import {
8
8
  __commonJS,
9
+ __privateAdd,
10
+ __privateGet,
11
+ __privateSet,
9
12
  __toESM
10
- } from "./chunk-B7F5QLE5.mjs";
13
+ } from "./chunk-WSIKPUZJ.mjs";
11
14
 
12
15
  // package.json
13
16
  var require_package = __commonJS({
14
17
  "package.json"(exports, module) {
15
18
  module.exports = {
16
19
  name: "@conto_finance/sdk",
17
- version: "0.5.3",
20
+ version: "0.5.4",
18
21
  description: "Conto SDK for AI agent payment authorization",
19
22
  main: "./dist/index.js",
20
23
  module: "./dist/index.mjs",
@@ -350,8 +353,11 @@ var ContoAdminError = class extends Error {
350
353
  this.retryGuidance = metadata.retryGuidance;
351
354
  }
352
355
  };
356
+ var _orgApiKey;
353
357
  var ContoAdmin = class {
354
358
  constructor(config) {
359
+ // An ECMAScript private field, so logging or serializing a client never prints the key.
360
+ __privateAdd(this, _orgApiKey);
355
361
  if (!config.orgApiKey) {
356
362
  throw new Error("Organization API key is required");
357
363
  }
@@ -365,7 +371,7 @@ var ContoAdmin = class {
365
371
  "Invalid API key format. Expected organization API key starting with conto_xxx..."
366
372
  );
367
373
  }
368
- this.orgApiKey = config.orgApiKey;
374
+ __privateSet(this, _orgApiKey, config.orgApiKey);
369
375
  this.baseUrl = (config.baseUrl || "https://conto.finance").replace(/\/$/, "");
370
376
  assertSecureBaseUrl(this.baseUrl);
371
377
  this.timeout = config.timeout || 3e4;
@@ -389,7 +395,7 @@ var ContoAdmin = class {
389
395
  {
390
396
  method: normalizedMethod,
391
397
  headers: {
392
- Authorization: `Bearer ${this.orgApiKey}`,
398
+ Authorization: `Bearer ${__privateGet(this, _orgApiKey)}`,
393
399
  "Content-Type": "application/json",
394
400
  "User-Agent": `@conto_finance/sdk-admin/${import_package_version.SDK_PACKAGE_VERSION}`
395
401
  },
@@ -429,6 +435,7 @@ var ContoAdmin = class {
429
435
  }
430
436
  }
431
437
  };
438
+ _orgApiKey = new WeakMap();
432
439
  var PaymentRailsClient = class {
433
440
  constructor(client) {
434
441
  this.client = client;
@@ -866,14 +873,6 @@ var TeamClient = class {
866
873
  };
867
874
 
868
875
  // src/index.ts
869
- if (process.env.SENTRY_DSN) {
870
- Sentry2.init({
871
- dsn: process.env.SENTRY_DSN,
872
- environment: process.env.NODE_ENV || "production",
873
- tracesSampleRate: 0.05,
874
- enableLogs: true
875
- });
876
- }
877
876
  function isValidBrowserActionObservation(value) {
878
877
  if (!value || typeof value !== "object") return false;
879
878
  const observation = value;
@@ -975,21 +974,25 @@ function rethrowAmbiguousCommerceMutation(error, executionId, action) {
975
974
  }
976
975
  throw error;
977
976
  }
977
+ var _apiKey;
978
978
  var Conto = class {
979
979
  constructor(config) {
980
+ // An ECMAScript private field, so logging or serializing a client never prints the key.
981
+ __privateAdd(this, _apiKey);
980
982
  if (!config.apiKey) {
981
983
  throw new Error("API key is required");
982
984
  }
983
985
  if (!config.apiKey.startsWith("conto_agent_")) {
984
986
  throw new Error("Invalid API key format. Expected conto_agent_xxx...");
985
987
  }
986
- this.apiKey = config.apiKey;
988
+ __privateSet(this, _apiKey, config.apiKey);
987
989
  this.baseUrl = (config.baseUrl || "https://conto.finance").replace(/\/$/, "");
988
990
  assertSecureBaseUrl(this.baseUrl);
989
991
  this.timeout = config.timeout || 3e4;
990
992
  this.payments = new PaymentsClient(this);
991
993
  this.cards = new CardsClient(this);
992
994
  this.connectedCards = new ConnectedCardsClient(this);
995
+ this.testCards = new TestCardsClient(this);
993
996
  this.x402 = new X402Client(this);
994
997
  this.mpp = new MppClient(this);
995
998
  }
@@ -1281,7 +1284,7 @@ var Conto = class {
1281
1284
  {
1282
1285
  method: normalizedMethod,
1283
1286
  headers: {
1284
- Authorization: `Bearer ${this.apiKey}`,
1287
+ Authorization: `Bearer ${__privateGet(this, _apiKey)}`,
1285
1288
  "Content-Type": "application/json",
1286
1289
  "User-Agent": `@conto_finance/sdk/${import_package_version2.SDK_PACKAGE_VERSION}`
1287
1290
  },
@@ -1321,6 +1324,7 @@ var Conto = class {
1321
1324
  }
1322
1325
  }
1323
1326
  };
1327
+ _apiKey = new WeakMap();
1324
1328
  var CardsClient = class {
1325
1329
  constructor(client) {
1326
1330
  this.client = client;
@@ -1557,6 +1561,65 @@ var ConnectedCardsClient = class {
1557
1561
  return this.client.request("GET", "/api/sdk/connected-cards");
1558
1562
  }
1559
1563
  };
1564
+ var TestCardsClient = class {
1565
+ constructor(client) {
1566
+ this.client = client;
1567
+ }
1568
+ /** The agent's test cards and active test authorizations, plus the test merchants. */
1569
+ async list() {
1570
+ return this.client.request("GET", "/api/sdk/connected-cards/test");
1571
+ }
1572
+ /**
1573
+ * Request a single-use test credential. Same rules as
1574
+ * {@link ConnectedCardsClient.draw}: one stable idempotency key per purchase,
1575
+ * no automatic transport retry, and after a human approves a review, resend
1576
+ * the identical request with the same key.
1577
+ */
1578
+ async draw(input) {
1579
+ const idempotencyKey = input.idempotencyKey?.trim();
1580
+ if (!idempotencyKey || idempotencyKey.length < 8 || idempotencyKey.length > 128) {
1581
+ throw new ContoError("idempotencyKey must contain 8 to 128 characters", {
1582
+ code: "INVALID_IDEMPOTENCY_KEY",
1583
+ status: 0,
1584
+ retryGuidance: "Generate one stable identifier per purchase and reuse it only to resume the same purchase."
1585
+ });
1586
+ }
1587
+ return this.client.request("POST", "/api/sdk/connected-cards/test/draws", {
1588
+ ...input,
1589
+ idempotencyKey,
1590
+ currency: input.currency ?? "USD"
1591
+ });
1592
+ }
1593
+ /** Record receipt of a test credential. Not a checkout and not a payment. */
1594
+ async acknowledgeDelivery(requestId) {
1595
+ return this.client.request(
1596
+ "POST",
1597
+ `/api/sdk/connected-cards/test/draws/${encodeURIComponent(requestId)}/acknowledge`,
1598
+ {},
1599
+ { idempotent: true }
1600
+ );
1601
+ }
1602
+ /**
1603
+ * Complete a simulated purchase at the Conto test merchant with the test
1604
+ * credential. Retrying with the same draw and credential returns the same
1605
+ * receipt with `replayed: true`, so this call is safe to retry.
1606
+ */
1607
+ async checkout(input) {
1608
+ return this.client.request(
1609
+ "POST",
1610
+ "/api/sdk/connected-cards/test/checkout",
1611
+ { ...input },
1612
+ { idempotent: true }
1613
+ );
1614
+ }
1615
+ /** Read back one of this agent's simulated receipts. */
1616
+ async receipt(orderId) {
1617
+ return this.client.request(
1618
+ "GET",
1619
+ `/api/sdk/connected-cards/test/orders/${encodeURIComponent(orderId)}`
1620
+ );
1621
+ }
1622
+ };
1560
1623
  function approvalRetryGuidance(requestId) {
1561
1624
  const id = JSON.stringify(requestId);
1562
1625
  return `An approver in Conto executes the payment when they approve it. After approval, call payments.execute(${id}) or payments.status(${id}) to get the receipt. Do not request the payment again.`;
@@ -1879,6 +1942,7 @@ export {
1879
1942
  ControlledExternalCardPaymentTool,
1880
1943
  ExternalCardConfirmationPendingError,
1881
1944
  Conto as Giro,
1945
+ TestCardsClient,
1882
1946
  canonicalizeBrowserCheckoutTarget,
1883
1947
  createVerifiedBrowserCheckoutDriver,
1884
1948
  index_default as default,
@@ -91,6 +91,8 @@ interface GuardedPlaywrightCheckoutRuntimeConfig extends PlaywrightCheckoutAdapt
91
91
  browserSessionId: string;
92
92
  targetFingerprint: string;
93
93
  }): Promise<string>;
94
+ /** Atomically starts an attempt once across runtime instances. Never release after a failure. */
95
+ claimDispatchAttempt?(dispatchAttemptId: string): Promise<boolean>;
94
96
  }
95
97
  /**
96
98
  * Safe façade to expose as the agent's checkout capability. It intentionally
@@ -191,6 +193,7 @@ interface GuardedPlaywrightCheckoutRuntimeHostConfig {
191
193
  targetStore: EncryptedPlaywrightCheckoutTargetStoreConfig;
192
194
  /** Atomically loads or creates one stable attempt for the checkout intent. */
193
195
  dispatchAttemptFor: GuardedPlaywrightCheckoutRuntimeConfig['dispatchAttemptFor'];
196
+ claimDispatchAttempt?: GuardedPlaywrightCheckoutRuntimeConfig['claimDispatchAttempt'];
194
197
  /** Dedicated service credential. Conto API keys are rejected. */
195
198
  token: string;
196
199
  maxBodyBytes?: number;
@@ -91,6 +91,8 @@ interface GuardedPlaywrightCheckoutRuntimeConfig extends PlaywrightCheckoutAdapt
91
91
  browserSessionId: string;
92
92
  targetFingerprint: string;
93
93
  }): Promise<string>;
94
+ /** Atomically starts an attempt once across runtime instances. Never release after a failure. */
95
+ claimDispatchAttempt?(dispatchAttemptId: string): Promise<boolean>;
94
96
  }
95
97
  /**
96
98
  * Safe façade to expose as the agent's checkout capability. It intentionally
@@ -191,6 +193,7 @@ interface GuardedPlaywrightCheckoutRuntimeHostConfig {
191
193
  targetStore: EncryptedPlaywrightCheckoutTargetStoreConfig;
192
194
  /** Atomically loads or creates one stable attempt for the checkout intent. */
193
195
  dispatchAttemptFor: GuardedPlaywrightCheckoutRuntimeConfig['dispatchAttemptFor'];
196
+ claimDispatchAttempt?: GuardedPlaywrightCheckoutRuntimeConfig['claimDispatchAttempt'];
194
197
  /** Dedicated service credential. Conto API keys are rejected. */
195
198
  token: string;
196
199
  maxBodyBytes?: number;
@@ -585,6 +585,12 @@ function createGuardedPlaywrightCheckoutRuntime(config) {
585
585
  "dispatchAttemptId",
586
586
  255
587
587
  );
588
+ if (config.claimDispatchAttempt && !await config.claimDispatchAttempt(dispatchAttemptId)) {
589
+ throw Object.assign(
590
+ new Error("This dispatch attempt has already started. Reconcile before another action."),
591
+ { code: "CONFLICT", status: 409 }
592
+ );
593
+ }
588
594
  return config.conto.runGuardedCheckoutWithDriver(input, {
589
595
  dispatchAttemptId,
590
596
  driver: adapter.driver
@@ -919,6 +925,7 @@ function createGuardedPlaywrightCheckoutRuntimeHost(config) {
919
925
  pageForSession: browserSessions.pageForSession,
920
926
  targetStore,
921
927
  dispatchAttemptFor: config.dispatchAttemptFor,
928
+ claimDispatchAttempt: config.claimDispatchAttempt,
922
929
  clickTimeoutMs: config.clickTimeoutMs,
923
930
  popupTimeoutMs: config.popupTimeoutMs,
924
931
  targetTtlMs: config.targetTtlMs,
@@ -1242,7 +1249,7 @@ function safeRuntimeError(error) {
1242
1249
  return httpJson(error.status, { code: error.code });
1243
1250
  }
1244
1251
  const record = error && typeof error === "object" ? error : void 0;
1245
- const candidateCode = record?.code;
1252
+ const candidateCode = record?.code === "POLICY_VIOLATION" ? "POLICY_DENIED" : record?.code === "APPROVAL_REQUIRED" ? "REQUIRES_APPROVAL" : record?.code;
1246
1253
  const code = typeof candidateCode === "string" && SAFE_RUNTIME_ERROR_CODES.has(candidateCode) ? candidateCode : "SERVER_ERROR";
1247
1254
  let status = typeof record?.status === "number" ? record.status : code.startsWith("BROWSER_") ? 409 : 500;
1248
1255
  if (!Number.isInteger(status) || status < 400 || status > 599) status = 409;
@@ -7,9 +7,9 @@ import {
7
7
  createPlaywrightCdpSessionRegistry,
8
8
  createPlaywrightCheckoutAdapter,
9
9
  createPlaywrightSessionObserver
10
- } from "./chunk-HM4EG5MH.mjs";
10
+ } from "./chunk-VSIO6PYA.mjs";
11
11
  import "./chunk-O5RAAB2U.mjs";
12
- import "./chunk-B7F5QLE5.mjs";
12
+ import "./chunk-WSIKPUZJ.mjs";
13
13
  export {
14
14
  createEncryptedPlaywrightCheckoutTargetStore,
15
15
  createGuardedPlaywrightCheckoutHttpHandler,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@conto_finance/sdk",
3
- "version": "0.5.3",
3
+ "version": "0.5.4",
4
4
  "description": "Conto SDK for AI agent payment authorization",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",