apiempresas 1.1.0 → 1.4.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 +223 -110
- package/dist/ApiEmpresas.d.ts +28 -2
- package/dist/ApiEmpresas.js +38 -2
- package/dist/errors/ApiError.d.ts +9 -1
- package/dist/errors/ApiError.js +17 -2
- package/dist/index.d.ts +6 -0
- package/dist/index.js +14 -1
- package/dist/resources/Companies.d.ts +39 -5
- package/dist/resources/Companies.js +65 -5
- package/dist/resources/Sanctions.d.ts +13 -0
- package/dist/resources/Sanctions.js +32 -0
- package/dist/resources/Tenders.d.ts +15 -0
- package/dist/resources/Tenders.js +31 -0
- 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 +519 -10
- package/dist/webhooks/signature.d.ts +13 -0
- package/dist/webhooks/signature.js +49 -0
- package/package.json +1 -1
|
@@ -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) {
|
|
@@ -16,6 +30,51 @@ class Companies {
|
|
|
16
30
|
const response = await this.client.request(`/companies?${params.toString()}`);
|
|
17
31
|
return response.data;
|
|
18
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
|
+
}
|
|
19
78
|
/**
|
|
20
79
|
* Busca empresas por nombre o razón social.
|
|
21
80
|
*/
|
|
@@ -74,7 +133,7 @@ class Companies {
|
|
|
74
133
|
return response.data;
|
|
75
134
|
}
|
|
76
135
|
/**
|
|
77
|
-
* (Business)
|
|
136
|
+
* (Business; en Pro, vista previa con profile y conversion_probability) Insights IA de una empresa.
|
|
78
137
|
*/
|
|
79
138
|
async insights(cif) {
|
|
80
139
|
const params = new URLSearchParams({ cif });
|
|
@@ -82,7 +141,7 @@ class Companies {
|
|
|
82
141
|
return response.data;
|
|
83
142
|
}
|
|
84
143
|
/**
|
|
85
|
-
* (
|
|
144
|
+
* (Business) Preparación del contacto comercial generada por IA.
|
|
86
145
|
*/
|
|
87
146
|
async contactPrep(cif) {
|
|
88
147
|
const params = new URLSearchParams({ cif });
|
|
@@ -90,11 +149,12 @@ class Companies {
|
|
|
90
149
|
return response.data;
|
|
91
150
|
}
|
|
92
151
|
/**
|
|
93
|
-
* (
|
|
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.
|
|
94
154
|
*/
|
|
95
155
|
async radar(cifOrOptions = {}) {
|
|
96
156
|
// Compatibilidad: antes se pasaba un CIF, que el Radar no usa. Ahora se pasan
|
|
97
|
-
// los filtros (province, priority, range).
|
|
157
|
+
// los filtros (province, priority, range, cnae, min_score, main_act_type, has_phone).
|
|
98
158
|
const params = new URLSearchParams();
|
|
99
159
|
if (typeof cifOrOptions === 'string') {
|
|
100
160
|
params.set('cif', cifOrOptions);
|
|
@@ -120,7 +180,7 @@ class Companies {
|
|
|
120
180
|
return response.data;
|
|
121
181
|
}
|
|
122
182
|
/**
|
|
123
|
-
* (Business)
|
|
183
|
+
* (Pro y Business) Red societaria de una empresa a través de sus administradores.
|
|
124
184
|
*/
|
|
125
185
|
async network(cif) {
|
|
126
186
|
const params = new URLSearchParams({ cif });
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ApiEmpresas } from '../ApiEmpresas';
|
|
2
|
+
import { SanctionsOptions, SanctionsResult } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* (Business) Listas de sanciones de la UE, la ONU y OFAC (EE. UU.). 1 consulta por llamada.
|
|
5
|
+
* Cada coincidencia trae su grado (strong o possible): confírmala con la fecha de nacimiento,
|
|
6
|
+
* el país y los documentos antes de decidir.
|
|
7
|
+
*/
|
|
8
|
+
export declare class Sanctions {
|
|
9
|
+
private client;
|
|
10
|
+
constructor(client: ApiEmpresas);
|
|
11
|
+
/** Comprueba una empresa (cif, con sus administradores vigentes) o un nombre (name). */
|
|
12
|
+
screen(options: SanctionsOptions): Promise<SanctionsResult>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Sanctions = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* (Business) Listas de sanciones de la UE, la ONU y OFAC (EE. UU.). 1 consulta por llamada.
|
|
6
|
+
* Cada coincidencia trae su grado (strong o possible): confírmala con la fecha de nacimiento,
|
|
7
|
+
* el país y los documentos antes de decidir.
|
|
8
|
+
*/
|
|
9
|
+
class Sanctions {
|
|
10
|
+
client;
|
|
11
|
+
constructor(client) {
|
|
12
|
+
this.client = client;
|
|
13
|
+
}
|
|
14
|
+
/** Comprueba una empresa (cif, con sus administradores vigentes) o un nombre (name). */
|
|
15
|
+
async screen(options) {
|
|
16
|
+
if (!options || (!options.cif && !options.name)) {
|
|
17
|
+
throw new Error("Indica 'cif' o 'name'.");
|
|
18
|
+
}
|
|
19
|
+
const params = new URLSearchParams();
|
|
20
|
+
if (options.cif)
|
|
21
|
+
params.set('cif', options.cif);
|
|
22
|
+
if (options.name)
|
|
23
|
+
params.set('name', options.name);
|
|
24
|
+
if (options.type)
|
|
25
|
+
params.set('type', options.type);
|
|
26
|
+
if (options.directors === false)
|
|
27
|
+
params.set('directors', 'false');
|
|
28
|
+
const r = await this.client.request(`/sanctions/screen?${params.toString()}`);
|
|
29
|
+
return r.data;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.Sanctions = Sanctions;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ApiEmpresas } from '../ApiEmpresas';
|
|
2
|
+
import { TendersOptions, TendersResult } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* (Business) Licitaciones públicas abiertas: Plataforma de Contratación del Sector Público y
|
|
5
|
+
* plataformas autonómicas agregadas. 1 consulta por llamada. En Free y Pro, ApiError 403
|
|
6
|
+
* PLAN_RESTRICTION con el número de licitaciones y 3 de muestra en raw.upsell_opportunities.
|
|
7
|
+
*/
|
|
8
|
+
export declare class Tenders {
|
|
9
|
+
private client;
|
|
10
|
+
constructor(client: ApiEmpresas);
|
|
11
|
+
/** Busca licitaciones. Con cif, las parecidas a los contratos que esa empresa ya ha ganado. */
|
|
12
|
+
list(options?: TendersOptions): Promise<TendersResult>;
|
|
13
|
+
/** Atajo: licitaciones abiertas parecidas a lo que ya ha ganado una empresa. */
|
|
14
|
+
forCompany(cif: string, options?: Omit<TendersOptions, 'cif'>): Promise<TendersResult>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Tenders = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* (Business) Licitaciones públicas abiertas: Plataforma de Contratación del Sector Público y
|
|
6
|
+
* plataformas autonómicas agregadas. 1 consulta por llamada. En Free y Pro, ApiError 403
|
|
7
|
+
* PLAN_RESTRICTION con el número de licitaciones y 3 de muestra en raw.upsell_opportunities.
|
|
8
|
+
*/
|
|
9
|
+
class Tenders {
|
|
10
|
+
client;
|
|
11
|
+
constructor(client) {
|
|
12
|
+
this.client = client;
|
|
13
|
+
}
|
|
14
|
+
/** Busca licitaciones. Con cif, las parecidas a los contratos que esa empresa ya ha ganado. */
|
|
15
|
+
async list(options = {}) {
|
|
16
|
+
const params = new URLSearchParams();
|
|
17
|
+
for (const [k, v] of Object.entries(options)) {
|
|
18
|
+
if (v === undefined || v === null || v === '')
|
|
19
|
+
continue;
|
|
20
|
+
params.set(k, Array.isArray(v) ? v.join(',') : String(v));
|
|
21
|
+
}
|
|
22
|
+
const qs = params.toString();
|
|
23
|
+
const r = await this.client.request(`/tenders${qs ? '?' + qs : ''}`);
|
|
24
|
+
return { ...r.data, meta: r.meta };
|
|
25
|
+
}
|
|
26
|
+
/** Atajo: licitaciones abiertas parecidas a lo que ya ha ganado una empresa. */
|
|
27
|
+
async forCompany(cif, options = {}) {
|
|
28
|
+
return this.list({ ...options, cif });
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.Tenders = Tenders;
|
|
@@ -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;
|