@chronary/sdk 0.7.1 → 0.8.1
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 +28 -0
- package/README.md +6 -0
- package/dist/index.cjs +313 -44
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +615 -41
- package/dist/index.d.ts +615 -41
- package/dist/index.js +310 -44
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,31 +1,61 @@
|
|
|
1
1
|
// src/version.ts
|
|
2
|
-
var VERSION = "0.
|
|
2
|
+
var VERSION = "0.8.1";
|
|
3
3
|
|
|
4
4
|
// src/error.ts
|
|
5
|
+
function str(body, key) {
|
|
6
|
+
const v = body?.[key];
|
|
7
|
+
return typeof v === "string" ? v : void 0;
|
|
8
|
+
}
|
|
9
|
+
function num(body, key) {
|
|
10
|
+
const v = body?.[key];
|
|
11
|
+
return typeof v === "number" ? v : void 0;
|
|
12
|
+
}
|
|
5
13
|
var ChronaryError = class extends Error {
|
|
6
14
|
status;
|
|
7
15
|
requestId;
|
|
8
16
|
headers;
|
|
9
17
|
errorType;
|
|
10
|
-
|
|
18
|
+
/** Raw `error` object from the response body (all server-provided fields). */
|
|
19
|
+
body;
|
|
20
|
+
/** Where a human can upgrade the plan (plan_required / quota_exceeded errors). */
|
|
21
|
+
upgradeUrl;
|
|
22
|
+
docsUrl;
|
|
23
|
+
requiredPlan;
|
|
24
|
+
/** Self-serve plan `upgradeUrl` leads to: the next plan up (quota_exceeded and count-cap errors). */
|
|
25
|
+
upgradePlan;
|
|
26
|
+
feature;
|
|
27
|
+
contactUrl;
|
|
28
|
+
/** Quota metric that was exhausted (quota_exceeded errors). */
|
|
29
|
+
metric;
|
|
30
|
+
limit;
|
|
31
|
+
constructor(message, status, requestId, headers, errorType, body) {
|
|
11
32
|
super(message);
|
|
12
33
|
this.name = "ChronaryError";
|
|
13
34
|
this.status = status;
|
|
14
35
|
this.requestId = requestId;
|
|
15
36
|
this.headers = headers;
|
|
16
37
|
this.errorType = errorType;
|
|
38
|
+
this.body = body;
|
|
39
|
+
this.upgradeUrl = str(body, "upgrade_url");
|
|
40
|
+
this.docsUrl = str(body, "docs_url");
|
|
41
|
+
this.requiredPlan = str(body, "required_plan");
|
|
42
|
+
this.upgradePlan = str(body, "upgrade_plan");
|
|
43
|
+
this.feature = str(body, "feature");
|
|
44
|
+
this.contactUrl = str(body, "contact_url");
|
|
45
|
+
this.metric = str(body, "metric");
|
|
46
|
+
this.limit = num(body, "limit");
|
|
17
47
|
}
|
|
18
48
|
};
|
|
19
49
|
var AuthenticationError = class extends ChronaryError {
|
|
20
|
-
constructor(message, requestId, headers) {
|
|
21
|
-
super(message, 401, requestId, headers, "authentication_error");
|
|
50
|
+
constructor(message, requestId, headers, body) {
|
|
51
|
+
super(message, 401, requestId, headers, "authentication_error", body);
|
|
22
52
|
this.name = "AuthenticationError";
|
|
23
53
|
}
|
|
24
54
|
};
|
|
25
55
|
var RateLimitError = class extends ChronaryError {
|
|
26
56
|
retryAfter;
|
|
27
|
-
constructor(message, requestId, headers) {
|
|
28
|
-
super(message, 429, requestId, headers, "rate_limit_error");
|
|
57
|
+
constructor(message, requestId, headers, body) {
|
|
58
|
+
super(message, 429, requestId, headers, "rate_limit_error", body);
|
|
29
59
|
this.name = "RateLimitError";
|
|
30
60
|
if (headers) {
|
|
31
61
|
const ra = headers.get("retry-after");
|
|
@@ -34,23 +64,29 @@ var RateLimitError = class extends ChronaryError {
|
|
|
34
64
|
}
|
|
35
65
|
};
|
|
36
66
|
var NotFoundError = class extends ChronaryError {
|
|
37
|
-
constructor(message, requestId, headers) {
|
|
38
|
-
super(message, 404, requestId, headers, "not_found");
|
|
67
|
+
constructor(message, requestId, headers, body) {
|
|
68
|
+
super(message, 404, requestId, headers, "not_found", body);
|
|
39
69
|
this.name = "NotFoundError";
|
|
40
70
|
}
|
|
41
71
|
};
|
|
42
72
|
var ValidationError = class extends ChronaryError {
|
|
43
|
-
constructor(message, status, requestId, headers) {
|
|
44
|
-
super(message, status, requestId, headers, "validation_error");
|
|
73
|
+
constructor(message, status, requestId, headers, body) {
|
|
74
|
+
super(message, status, requestId, headers, "validation_error", body);
|
|
45
75
|
this.name = "ValidationError";
|
|
46
76
|
}
|
|
47
77
|
};
|
|
48
78
|
var QuotaExceededError = class extends ChronaryError {
|
|
49
|
-
constructor(message, requestId, headers) {
|
|
50
|
-
super(message,
|
|
79
|
+
constructor(message, requestId, headers, body, status = 429) {
|
|
80
|
+
super(message, status, requestId, headers, "quota_exceeded", body);
|
|
51
81
|
this.name = "QuotaExceededError";
|
|
52
82
|
}
|
|
53
83
|
};
|
|
84
|
+
var PlanRequiredError = class extends ChronaryError {
|
|
85
|
+
constructor(message, requestId, headers, body) {
|
|
86
|
+
super(message, 403, requestId, headers, "plan_required", body);
|
|
87
|
+
this.name = "PlanRequiredError";
|
|
88
|
+
}
|
|
89
|
+
};
|
|
54
90
|
var TimeoutError = class extends ChronaryError {
|
|
55
91
|
constructor(message) {
|
|
56
92
|
super(message, 0);
|
|
@@ -151,7 +187,7 @@ var CoreClient = class {
|
|
|
151
187
|
extraHeaders;
|
|
152
188
|
constructor(config = {}) {
|
|
153
189
|
this.apiKey = config.apiKey ?? getEnvVar("CHRONARY_API_KEY") ?? "";
|
|
154
|
-
this.baseUrl = (config.baseUrl ?? DEFAULT_BASE_URL)
|
|
190
|
+
this.baseUrl = stripTrailingSlashes(config.baseUrl ?? DEFAULT_BASE_URL);
|
|
155
191
|
this.timeout = config.timeout ?? DEFAULT_TIMEOUT;
|
|
156
192
|
this.maxRetries = config.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
157
193
|
this.logLevel = resolveLogLevel(config);
|
|
@@ -274,7 +310,12 @@ var CoreClient = class {
|
|
|
274
310
|
if (!query) return base;
|
|
275
311
|
const params = new URLSearchParams();
|
|
276
312
|
for (const [key, value] of Object.entries(query)) {
|
|
277
|
-
if (value
|
|
313
|
+
if (value === void 0) continue;
|
|
314
|
+
if (Array.isArray(value)) {
|
|
315
|
+
for (const v of value) params.append(key, v);
|
|
316
|
+
} else {
|
|
317
|
+
params.set(key, String(value));
|
|
318
|
+
}
|
|
278
319
|
}
|
|
279
320
|
const qs = params.toString();
|
|
280
321
|
return qs ? `${base}?${qs}` : base;
|
|
@@ -288,28 +329,34 @@ var CoreClient = class {
|
|
|
288
329
|
const message = errorBody?.error?.message ?? `HTTP ${response.status}`;
|
|
289
330
|
const rid = requestId ?? errorBody?.error?.request_id;
|
|
290
331
|
const errorType = errorBody?.error?.type;
|
|
332
|
+
const body = errorBody?.error;
|
|
291
333
|
switch (response.status) {
|
|
292
334
|
case 400:
|
|
293
335
|
if (errorType === "validation_error") {
|
|
294
|
-
return new ValidationError(message, response.status, rid, response.headers);
|
|
336
|
+
return new ValidationError(message, response.status, rid, response.headers, body);
|
|
295
337
|
}
|
|
296
|
-
return new ChronaryError(message, response.status, rid, response.headers, errorType);
|
|
338
|
+
return new ChronaryError(message, response.status, rid, response.headers, errorType, body);
|
|
297
339
|
case 401:
|
|
298
|
-
return new AuthenticationError(message, rid, response.headers);
|
|
340
|
+
return new AuthenticationError(message, rid, response.headers, body);
|
|
299
341
|
case 402:
|
|
300
|
-
return new QuotaExceededError(message, rid, response.headers);
|
|
342
|
+
return new QuotaExceededError(message, rid, response.headers, body, 402);
|
|
343
|
+
case 403:
|
|
344
|
+
if (errorType === "plan_required") {
|
|
345
|
+
return new PlanRequiredError(message, rid, response.headers, body);
|
|
346
|
+
}
|
|
347
|
+
return new ChronaryError(message, response.status, rid, response.headers, errorType, body);
|
|
301
348
|
case 404:
|
|
302
|
-
return new NotFoundError(message, rid, response.headers);
|
|
349
|
+
return new NotFoundError(message, rid, response.headers, body);
|
|
303
350
|
case 422:
|
|
304
|
-
return new ValidationError(message, response.status, rid, response.headers);
|
|
351
|
+
return new ValidationError(message, response.status, rid, response.headers, body);
|
|
305
352
|
case 429: {
|
|
306
353
|
if (errorType === "quota_exceeded") {
|
|
307
|
-
return new QuotaExceededError(message, rid, response.headers);
|
|
354
|
+
return new QuotaExceededError(message, rid, response.headers, body, 429);
|
|
308
355
|
}
|
|
309
|
-
return new RateLimitError(message, rid, response.headers);
|
|
356
|
+
return new RateLimitError(message, rid, response.headers, body);
|
|
310
357
|
}
|
|
311
358
|
default:
|
|
312
|
-
return new ChronaryError(message, response.status, rid, response.headers, errorType);
|
|
359
|
+
return new ChronaryError(message, response.status, rid, response.headers, errorType, body);
|
|
313
360
|
}
|
|
314
361
|
}
|
|
315
362
|
retryDelay(attempt, lastError) {
|
|
@@ -342,11 +389,30 @@ function parseQuotaSnapshot(headers) {
|
|
|
342
389
|
};
|
|
343
390
|
}
|
|
344
391
|
function parseStructuredParam(header, key) {
|
|
345
|
-
const
|
|
346
|
-
const
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
392
|
+
const prefix = `${key}=`;
|
|
393
|
+
for (const member of header.split(";")) {
|
|
394
|
+
const trimmed = member.trimStart();
|
|
395
|
+
if (!trimmed.startsWith(prefix)) continue;
|
|
396
|
+
const value = trimmed.slice(prefix.length);
|
|
397
|
+
if (!isSignedInteger(value)) continue;
|
|
398
|
+
const n = Number(value);
|
|
399
|
+
return Number.isFinite(n) ? n : void 0;
|
|
400
|
+
}
|
|
401
|
+
return void 0;
|
|
402
|
+
}
|
|
403
|
+
function isSignedInteger(value) {
|
|
404
|
+
const start = value.startsWith("-") ? 1 : 0;
|
|
405
|
+
if (value.length === start) return false;
|
|
406
|
+
for (let i = start; i < value.length; i++) {
|
|
407
|
+
const c = value.charCodeAt(i);
|
|
408
|
+
if (c < 48 || c > 57) return false;
|
|
409
|
+
}
|
|
410
|
+
return true;
|
|
411
|
+
}
|
|
412
|
+
function stripTrailingSlashes(url) {
|
|
413
|
+
let end = url.length;
|
|
414
|
+
while (end > 0 && url.charCodeAt(end - 1) === 47) end--;
|
|
415
|
+
return url.slice(0, end);
|
|
350
416
|
}
|
|
351
417
|
|
|
352
418
|
// src/pagination.ts
|
|
@@ -450,6 +516,14 @@ var CalendarsClient = class {
|
|
|
450
516
|
async delete(id, options) {
|
|
451
517
|
await this.client.request("DELETE", `/v1/calendars/${id}`, void 0, void 0, options);
|
|
452
518
|
}
|
|
519
|
+
/**
|
|
520
|
+
* Regenerate the calendar's iCal subscribe URL. The old URL stops working
|
|
521
|
+
* (copies cached elsewhere can be served for up to 5 minutes); returns the
|
|
522
|
+
* calendar with its new `ical_url`. Organization keys only.
|
|
523
|
+
*/
|
|
524
|
+
async rotateIcalToken(id, options) {
|
|
525
|
+
return this.client.request("POST", `/v1/calendars/${id}/ical-token/rotate`, void 0, void 0, options);
|
|
526
|
+
}
|
|
453
527
|
async getContext(id, options) {
|
|
454
528
|
return this.client.request(
|
|
455
529
|
"GET",
|
|
@@ -501,9 +575,10 @@ var BookingPagesClient = class {
|
|
|
501
575
|
return this.client.request("GET", `/v1/booking-pages/${id}`, void 0, void 0, options);
|
|
502
576
|
}
|
|
503
577
|
list(params = {}) {
|
|
504
|
-
const { limit = 50, offset = 0 } = params;
|
|
578
|
+
const { limit = 50, offset = 0, ...filters } = params;
|
|
505
579
|
return new PageIterator(
|
|
506
580
|
(offset2, l) => this.client.request("GET", "/v1/booking-pages", void 0, {
|
|
581
|
+
...filters,
|
|
507
582
|
limit: l,
|
|
508
583
|
offset: offset2
|
|
509
584
|
}),
|
|
@@ -517,6 +592,22 @@ var BookingPagesClient = class {
|
|
|
517
592
|
async delete(id, options) {
|
|
518
593
|
await this.client.request("DELETE", `/v1/booking-pages/${id}`, void 0, void 0, options);
|
|
519
594
|
}
|
|
595
|
+
/**
|
|
596
|
+
* One page of the bookings made through a booking page, newest start first,
|
|
597
|
+
* with the invitee's details. Pass the returned `next_cursor` as `cursor`
|
|
598
|
+
* for the next page (null on the last page). Bookings made before this
|
|
599
|
+
* endpoint was released are not linked to their page.
|
|
600
|
+
*/
|
|
601
|
+
async listBookings(id, params = {}, options) {
|
|
602
|
+
return this.client.request("GET", `/v1/booking-pages/${id}/bookings`, void 0, { ...params }, options);
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* Replace the page's public link. The old `/book/<slug>` stops working at
|
|
606
|
+
* once; returns the page with its new `slug` and `booking_url`.
|
|
607
|
+
*/
|
|
608
|
+
async rotateSlug(id, options) {
|
|
609
|
+
return this.client.request("POST", `/v1/booking-pages/${id}/rotate-slug`, void 0, void 0, options);
|
|
610
|
+
}
|
|
520
611
|
/**
|
|
521
612
|
* Public: list available slots for a booking page by its slug. No API key is
|
|
522
613
|
* required for this endpoint (the slug is the credential); any key set on the
|
|
@@ -579,6 +670,23 @@ var EventsClient = class {
|
|
|
579
670
|
offset
|
|
580
671
|
);
|
|
581
672
|
}
|
|
673
|
+
/**
|
|
674
|
+
* List events across all of the organization's calendars (`GET /v1/events`),
|
|
675
|
+
* ordered by start time. An agent-scoped key sees only its agent's
|
|
676
|
+
* calendars. `q` searches titles and needs a window of at most 31 days.
|
|
677
|
+
*/
|
|
678
|
+
listAll(params = {}) {
|
|
679
|
+
const { limit = 50, offset = 0, ...filters } = params;
|
|
680
|
+
return new PageIterator(
|
|
681
|
+
(offset2, l) => this.client.request("GET", "/v1/events", void 0, {
|
|
682
|
+
...filters,
|
|
683
|
+
limit: l,
|
|
684
|
+
offset: offset2
|
|
685
|
+
}),
|
|
686
|
+
limit,
|
|
687
|
+
offset
|
|
688
|
+
);
|
|
689
|
+
}
|
|
582
690
|
async update(calendarId, eventId, params, options) {
|
|
583
691
|
return this.client.request(
|
|
584
692
|
"PATCH",
|
|
@@ -767,12 +875,75 @@ var WebhooksClient = class {
|
|
|
767
875
|
await this.client.request("DELETE", `/v1/webhooks/${id}`, void 0, void 0, options);
|
|
768
876
|
}
|
|
769
877
|
async listDeliveries(webhookId, params = {}, options) {
|
|
770
|
-
const { limit = 20, offset = 0,
|
|
878
|
+
const { limit = 20, offset = 0, ...filters } = params;
|
|
879
|
+
const query = { limit, offset };
|
|
880
|
+
for (const [key, value] of Object.entries(filters)) {
|
|
881
|
+
if (value !== void 0) query[key] = value;
|
|
882
|
+
}
|
|
771
883
|
return this.client.request(
|
|
772
884
|
"GET",
|
|
773
885
|
`/v1/webhooks/${webhookId}/deliveries`,
|
|
774
886
|
void 0,
|
|
775
|
-
|
|
887
|
+
query,
|
|
888
|
+
options
|
|
889
|
+
);
|
|
890
|
+
}
|
|
891
|
+
/** One delivery with its payload and every attempt, oldest first. */
|
|
892
|
+
async getDelivery(webhookId, deliveryId, options) {
|
|
893
|
+
return this.client.request(
|
|
894
|
+
"GET",
|
|
895
|
+
`/v1/webhooks/${webhookId}/deliveries/${deliveryId}`,
|
|
896
|
+
void 0,
|
|
897
|
+
void 0,
|
|
898
|
+
options
|
|
899
|
+
);
|
|
900
|
+
}
|
|
901
|
+
/**
|
|
902
|
+
* Send a signed sample payload of one event type to the endpoint. The
|
|
903
|
+
* delivery is marked `is_test`, carries `X-Chronary-Test: 1`, makes one
|
|
904
|
+
* attempt and does not count toward the monthly quota. Poll `getDelivery`
|
|
905
|
+
* with the returned `delivery_id` for the result. Limited to 10 per minute.
|
|
906
|
+
*/
|
|
907
|
+
async sendTest(webhookId, params, options) {
|
|
908
|
+
return this.client.request(
|
|
909
|
+
"POST",
|
|
910
|
+
`/v1/webhooks/${webhookId}/test`,
|
|
911
|
+
params,
|
|
912
|
+
void 0,
|
|
913
|
+
options
|
|
914
|
+
);
|
|
915
|
+
}
|
|
916
|
+
/**
|
|
917
|
+
* Send a `failed` or `dropped` delivery again as a new delivery with its
|
|
918
|
+
* own `delivery_id` (Developer or Pro). The stored payload goes out unchanged, signed
|
|
919
|
+
* with the endpoint's current secret, with an `X-Chronary-Replay-Of`
|
|
920
|
+
* header. It follows the normal retry schedule and counts toward the
|
|
921
|
+
* monthly delivery quota. The endpoint must be active. Sent with an
|
|
922
|
+
* `Idempotency-Key` (generated, or `options.idempotencyKey`), so a retry
|
|
923
|
+
* returns the same replay. Limited to 30 per minute.
|
|
924
|
+
*/
|
|
925
|
+
async replayDelivery(webhookId, deliveryId, options) {
|
|
926
|
+
return this.client.request(
|
|
927
|
+
"POST",
|
|
928
|
+
`/v1/webhooks/${webhookId}/deliveries/${deliveryId}/replay`,
|
|
929
|
+
void 0,
|
|
930
|
+
void 0,
|
|
931
|
+
options
|
|
932
|
+
);
|
|
933
|
+
}
|
|
934
|
+
/**
|
|
935
|
+
* Rotate the endpoint's signing secret (Developer or Pro). The new secret is returned
|
|
936
|
+
* once and signs `X-Signature` from the next attempt. The replaced secret
|
|
937
|
+
* keeps signing `X-Signature-Previous` until `expire_old_in` has passed
|
|
938
|
+
* (default `24h`; `now` drops it at once), so receivers can switch
|
|
939
|
+
* without rejecting deliveries. `verifySignature` accepts either header.
|
|
940
|
+
*/
|
|
941
|
+
async rotateSecret(webhookId, params = {}, options) {
|
|
942
|
+
return this.client.request(
|
|
943
|
+
"POST",
|
|
944
|
+
`/v1/webhooks/${webhookId}/secret/rotate`,
|
|
945
|
+
params,
|
|
946
|
+
void 0,
|
|
776
947
|
options
|
|
777
948
|
);
|
|
778
949
|
}
|
|
@@ -833,6 +1004,12 @@ var ICalSubscriptionsClient = class {
|
|
|
833
1004
|
options
|
|
834
1005
|
);
|
|
835
1006
|
}
|
|
1007
|
+
/**
|
|
1008
|
+
* Start an immediate fetch of the feed. Resolves with `{ status: 'syncing' }`
|
|
1009
|
+
* as soon as the fetch has started; read the subscription a few seconds later
|
|
1010
|
+
* for `last_synced_at` / `last_error`. A paused feed rejects with 409, and a
|
|
1011
|
+
* second sync of the same feed within a minute rejects with 429.
|
|
1012
|
+
*/
|
|
836
1013
|
async sync(id, options) {
|
|
837
1014
|
return this.client.request(
|
|
838
1015
|
"POST",
|
|
@@ -842,6 +1019,26 @@ var ICalSubscriptionsClient = class {
|
|
|
842
1019
|
options
|
|
843
1020
|
);
|
|
844
1021
|
}
|
|
1022
|
+
/** Stop polling the feed until it is resumed. Pausing a paused feed changes nothing. */
|
|
1023
|
+
async pause(id, options) {
|
|
1024
|
+
return this.client.request(
|
|
1025
|
+
"POST",
|
|
1026
|
+
`/v1/ical-subscriptions/${id}/pause`,
|
|
1027
|
+
void 0,
|
|
1028
|
+
void 0,
|
|
1029
|
+
options
|
|
1030
|
+
);
|
|
1031
|
+
}
|
|
1032
|
+
/** Return a paused or failing feed to polling and clear `last_error`. */
|
|
1033
|
+
async resume(id, options) {
|
|
1034
|
+
return this.client.request(
|
|
1035
|
+
"POST",
|
|
1036
|
+
`/v1/ical-subscriptions/${id}/resume`,
|
|
1037
|
+
void 0,
|
|
1038
|
+
void 0,
|
|
1039
|
+
options
|
|
1040
|
+
);
|
|
1041
|
+
}
|
|
845
1042
|
};
|
|
846
1043
|
|
|
847
1044
|
// src/resources/scheduling.ts
|
|
@@ -919,6 +1116,15 @@ var UsageClient = class {
|
|
|
919
1116
|
async get(options) {
|
|
920
1117
|
return this.client.request("GET", "/v1/usage", void 0, void 0, options);
|
|
921
1118
|
}
|
|
1119
|
+
/**
|
|
1120
|
+
* Monthly totals for the last 1-12 UTC calendar months (default 6), oldest
|
|
1121
|
+
* first, ending with the current partial month. Org-level keys only; not
|
|
1122
|
+
* counted toward API calls.
|
|
1123
|
+
*/
|
|
1124
|
+
async history(params, options) {
|
|
1125
|
+
const query = { months: params?.months };
|
|
1126
|
+
return this.client.request("GET", "/v1/usage/history", void 0, query, options);
|
|
1127
|
+
}
|
|
922
1128
|
};
|
|
923
1129
|
|
|
924
1130
|
// src/resources/audit-log.ts
|
|
@@ -933,6 +1139,12 @@ var AuditLogClient = class {
|
|
|
933
1139
|
to: params?.to,
|
|
934
1140
|
action: params?.action,
|
|
935
1141
|
actor_key_prefix: params?.actor_key_prefix,
|
|
1142
|
+
actor_type: params?.actor_type,
|
|
1143
|
+
actor_id: params?.actor_id,
|
|
1144
|
+
request_id: params?.request_id,
|
|
1145
|
+
resource: params?.resource,
|
|
1146
|
+
status_class: params?.status_class,
|
|
1147
|
+
category: params?.category,
|
|
936
1148
|
cursor: params?.cursor,
|
|
937
1149
|
limit: params?.limit
|
|
938
1150
|
};
|
|
@@ -1031,19 +1243,18 @@ var WaitlistClient = class {
|
|
|
1031
1243
|
}
|
|
1032
1244
|
client;
|
|
1033
1245
|
/**
|
|
1034
|
-
* Join the Chronary waitlist
|
|
1035
|
-
*
|
|
1036
|
-
*
|
|
1246
|
+
* Join the Chronary waitlist. Used while open sign-up is gated. Adds the
|
|
1247
|
+
* email to the waitlist; an account is created only when a founder approves
|
|
1248
|
+
* it and the person accepts the emailed invite.
|
|
1037
1249
|
*
|
|
1038
1250
|
* No authentication required — invoke on a `Chronary` client constructed
|
|
1039
1251
|
* with no `apiKey`.
|
|
1040
1252
|
*
|
|
1041
|
-
*
|
|
1042
|
-
* the
|
|
1043
|
-
*
|
|
1253
|
+
* Always resolves to the same `{ waitlisted: true, message }` (HTTP 202),
|
|
1254
|
+
* whether the email is new, already on the list, or has an active account,
|
|
1255
|
+
* so the response can't be used to look up other people's accounts. Only a
|
|
1256
|
+
* new email is sent the confirmation email.
|
|
1044
1257
|
*
|
|
1045
|
-
* @throws ChronaryError (409 `email_taken`) when an active account already
|
|
1046
|
-
* exists for this email — direct the user to sign-in instead.
|
|
1047
1258
|
* @throws ChronaryError (409 `tos_version_stale`) when the supplied
|
|
1048
1259
|
* `tos_version` doesn't match the currently-published version.
|
|
1049
1260
|
* @throws ChronaryError (429 `rate_limit_error`) on the per-IP / per-email
|
|
@@ -1067,7 +1278,7 @@ var FeedbackClient = class {
|
|
|
1067
1278
|
}
|
|
1068
1279
|
client;
|
|
1069
1280
|
/**
|
|
1070
|
-
* Submit structured feedback (bug, feature, or
|
|
1281
|
+
* Submit structured feedback (bug, feature, friction, or support) to Chronary.
|
|
1071
1282
|
*
|
|
1072
1283
|
* Rate-limited to 25 submissions per day per organization (UTC day).
|
|
1073
1284
|
* Available on all plans, including free. The 26th submission returns
|
|
@@ -1094,7 +1305,7 @@ var PlansClient = class {
|
|
|
1094
1305
|
/**
|
|
1095
1306
|
* Fetch the public plan catalog (`GET /v1/plans`).
|
|
1096
1307
|
*
|
|
1097
|
-
* Returns all sellable tiers (free,
|
|
1308
|
+
* Returns all sellable tiers (free, developer, pro) plus the enterprise
|
|
1098
1309
|
* tier with `custom_pricing: true`. No authentication required.
|
|
1099
1310
|
* Responses are cacheable for 5 minutes at the edge.
|
|
1100
1311
|
*/
|
|
@@ -1174,6 +1385,17 @@ var ConnectionLinksClient = class {
|
|
|
1174
1385
|
async create(calendarId, params, options) {
|
|
1175
1386
|
return this.client.request("POST", `/v1/calendars/${calendarId}/connection-links`, params, void 0, options);
|
|
1176
1387
|
}
|
|
1388
|
+
/** Setup links, newest first. An agent-scoped key sees only its own calendars' links. */
|
|
1389
|
+
async list(params = {}, options) {
|
|
1390
|
+
const { status, calendar_id, limit } = params;
|
|
1391
|
+
return this.client.request(
|
|
1392
|
+
"GET",
|
|
1393
|
+
"/v1/connection-links",
|
|
1394
|
+
void 0,
|
|
1395
|
+
{ ...status !== void 0 && { status }, ...calendar_id !== void 0 && { calendar_id }, ...limit !== void 0 && { limit } },
|
|
1396
|
+
options
|
|
1397
|
+
);
|
|
1398
|
+
}
|
|
1177
1399
|
async get(id, options) {
|
|
1178
1400
|
return this.client.request("GET", `/v1/connection-links/${id}`, void 0, void 0, options);
|
|
1179
1401
|
}
|
|
@@ -1182,6 +1404,42 @@ var ConnectionLinksClient = class {
|
|
|
1182
1404
|
}
|
|
1183
1405
|
};
|
|
1184
1406
|
|
|
1407
|
+
// src/resources/billing.ts
|
|
1408
|
+
var UpgradeRequestsClient = class {
|
|
1409
|
+
constructor(client) {
|
|
1410
|
+
this.client = client;
|
|
1411
|
+
}
|
|
1412
|
+
client;
|
|
1413
|
+
/**
|
|
1414
|
+
* Ask a human to upgrade this account's plan. Org keys (`chr_sk_`) only.
|
|
1415
|
+
* Returns an `approval_url` to hand to your human. Honors `idempotencyKey`;
|
|
1416
|
+
* if `reused` is true a request is already pending — poll it instead.
|
|
1417
|
+
*/
|
|
1418
|
+
async create(params = {}, options) {
|
|
1419
|
+
return this.client.request("POST", "/v1/billing/upgrade-requests", params, void 0, options);
|
|
1420
|
+
}
|
|
1421
|
+
/** Poll an upgrade request (at most once a minute). */
|
|
1422
|
+
async get(id, options) {
|
|
1423
|
+
return this.client.request("GET", `/v1/billing/upgrade-requests/${id}`, void 0, void 0, options);
|
|
1424
|
+
}
|
|
1425
|
+
/** Withdraw a pending upgrade request. */
|
|
1426
|
+
async cancel(id, options) {
|
|
1427
|
+
return this.client.request("POST", `/v1/billing/upgrade-requests/${id}/cancel`, void 0, void 0, options);
|
|
1428
|
+
}
|
|
1429
|
+
};
|
|
1430
|
+
var BillingClient = class {
|
|
1431
|
+
constructor(client) {
|
|
1432
|
+
this.client = client;
|
|
1433
|
+
this.upgradeRequests = new UpgradeRequestsClient(client);
|
|
1434
|
+
}
|
|
1435
|
+
client;
|
|
1436
|
+
upgradeRequests;
|
|
1437
|
+
/** Read-only billing summary for the org (plan, status, upgrade options, pending upgrade request). */
|
|
1438
|
+
async get(options) {
|
|
1439
|
+
return this.client.request("GET", "/v1/billing", void 0, void 0, options);
|
|
1440
|
+
}
|
|
1441
|
+
};
|
|
1442
|
+
|
|
1185
1443
|
// src/webhook-verify.ts
|
|
1186
1444
|
var DEFAULT_TOLERANCE = 5 * 60 * 1e3;
|
|
1187
1445
|
function bufToHex(buf) {
|
|
@@ -1225,10 +1483,11 @@ function extractHeaders(headers) {
|
|
|
1225
1483
|
return getHeader(headers, name);
|
|
1226
1484
|
};
|
|
1227
1485
|
const signature = get("X-Signature") ?? get("x-signature");
|
|
1486
|
+
const previousSignature = get("X-Signature-Previous") ?? get("x-signature-previous");
|
|
1228
1487
|
const timestamp = get("X-Timestamp") ?? get("x-timestamp");
|
|
1229
1488
|
if (!signature) throw new ChronaryError("Missing X-Signature header", 0);
|
|
1230
1489
|
if (!timestamp) throw new ChronaryError("Missing X-Timestamp header", 0);
|
|
1231
|
-
return { signature, timestamp };
|
|
1490
|
+
return { signature, previousSignature: previousSignature || null, timestamp };
|
|
1232
1491
|
}
|
|
1233
1492
|
async function verifySignature(rawBody, headers, secret, options) {
|
|
1234
1493
|
if (typeof rawBody !== "string") {
|
|
@@ -1237,7 +1496,7 @@ async function verifySignature(rawBody, headers, secret, options) {
|
|
|
1237
1496
|
0
|
|
1238
1497
|
);
|
|
1239
1498
|
}
|
|
1240
|
-
const { signature, timestamp } = extractHeaders(headers);
|
|
1499
|
+
const { signature, previousSignature, timestamp } = extractHeaders(headers);
|
|
1241
1500
|
const tolerance = options?.tolerance ?? DEFAULT_TOLERANCE;
|
|
1242
1501
|
const tsMs = parseInt(timestamp, 10) * 1e3;
|
|
1243
1502
|
const now = Date.now();
|
|
@@ -1248,7 +1507,9 @@ async function verifySignature(rawBody, headers, secret, options) {
|
|
|
1248
1507
|
);
|
|
1249
1508
|
}
|
|
1250
1509
|
const expected = await computeSignature(secret, timestamp, rawBody);
|
|
1251
|
-
|
|
1510
|
+
const matchesCurrent = constantTimeEqual(expected, signature);
|
|
1511
|
+
const matchesPrevious = previousSignature !== null && constantTimeEqual(expected, previousSignature);
|
|
1512
|
+
if (!matchesCurrent && !matchesPrevious) {
|
|
1252
1513
|
throw new ChronaryError("Webhook signature verification failed", 0);
|
|
1253
1514
|
}
|
|
1254
1515
|
}
|
|
@@ -1280,6 +1541,7 @@ var Chronary = class {
|
|
|
1280
1541
|
account;
|
|
1281
1542
|
terms;
|
|
1282
1543
|
connectionLinks;
|
|
1544
|
+
billing;
|
|
1283
1545
|
constructor(config) {
|
|
1284
1546
|
const client = new CoreClient(config);
|
|
1285
1547
|
this.agents = new AgentsClient(client);
|
|
@@ -1300,6 +1562,7 @@ var Chronary = class {
|
|
|
1300
1562
|
this.account = new AccountClient(client);
|
|
1301
1563
|
this.terms = new TermsClient(client);
|
|
1302
1564
|
this.connectionLinks = new ConnectionLinksClient(client);
|
|
1565
|
+
this.billing = new BillingClient(client);
|
|
1303
1566
|
}
|
|
1304
1567
|
static webhooks = {
|
|
1305
1568
|
verifySignature,
|
|
@@ -1310,6 +1573,7 @@ var index_default = Chronary;
|
|
|
1310
1573
|
export {
|
|
1311
1574
|
APIPromise,
|
|
1312
1575
|
AuthenticationError,
|
|
1576
|
+
BillingClient,
|
|
1313
1577
|
BookingPagesClient,
|
|
1314
1578
|
Chronary,
|
|
1315
1579
|
ChronaryError,
|
|
@@ -1318,9 +1582,11 @@ export {
|
|
|
1318
1582
|
CoreClient,
|
|
1319
1583
|
NotFoundError,
|
|
1320
1584
|
PageIterator,
|
|
1585
|
+
PlanRequiredError,
|
|
1321
1586
|
QuotaExceededError,
|
|
1322
1587
|
RateLimitError,
|
|
1323
1588
|
TimeoutError,
|
|
1589
|
+
UpgradeRequestsClient,
|
|
1324
1590
|
VERSION,
|
|
1325
1591
|
ValidationError,
|
|
1326
1592
|
constructEvent,
|