Woo: construir base de API REST de forma idempotente
El operador puede cargar el base_url con o sin /wp-json/wc/v3. El código anterior siempre concatenaba el sufijo, lo que producía URLs duplicadas tipo https://store/wp-json/wc/v3/wp-json/wc/v3/products → 404 (rest_no_route). Nuevo helper buildWooApiBase detecta si la URL ya incluye /wp-json/ y respeta lo que vino. Centraliza la lógica en un solo lugar consumido por los tres clientes Woo (wooSnapshot, wooOrders, woo.js). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import crypto from "crypto";
|
||||
import { getDecryptedTenantEcommerceConfig } from "../db/repo.js";
|
||||
import { debug } from "../../shared/debug.js";
|
||||
import { buildWooApiBase } from "../../shared/wooApiBase.js";
|
||||
|
||||
// --- Simple in-memory lock to serialize work per key (e.g. wa_chat_id) ---
|
||||
const locks = new Map();
|
||||
@@ -172,7 +173,7 @@ export async function createWooCustomer({ tenantId, wa_chat_id, phone, name }) {
|
||||
throw new Error("consumer_secret not set");
|
||||
})();
|
||||
|
||||
const base = `${cfg.base_url.replace(/\/+$/, "")}/wp-json/${cfg.api_version || "wc/v3"}`;
|
||||
const base = buildWooApiBase(cfg.base_url, cfg.api_version);
|
||||
const email = `${phone || wa_chat_id}@no-email.local`;
|
||||
const username = wa_chat_id;
|
||||
const timeout = Math.max(cfg.timeout_ms ?? 20000, 20000);
|
||||
|
||||
Reference in New Issue
Block a user