@fayz-ai/shop 0.8.4 → 0.9.0-next.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/dist/catalog.js +2 -176
- package/dist/catalog.js.map +1 -1
- package/dist/{catalog.cjs → chunk-CTKZ6O2J.js} +3 -9
- package/dist/chunk-CTKZ6O2J.js.map +1 -0
- package/dist/chunk-IYQHKMLB.js +21 -0
- package/dist/chunk-IYQHKMLB.js.map +1 -0
- package/dist/chunk-JR25TISO.js +3 -0
- package/dist/chunk-JR25TISO.js.map +1 -0
- package/dist/{mock.cjs → chunk-SVTCJ6HP.js} +4 -102
- package/dist/chunk-SVTCJ6HP.js.map +1 -0
- package/dist/index.js +18 -639
- package/dist/index.js.map +1 -1
- package/dist/mock.js +2 -533
- package/dist/mock.js.map +1 -1
- package/dist/runtime.js +3 -549
- package/dist/runtime.js.map +1 -1
- package/package.json +22 -26
- package/dist/catalog.cjs.map +0 -1
- package/dist/index.cjs +0 -1365
- package/dist/index.cjs.map +0 -1
- package/dist/mock.cjs.map +0 -1
- package/dist/provider.cjs +0 -4
- package/dist/provider.cjs.map +0 -1
- package/dist/runtime.cjs +0 -555
- package/dist/runtime.cjs.map +0 -1
- package/dist/types.cjs +0 -4
- package/dist/types.cjs.map +0 -1
package/dist/mock.js
CHANGED
|
@@ -1,535 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
function svgPlaceholder(label, hueA, hueB) {
|
|
4
|
-
const initials = label.split(/\s+/).map((w) => w[0]).slice(0, 2).join("").toUpperCase();
|
|
5
|
-
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="600" height="600"><defs><linearGradient id="g" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="hsl(${hueA},45%,82%)"/><stop offset="1" stop-color="hsl(${hueB},50%,62%)"/></linearGradient></defs><rect width="600" height="600" fill="url(#g)"/><text x="300" y="330" font-family="sans-serif" font-size="120" font-weight="700" fill="rgba(255,255,255,0.85)" text-anchor="middle">${initials}</text></svg>`;
|
|
6
|
-
return `data:image/svg+xml;utf8,${encodeURIComponent(svg)}`;
|
|
7
|
-
}
|
|
8
|
-
function image(productId, name, hueA, hueB, idx = 0) {
|
|
9
|
-
return {
|
|
10
|
-
id: `img-${productId}-${idx}`,
|
|
11
|
-
productId,
|
|
12
|
-
url: svgPlaceholder(name, hueA, hueB),
|
|
13
|
-
altText: name,
|
|
14
|
-
sortOrder: idx,
|
|
15
|
-
isPrimary: idx === 0,
|
|
16
|
-
createdAt: T0
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
var MOCK_CATEGORIES = [
|
|
20
|
-
{ id: "cat-apparel", tenantId: "mock", name: "Apparel", slug: "apparel", description: "Clothing and wearables", parentId: null, sortOrder: 0, createdAt: T0 },
|
|
21
|
-
{ id: "cat-bags", tenantId: "mock", name: "Bags & Accessories", slug: "bags-accessories", description: "Bags, wallets and carry gear", parentId: null, sortOrder: 1, createdAt: T0 },
|
|
22
|
-
{ id: "cat-home", tenantId: "mock", name: "Home & Kitchen", slug: "home-kitchen", description: "Everyday home goods", parentId: null, sortOrder: 2, createdAt: T0 },
|
|
23
|
-
{ id: "cat-tech", tenantId: "mock", name: "Stationery & Tech", slug: "stationery-tech", description: "Desk, audio and paper goods", parentId: null, sortOrder: 3, createdAt: T0 }
|
|
24
|
-
];
|
|
25
|
-
var SEEDS = [
|
|
26
|
-
// --- Apparel ---
|
|
27
|
-
{ id: "p-01", name: "Classic T-Shirt", slug: "classic-t-shirt", description: "A timeless crew-neck tee in heavyweight combed cotton. Pre-shrunk, breathable, and built to outlast trends.", price: 59.9, compareAtPrice: 79.9, inventoryCount: 50, sku: "TSH-001", categoryId: "cat-apparel", hues: [210, 240], weight: 0.2 },
|
|
28
|
-
{ id: "p-02", name: "Linen Shirt", slug: "linen-shirt", description: "A relaxed-fit shirt in 100% European linen. Naturally breathable and softer with every wash.", price: 189.9, inventoryCount: 24, sku: "LNS-002", categoryId: "cat-apparel", hues: [35, 20], weight: 0.3 },
|
|
29
|
-
{ id: "p-03", name: "Denim Jacket", slug: "denim-jacket", description: "A structured trucker jacket in 12oz raw denim. Ages beautifully with hidden interior pockets.", price: 299.9, inventoryCount: 12, sku: "DNJ-003", categoryId: "cat-apparel", hues: [215, 200], weight: 0.8 },
|
|
30
|
-
{ id: "p-04", name: "Wool Beanie", slug: "wool-beanie", description: "A double-layer merino wool beanie. Warm without itch, with a low-profile cuffed fit.", price: 79.9, inventoryCount: 0, sku: "WBN-004", categoryId: "cat-apparel", hues: [0, 350], weight: 0.1 },
|
|
31
|
-
// --- Bags & Accessories ---
|
|
32
|
-
{ id: "p-05", name: "Canvas Tote Bag", slug: "canvas-tote-bag", description: "An everyday carryall in 16oz waxed canvas with reinforced straps and an interior zip pocket.", price: 39.9, inventoryCount: 30, sku: "BAG-001", categoryId: "cat-bags", hues: [80, 110], weight: 0.3 },
|
|
33
|
-
{ id: "p-06", name: "Leather Backpack", slug: "leather-backpack", description: 'Full-grain leather backpack with a padded 15" laptop sleeve, magnetic closures and brass hardware.', price: 549.9, inventoryCount: 8, sku: "LBP-006", categoryId: "cat-bags", hues: [25, 15], weight: 1.4 },
|
|
34
|
-
{ id: "p-07", name: "Leather Card Wallet", slug: "leather-card-wallet", description: "A slim six-card wallet in vegetable-tanned leather. RFID-shielded with a center cash slot.", price: 89.9, compareAtPrice: 119.9, inventoryCount: 45, sku: "LCW-007", categoryId: "cat-bags", hues: [30, 45], weight: 0.08 },
|
|
35
|
-
{ id: "p-08", name: "Travel Duffel", slug: "travel-duffel", description: "A 40L weekender in ballistic nylon with a trolley sleeve, shoe compartment and detachable strap.", price: 329.9, inventoryCount: 15, sku: "TDF-008", categoryId: "cat-bags", hues: [150, 170], weight: 1.1 },
|
|
36
|
-
// --- Home & Kitchen ---
|
|
37
|
-
{ id: "p-09", name: "Ceramic Coffee Mug", slug: "ceramic-coffee-mug", description: "A 350ml stoneware mug with a matte glaze and comfortable wide handle. Dishwasher and microwave safe.", price: 34.9, inventoryCount: 0, sku: "MUG-001", categoryId: "cat-home", hues: [190, 210], weight: 0.4 },
|
|
38
|
-
{ id: "p-10", name: "Scented Soy Candle", slug: "scented-soy-candle", description: "Hand-poured soy wax candle with cedar and bergamot notes. 45-hour burn time in a reusable glass jar.", price: 69.9, inventoryCount: 60, sku: "SSC-010", categoryId: "cat-home", hues: [45, 30], weight: 0.5 },
|
|
39
|
-
{ id: "p-11", name: "Bamboo Cutting Board", slug: "bamboo-cutting-board", description: "An end-grain bamboo board that is gentle on knives, with a juice groove and inset handles.", price: 119.9, inventoryCount: 22, sku: "BCB-011", categoryId: "cat-home", hues: [90, 70], weight: 1.2 },
|
|
40
|
-
{ id: "p-12", name: "Stoneware Plate Set", slug: "stoneware-plate-set", description: "A set of four reactive-glaze dinner plates. Each piece is unique, oven-safe to 220\xB0C.", price: 249.9, inventoryCount: 10, sku: "SPS-012", categoryId: "cat-home", hues: [200, 180], weight: 2.4 },
|
|
41
|
-
// --- Stationery & Tech ---
|
|
42
|
-
{ id: "p-13", name: "Wireless Headphones", slug: "wireless-headphones", description: "Over-ear headphones with active noise cancelling, 40-hour battery and multipoint Bluetooth 5.3.", price: 899.9, inventoryCount: 18, sku: "WHP-013", categoryId: "cat-tech", hues: [260, 280], weight: 0.35 },
|
|
43
|
-
{ id: "p-14", name: "Notebook Set", slug: "notebook-set", description: "Three A5 dot-grid notebooks with 120gsm paper, lay-flat binding and numbered pages.", price: 29.9, inventoryCount: 80, sku: "NBS-014", categoryId: "cat-tech", hues: [330, 310], weight: 0.45 },
|
|
44
|
-
{ id: "p-15", name: "Bluetooth Speaker", slug: "bluetooth-speaker", description: "A pocket-size speaker with surprising low end, IPX7 waterproofing and 14-hour playtime.", price: 199.9, compareAtPrice: 259.9, inventoryCount: 26, sku: "BTS-015", categoryId: "cat-tech", hues: [170, 190], weight: 0.3 },
|
|
45
|
-
{ id: "p-16", name: "Felt Desk Mat", slug: "felt-desk-mat", description: "A 80x30cm merino felt desk mat with a cork base. Protects the desk and quiets the keyboard.", price: 99.9, inventoryCount: 34, sku: "FDM-016", categoryId: "cat-tech", hues: [220, 230], weight: 0.6 }
|
|
46
|
-
];
|
|
47
|
-
var CATEGORY_NAME = Object.fromEntries(
|
|
48
|
-
MOCK_CATEGORIES.map((c) => [c.id, c.name])
|
|
49
|
-
);
|
|
50
|
-
var MOCK_PRODUCTS = SEEDS.map((s, i) => ({
|
|
51
|
-
id: s.id,
|
|
52
|
-
tenantId: "mock",
|
|
53
|
-
name: s.name,
|
|
54
|
-
slug: s.slug,
|
|
55
|
-
description: s.description,
|
|
56
|
-
price: s.price,
|
|
57
|
-
compareAtPrice: s.compareAtPrice ?? null,
|
|
58
|
-
currency: "BRL",
|
|
59
|
-
status: "active",
|
|
60
|
-
inventoryCount: s.inventoryCount,
|
|
61
|
-
sku: s.sku,
|
|
62
|
-
sortOrder: i,
|
|
63
|
-
metadata: {},
|
|
64
|
-
images: [image(s.id, s.name, s.hues[0], s.hues[1])],
|
|
65
|
-
categoryId: s.categoryId,
|
|
66
|
-
categoryName: CATEGORY_NAME[s.categoryId] ?? null,
|
|
67
|
-
isPhysical: true,
|
|
68
|
-
weight: s.weight,
|
|
69
|
-
weightUnit: "kg",
|
|
70
|
-
// staggered timestamps → deterministic 'newest' sort (p-16 newest)
|
|
71
|
-
createdAt: `2026-01-${String(i + 1).padStart(2, "0")}T12:00:00.000Z`,
|
|
72
|
-
updatedAt: `2026-01-${String(i + 1).padStart(2, "0")}T12:00:00.000Z`
|
|
73
|
-
}));
|
|
74
|
-
var MOCK_DISCOUNTS = [
|
|
75
|
-
{
|
|
76
|
-
id: "disc-welcome",
|
|
77
|
-
tenantId: "mock",
|
|
78
|
-
title: "Welcome 10%",
|
|
79
|
-
code: "BEMVINDO10",
|
|
80
|
-
type: "percentage",
|
|
81
|
-
method: "code",
|
|
82
|
-
value: 10,
|
|
83
|
-
usageLimit: null,
|
|
84
|
-
oncePerCustomer: false,
|
|
85
|
-
minSubtotal: null,
|
|
86
|
-
appliesTo: "all",
|
|
87
|
-
productIds: [],
|
|
88
|
-
categoryIds: [],
|
|
89
|
-
startsAt: T0,
|
|
90
|
-
endsAt: null,
|
|
91
|
-
status: "active",
|
|
92
|
-
timesUsed: 0,
|
|
93
|
-
createdAt: T0,
|
|
94
|
-
updatedAt: T0
|
|
95
|
-
}
|
|
96
|
-
];
|
|
97
|
-
|
|
98
|
-
// src/mock-provider.ts
|
|
99
|
-
function uid() {
|
|
100
|
-
return Math.random().toString(36).slice(2);
|
|
101
|
-
}
|
|
102
|
-
function now() {
|
|
103
|
-
return (/* @__PURE__ */ new Date()).toISOString();
|
|
104
|
-
}
|
|
105
|
-
var ORDERS_KEY = "fayz.shop.mock.orders.v1";
|
|
106
|
-
var CUSTOMERS_KEY = "fayz.shop.mock.customers.v1";
|
|
107
|
-
var ENQUIRIES_KEY = "fayz.shop.mock.enquiries.v1";
|
|
108
|
-
var CHANNELS_KEY = "fayz.shop.mock.channels.v1";
|
|
109
|
-
var DEFAULT_CHANNELS = [
|
|
110
|
-
{ id: "online-store", tenantId: "mock", kind: "online_store", label: "Loja Online", url: null, enabled: true, position: 0, createdAt: now(), updatedAt: now() }
|
|
111
|
-
];
|
|
112
|
-
function loadStored(key) {
|
|
113
|
-
try {
|
|
114
|
-
if (typeof localStorage === "undefined") return [];
|
|
115
|
-
const raw = localStorage.getItem(key);
|
|
116
|
-
return raw ? JSON.parse(raw) : [];
|
|
117
|
-
} catch {
|
|
118
|
-
return [];
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
function store(key, value) {
|
|
122
|
-
try {
|
|
123
|
-
if (typeof localStorage === "undefined") return;
|
|
124
|
-
localStorage.setItem(key, JSON.stringify(value));
|
|
125
|
-
} catch {
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
var MockShopProvider = class {
|
|
129
|
-
constructor(seed) {
|
|
130
|
-
this.orders = loadStored(ORDERS_KEY);
|
|
131
|
-
this.customers = loadStored(CUSTOMERS_KEY);
|
|
132
|
-
this.enquiries = loadStored(ENQUIRIES_KEY);
|
|
133
|
-
this.channels = (() => {
|
|
134
|
-
const stored = loadStored(CHANNELS_KEY);
|
|
135
|
-
return stored.length ? stored : DEFAULT_CHANNELS.map((c) => ({ ...c }));
|
|
136
|
-
})();
|
|
137
|
-
this.products = (seed?.products ?? MOCK_PRODUCTS).map((p) => ({ ...p }));
|
|
138
|
-
this.categories = (seed?.categories ?? MOCK_CATEGORIES).map((c) => ({ ...c }));
|
|
139
|
-
this.discounts = (seed?.discounts ?? MOCK_DISCOUNTS).map((d) => ({ ...d }));
|
|
140
|
-
}
|
|
141
|
-
// Re-read before mutating: HMR can re-instantiate the provider mid-session
|
|
142
|
-
// and a stale in-memory copy must not clobber persisted records.
|
|
143
|
-
syncOrders() {
|
|
144
|
-
this.orders = loadStored(ORDERS_KEY);
|
|
145
|
-
}
|
|
146
|
-
syncCustomers() {
|
|
147
|
-
this.customers = loadStored(CUSTOMERS_KEY);
|
|
148
|
-
}
|
|
149
|
-
syncEnquiries() {
|
|
150
|
-
this.enquiries = loadStored(ENQUIRIES_KEY);
|
|
151
|
-
}
|
|
152
|
-
syncChannels() {
|
|
153
|
-
const stored = loadStored(CHANNELS_KEY);
|
|
154
|
-
if (stored.length) this.channels = stored;
|
|
155
|
-
}
|
|
156
|
-
persistOrders() {
|
|
157
|
-
store(ORDERS_KEY, this.orders);
|
|
158
|
-
}
|
|
159
|
-
persistCustomers() {
|
|
160
|
-
store(CUSTOMERS_KEY, this.customers);
|
|
161
|
-
}
|
|
162
|
-
persistEnquiries() {
|
|
163
|
-
store(ENQUIRIES_KEY, this.enquiries);
|
|
164
|
-
}
|
|
165
|
-
persistChannels() {
|
|
166
|
-
store(CHANNELS_KEY, this.channels);
|
|
167
|
-
}
|
|
168
|
-
// ---------------------------------------------------------------------------
|
|
169
|
-
// Products
|
|
170
|
-
// ---------------------------------------------------------------------------
|
|
171
|
-
async listProducts(opts) {
|
|
172
|
-
let list = [...this.products];
|
|
173
|
-
if (opts?.status) list = list.filter((p) => p.status === opts.status);
|
|
174
|
-
if (opts?.categoryId) list = list.filter((p) => p.categoryId === opts.categoryId);
|
|
175
|
-
if (opts?.slug) list = list.filter((p) => p.slug === opts.slug);
|
|
176
|
-
if (opts?.search) {
|
|
177
|
-
const q = opts.search.toLowerCase();
|
|
178
|
-
list = list.filter(
|
|
179
|
-
(p) => p.name.toLowerCase().includes(q) || (p.description ?? "").toLowerCase().includes(q) || (p.sku ?? "").toLowerCase().includes(q)
|
|
180
|
-
);
|
|
181
|
-
}
|
|
182
|
-
const orderBy = opts?.orderBy ?? "sort_order";
|
|
183
|
-
const dir = opts?.order === "desc" ? -1 : 1;
|
|
184
|
-
list.sort((a, b) => {
|
|
185
|
-
switch (orderBy) {
|
|
186
|
-
case "name":
|
|
187
|
-
return a.name.localeCompare(b.name) * dir;
|
|
188
|
-
case "price":
|
|
189
|
-
return (a.price - b.price) * dir;
|
|
190
|
-
case "created_at":
|
|
191
|
-
return a.createdAt.localeCompare(b.createdAt) * dir;
|
|
192
|
-
default:
|
|
193
|
-
return (a.sortOrder - b.sortOrder) * dir;
|
|
194
|
-
}
|
|
195
|
-
});
|
|
196
|
-
const offset = opts?.offset ?? 0;
|
|
197
|
-
if (offset || opts?.limit) list = list.slice(offset, opts?.limit ? offset + opts.limit : void 0);
|
|
198
|
-
return list;
|
|
199
|
-
}
|
|
200
|
-
async getProduct(id) {
|
|
201
|
-
return this.products.find((p) => p.id === id) ?? null;
|
|
202
|
-
}
|
|
203
|
-
async createProduct(input) {
|
|
204
|
-
const p = { id: uid(), tenantId: "mock", name: input.name, slug: input.slug ?? input.name.toLowerCase().replace(/\s+/g, "-"), description: input.description ?? null, price: input.price, compareAtPrice: input.compareAtPrice ?? null, currency: input.currency ?? "BRL", status: input.status ?? "active", inventoryCount: input.inventoryCount ?? 0, sku: input.sku ?? null, sortOrder: input.sortOrder ?? 0, metadata: input.metadata ?? {}, images: [], categoryId: input.categoryId ?? null, categoryName: null, isPhysical: input.isPhysical ?? true, weight: input.weight ?? null, weightUnit: input.weightUnit ?? "kg", createdAt: now(), updatedAt: now() };
|
|
205
|
-
this.products.push(p);
|
|
206
|
-
return p;
|
|
207
|
-
}
|
|
208
|
-
async updateProduct(id, input) {
|
|
209
|
-
const i = this.products.findIndex((p) => p.id === id);
|
|
210
|
-
if (i < 0) throw new Error("Product not found");
|
|
211
|
-
this.products[i] = { ...this.products[i], ...input, updatedAt: now() };
|
|
212
|
-
return this.products[i];
|
|
213
|
-
}
|
|
214
|
-
async deleteProduct(id) {
|
|
215
|
-
this.products = this.products.filter((p) => p.id !== id);
|
|
216
|
-
}
|
|
217
|
-
async uploadProductImage(_productId, _file) {
|
|
218
|
-
throw new Error("Image upload not available in mock mode");
|
|
219
|
-
}
|
|
220
|
-
async deleteProductImage(_imageId) {
|
|
221
|
-
}
|
|
222
|
-
async createProductEnquiry(input) {
|
|
223
|
-
this.syncEnquiries();
|
|
224
|
-
const ts = now();
|
|
225
|
-
const enquiry = {
|
|
226
|
-
id: uid(),
|
|
227
|
-
tenantId: "mock",
|
|
228
|
-
productId: input.productId ?? null,
|
|
229
|
-
productName: input.productName,
|
|
230
|
-
productSlug: input.productSlug ?? null,
|
|
231
|
-
customerName: input.customerName,
|
|
232
|
-
customerEmail: input.customerEmail,
|
|
233
|
-
customerPhone: input.customerPhone ?? null,
|
|
234
|
-
subject: input.subject ?? null,
|
|
235
|
-
message: input.message,
|
|
236
|
-
sourceUrl: input.sourceUrl ?? null,
|
|
237
|
-
status: "new",
|
|
238
|
-
metadata: input.metadata ?? {},
|
|
239
|
-
createdAt: ts,
|
|
240
|
-
updatedAt: ts
|
|
241
|
-
};
|
|
242
|
-
this.enquiries.unshift(enquiry);
|
|
243
|
-
this.persistEnquiries();
|
|
244
|
-
return enquiry;
|
|
245
|
-
}
|
|
246
|
-
async listProductEnquiries(opts) {
|
|
247
|
-
this.syncEnquiries();
|
|
248
|
-
let list = [...this.enquiries];
|
|
249
|
-
if (opts?.productId) list = list.filter((e) => e.productId === opts.productId);
|
|
250
|
-
if (opts?.customerEmail) {
|
|
251
|
-
const email = opts.customerEmail.toLowerCase();
|
|
252
|
-
list = list.filter((e) => e.customerEmail.toLowerCase() === email);
|
|
253
|
-
}
|
|
254
|
-
if (opts?.status) list = list.filter((e) => e.status === opts.status);
|
|
255
|
-
list.sort((a, b) => b.createdAt.localeCompare(a.createdAt));
|
|
256
|
-
const offset = opts?.offset ?? 0;
|
|
257
|
-
if (offset || opts?.limit) list = list.slice(offset, opts?.limit ? offset + opts.limit : void 0);
|
|
258
|
-
return list;
|
|
259
|
-
}
|
|
260
|
-
// ---------------------------------------------------------------------------
|
|
261
|
-
// Categories
|
|
262
|
-
// ---------------------------------------------------------------------------
|
|
263
|
-
async listCategories() {
|
|
264
|
-
return [...this.categories].sort((a, b) => a.sortOrder - b.sortOrder);
|
|
265
|
-
}
|
|
266
|
-
async createCategory(input) {
|
|
267
|
-
const c = { id: uid(), tenantId: "mock", name: input.name, slug: input.slug ?? input.name.toLowerCase().replace(/\s+/g, "-"), description: input.description ?? null, parentId: input.parentId ?? null, sortOrder: input.sortOrder ?? 0, createdAt: now() };
|
|
268
|
-
this.categories.push(c);
|
|
269
|
-
return c;
|
|
270
|
-
}
|
|
271
|
-
async updateCategory(id, input) {
|
|
272
|
-
const i = this.categories.findIndex((c) => c.id === id);
|
|
273
|
-
if (i < 0) throw new Error("Category not found");
|
|
274
|
-
this.categories[i] = { ...this.categories[i], ...input };
|
|
275
|
-
return this.categories[i];
|
|
276
|
-
}
|
|
277
|
-
async deleteCategory(id) {
|
|
278
|
-
this.categories = this.categories.filter((c) => c.id !== id);
|
|
279
|
-
}
|
|
280
|
-
// ---------------------------------------------------------------------------
|
|
281
|
-
// Orders
|
|
282
|
-
// ---------------------------------------------------------------------------
|
|
283
|
-
async listOrders(opts) {
|
|
284
|
-
this.syncOrders();
|
|
285
|
-
let list = [...this.orders];
|
|
286
|
-
if (opts?.status) list = list.filter((o) => o.status === opts.status);
|
|
287
|
-
if (opts?.financialStatus) list = list.filter((o) => o.financialStatus === opts.financialStatus);
|
|
288
|
-
if (opts?.fulfillmentStatus) list = list.filter((o) => o.fulfillmentStatus === opts.fulfillmentStatus);
|
|
289
|
-
if (opts?.customerId) list = list.filter((o) => o.customerId === opts.customerId);
|
|
290
|
-
if (opts?.customerEmail) {
|
|
291
|
-
const email = opts.customerEmail.toLowerCase();
|
|
292
|
-
list = list.filter((o) => (o.customerEmail ?? "").toLowerCase() === email);
|
|
293
|
-
}
|
|
294
|
-
if (opts?.search) {
|
|
295
|
-
const q = opts.search.toLowerCase();
|
|
296
|
-
list = list.filter(
|
|
297
|
-
(o) => (o.customerName ?? "").toLowerCase().includes(q) || (o.customerEmail ?? "").toLowerCase().includes(q) || String(o.orderNumber).includes(q)
|
|
298
|
-
);
|
|
299
|
-
}
|
|
300
|
-
list.sort((a, b) => b.createdAt.localeCompare(a.createdAt));
|
|
301
|
-
if (opts?.limit) list = list.slice(0, opts.limit);
|
|
302
|
-
return list;
|
|
303
|
-
}
|
|
304
|
-
async getOrder(id) {
|
|
305
|
-
this.syncOrders();
|
|
306
|
-
return this.orders.find((o) => o.id === id) ?? null;
|
|
307
|
-
}
|
|
308
|
-
async createOrder(input) {
|
|
309
|
-
this.syncOrders();
|
|
310
|
-
const subtotal = input.items.reduce((s, i) => s + i.quantity * i.unitPrice, 0);
|
|
311
|
-
const discountTotal = input.discountTotal ?? 0;
|
|
312
|
-
const shippingTotal = input.shippingTotal ?? 0;
|
|
313
|
-
const total = Math.round((subtotal - discountTotal + shippingTotal) * 100) / 100;
|
|
314
|
-
const orderId = uid();
|
|
315
|
-
const maxNumber = this.orders.reduce((m, o2) => Math.max(m, o2.orderNumber), 1e3);
|
|
316
|
-
const o = {
|
|
317
|
-
id: orderId,
|
|
318
|
-
tenantId: "mock",
|
|
319
|
-
orderNumber: maxNumber + 1,
|
|
320
|
-
status: "open",
|
|
321
|
-
financialStatus: "pending",
|
|
322
|
-
fulfillmentStatus: "unfulfilled",
|
|
323
|
-
currency: input.currency ?? "BRL",
|
|
324
|
-
subtotal: Math.round(subtotal * 100) / 100,
|
|
325
|
-
taxTotal: 0,
|
|
326
|
-
discountTotal,
|
|
327
|
-
shippingTotal,
|
|
328
|
-
total,
|
|
329
|
-
customerId: input.customerId ?? null,
|
|
330
|
-
customerName: input.customerName ?? null,
|
|
331
|
-
customerEmail: input.customerEmail ?? null,
|
|
332
|
-
discountCode: input.discountCode ?? null,
|
|
333
|
-
notes: input.notes ?? null,
|
|
334
|
-
shippingAddress: null,
|
|
335
|
-
// CreateOrderInput has no payment method — that is a PlaceOrderInput
|
|
336
|
-
// concern; the mock records none rather than inventing one.
|
|
337
|
-
paymentMethodKind: null,
|
|
338
|
-
paidAt: null,
|
|
339
|
-
items: input.items.map((i) => ({ id: uid(), orderId, productId: i.productId ?? null, name: i.name, sku: i.sku ?? null, quantity: i.quantity, unitPrice: i.unitPrice, total: Math.round(i.quantity * i.unitPrice * 100) / 100, imageUrl: i.imageUrl ?? null })),
|
|
340
|
-
createdAt: now(),
|
|
341
|
-
updatedAt: now()
|
|
342
|
-
};
|
|
343
|
-
this.orders.push(o);
|
|
344
|
-
this.persistOrders();
|
|
345
|
-
return o;
|
|
346
|
-
}
|
|
347
|
-
async updateOrder(id, input) {
|
|
348
|
-
this.syncOrders();
|
|
349
|
-
const i = this.orders.findIndex((o) => o.id === id);
|
|
350
|
-
if (i < 0) throw new Error("Order not found");
|
|
351
|
-
this.orders[i] = { ...this.orders[i], ...input, updatedAt: now() };
|
|
352
|
-
this.persistOrders();
|
|
353
|
-
return this.orders[i];
|
|
354
|
-
}
|
|
355
|
-
// Trusted placement (mock parity with the shop_place_order RPC): re-reads
|
|
356
|
-
// prices + stock from the catalog, validates the discount, decrements
|
|
357
|
-
// inventory. The browser-supplied prices are never used.
|
|
358
|
-
async placeOrder(input) {
|
|
359
|
-
this.syncOrders();
|
|
360
|
-
this.syncCustomers();
|
|
361
|
-
let customerId = input.customerId ?? null;
|
|
362
|
-
let customerName = input.customer?.name?.trim() || null;
|
|
363
|
-
const email = input.customer?.email?.trim().toLowerCase() || null;
|
|
364
|
-
if (!customerId && email) {
|
|
365
|
-
const existing = this.customers.find((c) => (c.email ?? "").toLowerCase() === email);
|
|
366
|
-
if (existing) {
|
|
367
|
-
customerId = existing.id;
|
|
368
|
-
customerName = customerName ?? `${existing.firstName} ${existing.lastName}`.trim();
|
|
369
|
-
} else {
|
|
370
|
-
const [first, ...rest] = (customerName ?? email).split(" ");
|
|
371
|
-
const created = await this.createCustomer({ firstName: first || email, lastName: rest.join(" "), email });
|
|
372
|
-
customerId = created.id;
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
const items = [];
|
|
376
|
-
const lineDetails = [];
|
|
377
|
-
let subtotal = 0;
|
|
378
|
-
for (const line of input.items) {
|
|
379
|
-
const product = this.products.find((p) => p.id === line.productId);
|
|
380
|
-
if (!product || product.status !== "active") throw new Error(`Product unavailable: ${line.productId}`);
|
|
381
|
-
if (product.inventoryCount < line.quantity) throw new Error(`Insufficient stock for ${product.name}`);
|
|
382
|
-
const name = line.optionsLabel ? `${product.name} (${line.optionsLabel})` : product.name;
|
|
383
|
-
const lineTotal = product.price * line.quantity;
|
|
384
|
-
subtotal += lineTotal;
|
|
385
|
-
lineDetails.push({ productId: product.id, categoryId: product.categoryId, lineTotal });
|
|
386
|
-
items.push({ productId: product.id, name, sku: product.sku ?? void 0, quantity: line.quantity, unitPrice: product.price, imageUrl: product.images[0]?.url });
|
|
387
|
-
}
|
|
388
|
-
subtotal = Math.round(subtotal * 100) / 100;
|
|
389
|
-
let shippingTotal = Math.max(input.shippingTotal ?? 0, 0);
|
|
390
|
-
let discountTotal = 0;
|
|
391
|
-
let appliedCode = null;
|
|
392
|
-
if (input.discountCode) {
|
|
393
|
-
const code = input.discountCode.trim().toLowerCase();
|
|
394
|
-
const d = this.discounts.find((x) => (x.code ?? "").toLowerCase() === code);
|
|
395
|
-
const ts = now();
|
|
396
|
-
const meetsMin = !d?.minSubtotal || subtotal >= d.minSubtotal;
|
|
397
|
-
const valid = !!d && d.status === "active" && d.startsAt <= ts && (!d.endsAt || d.endsAt >= ts) && (d.usageLimit == null || d.timesUsed < d.usageLimit) && meetsMin;
|
|
398
|
-
if (valid && d) {
|
|
399
|
-
appliedCode = d.code;
|
|
400
|
-
let eligible = subtotal;
|
|
401
|
-
if (d.appliesTo === "products") {
|
|
402
|
-
eligible = lineDetails.filter((l) => d.productIds.includes(l.productId)).reduce((s, l) => s + l.lineTotal, 0);
|
|
403
|
-
} else if (d.appliesTo === "categories") {
|
|
404
|
-
eligible = lineDetails.filter((l) => l.categoryId && d.categoryIds.includes(l.categoryId)).reduce((s, l) => s + l.lineTotal, 0);
|
|
405
|
-
}
|
|
406
|
-
eligible = Math.round(eligible * 100) / 100;
|
|
407
|
-
if (d.type === "percentage") discountTotal = Math.round(eligible * d.value) / 100;
|
|
408
|
-
else if (d.type === "fixed_amount") discountTotal = Math.min(d.value, eligible);
|
|
409
|
-
else if (d.type === "free_shipping") shippingTotal = 0;
|
|
410
|
-
d.timesUsed += 1;
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
discountTotal = Math.round(Math.min(Math.max(discountTotal, 0), subtotal) * 100) / 100;
|
|
414
|
-
const order = await this.createOrder({
|
|
415
|
-
customerId: customerId ?? void 0,
|
|
416
|
-
customerName: customerName ?? void 0,
|
|
417
|
-
customerEmail: input.customer?.email ?? void 0,
|
|
418
|
-
currency: input.currency,
|
|
419
|
-
notes: input.notes,
|
|
420
|
-
discountCode: appliedCode ?? void 0,
|
|
421
|
-
discountTotal,
|
|
422
|
-
shippingTotal,
|
|
423
|
-
items
|
|
424
|
-
});
|
|
425
|
-
for (const line of input.items) {
|
|
426
|
-
const product = this.products.find((p) => p.id === line.productId);
|
|
427
|
-
if (product) product.inventoryCount = Math.max(0, product.inventoryCount - line.quantity);
|
|
428
|
-
}
|
|
429
|
-
return order;
|
|
430
|
-
}
|
|
431
|
-
// ---------------------------------------------------------------------------
|
|
432
|
-
// Customers
|
|
433
|
-
// ---------------------------------------------------------------------------
|
|
434
|
-
async listCustomers(opts) {
|
|
435
|
-
this.syncCustomers();
|
|
436
|
-
let list = [...this.customers];
|
|
437
|
-
if (opts?.search) list = list.filter((c) => `${c.firstName} ${c.lastName} ${c.email}`.toLowerCase().includes(opts.search.toLowerCase()));
|
|
438
|
-
if (opts?.limit) list = list.slice(0, opts.limit);
|
|
439
|
-
return list;
|
|
440
|
-
}
|
|
441
|
-
async getCustomer(id) {
|
|
442
|
-
this.syncCustomers();
|
|
443
|
-
return this.customers.find((c) => c.id === id) ?? null;
|
|
444
|
-
}
|
|
445
|
-
async createCustomer(input) {
|
|
446
|
-
this.syncCustomers();
|
|
447
|
-
const c = { id: uid(), tenantId: "mock", firstName: input.firstName, lastName: input.lastName ?? "", email: input.email ?? null, phone: input.phone ?? null, notes: input.notes ?? null, ordersCount: 0, totalSpent: 0, createdAt: now(), updatedAt: now() };
|
|
448
|
-
this.customers.push(c);
|
|
449
|
-
this.persistCustomers();
|
|
450
|
-
return c;
|
|
451
|
-
}
|
|
452
|
-
async updateCustomer(id, input) {
|
|
453
|
-
this.syncCustomers();
|
|
454
|
-
const i = this.customers.findIndex((c) => c.id === id);
|
|
455
|
-
if (i < 0) throw new Error("Customer not found");
|
|
456
|
-
this.customers[i] = { ...this.customers[i], ...input, updatedAt: now() };
|
|
457
|
-
this.persistCustomers();
|
|
458
|
-
return this.customers[i];
|
|
459
|
-
}
|
|
460
|
-
async deleteCustomer(id) {
|
|
461
|
-
this.syncCustomers();
|
|
462
|
-
this.customers = this.customers.filter((c) => c.id !== id);
|
|
463
|
-
this.persistCustomers();
|
|
464
|
-
}
|
|
465
|
-
async resolveCustomer(input) {
|
|
466
|
-
this.syncCustomers();
|
|
467
|
-
const email = input.email.trim().toLowerCase();
|
|
468
|
-
const existing = this.customers.find((c) => (c.email ?? "").toLowerCase() === email);
|
|
469
|
-
if (existing) return existing;
|
|
470
|
-
const [first, ...rest] = (input.name?.trim() || email).split(/\s+/);
|
|
471
|
-
return this.createCustomer({ firstName: first || email, lastName: rest.join(" "), email });
|
|
472
|
-
}
|
|
473
|
-
// ---------------------------------------------------------------------------
|
|
474
|
-
// Discounts
|
|
475
|
-
// ---------------------------------------------------------------------------
|
|
476
|
-
async listDiscounts(opts) {
|
|
477
|
-
let list = [...this.discounts];
|
|
478
|
-
if (opts?.status) list = list.filter((d) => d.status === opts.status);
|
|
479
|
-
if (opts?.type) list = list.filter((d) => d.type === opts.type);
|
|
480
|
-
if (opts?.search) list = list.filter((d) => d.title.toLowerCase().includes(opts.search.toLowerCase()));
|
|
481
|
-
if (opts?.limit) list = list.slice(0, opts.limit);
|
|
482
|
-
return list;
|
|
483
|
-
}
|
|
484
|
-
async getDiscount(id) {
|
|
485
|
-
return this.discounts.find((d) => d.id === id) ?? null;
|
|
486
|
-
}
|
|
487
|
-
async createDiscount(input) {
|
|
488
|
-
const d = { id: uid(), tenantId: "mock", title: input.title, code: input.code ?? null, type: input.type, method: input.method ?? "code", value: input.value, usageLimit: input.usageLimit ?? null, oncePerCustomer: input.oncePerCustomer ?? false, minSubtotal: input.minSubtotal ?? null, appliesTo: input.appliesTo ?? "all", productIds: input.productIds ?? [], categoryIds: input.categoryIds ?? [], startsAt: input.startsAt ?? now(), endsAt: input.endsAt ?? null, status: input.status ?? "active", timesUsed: 0, createdAt: now(), updatedAt: now() };
|
|
489
|
-
this.discounts.push(d);
|
|
490
|
-
return d;
|
|
491
|
-
}
|
|
492
|
-
async updateDiscount(id, input) {
|
|
493
|
-
const i = this.discounts.findIndex((d) => d.id === id);
|
|
494
|
-
if (i < 0) throw new Error("Discount not found");
|
|
495
|
-
this.discounts[i] = { ...this.discounts[i], ...input, updatedAt: now() };
|
|
496
|
-
return this.discounts[i];
|
|
497
|
-
}
|
|
498
|
-
async deleteDiscount(id) {
|
|
499
|
-
this.discounts = this.discounts.filter((d) => d.id !== id);
|
|
500
|
-
}
|
|
501
|
-
// ---------------------------------------------------------------------------
|
|
502
|
-
// Sales channels
|
|
503
|
-
// ---------------------------------------------------------------------------
|
|
504
|
-
async listSalesChannels() {
|
|
505
|
-
this.syncChannels();
|
|
506
|
-
return [...this.channels].sort((a, b) => a.position - b.position);
|
|
507
|
-
}
|
|
508
|
-
async createSalesChannel(input) {
|
|
509
|
-
this.syncChannels();
|
|
510
|
-
const c = { id: uid(), tenantId: "mock", kind: input.kind, label: input.label, url: input.url ?? null, enabled: input.enabled ?? true, position: input.position ?? this.channels.length, createdAt: now(), updatedAt: now() };
|
|
511
|
-
this.channels.push(c);
|
|
512
|
-
this.persistChannels();
|
|
513
|
-
return c;
|
|
514
|
-
}
|
|
515
|
-
async updateSalesChannel(id, input) {
|
|
516
|
-
this.syncChannels();
|
|
517
|
-
const i = this.channels.findIndex((c) => c.id === id);
|
|
518
|
-
if (i < 0) throw new Error("Sales channel not found");
|
|
519
|
-
this.channels[i] = { ...this.channels[i], ...input, updatedAt: now() };
|
|
520
|
-
this.persistChannels();
|
|
521
|
-
return this.channels[i];
|
|
522
|
-
}
|
|
523
|
-
async deleteSalesChannel(id) {
|
|
524
|
-
this.syncChannels();
|
|
525
|
-
this.channels = this.channels.filter((c) => c.id !== id);
|
|
526
|
-
this.persistChannels();
|
|
527
|
-
}
|
|
528
|
-
};
|
|
529
|
-
function createMockShopProvider(seed) {
|
|
530
|
-
return new MockShopProvider(seed);
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
export { MockShopProvider, createMockShopProvider };
|
|
1
|
+
export { MockShopProvider, createMockShopProvider } from './chunk-SVTCJ6HP.js';
|
|
2
|
+
import './chunk-CTKZ6O2J.js';
|
|
534
3
|
//# sourceMappingURL=mock.js.map
|
|
535
4
|
//# sourceMappingURL=mock.js.map
|