@kite-sa/sdk 0.5.0 → 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.
@@ -124,6 +124,20 @@ export async function referenceLimits(config) {
124
124
  const res = await _request("GET", "/limits", {}, config);
125
125
  return res.json();
126
126
  }
127
+ /**
128
+ * @throws {ApiError<400, Error>}
129
+ * @throws {ApiError<401, Error>}
130
+ * @throws {ApiError<403, Error>}
131
+ * @throws {ApiError<429, Error>}
132
+ * @throws {ApiError<500, Error>}
133
+ */
134
+ export async function referenceCoverage(params, config) {
135
+ const searchParams = new URLSearchParams();
136
+ if (params?.city != null)
137
+ searchParams.set("city", String(params.city));
138
+ const res = await _request("GET", "/coverage", { searchParams }, config);
139
+ return res.json();
140
+ }
127
141
  /**
128
142
  * @throws {ApiError<400, Error>}
129
143
  * @throws {ApiError<401, Error>}
@@ -193,6 +207,10 @@ export async function listingsSearch(params, config) {
193
207
  for (const v of params.amenitiesExclude)
194
208
  searchParams.append("amenities_exclude", String(v));
195
209
  }
210
+ if (params?.photoFeatures != null) {
211
+ for (const v of params.photoFeatures)
212
+ searchParams.append("photo_features", String(v));
213
+ }
196
214
  if (params?.floor != null)
197
215
  searchParams.set("floor", String(params.floor));
198
216
  if (params?.sourceExclude != null) {
@@ -293,6 +311,10 @@ export async function listingsCount(params, config) {
293
311
  for (const v of params.amenitiesExclude)
294
312
  searchParams.append("amenities_exclude", String(v));
295
313
  }
314
+ if (params?.photoFeatures != null) {
315
+ for (const v of params.photoFeatures)
316
+ searchParams.append("photo_features", String(v));
317
+ }
296
318
  if (params?.floor != null)
297
319
  searchParams.set("floor", String(params.floor));
298
320
  if (params?.sourceExclude != null) {
@@ -516,6 +538,34 @@ export async function marketNeighborhoods(params, config) {
516
538
  const res = await _request("GET", "/market/neighborhoods", { searchParams }, config);
517
539
  return res.json();
518
540
  }
541
+ /**
542
+ * @throws {ApiError<400, Error>}
543
+ * @throws {ApiError<401, Error>}
544
+ * @throws {ApiError<403, Error>}
545
+ * @throws {ApiError<429, Error>}
546
+ * @throws {ApiError<500, Error>}
547
+ */
548
+ export async function marketCommercialRents(params, config) {
549
+ const searchParams = new URLSearchParams();
550
+ if (params?.city != null)
551
+ searchParams.set("city", String(params.city));
552
+ if (params?.propertyType != null) {
553
+ for (const v of params.propertyType)
554
+ searchParams.append("property_type", String(v));
555
+ }
556
+ if (params?.neighborhoodId != null) {
557
+ for (const v of params.neighborhoodId)
558
+ searchParams.append("neighborhood_id", String(v));
559
+ }
560
+ if (params?.areaMin != null)
561
+ searchParams.set("area_min", String(params.areaMin));
562
+ if (params?.areaMax != null)
563
+ searchParams.set("area_max", String(params.areaMax));
564
+ if (params?.minSampleSize != null)
565
+ searchParams.set("min_sample_size", String(params.minSampleSize));
566
+ const res = await _request("GET", "/market/commercial-rents", { searchParams }, config);
567
+ return res.json();
568
+ }
519
569
  /**
520
570
  * @throws {ApiError<400, Error>}
521
571
  * @throws {ApiError<401, Error>}
@@ -608,6 +658,39 @@ export async function analyticsListingPriceBand(id, config) {
608
658
  * @throws {ApiError<429, Error>}
609
659
  * @throws {ApiError<500, Error>}
610
660
  */
