@tileflow/search 0.0.0-bootstrap.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,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,107 @@
1
+ # `@tileflow/search`
2
+
3
+ Headless geocoding and location selection for Tileflow.
4
+
5
+ ```ts
6
+ import {geocode} from '@tileflow/search';
7
+
8
+ const response = await geocode(
9
+ {query: 'Rua Tileflow 42, Lisboa', language: 'en', retention: 'temporary'},
10
+ {apiKey: process.env.TILEFLOW_API_KEY!},
11
+ );
12
+
13
+ console.log(response.results);
14
+ ```
15
+
16
+ Reverse geocoding returns nearby addresses or geographic places:
17
+
18
+ ```ts
19
+ import {geocodeReverse} from '@tileflow/search';
20
+
21
+ const response = await geocodeReverse(
22
+ {
23
+ position: [-9.1393, 38.7223],
24
+ kinds: ['address', 'place'],
25
+ language: 'en',
26
+ retention: 'temporary',
27
+ },
28
+ {apiKey: process.env.TILEFLOW_API_KEY!},
29
+ );
30
+ ```
31
+
32
+ Location selection starts with suggestions and resolves one selected token:
33
+
34
+ ```ts
35
+ import {autocomplete, resolveSuggestion} from '@tileflow/search';
36
+
37
+ const suggestions = await autocomplete(
38
+ {query: 'Hospital La Paz', language: 'en'},
39
+ {apiKey: process.env.TILEFLOW_API_KEY!},
40
+ );
41
+
42
+ async function resolveUserSelection(token: string) {
43
+ const response = await resolveSuggestion(
44
+ {token, retention: 'temporary'},
45
+ {apiKey: process.env.TILEFLOW_API_KEY!},
46
+ );
47
+ console.log(response.result);
48
+ }
49
+ ```
50
+
51
+ Call `resolveUserSelection` only after an explicit user selection. The package provides no UI.
52
+
53
+ `geocode` and `geocodeReverse` each send one authenticated request to Tileflow and never retry
54
+ automatically. They validate strict requests and bounded normalized responses. Forward queries
55
+ contain at most 200 characters; `bounds` and `proximity` are mutually exclusive. Reverse positions
56
+ are `[longitude, latitude]` WGS84 coordinates. Reverse `limit` defaults to 1 and accepts 1–10.
57
+ Optional `kinds` are an OR filter containing 1–4 of `address`, `street`, `locality`, or `place`;
58
+ order adds no priority and repeated values have no additional effect. Provider selection and raw
59
+ provider options are not public.
60
+
61
+ `autocomplete` accepts the same text, language, `bounds`, and `proximity` rules as forward
62
+ geocoding. Its `limit` defaults to 5 and accepts 1–10. Suggestions are ephemeral opaque tokens;
63
+ they can expire, and an expired token requires fresh suggestions. Suggestions do not promise a
64
+ match for every named location and do not provide category or discovery queries. `autocomplete`
65
+ rejects `retention` and returns no usage record. Each completed `resolveSuggestion` returns one
66
+ existing result and `usage.units: 1`; replaying a resolution is another request and unit.
67
+
68
+ Applications may debounce autocomplete calls and cancel superseded calls or ignore stale results.
69
+ The client has no shared interaction state and never retries automatically. Do not expose
70
+ privileged credentials in browser code.
71
+
72
+ Reverse results are nearby candidates reasonably corresponding to the position, in provider order.
73
+ They do not guarantee containment, administrative membership, parcel or entrance precision,
74
+ routability, postal precision, or a validated or deliverable address. A successful empty result
75
+ still reports `usage.units: 1`.
76
+
77
+ Supply `fetch` and `apiUrl` for tests or a custom runtime, and pass an `AbortSignal` to control
78
+ cancellation. API URLs require HTTPS except for an explicit loopback HTTP origin used during local
79
+ development.
80
+
81
+ `retention` expresses whether the client intends to store results. It accepts `temporary` (the
82
+ default) or `persistent`. `temporary` permits immediate use without a right granted by Tileflow to
83
+ retain results permanently. `persistent` requests compatible storage rights for the client; it
84
+ neither requests nor promises Tileflow storage. Persistent retention is unavailable
85
+ for some territories. The API reports `GEOCODING_TERRITORY_UNSUPPORTED` with HTTP 422 when the
86
+ requested mode is unsupported, including AWS HERE-backed geocoding in Japan. This applies equally
87
+ to forward, reverse, and suggestion resolution. It does not apply to autocomplete. Retain only a
88
+ resolved candidate with its source and attribution; do not retain a suggestion token or label.
89
+
90
+ Geocoding requires an enabled Tileflow API environment and a Team key or signed Team capability
91
+ with `geocoding:read`; a disabled service returns `GEOCODING_DISABLED`. Each completed forward,
92
+ reverse, or suggestion resolution reports `usage.units: 1`. Forward and reverse also count empty
93
+ results. Autocomplete consumes zero units. These are usage units, not monetary prices.
94
+
95
+ Suggestion resolution can report `GEOCODING_INVALID_SUGGESTION` (400),
96
+ `GEOCODING_SUGGESTION_EXPIRED` (410), `GEOCODING_UPSTREAM_THROTTLED` (429), or
97
+ `GEOCODING_PICK_LIMIT_EXCEEDED` (429). The client never retries automatically.
98
+
99
+ Responses include source metadata and one or more attribution entries. Applications must pass every
100
+ entry through to end users or documentation and preserve any supplied URL as required by its source
101
+ terms. A source revision may be `null` when no reliable revision is available.
102
+
103
+ The package does not provide autocomplete UI, structured address input, category discovery,
104
+ batches, or address validation.
105
+
106
+ Use `@tileflow/search/contract` for the request and result schemas, or
107
+ `@tileflow/search/client` for transport without importing the root facade.
@@ -0,0 +1,165 @@
1
+ // src/contract.ts
2
+ import { z } from "zod";
3
+ var controlCharacterPattern = /\p{Cc}/u;
4
+ var languagePattern = /^[a-z]{2,3}(?:-[A-Za-z0-9]{2,8})*$/u;
5
+ var sourceReferencePattern = /^[A-Za-z0-9][A-Za-z0-9._:/-]{0,127}$/u;
6
+ var queryIdPattern = /^gq_[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/u;
7
+ var geocodingLimits = Object.freeze({
8
+ defaultLimit: 5,
9
+ defaultReverseLimit: 1,
10
+ maximumAddressPartCharacters: 256,
11
+ maximumAttributionEntries: 8,
12
+ maximumAttributionTextCharacters: 512,
13
+ maximumLanguageCharacters: 35,
14
+ maximumLimit: 10,
15
+ maximumQueryCharacters: 200,
16
+ maximumResponseBytes: 64 * 1024,
17
+ maximumSafeErrorBytes: 8 * 1024,
18
+ maximumSourceCharacters: 128,
19
+ maximumSuggestionTokenCharacters: 2048
20
+ });
21
+ var boundedText = (maximum) => z.string().trim().min(1).max(maximum).refine((value) => !controlCharacterPattern.test(value), {
22
+ message: "Control characters are not allowed"
23
+ });
24
+ var longitude = z.number().finite().min(-180).max(180);
25
+ var latitude = z.number().finite().min(-90).max(90);
26
+ var geocodingPositionSchema = z.tuple([longitude, latitude]);
27
+ var geocodingRetentionModes = ["temporary", "persistent"];
28
+ var geocodingBoundsSchema = z.tuple([longitude, latitude, longitude, latitude]).refine(([west, south, east]) => west < east, { message: "West must be less than east" }).refine(([, south, , north]) => south < north, {
29
+ message: "South must be less than north"
30
+ });
31
+ var geocodingForwardRequestSchema = z.object({
32
+ bounds: geocodingBoundsSchema.optional(),
33
+ language: z.string().max(geocodingLimits.maximumLanguageCharacters).regex(languagePattern).optional(),
34
+ limit: z.number().int().min(1).max(geocodingLimits.maximumLimit).optional(),
35
+ proximity: geocodingPositionSchema.optional(),
36
+ query: boundedText(geocodingLimits.maximumQueryCharacters),
37
+ retention: z.enum(geocodingRetentionModes).default("temporary")
38
+ }).strict().refine((request) => request.bounds === void 0 || request.proximity === void 0, {
39
+ message: "Bounds and proximity are mutually exclusive",
40
+ path: ["proximity"]
41
+ });
42
+ var autocompleteRequestSchema = z.object({
43
+ bounds: geocodingBoundsSchema.optional(),
44
+ language: z.string().max(geocodingLimits.maximumLanguageCharacters).regex(languagePattern).optional(),
45
+ limit: z.number().int().min(1).max(geocodingLimits.maximumLimit).default(geocodingLimits.defaultLimit),
46
+ proximity: geocodingPositionSchema.optional(),
47
+ query: boundedText(geocodingLimits.maximumQueryCharacters)
48
+ }).strict().refine((request) => request.bounds === void 0 || request.proximity === void 0, {
49
+ message: "Bounds and proximity are mutually exclusive",
50
+ path: ["proximity"]
51
+ });
52
+ var reverseGeocodingKindSchema = z.enum(["address", "street", "locality", "place"]);
53
+ var geocodingReverseRequestSchema = z.object({
54
+ kinds: z.array(reverseGeocodingKindSchema).min(1).max(4).optional(),
55
+ language: z.string().max(geocodingLimits.maximumLanguageCharacters).regex(languagePattern).optional(),
56
+ limit: z.number().int().min(1).max(geocodingLimits.maximumLimit).default(geocodingLimits.defaultReverseLimit),
57
+ position: geocodingPositionSchema,
58
+ retention: z.enum(geocodingRetentionModes).default("temporary")
59
+ }).strict();
60
+ var geocodingResultKinds = [
61
+ "address",
62
+ "street",
63
+ "locality",
64
+ "district",
65
+ "county",
66
+ "region",
67
+ "country",
68
+ "place",
69
+ "unknown"
70
+ ];
71
+ var addressPart = boundedText(geocodingLimits.maximumAddressPartCharacters);
72
+ var geocodingAddressSchema = z.object({
73
+ city: addressPart.optional(),
74
+ country: addressPart.optional(),
75
+ countryCode: z.string().regex(/^[A-Z]{2}$/u).optional(),
76
+ county: addressPart.optional(),
77
+ district: addressPart.optional(),
78
+ houseNumber: addressPart.optional(),
79
+ locality: addressPart.optional(),
80
+ name: addressPart.optional(),
81
+ postalCode: addressPart.optional(),
82
+ region: addressPart.optional(),
83
+ street: addressPart.optional()
84
+ }).strict();
85
+ var geocodingResultSchema = z.object({
86
+ address: geocodingAddressSchema,
87
+ bounds: geocodingBoundsSchema.optional(),
88
+ kind: z.enum(geocodingResultKinds),
89
+ label: boundedText(512),
90
+ position: geocodingPositionSchema,
91
+ sourceRef: z.string().regex(sourceReferencePattern).optional()
92
+ }).strict();
93
+ var geocodingSourceSchema = z.object({
94
+ id: boundedText(geocodingLimits.maximumSourceCharacters),
95
+ revision: boundedText(geocodingLimits.maximumSourceCharacters).nullable()
96
+ }).strict();
97
+ var geocodingAttributionSchema = z.object({
98
+ text: boundedText(geocodingLimits.maximumAttributionTextCharacters),
99
+ url: z.string().max(2048).refine((value) => !controlCharacterPattern.test(value), {
100
+ message: "Control characters are not allowed"
101
+ }).url().refine(isCredentialFreeHttpsUrl, {
102
+ message: "Expected an HTTPS URL without credentials"
103
+ }).optional()
104
+ }).strict();
105
+ var geocodingForwardResponseSchema = z.object({
106
+ attribution: z.array(geocodingAttributionSchema).min(1).max(geocodingLimits.maximumAttributionEntries),
107
+ queryId: z.string().regex(queryIdPattern),
108
+ results: z.array(geocodingResultSchema).max(geocodingLimits.maximumLimit),
109
+ schemaVersion: z.literal(1),
110
+ source: geocodingSourceSchema,
111
+ usage: z.object({ units: z.literal(1) }).strict()
112
+ }).strict();
113
+ var geocodingReverseResponseSchema = geocodingForwardResponseSchema;
114
+ var geocodingSuggestionSchema = z.object({
115
+ kind: z.enum(geocodingResultKinds),
116
+ label: boundedText(512),
117
+ token: z.string().min(1).max(geocodingLimits.maximumSuggestionTokenCharacters).regex(/^[\x21-\x7e]+$/u)
118
+ }).strict();
119
+ var autocompleteResponseSchema = z.object({
120
+ attribution: z.array(geocodingAttributionSchema).min(1).max(geocodingLimits.maximumAttributionEntries),
121
+ schemaVersion: z.literal(1),
122
+ source: geocodingSourceSchema,
123
+ suggestions: z.array(geocodingSuggestionSchema).max(geocodingLimits.maximumLimit)
124
+ }).strict();
125
+ var resolveSuggestionRequestSchema = z.object({
126
+ retention: z.enum(geocodingRetentionModes).default("temporary"),
127
+ token: z.string().min(1).max(geocodingLimits.maximumSuggestionTokenCharacters).regex(/^[\x21-\x7e]+$/u)
128
+ }).strict();
129
+ var resolveSuggestionResponseSchema = z.object({
130
+ attribution: z.array(geocodingAttributionSchema).min(1).max(geocodingLimits.maximumAttributionEntries),
131
+ result: geocodingResultSchema,
132
+ schemaVersion: z.literal(1),
133
+ source: geocodingSourceSchema,
134
+ usage: z.object({ units: z.literal(1) }).strict()
135
+ }).strict();
136
+ function isCredentialFreeHttpsUrl(value) {
137
+ try {
138
+ const url = new URL(value);
139
+ return url.protocol === "https:" && url.username === "" && url.password === "";
140
+ } catch {
141
+ return false;
142
+ }
143
+ }
144
+
145
+ export {
146
+ geocodingLimits,
147
+ geocodingPositionSchema,
148
+ geocodingRetentionModes,
149
+ geocodingBoundsSchema,
150
+ geocodingForwardRequestSchema,
151
+ autocompleteRequestSchema,
152
+ reverseGeocodingKindSchema,
153
+ geocodingReverseRequestSchema,
154
+ geocodingResultKinds,
155
+ geocodingAddressSchema,
156
+ geocodingResultSchema,
157
+ geocodingSourceSchema,
158
+ geocodingAttributionSchema,
159
+ geocodingForwardResponseSchema,
160
+ geocodingReverseResponseSchema,
161
+ geocodingSuggestionSchema,
162
+ autocompleteResponseSchema,
163
+ resolveSuggestionRequestSchema,
164
+ resolveSuggestionResponseSchema
165
+ };
@@ -0,0 +1,286 @@
1
+ import {
2
+ autocompleteRequestSchema,
3
+ autocompleteResponseSchema,
4
+ geocodingForwardRequestSchema,
5
+ geocodingForwardResponseSchema,
6
+ geocodingLimits,
7
+ geocodingReverseRequestSchema,
8
+ resolveSuggestionRequestSchema,
9
+ resolveSuggestionResponseSchema
10
+ } from "./chunk-EDYCZVXI.js";
11
+
12
+ // src/client.ts
13
+ import { z } from "zod";
14
+ var GEOCODING_ERROR_CODES = [
15
+ "GEOCODING_ABORTED",
16
+ "GEOCODING_DISABLED",
17
+ "GEOCODING_INVALID_REQUEST",
18
+ "GEOCODING_INVALID_SUGGESTION",
19
+ "GEOCODING_PICK_LIMIT_EXCEEDED",
20
+ "GEOCODING_QUOTA_EXCEEDED",
21
+ "GEOCODING_REQUEST_TOO_LARGE",
22
+ "GEOCODING_SUGGESTION_EXPIRED",
23
+ "GEOCODING_TERRITORY_UNSUPPORTED",
24
+ "GEOCODING_UNAVAILABLE",
25
+ "GEOCODING_UPSTREAM_INVALID",
26
+ "GEOCODING_UPSTREAM_THROTTLED",
27
+ "GEOCODING_UPSTREAM_TIMEOUT",
28
+ "GEOCODING_UPSTREAM_UNAVAILABLE",
29
+ "GEOCODING_USAGE_UNCONFIRMED"
30
+ ];
31
+ var geocodingErrorStatuses = {
32
+ GEOCODING_ABORTED: 499,
33
+ GEOCODING_DISABLED: 503,
34
+ GEOCODING_INVALID_REQUEST: 400,
35
+ GEOCODING_INVALID_SUGGESTION: 400,
36
+ GEOCODING_PICK_LIMIT_EXCEEDED: 429,
37
+ GEOCODING_QUOTA_EXCEEDED: 429,
38
+ GEOCODING_REQUEST_TOO_LARGE: 413,
39
+ GEOCODING_SUGGESTION_EXPIRED: 410,
40
+ GEOCODING_TERRITORY_UNSUPPORTED: 422,
41
+ GEOCODING_UNAVAILABLE: 503,
42
+ GEOCODING_UPSTREAM_INVALID: 502,
43
+ GEOCODING_UPSTREAM_THROTTLED: 429,
44
+ GEOCODING_UPSTREAM_TIMEOUT: 504,
45
+ GEOCODING_UPSTREAM_UNAVAILABLE: 502,
46
+ GEOCODING_USAGE_UNCONFIRMED: 503
47
+ };
48
+ var safeErrorText = z.string().trim().min(1).max(512).refine((value) => !/\p{Cc}/u.test(value));
49
+ var requestId = z.string().min(1).max(128).regex(/^[A-Za-z0-9][A-Za-z0-9._:-]*$/u);
50
+ var geocodingErrorResponseSchema = z.object({
51
+ code: z.enum(GEOCODING_ERROR_CODES),
52
+ error: safeErrorText,
53
+ requestId: requestId.optional()
54
+ }).strict();
55
+ var credentialErrorResponseSchema = z.object({
56
+ error: safeErrorText,
57
+ requestId: requestId.optional()
58
+ }).strict();
59
+ var GeocodingError = class extends Error {
60
+ code;
61
+ requestId;
62
+ status;
63
+ constructor(message, input) {
64
+ super(message);
65
+ this.name = "GeocodingError";
66
+ this.code = input.code ?? null;
67
+ this.requestId = input.requestId ?? null;
68
+ this.status = input.status;
69
+ }
70
+ };
71
+ async function geocode(request, options) {
72
+ const parsedRequest = geocodingForwardRequestSchema.safeParse(request);
73
+ if (!parsedRequest.success) {
74
+ throw new Error("Invalid Tileflow geocoding request");
75
+ }
76
+ return requestGeocoding(
77
+ "/v1/geocoding/forward",
78
+ parsedRequest.data,
79
+ options,
80
+ geocodingForwardResponseSchema,
81
+ (response) => response.results.length <= (parsedRequest.data.limit ?? geocodingLimits.defaultLimit)
82
+ );
83
+ }
84
+ async function geocodeReverse(request, options) {
85
+ const parsedRequest = geocodingReverseRequestSchema.safeParse(request);
86
+ if (!parsedRequest.success) {
87
+ throw new Error("Invalid Tileflow geocoding request");
88
+ }
89
+ return requestGeocoding(
90
+ "/v1/geocoding/reverse",
91
+ parsedRequest.data,
92
+ options,
93
+ geocodingForwardResponseSchema,
94
+ (response) => response.results.length <= parsedRequest.data.limit && containsOnlyKinds(response, parsedRequest.data.kinds)
95
+ );
96
+ }
97
+ async function autocomplete(request, options) {
98
+ const parsedRequest = autocompleteRequestSchema.safeParse(request);
99
+ if (!parsedRequest.success) {
100
+ throw new Error("Invalid Tileflow geocoding request");
101
+ }
102
+ return requestGeocoding(
103
+ "/v1/geocoding/autocomplete",
104
+ parsedRequest.data,
105
+ options,
106
+ autocompleteResponseSchema,
107
+ (response) => response.suggestions.length <= parsedRequest.data.limit
108
+ );
109
+ }
110
+ async function resolveSuggestion(request, options) {
111
+ const parsedRequest = resolveSuggestionRequestSchema.safeParse(request);
112
+ if (!parsedRequest.success) {
113
+ throw new Error("Invalid Tileflow geocoding request");
114
+ }
115
+ return requestGeocoding(
116
+ "/v1/geocoding/resolve-suggestion",
117
+ parsedRequest.data,
118
+ options,
119
+ resolveSuggestionResponseSchema
120
+ );
121
+ }
122
+ async function requestGeocoding(path, request, options, responseSchema, isExpectedResponse = () => true) {
123
+ const apiKey = normalizeApiKey(options.apiKey);
124
+ const apiUrl = normalizeApiUrl(options.apiUrl ?? "https://api.tileflow.dev");
125
+ const fetcher = options.fetch ?? fetch;
126
+ let response;
127
+ try {
128
+ response = await fetcher(`${apiUrl}${path}`, {
129
+ body: JSON.stringify(request),
130
+ headers: {
131
+ Accept: "application/json",
132
+ Authorization: `Bearer ${apiKey}`,
133
+ "Content-Type": "application/json"
134
+ },
135
+ method: "POST",
136
+ redirect: "error",
137
+ signal: options.signal
138
+ });
139
+ } catch (error) {
140
+ if (options.signal?.aborted) throw options.signal.reason ?? error;
141
+ throw new GeocodingError("Tileflow geocoding request failed", { status: 0 });
142
+ }
143
+ if (response.redirected) {
144
+ void response.body?.cancel().catch(() => void 0);
145
+ throw new GeocodingError("Tileflow geocoding request failed", { status: response.status });
146
+ }
147
+ if (!response.ok) {
148
+ throw await readGeocodingError(response, options.signal);
149
+ }
150
+ let body;
151
+ try {
152
+ body = await readBoundedJson(response, geocodingLimits.maximumResponseBytes, options.signal);
153
+ } catch (error) {
154
+ if (options.signal?.aborted) throw options.signal.reason ?? error;
155
+ throw new GeocodingError("Tileflow geocoding returned an invalid response", {
156
+ status: response.status
157
+ });
158
+ }
159
+ const parsedResponse = responseSchema.safeParse(body);
160
+ if (!parsedResponse.success || !isExpectedResponse(parsedResponse.data)) {
161
+ throw new GeocodingError("Tileflow geocoding returned an invalid response", {
162
+ status: response.status
163
+ });
164
+ }
165
+ return parsedResponse.data;
166
+ }
167
+ function containsOnlyKinds(response, allowedKinds) {
168
+ if (!allowedKinds) return true;
169
+ const kindFilter = new Set(allowedKinds);
170
+ return response.results.every(({ kind }) => kindFilter.has(kind));
171
+ }
172
+ function normalizeApiKey(value) {
173
+ if (typeof value !== "string" || value.length < 1 || value.length > 4096 || value !== value.trim() || /\p{Cc}/u.test(value)) {
174
+ throw new Error("Invalid Tileflow API key");
175
+ }
176
+ return value;
177
+ }
178
+ function normalizeApiUrl(value) {
179
+ let url;
180
+ try {
181
+ url = new URL(value);
182
+ } catch {
183
+ throw new Error("Invalid Tileflow API URL");
184
+ }
185
+ const loopback = ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname);
186
+ if (url.protocol !== "https:" && !(url.protocol === "http:" && loopback) || url.username !== "" || url.password !== "" || url.search !== "" || url.hash !== "") {
187
+ throw new Error("Invalid Tileflow API URL");
188
+ }
189
+ return url.href.replace(/\/$/u, "");
190
+ }
191
+ async function readGeocodingError(response, signal) {
192
+ let body;
193
+ try {
194
+ body = await readBoundedJson(response, geocodingLimits.maximumSafeErrorBytes, signal);
195
+ } catch (error) {
196
+ if (signal?.aborted) throw signal.reason ?? error;
197
+ return new GeocodingError("Tileflow geocoding request failed", { status: response.status });
198
+ }
199
+ const geocoding = geocodingErrorResponseSchema.safeParse(body);
200
+ if (geocoding.success && geocodingErrorStatuses[geocoding.data.code] === response.status) {
201
+ return new GeocodingError(geocoding.data.error, {
202
+ code: geocoding.data.code,
203
+ requestId: geocoding.data.requestId,
204
+ status: response.status
205
+ });
206
+ }
207
+ const credential = credentialErrorResponseSchema.safeParse(body);
208
+ if (credential.success && [401, 403, 429].includes(response.status)) {
209
+ return new GeocodingError(credential.data.error, {
210
+ requestId: credential.data.requestId,
211
+ status: response.status
212
+ });
213
+ }
214
+ return new GeocodingError("Tileflow geocoding request failed", { status: response.status });
215
+ }
216
+ async function readBoundedJson(response, maximumBytes, signal) {
217
+ const declaredLength = response.headers.get("Content-Length");
218
+ if (declaredLength && /^\d+$/u.test(declaredLength) && Number(declaredLength) > maximumBytes) {
219
+ void response.body?.cancel().catch(() => void 0);
220
+ throw new Error("Tileflow geocoding response is too large");
221
+ }
222
+ if (!response.body) throw new Error("Tileflow geocoding response is empty");
223
+ if (signal?.aborted) {
224
+ void response.body.cancel(signal.reason).catch(() => void 0);
225
+ throw signal.reason ?? new Error("Tileflow geocoding request was aborted");
226
+ }
227
+ const reader = response.body.getReader();
228
+ const chunks = [];
229
+ let byteLength = 0;
230
+ try {
231
+ while (true) {
232
+ const { done, value } = await readResponseChunk(reader, signal);
233
+ if (done) break;
234
+ byteLength += value.byteLength;
235
+ if (byteLength > maximumBytes) {
236
+ void reader.cancel().catch(() => void 0);
237
+ throw new Error("Tileflow geocoding response is too large");
238
+ }
239
+ chunks.push(value);
240
+ }
241
+ } finally {
242
+ reader.releaseLock();
243
+ }
244
+ const bytes = new Uint8Array(byteLength);
245
+ let offset = 0;
246
+ for (const chunk of chunks) {
247
+ bytes.set(chunk, offset);
248
+ offset += chunk.byteLength;
249
+ }
250
+ let source;
251
+ try {
252
+ source = new TextDecoder("utf-8", { fatal: true }).decode(bytes);
253
+ } catch {
254
+ throw new Error("Tileflow geocoding response is not UTF-8");
255
+ }
256
+ return JSON.parse(source);
257
+ }
258
+ async function readResponseChunk(reader, signal) {
259
+ if (!signal) return reader.read();
260
+ let aborted = false;
261
+ const abort = () => {
262
+ aborted = true;
263
+ void reader.cancel(signal.reason).catch(() => void 0);
264
+ };
265
+ if (signal.aborted) abort();
266
+ else signal.addEventListener("abort", abort, { once: true });
267
+ try {
268
+ const chunk = await reader.read();
269
+ if (aborted) throw signal.reason ?? new Error("Tileflow geocoding request was aborted");
270
+ return chunk;
271
+ } catch (error) {
272
+ if (aborted) throw signal.reason ?? error;
273
+ throw error;
274
+ } finally {
275
+ signal.removeEventListener("abort", abort);
276
+ }
277
+ }
278
+
279
+ export {
280
+ GEOCODING_ERROR_CODES,
281
+ GeocodingError,
282
+ geocode,
283
+ geocodeReverse,
284
+ autocomplete,
285
+ resolveSuggestion
286
+ };
@@ -0,0 +1,27 @@
1
+ import { AutocompleteRequest, AutocompleteResponse, GeocodingForwardRequest, GeocodingForwardResponse, GeocodingReverseRequest, GeocodingReverseResponse, ResolveSuggestionRequest, ResolveSuggestionResponse } from './contract.js';
2
+ import 'zod';
3
+
4
+ declare const GEOCODING_ERROR_CODES: readonly ["GEOCODING_ABORTED", "GEOCODING_DISABLED", "GEOCODING_INVALID_REQUEST", "GEOCODING_INVALID_SUGGESTION", "GEOCODING_PICK_LIMIT_EXCEEDED", "GEOCODING_QUOTA_EXCEEDED", "GEOCODING_REQUEST_TOO_LARGE", "GEOCODING_SUGGESTION_EXPIRED", "GEOCODING_TERRITORY_UNSUPPORTED", "GEOCODING_UNAVAILABLE", "GEOCODING_UPSTREAM_INVALID", "GEOCODING_UPSTREAM_THROTTLED", "GEOCODING_UPSTREAM_TIMEOUT", "GEOCODING_UPSTREAM_UNAVAILABLE", "GEOCODING_USAGE_UNCONFIRMED"];
5
+ type GeocodingErrorCode = (typeof GEOCODING_ERROR_CODES)[number];
6
+ type GeocodeOptions = Readonly<{
7
+ apiKey: string;
8
+ apiUrl?: string;
9
+ fetch?: typeof fetch;
10
+ signal?: AbortSignal;
11
+ }>;
12
+ declare class GeocodingError extends Error {
13
+ readonly code: GeocodingErrorCode | null;
14
+ readonly requestId: string | null;
15
+ readonly status: number;
16
+ constructor(message: string, input: {
17
+ code?: GeocodingErrorCode;
18
+ requestId?: string;
19
+ status: number;
20
+ });
21
+ }
22
+ declare function geocode(request: GeocodingForwardRequest, options: GeocodeOptions): Promise<GeocodingForwardResponse>;
23
+ declare function geocodeReverse(request: GeocodingReverseRequest, options: GeocodeOptions): Promise<GeocodingReverseResponse>;
24
+ declare function autocomplete(request: AutocompleteRequest, options: GeocodeOptions): Promise<AutocompleteResponse>;
25
+ declare function resolveSuggestion(request: ResolveSuggestionRequest, options: GeocodeOptions): Promise<ResolveSuggestionResponse>;
26
+
27
+ export { GEOCODING_ERROR_CODES, type GeocodeOptions, GeocodingError, type GeocodingErrorCode, autocomplete, geocode, geocodeReverse, resolveSuggestion };
package/dist/client.js ADDED
@@ -0,0 +1,17 @@
1
+ import {
2
+ GEOCODING_ERROR_CODES,
3
+ GeocodingError,
4
+ autocomplete,
5
+ geocode,
6
+ geocodeReverse,
7
+ resolveSuggestion
8
+ } from "./chunk-YMLUPVQH.js";
9
+ import "./chunk-EDYCZVXI.js";
10
+ export {
11
+ GEOCODING_ERROR_CODES,
12
+ GeocodingError,
13
+ autocomplete,
14
+ geocode,
15
+ geocodeReverse,
16
+ resolveSuggestion
17
+ };
@@ -0,0 +1,309 @@
1
+ import { z } from 'zod';
2
+
3
+ declare const geocodingLimits: Readonly<{
4
+ defaultLimit: 5;
5
+ defaultReverseLimit: 1;
6
+ maximumAddressPartCharacters: 256;
7
+ maximumAttributionEntries: 8;
8
+ maximumAttributionTextCharacters: 512;
9
+ maximumLanguageCharacters: 35;
10
+ maximumLimit: 10;
11
+ maximumQueryCharacters: 200;
12
+ maximumResponseBytes: number;
13
+ maximumSafeErrorBytes: number;
14
+ maximumSourceCharacters: 128;
15
+ maximumSuggestionTokenCharacters: 2048;
16
+ }>;
17
+ declare const geocodingPositionSchema: z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>;
18
+ declare const geocodingRetentionModes: readonly ["temporary", "persistent"];
19
+ declare const geocodingBoundsSchema: z.ZodTuple<[z.ZodNumber, z.ZodNumber, z.ZodNumber, z.ZodNumber], null>;
20
+ declare const geocodingForwardRequestSchema: z.ZodObject<{
21
+ bounds: z.ZodOptional<z.ZodTuple<[z.ZodNumber, z.ZodNumber, z.ZodNumber, z.ZodNumber], null>>;
22
+ language: z.ZodOptional<z.ZodString>;
23
+ limit: z.ZodOptional<z.ZodNumber>;
24
+ proximity: z.ZodOptional<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>>;
25
+ query: z.ZodString;
26
+ retention: z.ZodDefault<z.ZodEnum<{
27
+ temporary: "temporary";
28
+ persistent: "persistent";
29
+ }>>;
30
+ }, z.core.$strict>;
31
+ declare const autocompleteRequestSchema: z.ZodObject<{
32
+ bounds: z.ZodOptional<z.ZodTuple<[z.ZodNumber, z.ZodNumber, z.ZodNumber, z.ZodNumber], null>>;
33
+ language: z.ZodOptional<z.ZodString>;
34
+ limit: z.ZodDefault<z.ZodNumber>;
35
+ proximity: z.ZodOptional<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>>;
36
+ query: z.ZodString;
37
+ }, z.core.$strict>;
38
+ declare const reverseGeocodingKindSchema: z.ZodEnum<{
39
+ address: "address";
40
+ locality: "locality";
41
+ street: "street";
42
+ place: "place";
43
+ }>;
44
+ declare const geocodingReverseRequestSchema: z.ZodObject<{
45
+ kinds: z.ZodOptional<z.ZodArray<z.ZodEnum<{
46
+ address: "address";
47
+ locality: "locality";
48
+ street: "street";
49
+ place: "place";
50
+ }>>>;
51
+ language: z.ZodOptional<z.ZodString>;
52
+ limit: z.ZodDefault<z.ZodNumber>;
53
+ position: z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>;
54
+ retention: z.ZodDefault<z.ZodEnum<{
55
+ temporary: "temporary";
56
+ persistent: "persistent";
57
+ }>>;
58
+ }, z.core.$strict>;
59
+ declare const geocodingResultKinds: readonly ["address", "street", "locality", "district", "county", "region", "country", "place", "unknown"];
60
+ declare const geocodingAddressSchema: z.ZodObject<{
61
+ city: z.ZodOptional<z.ZodString>;
62
+ country: z.ZodOptional<z.ZodString>;
63
+ countryCode: z.ZodOptional<z.ZodString>;
64
+ county: z.ZodOptional<z.ZodString>;
65
+ district: z.ZodOptional<z.ZodString>;
66
+ houseNumber: z.ZodOptional<z.ZodString>;
67
+ locality: z.ZodOptional<z.ZodString>;
68
+ name: z.ZodOptional<z.ZodString>;
69
+ postalCode: z.ZodOptional<z.ZodString>;
70
+ region: z.ZodOptional<z.ZodString>;
71
+ street: z.ZodOptional<z.ZodString>;
72
+ }, z.core.$strict>;
73
+ declare const geocodingResultSchema: z.ZodObject<{
74
+ address: z.ZodObject<{
75
+ city: z.ZodOptional<z.ZodString>;
76
+ country: z.ZodOptional<z.ZodString>;
77
+ countryCode: z.ZodOptional<z.ZodString>;
78
+ county: z.ZodOptional<z.ZodString>;
79
+ district: z.ZodOptional<z.ZodString>;
80
+ houseNumber: z.ZodOptional<z.ZodString>;
81
+ locality: z.ZodOptional<z.ZodString>;
82
+ name: z.ZodOptional<z.ZodString>;
83
+ postalCode: z.ZodOptional<z.ZodString>;
84
+ region: z.ZodOptional<z.ZodString>;
85
+ street: z.ZodOptional<z.ZodString>;
86
+ }, z.core.$strict>;
87
+ bounds: z.ZodOptional<z.ZodTuple<[z.ZodNumber, z.ZodNumber, z.ZodNumber, z.ZodNumber], null>>;
88
+ kind: z.ZodEnum<{
89
+ unknown: "unknown";
90
+ address: "address";
91
+ country: "country";
92
+ county: "county";
93
+ district: "district";
94
+ locality: "locality";
95
+ region: "region";
96
+ street: "street";
97
+ place: "place";
98
+ }>;
99
+ label: z.ZodString;
100
+ position: z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>;
101
+ sourceRef: z.ZodOptional<z.ZodString>;
102
+ }, z.core.$strict>;
103
+ declare const geocodingSourceSchema: z.ZodObject<{
104
+ id: z.ZodString;
105
+ revision: z.ZodNullable<z.ZodString>;
106
+ }, z.core.$strict>;
107
+ declare const geocodingAttributionSchema: z.ZodObject<{
108
+ text: z.ZodString;
109
+ url: z.ZodOptional<z.ZodString>;
110
+ }, z.core.$strict>;
111
+ declare const geocodingForwardResponseSchema: z.ZodObject<{
112
+ attribution: z.ZodArray<z.ZodObject<{
113
+ text: z.ZodString;
114
+ url: z.ZodOptional<z.ZodString>;
115
+ }, z.core.$strict>>;
116
+ queryId: z.ZodString;
117
+ results: z.ZodArray<z.ZodObject<{
118
+ address: z.ZodObject<{
119
+ city: z.ZodOptional<z.ZodString>;
120
+ country: z.ZodOptional<z.ZodString>;
121
+ countryCode: z.ZodOptional<z.ZodString>;
122
+ county: z.ZodOptional<z.ZodString>;
123
+ district: z.ZodOptional<z.ZodString>;
124
+ houseNumber: z.ZodOptional<z.ZodString>;
125
+ locality: z.ZodOptional<z.ZodString>;
126
+ name: z.ZodOptional<z.ZodString>;
127
+ postalCode: z.ZodOptional<z.ZodString>;
128
+ region: z.ZodOptional<z.ZodString>;
129
+ street: z.ZodOptional<z.ZodString>;
130
+ }, z.core.$strict>;
131
+ bounds: z.ZodOptional<z.ZodTuple<[z.ZodNumber, z.ZodNumber, z.ZodNumber, z.ZodNumber], null>>;
132
+ kind: z.ZodEnum<{
133
+ unknown: "unknown";
134
+ address: "address";
135
+ country: "country";
136
+ county: "county";
137
+ district: "district";
138
+ locality: "locality";
139
+ region: "region";
140
+ street: "street";
141
+ place: "place";
142
+ }>;
143
+ label: z.ZodString;
144
+ position: z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>;
145
+ sourceRef: z.ZodOptional<z.ZodString>;
146
+ }, z.core.$strict>>;
147
+ schemaVersion: z.ZodLiteral<1>;
148
+ source: z.ZodObject<{
149
+ id: z.ZodString;
150
+ revision: z.ZodNullable<z.ZodString>;
151
+ }, z.core.$strict>;
152
+ usage: z.ZodObject<{
153
+ units: z.ZodLiteral<1>;
154
+ }, z.core.$strict>;
155
+ }, z.core.$strict>;
156
+ declare const geocodingReverseResponseSchema: z.ZodObject<{
157
+ attribution: z.ZodArray<z.ZodObject<{
158
+ text: z.ZodString;
159
+ url: z.ZodOptional<z.ZodString>;
160
+ }, z.core.$strict>>;
161
+ queryId: z.ZodString;
162
+ results: z.ZodArray<z.ZodObject<{
163
+ address: z.ZodObject<{
164
+ city: z.ZodOptional<z.ZodString>;
165
+ country: z.ZodOptional<z.ZodString>;
166
+ countryCode: z.ZodOptional<z.ZodString>;
167
+ county: z.ZodOptional<z.ZodString>;
168
+ district: z.ZodOptional<z.ZodString>;
169
+ houseNumber: z.ZodOptional<z.ZodString>;
170
+ locality: z.ZodOptional<z.ZodString>;
171
+ name: z.ZodOptional<z.ZodString>;
172
+ postalCode: z.ZodOptional<z.ZodString>;
173
+ region: z.ZodOptional<z.ZodString>;
174
+ street: z.ZodOptional<z.ZodString>;
175
+ }, z.core.$strict>;
176
+ bounds: z.ZodOptional<z.ZodTuple<[z.ZodNumber, z.ZodNumber, z.ZodNumber, z.ZodNumber], null>>;
177
+ kind: z.ZodEnum<{
178
+ unknown: "unknown";
179
+ address: "address";
180
+ country: "country";
181
+ county: "county";
182
+ district: "district";
183
+ locality: "locality";
184
+ region: "region";
185
+ street: "street";
186
+ place: "place";
187
+ }>;
188
+ label: z.ZodString;
189
+ position: z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>;
190
+ sourceRef: z.ZodOptional<z.ZodString>;
191
+ }, z.core.$strict>>;
192
+ schemaVersion: z.ZodLiteral<1>;
193
+ source: z.ZodObject<{
194
+ id: z.ZodString;
195
+ revision: z.ZodNullable<z.ZodString>;
196
+ }, z.core.$strict>;
197
+ usage: z.ZodObject<{
198
+ units: z.ZodLiteral<1>;
199
+ }, z.core.$strict>;
200
+ }, z.core.$strict>;
201
+ declare const geocodingSuggestionSchema: z.ZodObject<{
202
+ kind: z.ZodEnum<{
203
+ unknown: "unknown";
204
+ address: "address";
205
+ country: "country";
206
+ county: "county";
207
+ district: "district";
208
+ locality: "locality";
209
+ region: "region";
210
+ street: "street";
211
+ place: "place";
212
+ }>;
213
+ label: z.ZodString;
214
+ token: z.ZodString;
215
+ }, z.core.$strict>;
216
+ declare const autocompleteResponseSchema: z.ZodObject<{
217
+ attribution: z.ZodArray<z.ZodObject<{
218
+ text: z.ZodString;
219
+ url: z.ZodOptional<z.ZodString>;
220
+ }, z.core.$strict>>;
221
+ schemaVersion: z.ZodLiteral<1>;
222
+ source: z.ZodObject<{
223
+ id: z.ZodString;
224
+ revision: z.ZodNullable<z.ZodString>;
225
+ }, z.core.$strict>;
226
+ suggestions: z.ZodArray<z.ZodObject<{
227
+ kind: z.ZodEnum<{
228
+ unknown: "unknown";
229
+ address: "address";
230
+ country: "country";
231
+ county: "county";
232
+ district: "district";
233
+ locality: "locality";
234
+ region: "region";
235
+ street: "street";
236
+ place: "place";
237
+ }>;
238
+ label: z.ZodString;
239
+ token: z.ZodString;
240
+ }, z.core.$strict>>;
241
+ }, z.core.$strict>;
242
+ declare const resolveSuggestionRequestSchema: z.ZodObject<{
243
+ retention: z.ZodDefault<z.ZodEnum<{
244
+ temporary: "temporary";
245
+ persistent: "persistent";
246
+ }>>;
247
+ token: z.ZodString;
248
+ }, z.core.$strict>;
249
+ declare const resolveSuggestionResponseSchema: z.ZodObject<{
250
+ attribution: z.ZodArray<z.ZodObject<{
251
+ text: z.ZodString;
252
+ url: z.ZodOptional<z.ZodString>;
253
+ }, z.core.$strict>>;
254
+ result: z.ZodObject<{
255
+ address: z.ZodObject<{
256
+ city: z.ZodOptional<z.ZodString>;
257
+ country: z.ZodOptional<z.ZodString>;
258
+ countryCode: z.ZodOptional<z.ZodString>;
259
+ county: z.ZodOptional<z.ZodString>;
260
+ district: z.ZodOptional<z.ZodString>;
261
+ houseNumber: z.ZodOptional<z.ZodString>;
262
+ locality: z.ZodOptional<z.ZodString>;
263
+ name: z.ZodOptional<z.ZodString>;
264
+ postalCode: z.ZodOptional<z.ZodString>;
265
+ region: z.ZodOptional<z.ZodString>;
266
+ street: z.ZodOptional<z.ZodString>;
267
+ }, z.core.$strict>;
268
+ bounds: z.ZodOptional<z.ZodTuple<[z.ZodNumber, z.ZodNumber, z.ZodNumber, z.ZodNumber], null>>;
269
+ kind: z.ZodEnum<{
270
+ unknown: "unknown";
271
+ address: "address";
272
+ country: "country";
273
+ county: "county";
274
+ district: "district";
275
+ locality: "locality";
276
+ region: "region";
277
+ street: "street";
278
+ place: "place";
279
+ }>;
280
+ label: z.ZodString;
281
+ position: z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>;
282
+ sourceRef: z.ZodOptional<z.ZodString>;
283
+ }, z.core.$strict>;
284
+ schemaVersion: z.ZodLiteral<1>;
285
+ source: z.ZodObject<{
286
+ id: z.ZodString;
287
+ revision: z.ZodNullable<z.ZodString>;
288
+ }, z.core.$strict>;
289
+ usage: z.ZodObject<{
290
+ units: z.ZodLiteral<1>;
291
+ }, z.core.$strict>;
292
+ }, z.core.$strict>;
293
+ type GeocodingForwardRequest = z.input<typeof geocodingForwardRequestSchema>;
294
+ type NormalizedGeocodingForwardRequest = z.output<typeof geocodingForwardRequestSchema>;
295
+ type ReverseGeocodingKind = z.infer<typeof reverseGeocodingKindSchema>;
296
+ type GeocodingReverseRequest = z.input<typeof geocodingReverseRequestSchema>;
297
+ type NormalizedGeocodingReverseRequest = z.output<typeof geocodingReverseRequestSchema>;
298
+ type GeocodingResult = z.infer<typeof geocodingResultSchema>;
299
+ type GeocodingForwardResponse = z.infer<typeof geocodingForwardResponseSchema>;
300
+ type GeocodingReverseResponse = GeocodingForwardResponse;
301
+ type AutocompleteRequest = z.input<typeof autocompleteRequestSchema>;
302
+ type NormalizedAutocompleteRequest = z.output<typeof autocompleteRequestSchema>;
303
+ type GeocodingSuggestion = z.infer<typeof geocodingSuggestionSchema>;
304
+ type AutocompleteResponse = z.infer<typeof autocompleteResponseSchema>;
305
+ type ResolveSuggestionRequest = z.input<typeof resolveSuggestionRequestSchema>;
306
+ type NormalizedResolveSuggestionRequest = z.output<typeof resolveSuggestionRequestSchema>;
307
+ type ResolveSuggestionResponse = z.infer<typeof resolveSuggestionResponseSchema>;
308
+
309
+ export { type AutocompleteRequest, type AutocompleteResponse, type GeocodingForwardRequest, type GeocodingForwardResponse, type GeocodingResult, type GeocodingReverseRequest, type GeocodingReverseResponse, type GeocodingSuggestion, type NormalizedAutocompleteRequest, type NormalizedGeocodingForwardRequest, type NormalizedGeocodingReverseRequest, type NormalizedResolveSuggestionRequest, type ResolveSuggestionRequest, type ResolveSuggestionResponse, type ReverseGeocodingKind, autocompleteRequestSchema, autocompleteResponseSchema, geocodingAddressSchema, geocodingAttributionSchema, geocodingBoundsSchema, geocodingForwardRequestSchema, geocodingForwardResponseSchema, geocodingLimits, geocodingPositionSchema, geocodingResultKinds, geocodingResultSchema, geocodingRetentionModes, geocodingReverseRequestSchema, geocodingReverseResponseSchema, geocodingSourceSchema, geocodingSuggestionSchema, resolveSuggestionRequestSchema, resolveSuggestionResponseSchema, reverseGeocodingKindSchema };
@@ -0,0 +1,42 @@
1
+ import {
2
+ autocompleteRequestSchema,
3
+ autocompleteResponseSchema,
4
+ geocodingAddressSchema,
5
+ geocodingAttributionSchema,
6
+ geocodingBoundsSchema,
7
+ geocodingForwardRequestSchema,
8
+ geocodingForwardResponseSchema,
9
+ geocodingLimits,
10
+ geocodingPositionSchema,
11
+ geocodingResultKinds,
12
+ geocodingResultSchema,
13
+ geocodingRetentionModes,
14
+ geocodingReverseRequestSchema,
15
+ geocodingReverseResponseSchema,
16
+ geocodingSourceSchema,
17
+ geocodingSuggestionSchema,
18
+ resolveSuggestionRequestSchema,
19
+ resolveSuggestionResponseSchema,
20
+ reverseGeocodingKindSchema
21
+ } from "./chunk-EDYCZVXI.js";
22
+ export {
23
+ autocompleteRequestSchema,
24
+ autocompleteResponseSchema,
25
+ geocodingAddressSchema,
26
+ geocodingAttributionSchema,
27
+ geocodingBoundsSchema,
28
+ geocodingForwardRequestSchema,
29
+ geocodingForwardResponseSchema,
30
+ geocodingLimits,
31
+ geocodingPositionSchema,
32
+ geocodingResultKinds,
33
+ geocodingResultSchema,
34
+ geocodingRetentionModes,
35
+ geocodingReverseRequestSchema,
36
+ geocodingReverseResponseSchema,
37
+ geocodingSourceSchema,
38
+ geocodingSuggestionSchema,
39
+ resolveSuggestionRequestSchema,
40
+ resolveSuggestionResponseSchema,
41
+ reverseGeocodingKindSchema
42
+ };
@@ -0,0 +1,3 @@
1
+ export { GEOCODING_ERROR_CODES, GeocodeOptions, GeocodingError, GeocodingErrorCode, autocomplete, geocode, geocodeReverse, resolveSuggestion } from './client.js';
2
+ export { AutocompleteRequest, AutocompleteResponse, GeocodingForwardRequest, GeocodingForwardResponse, GeocodingResult, GeocodingReverseRequest, GeocodingReverseResponse, GeocodingSuggestion, NormalizedAutocompleteRequest, NormalizedGeocodingForwardRequest, NormalizedGeocodingReverseRequest, NormalizedResolveSuggestionRequest, ResolveSuggestionRequest, ResolveSuggestionResponse, ReverseGeocodingKind, autocompleteRequestSchema, autocompleteResponseSchema, geocodingAddressSchema, geocodingAttributionSchema, geocodingBoundsSchema, geocodingForwardRequestSchema, geocodingForwardResponseSchema, geocodingLimits, geocodingPositionSchema, geocodingResultKinds, geocodingResultSchema, geocodingRetentionModes, geocodingReverseRequestSchema, geocodingReverseResponseSchema, geocodingSourceSchema, geocodingSuggestionSchema, resolveSuggestionRequestSchema, resolveSuggestionResponseSchema, reverseGeocodingKindSchema } from './contract.js';
3
+ import 'zod';
package/dist/index.js ADDED
@@ -0,0 +1,56 @@
1
+ import {
2
+ GEOCODING_ERROR_CODES,
3
+ GeocodingError,
4
+ autocomplete,
5
+ geocode,
6
+ geocodeReverse,
7
+ resolveSuggestion
8
+ } from "./chunk-YMLUPVQH.js";
9
+ import {
10
+ autocompleteRequestSchema,
11
+ autocompleteResponseSchema,
12
+ geocodingAddressSchema,
13
+ geocodingAttributionSchema,
14
+ geocodingBoundsSchema,
15
+ geocodingForwardRequestSchema,
16
+ geocodingForwardResponseSchema,
17
+ geocodingLimits,
18
+ geocodingPositionSchema,
19
+ geocodingResultKinds,
20
+ geocodingResultSchema,
21
+ geocodingRetentionModes,
22
+ geocodingReverseRequestSchema,
23
+ geocodingReverseResponseSchema,
24
+ geocodingSourceSchema,
25
+ geocodingSuggestionSchema,
26
+ resolveSuggestionRequestSchema,
27
+ resolveSuggestionResponseSchema,
28
+ reverseGeocodingKindSchema
29
+ } from "./chunk-EDYCZVXI.js";
30
+ export {
31
+ GEOCODING_ERROR_CODES,
32
+ GeocodingError,
33
+ autocomplete,
34
+ autocompleteRequestSchema,
35
+ autocompleteResponseSchema,
36
+ geocode,
37
+ geocodeReverse,
38
+ geocodingAddressSchema,
39
+ geocodingAttributionSchema,
40
+ geocodingBoundsSchema,
41
+ geocodingForwardRequestSchema,
42
+ geocodingForwardResponseSchema,
43
+ geocodingLimits,
44
+ geocodingPositionSchema,
45
+ geocodingResultKinds,
46
+ geocodingResultSchema,
47
+ geocodingRetentionModes,
48
+ geocodingReverseRequestSchema,
49
+ geocodingReverseResponseSchema,
50
+ geocodingSourceSchema,
51
+ geocodingSuggestionSchema,
52
+ resolveSuggestion,
53
+ resolveSuggestionRequestSchema,
54
+ resolveSuggestionResponseSchema,
55
+ reverseGeocodingKindSchema
56
+ };
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@tileflow/search",
3
+ "version": "0.0.0-bootstrap.0",
4
+ "license": "Apache-2.0",
5
+ "description": "Headless geocoding and location selection client and wire contracts for Tileflow.",
6
+ "type": "module",
7
+ "sideEffects": false,
8
+ "homepage": "https://tileflow.dev",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/tileflow/tileflow-sdk.git",
12
+ "directory": "packages/search"
13
+ },
14
+ "bugs": {
15
+ "url": "https://github.com/tileflow/tileflow-sdk/issues"
16
+ },
17
+ "keywords": [
18
+ "tileflow",
19
+ "maps",
20
+ "search",
21
+ "geocoding"
22
+ ],
23
+ "main": "./dist/index.js",
24
+ "types": "./dist/index.d.ts",
25
+ "files": [
26
+ "dist",
27
+ "LICENSE"
28
+ ],
29
+ "exports": {
30
+ ".": {
31
+ "types": "./dist/index.d.ts",
32
+ "import": "./dist/index.js",
33
+ "default": "./dist/index.js"
34
+ },
35
+ "./contract": {
36
+ "types": "./dist/contract.d.ts",
37
+ "import": "./dist/contract.js",
38
+ "default": "./dist/contract.js"
39
+ },
40
+ "./client": {
41
+ "types": "./dist/client.d.ts",
42
+ "import": "./dist/client.js",
43
+ "default": "./dist/client.js"
44
+ },
45
+ "./package.json": "./package.json"
46
+ },
47
+ "publishConfig": {
48
+ "access": "public"
49
+ },
50
+ "dependencies": {
51
+ "zod": "^4.4.3"
52
+ },
53
+ "scripts": {
54
+ "build": "tsup src/index.ts src/contract.ts src/client.ts --format esm --dts --clean --splitting",
55
+ "verify": "pnpm run build && tsx --test test/*.test.ts",
56
+ "typecheck": "tsc -p tsconfig.json --noEmit",
57
+ "lint": "tsc -p tsconfig.json --noEmit"
58
+ }
59
+ }