clearpostcode 0.0.0-stage → 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/LICENSE +16 -0
- package/README.md +207 -2
- package/dist/cjs/addresses.d.ts +28 -0
- package/dist/cjs/addresses.js +64 -0
- package/dist/cjs/browser.d.ts +39 -0
- package/dist/cjs/browser.js +54 -0
- package/dist/cjs/client.d.ts +146 -0
- package/dist/cjs/client.js +188 -0
- package/dist/cjs/errors.d.ts +73 -0
- package/dist/cjs/errors.js +111 -0
- package/dist/cjs/generated.d.ts +546 -0
- package/dist/cjs/generated.js +63 -0
- package/dist/cjs/http.d.ts +62 -0
- package/dist/cjs/http.js +173 -0
- package/dist/cjs/index.d.ts +24 -0
- package/dist/cjs/index.js +54 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/page.d.ts +20 -0
- package/dist/cjs/page.js +39 -0
- package/dist/cjs/version.d.ts +2 -0
- package/dist/cjs/version.js +24 -0
- package/dist/esm/addresses.d.ts +28 -0
- package/dist/esm/addresses.js +47 -0
- package/dist/esm/browser.d.ts +39 -0
- package/dist/esm/browser.js +33 -0
- package/dist/esm/client.d.ts +146 -0
- package/dist/esm/client.js +169 -0
- package/dist/esm/errors.d.ts +73 -0
- package/dist/esm/errors.js +92 -0
- package/dist/esm/generated.d.ts +546 -0
- package/dist/esm/generated.js +42 -0
- package/dist/esm/http.d.ts +62 -0
- package/dist/esm/http.js +161 -0
- package/dist/esm/index.d.ts +24 -0
- package/dist/esm/index.js +37 -0
- package/dist/esm/page.d.ts +20 -0
- package/dist/esm/page.js +17 -0
- package/dist/esm/version.d.ts +2 -0
- package/dist/esm/version.js +2 -0
- package/package.json +80 -4
|
@@ -0,0 +1,546 @@
|
|
|
1
|
+
export declare const BASE_URL = "https://api.clearpostcode.co.uk/v1";
|
|
2
|
+
export interface Named {
|
|
3
|
+
code: string;
|
|
4
|
+
name: string | null;
|
|
5
|
+
}
|
|
6
|
+
export interface PostcodeLocation {
|
|
7
|
+
latitude: number | null;
|
|
8
|
+
longitude: number | null;
|
|
9
|
+
easting: number | null;
|
|
10
|
+
northing: number | null;
|
|
11
|
+
positional_quality: number | null;
|
|
12
|
+
positional_quality_label: string | null;
|
|
13
|
+
}
|
|
14
|
+
export interface PostcodeRuralUrban {
|
|
15
|
+
code: string;
|
|
16
|
+
name: string | null;
|
|
17
|
+
urban: boolean | null;
|
|
18
|
+
}
|
|
19
|
+
export interface PostcodeDeprivation {
|
|
20
|
+
index: string;
|
|
21
|
+
rank: number;
|
|
22
|
+
of: number;
|
|
23
|
+
decile: number;
|
|
24
|
+
}
|
|
25
|
+
export interface Postcode {
|
|
26
|
+
/** Canonical form, e.g. "SW1A 1AA". */
|
|
27
|
+
postcode: string;
|
|
28
|
+
status: "live" | "terminated";
|
|
29
|
+
outcode?: string;
|
|
30
|
+
incode?: string;
|
|
31
|
+
sector?: string;
|
|
32
|
+
district?: string;
|
|
33
|
+
area?: string;
|
|
34
|
+
/** YYYY-MM */
|
|
35
|
+
introduced?: string | null;
|
|
36
|
+
/** YYYY-MM */
|
|
37
|
+
terminated?: string | null;
|
|
38
|
+
/** For a terminated postcode: the nearest live postcode. */
|
|
39
|
+
replaced_by?: string | null;
|
|
40
|
+
user_type?: "small" | "large";
|
|
41
|
+
location?: PostcodeLocation;
|
|
42
|
+
country?: Named | null;
|
|
43
|
+
region?: Named | null;
|
|
44
|
+
county?: Named | null;
|
|
45
|
+
county_electoral_division?: Named | null;
|
|
46
|
+
local_authority?: Named | null;
|
|
47
|
+
ward?: Named | null;
|
|
48
|
+
parish?: Named | null;
|
|
49
|
+
constituency?: Named | null;
|
|
50
|
+
police_force?: Named | null;
|
|
51
|
+
nhs_region?: Named | null;
|
|
52
|
+
icb?: Named | null;
|
|
53
|
+
sub_icb?: Named | null;
|
|
54
|
+
national_park?: Named | null;
|
|
55
|
+
built_up_area?: Named | null;
|
|
56
|
+
travel_to_work_area?: Named | null;
|
|
57
|
+
lsoa?: Named | null;
|
|
58
|
+
msoa?: Named | null;
|
|
59
|
+
output_area?: string | null;
|
|
60
|
+
rural_urban?: PostcodeRuralUrban | null;
|
|
61
|
+
area_classification?: string | null;
|
|
62
|
+
deprivation?: PostcodeDeprivation | null;
|
|
63
|
+
}
|
|
64
|
+
export interface Validation {
|
|
65
|
+
input: string;
|
|
66
|
+
postcode: string | null;
|
|
67
|
+
format_valid: boolean;
|
|
68
|
+
known: boolean | null;
|
|
69
|
+
status: "live" | "terminated" | null;
|
|
70
|
+
valid: boolean | null;
|
|
71
|
+
coverage: "covered" | "not_covered";
|
|
72
|
+
country: Named | null;
|
|
73
|
+
replaced_by: string | null;
|
|
74
|
+
}
|
|
75
|
+
export interface Near {
|
|
76
|
+
postcode: string;
|
|
77
|
+
distance_m: number;
|
|
78
|
+
latitude: number;
|
|
79
|
+
longitude: number;
|
|
80
|
+
}
|
|
81
|
+
export interface BulkItem {
|
|
82
|
+
query: string;
|
|
83
|
+
result: Postcode | null;
|
|
84
|
+
error?: "invalid_postcode" | "not_covered" | "postcode_not_found";
|
|
85
|
+
}
|
|
86
|
+
export interface ReverseItemQuery {
|
|
87
|
+
latitude: number | null;
|
|
88
|
+
longitude: number | null;
|
|
89
|
+
}
|
|
90
|
+
export interface ReverseItem {
|
|
91
|
+
query: ReverseItemQuery;
|
|
92
|
+
result: Near[];
|
|
93
|
+
error?: "bad_point";
|
|
94
|
+
}
|
|
95
|
+
export interface DistrictSuggestion {
|
|
96
|
+
type: "district";
|
|
97
|
+
outcode: string;
|
|
98
|
+
postcodes: number;
|
|
99
|
+
}
|
|
100
|
+
export interface PostcodeSuggestion {
|
|
101
|
+
type: "postcode";
|
|
102
|
+
postcode: string;
|
|
103
|
+
}
|
|
104
|
+
export interface DistanceEnd {
|
|
105
|
+
postcode: string;
|
|
106
|
+
latitude: number;
|
|
107
|
+
longitude: number;
|
|
108
|
+
easting: number;
|
|
109
|
+
northing: number;
|
|
110
|
+
positional_quality: number;
|
|
111
|
+
positional_quality_label: string;
|
|
112
|
+
}
|
|
113
|
+
export interface Distance {
|
|
114
|
+
from: DistanceEnd;
|
|
115
|
+
to: DistanceEnd;
|
|
116
|
+
km: number;
|
|
117
|
+
miles: number;
|
|
118
|
+
bearing_deg: number;
|
|
119
|
+
direction: string;
|
|
120
|
+
method: string;
|
|
121
|
+
}
|
|
122
|
+
export interface DistrictSectorsItem {
|
|
123
|
+
sector: string;
|
|
124
|
+
live: number;
|
|
125
|
+
terminated: number;
|
|
126
|
+
}
|
|
127
|
+
export interface Point {
|
|
128
|
+
latitude: number;
|
|
129
|
+
longitude: number;
|
|
130
|
+
}
|
|
131
|
+
export interface AreaShare {
|
|
132
|
+
code: string;
|
|
133
|
+
name: string | null;
|
|
134
|
+
postcodes: number;
|
|
135
|
+
share: number;
|
|
136
|
+
}
|
|
137
|
+
export interface DistrictDeprivation {
|
|
138
|
+
index: string;
|
|
139
|
+
deciles: number[];
|
|
140
|
+
}
|
|
141
|
+
export interface DistrictPlacesItem {
|
|
142
|
+
name: string;
|
|
143
|
+
type: string;
|
|
144
|
+
}
|
|
145
|
+
export interface DistrictNewestItem {
|
|
146
|
+
postcode: string;
|
|
147
|
+
introduced: string | null;
|
|
148
|
+
}
|
|
149
|
+
export interface District {
|
|
150
|
+
district: string;
|
|
151
|
+
area: string;
|
|
152
|
+
area_name: string | null;
|
|
153
|
+
live: number;
|
|
154
|
+
terminated: number;
|
|
155
|
+
large_user: number;
|
|
156
|
+
sectors: DistrictSectorsItem[];
|
|
157
|
+
centre: Point | null;
|
|
158
|
+
country: Named | null;
|
|
159
|
+
regions: AreaShare[];
|
|
160
|
+
counties: AreaShare[];
|
|
161
|
+
local_authorities: AreaShare[];
|
|
162
|
+
wards: AreaShare[];
|
|
163
|
+
constituencies: AreaShare[];
|
|
164
|
+
police_forces: AreaShare[];
|
|
165
|
+
icbs: AreaShare[];
|
|
166
|
+
national_parks: AreaShare[];
|
|
167
|
+
built_up_areas: AreaShare[];
|
|
168
|
+
parishes: AreaShare[];
|
|
169
|
+
urban_share: number | null;
|
|
170
|
+
deprivation: DistrictDeprivation | null;
|
|
171
|
+
places: DistrictPlacesItem[];
|
|
172
|
+
neighbours: string[];
|
|
173
|
+
newest: DistrictNewestItem[];
|
|
174
|
+
oldest_introduced: string | null;
|
|
175
|
+
}
|
|
176
|
+
export interface OutcodePostcode {
|
|
177
|
+
postcode: string;
|
|
178
|
+
latitude: number | null;
|
|
179
|
+
longitude: number | null;
|
|
180
|
+
}
|
|
181
|
+
export interface AreaCount {
|
|
182
|
+
code: string;
|
|
183
|
+
name: string | null;
|
|
184
|
+
postcodes: number;
|
|
185
|
+
}
|
|
186
|
+
export interface SectorPostcodesItem {
|
|
187
|
+
postcode: string;
|
|
188
|
+
latitude: number | null;
|
|
189
|
+
longitude: number | null;
|
|
190
|
+
user_type: "small" | "large";
|
|
191
|
+
}
|
|
192
|
+
export interface Sector {
|
|
193
|
+
sector: string;
|
|
194
|
+
district: string;
|
|
195
|
+
live: number;
|
|
196
|
+
centre: Point | null;
|
|
197
|
+
local_authorities: AreaCount[];
|
|
198
|
+
wards: AreaCount[];
|
|
199
|
+
constituencies: AreaCount[];
|
|
200
|
+
parishes: AreaCount[];
|
|
201
|
+
postcodes: SectorPostcodesItem[];
|
|
202
|
+
}
|
|
203
|
+
export interface AreaDistrictsItem {
|
|
204
|
+
district: string;
|
|
205
|
+
live: number;
|
|
206
|
+
terminated: number;
|
|
207
|
+
local_authority: string | null;
|
|
208
|
+
}
|
|
209
|
+
export interface Area {
|
|
210
|
+
area: string;
|
|
211
|
+
name: string | null;
|
|
212
|
+
live: number;
|
|
213
|
+
terminated: number;
|
|
214
|
+
districts: AreaDistrictsItem[];
|
|
215
|
+
}
|
|
216
|
+
export interface Place {
|
|
217
|
+
name: string;
|
|
218
|
+
alternative_name: string | null;
|
|
219
|
+
type: string;
|
|
220
|
+
district: string;
|
|
221
|
+
latitude: number;
|
|
222
|
+
longitude: number;
|
|
223
|
+
local_authority: string | null;
|
|
224
|
+
county: string | null;
|
|
225
|
+
}
|
|
226
|
+
export interface Usage {
|
|
227
|
+
plan: "free" | "starter" | "pro" | "business";
|
|
228
|
+
plan_name: string;
|
|
229
|
+
period_start: string;
|
|
230
|
+
resets: string;
|
|
231
|
+
allowance: number;
|
|
232
|
+
used: number;
|
|
233
|
+
remaining: number;
|
|
234
|
+
credits: number;
|
|
235
|
+
}
|
|
236
|
+
export interface AddressWelsh {
|
|
237
|
+
line_1: string;
|
|
238
|
+
line_2: string;
|
|
239
|
+
line_3: string;
|
|
240
|
+
post_town: string;
|
|
241
|
+
dependant_locality: string;
|
|
242
|
+
double_dependant_locality: string;
|
|
243
|
+
thoroughfare: string;
|
|
244
|
+
dependant_thoroughfare: string;
|
|
245
|
+
}
|
|
246
|
+
export interface Address {
|
|
247
|
+
/** Royal Mail's Unique Delivery Point Reference Number. */
|
|
248
|
+
udprn: string;
|
|
249
|
+
/** Multiple Residence unit number (null: not a unit). */
|
|
250
|
+
umprn: string | null;
|
|
251
|
+
/** Ordnance Survey's property id where held (null otherwise). */
|
|
252
|
+
uprn: string | null;
|
|
253
|
+
line_1: string;
|
|
254
|
+
line_2: string;
|
|
255
|
+
line_3: string;
|
|
256
|
+
post_town: string;
|
|
257
|
+
postcode: string;
|
|
258
|
+
organisation_name: string;
|
|
259
|
+
department_name: string;
|
|
260
|
+
sub_building_name: string;
|
|
261
|
+
building_name: string;
|
|
262
|
+
building_number: string;
|
|
263
|
+
dependant_thoroughfare: string;
|
|
264
|
+
thoroughfare: string;
|
|
265
|
+
double_dependant_locality: string;
|
|
266
|
+
dependant_locality: string;
|
|
267
|
+
po_box: string;
|
|
268
|
+
/** S: a small user postcode; L: a large user with its own postcode. */
|
|
269
|
+
postcode_type?: "S" | "L";
|
|
270
|
+
/** With the postcode, identifies the delivery point (1A to 9T). */
|
|
271
|
+
delivery_point_suffix?: string;
|
|
272
|
+
/** A small user organisation is at this address. */
|
|
273
|
+
su_organisation_indicator?: boolean;
|
|
274
|
+
/** Households behind this delivery point (more than 1: multiple occupancy). */
|
|
275
|
+
households?: number;
|
|
276
|
+
postal_county?: string;
|
|
277
|
+
traditional_county?: string;
|
|
278
|
+
administrative_county?: string;
|
|
279
|
+
welsh?: AddressWelsh | null;
|
|
280
|
+
}
|
|
281
|
+
export interface SuggestedAddress {
|
|
282
|
+
kind: "address";
|
|
283
|
+
/** Resolve with /addresses/retrieve/{id}. */
|
|
284
|
+
id: string;
|
|
285
|
+
/** The line to show the customer. */
|
|
286
|
+
suggestion: string;
|
|
287
|
+
}
|
|
288
|
+
export interface SuggestedContainer {
|
|
289
|
+
kind: "container";
|
|
290
|
+
/** Pass as container= to list what it holds. */
|
|
291
|
+
id: string;
|
|
292
|
+
suggestion: string;
|
|
293
|
+
type: "postcode" | "sector" | "street" | "building";
|
|
294
|
+
count: number;
|
|
295
|
+
}
|
|
296
|
+
export interface AddressMeta {
|
|
297
|
+
/** The Royal Mail PAF edition answering. */
|
|
298
|
+
edition: string;
|
|
299
|
+
coverage: string;
|
|
300
|
+
source: string;
|
|
301
|
+
/** Royal Mail's ownership of PAF data: show it where your product credits its data. */
|
|
302
|
+
acknowledgement: string;
|
|
303
|
+
/** The End User Terms this data is used under. */
|
|
304
|
+
terms: string;
|
|
305
|
+
docs: string;
|
|
306
|
+
total?: number;
|
|
307
|
+
next_cursor?: string | null;
|
|
308
|
+
next?: string | null;
|
|
309
|
+
}
|
|
310
|
+
export interface MetaNextEditionExpected {
|
|
311
|
+
from: string;
|
|
312
|
+
to: string;
|
|
313
|
+
}
|
|
314
|
+
export interface Meta {
|
|
315
|
+
/** The ONS Postcode Directory edition, YYYY-MM. */
|
|
316
|
+
edition: string;
|
|
317
|
+
/** The next quarterly edition, YYYY-MM. */
|
|
318
|
+
next_edition: string;
|
|
319
|
+
/** The dates the ONS usually publishes it between. */
|
|
320
|
+
next_edition_expected: MetaNextEditionExpected;
|
|
321
|
+
coverage: string;
|
|
322
|
+
licence: string;
|
|
323
|
+
attribution: string[];
|
|
324
|
+
docs: string;
|
|
325
|
+
radius_m?: number;
|
|
326
|
+
found?: number;
|
|
327
|
+
sent?: number;
|
|
328
|
+
total?: number;
|
|
329
|
+
next_cursor?: string | null;
|
|
330
|
+
next?: string | null;
|
|
331
|
+
source?: string;
|
|
332
|
+
/** Royal Mail's ownership of PAF data, on an answer that used it (a Northern Ireland postcode validated against PAF). */
|
|
333
|
+
acknowledgement?: string;
|
|
334
|
+
}
|
|
335
|
+
export interface Problem {
|
|
336
|
+
type: string;
|
|
337
|
+
title: string;
|
|
338
|
+
status: number;
|
|
339
|
+
detail: string;
|
|
340
|
+
instance: string;
|
|
341
|
+
request_id: string;
|
|
342
|
+
postcode?: string;
|
|
343
|
+
format_valid?: boolean;
|
|
344
|
+
known?: boolean;
|
|
345
|
+
coverage?: "not_covered";
|
|
346
|
+
country?: string;
|
|
347
|
+
upgrade?: string;
|
|
348
|
+
resets?: string;
|
|
349
|
+
fields?: string[];
|
|
350
|
+
early_access?: string;
|
|
351
|
+
/** Where to switch Address lookup on for this key. */
|
|
352
|
+
setup?: string;
|
|
353
|
+
parameters?: string[];
|
|
354
|
+
accepted?: string[];
|
|
355
|
+
}
|
|
356
|
+
export type Suggestion = DistrictSuggestion | PostcodeSuggestion;
|
|
357
|
+
export type AddressSuggestion = SuggestedAddress | SuggestedContainer;
|
|
358
|
+
/** Every problem type the API answers: the fragment of a problem's `type` URI. */
|
|
359
|
+
export type ProblemCode = "address_credits_exhausted" | "address_lookup_not_enabled" | "bad_request" | "body_too_large" | "daily_cap_reached" | "invalid_key" | "invalid_postcode" | "key_required" | "method_not_allowed" | "no_position" | "not_acceptable" | "not_covered" | "not_found" | "origin_not_allowed" | "postcode_not_found" | "publishable_key_not_allowed" | "quota_exceeded" | "rate_limited" | "secret_key_in_browser" | "secret_key_in_url" | "server_error" | "service_unavailable" | "suggestions_capped" | "unknown_parameter";
|
|
360
|
+
/** Each operation's answer: the type of `data` and of `meta`. */
|
|
361
|
+
export interface OperationTypes {
|
|
362
|
+
getPostcode: {
|
|
363
|
+
data: Postcode;
|
|
364
|
+
meta: Meta;
|
|
365
|
+
};
|
|
366
|
+
validatePostcode: {
|
|
367
|
+
data: Validation;
|
|
368
|
+
meta: Meta;
|
|
369
|
+
};
|
|
370
|
+
nearestToPostcode: {
|
|
371
|
+
data: Near[];
|
|
372
|
+
meta: Meta;
|
|
373
|
+
};
|
|
374
|
+
reverseGeocode: {
|
|
375
|
+
data: Near[];
|
|
376
|
+
meta: Meta;
|
|
377
|
+
};
|
|
378
|
+
bulkLookup: {
|
|
379
|
+
data: BulkItem[];
|
|
380
|
+
meta: Meta;
|
|
381
|
+
};
|
|
382
|
+
bulkReverse: {
|
|
383
|
+
data: ReverseItem[];
|
|
384
|
+
meta: Meta;
|
|
385
|
+
};
|
|
386
|
+
autocomplete: {
|
|
387
|
+
data: Suggestion[];
|
|
388
|
+
meta: Meta;
|
|
389
|
+
};
|
|
390
|
+
distance: {
|
|
391
|
+
data: Distance;
|
|
392
|
+
meta: Meta;
|
|
393
|
+
};
|
|
394
|
+
getOutcode: {
|
|
395
|
+
data: District;
|
|
396
|
+
meta: Meta;
|
|
397
|
+
};
|
|
398
|
+
outcodePostcodes: {
|
|
399
|
+
data: OutcodePostcode[];
|
|
400
|
+
meta: Meta;
|
|
401
|
+
};
|
|
402
|
+
getSector: {
|
|
403
|
+
data: Sector;
|
|
404
|
+
meta: Meta;
|
|
405
|
+
};
|
|
406
|
+
getArea: {
|
|
407
|
+
data: Area;
|
|
408
|
+
meta: Meta;
|
|
409
|
+
};
|
|
410
|
+
places: {
|
|
411
|
+
data: Place[];
|
|
412
|
+
meta: Meta;
|
|
413
|
+
};
|
|
414
|
+
usage: {
|
|
415
|
+
data: Usage;
|
|
416
|
+
meta: Meta;
|
|
417
|
+
};
|
|
418
|
+
addressesByPostcode: {
|
|
419
|
+
data: Address[];
|
|
420
|
+
meta: AddressMeta;
|
|
421
|
+
};
|
|
422
|
+
addressSuggest: {
|
|
423
|
+
data: AddressSuggestion[];
|
|
424
|
+
meta: AddressMeta;
|
|
425
|
+
};
|
|
426
|
+
addressRetrieve: {
|
|
427
|
+
data: Address;
|
|
428
|
+
meta: AddressMeta;
|
|
429
|
+
};
|
|
430
|
+
addressByUdprn: {
|
|
431
|
+
data: Address;
|
|
432
|
+
meta: AddressMeta;
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
export type OperationId = keyof OperationTypes;
|
|
436
|
+
/** Each operation's method, path and the query parameters it takes. */
|
|
437
|
+
export declare const OPERATIONS: {
|
|
438
|
+
/** Look up a postcode */
|
|
439
|
+
readonly getPostcode: {
|
|
440
|
+
readonly method: "GET";
|
|
441
|
+
readonly path: "/postcodes/{postcode}";
|
|
442
|
+
readonly query: readonly ["fields"];
|
|
443
|
+
};
|
|
444
|
+
/** Validate a postcode */
|
|
445
|
+
readonly validatePostcode: {
|
|
446
|
+
readonly method: "GET";
|
|
447
|
+
readonly path: "/postcodes/{postcode}/validate";
|
|
448
|
+
readonly query: readonly [];
|
|
449
|
+
};
|
|
450
|
+
/** Postcodes near a postcode */
|
|
451
|
+
readonly nearestToPostcode: {
|
|
452
|
+
readonly method: "GET";
|
|
453
|
+
readonly path: "/postcodes/{postcode}/nearest";
|
|
454
|
+
readonly query: readonly ["radius", "limit"];
|
|
455
|
+
};
|
|
456
|
+
/** Postcodes near a point (reverse geocode) */
|
|
457
|
+
readonly reverseGeocode: {
|
|
458
|
+
readonly method: "GET";
|
|
459
|
+
readonly path: "/postcodes";
|
|
460
|
+
readonly query: readonly ["lat", "lon", "radius", "limit"];
|
|
461
|
+
};
|
|
462
|
+
/** Bulk lookup (up to 100) */
|
|
463
|
+
readonly bulkLookup: {
|
|
464
|
+
readonly method: "POST";
|
|
465
|
+
readonly path: "/postcodes";
|
|
466
|
+
readonly query: readonly ["fields"];
|
|
467
|
+
};
|
|
468
|
+
/** Bulk reverse geocode (up to 20) */
|
|
469
|
+
readonly bulkReverse: {
|
|
470
|
+
readonly method: "POST";
|
|
471
|
+
readonly path: "/reverse";
|
|
472
|
+
readonly query: readonly [];
|
|
473
|
+
};
|
|
474
|
+
/** Autocomplete a partial postcode */
|
|
475
|
+
readonly autocomplete: {
|
|
476
|
+
readonly method: "GET";
|
|
477
|
+
readonly path: "/autocomplete";
|
|
478
|
+
readonly query: readonly ["q", "limit"];
|
|
479
|
+
};
|
|
480
|
+
/** Distance between two postcodes */
|
|
481
|
+
readonly distance: {
|
|
482
|
+
readonly method: "GET";
|
|
483
|
+
readonly path: "/distance";
|
|
484
|
+
readonly query: readonly ["from", "to"];
|
|
485
|
+
};
|
|
486
|
+
/** A postcode district */
|
|
487
|
+
readonly getOutcode: {
|
|
488
|
+
readonly method: "GET";
|
|
489
|
+
readonly path: "/outcodes/{outcode}";
|
|
490
|
+
readonly query: readonly [];
|
|
491
|
+
};
|
|
492
|
+
/** Every postcode in a district */
|
|
493
|
+
readonly outcodePostcodes: {
|
|
494
|
+
readonly method: "GET";
|
|
495
|
+
readonly path: "/outcodes/{outcode}/postcodes";
|
|
496
|
+
readonly query: readonly ["cursor", "limit"];
|
|
497
|
+
};
|
|
498
|
+
/** A postcode sector */
|
|
499
|
+
readonly getSector: {
|
|
500
|
+
readonly method: "GET";
|
|
501
|
+
readonly path: "/sectors/{sector}";
|
|
502
|
+
readonly query: readonly [];
|
|
503
|
+
};
|
|
504
|
+
/** A postcode area */
|
|
505
|
+
readonly getArea: {
|
|
506
|
+
readonly method: "GET";
|
|
507
|
+
readonly path: "/areas/{area}";
|
|
508
|
+
readonly query: readonly [];
|
|
509
|
+
};
|
|
510
|
+
/** Find a place */
|
|
511
|
+
readonly places: {
|
|
512
|
+
readonly method: "GET";
|
|
513
|
+
readonly path: "/places";
|
|
514
|
+
readonly query: readonly ["q", "limit"];
|
|
515
|
+
};
|
|
516
|
+
/** Your usage */
|
|
517
|
+
readonly usage: {
|
|
518
|
+
readonly method: "GET";
|
|
519
|
+
readonly path: "/usage";
|
|
520
|
+
readonly query: readonly [];
|
|
521
|
+
};
|
|
522
|
+
/** Addresses at a postcode (early access) */
|
|
523
|
+
readonly addressesByPostcode: {
|
|
524
|
+
readonly method: "GET";
|
|
525
|
+
readonly path: "/addresses";
|
|
526
|
+
readonly query: readonly ["postcode", "cursor"];
|
|
527
|
+
};
|
|
528
|
+
/** Address autocomplete (early access) */
|
|
529
|
+
readonly addressSuggest: {
|
|
530
|
+
readonly method: "GET";
|
|
531
|
+
readonly path: "/addresses/suggest";
|
|
532
|
+
readonly query: readonly ["q", "container", "limit"];
|
|
533
|
+
};
|
|
534
|
+
/** Resolve a suggestion (early access) */
|
|
535
|
+
readonly addressRetrieve: {
|
|
536
|
+
readonly method: "GET";
|
|
537
|
+
readonly path: "/addresses/retrieve/{id}";
|
|
538
|
+
readonly query: readonly [];
|
|
539
|
+
};
|
|
540
|
+
/** One address by UDPRN (early access) */
|
|
541
|
+
readonly addressByUdprn: {
|
|
542
|
+
readonly method: "GET";
|
|
543
|
+
readonly path: "/addresses/{udprn}";
|
|
544
|
+
readonly query: readonly [];
|
|
545
|
+
};
|
|
546
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var generated_exports = {};
|
|
20
|
+
__export(generated_exports, {
|
|
21
|
+
BASE_URL: () => BASE_URL,
|
|
22
|
+
OPERATIONS: () => OPERATIONS
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(generated_exports);
|
|
25
|
+
const BASE_URL = "https://api.clearpostcode.co.uk/v1";
|
|
26
|
+
const OPERATIONS = {
|
|
27
|
+
/** Look up a postcode */
|
|
28
|
+
getPostcode: { method: "GET", path: "/postcodes/{postcode}", query: ["fields"] },
|
|
29
|
+
/** Validate a postcode */
|
|
30
|
+
validatePostcode: { method: "GET", path: "/postcodes/{postcode}/validate", query: [] },
|
|
31
|
+
/** Postcodes near a postcode */
|
|
32
|
+
nearestToPostcode: { method: "GET", path: "/postcodes/{postcode}/nearest", query: ["radius", "limit"] },
|
|
33
|
+
/** Postcodes near a point (reverse geocode) */
|
|
34
|
+
reverseGeocode: { method: "GET", path: "/postcodes", query: ["lat", "lon", "radius", "limit"] },
|
|
35
|
+
/** Bulk lookup (up to 100) */
|
|
36
|
+
bulkLookup: { method: "POST", path: "/postcodes", query: ["fields"] },
|
|
37
|
+
/** Bulk reverse geocode (up to 20) */
|
|
38
|
+
bulkReverse: { method: "POST", path: "/reverse", query: [] },
|
|
39
|
+
/** Autocomplete a partial postcode */
|
|
40
|
+
autocomplete: { method: "GET", path: "/autocomplete", query: ["q", "limit"] },
|
|
41
|
+
/** Distance between two postcodes */
|
|
42
|
+
distance: { method: "GET", path: "/distance", query: ["from", "to"] },
|
|
43
|
+
/** A postcode district */
|
|
44
|
+
getOutcode: { method: "GET", path: "/outcodes/{outcode}", query: [] },
|
|
45
|
+
/** Every postcode in a district */
|
|
46
|
+
outcodePostcodes: { method: "GET", path: "/outcodes/{outcode}/postcodes", query: ["cursor", "limit"] },
|
|
47
|
+
/** A postcode sector */
|
|
48
|
+
getSector: { method: "GET", path: "/sectors/{sector}", query: [] },
|
|
49
|
+
/** A postcode area */
|
|
50
|
+
getArea: { method: "GET", path: "/areas/{area}", query: [] },
|
|
51
|
+
/** Find a place */
|
|
52
|
+
places: { method: "GET", path: "/places", query: ["q", "limit"] },
|
|
53
|
+
/** Your usage */
|
|
54
|
+
usage: { method: "GET", path: "/usage", query: [] },
|
|
55
|
+
/** Addresses at a postcode (early access) */
|
|
56
|
+
addressesByPostcode: { method: "GET", path: "/addresses", query: ["postcode", "cursor"] },
|
|
57
|
+
/** Address autocomplete (early access) */
|
|
58
|
+
addressSuggest: { method: "GET", path: "/addresses/suggest", query: ["q", "container", "limit"] },
|
|
59
|
+
/** Resolve a suggestion (early access) */
|
|
60
|
+
addressRetrieve: { method: "GET", path: "/addresses/retrieve/{id}", query: [] },
|
|
61
|
+
/** One address by UDPRN (early access) */
|
|
62
|
+
addressByUdprn: { method: "GET", path: "/addresses/{udprn}", query: [] }
|
|
63
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { type OperationId, type OperationTypes } from "./generated.js";
|
|
2
|
+
/** Options for one call. */
|
|
3
|
+
export interface RequestOptions {
|
|
4
|
+
/** Cancel the call (and any retry wait). */
|
|
5
|
+
signal?: AbortSignal;
|
|
6
|
+
/** Milliseconds to wait for each attempt. */
|
|
7
|
+
timeout?: number;
|
|
8
|
+
/** Retries after a 429, a 5xx, a timeout or a dropped connection. */
|
|
9
|
+
maxRetries?: number;
|
|
10
|
+
}
|
|
11
|
+
/** The limit closest to running out, from the RateLimit headers. */
|
|
12
|
+
export interface RateLimit {
|
|
13
|
+
/** Which limit: "month" (a keyed call's lookups), "day" (keyless), "burst" or "minute". */
|
|
14
|
+
policy: string | null;
|
|
15
|
+
limit: number | null;
|
|
16
|
+
remaining: number | null;
|
|
17
|
+
/** Seconds until it resets. */
|
|
18
|
+
reset: number | null;
|
|
19
|
+
}
|
|
20
|
+
/** One answer: `data` and `meta` as the API sent them, with the call's id and rate-limit state. */
|
|
21
|
+
export interface Result<D, M> {
|
|
22
|
+
readonly data: D;
|
|
23
|
+
readonly meta: M;
|
|
24
|
+
readonly status: number;
|
|
25
|
+
/** Quote it to support and the call can be traced. */
|
|
26
|
+
readonly requestId: string | null;
|
|
27
|
+
readonly rateLimit: RateLimit | null;
|
|
28
|
+
}
|
|
29
|
+
/** What the client needs to make calls. */
|
|
30
|
+
export interface TransportConfig {
|
|
31
|
+
key: string | null;
|
|
32
|
+
baseUrl: string;
|
|
33
|
+
timeout: number;
|
|
34
|
+
maxRetries: number;
|
|
35
|
+
/** The longest wait the client accepts before a retry; a longer Retry-After is thrown to you at once. */
|
|
36
|
+
maxRetryDelay: number;
|
|
37
|
+
fetch: typeof fetch;
|
|
38
|
+
/** Headers sent on every call (the user agent, outside browsers). */
|
|
39
|
+
headers: Record<string, string>;
|
|
40
|
+
/** Send the key as ?key= (publishable keys in browsers: no preflight) instead of the X-Api-Key header. */
|
|
41
|
+
keyInQuery: boolean;
|
|
42
|
+
}
|
|
43
|
+
export type Params = Record<string, string | number | null | undefined>;
|
|
44
|
+
/** One operation's call: path parameters, query parameters (only the ones the operation takes) and a JSON body. */
|
|
45
|
+
export interface Call {
|
|
46
|
+
path?: Record<string, string>;
|
|
47
|
+
query?: Params;
|
|
48
|
+
body?: unknown;
|
|
49
|
+
}
|
|
50
|
+
/** RateLimit-Limit/-Remaining/-Reset, with the policy name and any gaps filled from RateLimit and RateLimit-Policy. */
|
|
51
|
+
export declare function rateLimitOf(h: Headers): RateLimit | null;
|
|
52
|
+
export declare class Transport {
|
|
53
|
+
readonly config: TransportConfig;
|
|
54
|
+
constructor(config: TransportConfig);
|
|
55
|
+
/** The URL for an operation: path parameters encoded into the path, then the query it takes. */
|
|
56
|
+
url(id: OperationId, call: Call): string;
|
|
57
|
+
/** Make the call, retrying 429s, 5xx answers, timeouts and dropped connections with backoff (a POST: 429 and 503
|
|
58
|
+
* only). No wait is longer than maxRetryDelay: a longer Retry-After is thrown at once. */
|
|
59
|
+
request<I extends OperationId>(id: I, call?: Call, options?: RequestOptions): Promise<Result<OperationTypes[I]["data"], OperationTypes[I]["meta"]>>;
|
|
60
|
+
/** One attempt within the timeout: the response and its body. */
|
|
61
|
+
private attempt;
|
|
62
|
+
}
|