apiempresas 1.0.1 → 1.3.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 +198 -87
- package/dist/ApiEmpresas.d.ts +23 -1
- package/dist/ApiEmpresas.js +53 -2
- package/dist/errors/ApiError.d.ts +11 -1
- package/dist/errors/ApiError.js +19 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.js +10 -1
- package/dist/resources/Companies.d.ts +74 -8
- package/dist/resources/Companies.js +115 -8
- package/dist/resources/Watchlist.d.ts +38 -0
- package/dist/resources/Watchlist.js +63 -0
- package/dist/resources/Webhooks.d.ts +21 -0
- package/dist/resources/Webhooks.js +60 -0
- package/dist/types.d.ts +380 -8
- package/dist/webhooks/signature.d.ts +13 -0
- package/dist/webhooks/signature.js +49 -0
- package/package.json +36 -29
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Companies = void 0;
|
|
4
|
+
function filterParams(o) {
|
|
5
|
+
const p = new URLSearchParams();
|
|
6
|
+
for (const [k, v] of Object.entries(o || {})) {
|
|
7
|
+
if (v === undefined || v === null || v === '')
|
|
8
|
+
continue;
|
|
9
|
+
if (Array.isArray(v))
|
|
10
|
+
p.set(k, v.join(','));
|
|
11
|
+
else if (typeof v === 'boolean')
|
|
12
|
+
p.set(k, v ? 'true' : 'false');
|
|
13
|
+
else
|
|
14
|
+
p.set(k, String(v));
|
|
15
|
+
}
|
|
16
|
+
return p;
|
|
17
|
+
}
|
|
4
18
|
class Companies {
|
|
5
19
|
client;
|
|
6
20
|
constructor(client) {
|
|
@@ -9,11 +23,58 @@ class Companies {
|
|
|
9
23
|
/**
|
|
10
24
|
* Obtiene los datos básicos de una empresa por su CIF.
|
|
11
25
|
*/
|
|
12
|
-
async get(cif) {
|
|
26
|
+
async get(cif, options = {}) {
|
|
13
27
|
const params = new URLSearchParams({ cif });
|
|
28
|
+
if (options.admin)
|
|
29
|
+
params.set('admin', 'true');
|
|
14
30
|
const response = await this.client.request(`/companies?${params.toString()}`);
|
|
15
31
|
return response.data;
|
|
16
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* (Pro) Verificación KYB en una llamada: estado, nombre, administrador, VIES y
|
|
35
|
+
* alertas, con decision_hint pass / review / fail. Coste: 2 consultas.
|
|
36
|
+
*/
|
|
37
|
+
async verify(cif, options = {}) {
|
|
38
|
+
const params = new URLSearchParams({ cif });
|
|
39
|
+
if (options.name)
|
|
40
|
+
params.set('name', options.name);
|
|
41
|
+
if (options.person)
|
|
42
|
+
params.set('person', options.person);
|
|
43
|
+
if (options.vat)
|
|
44
|
+
params.set('vat', 'true');
|
|
45
|
+
const response = await this.client.request(`/companies/verify?${params.toString()}`);
|
|
46
|
+
return response.data;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* (Pro) Nombre a CIF, hasta 100 por petición. 1 consulta por cada "match";
|
|
50
|
+
* ambiguous y no_match no se cobran.
|
|
51
|
+
*/
|
|
52
|
+
async reconcile(items) {
|
|
53
|
+
const body = { items: items.map((i) => (typeof i === 'string' ? { name: i } : i)) };
|
|
54
|
+
const response = await this.client.request('/companies/reconcile', {
|
|
55
|
+
method: 'POST',
|
|
56
|
+
body: JSON.stringify(body)
|
|
57
|
+
});
|
|
58
|
+
return { data: response.data, meta: response.meta };
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Cuántas empresas encajan con los filtros. Gratis en todos los planes.
|
|
62
|
+
*/
|
|
63
|
+
async count(options) {
|
|
64
|
+
const params = filterParams(options);
|
|
65
|
+
params.set('count_only', 'true');
|
|
66
|
+
const response = await this.client.request(`/companies/filter?${params.toString()}`);
|
|
67
|
+
return response.data.total;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* (Business) Empresas de un segmento. 5 consultas por fila devuelta; para la página
|
|
71
|
+
* siguiente, pasa meta.next_cursor como cursor con los mismos filtros.
|
|
72
|
+
*/
|
|
73
|
+
async filter(options) {
|
|
74
|
+
const params = filterParams(options);
|
|
75
|
+
const response = await this.client.request(`/companies/filter?${params.toString()}`);
|
|
76
|
+
return { data: response.data, meta: response.meta };
|
|
77
|
+
}
|
|
17
78
|
/**
|
|
18
79
|
* Busca empresas por nombre o razón social.
|
|
19
80
|
*/
|
|
@@ -22,6 +83,21 @@ class Companies {
|
|
|
22
83
|
const response = await this.client.request(`/companies/search?${params.toString()}`);
|
|
23
84
|
return response.data;
|
|
24
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Búsqueda con varios resultados (multiple=true). Devuelve data y meta;
|
|
88
|
+
* para la página siguiente, pasa meta.next_cursor como cursor.
|
|
89
|
+
*/
|
|
90
|
+
async searchMultiple(q, options = {}) {
|
|
91
|
+
const params = new URLSearchParams({ q, multiple: 'true' });
|
|
92
|
+
if (options.limit !== undefined)
|
|
93
|
+
params.set('limit', String(options.limit));
|
|
94
|
+
if (options.page !== undefined)
|
|
95
|
+
params.set('page', String(options.page));
|
|
96
|
+
if (options.cursor !== undefined)
|
|
97
|
+
params.set('cursor', options.cursor);
|
|
98
|
+
const response = await this.client.request(`/companies/search?${params.toString()}`);
|
|
99
|
+
return { data: response.data, meta: response.meta };
|
|
100
|
+
}
|
|
25
101
|
/**
|
|
26
102
|
* Consulta múltiple de CIFs en una sola petición.
|
|
27
103
|
*/
|
|
@@ -57,7 +133,7 @@ class Companies {
|
|
|
57
133
|
return response.data;
|
|
58
134
|
}
|
|
59
135
|
/**
|
|
60
|
-
* (Business)
|
|
136
|
+
* (Business; en Pro, vista previa con profile y conversion_probability) Insights IA de una empresa.
|
|
61
137
|
*/
|
|
62
138
|
async insights(cif) {
|
|
63
139
|
const params = new URLSearchParams({ cif });
|
|
@@ -65,7 +141,7 @@ class Companies {
|
|
|
65
141
|
return response.data;
|
|
66
142
|
}
|
|
67
143
|
/**
|
|
68
|
-
* (
|
|
144
|
+
* (Business) Preparación del contacto comercial generada por IA.
|
|
69
145
|
*/
|
|
70
146
|
async contactPrep(cif) {
|
|
71
147
|
const params = new URLSearchParams({ cif });
|
|
@@ -73,28 +149,59 @@ class Companies {
|
|
|
73
149
|
return response.data;
|
|
74
150
|
}
|
|
75
151
|
/**
|
|
76
|
-
* (
|
|
152
|
+
* (Todos los planes: Free 10 resultados con nombre y CIF ocultos, Pro 100, Business 1.000)
|
|
153
|
+
* Empresas recién constituidas. Devuelve la lista (data); el resumen (meta) no se incluye.
|
|
77
154
|
*/
|
|
78
|
-
async radar(
|
|
79
|
-
|
|
155
|
+
async radar(cifOrOptions = {}) {
|
|
156
|
+
// Compatibilidad: antes se pasaba un CIF, que el Radar no usa. Ahora se pasan
|
|
157
|
+
// los filtros (province, priority, range, cnae, min_score, main_act_type, has_phone).
|
|
158
|
+
const params = new URLSearchParams();
|
|
159
|
+
if (typeof cifOrOptions === 'string') {
|
|
160
|
+
params.set('cif', cifOrOptions);
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
for (const [k, v] of Object.entries(cifOrOptions)) {
|
|
164
|
+
if (v !== undefined && v !== null)
|
|
165
|
+
params.set(k, String(v));
|
|
166
|
+
}
|
|
167
|
+
}
|
|
80
168
|
const response = await this.client.request(`/companies/radar?${params.toString()}`);
|
|
81
169
|
return response.data;
|
|
82
170
|
}
|
|
83
171
|
/**
|
|
84
172
|
* (Business) Realiza un match avanzado con los datos de una empresa.
|
|
85
173
|
*/
|
|
86
|
-
async match(cif) {
|
|
174
|
+
async match(cif, sellerSector) {
|
|
175
|
+
// seller_sector es obligatorio en la API: sin él responde 400.
|
|
87
176
|
const params = new URLSearchParams({ cif });
|
|
177
|
+
if (sellerSector)
|
|
178
|
+
params.set('seller_sector', sellerSector);
|
|
88
179
|
const response = await this.client.request(`/companies/match?${params.toString()}`);
|
|
89
180
|
return response.data;
|
|
90
181
|
}
|
|
91
182
|
/**
|
|
92
|
-
* (Business)
|
|
183
|
+
* (Pro y Business) Red societaria de una empresa a través de sus administradores.
|
|
93
184
|
*/
|
|
94
185
|
async network(cif) {
|
|
95
186
|
const params = new URLSearchParams({ cif });
|
|
96
187
|
const response = await this.client.request(`/companies/network?${params.toString()}`);
|
|
97
188
|
return response.data;
|
|
98
189
|
}
|
|
190
|
+
/**
|
|
191
|
+
* (Business) Obtiene los contratos públicos y licitaciones adjudicadas a una empresa.
|
|
192
|
+
*/
|
|
193
|
+
async contracts(cif, page = 1, limit = 20) {
|
|
194
|
+
const params = new URLSearchParams({ cif, page: page.toString(), limit: limit.toString() });
|
|
195
|
+
const response = await this.client.request(`/companies/contracts?${params.toString()}`);
|
|
196
|
+
return response.data;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* (Business) Obtiene el perfil de riesgo corporativo y solvencia de una empresa.
|
|
200
|
+
*/
|
|
201
|
+
async riskProfile(cif) {
|
|
202
|
+
const params = new URLSearchParams({ cif });
|
|
203
|
+
const response = await this.client.request(`/companies/risk-profile?${params.toString()}`);
|
|
204
|
+
return response.data;
|
|
205
|
+
}
|
|
99
206
|
}
|
|
100
207
|
exports.Companies = Companies;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ApiEmpresas } from '../ApiEmpresas';
|
|
2
|
+
import { WatchlistAddResult, WatchlistEvent, WatchlistEventsOptions, WatchlistMeta } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* (Pro / Business) Vigilancia de empresas: 100 en Pro, 1.000 en Business.
|
|
5
|
+
* Ninguna de estas llamadas consume consultas.
|
|
6
|
+
*/
|
|
7
|
+
export declare class Watchlist {
|
|
8
|
+
private client;
|
|
9
|
+
constructor(client: ApiEmpresas);
|
|
10
|
+
/** Empresas vigiladas. */
|
|
11
|
+
list(options?: {
|
|
12
|
+
page?: number;
|
|
13
|
+
limit?: number;
|
|
14
|
+
}): Promise<{
|
|
15
|
+
data: any[];
|
|
16
|
+
meta: WatchlistMeta;
|
|
17
|
+
}>;
|
|
18
|
+
/** Añade uno o varios CIF. Devuelve qué se añadió, qué ya estaba y qué no se pudo. */
|
|
19
|
+
add(cifs: string | string[]): Promise<{
|
|
20
|
+
data: WatchlistAddResult;
|
|
21
|
+
meta: WatchlistMeta;
|
|
22
|
+
message?: string;
|
|
23
|
+
upgrade_url?: string;
|
|
24
|
+
}>;
|
|
25
|
+
/** Quita una empresa de la vigilancia. */
|
|
26
|
+
remove(cif: string): Promise<{
|
|
27
|
+
cif: string;
|
|
28
|
+
removed: boolean;
|
|
29
|
+
}>;
|
|
30
|
+
/**
|
|
31
|
+
* Cambios en las empresas vigiladas desde una fecha (borme_act, status_change,
|
|
32
|
+
* risk_level_change), de más antiguo a más reciente.
|
|
33
|
+
*/
|
|
34
|
+
events(options?: WatchlistEventsOptions): Promise<{
|
|
35
|
+
data: WatchlistEvent[];
|
|
36
|
+
meta: WatchlistMeta;
|
|
37
|
+
}>;
|
|
38
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Watchlist = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* (Pro / Business) Vigilancia de empresas: 100 en Pro, 1.000 en Business.
|
|
6
|
+
* Ninguna de estas llamadas consume consultas.
|
|
7
|
+
*/
|
|
8
|
+
class Watchlist {
|
|
9
|
+
client;
|
|
10
|
+
constructor(client) {
|
|
11
|
+
this.client = client;
|
|
12
|
+
}
|
|
13
|
+
/** Empresas vigiladas. */
|
|
14
|
+
async list(options = {}) {
|
|
15
|
+
const params = new URLSearchParams();
|
|
16
|
+
if (options.page !== undefined)
|
|
17
|
+
params.set('page', String(options.page));
|
|
18
|
+
if (options.limit !== undefined)
|
|
19
|
+
params.set('limit', String(options.limit));
|
|
20
|
+
const qs = params.toString();
|
|
21
|
+
const r = await this.client.request(`/watchlist${qs ? '?' + qs : ''}`);
|
|
22
|
+
return { data: r.data, meta: r.meta };
|
|
23
|
+
}
|
|
24
|
+
/** Añade uno o varios CIF. Devuelve qué se añadió, qué ya estaba y qué no se pudo. */
|
|
25
|
+
async add(cifs) {
|
|
26
|
+
const r = await this.client.request('/watchlist', {
|
|
27
|
+
method: 'POST',
|
|
28
|
+
body: JSON.stringify({ cifs: Array.isArray(cifs) ? cifs : [cifs] })
|
|
29
|
+
});
|
|
30
|
+
const out = { data: r.data, meta: r.meta };
|
|
31
|
+
if (r.message)
|
|
32
|
+
out.message = r.message;
|
|
33
|
+
if (r.upgrade_url)
|
|
34
|
+
out.upgrade_url = r.upgrade_url;
|
|
35
|
+
return out;
|
|
36
|
+
}
|
|
37
|
+
/** Quita una empresa de la vigilancia. */
|
|
38
|
+
async remove(cif) {
|
|
39
|
+
const r = await this.client.request(`/watchlist/${encodeURIComponent(cif)}`, { method: 'DELETE' });
|
|
40
|
+
return r.data;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Cambios en las empresas vigiladas desde una fecha (borme_act, status_change,
|
|
44
|
+
* risk_level_change), de más antiguo a más reciente.
|
|
45
|
+
*/
|
|
46
|
+
async events(options = {}) {
|
|
47
|
+
const params = new URLSearchParams();
|
|
48
|
+
if (options.since)
|
|
49
|
+
params.set('since', options.since);
|
|
50
|
+
if (options.types)
|
|
51
|
+
params.set('types', Array.isArray(options.types) ? options.types.join(',') : options.types);
|
|
52
|
+
if (options.cif)
|
|
53
|
+
params.set('cif', options.cif);
|
|
54
|
+
if (options.page !== undefined)
|
|
55
|
+
params.set('page', String(options.page));
|
|
56
|
+
if (options.limit !== undefined)
|
|
57
|
+
params.set('limit', String(options.limit));
|
|
58
|
+
const qs = params.toString();
|
|
59
|
+
const r = await this.client.request(`/watchlist/events${qs ? '?' + qs : ''}`);
|
|
60
|
+
return { data: r.data, meta: r.meta };
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.Watchlist = Watchlist;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ApiEmpresas } from '../ApiEmpresas';
|
|
2
|
+
import { WebhookCreateOptions, WebhookCreated, WebhookTestResult, WebhookDeliveriesOptions, WebhookDeliveries } from '../types';
|
|
3
|
+
/** (Business) Webhooks: la API te avisa por POST firmado cuando cambia algo que vigilas. */
|
|
4
|
+
export declare class Webhooks {
|
|
5
|
+
private client;
|
|
6
|
+
constructor(client: ApiEmpresas);
|
|
7
|
+
list(): Promise<any[]>;
|
|
8
|
+
/** Guarda el secret que devuelve: con él se comprueba la firma (verifyWebhookSignature). */
|
|
9
|
+
create(options: WebhookCreateOptions): Promise<WebhookCreated>;
|
|
10
|
+
remove(id: number): Promise<boolean>;
|
|
11
|
+
/**
|
|
12
|
+
* Envía un test.ping a la URL del webhook y devuelve lo que respondió. Si tu servidor
|
|
13
|
+
* falla, la API responde 502: aquí se devuelve igualmente el resultado (delivered: false).
|
|
14
|
+
*/
|
|
15
|
+
test(id: number): Promise<WebhookTestResult>;
|
|
16
|
+
/**
|
|
17
|
+
* Historial de entregas del webhook, de la más reciente a la más antigua: estado, intentos,
|
|
18
|
+
* código HTTP de tu servidor, duración y error. Pagina con page/limit mientras meta.has_more.
|
|
19
|
+
*/
|
|
20
|
+
deliveries(id: number, options?: WebhookDeliveriesOptions): Promise<WebhookDeliveries>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Webhooks = void 0;
|
|
4
|
+
const ApiError_1 = require("../errors/ApiError");
|
|
5
|
+
/** (Business) Webhooks: la API te avisa por POST firmado cuando cambia algo que vigilas. */
|
|
6
|
+
class Webhooks {
|
|
7
|
+
client;
|
|
8
|
+
constructor(client) {
|
|
9
|
+
this.client = client;
|
|
10
|
+
}
|
|
11
|
+
async list() {
|
|
12
|
+
const r = await this.client.request('/webhooks');
|
|
13
|
+
return r.data;
|
|
14
|
+
}
|
|
15
|
+
/** Guarda el secret que devuelve: con él se comprueba la firma (verifyWebhookSignature). */
|
|
16
|
+
async create(options) {
|
|
17
|
+
const r = await this.client.request('/webhooks', {
|
|
18
|
+
method: 'POST',
|
|
19
|
+
body: JSON.stringify(options)
|
|
20
|
+
});
|
|
21
|
+
return { id: r.id, event: r.event, secret: r.secret, message: r.message };
|
|
22
|
+
}
|
|
23
|
+
async remove(id) {
|
|
24
|
+
const r = await this.client.request(`/webhooks/${encodeURIComponent(String(id))}`, { method: 'DELETE' });
|
|
25
|
+
return !!(r && r.success !== false);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Envía un test.ping a la URL del webhook y devuelve lo que respondió. Si tu servidor
|
|
29
|
+
* falla, la API responde 502: aquí se devuelve igualmente el resultado (delivered: false).
|
|
30
|
+
*/
|
|
31
|
+
async test(id) {
|
|
32
|
+
try {
|
|
33
|
+
const r = await this.client.request(`/webhooks/${encodeURIComponent(String(id))}/test`, { method: 'POST' });
|
|
34
|
+
return r.data;
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
if (e instanceof ApiError_1.ApiError && e.status === 502 && e.rawData && e.rawData.data) {
|
|
38
|
+
return e.rawData.data;
|
|
39
|
+
}
|
|
40
|
+
throw e;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Historial de entregas del webhook, de la más reciente a la más antigua: estado, intentos,
|
|
45
|
+
* código HTTP de tu servidor, duración y error. Pagina con page/limit mientras meta.has_more.
|
|
46
|
+
*/
|
|
47
|
+
async deliveries(id, options = {}) {
|
|
48
|
+
const params = new URLSearchParams();
|
|
49
|
+
if (options.status)
|
|
50
|
+
params.set('status', options.status);
|
|
51
|
+
if (options.page !== undefined)
|
|
52
|
+
params.set('page', String(options.page));
|
|
53
|
+
if (options.limit !== undefined)
|
|
54
|
+
params.set('limit', String(options.limit));
|
|
55
|
+
const qs = params.toString();
|
|
56
|
+
const r = await this.client.request(`/webhooks/${encodeURIComponent(String(id))}/deliveries${qs ? '?' + qs : ''}`);
|
|
57
|
+
return { data: r.data, meta: r.meta };
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.Webhooks = Webhooks;
|