csv2geo-sdk 1.4.0 → 1.5.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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +45 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "csv2geo-sdk",
3
- "version": "1.4.0",
3
+ "version": "1.5.1",
4
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",
package/src/index.js CHANGED
@@ -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
- async placesChain(brand, country) {
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,48 @@ 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
- return this._request('POST', '/places/batch', {}, body);
428
- }
429
-
430
- /** Single place by id. GET /places/{id} */
431
- async placeById(placeId) {
432
- return this._request('GET', `/places/${encodeURIComponent(placeId)}`);
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);
442
+ }
443
+
444
+ /** Single place by id. GET /places/by-id/{id} (customer URL).
445
+ * The customer-facing Laravel proxy nests this under /places/by-id/{id}
446
+ * even though the underlying Go service uses /places/{id} — SDK MUST
447
+ * target the customer path. (Bug fix 1.5.1; was broken in 1.5.0 and
448
+ * earlier.)
449
+ * options: { lang, includeOtherNames, include } */
450
+ async placeById(placeId, options = {}) {
451
+ const params = {};
452
+ this._mergePlacesI18n(params, options);
453
+ return this._request('GET', `/places/by-id/${encodeURIComponent(placeId)}`, params);
454
+ }
455
+
456
+ /** Internal: merge ?lang= and ?include=other_names options into params.
457
+ * Sprint 2.1b — translations on places (234K places, 17 langs from Overture). */
458
+ _mergePlacesI18n(params, options) {
459
+ if (options.lang) params.lang = options.lang;
460
+ if (options.include) {
461
+ params.include = options.include;
462
+ } else if (options.includeOtherNames) {
463
+ params.include = 'other_names';
464
+ }
433
465
  }
434
466
 
435
467
  // ─────────────────────────────────────────────────────────