iptuapi 1.2.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +230 -44
- package/dist/index.d.mts +276 -78
- package/dist/index.d.ts +276 -78
- package/dist/index.js +450 -98
- package/dist/index.mjs +444 -97
- package/package.json +25 -3
package/README.md
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
# IPTU API - JavaScript/TypeScript SDK
|
|
2
2
|
|
|
3
|
-
SDK oficial para
|
|
3
|
+
SDK oficial JavaScript/TypeScript para integracao com a IPTU API. Acesso a dados de IPTU de mais de 10 cidades brasileiras.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[](https://www.npmjs.com/package/iptuapi)
|
|
6
|
+
[](https://www.typescriptlang.org/)
|
|
7
|
+
[](LICENSE)
|
|
8
|
+
|
|
9
|
+
## Instalacao
|
|
6
10
|
|
|
7
11
|
```bash
|
|
8
12
|
npm install iptuapi
|
|
@@ -12,21 +16,14 @@ yarn add iptuapi
|
|
|
12
16
|
pnpm add iptuapi
|
|
13
17
|
```
|
|
14
18
|
|
|
15
|
-
##
|
|
16
|
-
|
|
17
|
-
| Cidade | Código | Identificador |
|
|
18
|
-
|--------|--------|---------------|
|
|
19
|
-
| São Paulo | `sao_paulo` | Número SQL |
|
|
20
|
-
| Belo Horizonte | `belo_horizonte` | Índice Cadastral |
|
|
21
|
-
|
|
22
|
-
## Uso Rápido
|
|
19
|
+
## Uso Rapido
|
|
23
20
|
|
|
24
21
|
```typescript
|
|
25
22
|
import { IPTUClient } from 'iptuapi';
|
|
26
23
|
|
|
27
24
|
const client = new IPTUClient('sua_api_key');
|
|
28
25
|
|
|
29
|
-
// Consulta por
|
|
26
|
+
// Consulta por endereco
|
|
30
27
|
const resultado = await client.consultaEndereco('Avenida Paulista', '1000');
|
|
31
28
|
console.log(resultado);
|
|
32
29
|
|
|
@@ -34,81 +31,270 @@ console.log(resultado);
|
|
|
34
31
|
const dados = await client.consultaSQL('100-01-001-001');
|
|
35
32
|
```
|
|
36
33
|
|
|
37
|
-
##
|
|
34
|
+
## Configuracao
|
|
35
|
+
|
|
36
|
+
### Cliente Basico
|
|
38
37
|
|
|
39
38
|
```typescript
|
|
40
|
-
import { IPTUClient
|
|
39
|
+
import { IPTUClient } from 'iptuapi';
|
|
41
40
|
|
|
42
41
|
const client = new IPTUClient('sua_api_key');
|
|
42
|
+
```
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
const resultadosSP = await client.consultaIPTU('sao_paulo', 'Avenida Paulista', 1000, 2024);
|
|
46
|
-
for (const imovel of resultadosSP) {
|
|
47
|
-
console.log(`SQL: ${imovel.sql}, Valor Venal: R$ ${imovel.valor_venal.toLocaleString()}`);
|
|
48
|
-
}
|
|
44
|
+
### Configuracao Avancada
|
|
49
45
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
46
|
+
```typescript
|
|
47
|
+
import { IPTUClient, ClientConfig, RetryConfig } from 'iptuapi';
|
|
48
|
+
|
|
49
|
+
const retryConfig: RetryConfig = {
|
|
50
|
+
maxRetries: 5,
|
|
51
|
+
initialDelayMs: 1000,
|
|
52
|
+
maxDelayMs: 30000,
|
|
53
|
+
backoffFactor: 2.0,
|
|
54
|
+
retryableStatuses: [429, 500, 502, 503, 504]
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const config: ClientConfig = {
|
|
58
|
+
baseUrl: 'https://iptuapi.com.br/api/v1',
|
|
59
|
+
timeout: 60000,
|
|
60
|
+
retryConfig,
|
|
61
|
+
logger: console // ou seu logger customizado
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const client = new IPTUClient('sua_api_key', config);
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Logging Customizado
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
import { IPTUClient, Logger } from 'iptuapi';
|
|
71
|
+
|
|
72
|
+
const customLogger: Logger = {
|
|
73
|
+
debug: (msg, meta) => console.debug(`[IPTU] ${msg}`, meta),
|
|
74
|
+
info: (msg, meta) => console.info(`[IPTU] ${msg}`, meta),
|
|
75
|
+
warn: (msg, meta) => console.warn(`[IPTU] ${msg}`, meta),
|
|
76
|
+
error: (msg, meta) => console.error(`[IPTU] ${msg}`, meta)
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const client = new IPTUClient('sua_api_key', { logger: customLogger });
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Endpoints da API
|
|
83
|
+
|
|
84
|
+
### Consultas (Todos os Planos)
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
// Consulta por endereco
|
|
88
|
+
const resultado = await client.consultaEndereco('Avenida Paulista', '1000', 'sp');
|
|
55
89
|
|
|
56
|
-
//
|
|
57
|
-
|
|
58
|
-
const dadosSP = await client.consultaIPTUSQL('sao_paulo', '00904801381');
|
|
90
|
+
// Consulta por CEP
|
|
91
|
+
const resultado = await client.consultaCEP('01310-100', 'sp');
|
|
59
92
|
|
|
60
|
-
//
|
|
61
|
-
const
|
|
93
|
+
// Consulta por coordenadas (zoneamento)
|
|
94
|
+
const resultado = await client.consultaZoneamento(-23.5505, -46.6333);
|
|
62
95
|
```
|
|
63
96
|
|
|
64
|
-
|
|
97
|
+
### Consultas Avancadas (Starter+)
|
|
65
98
|
|
|
66
99
|
```typescript
|
|
100
|
+
// Consulta por numero SQL
|
|
101
|
+
const resultado = await client.consultaSQL('100-01-001-001', 'sp');
|
|
102
|
+
|
|
103
|
+
// Historico de valores IPTU
|
|
104
|
+
const historico = await client.dadosIPTUHistorico('100-01-001-001', 'sp');
|
|
105
|
+
|
|
106
|
+
// Consulta CNPJ
|
|
107
|
+
const empresa = await client.dadosCNPJ('12345678000100');
|
|
108
|
+
|
|
109
|
+
// Correcao monetaria IPCA
|
|
110
|
+
const corrigido = await client.dadosIPCACorrigir(100000, '2020-01', '2024-01');
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Valuation (Pro+)
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
// Estimativa de valor de mercado
|
|
67
117
|
const avaliacao = await client.valuationEstimate({
|
|
68
118
|
area_terreno: 250,
|
|
69
119
|
area_construida: 180,
|
|
70
120
|
bairro: 'Pinheiros',
|
|
71
121
|
zona: 'ZM',
|
|
72
122
|
tipo_uso: 'Residencial',
|
|
73
|
-
tipo_padrao: '
|
|
74
|
-
ano_construcao: 2010
|
|
123
|
+
tipo_padrao: 'Medio',
|
|
124
|
+
ano_construcao: 2010
|
|
75
125
|
});
|
|
76
126
|
console.log(`Valor estimado: R$ ${avaliacao.valor_estimado.toLocaleString()}`);
|
|
127
|
+
|
|
128
|
+
// Buscar comparaveis
|
|
129
|
+
const comparaveis = await client.valuationComparables({
|
|
130
|
+
bairro: 'Pinheiros',
|
|
131
|
+
areaMin: 150,
|
|
132
|
+
areaMax: 250,
|
|
133
|
+
cidade: 'sp',
|
|
134
|
+
limit: 10
|
|
135
|
+
});
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Batch Operations (Enterprise)
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
// Valuation em lote (ate 100 imoveis)
|
|
142
|
+
const imoveis = [
|
|
143
|
+
{ area_terreno: 250, area_construida: 180, bairro: 'Pinheiros' },
|
|
144
|
+
{ area_terreno: 300, area_construida: 200, bairro: 'Moema' }
|
|
145
|
+
];
|
|
146
|
+
const resultados = await client.valuationBatch(imoveis);
|
|
77
147
|
```
|
|
78
148
|
|
|
79
149
|
## Tratamento de Erros
|
|
80
150
|
|
|
81
151
|
```typescript
|
|
82
|
-
import {
|
|
152
|
+
import {
|
|
153
|
+
IPTUClient,
|
|
154
|
+
IPTUAPIError,
|
|
155
|
+
AuthenticationError,
|
|
156
|
+
ForbiddenError,
|
|
157
|
+
NotFoundError,
|
|
158
|
+
RateLimitError,
|
|
159
|
+
ValidationError,
|
|
160
|
+
ServerError,
|
|
161
|
+
TimeoutError,
|
|
162
|
+
NetworkError
|
|
163
|
+
} from 'iptuapi';
|
|
83
164
|
|
|
84
165
|
const client = new IPTUClient('sua_api_key');
|
|
85
166
|
|
|
86
167
|
try {
|
|
87
|
-
const resultado = await client.
|
|
168
|
+
const resultado = await client.consultaEndereco('Rua Teste', '100');
|
|
88
169
|
} catch (error) {
|
|
89
|
-
if (error instanceof
|
|
90
|
-
console.log('
|
|
170
|
+
if (error instanceof AuthenticationError) {
|
|
171
|
+
console.log('API Key invalida');
|
|
172
|
+
} else if (error instanceof ForbiddenError) {
|
|
173
|
+
console.log(`Plano nao autorizado. Requer: ${error.requiredPlan}`);
|
|
174
|
+
} else if (error instanceof NotFoundError) {
|
|
175
|
+
console.log('Imovel nao encontrado');
|
|
91
176
|
} else if (error instanceof RateLimitError) {
|
|
92
|
-
console.log(
|
|
177
|
+
console.log(`Rate limit excedido. Retry em ${error.retryAfter}s`);
|
|
178
|
+
} else if (error instanceof ValidationError) {
|
|
179
|
+
console.log('Parametros invalidos:', error.errors);
|
|
180
|
+
} else if (error instanceof ServerError) {
|
|
181
|
+
console.log('Erro no servidor (retryable)');
|
|
182
|
+
} else if (error instanceof TimeoutError) {
|
|
183
|
+
console.log(`Timeout apos ${error.timeoutMs}ms`);
|
|
184
|
+
} else if (error instanceof NetworkError) {
|
|
185
|
+
console.log('Erro de conexao');
|
|
186
|
+
} else if (error instanceof IPTUAPIError) {
|
|
187
|
+
console.log(`Erro: ${error.message}, Request ID: ${error.requestId}`);
|
|
93
188
|
}
|
|
94
189
|
}
|
|
95
190
|
```
|
|
96
191
|
|
|
97
|
-
|
|
192
|
+
### Propriedades dos Erros
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
try {
|
|
196
|
+
const resultado = await client.consultaEndereco('Rua Teste', '100');
|
|
197
|
+
} catch (error) {
|
|
198
|
+
if (error instanceof IPTUAPIError) {
|
|
199
|
+
console.log(`Status Code: ${error.statusCode}`);
|
|
200
|
+
console.log(`Request ID: ${error.requestId}`);
|
|
201
|
+
console.log(`Retryable: ${error.isRetryable}`);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
```
|
|
98
205
|
|
|
99
|
-
|
|
206
|
+
## Rate Limiting
|
|
207
|
+
|
|
208
|
+
```typescript
|
|
209
|
+
// Verificar rate limit apos requisicao
|
|
210
|
+
const rateLimit = client.getRateLimitInfo();
|
|
211
|
+
if (rateLimit) {
|
|
212
|
+
console.log(`Limite: ${rateLimit.limit}`);
|
|
213
|
+
console.log(`Restantes: ${rateLimit.remaining}`);
|
|
214
|
+
console.log(`Reset em: ${new Date(rateLimit.reset * 1000)}`);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// ID da ultima requisicao (util para suporte)
|
|
218
|
+
console.log(`Request ID: ${client.getLastRequestId()}`);
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## Tipos TypeScript
|
|
100
222
|
|
|
101
223
|
```typescript
|
|
102
224
|
import type {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
225
|
+
ClientConfig,
|
|
226
|
+
RetryConfig,
|
|
227
|
+
RateLimitInfo,
|
|
228
|
+
PropertyData,
|
|
107
229
|
ValuationParams,
|
|
108
230
|
ValuationResult,
|
|
231
|
+
ComparableProperty,
|
|
232
|
+
ZoningInfo,
|
|
233
|
+
IPTUHistoryItem
|
|
109
234
|
} from 'iptuapi';
|
|
235
|
+
|
|
236
|
+
// Exemplo de uso com tipos
|
|
237
|
+
const config: ClientConfig = {
|
|
238
|
+
timeout: 30000
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
const params: ValuationParams = {
|
|
242
|
+
area_terreno: 250,
|
|
243
|
+
area_construida: 180,
|
|
244
|
+
bairro: 'Pinheiros'
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
const resultado: ValuationResult = await client.valuationEstimate(params);
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
## Browser Support
|
|
251
|
+
|
|
252
|
+
O SDK funciona tanto em Node.js quanto em browsers modernos:
|
|
253
|
+
|
|
254
|
+
```html
|
|
255
|
+
<script type="module">
|
|
256
|
+
import { IPTUClient } from 'https://unpkg.com/iptuapi@latest/dist/browser.js';
|
|
257
|
+
|
|
258
|
+
const client = new IPTUClient('sua_api_key');
|
|
259
|
+
const resultado = await client.consultaEndereco('Avenida Paulista', '1000');
|
|
260
|
+
console.log(resultado);
|
|
261
|
+
</script>
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
## Testes
|
|
265
|
+
|
|
266
|
+
```bash
|
|
267
|
+
# Rodar testes
|
|
268
|
+
npm test
|
|
269
|
+
|
|
270
|
+
# Watch mode
|
|
271
|
+
npm run test:watch
|
|
272
|
+
|
|
273
|
+
# Coverage
|
|
274
|
+
npm run test:coverage
|
|
110
275
|
```
|
|
111
276
|
|
|
112
|
-
##
|
|
277
|
+
## Cidades Suportadas
|
|
278
|
+
|
|
279
|
+
| Codigo | Cidade |
|
|
280
|
+
|--------|--------|
|
|
281
|
+
| sp | Sao Paulo |
|
|
282
|
+
| rj | Rio de Janeiro |
|
|
283
|
+
| bh | Belo Horizonte |
|
|
284
|
+
| recife | Recife |
|
|
285
|
+
| curitiba | Curitiba |
|
|
286
|
+
| poa | Porto Alegre |
|
|
287
|
+
| salvador | Salvador |
|
|
288
|
+
| fortaleza | Fortaleza |
|
|
289
|
+
| campinas | Campinas |
|
|
290
|
+
| santos | Santos |
|
|
291
|
+
|
|
292
|
+
## Licenca
|
|
293
|
+
|
|
294
|
+
MIT License - veja [LICENSE](LICENSE) para detalhes.
|
|
295
|
+
|
|
296
|
+
## Links
|
|
113
297
|
|
|
114
|
-
|
|
298
|
+
- [Documentacao](https://iptuapi.com.br/docs)
|
|
299
|
+
- [API Reference](https://iptuapi.com.br/docs/api)
|
|
300
|
+
- [Portal do Desenvolvedor](https://iptuapi.com.br/dashboard)
|