Skip to content

Commit

Permalink
Add route to return the rectification config value
Browse files Browse the repository at this point in the history
  • Loading branch information
rerissondaniel committed Jan 15, 2025
1 parent 6f85bfb commit 2ec80ba
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
6 changes: 6 additions & 0 deletions node/clients/oms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,10 @@ export class OMS extends JanusClient {
order: (id: string) => `${base}/pvt/orders/${id}`,
}
}

public getRmailRetificationConfig() {
return this.http.get('/api/oms/configuration/email-rectification-enabled', {
headers: { VtexIdclientAutCookie: this.context.authToken },
})
}
}
8 changes: 7 additions & 1 deletion node/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import './globals'

import { LRUCache, Service } from '@vtex/api'
import { LRUCache, method, Service } from '@vtex/api'

import { Clients } from './clients'
import { dataSources } from './dataSources'
import { schemaDirectives } from './directives'
import { resolvers } from './resolvers'
import { getEmailRetificationConfig } from './routes'

const TWO_SECONDS_MS = 2 * 1000
const THREE_SECONDS_MS = 3 * 1000
Expand Down Expand Up @@ -62,4 +63,9 @@ export default new Service<Clients, void, CustomContext>({
resolvers,
schemaDirectives,
},
routes: {
'rectification-config': method({
GET: [getEmailRetificationConfig],
}),
},
})
36 changes: 36 additions & 0 deletions node/routes/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
export async function getEmailRetificationConfig(
ctx: Context,
next: () => Promise<any>
) {
try {
const userStoreToken = ctx.vtex.storeUserAuthToken?.split('.')[1] ?? ''

const { account } = JSON.parse(
Buffer.from(userStoreToken, 'base64').toString()
)

if (account !== ctx.vtex.account) {
setForbiddenStatus(ctx)

return
}
} catch (e) {
setForbiddenStatus(ctx)

return
}

//@ts-ignore

Check failure on line 23 in node/routes/index.ts

View workflow job for this annotation

GitHub Actions / Lint

Do not use "// @ts-ignore" because it alters compilation errors

Check failure on line 23 in node/routes/index.ts

View workflow job for this annotation

GitHub Actions / Lint

Expected exception block, space or tab after '//' in comment
ctx.status = 200
//@ts-ignore

Check failure on line 25 in node/routes/index.ts

View workflow job for this annotation

GitHub Actions / Lint

Do not use "// @ts-ignore" because it alters compilation errors

Check failure on line 25 in node/routes/index.ts

View workflow job for this annotation

GitHub Actions / Lint

Expected exception block, space or tab after '//' in comment
ctx.body = await ctx.clients.oms.getRmailRetificationConfig()

await next()
}

function setForbiddenStatus(ctx: Context) {
//@ts-ignore

Check failure on line 32 in node/routes/index.ts

View workflow job for this annotation

GitHub Actions / Lint

Do not use "// @ts-ignore" because it alters compilation errors

Check failure on line 32 in node/routes/index.ts

View workflow job for this annotation

GitHub Actions / Lint

Expected exception block, space or tab after '//' in comment
ctx.status = 403
//@ts-ignore

Check failure on line 34 in node/routes/index.ts

View workflow job for this annotation

GitHub Actions / Lint

Do not use "// @ts-ignore" because it alters compilation errors

Check failure on line 34 in node/routes/index.ts

View workflow job for this annotation

GitHub Actions / Lint

Expected exception block, space or tab after '//' in comment
ctx.body = 'Forbidden'
}
8 changes: 7 additions & 1 deletion node/service.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,11 @@
"timeout": 40,
"minReplicas": 50,
"maxReplicas": 200,
"cpu": 30
"cpu": 30,
"routes": {
"rectification-config": {
"path": "/_v/private/rectification-config",
"public": true
}
}
}

0 comments on commit 2ec80ba

Please sign in to comment.