@ideal-postcodes/sdk 0.1.0 → 0.2.1

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 (45) hide show
  1. package/LICENSE +1 -23
  2. package/README.md +16 -18
  3. package/dist/autocomplete.cjs +1 -146
  4. package/dist/autocomplete.d.cts +27 -15
  5. package/dist/autocomplete.d.ts +27 -15
  6. package/dist/autocomplete.mjs +1 -146
  7. package/dist/chunk-27HFF2QV.mjs +6 -0
  8. package/dist/chunk-62UQ3UYV.mjs +1 -0
  9. package/dist/chunk-6R56WDLC.mjs +1 -0
  10. package/dist/chunk-CKB3E7DA.cjs +1 -0
  11. package/dist/chunk-MO2HGDFA.cjs +1 -0
  12. package/dist/chunk-WQKSRULX.cjs +6 -0
  13. package/dist/index.cjs +1 -76
  14. package/dist/index.d-BuZcXRMe.d.cts +45 -0
  15. package/dist/index.d-BuZcXRMe.d.ts +45 -0
  16. package/dist/index.d.cts +6 -12
  17. package/dist/index.d.ts +6 -12
  18. package/dist/index.mjs +1 -76
  19. package/dist/preact-query.cjs +1 -497
  20. package/dist/preact-query.d.cts +342 -325
  21. package/dist/preact-query.d.ts +342 -325
  22. package/dist/preact-query.mjs +1 -497
  23. package/dist/react-query.cjs +1 -497
  24. package/dist/react-query.d.cts +341 -324
  25. package/dist/react-query.d.ts +341 -324
  26. package/dist/react-query.mjs +1 -497
  27. package/dist/sdk.gen-C47s0BYz.d.ts +416 -0
  28. package/dist/sdk.gen-DdAMouYk.d.cts +416 -0
  29. package/dist/{types.gen-l7tYP1ZJ.d.cts → types.gen-Cr3qI_1Q.d.cts} +4658 -2712
  30. package/dist/{types.gen-l7tYP1ZJ.d.ts → types.gen-Cr3qI_1Q.d.ts} +4658 -2712
  31. package/package.json +71 -38
  32. package/dist/autocomplete.cjs.map +0 -1
  33. package/dist/autocomplete.mjs.map +0 -1
  34. package/dist/chunk-AVMJGCHZ.mjs +0 -913
  35. package/dist/chunk-AVMJGCHZ.mjs.map +0 -1
  36. package/dist/chunk-ZZUZHG5D.cjs +0 -913
  37. package/dist/chunk-ZZUZHG5D.cjs.map +0 -1
  38. package/dist/index.cjs.map +0 -1
  39. package/dist/index.mjs.map +0 -1
  40. package/dist/preact-query.cjs.map +0 -1
  41. package/dist/preact-query.mjs.map +0 -1
  42. package/dist/react-query.cjs.map +0 -1
  43. package/dist/react-query.mjs.map +0 -1
  44. package/dist/sdk.gen-C45EbTVQ.d.cts +0 -302
  45. package/dist/sdk.gen-_z1PNdoT.d.ts +0 -302
package/LICENSE CHANGED
@@ -1,23 +1 @@
1
- Copyright (c) IDDQD Limited. All rights reserved.
2
-
3
- This software is proprietary and confidential. Use of this software is permitted
4
- only as a dependency in your applications via package managers (e.g., npm install).
5
-
6
- You may:
7
- - Install and use this software as a dependency in your projects
8
- - Bundle this software as part of your application
9
-
10
- You may not:
11
- - Modify, adapt, or create derivative works of the source code
12
- - Redistribute, sublicense, or sell copies of the source code
13
- - Remove or alter any copyright notices
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.
22
-
23
- For licensing inquiries, contact: support@ideal-postcodes.co.uk
1
+ Copyright (C) IDDQD Limited - All Rights Reserved
package/README.md CHANGED
@@ -1,28 +1,26 @@
1
- # @ideal-postcodes/sdk
1
+ # Ideal Postcodes TypeScript SDK
2
2
 
