@revenexx/cover 0.1.23 → 0.2.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/app/api/offers.ts +3 -0
- package/app/components/account/directorder/AccountDirectOrder.vue +8 -4
- package/app/components/cart/item/CartItem.vue +5 -3
- package/app/components/cart/position/CartPosition.vue +5 -3
- package/app/components/cart/quickadd/CartQuickAdd.vue +6 -3
- package/app/components/cart/recommend/CartCrossSell.vue +7 -4
- package/app/components/category/info/CategoryPrice.vue +12 -3
- package/app/components/category/info/CategoryStock.vue +13 -3
- package/app/components/category/view/GridView.vue +1 -4
- package/app/components/category/view/ListView.vue +1 -4
- package/app/components/layout/footer/Footer.vue +7 -5
- package/app/components/layout/header/MainNav.vue +10 -3
- package/app/components/layout/header/TopBar.vue +3 -2
- package/app/components/product/detail/ProductDetailImageGallery.vue +50 -5
- package/app/composables/useOffers.ts +117 -0
- package/app/composables/useProduct.ts +15 -3
- package/app/composables/useProductCardActions.ts +11 -11
- package/app/composables/useProductListing.ts +10 -0
- package/app/composables/useProductUrl.ts +5 -5
- package/app/composables/useProducts.ts +22 -4
- package/app/plugins/model-viewer.client.ts +7 -0
- package/nuxt.config.ts +8 -0
- package/package.json +3 -2
- package/server/api/offers.post.ts +34 -0
- package/server/api/product/[id].get.ts +3 -2
- package/server/api/products/[id].get.ts +3 -3
- package/server/api/products/index.get.ts +3 -2
- package/server/api/typesense/search.post.ts +9 -15
- package/server/api/typesense/seed.get.ts +3 -4
- package/server/interfaces/offer.ts +36 -0
- package/server/services/LocalFileProductService.ts +10 -5
- package/server/services/MockOfferService.ts +89 -0
- package/server/utils/liveCatalog.ts +3 -4
- package/server/utils/liveInventories.ts +25 -33
- package/server/utils/livePrices.ts +21 -32
- package/server/utils/offerService.ts +57 -0
- package/server/utils/productsSchema.ts +2 -2
- package/server/utils/liveEnrichment.ts +0 -51
|
@@ -87,11 +87,29 @@ export function parseProductIdFromSlug(slug: string): string {
|
|
|
87
87
|
return slug.split("-")[0] ?? "";
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
90
|
+
/**
|
|
91
|
+
* Build a product detail path that tolerates ANY category depth.
|
|
92
|
+
*
|
|
93
|
+
* The detail route is `/category/<…category path>/product/<slug>` where the
|
|
94
|
+
* category path may be one, two or more segments. Empty / nullish / literal
|
|
95
|
+
* "undefined" segments are dropped, so a product with no subcategory yields
|
|
96
|
+
* `/category/<cat>/product/<slug>` instead of the broken
|
|
97
|
+
* `/category/<cat>/undefined/product/<slug>`. When no category segment is known
|
|
98
|
+
* a single placeholder keeps the URL shape valid (the page only needs the slug).
|
|
99
|
+
*/
|
|
100
|
+
export function categoryProductPath(
|
|
101
|
+
categorySegments: Array<string | null | undefined>,
|
|
102
|
+
product: Pick<Product, "id" | "name">,
|
|
103
|
+
): string {
|
|
104
|
+
const cats = categorySegments.filter(
|
|
105
|
+
(s): s is string => Boolean(s) && s !== "undefined",
|
|
106
|
+
);
|
|
107
|
+
const prefix = cats.length > 0 ? cats.join("/") : "_";
|
|
108
|
+
return `/category/${prefix}/product/${slugify(product as Product)}`;
|
|
109
|
+
}
|
|
110
|
+
|
|
93
111
|
export function productUrl(product: Product): string {
|
|
94
|
-
return
|
|
112
|
+
return categoryProductPath([product.categorySlug, product.subcategorySlug], product);
|
|
95
113
|
}
|
|
96
114
|
|
|
97
115
|
export const useProducts = (
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Registers the <rx-model-viewer> custom element (from
|
|
2
|
+
// @revenexx/storage-model-viewer). Client-only: it renders WebGL. The default
|
|
3
|
+
// (three.js) engine loads on mount; @google/model-viewer is only pulled in when
|
|
4
|
+
// a consumer opts into engine="model-viewer" (AR), which the storefront does not.
|
|
5
|
+
export default defineNuxtPlugin(async () => {
|
|
6
|
+
await import("@revenexx/storage-model-viewer");
|
|
7
|
+
});
|
package/nuxt.config.ts
CHANGED
|
@@ -47,6 +47,14 @@ export default defineNuxtConfig({
|
|
|
47
47
|
name: "@revenexx/cover",
|
|
48
48
|
},
|
|
49
49
|
|
|
50
|
+
// <rx-model-viewer> (from @revenexx/storage-model-viewer) is a custom element —
|
|
51
|
+
// don't let the Vue compiler try to resolve it as a component.
|
|
52
|
+
vue: {
|
|
53
|
+
compilerOptions: {
|
|
54
|
+
isCustomElement: (tag: string) => tag === "rx-model-viewer",
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
|
|
50
58
|
// Forms: FormKit renders the BFF-served form schemas (SSR-safe). The
|
|
51
59
|
// module and config ship with the layer so every consumer gets them.
|
|
52
60
|
modules: ["@formkit/nuxt"],
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@revenexx/cover",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Cover
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Cover — revenexx design system for Nuxt. Distributed as a Nuxt layer: generic UI components, theming tokens and stores shared by the demo shop, custom storefronts and the Blokkli theme.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./nuxt.config.ts",
|
|
7
7
|
"license": "MIT",
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"@iconify-json/lucide": "^1.2.111",
|
|
40
40
|
"@internationalized/date": "^3.12.0",
|
|
41
41
|
"@revenexx/sdk": "^0.0.5",
|
|
42
|
+
"@revenexx/storage-model-viewer": "^0.3.0",
|
|
42
43
|
"@vueuse/core": "^14.3.0",
|
|
43
44
|
"typesense": "^3.0.5"
|
|
44
45
|
},
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Offer, OfferRequestItem } from "../interfaces/offer";
|
|
2
|
+
|
|
3
|
+
const MAX_ITEMS = 250;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Batch offer (price + availability) resolution for a set of products.
|
|
7
|
+
* The single decoupled call the client makes after rendering the catalog
|
|
8
|
+
* shell. Fails SOFT: any upstream error returns empty offers so the UI
|
|
9
|
+
* degrades to "price on request" rather than breaking the page.
|
|
10
|
+
*/
|
|
11
|
+
export default defineEventHandler(async (event) => {
|
|
12
|
+
const body = await readBody<{ items?: OfferRequestItem[] }>(event);
|
|
13
|
+
const items = (body?.items ?? [])
|
|
14
|
+
.filter((i): i is OfferRequestItem => !!i && typeof i.id === "string" && i.id.length > 0)
|
|
15
|
+
.slice(0, MAX_ITEMS)
|
|
16
|
+
.map(i => ({ id: i.id, ...(typeof i.sku === "string" && i.sku ? { sku: i.sku } : {}) }));
|
|
17
|
+
|
|
18
|
+
if (items.length === 0) {
|
|
19
|
+
return { offers: {} as Record<string, Offer> };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
const resolved = await getOffers(event, items);
|
|
24
|
+
const offers: Record<string, Offer> = {};
|
|
25
|
+
for (const [id, offer] of resolved) {
|
|
26
|
+
offers[id] = offer;
|
|
27
|
+
}
|
|
28
|
+
return { offers };
|
|
29
|
+
}
|
|
30
|
+
catch (err) {
|
|
31
|
+
getLogService().error("Service error: offers", toErrorContext(err));
|
|
32
|
+
return { offers: {} as Record<string, Offer> };
|
|
33
|
+
}
|
|
34
|
+
});
|
|
@@ -7,11 +7,12 @@ export default defineEventHandler(async (event) => {
|
|
|
7
7
|
const locale = resolveLocale(event);
|
|
8
8
|
|
|
9
9
|
try {
|
|
10
|
-
|
|
10
|
+
const detail = await getProductService(event).getProductDetail(id, locale);
|
|
11
11
|
if (!detail) {
|
|
12
12
|
throw createError({ statusCode: 404, message: "Product not found" });
|
|
13
13
|
}
|
|
14
|
-
|
|
14
|
+
// Catalog shell only — offer (price + availability) via POST /api/offers.
|
|
15
|
+
return detail;
|
|
15
16
|
}
|
|
16
17
|
catch (err) {
|
|
17
18
|
if (err !== null && typeof err === "object" && "statusCode" in err) {
|
|
@@ -6,12 +6,12 @@ export default defineEventHandler(async (event) => {
|
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
try {
|
|
9
|
-
|
|
9
|
+
const product = await getProductService(event).getProductById(id, locale);
|
|
10
10
|
if (!product) {
|
|
11
11
|
throw createError({ status: 404, message: "Product not found" });
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
return
|
|
13
|
+
// Catalog shell only — offer (price + availability) via POST /api/offers.
|
|
14
|
+
return product;
|
|
15
15
|
}
|
|
16
16
|
catch (err) {
|
|
17
17
|
if (err !== null && typeof err === "object" && "statusCode" in err) {
|
|
@@ -5,8 +5,9 @@ export default defineEventHandler(async (event) => {
|
|
|
5
5
|
};
|
|
6
6
|
|
|
7
7
|
try {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
// Catalog shell only — price + availability are the Offer domain,
|
|
9
|
+
// resolved separately via POST /api/offers (never blocks the catalog).
|
|
10
|
+
return await getProductService(event).listProducts({ category, subcategory, locale });
|
|
10
11
|
}
|
|
11
12
|
catch (err) {
|
|
12
13
|
getLogService().error("Service error: products/list", toErrorContext(err));
|
|
@@ -88,8 +88,9 @@ export default defineEventHandler(async (event) => {
|
|
|
88
88
|
perPage,
|
|
89
89
|
});
|
|
90
90
|
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
// Catalog shell only — offers (price + availability) hydrate
|
|
92
|
+
// separately via POST /api/offers, never blocking search.
|
|
93
|
+
const products: ProductList[] = (results.hits ?? []).map(hit => mapLiveDocToProduct(hit.document));
|
|
93
94
|
const facets: SearchFacet[] = (results.facet_counts ?? []).map(fc => ({
|
|
94
95
|
fieldName: fc.field_name,
|
|
95
96
|
counts: (fc.counts ?? []).map(c => ({ value: c.value, count: c.count })),
|
|
@@ -147,27 +148,20 @@ export default defineEventHandler(async (event) => {
|
|
|
147
148
|
per_page: perPage,
|
|
148
149
|
});
|
|
149
150
|
|
|
150
|
-
// The index
|
|
151
|
-
//
|
|
152
|
-
//
|
|
151
|
+
// Catalog shell only. The index keeps a scalar `price` purely as a
|
|
152
|
+
// sort/filter key (catalog list price) and the catalog tax rate; the
|
|
153
|
+
// buyer-facing price tiers + availability are the Offer domain and
|
|
154
|
+
// hydrate separately via POST /api/offers — never welded into search.
|
|
153
155
|
const products: ProductList[] = (results.hits ?? []).map((hit) => {
|
|
154
|
-
const doc = hit.document as unknown as Omit<ProductList, "id" | "prices" | "tax"> & {
|
|
156
|
+
const doc = hit.document as unknown as Omit<ProductList, "id" | "prices" | "tax" | "stocks"> & {
|
|
155
157
|
id: string;
|
|
156
|
-
prices?: Record<string, number> | Record<string, number>[];
|
|
157
158
|
taxRate?: number;
|
|
158
|
-
stockQuantity?: number;
|
|
159
159
|
};
|
|
160
|
-
const prices = Array.isArray(doc.prices)
|
|
161
|
-
? doc.prices
|
|
162
|
-
: doc.prices
|
|
163
|
-
? [doc.prices]
|
|
164
|
-
: [];
|
|
165
160
|
return {
|
|
166
161
|
...doc,
|
|
167
162
|
id: String(doc.id),
|
|
168
|
-
prices,
|
|
163
|
+
prices: [],
|
|
169
164
|
tax: { rate: doc.taxRate ?? 19 },
|
|
170
|
-
isOutOfStock: (doc.stockQuantity ?? 0) <= 0,
|
|
171
165
|
};
|
|
172
166
|
});
|
|
173
167
|
|
|
@@ -5,7 +5,8 @@ const MAX_COUNT = 5000;
|
|
|
5
5
|
|
|
6
6
|
function mapEntry(entry: (typeof productsData)[number], idOffset: number) {
|
|
7
7
|
const product = entry.product[0];
|
|
8
|
-
|
|
8
|
+
// Catalog list price only — a sort/filter key. Price tiers + stock are the
|
|
9
|
+
// Offer domain (MockOfferService), never indexed.
|
|
9
10
|
const prices = entry.prices[0] as Record<string, number>;
|
|
10
11
|
const longDescription = entry.descriptions.find(d => d.type === "long");
|
|
11
12
|
const mainCategory = entry.categories.find(c => c.type === "main");
|
|
@@ -32,10 +33,8 @@ function mapEntry(entry: (typeof productsData)[number], idOffset: number) {
|
|
|
32
33
|
name: `${product.name}${suffix}`,
|
|
33
34
|
sku: idOffset === 0 ? product.sku : `${product.sku}-${idOffset}`,
|
|
34
35
|
manufacturer: product.manufacturer,
|
|
35
|
-
available:
|
|
36
|
-
stockQuantity: stock.quantity,
|
|
36
|
+
available: product.available,
|
|
37
37
|
price: basePrice,
|
|
38
|
-
prices,
|
|
39
38
|
description: longDescription?.content,
|
|
40
39
|
category: mainCategory?.name ?? "",
|
|
41
40
|
categorySlug,
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Offer domain — a product's buyer-facing PRICE and AVAILABILITY.
|
|
3
|
+
*
|
|
4
|
+
* Deliberately separate from the catalog (name, image, category, tax). The
|
|
5
|
+
* catalog is cacheable, indexable and cheap; the offer is buyer-specific and
|
|
6
|
+
* volatile — in production a heavyweight ERP/SAP roundtrip. Keeping them on
|
|
7
|
+
* two axes means catalog and search render from the shell immediately and the
|
|
8
|
+
* offer hydrates on its own, never blocking first paint.
|
|
9
|
+
*
|
|
10
|
+
* Resolved through TWO registry keys (they really are two upstreams):
|
|
11
|
+
* - priceService ("mock" | "api") → price tiers
|
|
12
|
+
* - inventoryService ("mock" | "api") → availability
|
|
13
|
+
* so either can be live while the other stays demo.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export interface OfferRequestItem {
|
|
17
|
+
/** Product entity id — the offer map is keyed by this. */
|
|
18
|
+
id: string;
|
|
19
|
+
/** Optional SKU, used as a secondary resolution key upstream. */
|
|
20
|
+
sku?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface OfferStock {
|
|
24
|
+
quantity: number;
|
|
25
|
+
maxOrderQuantity: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface Offer {
|
|
29
|
+
id: string;
|
|
30
|
+
/** Tier map [{ "<minQty>": totalCents }] — EMPTY means price on request (never €0). */
|
|
31
|
+
prices: { [key: string]: number }[];
|
|
32
|
+
/** Per-location availability; empty = untracked/unknown (sells freely). */
|
|
33
|
+
stocks: OfferStock[];
|
|
34
|
+
/** True only when the item is tracked AND not orderable. */
|
|
35
|
+
isOutOfStock: boolean;
|
|
36
|
+
}
|
|
@@ -63,7 +63,6 @@ function mapToProduct(source: SourceItem): Product | null {
|
|
|
63
63
|
?? source.images?.[0]?.url
|
|
64
64
|
?? "";
|
|
65
65
|
|
|
66
|
-
const maxOrderQuantity = source.stocks?.[0]?.maxOrderQuantity;
|
|
67
66
|
const taxRate = typeof source.tax?.rate === "number" && Number.isFinite(source.tax.rate)
|
|
68
67
|
? source.tax.rate
|
|
69
68
|
: 0;
|
|
@@ -74,10 +73,11 @@ function mapToProduct(source: SourceItem): Product | null {
|
|
|
74
73
|
name: mainProduct.name,
|
|
75
74
|
sku: mainProduct.sku,
|
|
76
75
|
available: mainProduct.available,
|
|
77
|
-
|
|
76
|
+
// Catalog shell — price + availability are the Offer domain
|
|
77
|
+
// (MockOfferService reads them from the same JSON). tax is catalog-owned.
|
|
78
|
+
prices: [],
|
|
78
79
|
tax: { rate: taxRate, includedInPrice: source.tax?.includedInPrice },
|
|
79
|
-
stocks:
|
|
80
|
-
...(typeof maxOrderQuantity === "number" ? { maxOrderQuantity } : {}),
|
|
80
|
+
stocks: [],
|
|
81
81
|
image: primaryImage,
|
|
82
82
|
category: categoryName,
|
|
83
83
|
categorySlug,
|
|
@@ -123,6 +123,11 @@ export class LocalFileProductService implements IProductService {
|
|
|
123
123
|
|
|
124
124
|
async getProductDetail(id: string): Promise<ProductDetail | null> {
|
|
125
125
|
const all = await readCoverDataJson<Record<string, ProductDetail>>(this.detailKey);
|
|
126
|
-
|
|
126
|
+
const detail = all[id];
|
|
127
|
+
if (!detail) {
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
// Catalog shell — strip price + availability; the Offer domain owns them.
|
|
131
|
+
return { ...detail, prices: [], stocks: [] };
|
|
127
132
|
}
|
|
128
133
|
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import productList from "../data/product-list.json";
|
|
2
|
+
import type { Offer, OfferRequestItem } from "../interfaces/offer";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Demo offer source. Prices and availability for the demo shop live HERE —
|
|
6
|
+
* NOT in the catalog payload or the Typesense index — so the demo exercises
|
|
7
|
+
* the exact same decoupled path as live: catalog renders the shell, the offer
|
|
8
|
+
* is resolved separately. Standing in for the production ERP/price upstream.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
interface OfferRecord {
|
|
12
|
+
prices: { [key: string]: number }[];
|
|
13
|
+
stocks: { quantity: number; maxOrderQuantity: number }[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function buildIndex(): Map<string, OfferRecord> {
|
|
17
|
+
const map = new Map<string, OfferRecord>();
|
|
18
|
+
for (const entry of productList) {
|
|
19
|
+
const product = entry.product?.[0];
|
|
20
|
+
if (!product) {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
const record: OfferRecord = {
|
|
24
|
+
prices: (entry.prices as { [key: string]: number }[]) ?? [],
|
|
25
|
+
stocks: entry.stocks ?? [],
|
|
26
|
+
};
|
|
27
|
+
map.set(String(product.id), record);
|
|
28
|
+
if (product.sku) {
|
|
29
|
+
map.set(product.sku, record);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return map;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const INDEX = buildIndex();
|
|
36
|
+
|
|
37
|
+
/** Stable hash → deterministic offer for inflated/seeded ids unknown to the base data. */
|
|
38
|
+
function syntheticOffer(seed: string): OfferRecord {
|
|
39
|
+
let hash = 0;
|
|
40
|
+
for (let i = 0; i < seed.length; i++) {
|
|
41
|
+
hash = (hash * 31 + seed.charCodeAt(i)) >>> 0;
|
|
42
|
+
}
|
|
43
|
+
const unitCents = 1990 + (hash % 480) * 100; // 19.90 … ~499.90 €
|
|
44
|
+
const quantity = hash % 7 === 0 ? 0 : 5 + (hash % 200); // ~1/7 out of stock
|
|
45
|
+
return {
|
|
46
|
+
prices: [{ "1": unitCents, "10": unitCents * 9 }],
|
|
47
|
+
stocks: [{ quantity, maxOrderQuantity: Math.max(1, Math.floor(quantity / 2)) }],
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Demo ids/skus from the inflated Typesense seed: `id + n*100000`, `sku-n`. */
|
|
52
|
+
function lookup(item: OfferRequestItem): OfferRecord {
|
|
53
|
+
const byId = INDEX.get(item.id);
|
|
54
|
+
if (byId) {
|
|
55
|
+
return byId;
|
|
56
|
+
}
|
|
57
|
+
const numeric = Number(item.id);
|
|
58
|
+
if (Number.isFinite(numeric) && numeric >= 100_000) {
|
|
59
|
+
const base = INDEX.get(String(numeric % 100_000));
|
|
60
|
+
if (base) {
|
|
61
|
+
return base;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (item.sku) {
|
|
65
|
+
const bySku = INDEX.get(item.sku) ?? INDEX.get(item.sku.replace(/-\d+$/, ""));
|
|
66
|
+
if (bySku) {
|
|
67
|
+
return bySku;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return syntheticOffer(item.sku ?? item.id);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export class MockOfferService {
|
|
74
|
+
resolve(items: OfferRequestItem[]): Map<string, Offer> {
|
|
75
|
+
const out = new Map<string, Offer>();
|
|
76
|
+
for (const item of items) {
|
|
77
|
+
const record = lookup(item);
|
|
78
|
+
out.set(item.id, {
|
|
79
|
+
id: item.id,
|
|
80
|
+
prices: record.prices,
|
|
81
|
+
stocks: record.stocks,
|
|
82
|
+
isOutOfStock: (record.stocks[0]?.quantity ?? 0) <= 0,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return out;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export const mockOfferService = new MockOfferService();
|
|
@@ -56,8 +56,6 @@ const PRODUCT_PLACEHOLDER_IMAGE = "/img/product-placeholder.svg";
|
|
|
56
56
|
/** TODO(markets): resolve from the market's tax classes instead of a constant. */
|
|
57
57
|
const LIVE_DEFAULT_TAX_RATE = 19;
|
|
58
58
|
|
|
59
|
-
/** The live index has no stock data — treat everything as orderable. */
|
|
60
|
-
const LIVE_DEFAULT_STOCK = { quantity: 9999, maxOrderQuantity: 999999 };
|
|
61
59
|
|
|
62
60
|
export async function searchLiveProducts(params: LiveSearchParams): Promise<LiveSearchResponse> {
|
|
63
61
|
// Raw call (GET form): the gateway currently 404s the POST search route
|
|
@@ -94,9 +92,10 @@ export function mapLiveDocToProduct(doc: LiveProductDoc): Product {
|
|
|
94
92
|
name: doc.name,
|
|
95
93
|
sku: doc.sku,
|
|
96
94
|
available: doc.enabled,
|
|
95
|
+
// Catalog shell — price + availability are the Offer domain.
|
|
97
96
|
isOutOfStock: false,
|
|
98
97
|
prices: [],
|
|
99
|
-
stocks: [
|
|
98
|
+
stocks: [],
|
|
100
99
|
tax: { rate: LIVE_DEFAULT_TAX_RATE },
|
|
101
100
|
image: PRODUCT_PLACEHOLDER_IMAGE,
|
|
102
101
|
category,
|
|
@@ -119,7 +118,7 @@ export function mapLiveDocToDetail(doc: LiveProductDoc): ProductDetail {
|
|
|
119
118
|
deletedAt: null,
|
|
120
119
|
available: doc.enabled,
|
|
121
120
|
}],
|
|
122
|
-
stocks: [
|
|
121
|
+
stocks: [],
|
|
123
122
|
tax: { rate: LIVE_DEFAULT_TAX_RATE },
|
|
124
123
|
descriptions: doc.description
|
|
125
124
|
? [{ type: "long", content: doc.description }]
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import type { H3Event } from "h3";
|
|
2
1
|
import type { Models } from "@revenexx/sdk";
|
|
3
2
|
|
|
4
|
-
import type {
|
|
5
|
-
import type { ProductDetail } from "../../app/interfaces/product-detail";
|
|
3
|
+
import type { Offer, OfferRequestItem } from "../interfaces/offer";
|
|
6
4
|
|
|
7
5
|
/**
|
|
8
|
-
* Live availability from the inventories app — THE stock call (
|
|
9
|
-
* designated gateway override point for
|
|
10
|
-
* their real `available` quantity and
|
|
11
|
-
* inventory (`tracked: false`) keep selling
|
|
12
|
-
* storefront's call,
|
|
6
|
+
* Live availability from the inventories app — THE stock call (the Offer
|
|
7
|
+
* domain's availability axis, and the designated gateway override point for
|
|
8
|
+
* ERP stock). Tracked items get their real `available` quantity and
|
|
9
|
+
* `orderable` flag; items unknown to inventory (`tracked: false`) keep selling
|
|
10
|
+
* freely — the storefront's call, permissive in the demo.
|
|
13
11
|
*/
|
|
14
12
|
|
|
15
13
|
const UNTRACKED_STOCK = { quantity: 9999, maxOrderQuantity: 999999 };
|
|
@@ -42,35 +40,29 @@ async function fetchAvailability(items: Array<{ product_id?: string; sku?: strin
|
|
|
42
40
|
return byKey;
|
|
43
41
|
}
|
|
44
42
|
|
|
45
|
-
/**
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Batch-resolve live availability for the given items, keyed by product id.
|
|
45
|
+
* Missing items map to "unknown" (empty stocks, orderable). Drives the Offer
|
|
46
|
+
* provider.
|
|
47
|
+
*/
|
|
48
|
+
export async function resolveLiveAvailabilityMap(
|
|
49
|
+
items: OfferRequestItem[],
|
|
50
|
+
): Promise<Map<string, { stocks: Offer["stocks"]; isOutOfStock: boolean }>> {
|
|
51
|
+
const out = new Map<string, { stocks: Offer["stocks"]; isOutOfStock: boolean }>();
|
|
52
|
+
if (items.length === 0) {
|
|
53
|
+
return out;
|
|
49
54
|
}
|
|
50
|
-
const byKey = await fetchAvailability(
|
|
51
|
-
|
|
52
|
-
const entry = byKey.get(
|
|
55
|
+
const byKey = await fetchAvailability(items.map(i => ({ product_id: i.id, sku: i.sku })));
|
|
56
|
+
for (const item of items) {
|
|
57
|
+
const entry = byKey.get(item.id) ?? (item.sku ? byKey.get(item.sku) : undefined);
|
|
53
58
|
if (!entry) {
|
|
54
|
-
|
|
59
|
+
out.set(item.id, { stocks: [], isOutOfStock: false });
|
|
60
|
+
continue;
|
|
55
61
|
}
|
|
56
|
-
|
|
57
|
-
...product,
|
|
62
|
+
out.set(item.id, {
|
|
58
63
|
stocks: [toStock(entry)],
|
|
59
64
|
isOutOfStock: entry.tracked && !entry.orderable,
|
|
60
|
-
};
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/** Single-product variant for the PDP detail payload. */
|
|
65
|
-
export async function enrichDetailWithLiveAvailability(event: H3Event, detail: ProductDetail): Promise<ProductDetail> {
|
|
66
|
-
const product = detail.product[0];
|
|
67
|
-
if (!product) {
|
|
68
|
-
return detail;
|
|
69
|
-
}
|
|
70
|
-
const byKey = await fetchAvailability([{ product_id: product.id, sku: product.sku }]);
|
|
71
|
-
const entry = byKey.get(product.id) ?? byKey.get(product.sku);
|
|
72
|
-
if (!entry) {
|
|
73
|
-
return detail;
|
|
65
|
+
});
|
|
74
66
|
}
|
|
75
|
-
return
|
|
67
|
+
return out;
|
|
76
68
|
}
|
|
@@ -2,15 +2,15 @@ import type { H3Event } from "h3";
|
|
|
2
2
|
import type { Models } from "@revenexx/sdk";
|
|
3
3
|
|
|
4
4
|
import type { StoredSession } from "../../app/interfaces/auth";
|
|
5
|
-
import type {
|
|
6
|
-
import type { ProductDetail } from "../../app/interfaces/product-detail";
|
|
5
|
+
import type { Offer, OfferRequestItem } from "../interfaces/offer";
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
|
-
* Live prices from the prices app — THE live price call
|
|
10
|
-
* price shape is the tier map
|
|
11
|
-
*
|
|
12
|
-
* quantity. A product the prices
|
|
13
|
-
* EMPTY prices array — the UI renders
|
|
8
|
+
* Live prices from the prices app — THE live price call (the Offer domain's
|
|
9
|
+
* price axis). The storefront's price shape is the tier map
|
|
10
|
+
* (`prices: [{ "<qty>": totalCents }]`), so the resolve response (unit prices
|
|
11
|
+
* per tier) converts to total cents per tier quantity. A product the prices
|
|
12
|
+
* app answers `on_request` for keeps an EMPTY prices array — the UI renders
|
|
13
|
+
* "price on request", never €0.
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
interface ResolvedPrice {
|
|
@@ -55,16 +55,20 @@ function toPriceMap(resolved: ResolvedPrice): { [key: string]: number }[] {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
/**
|
|
58
|
-
* Batch-
|
|
59
|
-
*
|
|
58
|
+
* Batch-resolve live price tiers for the given items, keyed by product id.
|
|
59
|
+
* Missing items map to `[]` (price on request). Drives the Offer provider.
|
|
60
60
|
*/
|
|
61
|
-
export async function
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
export async function resolveLivePriceMap(
|
|
62
|
+
event: H3Event,
|
|
63
|
+
items: OfferRequestItem[],
|
|
64
|
+
): Promise<Map<string, Offer["prices"]>> {
|
|
65
|
+
const out = new Map<string, Offer["prices"]>();
|
|
66
|
+
if (items.length === 0) {
|
|
67
|
+
return out;
|
|
64
68
|
}
|
|
65
69
|
const currency = resolveSelectedCurrency(event);
|
|
66
70
|
const { prices } = await useRevenexxSdk().prices.pricesResolve({
|
|
67
|
-
items:
|
|
71
|
+
items: items.map(i => ({ product_id: i.id, sku: i.sku, quantity: 1 })) as Models.PriceResolveItem[],
|
|
68
72
|
...priceContext(event),
|
|
69
73
|
...(currency ? { currency } : {}),
|
|
70
74
|
}) as unknown as { prices: ResolvedPrice[] };
|
|
@@ -75,24 +79,9 @@ export async function enrichProductsWithLivePrices(event: H3Event, products: Pro
|
|
|
75
79
|
else if (price.sku) byKey.set(price.sku, price);
|
|
76
80
|
}
|
|
77
81
|
|
|
78
|
-
|
|
79
|
-
const resolved = byKey.get(
|
|
80
|
-
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/** Single-product variant for the PDP detail payload. */
|
|
85
|
-
export async function enrichDetailWithLivePrices(event: H3Event, detail: ProductDetail): Promise<ProductDetail> {
|
|
86
|
-
const product = detail.product[0];
|
|
87
|
-
if (!product) {
|
|
88
|
-
return detail;
|
|
82
|
+
for (const item of items) {
|
|
83
|
+
const resolved = byKey.get(item.id) ?? (item.sku ? byKey.get(item.sku) : undefined);
|
|
84
|
+
out.set(item.id, resolved ? toPriceMap(resolved) : []);
|
|
89
85
|
}
|
|
90
|
-
|
|
91
|
-
const { prices } = await useRevenexxSdk().prices.pricesResolve({
|
|
92
|
-
items: [{ product_id: product.id, sku: product.sku, quantity: 1 }] as Models.PriceResolveItem[],
|
|
93
|
-
...priceContext(event),
|
|
94
|
-
...(currency ? { currency } : {}),
|
|
95
|
-
}) as unknown as { prices: ResolvedPrice[] };
|
|
96
|
-
const resolved = prices[0];
|
|
97
|
-
return { ...detail, prices: resolved ? toPriceMap(resolved) : [] };
|
|
86
|
+
return out;
|
|
98
87
|
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { H3Event } from "h3";
|
|
2
|
+
|
|
3
|
+
import type { Offer, OfferRequestItem } from "../interfaces/offer";
|
|
4
|
+
import { mockOfferService } from "../services/MockOfferService";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The Offer provider — composes a product's PRICE (priceService axis) and
|
|
8
|
+
* AVAILABILITY (inventoryService axis) into one Offer. Each axis resolves
|
|
9
|
+
* independently against its registry key ("mock" = demo stub, "api" = live
|
|
10
|
+
* upstream), so price can be live while stock stays demo, or vice versa.
|
|
11
|
+
*
|
|
12
|
+
* This is the ONLY place price + availability are fetched. Catalog and search
|
|
13
|
+
* never call it — they return the shell; the client hydrates offers via
|
|
14
|
+
* POST /api/offers after first paint.
|
|
15
|
+
*/
|
|
16
|
+
export async function getOffers(event: H3Event, items: OfferRequestItem[]): Promise<Map<string, Offer>> {
|
|
17
|
+
const seen = new Set<string>();
|
|
18
|
+
const unique: OfferRequestItem[] = [];
|
|
19
|
+
for (const item of items) {
|
|
20
|
+
if (!item?.id || seen.has(item.id)) {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
seen.add(item.id);
|
|
24
|
+
unique.push({ id: item.id, ...(item.sku ? { sku: item.sku } : {}) });
|
|
25
|
+
}
|
|
26
|
+
if (unique.length === 0) {
|
|
27
|
+
return new Map();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const priceLive = resolvePriceServiceKey(event) === "api";
|
|
31
|
+
const stockLive = resolveInventoryServiceKey(event) === "api";
|
|
32
|
+
|
|
33
|
+
const [livePrices, liveAvailability, mock] = await Promise.all([
|
|
34
|
+
priceLive ? resolveLivePriceMap(event, unique) : null,
|
|
35
|
+
stockLive ? resolveLiveAvailabilityMap(unique) : null,
|
|
36
|
+
priceLive && stockLive ? null : Promise.resolve(mockOfferService.resolve(unique)),
|
|
37
|
+
]);
|
|
38
|
+
|
|
39
|
+
const out = new Map<string, Offer>();
|
|
40
|
+
for (const item of unique) {
|
|
41
|
+
const demo = mock?.get(item.id);
|
|
42
|
+
const prices = priceLive
|
|
43
|
+
? (livePrices!.get(item.id) ?? [])
|
|
44
|
+
: (demo?.prices ?? []);
|
|
45
|
+
const availability = stockLive
|
|
46
|
+
? (liveAvailability!.get(item.id) ?? { stocks: [], isOutOfStock: false })
|
|
47
|
+
: { stocks: demo?.stocks ?? [], isOutOfStock: demo?.isOutOfStock ?? false };
|
|
48
|
+
|
|
49
|
+
out.set(item.id, {
|
|
50
|
+
id: item.id,
|
|
51
|
+
prices,
|
|
52
|
+
stocks: availability.stocks,
|
|
53
|
+
isOutOfStock: availability.isOutOfStock,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return out;
|
|
57
|
+
}
|
|
@@ -10,9 +10,9 @@ export const productsSchema = {
|
|
|
10
10
|
{ name: "sku", type: "string" as const },
|
|
11
11
|
{ name: "manufacturer", type: "string" as const, facet: true },
|
|
12
12
|
{ name: "available", type: "bool" as const, facet: true },
|
|
13
|
-
|
|
13
|
+
// Catalog list price — a sort/filter key ONLY (not the displayed price).
|
|
14
|
+
// The buyer-facing price tiers + stock are the Offer domain, never indexed.
|
|
14
15
|
{ name: "price", type: "int32" as const },
|
|
15
|
-
{ name: "prices", type: "object" as const },
|
|
16
16
|
{ name: "description", type: "string" as const, optional: true },
|
|
17
17
|
{ name: "category", type: "string" as const, facet: true },
|
|
18
18
|
{ name: "categorySlug", type: "string" as const, facet: true },
|