-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (33 loc) · 1.11 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const V = require('argument-validator');
const MelhorEnvioBaseClient = require('./core/base-client');
const servicesMelhorEnvio = {
'PAC': 1,
'SEDEX': 2
}
class MelhorEnvio extends MelhorEnvioBaseClient {
// https://docs.melhorenvio.com.br/reference/calculo-de-fretes-por-produtos
async calcFrete(from, to, products, services, options = {}) {
V.string(from, 'from');
V.string(to, 'to');
V.isArray(services);
const servicesSelected = [];
for (const service of services) {
const s = servicesMelhorEnvio[service.toUpperCase()];
if (s) { servicesSelected.push(s); }
}
const res = await this.doRequest('POST', 'api/v2/me/shipment/calculate', {
from: { postal_code: from },
to: { postal_code: to },
products,
options: {
// aviso de recabimento
receipt: false,
// mão própria
own_hand: false
},
services: servicesSelected.join(',')
});
return res;
}
}
module.exports = MelhorEnvio;