@proconnect-gouv/proconnect.insee 1.0.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/CHANGELOG.md +12 -0
- package/dist/api/find-by-siren.d.ts +58 -0
- package/dist/api/find-by-siren.d.ts.map +1 -0
- package/dist/api/find-by-siren.js +33 -0
- package/dist/api/find-by-siret.d.ts +37 -19
- package/dist/api/find-by-siret.d.ts.map +1 -1
- package/dist/api/find-by-siret.js +7 -4
- package/dist/api/index.d.ts +96 -7
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +15 -2
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +1 -4
- package/dist/formatters/birthdate.d.ts.map +1 -1
- package/dist/formatters/birthdate.js +3 -1
- package/dist/testing/seed/index.d.ts +4 -0
- package/dist/testing/seed/index.d.ts.map +1 -0
- package/dist/testing/seed/index.js +16 -0
- package/dist/types/etablissement.d.ts +2 -2
- package/dist/types/etablissement.d.ts.map +1 -1
- package/openapi/index.d.ts +31 -17
- package/openapi/index.yaml +48 -16
- package/package.json +6 -5
- package/src/api/find-by-siren.test.ts +71 -0
- package/src/api/find-by-siren.ts +49 -0
- package/src/api/find-by-siret.test.ts +8 -11
- package/src/api/find-by-siret.ts +11 -7
- package/src/api/index.ts +20 -10
- package/src/client/index.ts +0 -4
- package/src/formatters/birthdate.test.ts +4 -8
- package/src/formatters/birthdate.ts +3 -1
- package/src/testing/seed/index.ts +19 -0
- package/src/types/etablissement.ts +4 -4
- package/tsconfig.lib.tsbuildinfo +1 -1
package/openapi/index.yaml
CHANGED
|
@@ -1069,7 +1069,9 @@ components:
|
|
|
1069
1069
|
et dateFin
|
|
1070
1070
|
properties:
|
|
1071
1071
|
dateFin:
|
|
1072
|
-
type:
|
|
1072
|
+
type:
|
|
1073
|
+
- string
|
|
1074
|
+
- "null"
|
|
1073
1075
|
format: date
|
|
1074
1076
|
$comment:
|
|
1075
1077
|
Null pour la période contenant les valeurs courantes de l'entreprise
|
|
@@ -1129,7 +1131,10 @@ components:
|
|
|
1129
1131
|
"Nomenclature de l'activité, permet de savoir à partir de quelle\
|
|
1130
1132
|
\ nomenclature est codifiée ActivitePrincipaleEtablissement"
|
|
1131
1133
|
enum:
|
|
1132
|
-
-
|
|
1134
|
+
- NAP
|
|
1135
|
+
- NAFRev1
|
|
1136
|
+
- NAFRev2
|
|
1137
|
+
- NAF1993
|
|
1133
1138
|
changementActivitePrincipaleEtablissement:
|
|
1134
1139
|
type: boolean
|
|
1135
1140
|
description:
|
|
@@ -1229,7 +1234,10 @@ components:
|
|
|
1229
1234
|
"Catégorie à laquelle appartient l'entreprise : Petite ou moyenne\
|
|
1230
1235
|
\ entreprise, Entreprise de taille intermédiaire, Grande entreprise"
|
|
1231
1236
|
enum:
|
|
1232
|
-
-
|
|
1237
|
+
- PME
|
|
1238
|
+
- ETI
|
|
1239
|
+
- GE
|
|
1240
|
+
- null
|
|
1233
1241
|
anneeCategorieEntreprise:
|
|
1234
1242
|
type: string
|
|
1235
1243
|
description: Année de validité de la catégorie d'entreprise
|
|
@@ -1240,7 +1248,9 @@ components:
|
|
|
1240
1248
|
type: string
|
|
1241
1249
|
description: Sexe pour les personnes physiques sinon null
|
|
1242
1250
|
enum:
|
|
1243
|
-
-
|
|
1251
|
+
- M
|
|
1252
|
+
- F
|
|
1253
|
+
- null
|
|
1244
1254
|
prenom1UniteLegale:
|
|
1245
1255
|
type: string
|
|
1246
1256
|
description:
|
|
@@ -1270,7 +1280,8 @@ components:
|
|
|
1270
1280
|
"État de l'entreprise pendant la période (A= entreprise active,\
|
|
1271
1281
|
\ C= entreprise cessée)"
|
|
1272
1282
|
enum:
|
|
1273
|
-
-
|
|
1283
|
+
- A
|
|
1284
|
+
- C
|
|
1274
1285
|
nomUniteLegale:
|
|
1275
1286
|
type: string
|
|
1276
1287
|
$comment: Null pour les personnes morales
|
|
@@ -1318,7 +1329,10 @@ components:
|
|
|
1318
1329
|
"Nomenclature de l'activité, permet de savoir à partir de quelle\
|
|
1319
1330
|
\ nomenclature est codifiée ActivitePrincipale"
|
|
1320
1331
|
enum:
|
|
1321
|
-
-
|
|
1332
|
+
- NAP
|
|
1333
|
+
- NAFRev1
|
|
1334
|
+
- NAFRev2
|
|
1335
|
+
- NAF1993
|
|
1322
1336
|
nomUsageUniteLegale:
|
|
1323
1337
|
type: string
|
|
1324
1338
|
description: Nom d’usage pour les personnes physiques sinon null
|
|
@@ -1336,7 +1350,9 @@ components:
|
|
|
1336
1350
|
Caractère employeur de l'entreprise. Valeur courante=O si au
|
|
1337
1351
|
moins l'un des établissements actifs de l'unité légale emploie des salariés
|
|
1338
1352
|
enum:
|
|
1339
|
-
-
|
|
1353
|
+
- O
|
|
1354
|
+
- N
|
|
1355
|
+
- null
|
|
1340
1356
|
ReponseErreur:
|
|
1341
1357
|
type: object
|
|
1342
1358
|
properties:
|
|
@@ -1397,7 +1413,9 @@ components:
|
|
|
1397
1413
|
type: object
|
|
1398
1414
|
properties:
|
|
1399
1415
|
dateFin:
|
|
1400
|
-
type:
|
|
1416
|
+
type:
|
|
1417
|
+
- string
|
|
1418
|
+
- "null"
|
|
1401
1419
|
format: date
|
|
1402
1420
|
$comment:
|
|
1403
1421
|
Null pour la période contenant les valeurs courantes de l'entreprise
|
|
@@ -1416,7 +1434,8 @@ components:
|
|
|
1416
1434
|
"État de l'entreprise pendant la période (A= entreprise active,\
|
|
1417
1435
|
\ C= entreprise cessée)"
|
|
1418
1436
|
enum:
|
|
1419
|
-
-
|
|
1437
|
+
- A
|
|
1438
|
+
- C
|
|
1420
1439
|
changementEtatAdministratifUniteLegale:
|
|
1421
1440
|
type: boolean
|
|
1422
1441
|
description: Indicatrice de changement d'état par rapport à la période précédente
|
|
@@ -1489,7 +1508,10 @@ components:
|
|
|
1489
1508
|
"Nomenclature de l'activité, permet de savoir à partir de quelle\
|
|
1490
1509
|
\ nomenclature est codifiée ActivitePrincipale"
|
|
1491
1510
|
enum:
|
|
1492
|
-
-
|
|
1511
|
+
- NAP
|
|
1512
|
+
- NAFRev1
|
|
1513
|
+
- NAFRev2
|
|
1514
|
+
- NAF1993
|
|
1493
1515
|
changementActivitePrincipaleUniteLegale:
|
|
1494
1516
|
type: boolean
|
|
1495
1517
|
description:
|
|
@@ -1532,7 +1554,9 @@ components:
|
|
|
1532
1554
|
Caractère employeur de l'entreprise. Valeur courante=O si au
|
|
1533
1555
|
moins l'un des établissements actifs de l'unité légale emploie des salariés
|
|
1534
1556
|
enum:
|
|
1535
|
-
-
|
|
1557
|
+
- O
|
|
1558
|
+
- N
|
|
1559
|
+
- null
|
|
1536
1560
|
changementCaractereEmployeurUniteLegale:
|
|
1537
1561
|
type: boolean
|
|
1538
1562
|
description:
|
|
@@ -1644,7 +1668,10 @@ components:
|
|
|
1644
1668
|
"Catégorie à laquelle appartient l'entreprise : Petite ou moyenne\
|
|
1645
1669
|
\ entreprise, Entreprise de taille intermédiaire, Grande entreprise"
|
|
1646
1670
|
enum:
|
|
1647
|
-
-
|
|
1671
|
+
- PME
|
|
1672
|
+
- ETI
|
|
1673
|
+
- GE
|
|
1674
|
+
- null
|
|
1648
1675
|
anneeCategorieEntreprise:
|
|
1649
1676
|
type: string
|
|
1650
1677
|
description: Année de validité de la catégorie d'entreprise
|
|
@@ -1655,7 +1682,9 @@ components:
|
|
|
1655
1682
|
type: string
|
|
1656
1683
|
description: Sexe pour les personnes physiques sinon null
|
|
1657
1684
|
enum:
|
|
1658
|
-
-
|
|
1685
|
+
- M
|
|
1686
|
+
- F
|
|
1687
|
+
- null
|
|
1659
1688
|
prenom1UniteLegale:
|
|
1660
1689
|
type: string
|
|
1661
1690
|
description:
|
|
@@ -1795,7 +1824,8 @@ components:
|
|
|
1795
1824
|
type: string
|
|
1796
1825
|
description: Nom de la collection
|
|
1797
1826
|
enum:
|
|
1798
|
-
- "Unités Légales
|
|
1827
|
+
- "Unités Légales"
|
|
1828
|
+
- "Établissements"
|
|
1799
1829
|
dateDerniereMiseADisposition:
|
|
1800
1830
|
type: string
|
|
1801
1831
|
format: date-time
|
|
@@ -1829,7 +1859,8 @@ components:
|
|
|
1829
1859
|
type: string
|
|
1830
1860
|
description: Etat du service
|
|
1831
1861
|
enum:
|
|
1832
|
-
-
|
|
1862
|
+
- UP
|
|
1863
|
+
- DOWN
|
|
1833
1864
|
ReponseInformations:
|
|
1834
1865
|
type: object
|
|
1835
1866
|
description:
|
|
@@ -1842,7 +1873,8 @@ components:
|
|
|
1842
1873
|
type: string
|
|
1843
1874
|
description: État actuel du service
|
|
1844
1875
|
enum:
|
|
1845
|
-
-
|
|
1876
|
+
- UP
|
|
1877
|
+
- DOWN
|
|
1846
1878
|
etatsDesServices:
|
|
1847
1879
|
type: array
|
|
1848
1880
|
description: Etats des services
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@proconnect-gouv/proconnect.insee",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"homepage": "https://github.com/proconnect-gouv/proconnect-identite/tree/main/packages/insee#readme",
|
|
5
5
|
"bugs": "https://github.com/proconnect-gouv/proconnect-identite/issues",
|
|
6
6
|
"repository": {
|
|
@@ -28,17 +28,18 @@
|
|
|
28
28
|
},
|
|
29
29
|
"scripts": {
|
|
30
30
|
"build": "tsc --build tsconfig.lib.json",
|
|
31
|
-
"check": "npm run build -- --noEmit",
|
|
32
|
-
"dev": "npm run build -- --watch --preserveWatchOutput",
|
|
33
31
|
"build:openapi": "npm run build:openapi:auth && npm run build:openapi:index",
|
|
32
|
+
"postbuild:openapi": "prettier --write openapi/*.d.ts",
|
|
34
33
|
"build:openapi:auth": "openapi-typescript openapi/auth.yaml -o openapi/auth.d.ts",
|
|
35
34
|
"build:openapi:index": "openapi-typescript openapi/index.yaml -o openapi/index.d.ts",
|
|
35
|
+
"check": "npm run build -- --noEmit",
|
|
36
|
+
"clean": "rm -rf dist tsconfig*.tsbuildinfo",
|
|
37
|
+
"dev": "npm run build -- --watch --preserveWatchOutput",
|
|
36
38
|
"dev:test": "tsx --watch --test src/**/*.test.ts",
|
|
37
|
-
"postbuild:openapi": "prettier --write openapi/*.d.ts",
|
|
38
39
|
"test": "tsx --test --test-reporter=spec src/**/*.test.ts"
|
|
39
40
|
},
|
|
40
41
|
"dependencies": {
|
|
41
|
-
"openapi-fetch": "^0.
|
|
42
|
+
"openapi-fetch": "^0.17.0"
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
|
44
45
|
"@proconnect-gouv/proconnect.devtools.typescript": "1.0.0",
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import { createInseeSirenePrivateOpenApiClient } from "#src/client";
|
|
4
|
+
import { InseeApiError } from "#src/types";
|
|
5
|
+
import assert from "node:assert/strict";
|
|
6
|
+
import { mock, suite, test } from "node:test";
|
|
7
|
+
import { findUniteLegaleBySirenFactory } from "./find-by-siren.js";
|
|
8
|
+
|
|
9
|
+
//
|
|
10
|
+
|
|
11
|
+
suite("findBySirenFactory", () => {
|
|
12
|
+
test("should return an establishment from a siret", async () => {
|
|
13
|
+
const fetch = mock.fn(() => {
|
|
14
|
+
return Promise.resolve(
|
|
15
|
+
new Response(
|
|
16
|
+
JSON.stringify({
|
|
17
|
+
header: { statut: 200 },
|
|
18
|
+
uniteLegale: {
|
|
19
|
+
prenom1UniteLegale: "🐹",
|
|
20
|
+
periodesUniteLegale: [{ dateFin: null, nomUniteLegale: "🦄" }],
|
|
21
|
+
},
|
|
22
|
+
}),
|
|
23
|
+
),
|
|
24
|
+
);
|
|
25
|
+
});
|
|
26
|
+
const client = createInseeSirenePrivateOpenApiClient({
|
|
27
|
+
fetch,
|
|
28
|
+
});
|
|
29
|
+
const findUniteLegaleBySiret = findUniteLegaleBySirenFactory(client);
|
|
30
|
+
|
|
31
|
+
const uniteLegale = await findUniteLegaleBySiret("662042449");
|
|
32
|
+
|
|
33
|
+
assert.deepEqual(uniteLegale, {
|
|
34
|
+
prenom1UniteLegale: "🐹",
|
|
35
|
+
periodesUniteLegale: [{ dateFin: null, nomUniteLegale: "🦄" }],
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("❎ fails if not active period found", async () => {
|
|
40
|
+
const fetch = mock.fn(() => {
|
|
41
|
+
return Promise.resolve(
|
|
42
|
+
new Response(
|
|
43
|
+
JSON.stringify({
|
|
44
|
+
header: { statut: 200 },
|
|
45
|
+
uniteLegale: {
|
|
46
|
+
prenom1UniteLegale: "🐹",
|
|
47
|
+
periodesUniteLegale: [
|
|
48
|
+
{ dateFin: "2023-01-01", nomUniteLegale: "🦄" },
|
|
49
|
+
],
|
|
50
|
+
},
|
|
51
|
+
}),
|
|
52
|
+
),
|
|
53
|
+
);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const client = createInseeSirenePrivateOpenApiClient({
|
|
57
|
+
fetch,
|
|
58
|
+
});
|
|
59
|
+
const findUniteLegaleBySiret = findUniteLegaleBySirenFactory(client);
|
|
60
|
+
|
|
61
|
+
await assert.rejects(
|
|
62
|
+
findUniteLegaleBySiret("♨️"),
|
|
63
|
+
new InseeApiError({
|
|
64
|
+
header: {
|
|
65
|
+
statut: 409,
|
|
66
|
+
message: "Not active periode with nomUniteLegale",
|
|
67
|
+
},
|
|
68
|
+
}),
|
|
69
|
+
);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import type { InseeSirenePrivateOpenApiClient } from "#src/client";
|
|
4
|
+
import { InseeApiError } from "#src/types";
|
|
5
|
+
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
export function findUniteLegaleBySirenFactory(
|
|
9
|
+
client: InseeSirenePrivateOpenApiClient,
|
|
10
|
+
) {
|
|
11
|
+
return async function findUniteLegaleBySiren(siren: string) {
|
|
12
|
+
const { data, error } = await client.GET("/siren/{siren}", {
|
|
13
|
+
params: {
|
|
14
|
+
path: {
|
|
15
|
+
siren,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
if (error) throw new InseeApiError(error);
|
|
21
|
+
if (!data)
|
|
22
|
+
throw new InseeApiError({
|
|
23
|
+
header: { statut: 404, message: "Not Data" },
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
if (!data.uniteLegale)
|
|
27
|
+
throw new InseeApiError({
|
|
28
|
+
header: { statut: 404, message: "Not unite legale" },
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const nomUniteLegale = data.uniteLegale.periodesUniteLegale?.find(
|
|
32
|
+
(periode) => periode.dateFin === null,
|
|
33
|
+
)?.nomUniteLegale;
|
|
34
|
+
|
|
35
|
+
if (!nomUniteLegale)
|
|
36
|
+
throw new InseeApiError({
|
|
37
|
+
header: {
|
|
38
|
+
statut: 409,
|
|
39
|
+
message: "Not active periode with nomUniteLegale",
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
return data.uniteLegale;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export type FindUniteLegaleBySirenHandler = ReturnType<
|
|
48
|
+
typeof findUniteLegaleBySirenFactory
|
|
49
|
+
>;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { createInseeSirenePrivateOpenApiClient } from "#src/client";
|
|
4
4
|
import assert from "node:assert/strict";
|
|
5
5
|
import { mock, suite, test } from "node:test";
|
|
6
|
-
import {
|
|
6
|
+
import { findUniteLegaleBySiretFactory } from "./find-by-siret.js";
|
|
7
7
|
|
|
8
8
|
//
|
|
9
9
|
|
|
@@ -14,21 +14,18 @@ suite("findBySiretFactory", () => {
|
|
|
14
14
|
new Response(
|
|
15
15
|
JSON.stringify({
|
|
16
16
|
header: { statut: 200 },
|
|
17
|
-
etablissement: {
|
|
17
|
+
etablissement: { uniteLegale: { nomUniteLegale: "🦄" } },
|
|
18
18
|
}),
|
|
19
19
|
),
|
|
20
20
|
);
|
|
21
21
|
});
|
|
22
|
-
const client = createInseeSirenePrivateOpenApiClient(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
},
|
|
27
|
-
);
|
|
28
|
-
const findBySiret = findBySiretFactory(client);
|
|
22
|
+
const client = createInseeSirenePrivateOpenApiClient({
|
|
23
|
+
fetch,
|
|
24
|
+
});
|
|
25
|
+
const findUniteLegaleBySiret = findUniteLegaleBySiretFactory(client);
|
|
29
26
|
|
|
30
|
-
const
|
|
27
|
+
const uniteLegale = await findUniteLegaleBySiret("662042449");
|
|
31
28
|
|
|
32
|
-
assert.equal(
|
|
29
|
+
assert.equal(uniteLegale.nomUniteLegale, "🦄");
|
|
33
30
|
});
|
|
34
31
|
});
|
package/src/api/find-by-siret.ts
CHANGED
|
@@ -2,17 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
import type { InseeSirenePrivateOpenApiClient } from "#src/client";
|
|
4
4
|
import { InseeApiError } from "#src/types";
|
|
5
|
-
import type { FetchOptions } from "openapi-fetch";
|
|
6
5
|
|
|
7
6
|
//
|
|
8
7
|
|
|
9
|
-
export function
|
|
8
|
+
export function findUniteLegaleBySiretFactory(
|
|
10
9
|
client: InseeSirenePrivateOpenApiClient,
|
|
11
|
-
optionsFn: () => FetchOptions<unknown> = () => ({}),
|
|
12
10
|
) {
|
|
13
|
-
return async function
|
|
11
|
+
return async function findUniteLegaleBySiret(siret: string) {
|
|
14
12
|
const { data, error } = await client.GET("/siret/{siret}", {
|
|
15
|
-
...optionsFn(),
|
|
16
13
|
params: {
|
|
17
14
|
path: {
|
|
18
15
|
siret,
|
|
@@ -29,8 +26,15 @@ export function findBySiretFactory(
|
|
|
29
26
|
if (data.header?.statut !== 200 || !data.etablissement)
|
|
30
27
|
throw new InseeApiError(data);
|
|
31
28
|
|
|
32
|
-
|
|
29
|
+
if (!data.etablissement.uniteLegale)
|
|
30
|
+
throw new InseeApiError({
|
|
31
|
+
header: { statut: 404, message: "Not unite legale" },
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
return data.etablissement.uniteLegale;
|
|
33
35
|
};
|
|
34
36
|
}
|
|
35
37
|
|
|
36
|
-
export type
|
|
38
|
+
export type FindUniteLegaleBySiretHandler = ReturnType<
|
|
39
|
+
typeof findUniteLegaleBySiretFactory
|
|
40
|
+
>;
|
package/src/api/index.ts
CHANGED
|
@@ -1,16 +1,26 @@
|
|
|
1
1
|
//
|
|
2
2
|
|
|
3
|
-
import type {
|
|
4
|
-
import
|
|
3
|
+
import type { InseeSirenePrivateOpenApiClient } from "#src/client";
|
|
4
|
+
import { findUniteLegaleBySirenFactory } from "./find-by-siren.js";
|
|
5
|
+
import { findUniteLegaleBySiretFactory } from "./find-by-siret.js";
|
|
5
6
|
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
export * from "./find-by-siret.js";
|
|
9
7
|
export * from "./get-insee-access-token.js";
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
export function createApiInseeClient(
|
|
10
|
+
client: InseeSirenePrivateOpenApiClient,
|
|
11
|
+
getAuthorizationToken: () => Promise<string>,
|
|
12
|
+
) {
|
|
13
|
+
client.use({
|
|
14
|
+
async onRequest({ request }) {
|
|
15
|
+
const token = await getAuthorizationToken();
|
|
16
|
+
request.headers.set("Authorization", `Bearer ${token}`);
|
|
17
|
+
return request;
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
return {
|
|
21
|
+
findBySiren: findUniteLegaleBySirenFactory(client),
|
|
22
|
+
findBySiret: findUniteLegaleBySiretFactory(client),
|
|
23
|
+
};
|
|
16
24
|
}
|
|
25
|
+
|
|
26
|
+
export type ApiInseeClient = ReturnType<typeof createApiInseeClient>;
|
package/src/client/index.ts
CHANGED
|
@@ -13,14 +13,10 @@ import createClient, { type ClientOptions } from "openapi-fetch";
|
|
|
13
13
|
* @returns the client
|
|
14
14
|
*/
|
|
15
15
|
export function createInseeSirenePrivateOpenApiClient(
|
|
16
|
-
token: string,
|
|
17
16
|
options: ClientOptions = {},
|
|
18
17
|
) {
|
|
19
18
|
return createClient<paths>({
|
|
20
19
|
baseUrl: options.baseUrl ?? "https://api.insee.fr/api-sirene/prive/3.11",
|
|
21
|
-
headers: {
|
|
22
|
-
Authorization: `Bearer ${token}`,
|
|
23
|
-
},
|
|
24
20
|
...options,
|
|
25
21
|
});
|
|
26
22
|
}
|
|
@@ -8,8 +8,9 @@ import { formatBirthdate } from "./birthdate.js";
|
|
|
8
8
|
|
|
9
9
|
describe("formatBirthdate", function () {
|
|
10
10
|
const cases: [Parameters<typeof formatBirthdate>, Date][] = [
|
|
11
|
-
[["
|
|
12
|
-
[["
|
|
11
|
+
[["00000000"], new Date(Date.UTC(0, -1, 0))],
|
|
12
|
+
[["18991129"], new Date(Date.UTC(1899, 10, 29))],
|
|
13
|
+
[["19800601"], new Date(Date.UTC(1980, 5, 1))],
|
|
13
14
|
];
|
|
14
15
|
|
|
15
16
|
for (const [parameters, expected] of cases) {
|
|
@@ -25,12 +26,7 @@ describe("formatBirthdate", function () {
|
|
|
25
26
|
new Error("Invalid date format. Expected YYYYMMDD. Actual: "),
|
|
26
27
|
);
|
|
27
28
|
});
|
|
28
|
-
|
|
29
|
-
assert.throws(
|
|
30
|
-
() => formatBirthdate("00000000"),
|
|
31
|
-
new Error("Invalid date format. 0000-00-00"),
|
|
32
|
-
);
|
|
33
|
-
});
|
|
29
|
+
|
|
34
30
|
it("❎ fails with unexpected format", function () {
|
|
35
31
|
assert.throws(
|
|
36
32
|
() => formatBirthdate("1er avril 4444"),
|
|
@@ -15,7 +15,9 @@ export function formatBirthdate(value: string) {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
const { year, month, day } = match.groups;
|
|
18
|
-
|
|
18
|
+
// Use Date.UTC to ensure timezone-independent date creation
|
|
19
|
+
// Month is 0-indexed in Date.UTC
|
|
20
|
+
const date = new Date(Date.UTC(Number(year), Number(month) - 1, Number(day)));
|
|
19
21
|
if (isNaN(date.getTime())) {
|
|
20
22
|
throw new Error(`Invalid date format. ${year}-${month}-${day}`);
|
|
21
23
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { InseSirenUniteLegale } from "#src/types";
|
|
2
|
+
|
|
3
|
+
export const LiElJonsonEstablishment: InseSirenUniteLegale = {
|
|
4
|
+
codePaysNaissanceUniteLegale: undefined,
|
|
5
|
+
codeCommuneNaissanceUniteLegale: "75056",
|
|
6
|
+
dateNaissanceUniteLegale: "285000205",
|
|
7
|
+
periodesUniteLegale: [{ dateFin: null, nomUniteLegale: "EL'JONSON" }],
|
|
8
|
+
prenom1UniteLegale: "LION",
|
|
9
|
+
sexeUniteLegale: "M",
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const RogalDornEstablishment: InseSirenUniteLegale = {
|
|
13
|
+
codePaysNaissanceUniteLegale: "99102",
|
|
14
|
+
codeCommuneNaissanceUniteLegale: undefined,
|
|
15
|
+
dateNaissanceUniteLegale: "290000107",
|
|
16
|
+
periodesUniteLegale: [{ dateFin: null, nomUniteLegale: "DORN" }],
|
|
17
|
+
prenom1UniteLegale: "ROGAL",
|
|
18
|
+
sexeUniteLegale: "M",
|
|
19
|
+
};
|
|
@@ -4,9 +4,9 @@ import type { paths } from "#openapi";
|
|
|
4
4
|
|
|
5
5
|
//
|
|
6
6
|
|
|
7
|
-
export type
|
|
8
|
-
paths["/
|
|
7
|
+
export type InseeSirenResponse =
|
|
8
|
+
paths["/siren/{siren}"]["get"]["responses"][200]["content"]["application/json"];
|
|
9
9
|
|
|
10
|
-
export type
|
|
11
|
-
|
|
10
|
+
export type InseSirenUniteLegale = NonNullable<
|
|
11
|
+
InseeSirenResponse["uniteLegale"]
|
|
12
12
|
>;
|