id
stringlengths 12
53
| messages
listlengths 3
3
|
|---|---|
code_Indexer-listener_11946bf9
|
[
{
"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 Indexer-listener/node/utils.ts from the Indexer-listener VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\n\n\n \nexport const toSkuProvider = (id: string) => `SKU-id.${id}`\nexport const toProductProvider = (id: string) => `Product-id.${id}`\nexport const toBrandProvider = (id: string) => `Brand-id.${id}`\nexport const toCategoryProvider = (id: string) => `Category-id.${id}`\nexport const providerToVbaseFilename = (provider: string) => `${provider}.json`\n\nexport interface Storage{\nhash: string\n}\n \n```"
}
] |
code_Indexer-listener_d5be3f87
|
[
{
"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 Indexer-listener/node/package.json from the Indexer-listener VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"dependencies\": {\n \"@gocommerce/utils\": \"^0.6.11\",\n \"co-body\": \"^6.0.0\",\n \"ramda\": \"^0.25.0\"\n },\n \"devDependencies\": {\n \"@types/co-body\": \"^0.0.3\",\n \"@types/node\": \"8.x\",\n \"@types/ramda\": \"types/npm-ramda#dist\",\n \"@vtex/api\": \"3.8.1\",\n \"tslint\": \"^5.14.0\",\n \"tslint-config-vtex\": \"^2.1.0\",\n \"typescript\": \"3.5.2\"\n },\n \"scripts\": {\n \"lint\": \"tsc --noEmit --pretty && tslint -c tslint.json --fix './**/*.ts'\"\n }\n}\n\n```"
}
] |
code_Indexer-listener_50d32a83
|
[
{
"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 Indexer-listener/node/index.ts from the Indexer-listener VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { ClientsConfig, LRUCache, Service, ServiceContext } from '@vtex/api'\nimport { Clients } from './clients'\nimport { Settings } from './directives/settings'\nimport { processModification } from './middlewares/methods'\nimport { injectAndCheckAppSettings } from './middlewares/settings'\nimport { injectAppSettingsCrossAccount } from './middlewares/settings'\n\n\nconst TIMEOUT_MS = 800\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})\nmetrics.trackCache('status', memoryCache)\n\n// This is the configuration for clients available in `ctx.clients`.\nconst clients: ClientsConfig<Clients> = {\n // We pass our custom implementation of the clients bag, containing the Status client.\n implementation: Clients,\n options: {\n // All IO Clients will be initialized with these options, unless otherwise specified.\n default: {\n retries: 2,\n timeout: TIMEOUT_MS,\n },\n // This key will be merged with the default options and add this cache to our Status client.\n status: {\n memoryCache,\n },\n vbase: {\n memoryCache,\n },\n },\n}\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, State>\n\n\n // The shape of our State object found in `ctx.state`. This is used as state bag to communicate between middlewares.\n interface State {\n code: number,\n modifDescription: any,\n settings: Settings,\n }\n\n}\n\n// Export a service that defines route handlers and client options.\nexport default new Service<Clients, State>({\n clients,\n routes: {\n // `status` is the route ID from service.json. It maps to an array of middlewares (or a single handler).\n settings:[\n injectAppSettingsCrossAccount,\n ],\n status: [\n injectAndCheckAppSettings,\n processModification, \n ],\n },\n})\n\n```"
}
] |
code_Indexer-listener_75cf78f2
|
[
{
"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 Indexer-listener/node/directives/settings.ts from the Indexer-listener VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\n\n\nexport interface Settings {\n enabled: boolean\n}\n\nexport const DEFAULT_SETTINGS: Settings = {\n enabled: true,\n}\n\nexport const settings = async (appSettings: any): Promise<Settings> => {\n const {\n enabled,\n }: {\n enabled: boolean\n } = {\n ...DEFAULT_SETTINGS,\n ...appSettings,\n }\n\n return {\n enabled,\n }\n }\n```"
}
] |
code_Indexer-listener_0185b388
|
[
{
"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 Indexer-listener/node/clients/status.ts from the Indexer-listener VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { ExternalClient, InstanceOptions, IOContext, IOResponse } from '@vtex/api'\n\nexport default class Status extends ExternalClient {\n constructor(context: IOContext, options?: InstanceOptions) {\n super('http://httpstat.us', context, options)\n }\n\n public async getStatus (status: number): Promise<string> {\n return this.http.get(status.toString(), {\n metric: 'status-get',\n })\n }\n\n public async getStatusWithHeaders (status: number): Promise<IOResponse<string>> {\n return this.http.getRaw(status.toString(), {\n metric: 'status-get-raw',\n })\n }\n}\n\n```"
}
] |
code_Indexer-listener_eb926c01
|
[
{
"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 Indexer-listener/node/clients/index.ts from the Indexer-listener VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { IOClients } from '@vtex/api'\nimport { Catalog } from './catalog'\nimport { Itself } from './itself'\n\n\n\nimport Status from './status'\n\n// Extend the default IOClients implementation with our own custom clients.\nexport class Clients extends IOClients {\n public get status() {\n return this.getOrSet('status', Status)\n }\n public get catalog() {\n return this.getOrSet('catalog', Catalog)\n }\n public get itself() {\n return this.getOrSet('itself', Itself)\n }\n}\n\n```"
}
] |
code_Indexer-listener_312e8aa8
|
[
{
"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 Indexer-listener/node/clients/itself.ts from the Indexer-listener VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { AppClient, InstanceOptions, IOContext } from '@vtex/api'\n\nexport class Itself extends AppClient {\n constructor(ctx: IOContext, opts?: InstanceOptions) {\n super('vtex.broadcaster-listener', { ...ctx, account: 'storecomponents', workspace: 'araripe2' }, opts)\n }\n\n public getAppSettingsCrossAccount = async (): Promise<any> => {\n console.log('Called client Itself.')\n const appSettings = await this.http.get<any>('/settings')\n \n return appSettings\n }\n\n \n}\n\n```"
}
] |
code_Indexer-listener_f163612a
|
[
{
"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 Indexer-listener/node/clients/catalog.ts from the Indexer-listener VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { AppClient, InstanceOptions, IOContext } from '@vtex/api'\nimport { isArray } from 'util' \n\nexport class Catalog extends AppClient {\n public constructor(ctx: IOContext, opts?: InstanceOptions) {\n super('vtex.catalog-api-proxy', ctx, opts)\n \n }\n\n public getSku = async (id: string, platform: string): Promise<any> => {\n const isGocommerce = platform === 'gocommerce'\n const path = isGocommerce\n ? `/proxy/catalog/pvt/sku/stockkeepingunitbyid/${id}` \n : `/proxy/catalog/pvt/sku/stockkeepingunitbyid/${id}`\n const data = await this.http.get<any | [any]>(path, { metric: 'catalog-sales-channel'})\n return isArray(data) ? data[0] : data\n }\n public getProduct = async (id: string, platform: string): Promise<any> => {\n const isGocommerce = platform === 'gocommerce'\n const path = isGocommerce\n ? `/proxy/catalog/pvt/products/ProductGet/${id}` \n : `/proxy/catalog/pvt/products/ProductGet/${id}`\n const data = await this.http.get<any | [any]>(path, { metric: 'catalog-sales-channel'})\n return isArray(data) ? data[0] : data\n }\n public getCategory = async (id: string, platform: string): Promise<any> => {\n const isGocommerce = platform === 'gocommerce'\n const path = isGocommerce\n ? `/proxy/catalog/pvt/category/${id}` \n : `/proxy/catalog/pvt/category/${id}`\n const data = await this.http.get<any | [any]>(path, { metric: 'catalog-sales-channel'})\n return isArray(data) ? data[0] : data\n }\n public getBrand = async (id: string, platform: string): Promise<any> => {\n const isGocommerce = platform === 'gocommerce'\n const path = isGocommerce\n ? `/proxy/catalog/pvt/brand/${id}` \n : `/proxy/catalog/pvt/brand/${id}`\n const data = await this.http.get<any | [any]>(path, { metric: 'catalog-sales-channel'})\n return isArray(data) ? data[0] : data\n }\n\n}\n```"
}
] |
code_Indexer-listener_e5618173
|
[
{
"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 Indexer-listener/node/middlewares/status.ts from the Indexer-listener VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nexport const status = async (ctx: Context, next: () => Promise<any>) => {\n const {state: {code}, clients: {status: statusClient}} = ctx\n console.log('Received code:', code)\n\n const statusResponse = await statusClient.getStatus(code)\n console.log('Status response:', statusResponse)\n\n const {headers, data, status: responseStatus} = await statusClient.getStatusWithHeaders(code)\n console.log('Status headers', headers)\n console.log('Status data:', data)\n\n ctx.status = responseStatus\n ctx.body = data\n ctx.set('Cache-Control', headers['cache-control'])\n\n await next()\n}\n\n```"
}
] |
code_Indexer-listener_3547bfdc
|
[
{
"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 Indexer-listener/node/middlewares/settings.ts from the Indexer-listener VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\n\n// import inflight from 'promise-inflight'\n\nimport {json} from 'co-body'\nimport {settings} from '../directives/settings'\n\n\nexport const injectAndCheckAppSettings = async (ctx: Context, next: () => Promise<any>) => {\n\n console.log('Service started!!!!!')\n\n const appSettings = await ctx.clients.apps.getAppSettings(''+process.env.VTEX_APP_ID)\n const appSettingsResolved = await settings(appSettings)\n const enabled = appSettingsResolved.enabled \n\n if (!enabled){\n console.log('Service not enabled.')\n ctx.status = 401\n ctx.body = 'Service not enabled.'\n return \n }\n\n const body = await json(ctx.req)\n\n // Temporary if, in the near future broadcaster will only notify us modifications in SKUs or product.\n if (!body.HasStockKeepingUnitModified){\n console.log('False alarm.')\n ctx.status = 204\n return\n }\n ctx.state.modifDescription = body\n await next()\n\n\n}\n\nexport const injectAppSettingsCrossAccount = async (ctx: Context, next: () => Promise<any>)=>{\n console.log('Called route settings.')\n const appSettings = await ctx.clients.apps.getAppSettings(''+process.env.VTEX_APP_ID)\n const appSettingsResolved = await settings(appSettings)\n // const appSettingsResolved = {enabled: true}\n ctx.body = appSettingsResolved\n await next()\n}\n\n\n\n\n\n\n```"
}
] |
code_Indexer-listener_fcace6dd
|
[
{
"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 Indexer-listener/node/middlewares/validate.ts from the Indexer-listener VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { UserInputError } from '@vtex/api'\n\nexport const validate = async (ctx: Context, next: () => Promise<any>) => {\n const {vtex: {route: {params, params: {code}}}} = ctx\n\n console.log('Received params:', params)\n\n if (!code) {\n throw new UserInputError('Code is required')\n }\n\n const codeNumber = parseInt(code as string, 10)\n\n if (isNaN(codeNumber) || codeNumber < 100 || codeNumber > 600) {\n throw new UserInputError('Code must be a number')\n }\n\n ctx.state.code = codeNumber\n\n await next()\n}\n\n```"
}
] |
code_Indexer-listener_83ef8eea
|
[
{
"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 Indexer-listener/node/middlewares/methods.ts from the Indexer-listener VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { Functions } from '@gocommerce/utils'\nimport * as crypto from 'crypto'\nimport { filter, keys, pick} from 'ramda'\nimport { USER_BUCKET } from '../constants'\nimport { providerToVbaseFilename, Storage, toBrandProvider, toCategoryProvider, toProductProvider,toSkuProvider } from '../utils'\n\n\nconst propertiesNotProductInProduct = new Set(['DepartmentId','CategoryId','BrandId'])\nconst propertiesProductInSku = new Set(['ProductName','ProductDescription','ProductRefId']) // For now, ProductSpecifications is a SKU property, it will soon be a Specification prop.\nconst propertiesBrandInSku = new Set(['BrandName'])\nconst propertiesCategoryInSku = new Set(['ProductCategories'])\nconst propertiesIdInSku = new Set(['ProductId','ProductRefId','BrandId','ProductCategoryIds','ProductClustersIds'])\nconst propertiesNotSkuInSku = new Set([\n ...propertiesProductInSku,\n ...propertiesBrandInSku,\n ...propertiesCategoryInSku,\n ...propertiesIdInSku,\n])\n\nexport const processModification = async (ctx: Context, next:()=> Promise<any>) => {\n\n console.log('ProcessModification')\n const catalog = ctx.clients.catalog\n const idSku = ctx.state.modifDescription.IdSku\n const platform = getPlatform(ctx)\n\n const dataSku = await catalog.getSku(idSku,platform)\n console.log({dataSku})\n\n\n // Modification in SKU\n const filenameSku = providerToVbaseFilename(toSkuProvider(idSku))\n await evalModification(propertiesNotSkuInSku,'sku',dataSku, filenameSku, ctx)\n \n\n // Modification in Product\n const idProduct = dataSku.ProductId\n const filenameProduct = providerToVbaseFilename(toProductProvider(idProduct))\n const dataProduct = await ctx.clients.catalog.getProduct(idProduct,platform)\n await evalModification(propertiesNotProductInProduct,'product',dataProduct, filenameProduct, ctx)\n\n // Modification in Brand\n const idBrand = dataSku.BrandId\n const filenameBrand = providerToVbaseFilename(toBrandProvider(idBrand))\n const dataBrand = await ctx.clients.catalog.getBrand(idBrand,platform)\n await evalModification(null,'brand',dataBrand, filenameBrand, ctx)\n\n // Modification in Category\n const idsCategoryStr = dataSku.ProductCategoryIds\n const idsCategory = idsCategoryStr.substring(1,idsCategoryStr.length - 1).split('/')\n let filenameCategory\n let dataCategory\n for (const id of idsCategory){\n filenameCategory = providerToVbaseFilename(toCategoryProvider(id))\n dataCategory = await ctx.clients.catalog.getCategory(id,platform)\n await evalModification(null,'category',dataCategory, filenameCategory, ctx)\n }\n \n \n \n\n ctx.status = 200\n await next()\n}\n\nconst evalModification = async (excludedProps:Set<string>|null,route:string, data:any, fileName: string, ctx: Context)=>{\n console.log(`Data in ${route}`,{data})\n let dataObjInObj = null\n if (excludedProps !== null){\n const propertiesObjInObj = filter(\n (key) => \n !excludedProps.has(key),\n keys(data)\n )\n dataObjInObj = pick(propertiesObjInObj, data)\n }\n \n const hashNew = crypto.createHash('md5').update(JSON.stringify( dataObjInObj || data,null,2)).digest('hex')\n const jsonNew:Storage = {hash:hashNew}\n const jsonOld = await ctx.clients.vbase.getJSON<Storage | null>(USER_BUCKET,fileName,true)\n console.log(`Old json ${fileName}`,JSON.stringify(jsonOld,null,2)) \n\n // if ((jsonOld === null) || (hashNew !== jsonOld.hash)){\n // console.log(`Json modified. New json ${fileName}:`,JSON.stringify(jsonNew.hash,null,2))\n // ctx.clients.vbase.saveJSON(USER_BUCKET, fileName,jsonNew)\n const response = await ctx.clients.events.sendEvent('',`broadcaster.${route}`,data)\n console.log(`Colossus response to : ${process.env.VTEX_APP_ID!}`, {response})\n // return true\n // }\n return false\n}\n\n\nconst getPlatform = (ctx: Context) => {\n return Functions.isGoCommerceAcc(ctx) ? 'gocommerce' : 'vtex'\n }\n\n\n```"
}
] |
code_lucky-orange_7734cdbd
|
[
{
"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 lucky-orange/docs/README.md from the lucky-orange VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```markdown\n# Lucky Orange\n\nLucky Orange first-party app.\n\n## How to install\n\nOpen the VTEX App Store and install this app on your store.\n\nNow, open the app settings on your admin and fill your Lucky Orange`s Site ID.\n\n```"
}
] |
code_KI-739693_546d35af
|
[
{
"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 KI-739693/docs/README.md from the KI-739693 VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```markdown\n# Kit Indexer\n\nApp in VTEX that receives a notification when a SKU is changed, if the SKU changed is a KIT, the SKU is updated with the correct weight which is the sum of the weights of its components.\n\n## How it works?\n\n\n\n## How to install\n\n⚠️ First, make sure the broadcaster app is installed.\n\n\nRun command: `vtex install vtex.ki-739693`\n\n```"
}
] |
code_KI-739693_cb910564
|
[
{
"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 KI-739693/node/service.json from the KI-739693 VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"memory\": 128,\n \"ttl\": 10,\n \"timeout\": 2,\n \"minReplicas\": 2,\n \"maxReplicas\": 10,\n \"workers\": 4,\n \"events\": {\n \"skuChange\": {\n \"keys\": [\"broadcaster.notification\"]\n }\n }\n}\n\n```"
}
] |
code_KI-739693_6fde1bf6
|
[
{
"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 KI-739693/node/package.json from the KI-739693 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.15\",\n \"@vtex/tsconfig\": \"^0.5.6\",\n \"typescript\": \"3.9.7\"\n },\n \"scripts\": {\n \"lint\": \"tsc --noEmit --pretty && eslint -c .eslintrc.json --fix './**/*.ts'\"\n },\n \"version\": \"0.7.2\"\n}\n\n```"
}
] |
code_KI-739693_b4f5d737
|
[
{
"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 KI-739693/node/index.ts from the KI-739693 VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport type {\n ParamsContext,\n ServiceContext,\n RecorderState,\n ClientsConfig,\n} from '@vtex/api'\nimport { Service } from '@vtex/api'\n\nimport { skuChange } from './events/skuChange'\nimport { Clients } from './clients'\n\nconst TIMEOUT_MS = 10000\nconst CONCURRENCY = 10\n\ndeclare global {\n type Context = ServiceContext<Clients, State>\n\n interface State extends RecorderState {\n code: number\n }\n}\n\nconst clients: ClientsConfig<Clients> = {\n // We pass our custom implementation of the clients bag, containing the Status client.\n implementation: Clients,\n options: {\n // All IO Clients will be initialized with these options, unless otherwise specified.\n default: {\n retries: 2,\n timeout: TIMEOUT_MS,\n },\n events: {\n exponentialTimeoutCoefficient: 2,\n exponentialBackoffCoefficient: 2,\n initialBackoffDelay: 50,\n retries: 1,\n timeout: TIMEOUT_MS,\n concurrency: CONCURRENCY,\n },\n },\n}\n\nexport default new Service<Clients, State, ParamsContext>({\n clients,\n events: {\n skuChange,\n },\n})\n\n```"
}
] |
code_KI-739693_df69ee9b
|
[
{
"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 KI-739693/node/clients/pricing.ts from the KI-739693 VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport type { InstanceOptions, IOContext } from '@vtex/api'\nimport { ExternalClient } from '@vtex/api'\n\ninterface UpdateBody {\n itemId: string\n listPrice: number\n costPrice: number\n markup: number | null\n basePrice: number\n fixedPrices: FixedPrice[]\n}\n\ninterface FixedPrice {\n tradePolicyId: string\n value: number\n listPrice: number\n minQuantity: number\n dateRange: DateInput\n}\n\ninterface DateInput {\n from: string\n to: string\n}\n\nexport default class Pricing extends ExternalClient {\n constructor(context: IOContext, options?: InstanceOptions) {\n super(`https://api.vtex.com/${context.account}`, context, {\n ...options,\n headers: {\n ...options?.headers,\n VtexIdclientAutCookie:\n context.adminUserAuthToken ?? context.authToken ?? '',\n 'X-Vtex-Use-Https': 'true',\n },\n })\n }\n\n public async getPrice(sku: string) {\n return this.http.get(`/pricing/prices/${sku}`, {\n metric: 'get-prices-by-sku-id',\n })\n }\n\n public async updatePrice(sku: string, data: UpdateBody) {\n return this.http.put(`/pricing/prices/${sku}`, data, {\n metric: 'get-prices-by-sku-id',\n })\n }\n}\n\n```"
}
] |
code_KI-739693_f80c8491
|
[
{
"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 KI-739693/node/clients/index.ts from the KI-739693 VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { IOClients } from '@vtex/api'\n\nimport Catalog from './catalog'\nimport Pricing from './pricing'\n\n// Extend the default IOClients implementation with our own custom clients.\nexport class Clients extends IOClients {\n public get catalog() {\n return this.getOrSet('catalog', Catalog)\n }\n\n public get pricing() {\n return this.getOrSet('pricing', Pricing)\n }\n}\n\n```"
}
] |
code_KI-739693_a6c482e2
|
[
{
"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 KI-739693/node/clients/catalog.ts from the KI-739693 VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport type { InstanceOptions, IOContext } from '@vtex/api'\nimport { ExternalClient } from '@vtex/api'\n\nexport default class Catalog extends ExternalClient {\n constructor(context: IOContext, options?: InstanceOptions) {\n super(`http://${context.account}.myvtex.com/api`, context, {\n ...options,\n headers: {\n ...options?.headers,\n VtexIdclientAutCookie:\n context.adminUserAuthToken ?? context.authToken ?? '',\n 'X-Vtex-Use-Https': 'true',\n },\n })\n }\n\n public async getProduct(sku: string) {\n return this.http.get(\n `/catalog_system/pvt/sku/stockkeepingunitbyid/${sku}`,\n {\n metric: 'get-product-by-sku-id',\n }\n )\n }\n}\n\n```"
}
] |
code_KI-739693_7ef0bc2b
|
[
{
"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 KI-739693/node/events/skuChange.ts from the KI-739693 VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport type { EventContext } from '@vtex/api'\nimport { LogLevel, NotFoundError, ResolverError } from '@vtex/api'\n\nimport type { Clients } from '../clients'\n\ninterface Item {\n Id: number\n Name: string\n UnitPrice: number\n Amount: number\n EstimatedDateArrival: string\n Dimension: Dimension\n RefId: string\n EAN: string\n IsKitOptimized: boolean\n}\n\ninterface Dimension {\n cubicweight: number\n height: number\n length: number\n weight: number\n width: number\n}\n\nexport async function skuChange(ctx: EventContext<Clients>) {\n const {\n clients: { catalog: catalogClient, pricing: pricingClient },\n } = ctx\n\n const { IdSku, HasStockKeepingUnitModified } = ctx.body\n\n if (!HasStockKeepingUnitModified) return\n\n let product\n let totalPrice = 0\n\n try {\n // Add individual prices\n product = await catalogClient.getProduct(IdSku)\n\n if (product.IsKit) {\n const { KitItems } = product\n\n totalPrice = 0\n\n KitItems.forEach((element: Item) => {\n totalPrice += element.UnitPrice * element.Amount\n })\n }\n } catch (error) {\n const erroMessage = `SKU ${IdSku} not found.`\n const splunkError = {\n error: erroMessage,\n detail: error,\n }\n\n ctx.vtex.logger.log(splunkError, LogLevel.Error)\n throw new NotFoundError(erroMessage)\n }\n\n if (product?.IsKit) {\n try {\n // Get price\n const price = await pricingClient.getPrice(IdSku)\n\n // Update price with new calculated price\n await pricingClient.updatePrice(IdSku, {\n ...price,\n listPrice: totalPrice,\n costPrice: totalPrice,\n basePrice: totalPrice,\n fixedPrices: [\n {\n ...price.fixedPrices[0],\n value: totalPrice,\n listPrice: totalPrice,\n },\n ],\n })\n } catch (error) {\n const erroMessage = `SKU ${IdSku} cannot be updated.`\n const splunkError = {\n error: erroMessage,\n detail: error,\n }\n\n ctx.vtex.logger.log(splunkError, LogLevel.Error)\n throw new ResolverError(erroMessage)\n }\n }\n}\n\n```"
}
] |
code_store-framework-course_a8238a4c
|
[
{
"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 store-framework-course/course/config.json from the store-framework-course VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"title\": \"Store Framework\",\n \"tagline\": \"A brand new course on Learning Lab\",\n \"description\": \"Learning how to build a store using the Store Framework blocks language, powered by VTEX IO.\",\n \"languages\": [\n \"en\",\n \"es\",\n \"pt\"\n ],\n \"steps\": [\n {\n \"folder\": \"setup\",\n \"title\": {\n \"en\": \"Store Framework course\",\n \"es\": \"Curso del Store Framework\",\n \"pt\": \"Curso de Store Framework\"\n },\n \"description\": {\n \"en\": \"Store Framework development prerequisites\",\n \"es\": \"Requisitos previos para desarrollar con Store Framework\",\n \"pt\": \"Pré-requisitos para desenvolver com o Store Framework\"\n },\n \"challenge\": \"none\"\n }\n ]\n}\n```"
}
] |
code_store-framework-course_7d15473c
|
[
{
"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 store-framework-course/course/README.md from the store-framework-course VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```markdown\n# Store Framework course\n\n> **This content was moved to another place. We no longer support these courses and learning portal.**\n\nThis course was divided into smaller ones, you can start by checking out [this course](https://developers.vtex.com/learning/docs/course-basic-blocks-lang-en). You can also have a look at [our new landing page](https://developers.vtex.com/learning), where it's possible to find some interesting content!\n\n```"
}
] |
code_store-framework-course_94386388
|
[
{
"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 store-framework-course/course/package.json from the store-framework-course VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"scripts\": {\n \"build\": \"tsc\",\n \"test\": \"yarn jest\"\n },\n \"dependencies\": {\n \"postcss\": \"^7.0.27\",\n \"ramda\": \"^0.27.0\",\n \"typescript\": \"3.7.3\"\n },\n \"devDependencies\": {\n \"@types/ramda\": \"^0.26.43\"\n }\n}\n\n```"
}
] |
code_store-framework-course_f7f7d4fb
|
[
{
"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 store-framework-course/course/global.d.ts from the store-framework-course VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport * as ramda from 'ramda'\n\nexport {} \n\ndeclare global {\n interface TestContext {\n getFile: (path: string) => Promise<string>\n parseCss: (content: string) => object\n parseJsonc: (content: string) => object\n ramda: typeof ramda\n [key: string]: any\n }\n\n interface TestFunctionParameters {\n ctx: TestContext\n }\n\n interface TestCase {\n tests: {\n description: string\n failMsg: string\n test: (param: TestFunctionParameters) => Promise<boolean> | boolean\n }[]\n }\n}\n\n```"
}
] |
code_store-framework-course_a17a79c6
|
[
{
"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 store-framework-course/course/template/README.md from the store-framework-course VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```markdown\n# store-framework-template\nThe template repository for the Store Framework course on Learning Lab.\n\n```"
}
] |
code_store-framework-course_849c33c7
|
[
{
"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 store-framework-course/course/template/manifest.json from the store-framework-course VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"vendor\": \"vtex\",\n \"name\": \"theme\",\n \"version\": \"0.0.1\",\n \"builders\": {\n \"styles\": \"2.x\",\n \"store\": \"0.x\"\n },\n \"scripts\": {\n \"postreleasy\": \"vtex publish --verbose\"\n },\n \"dependencies\": {\n \"vtex.store\": \"2.x\",\n \"vtex.store-header\": \"2.x\",\n \"vtex.product-summary\": \"2.x\",\n \"vtex.store-footer\": \"2.x\",\n \"vtex.store-components\": \"3.x\",\n \"vtex.styleguide\": \"9.x\",\n \"vtex.slider\": \"0.x\",\n \"vtex.carousel\": \"2.x\",\n \"vtex.shelf\": \"1.x\",\n \"vtex.menu\": \"2.x\",\n \"vtex.minicart\": \"2.x\",\n \"vtex.product-details\": \"1.x\",\n \"vtex.product-kit\": \"1.x\",\n \"vtex.search-result\": \"3.x\",\n \"vtex.login\": \"2.x\",\n \"vtex.my-account\": \"1.x\",\n \"vtex.flex-layout\": \"0.x\",\n \"vtex.rich-text\": \"0.x\",\n \"vtex.store-drawer\": \"0.x\",\n \"vtex.locale-switcher\": \"0.x\",\n \"vtex.product-quantity\": \"1.x\",\n \"vtex.product-identifier\": \"0.x\",\n \"vtex.product-specification-badges\": \"0.x\",\n \"vtex.product-review-interfaces\": \"1.x\",\n \"vtex.telemarketing\": \"2.x\",\n \"vtex.order-placed\": \"1.x\",\n \"vtex.stack-layout\": \"0.x\",\n \"vtex.tab-layout\": \"0.x\",\n \"vtex.responsive-layout\": \"0.x\",\n \"vtex.slider-layout\": \"0.x\",\n \"vtex.iframe\": \"0.x\",\n \"vtex.breadcrumb\": \"1.x\"\n },\n \"$schema\": \"https://raw.githubusercontent.com/vtex/node-vtex-api/master/gen/manifest.schema\"\n}\n\n```"
}
] |
code_store-framework-course_0a27f2c1
|
[
{
"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 store-framework-course/course/template/styles/configs/style.json from the store-framework-course VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"typeScale\": [\n 3,\n 2.25,\n 1.5,\n 1.25,\n 1,\n 0.875,\n 0.75\n ],\n \"spacing\": [\n 0.125,\n 0.25,\n 0.5,\n 0.75,\n 1,\n 1.5,\n 2,\n 3,\n 4,\n 8,\n 16\n ],\n \"customMedia\": [\n {\n \"s\": 20\n },\n {\n \"ns\": {\n \"value\": 40,\n \"minWidth\": true\n }\n },\n {\n \"m\": {\n \"value\": 40,\n \"minWidth\": true\n }\n },\n {\n \"l\": {\n \"value\": 64,\n \"minWidth\": true\n }\n },\n {\n \"xl\": {\n \"value\": 80,\n \"minWidth\": true\n }\n }\n ],\n \"colors\": {\n \"black-90\": \"rgba(0,0,0,.9)\",\n \"black-80\": \"rgba(0,0,0,.8)\",\n \"black-70\": \"rgba(0,0,0,.7)\",\n \"black-60\": \"rgba(0,0,0,.6)\",\n \"black-50\": \"rgba(0,0,0,.5)\",\n \"black-40\": \"rgba(0,0,0,.4)\",\n \"black-30\": \"rgba(0,0,0,.3)\",\n \"black-20\": \"rgba(0,0,0,.2)\",\n \"black-10\": \"rgba(0,0,0,.1)\",\n \"black-05\": \"rgba(0,0,0,.05)\",\n \"black-025\": \"rgba(0,0,0,.025)\",\n \"black-0125\": \"rgba(0,0,0,.0125)\",\n \"white-90\": \"rgba(255,255,255,.9)\",\n \"white-80\": \"rgba(255,255,255,.8)\",\n \"white-70\": \"rgba(255,255,255,.7)\",\n \"white-60\": \"rgba(255,255,255,.6)\",\n \"white-50\": \"rgba(255,255,255,.5)\",\n \"white-40\": \"rgba(255,255,255,.4)\",\n \"white-30\": \"rgba(255,255,255,.3)\",\n \"white-20\": \"rgba(255,255,255,.2)\",\n \"white-10\": \"rgba(255,255,255,.1)\",\n \"white-05\": \"rgba(255,255,255,.05)\",\n \"white-025\": \"rgba(255,255,255,.025)\",\n \"white-0125\": \"rgba(255,255,255,.0125)\"\n },\n \"semanticColors\": {\n \"background\": {\n \"base\": \"#ffffff\",\n \"base--inverted\": \"#03044e\",\n \"action-primary\": \"#0F3E99\",\n \"action-secondary\": \"#eef3f7\",\n \"emphasis\": \"#f71963\",\n \"disabled\": \"#f2f4f5\",\n \"success\": \"#8bc34a\",\n \"success--faded\": \"#eafce3\",\n \"danger\": \"#ff4c4c\",\n \"danger--faded\": \"#ffe6e6\",\n \"warning\": \"#ffb100\",\n \"warning--faded\": \"#fff6e0\",\n \"muted-1\": \"#727273\",\n \"muted-2\": \"#979899\",\n \"muted-3\": \"#cacbcc\",\n \"muted-4\": \"#e3e4e6\",\n \"muted-5\": \"#f2f4f5\"\n },\n \"hover-background\": {\n \"action-primary\": \"#072c75\",\n \"action-secondary\": \"#dbe9fd\",\n \"emphasis\": \"#dd1659\",\n \"success\": \"#8bc34a\",\n \"success--faded\": \"#eafce3\",\n \"danger\": \"#e13232\",\n \"danger--faded\": \"#ffe6e6\",\n \"warning\": \"#ffb100\",\n \"warning--faded\": \"#fff6e0\",\n \"muted-1\": \"#727273\",\n \"muted-2\": \"#979899\",\n \"muted-3\": \"#cacbcc\",\n \"muted-4\": \"#e3e4e6\",\n \"muted-5\": \"#f2f4f5\"\n },\n \"active-background\": {\n \"action-primary\": \"#0c389f\",\n \"action-secondary\": \"#dbe9fd\",\n \"emphasis\": \"#dd1659\",\n \"success\": \"#8bc34a\",\n \"success--faded\": \"#eafce3\",\n \"danger\": \"#ff4c4c\",\n \"danger--faded\": \"#ffe6e6\",\n \"warning\": \"#ffb100\",\n \"warning--faded\": \"#fff6e0\",\n \"muted-1\": \"#727273\",\n \"muted-2\": \"#979899\",\n \"muted-3\": \"#cacbcc\",\n \"muted-4\": \"#e3e4e6\",\n \"muted-5\": \"#f2f4f5\"\n },\n \"text\": {\n \"action-primary\": \"#0F3E99\",\n \"action-secondary\": \"#eef3f7\",\n \"link\": \"#0F3E99\",\n \"emphasis\": \"#f71963\",\n \"disabled\": \"#979899\",\n \"success\": \"#8bc34a\",\n \"success--faded\": \"#eafce3\",\n \"danger\": \"#ff4c4c\",\n \"danger--faded\": \"#ffe6e6\",\n \"warning\": \"#ffb100\",\n \"warning--faded\": \"#fff6e0\",\n \"muted-1\": \"#727273\",\n \"muted-2\": \"#979899\",\n \"muted-3\": \"#cacbcc\",\n \"muted-4\": \"#e3e4e6\",\n \"muted-5\": \"#f2f4f5\"\n },\n \"visited-text\": {\n \"link\": \"#0c389f\"\n },\n \"hover-text\": {\n \"action-primary\": \"#072c75\",\n \"action-secondary\": \"#dbe9fd\",\n \"link\": \"#0c389f\",\n \"emphasis\": \"#dd1659\",\n \"success\": \"#8bc34a\",\n \"success--faded\": \"#eafce3\",\n \"danger\": \"#e13232\",\n \"danger--faded\": \"#ffe6e6\",\n \"warning\": \"#ffb100\",\n \"warning--faded\": \"#fff6e0\"\n },\n \"active-text\": {\n \"link\": \"#0c389f\",\n \"emphasis\": \"#dd1659\",\n \"success\": \"#8bc34a\",\n \"success--faded\": \"#eafce3\",\n \"danger\": \"#ff4c4c\",\n \"danger--faded\": \"#ffe6e6\",\n \"warning\": \"#ffb100\",\n \"warning--faded\": \"#fff6e0\"\n },\n \"border\": {\n \"action-primary\": \"#0F3E99\",\n \"action-secondary\": \"#eef3f7\",\n \"emphasis\": \"#f71963\",\n \"disabled\": \"#e3e4e6\",\n \"success\": \"#8bc34a\",\n \"success--faded\": \"#eafce3\",\n \"danger\": \"#ff4c4c\",\n \"danger--faded\": \"#ffe6e6\",\n \"warning\": \"#ffb100\",\n \"warning--faded\": \"#fff6e0\",\n \"muted-1\": \"#727273\",\n \"muted-2\": \"#979899\",\n \"muted-3\": \"#cacbcc\",\n \"muted-4\": \"#e3e4e6\",\n \"muted-5\": \"#f2f4f5\"\n },\n \"hover-border\": {\n \"action-primary\": \"#072c75\",\n \"action-secondary\": \"#dbe9fd\",\n \"emphasis\": \"#dd1659\",\n \"success\": \"#8bc34a\",\n \"success--faded\": \"#eafce3\",\n \"danger\": \"#e13232\",\n \"danger--faded\": \"#ffe6e6\",\n \"warning\": \"#ffb100\",\n \"warning--faded\": \"#fff6e0\",\n \"muted-1\": \"#727273\",\n \"muted-2\": \"#979899\",\n \"muted-3\": \"#cacbcc\",\n \"muted-4\": \"#e3e4e6\",\n \"muted-5\": \"#f2f4f5\"\n },\n \"active-border\": {\n \"action-primary\": \"#0c389f\",\n \"action-secondary\": \"#dbe9fd\",\n \"emphasis\": \"#dd1659\",\n \"success\": \"#8bc34a\",\n \"success--faded\": \"#eafce3\",\n \"danger\": \"#ff4c4c\",\n \"danger--faded\": \"#ffe6e6\",\n \"warning\": \"#ffb100\",\n \"warning--faded\": \"#fff6e0\",\n \"muted-1\": \"#727273\",\n \"muted-2\": \"#979899\",\n \"muted-3\": \"#cacbcc\",\n \"muted-4\": \"#e3e4e6\",\n \"muted-5\": \"#f2f4f5\"\n },\n \"on\": {\n \"base\": \"#3f3f40\",\n \"base--inverted\": \"#ffffff\",\n \"action-primary\": \"#ffffff\",\n \"action-secondary\": \"#0F3E99\",\n \"emphasis\": \"#ffffff\",\n \"disabled\": \"#979899\",\n \"success\": \"#ffffff\",\n \"success--faded\": \"#3f3f40\",\n \"danger\": \"#ffffff\",\n \"danger--faded\": \"#3f3f40\",\n \"warning\": \"#ffffff\",\n \"warning--faded\": \"#1a1a1a\",\n \"muted-1\": \"#ffffff\",\n \"muted-2\": \"#ffffff\",\n \"muted-3\": \"#3f3f40\",\n \"muted-4\": \"#3f3f40\",\n \"muted-5\": \"#3f3f40\"\n },\n \"hover-on\": {\n \"action-primary\": \"#ffffff\",\n \"action-secondary\": \"#0F3E99\",\n \"emphasis\": \"#ffffff\",\n \"success\": \"#ffffff\",\n \"success--faded\": \"#3f3f40\",\n \"danger\": \"#ffffff\",\n \"danger--faded\": \"#3f3f40\",\n \"warning\": \"#ffffff\",\n \"warning--faded\": \"#1a1a1a\"\n },\n \"active-on\": {\n \"action-primary\": \"#ffffff\",\n \"action-secondary\": \"#0F3E99\",\n \"emphasis\": \"#ffffff\",\n \"success\": \"#ffffff\",\n \"success--faded\": \"#3f3f40\",\n \"danger\": \"#ffffff\",\n \"danger--faded\": \"#3f3f40\",\n \"warning\": \"#ffffff\",\n \"warning--faded\": \"#1a1a1a\"\n }\n },\n \"borderWidths\": [\n 0,\n 0.125,\n 0.25,\n 0.5,\n 1,\n 2\n ],\n \"borderRadius\": [\n 0,\n 0.125,\n 0.25,\n 0.5,\n 1\n ],\n \"widths\": [\n 1,\n 2,\n 4,\n 8,\n 16\n ],\n \"maxWidths\": [\n 1,\n 2,\n 4,\n 8,\n 16,\n 32,\n 48,\n 64,\n 96\n ],\n \"heights\": [\n 1,\n 2,\n 4,\n 8,\n 16\n ],\n \"sizes\": [\n {\n \"name\": \"small\",\n \"value\": 2\n },\n {\n \"name\": \"regular\",\n \"value\": 2.5\n },\n {\n \"name\": \"large\",\n \"value\": 3\n }\n ],\n \"typography\": {\n \"measure\": [\n 30,\n 34,\n 20\n ],\n \"styles\": {\n \"heading-1\": {\n \"fontFamily\": \"Fabriga, -apple-system, BlinkMacSystemFont, avenir next, avenir, helvetica neue, helvetica, ubuntu, roboto, noto, segoe ui, arial, sans-serif\",\n \"fontWeight\": \"700\",\n \"fontSize\": \"3rem\",\n \"textTransform\": \"initial\",\n \"letterSpacing\": \"0\"\n },\n \"heading-2\": {\n \"fontFamily\": \"Fabriga, -apple-system, BlinkMacSystemFont, avenir next, avenir, helvetica neue, helvetica, ubuntu, roboto, noto, segoe ui, arial, sans-serif\",\n \"fontWeight\": \"700\",\n \"fontSize\": \"2.25rem\",\n \"textTransform\": \"initial\",\n \"letterSpacing\": \"0\"\n },\n \"heading-3\": {\n \"fontFamily\": \"Fabriga, -apple-system, BlinkMacSystemFont, avenir next, avenir, helvetica neue, helvetica, ubuntu, roboto, noto, segoe ui, arial, sans-serif\",\n \"fontWeight\": \"700\",\n \"fontSize\": \"1.75rem\",\n \"textTransform\": \"initial\",\n \"letterSpacing\": \"0\"\n },\n \"heading-4\": {\n \"fontFamily\": \"Fabriga, -apple-system, BlinkMacSystemFont, avenir next, avenir, helvetica neue, helvetica, ubuntu, roboto, noto, segoe ui, arial, sans-serif\",\n \"fontWeight\": \"normal\",\n \"fontSize\": \"1.5rem\",\n \"textTransform\": \"initial\",\n \"letterSpacing\": \"0\"\n },\n \"heading-5\": {\n \"fontFamily\": \"Fabriga, -apple-system, BlinkMacSystemFont, avenir next, avenir, helvetica neue, helvetica, ubuntu, roboto, noto, segoe ui, arial, sans-serif\",\n \"fontWeight\": \"normal\",\n \"fontSize\": \"1.25rem\",\n \"textTransform\": \"initial\",\n \"letterSpacing\": \"0\"\n },\n \"heading-6\": {\n \"fontFamily\": \"Fabriga, -apple-system, BlinkMacSystemFont, avenir next, avenir, helvetica neue, helvetica, ubuntu, roboto, noto, segoe ui, arial, sans-serif\",\n \"fontWeight\": \"normal\",\n \"fontSize\": \"1.25rem\",\n \"textTransform\": \"initial\",\n \"letterSpacing\": \"0\"\n },\n \"body\": {\n \"fontFamily\": \"Fabriga, -apple-system, BlinkMacSystemFont, avenir next, avenir, helvetica neue, helvetica, ubuntu, roboto, noto, segoe ui, arial, sans-serif\",\n \"fontWeight\": \"normal\",\n \"fontSize\": \"1rem\",\n \"textTransform\": \"initial\",\n \"letterSpacing\": \"0\"\n },\n \"small\": {\n \"fontFamily\": \"Fabriga, -apple-system, BlinkMacSystemFont, avenir next, avenir, helvetica neue, helvetica, ubuntu, roboto, noto, segoe ui, arial, sans-serif\",\n \"fontWeight\": \"normal\",\n \"fontSize\": \"0.875rem\",\n \"textTransform\": \"initial\",\n \"letterSpacing\": \"0\"\n },\n \"mini\": {\n \"fontFamily\": \"Fabriga, -apple-system, BlinkMacSystemFont, avenir next, avenir, helvetica neue, helvetica, ubuntu, roboto, noto, segoe ui, arial, sans-serif\",\n \"fontWeight\": \"normal\",\n \"fontSize\": \"0.75rem\",\n \"textTransform\": \"initial\",\n \"letterSpacing\": \"0\"\n },\n \"action\": {\n \"fontFamily\": \"Fabriga, -apple-system, BlinkMacSystemFont, avenir next, avenir, helvetica neue, helvetica, ubuntu, roboto, noto, segoe ui, arial, sans-serif\",\n \"fontWeight\": \"500\",\n \"fontSize\": \"1rem\",\n \"textTransform\": \"uppercase\",\n \"letterSpacing\": \"0\"\n },\n \"action--small\": {\n \"fontFamily\": \"Fabriga, -apple-system, BlinkMacSystemFont, avenir next, avenir, helvetica neue, helvetica, ubuntu, roboto, noto, segoe ui, arial, sans-serif\",\n \"fontWeight\": \"500\",\n \"fontSize\": \"0.875rem\",\n \"textTransform\": \"uppercase\",\n \"letterSpacing\": \"0\"\n },\n \"action--large\": {\n \"fontFamily\": \"Fabriga, -apple-system, BlinkMacSystemFont, avenir next, avenir, helvetica neue, helvetica, ubuntu, roboto, noto, segoe ui, arial, sans-serif\",\n \"fontWeight\": \"500\",\n \"fontSize\": \"1.25rem\",\n \"textTransform\": \"uppercase\",\n \"letterSpacing\": \"0\"\n },\n \"code\": {\n \"fontFamily\": \"Consolas, monaco, monospace\",\n \"fontWeight\": \"normal\",\n \"fontSize\": \"1rem\",\n \"textTransform\": \"initial\",\n \"letterSpacing\": \"0\"\n }\n }\n },\n \"opacity\": [\n 1,\n 0.9,\n 0.8,\n 0.7,\n 0.6,\n 0.5,\n 0.4,\n 0.3,\n 0.2,\n 0.1,\n 0.05,\n 0.025,\n 0\n ]\n}\n\n```"
}
] |
code_store-framework-course_47e1ab50
|
[
{
"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 store-framework-course/course/template/store/blocks/drawer.jsonc from the store-framework-course VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"drawer\": {\n \"children\": [\n \"vtex.menu@2.x:menu#drawer\"\n ]\n },\n\n \"vtex.menu@2.x:menu#drawer\": {\n \"children\": [\n \"menu-item#major-appliances-acc\",\n \"menu-item#small-appliances-acc\",\n \"menu-item#electronics-acc\"\n ],\n \"props\":{\n \"orientation\": \"vertical\"\n }\n },\n \"menu-item#major-appliances-acc\": {\n \"props\":\n {\n \"type\": \"category\",\n \"highlight\": true,\n \"itemProps\": {\n \"categoryId\": 1, \n \"text\": \"Major Appliances\"\n }\n },\n \"blocks\": [\n \"vtex.menu@2.x:submenu.accordion#major\"\n ]\n },\n \"menu-item#small-appliances-acc\": {\n \"props\":\n {\n \"type\": \"category\",\n \"highlight\": true,\n \"itemProps\": {\n \"categoryId\": 2, \n \"text\": \"Small Appliances\"\n }\n },\n \"blocks\": [\n \"vtex.menu@2.x:submenu.accordion#small\"\n ]\n },\n \"menu-item#electronics-acc\": {\n \"props\":\n {\n \"type\": \"category\",\n \"highlight\": true,\n \"itemProps\": {\n \"categoryId\": 3, \n \"text\": \"Electronics\"\n }\n },\n \"blocks\": [\n \"vtex.menu@2.x:submenu.accordion#electronics\"\n ]\n },\n \"vtex.menu@2.x:submenu.accordion#major\":{\n \"children\":[\n \"vtex.menu@2.x:menu#major\"\n ]\n },\n \"vtex.menu@2.x:submenu.accordion#small\":{\n \"children\":[\n \"vtex.menu@2.x:menu#small\"\n ]\n },\n \"vtex.menu@2.x:submenu.accordion#electronics\":{\n \"children\":[\n \"vtex.menu@2.x:menu#electronics\"\n ]\n },\n \"vtex.menu@2.x:menu#major\":{\n \"children\": [\n \"menu-item#refrigerators\",\n \"menu-item#ovens\",\n \"menu-item#washers\"\n ],\n \"props\":{\n \"orientation\": \"vertical\"\n }\n },\n \"vtex.menu@2.x:menu#small\":{\n \"children\": [\n \"menu-item#mixers\",\n \"menu-item#toasters\",\n \"menu-item#coffee\"\n ],\n \"props\":{\n \"orientation\": \"vertical\"\n }\n },\n \"vtex.menu@2.x:menu#electronics\":{\n \"children\": [\n \"menu-item#cameras\",\n \"menu-item#laptops\",\n \"menu-item#tvs\"\n ],\n \"props\":{\n \"orientation\": \"vertical\"\n }\n }\n}\n```"
}
] |
code_store-framework-course_0829fb6e
|
[
{
"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 store-framework-course/course/template/store/blocks/default.jsonc from the store-framework-course VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"store.orderplaced\": {\n \"blocks\": [\"order-placed\"]\n },\n\n \"store.account\": {\n \"blocks\": [\"my-account\"],\n \"parent\": {\n \"challenge\": \"challenge.profile\"\n }\n },\n\n \"store.login\": {\n \"blocks\": [\"login-content#default\"]\n },\n\n \"login-content#default\": {\n \"props\": {\n \"isInitialScreenOptionOnly\": false,\n \"defaultOption\": 1,\n \"showPasswordVerificationIntoTooltip\": true\n }\n },\n\n \"product-summary.shelf\": {\n \"children\": [\n \"product-summary-add-to-list-button\",\n \"product-summary-name\",\n \"product-rating-inline\",\n \"product-summary-space\",\n \"product-summary-price\",\n \"product-identifier.summary\",\n \"product-summary-buy-button\"\n ]\n }\n}\n\n```"
}
] |
code_store-framework-course_b494d46f
|
[
{
"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 store-framework-course/course/template/store/blocks/menu-items.jsonc from the store-framework-course VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"menu-item#major-appliances\": {\n \"props\": {\n \"type\": \"custom\",\n \"highlight\": true,\n \"itemProps\": {\n \"text\": \"Major Aplliances\"\n }\n }\n },\n \"menu-item#small-appliances\": {\n \"props\":\n {\n \"type\": \"category\",\n \"highlight\": true,\n \"itemProps\": {\n \"categoryId\": 2, \n \"text\": \"Small Appliances\"\n }\n }\n },\n \"menu-item#electronics\": {\n \"props\":\n {\n \"type\": \"category\",\n \"highlight\": true,\n \"itemProps\": {\n \"categoryId\": 3, \n \"text\": \"Electronics\"\n }\n }\n },\n \"menu-item#refrigerators\": {\n \"props\":\n {\n \"type\": \"category\",\n \"highlight\": true,\n \"itemProps\": {\n \"categoryId\": 4, \n \"text\": \"Refrigerators\"\n }\n }\n },\n \"menu-item#ovens\": {\n \"props\":\n {\n \"type\": \"category\",\n \"highlight\": true,\n \"itemProps\": {\n \"categoryId\": 5, \n \"text\": \"Ranges & Ovens\"\n }\n }\n },\n \"menu-item#washers\": {\n \"props\":\n {\n \"type\": \"category\",\n \"highlight\": true,\n \"itemProps\": {\n \"categoryId\": 6, \n \"text\": \"Washers & Dryers\"\n }\n }\n },\n \"menu-item#mixers\": {\n \"props\":\n {\n \"type\": \"category\",\n \"highlight\": true,\n \"itemProps\": {\n \"categoryId\": 7, \n \"text\": \"Mixers & Blenders\"\n }\n }\n },\n \"menu-item#toasters\": {\n \"props\":\n {\n \"type\": \"category\",\n \"highlight\": true,\n \"itemProps\": {\n \"categoryId\": 8, \n \"text\": \"Toasters & Grills\"\n }\n }\n },\n \"menu-item#coffee\": {\n \"props\":\n {\n \"type\": \"category\",\n \"highlight\": true,\n \"itemProps\": {\n \"categoryId\": 9, \n \"text\": \"Coffee Makers\"\n }\n }\n },\n \"menu-item#tvs\": {\n \"props\":\n {\n \"type\": \"category\",\n \"highlight\": true,\n \"itemProps\": {\n \"categoryId\": 10, \n \"text\": \"TVs\"\n }\n }\n },\n \"menu-item#laptops\": {\n \"props\":\n {\n \"type\": \"category\",\n \"highlight\": true,\n \"itemProps\": {\n \"categoryId\": 11, \n \"text\": \"Laptops\"\n }\n }\n },\n \"menu-item#cameras\": {\n \"props\":\n {\n \"type\": \"category\",\n \"highlight\": true,\n \"itemProps\": {\n \"categoryId\": 12, \n \"text\": \"Cameras\"\n }\n }\n }\n}\n```"
}
] |
code_store-framework-course_cd0f11ef
|
[
{
"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 store-framework-course/course/template/store/blocks/home.jsonc from the store-framework-course VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"store.home\": { \n \"blocks\": [\n \n ]\n }\n}\n```"
}
] |
code_store-framework-course_09059efb
|
[
{
"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 store-framework-course/course/template/store/blocks/product.jsonc from the store-framework-course VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"store.product\": {\n \"children\": [\n ]\n }\n}\n```"
}
] |
code_sticky-layout_71ff2f6b
|
[
{
"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 sticky-layout/docs/README.md from the sticky-layout VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```markdown\n# VTEX Sticky Layout\n<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->\n[](#contributors-)\n<!-- ALL-CONTRIBUTORS-BADGE:END -->\n\nThe Sticky Layout app provides layout structures to help building elements that should be fixed relative to the viewport in certain contexts.\n\n> Sticky positioning is a hybrid of relative and fixed positioning. The element is treated as relative positioned until it crosses a specified threshold, at which point it is treated as fixed positioned.\n>\n> You can understand more by reading about in the [MDN `position` documentation](https://developer.mozilla.org/en-US/docs/Web/CSS/position#Sticky_positioning).\n\n<!-- @import \"[TOC]\" {cmd=\"toc\" depthFrom=3 depthTo=6 orderedList=false} -->\n\n<!-- code_chunk_output -->\n\n- [`sticky-layout`](#sticky-layout)\n- [`sticky-layout.stack-container`](#sticky-layoutstack-container)\n\n<!-- /code_chunk_output -->\n\n## Blocks\n\n### `sticky-layout`\n\nThe `sticky-layout` block is responsible for making its children _stick_ to a certain position on the page when exiting the viewport while scrolling.\n\n**Props:**\n\n| Prop name | Type | Description | Default value |\n| ----------------- | -------------- | -------------------------------------------------------------------------------- | ------------- |\n| `blockClass` | `String` | Unique class name to be appended to the container class | `\"\"` |\n| `position` | `PositionEnum` | Indicates where the component should stick | `N/A` |\n| `verticalSpacing` | `Number` | Indicates the distance in pixels from the position chosen in the `position` prop | `0` |\n\n`PositionEnum` options:\n\n| Enum name | Enum value | Description |\n| --------- | ---------- | -------------------------------------------- |\n| `TOP` | `'top'` | Component will stick to the top of screen |\n| `BOTTOM` | `'bottom'` | Component will stick to the bottom of screen |\n\n**CSS Handles:**\n\n| Prop name | Description |\n| ---------------- | ------------------------------------------------------------------------------------------------------------- |\n| `container` | Sticky layout container |\n| `wrapper` | Wrapper element that takes up the space previously used by the stuck element to prevent the page from jumping |\n| `wrapper--stuck` | Sticky layout wrapper when stuck to a position on the page |\n\n**Example usage:**\n\n```jsonc\n{\n \"store.product\": {\n \"children\": [\n \"flex-layout.row#product-breadcrumb\",\n \"flex-layout.row#product-main\",\n \"sticky-layout#buy-button\"\n ],\n \"parent\": {\n \"challenge\": \"challenge.address\"\n }\n },\n \"sticky-layout#buy-button\": {\n \"props\": {\n \"position\": \"bottom\"\n },\n \"children\": [\"flex-layout.row#buy-button\"]\n },\n \"flex-layout.row#buy-button\": {\n \"props\": {\n \"marginTop\": 4,\n \"marginBottom\": 7,\n \"paddingBottom\": 2\n },\n \"children\": [\"buy-button\"]\n }\n}\n```\n\n### `sticky-layout.stack-container`\n\nThe `sticky-layout.stack-container` block can be used to orchestrate multiple `sticky-layout`s to have a stack behavior instead of one being on top of the other.\n\n**Props:**\n\n| Prop name | Type | Description | Default value |\n| ---------- | -------------- | --------------------------------------------------------------------------------------------------------- | ------------- |\n| `position` | `PositionEnum` | Indicates where the component should stick. _It overrides the `position` of its children `sticky-layout`_ | `N/A` |\n\n`PositionEnum` options:\n\n| Enum name | Enum value | Description |\n| --------- | ---------- | -------------------------------------------- |\n| `TOP` | `'top'` | Component will stick to the top of screen |\n| `BOTTOM` | `'bottom'` | Component will stick to the bottom of screen |\n\n**Example usage:**\n\nImagine three blocks: the first and the last being a `sticky-layout` and the second being any other block. A gap between both `sticky-layout`s will appear the moment the user starts scrolling the page. By defining those blocks inside a `sticky-layout.stack-container`, the second `sticky-layout` block will stick to the first `sticky-layout` instead of respecting the aformetioned gap or being one on top of the other.\n\n```jsonc\n{\n \"header\": {\n \"blocks\": [\"header-layout.desktop\"]\n },\n \"header.full\": {\n \"blocks\": [\"header-layout.desktop\"]\n },\n \"header-layout.desktop\": {\n // define a stack-container\n \"children\": [\"sticky-layout.stack-container#header\"]\n },\n \"sticky-layout.stack-container#header\": {\n \"props\": {\n \"position\": \"top\"\n },\n \"children\": [\n \"sticky-layout#links-menu\",\n // this notification.bar is not sticky, it will be scrolled away\n \"notification.bar#home\",\n \"sticky-layout#main-menu\"\n ]\n },\n \"notification.bar#home\": {\n \"props\": {\n \"content\": \"SELECTED ITEMS ON SALE! CHECK IT OUT!\"\n }\n },\n \"sticky-layout#links-menu\": {\n \"children\": [\"vtex.menu@2.x:menu#websites\"]\n },\n \"sticky-layout#main-menu\": {\n \"children\": [\"vtex.menu@2.x:menu#category-menu\"]\n }\n}\n```\n\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<!-- 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 welcome!\n```"
}
] |
code_sticky-layout_cce3d57d
|
[
{
"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 sticky-layout/react/StackContainer.tsx from the sticky-layout VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport React, { FC, createContext } from 'react'\n\nimport useCumulativeHeightState from './modules/useCumulativeHeightState'\nimport { Positions } from './types'\n\ninterface StackContext {\n position?: Positions\n onResize(height: number): void\n stickOffset: number\n}\n\ninterface Props {\n position: Positions\n}\n\nexport const StackContext = createContext<StackContext>({\n onResize: () => {},\n stickOffset: 0,\n})\n\n/** This component is used to accumulate the height of multiple StickLayout blocks,\n * so that they get stacked instead of appearing in front of each other */\nconst StackContainer: FC<Props> = ({ children, position = Positions.TOP }) => {\n const { updateRowHeight, getAccumulatedHeight } = useCumulativeHeightState()\n\n return (\n <React.Fragment>\n {React.Children.map(children, (child, index) => (\n <StackContext.Provider\n value={{\n position,\n onResize: (height: number) => updateRowHeight({ height, index }),\n stickOffset: getAccumulatedHeight(index),\n }}\n >\n {child}\n </StackContext.Provider>\n ))}\n </React.Fragment>\n )\n}\n\nexport default StackContainer\n\n```"
}
] |
code_sticky-layout_0208dc7a
|
[
{
"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 sticky-layout/react/StickyLayout.tsx from the sticky-layout VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport React, {\n FC,\n useContext,\n useState,\n useLayoutEffect,\n useCallback,\n useRef,\n CSSProperties,\n} from 'react'\nimport ReactResizeDetector from 'react-resize-detector'\nimport { useCssHandles, applyModifiers } from 'vtex.css-handles'\n\nimport { useStickyScroll } from './modules/useStickyScroll'\nimport { StackContext } from './StackContainer'\nimport { Positions } from './types'\nimport { useWindowListener } from './modules/useWindowListener'\n\nconst CSS_HANDLES = ['container', 'wrapper'] as const\n\ninterface Props {\n position?: Positions\n verticalSpacing?: number\n zIndex?: number\n}\n\nconst StickyLayoutComponent: FC<Props> = ({\n children,\n position: positionProp,\n zIndex,\n verticalSpacing = 0,\n}) => {\n const handles = useCssHandles(CSS_HANDLES)\n\n const wrapperRef = useRef<HTMLDivElement>(null)\n const containerRef = useRef<HTMLDivElement>(null)\n\n // Height of the sticky layout content\n const [contentHeight, setContentHeight] = useState<number | string>('auto')\n // Distance of the sticky layout wrapper to the top of the page\n const [wrapperOffsetTop, setWrapperOffsetTop] = useState<number | undefined>()\n\n const { stickOffset, onResize, position: positionContext } = useContext(\n StackContext\n )\n\n // Capturing the `wrapper.offsetTop` is costly, triggering\n // the layer tree update, paint and composite steps.\n // To solve this, we use the DOMContentLoaded together with a setInterval\n // to regularly update this value instead of reading it on EVERY scroll handler.\n const updateWrapperOffset = useCallback(() => {\n const offsetTop = wrapperRef.current?.offsetTop ?? 0\n if (offsetTop !== wrapperOffsetTop) {\n setWrapperOffsetTop(offsetTop)\n }\n }, [wrapperOffsetTop])\n\n // update the wrapper offset regularly because the page structure may have changed\n useLayoutEffect(() => {\n const intervalID = setInterval(updateWrapperOffset, 3000)\n return () => clearInterval(intervalID)\n }, [updateWrapperOffset])\n\n // update the wrapper offset when DOM parsing is done\n useWindowListener(['DOMContentLoaded', 'resize'], updateWrapperOffset)\n\n // Context position prop precedes the StickyLayout position prop\n const position = positionContext ?? positionProp ?? Positions.TOP\n\n const { isStuck } = useStickyScroll({\n stickOffset,\n position,\n verticalSpacing,\n contentHeight,\n wrapperOffsetTop,\n })\n\n if (positionContext != null && positionProp != null) {\n console.warn(\n '\"StackContainer\" overrides the \"StickyLayout\" \"position\" prop.'\n )\n }\n\n const containerClassname = [\n handles.container,\n !zIndex && 'z-999',\n isStuck ? 'fixed' : 'relative',\n 'left-0 right-0',\n ]\n .filter(Boolean)\n .join(' ')\n\n const wrapperClassname = isStuck\n ? applyModifiers(handles.wrapper, ['stuck'])\n : handles.wrapper\n\n const containerStyle: CSSProperties = {\n [position]: isStuck ? verticalSpacing + stickOffset : 0,\n zIndex,\n }\n\n const wrapperStyle: CSSProperties = {\n position: 'relative',\n height: contentHeight,\n }\n\n return (\n <div ref={wrapperRef} className={wrapperClassname} style={wrapperStyle}>\n <div\n ref={containerRef}\n className={containerClassname}\n style={containerStyle}\n >\n {children}\n <ReactResizeDetector\n handleHeight\n onResize={(_, height) => {\n if (isStuck === false) {\n setContentHeight(height)\n }\n onResize(height)\n }}\n />\n </div>\n </div>\n )\n}\n\nexport default StickyLayoutComponent\n\n```"
}
] |
code_sticky-layout_1f30f861
|
[
{
"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 sticky-layout/react/package.json from the sticky-layout VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"name\": \"vtex.sticky-layout\",\n \"scripts\": {\n \"lint\": \"eslint . --ext .ts --ext .tsx\",\n \"lint:fix\": \"eslint --fix . --ext .ts --ext .tsx\",\n \"test\": \"vtex-test-tools test\"\n },\n \"dependencies\": {\n \"react-resize-detector\": \"^4.2.1\",\n \"throttleit\": \"^1.0.0\"\n },\n \"devDependencies\": {\n \"@types/jest\": \"^25.1.2\",\n \"@types/node\": \"^13.7.1\",\n \"@types/ramda\": \"^0.26.41\",\n \"@types/react\": \"^16.9.19\",\n \"@types/react-resize-detector\": \"^4.2.0\",\n \"@vtex/test-tools\": \"^3.0.3\",\n \"@vtex/tsconfig\": \"^0.4.3\",\n \"apollo-cache-inmemory\": \"^1.6.5\",\n \"apollo-client\": \"^2.6.8\",\n \"typescript\": \"3.9.7\",\n \"vtex.css-handles\": \"http://vtex.vtexassets.com/_v/public/typings/v1/vtex.css-handles@0.4.1/public/@types/vtex.css-handles\",\n \"vtex.render-runtime\": \"http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@8.90.2/public/@types/vtex.render-runtime\"\n },\n \"vtexTestTools\": {\n \"defaultLocale\": \"pt-BR\"\n },\n \"version\": \"0.3.6\"\n}\n\n```"
}
] |
code_sticky-layout_3a00da42
|
[
{
"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 sticky-layout/store/interfaces.json from the sticky-layout VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"sticky-layout\": {\n \"allowed\": \"*\",\n \"component\": \"StickyLayout\",\n \"composition\": \"children\"\n },\n \"sticky-layout.stack-container\": {\n \"allowed\": \"*\",\n \"component\": \"StackContainer\",\n \"composition\": \"children\"\n }\n}\n\n```"
}
] |
code_sticky-layout_04cb22a7
|
[
{
"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 sticky-layout/react/types/index.ts from the sticky-layout VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nexport enum Positions {\n BOTTOM = 'bottom',\n TOP = 'top',\n}\n\n```"
}
] |
code_sticky-layout_319c8b05
|
[
{
"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 sticky-layout/react/typings/vtex.css-handles.d.ts from the sticky-layout VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\ndeclare module 'vtex.css-handles' {\n type CssHandlesInput = readonly string[]\n type ValueOf<T extends readonly any[]> = T[number]\n type CssHandles<T extends CssHandlesInput> = Record<ValueOf<T>, string>\n interface CssHandlesOptions {\n migrationFrom?: string | string[]\n }\n\n export const useCssHandles: <T extends CssHandlesInput>(\n handles: T,\n options: CssHandlesOptions = {}\n ) => CssHandles<T>\n export const applyModifiers: (\n handles: string,\n modifier: string | string[]\n ) => string\n}\n\n```"
}
] |
code_sticky-layout_1730f676
|
[
{
"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 sticky-layout/react/typings/css.d.ts from the sticky-layout VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\ndeclare module '*.css' {\n const css: any\n export default css\n}\n\n```"
}
] |
code_sticky-layout_17046889
|
[
{
"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 sticky-layout/react/typings/vtex.styleguide.d.ts from the sticky-layout VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\ndeclare module 'vtex.styleguide' {\n export const Button\n export const Modal\n}\n\n```"
}
] |
code_sticky-layout_a4ea38b5
|
[
{
"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 sticky-layout/react/modules/useWindowListener.ts from the sticky-layout VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { useLayoutEffect } from 'react'\nimport throttle from 'throttleit'\n\nimport canUsePassiveEventListeners from './canUsePassiveEventListeners'\n\nconst canUsePassiveListener = canUsePassiveEventListeners()\nconst currentEvents: Record<string, Set<Function>> = {}\n\nconst throttledScrollResizeHandler = throttle((e: Event) => {\n const scrollY = window.pageYOffset\n currentEvents[e.type].forEach(fn => fn(scrollY))\n}, 50)\n\nconst handlers: Record<string, (e: Event) => void> = {\n scroll: throttledScrollResizeHandler,\n resize: throttledScrollResizeHandler,\n default: (e: Event) => {\n currentEvents[e.type].forEach(fn => fn(e))\n },\n}\n\nfunction getHandler(event: string): (e: Event) => void {\n return handlers[event] ?? handlers.default\n}\n\nfunction detachListener(eventList: string[], fn: Function) {\n if (typeof window === 'undefined') {\n return\n }\n\n eventList.forEach(event => {\n currentEvents[event].delete(fn)\n if (currentEvents[event].size === 0) {\n window.removeEventListener(event, getHandler(event))\n }\n })\n}\n\nfunction attachListener(eventList: string[], fn: Function) {\n if (typeof window === 'undefined') {\n return\n }\n\n eventList.forEach(event => {\n if (!(event in currentEvents)) currentEvents[event] = new Set()\n if (currentEvents[event].size === 0) {\n window.addEventListener(\n event,\n getHandler(event),\n canUsePassiveListener ? { passive: true } : false\n )\n }\n currentEvents[event].add(fn)\n })\n\n return () => detachListener(eventList, fn)\n}\n\n/**\n * Hook responsible for handling multiple event callbacks\n * by using a single listener per event\n * @export\n * @param {string[]} eventList\n * @param {Function} fn\n */\nexport function useWindowListener(eventList: string[], fn: Function) {\n useLayoutEffect(() => attachListener(eventList, fn), [eventList, fn])\n}\n\n```"
}
] |
code_sticky-layout_b5d836c5
|
[
{
"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 sticky-layout/react/modules/useStickyScroll.ts from the sticky-layout VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { useCallback, useState } from 'react'\n\nimport { useWindowListener } from './useWindowListener'\nimport { Positions } from '../types'\n\ninterface StickyProps {\n position?: Positions\n verticalSpacing?: number\n stickOffset?: number\n contentHeight: number | string\n wrapperOffsetTop: number | undefined\n}\n\n/*\n * Hook responsible for defining if a sticky element should stuck to the viewport or not\n *\n * @param {StickyProps} {\n * position,\n * verticalSpacing = 0,\n * stickOffset = 0,\n * contentHeight,\n * wrapperOffsetTop,\n * }\n * @returns { isStuck }\n */\nexport const useStickyScroll = ({\n position,\n verticalSpacing = 0,\n stickOffset = 0,\n contentHeight,\n wrapperOffsetTop,\n}: StickyProps) => {\n const [isStuck, setStuck] = useState<boolean>(false)\n\n const handlePosition = useCallback(\n (scrollY: number) => {\n if (!contentHeight || typeof contentHeight !== 'number' || wrapperOffsetTop === undefined) return\n\n const offset = stickOffset + verticalSpacing\n let currentPosition = scrollY\n let stuckPosition = wrapperOffsetTop\n\n if (position === Positions.TOP) {\n stuckPosition -= offset\n /*\n * We remove `1` from the current position because stuck elements at the top\n * of the page must be able to be considered \"unstuck\".\n * In example, a mobile header at the top of the page should be considered unstuck\n * if the user scrolls back to the top of the page.\n */\n if (stuckPosition === 0 && currentPosition === 0) {\n currentPosition -= 1\n }\n } else {\n currentPosition += window.innerHeight\n stuckPosition += offset + contentHeight\n }\n\n const shouldStick = currentPosition >= stuckPosition\n\n // same state, do nothing\n if (isStuck === shouldStick) return\n\n setStuck(shouldStick)\n },\n [\n contentHeight,\n wrapperOffsetTop,\n position,\n isStuck,\n stickOffset,\n verticalSpacing,\n ]\n )\n\n useWindowListener(['resize', 'scroll'], handlePosition)\n\n return {\n isStuck,\n }\n}\n\n```"
}
] |
code_sticky-layout_f3ef0a0a
|
[
{
"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 sticky-layout/react/modules/useCumulativeHeightState.ts from the sticky-layout VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { useState } from 'react'\n\ntype State = Record<number, number>\n\n/**\n * Accumulate the height of multiple elements.\n *\n * @returns { getAccumulatedHeight, updateRowHeight }\n */\nconst useCumulativeHeightState = () => {\n const [state, set] = useState<State>({})\n\n const updateRowHeight = ({\n height,\n index,\n }: {\n height: number\n index: number\n }) => {\n if (state[index] === height) {\n return\n }\n\n set(prev => ({ ...prev, [index]: height }))\n }\n\n const getAccumulatedHeight = (index: number) => {\n const sortedIndices = Object.keys(state)\n .map(key => parseInt(key, 10))\n .sort((a, b) => a - b)\n\n const indices = sortedIndices.slice(0, sortedIndices.indexOf(index))\n return indices.reduce((acc, cur) => (state[cur] || 0) + acc, 0)\n }\n\n return {\n getAccumulatedHeight,\n updateRowHeight,\n }\n}\n\nexport default useCumulativeHeightState\n\n```"
}
] |
code_sticky-layout_accbac67
|
[
{
"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 sticky-layout/react/modules/canUsePassiveEventListeners.ts from the sticky-layout VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\n// Adapted from https://github.com/lencioni/consolidated-events/blob/master/src/canUsePassiveEventListeners.js\nfunction testPassiveEventListeners() {\n if (typeof window === 'undefined') {\n return false\n }\n\n let supportsPassiveOption = false\n try {\n const opts = Object.defineProperty({}, 'passive', {\n get() {\n supportsPassiveOption = true\n },\n })\n const noop = () => {}\n window.addEventListener('testPassiveEventSupport', noop, opts)\n window.removeEventListener('testPassiveEventSupport', noop, opts)\n } catch (e) {\n // do nothing\n }\n\n return supportsPassiveOption\n}\n\nlet memoizedResult: boolean\n\n/**\n * Checks if the browser supports using passive event listeners.\n *\n * @export\n * @returns\n */\nexport default function canUsePassiveEventListeners() {\n if (memoizedResult === undefined) {\n memoizedResult = testPassiveEventListeners()\n }\n return memoizedResult\n}\n\n```"
}
] |
code_crowdin-integration_b2e11720
|
[
{
"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 crowdin-integration/docs/README.md from the crowdin-integration VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```markdown\n# Crowdin Integration\n\nIntegration between IO Messages and Crowdin.\n\n```"
}
] |
code_crowdin-integration_217eb480
|
[
{
"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 crowdin-integration/node/service.json from the crowdin-integration VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"memory\": 256,\n \"ttl\": 10,\n \"timeout\": 15,\n \"minReplicas\": 2,\n \"maxReplicas\": 4,\n \"events\": {\n \"updateMessage\": {\n \"sender\": \"vtex.messages\",\n \"keys\": [\"updateMessage\"]\n },\n \"receiveExportedMessages\": {\n \"sender\": \"vtex.messages\",\n \"keys\": [\"sendExportedMessages\"]\n }\n },\n \"routes\" : {\n \"listenToUpdates\": {\n \"path\": \"/_v/translations/update\",\n \"public\": true,\n \"smartcache\": false\n }\n }\n}\n\n```"
}
] |
code_crowdin-integration_edf3bb30
|
[
{
"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 crowdin-integration/node/package.json from the crowdin-integration VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"dependencies\": {\n \"bluebird\": \"^3.5.5\",\n \"co-body\": \"^6.0.0\",\n \"crypto\": \"^1.0.1\",\n \"form-data\": \"^2.5.1\",\n \"koa-compose\": \"^4.0.0\",\n \"ramda\": \"^0.25.0\",\n \"@vtex/api\": \"3.65.0\"\n },\n \"devDependencies\": {\n \"@types/bluebird\": \"^3.5.27\",\n \"@types/form-data\": \"^2.2.1\",\n \"@types/co-body\": \"^0.x\",\n \"@types/koa-compose\": \"^3.2.0\",\n \"@types/node\": \"8.x\",\n \"@types/ramda\": \"types/npm-ramda#dist\",\n \"@vtex/api\": \"^3.65.0\",\n \"tslint\": \"^5.14.0\",\n \"tslint-config-vtex\": \"^2.1.0\",\n \"typescript\": \"3.5.2\"\n },\n \"scripts\": {\n \"lint\": \"tsc --noEmit --pretty && tslint -c tslint.json --fix './**/*.ts'\"\n },\n \"version\": \"0.7.2\"\n}\n\n```"
}
] |
code_crowdin-integration_ef5fad98
|
[
{
"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 crowdin-integration/node/index.ts from the crowdin-integration VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { ClientsConfig, LRUCache, method, Service } from '@vtex/api'\n\nimport { Clients } from './clients'\nimport { unwrap } from './events/crowdinAPI/unwrap'\nimport { updateCrowdinProject } from './events/crowdinAPI/update'\nimport { saveInCrowdin } from './events/export'\nimport { getSettings } from './events/settings'\nimport { getInfosFromCrowdin } from './middlewares/listenToUpdates'\nimport { saveIOMessage } from './middlewares/saveUpdateInMessages'\n\nconst TIMEOUT_MS = 3000\nconst TRANSLATION_CONCURRENCY = 5\nconst TRANSLATION_RETRIES = 3\nconst SHORT_TIMEOUT_MS = 1 * 1000\nconst CONCURRENCY = 10\n\nconst appsCacheStorage = new LRUCache<string, any>({\n max: 10,\n})\n\nmetrics.trackCache('apps', appsCacheStorage)\n\nconst clients: ClientsConfig<Clients> = {\n implementation: Clients,\n options: {\n apps: {\n concurrency: CONCURRENCY,\n memoryCache: appsCacheStorage,\n retries: 1,\n timeout: SHORT_TIMEOUT_MS,\n },\n default: {\n retries: 2,\n timeout: TIMEOUT_MS,\n },\n messagesGraphQL: {\n concurrency: TRANSLATION_CONCURRENCY,\n retries: TRANSLATION_RETRIES,\n timeout: TIMEOUT_MS,\n },\n },\n}\n\nexport default new Service<Clients, State>({\n clients,\n events: {\n receiveExportedMessages: [getSettings, saveInCrowdin],\n updateMessage: [getSettings, unwrap, updateCrowdinProject],\n },\n routes: {\n listenToUpdates: method({\n POST: [getSettings, getInfosFromCrowdin, saveIOMessage],\n }),\n },\n})\n\n```"
}
] |
code_crowdin-integration_9da70c91
|
[
{
"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 crowdin-integration/node/clients/Crowdin.ts from the crowdin-integration VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { ExternalClient, InstanceOptions, IOContext } from '@vtex/api'\n\nimport {\n CrowdinGetProjectResponse,\n CrowdinGetStringResponse,\n CrowdinGetTranslationResponse,\n CrowdinListProjects,\n StringToCrowdin,\n TranslationToCrowdin\n} from '../typings/Crowdin'\nimport { crowdinSettings } from '../utils/crowdin'\n\nexport class Crowdin extends ExternalClient {\n constructor(context: IOContext, options?: InstanceOptions){\n super('http://api.crowdin.com', context, {\n ...options,\n headers: {\n Authorization: `Bearer ${crowdinSettings.tokenApiV2}`,\n 'content-type': 'application/json',\n 'x-vtex-use-https': 'true',\n },\n })\n }\n\n public async addString(data: StringToCrowdin, projectId: string) {\n const dataToCrowdin = {\n context: data.groupContext,\n identifier: data.key,\n text: data.message,\n }\n\n let errMsg\n const res = await this.http.post<any>(`/api/v2/projects/${projectId}/strings`,\n dataToCrowdin,\n {\n metric: 'crowdin-add-string',\n })\n .catch((err) => {errMsg = err.response}\n )\n\n return {\n err: errMsg,\n res,\n }\n }\n\n public async addTranslation(data: TranslationToCrowdin, projectId: string) {\n const dataToCrowdin = {\n languageId: data.to,\n stringId: data.stringId,\n text: data.translation,\n }\n let errMsg\n\n const res = await this.http.post<any>(`/api/v2/projects/${projectId}/translations`,\n dataToCrowdin,\n {\n metric: 'crowdin-add-translation',\n })\n .catch((err) => {errMsg = err.response}\n )\n\n return {\n err: errMsg,\n res,\n }\n }\n\n public async getString(stringId: string, projectId: string) {\n let errMsg\n const res = await this.http.get<CrowdinGetStringResponse>(`/api/v2/projects/${projectId}/strings/${stringId}`,\n {\n metric: 'crowdin-get-string',\n }\n )\n .catch((err) => {errMsg = err.response})\n\n return {\n err: errMsg,\n res,\n }\n }\n\n public async getTranslation(translationId: string, projectId: string) {\n let errMsg\n const res = await this.http.get<CrowdinGetTranslationResponse>(`/api/v2/projects/${projectId}/translations/${translationId}`,\n {\n metric: 'crowdin-get-translation',\n }\n )\n .catch((err) => {errMsg = err.response})\n\n return {\n err: errMsg,\n res,\n }\n }\n\n public async getProject(projectId: string) {\n let errMsg\n const res = await this.http.get<CrowdinGetProjectResponse>(`/api/v2/projects/${projectId}`,\n {\n metric: 'crowdin-get-project',\n }\n )\n .catch((err) => {errMsg = err.response})\n\n return {\n err: errMsg,\n res,\n }\n }\n\n public async listProjects() {\n let errMsg\n const res = await this.http.get<CrowdinListProjects>(`/api/v2/projects`,\n {\n metric: 'crowdin-list-projects',\n }\n )\n .catch((err) => {errMsg = err.response})\n\n return {\n err: errMsg,\n res,\n }\n }\n}\n\n```"
}
] |
code_crowdin-integration_b05961f4
|
[
{
"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 crowdin-integration/node/clients/index.ts from the crowdin-integration VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { IOClients } from '@vtex/api'\n\nimport { Crowdin } from './Crowdin'\n\nexport class Clients extends IOClients {\n public get crowdin() {\n return this.getOrSet('crowdin', Crowdin)\n }\n}\n\n```"
}
] |
code_crowdin-integration_c3db40f9
|
[
{
"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 crowdin-integration/node/typings/Colossus.ts from the crowdin-integration VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { EventContext } from '@vtex/api'\n\nimport { Clients } from '../clients'\nimport { MessagesCrowdinByGroupContextAndSrcLang } from './Messages'\n\nexport interface ColossusEventContext extends EventContext<Clients, State> {\n status: number\n key: string\n sender: string\n body: any\n clients: Clients\n state: State\n}\n\nexport interface State {\n to: string\n messagesCrowdinByGroupContextAndSrcLang: MessagesCrowdinByGroupContextAndSrcLang\n}\n\n```"
}
] |
code_crowdin-integration_d1a0610c
|
[
{
"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 crowdin-integration/node/typings/Messages.ts from the crowdin-integration VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nexport interface MessagesCrowdin {\n [key: string] : {\n message: string,\n srcMessage?: string,\n description?: string\n }\n}\n\nexport interface MessagesCrowdinBySrcLang {\n [from: string]: MessagesCrowdin\n}\n\nexport interface MessagesCrowdinByGroupContextAndSrcLang {\n [groupContext: string]: MessagesCrowdinBySrcLang\n}\n\nexport interface UpdateMessageToCrowdinArg {\n to?: string,\n from: string,\n groupContext: string,\n messages: MessagesCrowdin\n}\n\nexport interface Translations {\n lang: string\n translation: string\n}\n\nexport interface ExportedMessage {\n srcLang: string\n groupContext?: string\n context: string\n translations: Translations[]\n}\n\nexport interface Range {\n from: number\n to: number\n}\n\nexport interface ExportedMessageObject {\n finished: boolean,\n range: Range\n messages: ExportedMessage[]\n}\n\n```"
}
] |
code_crowdin-integration_5ca1f92c
|
[
{
"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 crowdin-integration/node/typings/Crowdin.ts from the crowdin-integration VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nexport interface StringToCrowdin {\n message: string,\n key: string,\n groupContext: string\n}\n\nexport interface TranslationToCrowdin {\n translation: string,\n to: string,\n stringId: number\n}\n\nexport interface CrowdinListProjects {\n data: CrowdinGetProjectResponse[]\n}\n\nexport interface CrowdinGetProjectResponse {\n data: CrowdinGetProjectResponseData\n}\n\ninterface CrowdinGetProjectResponseData {\n id: string,\n groupId: string,\n userId: string,\n sourceLanguageId: string,\n targetLanguageIds: string[],\n joinPolicy: string,\n languageAccessPolicy: string,\n name: string,\n cname: string,\n identifier: string,\n description: string,\n visibility: string,\n logo: string,\n background: string,\n isExternal: boolean,\n externalType: string,\n advancedWorkflowId: number,\n hasCrowdsourcing: boolean,\n createdAt: string,\n updatedAt: string\n}\n\nexport interface CrowdinGetStringResponse {\n data: CrowdinGetStringResponseData\n}\n\ninterface CrowdinGetStringResponseData {\n id: number,\n projectId: number,\n fileId: number,\n identifier: string,\n text: string,\n type: string,\n context: string,\n maxLength: number,\n isHidden: boolean,\n revision: number,\n isIc: boolean,\n createdAt: string,\n updatedAt: string\n}\n\nexport interface CrowdinGetTranslationResponse {\n data: CrowdinGetTranslationResponseData\n}\n\ninterface CrowdinGetTranslationResponseData {\n id: number,\n text: string,\n pluralCategoryName: string,\n user: CrowdinUser,\n rating: number\n}\n\ninterface CrowdinUser {\n id: number,\n login: string\n}\n\nexport interface CrowdinNewTranslationApprovedEvent {\n event: string,\n project: string,\n project_id: string,\n language: string,\n source_string_id: string,\n translation_id: string,\n user: string,\n user_id: string,\n file_id: string,\n file: string\n}\n\n```"
}
] |
code_crowdin-integration_d696839e
|
[
{
"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 crowdin-integration/node/typings/typings.ts from the crowdin-integration VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { ServiceContext } from '@vtex/api'\n\nimport { Clients } from '../clients'\n\ndeclare global {\n interface State {\n srcMessage: string,\n targetMessage: string,\n srcLang: string,\n targetLang: string,\n groupContext: string\n }\n\n type Context = ServiceContext<Clients, State, void>\n}\n\n```"
}
] |
code_crowdin-integration_decc00fe
|
[
{
"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 crowdin-integration/node/middlewares/saveUpdateInMessages.ts from the crowdin-integration VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nexport async function saveIOMessage(ctx: Context, next:() => Promise<any>) {\n const {\n clients: {messagesGraphQL},\n state: {\n groupContext,\n srcLang,\n srcMessage,\n targetLang,\n targetMessage,\n },\n } = ctx\n\n const messages = [{\n groupContext,\n srcLang,\n srcMessage,\n targetMessage,\n }]\n\n await messagesGraphQL.saveV2({\n fireEvent: false,\n messages,\n to: targetLang,\n })\n\n ctx.status = 200\n await next()\n}\n\n```"
}
] |
code_crowdin-integration_04e47368
|
[
{
"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 crowdin-integration/node/middlewares/listenToUpdates.ts from the crowdin-integration VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport parseBody = require('co-body')\nimport { isEmpty, toPairs } from 'ramda'\n\nimport {\n CrowdinGetProjectResponse,\n CrowdinGetStringResponse,\n CrowdinGetTranslationResponse,\n CrowdinNewTranslationApprovedEvent\n} from '../typings/Crowdin'\nimport { CROWDIN_BUCKET } from '../utils/constants'\nimport { crowdinProjectsIds } from '../utils/crowdin'\n\nexport async function getInfosFromCrowdin(ctx: Context, next: () => Promise<void>) {\n const { crowdin, vbase } = ctx.clients\n const { logger } = ctx.vtex\n const body = await parseBody(ctx.req) as CrowdinNewTranslationApprovedEvent\n\n const vbaseFileName = body.source_string_id\n const stringCrowdinId = await vbase.getJSON<any>(CROWDIN_BUCKET, vbaseFileName, true)\n const stringId = stringCrowdinId.crowdinId\n const srcMessageInfoFromCrowdin = await crowdin.getString(stringId, body.project_id)\n if(srcMessageInfoFromCrowdin.err) {\n logger.error(srcMessageInfoFromCrowdin.err)\n return\n }\n if(!(srcMessageInfoFromCrowdin.res as CrowdinGetStringResponse).data) {\n logger.error('Unexpected data format returned from Crowdin')\n return\n }\n const srcMessage = (srcMessageInfoFromCrowdin.res as CrowdinGetStringResponse).data.text\n const groupContext = (srcMessageInfoFromCrowdin.res as CrowdinGetStringResponse).data.context\n\n const targetMessageCrowdinId = body.translation_id\n const targetMessageInfoFromCrowdin = await crowdin.getTranslation(targetMessageCrowdinId, body.project_id)\n if(targetMessageInfoFromCrowdin.err) {\n logger.error(targetMessageInfoFromCrowdin.err)\n return\n }\n if(!(targetMessageInfoFromCrowdin.res as CrowdinGetTranslationResponse).data) {\n logger.error('Unexpected data format returned from Crowdin')\n return\n }\n const targetMessage = (targetMessageInfoFromCrowdin.res as CrowdinGetTranslationResponse).data.text\n\n const crowdinProjectsIdsArray = toPairs(crowdinProjectsIds)\n const maybeProject = crowdinProjectsIdsArray.filter(([_, projectId]) => body.project_id === projectId)\n let srcLang\n if(isEmpty(maybeProject)) {\n const projectInfoFromCrowdin = await crowdin.getProject(body.project_id)\n if(projectInfoFromCrowdin.err) {\n logger.error(projectInfoFromCrowdin.err)\n return\n }\n srcLang = (projectInfoFromCrowdin.res as CrowdinGetProjectResponse).data.sourceLanguageId\n } else {\n srcLang = maybeProject[0][0]\n }\n\n const targetLang = body.language\n\n ctx.state = {\n groupContext,\n srcLang,\n srcMessage,\n targetLang,\n targetMessage,\n }\n await next()\n}\n\n```"
}
] |
code_crowdin-integration_1a7c7441
|
[
{
"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 crowdin-integration/node/utils/crowdin.ts from the crowdin-integration VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { objToHash } from '.'\nimport { Crowdin } from '../clients/Crowdin'\nimport { CrowdinListProjects } from '../typings/Crowdin'\n\nexport const toCrowdinFilePath = (groupContext: string) => {\n let dirPath = ''\n if (groupContext.toLowerCase().startsWith('product')){\n dirPath = 'Catalog/Products/'\n }\n if (groupContext.toLowerCase().startsWith('sku')){\n dirPath = 'Catalog/SKUs/'\n }\n if (groupContext.toLowerCase().startsWith('brand')){\n dirPath = 'Catalog/Brands/'\n }\n if (groupContext.toLowerCase().startsWith('category')){\n dirPath = 'Catalog/Categories/'\n }\n if (groupContext.toLowerCase().startsWith('specification')){\n dirPath = 'Catalog/'\n }\n\n return {\n dirPath,\n fileName: `${groupContext}.json`,\n }\n}\n\nexport const toVbaseSourceCrowdinFileName = (dirPath: string, fileName: string) => {\n const filePath = `${dirPath}${fileName}`\n return `${objToHash<string>(filePath)}.json`\n}\n\nexport function languageLocaleToCrowdinLanguageId(lang: string): string {\n switch (lang) {\n case 'en-DV':\n return 'en'\n case 'ja-JP':\n return 'ja'\n default:\n return lang\n }\n}\n\nexport async function languageLocaleToCrowdinProjectId(crowdin: Crowdin, languageLocale: string) {\n const crowdinLangId = languageLocaleToCrowdinLanguageId(languageLocale)\n\n if(crowdinProjectsIds[crowdinLangId]) {\n return {value: crowdinProjectsIds[crowdinLangId], err: null}\n } else {\n const projectsInfoObj = await crowdin.listProjects()\n if(projectsInfoObj.err) {\n return {value: null, err: 'Error getting projects list for account'}\n }\n const projectsInfo = (projectsInfoObj.res as CrowdinListProjects).data\n const projectBySrcLang = projectsInfo.filter((projectInfo) => projectInfo.data.sourceLanguageId === crowdinLangId)\n if(projectBySrcLang.length === 0) {\n return {value: null, err: `There is not a project with source language ${crowdinLangId} in Crowdin. You need to create it before saving strings in that language.`}\n }\n projectsInfo.map((project) => crowdinProjectsIds[project.data.sourceLanguageId] = project.data.id)\n\n return {value: projectBySrcLang[0].data.id, err: null}\n }\n}\n\nexport const crowdinSettings = { tokenApiV2: '' }\nexport const crowdinProjectsIds = {} as Record<string, string>\n\n```"
}
] |
code_crowdin-integration_88f34f64
|
[
{
"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 crowdin-integration/node/utils/constants.ts from the crowdin-integration VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nexport const CROWDIN_BUCKET = 'crowdin'\nexport const FILE_NOT_FOUND = 8\nexport const DIRECTORY_ALREADY_EXISTS = 50\nexport const STRING_ALREADY_EXPORTED_MESSAGE = 'Invalid identifier given. Identifier must be unique'\nexport const APP_ID = process.env.VTEX_APP_ID!\n\n\n```"
}
] |
code_crowdin-integration_e444267b
|
[
{
"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 crowdin-integration/node/utils/index.ts from the crowdin-integration VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport * as crypto from 'crypto'\n\nexport const objToHash = <T>(obj: T) =>\n crypto\n .createHash('md5')\n .update(JSON.stringify(obj))\n .digest('hex')\n\n```"
}
] |
code_crowdin-integration_2d0b9f8f
|
[
{
"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 crowdin-integration/node/events/settings.ts from the crowdin-integration VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { ColossusEventContext } from '../typings/Colossus'\nimport { APP_ID } from '../utils/constants'\nimport { crowdinSettings } from './../utils/crowdin'\n\nexport async function getSettings(ctx: Context | ColossusEventContext, next: () => Promise<any>) {\n const {clients: { apps }} = ctx\n\n if(!crowdinSettings.tokenApiV2) {\n const appSettings = await apps.getAppSettings(`${APP_ID}`)\n crowdinSettings.tokenApiV2 = appSettings.CrowdinAPIToken\n }\n\n await next()\n}\n\n```"
}
] |
code_crowdin-integration_7b4b5626
|
[
{
"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 crowdin-integration/node/events/export.ts from the crowdin-integration VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { TooManyRequestsError } from '@vtex/api'\n\nimport { ColossusEventContext } from '../typings/Colossus'\nimport { ExportedMessageObject } from '../typings/Messages'\nimport { objToHash } from '../utils'\nimport { CROWDIN_BUCKET, STRING_ALREADY_EXPORTED_MESSAGE } from '../utils/constants'\nimport { languageLocaleToCrowdinLanguageId, languageLocaleToCrowdinProjectId } from '../utils/crowdin'\n\ninterface ExportErrors {\n type: 'string' | 'translation'\n from: string\n to: string\n string: string\n status: string\n projectId?: string\n originalStringId?: number\n}\n\nexport async function saveInCrowdin(ctx: ColossusEventContext, next: () => Promise<any>) {\n const { crowdin, vbase } = ctx.clients\n const { logger } = ctx.vtex\n const { finished, messages } = ctx.body as ExportedMessageObject\n const errors = [] as ExportErrors[]\n\n if(!finished) {\n await Promise.all(messages.map(async ({srcLang, context, groupContext, translations}) => {\n const crowdinGroupContext = groupContext ? groupContext : ''\n const crowdinContext = context ? context : ''\n const projectId = await languageLocaleToCrowdinProjectId(crowdin, srcLang)\n let stringCrowdinId = 0\n let shouldLogError = true\n\n await Promise.all(translations.map(async ({ lang, translation }) => {\n shouldLogError = true\n if(srcLang === lang) {\n if(projectId.err) {\n errors.push({type: 'string', string: translation, from: lang, to: lang, status: `Error getting projectId. Returned error: ${projectId.err}`})\n } else if (projectId.value) {\n const key = objToHash<string>(translation + crowdinContext + srcLang)\n const saveMessageInCrowdin = await crowdin.addString({message: translation, key, groupContext: crowdinGroupContext}, projectId.value)\n if(saveMessageInCrowdin.err) {\n const statusCode = (saveMessageInCrowdin.err as any).status\n const errorMessage = (saveMessageInCrowdin.err as any).data.errors[0].error.errors[0].message\n if(errorMessage === STRING_ALREADY_EXPORTED_MESSAGE) {\n shouldLogError = false\n } else {\n errors.push({type: 'string', string: translation, from: lang, to: lang, status: errorMessage, projectId: projectId.value})\n }\n if (statusCode === 429) {\n throw new TooManyRequestsError()\n }\n }\n if(saveMessageInCrowdin.res) {\n stringCrowdinId = saveMessageInCrowdin.res.data.id\n const vbaseFileName = key\n await vbase.saveJSON(CROWDIN_BUCKET, vbaseFileName, {crowdinId: stringCrowdinId})\n }\n }\n }\n }))\n\n await Promise.all(translations.map(async ({lang, translation}) => {\n if(srcLang !== lang) {\n const to = languageLocaleToCrowdinLanguageId(lang)\n if(projectId.err) {\n errors.push({type: 'translation', string: translation, from: srcLang, to, status: `Error getting projectId. Returned error: ${projectId.err}`})\n } else if (projectId.value) {\n if(stringCrowdinId) {\n const saveTranslationsInCrowdin = await crowdin.addTranslation({translation, to, stringId: stringCrowdinId}, projectId.value)\n if(saveTranslationsInCrowdin.err) {\n const statusCode = (saveTranslationsInCrowdin.err as any).status\n const errorMessage = (saveTranslationsInCrowdin.err as any).data.errors[0].error.errors[0].message\n errors.push({type: 'translation', string: translation, from: srcLang, to, status: errorMessage, originalStringId: stringCrowdinId, projectId: projectId.value})\n if (statusCode === 429) {\n throw new TooManyRequestsError()\n }\n }\n } else if(shouldLogError){\n errors.push({type: 'translation', string: translation, from: srcLang, to, status: 'Cannot get the Crowdin id of original string', projectId: projectId.value})\n }\n }\n }\n }))\n\n }))\n }\n\n logger.error(errors)\n\n await next()\n}\n\n```"
}
] |
code_crowdin-integration_62e82006
|
[
{
"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 crowdin-integration/node/events/crowdinAPI/unwrap.ts from the crowdin-integration VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { SaveArgsV2 as MessagesObject } from '@vtex/api'\nimport { reduce } from 'ramda'\n\nimport { ColossusEventContext } from '../../typings/Colossus'\nimport { MessagesCrowdinByGroupContextAndSrcLang } from '../../typings/Messages'\nimport { objToHash } from '../../utils'\nimport { languageLocaleToCrowdinLanguageId } from '../../utils/crowdin'\n\nexport async function unwrap(ctx: ColossusEventContext, next: () => Promise<any>){\n const messagesObject = ctx.body as MessagesObject\n const to = languageLocaleToCrowdinLanguageId(messagesObject.to)\n const messages = messagesObject.messages.map((message) => {\n message.srcLang = languageLocaleToCrowdinLanguageId(message.srcLang)\n return message\n })\n if(!messages || ! to) {\n return\n }\n\n const messagesCrowdinByGroupContextAndSrcLang = reduce(\n (acc, {srcLang, srcMessage, targetMessage, groupContext = 'Sorted', context}) => {\n const messageHash = objToHash<string>(srcMessage + (context || '') + srcLang)\n if(!acc[groupContext]) {\n acc[groupContext] = {}\n }\n acc[groupContext][srcLang] = {\n ...acc[groupContext][srcLang],\n [messageHash] : {\n message: targetMessage,\n srcMessage,\n ...context && {description: context},\n },\n }\n return acc\n },\n {} as MessagesCrowdinByGroupContextAndSrcLang,\n messages\n )\n\n ctx.state.messagesCrowdinByGroupContextAndSrcLang = messagesCrowdinByGroupContextAndSrcLang\n ctx.state.to = to\n\n await next()\n}\n\n\n```"
}
] |
code_crowdin-integration_3288726c
|
[
{
"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 crowdin-integration/node/events/crowdinAPI/update.ts from the crowdin-integration VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { TooManyRequestsError } from '@vtex/api'\nimport { map as mapP } from 'bluebird'\nimport { map, toPairs } from 'ramda'\n\nimport { ColossusEventContext } from '../../typings/Colossus'\nimport { UpdateMessageToCrowdinArg } from '../../typings/Messages'\nimport { objToHash } from '../../utils'\nimport { CROWDIN_BUCKET, STRING_ALREADY_EXPORTED_MESSAGE } from '../../utils/constants'\nimport { languageLocaleToCrowdinProjectId } from '../../utils/crowdin'\n\nconst updateStringBasedCrowdinString = async (args: UpdateMessageToCrowdinArg, {clients: {crowdin, vbase}, vtex: {logger}}: ColossusEventContext, srcLang: string) => {\n const messagesInPairs = toPairs(args.messages)\n const groupContext = args.groupContext ? args.groupContext : ''\n map(async ([key, {message}]) => {\n const projectId = await languageLocaleToCrowdinProjectId(crowdin, srcLang)\n if (projectId.err) {\n logger.error(projectId.err)\n } else if (projectId.value) {\n const saveMessageInCrowdin = await crowdin.addString({message, key, groupContext}, projectId.value)\n if(saveMessageInCrowdin.err) {\n const statusCode = (saveMessageInCrowdin.err as any).status\n const errorMessage = (saveMessageInCrowdin.err as any).data.errors ? (saveMessageInCrowdin.err as any).data.errors[0].error.errors[0].message : ''\n if(errorMessage !== STRING_ALREADY_EXPORTED_MESSAGE) {\n logger.error(saveMessageInCrowdin.err)\n }\n if (statusCode === 429) {\n throw new TooManyRequestsError()\n }\n } else {\n const stringCrowdinId = saveMessageInCrowdin.res.data.id\n if(stringCrowdinId) {\n const vbaseFileName = key\n await vbase.saveJSON<any>(CROWDIN_BUCKET, vbaseFileName, {crowdinId: stringCrowdinId})\n }\n }\n }\n }, messagesInPairs)\n}\n\nconst updateStringBasedCrowdinTranslation = async (args: UpdateMessageToCrowdinArg, {clients: {crowdin, vbase}, vtex: {logger}}: ColossusEventContext, srcLang: string) => {\n const messagesInPairs = toPairs(args.messages)\n map(async ([_, {message, srcMessage, description}]) => {\n const context = description ? description : ''\n const vbaseFileName = objToHash<string>(srcMessage + (context || '') + args.from)\n const stringCrowdinId = await vbase.getJSON<any>(CROWDIN_BUCKET, vbaseFileName, true)\n const projectId = await languageLocaleToCrowdinProjectId(crowdin, srcLang)\n if (projectId.err) {\n logger.error(projectId.err)\n } else if (projectId.value) {\n const saveTranslationsInCrowdin = await crowdin.addTranslation({translation: message, to: args.to!, stringId: stringCrowdinId.crowdinId}, projectId.value)\n if(saveTranslationsInCrowdin.err) {\n const statusCode = (saveTranslationsInCrowdin.err as any).status\n logger.error(saveTranslationsInCrowdin.err)\n if (statusCode === 429) {\n throw new TooManyRequestsError()\n }\n }\n }\n }, messagesInPairs)\n}\n\nexport async function updateCrowdinProject(ctx: ColossusEventContext, next: () => Promise<any>){\n const {to, messagesCrowdinByGroupContextAndSrcLang} = ctx.state\n const messagesCrowdinByGroupContextPairs = toPairs(messagesCrowdinByGroupContextAndSrcLang)\n\n await mapP(\n messagesCrowdinByGroupContextPairs,\n ([groupContext, messagesBySrcLang]) => {\n const messagesBySrcLangPairs = toPairs(messagesBySrcLang)\n map(\n ([srcLang, messages]) => {\n (srcLang === to) ?\n updateStringBasedCrowdinString({messages, groupContext, from: srcLang}, ctx, srcLang) :\n updateStringBasedCrowdinTranslation({messages, groupContext, to, from: srcLang}, ctx, srcLang)\n },\n messagesBySrcLangPairs\n )\n }\n )\n\n await next()\n}\n\n```"
}
] |
code_google-analytics_b1ce616b
|
[
{
"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 google-analytics/docs/README.md from the google-analytics VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```markdown\n# DEPRECATED\n\nPlease use Google Tag Manager pixel instead.\n```"
}
] |
code_google-analytics_34999304
|
[
{
"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 google-analytics/react/index.tsx from the google-analytics VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport { orderPlaced } from './events/commonEvents'\nimport {\n addToCart,\n productDetail,\n productClick,\n productImpression,\n purchase,\n removeFromCart,\n Impression,\n} from './events/enhancedCommerce'\n\nlet currentUrl = ''\n\ninterface EventData {\n event: string\n eventName: string\n currency: string\n}\n\ninterface PageViewData extends EventData {\n pageTitle: string\n pageUrl: string\n}\n\n// Common pageview function\nconst pageView = (origin: string, data: PageViewData) => {\n if (!data.pageUrl || data.pageUrl === currentUrl) {\n return\n }\n\n currentUrl = data.pageUrl\n ga('set', {\n location: currentUrl,\n page: currentUrl.replace(origin, ''),\n ...(data.pageTitle && {\n title: data.pageTitle,\n }),\n })\n ga('send', 'pageview')\n}\n\nfunction listener(e: MessageEvent) {\n // Event listener for productDetail\n if (e.data.event === 'productView') {\n productDetail(e.data.product)\n return\n }\n\n // Event listener for productClick\n if (e.data.event === 'productClick') {\n const prodData = e.data.product\n const skuId = prodData && prodData.sku && prodData.sku.itemId\n const selectedProduct = {\n ...e.data.product,\n selectedSku: skuId,\n }\n productClick(selectedProduct)\n return\n }\n\n // Event listener for productImpression\n if (e.data.event === 'productImpression') {\n const {\n product: oldFormatProduct,\n position: oldFormatPosition,\n impressions,\n } = e.data\n let parsedImpressions: Impression[] = []\n if (oldFormatProduct != null && oldFormatPosition !== null) {\n const skuId =\n oldFormatProduct && oldFormatProduct.sku && oldFormatProduct.sku.itemId\n const newProduct = { ...oldFormatProduct, selectedSku: skuId }\n parsedImpressions = [{ product: newProduct, position: oldFormatPosition }]\n }\n\n if (impressions != null) {\n parsedImpressions = impressions.map(({ product }: Impression) => {\n const skuId = product && product.sku && product.sku.itemId\n return { ...product, selectedSku: skuId }\n })\n }\n\n productImpression(parsedImpressions, e.data.list)\n return\n }\n\n // Event listener for orderPlaced\n if (e.data.event === 'orderPlaced') {\n orderPlaced(e.data)\n purchase(e.data)\n return\n }\n\n if (e.data.event === 'pageView') {\n pageView(e.origin, e.data)\n return\n }\n\n if (e.data.event === 'addToCart') {\n e.data.items.forEach((product: any) => {\n product.productName = product.name\n addToCart(product, product.price, product.quantity)\n })\n return\n }\n\n if (e.data.event === 'removeFromCart') {\n e.data.items.forEach((product: any) => {\n product.productId = product.id\n product.productName = product.name\n removeFromCart(product, product.sellingPrice)\n })\n return\n }\n}\n\n// Event listener for pageview\nwindow.addEventListener('message', listener)\n\n```"
}
] |
code_google-analytics_477ba8c5
|
[
{
"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 google-analytics/react/tests-setup.js from the google-analytics VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```javascript\n/* eslint-disable */\nwindow.matchMedia = window.matchMedia || function() {\n return {\n matches: false,\n addListener: function() {},\n removeListener: function() {},\n }\n}\n\n```"
}
] |
code_google-analytics_fc0dacd7
|
[
{
"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 google-analytics/react/package.json from the google-analytics VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"name\": \"vtex.google-analytics\",\n \"description\": \"Google Analytics Pixel App\",\n \"scripts\": {\n \"test\": \"jest\"\n },\n \"author\": \"VTEX\",\n \"license\": \"ISC\",\n \"devDependencies\": {\n \"@types/node\": \"^10.12.18\",\n \"eslint\": \"^5.15.1\",\n \"eslint-config-vtex\": \"^10.1.0\",\n \"identity-obj-proxy\": \"^3.0.0\",\n \"tslint\": \"^5.11.0\",\n \"tslint-config-vtex\": \"^2.0.0\",\n \"tslint-eslint-rules\": \"^5.4.0\",\n \"typescript\": \"3.5.2\"\n },\n \"jest\": {\n \"verbose\": true,\n \"transform\": {\n \"^.+\\\\.(js|jsx|mjs)$\": \"<rootDir>/node_modules/babel-jest\"\n },\n \"transformIgnorePatterns\": [\n \"[/\\\\\\\\]node_modules[/\\\\\\\\].+\\\\.(js|jsx|mjs)$\"\n ],\n \"setupFiles\": [\n \"./tests-setup.js\"\n ],\n \"moduleNameMapper\": {\n \"\\\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$\": \"<rootDir>/__test__/fileMock.js\",\n \"\\\\.(css|less|scss)$\": \"identity-obj-proxy\"\n }\n },\n \"dependencies\": {\n \"@types/google.analytics\": \"0.0.39\"\n },\n \"version\": \"1.1.0\"\n}\n\n```"
}
] |
code_google-analytics_589612ba
|
[
{
"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 google-analytics/react/utils.tsx from the google-analytics VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nexport const getCategory = (rawCategories: string[]) => {\n if (!rawCategories || !rawCategories.length) return\n\n const _filterEmpty = (string: string) => {\n if (string.length > 0) return string\n }\n\n const categories = rawCategories.map(function (categoryPath: string) {\n let splitedPath = categoryPath.split('/').filter(_filterEmpty)\n return splitedPath[0]\n })\n\n return categories ? categories[0] : categories\n}\n\n```"
}
] |
code_google-analytics_78cdf405
|
[
{
"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 google-analytics/react/typings/global.d.ts from the google-analytics VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\ninterface Window extends Window {\n ga: Function\n}\n\n```"
}
] |
code_google-analytics_c1ed2529
|
[
{
"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 google-analytics/react/events/commonEvents.ts from the google-analytics VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\n// Common OrderPlaced function\nexport const orderPlaced = (order: any) => {\n ga('send', 'event', {\n eventAction: 'view',\n eventCategory: 'orderPlaced',\n ...order,\n })\n}\n\n```"
}
] |
code_google-analytics_af50249a
|
[
{
"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 google-analytics/react/events/enhancedCommerce.ts from the google-analytics VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { getCategory } from './../utils'\n\ninterface Item {\n itemId: string\n name: string\n}\n\nexport interface Product {\n brand: string\n categoryId: string\n categories: string[]\n productId: string\n productName: string\n selectedSku: string\n items: Item[]\n variant: string\n sku: any\n}\n\nexport interface Impression {\n product: Product\n position: number\n}\n\nconst getSkuName = (selectedSku: string, items: Item[]) =>\n (items.find((item: Item) => selectedSku === item.itemId) || ({} as Item)).name\n\n/** Product viewed event\n * https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#measuring-actvities\n */\nexport const productDetail = (product: Product) => {\n if (!product) return\n\n const category = getCategory(product.categories)\n\n ga('ec:addProduct', {\n brand: product.brand,\n category: category,\n id: product.productId,\n name: product.productName,\n variant: getSkuName(product.selectedSku, product.items),\n })\n ga('ec:setAction', 'detail')\n ga('send', 'event', {\n eventAction: 'Detail',\n eventCategory: 'Ecommerce',\n nonInteraction: 1,\n })\n}\n\n/** Product clicked event\n * https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#product-click\n */\nexport const productClick = (product: Product) => {\n if (!product) return\n\n const category = getCategory(product.categories)\n\n ga('ec:addProduct', {\n id: product.productId,\n name: product.productName,\n category: category,\n brand: product.brand,\n variant: getSkuName(product.selectedSku, product.items),\n })\n ga('ec:setAction', 'click')\n ga('send', 'event', {\n eventAction: 'Click',\n eventCategory: 'Product',\n })\n}\n\n/** Product Impression event\n * https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#product-impression\n */\nexport const productImpression = (impressions: Impression[], list: string) => {\n impressions.forEach(({ product, position }) => {\n if (!product) return\n\n const category = getCategory(product.categories)\n\n ga('ec:addImpression', {\n id: product.productId,\n name: product.productName,\n category: category,\n brand: product.brand,\n variant: getSkuName(product.selectedSku, product.items),\n list: list,\n position: position,\n })\n ga('send', 'event', {\n eventAction: 'Impression',\n eventCategory: 'Product',\n nonInteraction: 1,\n })\n })\n}\n\n/** Addition to cart events\n * https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#add-remove-cart\n */\nexport const addToCart = (\n product: Product,\n price: number,\n quantity: number\n) => {\n if (!product) return\n\n ga('ec:addProduct', {\n name: product.productName,\n brand: product.brand,\n variant: product.variant,\n price,\n quantity,\n })\n ga('ec:setAction', 'add')\n ga('send', 'event', {\n eventAction: 'Click',\n eventCategory: 'Add to cart',\n })\n}\n\n/** Removal from cart events\n * https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#add-remove-cart\n */\nexport const removeFromCart = (product: Product, price: number) => {\n if (!product) return\n\n ga('ec:addProduct', {\n id: product.productId,\n name: product.productName,\n price,\n })\n ga('ec:setAction', 'remove')\n ga('send', 'event', {\n eventAction: 'Click',\n eventCategory: 'Remove from cart',\n })\n}\n\n/** Purchase event\n * https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#measuring-transaction\n */\nexport const purchase = (order: any) => {\n order.transactionProducts.map((product: any) => {\n ga('ec:addProduct', {\n brand: product.brand,\n category: product.category,\n id: product.id,\n name: product.name,\n price: product.sellingPrice,\n quantity: product.quantity,\n variant: product.skuName,\n })\n })\n\n ga('ec:setAction', 'purchase', {\n affiliation: order.transactionAffiliation,\n coupon: order.coupon,\n id: order.orderGroup,\n revenue: order.transactionTotal,\n shipping: order.transactionShipping,\n tax: order.transactionTax,\n })\n\n ga('send', 'event', {\n eventAction: 'Purchase',\n eventCategory: 'Ecommerce',\n nonInteraction: 1,\n })\n}\n\n```"
}
] |
code_orders-tracking-example_0a7c1dbb
|
[
{
"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 orders-tracking-example/docs/README.md from the orders-tracking-example VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```markdown\n# Orders Tracking Example\n\nA boilerplate app implementing an event handler receiving invoice/tracking notifications from OMS.\n\n## How to Use\n\nThis app handles events sent by the app `vtex.sno`, as you can see by looking at `node/service.json`.\n\n```json\n{\n \"memory\": 256,\n \"ttl\": 10,\n \"timeout\": 2,\n \"minReplicas\": 2,\n \"maxReplicas\": 4,\n \"workers\": 1,\n \"events\": {\n \"snoHandler\": {\n \"sender\": \"vtex.sno\",\n \"topics\": [\"invoice-notification\"]\n }\n }\n}\n```\n\nNormally `vtex.sno` sends events only in `master` workspace. If you want to use it in a developer workspace, you have to do the following:\n\n1. Create your development workspace by running `vtex use {workspaceName}`\n2. Go to `https://{accountName}.myvtex.com/admin/apps/vtex.sno/setup`\n3. Change the `Target Workspace` variable to the name of the workspace you have created previously.\n4. Now you can link this app (`vtex.sno`) in your desired workspace and receive order status updates.\n\nHere is an example body that you can expect to receive:\n\n```json\n{\n \"recorder\": {\n \"_record\": {\n \"x-vtex-meta\": {},\n \"x-vtex-meta-bucket\": {}\n }\n },\n \"invoiceNumber\": \"691\",\n \"trackingNumber\": null,\n \"trackingUrl\": null,\n \"invoiceKey\": null,\n \"courier\": null,\n \"orderId\": \"00-v70368842atmc-01\",\n \"type\": \"Output\",\n \"eventType\": \"InvoiceNotification\",\n \"eventId\": \"01ac8957-f5b1-48b8-b865-33811d154791_00-v70368842atmc-01_691_InvoiceNotification_0\"\n}```\n\nIf you want to understand further how invoices work, check out [this documentation](https://developers.vtex.com/reference/tracking#updatetrackingstatus).\n\n```"
}
] |
code_orders-tracking-example_1defbc38
|
[
{
"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 orders-tracking-example/node/service.json from the orders-tracking-example 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 \"events\": {\n \"snoHandler\": {\n \"sender\": \"vtex.sno\",\n \"topics\": [\"invoice-notification\"]\n }\n }\n}\n\n```"
}
] |
code_orders-tracking-example_0551fc53
|
[
{
"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 orders-tracking-example/node/package.json from the orders-tracking-example 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 },\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 \"@vtex/api\": \"6.35.0\",\n \"@vtex/test-tools\": \"^1.0.0\",\n \"tslint\": \"^5.14.0\",\n \"tslint-config-vtex\": \"^2.1.0\",\n \"typescript\": \"3.8.3\"\n },\n \"scripts\": {\n \"lint\": \"tsc --noEmit --pretty && tslint -c tslint.json --fix './**/*.ts'\"\n },\n \"version\": \"0.2.0\"\n}\n\n```"
}
] |
code_orders-tracking-example_a9825e57
|
[
{
"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 orders-tracking-example/node/index.ts from the orders-tracking-example VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport {\n ClientsConfig,\n LRUCache,\n Service,\n ServiceContext,\n RecorderState,\n EventContext,\n} from '@vtex/api'\n\nimport { Clients } from './clients'\nimport { snoHandler } from './middlewares/snoHandler'\nimport { EventType } from './typings/notification'\n\nconst TIMEOUT_MS = 800\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 })\nmetrics.trackCache('status', memoryCache)\n\n// This is the configuration for clients available in `ctx.clients`.\nconst clients: ClientsConfig<Clients> = {\n // We pass our custom implementation of the clients bag, containing the Status client.\n implementation: Clients,\n options: {\n // All IO Clients will be initialized with these options, unless otherwise specified.\n default: {\n retries: 2,\n timeout: TIMEOUT_MS,\n },\n // This key will be merged with the default options and add this cache to our Status client.\n status: {\n memoryCache,\n },\n },\n}\n\ndeclare global {\n type Context = ServiceContext<Clients, State>\n\n interface NotificationContext extends EventContext<Clients> {\n body: {\n type: string,\n invoiceNumber: string,\n trackingNumber: string,\n trackingUrl: string,\n courier: string,\n orderId: string,\n eventType: EventType,\n eventId: string,\n invoiceKey: string\n }\n }\n // The shape of our State object found in `ctx.state`. This is used as state bag to communicate between middlewares.\n interface State extends RecorderState {}\n}\n\n// Export a service that defines route handlers and client options.\nexport default new Service({\n clients,\n events: {\n snoHandler\n },\n})\n\n```"
}
] |
code_orders-tracking-example_b5b5e568
|
[
{
"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 orders-tracking-example/node/clients/index.ts from the orders-tracking-example VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { IOClients } from \"@vtex/api\";\n\n// Extend the default IOClients implementation with our own custom clients.\nexport class Clients extends IOClients {}\n\n```"
}
] |
code_orders-tracking-example_7b8cf954
|
[
{
"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 orders-tracking-example/node/typings/notification.ts from the orders-tracking-example VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nexport enum EventType {\n SHIPPING = 'ShippingNotification',\n INVOICE = 'InvoiceNotification',\n INVOICE_STATUS_POOLING = 'InvoiceStatusPooling',\n SHIPPING_STATUS_CHANGED = 'ShippingStatusChanged'\n}\n\n```"
}
] |
code_orders-tracking-example_dd1a5999
|
[
{
"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 orders-tracking-example/node/middlewares/snoHandler.ts from the orders-tracking-example VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nexport async function snoHandler(\n ctx: NotificationContext,\n next: () => Promise<any>\n) {\n console.log(ctx.body)\n await next()\n}\n\n```"
}
] |
code_freshchat_735f6e51
|
[
{
"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 freshchat/docs/README.md from the freshchat VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```markdown\n# FreshChat\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.freshchat-pixel@1.x\n```\n\nNext, open the app settings on your admin and fill the form with Site ID.\n\n```"
}
] |
code_freshchat_e5c56c0a
|
[
{
"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 freshchat/react/index.tsx from the freshchat VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport { canUseDOM } from 'vtex.render-runtime'\nimport { PixelMessage } from './typings/events'\n\nexport function handleEvents(e: PixelMessage) {\n switch (e.data.eventName) {\n case 'vtex:pageView': {\n\n }\n default: {\n return\n }\n }\n}\n\nif (canUseDOM) {\n window.addEventListener('message', handleEvents)\n}\n\n```"
}
] |
code_freshchat_98417825
|
[
{
"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 freshchat/react/package.json from the freshchat VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"scripts\": {\n \"test\": \"vtex-test-tools test\"\n },\n \"dependencies\": {\n \"ramda\": \"^0.26.1\"\n },\n \"devDependencies\": {\n \"@types/graphql\": \"^14.5.0\",\n \"@types/jest\": \"^24.0.11\",\n \"@types/node\": \"^11.13.0\",\n \"@types/ramda\": \"^0.26.5\",\n \"@vtex/test-tools\": \"^1.1.0\",\n \"eslint\": \"^5.16.0\",\n \"eslint-config-vtex-react\": \"^4.1.0\",\n \"graphql\": \"^14.5.4\",\n \"prettier\": \"^1.18.2\",\n \"tslint-eslint-rules\": \"^5.4.0\",\n \"typescript\": \"3.5.2\"\n },\n \"version\": \"1.0.1\"\n}\n\n```"
}
] |
code_freshchat_b54fa374
|
[
{
"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 freshchat/store/interfaces.json from the freshchat VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"pixel.freshchat-pixel\": {\n \"component\": \"index\"\n }\n}\n\n```"
}
] |
code_freshchat_e4fc8070
|
[
{
"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 freshchat/react/typings/events.d.ts from the freshchat VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nexport interface PixelMessage extends MessageEvent {\n data:\n | ProductViewData\n | ProductClickData\n | OrderPlacedData\n | PageViewData\n | ProductImpressionData\n | AddToCartData\n | RemoveToCartData\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_freshchat_14ca5fec
|
[
{
"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 freshchat/react/typings/vtex.render-runtime.d.ts from the freshchat 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_freshchat_5cc686cb
|
[
{
"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 freshchat/react/typings/global.d.ts from the freshchat VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\ninterface Window extends Window {\n dataLayer: any[]\n}\n\n```"
}
] |
code_iframe_57c9869b
|
[
{
"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 iframe/messages/pt.json from the iframe VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"editor.iframe.title\": \"Iframe\",\n \"editor.iframe.src.description\": \"Endereço de origem do iframe\",\n \"editor.iframe.src.title\": \"Src\",\n \"editor.iframe.height.title\": \"Altura\",\n \"editor.iframe.width.title\": \"Comprimento\",\n \"editor.iframe.id.title\": \"ID\",\n \"editor.iframe.className.title\": \"className\",\n \"editor.iframe.onLoad.title\": \"onLoad\",\n \"editor.dynamiciframe.id.title\": \"ID\",\n \"editor.dynamiciframe.className.title\": \"className\",\n \"editor.dynamiciframe.onLoad.title\": \"onLoad\",\n \"editor.iframe.title.title\": \"Title\",\n \"editor.iframe.allow.title\": \"Allow\",\n \"editor.dynamiciframe.title\": \"Dynamic Iframe\",\n \"editor.dynamiciframe.title.title\": \"Title\",\n \"editor.dynamiciframe.srcPrepend.description\": \"iframe source url pre-pended string\",\n \"editor.dynamiciframe.srcPrepend.title\": \"Prepend\",\n \"editor.dynamiciframe.srcAppend.description\": \"iframe source url appended string\",\n \"editor.dynamiciframe.srcAppend.title\": \"Append\",\n \"editor.dynamiciframe.height.title\": \"Height\",\n \"editor.dynamiciframe.width.title\": \"Width\",\n \"editor.dynamiciframe.allow.title\": \"Allow\"\n}\n\n```"
}
] |
code_iframe_0fcb482b
|
[
{
"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 iframe/messages/en.json from the iframe VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"editor.iframe.title\": \"Iframe\",\n \"editor.iframe.src.description\": \"Source url of the iframe\",\n \"editor.iframe.src.title\": \"Src\",\n \"editor.iframe.height.title\": \"Height\",\n \"editor.iframe.width.title\": \"Width\",\n \"editor.iframe.title.title\": \"Title\",\n \"editor.iframe.allow.title\": \"Allow\",\n \"editor.iframe.id.title\": \"ID\",\n \"editor.iframe.className.title\": \"className\",\n \"editor.iframe.onLoad.title\": \"onLoad\",\n \"editor.dynamiciframe.id.title\": \"ID\",\n \"editor.dynamiciframe.className.title\": \"className\",\n \"editor.dynamiciframe.onLoad.title\": \"onLoad\",\n \"editor.dynamiciframe.title\": \"Dynamic Iframe\",\n \"editor.dynamiciframe.title.title\": \"Title\",\n \"editor.dynamiciframe.srcPrepend.description\": \"iframe source url pre-pended string\",\n \"editor.dynamiciframe.srcPrepend.title\": \"Prepend\",\n \"editor.dynamiciframe.srcAppend.description\": \"iframe source url appended string\",\n \"editor.dynamiciframe.srcAppend.title\": \"Append\",\n \"editor.dynamiciframe.height.title\": \"Height\",\n \"editor.dynamiciframe.width.title\": \"Width\",\n \"editor.dynamiciframe.allow.title\": \"Allow\"\n}\n\n```"
}
] |
code_iframe_b921e37e
|
[
{
"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 iframe/messages/context.json from the iframe VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"editor.iframe.title\": \"editor.iframe.title\",\n \"editor.iframe.src.description\": \"editor.iframe.src.description\",\n \"editor.iframe.src.title\": \"editor.iframe.src.title\",\n \"editor.iframe.height.title\": \"editor.iframe.height.title\",\n \"editor.iframe.width.title\": \"editor.iframe.width.title\",\n \"editor.iframe.title.title\": \"editor.iframe.title.title\",\n \"editor.iframe.allow.title\": \"editor.iframe.allow.title\",\n \"editor.iframe.id.title\": \"editor.iframe.id.title\",\n \"editor.iframe.className.title\": \"editor.iframe.className.title\",\n \"editor.iframe.onLoad.title\": \"editor.iframe.onLoad.title\",\n \"editor.dynamiciframe.title\": \"editor.dynamiciframe.title\",\n \"editor.dynamiciframe.title.title\": \"editor.dynamiciframe.title.title\",\n \"editor.dynamiciframe.srcPrepend.description\": \"editor.dynamiciframe.srcPrepend.description\",\n \"editor.dynamiciframe.srcPrepend.title\": \"editor.dynamiciframe.srcPrepend.title\",\n \"editor.dynamiciframe.srcAppend.description\": \"editor.dynamiciframe.srcAppend.description\",\n \"editor.dynamiciframe.srcAppend.title\": \"editor.dynamiciframe.srcAppend.title\",\n \"editor.dynamiciframe.height.title\": \"editor.dynamiciframe.height.title\",\n \"editor.dynamiciframe.width.title\": \"editor.dynamiciframe.width.title\",\n \"editor.dynamiciframe.allow.title\": \"editor.dynamiciframe.allow.title\",\n \"editor.dynamiciframe.id.title\": \"editor.dynamiciframe.id.title\",\n \"editor.dynamiciframe.className.title\": \"editor.dynamiciframe.className.title\",\n \"editor.dynamiciframe.onLoad.title\": \"editor.dynamiciframe.onLoad.title\"\n}\n\n```"
}
] |
code_iframe_35590ee1
|
[
{
"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 iframe/messages/es.json from the iframe VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"editor.iframe.title\": \"Iframe\",\n \"editor.iframe.src.description\": \"Dirección de origen del iframe\",\n \"editor.iframe.src.title\": \"Src\",\n \"editor.iframe.height.title\": \"Altura\",\n \"editor.iframe.width.title\": \"Longitud\",\n \"editor.iframe.id.title\": \"ID\",\n \"editor.iframe.className.title\": \"className\",\n \"editor.iframe.onLoad.title\": \"onLoad\",\n \"editor.dynamiciframe.id.title\": \"ID\",\n \"editor.dynamiciframe.className.title\": \"className\",\n \"editor.dynamiciframe.onLoad.title\": \"onLoad\",\n \"editor.iframe.title.title\": \"Title\",\n \"editor.iframe.allow.title\": \"Allow\",\n \"editor.dynamiciframe.title\": \"Dynamic Iframe\",\n \"editor.dynamiciframe.title.title\": \"Title\",\n \"editor.dynamiciframe.srcPrepend.description\": \"iframe source url pre-pended string\",\n \"editor.dynamiciframe.srcPrepend.title\": \"Prepend\",\n \"editor.dynamiciframe.srcAppend.description\": \"iframe source url appended string\",\n \"editor.dynamiciframe.srcAppend.title\": \"Append\",\n \"editor.dynamiciframe.height.title\": \"Height\",\n \"editor.dynamiciframe.width.title\": \"Width\",\n \"editor.dynamiciframe.allow.title\": \"Allow\"\n}\n\n```"
}
] |
code_iframe_87a6222d
|
[
{
"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 iframe/messages/ar.json from the iframe VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"editor.iframe.title\": \"اطار الموقع\",\n \"editor.iframe.src.description\": \"مصدر رابط محدد لأطار الموقع \",\n \"editor.iframe.src.title\": \"المصدر\",\n \"editor.iframe.height.title\": \"الطول\",\n \"editor.iframe.width.title\": \"العرض\",\n \"editor.iframe.title.title\": \"العنوان\",\n \"editor.iframe.allow.title\": \"السماح\",\n \"editor.iframe.id.title\": \"ID\",\n \"editor.iframe.className.title\": \"className\",\n \"editor.iframe.onLoad.title\": \"onLoad\",\n \"editor.dynamiciframe.id.title\": \"ID\",\n \"editor.dynamiciframe.className.title\": \"className\",\n \"editor.dynamiciframe.onLoad.title\": \"onLoad\",\n \"editor.dynamiciframe.title\": \"اطار مواقع ديناميكي\",\n \"editor.dynamiciframe.title.title\": \"العنوان\",\n \"editor.dynamiciframe.srcPrepend.description\": \"مصدر رابط اطار الموقع من السلسة الساقة\",\n \"editor.dynamiciframe.srcPrepend.title\": \"سلسلة سابقة\",\n \"editor.dynamiciframe.srcAppend.description\": \" مصدر رابط اطار الموقع من السلسة الساقة \",\n \"editor.dynamiciframe.srcAppend.title\": \"ارفق\",\n \"editor.dynamiciframe.height.title\": \"الطول\",\n \"editor.dynamiciframe.width.title\": \"العرض\",\n \"editor.dynamiciframe.allow.title\": \"السماح\"\n}\n\n```"
}
] |
code_iframe_6152f26b
|
[
{
"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 iframe/docs/README.md from the iframe VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```markdown\n📢 Use this project, [contribute](https://github.com/vtex-apps/iframe) to it or open issues to help evolve it using [Store Discussion](https://github.com/vtex-apps/store-discussion).\n\n# Iframe\n\n<!-- DOCS-IGNORE:start -->\n<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->\n\n[](#contributors-)\n\n<!-- ALL-CONTRIBUTORS-BADGE:END -->\n<!-- DOCS-IGNORE:end -->\n\nAn app that makes it possible to render external iframes on a store.\n\n\n\n## Configuration - standard Iframe\n\n1. Add the `vtex.iframe` to the theme's dependencies on the `manifest.json`\n\n```json\n\"dependencies\": {\n \"vtex.iframe\": \"0.x\"\n}\n```\n\n2. Add the interface `iframe` to any **custom page** (Iframes are not allowed outside custom pages).\n\n```json\n{\n \"store.custom#about-us\": {\n \"blocks\": [\"flex-layout.row#about-us\", \"iframe\"]\n },\n\n \"iframe\": {\n \"props\": {\n \"src\": \"\"\n }\n }\n}\n```\n\n| Prop name | Type | Description | Default value |\n| --------- | ------ | --------------------------------------- | ------------- |\n| `src` | String | Source address the iframe should render | `null` |\n| `width` | Number | Width attribute of the iframe | `null` |\n| `height` | Number | Height attribute of the iframe | `null` |\n| `allow` | String | allow attribute of the iframe | `null` |\n\n## Configuration - dynamic Iframe\n\n1. Add the `vtex.iframe` to the theme's dependencies on the `manifest.json`\n\n```json\n\"dependencies\": {\n \"vtex.iframe\": \"0.x\"\n}\n```\n\n2. Add the dynamicIframe block and its properties to the blocks.json file\n\n```json\n{\n \"store.custom#locationPage\": {\n \"children\": [\"iframe.dynamic-src\"]\n },\n \"iframe.dynamic-src\": {\n \"props\": {\n \"dynamicSrc\": \"https://www.test.com/exampleStaticPathName/{dynamicParam1}/{dynamicParam2}/exampleStaticPageName\",\n \"width\": \"1920\",\n \"height\": \"1000\",\n \"title\": \"exampleStaticPageName iframe wrapper for {account}\",\n \"allow\": \"geolocation\"\n }\n }\n}\n```\n\n3. register your new page in routes.json with appropriate parameters passed into the page url\n\n```json\n{\n \"store.custom#locationPage\": {\n \"path\": \"/:param1/:param2/pagename\"\n }\n}\n```\n\n| Prop name | Type | Description | Default value |\n| ------------ | ------ | ----------------------------------------------------------------- | ------------- |\n| `dynamicSrc` | String | iframe src with dynamic parameters from page URL enclosed in '{}' | `null` |\n| `width` | Number | Width attribute of the iframe | `null` |\n| `height` | Number | Height attribute of the iframe | `null` |\n| `title` | String | title attribute of the iframe | `null` |\n| `allow` | String | allow attribute of the iframe | `null` |\n| `id` | String | ID attribute of the iframe | `null` |\n| `className` | String | class attribute of the iframe | `null` |\n| `onLoad` | String | onLoad attribute of the iframe | `null` |\n| `srcAccount` | Object | Object with account name and src | `null` |\n\n### srcAccount\n\nUsing srcAccount\n\n```json\n \"iframe#logout\": {\n \"props\": {\n \"src\": \"//www.mywebsiteprod.com/logout\",\n \"srcAccount\": {\n \"mywebsiteprod\": \"//www.mywebsite.com/logout\",\n \"mywebsiteqa\": \"//qa.mywebsite.com/logout\"\n },\n \"onLoad\": \"setTimeout(() => {window.location.href='/'}, 5000)\",\n \"className\": \"iframeLogout\",\n \"id\": \"iframeLogout\"\n }\n },\n```\n\n## Customization\n\nThere is a `.container` handle that wraps the iframe, it's also possible to use `blockClass`.\n\n<!-- DOCS-IGNORE:start -->\n\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<!-- markdownlint-enable -->\n<!-- prettier-ignore-end -->\n\n<!-- ALL-CONTRIBUTORS-LIST:END -->\n\nThis project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!\n\n<!-- DOCS-IGNORE:end -->\n\n```"
}
] |
code_iframe_8fee608f
|
[
{
"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 iframe/react/package.json from the iframe VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"scripts\": {\n \"test\": \"vtex-test-tools test\",\n \"lint\": \"tsc --noEmit && eslint --ext ts,tsx .\"\n },\n \"dependencies\": {\n \"classnames\": \"^2.2.6\",\n \"ramda\": \"^0.26.1\",\n \"react\": \"^16.13.1\",\n \"react-dom\": \"^16.13.1\",\n \"react-intl\": \"^3.12.0\"\n },\n \"devDependencies\": {\n \"@apollo/react-testing\": \"^3.1.3\",\n \"@types/classnames\": \"^2.2.7\",\n \"@types/graphql\": \"^14.5.0\",\n \"@types/jest\": \"^25.1.4\",\n \"@types/node\": \"^13.9.8\",\n \"@types/prop-types\": \"^15.7.0\",\n \"@types/ramda\": \"^0.26.5\",\n \"@types/react\": \"^16.9.31\",\n \"@vtex/test-tools\": \"^3.1.0\",\n \"@vtex/tsconfig\": \"^0.4.4\",\n \"apollo-cache-inmemory\": \"^1.6.5\",\n \"apollo-client\": \"^2.6.8\",\n \"graphql\": \"^14.6.0\",\n \"typescript\": \"3.9.7\",\n \"vtex.css-handles\": \"http://vtex.vtexassets.com/_v/public/typings/v1/vtex.css-handles@0.4.4/public/@types/vtex.css-handles\",\n \"vtex.render-runtime\": \"http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@8.132.4/public/@types/vtex.render-runtime\",\n \"vtex.styleguide\": \"http://vtex.vtexassets.com/_v/public/typings/v1/vtex.styleguide@9.146.4/public/@types/vtex.styleguide\"\n },\n \"version\": \"0.8.0\"\n}\n\n```"
}
] |
code_iframe_88ab5824
|
[
{
"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 iframe/react/DynamicIframe.tsx from the iframe VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport React from 'react'\nimport { useRuntime } from 'vtex.render-runtime'\n\nimport Iframe from './Iframe'\n\ninterface Props {\n dynamicSrc: string\n width?: number\n height?: number\n title?: string\n allow?: string\n id?: string\n className?: string\n onLoad?: any\n}\n\nfunction DynamicIframe({\n dynamicSrc = '',\n width,\n height,\n title,\n allow,\n id,\n className,\n onLoad,\n}: Props) {\n const {\n route: { params, queryString },\n query = {},\n } = useRuntime()\n\n const _dynamicParams: any = Object.keys(params).length ? params : queryString\n\n let allParamsExist = true\n\n const queryStringSearch = Object.keys(params).length\n ? Object.keys(query).reduce((acc, key) => {\n return `${acc || '?'}${key}=${query[key]}&`\n }, '')\n : ``\n\n const src = dynamicSrc.replace(/({[A-z0-9]*})/g, (match: string) => {\n const thisParam = match.replace(/{|}/g, '')\n if (!thisParam || !_dynamicParams[thisParam]) {\n allParamsExist = false\n console.error(\n `parameter ${thisParam} not found in runtime params: ${_dynamicParams}`\n )\n return ''\n }\n return _dynamicParams[thisParam]\n })\n\n if (allParamsExist !== true || !src) {\n return null\n }\n\n return (\n <Iframe\n title={title}\n src={src + queryStringSearch}\n width={width}\n height={height}\n allow={allow}\n id={id}\n className={className}\n onLoad={onLoad}\n />\n )\n}\n\nDynamicIframe.schema = {\n title: 'editor.dynamiciframe.title',\n type: 'object',\n properties: {\n dynamicSrc: {\n title: 'editor.dynamiciframe.dynamicSrc.title',\n description: 'editor.dynamiciframe.dynamicSrc.description',\n type: 'string',\n default: null,\n },\n width: {\n title: 'editor.dynamiciframe.width.title',\n type: 'number',\n default: null,\n },\n height: {\n title: 'editor.dynamiciframe.height.title',\n type: 'number',\n default: null,\n },\n title: {\n title: 'editor.dynamiciframe.title.title',\n type: 'string',\n default: null,\n },\n id: {\n title: 'editor.dynamiciframe.id.title',\n type: 'string',\n default: null,\n },\n className: {\n title: 'editor.dynamiciframe.className.title',\n type: 'string',\n default: null,\n },\n onLoad: {\n title: 'editor.dynamiciframe.onLoad.title',\n type: 'string',\n default: null,\n },\n allow: {\n title: 'editor.dynamiciframe.allow.title',\n type: 'string',\n default: null,\n },\n },\n}\n\nexport default DynamicIframe\n\n```"
}
] |
code_iframe_2de113a0
|
[
{
"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 iframe/react/Iframe.tsx from the iframe VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\n/* eslint-disable no-console */\nimport React from 'react'\nimport { useCssHandles } from 'vtex.css-handles'\nimport { useRuntime } from 'vtex.render-runtime'\n\nconst CSS_HANDLES = ['container'] as const\n\ninterface Props {\n src?: string\n srcAccount?: any\n width?: number\n height?: number\n allow?: string\n title?: string\n id?: string\n className?: string\n onLoad?: any\n}\n\nfunction Iframe(props: Props) {\n const {\n src,\n srcAccount,\n width,\n height,\n title,\n allow,\n id,\n className,\n onLoad,\n } = props\n const handles = useCssHandles(CSS_HANDLES)\n const runtime = useRuntime()\n\n const handleIframeLoad = () => {\n if (!onLoad) return null\n // eslint-disable-next-line @typescript-eslint/no-implied-eval, no-new-func\n return Function('IframeHandler', `\"use strict\";(${onLoad});`)(onLoad)\n }\n\n const processSrc = () => srcAccount?.[runtime.account] ?? src\n\n console.log('processSrc =>', processSrc())\n\n return (\n <div className={`${handles.container} w-100 flex justify-center`}>\n <iframe\n title={title}\n src={processSrc()}\n width={width}\n height={height}\n allow={allow}\n id={id}\n className={className}\n onLoad={handleIframeLoad}\n frameBorder=\"0\"\n />\n </div>\n )\n}\n\nIframe.schema = {\n title: 'editor.iframe.title',\n type: 'object',\n properties: {\n src: {\n title: 'editor.iframe.src.title',\n description: 'editor.iframe.src.description',\n type: 'string',\n default: null,\n },\n srcAccount: {\n title: 'editor.iframe.srcAccount.title',\n description: 'editor.iframe.srcAccount.description',\n type: 'string',\n default: null,\n },\n width: {\n title: 'editor.iframe.width.title',\n type: 'number',\n default: null,\n },\n height: {\n title: 'editor.iframe.height.title',\n type: 'number',\n default: null,\n },\n title: {\n title: 'editor.iframe.title.title',\n type: 'string',\n default: null,\n },\n id: {\n title: 'editor.iframe.id.title',\n type: 'string',\n default: null,\n },\n className: {\n title: 'editor.iframe.className.title',\n type: 'string',\n default: null,\n },\n onLoad: {\n title: 'editor.iframe.onLoad.title',\n type: 'string',\n default: null,\n },\n allow: {\n title: 'editor.iframe.allow.title',\n type: 'string',\n default: null,\n },\n },\n}\n\nexport default Iframe\n\n```"
}
] |
code_iframe_e2e833ce
|
[
{
"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 iframe/store/interfaces.json from the iframe VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"iframe\": {\n \"component\": \"Iframe\"\n },\n \"iframe.dynamic-src\":{\n \"component\": \"DynamicIframe\"\n }\n}\n```"
}
] |
code_iframe_f959c692
|
[
{
"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 iframe/react/__tests__/index.test.tsx from the iframe VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport React from 'react'\nimport { render } from '@vtex/test-tools/react'\nimport { useRuntime } from 'vtex.render-runtime'\n\nimport DynamicIframe from '../DynamicIframe'\n\nconst mockedUseRuntime = useRuntime as jest.Mock\n\ndescribe('DynamicIframe', () => {\n it('should render the right URL', () => {\n mockedUseRuntime.mockImplementation(() => {\n return {\n route: {\n params: {\n param1: 'foo',\n param2: 'bar',\n },\n },\n }\n })\n\n const { container } = render(\n <DynamicIframe dynamicSrc=\"https://{param1}.com/{param2}.aspx\" />\n )\n\n const iframe = container.querySelector('iframe') as HTMLIFrameElement\n\n expect(iframe.src).toBe('https://foo.com/bar.aspx')\n })\n})\n\n```"
}
] |
code_kit-indexer_80827e03
|
[
{
"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 kit-indexer/docs/README.md from the kit-indexer VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```markdown\n# Kit Indexer\n\nApp in VTEX that receives a notification when a SKU is changed, if the SKU changed is a KIT, the SKU is updated with the correct weight which is the sum of the weights of its components.\n\n## How it works?\n\n\n\n## How to install\n\n⚠️ First, make sure the broadcaster app is installed.\n\n\nRun command: `vtex install vtex.kit-indexer`\n\n```"
}
] |
code_kit-indexer_c0b200ae
|
[
{
"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 kit-indexer/node/service.json from the kit-indexer VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"memory\": 128,\n \"ttl\": 10,\n \"timeout\": 2,\n \"minReplicas\": 2,\n \"maxReplicas\": 10,\n \"workers\": 4,\n \"events\": {\n \"skuChange\": {\n \"keys\": [\"broadcaster.notification\"]\n }\n }\n}\n\n```"
}
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.