@vexpay/maps 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,208 @@
1
+ import * as maplibre_gl from 'maplibre-gl';
2
+ import { MapOptions, Map } from 'maplibre-gl';
3
+
4
+ type Country = 've' | 'co';
5
+ interface Point {
6
+ lat: number;
7
+ lng: number;
8
+ }
9
+ type Kind = 'address' | 'street' | 'building' | 'place' | 'neighbourhood' | 'locality' | 'admin';
10
+ type Precision = 'ADDRESS' | 'BLOCK' | 'BUILDING' | 'STREET' | 'PLACE' | 'AREA';
11
+ interface SearchResult {
12
+ id: string;
13
+ label: string;
14
+ kind: Kind;
15
+ precision: Precision;
16
+ point: Point;
17
+ /** Estado or departamento (level1), municipio (level2). */
18
+ admin: {
19
+ level1: string | null;
20
+ level2: string | null;
21
+ };
22
+ neighbourhood: string | null;
23
+ source: string;
24
+ }
25
+ interface SearchResponse {
26
+ results: SearchResult[];
27
+ attribution: string[];
28
+ }
29
+ interface ReverseResult {
30
+ admin: {
31
+ level1: string | null;
32
+ level2: string | null;
33
+ };
34
+ neighbourhood: {
35
+ label: string;
36
+ source: string;
37
+ } | null;
38
+ street: {
39
+ label: string;
40
+ distanceM: number;
41
+ source: string;
42
+ } | null;
43
+ place: {
44
+ label: string;
45
+ kind: string;
46
+ distanceM: number;
47
+ source: string;
48
+ } | null;
49
+ /** Present only when the calling product has a service area in this country. */
50
+ inServiceArea?: boolean;
51
+ zone?: string | null;
52
+ attribution: string[];
53
+ }
54
+ /** Map themes served by VEX Maps. `light` is the default. */
55
+ declare const MAP_THEMES: readonly ["light", "dark", "white", "grayscale", "purple"];
56
+ type MapTheme = (typeof MAP_THEMES)[number];
57
+ interface CountryInfo {
58
+ code: Country;
59
+ name: string;
60
+ bbox: [number, number, number, number];
61
+ }
62
+ interface VexMapsOptions {
63
+ /** A publishable key (`vexmap_pk_…`) in browsers, a secret key (`vexmap_sk_…`) on servers. */
64
+ key: string;
65
+ /** Default country for search and reverse. */
66
+ country?: Country;
67
+ /** API base URL. Default `https://maps.chuventures.com`. */
68
+ baseUrl?: string;
69
+ /** Map theme: `light` (default), `dark`, `white`, `grayscale` or `purple`. */
70
+ theme?: MapTheme;
71
+ /** Style URL for maps; overrides `theme`. Default: the VEX Maps style for the theme. */
72
+ styleUrl?: string;
73
+ /** Per-request timeout; past it the call fails with `unavailable`. Default 2000 ms. */
74
+ timeoutMs?: number;
75
+ /** Custom fetch (tests, proxies). */
76
+ fetch?: typeof fetch;
77
+ }
78
+ interface VexMaps {
79
+ readonly country: Country | undefined;
80
+ readonly styleUrl: string;
81
+ search(text: string, opts?: {
82
+ country?: Country;
83
+ near?: Point;
84
+ signal?: AbortSignal;
85
+ }): Promise<SearchResponse>;
86
+ reverse(point: Point, opts?: {
87
+ country?: Country;
88
+ signal?: AbortSignal;
89
+ }): Promise<ReverseResult>;
90
+ /** Secret keys only. */
91
+ countries(): Promise<CountryInfo[]>;
92
+ }
93
+ declare const DEFAULT_BASE_URL = "https://maps.chuventures.com";
94
+ declare const DEFAULT_TILES_URL = "https://tiles.chuventures.com";
95
+ declare const DEFAULT_STYLE_URL = "https://tiles.chuventures.com/style.json";
96
+ /** The style URL of a theme on the VEX Maps tile host. */
97
+ declare function styleUrlFor(theme?: MapTheme, tilesUrl?: string): string;
98
+ declare function createVexMaps(options: VexMapsOptions): VexMaps;
99
+
100
+ /** Every failure the SDK reports. `unavailable` means VEX Maps could not be reached in time. */
101
+ type VexMapsErrorCode = 'unavailable' | 'invalid_api_key' | 'origin_not_allowed' | 'country_not_allowed' | 'secret_key_required' | 'secret_key_in_browser' | 'invalid_text' | 'invalid_country' | 'invalid_point' | 'point_outside_country' | 'rate_limited' | 'not_found' | 'error';
102
+ declare class VexMapsError extends Error {
103
+ readonly code: VexMapsErrorCode | string;
104
+ readonly status?: number | undefined;
105
+ /** Seconds to wait, on `rate_limited`. */
106
+ readonly retryAfter?: number | undefined;
107
+ readonly name = "VexMapsError";
108
+ constructor(code: VexMapsErrorCode | string, message: string, status?: number | undefined,
109
+ /** Seconds to wait, on `rate_limited`. */
110
+ retryAfter?: number | undefined);
111
+ }
112
+ declare const isUnavailable: (e: unknown) => boolean;
113
+
114
+ type Listener<T> = (payload: T) => void;
115
+ declare class Emitter<E extends Record<string, unknown>> {
116
+ private l;
117
+ on<K extends keyof E>(event: K, fn: Listener<E[K]>): () => void;
118
+ emit<K extends keyof E>(event: K, payload: E[K]): void;
119
+ clear(): void;
120
+ }
121
+
122
+ /** Spanish by default; every string can be overridden. The signature is not a string here. */
123
+ interface VexMapsStrings {
124
+ placeholder: string;
125
+ label: string;
126
+ searching: string;
127
+ noResults: string;
128
+ unavailable: string;
129
+ useMyLocation: string;
130
+ locating: string;
131
+ locationDenied: string;
132
+ confirm: string;
133
+ adjustPin: string;
134
+ mapUnavailable: string;
135
+ zoomIn: string;
136
+ zoomOut: string;
137
+ recenter: string;
138
+ mapControls: string;
139
+ }
140
+ declare const DEFAULT_STRINGS: VexMapsStrings;
141
+
142
+ type MapLibre = typeof maplibre_gl;
143
+ interface MapWidgetOptions {
144
+ center?: Point;
145
+ zoom?: number;
146
+ /** `light` (default), `dark`, `white`, `grayscale` or `purple`. */
147
+ theme?: MapTheme;
148
+ /** A full style URL; overrides `theme`. */
149
+ styleUrl?: string;
150
+ /** Extra MapLibre options. `style`, `container` and the attribution stay VEX Maps'. */
151
+ mapOptions?: Partial<Omit<MapOptions, 'container' | 'style' | 'attributionControl'>>;
152
+ /** Pass MapLibre in yourself (otherwise `window.maplibregl` or a dynamic import of `maplibre-gl`). */
153
+ maplibregl?: MapLibre;
154
+ }
155
+ type MapEvents = {
156
+ ready: Map;
157
+ unavailable: VexMapsError;
158
+ moveend: Point;
159
+ };
160
+ interface MapWidget {
161
+ on: Emitter<MapEvents>['on'];
162
+ /** The MapLibre map once ready. */
163
+ readonly map: Map | null;
164
+ center(): Point | null;
165
+ flyTo(p: Point, zoom?: number): void;
166
+ destroy(): void;
167
+ }
168
+ /** A MapLibre map with the VEX Maps style and the "VEX Maps · © OpenStreetMap" signature. */
169
+ declare function mountMap(container: HTMLElement, opts?: MapWidgetOptions): MapWidget;
170
+
171
+ interface LocationPickerOptions {
172
+ client: VexMaps;
173
+ country?: Country;
174
+ /** Where the map starts (a saved address, or the city). */
175
+ center?: Point;
176
+ zoom?: number;
177
+ strings?: Partial<VexMapsStrings>;
178
+ maplibregl?: MapWidgetOptions['maplibregl'];
179
+ /** Map theme; default the client's (`light`). */
180
+ theme?: MapTheme;
181
+ /** Look up the address under the pin as the map moves. Default true. */
182
+ liveReverse?: boolean;
183
+ /** The pin's colour, any CSS colour. Default a warm red (`#d1372b`). */
184
+ pinColor?: string;
185
+ }
186
+ interface PickerConfirm {
187
+ point: Point;
188
+ reverse: ReverseResult | null;
189
+ picked: SearchResult | null;
190
+ }
191
+ type LocationPickerEvents = {
192
+ confirm: PickerConfirm;
193
+ unavailable: VexMapsError;
194
+ move: Point;
195
+ };
196
+ interface LocationPicker {
197
+ on: Emitter<LocationPickerEvents>['on'];
198
+ /** The point under the pin. */
199
+ point(): Point | null;
200
+ destroy(): void;
201
+ }
202
+ /**
203
+ * Search, then drag the map under a fixed centre pin, then confirm. The page receives the point
204
+ * and the reverse lookup (or `reverse: null` if it failed: the point is still good).
205
+ */
206
+ declare function mountLocationPicker(container: HTMLElement, opts: LocationPickerOptions): LocationPicker;
207
+
208
+ export { type Country as C, DEFAULT_BASE_URL as D, Emitter as E, type Kind as K, type LocationPicker as L, MAP_THEMES as M, type Point as P, type ReverseResult as R, type SearchResult as S, VexMapsError as V, type VexMaps as a, type VexMapsStrings as b, type CountryInfo as c, DEFAULT_STRINGS as d, DEFAULT_STYLE_URL as e, DEFAULT_TILES_URL as f, type LocationPickerOptions as g, type MapTheme as h, type MapWidget as i, type MapWidgetOptions as j, type PickerConfirm as k, type Precision as l, type SearchResponse as m, type VexMapsErrorCode as n, type VexMapsOptions as o, createVexMaps as p, isUnavailable as q, mountLocationPicker as r, mountMap as s, styleUrlFor as t };