@revenexx/cover 0.2.4 → 0.2.6

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.
@@ -14,8 +14,16 @@ const localePath = useLocalePath();
14
14
  const { to } = useAppUrl();
15
15
  const toast = useToast();
16
16
  const cart = useCartStore();
17
- const { orders, status, error } = useAccountOrders();
17
+ const { orders, total, page, pageSize, status, error } = useAccountOrders();
18
18
  const { formatCurrency } = useCartSummaryFormatting();
19
+
20
+ const pageCount = computed(() => Math.max(1, Math.ceil(total.value / pageSize)));
21
+ function prevPage(): void {
22
+ if (page.value > 1) page.value -= 1;
23
+ }
24
+ function nextPage(): void {
25
+ if (page.value < pageCount.value) page.value += 1;
26
+ }
19
27
  const { tableUi } = useDataTable();
20
28
 
21
29
  const statusColors: Record<AccountOrderStatus, "info" | "warning" | "primary" | "success" | "error"> = {
@@ -276,6 +284,34 @@ async function orderAgain(order: AccountOrder): Promise<void> {
276
284
  />
277
285
  </template>
278
286
  </UTable>
287
+
288
+ <div
289
+ v-if="total > pageSize"
290
+ class="flex items-center justify-between gap-4 pt-4 border-t border-(--ui-border)"
291
+ >
292
+ <span class="text-sm text-muted">
293
+ {{ t('orders.pagination.summary', { from: (page - 1) * pageSize + 1, to: Math.min(page * pageSize, total), total }) }}
294
+ </span>
295
+ <div class="flex items-center gap-2">
296
+ <UButton
297
+ :icon="icon('chevron-left')"
298
+ color="neutral"
299
+ variant="outline"
300
+ :disabled="page <= 1"
301
+ :label="t('orders.pagination.prev')"
302
+ @click="prevPage"
303
+ />
304
+ <UButton
305
+ :icon="icon('chevron-right')"
306
+ color="neutral"
307
+ variant="outline"
308
+ trailing
309
+ :disabled="page >= pageCount"
310
+ :label="t('orders.pagination.next')"
311
+ @click="nextPage"
312
+ />
313
+ </div>
314
+ </div>
279
315
  </template>
280
316
  </div>
281
317
  </template>
@@ -1,16 +1,28 @@
1
1
  import { accountApi } from "../api/account";
2
2
  import type { AccountOrder, AccountOrderListResponse } from "../interfaces/account/order-list";
3
3
 
4
+ const PAGE_SIZE = 20;
5
+
4
6
  export const useAccountOrders = () => {
5
- const { data, status, error, refresh } = useFetch<AccountOrderListResponse>(accountApi.orders(), {
6
- key: "account-orders",
7
- default: () => ({ orders: [] as AccountOrder[] }),
8
- });
7
+ const page = ref(1);
8
+
9
+ const { data, status, error, refresh } = useFetch<AccountOrderListResponse>(
10
+ () => `${accountApi.orders()}?offset=${(page.value - 1) * PAGE_SIZE}&limit=${PAGE_SIZE}`,
11
+ {
12
+ key: "account-orders",
13
+ default: () => ({ orders: [] as AccountOrder[] }),
14
+ watch: [page],
15
+ },
16
+ );
9
17
 
10
18
  const orders = computed(() => data.value.orders);
19
+ const total = computed(() => data.value.total ?? orders.value.length);
11
20
 
12
21
  return {
13
22
  orders,
23
+ total,
24
+ page,
25
+ pageSize: PAGE_SIZE,
14
26
  status,
15
27
  error,
16
28
  refresh,
@@ -50,4 +50,8 @@ export interface AccountOrder {
50
50
 
51
51
  export interface AccountOrderListResponse {
52
52
  readonly orders: AccountOrder[];
53
+ /** Total orders for the contact (server-paginated history). */
54
+ readonly total?: number;
55
+ /** More pages beyond this window. */
56
+ readonly hasMore?: boolean;
53
57
  }
@@ -56,6 +56,7 @@
56
56
  "orders": {
57
57
  "title": "Ihre Bestellungen",
58
58
  "description": "Alle Ihre bisherigen Bestellungen im Überblick.",
59
+ "pagination": { "summary": "{from}–{to} von {total} Bestellungen", "prev": "Zurück", "next": "Weiter" },
59
60
  "errorTitle": "Bestellungen konnten nicht geladen werden",
60
61
  "errorDescription": "Bitte versuchen Sie es später erneut.",
61
62
  "empty": {
@@ -56,6 +56,7 @@
56
56
  "orders": {
57
57
  "title": "Your orders",
58
58
  "description": "View and track all your past orders.",
59
+ "pagination": { "summary": "{from}–{to} of {total} orders", "prev": "Back", "next": "Next" },
59
60
  "errorTitle": "Orders could not be loaded",
60
61
  "errorDescription": "Please try again later.",
61
62
  "empty": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revenexx/cover",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
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",
@@ -38,7 +38,7 @@
38
38
  "@formkit/vue": "^1.6.0",
39
39
  "@iconify-json/lucide": "^1.2.111",
40
40
  "@internationalized/date": "^3.12.0",
41
- "@revenexx/sdk": "^0.0.7",
41
+ "@revenexx/sdk": "^0.0.11",
42
42
  "@revenexx/storage-model-viewer": "^0.3.0",
43
43
  "@vueuse/core": "^14.3.0",
44
44
  "typesense": "^3.0.5"
@@ -19,20 +19,32 @@ export default defineEventHandler(async (event): Promise<AccountOrderListRespons
19
19
  }
20
20
  try {
21
21
  const sdk = useRevenexxSdk();
22
- // Raw call: orders.list does not declare its query parameters in
23
- // the contract yet, so ordersList() cannot filter by contact.
24
- const { items } = await sdk.call<{ items: LiveOrder[] }>("GET", "/v1/orders", {
25
- query: { contact_id: contactId, limit: LIVE_HISTORY_LIMIT },
26
- });
27
- // The list rows carry no positions — load the aggregates (the
28
- // history is capped, so this stays a bounded fan-out).
22
+ // Server-paginated: page through the contact's full history.
23
+ const q = getQuery(event);
24
+ const limit = Math.min(Math.max(Number(q.limit) || LIVE_HISTORY_LIMIT, 1), 100);
25
+ const offset = Math.max(Number(q.offset) || 0, 0);
26
+ // Typed list call (orders.list now declares its query parameters —
27
+ // @revenexx/sdk >= 0.0.9). order=created_at.desc is REQUIRED: without
28
+ // it mountCrud returns the oldest rows first, so with a limit the
29
+ // NEWEST orders fall outside the window and never show. created_at is
30
+ // not-null (placed_at can be null), so it sorts deterministically.
31
+ // The list response stays untyped (the page schema is unnamed), so
32
+ // cast to the known list shape.
33
+ const { items, page } = await sdk.orders.ordersList({
34
+ contactId, limit, offset, order: "created_at.desc",
35
+ }) as unknown as {
36
+ items: LiveOrder[];
37
+ page?: { total?: number; hasMore?: boolean };
38
+ };
39
+ // The list rows carry no positions — load the aggregates (one page
40
+ // at a time, so this stays a bounded fan-out).
29
41
  const aggregates = await Promise.all(
30
42
  items.map(async row => await sdk.orders.ordersGet({ id: row.id }) as unknown as LiveOrder),
31
43
  );
32
44
  const orders = aggregates
33
45
  .sort((a, b) => (b.placed_at ?? b.created_at).localeCompare(a.placed_at ?? a.created_at))
34
46
  .map(mapLiveOrderToAccount);
35
- return { orders };
47
+ return { orders, total: page?.total ?? offset + orders.length, hasMore: page?.hasMore ?? false };
36
48
  }
37
49
  catch (err) {
38
50
  getLogService().error("Live order history failed", apiErrorContext(err));
@@ -75,12 +75,12 @@ export class ApiAddressBookService implements IAddressBookService {
75
75
  return [];
76
76
  }
77
77
  try {
78
- // Raw call: the list contract does not declare query params yet.
79
- const { items } = await useRevenexxSdk().call<{ items: ApiAddressRow[] }>(
80
- "GET",
81
- "/v1/customers/addresses",
82
- { query: { contact_id, limit: 200 } },
83
- );
78
+ // Typed list filter (customers.addresses.list declares its query
79
+ // params — @revenexx/sdk >= 0.0.11).
80
+ const { items } = await useRevenexxSdk().customers.customersAddressesList({
81
+ contactId: contact_id,
82
+ limit: 200,
83
+ }) as unknown as { items: ApiAddressRow[] };
84
84
  return items.map(toAccountAddress);
85
85
  }
86
86
  catch (err) {
@@ -58,10 +58,6 @@ function resolveOwner(event: H3Event): CartOwner {
58
58
  return { contactId, sessionKey: getOrCreateCartSessionId(event) };
59
59
  }
60
60
 
61
- function ownerQuery(owner: CartOwner): Record<string, string> {
62
- return owner.contactId ? { contact_id: owner.contactId } : { session_key: owner.sessionKey };
63
- }
64
-
65
61
  /** Storefront CartItem → carts-app line. The snapshot is the loose product copy. */
66
62
  function toApiLine(item: CartItem, position: number): Record<string, unknown> {
67
63
  return {
@@ -138,16 +134,13 @@ function toSummary(cart: ApiCart): CartSummaryRow {
138
134
  */
139
135
  export class ApiCartService implements ICartService, ICartManager {
140
136
  private async listActive(owner: CartOwner): Promise<ApiCart[]> {
141
- // Raw call: carts.list does not declare its query parameters in the
142
- // contract yet, so the generated cartsList() cannot filter by owner.
143
- const { items } = await useRevenexxSdk().call<{ items: ApiCart[] }>("GET", "/v1/carts", {
144
- query: {
145
- ...ownerQuery(owner),
146
- status: "active",
147
- limit: 100,
148
- order: "updated_at.desc",
149
- },
150
- });
137
+ // Typed list filter (carts.list declares its query params — @revenexx/sdk >= 0.0.11).
138
+ const { items } = await useRevenexxSdk().carts.cartsList({
139
+ ...(owner.contactId ? { contactId: owner.contactId } : { sessionKey: owner.sessionKey }),
140
+ status: "active",
141
+ limit: 100,
142
+ order: "updated_at.desc",
143
+ }) as unknown as { items: ApiCart[] };
151
144
  return items;
152
145
  }
153
146
 
@@ -189,12 +189,13 @@ async function loadLiveCategoryRows(): Promise<LiveCategoryRow[]> {
189
189
  const rows: LiveCategoryRow[] = [];
190
190
  let offset = 0;
191
191
  // Paginate defensively — the demo tenant has a few hundred categories.
192
- // Raw call: the categories list contract does not declare limit/offset
193
- // yet, so the generated productsCategoriesList() cannot paginate.
192
+ // Typed list (products.categories.list declares limit/offset/order —
193
+ // @revenexx/sdk >= 0.0.11).
194
194
  for (let pageIndex = 0; pageIndex < 25; pageIndex++) {
195
- const page = await sdk.call<LiveCategoryPage>("GET", "/v1/products/categories", {
196
- query: { limit: CATEGORY_PAGE_LIMIT, offset },
197
- });
195
+ const page = await sdk.products.productsCategoriesList({
196
+ limit: CATEGORY_PAGE_LIMIT,
197
+ offset,
198
+ }) as unknown as LiveCategoryPage;
198
199
  rows.push(...page.items);
199
200
  if (!page.page.hasMore) {
200
201
  break;
@@ -9,9 +9,8 @@ import type { OrderList, OrderListPosition } from "../../app/interfaces/account/
9
9
  * service. Request params are camelCase (the SDK maps to the gateway's
10
10
  * snake_case); responses come back snake_case.
11
11
  *
12
- * Only the visibility-filtered LIST still uses the `sdk.call()` escape
13
- * hatch: `orderlistsList()` declares no query parameters in the contract
14
- * yet, so it cannot filter by owner/organization. Everything else is typed.
12
+ * The visibility-filtered LIST is typed too (orderlists.list declares
13
+ * owner_id/organization_id/kind since @revenexx/sdk >= 0.0.11).
15
14
  *
16
15
  * Identity: the app stores `owner_id`/`organization_id` and `GET /orderlists`
17
16
  * returns the owner's own lists ∪ the organization's shared lists. We supply
@@ -76,13 +75,12 @@ function toCoverPosition(item: AppItem): OrderListPosition {
76
75
  }
77
76
 
78
77
  /**
79
- * cover position → the gateway's item payload. The typed methods declare
80
- * `items: Models.OrderListItemInput[]` (camelCase), but the SDK passes the
81
- * `items` array through RAW (no camelCase→snake_case conversion of nested
82
- * objects — unlike top-level params). The orderlists app reads snake_case,
83
- * so we build snake_case keys and cast to the typed shape; sending camelCase
84
- * silently drops the multi-word fields (tax_rate, cost_center_id, …).
85
- * TODO(sdk-generator): deep-convert nested object params so this cast can go.
78
+ * cover position → the gateway's item payload. `Models.OrderListItemInput`
79
+ * is snake_case (tax_rate, cost_center_id, …), so we build snake_case keys
80
+ * that match the typed shape directly. (The SDK also deep-converts nested
81
+ * camelCase keys since @revenexx/sdk >= 0.0.10 / DX-55, but building the
82
+ * wire keys here keeps this type-aligned with the model.) The conditional
83
+ * spreads still need a cast for exactness.
86
84
  */
87
85
  function toItemInput(position: OrderListPosition): Models.OrderListItemInput {
88
86
  const item: Record<string, unknown> = {
@@ -119,11 +117,12 @@ function toCoverList(row: AppList): OrderList {
119
117
  export async function listOrderLists(event: H3Event): Promise<OrderList[]> {
120
118
  const me = await actor(event);
121
119
  const sdk = useRevenexxSdk();
122
- // Escape hatch: orderlistsList() declares no query params, so it cannot
123
- // filter by owner/organization. The fan-out to full lists is typed.
124
- const { items } = await sdk.call<{ items: AppList[] }>("GET", "/v1/orderlists", {
125
- query: { owner_id: me.contactId, ...(me.organizationId ? { organization_id: me.organizationId } : {}) },
126
- });
120
+ // Typed list filter (orderlists.list declares owner_id/organization_id —
121
+ // @revenexx/sdk >= 0.0.11). The fan-out to full lists is typed too.
122
+ const { items } = await sdk.orderlists.orderlistsList({
123
+ ownerId: me.contactId,
124
+ ...(me.organizationId ? { organizationId: me.organizationId } : {}),
125
+ }) as unknown as { items: AppList[] };
127
126
  const full = await Promise.all(items.map(async row => sdk.orderlists.orderlistsGet({ id: row.id })));
128
127
  return full.map(row => toCoverList(row as unknown as AppList));
129
128
  }
@@ -136,9 +136,10 @@ export function mapLiveOrderToAccount(order: LiveOrder): AccountOrder {
136
136
  /** Fetch one live order by its display number (the account history id). */
137
137
  export async function getLiveOrderByNumber(number: string): Promise<LiveOrder | null> {
138
138
  const sdk = useRevenexxSdk();
139
- // Raw call: orders.list does not declare its query parameters in the
140
- // contract yet, so the generated ordersList() cannot filter by number.
141
- const { items } = await sdk.call<{ items: LiveOrder[] }>("GET", "/v1/orders", { query: { number, limit: 1 } });
139
+ // Typed list filter — orders.list now declares its query parameters
140
+ // (@revenexx/sdk >= 0.0.10). The list response stays untyped (unnamed page
141
+ // schema), so cast to the known shape.
142
+ const { items } = await sdk.orders.ordersList({ number, limit: 1 }) as unknown as { items: LiveOrder[] };
142
143
  const row = items[0];
143
144
  if (!row) {
144
145
  return null;