@conto_finance/sdk 0.6.1 → 0.7.0

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
@@ -1,6 +1,9 @@
1
+ import { LinkWallet, LinkCardCredential } from './link-wallet.js';
2
+ export { LinkCallOptions, LinkCardRequestInput, LinkSpendRequest, LinkSpendRequestStatus, LinkWaitOptions } from './link-wallet.js';
3
+
1
4
  type PurchaseStatus = 'queued' | 'running' | 'awaiting_action' | 'submitting' | 'reconciling' | 'succeeded' | 'blocked' | 'failed' | 'cancelled';
2
5
  type PurchasePhase = 'queued' | 'shopping' | 'checkout' | 'review' | 'scheduled' | 'authorization' | 'payment' | 'reconciliation' | 'closed_unconfirmed' | 'complete';
3
- type PurchaseActionKind = 'buyer_details' | 'purchase_review' | 'organization_approval' | 'card_verification' | 'merchant_signin' | 'merchant_challenge';
6
+ type PurchaseActionKind = 'buyer_details' | 'purchase_review' | 'organization_approval' | 'card_verification' | 'merchant_signin' | 'merchant_challenge' | 'budget_increase';
4
7
  type PurchaseActionAuthority = 'agent_or_buyer' | 'buyer' | 'cardholder' | 'organization';
