@thorprovider/types 7.2.0 → 7.3.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 +18 -19
- package/CHANGELOG.md +36 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/index.d.mts +276 -2
- package/dist/index.d.ts +276 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/admin/DropshippingAdmin.ts +4 -1
- package/src/auth.ts +6 -0
- package/src/checkout.ts +152 -0
- package/src/commerce-provider.ts +40 -0
- package/src/customer.ts +1 -0
- package/src/index.ts +34 -0
- package/src/shipping.ts +101 -0
- package/.turbo/turbo-type-check.log +0 -0
package/src/commerce-provider.ts
CHANGED
|
@@ -43,6 +43,7 @@ import type { PaymentMethod, PaymentMethodsOptions } from './payment';
|
|
|
43
43
|
import type { AuthProvider } from './auth';
|
|
44
44
|
import type { StorefrontContext } from './storefront';
|
|
45
45
|
import type { StockLocation, InventoryLevel, StockValidation, FulfillmentOption } from './stock-location';
|
|
46
|
+
import type { ShippingGroupQuote, ShippingGroupSelection } from './shipping';
|
|
46
47
|
import type { StorefrontConfig } from './storefront-config';
|
|
47
48
|
import type { DesignerConfig, DesignerHistoryEntry } from './designer-config';
|
|
48
49
|
import type { CatalogQuery, CatalogQueryOutcome, CatalogSortKey } from './catalog';
|
|
@@ -685,6 +686,45 @@ export interface CommerceProvider {
|
|
|
685
686
|
* ```
|
|
686
687
|
*/
|
|
687
688
|
addShippingMethod(cartId: string, methodId: string): Promise<Cart>;
|
|
689
|
+
|
|
690
|
+
/**
|
|
691
|
+
* Get the backend's grouped shipping quote for a cart (OPTIONAL).
|
|
692
|
+
*
|
|
693
|
+
* Returns the backend's own delivery groups — one per shipping profile —
|
|
694
|
+
* each with the variants it contains and the options valid for it. The
|
|
695
|
+
* storefront consumes these groups as they are: it never groups, splits,
|
|
696
|
+
* ranks, or re-prices shipments locally.
|
|
697
|
+
*
|
|
698
|
+
* Optional so a provider without a grouped store endpoint keeps its existing
|
|
699
|
+
* contract; callers must treat its absence as an unsupported capability
|
|
700
|
+
* rather than as an empty quote. Amounts are backend major units and are not
|
|
701
|
+
* authoritative for the order total (the cart is re-read after applying).
|
|
702
|
+
*
|
|
703
|
+
* @param cartId - Cart ID
|
|
704
|
+
* @returns The grouped quote, or `{ groups: [], count: 0 }` when the cart has
|
|
705
|
+
* no shipping address yet (nothing can be quoted without a destination)
|
|
706
|
+
* @throws {ProviderAPIError} If the backend fails or returns an invalid quote
|
|
707
|
+
*/
|
|
708
|
+
getCheckoutShippingGroups?(cartId: string): Promise<ShippingGroupQuote>;
|
|
709
|
+
|
|
710
|
+
/**
|
|
711
|
+
* Apply one selected shipping option per backend group (OPTIONAL).
|
|
712
|
+
*
|
|
713
|
+
* Sends the shopper's selections keyed by the backend group identity
|
|
714
|
+
* (`products` + `option_id`). Acceptance is all this call guarantees: the
|
|
715
|
+
* caller re-reads the authoritative cart for totals after it resolves, and
|
|
716
|
+
* never derives totals from a response body.
|
|
717
|
+
*
|
|
718
|
+
* Optional for the same reason as `getCheckoutShippingGroups`.
|
|
719
|
+
*
|
|
720
|
+
* @param cartId - Cart ID
|
|
721
|
+
* @param selections - One `{ products, option_id }` per backend group
|
|
722
|
+
* @throws {ProviderAPIError} If the backend rejects the selection set
|
|
723
|
+
*/
|
|
724
|
+
applyCheckoutShippingGroups?(
|
|
725
|
+
cartId: string,
|
|
726
|
+
selections: ShippingGroupSelection[],
|
|
727
|
+
): Promise<void>;
|
|
688
728
|
|
|
689
729
|
/**
|
|
690
730
|
* Initiate payment session with provider
|
package/src/customer.ts
CHANGED
|
@@ -29,6 +29,7 @@ export interface Address {
|
|
|
29
29
|
postalCode?: string; // Shopify: zip, Medusa: postal_code, WooCommerce: postcode
|
|
30
30
|
countryCode: string; // ISO 3166-1 alpha-2 code (e.g., "US", "CA", "GB")
|
|
31
31
|
phone?: string;
|
|
32
|
+
label?: string; // Customer-facing name for the address (e.g., "Home")
|
|
32
33
|
isDefault?: boolean; // Whether this is the default/primary address for the customer
|
|
33
34
|
isDefaultBilling?: boolean; // Whether this is the default billing address
|
|
34
35
|
isDefaultShipping?: boolean; // Whether this is the default shipping address
|
package/src/index.ts
CHANGED
|
@@ -30,6 +30,40 @@ export type {
|
|
|
30
30
|
OrderReceipt,
|
|
31
31
|
} from './commerce';
|
|
32
32
|
|
|
33
|
+
// ============================================
|
|
34
|
+
// Checkout Contracts (type-only)
|
|
35
|
+
// ============================================
|
|
36
|
+
export type {
|
|
37
|
+
CheckoutReadState,
|
|
38
|
+
CheckoutAddressOption,
|
|
39
|
+
CheckoutAddressLevel,
|
|
40
|
+
CheckoutLocationOptions,
|
|
41
|
+
CheckoutAddressValues,
|
|
42
|
+
CheckoutContactValues,
|
|
43
|
+
CheckoutCustomerIdentity,
|
|
44
|
+
CheckoutSavedAddress,
|
|
45
|
+
CheckoutShippingOption,
|
|
46
|
+
CheckoutShippingGroup,
|
|
47
|
+
CheckoutShippingGroupItem,
|
|
48
|
+
CheckoutAdjustmentPayment,
|
|
49
|
+
CheckoutInterruptionKind,
|
|
50
|
+
CheckoutInterruptionAction,
|
|
51
|
+
CheckoutInterruption,
|
|
52
|
+
CheckoutSubmission,
|
|
53
|
+
} from './checkout';
|
|
54
|
+
|
|
55
|
+
// ============================================
|
|
56
|
+
// Grouped Shipping Contracts (type-only)
|
|
57
|
+
// ============================================
|
|
58
|
+
export type {
|
|
59
|
+
ShippingGroupLocation,
|
|
60
|
+
ShippingGroupOption,
|
|
61
|
+
ShippingGroupItem,
|
|
62
|
+
ShippingGroup,
|
|
63
|
+
ShippingGroupQuote,
|
|
64
|
+
ShippingGroupSelection,
|
|
65
|
+
} from './shipping';
|
|
66
|
+
|
|
33
67
|
export type {
|
|
34
68
|
AuthorConfig,
|
|
35
69
|
BrandConfig,
|
package/src/shipping.ts
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Grouped shipping-delivery contracts shared by the commerce boundary and the
|
|
3
|
+
* storefront host.
|
|
4
|
+
*
|
|
5
|
+
* These types mirror the backend grouped-shipping response (shipping profiles
|
|
6
|
+
* with their eligible options) and stay free of any presentation concern: no
|
|
7
|
+
* UI ids, labels, currency formatting, grouping, ranking, or price summation
|
|
8
|
+
* live here. Amounts are backend major units (design D8), exactly as returned
|
|
9
|
+
* by the store endpoint; the host maps them to `Money` without converting.
|
|
10
|
+
*
|
|
11
|
+
* A group is identified by the backend's own identity: `profile_id` plus its
|
|
12
|
+
* `products` (variant ids). A selection round-trips that identity and the
|
|
13
|
+
* chosen `option_id`, so the backend can apply the shopper's choice per group.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Pickup/stock location an option is served from, when the backend exposes it.
|
|
18
|
+
* Descriptive only: the checkout does not use it to allocate shipments.
|
|
19
|
+
*/
|
|
20
|
+
export interface ShippingGroupLocation {
|
|
21
|
+
id: string;
|
|
22
|
+
name: string;
|
|
23
|
+
address?: {
|
|
24
|
+
address_1: string;
|
|
25
|
+
address_2: string | null;
|
|
26
|
+
city: string | null;
|
|
27
|
+
province: string | null;
|
|
28
|
+
postal_code: string | null;
|
|
29
|
+
country_code: string;
|
|
30
|
+
} | null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* One selectable shipping option valid for a single backend group.
|
|
35
|
+
*
|
|
36
|
+
* Intentionally mirrors the admin `DropshipperShippingGroupOption`
|
|
37
|
+
* (`admin/DropshippingAdmin.ts`); keep both grouped-shipping shapes aligned.
|
|
38
|
+
*/
|
|
39
|
+
export interface ShippingGroupOption {
|
|
40
|
+
id: string;
|
|
41
|
+
name: string;
|
|
42
|
+
/** Backend amount in major units (for example `4.99`). Never re-priced locally. */
|
|
43
|
+
amount: number;
|
|
44
|
+
currency_code: string;
|
|
45
|
+
price_type: string;
|
|
46
|
+
/** Backend default for the group; the host may pre-select it. */
|
|
47
|
+
is_default: boolean;
|
|
48
|
+
fulfillment_set_type: string | null;
|
|
49
|
+
estimated_days?: string | null;
|
|
50
|
+
location?: ShippingGroupLocation | null;
|
|
51
|
+
/**
|
|
52
|
+
* Backend option type (`label`/`code`), shared with the admin shape as an
|
|
53
|
+
* optional display/identification field; the checkout does not branch on it.
|
|
54
|
+
*/
|
|
55
|
+
type?: {
|
|
56
|
+
id: string;
|
|
57
|
+
label: string;
|
|
58
|
+
code: string | null;
|
|
59
|
+
} | null;
|
|
60
|
+
stock_location_id: string;
|
|
61
|
+
shipping_profile_id: string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* One variant line inside a group. Line membership is by variant id; the host
|
|
66
|
+
* only maps it to a cart line when that mapping is unambiguous.
|
|
67
|
+
*/
|
|
68
|
+
export interface ShippingGroupItem {
|
|
69
|
+
variant_id: string;
|
|
70
|
+
quantity: number;
|
|
71
|
+
product_title?: string | null;
|
|
72
|
+
variant_title?: string | null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* One delivery group as decided by the backend. The storefront never groups,
|
|
77
|
+
* splits, or re-keys these: `profile_id` + `products` is the group identity.
|
|
78
|
+
*/
|
|
79
|
+
export interface ShippingGroup {
|
|
80
|
+
profile_id: string;
|
|
81
|
+
profile_label: string;
|
|
82
|
+
/** Variant ids of the group; the roundtrip value for a selection's `products`. */
|
|
83
|
+
products: string[];
|
|
84
|
+
items: ShippingGroupItem[];
|
|
85
|
+
options: ShippingGroupOption[];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** The grouped-shipping quote for a cart. `count` is the backend's group count. */
|
|
89
|
+
export interface ShippingGroupQuote {
|
|
90
|
+
groups: ShippingGroup[];
|
|
91
|
+
count: number;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* The shopper's chosen option for one backend group.
|
|
96
|
+
* `products` must be the group's own `products` array, not a derived id.
|
|
97
|
+
*/
|
|
98
|
+
export interface ShippingGroupSelection {
|
|
99
|
+
products: string[];
|
|
100
|
+
option_id: string;
|
|
101
|
+
}
|
|
File without changes
|