@whereq/cloud 0.5.1 → 0.7.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 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,111 @@ 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
+
138
+ ## Local
139
+
140
+ News, events, stories and notices from the configured local feeds, plus the
141
+ points of interest from the OpenStreetMap sweep — with their positions.
142
+
143
+ ```ts
144
+ // The feed — news, events, stories, notices
145
+ await wq.localContent({ type: "news", city: "Toronto", limit: 20 });
146
+ await wq.localContent({ q: "storm", has_location: true });
147
+
148
+ // One item, with its tags
149
+ await wq.localContentItem(42);
150
+
151
+ // The points of interest. lat/lng/radius_km go together.
152
+ await wq.localPlaces({ category: "food", limit: 50 });
153
+ await wq.localPlaces({ lat: 43.65, lng: -79.38, radius_km: 5 });
154
+
155
+ // One place, the configured feeds, and the vocabulary
156
+ await wq.localPlace(7);
157
+ await wq.localSources();
158
+ await wq.localTaxonomy();
159
+ ```
160
+
161
+ ## Schools
162
+
163
+ The school boards' own published directories: the name, the board, the type,
164
+ the grade range, the programmes, the contact block and the position.
165
+
166
+ ```ts
167
+ // The directory
168
+ await wq.schools({ board: "ycdsb", type: "secondary", limit: 50 });
169
+ await wq.schools({ q: "theresa", has_boundary: true });
170
+
171
+ // The board registry, and the vocabulary
172
+ await wq.schoolBoards();
173
+ await wq.schoolTaxonomy();
174
+
175
+ // One school. The uid is board-qualified and carries a slash.
176
+ await wq.school("ycdsb/0158");
177
+
178
+ // The catchments and the scores — these need the `school_licensed` scope.
179
+ await wq.schoolsAt({ lat: 43.89, lng: -79.47 });
180
+ await wq.schoolBoundary("ycdsb/0158", { simplify: 50 });
181
+ await wq.schoolScores("ycdsb/0158", { year: 2024 });
182
+ ```
183
+
184
+ ### The two licence tiers
185
+
186
+ The school data splits in two, and the split is by licence:
187
+
188
+ - **The open tier** — the name, the board, the type, the grade range, the
189
+ programmes, the address, the contact block, the position. The boards
190
+ publish these on their own websites. Scope: `school`.
191
+ - **The licensed tier** — the catchment polygons and the assessment
192
+ scores. The catchment maps are the boards' licensed data (**viewing, not
193
+ redistribution**), and the scores come from a commercially-encumbered
194
+ feed. Scope: `school_licensed`, which is **internal-only** — it is never
195
+ granted to a customer-facing key.
196
+
197
+ So the behaviour is:
198
+
199
+ - A key **without** `school_licensed` gets the school back with the `hs_*`
200
+ fields **absent** — not null, absent — and `schoolBoundary()`,
201
+ `schoolScores()` and `schoolsAt()` reject with a `WhereqError` of status
202
+ **403**.
203
+ - A key **with** `school_licensed` gets the scores and the polygons.
204
+
205
+ A valid key that lacks the scope gets 403, not 401: 401 means "who are
206
+ you", and a client that gets 401 retries with different credentials.
207
+
208
+
96
209
  ## License
97
210
 
98
211
  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.7.0"};
8
+
5
9
  // src/index.ts
