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