csv2geo-sdk 1.2.0 → 1.4.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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/index.js +79 -2
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "csv2geo-sdk",
3
- "version": "1.2.0",
4
- "description": "Node.js SDK for CSV2GEO Geocoding API — 461M+ addresses, 39 countries, 42+ endpoints. Forward, reverse, batch, places, divisions (incl. postcode → boundary), IP geolocation with county overlay, coverage, autocomplete. 3,000 free requests/day.",
3
+ "version": "1.4.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.2.0',
78
+ 'User-Agent': 'csv2geo-node/1.4.0',
79
79
  },
80
80
  signal: controller.signal,
81
81
  };
@@ -469,6 +469,7 @@ class Client {
469
469
  const params = { code, country };
470
470
  if (options.include) params.include = options.include;
471
471
  if (options.precision) params.precision = options.precision;
472
+ if (options.lang) params.lang = options.lang;
472
473
  return this._request('GET', '/divisions/by-postcode', params);
473
474
  }
474
475
 
@@ -497,7 +498,12 @@ class Client {
497
498
  return this._request('GET', '/divisions/random', params);
498
499
  }
499
500
 
500
- /** Full parent/child chain for a division. GET /divisions/hierarchy/{id} */
501
+ /**
502
+ * Children of a division (immediate sub-divisions). GET /divisions/hierarchy/{id}
503
+ *
504
+ * Note: returns CHILDREN, not ancestors. For walk-UP "part-of" chain, use
505
+ * `divisionAncestors()`. Kept under the original name for backward compatibility.
506
+ */
501
507
  async divisionHierarchy(divisionId) {
502
508
  return this._request('GET', `/divisions/hierarchy/${encodeURIComponent(divisionId)}`);
503
509
  }
@@ -507,6 +513,77 @@ class Client {
507
513
  return this._request('GET', `/divisions/${encodeURIComponent(divisionId)}`);
508
514
  }
509
515
 
516
+ // ─────────────────────────────────────────────────────────
517
+ // Boundaries (Sprint 1.8)
518
+ // ─────────────────────────────────────────────────────────
519
+
520
+ /**
521
+ * Walk-up "part-of" chain: input → parent → root.
522
+ * GET /divisions/ancestors/{id}
523
+ *
524
+ * @param {string} divisionId - Overture ID of the leaf division.
525
+ * @param {object} [options]
526
+ * @param {string} [options.include] - "geometry" to include each level's polygon.
527
+ * @param {string} [options.precision] - "low" | "med" (default) | "full".
528
+ * @param {number} [options.maxDepth] - Hard cap (default 8, max 12).
529
+ * @returns {Promise<{id: string, depth: number, results: object[]}>}
530
+ *
531
+ * @example
532
+ * const chain = await client.divisionAncestors(beverlyHillsId, { include: 'geometry' });
533
+ * chain.results.forEach(level => console.log(level.subtype, level.name));
534
+ */
535
+ async divisionAncestors(divisionId, options = {}) {
536
+ const params = {};
537
+ if (options.include) params.include = options.include;
538
+ if (options.precision) params.precision = options.precision;
539
+ if (options.maxDepth) params.max_depth = options.maxDepth;
540
+ if (options.lang) params.lang = options.lang;
541
+ return this._request('GET', `/divisions/ancestors/${encodeURIComponent(divisionId)}`, params);
542
+ }
543
+
544
+ /**
545
+ * Immediate sub-divisions of a division (clearer-named alias of
546
+ * divisionHierarchy plus optional polygon enrichment).
547
+ * GET /divisions/children/{id}
548
+ *
549
+ * @param {string} divisionId
550
+ * @param {object} [options]
551
+ * @param {string} [options.include] - "geometry" to include polygons.
552
+ * @param {string} [options.precision] - "low" | "med" (default) | "full".
553
+ * @param {string} [options.subtype] - Filter by admin subtype.
554
+ * @param {number} [options.limit] - Max children (default 100, max 500).
555
+ */
556
+ async divisionChildren(divisionId, options = {}) {
557
+ const params = {};
558
+ if (options.include) params.include = options.include;
559
+ if (options.precision) params.precision = options.precision;
560
+ if (options.subtype) params.subtype = options.subtype;
561
+ if (options.limit) params.limit = options.limit;
562
+ if (options.lang) params.lang = options.lang;
563
+ return this._request('GET', `/divisions/children/${encodeURIComponent(divisionId)}`, params);
564
+ }
565
+
566
+ /**
567
+ * Consolidated entity lookup. Resolves canonical OR member id — e.g. any of
568
+ * NYC's 5 borough ids returns the canonical "New York City" record + members.
569
+ * GET /divisions/consolidated/{id}
570
+ *
571
+ * @param {string} divisionId
572
+ * @param {object} [options]
573
+ * @param {string} [options.include] - "geometry" for canonical's outline.
574
+ * @param {string} [options.precision] - "low" | "med" (default) | "full".
575
+ * @returns {Promise<{canonical: object, members: object[], matched_as: string, source: string}>}
576
+ *
577
+ * @throws ApiError(404) when the id is not part of any consolidated entity.
578
+ */
579
+ async divisionConsolidated(divisionId, options = {}) {
580
+ const params = {};
581
+ if (options.include) params.include = options.include;
582
+ if (options.precision) params.precision = options.precision;
583
+ if (options.lang) params.lang = options.lang;
584
+ return this._request('GET', `/divisions/consolidated/${encodeURIComponent(divisionId)}`, params);
585
+ }
586
+
510
587
  // ─────────────────────────────────────────────────────────
511
588
  // Coverage
512
589
  // ─────────────────────────────────────────────────────────