6
- var VERSION = "0.5.1";
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,127 @@ 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
+ }
264
+ // -- local (news, events, stories, places) --------------------------------
265
+ /** The local feed — news, events, stories and notices. */
266
+ localContent(p = {}) {
267
+ return this.get("/v1/local/content", p);
268
+ }
269
+ /** One item, with its tags. */
270
+ localContentItem(contentId) {
271
+ return this.get(`/v1/local/content/${contentId}`);
272
+ }
273
+ /** The points of interest — the OpenStreetMap sweep.
274
+ *
275
+ * `lat`, `lng` and `radius_km` go together: a proximity search needs
276
+ * all three.
277
+ */
278
+ localPlaces(p = {}) {
279
+ return this.get("/v1/local/places", p);
280
+ }
281
+ /** One place. */
282
+ localPlace(placeId) {
283
+ return this.get(`/v1/local/places/${placeId}`);
284
+ }
285
+ /** The configured local feeds. */
286
+ localSources(p = {}) {
287
+ return this.get("/v1/local/sources", p);
288
+ }
289
+ /** The local vocabulary — types, categories, place categories, sources. */
290
+ localTaxonomy() {
291
+ return this.get("/v1/local/taxonomy");
292
+ }
293
+ // -- schools ----------------------------------------------------------------
294
+ /** The school directory. */
295
+ schools(p = {}) {
296
+ return this.get("/v1/schools", p);
297
+ }
298
+ /** The board registry — the vocabulary the `board` filter uses. */
299
+ schoolBoards() {
300
+ return this.get("/v1/schools/boards");
301
+ }
302
+ /** The school vocabulary and the headline counts. */
303
+ schoolTaxonomy() {
304
+ return this.get("/v1/schools/taxonomy");
305
+ }
306
+ /** The catchments that cover a point.
307
+ *
308
+ * **Licensed.** This reads the catchment polygons, so it needs the
309
+ * `school_licensed` scope — a key without it gets a 403.
310
+ */
311
+ schoolsAt(p) {
312
+ return this.get("/v1/schools/at", p);
313
+ }
314
+ /** One school.
315
+ *
316
+ * The uid is board-qualified — `ycdsb/0158`, or
317
+ * `ycdsb/st-theresa-of-lisieux-chs` when the board publishes no code.
318
+ * It carries a slash, and the API's route is built for that.
319
+ *
320
+ * The scores come back only with the `school_licensed` scope.
321
+ */
322
+ school(uid) {
323
+ return this.get(`/v1/schools/${uid}`);
324
+ }
325
+ /** A school's catchment outline, as GeoJSON. **Licensed.**
326
+ * `simplify` is in METRES. */
327
+ schoolBoundary(uid, p = {}) {
328
+ return this.get(`/v1/schools/${uid}/boundary`, p);
329
+ }
330
+ /** One year's assessment snapshot, with the EQAO marks. **Licensed.**
331
+ * `year` picks a year; the latest is the default. */
332
+ schoolScores(uid, p = {}) {
333
+ return this.get(`/v1/schools/${uid}/scores`, p);
334
+ }
210
335
  };
211
336
  var index_default = Whereq;
