csv2geo-sdk 1.3.0 → 1.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/package.json +2 -2
- package/src/index.js +44 -12
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "csv2geo-sdk",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Node.js SDK for CSV2GEO Geocoding API — 461M+ addresses, 39 countries,
|
|
3
|
+
"version": "1.5.0",
|
|
4
|
+
"description": "Node.js SDK for CSV2GEO Geocoding API — 461M+ addresses, 39 countries, 48+ endpoints. Forward, reverse, batch, places, boundaries (postcode → polygon, ancestors walk-up, children walk-down, consolidated cities), IP geolocation with county overlay, coverage, autocomplete. 3,000 free requests/day.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"types": "src/index.d.ts",
|
|
7
7
|
"files": [
|
package/src/index.js
CHANGED
|
@@ -75,7 +75,7 @@ class Client {
|
|
|
75
75
|
headers: {
|
|
76
76
|
'Authorization': `Bearer ${this.apiKey}`,
|
|
77
77
|
'Content-Type': 'application/json',
|
|
78
|
-
'User-Agent': 'csv2geo-node/1.
|
|
78
|
+
'User-Agent': 'csv2geo-node/1.4.0',
|
|
79
79
|
},
|
|
80
80
|
signal: controller.signal,
|
|
81
81
|
};
|
|
@@ -352,21 +352,25 @@ class Client {
|
|
|
352
352
|
// Places
|
|
353
353
|
// ─────────────────────────────────────────────────────────
|
|
354
354
|
|
|
355
|
-
/** Search places (POIs). GET /places
|
|
355
|
+
/** Search places (POIs). GET /places
|
|
356
|
+
* options: { q, country, category, limit, lang, includeOtherNames, include } */
|
|
356
357
|
async places(options = {}) {
|
|
357
358
|
const params = {};
|
|
358
359
|
if (options.q || options.query) params.q = options.q || options.query;
|
|
359
360
|
if (options.country) params.country = options.country;
|
|
360
361
|
if (options.category) params.category = options.category;
|
|
361
362
|
if (options.limit) params.limit = options.limit;
|
|
363
|
+
this._mergePlacesI18n(params, options);
|
|
362
364
|
return this._request('GET', '/places', params);
|
|
363
365
|
}
|
|
364
366
|
|
|
365
|
-
/** Places within radius of a coordinate. GET /places/nearby
|
|
367
|
+
/** Places within radius of a coordinate. GET /places/nearby
|
|
368
|
+
* options: { radius, category, limit, lang, includeOtherNames, include } */
|
|
366
369
|
async placesNearby(lat, lng, options = {}) {
|
|
367
370
|
const params = { lat, lng, radius: options.radius || 200 };
|
|
368
371
|
if (options.category) params.category = options.category;
|
|
369
372
|
if (options.limit) params.limit = options.limit;
|
|
373
|
+
this._mergePlacesI18n(params, options);
|
|
370
374
|
return this._request('GET', '/places/nearby', params);
|
|
371
375
|
}
|
|
372
376
|
|
|
@@ -375,11 +379,13 @@ class Client {
|
|
|
375
379
|
return this._request('GET', '/places/categories');
|
|
376
380
|
}
|
|
377
381
|
|
|
378
|
-
/** Random places. GET /places/random
|
|
382
|
+
/** Random places. GET /places/random
|
|
383
|
+
* options: { country, category, limit, lang, includeOtherNames, include } */
|
|
379
384
|
async placesRandom(options = {}) {
|
|
380
385
|
const params = { limit: options.limit || 1 };
|
|
381
386
|
if (options.country) params.country = options.country;
|
|
382
387
|
if (options.category) params.category = options.category;
|
|
388
|
+
this._mergePlacesI18n(params, options);
|
|
383
389
|
return this._request('GET', '/places/random', params);
|
|
384
390
|
}
|
|
385
391
|
|
|
@@ -397,10 +403,12 @@ class Client {
|
|
|
397
403
|
return this._request('GET', '/places/brands', params);
|
|
398
404
|
}
|
|
399
405
|
|
|
400
|
-
/** All locations of a brand/chain. GET /places/chain
|
|
401
|
-
|
|
406
|
+
/** All locations of a brand/chain. GET /places/chain
|
|
407
|
+
* options: { country, lang, includeOtherNames, include } */
|
|
408
|
+
async placesChain(brand, country, options = {}) {
|
|
402
409
|
const params = { brand };
|
|
403
410
|
if (country) params.country = country;
|
|
411
|
+
this._mergePlacesI18n(params, options);
|
|
404
412
|
return this._request('GET', '/places/chain', params);
|
|
405
413
|
}
|
|
406
414
|
|
|
@@ -412,24 +420,44 @@ class Client {
|
|
|
412
420
|
return this._request('GET', '/places/count', params);
|
|
413
421
|
}
|
|
414
422
|
|
|
415
|
-
/** Places similar to a given one. GET /places/similar
|
|
423
|
+
/** Places similar to a given one. GET /places/similar
|
|
424
|
+
* options: { limit, lang, includeOtherNames, include } */
|
|
416
425
|
async placesSimilar(placeId, options = {}) {
|
|
417
426
|
const params = { id: placeId };
|
|
418
427
|
if (options.limit) params.limit = options.limit;
|
|
428
|
+
this._mergePlacesI18n(params, options);
|
|
419
429
|
return this._request('GET', '/places/similar', params);
|
|
420
430
|
}
|
|
421
431
|
|
|
422
|
-
/** Batch nearby-places lookup. POST /places/batch
|
|
432
|
+
/** Batch nearby-places lookup. POST /places/batch
|
|
433
|
+
* options: { radius, category, lang, includeOtherNames, include } */
|
|
423
434
|
async placesBatch(coordinates, options = {}) {
|
|
424
435
|
if (coordinates.length > 10000) throw new InvalidRequestError('Max 10,000 per batch');
|
|
425
436
|
const body = { coordinates, radius: options.radius || 200 };
|
|
426
437
|
if (options.category) body.category = options.category;
|
|
427
|
-
|
|
438
|
+
// lang / include are forwarded via query string (not body)
|
|
439
|
+
const queryParams = {};
|
|
440
|
+
this._mergePlacesI18n(queryParams, options);
|
|
441
|
+
return this._request('POST', '/places/batch', queryParams, body);
|
|
428
442
|
}
|
|
429
443
|
|
|
430
|
-
/** Single place by id. GET /places/{id}
|
|
431
|
-
|
|
432
|
-
|
|
444
|
+
/** Single place by id. GET /places/{id}
|
|
445
|
+
* options: { lang, includeOtherNames, include } */
|
|
446
|
+
async placeById(placeId, options = {}) {
|
|
447
|
+
const params = {};
|
|
448
|
+
this._mergePlacesI18n(params, options);
|
|
449
|
+
return this._request('GET', `/places/${encodeURIComponent(placeId)}`, params);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/** Internal: merge ?lang= and ?include=other_names options into params.
|
|
453
|
+
* Sprint 2.1b — translations on places (234K places, 17 langs from Overture). */
|
|
454
|
+
_mergePlacesI18n(params, options) {
|
|
455
|
+
if (options.lang) params.lang = options.lang;
|
|
456
|
+
if (options.include) {
|
|
457
|
+
params.include = options.include;
|
|
458
|
+
} else if (options.includeOtherNames) {
|
|
459
|
+
params.include = 'other_names';
|
|
460
|
+
}
|
|
433
461
|
}
|
|
434
462
|
|
|
435
463
|
// ─────────────────────────────────────────────────────────
|
|
@@ -469,6 +497,7 @@ class Client {
|
|
|
469
497
|
const params = { code, country };
|
|
470
498
|
if (options.include) params.include = options.include;
|
|
471
499
|
if (options.precision) params.precision = options.precision;
|
|
500
|
+
if (options.lang) params.lang = options.lang;
|
|
472
501
|
return this._request('GET', '/divisions/by-postcode', params);
|
|
473
502
|
}
|
|
474
503
|
|
|
@@ -536,6 +565,7 @@ class Client {
|
|
|
536
565
|
if (options.include) params.include = options.include;
|
|
537
566
|
if (options.precision) params.precision = options.precision;
|
|
538
567
|
if (options.maxDepth) params.max_depth = options.maxDepth;
|
|
568
|
+
if (options.lang) params.lang = options.lang;
|
|
539
569
|
return this._request('GET', `/divisions/ancestors/${encodeURIComponent(divisionId)}`, params);
|
|
540
570
|
}
|
|
541
571
|
|
|
@@ -557,6 +587,7 @@ class Client {
|
|
|
557
587
|
if (options.precision) params.precision = options.precision;
|
|
558
588
|
if (options.subtype) params.subtype = options.subtype;
|
|
559
589
|
if (options.limit) params.limit = options.limit;
|
|
590
|
+
if (options.lang) params.lang = options.lang;
|
|
560
591
|
return this._request('GET', `/divisions/children/${encodeURIComponent(divisionId)}`, params);
|
|
561
592
|
}
|
|
562
593
|
|
|
@@ -577,6 +608,7 @@ class Client {
|
|
|
577
608
|
const params = {};
|
|
578
609
|
if (options.include) params.include = options.include;
|
|
579
610
|
if (options.precision) params.precision = options.precision;
|
|
611
|
+
if (options.lang) params.lang = options.lang;
|
|
580
612
|
return this._request('GET', `/divisions/consolidated/${encodeURIComponent(divisionId)}`, params);
|
|
581
613
|
}
|
|
582
614
|
|