@wix/agent-skills 1.18.0 → 1.18.2

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.
Files changed (76) hide show
  1. package/package.json +1 -1
  2. package/skills/wix-app/SKILL.md +4 -4
  3. package/skills/wix-app/references/APP_VALIDATION.md +7 -33
  4. package/skills/wix-app/references/DASHBOARD_PAGE.md +18 -14
  5. package/skills/wix-app/references/EDITOR_REACT_COMPONENT.md +75 -92
  6. package/skills/wix-app/references/WIX_PATTERNS_DOCS.md +23 -26
  7. package/skills/wix-app/references/dashboard-page/COLLECTION_TOOLKIT.md +7 -6
  8. package/skills/wix-app/references/dashboard-page/ENTITY_PAGE_TOOLKIT.md +71 -4
  9. package/skills/wix-app/references/dashboard-page/PATTERNS_BUNDLE_READING.md +67 -7
  10. package/skills/wix-app/references/editor-react-component/ACCESSIBILITY.md +1 -1
  11. package/skills/wix-app/references/editor-react-component/ANIMATED-COMPONENTS.md +9 -6
  12. package/skills/wix-app/references/editor-react-component/COMPONENT-CONTRACT.md +59 -89
  13. package/skills/wix-app/references/editor-react-component/COMPONENT-PREVIEW.md +23 -4
  14. package/skills/wix-app/references/editor-react-component/CSS-GUIDELINES.md +29 -14
  15. package/skills/wix-base44-connector/SKILL.md +168 -48
  16. package/skills/wix-base44-connector/scripts/{utils.js → utils.cjs} +69 -48
  17. package/skills/wix-docs/SKILL.md +109 -111
  18. package/skills/wix-docs/references/API_SPEC_SEARCH.md +35 -23
  19. package/skills/wix-docs/references/CALLING.md +91 -0
  20. package/skills/wix-docs/references/EXTRACTING.md +5 -3
  21. package/skills/wix-headless/references/DOC_DISCOVERY.md +9 -3
  22. package/skills/wix-headless/references/inline-recipes/setup-forms.md +57 -10
  23. package/skills/wix-manage/SKILL.md +106 -92
  24. package/skills/wix-manage/references/dashboard-navigation/routes.json +12 -52
  25. package/skills/wix-manage/references/ecommerce/shipping/ecom-shipping-api.md +0 -2
  26. package/skills/wix-manage/references/forms/create-form.md +272 -184
  27. package/skills/wix-manage/references/forms/forms-dashboard-navigation.md +13 -10
  28. package/skills/wix-manage/references/forms/update-form.md +122 -0
  29. package/skills/wix-manage/references/media/generate-image-with-ai.md +86 -0
  30. package/skills/wix-manage/references/seo/manage-content-plan.md +247 -0
  31. package/skills/wix-manage/references/seo/manage-seo-tags.md +59 -6
  32. package/skills/wix-manage/references/stores/change-store-currency.md +10 -0
  33. package/skills/wix-manage/references/stores/create-product-catalog-v3.md +16 -1
  34. package/skills/wix-manage/references/stores/update-product-with-options.md +9 -0
  35. package/skills/wix-vibe-headless/SKILL.md +17 -18
  36. package/skills/wix-vibe-headless/install/pin-agents-md.cjs +1 -1
  37. package/skills/wix-vibe-headless/platforms/base44-ecom-light-seed-with-install.md +118 -0
  38. package/skills/wix-vibe-headless/platforms/base44-ecom-light-seed.md +55 -62
  39. package/skills/wix-vibe-headless/platforms/base44-ecom-light.md +31 -29
  40. package/skills/wix-vibe-headless/platforms/base44.md +12 -5
  41. package/skills/wix-vibe-headless/platforms/generic.md +13 -12
  42. package/skills/wix-vibe-headless/references/blog/INSTRUCTIONS.md +4 -13
  43. package/skills/wix-vibe-headless/references/blog/seed/SEED.md +4 -8
  44. package/skills/wix-vibe-headless/references/blog/seed/{seed-blog.js → seed-blog.cjs} +2 -3
  45. package/skills/wix-vibe-headless/references/bookings/INSTRUCTIONS.md +5 -14
  46. package/skills/wix-vibe-headless/references/bookings/seed/SEED.md +5 -9
  47. package/skills/wix-vibe-headless/references/bookings/seed/{seed-bookings.js → seed-bookings.cjs} +2 -2
  48. package/skills/wix-vibe-headless/references/bookings/seed/{seed-rentals.js → seed-rentals.cjs} +3 -3
  49. package/skills/wix-vibe-headless/references/cms/INSTRUCTIONS.md +1 -1
  50. package/skills/wix-vibe-headless/references/cms/seed/SEED.md +2 -2
  51. package/skills/wix-vibe-headless/references/events/INSTRUCTIONS.md +4 -13
  52. package/skills/wix-vibe-headless/references/events/seed/SEED.md +3 -7
  53. package/skills/wix-vibe-headless/references/events/seed/{seed-events.js → seed-events.cjs} +2 -2
  54. package/skills/wix-vibe-headless/references/forms/INSTRUCTIONS.md +24 -7
  55. package/skills/wix-vibe-headless/references/forms/seed/SEED.md +91 -17
  56. package/skills/wix-vibe-headless/references/members/INSTRUCTIONS.md +4 -13
  57. package/skills/wix-vibe-headless/references/members/seed/SEED.md +2 -3
  58. package/skills/wix-vibe-headless/references/portfolio/INSTRUCTIONS.md +4 -13
  59. package/skills/wix-vibe-headless/references/portfolio/app/components/ProjectMedia.jsx +1 -1
  60. package/skills/wix-vibe-headless/references/portfolio/seed/SEED.md +3 -7
  61. package/skills/wix-vibe-headless/references/portfolio/seed/{seed-portfolio.js → seed-portfolio.cjs} +2 -2
  62. package/skills/wix-vibe-headless/references/pricing-plans/INSTRUCTIONS.md +5 -14
  63. package/skills/wix-vibe-headless/references/pricing-plans/app/components/OrderCard.jsx +1 -1
  64. package/skills/wix-vibe-headless/references/pricing-plans/seed/SEED.md +3 -7
  65. package/skills/wix-vibe-headless/references/pricing-plans/seed/{seed-pricing-plans.js → seed-pricing-plans.cjs} +2 -2
  66. package/skills/wix-vibe-headless/references/restaurants/INSTRUCTIONS.md +5 -15
  67. package/skills/wix-vibe-headless/references/restaurants/seed/SEED.md +3 -7
  68. package/skills/wix-vibe-headless/references/restaurants/seed/{seed-restaurants.js → seed-restaurants.cjs} +2 -2
  69. package/skills/wix-vibe-headless/references/storefront/INSTRUCTIONS.md +359 -327
  70. package/skills/wix-vibe-headless/references/storefront/app/context/CartContext.jsx +1 -0
  71. package/skills/wix-vibe-headless/references/storefront/app/hooks/useProductDetail.js +2 -2
  72. package/skills/wix-vibe-headless/references/storefront/app/hooks/useShop.js +63 -78
  73. package/skills/wix-vibe-headless/references/storefront/app/rest/wix-store-catalog.js +59 -43
  74. package/skills/wix-vibe-headless/references/storefront/seed/SEED.md +46 -10
  75. package/skills/wix-vibe-headless/references/storefront/seed/{seed-store.js → seed-store.cjs} +163 -25
  76. package/skills/wix-vibe-headless/references/storefront/app/pages/Shop.jsx +0 -75