212
337
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":[],"mappings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AA,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.1\";\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\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,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,EAC6B;AAC7B,IAAA,OAAO,IAAA,CAAK,GAAA,CAAwB,gBAAA,EAAkB,CAAC,CAAA;AAAA,EACzD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,OAAO,GAAA,EAAoC;AACzC,IAAA,OAAO,IAAA,CAAK,GAAA,CAAkB,CAAA,YAAA,EAAe,GAAG,CAAA,CAAE,CAAA;AAAA,EACpD;AAAA;AAAA;AAAA,EAIA,cAAA,CACE,GAAA,EACA,CAAA,GAAoC,EAAC,EACZ;AACzB,IAAA,OAAO,IAAA,CAAK,GAAA,CAAoB,CAAA,YAAA,EAAe,GAAG,aAAa,CAAC,CAAA;AAAA,EAClE;AAAA;AAAA;AAAA,EAIA,YAAA,CACE,GAAA,EACA,CAAA,GAAgC,EAAC,EACV;AACvB,IAAA,OAAO,IAAA,CAAK,GAAA,CAAkB,CAAA,YAAA,EAAe,GAAG,WAAW,CAAC,CAAA;AAAA,EAC9D;AACF;AAEA,IAAO,aAAA,GAAQ","file":"index.cjs","sourcesContent":["{\n \"name\": \"@whereq/cloud\",\n \"version\": \"0.7.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 \"prepublishOnly\": \"pnpm run build\"\n },\n \"devDependencies\": {\n \"@types/node\": \"^22.10.2\",\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. The release tooling bumps `package.json`; this\n * 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\n/* -- local (news, events, stories, places) -------------------------------- */\n\n/** One item from a local feed — a story, an event, a notice. */\nexport interface LocalContent {\n id: number;\n type: string;\n category?: string | null;\n title: string;\n summary?: string | null;\n description?: string | null;\n source_name?: string | null;\n source_url?: string | null;\n url?: string | null;\n publish_time?: string | null;\n latitude?: number | null;\n longitude?: number | null;\n city?: string | null;\n province?: string | null;\n country?: string | null;\n geocode_status?: string | null;\n confidence_score?: number | null;\n status: string;\n expires_at?: string | null;\n tags?: string[];\n}\n\n/** One point of interest. */\nexport interface LocalPlace {\n id: number;\n source: string;\n source_url?: string | null;\n license?: string | null;\n external_id: string;\n name: string;\n latitude?: number | null;\n longitude?: number | null;\n city?: string | null;\n province?: string | null;\n country?: string | null;\n category?: string | null;\n kind?: string | null;\n metadata?: Record<string, unknown>;\n}\n\n/** One configured local feed. */\nexport interface LocalSource {\n slug: string;\n name: string;\n kind: string;\n url?: string | null;\n default_type?: string | null;\n default_city?: string | null;\n default_province?: string | null;\n default_country?: string | null;\n enabled: boolean;\n crawl_interval_minutes: number;\n}\n\n/** The page envelope every list endpoint uses. */\nexport interface Page<T> {\n data: T[];\n pagination: {\n limit: number;\n count: number;\n next_cursor?: string | null;\n offset?: number;\n };\n}\n\n/* -- schools ---------------------------------------------------------------- */\n\n/** One school board. */\nexport interface SchoolBoard {\n slug: string;\n name: string;\n type?: string | null;\n region?: string | null;\n school_count: number;\n}\n\n/**\n * One school.\n *\n * The `hs_*` fields are **present only when the API key holds the\n * `school_licensed` scope**. Without it they are absent — not null — so a\n * caller can tell \"you are not entitled to this\" from \"there is no value\n * here\".\n */\nexport interface SchoolSummary {\n uid: string;\n name: string;\n type?: string | null;\n status?: string | null;\n province?: string | null;\n region?: string | null;\n city?: string | null;\n municipality?: string | null;\n board?: SchoolBoard | null;\n latitude?: number | null;\n longitude?: number | null;\n grade_range?: string | null;\n programs: string[];\n has_boundary: boolean;\n source?: string | null;\n source_url?: string | null;\n license?: string | null;\n hs_score?: number | null;\n hs_rank?: number | null;\n hs_rank_total?: number | null;\n hs_school_type?: string | null;\n}\n\n/** One school's yearly assessment snapshot. Licensed. */\nexport interface SchoolScores {\n uid: string;\n year: number;\n rank?: number | null;\n rank_total?: number | null;\n rank_score?: number | null;\n avg_exam_mark?: number | null;\n year_label?: string | null;\n source?: string | null;\n eqao: Array<{\n grade: number;\n year_mark?: string | null;\n rank?: number | null;\n total?: number | null;\n last5_avg?: number | null;\n }>;\n}\n\n/** One school, with its contact block. `scores` needs `school_licensed`. */\nexport interface SchoolDetail extends SchoolSummary {\n address?: string | null;\n phone?: string | null;\n phone2?: string | null;\n fax?: string | null;\n website_url?: string | null;\n boundary_pdf_url?: string | null;\n principal?: string | null;\n feeder_schools?: Record<string, unknown> | null;\n extra?: Record<string, unknown> | null;\n scores?: SchoolScores[];\n}\n\n/** A school's catchment outline. Licensed. */\nexport interface SchoolBoundary {\n uid: string;\n name: string;\n geometry?: { type: string; coordinates: unknown } | null;\n polygon_count: number;\n point_count: number;\n source?: string | null;\n source_url?: string | null;\n license?: string | null;\n}\n\n/** One catchment covering a queried point. Licensed. */\nexport interface CatchmentHit {\n uid: string;\n name: string;\n type?: string | null;\n distance_m?: number | null;\n}\n\n/** The school vocabulary and the headline counts. */\nexport interface SchoolTaxonomy {\n boards: SchoolBoard[];\n types: Array<{ id: string; name: string; count: number }>;\n program_categories: Array<{ id: string; name: string; count: number }>;\n stats: Record<string, number>;\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 // -- local (news, events, stories, places) --------------------------------\n /** The local feed — news, events, stories and notices. */\n localContent(\n p: {\n type?: string;\n category?: string;\n source?: string;\n city?: string;\n province?: string;\n bbox?: string;\n q?: string;\n since?: string;\n until?: string;\n has_location?: boolean;\n include_expired?: boolean;\n limit?: number;\n cursor?: string;\n } & Params = {},\n ): Promise<Page<LocalContent>> {\n return this.get<Page<LocalContent>>(\"/v1/local/content\", p);\n }\n\n /** One item, with its tags. */\n localContentItem(contentId: number): Promise<LocalContent> {\n return this.get<LocalContent>(`/v1/local/content/${contentId}`);\n }\n\n /** The points of interest — the OpenStreetMap sweep.\n *\n * `lat`, `lng` and `radius_km` go together: a proximity search needs\n * all three.\n */\n localPlaces(\n p: {\n category?: string;\n kind?: string;\n sub?: string;\n bbox?: string;\n lat?: number;\n lng?: number;\n radius_km?: number;\n q?: string;\n limit?: number;\n offset?: number;\n } & Params = {},\n ): Promise<Page<LocalPlace>> {\n return this.get<Page<LocalPlace>>(\"/v1/local/places\", p);\n }\n\n /** One place. */\n localPlace(placeId: number): Promise<LocalPlace> {\n return this.get<LocalPlace>(`/v1/local/places/${placeId}`);\n }\n\n /** The configured local feeds. */\n localSources(\n p: { enabled?: boolean; kind?: string; limit?: number } & Params = {},\n ): Promise<Page<LocalSource>> {\n return this.get<Page<LocalSource>>(\"/v1/local/sources\", p);\n }\n\n /** The local vocabulary — types, categories, place categories, sources. */\n localTaxonomy(): Promise<{\n types: Array<{ id: string; name: string; count: number }>;\n categories: Array<{ id: string; name: string; count: number }>;\n place_categories: Array<{ id: string; name: string; count: number }>;\n sources: Array<{ slug: string; name: string; count: number }>;\n }> {\n return this.get(\"/v1/local/taxonomy\");\n }\n\n // -- schools ----------------------------------------------------------------\n /** The school directory. */\n schools(\n p: {\n q?: string;\n board?: string;\n city?: string;\n province?: string;\n type?: string;\n bbox?: string;\n lat?: number;\n lng?: number;\n radius_km?: number;\n has_boundary?: boolean;\n limit?: number;\n offset?: number;\n } & Params = {},\n ): Promise<Page<SchoolSummary>> {\n return this.get<Page<SchoolSummary>>(\"/v1/schools\", p);\n }\n\n /** The board registry — the vocabulary the `board` filter uses. */\n schoolBoards(): Promise<Page<SchoolBoard>> {\n return this.get<Page<SchoolBoard>>(\"/v1/schools/boards\");\n }\n\n /** The school vocabulary and the headline counts. */\n schoolTaxonomy(): Promise<SchoolTaxonomy> {\n return this.get<SchoolTaxonomy>(\"/v1/schools/taxonomy\");\n }\n\n /** The catchments that cover a point.\n *\n * **Licensed.** This reads the catchment polygons, so it needs the\n * `school_licensed` scope — a key without it gets a 403.\n */\n schoolsAt(\n p: { lat: number; lng: number; limit?: number } & Params,\n ): Promise<Page<CatchmentHit>> {\n return this.get<Page<CatchmentHit>>(\"/v1/schools/at\", p);\n }\n\n /** One school.\n *\n * The uid is board-qualified — `ycdsb/0158`, or\n * `ycdsb/st-theresa-of-lisieux-chs` when the board publishes no code.\n * It carries a slash, and the API's route is built for that.\n *\n * The scores come back only with the `school_licensed` scope.\n */\n school(uid: string): Promise<SchoolDetail> {\n return this.get<SchoolDetail>(`/v1/schools/${uid}`);\n }\n\n /** A school's catchment outline, as GeoJSON. **Licensed.**\n * `simplify` is in METRES. */\n schoolBoundary(\n uid: string,\n p: { simplify?: number } & Params = {},\n ): Promise<SchoolBoundary> {\n return this.get<SchoolBoundary>(`/v1/schools/${uid}/boundary`, p);\n }\n\n /** One year's assessment snapshot, with the EQAO marks. **Licensed.**\n * `year` picks a year; the latest is the default. */\n schoolScores(\n uid: string,\n p: { year?: number } & Params = {},\n ): Promise<SchoolScores> {\n return this.get<SchoolScores>(`/v1/schools/${uid}/scores`, p);\n }\n}\n\nexport default Whereq;\n"]}