@revenexx/cover 0.2.19 → 0.2.20
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/app.config.ts +21 -0
- package/app/composables/useCategoryListing.ts +5 -3
- package/app/composables/useProduct.ts +23 -2
- package/app/composables/useProductListing.ts +54 -27
- package/app/composables/useSearchListing.ts +18 -5
- package/app/layouts/default.vue +2 -3
- package/i18n/locales/de/search.json +3 -1
- package/i18n/locales/en/search.json +3 -1
- package/package.json +1 -1
- package/server/api/typesense/search.post.ts +55 -6
- package/server/interfaces/log.ts +7 -0
- package/server/services/LogService.ts +9 -1
- package/server/data/media/60794300.jpg +0 -0
- package/server/data/media/aussen-rueckwaertsdrehen.jpg +0 -0
- package/server/data/media/bohrtiefe-8.jpg +0 -0
- package/server/data/media/dummy-brw-image.png +0 -0
- package/server/data/media/feindrehen.jpg +0 -0
- package/server/data/media/header-aktuelles.jpg +0 -0
- package/server/data/media/sternsiebeinsatz-gr-3-000028480.stp +0 -19039
- package/server/data/media/zaehnezahl-z4.jpg +0 -0
- package/server/data/media/zaehnezahl-z6.jpg +0 -0
package/app/app.config.ts
CHANGED
|
@@ -32,6 +32,27 @@ export default defineAppConfig({
|
|
|
32
32
|
// crashed SearchInput with "Cannot read … 'autocompleteMinChars'").
|
|
33
33
|
search: {
|
|
34
34
|
autocompleteMinChars: 2,
|
|
35
|
+
// Which sorts the listing toolbar offers. A storefront switches off
|
|
36
|
+
// what its catalogue cannot honour — offering a control that silently
|
|
37
|
+
// does nothing is worse than not offering it, and a live search index
|
|
38
|
+
// that projects no price field can never sort by price.
|
|
39
|
+
//
|
|
40
|
+
// A MAP and not a list on purpose: app.config is merged with defu,
|
|
41
|
+
// which CONCATENATES arrays. A storefront overriding a list would
|
|
42
|
+
// append to the layer's five rather than replace them, and every
|
|
43
|
+
// option would stay on. Booleans merge key by key, so
|
|
44
|
+
// `sorts: { price_asc: false }` in a storefront means exactly that.
|
|
45
|
+
//
|
|
46
|
+
// Display order follows this declaration, not the override.
|
|
47
|
+
sorts: {
|
|
48
|
+
relevance: true,
|
|
49
|
+
price_asc: true,
|
|
50
|
+
price_desc: true,
|
|
51
|
+
name_asc: true,
|
|
52
|
+
name_desc: true,
|
|
53
|
+
sku_asc: true,
|
|
54
|
+
sku_desc: true,
|
|
55
|
+
},
|
|
35
56
|
},
|
|
36
57
|
ui: {
|
|
37
58
|
icons: nuxtUiIcons(DEFAULT_ICON_WEIGHT),
|
|
@@ -52,10 +52,12 @@ export const useCategoryListing = (options: CategoryListingOptions) => {
|
|
|
52
52
|
...(subcategorySlug.value ? { subcategorySlug: [subcategorySlug.value] } : {}),
|
|
53
53
|
}),
|
|
54
54
|
// The category itself is fixed; subcategories remain filterable on the
|
|
55
|
-
// category root, manufacturers and availability everywhere.
|
|
56
|
-
|
|
55
|
+
// category root, manufacturers and availability everywhere. Passed as a
|
|
56
|
+
// getter so switching subcategory (route change or editor edit) updates
|
|
57
|
+
// the offered facets instead of freezing the first render's list.
|
|
58
|
+
facetFields: () => (subcategorySlug.value
|
|
57
59
|
? ["manufacturer", "available"]
|
|
58
|
-
: ["subcategory", "manufacturer", "available"],
|
|
60
|
+
: ["subcategory", "manufacturer", "available"]),
|
|
59
61
|
});
|
|
60
62
|
|
|
61
63
|
const title = computed(() =>
|
|
@@ -15,7 +15,11 @@ export const useProductDetail = (id: MaybeRefOrGetter<string>) => {
|
|
|
15
15
|
const currency = useDisplayCurrency();
|
|
16
16
|
const { locale: activeLocale } = useI18n();
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
// Kept as one object (rather than destructured straight away) so `ready()`
|
|
19
|
+
// below can await the AsyncData thenable — destructuring drops it, which is
|
|
20
|
+
// why a setup-time `error.value` check can never see a 404: SSR only awaits
|
|
21
|
+
// the request in onServerPrefetch, i.e. after setup has returned.
|
|
22
|
+
const detailRequest = useFetch<ProductDetail | null>(
|
|
19
23
|
() => productApi.detail(toValue(id)),
|
|
20
24
|
{
|
|
21
25
|
// The BFF resolves the locale from `x-locale` first. Without this
|
|
@@ -29,9 +33,17 @@ export const useProductDetail = (id: MaybeRefOrGetter<string>) => {
|
|
|
29
33
|
// until it resolves.
|
|
30
34
|
key: () => `product-detail:${toValue(id)}`,
|
|
31
35
|
default: () => null,
|
|
36
|
+
// Without this guard an empty id requests `/api/product/`, which the
|
|
37
|
+
// BFF answers 400. Callers that can produce an empty id (a malformed
|
|
38
|
+
// product URL) render a not-found state instead of fetching. Safe as a
|
|
39
|
+
// one-time evaluation: Nuxt keys pages by the interpolated path, so a
|
|
40
|
+
// route change remounts the page and re-evaluates this.
|
|
41
|
+
immediate: Boolean(toValue(id)),
|
|
32
42
|
},
|
|
33
43
|
);
|
|
34
44
|
|
|
45
|
+
const { data: detail, status, error, refresh } = detailRequest;
|
|
46
|
+
|
|
35
47
|
// Price + availability are the Offer domain — fetched on their own axis
|
|
36
48
|
// (heavyweight ERP call in production), never blocking the detail render.
|
|
37
49
|
const { loadOffers, useOffer } = useOffers();
|
|
@@ -103,8 +115,17 @@ export const useProductDetail = (id: MaybeRefOrGetter<string>) => {
|
|
|
103
115
|
return imagesApi.detail(filename);
|
|
104
116
|
};
|
|
105
117
|
|
|
118
|
+
/**
|
|
119
|
+
* Resolves once the initial detail request has settled — for pages that own
|
|
120
|
+
* the HTTP status and SEO tags and must know whether the product exists
|
|
121
|
+
* before they render. Never await this inside a block.
|
|
122
|
+
*/
|
|
123
|
+
const ready = async (): Promise<void> => {
|
|
124
|
+
await detailRequest;
|
|
125
|
+
};
|
|
126
|
+
|
|
106
127
|
return {
|
|
107
|
-
detail, status, error, refresh,
|
|
128
|
+
detail, status, error, refresh, ready,
|
|
108
129
|
productInfo, mainImages, longDescription,
|
|
109
130
|
stocks, attributes, prices, taxRate, offerPending,
|
|
110
131
|
productCategories, categorySlug, subcategorySlug,
|
|
@@ -13,13 +13,24 @@ export interface ProductListingOptions {
|
|
|
13
13
|
*/
|
|
14
14
|
fixedFilters?: () => Record<string, string[]>;
|
|
15
15
|
/** Facet fields offered to the user, in display order. */
|
|
16
|
-
facetFields?: string[]
|
|
16
|
+
facetFields?: MaybeRefOrGetter<string[]>;
|
|
17
17
|
/** Run the first request even with an empty query (category pages). */
|
|
18
18
|
allowEmptyQuery?: boolean;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
const DEFAULT_FACETS = ["category", "subcategory", "manufacturer", "available"];
|
|
22
22
|
|
|
23
|
+
/** Every sort the layer knows, and the i18n key that names it. */
|
|
24
|
+
const SORT_LABEL_KEYS = {
|
|
25
|
+
relevance: "search.sort.relevance",
|
|
26
|
+
price_asc: "search.sort.priceAsc",
|
|
27
|
+
price_desc: "search.sort.priceDesc",
|
|
28
|
+
name_asc: "search.sort.nameAsc",
|
|
29
|
+
name_desc: "search.sort.nameDesc",
|
|
30
|
+
sku_asc: "search.sort.skuAsc",
|
|
31
|
+
sku_desc: "search.sort.skuDesc",
|
|
32
|
+
} as const;
|
|
33
|
+
|
|
23
34
|
export interface ListingResponse {
|
|
24
35
|
products: ProductList[];
|
|
25
36
|
facets: SearchFacet[];
|
|
@@ -43,10 +54,10 @@ export function useProductListing(options: ProductListingOptions) {
|
|
|
43
54
|
// per-tenant `attrs.<code>` facets from the Products app's
|
|
44
55
|
// `is_filterable` flags. The dynamic side reacts to the SSR-loaded
|
|
45
56
|
// useFacetMeta payload — first render already includes them.
|
|
46
|
-
const staticFacets = options.facetFields ?? DEFAULT_FACETS;
|
|
57
|
+
const staticFacets = computed(() => toValue(options.facetFields) ?? DEFAULT_FACETS);
|
|
47
58
|
const facetMeta = useFacetMeta();
|
|
48
59
|
const facetFields = computed(() => [
|
|
49
|
-
...staticFacets,
|
|
60
|
+
...staticFacets.value,
|
|
50
61
|
...facetMeta.codes.value.map(c => `attrs.${c}`),
|
|
51
62
|
]);
|
|
52
63
|
const query = computed(() => options.query?.() ?? "");
|
|
@@ -74,8 +85,30 @@ export function useProductListing(options: ProductListingOptions) {
|
|
|
74
85
|
void router.replace({ query: next });
|
|
75
86
|
}
|
|
76
87
|
|
|
88
|
+
// Which sorts this storefront offers (app.config `search.sortOptions`),
|
|
89
|
+
// in the configured order. Falls back to the full set so a storefront that
|
|
90
|
+
// configures nothing behaves as before.
|
|
91
|
+
const appConfig = useAppConfig();
|
|
92
|
+
const enabledSorts = computed<string[]>(() => {
|
|
93
|
+
const configured = appConfig.search?.sorts as Record<string, boolean> | undefined;
|
|
94
|
+
// Declaration order of SORT_LABEL_KEYS decides display order; the
|
|
95
|
+
// config only decides membership. An unset key stays enabled, so a
|
|
96
|
+
// storefront that configures nothing behaves exactly as before.
|
|
97
|
+
const enabled = Object.keys(SORT_LABEL_KEYS)
|
|
98
|
+
.filter(value => configured?.[value] !== false);
|
|
99
|
+
return enabled.length > 0 ? enabled : ["relevance"];
|
|
100
|
+
});
|
|
101
|
+
|
|
77
102
|
const sort = computed({
|
|
78
|
-
|
|
103
|
+
// A disabled sort must not be reachable by hand-editing the URL — it
|
|
104
|
+
// would apply a sort the toolbar cannot show, and on a live index it
|
|
105
|
+
// could ask Typesense for a field that is not there.
|
|
106
|
+
get: () => {
|
|
107
|
+
const requested = (route.query.sort as string) ?? "relevance";
|
|
108
|
+
return enabledSorts.value.includes(requested)
|
|
109
|
+
? requested
|
|
110
|
+
: (enabledSorts.value[0] ?? "relevance");
|
|
111
|
+
},
|
|
79
112
|
set: (value: string) => updateUrl({ sort: value === "relevance" ? null : value }),
|
|
80
113
|
});
|
|
81
114
|
|
|
@@ -139,23 +172,20 @@ export function useProductListing(options: ProductListingOptions) {
|
|
|
139
172
|
// index by locale, and without this header it uses the browser's
|
|
140
173
|
// Accept-Language instead of the locale the visitor selected.
|
|
141
174
|
headers: computed(() => ({ "x-locale": locale.value })),
|
|
142
|
-
immediate
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
void execute();
|
|
156
|
-
}
|
|
175
|
+
// `immediate` is what registers Nuxt's onServerPrefetch, so it must be
|
|
176
|
+
// truthy for the first request to be AWAITED during SSR — with
|
|
177
|
+
// `immediate: false` the listing markup server-rendered empty and the
|
|
178
|
+
// in-flight fetch raced into payload.data (a hydration mismatch).
|
|
179
|
+
// An empty query has nothing to render, so it legitimately stays false;
|
|
180
|
+
// the watcher below still picks it up once a query arrives.
|
|
181
|
+
immediate: hasQuery.value,
|
|
182
|
+
// SSR awaits the request; on the client the fetch moves to onBeforeMount
|
|
183
|
+
// so a route change doesn't block navigation on the listing.
|
|
184
|
+
lazy: true,
|
|
185
|
+
// No explicit `watch`: Nuxt's default watches the reactive request
|
|
186
|
+
// options, and every URL-derived input (query, facets, price, sort,
|
|
187
|
+
// page) flows through `requestBody`.
|
|
157
188
|
},
|
|
158
|
-
{ deep: true },
|
|
159
189
|
);
|
|
160
190
|
|
|
161
191
|
/* ---- derived view state -------------------------------------------- */
|
|
@@ -213,13 +243,10 @@ export function useProductListing(options: ProductListingOptions) {
|
|
|
213
243
|
updateUrl(updates);
|
|
214
244
|
}
|
|
215
245
|
|
|
216
|
-
const sortOptions = computed(() =>
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
{ value: "name_asc", label: t("search.sort.nameAsc") },
|
|
221
|
-
{ value: "name_desc", label: t("search.sort.nameDesc") },
|
|
222
|
-
]);
|
|
246
|
+
const sortOptions = computed(() => enabledSorts.value.map(value => ({
|
|
247
|
+
value,
|
|
248
|
+
label: t(SORT_LABEL_KEYS[value as keyof typeof SORT_LABEL_KEYS]),
|
|
249
|
+
})));
|
|
223
250
|
|
|
224
251
|
return {
|
|
225
252
|
query, sort, sortOptions, page, activeFilters, priceRange,
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { useDebounceFn } from "@vueuse/core";
|
|
2
2
|
|
|
3
3
|
export interface SearchListingOptions {
|
|
4
|
-
/**
|
|
5
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Fallback search value, used only when the URL carries no `?q` — the
|
|
6
|
+
* authored sample on the blokkli search page and in the editor canvas,
|
|
7
|
+
* which has no route query of its own.
|
|
8
|
+
*/
|
|
9
|
+
readonly query?: () => string;
|
|
6
10
|
}
|
|
7
11
|
|
|
8
12
|
/**
|
|
@@ -11,6 +15,11 @@ export interface SearchListingOptions {
|
|
|
11
15
|
* ListingContext) so the shared `listing_*` widgets work unchanged. There is no
|
|
12
16
|
* category/subcategory here (those resolve to undefined). The locked `search`
|
|
13
17
|
* wrapper block calls this once and provides the result.
|
|
18
|
+
*
|
|
19
|
+
* The term is read from `?q` FIRST and only falls back to `options.query` — that
|
|
20
|
+
* is what closes the loop with `pushQuery` below (which writes `?q`) and makes
|
|
21
|
+
* the in-page search box actually change the results. The fallback keeps the
|
|
22
|
+
* editor canvas rendering the authored sample, since it has no route query.
|
|
14
23
|
*/
|
|
15
24
|
export const useSearchListing = (options: SearchListingOptions) => {
|
|
16
25
|
const route = useRoute();
|
|
@@ -18,7 +27,11 @@ export const useSearchListing = (options: SearchListingOptions) => {
|
|
|
18
27
|
const { t } = useI18n();
|
|
19
28
|
const localePath = useLocalePath();
|
|
20
29
|
|
|
21
|
-
const
|
|
30
|
+
const routeQuery = computed(() => {
|
|
31
|
+
const q = route.query.q;
|
|
32
|
+
return Array.isArray(q) ? q[0] : q;
|
|
33
|
+
});
|
|
34
|
+
const query = computed(() => routeQuery.value ?? options.query?.() ?? "");
|
|
22
35
|
|
|
23
36
|
// No category context on the search page — kept for shape parity with
|
|
24
37
|
// useCategoryListing so the shared listing widgets (incl. the header) work.
|
|
@@ -27,8 +40,8 @@ export const useSearchListing = (options: SearchListingOptions) => {
|
|
|
27
40
|
const categorySlug = computed(() => "");
|
|
28
41
|
const subcategorySlug = computed(() => undefined);
|
|
29
42
|
|
|
30
|
-
// Mirrors the in-category search box mechanics
|
|
31
|
-
//
|
|
43
|
+
// Mirrors the in-category search box mechanics: `pushQuery` writes `?q` and
|
|
44
|
+
// `query` above reads it back, so typing re-runs the search.
|
|
32
45
|
const q = computed(() => query.value);
|
|
33
46
|
const searchInput = ref(q.value);
|
|
34
47
|
const pushQuery = useDebounceFn(() => {
|
package/app/layouts/default.vue
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
const head = useLocaleHead({ seo: true });
|
|
3
|
-
const {
|
|
3
|
+
const { navigateToSearch } = useSearch();
|
|
4
4
|
const route = useRoute();
|
|
5
5
|
const cart = useCartStore();
|
|
6
6
|
|
|
@@ -13,8 +13,7 @@ watch(isCartOrCheckoutPage, (isRestrictedPage) => {
|
|
|
13
13
|
}, { immediate: true });
|
|
14
14
|
|
|
15
15
|
async function handleSearch(q: string): Promise<void> {
|
|
16
|
-
|
|
17
|
-
await navigateTo("/search");
|
|
16
|
+
await navigateToSearch(q);
|
|
18
17
|
}
|
|
19
18
|
</script>
|
|
20
19
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@revenexx/cover",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.20",
|
|
4
4
|
"description": "Cover \u2014 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",
|
|
@@ -16,7 +16,20 @@ function isMissingFacetFieldError(err: unknown): boolean {
|
|
|
16
16
|
return /Could not find a facet field named/i.test(msg);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Same shape, for sorting: a collection provisioned before `name` was declared
|
|
21
|
+
* `sort: true` answers 404 "Could not find a field named `name` in the schema
|
|
22
|
+
* for sorting." Sorting is a nicety; the listing is not. Retry unsorted rather
|
|
23
|
+
* than fail the page, and let it start working by itself once the tenant's
|
|
24
|
+
* collection carries the field.
|
|
25
|
+
*/
|
|
26
|
+
function isMissingSortFieldError(err: unknown): boolean {
|
|
27
|
+
if (!err) return false;
|
|
28
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
29
|
+
return /Could not find a field named .* in the schema for sorting/i.test(msg);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
type SortOption = "relevance" | "price_asc" | "price_desc" | "name_asc" | "name_desc" | "sku_asc" | "sku_desc";
|
|
20
33
|
|
|
21
34
|
const SORT_MAP: Record<SortOption, string> = {
|
|
22
35
|
relevance: "_text_match:desc",
|
|
@@ -24,6 +37,8 @@ const SORT_MAP: Record<SortOption, string> = {
|
|
|
24
37
|
price_desc: "price:desc",
|
|
25
38
|
name_asc: "name:asc",
|
|
26
39
|
name_desc: "name:desc",
|
|
40
|
+
sku_asc: "sku:asc",
|
|
41
|
+
sku_desc: "sku:desc",
|
|
27
42
|
};
|
|
28
43
|
|
|
29
44
|
interface SearchBody {
|
|
@@ -122,19 +137,36 @@ export default defineEventHandler(async (event) => {
|
|
|
122
137
|
// Retry once without dynamic facets so the storefront keeps
|
|
123
138
|
// rendering with spine facets only; the meta cache repairs on
|
|
124
139
|
// its next refresh.
|
|
125
|
-
|
|
140
|
+
// The sort the visitor picked was computed and then never sent: the
|
|
141
|
+
// dropdown has been inert in live mode. Only the sorts the live
|
|
142
|
+
// collection can actually carry are passed on — it projects no `price`
|
|
143
|
+
// field, so a price sort would 404; "relevance" is the absence of
|
|
144
|
+
// sort_by, which is what Typesense does by itself.
|
|
145
|
+
//
|
|
146
|
+
// `name` and `sku` are STRINGS, and Typesense only sorts a string field
|
|
147
|
+
// that was declared `sort: true` at schema time. A catalogue whose
|
|
148
|
+
// search.json predates that is handled below: the request is retried
|
|
149
|
+
// unsorted rather than failing the listing.
|
|
150
|
+
const LIVE_SORTABLE: readonly SortOption[] = ["name_asc", "name_desc", "sku_asc", "sku_desc"];
|
|
151
|
+
const liveSortBy = LIVE_SORTABLE.includes(sort)
|
|
152
|
+
? SORT_MAP[sort]
|
|
153
|
+
: undefined;
|
|
154
|
+
|
|
155
|
+
const runSearch = async (facetBy: string, sortBy?: string) => searchLiveProducts({
|
|
126
156
|
q,
|
|
127
157
|
queryBy: "name,sku,description,manufacturer",
|
|
128
158
|
filterBy: liveFilterParts.join(" && "),
|
|
129
159
|
facetBy,
|
|
160
|
+
...(sortBy ? { sortBy } : {}),
|
|
130
161
|
page,
|
|
131
162
|
perPage,
|
|
132
163
|
});
|
|
133
164
|
|
|
134
|
-
|
|
135
|
-
|
|
165
|
+
// Two independent degradations, each retried once: a dynamic facet the
|
|
166
|
+
// tenant's schema no longer has, and a sort field it never had.
|
|
167
|
+
const searchWithFallbacks = async (sortBy?: string) => {
|
|
136
168
|
try {
|
|
137
|
-
|
|
169
|
+
return await runSearch(liveFacetBy, sortBy);
|
|
138
170
|
}
|
|
139
171
|
catch (err) {
|
|
140
172
|
if (dynamicFacets.length > 0 && isMissingFacetFieldError(err)) {
|
|
@@ -142,7 +174,24 @@ export default defineEventHandler(async (event) => {
|
|
|
142
174
|
"search: dynamic facet missing in Typesense, retrying with spine facets only",
|
|
143
175
|
toErrorContext(err),
|
|
144
176
|
);
|
|
145
|
-
|
|
177
|
+
return await runSearch(spineFacetBy, sortBy);
|
|
178
|
+
}
|
|
179
|
+
throw err;
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
try {
|
|
184
|
+
let results;
|
|
185
|
+
try {
|
|
186
|
+
results = await searchWithFallbacks(liveSortBy);
|
|
187
|
+
}
|
|
188
|
+
catch (err) {
|
|
189
|
+
if (liveSortBy && isMissingSortFieldError(err)) {
|
|
190
|
+
getLogService().warn(
|
|
191
|
+
"search: collection has no sortable field for this sort, retrying unsorted",
|
|
192
|
+
toErrorContext(err),
|
|
193
|
+
);
|
|
194
|
+
results = await searchWithFallbacks(undefined);
|
|
146
195
|
}
|
|
147
196
|
else {
|
|
148
197
|
throw err;
|
package/server/interfaces/log.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
export interface ILogService {
|
|
2
2
|
error(message: string, context?: Record<string, unknown>): void;
|
|
3
|
+
/**
|
|
4
|
+
* A degradation the request survived — a retry that worked, a feature
|
|
5
|
+
* switched off because its data was missing. Distinct from `error` so a
|
|
6
|
+
* log full of graceful fallbacks does not read like a log full of
|
|
7
|
+
* failures.
|
|
8
|
+
*/
|
|
9
|
+
warn(message: string, context?: Record<string, unknown>): void;
|
|
3
10
|
}
|
|
@@ -12,8 +12,16 @@ export class LogService implements ILogService {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
error(message: string, context?: Record<string, unknown>): void {
|
|
15
|
+
this.write("error", message, context);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
warn(message: string, context?: Record<string, unknown>): void {
|
|
19
|
+
this.write("warn", message, context);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
private write(level: string, message: string, context?: Record<string, unknown>): void {
|
|
15
23
|
const entry = JSON.stringify({
|
|
16
|
-
level
|
|
24
|
+
level,
|
|
17
25
|
timestamp: new Date().toISOString(),
|
|
18
26
|
message,
|
|
19
27
|
...context,
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|