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
package/dist/types.d.ts
CHANGED
|
@@ -37,17 +37,355 @@ export interface Company {
|
|
|
37
37
|
capital_social_raw?: string;
|
|
38
38
|
lat?: number;
|
|
39
39
|
lng?: number;
|
|
40
|
-
/**
|
|
40
|
+
/**
|
|
41
|
+
* Estado normalizado (desde 1.2.0): ACTIVE, PRESUMED_ACTIVE, INSOLVENCY, IN_LIQUIDATION,
|
|
42
|
+
* DISSOLVED, REGISTRY_CLOSED, MERGED, INACTIVE, EXTINCT o UNKNOWN.
|
|
43
|
+
*/
|
|
44
|
+
status_code?: StatusCode;
|
|
45
|
+
/** De dónde sale el estado (Registro, BORME...). */
|
|
46
|
+
status_source?: string | null;
|
|
47
|
+
/** Fecha del hecho que fija el estado (YYYY-MM-DD). */
|
|
48
|
+
status_date?: string | null;
|
|
49
|
+
/** Pro/Business: tramo de tamaño y año de las últimas cuentas vistas. */
|
|
50
|
+
financials?: CompanyFinancials | null;
|
|
51
|
+
/** Todos los planes (desde 1.3.0): código LEI de GLEIF. */
|
|
52
|
+
identifiers?: CompanyIdentifiers;
|
|
53
|
+
/** Todos los planes (desde 1.3.0): forma jurídica con su código ISO 20275 (ELF). */
|
|
54
|
+
legal_form?: CompanyLegalForm;
|
|
55
|
+
/** Pro/Business (desde 1.3.0): matriz directa y última declaradas a GLEIF. null si no tiene LEI. */
|
|
56
|
+
group?: CompanyGroup | null;
|
|
57
|
+
/** Pro/Business (desde 1.3.0): socio único según el BORME. */
|
|
58
|
+
ownership?: CompanyOwnership;
|
|
59
|
+
/** Solo con get(cif, { admin: true }) en Pro/Business. since: fecha del nombramiento. */
|
|
41
60
|
administrators?: Array<{
|
|
42
61
|
name: string;
|
|
43
62
|
position: string;
|
|
63
|
+
since?: string | null;
|
|
44
64
|
[key: string]: any;
|
|
45
65
|
}>;
|
|
46
66
|
/** Solo en el plan Free: indica que la respuesta viene recortada. */
|
|
47
67
|
upsell_opportunities?: {
|
|
48
|
-
campos_ocultos
|
|
49
|
-
mensaje
|
|
68
|
+
campos_ocultos?: string[];
|
|
69
|
+
mensaje?: string;
|
|
70
|
+
[key: string]: any;
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
export type StatusCode = 'ACTIVE' | 'PRESUMED_ACTIVE' | 'INSOLVENCY' | 'IN_LIQUIDATION' | 'DISSOLVED' | 'REGISTRY_CLOSED' | 'MERGED' | 'INACTIVE' | 'EXTINCT' | 'UNKNOWN';
|
|
74
|
+
export interface CompanyIdentifiers {
|
|
75
|
+
lei: string | null;
|
|
76
|
+
/** Estado del LEI en GLEIF: ISSUED, LAPSED, RETIRED... */
|
|
77
|
+
lei_status: string | null;
|
|
78
|
+
lei_next_renewal_date: string | null;
|
|
79
|
+
lei_source: 'gleif' | null;
|
|
80
|
+
lei_as_of: string | null;
|
|
81
|
+
}
|
|
82
|
+
export interface CompanyLegalForm {
|
|
83
|
+
/** SL, SA, SLP, SLL, SLNE, SAL, SAD, SCOOP, AIE, UTE, FUNDACION... */
|
|
84
|
+
code: string | null;
|
|
85
|
+
label: string | null;
|
|
86
|
+
/** Código ELF de la ISO 20275 (DP3Q = SL, 5RDO = SA). null si la forma no tiene código propio. */
|
|
87
|
+
iso20275: string | null;
|
|
88
|
+
/** name: leída de la razón social; cif: deducida de la letra del CIF. */
|
|
89
|
+
source: 'name' | 'cif' | null;
|
|
90
|
+
}
|
|
91
|
+
export interface CompanyParent {
|
|
92
|
+
lei: string;
|
|
93
|
+
name: string | null;
|
|
94
|
+
country: string | null;
|
|
95
|
+
/** CIF de la matriz si es una sociedad española con ficha. */
|
|
96
|
+
cif: string | null;
|
|
97
|
+
}
|
|
98
|
+
export interface CompanyGroup {
|
|
99
|
+
direct_parent: CompanyParent | null;
|
|
100
|
+
ultimate_parent: CompanyParent | null;
|
|
101
|
+
source: 'gleif';
|
|
102
|
+
as_of: string | null;
|
|
103
|
+
}
|
|
104
|
+
export interface CompanyOwnership {
|
|
105
|
+
/** true, false o null (no consta: el accionariado con varios socios no es público). */
|
|
106
|
+
unipersonal: boolean | null;
|
|
107
|
+
sole_shareholder: {
|
|
108
|
+
name: string;
|
|
109
|
+
type: 'person' | 'company';
|
|
110
|
+
since: string | null;
|
|
111
|
+
url_pdf: string | null;
|
|
112
|
+
} | null;
|
|
113
|
+
/** borme: último acto de unipersonalidad; name: solo el nombre dice SLU o SAU. */
|
|
114
|
+
source: 'borme' | 'name' | null;
|
|
115
|
+
as_of: string | null;
|
|
116
|
+
}
|
|
117
|
+
export interface CompanyFinancials {
|
|
118
|
+
size_band?: string | null;
|
|
119
|
+
size_band_label?: string | null;
|
|
120
|
+
last_accounts_year?: number | null;
|
|
121
|
+
}
|
|
122
|
+
export interface VerifyOptions {
|
|
123
|
+
/** Razón social que te han dado, para compararla con la oficial. */
|
|
124
|
+
name?: string;
|
|
125
|
+
/** Nombre y apellidos de quien firma, para comprobar que es administrador vigente. */
|
|
126
|
+
person?: string;
|
|
127
|
+
/** true: comprueba el NIF-IVA intracomunitario en VIES. */
|
|
128
|
+
vat?: boolean;
|
|
129
|
+
}
|
|
130
|
+
export interface VerifyFlag {
|
|
131
|
+
code: string;
|
|
132
|
+
severity: 'low' | 'medium' | 'high' | 'critical';
|
|
133
|
+
message: string;
|
|
134
|
+
}
|
|
135
|
+
export interface VerifyResult {
|
|
136
|
+
cif: string;
|
|
137
|
+
exists: boolean;
|
|
138
|
+
name: string | null;
|
|
139
|
+
status: string | null;
|
|
140
|
+
status_code: StatusCode | null;
|
|
141
|
+
status_source: string | null;
|
|
142
|
+
status_date: string | null;
|
|
143
|
+
identifiers?: CompanyIdentifiers;
|
|
144
|
+
legal_form?: CompanyLegalForm;
|
|
145
|
+
group?: CompanyGroup | null;
|
|
146
|
+
ownership?: CompanyOwnership;
|
|
147
|
+
checks: {
|
|
148
|
+
name?: {
|
|
149
|
+
provided: string;
|
|
150
|
+
score: number;
|
|
151
|
+
match: boolean;
|
|
152
|
+
};
|
|
153
|
+
person?: {
|
|
154
|
+
provided: string;
|
|
155
|
+
is_current_admin: boolean;
|
|
156
|
+
matched_name: string | null;
|
|
157
|
+
position: string | null;
|
|
158
|
+
since: string | null;
|
|
159
|
+
is_sole_shareholder?: boolean;
|
|
160
|
+
};
|
|
161
|
+
vat?: {
|
|
162
|
+
vat_number: string;
|
|
163
|
+
checked: boolean;
|
|
164
|
+
valid: boolean | null;
|
|
165
|
+
source: string;
|
|
166
|
+
error: string | null;
|
|
167
|
+
};
|
|
168
|
+
accounts?: {
|
|
169
|
+
last_accounts_year: number | null;
|
|
170
|
+
};
|
|
171
|
+
/** Solo en Business: listas de sanciones (UE, ONU, OFAC) de la empresa y sus administradores. */
|
|
172
|
+
sanctions?: {
|
|
173
|
+
result: SanctionsResultCode;
|
|
174
|
+
strong_matches: number;
|
|
175
|
+
possible_matches: number;
|
|
176
|
+
directors_checked: number;
|
|
177
|
+
company_matches: SanctionMatch[];
|
|
178
|
+
director_matches: SanctionDirectorMatches[];
|
|
179
|
+
/** Fecha de cada lista cargada: { EU: '2026-10-15', UN: ..., OFAC: ... } */
|
|
180
|
+
lists: Record<string, string | null>;
|
|
181
|
+
};
|
|
50
182
|
};
|
|
183
|
+
/** Solo en Business. */
|
|
184
|
+
risk?: {
|
|
185
|
+
risk_level: string;
|
|
186
|
+
risk_score: number;
|
|
187
|
+
updated_at: string;
|
|
188
|
+
} | null;
|
|
189
|
+
flags: VerifyFlag[];
|
|
190
|
+
decision_hint: 'pass' | 'review' | 'fail';
|
|
191
|
+
checked_at: string;
|
|
192
|
+
}
|
|
193
|
+
export interface ReconcileItem {
|
|
194
|
+
name: string;
|
|
195
|
+
province?: string;
|
|
196
|
+
}
|
|
197
|
+
export interface ReconcileCandidate {
|
|
198
|
+
cif: string;
|
|
199
|
+
name: string;
|
|
200
|
+
province: string | null;
|
|
201
|
+
status: string | null;
|
|
202
|
+
status_code: StatusCode | null;
|
|
203
|
+
score: number;
|
|
204
|
+
}
|
|
205
|
+
export interface ReconcileResult {
|
|
206
|
+
input: {
|
|
207
|
+
name: string;
|
|
208
|
+
province: string | null;
|
|
209
|
+
};
|
|
210
|
+
status: 'match' | 'ambiguous' | 'no_match' | 'invalid' | 'skipped_quota';
|
|
211
|
+
score?: number;
|
|
212
|
+
company?: ReconcileCandidate;
|
|
213
|
+
candidates?: ReconcileCandidate[];
|
|
214
|
+
message?: string;
|
|
215
|
+
}
|
|
216
|
+
export interface ReconcileMeta {
|
|
217
|
+
requested: number;
|
|
218
|
+
matched: number;
|
|
219
|
+
ambiguous: number;
|
|
220
|
+
no_match: number;
|
|
221
|
+
invalid: number;
|
|
222
|
+
skipped_quota: number;
|
|
223
|
+
cost: number;
|
|
224
|
+
thresholds: {
|
|
225
|
+
match: number;
|
|
226
|
+
ambiguous: number;
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
export interface FilterOptions {
|
|
230
|
+
/** Prefijos CNAE (ej: ['62'] o '4711,4719'). Hace falta cnae, province o municipality. */
|
|
231
|
+
cnae?: string | string[];
|
|
232
|
+
province?: string;
|
|
233
|
+
municipality?: string;
|
|
234
|
+
/** active (por defecto), active_or_unknown o any. */
|
|
235
|
+
status?: 'active' | 'active_or_unknown' | 'any';
|
|
236
|
+
founded_from?: string;
|
|
237
|
+
founded_to?: string;
|
|
238
|
+
has_phone?: boolean;
|
|
239
|
+
size_band?: Array<'NO_REVENUE' | 'LT_500K' | '500K_1M' | 'GT_1M'> | string;
|
|
240
|
+
min_accounts_year?: number;
|
|
241
|
+
/** Filas por página (1-1000). */
|
|
242
|
+
limit?: number;
|
|
243
|
+
cursor?: string;
|
|
244
|
+
}
|
|
245
|
+
export interface SegmentRow {
|
|
246
|
+
cif: string;
|
|
247
|
+
name: string;
|
|
248
|
+
cnae: string | null;
|
|
249
|
+
cnae_label: string | null;
|
|
250
|
+
province: string | null;
|
|
251
|
+
municipality: string | null;
|
|
252
|
+
founded: string | null;
|
|
253
|
+
status: string | null;
|
|
254
|
+
status_code: StatusCode | null;
|
|
255
|
+
status_source: string | null;
|
|
256
|
+
financials: CompanyFinancials | null;
|
|
257
|
+
has_phone: boolean;
|
|
258
|
+
}
|
|
259
|
+
export interface SegmentMeta {
|
|
260
|
+
total: number;
|
|
261
|
+
returned: number;
|
|
262
|
+
limit: number;
|
|
263
|
+
has_more: boolean;
|
|
264
|
+
next_cursor: string | null;
|
|
265
|
+
cost: number;
|
|
266
|
+
cost_per_row: number;
|
|
267
|
+
truncated: boolean;
|
|
268
|
+
filters: Record<string, any>;
|
|
269
|
+
}
|
|
270
|
+
export type WatchlistEventType = 'borme_act' | 'status_change' | 'risk_level_change';
|
|
271
|
+
export interface WatchlistEvent {
|
|
272
|
+
/** Estable: úsalo para no procesar dos veces el mismo evento. */
|
|
273
|
+
id: string;
|
|
274
|
+
type: WatchlistEventType;
|
|
275
|
+
cif: string;
|
|
276
|
+
company_name?: string | null;
|
|
277
|
+
date: string;
|
|
278
|
+
/** borme_act: act_types, description, url_pdf. status_change: status, status_code.
|
|
279
|
+
* risk_level_change: from, to, model_change (true/false, o null si no consta la versión del modelo). */
|
|
280
|
+
data: Record<string, any>;
|
|
281
|
+
}
|
|
282
|
+
export interface WatchlistAddResult {
|
|
283
|
+
added: string[];
|
|
284
|
+
already_watching: string[];
|
|
285
|
+
not_found: string[];
|
|
286
|
+
invalid: string[];
|
|
287
|
+
rejected_over_limit: string[];
|
|
288
|
+
}
|
|
289
|
+
export interface WatchlistMeta {
|
|
290
|
+
total?: number;
|
|
291
|
+
watch_limit?: number;
|
|
292
|
+
page?: number;
|
|
293
|
+
limit?: number;
|
|
294
|
+
[key: string]: any;
|
|
295
|
+
}
|
|
296
|
+
export interface WatchlistEventsOptions {
|
|
297
|
+
/** YYYY-MM-DD (incluida). Por defecto, hace 7 días; máximo 90. */
|
|
298
|
+
since?: string;
|
|
299
|
+
types?: WatchlistEventType[] | string;
|
|
300
|
+
cif?: string;
|
|
301
|
+
page?: number;
|
|
302
|
+
limit?: number;
|
|
303
|
+
}
|
|
304
|
+
export type WebhookEvent = 'company.borme_act' | 'company.status_changed' | 'company.risk_level_changed' | 'watchlist.*' | 'test.ping' | string;
|
|
305
|
+
export interface WebhookCreateOptions {
|
|
306
|
+
url: string;
|
|
307
|
+
event: WebhookEvent;
|
|
308
|
+
/** Si no lo pasas, la API genera uno y lo devuelve. */
|
|
309
|
+
secret?: string;
|
|
310
|
+
}
|
|
311
|
+
export interface WebhookCreated {
|
|
312
|
+
id: number;
|
|
313
|
+
event: string;
|
|
314
|
+
secret: string;
|
|
315
|
+
message?: string;
|
|
316
|
+
}
|
|
317
|
+
export interface WebhookTestResult {
|
|
318
|
+
delivered: boolean;
|
|
319
|
+
http_status: number | null;
|
|
320
|
+
duration_ms: number;
|
|
321
|
+
error: string | null;
|
|
322
|
+
delivery_id: string;
|
|
323
|
+
}
|
|
324
|
+
/** Estado de una entrega de webhook. */
|
|
325
|
+
export type WebhookDeliveryStatus = 'pending' | 'processing' | 'retry' | 'delivered' | 'dead';
|
|
326
|
+
export interface WebhookDeliveriesOptions {
|
|
327
|
+
/** Solo las entregas en ese estado. */
|
|
328
|
+
status?: WebhookDeliveryStatus;
|
|
329
|
+
/** Página (desde 1). */
|
|
330
|
+
page?: number;
|
|
331
|
+
/** Entregas por página (1-100). Por defecto, 50. */
|
|
332
|
+
limit?: number;
|
|
333
|
+
}
|
|
334
|
+
export interface WebhookDelivery {
|
|
335
|
+
delivery_id: string;
|
|
336
|
+
event: string;
|
|
337
|
+
/** id del evento de la vigilancia (el mismo de /watchlist/events), si lo hay. */
|
|
338
|
+
event_id: string | null;
|
|
339
|
+
status: WebhookDeliveryStatus;
|
|
340
|
+
attempts: number;
|
|
341
|
+
/** Código HTTP con el que respondió tu servidor. */
|
|
342
|
+
http_status: number | null;
|
|
343
|
+
duration_ms: number | null;
|
|
344
|
+
error: string | null;
|
|
345
|
+
created_at: string;
|
|
346
|
+
last_attempt_at: string | null;
|
|
347
|
+
next_attempt_at: string | null;
|
|
348
|
+
completed_at: string | null;
|
|
349
|
+
}
|
|
350
|
+
export interface WebhookDeliveries {
|
|
351
|
+
data: WebhookDelivery[];
|
|
352
|
+
meta: {
|
|
353
|
+
webhook_id: number;
|
|
354
|
+
total: number;
|
|
355
|
+
page: number;
|
|
356
|
+
limit: number;
|
|
357
|
+
has_more: boolean;
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
/** Valores válidos de los filtros (GET /catalog). No gasta consultas. */
|
|
361
|
+
export interface CatalogData {
|
|
362
|
+
province: string[];
|
|
363
|
+
cnae: {
|
|
364
|
+
format: string;
|
|
365
|
+
count: string;
|
|
366
|
+
};
|
|
367
|
+
size_band: {
|
|
368
|
+
value: string;
|
|
369
|
+
label: string;
|
|
370
|
+
}[];
|
|
371
|
+
status: string[];
|
|
372
|
+
radar: {
|
|
373
|
+
range: string[];
|
|
374
|
+
range_note: string;
|
|
375
|
+
priority: string[];
|
|
376
|
+
main_act_type: string[];
|
|
377
|
+
};
|
|
378
|
+
score_priority: string[];
|
|
379
|
+
webhook_events: string[];
|
|
380
|
+
watchlist_event_types: string[];
|
|
381
|
+
[key: string]: any;
|
|
382
|
+
}
|
|
383
|
+
/** Cuerpo que recibe tu servidor. */
|
|
384
|
+
export interface WebhookPayload<T = any> {
|
|
385
|
+
id: string;
|
|
386
|
+
event: string;
|
|
387
|
+
created_at: string;
|
|
388
|
+
data: T;
|
|
51
389
|
}
|
|
52
390
|
export interface BatchRequest {
|
|
53
391
|
cifs: string[];
|
|
@@ -59,15 +397,18 @@ export interface BatchResponse {
|
|
|
59
397
|
cost: number;
|
|
60
398
|
truncated: boolean;
|
|
61
399
|
}
|
|
400
|
+
export type Priority = 'muy_alta' | 'alta' | 'media' | 'baja' | 'muy_baja';
|
|
401
|
+
/** En el plan Free, priority, reasons y last_signal llegan como texto bloqueado ("🔒 Disponible en Pro"). */
|
|
62
402
|
export interface ScoreData {
|
|
63
403
|
cif: string;
|
|
64
404
|
score: number;
|
|
65
|
-
priority: string;
|
|
66
|
-
reasons: string[];
|
|
405
|
+
priority: Priority | string;
|
|
406
|
+
reasons: string[] | string;
|
|
67
407
|
last_signal?: {
|
|
68
408
|
type: string;
|
|
69
|
-
date: string;
|
|
70
|
-
};
|
|
409
|
+
date: string | null;
|
|
410
|
+
} | string;
|
|
411
|
+
source?: string;
|
|
71
412
|
}
|
|
72
413
|
export interface BormeEvent {
|
|
73
414
|
date: string;
|
|
@@ -80,13 +421,181 @@ export interface BormeData {
|
|
|
80
421
|
company_name: string;
|
|
81
422
|
events: BormeEvent[];
|
|
82
423
|
}
|
|
424
|
+
/** Como mucho un elemento: el último acto del BORME que cuenta para la puntuación. */
|
|
83
425
|
export interface SignalEvent {
|
|
84
|
-
type: string;
|
|
426
|
+
type: 'borme_event' | string;
|
|
85
427
|
label: string;
|
|
86
|
-
date: string;
|
|
87
|
-
|
|
428
|
+
date: string | null;
|
|
429
|
+
/** Prioridad comercial de la empresa (la misma que priority en score), no la fiabilidad del evento. */
|
|
430
|
+
probability: Priority | string;
|
|
88
431
|
}
|
|
89
432
|
export interface SignalsData {
|
|
90
433
|
cif: string;
|
|
91
434
|
signals: SignalEvent[];
|
|
92
435
|
}
|
|
436
|
+
export interface UsageData {
|
|
437
|
+
stats: {
|
|
438
|
+
monthly_queries: number;
|
|
439
|
+
total_queries: number;
|
|
440
|
+
monthly_quota: number;
|
|
441
|
+
remaining_calls: number;
|
|
442
|
+
wallet_balance: number;
|
|
443
|
+
plan_name: string;
|
|
444
|
+
plan_slug: string;
|
|
445
|
+
/** monthly (se renueva cada mes) o lifetime (Free: 100 en total). */
|
|
446
|
+
quota_period: 'monthly' | 'lifetime';
|
|
447
|
+
quota_resets_at: string | null;
|
|
448
|
+
checkout_url?: string | null;
|
|
449
|
+
recharge_url?: string | null;
|
|
450
|
+
};
|
|
451
|
+
/** Las 20 últimas empresas consultadas (respuesta 200 en producción). */
|
|
452
|
+
history: Array<Record<string, any> & {
|
|
453
|
+
cif: string;
|
|
454
|
+
query_count: number;
|
|
455
|
+
last_query: string;
|
|
456
|
+
found: boolean;
|
|
457
|
+
}>;
|
|
458
|
+
}
|
|
459
|
+
export interface TendersOptions {
|
|
460
|
+
/** Palabras del título (todas deben aparecer). */
|
|
461
|
+
q?: string;
|
|
462
|
+
/** CPV o su principio; varios en lista o separados por comas ('72,48'). */
|
|
463
|
+
cpv?: string | string[];
|
|
464
|
+
/** Provincia del órgano de contratación (Madrid, Bizkaia, A Coruña...). */
|
|
465
|
+
province?: string;
|
|
466
|
+
type?: 'supplies' | 'services' | 'works';
|
|
467
|
+
/** Código de procedimiento: '1' abierto, '9' abierto simplificado... */
|
|
468
|
+
procedure?: string;
|
|
469
|
+
min_amount?: number;
|
|
470
|
+
max_amount?: number;
|
|
471
|
+
/** AAAA-MM-DD */
|
|
472
|
+
deadline_from?: string;
|
|
473
|
+
deadline_to?: string;
|
|
474
|
+
published_from?: string;
|
|
475
|
+
/** Licitaciones parecidas a los contratos que esta empresa ya ha ganado. */
|
|
476
|
+
cif?: string;
|
|
477
|
+
status?: 'open' | 'prior_notice' | 'all';
|
|
478
|
+
sort?: 'deadline' | 'published' | 'amount' | 'relevance';
|
|
479
|
+
page?: number;
|
|
480
|
+
/** Máximo 100. */
|
|
481
|
+
limit?: number;
|
|
482
|
+
}
|
|
483
|
+
export interface Tender {
|
|
484
|
+
tender_id: string;
|
|
485
|
+
file_number: string | null;
|
|
486
|
+
title: string | null;
|
|
487
|
+
status: 'open' | 'prior_notice' | 'deadline_passed' | 'under_evaluation' | 'awarded' | 'resolved' | 'cancelled' | 'withdrawn' | string;
|
|
488
|
+
contracting_authority: {
|
|
489
|
+
name: string | null;
|
|
490
|
+
nif: string | null;
|
|
491
|
+
city: string | null;
|
|
492
|
+
province: string | null;
|
|
493
|
+
};
|
|
494
|
+
contract_type: 'supplies' | 'services' | 'works' | 'other' | null;
|
|
495
|
+
procedure: string | null;
|
|
496
|
+
procedure_code: string | null;
|
|
497
|
+
amount_excl_vat: number | null;
|
|
498
|
+
amount_incl_vat: number | null;
|
|
499
|
+
estimated_value: number | null;
|
|
500
|
+
currency: 'EUR';
|
|
501
|
+
lots: number | null;
|
|
502
|
+
main_cpv: string | null;
|
|
503
|
+
cpv_codes: string[];
|
|
504
|
+
execution_place: string | null;
|
|
505
|
+
published_date: string | null;
|
|
506
|
+
/** ISO 8601 con desfase horario de Madrid. */
|
|
507
|
+
deadline: string | null;
|
|
508
|
+
/** Días naturales hasta el día del plazo (0 = cierra hoy). */
|
|
509
|
+
days_left: number | null;
|
|
510
|
+
submission_platform: string;
|
|
511
|
+
url: string | null;
|
|
512
|
+
last_updated: string | null;
|
|
513
|
+
/** Solo con cif: parecido con lo que la empresa ya ha ganado. */
|
|
514
|
+
match_score?: number;
|
|
515
|
+
}
|
|
516
|
+
export interface TendersResult {
|
|
517
|
+
/** Solo con cif. */
|
|
518
|
+
company?: {
|
|
519
|
+
cif: string;
|
|
520
|
+
name: string | null;
|
|
521
|
+
contracts_used: number;
|
|
522
|
+
keywords: string[];
|
|
523
|
+
note?: string;
|
|
524
|
+
};
|
|
525
|
+
tenders: Tender[];
|
|
526
|
+
pagination: {
|
|
527
|
+
total: number;
|
|
528
|
+
page: number;
|
|
529
|
+
limit: number;
|
|
530
|
+
total_pages: number;
|
|
531
|
+
has_more: boolean;
|
|
532
|
+
};
|
|
533
|
+
meta: {
|
|
534
|
+
source: string;
|
|
535
|
+
data_updated_at: string | null;
|
|
536
|
+
status_filter: string;
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
export type SanctionsResultCode = 'clear' | 'possible_match' | 'match';
|
|
540
|
+
export interface SanctionsOptions {
|
|
541
|
+
/** CIF: la empresa y sus administradores vigentes. */
|
|
542
|
+
cif?: string;
|
|
543
|
+
/** O un nombre suelto (persona o entidad). */
|
|
544
|
+
name?: string;
|
|
545
|
+
/** Con name: 'person', 'entity' o 'any' (por defecto). */
|
|
546
|
+
type?: 'person' | 'entity' | 'any';
|
|
547
|
+
/** Con cif: false para no comprobar los administradores. */
|
|
548
|
+
directors?: boolean;
|
|
549
|
+
}
|
|
550
|
+
export interface SanctionMatch {
|
|
551
|
+
level: 'strong' | 'possible';
|
|
552
|
+
score: number;
|
|
553
|
+
list: 'EU' | 'UN' | 'OFAC' | string;
|
|
554
|
+
matched_name: string;
|
|
555
|
+
listed_name: string;
|
|
556
|
+
entry_type: 'person' | 'entity' | 'vessel' | 'aircraft' | 'other';
|
|
557
|
+
programs: string[];
|
|
558
|
+
listed_on: string | null;
|
|
559
|
+
countries: string[];
|
|
560
|
+
birth_dates: string[];
|
|
561
|
+
identifiers: string[];
|
|
562
|
+
reference: string;
|
|
563
|
+
url: string | null;
|
|
564
|
+
}
|
|
565
|
+
export interface SanctionDirectorMatches {
|
|
566
|
+
name: string;
|
|
567
|
+
position: string | null;
|
|
568
|
+
matches: SanctionMatch[];
|
|
569
|
+
}
|
|
570
|
+
export interface SanctionsList {
|
|
571
|
+
list: string;
|
|
572
|
+
description: string;
|
|
573
|
+
entries: number;
|
|
574
|
+
list_date: string | null;
|
|
575
|
+
loaded_at: string;
|
|
576
|
+
}
|
|
577
|
+
export interface SanctionsResult {
|
|
578
|
+
/** Con name. */
|
|
579
|
+
query?: {
|
|
580
|
+
name: string;
|
|
581
|
+
type: string;
|
|
582
|
+
};
|
|
583
|
+
matches?: SanctionMatch[];
|
|
584
|
+
/** Con cif. */
|
|
585
|
+
company?: {
|
|
586
|
+
cif: string;
|
|
587
|
+
name: string;
|
|
588
|
+
matches: SanctionMatch[];
|
|
589
|
+
};
|
|
590
|
+
directors?: SanctionDirectorMatches[];
|
|
591
|
+
summary: {
|
|
592
|
+
strong_matches: number;
|
|
593
|
+
possible_matches: number;
|
|
594
|
+
result: SanctionsResultCode;
|
|
595
|
+
directors_checked?: number;
|
|
596
|
+
directors_included?: boolean;
|
|
597
|
+
};
|
|
598
|
+
lists: SanctionsList[];
|
|
599
|
+
checked_at: string;
|
|
600
|
+
note: string;
|
|
601
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { WebhookPayload } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Comprueba la cabecera X-ApiEmpresas-Signature (t=<timestamp>,v1=<hex>).
|
|
4
|
+
* La firma es HMAC-SHA256(secret, `${t}.${cuerpo}`) sobre el cuerpo tal cual llega:
|
|
5
|
+
* pásale el cuerpo en bruto (string o Buffer), no el JSON ya parseado.
|
|
6
|
+
*
|
|
7
|
+
* @param toleranceSeconds antigüedad máxima aceptada (300 por defecto; 0 = sin límite).
|
|
8
|
+
*/
|
|
9
|
+
export declare function verifyWebhookSignature(rawBody: string | Buffer, signatureHeader: string | null | undefined, secret: string, toleranceSeconds?: number, now?: number): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Comprueba la firma y devuelve el evento parseado. Lanza un Error si la firma no es válida.
|
|
12
|
+
*/
|
|
13
|
+
export declare function constructWebhookEvent<T = any>(rawBody: string | Buffer, signatureHeader: string | null | undefined, secret: string, toleranceSeconds?: number): WebhookPayload<T>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.verifyWebhookSignature = verifyWebhookSignature;
|
|
4
|
+
exports.constructWebhookEvent = constructWebhookEvent;
|
|
5
|
+
const crypto_1 = require("crypto");
|
|
6
|
+
/**
|
|
7
|
+
* Comprueba la cabecera X-ApiEmpresas-Signature (t=<timestamp>,v1=<hex>).
|
|
8
|
+
* La firma es HMAC-SHA256(secret, `${t}.${cuerpo}`) sobre el cuerpo tal cual llega:
|
|
9
|
+
* pásale el cuerpo en bruto (string o Buffer), no el JSON ya parseado.
|
|
10
|
+
*
|
|
11
|
+
* @param toleranceSeconds antigüedad máxima aceptada (300 por defecto; 0 = sin límite).
|
|
12
|
+
*/
|
|
13
|
+
function verifyWebhookSignature(rawBody, signatureHeader, secret, toleranceSeconds = 300, now = Math.floor(Date.now() / 1000)) {
|
|
14
|
+
if (!signatureHeader || !secret)
|
|
15
|
+
return false;
|
|
16
|
+
let t;
|
|
17
|
+
const v1 = [];
|
|
18
|
+
for (const part of signatureHeader.split(',')) {
|
|
19
|
+
const i = part.indexOf('=');
|
|
20
|
+
if (i < 0)
|
|
21
|
+
continue;
|
|
22
|
+
const k = part.slice(0, i).trim();
|
|
23
|
+
const v = part.slice(i + 1).trim();
|
|
24
|
+
if (k === 't')
|
|
25
|
+
t = v;
|
|
26
|
+
else if (k === 'v1')
|
|
27
|
+
v1.push(v);
|
|
28
|
+
}
|
|
29
|
+
if (!t || !/^\d+$/.test(t) || v1.length === 0)
|
|
30
|
+
return false;
|
|
31
|
+
if (toleranceSeconds > 0 && Math.abs(now - parseInt(t, 10)) > toleranceSeconds)
|
|
32
|
+
return false;
|
|
33
|
+
const body = typeof rawBody === 'string' ? rawBody : rawBody.toString('utf8');
|
|
34
|
+
const expected = Buffer.from((0, crypto_1.createHmac)('sha256', secret).update(`${t}.${body}`).digest('hex'), 'utf8');
|
|
35
|
+
return v1.some((sig) => {
|
|
36
|
+
const got = Buffer.from(sig, 'utf8');
|
|
37
|
+
return got.length === expected.length && (0, crypto_1.timingSafeEqual)(got, expected);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Comprueba la firma y devuelve el evento parseado. Lanza un Error si la firma no es válida.
|
|
42
|
+
*/
|
|
43
|
+
function constructWebhookEvent(rawBody, signatureHeader, secret, toleranceSeconds = 300) {
|
|
44
|
+
if (!verifyWebhookSignature(rawBody, signatureHeader, secret, toleranceSeconds)) {
|
|
45
|
+
throw new Error('Firma del webhook no válida o caducada.');
|
|
46
|
+
}
|
|
47
|
+
const body = typeof rawBody === 'string' ? rawBody : rawBody.toString('utf8');
|
|
48
|
+
return JSON.parse(body);
|
|
49
|
+
}
|