@dk-address/client 0.0.0-stage → 0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Dyrhoi
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,9 @@
1
- # Temporary Holding Version
1
+ # @dk-address/client
2
2
 
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.
3
+ A typed client for [KDS Adressevælger](https://confluence.kds.dk/spaces/ADV/pages/234782998), the Danish address search that replaces DAWA's autocomplete. It wraps the search and lookup endpoints in English names and types, and uses KDS's shared token unless you pass your own.
4
+
5
+ ```sh
6
+ npm i @dk-address/client
7
+ ```
8
+
9
+ Read the [Client reference](https://dk-address.dyrhoi.com/docs/reference/client) for every method and option.
@@ -0,0 +1,43 @@
1
+ import type { AccessAddress, Address, SearchKind, Street, Suggestion } from "./types.ts";
2
+ /** KDS asks everyone to use this token until user management launches (expected around 2027). */
3
+ export declare const DEFAULT_TOKEN = "adressevaelger123";
4
+ export declare const DEFAULT_BASE_URL = "https://adressevaelger.dk";
5
+ /** KDS caps `maksimum` at 200 and defaults to 100. */
6
+ export declare const MAX_LIMIT = 200;
7
+ export interface ClientOptions {
8
+ /** At least 10 characters. Defaults to KDS's shared token. */
9
+ token?: string;
10
+ baseUrl?: string;
11
+ /** Custom fetch, e.g. for tests or a proxy. Defaults to `globalThis.fetch`. */
12
+ fetch?: typeof fetch;
13
+ }
14
+ export interface RequestOptions {
15
+ signal?: AbortSignal;
16
+ }
17
+ export interface SearchOptions extends RequestOptions {
18
+ /** Defaults to `"address"`. */
19
+ kind?: SearchKind;
20
+ /** 1 to 200. KDS defaults to 100. */
21
+ limit?: number;
22
+ /** Limit results to these municipalities, e.g. `["0101", "0147"]`. */
23
+ municipalityCodes?: readonly (string | number)[];
24
+ /** Include provisional (foreløbige) addresses. */
25
+ includeProvisional?: boolean;
26
+ }
27
+ export interface AdressevaelgerClient {
28
+ /** Free-text phonetic search. Returns `[]` without a request when the cleaned text is empty. */
29
+ search(text: string, options?: SearchOptions): Promise<Suggestion[]>;
30
+ /** `null` when KDS has no address with this id. */
31
+ getAddress(id: string, options?: RequestOptions): Promise<Address | null>;
32
+ /** Results follow the order of `ids`. Unknown ids are left out. */
33
+ getAddresses(ids: readonly string[], options?: RequestOptions): Promise<Address[]>;
34
+ getAccessAddress(id: string, options?: RequestOptions): Promise<AccessAddress | null>;
35
+ getAccessAddresses(ids: readonly string[], options?: RequestOptions): Promise<AccessAddress[]>;
36
+ /** Every address (floor/door unit) of one access address. */
37
+ getAccessAddressUnits(id: string, options?: RequestOptions): Promise<Address[]>;
38
+ /** A road within one postal area. Uses an endpoint KDS does not document. */
39
+ getStreet(id: string, options?: RequestOptions): Promise<Street | null>;
40
+ /** Every access address on a road within one postal area. Uses an endpoint KDS does not document. */
41
+ getStreetAccessAddresses(id: string, options?: RequestOptions): Promise<AccessAddress[]>;
42
+ }
43
+ export declare function createClient(options?: ClientOptions): AdressevaelgerClient;
package/dist/client.js ADDED
@@ -0,0 +1,109 @@
1
+ import { AdressevaelgerError } from "./errors.js";
2
+ import { normalizeAccessAddress, normalizeAddress, normalizeStreet, normalizeSuggestion, } from "./normalize.js";
3
+ import { normalizeMunicipalityCode, sanitizeQuery } from "./query.js";
4
+ /** KDS asks everyone to use this token until user management launches (expected around 2027). */
5
+ export const DEFAULT_TOKEN = "adressevaelger123";
6
+ export const DEFAULT_BASE_URL = "https://adressevaelger.dk";
7
+ /** KDS caps `maksimum` at 200 and defaults to 100. */
8
+ export const MAX_LIMIT = 200;
9
+ export function createClient(options = {}) {
10
+ const token = options.token ?? DEFAULT_TOKEN;
11
+ const baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
12
+ const fetchImpl = options.fetch ?? ((input, init) => globalThis.fetch(input, init));
13
+ async function request(path, query, signal) {
14
+ const withToken = [...query, ["token", token]];
15
+ const params = withToken.map(([key, value]) => `${key}=${encodeURIComponent(value)}`).join("&");
16
+ const url = `${baseUrl}/${path}?${params}`;
17
+ const response = await fetchImpl(url, { signal, headers: { accept: "application/json" } });
18
+ if (response.status === 404)
19
+ return null;
20
+ const text = await response.text();
21
+ if (!response.ok) {
22
+ throw new AdressevaelgerError(text.trim() || response.statusText || `HTTP ${response.status}`, {
23
+ status: response.status,
24
+ url,
25
+ });
26
+ }
27
+ let body;
28
+ try {
29
+ body = JSON.parse(text);
30
+ }
31
+ catch {
32
+ throw new AdressevaelgerError(`Expected JSON from KDS, got: ${text.slice(0, 200)}`, {
33
+ status: response.status,
34
+ url,
35
+ });
36
+ }
37
+ const status = body.status;
38
+ if (status === "fejl") {
39
+ const description = body.beskrivelse;
40
+ throw new AdressevaelgerError(typeof description === "string" ? description : "KDS returned an error", {
41
+ status: response.status,
42
+ url,
43
+ });
44
+ }
45
+ return body;
46
+ }
47
+ function orderByIds(items, ids) {
48
+ const byId = new Map(items.map((item) => [item.id, item]));
49
+ return ids.flatMap((id) => byId.get(id) ?? []);
50
+ }
51
+ return {
52
+ async search(text, searchOptions = {}) {
53
+ const tekst = sanitizeQuery(text);
54
+ if (!tekst)
55
+ return [];
56
+ const query = [["tekst", tekst]];
57
+ if (searchOptions.limit !== undefined) {
58
+ const { limit } = searchOptions;
59
+ if (!Number.isInteger(limit) || limit < 1 || limit > MAX_LIMIT) {
60
+ throw new RangeError(`limit must be an integer from 1 to ${MAX_LIMIT}, got ${limit}`);
61
+ }
62
+ query.push(["maksimum", String(limit)]);
63
+ }
64
+ if (searchOptions.municipalityCodes?.length) {
65
+ query.push([
66
+ "kommunekode",
67
+ searchOptions.municipalityCodes.map(normalizeMunicipalityCode).join(","),
68
+ ]);
69
+ }
70
+ if (searchOptions.includeProvisional)
71
+ query.push(["medtagforeloebige", "true"]);
72
+ const collection = (searchOptions.kind ?? "address") === "address" ? "adresser" : "husnumre";
73
+ const body = await request(`${collection}/soeg`, query, searchOptions.signal);
74
+ return (body?.fund ?? []).flatMap((hit) => normalizeSuggestion(hit) ?? []);
75
+ },
76
+ async getAddress(id, requestOptions = {}) {
77
+ const body = await request(`adresser/${encodeURIComponent(id)}`, [], requestOptions.signal);
78
+ return body ? normalizeAddress(body.adresse) : null;
79
+ },
80
+ async getAddresses(ids, requestOptions = {}) {
81
+ if (ids.length === 0)
82
+ return [];
83
+ const body = await request("adresser", [["id_lokalids", ids.join(",")]], requestOptions.signal);
84
+ return orderByIds((body?.adresser ?? []).map(normalizeAddress), ids);
85
+ },
86
+ async getAccessAddress(id, requestOptions = {}) {
87
+ const body = await request(`husnumre/${encodeURIComponent(id)}`, [], requestOptions.signal);
88
+ return body ? normalizeAccessAddress(body.husnummer) : null;
89
+ },
90
+ async getAccessAddresses(ids, requestOptions = {}) {
91
+ if (ids.length === 0)
92
+ return [];
93
+ const body = await request("husnumre", [["id_lokalids", ids.join(",")]], requestOptions.signal);
94
+ return orderByIds((body?.husnumre ?? []).map(normalizeAccessAddress), ids);
95
+ },
96
+ async getAccessAddressUnits(id, requestOptions = {}) {
97
+ const body = await request(`husnumre/${encodeURIComponent(id)}/adresser`, [], requestOptions.signal);
98
+ return (body?.adresser ?? []).map(normalizeAddress);
99
+ },
100
+ async getStreet(id, requestOptions = {}) {
101
+ const body = await request(`navngivenvejpostnumre/${encodeURIComponent(id)}`, [], requestOptions.signal);
102
+ return body ? normalizeStreet(body.navngivenvejpostnummer) : null;
103
+ },
104
+ async getStreetAccessAddresses(id, requestOptions = {}) {
105
+ const body = await request(`navngivenvejpostnumre/${encodeURIComponent(id)}/husnumre`, [], requestOptions.signal);
106
+ return (body?.husnumre ?? []).map(normalizeAccessAddress);
107
+ },
108
+ };
109
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * A failed request to KDS Adressevælger. KDS answers errors with plain Danish text
3
+ * (e.g. `maksimum skal være <= 200 (500)`), which is kept as `message`.
4
+ */
5
+ export declare class AdressevaelgerError extends Error {
6
+ readonly name = "AdressevaelgerError";
7
+ /** HTTP status. `200` when KDS answered `{ status: "fejl" }`. */
8
+ readonly status: number;
9
+ /** Request URL with the token redacted. */
10
+ readonly url: string;
11
+ constructor(message: string, options: {
12
+ status: number;
13
+ url: string;
14
+ });
15
+ }
16
+ export declare function redactToken(url: string): string;
17
+ export declare function isAbortError(error: unknown): boolean;
package/dist/errors.js ADDED
@@ -0,0 +1,22 @@
1
+ /**
2
+ * A failed request to KDS Adressevælger. KDS answers errors with plain Danish text
3
+ * (e.g. `maksimum skal være <= 200 (500)`), which is kept as `message`.
4
+ */
5
+ export class AdressevaelgerError extends Error {
6
+ name = "AdressevaelgerError";
7
+ /** HTTP status. `200` when KDS answered `{ status: "fejl" }`. */
8
+ status;
9
+ /** Request URL with the token redacted. */
10
+ url;
11
+ constructor(message, options) {
12
+ super(message);
13
+ this.status = options.status;
14
+ this.url = redactToken(options.url);
15
+ }
16
+ }
17
+ export function redactToken(url) {
18
+ return url.replace(/([?&]token=)[^&]*/i, "$1***");
19
+ }
20
+ export function isAbortError(error) {
21
+ return error instanceof Error && error.name === "AbortError";
22
+ }
@@ -0,0 +1,6 @@
1
+ export { createClient, DEFAULT_BASE_URL, DEFAULT_TOKEN, MAX_LIMIT, type AdressevaelgerClient, type ClientOptions, type RequestOptions, type SearchOptions, } from "./client.ts";
2
+ export { AdressevaelgerError, isAbortError } from "./errors.ts";
3
+ export { normalizeAccessAddress, normalizeAddress, normalizeStreet, normalizeSuggestion, suggestionKey, } from "./normalize.ts";
4
+ export { MAX_QUERY_LENGTH, normalizeMunicipalityCode, sanitizeQuery } from "./query.ts";
5
+ export type * from "./raw.ts";
6
+ export type * from "./types.ts";
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export { createClient, DEFAULT_BASE_URL, DEFAULT_TOKEN, MAX_LIMIT, } from "./client.js";
2
+ export { AdressevaelgerError, isAbortError } from "./errors.js";
3
+ export { normalizeAccessAddress, normalizeAddress, normalizeStreet, normalizeSuggestion, suggestionKey, } from "./normalize.js";
4
+ export { MAX_QUERY_LENGTH, normalizeMunicipalityCode, sanitizeQuery } from "./query.js";
@@ -0,0 +1,9 @@
1
+ import type { RawAdresse, RawHusnummer, RawNavngivenvejpostnummer, RawSearchHit } from "./raw.ts";
2
+ import type { AccessAddress, Address, Street, Suggestion } from "./types.ts";
3
+ /** Normalize one search hit. Returns `null` for hit types this library does not know. */
4
+ export declare function normalizeSuggestion(hit: RawSearchHit): Suggestion | null;
5
+ export declare function normalizeAccessAddress(raw: RawHusnummer): AccessAddress;
6
+ export declare function normalizeAddress(raw: RawAdresse): Address;
7
+ export declare function normalizeStreet(raw: RawNavngivenvejpostnummer): Street;
8
+ /** A stable key for rendering lists. `streetName` and `streetNameNumber` suggestions have no id. */
9
+ export declare function suggestionKey(suggestion: Suggestion): string;
@@ -0,0 +1,105 @@
1
+ /** Normalize one search hit. Returns `null` for hit types this library does not know. */
2
+ export function normalizeSuggestion(hit) {
3
+ const streetName = hit.vejnavn ?? hit.vejNavn ?? "";
4
+ const houseNumber = hit.husnummer ?? hit.husNummer ?? "";
5
+ switch (hit.type) {
6
+ case "vejnavn":
7
+ return { type: "streetName", label: hit.titel, streetName: streetName || hit.titel };
8
+ case "vejnavnhusnummer":
9
+ return { type: "streetNameNumber", label: hit.titel, streetName, houseNumber };
10
+ case "navngivenvejpostnummer":
11
+ if (!hit.id)
12
+ return null;
13
+ return {
14
+ type: "street",
15
+ id: hit.id,
16
+ label: hit.titel,
17
+ streetName,
18
+ postalCode: hit.postnr ?? "",
19
+ postalDistrict: hit.postdistrikt ?? "",
20
+ accessAddressCount: hit.antal_husnumre ?? 0,
21
+ };
22
+ case "husnummer":
23
+ if (!hit.id)
24
+ return null;
25
+ return { type: "accessAddress", id: hit.id, label: hit.titel, streetName, houseNumber };
26
+ case "adresse":
27
+ if (!hit.id)
28
+ return null;
29
+ return {
30
+ type: "address",
31
+ id: hit.id,
32
+ label: hit.titel,
33
+ accessAddressId: hit.husnummerId ?? "",
34
+ };
35
+ default:
36
+ return null;
37
+ }
38
+ }
39
+ function validity(raw) {
40
+ return {
41
+ validFrom: raw.virkningfra,
42
+ validTo: raw.virkningtil,
43
+ registeredFrom: raw.registreringfra,
44
+ registeredTo: raw.registreringtil,
45
+ };
46
+ }
47
+ export function normalizeAccessAddress(raw) {
48
+ const point = raw.adgangspunkt?.koordinater ?? null;
49
+ return {
50
+ type: "accessAddress",
51
+ id: raw.id_lokalid,
52
+ label: raw.adgangsadressebetegnelse,
53
+ houseNumber: raw.husnummertekst,
54
+ streetName: raw.vejnavn,
55
+ statusCode: raw.status,
56
+ position: point ? { x: point.x, y: point.y, crs: "EPSG:25832" } : null,
57
+ postalCode: {
58
+ id: raw.postnummer.id_lokalid,
59
+ code: raw.postnummer.postnr,
60
+ name: raw.postnummer.navn,
61
+ },
62
+ municipalityCode: raw.navngivenvejkommunedel?.kommune ?? null,
63
+ roadCode: raw.navngivenvejkommunedel?.vejkode ?? null,
64
+ streetId: raw.navngivenvejpostnummer?.id_lokalid ?? null,
65
+ namedRoadId: raw.navngivenvej?.id_lokalid ?? null,
66
+ supplementaryTownName: raw.supplerendebynavn?.navn ?? null,
67
+ ...validity(raw),
68
+ raw,
69
+ };
70
+ }
71
+ export function normalizeAddress(raw) {
72
+ return {
73
+ type: "address",
74
+ id: raw.id_lokalid,
75
+ label: raw.adressebetegnelse,
76
+ floor: raw.etagebetegnelse,
77
+ door: raw.doerbetegnelse,
78
+ statusCode: raw.status,
79
+ accessAddress: normalizeAccessAddress(raw.husnummer),
80
+ ...validity(raw),
81
+ raw,
82
+ };
83
+ }
84
+ export function normalizeStreet(raw) {
85
+ return {
86
+ type: "street",
87
+ id: raw.id,
88
+ label: raw.titel,
89
+ streetName: raw.vejnavn,
90
+ postalCode: raw.postnr,
91
+ postalDistrict: raw.postdistrikt,
92
+ postalCodeId: raw.postnummer,
93
+ accessAddressCount: raw.antal_husnumre,
94
+ geometry: raw.geometri
95
+ ? { type: "MultiLineString", coordinates: raw.geometri.coordinates, crs: "EPSG:25832" }
96
+ : null,
97
+ raw,
98
+ };
99
+ }
100
+ /** A stable key for rendering lists. `streetName` and `streetNameNumber` suggestions have no id. */
101
+ export function suggestionKey(suggestion) {
102
+ return "id" in suggestion
103
+ ? `${suggestion.type}:${suggestion.id}`
104
+ : `${suggestion.type}:${suggestion.label}`;
105
+ }
@@ -0,0 +1,9 @@
1
+ /** KDS rejects `tekst` longer than this with a 400. */
2
+ export declare const MAX_QUERY_LENGTH = 73;
3
+ /**
4
+ * Clean free text before sending it as `tekst`: replace characters KDS chokes on with
5
+ * spaces, collapse whitespace and cap the length. Returns `""` when nothing is left.
6
+ */
7
+ export declare function sanitizeQuery(text: string): string;
8
+ /** KDS wants 4-digit municipality codes. Accepts `"101"` or `101` and pads to `"0101"`. */
9
+ export declare function normalizeMunicipalityCode(code: string | number): string;
package/dist/query.js ADDED
@@ -0,0 +1,25 @@
1
+ /** KDS rejects `tekst` longer than this with a 400. */
2
+ export const MAX_QUERY_LENGTH = 73;
3
+ // Anything other than letters, digits, whitespace and . , ' - changes results:
4
+ // "&" returns nothing, "%" returns fewer hits, and HTML returns nothing.
5
+ const DISALLOWED = /[^\p{L}\p{N}\s.,'-]/gu;
6
+ /**
7
+ * Clean free text before sending it as `tekst`: replace characters KDS chokes on with
8
+ * spaces, collapse whitespace and cap the length. Returns `""` when nothing is left.
9
+ */
10
+ export function sanitizeQuery(text) {
11
+ return text
12
+ .replace(DISALLOWED, " ")
13
+ .replace(/\s+/g, " ")
14
+ .trim()
15
+ .slice(0, MAX_QUERY_LENGTH)
16
+ .trimEnd();
17
+ }
18
+ /** KDS wants 4-digit municipality codes. Accepts `"101"` or `101` and pads to `"0101"`. */
19
+ export function normalizeMunicipalityCode(code) {
20
+ const text = String(code).trim();
21
+ if (!/^\d{1,4}$/.test(text)) {
22
+ throw new RangeError(`Municipality code must be 1 to 4 digits, got "${text}"`);
23
+ }
24
+ return text.padStart(4, "0");
25
+ }
package/dist/raw.d.ts ADDED
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Response shapes as KDS Adressevælger returns them (Danish field names).
3
+ * These are what `raw` holds on the normalized types.
4
+ */
5
+ export type RawHitType = "vejnavn" | "vejnavnhusnummer" | "navngivenvejpostnummer" | "husnummer" | "adresse";
6
+ /** One search hit. Field casing differs by type: `vejnavn` and `vejnavnhusnummer` use camelCase and have no id. */
7
+ export interface RawSearchHit {
8
+ type: RawHitType | (string & {});
9
+ titel: string;
10
+ id?: string;
11
+ vejnavn?: string;
12
+ vejNavn?: string;
13
+ husnummer?: string;
14
+ husNummer?: string;
15
+ postnr?: string;
16
+ postdistrikt?: string;
17
+ antal_husnumre?: number;
18
+ husnummerId?: string;
19
+ }
20
+ export interface RawSearchResponse {
21
+ status: "ok" | "fejl" | (string & {});
22
+ beskrivelse: string;
23
+ fund: RawSearchHit[];
24
+ }
25
+ export interface RawValidity {
26
+ virkningfra: string | null;
27
+ virkningtil: string | null;
28
+ registreringfra: string | null;
29
+ registreringtil: string | null;
30
+ }
31
+ export interface RawPointGeometry {
32
+ type: "Point";
33
+ crs: {
34
+ type: "name";
35
+ properties: {
36
+ name: string;
37
+ };
38
+ };
39
+ coordinates: [number, number];
40
+ }
41
+ export interface RawMultiLineStringGeometry {
42
+ type: "MultiLineString";
43
+ crs: {
44
+ type: "name";
45
+ properties: {
46
+ name: string;
47
+ };
48
+ };
49
+ coordinates: [number, number][][];
50
+ }
51
+ export interface RawHusnummer extends RawValidity {
52
+ id_lokalid: string;
53
+ husnummertekst: string;
54
+ adgangsadressebetegnelse: string;
55
+ vejnavn: string;
56
+ status: string;
57
+ adgangspunkt: (RawValidity & {
58
+ id_lokalid: string;
59
+ status: string;
60
+ geometri: RawPointGeometry | null;
61
+ koordinater: {
62
+ x: number;
63
+ y: number;
64
+ } | null;
65
+ }) | null;
66
+ postnummer: RawValidity & {
67
+ id_lokalid: string;
68
+ navn: string;
69
+ postnr: string;
70
+ status: string;
71
+ };
72
+ navngivenvej: (RawValidity & {
73
+ id_lokalid: string;
74
+ vejnavn: string;
75
+ }) | null;
76
+ navngivenvejkommunedel: (RawValidity & {
77
+ id_lokalid: string;
78
+ kommune: string;
79
+ vejkode: string;
80
+ navngivenvej: string;
81
+ }) | null;
82
+ navngivenvejpostnummer: (RawValidity & {
83
+ id_lokalid: string;
84
+ }) | null;
85
+ supplerendebynavn: RawValidity & {
86
+ id_lokalid: string | null;
87
+ status: string | null;
88
+ supplerendebynavn: string | null;
89
+ navn: string | null;
90
+ };
91
+ }
92
+ export interface RawAdresse extends RawValidity {
93
+ id_lokalid: string;
94
+ adressebetegnelse: string;
95
+ etagebetegnelse: string | null;
96
+ doerbetegnelse: string | null;
97
+ status: string;
98
+ husnummer: RawHusnummer;
99
+ }
100
+ export interface RawNavngivenvejpostnummer {
101
+ id: string;
102
+ type: "navngivenvejpostnummer";
103
+ titel: string;
104
+ vejnavn: string;
105
+ postnummer: string;
106
+ postnr: string;
107
+ postdistrikt: string;
108
+ antal_husnumre: number;
109
+ geometri: RawMultiLineStringGeometry | null;
110
+ }
package/dist/raw.js ADDED
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Response shapes as KDS Adressevælger returns them (Danish field names).
3
+ * These are what `raw` holds on the normalized types.
4
+ */
@@ -0,0 +1,117 @@
1
+ import type { RawAdresse, RawHusnummer, RawNavngivenvejpostnummer } from "./raw.ts";
2
+ /**
3
+ * What to search for.
4
+ * - `address`: a full address down to floor and door (KDS "adresse", `/adresser`).
5
+ * - `accessAddress`: a house number / entrance (KDS "husnummer" or "adgangsadresse", `/husnumre`).
6
+ */
7
+ export type SearchKind = "address" | "accessAddress";
8
+ /** A road name with no postal area yet (KDS `vejnavn`). Has no id. */
9
+ export interface StreetNameSuggestion {
10
+ type: "streetName";
11
+ label: string;
12
+ streetName: string;
13
+ }
14
+ /** A road name plus house number across postal areas (KDS `vejnavnhusnummer`). Has no id. */
15
+ export interface StreetNameNumberSuggestion {
16
+ type: "streetNameNumber";
17
+ label: string;
18
+ streetName: string;
19
+ houseNumber: string;
20
+ }
21
+ /** A road within one postal area (KDS `navngivenvejpostnummer`). */
22
+ export interface StreetSuggestion {
23
+ type: "street";
24
+ id: string;
25
+ label: string;
26
+ streetName: string;
27
+ postalCode: string;
28
+ postalDistrict: string;
29
+ accessAddressCount: number;
30
+ }
31
+ /** A house number / entrance (KDS `husnummer`). Final when searching access addresses. */
32
+ export interface AccessAddressSuggestion {
33
+ type: "accessAddress";
34
+ id: string;
35
+ label: string;
36
+ streetName: string;
37
+ houseNumber: string;
38
+ }
39
+ /** A full address (KDS `adresse`). Final when searching addresses. */
40
+ export interface AddressSuggestion {
41
+ type: "address";
42
+ id: string;
43
+ label: string;
44
+ accessAddressId: string;
45
+ }
46
+ export type Suggestion = StreetNameSuggestion | StreetNameNumberSuggestion | StreetSuggestion | AccessAddressSuggestion | AddressSuggestion;
47
+ export type SuggestionType = Suggestion["type"];
48
+ /** Start and end of an object's current version, as registered in DAR. */
49
+ export interface Validity {
50
+ validFrom: string | null;
51
+ validTo: string | null;
52
+ registeredFrom: string | null;
53
+ registeredTo: string | null;
54
+ }
55
+ /** A point in ETRS89 / UTM zone 32N, the only coordinate system KDS returns. */
56
+ export interface Position {
57
+ x: number;
58
+ y: number;
59
+ crs: "EPSG:25832";
60
+ }
61
+ export interface PostalCode {
62
+ id: string;
63
+ code: string;
64
+ name: string;
65
+ }
66
+ export interface AccessAddress extends Validity {
67
+ type: "accessAddress";
68
+ id: string;
69
+ /** e.g. `Vesterbrogade 28, 1620 København V` */
70
+ label: string;
71
+ houseNumber: string;
72
+ streetName: string;
73
+ /** DAR status code, e.g. `"3"`. KDS does not document the values. */
74
+ statusCode: string;
75
+ position: Position | null;
76
+ postalCode: PostalCode;
77
+ /** 4-digit municipality code, e.g. `"0101"`. */
78
+ municipalityCode: string | null;
79
+ /** 4-digit road code within the municipality. */
80
+ roadCode: string | null;
81
+ /** Id of the road within its postal area. Matches `Street.id` and `StreetSuggestion.id`. */
82
+ streetId: string | null;
83
+ /** Id of the named road across postal areas (DAR NavngivenVej). */
84
+ namedRoadId: string | null;
85
+ supplementaryTownName: string | null;
86
+ raw: RawHusnummer;
87
+ }
88
+ export interface Address extends Validity {
89
+ type: "address";
90
+ id: string;
91
+ /** e.g. `Vesterbrogade 28, st. 1, 1620 København V` */
92
+ label: string;
93
+ /** e.g. `"st"`, `"1"`, `"kl"`. */
94
+ floor: string | null;
95
+ /** e.g. `"tv"`, `"th"`, `"1"`. */
96
+ door: string | null;
97
+ statusCode: string;
98
+ accessAddress: AccessAddress;
99
+ raw: RawAdresse;
100
+ }
101
+ export interface Street {
102
+ type: "street";
103
+ id: string;
104
+ /** e.g. `Vesterbrogade 1620 København V` */
105
+ label: string;
106
+ streetName: string;
107
+ postalCode: string;
108
+ postalDistrict: string;
109
+ postalCodeId: string;
110
+ accessAddressCount: number;
111
+ geometry: {
112
+ type: "MultiLineString";
113
+ coordinates: [number, number][][];
114
+ crs: "EPSG:25832";
115
+ } | null;
116
+ raw: RawNavngivenvejpostnummer;
117
+ }
package/dist/types.js ADDED
File without changes
package/package.json CHANGED
@@ -1,6 +1,52 @@
1
1
  {
2
2
  "name": "@dk-address/client",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Typed client for KDS Adressevælger, the Danish address search that replaces DAWA's autocomplete.",
5
+ "keywords": [
6
+ "address",
7
+ "adressevaelger",
8
+ "autocomplete",
9
+ "danish",
10
+ "dar",
11
+ "dawa",
12
+ "denmark",
13
+ "kds"
14
+ ],
15
+ "homepage": "https://dk-address.dyrhoi.com/docs",
16
+ "bugs": "https://github.com/Dyrhoi/dk-address/issues",
17
+ "license": "MIT",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/Dyrhoi/dk-address.git",
21
+ "directory": "packages/client"
22
+ },
23
+ "files": [
24
+ "dist"
25
+ ],
26
+ "type": "module",
27
+ "sideEffects": false,
28
+ "exports": {
29
+ ".": {
30
+ "types": "./dist/index.d.ts",
31
+ "default": "./dist/index.js"
32
+ }
33
+ },
34
+ "publishConfig": {
35
+ "access": "public"
36
+ },
37
+ "scripts": {
38
+ "build": "rm -rf dist && tsc -p tsconfig.build.json",
39
+ "lint": "bun lint --deny-warnings",
40
+ "typecheck": "bun check",
41
+ "test": "vitest run"
42
+ },
43
+ "devDependencies": {
44
+ "@repo/kds-fixtures": "0.0.0",
45
+ "@repo/oxlint-config": "0.0.0",
46
+ "@repo/typescript-config": "0.0.0",
47
+ "@types/bun": "1.4.5",
48
+ "vitest": "5.1.1"
49
+ },
50
+ "main": "./dist/index.js",
51
+ "types": "./dist/index.d.ts"
52
+ }