@conto_finance/sdk 0.6.1 → 0.6.2-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,6 +1,9 @@
1
+ import { LinkWallet, LinkCardCredential } from './link-wallet.mjs';
2
+ export { LinkCallOptions, LinkCardRequestInput, LinkSpendRequest, LinkSpendRequestStatus, LinkWaitOptions } from './link-wallet.mjs';
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,35 @@ 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
+ interface PurchaseRequest {
44
+ url: string;
45
+ task?: string;
46
+ items?: PurchaseItem[];
47
+ groceryList?: PurchaseGroceryList;
48
+ }
17
49
  interface PurchaseAction {
18
50
  id: string;
19
51
  kind: PurchaseActionKind;
@@ -24,6 +56,16 @@ interface PurchaseAction {
24
56
  /** For buyer_details: the form and the field names it accepts. */
25
57
  form?: 'delivery' | 'billing' | 'store_order_contact';
26
58
  fields?: string[];
59
+ /**
60
+ * For budget_increase: the maximum is above maxCost. Answer
61
+ * `{ decision: 'raise', maxCostMinor }` with at least the maximum, or
62
+ * `{ decision: 'decline' }`.
63
+ */
64
+ budget?: {
65
+ estimate: PurchaseMoney;
66
+ maximum: PurchaseMoney;
67
+ maxCost: PurchaseMoney;
68
+ };
27
69
  /**
28
70
  * For buyer, cardholder and reviewer actions: the Conto page that completes
29
71
  * it. It works only inside a hosted buyer session or the dashboard, so it is
@@ -60,16 +102,17 @@ interface Purchase {
60
102
  phase: PurchasePhase;
61
103
  /** Increases by one with every visible change. */
62
104
  version: number;
63
- request: {
64
- url: string;
65
- task?: string;
66
- items?: PurchaseItem[];
67
- };
105
+ request: PurchaseRequest;
68
106
  maxCost: PurchaseMoney;
69
107
  quote: {
70
108
  merchant: string;
71
109
  description: string | null;
110
+ /** What limits and the card are held to: the maximum, until a receipt records the final total. */
72
111
  total: PurchaseMoney;
112
+ /** The store's own total. */
113
+ estimate: PurchaseMoney;
114
+ /** The most the order can come to. The same as the estimate for an exact total. */
115
+ maximum: PurchaseMoney;
73
116
  estimatedTax: boolean;
74
117
  } | null;
75
118
  requiredAction: PurchaseAction | null;
@@ -83,6 +126,8 @@ interface Purchase {
83
126
  message: string | null;
84
127
  };
85
128
  reasonCode: string | null;
129
+ /** With POLICY_DENIED on a company card: which limit refused the purchase. */
130
+ limitReached?: 'buyer_daily' | 'buyer_monthly' | 'buyer_daily_count' | 'store' | 'card_or_policy';
86
131
  cancellation: {
87
132
  requestedAt: string;
88
133
  } | null;
@@ -131,11 +176,7 @@ interface PurchaseList {
131
176
  }
132
177
  interface CreatePurchaseInput {
133
178
  buyerId: string;
134
- request: {
135
- url: string;
136
- task?: string;
137
- items?: PurchaseItem[];
138
- };
179
+ request: PurchaseRequest;
139
180
  /** The most this purchase may cost, delivered. It narrows the delegation, never widens it. */
140
181
  maxCost: PurchaseMoney;
141
182
  /**
@@ -148,8 +189,12 @@ interface CreatePurchaseInput {
148
189
  methodId: string;
149
190
  delegationId: string;
150
191
  };
151
- /** The buyer id, to use the buyer's saved delivery details. */
152
- buyerProfileId?: string;
192
+ /**
193
+ * The buyer's saved delivery details answer the store's delivery form when
194
+ * the buyer has them. Leave out to use them when present, pass the buyer id
195
+ * to require them, or null to never use them.
196
+ */
197
+ buyerProfileId?: string | null;
153
198
  }
154
199
  interface PurchaseResponseAck {
155
200
  id: string;
@@ -172,7 +217,7 @@ interface WatchPurchaseOptions {
172
217
  mode?: 'auto' | 'stream' | 'poll';
173
218
  /** Polling interval. Defaults to 2000 ms. */
174
219
  pollIntervalMs?: number;
175
- /** Stop waiting after this long. Defaults to no limit. */
220
+ /** Stop observing after this many milliseconds (0 stops immediately). Does not cancel the purchase. */
176
221
  maxWaitMs?: number;
177
222
  }
178
223
  declare const isFinalPurchaseStatus: (status: PurchaseStatus) => boolean;
@@ -192,7 +237,7 @@ type SseFrame = {
192
237
  data: string;
193
238
  };
194
239
  /** Parses server-sent events from a byte stream. */
195
- declare function parseServerSentEvents(body: ReadableStream<Uint8Array>): AsyncGenerator<SseFrame>;
240
+ declare function parseServerSentEvents(body: ReadableStream<Uint8Array>, signal?: AbortSignal): AsyncGenerator<SseFrame>;
196
241
  type RecurringPurchaseCycleStatus = 'checking' | 'scheduled' | 'needs_review' | 'paying' | 'paid' | 'skipped' | 'missed' | 'failed' | 'cancelled';
197
242
  /** A repeat order the buyer set up while approving a purchase on Conto's hosted page. */
198
243
  interface RecurringPurchase {
@@ -350,8 +395,132 @@ interface PurchasePaymentMethod {
350
395
  brand: string;
351
396
  last4: string;
352
397
  status: 'active' | 'removed';
398
+ /** `organization`: your company card, which this buyer draws from. */
399
+ owner: 'buyer' | 'organization';
400
+ companyCardId?: string;
353
401
  createdAt: string;
354
402
  }
403
+ /** A card your organization pays its buyers' purchases with. */
404
+ interface PurchaseCompanyCard {
405
+ id: string;
406
+ object: 'company_card';
407
+ environment: 'live' | 'test';
408
+ brand: string;
409
+ last4: string;
410
+ status: 'active' | 'removed';
411
+ /** The most one order may cost, and the most all buyers together may spend in a month. */
412
+ limits: {
413
+ perPurchaseMinor: number;
414
+ monthlyMinor: number;
415
+ currency: 'USD';
416
+ };
417
+ createdAt: string;
418
+ }
419
+ /** One buyer's limits on a company card. */
420
+ interface PurchaseBuyerCompanyCardLimits {
421
+ perPurchaseMinor: number;
422
+ dailyMinor: number;
423
+ monthlyMinor: number;
424
+ /**
425
+ * Orders above this wait for your `purchase_review` answer. Left out,
426
+ * every order up to `perPurchaseMinor` goes ahead without review.
427
+ */
428
+ reviewAboveMinor?: number;
429
+ }
430
+ interface PurchaseBuyerCompanyCard {
431
+ object: 'buyer_company_card';
432
+ buyerId: string;
433
+ companyCardId: string;
434
+ paymentMethodId: string;
435
+ delegationId: string;
436
+ limits: Omit<PurchaseBuyerCompanyCardLimits, 'reviewAboveMinor'> & {
437
+ reviewAboveMinor: number | null;
438
+ currency: 'USD';
439
+ };
440
+ }
441
+ /** What a buyer has at home, as your app reports it. Buyer data for the agent, never instructions. */
442
+ type PurchaseKitchenContext = {
443
+ version: 1;
444
+ /** When your app took the snapshot. ISO 8601. */
445
+ capturedAt: string;
446
+ inventory?: PurchaseKitchenInventoryItem[];
447
+ usuals?: PurchaseKitchenUsual[];
448
+ preferences?: PurchaseKitchenPreferences;
449
+ /** Only the recipes the buyer picked to cook. */
450
+ recipes?: PurchaseKitchenRecipe[];
451
+ /** The list the buyer keeps in your app. */
452
+ list?: PurchaseKitchenListItem[];
453
+ };
454
+ interface PurchaseKitchenInventoryItem {
455
+ item: string;
456
+ quantity?: number;
457
+ unit?: string;
458
+ /** Left out: ok, or out when quantity is 0. */
459
+ level?: 'ok' | 'low' | 'out';
460
+ updatedAt?: string;
461
+ expiresAt?: string;
462
+ }
463
+ interface PurchaseKitchenUsual {
464
+ item: string;
465
+ typicalQuantity?: number;
466
+ unit?: string;
467
+ size?: string;
468
+ brand?: string;
469
+ cadenceDays?: number;
470
+ lastBoughtAt?: string;
471
+ }
472
+ interface PurchaseKitchenPreferences {
473
+ dietary?: Array<{
474
+ value: string;
475
+ strength: 'required' | 'preferred';
476
+ }>;
477
+ avoidBrands?: string[];
478
+ likeBrands?: string[];
479
+ organic?: 'prefer' | 'avoid' | 'none';
480
+ substitutions?: 'allow' | 'ask' | 'never';
481
+ /** An https store link, such as an Instacart storefront. */
482
+ preferredStore?: string;
483
+ householdSize?: number;
484
+ weeklyBudgetMinor?: number;
485
+ }
486
+ interface PurchaseKitchenRecipe {
487
+ id?: string;
488
+ title: string;
489
+ servings?: number;
490
+ /** The planned day, as YYYY-MM-DD. */
491
+ cookOn?: string;
492
+ /** Whether your app finds it cookable from what is at home. */
493
+ cookable?: boolean;
494
+ ingredients: Array<{
495
+ item: string;
496
+ quantity?: number;
497
+ unit?: string;
498
+ optional?: boolean;
499
+ }>;
500
+ }
501
+ interface PurchaseKitchenListItem {
502
+ item: string;
503
+ quantity?: number;
504
+ unit?: string;
505
+ note?: string;
506
+ }
507
+ interface PurchaseBuyerKitchenContext {
508
+ object: 'buyer_kitchen_context';
509
+ buyerId: string;
510
+ /** Null when nothing was pushed. */
511
+ context: PurchaseKitchenContext | null;
512
+ summary: {
513
+ capturedAt: string;
514
+ inventory: number;
515
+ low: number;
516
+ out: number;
517
+ usuals: number;
518
+ recipes: number;
519
+ list: number;
520
+ } | null;
521
+ /** When Conto received the snapshot. */
522
+ receivedAt: string | null;
523
+ }
355
524
  interface PurchaseDelegation {
356
525
  id: string;
357
526
  object: 'delegation';
@@ -363,9 +532,14 @@ interface PurchaseDelegation {
363
532
  limits: {
364
533
  perPurchaseMinor: number;
365
534
  dailyMinor: number;
535
+ /** Company card only. */
536
+ monthlyMinor?: number;
537
+ /** Company card only: orders above this wait for your review. */
538
+ reviewAboveMinor?: number;
366
539
  currency: 'USD';
367
540
  };
368
- requiresPurchaseReview: true;
541
+ /** false for a company card delegation, which you review above `reviewAboveMinor` only. */
542
+ requiresPurchaseReview: boolean;
369
543
  requiresCardVerification: boolean;
370
544
  createdAt: string;
371
545
  revokedAt: string | null;
@@ -380,6 +554,39 @@ interface PurchaseHostedLink {
380
554
  url: string;
381
555
  expiresAt: string;
382
556
  }
557
+ /** Buyer-approved spending at one store; not a merchant-independent allowance. */
558
+ interface PurchaseAllowance {
559
+ id: string;
560
+ object: 'allowance';
561
+ buyerId: string;
562
+ agentId: string;
563
+ delegationId: string;
564
+ paymentMethodId: string;
565
+ environment: 'live' | 'test';
566
+ status: 'pending_verification' | 'active' | 'revoked' | 'expired';
567
+ kind: 'store' | 'recurrence';
568
+ merchant: {
569
+ name: string;
570
+ origin: string;
571
+ };
572
+ limits: {
573
+ perPurchaseMinor: number;
574
+ periodMinor: number;
575
+ period: 'day' | 'week' | 'month';
576
+ totalMinor: number;
577
+ currency: 'USD';
578
+ };
579
+ expiresAt: string;
580
+ createdAt: string;
581
+ activatedAt: string | null;
582
+ revokedAt: string | null;
583
+ }
584
+ interface PurchasingSettings {
585
+ /** Origins a hosted page may return the buyer to. */
586
+ allowedReturnOrigins: string[];
587
+ /** Whether Conto emails buyers about their purchases. On by default. */
588
+ buyerEmails: boolean;
589
+ }
383
590
  interface PurchasingCapabilities {
384
591
  object: 'purchasing_capabilities';
385
592
  /** Test mode is open to every organization. Live needs Conto to enable it. */
@@ -389,6 +596,7 @@ interface PurchasingCapabilities {
389
596
  }>;
390
597
  currencies: string[];
391
598
  cardNetworks: string[];
599
+ /** Checkout paths: `browser_checkout`, `store_order` and `test_store`. */
392
600
  executors: Array<{
393
601
  executor: string;
394
602
  available: boolean;
@@ -398,6 +606,10 @@ interface PurchasingCapabilities {
398
606
  allowances?: Record<'test' | 'live', {
399
607
  available: boolean;
400
608
  }>;
609
+ /** Whether your app can push what its buyers have at home. */
610
+ kitchenContext?: {
611
+ available: boolean;
612
+ };
401
613
  unsupported: Array<{
402
614
  capability: string;
403
615
  reason: string;
@@ -429,6 +641,18 @@ declare class AdminPurchasingClient {
429
641
  constructor(client: AdminTransport);
430
642
  /** Buyers' repeat orders: list, read, start or skip an order, and cancel. */
431
643
  readonly recurringPurchases: OrganizationRecurringPurchasesClient;
644
+ /** Inspect or revoke buyer-approved allowances. Grants remain on the buyer's hosted page. */
645
+ readonly allowances: {
646
+ /** Returns up to 50 allowances for this buyer, newest first. */
647
+ list: (params: {
648
+ buyerId: string;
649
+ }) => Promise<{
650
+ items: PurchaseAllowance[];
651
+ }>;
652
+ get: (id: string) => Promise<PurchaseAllowance>;
653
+ /** Stops future credential release; does not undo payments already submitted. */
654
+ revoke: (id: string) => Promise<PurchaseAllowance>;
655
+ };
432
656
  readonly buyers: {
433
657
  /** Maps one of your users to a buyer with its own agent, or returns the existing one. */
434
658
  create: (input: {
@@ -447,6 +671,56 @@ declare class AdminPurchasingClient {
447
671
  }>;
448
672
  /** Stops the buyer's agent. Purchases that may already be paid stay visible. */
449
673
  stop: (id: string) => Promise<PurchaseBuyer>;
674
+ /**
675
+ * Lets the buyer pay with your company card within limits you set for
676
+ * them, or replaces those limits. The buyer must not have their own card.
677
+ */
678
+ setCompanyCard: (id: string, input: {
679
+ companyCardId: string;
680
+ limits: PurchaseBuyerCompanyCardLimits;
681
+ }) => Promise<PurchaseBuyerCompanyCard>;
682
+ /** The buyer stops paying with your company card. */
683
+ removeCompanyCard: (id: string) => Promise<{
684
+ buyerId: string;
685
+ object: "buyer_company_card";
686
+ removed: true;
687
+ }>;
688
+ /**
689
+ * Replaces what the buyer has at home: inventory, usuals, preferences,
690
+ * chosen recipes and their list. The whole snapshot, every time. Needs
691
+ * Conto to enable kitchen context for your organization.
692
+ */
693
+ setKitchenContext: (id: string, context: PurchaseKitchenContext) => Promise<PurchaseBuyerKitchenContext>;
694
+ /** The snapshot Conto holds, with context null when nothing was pushed. */
695
+ getKitchenContext: (id: string) => Promise<PurchaseBuyerKitchenContext>;
696
+ clearKitchenContext: (id: string) => Promise<{
697
+ buyerId: string;
698
+ object: "buyer_kitchen_context";
699
+ removed: true;
700
+ }>;
701
+ };
702
+ /** Cards your organization pays its buyers' purchases with. Test cards only for now. */
703
+ readonly companyCards: {
704
+ create: (input: {
705
+ environment: "live" | "test";
706
+ limits: {
707
+ perPurchaseMinor: number;
708
+ monthlyMinor: number;
709
+ };
710
+ }) => Promise<PurchaseCompanyCard>;
711
+ list: () => Promise<{
712
+ items: PurchaseCompanyCard[];
713
+ }>;
714
+ get: (id: string) => Promise<PurchaseCompanyCard>;
715
+ /** Changes the card's own caps. Each buyer's limits stay as they are. */
716
+ update: (id: string, input: {
717
+ limits: {
718
+ perPurchaseMinor: number;
719
+ monthlyMinor: number;
720
+ };
721
+ }) => Promise<PurchaseCompanyCard>;
722
+ /** No buyer can start or pay a purchase with the card after this. */
723
+ remove: (id: string) => Promise<PurchaseCompanyCard>;
450
724
  };
451
725
  readonly paymentMethods: {
452
726
  /** A single-use link to the hosted setup page: limits, card and delegation. */
@@ -477,14 +751,12 @@ declare class AdminPurchasingClient {
477
751
  */
478
752
  readonly purchases: OrganizationPurchasesClient;
479
753
  readonly settings: {
480
- get: () => Promise<{
481
- allowedReturnOrigins: string[];
482
- }>;
754
+ get: () => Promise<PurchasingSettings>;
755
+ /** Changes only the fields you pass. */
483
756
  update: (input: {
484
- allowedReturnOrigins: string[];
485
- }) => Promise<{
486
- allowedReturnOrigins: string[];
487
- }>;
757
+ allowedReturnOrigins?: string[];
758
+ buyerEmails?: boolean;
759
+ }) => Promise<PurchasingSettings>;
488
760
  };
489
761
  /** What this organization can run now: test mode always, live once Conto enables it. */
490
762
  capabilities(): Promise<PurchasingCapabilities>;
@@ -2209,21 +2481,34 @@ interface BeginCheckoutCheckpointInput {
2209
2481
  /** Defaults to one Total entry equal to amountMinor. */
2210
2482
  totals?: CommerceTotalInput[];
2211
2483
  }
2484
+ /**
2485
+ * The payment behind a checkout, such as the Link spend request that issued a
2486
+ * Link card. An id only, never card data.
2487
+ */
2488
+ interface CheckoutPaymentReference {
2489
+ provider: 'LINK';
2490
+ /** The Link spend request id, such as lsrq_... */
2491
+ id: string;
2492
+ }
2212
2493
  /** Second checkpoint: the final total shown right before the payment is submitted. */
2213
2494
  interface ConfirmCheckoutCheckpointInput {
2214
2495
  amountMinor: number;
2215
2496
  currency?: 'USD';
2216
- /** Final line items, needed only when the total changed. Defaults to the approved items. */
2497
+ /** Observed final items. Supplied items are checked even when the total is unchanged. */
2217
2498
  lineItems?: CommerceLineItemInput[];
2218
- /** Final totals, such as tax and shipping. Defaults to one Total entry. */
2499
+ /** Observed final charges. Supplied charges are checked even when the total is unchanged. */
2219
2500
  totals?: CommerceTotalInput[];
2220
2501
  /** Page where the payment is submitted: the merchant's site or the payment method's. */
2221
2502
  pageUrl?: string;
2503
+ /** The Link card's spend request, from getLinkCard(). */
2504
+ paymentReference?: CheckoutPaymentReference;
2222
2505
  }
2223
2506
  interface ReportCheckoutOutcomeInput {
2224
2507
  outcome: CheckoutOutcome;
2225
2508
  /** Merchant order or receipt number. Never a payment credential. */
2226
2509
  reference?: string;
2510
+ /** The Link card's spend request, from getLinkCard(). */
2511
+ paymentReference?: CheckoutPaymentReference;
2227
2512
  }
2228
2513
  interface CheckoutCheckpoint {
2229
2514
  id: string;
@@ -2250,6 +2535,8 @@ interface CheckoutCheckpoint {
2250
2535
  /** Present when the agent's rules sent this purchase to the owner for approval. */
2251
2536
  approval?: CheckoutCheckpointApproval;
2252
2537
  outcomeReference?: string;
2538
+ /** The payment your checkout reported at confirm or outcome, such as a Link spend request. */
2539
+ paymentReference?: CheckoutPaymentReference;
2253
2540
  /** Outcomes are reported by your checkout. Conto does not verify settlement here. */
2254
2541
  settlementVerified: false;
2255
2542
  }
@@ -2266,6 +2553,45 @@ interface WaitForCheckoutApprovalOptions {
2266
2553
  pollIntervalMs?: number;
2267
2554
  signal?: AbortSignal;
2268
2555
  }
2556
+
2557
+ /**
2558
+ * A Link card for one purchase: the checkpoint begin input plus the Link
2559
+ * wallet that runs in your environment. The checkout method is always LINK.
2560
+ */
2561
+ interface GetLinkCardInput extends Omit<BeginCheckoutCheckpointInput, 'checkoutMethod'> {
2562
+ /** For example linkCliWallet() from @conto_finance/sdk/link-wallet. */
2563
+ wallet: LinkWallet;
2564
+ /** How long to wait for the owner when a rule requires approval. Defaults to 10 minutes. */
2565
+ ownerApprovalTimeoutMs?: number;
2566
+ /** How long to wait for the person to approve in Link. Defaults to 10 minutes. */
2567
+ linkApprovalTimeoutMs?: number;
2568
+ signal?: AbortSignal;
2569
+ }
2570
+ /** A new Link card for a changed final total. */
2571
+ interface ReplaceLinkCardInput {
2572
+ wallet: LinkWallet;
2573
+ /** The final total in cents, including shipping and tax. */
2574
+ amountMinor: number;
2575
+ /** Final line items. Defaults to the approved items. */
2576
+ lineItems?: CommerceLineItemInput[];
2577
+ /** Final totals, such as tax and shipping. Defaults to one Total entry. */
2578
+ totals?: CommerceTotalInput[];
2579
+ ownerApprovalTimeoutMs?: number;
2580
+ linkApprovalTimeoutMs?: number;
2581
+ signal?: AbortSignal;
2582
+ }
2583
+ interface LinkCardResult {
2584
+ /** The approved checkpoint. Pass it to confirm() right before paying. */
2585
+ checkpoint: CheckoutCheckpoint;
2586
+ /**
2587
+ * Live card data for this purchase only. It stays in this process: printing
2588
+ * or serializing the result shows only the last four digits.
2589
+ */
2590
+ card: LinkCardCredential;
2591
+ linkRequestId: string;
2592
+ /** Pass to confirm() and reportOutcome() so the owner sees which Link request paid. */
2593
+ paymentReference: CheckoutPaymentReference;
2594
+ }
2269
2595
  /** Exact Stripe Link purchase intent evaluated and bound by Conto policy. */
2270
2596
  interface BeginCommerceExecutionCommonInput {
2271
2597
  /** Stable key for this exact intent. Reuse it when reconciling or retrying begin. */
@@ -2957,6 +3283,41 @@ declare class CheckoutApprovalTimeoutError extends ContoError {
2957
3283
  readonly checkpoint: CheckoutCheckpoint;
2958
3284
  constructor(checkpoint: CheckoutCheckpoint);
2959
3285
  }
3286
+ /**
3287
+ * getLinkCard() or replaceLinkCard() stopped after Conto approved the purchase.
3288
+ * No card was returned. Conto cancelled the checkpoint to release the held
3289
+ * spend unless holdReleased is false. Do not pay.
3290
+ */
3291
+ declare class LinkCardError extends ContoError {
3292
+ readonly checkpoint: CheckoutCheckpoint;
3293
+ readonly linkRequestId?: string;
3294
+ /** True when Conto cancelled the checkpoint and released the held spend. */
3295
+ readonly holdReleased: boolean;
3296
+ constructor(input: {
3297
+ message: string;
3298
+ code: string;
3299
+ checkpoint: CheckoutCheckpoint;
3300
+ linkRequestId?: string;
3301
+ holdReleased: boolean;
3302
+ retryGuidance?: string;
3303
+ });
3304
+ }
3305
+ /** The person declined the Link card request, or it was cancelled in Link. */
3306
+ declare class LinkCardDeniedError extends LinkCardError {
3307
+ constructor(input: ConstructorParameters<typeof LinkCardError>[0]);
3308
+ }
3309
+ /** The Link card request expired before the person approved it. */
3310
+ declare class LinkCardExpiredError extends LinkCardError {
3311
+ constructor(input: ConstructorParameters<typeof LinkCardError>[0]);
3312
+ }
3313
+ /** The person did not approve in Link before linkApprovalTimeoutMs. Conto cancelled the request. */
3314
+ declare class LinkCardTimeoutError extends LinkCardError {
3315
+ constructor(input: ConstructorParameters<typeof LinkCardError>[0]);
3316
+ }
3317
+ /** The Link wallet cannot run here: link-cli is not installed or not logged in. */
3318
+ declare class LinkWalletUnavailableError extends LinkCardError {
3319
+ constructor(input: ConstructorParameters<typeof LinkCardError>[0]);
3320
+ }
2960
3321
  interface ContoRequestOptions {
2961
3322
  /** Set only when repeating this request cannot create an additional side effect. */
2962
3323
  idempotent?: boolean;
@@ -3396,6 +3757,37 @@ declare class CheckoutClient {
3396
3757
  */
3397
3758
  cancel(checkpointId: string): Promise<CheckoutCheckpoint>;
3398
3759
  get(checkpointId: string): Promise<CheckoutCheckpoint>;
3760
+ /**
3761
+ * Get a Stripe Link card for one purchase, issued only after Conto approves
3762
+ * it. Call this at the payment step, once the final total with shipping and
3763
+ * tax is known.
3764
+ *
3765
+ * 1. Conto runs checkpoint 1 and holds the spend. When a rule requires the
3766
+ * owner's approval, this waits for it.
3767
+ * 2. Only then does the wallet ask Link for a card for exactly the approved
3768
+ * amount at this merchant. The person approves it in their Link app.
3769
+ * 3. The card is returned. It never reaches Conto.
3770
+ *
3771
+ * Then fill in the card, call confirm(result.checkpoint, { amountMinor,
3772
+ * paymentReference: result.paymentReference }) right before paying, pay only
3773
+ * if it resolves, and report the outcome. If the final total differs, call
3774
+ * replaceLinkCard() instead of confirming.
3775
+ *
3776
+ * A Conto denial throws before Link is called. When Link declines, expires,
3777
+ * times out, or is unavailable, this cancels the checkpoint to release the
3778
+ * held spend and throws a LinkCardError. When Conto cannot cancel an open Link
3779
+ * request, it keeps the hold and throws LINK_CARD_NOT_CANCELLED with the
3780
+ * request id. Retrying with the same input resumes the same checkpoint and
3781
+ * Link request.
3782
+ */
3783
+ getLinkCard(input: GetLinkCardInput): Promise<LinkCardResult>;
3784
+ /**
3785
+ * The final total differs from the one the Link card covers. This cancels
3786
+ * the old Link request and checkpoint, begins a checkpoint at the final
3787
+ * total (waiting for the owner when a rule requires it), and gets a new card
3788
+ * for it. Confirm the returned checkpoint with the same total.
3789
+ */
3790
+ replaceLinkCard(previous: LinkCardResult, input: ReplaceLinkCardInput): Promise<LinkCardResult>;
3399
3791
  }
3400
3792
 
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 };
3793
+ 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 CheckoutPaymentReference, 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, type GetLinkCardInput, Conto as Giro, type ContoConfig as GiroConfig, ContoError as GiroError, type GuardCheckoutResult, type GuardedBrowserDispatchResult, type GuardedCheckoutInput, LinkCardCredential, LinkCardDeniedError, LinkCardError, LinkCardExpiredError, type LinkCardResult, LinkCardTimeoutError, LinkWallet, type LinkWalletInput, LinkWalletUnavailableError, 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 PurchaseAllowance, type PurchaseBuyer, type PurchaseBuyerCompanyCard, type PurchaseBuyerCompanyCardLimits, type PurchaseBuyerKitchenContext, type PurchaseCompanyCard, type PurchaseDelegation, type PurchaseEvent, type PurchaseEventPage, type PurchaseEvidence, type PurchaseGroceryItem, type PurchaseGroceryList, type PurchaseHostedLink, type PurchaseItem, type PurchaseKitchenContext, type PurchaseKitchenInventoryItem, type PurchaseKitchenListItem, type PurchaseKitchenPreferences, type PurchaseKitchenRecipe, type PurchaseKitchenUsual, type PurchaseList, type PurchaseMoney, type PurchasePaymentMethod, type PurchasePhase, type PurchaseRequest, type PurchaseResponseAck, type PurchaseStatus, PurchasesClient, type PurchasingCapabilities, type PurchasingSettings, type RecurringPurchase, type RecurringPurchaseCycleResult, type RecurringPurchaseCycleStatus, RecurringPurchasesClient, type RefreshBalanceResult, type RegisterExternalCardInput, type ReplaceLinkCardInput, 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 };