Skip to content

Commit eefb123

Browse files
authored
Merge pull request #13 from talesluna/release/1.2.0
Release/1.2.0
2 parents c624bdc + c70cf06 commit eefb123

11 files changed

+237
-336
lines changed

README.md

+88-55
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,39 @@
1-
# RastroJS
1+
# RastroJs
2+
Uma biblioteca Nodejs para rastreamento de encomendas nos Correios.
23

3-
Uma biblioteca JavaScript para rastreamento de encomendas nos Correios.
4+
*Este projeto não é oficial dos Correios e apesar de se alimentar de um sistema web legítimo dos Correios este não realiza integrações com o webservice dos Correios.*
45

6+
![](https://img.shields.io/badge/Node.js-339933?style=flat&logo=nodedotjs&logoColor=white)
7+
![](https://img.shields.io/npm/l/rastrojs?color=blue&label=License)
58

6-
- [Instalação](#instalação)
7-
- [Exemplos](#exemplos)
8-
- [Básico](#exemplo-básico)
9-
- [Com TypeScript](#exemplo-com-typescript)
10-
- [Contribuição](#contribuição)
11-
- [Licença](#licença)
9+
![](https://img.shields.io/npm/dm/rastrojs?label=Downloads&logo=npm)
10+
![](https://img.shields.io/github/issues/talesluna/rastrojs?color=red&label=Issues&logo=github&logoColor=white)
11+
![](https://img.shields.io/github/stars/talesluna/rastrojs?color=yellow&label=Stars&logo=github)
12+
---
1213

14+
[Instalação](#install) - [Exemplos](#examples) - [Respostas](#response) - [Contribuição](#contribution) - [Licença](#license)
1315

14-
## Instalação
15-
```sh
16-
npm install --save rastrojs
17-
```
18-
19-
## Exemplos
20-
21-
### Exemplo Básico
22-
23-
```js
24-
const rastrojs = require('rastrojs');
25-
26-
async function example() {
16+
----
2717

28-
const tracks = await rastrojs.track('JT124720455BR', 'NOT-CODE', 'AA124720455US');
29-
30-
console.log(tracks);
31-
32-
};
33-
34-
example();
18+
## Install
3519

20+
```sh
21+
npm install --save rastrojs
3622
```
3723

38-
### Exemplo com TypeScript
39-
40-
> Certifique-se de incluir "rastrojs" em "types" no tsconfig.json do seu projeto
24+
## Examples
4125

42-
```typescript
26+
```ts
4327
import rastrojs, { RastroJS, Tracking } from 'rastrojs';
4428

29+
// By function
30+
const tracksA = await rastrojs.track('JT124720455BR');
31+
const tracksB = await rastrojs.track(['JT124720455BR', '123']);
32+
const tracksC = await rastrojs.track('JT124720455BR', 'JT124720455BC', '123');
4533

46-
// Funções
47-
async function getObjects() {
48-
49-
const tracks1 = await rastrojs.track('JT124720455BR');
50-
const tracks2 = await rastrojs.track(['JT124720455BR', '123']);
51-
const tracks3 = await rastrojs.track('JT124720455BR', 'JT124720455BC', '123');
5234

53-
console.log(tracks1, tracks2, tracks3);
54-
55-
}
56-
57-
getObjects();
58-
59-
60-
// Classes
61-
class Example extends RastroJS {
35+
// Using classes
36+
class MyDeliveries extends RastroJS {
6237

6338
constructor(private codes: string[]) {
6439
super();
@@ -70,19 +45,77 @@ class Example extends RastroJS {
7045

7146
}
7247

73-
const example = new Example(['JT124720455BR', 'JT124720455BC', '123']);
48+
const myDeliveries = new MyDeliveries(['JT124720455BR', 'JT124720455BC', '123']);
49+
const tracks = await myDeliveries.tracks;
50+
51+
```
52+
53+
> Para TypeScript, certifique-se de incluir "rastrojs" em "types" no tsconfig.json do seu projeto
54+
55+
## Response
56+
57+
### Fields
58+
|Field|Type|Description|Exemple
59+
|-|-|-|-|
60+
|code|String|Código do objeto pesquisado|JT124720455BR
61+
|type|String|Tipo de enconenda segundo os Correios|Registrado Urgente
62+
|isDelivered|Boolean|Flag de entrega|true/false
63+
|postedAt|Date|Data da postagem do objeto|2021-12-22T21:15:00.000Z
64+
|updatedAt|Date|Data da última atualização do objeto|2022-01-07T17:18:00.000Z
65+
|tracks|Array| Lista de eventos registrados do objeto|-
66+
|tracks.locale|String|Local do evento|São Paulo / SP
67+
|tracks.status|String|Status do objeto segundo dos correios|Objeto postado
68+
|tracks.observation|String|Observações do evento registrado|De unidade X para ...
69+
|tracks.trackedAt|Date|Data do evento registrado|2022-01-03T14:26:00.000Z
70+
|error?|String|Mensagem de erro possível|service_unavailable*
71+
|isInvalid?|Boolean|Flag de resposta não esperada (erro)|true*
72+
73+
> *. isInvalid e error só existem em casos de respostas de erro.
7474
75-
example
76-
.tracks
77-
.then(tracks => console.log(tracks));
75+
```js
76+
[
77+
{
78+
code: 'JT124720455BR',
79+
type: 'registrado urgente',
80+
isDelivered: true,
81+
postedAt: 2021-12-22T21:15:00.000Z,
82+
updatedAt: 2022-01-07T17:18:00.000Z,
83+
tracks: [
84+
/* ... */
85+
{
86+
locale: 'sao paulo / sp',
87+
status: 'objeto entregue ao destinatário',
88+
observation: null,
89+
trackedAt: 2022-01-07T17:18:00.000Z
90+
}
91+
]
92+
},
93+
{
94+
code: 'JT124720455CH',
95+
error: 'not_found',
96+
isInvalid: true,
97+
},
98+
{
99+
code: 'JT124720455FR',
100+
error: 'service_unavailable',
101+
isInvalid: true,
102+
}
103+
]
78104
```
79105

80-
## Contribuição
106+
### Errors
107+
|Erro|Description
108+
|-|-|
109+
|invalid_code|O código informado não corresponde ao formato dos correios.
110+
|not_found|A encomenda não foi encontrada no serviços dos correios
111+
|service_unavailable|O serviço web dos correios estava indisponível no momento
112+
|internal_server_error|Ocorreu um erro interno no serviço web dos correios
113+
81114

82-
Veja como em: [CONTRIBUTING.md](./CONTRIBUTING.md)
115+
## Contribution
83116

84-
> Qualquer dúvida ou sugestão: [email protected]
117+
Veja como em: [CONTRIBUTING.md](./CONTRIBUTING.md) - Qualquer dúvida ou sugestão: [email protected]
85118

86-
## Licença
119+
## License
87120

88121
RastroJS é totalmente aberta e está sob licença [MIT](./LICENSE), use a vontade.

examples/example-1.js

-11
This file was deleted.

examples/example-2.ts

-35
This file was deleted.

examples/example.mjs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import rastrojs from 'rastrojs';
2+
3+
(async () => {
4+
const tracks = await rastrojs.track('NX673812505BR', 'NX673812505CH');
5+
console.log(tracks);
6+
})();

examples/example.ts

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import rastrojs, { RastroJS, Tracking } from 'rastrojs';
2+
3+
(async () => {
4+
5+
class MyDeliveries extends RastroJS {
6+
7+
constructor(private codes: string[]) {
8+
super();
9+
}
10+
11+
public get tracks(): Promise<Tracking[]> {
12+
return this.track(this.codes);
13+
}
14+
15+
}
16+
17+
const myDeliveries = new MyDeliveries(['123', 'NX673812505BR']);
18+
19+
const tracks = await myDeliveries.tracks;
20+
const [ other ] = await rastrojs.track('JT124720455BC');
21+
22+
console.log([...tracks, other]);
23+
24+
})();

index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ declare module 'rastrojs' {
1313
postedAt?: Date;
1414
updatedAt?: Date;
1515
isInvalid?: boolean;
16-
error?: 'invalid_code' | 'not_found';
16+
error?: string;
1717
}
1818

1919
export function track(codes: string[]): Promise<Tracking[]>;

0 commit comments

Comments
 (0)