@placekit/client-js
Advanced tools
Comparing version 2.2.0 to 2.3.0
@@ -1,2 +0,2 @@ | ||
/*! @placekit/client-js v2.2.0 | © placekit.io | MIT license | https://github.com/placekit/client-js#readme */ | ||
/*! @placekit/client-js v2.3.0 | © placekit.io | MIT license | https://github.com/placekit/client-js#readme */ | ||
export default PlaceKit; | ||
@@ -17,4 +17,15 @@ export as namespace PlaceKit; | ||
type PKType = "airport" | "bus" | "city" | "country" | "street" | "tourism" | "townhall" | "train"; | ||
type PKTypeFilter = PKType | "-airport" | "-bus" | "-city" | "-country" | "-street" | "-tourism" | "-townhall" | "-train"; | ||
type PKType = 'administrative' | 'airport' | 'bus' | 'city' | 'country' | 'county' | 'street' | 'tourism' | 'townhall' | 'train'; | ||
type PKTypeFilter = | ||
| PKType | ||
| '-administrative' | ||
| '-airport' | ||
| '-bus' | ||
| '-city' | ||
| '-country' | ||
| '-county' | ||
| '-street' | ||
| '-tourism' | ||
| '-townhall' | ||
| '-train'; | ||
@@ -57,2 +68,2 @@ export type PKOptions = { | ||
query: string; | ||
}; | ||
}; |
@@ -1,2 +0,2 @@ | ||
/*! @placekit/client-js v2.2.0 | © placekit.io | MIT license | https://github.com/placekit/client-js#readme */ | ||
/*! @placekit/client-js v2.3.0 | © placekit.io | MIT license | https://github.com/placekit/client-js#readme */ | ||
const extensions = new Map(); | ||
@@ -8,3 +8,3 @@ function getUserAgent() { | ||
} | ||
chunks.push(`PlaceKit/2.2.0 (Client=JavaScript)`); | ||
chunks.push(`PlaceKit/2.3.0 (Client=JavaScript)`); | ||
if (typeof process !== 'undefined' && process.version) { | ||
@@ -22,5 +22,3 @@ chunks.push(`NodeJS/${process.version}`); | ||
let currentHost = 0; | ||
const hosts = [ | ||
`https://api.placekit.co`, | ||
]; | ||
const hosts = [`https://api.placekit.co`]; | ||
let hasGeolocation = false; | ||
@@ -37,3 +35,4 @@ const globalParams = { | ||
const controller = new AbortController(); | ||
const id = typeof timeout !== 'undefined' ? setTimeout(() => controller.abort(), timeout) : undefined; | ||
const id = | ||
typeof timeout !== 'undefined' ? setTimeout(() => controller.abort(), timeout) : undefined; | ||
const url = new URL(resource.trim().replace(/^\/+/, ''), hosts[currentHost]); | ||
@@ -56,23 +55,26 @@ if (['GET', 'HEAD'].includes(method) && typeof params !== 'undefined') { | ||
body: !['GET', 'HEAD'].includes(method) ? JSON.stringify(params) : undefined, | ||
}).then(async (res) => { | ||
clearTimeout(id); | ||
const body = await res.json(); | ||
if (!res.ok) { | ||
throw ({ | ||
status: res.status, | ||
statusText: res.statusText, | ||
...body, | ||
}); | ||
} | ||
return body; | ||
}).catch((err) => { | ||
if (err.name === 'AbortError' || (err.status && err.status >= 500)) { | ||
currentHost++; | ||
if (currentHost < hosts.length-1) { | ||
return request(method, resource, opts); | ||
}) | ||
.then(async (res) => { | ||
clearTimeout(id); | ||
const body = await res.json(); | ||
if (!res.ok) { | ||
throw { | ||
status: res.status, | ||
statusText: res.statusText, | ||
...body, | ||
}; | ||
} | ||
} | ||
throw err; | ||
}); | ||
} const client = { | ||
return body; | ||
}) | ||
.catch((err) => { | ||
if (err.name === 'AbortError' || (err.status && err.status >= 500)) { | ||
currentHost++; | ||
if (currentHost < hosts.length - 1) { | ||
return request(method, resource, opts); | ||
} | ||
} | ||
throw err; | ||
}); | ||
} | ||
const client = { | ||
get options() { | ||
@@ -96,3 +98,5 @@ return globalParams; | ||
if (typeof window === 'undefined' || !navigator.geolocation) { | ||
reject(Error('PlaceKit.requestGeolocation: geolocation is only available in the browser.')); | ||
reject( | ||
Error('PlaceKit.requestGeolocation: geolocation is only available in the browser.'), | ||
); | ||
} else { | ||
@@ -110,3 +114,3 @@ navigator.geolocation.getCurrentPosition( | ||
}, | ||
opts | ||
opts, | ||
); | ||
@@ -130,3 +134,3 @@ } | ||
} | ||
placekit.extend = function(resource, init) { | ||
placekit.extend = function (resource, init) { | ||
if (!init?.call) { | ||
@@ -133,0 +137,0 @@ throw Error('PlaceKit extend: `init` argument is invalid, expected a function.'); |
@@ -1,2 +0,2 @@ | ||
/*! @placekit/client-js v2.2.0 | © placekit.io | MIT license | https://github.com/placekit/client-js#readme */ | ||
/*! @placekit/client-js v2.3.0 | © placekit.io | MIT license | https://github.com/placekit/client-js#readme */ | ||
(function (global, factory) { | ||
@@ -27,5 +27,3 @@ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
let currentHost = 0; | ||
const hosts = [ | ||
`https://api.placekit.co`, | ||
]; | ||
const hosts = [`https://api.placekit.co`]; | ||
let hasGeolocation = false; | ||
@@ -42,3 +40,4 @@ const globalParams = { | ||
const controller = new AbortController(); | ||
const id = typeof timeout !== 'undefined' ? setTimeout(() => controller.abort(), timeout) : undefined; | ||
const id = | ||
typeof timeout !== 'undefined' ? setTimeout(() => controller.abort(), timeout) : undefined; | ||
const url = new URL(resource.trim().replace(/^\/+/, ''), hosts[currentHost]); | ||
@@ -61,23 +60,26 @@ if (['GET', 'HEAD'].includes(method) && typeof params !== 'undefined') { | ||
body: !['GET', 'HEAD'].includes(method) ? JSON.stringify(params) : undefined, | ||
}).then(async (res) => { | ||
clearTimeout(id); | ||
const body = await res.json(); | ||
if (!res.ok) { | ||
throw ({ | ||
status: res.status, | ||
statusText: res.statusText, | ||
...body, | ||
}); | ||
} | ||
return body; | ||
}).catch((err) => { | ||
if (err.name === 'AbortError' || (err.status && err.status >= 500)) { | ||
currentHost++; | ||
if (currentHost < hosts.length-1) { | ||
return request(method, resource, opts); | ||
}) | ||
.then(async (res) => { | ||
clearTimeout(id); | ||
const body = await res.json(); | ||
if (!res.ok) { | ||
throw { | ||
status: res.status, | ||
statusText: res.statusText, | ||
...body, | ||
}; | ||
} | ||
} | ||
throw err; | ||
}); | ||
} const client = { | ||
return body; | ||
}) | ||
.catch((err) => { | ||
if (err.name === 'AbortError' || (err.status && err.status >= 500)) { | ||
currentHost++; | ||
if (currentHost < hosts.length - 1) { | ||
return request(method, resource, opts); | ||
} | ||
} | ||
throw err; | ||
}); | ||
} | ||
const client = { | ||
get options() { | ||
@@ -101,3 +103,5 @@ return globalParams; | ||
if (typeof window === 'undefined' || !navigator.geolocation) { | ||
reject(Error('PlaceKit.requestGeolocation: geolocation is only available in the browser.')); | ||
reject( | ||
Error('PlaceKit.requestGeolocation: geolocation is only available in the browser.'), | ||
); | ||
} else { | ||
@@ -115,3 +119,3 @@ navigator.geolocation.getCurrentPosition( | ||
}, | ||
opts | ||
opts, | ||
); | ||
@@ -135,3 +139,3 @@ } | ||
} | ||
placekit.extend = function(resource, init) { | ||
placekit.extend = function (resource, init) { | ||
if (!init?.call) { | ||
@@ -138,0 +142,0 @@ throw Error('PlaceKit extend: `init` argument is invalid, expected a function.'); |
@@ -1,2 +0,2 @@ | ||
/*! @placekit/client-js v2.2.0 | © placekit.io | MIT license | https://github.com/placekit/client-js#readme */ | ||
/*! @placekit/client-js v2.3.0 | © placekit.io | MIT license | https://github.com/placekit/client-js#readme */ | ||
export default PlaceKit; | ||
@@ -19,7 +19,4 @@ export as namespace PlaceKit; | ||
list(opts?: PKPatchListOptions): Promise<PKPatchListResponse>; | ||
create(update: PKPatchUpdate, opts?: PKPatchUpdateOptions): Promise<PKPatchResult>; | ||
create( | ||
update: PKPatchUpdate, | ||
opts?: PKPatchUpdateOptions | ||
): Promise<PKPatchResult>; | ||
create( | ||
update: AtLeastOne<PKPatchUpdate>, | ||
@@ -33,3 +30,3 @@ opts?: PKPatchUpdateOptions, | ||
update?: AtLeastOne<PKPatchUpdate>, | ||
opts?: PKPatchUpdateOptions | ||
opts?: PKPatchUpdateOptions, | ||
): Promise<PKPatchResult>; | ||
@@ -41,11 +38,5 @@ delete(id: string): Promise<void>; | ||
list(): Promise<PKKeysResult[]>; | ||
create( | ||
role: "public" | "private", | ||
opts?: PKKeysOptions, | ||
): Promise<PKKeysResult>; | ||
create(role: 'public' | 'private', opts?: PKKeysOptions): Promise<PKKeysResult>; | ||
get(id: string): Promise<PKKeysResult>; | ||
update( | ||
id: string, | ||
opts?: PKKeysOptions | ||
): Promise<PKKeysResult>; | ||
update(id: string, opts?: PKKeysOptions): Promise<PKKeysResult>; | ||
delete(id: string): Promise<void>; | ||
@@ -55,6 +46,17 @@ }; | ||
type PKType = "airport" | "bus" | "city" | "country" | "street" | "tourism" | "townhall" | "train"; | ||
type PKTypeFilter = PKType | "-airport" | "-bus" | "-city" | "-country" | "-street" | "-tourism" | "-townhall" | "-train"; | ||
type PKPatchType = Exclude<PKType, "country">; | ||
type PKPatchTypeFilter = Exclude<PKTypeFilter, "country" | "-country">; | ||
type PKType = 'administrative' | 'airport' | 'bus' | 'city' | 'country' | 'county' | 'street' | 'tourism' | 'townhall' | 'train'; | ||
type PKTypeFilter = | ||
| PKType | ||
| '-administrative' | ||
| '-airport' | ||
| '-bus' | ||
| '-city' | ||
| '-country' | ||
| '-county' | ||
| '-street' | ||
| '-tourism' | ||
| '-townhall' | ||
| '-train'; | ||
type PKPatchType = Exclude<PKType, 'country'>; | ||
type PKPatchTypeFilter = Exclude<PKTypeFilter, 'country' | '-country'>; | ||
type PKPatchStatus = 'pending' | 'approved'; | ||
@@ -100,3 +102,3 @@ | ||
export type PKPatchResult = Omit<PKResult, "type"> & { | ||
export type PKPatchResult = Omit<PKResult, 'type'> & { | ||
id: string; | ||
@@ -146,10 +148,10 @@ status: PKPatchStatus; | ||
appId: string; | ||
role: "public" | "private"; | ||
role: 'public' | 'private'; | ||
domains: string[]; | ||
createdAt: string; | ||
updatedAt: string; | ||
} | ||
}; | ||
export type PKKeysOptions = { | ||
domains?: string[]; | ||
}; | ||
}; |
@@ -1,2 +0,2 @@ | ||
/*! @placekit/client-js v2.2.0 | © placekit.io | MIT license | https://github.com/placekit/client-js#readme */ | ||
/*! @placekit/client-js v2.3.0 | © placekit.io | MIT license | https://github.com/placekit/client-js#readme */ | ||
import placekit from './placekit-lite.js'; | ||
@@ -16,6 +16,9 @@ | ||
const method = typeof origin === 'undefined' ? 'POST' : 'PUT'; | ||
const data = typeof origin === 'undefined' ? { record: update } : { | ||
origin, | ||
update, | ||
}; | ||
const data = | ||
typeof origin === 'undefined' | ||
? { record: update } | ||
: { | ||
origin, | ||
update, | ||
}; | ||
return request(method, 'patch', { | ||
@@ -73,3 +76,5 @@ ...data, | ||
if (!['public', 'private'].includes(role)) { | ||
throw Error('PlaceKit.keys.create: `role` argument is invalid, expected either "public" or "private".'); | ||
throw Error( | ||
'PlaceKit.keys.create: `role` argument is invalid, expected either "public" or "private".', | ||
); | ||
} | ||
@@ -76,0 +81,0 @@ if (!['object', 'undefined'].includes(typeof opts) || Array.isArray(opts) || opts === null) { |
{ | ||
"name": "@placekit/client-js", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"author": "PlaceKit <support@placekit.io>", | ||
"description": "PlaceKit JavaScript client", | ||
"keywords": [ | ||
"addresses", | ||
"api", | ||
"geocoder", | ||
"geocoding", | ||
"locations", | ||
"places" | ||
], | ||
"license": "MIT", | ||
@@ -50,3 +58,3 @@ "homepage": "https://github.com/placekit/client-js#readme", | ||
"lint": "eslint ./src", | ||
"format": "eslint ./src --fix", | ||
"format": "prettier --write ./src", | ||
"test": "node --test ./src", | ||
@@ -56,12 +64,12 @@ "test:watch": "node --test ./src --watch" | ||
"devDependencies": { | ||
"eslint": "^8.50.0", | ||
"eslint-config-google": "^0.14.0", | ||
"rimraf": "^5.0.4", | ||
"rollup": "^3.29.3", | ||
"@rollup/plugin-replace": "^5.0.5", | ||
"eslint": "^8.56.0", | ||
"eslint-config-prettier": "^9.1.0", | ||
"eslint-plugin-prettier": "^5.1.3", | ||
"prettier": "^3.2.5", | ||
"rimraf": "^5.0.5", | ||
"rollup": "^4.12.0", | ||
"rollup-plugin-cleanup": "^3.2.1", | ||
"rollup-plugin-copy": "^3.5.0" | ||
}, | ||
"dependencies": { | ||
"@rollup/plugin-replace": "^5.0.2" | ||
} | ||
} |
337
README.md
@@ -11,5 +11,5 @@ <h1 align="center"> | ||
[![NPM](https://img.shields.io/npm/v/@placekit/client-js?style=flat-square)](https://www.npmjs.com/package/@placekit/client-js?activeTab=readme) | ||
[![LICENSE](https://img.shields.io/github/license/placekit/client-js?style=flat-square)](./LICENSE) | ||
[![NPM](https://img.shields.io/npm/v/@placekit/client-js?style=flat-square)](https://www.npmjs.com/package/@placekit/client-js?activeTab=readme) | ||
[![LICENSE](https://img.shields.io/github/license/placekit/client-js?style=flat-square)](./LICENSE) | ||
</div> | ||
@@ -21,4 +21,4 @@ | ||
<a href="#-reference">Reference</a> • | ||
<a href="./examples">Examples</a> • | ||
<a href="#%EF%B8%8F-license">License</a> | ||
<a href="#%EF%B8%8F-license">License</a> • | ||
<a href="https://github.com/placekit/examples">Examples</a> | ||
</p> | ||
@@ -30,3 +30,3 @@ | ||
👉 If you're looking for a full Autocomplete experience, have a look at our standalone [PlaceKit Autocomplete JS library](https://github.com/placekit/autocomplete-js), or check out our [examples](./examples) to learn how to integrate with an existing components library. | ||
👉 If you're looking for a full Autocomplete experience, have a look at our standalone [PlaceKit Autocomplete JS library](https://github.com/placekit/autocomplete-js), or check out our [examples](https://github.com/placekit/examples) to learn how to integrate with an existing components library. | ||
@@ -37,3 +37,3 @@ ## ✨ Features | ||
- Works both on the **browser** and **node.js** | ||
- Integrates with **your preferred stack** and autocomplete components (see [examples](./examples)) | ||
- Integrates with **your preferred stack** and autocomplete components (see [examples](https://github.com/placekit/examples)) | ||
- **TypeScript** compatible | ||
@@ -55,12 +55,12 @@ | ||
// CommonJS syntax: | ||
const placekit = require('@placekit/client-js/lite'); | ||
const placekit = require("@placekit/client-js/lite"); | ||
// ES6 Modules syntax: | ||
import placekit from '@placekit/client-js/lite'; | ||
import placekit from "@placekit/client-js/lite"; | ||
const pk = placekit('<your-api-key>', { | ||
const pk = placekit("<your-api-key>", { | ||
//... | ||
}); | ||
pk.search('Paris').then((res) => { | ||
pk.search("Paris").then((res) => { | ||
console.log(res.results); | ||
@@ -70,3 +70,3 @@ }); | ||
👉 For advanced usages, check out our [examples](./examples). | ||
👉 **Check out our [examples](https://github.com/placekit/examples) for different use cases and advance usages!** | ||
@@ -78,3 +78,3 @@ ### CDN | ||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/@placekit/client-js@2.1.0/dist/placekit-lite.umd.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/@placekit/client-js@2.3.0/dist/placekit-lite.umd.js"></script> | ||
``` | ||
@@ -87,7 +87,7 @@ | ||
<script> | ||
const pk = placekit('<your-api-key>', { | ||
const pk = placekit("<your-api-key>", { | ||
//... | ||
}); | ||
pk.search('Paris').then((res) => { | ||
pk.search("Paris").then((res) => { | ||
console.log(res.results); | ||
@@ -102,3 +102,3 @@ }); | ||
<script type="module"> | ||
import placekit from 'https://cdn.jsdelivr.net/npm/@placekit/client-js@2.1.0/dist/placekit-lite.js'; | ||
import placekit from "https://cdn.jsdelivr.net/npm/@placekit/client-js@2.3.0/dist/placekit-lite.js"; | ||
const pk = placekit(/* ... */); | ||
@@ -109,4 +109,2 @@ // ... | ||
👉 For advanced usages, check out our [examples](./examples). | ||
## 🧰 Reference | ||
@@ -116,6 +114,6 @@ | ||
| Version | Path | Methods | Modules | | ||
| --- | --- | --- | --- | | ||
| **Lite** | `@placekit/client-js/lite` | Search methods | ESM, CJS, UMD | | ||
| **Extended** | `@placekit/client-js` | All methods | ESM, CJS | | ||
| Version | Path | Methods | Modules | | ||
| ------------ | -------------------------- | -------------- | ------------- | | ||
| **Lite** | `@placekit/client-js/lite` | Search methods | ESM, CJS, UMD | | ||
| **Extended** | `@placekit/client-js` | All methods | ESM, CJS | | ||
@@ -157,21 +155,21 @@ - Lite version has an optimized bundle size for the browser, but works also in the back-end. | ||
PlaceKit initialization function returns a PlaceKit client, named `pk` in all examples. | ||
PlaceKit initialization function returns a PlaceKit client, named `pk` in all snippets below. | ||
```js | ||
// Lite version, CommonJS syntax: | ||
const placekit = require('@placekit/client-js/lite'); | ||
const placekit = require("@placekit/client-js/lite"); | ||
// Lite version, ES6 Modules syntax: | ||
import placekit from '@placekit/client-js/lite'; | ||
import placekit from "@placekit/client-js/lite"; | ||
// Extended version, CommonJS syntax: | ||
const placekit = require('@placekit/client-js'); | ||
const placekit = require("@placekit/client-js"); | ||
// Extended version, ES6 Modules syntax: | ||
import placekit from '@placekit/client-js'; | ||
import placekit from "@placekit/client-js"; | ||
// Initialize PlaceKit client | ||
const pk = placekit('<your-api-key>', { | ||
countries: ['fr'], | ||
language: 'en', | ||
const pk = placekit("<your-api-key>", { | ||
countries: ["fr"], | ||
language: "en", | ||
maxResults: 10, | ||
@@ -181,5 +179,5 @@ }); | ||
| Parameter | Type | Description | | ||
| --- | --- | --- | | ||
| `apiKey` | `string` | API key | | ||
| Parameter | Type | Description | | ||
| --------- | ------------------------------ | ---------------------------------------------- | | ||
| `apiKey` | `string` | API key | | ||
| `options` | `key-value mapping` (optional) | Global parameters (see [options](#pkoptions)). | | ||
@@ -193,5 +191,5 @@ | ||
```js | ||
pk.search('Paris', { | ||
countries: ['fr'], | ||
maxResults: 5, | ||
pk.search("Paris", { | ||
countries: ["fr"], | ||
maxResults: 5, | ||
}).then((res) => { | ||
@@ -202,6 +200,6 @@ console.log(res.results); | ||
| Parameter | Type | Description | | ||
| --- | --- | --- | | ||
| `query` | `string` | Search terms | | ||
| `opts` | `key-value mapping` (optional) | Search-specific parameters (see [options](#pkoptions)). | | ||
| Parameter | Type | Description | | ||
| --------- | ------------------------------ | ------------------------------------------------------- | | ||
| `query` | `string` | Search terms | | ||
| `opts` | `key-value mapping` (optional) | Search-specific parameters (see [options](#pkoptions)). | | ||
@@ -216,4 +214,4 @@ ### `pk.reverse()` | ||
pk.reverse({ | ||
coordinates: '48.871086,2.3036339', | ||
countries: ['fr'], | ||
coordinates: "48.871086,2.3036339", | ||
countries: ["fr"], | ||
maxResults: 5, | ||
@@ -225,7 +223,8 @@ }).then((res) => { | ||
| Parameter | Type | Description | | ||
| --- | --- | --- | | ||
| `opts` | `key-value mapping` (optional) | Search-specific parameters (see [options](#pkoptions)). | | ||
| Parameter | Type | Description | | ||
| --------- | ------------------------------ | ------------------------------------------------------- | | ||
| `opts` | `key-value mapping` (optional) | Search-specific parameters (see [options](#pkoptions)). | | ||
**Notes:** | ||
- If you omit `options.coordinates`, it'll use `coordinates` from global parameters set when instanciating with `placekit()` or with `pk.configure()`. | ||
@@ -242,12 +241,12 @@ | ||
| Option | Type | Default | Description | | ||
| --- | --- | --- | --- | | ||
| `countries` | `string[]?` | `undefined` | Countries to search in, default to current IP country. Array of [two-letter ISO](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) country codes<sup>[(1)](#ft1)</sup>. | | ||
| `language` | `string?` | `undefined` | Preferred language for the results<sup>[(1)](#ft1)</sup>, [two-letter ISO](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) language code. Supported languages are `en` and `fr`. By default the results are displayed in their country's language. | | ||
| `types` | `string[]?` | `undefined` | Type of results to show. Array of accepted values: `street`, `city`, `country`, `airport`, `bus`, `train`, `townhall`, `tourism`. Prepend `-` to omit a type like `['-bus']`. Unset to return all. | | ||
| `maxResults` | `integer?` | `5` | Number of results per page. | | ||
| `coordinates` | `string?` | `undefined` | Coordinates to search around. Automatically set when calling [`pk.requestGeolocation()`](#pkrequestGeolocation). | | ||
| `forwardIP` | `string?` | `undefined` | Set `x-forwarded-for` header to forward the provided IP for back-end usages (otherwise it'll use the server IP). | | ||
| Option | Type | Default | Description | | ||
| ------------- | ----------- | ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| `countries` | `string[]?` | `undefined` | Countries to search in, default to current IP country. Array of [two-letter ISO](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) country codes<sup>[(1)](#ft1)</sup>. | | ||
| `language` | `string?` | `undefined` | Preferred language for the results<sup>[(1)](#ft1)</sup>, [two-letter ISO](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) language code. Supported languages are `en` and `fr`. By default the results are displayed in their country's language. | | ||
| `types` | `string[]?` | `undefined` | Type of results to show. Array of accepted values: `street`, `city`, `country`, `administrative`, `airport`, `bus`, `county`, `train`, `townhall`, `tourism`. Prepend `-` to omit a type like `['-bus']`. Unset to return all. | | ||
| `maxResults` | `integer?` | `5` | Number of results per page. | | ||
| `coordinates` | `string?` | `undefined` | Coordinates to search around. Automatically set when calling [`pk.requestGeolocation()`](#pkrequestGeolocation). | | ||
| `forwardIP` | `string?` | `undefined` | Set `x-forwarded-for` header to forward the provided IP for back-end usages (otherwise it'll use the server IP). | | ||
<a id="ft1"><b>[1]</b></a>: See [Scope and Limitations](https://placekit.io/terms/scope) for more details. | ||
<a id="ft1"><b>[1]</b></a>: See [Coverage](https://placekit.io/terms/coverage) for more details. | ||
@@ -260,3 +259,3 @@ ### `pk.configure()` | ||
pk.configure({ | ||
language: 'fr', | ||
language: "fr", | ||
maxResults: 5, | ||
@@ -266,5 +265,5 @@ }); | ||
| Parameter | Type | Description | | ||
| --- | --- | --- | | ||
| `opts` | `key-value mapping` (optional) | Global parameters (see [options](#pkoptions)) | | ||
| Parameter | Type | Description | | ||
| --------- | ------------------------------ | --------------------------------------------- | | ||
| `opts` | `key-value mapping` (optional) | Global parameters (see [options](#pkoptions)) | | ||
@@ -276,8 +275,10 @@ ### `pk.requestGeolocation()` | ||
```js | ||
pk.requestGeolocation({ timeout: 10000 }).then((pos) => console.log(pos.coords)); | ||
pk.requestGeolocation({ timeout: 10000 }).then((pos) => | ||
console.log(pos.coords) | ||
); | ||
``` | ||
| Parameter | Type | Description | | ||
| --- | --- | --- | | ||
| `opts` | `key-value mapping` (optional) | `navigator.geolocation.getCurrentPosition` [options](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/getCurrentPosition). | | ||
| Parameter | Type | Description | | ||
| --------- | ------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------- | | ||
| `opts` | `key-value mapping` (optional) | `navigator.geolocation.getCurrentPosition` [options](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/getCurrentPosition). | | ||
@@ -317,23 +318,26 @@ The location will be store in the `coordinates` global options, you can still manually override it. | ||
// filter and paginate patches | ||
pk.patch.list({ | ||
status: 'approved', | ||
maxResults: 10, | ||
offset: 10, | ||
}).then((res) => { | ||
console.log(res.results); | ||
}); | ||
pk.patch | ||
.list({ | ||
status: "approved", | ||
maxResults: 10, | ||
offset: 10, | ||
}) | ||
.then((res) => { | ||
console.log(res.results); | ||
}); | ||
``` | ||
| Parameter | Type | Description | | ||
| --- | --- | --- | | ||
| `opts` | `key-value mapping` (optional) | Search options. | | ||
| `opts.status` | `('pending' \| 'approved')?` | Publication status. | | ||
| `opts.query` | `string?` | Terms filter. | | ||
| `opts.countries` | `string[]?` | Countries filter, array of [two-letter ISO](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) country codes. | | ||
| `opts.types` | `string[]?` | Types filter, array of accepted values: `street`, `city`, `airport`, `bus`, `train`, `townhall`, `tourism`. Prepend `-` to omit a type like `['-bus']`. Unset to return all. | | ||
| `opts.language` | `string?` | `undefined` | Preferred language for the results, [two-letter ISO](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) language code. | | ||
| `opts.maxResults` | `number?` | Maximum number of results to return. | | ||
| `opts.offset` | `number?` | Paginate results starting from the offset. | | ||
| Parameter | Type | Description | | ||
| ----------------- | ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | ||
| `opts` | `key-value mapping` (optional) | Search options. | | ||
| `opts.status` | `('pending' \| 'approved')?` | Publication status. | | ||
| `opts.query` | `string?` | Terms filter. | | ||
| `opts.countries` | `string[]?` | Countries filter, array of [two-letter ISO](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) country codes. | | ||
| `opts.types` | `string[]?` | Types filter, array of accepted values: `street`, `city`, `administrative`, `airport`, `bus`, `county`, `train`, `townhall`, `tourism`. Prepend `-` to omit a type like `['-bus']`. Unset to return all. | | ||
| `opts.language` | `string?` | `undefined` | Preferred language for the results, [two-letter ISO](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) language code. | | ||
| `opts.maxResults` | `number?` | Maximum number of results to return. | | ||
| `opts.offset` | `number?` | Paginate results starting from the offset. | | ||
#### Patch Record `status` explained | ||
- `pending`: only available through Live Patching endpoints, | ||
@@ -376,22 +380,24 @@ - `approved`: available to end-users through Search endpoints. | ||
| Parameter | Type | Description | | ||
| --- | --- | --- | | ||
| `update` | `key-value mapping` | Full patch record if adding, at least one property if fixing. | | ||
| `update.type` | `string` | Record type, one of `airport`, `bus`, `city`, `street`, `tourism`, `townhall`, `train`. | | ||
| `update.name` | `string` | Record display name (street name, city name, station name...). | | ||
| `update.city` | `string` | Record city name. | | ||
| `update.county` | `string` | Record county/province/department. | | ||
| `update.administrative` | `string` | Record administrative/region/state. | | ||
| `update.country` | `string` | Record country name. | | ||
| `update.countrycode` | `string` | Record [two-letter ISO](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) country code. | | ||
| `update.coordinates` | `string` | Record coordinates in format `lat,lng`. | | ||
| `update.zipcode` | `string[]` | Record postal/zip code(s). | | ||
| `update.population` | `number` | Record population of its city. | | ||
| `opts` | `key-value mapping` (optional) | Patch record options. | | ||
| `opts.status` | `('pending' \| 'approved')?` | Record status. | | ||
| `opts.language` | `string?` | Language in which the record is written, [two-letter ISO](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) language code. | | ||
| `origin` | `key-value mapping` (optional) | Original (and complete) record to fix, from `pk.search()` or `pk.reverse()`. | | ||
| Parameter | Type | Description | | ||
| ----------------------- | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------- | | ||
| `update` | `key-value mapping` | Full patch record if adding, at least one property if fixing. | | ||
| `update.type` | `string` | Record type, one of `administrative`, `airport`, `bus`, `city`, `county`, `street`, `tourism`, `townhall`, `train`. | | ||
| `update.name` | `string` | Record display name (street name, city name, station name...). | | ||
| `update.city` | `string` | Record city name. | | ||
| `update.county` | `string` (optional) | Record county/province/department. | | ||
| `update.administrative` | `string` (optional) | Record administrative/region/state. | | ||
| `update.country` | `string` | Record country name. | | ||
| `update.countrycode` | `string` | Record [two-letter ISO](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) country code. | | ||
| `update.coordinates` | `string` | Record coordinates in format `lat,lng`. | | ||
| `update.zipcode` | `string[]` | Record postal/zip code(s). | | ||
| `update.population` | `number` | Record population of its city. | | ||
| `opts` | `key-value mapping` (optional) | Patch record options. | | ||
| `opts.status` | `('pending' \| 'approved')?` | Record status. | | ||
| `opts.language` | `string?` | Language in which the record is written, [two-letter ISO](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) language code. | | ||
| `origin` | `key-value mapping` (optional) | Original (and complete) record to fix, from `pk.search()` or `pk.reverse()`. | | ||
#### Patch Record `language` explained | ||
Language is always considered as "preferred display language", which means: | ||
- If you omit `opts.language`, then details will be set in the `default` language. | ||
@@ -409,3 +415,3 @@ - If the patch record has a translation but no `default`, then the first available translation will be used as default. | ||
// get record default language | ||
pk.patch.get('<patch-id>').then((record) => { | ||
pk.patch.get("<patch-id>").then((record) => { | ||
console.log(record); | ||
@@ -415,3 +421,3 @@ }); | ||
// get record FR translation | ||
pk.patch.get('<patch-id>', 'fr').then((record) => { | ||
pk.patch.get("<patch-id>", "fr").then((record) => { | ||
console.log(record); | ||
@@ -421,5 +427,5 @@ }); | ||
| Parameter | Type | Description | | ||
| --- | --- | --- | | ||
| `id` | `string` | Record ID. | | ||
| Parameter | Type | Description | | ||
| ---------- | --------- | ------------------------------------------------------------------------------------------------------- | | ||
| `id` | `string` | Record ID. | | ||
| `language` | `string?` | Language to get, [two-letter ISO](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) language code. | | ||
@@ -435,46 +441,44 @@ | ||
// update and publish | ||
pk.patch.update( | ||
'<patch-id>', | ||
{ coordinates: '33.9955095,-118.472482' }, | ||
{ status: 'approved' } | ||
).then((record) => { | ||
console.log(record); | ||
}); | ||
pk.patch | ||
.update( | ||
"<patch-id>", | ||
{ coordinates: "33.9955095,-118.472482" }, | ||
{ status: "approved" } | ||
) | ||
.then((record) => { | ||
console.log(record); | ||
}); | ||
// update translation | ||
pk.patch.update( | ||
'<patch-id>', | ||
{ name: 'Rue Nouvelle' }, | ||
{ language: 'fr' } | ||
).then((record) => { | ||
console.log(record); | ||
}); | ||
pk.patch | ||
.update("<patch-id>", { name: "Rue Nouvelle" }, { language: "fr" }) | ||
.then((record) => { | ||
console.log(record); | ||
}); | ||
// unpublish | ||
pk.patch.update( | ||
'<patch-id>', | ||
undefined, | ||
{ status: 'pending' } | ||
).then((record) => { | ||
console.log(record); | ||
}); | ||
pk.patch | ||
.update("<patch-id>", undefined, { status: "pending" }) | ||
.then((record) => { | ||
console.log(record); | ||
}); | ||
``` | ||
| Parameter | Type | Description | | ||
| --- | --- | --- | | ||
| `id` | `string` | Record ID. | | ||
| `update` | `key-value mapping` (optional) | Updated fields, at least one property must be set if defined. | | ||
| `update.type` | `string` | One of `airport`, `bus`, `city`, `street`, `tourism`, `townhall`, `train`. | | ||
| `update.name` | `string` | Record display name (street name, city name, station name...). | | ||
| `update.city` | `string` | Record city name. | | ||
| `update.county` | `string` | Record county/province/department. | | ||
| `update.administrative` | `string` | Record administrative/region/state. | | ||
| `update.country` | `string` | Record country name. | | ||
| `update.countrycode` | `string` | Record [two-letter ISO](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) country code. | | ||
| `update.coordinates` | `string` | Record coordinates in format `lat,lng`. | | ||
| `update.zipcode` | `string[]` | Record postal/zip code(s). | | ||
| `update.population` | `number` | Record population of its city. | | ||
| `opts` | `key-value mapping` (optional) | Patch options. | | ||
| `opts.status` | `('pending' \| 'approved')?` | Publication status. | | ||
| `opts.language` | `string?` | Target language, [two-letter ISO](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) language code. | | ||
| Parameter | Type | Description | | ||
| ----------------------- | ------------------------------ | ------------------------------------------------------------------------------------------------------- | | ||
| `id` | `string` | Record ID. | | ||
| `update` | `key-value mapping` (optional) | Updated fields, at least one property must be set if defined. | | ||
| `update.type` | `string` | One of `administrative`, `airport`, `bus`, `city`, `county`, `street`, `tourism`, `townhall`, `train`. | | ||
| `update.name` | `string` | Record display name (street name, city name, station name...). | | ||
| `update.city` | `string` | Record city name. | | ||
| `update.county` | `string` (optional) | Record county/province/department. | | ||
| `update.administrative` | `string` (optional) | Record administrative/region/state. | | ||
| `update.country` | `string` | Record country name. | | ||
| `update.countrycode` | `string` | Record [two-letter ISO](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) country code. | | ||
| `update.coordinates` | `string` | Record coordinates in format `lat,lng`. | | ||
| `update.zipcode` | `string[]` | Record postal/zip code(s). | | ||
| `update.population` | `number` | Record population of its city. | | ||
| `opts` | `key-value mapping` (optional) | Patch options. | | ||
| `opts.status` | `('pending' \| 'approved')?` | Publication status. | | ||
| `opts.language` | `string?` | Target language, [two-letter ISO](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) language code. | | ||
@@ -488,8 +492,8 @@ ### `pk.patch.delete()` | ||
```js | ||
pk.patch.delete('<patch-id>'); | ||
pk.patch.delete("<patch-id>"); | ||
``` | ||
| Parameter | Type | Description | | ||
| --- | --- | --- | | ||
| `id` | `string` | Record ID. | | ||
| Parameter | Type | Description | | ||
| --------- | -------- | ----------- | | ||
| `id` | `string` | Record ID. | | ||
@@ -503,11 +507,12 @@ ### `pk.patch.deleteLang()` | ||
```js | ||
pk.patch.deleteLang('<patch-id>', 'fr'); | ||
pk.patch.deleteLang("<patch-id>", "fr"); | ||
``` | ||
| Parameter | Type | Description | | ||
| --- | --- | --- | | ||
| `id` | `string` | Record ID. | | ||
| Parameter | Type | Description | | ||
| ---------- | -------- | --------------------------------------------------------------------------------------------------------- | | ||
| `id` | `string` | Record ID. | | ||
| `language` | `string` | Language to unset, [two-letter ISO](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) language code. | | ||
NOTES: | ||
- Deleting a translation will return a `409` error if there is no default language and no other translation available. | ||
@@ -532,10 +537,10 @@ | ||
```js | ||
pk.keys.create('<role>', { domains: [] }); | ||
pk.keys.create("<role>", { domains: [] }); | ||
``` | ||
| Parameter | Type | Description | | ||
| --- | --- | --- | | ||
| `role` | `('public' \| 'private')` | API key role. | | ||
| `options` | `object?` | API key options. | | ||
| `options.domains` | `string[]?` | Domain restriction. | | ||
| Parameter | Type | Description | | ||
| ----------------- | ------------------------- | ------------------- | | ||
| `role` | `('public' \| 'private')` | API key role. | | ||
| `options` | `object?` | API key options. | | ||
| `options.domains` | `string[]?` | Domain restriction. | | ||
@@ -549,8 +554,8 @@ ### `pk.keys.get()` | ||
```js | ||
pk.keys.get('<key-id>'); | ||
pk.keys.get("<key-id>"); | ||
``` | ||
| Parameter | Type | Description | | ||
| --- | --- | --- | | ||
| `id` | `string` | API key ID. | | ||
| Parameter | Type | Description | | ||
| --------- | -------- | ----------- | | ||
| `id` | `string` | API key ID. | | ||
@@ -564,9 +569,9 @@ ### `pk.keys.update()` | ||
```js | ||
pk.keys.update('<key-id>', { domains: [] }); | ||
pk.keys.update("<key-id>", { domains: [] }); | ||
``` | ||
| Parameter | Type | Description | | ||
| --- | --- | --- | | ||
| `id` | `string` | API key ID. | | ||
| `options` | `object?` | API key options. | | ||
| Parameter | Type | Description | | ||
| ----------------- | ----------- | ------------------------------------------------ | | ||
| `id` | `string` | API key ID. | | ||
| `options` | `object?` | API key options. | | ||
| `options.domains` | `string[]?` | Domain or IP restriction (for public keys only). | | ||
@@ -581,8 +586,8 @@ | ||
```js | ||
pk.keys.delete('<key-id>'); | ||
pk.keys.delete("<key-id>"); | ||
``` | ||
| Parameter | Type | Description | | ||
| --- | --- | --- | | ||
| `id` | `string` | API key ID. | | ||
| Parameter | Type | Description | | ||
| --------- | -------- | ----------- | | ||
| `id` | `string` | API key ID. | | ||
@@ -589,0 +594,0 @@ ## ⚖️ License |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
59973
0
894
564
9
4
- Removed@rollup/plugin-replace@^5.0.2
- Removed@jridgewell/sourcemap-codec@1.5.0(transitive)
- Removed@rollup/plugin-replace@5.0.7(transitive)
- Removed@rollup/pluginutils@5.1.4(transitive)
- Removed@types/estree@1.0.6(transitive)
- Removedestree-walker@2.0.2(transitive)
- Removedmagic-string@0.30.17(transitive)
- Removedpicomatch@4.0.2(transitive)