@whereq/cloud 0.5.0 → 0.6.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/README.md +42 -0
- package/dist/index.cjs +55 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +217 -19
- package/dist/index.d.ts +217 -19
- package/dist/index.js +55 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -43,6 +43,14 @@ await wq.lotteryDraws({ game: "ny_lotto", days: 30 });
|
|
|
43
43
|
await wq.lotteryLatestDraw("ny_lotto");
|
|
44
44
|
await wq.lotteryFrequency("ny_lotto", 365);
|
|
45
45
|
|
|
46
|
+
// Geography — places, drawable boundaries, and the containment hierarchy
|
|
47
|
+
await wq.geoPlaces({ kind: "ward", country: "CA" }); // "CA" or "CAN" — either finds Canada
|
|
48
|
+
await wq.geoPlace("osm:r1428125"); // one place + its parents + its children
|
|
49
|
+
await wq.geoBoundary("osm:r1428125", { simplify: 50 });// GeoJSON, simplification in METRES
|
|
50
|
+
await wq.geoAt(-79.38, 43.65); // every place containing a point
|
|
51
|
+
await wq.geoConcepts(); // the vocabulary, with live counts
|
|
52
|
+
await wq.geoOverlaps({ bbox: "-79.6,43.5,-79.2,43.8" }); // pairs covering the same ground
|
|
53
|
+
|
|
46
54
|
// Discovery
|
|
47
55
|
await wq.catalog(); await wq.categories(); await wq.regions(); await wq.domains();
|
|
48
56
|
|
|
@@ -93,6 +101,40 @@ Products are `regular`, `midgrade`, `premium` and `diesel` — `FUEL_PRODUCTS`,
|
|
|
93
101
|
(EIA weekly for the US, StatCan monthly for Canada, CRE for Mexico), not
|
|
94
102
|
station-level prices.
|
|
95
103
|
|
|
104
|
+
## Geography
|
|
105
|
+
|
|
106
|
+
Provinces, regions, municipalities, cities, towns, wards and neighbourhoods —
|
|
107
|
+
with real, drawable boundaries, and with the places that cover the same ground
|
|
108
|
+
kept side by side rather than merged into one.
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
// The place list. "CA" and "CAN" find the same country, in both vocabularies.
|
|
112
|
+
await wq.geoPlaces({ kind: "city", country: "CA", limit: 50 });
|
|
113
|
+
await wq.geoPlaces({ source: "osm", has_boundary: true }); // only places with an outline
|
|
114
|
+
|
|
115
|
+
// One place: its containers AND the places inside it
|
|
116
|
+
const detail = await wq.geoPlace("osm:r1428125");
|
|
117
|
+
console.log(detail.place.name, detail.parents.length, detail.children.length);
|
|
118
|
+
|
|
119
|
+
// The outline as GeoJSON — simplification is in METRES
|
|
120
|
+
await wq.geoBoundary("osm:r1428125", { simplify: 50 });
|
|
121
|
+
|
|
122
|
+
// "Which district is this?" — every container, broadest first, none picked
|
|
123
|
+
const stack = await wq.geoAt(-79.38, 43.65);
|
|
124
|
+
for (const place of stack.places) {
|
|
125
|
+
console.log(place.kind, place.name, place.country_code);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// The vocabulary, and the pairs of places covering the same ground
|
|
129
|
+
await wq.geoConcepts();
|
|
130
|
+
await wq.geoOverlaps({ bbox: "-79.6,43.5,-79.2,43.8", min_ratio: 0.2 });
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
A place belongs to **several** things at once — a neighbourhood is in a ward,
|
|
134
|
+
in a city, in a census division, in a province and in a country. `parents` is an
|
|
135
|
+
array on purpose. `bbox` is required on `geoOverlaps()`: comparing every pair in
|
|
136
|
+
the country is a quadratic join.
|
|
137
|
+
|
|
96
138
|
## License
|
|
97
139
|
|
|
98
140
|
MIT © WhereQ
|
package/dist/index.cjs
CHANGED
|
@@ -2,8 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
// package.json
|
|
6
|
+
var package_default = {
|
|
7
|
+
version: "0.6.0"};
|
|
8
|
+
|
|
5
9
|
// src/index.ts
|
|
6
|
-
var VERSION =
|
|
10
|
+
var VERSION = package_default.version;
|
|
7
11
|
var DEFAULT_BASE_URL = "https://api.whereq.cloud";
|
|
8
12
|
var FUEL_PRODUCTS = ["regular", "midgrade", "premium", "diesel"];
|
|
9
13
|
var FUEL_COUNTRIES = ["MX", "US", "CA"];
|
|
@@ -207,6 +211,56 @@ var Whereq = class {
|
|
|
207
211
|
fuelPrices(p = {}) {
|
|
208
212
|
return this.get("/v1/prices", { domain: "fuel", ...p });
|
|
209
213
|
}
|
|
214
|
+
// -- geography (places, boundaries, hierarchy) ------------------------------
|
|
215
|
+
/** The place list — provinces, regions, municipalities, cities, towns,
|
|
216
|
+
* wards, neighbourhoods, countries.
|
|
217
|
+
*
|
|
218
|
+
* `country` takes an ISO code and either spelling works: `"CA"` and
|
|
219
|
+
* `"CAN"` find the same places, in both vocabularies.
|
|
220
|
+
*/
|
|
221
|
+
geoPlaces(p = {}) {
|
|
222
|
+
return this.get("/v1/geo/places", p);
|
|
223
|
+
}
|
|
224
|
+
/** One place, with its containers AND the places inside it.
|
|
225
|
+
*
|
|
226
|
+
* The parents are a list on purpose: a place belongs to several things
|
|
227
|
+
* at once.
|
|
228
|
+
*/
|
|
229
|
+
geoPlace(uid) {
|
|
230
|
+
return this.get(`/v1/geo/places/${encodeURIComponent(uid)}`);
|
|
231
|
+
}
|
|
232
|
+
/** A place's outline as GeoJSON.
|
|
233
|
+
*
|
|
234
|
+
* `simplify` is in METRES: the outline keeps every corner more than
|
|
235
|
+
* that far from the original, and the result is still a valid polygon.
|
|
236
|
+
*/
|
|
237
|
+
geoBoundary(uid, p = {}) {
|
|
238
|
+
return this.get(`/v1/geo/places/${encodeURIComponent(uid)}/boundary`, p);
|
|
239
|
+
}
|
|
240
|
+
/** Every place containing a point, broadest first.
|
|
241
|
+
*
|
|
242
|
+
* The answer to "which district is this?" without picking a winner: a
|
|
243
|
+
* point downtown Toronto lands in a neighbourhood, a ward, a city, a
|
|
244
|
+
* census division, a province and a country, and all of them are
|
|
245
|
+
* returned.
|
|
246
|
+
*/
|
|
247
|
+
geoAt(lon, lat) {
|
|
248
|
+
return this.get("/v1/geo/at", { lon, lat });
|
|
249
|
+
}
|
|
250
|
+
/** The vocabulary: every concept, in both languages, with a live count of
|
|
251
|
+
* how many places and outlines it has. */
|
|
252
|
+
geoConcepts() {
|
|
253
|
+
return this.get("/v1/geo/concepts");
|
|
254
|
+
}
|
|
255
|
+
/** The places of different kinds that cover the same ground.
|
|
256
|
+
*
|
|
257
|
+
* `bbox` is required — "minLon,minLat,maxLon,maxLat". Comparing every
|
|
258
|
+
* pair in the country is a quadratic join, and nobody asks that
|
|
259
|
+
* question about all of Canada at once.
|
|
260
|
+
*/
|
|
261
|
+
geoOverlaps(p) {
|
|
262
|
+
return this.get("/v1/geo/overlaps", p);
|
|
263
|
+
}
|
|
210
264
|
};
|
|
211
265
|
var index_default = Whereq;
|
|
212
266
|
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAiBO,IAAM,OAAA,GAAU;AACvB,IAAM,gBAAA,GAAmB,0BAAA;AAIlB,IAAM,aAAA,GAAgB,CAAC,SAAA,EAAW,UAAA,EAAY,WAAW,QAAQ;AAIjE,IAAM,cAAA,GAAiB,CAAC,IAAA,EAAM,IAAA,EAAM,IAAI;AAIxC,IAAM,eAAA,GAA+C;AAAA,EAC1D,EAAA,EAAI,OAAA;AAAA,EACJ,EAAA,EAAI,OAAA;AAAA,EACJ,EAAA,EAAI;AACN;AA4HO,IAAM,WAAA,GAAN,cAA0B,KAAA,CAAM;AAAA,EACrC,WAAA,CACkB,MAAA,EAChB,OAAA,EACgB,GAAA,EAChB;AACA,IAAA,KAAA,CAAM,0BAA0B,MAAM,CAAA,KAAA,EAAQ,GAAG,CAAA,EAAA,EAAK,OAAO,CAAA,CAAE,CAAA;AAJ/C,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AAEA,IAAA,IAAA,CAAA,GAAA,GAAA,GAAA;AAGhB,IAAA,IAAA,CAAK,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AK,GAAA,CAAI,MAAA,CAAO,CAAA,CAAE,KAAA,IAAS,GAAG,CAAA,EAAG,CAAC,CAAA,EAAG,GAAG,CAAA;AAClE,IAAA,IAAI,MAAA,GAAS,MAAA,CAAO,CAAA,CAAE,MAAA,IAAU,CAAC,CAAA;AACjC,IAAA,WAAS;AACP,MAAA,MAAM,IAAA,GAAO,MAAM,IAAA,CAAK,YAAA,CAAa,EAAE,GAAG,CAAA,EAAG,KAAA,EAAO,QAAA,EAAU,MAAA,EAAQ,CAAA;AACtE,MAAA,MAAM,QAAA,GAAW,IAAA,CAAK,QAAA,IAAY,EAAC;AACnC,MAAA,IAAI,QAAA,CAAS,WAAW,CAAA,EAAG;AAC3B,MAAA,KAAA,MAAW,CAAA,IAAK,UAAU,MAAM,CAAA;AAChC,MAAA,IAAI,KAAK,IAAA,EAAM;AACf,MAAA,MAAA,IAAU,QAAA,CAAS,MAAA;AACnB,MAAA,IAAI,IAAA,CAAK,KAAA,IAAS,IAAA,IAAQ,MAAA,IAAU,KAAK,KAAA,EAAO;AAAA,IAClD;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,UAAA,CAAW,CAAA,GAA+B,EAAC,EAAiC;AAC1E,IAAA,OAAO,IAAA,CAAK,IAAyB,YAAA,EAAc,EAAE,QAAQ,MAAA,EAAQ,GAAG,GAAG,CAAA;AAAA,EAC7E;AACF;AAEA,IAAO,aAAA,GAAQ","file":"index.cjs","sourcesContent":["/**\n * whereq.cloud — official JavaScript/TypeScript SDK for the WhereQ data cloud.\n *\n * A thin, typed wrapper over the versioned `/v1` HTTP API at `api.whereq.cloud`.\n * Public endpoints work with no key; metered endpoints take an API key.\n *\n * ```ts\n * import { Whereq } from \"@whereq/cloud\";\n *\n * const wq = new Whereq(); // public access\n * // const wq = new Whereq({ apiKey: \"wq_live_…\" }); // metered tier\n *\n * await wq.costOfLiving(\"us:California,ca:Ontario\");\n * await wq.prices({ domain: \"rent\", region: \"us\", bedrooms: 2 });\n * await wq.get(\"/v1/trending\", { limit: 10 }); // escape hatch\n * ```\n */\nexport const VERSION = \"0.5.0\";\nconst DEFAULT_BASE_URL = \"https://api.whereq.cloud\";\n\n/** The products a station can quote. Mexico's CRE feed carries the first,\n * second and fourth; GasBuddy (US/Canada) adds midgrade. */\nexport const FUEL_PRODUCTS = [\"regular\", \"midgrade\", \"premium\", \"diesel\"] as const;\nexport type FuelProduct = (typeof FUEL_PRODUCTS)[number];\n\n/** Countries with station-level fuel data. */\nexport const FUEL_COUNTRIES = [\"MX\", \"US\", \"CA\"] as const;\nexport type FuelCountry = (typeof FUEL_COUNTRIES)[number];\n\n/** The unit each country quotes in — always local currency per litre. */\nexport const FUEL_CURRENCIES: Record<FuelCountry, string> = {\n MX: \"MXN/L\",\n US: \"USD/L\",\n CA: \"CAD/L\",\n};\n\n/** One product's latest price at a station. */\nexport interface FuelStationPrice {\n price: number;\n observed_at: string;\n}\n\n/** A geolocated retail fuel station and its latest prices.\n * `state` is the human label (\"Ontario\", \"Texas\"); `state_iso` is the\n * two-letter code (\"ON\", \"TX\"). */\nexport interface FuelStation {\n id: number;\n source: string;\n ext_id: string;\n country: string;\n name: string;\n brand?: string | null;\n state?: string | null;\n state_iso?: string | null;\n municipality?: string | null;\n lat?: number | null;\n lon?: number | null;\n prices: Record<string, FuelStationPrice>;\n}\n\n/** Filters for `fuelStations()`. */\nexport interface FuelStationsParams {\n /** \"MX\", \"US\" or \"CA\". */\n country?: FuelCountry | string;\n /** State/province name *or* ISO code — \"Ontario\"/\"ON\", \"Texas\"/\"TX\". */\n state?: string;\n /** City name, e.g. \"Mississauga\". */\n municipality?: string;\n product?: FuelProduct | string;\n /** \"minLon,minLat,maxLon,maxLat\" — a map viewport. */\n bbox?: string;\n /** Station-name search. */\n q?: string;\n /** 1–500 rows per page (default 100). */\n limit?: number;\n /** Row offset for paging. */\n offset?: number;\n}\n\n/** Filters for `fuelStation()`. */\nexport interface FuelStationParams {\n /** Restrict the timeline to one product. */\n product?: FuelProduct | string;\n /** How far back the timeline reaches (1–1825, default 90). */\n days?: number;\n}\n\n/** `GET /v1/fuel/stations`. Unentitled callers get a 100-row preview of the\n * oldest rows: `demo` is true, `total` is null and paging is ignored. */\nexport interface FuelStationsResponse {\n demo?: boolean;\n preview_rows?: number;\n note?: string;\n upgrade_url?: string;\n as_of: string;\n count: number;\n total?: number | null;\n stations: FuelStation[];\n}\n\n/** One observed price change — the intra-day timeline for a station. */\nexport interface FuelStationPricePoint {\n product: string;\n observed_at: string;\n price: number;\n}\n\n/** `GET /v1/fuel/stations/{id}`. `days` is null in the unentitled preview. */\nexport interface FuelStationDetail {\n demo?: boolean;\n preview_rows?: number;\n note?: string;\n upgrade_url?: string;\n station: FuelStation;\n days?: number | null;\n prices: FuelStationPricePoint[];\n}\n\n/** Filters for `fuelPrices()`. */\nexport interface FuelPricesParams {\n /** Region slug, or a comma-separated list of them (\"us,ca\"). */\n region?: string;\n /** Free-text place name (\"Calgary, Alberta\"). */\n geo?: string;\n q?: string;\n limit?: number;\n offset?: number;\n}\n\n/** One aggregated price series (state / national / metro). */\nexport interface PriceSeries {\n id: number;\n domain: string;\n source: string;\n region?: string | null;\n geo?: string | null;\n item: string;\n item_cn?: string | null;\n unit?: string | null;\n unit_cn?: string | null;\n frequency?: string | null;\n latest_period?: string | null;\n latest_value?: number | null;\n prev_value?: number | null;\n points?: number | null;\n spark?: number[];\n}\n\n/** `GET /v1/prices` — a page of series plus the page's own metadata. */\nexport interface PriceSeriesResponse {\n count: number;\n domain?: string | null;\n region?: string | null;\n limit: number;\n offset: number;\n data: PriceSeries[];\n}\n\nexport class WhereqError extends Error {\n constructor(\n public readonly status: number,\n message: string,\n public readonly url: string,\n ) {\n super(`whereq.cloud API error ${status} for ${url}: ${message}`);\n this.name = \"WhereqError\";\n }\n}\n\nexport interface ClientOptions {\n /** `wq_live_…` key for metered endpoints (sent as `X-API-Key`). */\n apiKey?: string;\n /** Override the API base (default `https://api.whereq.cloud`). */\n baseUrl?: string;\n /** Custom fetch (e.g. for Node <18 or testing). Defaults to global `fetch`. */\n fetch?: typeof fetch;\n}\n\ntype Params = Record<string, unknown>;\n\n/** The API key from the environment, when there is one. */\nfunction envApiKey(): string {\n const proc = (globalThis as { process?: { env?: Record<string, string | undefined> } }).process;\n return proc?.env?.WHEREQ_API_KEY ?? \"\";\n}\n\nexport class Whereq {\n private readonly baseUrl: string;\n private readonly headers: Record<string, string>;\n private readonly _fetch: typeof fetch;\n\n constructor(opts: ClientOptions = {}) {\n this.baseUrl = (opts.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n this.headers = { Accept: \"application/json\" };\n // The key may come from the options or the environment, in that order.\n const key = opts.apiKey ?? envApiKey();\n if (key) this.headers[\"X-API-Key\"] = key;\n const f = opts.fetch ?? globalThis.fetch;\n if (!f) throw new Error(\"No global fetch available — pass `fetch` in options (Node <18).\");\n this._fetch = f;\n }\n\n private url(path: string, params: Params): string {\n const qs = new URLSearchParams();\n for (const [k, v] of Object.entries(params)) {\n if (v !== undefined && v !== null) qs.set(k, String(v));\n }\n const s = qs.toString();\n return `${this.baseUrl}${path}${s ? `?${s}` : \"\"}`;\n }\n\n /** GET any endpoint; `undefined`/`null` params are dropped. Returns parsed JSON. */\n async get<T = unknown>(path: string, params: Params = {}): Promise<T> {\n const url = this.url(path, params);\n const res = await this._fetch(url, { headers: this.headers });\n if (!res.ok) {\n let msg = res.statusText;\n try {\n const j = (await res.json()) as { detail?: string };\n msg = j?.detail || JSON.stringify(j) || msg;\n } catch {\n /* non-JSON error body */\n }\n throw new WhereqError(res.status, msg, url);\n }\n return (await res.json()) as T;\n }\n\n /** GET a non-JSON endpoint (e.g. CSV export) as text. */\n async getText(path: string, params: Params = {}): Promise<string> {\n const url = this.url(path, params);\n const res = await this._fetch(url, { headers: this.headers });\n if (!res.ok) throw new WhereqError(res.status, res.statusText, url);\n return res.text();\n }\n\n // -- prices / cost of living ------------------------------------------------\n /** Cost-of-living price series (fuel | food | energy | housing | rent).\n * `region` takes a region slug or a comma-separated list (\"us,ca\");\n * `geo` is a free-text place name (\"Calgary, Alberta\"). */\n prices(p: { domain?: string; region?: string; geo?: string; bedrooms?: number; q?: string; limit?: number; offset?: number } = {}): Promise<PriceSeriesResponse> {\n return this.get<PriceSeriesResponse>(\"/v1/prices\", p);\n }\n price(seriesId: number) {\n return this.get(`/v1/prices/${seriesId}`);\n }\n pricesCsv(p: { domain?: string; region?: string; geo?: string; bedrooms?: number; q?: string } = {}) {\n return this.getText(\"/v1/prices/export\", p);\n }\n /** Compare cost of living across US states / CA provinces / metros.\n * `places`: comma-separated `region:name` or `m:<rent-series-id>`. */\n costOfLiving(places: string) {\n return this.get(\"/v1/cost-of-living\", { places });\n }\n\n // -- discovery / facets -----------------------------------------------------\n catalog() { return this.get(\"/v1/catalog\"); }\n categories() { return this.get(\"/v1/categories\"); }\n regions() { return this.get(\"/v1/regions\"); }\n domains() { return this.get(\"/v1/domains\"); }\n trending(p: Params = {}) { return this.get(\"/v1/trending\", p); }\n\n // -- finance ----------------------------------------------------------------\n hotstocks(limit = 20) { return this.get(\"/v1/hotstocks\", { limit }); }\n quotes(p: Params = {}) { return this.get(\"/v1/quotes\", p); }\n news(p: Params = {}) { return this.get(\"/v1/news\", p); }\n screener(p: Params = {}) { return this.get(\"/v1/screener\", p); }\n search(q: string, p: Params = {}) { return this.get(\"/v1/search\", { q, ...p }); }\n\n // -- autos ------------------------------------------------------------------\n autosRecalls(p: Params = {}) { return this.get(\"/v1/autos/recalls\", p); }\n autosListings(p: Params = {}) { return this.get(\"/v1/autos/listings\", p); }\n autosFuelEconomy(p: Params = {}) { return this.get(\"/v1/autos/fuel-economy\", p); }\n autosModels(p: Params = {}) { return this.get(\"/v1/autos/models\", p); }\n\n // -- lottery -----------------------------------------------------------------\n /** Recent lottery draws, newest first.\n *\n * Unentitled callers get the oldest 100 draws instead of the recent\n * ones — check `response.demo`.\n */\n lotteryDraws(p: { game?: string; days?: number; limit?: number } & Params = {}): Promise<any> {\n return this.get(\"/v1/lottery/draws\", p);\n }\n /** The most recent draw for a game. On the unentitled preview this is the\n * *oldest* draw — the recent one is the gated, valuable row. */\n lotteryLatestDraw(game: string): Promise<any> {\n return this.get(`/v1/lottery/draws/${encodeURIComponent(game)}/latest`);\n }\n /** Per-number frequency for a game over a window (30–1825 days). */\n lotteryFrequency(game: string, days = 365): Promise<any> {\n return this.get(`/v1/lottery/draws/${encodeURIComponent(game)}/frequency`, { days });\n }\n /** The lottery game registry: names, play rules and draw days. */\n lotteryGames(p: { country?: string; region?: string } & Params = {}): Promise<any> {\n return this.get(\"/v1/lottery/games\", p);\n }\n /** One game's full play rules and metadata. */\n lotteryGame(slug: string): Promise<any> {\n return this.get(`/v1/lottery/games/${encodeURIComponent(slug)}`);\n }\n\n // -- fuel (gas & diesel) ----------------------------------------------------\n /** Geolocated retail fuel stations with their latest prices.\n *\n * Coverage: Mexico (`MX`, CRE open data), the United States (`US`) and\n * Canada (`CA`). Prices are in **local currency per litre** — `MXN/L`,\n * `USD/L` and `CAD/L` respectively.\n *\n * Unentitled callers get a 100-row preview of the oldest rows and the\n * pagination arguments are ignored — check `response.demo`.\n */\n fuelStations(p: FuelStationsParams & Params = {}): Promise<FuelStationsResponse> {\n return this.get<FuelStationsResponse>(\"/v1/fuel/stations\", p);\n }\n\n /** One station: location, latest prices and its price-change timeline. */\n fuelStation(\n id: number | string,\n p: FuelStationParams & Params = {},\n ): Promise<FuelStationDetail> {\n return this.get<FuelStationDetail>(\n `/v1/fuel/stations/${encodeURIComponent(String(id))}`,\n p,\n );\n }\n\n /** Yield every matching station, paging through the API for you.\n *\n * Only meaningful with an entitled key. The unentitled preview always\n * returns the *same* oldest 100 rows and ignores the paging arguments,\n * so there is nothing more to fetch: this yields that first page and\n * stops rather than looping on it.\n */\n async *fuelStationsAll(\n p: FuelStationsParams & Params = {},\n ): AsyncGenerator<FuelStation> {\n const pageSize = Math.min(Math.max(Number(p.limit ?? 500), 1), 500);\n let offset = Number(p.offset ?? 0);\n for (;;) {\n const page = await this.fuelStations({ ...p, limit: pageSize, offset });\n const stations = page.stations ?? [];\n if (stations.length === 0) return;\n for (const s of stations) yield s;\n if (page.demo) return; // preview: every page is the same slice\n offset += stations.length;\n if (page.total != null && offset >= page.total) return;\n }\n }\n\n /** Aggregated fuel price series (state / national / metro).\n *\n * These are the *series* behind the charts — EIA weekly for the US,\n * StatCan monthly for Canada, CRE for Mexico — not the station-level\n * prices that `fuelStations()` returns.\n */\n fuelPrices(p: FuelPricesParams & Params = {}): Promise<PriceSeriesResponse> {\n return this.get<PriceSeriesResponse>(\"/v1/prices\", { domain: \"fuel\", ...p });\n }\n}\n\nexport default Whereq;\n"]}
|
|
1
|
+
{"version":3,"sources":["../package.json","../src/index.ts"],"names":[],"mappings":";;;;;AAAA,IAAA,eAAA,GAAA;AAAA,EAEE,OAAA,EAAW,OA+Db,CAAA;;;AC1CO,IAAM,UAAU,eAAA,CAAI;AAE3B,IAAM,gBAAA,GAAmB,0BAAA;AAIlB,IAAM,aAAA,GAAgB,CAAC,SAAA,EAAW,UAAA,EAAY,WAAW,QAAQ;AAIjE,IAAM,cAAA,GAAiB,CAAC,IAAA,EAAM,IAAA,EAAM,IAAI;AAIxC,IAAM,eAAA,GAA+C;AAAA,EAC1D,EAAA,EAAI,OAAA;AAAA,EACJ,EAAA,EAAI,OAAA;AAAA,EACJ,EAAA,EAAI;AACN;AAkTO,IAAM,WAAA,GAAN,cAA0B,KAAA,CAAM;AAAA,EACrC,WAAA,CACkB,MAAA,EAChB,OAAA,EACgB,GAAA,EAChB;AACA,IAAA,KAAA,CAAM,0BAA0B,MAAM,CAAA,KAAA,EAAQ,GAAG,CAAA,EAAA,EAAK,OAAO,CAAA,CAAE,CAAA;AAJ/C,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AAEA,IAAA,IAAA,CAAA,GAAA,GAAA,GAAA;AAGhB,IAAA,IAAA,CAAK,IAAA,GAAO,aAAA;AAAA,EACd;AAAA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AAY,GAAA,EAAa,CAAA,GAAoC,EAAC,EAAyB;AACrF,IAAA,OAAO,KAAK,GAAA,CAAiB,CAAA,eAAA,EAAkB,mBAAmB,GAAG,CAAC,aAAa,CAAC,CAAA;AAAA,EACtF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,KAAA,CAAM,KAAa,GAAA,EAAqC;AACtD,IAAA,OAAO,KAAK,GAAA,CAAmB,YAAA,EAAc,EAAE,GAAA,EAAK,KAAK,CAAA;AAAA,EAC3D;AAAA;AAAA;AAAA,EAIA,WAAA,GAAuC;AACrC,IAAA,OAAO,IAAA,CAAK,IAAoB,kBAAkB,CAAA;AAAA,EACpD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,YACE,CAAA,EACyB;AACzB,IAAA,OAAO,IAAA,CAAK,GAAA,CAAoB,kBAAA,EAAoB,CAAC,CAAA;AAAA,EACvD;AACF;AAEA,IAAO,aAAA,GAAQ","file":"index.cjs","sourcesContent":["{\n \"name\": \"@whereq/cloud\",\n \"version\": \"0.6.0\",\n \"packageManager\": \"pnpm@9.15.9\",\n \"description\": \"Official JavaScript/TypeScript SDK for the WhereQ data cloud (api.whereq.cloud) — North-America fuel & gas-station prices, cost-of-living prices, autos, lottery, trending, finance & more.\",\n \"license\": \"MIT\",\n \"author\": \"WhereQ <whereq@gmail.com>\",\n \"type\": \"module\",\n \"main\": \"./dist/index.cjs\",\n \"module\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"exports\": {\n \".\": {\n \"types\": \"./dist/index.d.ts\",\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n },\n \"./package.json\": \"./package.json\"\n },\n \"files\": [\n \"dist\",\n \"README.md\",\n \"LICENSE\"\n ],\n \"sideEffects\": false,\n \"engines\": {\n \"node\": \">=18\"\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/whereq/whereq-cloud-js.git\"\n },\n \"homepage\": \"https://whereq.cloud\",\n \"bugs\": \"https://github.com/whereq/whereq-cloud-js/issues\",\n \"keywords\": [\n \"whereq\",\n \"data\",\n \"api\",\n \"fuel-prices\",\n \"gas-prices\",\n \"cost-of-living\",\n \"prices\",\n \"autos\",\n \"trending\",\n \"finance\",\n \"sdk\"\n ],\n \"scripts\": {\n \"build\": \"tsup\",\n \"typecheck\": \"tsc --noEmit\",\n \"test\": \"vitest run\",\n \"verify\": \"pnpm run typecheck && pnpm run test && pnpm run build\",\n \"release\": \"pnpm run build && changeset publish\",\n \"prepublishOnly\": \"pnpm run build\"\n },\n \"devDependencies\": {\n \"@changesets/cli\": \"^2.27.9\",\n \"tsup\": \"^8.3.0\",\n \"typescript\": \"^5.7.2\",\n \"vitest\": \"^2.1.0\"\n },\n \"publishConfig\": {\n \"access\": \"public\",\n \"provenance\": true\n }\n}\n","/**\n * whereq.cloud — official JavaScript/TypeScript SDK for the WhereQ data cloud.\n *\n * A thin, typed wrapper over the versioned `/v1` HTTP API at `api.whereq.cloud`.\n * Public endpoints work with no key; metered endpoints take an API key.\n *\n * ```ts\n * import { Whereq } from \"@whereq/cloud\";\n *\n * const wq = new Whereq(); // public access\n * // const wq = new Whereq({ apiKey: \"wq_live_…\" }); // metered tier\n *\n * await wq.costOfLiving(\"us:California,ca:Ontario\");\n * await wq.prices({ domain: \"rent\", region: \"us\", bedrooms: 2 });\n * await wq.get(\"/v1/trending\", { limit: 10 }); // escape hatch\n * ```\n */\nimport pkg from \"../package.json\";\n\n/**\n * The SDK version, read straight from `package.json` so it can never drift\n * from what is published. Changesets bumps `package.json`; this follows it.\n */\nexport const VERSION = pkg.version;\n\nconst DEFAULT_BASE_URL = \"https://api.whereq.cloud\";\n\n/** The products a station can quote. Mexico's CRE feed carries the first,\n * second and fourth; GasBuddy (US/Canada) adds midgrade. */\nexport const FUEL_PRODUCTS = [\"regular\", \"midgrade\", \"premium\", \"diesel\"] as const;\nexport type FuelProduct = (typeof FUEL_PRODUCTS)[number];\n\n/** Countries with station-level fuel data. */\nexport const FUEL_COUNTRIES = [\"MX\", \"US\", \"CA\"] as const;\nexport type FuelCountry = (typeof FUEL_COUNTRIES)[number];\n\n/** The unit each country quotes in — always local currency per litre. */\nexport const FUEL_CURRENCIES: Record<FuelCountry, string> = {\n MX: \"MXN/L\",\n US: \"USD/L\",\n CA: \"CAD/L\",\n};\n\n/** One product's latest price at a station. */\nexport interface FuelStationPrice {\n price: number;\n observed_at: string;\n}\n\n/** A geolocated retail fuel station.\n * `state` is the human label (\"Ontario\", \"Texas\"); `state_iso` is the\n * two-letter code (\"ON\", \"TX\"). */\nexport interface FuelStation {\n id: number;\n source: string;\n ext_id: string;\n country: string;\n name: string;\n brand?: string | null;\n state?: string | null;\n state_iso?: string | null;\n municipality?: string | null;\n lat?: number | null;\n lon?: number | null;\n /** The latest price per product — present on the *list* endpoint. The\n * *detail* endpoint omits it: its timeline comes back as the separate\n * `prices` array on the response. */\n prices?: Record<string, FuelStationPrice>;\n}\n\n/** Filters for `fuelStations()`. */\nexport interface FuelStationsParams {\n /** \"MX\", \"US\" or \"CA\". */\n country?: FuelCountry | string;\n /** State/province name *or* ISO code — \"Ontario\"/\"ON\", \"Texas\"/\"TX\". */\n state?: string;\n /** City name, e.g. \"Mississauga\". */\n municipality?: string;\n product?: FuelProduct | string;\n /** \"minLon,minLat,maxLon,maxLat\" — a map viewport. */\n bbox?: string;\n /** Station-name search. */\n q?: string;\n /** 1–500 rows per page (default 100). */\n limit?: number;\n /** Row offset for paging. */\n offset?: number;\n}\n\n/** Filters for `fuelStation()`. */\nexport interface FuelStationParams {\n /** Restrict the timeline to one product. */\n product?: FuelProduct | string;\n /** How far back the timeline reaches (1–1825, default 90). */\n days?: number;\n}\n\n/** `GET /v1/fuel/stations`. Unentitled callers get a 100-row preview of the\n * oldest rows: `demo` is true, `total` is null and paging is ignored. */\nexport interface FuelStationsResponse {\n demo?: boolean;\n preview_rows?: number;\n note?: string;\n upgrade_url?: string;\n as_of: string;\n count: number;\n total?: number | null;\n stations: FuelStation[];\n}\n\n/** One observed price change — the intra-day timeline for a station. */\nexport interface FuelStationPricePoint {\n product: string;\n observed_at: string;\n price: number;\n}\n\n/** `GET /v1/fuel/stations/{id}`. `days` is null in the unentitled preview. */\nexport interface FuelStationDetail {\n demo?: boolean;\n preview_rows?: number;\n note?: string;\n upgrade_url?: string;\n station: FuelStation;\n days?: number | null;\n prices: FuelStationPricePoint[];\n}\n\n/** Filters for `fuelPrices()`. */\nexport interface FuelPricesParams {\n /** Region slug, or a comma-separated list of them (\"us,ca\"). */\n region?: string;\n /** Free-text place name (\"Calgary, Alberta\"). */\n geo?: string;\n q?: string;\n limit?: number;\n offset?: number;\n}\n\n/** One aggregated price series (state / national / metro). */\nexport interface PriceSeries {\n id: number;\n domain: string;\n source: string;\n region?: string | null;\n geo?: string | null;\n item: string;\n item_cn?: string | null;\n unit?: string | null;\n unit_cn?: string | null;\n frequency?: string | null;\n latest_period?: string | null;\n latest_value?: number | null;\n prev_value?: number | null;\n points?: number | null;\n spark?: number[];\n}\n\n/** `GET /v1/prices` — a page of series plus the page's own metadata. */\nexport interface PriceSeriesResponse {\n count: number;\n domain?: string | null;\n region?: string | null;\n limit: number;\n offset: number;\n data: PriceSeries[];\n}\n\n// -- geography (places, boundaries, hierarchy) ---------------------------------\n\n/** One place — a province, a municipality, a ward, a neighbourhood.\n *\n * `kind` is the platform's own concept (`province`, `region`,\n * `municipality`, `city`, `town`, `ward`, `neighbourhood`…), not the\n * source's admin level. `country_code` is the two-letter ISO code and is\n * the same for both vocabularies — a country filter accepts `CA` or\n * `CAN` and answers with the same places either way.\n */\nexport interface GeoPlace {\n uid: string;\n kind: string;\n kind_source: string;\n name: string;\n name_en?: string | null;\n name_zh?: string | null;\n name_local?: string | null;\n official_name?: string | null;\n source: string;\n source_id: string;\n source_url?: string | null;\n license?: string | null;\n raw_admin_level?: number | null;\n raw_place?: string | null;\n raw_boundary?: string | null;\n country_code?: string | null;\n province_code?: string | null;\n iso_code?: string | null;\n ref?: string | null;\n population?: number | null;\n population_date?: string | null;\n wikidata?: string | null;\n wikipedia?: string | null;\n website?: string | null;\n capital?: string | null;\n centroid_lon?: number | null;\n centroid_lat?: number | null;\n bbox_min_lon?: number | null;\n bbox_min_lat?: number | null;\n bbox_max_lon?: number | null;\n bbox_max_lat?: number | null;\n area_km2?: number | null;\n has_boundary: boolean;\n}\n\nexport interface GeoPlaceList {\n count: number;\n data: GeoPlace[];\n limit: number;\n offset: number;\n}\n\n/** One container of a place, as the detail endpoint lists them.\n *\n * A place has SEVERAL parents — a neighbourhood is in a ward, in a city,\n * in a census division and in a province, all at once. The list is\n * deliberately a list.\n */\nexport interface GeoParent {\n uid: string;\n kind: string;\n name: string;\n source: string;\n area_ratio?: number | null;\n is_primary: boolean;\n}\n\n/** One place with its containers and the places inside it. */\nexport interface GeoPlaceDetail {\n uid: string;\n place: GeoPlace;\n parents: GeoParent[];\n children: GeoParent[];\n}\n\n/** One concept in the vocabulary, with a live count behind it. */\nexport interface GeoConcept {\n kind: string;\n name: string;\n name_cn?: string | null;\n description?: string | null;\n description_cn?: string | null;\n places: number;\n with_boundary: number;\n rank: number;\n}\n\n/** The vocabulary, explained. */\nexport interface GeoConceptList {\n count: number;\n concepts: GeoConcept[];\n sources: Array<Record<string, unknown>>;\n}\n\n/** Two places of DIFFERENT kinds covering the same ground.\n *\n * This is the deliberate part of the dataset: a census subdivision and\n * an OpenStreetMap city boundary that describe the same town in two\n * vocabularies. The platform keeps both rather than picking one.\n */\nexport interface GeoOverlap {\n a_id: number;\n b_id: number;\n a_uid: string;\n b_uid: string;\n a_name: string;\n b_name: string;\n a_kind: string;\n b_kind: string;\n a_source: string;\n b_source: string;\n overlap_ratio: number;\n a_concept: string;\n b_concept: string;\n}\n\n/** The overlapping pairs inside a box. */\nexport interface GeoOverlapList {\n bbox: Record<string, number>;\n min_ratio: number;\n count: number;\n overlaps: GeoOverlap[];\n}\n\n/** One place in the containing stack at a point.\n *\n * `country_code` is on every level, so the stack can be read without a\n * second lookup.\n */\nexport interface GeoAtPlace {\n uid: string;\n kind: string;\n kind_source: string;\n name: string;\n name_en?: string | null;\n name_zh?: string | null;\n source: string;\n raw_admin_level?: number | null;\n raw_place?: string | null;\n population?: number | null;\n wikidata?: string | null;\n centroid_lon?: number | null;\n centroid_lat?: number | null;\n area_km2?: number | null;\n country_code?: string | null;\n province_code?: string | null;\n boundary_area_km2?: number | null;\n concept?: Record<string, unknown>;\n}\n\n/** Every place containing a point, broadest first: country, province,\n * region, municipality, city, ward, neighbourhood. The answer to \"where\n * am I?\" without pretending one of them is *the* answer. */\nexport interface GeoAtResponse {\n lon: number;\n lat: number;\n count: number;\n places: GeoAtPlace[];\n}\n\n/** A place's outline as GeoJSON — a FeatureCollection you can hand\n * straight to a map library. */\nexport interface GeoBoundary {\n type: string;\n features: Array<Record<string, unknown>>;\n}\n\nexport interface GeoPlacesParams {\n kind?: string;\n source?: string;\n country?: string;\n q?: string;\n bbox?: string;\n has_boundary?: boolean;\n limit?: number;\n offset?: number;\n}\n\nexport class WhereqError extends Error {\n constructor(\n public readonly status: number,\n message: string,\n public readonly url: string,\n ) {\n super(`whereq.cloud API error ${status} for ${url}: ${message}`);\n this.name = \"WhereqError\";\n }\n}\n\nexport interface ClientOptions {\n /** `wq_live_…` key for metered endpoints (sent as `X-API-Key`). */\n apiKey?: string;\n /** Override the API base (default `https://api.whereq.cloud`). */\n baseUrl?: string;\n /** Custom fetch (e.g. for Node <18 or testing). Defaults to global `fetch`. */\n fetch?: typeof fetch;\n}\n\ntype Params = Record<string, unknown>;\n\n/** The API key from the environment, when there is one. */\nfunction envApiKey(): string {\n const proc = (globalThis as { process?: { env?: Record<string, string | undefined> } }).process;\n return proc?.env?.WHEREQ_API_KEY ?? \"\";\n}\n\nexport class Whereq {\n private readonly baseUrl: string;\n private readonly headers: Record<string, string>;\n private readonly _fetch: typeof fetch;\n\n constructor(opts: ClientOptions = {}) {\n this.baseUrl = (opts.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n this.headers = { Accept: \"application/json\" };\n // The key may come from the options or the environment, in that order.\n const key = opts.apiKey ?? envApiKey();\n if (key) this.headers[\"X-API-Key\"] = key;\n const f = opts.fetch ?? globalThis.fetch;\n if (!f) throw new Error(\"No global fetch available — pass `fetch` in options (Node <18).\");\n this._fetch = f;\n }\n\n private url(path: string, params: Params): string {\n const qs = new URLSearchParams();\n for (const [k, v] of Object.entries(params)) {\n if (v !== undefined && v !== null) qs.set(k, String(v));\n }\n const s = qs.toString();\n return `${this.baseUrl}${path}${s ? `?${s}` : \"\"}`;\n }\n\n /** GET any endpoint; `undefined`/`null` params are dropped. Returns parsed JSON. */\n async get<T = unknown>(path: string, params: Params = {}): Promise<T> {\n const url = this.url(path, params);\n const res = await this._fetch(url, { headers: this.headers });\n if (!res.ok) {\n let msg = res.statusText;\n try {\n const j = (await res.json()) as { detail?: string };\n msg = j?.detail || JSON.stringify(j) || msg;\n } catch {\n /* non-JSON error body */\n }\n throw new WhereqError(res.status, msg, url);\n }\n return (await res.json()) as T;\n }\n\n /** GET a non-JSON endpoint (e.g. CSV export) as text. */\n async getText(path: string, params: Params = {}): Promise<string> {\n const url = this.url(path, params);\n const res = await this._fetch(url, { headers: this.headers });\n if (!res.ok) throw new WhereqError(res.status, res.statusText, url);\n return res.text();\n }\n\n // -- prices / cost of living ------------------------------------------------\n /** Cost-of-living price series (fuel | food | energy | housing | rent).\n * `region` takes a region slug or a comma-separated list (\"us,ca\");\n * `geo` is a free-text place name (\"Calgary, Alberta\"). */\n prices(p: { domain?: string; region?: string; geo?: string; bedrooms?: number; q?: string; limit?: number; offset?: number } = {}): Promise<PriceSeriesResponse> {\n return this.get<PriceSeriesResponse>(\"/v1/prices\", p);\n }\n price(seriesId: number) {\n return this.get(`/v1/prices/${seriesId}`);\n }\n pricesCsv(p: { domain?: string; region?: string; geo?: string; bedrooms?: number; q?: string } = {}) {\n return this.getText(\"/v1/prices/export\", p);\n }\n /** Compare cost of living across US states / CA provinces / metros.\n * `places`: comma-separated `region:name` or `m:<rent-series-id>`. */\n costOfLiving(places: string) {\n return this.get(\"/v1/cost-of-living\", { places });\n }\n\n // -- discovery / facets -----------------------------------------------------\n catalog() { return this.get(\"/v1/catalog\"); }\n categories() { return this.get(\"/v1/categories\"); }\n regions() { return this.get(\"/v1/regions\"); }\n domains() { return this.get(\"/v1/domains\"); }\n trending(p: Params = {}) { return this.get(\"/v1/trending\", p); }\n\n // -- finance ----------------------------------------------------------------\n hotstocks(limit = 20) { return this.get(\"/v1/hotstocks\", { limit }); }\n quotes(p: Params = {}) { return this.get(\"/v1/quotes\", p); }\n news(p: Params = {}) { return this.get(\"/v1/news\", p); }\n screener(p: Params = {}) { return this.get(\"/v1/screener\", p); }\n search(q: string, p: Params = {}) { return this.get(\"/v1/search\", { q, ...p }); }\n\n // -- autos ------------------------------------------------------------------\n autosRecalls(p: Params = {}) { return this.get(\"/v1/autos/recalls\", p); }\n autosListings(p: Params = {}) { return this.get(\"/v1/autos/listings\", p); }\n autosFuelEconomy(p: Params = {}) { return this.get(\"/v1/autos/fuel-economy\", p); }\n autosModels(p: Params = {}) { return this.get(\"/v1/autos/models\", p); }\n\n // -- lottery -----------------------------------------------------------------\n /** Recent lottery draws, newest first.\n *\n * Unentitled callers get the oldest 100 draws instead of the recent\n * ones — check `response.demo`.\n */\n lotteryDraws(p: { game?: string; days?: number; limit?: number } & Params = {}): Promise<any> {\n return this.get(\"/v1/lottery/draws\", p);\n }\n /** The most recent draw for a game. On the unentitled preview this is the\n * *oldest* draw — the recent one is the gated, valuable row. */\n lotteryLatestDraw(game: string): Promise<any> {\n return this.get(`/v1/lottery/draws/${encodeURIComponent(game)}/latest`);\n }\n /** Per-number frequency for a game over a window (30–1825 days). */\n lotteryFrequency(game: string, days = 365): Promise<any> {\n return this.get(`/v1/lottery/draws/${encodeURIComponent(game)}/frequency`, { days });\n }\n /** The lottery game registry: names, play rules and draw days. */\n lotteryGames(p: { country?: string; region?: string } & Params = {}): Promise<any> {\n return this.get(\"/v1/lottery/games\", p);\n }\n /** One game's full play rules and metadata. */\n lotteryGame(slug: string): Promise<any> {\n return this.get(`/v1/lottery/games/${encodeURIComponent(slug)}`);\n }\n\n // -- fuel (gas & diesel) ----------------------------------------------------\n /** Geolocated retail fuel stations with their latest prices.\n *\n * Coverage: Mexico (`MX`, CRE open data), the United States (`US`) and\n * Canada (`CA`). Prices are in **local currency per litre** — `MXN/L`,\n * `USD/L` and `CAD/L` respectively.\n *\n * Unentitled callers get a 100-row preview of the oldest rows and the\n * pagination arguments are ignored — check `response.demo`.\n */\n fuelStations(p: FuelStationsParams & Params = {}): Promise<FuelStationsResponse> {\n return this.get<FuelStationsResponse>(\"/v1/fuel/stations\", p);\n }\n\n /** One station: location, latest prices and its price-change timeline. */\n fuelStation(\n id: number | string,\n p: FuelStationParams & Params = {},\n ): Promise<FuelStationDetail> {\n return this.get<FuelStationDetail>(\n `/v1/fuel/stations/${encodeURIComponent(String(id))}`,\n p,\n );\n }\n\n /** Yield every matching station, paging through the API for you.\n *\n * Only meaningful with an entitled key. The unentitled preview always\n * returns the *same* oldest 100 rows and ignores the paging arguments,\n * so there is nothing more to fetch: this yields that first page and\n * stops rather than looping on it.\n */\n async *fuelStationsAll(\n p: FuelStationsParams & Params = {},\n ): AsyncGenerator<FuelStation> {\n const pageSize = Math.min(Math.max(Number(p.limit ?? 500), 1), 500);\n let offset = Number(p.offset ?? 0);\n for (;;) {\n const page = await this.fuelStations({ ...p, limit: pageSize, offset });\n const stations = page.stations ?? [];\n if (stations.length === 0) return;\n for (const s of stations) yield s;\n if (page.demo) return; // preview: every page is the same slice\n offset += stations.length;\n if (page.total != null && offset >= page.total) return;\n }\n }\n\n /** Aggregated fuel price series (state / national / metro).\n *\n * These are the *series* behind the charts — EIA weekly for the US,\n * StatCan monthly for Canada, CRE for Mexico — not the station-level\n * prices that `fuelStations()` returns.\n */\n fuelPrices(p: FuelPricesParams & Params = {}): Promise<PriceSeriesResponse> {\n return this.get<PriceSeriesResponse>(\"/v1/prices\", { domain: \"fuel\", ...p });\n }\n\n // -- geography (places, boundaries, hierarchy) ------------------------------\n /** The place list — provinces, regions, municipalities, cities, towns,\n * wards, neighbourhoods, countries.\n *\n * `country` takes an ISO code and either spelling works: `\"CA\"` and\n * `\"CAN\"` find the same places, in both vocabularies.\n */\n geoPlaces(p: GeoPlacesParams & Params = {}): Promise<GeoPlaceList> {\n return this.get<GeoPlaceList>(\"/v1/geo/places\", p);\n }\n\n /** One place, with its containers AND the places inside it.\n *\n * The parents are a list on purpose: a place belongs to several things\n * at once.\n */\n geoPlace(uid: string): Promise<GeoPlaceDetail> {\n return this.get<GeoPlaceDetail>(`/v1/geo/places/${encodeURIComponent(uid)}`);\n }\n\n /** A place's outline as GeoJSON.\n *\n * `simplify` is in METRES: the outline keeps every corner more than\n * that far from the original, and the result is still a valid polygon.\n */\n geoBoundary(uid: string, p: { simplify?: number } & Params = {}): Promise<GeoBoundary> {\n return this.get<GeoBoundary>(`/v1/geo/places/${encodeURIComponent(uid)}/boundary`, p);\n }\n\n /** Every place containing a point, broadest first.\n *\n * The answer to \"which district is this?\" without picking a winner: a\n * point downtown Toronto lands in a neighbourhood, a ward, a city, a\n * census division, a province and a country, and all of them are\n * returned.\n */\n geoAt(lon: number, lat: number): Promise<GeoAtResponse> {\n return this.get<GeoAtResponse>(\"/v1/geo/at\", { lon, lat });\n }\n\n /** The vocabulary: every concept, in both languages, with a live count of\n * how many places and outlines it has. */\n geoConcepts(): Promise<GeoConceptList> {\n return this.get<GeoConceptList>(\"/v1/geo/concepts\");\n }\n\n /** The places of different kinds that cover the same ground.\n *\n * `bbox` is required — \"minLon,minLat,maxLon,maxLat\". Comparing every\n * pair in the country is a quadratic join, and nobody asks that\n * question about all of Canada at once.\n */\n geoOverlaps(\n p: { bbox: string; min_ratio?: number; limit?: number } & Params,\n ): Promise<GeoOverlapList> {\n return this.get<GeoOverlapList>(\"/v1/geo/overlaps\", p);\n }\n}\n\nexport default Whereq;\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,21 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* A thin, typed wrapper over the versioned `/v1` HTTP API at `api.whereq.cloud`.
|
|
5
|
-
* Public endpoints work with no key; metered endpoints take an API key.
|
|
6
|
-
*
|
|
7
|
-
* ```ts
|
|
8
|
-
* import { Whereq } from "@whereq/cloud";
|
|
9
|
-
*
|
|
10
|
-
* const wq = new Whereq(); // public access
|
|
11
|
-
* // const wq = new Whereq({ apiKey: "wq_live_…" }); // metered tier
|
|
12
|
-
*
|
|
13
|
-
* await wq.costOfLiving("us:California,ca:Ontario");
|
|
14
|
-
* await wq.prices({ domain: "rent", region: "us", bedrooms: 2 });
|
|
15
|
-
* await wq.get("/v1/trending", { limit: 10 }); // escape hatch
|
|
16
|
-
* ```
|
|
2
|
+
* The SDK version, read straight from `package.json` so it can never drift
|
|
3
|
+
* from what is published. Changesets bumps `package.json`; this follows it.
|
|
17
4
|
*/
|
|
18
|
-
declare const VERSION
|
|
5
|
+
declare const VERSION: string;
|
|
19
6
|
/** The products a station can quote. Mexico's CRE feed carries the first,
|
|
20
7
|
* second and fourth; GasBuddy (US/Canada) adds midgrade. */
|
|
21
8
|
declare const FUEL_PRODUCTS: readonly ["regular", "midgrade", "premium", "diesel"];
|
|
@@ -30,7 +17,7 @@ interface FuelStationPrice {
|
|
|
30
17
|
price: number;
|
|
31
18
|
observed_at: string;
|
|
32
19
|
}
|
|
33
|
-
/** A geolocated retail fuel station
|
|
20
|
+
/** A geolocated retail fuel station.
|
|
34
21
|
* `state` is the human label ("Ontario", "Texas"); `state_iso` is the
|
|
35
22
|
* two-letter code ("ON", "TX"). */
|
|
36
23
|
interface FuelStation {
|
|
@@ -45,7 +32,10 @@ interface FuelStation {
|
|
|
45
32
|
municipality?: string | null;
|
|
46
33
|
lat?: number | null;
|
|
47
34
|
lon?: number | null;
|
|
48
|
-
|
|
35
|
+
/** The latest price per product — present on the *list* endpoint. The
|
|
36
|
+
* *detail* endpoint omits it: its timeline comes back as the separate
|
|
37
|
+
* `prices` array on the response. */
|
|
38
|
+
prices?: Record<string, FuelStationPrice>;
|
|
49
39
|
}
|
|
50
40
|
/** Filters for `fuelStations()`. */
|
|
51
41
|
interface FuelStationsParams {
|
|
@@ -137,6 +127,171 @@ interface PriceSeriesResponse {
|
|
|
137
127
|
offset: number;
|
|
138
128
|
data: PriceSeries[];
|
|
139
129
|
}
|
|
130
|
+
/** One place — a province, a municipality, a ward, a neighbourhood.
|
|
131
|
+
*
|
|
132
|
+
* `kind` is the platform's own concept (`province`, `region`,
|
|
133
|
+
* `municipality`, `city`, `town`, `ward`, `neighbourhood`…), not the
|
|
134
|
+
* source's admin level. `country_code` is the two-letter ISO code and is
|
|
135
|
+
* the same for both vocabularies — a country filter accepts `CA` or
|
|
136
|
+
* `CAN` and answers with the same places either way.
|
|
137
|
+
*/
|
|
138
|
+
interface GeoPlace {
|
|
139
|
+
uid: string;
|
|
140
|
+
kind: string;
|
|
141
|
+
kind_source: string;
|
|
142
|
+
name: string;
|
|
143
|
+
name_en?: string | null;
|
|
144
|
+
name_zh?: string | null;
|
|
145
|
+
name_local?: string | null;
|
|
146
|
+
official_name?: string | null;
|
|
147
|
+
source: string;
|
|
148
|
+
source_id: string;
|
|
149
|
+
source_url?: string | null;
|
|
150
|
+
license?: string | null;
|
|
151
|
+
raw_admin_level?: number | null;
|
|
152
|
+
raw_place?: string | null;
|
|
153
|
+
raw_boundary?: string | null;
|
|
154
|
+
country_code?: string | null;
|
|
155
|
+
province_code?: string | null;
|
|
156
|
+
iso_code?: string | null;
|
|
157
|
+
ref?: string | null;
|
|
158
|
+
population?: number | null;
|
|
159
|
+
population_date?: string | null;
|
|
160
|
+
wikidata?: string | null;
|
|
161
|
+
wikipedia?: string | null;
|
|
162
|
+
website?: string | null;
|
|
163
|
+
capital?: string | null;
|
|
164
|
+
centroid_lon?: number | null;
|
|
165
|
+
centroid_lat?: number | null;
|
|
166
|
+
bbox_min_lon?: number | null;
|
|
167
|
+
bbox_min_lat?: number | null;
|
|
168
|
+
bbox_max_lon?: number | null;
|
|
169
|
+
bbox_max_lat?: number | null;
|
|
170
|
+
area_km2?: number | null;
|
|
171
|
+
has_boundary: boolean;
|
|
172
|
+
}
|
|
173
|
+
interface GeoPlaceList {
|
|
174
|
+
count: number;
|
|
175
|
+
data: GeoPlace[];
|
|
176
|
+
limit: number;
|
|
177
|
+
offset: number;
|
|
178
|
+
}
|
|
179
|
+
/** One container of a place, as the detail endpoint lists them.
|
|
180
|
+
*
|
|
181
|
+
* A place has SEVERAL parents — a neighbourhood is in a ward, in a city,
|
|
182
|
+
* in a census division and in a province, all at once. The list is
|
|
183
|
+
* deliberately a list.
|
|
184
|
+
*/
|
|
185
|
+
interface GeoParent {
|
|
186
|
+
uid: string;
|
|
187
|
+
kind: string;
|
|
188
|
+
name: string;
|
|
189
|
+
source: string;
|
|
190
|
+
area_ratio?: number | null;
|
|
191
|
+
is_primary: boolean;
|
|
192
|
+
}
|
|
193
|
+
/** One place with its containers and the places inside it. */
|
|
194
|
+
interface GeoPlaceDetail {
|
|
195
|
+
uid: string;
|
|
196
|
+
place: GeoPlace;
|
|
197
|
+
parents: GeoParent[];
|
|
198
|
+
children: GeoParent[];
|
|
199
|
+
}
|
|
200
|
+
/** One concept in the vocabulary, with a live count behind it. */
|
|
201
|
+
interface GeoConcept {
|
|
202
|
+
kind: string;
|
|
203
|
+
name: string;
|
|
204
|
+
name_cn?: string | null;
|
|
205
|
+
description?: string | null;
|
|
206
|
+
description_cn?: string | null;
|
|
207
|
+
places: number;
|
|
208
|
+
with_boundary: number;
|
|
209
|
+
rank: number;
|
|
210
|
+
}
|
|
211
|
+
/** The vocabulary, explained. */
|
|
212
|
+
interface GeoConceptList {
|
|
213
|
+
count: number;
|
|
214
|
+
concepts: GeoConcept[];
|
|
215
|
+
sources: Array<Record<string, unknown>>;
|
|
216
|
+
}
|
|
217
|
+
/** Two places of DIFFERENT kinds covering the same ground.
|
|
218
|
+
*
|
|
219
|
+
* This is the deliberate part of the dataset: a census subdivision and
|
|
220
|
+
* an OpenStreetMap city boundary that describe the same town in two
|
|
221
|
+
* vocabularies. The platform keeps both rather than picking one.
|
|
222
|
+
*/
|
|
223
|
+
interface GeoOverlap {
|
|
224
|
+
a_id: number;
|
|
225
|
+
b_id: number;
|
|
226
|
+
a_uid: string;
|
|
227
|
+
b_uid: string;
|
|
228
|
+
a_name: string;
|
|
229
|
+
b_name: string;
|
|
230
|
+
a_kind: string;
|
|
231
|
+
b_kind: string;
|
|
232
|
+
a_source: string;
|
|
233
|
+
b_source: string;
|
|
234
|
+
overlap_ratio: number;
|
|
235
|
+
a_concept: string;
|
|
236
|
+
b_concept: string;
|
|
237
|
+
}
|
|
238
|
+
/** The overlapping pairs inside a box. */
|
|
239
|
+
interface GeoOverlapList {
|
|
240
|
+
bbox: Record<string, number>;
|
|
241
|
+
min_ratio: number;
|
|
242
|
+
count: number;
|
|
243
|
+
overlaps: GeoOverlap[];
|
|
244
|
+
}
|
|
245
|
+
/** One place in the containing stack at a point.
|
|
246
|
+
*
|
|
247
|
+
* `country_code` is on every level, so the stack can be read without a
|
|
248
|
+
* second lookup.
|
|
249
|
+
*/
|
|
250
|
+
interface GeoAtPlace {
|
|
251
|
+
uid: string;
|
|
252
|
+
kind: string;
|
|
253
|
+
kind_source: string;
|
|
254
|
+
name: string;
|
|
255
|
+
name_en?: string | null;
|
|
256
|
+
name_zh?: string | null;
|
|
257
|
+
source: string;
|
|
258
|
+
raw_admin_level?: number | null;
|
|
259
|
+
raw_place?: string | null;
|
|
260
|
+
population?: number | null;
|
|
261
|
+
wikidata?: string | null;
|
|
262
|
+
centroid_lon?: number | null;
|
|
263
|
+
centroid_lat?: number | null;
|
|
264
|
+
area_km2?: number | null;
|
|
265
|
+
country_code?: string | null;
|
|
266
|
+
province_code?: string | null;
|
|
267
|
+
boundary_area_km2?: number | null;
|
|
268
|
+
concept?: Record<string, unknown>;
|
|
269
|
+
}
|
|
270
|
+
/** Every place containing a point, broadest first: country, province,
|
|
271
|
+
* region, municipality, city, ward, neighbourhood. The answer to "where
|
|
272
|
+
* am I?" without pretending one of them is *the* answer. */
|
|
273
|
+
interface GeoAtResponse {
|
|
274
|
+
lon: number;
|
|
275
|
+
lat: number;
|
|
276
|
+
count: number;
|
|
277
|
+
places: GeoAtPlace[];
|
|
278
|
+
}
|
|
279
|
+
/** A place's outline as GeoJSON — a FeatureCollection you can hand
|
|
280
|
+
* straight to a map library. */
|
|
281
|
+
interface GeoBoundary {
|
|
282
|
+
type: string;
|
|
283
|
+
features: Array<Record<string, unknown>>;
|
|
284
|
+
}
|
|
285
|
+
interface GeoPlacesParams {
|
|
286
|
+
kind?: string;
|
|
287
|
+
source?: string;
|
|
288
|
+
country?: string;
|
|
289
|
+
q?: string;
|
|
290
|
+
bbox?: string;
|
|
291
|
+
has_boundary?: boolean;
|
|
292
|
+
limit?: number;
|
|
293
|
+
offset?: number;
|
|
294
|
+
}
|
|
140
295
|
declare class WhereqError extends Error {
|
|
141
296
|
readonly status: number;
|
|
142
297
|
readonly url: string;
|
|
@@ -247,6 +402,49 @@ declare class Whereq {
|
|
|
247
402
|
* prices that `fuelStations()` returns.
|
|
248
403
|
*/
|
|
249
404
|
fuelPrices(p?: FuelPricesParams & Params): Promise<PriceSeriesResponse>;
|
|
405
|
+
/** The place list — provinces, regions, municipalities, cities, towns,
|
|
406
|
+
* wards, neighbourhoods, countries.
|
|
407
|
+
*
|
|
408
|
+
* `country` takes an ISO code and either spelling works: `"CA"` and
|
|
409
|
+
* `"CAN"` find the same places, in both vocabularies.
|
|
410
|
+
*/
|
|
411
|
+
geoPlaces(p?: GeoPlacesParams & Params): Promise<GeoPlaceList>;
|
|
412
|
+
/** One place, with its containers AND the places inside it.
|
|
413
|
+
*
|
|
414
|
+
* The parents are a list on purpose: a place belongs to several things
|
|
415
|
+
* at once.
|
|
416
|
+
*/
|
|
417
|
+
geoPlace(uid: string): Promise<GeoPlaceDetail>;
|
|
418
|
+
/** A place's outline as GeoJSON.
|
|
419
|
+
*
|
|
420
|
+
* `simplify` is in METRES: the outline keeps every corner more than
|
|
421
|
+
* that far from the original, and the result is still a valid polygon.
|
|
422
|
+
*/
|
|
423
|
+
geoBoundary(uid: string, p?: {
|
|
424
|
+
simplify?: number;
|
|
425
|
+
} & Params): Promise<GeoBoundary>;
|
|
426
|
+
/** Every place containing a point, broadest first.
|
|
427
|
+
*
|
|
428
|
+
* The answer to "which district is this?" without picking a winner: a
|
|
429
|
+
* point downtown Toronto lands in a neighbourhood, a ward, a city, a
|
|
430
|
+
* census division, a province and a country, and all of them are
|
|
431
|
+
* returned.
|
|
432
|
+
*/
|
|
433
|
+
geoAt(lon: number, lat: number): Promise<GeoAtResponse>;
|
|
434
|
+
/** The vocabulary: every concept, in both languages, with a live count of
|
|
435
|
+
* how many places and outlines it has. */
|
|
436
|
+
geoConcepts(): Promise<GeoConceptList>;
|
|
437
|
+
/** The places of different kinds that cover the same ground.
|
|
438
|
+
*
|
|
439
|
+
* `bbox` is required — "minLon,minLat,maxLon,maxLat". Comparing every
|
|
440
|
+
* pair in the country is a quadratic join, and nobody asks that
|
|
441
|
+
* question about all of Canada at once.
|
|
442
|
+
*/
|
|
443
|
+
geoOverlaps(p: {
|
|
444
|
+
bbox: string;
|
|
445
|
+
min_ratio?: number;
|
|
446
|
+
limit?: number;
|
|
447
|
+
} & Params): Promise<GeoOverlapList>;
|
|
250
448
|
}
|
|
251
449
|
|
|
252
|
-
export { type ClientOptions, FUEL_COUNTRIES, FUEL_CURRENCIES, FUEL_PRODUCTS, type FuelCountry, type FuelPricesParams, type FuelProduct, type FuelStation, type FuelStationDetail, type FuelStationParams, type FuelStationPrice, type FuelStationPricePoint, type FuelStationsParams, type FuelStationsResponse, type PriceSeries, type PriceSeriesResponse, VERSION, Whereq, WhereqError, Whereq as default };
|
|
450
|
+
export { type ClientOptions, FUEL_COUNTRIES, FUEL_CURRENCIES, FUEL_PRODUCTS, type FuelCountry, type FuelPricesParams, type FuelProduct, type FuelStation, type FuelStationDetail, type FuelStationParams, type FuelStationPrice, type FuelStationPricePoint, type FuelStationsParams, type FuelStationsResponse, type GeoAtPlace, type GeoAtResponse, type GeoBoundary, type GeoConcept, type GeoConceptList, type GeoOverlap, type GeoOverlapList, type GeoParent, type GeoPlace, type GeoPlaceDetail, type GeoPlaceList, type GeoPlacesParams, type PriceSeries, type PriceSeriesResponse, VERSION, Whereq, WhereqError, Whereq as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,21 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* A thin, typed wrapper over the versioned `/v1` HTTP API at `api.whereq.cloud`.
|
|
5
|
-
* Public endpoints work with no key; metered endpoints take an API key.
|
|
6
|
-
*
|
|
7
|
-
* ```ts
|
|
8
|
-
* import { Whereq } from "@whereq/cloud";
|
|
9
|
-
*
|
|
10
|
-
* const wq = new Whereq(); // public access
|
|
11
|
-
* // const wq = new Whereq({ apiKey: "wq_live_…" }); // metered tier
|
|
12
|
-
*
|
|
13
|
-
* await wq.costOfLiving("us:California,ca:Ontario");
|
|
14
|
-
* await wq.prices({ domain: "rent", region: "us", bedrooms: 2 });
|
|
15
|
-
* await wq.get("/v1/trending", { limit: 10 }); // escape hatch
|
|
16
|
-
* ```
|
|
2
|
+
* The SDK version, read straight from `package.json` so it can never drift
|
|
3
|
+
* from what is published. Changesets bumps `package.json`; this follows it.
|
|
17
4
|
*/
|
|
18
|
-
declare const VERSION
|
|
5
|
+
declare const VERSION: string;
|
|
19
6
|
/** The products a station can quote. Mexico's CRE feed carries the first,
|
|
20
7
|
* second and fourth; GasBuddy (US/Canada) adds midgrade. */
|
|
21
8
|
declare const FUEL_PRODUCTS: readonly ["regular", "midgrade", "premium", "diesel"];
|
|
@@ -30,7 +17,7 @@ interface FuelStationPrice {
|
|
|
30
17
|
price: number;
|
|
31
18
|
observed_at: string;
|
|
32
19
|
}
|
|
33
|
-
/** A geolocated retail fuel station
|
|
20
|
+
/** A geolocated retail fuel station.
|
|
34
21
|
* `state` is the human label ("Ontario", "Texas"); `state_iso` is the
|
|
35
22
|
* two-letter code ("ON", "TX"). */
|
|
36
23
|
interface FuelStation {
|
|
@@ -45,7 +32,10 @@ interface FuelStation {
|
|
|
45
32
|
municipality?: string | null;
|
|
46
33
|
lat?: number | null;
|
|
47
34
|
lon?: number | null;
|
|
48
|
-
|
|
35
|
+
/** The latest price per product — present on the *list* endpoint. The
|
|
36
|
+
* *detail* endpoint omits it: its timeline comes back as the separate
|
|
37
|
+
* `prices` array on the response. */
|
|
38
|
+
prices?: Record<string, FuelStationPrice>;
|
|
49
39
|
}
|
|
50
40
|
/** Filters for `fuelStations()`. */
|
|
51
41
|
interface FuelStationsParams {
|
|
@@ -137,6 +127,171 @@ interface PriceSeriesResponse {
|
|
|
137
127
|
offset: number;
|
|
138
128
|
data: PriceSeries[];
|
|
139
129
|
}
|
|
130
|
+
/** One place — a province, a municipality, a ward, a neighbourhood.
|
|
131
|
+
*
|
|
132
|
+
* `kind` is the platform's own concept (`province`, `region`,
|
|
133
|
+
* `municipality`, `city`, `town`, `ward`, `neighbourhood`…), not the
|
|
134
|
+
* source's admin level. `country_code` is the two-letter ISO code and is
|
|
135
|
+
* the same for both vocabularies — a country filter accepts `CA` or
|
|
136
|
+
* `CAN` and answers with the same places either way.
|
|
137
|
+
*/
|
|
138
|
+
interface GeoPlace {
|
|
139
|
+
uid: string;
|
|
140
|
+
kind: string;
|
|
141
|
+
kind_source: string;
|
|
142
|
+
name: string;
|
|
143
|
+
name_en?: string | null;
|
|
144
|
+
name_zh?: string | null;
|
|
145
|
+
name_local?: string | null;
|
|
146
|
+
official_name?: string | null;
|
|
147
|
+
source: string;
|
|
148
|
+
source_id: string;
|
|
149
|
+
source_url?: string | null;
|
|
150
|
+
license?: string | null;
|
|
151
|
+
raw_admin_level?: number | null;
|
|
152
|
+
raw_place?: string | null;
|
|
153
|
+
raw_boundary?: string | null;
|
|
154
|
+
country_code?: string | null;
|
|
155
|
+
province_code?: string | null;
|
|
156
|
+
iso_code?: string | null;
|
|
157
|
+
ref?: string | null;
|
|
158
|
+
population?: number | null;
|
|
159
|
+
population_date?: string | null;
|
|
160
|
+
wikidata?: string | null;
|
|
161
|
+
wikipedia?: string | null;
|
|
162
|
+
website?: string | null;
|
|
163
|
+
capital?: string | null;
|
|
164
|
+
centroid_lon?: number | null;
|
|
165
|
+
centroid_lat?: number | null;
|
|
166
|
+
bbox_min_lon?: number | null;
|
|
167
|
+
bbox_min_lat?: number | null;
|
|
168
|
+
bbox_max_lon?: number | null;
|
|
169
|
+
bbox_max_lat?: number | null;
|
|
170
|
+
area_km2?: number | null;
|
|
171
|
+
has_boundary: boolean;
|
|
172
|
+
}
|
|
173
|
+
interface GeoPlaceList {
|
|
174
|
+
count: number;
|
|
175
|
+
data: GeoPlace[];
|
|
176
|
+
limit: number;
|
|
177
|
+
offset: number;
|
|
178
|
+
}
|
|
179
|
+
/** One container of a place, as the detail endpoint lists them.
|
|
180
|
+
*
|
|
181
|
+
* A place has SEVERAL parents — a neighbourhood is in a ward, in a city,
|
|
182
|
+
* in a census division and in a province, all at once. The list is
|
|
183
|
+
* deliberately a list.
|
|
184
|
+
*/
|
|
185
|
+
interface GeoParent {
|
|
186
|
+
uid: string;
|
|
187
|
+
kind: string;
|
|
188
|
+
name: string;
|
|
189
|
+
source: string;
|
|
190
|
+
area_ratio?: number | null;
|
|
191
|
+
is_primary: boolean;
|
|
192
|
+
}
|
|
193
|
+
/** One place with its containers and the places inside it. */
|
|
194
|
+
interface GeoPlaceDetail {
|
|
195
|
+
uid: string;
|
|
196
|
+
place: GeoPlace;
|
|
197
|
+
parents: GeoParent[];
|
|
198
|
+
children: GeoParent[];
|
|
199
|
+
}
|
|
200
|
+
/** One concept in the vocabulary, with a live count behind it. */
|
|
201
|
+
interface GeoConcept {
|
|
202
|
+
kind: string;
|
|
203
|
+
name: string;
|
|
204
|
+
name_cn?: string | null;
|
|
205
|
+
description?: string | null;
|
|
206
|
+
description_cn?: string | null;
|
|
207
|
+
places: number;
|
|
208
|
+
with_boundary: number;
|
|
209
|
+
rank: number;
|
|
210
|
+
}
|
|
211
|
+
/** The vocabulary, explained. */
|
|
212
|
+
interface GeoConceptList {
|
|
213
|
+
count: number;
|
|
214
|
+
concepts: GeoConcept[];
|
|
215
|
+
sources: Array<Record<string, unknown>>;
|
|
216
|
+
}
|
|
217
|
+
/** Two places of DIFFERENT kinds covering the same ground.
|
|
218
|
+
*
|
|
219
|
+
* This is the deliberate part of the dataset: a census subdivision and
|
|
220
|
+
* an OpenStreetMap city boundary that describe the same town in two
|
|
221
|
+
* vocabularies. The platform keeps both rather than picking one.
|
|
222
|
+
*/
|
|
223
|
+
interface GeoOverlap {
|
|
224
|
+
a_id: number;
|
|
225
|
+
b_id: number;
|
|
226
|
+
a_uid: string;
|
|
227
|
+
b_uid: string;
|
|
228
|
+
a_name: string;
|
|
229
|
+
b_name: string;
|
|
230
|
+
a_kind: string;
|
|
231
|
+
b_kind: string;
|
|
232
|
+
a_source: string;
|
|
233
|
+
b_source: string;
|
|
234
|
+
overlap_ratio: number;
|
|
235
|
+
a_concept: string;
|
|
236
|
+
b_concept: string;
|
|
237
|
+
}
|
|
238
|
+
/** The overlapping pairs inside a box. */
|
|
239
|
+
interface GeoOverlapList {
|
|
240
|
+
bbox: Record<string, number>;
|
|
241
|
+
min_ratio: number;
|
|
242
|
+
count: number;
|
|
243
|
+
overlaps: GeoOverlap[];
|
|
244
|
+
}
|
|
245
|
+
/** One place in the containing stack at a point.
|
|
246
|
+
*
|
|
247
|
+
* `country_code` is on every level, so the stack can be read without a
|
|
248
|
+
* second lookup.
|
|
249
|
+
*/
|
|
250
|
+
interface GeoAtPlace {
|
|
251
|
+
uid: string;
|
|
252
|
+
kind: string;
|
|
253
|
+
kind_source: string;
|
|
254
|
+
name: string;
|
|
255
|
+
name_en?: string | null;
|
|
256
|
+
name_zh?: string | null;
|
|
257
|
+
source: string;
|
|
258
|
+
raw_admin_level?: number | null;
|
|
259
|
+
raw_place?: string | null;
|
|
260
|
+
population?: number | null;
|
|
261
|
+
wikidata?: string | null;
|
|
262
|
+
centroid_lon?: number | null;
|
|
263
|
+
centroid_lat?: number | null;
|
|
264
|
+
area_km2?: number | null;
|
|
265
|
+
country_code?: string | null;
|
|
266
|
+
province_code?: string | null;
|
|
267
|
+
boundary_area_km2?: number | null;
|
|
268
|
+
concept?: Record<string, unknown>;
|
|
269
|
+
}
|
|
270
|
+
/** Every place containing a point, broadest first: country, province,
|
|
271
|
+
* region, municipality, city, ward, neighbourhood. The answer to "where
|
|
272
|
+
* am I?" without pretending one of them is *the* answer. */
|
|
273
|
+
interface GeoAtResponse {
|
|
274
|
+
lon: number;
|
|
275
|
+
lat: number;
|
|
276
|
+
count: number;
|
|
277
|
+
places: GeoAtPlace[];
|
|
278
|
+
}
|
|
279
|
+
/** A place's outline as GeoJSON — a FeatureCollection you can hand
|
|
280
|
+
* straight to a map library. */
|
|
281
|
+
interface GeoBoundary {
|
|
282
|
+
type: string;
|
|
283
|
+
features: Array<Record<string, unknown>>;
|
|
284
|
+
}
|
|
285
|
+
interface GeoPlacesParams {
|
|
286
|
+
kind?: string;
|
|
287
|
+
source?: string;
|
|
288
|
+
country?: string;
|
|
289
|
+
q?: string;
|
|
290
|
+
bbox?: string;
|
|
291
|
+
has_boundary?: boolean;
|
|
292
|
+
limit?: number;
|
|
293
|
+
offset?: number;
|
|
294
|
+
}
|
|
140
295
|
declare class WhereqError extends Error {
|
|
141
296
|
readonly status: number;
|
|
142
297
|
readonly url: string;
|
|
@@ -247,6 +402,49 @@ declare class Whereq {
|
|
|
247
402
|
* prices that `fuelStations()` returns.
|
|
248
403
|
*/
|
|
249
404
|
fuelPrices(p?: FuelPricesParams & Params): Promise<PriceSeriesResponse>;
|
|
405
|
+
/** The place list — provinces, regions, municipalities, cities, towns,
|
|
406
|
+
* wards, neighbourhoods, countries.
|
|
407
|
+
*
|
|
408
|
+
* `country` takes an ISO code and either spelling works: `"CA"` and
|
|
409
|
+
* `"CAN"` find the same places, in both vocabularies.
|
|
410
|
+
*/
|
|
411
|
+
geoPlaces(p?: GeoPlacesParams & Params): Promise<GeoPlaceList>;
|
|
412
|
+
/** One place, with its containers AND the places inside it.
|
|
413
|
+
*
|
|
414
|
+
* The parents are a list on purpose: a place belongs to several things
|
|
415
|
+
* at once.
|
|
416
|
+
*/
|
|
417
|
+
geoPlace(uid: string): Promise<GeoPlaceDetail>;
|
|
418
|
+
/** A place's outline as GeoJSON.
|
|
419
|
+
*
|
|
420
|
+
* `simplify` is in METRES: the outline keeps every corner more than
|
|
421
|
+
* that far from the original, and the result is still a valid polygon.
|
|
422
|
+
*/
|
|
423
|
+
geoBoundary(uid: string, p?: {
|
|
424
|
+
simplify?: number;
|
|
425
|
+
} & Params): Promise<GeoBoundary>;
|
|
426
|
+
/** Every place containing a point, broadest first.
|
|
427
|
+
*
|
|
428
|
+
* The answer to "which district is this?" without picking a winner: a
|
|
429
|
+
* point downtown Toronto lands in a neighbourhood, a ward, a city, a
|
|
430
|
+
* census division, a province and a country, and all of them are
|
|
431
|
+
* returned.
|
|
432
|
+
*/
|
|
433
|
+
geoAt(lon: number, lat: number): Promise<GeoAtResponse>;
|
|
434
|
+
/** The vocabulary: every concept, in both languages, with a live count of
|
|
435
|
+
* how many places and outlines it has. */
|
|
436
|
+
geoConcepts(): Promise<GeoConceptList>;
|
|
437
|
+
/** The places of different kinds that cover the same ground.
|
|
438
|
+
*
|
|
439
|
+
* `bbox` is required — "minLon,minLat,maxLon,maxLat". Comparing every
|
|
440
|
+
* pair in the country is a quadratic join, and nobody asks that
|
|
441
|
+
* question about all of Canada at once.
|
|
442
|
+
*/
|
|
443
|
+
geoOverlaps(p: {
|
|
444
|
+
bbox: string;
|
|
445
|
+
min_ratio?: number;
|
|
446
|
+
limit?: number;
|
|
447
|
+
} & Params): Promise<GeoOverlapList>;
|
|
250
448
|
}
|
|
251
449
|
|
|
252
|
-
export { type ClientOptions, FUEL_COUNTRIES, FUEL_CURRENCIES, FUEL_PRODUCTS, type FuelCountry, type FuelPricesParams, type FuelProduct, type FuelStation, type FuelStationDetail, type FuelStationParams, type FuelStationPrice, type FuelStationPricePoint, type FuelStationsParams, type FuelStationsResponse, type PriceSeries, type PriceSeriesResponse, VERSION, Whereq, WhereqError, Whereq as default };
|
|
450
|
+
export { type ClientOptions, FUEL_COUNTRIES, FUEL_CURRENCIES, FUEL_PRODUCTS, type FuelCountry, type FuelPricesParams, type FuelProduct, type FuelStation, type FuelStationDetail, type FuelStationParams, type FuelStationPrice, type FuelStationPricePoint, type FuelStationsParams, type FuelStationsResponse, type GeoAtPlace, type GeoAtResponse, type GeoBoundary, type GeoConcept, type GeoConceptList, type GeoOverlap, type GeoOverlapList, type GeoParent, type GeoPlace, type GeoPlaceDetail, type GeoPlaceList, type GeoPlacesParams, type PriceSeries, type PriceSeriesResponse, VERSION, Whereq, WhereqError, Whereq as default };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
// package.json
|
|
2
|
+
var package_default = {
|
|
3
|
+
version: "0.6.0"};
|
|
4
|
+
|
|
1
5
|
// src/index.ts
|
|
2
|
-
var VERSION =
|
|
6
|
+
var VERSION = package_default.version;
|
|
3
7
|
var DEFAULT_BASE_URL = "https://api.whereq.cloud";
|
|
4
8
|
var FUEL_PRODUCTS = ["regular", "midgrade", "premium", "diesel"];
|
|
5
9
|
var FUEL_COUNTRIES = ["MX", "US", "CA"];
|
|
@@ -203,6 +207,56 @@ var Whereq = class {
|
|
|
203
207
|
fuelPrices(p = {}) {
|
|
204
208
|
return this.get("/v1/prices", { domain: "fuel", ...p });
|
|
205
209
|
}
|
|
210
|
+
// -- geography (places, boundaries, hierarchy) ------------------------------
|
|
211
|
+
/** The place list — provinces, regions, municipalities, cities, towns,
|
|
212
|
+
* wards, neighbourhoods, countries.
|
|
213
|
+
*
|
|
214
|
+
* `country` takes an ISO code and either spelling works: `"CA"` and
|
|
215
|
+
* `"CAN"` find the same places, in both vocabularies.
|
|
216
|
+
*/
|
|
217
|
+
geoPlaces(p = {}) {
|
|
218
|
+
return this.get("/v1/geo/places", p);
|
|
219
|
+
}
|
|
220
|
+
/** One place, with its containers AND the places inside it.
|
|
221
|
+
*
|
|
222
|
+
* The parents are a list on purpose: a place belongs to several things
|
|
223
|
+
* at once.
|
|
224
|
+
*/
|
|
225
|
+
geoPlace(uid) {
|
|
226
|
+
return this.get(`/v1/geo/places/${encodeURIComponent(uid)}`);
|
|
227
|
+
}
|
|
228
|
+
/** A place's outline as GeoJSON.
|
|
229
|
+
*
|
|
230
|
+
* `simplify` is in METRES: the outline keeps every corner more than
|
|
231
|
+
* that far from the original, and the result is still a valid polygon.
|
|
232
|
+
*/
|
|
233
|
+
geoBoundary(uid, p = {}) {
|
|
234
|
+
return this.get(`/v1/geo/places/${encodeURIComponent(uid)}/boundary`, p);
|
|
235
|
+
}
|
|
236
|
+
/** Every place containing a point, broadest first.
|
|
237
|
+
*
|
|
238
|
+
* The answer to "which district is this?" without picking a winner: a
|
|
239
|
+
* point downtown Toronto lands in a neighbourhood, a ward, a city, a
|
|
240
|
+
* census division, a province and a country, and all of them are
|
|
241
|
+
* returned.
|
|
242
|
+
*/
|
|
243
|
+
geoAt(lon, lat) {
|
|
244
|
+
return this.get("/v1/geo/at", { lon, lat });
|
|
245
|
+
}
|
|
246
|
+
/** The vocabulary: every concept, in both languages, with a live count of
|
|
247
|
+
* how many places and outlines it has. */
|
|
248
|
+
geoConcepts() {
|
|
249
|
+
return this.get("/v1/geo/concepts");
|
|
250
|
+
}
|
|
251
|
+
/** The places of different kinds that cover the same ground.
|
|
252
|
+
*
|
|
253
|
+
* `bbox` is required — "minLon,minLat,maxLon,maxLat". Comparing every
|
|
254
|
+
* pair in the country is a quadratic join, and nobody asks that
|
|
255
|
+
* question about all of Canada at once.
|
|
256
|
+
*/
|
|
257
|
+
geoOverlaps(p) {
|
|
258
|
+
return this.get("/v1/geo/overlaps", p);
|
|
259
|
+
}
|
|
206
260
|
};
|
|
207
261
|
var index_default = Whereq;
|
|
208
262
|
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";AAiBO,IAAM,OAAA,GAAU;AACvB,IAAM,gBAAA,GAAmB,0BAAA;AAIlB,IAAM,aAAA,GAAgB,CAAC,SAAA,EAAW,UAAA,EAAY,WAAW,QAAQ;AAIjE,IAAM,cAAA,GAAiB,CAAC,IAAA,EAAM,IAAA,EAAM,IAAI;AAIxC,IAAM,eAAA,GAA+C;AAAA,EAC1D,EAAA,EAAI,OAAA;AAAA,EACJ,EAAA,EAAI,OAAA;AAAA,EACJ,EAAA,EAAI;AACN;AA4HO,IAAM,WAAA,GAAN,cAA0B,KAAA,CAAM;AAAA,EACrC,WAAA,CACkB,MAAA,EAChB,OAAA,EACgB,GAAA,EAChB;AACA,IAAA,KAAA,CAAM,0BAA0B,MAAM,CAAA,KAAA,EAAQ,GAAG,CAAA,EAAA,EAAK,OAAO,CAAA,CAAE,CAAA;AAJ/C,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AAEA,IAAA,IAAA,CAAA,GAAA,GAAA,GAAA;AAGhB,IAAA,IAAA,CAAK,IAAA,GAAO,aAAA;AAAA,EACd;AAAA,EANkB,MAAA;AAAA,EAEA,GAAA;AAKpB;AAcA,SAAS,SAAA,GAAoB;AAC3B,EAAA,MAAM,OAAQ,UAAA,CAA0E,OAAA;AACxF,EAAA,OAAO,IAAA,EAAM,KAAK,cAAA,IAAkB,EAAA;AACtC;AAEO,IAAM,SAAN,MAAa;AAAA,EACD,OAAA;AAAA,EACA,OAAA;AAAA,EACA,MAAA;AAAA,EAEjB,WAAA,CAAY,IAAA,GAAsB,EAAC,EAAG;AACpC,IAAA,IAAA,CAAK,WAAW,IAAA,CAAK,OAAA,IAAW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AACnC,MAAA,IAAI,QAAA,CAAS,WAAW,CAAA,EAAG;AAC3B,MAAA,KAAA,MAAW,CAAA,IAAK,UAAU,MAAM,CAAA;AAChC,MAAA,IAAI,KAAK,IAAA,EAAM;AACf,MAAA,MAAA,IAAU,QAAA,CAAS,MAAA;AACnB,MAAA,IAAI,IAAA,CAAK,KAAA,IAAS,IAAA,IAAQ,MAAA,IAAU,KAAK,KAAA,EAAO;AAAA,IAClD;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,UAAA,CAAW,CAAA,GAA+B,EAAC,EAAiC;AAC1E,IAAA,OAAO,IAAA,CAAK,IAAyB,YAAA,EAAc,EAAE,QAAQ,MAAA,EAAQ,GAAG,GAAG,CAAA;AAAA,EAC7E;AACF;AAEA,IAAO,aAAA,GAAQ","file":"index.js","sourcesContent":["/**\n * whereq.cloud — official JavaScript/TypeScript SDK for the WhereQ data cloud.\n *\n * A thin, typed wrapper over the versioned `/v1` HTTP API at `api.whereq.cloud`.\n * Public endpoints work with no key; metered endpoints take an API key.\n *\n * ```ts\n * import { Whereq } from \"@whereq/cloud\";\n *\n * const wq = new Whereq(); // public access\n * // const wq = new Whereq({ apiKey: \"wq_live_…\" }); // metered tier\n *\n * await wq.costOfLiving(\"us:California,ca:Ontario\");\n * await wq.prices({ domain: \"rent\", region: \"us\", bedrooms: 2 });\n * await wq.get(\"/v1/trending\", { limit: 10 }); // escape hatch\n * ```\n */\nexport const VERSION = \"0.5.0\";\nconst DEFAULT_BASE_URL = \"https://api.whereq.cloud\";\n\n/** The products a station can quote. Mexico's CRE feed carries the first,\n * second and fourth; GasBuddy (US/Canada) adds midgrade. */\nexport const FUEL_PRODUCTS = [\"regular\", \"midgrade\", \"premium\", \"diesel\"] as const;\nexport type FuelProduct = (typeof FUEL_PRODUCTS)[number];\n\n/** Countries with station-level fuel data. */\nexport const FUEL_COUNTRIES = [\"MX\", \"US\", \"CA\"] as const;\nexport type FuelCountry = (typeof FUEL_COUNTRIES)[number];\n\n/** The unit each country quotes in — always local currency per litre. */\nexport const FUEL_CURRENCIES: Record<FuelCountry, string> = {\n MX: \"MXN/L\",\n US: \"USD/L\",\n CA: \"CAD/L\",\n};\n\n/** One product's latest price at a station. */\nexport interface FuelStationPrice {\n price: number;\n observed_at: string;\n}\n\n/** A geolocated retail fuel station and its latest prices.\n * `state` is the human label (\"Ontario\", \"Texas\"); `state_iso` is the\n * two-letter code (\"ON\", \"TX\"). */\nexport interface FuelStation {\n id: number;\n source: string;\n ext_id: string;\n country: string;\n name: string;\n brand?: string | null;\n state?: string | null;\n state_iso?: string | null;\n municipality?: string | null;\n lat?: number | null;\n lon?: number | null;\n prices: Record<string, FuelStationPrice>;\n}\n\n/** Filters for `fuelStations()`. */\nexport interface FuelStationsParams {\n /** \"MX\", \"US\" or \"CA\". */\n country?: FuelCountry | string;\n /** State/province name *or* ISO code — \"Ontario\"/\"ON\", \"Texas\"/\"TX\". */\n state?: string;\n /** City name, e.g. \"Mississauga\". */\n municipality?: string;\n product?: FuelProduct | string;\n /** \"minLon,minLat,maxLon,maxLat\" — a map viewport. */\n bbox?: string;\n /** Station-name search. */\n q?: string;\n /** 1–500 rows per page (default 100). */\n limit?: number;\n /** Row offset for paging. */\n offset?: number;\n}\n\n/** Filters for `fuelStation()`. */\nexport interface FuelStationParams {\n /** Restrict the timeline to one product. */\n product?: FuelProduct | string;\n /** How far back the timeline reaches (1–1825, default 90). */\n days?: number;\n}\n\n/** `GET /v1/fuel/stations`. Unentitled callers get a 100-row preview of the\n * oldest rows: `demo` is true, `total` is null and paging is ignored. */\nexport interface FuelStationsResponse {\n demo?: boolean;\n preview_rows?: number;\n note?: string;\n upgrade_url?: string;\n as_of: string;\n count: number;\n total?: number | null;\n stations: FuelStation[];\n}\n\n/** One observed price change — the intra-day timeline for a station. */\nexport interface FuelStationPricePoint {\n product: string;\n observed_at: string;\n price: number;\n}\n\n/** `GET /v1/fuel/stations/{id}`. `days` is null in the unentitled preview. */\nexport interface FuelStationDetail {\n demo?: boolean;\n preview_rows?: number;\n note?: string;\n upgrade_url?: string;\n station: FuelStation;\n days?: number | null;\n prices: FuelStationPricePoint[];\n}\n\n/** Filters for `fuelPrices()`. */\nexport interface FuelPricesParams {\n /** Region slug, or a comma-separated list of them (\"us,ca\"). */\n region?: string;\n /** Free-text place name (\"Calgary, Alberta\"). */\n geo?: string;\n q?: string;\n limit?: number;\n offset?: number;\n}\n\n/** One aggregated price series (state / national / metro). */\nexport interface PriceSeries {\n id: number;\n domain: string;\n source: string;\n region?: string | null;\n geo?: string | null;\n item: string;\n item_cn?: string | null;\n unit?: string | null;\n unit_cn?: string | null;\n frequency?: string | null;\n latest_period?: string | null;\n latest_value?: number | null;\n prev_value?: number | null;\n points?: number | null;\n spark?: number[];\n}\n\n/** `GET /v1/prices` — a page of series plus the page's own metadata. */\nexport interface PriceSeriesResponse {\n count: number;\n domain?: string | null;\n region?: string | null;\n limit: number;\n offset: number;\n data: PriceSeries[];\n}\n\nexport class WhereqError extends Error {\n constructor(\n public readonly status: number,\n message: string,\n public readonly url: string,\n ) {\n super(`whereq.cloud API error ${status} for ${url}: ${message}`);\n this.name = \"WhereqError\";\n }\n}\n\nexport interface ClientOptions {\n /** `wq_live_…` key for metered endpoints (sent as `X-API-Key`). */\n apiKey?: string;\n /** Override the API base (default `https://api.whereq.cloud`). */\n baseUrl?: string;\n /** Custom fetch (e.g. for Node <18 or testing). Defaults to global `fetch`. */\n fetch?: typeof fetch;\n}\n\ntype Params = Record<string, unknown>;\n\n/** The API key from the environment, when there is one. */\nfunction envApiKey(): string {\n const proc = (globalThis as { process?: { env?: Record<string, string | undefined> } }).process;\n return proc?.env?.WHEREQ_API_KEY ?? \"\";\n}\n\nexport class Whereq {\n private readonly baseUrl: string;\n private readonly headers: Record<string, string>;\n private readonly _fetch: typeof fetch;\n\n constructor(opts: ClientOptions = {}) {\n this.baseUrl = (opts.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n this.headers = { Accept: \"application/json\" };\n // The key may come from the options or the environment, in that order.\n const key = opts.apiKey ?? envApiKey();\n if (key) this.headers[\"X-API-Key\"] = key;\n const f = opts.fetch ?? globalThis.fetch;\n if (!f) throw new Error(\"No global fetch available — pass `fetch` in options (Node <18).\");\n this._fetch = f;\n }\n\n private url(path: string, params: Params): string {\n const qs = new URLSearchParams();\n for (const [k, v] of Object.entries(params)) {\n if (v !== undefined && v !== null) qs.set(k, String(v));\n }\n const s = qs.toString();\n return `${this.baseUrl}${path}${s ? `?${s}` : \"\"}`;\n }\n\n /** GET any endpoint; `undefined`/`null` params are dropped. Returns parsed JSON. */\n async get<T = unknown>(path: string, params: Params = {}): Promise<T> {\n const url = this.url(path, params);\n const res = await this._fetch(url, { headers: this.headers });\n if (!res.ok) {\n let msg = res.statusText;\n try {\n const j = (await res.json()) as { detail?: string };\n msg = j?.detail || JSON.stringify(j) || msg;\n } catch {\n /* non-JSON error body */\n }\n throw new WhereqError(res.status, msg, url);\n }\n return (await res.json()) as T;\n }\n\n /** GET a non-JSON endpoint (e.g. CSV export) as text. */\n async getText(path: string, params: Params = {}): Promise<string> {\n const url = this.url(path, params);\n const res = await this._fetch(url, { headers: this.headers });\n if (!res.ok) throw new WhereqError(res.status, res.statusText, url);\n return res.text();\n }\n\n // -- prices / cost of living ------------------------------------------------\n /** Cost-of-living price series (fuel | food | energy | housing | rent).\n * `region` takes a region slug or a comma-separated list (\"us,ca\");\n * `geo` is a free-text place name (\"Calgary, Alberta\"). */\n prices(p: { domain?: string; region?: string; geo?: string; bedrooms?: number; q?: string; limit?: number; offset?: number } = {}): Promise<PriceSeriesResponse> {\n return this.get<PriceSeriesResponse>(\"/v1/prices\", p);\n }\n price(seriesId: number) {\n return this.get(`/v1/prices/${seriesId}`);\n }\n pricesCsv(p: { domain?: string; region?: string; geo?: string; bedrooms?: number; q?: string } = {}) {\n return this.getText(\"/v1/prices/export\", p);\n }\n /** Compare cost of living across US states / CA provinces / metros.\n * `places`: comma-separated `region:name` or `m:<rent-series-id>`. */\n costOfLiving(places: string) {\n return this.get(\"/v1/cost-of-living\", { places });\n }\n\n // -- discovery / facets -----------------------------------------------------\n catalog() { return this.get(\"/v1/catalog\"); }\n categories() { return this.get(\"/v1/categories\"); }\n regions() { return this.get(\"/v1/regions\"); }\n domains() { return this.get(\"/v1/domains\"); }\n trending(p: Params = {}) { return this.get(\"/v1/trending\", p); }\n\n // -- finance ----------------------------------------------------------------\n hotstocks(limit = 20) { return this.get(\"/v1/hotstocks\", { limit }); }\n quotes(p: Params = {}) { return this.get(\"/v1/quotes\", p); }\n news(p: Params = {}) { return this.get(\"/v1/news\", p); }\n screener(p: Params = {}) { return this.get(\"/v1/screener\", p); }\n search(q: string, p: Params = {}) { return this.get(\"/v1/search\", { q, ...p }); }\n\n // -- autos ------------------------------------------------------------------\n autosRecalls(p: Params = {}) { return this.get(\"/v1/autos/recalls\", p); }\n autosListings(p: Params = {}) { return this.get(\"/v1/autos/listings\", p); }\n autosFuelEconomy(p: Params = {}) { return this.get(\"/v1/autos/fuel-economy\", p); }\n autosModels(p: Params = {}) { return this.get(\"/v1/autos/models\", p); }\n\n // -- lottery -----------------------------------------------------------------\n /** Recent lottery draws, newest first.\n *\n * Unentitled callers get the oldest 100 draws instead of the recent\n * ones — check `response.demo`.\n */\n lotteryDraws(p: { game?: string; days?: number; limit?: number } & Params = {}): Promise<any> {\n return this.get(\"/v1/lottery/draws\", p);\n }\n /** The most recent draw for a game. On the unentitled preview this is the\n * *oldest* draw — the recent one is the gated, valuable row. */\n lotteryLatestDraw(game: string): Promise<any> {\n return this.get(`/v1/lottery/draws/${encodeURIComponent(game)}/latest`);\n }\n /** Per-number frequency for a game over a window (30–1825 days). */\n lotteryFrequency(game: string, days = 365): Promise<any> {\n return this.get(`/v1/lottery/draws/${encodeURIComponent(game)}/frequency`, { days });\n }\n /** The lottery game registry: names, play rules and draw days. */\n lotteryGames(p: { country?: string; region?: string } & Params = {}): Promise<any> {\n return this.get(\"/v1/lottery/games\", p);\n }\n /** One game's full play rules and metadata. */\n lotteryGame(slug: string): Promise<any> {\n return this.get(`/v1/lottery/games/${encodeURIComponent(slug)}`);\n }\n\n // -- fuel (gas & diesel) ----------------------------------------------------\n /** Geolocated retail fuel stations with their latest prices.\n *\n * Coverage: Mexico (`MX`, CRE open data), the United States (`US`) and\n * Canada (`CA`). Prices are in **local currency per litre** — `MXN/L`,\n * `USD/L` and `CAD/L` respectively.\n *\n * Unentitled callers get a 100-row preview of the oldest rows and the\n * pagination arguments are ignored — check `response.demo`.\n */\n fuelStations(p: FuelStationsParams & Params = {}): Promise<FuelStationsResponse> {\n return this.get<FuelStationsResponse>(\"/v1/fuel/stations\", p);\n }\n\n /** One station: location, latest prices and its price-change timeline. */\n fuelStation(\n id: number | string,\n p: FuelStationParams & Params = {},\n ): Promise<FuelStationDetail> {\n return this.get<FuelStationDetail>(\n `/v1/fuel/stations/${encodeURIComponent(String(id))}`,\n p,\n );\n }\n\n /** Yield every matching station, paging through the API for you.\n *\n * Only meaningful with an entitled key. The unentitled preview always\n * returns the *same* oldest 100 rows and ignores the paging arguments,\n * so there is nothing more to fetch: this yields that first page and\n * stops rather than looping on it.\n */\n async *fuelStationsAll(\n p: FuelStationsParams & Params = {},\n ): AsyncGenerator<FuelStation> {\n const pageSize = Math.min(Math.max(Number(p.limit ?? 500), 1), 500);\n let offset = Number(p.offset ?? 0);\n for (;;) {\n const page = await this.fuelStations({ ...p, limit: pageSize, offset });\n const stations = page.stations ?? [];\n if (stations.length === 0) return;\n for (const s of stations) yield s;\n if (page.demo) return; // preview: every page is the same slice\n offset += stations.length;\n if (page.total != null && offset >= page.total) return;\n }\n }\n\n /** Aggregated fuel price series (state / national / metro).\n *\n * These are the *series* behind the charts — EIA weekly for the US,\n * StatCan monthly for Canada, CRE for Mexico — not the station-level\n * prices that `fuelStations()` returns.\n */\n fuelPrices(p: FuelPricesParams & Params = {}): Promise<PriceSeriesResponse> {\n return this.get<PriceSeriesResponse>(\"/v1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AAK,IAAoB,kBAAkB,CAAA;AAAA,EACpD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,YACE,CAAA,EACyB;AACzB,IAAA,OAAO,IAAA,CAAK,GAAA,CAAoB,kBAAA,EAAoB,CAAC,CAAA;AAAA,EACvD;AACF;AAEA,IAAO,aAAA,GAAQ","file":"index.js","sourcesContent":["{\n \"name\": \"@whereq/cloud\",\n \"version\": \"0.6.0\",\n \"packageManager\": \"pnpm@9.15.9\",\n \"description\": \"Official JavaScript/TypeScript SDK for the WhereQ data cloud (api.whereq.cloud) — North-America fuel & gas-station prices, cost-of-living prices, autos, lottery, trending, finance & more.\",\n \"license\": \"MIT\",\n \"author\": \"WhereQ <whereq@gmail.com>\",\n \"type\": \"module\",\n \"main\": \"./dist/index.cjs\",\n \"module\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"exports\": {\n \".\": {\n \"types\": \"./dist/index.d.ts\",\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n },\n \"./package.json\": \"./package.json\"\n },\n \"files\": [\n \"dist\",\n \"README.md\",\n \"LICENSE\"\n ],\n \"sideEffects\": false,\n \"engines\": {\n \"node\": \">=18\"\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/whereq/whereq-cloud-js.git\"\n },\n \"homepage\": \"https://whereq.cloud\",\n \"bugs\": \"https://github.com/whereq/whereq-cloud-js/issues\",\n \"keywords\": [\n \"whereq\",\n \"data\",\n \"api\",\n \"fuel-prices\",\n \"gas-prices\",\n \"cost-of-living\",\n \"prices\",\n \"autos\",\n \"trending\",\n \"finance\",\n \"sdk\"\n ],\n \"scripts\": {\n \"build\": \"tsup\",\n \"typecheck\": \"tsc --noEmit\",\n \"test\": \"vitest run\",\n \"verify\": \"pnpm run typecheck && pnpm run test && pnpm run build\",\n \"release\": \"pnpm run build && changeset publish\",\n \"prepublishOnly\": \"pnpm run build\"\n },\n \"devDependencies\": {\n \"@changesets/cli\": \"^2.27.9\",\n \"tsup\": \"^8.3.0\",\n \"typescript\": \"^5.7.2\",\n \"vitest\": \"^2.1.0\"\n },\n \"publishConfig\": {\n \"access\": \"public\",\n \"provenance\": true\n }\n}\n","/**\n * whereq.cloud — official JavaScript/TypeScript SDK for the WhereQ data cloud.\n *\n * A thin, typed wrapper over the versioned `/v1` HTTP API at `api.whereq.cloud`.\n * Public endpoints work with no key; metered endpoints take an API key.\n *\n * ```ts\n * import { Whereq } from \"@whereq/cloud\";\n *\n * const wq = new Whereq(); // public access\n * // const wq = new Whereq({ apiKey: \"wq_live_…\" }); // metered tier\n *\n * await wq.costOfLiving(\"us:California,ca:Ontario\");\n * await wq.prices({ domain: \"rent\", region: \"us\", bedrooms: 2 });\n * await wq.get(\"/v1/trending\", { limit: 10 }); // escape hatch\n * ```\n */\nimport pkg from \"../package.json\";\n\n/**\n * The SDK version, read straight from `package.json` so it can never drift\n * from what is published. Changesets bumps `package.json`; this follows it.\n */\nexport const VERSION = pkg.version;\n\nconst DEFAULT_BASE_URL = \"https://api.whereq.cloud\";\n\n/** The products a station can quote. Mexico's CRE feed carries the first,\n * second and fourth; GasBuddy (US/Canada) adds midgrade. */\nexport const FUEL_PRODUCTS = [\"regular\", \"midgrade\", \"premium\", \"diesel\"] as const;\nexport type FuelProduct = (typeof FUEL_PRODUCTS)[number];\n\n/** Countries with station-level fuel data. */\nexport const FUEL_COUNTRIES = [\"MX\", \"US\", \"CA\"] as const;\nexport type FuelCountry = (typeof FUEL_COUNTRIES)[number];\n\n/** The unit each country quotes in — always local currency per litre. */\nexport const FUEL_CURRENCIES: Record<FuelCountry, string> = {\n MX: \"MXN/L\",\n US: \"USD/L\",\n CA: \"CAD/L\",\n};\n\n/** One product's latest price at a station. */\nexport interface FuelStationPrice {\n price: number;\n observed_at: string;\n}\n\n/** A geolocated retail fuel station.\n * `state` is the human label (\"Ontario\", \"Texas\"); `state_iso` is the\n * two-letter code (\"ON\", \"TX\"). */\nexport interface FuelStation {\n id: number;\n source: string;\n ext_id: string;\n country: string;\n name: string;\n brand?: string | null;\n state?: string | null;\n state_iso?: string | null;\n municipality?: string | null;\n lat?: number | null;\n lon?: number | null;\n /** The latest price per product — present on the *list* endpoint. The\n * *detail* endpoint omits it: its timeline comes back as the separate\n * `prices` array on the response. */\n prices?: Record<string, FuelStationPrice>;\n}\n\n/** Filters for `fuelStations()`. */\nexport interface FuelStationsParams {\n /** \"MX\", \"US\" or \"CA\". */\n country?: FuelCountry | string;\n /** State/province name *or* ISO code — \"Ontario\"/\"ON\", \"Texas\"/\"TX\". */\n state?: string;\n /** City name, e.g. \"Mississauga\". */\n municipality?: string;\n product?: FuelProduct | string;\n /** \"minLon,minLat,maxLon,maxLat\" — a map viewport. */\n bbox?: string;\n /** Station-name search. */\n q?: string;\n /** 1–500 rows per page (default 100). */\n limit?: number;\n /** Row offset for paging. */\n offset?: number;\n}\n\n/** Filters for `fuelStation()`. */\nexport interface FuelStationParams {\n /** Restrict the timeline to one product. */\n product?: FuelProduct | string;\n /** How far back the timeline reaches (1–1825, default 90). */\n days?: number;\n}\n\n/** `GET /v1/fuel/stations`. Unentitled callers get a 100-row preview of the\n * oldest rows: `demo` is true, `total` is null and paging is ignored. */\nexport interface FuelStationsResponse {\n demo?: boolean;\n preview_rows?: number;\n note?: string;\n upgrade_url?: string;\n as_of: string;\n count: number;\n total?: number | null;\n stations: FuelStation[];\n}\n\n/** One observed price change — the intra-day timeline for a station. */\nexport interface FuelStationPricePoint {\n product: string;\n observed_at: string;\n price: number;\n}\n\n/** `GET /v1/fuel/stations/{id}`. `days` is null in the unentitled preview. */\nexport interface FuelStationDetail {\n demo?: boolean;\n preview_rows?: number;\n note?: string;\n upgrade_url?: string;\n station: FuelStation;\n days?: number | null;\n prices: FuelStationPricePoint[];\n}\n\n/** Filters for `fuelPrices()`. */\nexport interface FuelPricesParams {\n /** Region slug, or a comma-separated list of them (\"us,ca\"). */\n region?: string;\n /** Free-text place name (\"Calgary, Alberta\"). */\n geo?: string;\n q?: string;\n limit?: number;\n offset?: number;\n}\n\n/** One aggregated price series (state / national / metro). */\nexport interface PriceSeries {\n id: number;\n domain: string;\n source: string;\n region?: string | null;\n geo?: string | null;\n item: string;\n item_cn?: string | null;\n unit?: string | null;\n unit_cn?: string | null;\n frequency?: string | null;\n latest_period?: string | null;\n latest_value?: number | null;\n prev_value?: number | null;\n points?: number | null;\n spark?: number[];\n}\n\n/** `GET /v1/prices` — a page of series plus the page's own metadata. */\nexport interface PriceSeriesResponse {\n count: number;\n domain?: string | null;\n region?: string | null;\n limit: number;\n offset: number;\n data: PriceSeries[];\n}\n\n// -- geography (places, boundaries, hierarchy) ---------------------------------\n\n/** One place — a province, a municipality, a ward, a neighbourhood.\n *\n * `kind` is the platform's own concept (`province`, `region`,\n * `municipality`, `city`, `town`, `ward`, `neighbourhood`…), not the\n * source's admin level. `country_code` is the two-letter ISO code and is\n * the same for both vocabularies — a country filter accepts `CA` or\n * `CAN` and answers with the same places either way.\n */\nexport interface GeoPlace {\n uid: string;\n kind: string;\n kind_source: string;\n name: string;\n name_en?: string | null;\n name_zh?: string | null;\n name_local?: string | null;\n official_name?: string | null;\n source: string;\n source_id: string;\n source_url?: string | null;\n license?: string | null;\n raw_admin_level?: number | null;\n raw_place?: string | null;\n raw_boundary?: string | null;\n country_code?: string | null;\n province_code?: string | null;\n iso_code?: string | null;\n ref?: string | null;\n population?: number | null;\n population_date?: string | null;\n wikidata?: string | null;\n wikipedia?: string | null;\n website?: string | null;\n capital?: string | null;\n centroid_lon?: number | null;\n centroid_lat?: number | null;\n bbox_min_lon?: number | null;\n bbox_min_lat?: number | null;\n bbox_max_lon?: number | null;\n bbox_max_lat?: number | null;\n area_km2?: number | null;\n has_boundary: boolean;\n}\n\nexport interface GeoPlaceList {\n count: number;\n data: GeoPlace[];\n limit: number;\n offset: number;\n}\n\n/** One container of a place, as the detail endpoint lists them.\n *\n * A place has SEVERAL parents — a neighbourhood is in a ward, in a city,\n * in a census division and in a province, all at once. The list is\n * deliberately a list.\n */\nexport interface GeoParent {\n uid: string;\n kind: string;\n name: string;\n source: string;\n area_ratio?: number | null;\n is_primary: boolean;\n}\n\n/** One place with its containers and the places inside it. */\nexport interface GeoPlaceDetail {\n uid: string;\n place: GeoPlace;\n parents: GeoParent[];\n children: GeoParent[];\n}\n\n/** One concept in the vocabulary, with a live count behind it. */\nexport interface GeoConcept {\n kind: string;\n name: string;\n name_cn?: string | null;\n description?: string | null;\n description_cn?: string | null;\n places: number;\n with_boundary: number;\n rank: number;\n}\n\n/** The vocabulary, explained. */\nexport interface GeoConceptList {\n count: number;\n concepts: GeoConcept[];\n sources: Array<Record<string, unknown>>;\n}\n\n/** Two places of DIFFERENT kinds covering the same ground.\n *\n * This is the deliberate part of the dataset: a census subdivision and\n * an OpenStreetMap city boundary that describe the same town in two\n * vocabularies. The platform keeps both rather than picking one.\n */\nexport interface GeoOverlap {\n a_id: number;\n b_id: number;\n a_uid: string;\n b_uid: string;\n a_name: string;\n b_name: string;\n a_kind: string;\n b_kind: string;\n a_source: string;\n b_source: string;\n overlap_ratio: number;\n a_concept: string;\n b_concept: string;\n}\n\n/** The overlapping pairs inside a box. */\nexport interface GeoOverlapList {\n bbox: Record<string, number>;\n min_ratio: number;\n count: number;\n overlaps: GeoOverlap[];\n}\n\n/** One place in the containing stack at a point.\n *\n * `country_code` is on every level, so the stack can be read without a\n * second lookup.\n */\nexport interface GeoAtPlace {\n uid: string;\n kind: string;\n kind_source: string;\n name: string;\n name_en?: string | null;\n name_zh?: string | null;\n source: string;\n raw_admin_level?: number | null;\n raw_place?: string | null;\n population?: number | null;\n wikidata?: string | null;\n centroid_lon?: number | null;\n centroid_lat?: number | null;\n area_km2?: number | null;\n country_code?: string | null;\n province_code?: string | null;\n boundary_area_km2?: number | null;\n concept?: Record<string, unknown>;\n}\n\n/** Every place containing a point, broadest first: country, province,\n * region, municipality, city, ward, neighbourhood. The answer to \"where\n * am I?\" without pretending one of them is *the* answer. */\nexport interface GeoAtResponse {\n lon: number;\n lat: number;\n count: number;\n places: GeoAtPlace[];\n}\n\n/** A place's outline as GeoJSON — a FeatureCollection you can hand\n * straight to a map library. */\nexport interface GeoBoundary {\n type: string;\n features: Array<Record<string, unknown>>;\n}\n\nexport interface GeoPlacesParams {\n kind?: string;\n source?: string;\n country?: string;\n q?: string;\n bbox?: string;\n has_boundary?: boolean;\n limit?: number;\n offset?: number;\n}\n\nexport class WhereqError extends Error {\n constructor(\n public readonly status: number,\n message: string,\n public readonly url: string,\n ) {\n super(`whereq.cloud API error ${status} for ${url}: ${message}`);\n this.name = \"WhereqError\";\n }\n}\n\nexport interface ClientOptions {\n /** `wq_live_…` key for metered endpoints (sent as `X-API-Key`). */\n apiKey?: string;\n /** Override the API base (default `https://api.whereq.cloud`). */\n baseUrl?: string;\n /** Custom fetch (e.g. for Node <18 or testing). Defaults to global `fetch`. */\n fetch?: typeof fetch;\n}\n\ntype Params = Record<string, unknown>;\n\n/** The API key from the environment, when there is one. */\nfunction envApiKey(): string {\n const proc = (globalThis as { process?: { env?: Record<string, string | undefined> } }).process;\n return proc?.env?.WHEREQ_API_KEY ?? \"\";\n}\n\nexport class Whereq {\n private readonly baseUrl: string;\n private readonly headers: Record<string, string>;\n private readonly _fetch: typeof fetch;\n\n constructor(opts: ClientOptions = {}) {\n this.baseUrl = (opts.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n this.headers = { Accept: \"application/json\" };\n // The key may come from the options or the environment, in that order.\n const key = opts.apiKey ?? envApiKey();\n if (key) this.headers[\"X-API-Key\"] = key;\n const f = opts.fetch ?? globalThis.fetch;\n if (!f) throw new Error(\"No global fetch available — pass `fetch` in options (Node <18).\");\n this._fetch = f;\n }\n\n private url(path: string, params: Params): string {\n const qs = new URLSearchParams();\n for (const [k, v] of Object.entries(params)) {\n if (v !== undefined && v !== null) qs.set(k, String(v));\n }\n const s = qs.toString();\n return `${this.baseUrl}${path}${s ? `?${s}` : \"\"}`;\n }\n\n /** GET any endpoint; `undefined`/`null` params are dropped. Returns parsed JSON. */\n async get<T = unknown>(path: string, params: Params = {}): Promise<T> {\n const url = this.url(path, params);\n const res = await this._fetch(url, { headers: this.headers });\n if (!res.ok) {\n let msg = res.statusText;\n try {\n const j = (await res.json()) as { detail?: string };\n msg = j?.detail || JSON.stringify(j) || msg;\n } catch {\n /* non-JSON error body */\n }\n throw new WhereqError(res.status, msg, url);\n }\n return (await res.json()) as T;\n }\n\n /** GET a non-JSON endpoint (e.g. CSV export) as text. */\n async getText(path: string, params: Params = {}): Promise<string> {\n const url = this.url(path, params);\n const res = await this._fetch(url, { headers: this.headers });\n if (!res.ok) throw new WhereqError(res.status, res.statusText, url);\n return res.text();\n }\n\n // -- prices / cost of living ------------------------------------------------\n /** Cost-of-living price series (fuel | food | energy | housing | rent).\n * `region` takes a region slug or a comma-separated list (\"us,ca\");\n * `geo` is a free-text place name (\"Calgary, Alberta\"). */\n prices(p: { domain?: string; region?: string; geo?: string; bedrooms?: number; q?: string; limit?: number; offset?: number } = {}): Promise<PriceSeriesResponse> {\n return this.get<PriceSeriesResponse>(\"/v1/prices\", p);\n }\n price(seriesId: number) {\n return this.get(`/v1/prices/${seriesId}`);\n }\n pricesCsv(p: { domain?: string; region?: string; geo?: string; bedrooms?: number; q?: string } = {}) {\n return this.getText(\"/v1/prices/export\", p);\n }\n /** Compare cost of living across US states / CA provinces / metros.\n * `places`: comma-separated `region:name` or `m:<rent-series-id>`. */\n costOfLiving(places: string) {\n return this.get(\"/v1/cost-of-living\", { places });\n }\n\n // -- discovery / facets -----------------------------------------------------\n catalog() { return this.get(\"/v1/catalog\"); }\n categories() { return this.get(\"/v1/categories\"); }\n regions() { return this.get(\"/v1/regions\"); }\n domains() { return this.get(\"/v1/domains\"); }\n trending(p: Params = {}) { return this.get(\"/v1/trending\", p); }\n\n // -- finance ----------------------------------------------------------------\n hotstocks(limit = 20) { return this.get(\"/v1/hotstocks\", { limit }); }\n quotes(p: Params = {}) { return this.get(\"/v1/quotes\", p); }\n news(p: Params = {}) { return this.get(\"/v1/news\", p); }\n screener(p: Params = {}) { return this.get(\"/v1/screener\", p); }\n search(q: string, p: Params = {}) { return this.get(\"/v1/search\", { q, ...p }); }\n\n // -- autos ------------------------------------------------------------------\n autosRecalls(p: Params = {}) { return this.get(\"/v1/autos/recalls\", p); }\n autosListings(p: Params = {}) { return this.get(\"/v1/autos/listings\", p); }\n autosFuelEconomy(p: Params = {}) { return this.get(\"/v1/autos/fuel-economy\", p); }\n autosModels(p: Params = {}) { return this.get(\"/v1/autos/models\", p); }\n\n // -- lottery -----------------------------------------------------------------\n /** Recent lottery draws, newest first.\n *\n * Unentitled callers get the oldest 100 draws instead of the recent\n * ones — check `response.demo`.\n */\n lotteryDraws(p: { game?: string; days?: number; limit?: number } & Params = {}): Promise<any> {\n return this.get(\"/v1/lottery/draws\", p);\n }\n /** The most recent draw for a game. On the unentitled preview this is the\n * *oldest* draw — the recent one is the gated, valuable row. */\n lotteryLatestDraw(game: string): Promise<any> {\n return this.get(`/v1/lottery/draws/${encodeURIComponent(game)}/latest`);\n }\n /** Per-number frequency for a game over a window (30–1825 days). */\n lotteryFrequency(game: string, days = 365): Promise<any> {\n return this.get(`/v1/lottery/draws/${encodeURIComponent(game)}/frequency`, { days });\n }\n /** The lottery game registry: names, play rules and draw days. */\n lotteryGames(p: { country?: string; region?: string } & Params = {}): Promise<any> {\n return this.get(\"/v1/lottery/games\", p);\n }\n /** One game's full play rules and metadata. */\n lotteryGame(slug: string): Promise<any> {\n return this.get(`/v1/lottery/games/${encodeURIComponent(slug)}`);\n }\n\n // -- fuel (gas & diesel) ----------------------------------------------------\n /** Geolocated retail fuel stations with their latest prices.\n *\n * Coverage: Mexico (`MX`, CRE open data), the United States (`US`) and\n * Canada (`CA`). Prices are in **local currency per litre** — `MXN/L`,\n * `USD/L` and `CAD/L` respectively.\n *\n * Unentitled callers get a 100-row preview of the oldest rows and the\n * pagination arguments are ignored — check `response.demo`.\n */\n fuelStations(p: FuelStationsParams & Params = {}): Promise<FuelStationsResponse> {\n return this.get<FuelStationsResponse>(\"/v1/fuel/stations\", p);\n }\n\n /** One station: location, latest prices and its price-change timeline. */\n fuelStation(\n id: number | string,\n p: FuelStationParams & Params = {},\n ): Promise<FuelStationDetail> {\n return this.get<FuelStationDetail>(\n `/v1/fuel/stations/${encodeURIComponent(String(id))}`,\n p,\n );\n }\n\n /** Yield every matching station, paging through the API for you.\n *\n * Only meaningful with an entitled key. The unentitled preview always\n * returns the *same* oldest 100 rows and ignores the paging arguments,\n * so there is nothing more to fetch: this yields that first page and\n * stops rather than looping on it.\n */\n async *fuelStationsAll(\n p: FuelStationsParams & Params = {},\n ): AsyncGenerator<FuelStation> {\n const pageSize = Math.min(Math.max(Number(p.limit ?? 500), 1), 500);\n let offset = Number(p.offset ?? 0);\n for (;;) {\n const page = await this.fuelStations({ ...p, limit: pageSize, offset });\n const stations = page.stations ?? [];\n if (stations.length === 0) return;\n for (const s of stations) yield s;\n if (page.demo) return; // preview: every page is the same slice\n offset += stations.length;\n if (page.total != null && offset >= page.total) return;\n }\n }\n\n /** Aggregated fuel price series (state / national / metro).\n *\n * These are the *series* behind the charts — EIA weekly for the US,\n * StatCan monthly for Canada, CRE for Mexico — not the station-level\n * prices that `fuelStations()` returns.\n */\n fuelPrices(p: FuelPricesParams & Params = {}): Promise<PriceSeriesResponse> {\n return this.get<PriceSeriesResponse>(\"/v1/prices\", { domain: \"fuel\", ...p });\n }\n\n // -- geography (places, boundaries, hierarchy) ------------------------------\n /** The place list — provinces, regions, municipalities, cities, towns,\n * wards, neighbourhoods, countries.\n *\n * `country` takes an ISO code and either spelling works: `\"CA\"` and\n * `\"CAN\"` find the same places, in both vocabularies.\n */\n geoPlaces(p: GeoPlacesParams & Params = {}): Promise<GeoPlaceList> {\n return this.get<GeoPlaceList>(\"/v1/geo/places\", p);\n }\n\n /** One place, with its containers AND the places inside it.\n *\n * The parents are a list on purpose: a place belongs to several things\n * at once.\n */\n geoPlace(uid: string): Promise<GeoPlaceDetail> {\n return this.get<GeoPlaceDetail>(`/v1/geo/places/${encodeURIComponent(uid)}`);\n }\n\n /** A place's outline as GeoJSON.\n *\n * `simplify` is in METRES: the outline keeps every corner more than\n * that far from the original, and the result is still a valid polygon.\n */\n geoBoundary(uid: string, p: { simplify?: number } & Params = {}): Promise<GeoBoundary> {\n return this.get<GeoBoundary>(`/v1/geo/places/${encodeURIComponent(uid)}/boundary`, p);\n }\n\n /** Every place containing a point, broadest first.\n *\n * The answer to \"which district is this?\" without picking a winner: a\n * point downtown Toronto lands in a neighbourhood, a ward, a city, a\n * census division, a province and a country, and all of them are\n * returned.\n */\n geoAt(lon: number, lat: number): Promise<GeoAtResponse> {\n return this.get<GeoAtResponse>(\"/v1/geo/at\", { lon, lat });\n }\n\n /** The vocabulary: every concept, in both languages, with a live count of\n * how many places and outlines it has. */\n geoConcepts(): Promise<GeoConceptList> {\n return this.get<GeoConceptList>(\"/v1/geo/concepts\");\n }\n\n /** The places of different kinds that cover the same ground.\n *\n * `bbox` is required — \"minLon,minLat,maxLon,maxLat\". Comparing every\n * pair in the country is a quadratic join, and nobody asks that\n * question about all of Canada at once.\n */\n geoOverlaps(\n p: { bbox: string; min_ratio?: number; limit?: number } & Params,\n ): Promise<GeoOverlapList> {\n return this.get<GeoOverlapList>(\"/v1/geo/overlaps\", p);\n }\n}\n\nexport default Whereq;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@whereq/cloud",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Official JavaScript/TypeScript SDK for the WhereQ data cloud (api.whereq.cloud) — North-America fuel & gas-station prices, cost-of-living prices, autos, lottery, trending, finance & more.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "WhereQ <whereq@gmail.com>",
|