@revenexx/cover 0.2.26 → 0.2.27
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/brands.ts +5 -0
- package/app/api/categories.ts +1 -0
- package/app/api/product.ts +2 -0
- package/app/app.config.ts +8 -0
- package/app/components/cart/quickadd/CartQuickAdd.vue +110 -34
- package/app/components/category/view/GridView.vue +34 -13
- package/app/components/category/view/ListView.vue +5 -5
- package/app/components/layout/AppLogo.vue +2 -1
- package/app/components/layout/footer/Footer.vue +9 -3
- package/app/components/layout/header/CategoryPanel.vue +92 -0
- package/app/components/layout/header/MainNav.vue +89 -2
- package/app/components/listing/ListingResults.vue +16 -2
- package/app/components/listing/ListingSubcategories.vue +124 -0
- package/app/components/product/card/Compact.vue +144 -0
- package/app/components/product/detail/ProductDetailAssociations.vue +96 -0
- package/app/components/product/detail/ProductDetailIdentity.vue +50 -5
- package/app/components/product/detail/ProductDetailVariantRow.vue +139 -0
- package/app/components/product/detail/ProductDetailVariants.vue +613 -0
- package/app/components/product/media/ProductMediaImage.vue +70 -0
- package/app/components/ui/forms/SearchInput.vue +14 -2
- package/app/components/ui/media/ImageSlider.vue +158 -0
- package/app/composables/useBranding.ts +22 -0
- package/app/composables/useBrands.ts +42 -0
- package/app/composables/useCategories.ts +55 -1
- package/app/composables/useProduct.ts +5 -4
- package/app/composables/useProductAssociations.ts +35 -0
- package/app/composables/useProductImage.ts +35 -2
- package/app/composables/useProductVariants.ts +46 -0
- package/app/composables/useSearchListing.ts +16 -5
- package/app/composables/useSubcategoryTiles.ts +36 -0
- package/app/config/navigation.ts +9 -0
- package/app/config/palette.ts +1 -0
- package/app/config/quickActions.ts +137 -0
- package/app/config/themes.ts +1 -0
- package/app/interfaces/brand.ts +16 -0
- package/app/interfaces/category.ts +45 -0
- package/app/interfaces/image-slider.ts +18 -0
- package/app/interfaces/product-associations.ts +32 -0
- package/app/interfaces/product-detail.ts +6 -0
- package/app/interfaces/product-variants.ts +73 -0
- package/i18n/locales/de/account.json +17 -0
- package/i18n/locales/de/cart.json +5 -1
- package/i18n/locales/de/common.json +42 -2
- package/i18n/locales/de/editor.json +91 -0
- package/i18n/locales/de/product.json +48 -2
- package/i18n/locales/de/search.json +4 -2
- package/i18n/locales/en/account.json +17 -0
- package/i18n/locales/en/cart.json +4 -0
- package/i18n/locales/en/common.json +42 -2
- package/i18n/locales/en/editor.json +91 -0
- package/i18n/locales/en/product.json +47 -1
- package/i18n/locales/en/search.json +3 -1
- package/nuxt.config.ts +10 -0
- package/package.json +3 -1
- package/public/img/brands/revenexx.svg +39 -0
- package/server/api/brands.get.ts +27 -0
- package/server/api/categories/[slug]/subcategories.get.ts +280 -0
- package/server/api/product/[id]/associations.get.ts +27 -0
- package/server/api/product/[id]/variants.get.ts +27 -0
- package/server/api/quick-actions.get.ts +43 -0
- package/server/api/typesense/search.post.ts +116 -13
- package/server/data/categories.json +5 -0
- package/server/data/product-associations.json +44 -0
- package/server/data/product-detail.json +346 -0
- package/server/data/product-list.json +340 -0
- package/server/data/product-variant-models.json +75 -0
- package/server/interfaces/brand.ts +17 -0
- package/server/interfaces/product.ts +14 -0
- package/server/services/ApiBrandService.ts +110 -0
- package/server/services/ApiProductService.ts +43 -9
- package/server/services/LocalFileProductService.ts +200 -6
- package/server/services/MockBrandService.ts +52 -0
- package/server/utils/brandService.ts +24 -0
- package/server/utils/contentTenant.ts +67 -0
- package/server/utils/liveCatalog.ts +744 -46
- package/server/utils/productService.ts +6 -1
- package/server/utils/productsSchema.ts +5 -2
- package/server/utils/revenexxCredentials.ts +258 -0
- package/server/utils/revenexxSdk.ts +38 -47
|
@@ -5,7 +5,12 @@ import { ApiProductService } from "../services/ApiProductService";
|
|
|
5
5
|
import { LocalFileProductService } from "../services/LocalFileProductService";
|
|
6
6
|
|
|
7
7
|
const serviceRegistry: Record<string, IProductService> = {
|
|
8
|
-
mock: new LocalFileProductService(
|
|
8
|
+
mock: new LocalFileProductService(
|
|
9
|
+
"product-list.json",
|
|
10
|
+
"product-detail.json",
|
|
11
|
+
"product-variant-models.json",
|
|
12
|
+
"product-associations.json",
|
|
13
|
+
),
|
|
9
14
|
api: new ApiProductService(),
|
|
10
15
|
};
|
|
11
16
|
|
|
@@ -6,8 +6,11 @@ export const productsSchema = {
|
|
|
6
6
|
name: PRODUCTS_COLLECTION,
|
|
7
7
|
enable_nested_fields: true,
|
|
8
8
|
fields: [
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
// `sort: true` is required for Typesense to sort a STRING field at all —
|
|
10
|
+
// without it a `sort_by: name:asc` query 404s. The listing toolbar offers
|
|
11
|
+
// name_asc/name_desc/sku_asc/sku_desc, so both fields need it.
|
|
12
|
+
{ name: "name", type: "string" as const, sort: true },
|
|
13
|
+
{ name: "sku", type: "string" as const, sort: true },
|
|
11
14
|
{ name: "manufacturer", type: "string" as const, facet: true },
|
|
12
15
|
{ name: "available", type: "bool" as const, facet: true },
|
|
13
16
|
// Catalog list price — a sort/filter key ONLY (not the displayed price).
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import type { H3Event } from "h3";
|
|
2
|
+
|
|
3
|
+
// Imported explicitly rather than left to Nitro's auto-imports: this module is
|
|
4
|
+
// unit-tested outside a Nitro build, where those do not exist.
|
|
5
|
+
import { isContentTenantKey, resolveContentTenantKey } from "./contentTenant";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Which gateway tenant — and which key — this request talks to
|
|
9
|
+
* api.revenexx.com as.
|
|
10
|
+
*
|
|
11
|
+
* Kept out of ./revenexxSdk.ts so the resolution can be reasoned about (and
|
|
12
|
+
* unit-tested) without pulling in the generated SDK, and so the theme's
|
|
13
|
+
* storage/CDN/pages-app proxies can share it. They must: those proxies used to
|
|
14
|
+
* resolve the tenant and the API key from INDEPENDENT sources, which was
|
|
15
|
+
* already able to pair tenant A's slug with tenant B's key. With per-tenant
|
|
16
|
+
* credentials in play that latent mismatch becomes a certain 401, so the pair
|
|
17
|
+
* is resolved as one object here and never split apart again.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/** One content tenant's gateway credentials, as declared in runtime config. */
|
|
21
|
+
export interface RevenexxTenantCredential {
|
|
22
|
+
/** GATEWAY tenant slug — not necessarily the content tenant's own key. */
|
|
23
|
+
readonly tenant: string;
|
|
24
|
+
/** rvxk_… gateway key. Server-side only. */
|
|
25
|
+
readonly apiKey: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** The resolved identity for one request. Exactly one of apiKey/jwt is set. */
|
|
29
|
+
export interface RevenexxCredentials {
|
|
30
|
+
readonly tenant: string;
|
|
31
|
+
readonly apiKey: string;
|
|
32
|
+
readonly jwt: string;
|
|
33
|
+
readonly source: "brokered" | "content-tenant" | "env";
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
type TenantCredentialMap = Record<string, RevenexxTenantCredential>;
|
|
37
|
+
|
|
38
|
+
/** Keys that would reach up the prototype chain instead of into the map. */
|
|
39
|
+
const UNSAFE_KEYS = new Set(["__proto__", "constructor", "prototype"]);
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Parse the `revenexxTenants` runtime-config value into a credential map.
|
|
43
|
+
*
|
|
44
|
+
* Nitro runs `destr()` over every NUXT_* environment value, so a JSON string in
|
|
45
|
+
* the environment arrives here already PARSED — but a value declared directly
|
|
46
|
+
* in nuxt.config, or an env value that failed to parse, arrives as an object or
|
|
47
|
+
* a string respectively. Both shapes are accepted rather than guessed at.
|
|
48
|
+
*
|
|
49
|
+
* Malformed input yields an empty map instead of throwing: a typo'd credential
|
|
50
|
+
* must degrade to the single env tenant, not take the storefront down.
|
|
51
|
+
*
|
|
52
|
+
* Pure and exported for tests.
|
|
53
|
+
*/
|
|
54
|
+
export function parseTenantCredentialMap(raw: unknown): TenantCredentialMap {
|
|
55
|
+
let source = raw;
|
|
56
|
+
|
|
57
|
+
if (typeof source === "string") {
|
|
58
|
+
if (!source.trim()) {
|
|
59
|
+
return {};
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
source = JSON.parse(source);
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
// Fall through to the shape check below, which returns {}.
|
|
66
|
+
source = null;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (typeof source !== "object" || source === null || Array.isArray(source)) {
|
|
71
|
+
return {};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const map: TenantCredentialMap = {};
|
|
75
|
+
for (const [rawKey, value] of Object.entries(source as Record<string, unknown>)) {
|
|
76
|
+
const key = rawKey.trim().toLowerCase();
|
|
77
|
+
if (UNSAFE_KEYS.has(key) || !isContentTenantKey(key)) {
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
if (typeof value !== "object" || value === null) {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
const entry = value as Record<string, unknown>;
|
|
84
|
+
const tenant = typeof entry.tenant === "string" ? entry.tenant.trim() : "";
|
|
85
|
+
const apiKey = typeof entry.apiKey === "string" ? entry.apiKey.trim() : "";
|
|
86
|
+
// A half-filled entry would fail later, at the gateway, with a much
|
|
87
|
+
// worse error than simply not existing.
|
|
88
|
+
if (tenant && apiKey) {
|
|
89
|
+
map[key] = { tenant, apiKey };
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return map;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Parsing is per-process work, not per-request: runtimeConfig is built once, so
|
|
97
|
+
* the raw value's identity is stable and can key the memo.
|
|
98
|
+
*/
|
|
99
|
+
let memo: { source: unknown; map: TenantCredentialMap } | null = null;
|
|
100
|
+
let warnedInProduction = false;
|
|
101
|
+
|
|
102
|
+
function credentialMap(): TenantCredentialMap {
|
|
103
|
+
const raw: unknown = useRuntimeConfig().revenexxTenants;
|
|
104
|
+
if (memo?.source !== raw) {
|
|
105
|
+
memo = { source: raw, map: parseTenantCredentialMap(raw) };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// A populated map means a client-writable cookie can choose which tenant's
|
|
109
|
+
// API key the BFF authenticates with. That is the point in local dev; on a
|
|
110
|
+
// deployed Site the brokered headers win and the map should be absent.
|
|
111
|
+
if (!import.meta.dev && !warnedInProduction && Object.keys(memo.map).length > 0) {
|
|
112
|
+
warnedInProduction = true;
|
|
113
|
+
console.warn(
|
|
114
|
+
"[revenexx] NUXT_REVENEXX_TENANTS is set in a non-dev build. It lets the "
|
|
115
|
+
+ "cover-tenant cookie select gateway credentials and is intended for local "
|
|
116
|
+
+ "development only — deployed Sites use the brokered tenant context.",
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return memo.map;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Content tenants that declare gateway credentials. Keys only, never the keys'
|
|
125
|
+
* values — the theme's dev switcher uses this to know which tenants can serve
|
|
126
|
+
* live data.
|
|
127
|
+
*/
|
|
128
|
+
export function revenexxCredentialTenants(): string[] {
|
|
129
|
+
return Object.keys(credentialMap()).sort();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Whether the single env-configured gateway pair is usable on its own.
|
|
134
|
+
*
|
|
135
|
+
* Mirrors the `source: "env"` branch of resolveRevenexxCredentials() below, and
|
|
136
|
+
* has to keep mirroring it: a content tenant that declares no credentials falls
|
|
137
|
+
* through to that pair, so it can serve live data whenever this is true. The
|
|
138
|
+
* theme's dev switcher offers its live-data toggle on exactly that basis
|
|
139
|
+
* (server/api/blokkli/tenants.get.ts) — and a capability probe that only looked
|
|
140
|
+
* at the map is what kept the toggle disabled for `cover`, whose credentials
|
|
141
|
+
* resolve perfectly well.
|
|
142
|
+
*
|
|
143
|
+
* Trimmed, unlike the resolver: a whitespace-only environment value is a
|
|
144
|
+
* configuration typo, and offering the toggle for one only produces a gateway
|
|
145
|
+
* error further down.
|
|
146
|
+
*/
|
|
147
|
+
export function hasEnvRevenexxCredentials(): boolean {
|
|
148
|
+
const config = useRuntimeConfig();
|
|
149
|
+
return String(config.revenexxTenant || "").trim() !== ""
|
|
150
|
+
&& String(config.revenexxApiKey || "").trim() !== "";
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Which of the given content tenants can actually read live catalogue data.
|
|
155
|
+
*
|
|
156
|
+
* The list comes from the caller because enumerating content bundles belongs to
|
|
157
|
+
* the layer that ships them — but the RULE lives here, beside the resolver it
|
|
158
|
+
* has to agree with. A tenant is capable when it declares credentials of its
|
|
159
|
+
* own, OR when the env pair it falls through to is configured; asking only the
|
|
160
|
+
* map is what left the toggle disabled for every tenant on the fallback.
|
|
161
|
+
*
|
|
162
|
+
* Note what this deliberately does not promise: that live data will be THIS
|
|
163
|
+
* tenant's catalogue. A bundle on the fallback reads the env tenant's articles,
|
|
164
|
+
* which is why the caller also reports the resolved gateway tenant.
|
|
165
|
+
*/
|
|
166
|
+
export function liveCapableTenants(tenants: readonly string[]): string[] {
|
|
167
|
+
if (hasEnvRevenexxCredentials()) {
|
|
168
|
+
return [...tenants];
|
|
169
|
+
}
|
|
170
|
+
const declared = new Set(revenexxCredentialTenants());
|
|
171
|
+
return tenants.filter(tenant => declared.has(tenant));
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* The platform's per-invocation tenant context (ADR-0057 §8): on a deployed
|
|
176
|
+
* Site the entrypoint resolves the tenant from the request Host and injects
|
|
177
|
+
* x-revenexx-tenant the tenant slug
|
|
178
|
+
* x-revenexx-context the brokered per-tenant JWT for gateway calls
|
|
179
|
+
*/
|
|
180
|
+
function brokeredContext(event: H3Event): { tenant: string; jwt: string } | null {
|
|
181
|
+
const tenant = getRequestHeader(event, "x-revenexx-tenant");
|
|
182
|
+
if (!tenant) {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
return { tenant, jwt: getRequestHeader(event, "x-revenexx-context") ?? "" };
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* The configured API key for one gateway tenant, or "" when nothing configured
|
|
190
|
+
* names it. Never returns a key belonging to a different tenant.
|
|
191
|
+
*/
|
|
192
|
+
function configuredKeyFor(tenant: string): string {
|
|
193
|
+
const config = useRuntimeConfig();
|
|
194
|
+
if (String(config.revenexxTenant || "") === tenant) {
|
|
195
|
+
return String(config.revenexxApiKey || "");
|
|
196
|
+
}
|
|
197
|
+
const entry = Object.values(credentialMap()).find(candidate => candidate.tenant === tenant);
|
|
198
|
+
return entry?.apiKey ?? "";
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** The current request — explicit where callers have one, async context otherwise. */
|
|
202
|
+
function currentEvent(explicit?: H3Event): H3Event | undefined {
|
|
203
|
+
if (explicit) {
|
|
204
|
+
return explicit;
|
|
205
|
+
}
|
|
206
|
+
try {
|
|
207
|
+
return useEvent();
|
|
208
|
+
}
|
|
209
|
+
catch {
|
|
210
|
+
// Nitro throws rather than returning null when there is no async
|
|
211
|
+
// context, so "no request" has to be caught, not tested for.
|
|
212
|
+
return undefined;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Who this request talks to the gateway as, in descending precedence:
|
|
218
|
+
*
|
|
219
|
+
* 1. the platform's brokered context headers — a deployed Site. Always wins,
|
|
220
|
+
* so production behaviour is unchanged by anything below.
|
|
221
|
+
* 2. the content tenant's own credentials, when it declares any. This is what
|
|
222
|
+
* makes the `cover-tenant` cookie scope PRODUCTS and not just pages.
|
|
223
|
+
* 3. the single env-configured tenant API key — local dev, the demo shop.
|
|
224
|
+
*
|
|
225
|
+
* A content tenant with no entry falls through to (3) rather than failing, so a
|
|
226
|
+
* developer who configures nothing sees exactly today's behaviour.
|
|
227
|
+
*
|
|
228
|
+
* Every caller must go through this, including revenexxTenantKey(): a cache
|
|
229
|
+
* partitioned by a tenant the client did not actually use is worse than none.
|
|
230
|
+
*/
|
|
231
|
+
export function resolveRevenexxCredentials(event?: H3Event): RevenexxCredentials {
|
|
232
|
+
const resolved = currentEvent(event);
|
|
233
|
+
|
|
234
|
+
const brokered = resolved ? brokeredContext(resolved) : null;
|
|
235
|
+
if (brokered) {
|
|
236
|
+
// A tenant header WITHOUT a context token means the tenant is known but
|
|
237
|
+
// the auth is not. Take a key only from a configured credential that
|
|
238
|
+
// names the same gateway tenant — the storage and pages proxies used to
|
|
239
|
+
// pair the header tenant with the env key unconditionally, which
|
|
240
|
+
// authenticates as nobody the moment the two differ.
|
|
241
|
+
const apiKey = brokered.jwt ? "" : configuredKeyFor(brokered.tenant);
|
|
242
|
+
return { tenant: brokered.tenant, apiKey, jwt: brokered.jwt, source: "brokered" };
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const contentTenant = resolveContentTenantKey(resolved);
|
|
246
|
+
const entry = contentTenant ? credentialMap()[contentTenant] : undefined;
|
|
247
|
+
if (entry) {
|
|
248
|
+
return { tenant: entry.tenant, apiKey: entry.apiKey, jwt: "", source: "content-tenant" };
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const config = useRuntimeConfig();
|
|
252
|
+
return {
|
|
253
|
+
tenant: String(config.revenexxTenant || ""),
|
|
254
|
+
apiKey: String(config.revenexxApiKey || ""),
|
|
255
|
+
jwt: "",
|
|
256
|
+
source: "env",
|
|
257
|
+
};
|
|
258
|
+
}
|
|
@@ -24,6 +24,11 @@ import {
|
|
|
24
24
|
* NUXT_REVENEXX_API_URL (default https://api.revenexx.com)
|
|
25
25
|
* NUXT_REVENEXX_TENANT (tenant slug, e.g. "revenexx")
|
|
26
26
|
* NUXT_REVENEXX_API_KEY (rvxk_… gateway key)
|
|
27
|
+
* NUXT_REVENEXX_TENANTS (optional per-content-tenant credentials, dev only)
|
|
28
|
+
*
|
|
29
|
+
* Which of those applies to a given request — and how the brokered platform
|
|
30
|
+
* context and the `cover-tenant` cookie override them — is decided in one
|
|
31
|
+
* place, ./revenexxCredentials.ts.
|
|
27
32
|
*/
|
|
28
33
|
|
|
29
34
|
// Re-exported so route handlers can narrow SDK failures without importing
|
|
@@ -93,44 +98,32 @@ export function apiErrorContext(err: unknown): Record<string, unknown> {
|
|
|
93
98
|
return { errorMessage: err instanceof Error ? err.message : String(err) };
|
|
94
99
|
}
|
|
95
100
|
|
|
96
|
-
let sdk: RevenexxSdk | null = null;
|
|
97
|
-
|
|
98
101
|
/**
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
102
|
+
* One client per gateway tenant, NOT one per process. A multi-tenant theme
|
|
103
|
+
* would otherwise serve whichever tenant happened to warm the cache first to
|
|
104
|
+
* every later request — the same leak revenexxTenantKey() guards the data
|
|
105
|
+
* caches against.
|
|
106
|
+
*
|
|
107
|
+
* Only credential-derived, market-less clients land here, so every key
|
|
108
|
+
* originates from configuration and the map is bounded by the number of
|
|
109
|
+
* configured tenants. Brokered clients are request-scoped (the JWT rotates per
|
|
110
|
+
* invocation) and a market comes from a client-writable cookie, so caching
|
|
111
|
+
* either would let a caller mint unbounded entries.
|
|
107
112
|
*/
|
|
108
|
-
|
|
109
|
-
try {
|
|
110
|
-
const event = useEvent();
|
|
111
|
-
const tenant = getRequestHeader(event, "x-revenexx-tenant");
|
|
112
|
-
if (!tenant) {
|
|
113
|
-
return null;
|
|
114
|
-
}
|
|
115
|
-
return { tenant, jwt: getRequestHeader(event, "x-revenexx-context") ?? "" };
|
|
116
|
-
}
|
|
117
|
-
catch {
|
|
118
|
-
// No async context (e.g. startup code) — fall back to env credentials.
|
|
119
|
-
return null;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
113
|
+
const clients = new Map<string, RevenexxSdk>();
|
|
122
114
|
|
|
123
115
|
/**
|
|
124
116
|
* The active market for the current request, from the `cover-market` cookie the
|
|
125
117
|
* locale selector sets. "" when none — then no X-Revenexx-Market is sent and the
|
|
126
|
-
* gateway returns only global rows. Per-request,
|
|
127
|
-
*
|
|
118
|
+
* gateway returns only global rows. Per-request, and never part of a cache key
|
|
119
|
+
* (see useRevenexxSdk).
|
|
128
120
|
*/
|
|
129
121
|
function activeMarket(): string {
|
|
130
122
|
try {
|
|
131
123
|
return resolveSelectedMarket(useEvent()) ?? "";
|
|
132
124
|
}
|
|
133
125
|
catch {
|
|
126
|
+
// No async context (e.g. startup code) — no market scoping.
|
|
134
127
|
return "";
|
|
135
128
|
}
|
|
136
129
|
}
|
|
@@ -140,33 +133,33 @@ function activeMarket(): string {
|
|
|
140
133
|
* key for any server-side cache of gateway data (markets, categories, …).
|
|
141
134
|
* Module-level caches MUST be partitioned by this, or a multi-tenant theme
|
|
142
135
|
* leaks one tenant's data into another's pages.
|
|
136
|
+
*
|
|
137
|
+
* Shares resolveRevenexxCredentials() with useRevenexxSdk() so the key can
|
|
138
|
+
* never name a tenant other than the one the client actually authenticated as.
|
|
143
139
|
*/
|
|
144
140
|
export function revenexxTenantKey(): string {
|
|
145
|
-
|
|
146
|
-
if (brokered) {
|
|
147
|
-
return brokered.tenant;
|
|
148
|
-
}
|
|
149
|
-
const config = useRuntimeConfig();
|
|
150
|
-
return String(config.revenexxTenant || "");
|
|
141
|
+
return resolveRevenexxCredentials().tenant;
|
|
151
142
|
}
|
|
152
143
|
|
|
153
144
|
export function useRevenexxSdk(): RevenexxSdk {
|
|
154
|
-
const
|
|
145
|
+
const { tenant, apiKey, jwt, source } = resolveRevenexxCredentials();
|
|
155
146
|
const market = activeMarket();
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
if (
|
|
159
|
-
|
|
147
|
+
|
|
148
|
+
const isCacheable = source !== "brokered" && !market;
|
|
149
|
+
if (isCacheable) {
|
|
150
|
+
const cached = clients.get(tenant);
|
|
151
|
+
if (cached) {
|
|
152
|
+
return cached;
|
|
153
|
+
}
|
|
160
154
|
}
|
|
161
155
|
|
|
162
156
|
const config = useRuntimeConfig();
|
|
163
157
|
const endpoint = String(config.revenexxApiUrl || "https://api.revenexx.com").replace(/\/+$/, "");
|
|
164
|
-
const tenant = brokered?.tenant ?? String(config.revenexxTenant || "");
|
|
165
|
-
const apiKey = String(config.revenexxApiKey || "");
|
|
166
158
|
|
|
167
|
-
if (!tenant || (!
|
|
159
|
+
if (!tenant || (!jwt && !apiKey)) {
|
|
168
160
|
throw new RevenexxException(
|
|
169
|
-
"revenexx API credentials are not configured (NUXT_REVENEXX_TENANT / NUXT_REVENEXX_API_KEY
|
|
161
|
+
"revenexx API credentials are not configured (NUXT_REVENEXX_TENANT / NUXT_REVENEXX_API_KEY, "
|
|
162
|
+
+ "or an entry in NUXT_REVENEXX_TENANTS for the active content tenant)",
|
|
170
163
|
503,
|
|
171
164
|
"api_not_configured",
|
|
172
165
|
"",
|
|
@@ -188,8 +181,8 @@ export function useRevenexxSdk(): RevenexxSdk {
|
|
|
188
181
|
// "Bearer " prefix works around @revenexx/sdk <= 0.0.5 writing the raw
|
|
189
182
|
// value into the Authorization header (generator fix: sdk-generator #9;
|
|
190
183
|
// the fixed setter keeps an existing prefix, so this stays correct).
|
|
191
|
-
if (
|
|
192
|
-
client.setBearerAuth(`Bearer ${
|
|
184
|
+
if (jwt) {
|
|
185
|
+
client.setBearerAuth(`Bearer ${jwt}`);
|
|
193
186
|
}
|
|
194
187
|
else {
|
|
195
188
|
client.setApiKeyAuth(apiKey);
|
|
@@ -240,10 +233,8 @@ export function useRevenexxSdk(): RevenexxSdk {
|
|
|
240
233
|
shipping: new Shipping(client),
|
|
241
234
|
call,
|
|
242
235
|
};
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
if (!brokered && !market) {
|
|
246
|
-
sdk = instance;
|
|
236
|
+
if (isCacheable) {
|
|
237
|
+
clients.set(tenant, instance);
|
|
247
238
|
}
|
|
248
239
|
return instance;
|
|
249
240
|
}
|