Skip to content

Commit

Permalink
add props
Browse files Browse the repository at this point in the history
  • Loading branch information
lagden committed Jun 7, 2022
1 parent 6336f1a commit 92574fd
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 37 deletions.
80 changes: 47 additions & 33 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tadashi/cep",
"version": "2.1.0",
"version": "2.1.1",
"description": "Busca por CEP diretamente da API dos Correios",
"keywords": [
"cep",
Expand Down Expand Up @@ -37,6 +37,7 @@
"readme.md"
],
"dependencies": {
"@tadashi/hex-id": "2.0.0",
"camaro": "6.1.0",
"got": "12.1.0"
},
Expand All @@ -48,11 +49,11 @@
"eslint": "8.17.0",
"eslint-config-xo": "0.41.0",
"eslint-plugin-unicorn": "42.0.0",
"@snyk/protect": "1.946.0"
"@snyk/protect": "1.947.0"
},
"snyk": true,
"ava": {
"timeout": "30s"
},
"babel": {}
}
}
9 changes: 8 additions & 1 deletion src/lib/service.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// import {inspect} from 'node:util'
import got from 'got'
import hexID from '@tadashi/hex-id'
import {transform} from 'camaro'
import CepError from './cep-error.js'
import dict from './dict.js'
Expand All @@ -10,6 +11,8 @@ const wsdl = {
}

async function service(code) {
const id = hexID()

try {
const xml = `<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://cliente.bean.master.sigep.bsb.correios.com.br/"><soap:Body><tns:consultaCEP><cep>${code}</cep></tns:consultaCEP></soap:Body></soap:Envelope>`
const response = await got.post(wsdl.producao, {
Expand All @@ -26,7 +29,9 @@ async function service(code) {
bairro: '//bairro',
cep: '//cep',
cidade: '//cidade',
complemento: '//complemento2',
complemento: '//complemento',
complemento2: '//complemento2',
end: '//end',
endereco: '//end',
uf: '//uf',
}
Expand All @@ -42,13 +47,15 @@ async function service(code) {

const data = await transform(response.body, template)
return {
id,
success: true,
status: 200,
...data,
}
} catch (error) {
const r = dict.has(error.message) && dict.get(error.message)
const b = {
id,
success: false,
status: 500,
message: error.message,
Expand Down

0 comments on commit 92574fd

Please sign in to comment.