661
+ export async function analyticsBelowMarket(params, config) {
662
+ const searchParams = new URLSearchParams();
663
+ if (params?.city != null)
664
+ searchParams.set("city", String(params.city));
665
+ if (params?.listingType != null)
666
+ searchParams.set("listing_type", String(params.listingType));
667
+ if (params?.propertyType != null)
668
+ searchParams.set("property_type", String(params.propertyType));
669
+ if (params?.beds != null)
670
+ searchParams.set("beds", String(params.beds));
671
+ if (params?.neighborhoodId != null) {
672
+ for (const v of params.neighborhoodId)
673
+ searchParams.append("neighborhood_id", String(v));
674
+ }
675
+ if (params?.minDiscountPct != null)
676
+ searchParams.set("min_discount_pct", String(params.minDiscountPct));
677
+ if (params?.maxDiscountPct != null)
678
+ searchParams.set("max_discount_pct", String(params.maxDiscountPct));
679
+ if (params?.limit != null)
680
+ searchParams.set("limit", String(params.limit));
681
+ if (params?.cursor != null)
682
+ searchParams.set("cursor", String(params.cursor));
683
+ const res = await _request("GET", "/market/below-market", { searchParams }, config);
684
+ return res.json();
685
+ }
686
+ /**
687
+ * @deprecated
688
+ * @throws {ApiError<400, Error>}
689
+ * @throws {ApiError<401, Error>}
690
+ * @throws {ApiError<403, Error>}
691
+ * @throws {ApiError<429, Error>}
692
+ * @throws {ApiError<500, Error>}
693
+ */
611
694
  export async function analyticsDeals(params, config) {
612
695
  const searchParams = new URLSearchParams();
613
696
  if (params?.city != null)
@@ -802,6 +885,8 @@ export async function marketLandPrices(params, config) {
802
885
  for (const v of params.neighborhoodId)
803
886
  searchParams.append("neighborhood_id", String(v));
804
887
  }
888
+ if (params?.groupBy != null)
889
+ searchParams.set("group_by", String(params.groupBy));
805
890
  if (params?.landUse != null)
806
891
  searchParams.set("land_use", String(params.landUse));
807
892
  if (params?.quarterFrom != null)
@@ -916,6 +1001,27 @@ export async function projectsUnits(id, params, config) {
916
1001
  const res = await _request("GET", `/projects/${encodeURIComponent(id)}/units`, { searchParams }, config);
917
1002
  return res.json();
918
1003
  }
1004
+ /**
1005
+ * @throws {ApiError<400, Error>}
1006
+ * @throws {ApiError<401, Error>}
1007
+ * @throws {ApiError<403, Error>}
1008
+ * @throws {ApiError<404, Error>}
1009
+ * @throws {ApiError<429, Error>}
1010
+ * @throws {ApiError<500, Error>}
1011
+ */
1012
+ export async function projectsAvailability(id, params, config) {
1013
+ const searchParams = new URLSearchParams();
1014
+ if (params?.interval != null)
1015
+ searchParams.set("interval", String(params.interval));
1016
+ if (params?.from != null)
1017
+ searchParams.set("from", String(params.from));
1018
+ if (params?.to != null)
1019
+ searchParams.set("to", String(params.to));
1020
+ if (params?.unitType != null)
1021
+ searchParams.set("unit_type", String(params.unitType));
1022
+ const res = await _request("GET", `/projects/${encodeURIComponent(id)}/availability`, { searchParams }, config);
1023
+ return res.json();
1024
+ }
919
1025
  /**
920
1026
  * @throws {ApiError<400, Error>}
921
1027
  * @throws {ApiError<401, Error>}
@@ -1198,6 +1304,54 @@ export async function organizationWebhooksCreate(body, params, config) {
1198
1304
  const res = await _request("POST", "/organization/webhooks", { body, extraHeaders }, config);
1199
1305
  return res.json();
1200
1306
  }
1307
+ /**
1308
+ * @throws {ApiError<400, Error>}
1309
+ * @throws {ApiError<401, Error>}
1310
+ * @throws {ApiError<403, Error>}
1311
+ * @throws {ApiError<404, Error>}
1312
+ * @throws {ApiError<409, Error>}
1313
+ * @throws {ApiError<429, Error>}
1314
+ * @throws {ApiError<500, Error>}
1315
+ */
1316
+ export async function organizationWebhooksUpdate(webhookId, body, params, config) {
1317
+ const extraHeaders = {
1318
+ ...(params?.idempotencyKey != null ? { "Idempotency-Key": String(params.idempotencyKey) } : {}),
1319
+ };
1320
+ const res = await _request("POST", `/organization/webhooks/${encodeURIComponent(webhookId)}/update`, { body, extraHeaders }, config);
1321
+ return res.json();
1322
+ }
1323
+ /**
1324
+ * @throws {ApiError<400, Error>}
1325
+ * @throws {ApiError<401, Error>}
1326
+ * @throws {ApiError<403, Error>}
1327
+ * @throws {ApiError<404, Error>}
1328
+ * @throws {ApiError<409, Error>}
1329
+ * @throws {ApiError<429, Error>}
1330
+ * @throws {ApiError<500, Error>}
1331
+ */
1332
+ export async function organizationWebhooksEnable(webhookId, params, config) {
1333
+ const extraHeaders = {
1334
+ ...(params?.idempotencyKey != null ? { "Idempotency-Key": String(params.idempotencyKey) } : {}),
1335
+ };
1336
+ const res = await _request("POST", `/organization/webhooks/${encodeURIComponent(webhookId)}/enable`, { extraHeaders }, config);
1337
+ return res.json();
1338
+ }
1339
+ /**
1340
+ * @throws {ApiError<400, Error>}
1341
+ * @throws {ApiError<401, Error>}
1342
+ * @throws {ApiError<403, Error>}
1343
+ * @throws {ApiError<404, Error>}
1344
+ * @throws {ApiError<409, Error>}
1345
+ * @throws {ApiError<429, Error>}
1346
+ * @throws {ApiError<500, Error>}
1347
+ */
1348
+ export async function organizationWebhooksRotateSecret(webhookId, body, params, config) {
1349
+ const extraHeaders = {
1350
+ ...(params?.idempotencyKey != null ? { "Idempotency-Key": String(params.idempotencyKey) } : {}),
1351
+ };
1352
+ const res = await _request("POST", `/organization/webhooks/${encodeURIComponent(webhookId)}/rotate-secret`, { body, extraHeaders }, config);
1353
+ return res.json();
1354
+ }
1201
1355
  /**
1202
1356
  * @throws {ApiError<400, Error>}
1203
1357
  * @throws {ApiError<401, Error>}
@@ -1226,6 +1380,8 @@ export async function organizationWebhooksDeliveries(webhookId, params, config)
1226
1380
  const searchParams = new URLSearchParams();
1227
1381
  if (params?.limit != null)
1228
1382
  searchParams.set("limit", String(params.limit));
1383
+ if (params?.cursor != null)
1384
+ searchParams.set("cursor", String(params.cursor));
1229
1385
  const res = await _request("GET", `/organization/webhooks/${encodeURIComponent(webhookId)}/deliveries`, { searchParams }, config);
1230
1386
  return res.json();
1231
1387
  }
@@ -86,6 +86,8 @@ export interface Listing {
86
86
  };
87
87
  previous_yearly_sar: number | null;
88
88
  changed_at: string | null;
89
+ price_basis: "yearly_rent" | "sale_price";
90
+ price_source: "asking" | "registered";
89
91
  };
90
92
  financing: {
91
93
  rent_now_pay_later_monthly_sar: number | null;
@@ -104,6 +106,10 @@ export interface Listing {
104
106
  age_years: number | null;
105
107
  furnished: boolean | null;
106
108
  amenities: string[];
109
+ photo_features: {
110
+ feature: "real_photos" | "kitchen_installed" | "ac_split" | "pool" | "roof_terrace" | "balcony" | "large_windows";
111
+ image_index: number | null;
112
+ }[] | null;
107
113
  location: {
108
114
  city: string | null;
109
115
  city_name_en: string | null;
package/dist/openapi.d.ts CHANGED
@@ -56,9 +56,21 @@ export interface operations {
56
56
  };
57
57
  };
58
58
  };
59
+ "reference.coverage": {
60
+ parameters: {
61
+ query?: Pick<SnakeKeys<NonNullable<Parameters<typeof import("./openapi-zod/client.js").referenceCoverage>[0]>>, "city">;
62
+ };
63
+ responses: {
64
+ 200: {
65
+ content: {
66
+ "application/json": Awaited<ReturnType<typeof import("./openapi-zod/client.js").referenceCoverage>>;
67
+ };
68
+ };
69
+ };
70
+ };
59
71
  "listings.search": {
60
72
  parameters: {
61
- query?: Pick<SnakeKeys<NonNullable<Parameters<typeof import("./openapi-zod/client.js").listingsSearch>[0]>>, "city" | "listing_type" | "listing_category" | "property_type" | "neighborhood_id" | "beds" | "beds_min" | "beds_max" | "bathrooms_min" | "price_min" | "price_max" | "area_min" | "area_max" | "furnished" | "source" | "bbox" | "updated_since" | "bathrooms" | "bathrooms_max" | "livings_min" | "neighborhood_id_exclude" | "q" | "amenities" | "amenities_exclude" | "floor" | "source_exclude" | "max_age" | "verified" | "advertiser_type" | "compound" | "in_compound" | "rent_frequency" | "days_on_market_min" | "days_on_market_max" | "sort" | "limit" | "cursor">;
73
+ query?: Pick<SnakeKeys<NonNullable<Parameters<typeof import("./openapi-zod/client.js").listingsSearch>[0]>>, "city" | "listing_type" | "listing_category" | "property_type" | "neighborhood_id" | "beds" | "beds_min" | "beds_max" | "bathrooms_min" | "price_min" | "price_max" | "area_min" | "area_max" | "furnished" | "source" | "bbox" | "updated_since" | "bathrooms" | "bathrooms_max" | "livings_min" | "neighborhood_id_exclude" | "q" | "amenities" | "amenities_exclude" | "photo_features" | "floor" | "source_exclude" | "max_age" | "verified" | "advertiser_type" | "compound" | "in_compound" | "rent_frequency" | "days_on_market_min" | "days_on_market_max" | "sort" | "limit" | "cursor">;
62
74
  };
63
75
  responses: {
64
76
  200: {
@@ -70,7 +82,7 @@ export interface operations {
70
82
  };
71
83
  "listings.count": {
72
84
  parameters: {
73
- query?: Pick<SnakeKeys<NonNullable<Parameters<typeof import("./openapi-zod/client.js").listingsCount>[0]>>, "city" | "listing_type" | "listing_category" | "property_type" | "neighborhood_id" | "beds" | "beds_min" | "beds_max" | "bathrooms_min" | "price_min" | "price_max" | "area_min" | "area_max" | "furnished" | "source" | "bbox" | "updated_since" | "bathrooms" | "bathrooms_max" | "livings_min" | "neighborhood_id_exclude" | "q" | "amenities" | "amenities_exclude" | "floor" | "source_exclude" | "max_age" | "verified" | "advertiser_type" | "compound" | "in_compound" | "rent_frequency" | "days_on_market_min" | "days_on_market_max">;
85
+ query?: Pick<SnakeKeys<NonNullable<Parameters<typeof import("./openapi-zod/client.js").listingsCount>[0]>>, "city" | "listing_type" | "listing_category" | "property_type" | "neighborhood_id" | "beds" | "beds_min" | "beds_max" | "bathrooms_min" | "price_min" | "price_max" | "area_min" | "area_max" | "furnished" | "source" | "bbox" | "updated_since" | "bathrooms" | "bathrooms_max" | "livings_min" | "neighborhood_id_exclude" | "q" | "amenities" | "amenities_exclude" | "photo_features" | "floor" | "source_exclude" | "max_age" | "verified" | "advertiser_type" | "compound" | "in_compound" | "rent_frequency" | "days_on_market_min" | "days_on_market_max">;
74
86
  };
75
87
  responses: {
76
88
  200: {
@@ -184,6 +196,18 @@ export interface operations {
184
196
  };
185
197
  };
186
198
  };
199
+ "market.commercial_rents": {
200
+ parameters: {
201
+ query?: Pick<SnakeKeys<NonNullable<Parameters<typeof import("./openapi-zod/client.js").marketCommercialRents>[0]>>, "city" | "property_type" | "neighborhood_id" | "area_min" | "area_max" | "min_sample_size">;
202
+ };
203
+ responses: {
204
+ 200: {
205
+ content: {
206
+ "application/json": Awaited<ReturnType<typeof import("./openapi-zod/client.js").marketCommercialRents>>;
207
+ };
208
+ };
209
+ };
210
+ };
187
211
  "official.registered_rents": {
188
212
  parameters: {
189
213
  query?: Pick<SnakeKeys<NonNullable<Parameters<typeof import("./openapi-zod/client.js").officialRegisteredRents>[0]>>, "city" | "neighborhood_id" | "property_type" | "period" | "min_sample_size">;
@@ -240,6 +264,18 @@ export interface operations {
240
264
  };
241
265
  };
242
266
  };
267
+ "analytics.below_market": {
268
+ parameters: {
269
+ query?: Pick<SnakeKeys<NonNullable<Parameters<typeof import("./openapi-zod/client.js").analyticsBelowMarket>[0]>>, "city" | "listing_type" | "property_type" | "beds" | "neighborhood_id" | "min_discount_pct" | "max_discount_pct" | "limit" | "cursor">;
270
+ };
271
+ responses: {
272
+ 200: {
273
+ content: {
274
+ "application/json": Awaited<ReturnType<typeof import("./openapi-zod/client.js").analyticsBelowMarket>>;
275
+ };
276
+ };
277
+ };
278
+ };
243
279
  "analytics.deals": {
244
280
  parameters: {
245
281
  query?: Pick<SnakeKeys<NonNullable<Parameters<typeof import("./openapi-zod/client.js").analyticsDeals>[0]>>, "city" | "listing_type" | "property_type" | "beds" | "neighborhood_id" | "min_discount_pct" | "max_discount_pct" | "limit" | "cursor">;
@@ -314,7 +350,7 @@ export interface operations {
314
350
  };
315
351
  "market.land_prices": {
316
352
  parameters: {
317
- query?: Pick<SnakeKeys<NonNullable<Parameters<typeof import("./openapi-zod/client.js").marketLandPrices>[0]>>, "city" | "neighborhood_id" | "land_use" | "quarter_from" | "quarter_to" | "min_sample_size">;
353
+ query?: Pick<SnakeKeys<NonNullable<Parameters<typeof import("./openapi-zod/client.js").marketLandPrices>[0]>>, "city" | "neighborhood_id" | "group_by" | "land_use" | "quarter_from" | "quarter_to" | "min_sample_size">;
318
354
  };
319
355
  responses: {
320
356
  200: {
@@ -358,6 +394,18 @@ export interface operations {
358
394
  };
359
395
  };
360
396
  };
397
+ "projects.availability": {
398
+ parameters: {
399
+ query?: Pick<SnakeKeys<NonNullable<Parameters<typeof import("./openapi-zod/client.js").projectsAvailability>[1]>>, "interval" | "from" | "to" | "unit_type">;
400
+ };
401
+ responses: {
402
+ 200: {
403
+ content: {
404
+ "application/json": Awaited<ReturnType<typeof import("./openapi-zod/client.js").projectsAvailability>>;
405
+ };
406
+ };
407
+ };
408
+ };
361
409
  "projects.units_search": {
362
410
  parameters: {
363
411
  query?: Pick<SnakeKeys<NonNullable<Parameters<typeof import("./openapi-zod/client.js").projectsUnitsSearch>[0]>>, "city" | "neighborhood_id" | "developer" | "status" | "project_type" | "listing_category" | "features" | "banks" | "listing_type" | "property_type" | "bedrooms" | "bedrooms_min" | "bedrooms_max" | "bathrooms" | "bathrooms_min" | "price_min" | "price_max" | "area_min" | "area_max" | "sort" | "limit" | "cursor">;
@@ -553,6 +601,52 @@ export interface operations {
553
601
  };
554
602
  };
555
603
  };
604
+ "organization.webhooks.update": {
605
+ parameters: {
606
+ header?: Pick<HeaderKeys<NonNullable<Parameters<typeof import("./openapi-zod/client.js").organizationWebhooksUpdate>[2]>>, "Idempotency-Key">;
607
+ };
608
+ requestBody: {
609
+ content: {
610
+ "application/json": Parameters<typeof import("./openapi-zod/client.js").organizationWebhooksUpdate>[1];
611
+ };
612
+ };
613
+ responses: {
614
+ 200: {
615
+ content: {
616
+ "application/json": Awaited<ReturnType<typeof import("./openapi-zod/client.js").organizationWebhooksUpdate>>;
617
+ };
618
+ };
619
+ };
620
+ };
621
+ "organization.webhooks.enable": {
622
+ parameters: {
623
+ header?: Pick<HeaderKeys<NonNullable<Parameters<typeof import("./openapi-zod/client.js").organizationWebhooksEnable>[1]>>, "Idempotency-Key">;
624
+ };
625
+ responses: {
626
+ 200: {
627
+ content: {
628
+ "application/json": Awaited<ReturnType<typeof import("./openapi-zod/client.js").organizationWebhooksEnable>>;
629
+ };
630
+ };
631
+ };
632
+ };
633
+ "organization.webhooks.rotate_secret": {
634
+ parameters: {
635
+ header?: Pick<HeaderKeys<NonNullable<Parameters<typeof import("./openapi-zod/client.js").organizationWebhooksRotateSecret>[2]>>, "Idempotency-Key">;
636
+ };
637
+ requestBody: {
638
+ content: {
639
+ "application/json": Parameters<typeof import("./openapi-zod/client.js").organizationWebhooksRotateSecret>[1];
640
+ };
641
+ };
642
+ responses: {
643
+ 200: {
644
+ content: {
645
+ "application/json": Awaited<ReturnType<typeof import("./openapi-zod/client.js").organizationWebhooksRotateSecret>>;
646
+ };
647
+ };
648
+ };
649
+ };
556
650
  "organization.webhooks.delete": {
557
651
  parameters: {
558
652
  header?: Pick<HeaderKeys<NonNullable<Parameters<typeof import("./openapi-zod/client.js").organizationWebhooksDelete>[1]>>, "Idempotency-Key">;
@@ -567,7 +661,7 @@ export interface operations {
567
661
  };
568
662
  "organization.webhooks.deliveries": {
569
663
  parameters: {
570
- query?: Pick<SnakeKeys<NonNullable<Parameters<typeof import("./openapi-zod/client.js").organizationWebhooksDeliveries>[1]>>, "limit">;
664
+ query?: Pick<SnakeKeys<NonNullable<Parameters<typeof import("./openapi-zod/client.js").organizationWebhooksDeliveries>[1]>>, "limit" | "cursor">;
571
665
  };
572
666
  responses: {
573
667
  200: {
@@ -0,0 +1,18 @@
1
+ /** The shape every cursor-paginated list endpoint returns. */
2
+ export interface Page<T> {
3
+ data: T[];
4
+ pagination: {
5
+ has_more: boolean;
6
+ next_cursor?: string | null;
7
+ };
8
+ }
9
+ /**
10
+ * Yields every item of a cursor-paginated endpoint, fetching the next page only
11
+ * when the previous one is consumed. `fetchPage` receives `params` plus the
12
+ * cursor, so path arguments go in a closure:
13
+ *
14
+ * paginate((p) => kite.projects.units(42, p), { beds: 2 })
15
+ */
16
+ export declare function paginate<P extends {
17
+ cursor?: string;
18
+ }, T>(fetchPage: (params: P) => Promise<Page<T>>, params: Omit<P, "cursor">): AsyncGenerator<T>;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Yields every item of a cursor-paginated endpoint, fetching the next page only
3
+ * when the previous one is consumed. `fetchPage` receives `params` plus the
4
+ * cursor, so path arguments go in a closure:
5
+ *
6
+ * paginate((p) => kite.projects.units(42, p), { beds: 2 })
7
+ */
8
+ export async function* paginate(fetchPage, params) {
9
+ let cursor;
10
+ do {
11
+ const page = await fetchPage({ ...params, cursor });
12
+ yield* page.data;
13
+ cursor = page.pagination.has_more ? (page.pagination.next_cursor ?? undefined) : undefined;
14
+ } while (cursor);
15
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Header Kite signs each webhook delivery with. Deliveries also carry the
3
+ * deprecated `Darak-Signature` with the same value; either verifies.
4
+ */
5
+ export declare const SIGNATURE_HEADER = "Kite-Signature";
6
+ /** How old a signature may be before it is rejected, in seconds. */
7
+ export declare const TOLERANCE_SECONDS = 300;
8
+ export interface VerifyResult {
9
+ valid: boolean;
10
+ /** Why not, for your logs. Never send it back to the caller. */
11
+ reason?: "malformed" | "no_match" | "too_old";
12
+ }
13
+ export interface VerifyOptions {
14
+ /** Seconds a signature stays valid (default 300). */
15
+ toleranceSeconds?: number;
16
+ /** Current time in Unix seconds; for tests. */
17
+ now?: number;
18
+ }
19
+ /**
20
+ * Checks a `Kite-Signature` header (`t=<unix>,v1=<hex>`) against the raw
21
+ * request body: HMAC-SHA256 of `${t}.${body}` under your endpoint's signing
22
+ * secret, compared in constant time. Pass the body exactly as received, before
23
+ * any JSON parsing. `secret` may be an array so a rotation can overlap: the old
24
+ * secret keeps verifying until the deploy carrying the new one is through.
25
+ * During a rotation overlap the header has a `v1` entry per live secret; the
26
+ * signature is valid if any of them matches.
27
+ *
28
+ * Imported from `@kite-sa/sdk/webhooks` because it needs `node:crypto`; the
29
+ * main entry stays runtime-neutral.
30
+ */
31
+ export declare function verifyWebhookSignature(header: string | null | undefined, body: string, secret: string | readonly string[], options?: VerifyOptions): VerifyResult;
@@ -0,0 +1,49 @@
1
+ import { createHmac, timingSafeEqual } from "node:crypto";
2
+ /**
3
+ * Header Kite signs each webhook delivery with. Deliveries also carry the
4
+ * deprecated `Darak-Signature` with the same value; either verifies.
5
+ */
6
+ export const SIGNATURE_HEADER = "Kite-Signature";
7
+ /** How old a signature may be before it is rejected, in seconds. */
8
+ export const TOLERANCE_SECONDS = 300;
9
+ /**
10
+ * Checks a `Kite-Signature` header (`t=<unix>,v1=<hex>`) against the raw
11
+ * request body: HMAC-SHA256 of `${t}.${body}` under your endpoint's signing
12
+ * secret, compared in constant time. Pass the body exactly as received, before
13
+ * any JSON parsing. `secret` may be an array so a rotation can overlap: the old
14
+ * secret keeps verifying until the deploy carrying the new one is through.
15
+ * During a rotation overlap the header has a `v1` entry per live secret; the
16
+ * signature is valid if any of them matches.
17
+ *
18
+ * Imported from `@kite-sa/sdk/webhooks` because it needs `node:crypto`; the
19
+ * main entry stays runtime-neutral.
20
+ */
21
+ export function verifyWebhookSignature(header, body, secret, options = {}) {
22
+ if (!header)
23
+ return { valid: false, reason: "malformed" };
24
+ const pairs = header
25
+ .split(",")
26
+ .map((p) => p.trim().split("=", 2))
27
+ .filter((p) => p.length === 2);
28
+ const tText = pairs.find(([k]) => k === "t")?.[1];
29
+ const t = Number(tText);
30
+ // After a secret rotation the header carries one `v1` per live secret (new
31
+ // first) until the overlap ends; any of them may match.
32
+ const v1s = pairs.filter(([k, v]) => k === "v1" && v).map(([, v]) => v);
33
+ if (v1s.length === 0 || !tText || !Number.isFinite(t)) {
34
+ return { valid: false, reason: "malformed" };
35
+ }
36
+ // Age first and independently of the secret: a genuine but stale signature
37
+ // is a replay, not an authentication failure.
38
+ const now = options.now ?? Math.floor(Date.now() / 1000);
39
+ if (Math.abs(now - t) > (options.toleranceSeconds ?? TOLERANCE_SECONDS)) {
40
+ return { valid: false, reason: "too_old" };
41
+ }
42
+ const secrets = typeof secret === "string" ? [secret] : secret;
43
+ const given = v1s.map((v1) => Buffer.from(v1, "utf8"));
44
+ const matches = secrets.some((s) => {
45
+ const expected = Buffer.from(createHmac("sha256", s).update(`${t}.${body}`).digest("hex"));
46
+ return given.some((g) => expected.length === g.length && timingSafeEqual(expected, g));
47
+ });
48
+ return matches ? { valid: true } : { valid: false, reason: "no_match" };
49
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kite-sa/sdk",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "description": "Official JavaScript/TypeScript client for the Kite API: Saudi real-estate listings and market data.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -8,6 +8,10 @@
8
8
  ".": {
9
9
  "types": "./dist/index.d.ts",
10
10
  "import": "./dist/index.js"
11
+ },
12
+ "./webhooks": {
13
+ "types": "./dist/webhooks.d.ts",
14
+ "import": "./dist/webhooks.js"
11
15
  }
12
16
  },
13
17
  "files": [
@@ -26,7 +30,7 @@
26
30
  "directory": "packages/sdk-js"
27
31
  },
28
32
  "bugs": {
29
- "url": "https://github.com/basseko/kite/issues"
33
+ "email": "api@kite.sa"
30
34
  },
31
35
  "author": "Kite",
32
36
  "keywords": [