@thorprovider/types 7.6.0 → 7.8.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/src/checkout.ts CHANGED
@@ -62,6 +62,23 @@ export interface CheckoutContactValues {
62
62
  phone: string;
63
63
  }
64
64
 
65
+ /**
66
+ * Guest contact stored on the cart/order (never on the Customer record).
67
+ *
68
+ * The email is authoritative on `Cart.email`; this shape carries the display
69
+ * name and phone the shopper entered for the order.
70
+ */
71
+ export interface GuestContact {
72
+ firstName: string;
73
+ lastName: string;
74
+ phone: string;
75
+ }
76
+
77
+ /** Guest contact payload accepted by the checkout contact route. */
78
+ export interface CheckoutGuestContact extends GuestContact {
79
+ email: string;
80
+ }
81
+
65
82
  /** Authenticated identity mapped by the host. No token or raw customer object. */
66
83
  export interface CheckoutCustomerIdentity {
67
84
  id: string;
@@ -20,6 +20,7 @@ import type {
20
20
  Cart,
21
21
  CartLineInput,
22
22
  CartLineUpdate,
23
+ CheckoutLineProjection,
23
24
  ShippingMethod
24
25
  } from './cart';
25
26
  import type {
@@ -39,7 +40,13 @@ import type {
39
40
  CustomerOrdersPage,
40
41
  } from './order';
41
42
  import type { Region } from './region';
42
- import type { PaymentMethod, PaymentMethodsOptions } from './payment';
43
+ import type {
44
+ PaymentMethod,
45
+ PaymentMethodsOptions,
46
+ GiftCardValidationResult,
47
+ StoreCreditAccountSummary,
48
+ } from './payment';
49
+ import type { CheckoutGuestContact } from './checkout';
43
50
  import type { AuthProvider } from './auth';
44
51
  import type { StorefrontContext } from './storefront';
45
52
  import type { StockLocation, InventoryLevel, StockValidation, FulfillmentOption } from './stock-location';
@@ -540,7 +547,7 @@ export interface CommerceProvider {
540
547
  * @param options.regionId - Region ID for the cart (required for some providers like Medusa)
541
548
  * @returns New cart instance
542
549
  */
543
- createCart(options?: { regionId?: string }): Promise<Cart>;
550
+ createCart(options?: { regionId?: string; salesChannelId?: string }): Promise<Cart>;
544
551
 
545
552
  /**
546
553
  * Get an existing cart by ID
@@ -562,6 +569,23 @@ export interface CommerceProvider {
562
569
  * @throws {ProviderAPIError} If the cart cannot be transferred
563
570
  */
564
571
  assignCartToCustomer?(cartId: string): Promise<Cart>;
572
+
573
+ /**
574
+ * Persist the guest checkout contact (email + name + phone) on the cart.
575
+ *
576
+ * The backend writes `cart.email` and merges
577
+ * `cart.metadata.guest_contact`; it never writes the Customer record. The
578
+ * provider must carry no customer token: the cart id is the capability and
579
+ * the backend enforces the guest/channel rules.
580
+ *
581
+ * @param cartId - Cart ID
582
+ * @param contact - Guest contact values
583
+ * @returns The updated cart with the contact stored
584
+ */
585
+ updateCheckoutGuestContact?(
586
+ cartId: string,
587
+ contact: CheckoutGuestContact,
588
+ ): Promise<Cart>;
565
589
 
566
590
  /**
567
591
  * Add items to cart
@@ -739,6 +763,23 @@ export interface CommerceProvider {
739
763
  cartId: string,
740
764
  selections: ShippingGroupSelection[],
741
765
  ): Promise<void>;
766
+
767
+ /**
768
+ * Project stock and the effective quantity-price ladder for each cart line
769
+ * (OPTIONAL).
770
+ *
771
+ * The backend selects the effective price group with Medusa's pricing engine
772
+ * and reports the maximum number of complete units a single sales-channel
773
+ * warehouse can serve. Callers render the values; they never sum stock across
774
+ * warehouses, mix price groups or derive a price locally.
775
+ *
776
+ * Optional for the same reason as `getCheckoutShippingGroups`; its absence
777
+ * is an unsupported capability, not an empty projection.
778
+ *
779
+ * @param cartId - Cart ID
780
+ * @throws {ProviderAPIError} If the backend fails or returns an invalid projection
781
+ */
782
+ getCheckoutLineProjection?(cartId: string): Promise<CheckoutLineProjection>;
742
783
 
743
784
  /**
744
785
  * Initiate payment session with provider
@@ -913,6 +954,18 @@ export interface CommerceProvider {
913
954
  * @returns Order or undefined if not found
914
955
  */
915
956
  getOrder?(orderId: string): Promise<Order | undefined>;
957
+
958
+ /**
959
+ * Read a single order through the channel-scoped guest receipt route
960
+ * (OPTIONAL).
961
+ *
962
+ * Unlike `getOrder`, the backend resolves the sales channel from the
963
+ * publishable key and returns 404 for an order from another channel. The
964
+ * runtime uses it for the unauthenticated confirmation page; a provider
965
+ * without it falls back to `getOrder` and must expose `Order.salesChannelId`
966
+ * so the runtime can verify the channel itself.
967
+ */
968
+ getCheckoutOrder?(orderId: string): Promise<Order | undefined>;
916
969
 
917
970
  /**
918
971
  * Get all orders for a customer (optional)
@@ -993,6 +1046,40 @@ export interface CommerceProvider {
993
1046
  */
994
1047
  getPaymentMethods(options: PaymentMethodsOptions): Promise<PaymentMethod[]>;
995
1048
 
1049
+ /**
1050
+ * Validate a gift-card code before it is added to the checkout payment plan
1051
+ * (OPTIONAL).
1052
+ *
1053
+ * Read-only: it must not create a payment session, reserve balance or mutate
1054
+ * the cart. The backend remains the authority; a valid result can still be
1055
+ * rejected when the plan is completed if the balance or currency changed.
1056
+ *
1057
+ * Optional so a provider without gift-card support keeps its existing
1058
+ * contract; callers must treat its absence as an unsupported capability
1059
+ * rather than as an invalid gift card.
1060
+ *
1061
+ * @param code - Gift-card code supplied by the shopper
1062
+ * @returns The backend's validation result, including balance and status
1063
+ * @throws {ProviderAPIError} If the backend fails or returns an invalid shape
1064
+ */
1065
+ validateGiftCard?(code: string): Promise<GiftCardValidationResult>;
1066
+
1067
+ /**
1068
+ * List the authenticated customer's store-credit accounts (OPTIONAL).
1069
+ *
1070
+ * Read-only: it must not create a payment session or debit the account. The
1071
+ * checkout filters these accounts by the cart currency and lets the shopper
1072
+ * choose one; the backend validates the account and amount again when the
1073
+ * payment plan is completed.
1074
+ *
1075
+ * Optional for the same reason as {@link validateGiftCard}.
1076
+ *
1077
+ * @returns Store-credit accounts with their backend-authoritative balances
1078
+ * @throws {ProviderAPIError} If the customer is not authenticated or the
1079
+ * backend fails
1080
+ */
1081
+ getStoreCreditAccounts?(): Promise<StoreCreditAccountSummary[]>;
1082
+
996
1083
  // ============================================
997
1084
  // Inventory Operations (Admin API — Optional)
998
1085
  // ============================================
package/src/common.ts CHANGED
@@ -93,3 +93,36 @@ export interface Country {
93
93
  /** ISO 3166-1 numeric code (optional, e.g., "840", "724") */
94
94
  numCode?: string;
95
95
  }
96
+
97
+ /**
98
+ * How a promotion was applied.
99
+ *
100
+ * - `coupon`: the shopper entered a code.
101
+ * - `automatic`: the backend applied it without a code.
102
+ * - `discount`: an adjustment whose promotion identity is not available.
103
+ */
104
+ export type PromotionKind = 'coupon' | 'automatic' | 'discount';
105
+
106
+ /**
107
+ * Where a promotion was applied, as far as the backend adjustments reveal.
108
+ *
109
+ * `items` and `shipping` are derived from the adjustment location. `order` is
110
+ * used when no adjustment location is available yet (for example a code applied
111
+ * before a shipping method exists).
112
+ */
113
+ export type PromotionScope = 'order' | 'items' | 'shipping';
114
+
115
+ /**
116
+ * One promotion row from the backend's discount adjustments.
117
+ *
118
+ * `amount` is the sum of the adjustments attributed to this promotion, never a
119
+ * locally computed percentage or configured value.
120
+ */
121
+ export interface PromotionSummary {
122
+ id: string;
123
+ code?: string;
124
+ label: string;
125
+ kind: PromotionKind;
126
+ scope: PromotionScope;
127
+ amount: Money;
128
+ }
package/src/index.ts CHANGED
@@ -18,6 +18,9 @@ export type {
18
18
  PaginationOptions,
19
19
  SortOptions,
20
20
  Country,
21
+ PromotionKind,
22
+ PromotionScope,
23
+ PromotionSummary,
21
24
  } from './common';
22
25
 
23
26
  // ============================================
@@ -40,6 +43,8 @@ export type {
40
43
  CheckoutLocationOptions,
41
44
  CheckoutAddressValues,
42
45
  CheckoutContactValues,
46
+ GuestContact,
47
+ CheckoutGuestContact,
43
48
  CheckoutCustomerIdentity,
44
49
  CheckoutSavedAddress,
45
50
  CheckoutShippingOption,
@@ -140,6 +145,9 @@ export type {
140
145
  CartLineUpdate,
141
146
  ShippingMethod,
142
147
  DiscountCode,
148
+ PriceTier,
149
+ CheckoutLineProjection,
150
+ CheckoutLineProjectionLine,
143
151
  } from './cart';
144
152
 
145
153
  // ============================================
@@ -196,6 +204,8 @@ export type {
196
204
  Order,
197
205
  OrderDeliveryGroup,
198
206
  OrderItem,
207
+ OrderPayment,
208
+ OrderPaymentStatus,
199
209
  OrderStatus,
200
210
  PaymentStatus,
201
211
  FulfillmentStatus,
@@ -276,6 +286,13 @@ export type {
276
286
  PaymentMethodFeatures,
277
287
  PaymentMethodsOptions,
278
288
  CachedPaymentMethods,
289
+ CheckoutCapturePolicy,
290
+ CheckoutPaymentPlanItem,
291
+ GiftCardValidationResult,
292
+ StoreCreditAccountSummary,
293
+ CheckoutPaymentSummary,
294
+ CheckoutPaymentSummaryPayment,
295
+ CheckoutPaymentSummaryStatus,
279
296
  } from './payment';
280
297
 
281
298
  // ============================================
package/src/order.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  * Universal interfaces compatible with: Shopify, Medusa.js, WooCommerce, Magento, BigCommerce
5
5
  */
6
6
 
7
- import type { Money, Image } from './common';
7
+ import type { Money, Image, PromotionSummary } from './common';
8
8
  import type { Address, Customer } from './customer';
9
9
 
10
10
  /**
@@ -97,10 +97,27 @@ export interface OrderDeliveryGroup {
97
97
  /**
98
98
  * Order-line ids belonging to this group, only when the backend exposes the
99
99
  * membership. Consumers MUST NOT invent an assignment when it is absent.
100
+ * A line whose allocations span more than one group is ambiguous and is
101
+ * omitted from every group rather than assigned arbitrarily.
100
102
  */
101
103
  lineIds?: string[];
102
104
  }
103
105
 
106
+ /** One payment captured/authorized against an order. */
107
+ export type OrderPaymentStatus = 'authorized' | 'captured' | 'canceled' | 'pending';
108
+
109
+ export interface OrderPayment {
110
+ id: string;
111
+ providerId: string;
112
+ /** Provider display label when the adapter can resolve one. */
113
+ label?: string;
114
+ /** Payment amount in the order currency. */
115
+ amount?: Money;
116
+ status: OrderPaymentStatus;
117
+ capturedAt?: string;
118
+ canceledAt?: string;
119
+ }
120
+
104
121
  /**
105
122
  * Order
106
123
  *
@@ -123,6 +140,14 @@ export interface Order {
123
140
  // Customer
124
141
  customerId?: string;
125
142
  customer?: Customer;
143
+ /**
144
+ * Sales channel the order belongs to (Medusa `sales_channel_id`).
145
+ *
146
+ * Carried so the runtime can prove a receipt belongs to the validated store
147
+ * channel before rendering it; a provider that cannot expose it leaves it
148
+ * absent and the receipt path fails closed.
149
+ */
150
+ salesChannelId?: string;
126
151
 
127
152
  // Items
128
153
  items: OrderItem[];
@@ -153,7 +178,20 @@ export interface Order {
153
178
  providerId?: string;
154
179
  label?: string;
155
180
  detail?: string;
181
+ amount?: Money;
182
+ capturedAt?: string;
156
183
  };
184
+ /**
185
+ * Every payment on the order, when the backend reports them. Kept separate
186
+ * from `payment` (the first/primary payment) so a multi-instrument checkout
187
+ * can render its breakdown after a reload without inventing amounts.
188
+ */
189
+ payments?: OrderPayment[];
190
+ /**
191
+ * One row per promotion resolved from the order's item and shipping
192
+ * adjustments. Absent when the backend does not expose a breakdown.
193
+ */
194
+ promotions?: PromotionSummary[];
157
195
  /** Backend tax rate in basis points, when the order reports one rate. */
158
196
  taxRateBps?: number;
159
197
 
package/src/payment.ts CHANGED
@@ -8,6 +8,8 @@
8
8
  * @see packages/adapters/PAYMENT_METHODS_ARCHITECTURE.md
9
9
  */
10
10
 
11
+ import type { Money } from './common';
12
+
11
13
  /**
12
14
  * Payment method type identifier
13
15
  * Normalized across all backends
@@ -22,11 +24,13 @@
22
24
  */
23
25
  export type PaymentMethodType =
24
26
  | 'card' // Credit/debit cards (Visa, Mastercard, Amex, etc.)
25
- | 'wallet' // Digital wallets (Apple Pay, Google Pay, PayPal)
26
- | 'bank_transfer' // Bank transfers (ACH, SEPA, wire transfer)
27
+ | 'wallet' // Digital wallets (Apple Pay, Google Pay, PayPal, Cash App)
28
+ | 'bank_transfer' // Bank transfers (ACH, SEPA, wire transfer, Zelle)
27
29
  | 'buy_now_pay_later' // BNPL services (Klarna, Affirm, Afterpay)
28
30
  | 'cash_on_delivery' // Cash on delivery / Manual payment
29
31
  | 'crypto' // Cryptocurrency payments
32
+ | 'gift_card' // Redeemable gift-card balance
33
+ | 'store_credit' // Customer store-credit balance
30
34
  | 'other'; // Custom or unclassified methods
31
35
 
32
36
  /**
@@ -257,3 +261,96 @@ export interface CachedPaymentMethods {
257
261
  */
258
262
  ttl: number;
259
263
  }
264
+
265
+ /**
266
+ * When a checkout payment is captured.
267
+ *
268
+ * - `now`: captured as part of the checkout completion (gift card, store credit,
269
+ * card/PSP that supports immediate capture).
270
+ * - `deferred`: authorized at checkout and captured later by the admin (Zelle,
271
+ * Cash App, system/manual methods).
272
+ */
273
+ export type CheckoutCapturePolicy = 'now' | 'deferred'
274
+
275
+ /**
276
+ * One instrument of the checkout payment plan.
277
+ *
278
+ * The backend is authoritative: `amount` is the exact amount for this
279
+ * instrument and the plan must sum to the cart total. Gift card and store credit
280
+ * carry the data the backend needs to validate and create the payment session.
281
+ */
282
+ export interface CheckoutPaymentPlanItem {
283
+ provider_id: string
284
+ amount: number
285
+ capture: CheckoutCapturePolicy
286
+ /** Gift-card code; required when `provider_id` is the gift-card provider. */
287
+ gift_card_code?: string
288
+ /** Store-credit account id; resolved from the customer when omitted. */
289
+ account_id?: string
290
+ }
291
+
292
+ /**
293
+ * Result of validating a gift-card code before it is added to a payment plan.
294
+ *
295
+ * The backend is the authority: this is a read-only check, not a session or a
296
+ * reservation. The balance and currency belong to the gift card; a valid card
297
+ * can still be rejected later when the plan is completed if its balance or
298
+ * currency changed.
299
+ */
300
+ export type GiftCardValidationResult =
301
+ | {
302
+ valid: true
303
+ status: string
304
+ balance: Money
305
+ expiresAt?: string
306
+ }
307
+ | {
308
+ valid: false
309
+ reason: string
310
+ status?: string
311
+ }
312
+
313
+ /**
314
+ * One store-credit account available to the authenticated customer.
315
+ *
316
+ * Amounts are backend-authoritative. The checkout only offers accounts whose
317
+ * currency matches the cart currency; the backend still validates the account
318
+ * and amount again when the payment plan is completed.
319
+ */
320
+ export interface StoreCreditAccountSummary {
321
+ id: string
322
+ currencyCode: string
323
+ balance: Money
324
+ credits?: Money
325
+ debits?: Money
326
+ }
327
+
328
+ /**
329
+ * Authoritative payment state returned by the checkout completion.
330
+ *
331
+ * `captured_amount` and `pending_amount` are separate from `total`: the order
332
+ * total is never reduced by a payment.
333
+ */
334
+ export interface CheckoutPaymentSummaryPayment {
335
+ id: string
336
+ provider_id: string
337
+ amount: number
338
+ capture: CheckoutCapturePolicy
339
+ captured_at: string | null
340
+ }
341
+
342
+ export type CheckoutPaymentSummaryStatus =
343
+ | 'captured'
344
+ | 'partially_captured'
345
+ | 'pending'
346
+ | 'reconciliation_required'
347
+
348
+ export interface CheckoutPaymentSummary {
349
+ total: number
350
+ captured_amount: number
351
+ pending_amount: number
352
+ status: CheckoutPaymentSummaryStatus
353
+ payments: CheckoutPaymentSummaryPayment[]
354
+ reconciliation_required: boolean
355
+ errors?: Array<{ code: string; message: string }>
356
+ }
package/AGENTS.md DELETED
@@ -1 +0,0 @@
1
- <!-- TYPES-AGENTS-MD-START -->[@thorprovider/types Docs]|root: ./types|Electrostore MVP: see director roadmap.|To regenerate: yarn generate:agents-index|.:{README.md}|src:{header-config.README.md}<!-- TYPES-AGENTS-MD-END -->