feeef 0.12.4 → 0.12.5
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.
|
@@ -29,6 +29,17 @@ export interface ProductEntity {
|
|
|
29
29
|
dislikes: number;
|
|
30
30
|
variant?: ProductVariant | null;
|
|
31
31
|
offers?: ProductOffer[] | null;
|
|
32
|
+
/**
|
|
33
|
+
* When true, the customer must keep an offer selected.
|
|
34
|
+
* If [defaultOfferCode] also resolves to a valid offer, that offer is locked
|
|
35
|
+
* (cannot switch or deselect). Independent of [defaultOfferCode] being set.
|
|
36
|
+
*/
|
|
37
|
+
forceOffer?: boolean | null;
|
|
38
|
+
/**
|
|
39
|
+
* Offer code to preselect on the storefront. Cleared (synced to null) when the
|
|
40
|
+
* code is missing from [offers] — callers should treat a stale code as unset.
|
|
41
|
+
*/
|
|
42
|
+
defaultOfferCode?: string | null;
|
|
32
43
|
metadata: Record<string, any>;
|
|
33
44
|
status: ProductStatus;
|
|
34
45
|
type: ProductType;
|
|
@@ -231,6 +242,10 @@ export interface ProductCreateInput {
|
|
|
231
242
|
stock?: number;
|
|
232
243
|
variant?: ProductVariant;
|
|
233
244
|
offers?: ProductOffer[];
|
|
245
|
+
/** See [ProductEntity.forceOffer]. */
|
|
246
|
+
forceOffer?: boolean | null;
|
|
247
|
+
/** See [ProductEntity.defaultOfferCode]. */
|
|
248
|
+
defaultOfferCode?: string | null;
|
|
234
249
|
addons?: ProductAddon[];
|
|
235
250
|
metadata?: Record<string, any>;
|
|
236
251
|
status?: ProductStatus;
|
|
@@ -260,6 +275,10 @@ export interface ProductUpdateInput {
|
|
|
260
275
|
stock?: number;
|
|
261
276
|
variant?: ProductVariant;
|
|
262
277
|
offers?: ProductOffer[];
|
|
278
|
+
/** See [ProductEntity.forceOffer]. */
|
|
279
|
+
forceOffer?: boolean | null;
|
|
280
|
+
/** See [ProductEntity.defaultOfferCode]. */
|
|
281
|
+
defaultOfferCode?: string | null;
|
|
263
282
|
addons?: ProductAddon[];
|
|
264
283
|
metadata?: Record<string, any>;
|
|
265
284
|
status?: ProductStatus;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ProductEntity, ProductOffer } from './product.js';
|
|
2
|
+
/** Minimal product shape needed to resolve default / forced offer policy. */
|
|
3
|
+
export type ProductOfferPolicySource = Pick<ProductEntity, 'offers' | 'forceOffer' | 'defaultOfferCode'>;
|
|
4
|
+
/**
|
|
5
|
+
* Returns [defaultOfferCode] only when it exists in [offers]; otherwise null.
|
|
6
|
+
* Use whenever persisting or applying a default so stale codes never leak.
|
|
7
|
+
*/
|
|
8
|
+
export declare function syncDefaultOfferCode(offers: ProductOffer[] | null | undefined, defaultOfferCode: string | null | undefined): string | null;
|
|
9
|
+
/**
|
|
10
|
+
* Offer that should be preselected for a product (if any).
|
|
11
|
+
* Respects synced [defaultOfferCode] only — does not invent a "first offer".
|
|
12
|
+
*/
|
|
13
|
+
export declare function resolveInitialProductOffer(product: ProductOfferPolicySource): ProductOffer | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* True when the product requires an offer to remain selected (cannot deselect).
|
|
16
|
+
* Independent of whether a specific default code is set.
|
|
17
|
+
*/
|
|
18
|
+
export declare function isProductOfferRequired(product: ProductOfferPolicySource): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* True when offer selection is locked to the synced default code
|
|
21
|
+
* (`forceOffer` + valid `defaultOfferCode`). Customer cannot switch offers.
|
|
22
|
+
*/
|
|
23
|
+
export declare function isProductOfferLocked(product: ProductOfferPolicySource): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Offer that must be applied when locked; otherwise undefined.
|
|
26
|
+
*/
|
|
27
|
+
export declare function resolveForcedProductOffer(product: ProductOfferPolicySource): ProductOffer | undefined;
|
|
@@ -77,9 +77,17 @@ export declare class CartService extends NotifiableService {
|
|
|
77
77
|
private findItemIndex;
|
|
78
78
|
/**
|
|
79
79
|
* Sets the current item to be managed in the cart.
|
|
80
|
+
* Applies product [defaultOfferCode] when the item has no offer yet, and
|
|
81
|
+
* re-applies a forced offer when [forceOffer] locks selection.
|
|
80
82
|
* @param item - The item to be set as current.
|
|
81
83
|
*/
|
|
82
84
|
setCurrentItem(item: CartItem, notify?: boolean): void;
|
|
85
|
+
/**
|
|
86
|
+
* Hydrates / locks offer from product policy without mutating unrelated fields.
|
|
87
|
+
* - Default: preselect when item has no offer
|
|
88
|
+
* - Forced+default: always keep the forced offer
|
|
89
|
+
*/
|
|
90
|
+
private applyProductOfferPolicy;
|
|
83
91
|
/**
|
|
84
92
|
* Clamps the quantity to be within the offer's min/max range
|
|
85
93
|
* @param offer - The offer containing quantity constraints
|
|
@@ -198,6 +206,11 @@ export declare class CartService extends NotifiableService {
|
|
|
198
206
|
* @param offer - The offer to apply, or undefined to remove the offer
|
|
199
207
|
*/
|
|
200
208
|
updateCurrentItemOffer(offer?: ProductOffer): void;
|
|
209
|
+
/**
|
|
210
|
+
* Enforces product offer policy for a requested offer change.
|
|
211
|
+
* Returns `'blocked'` when the change is not allowed.
|
|
212
|
+
*/
|
|
213
|
+
private resolveOfferUpdate;
|
|
201
214
|
/**
|
|
202
215
|
* Sets the shipping method.
|
|
203
216
|
* @param method - Either a store or a shipping method.
|
package/build/src/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export * from './delivery/delivery_carrier_client.js';
|
|
|
5
5
|
export * from './core/entities/order.js';
|
|
6
6
|
export * from './core/entities/store.js';
|
|
7
7
|
export * from './core/entities/product.js';
|
|
8
|
+
export * from './core/entities/product_offer_policy.js';
|
|
8
9
|
export * from './core/entities/product_landing_page.js';
|
|
9
10
|
export * from './core/entities/product_landing_page_template.js';
|
|
10
11
|
export * from './core/entities/attachment.js';
|