@@ -5,22 +5,44 @@
5
5
  //
6
6
  // Usage (build-time exec_tool):
7
7
  // const { accessToken } = await base44.asServiceRole.connectors.getConnection("wix"); // Base44
8
- // const seed = require("/app/.agents/skills/wix-vibe-headless/references/storefront/seed/seed-store.js");
9
- // const ctx = { token: accessToken, siteId: WIX_METASITE_ID };
8
+ // const seed = require("/app/.agents/skills/wix-vibe-headless/references/storefront/seed/seed-store.cjs");
9
+ // const ctx = { token: accessToken }; // Installation reads the site ID from the deployed Wix config.
10
10
  // await seed.installStoresApp(ctx);
11
11
  // const products = await seed.bulkCreateProducts(ctx, [{ name, description, price, quantity, options? }]);
12
12
  // const cats = await seed.createCategories(ctx, ["Legends", "Rising Stars"]);
13
13
  // await seed.addProductsToCategories(ctx, { [cats[0].id]: products.map(p => p.id) });
14
14
  // await seed.attachProductImages(ctx, products.map((p,i) => ({ id:p.id, url:imageUrls[i], altText:p.slug })));
15
15
  //
16
- // If any call fails with a shape the caller didn't expect, fall back to the wix-docs skill
16
+ // If any call fails with a shape the caller didn't expect, fall back to the documentation skill available in your environment
17
17
  // (search + read the live Wix API reference) — never guess. Source recipe (authoritative):
