@wix/agent-skills 1.18.1 → 1.19.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.
Files changed (74) hide show
  1. package/package.json +1 -1
  2. package/skills/wix-app/SKILL.md +13 -13
  3. package/skills/wix-app/references/APP_VALIDATION.md +7 -33
  4. package/skills/wix-app/references/BACKEND_API.md +151 -152
  5. package/skills/wix-app/references/DASHBOARD_PAGE.md +18 -14
  6. package/skills/wix-app/references/EDITOR_REACT_COMPONENT.md +6 -3
  7. package/skills/wix-app/references/EXTENSION_REGISTRATION.md +12 -8
  8. package/skills/wix-app/references/WIX_PATTERNS_DOCS.md +23 -26
  9. package/skills/wix-app/references/dashboard-page/COLLECTION_TOOLKIT.md +7 -6
  10. package/skills/wix-app/references/dashboard-page/ENTITY_PAGE_TOOLKIT.md +71 -4
  11. package/skills/wix-app/references/dashboard-page/PATTERNS_BUNDLE_READING.md +67 -7
  12. package/skills/wix-app/references/editor-react-component/ACCESSIBILITY.md +1 -1
  13. package/skills/wix-app/references/editor-react-component/ANIMATED-COMPONENTS.md +9 -6
  14. package/skills/wix-app/references/editor-react-component/COMPONENT-CONTRACT.md +59 -89
  15. package/skills/wix-app/references/editor-react-component/COMPONENT-PREVIEW.md +23 -4
  16. package/skills/wix-base44-connector/SKILL.md +168 -48
  17. package/skills/wix-base44-connector/scripts/{utils.js → utils.cjs} +69 -48
  18. package/skills/wix-docs/SKILL.md +109 -111
  19. package/skills/wix-docs/references/API_SPEC_SEARCH.md +35 -23
  20. package/skills/wix-docs/references/CALLING.md +91 -0
  21. package/skills/wix-docs/references/EXTRACTING.md +5 -3
  22. package/skills/wix-headless/references/DOC_DISCOVERY.md +9 -3
  23. package/skills/wix-manage/SKILL.md +8 -2
  24. package/skills/wix-manage/references/bookings/booking-service-policy-setup.md +59 -33
  25. package/skills/wix-manage/references/bookings/bookings-staff-setup.md +45 -22
  26. package/skills/wix-manage/references/bookings/multi-resource-service-creation.md +70 -12
  27. package/skills/wix-manage/references/calendar/configure-default-business-hours.md +53 -17
  28. package/skills/wix-manage/references/seo/manage-content-plan.md +247 -0
  29. package/skills/wix-manage/references/seo/manage-seo-tags.md +59 -6
  30. package/skills/wix-manage/references/stores/change-store-currency.md +10 -0
  31. package/skills/wix-manage/references/stores/create-product-catalog-v3.md +17 -1
  32. package/skills/wix-manage/references/stores/update-product-with-options.md +9 -0
  33. package/skills/wix-vibe-headless/SKILL.md +17 -18
  34. package/skills/wix-vibe-headless/install/pin-agents-md.cjs +1 -1
  35. package/skills/wix-vibe-headless/platforms/base44-ecom-light-seed-with-install.md +119 -0
  36. package/skills/wix-vibe-headless/platforms/base44-ecom-light-seed.md +61 -67
  37. package/skills/wix-vibe-headless/platforms/base44-ecom-light.md +31 -29
  38. package/skills/wix-vibe-headless/platforms/base44.md +18 -7
  39. package/skills/wix-vibe-headless/platforms/generic.md +13 -12
  40. package/skills/wix-vibe-headless/references/blog/INSTRUCTIONS.md +4 -13
  41. package/skills/wix-vibe-headless/references/blog/seed/SEED.md +4 -8
  42. package/skills/wix-vibe-headless/references/blog/seed/{seed-blog.js → seed-blog.cjs} +2 -3
  43. package/skills/wix-vibe-headless/references/bookings/INSTRUCTIONS.md +5 -14
  44. package/skills/wix-vibe-headless/references/bookings/seed/SEED.md +5 -9
  45. package/skills/wix-vibe-headless/references/bookings/seed/{seed-bookings.js → seed-bookings.cjs} +2 -2
  46. package/skills/wix-vibe-headless/references/bookings/seed/{seed-rentals.js → seed-rentals.cjs} +3 -3
  47. package/skills/wix-vibe-headless/references/cms/INSTRUCTIONS.md +1 -1
  48. package/skills/wix-vibe-headless/references/cms/seed/SEED.md +2 -2
  49. package/skills/wix-vibe-headless/references/events/INSTRUCTIONS.md +4 -13
  50. package/skills/wix-vibe-headless/references/events/seed/SEED.md +3 -7
  51. package/skills/wix-vibe-headless/references/events/seed/{seed-events.js → seed-events.cjs} +2 -2
  52. package/skills/wix-vibe-headless/references/forms/INSTRUCTIONS.md +2 -1
  53. package/skills/wix-vibe-headless/references/forms/seed/SEED.md +1 -1
  54. package/skills/wix-vibe-headless/references/members/INSTRUCTIONS.md +4 -13
  55. package/skills/wix-vibe-headless/references/members/seed/SEED.md +2 -3
  56. package/skills/wix-vibe-headless/references/portfolio/INSTRUCTIONS.md +4 -13
  57. package/skills/wix-vibe-headless/references/portfolio/app/components/ProjectMedia.jsx +1 -1
  58. package/skills/wix-vibe-headless/references/portfolio/seed/SEED.md +3 -7
  59. package/skills/wix-vibe-headless/references/portfolio/seed/{seed-portfolio.js → seed-portfolio.cjs} +2 -2
  60. package/skills/wix-vibe-headless/references/pricing-plans/INSTRUCTIONS.md +5 -14
  61. package/skills/wix-vibe-headless/references/pricing-plans/app/components/OrderCard.jsx +1 -1
  62. package/skills/wix-vibe-headless/references/pricing-plans/seed/SEED.md +3 -7
  63. package/skills/wix-vibe-headless/references/pricing-plans/seed/{seed-pricing-plans.js → seed-pricing-plans.cjs} +2 -2
  64. package/skills/wix-vibe-headless/references/restaurants/INSTRUCTIONS.md +5 -15
  65. package/skills/wix-vibe-headless/references/restaurants/seed/SEED.md +3 -7
  66. package/skills/wix-vibe-headless/references/restaurants/seed/{seed-restaurants.js → seed-restaurants.cjs} +2 -2
  67. package/skills/wix-vibe-headless/references/storefront/INSTRUCTIONS.md +363 -327
  68. package/skills/wix-vibe-headless/references/storefront/app/context/CartContext.jsx +1 -0
  69. package/skills/wix-vibe-headless/references/storefront/app/hooks/useProductDetail.js +2 -2
  70. package/skills/wix-vibe-headless/references/storefront/app/hooks/useShop.js +63 -78
  71. package/skills/wix-vibe-headless/references/storefront/app/rest/wix-store-catalog.js +59 -43
  72. package/skills/wix-vibe-headless/references/storefront/seed/SEED.md +51 -14
  73. package/skills/wix-vibe-headless/references/storefront/seed/{seed-store.js → seed-store.cjs} +194 -28
  74. 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 = [[]];