5
8
  interface PurchaseMoney {
6
9
  /** Positive integer in minor units. */
@@ -14,6 +17,77 @@ interface PurchaseItem {
14
17
  quantity?: number;
15
18
  options?: string[];
16
19
  }
20
+ /** One grocery to find, in the shopper's words. Conto never substitutes a different product. */
21
+ interface PurchaseGroceryItem {
22
+ /** A short name, such as `Bananas`. */
23
+ label: string;
24
+ /** Plain search words, such as `bananas`. No prices, quantities or package sizes. */
25
+ query: string;
26
+ /** 1 to 20. */
27
+ quantity: number;
28
+ /** A package size, such as `1 pint`. */
29
+ size?: string;
30
+ /** How the item is sold, such as `bunch`, `bag` or `lb`. */
31
+ unit?: string;
32
+ brand?: string;
33
+ /** Words the item must not match, such as `organic`. */
34
+ exclude?: string[];
35
+ }
36
+ /**
37
+ * Groceries for one grocery store: an Instacart store link, or Conto Test
38
+ * Grocery in test mode. Up to 20 items. Use instead of `items`.
39
+ */
40
+ interface PurchaseGroceryList {
41
+ items: PurchaseGroceryItem[];
42
+ }
43
+ /** A grocery list purchase's items, delivery and fees at the store. */
44
+ interface PurchaseGrocery {
45
+ /** Each list item that has settled so far, by its position in the list. */
46
+ items: ({
47
+ index: number;
48
+ label: string;
49
+ status: 'added';
50
+ /** The store's product name. */
51
+ name: string;
52
+ quantity: number;
53
+ /** The line's price for that quantity. */
54
+ price: PurchaseMoney;
55
+ } | {
56
+ index: number;
57
+ label: string;
58
+ status: 'skipped';
59
+ reason: 'no_match' | 'size_unavailable' | 'brand_unavailable' | 'excluded';
60
+ })[];
61
+ /** The delivery time chosen at checkout. */
62
+ delivery: {
63
+ title: string;
64
+ window: string;
65
+ kind: 'priority' | 'standard' | 'scheduled' | 'other';
66
+ windowStart: string | null;
67
+ windowEnd: string | null;
68
+ price: PurchaseMoney | null;
69
+ } | null;
70
+ /** The store checkout's totals and fees, as it showed them. */
71
+ summary: {
72
+ itemsSubtotal: PurchaseMoney | null;
73
+ deliveryFee: PurchaseMoney | null;
74
+ serviceFee: PurchaseMoney | null;
75
+ bagFee: PurchaseMoney | null;
76
+ tax: PurchaseMoney | null;
77
+ tip: PurchaseMoney | null;
78
+ otherFees: {
79
+ label: string;
80
+ amount: PurchaseMoney;
81
+ }[];
82
+ total: PurchaseMoney | null;
83
+ } | null;
84
+ }
85
+ interface PurchaseRequest {
86
+ url: string;
87
+ task?: string;
88
+ items?: PurchaseItem[];
89
+ groceryList?: PurchaseGroceryList;
90
+ }
17
91
  interface PurchaseAction {
18
92
  id: string;
19
93
  kind: PurchaseActionKind;
@@ -24,6 +98,25 @@ interface PurchaseAction {
24
98
  /** For buyer_details: the form and the field names it accepts. */
25
99
  form?: 'delivery' | 'billing' | 'store_order_contact';
26
100
  fields?: string[];
101
+ /**
102
+ * For budget_increase: the maximum is above maxCost. Answer
103
+ * `{ decision: 'raise', maxCostMinor }` with at least the maximum, or
104
+ * `{ decision: 'decline' }`.
105
+ */
106
+ budget?: {
107
+ estimate: PurchaseMoney;
108
+ maximum: PurchaseMoney;
109
+ maxCost: PurchaseMoney;
110
+ };
111
+ /**
112
+ * For a merchant_signin you answer: the store sign-in step. Answer `email`
113
+ * with `{ email }` (or `{ email, createAccount: true, agreedToStoreTerms: true }`)
114
+ * and `code` with `{ code }`, the 6-digit code the store sent the buyer.
115
+ */
116
+ signin?: {
117
+ store: 'instacart';
118
+ step: 'email' | 'code';
119
+ };
27
120
  /**
28
121
  * For buyer, cardholder and reviewer actions: the Conto page that completes
29
122
  * it. It works only inside a hosted buyer session or the dashboard, so it is
@@ -60,29 +153,40 @@ interface Purchase {
60
153
  phase: PurchasePhase;
61
154
  /** Increases by one with every visible change. */
62
155
  version: number;
63
- request: {
64
- url: string;
65
- task?: string;
66
- items?: PurchaseItem[];
67
- };
156
+ request: PurchaseRequest;
68
157
  maxCost: PurchaseMoney;
69
158
  quote: {
70
159
  merchant: string;
71
160
  description: string | null;
161
+ /** What limits and the card are held to: the maximum, until a receipt records the final total. */
72
162
  total: PurchaseMoney;
163
+ /** The store's own total. */
164
+ estimate: PurchaseMoney;
165
+ /** The most the order can come to. The same as the estimate for an exact total. */
166
+ maximum: PurchaseMoney;
73
167
  estimatedTax: boolean;
74
168
  } | null;
75
169
  requiredAction: PurchaseAction | null;
76
170
  result: {
77
171
  outcome: 'merchant_confirmed' | 'checkout_reported' | 'credential_unused' | 'not_completed' | 'denied' | 'cancelled';
78
172
  merchantReference: string | null;
173
+ /** merchant_confirmed: the store's order number, when shown. */
174
+ orderNumber?: string | null;
175
+ /** merchant_confirmed: the store's receipt or order page, when shown. */
176
+ receiptUrl?: string | null;
177
+ /** merchant_confirmed: the amount the store charged, when shown. */
178
+ charged?: PurchaseMoney | null;
79
179
  } | null;
180
+ /** Present for a grocery list purchase. */
181
+ grocery?: PurchaseGrocery;
80
182
  paymentEvidence: PurchaseEvidence;
81
183
  progress: {
82
184
  steps: number;
83
185
  message: string | null;
84
186
  };
85
187
  reasonCode: string | null;
188
+ /** With POLICY_DENIED on a company card: which limit refused the purchase. */
189
+ limitReached?: 'buyer_daily' | 'buyer_monthly' | 'buyer_daily_count' | 'store' | 'card_or_policy';
86
190
  cancellation: {
87
191
  requestedAt: string;
88
192
  } | null;
@@ -131,11 +235,7 @@ interface PurchaseList {
131
235
  }
132
236
  interface CreatePurchaseInput {
133
237
  buyerId: string;
134
- request: {
135
- url: string;
136
- task?: string;
137
- items?: PurchaseItem[];
138
- };
238
+ request: PurchaseRequest;
139
239
  /** The most this purchase may cost, delivered. It narrows the delegation, never widens it. */
140
240
  maxCost: PurchaseMoney;
141
241
  /**
@@ -148,8 +248,12 @@ interface CreatePurchaseInput {
148
248
  methodId: string;
149
249
  delegationId: string;
150
250
  };
151
- /** The buyer id, to use the buyer's saved delivery details. */
152
- buyerProfileId?: string;
251
+ /**
252
+ * New purchases snapshot saved delivery details at creation for the store's
253
+ * delivery form. Leave out to use them when present, pass the buyer id
254
+ * to require them, or null to never use them.
255
+ */
256
+ buyerProfileId?: string | null;
153
257
  }
154
258
  interface PurchaseResponseAck {
155
259
  id: string;
@@ -172,7 +276,7 @@ interface WatchPurchaseOptions {
172
276
  mode?: 'auto' | 'stream' | 'poll';
173
277
  /** Polling interval. Defaults to 2000 ms. */
174
278
  pollIntervalMs?: number;
175
- /** Stop waiting after this long. Defaults to no limit. */
279
+ /** Stop observing after this many milliseconds (0 stops immediately). Does not cancel the purchase. */
176
280
  maxWaitMs?: number;
177
281
  }
178
282
  declare const isFinalPurchaseStatus: (status: PurchaseStatus) => boolean;
@@ -192,7 +296,7 @@ type SseFrame = {
192
296
  data: string;
193
297
  };
194
298
  /** Parses server-sent events from a byte stream. */
195
- declare function parseServerSentEvents(body: ReadableStream<Uint8Array>): AsyncGenerator<SseFrame>;
299
+ declare function parseServerSentEvents(body: ReadableStream<Uint8Array>, signal?: AbortSignal): AsyncGenerator<SseFrame>;
196
300
  type RecurringPurchaseCycleStatus = 'checking' | 'scheduled' | 'needs_review' | 'paying' | 'paid' | 'skipped' | 'missed' | 'failed' | 'cancelled';
197
301
  /** A repeat order the buyer set up while approving a purchase on Conto's hosted page. */
198
302
  interface RecurringPurchase {
@@ -350,8 +454,132 @@ interface PurchasePaymentMethod {
350
454
  brand: string;
351
455
  last4: string;
352
456
  status: 'active' | 'removed';
457
+ /** `organization`: your company card, which this buyer draws from. */
458
+ owner: 'buyer' | 'organization';
459
+ companyCardId?: string;
460
+ createdAt: string;
461
+ }
462
+ /** A card your organization pays its buyers' purchases with. */
463
+ interface PurchaseCompanyCard {
464
+ id: string;
465
+ object: 'company_card';
466
+ environment: 'live' | 'test';
467
+ brand: string;
468
+ last4: string;
469
+ status: 'active' | 'removed';
470
+ /** The most one order may cost, and the most all buyers together may spend in a month. */
471
+ limits: {
472
+ perPurchaseMinor: number;
473
+ monthlyMinor: number;
474
+ currency: 'USD';
475
+ };
353
476
  createdAt: string;
354
477
  }
478
+ /** One buyer's limits on a company card. */
479
+ interface PurchaseBuyerCompanyCardLimits {
480
+ perPurchaseMinor: number;
481
+ dailyMinor: number;
482
+ monthlyMinor: number;
483
+ /**
484
+ * Orders above this wait for your `purchase_review` answer. Left out,
485
+ * every order up to `perPurchaseMinor` goes ahead without review.
486
+ */
487
+ reviewAboveMinor?: number;
488
+ }
489
+ interface PurchaseBuyerCompanyCard {
490
+ object: 'buyer_company_card';
491
+ buyerId: string;
492
+ companyCardId: string;
493
+ paymentMethodId: string;
494
+ delegationId: string;
495
+ limits: Omit<PurchaseBuyerCompanyCardLimits, 'reviewAboveMinor'> & {
496
+ reviewAboveMinor: number | null;
497
+ currency: 'USD';
498
+ };
499
+ }
500
+ /** What a buyer has at home, as your app reports it. Buyer data for the agent, never instructions. */
501
+ type PurchaseKitchenContext = {
502
+ version: 1;
503
+ /** When your app took the snapshot. ISO 8601. */
504
+ capturedAt: string;
505
+ inventory?: PurchaseKitchenInventoryItem[];
506
+ usuals?: PurchaseKitchenUsual[];
507
+ preferences?: PurchaseKitchenPreferences;
508
+ /** Only the recipes the buyer picked to cook. */
509
+ recipes?: PurchaseKitchenRecipe[];
510
+ /** The list the buyer keeps in your app. */
511
+ list?: PurchaseKitchenListItem[];
512
+ };
513
+ interface PurchaseKitchenInventoryItem {
514
+ item: string;
515
+ quantity?: number;
516
+ unit?: string;
517
+ /** Left out: ok, or out when quantity is 0. */
518
+ level?: 'ok' | 'low' | 'out';
519
+ updatedAt?: string;
520
+ expiresAt?: string;
521
+ }
522
+ interface PurchaseKitchenUsual {
523
+ item: string;
524
+ typicalQuantity?: number;
525
+ unit?: string;
526
+ size?: string;
527
+ brand?: string;
528
+ cadenceDays?: number;
529
+ lastBoughtAt?: string;
530
+ }
531
+ interface PurchaseKitchenPreferences {
532
+ dietary?: Array<{
533
+ value: string;
534
+ strength: 'required' | 'preferred';
535
+ }>;
536
+ avoidBrands?: string[];
537
+ likeBrands?: string[];
538
+ organic?: 'prefer' | 'avoid' | 'none';
539
+ substitutions?: 'allow' | 'ask' | 'never';
540
+ /** An https store link, such as an Instacart storefront. */
541
+ preferredStore?: string;
542
+ householdSize?: number;
543
+ weeklyBudgetMinor?: number;
544
+ }
545
+ interface PurchaseKitchenRecipe {
546
+ id?: string;
547
+ title: string;
548
+ servings?: number;
549
+ /** The planned day, as YYYY-MM-DD. */
550
+ cookOn?: string;
551
+ /** Whether your app finds it cookable from what is at home. */
552
+ cookable?: boolean;
553
+ ingredients: Array<{
554
+ item: string;
555
+ quantity?: number;
556
+ unit?: string;
557
+ optional?: boolean;
558
+ }>;
559
+ }
560
+ interface PurchaseKitchenListItem {
561
+ item: string;
562
+ quantity?: number;
563
+ unit?: string;
564
+ note?: string;
565
+ }
566
+ interface PurchaseBuyerKitchenContext {
567
+ object: 'buyer_kitchen_context';
568
+ buyerId: string;
569
+ /** Null when nothing was pushed. */
570
+ context: PurchaseKitchenContext | null;
571
+ summary: {
572
+ capturedAt: string;
573
+ inventory: number;
574
+ low: number;
575
+ out: number;
576
+ usuals: number;
577
+ recipes: number;
578
+ list: number;
579
+ } | null;
580
+ /** When Conto received the snapshot. */
581
+ receivedAt: string | null;
582
+ }
355
583
  interface PurchaseDelegation {
356
584
  id: string;
357
585
  object: 'delegation';
@@ -363,9 +591,14 @@ interface PurchaseDelegation {
363
591
  limits: {
364
592
  perPurchaseMinor: number;
365
593
  dailyMinor: number;
594
+ /** Company card only. */
595
+ monthlyMinor?: number;
596
+ /** Company card only: orders above this wait for your review. */
597
+ reviewAboveMinor?: number;
366
598
  currency: 'USD';
367
599
  };
368
- requiresPurchaseReview: true;
600
+ /** false for a company card delegation, which you review above `reviewAboveMinor` only. */
601
+ requiresPurchaseReview: boolean;
369
602
  requiresCardVerification: boolean;
370
603
  createdAt: string;
371
604
  revokedAt: string | null;
@@ -380,6 +613,39 @@ interface PurchaseHostedLink {
380
613
  url: string;
381
614
  expiresAt: string;
382
615
  }
616
+ /** Buyer-approved spending at one store; not a merchant-independent allowance. */
617
+ interface PurchaseAllowance {
618
+ id: string;
619
+ object: 'allowance';
620
+ buyerId: string;
621
+ agentId: string;
622
+ delegationId: string;
623
+ paymentMethodId: string;
624
+ environment: 'live' | 'test';
625
+ status: 'pending_verification' | 'active' | 'revoked' | 'expired';
626
+ kind: 'store' | 'recurrence';
627
+ merchant: {
628
+ name: string;
629
+ origin: string;
630
+ };
631
+ limits: {
632
+ perPurchaseMinor: number;
633
+ periodMinor: number;
634
+ period: 'day' | 'week' | 'month';
635
+ totalMinor: number;
636
+ currency: 'USD';
637
+ };
638
+ expiresAt: string;
639
+ createdAt: string;
640
+ activatedAt: string | null;
641
+ revokedAt: string | null;
642
+ }
643
+ interface PurchasingSettings {
644
+ /** Origins a hosted page may return the buyer to. */
645
+ allowedReturnOrigins: string[];
646
+ /** Whether Conto emails buyers about their purchases. On by default. */
647
+ buyerEmails: boolean;
648
+ }
383
649
  interface PurchasingCapabilities {
384
650
  object: 'purchasing_capabilities';
385
651
  /** Test mode is open to every organization. Live needs Conto to enable it. */
@@ -389,6 +655,7 @@ interface PurchasingCapabilities {
389
655
  }>;
390
656
  currencies: string[];
391
657
  cardNetworks: string[];
658
+ /** Checkout paths: `browser_checkout`, `store_order` and `test_store`. */
392
659
  executors: Array<{
393
660
  executor: string;
394
661
  available: boolean;
@@ -398,6 +665,10 @@ interface PurchasingCapabilities {
398
665
  allowances?: Record<'test' | 'live', {
399
666
  available: boolean;
400
667
  }>;
668
+ /** Whether your app can push what its buyers have at home. */
669
+ kitchenContext?: {
670
+ available: boolean;
671
+ };
401
672
  unsupported: Array<{
402
673
  capability: string;
403
674
  reason: string;
@@ -429,6 +700,18 @@ declare class AdminPurchasingClient {
429
700
  constructor(client: AdminTransport);
430
701
  /** Buyers' repeat orders: list, read, start or skip an order, and cancel. */
431
702
  readonly recurringPurchases: OrganizationRecurringPurchasesClient;
703
+ /** Inspect or revoke buyer-approved allowances. Grants remain on the buyer's hosted page. */
704
+ readonly allowances: {
705
+ /** Returns up to 50 allowances for this buyer, newest first. */
706
+ list: (params: {
707
+ buyerId: string;
708
+ }) => Promise<{
709
+ items: PurchaseAllowance[];
710
+ }>;
711
+ get: (id: string) => Promise<PurchaseAllowance>;
712
+ /** Stops future credential release; does not undo payments already submitted. */
713
+ revoke: (id: string) => Promise<PurchaseAllowance>;
714
+ };
432
715
  readonly buyers: {
433
716
  /** Maps one of your users to a buyer with its own agent, or returns the existing one. */
434
717
  create: (input: {
@@ -447,6 +730,56 @@ declare class AdminPurchasingClient {
447
730
  }>;
448
731
  /** Stops the buyer's agent. Purchases that may already be paid stay visible. */
449
732
  stop: (id: string) => Promise<PurchaseBuyer>;
733
+ /**
734
+ * Lets the buyer pay with your company card within limits you set for
735
+ * them, or replaces those limits. The buyer must not have their own card.
736
+ */
737
+ setCompanyCard: (id: string, input: {
738
+ companyCardId: string;
739
+ limits: PurchaseBuyerCompanyCardLimits;
740
+ }) => Promise<PurchaseBuyerCompanyCard>;
741
+ /** The buyer stops paying with your company card. */
742
+ removeCompanyCard: (id: string) => Promise<{
743
+ buyerId: string;
744
+ object: "buyer_company_card";
745
+ removed: true;
746
+ }>;
747
+ /**
748
+ * Replaces what the buyer has at home: inventory, usuals, preferences,
749
+ * chosen recipes and their list. The whole snapshot, every time. Needs
750
+ * Conto to enable kitchen context for your organization.
751
+ */
752
+ setKitchenContext: (id: string, context: PurchaseKitchenContext) => Promise<PurchaseBuyerKitchenContext>;
753
+ /** The snapshot Conto holds, with context null when nothing was pushed. */
754
+ getKitchenContext: (id: string) => Promise<PurchaseBuyerKitchenContext>;
755
+ clearKitchenContext: (id: string) => Promise<{
756
+ buyerId: string;
757
+ object: "buyer_kitchen_context";
758
+ removed: true;
759
+ }>;
760
+ };
761
+ /** Cards your organization pays its buyers' purchases with. Test cards only for now. */
762
+ readonly companyCards: {
763
+ create: (input: {
764
+ environment: "live" | "test";
765
+ limits: {
766
+ perPurchaseMinor: number;
767
+ monthlyMinor: number;
768
+ };
769
+ }) => Promise<PurchaseCompanyCard>;
770
+ list: () => Promise<{
771
+ items: PurchaseCompanyCard[];
772
+ }>;
773
+ get: (id: string) => Promise<PurchaseCompanyCard>;
774
+ /** Changes the card's own caps. Each buyer's limits stay as they are. */
775
+ update: (id: string, input: {
776
+ limits: {
777
+ perPurchaseMinor: number;
778
+ monthlyMinor: number;
779
+ };
780
+ }) => Promise<PurchaseCompanyCard>;
781
+ /** No buyer can start or pay a purchase with the card after this. */
782
+ remove: (id: string) => Promise<PurchaseCompanyCard>;
450
783
  };
451
784
  readonly paymentMethods: {
452
785
  /** A single-use link to the hosted setup page: limits, card and delegation. */
@@ -477,14 +810,12 @@ declare class AdminPurchasingClient {
477
810
  */
478
811
  readonly purchases: OrganizationPurchasesClient;
479
812
  readonly settings: {
480
- get: () => Promise<{
481
- allowedReturnOrigins: string[];
482
- }>;
813
+ get: () => Promise<PurchasingSettings>;
814
+ /** Changes only the fields you pass. */
483
815
  update: (input: {
484
- allowedReturnOrigins: string[];
485
- }) => Promise<{
486
- allowedReturnOrigins: string[];
487
- }>;
816
+ allowedReturnOrigins?: string[];
817
+ buyerEmails?: boolean;
818
+ }) => Promise<PurchasingSettings>;
488
819
  };
489
820
  /** What this organization can run now: test mode always, live once Conto enables it. */
490
821
  capabilities(): Promise<PurchasingCapabilities>;
@@ -1022,6 +1353,29 @@ interface RefreshBalanceResult {
1022
1353
  balances: WalletChainBalanceSnapshot[];
1023
1354
  lastRefreshed: string;
1024
1355
  }
1356
+ /** A one-time message for a self-custody wallet's address to sign. */
1357
+ interface WalletOwnershipChallenge {
1358
+ walletId: string;
1359
+ address: string;
1360
+ chainType: ChainType;
1361
+ chainId: string;
1362
+ /** Sign exactly this text: EIP-191 personal_sign on EVM, Ed25519 on Solana. */
1363
+ message: string;
1364
+ expiresAt: string;
1365
+ /** When the wallet was last proven, or null if never. */
1366
+ provenAt: string | null;
1367
+ }
1368
+ interface ProveWalletOwnershipInput {
1369
+ /** The challenge message, unchanged. */
1370
+ message: string;
1371
+ /** EVM: 0x-prefixed hex signature. Solana: base58 or base64 signature. */
1372
+ signature: string;
1373
+ }
1374
+ interface WalletOwnershipProof {
1375
+ walletId: string;
1376
+ proven: true;
1377
+ provenAt: string;
1378
+ }
1025
1379
  interface PolicyRule {
1026
1380
  id: string;
1027
1381
  policyId: string;
@@ -1311,6 +1665,13 @@ declare class WalletsClient {
1311
1665
  provision(walletId: string): Promise<ProvisionWalletResult>;
1312
1666
  /** Refresh a wallet's balance from the chain */
1313
1667
  refreshBalance(walletId: string): Promise<RefreshBalanceResult>;
1668
+ /**
1669
+ * Get a one-time message for a self-custody wallet's address to sign. It
1670
+ * expires after 10 minutes and replaces any earlier challenge.
1671
+ */
1672
+ createOwnershipChallenge(walletId: string): Promise<WalletOwnershipChallenge>;
1673
+ /** Prove your organization controls a self-custody wallet's address. */
1674
+ proveOwnership(walletId: string, input: ProveWalletOwnershipInput): Promise<WalletOwnershipProof>;
1314
1675
  }
1315
1676
  declare class PoliciesClient {
1316
1677
  private client;
@@ -2209,21 +2570,34 @@ interface BeginCheckoutCheckpointInput {
2209
2570
  /** Defaults to one Total entry equal to amountMinor. */
2210
2571
  totals?: CommerceTotalInput[];
2211
2572
  }
2573
+ /**
2574
+ * The payment behind a checkout, such as the Link spend request that issued a
2575
+ * Link card. An id only, never card data.
2576
+ */
2577
+ interface CheckoutPaymentReference {
2578
+ provider: 'LINK';
2579
+ /** The Link spend request id, such as lsrq_... */
2580
+ id: string;
2581
+ }
2212
2582
  /** Second checkpoint: the final total shown right before the payment is submitted. */
2213
2583
  interface ConfirmCheckoutCheckpointInput {
2214
2584
  amountMinor: number;
2215
2585
  currency?: 'USD';
2216
- /** Final line items, needed only when the total changed. Defaults to the approved items. */
2586
+ /** Observed final items. Supplied items are checked even when the total is unchanged. */
2217
2587
  lineItems?: CommerceLineItemInput[];
2218
- /** Final totals, such as tax and shipping. Defaults to one Total entry. */
2588
+ /** Observed final charges. Supplied charges are checked even when the total is unchanged. */
2219
2589
  totals?: CommerceTotalInput[];
2220
2590
  /** Page where the payment is submitted: the merchant's site or the payment method's. */
2221
2591
  pageUrl?: string;
2592
+ /** The Link card's spend request, from getLinkCard(). */
2593
+ paymentReference?: CheckoutPaymentReference;
2222
2594
  }
2223
2595
  interface ReportCheckoutOutcomeInput {
2224
2596
  outcome: CheckoutOutcome;
2225
2597
  /** Merchant order or receipt number. Never a payment credential. */
2226
2598
  reference?: string;
2599
+ /** The Link card's spend request, from getLinkCard(). */
2600
+ paymentReference?: CheckoutPaymentReference;
2227
2601
  }
2228
2602
  interface CheckoutCheckpoint {
2229
2603
  id: string;
@@ -2250,6 +2624,8 @@ interface CheckoutCheckpoint {
2250
2624
  /** Present when the agent's rules sent this purchase to the owner for approval. */
2251
2625
  approval?: CheckoutCheckpointApproval;
2252
2626
  outcomeReference?: string;
2627
+ /** The payment your checkout reported at confirm or outcome, such as a Link spend request. */
2628
+ paymentReference?: CheckoutPaymentReference;
2253
2629
  /** Outcomes are reported by your checkout. Conto does not verify settlement here. */
2254
2630
  settlementVerified: false;
2255
2631
  }
@@ -2266,6 +2642,45 @@ interface WaitForCheckoutApprovalOptions {
2266
2642
  pollIntervalMs?: number;
2267
2643
  signal?: AbortSignal;
2268
2644
  }
2645
+
2646
+ /**
2647
+ * A Link card for one purchase: the checkpoint begin input plus the Link
2648
+ * wallet that runs in your environment. The checkout method is always LINK.
2649
+ */
2650
+ interface GetLinkCardInput extends Omit<BeginCheckoutCheckpointInput, 'checkoutMethod'> {
2651
+ /** For example linkCliWallet() from @conto_finance/sdk/link-wallet. */
2652
+ wallet: LinkWallet;
2653
+ /** How long to wait for the owner when a rule requires approval. Defaults to 10 minutes. */
2654
+ ownerApprovalTimeoutMs?: number;
2655
+ /** How long to wait for the person to approve in Link. Defaults to 10 minutes. */
2656
+ linkApprovalTimeoutMs?: number;
2657
+ signal?: AbortSignal;
2658
+ }
2659
+ /** A new Link card for a changed final total. */
2660
+ interface ReplaceLinkCardInput {
2661
+ wallet: LinkWallet;
2662
+ /** The final total in cents, including shipping and tax. */
2663
+ amountMinor: number;
2664
+ /** Final line items. Defaults to the approved items. */
2665
+ lineItems?: CommerceLineItemInput[];
2666
+ /** Final totals, such as tax and shipping. Defaults to one Total entry. */
2667
+ totals?: CommerceTotalInput[];
2668
+ ownerApprovalTimeoutMs?: number;
2669
+ linkApprovalTimeoutMs?: number;
2670
+ signal?: AbortSignal;
2671
+ }
2672
+ interface LinkCardResult {
2673
+ /** The approved checkpoint. Pass it to confirm() right before paying. */
2674
+ checkpoint: CheckoutCheckpoint;
2675
+ /**
2676
+ * Live card data for this purchase only. It stays in this process: printing
2677
+ * or serializing the result shows only the last four digits.
2678
+ */
2679
+ card: LinkCardCredential;
2680
+ linkRequestId: string;
2681
+ /** Pass to confirm() and reportOutcome() so the owner sees which Link request paid. */
2682
+ paymentReference: CheckoutPaymentReference;
2683
+ }
2269
2684
  /** Exact Stripe Link purchase intent evaluated and bound by Conto policy. */
2270
2685
  interface BeginCommerceExecutionCommonInput {
2271
2686
  /** Stable key for this exact intent. Reuse it when reconciling or retrying begin. */
@@ -2957,6 +3372,41 @@ declare class CheckoutApprovalTimeoutError extends ContoError {
2957
3372
  readonly checkpoint: CheckoutCheckpoint;
2958
3373
  constructor(checkpoint: CheckoutCheckpoint);
2959
3374
  }
3375
+ /**
3376
+ * getLinkCard() or replaceLinkCard() stopped after Conto approved the purchase.
3377
+ * No card was returned. Conto cancelled the checkpoint to release the held
3378
+ * spend unless holdReleased is false. Do not pay.
3379
+ */
3380
+ declare class LinkCardError extends ContoError {
3381
+ readonly checkpoint: CheckoutCheckpoint;
3382
+ readonly linkRequestId?: string;
3383
+ /** True when Conto cancelled the checkpoint and released the held spend. */
3384
+ readonly holdReleased: boolean;
3385
+ constructor(input: {
3386
+ message: string;
3387
+ code: string;
3388
+ checkpoint: CheckoutCheckpoint;
3389
+ linkRequestId?: string;
3390
+ holdReleased: boolean;
3391
+ retryGuidance?: string;
3392
+ });
3393
+ }
3394
+ /** The person declined the Link card request, or it was cancelled in Link. */
3395
+ declare class LinkCardDeniedError extends LinkCardError {
3396
+ constructor(input: ConstructorParameters<typeof LinkCardError>[0]);
3397
+ }
3398
+ /** The Link card request expired before the person approved it. */
3399
+ declare class LinkCardExpiredError extends LinkCardError {
3400
+ constructor(input: ConstructorParameters<typeof LinkCardError>[0]);
3401
+ }
3402
+ /** The person did not approve in Link before linkApprovalTimeoutMs. Conto cancelled the request. */
3403
+ declare class LinkCardTimeoutError extends LinkCardError {
3404
+ constructor(input: ConstructorParameters<typeof LinkCardError>[0]);
3405
+ }
3406
+ /** The Link wallet cannot run here: link-cli is not installed or not logged in. */
3407
+ declare class LinkWalletUnavailableError extends LinkCardError {
3408
+ constructor(input: ConstructorParameters<typeof LinkCardError>[0]);
3409
+ }
2960
3410
  interface ContoRequestOptions {
2961
3411
  /** Set only when repeating this request cannot create an additional side effect. */
2962
3412
  idempotent?: boolean;
@@ -3396,6 +3846,38 @@ declare class CheckoutClient {
3396
3846
  */
3397
3847
  cancel(checkpointId: string): Promise<CheckoutCheckpoint>;
3398
3848
  get(checkpointId: string): Promise<CheckoutCheckpoint>;
3849
+ /**
3850
+ * Get a Stripe Link card for one purchase, issued only after Conto approves
3851
+ * it. Call this at the payment step, once the final total with shipping and
3852
+ * tax is known.
3853
+ *
3854
+ * 1. Conto runs checkpoint 1 and holds the spend. When a rule requires the
3855
+ * owner's approval, this waits for it.
3856
+ * 2. Only then does the wallet ask Link for a card for exactly the approved
3857
+ * amount at this merchant. The person approves it in Link.
3858
+ * 3. The card is returned. It never reaches Conto.
3859
+ *
3860
+ * Then fill in the card, call confirm(result.checkpoint, { amountMinor,
3861
+ * paymentReference: result.paymentReference }) right before paying, pay only
3862
+ * if it resolves, and report the outcome. If the final total differs, call
3863
+ * replaceLinkCard() instead of confirming.
3864
+ *
3865
+ * A Conto denial throws before Link is called. When Link declines, expires,
3866
+ * times out, or is unavailable, this cancels the checkpoint to release the
3867
+ * held spend and throws a LinkCardError. When Conto cannot cancel an open Link
3868
+ * request, it keeps the hold and throws LINK_CARD_NOT_CANCELLED with the
3869
+ * request id. Retrying with the same input resumes the same checkpoint and
3870
+ * Link request.
3871
+ */
3872
+ getLinkCard(input: GetLinkCardInput): Promise<LinkCardResult>;
3873
+ /**
3874
+ * The final total differs from the one the Link card covers. This cancels
3875
+ * the old Link request and checkpoint, begins a checkpoint at the final
3876
+ * total (waiting for the owner when a rule requires it), and gets a new card
3877
+ * for it. Confirm the returned checkpoint with the same total.
3878
+ */
3879
+ replaceLinkCard(previous: LinkCardResult, input: ReplaceLinkCardInput): Promise<LinkCardResult>;
3399
3880
  }
3400
3881
 
3401
- export { type AdminExternalCardOverlayEnforcement, AdminPurchasingClient, 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 BeginCheckoutCheckpointInput, type BeginCommerceExecutionInput, type BrowserActionClaimResult, type BrowserActionDispatchObservationInput, BrowserActionFinalizationPendingError, type BrowserActionFinalizeResult, type BrowserCheckoutAction, type BrowserCheckoutTargetResolver, type BrowserCheckoutTargetSnapshot, type BrowserCheckoutTargetVerificationCode, BrowserCheckoutTargetVerificationError, type CancellationOutcome, type CanonicalBrowserCheckoutTargetSnapshot, CardsClient, type ChainType, type CheckoutActionAuthorization, CheckoutApprovalDeniedError, CheckoutApprovalExpiredError, CheckoutApprovalPendingError, CheckoutApprovalTimeoutError, type CheckoutCheckpoint, type CheckoutCheckpointApproval, CheckoutCheckpointClosedError, type CheckoutCheckpointMethod, type CheckoutCheckpointNextAction, type CheckoutCheckpointStage, CheckoutClient, type CheckoutOutcome, 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 ConfirmCheckoutCheckpointInput, type ConnectedCardBrief, type ConnectedCardCredential, type ConnectedCardDrawInput, type ConnectedCardDrawMerchant, type ConnectedCardDrawResult, type ConnectedCardDrawable, type ConnectedCardListResult, type ConnectedCardMandate, type ConnectedCardMandateMerchant, type ConnectedCardOutcomeReport, type ConnectedCardOutcomeReportResult, type ConnectedCardReference, ConnectedCardsClient, Conto, ContoAdmin, type ContoAdminConfig, ContoAdminError, type ContoConfig, ContoError, type ContoRequestOptions, type ControlledExternalCardPaymentResult, ControlledExternalCardPaymentTool, type CreateAgentInput, type CreatePolicyInput, type CreatePolicyRuleInput, type CreatePurchaseInput, 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 ListWalletsParams, type ListWalletsResponse, type MppBudgetResult, type MppPreAuthorizeInput, type MppPreAuthorizeResult, type MppRecordInput, type MppRecordResult, type NormalizeCommerceProposalInput, type OrganizationMember, OrganizationPurchasesClient, OrganizationRecurringPurchasesClient, 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 Purchase, type PurchaseAction, type PurchaseActionAuthority, type PurchaseActionKind, type PurchaseBuyer, type PurchaseDelegation, type PurchaseEvent, type PurchaseEventPage, type PurchaseEvidence, type PurchaseHostedLink, type PurchaseItem, type PurchaseList, type PurchaseMoney, type PurchasePaymentMethod, type PurchasePhase, type PurchaseResponseAck, type PurchaseStatus, PurchasesClient, type PurchasingCapabilities, type RecurringPurchase, type RecurringPurchaseCycleResult, type RecurringPurchaseCycleStatus, RecurringPurchasesClient, type RefreshBalanceResult, type RegisterExternalCardInput, type ReportCheckoutOutcomeInput, 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 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 WaitForCheckoutApprovalOptions, type Wallet, type WalletChainBalanceSnapshot, type WalletStatus, type WalletType, type WatchPurchaseOptions, type X402Authorization, type X402BudgetResult, type X402PayInput, type X402PayResult, type X402PaymentRequirements, type X402PreAuthorizeInput, type X402PreAuthorizeResult, type X402RecordInput, type X402RecordResult, canonicalizeBrowserCheckoutTarget, createVerifiedBrowserCheckoutDriver, Conto as default, fingerprintBrowserCheckoutTarget, isFinalPurchaseStatus, parseServerSentEvents, verifyPurchaseWebhook };
3882
+ export { AdminPurchasingClient, BrowserActionFinalizationPendingError, BrowserCheckoutTargetVerificationError, CardsClient, CheckoutApprovalDeniedError, CheckoutApprovalExpiredError, CheckoutApprovalPendingError, CheckoutApprovalTimeoutError, CheckoutCheckpointClosedError, CheckoutClient, ConnectedCardsClient, Conto, ContoAdmin, ContoAdminError, ContoError, ControlledExternalCardPaymentTool, ExternalCardConfirmationPendingError, Conto as Giro, ContoError as GiroError, LinkCardCredential, LinkCardDeniedError, LinkCardError, LinkCardExpiredError, LinkCardTimeoutError, LinkWallet, LinkWalletUnavailableError, OrganizationPurchasesClient, OrganizationRecurringPurchasesClient, PurchasesClient, RecurringPurchasesClient, TestCardsClient, canonicalizeBrowserCheckoutTarget, createVerifiedBrowserCheckoutDriver, Conto as default, fingerprintBrowserCheckoutTarget, isFinalPurchaseStatus, parseServerSentEvents, verifyPurchaseWebhook };
3883
+ export type { AdminExternalCardOverlayEnforcement, Agent, AgentCheckoutAction, AgentCheckoutActionKind, AgentExternalCard, AgentSetupResult, AgentStatus, AgentType, AgentWalletLink, ApprovedExternalCardExecution, AssignExternalCardInput, AssignedPolicy, AuthorizeCheckoutActionResult, BeginCheckoutCheckpointInput, BeginCommerceExecutionInput, BrowserActionClaimResult, BrowserActionDispatchObservationInput, BrowserActionFinalizeResult, BrowserCheckoutAction, BrowserCheckoutTargetResolver, BrowserCheckoutTargetSnapshot, BrowserCheckoutTargetVerificationCode, CancellationOutcome, CanonicalBrowserCheckoutTargetSnapshot, ChainType, CheckoutActionAuthorization, CheckoutCheckpoint, CheckoutCheckpointApproval, CheckoutCheckpointMethod, CheckoutCheckpointNextAction, CheckoutCheckpointStage, CheckoutOutcome, CheckoutPaymentReference, CommerceCheckoutMethod, CommerceContextRequirement, CommerceExecution, CommerceExecutionAdapterKind, CommerceExecutionArtifactKind, CommerceExecutionChannel, CommerceExecutionConstraint, CommerceExecutionConstraintCoverage, CommerceExecutionConstraintCoverageLevel, CommerceExecutionDeliveryMode, CommerceExecutionEvidence, CommerceExecutionProvider, CommerceExecutionResult, CommerceExecutionSourceKind, CommerceExecutionStatus, CommerceFactConfidence, CommerceFactProvenanceInput, CommerceFactSource, CommerceFulfillmentInput, CommerceLineItemInput, CommerceProposalFactKey, CommerceProposalMissingFact, CommerceProposalResolution, CommerceProposalState, CommerceSettlementRail, CommerceTotalInput, CommerceTotalType, ComparePolicyVersionsResponse, ConfirmCheckoutCheckpointInput, ConnectedCardBrief, ConnectedCardCredential, ConnectedCardDrawInput, ConnectedCardDrawMerchant, ConnectedCardDrawResult, ConnectedCardDrawable, ConnectedCardListResult, ConnectedCardMandate, ConnectedCardMandateMerchant, ConnectedCardOutcomeReport, ConnectedCardOutcomeReportResult, ConnectedCardReference, ContoAdminConfig, ContoConfig, ContoRequestOptions, ControlledExternalCardPaymentResult, CreateAgentInput, CreatePolicyInput, CreatePolicyRuleInput, CreatePurchaseInput, CreateSdkKeyInput, CreateSdkKeyResult, CreateWalletInput, CustodyType, CustomerCustodyMode, CustomerWalletControlModel, CustomerWalletKeyAccess, DelegationType, ExecuteCommerceExecutionResult, ExternalCard, ExternalCardApprovalInput, ExternalCardApprovalResult, ExternalCardConfirmationInput, ExternalCardConfirmationResult, ExternalCardExecutionClaimResult, ExternalCardExecutionResult, ExternalCardExecutor, ExternalCardOverlayEnforcement, ExternalCardRequestStatusResult, ExternalWalletApprovalInput, ExternalWalletApprovalResult, ExternalWalletConfirmationInput, ExternalWalletConfirmationResult, FreezeAgentInput, GetLinkCardInput, ContoConfig as GiroConfig, GuardCheckoutResult, GuardedBrowserDispatchResult, GuardedCheckoutInput, LinkCardResult, LinkWalletInput, ListAgentsParams, ListAgentsResponse, ListPoliciesParams, ListPoliciesResponse, ListPolicyVersionsResponse, ListWalletsParams, ListWalletsResponse, MppBudgetResult, MppPreAuthorizeInput, MppPreAuthorizeResult, MppRecordInput, MppRecordResult, NormalizeCommerceProposalInput, OrganizationMember, PaginatedResponse, PaginationParams, PauseExternalCardAssignmentResult, PaymentExecuteResult, PaymentRequestInput, PaymentRequestResult, PaymentStatusResult, Policy, PolicyRule, PolicyType, PolicyVersionChangeType, PolicyVersionDetail, PolicyVersionDiff, PolicyVersionFieldChange, PolicyVersionSnapshot, PolicyVersionSnapshotRule, PolicyVersionSummary, PrivilegedBrowserCheckoutDriver, ProtocolBudgetResult, ProtocolPreAuthorizeResult, ProtocolRecordGrant, ProtocolRecordGrantResult, ProtocolServiceSummary, ProtocolServicesResult, ProveWalletOwnershipInput, ProvisionWalletResult, Purchase, PurchaseAction, PurchaseActionAuthority, PurchaseActionKind, PurchaseAllowance, PurchaseBuyer, PurchaseBuyerCompanyCard, PurchaseBuyerCompanyCardLimits, PurchaseBuyerKitchenContext, PurchaseCompanyCard, PurchaseDelegation, PurchaseEvent, PurchaseEventPage, PurchaseEvidence, PurchaseGrocery, PurchaseGroceryItem, PurchaseGroceryList, PurchaseHostedLink, PurchaseItem, PurchaseKitchenContext, PurchaseKitchenInventoryItem, PurchaseKitchenListItem, PurchaseKitchenPreferences, PurchaseKitchenRecipe, PurchaseKitchenUsual, PurchaseList, PurchaseMoney, PurchasePaymentMethod, PurchasePhase, PurchaseRequest, PurchaseResponseAck, PurchaseStatus, PurchasingCapabilities, PurchasingSettings, RecurringPurchase, RecurringPurchaseCycleResult, RecurringPurchaseCycleStatus, RefreshBalanceResult, RegisterExternalCardInput, ReplaceLinkCardInput, ReportCheckoutOutcomeInput, RollbackPolicyVersionResponse, RuleAction, RuleOperator, RuleType, RunGuardedCheckoutResult, SdkKey, SdkKeyType, SetupCapabilityState, SetupCardDiagnostics, SetupDiagnosticAction, SetupDiagnosticIssue, SetupDiagnosticIssueCode, SetupDiagnostics, SetupWalletDiagnostics, TestCardCredential, TestCardDrawResult, TestCardDrawable, TestCardListResult, TestCardReceipt, TestCheckoutInput, TestCheckoutResult, TestMerchant, TestMerchantProduct, UnfreezeAgentInput, UpdateAgentInput, UpdateExternalCardAssignmentInput, UpdatePolicyInput, UpdatePolicyRuleInput, UpdateWalletInput, VerifiedBrowserCheckoutTarget, WaitForCheckoutApprovalOptions, Wallet, WalletChainBalanceSnapshot, WalletOwnershipChallenge, WalletOwnershipProof, WalletStatus, WalletType, WatchPurchaseOptions, X402Authorization, X402BudgetResult, X402PayInput, X402PayResult, X402PaymentRequirements, X402PreAuthorizeInput, X402PreAuthorizeResult, X402RecordInput, X402RecordResult };