3
- Fetch-based, treeshakable TypeScript SDK for [api.ideal-postcodes.co.uk](https://api.ideal-postcodes.co.uk).
3
+ Typed API calls over native fetch for browsers and Node.js 22 or later.
4
4
 
5
- ## Install
6
-
7
- ```sh
8
- npm install @ideal-postcodes/sdk
5
+ ```bash
6
+ pnpm add @ideal-postcodes/sdk
9
7
  ```
10
8
 
11
- ## Quick start
12
-
13
9
  ```ts
14
- import { createIdpcClient, postcodes } from "@ideal-postcodes/sdk";
15
-
16
- const client = createIdpcClient({ apiKey: "ak_..." });
17
-
18
- const { data } = await postcodes({ client, path: { postcode: "SW1A2AA" } });
19
- console.log(data?.result);
10
+ import { createIdpcClient, findAddress } from "@ideal-postcodes/sdk";
11
+
12
+ const client = createIdpcClient({ apiKey: "ak_test" });
13
+ const { data } = await findAddress({
14
+ client,
15
+ query: { query: "10 Downing Street" },
16
+ });
17
+ console.log(data.result.hits);
20
18
  ```
21
19
 
22
- ## Documentation
20
+ HTTP errors throw `ApiError`, with the HTTP `status` and the API's error `code` and `message`. Pass `throwOnError: false` to receive `{ data, error }` instead.
23
21
 
24
- Full documentation lives at [docs.ideal-postcodes.co.uk/docs/sdks/typescript](https://docs.ideal-postcodes.co.uk/docs/sdks/typescript) — concepts, autocomplete utilities, TanStack Query bindings, and a per-operation API reference.
22
+ [Documentation](https://docs.ideal-postcodes.co.uk/docs/sdks/typescript/) covers authentication, errors, autocomplete and optional React/Preact adapters. Named ESM imports support tree-shaking.
25
23
 
26
- ## Licence
24
+ ## License
27
25
 
28
- See [`LICENSE`](./LICENSE).
26
+ SEE LICENSE IN LICENSE
@@ -1,146 +1 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
-
3
-
4
- var _chunkZZUZHG5Dcjs = require('./chunk-ZZUZHG5D.cjs');
5
-
6
- // src/cache.ts
7
- var LruCache = class {
8
- constructor(options = {}) {
9
- this.map = /* @__PURE__ */ new Map();
10
- this.max = _nullishCoalesce(options.max, () => ( 50));
11
- this.ttlMs = _nullishCoalesce(options.ttlMs, () => ( 6e4));
12
- }
13
- get(key) {
14
- const entry = this.map.get(key);
15
- if (!entry) return void 0;
16
- if (entry.expiresAt <= Date.now()) {
17
- this.map.delete(key);
18
- return void 0;
19
- }
20
- this.map.delete(key);
21
- this.map.set(key, entry);
22
- return entry.value;
23
- }
24
- set(key, value) {
25
- if (this.map.has(key)) {
26
- this.map.delete(key);
27
- } else if (this.map.size >= this.max) {
28
- const oldest = this.map.keys().next().value;
29
- if (oldest !== void 0) this.map.delete(oldest);
30
- }
31
- this.map.set(key, { value, expiresAt: Date.now() + this.ttlMs });
32
- }
33
- delete(key) {
34
- return this.map.delete(key);
35
- }
36
- clear() {
37
- this.map.clear();
38
- }
39
- get size() {
40
- return this.map.size;
41
- }
42
- };
43
- var stableKey = (input) => {
44
- const seen = /* @__PURE__ */ new WeakSet();
45
- const norm = (value) => {
46
- if (value === null || typeof value !== "object") return value;
47
- if (seen.has(value)) return null;
48
- seen.add(value);
49
- if (Array.isArray(value)) return value.map(norm);
50
- const entries = Object.entries(value).filter(([, v]) => v !== void 0).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
51
- return Object.fromEntries(entries.map(([k, v]) => [k, norm(v)]));
52
- };
53
- return JSON.stringify(norm(input));
54
- };
55
-
56
- // src/debounce.ts
57
- var abortError = (message) => new DOMException(message, "AbortError");
58
- var debounce = (fn, ms) => {
59
- let timer = null;
60
- let controller = null;
61
- let pendingReject = null;
62
- const abort = (reason) => {
63
- if (timer !== null) {
64
- clearTimeout(timer);
65
- timer = null;
66
- }
67
- if (controller) {
68
- controller.abort(reason);
69
- controller = null;
70
- }
71
- if (pendingReject) {
72
- pendingReject(reason);
73
- pendingReject = null;
74
- }
75
- };
76
- const debounced = ((...args) => new Promise((resolve, reject) => {
77
- abort(abortError("debounced call superseded"));
78
- pendingReject = reject;
79
- const localController = new AbortController();
80
- controller = localController;
81
- timer = setTimeout(() => {
82
- timer = null;
83
- fn(localController.signal, ...args).then(
84
- (value) => {
85
- if (localController.signal.aborted) return;
86
- controller = null;
87
- pendingReject = null;
88
- resolve(value);
89
- },
90
- (err) => {
91
- if (localController.signal.aborted) return;
92
- controller = null;
93
- pendingReject = null;
94
- reject(err);
95
- }
96
- );
97
- }, ms);
98
- }));
99
- debounced.cancel = () => {
100
- abort(abortError("debounced call cancelled"));
101
- };
102
- return debounced;
103
- };
104
-
105
- // src/autocomplete.ts
106
- var makeCache = (cache) => cache === false ? null : new LruCache(cache);
107
- var createAutocomplete = (options) => {
108
- const { client, debounceMs = 100, cache } = options;
109
- const searchCache = makeCache(cache);
110
- const resolveGbrCache = makeCache(cache);
111
- const debouncedSearch = debounce(
112
- async (signal, input) => {
113
- const key = stableKey(input);
114
- const cached = _optionalChain([searchCache, 'optionalAccess', _ => _.get, 'call', _2 => _2(key)]);
115
- if (cached) return cached;
116
- const { data } = await _chunkZZUZHG5Dcjs.findAddress.call(void 0, {
117
- client,
118
- signal,
119
- throwOnError: true,
120
- ...input
121
- });
122
- _optionalChain([searchCache, 'optionalAccess', _3 => _3.set, 'call', _4 => _4(key, data)]);
123
- return data;
124
- },
125
- debounceMs
126
- );
127
- return {
128
- search: (input) => debouncedSearch(input),
129
- resolveGbr: async (input) => {
130
- const key = stableKey(input);
131
- const cached = _optionalChain([resolveGbrCache, 'optionalAccess', _5 => _5.get, 'call', _6 => _6(key)]);
132
- if (cached) return cached;
133
- const { data } = await _chunkZZUZHG5Dcjs.resolveAddress.call(void 0, {
134
- client,
135
- throwOnError: true,
136
- ...input
137
- });
138
- _optionalChain([resolveGbrCache, 'optionalAccess', _7 => _7.set, 'call', _8 => _8(key, data)]);
139
- return data;
140
- }
141
- };
142
- };
143
-
144
-
145
- exports.createAutocomplete = createAutocomplete;
146
- //# sourceMappingURL=autocomplete.cjs.map
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunkMO2HGDFAcjs = require('./chunk-MO2HGDFA.cjs');var _chunkWQKSRULXcjs = require('./chunk-WQKSRULX.cjs');var v=f=>{let{client:s,debounceMs:y=100,cache:r}=f,o=r===!1?null:new (0, _chunkMO2HGDFAcjs.a)(r),i=_chunkMO2HGDFAcjs.c.call(void 0, async(e,{signal:t,...n})=>{_optionalChain([t, 'optionalAccess', _ => _.throwIfAborted, 'call', _2 => _2()]);let d=_chunkMO2HGDFAcjs.b.call(void 0, n),a=_optionalChain([o, 'optionalAccess', _3 => _3.get, 'call', _4 => _4(d)]);if(a)return a;let{data:h}=await _chunkWQKSRULXcjs.k.call(void 0, {client:s,signal:t?AbortSignal.any([e,t]):e,query:n,throwOnError:!0}),c=h.result.hits;return _optionalChain([o, 'optionalAccess', _5 => _5.set, 'call', _6 => _6(d,c)]),c},y);return{find:e=>i(e),cancel:()=>i.cancel(),resolve:async({hit:e,signal:t})=>{let{data:n}=await _chunkWQKSRULXcjs.l.call(void 0, {client:s,signal:t,path:{address:e.id},throwOnError:!0});return n.result}}};exports.createAutocomplete = v;
@@ -1,25 +1,37 @@
1
- import { C as Client, cU as FindAddressData, cY as FindAddressResponse, cZ as ResolveAddressData, d1 as ResolveAddressResponse } from './types.gen-l7tYP1ZJ.cjs';
2
-
3
- interface CacheOptions {
4
- /** Max entries before LRU eviction. Default 50. */
5
- max?: number;
6
- /** Time-to-live in ms. Default 60_000. */
7
- ttlMs?: number;
8
- }
1
+ import { C as CacheOptions } from './index.d-BuZcXRMe.cjs';
2
+ import { F as FindAddressData, a as FindAddressResponse, R as ResolveAddressResponse, C as Client } from './types.gen-Cr3qI_1Q.cjs';
9
3
 
10
4
  interface CreateAutocompleteOptions {
11
5
  client: Client;
12
- /** Quiet-period in ms before a search fires. Default 100. */
6
+ /** Quiet-period in ms before a find fires. Default 100. */
13
7
  debounceMs?: number;
14
- /** Cache settings, or false to disable. Default { max: 50, ttlMs: 60_000 }. */
8
+ /** Suggestions cache settings, or false to disable. Default { max: 50, ttlMs: 60_000 }. */
15
9
  cache?: CacheOptions | false;
16
10
  }
17
- type SearchInput = Omit<FindAddressData, "body" | "path">;
18
- type ResolveInput = Omit<ResolveAddressData, "body">;
11
+ /** One address suggestion returned by `find`. */
12
+ type Hit = FindAddressResponse["result"]["hits"][number];
13
+ /** The full address returned by `resolve`. */
14
+ type ResolvedAddress = ResolveAddressResponse["result"];
15
+ type FindInput = Omit<NonNullable<FindAddressData["query"]>, "api_key" | "query"> & {
16
+ query: string;
17
+ /** Aborting rejects this find with AbortError. */
18
+ signal?: AbortSignal;
19
+ };
20
+ interface ResolveInput {
21
+ hit: Hit;
22
+ signal?: AbortSignal;
23
+ }
19
24
  interface Autocomplete {
20
- search(input: SearchInput): Promise<FindAddressResponse>;
21
- resolveGbr(input: ResolveInput): Promise<ResolveAddressResponse>;
25
+ /**
26
+ * Suggestions for `query`, `[]` when nothing matches. Resolves `undefined`
27
+ * when superseded by a newer find or cancelled.
28
+ */
29
+ find(input: FindInput): Promise<Hit[] | undefined>;
30
+ /** Fetch the full address for a hit. */
31
+ resolve(input: ResolveInput): Promise<ResolvedAddress>;
32
+ /** Drop the pending find; its Promise resolves `undefined`. */
33
+ cancel(): void;
22
34
  }
23
35
  declare const createAutocomplete: (options: CreateAutocompleteOptions) => Autocomplete;
24
36
 
25
- export { type Autocomplete, type CreateAutocompleteOptions, createAutocomplete };
37
+ export { type Autocomplete, type CreateAutocompleteOptions, type FindInput, type Hit, type ResolveInput, type ResolvedAddress, createAutocomplete };
@@ -1,25 +1,37 @@
1
- import { C as Client, cU as FindAddressData, cY as FindAddressResponse, cZ as ResolveAddressData, d1 as ResolveAddressResponse } from './types.gen-l7tYP1ZJ.js';
2
-
3
- interface CacheOptions {
4
- /** Max entries before LRU eviction. Default 50. */
5
- max?: number;
6
- /** Time-to-live in ms. Default 60_000. */
7
- ttlMs?: number;
8
- }
1
+ import { C as CacheOptions } from './index.d-BuZcXRMe.js';
2
+ import { F as FindAddressData, a as FindAddressResponse, R as ResolveAddressResponse, C as Client } from './types.gen-Cr3qI_1Q.js';
9
3
 
10
4
  interface CreateAutocompleteOptions {
11
5
  client: Client;
12
- /** Quiet-period in ms before a search fires. Default 100. */
6
+ /** Quiet-period in ms before a find fires. Default 100. */
13
7
  debounceMs?: number;
14
- /** Cache settings, or false to disable. Default { max: 50, ttlMs: 60_000 }. */
8
+ /** Suggestions cache settings, or false to disable. Default { max: 50, ttlMs: 60_000 }. */
15
9
  cache?: CacheOptions | false;
16
10
  }
17
- type SearchInput = Omit<FindAddressData, "body" | "path">;
18
- type ResolveInput = Omit<ResolveAddressData, "body">;
11
+ /** One address suggestion returned by `find`. */
12
+ type Hit = FindAddressResponse["result"]["hits"][number];
13
+ /** The full address returned by `resolve`. */
14
+ type ResolvedAddress = ResolveAddressResponse["result"];
15
+ type FindInput = Omit<NonNullable<FindAddressData["query"]>, "api_key" | "query"> & {
16
+ query: string;
17
+ /** Aborting rejects this find with AbortError. */
18
+ signal?: AbortSignal;
19
+ };
20
+ interface ResolveInput {
21
+ hit: Hit;
22
+ signal?: AbortSignal;
23
+ }
19
24
  interface Autocomplete {
20
- search(input: SearchInput): Promise<FindAddressResponse>;
21
- resolveGbr(input: ResolveInput): Promise<ResolveAddressResponse>;
25
+ /**
26
+ * Suggestions for `query`, `[]` when nothing matches. Resolves `undefined`
27
+ * when superseded by a newer find or cancelled.
28
+ */
29
+ find(input: FindInput): Promise<Hit[] | undefined>;
30
+ /** Fetch the full address for a hit. */
31
+ resolve(input: ResolveInput): Promise<ResolvedAddress>;
32
+ /** Drop the pending find; its Promise resolves `undefined`. */
33
+ cancel(): void;
22
34
  }
23
35
  declare const createAutocomplete: (options: CreateAutocompleteOptions) => Autocomplete;
24
36
 
25
- export { type Autocomplete, type CreateAutocompleteOptions, createAutocomplete };
37
+ export { type Autocomplete, type CreateAutocompleteOptions, type FindInput, type Hit, type ResolveInput, type ResolvedAddress, createAutocomplete };
@@ -1,146 +1 @@
1
- import {
2
- findAddress,
3
- resolveAddress
4
- } from "./chunk-AVMJGCHZ.mjs";
5
-
6
- // src/cache.ts
7
- var LruCache = class {
8
- constructor(options = {}) {
9
- this.map = /* @__PURE__ */ new Map();
10
- this.max = options.max ?? 50;
11
- this.ttlMs = options.ttlMs ?? 6e4;
12
- }
13
- get(key) {
14
- const entry = this.map.get(key);
15
- if (!entry) return void 0;
16
- if (entry.expiresAt <= Date.now()) {
17
- this.map.delete(key);
18
- return void 0;
19
- }
20
- this.map.delete(key);
21
- this.map.set(key, entry);
22
- return entry.value;
23
- }
24
- set(key, value) {
25
- if (this.map.has(key)) {
26
- this.map.delete(key);
27
- } else if (this.map.size >= this.max) {
28
- const oldest = this.map.keys().next().value;
29
- if (oldest !== void 0) this.map.delete(oldest);
30
- }
31
- this.map.set(key, { value, expiresAt: Date.now() + this.ttlMs });
32
- }
33
- delete(key) {
34
- return this.map.delete(key);
35
- }
36
- clear() {
37
- this.map.clear();
38
- }
39
- get size() {
40
- return this.map.size;
41
- }
42
- };
43
- var stableKey = (input) => {
44
- const seen = /* @__PURE__ */ new WeakSet();
45
- const norm = (value) => {
46
- if (value === null || typeof value !== "object") return value;
47
- if (seen.has(value)) return null;
48
- seen.add(value);
49
- if (Array.isArray(value)) return value.map(norm);
50
- const entries = Object.entries(value).filter(([, v]) => v !== void 0).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
51
- return Object.fromEntries(entries.map(([k, v]) => [k, norm(v)]));
52
- };
53
- return JSON.stringify(norm(input));
54
- };
55
-
56
- // src/debounce.ts
57
- var abortError = (message) => new DOMException(message, "AbortError");
58
- var debounce = (fn, ms) => {
59
- let timer = null;
60
- let controller = null;
61
- let pendingReject = null;
62
- const abort = (reason) => {
63
- if (timer !== null) {
64
- clearTimeout(timer);
65
- timer = null;
66
- }
67
- if (controller) {
68
- controller.abort(reason);
69
- controller = null;
70
- }
71
- if (pendingReject) {
72
- pendingReject(reason);
73
- pendingReject = null;
74
- }
75
- };
76
- const debounced = ((...args) => new Promise((resolve, reject) => {
77
- abort(abortError("debounced call superseded"));
78
- pendingReject = reject;
79
- const localController = new AbortController();
80
- controller = localController;
81
- timer = setTimeout(() => {
82
- timer = null;
83
- fn(localController.signal, ...args).then(
84
- (value) => {
85
- if (localController.signal.aborted) return;
86
- controller = null;
87
- pendingReject = null;
88
- resolve(value);
89
- },
90
- (err) => {
91
- if (localController.signal.aborted) return;
92
- controller = null;
93
- pendingReject = null;
94
- reject(err);
95
- }
96
- );
97
- }, ms);
98
- }));
99
- debounced.cancel = () => {
100
- abort(abortError("debounced call cancelled"));
101
- };
102
- return debounced;
103
- };
104
-
105
- // src/autocomplete.ts
106
- var makeCache = (cache) => cache === false ? null : new LruCache(cache);
107
- var createAutocomplete = (options) => {
108
- const { client, debounceMs = 100, cache } = options;
109
- const searchCache = makeCache(cache);
110
- const resolveGbrCache = makeCache(cache);
111
- const debouncedSearch = debounce(
112
- async (signal, input) => {
113
- const key = stableKey(input);
114
- const cached = searchCache?.get(key);
115
- if (cached) return cached;
116
- const { data } = await findAddress({
117
- client,
118
- signal,
119
- throwOnError: true,
120
- ...input
121
- });
122
- searchCache?.set(key, data);
123
- return data;
124
- },
125
- debounceMs
126
- );
127
- return {
128
- search: (input) => debouncedSearch(input),
129
- resolveGbr: async (input) => {
130
- const key = stableKey(input);
131
- const cached = resolveGbrCache?.get(key);
132
- if (cached) return cached;
133
- const { data } = await resolveAddress({
134
- client,
135
- throwOnError: true,
136
- ...input
137
- });
138
- resolveGbrCache?.set(key, data);
139
- return data;
140
- }
141
- };
142
- };
143
- export {
144
- createAutocomplete
145
- };
146
- //# sourceMappingURL=autocomplete.mjs.map
1
+ import{a as p,b as l,c as u}from"./chunk-62UQ3UYV.mjs";import{k as A,l as m}from"./chunk-27HFF2QV.mjs";var v=f=>{let{client:s,debounceMs:y=100,cache:r}=f,o=r===!1?null:new p(r),i=u(async(e,{signal:t,...n})=>{t?.throwIfAborted();let d=l(n),a=o?.get(d);if(a)return a;let{data:h}=await A({client:s,signal:t?AbortSignal.any([e,t]):e,query:n,throwOnError:!0}),c=h.result.hits;return o?.set(d,c),c},y);return{find:e=>i(e),cancel:()=>i.cancel(),resolve:async({hit:e,signal:t})=>{let{data:n}=await m({client:s,signal:t,path:{address:e.id},throwOnError:!0});return n.result}}};export{v as createAutocomplete};
@@ -0,0 +1,6 @@
1
+ var F={bodySerializer:e=>JSON.stringify(e,(r,t)=>typeof t=="bigint"?t.toString():t)};function W({onRequest:e,onSseError:r,onSseEvent:t,responseTransformer:n,responseValidator:i,sseDefaultRetryDelay:l,sseMaxRetryAttempts:o,sseMaxRetryDelay:s,sseSleepFn:a,url:O,...p}){let c,R=a??(u=>new Promise(f=>setTimeout(f,u)));return{stream:async function*(){let u=l??3e3,f=0,b=p.signal??new AbortController().signal;for(;!b.aborted;){f++;let A=p.headers instanceof Headers?p.headers:new Headers(p.headers);c!==void 0&&A.set("Last-Event-ID",c);try{let T={redirect:"follow",...p,body:p.serializedBody,headers:A,signal:b},x=new Request(O,T);e&&(x=await e(O,T));let h=await(p.fetch??globalThis.fetch)(x);if(!h.ok)throw new Error(`SSE failed: ${h.status} ${h.statusText}`);if(!h.body)throw new Error("No body in SSE response");let E=h.body.pipeThrough(new TextDecoderStream).getReader(),g="",B=()=>{try{E.cancel()}catch{}};b.addEventListener("abort",B);try{for(;;){let{done:Y,value:Z}=await E.read();if(Y)break;g+=Z,g=g.replace(/\r\n?/g,`
2
+ `);let N=g.split(`
3
+
4
+ `);g=N.pop()??"";for(let ee of N){let re=ee.split(`
5
+ `),z=[],$;for(let w of re)if(w.startsWith("data:"))z.push(w.replace(/^data:\s*/,""));else if(w.startsWith("event:"))$=w.replace(/^event:\s*/,"");else if(w.startsWith("id:"))c=w.replace(/^id:\s*/,"");else if(w.startsWith("retry:")){let H=Number.parseInt(w.replace(/^retry:\s*/,""),10);Number.isNaN(H)||(u=H)}let S,V=!1;if(z.length){let w=z.join(`
6
+ `);try{S=JSON.parse(w),V=!0}catch{S=w}}V&&(i&&await i(S),n&&(S=await n(S))),t?.({data:S,event:$,id:c,retry:u}),z.length&&(yield S)}}}finally{b.removeEventListener("abort",B),E.releaseLock()}break}catch(T){if(r?.(T),o!==void 0&&f>=o)break;let x=Math.min(u*2**(f-1),s??3e4);await R(x)}}}()}}var te=e=>{switch(e){case"label":return".";case"matrix":return";";case"simple":return",";default:return"&"}},se=e=>{switch(e){case"form":return",";case"pipeDelimited":return"|";case"spaceDelimited":return"%20";default:return","}},ne=e=>{switch(e){case"label":return".";case"matrix":return";";case"simple":return",";default:return"&"}},q=({allowReserved:e,explode:r,name:t,style:n,value:i})=>{if(!r){let s=(e?i:i.map(a=>encodeURIComponent(a))).join(se(n));switch(n){case"label":return`.${s}`;case"matrix":return`;${t}=${s}`;case"simple":return s;default:return`${t}=${s}`}}let l=te(n),o=i.map(s=>n==="label"||n==="simple"?e?s:encodeURIComponent(s):C({allowReserved:e,name:t,value:s})).join(l);return n==="label"||n==="matrix"?l+o:o},C=({allowReserved:e,name:r,value:t})=>{if(t==null)return"";if(typeof t=="object")throw new Error("Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these.");return`${r}=${e?t:encodeURIComponent(t)}`},P=({allowReserved:e,explode:r,name:t,style:n,value:i,valueOnly:l})=>{if(i instanceof Date)return l?i.toISOString():`${t}=${i.toISOString()}`;if(n!=="deepObject"&&!r){let a=[];Object.entries(i).forEach(([p,c])=>{a=[...a,p,e?c:encodeURIComponent(c)]});let O=a.join(",");switch(n){case"form":return`${t}=${O}`;case"label":return`.${O}`;case"matrix":return`;${t}=${O}`;default:return O}}let o=ne(n),s=Object.entries(i).map(([a,O])=>C({allowReserved:e,name:n==="deepObject"?`${t}[${a}]`:a,value:O})).join(o);return n==="label"||n==="matrix"?o+s:s};var oe=/\{[^{}]+\}/g,ae=({path:e,url:r})=>{let t=r,n=r.match(oe);if(n)for(let i of n){let l=!1,o=i.substring(1,i.length-1),s="simple";o.endsWith("*")&&(l=!0,o=o.substring(0,o.length-1)),o.startsWith(".")?(o=o.substring(1),s="label"):o.startsWith(";")&&(o=o.substring(1),s="matrix");let a=e[o];if(a==null)continue;if(Array.isArray(a)){t=t.replace(i,q({explode:l,name:o,style:s,value:a}));continue}if(typeof a=="object"){t=t.replace(i,P({explode:l,name:o,style:s,value:a,valueOnly:!0}));continue}if(s==="matrix"){t=t.replace(i,`;${C({name:o,value:a})}`);continue}let O=encodeURIComponent(s==="label"?`.${a}`:a);t=t.replace(i,O)}return t},Q=({baseUrl:e,path:r,query:t,querySerializer:n,url:i})=>{let l=i.startsWith("/")?i:`/${i}`,o=(e??"")+l;r&&(o=ae({path:r,url:o}));let s=t?n(t):"";return s.startsWith("?")&&(s=s.substring(1)),s&&(o+=`?${s}`),o};function L(e){let r=e.body!==void 0;if(r&&e.bodySerializer)return"serializedBody"in e?e.serializedBody!==void 0&&e.serializedBody!==""?e.serializedBody:null:e.body!==""?e.body:null;if(r)return e.body}var M=async(e,r)=>{let t=typeof r=="function"?await r(e):r;if(t)return e.scheme==="bearer"?`Bearer ${t}`:e.scheme==="basic"?`Basic ${btoa(t)}`:t};var J=({parameters:e={},...r}={})=>n=>{let i=[];if(n&&typeof n=="object")for(let l in n){let o=n[l];if(o==null)continue;let s=e[l]||r;if(Array.isArray(o)){let a=q({allowReserved:s.allowReserved,explode:!0,name:l,style:"form",value:o,...s.array});a&&i.push(a)}else if(typeof o=="object"){let a=P({allowReserved:s.allowReserved,explode:!0,name:l,style:"deepObject",value:o,...s.object});a&&i.push(a)}else{let a=C({allowReserved:s.allowReserved,name:l,value:o});a&&i.push(a)}}return i.join("&")},_=e=>{if(!e)return"stream";let r=e.split(";")[0]?.trim();if(r){if(r.startsWith("application/json")||r.endsWith("+json"))return"json";if(r==="multipart/form-data")return"formData";if(["application/","audio/","image/","video/"].some(t=>r.startsWith(t)))return"blob";if(r.startsWith("text/"))return"text"}},ie=(e,r)=>r?!!(e.headers.has(r)||e.query?.[r]||e.headers.get("Cookie")?.includes(`${r}=`)):!1;async function G(e){for(let r of e.security??[]){if(ie(e,r.name))continue;let t=await M(r,e.auth);if(!t)continue;let n=r.name??"Authorization";switch(r.in){case"query":e.query||(e.query={}),e.query[n]=t;break;case"cookie":e.headers.append("Cookie",`${n}=${t}`);break;default:e.headers.set(n,t);break}}}var U=e=>Q({baseUrl:e.baseUrl,path:e.path,query:e.query,querySerializer:typeof e.querySerializer=="function"?e.querySerializer:J(e.querySerializer),url:e.url}),I=(e,r)=>{let t={...e,...r};return t.baseUrl?.endsWith("/")&&(t.baseUrl=t.baseUrl.substring(0,t.baseUrl.length-1)),t.headers=v(e.headers,r.headers),t},le=e=>{let r=[];return e.forEach((t,n)=>{r.push([n,t])}),r},v=(...e)=>{let r=new Headers;for(let t of e){if(!t)continue;let n=t instanceof Headers?le(t):Object.entries(t);for(let[i,l]of n)if(l===null)r.delete(i);else if(Array.isArray(l))for(let o of l)r.append(i,o);else l!==void 0&&r.set(i,typeof l=="object"?JSON.stringify(l):l)}return r},D=class{constructor(){this.fns=[]}clear(){this.fns=[]}eject(r){let t=this.getInterceptorIndex(r);this.fns[t]&&(this.fns[t]=null)}exists(r){let t=this.getInterceptorIndex(r);return!!this.fns[t]}getInterceptorIndex(r){return typeof r=="number"?this.fns[r]?r:-1:this.fns.indexOf(r)}update(r,t){let n=this.getInterceptorIndex(r);return this.fns[n]?(this.fns[n]=t,r):!1}use(r){return this.fns.push(r),this.fns.length-1}},X=()=>({error:new D,request:new D,response:new D}),ce=J({allowReserved:!1,array:{explode:!0,style:"form"},object:{explode:!0,style:"deepObject"}}),pe={"Content-Type":"application/json"},k=(e={})=>({...F,headers:pe,parseAs:"auto",querySerializer:ce,...e});var K=(e={})=>{let r=I(k(),e),t=()=>({...r}),n=p=>(r=I(r,p),t()),i=X(),l=async p=>{let c={...r,...p,fetch:p.fetch??r.fetch??globalThis.fetch,headers:v(r.headers,p.headers),serializedBody:void 0};c.security&&await G(c),c.requestValidator&&await c.requestValidator(c),c.body!==void 0&&c.bodySerializer&&(c.serializedBody=c.bodySerializer(c.body)),(c.body===void 0||c.serializedBody==="")&&c.headers.delete("Content-Type");let R=c,m=U(R);return{opts:R,url:m}},o=async p=>{let c=p.throwOnError??r.throwOnError,R=p.responseStyle??r.responseStyle,m,y;try{let{opts:u,url:f}=await l(p),b={redirect:"follow",...u,body:L(u)};m=new Request(f,b);for(let h of i.request.fns)h&&(m=await h(m,u));let A=u.fetch;y=await A(m);for(let h of i.response.fns)h&&(y=await h(y,m,u));let T={request:m,response:y};if(y.ok){let h=(u.parseAs==="auto"?_(y.headers.get("Content-Type")):u.parseAs)??"json";if(y.status===204||y.headers.get("Content-Length")==="0"){let g;switch(h){case"arrayBuffer":case"blob":case"text":g=await y[h]();break;case"formData":g=new FormData;break;case"stream":g=y.body;break;default:g={};break}return u.responseStyle==="data"?g:{data:g,...T}}let E;switch(h){case"arrayBuffer":case"blob":case"formData":case"text":E=await y[h]();break;case"json":{let g=await y.text();E=g?JSON.parse(g):{};break}case"stream":return u.responseStyle==="data"?y.body:{data:y.body,...T}}return h==="json"&&(u.responseValidator&&await u.responseValidator(E),u.responseTransformer&&(E=await u.responseTransformer(E))),u.responseStyle==="data"?E:{data:E,...T}}let x=await y.text(),j;try{j=JSON.parse(x)}catch{}throw j??x}catch(u){let f=u;for(let b of i.error.fns)b&&(f=await b(f,y,m,p));if(f=f||{},c)throw f;return R==="data"?void 0:{error:f,request:m,response:y}}},s=p=>c=>o({...c,method:p}),a=p=>async c=>{let{opts:R,url:m}=await l(c);return W({...R,body:R.body,method:p,onRequest:async(y,u)=>{let f=new Request(y,u);for(let b of i.request.fns)b&&(f=await b(f,R));return f},serializedBody:L(R),url:m})};return{buildUrl:p=>U({...r,...p}),connect:s("CONNECT"),delete:s("DELETE"),get:s("GET"),getConfig:t,head:s("HEAD"),interceptors:i,options:s("OPTIONS"),patch:s("PATCH"),post:s("POST"),put:s("PUT"),request:o,setConfig:n,sse:{connect:a("CONNECT"),delete:a("DELETE"),get:a("GET"),head:a("HEAD"),options:a("OPTIONS"),patch:a("PATCH"),post:a("POST"),put:a("PUT"),trace:a("TRACE")},trace:s("TRACE")}};var d=K(k({baseUrl:"https://api.ideal-postcodes.co.uk/v1",throwOnError:!0}));var Pe=e=>(e.client??d).get({querySerializer:{parameters:{dataset:{array:{explode:!1}}}},security:[{scheme:"bearer",type:"http"}],url:"/postcodes/{postcode}",...e}),ve=e=>(e.client??d).get({url:"/keys/{key}",...e}),je=e=>(e.client??d).get({security:[{scheme:"bearer",type:"http"}],url:"/keys/{key}/details",...e}),Le=e=>(e.client??d).put({security:[{scheme:"bearer",type:"http"}],url:"/keys/{key}/details",...e,headers:{"Content-Type":"application/json",...e.headers}}),Ue=e=>(e.client??d).get({security:[{scheme:"bearer",type:"http"}],url:"/keys/{key}/usage",...e}),Ie=e=>(e.client??d).get({security:[{scheme:"bearer",type:"http"}],url:"/keys/{key}/lookups",...e}),Ke=e=>(e.client??d).post({security:[{scheme:"bearer",type:"http"}],url:"/cleanse/addresses",...e,headers:{"Content-Type":"application/json",...e.headers}}),Be=e=>(e?.client??d).get({querySerializer:{parameters:{dataset:{array:{explode:!1}}}},security:[{scheme:"bearer",type:"http"}],url:"/autocomplete/addresses",...e}),Ne=e=>(e.client??d).get({security:[{scheme:"bearer",type:"http"}],url:"/autocomplete/addresses/{address}/gbr",...e}),$e=e=>(e?.client??d).get({querySerializer:{parameters:{dataset:{array:{explode:!1}}}},security:[{scheme:"bearer",type:"http"}],url:"/addresses",...e}),Ve=e=>(e?.client??d).get({security:[{scheme:"bearer",type:"http"}],url:"/places",...e}),He=e=>(e.client??d).get({security:[{scheme:"bearer",type:"http"}],url:"/places/{place}",...e}),Fe=e=>(e.client??d).get({security:[{scheme:"bearer",type:"http"}],url:"/keys/{key}/licensees",...e}),We=e=>(e.client??d).post({security:[{scheme:"bearer",type:"http"}],url:"/keys/{key}/licensees",...e,headers:{"Content-Type":"application/json",...e.headers}}),Qe=e=>(e.client??d).delete({security:[{scheme:"bearer",type:"http"}],url:"/keys/{key}/licensees/{licensee}",...e}),Me=e=>(e.client??d).get({security:[{scheme:"bearer",type:"http"}],url:"/keys/{key}/licensees/{licensee}",...e}),Je=e=>(e.client??d).post({security:[{scheme:"bearer",type:"http"}],url:"/keys/{key}/licensees/{licensee}",...e,headers:{"Content-Type":"application/json",...e.headers}}),_e=e=>(e.client??d).post({security:[{scheme:"bearer",type:"http"}],url:"/keys/{key}/licensees/{licensee}/regenerate-key",...e}),Ge=e=>(e.client??d).get({security:[{scheme:"bearer",type:"http"}],url:"/keys/{key}/configs",...e}),Xe=e=>(e.client??d).post({security:[{scheme:"bearer",type:"http"}],url:"/keys/{key}/configs",...e,headers:{"Content-Type":"application/json",...e.headers}}),Ye=e=>(e.client??d).delete({security:[{scheme:"bearer",type:"http"}],url:"/keys/{key}/configs/{config}",...e}),Ze=e=>(e.client??d).get({url:"/keys/{key}/configs/{config}",...e}),er=e=>(e.client??d).post({security:[{scheme:"bearer",type:"http"}],url:"/keys/{key}/configs/{config}",...e,headers:{"Content-Type":"application/json",...e.headers}}),rr=e=>(e.client??d).get({security:[{scheme:"bearer",type:"http"}],url:"/emails",...e}),tr=e=>(e.client??d).get({security:[{scheme:"bearer",type:"http"}],url:"/phone_numbers",...e});export{k as a,K as b,d as c,Pe as d,ve as e,je as f,Le as g,Ue as h,Ie as i,Ke as j,Be as k,Ne as l,$e as m,Ve as n,He as o,Fe as p,We as q,Qe as r,Me as s,Je as t,_e as u,Ge as v,Xe as w,Ye as x,Ze as y,er as z,rr as A,tr as B};
@@ -0,0 +1 @@
1
+ var E=class{constructor(e={}){this.map=new Map,this.max=e.max??50,this.ttlMs=e.ttlMs??6e4}get(e){let t=this.map.get(e);if(t){if(t.expiresAt<=Date.now()){this.map.delete(e);return}return this.map.delete(e),this.map.set(e,t),t.value}}set(e,t){if(this.map.has(e))this.map.delete(e);else if(this.map.size>=this.max){let r=this.map.keys().next().value;r!==void 0&&this.map.delete(r)}this.map.set(e,{value:t,expiresAt:Date.now()+this.ttlMs})}delete(e){return this.map.delete(e)}clear(){this.map.clear()}get size(){return this.map.size}},d=(e,t)=>e<t?-1:e>t?1:0,p=e=>e instanceof Map||typeof Headers<"u"&&e instanceof Headers||typeof URLSearchParams<"u"&&e instanceof URLSearchParams,T=e=>{let t=new Set,r=n=>{if(n===null||typeof n!="object")return n;if(t.has(n))return null;t.add(n);try{return o(n)}finally{t.delete(n)}},o=n=>{if(Array.isArray(n))return n.map(r);if(p(n))return Array.from(n.entries(),([i,u])=>[r(i),r(u)]).map(i=>[JSON.stringify(i),i]).sort(([i],[u])=>d(i,u)).map(([,i])=>i);let a=Object.entries(n).filter(([,i])=>i!==void 0).sort(([i],[u])=>d(i,u));return Object.fromEntries(a.map(([i,u])=>[i,r(u)]))};return JSON.stringify(r(e))},y=e=>new DOMException(e,"AbortError"),O=(e,t)=>{let r=null,o=null,n=null,a=u=>{r!==null&&(clearTimeout(r),r=null),o?.abort(y(u)),o=null,n?.(void 0),n=null},i=((...u)=>new Promise((f,m)=>{a("debounced call superseded"),n=f;let l=new AbortController;o=l;let v=()=>l.signal.aborted?!1:(o=null,n=null,!0);r=setTimeout(()=>{r=null,e(l.signal,...u).then(s=>v()&&f(s),s=>v()&&m(s))},t)}));return i.cancel=()=>a("debounced call cancelled"),i},c="/keys/{key}",g=["GET /details","PUT /details","GET /usage","GET /lookups","GET /licensees","POST /licensees","GET /licensees/{licensee}","DELETE /licensees/{licensee}","POST /licensees/{licensee}","POST /licensees/{licensee}/regenerate-key","GET /configs","POST /configs","DELETE /configs/{config}","POST /configs/{config}"],h=e=>e===c||e.startsWith(`${c}/`),w=(e,t)=>h(t)&&g.includes(`${e} ${t.slice(c.length)}`),A=(e,t,r)=>{let o=new URL(e.url);!h(t)&&!o.searchParams.has("api_key")&&o.searchParams.set("api_key",r.apiKey);let n=new Request(o,e);return!r.userToken||!w(e.method,t)||o.searchParams.has("user_token")||n.headers.has("Authorization")||n.headers.set("Authorization",`user_token="${r.userToken}"`),n},_=class extends Error{constructor(e,t){let{code:r,message:o}=typeof t=="object"&&t!==null?t:{};super(typeof o=="string"?o:e.statusText||`HTTP ${e.status}`),this.name="ApiError",this.status=e.status,typeof r=="number"&&(this.code=r),this.body=t,this.response=e}},S=(e,t,r,o)=>t&&!t.ok&&!(e instanceof Error)&&o?.throwOnError!==!1?new _(t,e):e;export{E as a,T as b,O as c,A as d,_ as e,S as f};
@@ -0,0 +1 @@
1
+ var t=e=>(...n)=>({...e(...n),gcTime:0,staleTime:0});export{t as a};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var t=e=>(...n)=>({...e(...n),gcTime:0,staleTime:0});exports.a = t;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var E=class{constructor(e={}){this.map=new Map,this.max=_nullishCoalesce(e.max, () => (50)),this.ttlMs=_nullishCoalesce(e.ttlMs, () => (6e4))}get(e){let t=this.map.get(e);if(t){if(t.expiresAt<=Date.now()){this.map.delete(e);return}return this.map.delete(e),this.map.set(e,t),t.value}}set(e,t){if(this.map.has(e))this.map.delete(e);else if(this.map.size>=this.max){let r=this.map.keys().next().value;r!==void 0&&this.map.delete(r)}this.map.set(e,{value:t,expiresAt:Date.now()+this.ttlMs})}delete(e){return this.map.delete(e)}clear(){this.map.clear()}get size(){return this.map.size}},d=(e,t)=>e<t?-1:e>t?1:0,p=e=>e instanceof Map||typeof Headers<"u"&&e instanceof Headers||typeof URLSearchParams<"u"&&e instanceof URLSearchParams,T= exports.b =e=>{let t=new Set,r=n=>{if(n===null||typeof n!="object")return n;if(t.has(n))return null;t.add(n);try{return o(n)}finally{t.delete(n)}},o=n=>{if(Array.isArray(n))return n.map(r);if(p(n))return Array.from(n.entries(),([i,u])=>[r(i),r(u)]).map(i=>[JSON.stringify(i),i]).sort(([i],[u])=>d(i,u)).map(([,i])=>i);let a=Object.entries(n).filter(([,i])=>i!==void 0).sort(([i],[u])=>d(i,u));return Object.fromEntries(a.map(([i,u])=>[i,r(u)]))};return JSON.stringify(r(e))},y=e=>new DOMException(e,"AbortError"),O= exports.c =(e,t)=>{let r=null,o=null,n=null,a=u=>{r!==null&&(clearTimeout(r),r=null),_optionalChain([o, 'optionalAccess', _2 => _2.abort, 'call', _3 => _3(y(u))]),o=null,_optionalChain([n, 'optionalCall', _4 => _4(void 0)]),n=null},i=((...u)=>new Promise((f,m)=>{a("debounced call superseded"),n=f;let l=new AbortController;o=l;let v=()=>l.signal.aborted?!1:(o=null,n=null,!0);r=setTimeout(()=>{r=null,e(l.signal,...u).then(s=>v()&&f(s),s=>v()&&m(s))},t)}));return i.cancel=()=>a("debounced call cancelled"),i},c="/keys/{key}",g=["GET /details","PUT /details","GET /usage","GET /lookups","GET /licensees","POST /licensees","GET /licensees/{licensee}","DELETE /licensees/{licensee}","POST /licensees/{licensee}","POST /licensees/{licensee}/regenerate-key","GET /configs","POST /configs","DELETE /configs/{config}","POST /configs/{config}"],h=e=>e===c||e.startsWith(`${c}/`),w=(e,t)=>h(t)&&g.includes(`${e} ${t.slice(c.length)}`),A= exports.d =(e,t,r)=>{let o=new URL(e.url);!h(t)&&!o.searchParams.has("api_key")&&o.searchParams.set("api_key",r.apiKey);let n=new Request(o,e);return!r.userToken||!w(e.method,t)||o.searchParams.has("user_token")||n.headers.has("Authorization")||n.headers.set("Authorization",`user_token="${r.userToken}"`),n},_= exports.e =class extends Error{constructor(e,t){let{code:r,message:o}=typeof t=="object"&&t!==null?t:{};super(typeof o=="string"?o:e.statusText||`HTTP ${e.status}`),this.name="ApiError",this.status=e.status,typeof r=="number"&&(this.code=r),this.body=t,this.response=e}},S= exports.f =(e,t,r,o)=>t&&!t.ok&&!(e instanceof Error)&&_optionalChain([o, 'optionalAccess', _5 => _5.throwOnError])!==!1?new _(t,e):e;exports.a = E; exports.b = T; exports.c = O; exports.d = A; exports.e = _; exports.f = S;
@@ -0,0 +1,6 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var F={bodySerializer:e=>JSON.stringify(e,(r,t)=>typeof t=="bigint"?t.toString():t)};function W({onRequest:e,onSseError:r,onSseEvent:t,responseTransformer:n,responseValidator:i,sseDefaultRetryDelay:l,sseMaxRetryAttempts:o,sseMaxRetryDelay:s,sseSleepFn:a,url:O,...p}){let c,R=_nullishCoalesce(a, () => ((u=>new Promise(f=>setTimeout(f,u)))));return{stream:async function*(){let u=_nullishCoalesce(l, () => (3e3)),f=0,b=_nullishCoalesce(p.signal, () => (new AbortController().signal));for(;!b.aborted;){f++;let A=p.headers instanceof Headers?p.headers:new Headers(p.headers);c!==void 0&&A.set("Last-Event-ID",c);try{let T={redirect:"follow",...p,body:p.serializedBody,headers:A,signal:b},x=new Request(O,T);e&&(x=await e(O,T));let h=await(_nullishCoalesce(p.fetch, () => (globalThis.fetch)))(x);if(!h.ok)throw new Error(`SSE failed: ${h.status} ${h.statusText}`);if(!h.body)throw new Error("No body in SSE response");let E=h.body.pipeThrough(new TextDecoderStream).getReader(),g="",B=()=>{try{E.cancel()}catch (e2){}};b.addEventListener("abort",B);try{for(;;){let{done:Y,value:Z}=await E.read();if(Y)break;g+=Z,g=g.replace(/\r\n?/g,`
2
+ `);let N=g.split(`
3
+
4
+ `);g=_nullishCoalesce(N.pop(), () => (""));for(let ee of N){let re=ee.split(`
5
+ `),z=[],$;for(let w of re)if(w.startsWith("data:"))z.push(w.replace(/^data:\s*/,""));else if(w.startsWith("event:"))$=w.replace(/^event:\s*/,"");else if(w.startsWith("id:"))c=w.replace(/^id:\s*/,"");else if(w.startsWith("retry:")){let H=Number.parseInt(w.replace(/^retry:\s*/,""),10);Number.isNaN(H)||(u=H)}let S,V=!1;if(z.length){let w=z.join(`
6
+ `);try{S=JSON.parse(w),V=!0}catch (e3){S=w}}V&&(i&&await i(S),n&&(S=await n(S))),_optionalChain([t, 'optionalCall', _2 => _2({data:S,event:$,id:c,retry:u})]),z.length&&(yield S)}}}finally{b.removeEventListener("abort",B),E.releaseLock()}break}catch(T){if(_optionalChain([r, 'optionalCall', _3 => _3(T)]),o!==void 0&&f>=o)break;let x=Math.min(u*2**(f-1),_nullishCoalesce(s, () => (3e4)));await R(x)}}}()}}var te=e=>{switch(e){case"label":return".";case"matrix":return";";case"simple":return",";default:return"&"}},se=e=>{switch(e){case"form":return",";case"pipeDelimited":return"|";case"spaceDelimited":return"%20";default:return","}},ne=e=>{switch(e){case"label":return".";case"matrix":return";";case"simple":return",";default:return"&"}},q=({allowReserved:e,explode:r,name:t,style:n,value:i})=>{if(!r){let s=(e?i:i.map(a=>encodeURIComponent(a))).join(se(n));switch(n){case"label":return`.${s}`;case"matrix":return`;${t}=${s}`;case"simple":return s;default:return`${t}=${s}`}}let l=te(n),o=i.map(s=>n==="label"||n==="simple"?e?s:encodeURIComponent(s):C({allowReserved:e,name:t,value:s})).join(l);return n==="label"||n==="matrix"?l+o:o},C=({allowReserved:e,name:r,value:t})=>{if(t==null)return"";if(typeof t=="object")throw new Error("Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these.");return`${r}=${e?t:encodeURIComponent(t)}`},P=({allowReserved:e,explode:r,name:t,style:n,value:i,valueOnly:l})=>{if(i instanceof Date)return l?i.toISOString():`${t}=${i.toISOString()}`;if(n!=="deepObject"&&!r){let a=[];Object.entries(i).forEach(([p,c])=>{a=[...a,p,e?c:encodeURIComponent(c)]});let O=a.join(",");switch(n){case"form":return`${t}=${O}`;case"label":return`.${O}`;case"matrix":return`;${t}=${O}`;default:return O}}let o=ne(n),s=Object.entries(i).map(([a,O])=>C({allowReserved:e,name:n==="deepObject"?`${t}[${a}]`:a,value:O})).join(o);return n==="label"||n==="matrix"?o+s:s};var oe=/\{[^{}]+\}/g,ae=({path:e,url:r})=>{let t=r,n=r.match(oe);if(n)for(let i of n){let l=!1,o=i.substring(1,i.length-1),s="simple";o.endsWith("*")&&(l=!0,o=o.substring(0,o.length-1)),o.startsWith(".")?(o=o.substring(1),s="label"):o.startsWith(";")&&(o=o.substring(1),s="matrix");let a=e[o];if(a==null)continue;if(Array.isArray(a)){t=t.replace(i,q({explode:l,name:o,style:s,value:a}));continue}if(typeof a=="object"){t=t.replace(i,P({explode:l,name:o,style:s,value:a,valueOnly:!0}));continue}if(s==="matrix"){t=t.replace(i,`;${C({name:o,value:a})}`);continue}let O=encodeURIComponent(s==="label"?`.${a}`:a);t=t.replace(i,O)}return t},Q=({baseUrl:e,path:r,query:t,querySerializer:n,url:i})=>{let l=i.startsWith("/")?i:`/${i}`,o=(_nullishCoalesce(e, () => ("")))+l;r&&(o=ae({path:r,url:o}));let s=t?n(t):"";return s.startsWith("?")&&(s=s.substring(1)),s&&(o+=`?${s}`),o};function L(e){let r=e.body!==void 0;if(r&&e.bodySerializer)return"serializedBody"in e?e.serializedBody!==void 0&&e.serializedBody!==""?e.serializedBody:null:e.body!==""?e.body:null;if(r)return e.body}var M=async(e,r)=>{let t=typeof r=="function"?await r(e):r;if(t)return e.scheme==="bearer"?`Bearer ${t}`:e.scheme==="basic"?`Basic ${btoa(t)}`:t};var J=({parameters:e={},...r}={})=>n=>{let i=[];if(n&&typeof n=="object")for(let l in n){let o=n[l];if(o==null)continue;let s=e[l]||r;if(Array.isArray(o)){let a=q({allowReserved:s.allowReserved,explode:!0,name:l,style:"form",value:o,...s.array});a&&i.push(a)}else if(typeof o=="object"){let a=P({allowReserved:s.allowReserved,explode:!0,name:l,style:"deepObject",value:o,...s.object});a&&i.push(a)}else{let a=C({allowReserved:s.allowReserved,name:l,value:o});a&&i.push(a)}}return i.join("&")},_=e=>{if(!e)return"stream";let r=_optionalChain([e, 'access', _4 => _4.split, 'call', _5 => _5(";"), 'access', _6 => _6[0], 'optionalAccess', _7 => _7.trim, 'call', _8 => _8()]);if(r){if(r.startsWith("application/json")||r.endsWith("+json"))return"json";if(r==="multipart/form-data")return"formData";if(["application/","audio/","image/","video/"].some(t=>r.startsWith(t)))return"blob";if(r.startsWith("text/"))return"text"}},ie=(e,r)=>r?!!(e.headers.has(r)||_optionalChain([e, 'access', _9 => _9.query, 'optionalAccess', _10 => _10[r]])||_optionalChain([e, 'access', _11 => _11.headers, 'access', _12 => _12.get, 'call', _13 => _13("Cookie"), 'optionalAccess', _14 => _14.includes, 'call', _15 => _15(`${r}=`)])):!1;async function G(e){for(let r of _nullishCoalesce(e.security, () => ([]))){if(ie(e,r.name))continue;let t=await M(r,e.auth);if(!t)continue;let n=_nullishCoalesce(r.name, () => ("Authorization"));switch(r.in){case"query":e.query||(e.query={}),e.query[n]=t;break;case"cookie":e.headers.append("Cookie",`${n}=${t}`);break;default:e.headers.set(n,t);break}}}var U=e=>Q({baseUrl:e.baseUrl,path:e.path,query:e.query,querySerializer:typeof e.querySerializer=="function"?e.querySerializer:J(e.querySerializer),url:e.url}),I=(e,r)=>{let t={...e,...r};return _optionalChain([t, 'access', _16 => _16.baseUrl, 'optionalAccess', _17 => _17.endsWith, 'call', _18 => _18("/")])&&(t.baseUrl=t.baseUrl.substring(0,t.baseUrl.length-1)),t.headers=v(e.headers,r.headers),t},le=e=>{let r=[];return e.forEach((t,n)=>{r.push([n,t])}),r},v=(...e)=>{let r=new Headers;for(let t of e){if(!t)continue;let n=t instanceof Headers?le(t):Object.entries(t);for(let[i,l]of n)if(l===null)r.delete(i);else if(Array.isArray(l))for(let o of l)r.append(i,o);else l!==void 0&&r.set(i,typeof l=="object"?JSON.stringify(l):l)}return r},D=class{constructor(){this.fns=[]}clear(){this.fns=[]}eject(r){let t=this.getInterceptorIndex(r);this.fns[t]&&(this.fns[t]=null)}exists(r){let t=this.getInterceptorIndex(r);return!!this.fns[t]}getInterceptorIndex(r){return typeof r=="number"?this.fns[r]?r:-1:this.fns.indexOf(r)}update(r,t){let n=this.getInterceptorIndex(r);return this.fns[n]?(this.fns[n]=t,r):!1}use(r){return this.fns.push(r),this.fns.length-1}},X=()=>({error:new D,request:new D,response:new D}),ce=J({allowReserved:!1,array:{explode:!0,style:"form"},object:{explode:!0,style:"deepObject"}}),pe={"Content-Type":"application/json"},k= exports.a =(e={})=>({...F,headers:pe,parseAs:"auto",querySerializer:ce,...e});var K=(e={})=>{let r=I(k(),e),t=()=>({...r}),n=p=>(r=I(r,p),t()),i=X(),l=async p=>{let c={...r,...p,fetch:_nullishCoalesce(_nullishCoalesce(p.fetch, () => (r.fetch)), () => (globalThis.fetch)),headers:v(r.headers,p.headers),serializedBody:void 0};c.security&&await G(c),c.requestValidator&&await c.requestValidator(c),c.body!==void 0&&c.bodySerializer&&(c.serializedBody=c.bodySerializer(c.body)),(c.body===void 0||c.serializedBody==="")&&c.headers.delete("Content-Type");let R=c,m=U(R);return{opts:R,url:m}},o=async p=>{let c=_nullishCoalesce(p.throwOnError, () => (r.throwOnError)),R=_nullishCoalesce(p.responseStyle, () => (r.responseStyle)),m,y;try{let{opts:u,url:f}=await l(p),b={redirect:"follow",...u,body:L(u)};m=new Request(f,b);for(let h of i.request.fns)h&&(m=await h(m,u));let A=u.fetch;y=await A(m);for(let h of i.response.fns)h&&(y=await h(y,m,u));let T={request:m,response:y};if(y.ok){let h=_nullishCoalesce((u.parseAs==="auto"?_(y.headers.get("Content-Type")):u.parseAs), () => ("json"));if(y.status===204||y.headers.get("Content-Length")==="0"){let g;switch(h){case"arrayBuffer":case"blob":case"text":g=await y[h]();break;case"formData":g=new FormData;break;case"stream":g=y.body;break;default:g={};break}return u.responseStyle==="data"?g:{data:g,...T}}let E;switch(h){case"arrayBuffer":case"blob":case"formData":case"text":E=await y[h]();break;case"json":{let g=await y.text();E=g?JSON.parse(g):{};break}case"stream":return u.responseStyle==="data"?y.body:{data:y.body,...T}}return h==="json"&&(u.responseValidator&&await u.responseValidator(E),u.responseTransformer&&(E=await u.responseTransformer(E))),u.responseStyle==="data"?E:{data:E,...T}}let x=await y.text(),j;try{j=JSON.parse(x)}catch (e4){}throw _nullishCoalesce(j, () => (x))}catch(u){let f=u;for(let b of i.error.fns)b&&(f=await b(f,y,m,p));if(f=f||{},c)throw f;return R==="data"?void 0:{error:f,request:m,response:y}}},s=p=>c=>o({...c,method:p}),a=p=>async c=>{let{opts:R,url:m}=await l(c);return W({...R,body:R.body,method:p,onRequest:async(y,u)=>{let f=new Request(y,u);for(let b of i.request.fns)b&&(f=await b(f,R));return f},serializedBody:L(R),url:m})};return{buildUrl:p=>U({...r,...p}),connect:s("CONNECT"),delete:s("DELETE"),get:s("GET"),getConfig:t,head:s("HEAD"),interceptors:i,options:s("OPTIONS"),patch:s("PATCH"),post:s("POST"),put:s("PUT"),request:o,setConfig:n,sse:{connect:a("CONNECT"),delete:a("DELETE"),get:a("GET"),head:a("HEAD"),options:a("OPTIONS"),patch:a("PATCH"),post:a("POST"),put:a("PUT"),trace:a("TRACE")},trace:s("TRACE")}};var d=K(k({baseUrl:"https://api.ideal-postcodes.co.uk/v1",throwOnError:!0}));var Pe=e=>(_nullishCoalesce(e.client, () => (d))).get({querySerializer:{parameters:{dataset:{array:{explode:!1}}}},security:[{scheme:"bearer",type:"http"}],url:"/postcodes/{postcode}",...e}),ve= exports.e =e=>(_nullishCoalesce(e.client, () => (d))).get({url:"/keys/{key}",...e}),je= exports.f =e=>(_nullishCoalesce(e.client, () => (d))).get({security:[{scheme:"bearer",type:"http"}],url:"/keys/{key}/details",...e}),Le= exports.g =e=>(_nullishCoalesce(e.client, () => (d))).put({security:[{scheme:"bearer",type:"http"}],url:"/keys/{key}/details",...e,headers:{"Content-Type":"application/json",...e.headers}}),Ue= exports.h =e=>(_nullishCoalesce(e.client, () => (d))).get({security:[{scheme:"bearer",type:"http"}],url:"/keys/{key}/usage",...e}),Ie= exports.i =e=>(_nullishCoalesce(e.client, () => (d))).get({security:[{scheme:"bearer",type:"http"}],url:"/keys/{key}/lookups",...e}),Ke= exports.j =e=>(_nullishCoalesce(e.client, () => (d))).post({security:[{scheme:"bearer",type:"http"}],url:"/cleanse/addresses",...e,headers:{"Content-Type":"application/json",...e.headers}}),Be= exports.k =e=>(_nullishCoalesce(_optionalChain([e, 'optionalAccess', _19 => _19.client]), () => (d))).get({querySerializer:{parameters:{dataset:{array:{explode:!1}}}},security:[{scheme:"bearer",type:"http"}],url:"/autocomplete/addresses",...e}),Ne= exports.l =e=>(_nullishCoalesce(e.client, () => (d))).get({security:[{scheme:"bearer",type:"http"}],url:"/autocomplete/addresses/{address}/gbr",...e}),$e= exports.m =e=>(_nullishCoalesce(_optionalChain([e, 'optionalAccess', _20 => _20.client]), () => (d))).get({querySerializer:{parameters:{dataset:{array:{explode:!1}}}},security:[{scheme:"bearer",type:"http"}],url:"/addresses",...e}),Ve= exports.n =e=>(_nullishCoalesce(_optionalChain([e, 'optionalAccess', _21 => _21.client]), () => (d))).get({security:[{scheme:"bearer",type:"http"}],url:"/places",...e}),He= exports.o =e=>(_nullishCoalesce(e.client, () => (d))).get({security:[{scheme:"bearer",type:"http"}],url:"/places/{place}",...e}),Fe= exports.p =e=>(_nullishCoalesce(e.client, () => (d))).get({security:[{scheme:"bearer",type:"http"}],url:"/keys/{key}/licensees",...e}),We= exports.q =e=>(_nullishCoalesce(e.client, () => (d))).post({security:[{scheme:"bearer",type:"http"}],url:"/keys/{key}/licensees",...e,headers:{"Content-Type":"application/json",...e.headers}}),Qe= exports.r =e=>(_nullishCoalesce(e.client, () => (d))).delete({security:[{scheme:"bearer",type:"http"}],url:"/keys/{key}/licensees/{licensee}",...e}),Me= exports.s =e=>(_nullishCoalesce(e.client, () => (d))).get({security:[{scheme:"bearer",type:"http"}],url:"/keys/{key}/licensees/{licensee}",...e}),Je= exports.t =e=>(_nullishCoalesce(e.client, () => (d))).post({security:[{scheme:"bearer",type:"http"}],url:"/keys/{key}/licensees/{licensee}",...e,headers:{"Content-Type":"application/json",...e.headers}}),_e= exports.u =e=>(_nullishCoalesce(e.client, () => (d))).post({security:[{scheme:"bearer",type:"http"}],url:"/keys/{key}/licensees/{licensee}/regenerate-key",...e}),Ge= exports.v =e=>(_nullishCoalesce(e.client, () => (d))).get({security:[{scheme:"bearer",type:"http"}],url:"/keys/{key}/configs",...e}),Xe= exports.w =e=>(_nullishCoalesce(e.client, () => (d))).post({security:[{scheme:"bearer",type:"http"}],url:"/keys/{key}/configs",...e,headers:{"Content-Type":"application/json",...e.headers}}),Ye= exports.x =e=>(_nullishCoalesce(e.client, () => (d))).delete({security:[{scheme:"bearer",type:"http"}],url:"/keys/{key}/configs/{config}",...e}),Ze= exports.y =e=>(_nullishCoalesce(e.client, () => (d))).get({url:"/keys/{key}/configs/{config}",...e}),er= exports.z =e=>(_nullishCoalesce(e.client, () => (d))).post({security:[{scheme:"bearer",type:"http"}],url:"/keys/{key}/configs/{config}",...e,headers:{"Content-Type":"application/json",...e.headers}}),rr= exports.A =e=>(_nullishCoalesce(e.client, () => (d))).get({security:[{scheme:"bearer",type:"http"}],url:"/emails",...e}),tr= exports.B =e=>(_nullishCoalesce(e.client, () => (d))).get({security:[{scheme:"bearer",type:"http"}],url:"/phone_numbers",...e});exports.a = k; exports.b = K; exports.c = d; exports.d = Pe; exports.e = ve; exports.f = je; exports.g = Le; exports.h = Ue; exports.i = Ie; exports.j = Ke; exports.k = Be; exports.l = Ne; exports.m = $e; exports.n = Ve; exports.o = He; exports.p = Fe; exports.q = We; exports.r = Qe; exports.s = Me; exports.t = Je; exports.u = _e; exports.v = Ge; exports.w = Xe; exports.x = Ye; exports.y = Ze; exports.z = er; exports.A = rr; exports.B = tr;