@revenexx/cover 0.12.0 → 0.13.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/components/cart/recommend/CartCrossSell.vue +2 -1
- package/app/components/listing/ListingFilterBar.vue +1 -0
- package/app/components/listing/ListingFilterDrawer.vue +1 -0
- package/app/components/listing/ListingFilterRail.vue +1 -0
- package/app/components/search/filter/SearchFacets.vue +10 -3
- package/app/components/search/filter/SearchFacetsBar.vue +7 -3
- package/app/components/search/filter/SearchFacetsDrawer.vue +7 -2
- package/app/components/ui/forms/SearchInput.vue +4 -1
- package/app/composables/useFacetMeta.ts +6 -6
- package/app/composables/useProductListing.ts +18 -2
- package/app/composables/useSearchListing.ts +16 -0
- package/app/shared/locale.ts +114 -0
- package/nuxt.config.ts +22 -0
- package/package.json +1 -1
- package/server/api/account/quotes/[id]/order.post.ts +14 -3
- package/server/api/cart/calculate.post.ts +4 -0
- package/server/api/categories/[slug]/subcategories.get.ts +34 -31
- package/server/api/orders/index.post.ts +78 -31
- package/server/api/payment/psp-config.get.ts +11 -21
- package/server/api/quotes/request.post.ts +2 -2
- package/server/api/typesense/search.post.ts +61 -317
- package/server/api/typesense/suggest.post.ts +14 -9
- package/server/{api/typesense/drop.get.ts → dev/typesense/drop.ts} +2 -1
- package/server/{api/typesense/health.get.ts → dev/typesense/health.ts} +1 -0
- package/server/dev/typesense/seed.ts +59 -0
- package/server/dev/typesense/seedDocuments.ts +105 -0
- package/server/routes/punchout/start.get.ts +40 -3
- package/server/services/ApiBrandService.ts +28 -42
- package/server/services/ApiProductService.ts +10 -11
- package/server/utils/buyerIdentity.ts +11 -0
- package/server/utils/liveCatalog.ts +132 -49
- package/server/utils/liveListingSearch.ts +201 -0
- package/server/utils/livePrices.ts +24 -9
- package/server/utils/orderLinePrices.ts +72 -0
- package/server/utils/paymentFee.ts +59 -0
- package/server/utils/pspConfig.ts +42 -0
- package/server/utils/revenexxSdk.ts +25 -2
- package/server/utils/searchClient.ts +305 -0
- package/server/utils/searchMultiSearchFallback.ts +216 -0
- package/server/api/typesense/seed.get.ts +0 -111
|
@@ -16,7 +16,7 @@ const props = defineProps<{
|
|
|
16
16
|
}>();
|
|
17
17
|
|
|
18
18
|
const { icon } = useIcons();
|
|
19
|
-
const { t } = useI18n();
|
|
19
|
+
const { locale, t } = useI18n();
|
|
20
20
|
const toast = useToast();
|
|
21
21
|
const cart = useCartStore();
|
|
22
22
|
|
|
@@ -33,6 +33,7 @@ const { data } = useFetch<{ products: ProductList[] }>(searchApi.search(), {
|
|
|
33
33
|
key: `cart-cross-sell:${props.popular ? "popular" : "category"}`,
|
|
34
34
|
method: "POST",
|
|
35
35
|
body: requestBody,
|
|
36
|
+
headers: computed(() => ({ "x-locale": locale.value })),
|
|
36
37
|
server: false,
|
|
37
38
|
lazy: true,
|
|
38
39
|
default: () => ({ products: [] }),
|
|
@@ -55,6 +55,7 @@ const listing = props.listing;
|
|
|
55
55
|
v-model="listing.activeFilters.value"
|
|
56
56
|
v-model:price-range="listing.priceRange.value"
|
|
57
57
|
:facets="listing.facets.value"
|
|
58
|
+
:show-price="listing.priceFilter.value"
|
|
58
59
|
/>
|
|
59
60
|
</div>
|
|
60
61
|
<div class="border-t border-(--ui-border) p-4">
|
|
@@ -7,11 +7,15 @@ import type { PriceRange, SearchFacet } from "../../../interfaces/search-facets"
|
|
|
7
7
|
* shared facet logic (toggling, labels, debounced price) lives in
|
|
8
8
|
* useFacetFilters; this component owns the vertical accordion presentation.
|
|
9
9
|
*/
|
|
10
|
-
const props = defineProps<{
|
|
10
|
+
const props = withDefaults(defineProps<{
|
|
11
11
|
facets: SearchFacet[];
|
|
12
12
|
modelValue: Record<string, string[]>;
|
|
13
13
|
priceRange: PriceRange;
|
|
14
|
-
|
|
14
|
+
/** Offer the price range — off where the index carries no price. */
|
|
15
|
+
showPrice?: boolean;
|
|
16
|
+
}>(), {
|
|
17
|
+
showPrice: true,
|
|
18
|
+
});
|
|
15
19
|
|
|
16
20
|
const emit = defineEmits<{
|
|
17
21
|
"update:modelValue": [value: Record<string, string[]>];
|
|
@@ -108,7 +112,10 @@ function toggleGroup(field: string): void {
|
|
|
108
112
|
</section>
|
|
109
113
|
|
|
110
114
|
<!-- Price range -->
|
|
111
|
-
<section
|
|
115
|
+
<section
|
|
116
|
+
v-if="showPrice"
|
|
117
|
+
class="py-1"
|
|
118
|
+
>
|
|
112
119
|
<button
|
|
113
120
|
type="button"
|
|
114
121
|
tabindex="0"
|
|
@@ -7,11 +7,15 @@ import type { PriceRange, SearchFacet } from "../../../interfaces/search-facets"
|
|
|
7
7
|
* logic with the vertical SearchFacets via useFacetFilters; only the popover
|
|
8
8
|
* presentation differs.
|
|
9
9
|
*/
|
|
10
|
-
const props = defineProps<{
|
|
10
|
+
const props = withDefaults(defineProps<{
|
|
11
11
|
facets: SearchFacet[];
|
|
12
12
|
modelValue: Record<string, string[]>;
|
|
13
13
|
priceRange: PriceRange;
|
|
14
|
-
|
|
14
|
+
/** Offer the price range — off where the index carries no price. */
|
|
15
|
+
showPrice?: boolean;
|
|
16
|
+
}>(), {
|
|
17
|
+
showPrice: true,
|
|
18
|
+
});
|
|
15
19
|
|
|
16
20
|
const emit = defineEmits<{
|
|
17
21
|
"update:modelValue": [value: Record<string, string[]>];
|
|
@@ -94,7 +98,7 @@ const {
|
|
|
94
98
|
</UPopover>
|
|
95
99
|
|
|
96
100
|
<!-- Price -->
|
|
97
|
-
<UPopover>
|
|
101
|
+
<UPopover v-if="showPrice">
|
|
98
102
|
<UButton
|
|
99
103
|
color="neutral"
|
|
100
104
|
variant="outline"
|
|
@@ -3,11 +3,15 @@ import type { PriceRange, SearchFacet } from "../../../interfaces/search-facets"
|
|
|
3
3
|
|
|
4
4
|
const { icon } = useIcons();
|
|
5
5
|
|
|
6
|
-
const props = defineProps<{
|
|
6
|
+
const props = withDefaults(defineProps<{
|
|
7
7
|
facets: SearchFacet[];
|
|
8
8
|
modelValue: Record<string, string[]>;
|
|
9
9
|
priceRange: PriceRange;
|
|
10
|
-
|
|
10
|
+
/** Offer the price range — off where the index carries no price. */
|
|
11
|
+
showPrice?: boolean;
|
|
12
|
+
}>(), {
|
|
13
|
+
showPrice: true,
|
|
14
|
+
});
|
|
11
15
|
|
|
12
16
|
const emit = defineEmits<{
|
|
13
17
|
"update:modelValue": [value: Record<string, string[]>];
|
|
@@ -50,6 +54,7 @@ const priceRangeProxy = computed({
|
|
|
50
54
|
v-model="filtersProxy"
|
|
51
55
|
v-model:price-range="priceRangeProxy"
|
|
52
56
|
:facets="facets"
|
|
57
|
+
:show-price="showPrice"
|
|
53
58
|
/>
|
|
54
59
|
</div>
|
|
55
60
|
</template>
|
|
@@ -24,7 +24,7 @@ const props = withDefaults(defineProps<{
|
|
|
24
24
|
placeholder: undefined,
|
|
25
25
|
});
|
|
26
26
|
|
|
27
|
-
const { t } = useI18n();
|
|
27
|
+
const { locale, t } = useI18n();
|
|
28
28
|
|
|
29
29
|
const placeholder = computed(() => props.placeholder || t("search.input.placeholder"));
|
|
30
30
|
|
|
@@ -85,6 +85,9 @@ async function fetchSuggestions(q: string): Promise<void> {
|
|
|
85
85
|
const data = await $fetch<{ suggestions: Suggestion[] }>(searchApi.suggest(), {
|
|
86
86
|
method: "POST",
|
|
87
87
|
body: { q },
|
|
88
|
+
// The BFF filters the index by locale; without it, it guesses from the
|
|
89
|
+
// cookie or Accept-Language and may suggest the other language.
|
|
90
|
+
headers: { "x-locale": locale.value },
|
|
88
91
|
}).catch(() => ({ suggestions: [] }));
|
|
89
92
|
suggestions.value = data.suggestions;
|
|
90
93
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { productsApi } from "../api/products";
|
|
2
|
+
import { pickLocalizedLabel } from "../shared/locale";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Per-tenant Typesense facet metadata — the subset of product
|
|
@@ -52,13 +53,14 @@ export function useFacetMeta() {
|
|
|
52
53
|
|
|
53
54
|
/**
|
|
54
55
|
* Resolve a localized label for a facet whose Typesense field name
|
|
55
|
-
* is `attrs.<code>`.
|
|
56
|
-
*
|
|
56
|
+
* is `attrs.<code>`. Same chain the BFF uses for every catalogue label
|
|
57
|
+
* (requested → de → en, `de` and `de-DE` keys alike), then the raw code
|
|
58
|
+
* so the UI never renders an empty header.
|
|
57
59
|
*/
|
|
58
60
|
function label(code: string): string {
|
|
59
61
|
const entry = byCode.value.get(code);
|
|
60
62
|
if (!entry) return code;
|
|
61
|
-
return entry.labels
|
|
63
|
+
return pickLocalizedLabel(entry.labels, locale.value, code);
|
|
62
64
|
}
|
|
63
65
|
|
|
64
66
|
/**
|
|
@@ -71,9 +73,7 @@ export function useFacetMeta() {
|
|
|
71
73
|
function valueLabel(code: string, value: string): string {
|
|
72
74
|
const entry = byCode.value.get(code);
|
|
73
75
|
if (!entry) return value;
|
|
74
|
-
|
|
75
|
-
if (!optionLabels) return value;
|
|
76
|
-
return optionLabels[locale.value] ?? optionLabels.en ?? value;
|
|
76
|
+
return pickLocalizedLabel(entry.options[value], locale.value, value);
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
return { codes, byCode, label, valueLabel, status, error };
|
|
@@ -52,6 +52,13 @@ export interface ListingResponse {
|
|
|
52
52
|
found: number;
|
|
53
53
|
page: number;
|
|
54
54
|
perPage: number;
|
|
55
|
+
/**
|
|
56
|
+
* Whether a price range filters anything on this index. Absent means yes
|
|
57
|
+
* (older BFFs); the live index answers false when it carries no price.
|
|
58
|
+
*/
|
|
59
|
+
priceFilter?: boolean;
|
|
60
|
+
/** Where curation sends this search instead of showing results. */
|
|
61
|
+
redirect?: string;
|
|
55
62
|
}
|
|
56
63
|
|
|
57
64
|
/**
|
|
@@ -289,9 +296,18 @@ export function useProductListing(options: ProductListingOptions) {
|
|
|
289
296
|
.filter((f): f is SearchFacet => Boolean(f && f.counts.length > 0));
|
|
290
297
|
});
|
|
291
298
|
|
|
299
|
+
/**
|
|
300
|
+
* Whether the price filter is offered. The live index may carry no price
|
|
301
|
+
* field; a filter that does nothing is not shown at all.
|
|
302
|
+
*/
|
|
303
|
+
const priceFilter = computed(() => data.value?.priceFilter !== false);
|
|
304
|
+
|
|
305
|
+
/** A curated redirect for this query (search view only), or undefined. */
|
|
306
|
+
const redirect = computed(() => data.value?.redirect || undefined);
|
|
307
|
+
|
|
292
308
|
const activeFilterCount = computed(() =>
|
|
293
309
|
Object.values(activeFilters.value).reduce((sum, values) => sum + values.length, 0)
|
|
294
|
-
+ (priceRange.value.min !== undefined || priceRange.value.max !== undefined ? 1 : 0),
|
|
310
|
+
+ (priceFilter.value && (priceRange.value.min !== undefined || priceRange.value.max !== undefined) ? 1 : 0),
|
|
295
311
|
);
|
|
296
312
|
|
|
297
313
|
const chips = computed(() => {
|
|
@@ -326,7 +342,7 @@ export function useProductListing(options: ProductListingOptions) {
|
|
|
326
342
|
})));
|
|
327
343
|
|
|
328
344
|
return {
|
|
329
|
-
query, sort, sortOptions, page, activeFilters, priceRange,
|
|
345
|
+
query, sort, sortOptions, page, activeFilters, priceRange, priceFilter, redirect,
|
|
330
346
|
data, pending, error, execute,
|
|
331
347
|
products, facets, found, totalPages, isEmpty,
|
|
332
348
|
chips, activeFilterCount, removeChip, clearFilters,
|
|
@@ -63,6 +63,20 @@ export const useSearchListing = (options: SearchListingOptions) => {
|
|
|
63
63
|
listEvent: () => ({ event: "search", listId: "search", term: query.value }),
|
|
64
64
|
});
|
|
65
65
|
|
|
66
|
+
// Curation can send a query somewhere else (a category, a landing page):
|
|
67
|
+
// the search answers with a redirect action instead of results to show.
|
|
68
|
+
// Followed on the client and only for a term the visitor actually searched
|
|
69
|
+
// (`?q`), so the editor canvas, which renders an authored sample, stays put.
|
|
70
|
+
// `replace` keeps the back button from bouncing straight back here.
|
|
71
|
+
const redirecting = computed(() => routeQuery.value !== undefined && Boolean(listing.redirect.value));
|
|
72
|
+
if (import.meta.client) {
|
|
73
|
+
watch(() => (routeQuery.value !== undefined ? listing.redirect.value : undefined), (target) => {
|
|
74
|
+
if (target) {
|
|
75
|
+
void navigateTo(target, { replace: true, external: /^https?:\/\//i.test(target) });
|
|
76
|
+
}
|
|
77
|
+
}, { immediate: true });
|
|
78
|
+
}
|
|
79
|
+
|
|
66
80
|
// `?q=*` is the match-all link (Typesense's native catch-all query): the
|
|
67
81
|
// full catalog, presented as such instead of as results for a "*" term.
|
|
68
82
|
const isCatalog = computed(() => query.value.trim() === "*");
|
|
@@ -93,6 +107,8 @@ export const useSearchListing = (options: SearchListingOptions) => {
|
|
|
93
107
|
category, subcategory, categorySlug, subcategorySlug,
|
|
94
108
|
title, breadcrumb,
|
|
95
109
|
q, searchInput, pushQuery,
|
|
110
|
+
/** True while the search is being sent to a curated redirect target. */
|
|
111
|
+
redirecting,
|
|
96
112
|
};
|
|
97
113
|
};
|
|
98
114
|
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Locale codes as the catalogue speaks them, next to the language the
|
|
3
|
+
* storefront speaks.
|
|
4
|
+
*
|
|
5
|
+
* The UI works in a bare language (`de`, `en`: the URL prefix, the i18n
|
|
6
|
+
* files). The catalogue does not agree with itself: search documents carry
|
|
7
|
+
* `locale: "de"` today and `locale: "de-DE"` after the full-code migration,
|
|
8
|
+
* and label maps from different PIMs are keyed either way. Everything here
|
|
9
|
+
* accepts both forms in both directions and prefers the full code, so the
|
|
10
|
+
* shop works before, during and after that migration.
|
|
11
|
+
*
|
|
12
|
+
* Pure functions, shared by the BFF (search filters, label picking) and the
|
|
13
|
+
* client (facet labels), so both resolve a label the same way.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/** The region a bare UI language stands for when a full code is needed. */
|
|
17
|
+
export const DEFAULT_LOCALE_REGIONS: Readonly<Record<string, string>> = {
|
|
18
|
+
de: "DE",
|
|
19
|
+
en: "US",
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/** Languages a label falls back to, in order, after the requested one. */
|
|
23
|
+
export const LABEL_FALLBACK_LANGUAGES = ["de", "en"] as const;
|
|
24
|
+
|
|
25
|
+
/** `de_de` / `DE-de` / ` de-DE ` → `de-DE`; `DE` → `de`. */
|
|
26
|
+
export function normalizeLocaleCode(code: string): string {
|
|
27
|
+
const [language = "", region, ...rest] = code.trim().replace(/_/g, "-").split("-");
|
|
28
|
+
if (!region) {
|
|
29
|
+
return language.toLowerCase();
|
|
30
|
+
}
|
|
31
|
+
return [language.toLowerCase(), region.length === 2 ? region.toUpperCase() : region, ...rest].join("-");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The language subtag: `de-DE` → `de`, `de` → `de`. */
|
|
35
|
+
export function localeLanguage(code: string): string {
|
|
36
|
+
return normalizeLocaleCode(code).split("-")[0] ?? "";
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The full BCP-47 code for a locale: a full code is kept as it is, a bare
|
|
41
|
+
* language gets its default region (`de` → `de-DE`, `en` → `en-US`). A
|
|
42
|
+
* language without a known region stays bare.
|
|
43
|
+
*/
|
|
44
|
+
export function fullLocaleCode(code: string): string {
|
|
45
|
+
const normalized = normalizeLocaleCode(code);
|
|
46
|
+
if (normalized.includes("-")) {
|
|
47
|
+
return normalized;
|
|
48
|
+
}
|
|
49
|
+
const region = DEFAULT_LOCALE_REGIONS[normalized];
|
|
50
|
+
return region ? `${normalized}-${region}` : normalized;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The locale values a catalogue document may carry for this locale, most
|
|
55
|
+
* preferred first: the full code, then the bare language.
|
|
56
|
+
* `de` → `["de-DE", "de"]`, `de-AT` → `["de-AT", "de"]`.
|
|
57
|
+
*/
|
|
58
|
+
export function searchLocaleKeys(code: string): string[] {
|
|
59
|
+
const language = localeLanguage(code);
|
|
60
|
+
if (!language) {
|
|
61
|
+
return [];
|
|
62
|
+
}
|
|
63
|
+
const full = fullLocaleCode(code);
|
|
64
|
+
return full === language ? [language] : [full, language];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* A label map's value for one locale, whichever form its keys take.
|
|
69
|
+
*
|
|
70
|
+
* Tried in order: the locale's full code, its bare language, then any other
|
|
71
|
+
* region of the same language (in sorted key order, so a map carrying
|
|
72
|
+
* `de-AT` and `de-CH` always answers the same way). Keys are compared
|
|
73
|
+
* normalised (`de_DE`, `DE-de`). An empty string counts as no label: it
|
|
74
|
+
* renders as a blank name, which is worse than the fallback.
|
|
75
|
+
*/
|
|
76
|
+
export function labelForLocale(labels: Record<string, string>, locale: string): string | undefined {
|
|
77
|
+
const present = Object.keys(labels)
|
|
78
|
+
.filter(key => labels[key])
|
|
79
|
+
.sort()
|
|
80
|
+
.map(key => ({ key, code: normalizeLocaleCode(key) }));
|
|
81
|
+
|
|
82
|
+
for (const wanted of searchLocaleKeys(locale)) {
|
|
83
|
+
const hit = present.find(entry => entry.code === wanted);
|
|
84
|
+
if (hit) {
|
|
85
|
+
return labels[hit.key];
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const language = localeLanguage(locale);
|
|
90
|
+
const sameLanguage = present.find(entry => entry.code.split("-")[0] === language);
|
|
91
|
+
return sameLanguage ? labels[sameLanguage.key] : undefined;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Localised label with the catalogue's fallback chain: the requested locale,
|
|
96
|
+
* then German, then English, then `fallback` (usually the technical code).
|
|
97
|
+
* Every step matches full and short codes in both directions.
|
|
98
|
+
*/
|
|
99
|
+
export function pickLocalizedLabel(
|
|
100
|
+
labels: Record<string, string> | null | undefined,
|
|
101
|
+
locale: string,
|
|
102
|
+
fallback: string,
|
|
103
|
+
): string {
|
|
104
|
+
if (!labels) {
|
|
105
|
+
return fallback;
|
|
106
|
+
}
|
|
107
|
+
for (const candidate of [locale, ...LABEL_FALLBACK_LANGUAGES]) {
|
|
108
|
+
const label = labelForLocale(labels, candidate);
|
|
109
|
+
if (label) {
|
|
110
|
+
return label;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return fallback;
|
|
114
|
+
}
|
package/nuxt.config.ts
CHANGED
|
@@ -176,6 +176,28 @@ export default defineNuxtConfig({
|
|
|
176
176
|
},
|
|
177
177
|
|
|
178
178
|
hooks: {
|
|
179
|
+
/**
|
|
180
|
+
* Local Typesense maintenance (seed/drop/health), dev server only.
|
|
181
|
+
*
|
|
182
|
+
* They act on the local demo index without any auth, so they must not
|
|
183
|
+
* exist in a build: they live outside server/api and are only
|
|
184
|
+
* registered here when Nuxt runs in dev. A production build seeds via
|
|
185
|
+
* `pnpm typesense:seed` (scripts/seed-typesense.mjs) instead.
|
|
186
|
+
*/
|
|
187
|
+
"nitro:config": (nitroConfig) => {
|
|
188
|
+
if (!useNuxt().options.dev) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
nitroConfig.handlers = [
|
|
192
|
+
...(nitroConfig.handlers ?? []),
|
|
193
|
+
...["seed", "drop", "health"].map(name => ({
|
|
194
|
+
route: `/api/typesense/${name}`,
|
|
195
|
+
method: "get" as const,
|
|
196
|
+
handler: resolve(currentDir, `server/dev/typesense/${name}.ts`),
|
|
197
|
+
})),
|
|
198
|
+
];
|
|
199
|
+
},
|
|
200
|
+
|
|
179
201
|
/**
|
|
180
202
|
* Hand the consuming app's i18n routing strategy to the server.
|
|
181
203
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@revenexx/cover",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
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",
|
|
@@ -96,8 +96,16 @@ export default defineEventHandler(async (event): Promise<QuoteOrderResult> => {
|
|
|
96
96
|
let placed: { id: string; number: string; grand_total?: number };
|
|
97
97
|
try {
|
|
98
98
|
placed = await sdk.orders.ordersPlace({
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
// A buyer's call is placed for the buyer the principal names, and the
|
|
100
|
+
// orders app refuses a body that names anybody else (RAD-174) — a
|
|
101
|
+
// colleague's quote included, where the draft carries the colleague.
|
|
102
|
+
// Only a call acting for nobody states who the order is for.
|
|
103
|
+
...(principalContactId(event)
|
|
104
|
+
? {}
|
|
105
|
+
: {
|
|
106
|
+
contactId: draft.contact_id ?? actor.contactId,
|
|
107
|
+
organizationId: draft.organization_id ?? actor.organizationId,
|
|
108
|
+
}),
|
|
101
109
|
currency: draft.currency,
|
|
102
110
|
...(body?.customerOrderNumber?.trim() ? { customerOrderNumber: body.customerOrderNumber.trim() } : {}),
|
|
103
111
|
buyer: (draft.buyer ?? { name: actor.user.name, email: actor.user.email }) as object,
|
|
@@ -135,6 +143,7 @@ export default defineEventHandler(async (event): Promise<QuoteOrderResult> => {
|
|
|
135
143
|
}
|
|
136
144
|
|
|
137
145
|
if (resolvePaymentServiceKey(event) === "api") {
|
|
146
|
+
const payerContactId = principalContactId(event);
|
|
138
147
|
try {
|
|
139
148
|
const payment = await sdk.call<{ id: string; status: string }>("POST", "/v1/payments", {
|
|
140
149
|
body: {
|
|
@@ -143,6 +152,8 @@ export default defineEventHandler(async (event): Promise<QuoteOrderResult> => {
|
|
|
143
152
|
currency: draft.currency,
|
|
144
153
|
country: toIsoCountry(draft.billing_address?.country ?? draft.shipping_address?.country),
|
|
145
154
|
order_ref: placed.number,
|
|
155
|
+
// The buyer's own payment, listed on their payments page (RAD-171).
|
|
156
|
+
...(payerContactId ? { contact_id: payerContactId } : {}),
|
|
146
157
|
idempotency_key: `quote-${quote.id}-${placed.id}`,
|
|
147
158
|
metadata: { quote_number: quote.number },
|
|
148
159
|
},
|
|
@@ -150,7 +161,7 @@ export default defineEventHandler(async (event): Promise<QuoteOrderResult> => {
|
|
|
150
161
|
const mapped = ["captured", "succeeded", "paid"].includes(payment.status)
|
|
151
162
|
? OrderPaymentStatus.Paid
|
|
152
163
|
: payment.status === "authorized" ? OrderPaymentStatus.Authorized : OrderPaymentStatus.Pending;
|
|
153
|
-
await
|
|
164
|
+
await useTenantSdk().orders.ordersPaymentStatusUpdate({ id: placed.id, status: mapped });
|
|
154
165
|
}
|
|
155
166
|
catch (err) {
|
|
156
167
|
// An invoice order stands without a captured payment; the payment
|
|
@@ -37,6 +37,10 @@ async function resolveOverrides(
|
|
|
37
37
|
sku: it.sku ? String(it.sku) : undefined,
|
|
38
38
|
quantity: Number(it.quantity) || 1,
|
|
39
39
|
})) as Models.PriceResolveItem[],
|
|
40
|
+
// The signed-in buyer's own prices — contract and organization
|
|
41
|
+
// lists included — not the anonymous ones (RAD-170). The same
|
|
42
|
+
// scope the order is priced under.
|
|
43
|
+
...priceBuyerContext(event),
|
|
40
44
|
...(currency ? { currency } : {}),
|
|
41
45
|
}) as unknown as { prices: Array<{ product_id: string | null; sku: string | null; tax_rate: number | null; on_request: boolean; unit_price: number | null }> };
|
|
42
46
|
const itemTaxRates: Record<string, number> = {};
|
|
@@ -7,8 +7,6 @@ import {
|
|
|
7
7
|
liveSubcategoryIndex,
|
|
8
8
|
mapLiveDocToProduct,
|
|
9
9
|
rollUpSubcategoryCounts,
|
|
10
|
-
searchLiveProducts,
|
|
11
|
-
searchLiveProductsMulti,
|
|
12
10
|
tsFilterValue,
|
|
13
11
|
} from "../../../utils/liveCatalog";
|
|
14
12
|
import { PRODUCTS_COLLECTION } from "../../../utils/productsSchema";
|
|
@@ -38,11 +36,15 @@ import { PRODUCTS_COLLECTION } from "../../../utils/productsSchema";
|
|
|
38
36
|
const MAX_SUBCATEGORY_VALUES = 250;
|
|
39
37
|
|
|
40
38
|
/**
|
|
41
|
-
* Sub-searches per multi_search request. Typesense's
|
|
42
|
-
* defaults to 50; staying under it keeps a category with
|
|
39
|
+
* Sub-searches per multi_search request against the mock index. Typesense's
|
|
40
|
+
* `limit_multi_searches` defaults to 50; staying under it keeps a category with
|
|
41
|
+
* many children working.
|
|
43
42
|
*/
|
|
44
43
|
const SEARCH_BATCH_SIZE = 40;
|
|
45
44
|
|
|
45
|
+
/** Live image lookups in flight at once — one search per child. */
|
|
46
|
+
const LIVE_IMAGE_CONCURRENCY = 8;
|
|
47
|
+
|
|
46
48
|
/** Narrowed shape of the mock index's multi_search response. */
|
|
47
49
|
interface MockMultiSearchResponse {
|
|
48
50
|
results?: {
|
|
@@ -78,19 +80,10 @@ function toTiles(
|
|
|
78
80
|
// products are spread over every code beneath it.
|
|
79
81
|
// ---------------------------------------------------------------------------
|
|
80
82
|
|
|
81
|
-
/** `locale:=… && enabled:=true && categories:=[…]`, the live catalogue's baseline. */
|
|
82
|
-
function liveFilter(locale: Locale, codes: readonly string[]): string {
|
|
83
|
-
return [
|
|
84
|
-
`locale:=${tsFilterValue(locale)}`,
|
|
85
|
-
"enabled:=true",
|
|
86
|
-
`categories:=[${codes.map(tsFilterValue).join(",")}]`,
|
|
87
|
-
].join(" && ");
|
|
88
|
-
}
|
|
89
|
-
|
|
90
83
|
/**
|
|
91
|
-
* Product counts per direct child
|
|
92
|
-
*
|
|
93
|
-
*
|
|
84
|
+
* Product counts per direct child, from the search service's `category` view —
|
|
85
|
+
* the view the category page's listing asks, so the cards and the filter rail
|
|
86
|
+
* can never disagree. The service pins locale and enabled products.
|
|
94
87
|
*/
|
|
95
88
|
async function liveCounts(categorySlug: string, locale: Locale): Promise<Map<string, number>> {
|
|
96
89
|
const { branchOf } = await liveSubcategoryIndex(categorySlug, locale);
|
|
@@ -99,27 +92,27 @@ async function liveCounts(categorySlug: string, locale: Locale): Promise<Map<str
|
|
|
99
92
|
return new Map();
|
|
100
93
|
}
|
|
101
94
|
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
facetBy: "categories",
|
|
106
|
-
maxFacetValues: MAX_SUBCATEGORY_VALUES,
|
|
95
|
+
const result = await searchClient.search({
|
|
96
|
+
view: "category",
|
|
97
|
+
filters: { categories: leafCodes },
|
|
107
98
|
perPage: 1,
|
|
99
|
+
locale,
|
|
108
100
|
});
|
|
109
101
|
|
|
110
102
|
return rollUpSubcategoryCounts(
|
|
111
|
-
|
|
103
|
+
result.facets.find(facet => facet.field === "categories")?.counts ?? [],
|
|
112
104
|
branchOf,
|
|
113
105
|
);
|
|
114
106
|
}
|
|
115
107
|
|
|
116
108
|
/**
|
|
117
109
|
* One representative product image per direct child: a 1-hit search per child,
|
|
118
|
-
*
|
|
110
|
+
* a few at a time.
|
|
119
111
|
*
|
|
120
|
-
* Per child rather than one big page of hits, because a page is capped
|
|
121
|
-
*
|
|
122
|
-
*
|
|
112
|
+
* Per child rather than one big page of hits, because a page is capped and a
|
|
113
|
+
* category with thousands of products would leave most children imageless —
|
|
114
|
+
* which is exactly how this looked when it was broken. A child whose lookup
|
|
115
|
+
* fails keeps its icon; the others keep their images.
|
|
123
116
|
*/
|
|
124
117
|
async function liveImages(categorySlug: string, locale: Locale): Promise<Map<string, string>> {
|
|
125
118
|
const { branchOf } = await liveSubcategoryIndex(categorySlug, locale);
|
|
@@ -136,15 +129,25 @@ async function liveImages(categorySlug: string, locale: Locale): Promise<Map<str
|
|
|
136
129
|
const children = [...leavesByChild.keys()];
|
|
137
130
|
const images = new Map<string, string>();
|
|
138
131
|
|
|
139
|
-
for (const batch of chunk(children,
|
|
140
|
-
const results = await
|
|
141
|
-
|
|
142
|
-
|
|
132
|
+
for (const batch of chunk(children, LIVE_IMAGE_CONCURRENCY)) {
|
|
133
|
+
const results = await Promise.allSettled(batch.map(child => searchClient.search({
|
|
134
|
+
view: "category",
|
|
135
|
+
filters: { categories: leavesByChild.get(child) ?? [child] },
|
|
143
136
|
perPage: 1,
|
|
137
|
+
locale,
|
|
144
138
|
})));
|
|
145
139
|
|
|
140
|
+
const failed = results.find((r): r is PromiseRejectedResult => r.status === "rejected");
|
|
141
|
+
if (failed) {
|
|
142
|
+
getLogService().warn(
|
|
143
|
+
"categories/subcategories: some preview image lookups failed",
|
|
144
|
+
{ slug: categorySlug, ...toErrorContext(failed.reason) },
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
146
148
|
batch.forEach((child, index) => {
|
|
147
|
-
const
|
|
149
|
+
const settled = results[index];
|
|
150
|
+
const doc = settled?.status === "fulfilled" ? settled.value.docs[0] : undefined;
|
|
148
151
|
if (doc) {
|
|
149
152
|
images.set(child, mapLiveDocToProduct(doc).image);
|
|
150
153
|
}
|