@kite-sa/sdk 0.7.0 → 0.9.2

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/dist/generated.js CHANGED
@@ -2,6 +2,14 @@
2
2
  export function createEndpoints(request) {
3
3
  return {
4
4
  analytics: {
5
+ /**
6
+ * List advertisers by matching listings. The advertisers behind the listings a
7
+ * search matches: one row per advertiser, with how many matching listings they
8
+ * hold, their price range and where they list.
9
+ */
10
+ advertisers: (params) => request("GET", "/advertisers", {
11
+ query: params,
12
+ }),
5
13
  /**
6
14
  * Find below-market listings. Residential listings asking noticeably less than
7
15
  * similar listings nearby, biggest gap first.
@@ -84,6 +92,11 @@ export function createEndpoints(request) {
84
92
  listings: {
85
93
  /** Get listings by id. Up to 100 listings in one call, in the order requested. */
86
94
  batch: (params) => request("GET", "/listings/batch", { query: params }),
95
+ /**
96
+ * Get a listing's advertiser contact. The advertiser's phone number for one
97
+ * active listing.
98
+ */
99
+ contact: (id) => request("GET", `/listings/${encodeURIComponent(String(id))}/contact`),
87
100
  /** Count listings. How many listings match the same filters as search. */
88
101
  count: (params) => request("GET", "/listings/count", { query: params }),
89
102
  /** Get a listing. One active listing. */
@@ -100,6 +113,24 @@ export function createEndpoints(request) {
100
113
  search: (params) => request("GET", "/listings", { query: params }),
101
114
  },
102
115
  market: {
116
+ /**
117
+ * Project absorption by area, developer or type. Month-by-month absorption
118
+ * pooled over projects: per city (the default), neighborhood, developer,
119
+ * property type or project type, the units on offer at the start and end of each
120
+ * month, units gone, released and re-added, the pooled and median absorption
121
+ * rate, and months of stock at the month's pace.
122
+ */
123
+ absorption: (params) => request("GET", "/market/absorption", {
124
+ query: (params ?? {}),
125
+ }),
126
+ /**
127
+ * Places, population and landmarks around a point or in a neighborhood. What is
128
+ * around a location: mapped places by category, the resident population and how
129
+ * it changed over five years, and the nearest landmarks.
130
+ */
131
+ areaContext: (params) => request("GET", "/market/area-context", {
132
+ query: (params ?? {}),
133
+ }),
103
134
  /**
104
135
  * Area distribution. Histogram and percentiles of floor/plot area (m²) over
105
136
  * listings in the sample that state an area (`without_area_count` did not).
@@ -107,6 +138,14 @@ export function createEndpoints(request) {
107
138
  areaDistribution: (params) => request("GET", "/market/area-distribution", {
108
139
  query: params,
109
140
  }),
141
+ /**
142
+ * Registered sale price against the asking price. What plots advertised for sale
143
+ * went on to register at, as a share of what their ads were asking: a
144
+ * negotiation margin to set bids by.
145
+ */
146
+ askToDeal: (params) => request("GET", "/market/ask-to-deal", {
147
+ query: params,
148
+ }),
110
149
  /**
111
150
  * Commercial rent per m² by neighborhood. Asking rent per m² of commercial space
112
151
  * (shops, offices, warehouses, commercial land and whole buildings) by
@@ -125,6 +164,13 @@ export function createEndpoints(request) {
125
164
  landPrices: (params) => request("GET", "/market/land-prices", {
126
165
  query: params,
127
166
  }),
167
+ /**
168
+ * Plots for sale against their last registered sale. How the plots on the market
169
+ * compare with what they last sold for.
170
+ */
171
+ landResale: (params) => request("GET", "/market/land-resale", {
172
+ query: params,
173
+ }),
128
174
  /**
129
175
  * Prices by neighborhood. Median and quartile price per neighborhood in a city,
130
176
  * most expensive first.
@@ -274,6 +320,11 @@ export function createEndpoints(request) {
274
320
  * the response.
275
321
  */
276
322
  rotateSecret: (webhookId, body, headers) => request("POST", `/organization/webhooks/${encodeURIComponent(String(webhookId))}/rotate-secret`, { body, headers: headers }),
323
+ /**
324
+ * Send a test event. Sends one event of `event_type` (default
325
+ * `listing.created`) to the endpoint now and returns what it answered.
326
+ */
327
+ test: (webhookId, body, headers) => request("POST", `/organization/webhooks/${encodeURIComponent(String(webhookId))}/test`, { body, headers: headers }),
277
328
  /**
278
329
  * Update a webhook endpoint. Changes the URL, event types, filters or
279
330
  * description of an endpoint; send only what changes.
@@ -282,6 +333,13 @@ export function createEndpoints(request) {
282
333
  },
283
334
  },
284
335
  projects: {
336
+ /**
337
+ * Get a project's absorption by month. How fast a project's offered units go,
338
+ * per calendar month: units on offer at the start and end, units gone, units
339
+ * re-added and released, the absorption rate (units gone ÷ units at the start),
340
+ * and months of stock left at that pace.
341
+ */
342
+ absorption: (id, params) => request("GET", `/projects/${encodeURIComponent(String(id))}/absorption`, { query: (params ?? {}) }),
285
343
  /**
286
344
  * Get a project's unit availability over time. Daily snapshots of a project's
287
345
  * unit count and the availability its source reports, as daily, weekly or
@@ -353,13 +411,22 @@ export function createEndpoints(request) {
353
411
  },
354
412
  transactions: {
355
413
  /**
356
- * Search registered deals. Individual sale deals registered with the Ministry of
357
- * Justice, from its quarterly open data, in one city: month, neighborhood,
358
- * land-use class, area, price and price per m².
414
+ * Search registered deals. Individual registered sale deals in one city: month,
415
+ * neighborhood, land-use class, area, price and price per m².
359
416
  */
360
417
  search: (params) => request("GET", "/transactions", {
361
418
  query: params,
362
419
  }),
363
420
  },
421
+ valuations: {
422
+ /**
423
+ * Check the asking price for any home. The asking-price range for a home you
424
+ * describe, from the asking prices of similar homes nearby: like an appraiser's
425
+ * comparables, but for any unit, not just one listed on Kite.
426
+ */
427
+ askingRange: (params) => request("GET", "/valuations/asking-range", {
428
+ query: params,
429
+ }),
430
+ },
364
431
  };
365
432
  }
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { type Endpoints } from "./generated.js";
2
2
  import type { operations } from "./openapi.js";
3
- import { type Page } from "./paginate.js";
3
+ import { type CursorPage } from "./paginate.js";
4
4
  export type { operations } from "./openapi.js";
5
5
  export type { Endpoints } from "./generated.js";
6
- export { paginate, type Page } from "./paginate.js";
6
+ export { paginate, type Page, type CursorPage } from "./paginate.js";
7
7
  type Op = keyof operations;
8
8
  type QueryOf<K extends Op> = operations[K]["parameters"] extends {
9
9
  query?: infer Q;
@@ -49,7 +49,7 @@ export interface KiteOptions {
49
49
  }
50
50
  type Query = Record<string, string | number | boolean | readonly (string | number)[] | undefined>;
51
51
  /** Kept in step with package.json by src/index.test.ts. */
52
- export declare const VERSION = "0.7.0";
52
+ export declare const VERSION = "0.9.2";
53
53
  /** Arrays go comma-separated, as the API expects; unset values are dropped. */
54
54
  export declare function toSearchParams(query?: Query): string;
55
55
  /**
@@ -82,9 +82,9 @@ export declare class Kite {
82
82
  * Path arguments go in the closure: `(p) => kite.projects.units(42, p)`.
83
83
  * Stops at the end of the results or at your plan's paging depth.
84
84
  */
85
- paginate<P extends {
85
+ paginate<const P extends object, T>(fetchPage: (params: P & {
86
86
  cursor?: string;
87
- }, T>(fetchPage: (params: P) => Promise<Page<T>>, params: Omit<P, "cursor">): AsyncGenerator<T>;
87
+ }) => Promise<CursorPage<T>>, params: P): AsyncGenerator<T>;
88
88
  /**
89
89
  * Low-level call for any endpoint; prefer the typed helpers below.
90
90
  *
package/dist/index.js CHANGED
@@ -24,7 +24,7 @@ export class KiteError extends Error {
24
24
  }
25
25
  }
26
26
  /** Kept in step with package.json by src/index.test.ts. */
27
- export const VERSION = "0.7.0";
27
+ export const VERSION = "0.9.2";
28
28
  const USER_AGENT = `kite-sa-js/${VERSION}`;
29
29
  /** Longest Retry-After worth waiting for; anything longer (a monthly quota) throws. */
30
30
  const MAX_RETRY_WAIT_S = 60;
@@ -114,16 +114,18 @@ export class Kite {
114
114
  body: options.body === undefined ? undefined : JSON.stringify(options.body),
115
115
  signal: AbortSignal.timeout(this.timeoutMs),
116
116
  });
117
+ if (res.ok) {
118
+ const body = await res.text();
119
+ return JSON.parse(body);
120
+ }
117
121
  }