18
18
  // wix-headless/references/inline-recipes/setup-online-store.md.
19
19
 
20
20
  const API = "https://www.wixapis.com";
21
21
  const STORES_APP_ID = "215238eb-22a5-4c36-9e7b-e7c08025e04e";
22
+ const WIX_CONFIG_PATH = "/app/src/rest/wix-config.js";
23
+ let siteId;
22
24
 
23
- async function req(ctx, path, { method = "POST", body } = {}) {
25
+ function getSiteId() {
26
+ if (siteId) return siteId;
27
+ let source;
28
+ try {
29
+ source = require("fs").readFileSync(WIX_CONFIG_PATH, "utf8");
30
+ } catch {
31
+ throw new Error(`Cannot read ${WIX_CONFIG_PATH}; deploy the Wix config before seeding.`);
32
+ }
33
+ // Base44/deploy writes a named export containing a JSON string literal. Do not execute config.
34
+ const match = source.match(/^export const WIX_METASITE_ID\s*=\s*("(?:[^"\\]|\\.)*")\s*;/m);
35
+ let value;
36
+ try { value = match && JSON.parse(match[1]); } catch { /* invalid config */ }
37
+ if (typeof value !== "string" || !/^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i.test(value)) {
38
+ throw new Error(`Missing or invalid WIX_METASITE_ID in ${WIX_CONFIG_PATH}; deploy the Wix config before seeding.`);
39
+ }
40
+ siteId = value;
41
+ return siteId;
42
+ }
43
+
44
+
45
+ async function req(ctx, path, { method = "POST", body, headers = {} } = {}) {
24
46
  // Retry while the catalog is still provisioning: right after a fresh Stores install the V3 WRITE
25
47
  // path becomes usable a bit later than the V3 read path, so even once waitForCatalogV3 (a read
26
48
  // probe) returns, the first bulk-create can still 428. Wait it out (~80s budget); every other
@@ -30,7 +52,7 @@ async function req(ctx, path, { method = "POST", body } = {}) {
30
52
  method,
31
53
  headers: {
32
54
  Authorization: `Bearer ${ctx.token}`,
33
- "wix-site-id": ctx.siteId,
55
+ ...headers,
34
56
  "Content-Type": "application/json",
35
57
  },
36
58
  body: body ? JSON.stringify(body) : undefined,
@@ -69,7 +91,7 @@ async function waitForCatalogV3(ctx, { attempts = 40, delayMs = 2000 } = {}) {
69
91
  for (let i = 0; i < attempts; i++) {
70
92
  const res = await fetch(`${API}/stores/v3/products/query`, {
71
93
  method: "POST",
72
- headers: { Authorization: `Bearer ${ctx.token}`, "wix-site-id": ctx.siteId, "Content-Type": "application/json" },
94
+ headers: { Authorization: `Bearer ${ctx.token}`, "Content-Type": "application/json" },
73
95
  body: JSON.stringify({ query: { paging: { limit: 1 } } }),
74
96
  });
75
97
  if (res.ok) return;
@@ -148,8 +170,57 @@ function buildOptions(options = []) {
148
170
  });
149
171
  }
150
172
 
173
+ // Validate the whole batch before installation, uploads, or product creation.
174
+ function validateProducts(products) {
175
+ const seen = new Map();
176
+ for (const product of products) {
177
+ if (product.inStock !== undefined && typeof product.inStock !== "boolean") {
178
+ throw new Error(`Product "${product.name}": inStock must be a boolean. No products were created by this call.`);
179
+ }
180
+ if (product.inStock !== undefined && product.quantity !== undefined) {
181
+ throw new Error(`Product "${product.name}": supply either inStock or quantity, not both. No products were created by this call.`);
182
+ }
183
+ if (!product.digitalFileUrl && product.quantity !== undefined &&
184
+ (!Number.isInteger(product.quantity) || product.quantity < 0 || product.quantity > 99999)) {
185
+ throw new Error(`Product "${product.name}": quantity must be an integer from 0 to 99999. ` +
186
+ `For unlimited stock, use inStock: true without quantity. No products were created by this call.`);
187
+ }
188
+ for (const option of product.options ?? []) {
189
+ const choiceNames = new Set();
190
+ for (const choice of option.choices ?? []) {
191
+ const name = typeof choice === "string" ? choice : choice.name;
192
+ const normalized = name.trim().toLowerCase();
193
+ if (choiceNames.has(normalized)) {
194
+ throw new Error(`Duplicate choice "${name}" in option "${option.name}" on product "${product.name}". ` +
195
+ `Each choice name must be unique within an option. No products were created by this call.`);
196
+ }
197
+ choiceNames.add(normalized);
198
+ if (option.type !== "color") continue;
199
+ const key = JSON.stringify([option.name.trim().toLowerCase(), choice.name.trim().toLowerCase()]);
200
+ const code = choice.colorCode?.trim().toLowerCase();
201
+ const previous = seen.get(key);
202
+ if (previous && previous.code !== code) {
203
+ throw new Error(`Conflicting color "${choice.name}" in option "${option.name}": ` +
204
+ `"${previous.product}" uses ${previous.code}, but "${product.name}" uses ${code}. ` +
205
+ `Use one color code for this name across the batch, or distinct names for different shades. No products were created by this call.`);
206
+ }
207
+ seen.set(key, { code, product: product.name });
208
+ }
209
+ }
210
+ }
211
+ }
212
+
213
+ // Choose one inventory tracking mode; downloads retain their default available stock.
214
+ function inventoryFor(product) {
215
+ if (product.inStock !== undefined) return { inStock: product.inStock };
216
+ if (product.digitalFileUrl) return { inStock: true };
217
+ return { quantity: product.quantity ?? 0 };
218
+ }
219
+
151
220
  // full Cartesian product of variants, each priced/stocked from the product; visible:true baked in
152
- function expandVariants(options = [], { price, compareAtPrice, quantity }, digitalFileId) {
221
+ function expandVariants(options = [], product, digitalFileId) {
222
+ const { price, compareAtPrice } = product;
223
+ const inventoryItem = inventoryFor(product);
153
224
  const base = {
154
225
  price: {
155
226
  actualPrice: { amount: String(price) },
@@ -157,8 +228,9 @@ function expandVariants(options = [], { price, compareAtPrice, quantity }, digit
157
228
  },
158
229
  visible: true,
159
230
  ...(digitalFileId
160
- ? { digitalProperties: { digitalFile: { id: digitalFileId } }, inventoryItem: { inStock: true } }
161
- : { physicalProperties: {}, inventoryItem: { quantity: quantity ?? 0, preorderInfo: { enabled: false } } }),
231
+ ? { digitalProperties: { digitalFile: { id: digitalFileId } }, inventoryItem }
232
+ : { physicalProperties: {}, inventoryItem: { ...inventoryItem,
233
+ ...(inventoryItem.quantity !== undefined ? { preorderInfo: { enabled: false } } : {}) } }),
162
234
  };
163
235
  if (!options.length) return [base];
164
236
  let combos = [[]];
@@ -201,9 +273,10 @@ const digitalFileName = (p) =>
201
273
  // ---- exported operations ----
202
274
 
203
275
  async function installStoresApp(ctx) {
276
+ const siteId = getSiteId(); // Fail before the install-error catch if config is missing.
204
277
  try {
205
- await req(ctx, "/apps-installer-service/v1/app-instance/install", { body: {
206
- tenant: { tenantType: "SITE", id: ctx.siteId },
278
+ await req(ctx, "/apps-installer-service/v1/app-instance/install", { headers: { "wix-site-id": siteId }, body: {
279
+ tenant: { tenantType: "SITE", id: siteId },
207
280
  appInstance: { appDefId: STORES_APP_ID, enabled: true },
208
281
  } });
209
282
  } catch {
@@ -220,7 +293,7 @@ async function listProducts(ctx) {
220
293
 
221
294
  /**
222
295
  * Bulk-create products.
223
- * @param products [{ name, description, price, compareAtPrice?, quantity,
296
+ * @param products [{ name, description, price, compareAtPrice?, quantity?, inStock?,
224
297
  * options?: [{ name, type?:"text"|"color", choices:["8","9"] | [{name,colorCode}] }],
225
298
  * digitalFileUrl?, digitalFileName? }]
226
299
  * digitalFileUrl: makes the product a DIGITAL download — the file is uploaded and the variant
@@ -229,10 +302,12 @@ async function listProducts(ctx) {
229
302
  * Wix rich text here, so the storefront renders paragraphs and bold rather than tag text.
230
303
  * options = ONLY things the buyer selects-and-buys (Size, Color) -> become variants.
231
304
  * Display-only attributes go in name/category/description, NOT options. Default: no options.
232
- * visible/physicalProperties/variant-expansion handled here. `quantity` is the stock created.
305
+ * visible/physicalProperties/variant-expansion handled here. `quantity` tracks 0–99999 units (default 0); `inStock` selects availability without a count.
306
+ * Supply only one. Each variant inherits that stock mode. Downloads default to inStock:true.
233
307
  * @returns [{ id, slug, revision }]
234
308
  */
235
309
  async function bulkCreateProducts(ctx, products) {
310
+ validateProducts(products);
236
311
  const fileIds = await Promise.all(products.map((p) =>
237
312
  p.digitalFileUrl ? uploadDigitalFile(ctx, p.digitalFileUrl, digitalFileName(p)) : null));
238
313
  const body = {
@@ -251,13 +326,39 @@ async function bulkCreateProducts(ctx, products) {
251
326
  };
252
327
  const r = await req(ctx, "/stores/v3/bulk/products-with-inventory/create", { body });
253
328
  // NB: results nest under productResults.results[].item — NOT a top-level `results`.
254
- const created = (r.productResults?.results ?? []).map((x, i) => ({
255
- id: x.item?.id, slug: x.item?.slug, revision: x.item?.revision,
256
- variantId: x.item?.variantsInfo?.variants?.[0]?.id,
257
- hasOptions: (products[i]?.options?.length ?? 0) > 0,
258
- isDigital: !!fileIds[i],
259
- quantity: products[i]?.quantity ?? 0,
260
- }));
329
+ const results = r.productResults?.results ?? [];
330
+ const created = [];
331
+ const failures = [];
332
+ const seen = new Set();
333
+ for (const [position, result] of results.entries()) {
334
+ const index = result.itemMetadata?.originalIndex ?? position;
335
+ seen.add(index);
336
+ if (result.itemMetadata?.success === false || !result.item?.id) {
337
+ failures.push({ index, name: products[index]?.name, ...result.itemMetadata?.error,
338
+ message: result.itemMetadata?.error?.description ?? "Create result has no product ID" });
339
+ continue;
340
+ }
341
+ created.push({
342
+ id: result.item.id, slug: result.item.slug, revision: result.item.revision,
343
+ variantId: result.item.variantsInfo?.variants?.[0]?.id,
344
+ hasOptions: (products[index]?.options?.length ?? 0) > 0,
345
+ isDigital: !!fileIds[index], inventory: inventoryFor(products[index]),
346
+ index, name: products[index]?.name,
347
+ });
348
+ }
349
+ products.forEach((product, index) => {
350
+ if (!seen.has(index)) failures.push({ index, name: product.name, message: "Missing bulk-create result; creation status unknown" });
351
+ });
352
+ if (failures.length) {
353
+ const successes = created.map(({ id, name, index }) => ({ id, name, index }));
354
+ const error = new Error(`Product creation did not fully succeed. ` +
355
+ `Created: ${JSON.stringify(successes)}. Failures: ${JSON.stringify(failures)}. ` +
356
+ `Stopped before stock, categories, or images. Do not rerun the full seed: existing products would be duplicated.`);
357
+ error.createdProducts = successes;
358
+ error.failures = failures;
359
+ throw error;
360
+ }
361
+ created.sort((a, b) => a.index - b.index);
261
362
  await stockOptionlessProducts(ctx, created);
262
363
  return created.map((p) => ({ id: p.id, slug: p.slug, revision: p.revision }));
263
364
  }
@@ -278,7 +379,7 @@ async function stockOptionlessProducts(ctx, created) {
278
379
  }
279
380
  const inventoryItems = need
280
381
  .filter((p) => p.variantId)
281
- .map((p) => ({ productId: p.id, variantId: p.variantId, quantity: p.quantity }));
382
+ .map((p) => ({ productId: p.id, variantId: p.variantId, ...p.inventory }));
282
383
  if (inventoryItems.length) {
283
384
  await req(ctx, "/stores/v3/bulk/inventory-items/create", { body: { inventoryItems } });
284
385
  }
@@ -317,6 +418,7 @@ async function addProductsToCategories(ctx, mapping) {
317
418
  // (propagation) — that's normal, not a failure, so we don't block on it.
318
419
  async function attachProductImages(ctx, items) {
319
420
  if (!items?.length) return;
421
+ if (items.some((it) => !it.id)) throw new Error("Image attachment requires a product ID for every item; no image request was sent.");
320
422
  const ids = items.map((it) => it.id);
321
423
  const q = await req(ctx, "/stores/v3/products/query", { body: { query: { filter: { id: { $in: ids } }, paging: { limit: ids.length } } } });
322
424
  const revById = new Map((q.products ?? []).map((p) => [p.id, p.revision]));
@@ -329,21 +431,57 @@ async function attachProductImages(ctx, items) {
329
431
  });
330
432
  }
331
433
 
434
+ // Site-wide payment currency; product amounts are not converted when this changes.
435
+ // https://dev.wix.com/docs/api-reference/business-management/site-properties/skills/change-payment-currency-site-properties.md
436
+ async function configureCurrency(ctx, requested) {
437
+ const result = { requested: requested ?? null, actual: null, status: "unchanged", warnings: [] };
438
+ if (requested !== undefined) {
439
+ try {
440
+ if (typeof requested !== "string" || !/^[A-Z]{3}$/.test(requested))
441
+ throw new Error("currency must be a three-letter uppercase ISO currency code");
442
+ await req(ctx, "/site-properties/v4/properties", {
443
+ method: "PATCH",
444
+ body: { properties: { paymentCurrency: requested }, fields: { paths: ["paymentCurrency"] } },
445
+ });
446
+ result.status = "updated";
447
+ } catch (error) {
448
+ result.status = "failed";
449
+ result.warnings.push(`Currency update failed; seeding continued: ${error.message}`);
450
+ }
451
+ }
452
+ try {
453
+ const snapshot = await req(ctx, "/site-properties/v4/properties", { method: "GET" });
454
+ result.actual = snapshot.properties?.paymentCurrency ?? null;
455
+ if (!result.actual) throw new Error("Site Properties returned no paymentCurrency");
456
+ if (requested !== undefined && result.actual !== requested) {
457
+ result.status = "failed";
458
+ result.warnings.push(`Requested currency ${requested}; site currency is ${result.actual}.`);
459
+ }
460
+ } catch (error) {
461
+ result.status = "failed";
462
+ result.warnings.push(`Currency verification failed; seeding continued: ${error.message}`);
463
+ }
464
+ return result;
465
+ }
466
+
332
467
  /**
333
468
  * ONE-CALL seed: install → create products → categories → attach images, in the correct order,
334
469
  * keeping the created ids in memory (no hand-threading of product ids across exec calls). This is
335
470
  * the DEFAULT path — call it once instead of the individual functions.
336
471
  *
337
472
  * @param plan {{
338
- * products: [{ name, description, price, compareAtPrice?, quantity, options?, imageUrl?, altText?,
473
+ * currency?: string, // requested site payment currency; omitted preserves the current setting
474
+ * products: [{ name, description, price, compareAtPrice?, quantity?, inStock?, options?, imageUrl?, altText?,
339
475
  * digitalFileUrl?, digitalFileName? }],
340
476
  * categories?: { [categoryName]: string[] }, // map of category name -> product NAMES in it
341
477
  * }}
342
- * @returns { products: [{id,slug,revision,name}], categories: [{id,name}], imagesAttached: number }
478
+ * @returns { products: [{id,slug,revision,name}], categories: [{id,name}], imagesAttached: number, currency: {requested,actual,status,warnings} }
343
479
  */
344
- async function setupStore(ctx, { products = [], categories = {} } = {}) {
480
+ async function setupStore(ctx, { products = [], categories = {}, currency } = {}) {
481
+ validateProducts(products);
345
482
  await installStoresApp(ctx); // installs if needed AND waits for the V3 catalog to be ready
346
483
 
484
+ const currencyResult = await configureCurrency(ctx, currency);
347
485
  const created = await bulkCreateProducts(ctx, products);
348
486
  const withNames = created.map((p, i) => ({ ...p, name: products[i]?.name }));
349
487
  const idByName = new Map(withNames.map((p) => [p.name, p.id]));
@@ -364,7 +502,7 @@ async function setupStore(ctx, { products = [], categories = {} } = {}) {
364
502
  .filter((it) => it.url);
365
503
  if (imageItems.length) await attachProductImages(ctx, imageItems);
366
504
 
367
- return { products: withNames, categories: cats, imagesAttached: imageItems.length };
505
+ return { products: withNames, categories: cats, imagesAttached: imageItems.length, currency: currencyResult };
368
506
  }
369
507
 
370
508
  module.exports = {
@@ -1,75 +0,0 @@
1
- // Shop / catalog page — thin view over useShop (all logic lives in the hook). Category menu, sort,
2
- // cursor paging, plus the loading / empty / failed states a seeded-separately catalog needs.
3
- // Styled with base44 design tokens (shadcn Tailwind classes).
4
- import { useShop, SORTS } from "@/hooks/useShop";
5
- import ProductGrid from "@/components/ProductGrid";
6
-
7
- export default function Shop() {
8
- const s = useShop();
9
- const showCategories = s.categories.length > 0;
10
-
11
- return (
12
- <main className="max-w-[1200px] mx-auto p-4">
13
- <div className="flex flex-wrap items-end justify-between gap-3 mb-4">
14
- <h1 className="font-display m-0">{s.activeCategory?.name || "Shop"}</h1>
15
- {s.products?.length > 0 && (
16
- <label className="flex items-center gap-2 text-sm text-muted-foreground">
17
- Sort
18
- <select value={s.sort} onChange={(e) => s.setSort(e.target.value)}
19
- className="py-1.5 px-2 border border-input rounded-sm bg-background text-foreground text-sm">
20
- {Object.entries(SORTS).map(([key, { label }]) => <option key={key} value={key}>{label}</option>)}
21
- </select>
22
- </label>
23
- )}
24
- </div>
25
-
26
- {showCategories && (
27
- <nav aria-label="Categories" className="flex flex-wrap gap-2 mb-6">
28
- <CategoryChip active={!s.activeCategory} onClick={() => s.setActiveCategory(null)}>All</CategoryChip>
29
- {s.categories.map((c) => (
30
- <CategoryChip key={c.id} active={s.activeCategory?.id === c.id} onClick={() => s.setActiveCategory(c)}>
31
- {c.name}
32
- </CategoryChip>
33
- ))}
34
- </nav>
35
- )}
36
-
37
- {s.error ? (
38
- <div role="alert" className="flex flex-col items-center gap-3 py-16 text-center">
39
- <p className="m-0 text-muted-foreground">{s.error}</p>
40
- <button onClick={s.retry}
41
- className="border border-border bg-card text-foreground rounded-sm py-2 px-4 cursor-pointer text-sm">Try again</button>
42
- </div>
43
- ) : (
44
- <>
45
- <ProductGrid
46
- products={s.products}
47
- loading={s.loading}
48
- empty={s.activeCategory ? `Nothing in ${s.activeCategory.name} yet.` : "No products yet."}
49
- emptyHint={s.activeCategory
50
- ? "Pick another category, or add products to this one from your Wix dashboard."
51
- : "Add products in your Wix dashboard and they'll appear here — no redeploy needed."}
52
- />
53
-
54
- {s.hasMore && (
55
- <div className="flex justify-center mt-8">
56
- <button onClick={s.loadMore} disabled={s.loadingMore}
57
- className="border border-border bg-card text-foreground rounded-sm py-2.5 px-6 cursor-pointer text-sm font-semibold disabled:opacity-60 disabled:cursor-wait">
58
- {s.loadingMore ? "Loading…" : "Load more"}
59
- </button>
60
- </div>
61
- )}
62
- </>
63
- )}
64
- </main>
65
- );
66
- }
67
-
68
- function CategoryChip({ active, onClick, children }) {
69
- return (
70
- <button onClick={onClick} aria-pressed={active}
71
- className={`py-1.5 px-3 cursor-pointer text-sm rounded-sm border ${
72
- active ? "border-primary bg-primary text-primary-foreground" : "border-border bg-card text-foreground"
73
- }`}>{children}</button>
74
- );
75
- }