{"version":3,"file":"StructuredData.CpTBe6BT.js","sources":["../../../../../../src/lib/js/structured_data.ts","../../../../../../src/lib/components/common/StructuredData.svelte"],"sourcesContent":["import { getProductFinalPriceWithTax } from '$lib/js/helpers'\nimport { PUBLIC_BIXOTO_MEDIA, PUBLIC_MAGENTO_ENDPOINT, PUBLIC_STRAPI_MEDIA } from '$env/static/public'\nimport { gt } from 'svelte-i18n-lingui'\nimport type { BaseProduct, FullBrand, FullProduct } from '$lib/js/elasticsearch/types'\nimport type { BlogPost, HeroSection } from '$lib/js/strapi/types'\nimport type { Review } from '$lib/js/reviewsio/types'\nimport type { SiteScope } from '$lib/js/helpers/i18n'\n\nexport function serializeSchema(thing: Record) {\n\treturn ``\n}\n\n/**\n * Get merchant data\n **/\nexport function getMerchantSchema(product: FullProduct | BaseProduct, options: {\n\tbrand?: FullBrand,\n\treviews?: Review[],\n\tscope: SiteScope,\n}) {\n\tlet price = Math.round((getProductFinalPriceWithTax(product) + Number.EPSILON) * 100) / 100\n\tlet shipping_info: Record\n\n\tconst { brand, reviews, scope } = options\n\n\tlet merchantSchema: Record = {\n\t\t'@context': 'https://schema.org',\n\t\t'@type': 'Product',\n\t\t'name': product.name,\n\t\t'sku': product.sku,\n\t\t'description': (product).description || product.name,\n\t\t'offers': {\n\t\t\t'@type': 'https://schema.org/Offer',\n\t\t\t'price': price,\n\t\t\t'url': `${PUBLIC_MAGENTO_ENDPOINT}/${scope}/p/${product.url_key}`,\n\t\t\t'priceCurrency': 'EUR',\n\t\t\t'availability': 'https://schema.org/InStock', // TODO: make this dynamic\n\t\t\t'itemCondition': 'https://schema.org/NewCondition', // TODO: make this dynamic\n\t\t\t'priceValidUntil': '2025-12-31', // TODO: make this dynamic\n\t\t\t'shippingDetails': '',\n\t\t\t'hasMerchantReturnPolicy': {\n\t\t\t\t'@type': 'MerchantReturnPolicy',\n\t\t\t\t'applicableCountry': scope.toLocaleUpperCase(),\n\t\t\t\t'returnPolicyCategory': 'https://schema.org/MerchantReturnFiniteReturnWindow',\n\t\t\t\t'merchantReturnDays': 14, // Should this depend on the scope?\n\t\t\t\t'returnMethod': 'https://schema.org/ReturnByMail',\n\t\t\t},\n\t\t},\n\t\t'productID': product.sku,\n\t\t'gtin13': product.ean13,\n\t\t'category': product.category && product.category.length > 0 ? product.category[product.category.length - 1].name : '',\n\t}\n\n\t// Some products have no image (e.g. BigBuy's variations)\n\tif (product.resized_image) {\n\t\tmerchantSchema['image'] = `${PUBLIC_BIXOTO_MEDIA}${product.resized_image.path}`\n\t}\n\n\tif (price > 69) {\n\t\tshipping_info = {\n\t\t\t'@type': 'OfferShippingDetails',\n\t\t\t'shippingRate': {\n\t\t\t\t'@type': 'MonetaryAmount',\n\t\t\t\t'value': '0',\n\t\t\t\t'currency': 'EUR',\n\t\t\t},\n\t\t\t'shippingDestination': {\n\t\t\t\t'@type': 'DefinedRegion',\n\t\t\t\t'addressCountry': 'ES',\n\t\t\t},\n\t\t\t'deliveryTime': {\n\t\t\t\t'@type': 'ShippingDeliveryTime',\n\t\t\t\t'handlingTime': {\n\t\t\t\t\t'@type': 'QuantitativeValue',\n\t\t\t\t\t'minValue': 0,\n\t\t\t\t\t'maxValue': 1,\n\t\t\t\t\t'unitCode': 'DAY',\n\t\t\t\t},\n\t\t\t\t'transitTime': {\n\t\t\t\t\t'@type': 'QuantitativeValue',\n\t\t\t\t\t'minValue': 0,\n\t\t\t\t\t'maxValue': 4,\n\t\t\t\t\t'unitCode': 'DAY',\n\t\t\t\t},\n\t\t\t},\n\t\t}\n\t} else {\n\t\tshipping_info = {\n\t\t\t'@type': 'OfferShippingDetails',\n\t\t\t'shippingRate': {\n\t\t\t\t'@type': 'MonetaryAmount',\n\t\t\t\t'value': 3.99,\n\t\t\t\t'currency': 'EUR',\n\t\t\t},\n\t\t\t'shippingDestination': {\n\t\t\t\t'@type': 'DefinedRegion',\n\t\t\t\t'addressCountry': 'ES',\n\t\t\t},\n\t\t\t'deliveryTime': {\n\t\t\t\t'@type': 'ShippingDeliveryTime',\n\t\t\t\t'handlingTime': {\n\t\t\t\t\t'@type': 'QuantitativeValue',\n\t\t\t\t\t'minValue': 0,\n\t\t\t\t\t'maxValue': 1,\n\t\t\t\t\t'unitCode': 'DAY',\n\t\t\t\t},\n\t\t\t\t'transitTime': {\n\t\t\t\t\t'@type': 'QuantitativeValue',\n\t\t\t\t\t'minValue': 0,\n\t\t\t\t\t'maxValue': 4,\n\t\t\t\t\t'unitCode': 'DAY',\n\t\t\t\t},\n\t\t\t},\n\t\t}\n\t}\n\n\tmerchantSchema.offers.shippingDetails = shipping_info\n\n\tif (brand && brand.page_title) {\n\t\tmerchantSchema.brand = {\n\t\t\t'@type': 'Brand',\n\t\t\t'name': brand.page_title,\n\t\t}\n\t\tmerchantSchema.manufacturer = brand.page_title\n\t}\n\n\tif (product.reviews_number && product.reviews_number > 0 && product.rating_average && product.rating_average >= 3 && reviews) {\n\t\tlet allRevs: Record[] = []\n\n\t\tfor (const review of reviews) {\n\t\t\tallRevs.push({\n\t\t\t\t'@type': 'Review',\n\t\t\t\t'reviewRating': {\n\t\t\t\t\t'@type': 'Rating',\n\t\t\t\t\t'ratingValue': review.rating,\n\t\t\t\t},\n\t\t\t\t'author': {\n\t\t\t\t\t'@type': 'Person',\n\t\t\t\t\t'name': review.author.name,\n\t\t\t\t},\n\t\t\t})\n\t\t}\n\n\t\tmerchantSchema.review = allRevs\n\t\tmerchantSchema.aggregateRating = {\n\t\t\t'@type': 'AggregateRating',\n\t\t\t'ratingValue': product.rating_average,\n\t\t\t'ratingCount': product.reviews_number,\n\t\t}\n\t}\n\n\treturn merchantSchema\n}\n\n/**\n * Get post structured data\n **/\nexport function getPostSchema(post: BlogPost) {\n\treturn {\n\t\t'@context': 'https://schema.org',\n\t\t'@type': 'NewsArticle',\n\t\t'headline': post.page_title,\n\t\t'image': [\n\t\t\tPUBLIC_STRAPI_MEDIA + post.hero_section.bg_img?.url,\n\t\t],\n\t\t'datePublished': post.publishedAt,\n\t\t'dateModified': post.updatedAt,\n\t\t'author': [{\n\t\t\t'@type': 'Organization',\n\t\t\t'name': 'Bixoto',\n\t\t\t'url': PUBLIC_MAGENTO_ENDPOINT,\n\t\t}],\n\t}\n}\n\n/* Get page structured data */\nexport function getPageSchema(url: URL, data: { page_data?: { hero_section?: HeroSection } }) {\n\tlet title = data?.page_data?.hero_section?.page_title\n\n\treturn {\n\t\t'@context': 'https://schema.org/',\n\t\t'@type': 'BreadcrumbList',\n\t\t'itemListElement': [{\n\t\t\t'@type': 'ListItem',\n\t\t\t'item': {\n\t\t\t\t'id': url.href,\n\t\t\t\t'type': 'Thing',\n\t\t\t\t'name': title || 'Bixoto',\n\t\t\t},\n\t\t\t'position': '1',\n\t\t}],\n\t}\n}\n\n/* Get breadcrumbs structured data */\nexport function getBreadcrumbsSchema(product_categories: { name: string, position: number }[]) {\n\treturn {\n\t\t'@context': 'https://schema.org/',\n\t\t'@type': 'BreadcrumbList',\n\t\t'itemListElement': product_categories.map(category => ({\n\t\t\t'@type': 'ListItem',\n\t\t\t'item': {\n\t\t\t\t'id': category.name,\n\t\t\t\t'type': 'Thing',\n\t\t\t\t'name': category.name,\n\t\t\t},\n\t\t\t'position': category.position,\n\t\t})),\n\t}\n}\n\nexport function getWebsiteSchema({ scope }: { scope: SiteScope }): Record {\n\treturn {\n\t\t'@context': 'https://schema.org',\n\t\t'@type': 'Organization',\n\t\t'name': 'Bixoto',\n\t\t'url': 'www.bixoto.com',\n\t\t'description': gt`Your sustainable online store`,\n\t\t'image': 'https://bixoto.com/images/bg-brand.jpg',\n\t\t'address': {\n\t\t\t'type': 'PostalAddress',\n\t\t\t'streetAddress': 'Ronda Sant Pere 52',\n\t\t\t'addressLocality': 'Barcelona',\n\t\t\t'postalCode': '08010',\n\t\t},\n\t\t// TODO[i18n]: either add a French number or add the +34 prefix\n\t\t'telephone': '613017716',\n\t}\n}\n","\n\n\n\t{@html serializeSchema(schema)}\n\n"],"names":["serializeSchema","thing","getMerchantSchema","product","options","price","getProductFinalPriceWithTax","shipping_info","brand","reviews","scope","merchantSchema","PUBLIC_MAGENTO_ENDPOINT","PUBLIC_BIXOTO_MEDIA","allRevs","review","getPostSchema","post","PUBLIC_STRAPI_MEDIA","_a","getPageSchema","url","data","title","_b","getBreadcrumbsSchema","product_categories","category","getWebsiteSchema","gt","raw_value","ctx","dirty","html_tag","schema","$$props"],"mappings":"q4BAQO,SAASA,EAAgBC,EAA4B,CAC3D,MAAO,sCAAsC,KAAK,UAAUA,EAAO,IAAI,CAAC,YACzE,CAKgB,SAAAC,EAAkBC,EAAoCC,EAInE,CACE,IAAAC,EAAQ,KAAK,OAAOC,EAA4BH,CAAO,EAAI,OAAO,SAAW,GAAG,EAAI,IACpFI,EAEJ,KAAM,CAAE,MAAAC,EAAO,QAAAC,EAAS,MAAAC,CAAA,EAAUN,EAElC,IAAIO,EAAsC,CACzC,WAAY,qBACZ,QAAS,UACT,KAAQR,EAAQ,KAChB,IAAOA,EAAQ,IACf,YAA6BA,EAAS,aAAeA,EAAQ,KAC7D,OAAU,CACT,QAAS,2BACT,MAASE,EACT,IAAO,GAAGO,CAAuB,IAAIF,CAAK,MAAMP,EAAQ,OAAO,GAC/D,cAAiB,MACjB,aAAgB,6BAChB,cAAiB,kCACjB,gBAAmB,aACnB,gBAAmB,GACnB,wBAA2B,CAC1B,QAAS,uBACT,kBAAqBO,EAAM,kBAAkB,EAC7C,qBAAwB,sDACxB,mBAAsB,GACtB,aAAgB,iCACjB,CACD,EACA,UAAaP,EAAQ,IACrB,OAAUA,EAAQ,MAClB,SAAYA,EAAQ,UAAYA,EAAQ,SAAS,OAAS,EAAIA,EAAQ,SAASA,EAAQ,SAAS,OAAS,CAAC,EAAE,KAAO,EAAA,EA4EhH,GAxEAA,EAAQ,gBACXQ,EAAe,MAAW,GAAGE,CAAmB,GAAGV,EAAQ,cAAc,IAAI,IAG1EE,EAAQ,GACKE,EAAA,CACf,QAAS,uBACT,aAAgB,CACf,QAAS,iBACT,MAAS,IACT,SAAY,KAC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