@nexgen-os/ban 0.0.0-stage → 0.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/LICENSE +21 -0
- package/README.md +14 -2
- package/dist/index.d.ts +6 -0
- package/dist/index.js +58 -0
- package/package.json +35 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nexgen OS contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@nexgen-os/ban` — the French national address base
|
|
2
|
+
|
|
3
|
+
The Base Adresse Nationale of France: search as you type and reverse geocoding with house-number precision, the ISO 3166-2 subdivision of the department as region (`FR-34`; Paris is `FR-75C`). Source `ban`. MIT; the data is under the Licence Ouverte 2.0, no key. The country pack `fr` names the register as a source; the code lives here.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { ban } from '@nexgen-os/ban';
|
|
7
|
+
|
|
8
|
+
const geocoder = ban();
|
|
9
|
+
const [place] = await geocoder.search('20 avenue de Ségur, Paris');
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
The place is the standard shape of `@nexgen-os/core` (address, WGS 84 point,
|
|
13
|
+
precision, source); `placeFields(place)` gives the place columns of `participants` it fills.
|
|
14
|
+
Decision [0009](../../../docs/decisions/0009-what-applies-follows-the-region.md).
|
|
2
15
|
|
|
3
|
-
This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// Base Adresse Nationale — https://adresse.data.gouv.fr, the French address
|
|
2
|
+
// register, as a Geocoder of the core's shape. Open (Licence Ouverte 2.0),
|
|
3
|
+
// no key, house-number precision, search as you type. The `fr` pack names
|
|
4
|
+
// the register as a source (`ban`); the adapter lives here with the other
|
|
5
|
+
// geocoders, as code never belongs in a pack.
|
|
6
|
+
export const SOURCE_CODE = 'ban';
|
|
7
|
+
// Paris is one territorial collectivity, `FR-75C` in ISO 3166-2, where its
|
|
8
|
+
// context reads the department code `75`.
|
|
9
|
+
const SUBDIVISION = { '75': '75C' };
|
|
10
|
+
const PRECISION = {
|
|
11
|
+
housenumber: 'rooftop',
|
|
12
|
+
street: 'street',
|
|
13
|
+
locality: 'city',
|
|
14
|
+
municipality: 'city',
|
|
15
|
+
};
|
|
16
|
+
export function ban(options = {}) {
|
|
17
|
+
const base = (options.baseUrl ?? 'https://api-adresse.data.gouv.fr').replace(/\/+$/, '');
|
|
18
|
+
const doFetch = options.fetch ?? globalThis.fetch;
|
|
19
|
+
return {
|
|
20
|
+
source_code: SOURCE_CODE,
|
|
21
|
+
async search(text, search = {}) {
|
|
22
|
+
const params = new URLSearchParams({ q: text, limit: String(search.limit ?? 5), autocomplete: '1' });
|
|
23
|
+
if (search.near) {
|
|
24
|
+
params.set('lat', String(search.near.lat));
|
|
25
|
+
params.set('lon', String(search.near.lon));
|
|
26
|
+
}
|
|
27
|
+
const body = (await getJson(doFetch, `${base}/search/?${params}`));
|
|
28
|
+
return body.features.map(fromBan);
|
|
29
|
+
},
|
|
30
|
+
async reverse(lon, lat) {
|
|
31
|
+
const body = (await getJson(doFetch, `${base}/reverse/?lon=${lon}&lat=${lat}`));
|
|
32
|
+
return body.features[0] ? fromBan(body.features[0]) : null;
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function fromBan(f) {
|
|
37
|
+
const p = f.properties;
|
|
38
|
+
const street = [p.street ?? (p.type === 'street' ? p.name : undefined), p.housenumber].filter(Boolean).join(' ') || null;
|
|
39
|
+
// The context reads "<department code>, <department>, <region>": the department code is the ISO 3166-2 subdivision.
|
|
40
|
+
const department = p.context?.split(',')[0]?.trim();
|
|
41
|
+
const place = {
|
|
42
|
+
address: { address_line1: street, address_line2: null, postal_code: p.postcode ?? null, city: p.city ?? null, region: department ? `FR-${SUBDIVISION[department] ?? department}` : null, municipality_code: p.citycode ?? null, country: 'FR' },
|
|
43
|
+
lon: f.geometry.coordinates[0],
|
|
44
|
+
lat: f.geometry.coordinates[1],
|
|
45
|
+
precision: PRECISION[p.type] ?? 'city',
|
|
46
|
+
source_code: SOURCE_CODE,
|
|
47
|
+
label: p.label,
|
|
48
|
+
};
|
|
49
|
+
if (p.id)
|
|
50
|
+
place.identifier = { scheme: 'ban_address', value: p.id };
|
|
51
|
+
return place;
|
|
52
|
+
}
|
|
53
|
+
async function getJson(doFetch, url) {
|
|
54
|
+
const response = await doFetch(url, { headers: { Accept: 'application/json' } });
|
|
55
|
+
if (!response.ok)
|
|
56
|
+
throw new Error(`geocoder_unavailable: ${response.status} from ${url}`);
|
|
57
|
+
return response.json();
|
|
58
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nexgen-os/ban",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "The French national address base (BAN) as a Nexgen OS geocoder.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/nexgen-os/nexgen-os.git",
|
|
9
|
+
"directory": "packages/connectors/ban"
|
|
10
|
+
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=20"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"README.md",
|
|
21
|
+
"LICENSE"
|
|
22
|
+
],
|
|
23
|
+
"main": "./dist/index.js",
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"import": "./dist/index.js"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsc -p tsconfig.build.json"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@nexgen-os/core": "^0.4.0"
|
|
36
|
+
}
|
|
37
|
+
}
|