PageSourceSearch

https://horizon-management-portal-4107.taskade.app/chunks/woo-stock-sync-Y7JVZZ6R.js

js horizon-management-portal-4107.taskade.app collected 2026-10-03 15:01:13 UTC 4,993 bytes, 2 lines download raw bytes

1var __IMPORT_META_ENV={};var __PROCESS_ENV={NODE_ENV:"production"};
2import"/chunks/chunk-43M3N6VY.js";var P=new Map,x=new Map,$=new Map;var p=null,M=3e3,O=9e4;function E(s,a,n){let r=[];for(let t of s){if(!t.sku||!t.wooProductId)continue;let c=t.sku.trim().toUpperCase(),o=a.find(g=>g.sku&&g.sku.toUpperCase()===c);o||(o=a.filter(d=>d.sku&&c.startsWith(d.sku.toUpperCase()+"-")).sort((d,w)=>w.sku.length-d.sku.length)[0]),o&&(n&&o.wooIds?.[n]===t.wooProductId||!n&&o.wooId&&o.wooId===t.wooProductId||(n&&(o.wooIds||(o.wooIds={}),o.wooIds[n]=t.wooProductId),o.wooId||(o.wooId=t.wooProductId),r.push(o)))}return r}function T(s,a){let n=s.stockAllocation?.find(r=>r.channelId===a);return n?n.percentage:s.stock}function _(s,a){return s.wooIds?.[a]||s.wooId||void 0}function W(s,a){let n=a.filter(r=>r.type==="woocommerce"&&r.status==="active"&&r.wooConfig?.connectionMode==="direct"&&r.wooConfig.consumerKey&&r.wooConfig.consumerSecret&&r.wooConfig.syncStockOutbound!==!1);if(n.length!==0){for(let r of n)_(s,r.id)&&P.set(`${s.id}:${r.id}`,{product:s,wooConfig:r.wooConfig,channelId:r.id});p&&clearTimeout(p),p=setTimeout(b,M)}}async function b(){if(p=null,P.size===0)return;let{isCircuitOpen:s,getCircuitCooldownSecs:a}=await import("/chunks/woo-client-TPDXL4ZA.js");if(s()){let t=(a()+5)*1e3;console.warn(`[woo-stock-sync] \u26A1 Global circuit breaker OPEN \u2014 retrying ${P.size} pushes in ${Math.round(t/1e3)}s`),p||(p=setTimeout(b,t));return}let n=Array.from(P.entries());P.clear();let{updateWooStock:r}=await import("/chunks/woo-client-TPDXL4ZA.js");for(let[t,c]of n){let{product:o,wooConfig:g,channelId:d}=c,w=_(o,d);if(!w)continue;let k=T(o,d),y=x.get(t);if(y!==void 0&&y===k)continue;let m=g.siteUrl||d;try{await r(g,w,k),x.set(t,k),$.delete(t),console.log(`[woo-stock-sync] \u2713 ${o.sku} \u2192 ${m} stock: ${k}`),import("/chunks/dist-XEY5NGMG.js").then(({toast:f})=>{f.success(`Stock sync: ${o.name??o.sku} \u2192 ${k} (${m})`)}).catch(()=>{})}catch(f){let h=f instanceof Error?f.message:String(f);if(/Proxy error.*HTTP 5/i.test(h)||f?.__noRetry||f?.__circuitOpen){let u=n.findIndex(([l])=>l===t),i=u>=0?n.slice(u):[[t,c]];for(let[l,C]of i)P.set(l,C);p||(p=setTimeout(b,O+5e3)),console.warn(`[woo-stock-sync] \u26A1 Proxy DOWN \u2014 ${i.length} pushes re-queued for auto-retry in ~90s.`);break}console.warn(`[woo-stock-sync] \u2717 ${o.sku} \u2192 ${m} stock push failed:`,f);let I=/HTTP 404/i.test(h)||/invalid_id/i.test(h),e=($.get(t)??0)+1;$.set(t,e),I&&o.wooIds?.[d]?(console.warn(`[woo-stock-sync] \u26A0 404 for ${o.sku} (wooId ${o.wooIds[d]}) on ${m} \u2014 failure ${e}. Link preserved (manual removal only).`),import("/chunks/dist-XEY5NGMG.js").then(({toast:u})=>{u.error(`Sync \xE9chou\xE9e: ${o.name??o.sku} \u2192 ${m} \u2014 produit introuvable (404). V\xE9rifiez que l'ID WooCommerce ${o.wooIds?.[d]} existe toujours.`,{duration:8e3})}).catch(()=>{})):import("/chunks/dist-XEY5NGMG.js").then(({toast:u})=>{u.error(`Sync \xE9chou\xE9e: ${o.name??o.sku} \u2192 ${m} \u2014 ${h}`)}).catch(()=>{})}}}function U(s,a,n){for(let r of s){let t=a.find(o=>o.id===r),c=t?.wooId||t?.wooIds&&Object.keys(t.wooIds).length>0;t&&c&&W(t,n)}}async function A(s,a){let n=s.wooConfig;if(!n?.siteUrl||!n.consumerKey||!n.consumerSecret)throw new Error("Configuration WooCommerce incompl\xE8te");let{fetchProducts:r,fetchProductVariations:t}=await import("/chunks/woo-client-TPDXL4ZA.js"),c=[],o=1,g=100;for(;;){let e=await r(n,{page:o,perPage:g});if(c.push(...e),e.length<g||(o++,o>20))break}let d=c.filter(e=>e.type==="variable"),w=[];for(let e of d)try{let u=1;for(;;){let i=await t(n,e.id,{page:u,perPage:100});for(let l of i)l.sku&&w.push({parentId:e.id,sku:l.sku,name:`${e.name} (${l.sku})`});if(i.length<100||(u++,u>5))break}}catch(u){console.warn(`[SKU Match] Failed to fetch variations for ${e.name} (id=${e.id}):`,u)}console.log(`[SKU Match] Fetched ${c.length} products + ${w.length} variations from ${n.siteUrl}`);let k=new Map;for(let e of a)e.sku&&k.set(e.sku.trim().toLowerCase(),e);let y=[],m=new Set,f=0,h=[];function v(e){let u=e.trim().toLowerCase(),i=k.get(u);if(i)return i;let l,C=0;for(let[S,L]of k)u.startsWith(S+"-")&&S.length>C&&(l=L,C=S.length);return l}function I(e,u){if(!e)return;let i=v(e);if(!i){h.push(e);return}if((i.wooIds?.[s.id]||i.wooId)===u){f++;return}
2m.has(i.id)||(i.wooIds||(i.wooIds={}),i.wooIds[s.id]=u,i.wooId||(i.wooId=u),y.push(i),m.add(i.id))}for(let e of c)I(e.sku,String(e.id));for(let e of w)I(e.sku,String(e.parentId));return{linked:y,alreadyLinked:f,noMatch:h,total:c.length+w.length}}function R(s,a){let n=a.trim().toLowerCase(),r=null;for(let t of s)if(Array.isArray(t.items))for(let c of t.items){if(!c.sku||!c.wooProductId)continue;let o=c.sku.trim().toLowerCase();if(o===n)return c.wooProductId;!r&&o.startsWith(n+"-")&&(r=c.wooProductId)}return r}export{T as computeChannelStock,E as linkProductsBySkuIfNeeded,A as matchAllProductsBySku,R as matchSingleProductBySkuFromOrders,U as queueAffectedProducts,W as queueWooStockUpdate};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.