@marvalt/wadapter 2.3.45 â 2.3.46
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/client/wordpress-client.d.ts.map +1 -1
- package/dist/generators/wordpress/wordpress-generator.d.ts.map +1 -1
- package/dist/generators.cjs +202 -9
- package/dist/generators.cjs.map +1 -1
- package/dist/generators.esm.js +202 -9
- package/dist/generators.esm.js.map +1 -1
- package/dist/index.esm.js +57 -9
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +57 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -294,53 +294,101 @@ class WordPressClient {
|
|
|
294
294
|
* @returns Menu data with hierarchical items
|
|
295
295
|
*/
|
|
296
296
|
async getMenu(menuId) {
|
|
297
|
+
console.log(`đ [WordPressClient] Fetching menu ID ${menuId}...`);
|
|
297
298
|
try {
|
|
298
299
|
// First try the custom endpoint (handles both menu terms and wp_navigation posts)
|
|
299
|
-
|
|
300
|
+
console.log(` â Trying endpoint: /wp-custom/v1/menus/${menuId}`);
|
|
301
|
+
const result = await this.makeRequest(`/wp-custom/v1/menus/${menuId}`);
|
|
302
|
+
console.log(` â
Successfully fetched menu ID ${menuId} as menu term: ${result.name}`);
|
|
303
|
+
return result;
|
|
300
304
|
}
|
|
301
305
|
catch (error) {
|
|
306
|
+
const errorStatus = error.status || (error.response?.status) || 'unknown';
|
|
307
|
+
const errorMessage = error.message || 'Unknown error';
|
|
308
|
+
console.log(` â Menu term fetch failed (status: ${errorStatus}): ${errorMessage}`);
|
|
302
309
|
// If 404, try fetching as wp_navigation post
|
|
303
|
-
if (
|
|
304
|
-
console.log(
|
|
310
|
+
if (errorStatus === 404 || errorMessage?.includes('404')) {
|
|
311
|
+
console.log(` â Menu ID ${menuId} not found as menu term, trying as wp_navigation post...`);
|
|
305
312
|
// Try custom endpoint first
|
|
306
313
|
try {
|
|
314
|
+
console.log(` â Trying navigation post endpoint: /wp-custom/v1/navigation/${menuId}`);
|
|
307
315
|
const navPost = await this.makeRequest(`/wp-custom/v1/navigation/${menuId}`);
|
|
316
|
+
console.log(` â
Navigation post fetched:`, {
|
|
317
|
+
id: navPost.id,
|
|
318
|
+
hasMenu: !!navPost.menu,
|
|
319
|
+
menuTermId: navPost.menu_term_id,
|
|
320
|
+
});
|
|
308
321
|
if (navPost.menu) {
|
|
322
|
+
console.log(` â
Returning menu from navigation post: ${navPost.menu.name}`);
|
|
309
323
|
return navPost.menu;
|
|
310
324
|
}
|
|
311
325
|
// If navigation post has a menu_term_id, fetch that menu
|
|
312
326
|
if (navPost.menu_term_id) {
|
|
313
|
-
|
|
327
|
+
console.log(` â Navigation post has menu_term_id ${navPost.menu_term_id}, fetching menu...`);
|
|
328
|
+
const menu = await this.makeRequest(`/wp-custom/v1/menus/${navPost.menu_term_id}`);
|
|
329
|
+
console.log(` â
Fetched menu from menu_term_id ${navPost.menu_term_id}: ${menu.name}`);
|
|
330
|
+
return menu;
|
|
331
|
+
}
|
|
332
|
+
else {
|
|
333
|
+
console.warn(` â ī¸ Navigation post ${menuId} has no menu_term_id and no menu data`);
|
|
334
|
+
throw new Error(`Navigation post ${menuId} has no menu_term_id and no menu data`);
|
|
314
335
|
}
|
|
315
336
|
}
|
|
316
337
|
catch (navError) {
|
|
338
|
+
const navErrorStatus = navError.status || (navError.response?.status) || 'unknown';
|
|
339
|
+
const navErrorMessage = navError.message || 'Unknown error';
|
|
340
|
+
console.log(` â Navigation post fetch failed (status: ${navErrorStatus}): ${navErrorMessage}`);
|
|
317
341
|
// If custom endpoint fails, try WordPress native REST API (WordPress 6.3+)
|
|
318
|
-
if (
|
|
319
|
-
console.log(
|
|
342
|
+
if (navErrorStatus === 404 || navErrorMessage?.includes('404')) {
|
|
343
|
+
console.log(` â Custom navigation endpoint not found, trying WordPress native REST API...`);
|
|
320
344
|
try {
|
|
345
|
+
console.log(` â Trying WordPress native REST API: /wp/v2/navigation/${menuId}`);
|
|
321
346
|
// WordPress 6.3+ has native REST API for wp_navigation posts
|
|
322
347
|
const navPost = await this.makeRequest(`/wp/v2/navigation/${menuId}`);
|
|
348
|
+
console.log(` â
WordPress native navigation post fetched:`, {
|
|
349
|
+
id: navPost.id,
|
|
350
|
+
title: navPost.title?.rendered,
|
|
351
|
+
hasContent: !!navPost.content?.raw,
|
|
352
|
+
});
|
|
323
353
|
// Parse blocks from content to find menu reference
|
|
324
354
|
// The content.raw contains the block JSON
|
|
325
355
|
if (navPost.content?.raw) {
|
|
326
356
|
try {
|
|
327
357
|
const blocks = JSON.parse(navPost.content.raw);
|
|
358
|
+
console.log(` â Parsed ${Array.isArray(blocks) ? blocks.length : 'unknown'} blocks from navigation post`);
|
|
328
359
|
// Look for menu reference in blocks (this would need to be done server-side)
|
|
329
|
-
// For now,
|
|
360
|
+
// For now, throw error to indicate menu extraction requires server-side processing
|
|
330
361
|
console.log(`âšī¸ Found wp_navigation post ${menuId}, but menu extraction requires server-side processing`);
|
|
362
|
+
throw new Error(`Menu extraction from wp_navigation post ${menuId} requires server-side processing`);
|
|
331
363
|
}
|
|
332
364
|
catch (parseError) {
|
|
333
365
|
console.log(`â ī¸ Could not parse navigation post content`);
|
|
366
|
+
throw new Error(`Could not parse navigation post content for menu ID ${menuId}`);
|
|
334
367
|
}
|
|
335
368
|
}
|
|
369
|
+
else {
|
|
370
|
+
throw new Error(`wp_navigation post ${menuId} has no content to parse`);
|
|
371
|
+
}
|
|
336
372
|
}
|
|
337
373
|
catch (wpError) {
|
|
338
|
-
|
|
374
|
+
const wpErrorStatus = wpError.status || (wpError.response?.status) || 'unknown';
|
|
375
|
+
const wpErrorMessage = wpError.message || 'Unknown error';
|
|
376
|
+
console.error(` â WordPress native REST API also failed (status: ${wpErrorStatus}): ${wpErrorMessage}`);
|
|
377
|
+
console.error(` Full WordPress API error:`, wpError);
|
|
378
|
+
// Re-throw to ensure error is propagated
|
|
379
|
+
throw new Error(`Could not fetch menu ID ${menuId} via any method: ${wpErrorMessage}`);
|
|
339
380
|
}
|
|
340
381
|
}
|
|
382
|
+
else {
|
|
383
|
+
console.error(` â Navigation post fetch failed with non-404 error, re-throwing...`);
|
|
384
|
+
throw navError; // Re-throw navigation error
|
|
385
|
+
}
|
|
341
386
|
}
|
|
342
387
|
}
|
|
343
|
-
|
|
388
|
+
else {
|
|
389
|
+
console.error(` â Menu term fetch failed with non-404 error (status: ${errorStatus}), re-throwing...`);
|
|
390
|
+
throw error; // Re-throw original error
|
|
391
|
+
}
|
|
344
392
|
}
|
|
345
393
|
}
|
|
346
394
|
async getFooter(slug = 'footer', area = 'footer') {
|