@soma-vertical-web/multi-lib 0.0.33 → 0.0.34
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/__vite-browser-external-CpdIDx9o.mjs +79 -0
- package/__vite-browser-external-DDWPeg5L.js +1 -0
- package/constants.d.ts +32 -0
- package/contexts/contexts/search/Facets.d.ts +5 -0
- package/contexts/contexts/search/Products.d.ts +5 -0
- package/contexts/contexts/search/Root.d.ts +5 -0
- package/contexts/contexts/search/Search.d.ts +5 -0
- package/contexts/contexts/search/SuggestedTerms.d.ts +5 -0
- package/contexts/contexts/search/TopSearches.d.ts +6 -0
- package/contexts/index.d.ts +24 -0
- package/data/api/search/crosseling/index.d.ts +4 -8
- package/index.js +19 -19
- package/index.mjs +4336 -3979
- package/index2.js +1 -1
- package/index2.mjs +493 -560
- package/package.json +1 -1
- package/types/constants.d.ts +4 -24
- package/types/contexts/contexts/search.d.ts +8 -2
- package/types/layout/team-components/AddToCart/index.d.ts +2 -2
- package/types/layout/team-components/Sort/index.d.ts +2 -3
package/index2.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const re=require("yup"),ne=require("./__vite-browser-external-Cjz79hOw.js"),oe=require("sanitize-html");function ae(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const o=ae(re),l=async(e,t={})=>{const{method:n="GET",body:r,headers:s={},priority:a="auto",cache:i="default"}=t;return fetch(e,{method:n,headers:{...s,Accept:"application/json","Content-Type":"application/json"},priority:a,cache:i,...r?{body:JSON.stringify(r)}:{}}).then(c=>c.json()).catch(c=>{console.error("[ERROR FETCH VTEX]",c)})},O=new Map;async function se(e,t={}){var n;try{const{abort:r=!1}=t,s=new AbortController;r&&(O.has(e)&&((n=O.get(e))==null||n.abort(),O.delete(e)),O.set(e,s));const a=l(e,{...t,...r?{signal:s.signal}:{}});return r&&O.delete(e),a}catch(r){if(r.name==="AbortError"){console.log(`[REQUEST CANCELLED]: ${e}`);return}throw console.error(`[ERROR API]: ${r.message}`),r}}const ie=o.object({country:o.string().length(3,"Country code must be 3 characters long").required("Country is required"),postalCode:o.string().nullable()});async function ce({apiUrl:e,body:t,fetchOptions:n}){if(!t){console.error("[ERROR FETCHING] Body is required");return}await ie.validate(t);const{country:r,postalCode:s}=t;return await l(`${e}/api/checkout/pub/postal-code/${r}/${s}`,{method:"POST",body:t,...n})}const le=o.object({orderFormId:o.string().nullable(),sellerCode:o.string().nullable(),sellerName:o.string().nullable()});async function L({apiUrl:e,body:t,fetchOptions:n}){if(!t){console.error("[ERROR FETCHING] Body is required");return}await le.validate(t);const{orderFormId:r,sellerCode:s,sellerName:a}=t,i=s?`${s.trim()} - ${a}`:null;return l(`${e}/api/checkout/pub/orderForm/${r}/attachments/openTextField`,{method:"POST",body:{value:i},...n})}const ue=o.object({orderFormId:o.string().nullable(),sellerCode:o.string().nullable(),marketingData:o.object()});async function V({apiUrl:e,body:t,fetchOptions:n}){if(!t){console.error("[ERROR FETCHING] Body is required");return}await ue.validate(t);const{orderFormId:r,sellerCode:s,marketingData:a}=t,i=s?{utmCampaign:s?s.toUpperCase():"",utmiCampaign:s?"codigodavendedora":"semcodigo"}:{};return l(`${e}/api/checkout/pub/orderForm/${r}/attachments/marketingData`,{method:"POST",body:{...a,...i},...n})}const de=o.object({orderFormId:o.string().nullable(),sellerCode:o.string().nullable(),sellerName:o.string().nullable()});async function me({apiUrl:e,body:t,fetchOptions:n}){if(!t){console.error("[ERROR FETCHING] Body is required");return}await de.validate(t);const r=await L({apiUrl:e,body:t,fetchOptions:n});return V({apiUrl:e,body:{...t,marketingData:r==null?void 0:r.marketingData},fetchOptions:n})}const pe=o.object({orderFormId:o.string().nullable(),coupon:o.string().nullable()});async function fe({apiUrl:e,body:t,fetchOptions:n}){if(!t){console.error("[ERROR FETCHING] Body is required");return}await pe.validate(t);const{coupon:r="",orderFormId:s}=t;return l(`${e}/api/checkout/pub/orderForm/${s}/coupons`,{method:"POST",body:{text:r},...n})}const ge=o.object({appId:o.string().required("App ID is required"),orderFormId:o.string().nullable(),key:o.array().of(o.string())});async function he({apiUrl:e,body:t,fetchOptions:n}){if(!t){console.error("[ERROR FETCHING] Body is required");return}await ge.validate(t);const{appId:r="faststore",orderFormId:s,key:a}=t;return l(`${e}/api/checkout/pub/orderForm/${s}/customData/${r}/${a}`,{method:"PUT",...n})}const Ie=o.object().shape({name:o.string().required("Attachment name is required"),content:o.object().nullable()});var G;const be=o.object().shape({attachments:(G=o.array().of(Ie))==null?void 0:G.nullable(),id:o.string().required("ID of SKU is required"),index:o.number().integer().nullable(),quantity:o.number().integer().nullable(),seller:o.string().required("Seller is required"),price:o.number().integer()}),ye=o.object({orderFormId:o.string().required("OrderFormId is required"),orderItems:o.array().of(be)});async function Re({apiUrl:e,body:t,fetchOptions:n}){if(!t){console.error("[ERROR FETCHING] Body is required");return}await ye.validate(t);const{orderFormId:r,orderItems:s}=t;return l(`${e}/api/checkout/pub/orderForm/${r}/items`,{method:"POST",body:{orderItems:s},...n})}const Ce=o.object({orderFormId:o.string().nullable()});async function ve({apiUrl:e,body:t,fetchOptions:n}){if(!t){console.error("[ERROR FETCHING] Body is required");return}await Ce.validate(t);const{orderFormId:r}=t;return l(`${e}/api/checkout/pub/orderForm/${r}/items/removeAll`,{method:"POST",...n})}const Oe=o.object().shape({name:o.string().required("Attachment name is required"),content:o.object().nullable()});var U;const Fe=o.object().shape({attachments:(U=o.array().of(Oe))==null?void 0:U.nullable(),id:o.string().required("ID of SKU is required"),index:o.number().integer().nullable(),quantity:o.number().integer().nullable(),seller:o.string().required("Seller is required"),price:o.number().integer()}),Se=o.object({orderFormId:o.string().nullable(),orderItems:o.array().of(Fe)});async function $e({apiUrl:e,body:t,fetchOptions:n}){if(!t){console.error("[ERROR FETCHING] Body is required");return}await Se.validate(t);const{orderFormId:r,orderItems:s}=t;return l(`${e}/api/checkout/pub/orderForm/${r}/items/update`,{method:"POST",body:{orderItems:s},...n})}const Ee=o.object({orderFormId:o.string().nullable()});async function qe({apiUrl:e,body:t,fetchOptions:n}){if(!t){console.error("[ERROR FETCHING] Body is required");return}await Ee.validate(t);const{orderFormId:r}=t;return l(`${e}/api/checkout/pub/orderForm/${r}/messages/clear`,{method:"POST",...n})}const Te=o.object({id:o.string().nullable(),itemIndex:o.number().nullable(),orderFormId:o.string().nullable(),remove:o.boolean().nullable()});async function Ae({apiUrl:e,body:t,fetchOptions:n}){if(!t){console.error("[ERROR FETCHING] Body is required");return}await Te.validate(t);const{itemIndex:r,orderFormId:s,id:a,remove:i}=t,c=i?`/${a}/remove`:"",u=`${e}/api/checkout/pub/orderForm/${s}/items/${r}/offerings${c}`;return l(u,{method:"POST",body:{id:a},...n})}const Pe=o.object({orderFormId:o.string().nullable()});async function je({apiUrl:e,body:t,fetchOptions:n,extraData:r}){var i;if(!t){console.error("[ERROR FETCHING] Body is required");return}await Pe.validate(t);const s=new URLSearchParams({refreshOutdatedData:"true"}),a=t.orderFormId&&((i=r.orderFormPurchaseId)==null?void 0:i.value)!==t.orderFormId?`${e}/api/checkout/pub/orderForm/${t.orderFormId}?${String(s)}`:`${e}/api/checkout/pub/orderForm`;return l(a,{method:"GET",...n})}const ke=o.object({orderFormId:o.string().nullable(),email:o.string().email().required(),firstName:o.string().required(),lastName:o.string().required(),documentType:o.string().required(),document:o.string().required(),phone:o.string().matches(/^\+\d{1,3}\d{10,11}$/)});async function Ne({apiUrl:e,body:t,fetchOptions:n}){if(!t){console.error("[ERROR FETCHING] Body is required");return}await ke.validate(t);const{orderFormId:r,...s}=t;return l(`${e}/api/checkout/pub/orderForm/${r}/attachments/clientProfileData`,{method:"POST",body:{...s},...n})}const we=o.object({sellerCode:o.string().nullable()});async function _e({apiUrl:e,body:t,fetchOptions:n}){if(!t){console.error("[ERROR FETCHING] Body is required");return}await we.validate(t);const{sellerCode:r=""}=t;return l(`${e}/api/dataentities/VD/search?_fields=id,cod,name,ativo&cod=${r}`,{method:"GET",headers:{Accept:"application/vnd.vtex.ds.v10+json"},...n})}const De=o.object().shape({country:o.string().length(3,"Country code must be 3 characters long").required("Country is required"),orderFormId:o.string().nullable(),postalCode:o.string().nullable()});async function Be({apiUrl:e,body:t,fetchOptions:n}){if(!t){console.error("[ERROR FETCHING] Body is required");return}await De.validate(t);const{country:r,orderFormId:s,postalCode:a}=t,i=a?{address:{addressType:"residential",postalCode:a,country:r}}:{logisticsInfo:[],clearAddressIfPostalCodeNotFound:!0};return l(`${e}/api/checkout/pub/orderForm/${s}/attachments/shippingData`,{method:"POST",body:i,...n})}const He=o.object().shape({orderFormId:o.string().nullable(),options:o.array().of(o.object().shape({itemIndex:o.number(),selectedDeliveryChannel:o.string(),selectedSla:o.string()})),selectedAddresses:o.array().of(o.object().shape({addressId:o.string().required(),addressType:o.string().required(),city:o.string().nullable(),complement:o.string().nullable(),country:o.string().required().length(3),geoCoordinates:o.array().of(o.number()).required().min(0),isDisposable:o.boolean().required(),neighborhood:o.string().nullable(),number:o.string().nullable(),postalCode:o.string().required(),receiverName:o.string().nullable(),reference:o.string().nullable(),state:o.string().nullable(),street:o.string().nullable()}))});async function Ge({apiUrl:e,body:t,fetchOptions:n}){if(!t){console.error("[ERROR FETCHING] Body is required");return}await He.validate(t);const{orderFormId:r,options:s,selectedAddresses:a}=t;return l(`${e}/api/checkout/pub/orderForm/${r}/attachments/shippingData`,{method:"POST",body:{selectedAddresses:a,clearAddressIfPostalCodeNotFound:!1,logisticsInfo:s},...n})}const Ue=o.object({country:o.string().length(3,"Country code must be 3 characters long").required("Country is required"),postalCode:o.string().nullable(),geoCoordinates:o.object().shape({longitude:o.number().required(),latitude:o.number().required()})});async function Le({apiUrl:e,body:t,fetchOptions:n}){if(!t){console.error("[ERROR FETCHING] Body is required");return}await Ue.validate(t);const{country:r="",geoCoordinates:s,postalCode:a=""}=t,i=new URLSearchParams({country:String(r)});return a?i.append("postalCode",a):i.append("geoCoordinates",`${s==null?void 0:s.longitude};${s==null?void 0:s.latitude}`),await l(`${e}/api/checkout/pub/regions/?${i.toString()}`,{method:"GET",...n})}const Ve=o.object({id:o.string().required("ID of SKU is required"),quantity:o.number().integer().required("Quantity of item is required"),seller:o.string()}),Me=o.object({items:o.array().of(Ve),country:o.string().length(3,"Country code must be 3 characters long").required("Country is required"),postalCode:o.string().nullable(),geoCoordinates:o.array().nullable().of(o.number()).length(2)});async function ze({apiUrl:e,body:t,fetchOptions:n}){if(!t){console.error("[ERROR FETCHING] Body is required");return}return await Me.validate(t),l(`${e}/api/checkout/pub/orderForms/simulation`,{method:"POST",body:t,...n})}const xe=Object.freeze(Object.defineProperty({__proto__:null,getMasterDataSellerCode:_e,getOrderForm:je,postOrderFormAddCoupon:fe,postOrderFormAttachClientProfileData:Ne,postOrderFormAttachOrderFormData:me,postOrderFormAttachShippingData:Be,postOrderFormAttachmentsMarketingData:V,postOrderFormAttachmentsOpenTextField:L,postOrderFormClearMessages:qe,postOrderFormFreightSimulation:ze,postOrderFormItems:Re,postOrderFormRegion:Le,postOrderFormRemoveAllItems:ve,postOrderFormUpdateItems:$e,postOrderFormUpdateShippingData:Ge,postOrderformAddress:ce,putOrderFormCustomData:he,updateOrderFormOffering:Ae},Symbol.toStringTag,{value:"Module"})),Qe=o.object({skuId:o.string()});async function Ye({apiUrl:e,body:t,fetchOptions:n}){if(!t){console.error("[ERROR FETCHING] Body is required");return}await Qe.validate(t);const{skuId:r}=t;return l(`${e}/api/catalog/pvt/stockkeepingunitkit?parentSkuId=${r}`,{...n})}const Ke=o.object({ids:o.array().of(o.string().required("ID are required")).required("IDs are required")});async function Je({apiUrl:e,body:t,fetchOptions:n}){if(!t){console.error("[ERROR FETCHING] Body is required");return}await Ke.validate(t);const{ids:r}=t;return l(`${e}/api/catalog_system/pub/products/search?fq=${r.map(s=>`productId:${s}`).join("&fq=")}`,{...n})}const Ze=o.object({productId:o.number().required("Product ID is required")});async function Xe({apiUrl:e,body:t,fetchOptions:n}){if(!t){console.error("[ERROR FETCHING] Body is required");return}await Ze.validate(t);const{productId:r}=t;return l(`${e}/api/catalog_system/pub/products/crossselling/similars/${r.toString()}`,{...n})}const We=Object.freeze(Object.defineProperty({__proto__:null,getCatalogKitProducts:Ye,getCatalogProducts:Je,getCatalogSimilars:Xe},Symbol.toStringTag,{value:"Module"})),et=(e="")=>e.charAt(0).toUpperCase()+e.slice(1),w=(e,t=" ")=>!e||typeof e=="string"&&e.length===0?e:(Array.isArray(e)?e:e.split("-")).map(et).join(t),tt=({canonical:e,seo:t,slug:n})=>{const r=Array.isArray(n)?n.join(", "):n;return{id:0,Title:`${Array.isArray(n)?n.map(a=>w(a)).join(","):w(n)} - ${t.title}`,MetaTagDescription:t.description,name:r,hasChildren:!1,url:e,children:[]}},rt=({canonical:e,category:t,previousImages:n,seo:r})=>({category:String(t==null?void 0:t.id),title:(t==null?void 0:t.Title)??r.title,description:(t==null?void 0:t.MetaTagDescription)??r.description,alternates:{canonical:e},openGraph:{type:"website",title:(t==null?void 0:t.Title)??r.title,description:(t==null?void 0:t.MetaTagDescription)??r.description,images:Array.isArray(n)?[...n]:[]}}),nt=({items:e,parent:t,apiUrl:n,find:r})=>{const s=e.find(i=>i.url.replace(n,"")===decodeURIComponent(t.toLowerCase()));return(s==null?void 0:s.children.find(i=>i.name.toLowerCase()===decodeURIComponent(String(r))))??s},ot=e=>{e instanceof Error?(console.error(`[ERROR CATEGORY INFO]: ${e.message}`),console.error(e.stack)):console.error("[ERROR CATEGORY INFO]: Unknown error",e)},at=new Set(["brand","category","department","subcategory","collection","cluster"]),st=e=>typeof(e==null?void 0:e.pageType)=="string"&&at.has(e==null?void 0:e.pageType.toLowerCase()),it=e=>({collection:e.Coleção,categoryId:e.categoryId,current_collection:e["Coleção Atual"],items:e.items}),ct=(e,t)=>e.reduce((n,r)=>{if(r.items.filter(i=>i.sellers.find(c=>c.commertialOffer.IsAvailable)).length===0||(n==null?void 0:n.find(i=>(i==null?void 0:i.productId)===(r==null?void 0:r.productId)))!==void 0)return n;const a=r.items[0].images.find(i=>t.includes(i.imageLabel));return n.push({slug:`/${r.linkText}/p`,productId:r==null?void 0:r.productId,textureImage:(a==null?void 0:a.imageUrl)??"",textureAlt:(a==null?void 0:a.imageText)??""}),n},[]),lt=Object.freeze(Object.defineProperty({__proto__:null,createEmptySeoCategory:tt,createSeoCategory:rt,findCategory:nt,formattedSimilars:ct,isCollectionPageType:st,notFindCategoryError:ot,responseAdapter:it},Symbol.toStringTag,{value:"Module"}));async function ut({contentType:e,storeId:t,CMS_PROJECT_NAME:n,NextCookies:r}){const s=await M({contentType:e,storeId:t,CMS_PROJECT_NAME:n,NextCookies:r});if(s.status===200){const a={timestamp:new Date().toISOString(),contentType:e,data:s.data};console.log("Resultado da chamada:",s);const i=`backup-${e}-${Date.now()}.json`;return await ne.fs.writeFile(`./backups/${i}`,JSON.stringify(a,null,2),"utf-8"),{success:!0,fileName:i}}return{success:!1,error:s.error||"No data to backup"}}async function dt(e){return ut(e)}async function mt({contentType:e,documentId:t,versionId:n,storeId:r,CMS_PROJECT_NAME:s}){const a=t&&t.length?`/${t}`:"",i=n&&n.length?`?versionId=${n}`:"";return fetch(`https://${r}.myvtex.com/_v/cms/api/${s}/${e}${a}${i}`,{cache:"no-cache"})}async function pt({contentType:e,documents:t,NextCookies:n,CMS_PROJECT_NAME:r,storeId:s}){var i;const a=JSON.parse(((i=n().get("cms_preview_data"))==null?void 0:i.value)??"{}");if(a&&(a==null?void 0:a.contentType)===e){const c=a.documentId&&a.documentId.length?`/${a.documentId}`:"",u=a!=null&&a.versionId&&(a!=null&&a.versionId.length)?`?versionId=${a==null?void 0:a.versionId}`:"",m=await(await fetch(`https://${s}.myvtex.com/_v/cms/api/${r}/${e}${c}${u}`,{cache:"no-store"})).json(),d=t.filter(f=>m.id!==f.documentId);return d.unshift(m),d}return t}async function M({contentType:e,NextCookies:t,CMS_PROJECT_NAME:n,storeId:r}){var p,m;const s=JSON.parse(((p=t().get("cms_preview_data"))==null?void 0:p.value)??"{}"),a=[];let i=1,c=0,u=!0;try{do{const f=await(await fetch(`https://${r}.myvtex.com/_v/cms/api/${n}/${e}?page=${i}`)).json();i===1&&(c=f.totalItems),(m=f==null?void 0:f.data)!=null&&m.length&&a.push(...f.data),u=f.hasNextPage,i++}while(u&&a.length<c);if(s.previewMode&&a.length){const d=await pt({contentType:e,documents:a,NextCookies:t,CMS_PROJECT_NAME:n,storeId:r});return{status:d.length>0?200:404,data:d??[]}}return{status:a.length?200:404,data:a}}catch(d){return{status:"error",data:[],error:d}}}const ft=Object.freeze(Object.defineProperty({__proto__:null,cmsBackup:dt,getCMSContentType:mt,getContentType:M},Symbol.toStringTag,{value:"Module"})),gt=o.object({query:o.string()});async function ht({apiUrl:e,body:t,fetchOptions:n}){if(!t){console.error("[ERROR FETCHING] Body is required");return}await gt.validate(t);const{query:r=""}=t,s=new URLSearchParams({query:r});return l(`${e}/api/io/_v/api/intelligent-search/autocomplete_suggestions?${s.toString()}`,{...n})}const It=(e,t)=>oe(e,t),bt=e=>({...e,description:e.description?It(e.description):e.description}),yt=({offer:e,seller:t,product:n})=>({...e,product:n,seller:t}),z=(e,t)=>({...e,isVariantOf:bt(t)}),Rt=e=>e?"https://schema.org/InStock":"https://schema.org/OutOfStock",$=e=>e.AvailableQuantity>0,_=e=>e.spotPrice??0,Ct=e=>e.Price??0,x=(e,t)=>$(e)&&!$(t)?-1:!$(e)&&$(t)?1:_(e)-_(t),vt=(e,t)=>{let n=0;for(let r=1;r<e.length;r++)t(e[n],e[r])>0&&(n=r);return e[n]},Q=e=>{const t=e.flatMap(r=>r.sellers.map(s=>({offer:s.commertialOffer,sku:r}))),n=vt(t,({offer:r},{offer:s})=>x(r,s));return n?n.sku:e[0]},Y=e=>e.map(({imageUrl:t,imageText:n,imageLabel:r})=>({alternateName:n??"",url:t.replace("vteximg.com.br","vtexassets.com"),keywords:r})),E={attachment:"ATTACHMENT",specification:"SPECIFICATION",attribute:"ATTRIBUTE"},Ot=e=>({name:e.name,value:e.content,valueReference:E.attachment}),Ft=e=>({propertyID:e.id,name:e.name,value:e.value,valueReference:{valueReference:E.attribute,visible:e.visible}}),q=(e,t,n)=>{const r=e.flatMap(({name:i,values:c})=>c?c.map(u=>({name:i,value:u,valueReference:E.specification})):{name:i,value:"",valueReference:E.specification}),s=Array.isArray(n)?n.map(Ot):[],a=t?t.map(Ft):[];return[...r,...s,...a]},D="ÁÄÂÀÃÅČÇĆĎÉĚËÈÊẼĔȆÍÌÎÏŇÑÓÖÒÔÕØŘŔŠŤÚŮÜÙÛÝŸŽáäâàãåčçćďéěëèêẽĕȇíìîïňñóöòôõøðřŕšťúůüùûýÿžþÞĐđ߯a",St="AAAAAACCCDEEEEEEEEIIIINNOOOOOORRSTUUUUUYYZaaaaaacccdeeeeeeeeiiiinnooooooorrstuuuuuyyzbBDdBAa",$t=e=>{let t=e.slice(0);for(let n=0;n<D.length;n++)t=t.replace(new RegExp(D.charAt(n),"g"),St.charAt(n));return t},Et=e=>e.replace(/[·/_,:]/,"-"),K=e=>{const n=e.replace(/,/g,"").replace(/[*+~.()'"!:@&\[\]`/ %$#?{}|><=_^]/g,"-");return Et($t(n)).toLowerCase()},J=e=>`/${e}/p`,Z=e=>{const t=Math.max(...e.map(r=>r.NumberOfInstallments)),n=e.find(r=>r.NumberOfInstallments===t);return{count:(n==null?void 0:n.NumberOfInstallments)??0,value:(n==null?void 0:n.Value)??0}},X=(e,t)=>{const n={price:0,listPrice:0,sellerDefault:!1},s=e.map(a=>yt({offer:a.commertialOffer,seller:a,product:t})).sort(x).map(a=>(a.seller.sellerId==="1"&&a.AvailableQuantity>0&&(n.price=a.Price,n.listPrice=a.ListPrice,n.sellerDefault=!0),{availability:a.AvailableQuantity>0,listPrice:a.ListPrice,price:Ct(a),priceValidUntil:a.PriceValidUntil,priceCurrency:"BRL",installments:a.Installments,lowPrice:a.spotPrice,quantity:a.AvailableQuantity,seller:{identifier:a.seller.sellerId}}));return{lowPrice:n.sellerDefault?n.price:s[0].price,highPrice:n.sellerDefault?n.listPrice:s[0].listPrice,offers:s}},W=e=>{const{attributes:t,itemId:n,name:r,sellers:s,variations:a}=e;return{additionalProperty:q(a,t,[]),name:r,offers:{offers:s.map(({sellerId:i,commertialOffer:c})=>({availability:Rt(c.AvailableQuantity>0),listPrice:c.ListPrice,price:c.Price,quantity:c.AvailableQuantity,seller:{identifier:i}}))},sku:n}},qt=e=>{var C;const{attributes:t,referenceId:n,isVariantOf:r,images:s,itemId:a,name:i,sellers:c,videos:u,variations:p}=e,{brand:m,categories:d,categoriesIds:f,description:b,linkText:g,productClusters:T,clusterHighlights:F,productName:S,properties:A,productId:P}=r,j=d.slice().reverse(),y=X(c,e.isVariantOf),k=Z(y.offers[0].installments);return{sku:a,gtin:((C=n[0])==null?void 0:C.Value)??"",name:S??i,description:b,releaseDate:r.releaseDate??"",slug:g,video:u[0],categories:d,categoriesIds:f,id:P,brand:{name:m,brandName:m},seo:{description:b,title:S,canonical:J(g)},cluster:{generals:T,highlights:F},properties:A,availability:{status:y.offers[0].availability},breadcrumbList:{itemListElement:[...j.map((h,v)=>{const I=h.split("/"),R=I[I.length-2],N=I.map(K).join("/");return{name:R,item:N,position:v+1}}),{name:r.productName,item:g,position:d.length+1}],numberOfItems:d.length},image:Y(s),offers:y,additionalProperty:q(p,t,[]),isVariantOf:{productGroupID:r.productId,hasVariant:r.items.map(h=>W(h))},installments:k}},Tt=e=>{var C;const{attributes:t,referenceId:n,isVariantOf:r,images:s,itemId:a,name:i,sellers:c,Videos:u,variations:p}=e,{brand:m,categories:d,categoriesIds:f,description:b,linkText:g,productClusters:T,productName:F,Coleção:S,"ID Coleção":A,productId:P}=r,j=d.slice().reverse(),y=X(c,e.isVariantOf),k=Z(y.offers[0].installments);return{sku:a,gtin:((C=n[0])==null?void 0:C.Value)??"",name:F??i,description:b,releaseDate:r.releaseDate??"",slug:g,video:u[0],categories:d,categoriesIds:f,collection:S,collectionId:A,id:P,brand:{name:m,brandName:m},seo:{description:b,title:F,canonical:J(g)},cluster:{generals:T,highlights:[]},availability:{status:y.offers[0].availability},breadcrumbList:{itemListElement:[...j.map((h,v)=>{const I=h.split("/"),R=I[I.length-2],N=I.map(K).join("/");return{name:R,item:N,position:v+1}}),{name:r.productName,item:g,position:d.length+1}],numberOfItems:d.length},image:Y(s),offers:y,additionalProperty:q(p,t,[]),isVariantOf:{productGroupID:r.productId,hasVariant:r.items.map(h=>{const{variations:v}=h,I=v.map(R=>({name:R,values:h[R]}));return{...W(h),additionalProperty:q(I,t,[])}})},installments:k}},B="fuzzy",H="operator",At=e=>({isDepartment:e!=null&&e.length?e[0].key==="category-1":!1}),Pt=(e,t)=>{const n=decodeURIComponent(t??"").slice(1).split("/");return e.map(r=>{if(r.key==="category-2"&&r.__typename==="FacetBoolean"){const s=r.values;return{...r,values:s.filter(a=>!n.find(i=>i.toLowerCase()===a.value||i.toLowerCase()===a.name.toLowerCase()))}}return r})},ee=(e,t)=>t?e==="category-1":!1,jt=e=>e.key==="operator"&&(e.value==="and"||e.value==="or"),kt=e=>e.type==="TEXT",Nt=e=>e.key==="fuzzy"&&(e.value==="0"||e.value==="1"||e.value==="auto"),wt=e=>{const{key:t,name:n,values:r}=e;return{__typename:"FacetBoolean",key:t,label:n,values:r.slice().sort((s,a)=>s.name.localeCompare(a.name))}},_t=({key:e,values:t})=>({__typename:"FacetRange",key:e,values:t}),Dt=(e,t,n)=>{if(!(e instanceof Object)||!("facets"in e))return[];const{facets:r=[]}=e,s=t!=null&&t.length?t[0].key==="category-1":!1;return r.filter(i=>!n||!ee(i.key,s)).map(i=>kt(i)?wt(i):_t(i))},Bt=(e,t)=>{const n=e.find(({key:s})=>s===B)??null,r=e.find(({key:s})=>s===H)??null;n&&Nt(n)&&t.append(B,n.value),r&&jt(r)&&t.append(H,r.value)},Ht=e=>e.map(t=>{const[n,r]=t.split("/");return{key:n,value:r}}),Gt=(e,t)=>{const n=decodeURIComponent(t??"").slice(1).split("/"),r=e.filter(({value:a})=>!n.includes(decodeURIComponent(a))).map(a=>({...a,value:decodeURIComponent(a.value)})),{isDepartment:s}=At(r);return r==null?void 0:r.filter(a=>!ee(a.key,s))},Ut=o.object({facets:o.array().of(o.object({key:o.string().required(),value:o.string().required()})).required("Facets are required")});async function Lt({apiUrl:e,body:t,fetchOptions:n}){if(!t){console.error("[ERROR FETCHING] Body is required");return}await Ut.validate(t);const{facets:r}=t,s=new URLSearchParams({}),a=r.map(({key:c,value:u})=>`${c}/${u}`).join("/");Bt(r,s);const i=`${e}/api/catalog_system/pub/products/crossselling/${a}`;return l(i,{cache:"no-store",...n}).then(c=>c.json()).then(c=>c.map(p=>{const m=Q(p.items);return m&&z(m,p)}).filter(p=>!!p).map(p=>({node:Tt(p)})))}const te=({apiUrl:e,body:t,fetchOptions:n,extraData:r})=>{if(!t){console.error("[ERROR FETCHING] Body is required");return}const{query:s="",page:a=1,count:i,sort:c="",facets:u=[],type:p,hideUnavailableItems:m=!0,locale:d=""}=t,f=new URLSearchParams({page:a.toString(),count:(i==null?void 0:i.toString())??(r==null?void 0:r.ITEMS_PER_PAGE)??24,query:s,sort:c,locale:d});m!==void 0&&f.append("hideUnavailableItems",m.toString());const b=u.map(g=>`${g.key}/${g.value}`).join("/")??"";return se(`${e}/api/io/_v/api/intelligent-search/${p}/${b}?${f.toString()}`,{headers:{Accept:"application/json","content-type":"application/json"},...n})};async function Vt({body:e,extraData:t,...n}){if(!e){console.error("[ERROR FETCHING] Body is required");return}const r=await te({body:{...e,type:"product_search"},extraData:t,...n}),s=(r==null?void 0:r.products.map(c=>{const u=Q(c.items);return u&&z(u,c)}).filter(c=>!!c))??[],{pagination:a,recordsFiltered:i}=r;return{data:{pagination:{nextPage:a.after.length>0,previousPage:a.before.length>0,startCursor:"0",endCursor:i.toString(),count:i,total:a.count},products:s.map((c,u)=>({node:qt(c),cursor:u.toString()}))}}}async function Mt({body:e,extraData:t,...n}){if(!e){console.error("[ERROR FETCHING] Body is required");return}const r=await te({body:{...e,type:"facets"},extraData:t,...n});return!r||!r.facets?(console.error("[ERROR FETCHING] No facets found"),{data:{facets:[]}}):{data:{...r,facets:Dt(r,e==null?void 0:e.selectedFacets,(e==null?void 0:e.query)??"")}}}const zt=o.object({query:o.string().optional(),locale:o.string().optional()});async function xt({apiUrl:e,body:t,fetchOptions:n}){if(!t){console.error("[ERROR FETCHING] Body is required");return}await zt.validate(t);const{query:r="",locale:s="default_locale"}=t,a=new URLSearchParams({query:r,locale:s});return l(`${e}/api/io/_v/api/intelligent-search/search_suggestions?${a.toString()}`,{...n})}async function Qt({apiUrl:e}){return l(`${e}/api/io/_v/api/intelligent-search/top_searches`)}const Yt=Object.freeze(Object.defineProperty({__proto__:null,getSearchAutoCompleteSuggestions:ht,getSearchCrossellingProducts:Lt,getSearchFacets:Mt,getSearchProducts:Vt,getSearchSuggestedTerms:xt,getSearchTopSearchs:Qt},Symbol.toStringTag,{value:"Module"})),Kt=({pathname:e,searchParams:t},n)=>{const r=t.get("sort")??"",s=t.get("query")??null,a=parseInt(t.get("page")??"1",10);return{sort:r,facets:Ht(n),term:s,base:s?"":e,page:a}},Jt=e=>{const t=new URLSearchParams;return Object.entries(e).forEach(([n,r])=>{Array.isArray(r)?r.forEach(s=>t.append(n,s)):r!==void 0&&t.append(n,r)}),t},Zt={parseSearchState:Kt,convertSearchParams:Jt,filterNonRootFacets:Gt,filterNonCategorySelected:Pt},Xt={checkout:xe,catalog:We,cms:ft,search:Yt},Wt={catalog:lt,search:Zt};exports.serverAPIs=Xt;exports.serverHelpers=Wt;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ee=require("yup"),C=require("./__vite-browser-external-DDWPeg5L.js"),te=require("sanitize-html");function re(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:()=>e[r]})}}return t.default=e,Object.freeze(t)}const o=re(ee),u=async(e,t={})=>{const{method:r="GET",body:n,headers:s={},priority:a="auto",cache:i="default"}=t;return fetch(e,{method:r,headers:{...s,Accept:"application/json","Content-Type":"application/json"},priority:a,cache:i,...n?{body:JSON.stringify(n)}:{}}).then(c=>c.json()).catch(c=>{console.error("[ERROR FETCH VTEX]",c)})},v=new Map;async function ne(e,t={}){var r;try{const{abort:n=!1}=t,s=new AbortController;n&&(v.has(e)&&((r=v.get(e))==null||r.abort(),v.delete(e)),v.set(e,s));const a=u(e,{...t,...n?{signal:s.signal}:{}});return n&&v.delete(e),a}catch(n){if(n.name==="AbortError"){console.log(`[REQUEST CANCELLED]: ${e}`);return}throw console.error(`[ERROR API]: ${n.message}`),n}}const oe=o.object({country:o.string().length(3,"Country code must be 3 characters long").required("Country is required"),postalCode:o.string().nullable()});async function ae({apiUrl:e,body:t,fetchOptions:r}){if(!t){console.error("[ERROR FETCHING] Body is required");return}await oe.validate(t);const{country:n,postalCode:s}=t;return await u(`${e}/api/checkout/pub/postal-code/${n}/${s}`,{method:"POST",body:t,...r})}const se=o.object({orderFormId:o.string().nullable(),sellerCode:o.string().nullable(),sellerName:o.string().nullable()});async function U({apiUrl:e,body:t,fetchOptions:r}){if(!t){console.error("[ERROR FETCHING] Body is required");return}await se.validate(t);const{orderFormId:n,sellerCode:s,sellerName:a}=t,i=s?`${s.trim()} - ${a}`:null;return u(`${e}/api/checkout/pub/orderForm/${n}/attachments/openTextField`,{method:"POST",body:{value:i},...r})}const ie=o.object({orderFormId:o.string().nullable(),sellerCode:o.string().nullable(),marketingData:o.object()});async function V({apiUrl:e,body:t,fetchOptions:r}){if(!t){console.error("[ERROR FETCHING] Body is required");return}await ie.validate(t);const{orderFormId:n,sellerCode:s,marketingData:a}=t,i=s?{utmCampaign:s?s.toUpperCase():"",utmiCampaign:s?"codigodavendedora":"semcodigo"}:{};return u(`${e}/api/checkout/pub/orderForm/${n}/attachments/marketingData`,{method:"POST",body:{...a,...i},...r})}const ce=o.object({orderFormId:o.string().nullable(),sellerCode:o.string().nullable(),sellerName:o.string().nullable()});async function le({apiUrl:e,body:t,fetchOptions:r}){if(!t){console.error("[ERROR FETCHING] Body is required");return}await ce.validate(t);const n=await U({apiUrl:e,body:t,fetchOptions:r});return V({apiUrl:e,body:{...t,marketingData:n==null?void 0:n.marketingData},fetchOptions:r})}const ue=o.object({orderFormId:o.string().nullable(),coupon:o.string().nullable()});async function de({apiUrl:e,body:t,fetchOptions:r}){if(!t){console.error("[ERROR FETCHING] Body is required");return}await ue.validate(t);const{coupon:n="",orderFormId:s}=t;return u(`${e}/api/checkout/pub/orderForm/${s}/coupons`,{method:"POST",body:{text:n},...r})}const me=o.object({appId:o.string().required("App ID is required"),orderFormId:o.string().nullable(),key:o.array().of(o.string())});async function pe({apiUrl:e,body:t,fetchOptions:r}){if(!t){console.error("[ERROR FETCHING] Body is required");return}await me.validate(t);const{appId:n="faststore",orderFormId:s,key:a}=t;return u(`${e}/api/checkout/pub/orderForm/${s}/customData/${n}/${a}`,{method:"PUT",...r})}const ge=o.object().shape({name:o.string().required("Attachment name is required"),content:o.object().nullable()});var G;const fe=o.object().shape({attachments:(G=o.array().of(ge))==null?void 0:G.nullable(),id:o.string().required("ID of SKU is required"),index:o.number().integer().nullable(),quantity:o.number().integer().nullable(),seller:o.string().required("Seller is required"),price:o.number().integer()}),he=o.object({orderFormId:o.string().required("OrderFormId is required"),orderItems:o.array().of(fe)});async function Ie({apiUrl:e,body:t,fetchOptions:r}){if(!t){console.error("[ERROR FETCHING] Body is required");return}await he.validate(t);const{orderFormId:n,orderItems:s}=t;return u(`${e}/api/checkout/pub/orderForm/${n}/items`,{method:"POST",body:{orderItems:s},...r})}const be=o.object({orderFormId:o.string().nullable()});async function ye({apiUrl:e,body:t,fetchOptions:r}){if(!t){console.error("[ERROR FETCHING] Body is required");return}await be.validate(t);const{orderFormId:n}=t;return u(`${e}/api/checkout/pub/orderForm/${n}/items/removeAll`,{method:"POST",...r})}const Ce=o.object().shape({name:o.string().required("Attachment name is required"),content:o.object().nullable()});var B;const Re=o.object().shape({attachments:(B=o.array().of(Ce))==null?void 0:B.nullable(),id:o.string().required("ID of SKU is required"),index:o.number().integer().nullable(),quantity:o.number().integer().nullable(),seller:o.string().required("Seller is required"),price:o.number().integer()}),Oe=o.object({orderFormId:o.string().nullable(),orderItems:o.array().of(Re)});async function Fe({apiUrl:e,body:t,fetchOptions:r}){if(!t){console.error("[ERROR FETCHING] Body is required");return}await Oe.validate(t);const{orderFormId:n,orderItems:s}=t;return u(`${e}/api/checkout/pub/orderForm/${n}/items/update`,{method:"POST",body:{orderItems:s},...r})}const ve=o.object({orderFormId:o.string().nullable()});async function Se({apiUrl:e,body:t,fetchOptions:r}){if(!t){console.error("[ERROR FETCHING] Body is required");return}await ve.validate(t);const{orderFormId:n}=t;return u(`${e}/api/checkout/pub/orderForm/${n}/messages/clear`,{method:"POST",...r})}const $e=o.object({id:o.string().nullable(),itemIndex:o.number().nullable(),orderFormId:o.string().nullable(),remove:o.boolean().nullable()});async function Ee({apiUrl:e,body:t,fetchOptions:r}){if(!t){console.error("[ERROR FETCHING] Body is required");return}await $e.validate(t);const{itemIndex:n,orderFormId:s,id:a,remove:i}=t,c=i?`/${a}/remove`:"",l=`${e}/api/checkout/pub/orderForm/${s}/items/${n}/offerings${c}`;return u(l,{method:"POST",body:{id:a},...r})}const qe=o.object({orderFormId:o.string().nullable()});async function Te({apiUrl:e,body:t,fetchOptions:r,extraData:n}){var i;if(!t){console.error("[ERROR FETCHING] Body is required");return}await qe.validate(t);const s=new URLSearchParams({refreshOutdatedData:"true"}),a=t.orderFormId&&((i=n.orderFormPurchaseId)==null?void 0:i.value)!==t.orderFormId?`${e}/api/checkout/pub/orderForm/${t.orderFormId}?${String(s)}`:`${e}/api/checkout/pub/orderForm`;return u(a,{method:"GET",...r})}const Pe=o.object({orderFormId:o.string().nullable(),email:o.string().email().required(),firstName:o.string().required(),lastName:o.string().required(),documentType:o.string().required(),document:o.string().required(),phone:o.string().matches(/^\+\d{1,3}\d{10,11}$/)});async function Ae({apiUrl:e,body:t,fetchOptions:r}){if(!t){console.error("[ERROR FETCHING] Body is required");return}await Pe.validate(t);const{orderFormId:n,...s}=t;return u(`${e}/api/checkout/pub/orderForm/${n}/attachments/clientProfileData`,{method:"POST",body:{...s},...r})}const Ne=o.object({sellerCode:o.string().nullable()});async function je({apiUrl:e,body:t,fetchOptions:r}){if(!t){console.error("[ERROR FETCHING] Body is required");return}await Ne.validate(t);const{sellerCode:n=""}=t;return u(`${e}/api/dataentities/VD/search?_fields=id,cod,name,ativo&cod=${n}`,{method:"GET",headers:{Accept:"application/vnd.vtex.ds.v10+json"},...r})}const ke=o.object().shape({country:o.string().length(3,"Country code must be 3 characters long").required("Country is required"),orderFormId:o.string().nullable(),postalCode:o.string().nullable()});async function we({apiUrl:e,body:t,fetchOptions:r}){if(!t){console.error("[ERROR FETCHING] Body is required");return}await ke.validate(t);const{country:n,orderFormId:s,postalCode:a}=t,i=a?{address:{addressType:"residential",postalCode:a,country:n}}:{logisticsInfo:[],clearAddressIfPostalCodeNotFound:!0};return u(`${e}/api/checkout/pub/orderForm/${s}/attachments/shippingData`,{method:"POST",body:i,...r})}const _e=o.object().shape({orderFormId:o.string().nullable(),options:o.array().of(o.object().shape({itemIndex:o.number(),selectedDeliveryChannel:o.string(),selectedSla:o.string()})),selectedAddresses:o.array().of(o.object().shape({addressId:o.string().required(),addressType:o.string().required(),city:o.string().nullable(),complement:o.string().nullable(),country:o.string().required().length(3),geoCoordinates:o.array().of(o.number()).required().min(0),isDisposable:o.boolean().required(),neighborhood:o.string().nullable(),number:o.string().nullable(),postalCode:o.string().required(),receiverName:o.string().nullable(),reference:o.string().nullable(),state:o.string().nullable(),street:o.string().nullable()}))});async function De({apiUrl:e,body:t,fetchOptions:r}){if(!t){console.error("[ERROR FETCHING] Body is required");return}await _e.validate(t);const{orderFormId:n,options:s,selectedAddresses:a}=t;return u(`${e}/api/checkout/pub/orderForm/${n}/attachments/shippingData`,{method:"POST",body:{selectedAddresses:a,clearAddressIfPostalCodeNotFound:!1,logisticsInfo:s},...r})}const He=o.object({country:o.string().length(3,"Country code must be 3 characters long").required("Country is required"),postalCode:o.string().nullable(),geoCoordinates:o.object().shape({longitude:o.number().required(),latitude:o.number().required()})});async function Ge({apiUrl:e,body:t,fetchOptions:r}){if(!t){console.error("[ERROR FETCHING] Body is required");return}await He.validate(t);const{country:n="",geoCoordinates:s,postalCode:a=""}=t,i=new URLSearchParams({country:String(n)});return a?i.append("postalCode",a):i.append("geoCoordinates",`${s==null?void 0:s.longitude};${s==null?void 0:s.latitude}`),await u(`${e}/api/checkout/pub/regions/?${i.toString()}`,{method:"GET",...r})}const Be=o.object({id:o.string().required("ID of SKU is required"),quantity:o.number().integer().required("Quantity of item is required"),seller:o.string()}),Ue=o.object({items:o.array().of(Be),country:o.string().length(3,"Country code must be 3 characters long").required("Country is required"),postalCode:o.string().nullable(),geoCoordinates:o.array().nullable().of(o.number()).length(2)});async function Ve({apiUrl:e,body:t,fetchOptions:r}){if(!t){console.error("[ERROR FETCHING] Body is required");return}return await Ue.validate(t),u(`${e}/api/checkout/pub/orderForms/simulation`,{method:"POST",body:t,...r})}const Le=Object.freeze(Object.defineProperty({__proto__:null,getMasterDataSellerCode:je,getOrderForm:Te,postOrderFormAddCoupon:de,postOrderFormAttachClientProfileData:Ae,postOrderFormAttachOrderFormData:le,postOrderFormAttachShippingData:we,postOrderFormAttachmentsMarketingData:V,postOrderFormAttachmentsOpenTextField:U,postOrderFormClearMessages:Se,postOrderFormFreightSimulation:Ve,postOrderFormItems:Ie,postOrderFormRegion:Ge,postOrderFormRemoveAllItems:ye,postOrderFormUpdateItems:Fe,postOrderFormUpdateShippingData:De,postOrderformAddress:ae,putOrderFormCustomData:pe,updateOrderFormOffering:Ee},Symbol.toStringTag,{value:"Module"})),Me=o.object({skuId:o.string()});async function xe({apiUrl:e,body:t,fetchOptions:r}){if(!t){console.error("[ERROR FETCHING] Body is required");return}await Me.validate(t);const{skuId:n}=t;return u(`${e}/api/catalog/pvt/stockkeepingunitkit?parentSkuId=${n}`,{...r})}const ze=o.object({ids:o.array().of(o.string().required("ID are required")).required("IDs are required")});async function Qe({apiUrl:e,body:t,fetchOptions:r}){if(!t){console.error("[ERROR FETCHING] Body is required");return}await ze.validate(t);const{ids:n}=t;return u(`${e}/api/catalog_system/pub/products/search?fq=${n.map(s=>`productId:${s}`).join("&fq=")}`,{...r})}const Je=o.object({productId:o.number().required("Product ID is required")});async function Ke({apiUrl:e,body:t,fetchOptions:r}){if(!t){console.error("[ERROR FETCHING] Body is required");return}await Je.validate(t);const{productId:n}=t;return u(`${e}/api/catalog_system/pub/products/crossselling/similars/${n.toString()}`,{...r})}const Ye=Object.freeze(Object.defineProperty({__proto__:null,getCatalogKitProducts:xe,getCatalogProducts:Qe,getCatalogSimilars:Ke},Symbol.toStringTag,{value:"Module"})),We=(e="")=>e.charAt(0).toUpperCase()+e.slice(1),_=(e,t=" ")=>!e||typeof e=="string"&&e.length===0?e:(Array.isArray(e)?e:e.split("-")).map(We).join(t),Xe=({canonical:e,seo:t,slug:r})=>{const n=Array.isArray(r)?r.join(", "):r;return{id:0,Title:`${Array.isArray(r)?r.map(a=>_(a)).join(","):_(r)} - ${t.title}`,MetaTagDescription:t.description,name:n,hasChildren:!1,url:e,children:[]}},Ze=({canonical:e,category:t,previousImages:r,seo:n})=>({category:String(t==null?void 0:t.id),title:(t==null?void 0:t.Title)??n.title,description:(t==null?void 0:t.MetaTagDescription)??n.description,alternates:{canonical:e},openGraph:{type:"website",title:(t==null?void 0:t.Title)??n.title,description:(t==null?void 0:t.MetaTagDescription)??n.description,images:Array.isArray(r)?[...r]:[]}}),et=({items:e,parent:t,apiUrl:r,find:n})=>{const s=e.find(i=>i.url.replace(r,"")===decodeURIComponent(t.toLowerCase()));return(s==null?void 0:s.children.find(i=>i.name.toLowerCase()===decodeURIComponent(String(n))))??s},tt=e=>{e instanceof Error?(console.error(`[ERROR CATEGORY INFO]: ${e.message}`),console.error(e.stack)):console.error("[ERROR CATEGORY INFO]: Unknown error",e)},rt=new Set(["brand","category","department","subcategory","collection","cluster"]),nt=e=>typeof(e==null?void 0:e.pageType)=="string"&&rt.has(e==null?void 0:e.pageType.toLowerCase()),ot=e=>({collection:e.Coleção,categoryId:e.categoryId,current_collection:e["Coleção Atual"],items:e.items}),at=(e,t)=>e.reduce((r,n)=>{if(n.items.filter(i=>i.sellers.find(c=>c.commertialOffer.IsAvailable)).length===0||(r==null?void 0:r.find(i=>(i==null?void 0:i.productId)===(n==null?void 0:n.productId)))!==void 0)return r;const a=n.items[0].images.find(i=>t.includes(i.imageLabel));return r.push({slug:`/${n.linkText}/p`,productId:n==null?void 0:n.productId,textureImage:(a==null?void 0:a.imageUrl)??"",textureAlt:(a==null?void 0:a.imageText)??""}),r},[]),st=Object.freeze(Object.defineProperty({__proto__:null,createEmptySeoCategory:Xe,createSeoCategory:Ze,findCategory:et,formattedSimilars:at,isCollectionPageType:nt,notFindCategoryError:tt,responseAdapter:ot},Symbol.toStringTag,{value:"Module"}));async function it({contentType:e,storeId:t,CMS_PROJECT_NAME:r,NextCookies:n}){const s=await L({contentType:e,storeId:t,CMS_PROJECT_NAME:r,NextCookies:n});if(s.status===200){const a={timestamp:new Date().toISOString(),contentType:e,data:s.data};console.log("Resultado da chamada:",s);const i=`backup-${e}-${Date.now()}.json`;return await C.fs.writeFile(`./backups/${i}`,JSON.stringify(a,null,2),"utf-8"),{success:!0,fileName:i}}return{success:!1,error:s.error||"No data to backup"}}async function ct(e){return it(e)}async function lt({contentType:e,documentId:t,versionId:r,storeId:n,CMS_PROJECT_NAME:s}){const a=t&&t.length?`/${t}`:"",i=r&&r.length?`?versionId=${r}`:"";return fetch(`https://${n}.myvtex.com/_v/cms/api/${s}/${e}${a}${i}`,{cache:"no-cache"})}async function ut({contentType:e,documents:t,NextCookies:r,CMS_PROJECT_NAME:n,storeId:s}){var i;const a=JSON.parse(((i=r().get("cms_preview_data"))==null?void 0:i.value)??"{}");if(a&&(a==null?void 0:a.contentType)===e){const c=a.documentId&&a.documentId.length?`/${a.documentId}`:"",l=a!=null&&a.versionId&&(a!=null&&a.versionId.length)?`?versionId=${a==null?void 0:a.versionId}`:"",p=await(await fetch(`https://${s}.myvtex.com/_v/cms/api/${n}/${e}${c}${l}`,{cache:"no-store"})).json(),d=t.filter(m=>p.id!==m.documentId);return d.unshift(p),d}return t}async function L({contentType:e,NextCookies:t,CMS_PROJECT_NAME:r,storeId:n}){var g,p;const s=JSON.parse(((g=t().get("cms_preview_data"))==null?void 0:g.value)??"{}"),a=[];let i=1,c=0,l=!0;try{do{const m=await(await fetch(`https://${n}.myvtex.com/_v/cms/api/${r}/${e}?page=${i}`)).json();i===1&&(c=m.totalItems),(p=m==null?void 0:m.data)!=null&&p.length&&a.push(...m.data),l=m.hasNextPage,i++}while(l&&a.length<c);if(s.previewMode&&a.length){const d=await ut({contentType:e,documents:a,NextCookies:t,CMS_PROJECT_NAME:r,storeId:n});return{status:d.length>0?200:404,data:d??[]}}return{status:a.length?200:404,data:a}}catch(d){return{status:"error",data:[],error:d}}}const dt=Object.freeze(Object.defineProperty({__proto__:null,cmsBackup:ct,getCMSContentType:lt,getContentType:L},Symbol.toStringTag,{value:"Module"})),mt=o.object({query:o.string()});async function pt({apiUrl:e,body:t,fetchOptions:r}){if(!t){console.error("[ERROR FETCHING] Body is required");return}await mt.validate(t);const{query:n=""}=t,s=new URLSearchParams({query:n});return u(`${e}/api/io/_v/api/intelligent-search/autocomplete_suggestions?${s.toString()}`,{...r})}const gt=(e,t)=>te(e,t),ft=e=>({...e,description:e.description?gt(e.description):e.description}),ht=({offer:e,seller:t,product:r})=>({...e,product:r,seller:t}),M=(e,t)=>({...e,isVariantOf:ft(t)}),It=e=>e?"https://schema.org/InStock":"https://schema.org/OutOfStock",E=e=>e.AvailableQuantity>0,D=e=>e.spotPrice??0,bt=e=>e.Price??0,x=(e,t)=>E(e)&&!E(t)?-1:!E(e)&&E(t)?1:D(e)-D(t),yt=(e,t)=>{let r=0;for(let n=1;n<e.length;n++)t(e[r],e[n])>0&&(r=n);return e[r]},z=e=>{const t=e.flatMap(n=>n.sellers.map(s=>({offer:s.commertialOffer,sku:n}))),r=yt(t,({offer:n},{offer:s})=>x(n,s));return r?r.sku:e[0]},Q=e=>e.map(({imageUrl:t,imageText:r,imageLabel:n})=>({alternateName:r??"",url:t.replace("vteximg.com.br","vtexassets.com"),keywords:n})),q={attachment:"ATTACHMENT",specification:"SPECIFICATION",attribute:"ATTRIBUTE"},Ct=e=>({name:e.name,value:e.content,valueReference:q.attachment}),Rt=e=>({propertyID:e.id,name:e.name,value:e.value,valueReference:{valueReference:q.attribute,visible:e.visible}}),T=(e,t,r)=>{const n=e.flatMap(({name:i,values:c})=>c?c.map(l=>({name:i,value:l,valueReference:q.specification})):{name:i,value:"",valueReference:q.specification}),s=Array.isArray(r)?r.map(Ct):[],a=t?t.map(Rt):[];return[...n,...s,...a]},H="ÁÄÂÀÃÅČÇĆĎÉĚËÈÊẼĔȆÍÌÎÏŇÑÓÖÒÔÕØŘŔŠŤÚŮÜÙÛÝŸŽáäâàãåčçćďéěëèêẽĕȇíìîïňñóöòôõøðřŕšťúůüùûýÿžþÞĐđ߯a",Ot="AAAAAACCCDEEEEEEEEIIIINNOOOOOORRSTUUUUUYYZaaaaaacccdeeeeeeeeiiiinnooooooorrstuuuuuyyzbBDdBAa",Ft=e=>{let t=e.slice(0);for(let r=0;r<H.length;r++)t=t.replace(new RegExp(H.charAt(r),"g"),Ot.charAt(r));return t},vt=e=>e.replace(/[·/_,:]/,"-"),J=e=>{const r=e.replace(/,/g,"").replace(/[*+~.()'"!:@&\[\]`/ %$#?{}|><=_^]/g,"-");return vt(Ft(r)).toLowerCase()},K=e=>`/${e}/p`,Y=e=>{const t=Math.max(...e.map(n=>n.NumberOfInstallments)),r=e.find(n=>n.NumberOfInstallments===t);return{count:(r==null?void 0:r.NumberOfInstallments)??0,value:(r==null?void 0:r.Value)??0}},W=(e,t)=>{const r={price:0,listPrice:0,sellerDefault:!1},s=e.map(a=>ht({offer:a.commertialOffer,seller:a,product:t})).sort(x).map(a=>(a.seller.sellerId==="1"&&a.AvailableQuantity>0&&(r.price=a.Price,r.listPrice=a.ListPrice,r.sellerDefault=!0),{availability:a.AvailableQuantity>0,listPrice:a.ListPrice,price:bt(a),priceValidUntil:a.PriceValidUntil,priceCurrency:"BRL",installments:a.Installments,lowPrice:a.spotPrice,quantity:a.AvailableQuantity,seller:{identifier:a.seller.sellerId}}));return{lowPrice:r.sellerDefault?r.price:s[0].price,highPrice:r.sellerDefault?r.listPrice:s[0].listPrice,offers:s}},X=e=>{const{attributes:t,itemId:r,name:n,sellers:s,variations:a}=e;return{additionalProperty:T(a,t,[]),name:n,offers:{offers:s.map(({sellerId:i,commertialOffer:c})=>({availability:It(c.AvailableQuantity>0),listPrice:c.ListPrice,price:c.Price,quantity:c.AvailableQuantity,seller:{identifier:i}}))},sku:r}},St=e=>{var O;const{attributes:t,referenceId:r,isVariantOf:n,images:s,itemId:a,name:i,sellers:c,videos:l,variations:g}=e,{brand:p,categories:d,categoriesIds:m,description:b,linkText:f,productClusters:P,clusterHighlights:S,productName:$,properties:A,productId:N}=n,j=d.slice().reverse(),y=W(c,e.isVariantOf),k=Y(y.offers[0].installments);return{sku:a,gtin:((O=r[0])==null?void 0:O.Value)??"",name:$??i,description:b,releaseDate:n.releaseDate??"",slug:f,video:l[0],categories:d,categoriesIds:m,id:N,brand:{name:p,brandName:p},seo:{description:b,title:$,canonical:K(f)},cluster:{generals:P,highlights:S},properties:A,availability:{status:y.offers[0].availability},breadcrumbList:{itemListElement:[...j.map((h,F)=>{const I=h.split("/"),R=I[I.length-2],w=I.map(J).join("/");return{name:R,item:w,position:F+1}}),{name:n.productName,item:f,position:d.length+1}],numberOfItems:d.length},image:Q(s),offers:y,additionalProperty:T(g,t,[]),isVariantOf:{productGroupID:n.productId,hasVariant:n.items.map(h=>X(h))},installments:k}},$t=e=>{var O;const{attributes:t,referenceId:r,isVariantOf:n,images:s,itemId:a,name:i,sellers:c,Videos:l,variations:g}=e,{brand:p,categories:d,categoriesIds:m,description:b,linkText:f,productClusters:P,productName:S,Coleção:$,"ID Coleção":A,productId:N}=n,j=d.slice().reverse(),y=W(c,e.isVariantOf),k=Y(y.offers[0].installments);return{sku:a,gtin:((O=r[0])==null?void 0:O.Value)??"",name:S??i,description:b,releaseDate:n.releaseDate??"",slug:f,video:l[0],categories:d,categoriesIds:m,collection:$,collectionId:A,id:N,brand:{name:p,brandName:p},seo:{description:b,title:S,canonical:K(f)},cluster:{generals:P,highlights:[]},availability:{status:y.offers[0].availability},breadcrumbList:{itemListElement:[...j.map((h,F)=>{const I=h.split("/"),R=I[I.length-2],w=I.map(J).join("/");return{name:R,item:w,position:F+1}}),{name:n.productName,item:f,position:d.length+1}],numberOfItems:d.length},image:Q(s),offers:y,additionalProperty:T(g,t,[]),isVariantOf:{productGroupID:n.productId,hasVariant:n.items.map(h=>{const{variations:F}=h,I=F.map(R=>({name:R,values:h[R]}));return{...X(h),additionalProperty:T(I,t,[])}})},installments:k}},Et=o.array().of(o.object({key:o.string().required(),value:o.string().required()})).required("Facets are required");async function qt({apiUrl:e,body:t,fetchOptions:r}){if(!t){console.error("[ERROR FETCHING] Body is required");return}await Et.validate(t);const n=new URLSearchParams({}),s=t.map(({key:i,value:c})=>`${i}/${c}`).join("/");C.addSearchParamsFacets(t,n);const a=`${e}/api/catalog_system/pub/products/crossselling/${s}`;return u(a,{cache:"no-store",...r}).then(i=>i.map(l=>{const g=z(l.items);return g&&M(g,l)}).filter(l=>!!l).map(l=>({node:$t(l)})))}const Z=({apiUrl:e,body:t,fetchOptions:r,extraData:n})=>{if(!t){console.error("[ERROR FETCHING] Body is required");return}const{query:s="",page:a=1,count:i,sort:c="",facets:l=[],type:g,hideUnavailableItems:p=!0,locale:d=""}=t,m=new URLSearchParams({page:a.toString(),count:(i==null?void 0:i.toString())??(n==null?void 0:n.ITEMS_PER_PAGE)??24,query:s,sort:c,locale:d});p!==void 0&&m.append("hideUnavailableItems",p.toString());const b=l.map(f=>`${f.key}/${f.value}`).join("/")??"";return ne(`${e}/api/io/_v/api/intelligent-search/${g}/${b}?${m.toString()}`,{headers:{Accept:"application/json","content-type":"application/json"},...r})};async function Tt({body:e,extraData:t,...r}){if(!e){console.error("[ERROR FETCHING] Body is required");return}const n=await Z({body:{...e,type:"product_search"},extraData:t,...r}),s=(n==null?void 0:n.products.map(c=>{const l=z(c.items);return l&&M(l,c)}).filter(c=>!!c))??[],{pagination:a,recordsFiltered:i}=n;return{data:{pagination:{nextPage:a.after.length>0,previousPage:a.before.length>0,startCursor:"0",endCursor:i.toString(),count:i,total:a.count},products:s.map((c,l)=>({node:St(c),cursor:l.toString()}))}}}async function Pt({body:e,extraData:t,...r}){if(!e){console.error("[ERROR FETCHING] Body is required");return}const n=await Z({body:{...e,type:"facets"},extraData:t,...r});return!n||!n.facets?(console.error("[ERROR FETCHING] No facets found"),{data:{facets:[]}}):{data:{...n,facets:C.formattedFacets(n,e==null?void 0:e.selectedFacets,(e==null?void 0:e.query)??"")}}}const At=o.object({query:o.string().optional(),locale:o.string().optional()});async function Nt({apiUrl:e,body:t,fetchOptions:r}){if(!t){console.error("[ERROR FETCHING] Body is required");return}await At.validate(t);const{query:n="",locale:s="default_locale"}=t,a=new URLSearchParams({query:n,locale:s});return u(`${e}/api/io/_v/api/intelligent-search/search_suggestions?${a.toString()}`,{...r})}async function jt({apiUrl:e}){return u(`${e}/api/io/_v/api/intelligent-search/top_searches`)}const kt=Object.freeze(Object.defineProperty({__proto__:null,getSearchAutoCompleteSuggestions:pt,getSearchCrossellingProducts:qt,getSearchFacets:Pt,getSearchProducts:Tt,getSearchSuggestedTerms:Nt,getSearchTopSearchs:jt},Symbol.toStringTag,{value:"Module"})),wt={parseSearchState:C.parseSearchState,convertSearchParams:C.convertSearchParams,filterNonRootFacets:C.filterNonRootFacets,filterNonCategorySelected:C.filterNonCategorySelected},_t={checkout:Le,catalog:Ye,cms:dt,search:kt},Dt={catalog:st,search:wt};exports.serverAPIs=_t;exports.serverHelpers=Dt;
|