id
stringlengths 12
53
| messages
listlengths 3
3
|
|---|---|
code_sponsored-products_2b3dbe93
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of sponsored-products/react/AdsAnalytics.tsx from the sponsored-products VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport { AdsAnalytics } from './components/AdsAnalytics'\n\nexport default AdsAnalytics\n\n```"
}
] |
code_sponsored-products_64662068
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of sponsored-products/store/interfaces.json from the sponsored-products VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"sponsored-badge\": {\n \"component\": \"SponsoredBadge\"\n },\n \"ads-analytics\": {\n \"component\": \"AdsAnalytics\"\n }\n}\n\n```"
}
] |
code_sponsored-products_f1ef9135
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of sponsored-products/react/typings/gql.d.ts from the sponsored-products VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\ndeclare module '*.gql' {\n import { DocumentNode } from 'graphql'\n\n const Schema: DocumentNode\n\n export default Schema\n}\n\ndeclare module '*.graphql' {\n import { DocumentNode } from 'graphql'\n\n const schema: DocumentNode\n\n export default schema\n}\n\n```"
}
] |
code_sponsored-products_a2e23938
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of sponsored-products/react/typings/css.d.ts from the sponsored-products VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\ndeclare module '*.css' {\n type Styles = {\n [selector: string]: string\n }\n\n const styles: Styles\n\n export default styles\n}\n\n```"
}
] |
code_sponsored-products_39be278d
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of sponsored-products/react/utils/isSponsored.ts from the sponsored-products VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { Product } from 'vtex.product-summary-context/react/ProductSummaryTypes'\n\nconst isSponsored = (product: Product) => !!product?.advertisement?.adId\n\nexport default isSponsored\n\n```"
}
] |
code_sponsored-products_47fa6e4f
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of sponsored-products/react/utils/index.ts from the sponsored-products VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport isSponsored from './isSponsored'\n\nexport { isSponsored }\n\n```"
}
] |
code_sponsored-products_09942bd0
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of sponsored-products/react/utils/__tests__/isSponsored.test.ts from the sponsored-products VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { Product } from 'vtex.product-summary-context/react/ProductSummaryTypes'\n\nimport ProductFactory from '../../__testUtils__/factories/product'\nimport isSponsored from '../isSponsored'\n\ndescribe('#isSponsored', () => {\n describe('when the product is sponsored', () => {\n const product = ProductFactory.build() as Product\n\n it('should return true', () => {\n expect(isSponsored(product)).toBe(true)\n })\n })\n\n describe('when the product is not sponsored', () => {\n const product = ProductFactory.build({}, { isSponsored: false }) as Product\n\n it('should return true', () => {\n expect(isSponsored(product)).toBe(false)\n })\n })\n})\n\n```"
}
] |
code_sponsored-products_ef723da1
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of sponsored-products/react/components/SponsoredBadge/SponsoredBadge.tsx from the sponsored-products VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport React from 'react'\nimport { FormattedMessage } from 'react-intl'\nimport { useCssHandles } from 'vtex.css-handles'\nimport { ProductSummaryContext } from 'vtex.product-summary-context'\n\nimport { isSponsored } from '../../utils'\n\nconst { useProductSummary } = ProductSummaryContext\nconst CSS_HANDLES = ['badgeContainer', 'badgeText'] as const\n\nexport const SponsoredBadge = () => {\n const { product } = useProductSummary()\n const { handles } = useCssHandles(CSS_HANDLES)\n\n if (!isSponsored(product)) return null\n\n return (\n <div className={handles.badgeContainer}>\n <span className={handles.badgeText}>\n <FormattedMessage id=\"store/sponsoredBadge.title\" />\n </span>\n </div>\n )\n}\n\n```"
}
] |
code_sponsored-products_f5e6fb38
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of sponsored-products/react/components/AdsAnalytics/AdsAnalytics.types.tsx from the sponsored-products VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport { ProductSummaryTypes } from 'vtex.product-summary-context'\n\ntype ProductSummaryProps = {\n product: ProductSummaryTypes.Product\n position: number\n [x: string]: unknown\n}\n\nexport type AdsAnalyticsProps = {\n ProductSummary: React.FC<ProductSummaryProps>\n} & ProductSummaryProps\n\nexport type DataProperties = {\n 'data-van-prod-id': string\n 'data-van-prod-name': string\n 'data-van-position': number\n 'data-van-aid': string\n 'data-van-cid': string\n 'data-van-req-id': string\n 'data-van-res-id': string\n 'data-van-cpc': number\n}\n\n```"
}
] |
code_sponsored-products_d5212ec3
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of sponsored-products/react/components/AdsAnalytics/AdsAnalytics.tsx from the sponsored-products VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport React from 'react'\nimport { useCssHandles } from 'vtex.css-handles'\n\nimport { isSponsored } from '../../utils'\nimport { AdsAnalyticsProps } from './AdsAnalytics.types'\nimport { getDataProperties } from './utils'\n\nconst CSS_HANDLES = ['adsAnalyticsContainer'] as const\n\nexport const AdsAnalytics = ({\n ProductSummary,\n ...productSummaryProps\n}: AdsAnalyticsProps) => {\n const { handles } = useCssHandles(CSS_HANDLES)\n const { product, position } = productSummaryProps\n\n if (!isSponsored(product)) return <ProductSummary {...productSummaryProps} />\n\n const dataProperties = getDataProperties({ product, position })\n\n return (\n <div\n {...dataProperties}\n className={handles.adsAnalyticsContainer}\n data-testid=\"ads-analytics\"\n >\n <ProductSummary {...productSummaryProps} />\n </div>\n )\n}\n\n```"
}
] |
code_sponsored-products_ace03257
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of sponsored-products/react/components/SponsoredBadge/__tests__/SponsoredBadge.test.tsx from the sponsored-products VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport '@testing-library/jest-dom'\nimport { render, screen } from '@vtex/test-tools/react'\nimport React from 'react'\nimport { ProductSummaryContext } from 'vtex.product-summary-context'\nimport { Product } from 'vtex.product-summary-context/react/ProductSummaryTypes'\n\nimport ProductFactory from '../../../__testUtils__/factories/product'\nimport { SponsoredBadge } from '../SponsoredBadge'\n\nconst setupTests = ({ isSponsored = true } = {}) => {\n const product = ProductFactory.build({}, { isSponsored }) as Product\n\n return render(\n <ProductSummaryContext.ProductSummaryProvider product={product}>\n <SponsoredBadge />\n </ProductSummaryContext.ProductSummaryProvider>\n )\n}\n\ndescribe('<SponsoredBadge />', () => {\n describe('when the product is sponsored', () => {\n beforeEach(() => setupTests())\n\n it('should render the badge', () => {\n expect(screen.getByText(/Sponsored/i)).toBeInTheDocument()\n })\n })\n\n describe('when the product is not sponsored', () => {\n beforeEach(() => setupTests({ isSponsored: false }))\n\n it('should not render the badge', () => {\n expect(screen.queryByText(/Sponsored/i)).not.toBeInTheDocument()\n })\n })\n})\n\n```"
}
] |
code_sponsored-products_7f961fcf
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of sponsored-products/react/components/AdsAnalytics/utils/index.ts from the sponsored-products VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport getDataProperties from './getDataProperties'\n\nexport { getDataProperties }\n\n```"
}
] |
code_sponsored-products_9feb9c9a
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of sponsored-products/react/components/AdsAnalytics/utils/getDataProperties.ts from the sponsored-products VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { Product } from 'vtex.product-summary-context/react/ProductSummaryTypes'\n\nimport { isSponsored } from '../../../utils'\nimport { DataProperties } from '../AdsAnalytics.types'\n\ntype GetDataPropertiesArgs = {\n product: Product\n position: number\n}\n\nconst getDataProperties = ({\n product,\n position,\n}: GetDataPropertiesArgs): Nullable<DataProperties> => {\n if (!isSponsored(product)) return\n\n const {\n productId,\n productName,\n advertisement: { adId, campaignId, adRequestId, adResponseId, actionCost },\n } = product\n\n return {\n 'data-van-prod-id': productId,\n 'data-van-prod-name': productName,\n 'data-van-position': position,\n 'data-van-aid': adId,\n 'data-van-cid': campaignId,\n 'data-van-req-id': adRequestId,\n 'data-van-res-id': adResponseId,\n 'data-van-cpc': actionCost,\n }\n}\n\nexport default getDataProperties\n\n```"
}
] |
code_sponsored-products_6a1519b9
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of sponsored-products/react/components/AdsAnalytics/__tests__/AdsAnalytics.test.tsx from the sponsored-products VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport '@testing-library/jest-dom'\nimport { render } from '@vtex/test-tools/react'\nimport React from 'react'\nimport { Product } from 'vtex.product-summary-context/react/ProductSummaryTypes'\n\nimport ProductFactory from '../../../__testUtils__/factories/product'\nimport { AdsAnalytics } from '../AdsAnalytics'\n\nconst testId = 'product-summary'\nconst MockProductSummary = () => <div data-testid={testId}>ProductSummary</div>\n\nconst position = 1\n\nconst setupTest = (product: Product) => {\n return render(\n <AdsAnalytics\n ProductSummary={MockProductSummary}\n product={product}\n position={position}\n />\n )\n}\n\ndescribe('<AdsAnalytics />', () => {\n describe('when a product is sponsored', () => {\n const product = ProductFactory.build() as Product\n\n it('should render the ProductSummary component passed as prop', () => {\n const { getByTestId } = setupTest(product)\n\n expect(getByTestId(testId)).toBeInTheDocument()\n })\n\n it('should add a wrapper with the correct data properties', () => {\n const { getByTestId } = setupTest(product)\n const wrapper = getByTestId('ads-analytics')\n const {\n productId,\n productName,\n advertisement: {\n campaignId,\n adId,\n adRequestId,\n adResponseId,\n actionCost,\n },\n } = product\n\n expect(wrapper.getAttribute('data-van-prod-id')).toBe(productId)\n expect(wrapper.getAttribute('data-van-prod-name')).toBe(productName)\n expect(wrapper.getAttribute('data-van-position')).toBe('1')\n expect(wrapper.getAttribute('data-van-cid')).toBe(campaignId)\n expect(wrapper.getAttribute('data-van-aid')).toBe(adId)\n expect(wrapper.getAttribute('data-van-req-id')).toBe(adRequestId)\n expect(wrapper.getAttribute('data-van-res-id')).toBe(adResponseId)\n expect(wrapper.getAttribute('data-van-cpc')).toBe(actionCost.toString())\n })\n })\n\n describe('when a product is not sponsored', () => {\n const product = ProductFactory.build({}, { isSponsored: false }) as Product\n\n it('should render the ProductSummary component passed as prop', () => {\n const { getByTestId } = setupTest(product)\n\n expect(getByTestId(testId)).toBeInTheDocument()\n })\n\n it('should not add a wrapper with the data properties', () => {\n const { queryByTestId } = setupTest(product)\n\n expect(queryByTestId('ads-analytics')).not.toBeInTheDocument()\n })\n })\n})\n\n```"
}
] |
code_sponsored-products_df8be6af
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of sponsored-products/react/components/AdsAnalytics/utils/__tests__/getDataProperties.test.ts from the sponsored-products VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { Product } from 'vtex.product-summary-context/react/ProductSummaryTypes'\n\nimport ProductFactory from '../../../../__testUtils__/factories/product'\nimport getDataProperties from '../getDataProperties'\n\nconst position = 1\n\ndescribe('#getDataProperties', () => {\n describe('when product is sponsored', () => {\n const product = ProductFactory.build() as Product\n\n it('returns the correct data properties to be added to the HTML', () => {\n const dataProperties = getDataProperties({ product, position })\n\n expect(dataProperties).toMatchObject({\n 'data-van-prod-id': product.productId,\n 'data-van-prod-name': product.productName,\n 'data-van-position': position,\n 'data-van-aid': product.advertisement.adId,\n 'data-van-cid': product.advertisement.campaignId,\n 'data-van-req-id': product.advertisement.adRequestId,\n 'data-van-res-id': product.advertisement.adResponseId,\n 'data-van-cpc': product.advertisement.actionCost,\n })\n })\n })\n\n describe('when product is not sponsored', () => {\n const product = ProductFactory.build({}, { isSponsored: false }) as Product\n\n it('returns undefined', () => {\n const dataProperties = getDataProperties({ product, position })\n\n expect(dataProperties).toBeUndefined()\n })\n })\n})\n\n```"
}
] |
code_sponsored-products_d300efcd
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of sponsored-products/react/__testUtils__/factories/product.ts from the sponsored-products VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { faker } from '@faker-js/faker'\nimport { Factory } from 'rosie'\nimport { Product } from 'vtex.product-summary-context/react/ProductSummaryTypes'\n\nconst ProductFactory = Factory.define<Partial<Product>>('product')\n .option('isSponsored', true)\n .attr('productId', faker.string.uuid)\n .attr('productName', faker.commerce.productName())\n .attr('advertisement', ['isSponsored'], (isSponsored: boolean) => {\n if (!isSponsored) return\n\n return {\n adId: faker.string.uuid(),\n campaignId: faker.string.uuid(),\n adRequestId: faker.string.uuid(),\n adResponseId: faker.string.uuid(),\n actionCost: faker.number.float({ min: 0, max: 5, precision: 0.01 }),\n }\n })\n\nexport default ProductFactory\n\n```"
}
] |
code_criteo_d18576de
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of criteo/docs/README.md from the criteo VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```markdown\n# Criteo\nGet the holiday data you need to drive more sales. See the season’s peaks, top categories, and biggest mobile moments across the globe in our report and interactive map.\nFor more information please visit, [Criteo](https://www.criteo.com/) website.\n\n\n## How to install\n\nOpen the VTEX APP Store and install the app on your store.\n\nor\n\nRun the following command:\n\n```sh\nvtex install vtex.criteo@0.x\n```\n\nNext, open the app settings on your admin and fill the form with your Criteo details.\n```"
}
] |
code_criteo_2b06cd82
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of criteo/react/index.tsx from the criteo VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport { canUseDOM } from 'vtex.render-runtime'\nimport { PixelMessage } from './typings/events'\nimport { fetchEmail, getSiteType } from './helpers'\n\nasync function dispatchEvent(event: CriteoQ) {\n const { criteo_q = [], criteo_id: account } = window\n const setAccount: CriteoAccountEvent = { event: 'setAccount', account }\n const setEmail: CriteoEmailEvent = {\n event: 'setEmail',\n email: [await fetchEmail()],\n }\n const setSiteType: CriteoSiteTypeEvent = {\n event: 'setSiteType',\n type: getSiteType(),\n }\n criteo_q.push(setAccount, setEmail, setSiteType, event)\n}\n\nfunction handleMessages(event: PixelMessage) {\n const { criteo_q = [], criteo_id: account } = window\n if (!account) return\n\n switch (event.data.eventName) {\n case 'vtex:pageInfo': {\n if (event.data.eventType === 'homeView') {\n const setHomeView: CriteoViewHomeEvent = {\n event: 'viewHome',\n tms: 'gtm-vtex',\n }\n dispatchEvent(setHomeView)\n }\n break\n }\n case 'vtex:departmentView':\n case 'vtex:internalSiteSearchView':\n case 'vtex:categoryView': {\n const {\n data: { products },\n } = event\n const item: string[] = products\n .slice(0, 3)\n .map<string>(({ productId }) => productId)\n const setViewList: CriteoViewListEvent = {\n event: 'viewList',\n tms: 'gtm-vtex',\n item,\n }\n dispatchEvent(setViewList)\n break\n }\n case 'vtex:productView': {\n const {\n data: {\n product: { productId },\n },\n } = event\n const setViewItem: CriteoViewItemEvent = {\n event: 'viewItem',\n tms: 'gtm-vtex',\n item: productId,\n }\n dispatchEvent(setViewItem)\n break\n }\n case 'vtex:orderPlaced': {\n const {\n data: { transactionId, transactionProducts },\n } = event\n\n const item: CriteoTrackTransactionItem[] = transactionProducts.map<\n CriteoTrackTransactionItem\n >(({ id, sellingPrice, quantity }) => ({\n id,\n price: sellingPrice,\n quantity,\n }))\n\n const setTrackTransaction: CriteoTrackTransactionEvent = {\n event: 'trackTransaction',\n id: transactionId,\n tms: 'gtm-vtex',\n item,\n }\n\n dispatchEvent(setTrackTransaction)\n break\n }\n default:\n break\n }\n}\n\nif (canUseDOM) {\n window.addEventListener('message', handleMessages)\n}\n\n```"
}
] |
code_criteo_d9622c61
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of criteo/react/package.json from the criteo VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"author\": \"vtex\",\n \"scripts\": {\n \"test\": \"vtex-test-tools test\"\n },\n \"devDependencies\": {\n \"@types/graphql\": \"^14.2.0\",\n \"@types/jest\": \"^24.0.12\",\n \"@types/node\": \"^12.0.0\",\n \"@types/ramda\": \"^0.25.42\",\n \"@types/react\": \"^16.8.16\",\n \"@types/react-intl\": \"^2.3.17\",\n \"@vtex/test-tools\": \"^0.3.2\",\n \"apollo-cache-inmemory\": \"^1.5.1\",\n \"apollo-client\": \"^2.5.1\",\n \"eslint\": \"^6.4.0\",\n \"eslint-config-vtex\": \"^11.0.0\",\n \"eslint-config-vtex-react\": \"^5.0.1\",\n \"prettier\": \"^1.17.1\",\n \"typescript\": \"3.5.2\",\n \"vtex.pixel-interfaces\": \"http://vtex.vteximg.com.br/_v/public/typings/v1/vtex.pixel-interfaces@1.1.0/public/_types/react\",\n \"vtex.render-runtime\": \"http://vtex.vteximg.com.br/_v/public/typings/v1/vtex.render-runtime@8.67.0/public/@types/vtex.render-runtime\"\n },\n \"version\": \"0.0.5\"\n}\n\n```"
}
] |
code_criteo_a2996095
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of criteo/store/interfaces.json from the criteo VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"pixel.criteo\": {\n \"component\": \"index\"\n }\n}\n\n```"
}
] |
code_criteo_7db25c77
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of criteo/react/typings/events.d.ts from the criteo VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nexport interface PixelMessage extends MessageEvent {\n data:\n | PageInfo\n | ProductViewData\n | ProductClickData\n | OrderPlacedData\n | PageViewData\n | ProductImpressionData\n | AddToCartData\n | RemoveToCartData\n | CategoryViewData\n | DepartmentViewData\n | InternalSiteSearchViewData\n}\n\nexport interface InternalSiteSearchViewData extends EventData {\n event: 'internalSiteSearchView'\n eventName: 'vtex:internalSiteSearchView'\n products: Product[]\n}\n\nexport interface CategoryViewData extends EventData {\n event: 'categoryView'\n eventName: 'vtex:categoryView'\n products: Product[]\n}\n\nexport interface DepartmentViewData extends EventData {\n event: 'departmentView'\n eventName: 'vtex:departmentView'\n products: Product[]\n}\n\nexport interface PageInfo extends EventData {\n event: 'pageInfo'\n eventName: 'vtex:pageInfo'\n eventType: string\n}\n\nexport interface EventData {\n event: string\n eventName: string\n currency: string\n}\n\nexport interface PageViewData extends EventData {\n event: 'pageView'\n eventName: 'vtex:pageView'\n pageTitle: string\n pageUrl: string\n referrer: string\n}\n\nexport interface AddToCartData extends EventData {\n event: 'addToCart'\n eventName: 'vtex:addToCart'\n items: CartItem[]\n}\n\nexport interface RemoveToCartData extends EventData {\n event: 'removeFromCart'\n eventName: 'vtex:removeFromCart'\n items: CartItem[]\n}\n\nexport interface OrderPlacedData extends Order, EventData {\n event: 'orderPlaced'\n eventName: 'vtex:orderPlaced'\n}\n\nexport interface ProductViewData extends EventData {\n event: 'productView'\n eventName: 'vtex:productView'\n product: Product\n}\n\nexport interface ProductClickData extends EventData {\n event: 'productClick'\n eventName: 'vtex:productClick'\n product: Product\n}\n\nexport interface ProductImpressionData extends EventData {\n event: 'productImpression'\n eventName: 'vtex:productImpression'\n impressions: Impression[]\n product?: Product // deprecated, use impressions list!\n position?: number // deprecated, use impressions list!\n list: string\n}\n\ninterface CartItem {\n skuId: string\n variant: string\n price: number\n name: string\n quantity: number\n productRefId: string\n brand: string\n category: string\n}\n\nexport interface Order {\n currency: string\n accountName: string\n orderGroup: string\n salesChannel: string\n coupon: string\n visitorType: string\n visitorContactInfo: string[]\n visitorAddressState: string\n visitorAddressCountry: string\n visitorAddressPostalCode: string\n transactionId: string\n transactionDate: string\n transactionAffiliation: string\n transactionTotal: number\n transactionShipping: number\n transactionSubtotal: number\n transactionDiscounts: number\n transactionTax: number\n transactionCurrency: string\n transactionPaymentType: PaymentType[]\n transactionShippingMethod: ShippingMethod[]\n transactionProducts: ProductOrder[]\n transactionPayment: {\n id: string\n }\n}\n\nexport interface Impression {\n product: Product\n position: number\n}\n\ninterface PaymentType {\n group: string\n paymentSystemName: string\n installments: number\n value: number\n}\n\ninterface ShippingMethod {\n itemId: string\n selectedSla: string\n}\n\ninterface ProductOrder {\n id: string\n name: string\n sku: string\n skuRefId: string\n skuName: string\n productRefId: string\n ean: string\n slug: string\n brand: string\n brandId: string\n seller: string\n sellerId: string\n category: string\n categoryId: string\n categoryTree: string[]\n categoryIdTree: string[]\n priceTags: PriceTag[]\n originalPrice: number\n price: number\n sellingPrice: number\n tax: number\n quantity: number\n components: any[]\n measurementUnit: string\n unitMultiplier: number\n}\n\ninterface PriceTag {\n identifier: string\n isPercentual: boolean\n value: number\n}\n\ninterface Product {\n brand: string\n categoryId?: string // inconsistency\n categories: string[]\n productId: string\n productName: string\n selectedSku?: string // inconsistency\n items: Item[]\n sku: Item\n [key: string]: any\n}\n\ninterface Item {\n itemId: string\n name: string\n seller?: Seller\n [key: string]: any\n}\n\ninterface Seller {\n commertialOffer: CommertialOffer\n [key: string]: any\n}\n\ninterface CommertialOffer {\n Price: number\n [key: string]: any\n}\n\n```"
}
] |
code_criteo_61b37cd1
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of criteo/react/typings/criteo.d.ts from the criteo VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\ntype CriteoQ =\n | CriteoAccountEvent\n | CriteoSiteTypeEvent\n | CriteoEmailEvent\n | CriteoTrackTransactionEvent\n | CriteoViewHomeEvent\n | CriteoViewItemEvent\n | CriteoViewListEvent\n\ninterface CriteoEvent {\n event: string\n}\n\ninterface CriteoAccountEvent extends CriteoEvent {\n event: 'setAccount'\n account: string\n}\n\ninterface CriteoSiteTypeEvent extends CriteoEvent {\n event: 'setSiteType'\n type: 'm' | 't' | 'd'\n}\n\ninterface CriteoEmailEvent extends CriteoEvent {\n event: 'setEmail'\n email: string[]\n}\n\ninterface CriteoPixelEvent {\n tms: 'gtm-vtex'\n}\n\ninterface CriteoViewHomeEvent extends CriteoEvent, CriteoPixelEvent {\n event: 'viewHome'\n}\n\ninterface CriteoViewListEvent extends CriteoEvent, CriteoPixelEvent {\n event: 'viewList'\n item: string[]\n}\n\ninterface CriteoViewItemEvent extends CriteoEvent, CriteoPixelEvent {\n event: 'viewItem'\n item: string\n}\n\ninterface CriteoTrackTransactionEvent extends CriteoEvent, CriteoPixelEvent {\n event: 'trackTransaction'\n id: string\n item: CriteoTrackTransactionItem[]\n}\n\ninterface CriteoTrackTransactionItem {\n id: string\n price: number\n quantity: number\n}\n\n```"
}
] |
code_criteo_d5949eab
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of criteo/react/typings/vtex.render-runtime.d.ts from the criteo VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\ndeclare module 'vtex.render-runtime' {\n export const canUseDOM: boolean\n}\n\n```"
}
] |
code_criteo_0f90f488
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of criteo/react/typings/global.d.ts from the criteo VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\ninterface Window extends Window {\n criteo_q: CriteoQ[]\n criteo_id: string\n}\n\n```"
}
] |
code_criteo_8a420c7b
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of criteo/react/helpers/index.tsx from the criteo VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nexport async function fetchEmail(): Promise<string> {\n try {\n const { Email: email } = await (await fetch(\n '/no-cache/profileSystem/getProfile'\n )).json()\n return email\n } catch (err) {\n console.log(`Couldn't fetch logged in use email`)\n console.log(err)\n }\n return ''\n}\n\nexport function getSiteType() {\n return /iPad/.test(navigator.userAgent)\n ? 't'\n : /Mobile|iP(hone|od)|Android|BlackBerry|IEMobile/.test(navigator.userAgent)\n ? 'm'\n : 'd'\n}\n\n```"
}
] |
code_structured-data_9f323f84
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of structured-data/messages/en.json from the structured-data VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"admin/application-settings.decimals.title\": \"Number of decimals\",\n \"admin/application-settings.prices-with-tax.title\": \"Prices with tax\",\n \"admin/application-settings.decimals.description\": \"Set the number of decimals you want the prices to show\",\n \"admin/application-settings.prices-with-tax.description\": \"Add tax to the price shown on Google\"\n}\n\n```"
}
] |
code_structured-data_89e23495
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of structured-data/docs/README.md from the structured-data VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```markdown\n# Structured Data\n<!-- DOCS-IGNORE:start -->\n<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->\n[](#contributors-)\n<!-- ALL-CONTRIBUTORS-BADGE:END -->\n<!-- DOCS-IGNORE:end -->\n\n> Implements Structured Data schemas.\n\n<!-- DOCS-IGNORE:start -->\n## Contributors ✨\n\nThanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):\n\n<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->\n<!-- prettier-ignore-start -->\n<!-- markdownlint-disable -->\n<table>\n <tr>\n <td align=\"center\"><a href=\"https://github.com/MatheusR42\"><img src=\"https://avatars0.githubusercontent.com/u/16908590?v=4\" width=\"100px;\" alt=\"\"/><br /><sub><b>Matheus Araujo</b></sub></a><br /><a href=\"https://github.com/vtex-apps/structured-data/commits?author=MatheusR42\" title=\"Code\">💻</a></td>\n </tr>\n</table>\n\n<!-- markdownlint-enable -->\n<!-- prettier-ignore-end -->\n<!-- ALL-CONTRIBUTORS-LIST:END -->\n\nThis project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind are welcome!\n<!-- DOCS-IGNORE:end -->\n```"
}
] |
code_structured-data_df8af6b8
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of structured-data/react/ProductList.tsx from the structured-data VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport React from 'react'\nimport { jsonLdScriptProps } from 'react-schemaorg'\nimport { ItemList, WithContext, ListItem } from 'schema-dts'\nimport { useRuntime } from 'vtex.render-runtime'\n\nimport useAppSettings from './hooks/useAppSettings'\nimport { parseToJsonLD } from './Product'\n\ninterface Product {\n productName: string\n linkText: string\n link: string\n items: unknown[]\n}\n\ninterface Props {\n products?: Product[]\n}\n\nexport function getProductList({\n disableOffers,\n decimals,\n pricesWithTax,\n currency,\n products,\n}: {\n disableOffers: boolean\n decimals: number\n pricesWithTax: boolean\n currency: string\n products?: Product[]\n}) {\n if (!Array.isArray(products)) {\n return null\n }\n\n const productItems: ListItem[] = products.map((product, index) => {\n const [selectedItem] = product.items\n const item = parseToJsonLD({\n product,\n selectedItem,\n currency,\n disableOffers,\n decimals,\n pricesWithTax,\n })\n\n return {\n '@type': 'ListItem',\n position: index + 1,\n ...(item && { item }),\n }\n })\n\n return {\n '@context': 'https://schema.org',\n '@type': 'ItemList',\n itemListElement: productItems,\n } as WithContext<ItemList>\n}\n\nfunction ProductList({ products }: Props) {\n const {\n culture: { currency },\n } = useRuntime()\n\n const { disableOffers, decimals, pricesWithTax } = useAppSettings()\n const productListLD: WithContext<ItemList> | null = getProductList({\n disableOffers,\n decimals,\n pricesWithTax,\n currency,\n products,\n })\n\n if (!productListLD) {\n return null\n }\n\n return <script {...jsonLdScriptProps<ItemList>(productListLD)} />\n}\n\nexport default ProductList\n\n```"
}
] |
code_structured-data_26fc1221
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of structured-data/react/ProductBreadcrumb.tsx from the structured-data VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport React, { FC } from 'react'\nimport { BreadcrumbList, ListItem } from 'schema-dts'\nimport { jsonLdScriptProps } from 'react-schemaorg'\n\nimport { getBaseUrl } from './modules/baseUrl'\n\ninterface CategoryTreeItem {\n name: string\n href: string\n}\n\nexport const getProductBreadcrumb = (\n categoryTree?: CategoryTreeItem[],\n productName?: string,\n productSlug?: string\n) => {\n if (!Array.isArray(categoryTree)) {\n return null\n }\n\n const baseUrl = getBaseUrl()\n\n const categoryItems: ListItem[] = categoryTree.map((category, index) => ({\n '@type': 'ListItem',\n position: index + 1,\n name: category.name,\n item: baseUrl + category.href,\n }))\n\n if (productName && productSlug) {\n categoryItems.push({\n '@type': 'ListItem',\n position: categoryItems.length + 1,\n name: productName,\n item: `${baseUrl}/${productSlug}/p`,\n })\n }\n\n return jsonLdScriptProps<BreadcrumbList>({\n '@context': 'https://schema.org',\n '@type': 'BreadcrumbList',\n itemListElement: categoryItems,\n })\n}\n\ninterface Props {\n categoryTree?: CategoryTreeItem[]\n productName?: string\n productSlug?: string\n}\n\nconst ProductBreadcrumbStructuredData: FC<Props> = ({\n categoryTree,\n productName,\n productSlug,\n}) => {\n const breadcrumbLD = getProductBreadcrumb(\n categoryTree,\n productName,\n productSlug\n )\n\n if (!breadcrumbLD) {\n return null\n }\n\n return <script {...breadcrumbLD} />\n}\n\nexport default ProductBreadcrumbStructuredData\n\n```"
}
] |
code_structured-data_d8ef18d3
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of structured-data/react/SearchAction.tsx from the structured-data VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport React from 'react'\nimport { Helmet } from 'react-helmet'\nimport { WebSite } from 'schema-dts'\nimport { helmetJsonLdProp } from 'react-schemaorg'\n\nimport { getBaseUrl } from './modules/baseUrl'\n\ninterface Props {\n searchTermPath?: string\n}\n\nfunction SearchAction({ searchTermPath }: Props) {\n const baseUrl = getBaseUrl()\n const path = !searchTermPath ? '/' : searchTermPath\n\n return (\n <Helmet\n script={[\n helmetJsonLdProp<WebSite>({\n '@context': 'https://schema.org',\n '@type': 'WebSite',\n url: baseUrl,\n potentialAction: {\n '@type': 'SearchAction',\n target: `${baseUrl}${path}{search_term_string}?map=ft`,\n // @ts-expect-error it's a valid property\n 'query-input': 'required name=search_term_string',\n },\n }),\n ]}\n />\n )\n}\n\nexport default SearchAction\n\n```"
}
] |
code_structured-data_9099a420
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of structured-data/react/package.json from the structured-data VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"name\": \"structured-data\",\n \"scripts\": {\n \"test\": \"vtex-test-tools test\"\n },\n \"dependencies\": {\n \"apollo-client\": \"^2.6.8\",\n \"ramda\": \"^0.26.1\",\n \"react\": \"^16.12.0\",\n \"react-apollo\": \"^3.1.3\",\n \"react-dom\": \"^16.12.0\",\n \"react-helmet\": \"^5.2.1\",\n \"react-intl\": \"^3.12.0\",\n \"react-schemaorg\": \"^1.3.1\"\n },\n \"devDependencies\": {\n \"@apollo/react-testing\": \"^3.1.3\",\n \"@testing-library/react-hooks\": \"^7.0.1\",\n \"@types/jest\": \"^25.1.4\",\n \"@types/node\": \"^13.9.8\",\n \"@types/ramda\": \"^0.26.5\",\n \"@types/react\": \"^16.9.31\",\n \"@types/react-helmet\": \"^5.0.9\",\n \"@vtex/test-tools\": \"^3.1.0\",\n \"@vtex/tsconfig\": \"^0.4.4\",\n \"apollo-cache-inmemory\": \"^1.6.5\",\n \"graphql\": \"^14.6.0\",\n \"schema-dts\": \"^0.8.2\",\n \"typescript\": \"3.9.7\",\n \"vtex.apps-graphql\": \"http://vtex.vtexassets.com/_v/public/typings/v1/vtex.apps-graphql@3.17.4/public/@types/vtex.apps-graphql\",\n \"vtex.render-runtime\": \"http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@8.134.11/public/@types/vtex.render-runtime\",\n \"vtex.structured-data\": \"http://vtex.vtexassets.com/_v/public/typings/v1/vtex.structured-data@0.12.1/public/@types/vtex.structured-data\"\n },\n \"version\": \"0.16.1\"\n}\n\n```"
}
] |
code_structured-data_24576582
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of structured-data/react/SearchBreadcrumb.tsx from the structured-data VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport React, { FC } from 'react'\nimport { Helmet } from 'vtex.render-runtime'\nimport { BreadcrumbList } from 'schema-dts'\nimport { helmetJsonLdProp } from 'react-schemaorg'\n\nimport { getBaseUrl } from './modules/baseUrl'\n\ninterface SearchBreadcrumbItem {\n name: string\n href: string\n}\n\nconst getSearchBreadcrumb = (breadcrumb?: SearchBreadcrumbItem[]) => {\n if (!Array.isArray(breadcrumb) || breadcrumb?.length === 0) {\n return {}\n }\n\n const baseUrl = getBaseUrl()\n\n return helmetJsonLdProp<BreadcrumbList>({\n '@context': 'https://schema.org',\n '@type': 'BreadcrumbList',\n itemListElement: breadcrumb.map((item, index) => ({\n '@type': 'ListItem',\n position: index + 1,\n name: item.name,\n item: baseUrl + item.href,\n })),\n })\n}\n\ninterface Props {\n breadcrumb?: SearchBreadcrumbItem[]\n}\n\nconst SearchBreadcrumbStructuredData: FC<Props> = ({ breadcrumb }) => {\n const breadcrumbLD = getSearchBreadcrumb(breadcrumb)\n\n return <Helmet script={[breadcrumbLD]} />\n}\n\nexport default SearchBreadcrumbStructuredData\n\n```"
}
] |
code_structured-data_197da61d
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of structured-data/react/Product.d.ts from the structured-data VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nexport function parseToJsonLD({\n product,\n selectedItem,\n currency,\n disableOffers,\n decimals,\n pricesWithTax,\n userSellerDefault,\n}: {\n product: unknown\n selectedItem: unknown\n currency: string\n disableOffers: boolean\n decimals: number\n pricesWithTax: boolean\n userSellerDefault?: boolean\n}): {\n '@context': string\n '@type': string\n '@id': string\n name: string\n brand: {\n '@type': string\n name: string\n }\n image: string\n description: string\n gtin: string\n mpn: string\n sku: number\n category: string\n offers: {\n '@type': string\n lowPrice: number\n highPrice: number\n priceCurrency: string\n offers: Array<{\n '@type': string\n seller: {\n '@type': string\n name: string\n }\n }>\n offerCount: number\n }\n}\n\ndeclare const _default: import('react').MemoExoticComponent<typeof StructuredData>\n\nexport default _default\n\ndeclare function StructuredData({\n product,\n selectedItem,\n}: {\n product: unknown\n selectedItem: unknown\n}): JSX.Element\n\ndeclare namespace StructuredData {\n namespace propTypes {\n const product: unknown\n const selectedItem: unknown\n }\n}\n\n```"
}
] |
code_structured-data_fd09f3ad
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of structured-data/react/Product.js from the structured-data VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```javascript\n/* eslint-disable react/jsx-filename-extension */\nimport React, { memo } from 'react'\nimport { useRuntime } from 'vtex.render-runtime'\nimport PropTypes from 'prop-types'\n// eslint-disable-next-line no-restricted-imports\nimport { pathOr, path, sort, last, flatten } from 'ramda'\nimport { jsonLdScriptProps } from 'react-schemaorg'\n\nimport useAppSettings from './hooks/useAppSettings'\nimport { getBaseUrl } from './modules/baseUrl'\n\nconst getSpotPrice = path(['commertialOffer', 'spotPrice'])\nconst getPrice = path(['commertialOffer', 'Price'])\nconst getTax = path(['commertialOffer', 'Tax'])\nconst getAvailableQuantity = pathOr(0, ['commertialOffer', 'AvailableQuantity'])\n\nconst getFinalPrice = (value, getPriceFunc, { decimals, pricesWithTax }) => {\n return pricesWithTax\n ? Math.round(\n (getPriceFunc(value) + getTax(value) + Number.EPSILON) * 10 ** decimals\n ) /\n 10 ** decimals\n : getPriceFunc(value)\n}\n\nconst sortByPriceAsc = sort(\n (itemA, itemB) => getSpotPrice(itemA) - getSpotPrice(itemB)\n)\n\nconst sortByPriceWithTaxAsc = sort(\n (itemA, itemB) =>\n getSpotPrice(itemA) + getTax(itemA) - (getSpotPrice(itemB) + getTax(itemB))\n)\n\nconst isSkuAvailable = (sku) => getAvailableQuantity(sku) > 0\n\nconst lowHighForSellers = (sellers, { pricesWithTax }) => {\n const sortedByPrice = pricesWithTax\n ? sortByPriceWithTaxAsc(sellers)\n : sortByPriceAsc(sellers)\n\n const withStock = sortedByPrice.filter(isSkuAvailable)\n\n if (withStock.length === 0) {\n return {\n low: sortedByPrice[0],\n high: last(sortedByPrice),\n }\n }\n\n return {\n low: withStock[0],\n high: last(withStock),\n }\n}\n\nconst IN_STOCK = 'http://schema.org/InStock'\nconst OUT_OF_STOCK = 'http://schema.org/OutOfStock'\n\nconst getSKUAvailabilityString = (seller) =>\n isSkuAvailable(seller) ? IN_STOCK : OUT_OF_STOCK\n\nconst normalizeGTIN = (raw) => {\n if (raw === null || raw === undefined) return null\n const digits = String(raw).replace(/\\D+/g, '')\n\n if (!digits || /^0+$/.test(digits)) return null\n\n const validLengths = [8, 12, 13, 14]\n\n if (validLengths.includes(digits.length)) return digits\n\n const validLengthsTarget = validLengths.find((len) => digits.length < len)\n\n if (validLengthsTarget) return digits.padStart(validLengthsTarget, '0')\n\n return null\n}\n\nconst parseSKUToOffer = (\n item,\n currency,\n { decimals, pricesWithTax, useSellerDefault, gtinValue }\n) => {\n const seller = useSellerDefault\n ? getSellerDefault(item.sellers)\n : lowHighForSellers(item.sellers, { pricesWithTax }).low\n\n const availability = getSKUAvailabilityString(seller)\n const price = getFinalPrice(seller, getSpotPrice, { decimals, pricesWithTax })\n\n // When a product is not available the API can't define its price and returns zero.\n // If we set structured data product price as zero, Google will show that the\n // product it's free (wrong info), but out of stock.\n // It's better just not return any offer in that case.\n if (availability === OUT_OF_STOCK && price === 0) {\n return null\n }\n\n const rawSkuValue = item?.[gtinValue]\n const normalizedGtin = normalizeGTIN(rawSkuValue)\n const offerSku = normalizedGtin || item.itemId\n\n const offer = {\n '@type': 'Offer',\n price,\n priceCurrency: currency,\n availability,\n sku: offerSku,\n itemCondition: 'http://schema.org/NewCondition',\n priceValidUntil: path(['commertialOffer', 'PriceValidUntil'], seller),\n seller: {\n '@type': 'Organization',\n name: seller ? seller.sellerName : '',\n },\n }\n\n return offer\n}\n\nconst getAllSellers = (items) => {\n const allSellers = items.map((item) => item.sellers)\n const flat = flatten(allSellers)\n\n return flat\n}\n\nconst getSellerDefault = (sellers) => {\n const seller = sellers.find((s) => s.sellerDefault)\n\n return seller\n}\n\nconst composeAggregateOffer = (\n product,\n currency,\n {\n decimals,\n pricesWithTax,\n useSellerDefault,\n disableAggregateOffer,\n gtinValue,\n }\n) => {\n const items = product.items || []\n const allSellers = getAllSellers(items)\n const { low, high } = lowHighForSellers(allSellers, { pricesWithTax })\n\n const offersList = items\n .map((element) =>\n parseSKUToOffer(element, currency, {\n decimals,\n pricesWithTax,\n useSellerDefault,\n gtinValue,\n })\n )\n .filter(Boolean)\n\n if (offersList.length === 0) {\n return null\n }\n\n if (disableAggregateOffer) {\n return offersList\n }\n\n const aggregateOffer = {\n '@type': 'AggregateOffer',\n lowPrice: getFinalPrice(low, getSpotPrice, { decimals, pricesWithTax }),\n highPrice: getFinalPrice(high, getPrice, { decimals, pricesWithTax }),\n priceCurrency: currency,\n offers: offersList,\n offerCount: items.length,\n }\n\n return aggregateOffer\n}\n\nconst getCategoryName = (product) =>\n product.categoryTree &&\n product.categoryTree.length > 0 &&\n product.categoryTree[product.categoryTree.length - 1].name\n\nfunction parseBrand(brand) {\n return {\n '@type': 'Brand',\n name: typeof brand === 'string' ? brand : brand.name,\n }\n}\n\nexport const parseToJsonLD = ({\n product,\n selectedItem,\n currency,\n disableOffers,\n decimals,\n pricesWithTax,\n useSellerDefault,\n useImagesArray,\n disableAggregateOffer,\n gtinValue,\n}) => {\n const images = selectedItem ? selectedItem.images : []\n const { brand } = product\n const name = product.productName\n\n const mpn =\n selectedItem?.referenceId?.[0]?.Value ||\n product?.productReference ||\n product?.productId\n\n const offers = composeAggregateOffer(product, currency, {\n decimals,\n pricesWithTax,\n useSellerDefault,\n disableAggregateOffer,\n gtinValue,\n })\n\n if (offers === null) {\n return null\n }\n\n const baseUrl = getBaseUrl()\n const category = getCategoryName(product)\n\n const rawGTIN = selectedItem?.[gtinValue]\n const gtin = normalizeGTIN(rawGTIN)\n\n const merchantSKU = gtin || selectedItem?.itemId || null\n\n const productLD = {\n '@context': 'https://schema.org/',\n '@type': 'Product',\n '@id': `${baseUrl}/${product.linkText}/p`,\n name,\n brand: parseBrand(brand),\n image: useImagesArray\n ? images.map((el) => el.imageUrl)\n : images[0]?.imageUrl || null,\n description: product.metaTagDescription || product.description,\n mpn,\n sku: merchantSKU,\n category,\n offers: disableOffers ? null : offers,\n gtin,\n }\n\n return productLD\n}\n\nfunction StructuredData({ product, selectedItem }) {\n const {\n culture: { currency },\n } = useRuntime()\n\n const {\n decimals,\n disableOffers,\n pricesWithTax,\n useSellerDefault,\n useImagesArray,\n disableAggregateOffer,\n gtinValue,\n } = useAppSettings()\n\n const productLD = parseToJsonLD({\n product,\n selectedItem,\n currency,\n disableOffers,\n decimals,\n pricesWithTax,\n useSellerDefault,\n useImagesArray,\n disableAggregateOffer,\n gtinValue,\n })\n\n if (!productLD) return null\n\n return <script {...jsonLdScriptProps(productLD)} />\n}\n\nStructuredData.propTypes = {\n product: PropTypes.object,\n selectedItem: PropTypes.object,\n}\n\nexport default memo(StructuredData)\n\n```"
}
] |
code_structured-data_f13d0a38
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of structured-data/react/__fixtures__/marketplaceProductMock.js from the structured-data VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```javascript\nexport const product = {\n cacheId: 'my-prod',\n productName: 'Super cellphone',\n productId: '111',\n description: 'teste',\n titleTag: 'Title',\n metaTagDescription: 'Meta',\n linkText: 'my-prod',\n productReference: '1',\n categoryId: '1',\n categories: [\n '/Tecnologia/Celulares/Smartphones/',\n '/Tecnologia/Celulares/',\n '/Tecnologia/',\n ],\n brand: 'HUAWEI',\n brandId: 1212,\n items: [\n {\n itemId: '100304479',\n name: 'Super cell item',\n nameComplete: 'super cell item complete',\n complementName: '',\n ean: '111111',\n referenceId: null,\n measurementUnit: 'un',\n unitMultiplier: 1,\n images: [\n {\n imageId: '111',\n imageLabel: null,\n imageTag: '',\n imageUrl: 'myimage.com',\n imageText: null,\n },\n ],\n videos: [],\n sellers: [\n {\n sellerId: '1',\n sellerName: 'Seller sport',\n addToCartLink: 'lala.com',\n sellerDefault: false,\n commertialOffer: {\n discountHighlights: [],\n teasers: [],\n Price: 899000,\n spotPrice: 899000,\n ListPrice: 999000,\n PriceWithoutDiscount: 899000,\n RewardValue: 0,\n PriceValidUntil: '2020-09-20T19:47:56.9849658Z',\n AvailableQuantity: 5,\n Tax: 19,\n },\n },\n {\n sellerId: '2',\n sellerName: 'seller mundo movil',\n addToCartLink: 'lala.com',\n sellerDefault: false,\n commertialOffer: {\n discountHighlights: [],\n teasers: [],\n Price: 924330,\n spotPrice: 924330,\n ListPrice: 1200000,\n PriceWithoutDiscount: 924330,\n RewardValue: 0,\n PriceValidUntil: '2020-09-20T19:47:56.9613527Z',\n AvailableQuantity: 5,\n Tax: 19,\n },\n },\n {\n sellerId: '3',\n sellerName: 'celu store',\n addToCartLink: '',\n sellerDefault: false,\n commertialOffer: {\n discountHighlights: [],\n teasers: [],\n Price: 898999,\n spotPrice: 898999,\n ListPrice: 999998,\n PriceWithoutDiscount: 898999,\n RewardValue: 0,\n PriceValidUntil: '2020-09-20T19:47:56.9593497Z',\n AvailableQuantity: 10,\n Tax: 19,\n },\n },\n {\n sellerId: '3',\n sellerName: 'fake seller',\n addToCartLink: '',\n sellerDefault: false,\n commertialOffer: {\n discountHighlights: [],\n teasers: [],\n Price: 955900,\n spotPrice: 955900,\n ListPrice: 1219900,\n PriceWithoutDiscount: 955900,\n RewardValue: 0,\n PriceValidUntil: '2020-09-20T19:47:56.9559171Z',\n AvailableQuantity: 20,\n Tax: 19,\n },\n },\n {\n sellerId: '4',\n sellerName: 'another fake seller',\n addToCartLink: 'lala.com',\n sellerDefault: true,\n commertialOffer: {\n discountHighlights: [],\n teasers: [],\n Price: 869900,\n spotPrice: 869900,\n ListPrice: 1199900,\n PriceWithoutDiscount: 869900,\n RewardValue: 0,\n PriceValidUntil: '2020-09-20T19:47:56.9502296Z',\n AvailableQuantity: 9,\n Tax: 19,\n },\n },\n {\n sellerId: '11829',\n sellerName: 'multisistemas',\n addToCartLink: '',\n sellerDefault: false,\n commertialOffer: {\n discountHighlights: [],\n teasers: [],\n Price: 899000,\n spotPrice: 899000,\n ListPrice: 1100000,\n PriceWithoutDiscount: 899000,\n RewardValue: 0,\n PriceValidUntil: '2020-09-20T19:47:56.9596485Z',\n AvailableQuantity: 9,\n Tax: 19,\n },\n },\n {\n sellerId: '1',\n sellerName: 'last seller',\n addToCartLink: '',\n sellerDefault: false,\n commertialOffer: {\n discountHighlights: [],\n teasers: [],\n Price: 0,\n spotPrice: 0,\n ListPrice: 0,\n PriceWithoutDiscount: 0,\n RewardValue: 0,\n PriceValidUntil: null,\n AvailableQuantity: 0,\n Tax: 19,\n },\n },\n ],\n variations: [],\n kitItems: [],\n attachments: [],\n },\n ],\n}\n\n```"
}
] |
code_structured-data_7d730a71
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of structured-data/react/__fixtures__/productMock.js from the structured-data VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```javascript\nexport const createProduct = () => {\n return {\n cacheId: 'product-slug',\n productName: 'Product Name',\n productId: '1',\n description: 'Product Description',\n titleTag: 'Product Name',\n metaTagDescription: null,\n linkText: 'product-slug',\n categories: [\n '/Category A/',\n '/Category A/Category B/',\n '/Category A/Category B/Category C/',\n ],\n categoryId: '1',\n categoriesIds: ['/1/2/3/', '/1/2/', '/1/'],\n brand: 'Brand',\n categoryTree: [\n { id: '1', name: 'Category A', href: 'category-a' },\n { id: '2', name: 'Category B', href: 'category-a/category-b' },\n { id: '3', name: 'Category C', href: 'category-a/category-b/category-c' },\n ],\n items: [],\n }\n}\n\nexport const createItem = ({\n id = '1',\n price = 90,\n spotPrice = price,\n quantity = 10,\n customFields = {},\n}) => {\n return {\n itemId: id,\n name: `Item ${id}`,\n nameComplete: `Name ${id} Complete`,\n images: [\n {\n imageId: id,\n imageLabel: `${id}-Color`,\n imageTag: 'imageTag',\n imageUrl: 'imageurl.com',\n imageText: 'imageText',\n },\n ],\n sellers: [\n {\n sellerId: id,\n sellerName: 'Store Name',\n commertialOffer: {\n AvailableQuantity: quantity,\n ListPrice: price + 10,\n Price: price,\n spotPrice,\n },\n },\n ],\n ...customFields,\n }\n}\n\n```"
}
] |
code_structured-data_5da25923
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of structured-data/react/__fixtures__/productListMock.js from the structured-data VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```javascript\nimport { createItem } from './productMock'\n\nexport const createProductList = () => {\n const item = createItem({ id: 1, price: 100, spotPrice: 100, quantity: 2 })\n\n return [\n {\n cacheId: 'blouse',\n productName: 'Blouse',\n productId: '1',\n description: 'Product Description',\n titleTag: 'Product Name',\n metaTagDescription: null,\n linkText: 'blouse',\n categories: [\n '/Category A/',\n '/Category A/Category B/',\n '/Category A/Category B/Category C/',\n ],\n categoryId: '1',\n categoriesIds: ['/1/2/3/', '/1/2/', '/1/'],\n brand: 'Brand',\n categoryTree: [\n { id: '1', name: 'Category A', href: 'category-a' },\n { id: '2', name: 'Category B', href: 'category-a/category-b' },\n {\n id: '3',\n name: 'Category C',\n href: 'category-a/category-b/category-c',\n },\n ],\n items: [item],\n },\n {\n cacheId: 'skirt',\n productName: 'Skirt',\n productId: '2',\n description: 'Product Description',\n titleTag: 'Product Name',\n metaTagDescription: null,\n linkText: 'skirt',\n categories: [\n '/Category A/',\n '/Category A/Category B/',\n '/Category A/Category B/Category C/',\n ],\n categoryId: '1',\n categoriesIds: ['/1/2/3/', '/1/2/', '/1/'],\n brand: 'Brand',\n categoryTree: [\n {\n id: '1',\n name: 'Category A',\n href: 'category-a',\n },\n {\n id: '2',\n name: 'Category B',\n href: 'category-a/category-b',\n },\n {\n id: '3',\n name: 'Category C',\n href: 'category-a/category-b/category-c',\n },\n ],\n items: [item],\n },\n ]\n}\n\n```"
}
] |
code_structured-data_0081b323
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of structured-data/react/__fixtures__/unavailableProduct.js from the structured-data VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```javascript\nexport const product = {\n cacheId: 'rustic-striped-vase',\n productName: 'Rustic Striped Vase',\n productId: '2000023',\n description: 'Beautiful rustic and striped vase for flowers.',\n titleTag: 'Rustic Striped Vase',\n metaTagDescription: 'Beautiful rustic and striped vase for flowers.',\n linkText: 'rustic-striped-vase',\n productReference: '999987',\n categoryId: '40',\n categories: ['/Home & Decor/'],\n brand: 'Kawasaki',\n brandId: 2000001,\n properties: [],\n specificationGroups: [\n {\n name: 'allSpecifications',\n specifications: [],\n __typename: 'SpecificationGroup',\n },\n ],\n items: [\n {\n itemId: '2000563',\n name: 'Rustic Striped Vase',\n nameComplete: 'Rustic Striped Vase',\n complementName: 'Handmade ceramic.',\n ean: '',\n referenceId: [\n {\n Key: 'RefId',\n Value: '999987',\n __typename: 'Reference',\n },\n ],\n measurementUnit: 'un',\n unitMultiplier: 1,\n images: [\n {\n imageId: '155517',\n imageLabel: 'rusticvase',\n imageTag:\n '<img src=\"~/arquivos/ids/155517-#width#-#height#/download--69-.png?v=636942440196570000\" width=\"#width#\" height=\"#height#\" alt=\"rustic-vase\" id=\"\" />',\n imageUrl:\n 'https://storecomponents.vteximg.com.br/arquivos/ids/155517/download--69-.png?v=636942440196570000',\n imageText: 'rustic-vase',\n __typename: 'Image',\n },\n ],\n videos: [],\n sellers: [\n {\n sellerId: '1',\n sellerName: 'VTEX',\n addToCartLink:\n 'https://portal.vtexcommercestable.com.br/checkout/cart/add?sku=2000563&qty=1&seller=1&sc=1&price=0&cv=801c11e886cb596a5677ab2cfe4ca45a_&sc=1',\n sellerDefault: true,\n commertialOffer: {\n discountHighlights: [],\n teasers: [],\n Price: 0,\n spotPrice: 0,\n ListPrice: 0,\n PriceWithoutDiscount: 0,\n RewardValue: 0,\n PriceValidUntil: null,\n AvailableQuantity: 0,\n Tax: 0,\n CacheVersionUsedToCallCheckout: '801c11e886cb596a5677ab2cfe4ca45a_',\n Installments: [],\n __typename: 'Offer',\n },\n __typename: 'Seller',\n },\n ],\n variations: [],\n kitItems: [],\n attachments: [],\n __typename: 'SKU',\n },\n ],\n itemMetadata: null,\n productClusters: [],\n clusterHighlights: [],\n __typename: 'Product',\n}\n\n```"
}
] |
code_structured-data_4554c94d
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of structured-data/react/typings/graphql.d.ts from the structured-data VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\ndeclare module '*.graphql' {\n import { DocumentNode } from 'graphql'\n\n const value: DocumentNode\n export default value\n}\n\n```"
}
] |
code_structured-data_d20698a5
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of structured-data/react/queries/getSettings.graphql from the structured-data VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```graphql\nquery getSettings {\n publicSettingsForApp(app: \"vtex.structured-data\", version: \"0.x\")\n @context(provider: \"vtex.apps-graphql\") {\n message\n }\n}\n\n```"
}
] |
code_structured-data_b975dd6a
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of structured-data/react/__tests__/Product.test.js from the structured-data VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```javascript\nimport { clone } from 'ramda'\n\nimport { parseToJsonLD } from '../Product'\nimport { createProduct, createItem } from '../__fixtures__/productMock'\nimport { product as mktPlaceProduct } from '../__fixtures__/marketplaceProductMock'\nimport * as getBaseUrl from '../modules/baseUrl'\n\nlet mockDisableOffers = false\nlet mockDecimals = 2\nlet mockPricesWithTax = false\nlet mockUseSellerDefault = false\nlet mockGetBaseUrl\nconst mockedBaseUrl = `www.vtex.com.br`\n\nconst currency = 'BRL'\n\ndescribe('Product Structured Data', () => {\n beforeAll(() => {\n mockGetBaseUrl = jest\n .spyOn(getBaseUrl, 'getBaseUrl')\n .mockReturnValue(mockedBaseUrl)\n })\n\n afterAll(() => {\n mockGetBaseUrl.mockRestore()\n })\n\n it('should fill low and high prices', () => {\n const product = createProduct()\n const cheapItem = createItem({ id: '2', price: 45, quantity: 1 })\n const expensiveItem = createItem({ id: '3', price: 60, quantity: 2 })\n\n mockDisableOffers = false\n mockDecimals = 2\n mockPricesWithTax = false\n\n product.items.push(cheapItem)\n product.items.push(expensiveItem)\n\n const result = parseToJsonLD({\n product,\n selectedItem: product.items[0],\n currency,\n disableOffers: mockDisableOffers,\n decimals: mockDecimals,\n pricesWithTax: mockPricesWithTax,\n })\n\n expect(result.offers.lowPrice).toBe(45)\n expect(result.offers.highPrice).toBe(60)\n expect(result.offers.priceCurrency).toBe(currency)\n expect(result.sku).toBe(cheapItem.itemId)\n expect(result.category).toBe('Category C')\n })\n\n it('should use spotPrice as lowPrice', () => {\n const product = createProduct()\n const cheapItem = createItem({\n id: '2',\n spotPrice: 40,\n price: 45,\n quantity: 1,\n })\n\n product.items.push(cheapItem)\n\n mockDisableOffers = false\n mockDecimals = 2\n mockPricesWithTax = false\n\n const result = parseToJsonLD({\n product,\n selectedItem: product.items[0],\n currency,\n disableOffers: mockDisableOffers,\n decimals: mockDecimals,\n pricesWithTax: mockPricesWithTax,\n })\n\n expect(result.offers.lowPrice).toBe(40)\n expect(result.offers.highPrice).toBe(45)\n })\n\n it('should handle many skus availability', () => {\n const product = createProduct()\n const unavailableItem = createItem({ id: '2', price: 0, quantity: 0 })\n const availableItem = createItem({ id: '3', price: 60, quantity: 1 })\n\n product.items.push(unavailableItem)\n product.items.push(availableItem)\n\n mockDisableOffers = false\n mockDecimals = 2\n mockPricesWithTax = false\n\n const result = parseToJsonLD({\n product,\n selectedItem: product.items[0],\n currency,\n disableOffers: mockDisableOffers,\n decimals: mockDecimals,\n pricesWithTax: mockPricesWithTax,\n })\n\n expect(result.offers.lowPrice).toBe(60)\n expect(result.offers.highPrice).toBe(60)\n expect(result.offers.priceCurrency).toBe(currency)\n expect(result.offers.offers).toHaveLength(1)\n expect(result.offers.offers[0].availability).toBe(\n 'http://schema.org/InStock'\n )\n })\n\n it('should handle product that have only skus that are unavailable', () => {\n const productOneSku = createProduct()\n const unavailableItem = createItem({ id: '1', price: 0, quantity: 0 })\n\n productOneSku.items.push(unavailableItem)\n\n const productTwoSkus = createProduct()\n\n productTwoSkus.items.push(unavailableItem)\n productTwoSkus.items.push(unavailableItem)\n\n mockDisableOffers = false\n mockDecimals = 2\n mockPricesWithTax = false\n\n const resultOneSku = parseToJsonLD({\n product: productOneSku,\n selectedItem: productOneSku.items[0],\n currency,\n disableOffers: mockDisableOffers,\n decimals: mockDecimals,\n pricesWithTax: mockPricesWithTax,\n })\n\n const resultTwoSkus = parseToJsonLD({\n product: productTwoSkus,\n selectedItem: productTwoSkus.items[0],\n currency,\n disableOffers: mockDisableOffers,\n decimals: mockDecimals,\n pricesWithTax: mockPricesWithTax,\n })\n\n expect(resultOneSku).toBeNull()\n expect(resultTwoSkus).toBeNull()\n })\n\n it('should handle multiple sellers correctly, get correct low price and high price', () => {\n mockDisableOffers = false\n mockDecimals = 2\n mockPricesWithTax = false\n\n const result = parseToJsonLD({\n product: mktPlaceProduct,\n selectedItem: mktPlaceProduct.items[0],\n currency,\n disableOffers: mockDisableOffers,\n decimals: mockDecimals,\n pricesWithTax: mockPricesWithTax,\n })\n\n expect(result.offers.lowPrice).toBe(869900)\n expect(result.offers.highPrice).toBe(955900)\n expect(result.offers.offerCount).toBe(1)\n expect(result.offers.offers[0].price).toBe(869900)\n expect(result.offers.offers[0].seller.name).toBe('another fake seller')\n })\n\n it('should handle multiple sellers and multiple items correctly, get correct low price and high price', () => {\n const copyProduct = clone(mktPlaceProduct)\n const item = clone(copyProduct.items[0])\n\n item.sellers[2].commertialOffer.spotPrice = 1000\n copyProduct.items.push(item)\n\n mockDisableOffers = false\n mockDecimals = 2\n mockPricesWithTax = false\n\n const result = parseToJsonLD({\n product: copyProduct,\n selectedItem: copyProduct.items[0],\n currency,\n disableOffers: mockDisableOffers,\n decimals: mockDecimals,\n pricesWithTax: mockPricesWithTax,\n })\n\n expect(result.offers.lowPrice).toBe(1000)\n expect(result.offers.highPrice).toBe(955900)\n expect(result.offers.offerCount).toBe(2)\n expect(result.offers.offers[0].price).toBe(869900)\n expect(result.offers.offers[0].seller.name).toBe('another fake seller')\n expect(result.offers.offers[1].price).toBe(1000)\n expect(result.offers.offers[1].seller.name).toBe(item.sellers[2].sellerName)\n })\n\n it('should handle multiple sellers and multiple items correctly, get correct low price and high price for prices with tax', () => {\n const copyProduct = clone(mktPlaceProduct)\n const item = clone(copyProduct.items[0])\n\n item.sellers[2].commertialOffer.spotPrice = 1000\n copyProduct.items.push(item)\n\n mockDisableOffers = false\n mockDecimals = 2\n mockPricesWithTax = true\n\n const result = parseToJsonLD({\n product: copyProduct,\n selectedItem: copyProduct.items[0],\n currency,\n disableOffers: mockDisableOffers,\n decimals: mockDecimals,\n pricesWithTax: mockPricesWithTax,\n })\n\n expect(result.offers.lowPrice).toBe(1019)\n expect(result.offers.highPrice).toBe(955919)\n expect(result.offers.offerCount).toBe(2)\n expect(result.offers.offers[0].price).toBe(869919)\n expect(result.offers.offers[0].seller.name).toBe('another fake seller')\n expect(result.offers.offers[1].price).toBe(1019)\n expect(result.offers.offers[1].seller.name).toBe(item.sellers[2].sellerName)\n })\n\n it(`should have the product's final production URI as @id`, () => {\n const copyProduct = clone(mktPlaceProduct)\n\n const result = parseToJsonLD({\n product: copyProduct,\n selectedItem: copyProduct.items[0],\n currency,\n })\n\n expect(result['@id']).toBe(`${mockedBaseUrl}/${copyProduct.linkText}/p`)\n })\n\n it('should handle multiple sellers and option useSellerDefault, get correct seller name and price', () => {\n const copyProduct = clone(mktPlaceProduct)\n\n const [item] = copyProduct.items\n\n item.sellers.forEach((seller) => {\n seller.sellerDefault = seller.sellerId === '11829'\n })\n\n mockDecimals = 2\n mockPricesWithTax = false\n mockUseSellerDefault = true\n\n const result = parseToJsonLD({\n product: copyProduct,\n selectedItem: item,\n currency,\n decimals: mockDecimals,\n pricesWithTax: mockPricesWithTax,\n useSellerDefault: mockUseSellerDefault,\n })\n\n expect(result.offers.offers[0].seller.name).toBe('multisistemas')\n expect(result.offers.offers[0].price).toBe(899000)\n })\n\n it('should not fill offers if disableOffers is true', () => {\n const copyProduct = clone(mktPlaceProduct)\n\n mockDisableOffers = true\n mockDecimals = 2\n mockPricesWithTax = false\n\n const result = parseToJsonLD({\n product: copyProduct,\n selectedItem: copyProduct.items[0],\n currency,\n disableOffers: mockDisableOffers,\n decimals: mockDecimals,\n pricesWithTax: mockPricesWithTax,\n })\n\n expect(result.offers).toBeNull()\n })\n})\n\n```"
}
] |
code_structured-data_2bf540b3
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of structured-data/react/__tests__/useAppSettings.test.jsx from the structured-data VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```jsx\nimport { renderHook } from '@testing-library/react-hooks'\nimport { MockedProvider } from '@apollo/react-testing'\nimport React from 'react'\n\nimport useAppSettings from '../hooks/useAppSettings'\nimport GET_SETTINGS from '../queries/getSettings.graphql'\n\nconst mockQueryData = {\n request: {\n query: GET_SETTINGS,\n },\n result: {\n data: {\n publicSettingsForApp: {\n message:\n '{\"decimals\": 4, \"disableOffers\": false, \"pricesWithTax\": true, \"useSellerDefault\": true}',\n },\n },\n },\n}\n\nconst mockQueryDataNull = {\n request: {\n query: GET_SETTINGS,\n },\n result: {\n data: {\n publicSettingsForApp: {\n message:\n '{\"decimals\": null, \"disableOffers\": null, \"pricesWithTax\": null, \"useSellerDefault\": null}',\n },\n },\n },\n}\n\nfunction getHookWrapper(mocks = []) {\n const wrapper = ({ children }) => (\n <MockedProvider addTypename={false} mocks={mocks}>\n {children}\n </MockedProvider>\n )\n\n const { result, waitForNextUpdate } = renderHook(() => useAppSettings(), {\n wrapper,\n })\n\n return { result, waitForNextUpdate }\n}\n\ntest('should return object', async () => {\n const { result, waitForNextUpdate } = getHookWrapper([mockQueryData])\n\n await waitForNextUpdate()\n\n expect(result.current.disableOffers).toBe(false)\n expect(result.current.decimals).toBe(4)\n expect(result.current.pricesWithTax).toBe(true)\n expect(result.current.useSellerDefault).toBe(true)\n})\n\ntest('should return default object', async () => {\n const { result, waitForNextUpdate } = getHookWrapper([mockQueryDataNull])\n\n await waitForNextUpdate()\n\n expect(result.current.disableOffers).toBe(false)\n expect(result.current.decimals).toBe(2)\n expect(result.current.pricesWithTax).toBe(false)\n expect(result.current.useSellerDefault).toBe(false)\n})\n\n```"
}
] |
code_structured-data_5b8b1585
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of structured-data/react/__tests__/ProductList.test.js from the structured-data VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```javascript\nimport { getProductList } from '../ProductList'\nimport { createProductList } from '../__fixtures__/productListMock'\n\nconst disableOffers = false\nconst decimals = 2\nconst pricesWithTax = false\nconst currency = 'USD'\n\ndescribe('Product List Structured Data', () => {\n beforeEach(() => {\n global.__RUNTIME__ = {}\n global.__hostname__ = 'testSuite.com'\n })\n\n it('Should create a list', () => {\n const products = createProductList()\n\n const productListLD = getProductList({\n products,\n decimals,\n disableOffers,\n pricesWithTax,\n currency,\n })\n\n expect(productListLD['@type']).toBe('ItemList')\n expect(productListLD.itemListElement).toHaveLength(2)\n expect(productListLD.itemListElement[0]).toEqual({\n '@type': 'ListItem',\n position: 1,\n item: {\n '@context': 'https://schema.org/',\n name: products[0].productName,\n '@id': `https://testSuite.com/${\n products[0].link || products[0].linkText\n }/p`,\n '@type': 'Product',\n brand: {\n '@type': 'Brand',\n name: products[0].brand,\n },\n description: products[0].description,\n gtin: null,\n category:\n products[0].categoryTree[products[0].categoryTree.length - 1].name,\n image: products[0].items[0].images[0].imageUrl,\n mpn: products[0].productId,\n sku: products[0].items[0].itemId,\n offers: {\n '@type': 'AggregateOffer',\n highPrice: 100,\n lowPrice: 100,\n offerCount: 1,\n offers: [\n {\n '@type': 'Offer',\n availability: 'http://schema.org/InStock',\n itemCondition: 'http://schema.org/NewCondition',\n price: 100,\n priceCurrency: currency,\n priceValidUntil: undefined,\n seller: {\n '@type': 'Organization',\n name: 'Store Name',\n },\n sku: products[0].items[0].itemId,\n },\n ],\n priceCurrency: currency,\n },\n },\n })\n expect(productListLD.itemListElement[1]).toEqual({\n '@type': 'ListItem',\n position: 2,\n item: {\n '@context': 'https://schema.org/',\n name: products[1].productName,\n '@id': `https://testSuite.com/${\n products[1].link || products[1].linkText\n }/p`,\n '@type': 'Product',\n brand: {\n '@type': 'Brand',\n name: products[1].brand,\n },\n description: products[1].description,\n gtin: null,\n category:\n products[1].categoryTree[products[1].categoryTree.length - 1].name,\n image: products[1].items[0].images[0].imageUrl,\n mpn: products[1].productId,\n sku: products[1].items[0].itemId,\n offers: {\n '@type': 'AggregateOffer',\n highPrice: 100,\n lowPrice: 100,\n offerCount: 1,\n offers: [\n {\n '@type': 'Offer',\n availability: 'http://schema.org/InStock',\n itemCondition: 'http://schema.org/NewCondition',\n price: 100,\n priceCurrency: currency,\n priceValidUntil: undefined,\n seller: {\n '@type': 'Organization',\n name: 'Store Name',\n },\n sku: products[1].items[0].itemId,\n },\n ],\n priceCurrency: currency,\n },\n },\n })\n })\n\n it('Handles empty case', () => {\n const products = []\n const productListLD = getProductList({\n products,\n decimals,\n disableOffers,\n pricesWithTax,\n currency,\n })\n\n expect(productListLD.itemListElement).toHaveLength(0)\n })\n\n it('Handles undefined case', () => {\n const products = undefined\n const productListLD = getProductList({\n products,\n decimals,\n disableOffers,\n pricesWithTax,\n currency,\n })\n\n expect(productListLD).toBeNull()\n })\n\n it('should not fill offers if disableOffers is true', () => {\n const products = createProductList()\n\n const productListLD = getProductList({\n products,\n decimals,\n disableOffers: true,\n pricesWithTax,\n currency,\n })\n\n expect(productListLD['@type']).toBe('ItemList')\n expect(productListLD.itemListElement).toHaveLength(2)\n expect(productListLD.itemListElement[0].item.offers).toBeNull()\n })\n})\n\n```"
}
] |
code_structured-data_64203279
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of structured-data/react/hooks/useAppSettings.ts from the structured-data VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { useQuery } from 'react-apollo'\n\nimport GET_SETTINGS from '../queries/getSettings.graphql'\n\nconst DEFAULT_DISABLE_OFFERS = false\nconst DEFAULT_DECIMALS = 2\nconst DEFAULT_PRICES_WITH_TAX = false\nconst DEFAULT_USE_SELLER_DEFAULT = false\nconst DEFAULT_USE_IMAGES_ARRAY = false\nconst DEFAULT_DISABLE_AGGREGATE_OFFER = false\nconst DEFAULT_GTIN_VALUE = 'itemId'\n\ninterface Settings {\n disableOffers: boolean\n decimals: number\n pricesWithTax: boolean\n useSellerDefault: boolean\n useImagesArray: boolean\n disableAggregateOffer: boolean\n gtinValue?: string\n}\n\nconst useAppSettings = (): Settings => {\n const { data } = useQuery(GET_SETTINGS, { ssr: true })\n\n if (data?.publicSettingsForApp?.message) {\n const {\n decimals,\n disableOffers,\n pricesWithTax,\n useSellerDefault,\n useImagesArray,\n disableAggregateOffer,\n gtinValue,\n } = JSON.parse(data.publicSettingsForApp.message)\n\n return {\n disableOffers: disableOffers || DEFAULT_DISABLE_OFFERS,\n decimals: decimals || DEFAULT_DECIMALS,\n pricesWithTax: pricesWithTax || DEFAULT_PRICES_WITH_TAX,\n useSellerDefault: useSellerDefault || DEFAULT_USE_SELLER_DEFAULT,\n useImagesArray: useImagesArray || DEFAULT_USE_IMAGES_ARRAY,\n disableAggregateOffer:\n disableAggregateOffer || DEFAULT_DISABLE_AGGREGATE_OFFER,\n gtinValue: gtinValue || DEFAULT_GTIN_VALUE,\n }\n }\n\n return {\n disableOffers: DEFAULT_DISABLE_OFFERS,\n decimals: DEFAULT_DECIMALS,\n pricesWithTax: DEFAULT_PRICES_WITH_TAX,\n useSellerDefault: DEFAULT_USE_SELLER_DEFAULT,\n useImagesArray: DEFAULT_USE_IMAGES_ARRAY,\n disableAggregateOffer: DEFAULT_DISABLE_AGGREGATE_OFFER,\n gtinValue: DEFAULT_GTIN_VALUE,\n }\n}\n\nexport default useAppSettings\n\n```"
}
] |
code_structured-data_346de7c0
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of structured-data/react/modules/baseUrl.tsx from the structured-data VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport { canUseDOM } from 'vtex.render-runtime'\n\ninterface Runtime {\n rootPath?: string\n}\n\ndeclare let global: {\n __hostname__: string\n __protocol__: string\n __pathname__: string\n __RUNTIME__: Runtime\n}\n\ndeclare let window: {\n __RUNTIME__: Runtime\n location: Window['location']\n}\n\nexport const getBaseUrl = () => {\n const protocol = 'https'\n const hostname = canUseDOM ? window.location.hostname : global.__hostname__\n const rootPath = canUseDOM\n ? window.__RUNTIME__.rootPath\n : global.__RUNTIME__.rootPath\n\n const baseUrl = `${protocol}://${hostname}${rootPath ?? ''}`\n\n return baseUrl\n}\n\n```"
}
] |
code_supply-lots_bd9cc05e
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of supply-lots/messages/pt.json from the supply-lots VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"admin/inventory\": \"Gerenciar estoque futuro\",\n \"admin/options-true\": \"Sim\",\n \"admin/options-false\": \"Não\",\n \"admin/title-add\": \"Criar estoque futuro\",\n \"admin/title-edit\": \"Editar estoque futuro\",\n \"admin/save\": \"Salvar\",\n \"admin/cancel\": \"Cancelar\",\n \"admin/date\": \"Data de chegada\",\n \"admin/date-placeholder\": \"Adicionar a data da chegada do estoque futuro\",\n \"admin/total\": \"Total do lote\",\n \"admin/total-placeholder\": \"Total de itens no lote\",\n \"admin/keep\": \"Seguir vendendo?\",\n \"admin/keep-placeholder\": \"O produto deve ser vendido mesmo se a data de chegada já tiver passado?\",\n \"admin/delete\": \"Deletar\",\n \"admin/delete-text\": \"Excluir estoque futuro\",\n \"admin/delete-question\": \"Tem certeza que deseja excluir esse estoque futuro?\",\n \"admin/delete-reason\": \"(Todas as compras feitas com esses produtos serão canceladas)\",\n \"admin/limit\": \"Só é possível criar até 10 estoque futuros\",\n \"admin/transfer\": \"Transferir\",\n \"admin/transfer-text\": \"Transferir estoque futuro\",\n \"admin/transfer-question\": \"Tem certeza que deseja transferir esse estoque futuro?\",\n \"admin/title-product-table\": \"Estoque futuro\",\n \"admin/link\": \"Inventário\",\n \"admin/toolbar\": \"Criar estoque futuro\",\n \"admin/totalizers-sku\": \"SKU ID\",\n \"admin/totalizers-product\": \"Produto\",\n \"admin/totalizers-warehouse-id\": \"Estoque ID\",\n \"admin/totalizers-warehouse\": \"Nome do estoque\",\n \"admin/text-notice-number\": \"O total de lotes precisa ser maior que 0\",\n \"admin/text-notice\": \"Preencha todos os campos\",\n \"admin/yes\": \"Sim\",\n \"admin/no\": \"Não\",\n \"admin/regular\": \"Regular\",\n \"admin/expired\": \"Expirado\",\n \"admin/expired-yes\": \"Expirado e vendendo\",\n \"admin/expiring\": \"Expirando em \",\n \"admin/day\": \" dia\",\n \"admin/days\": \" dias\",\n \"admin/index\": \"Índice\",\n \"admin/date-provider\": \"Data de chegada\",\n \"admin/total-provider\": \"Total dos lotes\",\n \"admin/reserved\": \"Reservado\",\n \"admin/available\": \"Disponível\",\n \"admin/keep-provider\": \"Seguir vendendo\",\n \"admin/info\": \"O produto deve ser vendido mesmo se a data de chegada já tiver passado?\",\n \"admin/status\": \"Status\",\n \"admin/actions\": \"Ações\",\n \"admin/edit\": \"Editar\",\n \"admin/delete-provider\": \"Excluir\",\n \"admin/transfer-provider\": \"Transferir\"\n}\n\n```"
}
] |
code_supply-lots_d5e3007a
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of supply-lots/admin/navigation.json from the supply-lots VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"section\": \"storeSetup\",\n \"LMProductId\": \"55\",\n \"titleId\": \"audit.home.title\",\n \"path\": \"/admin/audit\"\n}\n\n```"
}
] |
code_supply-lots_5dfffc7c
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of supply-lots/admin/routes.json from the supply-lots VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"admin.app.supply-lots-inventory\": {\n \"component\": \"SupplyLots\",\n \"path\": \"/admin/app/supply-lots-inventory\"\n }\n}\n\n```"
}
] |
code_supply-lots_10f039c4
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of supply-lots/docs/README.md from the supply-lots VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```markdown\n# Supply Lots\n\nThe Supply Lots app is responsible for manage supply lots in the admin interface.\n\n\n\n## How to use\n\n1. You can save a new Supply Lot by clicking on the button \"New Supply Lot\". A modal box will open, where you can enter the Date of Supply, Item Quantity in the Lot and whether the Lot will still be used for reservations after the Date of Supply has expired.\n\n\n\n2. You can edit an existing Supply Lot by clicking on the Edit button, represented by a pencil icon. A modal box will open where you can edit any of the specified fields.\n\n\n\n\n3. You can delete a Supply Lot by clicking on the Delete button, represented by a trash can icon.\n\n\n\n4. You can transfer a Supply Lot to the active inventory by clicking on the Transfer button, represented by a a box and arrow icon.\n\n\n\n## Configuration\n\n1. Using your terminal and the VTEX IO Toolbelt, log into the desired VTEX account.\n2. Run vtex install vtex.supply-lots on the account you're working on.\n3. Access your VTEX account's admin.\n4. Access Inventory & shipping and then Inventory management.\n5. Choice the warehouse and products and then click on Supply lots.\n6. Make the changes on supply lot interface\n\n```"
}
] |
code_supply-lots_6038b74d
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of supply-lots/graphql/schema.graphql from the supply-lots VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```graphql\ntype Query {\n \"\"\"\n Check if a SKU and a Warehouse exist by their IDs and get their names\n \"\"\"\n getSkuAndWarehouseNames(\n \"\"\"\n SKU ID to be checked\n \"\"\"\n skuId: String!\n \"\"\"\n Warehouse ID to be checked\n \"\"\"\n warehouseId: String!\n ): [String]\n \"\"\"\n List all Supply Lots of a SKU scheduled to arrive at a Warehouse\n \"\"\"\n listSupplyLots(\n \"\"\"\n SKU scheduled to arrive in the Supply Lot\n \"\"\"\n skuId: ID!\n \"\"\"\n Warehouse where the Supply Lot is scheduled to arrive\n \"\"\"\n warehouseId: ID!\n \"\"\"\n ID of the Supply Lot, in the case the Query is used to verify if a ID was already used\n \"\"\"\n supplyLotId: ID\n \"\"\"\n Whether to ignore Supply Lots with a totalQuantity of 0 (true by default, to ignore Deleted Supply Lots).\n \"\"\"\n filterZeros: Boolean = true\n ): [SupplyLot]\n}\n\ntype Mutation {\n \"\"\"\n Save or update a Supply Lot of a SKU scheduled to arrive at a Warehouse\n \"\"\"\n setSupplyLot(\n \"\"\"\n Information necessary to save or update a Supply Lot\n \"\"\"\n supplyLotData: SupplyLotInput!\n \"\"\"\n Whether the Mutation will update a existing Supply Lot if the provided ID is already being used \n \"\"\"\n updateExisting: Boolean\n ): Boolean\n \"\"\"\n Transfer a Supply Lot of a SKU/Warehouse to the active Inventory\n \"\"\"\n transferSupplyLot(\n \"\"\"\n SKU scheduled to arrive in the Supply Lot\n \"\"\"\n skuId: ID!\n \"\"\"\n Warehouse where the Supply Lot is scheduled to arrive\n \"\"\"\n warehouseId: ID!\n \"\"\"\n ID of the Supply Lot which will be transfered to the active Inventory\n \"\"\"\n supplyLotId: ID!\n ): Boolean\n \"\"\"\n Deletes a Supply Lot of a SKU/Warehouse (the Supply Lot entity still exists, but with a Quantity set to 0).\n \"\"\"\n deleteSupplyLot(\n \"\"\"\n SKU scheduled to arrive in the Supply Lot\n \"\"\"\n skuId: ID!\n \"\"\"\n Warehouse where the Supply Lot is scheduled to arrive\n \"\"\"\n warehouseId: ID!\n \"\"\"\n ID of the Supply Lot which will be deleted\n \"\"\"\n supplyLotId: ID!\n ): Boolean\n}\n```"
}
] |
code_supply-lots_661070f4
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of supply-lots/node/service.json from the supply-lots VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"memory\": 256,\n \"ttl\": 10,\n \"timeout\": 2,\n \"minReplicas\": 2,\n \"maxReplicas\": 4,\n \"workers\": 1\n}\n\n```"
}
] |
code_supply-lots_4ccc79b4
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of supply-lots/node/package.json from the supply-lots VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"dependencies\": {\n \"co-body\": \"^6.0.0\",\n \"ramda\": \"^0.25.0\",\n \"uuid\": \"^8.3.2\"\n },\n \"devDependencies\": {\n \"@types/co-body\": \"^0.0.3\",\n \"@types/jest\": \"^24.0.18\",\n \"@types/node\": \"^12.0.0\",\n \"@types/ramda\": \"types/npm-ramda#dist\",\n \"@types/uuid\": \"^8.3.0\",\n \"@vtex/api\": \"6.43.0\",\n \"@vtex/test-tools\": \"^1.0.0\",\n \"@vtex/tsconfig\": \"^0.5.6\",\n \"typescript\": \"3.9.7\",\n \"vtex.render-runtime\": \"http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@8.128.4/public/@types/vtex.render-runtime\",\n \"vtex.styleguide\": \"http://vtex.vtexassets.com/_v/public/typings/v1/vtex.styleguide@9.143.0/public/@types/vtex.styleguide\"\n },\n \"scripts\": {\n \"lint\": \"tsc --noEmit --pretty\"\n },\n \"version\": \"0.1.0\"\n}\n\n```"
}
] |
code_supply-lots_5d724424
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of supply-lots/node/index.ts from the supply-lots VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { Service } from '@vtex/api'\n\nimport { clients } from './clients'\nimport { resolvers } from './resolvers'\n\n// Export a service that defines route handlers and client options.\nexport default new Service({\n clients,\n graphql: { resolvers },\n})\n\n```"
}
] |
code_supply-lots_7e1e8ebf
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of supply-lots/react/SupplyLots.tsx from the supply-lots VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport type { FC } from 'react'\nimport React from 'react'\nimport { FormattedMessage } from 'react-intl'\nimport { Layout, PageHeader } from 'vtex.styleguide'\n\nimport { commonMessages } from './utils/definedMessages'\nimport ProductsTable from './components/ProductsTable'\nimport WarehouseProvider from './components/Provider/Warehouse'\n\nconst SupplyLots: FC = () => (\n <Layout\n fullWidth\n pageHeader={\n <PageHeader title={<FormattedMessage {...commonMessages.inventory} />} />\n }\n >\n <WarehouseProvider>\n <ProductsTable />\n </WarehouseProvider>\n </Layout>\n)\n\nexport default SupplyLots\n\n```"
}
] |
code_supply-lots_2b20ba5f
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of supply-lots/react/package.json from the supply-lots VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"name\": \"vtex.admin-example\",\n \"version\": \"0.0.1\",\n \"scripts\": {\n \"test\": \"echo \\\"Error: no test specified\\\" && exit 1\"\n },\n \"devDependencies\": {\n \"@types/node\": \"^11.12.1\",\n \"@types/react\": \"^16.8.10\",\n \"@types/react-intl\": \"^2.3.17\",\n \"apollo-client\": \"^2.4.7\",\n \"graphql\": \"^14.0.2\",\n \"prop-types\": \"^15.7.2\",\n \"react\": \"^16.8.6\",\n \"react-apollo\": \"^3.1.3\",\n \"react-dom\": \"^16.8.6\",\n \"react-intl\": \"^5.18.2\",\n \"typescript\": \"3.9.7\",\n \"vtex.render-runtime\": \"http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@8.128.4/public/@types/vtex.render-runtime\",\n \"vtex.styleguide\": \"http://vtex.vtexassets.com/_v/public/typings/v1/vtex.styleguide@9.143.0/public/@types/vtex.styleguide\"\n },\n \"dependencies\": {\n \"@types/faker\": \"^4.1.5\",\n \"faker\": \"^4.1.0\",\n \"yup\": \"^0.32.9\"\n }\n}\n\n```"
}
] |
code_supply-lots_6e6dfc46
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of supply-lots/react/styles.global.css from the supply-lots VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```css\nhtml,\nbody,\n#render-container,\n#render-provider,\n.render-container,\n.render-provider {\n height: 100%;\n}\n\n```"
}
] |
code_supply-lots_23fe897c
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of supply-lots/graphql/types/entities.graphql from the supply-lots VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```graphql\ntype transfer {\n isTransfered: Boolean\n destinationItemAvailabilityId: String\n dateOfTransferUTC: String\n user: String\n}\n\ntype SupplyLot {\n \"\"\"\n ID of the Supply Lot in which the SKU's scheduling should be considered\n \"\"\"\n supplyLotId: ID\n \"\"\"\n SKU scheduled to arrive in the Supply Lot\n \"\"\"\n skuId: ID\n \"\"\"\n Warehouse where the Supply Lot is scheduled to arrive\n \"\"\"\n warehouseId: ID\n \"\"\"\n Total quantity in the Supply Lot\n \"\"\"\n totalQuantity: Int\n \"\"\"\n Quantity still available to be sold in the Supply Lot\n \"\"\"\n availableQuantity: Int\n \"\"\"\n Quantity already reserved in the Supply Lot\n \"\"\"\n reservedQuantity: Int\n \"\"\"\n Date to be considered in the SKU's scheduling\n \"\"\"\n dateOfSupplyUtc: String\n \"\"\"\n Whether to keep selling from the Supply the date expired\n \"\"\"\n keepSellingAfterExpiration: Boolean\n \"\"\"\n Details about a Supply Lot transfer, if it was already transfered\n \"\"\"\n transfer: Boolean\n dockId: ID\n isUnlimited: Boolean\n salesChannel: [String]\n deliveryChannels: [String]\n timeToRefill: String\n\n}\n \n input SupplyLotInput {\n \"\"\"\n ID of the Supply Lot in which the SKU's scheduling should be considered\n \"\"\"\n supplyLotId: ID\n \"\"\"\n SKU which will be scheduled to arrive in the Supply Lot\n \"\"\"\n skuId: ID!\n \"\"\"\n Warehouse where the Supply Lot will be scheduled to arrive\n \"\"\"\n warehouseId: ID!\n \"\"\"\n SKU quantity in the Supply Lot\n \"\"\"\n totalQuantity: Int!\n \"\"\"\n Date to be considered in the SKU's scheduling\n \"\"\"\n dateOfSupplyUtc: String!\n \"\"\"\n Whether to keep selling from the Supply the date expired\n \"\"\"\n keepSellingAfterExpiration: Boolean!\n}\n```"
}
] |
code_supply-lots_e0d60493
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of supply-lots/node/clients/supplyLot.ts from the supply-lots VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport type { InstanceOptions, IOContext } from '@vtex/api'\nimport { JanusClient } from '@vtex/api'\n\nexport class SupplyLot extends JanusClient {\n protected baseURL = '/api/logistics/pvt/inventory/items'\n constructor(ctx: IOContext, options?: InstanceOptions) {\n super(ctx, {\n ...options,\n headers: {\n ...options?.headers,\n ...(ctx.adminUserAuthToken\n ? { VtexIdclientAutCookie: ctx.adminUserAuthToken }\n : null),\n },\n })\n }\n\n public list = (skuId: string, warehouseId: string, supplyLotId?: string) =>\n this.http.get<SupplyLotInterface[]>(\n `${this.baseURL}/${encodeURI(skuId)}/warehouses/${encodeURI(\n warehouseId\n )}/supplyLots${supplyLotId ? `/${encodeURI(supplyLotId)}` : ``}`\n )\n\n public set = (supplyLotData: SupplyLotInterface) =>\n this.http\n .put(\n `${this.baseURL}/${encodeURI(\n supplyLotData.skuId\n )}/warehouses/${encodeURI(\n supplyLotData.warehouseId\n )}/supplyLots/${encodeURI(supplyLotData.supplyLotId)}`,\n {\n quantity: supplyLotData.totalQuantity,\n dateOfSupplyUtc: supplyLotData.dateOfSupplyUtc,\n keepSellingAfterExpiration: supplyLotData.keepSellingAfterExpiration,\n }\n )\n .then(() => true)\n\n public transfer = (skuId: string, warehouseId: string, supplyLotId: string) =>\n this.http\n .post(\n `${this.baseURL}/${encodeURI(skuId)}/warehouses/${encodeURI(\n warehouseId\n )}/supplyLots/${encodeURI(supplyLotId)}/transfer`\n )\n .then(() => true)\n\n public delete = (skuId: string, warehouseId: string, supplyLotId: string) =>\n this.http\n .delete(\n `${this.baseURL}/${encodeURI(skuId)}/warehouses/${encodeURI(\n warehouseId\n )}/supplyLots/${encodeURI(supplyLotId)}`\n )\n .then(() => true)\n}\n\n```"
}
] |
code_supply-lots_59e9c3f9
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of supply-lots/node/clients/logistics.ts from the supply-lots VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport type { InstanceOptions, IOContext } from '@vtex/api'\nimport { JanusClient } from '@vtex/api'\n\nexport class Logistics extends JanusClient {\n protected baseURL = '/api/logistics/pvt'\n constructor(ctx: IOContext, options?: InstanceOptions) {\n super(ctx, {\n ...options,\n headers: {\n ...options?.headers,\n ...(ctx.adminUserAuthToken\n ? { VtexIdclientAutCookie: ctx.adminUserAuthToken }\n : null),\n },\n })\n }\n\n public warehouseName = (warehouseId: string) =>\n this.http.get<{ id: string, name: string }[]>(\n `${this.baseURL}/configuration/warehouses`\n ).then(data => \n data.find((element: { id: string }) => \n element.id === warehouseId\n )?.name\n ).catch(() => undefined)\n}\n```"
}
] |
code_supply-lots_564b901c
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of supply-lots/node/clients/index.ts from the supply-lots VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport type { ClientsConfig } from '@vtex/api'\nimport { IOClients, LRUCache } from '@vtex/api'\n\nimport { SupplyLot } from './supplyLot'\nimport { Catalog } from './catalog'\nimport { Logistics } from './logistics'\n\nconst REQUESTS_TIMEOUT = 10000\n\n// Create a LRU memory cache for the Status client.\n// The @vtex/api HttpClient respects Cache-Control headers and uses the provided cache.\nconst memoryCache = new LRUCache<string, any>({ max: 5000 })\n\nmetrics.trackCache('status', memoryCache)\n\n// Extend the default IOClients implementation with our own custom clients.\nexport class Clients extends IOClients {\n public get supplyLot() {\n return this.getOrSet('supplyLot', SupplyLot)\n }\n public get catalog() {\n return this.getOrSet('catalog', Catalog)\n }\n public get logistics() {\n return this.getOrSet('logistics', Logistics)\n }\n}\n\nexport const clients: ClientsConfig<Clients> = {\n implementation: Clients,\n options: {\n default: {\n retries: 2,\n timeout: REQUESTS_TIMEOUT,\n },\n status: {\n memoryCache,\n }\n },\n}\n```"
}
] |
code_supply-lots_ddba2a7d
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of supply-lots/node/clients/catalog.ts from the supply-lots VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport type { IOContext, InstanceOptions } from '@vtex/api'\nimport { JanusClient } from '@vtex/api'\n\nexport class Catalog extends JanusClient {\n protected baseURL = '/api/catalog/pvt'\n constructor(ctx: IOContext, options?: InstanceOptions) {\n super(ctx, {\n ...options,\n headers: {\n ...options?.headers,\n ...(ctx.adminUserAuthToken\n ? { VtexIdclientAutCookie: ctx.adminUserAuthToken }\n : null),\n },\n })\n }\n\n public skuName = (skuId: string) => \n this.http.get<{ Name: string }>(\n `${this.baseURL}/stockkeepingunit/${encodeURI(skuId)}`\n ).then(sku => sku.Name)\n .catch(() => undefined)\n}\n\n\n```"
}
] |
code_supply-lots_4457d978
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of supply-lots/node/typings/supplyLot.d.ts from the supply-lots VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\ninterface SupplyLotInterface {\n supplyLotId: string\n skuId: string\n warehouseId: string\n totalQuantity: number\n dateOfSupplyUtc: string\n keepSellingAfterExpiration: boolean\n transfer: {\n isTransfered: boolean\n destinationItemAvailabilityId: string\n dateOfTransferUTC: string\n user: string\n }\n}\n\n```"
}
] |
code_supply-lots_7fc8dbc0
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of supply-lots/node/typings/index.d.ts from the supply-lots VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport type { ServiceContext } from '@vtex/api'\n\nimport type { Clients } from '../clients'\n\ndeclare global {\n // We declare a global Context type just to avoid re-writing ServiceContext<Clients, State> in every handler and resolver\n type Context = ServiceContext<Clients>\n}\n```"
}
] |
code_supply-lots_2799d22c
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of supply-lots/node/resolvers/index.ts from the supply-lots VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { getSkuAndWarehouseNames } from './getSkuAndWarehouseNames'\nimport { listSupplyLots, setSupplyLot, transferSupplyLot, deleteSupplyLot } from './supplyLots'\n\nexport const resolvers = {\n Query: {\n getSkuAndWarehouseNames,\n listSupplyLots\n },\n Mutation: {\n setSupplyLot,\n transferSupplyLot,\n deleteSupplyLot,\n },\n}\n```"
}
] |
code_supply-lots_44f69b87
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of supply-lots/node/resolvers/getSkuAndWarehouseNames.ts from the supply-lots VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nexport const getSkuAndWarehouseNames = (\n _: any,\n { skuId, warehouseId }: { skuId: string, warehouseId: string },\n { clients: { catalog, logistics } }: Context\n) => Promise.all([\n catalog.skuName(skuId),\n logistics.warehouseName(warehouseId)\n])\n\n```"
}
] |
code_supply-lots_8253d804
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of supply-lots/node/resolvers/supplyLots/index.ts from the supply-lots VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { v4 } from 'uuid'\n\nexport const listSupplyLots = (\n _: any,\n {\n skuId,\n warehouseId,\n supplyLotId,\n filterZeros,\n }: {\n skuId: string\n warehouseId: string\n supplyLotId?: string\n filterZeros: boolean\n },\n { clients: { supplyLot } }: Context\n) =>\n supplyLot\n .list(skuId, warehouseId, supplyLotId)\n .then((list) =>\n filterZeros ? list.filter((lot) => lot.totalQuantity > 0) : list\n )\n\nexport const setSupplyLot = (\n _: any,\n { supplyLotData }: { supplyLotData: SupplyLotInterface },\n { clients: { supplyLot } }: Context\n) =>\n (supplyLotData.supplyLotId = supplyLotData.supplyLotId || v4()) &&\n supplyLot.set(supplyLotData)\n\nexport const transferSupplyLot = (\n _: any,\n {\n skuId,\n warehouseId,\n supplyLotId,\n }: { skuId: string; warehouseId: string; supplyLotId: string },\n { clients: { supplyLot } }: Context\n) => supplyLot.transfer(skuId, warehouseId, supplyLotId)\n\nexport const deleteSupplyLot = (\n _: any,\n {\n skuId,\n warehouseId,\n supplyLotId,\n }: { skuId: string; warehouseId: string; supplyLotId: string },\n { clients: { supplyLot } }: Context\n) => supplyLot.delete(skuId, warehouseId, supplyLotId)\n\n```"
}
] |
code_supply-lots_2f40804d
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of supply-lots/react/typings/warehouse.d.ts from the supply-lots VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\ninterface Warehouse {\n name?: string\n id?: string\n [index: string]: string\n}\n\n```"
}
] |
code_supply-lots_aeb46ea7
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of supply-lots/react/typings/vtex.render-runtime.d.ts from the supply-lots VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\ndeclare module 'vtex.render-runtime'{\n export const useRuntime\n}\n```"
}
] |
code_supply-lots_f45ab185
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of supply-lots/react/typings/supplyLot.d.ts from the supply-lots VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\ninterface SupplyLotInput {\n supplyLotId?: string\n skuId: string\n warehouseId: string\n totalQuantity: number\n dateOfSupplyUtc: string\n keepSellingAfterExpiration: boolean\n transfer?: {\n isTransfered?: boolean\n destinationItemAvailabilityId?: string\n dateOfTransferUTC?: string\n user?: string\n }\n }\n```"
}
] |
code_supply-lots_cbf07571
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of supply-lots/react/typings/sku.d.ts from the supply-lots VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\ninterface Sku {\n name?: string\n id?: string\n [index: string]: string\n}\n\n```"
}
] |
code_supply-lots_99f66893
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of supply-lots/react/typings/graphql.d.ts from the supply-lots VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\ndeclare module '*.gql' {\n import type { DocumentNode } from 'graphql'\n\n const Schema: DocumentNode\n\n export default Schema\n}\n\n```"
}
] |
code_supply-lots_863ab095
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of supply-lots/react/typings/actions.d.ts from the supply-lots VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\ninterface ActionsValues {\n 1: boolean,\n 2: boolean,\n 3: boolean,\n 4: boolean,\n 5: boolean,\n 6: boolean,\n 7: boolean,\n 8: boolean,\n 9: boolean,\n 10: boolean,\n [index: number]: boolean\n}\n```"
}
] |
code_supply-lots_c412e26a
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of supply-lots/react/typings/vtex.styleguide.d.ts from the supply-lots VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\ndeclare module 'vtex.styleguide' {\n export const Alert\n export const Button\n export const PageBlock\n export const Layout\n export const PageHeader\n export const Card\n export const Checkbox\n export const Tab\n export const Tabs\n export const Tag\n export const ButtonWithIcon\n export const ButtonPlain\n export const IconDownload\n export const IconDelete\n export const IconEdit\n export const IconExternalLinkMini\n export const ToastProvider\n export const withToast\n export const Box\n export const LineChart\n export const Toggle\n export const Table\n export const IconArrowUp\n export const IconArrowDown\n export const IconWarning\n export const IconClose\n export const Spinner\n export const Tooltip\n export const InputSearch\n export const Input\n export const Modal\n export const FilterBar\n export const IconClear\n export const IconSearch\n export const IconFailure\n export const IconInfo\n export const Divider\n export const DatePicker\n export const Dropdown\n export const TimePicker\n // eslint-disable-next-line @typescript-eslint/naming-convention\n export const EXPERIMENTAL_Select\n // eslint-disable-next-line @typescript-eslint/naming-convention\n export const EXPERIMENTAL_useCheckboxTree\n // eslint-disable-next-line @typescript-eslint/naming-convention\n export const EXPERIMENTAL_useTableMeasures\n // eslint-disable-next-line @typescript-eslint/naming-convention\n export const EXPERIMENTAL_useTableProportion\n}\n\n```"
}
] |
code_supply-lots_389a7948
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of supply-lots/react/queries/deleteSupplyLot.gql from the supply-lots VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```graphql\nmutation deleteSupplyLot($skuId: ID!,$warehouseId: ID!, $supplyLotId: ID!){\n deleteSupplyLot(skuId: $skuId, warehouseId: $warehouseId, supplyLotId: $supplyLotId )\n}\n \n \n```"
}
] |
code_supply-lots_cc63d8bb
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of supply-lots/react/queries/transferSupplyLot.gql from the supply-lots VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```graphql\nmutation transferSupplyLot($skuId: ID!,$warehouseId: ID!, $supplyLotId: ID!){\n transferSupplyLot(skuId: $skuId, warehouseId: $warehouseId, supplyLotId: $supplyLotId )\n}\n \n \n```"
}
] |
code_supply-lots_bd4891f3
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of supply-lots/react/queries/listSupplyLots.gql from the supply-lots VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```graphql\nquery listSupplyLots($skuId: ID!, $warehouseId: ID!, $supplyLotId: ID) {\n listSupplyLots(skuId: $skuId, warehouseId: $warehouseId, supplyLotId: $supplyLotId) {\n supplyLotId\n skuId\n warehouseId\n totalQuantity\n dateOfSupplyUtc\n keepSellingAfterExpiration\n availableQuantity\n reservedQuantity\n }\n}\n\n```"
}
] |
code_supply-lots_64de1d67
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of supply-lots/react/queries/setSupplyLot.gql from the supply-lots VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```graphql\nmutation setSupplyLot($supplyLotData: SupplyLotInput!, $updateExisting: Boolean){\n setSupplyLot(supplyLotData: $supplyLotData, updateExisting: $updateExisting)\n}\n\n```"
}
] |
code_supply-lots_b20082ad
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of supply-lots/react/queries/getSkuAndWarehouseNames.gql from the supply-lots VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```graphql\nquery getSkuAndWarehouseNames($skuId: String!, $warehouseId: String!) {\n getSkuAndWarehouseNames(skuId: $skuId, warehouseId: $warehouseId) \n}\n\n```"
}
] |
code_supply-lots_4b0e8411
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of supply-lots/react/utils/definedMessages.ts from the supply-lots VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { defineMessages } from 'react-intl'\n\nexport const commonMessages = defineMessages({\n inventory: { id: 'admin/inventory' },\n retry: { id: 'admin/inventory.commons.retry' },\n loading: {\n id: 'admin/inventory.commons.loading',\n },\n skuDoesntExist: { id: 'admin/inventory.commons.sku-doesnt-exist' },\n})\n\nexport const optionModalAdd = defineMessages({\n optionsTrue: {\n id: 'admin/options-true',\n },\n optionsFalse: {\n id: 'admin/options-false',\n },\n})\n\nexport const commonModal = defineMessages({\n save: {\n id: 'admin/save',\n },\n cancel: {\n id: 'admin/cancel',\n },\n delete: {\n id: 'admin/delete',\n },\n})\n\nexport const modalAddTexts = defineMessages({\n titleEdit: {\n id: 'admin/title-edit',\n },\n titleAdd: {\n id: 'admin/title-add',\n },\n date: {\n id: 'admin/date',\n },\n datePlaceholder: {\n id: 'admin/date-placeholder',\n },\n total: {\n id: 'admin/total',\n },\n totalPlaceholder: {\n id: 'admin/total-placeholder',\n },\n keep: {\n id: 'admin/keep',\n },\n keepPlaceholder: {\n id: 'admin/keep-placeholder',\n },\n})\n\nexport const modalDelete = defineMessages({\n deleteText: {\n id: 'admin/delete-text',\n },\n deleteQuestion: {\n id: 'admin/delete-question',\n },\n deleteReason: {\n id: 'admin/delete-reason',\n },\n})\n\nexport const modalLimit = defineMessages({\n limit: {\n id: 'admin/limit',\n },\n})\n\nexport const modalTransfer = defineMessages({\n transfer: {\n id: 'admin/transfer',\n },\n transferText: {\n id: 'admin/transfer-text',\n },\n transferQuestion: {\n id: 'admin/transfer-question',\n },\n})\n\nexport const productTable = defineMessages({\n titleProdutctTable: {\n id: 'admin/title-product-table',\n },\n link: {\n id: 'admin/link',\n },\n toolbar: {\n id: 'admin/toolbar',\n },\n totalizersSku: {\n id: 'admin/totalizers-sku',\n },\n totalizersProduct: {\n id: 'admin/totalizers-product',\n },\n totalizersWarehouseId: {\n id: 'admin/totalizers-warehouse-id',\n },\n totalizersWarehouse: {\n id: 'admin/totalizers-warehouse',\n },\n})\n\nexport const provider = defineMessages({\n textNotice: {\n id: 'admin/text-notice',\n },\n textNoticeNumber: {\n id: 'admin/text-notice-number',\n },\n yes: {\n id: 'admin/yes',\n },\n no: {\n id: 'admin/no',\n },\n regular: {\n id: 'admin/regular',\n },\n expired: {\n id: 'admin/expired',\n },\n expiredYes: {\n id: 'admin/expired-yes',\n },\n expiring: {\n id: 'admin/expiring',\n },\n day: {\n id: 'admin/day',\n },\n days: {\n id: 'admin/days',\n },\n index: {\n id: 'admin/index',\n },\n date: {\n id: 'admin/date-provider',\n },\n total: {\n id: 'admin/total-provider',\n },\n reserved: {\n id: 'admin/reserved',\n },\n available: {\n id: 'admin/available',\n },\n keep: {\n id: 'admin/keep-provider',\n },\n info: {\n id: 'admin/info',\n },\n status: {\n id: 'admin/status',\n },\n actions: {\n id: 'admin/actions',\n },\n edit: {\n id: 'admin/edit',\n },\n delete: {\n id: 'admin/delete-provider',\n },\n transfer: {\n id: 'admin/transfer-provider',\n },\n})\n\n```"
}
] |
code_supply-lots_640ad38d
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of supply-lots/react/icons/IconsTransferBig.tsx from the supply-lots VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport type { FunctionComponent, ReactElement } from 'react'\nimport React from 'react'\n\nconst IconTransferBig: FunctionComponent = (): ReactElement => (\n <svg\n width=\"70\"\n height=\"70\"\n viewBox=\"0 0 16 16\"\n fill=\"rgb(237, 244, 250)\"\n xmlns=\"http://www.w3.org/2000/svg\"\n >\n <rect width=\"0\" height=\"0\" fill=\"rgb(237, 244, 250)\" />\n <path\n fill-rule=\"evenodd\"\n clip-rule=\"evenodd\"\n d=\"M5.21689 0.0303759C5.07513 -0.0101253 4.92487 -0.0101253 4.78311 0.0303759L0.577332 1.23203C0.554477 1.2384 0.531889 1.24581 0.509639 1.25425C0.401044 1.29535 0.305097 1.35902 0.226585 1.4389C0.184751 1.48144 0.148112 1.52834 0.117178 1.5786C0.042366 1.70005 2.62722e-06 1.84239 0 1.99247V8.00751C0 8.36 0.233666 8.66978 0.572589 8.76661L4.78311 9.96962C4.92487 10.0101 5.07513 10.0101 5.21689 9.96962L9.42741 8.76661C9.76633 8.66978 10 8.36 10 8.00751V1.99248C10 1.78388 9.91755 1.58545 9.77341 1.4389C9.74638 1.41142 9.71718 1.38575 9.68594 1.36219C9.62646 1.31732 9.56167 1.28163 9.49368 1.25551C9.47035 1.24655 9.44666 1.23872 9.42266 1.23203L9.42741 1.23338C9.44998 1.23983 9.47208 1.24723 9.49368 1.25551M8.42105 3.0391L5.78947 3.79098V8.16389L8.42105 7.41201V3.0391ZM1.57895 3.03911L4.21053 3.79099V8.16389L1.57895 7.41201V3.03911Z\"\n fill=\"rgb(61, 89, 128)\"\n />\n <path\n fill-rule=\"evenodd\"\n clip-rule=\"evenodd\"\n d=\"M12.6159 11.0572L10.8035 9.33333L12.2053 8L15.7097 11.3333C16.0968 11.7015 16.0968 12.2985 15.7097 12.6667L12.2053 16L10.8035 14.6667L12.6159 12.9428H8L8 11.0572H12.6159Z\"\n fill=\" rgb(61, 89, 128)\"\n />\n </svg>\n)\n\nexport default IconTransferBig\n\n```"
}
] |
code_supply-lots_40eeec66
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of supply-lots/react/icons/IconTrashCan.tsx from the supply-lots VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport type { FunctionComponent, ReactElement } from 'react'\nimport React from 'react'\n\nconst IconTrashCan: FunctionComponent = (): ReactElement => (\n <svg\n width=\"218\"\n height=\"70\"\n viewBox=\"0 0 218 70\"\n fill=\"none\"\n xmlns=\"http://www.w3.org/2000/svg\"\n >\n <path d=\"M100.613 7.73446V1H117.387V7.73446\" fill=\"#EDF4FA\" />\n <path\n d=\"M100.613 7.73446V1H117.387V7.73446\"\n stroke=\"#3D5980\"\n strokeWidth=\"2\"\n strokeMiterlimit=\"10\"\n strokeLinecap=\"square\"\n />\n <path\n d=\"M127.45 14.469V48.1413C127.45 50.0008 125.948 51.5085 124.095 51.5085H93.9017C92.049 51.5085 90.5469 50.0008 90.5469 48.1413V14.469\"\n fill=\"#EDF4FA\"\n />\n <path\n d=\"M127.45 14.469V48.1413C127.45 50.0008 125.948 51.5085 124.095 51.5085H93.9017C92.049 51.5085 90.5469 50.0008 90.5469 48.1413V14.469\"\n stroke=\"#3D5980\"\n strokeWidth=\"2\"\n strokeMiterlimit=\"10\"\n strokeLinecap=\"square\"\n />\n <path\n d=\"M109 25.4124V40.5649\"\n stroke=\"#3D5980\"\n strokeWidth=\"2\"\n strokeMiterlimit=\"10\"\n strokeLinecap=\"square\"\n />\n <path\n d=\"M100.613 25.4124V40.5649\"\n stroke=\"#3D5980\"\n strokeWidth=\"2\"\n strokeMiterlimit=\"10\"\n strokeLinecap=\"square\"\n />\n <path\n d=\"M117.387 25.4124V40.5649\"\n stroke=\"#3D5980\"\n strokeWidth=\"2\"\n strokeMiterlimit=\"10\"\n strokeLinecap=\"square\"\n />\n <path\n d=\"M132.483 7.73444H85.5156V14.4689H132.483V7.73444Z\"\n fill=\"#EDF4FA\"\n stroke=\"#3D5980\"\n strokeWidth=\"2\"\n strokeMiterlimit=\"10\"\n strokeLinecap=\"square\"\n />\n </svg>\n)\n\nexport default IconTrashCan\n\n```"
}
] |
code_supply-lots_68a24e3c
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of supply-lots/react/icons/IconsTransfer.tsx from the supply-lots VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport type { FunctionComponent, ReactElement } from 'react'\nimport React from 'react'\n\nconst IconTransfer: FunctionComponent = (): ReactElement => (\n <svg\n width=\"21\"\n height=\"21\"\n viewBox=\"0 0 16 16\"\n fill=\"red\"\n xmlns=\"http://www.w3.org/2000/svg\"\n >\n <rect width=\"0\" height=\"0\" fill=\"white\" />\n <path\n fill-rule=\"evenodd\"\n clip-rule=\"evenodd\"\n d=\"M5.21689 0.0303759C5.07513 -0.0101253 4.92487 -0.0101253 4.78311 0.0303759L0.577332 1.23203C0.554477 1.2384 0.531889 1.24581 0.509639 1.25425C0.401044 1.29535 0.305097 1.35902 0.226585 1.4389C0.184751 1.48144 0.148112 1.52834 0.117178 1.5786C0.042366 1.70005 2.62722e-06 1.84239 0 1.99247V8.00751C0 8.36 0.233666 8.66978 0.572589 8.76661L4.78311 9.96962C4.92487 10.0101 5.07513 10.0101 5.21689 9.96962L9.42741 8.76661C9.76633 8.66978 10 8.36 10 8.00751V1.99248C10 1.78388 9.91755 1.58545 9.77341 1.4389C9.74638 1.41142 9.71718 1.38575 9.68594 1.36219C9.62646 1.31732 9.56167 1.28163 9.49368 1.25551C9.47035 1.24655 9.44666 1.23872 9.42266 1.23203L9.42741 1.23338C9.44998 1.23983 9.47208 1.24723 9.49368 1.25551M8.42105 3.0391L5.78947 3.79098V8.16389L8.42105 7.41201V3.0391ZM1.57895 3.03911L4.21053 3.79099V8.16389L1.57895 7.41201V3.03911Z\"\n fill=\"#134cd8\"\n />\n <path\n fill-rule=\"evenodd\"\n clip-rule=\"evenodd\"\n d=\"M12.6159 11.0572L10.8035 9.33333L12.2053 8L15.7097 11.3333C16.0968 11.7015 16.0968 12.2985 15.7097 12.6667L12.2053 16L10.8035 14.6667L12.6159 12.9428H8L8 11.0572H12.6159Z\"\n fill=\"#134cd8\"\n />\n </svg>\n)\n\nexport default IconTransfer\n\n```"
}
] |
code_supply-lots_e2a3d1b8
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of supply-lots/react/components/Context/WarehouseContext.tsx from the supply-lots VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport type { SyntheticEvent } from 'react'\nimport React from 'react'\n\ninterface WarehouseContextType {\n warehouse: Warehouse\n sku: Sku\n newSupplyLot: () => void\n orderedItems: any\n schemaTable: any\n modal: number\n setModal: (modal: number) => void\n setDate: (date: Date) => void\n date: Date | undefined\n setKeep: (keep: boolean) => void\n keep: boolean | undefined\n updateItems: (object: number) => void\n items: number | undefined\n modalDelete: boolean | undefined\n setDelete: (modalDelete: boolean) => void\n modalTransfer: boolean | undefined\n setTransfer: (modalDelete: boolean) => void\n addSupplyLot: () => void\n editSupplyLot: () => void\n deleteSupplyLots: () => void\n transferSupplyLots: () => void\n text: string\n limit: boolean\n sortedByValue: string\n sortOrderValue: string\n sort: (sortOrder: any, sortedBy: any) => void\n setText: (text: string) => void\n}\nconst WarehouseContext = React.createContext<WarehouseContextType>({\n warehouse: {},\n sku: {},\n newSupplyLot: () => {},\n orderedItems: {},\n schemaTable: {},\n modal: 0,\n setModal: () => {},\n setDate: () => {},\n date: new Date(),\n setKeep: () => {},\n keep: false,\n updateItems: () => {},\n items: 0,\n modalDelete: false,\n setDelete: () => {},\n modalTransfer: false,\n setTransfer: () => {},\n addSupplyLot: () => {},\n editSupplyLot: () => {},\n deleteSupplyLots: () => {},\n transferSupplyLots: () => {},\n text: '',\n limit: false,\n sortedByValue: '',\n sortOrderValue: '',\n sort: () => {},\n setText: () => {},\n})\n\nexport default WarehouseContext\n\n```"
}
] |
code_supply-lots_bd69fc73
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of supply-lots/react/components/Provider/Warehouse.tsx from the supply-lots VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\n/* eslint-disable vtex/prefer-early-return */\n/* eslint-disable func-names */\nimport type { FC, SyntheticEvent } from 'react'\nimport React, { useEffect, useMemo, useState } from 'react'\nimport { useMutation, useQuery } from 'react-apollo'\nimport * as yup from 'yup'\nimport {\n IconDelete,\n IconEdit,\n Tag,\n Tooltip,\n Button,\n IconInfo,\n} from 'vtex.styleguide'\nimport { injectIntl, useIntl } from 'react-intl'\n\nimport WarehouseContext from '../Context/WarehouseContext'\nimport getSkuAndWarehouseNames from '../../queries/getSkuAndWarehouseNames.gql'\nimport listSupplyLots from '../../queries/listSupplyLots.gql'\nimport setSupplyLot from '../../queries/setSupplyLot.gql'\nimport deleteSupplyLot from '../../queries/deleteSupplyLot.gql'\nimport transferSupplyLot from '../../queries/transferSupplyLot.gql'\nimport IconTransfer from '../../icons/IconsTransfer'\nimport { provider } from '../../utils/definedMessages'\n\nconst initialSku = {\n id: '',\n name: '',\n}\n\nconst initialWarehouse = {\n id: '',\n name: '',\n}\n\nconst schemaYup = yup.object().shape({\n dateOfSupplyUtc: yup.date().required(),\n keepSellingAfterExpiration: yup.boolean().required(),\n totalQuantity: yup.number().required().positive().integer(),\n})\n\nconst WarehouseProvider: FC = (props) => {\n // Definições\n const intl = useIntl()\n const [warehouse, setWarehouse] = useState<Warehouse>(initialWarehouse)\n const [sku, setSku] = useState<Sku>(initialSku)\n const [date, setDate] = useState<Date>()\n const [keep, setKeep] = useState<boolean>()\n const [items, setItems] = useState<number>()\n const [modal, setModal] = useState(0)\n const [modalDelete, setDelete] = useState(false)\n const [modalTransfer, setTransfer] = useState(false)\n const [text, setText] = useState('')\n const [id, setId] = useState('')\n const [sortedByValue, setSortedBy] = useState('index')\n const [sortOrderValue, setSortOrder] = useState('index')\n const [limit, setLimit] = useState(false)\n const [orderedItems, setOrderedItems] = useState<any[]>()\n\n const { data: dataListSupplyLots, refetch } = useQuery(listSupplyLots, {\n variables: { skuId: sku.id, warehouseId: warehouse.id },\n })\n\n const { data: dataNames } = useQuery(getSkuAndWarehouseNames, {\n variables: { skuId: sku.id, warehouseId: warehouse.id },\n })\n\n const [setSupplyLotValue] = useMutation(setSupplyLot)\n const [deleteSupplyLotValue] = useMutation(deleteSupplyLot)\n const [transferSupplyLotValue] = useMutation(transferSupplyLot)\n\n useEffect(() => {\n const url = window.location.href\n let values = url.split('?')\n\n if (values[1] !== undefined) {\n values = values[1].split('&')\n const idSku = values[0].split('=')\n const idWarehouse = values[1].split('=')\n\n updateSku({ id: idSku[1] })\n updateWarehouse({ id: idWarehouse[1] })\n }\n }, [])\n\n useMemo(() => {\n if (dataNames) {\n updateSku({ name: dataNames?.getSkuAndWarehouseNames[0] })\n updateWarehouse({ name: dataNames?.getSkuAndWarehouseNames[1] })\n }\n }, [dataNames])\n\n function updateSku(object: Sku) {\n setSku({ ...sku, ...object })\n }\n\n function updateWarehouse(object: Warehouse) {\n setWarehouse({ ...warehouse, ...object })\n }\n\n function updateItems(object: number) {\n setItems(object)\n }\n\n // Funções da tabela\n async function validation() {\n const object = {\n dateOfSupplyUtc: date,\n keepSellingAfterExpiration: keep,\n totalQuantity: items,\n }\n\n const retorno = await schemaYup.validate(object).catch(function (err) {\n err.name\n err.errors\n\n if (err.errors[0] === 'totalQuantity must be a positive number') {\n setText(intl.formatMessage(provider.textNoticeNumber))\n } else {\n setText(intl.formatMessage(provider.textNotice))\n }\n\n return false\n })\n\n return retorno\n }\n\n async function addSupplyLot() {\n const valid = await validation()\n\n if (valid) {\n setModal(0)\n setText('')\n let dateValue = '0000-00-00'\n\n if (date !== undefined) dateValue = date?.toISOString()\n const supplyLotData: SupplyLotInput = {\n dateOfSupplyUtc: dateValue,\n keepSellingAfterExpiration: keep ?? false,\n skuId: sku.id ? sku.id : '',\n warehouseId: warehouse.id ? warehouse.id : '',\n totalQuantity: items ?? 0,\n }\n\n await setSupplyLotValue({ variables: { supplyLotData } })\n\n refetch()\n }\n }\n\n function newSupplyLot() {\n setModal(1)\n setDate(undefined)\n setKeep(undefined)\n setItems(undefined)\n }\n\n async function editSupplyLot() {\n const valid = await validation()\n\n if (valid) {\n setModal(0)\n setText('')\n\n let dateValue = '0000-00-00'\n\n if (date !== undefined) dateValue = date?.toISOString()\n const supplyLotData: SupplyLotInput = {\n dateOfSupplyUtc: dateValue,\n keepSellingAfterExpiration: keep ?? false,\n skuId: sku.id ? sku.id : '',\n warehouseId: warehouse.id ? warehouse.id : '',\n totalQuantity: items ?? 0,\n supplyLotId: id || '',\n }\n\n await setSupplyLotValue({ variables: { supplyLotData } })\n\n refetch()\n }\n }\n\n async function clickEdit(index: number, supplyLotId: string) {\n setModal(2)\n const dateValue = new Date(\n dataListSupplyLots?.listSupplyLots[index]?.dateOfSupplyUtc\n )\n\n setDate(dateValue)\n setItems(dataListSupplyLots?.listSupplyLots[index]?.totalQuantity)\n setKeep(\n dataListSupplyLots?.listSupplyLots[index]?.keepSellingAfterExpiration\n )\n\n setId(supplyLotId)\n }\n\n async function deleteSupplyLots() {\n setDelete(false)\n await deleteSupplyLotValue({\n variables: { skuId: sku.id, warehouseId: warehouse.id, supplyLotId: id },\n })\n\n refetch()\n }\n\n function clickDelete(supplyLotId: string) {\n setDelete(true)\n setId(supplyLotId)\n }\n\n async function transferSupplyLots() {\n setTransfer(false)\n await transferSupplyLotValue({\n variables: { skuId: sku.id, warehouseId: warehouse.id, supplyLotId: id },\n })\n\n refetch()\n }\n\n function clickTransfer(supplyLotId: string) {\n setTransfer(true)\n setId(supplyLotId)\n }\n\n const listSupplyLotsValues = useMemo(() => {\n const tableValues: any[] = []\n\n if (\n dataListSupplyLots?.listSupplyLots.length === 8 &&\n !limit &&\n modal === 1\n ) {\n setLimit(true)\n } else if (limit) {\n setLimit(false)\n }\n\n // eslint-disable-next-line array-callback-return\n dataListSupplyLots?.listSupplyLots.map(function (\n values: {\n supplyLotId: string\n dateOfSupplyUtc: string\n totalQuantity: number\n keepSellingAfterExpiration: boolean\n reservedQuantity: number\n availableQuantity: number\n },\n indexOf: number\n ) {\n const value = {\n index: indexOf + 1,\n date: new Date(values.dateOfSupplyUtc).toLocaleDateString(),\n total: values.totalQuantity,\n reserved: values.reservedQuantity,\n available: values.availableQuantity,\n keepSelling: values.keepSellingAfterExpiration\n ? intl.formatMessage(provider.yes)\n : intl.formatMessage(provider.no),\n color: colorLabel(\n values.keepSellingAfterExpiration,\n values.dateOfSupplyUtc\n ),\n actions: {\n index: indexOf,\n skuId: sku.id,\n warehouseId: warehouse.id,\n supplyLotId: values.supplyLotId,\n },\n }\n\n tableValues.push(value)\n })\n\n setOrderedItems(tableValues)\n\n return tableValues\n }, [dataListSupplyLots])\n\n function converter(dateConverter: string) {\n const parts = dateConverter.split('/')\n\n return new Date(\n parseInt(parts[2], 10),\n parseInt(parts[1], 10) - 1,\n parseInt(parts[0], 10)\n )\n }\n\n function sortDateASC() {\n listSupplyLotsValues.sort(function (a, b) {\n if (converter(a.date) > converter(b.date)) {\n return 1\n }\n\n if (converter(a.date) < converter(b.date)) {\n return -1\n }\n\n // a must be equal to b\n return 0\n })\n }\n\n function sortDateDESC() {\n listSupplyLotsValues.sort(function (a, b) {\n if (converter(a.date) < converter(b.date)) {\n return 1\n }\n\n if (converter(a.date) > converter(b.date)) {\n return -1\n }\n\n // a must be equal to b\n return 0\n })\n }\n\n function sortIndexASC() {\n listSupplyLotsValues.sort(function (a, b) {\n if (a.index > b.index) {\n return 1\n }\n\n if (a.index < b.index) {\n return -1\n }\n\n // a must be equal to b\n return 0\n })\n }\n\n function sortIndexDESC() {\n listSupplyLotsValues.sort(function (a, b) {\n if (a.index < b.index) {\n return 1\n }\n\n if (a.index > b.index) {\n return -1\n }\n\n // a must be equal to b\n return 0\n })\n }\n\n function sort({\n sortOrder,\n sortedBy,\n }: {\n sortOrder: string\n sortedBy: string\n }) {\n if (sortedBy === 'date') {\n if (sortOrder === 'ASC') {\n sortDateASC()\n } else {\n sortDateDESC()\n }\n } else if (sortOrder === 'ASC') {\n sortIndexASC()\n } else {\n sortIndexDESC()\n }\n\n setOrderedItems(listSupplyLotsValues)\n setSortOrder(sortOrder)\n setSortedBy(sortedBy)\n }\n\n useMemo(() => {\n listSupplyLotsValues.sort(function (a, b) {\n if (a.index > b.index) {\n return 1\n }\n\n if (a.index < b.index) {\n return -1\n }\n\n // a must be equal to b\n return 0\n })\n }, [listSupplyLotsValues])\n\n function colorLabel(\n keepSellingAfterExpiration: boolean,\n dateOfSupplyUtc: string\n ) {\n let color = '#8bc34a'\n let label = intl.formatMessage(provider.regular)\n const dateNow = new Date()\n const dateUTC = dateNow.toUTCString()\n\n const secondsdateOfSupplyUtc = Date.parse(dateOfSupplyUtc)\n const secondsNow = Date.parse(dateUTC)\n\n if (secondsdateOfSupplyUtc < secondsNow && !keepSellingAfterExpiration) {\n label = intl.formatMessage(provider.expired)\n color = 'red'\n } else if (\n secondsdateOfSupplyUtc < secondsNow &&\n keepSellingAfterExpiration\n ) {\n label = intl.formatMessage(provider.expiredYes)\n color = 'red'\n } else if (\n secondsdateOfSupplyUtc > secondsNow &&\n secondsdateOfSupplyUtc - secondsNow < 259200000\n ) {\n const days = Math.ceil(\n (secondsdateOfSupplyUtc - secondsNow) / (1000 * 60 * 60 * 24)\n ).toString()\n\n let notice = ''\n\n if (days === '1') {\n notice =\n // eslint-disable-next-line @typescript-eslint/restrict-plus-operands\n intl.formatMessage(provider.expiring) +\n days +\n intl.formatMessage(provider.day)\n } else {\n notice =\n // eslint-disable-next-line @typescript-eslint/restrict-plus-operands\n intl.formatMessage(provider.expiring) +\n days +\n intl.formatMessage(provider.days)\n }\n\n label = notice\n color = '#ffd700'\n }\n\n return { color, label }\n }\n\n const schemaTable = {\n properties: {\n index: {\n title: intl.formatMessage(provider.index),\n width: 80,\n sortable: true,\n },\n date: {\n title: intl.formatMessage(provider.date),\n minWidth: 100,\n sortable: true,\n },\n total: {\n title: intl.formatMessage(provider.total),\n },\n reserved: {\n title: intl.formatMessage(provider.reserved),\n },\n available: {\n title: intl.formatMessage(provider.available),\n },\n keepSelling: {\n minWidth: 200,\n headerRenderer: () => {\n return (\n <>\n <p>{intl.formatMessage(provider.keep)}</p>\n <div className=\"ml2\">\n <Tooltip label={intl.formatMessage(provider.info)}>\n <span className=\"c-on-base pointer\">\n <IconInfo />\n </span>\n </Tooltip>\n </div>\n </>\n )\n },\n },\n color: {\n title: intl.formatMessage(provider.status),\n minWidth: 200,\n cellRenderer: ({ cellData }: any) => {\n return (\n <Tag color=\"#ffff\" bgColor={cellData?.color}>\n <span className=\"nowrap\"> {cellData?.label} </span>\n </Tag>\n )\n },\n },\n actions: {\n title: intl.formatMessage(provider.actions),\n cellRenderer: ({ cellData }: any) => {\n return (\n <>\n <Tooltip label={intl.formatMessage(provider.edit)}>\n <Button\n icon={true}\n variation=\"tertiary\"\n onClick={(e: SyntheticEvent) => {\n e.preventDefault()\n clickEdit(cellData?.index, cellData?.supplyLotId)\n }}\n >\n <IconEdit />\n </Button>\n </Tooltip>\n <Tooltip label={intl.formatMessage(provider.delete)}>\n <Button\n icon={true}\n variation=\"tertiary\"\n onClick={(e: SyntheticEvent) => {\n e.preventDefault()\n clickDelete(cellData.supplyLotId)\n }}\n >\n <IconDelete />\n </Button>\n </Tooltip>\n <Tooltip label={intl.formatMessage(provider.transfer)}>\n <Button\n icon={true}\n variation=\"tertiary\"\n onClick={(e: SyntheticEvent) => {\n e.preventDefault()\n clickTransfer(cellData.supplyLotId)\n }}\n >\n <a>\n <IconTransfer />\n </a>\n </Button>\n </Tooltip>\n </>\n )\n },\n },\n },\n }\n\n return (\n <WarehouseContext.Provider\n value={{\n warehouse,\n sku,\n newSupplyLot,\n orderedItems,\n schemaTable,\n modal,\n setModal,\n setDate,\n date,\n setKeep,\n keep,\n items,\n updateItems,\n modalDelete,\n setDelete,\n modalTransfer,\n setTransfer,\n addSupplyLot,\n editSupplyLot,\n deleteSupplyLots,\n transferSupplyLots,\n text,\n limit,\n sortedByValue,\n sortOrderValue,\n sort,\n setText,\n }}\n >\n {props.children}\n </WarehouseContext.Provider>\n )\n}\n\nexport default injectIntl(WarehouseProvider)\n\n```"
}
] |
code_supply-lots_4b60dfc6
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of supply-lots/react/components/ProductsTable/index.tsx from the supply-lots VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport type { ComponentType } from 'react'\nimport React, { useContext } from 'react'\nimport { PageBlock, PageHeader, Table } from 'vtex.styleguide'\nimport { useRuntime } from 'vtex.render-runtime'\nimport type { InjectedIntlProps, IntlShape } from 'react-intl'\nimport { injectIntl } from 'react-intl'\n\nimport WarehouseContext from '../Context/WarehouseContext'\nimport ModalAdd from '../Modal/add'\nimport ModalDelete from '../Modal/delete'\nimport ModalTransfer from '../Modal/transfer'\nimport { productTable } from '../../utils/definedMessages'\n\ninterface Props {\n intl: IntlShape\n}\nconst ProductsTable: ComponentType<Props & InjectedIntlProps> = ({ intl }) => {\n const provider = useContext(WarehouseContext)\n\n const { history } = useRuntime()\n\n if (provider.modal !== 0) return <ModalAdd></ModalAdd>\n if (provider.modalDelete) return <ModalDelete></ModalDelete>\n if (provider.modalTransfer) return <ModalTransfer></ModalTransfer>\n\n return (\n <>\n <PageBlock>\n <PageHeader\n title={intl.formatMessage(productTable.titleProdutctTable)}\n linkLabel={intl.formatMessage(productTable.link)}\n onLinkClick={() => {\n history.goBack()\n }}\n />\n <Table\n fullWidth\n toolbar={{\n newLine: {\n label: intl.formatMessage(productTable.toolbar),\n handleCallback: () => provider.newSupplyLot(),\n },\n }}\n totalizers={[\n {\n label: intl.formatMessage(productTable.totalizersSku),\n value: provider.sku.id,\n },\n {\n label: intl.formatMessage(productTable.totalizersProduct),\n value: provider.sku.name,\n },\n {\n label: intl.formatMessage(productTable.totalizersWarehouseId),\n value: provider.warehouse.id,\n },\n {\n label: intl.formatMessage(productTable.totalizersWarehouse),\n value: provider.warehouse.name,\n },\n ]}\n schema={provider.schemaTable}\n items={provider.orderedItems}\n sort={{\n sortedBy: provider.sortedByValue,\n sortOrder: provider.sortOrderValue,\n }}\n onSort={provider.sort}\n ></Table>\n </PageBlock>\n </>\n )\n}\n\nexport default injectIntl(ProductsTable)\n\n```"
}
] |
code_supply-lots_bc478e34
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of supply-lots/react/components/Modal/add.tsx from the supply-lots VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport type { ComponentType, SyntheticEvent } from 'react'\nimport React, { useContext } from 'react'\nimport type { InjectedIntlProps, IntlShape } from 'react-intl'\nimport { injectIntl } from 'react-intl'\nimport { Button, DatePicker, Dropdown, Input, Modal } from 'vtex.styleguide'\n\nimport {\n commonModal,\n modalAddTexts,\n optionModalAdd,\n} from '../../utils/definedMessages'\nimport WarehouseContext from '../Context/WarehouseContext'\nimport ModalLimit from './limit'\n\ninterface Props {\n intl: IntlShape\n}\n\nconst ModalAdd: ComponentType<Props & InjectedIntlProps> = ({ intl }) => {\n const provider = useContext(WarehouseContext)\n\n function closeModal() {\n provider.setModal(0)\n provider.setText('')\n }\n\n const options = [\n {\n value: true,\n label: intl.formatMessage(optionModalAdd.optionsTrue),\n },\n {\n value: false,\n label: intl.formatMessage(optionModalAdd.optionsFalse),\n },\n ]\n\n const currentDate = new Date()\n const minDate = currentDate.setDate(currentDate.getDate() + 1)\n\n if (provider.limit) return <ModalLimit></ModalLimit>\n\n return (\n <Modal\n centered\n isOpen={provider.modal}\n title={\n provider.modal === 1\n ? intl.formatMessage(modalAddTexts.titleAdd)\n : intl.formatMessage(modalAddTexts.titleEdit)\n }\n responsiveFullScreen\n bottomBar={\n <div>\n <span className=\"mr4\">\n <Button\n variation=\"tertiary\"\n onClick={(e: SyntheticEvent) => {\n e.preventDefault\n closeModal()\n }}\n >\n {intl.formatMessage(commonModal.cancel)}\n </Button>\n </span>\n <span>\n <Button\n variation=\"primary\"\n onClick={(e: SyntheticEvent) => {\n e.preventDefault\n if (provider.modal === 1) provider.addSupplyLot()\n else provider.editSupplyLot()\n }}\n >\n {intl.formatMessage(commonModal.save)}\n </Button>\n </span>\n </div>\n }\n onClose={(e: SyntheticEvent) => {\n e.preventDefault\n closeModal()\n }}\n >\n <div>\n <div className=\"w-90 mv6\">\n <DatePicker\n label={intl.formatMessage(modalAddTexts.date)}\n size=\"large\"\n value={provider.date ? provider.date : undefined}\n placeholder={intl.formatMessage(modalAddTexts.datePlaceholder)}\n onChange={(date: Date) => provider.setDate(date)}\n locale=\"pt-BR\"\n minDate={minDate}\n />\n </div>\n <div className=\"w-90 mv6\">\n <Input\n placeholder={intl.formatMessage(modalAddTexts.totalPlaceholder)}\n size=\"large\"\n label={intl.formatMessage(modalAddTexts.total)}\n type=\"number\"\n min=\"0\"\n onChange={(e: any) => {\n provider.updateItems(parseInt(e.target.value, 10))\n }}\n value={\n provider.items?.toString()\n ? provider.items?.toString()\n : undefined\n }\n />\n </div>\n <div className=\"w-90 mv6\">\n <Dropdown\n size=\"large\"\n label={intl.formatMessage(modalAddTexts.keep)}\n placeholder={intl.formatMessage(modalAddTexts.keepPlaceholder)}\n options={options}\n value={provider.keep !== undefined ? provider.keep : undefined}\n onChange={(_: any, v: string) => {\n provider.setKeep(v === 'true')\n }}\n />\n </div>\n <p className=\"mt2\" style={{ color: 'red', fontSize: '12px' }}>\n {provider.text}\n </p>\n </div>\n </Modal>\n )\n}\n\nexport default injectIntl(ModalAdd)\n\n```"
}
] |
code_supply-lots_d2e526e3
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of supply-lots/react/components/Modal/limit.tsx from the supply-lots VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport type { ComponentType, FC, SyntheticEvent } from 'react'\nimport React, { useContext } from 'react'\nimport type { InjectedIntlProps, IntlShape } from 'react-intl'\nimport { injectIntl } from 'react-intl'\nimport { Button, Modal } from 'vtex.styleguide'\n\nimport { commonModal, modalLimit } from '../../utils/definedMessages'\nimport WarehouseContext from '../Context/WarehouseContext'\n\ninterface Props {\n intl: IntlShape\n}\nconst ModalLimit: ComponentType<Props & InjectedIntlProps> = ({ intl }) => {\n const provider = useContext(WarehouseContext)\n\n function closeModal() {\n provider.setModal(0)\n }\n\n return (\n <Modal\n title={intl.formatMessage(modalLimit.limit)}\n centered\n isOpen={provider.modal}\n responsiveFullScreen\n bottomBar={\n <div className=\"nowrap\">\n <span className=\"mr4\">\n <Button\n variation=\"tertiary\"\n onClick={(e: SyntheticEvent) => {\n e.preventDefault\n closeModal()\n }}\n >\n {intl.formatMessage(commonModal.cancel)}\n </Button>\n </span>\n </div>\n }\n onClose={(e: SyntheticEvent) => {\n e.preventDefault\n closeModal()\n }}\n ></Modal>\n )\n}\n\nexport default injectIntl(ModalLimit)\n\n```"
}
] |
code_supply-lots_a9d48899
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of supply-lots/react/components/Modal/transfer.tsx from the supply-lots VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport type { ComponentType, FC, SyntheticEvent } from 'react'\nimport React, { useContext } from 'react'\nimport type { InjectedIntlProps, IntlShape } from 'react-intl'\nimport { injectIntl } from 'react-intl'\nimport { Button, Modal } from 'vtex.styleguide'\n\nimport IconTransferBig from '../../icons/IconsTransferBig'\nimport { commonModal, modalTransfer } from '../../utils/definedMessages'\nimport WarehouseContext from '../Context/WarehouseContext'\n\ninterface Props {\n intl: IntlShape\n}\nconst ModalTransfer: ComponentType<Props & InjectedIntlProps> = ({ intl }) => {\n const provider = useContext(WarehouseContext)\n\n function closeModal() {\n provider.setTransfer(false)\n }\n\n return (\n <Modal\n isOpen={provider.modalTransfer}\n responsiveFullScreen\n bottomBar={\n <div className=\"nowrap\">\n <span className=\"mr4\">\n <Button\n variation=\"tertiary\"\n onClick={(e: SyntheticEvent) => {\n e.preventDefault\n closeModal()\n }}\n >\n {intl.formatMessage(commonModal.cancel)}\n </Button>\n </span>\n <span>\n <Button\n variation=\"primary\"\n onClick={(e: SyntheticEvent) => {\n e.preventDefault\n provider.transferSupplyLots()\n }}\n >\n {intl.formatMessage(modalTransfer.transfer)}\n </Button>\n </span>\n </div>\n }\n onClose={(e: SyntheticEvent) => {\n e.preventDefault\n closeModal()\n }}\n >\n <div className=\"flex flex-column items-center justify-center t-heading-5\">\n <IconTransferBig />\n <div className=\"pv3 t-heading-4\">\n {intl.formatMessage(modalTransfer.transferText)}\n </div>\n\n <div className=\"pv3 t-body c-muted-2\">\n {intl.formatMessage(modalTransfer.transferQuestion)}{' '}\n </div>\n </div>\n </Modal>\n )\n}\n\nexport default injectIntl(ModalTransfer)\n\n```"
}
] |
code_supply-lots_ab10015f
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of supply-lots/react/components/Modal/delete.tsx from the supply-lots VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport type { ComponentType, SyntheticEvent } from 'react'\nimport React, { useContext } from 'react'\nimport type { IntlShape, InjectedIntlProps } from 'react-intl'\nimport { injectIntl } from 'react-intl'\nimport { Button, Modal } from 'vtex.styleguide'\n\nimport IconTrashCan from '../../icons/IconTrashCan'\nimport { commonModal, modalDelete } from '../../utils/definedMessages'\nimport WarehouseContext from '../Context/WarehouseContext'\n\ninterface Props {\n intl: IntlShape\n}\nconst ModalDelete: ComponentType<Props & InjectedIntlProps> = ({ intl }) => {\n const provider = useContext(WarehouseContext)\n\n function closeModal() {\n provider.setDelete(false)\n }\n\n return (\n <Modal\n isOpen={provider.modalDelete}\n bottomBar={\n <div className=\"nowrap\">\n <span className=\"mr4\">\n <Button\n variation=\"tertiary\"\n onClick={(e: SyntheticEvent) => {\n e.preventDefault\n closeModal()\n }}\n >\n {intl.formatMessage(commonModal.cancel)}\n </Button>\n </span>\n <span>\n <Button\n variation=\"primary\"\n onClick={(e: SyntheticEvent) => {\n e.preventDefault\n provider.deleteSupplyLots()\n }}\n >\n {intl.formatMessage(commonModal.delete)}\n </Button>\n </span>\n </div>\n }\n onClose={(e: SyntheticEvent) => {\n e.preventDefault\n closeModal()\n }}\n >\n <div className=\"flex flex-column items-center justify-center t-heading-5\">\n <IconTrashCan />\n <div className=\"pv3 t-heading-4\">\n {intl.formatMessage(modalDelete.deleteText)}\n </div>\n\n <div className=\"pv3 t-body c-muted-2\">\n {intl.formatMessage(modalDelete.deleteQuestion)}\n </div>\n <div className=\"pv3 t-body c-muted-2\">\n {intl.formatMessage(modalDelete.deleteReason)}\n </div>\n </div>\n </Modal>\n )\n}\n\nexport default injectIntl(ModalDelete)\n\n```"
}
] |
code_broadcaster_ab117d5e
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of broadcaster/docs/README.md from the broadcaster VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```markdown\n# Broadcaster\n\nThe Broadcaster app is designed to adapt catalog broadcaster changes to an event in VTEX IO's Events system.\n\nTypically, it's used when developing another IO app that receives the events and calls handler functions to treat the events. For more details about this use, see the [Receiving Catalog Changes on VTEX IO](https://developers.vtex.com/docs/guides/how-to-receive-catalog-changes-on-vtex-io) guide.\n\nFor example, the [Availability Notify](https://developers.vtex.com/vtex-developer-docs/docs/vtex-availability-notify) app uses the Broadcaster app to monitor inventory updates. Once the requested SKU is back in stock, the app will email shoppers who asked to be notified.\n\n```mermaid\nflowchart LR\na1(\"Catalog changes\\n(Catalog broadcaster)\\n\\n\")\na2(\"Broadcaster app\")\nb1(\"Event system\")\nb2(\"Changes broadcast\\nto other apps\\n(e.g.: Availability Notify)\\n\\n\")\n\na1 -- \\nSKU that\\nchanged\\n\\n\\n --> a2 --> b1 --> b2\n```\n\nThe Broadcaster app receives a POST request from the catalog broadcaster with the details of the SKU that changed and pushes an event to the Event system to broadcast to apps that listen to these changes.\n\n> ⚠️ The Broadcaster app receives catalog changes from the same account where the app is installed and not from sellers.\n\n## SKU information\n\nWhen the Broadcaster app sends an event, it contains a payload with the following fields:\n\n| Field name | Description | Type |\n| - | - | - |\n| `IdSku` | SKU ID on VTEX. | string |\n| `ProductId` | Product ID on VTEX. This field is optional and is only sent in marketplace contexts when an event occurs in the affiliate catalog. | long |\n| `An` | Account name on VTEX, shown in the store’s VTEX Admin URL. | string |\n| `IdAffiliate` | ID code of the affiliate that generated the event. This field is optional and is only sent in marketplace contexts when an event occurs in the affiliate catalog. | string |\n| `SellerChain` | Sellers involved in the chain. This field is optional and is only sent in marketplace contexts with [Multilevel Omnichannel Inventory](https://help.vtex.com/en/tutorial/multilevel-omnichannel-inventory--7M1xyCZWUyCB7PcjNtOyw4) when an event occurs in the affiliate catalog. When there is more than one seller in the chain, they're all included in this field separated by a forward slash (`/`). Example: `\"cea/rihappy\"`. | string |\n| `DateModified` | Date when the item was updated. | string |\n| `IsActive` | Identifies whether the product is active or not. If `true`, the product/SKU is active. | boolean |\n| `StockModified` | Indicates that the inventory level has changed. If `false`, the inventory level hasn't changed. | boolean |\n| `PriceModified` | Indicates that the price has changed. If `false`, the product/SKU price hasn't changed. | boolean |\n| `HasStockKeepingUnitModified` | Indicates that the product/SKU details have changed, such as name, description, weight, etc. If `true`, the product/SKU details have changed. | boolean |\n| `HasStockKeepingUnitRemovedFromAffiliate` | Indicates that the product is no longer associated with the trade policy. If `true`, the trade policy has changed. | boolean |\n\n## Notifications in subaccounts\n\nWhen attempting to listen for catalog change notifications in a [subaccount](https://help.vtex.com/en/tutorial/creating-subaccount-multi-store-multi-domain--tutorials_510), you'll likely find that your app isn't receiving notifications. This is because, by default, catalog change notifications are only sent to the Broadcaster app installed in the main account.\n\n### \"Notify Subaccounts\" setting\n\nThe Broadcaster app installed in the main (parent) account can be configured to push a notification event to all associated subaccounts.\n\nTo configure this setting, follow the steps below:\n\n1. Go to **My Apps** in the VTEX Admin.\n2. In the list of installed apps, search for **Broadcaster**.\n3. Click `Settings` in the app box.\n4. Check the `Notify Subaccounts` box.\n5. Click `Save`.\n\n## Testing the app\n\nBy default, when the Broadcaster Adapter app sends events, they're only sent in the master workspace of each account. If you work in a **[development workspace](https://developers.vtex.com/vtex-developer-docs/docs/vtex-io-documentation-workspace)**, there's a way to receive events there:\n\n### \"Notify Target Workspace\" setting\n\nThe app installed in the master workspace can be configured to push a notification event to a selected target workspace in addition to the master workspace.\n\nTo configure this setting, follow the steps below:\n\n1. Go to **My Apps** in the VTEX Admin.\n2. In the list of installed apps, search for **Broadcaster**.\n3. Click `Settings`.\n4. Enter the name of the workspace you want to notify in the **Notify Target Workspace** field.\n5. Click `Save`.\n\n```"
}
] |
code_broadcaster_87d418a4
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of broadcaster/node/service.json from the broadcaster VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"memory\": 256,\n \"ttl\": 10,\n \"timeout\": 2,\n \"minReplicas\": 2,\n \"maxReplicas\": 10,\n \"workers\": 4,\n \"routes\": {\n \"notify\": {\n \"path\": \"/notify\",\n \"public\": false\n },\n \"notifySelf\": {\n \"path\": \"/_v/self/notify\",\n \"public\": false,\n \"policies\": [\n {\n \"effect\": \"allow\",\n \"actions\": [\"post\"],\n \"principals\": [\"vrn:apps:*:*:*:app/vtex.broadcaster@*\"]\n }\n ]\n }\n }\n}\n\n```"
}
] |
code_broadcaster_abf047b0
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of broadcaster/node/package.json from the broadcaster VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"dependencies\": {\n \"co-body\": \"^6.0.0\"\n },\n \"devDependencies\": {\n \"@types/co-body\": \"^0.0.3\",\n \"@types/node\": \"12.x\",\n \"@vtex/api\": \"6.45.12\",\n \"vtex.broadcaster\": \"http://vtex.vtexassets.com/_v/public/typings/v1/vtex.broadcaster@0.7.8/public/_types/react\"\n },\n \"scripts\": {\n \"lint\": \"tsc --noEmit --pretty && eslint -c .eslintrc.json --fix './**/*.ts'\"\n },\n \"version\": \"0.10.2\"\n}\n\n```"
}
] |
code_broadcaster_fc435d40
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of broadcaster/node/typings.ts from the broadcaster VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport type { RecorderState, ServiceContext } from '@vtex/api'\n\nimport { Clients } from './clients'\n\ndeclare global {\n type Context = ServiceContext<Clients, State>\n\n interface State extends RecorderState, BroadcasterEvent {\n payload: BroadcasterEvent\n }\n\n interface BroadcasterEvent {\n HasStockKeepingUnitModified: boolean\n IdSku: string\n }\n\n type ID = string\n type Float = number\n type Int = number\n}\n\n```"
}
] |
code_broadcaster_d0c221a3
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of broadcaster/node/constants.ts from the broadcaster VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nexport const ENABLED_GLOBALLY = true\n\nexport const BROADCASTER_NOTIFICATION = 'broadcaster.notification'\n\n```"
}
] |
code_broadcaster_0ae301f7
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of broadcaster/node/index.ts from the broadcaster VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport type { ClientsConfig, ParamsContext } from '@vtex/api'\nimport { Service, method } from '@vtex/api'\n\nimport { Clients } from './clients'\nimport { parseAndValidate } from './middlewares/parse'\nimport { throttle } from './middlewares/throttle'\nimport { pushNotification } from './middlewares/pushNotification'\nimport { notifyTargetWorkspace } from './middlewares/notifyTargetWorkspace'\nimport { notifyAllSubaccounts } from './middlewares/notifyAllSubaccounts'\n\nconst TREE_SECONDS_MS = 3 * 1000\nconst CONCURRENCY = 10\n\nconst clients: ClientsConfig<Clients> = {\n implementation: Clients,\n options: {\n events: {\n exponentialTimeoutCoefficient: 2,\n exponentialBackoffCoefficient: 2,\n initialBackoffDelay: 50,\n retries: 1,\n timeout: TREE_SECONDS_MS,\n concurrency: CONCURRENCY,\n },\n },\n}\n\nexport default new Service<Clients, State, ParamsContext>({\n clients,\n routes: {\n // notifications from catalog\n notify: method({\n POST: [\n throttle,\n parseAndValidate,\n pushNotification,\n notifyAllSubaccounts,\n notifyTargetWorkspace,\n ],\n }),\n // notifications from other vtex.broadcaster instances\n notifySelf: method({\n POST: [\n throttle,\n parseAndValidate,\n pushNotification,\n notifyAllSubaccounts,\n notifyTargetWorkspace,\n ],\n }),\n },\n})\n\n```"
}
] |
code_broadcaster_4508de2c
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of broadcaster/node/clients/broadcaster.ts from the broadcaster VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { AppClient, InstanceOptions, IOContext } from '@vtex/api'\n\nexport class BroadcasterClient extends AppClient {\n constructor(ioContext: IOContext, options?: InstanceOptions) {\n super('vtex.broadcaster@0.x', ioContext, {\n ...options,\n headers: {\n VtexIdclientAutCookie: ioContext.authToken,\n ...options?.headers,\n },\n })\n }\n\n public notify(payload: BroadcasterEvent): Promise<any> {\n return this.http.post(`/_v/self/notify`, payload, {\n headers: {\n ...this.options?.headers,\n },\n })\n }\n}\n\n```"
}
] |
code_broadcaster_b783e4f8
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of broadcaster/node/clients/index.ts from the broadcaster VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { IOClients } from '@vtex/api'\n\nimport { BroadcasterClient } from './broadcaster'\n\nexport class Clients extends IOClients {\n public get broadcaster() {\n return this.getOrSet('broadcaster', BroadcasterClient)\n }\n}\n\n```"
}
] |
code_broadcaster_48eb50c2
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of broadcaster/node/middlewares/pushNotification.ts from the broadcaster VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { BROADCASTER_NOTIFICATION } from '../constants'\n\nexport async function pushNotification(ctx: Context, next: () => Promise<any>) {\n const {\n clients: { events },\n } = ctx\n\n await events.sendEvent('', BROADCASTER_NOTIFICATION, ctx.state.payload)\n ctx.status = 200\n\n next()\n}\n\n```"
}
] |
code_broadcaster_6d8b59fa
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of broadcaster/node/middlewares/throttle.ts from the broadcaster VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { TooManyRequestsError } from '@vtex/api'\n\nconst MAX_REQUEST = 50\nlet COUNTER = 0\n\nexport async function throttle(ctx: Context, next: () => Promise<void>) {\n const {\n vtex: { platform },\n } = ctx\n\n if (platform !== 'vtex') {\n return\n }\n\n COUNTER++\n try {\n if (COUNTER > MAX_REQUEST) {\n throw new TooManyRequestsError()\n }\n await next()\n } finally {\n COUNTER--\n }\n}\n\n```"
}
] |
code_broadcaster_67d7d0c1
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of broadcaster/node/middlewares/parse.ts from the broadcaster VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { json } from 'co-body'\n\nimport { ENABLED_GLOBALLY } from '../constants'\n\nexport async function parseAndValidate(ctx: Context, next: () => Promise<any>) { \n if (!ENABLED_GLOBALLY) {\n ctx.body = 'Service not enabled.'\n ctx.status = 200\n return\n }\n\n const body = (await json(ctx.req)) as BroadcasterEvent\n\n ctx.state.payload = body\n\n await next()\n}\n\n```"
}
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.