@revenexx/cover 0.1.24 → 0.2.1
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/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/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/plugins/model-viewer.client.ts +7 -0
- package/nuxt.config.ts +8 -0
- package/package.json +2 -1
- 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/ApiAuthService.ts +13 -3
- 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
|
@@ -39,13 +39,17 @@ const { data: products } = useFetch<Product[]>(productsApi.list(), {
|
|
|
39
39
|
default: () => [],
|
|
40
40
|
});
|
|
41
41
|
|
|
42
|
+
// Offer (price + availability) is its own axis — merge it onto the catalog
|
|
43
|
+
// so direct-order rows resolve an orderable product with a price.
|
|
44
|
+
const offeredProducts = useOffers().withOffers(() => products.value ?? []);
|
|
45
|
+
|
|
42
46
|
function findProduct(sku: string): Product | undefined {
|
|
43
47
|
const needle = sku.trim().toLowerCase();
|
|
44
48
|
if (!needle) {
|
|
45
49
|
return undefined;
|
|
46
50
|
}
|
|
47
|
-
return
|
|
48
|
-
??
|
|
51
|
+
return offeredProducts.value.find(p => p.sku.toLowerCase() === needle)
|
|
52
|
+
?? offeredProducts.value.find(p => p.sku.toLowerCase().includes(needle));
|
|
49
53
|
}
|
|
50
54
|
|
|
51
55
|
/* ---- tab 1: quick row entry ----------------------------------------- */
|
|
@@ -198,8 +202,8 @@ function addProductToCart(product: Product, quantity: number, customSku?: string
|
|
|
198
202
|
categorySlug: product.categorySlug,
|
|
199
203
|
subcategorySlug: product.subcategorySlug,
|
|
200
204
|
...(customSku?.trim() ? { customSku: customSku.trim() } : {}),
|
|
201
|
-
...(typeof product.maxOrderQuantity === "number"
|
|
202
|
-
? { maxOrderQuantity: product.maxOrderQuantity }
|
|
205
|
+
...(typeof product.stocks?.[0]?.maxOrderQuantity === "number"
|
|
206
|
+
? { maxOrderQuantity: product.stocks[0].maxOrderQuantity }
|
|
203
207
|
: {}),
|
|
204
208
|
});
|
|
205
209
|
if (ok && quantity > 1) {
|
|
@@ -25,7 +25,7 @@ const { data: products } = useFetch<Product[]>(productsApi.list(), {
|
|
|
25
25
|
default: () => [],
|
|
26
26
|
});
|
|
27
27
|
|
|
28
|
-
const
|
|
28
|
+
const rawMatches = computed(() => {
|
|
29
29
|
const q = sku.value.trim().toLowerCase();
|
|
30
30
|
if (q.length < 2) {
|
|
31
31
|
return [];
|
|
@@ -35,6 +35,9 @@ const matches = computed(() => {
|
|
|
35
35
|
.slice(0, 5);
|
|
36
36
|
});
|
|
37
37
|
|
|
38
|
+
// Offers (price + availability) hydrate only for the few shown matches.
|
|
39
|
+
const matches = useOffers().withOffers(() => rawMatches.value);
|
|
40
|
+
|
|
38
41
|
function buildTiers(prices: { [key: string]: number }[]) {
|
|
39
42
|
return getPriceTiers(prices).map(tier => ({
|
|
40
43
|
minQuantity: tier.quantity,
|
|
@@ -59,8 +62,8 @@ function addProduct(product: Product): void {
|
|
|
59
62
|
priceTiers: buildTiers(product.prices),
|
|
60
63
|
categorySlug: product.categorySlug,
|
|
61
64
|
subcategorySlug: product.subcategorySlug,
|
|
62
|
-
...(typeof product.maxOrderQuantity === "number"
|
|
63
|
-
? { maxOrderQuantity: product.maxOrderQuantity }
|
|
65
|
+
...(typeof product.stocks?.[0]?.maxOrderQuantity === "number"
|
|
66
|
+
? { maxOrderQuantity: product.stocks[0].maxOrderQuantity }
|
|
64
67
|
: {}),
|
|
65
68
|
}, { chooseTarget: true });
|
|
66
69
|
if (added && qty > 1) {
|
|
@@ -38,12 +38,15 @@ const { data } = useFetch<{ products: ProductList[] }>(searchApi.search(), {
|
|
|
38
38
|
default: () => ({ products: [] }),
|
|
39
39
|
});
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
// Offers (price + availability) hydrate for the cross-sell candidates; the
|
|
42
|
+
// out-of-stock filter applies once they resolve.
|
|
43
|
+
const candidates = useOffers().withOffers(() => {
|
|
42
44
|
const inCart = new Set(cart.items.map(item => item.id));
|
|
43
|
-
return (data.value.products ?? [])
|
|
44
|
-
.filter(product => !inCart.has(product.id) && !product.isOutOfStock)
|
|
45
|
-
.slice(0, 8);
|
|
45
|
+
return (data.value.products ?? []).filter(product => !inCart.has(product.id));
|
|
46
46
|
});
|
|
47
|
+
const suggestions = computed(() =>
|
|
48
|
+
candidates.value.filter(product => !product.isOutOfStock).slice(0, 8),
|
|
49
|
+
);
|
|
47
50
|
|
|
48
51
|
function add(product: ProductList): void {
|
|
49
52
|
const price = getBaseUnitPrice(product.prices);
|
|
@@ -14,10 +14,14 @@ const props = defineProps<{
|
|
|
14
14
|
product: ProductList;
|
|
15
15
|
}>();
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
// Price is the Offer domain — resolved separately, hydrates after first paint.
|
|
18
|
+
const { offer, pending } = useOffers().useOffer(() => props.product.id);
|
|
19
|
+
const offerPrices = computed(() => offer.value?.prices ?? []);
|
|
20
|
+
|
|
21
|
+
const tiers = computed(() => getPriceTiers(offerPrices.value));
|
|
18
22
|
const hasTieredPricing = computed(() => tiers.value.length > 1);
|
|
19
23
|
const displayPrice = computed<number | null>(() => {
|
|
20
|
-
const basePrice = getDisplayUnitPrice(
|
|
24
|
+
const basePrice = getDisplayUnitPrice(offerPrices.value);
|
|
21
25
|
if (basePrice === null) {
|
|
22
26
|
return null;
|
|
23
27
|
}
|
|
@@ -28,7 +32,12 @@ const displayPrice = computed<number | null>(() => {
|
|
|
28
32
|
|
|
29
33
|
<template>
|
|
30
34
|
<div>
|
|
31
|
-
|
|
35
|
+
<!-- Offer still loading — show a placeholder, never a flash of €0. -->
|
|
36
|
+
<USkeleton
|
|
37
|
+
v-if="pending"
|
|
38
|
+
class="h-6 w-24"
|
|
39
|
+
/>
|
|
40
|
+
<template v-else-if="displayPrice !== null">
|
|
32
41
|
<div v-if="hasTieredPricing">
|
|
33
42
|
<span class="text-sm text-muted mt-0.5">{{ t('product.price.from') }}</span>
|
|
34
43
|
{{ formatPrice(displayPrice) }}
|
|
@@ -5,15 +5,25 @@ const { icon } = useIcons();
|
|
|
5
5
|
|
|
6
6
|
const { t } = useI18n();
|
|
7
7
|
|
|
8
|
-
defineProps<{
|
|
8
|
+
const props = defineProps<{
|
|
9
9
|
product: ProductList;
|
|
10
|
-
isOutOfStock: boolean;
|
|
11
10
|
}>();
|
|
11
|
+
|
|
12
|
+
// Availability is the Offer domain — resolved separately, hydrates after paint.
|
|
13
|
+
const { offer, pending } = useOffers().useOffer(() => props.product.id);
|
|
14
|
+
const isOutOfStock = computed(() => offer.value?.isOutOfStock ?? false);
|
|
12
15
|
</script>
|
|
13
16
|
|
|
14
17
|
<template>
|
|
15
18
|
<div>
|
|
16
|
-
<
|
|
19
|
+
<USkeleton
|
|
20
|
+
v-if="pending"
|
|
21
|
+
class="h-5 w-28"
|
|
22
|
+
/>
|
|
23
|
+
<span
|
|
24
|
+
v-else
|
|
25
|
+
class="flex items-center gap-1 text-sm font-medium"
|
|
26
|
+
>
|
|
17
27
|
{{ !isOutOfStock ? t('product.stock.available') : t('product.stock.unavailable') }}
|
|
18
28
|
<UIcon
|
|
19
29
|
:name="!isOutOfStock ? icon('check') : icon('close')"
|
|
@@ -42,10 +42,7 @@ const { isOutOfStock, hasPrice, addToCart } = useProductCardActions(() => props.
|
|
|
42
42
|
{{ product.name }}
|
|
43
43
|
</NuxtLink>
|
|
44
44
|
<CategoryInfoCategorySku :product="product" />
|
|
45
|
-
<CategoryInfoCategoryStock
|
|
46
|
-
:product="product"
|
|
47
|
-
:is-out-of-stock="isOutOfStock"
|
|
48
|
-
/>
|
|
45
|
+
<CategoryInfoCategoryStock :product="product" />
|
|
49
46
|
<CategoryInfoCategoryPrice :product="product" />
|
|
50
47
|
</div>
|
|
51
48
|
<template #footer>
|
|
@@ -41,10 +41,7 @@ const { isOutOfStock, hasPrice, addToCart } = useProductCardActions(() => props.
|
|
|
41
41
|
{{ product.name }}
|
|
42
42
|
</NuxtLink>
|
|
43
43
|
<CategoryInfoCategorySku :product="product" />
|
|
44
|
-
<CategoryInfoCategoryStock
|
|
45
|
-
:product="product"
|
|
46
|
-
:is-out-of-stock="isOutOfStock"
|
|
47
|
-
/>
|
|
44
|
+
<CategoryInfoCategoryStock :product="product" />
|
|
48
45
|
</div>
|
|
49
46
|
<div class="shrink-0 flex flex-col items-end gap-2">
|
|
50
47
|
<CategoryInfoCategoryPrice :product="product" />
|
|
@@ -4,13 +4,27 @@ import type { ProductDetailImage } from "../../../interfaces/product-detail";
|
|
|
4
4
|
const props = defineProps<{
|
|
5
5
|
images: ProductDetailImage[];
|
|
6
6
|
getImageUrl: (filename: string) => string;
|
|
7
|
+
/** Optional interactive 3D model (the asset's model_url, a .glb). */
|
|
8
|
+
modelUrl?: string | null;
|
|
9
|
+
/** Optional preview image shown before the 3D model loads (preview_url). */
|
|
10
|
+
modelPoster?: string | null;
|
|
7
11
|
}>();
|
|
8
12
|
|
|
13
|
+
const has3d = computed(() => !!props.modelUrl);
|
|
14
|
+
|
|
15
|
+
// 'image' shows the selected still; 'model' shows the interactive 3D viewer.
|
|
16
|
+
const mode = ref<"image" | "model">("image");
|
|
9
17
|
const selectedIndex = ref(0);
|
|
10
18
|
const selectedImage = computed(() => props.images[selectedIndex.value]);
|
|
11
19
|
|
|
20
|
+
function showImage(index: number): void {
|
|
21
|
+
selectedIndex.value = index;
|
|
22
|
+
mode.value = "image";
|
|
23
|
+
}
|
|
24
|
+
|
|
12
25
|
watch(() => props.images, () => {
|
|
13
26
|
selectedIndex.value = 0;
|
|
27
|
+
mode.value = "image";
|
|
14
28
|
});
|
|
15
29
|
</script>
|
|
16
30
|
|
|
@@ -20,8 +34,17 @@ watch(() => props.images, () => {
|
|
|
20
34
|
class="w-full aspect-square rounded-2xl overflow-hidden bg-elevated/60
|
|
21
35
|
ring-1 ring-(--ui-border) flex items-center justify-center p-8"
|
|
22
36
|
>
|
|
37
|
+
<!-- Interactive 3D (sovereign three.js engine; no AR). The square box
|
|
38
|
+
gives model-viewer a definite height so its canvas doesn't collapse. -->
|
|
39
|
+
<rx-model-viewer
|
|
40
|
+
v-if="mode === 'model' && modelUrl"
|
|
41
|
+
:src="modelUrl"
|
|
42
|
+
:poster="modelPoster || undefined"
|
|
43
|
+
auto-rotate
|
|
44
|
+
class="w-full h-full"
|
|
45
|
+
/>
|
|
23
46
|
<img
|
|
24
|
-
v-if="selectedImage"
|
|
47
|
+
v-else-if="selectedImage"
|
|
25
48
|
:src="getImageUrl(selectedImage.url)"
|
|
26
49
|
:alt="`Product image ${selectedIndex + 1}`"
|
|
27
50
|
class="max-w-full max-h-full object-contain"
|
|
@@ -29,7 +52,7 @@ watch(() => props.images, () => {
|
|
|
29
52
|
</div>
|
|
30
53
|
|
|
31
54
|
<div
|
|
32
|
-
v-if="images.length > 1"
|
|
55
|
+
v-if="images.length > 1 || has3d"
|
|
33
56
|
class="grid grid-cols-5 sm:grid-cols-6 gap-2"
|
|
34
57
|
>
|
|
35
58
|
<button
|
|
@@ -40,12 +63,12 @@ watch(() => props.images, () => {
|
|
|
40
63
|
class="aspect-square rounded-lg overflow-hidden bg-elevated/60 p-1.5
|
|
41
64
|
ring-1 transition-all cursor-pointer
|
|
42
65
|
focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-(--ui-primary)"
|
|
43
|
-
:class="index === selectedIndex
|
|
66
|
+
:class="mode === 'image' && index === selectedIndex
|
|
44
67
|
? 'ring-2 ring-(--ui-primary)'
|
|
45
68
|
: 'ring-(--ui-border) hover:ring-(--ui-primary)/50'"
|
|
46
69
|
:aria-label="`Thumbnail ${index + 1}`"
|
|
47
|
-
:aria-pressed="index === selectedIndex"
|
|
48
|
-
@click="
|
|
70
|
+
:aria-pressed="mode === 'image' && index === selectedIndex"
|
|
71
|
+
@click="showImage(index)"
|
|
49
72
|
>
|
|
50
73
|
<img
|
|
51
74
|
:src="getImageUrl(image.url)"
|
|
@@ -53,6 +76,28 @@ watch(() => props.images, () => {
|
|
|
53
76
|
class="w-full h-full object-contain"
|
|
54
77
|
>
|
|
55
78
|
</button>
|
|
79
|
+
|
|
80
|
+
<!-- 3D entry -->
|
|
81
|
+
<button
|
|
82
|
+
v-if="has3d"
|
|
83
|
+
type="button"
|
|
84
|
+
tabindex="0"
|
|
85
|
+
class="aspect-square rounded-lg overflow-hidden bg-elevated/60
|
|
86
|
+
ring-1 transition-all cursor-pointer flex flex-col items-center justify-center gap-0.5
|
|
87
|
+
focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-(--ui-primary)"
|
|
88
|
+
:class="mode === 'model'
|
|
89
|
+
? 'ring-2 ring-(--ui-primary)'
|
|
90
|
+
: 'ring-(--ui-border) hover:ring-(--ui-primary)/50'"
|
|
91
|
+
aria-label="3D view"
|
|
92
|
+
:aria-pressed="mode === 'model'"
|
|
93
|
+
@click="mode = 'model'"
|
|
94
|
+
>
|
|
95
|
+
<UIcon
|
|
96
|
+
name="i-lucide-rotate-3d"
|
|
97
|
+
class="size-5 text-muted"
|
|
98
|
+
/>
|
|
99
|
+
<span class="text-[10px] font-semibold uppercase tracking-wide text-muted">3D</span>
|
|
100
|
+
</button>
|
|
56
101
|
</div>
|
|
57
102
|
</div>
|
|
58
103
|
</template>
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { offersApi } from "../api/offers";
|
|
2
|
+
import type { ProductList } from "../interfaces/product-list";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Client-side Offer layer — the buyer-facing PRICE + AVAILABILITY, fetched on
|
|
6
|
+
* its own axis, decoupled from catalog and search.
|
|
7
|
+
*
|
|
8
|
+
* Catalog/search render the shell during SSR; `loadOffers()` is a no-op on the
|
|
9
|
+
* server, so the first byte never waits on the (heavyweight, ERP-grade) offer
|
|
10
|
+
* call. After hydration the page batches the visible products into ONE
|
|
11
|
+
* POST /api/offers, fills a shared cache, and the price/stock widgets fade in.
|
|
12
|
+
*
|
|
13
|
+
* Failure is soft: an unresolved offer reads as "price on request", never €0.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export interface OfferStock {
|
|
17
|
+
quantity: number;
|
|
18
|
+
maxOrderQuantity: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface Offer {
|
|
22
|
+
id: string;
|
|
23
|
+
prices: { [key: string]: number }[];
|
|
24
|
+
stocks: OfferStock[];
|
|
25
|
+
isOutOfStock: boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
type OfferRef = Pick<ProductList, "id" | "sku">;
|
|
29
|
+
|
|
30
|
+
export function useOffers() {
|
|
31
|
+
const cache = useState<Record<string, Offer>>("offers:cache", () => ({}));
|
|
32
|
+
const inflight = useState<Record<string, boolean>>("offers:pending", () => ({}));
|
|
33
|
+
// Ids whose offer fetch has finished (resolved or soft-failed). Until then a
|
|
34
|
+
// product reads as "pending" so SSR and the client both render a skeleton —
|
|
35
|
+
// no flash of "price on request", no hydration mismatch.
|
|
36
|
+
const attempted = useState<Record<string, boolean>>("offers:attempted", () => ({}));
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Batch-resolve offers for the given products. Deduped against cache and
|
|
40
|
+
* in-flight requests. Client-only — deferred so SSR is never blocked.
|
|
41
|
+
*/
|
|
42
|
+
async function loadOffers(items: OfferRef[]): Promise<void> {
|
|
43
|
+
if (import.meta.server) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const want = items.filter(
|
|
47
|
+
item => item?.id && !(item.id in cache.value) && !inflight.value[item.id],
|
|
48
|
+
);
|
|
49
|
+
if (want.length === 0) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
inflight.value = {
|
|
54
|
+
...inflight.value,
|
|
55
|
+
...Object.fromEntries(want.map(item => [item.id, true])),
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
const { offers } = await $fetch<{ offers: Record<string, Offer> }>(offersApi.resolve(), {
|
|
60
|
+
method: "POST",
|
|
61
|
+
body: { items: want.map(item => ({ id: item.id, sku: item.sku })) },
|
|
62
|
+
});
|
|
63
|
+
cache.value = { ...cache.value, ...offers };
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
// Soft failure — leave uncached; widgets render "price on request".
|
|
67
|
+
}
|
|
68
|
+
finally {
|
|
69
|
+
const next = { ...inflight.value };
|
|
70
|
+
for (const item of want) {
|
|
71
|
+
delete next[item.id];
|
|
72
|
+
}
|
|
73
|
+
inflight.value = next;
|
|
74
|
+
attempted.value = {
|
|
75
|
+
...attempted.value,
|
|
76
|
+
...Object.fromEntries(want.map(item => [item.id, true])),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Reactive accessor for a single product's offer + its loading state. */
|
|
82
|
+
function useOffer(getId: MaybeRefOrGetter<string>) {
|
|
83
|
+
const id = computed(() => toValue(getId));
|
|
84
|
+
const offer = computed<Offer | undefined>(() => cache.value[id.value]);
|
|
85
|
+
// Skeleton until the offer is resolved OR the attempt has finished
|
|
86
|
+
// (soft-failed → render "on request"). Default-pending so SSR and the
|
|
87
|
+
// first client render agree.
|
|
88
|
+
const pending = computed(() => !offer.value && !attempted.value[id.value]);
|
|
89
|
+
return { offer, pending };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Reactive list of products with their offer (price + availability) merged
|
|
94
|
+
* in, auto-loading offers as the list changes. For surfaces that fetch a
|
|
95
|
+
* catalog list and need orderable cards (quick-add, cross-sell, direct
|
|
96
|
+
* order). Products without a resolved offer read as "price on request".
|
|
97
|
+
*/
|
|
98
|
+
function withOffers<T extends ProductList>(getItems: MaybeRefOrGetter<T[]>) {
|
|
99
|
+
const items = computed(() => toValue(getItems) ?? []);
|
|
100
|
+
watch(items, (list) => {
|
|
101
|
+
if (list.length) {
|
|
102
|
+
void loadOffers(list);
|
|
103
|
+
}
|
|
104
|
+
}, { immediate: true });
|
|
105
|
+
return computed<T[]>(() => items.value.map((product) => {
|
|
106
|
+
const found = cache.value[product.id];
|
|
107
|
+
return {
|
|
108
|
+
...product,
|
|
109
|
+
prices: found?.prices ?? [],
|
|
110
|
+
stocks: found?.stocks ?? [],
|
|
111
|
+
isOutOfStock: found?.isOutOfStock ?? false,
|
|
112
|
+
};
|
|
113
|
+
}));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return { loadOffers, useOffer, withOffers };
|
|
117
|
+
}
|
|
@@ -21,6 +21,17 @@ export const useProductDetail = (id: MaybeRefOrGetter<string>) => {
|
|
|
21
21
|
},
|
|
22
22
|
);
|
|
23
23
|
|
|
24
|
+
// Price + availability are the Offer domain — fetched on their own axis
|
|
25
|
+
// (heavyweight ERP call in production), never blocking the detail render.
|
|
26
|
+
const { loadOffers, useOffer } = useOffers();
|
|
27
|
+
const { offer, pending: offerPending } = useOffer(() => toValue(id));
|
|
28
|
+
watch(detail, (loaded) => {
|
|
29
|
+
const product = loaded?.product?.[0];
|
|
30
|
+
if (product) {
|
|
31
|
+
void loadOffers([{ id: toValue(id), sku: product.sku }]);
|
|
32
|
+
}
|
|
33
|
+
}, { immediate: true });
|
|
34
|
+
|
|
24
35
|
const productInfo = computed<ProductDetailProduct | undefined>(
|
|
25
36
|
() => detail.value?.product?.[0],
|
|
26
37
|
);
|
|
@@ -35,8 +46,9 @@ export const useProductDetail = (id: MaybeRefOrGetter<string>) => {
|
|
|
35
46
|
() => detail.value?.descriptions?.find(d => d.type === "long")?.content,
|
|
36
47
|
);
|
|
37
48
|
|
|
49
|
+
// From the offer, not the catalog detail payload.
|
|
38
50
|
const stocks = computed<ProductDetailStock[]>(
|
|
39
|
-
() =>
|
|
51
|
+
() => offer.value?.stocks ?? [],
|
|
40
52
|
);
|
|
41
53
|
|
|
42
54
|
const attributes = computed<ProductDetailAttribute[]>(
|
|
@@ -44,7 +56,7 @@ export const useProductDetail = (id: MaybeRefOrGetter<string>) => {
|
|
|
44
56
|
);
|
|
45
57
|
|
|
46
58
|
const prices = computed<{ [key: string]: number }[]>(
|
|
47
|
-
() =>
|
|
59
|
+
() => offer.value?.prices ?? [],
|
|
48
60
|
);
|
|
49
61
|
|
|
50
62
|
const taxRate = computed<number>(() => detail.value?.tax?.rate ?? 0);
|
|
@@ -83,7 +95,7 @@ export const useProductDetail = (id: MaybeRefOrGetter<string>) => {
|
|
|
83
95
|
return {
|
|
84
96
|
detail, status, error, refresh,
|
|
85
97
|
productInfo, mainImages, longDescription,
|
|
86
|
-
stocks, attributes, prices, taxRate,
|
|
98
|
+
stocks, attributes, prices, taxRate, offerPending,
|
|
87
99
|
productCategories, categorySlug, subcategorySlug,
|
|
88
100
|
formatPrice, getDetailImageUrl,
|
|
89
101
|
};
|
|
@@ -8,16 +8,16 @@ export function useProductCardActions(getProduct: () => ProductList) {
|
|
|
8
8
|
const { icon } = useIcons();
|
|
9
9
|
const { t } = useI18n();
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
// Price + availability are the Offer domain — resolved separately and
|
|
12
|
+
// hydrated after first paint. Until the offer arrives the card is
|
|
13
|
+
// optimistically in-stock but NOT orderable (no price yet).
|
|
14
|
+
const { offer } = useOffers().useOffer(() => getProduct().id);
|
|
15
|
+
const offerPrices = computed(() => offer.value?.prices ?? []);
|
|
16
|
+
|
|
17
|
+
const isOutOfStock = computed(() => offer.value?.isOutOfStock ?? false);
|
|
18
18
|
|
|
19
19
|
/** Price on request (no price for this buyer context) — not orderable online. */
|
|
20
|
-
const hasPrice = computed(() => getBaseUnitPrice(
|
|
20
|
+
const hasPrice = computed(() => getBaseUnitPrice(offerPrices.value) !== null);
|
|
21
21
|
|
|
22
22
|
function buildPriceTiers(prices: { [key: string]: number }[]): CartItemPriceTier[] {
|
|
23
23
|
if (!prices.length) {
|
|
@@ -48,7 +48,7 @@ export function useProductCardActions(getProduct: () => ProductList) {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
const quantity = 1;
|
|
51
|
-
const maxQuantity =
|
|
51
|
+
const maxQuantity = offer.value?.stocks?.[0]?.maxOrderQuantity;
|
|
52
52
|
const currentCartQuantity
|
|
53
53
|
= cart.items.find((item: CartItem) => item.id === product.id)?.quantity ?? 0;
|
|
54
54
|
|
|
@@ -63,7 +63,7 @@ export function useProductCardActions(getProduct: () => ProductList) {
|
|
|
63
63
|
return;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
const baseUnitPrice = getBaseUnitPrice(
|
|
66
|
+
const baseUnitPrice = getBaseUnitPrice(offerPrices.value);
|
|
67
67
|
if (baseUnitPrice === null) {
|
|
68
68
|
return;
|
|
69
69
|
}
|
|
@@ -75,7 +75,7 @@ export function useProductCardActions(getProduct: () => ProductList) {
|
|
|
75
75
|
sku: product.sku,
|
|
76
76
|
price: baseUnitPrice,
|
|
77
77
|
taxRate: product.tax.rate,
|
|
78
|
-
priceTiers: buildPriceTiers(
|
|
78
|
+
priceTiers: buildPriceTiers(offerPrices.value),
|
|
79
79
|
categorySlug: product.categorySlug,
|
|
80
80
|
subcategorySlug: product.subcategorySlug,
|
|
81
81
|
...(typeof maxQuantity === "number" ? { maxOrderQuantity: maxQuantity } : {}),
|
|
@@ -147,6 +147,16 @@ export function useProductListing(options: ProductListingOptions) {
|
|
|
147
147
|
|
|
148
148
|
/* ---- derived view state -------------------------------------------- */
|
|
149
149
|
const products = computed<ProductList[]>(() => data.value?.products ?? []);
|
|
150
|
+
|
|
151
|
+
// Offer (price + availability) is its own axis — batch-hydrate the visible
|
|
152
|
+
// hits AFTER they arrive, never blocking the catalog/search render.
|
|
153
|
+
const { loadOffers } = useOffers();
|
|
154
|
+
watch(products, (list) => {
|
|
155
|
+
if (list.length) {
|
|
156
|
+
void loadOffers(list);
|
|
157
|
+
}
|
|
158
|
+
}, { immediate: true });
|
|
159
|
+
|
|
150
160
|
const found = computed(() => data.value?.found ?? 0);
|
|
151
161
|
const totalPages = computed(() => Math.ceil(found.value / (productsPerPage as number)));
|
|
152
162
|
const isEmpty = computed(() => data.value !== null && data.value !== undefined && products.value.length === 0);
|
|
@@ -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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@revenexx/cover",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
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",
|
|
@@ -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
|
+
}
|
|
@@ -111,10 +111,20 @@ export class ApiAuthService implements IAuthService {
|
|
|
111
111
|
};
|
|
112
112
|
}
|
|
113
113
|
catch (err) {
|
|
114
|
-
|
|
115
|
-
|
|
114
|
+
// Only a genuine auth failure (401 = revoked/expired session) proves
|
|
115
|
+
// the session is gone — clear the cookie so the user logs out cleanly.
|
|
116
|
+
// Any other error (5xx like the gateway's "capability dispatch failed",
|
|
117
|
+
// or a network blip) is transient infrastructure trouble, NOT proof the
|
|
118
|
+
// session is invalid. Deleting the cookie here turned a flaky gateway
|
|
119
|
+
// into a SILENT LOGOUT + empty order history (the account history is
|
|
120
|
+
// filtered strictly by contact_id and falls back to me()). So keep the
|
|
121
|
+
// cookie and return null: callers still degrade to the guest path for
|
|
122
|
+
// this one request, and the session self-heals on the next.
|
|
123
|
+
if (isApiUserError(err) && err.code === 401) {
|
|
124
|
+
deleteCookie(event, SESSION_COOKIE_NAME, sessionCookieOptions());
|
|
125
|
+
return null;
|
|
116
126
|
}
|
|
117
|
-
|
|
127
|
+
getLogService().error("API request failed: auth/me", apiErrorContext(err));
|
|
118
128
|
return null;
|
|
119
129
|
}
|
|
120
130
|
}
|
|
@@ -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 },
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import type { H3Event } from "h3";
|
|
2
|
-
|
|
3
|
-
import type { Product } from "../../app/composables/useProducts";
|
|
4
|
-
import type { ProductDetail } from "../../app/interfaces/product-detail";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Live catalog enrichment fan-out: prices and availability come from two
|
|
8
|
-
* independent apps — fetch them IN PARALLEL and merge their fields. The
|
|
9
|
-
* sequential await-chain this replaces paid both round-trips back to back
|
|
10
|
-
* on every PDP and listing request (~2x upstream latency).
|
|
11
|
-
* Respects the per-request service keys; mock domains stay untouched.
|
|
12
|
-
*/
|
|
13
|
-
export async function enrichProductsLive<T extends Product>(event: H3Event, products: T[]): Promise<T[]> {
|
|
14
|
-
if (products.length === 0) {
|
|
15
|
-
return products;
|
|
16
|
-
}
|
|
17
|
-
const wantPrices = resolvePriceServiceKey(event) === "api";
|
|
18
|
-
const wantStock = resolveInventoryServiceKey(event) === "api";
|
|
19
|
-
if (!wantPrices && !wantStock) {
|
|
20
|
-
return products;
|
|
21
|
-
}
|
|
22
|
-
const [priced, stocked] = await Promise.all([
|
|
23
|
-
wantPrices ? enrichProductsWithLivePrices(event, products) : null,
|
|
24
|
-
wantStock ? enrichProductsWithLiveAvailability(event, products) : null,
|
|
25
|
-
]);
|
|
26
|
-
return products.map((product, i) => ({
|
|
27
|
-
...product,
|
|
28
|
-
...(priced?.[i] ? { prices: priced[i].prices } : {}),
|
|
29
|
-
...(stocked?.[i]
|
|
30
|
-
? { stocks: stocked[i].stocks, isOutOfStock: stocked[i].isOutOfStock }
|
|
31
|
-
: {}),
|
|
32
|
-
}));
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/** Single-detail variant for the PDP payload. */
|
|
36
|
-
export async function enrichDetailLive(event: H3Event, detail: ProductDetail): Promise<ProductDetail> {
|
|
37
|
-
const wantPrices = resolvePriceServiceKey(event) === "api";
|
|
38
|
-
const wantStock = resolveInventoryServiceKey(event) === "api";
|
|
39
|
-
if (!wantPrices && !wantStock) {
|
|
40
|
-
return detail;
|
|
41
|
-
}
|
|
42
|
-
const [priced, stocked] = await Promise.all([
|
|
43
|
-
wantPrices ? enrichDetailWithLivePrices(event, detail) : null,
|
|
44
|
-
wantStock ? enrichDetailWithLiveAvailability(event, detail) : null,
|
|
45
|
-
]);
|
|
46
|
-
return {
|
|
47
|
-
...detail,
|
|
48
|
-
...(priced ? { prices: priced.prices } : {}),
|
|
49
|
-
...(stocked ? { stocks: stocked.stocks } : {}),
|
|
50
|
-
};
|
|
51
|
-
}
|