@@ -185,7 +257,8 @@ async function uploadDigitalFile(ctx, url, fileName) {
185
257
  if (!mimeType) throw new Error(`digitalFileName needs one of these extensions (${Object.keys(FILE_MIME).join(", ")}): ${fileName}`);
186
258
  const { uploadUrl } = await req(ctx, "/site-media/v1/files/generate-upload-url", { body: { mimeType, fileName } });
187
259
  const src = await fetch(url);
188
- if (!src.ok) throw new Error(`digitalFileUrl ${url} -> ${src.status}`);
260
+ if (!src.ok) throw new Error(`digitalFileUrl ${url} -> ${src.status}. A digital product needs a real, ` +
261
+ `fetchable file — with none at hand, seed this product as physical with inStock: true and tell the user.`);
189
262
  const res = await fetch(uploadUrl, {
190
263
  method: "PUT", headers: { "Content-Type": mimeType }, body: Buffer.from(await src.arrayBuffer()),
191
264
  });
@@ -201,9 +274,10 @@ const digitalFileName = (p) =>
201
274
  // ---- exported operations ----
202
275
 
203
276
  async function installStoresApp(ctx) {
277
+ const siteId = getSiteId(); // Fail before the install-error catch if config is missing.
204
278
  try {
205
- await req(ctx, "/apps-installer-service/v1/app-instance/install", { body: {
206
- tenant: { tenantType: "SITE", id: ctx.siteId },
279
+ await req(ctx, "/apps-installer-service/v1/app-instance/install", { headers: { "wix-site-id": siteId }, body: {
280
+ tenant: { tenantType: "SITE", id: siteId },
207
281
  appInstance: { appDefId: STORES_APP_ID, enabled: true },
208
282
  } });
209
283
  } catch {
@@ -220,7 +294,7 @@ async function listProducts(ctx) {
220
294
 
221
295
  /**
222
296
  * Bulk-create products.
223
- * @param products [{ name, description, price, compareAtPrice?, quantity,
297
+ * @param products [{ name, description, price, compareAtPrice?, quantity?, inStock?,
224
298
  * options?: [{ name, type?:"text"|"color", choices:["8","9"] | [{name,colorCode}] }],
225
299
  * digitalFileUrl?, digitalFileName? }]
226
300
  * digitalFileUrl: makes the product a DIGITAL download — the file is uploaded and the variant
@@ -229,10 +303,12 @@ async function listProducts(ctx) {
229
303
  * Wix rich text here, so the storefront renders paragraphs and bold rather than tag text.
230
304
  * options = ONLY things the buyer selects-and-buys (Size, Color) -> become variants.
231
305
  * 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.
306
+ * visible/physicalProperties/variant-expansion handled here. `quantity` tracks 0–99999 units (default 0); `inStock` selects availability without a count.
307
+ * Supply only one. Each variant inherits that stock mode. Downloads default to inStock:true.
233
308
  * @returns [{ id, slug, revision }]
234
309
  */
235
310
  async function bulkCreateProducts(ctx, products) {
311
+ validateProducts(products);
236
312
  const fileIds = await Promise.all(products.map((p) =>
237
313
  p.digitalFileUrl ? uploadDigitalFile(ctx, p.digitalFileUrl, digitalFileName(p)) : null));
238
314
  const body = {
@@ -251,13 +327,39 @@ async function bulkCreateProducts(ctx, products) {
251
327
  };
252
328
  const r = await req(ctx, "/stores/v3/bulk/products-with-inventory/create", { body });
253
329
  // 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
- }));
330
+ const results = r.productResults?.results ?? [];
331
+ const created = [];
332
+ const failures = [];
333
+ const seen = new Set();
334
+ for (const [position, result] of results.entries()) {
335
+ const index = result.itemMetadata?.originalIndex ?? position;
336
+ seen.add(index);
337
+ if (result.itemMetadata?.success === false || !result.item?.id) {
338
+ failures.push({ index, name: products[index]?.name, ...result.itemMetadata?.error,
339
+ message: result.itemMetadata?.error?.description ?? "Create result has no product ID" });
340
+ continue;
341
+ }
342
+ created.push({
343
+ id: result.item.id, slug: result.item.slug, revision: result.item.revision,
344
+ variantId: result.item.variantsInfo?.variants?.[0]?.id,
345
+ hasOptions: (products[index]?.options?.length ?? 0) > 0,
346
+ isDigital: !!fileIds[index], inventory: inventoryFor(products[index]),
347
+ index, name: products[index]?.name,
348
+ });
349
+ }
350
+ products.forEach((product, index) => {
351
+ if (!seen.has(index)) failures.push({ index, name: product.name, message: "Missing bulk-create result; creation status unknown" });
352
+ });
353
+ if (failures.length) {
354
+ const successes = created.map(({ id, name, index }) => ({ id, name, index }));
355
+ const error = new Error(`Product creation did not fully succeed. ` +
356
+ `Created: ${JSON.stringify(successes)}. Failures: ${JSON.stringify(failures)}. ` +
357
+ `Stopped before stock, categories, or images. Do not rerun the full seed: existing products would be duplicated.`);
358
+ error.createdProducts = successes;
359
+ error.failures = failures;
360
+ throw error;
361
+ }
362
+ created.sort((a, b) => a.index - b.index);
261
363
  await stockOptionlessProducts(ctx, created);
262
364
  return created.map((p) => ({ id: p.id, slug: p.slug, revision: p.revision }));
263
365
  }
@@ -278,7 +380,7 @@ async function stockOptionlessProducts(ctx, created) {
278
380
  }
279
381
  const inventoryItems = need
280
382
  .filter((p) => p.variantId)
281
- .map((p) => ({ productId: p.id, variantId: p.variantId, quantity: p.quantity }));
383
+ .map((p) => ({ productId: p.id, variantId: p.variantId, ...p.inventory }));
282
384
  if (inventoryItems.length) {
283
385
  await req(ctx, "/stores/v3/bulk/inventory-items/create", { body: { inventoryItems } });
284
386
  }
@@ -315,8 +417,17 @@ async function addProductsToCategories(ctx, mapping) {
315
417
  // caller never manages a revision token — attach any number of times, in any pass. Wix re-hosts the
316
418
  // image from the url server-side; the re-hosted media can take a little while to appear on read-back
317
419
  // (propagation) — that's normal, not a failure, so we don't block on it.
420
+ // Wix imports the image bytes server-side, so an attach needs an absolute, publicly fetchable url.
421
+ const isFetchableImageUrl = (url) => typeof url === "string" && /^https:\/\//.test(url);
422
+
318
423
  async function attachProductImages(ctx, items) {
319
424
  if (!items?.length) return;
425
+ if (items.some((it) => !it.id)) throw new Error("Image attachment requires a product ID for every item; no image request was sent.");
426
+ const unfetchable = items.filter((it) => !isFetchableImageUrl(it.url));
427
+ if (unfetchable.length) throw new Error(
428
+ `Image url(s) for [${unfetchable.map((it) => it.altText || it.id).join(", ")}] are not absolute ` +
429
+ `https:// urls, and Wix copies the image bytes at attach time. Re-call attachProductImages once each ` +
430
+ `image has its final url. No image request was sent; products are unaffected.`);
320
431
  const ids = items.map((it) => it.id);
321
432
  const q = await req(ctx, "/stores/v3/products/query", { body: { query: { filter: { id: { $in: ids } }, paging: { limit: ids.length } } } });
322
433
  const revById = new Map((q.products ?? []).map((p) => [p.id, p.revision]));
@@ -329,21 +440,58 @@ async function attachProductImages(ctx, items) {
329
440
  });
330
441
  }
331
442
 
443
+ // Site-wide payment currency; product amounts are not converted when this changes.
444
+ // https://dev.wix.com/docs/api-reference/business-management/site-properties/skills/change-payment-currency-site-properties.md
445
+ async function configureCurrency(ctx, requested) {
446
+ const result = { requested: requested ?? null, actual: null, status: "unchanged", warnings: [] };
447
+ if (requested !== undefined) {
448
+ try {
449
+ if (typeof requested !== "string" || !/^[A-Z]{3}$/.test(requested))
450
+ throw new Error("currency must be a three-letter uppercase ISO currency code");
451
+ await req(ctx, "/site-properties/v4/properties", {
452
+ method: "PATCH",
453
+ body: { properties: { paymentCurrency: requested }, fields: { paths: ["paymentCurrency"] } },
454
+ });
455
+ result.status = "updated";
456
+ } catch (error) {
457
+ result.status = "failed";
458
+ result.warnings.push(`Currency update failed; seeding continued: ${error.message}`);
459
+ }
460
+ }
461
+ try {
462
+ const snapshot = await req(ctx, "/site-properties/v4/properties", { method: "GET" });
463
+ result.actual = snapshot.properties?.paymentCurrency ?? null;
464
+ if (!result.actual) throw new Error("Site Properties returned no paymentCurrency");
465
+ if (requested !== undefined && result.actual !== requested) {
466
+ result.status = "failed";
467
+ result.warnings.push(`Requested currency ${requested}; site currency is ${result.actual}.`);
468
+ }
469
+ } catch (error) {
470
+ result.status = "failed";
471
+ result.warnings.push(`Currency verification failed; seeding continued: ${error.message}`);
472
+ }
473
+ return result;
474
+ }
475
+
332
476
  /**
333
477
  * ONE-CALL seed: install → create products → categories → attach images, in the correct order,
334
478
  * keeping the created ids in memory (no hand-threading of product ids across exec calls). This is
335
479
  * the DEFAULT path — call it once instead of the individual functions.
336
480
  *
337
481
  * @param plan {{
338
- * products: [{ name, description, price, compareAtPrice?, quantity, options?, imageUrl?, altText?,
482
+ * currency?: string, // requested site payment currency; omitted preserves the current setting
483
+ * products: [{ name, description, price, compareAtPrice?, quantity?, inStock?, options?, imageUrl?, altText?,
339
484
  * digitalFileUrl?, digitalFileName? }],
340
485
  * categories?: { [categoryName]: string[] }, // map of category name -> product NAMES in it
341
486
  * }}
342
- * @returns { products: [{id,slug,revision,name}], categories: [{id,name}], imagesAttached: number }
487
+ * @returns { products: [{id,slug,revision,name}], categories: [{id,name}], imagesAttached: number,
488
+ * imagesSkipped?: string[], note?: string, currency: {requested,actual,status,warnings} }
343
489
  */
344
- async function setupStore(ctx, { products = [], categories = {} } = {}) {
490
+ async function setupStore(ctx, { products = [], categories = {}, currency } = {}) {
491
+ validateProducts(products);
345
492
  await installStoresApp(ctx); // installs if needed AND waits for the V3 catalog to be ready
346
493
 
494
+ const currencyResult = await configureCurrency(ctx, currency);
347
495
  const created = await bulkCreateProducts(ctx, products);
348
496
  const withNames = created.map((p, i) => ({ ...p, name: products[i]?.name }));
349
497
  const idByName = new Map(withNames.map((p) => [p.name, p.id]));
@@ -360,11 +508,29 @@ async function setupStore(ctx, { products = [], categories = {} } = {}) {
360
508
  }
361
509
 
362
510
  const imageItems = withNames
363
- .map((p, i) => ({ id: p.id, url: products[i]?.imageUrl, altText: products[i]?.altText ?? p.slug }))
511
+ .map((p, i) => ({ id: p.id, url: products[i]?.imageUrl, altText: products[i]?.altText ?? p.slug, name: p.name }))
364
512
  .filter((it) => it.url);
365
- if (imageItems.length) await attachProductImages(ctx, imageItems);
513
+ // A url Wix cannot fetch would fail the attach: seed the product imageless and report it,
514
+ // so the caller attaches once the final url exists.
515
+ const readyItems = imageItems.filter((it) => isFetchableImageUrl(it.url));
516
+ const skipped = imageItems.filter((it) => !isFetchableImageUrl(it.url)).map((it) => it.name);
517
+ if (readyItems.length) await attachProductImages(ctx, readyItems);
366
518
 
367
- return { products: withNames, categories: cats, imagesAttached: imageItems.length };
519
+ const withoutImages = withNames.filter((p, i) => !products[i]?.imageUrl).map((p) => p.name);
520
+ return {
521
+ products: withNames, categories: cats, imagesAttached: readyItems.length,
522
+ ...(skipped.length && {
523
+ imagesSkipped: skipped,
524
+ note: "these products' image urls were not absolute https:// urls — attach them with " +
525
+ "attachProductImages once each image has its final url",
526
+ }),
527
+ ...(withoutImages.length && !skipped.length && {
528
+ productsWithoutImages: withoutImages,
529
+ note: "these products were seeded without an image — once their images have final urls, " +
530
+ "attach them with attachProductImages",
531
+ }),
532
+ currency: currencyResult,
533
+ };
368
534
  }
369
535
 
370
536
  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
- }