@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/CHANGELOG.md CHANGED
@@ -2,6 +2,45 @@
2
2
 
3
3
  Formerly `@darak-app/sdk`, which is deprecated. Versions before 0.5.0 were published under that name.
4
4
 
5
+ ## 0.9.2
6
+
7
+ - `parseWebhookEvent(header, body, secret)` from `@kite-sa/sdk/webhooks` verifies a delivery and returns its event typed by `type`; it throws `WebhookError` on a bad signature, a non-event body or an unknown type. `WebhookEvent`, `WebhookEventType`, `WEBHOOK_EVENT_TYPES` and the per-type event interfaces (`WebhookListingCreatedEvent`, …) are generated from the API's OpenAPI `webhooks` schemas. The README has a minimal receiver.
8
+ - The pagination helper now yields advertiser records when paging through `GET /advertisers`.
9
+
10
+ ## 0.9.1
11
+
12
+ - Honor HTTP dates in Retry-After responses, including the one-minute wait limit.
13
+
14
+ ## 0.9.0
15
+
16
+ - Resume listing syncs with the last `updated_at` and `updated_after_id` when multiple listings share a timestamp.
17
+ - Retry interrupted HTTP response bodies with the same POST idempotency key.
18
+
19
+ ## 0.8.0
20
+
21
+ - `kite.valuations.askingRange({...})` calls `GET /valuations/asking-range`: the asking-price
22
+ range for a home you describe (not a listing), with `status` `estimate`,
23
+ `range_only` or `insufficient_evidence`, a provisional `confidence` tier and
24
+ up to 15 comparables. 250 units a call; `market` scope (Starter and up).
25
+
26
+ - `kite.listings.contact(id)` calls `GET /listings/{id}/contact`: the
27
+ advertiser's phone and WhatsApp for one listing, or `available: false` with a
28
+ `reason`. Only to contact the advertiser about that listing. It needs the
29
+ `listings:contact` scope, which no plan includes (enabled per organization on
30
+ request, on any plan; never to test keys), and each organization gets
31
+ 200 numbers per day (Riyadh time) across its keys; past that the call fails
32
+ with 429 `contact_daily_cap_exceeded`.
33
+ - The `Listing` type's `advertiser` gains `name`, `name_en`, `company`, `logo`,
34
+ `fal_number`, `cr`, `ad_license` and `contact_available`. The identity fields
35
+ are null unless the ad carries a REGA licence. No listing carries a phone.
36
+
37
+ ## 0.7.1
38
+
39
+ - Docs only: the `furnished` listing filter now documents the API's new
40
+ behaviour. `furnished=false` matches every listing not confirmed furnished,
41
+ including those that don't state it; `furnished=true` is unchanged. Each
42
+ listing's `furnished` field is still `true`, `false` or `null` (unknown).
43
+
5
44
  ## 0.7.0
6
45
 
7
46
  - Writes are safe to retry. A POST without an `Idempotency-Key` now gets one,
package/README.md CHANGED
@@ -25,7 +25,7 @@ for await (const listing of kite.listings.searchAll({ city: "jeddah", listing_ty
25
25
  }
26
26
  ```
27
27
 
28
- Get a key at [platform.kite.sa](https://platform.kite.sa). Keys are secret: call the API from your servers, never from browsers.
28
+ Get a key at [platform.kite.sa](https://platform.kite.sa/?utm_source=npm&utm_medium=referral). Keys are secret: call the API from your servers, never from browsers.
29
29
 
30
30
  ## What you get
31
31
 
@@ -33,7 +33,7 @@ Get a key at [platform.kite.sa](https://platform.kite.sa). Keys are secret: call
33
33
  - Retries for `429` and `5xx` (and network errors) that honor `Retry-After`. A monthly-quota `429` isn't waited out; it throws.
34
34
  - Safe write retries: a POST is sent with an `Idempotency-Key`, generated for you unless you pass one (`kite.organization.keys.create(body, { "Idempotency-Key": myKey })`), and every retry reuses it, so a lost response never creates a second key, webhook or export.
35
35
  - `kite.paginate((p) => kite.transactions.search(p), { city: "riyadh" })` follows the cursor of any list endpoint (path arguments go in the closure: `(p) => kite.projects.units(42, p)`); `listings.searchAll` is the same for listings.
36
- - Webhook verification: `import { verifyWebhookSignature } from "@kite-sa/sdk/webhooks"` and call it with the `Kite-Signature` header, the raw body and your signing secret (or an array of secrets during a rotation). It checks the HMAC in constant time and rejects signatures older than five minutes. Node only (it uses `node:crypto`).
36
+ - Webhook verification and typed events from `@kite-sa/sdk/webhooks` (see [Receiving webhooks](#receiving-webhooks)). `verifyWebhookSignature` takes the `Kite-Signature` header, the raw body and your signing secret (or an array of secrets during a rotation), checks the HMAC in constant time and rejects signatures older than five minutes. Node only (it uses `node:crypto`).
37
37
  - `KiteError` with `status`, `code`, `message`, `param` and `requestId`. Branch on `code`; quote `requestId` to support.
38
38
 
39
39
  - Namespaces generated from the API's OpenAPI spec, so they track it exactly:
@@ -51,3 +51,42 @@ const projects = await kite.projects.search({ city: "riyadh" });
51
51
  0.1.x names for what is now `reference`.
52
52
 
53
53
  Options: `new Kite({ apiKey, baseUrl, maxRetries: 2, timeoutMs: 30000, fetch })`. Needs Node 18+ (or any runtime with `fetch`).
54
+
55
+ ## Receiving webhooks
56
+
57
+ `parseWebhookEvent` verifies a delivery and returns its event, typed by `type` (`WebhookEvent`, generated from the API's OpenAPI `webhooks` schemas). It throws `WebhookError` on a bad signature, a body that isn't an event, or an event type newer than this SDK. Pass the raw body, before any JSON parsing.
58
+
59
+ ```ts
60
+ import { parseWebhookEvent, WebhookError } from "@kite-sa/sdk/webhooks";
61
+
62
+ export async function POST(req: Request): Promise<Response> {
63
+ const body = await req.text(); // the raw body: the signature covers it byte for byte
64
+ let event;
65
+ try {
66
+ event = parseWebhookEvent(
67
+ req.headers.get("Kite-Signature"),
68
+ body,
69
+ process.env.KITE_WEBHOOK_SECRET!,
70
+ );
71
+ } catch (e) {
72
+ if (e instanceof WebhookError) return new Response(null, { status: 400 }); // log e.reason
73
+ throw e;
74
+ }
75
+ if (event.test) return new Response(null, { status: 204 }); // from "Send test event"
76
+ if (await alreadySeen(event.id)) return new Response(null, { status: 204 }); // = Kite-Event-Id
77
+ switch (event.type) {
78
+ case "listing.created":
79
+ await save(event.data);
80
+ break;
81
+ case "listing.price_changed":
82
+ await reprice(event.data.listing_id, event.data.price_yearly_sar);
83
+ break;
84
+ case "listing.delisted":
85
+ await remove(event.data.listing_id);
86
+ break;
87
+ }
88
+ return new Response(null, { status: 204 }); // any 2xx accepts; anything else is retried
89
+ }
90
+ ```
91
+
92
+ Deliveries are at least once, so deduplicate on `event.id` (the `Kite-Event-Id` header). Test events carry `test: true`.