118
122
  catch (err) {
119
- if (attempt < this.maxRetries) {
123
+ if (!(err instanceof SyntaxError) && attempt < this.maxRetries) {
120
124
  await sleep(backoff(attempt));
121
125
  continue;
122
126
  }
123
127
  throw err;
124
128
  }
125
- if (res.ok)
126
- return (await res.json());
127
129
  const error = await toError(res);
128
130
  const retryable = res.status === 429 || res.status >= 500;
129
131
  const wait = error.retryAfter ?? backoff(attempt) / 1000;
@@ -161,10 +163,15 @@ function backoff(attempt) {
161
163
  return Math.min(8000, 500 * 2 ** attempt) * (0.75 + Math.random() * 0.5);
162
164
  }
163
165
  async function toError(res) {
164
- const retryAfter = Number(res.headers.get("retry-after"));
166
+ const header = res.headers.get("retry-after")?.trim() ?? "";
167
+ const retryAfter = /^\d+(?:\.\d+)?$/.test(header)
168
+ ? Number(header)
169
+ : /[a-z]/i.test(header)
170
+ ? Math.max(0, (Date.parse(header.endsWith("GMT") ? header : header + " GMT") - Date.now()) / 1000)
171
+ : NaN;
165
172
  const requestId = res.headers.get("x-request-id");
166
173
  const body = (await res.json().catch(() => null));
167
174
  const e = body?.error;
168
- return new KiteError(res.status, e?.type ?? "api_error", e?.code ?? `http_${res.status}`, e?.message ?? `The API returned HTTP ${res.status}.`, e?.request_id ?? requestId, e?.param ?? null, Number.isFinite(retryAfter) && res.headers.has("retry-after") ? retryAfter : null);
175
+ return new KiteError(res.status, e?.type ?? "api_error", e?.code ?? `http_${res.status}`, e?.message ?? `The API returned HTTP ${res.status}.`, e?.request_id ?? requestId, e?.param ?? null, Number.isFinite(retryAfter) ? retryAfter : null);
169
176
  }
170
177
  export default Kite;