Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚀 feat(manifest.json): update outbound-access path to include all sub… #2

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"name": "outbound-access",
"attrs": {
"host": "*.myvtex.com",
"path": "/_v/return-request"
"path": "/_v/return-request/*"
}
},
{
Expand Down
3 changes: 2 additions & 1 deletion messages/bg.json
Original file line number Diff line number Diff line change
Expand Up @@ -338,5 +338,6 @@
"return-app.request-return-order-list.table-pagination.text-of": "от",
"return-app.request-return.orders.header": "Заявка за ново връщане",
"return-app.request-return.orders.header.subtitle": "Изберете поръчка, за да започнете процеса по заявка за връщане",
"return-app.return-payment-methods.input-iban-invalid.error": "IBAN е невалиден"
"return-app.return-payment-methods.input-iban-invalid.error": "IBAN е невалиден",
"return-app.return-request-list.table-filters.export-returns": "ЕКСПОРТИРАЙ"
}
21 changes: 1 addition & 20 deletions messages/context.json
Original file line number Diff line number Diff line change
Expand Up @@ -341,24 +341,5 @@
"return-app.request-return-order-list.table-header.select-order": "Select Order",
"return-app.request-return-order-list.table-pagination.text-of": "of",
"return-app.request-return-order-list.table-empty-state-label.no-orders-available": "No orders available for return",
"return-app.return-order-details.page-header.link": "Back to orders",
"return-app.return-order-details.page-header.title": "Return request form",
"return-app.return-order-details.page-header.subtitle": "Select the Product(s) you want to make a Refund",
"return-app.return-order-details.section-products": "Products available for return",
"return-app.return-order-details.section-details": "Contact information",
"return-app.return-order-details.section-payment": "Refund payment method",
"return-app.return-order-details.page-header.creation-date": "Creation Date",
"return-app.return-order-details.table-header.product": "Product",
"return-app.return-order-details.table-header.quantity": "Quantity",
"return-app.return-order-details.table-header.available-to-return": "Available to return",
"return-app.return-order-details.table-header.quantity-to-return": "Quantity to return",
"return-app.return-order-details.table-header.reason": "Reason",
"return-app.return-order-details.table-header.condition": "Condition",
"return-app.return-order-details.setting-provider.error.retry-action": "Try again",
"return-app.return-order-details.setting-provider.error": "There was an error loading app settings.",
"return-app.return-order-details.error.order-not-invoiced": "The order is not invoiced",
"return-app.return-order-details.error.out-of-max-days": "The order exceeds the maximum return period",
"return-app.return-order-details.error.order-not-found": "Order not found",
"return-app.return-order-details.error.forbidden": "You don't have access to this order",
"return-app.return-order-details.error.unknown": "Something failed, please try again."
"return-app.return-request-list.table-filters.export-returns": "EXPORT"
}
3 changes: 2 additions & 1 deletion messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -340,5 +340,6 @@
"return-app.return-order-details.error.out-of-max-days": "The order exceeds the maximum return period",
"return-app.return-order-details.error.order-not-found": "Order not found",
"return-app.return-order-details.error.forbidden": "You don't have access to this order",
"return-app.return-order-details.error.unknown": "Something failed, please try again."
"return-app.return-order-details.error.unknown": "Something failed, please try again.",
"return-app.return-request-list.table-filters.export-returns": "EXPORT"
}
3 changes: 2 additions & 1 deletion messages/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -338,5 +338,6 @@
"return-app.request-return-order-list.table-header.select-order": "Seleccionar pedido",
"return-app.request-return-order-list.table-pagination.text-of": "de",
"return-app.request-return-order-list.table-empty-state-label.no-orders-available": "No hay pedidos disponibles para devolución",
"return-app.return-payment-methods.input-iban-invalid.error": "El IBAN no es válido"
"return-app.return-payment-methods.input-iban-invalid.error": "El IBAN no es válido",
"return-app.return-request-list.table-filters.export-returns": "EXPORTAR"
}
3 changes: 2 additions & 1 deletion messages/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -338,5 +338,6 @@
"return-app.request-return-order-list.table-pagination.text-of": "de",
"return-app.request-return.orders.header": "Demander un nouveau retour",
"return-app.request-return.orders.header.subtitle": "Sélectionnez une commande pour commencer le processus de demande de retour",
"return-app.return-payment-methods.input-iban-invalid.error": "L'IBAN n'est pas valide"
"return-app.return-payment-methods.input-iban-invalid.error": "L'IBAN n'est pas valide",
"return-app.return-request-list.table-filters.export-returns": "EXPORTER"
}
3 changes: 2 additions & 1 deletion messages/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -338,5 +338,6 @@
"return-app.request-return-order-list.table-pagination.text-of": "di",
"return-app.request-return.orders.header": "Richiedi un nuovo reso",
"return-app.request-return.orders.header.subtitle": "Seleziona un ordine per avviare il processo di richiesta di reso",
"return-app.return-payment-methods.input-iban-invalid.error": "L'IBAN non è valido"
"return-app.return-payment-methods.input-iban-invalid.error": "L'IBAN non è valido",
"return-app.return-request-list.table-filters.export-returns": "ESPORTA"
}
3 changes: 2 additions & 1 deletion messages/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -338,5 +338,6 @@
"return-app.request-return-order-list.table-pagination.text-of": "van",
"return-app.request-return.orders.header": "Nieuwe retouraanvraag",
"return-app.request-return.orders.header.subtitle": "Selecteer een bestelling om het retouraanvraagproces te starten",
"return-app.return-payment-methods.input-iban-invalid.error": "IBAN is niet geldig"
"return-app.return-payment-methods.input-iban-invalid.error": "IBAN is niet geldig",
"return-app.return-request-list.table-filters.export-returns": "EXPORTEREN"
}
3 changes: 2 additions & 1 deletion messages/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -338,5 +338,6 @@
"return-app.request-return-order-list.table-pagination.text-of": "de",
"return-app.request-return.orders.header": "Solicitar Nova Devolução",
"return-app.request-return.orders.header.subtitle": "Selecione um pedido para iniciar o processo de solicitação de devolução",
"return-app.return-payment-methods.input-iban-invalid.error": "O IBAN não é válido"
"return-app.return-payment-methods.input-iban-invalid.error": "O IBAN não é válido",
"return-app.return-request-list.table-filters.export-returns": "EXPORTAR"
}
3 changes: 2 additions & 1 deletion messages/ro.json
Original file line number Diff line number Diff line change
Expand Up @@ -338,5 +338,6 @@
"return-app.request-return-order-list.table-pagination.text-of": "din",
"return-app.request-return.orders.header": "Solicitați o Nouă Returnare",
"return-app.request-return.orders.header.subtitle": "Selectați o comandă pentru a începe procesul de solicitare de returnare",
"return-app.return-payment-methods.input-iban-invalid.error": "IBAN nu este valid"
"return-app.return-payment-methods.input-iban-invalid.error": "IBAN nu este valid",
"return-app.return-request-list.table-filters.export-returns": "EXPORTĂ"
}
3 changes: 2 additions & 1 deletion messages/th.json
Original file line number Diff line number Diff line change
Expand Up @@ -338,5 +338,6 @@
"return-app.request-return-order-list.table-pagination.text-of": "от",
"return-app.request-return.orders.header": "Заявка за ново връщане",
"return-app.request-return.orders.header.subtitle": "Изберете поръчка, за да започнете процеса по заявка за връщане",
"return-app.return-payment-methods.input-iban-invalid.error": "IBAN е невалиден"
"return-app.return-payment-methods.input-iban-invalid.error": "IBAN е невалиден",
"return-app.return-request-list.table-filters.export-returns": "ส่งออก"
}
133 changes: 92 additions & 41 deletions node/clients/return.ts
Original file line number Diff line number Diff line change
@@ -1,121 +1,172 @@
import { InstanceOptions, IOContext, ResolverError } from '@vtex/api'
import { ExternalClient } from '@vtex/api'
import type { InstanceOptions, IOContext } from '@vtex/api'
import { ResolverError, ExternalClient } from '@vtex/api'

