csv2geo-sdk 1.0.1 → 1.1.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 +280 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "csv2geo-sdk",
|
|
3
|
-
"version": "1.0
|
|
4
|
-
"description": "Node.js SDK for CSV2GEO Geocoding API — 461M+ addresses,
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Node.js SDK for CSV2GEO Geocoding API — 461M+ addresses, 39 countries, 42 endpoints. Forward, reverse, batch, places, divisions (incl. postcode → boundary), 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
|
@@ -260,6 +260,286 @@ class Client {
|
|
|
260
260
|
}));
|
|
261
261
|
}
|
|
262
262
|
|
|
263
|
+
// ─────────────────────────────────────────────────────────
|
|
264
|
+
// Address Tools
|
|
265
|
+
// ─────────────────────────────────────────────────────────
|
|
266
|
+
|
|
267
|
+
/** Validate an address. GET /validate */
|
|
268
|
+
async validate(address, options = {}) {
|
|
269
|
+
const params = { q: address };
|
|
270
|
+
if (options.country) params.country = options.country;
|
|
271
|
+
return this._request('GET', '/validate', params);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/** Validate up to 10,000 addresses. POST /validate */
|
|
275
|
+
async validateBatch(addresses) {
|
|
276
|
+
if (addresses.length > 10000) throw new InvalidRequestError('Max 10,000 per batch');
|
|
277
|
+
return this._request('POST', '/validate', {}, { addresses });
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/** Address autocomplete suggestions. GET /autocomplete */
|
|
281
|
+
async autocomplete(query, options = {}) {
|
|
282
|
+
const params = { q: query };
|
|
283
|
+
if (options.country) params.country = options.country;
|
|
284
|
+
if (options.limit) params.limit = options.limit;
|
|
285
|
+
return this._request('GET', '/autocomplete', params);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/** Parse a free-form address into components. GET /parse */
|
|
289
|
+
async parse(address) {
|
|
290
|
+
return this._request('GET', '/parse', { q: address });
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/** Parse up to 10,000 addresses. POST /parse */
|
|
294
|
+
async parseBatch(addresses) {
|
|
295
|
+
if (addresses.length > 10000) throw new InvalidRequestError('Max 10,000 per batch');
|
|
296
|
+
return this._request('POST', '/parse', {}, { addresses });
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/** Standardize an address. GET /standardize */
|
|
300
|
+
async standardize(address) {
|
|
301
|
+
return this._request('GET', '/standardize', { q: address });
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/** Score similarity between two addresses. GET /addresses/compare */
|
|
305
|
+
async compareAddresses(address1, address2) {
|
|
306
|
+
return this._request('GET', '/addresses/compare', { a: address1, b: address2 });
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// ─────────────────────────────────────────────────────────
|
|
310
|
+
// Address inspection
|
|
311
|
+
// ─────────────────────────────────────────────────────────
|
|
312
|
+
|
|
313
|
+
/** Find addresses within radius of a coordinate. GET /addresses/nearby */
|
|
314
|
+
async addressesNearby(lat, lng, options = {}) {
|
|
315
|
+
const params = { lat, lng, radius: options.radius || 200 };
|
|
316
|
+
if (options.limit) params.limit = options.limit;
|
|
317
|
+
return this._request('GET', '/addresses/nearby', params);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/** Get all addresses on a street. GET /addresses/street */
|
|
321
|
+
async addressesStreet(country, city, street) {
|
|
322
|
+
return this._request('GET', '/addresses/street', { country, city, street });
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/** Address counts. GET /addresses/stats */
|
|
326
|
+
async addressesStats(country) {
|
|
327
|
+
const params = {};
|
|
328
|
+
if (country) params.country = country;
|
|
329
|
+
return this._request('GET', '/addresses/stats', params);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/** Random sample of addresses. GET /addresses/random */
|
|
333
|
+
async addressesRandom(options = {}) {
|
|
334
|
+
const params = { limit: options.limit || 1 };
|
|
335
|
+
if (options.country) params.country = options.country;
|
|
336
|
+
return this._request('GET', '/addresses/random', params);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/** Interpolate a coordinate from address-range data. GET /addresses/interpolate */
|
|
340
|
+
async addressesInterpolate(country, city, street, houseNumber) {
|
|
341
|
+
return this._request('GET', '/addresses/interpolate',
|
|
342
|
+
{ country, city, street, house_number: houseNumber });
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/** Find the intersection of two streets. GET /addresses/crossstreet */
|
|
346
|
+
async addressesCrossstreet(country, city, streetA, streetB) {
|
|
347
|
+
return this._request('GET', '/addresses/crossstreet',
|
|
348
|
+
{ country, city, street_a: streetA, street_b: streetB });
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// ─────────────────────────────────────────────────────────
|
|
352
|
+
// Places
|
|
353
|
+
// ─────────────────────────────────────────────────────────
|
|
354
|
+
|
|
355
|
+
/** Search places (POIs). GET /places */
|
|
356
|
+
async places(options = {}) {
|
|
357
|
+
const params = {};
|
|
358
|
+
if (options.q || options.query) params.q = options.q || options.query;
|
|
359
|
+
if (options.country) params.country = options.country;
|
|
360
|
+
if (options.category) params.category = options.category;
|
|
361
|
+
if (options.limit) params.limit = options.limit;
|
|
362
|
+
return this._request('GET', '/places', params);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/** Places within radius of a coordinate. GET /places/nearby */
|
|
366
|
+
async placesNearby(lat, lng, options = {}) {
|
|
367
|
+
const params = { lat, lng, radius: options.radius || 200 };
|
|
368
|
+
if (options.category) params.category = options.category;
|
|
369
|
+
if (options.limit) params.limit = options.limit;
|
|
370
|
+
return this._request('GET', '/places/nearby', params);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/** List all place categories. GET /places/categories */
|
|
374
|
+
async placesCategories() {
|
|
375
|
+
return this._request('GET', '/places/categories');
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/** Random places. GET /places/random */
|
|
379
|
+
async placesRandom(options = {}) {
|
|
380
|
+
const params = { limit: options.limit || 1 };
|
|
381
|
+
if (options.country) params.country = options.country;
|
|
382
|
+
if (options.category) params.category = options.category;
|
|
383
|
+
return this._request('GET', '/places/random', params);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/** Places counts. GET /places/stats */
|
|
387
|
+
async placesStats(country) {
|
|
388
|
+
const params = {};
|
|
389
|
+
if (country) params.country = country;
|
|
390
|
+
return this._request('GET', '/places/stats', params);
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/** List brand-tagged places. GET /places/brands */
|
|
394
|
+
async placesBrands(country) {
|
|
395
|
+
const params = {};
|
|
396
|
+
if (country) params.country = country;
|
|
397
|
+
return this._request('GET', '/places/brands', params);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/** All locations of a brand/chain. GET /places/chain */
|
|
401
|
+
async placesChain(brand, country) {
|
|
402
|
+
const params = { brand };
|
|
403
|
+
if (country) params.country = country;
|
|
404
|
+
return this._request('GET', '/places/chain', params);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/** Count places matching filter. GET /places/count */
|
|
408
|
+
async placesCount(options = {}) {
|
|
409
|
+
const params = {};
|
|
410
|
+
if (options.country) params.country = options.country;
|
|
411
|
+
if (options.category) params.category = options.category;
|
|
412
|
+
return this._request('GET', '/places/count', params);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/** Places similar to a given one. GET /places/similar */
|
|
416
|
+
async placesSimilar(placeId, options = {}) {
|
|
417
|
+
const params = { id: placeId };
|
|
418
|
+
if (options.limit) params.limit = options.limit;
|
|
419
|
+
return this._request('GET', '/places/similar', params);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/** Batch nearby-places lookup. POST /places/batch */
|
|
423
|
+
async placesBatch(coordinates, options = {}) {
|
|
424
|
+
if (coordinates.length > 10000) throw new InvalidRequestError('Max 10,000 per batch');
|
|
425
|
+
const body = { coordinates, radius: options.radius || 200 };
|
|
426
|
+
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)}`);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
// ─────────────────────────────────────────────────────────
|
|
436
|
+
// Divisions (Sprint 1 — postcode boundary)
|
|
437
|
+
// ─────────────────────────────────────────────────────────
|
|
438
|
+
|
|
439
|
+
/** Search administrative divisions. GET /divisions */
|
|
440
|
+
async divisionsSearch(options = {}) {
|
|
441
|
+
const params = {};
|
|
442
|
+
if (options.q || options.query) params.q = options.q || options.query;
|
|
443
|
+
if (options.country) params.country = options.country;
|
|
444
|
+
if (options.subtype) params.subtype = options.subtype;
|
|
445
|
+
if (options.limit) params.limit = options.limit;
|
|
446
|
+
return this._request('GET', '/divisions', params);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
/** Point-in-polygon: divisions containing a point. GET /divisions/contains */
|
|
450
|
+
async divisionsContains(lat, lng) {
|
|
451
|
+
return this._request('GET', '/divisions/contains', { lat, lng });
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* Postcode → boundary (bbox + optional polygon + population + wikidata).
|
|
456
|
+
* GET /divisions/by-postcode
|
|
457
|
+
*
|
|
458
|
+
* @param {string} code - Postcode (e.g. "90210", "SW1A 1AA")
|
|
459
|
+
* @param {string} country - ISO 3166-1 alpha-2
|
|
460
|
+
* @param {Object} [options]
|
|
461
|
+
* @param {string} [options.include] - "geometry" to include polygon
|
|
462
|
+
* @param {string} [options.precision] - "simplified" (default) or "full"
|
|
463
|
+
*
|
|
464
|
+
* @example
|
|
465
|
+
* const r = await client.divisionsByPostcode('90210', 'US', { include: 'geometry' });
|
|
466
|
+
* console.log(r.result.population, r.result.bbox);
|
|
467
|
+
*/
|
|
468
|
+
async divisionsByPostcode(code, country, options = {}) {
|
|
469
|
+
const params = { code, country };
|
|
470
|
+
if (options.include) params.include = options.include;
|
|
471
|
+
if (options.precision) params.precision = options.precision;
|
|
472
|
+
return this._request('GET', '/divisions/by-postcode', params);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/** List available division subtypes. GET /divisions/subtypes */
|
|
476
|
+
async divisionsSubtypes() {
|
|
477
|
+
return this._request('GET', '/divisions/subtypes');
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
/** List countries with division coverage. GET /divisions/countries */
|
|
481
|
+
async divisionsCountries() {
|
|
482
|
+
return this._request('GET', '/divisions/countries');
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/** Division counts. GET /divisions/stats */
|
|
486
|
+
async divisionsStats(country) {
|
|
487
|
+
const params = {};
|
|
488
|
+
if (country) params.country = country;
|
|
489
|
+
return this._request('GET', '/divisions/stats', params);
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
/** Random divisions. GET /divisions/random */
|
|
493
|
+
async divisionsRandom(options = {}) {
|
|
494
|
+
const params = { limit: options.limit || 1 };
|
|
495
|
+
if (options.country) params.country = options.country;
|
|
496
|
+
if (options.subtype) params.subtype = options.subtype;
|
|
497
|
+
return this._request('GET', '/divisions/random', params);
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
/** Full parent/child chain for a division. GET /divisions/hierarchy/{id} */
|
|
501
|
+
async divisionHierarchy(divisionId) {
|
|
502
|
+
return this._request('GET', `/divisions/hierarchy/${encodeURIComponent(divisionId)}`);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/** Single division by id. GET /divisions/{id} */
|
|
506
|
+
async divisionById(divisionId) {
|
|
507
|
+
return this._request('GET', `/divisions/${encodeURIComponent(divisionId)}`);
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
// ─────────────────────────────────────────────────────────
|
|
511
|
+
// Coverage
|
|
512
|
+
// ─────────────────────────────────────────────────────────
|
|
513
|
+
|
|
514
|
+
/** Live tier-by-country coverage matrix. GET /coverage */
|
|
515
|
+
async coverage() {
|
|
516
|
+
return this._request('GET', '/coverage');
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
/** Aggregate coverage totals. GET /coverage-stats */
|
|
520
|
+
async coverageStats() {
|
|
521
|
+
return this._request('GET', '/coverage-stats');
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
// ─────────────────────────────────────────────────────────
|
|
525
|
+
// Utilities
|
|
526
|
+
// ─────────────────────────────────────────────────────────
|
|
527
|
+
|
|
528
|
+
/** Timezone at a coordinate. GET /timezone */
|
|
529
|
+
async timezone(lat, lng) {
|
|
530
|
+
return this._request('GET', '/timezone', { lat, lng });
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
/** Great-circle distance between two coordinates. GET /distance */
|
|
534
|
+
async distance(lat1, lng1, lat2, lng2) {
|
|
535
|
+
return this._request('GET', '/distance', { lat1, lng1, lat2, lng2 });
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
/** Service health check. GET /health */
|
|
539
|
+
async health() {
|
|
540
|
+
return this._request('GET', '/health');
|
|
541
|
+
}
|
|
542
|
+
|
|
263
543
|
/**
|
|
264
544
|
* Parse API result into GeocodeResult
|
|
265
545
|
* @private
|