radar-sdk-js 4.5.0-beta.0 → 4.5.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/src/types.ts CHANGED
@@ -45,7 +45,8 @@ export type RadarTravelMode =
45
45
  export type RadarAvoidOption =
46
46
  | 'tolls'
47
47
  | 'highways'
48
- | 'ferries';
48
+ | 'ferries'
49
+ | 'borderCrossings';
49
50
 
50
51
  export interface RadarTripOptions {
51
52
  userId?: string;
@@ -76,8 +77,16 @@ export interface RadarTrackParams {
76
77
  fraud?: boolean;
77
78
  }
78
79
 
80
+ export interface RadarTrackVerifiedParams {
81
+ userId?: string;
82
+ description?: string;
83
+ metadata?: RadarMetadata;
84
+ skipVerifyApp?: boolean;
85
+ }
86
+
79
87
  export interface RadarStartTrackingVerifiedParams {
80
88
  interval: number;
89
+ skipVerifyApp?: boolean;
81
90
  }
82
91
 
83
92
  export enum RadarEventConfidence {
@@ -270,6 +279,7 @@ export type RadarGeocodeLayer =
270
279
  | 'address'
271
280
  | 'postalCode'
272
281
  | 'locality'
282
+ | 'neighborhood'
273
283
  | 'county'
274
284
  | 'state'
275
285
  | 'country'
@@ -302,10 +312,24 @@ export interface RadarAddress {
302
312
  street?: string;
303
313
  }
304
314
 
315
+ export interface RadarTimeZone {
316
+ id: string;
317
+ name: string;
318
+ code: string;
319
+ currentTime: string;
320
+ utcOffset: number;
321
+ dstOffset: number;
322
+ }
323
+
305
324
  export interface RadarAutocompleteAddress extends RadarAddress {
306
325
  unit?: string;
307
326
  }
308
327
 
328
+ export interface RadarGeocodeAddress extends RadarAddress {
329
+ unit?: string;
330
+ timeZone?: RadarTimeZone;
331
+ }
332
+
309
333
  export type RadarValidationRecordType = 'S' | 'R' | 'P' | 'M' | 'H' | 'G' | 'F' | undefined;
310
334
 
311
335
  export type RadarValidationPropertyType = 'commercial' | 'residential' | undefined;
@@ -325,6 +349,7 @@ export interface RadarForwardGeocodeParams {
325
349
  query: string;
326
350
  layers?: RadarGeocodeLayer[];
327
351
  country?: string;
352
+ lang?: string;
328
353
  }
329
354
 
330
355
  export interface RadarReverseGeocodeParams {
@@ -333,13 +358,13 @@ export interface RadarReverseGeocodeParams {
333
358
  layers?: RadarGeocodeLayer[];
334
359
  }
335
360
 
336
- export interface RadarGeocodeResponse extends RadarResponse {
337
- addresses: RadarAddress[];
361
+ export interface RadarGeocodeResponse extends RadarResponse {
362
+ addresses: RadarGeocodeAddress[];
338
363
  }
339
364
 
340
365
  export interface RadarIPGeocodeResponse extends RadarResponse {
341
366
  ip: string;
342
- address?: RadarAddress;
367
+ address?: RadarGeocodeAddress;
343
368
  proxy?: boolean;
344
369
  }
345
370
 
@@ -352,6 +377,8 @@ export interface RadarAutocompleteParams {
352
377
  /** @deprecated this is always true, regardless of the value passed here */
353
378
  expandUnits?: boolean;
354
379
  mailable?: boolean;
380
+ lang?: string;
381
+ postalCode?: string;
355
382
  }
356
383
 
357
384
  export interface RadarAutocompleteResponse extends RadarResponse {
@@ -375,13 +402,15 @@ export interface RadarSearchPlacesResponse extends RadarResponse {
375
402
  places: RadarSearchPlace[];
376
403
  }
377
404
 
405
+ export type RadarDistanceGeometryType = 'polyline' | 'polyline5' | 'polyline6' | 'linestring';
406
+
378
407
  export interface RadarDistanceParams {
379
408
  origin?: Location | string;
380
409
  destination: Location | string;
381
410
  modes: RadarTravelMode[] | string;
382
411
  units?: 'metric' | 'imperial';
383
- geometry?: boolean;
384
- geometryPoints?: boolean;
412
+ geometry?: RadarDistanceGeometryType;
413
+ geometryPoints?: number;
385
414
  avoid?: RadarAvoidOption[] | string;
386
415
  }
387
416
 
@@ -531,17 +560,12 @@ export interface RadarPolygonOptions {
531
560
  'border-opacity'?: number;
532
561
  },
533
562
  }
534
- export interface RadarAutocompleteUIOptions {
563
+ export interface RadarAutocompleteUIOptions extends Omit<RadarAutocompleteParams, 'query'> {
535
564
  container: string | HTMLElement;
536
- near?: string | Location; // bias for location results
537
565
  debounceMS?: number, // Debounce time in milliseconds
538
- threshold?: number, // DEPRECATED(use minCharacters instead)
566
+ /** @deprecated use minCharacters instead */
567
+ threshold?: number,
539
568
  minCharacters?: number, // Minimum number of characters to trigger autocomplete
540
- limit?: number, // Maximum number of autocomplete results
541
- layers?: RadarGeocodeLayer[];
542
- countryCode?: string;
543
- expandUnits?: boolean;
544
- mailable?: boolean;
545
569
  placeholder?: string, // Placeholder text for the input field
546
570
  onSelection?: (selection: any) => void,
547
571
  onRequest?: (params: RadarAutocompleteParams) => void,
@@ -557,7 +581,6 @@ export interface RadarAutocompleteUIOptions {
557
581
  }
558
582
 
559
583
  export interface RadarAutocompleteConfig extends RadarAutocompleteUIOptions {
560
- container: string | HTMLElement;
561
584
  debounceMS: number, // Debounce time in milliseconds
562
585
  threshold: number, // DEPRECATED(use minCharacters instead)
563
586
  minCharacters: number, // Minimum number of characters to trigger autocomplete
@@ -12,6 +12,7 @@ class RadarLogoControl {
12
12
  this.link.id = 'radar-map-logo';
13
13
  this.link.href = 'https://radar.com?ref=powered_by_radar';
14
14
  this.link.target = '_blank';
15
+ this.link.style.pointerEvents = "auto";
15
16
  this.link.appendChild(img);
16
17
 
17
18
  return this.link;
@@ -80,7 +80,6 @@ const getStyle = (options: RadarOptions, mapOptions: RadarMapOptions) => {
80
80
  class RadarMap extends maplibregl.Map {
81
81
  _markers: RadarMarker[] = [];
82
82
  _features: RadarMapFeature[] = [];
83
- _defaultMarker?: string;
84
83
 
85
84
  constructor(radarMapOptions: RadarMapOptions) {
86
85
  const config = Config.get();
@@ -97,7 +96,7 @@ class RadarMap extends maplibregl.Map {
97
96
  radarMapOptions,
98
97
  { style },
99
98
  );
100
- Logger.debug(`initialize map with options: ${JSON.stringify(mapOptions)}`);
99
+ Logger.debug('map initialized with options', mapOptions);
101
100
 
102
101
  (mapOptions as maplibregl.MapOptions).transformRequest = (url, resourceType) => {
103
102
  // this handles when a style is switched
@@ -153,16 +152,6 @@ class RadarMap extends maplibregl.Map {
153
152
  };
154
153
  this.on('resize', onResize);
155
154
  this.on('load', onResize);
156
-
157
- // parse radar metadata from style
158
- this.on('style.load', () => {
159
- const style = this.getStyle();
160
- const metadata: any = style.metadata || {};
161
-
162
- if (metadata['radar:marker']) { // default marker associated with custom style
163
- this._defaultMarker = metadata['radar:marker'];
164
- }
165
- });
166
155
  }
167
156
 
168
157
  addMarker(marker: RadarMarker) {
@@ -30,9 +30,9 @@ interface ImageOptions {
30
30
  }
31
31
 
32
32
  // cache URL loaded markers
33
- const IMAGE_CACHE = new Map<string, 'pending' | 'failed' | Blob>();
33
+ const IMAGE_CACHE = new Map<string, string>();
34
34
 
35
- const useCachedImage = (url: string, timeoutMS: number = 5000): Promise<Blob> => new Promise((resolve, reject) => {
35
+ const useCachedImage = (url: string, timeoutMS: number = 5000): Promise<string> => new Promise((resolve, reject) => {
36
36
  if (!IMAGE_CACHE.has(url)) { // nothing in cache
37
37
  IMAGE_CACHE.set(url, 'pending'); // request in flight
38
38
  return reject('miss');
@@ -50,9 +50,9 @@ const useCachedImage = (url: string, timeoutMS: number = 5000): Promise<Blob> =>
50
50
  clearInterval(interval);
51
51
  reject('failed');
52
52
 
53
- } else { // return data
53
+ } else if (cachedData !== undefined) { // return data
54
54
  clearInterval(interval);
55
- resolve(cachedData as Blob);
55
+ resolve(cachedData);
56
56
  }
57
57
  }, 100);
58
58
  });
@@ -89,7 +89,6 @@ const defaultMarkerOptions: RadarMarkerOptions = {
89
89
  };
90
90
 
91
91
  class RadarMarker extends maplibregl.Marker {
92
- _options: RadarMarkerOptions;
93
92
  _map!: RadarMap;
94
93
 
95
94
  constructor(markerOptions: RadarMarkerOptions) {
@@ -108,11 +107,84 @@ class RadarMarker extends maplibregl.Marker {
108
107
 
109
108
  super(maplibreOptions);
110
109
 
111
- this._options = markerOptions;
112
-
113
110
  // handle marker images (Radar marker, or custom URL)
114
111
  if (markerOptions.marker || markerOptions.url) {
115
- this.getCustomImage(markerOptions);
112
+ const originalElement = this._element.cloneNode(true);
113
+ this._element.childNodes.forEach((child) => {
114
+ child.remove();
115
+ });
116
+
117
+ const onSuccess = (url: string) => {
118
+ this._element.replaceChildren(createImageElement({
119
+ width: markerOptions.width,
120
+ height: markerOptions.height,
121
+ url,
122
+ }));
123
+ };
124
+
125
+ const onError = (err: any) => {
126
+ Logger.error(`Could not load marker: ${err.message} - falling back to default marker`);
127
+ IMAGE_CACHE.set(markerOptions.url as string, 'failed'); // mark as failed
128
+ this._element.replaceChildren(...Array.from(originalElement.childNodes));
129
+ }
130
+
131
+ // custom URL image
132
+ if (markerOptions.url) {
133
+ const loadImage = () => { // fetch marker data from URL
134
+ fetch(markerOptions.url as string)
135
+ .then(res => {
136
+ if (res.status === 200) {
137
+ res.blob()
138
+ .then((data) => {
139
+ const url = URL.createObjectURL(data);
140
+ IMAGE_CACHE.set(markerOptions.url as string, url); // cache data
141
+ onSuccess(url);
142
+ })
143
+ .catch(onError);
144
+ } else {
145
+ onError(new Error(res.statusText));
146
+ }
147
+ })
148
+ .catch(onError)
149
+ };
150
+
151
+ // attempt to use cached data, otherwise fetch marker image data from URL
152
+ useCachedImage(markerOptions.url)
153
+ .then(onSuccess)
154
+ .catch((reason: 'miss' | 'timedout' | 'failed' | Error) => {
155
+ if (reason !== 'miss') {
156
+ Logger.debug(`RadarMarker: cache lookup for ${markerOptions.url}: ${reason}`);
157
+ }
158
+ loadImage();
159
+ });
160
+ }
161
+
162
+ // Radar hosted image
163
+ if (markerOptions.marker) {
164
+ const loadMarker = () => {
165
+ Http.request({
166
+ method: 'GET',
167
+ version: 'maps',
168
+ path: `markers/${markerOptions.marker}`,
169
+ responseType: 'blob',
170
+ })
171
+ .then(({ data }) => {
172
+ const url = URL.createObjectURL(data);
173
+ IMAGE_CACHE.set(markerOptions.marker as string, url); // cache data
174
+ onSuccess(url)
175
+ })
176
+ .catch(onError);
177
+ };
178
+
179
+ useCachedImage(markerOptions.marker as string)
180
+ .then(onSuccess)
181
+ .catch((reason: 'miss' | 'timedout' | 'failed' | Error) => {
182
+ if (reason !== 'miss') {
183
+ Logger.debug(`RadarMarker: cache lookup for ${markerOptions.marker} ${reason}`);
184
+ }
185
+ loadMarker();
186
+ });
187
+ }
116
188
  }
117
189
 
118
190
  // handle deprecated popup options
@@ -155,7 +227,7 @@ class RadarMarker extends maplibregl.Marker {
155
227
  if (this.getPopup()) {
156
228
  // close any other open popups
157
229
  (this._map.getMarkers() || []).forEach((otherMarker) => {
158
- if (otherMarker.getPopup().isOpen()) {
230
+ if (otherMarker.getPopup()?.isOpen()) {
159
231
  otherMarker.togglePopup();
160
232
  }
161
233
  });
@@ -167,98 +239,7 @@ class RadarMarker extends maplibregl.Marker {
167
239
  }
168
240
  }
169
241
 
170
- // load marker image from a URL or as a Radar asset (custom styles)
171
- getCustomImage(markerOptions: RadarMarkerOptions) {
172
- const originalElement = this._element.cloneNode(true);
173
- this._element.childNodes.forEach((child) => {
174
- child.remove();
175
- });
176
-
177
- const onSuccess = (blob: Blob) => {
178
- const markerObject = URL.createObjectURL(blob);
179
- this._element.replaceChildren(createImageElement({
180
- width: markerOptions.width,
181
- height: markerOptions.height,
182
- url: markerObject,
183
- }));
184
- };
185
-
186
- const onError = (err: any) => {
187
- Logger.error(`Could not load marker: ${err.message} - falling back to default marker`);
188
- IMAGE_CACHE.set(markerOptions.url as string, 'failed'); // mark as failed
189
- this._element.replaceChildren(...Array.from(originalElement.childNodes));
190
- }
191
-
192
- // custom URL image
193
- if (markerOptions.url) {
194
- const loadImage = () => { // fetch marker data from URL
195
- fetch(markerOptions.url as string)
196
- .then(res => {
197
- if (res.status === 200) {
198
- res.blob()
199
- .then((data) => {
200
- IMAGE_CACHE.set(markerOptions.url as string, data); // cache data
201
- onSuccess(data);
202
- })
203
- .catch(onError);
204
- } else {
205
- onError(new Error(res.statusText));
206
- }
207
- })
208
- .catch(onError)
209
- };
210
-
211
- // attempt to use cached data, otherwise fetch marker image data from URL
212
- useCachedImage(markerOptions.url)
213
- .then(onSuccess)
214
- .catch((reason: 'miss' | 'timedout' | 'failed' | Error) => {
215
- if (reason !== 'miss') {
216
- Logger.debug(`RadarMarker: cache lookup for ${markerOptions.url}: ${reason}`);
217
- }
218
- loadImage();
219
- });
220
- }
221
-
222
- // Radar hosted image
223
- if (markerOptions.marker) {
224
- const loadMarker = () => {
225
- Http.request({
226
- method: 'GET',
227
- version: 'maps',
228
- path: `markers/${markerOptions.marker}`,
229
- responseType: 'blob',
230
- })
231
- .then(({ data }) => {
232
- IMAGE_CACHE.set(markerOptions.url as string, data); // cache data
233
- onSuccess(data)
234
- })
235
- .catch(onError);
236
- };
237
-
238
- useCachedImage(markerOptions.marker as string)
239
- .then(onSuccess)
240
- .catch((reason: 'miss' | 'timedout' | 'failed' | Error) => {
241
- if (reason !== 'miss') {
242
- Logger.debug(`RadarMarker: cache lookup for ${markerOptions.marker} ${reason}`);
243
- }
244
- loadMarker();
245
- });
246
- }
247
- }
248
-
249
242
  addTo(map: RadarMap) {
250
- // use default marker associated with map style, if none is provided in options
251
- // (and custom style has an associated marker)
252
- const markerOptions = this._options;
253
- if (!markerOptions.url && !markerOptions.marker && !markerOptions.color) {
254
- if (map._defaultMarker) {
255
- this.getCustomImage({
256
- ...markerOptions,
257
- marker: map._defaultMarker,
258
- });
259
- }
260
- }
261
-
262
243
  map.addMarker(this);
263
244
  return super.addTo(map);
264
245
  }
@@ -186,7 +186,7 @@ class AutocompleteUI {
186
186
  this.inputField.addEventListener('blur', this.close.bind(this), true);
187
187
  }
188
188
 
189
- Logger.debug(`AutocompleteUI iniailized with options: ${JSON.stringify(this.config)}`);
189
+ Logger.debug('AutocompleteUI initialized with options', this.config);
190
190
  }
191
191
 
192
192
  public handleInput() {
@@ -247,7 +247,7 @@ class AutocompleteUI {
247
247
  }
248
248
 
249
249
  public async fetchResults(query: string) {
250
- const { limit, layers, countryCode, expandUnits, mailable, onRequest } = this.config;
250
+ const { limit, layers, countryCode, expandUnits, mailable, lang, postalCode, onRequest } = this.config;
251
251
 
252
252
  const params: RadarAutocompleteParams = {
253
253
  query,
@@ -256,6 +256,8 @@ class AutocompleteUI {
256
256
  countryCode,
257
257
  expandUnits,
258
258
  mailable,
259
+ lang,
260
+ postalCode,
259
261
  }
260
262
 
261
263
  if (this.near) {
@@ -507,14 +509,22 @@ class AutocompleteUI {
507
509
  return this;
508
510
  }
509
511
 
510
- public setWidth(width: number | string) {
511
- this.config.width = width;
512
+ public setWidth(width: number | string | null) {
513
+ if (width === null) {
514
+ this.config.width = undefined;
515
+ } else if (typeof width === 'string' || typeof width === 'number') {
516
+ this.config.width = width;
517
+ }
512
518
  setWidth(this.wrapper, this.config);
513
519
  return this;
514
520
  }
515
521
 
516
- public setMaxHeight(height: number | string) {
517
- this.config.maxHeight = height;
522
+ public setMaxHeight(height: number | string | null) {
523
+ if (height === null) {
524
+ this.config.maxHeight = undefined;
525
+ } else if (typeof height === 'string' || typeof height === 'number') {
526
+ this.config.maxHeight = height;
527
+ }
518
528
  setHeight(this.resultsList, this.config);
519
529
  return this;
520
530
  }
@@ -530,6 +540,24 @@ class AutocompleteUI {
530
540
  return this;
531
541
  }
532
542
 
543
+ public setLang(lang: string | null) {
544
+ if (lang === null) {
545
+ this.config.lang = undefined;
546
+ } else if (typeof lang === 'string') {
547
+ this.config.lang = lang;
548
+ }
549
+ return this;
550
+ }
551
+
552
+ public setPostalCode(postalCode: string | null) {
553
+ if (postalCode === null) {
554
+ this.config.postalCode = undefined;
555
+ } else if (typeof postalCode === 'string') {
556
+ this.config.postalCode = postalCode;
557
+ }
558
+ return this;
559
+ }
560
+
533
561
  public setShowMarkers(showMarkers: boolean) {
534
562
  this.config.showMarkers = showMarkers;
535
563
  if (showMarkers) {
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export default '4.5.0-beta.0';
1
+ export default '4.5.0';