const defaultAccount = 'obidev'
const workspace = 'nmanrique'
const baseURL = 'myvtex.com/_v/return-request'

const routes = {
returnByID: (parentAccountName: string , returnId: string) => `http://nmanrique--${parentAccountName}.${baseURL}/${returnId}`,
createReturn: (parentAccountName: string) => `http://nmanrique--${parentAccountName}.${baseURL}`,
returnList: (parentAccountName: string) => `http://nmanrique--${parentAccountName}.${baseURL}`,
returnByID: (parentAccountName: string, returnId: string) =>
`http://${workspace}--${
parentAccountName ?? defaultAccount
}.${baseURL}/${returnId}`,
createReturn: (parentAccountName: string) =>
`http://${workspace}--${parentAccountName ?? defaultAccount}.${baseURL}`,
returnList: (parentAccountName: string) =>
`http://${workspace}--${parentAccountName ?? defaultAccount}.${baseURL}`,
exportReturns: (parentAccountName: string) =>
`http://${workspace}--${
parentAccountName ?? defaultAccount
}.${baseURL}/export`,
}

export class Return extends ExternalClient {
constructor(ctx: IOContext, options?: InstanceOptions) {
super('', ctx, options)
}

public async get ( id : string , accountInfo : any , param : [String]) : Promise<any | undefined> {
public async get(
id: string,
accountInfo: any,
param: [string]
): Promise<any | undefined> {
try {
const params = {
_orderId : id,
_filter: param[0]
_orderId: id,
_filter: param[0],
}

const response = await this.http.get(
routes.returnList(accountInfo.parentAccountName),

{
params,
headers: {
VtexIdClientAutCookie: this.context.adminUserAuthToken || "",
VtexIdClientAutCookie: this.context.adminUserAuthToken || '',
'X-Vtex-Use-Https': 'true',
}
},
}
)
return response

return response
} catch (error) {
throw new ResolverError('Error get')
}
}

}

