qarpeo 0.4.14 → 0.4.15

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.
@@ -92,7 +92,7 @@ export interface UseProductsReturn {
92
92
  * parameters, and infinite pagination support.
93
93
  *
94
94
  * @example
95
- * ```vue
95
+ * ;```vue
96
96
  * <script setup lang="ts">
97
97
  * const search = ref('')
98
98
  * const { products, total, loading, loadMore, hasMore } = useProducts({ search })
@@ -122,7 +122,7 @@ export interface UseProductReturn {
122
122
  * Headless single product details composable with variant selection and real-time inventory checks.
123
123
  *
124
124
  * @example
125
- * ```vue
125
+ * ;```vue
126
126
  * <script setup lang="ts">
127
127
  * const route = useRoute()
128
128
  * const { product, selectedVariant, currentPrice, inStock, selectVariant } = useProduct(() => route.params.slug as string)
@@ -157,7 +157,7 @@ export interface UseCheckoutReturn {
157
157
  * Headless e-commerce checkout composable for processing active shopping carts.
158
158
  *
159
159
  * @example
160
- * ```vue
160
+ * ;```vue
161
161
  * <script setup lang="ts">
162
162
  * const { submitCheckout, loading, error } = useCheckout()
163
163
  * async function onPay() {
@@ -173,7 +173,7 @@ export declare const useStoreCheckout: () => UseCheckoutReturn;
173
173
  * Client-side currency composable for multi-currency display and conversion.
174
174
  *
175
175
  * @example
176
- * ```vue
176
+ * ;```vue
177
177
  * <script setup>
178
178
  * const { currency, setCurrency, format, convert } = useCurrency()
179
179
  * </script>
@@ -197,3 +197,18 @@ export interface UseCurrencyReturn {
197
197
  rate: ComputedRef<number>;
198
198
  }
199
199
  export declare function useCurrency(): UseCurrencyReturn;
200
+ /** Headless store categories composable backed by Nuxt `useFetch` (lazy). */
201
+ export declare function useCategories(): any;
202
+ export interface UseOrdersOptions {
203
+ status?: MaybeRefOrGetter<string | undefined>;
204
+ limit?: MaybeRefOrGetter<number | undefined>;
205
+ offset?: MaybeRefOrGetter<number | undefined>;
206
+ }
207
+ /** Headless authenticated customer orders list composable backed by Nuxt `useFetch` (lazy). */
208
+ export declare function useOrders(options?: UseOrdersOptions): any;
209
+ /** Headless single order detail composable backed by Nuxt `useFetch` (lazy). */
210
+ export declare function useOrder(id: MaybeRefOrGetter<string>): any;
211
+ /** Headless vendor directory composable backed by Nuxt `useFetch` (lazy). */
212
+ export declare function useVendors(): any;
213
+ /** Headless single vendor profile composable backed by Nuxt `useFetch` (lazy). */
214
+ export declare function useVendor(id: MaybeRefOrGetter<string>): any;
@@ -4,7 +4,7 @@ import {
4
4
  toValue,
5
5
  watch
6
6
  } from "vue";
7
- import { useRuntimeConfig, useState, useCookie } from "#imports";
7
+ import { useRuntimeConfig, useState, useCookie, useFetch } from "#imports";
8
8
  function getStorePrefix() {
9
9
  try {
10
10
  const cfg = useRuntimeConfig();
@@ -164,10 +164,24 @@ export function useCart() {
164
164
  loading.value = false;
165
165
  }
166
166
  }
167
- if (!cart.value && typeof window !== "undefined") {
168
- fetchCart().catch(() => {
169
- });
170
- }
167
+ const { data: cartData } = useFetch(
168
+ `${prefix}/cart`,
169
+ {
170
+ key: "qarpeo-store-cart",
171
+ lazy: true,
172
+ server: false
173
+ }
174
+ );
175
+ watch(
176
+ cartData,
177
+ (res) => {
178
+ if (res?.cart) {
179
+ cart.value = res.cart;
180
+ totals.value = res.totals;
181
+ }
182
+ },
183
+ { immediate: true }
184
+ );
171
185
  return {
172
186
  cart,
173
187
  totals,
@@ -413,3 +427,47 @@ export function useCurrency() {
413
427
  }
414
428
  return { currency, currencies, setCurrency, convert, format, rate };
415
429
  }
430
+ export function useCategories() {
431
+ const prefix = getStorePrefix();
432
+ return useFetch(`${prefix}/categories`, {
433
+ key: "qarpeo-store-categories",
434
+ lazy: true,
435
+ default: () => []
436
+ });
437
+ }
438
+ export function useOrders(options = {}) {
439
+ const prefix = getStorePrefix();
440
+ const query = computed(() => ({
441
+ status: toValue(options.status) || void 0,
442
+ limit: toValue(options.limit) ?? 20,
443
+ offset: toValue(options.offset) ?? 0
444
+ }));
445
+ return useFetch(`${prefix}/orders`, {
446
+ key: "qarpeo-store-orders",
447
+ query,
448
+ lazy: true,
449
+ default: () => ({ orders: [], total: 0 })
450
+ });
451
+ }
452
+ export function useOrder(id) {
453
+ const prefix = getStorePrefix();
454
+ return useFetch(`${prefix}/orders/${toValue(id)}`, {
455
+ key: `qarpeo-store-order-${toValue(id)}`,
456
+ lazy: true
457
+ });
458
+ }
459
+ export function useVendors() {
460
+ const prefix = getStorePrefix();
461
+ return useFetch(`${prefix}/vendors`, {
462
+ key: "qarpeo-store-vendors",
463
+ lazy: true,
464
+ default: () => []
465
+ });
466
+ }
467
+ export function useVendor(id) {
468
+ const prefix = getStorePrefix();
469
+ return useFetch(`${prefix}/vendors/${toValue(id)}`, {
470
+ key: `qarpeo-store-vendor-${toValue(id)}`,
471
+ lazy: true
472
+ });
473
+ }
@@ -8,6 +8,7 @@ export default defineEventHandler(async (event) => {
8
8
  const search = query.search ? String(query.search).trim() : void 0;
9
9
  const categoryId = query.category ? String(query.category) : void 0;
10
10
  const type = query.type ? String(query.type) : void 0;
11
+ const vendorId = query.vendorId ? String(query.vendorId) : void 0;
11
12
  const sortBy = query.sortBy ? String(query.sortBy) : void 0;
12
13
  const activeTenant = getTenant(event);
13
14
  const tenantId = activeTenant ? activeTenant.id : query.tenantId ? String(query.tenantId) : void 0;
@@ -19,6 +20,7 @@ export default defineEventHandler(async (event) => {
19
20
  search,
20
21
  categoryId,
21
22
  type,
23
+ vendorId,
22
24
  sortBy,
23
25
  minPrice,
24
26
  maxPrice,
@@ -1,5 +1,5 @@
1
1
  import type { RequestEvent } from "nuxt/server";
2
- import type { StoreProduct, StoreOrderItem, StoreQueryProductsOptions, StoreVendorMetrics } from "../../../types/store";
2
+ import type { StoreProduct, StoreOrderItem, StoreQueryProductsOptions, StoreVendorMetrics, StoreVendorSummary } from "../../../types/store";
3
3
  export declare function isMultiVendorStore(event?: RequestEvent): boolean;
4
4
  export declare function getStoreVendorMetrics(vendorId: string, opts?: {
5
5
  tenantId?: string;
@@ -16,3 +16,13 @@ export declare function queryVendorOrderItems(vendorId: string, opts?: {
16
16
  items: StoreOrderItem[];
17
17
  total: number;
18
18
  }>;
19
+ /** List active vendors aggregated from published products. */
20
+ export declare function queryStoreVendors(opts?: {
21
+ tenantId?: string;
22
+ limit?: number;
23
+ offset?: number;
24
+ }, event?: RequestEvent): Promise<StoreVendorSummary[]>;
25
+ /** Fetch a single vendor summary by vendor ID. Returns null if no active products exist. */
26
+ export declare function getStoreVendor(vendorId: string, opts?: {
27
+ tenantId?: string;
28
+ }, event?: RequestEvent): Promise<StoreVendorSummary | null>;
@@ -66,3 +66,50 @@ export async function queryVendorOrderItems(vendorId, opts = {}, event) {
66
66
  ).bind(...params, limit, offset).all();
67
67
  return { items: (rows.results ?? []).map(rowToOrderItem), total };
68
68
  }
69
+ export async function queryStoreVendors(opts = {}, event) {
70
+ const db = getD1(event);
71
+ const p = storeProductTbl(event);
72
+ const whereClauses = ["status = 'active'", "vendor_id IS NOT NULL"];
73
+ const params = [];
74
+ if (opts.tenantId !== void 0) {
75
+ whereClauses.push("tenant_id = ?");
76
+ params.push(opts.tenantId);
77
+ }
78
+ const limit = Math.min(opts.limit ?? 50, 100);
79
+ const offset = opts.offset ?? 0;
80
+ const result = await db.prepare(
81
+ `SELECT vendor_id as id, COUNT(*) as product_count
82
+ FROM ${p}
83
+ WHERE ${whereClauses.join(" AND ")}
84
+ GROUP BY vendor_id
85
+ ORDER BY product_count DESC
86
+ LIMIT ? OFFSET ?`
87
+ ).bind(...params, limit, offset).all();
88
+ return (result.results ?? []).map((row) => ({
89
+ id: row.id,
90
+ name: row.id,
91
+ productCount: Number(row.product_count),
92
+ logoUrl: null,
93
+ description: null
94
+ }));
95
+ }
96
+ export async function getStoreVendor(vendorId, opts = {}, event) {
97
+ const db = getD1(event);
98
+ const p = storeProductTbl(event);
99
+ const whereClauses = ["status = 'active'", "vendor_id = ?"];
100
+ const params = [vendorId];
101
+ if (opts.tenantId !== void 0) {
102
+ whereClauses.push("tenant_id = ?");
103
+ params.push(opts.tenantId);
104
+ }
105
+ const row = await db.prepare(`SELECT COUNT(*) as product_count FROM ${p} WHERE ${whereClauses.join(" AND ")}`).bind(...params).first();
106
+ const count = Number(row?.product_count ?? 0);
107
+ if (count === 0) return null;
108
+ return {
109
+ id: vendorId,
110
+ name: vendorId,
111
+ productCount: count,
112
+ logoUrl: null,
113
+ description: null
114
+ };
115
+ }
@@ -209,6 +209,13 @@ export interface StoreVendorMetrics {
209
209
  itemsSoldCount: number;
210
210
  totalProducts: number;
211
211
  }
212
+ export interface StoreVendorSummary {
213
+ id: string;
214
+ name: string;
215
+ productCount: number;
216
+ logoUrl?: string | null;
217
+ description?: string | null;
218
+ }
212
219
  export interface StoreQueryDiscountsOptions {
213
220
  tenantId?: string;
214
221
  isActive?: boolean;
@@ -1,3 +1,13 @@
1
+ export interface StoreRoutesOptions {
2
+ products?: boolean;
3
+ categories?: boolean;
4
+ cart?: boolean;
5
+ coupons?: boolean;
6
+ checkout?: boolean;
7
+ orders?: boolean;
8
+ currencies?: boolean;
9
+ tax?: boolean;
10
+ }
1
11
  export interface StoreOptions {
2
12
  /**
3
13
  * Default 3-letter currency code (ISO 4217).
@@ -11,6 +21,17 @@ export interface StoreOptions {
11
21
  * @default "/api/store"
12
22
  */
13
23
  prefix?: string;
24
+ /**
25
+ * Enable or selectively disable auto-mounted Store REST API routes. Set to `false` to disable all
26
+ * injected routes (keep utils & composables only), or pass an object to disable specific route
27
+ * groups.
28
+ *
29
+ * Routes defined in your app's `server/` directory at the same path and method also automatically
30
+ * override the built-in route.
31
+ *
32
+ * @default true
33
+ */
34
+ routes?: boolean | StoreRoutesOptions;
14
35
  /**
15
36
  * Cookie expiration in seconds for anonymous guest carts.
16
37
  *
@@ -0,0 +1,12 @@
1
+ import type { Nuxt } from "@nuxt/schema";
2
+ /**
3
+ * Scan user-defined `server/api` and `server/routes` files across Nuxt layers and return a set of
4
+ * normalized `"METHOD /path"` keys (with `"ALL /path"` for methodless handlers).
5
+ */
6
+ export declare function collectUserServerRoutes(nuxt: Nuxt): Set<string>;
7
+ /** Register a Nitro server handler only if not overridden by a user-defined route in `server/`. */
8
+ export declare function addOverridableServerHandler(userRoutes: Set<string>, handler: {
9
+ route: string;
10
+ method?: string;
11
+ handler: string;
12
+ }): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qarpeo",
3
- "version": "0.4.14",
3
+ "version": "0.4.15",
4
4
  "description": "Zero-config Cloudflare Edge Platform for Nuxt",
5
5
  "keywords": [
6
6
  "analytics-engine",
@@ -141,7 +141,7 @@
141
141
  },
142
142
  "dependencies": {
143
143
  "@nuxt/devtools-kit": "^4.2.2",
144
- "@nuxt/kit": "npm:@nuxt/kit-nightly@^5.0.0-2611251439-b19192b",
144
+ "@nuxt/kit": "npm:@nuxt/kit-nightly@^5.0.0-2611271552-65da378",
145
145
  "citty": "^0.2.2",
146
146
  "defu": "^6.1.7",
147
147
  "giget": "^3.3.1",
@@ -175,7 +175,7 @@
175
175
  "drizzle-seed": "1.0.0-rc.5",
176
176
  "h3": "^2.0.8",
177
177
  "nitro": "3.0.261103-rc",
178
- "nuxt": "npm:nuxt-nightly@^5.0.0-2611251439-b19192b",
178
+ "nuxt": "npm:nuxt-nightly@^5.0.0-2611271552-65da378",
179
179
  "postgres": "^4.1.1",
180
180
  "shiki": "^4.6.0",
181
181
  "typescript": "^7.0.2",