@thorprovider/types 7.5.0 → 7.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/.turbo/turbo-build.log +6 -6
- package/CHANGELOG.md +26 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/index.d.mts +156 -2
- package/dist/index.d.ts +156 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/commerce-provider.ts +59 -1
- package/src/index.ts +9 -0
- package/src/order.ts +23 -0
- package/src/payment.ts +99 -2
- package/AGENTS.md +0 -1
package/src/commerce-provider.ts
CHANGED
|
@@ -39,7 +39,12 @@ import type {
|
|
|
39
39
|
CustomerOrdersPage,
|
|
40
40
|
} from './order';
|
|
41
41
|
import type { Region } from './region';
|
|
42
|
-
import type {
|
|
42
|
+
import type {
|
|
43
|
+
PaymentMethod,
|
|
44
|
+
PaymentMethodsOptions,
|
|
45
|
+
GiftCardValidationResult,
|
|
46
|
+
StoreCreditAccountSummary,
|
|
47
|
+
} from './payment';
|
|
43
48
|
import type { AuthProvider } from './auth';
|
|
44
49
|
import type { StorefrontContext } from './storefront';
|
|
45
50
|
import type { StockLocation, InventoryLevel, StockValidation, FulfillmentOption } from './stock-location';
|
|
@@ -937,6 +942,25 @@ export interface CommerceProvider {
|
|
|
937
942
|
* empty history.
|
|
938
943
|
*/
|
|
939
944
|
customerOrdersPage?(options: GetCustomerOrdersPageOptions): Promise<CustomerOrdersPage>;
|
|
945
|
+
|
|
946
|
+
/**
|
|
947
|
+
* Resolve ONE order for the authenticated customer (OPTIONAL, additive).
|
|
948
|
+
*
|
|
949
|
+
* Ownership is enforced by the provider: an order that belongs to another
|
|
950
|
+
* customer, another channel, or no customer resolves as `undefined` — the
|
|
951
|
+
* caller must not learn whether it exists. A provider that does not implement
|
|
952
|
+
* this method (a backend without a customer detail endpoint) fails closed at
|
|
953
|
+
* the runtime boundary; the storefront never derives the detail from the
|
|
954
|
+
* order-list payload.
|
|
955
|
+
*
|
|
956
|
+
* `options.salesChannelId` is the store's explicitly configured channel. A
|
|
957
|
+
* provider that can scope by channel MUST reject a foreign order as
|
|
958
|
+
* `undefined`.
|
|
959
|
+
*/
|
|
960
|
+
customerOrderDetail?(
|
|
961
|
+
orderId: string,
|
|
962
|
+
options?: { salesChannelId?: string },
|
|
963
|
+
): Promise<Order | undefined>;
|
|
940
964
|
|
|
941
965
|
// ============================================
|
|
942
966
|
// Payment Operations
|
|
@@ -974,6 +998,40 @@ export interface CommerceProvider {
|
|
|
974
998
|
*/
|
|
975
999
|
getPaymentMethods(options: PaymentMethodsOptions): Promise<PaymentMethod[]>;
|
|
976
1000
|
|
|
1001
|
+
/**
|
|
1002
|
+
* Validate a gift-card code before it is added to the checkout payment plan
|
|
1003
|
+
* (OPTIONAL).
|
|
1004
|
+
*
|
|
1005
|
+
* Read-only: it must not create a payment session, reserve balance or mutate
|
|
1006
|
+
* the cart. The backend remains the authority; a valid result can still be
|
|
1007
|
+
* rejected when the plan is completed if the balance or currency changed.
|
|
1008
|
+
*
|
|
1009
|
+
* Optional so a provider without gift-card support keeps its existing
|
|
1010
|
+
* contract; callers must treat its absence as an unsupported capability
|
|
1011
|
+
* rather than as an invalid gift card.
|
|
1012
|
+
*
|
|
1013
|
+
* @param code - Gift-card code supplied by the shopper
|
|
1014
|
+
* @returns The backend's validation result, including balance and status
|
|
1015
|
+
* @throws {ProviderAPIError} If the backend fails or returns an invalid shape
|
|
1016
|
+
*/
|
|
1017
|
+
validateGiftCard?(code: string): Promise<GiftCardValidationResult>;
|
|
1018
|
+
|
|
1019
|
+
/**
|
|
1020
|
+
* List the authenticated customer's store-credit accounts (OPTIONAL).
|
|
1021
|
+
*
|
|
1022
|
+
* Read-only: it must not create a payment session or debit the account. The
|
|
1023
|
+
* checkout filters these accounts by the cart currency and lets the shopper
|
|
1024
|
+
* choose one; the backend validates the account and amount again when the
|
|
1025
|
+
* payment plan is completed.
|
|
1026
|
+
*
|
|
1027
|
+
* Optional for the same reason as {@link validateGiftCard}.
|
|
1028
|
+
*
|
|
1029
|
+
* @returns Store-credit accounts with their backend-authoritative balances
|
|
1030
|
+
* @throws {ProviderAPIError} If the customer is not authenticated or the
|
|
1031
|
+
* backend fails
|
|
1032
|
+
*/
|
|
1033
|
+
getStoreCreditAccounts?(): Promise<StoreCreditAccountSummary[]>;
|
|
1034
|
+
|
|
977
1035
|
// ============================================
|
|
978
1036
|
// Inventory Operations (Admin API — Optional)
|
|
979
1037
|
// ============================================
|
package/src/index.ts
CHANGED
|
@@ -196,6 +196,8 @@ export type {
|
|
|
196
196
|
Order,
|
|
197
197
|
OrderDeliveryGroup,
|
|
198
198
|
OrderItem,
|
|
199
|
+
OrderPayment,
|
|
200
|
+
OrderPaymentStatus,
|
|
199
201
|
OrderStatus,
|
|
200
202
|
PaymentStatus,
|
|
201
203
|
FulfillmentStatus,
|
|
@@ -276,6 +278,13 @@ export type {
|
|
|
276
278
|
PaymentMethodFeatures,
|
|
277
279
|
PaymentMethodsOptions,
|
|
278
280
|
CachedPaymentMethods,
|
|
281
|
+
CheckoutCapturePolicy,
|
|
282
|
+
CheckoutPaymentPlanItem,
|
|
283
|
+
GiftCardValidationResult,
|
|
284
|
+
StoreCreditAccountSummary,
|
|
285
|
+
CheckoutPaymentSummary,
|
|
286
|
+
CheckoutPaymentSummaryPayment,
|
|
287
|
+
CheckoutPaymentSummaryStatus,
|
|
279
288
|
} from './payment';
|
|
280
289
|
|
|
281
290
|
// ============================================
|
package/src/order.ts
CHANGED
|
@@ -101,6 +101,21 @@ export interface OrderDeliveryGroup {
|
|
|
101
101
|
lineIds?: string[];
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
+
/** One payment captured/authorized against an order. */
|
|
105
|
+
export type OrderPaymentStatus = 'authorized' | 'captured' | 'canceled' | 'pending';
|
|
106
|
+
|
|
107
|
+
export interface OrderPayment {
|
|
108
|
+
id: string;
|
|
109
|
+
providerId: string;
|
|
110
|
+
/** Provider display label when the adapter can resolve one. */
|
|
111
|
+
label?: string;
|
|
112
|
+
/** Payment amount in the order currency. */
|
|
113
|
+
amount?: Money;
|
|
114
|
+
status: OrderPaymentStatus;
|
|
115
|
+
capturedAt?: string;
|
|
116
|
+
canceledAt?: string;
|
|
117
|
+
}
|
|
118
|
+
|
|
104
119
|
/**
|
|
105
120
|
* Order
|
|
106
121
|
*
|
|
@@ -153,7 +168,15 @@ export interface Order {
|
|
|
153
168
|
providerId?: string;
|
|
154
169
|
label?: string;
|
|
155
170
|
detail?: string;
|
|
171
|
+
amount?: Money;
|
|
172
|
+
capturedAt?: string;
|
|
156
173
|
};
|
|
174
|
+
/**
|
|
175
|
+
* Every payment on the order, when the backend reports them. Kept separate
|
|
176
|
+
* from `payment` (the first/primary payment) so a multi-instrument checkout
|
|
177
|
+
* can render its breakdown after a reload without inventing amounts.
|
|
178
|
+
*/
|
|
179
|
+
payments?: OrderPayment[];
|
|
157
180
|
/** Backend tax rate in basis points, when the order reports one rate. */
|
|
158
181
|
taxRateBps?: number;
|
|
159
182
|
|
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 -->
|