@revenexx/cover 0.16.0 → 0.17.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@revenexx/cover",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.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",
|
|
@@ -68,6 +68,29 @@ function visitCartId(event: H3Event): string | null {
|
|
|
68
68
|
return visit && !visit.handedBack ? visit.cartId : null;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
/**
|
|
72
|
+
* The query a call on `cartId` has to carry: the visit's pSid as
|
|
73
|
+
* `?session_key=` when the cart is the open visit's own, else null.
|
|
74
|
+
*
|
|
75
|
+
* The visit's cart is owned by its pSid, not by the contact, and every call
|
|
76
|
+
* this BFF makes for a signed-in buyer carries their principal. From carts
|
|
77
|
+
* 3.0.0 on such a call reaches a cart no contact owns only with that cart's
|
|
78
|
+
* key, so every call on the visit's cart presents it (RAD-167). carts accepts
|
|
79
|
+
* it from 2.5.0 on (RAD-252). The typed SDK takes no such parameter yet, so
|
|
80
|
+
* these calls go through the transport's escape hatch.
|
|
81
|
+
*/
|
|
82
|
+
function visitCartKey(event: H3Event, cartId: string): { session_key: string } | null {
|
|
83
|
+
const visit = readPunchoutVisit(event);
|
|
84
|
+
return visit && !visit.handedBack && visit.cartId === cartId && visit.psid
|
|
85
|
+
? { session_key: visit.psid }
|
|
86
|
+
: null;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** A cart's address in the gateway, with an optional sub-path. */
|
|
90
|
+
function cartPath(cartId: string, suffix = ""): string {
|
|
91
|
+
return `/v1/carts/${encodeURIComponent(cartId)}${suffix}`;
|
|
92
|
+
}
|
|
93
|
+
|
|
71
94
|
/** Storefront CartItem → carts-app line. The snapshot is the loose product copy. */
|
|
72
95
|
function toApiLine(item: CartItem, position: number): Record<string, unknown> {
|
|
73
96
|
return {
|
|
@@ -175,8 +198,11 @@ export class ApiCartService implements ICartService, ICartManager {
|
|
|
175
198
|
}) as unknown as ApiCart;
|
|
176
199
|
}
|
|
177
200
|
|
|
178
|
-
private async listItems(cartId: string): Promise<CartItem[]> {
|
|
179
|
-
const
|
|
201
|
+
private async listItems(event: H3Event, cartId: string): Promise<CartItem[]> {
|
|
202
|
+
const query = visitCartKey(event, cartId);
|
|
203
|
+
const { items } = (query
|
|
204
|
+
? await useRevenexxSdk().call("GET", cartPath(cartId, "/items"), { query })
|
|
205
|
+
: await useRevenexxSdk().cartsItems.cartsItemsList({ cartId })) as unknown as { items: ApiCartLine[] };
|
|
180
206
|
return items.map(toCartItem);
|
|
181
207
|
}
|
|
182
208
|
|
|
@@ -194,14 +220,20 @@ export class ApiCartService implements ICartService, ICartManager {
|
|
|
194
220
|
|
|
195
221
|
async getItems(event: H3Event): Promise<CartItem[]> {
|
|
196
222
|
const cartId = await this.activeCartId(event);
|
|
197
|
-
return cartId ? await this.listItems(cartId) : [];
|
|
223
|
+
return cartId ? await this.listItems(event, cartId) : [];
|
|
198
224
|
}
|
|
199
225
|
|
|
200
226
|
async saveItems(event: H3Event, items: CartItem[]): Promise<void> {
|
|
201
227
|
const cartId = visitCartId(event) ?? (await this.ensureActiveCart(resolveOwner(event))).id;
|
|
228
|
+
const lines = items.map((item, index) => toApiLine(item, index));
|
|
229
|
+
const query = visitCartKey(event, cartId);
|
|
230
|
+
if (query) {
|
|
231
|
+
await useRevenexxSdk().call("PUT", cartPath(cartId, "/items"), { query, body: { items: lines } });
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
202
234
|
await useRevenexxSdk().cartsItems.cartsItemsReplace({
|
|
203
235
|
cartId,
|
|
204
|
-
items:
|
|
236
|
+
items: lines as unknown as Models.CartItemCreateRequest[],
|
|
205
237
|
});
|
|
206
238
|
}
|
|
207
239
|
|
|
@@ -217,7 +249,7 @@ export class ApiCartService implements ICartService, ICartManager {
|
|
|
217
249
|
// sends that cart and no other. The visit sees exactly its own cart.
|
|
218
250
|
const visitCart = visitCartId(event);
|
|
219
251
|
if (visitCart) {
|
|
220
|
-
const cart = await useRevenexxSdk().call<ApiCart>("GET",
|
|
252
|
+
const cart = await useRevenexxSdk().call<ApiCart>("GET", cartPath(visitCart), { query: visitCartKey(event, visitCart) ?? {} });
|
|
221
253
|
return { carts: [{ ...toSummary(cart), active: true }], activeCartId: visitCart };
|
|
222
254
|
}
|
|
223
255
|
const carts = await this.listActive(resolveOwner(event));
|
|
@@ -244,10 +276,22 @@ export class ApiCartService implements ICartService, ICartManager {
|
|
|
244
276
|
}
|
|
245
277
|
|
|
246
278
|
async renameCart(event: H3Event, id: string, name: string): Promise<void> {
|
|
279
|
+
const query = visitCartKey(event, id);
|
|
280
|
+
if (query) {
|
|
281
|
+
await useRevenexxSdk().call("PUT", cartPath(id), { query, body: { name: name.trim() } });
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
247
284
|
await useRevenexxSdk().carts.cartsUpdate({ id, name: name.trim() });
|
|
248
285
|
}
|
|
249
286
|
|
|
250
287
|
async deleteCart(event: H3Event, id: string): Promise<void> {
|
|
288
|
+
// The visit's own cart never gets here (assertPunchoutCartKept), but a
|
|
289
|
+
// call on it would need its key all the same.
|
|
290
|
+
const query = visitCartKey(event, id);
|
|
291
|
+
if (query) {
|
|
292
|
+
await useRevenexxSdk().call("DELETE", cartPath(id), { query });
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
251
295
|
await useRevenexxSdk().carts.cartsDelete({ id });
|
|
252
296
|
}
|
|
253
297
|
|
|
@@ -262,11 +306,31 @@ export class ApiCartService implements ICartService, ICartManager {
|
|
|
262
306
|
if (!visitCart) {
|
|
263
307
|
await useRevenexxSdk().carts.cartsActivate({ id });
|
|
264
308
|
}
|
|
265
|
-
return await this.listItems(id);
|
|
309
|
+
return await this.listItems(event, id);
|
|
266
310
|
}
|
|
267
311
|
|
|
268
312
|
async addItemToCart(event: H3Event, id: string, item: CartItem): Promise<void> {
|
|
269
313
|
const line = toApiLine(item, 0);
|
|
314
|
+
const query = visitCartKey(event, id);
|
|
315
|
+
if (query) {
|
|
316
|
+
// The wire form of exactly what the typed call below sends.
|
|
317
|
+
await useRevenexxSdk().call("POST", cartPath(id, "/items"), {
|
|
318
|
+
query,
|
|
319
|
+
body: {
|
|
320
|
+
...(line.product_id ? { product_id: String(line.product_id) } : {}),
|
|
321
|
+
...(line.sku ? { sku: String(line.sku) } : {}),
|
|
322
|
+
name: String(line.name),
|
|
323
|
+
quantity: Number(line.quantity),
|
|
324
|
+
...(line.unit ? { unit: String(line.unit) } : {}),
|
|
325
|
+
unit_price: Number(line.unit_price),
|
|
326
|
+
tax_rate: Number(line.tax_rate),
|
|
327
|
+
position: Number(line.position),
|
|
328
|
+
snapshot: line.snapshot,
|
|
329
|
+
metadata: line.metadata,
|
|
330
|
+
},
|
|
331
|
+
});
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
270
334
|
await useRevenexxSdk().cartsItems.cartsItemsCreate({
|
|
271
335
|
cartId: id,
|
|
272
336
|
...(line.product_id ? { productId: String(line.product_id) } : {}),
|
|
@@ -287,6 +351,11 @@ export class ApiCartService implements ICartService, ICartManager {
|
|
|
287
351
|
if (!cartId) {
|
|
288
352
|
return null;
|
|
289
353
|
}
|
|
354
|
+
const query = visitCartKey(event, cartId);
|
|
355
|
+
if (query) {
|
|
356
|
+
await useRevenexxSdk().call("POST", cartPath(cartId, "/order"), { query, body: { order_ref: orderRef } });
|
|
357
|
+
return cartId;
|
|
358
|
+
}
|
|
290
359
|
await useRevenexxSdk().carts.cartsOrder({ id: cartId, orderRef });
|
|
291
360
|
return cartId;
|
|
292
361
|
}
|