@proconnect-gouv/proconnect.api_entreprise 1.1.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.
Files changed (126) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +66 -0
  3. package/dist/api/index.d.ts +10 -0
  4. package/dist/api/index.d.ts.map +1 -0
  5. package/dist/api/index.js +2 -0
  6. package/dist/api/infogreffe/find-mandataires-sociaux-by-siren.d.ts +21 -0
  7. package/dist/api/infogreffe/find-mandataires-sociaux-by-siren.d.ts.map +1 -0
  8. package/dist/api/infogreffe/find-mandataires-sociaux-by-siren.js +20 -0
  9. package/dist/api/infogreffe/index.d.ts +2 -0
  10. package/dist/api/infogreffe/index.d.ts.map +1 -0
  11. package/dist/api/infogreffe/index.js +2 -0
  12. package/dist/api/insee/find-by-siren.d.ts +95 -0
  13. package/dist/api/insee/find-by-siren.d.ts.map +1 -0
  14. package/dist/api/insee/find-by-siren.js +20 -0
  15. package/dist/api/insee/find-by-siret.d.ts +95 -0
  16. package/dist/api/insee/find-by-siret.d.ts.map +1 -0
  17. package/dist/api/insee/find-by-siret.js +20 -0
  18. package/dist/api/insee/index.d.ts +3 -0
  19. package/dist/api/insee/index.d.ts.map +1 -0
  20. package/dist/api/insee/index.js +3 -0
  21. package/dist/client/index.d.ts +21 -0
  22. package/dist/client/index.d.ts.map +1 -0
  23. package/dist/client/index.js +21 -0
  24. package/dist/formatters/adresse-establishment.d.ts +3 -0
  25. package/dist/formatters/adresse-establishment.d.ts.map +1 -0
  26. package/dist/formatters/adresse-establishment.js +41 -0
  27. package/dist/formatters/index.d.ts +5 -0
  28. package/dist/formatters/index.d.ts.map +1 -0
  29. package/dist/formatters/index.js +5 -0
  30. package/dist/formatters/libelle-from-code-effectif.d.ts +2 -0
  31. package/dist/formatters/libelle-from-code-effectif.d.ts.map +1 -0
  32. package/dist/formatters/libelle-from-code-effectif.js +10 -0
  33. package/dist/formatters/main-activity.d.ts +3 -0
  34. package/dist/formatters/main-activity.d.ts.map +1 -0
  35. package/dist/formatters/main-activity.js +7 -0
  36. package/dist/formatters/nom-complet.d.ts +10 -0
  37. package/dist/formatters/nom-complet.d.ts.map +1 -0
  38. package/dist/formatters/nom-complet.js +22 -0
  39. package/dist/testing/index.d.ts +3 -0
  40. package/dist/testing/index.d.ts.map +1 -0
  41. package/dist/testing/index.js +7 -0
  42. package/dist/testing/seed/insee/siret/00557246600026.d.ts +4 -0
  43. package/dist/testing/seed/insee/siret/00557246600026.d.ts.map +1 -0
  44. package/dist/testing/seed/insee/siret/00557246600026.js +96 -0
  45. package/dist/testing/seed/insee/siret/20007184300060.d.ts +4 -0
  46. package/dist/testing/seed/insee/siret/20007184300060.d.ts.map +1 -0
  47. package/dist/testing/seed/insee/siret/20007184300060.js +91 -0
  48. package/dist/testing/seed/insee/siret/21920023500014.d.ts +4 -0
  49. package/dist/testing/seed/insee/siret/21920023500014.d.ts.map +1 -0
  50. package/dist/testing/seed/insee/siret/21920023500014.js +91 -0
  51. package/dist/testing/seed/insee/siret/32122785200019.d.ts +4 -0
  52. package/dist/testing/seed/insee/siret/32122785200019.d.ts.map +1 -0
  53. package/dist/testing/seed/insee/siret/32122785200019.js +95 -0
  54. package/dist/testing/seed/insee/siret/39234600300198.d.ts +4 -0
  55. package/dist/testing/seed/insee/siret/39234600300198.d.ts.map +1 -0
  56. package/dist/testing/seed/insee/siret/39234600300198.js +92 -0
  57. package/dist/testing/seed/insee/siret/41816609600069.d.ts +4 -0
  58. package/dist/testing/seed/insee/siret/41816609600069.d.ts.map +1 -0
  59. package/dist/testing/seed/insee/siret/41816609600069.js +91 -0
  60. package/dist/testing/seed/insee/siret/43841606700017.d.ts +4 -0
  61. package/dist/testing/seed/insee/siret/43841606700017.d.ts.map +1 -0
  62. package/dist/testing/seed/insee/siret/43841606700017.js +91 -0
  63. package/dist/testing/seed/insee/siret/78824266700020.d.ts +4 -0
  64. package/dist/testing/seed/insee/siret/78824266700020.d.ts.map +1 -0
  65. package/dist/testing/seed/insee/siret/78824266700020.js +91 -0
  66. package/dist/testing/seed/insee/siret/81104725700019.d.ts +4 -0
  67. package/dist/testing/seed/insee/siret/81104725700019.d.ts.map +1 -0
  68. package/dist/testing/seed/insee/siret/81104725700019.js +93 -0
  69. package/dist/testing/seed/insee/siret/82271212100018.d.ts +4 -0
  70. package/dist/testing/seed/insee/siret/82271212100018.d.ts.map +1 -0
  71. package/dist/testing/seed/insee/siret/82271212100018.js +95 -0
  72. package/dist/testing/seed/insee/siret/94957325700019.d.ts +4 -0
  73. package/dist/testing/seed/insee/siret/94957325700019.d.ts.map +1 -0
  74. package/dist/testing/seed/insee/siret/94957325700019.js +96 -0
  75. package/dist/testing/seed/insee/siret/index.d.ts +12 -0
  76. package/dist/testing/seed/insee/siret/index.d.ts.map +1 -0
  77. package/dist/testing/seed/insee/siret/index.js +14 -0
  78. package/dist/types/errors.d.ts +17 -0
  79. package/dist/types/errors.d.ts.map +1 -0
  80. package/dist/types/errors.js +37 -0
  81. package/dist/types/establishment.d.ts +8 -0
  82. package/dist/types/establishment.d.ts.map +1 -0
  83. package/dist/types/establishment.js +2 -0
  84. package/dist/types/index.d.ts +3 -0
  85. package/dist/types/index.d.ts.map +1 -0
  86. package/dist/types/index.js +3 -0
  87. package/openapi/index.d.ts +13652 -0
  88. package/package.json +50 -0
  89. package/src/api/index.ts +13 -0
  90. package/src/api/infogreffe/find-mandataires-sociaux-by-siren.test.ts +161 -0
  91. package/src/api/infogreffe/find-mandataires-sociaux-by-siren.ts +41 -0
  92. package/src/api/infogreffe/index.ts +3 -0
  93. package/src/api/insee/find-by-siren.test.ts +27 -0
  94. package/src/api/insee/find-by-siren.ts +38 -0
  95. package/src/api/insee/find-by-siret.test.ts +26 -0
  96. package/src/api/insee/find-by-siret.ts +38 -0
  97. package/src/api/insee/index.ts +4 -0
  98. package/src/client/index.ts +43 -0
  99. package/src/formatters/adresse-establishment.test.ts +55 -0
  100. package/src/formatters/adresse-establishment.ts +67 -0
  101. package/src/formatters/index.ts +6 -0
  102. package/src/formatters/libelle-from-code-effectif.test.ts +23 -0
  103. package/src/formatters/libelle-from-code-effectif.ts +16 -0
  104. package/src/formatters/main-activity.test.ts +33 -0
  105. package/src/formatters/main-activity.ts +10 -0
  106. package/src/formatters/nom-complet.test.ts +67 -0
  107. package/src/formatters/nom-complet.ts +47 -0
  108. package/src/testing/index.ts +11 -0
  109. package/src/testing/seed/insee/siret/00557246600026.ts +99 -0
  110. package/src/testing/seed/insee/siret/20007184300060.ts +93 -0
  111. package/src/testing/seed/insee/siret/21920023500014.ts +93 -0
  112. package/src/testing/seed/insee/siret/32122785200019.ts +97 -0
  113. package/src/testing/seed/insee/siret/39234600300198.ts +95 -0
  114. package/src/testing/seed/insee/siret/41816609600069.ts +93 -0
  115. package/src/testing/seed/insee/siret/43841606700017.ts +95 -0
  116. package/src/testing/seed/insee/siret/78824266700020.ts +93 -0
  117. package/src/testing/seed/insee/siret/81104725700019.ts +95 -0
  118. package/src/testing/seed/insee/siret/82271212100018.ts +98 -0
  119. package/src/testing/seed/insee/siret/94957325700019.ts +99 -0
  120. package/src/testing/seed/insee/siret/index.ts +15 -0
  121. package/src/types/errors.ts +48 -0
  122. package/src/types/establishment.ts +24 -0
  123. package/src/types/index.ts +4 -0
  124. package/tsconfig.json +12 -0
  125. package/tsconfig.lib.json +9 -0
  126. package/tsconfig.lib.tsbuildinfo +1 -0
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@proconnect-gouv/proconnect.api_entreprise",
3
+ "version": "1.1.0",
4
+ "homepage": "https://github.com/proconnect-gouv/proconnect-identite/tree/main/packages/entreprise#readme",
5
+ "bugs": "https://github.com/proconnect-gouv/proconnect-identite/issues",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/proconnect-gouv/proconnect-identite.git",
9
+ "directory": "packages/entreprise"
10
+ },
11
+ "license": "MIT",
12
+ "sideEffects": false,
13
+ "type": "module",
14
+ "imports": {
15
+ "#openapi": "./openapi/index.d.ts",
16
+ "#src/*": {
17
+ "types": "./dist/*/index.d.ts",
18
+ "default": "./dist/*/index.js"
19
+ },
20
+ "#testing": "./src/testing/index.ts"
21
+ },
22
+ "exports": {
23
+ "./*": {
24
+ "types": "./dist/*/index.d.ts",
25
+ "default": "./dist/*/index.js"
26
+ }
27
+ },
28
+ "scripts": {
29
+ "build": "tsc --build tsconfig.lib.json",
30
+ "check": "npm run build -- --noEmit",
31
+ "dev": "npm run build -- --watch --preserveWatchOutput",
32
+ "build:openapi": "openapi-typescript https://entreprise.api.gouv.fr/open-api-without-deprecated-paths.yml -o openapi/index.d.ts",
33
+ "dev:test": "tsx --watch --test src/**/*.test.ts",
34
+ "postbuild:openapi": "prettier --write openapi/index.d.ts",
35
+ "test": "tsx --test --test-reporter=spec src/**/*.test.ts"
36
+ },
37
+ "dependencies": {
38
+ "openapi-fetch": "^0.15.0"
39
+ },
40
+ "devDependencies": {
41
+ "@proconnect-gouv/proconnect.devtools.typescript": "1.0.0",
42
+ "@types/node": "^22.18.6",
43
+ "openapi-typescript": "^7.9.1",
44
+ "tsx": "^4.20.3"
45
+ },
46
+ "publishConfig": {
47
+ "access": "public",
48
+ "provenance": true
49
+ }
50
+ }
@@ -0,0 +1,13 @@
1
+ //
2
+
3
+ import type { FindMandatairesSociauxBySirenHandler } from "./infogreffe/index.js";
4
+ import type { FindBySirenHandler, FindBySiretHandler } from "./insee/index.js";
5
+
6
+ export interface ApiEntrepriseInseeRepository {
7
+ findBySiren: FindBySirenHandler;
8
+ findBySiret: FindBySiretHandler;
9
+ }
10
+
11
+ export interface ApiEntrepriseInfogreffeRepository {
12
+ findMandatairesSociauxBySiren: FindMandatairesSociauxBySirenHandler;
13
+ }
@@ -0,0 +1,161 @@
1
+ //
2
+
3
+ import { createEntrepriseOpenApiClient } from "#src/client";
4
+ import { coolTrackingParams } from "#src/testing";
5
+ import { ApiEntrepriseError } from "#src/types";
6
+ import assert from "node:assert/strict";
7
+ import { mock, suite, test } from "node:test";
8
+ import { findMandatairesSociauxBySirenFactory } from "./find-mandataires-sociaux-by-siren.js";
9
+
10
+ //
11
+
12
+ suite("findMandatairesSociauxBySirenFactory", () => {
13
+ test("should return an array of mandataires from a siren", async () => {
14
+ const fetch = mock.fn(() => {
15
+ return Promise.resolve(
16
+ new Response(
17
+ JSON.stringify({
18
+ data: [
19
+ {
20
+ data: {
21
+ fonction: "Phaeron",
22
+ nom: "THE STORMLORD",
23
+ type: "personne_physique",
24
+ prenom: "IMOTEKH",
25
+ date_naissance: "2023-01-20",
26
+ date_naissance_timestamp: 1674172800,
27
+ lieu_naissance: "SAUTEKH TOMB WORLD",
28
+ pays_naissance: "NECRONTYR",
29
+ code_pays_naissance: "NC",
30
+ nationalite: "NECRON",
31
+ code_nationalite: "NC",
32
+ },
33
+ links: {
34
+ organization: 1,
35
+ },
36
+ meta: {
37
+ dynasty: "Sautekh",
38
+ },
39
+ },
40
+ {
41
+ data: {
42
+ fonction: "Archaeologist",
43
+ nom: "THE INFINITE",
44
+ type: "personne_physique",
45
+ prenom: "TRAZYN",
46
+ date_naissance: "2023-02-25",
47
+ date_naissance_timestamp: 1677283200,
48
+ lieu_naissance: "NIHILAKH TOMB WORLD",
49
+ pays_naissance: "NECRONTYR",
50
+ code_pays_naissance: "NC",
51
+ nationalite: "NECRON",
52
+ code_nationalite: "NC",
53
+ },
54
+ links: {
55
+ organization: 2,
56
+ },
57
+ meta: {
58
+ dynasty: "Nihilakh",
59
+ },
60
+ },
61
+ {
62
+ data: {
63
+ fonction: "Chapter Master",
64
+ nom: "CALGAR",
65
+ type: "personne_physique",
66
+ prenom: "MARNEUS",
67
+ date_naissance: "2023-06-20",
68
+ date_naissance_timestamp: 1687219200,
69
+ lieu_naissance: "MACRAGGE",
70
+ pays_naissance: "ULTRAMAR",
71
+ code_pays_naissance: "UM",
72
+ nationalite: "IMPERIAL",
73
+ code_nationalite: "IM",
74
+ },
75
+ links: {
76
+ organization: 5,
77
+ },
78
+ meta: {
79
+ chapter: "Ultramarines",
80
+ },
81
+ },
82
+ {
83
+ data: {
84
+ fonction: "Daemon Primarch",
85
+ nom: "PRIMARCH",
86
+ type: "personne_physique",
87
+ prenom: "MORTARION",
88
+ date_naissance: "2023-07-25",
89
+ date_naissance_timestamp: 1690243200,
90
+ lieu_naissance: "BARBARUS",
91
+ pays_naissance: "EYE OF TERROR",
92
+ code_pays_naissance: "ET",
93
+ nationalite: "CHAOS",
94
+ code_nationalite: "CH",
95
+ },
96
+ links: {},
97
+ meta: {
98
+ legion: "Death Guard",
99
+ },
100
+ },
101
+ ],
102
+ meta: {
103
+ personnes_physiques_count: 4,
104
+ personnes_morales_count: 0,
105
+ count: 4,
106
+ },
107
+ links: {},
108
+ }),
109
+ ),
110
+ );
111
+ });
112
+ const client = createEntrepriseOpenApiClient("SECRET_INSEE_TOKEN", {
113
+ fetch,
114
+ });
115
+ const findBySiren = findMandatairesSociauxBySirenFactory(
116
+ client,
117
+ coolTrackingParams,
118
+ );
119
+
120
+ const mandataires = await findBySiren("791088917");
121
+
122
+ assert.equal(mandataires.length, 4);
123
+ assert.equal(mandataires.at(0)?.prenom, "IMOTEKH");
124
+ });
125
+
126
+ test("fail with an ApiEntrepriseError", async () => {
127
+ const fetch = mock.fn(() => {
128
+ return Promise.resolve(
129
+ new Response(
130
+ JSON.stringify({
131
+ errors: [
132
+ {
133
+ code: "02003",
134
+ title: "Entité non trouvée",
135
+ detail:
136
+ "Le siren indiqué n'existe pas, n'est pas connu ou ne comporte aucune information pour cet appel. Veuillez vérifier que l'identifiant correspond au périmètre couvert par l'API.",
137
+ meta: {
138
+ provider: "Infogreffe",
139
+ provider_error: {
140
+ code: "006",
141
+ message: "DOSSIER NON TROUVE DANS LA BASE DE GREFFES",
142
+ },
143
+ },
144
+ },
145
+ ],
146
+ }),
147
+ { status: 404 },
148
+ ),
149
+ );
150
+ });
151
+ const client = createEntrepriseOpenApiClient("SECRET_INSEE_TOKEN", {
152
+ fetch,
153
+ });
154
+ const findBySiren = findMandatairesSociauxBySirenFactory(
155
+ client,
156
+ coolTrackingParams,
157
+ );
158
+
159
+ await assert.rejects(findBySiren("791088917"), ApiEntrepriseError);
160
+ });
161
+ });
@@ -0,0 +1,41 @@
1
+ //
2
+
3
+ import type {
4
+ ApiEntrepriseOpenApiClient,
5
+ ApiEntrepriseTrackingParams,
6
+ } from "#src/client";
7
+ import { ApiEntrepriseError } from "#src/types";
8
+ import type { FetchOptions } from "openapi-fetch";
9
+
10
+ //
11
+
12
+ export function findMandatairesSociauxBySirenFactory(
13
+ client: ApiEntrepriseOpenApiClient,
14
+ trackingParams: ApiEntrepriseTrackingParams,
15
+ optionsFn: () => FetchOptions<unknown> = () => ({}),
16
+ ) {
17
+ return async function findMandatairesSociauxBySiren(siren: string) {
18
+ const { data, error } = await client.GET(
19
+ "/v3/infogreffe/rcs/unites_legales/{siren}/mandataires_sociaux",
20
+ {
21
+ ...optionsFn(),
22
+ params: {
23
+ path: {
24
+ siren,
25
+ },
26
+ query: trackingParams,
27
+ },
28
+ },
29
+ );
30
+
31
+ if (error) throw new ApiEntrepriseError(error);
32
+
33
+ const { data: peoples } = data;
34
+
35
+ return peoples.map(({ data }) => data).filter((data) => !!data);
36
+ };
37
+ }
38
+
39
+ export type FindMandatairesSociauxBySirenHandler = ReturnType<
40
+ typeof findMandatairesSociauxBySirenFactory
41
+ >;
@@ -0,0 +1,3 @@
1
+ //
2
+
3
+ export * from "./find-mandataires-sociaux-by-siren.js";
@@ -0,0 +1,27 @@
1
+ //
2
+
3
+ import { createApiEntrepriseOpenApiClient } from "#src/client";
4
+ import { coolTrackingParams } from "#testing";
5
+ import assert from "node:assert/strict";
6
+ import { mock, suite, test } from "node:test";
7
+ import { findBySirenFactory } from "./find-by-siren.js";
8
+
9
+ //
10
+
11
+ suite("findBySirenFactory", () => {
12
+ test("should return an establishment from a siren", async () => {
13
+ const fetch = mock.fn(() => {
14
+ return Promise.resolve(
15
+ new Response(JSON.stringify({ data: { siret: "🦄" } })),
16
+ );
17
+ });
18
+ const client = createApiEntrepriseOpenApiClient("SECRET_INSEE_TOKEN", {
19
+ fetch,
20
+ });
21
+ const findBySiren = findBySirenFactory(client, coolTrackingParams);
22
+
23
+ const establishment = await findBySiren("791088917");
24
+
25
+ assert.equal(establishment.siret, "🦄");
26
+ });
27
+ });
@@ -0,0 +1,38 @@
1
+ //
2
+
3
+ import type {
4
+ ApiEntrepriseOpenApiClient,
5
+ ApiEntrepriseTrackingParams,
6
+ } from "#src/client";
7
+ import { ApiEntrepriseError } from "#src/types";
8
+ import type { FetchOptions } from "openapi-fetch";
9
+
10
+ //
11
+
12
+ export function findBySirenFactory(
13
+ client: ApiEntrepriseOpenApiClient,
14
+ trackingParams: ApiEntrepriseTrackingParams,
15
+ optionsFn: () => FetchOptions<unknown> = () => ({}),
16
+ ) {
17
+ return async function findBySiren(siren: string) {
18
+ const { data, error } = await client.GET(
19
+ "/v3/insee/sirene/unites_legales/{siren}/siege_social",
20
+ {
21
+ ...optionsFn(),
22
+ params: {
23
+ path: {
24
+ siren,
25
+ },
26
+ query: trackingParams,
27
+ },
28
+ },
29
+ );
30
+
31
+ if (error) throw new ApiEntrepriseError(error);
32
+
33
+ const { data: establishment } = data;
34
+ return establishment;
35
+ };
36
+ }
37
+
38
+ export type FindBySirenHandler = ReturnType<typeof findBySirenFactory>;
@@ -0,0 +1,26 @@
1
+ //
2
+
3
+ import { createApiEntrepriseOpenApiClient } from "#src/client";
4
+ import { coolTrackingParams } from "#testing";
5
+ import { mock, suite, test } from "node:test";
6
+ import { findBySiretFactory } from "./find-by-siret.js";
7
+
8
+ //
9
+
10
+ suite(findBySiretFactory.name, () => {
11
+ test("should return an establishment from a siret", async (t) => {
12
+ const fetch = mock.fn(() => {
13
+ return Promise.resolve(
14
+ new Response(JSON.stringify({ data: { siret: "🦄" } })),
15
+ );
16
+ });
17
+ const client = createApiEntrepriseOpenApiClient("SECRET_INSEE_TOKEN", {
18
+ fetch,
19
+ });
20
+ const findBySiret = findBySiretFactory(client, coolTrackingParams);
21
+
22
+ const establishment = await findBySiret("20007184300060");
23
+
24
+ t.assert.equal(establishment.siret, "🦄");
25
+ });
26
+ });
@@ -0,0 +1,38 @@
1
+ //
2
+
3
+ import type {
4
+ ApiEntrepriseOpenApiClient,
5
+ ApiEntrepriseTrackingParams,
6
+ } from "#src/client";
7
+ import { ApiEntrepriseError } from "#src/types";
8
+ import type { FetchOptions } from "openapi-fetch";
9
+
10
+ //
11
+
12
+ export function findBySiretFactory(
13
+ client: ApiEntrepriseOpenApiClient,
14
+ trackingParams: ApiEntrepriseTrackingParams,
15
+ optionsFn: () => FetchOptions<unknown> = () => ({}),
16
+ ) {
17
+ return async function findBySiret(siret: string) {
18
+ const { data, error } = await client.GET(
19
+ "/v3/insee/sirene/etablissements/{siret}",
20
+ {
21
+ ...optionsFn(),
22
+ params: {
23
+ path: {
24
+ siret,
25
+ },
26
+ query: trackingParams,
27
+ },
28
+ },
29
+ );
30
+
31
+ if (error) throw new ApiEntrepriseError(error);
32
+
33
+ const { data: establishment } = data;
34
+ return establishment;
35
+ };
36
+ }
37
+
38
+ export type FindBySiretHandler = ReturnType<typeof findBySiretFactory>;
@@ -0,0 +1,4 @@
1
+ //
2
+
3
+ export * from "./find-by-siren.js";
4
+ export * from "./find-by-siret.js";
@@ -0,0 +1,43 @@
1
+ //
2
+
3
+ import type { paths } from "#openapi";
4
+ import createClient, { type ClientOptions } from "openapi-fetch";
5
+
6
+ //
7
+
8
+ /**
9
+ * @see https://entreprise.api.gouv.fr/developpeurs#renseigner-les-param%C3%A8tres-dappel-et-de-tra%C3%A7abilit%C3%A9
10
+ */
11
+ export interface ApiEntrepriseTrackingParams {
12
+ recipient: string;
13
+ context: string;
14
+ object: string;
15
+ }
16
+
17
+ //
18
+
19
+ /**
20
+ * Create an Entreprise openapi-fetch client
21
+ * @see https://openapi-ts.dev/openapi-fetch/api#createclient
22
+ * @param token - the https://entreprise.api.gouv.fr token
23
+ * @param options - the client options
24
+ * @note `options.baseUrl` is "https://entreprise.api.gouv.fr/" by default
25
+ * @returns the client
26
+ */
27
+ export function createApiEntrepriseOpenApiClient(
28
+ token: string,
29
+ options: ClientOptions = {},
30
+ ) {
31
+ return createClient<paths>({
32
+ baseUrl: options.baseUrl ?? "https://entreprise.api.gouv.fr/",
33
+ headers: {
34
+ Authorization: `Bearer ${token}`,
35
+ ...options.headers,
36
+ },
37
+ ...options,
38
+ });
39
+ }
40
+
41
+ export type ApiEntrepriseOpenApiClient = ReturnType<
42
+ typeof createApiEntrepriseOpenApiClient
43
+ >;
@@ -0,0 +1,55 @@
1
+ //
2
+
3
+ import {
4
+ AppleEuropeInc,
5
+ CommunautéDeCommunes,
6
+ ExpertiseRurale,
7
+ MarneusCalgarFEntrepreneur,
8
+ MegevandSas,
9
+ NintendoOfEuropeSe,
10
+ OctoTechnology,
11
+ Papillon,
12
+ RogalDornEntrepreneur,
13
+ StihleFreres,
14
+ } from "#src/testing/seed/insee/siret";
15
+ import type { InseeAddressEstablishment } from "#src/types";
16
+ import assert from "node:assert/strict";
17
+ import { suite, test } from "node:test";
18
+ import { formatAddress } from "./adresse-establishment.js";
19
+
20
+ suite("formatAddress", { concurrency: true }, () => {
21
+ const cases: [InseeAddressEstablishment, string][] = [
22
+ [
23
+ AppleEuropeInc.adresse,
24
+ "100 west ten wilmington delawa, 99404, ETATS-UNIS",
25
+ ],
26
+ [
27
+ CommunautéDeCommunes.adresse,
28
+ "3 rue maison de vatimesnil, 27150 Etrepagny",
29
+ ],
30
+ [ExpertiseRurale.adresse, "le haut jumel, 62990 Beaurainville"],
31
+ [MarneusCalgarFEntrepreneur.adresse, "44049 Le croisic"],
32
+ [
33
+ Papillon.adresse,
34
+ "5-7, 5 rue du moulin aux moines, 72650 La chapelle-saint-aubin",
35
+ ],
36
+ [RogalDornEntrepreneur.adresse, "06155 Vallauris"],
37
+ [
38
+ MegevandSas.adresse,
39
+ "Za immeuble l'octogone, 226 rue du jura, 74160 Neydens",
40
+ ],
41
+ [
42
+ NintendoOfEuropeSe.adresse,
43
+ "goldsteinstrasse 235, 60528 frankfurt am main, 99109, ALLEMAGNE",
44
+ ],
45
+ [OctoTechnology.adresse, "34 avenue de l'opera, 75002 Paris"],
46
+ [StihleFreres.adresse, "7 rue de la fecht, 68230 Wihr-au-val"],
47
+ ];
48
+
49
+ for (const [inseeAddress, address] of cases) {
50
+ test(address, () => {
51
+ const formattedAddress = formatAddress(inseeAddress);
52
+ assert.equal(formattedAddress, address);
53
+ });
54
+ }
55
+ });
@@ -0,0 +1,67 @@
1
+ //
2
+
3
+ import type { InseeAddressEstablishment } from "#src/types";
4
+ import { capitalize } from "lodash-es";
5
+
6
+ //
7
+
8
+ const emptyInseeAddressEstablishment = {
9
+ complement_adresse: null,
10
+ distribution_speciale: null,
11
+ indice_repetition_voie: null,
12
+ libelle_voie: null,
13
+ numero_voie: null,
14
+ type_voie: null,
15
+ code_postal: null,
16
+ };
17
+
18
+ export function formatAddress(inseeAddress: InseeAddressEstablishment) {
19
+ const isPartiallyNonDiffusible =
20
+ inseeAddress.status_diffusion === "partiellement_diffusible";
21
+
22
+ const {
23
+ complement_adresse,
24
+ distribution_speciale,
25
+ indice_repetition_voie,
26
+ libelle_voie,
27
+ numero_voie,
28
+ type_voie,
29
+ } = isPartiallyNonDiffusible ? emptyInseeAddressEstablishment : inseeAddress;
30
+ const {
31
+ libelle_commune,
32
+ code_cedex,
33
+ libelle_cedex,
34
+ libelle_commune_etranger,
35
+ code_pays_etranger,
36
+ libelle_pays_etranger,
37
+ } = inseeAddress;
38
+ const code_postal = isPartiallyNonDiffusible
39
+ ? inseeAddress.code_commune
40
+ : (inseeAddress.code_postal ?? code_cedex);
41
+ return [
42
+ wrapWord(complement_adresse, ", ", true),
43
+ wrapWord(numero_voie),
44
+ wrapWord(indice_repetition_voie),
45
+ wrapWord(type_voie),
46
+ wrapWord(libelle_voie, ", "),
47
+ wrapWord(distribution_speciale, ", "),
48
+ wrapWord(code_postal),
49
+ wrapWord(
50
+ libelle_commune ?? libelle_cedex ?? libelle_commune_etranger,
51
+ code_pays_etranger ? ", " : "",
52
+ true,
53
+ ),
54
+ wrapWord(code_pays_etranger, ", "),
55
+ libelle_pays_etranger,
56
+ ].join("");
57
+ }
58
+
59
+ const wrapWord = (word: string | null, punct = " ", caps = false) => {
60
+ if (!word) {
61
+ return "";
62
+ }
63
+ if (caps) {
64
+ return capitalize(word) + punct;
65
+ }
66
+ return word.toString().toLowerCase() + punct;
67
+ };
@@ -0,0 +1,6 @@
1
+ //
2
+
3
+ export * from "./adresse-establishment.js";
4
+ export * from "./libelle-from-code-effectif.js";
5
+ export * from "./main-activity.js";
6
+ export * from "./nom-complet.js";
@@ -0,0 +1,23 @@
1
+ //
2
+
3
+ import assert from "node:assert/strict";
4
+ import { suite, test } from "node:test";
5
+ import { libelleFromCodeEffectif } from "./libelle-from-code-effectif.js";
6
+
7
+ //
8
+
9
+ suite(libelleFromCodeEffectif.name, { concurrency: true }, () => {
10
+ const cases: [Parameters<typeof libelleFromCodeEffectif>, string][] = [
11
+ [[null, null], ""],
12
+ [["1 ou 2 salariés", null], "1 ou 2 salariés"],
13
+ [[null, "2222"], ""],
14
+ [["1 ou 2 salariés", "2222"], "1 ou 2 salariés, en 2222"],
15
+ ];
16
+
17
+ for (const [parameters, expected] of cases) {
18
+ test(`[${parameters}] = ${expected}`, () => {
19
+ const actual = libelleFromCodeEffectif(...parameters);
20
+ assert.equal(actual, expected);
21
+ });
22
+ }
23
+ });
@@ -0,0 +1,16 @@
1
+ //
2
+
3
+ export const libelleFromCodeEffectif = (
4
+ libelle: string | null,
5
+ anneeEffectif: string | null,
6
+ ) => {
7
+ if (libelle && anneeEffectif) {
8
+ return `${libelle}, en ${anneeEffectif}`;
9
+ }
10
+
11
+ if (libelle) {
12
+ return libelle;
13
+ }
14
+
15
+ return "";
16
+ };
@@ -0,0 +1,33 @@
1
+ //
2
+
3
+ import assert from "node:assert/strict";
4
+ import { suite, test } from "node:test";
5
+ import { formatMainActivity } from "./main-activity.js";
6
+
7
+ //
8
+
9
+ suite(formatMainActivity.name, { concurrency: true }, () => {
10
+ const cases: [Parameters<typeof formatMainActivity>, string][] = [
11
+ [
12
+ [
13
+ {
14
+ code: "01.13Z",
15
+ nomenclature: "NAFRev2",
16
+ libelle: "Culture de légumes, de melons, de racines et de tubercules",
17
+ },
18
+ ],
19
+ "01.13Z - Culture de légumes, de melons, de racines et de tubercules",
20
+ ],
21
+ [
22
+ [{ code: null, libelle: "▪︎ ▪︎ ▪︎", nomenclature: null }],
23
+ "Activité inconnue",
24
+ ],
25
+ ];
26
+
27
+ for (const [parameters, expected] of cases) {
28
+ test(`${expected}`, () => {
29
+ const actual = formatMainActivity(...parameters);
30
+ assert.equal(actual, expected);
31
+ });
32
+ }
33
+ });
@@ -0,0 +1,10 @@
1
+ //
2
+
3
+ import type { InseeMainActivityEstablishment } from "#src/types";
4
+
5
+ //
6
+
7
+ export function formatMainActivity(activity: InseeMainActivityEstablishment) {
8
+ if (!activity.code) return "Activité inconnue";
9
+ return `${activity.code} - ${activity.libelle}`;
10
+ }