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