@chronary/sdk 0.7.1 → 0.9.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/dist/index.cjs CHANGED
@@ -22,6 +22,7 @@ var index_exports = {};
22
22
  __export(index_exports, {
23
23
  APIPromise: () => APIPromise,
24
24
  AuthenticationError: () => AuthenticationError,
25
+ BillingClient: () => BillingClient,
25
26
  BookingPagesClient: () => BookingPagesClient,
26
27
  Chronary: () => Chronary,
27
28
  ChronaryError: () => ChronaryError,
@@ -30,9 +31,11 @@ __export(index_exports, {
30
31
  CoreClient: () => CoreClient,
31
32
  NotFoundError: () => NotFoundError,
32
33
  PageIterator: () => PageIterator,
34
+ PlanRequiredError: () => PlanRequiredError,
33
35
  QuotaExceededError: () => QuotaExceededError,
34
36
  RateLimitError: () => RateLimitError,
35
37
  TimeoutError: () => TimeoutError,
38
+ UpgradeRequestsClient: () => UpgradeRequestsClient,
36
39
  VERSION: () => VERSION,
37
40
  ValidationError: () => ValidationError,
38
41
  constructEvent: () => constructEvent,
@@ -43,33 +46,63 @@ __export(index_exports, {
43
46
  module.exports = __toCommonJS(index_exports);
44
47
 
45
48
  // src/version.ts
46
- var VERSION = "0.7.1";
49
+ var VERSION = "0.9.0";
47
50
 
48
51
  // src/error.ts
52
+ function str(body, key) {
53
+ const v = body?.[key];
54
+ return typeof v === "string" ? v : void 0;
55
+ }
56
+ function num(body, key) {
57
+ const v = body?.[key];
58
+ return typeof v === "number" ? v : void 0;
59
+ }
49
60
  var ChronaryError = class extends Error {
50
61
  status;
51
62
  requestId;
52
63
  headers;
53
64
  errorType;
54
- constructor(message, status, requestId, headers, errorType) {
65
+ /** Raw `error` object from the response body (all server-provided fields). */
66
+ body;
67
+ /** Where a human can upgrade the plan (plan_required / quota_exceeded errors). */
68
+ upgradeUrl;
69
+ docsUrl;
70
+ requiredPlan;
71
+ /** Self-serve plan `upgradeUrl` leads to: the next plan up (quota_exceeded and count-cap errors). */
72
+ upgradePlan;
73
+ feature;
74
+ contactUrl;
75
+ /** Quota metric that was exhausted (quota_exceeded errors). */
76
+ metric;
77
+ limit;
78
+ constructor(message, status, requestId, headers, errorType, body) {
55
79
  super(message);
56
80
  this.name = "ChronaryError";
57
81
  this.status = status;
58
82
  this.requestId = requestId;
59
83
  this.headers = headers;
60
84
  this.errorType = errorType;
85
+ this.body = body;
86
+ this.upgradeUrl = str(body, "upgrade_url");
87
+ this.docsUrl = str(body, "docs_url");
88
+ this.requiredPlan = str(body, "required_plan");
89
+ this.upgradePlan = str(body, "upgrade_plan");
90
+ this.feature = str(body, "feature");
91
+ this.contactUrl = str(body, "contact_url");
92
+ this.metric = str(body, "metric");
93
+ this.limit = num(body, "limit");
61
94
  }
62
95
  };
63
96
  var AuthenticationError = class extends ChronaryError {
64
- constructor(message, requestId, headers) {
65
- super(message, 401, requestId, headers, "authentication_error");
97
+ constructor(message, requestId, headers, body) {
98
+ super(message, 401, requestId, headers, "authentication_error", body);
66
99
  this.name = "AuthenticationError";
67
100
  }
68
101
  };
69
102
  var RateLimitError = class extends ChronaryError {
70
103
  retryAfter;
71
- constructor(message, requestId, headers) {
72
- super(message, 429, requestId, headers, "rate_limit_error");
104
+ constructor(message, requestId, headers, body) {
105
+ super(message, 429, requestId, headers, "rate_limit_error", body);
73
106
  this.name = "RateLimitError";
74
107
  if (headers) {
75
108
  const ra = headers.get("retry-after");
@@ -78,23 +111,29 @@ var RateLimitError = class extends ChronaryError {
78
111
  }
79
112
  };
80
113
  var NotFoundError = class extends ChronaryError {
81
- constructor(message, requestId, headers) {
82
- super(message, 404, requestId, headers, "not_found");
114
+ constructor(message, requestId, headers, body) {
115
+ super(message, 404, requestId, headers, "not_found", body);
83
116
  this.name = "NotFoundError";
84
117
  }
85
118
  };
86
119
  var ValidationError = class extends ChronaryError {
87
- constructor(message, status, requestId, headers) {
88
- super(message, status, requestId, headers, "validation_error");
120
+ constructor(message, status, requestId, headers, body) {
121
+ super(message, status, requestId, headers, "validation_error", body);
89
122
  this.name = "ValidationError";
90
123
  }
91
124
  };
92
125
  var QuotaExceededError = class extends ChronaryError {
93
- constructor(message, requestId, headers) {
94
- super(message, 402, requestId, headers, "quota_exceeded");
126
+ constructor(message, requestId, headers, body, status = 429) {
127
+ super(message, status, requestId, headers, "quota_exceeded", body);
95
128
  this.name = "QuotaExceededError";
96
129
  }
97
130
  };
131
+ var PlanRequiredError = class extends ChronaryError {
132
+ constructor(message, requestId, headers, body) {
133
+ super(message, 403, requestId, headers, "plan_required", body);
134
+ this.name = "PlanRequiredError";
135
+ }
136
+ };
98
137
  var TimeoutError = class extends ChronaryError {
99
138
  constructor(message) {
100
139
  super(message, 0);
@@ -195,7 +234,7 @@ var CoreClient = class {
195
234
  extraHeaders;
196
235
  constructor(config = {}) {
197
236
  this.apiKey = config.apiKey ?? getEnvVar("CHRONARY_API_KEY") ?? "";
198
- this.baseUrl = (config.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
237
+ this.baseUrl = stripTrailingSlashes(config.baseUrl ?? DEFAULT_BASE_URL);
199
238
  this.timeout = config.timeout ?? DEFAULT_TIMEOUT;
200
239
  this.maxRetries = config.maxRetries ?? DEFAULT_MAX_RETRIES;
201
240
  this.logLevel = resolveLogLevel(config);
@@ -291,11 +330,12 @@ var CoreClient = class {
291
330
  const data = await response.json();
292
331
  return { data, rawResponse };
293
332
  }
294
- if (RETRYABLE_STATUS_CODES.has(response.status) && attempt < this.maxRetries) {
295
- lastError = await this.buildError(response, requestId);
333
+ const error = await this.buildError(response, requestId);
334
+ if (RETRYABLE_STATUS_CODES.has(response.status) && attempt < this.maxRetries && !(error instanceof QuotaExceededError)) {
335
+ lastError = error;
296
336
  continue;
297
337
  }
298
- throw await this.buildError(response, requestId);
338
+ throw error;
299
339
  } catch (err) {
300
340
  clearTimeout(timeoutId);
301
341
  options?.signal?.removeEventListener("abort", abortFromCaller);
@@ -318,7 +358,12 @@ var CoreClient = class {
318
358
  if (!query) return base;
319
359
  const params = new URLSearchParams();
320
360
  for (const [key, value] of Object.entries(query)) {
321
- if (value !== void 0) params.set(key, String(value));
361
+ if (value === void 0) continue;
362
+ if (Array.isArray(value)) {
363
+ for (const v of value) params.append(key, v);
364
+ } else {
365
+ params.set(key, String(value));
366
+ }
322
367
  }
323
368
  const qs = params.toString();
324
369
  return qs ? `${base}?${qs}` : base;
@@ -332,28 +377,34 @@ var CoreClient = class {
332
377
  const message = errorBody?.error?.message ?? `HTTP ${response.status}`;
333
378
  const rid = requestId ?? errorBody?.error?.request_id;
334
379
  const errorType = errorBody?.error?.type;
380
+ const body = errorBody?.error;
335
381
  switch (response.status) {
336
382
  case 400:
337
383
  if (errorType === "validation_error") {
338
- return new ValidationError(message, response.status, rid, response.headers);
384
+ return new ValidationError(message, response.status, rid, response.headers, body);
339
385
  }
340
- return new ChronaryError(message, response.status, rid, response.headers, errorType);
386
+ return new ChronaryError(message, response.status, rid, response.headers, errorType, body);
341
387
  case 401:
342
- return new AuthenticationError(message, rid, response.headers);
388
+ return new AuthenticationError(message, rid, response.headers, body);
343
389
  case 402:
344
- return new QuotaExceededError(message, rid, response.headers);
390
+ return new QuotaExceededError(message, rid, response.headers, body, 402);
391
+ case 403:
392
+ if (errorType === "plan_required") {
393
+ return new PlanRequiredError(message, rid, response.headers, body);
394
+ }
395
+ return new ChronaryError(message, response.status, rid, response.headers, errorType, body);
345
396
  case 404:
346
- return new NotFoundError(message, rid, response.headers);
397
+ return new NotFoundError(message, rid, response.headers, body);
347
398
  case 422:
348
- return new ValidationError(message, response.status, rid, response.headers);
399
+ return new ValidationError(message, response.status, rid, response.headers, body);
349
400
  case 429: {
350
401
  if (errorType === "quota_exceeded") {
351
- return new QuotaExceededError(message, rid, response.headers);
402
+ return new QuotaExceededError(message, rid, response.headers, body, 429);
352
403
  }
353
- return new RateLimitError(message, rid, response.headers);
404
+ return new RateLimitError(message, rid, response.headers, body);
354
405
  }
355
406
  default:
356
- return new ChronaryError(message, response.status, rid, response.headers, errorType);
407
+ return new ChronaryError(message, response.status, rid, response.headers, errorType, body);
357
408
  }
358
409
  }
359
410
  retryDelay(attempt, lastError) {
@@ -386,11 +437,30 @@ function parseQuotaSnapshot(headers) {
386
437
  };
387
438
  }
388
439
  function parseStructuredParam(header, key) {
389
- const re = new RegExp(`(?:^|;)\\s*${key}=(-?\\d+)(?:;|$)`);
390
- const match = re.exec(header);
391
- if (!match) return void 0;
392
- const n = Number(match[1]);
393
- return Number.isFinite(n) ? n : void 0;
440
+ const prefix = `${key}=`;
441
+ for (const member of header.split(";")) {
442
+ const trimmed = member.trimStart();
443
+ if (!trimmed.startsWith(prefix)) continue;
444
+ const value = trimmed.slice(prefix.length);
445
+ if (!isSignedInteger(value)) continue;
446
+ const n = Number(value);
447
+ return Number.isFinite(n) ? n : void 0;
448
+ }
449
+ return void 0;
450
+ }
451
+ function isSignedInteger(value) {
452
+ const start = value.startsWith("-") ? 1 : 0;
453
+ if (value.length === start) return false;
454
+ for (let i = start; i < value.length; i++) {
455
+ const c = value.charCodeAt(i);
456
+ if (c < 48 || c > 57) return false;
457
+ }
458
+ return true;
459
+ }
460
+ function stripTrailingSlashes(url) {
461
+ let end = url.length;
462
+ while (end > 0 && url.charCodeAt(end - 1) === 47) end--;
463
+ return url.slice(0, end);
394
464
  }
395
465
 
396
466
  // src/pagination.ts
@@ -494,6 +564,14 @@ var CalendarsClient = class {
494
564
  async delete(id, options) {
495
565
  await this.client.request("DELETE", `/v1/calendars/${id}`, void 0, void 0, options);
496
566
  }
567
+ /**
568
+ * Regenerate the calendar's iCal subscribe URL. The old URL stops working
569
+ * (copies cached elsewhere can be served for up to 5 minutes); returns the
570
+ * calendar with its new `ical_url`. Organization keys only.
571
+ */
572
+ async rotateIcalToken(id, options) {
573
+ return this.client.request("POST", `/v1/calendars/${id}/ical-token/rotate`, void 0, void 0, options);
574
+ }
497
575
  async getContext(id, options) {
498
576
  return this.client.request(
499
577
  "GET",
@@ -545,9 +623,10 @@ var BookingPagesClient = class {
545
623
  return this.client.request("GET", `/v1/booking-pages/${id}`, void 0, void 0, options);
546
624
  }
547
625
  list(params = {}) {
548
- const { limit = 50, offset = 0 } = params;
626
+ const { limit = 50, offset = 0, ...filters } = params;
549
627
  return new PageIterator(
550
628
  (offset2, l) => this.client.request("GET", "/v1/booking-pages", void 0, {
629
+ ...filters,
551
630
  limit: l,
552
631
  offset: offset2
553
632
  }),
@@ -561,6 +640,22 @@ var BookingPagesClient = class {
561
640
  async delete(id, options) {
562
641
  await this.client.request("DELETE", `/v1/booking-pages/${id}`, void 0, void 0, options);
563
642
  }
643
+ /**
644
+ * One page of the bookings made through a booking page, newest start first,
645
+ * with the invitee's details. Pass the returned `next_cursor` as `cursor`
646
+ * for the next page (null on the last page). Bookings made before this
647
+ * endpoint was released are not linked to their page.
648
+ */
649
+ async listBookings(id, params = {}, options) {
650
+ return this.client.request("GET", `/v1/booking-pages/${id}/bookings`, void 0, { ...params }, options);
651
+ }
652
+ /**
653
+ * Replace the page's public link. The old `/book/<slug>` stops working at
654
+ * once; returns the page with its new `slug` and `booking_url`.
655
+ */
656
+ async rotateSlug(id, options) {
657
+ return this.client.request("POST", `/v1/booking-pages/${id}/rotate-slug`, void 0, void 0, options);
658
+ }
564
659
  /**
565
660
  * Public: list available slots for a booking page by its slug. No API key is
566
661
  * required for this endpoint (the slug is the credential); any key set on the
@@ -623,6 +718,23 @@ var EventsClient = class {
623
718
  offset
624
719
  );
625
720
  }
721
+ /**
722
+ * List events across all of the organization's calendars (`GET /v1/events`),
723
+ * ordered by start time. An agent-scoped key sees only its agent's
724
+ * calendars. `q` searches titles and needs a window of at most 31 days.
725
+ */
726
+ listAll(params = {}) {
727
+ const { limit = 50, offset = 0, ...filters } = params;
728
+ return new PageIterator(
729
+ (offset2, l) => this.client.request("GET", "/v1/events", void 0, {
730
+ ...filters,
731
+ limit: l,
732
+ offset: offset2
733
+ }),
734
+ limit,
735
+ offset
736
+ );
737
+ }
626
738
  async update(calendarId, eventId, params, options) {
627
739
  return this.client.request(
628
740
  "PATCH",
@@ -811,12 +923,75 @@ var WebhooksClient = class {
811
923
  await this.client.request("DELETE", `/v1/webhooks/${id}`, void 0, void 0, options);
812
924
  }
813
925
  async listDeliveries(webhookId, params = {}, options) {
814
- const { limit = 20, offset = 0, status, include_payload } = params;
926
+ const { limit = 20, offset = 0, ...filters } = params;
927
+ const query = { limit, offset };
928
+ for (const [key, value] of Object.entries(filters)) {
929
+ if (value !== void 0) query[key] = value;
930
+ }
815
931
  return this.client.request(
816
932
  "GET",
817
933
  `/v1/webhooks/${webhookId}/deliveries`,
818
934
  void 0,
819
- { limit, offset, ...status !== void 0 && { status }, ...include_payload !== void 0 && { include_payload } },
935
+ query,
936
+ options
937
+ );
938
+ }
939
+ /** One delivery with its payload and every attempt, oldest first. */
940
+ async getDelivery(webhookId, deliveryId, options) {
941
+ return this.client.request(
942
+ "GET",
943
+ `/v1/webhooks/${webhookId}/deliveries/${deliveryId}`,
944
+ void 0,
945
+ void 0,
946
+ options
947
+ );
948
+ }
949
+ /**
950
+ * Send a signed sample payload of one event type to the endpoint. The
951
+ * delivery is marked `is_test`, carries `X-Chronary-Test: 1`, makes one
952
+ * attempt and does not count toward the monthly quota. Poll `getDelivery`
953
+ * with the returned `delivery_id` for the result. Limited to 10 per minute.
954
+ */
955
+ async sendTest(webhookId, params, options) {
956
+ return this.client.request(
957
+ "POST",
958
+ `/v1/webhooks/${webhookId}/test`,
959
+ params,
960
+ void 0,
961
+ options
962
+ );
963
+ }
964
+ /**
965
+ * Send a `failed` or `dropped` delivery again as a new delivery with its
966
+ * own `delivery_id` (Developer or Pro). The stored payload goes out unchanged, signed
967
+ * with the endpoint's current secret, with an `X-Chronary-Replay-Of`
968
+ * header. It follows the normal retry schedule and counts toward the
969
+ * monthly delivery quota. The endpoint must be active. Sent with an
970
+ * `Idempotency-Key` (generated, or `options.idempotencyKey`), so a retry
971
+ * returns the same replay. Limited to 30 per minute.
972
+ */
973
+ async replayDelivery(webhookId, deliveryId, options) {
974
+ return this.client.request(
975
+ "POST",
976
+ `/v1/webhooks/${webhookId}/deliveries/${deliveryId}/replay`,
977
+ void 0,
978
+ void 0,
979
+ options
980
+ );
981
+ }
982
+ /**
983
+ * Rotate the endpoint's signing secret (Developer or Pro). The new secret is returned
984
+ * once and signs `X-Signature` from the next attempt. The replaced secret
985
+ * keeps signing `X-Signature-Previous` until `expire_old_in` has passed
986
+ * (default `24h`; `now` drops it at once), so receivers can switch
987
+ * without rejecting deliveries. `verifySignature` accepts either header.
988
+ */
989
+ async rotateSecret(webhookId, params = {}, options) {
990
+ return this.client.request(
991
+ "POST",
992
+ `/v1/webhooks/${webhookId}/secret/rotate`,
993
+ params,
994
+ void 0,
820
995
  options
821
996
  );
822
997
  }
@@ -877,6 +1052,12 @@ var ICalSubscriptionsClient = class {
877
1052
  options
878
1053
  );
879
1054
  }
1055
+ /**
1056
+ * Start an immediate fetch of the feed. Resolves with `{ status: 'syncing' }`
1057
+ * as soon as the fetch has started; read the subscription a few seconds later
1058
+ * for `last_synced_at` / `last_error`. A paused feed rejects with 409, and a
1059
+ * second sync of the same feed within a minute rejects with 429.
1060
+ */
880
1061
  async sync(id, options) {
881
1062
  return this.client.request(
882
1063
  "POST",
@@ -886,6 +1067,26 @@ var ICalSubscriptionsClient = class {
886
1067
  options
887
1068
  );
888
1069
  }
1070
+ /** Stop polling the feed until it is resumed. Pausing a paused feed changes nothing. */
1071
+ async pause(id, options) {
1072
+ return this.client.request(
1073
+ "POST",
1074
+ `/v1/ical-subscriptions/${id}/pause`,
1075
+ void 0,
1076
+ void 0,
1077
+ options
1078
+ );
1079
+ }
1080
+ /** Return a paused or failing feed to polling and clear `last_error`. */
1081
+ async resume(id, options) {
1082
+ return this.client.request(
1083
+ "POST",
1084
+ `/v1/ical-subscriptions/${id}/resume`,
1085
+ void 0,
1086
+ void 0,
1087
+ options
1088
+ );
1089
+ }
889
1090
  };
890
1091
 
891
1092
  // src/resources/scheduling.ts
@@ -963,6 +1164,15 @@ var UsageClient = class {
963
1164
  async get(options) {
964
1165
  return this.client.request("GET", "/v1/usage", void 0, void 0, options);
965
1166
  }
1167
+ /**
1168
+ * Monthly totals for the last 1-12 UTC calendar months (default 6), oldest
1169
+ * first, ending with the current partial month. Org-level keys only; not
1170
+ * counted toward API calls.
1171
+ */
1172
+ async history(params, options) {
1173
+ const query = { months: params?.months };
1174
+ return this.client.request("GET", "/v1/usage/history", void 0, query, options);
1175
+ }
966
1176
  };
967
1177
 
968
1178
  // src/resources/audit-log.ts
@@ -977,6 +1187,12 @@ var AuditLogClient = class {
977
1187
  to: params?.to,
978
1188
  action: params?.action,
979
1189
  actor_key_prefix: params?.actor_key_prefix,
1190
+ actor_type: params?.actor_type,
1191
+ actor_id: params?.actor_id,
1192
+ request_id: params?.request_id,
1193
+ resource: params?.resource,
1194
+ status_class: params?.status_class,
1195
+ category: params?.category,
980
1196
  cursor: params?.cursor,
981
1197
  limit: params?.limit
982
1198
  };
@@ -1075,19 +1291,18 @@ var WaitlistClient = class {
1075
1291
  }
1076
1292
  client;
1077
1293
  /**
1078
- * Join the Chronary waitlist (#442). Used during private preview when open
1079
- * signup is gated. Creates a real organization row flagged as
1080
- * `is_waitlisted: true`; an admin flips the flag to activate the account.
1294
+ * Join the Chronary waitlist. Used while open sign-up is gated. Adds the
1295
+ * email to the waitlist; an account is created only when a founder approves
1296
+ * it and the person accepts the emailed invite.
1081
1297
  *
1082
1298
  * No authentication required — invoke on a `Chronary` client constructed
1083
1299
  * with no `apiKey`.
1084
1300
  *
1085
- * Idempotent on repeat hits: a second call with the same email returns
1086
- * the existing waitlisted org instead of erroring. An active (non-waitlisted)
1087
- * account at the same email returns 409 `email_taken`.
1301
+ * Always resolves to the same `{ waitlisted: true, message }` (HTTP 202),
1302
+ * whether the email is new, already on the list, or has an active account,
1303
+ * so the response can't be used to look up other people's accounts. Only a
1304
+ * new email is sent the confirmation email.
1088
1305
  *
1089
- * @throws ChronaryError (409 `email_taken`) when an active account already
1090
- * exists for this email — direct the user to sign-in instead.
1091
1306
  * @throws ChronaryError (409 `tos_version_stale`) when the supplied
1092
1307
  * `tos_version` doesn't match the currently-published version.
1093
1308
  * @throws ChronaryError (429 `rate_limit_error`) on the per-IP / per-email
@@ -1111,7 +1326,7 @@ var FeedbackClient = class {
1111
1326
  }
1112
1327
  client;
1113
1328
  /**
1114
- * Submit structured feedback (bug, feature, or friction) to Chronary.
1329
+ * Submit structured feedback (bug, feature, friction, or support) to Chronary.
1115
1330
  *
1116
1331
  * Rate-limited to 25 submissions per day per organization (UTC day).
1117
1332
  * Available on all plans, including free. The 26th submission returns
@@ -1138,7 +1353,7 @@ var PlansClient = class {
1138
1353
  /**
1139
1354
  * Fetch the public plan catalog (`GET /v1/plans`).
1140
1355
  *
1141
- * Returns all sellable tiers (free, pro, scale) plus the enterprise
1356
+ * Returns all sellable tiers (free, developer, pro) plus the enterprise
1142
1357
  * tier with `custom_pricing: true`. No authentication required.
1143
1358
  * Responses are cacheable for 5 minutes at the edge.
1144
1359
  */
@@ -1218,6 +1433,17 @@ var ConnectionLinksClient = class {
1218
1433
  async create(calendarId, params, options) {
1219
1434
  return this.client.request("POST", `/v1/calendars/${calendarId}/connection-links`, params, void 0, options);
1220
1435
  }
1436
+ /** Setup links, newest first. An agent-scoped key sees only its own calendars' links. */
1437
+ async list(params = {}, options) {
1438
+ const { status, calendar_id, limit } = params;
1439
+ return this.client.request(
1440
+ "GET",
1441
+ "/v1/connection-links",
1442
+ void 0,
1443
+ { ...status !== void 0 && { status }, ...calendar_id !== void 0 && { calendar_id }, ...limit !== void 0 && { limit } },
1444
+ options
1445
+ );
1446
+ }
1221
1447
  async get(id, options) {
1222
1448
  return this.client.request("GET", `/v1/connection-links/${id}`, void 0, void 0, options);
1223
1449
  }
@@ -1226,6 +1452,42 @@ var ConnectionLinksClient = class {
1226
1452
  }
1227
1453
  };
1228
1454
 
1455
+ // src/resources/billing.ts
1456
+ var UpgradeRequestsClient = class {
1457
+ constructor(client) {
1458
+ this.client = client;
1459
+ }
1460
+ client;
1461
+ /**
1462
+ * Ask a human to upgrade this account's plan. Org keys (`chr_sk_`) only.
1463
+ * Returns an `approval_url` to hand to your human. Honors `idempotencyKey`;
1464
+ * if `reused` is true a request is already pending — poll it instead.
1465
+ */
1466
+ async create(params = {}, options) {
1467
+ return this.client.request("POST", "/v1/billing/upgrade-requests", params, void 0, options);
1468
+ }
1469
+ /** Poll an upgrade request (at most once a minute). */
1470
+ async get(id, options) {
1471
+ return this.client.request("GET", `/v1/billing/upgrade-requests/${id}`, void 0, void 0, options);
1472
+ }
1473
+ /** Withdraw a pending upgrade request. */
1474
+ async cancel(id, options) {
1475
+ return this.client.request("POST", `/v1/billing/upgrade-requests/${id}/cancel`, void 0, void 0, options);
1476
+ }
1477
+ };
1478
+ var BillingClient = class {
1479
+ constructor(client) {
1480
+ this.client = client;
1481
+ this.upgradeRequests = new UpgradeRequestsClient(client);
1482
+ }
1483
+ client;
1484
+ upgradeRequests;
1485
+ /** Read-only billing summary for the org (plan, status, upgrade options, pending upgrade request). */
1486
+ async get(options) {
1487
+ return this.client.request("GET", "/v1/billing", void 0, void 0, options);
1488
+ }
1489
+ };
1490
+
1229
1491
  // src/webhook-verify.ts
1230
1492
  var DEFAULT_TOLERANCE = 5 * 60 * 1e3;
1231
1493
  function bufToHex(buf) {
@@ -1269,10 +1531,11 @@ function extractHeaders(headers) {
1269
1531
  return getHeader(headers, name);
1270
1532
  };
1271
1533
  const signature = get("X-Signature") ?? get("x-signature");
1534
+ const previousSignature = get("X-Signature-Previous") ?? get("x-signature-previous");
1272
1535
  const timestamp = get("X-Timestamp") ?? get("x-timestamp");
1273
1536
  if (!signature) throw new ChronaryError("Missing X-Signature header", 0);
1274
1537
  if (!timestamp) throw new ChronaryError("Missing X-Timestamp header", 0);
1275
- return { signature, timestamp };
1538
+ return { signature, previousSignature: previousSignature || null, timestamp };
1276
1539
  }
1277
1540
  async function verifySignature(rawBody, headers, secret, options) {
1278
1541
  if (typeof rawBody !== "string") {
@@ -1281,7 +1544,7 @@ async function verifySignature(rawBody, headers, secret, options) {
1281
1544
  0
1282
1545
  );
1283
1546
  }
1284
- const { signature, timestamp } = extractHeaders(headers);
1547
+ const { signature, previousSignature, timestamp } = extractHeaders(headers);
1285
1548
  const tolerance = options?.tolerance ?? DEFAULT_TOLERANCE;
1286
1549
  const tsMs = parseInt(timestamp, 10) * 1e3;
1287
1550
  const now = Date.now();
@@ -1292,7 +1555,9 @@ async function verifySignature(rawBody, headers, secret, options) {
1292
1555
  );
1293
1556
  }
1294
1557
  const expected = await computeSignature(secret, timestamp, rawBody);
1295
- if (!constantTimeEqual(expected, signature)) {
1558
+ const matchesCurrent = constantTimeEqual(expected, signature);
1559
+ const matchesPrevious = previousSignature !== null && constantTimeEqual(expected, previousSignature);
1560
+ if (!matchesCurrent && !matchesPrevious) {
1296
1561
  throw new ChronaryError("Webhook signature verification failed", 0);
1297
1562
  }
1298
1563
  }
@@ -1324,6 +1589,7 @@ var Chronary = class {
1324
1589
  account;
1325
1590
  terms;
1326
1591
  connectionLinks;
1592
+ billing;
1327
1593
  constructor(config) {
1328
1594
  const client = new CoreClient(config);
1329
1595
  this.agents = new AgentsClient(client);
@@ -1344,6 +1610,7 @@ var Chronary = class {
1344
1610
  this.account = new AccountClient(client);
1345
1611
  this.terms = new TermsClient(client);
1346
1612
  this.connectionLinks = new ConnectionLinksClient(client);
1613
+ this.billing = new BillingClient(client);
1347
1614
  }
1348
1615
  static webhooks = {
1349
1616
  verifySignature,
@@ -1355,6 +1622,7 @@ var index_default = Chronary;
1355
1622
  0 && (module.exports = {
1356
1623
  APIPromise,
1357
1624
  AuthenticationError,
1625
+ BillingClient,
1358
1626
  BookingPagesClient,
1359
1627
  Chronary,
1360
1628
  ChronaryError,
@@ -1363,9 +1631,11 @@ var index_default = Chronary;
1363
1631
  CoreClient,
1364
1632
  NotFoundError,
1365
1633
  PageIterator,
1634
+ PlanRequiredError,
1366
1635
  QuotaExceededError,
1367
1636
  RateLimitError,
1368
1637
  TimeoutError,
1638
+ UpgradeRequestsClient,
1369
1639
  VERSION,
1370
1640
  ValidationError,
1371
1641
  constructEvent,