iptuapi 1.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 ADDED
@@ -0,0 +1,75 @@
1
+ # IPTU API - JavaScript/TypeScript SDK
2
+
3
+ SDK oficial para integração com a IPTU API.
4
+
5
+ ## Instalação
6
+
7
+ ```bash
8
+ npm install iptuapi
9
+ # ou
10
+ yarn add iptuapi
11
+ # ou
12
+ pnpm add iptuapi
13
+ ```
14
+
15
+ ## Uso Rápido
16
+
17
+ ```typescript
18
+ import { IPTUClient } from 'iptuapi';
19
+
20
+ const client = new IPTUClient('sua_api_key');
21
+
22
+ // Consulta por endereço
23
+ const resultado = await client.consultaEndereco('Avenida Paulista', '1000');
24
+ console.log(resultado);
25
+
26
+ // Consulta por SQL (Starter+)
27
+ const dados = await client.consultaSQL('100-01-001-001');
28
+
29
+ // Avaliação de mercado (Pro+)
30
+ const avaliacao = await client.valuationEstimate({
31
+ area_terreno: 250,
32
+ area_construida: 180,
33
+ bairro: 'Pinheiros',
34
+ zona: 'ZM',
35
+ tipo_uso: 'Residencial',
36
+ tipo_padrao: 'Médio',
37
+ ano_construcao: 2010,
38
+ });
39
+ console.log(`Valor estimado: R$ ${avaliacao.valor_estimado.toLocaleString()}`);
40
+ ```
41
+
42
+ ## Tratamento de Erros
43
+
44
+ ```typescript
45
+ import { IPTUClient, NotFoundError, RateLimitError } from 'iptuapi';
46
+
47
+ const client = new IPTUClient('sua_api_key');
48
+
49
+ try {
50
+ const resultado = await client.consultaEndereco('Rua Inexistente');
51
+ } catch (error) {
52
+ if (error instanceof NotFoundError) {
53
+ console.log('Imóvel não encontrado');
54
+ } else if (error instanceof RateLimitError) {
55
+ console.log('Limite de requisições excedido');
56
+ }
57
+ }
58
+ ```
59
+
60
+ ## Tipos TypeScript
61
+
62
+ O SDK inclui tipos TypeScript completos:
63
+
64
+ ```typescript
65
+ import type {
66
+ ConsultaEnderecoResult,
67
+ ConsultaSQLResult,
68
+ ValuationParams,
69
+ ValuationResult,
70
+ } from 'iptuapi';
71
+ ```
72
+
73
+ ## Documentação
74
+
75
+ Acesse a documentação completa em [iptuapi.com.br/docs](https://iptuapi.com.br/docs)
@@ -0,0 +1,96 @@
1
+ /**
2
+ * IPTU API - JavaScript/TypeScript SDK
3
+ *
4
+ * SDK oficial para integração com a IPTU API.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * import { IPTUClient } from 'iptuapi';
9
+ *
10
+ * const client = new IPTUClient('sua_api_key');
11
+ * const resultado = await client.consultaEndereco('Avenida Paulista', '1000');
12
+ * ```
13
+ */
14
+ interface ConsultaEnderecoResult {
15
+ sql: string;
16
+ logradouro: string;
17
+ numero: string;
18
+ bairro: string;
19
+ cep: string;
20
+ area_terreno: number;
21
+ area_construida: number;
22
+ tipo_uso: string;
23
+ zona: string;
24
+ }
25
+ interface ConsultaSQLResult {
26
+ sql: string;
27
+ ano: number;
28
+ valor_venal: number;
29
+ valor_venal_terreno: number;
30
+ valor_venal_construcao: number;
31
+ iptu_valor: number;
32
+ logradouro: string;
33
+ numero: string;
34
+ bairro: string;
35
+ area_terreno: number;
36
+ area_construida: number;
37
+ }
38
+ interface ValuationParams {
39
+ area_terreno: number;
40
+ area_construida: number;
41
+ bairro: string;
42
+ zona: string;
43
+ tipo_uso: string;
44
+ tipo_padrao: string;
45
+ ano_construcao?: number;
46
+ }
47
+ interface ValuationResult {
48
+ success: boolean;
49
+ valor_estimado: number;
50
+ valor_minimo: number;
51
+ valor_maximo: number;
52
+ valor_m2: number;
53
+ confianca: number;
54
+ modelo_versao: string;
55
+ }
56
+ declare class IPTUAPIError extends Error {
57
+ statusCode?: number | undefined;
58
+ constructor(message: string, statusCode?: number | undefined);
59
+ }
60
+ declare class AuthenticationError extends IPTUAPIError {
61
+ constructor(message?: string);
62
+ }
63
+ declare class RateLimitError extends IPTUAPIError {
64
+ constructor(message?: string);
65
+ }
66
+ declare class NotFoundError extends IPTUAPIError {
67
+ constructor(message?: string);
68
+ }
69
+ declare class ForbiddenError extends IPTUAPIError {
70
+ constructor(message?: string);
71
+ }
72
+ interface IPTUClientOptions {
73
+ baseUrl?: string;
74
+ timeout?: number;
75
+ }
76
+ declare class IPTUClient {
77
+ private apiKey;
78
+ private baseUrl;
79
+ private timeout;
80
+ constructor(apiKey: string, options?: IPTUClientOptions);
81
+ private request;
82
+ /**
83
+ * Busca dados de IPTU por endereço
84
+ */
85
+ consultaEndereco(logradouro: string, numero?: string): Promise<ConsultaEnderecoResult>;
86
+ /**
87
+ * Busca dados de IPTU por número SQL (Starter+)
88
+ */
89
+ consultaSQL(sql: string): Promise<ConsultaSQLResult>;
90
+ /**
91
+ * Estima o valor de mercado do imóvel (Pro+)
92
+ */
93
+ valuationEstimate(params: ValuationParams): Promise<ValuationResult>;
94
+ }
95
+
96
+ export { AuthenticationError, type ConsultaEnderecoResult, type ConsultaSQLResult, ForbiddenError, IPTUAPIError, IPTUClient, type IPTUClientOptions, NotFoundError, RateLimitError, type ValuationParams, type ValuationResult, IPTUClient as default };
@@ -0,0 +1,96 @@
1
+ /**
2
+ * IPTU API - JavaScript/TypeScript SDK
3
+ *
4
+ * SDK oficial para integração com a IPTU API.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * import { IPTUClient } from 'iptuapi';
9
+ *
10
+ * const client = new IPTUClient('sua_api_key');
11
+ * const resultado = await client.consultaEndereco('Avenida Paulista', '1000');
12
+ * ```
13
+ */
14
+ interface ConsultaEnderecoResult {
15
+ sql: string;
16
+ logradouro: string;
17
+ numero: string;
18
+ bairro: string;
19
+ cep: string;
20
+ area_terreno: number;
21
+ area_construida: number;
22
+ tipo_uso: string;
23
+ zona: string;
24
+ }
25
+ interface ConsultaSQLResult {
26
+ sql: string;
27
+ ano: number;
28
+ valor_venal: number;
29
+ valor_venal_terreno: number;
30
+ valor_venal_construcao: number;
31
+ iptu_valor: number;
32
+ logradouro: string;
33
+ numero: string;
34
+ bairro: string;
35
+ area_terreno: number;
36
+ area_construida: number;
37
+ }
38
+ interface ValuationParams {
39
+ area_terreno: number;
40
+ area_construida: number;
41
+ bairro: string;
42
+ zona: string;
43
+ tipo_uso: string;
44
+ tipo_padrao: string;
45
+ ano_construcao?: number;
46
+ }
47
+ interface ValuationResult {
48
+ success: boolean;
49
+ valor_estimado: number;
50
+ valor_minimo: number;
51
+ valor_maximo: number;
52
+ valor_m2: number;
53
+ confianca: number;
54
+ modelo_versao: string;
55
+ }
56
+ declare class IPTUAPIError extends Error {
57
+ statusCode?: number | undefined;
58
+ constructor(message: string, statusCode?: number | undefined);
59
+ }
60
+ declare class AuthenticationError extends IPTUAPIError {
61
+ constructor(message?: string);
62
+ }
63
+ declare class RateLimitError extends IPTUAPIError {
64
+ constructor(message?: string);
65
+ }
66
+ declare class NotFoundError extends IPTUAPIError {
67
+ constructor(message?: string);
68
+ }
69
+ declare class ForbiddenError extends IPTUAPIError {
70
+ constructor(message?: string);
71
+ }
72
+ interface IPTUClientOptions {
73
+ baseUrl?: string;
74
+ timeout?: number;
75
+ }
76
+ declare class IPTUClient {
77
+ private apiKey;
78
+ private baseUrl;
79
+ private timeout;
80
+ constructor(apiKey: string, options?: IPTUClientOptions);
81
+ private request;
82
+ /**
83
+ * Busca dados de IPTU por endereço
84
+ */
85
+ consultaEndereco(logradouro: string, numero?: string): Promise<ConsultaEnderecoResult>;
86
+ /**
87
+ * Busca dados de IPTU por número SQL (Starter+)
88
+ */
89
+ consultaSQL(sql: string): Promise<ConsultaSQLResult>;
90
+ /**
91
+ * Estima o valor de mercado do imóvel (Pro+)
92
+ */
93
+ valuationEstimate(params: ValuationParams): Promise<ValuationResult>;
94
+ }
95
+
96
+ export { AuthenticationError, type ConsultaEnderecoResult, type ConsultaSQLResult, ForbiddenError, IPTUAPIError, IPTUClient, type IPTUClientOptions, NotFoundError, RateLimitError, type ValuationParams, type ValuationResult, IPTUClient as default };
package/dist/index.js ADDED
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ AuthenticationError: () => AuthenticationError,
24
+ ForbiddenError: () => ForbiddenError,
25
+ IPTUAPIError: () => IPTUAPIError,
26
+ IPTUClient: () => IPTUClient,
27
+ NotFoundError: () => NotFoundError,
28
+ RateLimitError: () => RateLimitError,
29
+ default: () => index_default
30
+ });
31
+ module.exports = __toCommonJS(index_exports);
32
+ var IPTUAPIError = class extends Error {
33
+ constructor(message, statusCode) {
34
+ super(message);
35
+ this.statusCode = statusCode;
36
+ this.name = "IPTUAPIError";
37
+ }
38
+ };
39
+ var AuthenticationError = class extends IPTUAPIError {
40
+ constructor(message = "API Key inv\xE1lida ou expirada") {
41
+ super(message, 401);
42
+ this.name = "AuthenticationError";
43
+ }
44
+ };
45
+ var RateLimitError = class extends IPTUAPIError {
46
+ constructor(message = "Limite de requisi\xE7\xF5es excedido") {
47
+ super(message, 429);
48
+ this.name = "RateLimitError";
49
+ }
50
+ };
51
+ var NotFoundError = class extends IPTUAPIError {
52
+ constructor(message = "Recurso n\xE3o encontrado") {
53
+ super(message, 404);
54
+ this.name = "NotFoundError";
55
+ }
56
+ };
57
+ var ForbiddenError = class extends IPTUAPIError {
58
+ constructor(message = "Plano n\xE3o autorizado para este recurso") {
59
+ super(message, 403);
60
+ this.name = "ForbiddenError";
61
+ }
62
+ };
63
+ var IPTUClient = class {
64
+ apiKey;
65
+ baseUrl;
66
+ timeout;
67
+ constructor(apiKey, options = {}) {
68
+ this.apiKey = apiKey;
69
+ this.baseUrl = options.baseUrl || "https://iptuapi.com.br/api/v1";
70
+ this.timeout = options.timeout || 3e4;
71
+ }
72
+ async request(method, endpoint, params, body) {
73
+ const url = new URL(`${this.baseUrl}${endpoint}`);
74
+ if (params) {
75
+ Object.entries(params).forEach(([key, value]) => {
76
+ if (value) url.searchParams.append(key, value);
77
+ });
78
+ }
79
+ const controller = new AbortController();
80
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
81
+ try {
82
+ const response = await fetch(url.toString(), {
83
+ method,
84
+ headers: {
85
+ "X-API-Key": this.apiKey,
86
+ "Content-Type": "application/json"
87
+ },
88
+ body: body ? JSON.stringify(body) : void 0,
89
+ signal: controller.signal
90
+ });
91
+ clearTimeout(timeoutId);
92
+ if (response.ok) {
93
+ return response.json();
94
+ }
95
+ switch (response.status) {
96
+ case 401:
97
+ throw new AuthenticationError();
98
+ case 403:
99
+ throw new ForbiddenError();
100
+ case 404:
101
+ throw new NotFoundError();
102
+ case 429:
103
+ throw new RateLimitError();
104
+ default:
105
+ const errorData = await response.json().catch(() => ({}));
106
+ throw new IPTUAPIError(
107
+ errorData.detail || `Erro na API: ${response.statusText}`,
108
+ response.status
109
+ );
110
+ }
111
+ } catch (error) {
112
+ clearTimeout(timeoutId);
113
+ if (error instanceof IPTUAPIError) throw error;
114
+ if (error instanceof Error && error.name === "AbortError") {
115
+ throw new IPTUAPIError("Timeout na requisi\xE7\xE3o", 408);
116
+ }
117
+ throw error;
118
+ }
119
+ }
120
+ /**
121
+ * Busca dados de IPTU por endereço
122
+ */
123
+ async consultaEndereco(logradouro, numero) {
124
+ return this.request("GET", "/consulta/endereco", {
125
+ logradouro,
126
+ numero: numero || ""
127
+ });
128
+ }
129
+ /**
130
+ * Busca dados de IPTU por número SQL (Starter+)
131
+ */
132
+ async consultaSQL(sql) {
133
+ return this.request("GET", "/consulta/sql", { sql });
134
+ }
135
+ /**
136
+ * Estima o valor de mercado do imóvel (Pro+)
137
+ */
138
+ async valuationEstimate(params) {
139
+ return this.request(
140
+ "POST",
141
+ "/valuation/estimate",
142
+ void 0,
143
+ params
144
+ );
145
+ }
146
+ };
147
+ var index_default = IPTUClient;
148
+ // Annotate the CommonJS export names for ESM import in node:
149
+ 0 && (module.exports = {
150
+ AuthenticationError,
151
+ ForbiddenError,
152
+ IPTUAPIError,
153
+ IPTUClient,
154
+ NotFoundError,
155
+ RateLimitError
156
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,126 @@
1
+ // src/index.ts
2
+ var IPTUAPIError = class extends Error {
3
+ constructor(message, statusCode) {
4
+ super(message);
5
+ this.statusCode = statusCode;
6
+ this.name = "IPTUAPIError";
7
+ }
8
+ };
9
+ var AuthenticationError = class extends IPTUAPIError {
10
+ constructor(message = "API Key inv\xE1lida ou expirada") {
11
+ super(message, 401);
12
+ this.name = "AuthenticationError";
13
+ }
14
+ };
15
+ var RateLimitError = class extends IPTUAPIError {
16
+ constructor(message = "Limite de requisi\xE7\xF5es excedido") {
17
+ super(message, 429);
18
+ this.name = "RateLimitError";
19
+ }
20
+ };
21
+ var NotFoundError = class extends IPTUAPIError {
22
+ constructor(message = "Recurso n\xE3o encontrado") {
23
+ super(message, 404);
24
+ this.name = "NotFoundError";
25
+ }
26
+ };
27
+ var ForbiddenError = class extends IPTUAPIError {
28
+ constructor(message = "Plano n\xE3o autorizado para este recurso") {
29
+ super(message, 403);
30
+ this.name = "ForbiddenError";
31
+ }
32
+ };
33
+ var IPTUClient = class {
34
+ apiKey;
35
+ baseUrl;
36
+ timeout;
37
+ constructor(apiKey, options = {}) {
38
+ this.apiKey = apiKey;
39
+ this.baseUrl = options.baseUrl || "https://iptuapi.com.br/api/v1";
40
+ this.timeout = options.timeout || 3e4;
41
+ }
42
+ async request(method, endpoint, params, body) {
43
+ const url = new URL(`${this.baseUrl}${endpoint}`);
44
+ if (params) {
45
+ Object.entries(params).forEach(([key, value]) => {
46
+ if (value) url.searchParams.append(key, value);
47
+ });
48
+ }
49
+ const controller = new AbortController();
50
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
51
+ try {
52
+ const response = await fetch(url.toString(), {
53
+ method,
54
+ headers: {
55
+ "X-API-Key": this.apiKey,
56
+ "Content-Type": "application/json"
57
+ },
58
+ body: body ? JSON.stringify(body) : void 0,
59
+ signal: controller.signal
60
+ });
61
+ clearTimeout(timeoutId);
62
+ if (response.ok) {
63
+ return response.json();
64
+ }
65
+ switch (response.status) {
66
+ case 401:
67
+ throw new AuthenticationError();
68
+ case 403:
69
+ throw new ForbiddenError();
70
+ case 404:
71
+ throw new NotFoundError();
72
+ case 429:
73
+ throw new RateLimitError();
74
+ default:
75
+ const errorData = await response.json().catch(() => ({}));
76
+ throw new IPTUAPIError(
77
+ errorData.detail || `Erro na API: ${response.statusText}`,
78
+ response.status
79
+ );
80
+ }
81
+ } catch (error) {
82
+ clearTimeout(timeoutId);
83
+ if (error instanceof IPTUAPIError) throw error;
84
+ if (error instanceof Error && error.name === "AbortError") {
85
+ throw new IPTUAPIError("Timeout na requisi\xE7\xE3o", 408);
86
+ }
87
+ throw error;
88
+ }
89
+ }
90
+ /**
91
+ * Busca dados de IPTU por endereço
92
+ */
93
+ async consultaEndereco(logradouro, numero) {
94
+ return this.request("GET", "/consulta/endereco", {
95
+ logradouro,
96
+ numero: numero || ""
97
+ });
98
+ }
99
+ /**
100
+ * Busca dados de IPTU por número SQL (Starter+)
101
+ */
102
+ async consultaSQL(sql) {
103
+ return this.request("GET", "/consulta/sql", { sql });
104
+ }
105
+ /**
106
+ * Estima o valor de mercado do imóvel (Pro+)
107
+ */
108
+ async valuationEstimate(params) {
109
+ return this.request(
110
+ "POST",
111
+ "/valuation/estimate",
112
+ void 0,
113
+ params
114
+ );
115
+ }
116
+ };
117
+ var index_default = IPTUClient;
118
+ export {
119
+ AuthenticationError,
120
+ ForbiddenError,
121
+ IPTUAPIError,
122
+ IPTUClient,
123
+ NotFoundError,
124
+ RateLimitError,
125
+ index_default as default
126
+ };
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "iptuapi",
3
+ "version": "1.0.0",
4
+ "description": "SDK oficial para a IPTU API - Dados de IPTU de São Paulo",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "scripts": {
12
+ "build": "tsup src/index.ts --format cjs,esm --dts",
13
+ "prepublishOnly": "npm run build"
14
+ },
15
+ "keywords": [
16
+ "iptu",
17
+ "api",
18
+ "são paulo",
19
+ "imóveis",
20
+ "dados",
21
+ "typescript"
22
+ ],
23
+ "author": "IPTU API <contato@iptuapi.com.br>",
24
+ "license": "MIT",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "https://github.com/iptuapi/iptuapi-js"
28
+ },
29
+ "homepage": "https://iptuapi.com.br",
30
+ "devDependencies": {
31
+ "tsup": "^8.0.0",
32
+ "typescript": "^5.3.0"
33
+ },
34
+ "engines": {
35
+ "node": ">=18"
36
+ }
37
+ }