@o2vend/theme-cli 1.0.35 → 1.0.37

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.
@@ -305,6 +305,55 @@ class WidgetService {
305
305
  }
306
306
  }
307
307
 
308
+ /**
309
+ * Get widgets for a specific page and section.
310
+ * Matches production API: POST /pages/{pageId}/sections/{section}/widgets
311
+ * @param {string} pageId - Page ID (home, product, category, products, categories, brand, checkout)
312
+ * @param {string} section - Section name (header, hero, content, footer)
313
+ * @returns {Promise<Array>} Array of normalized widgets sorted by Position
314
+ */
315
+ async getPageSectionWidgets(pageId, section) {
316
+ try {
317
+ if (!this.apiClient) return [];
318
+
319
+ const response = await this.apiClient.post(`/pages/${pageId}/sections/${section}/widgets`, { status: 'active' });
320
+ const widgets = Array.isArray(response) ? response : (response.widgets || []);
321
+ return this.normalizeWidgetArray(widgets);
322
+ } catch (error) {
323
+ console.warn(`[WidgetService] Error fetching widgets for page=${pageId} section=${section}:`, error.message);
324
+ return [];
325
+ }
326
+ }
327
+
328
+ /**
329
+ * Fetch all widgets for a page, organized by section.
330
+ * Mirrors the production fetchPageWidgets() helper.
331
+ * @param {string} pageId - Page ID
332
+ * @returns {Promise<Object>} Widgets organized by section { header:[], hero:[], content:[], footer:[] }
333
+ */
334
+ async fetchPageWidgets(pageId) {
335
+ const validPageIds = ['home', 'product', 'category', 'products', 'categories', 'brand', 'checkout'];
336
+ if (!pageId || !validPageIds.includes(pageId)) {
337
+ console.warn(`[WidgetService] Invalid pageId: ${pageId}, returning empty widgets`);
338
+ return { header: [], hero: [], content: [], footer: [] };
339
+ }
340
+
341
+ const sections = ['header', 'hero', 'content', 'footer'];
342
+ const results = await Promise.allSettled(
343
+ sections.map(section => this.getPageSectionWidgets(pageId, section))
344
+ );
345
+
346
+ const organized = {};
347
+ sections.forEach((section, index) => {
348
+ const result = results[index];
349
+ organized[section] = (result.status === 'fulfilled' && Array.isArray(result.value)) ? result.value : [];
350
+ });
351
+
352
+ const counts = sections.map(s => `${s}:${organized[s].length}`).join(', ');
353
+ console.log(`[WidgetService] fetchPageWidgets(${pageId}): ${counts}`);
354
+ return organized;
355
+ }
356
+
308
357
  /**
309
358
  * Check if widget template exists in theme
310
359
  * @param {string} widgetType - Widget type
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@o2vend/theme-cli",
3
- "version": "1.0.35",
3
+ "version": "1.0.37",
4
4
  "description": "O2VEND Theme Development CLI - Standalone tool for local theme development",
5
5
  "bin": {
6
6
  "o2vend": "./bin/o2vend"
@@ -46,7 +46,7 @@
46
46
  "table": "^6.8.3"
47
47
  },
48
48
  "engines": {
49
- "node": ">=18.0.0"
49
+ "node": ">=24.0.0"
50
50
  },
51
51
  "files": [
52
52
  "bin/**/*",