public async getReturnList ( params : any , accountInfo : any ) : Promise<any | undefined> {
public async getReturnList(
params: any,
accountInfo: any
): Promise<any | undefined> {
console.info('route: ', routes.returnList(accountInfo.parentAccountName))
console.info('params: ', params)
try {
const response = await this.http.get(
routes.returnList(accountInfo.parentAccountName),
{
params,
headers: {
VtexIdClientAutCookie: this.context.adminUserAuthToken || "",
VtexIdClientAutCookie: this.context.adminUserAuthToken || '',
'X-Vtex-Use-Https': 'true',
}
},
}
)
return response

return response
} catch (error) {
throw new ResolverError('Error getReturnList')
}

}

public async getReturnById ( returnId : any , accountInfo : any ) : Promise<any | undefined> {

public async getReturnById(
returnId: any,
accountInfo: any
): Promise<any | undefined> {
try {
const response = await this.http.get(
routes.returnByID(accountInfo.parentAccountName , returnId),
routes.returnByID(accountInfo.parentAccountName, returnId),
{
headers: {
VtexIdClientAutCookie: this.context.adminUserAuthToken || "",
VtexIdClientAutCookie: this.context.adminUserAuthToken || '',
'X-Vtex-Use-Https': 'true',
}
},
}
)
return response

return response
} catch (error) {
throw new ResolverError('Error getReturnById')
}
}

}


public async updateReturn ( returnId : any , updatedRequest:any , accountInfo : any ) : Promise<any | undefined> {
public async updateReturn(
returnId: any,
updatedRequest: any,
accountInfo: any
): Promise<any | undefined> {
try {
const response = await this.http.put(
routes.returnByID(accountInfo.parentAccountName , returnId),
routes.returnByID(accountInfo.parentAccountName, returnId),
updatedRequest,
{
headers: {
VtexIdClientAutCookie: this.context.adminUserAuthToken || "",
VtexIdClientAutCookie: this.context.adminUserAuthToken || '',
'X-Vtex-Use-Https': 'true',
}
},
}
)
return response

return response
} catch (error) {
throw new ResolverError('Error updateReturn')
}
}

}

public async createReturn ( createRequest:any , accountInfo : any ) : Promise<any | undefined> {
public async createReturn(
createRequest: any,
accountInfo: any
): Promise<any | undefined> {
try {
const response = await this.http.post(
routes.createReturn(accountInfo.parentAccountName ),
routes.createReturn(accountInfo.parentAccountName),
createRequest,
{
headers: {
VtexIdClientAutCookie: this.context.adminUserAuthToken || "",
VtexIdClientAutCookie: this.context.adminUserAuthToken || '',
'X-Vtex-Use-Https': 'true',
}
},
}
)
return response

return response
} catch (error) {
throw new ResolverError('Error createReturn')
}
}

public async exportReturns(
params: any,
accountInfo: any
): Promise<any | undefined> {
try {
const response = await this.http.get(
routes.exportReturns(accountInfo.parentAccountName),
{
params: {
_sellerName: this.context.account,
...params,
},
headers: {
VtexIdClientAutCookie: this.context.adminUserAuthToken ?? '',
'X-Vtex-Use-Https': true,
},
}
)

}
return response
} catch (error) {
console.info('message: ', error)
throw new ResolverError('Error generateExport')
}
}
}
9 changes: 7 additions & 2 deletions node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import type {
RecorderState,
ParamsContext,
} from '@vtex/api'
import { Service, LRUCache } from '@vtex/api'
import { method, Service, LRUCache } from '@vtex/api'

import { Clients } from './clients'
import { mutations, queries, resolvers } from './resolvers'
import { exportRequests } from './middlewares/exportRequests'
import { schemaDirectives } from './directives'

const TIMEOUT_MS = 10000
Expand Down Expand Up @@ -39,7 +40,11 @@ declare global {

export default new Service<Clients, State, ParamsContext>({
clients,
routes: {},
routes: {
exportRequests: method({
GET: [exportRequests],
}),
},
graphql: {
resolvers: {
...resolvers,
Expand Down
29 changes: 29 additions & 0 deletions node/middlewares/exportRequests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export async function exportRequests(ctx: Context, next: () => Promise<void>) {
const {
query,
clients: { return: returnClient, account },
} = ctx

const { _dateSubmitted } = query

try {
const accountInfo = await account.getInfo()

if (!_dateSubmitted) {
throw new Error("The '_dateSubmitted' query parameter is required")
}

const exports = await returnClient.exportReturns(query, accountInfo)

ctx.status = 200
ctx.set('Content-Type', 'application/csv')
ctx.set('Content-Disposition', `attachment; filename=request.csv`)
ctx.body = exports
} catch (error) {
ctx.status = 500
ctx.body = { error: error.message }
}

ctx.set('Cache-Control', 'no-cache')
await next()
}
7 changes: 6 additions & 1 deletion node/service.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@
"timeout": 5000,
"minReplicas": 2,
"maxReplicas": 4,
"routes": {}
"routes": {
"exportRequests": {
"path": "/_v/return-request/export",
"public": true
}
}
}
Loading