id
stringlengths
12
53
messages
listlengths
3
3
code_mycheckout-checkout-service_f357004a
[ { "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 mycheckout-checkout-service/src/app/masters/document-types/document-types.service.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Injectable } from '@nestjs/common';\nimport { InjectModel } from 'nestjs-dynamoose';\nimport { DocumentTypesDto } from './dtos/document-types.dto';\nimport {\n DocumentType,\n DocumentTypeModel,\n} from './schemas/document-type.schema';\n\n@Injectable()\nexport class DocumentTypesService {\n constructor(\n @InjectModel(DocumentType.name)\n private documentTypeModel: DocumentTypeModel,\n ) {}\n\n getAll() {\n return this.documentTypeModel.scan().exec();\n }\n\n create(documentTypesDto: DocumentTypesDto) {\n return this.documentTypeModel.insertMany(documentTypesDto.documents);\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_f2cf0d2f
[ { "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 mycheckout-checkout-service/src/app/masters/document-types/document-types.controller.spec.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Test, TestingModule } from '@nestjs/testing';\nimport { DocumentTypesController } from './document-types.controller';\nimport { DocumentTypesService } from './document-types.service';\n\ndescribe('DocumentTypesController', () => {\n let controller: DocumentTypesController;\n\n beforeEach(async () => {\n const ApiServiceProvider = {\n provide: DocumentTypesService,\n useFactory: () => ({}),\n };\n\n const module: TestingModule = await Test.createTestingModule({\n controllers: [DocumentTypesController],\n providers: [ApiServiceProvider],\n }).compile();\n\n controller = module.get<DocumentTypesController>(DocumentTypesController);\n });\n\n it('should be defined', () => {\n expect(controller).toBeDefined();\n });\n});\n\n```" } ]
code_mycheckout-checkout-service_3ad1cfba
[ { "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 mycheckout-checkout-service/src/app/masters/document-types/document-types.controller.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Body, Controller, Get, Post } from '@nestjs/common';\nimport { DocumentTypesService } from './document-types.service';\nimport { DocumentTypeDto } from './dtos/document-type.dto';\nimport { DocumentTypesDto } from './dtos/document-types.dto';\n\n@Controller('masters/documenttypes')\nexport class DocumentTypesController {\n constructor(private documentTypesService: DocumentTypesService) {}\n\n @Get()\n getAll() {\n return this.documentTypesService.getAll();\n }\n\n @Post()\n create(@Body() documentTypesDto: DocumentTypesDto) {\n return this.documentTypesService.create(documentTypesDto);\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_b73fa9b5
[ { "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 mycheckout-checkout-service/src/app/masters/cities/schemas/city.schema.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport {\n Model,\n Document,\n Schema,\n ModelDefinition,\n} from 'src/shared/utils/dynamoose-module';\n\nexport interface CityAttrs {\n city: string;\n state: string;\n country: string;\n phone: string;\n iso: string;\n postal_code: string;\n}\n\nexport interface CityDoc extends Document {\n city: string;\n citySearch: string;\n state: string;\n stateSearch: string;\n country: string;\n countrySearch: string;\n phone: string;\n iso: string;\n postal_code: string;\n}\n\nexport type CityModel = Model<CityDoc, CityAttrs>;\n\nconst CitySchema = Schema.build({\n city: { type: String, required: true },\n citySearch: {\n type: String,\n required: true,\n index: { global: true, name: 'cityIndex' },\n },\n state: { type: String, required: true },\n stateSearch: {\n type: String,\n required: true,\n index: { global: true, name: 'stateIndex' },\n },\n country: { type: String, required: true },\n countrySearch: {\n type: String,\n required: true,\n index: { global: true, name: 'countryIndex' },\n },\n phone: { type: String, required: true },\n iso: { type: String, required: true },\n postal_code: { type: String, required: true },\n});\n\nexport const City: ModelDefinition = {\n name: 'masters.cities',\n schema: CitySchema,\n methods: {\n transform: (ret: CityDoc) => {\n delete ret.citySearch;\n delete ret.countrySearch;\n delete ret.stateSearch;\n },\n },\n options: { throughput: 'ON_DEMAND' },\n};\n\n```" } ]
code_mycheckout-checkout-service_f4684f22
[ { "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 mycheckout-checkout-service/src/app/masters/cities/dtos/city.dto.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { ApiError } from '../../../../shared/responses';\nimport { IsNotEmpty, IsString, ValidationArguments } from 'class-validator';\n\nexport class CityDto {\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n city: string;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n citySearch: string;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n stateSearch: string;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n countrySearch: string;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n postal_code: string;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n state: string;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n country: string;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n phone: string;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n iso: string;\n}\n\n```" } ]
code_mycheckout-checkout-service_41811805
[ { "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 mycheckout-checkout-service/src/app/masters/cities/dtos/cities.dto.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Type } from 'class-transformer';\nimport {\n IsNotEmpty,\n ValidateNested,\n ValidationArguments,\n} from 'class-validator';\nimport { ApiError } from '../../../../shared/responses';\nimport { CityDto } from './city.dto';\n\nexport class CitiesDto {\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @ValidateNested()\n @Type(() => CityDto)\n cities: CityDto[];\n}\n\n```" } ]
code_mycheckout-checkout-service_fde722ed
[ { "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 mycheckout-checkout-service/src/app/masters/countries/schemas/country.schema.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport {\n Model,\n Document,\n Schema,\n ModelDefinition,\n} from 'src/shared/utils/dynamoose-module';\n\ninterface CountryAttrs {\n country: string;\n iso: string;\n phone: string;\n postal_code_regex: string;\n states: {\n state: string;\n cities: [{ city: string; city_id: string }];\n };\n}\n\nexport interface CountryDoc extends Document {\n country: string;\n iso: string;\n phone: string;\n postal_code_regex: string;\n states: {\n state: string;\n cities: [{ city: string; city_id: string }];\n };\n}\n\nexport type CountryModel = Model<CountryDoc, CountryAttrs>;\n\nconst CountrySchema = Schema.build({\n country: {\n type: String,\n required: true,\n index: { global: true, name: 'countryIndex' },\n },\n iso: {\n type: String,\n required: true,\n index: { global: true, name: 'isoIndex' },\n },\n phone: { type: String, required: true },\n postal_code_regex: { type: String, required: true },\n states: {\n type: Array,\n schema: [\n {\n type: Object,\n schema: {\n state: String,\n cities: {\n type: Array,\n schema: [\n {\n type: Object,\n schema: {\n city: String,\n city_id: String,\n },\n },\n ],\n },\n },\n },\n ],\n },\n});\n\nexport const Country: ModelDefinition = {\n name: 'masters.countries',\n schema: CountrySchema,\n};\n\n```" } ]
code_mycheckout-checkout-service_bda4ed3e
[ { "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 mycheckout-checkout-service/src/app/masters/countries/dtos/countries.dto.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Type } from 'class-transformer';\nimport {\n IsNotEmpty,\n ValidateNested,\n ValidationArguments,\n} from 'class-validator';\nimport { ApiError } from '../../../../shared/responses';\nimport { CountryDto } from './country.dto';\n\nexport class CountriesDto {\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @ValidateNested()\n @Type(() => CountryDto)\n countries: CountryDto[];\n}\n\n```" } ]
code_mycheckout-checkout-service_e4e15600
[ { "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 mycheckout-checkout-service/src/app/masters/countries/dtos/country.dto.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Type } from 'class-transformer';\nimport {\n IsNotEmpty,\n IsObject,\n IsString,\n ValidateNested,\n ValidationArguments,\n} from 'class-validator';\nimport { ApiError } from '../../../../shared/responses';\nimport { StateDto } from './state.dto';\n\nexport class CountryDto {\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n readonly country: string;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n readonly iso: string;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n readonly phone: string;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n readonly postal_code_regex: string;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @ValidateNested()\n //@Type(() => StateDto)\n states: StateDto[] | any;\n}\n\n```" } ]
code_mycheckout-checkout-service_7c75f2e2
[ { "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 mycheckout-checkout-service/src/app/masters/countries/dtos/state.dto.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Type } from 'class-transformer';\nimport {\n IsNotEmpty,\n IsString,\n ValidateNested,\n ValidationArguments,\n} from 'class-validator';\nimport { ApiError } from '../../../../shared/responses';\nimport { CityDto } from '../../cities/dtos/city.dto';\n\nexport class StateDto {\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n state: string;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @ValidateNested()\n @Type(() => CityDto)\n cities: CityDto[];\n}\n\n```" } ]
code_mycheckout-checkout-service_4b2a48b0
[ { "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 mycheckout-checkout-service/src/app/masters/document-types/schemas/document-type.schema.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport {\n Model,\n Document,\n Schema,\n ModelDefinition,\n} from 'src/shared/utils/dynamoose-module';\n\ninterface DocumentTypeAttrs {\n name: string;\n type: string;\n}\n\ninterface DocumentTypeDoc extends Document {\n name: string;\n type: string;\n}\n\nexport type DocumentTypeModel = Model<DocumentTypeDoc, DocumentTypeAttrs>;\n\nconst DocumentTypeSchema = Schema.build({\n name: { type: String, required: true },\n type: {\n type: String,\n required: true,\n index: { global: true, name: 'typeIndex' },\n },\n});\n\nexport const DocumentType: ModelDefinition = {\n name: 'masters.documentTypes',\n schema: DocumentTypeSchema,\n};\n\n```" } ]
code_mycheckout-checkout-service_6967eede
[ { "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 mycheckout-checkout-service/src/app/masters/document-types/dtos/document-type.dto.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { ApiError } from '../../../../shared/responses';\nimport { IsNotEmpty, IsString, ValidationArguments } from 'class-validator';\n\nexport class DocumentTypeDto {\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n type: string;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n name: string;\n}\n\n```" } ]
code_mycheckout-checkout-service_65ee569b
[ { "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 mycheckout-checkout-service/src/app/masters/document-types/dtos/document-types.dto.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Type } from 'class-transformer';\nimport {\n IsNotEmpty,\n ValidateNested,\n ValidationArguments,\n} from 'class-validator';\nimport { ApiError } from '../../../../shared/responses';\nimport { DocumentTypeDto } from './document-type.dto';\n\nexport class DocumentTypesDto {\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @ValidateNested()\n @Type(() => DocumentTypeDto)\n documents: DocumentTypeDto[];\n}\n\n```" } ]
code_mycheckout-checkout-service_55c83a13
[ { "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 mycheckout-checkout-service/src/app/orders/schemas/order.schema.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Account, AccountDoc } from 'src/app/accounts/schemas/account.schema';\nimport {\n Model,\n Document,\n Schema,\n ModelDefinition,\n} from 'src/shared/utils/dynamoose-module';\n\ninterface OrderAttrs {\n country: string;\n currency: string;\n status: string;\n salesChannel: string;\n channel?: string;\n oms?: string;\n account: AccountDoc;\n accountName: string;\n creationDate: string;\n createdAt: number;\n log: string;\n shipping: {\n address: {\n id: string;\n country: string;\n state: string;\n city: string;\n street: string;\n number: string;\n postalCode: string;\n reference?: string;\n neighborhood: string;\n receiverName?: string;\n geoCoordinates: {\n latitude: string;\n longitude: string;\n };\n };\n logisticsInfo: {\n itemIndex: number;\n selectedSla: string;\n selectedDeliveryChannel: string;\n }[];\n };\n user: {\n name: string;\n lastname: string;\n documentType: string;\n document: string;\n phoneCode: string;\n phoneNumber: string;\n email: string;\n };\n items: {\n id: string;\n quantity: number;\n seller: string;\n }[];\n customData?: {\n customApps: [\n {\n id: string;\n major: number;\n fields: {\n key: string;\n value: string;\n }[];\n },\n ];\n };\n}\n\nexport interface OrderDoc extends Document {\n total: number;\n totalShipping: number;\n country: string;\n currency: string;\n status: string;\n salesChannel: string;\n orderId: string;\n channel: string;\n oms: string;\n account: AccountDoc;\n accountName: string;\n creationDate: string;\n createdAt: number;\n log?: string;\n shipping: {\n address: {\n id: string;\n country: string;\n state: string;\n city: string;\n street: string;\n number: string;\n postalCode: string;\n reference: string;\n neighborhood: string;\n receiverName: string;\n geoCoordinates: {\n latitude: string;\n longitude: string;\n };\n };\n logisticsInfo: [\n {\n itemIndex: number;\n selectedSla: string;\n selectedDeliveryChannel: string;\n },\n ];\n };\n user: {\n name: string;\n lastname: string;\n documentType: string;\n document: string;\n phoneCode: string;\n phoneNumber: string;\n email: string;\n };\n items: {\n id: string;\n quantity: number;\n seller: string;\n };\n payment: {\n number: string;\n franchise: string;\n transactionId: string;\n gateway: string;\n paymentMethod: string;\n paymentSystem?: string;\n cardId: string;\n };\n customData?: {\n customApps: [\n {\n id: string;\n major: number;\n fields: {\n key: string;\n value: string;\n }[];\n },\n ];\n };\n}\n\nexport type OrderModel = Model<OrderDoc, OrderAttrs>;\n\nconst OrderSchema = Schema.build({\n total: { type: Number },\n totalShipping: { type: Number },\n country: { type: String, required: true },\n currency: { type: String },\n status: {\n type: String,\n default: 'incomplete',\n index: { global: true, name: 'statusIndex' },\n },\n salesChannel: { type: String },\n orderId: { type: String, index: { global: true, name: 'orderIdIndex' } },\n channel: { type: String },\n oms: { type: String },\n creationDate: { type: String },\n createdAt: { type: Number },\n log: { type: String },\n accountName: { type: String },\n shipping: {\n type: Object,\n schema: {\n address: {\n type: Object,\n schema: {\n id: { type: String, required: true },\n country: { type: String, required: true },\n state: { type: String, required: true },\n city: { type: String, required: true },\n street: { type: String, required: true },\n number: { type: String, required: true },\n postalCode: { type: String, required: true },\n neighborhood: { type: String, required: false },\n reference: { type: String },\n receiverName: { type: String },\n geoCoordinates: {\n type: Object,\n schema: {\n latitude: { type: String, required: true },\n longitude: { type: String, required: true },\n },\n },\n },\n },\n logisticsInfo: {\n type: Array,\n schema: [\n {\n type: Object,\n schema: {\n itemIndex: { type: Number, required: true },\n selectedSla: { type: String, required: true },\n selectedDeliveryChannel: { type: String, required: true },\n },\n },\n ],\n },\n },\n },\n user: {\n type: Object,\n schema: {\n name: { type: String, required: true },\n lastname: { type: String, required: true },\n documentType: { type: String, required: true },\n document: { type: String, required: true },\n phoneCode: { type: String, required: false, default: '' },\n phoneNumber: { type: String, required: true },\n email: { type: String, required: true },\n },\n },\n items: {\n type: Array,\n schema: [\n {\n type: Object,\n schema: {\n id: { type: String, required: true },\n quantity: { type: Number, required: true },\n seller: { type: String, required: true },\n },\n },\n ],\n },\n payment: {\n type: Object,\n schema: {\n number: { type: String },\n franchise: { type: String },\n transactionId: { type: String },\n gateway: { type: String },\n paymentMethod: { type: String },\n paymentSystem: { type: String },\n cardId: { type: String },\n },\n },\n customData: {\n type: Object,\n schema: {\n customApps: {\n type: Array,\n schema: [\n {\n type: Object,\n schema: {\n id: { type: String },\n major: { type: Number },\n fields: {\n type: Array,\n schema: [\n {\n type: Object,\n schema: {\n key: { type: String },\n value: { type: String },\n },\n },\n ],\n },\n },\n },\n ],\n },\n },\n },\n});\n\nexport const Order: ModelDefinition = {\n name: 'orders',\n schema: OrderSchema,\n population: function (populate) {\n this.schema.schemaObject.account = {\n type: populate(Account),\n index: { global: true, name: 'accountIndex' },\n };\n },\n};\n\n```" } ]
code_mycheckout-checkout-service_f47aad0a
[ { "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 mycheckout-checkout-service/src/app/orders/dtos/storePreferences.dto.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { ApiError } from '../../../shared/responses/api-error';\nimport {\n IsNotEmpty,\n IsOptional,\n IsString,\n ValidationArguments,\n} from 'class-validator';\n\nexport class StorePreferencesDto {\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n currencyCode: string;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n countryCode: string;\n\n @IsOptional()\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n salesChannel: string;\n}\n\n```" } ]
code_mycheckout-checkout-service_83a5a785
[ { "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 mycheckout-checkout-service/src/app/orders/dtos/customDataApps.dto.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { ApiError } from '../../../shared/responses';\nimport { Type } from 'class-transformer';\nimport {\n IsNotEmpty,\n IsNumber,\n IsString,\n ValidateNested,\n ValidationArguments,\n} from 'class-validator';\nimport { CustomDataFieldsDto } from './customDataFields.dto';\n\nexport class CustomDataAppsDto {\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n id: string;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsNumber(\n {},\n {\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_number', args),\n },\n )\n major: number;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @ValidateNested()\n @Type(() => CustomDataFieldsDto)\n fields: [CustomDataFieldsDto];\n}\n\n```" } ]
code_mycheckout-checkout-service_93d2cca7
[ { "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 mycheckout-checkout-service/src/app/orders/dtos/externalAddress.dto.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { ApiError } from '../../../shared/responses';\nimport {\n IsOptional,\n IsString,\n ValidateNested,\n ValidationArguments,\n} from 'class-validator';\nimport { GeoCoordinateDto } from 'src/app/users/addresses/dtos/geoCoordinates.dto';\n\nexport class ExternalAddressDto {\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n @IsOptional()\n addressId: string;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n postalCode: string;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n country: string;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n state: string;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n city: string;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n street: string;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n number: string;\n\n @ValidateNested()\n geoCoordinates: GeoCoordinateDto;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n neighborhood: string;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n receiverName: string;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n reference: string;\n}\n\n```" } ]
code_mycheckout-checkout-service_2d16f853
[ { "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 mycheckout-checkout-service/src/app/orders/dtos/logisticInfo.dto.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { ApiError } from '../../../shared/responses';\nimport { Type } from 'class-transformer';\nimport {\n IsNotEmpty,\n IsNumber,\n IsOptional,\n IsString,\n ValidateNested,\n ValidationArguments,\n} from 'class-validator';\nimport { DeliveryWindowDto } from './deliveryWindow.dto';\n\nexport class LogisticInfoDto {\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsNumber(\n {},\n {\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n },\n )\n itemIndex: number;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n selectedSla: string;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n selectedDeliveryChannel: string;\n\n @IsOptional()\n @ValidateNested()\n @Type(() => DeliveryWindowDto)\n deliveryWindow?: DeliveryWindowDto;\n}\n\n```" } ]
code_mycheckout-checkout-service_9a765379
[ { "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 mycheckout-checkout-service/src/app/orders/dtos/deliveryWindow.dto.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { ApiError } from '../../../shared/responses';\nimport { IsNotEmpty, IsString, ValidationArguments } from 'class-validator';\n\nexport class DeliveryWindowDto {\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n startDateUtc: string;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n endDateUtc: string;\n}\n\n```" } ]
code_mycheckout-checkout-service_3e782dda
[ { "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 mycheckout-checkout-service/src/app/orders/dtos/createOrder.dto.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { ApiError } from '../../../shared/responses/api-error';\nimport {\n IsNotEmpty,\n IsOptional,\n IsString,\n ValidateNested,\n ValidationArguments,\n} from 'class-validator';\nimport { Type } from 'class-transformer';\nimport { ItemDto } from './item.dto';\nimport { PaymentDataDto } from './paymentData.dto';\nimport { ProfileDto } from './profile.dto';\nimport { AccountDto } from './account.dto';\nimport { ShippingDto } from './shipping.dto';\nimport { OfferingDto } from './Offering.dto';\nimport { CustomDataDto } from './customData.dto';\nimport { MarketingDataDto } from './marketingData.dto';\n\nexport class CreateOrderDto {\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @ValidateNested()\n @Type(() => ProfileDto)\n profile: ProfileDto;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @ValidateNested()\n @Type(() => ShippingDto)\n shipping: ShippingDto;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @ValidateNested()\n @Type(() => AccountDto)\n account: AccountDto;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @ValidateNested()\n @Type(() => ItemDto)\n items: ItemDto[];\n\n @IsOptional()\n @ValidateNested()\n @Type(() => ItemDto)\n gifts?: ItemDto[];\n\n @IsOptional()\n @ValidateNested()\n @Type(() => OfferingDto)\n offerings?: OfferingDto[];\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @ValidateNested()\n @Type(() => PaymentDataDto)\n payment: PaymentDataDto;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n channel: string;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n oms: string;\n\n @IsOptional()\n @ValidateNested()\n @Type(() => CustomDataDto)\n customData?: CustomDataDto;\n\n @IsOptional()\n @ValidateNested()\n @Type(() => MarketingDataDto)\n marketingData?: MarketingDataDto;\n\n @IsOptional()\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n authToken?: string;\n\n @IsOptional()\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n ip: string;\n}\n\n```" } ]
code_mycheckout-checkout-service_6f6ae03f
[ { "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 mycheckout-checkout-service/src/app/orders/dtos/customData.dto.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { ApiError } from '../../../shared/responses';\nimport { Type } from 'class-transformer';\nimport {\n IsNotEmpty,\n ValidateNested,\n ValidationArguments,\n} from 'class-validator';\nimport { CustomDataAppsDto } from './customDataApps.dto';\n\nexport class CustomDataDto {\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @ValidateNested()\n @Type(() => CustomDataAppsDto)\n customApps: [CustomDataAppsDto];\n}\n\n```" } ]
code_mycheckout-checkout-service_da41d60b
[ { "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 mycheckout-checkout-service/src/app/orders/dtos/item.dto.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { ApiError } from '../../../shared/responses';\nimport {\n IsNotEmpty,\n IsNumber,\n IsString,\n ValidationArguments,\n} from 'class-validator';\n\nexport class ItemDto {\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n id: string;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsNumber(\n {},\n {\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n },\n )\n quantity: number;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n seller: string;\n}\n\n```" } ]
code_mycheckout-checkout-service_2807189a
[ { "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 mycheckout-checkout-service/src/app/orders/dtos/customDataFields.dto.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { ApiError } from '../../../shared/responses';\nimport { IsString, ValidationArguments } from 'class-validator';\n\nexport class CustomDataFieldsDto {\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n key: string;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n value: string;\n}\n\n```" } ]
code_mycheckout-checkout-service_27fc46dd
[ { "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 mycheckout-checkout-service/src/app/orders/dtos/shipping.dto.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Type } from 'class-transformer';\nimport {\n IsNotEmpty,\n IsOptional,\n IsString,\n ValidateNested,\n ValidationArguments,\n} from 'class-validator';\nimport { ApiError } from '../../../shared/responses';\nimport { ExternalAddressDto } from './externalAddress.dto';\nimport { LogisticInfoDto } from './logisticInfo.dto';\n\nexport class ShippingDto {\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n @IsOptional()\n addressId?: string;\n\n @ValidateNested()\n @IsOptional()\n @Type(() => ExternalAddressDto)\n externalAddress?: ExternalAddressDto;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @ValidateNested()\n @Type(() => LogisticInfoDto)\n logisticsInfo: LogisticInfoDto[];\n}\n\n```" } ]
code_mycheckout-checkout-service_3a09c1f0
[ { "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 mycheckout-checkout-service/src/app/orders/dtos/Offering.dto.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { ApiError } from '../../../shared/responses';\nimport { IsNotEmpty, IsString, ValidationArguments } from 'class-validator';\n\nexport class OfferingDto {\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n id: string;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n parentItemId: string;\n}\n\n```" } ]
code_mycheckout-checkout-service_c19694de
[ { "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 mycheckout-checkout-service/src/app/orders/dtos/profile.dto.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { ApiError } from '../../../shared/responses';\nimport {\n IsBoolean,\n IsEmail,\n IsNotEmpty,\n IsOptional,\n IsString,\n ValidationArguments,\n} from 'class-validator';\n\nexport class ProfileDto {\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsEmail(\n {},\n {\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_email', args),\n },\n )\n email: string;\n\n @IsOptional()\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n profileId?: string;\n\n @IsOptional()\n @IsBoolean({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n habeasData?: boolean;\n}\n\n```" } ]
code_mycheckout-checkout-service_24c2204d
[ { "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 mycheckout-checkout-service/src/app/orders/dtos/account.dto.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { ApiError } from '../../../shared/responses';\nimport { Type } from 'class-transformer';\nimport {\n IsNotEmpty,\n IsString,\n ValidateNested,\n ValidationArguments,\n} from 'class-validator';\nimport { StorePreferencesDto } from './storePreferences.dto';\n\nexport class AccountDto {\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n accountName: string;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n hostname: string;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @ValidateNested()\n @Type(() => StorePreferencesDto)\n storePreferences: StorePreferencesDto;\n}\n\n```" } ]
code_mycheckout-checkout-service_6859396d
[ { "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 mycheckout-checkout-service/src/app/orders/dtos/totalizers.dto.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { ApiError } from '../../../shared/responses';\nimport { Type } from 'class-transformer';\nimport { IsInt, ValidationArguments } from 'class-validator';\n\nexport class TotalizersDto {\n @IsInt({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.field_integer', args),\n })\n @Type(() => Number)\n totals: number;\n\n @IsInt({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.field_integer', args),\n })\n @Type(() => Number)\n shippingTotal: number;\n\n @IsInt({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.field_integer', args),\n })\n @Type(() => Number)\n subTotal: number;\n}\n\n```" } ]
code_mycheckout-checkout-service_bd4567a0
[ { "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 mycheckout-checkout-service/src/app/orders/dtos/marketingData.dto.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { ApiError } from '../../../shared/responses';\nimport { IsOptional, IsString, ValidationArguments } from 'class-validator';\n\nexport class MarketingDataDto {\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n @IsOptional()\n coupon?: string;\n}\n\n```" } ]
code_mycheckout-checkout-service_b408f04f
[ { "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 mycheckout-checkout-service/src/app/orders/dtos/processTransaction.dto.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { ApiError } from '../../../shared/responses/api-error';\nimport {\n IsNotEmpty,\n IsOptional,\n IsString,\n ValidateNested,\n ValidationArguments,\n} from 'class-validator';\nimport { Type } from 'class-transformer';\nimport { PaymentDataDto } from './paymentData.dto';\nimport { CreateAccountDto } from '../../accounts/dtos/createAccount.dto';\nimport { ShippingDto } from './shipping.dto';\nimport { ProfileDto } from './profile.dto';\nimport { TotalizersDto } from './totalizers.dto';\n\nexport class ProcessTransactionDto {\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @ValidateNested()\n @Type(() => ProfileDto)\n profile: ProfileDto;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @ValidateNested()\n @Type(() => ShippingDto)\n shipping: ShippingDto;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n orderId: string;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @ValidateNested()\n @Type(() => CreateAccountDto)\n account: CreateAccountDto;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @ValidateNested()\n @Type(() => PaymentDataDto)\n payment: PaymentDataDto;\n\n @IsOptional()\n omsExtraData: any;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n @IsOptional()\n version?: string;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n channel: string;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n oms: string;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n hostname: string;\n\n @IsOptional()\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n reference?: string;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @ValidateNested()\n @Type(() => TotalizersDto)\n totalizers: TotalizersDto;\n\n @IsOptional()\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n authToken?: string;\n}\n\n```" } ]
code_mycheckout-checkout-service_b296cded
[ { "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 mycheckout-checkout-service/src/app/orders/dtos/paymentData.dto.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { ApiError } from '../../../shared/responses';\nimport {\n IsNotEmpty,\n IsOptional,\n IsString,\n ValidationArguments,\n} from 'class-validator';\n\nexport class PaymentDataDto {\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n @IsOptional()\n token?: string;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n @IsOptional()\n franchise?: string;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n @IsOptional()\n number?: string;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n gateway: string;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n paymentMethod: string;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n @IsOptional()\n cardId?: string;\n\n @IsOptional()\n additionalData?: any;\n\n @IsOptional()\n cardContent?: any;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n @IsOptional()\n payment_method_id?: string;\n\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n @IsOptional()\n issuer_id?: string;\n\n @IsOptional()\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n cvv?: string;\n\n @IsOptional()\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n bin?: string;\n\n @IsOptional()\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n holderName?: string;\n\n @IsOptional()\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n paymentSystem?: string;\n\n @IsOptional()\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n holderDocument?: string;\n\n @IsOptional()\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n expirationDate?: string;\n\n @IsOptional()\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n cardNumber?: string;\n\n @IsOptional()\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n aliasCC?: string;\n\n @IsOptional()\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n aliasCVV?: string;\n}\n\n```" } ]
code_mycheckout-checkout-service_687cf47e
[ { "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 mycheckout-checkout-service/src/app/payment-providers/types/payment-providers.type.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { HttpService } from '@nestjs/common';\nimport { ConfigService } from '@nestjs/config';\nimport { CreditPayService } from '../credit-pay/credit-pay.service';\n\nexport type PaymentProviderServices = {\n httpService: HttpService;\n configService: ConfigService;\n creditPayService: CreditPayService;\n};\n\nexport enum PaymentProviderName {\n MercadoPago = 'mercadopago',\n Paymentez = 'paymentez',\n Noop = 'noop',\n CashOnDelivery = 'promissory',\n CreditPay = 'creditpay',\n Custom = 'custom',\n}\n\nexport enum PaymentMethodName {\n Promissory = 'promissory',\n CreditCard = 'tc',\n BNPL = 'BNPL',\n}\n\n```" } ]
code_mycheckout-checkout-service_e39cb4b1
[ { "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 mycheckout-checkout-service/src/app/payment-providers/credit-pay/credit-pay.service.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Injectable } from '@nestjs/common';\nimport { InjectModel } from 'nestjs-dynamoose';\nimport { CreateUserCreditDto } from './dto/createUserCredit.dto';\nimport { ValidateCreditDto } from './dto/validateCredit.dto';\nimport { Credit, CreditDoc, CreditModel } from './schema/credit.schema';\n\n@Injectable()\nexport class CreditPayService {\n constructor(@InjectModel(Credit.name) private creditModel: CreditModel) {}\n\n async createUserCredit(createUserCreditDto: CreateUserCreditDto) {\n let userCredit: CreditDoc = await this.creditModel\n .findOne({\n email: createUserCreditDto.email,\n })\n .exec();\n\n if (!userCredit) {\n userCredit = this.creditModel.build({\n email: createUserCreditDto.email,\n creditLimit: createUserCreditDto.creditLimit,\n });\n } else {\n userCredit.set({\n creditLimit: createUserCreditDto.creditLimit,\n });\n }\n\n return userCredit.save();\n }\n\n async chargeCredit(validateCreditDto: ValidateCreditDto) {\n const userCredit: CreditDoc = await this.creditModel\n .findOne({\n email: validateCreditDto.email,\n })\n .exec();\n\n userCredit.set({\n creditLimit: userCredit.creditLimit - validateCreditDto.totals,\n });\n\n return userCredit.save();\n }\n\n private calculateInstallments(total: number) {\n if (total <= 100000) {\n return 3;\n } else if (total > 100000 && total < 1000000) {\n return 12;\n } else {\n return 24;\n }\n }\n\n async validateCredit(validateCreditDto: ValidateCreditDto) {\n const userCredit = await this.creditModel\n .findOne({\n email: validateCreditDto.email,\n })\n .exec();\n\n if (!userCredit) {\n return {\n approvedCredit: 0,\n maxInstallments: 0,\n };\n }\n\n if (userCredit.creditLimit - validateCreditDto.totals > 0) {\n return {\n approvedCredit: validateCreditDto.totals,\n maxInstallments: this.calculateInstallments(validateCreditDto.totals),\n };\n }\n\n return {\n approvedCredit: 0,\n maxInstallments: 0,\n };\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_b4f9636a
[ { "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 mycheckout-checkout-service/src/app/payment-providers/credit-pay/credit-pay.controller.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Body, Controller, Post } from '@nestjs/common';\nimport { CreditPayService } from './credit-pay.service';\nimport { CreateUserCreditDto } from './dto/createUserCredit.dto';\nimport { ValidateCreditDto } from './dto/validateCredit.dto';\n\n@Controller('credit-pay')\nexport class CreditPayController {\n constructor(private creditPayService: CreditPayService) {}\n\n @Post('/user')\n createUserCredit(@Body() createUserDto: CreateUserCreditDto) {\n return this.creditPayService.createUserCredit(createUserDto);\n }\n\n @Post('/validate-credit')\n validateCredit(@Body() validateCreditDto: ValidateCreditDto) {\n return this.creditPayService.validateCredit(validateCreditDto);\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_eda327c7
[ { "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 mycheckout-checkout-service/src/app/payment-providers/credit-pay/credit-pay.controller.spec.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Test, TestingModule } from '@nestjs/testing';\nimport { CreditPayController } from './credit-pay.controller';\nimport { CreditPayService } from './credit-pay.service';\n\ndescribe('CreditPayController', () => {\n let controller: CreditPayController;\n\n beforeEach(async () => {\n const ApiServiceProvider = {\n provide: CreditPayService,\n useFactory: () => ({}),\n };\n\n const module: TestingModule = await Test.createTestingModule({\n controllers: [CreditPayController],\n providers: [ApiServiceProvider],\n }).compile();\n\n controller = module.get<CreditPayController>(CreditPayController);\n });\n\n it('should be defined', () => {\n expect(controller).toBeDefined();\n });\n});\n\n```" } ]
code_mycheckout-checkout-service_6cabb538
[ { "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 mycheckout-checkout-service/src/app/payment-providers/credit-pay/index.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { HttpException, HttpStatus } from '@nestjs/common';\nimport { PaymentProvider } from '../payment-provider';\nimport { ValidateCreditDto } from './dto/validateCredit.dto';\n\nexport class CreditPayProvider extends PaymentProvider {\n async authorizePayment(): Promise<void> {\n const {\n profile: { email },\n totalizers: { totals },\n } = this.ctx.processTransactionDto;\n\n const validateCreditDto = new ValidateCreditDto();\n validateCreditDto.email = email;\n validateCreditDto.totals = totals;\n\n const approvedCredit = await this.services.creditPayService.validateCredit(\n validateCreditDto,\n );\n\n if (approvedCredit.approvedCredit === 0) {\n throw new HttpException('Credit Limit Exceeded', HttpStatus.BAD_REQUEST);\n }\n\n await this.services.creditPayService.chargeCredit(validateCreditDto);\n\n this.ctx.transaction = {\n transactionId: 'credit',\n };\n }\n capturePayment(): Promise<void> {\n throw new Error('Method not implemented.');\n }\n refundPayment(): Promise<void> {\n throw new Error('Method not implemented.');\n }\n cancelPayment(): Promise<void> {\n throw new Error('Method not implemented.');\n }\n rollbackPayment(): Promise<void> {\n throw new Error('Method not implemented.');\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_0c21f181
[ { "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 mycheckout-checkout-service/src/app/payment-providers/credit-pay/credit-pay.service.spec.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { getModelToken } from '@nestjs/mongoose';\nimport { Test, TestingModule } from '@nestjs/testing';\nimport { CreditPayService } from './credit-pay.service';\nimport { Credit } from './schema/credit.schema';\n\ndescribe('CreditPayService', () => {\n let service: CreditPayService;\n\n beforeEach(async () => {\n const CreditModel = {\n provide: getModelToken(Credit.name),\n useFactory: () => ({}),\n };\n const module: TestingModule = await Test.createTestingModule({\n providers: [CreditPayService, CreditModel],\n }).compile();\n\n service = module.get<CreditPayService>(CreditPayService);\n });\n\n it('should be defined', () => {\n expect(service).toBeDefined();\n });\n});\n\n```" } ]
code_mycheckout-checkout-service_218b7128
[ { "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 mycheckout-checkout-service/src/app/payment-providers/mercadopago/mercadopago.service.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Injectable } from '@nestjs/common';\nimport { ConfigService } from '@nestjs/config';\nimport * as mercadopago from 'mercadopago';\nimport { IBaseAll } from '../base/base-all.interface';\nimport { CardsService } from './services/cards.service';\nimport { PreferencesService } from './services/preferences.service';\nimport { TransactionService } from './services/transaction.service';\n\n@Injectable()\nexport class MercadopagoService implements IBaseAll {\n cards: CardsService;\n transactions: TransactionService;\n preferences: PreferencesService;\n\n constructor(private readonly configService: ConfigService) {\n mercadopago.configure({\n access_token: this.configService.get('MERCADOPAGO_ACCESS_TOKEN'),\n });\n\n this.cards = new CardsService(mercadopago);\n this.transactions = new TransactionService(mercadopago);\n this.preferences = new PreferencesService(mercadopago);\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_a752994a
[ { "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 mycheckout-checkout-service/src/app/payment-providers/mercadopago/types.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nexport interface AdditionalData {\n issuerId: string;\n installments: number;\n}\n\nexport interface customerData {\n email: string;\n document: string;\n documentType: string;\n}\n\n```" } ]
code_mycheckout-checkout-service_5e524f88
[ { "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 mycheckout-checkout-service/src/app/payment-providers/mercadopago/index.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { OrderContext } from '../../../typings/OrderContext';\nimport * as mercadopago from 'mercadopago';\nimport { CreateCardPayload } from 'mercadopago/models/cards/create-payload';\nimport { CreateCustomerPayload } from 'mercadopago/models/customers/create-payload.model';\nimport { CreatePaymentPayload } from 'mercadopago/models/payment/create-payload.model';\nimport { PaymentProvider } from '../payment-provider';\nimport { PaymentProviderServices } from '../types/payment-providers.type';\nimport { CardsService } from './services/cards.service';\nimport { TransactionService } from './services/transaction.service';\nimport { AdditionalData } from './types';\n\nexport class MercadoPagoProvider extends PaymentProvider {\n cards: CardsService;\n transactions: TransactionService;\n\n constructor(\n public services: PaymentProviderServices,\n public ctx: OrderContext,\n ) {\n super(services, ctx);\n\n mercadopago.configure({\n access_token: this.services.configService.get('MERCADOPAGO_ACCESS_TOKEN'),\n });\n\n this.cards = new CardsService(mercadopago);\n this.transactions = new TransactionService(mercadopago);\n }\n\n private formattedEmail(profileId: string, email: string) {\n const splittedEmail = email.split('@');\n return `${splittedEmail[0]}+${profileId}@${splittedEmail[1]}`;\n }\n\n private createCustomer(profileId: string, email: string) {\n const customer: CreateCustomerPayload = {\n email: this.formattedEmail(profileId, email),\n };\n return mercadopago.customers.create(customer);\n }\n\n private createCard(customerId: string, token: string) {\n const card: CreateCardPayload = {\n customer_id: customerId,\n token,\n };\n\n return mercadopago.card.create(card);\n }\n\n private getCustomer(profileId: string, email: string) {\n return mercadopago.customers.search({\n qs: { email: this.formattedEmail(profileId, email) },\n });\n }\n\n async authorizePayment(): Promise<void> {\n const {\n processTransactionDto: {\n totalizers: { totals },\n payment: { additionalData: ad, ...payment },\n reference,\n orderId,\n profile: { email },\n },\n profile: { document, documentType, id },\n } = this.ctx;\n\n const additionalData = ad as AdditionalData;\n\n const paymentData: CreatePaymentPayload = {\n transaction_amount: totals,\n token: payment.token,\n description: reference || orderId,\n installments: Number(additionalData.installments),\n payment_method_id: payment.franchise,\n issuer_id: additionalData.issuerId,\n payer: {\n email: email,\n identification: {\n number: document,\n type: documentType,\n },\n },\n };\n\n if (payment.cardId) {\n paymentData.payer = {\n ...paymentData.payer,\n type: 'customer',\n id: (payment as any).internalCardContent.customerId,\n };\n }\n\n const transaction = await mercadopago.payment.create(paymentData);\n\n this.ctx.transaction = {\n transactionId: transaction.body.id,\n };\n\n if (!payment.cardId) {\n let customerId: string;\n\n const customerQuery = await this.getCustomer(id, email);\n\n if (\n customerQuery &&\n customerQuery.body &&\n customerQuery.body.results.length === 0\n ) {\n const customerCreated = await this.createCustomer(id, email);\n customerId = customerCreated.body.id;\n } else {\n customerId = customerQuery.body.results[0].id;\n }\n\n const card = await this.createCard(customerId, payment.token);\n\n this.ctx.transaction = {\n ...this.ctx.transaction,\n cardContent: {\n cardId: card.body.id,\n },\n internalCardContent: {\n customerId,\n },\n };\n }\n }\n capturePayment(): Promise<void> {\n throw new Error('Method not implemented.');\n }\n refundPayment(): Promise<void> {\n throw new Error('Method not implemented.');\n }\n cancelPayment(): Promise<void> {\n throw new Error('Method not implemented.');\n }\n rollbackPayment(): Promise<void> {\n return;\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_545c2d29
[ { "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 mycheckout-checkout-service/src/app/payment-providers/mercadopago/mercadopago.service.spec.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { HttpService } from '@nestjs/common';\nimport { ConfigService } from '@nestjs/config';\nimport { Test, TestingModule } from '@nestjs/testing';\nimport { MercadopagoService } from './mercadopago.service';\n\nconst HttpServiceProvider = {\n provide: HttpService,\n useFactory: () => ({}),\n};\n\nconst ConfigServiceProvider = {\n provide: ConfigService,\n useFactory: () => ({\n get() {\n return {};\n },\n }),\n};\n\ndescribe('MercadopagoService', () => {\n let service: MercadopagoService;\n\n beforeEach(async () => {\n const module: TestingModule = await Test.createTestingModule({\n providers: [\n MercadopagoService,\n HttpServiceProvider,\n ConfigServiceProvider,\n ],\n }).compile();\n\n service = module.get<MercadopagoService>(MercadopagoService);\n });\n\n it('should be defined', () => {\n expect(service).toBeDefined();\n });\n});\n\n```" } ]
code_mycheckout-checkout-service_4300efd2
[ { "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 mycheckout-checkout-service/src/app/payment-providers/cashOnDelivery/index.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { PaymentProvider } from '../payment-provider';\n\nexport class CashOnDelivery extends PaymentProvider {\n authorizePayment(): Promise<void> {\n this.ctx.transaction = {\n transactionId: 'promissory',\n };\n return;\n }\n capturePayment(): Promise<void> {\n throw new Error('Method not implemented.');\n }\n refundPayment(): Promise<void> {\n throw new Error('Method not implemented.');\n }\n cancelPayment(): Promise<void> {\n throw new Error('Method not implemented.');\n }\n rollbackPayment(): Promise<void> {\n return;\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_d338abba
[ { "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 mycheckout-checkout-service/src/app/payment-providers/custom/index.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { OrderContext } from 'src/typings/OrderContext';\nimport { PaymentProvider } from '../payment-provider';\nimport { PaymentProviderServices } from '../types/payment-providers.type';\n\nexport class Custom extends PaymentProvider {\n constructor(\n protected services: PaymentProviderServices,\n protected ctx: OrderContext,\n protected paymentMethod: string,\n ) {\n super(services, ctx);\n }\n authorizePayment(): Promise<void> {\n this.ctx.transaction = {\n transactionId: this.paymentMethod,\n };\n return;\n }\n capturePayment(): Promise<void> {\n throw new Error('Method not implemented.');\n }\n refundPayment(): Promise<void> {\n throw new Error('Method not implemented.');\n }\n cancelPayment(): Promise<void> {\n throw new Error('Method not implemented.');\n }\n rollbackPayment(): Promise<void> {\n return;\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_73e52546
[ { "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 mycheckout-checkout-service/src/app/payment-providers/kuikpay/kuikpay.service.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { CreateAccountDto } from '../../accounts/dtos/createAccount.dto';\nimport { PaymentDataDto } from '../../orders/dtos/paymentData.dto';\nimport { OrderVtexDto } from '../../vtex/dtos/orderVtex.dto';\nimport { PaymentVtexDto } from '../../vtex/dtos/paymentVtex.dto';\nimport { TransactionVtexDto } from '../../vtex/dtos/transactionVtex.dto';\nimport { Injectable } from '@nestjs/common';\nimport { PaymentProviderServices } from '../types/payment-providers.type';\nimport { OrderContext } from 'src/typings/OrderContext';\n\n@Injectable()\nexport class KuikpayService {\n private readonly api;\n constructor(public services: PaymentProviderServices) {\n this.api = this.services.configService.get('KUIKPAY_API_PAYMENTS');\n }\n\n sendPayment(\n payment: PaymentVtexDto,\n orderVtex: OrderVtexDto,\n transaction: TransactionVtexDto,\n accountData: CreateAccountDto,\n checkoutCookie: any,\n hostname: string,\n paymentData?: PaymentDataDto,\n ctx?: OrderContext,\n ) {\n const installments = paymentData.additionalData?.installments\n ? paymentData.additionalData?.installments\n : 1;\n const proxy: any = {};\n //TODO: revisar accountId al eliminar PCI proxy\n const accountId = paymentData.additionalData?.accountId;\n proxy.transactionId = paymentData.additionalData?.transactionId;\n proxy.token = paymentData.token;\n proxy.aliasCC = paymentData.aliasCC;\n proxy.aliasCVV = paymentData.aliasCVV;\n\n const payments = {\n proxy: proxy,\n gateway: proxy.token ? 'paymentez' : 'pci',\n vtex: {\n user: {\n email: ctx.processTransactionDto.profile.email,\n document: ctx.profile.document,\n },\n payment: {\n paymentSystem: Number.parseInt(payment.paymentSystem),\n installments: Number.parseInt(installments),\n installmentsInterestRate: 0,\n installmentsValue: 0,\n value: payment.value,\n franchise: paymentData.franchise,\n referenceValue: payment.referenceValue,\n fields: {\n validationCode: paymentData.cvv,\n holderName: paymentData.holderName,\n dueDate: paymentData.expirationDate,\n addressId: orderVtex.addressId,\n number: paymentData.number,\n bin: paymentData.bin,\n },\n transaction: {\n id: transaction.transactionId,\n merchantName: transaction.merchantName,\n },\n currencyCode: orderVtex.currencyCode,\n },\n order: {\n accountName: accountData.account,\n hostname,\n VtexChkoAuth: checkoutCookie,\n orderGroup: orderVtex.orderGroup,\n },\n },\n };\n\n if (accountId) {\n payments.vtex.payment.fields['cardNumber'] = null;\n payments.vtex.payment.fields['accountId'] = accountId;\n payments.vtex.payment.fields.dueDate = null;\n delete payments.vtex.payment.fields.holderName;\n }\n\n return this.services.httpService\n .post(this.api, payments, {\n headers: {\n ...ctx?.headers,\n },\n })\n .toPromise()\n .then((r: any) => {\n if (r?.data) {\n (ctx as any).transaction = {\n aliasCC: r.data.aliasCC,\n aliasCVV: r.data.aliasCVV,\n gatewayCallbackResponse: r.data.gatewayCallbackResponse,\n token: r.data.token,\n };\n }\n });\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_067136cb
[ { "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 mycheckout-checkout-service/src/app/payment-providers/kuikpay/types.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nexport interface AdditionalData {\n transactionId: string;\n installments: string;\n}\n\n```" } ]
code_mycheckout-checkout-service_6ebe62c1
[ { "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 mycheckout-checkout-service/src/app/payment-providers/kuikpay/index.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { GatewayException } from '../../../shared/exceptions/gateway-exception';\nimport { OrderContext } from '../../../typings/OrderContext';\nimport { PaymentProvider } from '../payment-provider';\nimport { PaymentProviderServices } from '../types/payment-providers.type';\nimport { KuikpayService } from './kuikpay.service';\nimport { AdditionalData } from './types';\n\nexport class KuikpayProvider extends PaymentProvider {\n constructor(\n public services: PaymentProviderServices,\n public ctx: OrderContext,\n ) {\n super(services, ctx);\n }\n\n async authorizePayment(): Promise<void> {\n const {\n processTransactionDto: {\n payment: { additionalData: ad, ...paymentData },\n omsExtraData: { order: orderVtex, transactions, checkoutCookie },\n account,\n hostname,\n },\n } = this.ctx;\n\n const additionalData = ad as AdditionalData;\n const kuikpayService = new KuikpayService(this.services);\n const transactionPromises = [];\n\n try {\n transactions.forEach((transaction) =>\n transaction.payments.forEach((payment) =>\n transactionPromises.push(\n kuikpayService.sendPayment(\n payment,\n orderVtex,\n transaction,\n account,\n checkoutCookie,\n hostname,\n { additionalData, ...paymentData },\n this.ctx,\n ),\n ),\n ),\n );\n await Promise.all(transactionPromises);\n } catch (err) {\n if (err.code && err.code === 'ECONNREFUSED') {\n throw new GatewayException(\n 'Payments service is not online',\n err.response,\n );\n }\n throw new GatewayException(\n 'Error in payment service',\n err.response?.data,\n );\n }\n\n this.ctx.transaction = {\n ...this.ctx.transaction,\n transactionId: additionalData?.transactionId,\n };\n }\n\n capturePayment(): Promise<void> {\n throw new Error('Method not implemented.');\n }\n refundPayment(): Promise<void> {\n throw new Error('Method not implemented.');\n }\n cancelPayment(): Promise<void> {\n throw new Error('Method not implemented.');\n }\n rollbackPayment(): Promise<void> {\n return;\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_8b296d7c
[ { "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 mycheckout-checkout-service/src/app/payment-providers/base/base-all.interface.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { CardsService as MercadopagoCard } from '../mercadopago/services/cards.service';\nimport { TransactionService as MercadopagoTransaction } from '../mercadopago/services/transaction.service';\n\nexport interface IBaseAll {\n cards: MercadopagoCard;\n transactions: MercadopagoTransaction;\n}\n\n```" } ]
code_mycheckout-checkout-service_1b3d075d
[ { "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 mycheckout-checkout-service/src/app/payment-providers/base/base-transaction.interface.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { ChargesDto } from './dtos/charges.dto';\nimport { CustomerDto } from './dtos/customer.dto';\n\nexport interface ITransactionService {\n createCharge(data: ChargesDto, customer: CustomerDto): Promise<any>;\n}\n\n```" } ]
code_mycheckout-checkout-service_1da0b850
[ { "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 mycheckout-checkout-service/src/app/payment-providers/base/base-cards.interface.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { CustomerDto } from './dtos/customer.dto';\n\nexport interface ICardsService {\n listOfUserCards(customer: CustomerDto): Promise<any>;\n deleteUserCards(token: string, customer: CustomerDto): Promise<any>;\n createCard(customer: CustomerDto, data: any);\n}\n\n```" } ]
code_mycheckout-checkout-service_d4a52b1f
[ { "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 mycheckout-checkout-service/src/app/payment-providers/credit-pay/dto/validateCredit.dto.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport {\n IsEmail,\n IsInt,\n IsNotEmpty,\n ValidationArguments,\n} from 'class-validator';\nimport { ApiError } from '../../../../shared/responses';\nimport { Type } from 'class-transformer';\n\nexport class ValidateCreditDto {\n @IsInt({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.field_integer', args),\n })\n @Type(() => Number)\n totals: number;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsEmail(\n {},\n {\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_email', args),\n },\n )\n email: string;\n}\n\n```" } ]
code_mycheckout-checkout-service_eb9245e3
[ { "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 mycheckout-checkout-service/src/app/payment-providers/credit-pay/dto/createUserCredit.dto.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport {\n IsEmail,\n IsInt,\n IsNotEmpty,\n ValidationArguments,\n} from 'class-validator';\nimport { ApiError } from '../../../../shared/responses';\nimport { Type } from 'class-transformer';\n\nexport class CreateUserCreditDto {\n @IsInt({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.field_integer', args),\n })\n @Type(() => Number)\n creditLimit: number;\n\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsEmail(\n {},\n {\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_email', args),\n },\n )\n email: string;\n}\n\n```" } ]
code_mycheckout-checkout-service_d3dca98d
[ { "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 mycheckout-checkout-service/src/app/payment-providers/credit-pay/schema/credit.schema.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport {\n Model,\n Document,\n Schema,\n ModelDefinition,\n} from 'src/shared/utils/dynamoose-module';\n\ninterface CreditAttrs {\n email: string;\n creditLimit: number;\n}\n\nexport interface CreditDoc extends Document {\n email: string;\n creditLimit: number;\n}\n\nexport type CreditModel = Model<CreditDoc, CreditAttrs>;\n\nconst CreditSchema = Schema.build({\n email: {\n type: String,\n required: true,\n index: { global: true, name: 'emailIndex' },\n },\n creditLimit: { type: Number, required: true },\n});\n\nexport const Credit: ModelDefinition = {\n name: 'credits',\n schema: CreditSchema,\n};\n\n```" } ]
code_mycheckout-checkout-service_91feef78
[ { "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 mycheckout-checkout-service/src/app/payment-providers/mercadopago/config/constants.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nconst DOMAIN = '';\n\nexport const MERCADOPAGO = {\n BUSINESS_NAME: 'Checkoutless',\n NOTIFICATION_URL: `https://`,\n SUCCESS_URL: `${DOMAIN}/ecommerce/success`,\n FAILURE_URL: `${DOMAIN}/ecommerce/failure`,\n PENDING_URL: `${DOMAIN}/ecommerce/pending`,\n};\n\n```" } ]
code_mycheckout-checkout-service_3be28e15
[ { "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 mycheckout-checkout-service/src/app/payment-providers/mercadopago/config/preference.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { MERCADOPAGO } from './constants';\nimport { OrderDoc } from '../../../orders/schemas/order.schema';\n\n//Available types in https://github.com/mercadopago/devsite-docs/issues/1173\n\nexport const preference = (order: OrderDoc) => {\n const user = order.user;\n const address = order.shipping.address;\n return {\n binary_mode: false,\n expires: true,\n expiration_date_from: new Date(Date.now()).toISOString(),\n expiration_date_to: new Date(Date.now() + 3).toISOString(),\n payer: {\n name: user.name,\n surname: user.lastname,\n email: user.email,\n phone: {\n area_code: user.phoneCode,\n number: Number(user.phoneNumber) as any,\n },\n identification: {\n type: user.documentType,\n number: user.document,\n },\n address: {\n street_name: address.neighborhood,\n zip_code: address.postalCode,\n street_number: address.street as any,\n },\n },\n shipments: {\n receiver_address: {\n zip_code: address.postalCode,\n street_number: address.street as any,\n city_name: address.city,\n state_name: address.state,\n },\n },\n external_reference: order.orderId,\n items: [\n {\n currency_id: order.currency,\n unit_price: order.total,\n category_id: `others`, // Available categories at https://api.mercadopago.com/item_categories\n },\n ],\n auto_return: 'approved',\n notification_url: MERCADOPAGO.NOTIFICATION_URL,\n back_urls: {\n success: MERCADOPAGO.SUCCESS_URL,\n failure: MERCADOPAGO.FAILURE_URL,\n pending: MERCADOPAGO.PENDING_URL,\n },\n payment_methods: {\n excluded_payment_methods: [{ id: 'amex' }],\n excluded_payment_types: [{ id: 'atm' }],\n installments: 6,\n default_installments: 6,\n },\n };\n};\n\n```" } ]
code_mycheckout-checkout-service_ad347159
[ { "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 mycheckout-checkout-service/src/app/payment-providers/mercadopago/services/transaction.service.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { ApiResponse } from '../../../../shared/responses';\nimport { ITransactionService } from '../../base/base-transaction.interface';\nimport { ChargesDto } from '../../base/dtos/charges.dto';\nimport { CustomerDto } from '../../base/dtos/customer.dto';\n\nexport class TransactionService implements ITransactionService {\n constructor(private readonly mercadopago) {}\n\n createCharge(data: ChargesDto, customer: CustomerDto): Promise<any> {\n // details in https://www.mercadopago.com.mx/developers/es/guides/online-payments/checkout-api/receiving-payment-by-card\n let transaction;\n if (data.order.issuer_id)\n transaction = this.mercadopago.payment.save({\n transaction_amount: data.order.amount,\n token: data.ccToken,\n description: data.order.description,\n installments: data.order.installments,\n payment_method_id: data.order.payment_method_id,\n issuer_id: data.order.issuer_id,\n payer: {\n email: customer.email,\n identification: {\n type: customer.documentType,\n number: customer.documentNumber,\n },\n },\n });\n else\n transaction = this.mercadopago.payment.create({\n transaction_amount: data.order.amount,\n token: data.ccToken,\n description: data.order.description,\n installments: data.order.installments,\n payer: {\n type: 'customer',\n id: customer.id,\n },\n });\n\n return transaction\n .then((response) => {\n this.paymentCapture(response.body.id);\n return {\n transaction_id: response.body.id,\n authorization_code: response.body.status_detail,\n status: response.body.status,\n };\n })\n .catch((error) => {\n console.log(error);\n throw ApiResponse.errorWithObject(\n 'errors.mercadopago_create_transaction',\n { error: error },\n );\n });\n }\n\n private paymentCapture(paymentId: number) {\n // acretited payment after being authorized\n return this.mercadopago.payment.capture(\n paymentId,\n this.mercadopago,\n (error, response) => {\n if (error) {\n console.log(error);\n } else {\n console.log(response);\n }\n },\n );\n }\n /*createOtherPayment(payment: PaymentDto, order: OrderDoc) {\n // details in https://www.mercadopago.com.mx/developers/es/guides/online-payments/checkout-api/other-payment-ways\n const user = order.user;\n return this.mercadopago.payment\n .create({\n ...payment,\n payer: {\n email: user.email,\n },\n })\n .then((response) => {\n this.paymentCapture(response.body.id);\n return {\n status: response.body.status,\n status_detail: response.body.status_detail,\n id: response.body.id,\n transaction_details: response.body.transaction_details,\n };\n })\n .catch((error) => {\n console.log(error);\n throw ApiResponse.errorWithObject(\n 'errors.mercadopago_create_transaction',\n { error: error },\n );\n });\n }*/\n\n getPaymentMethods() {\n return this.mercadopago\n .get('/v1/payment_methods')\n .then((response) => response.response)\n .catch((error) => error);\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_421c6c02
[ { "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 mycheckout-checkout-service/src/app/payment-providers/mercadopago/services/cards.service.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { ICardsService } from '../../base/base-cards.interface';\nimport { CustomerDto } from '../../base/dtos/customer.dto';\n\nexport class CardsService implements ICardsService {\n constructor(private readonly mercadopago) {}\n\n createCard(customer, data): Promise<any> {\n const saveCard = (customerData) => {\n const card_data = {\n token: data.token,\n customer: customerData.id,\n issuer_id: data.issuer_id,\n payment_method_id: data.payment_method_id,\n };\n\n return this.mercadopago.cards.create(card_data).then(function (card) {\n return card;\n });\n };\n\n if (!customer.id) {\n const customer_data = { email: customer.email };\n\n return this.mercadopago.customers\n .create(customer_data)\n .then((customerData) => {\n return saveCard(customerData);\n });\n } else {\n const filters = {\n id: customer.id,\n };\n\n this.mercadopago.customers\n .search({\n qs: filters,\n })\n .then((customerData) => {\n return saveCard(customerData);\n });\n }\n }\n\n listOfUserCards(customer: CustomerDto): Promise<any> {\n const filters = {\n id: customer.id,\n };\n return this.mercadopago.customers\n .search({\n qs: filters,\n })\n .then((customerData) => {\n return customerData;\n });\n }\n\n deleteUserCards(token: string, customer: CustomerDto): Promise<any> {\n throw new Error('Method not implemented.');\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_20e58a39
[ { "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 mycheckout-checkout-service/src/app/payment-providers/mercadopago/services/preferences.service.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { OrderDoc } from '../../../orders/schemas/order.schema';\nimport { preference } from '../config/preference';\n\nexport class PreferencesService {\n constructor(private readonly mercadopago) {}\n\n createPreference(order: OrderDoc) {\n return this.mercadopago.preferences\n .create(preference(order))\n .then((res) => res.body)\n .catch((error) => error);\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_9164e68e
[ { "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 mycheckout-checkout-service/src/app/payment-providers/base/dtos/orders.dto.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nexport class OrdersDto {\n amount: number;\n description: string;\n dev_reference?: string;\n vat?: number;\n installments?: number;\n payment_method_id?: any;\n issuer_id?: any;\n}\n\n```" } ]
code_mycheckout-checkout-service_ba8cc559
[ { "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 mycheckout-checkout-service/src/app/payment-providers/base/dtos/customer.dto.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nexport class CustomerDto {\n constructor(o: CustomerDto) {\n Object.assign(this, o);\n }\n\n email: string;\n id: any;\n documentType?: string;\n documentNumber?: string;\n}\n\n```" } ]
code_mycheckout-checkout-service_62ba80d2
[ { "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 mycheckout-checkout-service/src/app/payment-providers/base/dtos/charges.dto.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { ApiError } from '../../../../shared/responses';\nimport { Type } from 'class-transformer';\nimport {\n IsEmail,\n IsNotEmpty,\n IsOptional,\n IsString,\n ValidateNested,\n ValidationArguments,\n} from 'class-validator';\nimport { OrdersDto } from './orders.dto';\n\nexport class ChargesDto {\n /*cardToken arg*/\n //validations\n @IsNotEmpty({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.not_empty', args),\n })\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n //field\n ccToken: string;\n\n @IsOptional()\n @IsString({\n message: (args: ValidationArguments) =>\n ApiError.parse('validations.invalid_string', args),\n })\n cvv?: string;\n\n /*order field*/\n @ValidateNested()\n @Type(() => OrdersDto)\n order: OrdersDto;\n}\n\n```" } ]
code_mycheckout-checkout-service_4742b4e3
[ { "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 mycheckout-checkout-service/src/app/channels/types/services.type.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { AccountsService } from '../../accounts/accounts.service';\nimport { AddressesService } from '../../users/addresses/addresses.service';\nimport { CardsService } from '../../users/cards/cards.service';\nimport { ProfilesService } from '../../users/profiles/profiles.service';\n\nexport type ChannelServices = {\n profilesService: ProfilesService;\n addressesService: AddressesService;\n accountsServices: AccountsService;\n cardsServices: CardsService;\n};\n\nexport enum ChannelName {\n Kuikpay = 'kuikpay',\n Checkout = 'checkout',\n Whatsapp = 'whatsapp',\n}\n\n```" } ]
code_mycheckout-checkout-service_c670dfa1
[ { "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 mycheckout-checkout-service/src/app/channels/standard/index.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { AccountDoc } from '../../accounts/schemas/account.schema';\nimport { OrderDoc, OrderModel } from '../../orders/schemas/order.schema';\nimport { PaymentMethodName } from '../../payment-providers/types/payment-providers.type';\nimport { AddressDoc } from '../../users/addresses/schemas/address.schema';\nimport { ProfileDoc } from '../../users/profiles/schemas/profile.schema';\nimport { NotFoundException } from '../../../shared/exceptions/not-found-exception';\nimport { Channel } from '../channel';\nimport { decrypt } from 'src/shared/utils/encription';\n\nexport class StandardChannel extends Channel {\n async prepare(): Promise<void> {\n const {\n dataDto: {\n profile: { email },\n account: { accountName },\n shipping: { addressId, logisticsInfo },\n },\n headers,\n } = this.ctx;\n\n const promises: [\n Promise<ProfileDoc>,\n Promise<AddressDoc> | AddressDoc,\n Promise<AccountDoc>,\n Promise<void>,\n ] = [\n this.findProfile(email, accountName, headers),\n this.findAddress(addressId),\n this.findAccount(accountName),\n Promise.resolve(),\n ];\n\n const card = {\n token: this.ctx.dataDto.payment.token,\n franchise: this.ctx.dataDto.payment.franchise,\n number: this.ctx.dataDto.payment.number,\n gateway: this.ctx.dataDto.payment.gateway,\n paymentMethod: this.ctx.dataDto.payment.paymentMethod,\n paymentSystem: this.ctx.dataDto.payment.additionalData?.['paymentSystem'],\n cardId: this.ctx.dataDto.payment.cardId,\n bin: this.ctx.dataDto.payment.bin,\n holderName: this.ctx.dataDto.payment.holderName,\n holderDocument: this.ctx.dataDto.payment.holderDocument,\n expirationDate: this.ctx.dataDto.payment.expirationDate,\n cardNumber: this.ctx.dataDto.payment.cardNumber,\n additionalData: this.ctx.dataDto.payment.additionalData,\n cardContent: null,\n aliasCC: null,\n aliasCVV: null,\n internalCardContent: null,\n cvv: this.ctx.dataDto.payment.cvv,\n };\n\n if (this.ctx.dataDto.payment.cardId) {\n promises[3] = new Promise<any>(async (resolve) => {\n const cardData = await this.findCard();\n if (cardData) {\n card.token = decrypt(cardData.token);\n card.franchise = cardData.franchise;\n card.number = cardData.number;\n card.cardContent = cardData.cardContent;\n card.internalCardContent = cardData.internalCardContent;\n card.bin = cardData.bin || card.bin;\n card.holderName = cardData.holderName;\n card.aliasCC = cardData.aliasCC;\n card.expirationDate = cardData.expirationDate;\n card.cardNumber = cardData.cardNumber;\n card.holderDocument = cardData.holderDocument;\n }\n resolve(null);\n });\n }\n\n const [profile, address, account] = await Promise.all(promises);\n\n if (!profile) {\n throw new NotFoundException('errors.user_doesnt_exist');\n }\n\n if (\n !(address && address.geoCoordinates) &&\n logisticsInfo.find((lgi) => lgi.selectedDeliveryChannel === 'delivery')\n ) {\n throw new NotFoundException('errors.address_doesnt_exist');\n }\n const additionalData: any = card.additionalData;\n if (\n !card ||\n (card.paymentMethod === PaymentMethodName.CreditCard &&\n card &&\n !(\n card.token ||\n card.cardNumber ||\n additionalData?.transactionId ||\n card.aliasCVV ||\n additionalData?.accountId\n ))\n ) {\n throw new NotFoundException('errors.card_doesnt_exist');\n }\n\n if (!account) {\n throw new NotFoundException('errors.card_doesnt_exist');\n }\n\n this.ctx.profile = profile;\n this.ctx.addresses = [address];\n this.ctx.account = account;\n this.ctx.payment = card;\n\n this.ctx.queueMessage.profile.profileId = profile.id;\n this.ctx.queueMessage.payment = card;\n this.ctx.queueMessage.account = {\n account: account.account,\n additionalData: account.additionalData?.reduce<Record<string, string>>(\n (\n prev: Record<string, string>,\n item: { key: string; value: string },\n ) => {\n return {\n ...prev,\n [item.key]: item.value,\n };\n },\n {},\n ),\n };\n }\n\n async createOrder(orderModel: OrderModel): Promise<void> {\n const {\n profile,\n addresses,\n account,\n dataDto: {\n channel,\n oms,\n shipping: { logisticsInfo },\n items,\n account: {\n storePreferences: { salesChannel, currencyCode, countryCode },\n },\n customData,\n },\n } = this.ctx;\n\n const dataAdress = addresses[0] || addresses[1];\n const order = orderModel.build({\n channel,\n oms,\n account,\n accountName: account.account,\n creationDate: new Date().toISOString(),\n createdAt: Date.now(),\n log: '',\n user: {\n document: profile.document,\n documentType: profile.documentType,\n lastname: profile.lastname,\n name: profile.name,\n phoneNumber: profile.phoneNumber,\n phoneCode: profile.phoneCode,\n email: profile.email,\n },\n shipping: {\n address: {\n id: dataAdress.id,\n street: dataAdress.street,\n number: dataAdress.number,\n city: dataAdress.city,\n state: dataAdress.state,\n country: dataAdress.country,\n geoCoordinates: dataAdress.geoCoordinates,\n postalCode: dataAdress.postalCode,\n reference: dataAdress.reference,\n receiverName: dataAdress.receiverName,\n neighborhood: dataAdress.neighborhood,\n },\n logisticsInfo: logisticsInfo.map((logisticInfo) => ({\n itemIndex: logisticInfo.itemIndex,\n selectedDeliveryChannel: logisticInfo.selectedDeliveryChannel,\n selectedSla: logisticInfo.selectedSla,\n })),\n },\n country: countryCode,\n currency: currencyCode,\n salesChannel,\n status: 'pending',\n items: items.map((item) => ({\n id: item.id,\n quantity: item.quantity,\n seller: item.seller,\n })),\n customData: customData,\n });\n\n this.ctx.order = await order.save();\n this.ctx.queueMessage.orderId = this.ctx.order.id;\n }\n\n async prepareProcessTransaction(orderModel: OrderModel): Promise<void> {\n const {\n orderId,\n profile: { profileId },\n } = this.ctx.processTransactionDto;\n\n const promises: [Promise<ProfileDoc>, Promise<OrderDoc>] = [\n this.findProfileById(profileId),\n orderModel.get(orderId),\n ];\n\n const [profile, order] = await Promise.all(promises);\n\n this.ctx.profile = profile;\n this.ctx.order = order;\n }\n\n async onProcessTransaction(): Promise<void> {\n const {\n order,\n profile,\n processTransactionDto: {\n account,\n payment,\n omsExtraData: { order: orderVtex },\n totalizers,\n profile: { habeasData },\n shipping: { addressId },\n },\n transaction: { transactionId, token },\n } = this.ctx;\n\n const accountId = payment.additionalData?.accountId;\n if (!accountId) {\n if (\n !payment.cardId &&\n payment.paymentMethod === PaymentMethodName.CreditCard\n ) {\n const cardData = await this.createCard();\n\n payment.cardId = cardData.id;\n } else if (payment.cardId) {\n if (payment.bin) await this.updateCardData({ bin: payment.bin });\n if (payment.paymentSystem)\n await this.updateCardData({ paymentSystem: payment.paymentSystem });\n if (token && account.additionalData?.paymentez == 'true')\n await this.updateCardData({ token });\n }\n\n profile.set({\n selectedPayment: {\n paymentMethod: payment.paymentMethod,\n card: payment.cardId,\n },\n });\n }\n\n order.set({\n orderId: orderVtex.orderGroup,\n total: totalizers.totals,\n totalShipping: totalizers.shippingTotal,\n status: 'approved',\n payment: {\n number: payment.number,\n franchise: payment.franchise,\n transactionId: transactionId,\n gateway: payment.gateway,\n cardId: accountId || (payment.cardId && payment.cardId.toString()),\n paymentMethod: payment.paymentMethod,\n paymentSystem: payment.paymentSystem,\n },\n });\n\n await order.save();\n\n profile.set({\n habeasData: !habeasData ? profile.habeasData : habeasData,\n });\n\n if (addressId)\n profile.set({\n selectedAddress: addressId,\n });\n\n await profile.save();\n\n this.ctx.order = order;\n }\n\n async cancelOrder(orderModel: OrderModel, log = ''): Promise<void> {\n const {\n profile,\n addresses,\n account,\n payment,\n vtex: { order: orderVtex = {} },\n queueMessage: { totalizers },\n dataDto: {\n channel,\n oms,\n shipping: { logisticsInfo },\n items,\n account: {\n storePreferences: { salesChannel, currencyCode, countryCode },\n },\n customData,\n },\n } = this.ctx;\n\n const dataAdress = addresses[0] || addresses[1];\n const order = orderModel.build({\n channel,\n oms,\n account,\n accountName: account.account,\n creationDate: new Date().toISOString(),\n createdAt: Date.now(),\n log,\n orderId: orderVtex.orderGroup || 'null',\n user: {\n document: profile.document,\n documentType: profile.documentType,\n lastname: profile.lastname,\n name: profile.name,\n phoneNumber: profile.phoneNumber,\n phoneCode: profile.phoneCode,\n email: profile.email,\n },\n shipping: {\n address: {\n id: dataAdress.id,\n street: dataAdress.street,\n number: dataAdress.number,\n city: dataAdress.city,\n state: dataAdress.state,\n country: dataAdress.country,\n geoCoordinates: dataAdress.geoCoordinates,\n postalCode: dataAdress.postalCode,\n reference: dataAdress.reference,\n receiverName: dataAdress.receiverName,\n neighborhood: dataAdress.neighborhood,\n },\n logisticsInfo: logisticsInfo.map((logisticInfo) => ({\n itemIndex: logisticInfo.itemIndex,\n selectedDeliveryChannel: logisticInfo.selectedDeliveryChannel,\n selectedSla: logisticInfo.selectedSla,\n })),\n },\n country: countryCode,\n currency: currencyCode,\n salesChannel,\n status: 'cancelled',\n items: items.map((item) => ({\n id: item.id,\n quantity: item.quantity,\n seller: item.seller,\n })),\n customData: customData,\n total: totalizers.totals,\n totalShipping: totalizers.shippingTotal,\n payment: {\n number: payment.number,\n franchise: payment.franchise,\n transactionId: '',\n gateway: payment.gateway,\n cardId: '',\n paymentMethod: payment.paymentMethod,\n paymentSystem: payment.paymentSystem,\n },\n });\n\n this.ctx.order = await order.save();\n this.ctx.queueMessage.orderId = this.ctx.order.id;\n }\n\n async cancelOrderProcessTransaction(log = ''): Promise<void> {\n const {\n order,\n processTransactionDto: {\n payment,\n omsExtraData: { order: orderVtex },\n totalizers,\n },\n } = this.ctx;\n\n order.set({\n orderId: orderVtex.orderGroup,\n total: totalizers.totals,\n totalShipping: totalizers.shippingTotal,\n status: 'cancelled',\n log,\n payment: {\n number: payment.number,\n franchise: payment.franchise,\n transactionId: '',\n gateway: payment.gateway,\n cardId: '',\n paymentMethod: payment.paymentMethod,\n paymentSystem: payment.paymentSystem,\n },\n });\n\n await order.save();\n\n this.ctx.order = order;\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_f1ecc5ce
[ { "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 mycheckout-checkout-service/src/app/channels/kuikpay/index.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { StandardChannel } from '../standard';\n\nexport class KuikpayChannel extends StandardChannel {}\n\n```" } ]
code_mycheckout-checkout-service_0a9f5fce
[ { "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 mycheckout-checkout-service/src/app/channels/whatsapp/index.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { StandardChannel } from '../standard';\n\nexport class WhatsappChannel extends StandardChannel {}\n\n```" } ]
code_mycheckout-checkout-service_2425ef33
[ { "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 mycheckout-checkout-service/src/typings/vtex/checkout.d.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\ninterface CheckoutOrderForm {\n orderFormId: string;\n salesChannel: string;\n country: string;\n loggedIn: boolean;\n isCheckedIn: boolean;\n storeId: string | null;\n checkedInPickupPointId: string | null;\n allowManualPrice: boolean;\n canEditData: boolean;\n userProfileId: string | null;\n userType: string | null;\n ignoreProfileData: boolean;\n value: number;\n messages: any[];\n items: OrderFormItem[];\n selectableGifts: any[];\n totals: Array<{\n id: string;\n name: string;\n value: number;\n }>;\n logisticsInfo: LogisticsInfo[] | null;\n clientProfileData: ClientProfileData | null;\n paymentData: PaymentData;\n marketingData: OrderFormMarketingData | null;\n sellers: Array<{\n id: string;\n name: string;\n logo: string;\n }>;\n clientPreferencesData: {\n locale: string;\n optinNewsLetter: any | null;\n };\n commercialConditionData: any | null;\n storePreferencesData: {\n countryCode: string;\n currencyCode: string;\n currencyFormatInfo: {\n currencyDecimalDigits: number;\n currencyDecimalSeparator: string;\n currencyGroupSeparator: string;\n currencyGroupSize: number;\n startsWithCurrencySymbol: boolean;\n };\n currencyLocale: string;\n currencySymbol: string;\n saveUserData: boolean;\n timeZone: string;\n };\n giftRegistryData: any | null;\n openTextField: any | null;\n invoiceData: any | null;\n customData: any | null;\n itemMetadata: {\n items: MetadataItem[];\n };\n hooksData: any | null;\n ratesAndBenefitsData: {\n rateAndBenefitsIdentifiers: any[];\n teaser: any[];\n };\n subscriptionData: SubscriptionData | null;\n itemsOrdination: any | null;\n}\n\ninterface OrderFormItem {\n id: string;\n name: string;\n detailUrl: string;\n imageUrl: string;\n skuName: string;\n quantity: number;\n uniqueId: string;\n productId: string;\n refId: string;\n ean: string;\n priceValidUntil: string;\n price: number;\n tax: number;\n listPrice: number;\n sellingPrice: number;\n rewardValue: number;\n isGift: boolean;\n parentItemIndex: number | null;\n parentAssemblyBinding: string | null;\n productCategoryIds: string;\n priceTags: string[];\n manualPrice: number;\n measurementUnit: string;\n additionalInfo: {\n brandName: string;\n brandId: string;\n offeringInfo: any | null;\n offeringType: any | null;\n offeringTypeId: any | null;\n };\n offerings: any;\n productCategories: Record<string, string>;\n productRefId: string;\n seller: string;\n sellerChain: string[];\n availability: string;\n unitMultiplier: number;\n skuSpecifications: SKUSpecification[];\n}\n\ninterface SKUSpecification {\n fieldName: string;\n fieldValues: string[];\n}\n\ninterface MetadataItem {\n id: string;\n name: string;\n imageUrl: string;\n detailUrl: string;\n seller: string;\n assemblyOptions: AssemblyOption[];\n skuName: string;\n productId: string;\n refId: string;\n ean: string | null;\n}\n\ninterface CompositionItem {\n id: string;\n minQuantity: number;\n maxQuantity: number;\n initialQuantity: number;\n priceTable: string;\n seller: string;\n}\n\ninterface Composition {\n minQuantity: number;\n maxQuantity: number;\n items: CompositionItem[];\n}\n\ninterface AssemblyOption {\n id: string;\n name: string;\n composition: Composition | null;\n}\n\ninterface SubscriptionDataEntry {\n executionCount: number;\n itemIndex: number;\n plan: {\n frequency: {\n interval: number;\n periodicity: 'YEAR' | 'MONTH' | 'WEEK' | 'DAY';\n };\n type: string;\n // validity: {};\n };\n}\n\ninterface SubscriptionData {\n subscriptions: SubscriptionDataEntry[];\n}\n\ninterface ShippingData {\n address: CheckoutAddress | null;\n logisticsInfo: LogisticsInfo[];\n selectedAddresses: CheckoutAddress[];\n availableAddresses: CheckoutAddress[];\n pickupPoints: PickupPoint[];\n}\n\ninterface PickupPoint {\n friendlyName: string;\n address: CheckoutAddress;\n additionalInfo: string;\n id: string;\n businessHours: BusinessHour[];\n}\n\ninterface LogisticsInfo {\n addressId: string | null;\n deliveryChannels: DeliveryChannel[];\n itemId: string;\n itemIndex: number;\n shipsTo: string[];\n slas: SLA[];\n selectedDeliveryChannel: string | null;\n selectedSla: string | null;\n}\n\ninterface DeliveryChannel {\n id: string;\n}\n\ninterface SLA {\n id: string;\n deliveryChannel: string;\n name: string;\n deliveryIds: DeliveryId[];\n shippingEstimate: string;\n shippingEstimateDate: string | null;\n lockTTL: string | null;\n availableDeliveryWindows: any[];\n deliveryWindow: string | null;\n price: number;\n listPrice: number;\n tax: number;\n pickupStoreInfo: {\n isPickupStore: boolean;\n friendlyName: string | null;\n address: CheckoutAddress | null;\n additionalInfo: any | null;\n dockId: string | null;\n };\n pickupPointId: string | null;\n pickupDistance: number | null;\n polygonName: string | null;\n transitTime: string | null;\n}\n\ninterface DeliveryId {\n courierId: string;\n warehouseId: string;\n dockId: string;\n courierName: string;\n quantity: number;\n}\n\ninterface CheckoutAddress {\n addressId: string;\n addressType: string;\n city: string | null;\n complement: string | null;\n country: string;\n geoCoordinates: number[];\n neighborhood: string | null;\n number: string | null;\n postalCode: string | null;\n receiverName: string | null;\n reference: string | null;\n state: string | null;\n street: string | null;\n isDisposable: boolean;\n}\n\ninterface BusinessHour {\n DayOfWeek: number;\n ClosingTime: string;\n OpeningTime: string;\n}\n\ninterface ClientProfileData {\n email: string;\n firstName: string;\n lastName: string;\n document: string;\n documentType: string;\n phone: string;\n corporateName: string;\n tradeName: string;\n corporateDocument: string;\n stateInscription: string;\n corporatePhone: string;\n isCorporate: boolean;\n profileCompleteOnLoading: boolean;\n profileErrorOnLoading: boolean;\n customerClass: string;\n}\n\ninterface PaymentData {\n installmentOptions: Array<{\n paymentSystem: string;\n bin: string | null;\n paymentName: string | null;\n paymentGroupName: string | null;\n value: number;\n installments: Array<{\n count: number;\n hasInterestRate: false;\n interestRate: number;\n value: number;\n total: number;\n sellerMerchantInstallments: Array<{\n count: number;\n hasInterestRate: false;\n interestRate: number;\n value: number;\n total: number;\n }>;\n }>;\n }>;\n paymentSystems: Array<{\n id: string;\n name: string;\n groupName: string;\n validator: {\n regex: string;\n mask: string;\n cardCodeRegex: string;\n cardCodeMask: string;\n weights: number[];\n useCvv: boolean;\n useExpirationDate: boolean;\n useCardHolderName: boolean;\n useBillingAddress: boolean;\n };\n stringId: string;\n template: string;\n requiresDocument: boolean;\n isCustom: boolean;\n description: string | null;\n requiresAuthentication: boolean;\n dueDate: string;\n availablePayments: any | null;\n }>;\n payments: any[];\n giftCards: any[];\n giftCardMessages: any[];\n availableAccounts: any[];\n availableTokens: any[];\n}\n\ninterface OrderFormMarketingData {\n utmCampaign?: string;\n utmMedium?: string;\n utmSource?: string;\n utmiCampaign?: string;\n utmiPart?: string;\n utmipage?: string;\n marketingTags?: string;\n coupon?: string;\n}\n\ninterface ItemInput {\n id: string;\n quantity: number;\n seller: string;\n}\n\ninterface LogisticInfoInput {\n itemIndex: number;\n selectedSla: string;\n selectedDeliveryChannel: string;\n deliveryWindow?: { startDateUtc: string; endDateUtc: string };\n}\n\n```" } ]
code_mycheckout-checkout-service_c03a6eb8
[ { "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 mycheckout-checkout-service/src/typings/vtex/order.d.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { LogisticInfoDto } from '../../app/orders/dtos/logisticInfo.dto';\n\ninterface OrderVTEX {\n transactionData: TransactionData;\n orders: Order[];\n}\n\ninterface TransactionData {\n merchantTransactions: MerchantTransaction[];\n}\n\ninterface MerchantTransaction {\n id: string;\n merchantName: string;\n transactionId: string;\n payments: Payments[];\n}\n\ninterface Payments {\n paymentSystem: string;\n value: number;\n referenceValue: number;\n}\n\ninterface Order {\n orderId: string;\n orderGroup: string;\n shippingData: ShippingData;\n clientProfileData: ClientProfileData;\n storePreferencesData: {\n currencyCode: string;\n };\n}\n\ninterface OrderCreatedVtex {\n addressId: string;\n currencyCode: string;\n orderGroup: string;\n id: string;\n}\n\ninterface TransactionVtex {\n transactionId: string;\n merchantName: string;\n payments: {\n value: number;\n referenceValue: number;\n paymentSystem: string;\n }[];\n}\n\ninterface TransactionQueue {\n profile: {\n email: string;\n habeasData?: boolean;\n profileId?: string;\n };\n account: {\n account: string;\n additionalData: any;\n };\n payment: {\n number?: string;\n franchise?: string;\n gateway: string;\n cardId?: string;\n token?: string;\n holderName?: string;\n holderDocument: string;\n expirationDate?: string;\n cardNumber?: string;\n cvv?: string;\n bin?: string;\n paymentMethod: string;\n paymentSystem?: string;\n additionalData?: unknown;\n };\n shipping: {\n addressId?: string;\n logisticsInfo: LogisticInfoDto[];\n };\n totalizers: {\n totals: number;\n shippingTotal: number;\n subTotal: number;\n };\n orderId: string;\n reference?: string;\n omsExtraData: unknown;\n hostname: string;\n channel: string;\n oms: string;\n version: string;\n authToken: string;\n}\n\n```" } ]
code_mycheckout-checkout-service_5e63f5ab
[ { "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 mycheckout-checkout-service/src/shared/interceptors/mask.interceptor.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport {\n Injectable,\n ExecutionContext,\n CallHandler,\n NestInterceptor,\n} from '@nestjs/common';\nimport { map } from 'rxjs/operators';\nimport { Observable } from 'rxjs';\nimport { isArray } from 'class-validator';\nimport { JwtService } from '@nestjs/jwt';\nimport { AuthGuard } from '../guards/auth.guard';\nimport { ProfilesService } from '../../app/users/profiles/profiles.service';\n\n@Injectable()\nexport class MaskInterceptor implements NestInterceptor {\n constructor(\n private readonly jwtService: JwtService,\n private readonly usersService: ProfilesService,\n ) {}\n\n async intercept(\n context: ExecutionContext,\n next: CallHandler<any>,\n ): Promise<Observable<any>> {\n const authGuard = await new AuthGuard(\n this.jwtService,\n this.usersService,\n ).canActivate(context);\n const mask = !authGuard;\n return next.handle().pipe(\n map((result) => {\n if (mask) {\n try {\n if (isArray(result)) {\n return result.map((res) => {\n return res.mask();\n });\n } else return result.mask();\n } catch (e) {\n console.log('MASK ERROR', e, JSON.stringify(result));\n }\n }\n return result;\n }),\n );\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_41c06cf4
[ { "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 mycheckout-checkout-service/src/shared/responses/all-exceptions.filter.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport {\n ExceptionFilter,\n Catch,\n ArgumentsHost,\n HttpStatus,\n Logger,\n} from '@nestjs/common';\nimport { I18nService } from 'nestjs-i18n';\nimport { CustomHttpException } from '../exceptions/custom-http-exception';\nimport { ApiError } from './api-error';\nimport { OldException } from './old-exceptions';\n\n@Catch()\nexport class AllExceptionsFilter implements ExceptionFilter {\n private readonly logger = new Logger(AllExceptionsFilter.name);\n constructor(private readonly _i18n: I18nService) {}\n\n async catch(exception: unknown, host: ArgumentsHost) {\n let status, message: any, trace: unknown;\n const ctx = host.switchToHttp();\n const response = ctx.getResponse();\n const request = ctx.getRequest();\n\n if (exception instanceof OldException) {\n status = exception.getStatus();\n message = exception.getResponse();\n message = await this.i18n_traslate(message.message);\n } else if (exception instanceof CustomHttpException) {\n status = exception.getStatus();\n message = await Promise.all(\n exception.serializeErrors().map(async (err) => ({\n ...err,\n message: await this.i18n_translate(err.message),\n })),\n );\n trace = {\n stack: exception.stack,\n message: exception.message,\n data: exception.printError(),\n arguments: exception.parameters,\n };\n exception.printError();\n } else if (exception instanceof Error) {\n status = HttpStatus.INTERNAL_SERVER_ERROR;\n message = String('An error occurred on the server');\n trace = {\n stack: exception.stack,\n message: exception.message,\n };\n }\n\n if (![404, 428].includes(status)) {\n this.logger.error({\n error: message,\n trace,\n path: request.url,\n });\n }\n\n if (request.headers.debug) {\n response.status(status).json({\n error: message,\n trace,\n path: request.url,\n });\n } else {\n response.status(status).json({\n error: message,\n path: request.url,\n });\n }\n }\n\n private i18n_translate(text: string) {\n return this._i18n.translate(text);\n }\n\n private async i18n_traslate(response: any): Promise<any> {\n if (typeof response == 'string') return response;\n if (response instanceof ApiError) {\n return Promise.all(\n response.map(async (err) => {\n return this._i18n.translate(err.message, { args: err.args });\n }),\n )\n .then((resp) => {\n return resp.join(', ');\n })\n .catch(() => {\n return response;\n });\n } else return response.error ? response.error : response;\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_4ffd46d3
[ { "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 mycheckout-checkout-service/src/shared/responses/api-error.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { ValidationArguments } from 'class-validator';\nimport { ExceptionTranslateParse } from './exception-translate-parse';\n\nexport class ApiError extends Array<ExceptionTranslateParse> {\n protected constructor(error?: ApiError[0]) {\n super();\n if (error) this.push(error);\n }\n\n static parse(message: string, args?: Partial<ValidationArguments>) {\n return `${message}|${JSON.stringify({\n property: args.property,\n c0: args.constraints ? args.constraints[0] : null,\n })}`;\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_3c236933
[ { "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 mycheckout-checkout-service/src/shared/responses/exception-translate-parse.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nexport interface ExceptionTranslateParse {\n message: string;\n args: object;\n data?: object;\n}\n\n```" } ]
code_mycheckout-checkout-service_1c34bbb7
[ { "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 mycheckout-checkout-service/src/shared/responses/api-response.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { HttpStatus } from '@nestjs/common';\nimport { ApiError } from './api-error';\nimport { GeneralResponse } from './general-response';\nimport { OldException } from './old-exceptions';\n\nexport class ApiResponse extends ApiError {\n static send(message: string, data?: unknown) {\n return new GeneralResponse(message, data);\n }\n\n static errorWithObject(\n message: string,\n data: Record<string, unknown> = {},\n args: Record<string, unknown> = {},\n status: HttpStatus = HttpStatus.BAD_REQUEST,\n ): OldException {\n return new OldException(\n OldException.createBody(\n new ApiError({ message: message, args: args, data }),\n ),\n status,\n );\n }\n\n static error(\n message: string,\n args: Record<string, unknown> = {},\n status: HttpStatus = HttpStatus.BAD_REQUEST,\n ): OldException {\n return new OldException(\n OldException.createBody(new ApiError({ message: message, args: args })),\n status,\n );\n }\n\n static multipleErrors(\n errors: ApiError,\n status: HttpStatus = HttpStatus.BAD_REQUEST,\n ): OldException {\n const context = new this();\n errors.forEach((error) => {\n context.push({ message: error.message, args: error.args });\n });\n return new OldException(OldException.createBody(context), status);\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_060e5099
[ { "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 mycheckout-checkout-service/src/shared/responses/all-responses.interceptor.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport {\n NestInterceptor,\n ExecutionContext,\n CallHandler,\n Inject,\n} from '@nestjs/common';\nimport { I18nService } from 'nestjs-i18n';\nimport { Observable } from 'rxjs';\nimport { map } from 'rxjs/operators';\nimport { GeneralResponse } from './general-response';\n\nexport class AllResponsesInterceptor implements NestInterceptor {\n constructor(@Inject(I18nService) private readonly _i18n: I18nService) {}\n\n async intercept(\n _context: ExecutionContext,\n next: CallHandler<any>,\n ): Promise<Observable<any>> {\n return await next.handle().pipe(\n map(async (result) => {\n if (result instanceof GeneralResponse) {\n result.message = await this._i18n.translate(result.message);\n if (!result.data) delete result.data;\n }\n return result;\n }),\n );\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_545c08ef
[ { "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 mycheckout-checkout-service/src/shared/responses/index.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nexport * from './api-error';\nexport * from './api-response';\n\n```" } ]
code_mycheckout-checkout-service_05033379
[ { "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 mycheckout-checkout-service/src/shared/responses/general-response.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nexport class GeneralResponse {\n constructor(message: string, data?: any) {\n Object.assign(this, {\n message: message,\n data: data ? data : null,\n });\n }\n\n message: string;\n\n data?: any;\n}\n\n```" } ]
code_mycheckout-checkout-service_5d14f698
[ { "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 mycheckout-checkout-service/src/shared/responses/old-exceptions.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { HttpException } from '@nestjs/common';\n\nexport class OldException extends HttpException {\n constructor(response: string | Record<string, any>, status: number) {\n super(response, status);\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_a1b2afa4
[ { "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 mycheckout-checkout-service/src/shared/utils/validate-cvv.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { ApiResponse } from '../responses';\n\nexport async function ValidateCVV(cvv: string, service: any): Promise<any> {\n try {\n return true;\n } catch {\n throw ApiResponse.error('errors.invalid_cvv');\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_e153b587
[ { "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 mycheckout-checkout-service/src/shared/utils/encription.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst crypt = require('crypto');\n\nconst algorithm = 'aes-256-ctr';\nconst secretKey = 'pTYL1sdmp9WjRRIqCc7rdxs01lwr2dn2';\n\nexport const encrypt = (text) => {\n try {\n const iv = crypt.randomBytes(16);\n const cipher = crypt.createCipheriv(algorithm, secretKey, iv);\n const encrypted = Buffer.concat([cipher.update(text), cipher.final()]);\n\n return Buffer.from(\n `${iv.toString('hex')}|${encrypted.toString('hex')}`,\n ).toString('base64');\n } catch {\n return null;\n }\n};\n\nexport const decrypt = (hash) => {\n try {\n const data = Buffer.from(hash, 'base64').toString('ascii');\n\n const decipher = crypt.createDecipheriv(\n algorithm,\n secretKey,\n Buffer.from(data.split('|')[0], 'hex'),\n );\n\n const decrpyted = Buffer.concat([\n decipher.update(Buffer.from(data.split('|')[1], 'hex')),\n decipher.final(),\n ]);\n return decrpyted.toString();\n } catch {\n return hash;\n }\n};\n\n```" } ]
code_mycheckout-checkout-service_fce55c85
[ { "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 mycheckout-checkout-service/src/shared/utils/object-trim.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nexport const trimObjValues = (obj: unknown): unknown => {\n Object.keys(obj).map(\n (k) =>\n (obj[k] =\n typeof obj[k] == 'string'\n ? obj[k].trim()\n : typeof obj[k] == 'object'\n ? trimObjValues(obj[k])\n : obj[k]),\n );\n return obj;\n};\n\n```" } ]
code_mycheckout-checkout-service_33ec1879
[ { "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 mycheckout-checkout-service/src/shared/utils/object-id.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nexport const ObjectId = function () {\n const timestamp = ((new Date().getTime() / 1000) | 0).toString(16);\n return (\n timestamp +\n 'xxxxxxxxxxxxxxxx'\n .replace(/[x]/g, function () {\n return ((Math.random() * 16) | 0).toString(16);\n })\n .toLowerCase()\n );\n};\n\n```" } ]
code_mycheckout-checkout-service_1763cc79
[ { "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 mycheckout-checkout-service/src/shared/utils/validate-auth.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { ProfilesService } from '../../app/users/profiles/profiles.service';\nimport { JwtService } from '@nestjs/jwt';\n\nexport async function ValidateAuth(\n request: any,\n jwtService: JwtService,\n profilesService: ProfilesService,\n): Promise<any> {\n try {\n const email = request.params.email;\n const verifiedToken = await jwtService.verify(\n request.headers.authorization.replace('Bearer ', ''),\n );\n if (email && email !== verifiedToken.email) return false;\n\n request.user = await profilesService.getById(verifiedToken.id);\n request.user.email = verifiedToken.email;\n request.account = verifiedToken.account;\n return true;\n } catch (error) {\n return false;\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_8e7c9135
[ { "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 mycheckout-checkout-service/src/shared/utils/dynamoose-module.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport {\n ModelDefinition as ModelDefinitionBase,\n DynamooseModule as Base,\n getModelToken,\n} from 'nestjs-dynamoose';\nimport { model as Model, Schema as SchemaBuild } from 'dynamoose';\nimport { Model as IModel } from 'dynamoose/dist/Model';\nimport { DYNAMOOSE_INITIALIZATION } from 'nestjs-dynamoose/dist/dynamoose.constants';\nimport { FunctionType, ModelType } from 'dynamoose/dist/General';\nimport { AnyDocument, Document as DocumentBase } from 'dynamoose/dist/Document';\nimport { SchemaDefinition } from 'dynamoose/dist/Schema';\nimport { classToPlain } from 'class-transformer';\nimport { deleteNull } from './data-array';\nimport { ConditionInitalizer } from 'dynamoose/dist/Condition';\nimport { ObjectId } from './object-id';\n\nconst modelInstances: { [model: string]: ModelType<AnyDocument> } = {};\n\nexport class Schema {\n static build = (def: SchemaDefinition) =>\n new SchemaBuild({\n id: {\n type: String,\n hashKey: true,\n default: ObjectId,\n },\n ...def,\n });\n}\n\nexport declare class Document extends DocumentBase {\n set?: (attrs: Partial<this>) => void;\n save: (this: Document) => Promise<any>;\n id?: string;\n}\n\nexport interface Model<Doc extends Document, Attrs> extends IModel<Doc> {\n build(attrs: Attrs | Doc): Doc;\n findOne: (attrs: ConditionInitalizer) => { exec: () => Promise<Doc> };\n insertMany: (attrs: Attrs[]) => Promise<Doc[]>;\n}\n\nexport class CustomDynamooseModule extends Base {\n static forFeature(models: ModelDefinition[] = []) {\n const providers = createDynamooseProviders(models);\n return {\n module: CustomDynamooseModule,\n providers: providers,\n exports: providers,\n };\n }\n}\n\nexport declare interface ModelDefinition extends ModelDefinitionBase {\n methods?: { [name: string]: FunctionType };\n statics?: { [name: string]: FunctionType };\n population?: (\n config: (\n model: ModelDefinition,\n properties?: string[],\n ) => ModelType<Document>,\n ) => void;\n}\n\nfunction createDynamooseProviders(models: ModelDefinition[] = []) {\n const providers = (models || []).map((model) => ({\n provide: getModelToken(model.name),\n useFactory: () =>\n modelInstances[model.name] || SchemaInstanceFactory(model),\n inject: [DYNAMOOSE_INITIALIZATION],\n }));\n return providers;\n}\n\nexport function SchemaInstanceFactory(model: ModelDefinition) {\n {\n const modelInstance = Model(model.name, model.schema, model.options);\n if (model.serializers) {\n Object.entries(model.serializers).forEach(([key, value]) => {\n modelInstance.serializer.add(key, value);\n });\n }\n model.population?.((modelInfo) => {\n const schema =\n modelInstances[modelInfo.name] || SchemaInstanceFactory(modelInfo);\n model.population = null;\n return schema;\n });\n\n modelInstance.methods.document.set('set', function (attrs) {\n const data = modelInstance.build(attrs);\n delete data.id;\n Object.assign(this, data);\n });\n\n const createFn = modelInstance.create;\n modelInstance.create = async function (data) {\n return createFn(deleteNull(classToPlain(data))) as any;\n };\n\n modelInstance.insertMany = async function (data = []) {\n if (data) {\n const object = [];\n data.map((attrs) => {\n const info = this.build(attrs);\n object.push(info);\n return info;\n });\n await modelInstance.batchPut(object);\n }\n return data;\n };\n\n modelInstance.findOne = (query) => {\n return {\n exec: async () => {\n return modelInstance\n .query(query)\n .exec()\n .then((r) => r[0]);\n },\n };\n };\n\n modelInstance.build = function (attrs) {\n if (!attrs.id) attrs.id = ObjectId();\n attrs = new this(classToPlain(attrs));\n deleteNull(attrs);\n return attrs;\n };\n\n for (const fn in model.methods) {\n if (fn === 'transform') {\n modelInstance.prototype.toJSON = function () {\n model.methods.transform(this);\n return this;\n };\n } else {\n modelInstance.Model.Document.prototype[fn] = model.methods[fn];\n }\n }\n for (const fn in model.statics) {\n modelInstance[fn] = model.statics[fn];\n }\n modelInstances[model.name] = modelInstance;\n return modelInstances[model.name];\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_5985369e
[ { "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 mycheckout-checkout-service/src/shared/utils/data-array.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nexport function splitArrayIntoChunksOfLen(arr, len = 25, cb = (arr) => arr) {\n const chunks = [];\n let i = 0;\n const n = arr.length;\n while (i < n) {\n chunks.push(cb(arr.slice(i, (i += len))));\n }\n return chunks;\n}\n\nexport function deleteNull(attrs) {\n Object.keys(attrs).forEach(\n (index) => attrs[index] === null && delete attrs[index],\n );\n return attrs;\n}\n\n```" } ]
code_mycheckout-checkout-service_4ccc34cd
[ { "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 mycheckout-checkout-service/src/shared/utils/diacritic-sensitive.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nexport const diacriticSensitiveRegex = (string = '') => {\n return string\n .replace(/a/g, '[a,á,à,ä]')\n .replace(/e/g, '[e,é,ë]')\n .replace(/i/g, '[i,í,ï]')\n .replace(/o/g, '[o,ó,ö,ò]')\n .replace(/u/g, '[u,ü,ú,ù]');\n};\n\nexport const diacriticSensitive = (string = '') => {\n return string\n .replace(/á/g, 'a')\n .replace(/à/g, 'a')\n .replace(/ä/g, 'a')\n .replace(/é/g, 'e')\n .replace(/è/g, 'e')\n .replace(/ë/g, 'e')\n .replace(/í/g, 'i')\n .replace(/ì/g, 'i')\n .replace(/ï/g, 'i')\n .replace(/ó/g, 'o')\n .replace(/ò/g, 'o')\n .replace(/ö/g, 'o')\n .replace(/ú/g, 'u')\n .replace(/ù/g, 'u')\n .replace(/ü/g, 'u');\n};\n\n```" } ]
code_mycheckout-checkout-service_0353ef29
[ { "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 mycheckout-checkout-service/src/shared/exceptions/validation-exception.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { HttpStatus } from '@nestjs/common';\nimport { CustomHttpException } from './custom-http-exception';\n\nexport class ValidationException extends CustomHttpException {\n constructor(\n public message: string,\n public trace: unknown,\n parameters?: unknown,\n ) {\n super(message, HttpStatus.BAD_REQUEST, parameters);\n }\n serializeErrors(): { message: string; field?: string }[] {\n return [\n {\n message: this.message,\n },\n ];\n }\n\n printError(): unknown {\n return this.trace;\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_30e75b9a
[ { "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 mycheckout-checkout-service/src/shared/exceptions/not-found-exception.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { HttpStatus } from '@nestjs/common';\nimport { CustomHttpException } from './custom-http-exception';\n\nexport class NotFoundException extends CustomHttpException {\n constructor(public customMessage?: string) {\n super('Resource(s) not found', HttpStatus.NOT_FOUND);\n }\n\n printError() {\n return null;\n }\n\n serializeErrors(): { message: string; field?: string }[] {\n return [\n {\n message: this.customMessage || this.message,\n },\n ];\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_8b868759
[ { "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 mycheckout-checkout-service/src/shared/exceptions/gateway-exception.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { HttpStatus } from '@nestjs/common';\nimport { CustomHttpException } from './custom-http-exception';\n\nexport class GatewayException extends CustomHttpException {\n constructor(\n public message: string,\n public trace: unknown,\n parameters?: unknown,\n ) {\n super(message, HttpStatus.BAD_GATEWAY, parameters);\n }\n serializeErrors(): { message: string; field?: string }[] {\n return [\n {\n message: this.message,\n },\n ];\n }\n\n printError(): unknown {\n return this.trace;\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_c06c2dcd
[ { "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 mycheckout-checkout-service/src/shared/exceptions/forbidden-exception.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { HttpStatus } from '@nestjs/common';\nimport { CustomHttpException } from './custom-http-exception';\n\nexport class ForbiddenException extends CustomHttpException {\n constructor(public customMessage: string) {\n super('Forbidden resource(s)', HttpStatus.FORBIDDEN);\n }\n\n printError() {\n return null;\n }\n\n serializeErrors(): { message: string; field?: string }[] {\n return [\n {\n message: this.customMessage || this.message,\n },\n ];\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_f66ffd37
[ { "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 mycheckout-checkout-service/src/shared/exceptions/custom-http-exception.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { HttpException } from '@nestjs/common';\n\nexport abstract class CustomHttpException extends HttpException {\n parameters: unknown;\n constructor(message, status: number, parameters?: unknown) {\n super(message, status);\n this.parameters = parameters;\n }\n\n abstract printError(): unknown;\n\n abstract serializeErrors(): { message: string; field?: string }[];\n}\n\n```" } ]
code_mycheckout-checkout-service_239ca872
[ { "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 mycheckout-checkout-service/src/shared/transform/transformation-trim.pipe.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { PipeTransform, Injectable } from '@nestjs/common';\nimport { trimObjValues } from '../utils/object-trim';\n\n@Injectable()\nexport class TransformationTrim implements PipeTransform {\n transform(value: any) {\n return trimObjValues(value);\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_ed01ba96
[ { "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 mycheckout-checkout-service/src/shared/guards/auth.guard.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Injectable, CanActivate, ExecutionContext } from '@nestjs/common';\nimport { Observable } from 'rxjs';\nimport { JwtService } from '@nestjs/jwt';\nimport { ValidateAuth } from '../utils/validate-auth';\nimport { ProfilesService } from '../../app/users/profiles/profiles.service';\n\n@Injectable()\nexport class AuthGuard implements CanActivate {\n constructor(\n private readonly jwtService: JwtService,\n private readonly profilesService: ProfilesService,\n ) {}\n\n canActivate(\n context: ExecutionContext,\n ): boolean | Promise<boolean> | Observable<boolean> {\n const request = context.switchToHttp().getRequest();\n return ValidateAuth(request, this.jwtService, this.profilesService);\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_3cd16e86
[ { "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 mycheckout-checkout-service/src/shared/validation/data.validator.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Injectable } from '@nestjs/common';\nimport {\n ValidationArguments,\n ValidatorConstraintInterface,\n} from 'class-validator';\nimport { Connection } from 'typeorm';\n\n@Injectable()\nexport class DataValidator implements ValidatorConstraintInterface {\n protected repository: any;\n protected action: string;\n\n async validate(value: any, args: ValidationArguments) {\n try {\n const val: unknown = eval(\n `this.${this.action}(${JSON.stringify(value)})`,\n );\n return (await (<boolean>val)) == !args.constraints[1];\n } catch {\n return false;\n }\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_277dbefb
[ { "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 mycheckout-checkout-service/src/shared/validation/entity-validation.decorator.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { registerDecorator, ValidationOptions } from 'class-validator';\n\nexport function EntityValidation(\n validator: any,\n args: { entity: string; property?: string; negate?: boolean },\n validationOptions?: ValidationOptions,\n) {\n return function (object: any, propertyName: string) {\n registerDecorator({\n name: 'EntityValidations',\n target: object.constructor,\n propertyName: propertyName,\n options: validationOptions,\n constraints: args.entity\n ? [args.entity, args.property, args.negate]\n : [args],\n validator: validator,\n });\n };\n}\n\n```" } ]
code_mycheckout-checkout-service_6df4c52f
[ { "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 mycheckout-checkout-service/src/shared/validation/validate-params.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { isArray, ValidationArguments } from 'class-validator';\nimport { ApiError } from '../responses/api-error';\n\nexport class ValidateParams {\n validateParam(\n metatype: unknown,\n value: any,\n args: Partial<ValidationArguments>,\n ): { errors; isParam } {\n const types: unknown = [String, Boolean, Number, Array, Object];\n let error: string;\n let isParam = true;\n switch (metatype) {\n case types[0]:\n error = !this.isString(value)\n ? ApiError.parse('validations.invalid_string', args)\n : null;\n break;\n case types[1]:\n error = !this.isBoolean(value)\n ? ApiError.parse('validations.invalid_boolean', args)\n : null;\n break;\n case types[2]:\n error = !this.isNumber(value)\n ? ApiError.parse('validations.invalid_number', args)\n : null;\n break;\n case types[3]:\n error = !this.isArray(value)\n ? ApiError.parse('validations.invalid_array', args)\n : null;\n break;\n case types[4]:\n error = !this.isObject(value)\n ? ApiError.parse('validations.invalid_object', args)\n : null;\n break;\n /*case types[5]:\n error = !this.isObjectID(value)\n ? ApiError.parse('validations.invalid_objectid', args)\n : null;\n break;*/\n default:\n isParam = false;\n break;\n }\n const errors = error ? [{ constraints: { invalid_param: error } }] : [];\n return { errors, isParam };\n }\n\n private isObjectID(value: any): boolean {\n return value && value.match(/^[0-9a-fA-F]{24}$/) !== null;\n }\n\n private isArray(value: any): boolean {\n try {\n return (\n value &&\n /^[\\],:{}\\s]*$/.test(\n value\n .replace(/\\\\[\"\\\\\\/bfnrtu]/g, '@')\n .replace(\n /\"[^\"\\\\\\n\\r]*\"|true|false|null|-?\\d+(?:\\.\\d*)?(?:[eE][+\\-]?\\d+)?/g,\n ']',\n )\n .replace(/(?:^|:|,)(?:\\s*\\[)+/g, ''),\n )\n );\n } catch {\n return isArray(value);\n }\n }\n\n private isBoolean(value: any): boolean {\n return ['true', 'false', '1', '0'].includes(value);\n }\n\n private isNumber(value: any): boolean {\n return !isNaN(value);\n }\n\n private isString(value: any): boolean {\n return (\n value &&\n !(\n (this.isNumber(value) || this.isArray(value) || this.isBoolean(value)) //||\n //this.isObjectID(value)\n )\n );\n }\n\n private isObject(value: any): boolean {\n return (\n value &&\n !(\n this.isNumber(value) ||\n this.isArray(value) ||\n this.isBoolean(value) ||\n this.isObjectID(value)\n )\n );\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_07f79edd
[ { "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 mycheckout-checkout-service/src/shared/validation/validation.pipe.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { ValidationPipe as VP, Injectable } from '@nestjs/common';\nimport { plainToClass } from 'class-transformer';\nimport { validate } from 'class-validator';\nimport { ValidateParams } from './validate-params';\nimport { ArgumentMetadata } from './argument-metadata.interface';\nimport { ApiResponse } from '../responses/api-response';\nimport { ApiError } from '../responses/api-error';\n\n@Injectable()\nexport class ValidationPipe extends VP {\n async transform(value: any, { metatype, data }: ArgumentMetadata) {\n let { errors, isParam } = new ValidateParams().validateParam(\n metatype,\n value,\n { property: data },\n );\n\n let object = plainToClass(metatype, value);\n\n if (!isParam) {\n object =\n Object.getOwnPropertyNames(new metatype()).length > 0\n ? new metatype(value)\n : plainToClass(metatype, value);\n Object.keys(object).forEach(\n (key) => object[key] === undefined && delete object[key],\n );\n\n errors = await validate(object);\n }\n if (errors.length > 0) {\n throw ApiResponse.multipleErrors(this.formatErrors(errors));\n }\n\n return object;\n }\n\n private formatErrors(errors: any[], result: ApiError = []): ApiError {\n errors.forEach((err) => {\n if (err.children?.length > 0) this.formatErrors(err.children, result);\n for (const property in err.constraints) {\n const message = err.constraints[property];\n try {\n let [msg, args] = message.split('|');\n args = JSON.parse(args);\n result.push({ message: msg, args: args });\n } catch {\n result.push({ message: message, args: {} });\n }\n }\n });\n return result;\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_fda2afdd
[ { "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 mycheckout-checkout-service/src/shared/validation/data-validation.decorator.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { registerDecorator, ValidationOptions } from 'class-validator';\n\nexport function DataValidations(\n validator: any,\n args: { negate?: boolean } | any,\n validationOptions?: ValidationOptions,\n) {\n return function (object: any, propertyName: string) {\n registerDecorator({\n name: 'DataValidations',\n target: object.constructor,\n propertyName: propertyName,\n options: validationOptions,\n constraints: args.entity\n ? [args.entity, args.property, args.negate]\n : [args],\n validator: validator,\n });\n };\n}\n\n```" } ]
code_mycheckout-checkout-service_02373679
[ { "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 mycheckout-checkout-service/src/shared/validation/entity.validator.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Injectable } from '@nestjs/common';\nimport {\n ValidationArguments,\n ValidatorConstraintInterface,\n} from 'class-validator';\nimport { Connection } from 'typeorm';\n\n@Injectable()\nexport class EntityValidator implements ValidatorConstraintInterface {\n protected repository: any;\n protected action: string;\n\n constructor(protected readonly connection: Connection) {}\n\n async validate(value: any, args: ValidationArguments) {\n this.repository = this.connection.getRepository(args.constraints[0]);\n const property = args.constraints[1] ? args.constraints[1] : args.property;\n try {\n const val: unknown = eval(\n `this.${this.action}(\"${value}\",\"${property}\")`,\n );\n return (await (<boolean>val)) == !args.constraints[2];\n } catch {\n return false;\n }\n }\n}\n\n```" } ]
code_mycheckout-checkout-service_242cb0c9
[ { "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 mycheckout-checkout-service/src/shared/validation/argument-metadata.interface.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Type, ArgumentMetadata as AM } from '@nestjs/common';\n\nexport interface ArgumentMetadata extends AM {\n metatype?: Type<any> | undefined;\n}\n\n```" } ]
code_mycheckout-checkout-service_35281f12
[ { "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 mycheckout-checkout-service/src/shared/validation/rules/exists.rule.ts from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```typescript\nimport { Injectable } from '@nestjs/common';\n// import { ValidationArguments, ValidatorConstraint } from 'class-validator';\n// import { Connection } from 'typeorm';\n// import { EntityValidator } from '../entity.validator';\n\n// @ValidatorConstraint({ async: true })\n@Injectable()\nexport class ExistsRule /* extends EntityValidator */ {\n // constructor(protected readonly connection: Connection) {\n // super(connection)\n // this.action = this.exists.name\n // }\n // protected async exists(value, property: string) {\n // return (await this.repository.findAndCount({ [property]: value }))[1] > 0\n // }\n // public defaultMessage(args: ValidationArguments) {\n // const exists = args.constraints[2] ? 'already' : 'not'\n // return `${args.constraints[0].name} with the same '${args.property}' ${exists} exists`;\n // }\n}\n\n```" } ]
code_mycheckout-checkout-service_fef5b27a
[ { "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 mycheckout-checkout-service/src/assets/lang/en/errors.json from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```json\n{\n \"bad_request\": \"Bad Request\",\n \"bad_gateway\": \"An unexpected error has occurred\",\n \"internal_error\": \"An unexpected error has occurred\",\n \"external_api_error\": \"An unexpected error has occurred in the external api request\",\n \"not_found\": \"Resource does not exist\",\n \"user_doesnt_exist\": \"User does not exist\",\n \"address_doesnt_exist\": \"Address does not exist\",\n \"card_doesnt_exist\": \"Card does not exist\",\n \"invalid_code\": \"The code you had sent is invalid\",\n \"invalid_cvv\": \"The cvv you had sent is invalid\",\n \"expired_code\": \"The code you had sent has expired\",\n \"locked_action\": \"This action is not available at this time, try later\",\n \"non_existent_code\": \"This user does not have code assign, please login\",\n \"forbidden\": \"Forbidden resource\",\n \"vtex_create_order\": \"Error creating order in VTEX\",\n \"paymentez_create_transaction\": \"Error creating transaction in Paymentez\",\n \"create_transaction\": \"Error creating transaction\",\n \"link_exist\": \"Already exist a link active between these accounts\",\n \"mercadopago_create_transaction\": \"Error creating transaction in Mercadopago\",\n \"process_transaction_queue\": \"Can't create process transaction queue\"\n}\n\n```" } ]
code_mycheckout-checkout-service_7cd5a2f4
[ { "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 mycheckout-checkout-service/src/assets/lang/en/validations.json from the mycheckout-checkout-service VTEX app." }, { "role": "assistant", "content": "Here's the implementation:\n\n```json\n{\n \"field_greater\": \"{property} must not be greater than {c0}\",\n \"field_less\": \"{property} must not be less than {c0}\",\n \"field_integer\": \"{property} must be an integer number\",\n \"field_not_empty\": \"{property} must not be empty\",\n \"invalid_objectid\": \"{property} argument must be a single String of 12 bytes or a string of 24 hex characters\",\n \"invalid_string\": \"{property} argument must be a single String\",\n \"invalid_number\": \"{property} argument must be a single Number\",\n \"invalid_boolean\": \"{property} argument must be a single Boolean\",\n \"invalid_array\": \"{property} argument must be an Array\",\n \"invalid_object\": \"{property} argument must be an Object\",\n \"invalid_value\": \"{property} argument is invalid\",\n \"invalid_email\": \"{property} argument must be a valid email\",\n \"invalid_phone\": \"{property} argument must be a valid phone number\",\n \"not_empty\": \"{property} should not be empty\",\n \"max_length\": \"{property} must be shorter than or equal to {c0} characters\",\n \"exists\": \"{property} already exists\",\n \"non_exists\": \"{property} does not exist\",\n \"invalid_geocoordinate\": \"{property} is not a valid geocoordinate\",\n \"invalid_latitude\": \"{property} is not a valid latitude\",\n \"invalid_longitude\": \"{property} is not a valid longitude\",\n \"invalid_postal_code\": \"{property} is not a valid postal code\",\n \"invalid_credit_card\": \"{property} is not a valid credit card number\"\n}\n```" } ]