@pidgeon-ai/cli 0.0.0-stage → 1.0.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.
@@ -0,0 +1,1727 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ COMMANDS,
4
+ __export
5
+ } from "./chunk-Z2RNBVEN.js";
6
+
7
+ // ../sdk/dist/index.js
8
+ var dist_exports = {};
9
+ __export(dist_exports, {
10
+ SIGNATURE_HEADER: () => SIGNATURE_HEADER,
11
+ TIMESTAMP_HEADER: () => TIMESTAMP_HEADER,
12
+ agentAttachHuman: () => agentAttachHuman,
13
+ agentSignUp: () => agentSignUp,
14
+ agentVerify: () => agentVerify,
15
+ appPasswordsCreate: () => appPasswordsCreate,
16
+ appPasswordsList: () => appPasswordsList,
17
+ appPasswordsRevoke: () => appPasswordsRevoke,
18
+ attachmentsDownloadUrl: () => attachmentsDownloadUrl,
19
+ attachmentsUpload: () => attachmentsUpload,
20
+ calendarCreateEvent: () => calendarCreateEvent,
21
+ calendarDeleteEvent: () => calendarDeleteEvent,
22
+ calendarGet: () => calendarGet,
23
+ calendarGetAgenda: () => calendarGetAgenda,
24
+ calendarGetEvent: () => calendarGetEvent,
25
+ calendarListEventInstances: () => calendarListEventInstances,
26
+ calendarListEvents: () => calendarListEvents,
27
+ calendarRespondToEvent: () => calendarRespondToEvent,
28
+ calendarUpdate: () => calendarUpdate,
29
+ calendarUpdateEvent: () => calendarUpdateEvent,
30
+ client: () => client,
31
+ createClient: () => createClient,
32
+ createConfig: () => createConfig,
33
+ domainsCreate: () => domainsCreate,
34
+ domainsDelete: () => domainsDelete,
35
+ domainsGet: () => domainsGet,
36
+ domainsGetSetupLink: () => domainsGetSetupLink,
37
+ domainsList: () => domainsList,
38
+ domainsUpdate: () => domainsUpdate,
39
+ domainsVerify: () => domainsVerify,
40
+ domainsZoneFile: () => domainsZoneFile,
41
+ draftsCancelSchedule: () => draftsCancelSchedule,
42
+ draftsCreate: () => draftsCreate,
43
+ draftsDelete: () => draftsDelete,
44
+ draftsGet: () => draftsGet,
45
+ draftsList: () => draftsList,
46
+ draftsRemoveAttachment: () => draftsRemoveAttachment,
47
+ draftsSchedule: () => draftsSchedule,
48
+ draftsSend: () => draftsSend,
49
+ draftsUpdate: () => draftsUpdate,
50
+ eventsGet: () => eventsGet,
51
+ eventsList: () => eventsList,
52
+ identitiesAccessCreate: () => identitiesAccessCreate,
53
+ identitiesAccessDelete: () => identitiesAccessDelete,
54
+ identitiesAccessGet: () => identitiesAccessGet,
55
+ identitiesCreate: () => identitiesCreate,
56
+ identitiesDelete: () => identitiesDelete,
57
+ identitiesGet: () => identitiesGet,
58
+ identitiesList: () => identitiesList,
59
+ identitiesReceiveRulesCreate: () => identitiesReceiveRulesCreate,
60
+ identitiesReceiveRulesDelete: () => identitiesReceiveRulesDelete,
61
+ identitiesReceiveRulesGet: () => identitiesReceiveRulesGet,
62
+ identitiesSendRulesCreate: () => identitiesSendRulesCreate,
63
+ identitiesSendRulesDelete: () => identitiesSendRulesDelete,
64
+ identitiesSendRulesGet: () => identitiesSendRulesGet,
65
+ identitiesSuspendTenant: () => identitiesSuspendTenant,
66
+ identitiesUpdate: () => identitiesUpdate,
67
+ keysCreate: () => keysCreate,
68
+ keysGet: () => keysGet,
69
+ keysList: () => keysList,
70
+ keysRevoke: () => keysRevoke,
71
+ keysUpdate: () => keysUpdate,
72
+ labelsCreate: () => labelsCreate,
73
+ labelsDelete: () => labelsDelete,
74
+ labelsList: () => labelsList,
75
+ labelsUpdate: () => labelsUpdate,
76
+ mailboxesChanges: () => mailboxesChanges,
77
+ mailboxesEmptyTrash: () => mailboxesEmptyTrash,
78
+ mailboxesList: () => mailboxesList,
79
+ mailboxesListFolder: () => mailboxesListFolder,
80
+ messagesAct: () => messagesAct,
81
+ messagesForward: () => messagesForward,
82
+ messagesGet: () => messagesGet,
83
+ messagesListInThread: () => messagesListInThread,
84
+ messagesRaw: () => messagesRaw,
85
+ messagesReply: () => messagesReply,
86
+ messagesReplyAll: () => messagesReplyAll,
87
+ messagesRespondToInvitation: () => messagesRespondToInvitation,
88
+ messagesSearch: () => messagesSearch,
89
+ messagesSend: () => messagesSend,
90
+ messagesUndo: () => messagesUndo,
91
+ messagesUpdate: () => messagesUpdate,
92
+ metricsQuery: () => metricsQuery,
93
+ routingCreate: () => routingCreate,
94
+ routingDelete: () => routingDelete,
95
+ routingList: () => routingList,
96
+ routingUpdate: () => routingUpdate,
97
+ threadsGet: () => threadsGet,
98
+ threadsLabelsCreate: () => threadsLabelsCreate,
99
+ threadsLabelsDelete: () => threadsLabelsDelete,
100
+ threadsLabelsGet: () => threadsLabelsGet,
101
+ threadsList: () => threadsList,
102
+ threadsUpdate: () => threadsUpdate,
103
+ verifyWebhook: () => verifyWebhook,
104
+ webhooksCreate: () => webhooksCreate,
105
+ webhooksDelete: () => webhooksDelete,
106
+ webhooksDeliveries: () => webhooksDeliveries,
107
+ webhooksGet: () => webhooksGet,
108
+ webhooksGetHeaders: () => webhooksGetHeaders,
109
+ webhooksList: () => webhooksList,
110
+ webhooksReplay: () => webhooksReplay,
111
+ webhooksUpdate: () => webhooksUpdate,
112
+ webhooksUpdateHeaders: () => webhooksUpdateHeaders,
113
+ workspaceGet: () => workspaceGet,
114
+ workspaceMembers: () => workspaceMembers
115
+ });
116
+ var serializeFormDataPair = (data, key, value) => {
117
+ if (typeof value === "string" || value instanceof Blob) {
118
+ data.append(key, value);
119
+ } else if (value instanceof Date) {
120
+ data.append(key, value.toISOString());
121
+ } else {
122
+ data.append(key, JSON.stringify(value));
123
+ }
124
+ };
125
+ var formDataBodySerializer = {
126
+ bodySerializer: (body) => {
127
+ const data = new FormData();
128
+ Object.entries(body).forEach(([key, value]) => {
129
+ if (value === void 0 || value === null) {
130
+ return;
131
+ }
132
+ if (Array.isArray(value)) {
133
+ value.forEach((v) => serializeFormDataPair(data, key, v));
134
+ } else {
135
+ serializeFormDataPair(data, key, value);
136
+ }
137
+ });
138
+ return data;
139
+ }
140
+ };
141
+ var jsonBodySerializer = {
142
+ bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value)
143
+ };
144
+ function createSseClient({
145
+ onRequest,
146
+ onSseError,
147
+ onSseEvent,
148
+ responseTransformer,
149
+ responseValidator,
150
+ sseDefaultRetryDelay,
151
+ sseMaxRetryAttempts,
152
+ sseMaxRetryDelay,
153
+ sseSleepFn,
154
+ url,
155
+ ...options
156
+ }) {
157
+ let lastEventId;
158
+ const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
159
+ const createStream = async function* () {
160
+ let retryDelay = sseDefaultRetryDelay ?? 3e3;
161
+ let attempt = 0;
162
+ const signal = options.signal ?? new AbortController().signal;
163
+ while (true) {
164
+ if (signal.aborted) break;
165
+ attempt++;
166
+ const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
167
+ if (lastEventId !== void 0) {
168
+ headers.set("Last-Event-ID", lastEventId);
169
+ }
170
+ try {
171
+ const requestInit = {
172
+ redirect: "follow",
173
+ ...options,
174
+ body: options.serializedBody,
175
+ headers,
176
+ signal
177
+ };
178
+ let request = new Request(url, requestInit);
179
+ if (onRequest) {
180
+ request = await onRequest(url, requestInit);
181
+ }
182
+ const _fetch = options.fetch ?? globalThis.fetch;
183
+ const response = await _fetch(request);
184
+ if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
185
+ if (!response.body) throw new Error("No body in SSE response");
186
+ const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
187
+ let buffer = "";
188
+ const abortHandler = () => {
189
+ try {
190
+ reader.cancel();
191
+ } catch {
192
+ }
193
+ };
194
+ signal.addEventListener("abort", abortHandler);
195
+ try {
196
+ while (true) {
197
+ const { done, value } = await reader.read();
198
+ if (done) break;
199
+ buffer += value;
200
+ buffer = buffer.replace(/\r\n?/g, "\n");
201
+ const chunks = buffer.split("\n\n");
202
+ buffer = chunks.pop() ?? "";
203
+ for (const chunk of chunks) {
204
+ const lines = chunk.split("\n");
205
+ const dataLines = [];
206
+ let eventName;
207
+ for (const line of lines) {
208
+ if (line.startsWith("data:")) {
209
+ dataLines.push(line.replace(/^data:\s*/, ""));
210
+ } else if (line.startsWith("event:")) {
211
+ eventName = line.replace(/^event:\s*/, "");
212
+ } else if (line.startsWith("id:")) {
213
+ lastEventId = line.replace(/^id:\s*/, "");
214
+ } else if (line.startsWith("retry:")) {
215
+ const parsed = Number.parseInt(line.replace(/^retry:\s*/, ""), 10);
216
+ if (!Number.isNaN(parsed)) {
217
+ retryDelay = parsed;
218
+ }
219
+ }
220
+ }
221
+ let data;
222
+ let parsedJson = false;
223
+ if (dataLines.length) {
224
+ const rawData = dataLines.join("\n");
225
+ try {
226
+ data = JSON.parse(rawData);
227
+ parsedJson = true;
228
+ } catch {
229
+ data = rawData;
230
+ }
231
+ }
232
+ if (parsedJson) {
233
+ if (responseValidator) {
234
+ await responseValidator(data);
235
+ }
236
+ if (responseTransformer) {
237
+ data = await responseTransformer(data);
238
+ }
239
+ }
240
+ onSseEvent?.({
241
+ data,
242
+ event: eventName,
243
+ id: lastEventId,
244
+ retry: retryDelay
245
+ });
246
+ if (dataLines.length) {
247
+ yield data;
248
+ }
249
+ }
250
+ }
251
+ } finally {
252
+ signal.removeEventListener("abort", abortHandler);
253
+ reader.releaseLock();
254
+ }
255
+ break;
256
+ } catch (error) {
257
+ onSseError?.(error);
258
+ if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) {
259
+ break;
260
+ }
261
+ const backoff = Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 3e4);
262
+ await sleep(backoff);
263
+ }
264
+ }
265
+ };
266
+ const stream = createStream();
267
+ return { stream };
268
+ }
269
+ var separatorArrayExplode = (style) => {
270
+ switch (style) {
271
+ case "label":
272
+ return ".";
273
+ case "matrix":
274
+ return ";";
275
+ case "simple":
276
+ return ",";
277
+ default:
278
+ return "&";
279
+ }
280
+ };
281
+ var separatorArrayNoExplode = (style) => {
282
+ switch (style) {
283
+ case "form":
284
+ return ",";
285
+ case "pipeDelimited":
286
+ return "|";
287
+ case "spaceDelimited":
288
+ return "%20";
289
+ default:
290
+ return ",";
291
+ }
292
+ };
293
+ var separatorObjectExplode = (style) => {
294
+ switch (style) {
295
+ case "label":
296
+ return ".";
297
+ case "matrix":
298
+ return ";";
299
+ case "simple":
300
+ return ",";
301
+ default:
302
+ return "&";
303
+ }
304
+ };
305
+ var serializeArrayParam = ({
306
+ allowReserved,
307
+ explode,
308
+ name,
309
+ style,
310
+ value
311
+ }) => {
312
+ if (!explode) {
313
+ const joinedValues2 = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
314
+ switch (style) {
315
+ case "label":
316
+ return `.${joinedValues2}`;
317
+ case "matrix":
318
+ return `;${name}=${joinedValues2}`;
319
+ case "simple":
320
+ return joinedValues2;
321
+ default:
322
+ return `${name}=${joinedValues2}`;
323
+ }
324
+ }
325
+ const separator = separatorArrayExplode(style);
326
+ const joinedValues = value.map((v) => {
327
+ if (style === "label" || style === "simple") {
328
+ return allowReserved ? v : encodeURIComponent(v);
329
+ }
330
+ return serializePrimitiveParam({
331
+ allowReserved,
332
+ name,
333
+ value: v
334
+ });
335
+ }).join(separator);
336
+ return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
337
+ };
338
+ var serializePrimitiveParam = ({
339
+ allowReserved,
340
+ name,
341
+ value
342
+ }) => {
343
+ if (value === void 0 || value === null) {
344
+ return "";
345
+ }
346
+ if (typeof value === "object") {
347
+ throw new Error(
348
+ "Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these."
349
+ );
350
+ }
351
+ return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
352
+ };
353
+ var serializeObjectParam = ({
354
+ allowReserved,
355
+ explode,
356
+ name,
357
+ style,
358
+ value,
359
+ valueOnly
360
+ }) => {
361
+ if (value instanceof Date) {
362
+ return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
363
+ }
364
+ if (style !== "deepObject" && !explode) {
365
+ let values = [];
366
+ Object.entries(value).forEach(([key, v]) => {
367
+ values = [...values, key, allowReserved ? v : encodeURIComponent(v)];
368
+ });
369
+ const joinedValues2 = values.join(",");
370
+ switch (style) {
371
+ case "form":
372
+ return `${name}=${joinedValues2}`;
373
+ case "label":
374
+ return `.${joinedValues2}`;
375
+ case "matrix":
376
+ return `;${name}=${joinedValues2}`;
377
+ default:
378
+ return joinedValues2;
379
+ }
380
+ }
381
+ const separator = separatorObjectExplode(style);
382
+ const joinedValues = Object.entries(value).map(
383
+ ([key, v]) => serializePrimitiveParam({
384
+ allowReserved,
385
+ name: style === "deepObject" ? `${name}[${key}]` : key,
386
+ value: v
387
+ })
388
+ ).join(separator);
389
+ return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
390
+ };
391
+ var PATH_PARAM_RE = /\{[^{}]+\}/g;
392
+ var defaultPathSerializer = ({ path, url: _url }) => {
393
+ let url = _url;
394
+ const matches = _url.match(PATH_PARAM_RE);
395
+ if (matches) {
396
+ for (const match of matches) {
397
+ let explode = false;
398
+ let name = match.substring(1, match.length - 1);
399
+ let style = "simple";
400
+ if (name.endsWith("*")) {
401
+ explode = true;
402
+ name = name.substring(0, name.length - 1);
403
+ }
404
+ if (name.startsWith(".")) {
405
+ name = name.substring(1);
406
+ style = "label";
407
+ } else if (name.startsWith(";")) {
408
+ name = name.substring(1);
409
+ style = "matrix";
410
+ }
411
+ const value = path[name];
412
+ if (value === void 0 || value === null) {
413
+ continue;
414
+ }
415
+ if (Array.isArray(value)) {
416
+ url = url.replace(match, serializeArrayParam({ explode, name, style, value }));
417
+ continue;
418
+ }
419
+ if (typeof value === "object") {
420
+ url = url.replace(
421
+ match,
422
+ serializeObjectParam({
423
+ explode,
424
+ name,
425
+ style,
426
+ value,
427
+ valueOnly: true
428
+ })
429
+ );
430
+ continue;
431
+ }
432
+ if (style === "matrix") {
433
+ url = url.replace(
434
+ match,
435
+ `;${serializePrimitiveParam({
436
+ name,
437
+ value
438
+ })}`
439
+ );
440
+ continue;
441
+ }
442
+ const replaceValue = encodeURIComponent(
443
+ style === "label" ? `.${value}` : value
444
+ );
445
+ url = url.replace(match, replaceValue);
446
+ }
447
+ }
448
+ return url;
449
+ };
450
+ var getUrl = ({
451
+ baseUrl,
452
+ path,
453
+ query,
454
+ querySerializer,
455
+ url: _url
456
+ }) => {
457
+ const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
458
+ let url = (baseUrl ?? "") + pathUrl;
459
+ if (path) {
460
+ url = defaultPathSerializer({ path, url });
461
+ }
462
+ let search = query ? querySerializer(query) : "";
463
+ if (search.startsWith("?")) {
464
+ search = search.substring(1);
465
+ }
466
+ if (search) {
467
+ url += `?${search}`;
468
+ }
469
+ return url;
470
+ };
471
+ function getValidRequestBody(options) {
472
+ const hasBody = options.body !== void 0;
473
+ const isSerializedBody = hasBody && options.bodySerializer;
474
+ if (isSerializedBody) {
475
+ if ("serializedBody" in options) {
476
+ const hasSerializedBody = options.serializedBody !== void 0 && options.serializedBody !== "";
477
+ return hasSerializedBody ? options.serializedBody : null;
478
+ }
479
+ return options.body !== "" ? options.body : null;
480
+ }
481
+ if (hasBody) {
482
+ return options.body;
483
+ }
484
+ return void 0;
485
+ }
486
+ var getAuthToken = async (auth, callback) => {
487
+ const token = typeof callback === "function" ? await callback(auth) : callback;
488
+ if (!token) {
489
+ return;
490
+ }
491
+ if (auth.scheme === "bearer") {
492
+ return `Bearer ${token}`;
493
+ }
494
+ if (auth.scheme === "basic") {
495
+ return `Basic ${btoa(token)}`;
496
+ }
497
+ return token;
498
+ };
499
+ var createQuerySerializer = ({
500
+ parameters = {},
501
+ ...args
502
+ } = {}) => {
503
+ const querySerializer = (queryParams) => {
504
+ const search = [];
505
+ if (queryParams && typeof queryParams === "object") {
506
+ for (const name in queryParams) {
507
+ const value = queryParams[name];
508
+ if (value === void 0 || value === null) {
509
+ continue;
510
+ }
511
+ const options = parameters[name] || args;
512
+ if (Array.isArray(value)) {
513
+ const serializedArray = serializeArrayParam({
514
+ allowReserved: options.allowReserved,
515
+ explode: true,
516
+ name,
517
+ style: "form",
518
+ value,
519
+ ...options.array
520
+ });
521
+ if (serializedArray) search.push(serializedArray);
522
+ } else if (typeof value === "object") {
523
+ const serializedObject = serializeObjectParam({
524
+ allowReserved: options.allowReserved,
525
+ explode: true,
526
+ name,
527
+ style: "deepObject",
528
+ value,
529
+ ...options.object
530
+ });
531
+ if (serializedObject) search.push(serializedObject);
532
+ } else {
533
+ const serializedPrimitive = serializePrimitiveParam({
534
+ allowReserved: options.allowReserved,
535
+ name,
536
+ value
537
+ });
538
+ if (serializedPrimitive) search.push(serializedPrimitive);
539
+ }
540
+ }
541
+ }
542
+ return search.join("&");
543
+ };
544
+ return querySerializer;
545
+ };
546
+ var getParseAs = (contentType) => {
547
+ if (!contentType) {
548
+ return "stream";
549
+ }
550
+ const cleanContent = contentType.split(";")[0]?.trim();
551
+ if (!cleanContent) {
552
+ return;
553
+ }
554
+ if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) {
555
+ return "json";
556
+ }
557
+ if (cleanContent === "multipart/form-data") {
558
+ return "formData";
559
+ }
560
+ if (["application/", "audio/", "image/", "video/"].some((type) => cleanContent.startsWith(type))) {
561
+ return "blob";
562
+ }
563
+ if (cleanContent.startsWith("text/")) {
564
+ return "text";
565
+ }
566
+ return;
567
+ };
568
+ var checkForExistence = (options, name) => {
569
+ if (!name) {
570
+ return false;
571
+ }
572
+ if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) {
573
+ return true;
574
+ }
575
+ return false;
576
+ };
577
+ async function setAuthParams(options) {
578
+ for (const auth of options.security ?? []) {
579
+ if (checkForExistence(options, auth.name)) {
580
+ continue;
581
+ }
582
+ const token = await getAuthToken(auth, options.auth);
583
+ if (!token) {
584
+ continue;
585
+ }
586
+ const name = auth.name ?? "Authorization";
587
+ switch (auth.in) {
588
+ case "query":
589
+ if (!options.query) {
590
+ options.query = {};
591
+ }
592
+ options.query[name] = token;
593
+ break;
594
+ case "cookie":
595
+ options.headers.append("Cookie", `${name}=${token}`);
596
+ break;
597
+ case "header":
598
+ default:
599
+ options.headers.set(name, token);
600
+ break;
601
+ }
602
+ }
603
+ }
604
+ var buildUrl = (options) => getUrl({
605
+ baseUrl: options.baseUrl,
606
+ path: options.path,
607
+ query: options.query,
608
+ querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
609
+ url: options.url
610
+ });
611
+ var mergeConfigs = (a, b) => {
612
+ const config = { ...a, ...b };
613
+ if (config.baseUrl?.endsWith("/")) {
614
+ config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
615
+ }
616
+ config.headers = mergeHeaders(a.headers, b.headers);
617
+ return config;
618
+ };
619
+ var headersEntries = (headers) => {
620
+ const entries = [];
621
+ headers.forEach((value, key) => {
622
+ entries.push([key, value]);
623
+ });
624
+ return entries;
625
+ };
626
+ var mergeHeaders = (...headers) => {
627
+ const mergedHeaders = new Headers();
628
+ for (const header of headers) {
629
+ if (!header) {
630
+ continue;
631
+ }
632
+ const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
633
+ for (const [key, value] of iterator) {
634
+ if (value === null) {
635
+ mergedHeaders.delete(key);
636
+ } else if (Array.isArray(value)) {
637
+ for (const v of value) {
638
+ mergedHeaders.append(key, v);
639
+ }
640
+ } else if (value !== void 0) {
641
+ mergedHeaders.set(
642
+ key,
643
+ typeof value === "object" ? JSON.stringify(value) : value
644
+ );
645
+ }
646
+ }
647
+ }
648
+ return mergedHeaders;
649
+ };
650
+ var Interceptors = class {
651
+ fns = [];
652
+ clear() {
653
+ this.fns = [];
654
+ }
655
+ eject(id) {
656
+ const index = this.getInterceptorIndex(id);
657
+ if (this.fns[index]) {
658
+ this.fns[index] = null;
659
+ }
660
+ }
661
+ exists(id) {
662
+ const index = this.getInterceptorIndex(id);
663
+ return Boolean(this.fns[index]);
664
+ }
665
+ getInterceptorIndex(id) {
666
+ if (typeof id === "number") {
667
+ return this.fns[id] ? id : -1;
668
+ }
669
+ return this.fns.indexOf(id);
670
+ }
671
+ update(id, fn) {
672
+ const index = this.getInterceptorIndex(id);
673
+ if (this.fns[index]) {
674
+ this.fns[index] = fn;
675
+ return id;
676
+ }
677
+ return false;
678
+ }
679
+ use(fn) {
680
+ this.fns.push(fn);
681
+ return this.fns.length - 1;
682
+ }
683
+ };
684
+ var createInterceptors = () => ({
685
+ error: new Interceptors(),
686
+ request: new Interceptors(),
687
+ response: new Interceptors()
688
+ });
689
+ var defaultQuerySerializer = createQuerySerializer({
690
+ allowReserved: false,
691
+ array: {
692
+ explode: true,
693
+ style: "form"
694
+ },
695
+ object: {
696
+ explode: true,
697
+ style: "deepObject"
698
+ }
699
+ });
700
+ var defaultHeaders = {
701
+ "Content-Type": "application/json"
702
+ };
703
+ var createConfig = (override = {}) => ({
704
+ ...jsonBodySerializer,
705
+ headers: defaultHeaders,
706
+ parseAs: "auto",
707
+ querySerializer: defaultQuerySerializer,
708
+ ...override
709
+ });
710
+ var createClient = (config = {}) => {
711
+ let _config = mergeConfigs(createConfig(), config);
712
+ const getConfig = () => ({ ..._config });
713
+ const setConfig = (config2) => {
714
+ _config = mergeConfigs(_config, config2);
715
+ return getConfig();
716
+ };
717
+ const interceptors = createInterceptors();
718
+ const beforeRequest = async (options) => {
719
+ const opts = {
720
+ ..._config,
721
+ ...options,
722
+ fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
723
+ headers: mergeHeaders(_config.headers, options.headers),
724
+ serializedBody: void 0
725
+ };
726
+ if (opts.security) {
727
+ await setAuthParams(opts);
728
+ }
729
+ if (opts.requestValidator) {
730
+ await opts.requestValidator(opts);
731
+ }
732
+ if (opts.body !== void 0 && opts.bodySerializer) {
733
+ opts.serializedBody = opts.bodySerializer(opts.body);
734
+ }
735
+ if (opts.body === void 0 || opts.serializedBody === "") {
736
+ opts.headers.delete("Content-Type");
737
+ }
738
+ const resolvedOpts = opts;
739
+ const url = buildUrl(resolvedOpts);
740
+ return { opts: resolvedOpts, url };
741
+ };
742
+ const request = async (options) => {
743
+ const throwOnError = options.throwOnError ?? _config.throwOnError;
744
+ const responseStyle = options.responseStyle ?? _config.responseStyle;
745
+ let request2;
746
+ let response;
747
+ try {
748
+ const { opts, url } = await beforeRequest(options);
749
+ const requestInit = {
750
+ redirect: "follow",
751
+ ...opts,
752
+ body: getValidRequestBody(opts)
753
+ };
754
+ request2 = new Request(url, requestInit);
755
+ for (const fn of interceptors.request.fns) {
756
+ if (fn) {
757
+ request2 = await fn(request2, opts);
758
+ }
759
+ }
760
+ const _fetch = opts.fetch;
761
+ response = await _fetch(request2);
762
+ for (const fn of interceptors.response.fns) {
763
+ if (fn) {
764
+ response = await fn(response, request2, opts);
765
+ }
766
+ }
767
+ const result = {
768
+ request: request2,
769
+ response
770
+ };
771
+ if (response.ok) {
772
+ const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
773
+ if (response.status === 204 || response.headers.get("Content-Length") === "0") {
774
+ let emptyData;
775
+ switch (parseAs) {
776
+ case "arrayBuffer":
777
+ case "blob":
778
+ case "text":
779
+ emptyData = await response[parseAs]();
780
+ break;
781
+ case "formData":
782
+ emptyData = new FormData();
783
+ break;
784
+ case "stream":
785
+ emptyData = response.body;
786
+ break;
787
+ case "json":
788
+ default:
789
+ emptyData = {};
790
+ break;
791
+ }
792
+ return opts.responseStyle === "data" ? emptyData : {
793
+ data: emptyData,
794
+ ...result
795
+ };
796
+ }
797
+ let data;
798
+ switch (parseAs) {
799
+ case "arrayBuffer":
800
+ case "blob":
801
+ case "formData":
802
+ case "text":
803
+ data = await response[parseAs]();
804
+ break;
805
+ case "json": {
806
+ const text = await response.text();
807
+ data = text ? JSON.parse(text) : {};
808
+ break;
809
+ }
810
+ case "stream":
811
+ return opts.responseStyle === "data" ? response.body : {
812
+ data: response.body,
813
+ ...result
814
+ };
815
+ }
816
+ if (parseAs === "json") {
817
+ if (opts.responseValidator) {
818
+ await opts.responseValidator(data);
819
+ }
820
+ if (opts.responseTransformer) {
821
+ data = await opts.responseTransformer(data);
822
+ }
823
+ }
824
+ return opts.responseStyle === "data" ? data : {
825
+ data,
826
+ ...result
827
+ };
828
+ }
829
+ const textError = await response.text();
830
+ let jsonError;
831
+ try {
832
+ jsonError = JSON.parse(textError);
833
+ } catch {
834
+ }
835
+ throw jsonError ?? textError;
836
+ } catch (error) {
837
+ let finalError = error;
838
+ for (const fn of interceptors.error.fns) {
839
+ if (fn) {
840
+ finalError = await fn(finalError, response, request2, options);
841
+ }
842
+ }
843
+ finalError = finalError || {};
844
+ if (throwOnError) {
845
+ throw finalError;
846
+ }
847
+ return responseStyle === "data" ? void 0 : {
848
+ error: finalError,
849
+ request: request2,
850
+ response
851
+ };
852
+ }
853
+ };
854
+ const makeMethodFn = (method) => (options) => request({ ...options, method });
855
+ const makeSseFn = (method) => async (options) => {
856
+ const { opts, url } = await beforeRequest(options);
857
+ return createSseClient({
858
+ ...opts,
859
+ body: opts.body,
860
+ method,
861
+ onRequest: async (url2, init) => {
862
+ let request2 = new Request(url2, init);
863
+ for (const fn of interceptors.request.fns) {
864
+ if (fn) {
865
+ request2 = await fn(request2, opts);
866
+ }
867
+ }
868
+ return request2;
869
+ },
870
+ serializedBody: getValidRequestBody(opts),
871
+ url
872
+ });
873
+ };
874
+ const _buildUrl = (options) => buildUrl({ ..._config, ...options });
875
+ return {
876
+ buildUrl: _buildUrl,
877
+ connect: makeMethodFn("CONNECT"),
878
+ delete: makeMethodFn("DELETE"),
879
+ get: makeMethodFn("GET"),
880
+ getConfig,
881
+ head: makeMethodFn("HEAD"),
882
+ interceptors,
883
+ options: makeMethodFn("OPTIONS"),
884
+ patch: makeMethodFn("PATCH"),
885
+ post: makeMethodFn("POST"),
886
+ put: makeMethodFn("PUT"),
887
+ request,
888
+ setConfig,
889
+ sse: {
890
+ connect: makeSseFn("CONNECT"),
891
+ delete: makeSseFn("DELETE"),
892
+ get: makeSseFn("GET"),
893
+ head: makeSseFn("HEAD"),
894
+ options: makeSseFn("OPTIONS"),
895
+ patch: makeSseFn("PATCH"),
896
+ post: makeSseFn("POST"),
897
+ put: makeSseFn("PUT"),
898
+ trace: makeSseFn("TRACE")
899
+ },
900
+ trace: makeMethodFn("TRACE")
901
+ };
902
+ };
903
+ var client = createClient(
904
+ createConfig({ baseUrl: "https://pidgeon.ai/api/v1" })
905
+ );
906
+ var agentSignUp = (options) => (options.client ?? client).post({
907
+ url: "/agent/signup",
908
+ ...options,
909
+ headers: {
910
+ "Content-Type": "application/json",
911
+ ...options.headers
912
+ }
913
+ });
914
+ var agentAttachHuman = (options) => (options.client ?? client).post({
915
+ url: "/agent/human",
916
+ ...options,
917
+ headers: {
918
+ "Content-Type": "application/json",
919
+ ...options.headers
920
+ }
921
+ });
922
+ var agentVerify = (options) => (options.client ?? client).post({
923
+ url: "/agent/verify",
924
+ ...options,
925
+ headers: {
926
+ "Content-Type": "application/json",
927
+ ...options.headers
928
+ }
929
+ });
930
+ var identitiesList = (options) => (options?.client ?? client).get({
931
+ security: [{ scheme: "bearer", type: "http" }],
932
+ url: "/identities",
933
+ ...options
934
+ });
935
+ var identitiesCreate = (options) => (options.client ?? client).post({
936
+ security: [{ scheme: "bearer", type: "http" }],
937
+ url: "/identities",
938
+ ...options,
939
+ headers: {
940
+ "Content-Type": "application/json",
941
+ ...options.headers
942
+ }
943
+ });
944
+ var identitiesDelete = (options) => (options.client ?? client).delete({
945
+ security: [{ scheme: "bearer", type: "http" }],
946
+ url: "/identities/{id}",
947
+ ...options
948
+ });
949
+ var identitiesGet = (options) => (options.client ?? client).get({
950
+ security: [{ scheme: "bearer", type: "http" }],
951
+ url: "/identities/{id}",
952
+ ...options
953
+ });
954
+ var identitiesUpdate = (options) => (options.client ?? client).patch(
955
+ {
956
+ security: [{ scheme: "bearer", type: "http" }],
957
+ url: "/identities/{id}",
958
+ ...options,
959
+ headers: {
960
+ "Content-Type": "application/json",
961
+ ...options.headers
962
+ }
963
+ }
964
+ );
965
+ var identitiesAccessDelete = (options) => (options.client ?? client).delete({
966
+ security: [{ scheme: "bearer", type: "http" }],
967
+ url: "/identities/{id}/access",
968
+ ...options
969
+ });
970
+ var identitiesAccessGet = (options) => (options.client ?? client).get({
971
+ security: [{ scheme: "bearer", type: "http" }],
972
+ url: "/identities/{id}/access",
973
+ ...options
974
+ });
975
+ var identitiesAccessCreate = (options) => (options.client ?? client).post({
976
+ security: [{ scheme: "bearer", type: "http" }],
977
+ url: "/identities/{id}/access",
978
+ ...options,
979
+ headers: {
980
+ "Content-Type": "application/json",
981
+ ...options.headers
982
+ }
983
+ });
984
+ var identitiesSendRulesDelete = (options) => (options.client ?? client).delete({
985
+ security: [{ scheme: "bearer", type: "http" }],
986
+ url: "/identities/{id}/send-rules",
987
+ ...options
988
+ });
989
+ var identitiesSendRulesGet = (options) => (options.client ?? client).get({
990
+ security: [{ scheme: "bearer", type: "http" }],
991
+ url: "/identities/{id}/send-rules",
992
+ ...options
993
+ });
994
+ var identitiesSendRulesCreate = (options) => (options.client ?? client).post({
995
+ security: [{ scheme: "bearer", type: "http" }],
996
+ url: "/identities/{id}/send-rules",
997
+ ...options,
998
+ headers: {
999
+ "Content-Type": "application/json",
1000
+ ...options.headers
1001
+ }
1002
+ });
1003
+ var identitiesReceiveRulesDelete = (options) => (options.client ?? client).delete({
1004
+ security: [{ scheme: "bearer", type: "http" }],
1005
+ url: "/identities/{id}/receive-rules",
1006
+ ...options
1007
+ });
1008
+ var identitiesReceiveRulesGet = (options) => (options.client ?? client).get({
1009
+ security: [{ scheme: "bearer", type: "http" }],
1010
+ url: "/identities/{id}/receive-rules",
1011
+ ...options
1012
+ });
1013
+ var identitiesReceiveRulesCreate = (options) => (options.client ?? client).post({
1014
+ security: [{ scheme: "bearer", type: "http" }],
1015
+ url: "/identities/{id}/receive-rules",
1016
+ ...options,
1017
+ headers: {
1018
+ "Content-Type": "application/json",
1019
+ ...options.headers
1020
+ }
1021
+ });
1022
+ var identitiesSuspendTenant = (options) => (options.client ?? client).post({
1023
+ security: [{ scheme: "bearer", type: "http" }],
1024
+ url: "/tenants/{id}/suspend",
1025
+ ...options
1026
+ });
1027
+ var labelsList = (options) => (options.client ?? client).get({
1028
+ security: [{ scheme: "bearer", type: "http" }],
1029
+ url: "/labels",
1030
+ ...options
1031
+ });
1032
+ var labelsCreate = (options) => (options.client ?? client).post({
1033
+ security: [{ scheme: "bearer", type: "http" }],
1034
+ url: "/labels",
1035
+ ...options,
1036
+ headers: {
1037
+ "Content-Type": "application/json",
1038
+ ...options.headers
1039
+ }
1040
+ });
1041
+ var labelsDelete = (options) => (options.client ?? client).delete({
1042
+ security: [{ scheme: "bearer", type: "http" }],
1043
+ url: "/labels/{id}",
1044
+ ...options
1045
+ });
1046
+ var labelsUpdate = (options) => (options.client ?? client).patch({
1047
+ security: [{ scheme: "bearer", type: "http" }],
1048
+ url: "/labels/{id}",
1049
+ ...options,
1050
+ headers: {
1051
+ "Content-Type": "application/json",
1052
+ ...options.headers
1053
+ }
1054
+ });
1055
+ var threadsLabelsDelete = (options) => (options.client ?? client).delete({
1056
+ security: [{ scheme: "bearer", type: "http" }],
1057
+ url: "/threads/{id}/labels",
1058
+ ...options
1059
+ });
1060
+ var threadsLabelsGet = (options) => (options.client ?? client).get({
1061
+ security: [{ scheme: "bearer", type: "http" }],
1062
+ url: "/threads/{id}/labels",
1063
+ ...options
1064
+ });
1065
+ var threadsLabelsCreate = (options) => (options.client ?? client).post({
1066
+ security: [{ scheme: "bearer", type: "http" }],
1067
+ url: "/threads/{id}/labels",
1068
+ ...options,
1069
+ headers: {
1070
+ "Content-Type": "application/json",
1071
+ ...options.headers
1072
+ }
1073
+ });
1074
+ var messagesListInThread = (options) => (options.client ?? client).get({
1075
+ security: [{ scheme: "bearer", type: "http" }],
1076
+ url: "/messages",
1077
+ ...options
1078
+ });
1079
+ var messagesSend = (options) => (options.client ?? client).post({
1080
+ security: [{ scheme: "bearer", type: "http" }],
1081
+ url: "/messages",
1082
+ ...options,
1083
+ headers: {
1084
+ "Content-Type": "application/json",
1085
+ ...options.headers
1086
+ }
1087
+ });
1088
+ var messagesSearch = (options) => (options.client ?? client).get({
1089
+ security: [{ scheme: "bearer", type: "http" }],
1090
+ url: "/messages/search",
1091
+ ...options
1092
+ });
1093
+ var messagesAct = (options) => (options.client ?? client).post({
1094
+ security: [{ scheme: "bearer", type: "http" }],
1095
+ url: "/messages/actions",
1096
+ ...options,
1097
+ headers: {
1098
+ "Content-Type": "application/json",
1099
+ ...options.headers
1100
+ }
1101
+ });
1102
+ var messagesUndo = (options) => (options.client ?? client).post({
1103
+ security: [{ scheme: "bearer", type: "http" }],
1104
+ url: "/messages/undo",
1105
+ ...options,
1106
+ headers: {
1107
+ "Content-Type": "application/json",
1108
+ ...options.headers
1109
+ }
1110
+ });
1111
+ var messagesGet = (options) => (options.client ?? client).get({
1112
+ security: [{ scheme: "bearer", type: "http" }],
1113
+ url: "/messages/{id}",
1114
+ ...options
1115
+ });
1116
+ var messagesUpdate = (options) => (options.client ?? client).patch({
1117
+ security: [{ scheme: "bearer", type: "http" }],
1118
+ url: "/messages/{id}",
1119
+ ...options,
1120
+ headers: {
1121
+ "Content-Type": "application/json",
1122
+ ...options.headers
1123
+ }
1124
+ });
1125
+ var messagesReply = (options) => (options.client ?? client).post({
1126
+ security: [{ scheme: "bearer", type: "http" }],
1127
+ url: "/messages/{id}/reply",
1128
+ ...options,
1129
+ headers: {
1130
+ "Content-Type": "application/json",
1131
+ ...options.headers
1132
+ }
1133
+ });
1134
+ var messagesReplyAll = (options) => (options.client ?? client).post({
1135
+ security: [{ scheme: "bearer", type: "http" }],
1136
+ url: "/messages/{id}/reply-all",
1137
+ ...options,
1138
+ headers: {
1139
+ "Content-Type": "application/json",
1140
+ ...options.headers
1141
+ }
1142
+ });
1143
+ var messagesForward = (options) => (options.client ?? client).post({
1144
+ security: [{ scheme: "bearer", type: "http" }],
1145
+ url: "/messages/{id}/forward",
1146
+ ...options,
1147
+ headers: {
1148
+ "Content-Type": "application/json",
1149
+ ...options.headers
1150
+ }
1151
+ });
1152
+ var messagesRaw = (options) => (options.client ?? client).get({
1153
+ security: [{ scheme: "bearer", type: "http" }],
1154
+ url: "/messages/{id}/raw",
1155
+ ...options
1156
+ });
1157
+ var threadsList = (options) => (options?.client ?? client).get({
1158
+ security: [{ scheme: "bearer", type: "http" }],
1159
+ url: "/threads",
1160
+ ...options
1161
+ });
1162
+ var threadsGet = (options) => (options.client ?? client).get({
1163
+ security: [{ scheme: "bearer", type: "http" }],
1164
+ url: "/threads/{id}",
1165
+ ...options
1166
+ });
1167
+ var threadsUpdate = (options) => (options.client ?? client).patch({
1168
+ security: [{ scheme: "bearer", type: "http" }],
1169
+ url: "/threads/{id}",
1170
+ ...options,
1171
+ headers: {
1172
+ "Content-Type": "application/json",
1173
+ ...options.headers
1174
+ }
1175
+ });
1176
+ var domainsList = (options) => (options?.client ?? client).get({
1177
+ security: [{ scheme: "bearer", type: "http" }],
1178
+ url: "/domains",
1179
+ ...options
1180
+ });
1181
+ var domainsCreate = (options) => (options.client ?? client).post({
1182
+ security: [{ scheme: "bearer", type: "http" }],
1183
+ url: "/domains",
1184
+ ...options,
1185
+ headers: {
1186
+ "Content-Type": "application/json",
1187
+ ...options.headers
1188
+ }
1189
+ });
1190
+ var domainsZoneFile = (options) => (options.client ?? client).get({
1191
+ security: [{ scheme: "bearer", type: "http" }],
1192
+ url: "/domains/{id}/zone-file",
1193
+ ...options
1194
+ });
1195
+ var domainsGetSetupLink = (options) => (options.client ?? client).get({
1196
+ security: [{ scheme: "bearer", type: "http" }],
1197
+ url: "/domains/{id}/setup-link",
1198
+ ...options
1199
+ });
1200
+ var domainsVerify = (options) => (options.client ?? client).post({
1201
+ security: [{ scheme: "bearer", type: "http" }],
1202
+ url: "/domains/{id}/verify",
1203
+ ...options
1204
+ });
1205
+ var domainsDelete = (options) => (options.client ?? client).delete({
1206
+ security: [{ scheme: "bearer", type: "http" }],
1207
+ url: "/domains/{id}",
1208
+ ...options
1209
+ });
1210
+ var domainsGet = (options) => (options.client ?? client).get({
1211
+ security: [{ scheme: "bearer", type: "http" }],
1212
+ url: "/domains/{id}",
1213
+ ...options
1214
+ });
1215
+ var domainsUpdate = (options) => (options.client ?? client).patch({
1216
+ security: [{ scheme: "bearer", type: "http" }],
1217
+ url: "/domains/{id}",
1218
+ ...options,
1219
+ headers: {
1220
+ "Content-Type": "application/json",
1221
+ ...options.headers
1222
+ }
1223
+ });
1224
+ var routingList = (options) => (options?.client ?? client).get({
1225
+ security: [{ scheme: "bearer", type: "http" }],
1226
+ url: "/routing-rules",
1227
+ ...options
1228
+ });
1229
+ var routingCreate = (options) => (options.client ?? client).post({
1230
+ security: [{ scheme: "bearer", type: "http" }],
1231
+ url: "/routing-rules",
1232
+ ...options,
1233
+ headers: {
1234
+ "Content-Type": "application/json",
1235
+ ...options.headers
1236
+ }
1237
+ });
1238
+ var routingDelete = (options) => (options.client ?? client).delete({
1239
+ security: [{ scheme: "bearer", type: "http" }],
1240
+ url: "/routing-rules/{id}",
1241
+ ...options
1242
+ });
1243
+ var routingUpdate = (options) => (options.client ?? client).patch({
1244
+ security: [{ scheme: "bearer", type: "http" }],
1245
+ url: "/routing-rules/{id}",
1246
+ ...options,
1247
+ headers: {
1248
+ "Content-Type": "application/json",
1249
+ ...options.headers
1250
+ }
1251
+ });
1252
+ var mailboxesList = (options) => (options.client ?? client).get({
1253
+ security: [{ scheme: "bearer", type: "http" }],
1254
+ url: "/mailboxes",
1255
+ ...options
1256
+ });
1257
+ var mailboxesChanges = (options) => (options.client ?? client).get({
1258
+ security: [{ scheme: "bearer", type: "http" }],
1259
+ url: "/mailboxes/changes",
1260
+ ...options
1261
+ });
1262
+ var mailboxesEmptyTrash = (options) => (options.client ?? client).delete({
1263
+ security: [{ scheme: "bearer", type: "http" }],
1264
+ url: "/mailboxes/{folder}",
1265
+ ...options
1266
+ });
1267
+ var mailboxesListFolder = (options) => (options.client ?? client).get({
1268
+ security: [{ scheme: "bearer", type: "http" }],
1269
+ url: "/mailboxes/{folder}",
1270
+ ...options
1271
+ });
1272
+ var keysList = (options) => (options?.client ?? client).get({
1273
+ security: [{ scheme: "bearer", type: "http" }],
1274
+ url: "/api-keys",
1275
+ ...options
1276
+ });
1277
+ var keysCreate = (options) => (options.client ?? client).post({
1278
+ security: [{ scheme: "bearer", type: "http" }],
1279
+ url: "/api-keys",
1280
+ ...options,
1281
+ headers: {
1282
+ "Content-Type": "application/json",
1283
+ ...options.headers
1284
+ }
1285
+ });
1286
+ var keysRevoke = (options) => (options.client ?? client).delete({
1287
+ security: [{ scheme: "bearer", type: "http" }],
1288
+ url: "/api-keys/{id}",
1289
+ ...options
1290
+ });
1291
+ var keysGet = (options) => (options.client ?? client).get({
1292
+ security: [{ scheme: "bearer", type: "http" }],
1293
+ url: "/api-keys/{id}",
1294
+ ...options
1295
+ });
1296
+ var keysUpdate = (options) => (options.client ?? client).patch({
1297
+ security: [{ scheme: "bearer", type: "http" }],
1298
+ url: "/api-keys/{id}",
1299
+ ...options,
1300
+ headers: {
1301
+ "Content-Type": "application/json",
1302
+ ...options.headers
1303
+ }
1304
+ });
1305
+ var appPasswordsList = (options) => (options.client ?? client).get({
1306
+ security: [{ scheme: "bearer", type: "http" }],
1307
+ url: "/app-passwords",
1308
+ ...options
1309
+ });
1310
+ var appPasswordsCreate = (options) => (options.client ?? client).post({
1311
+ security: [{ scheme: "bearer", type: "http" }],
1312
+ url: "/app-passwords",
1313
+ ...options,
1314
+ headers: {
1315
+ "Content-Type": "application/json",
1316
+ ...options.headers
1317
+ }
1318
+ });
1319
+ var appPasswordsRevoke = (options) => (options.client ?? client).delete({
1320
+ security: [{ scheme: "bearer", type: "http" }],
1321
+ url: "/app-passwords/{id}",
1322
+ ...options
1323
+ });
1324
+ var workspaceGet = (options) => (options?.client ?? client).get({
1325
+ security: [{ scheme: "bearer", type: "http" }],
1326
+ url: "/workspace",
1327
+ ...options
1328
+ });
1329
+ var workspaceMembers = (options) => (options?.client ?? client).get({
1330
+ security: [{ scheme: "bearer", type: "http" }],
1331
+ url: "/workspace/members",
1332
+ ...options
1333
+ });
1334
+ var eventsList = (options) => (options?.client ?? client).get({
1335
+ security: [{ scheme: "bearer", type: "http" }],
1336
+ url: "/events",
1337
+ ...options
1338
+ });
1339
+ var eventsGet = (options) => (options.client ?? client).get({
1340
+ security: [{ scheme: "bearer", type: "http" }],
1341
+ url: "/events/{id}",
1342
+ ...options
1343
+ });
1344
+ var webhooksList = (options) => (options?.client ?? client).get({
1345
+ security: [{ scheme: "bearer", type: "http" }],
1346
+ url: "/webhooks",
1347
+ ...options
1348
+ });
1349
+ var webhooksCreate = (options) => (options.client ?? client).post({
1350
+ security: [{ scheme: "bearer", type: "http" }],
1351
+ url: "/webhooks",
1352
+ ...options,
1353
+ headers: {
1354
+ "Content-Type": "application/json",
1355
+ ...options.headers
1356
+ }
1357
+ });
1358
+ var webhooksDelete = (options) => (options.client ?? client).delete({
1359
+ security: [{ scheme: "bearer", type: "http" }],
1360
+ url: "/webhooks/{id}",
1361
+ ...options
1362
+ });
1363
+ var webhooksGet = (options) => (options.client ?? client).get({
1364
+ security: [{ scheme: "bearer", type: "http" }],
1365
+ url: "/webhooks/{id}",
1366
+ ...options
1367
+ });
1368
+ var webhooksUpdate = (options) => (options.client ?? client).patch({
1369
+ security: [{ scheme: "bearer", type: "http" }],
1370
+ url: "/webhooks/{id}",
1371
+ ...options,
1372
+ headers: {
1373
+ "Content-Type": "application/json",
1374
+ ...options.headers
1375
+ }
1376
+ });
1377
+ var webhooksGetHeaders = (options) => (options.client ?? client).get({
1378
+ security: [{ scheme: "bearer", type: "http" }],
1379
+ url: "/webhooks/{id}/headers",
1380
+ ...options
1381
+ });
1382
+ var webhooksUpdateHeaders = (options) => (options.client ?? client).put({
1383
+ security: [{ scheme: "bearer", type: "http" }],
1384
+ url: "/webhooks/{id}/headers",
1385
+ ...options,
1386
+ headers: {
1387
+ "Content-Type": "application/json",
1388
+ ...options.headers
1389
+ }
1390
+ });
1391
+ var webhooksDeliveries = (options) => (options.client ?? client).get({
1392
+ security: [{ scheme: "bearer", type: "http" }],
1393
+ url: "/deliveries",
1394
+ ...options
1395
+ });
1396
+ var webhooksReplay = (options) => (options.client ?? client).post({
1397
+ security: [{ scheme: "bearer", type: "http" }],
1398
+ url: "/deliveries/{id}/replay",
1399
+ ...options
1400
+ });
1401
+ var messagesRespondToInvitation = (options) => (options.client ?? client).post({
1402
+ security: [{ scheme: "bearer", type: "http" }],
1403
+ url: "/messages/{id}/invitation/respond",
1404
+ ...options,
1405
+ headers: {
1406
+ "Content-Type": "application/json",
1407
+ ...options.headers
1408
+ }
1409
+ });
1410
+ var calendarGet = (options) => (options.client ?? client).get({
1411
+ security: [{ scheme: "bearer", type: "http" }],
1412
+ url: "/identities/{id}/calendar",
1413
+ ...options
1414
+ });
1415
+ var calendarUpdate = (options) => (options.client ?? client).patch({
1416
+ security: [{ scheme: "bearer", type: "http" }],
1417
+ url: "/identities/{id}/calendar",
1418
+ ...options,
1419
+ headers: {
1420
+ "Content-Type": "application/json",
1421
+ ...options.headers
1422
+ }
1423
+ });
1424
+ var calendarListEvents = (options) => (options.client ?? client).get({
1425
+ security: [{ scheme: "bearer", type: "http" }],
1426
+ url: "/identities/{id}/calendar/events",
1427
+ ...options
1428
+ });
1429
+ var calendarCreateEvent = (options) => (options.client ?? client).post({
1430
+ security: [{ scheme: "bearer", type: "http" }],
1431
+ url: "/identities/{id}/calendar/events",
1432
+ ...options,
1433
+ headers: {
1434
+ "Content-Type": "application/json",
1435
+ ...options.headers
1436
+ }
1437
+ });
1438
+ var calendarRespondToEvent = (options) => (options.client ?? client).post({
1439
+ security: [{ scheme: "bearer", type: "http" }],
1440
+ url: "/identities/{id}/calendar/events/{eventId}/respond",
1441
+ ...options,
1442
+ headers: {
1443
+ "Content-Type": "application/json",
1444
+ ...options.headers
1445
+ }
1446
+ });
1447
+ var calendarListEventInstances = (options) => (options.client ?? client).get({
1448
+ security: [{ scheme: "bearer", type: "http" }],
1449
+ url: "/identities/{id}/calendar/events/{eventId}/instances",
1450
+ ...options
1451
+ });
1452
+ var calendarGetAgenda = (options) => (options.client ?? client).get(
1453
+ {
1454
+ security: [{ scheme: "bearer", type: "http" }],
1455
+ url: "/identities/{id}/calendar/agenda",
1456
+ ...options
1457
+ }
1458
+ );
1459
+ var calendarDeleteEvent = (options) => (options.client ?? client).delete({
1460
+ security: [{ scheme: "bearer", type: "http" }],
1461
+ url: "/identities/{id}/calendar/events/{eventId}",
1462
+ ...options
1463
+ });
1464
+ var calendarGetEvent = (options) => (options.client ?? client).get({
1465
+ security: [{ scheme: "bearer", type: "http" }],
1466
+ url: "/identities/{id}/calendar/events/{eventId}",
1467
+ ...options
1468
+ });
1469
+ var calendarUpdateEvent = (options) => (options.client ?? client).patch({
1470
+ security: [{ scheme: "bearer", type: "http" }],
1471
+ url: "/identities/{id}/calendar/events/{eventId}",
1472
+ ...options,
1473
+ headers: {
1474
+ "Content-Type": "application/json",
1475
+ ...options.headers
1476
+ }
1477
+ });
1478
+ var draftsList = (options) => (options.client ?? client).get({
1479
+ security: [{ scheme: "bearer", type: "http" }],
1480
+ url: "/drafts",
1481
+ ...options
1482
+ });
1483
+ var draftsCreate = (options) => (options.client ?? client).post({
1484
+ security: [{ scheme: "bearer", type: "http" }],
1485
+ url: "/drafts",
1486
+ ...options,
1487
+ headers: {
1488
+ "Content-Type": "application/json",
1489
+ ...options.headers
1490
+ }
1491
+ });
1492
+ var draftsDelete = (options) => (options.client ?? client).delete({
1493
+ security: [{ scheme: "bearer", type: "http" }],
1494
+ url: "/drafts/{id}",
1495
+ ...options
1496
+ });
1497
+ var draftsGet = (options) => (options.client ?? client).get({
1498
+ security: [{ scheme: "bearer", type: "http" }],
1499
+ url: "/drafts/{id}",
1500
+ ...options
1501
+ });
1502
+ var draftsUpdate = (options) => (options.client ?? client).patch({
1503
+ security: [{ scheme: "bearer", type: "http" }],
1504
+ url: "/drafts/{id}",
1505
+ ...options,
1506
+ headers: {
1507
+ "Content-Type": "application/json",
1508
+ ...options.headers
1509
+ }
1510
+ });
1511
+ var draftsSend = (options) => (options.client ?? client).post({
1512
+ security: [{ scheme: "bearer", type: "http" }],
1513
+ url: "/drafts/{id}/send",
1514
+ ...options
1515
+ });
1516
+ var draftsCancelSchedule = (options) => (options.client ?? client).delete({
1517
+ security: [{ scheme: "bearer", type: "http" }],
1518
+ url: "/drafts/{id}/schedule",
1519
+ ...options
1520
+ });
1521
+ var draftsSchedule = (options) => (options.client ?? client).post({
1522
+ security: [{ scheme: "bearer", type: "http" }],
1523
+ url: "/drafts/{id}/schedule",
1524
+ ...options,
1525
+ headers: {
1526
+ "Content-Type": "application/json",
1527
+ ...options.headers
1528
+ }
1529
+ });
1530
+ var draftsRemoveAttachment = (options) => (options.client ?? client).delete({
1531
+ security: [{ scheme: "bearer", type: "http" }],
1532
+ url: "/drafts/{id}/attachments/{attachmentId}",
1533
+ ...options
1534
+ });
1535
+ var metricsQuery = (options) => (options?.client ?? client).get({
1536
+ security: [{ scheme: "bearer", type: "http" }],
1537
+ url: "/metrics",
1538
+ ...options
1539
+ });
1540
+ var attachmentsUpload = (options) => (options.client ?? client).post({
1541
+ ...formDataBodySerializer,
1542
+ security: [{ scheme: "bearer", type: "http" }],
1543
+ url: "/attachments",
1544
+ ...options,
1545
+ headers: {
1546
+ "Content-Type": null,
1547
+ ...options.headers
1548
+ }
1549
+ });
1550
+ var attachmentsDownloadUrl = (options) => (options.client ?? client).get({
1551
+ security: [{ scheme: "bearer", type: "http" }],
1552
+ url: "/attachments/{id}",
1553
+ ...options
1554
+ });
1555
+ var SIGNATURE_HEADER = "x-pidgeon-signature";
1556
+ var TIMESTAMP_HEADER = "x-pidgeon-timestamp";
1557
+ async function verifyWebhook(input) {
1558
+ const get = (name) => input.headers instanceof Headers ? input.headers.get(name) ?? void 0 : input.headers[name] ?? input.headers[name.toLowerCase()];
1559
+ const timestamp = get(TIMESTAMP_HEADER);
1560
+ const signature = get(SIGNATURE_HEADER);
1561
+ if (!timestamp || !signature) throw new Error("This request is not signed.");
1562
+ const seconds = Number(timestamp);
1563
+ if (!Number.isFinite(seconds)) throw new Error("The signature timestamp is not a number.");
1564
+ const now = Math.floor((input.now ?? /* @__PURE__ */ new Date()).getTime() / 1e3);
1565
+ const tolerance = input.toleranceSeconds ?? 300;
1566
+ if (Math.abs(now - seconds) > tolerance) {
1567
+ throw new Error("This request is too old to trust. It may be a replay.");
1568
+ }
1569
+ const key = await crypto.subtle.importKey(
1570
+ "raw",
1571
+ new TextEncoder().encode(input.secret),
1572
+ { name: "HMAC", hash: "SHA-256" },
1573
+ false,
1574
+ ["sign"]
1575
+ );
1576
+ const mac = await crypto.subtle.sign(
1577
+ "HMAC",
1578
+ key,
1579
+ new TextEncoder().encode(`${seconds}.${input.rawBody}`)
1580
+ );
1581
+ const expected = `v1=${[...new Uint8Array(mac)].map((byte) => byte.toString(16).padStart(2, "0")).join("")}`;
1582
+ if (!constantTimeEqual(expected, signature)) {
1583
+ throw new Error("The signature does not match.");
1584
+ }
1585
+ return JSON.parse(input.rawBody);
1586
+ }
1587
+ function constantTimeEqual(a, b) {
1588
+ if (a.length !== b.length) return false;
1589
+ let difference = 0;
1590
+ for (let index = 0; index < a.length; index += 1) {
1591
+ difference |= a.charCodeAt(index) ^ b.charCodeAt(index);
1592
+ }
1593
+ return difference === 0;
1594
+ }
1595
+
1596
+ // src/index.ts
1597
+ var DEFAULT_BASE_URL = "https://pidgeon.ai/api/v1";
1598
+ var UsageError = class extends Error {
1599
+ };
1600
+ function coerce(flag, raw) {
1601
+ if (flag.kind === "number") {
1602
+ const value = Number(raw);
1603
+ if (Number.isNaN(value)) throw new UsageError(`--${flag.name} takes a number, not "${raw}".`);
1604
+ return value;
1605
+ }
1606
+ if (flag.kind === "json") {
1607
+ try {
1608
+ return JSON.parse(raw);
1609
+ } catch {
1610
+ throw new UsageError(`--${flag.name} takes JSON, and that did not parse.`);
1611
+ }
1612
+ }
1613
+ return raw;
1614
+ }
1615
+ function parse(command, argv) {
1616
+ const byName = new Map(command.flags.map((flag) => [flag.name, flag]));
1617
+ const out = { path: {}, query: {}, body: {} };
1618
+ for (let i = 0; i < argv.length; i++) {
1619
+ const token = argv[i];
1620
+ if (!token.startsWith("--")) throw new UsageError(`Unexpected argument "${token}".`);
1621
+ const [name, inline] = token.slice(2).split(/=([\s\S]*)/, 2);
1622
+ const flag = byName.get(name);
1623
+ if (!flag) {
1624
+ throw new UsageError(
1625
+ `\`${command.group} ${command.name}\` has no --${name}. Try \`pidgeon ${command.group} ${command.name} --help\`.`
1626
+ );
1627
+ }
1628
+ if (flag.kind === "boolean") {
1629
+ out[flag.where][name] = inline === void 0 ? true : inline === "true";
1630
+ continue;
1631
+ }
1632
+ const raw = inline ?? argv[++i];
1633
+ if (raw === void 0) throw new UsageError(`--${name} needs a value.`);
1634
+ if (flag.kind === "list") {
1635
+ const existing = out[flag.where][name] ?? [];
1636
+ out[flag.where][name] = [...existing, raw];
1637
+ continue;
1638
+ }
1639
+ out[flag.where][name] = coerce(flag, raw);
1640
+ }
1641
+ const missing = command.flags.filter((flag) => flag.required).filter((flag) => out[flag.where][flag.name] === void 0).map((flag) => `--${flag.name}`);
1642
+ if (missing.length > 0) {
1643
+ throw new UsageError(`\`${command.group} ${command.name}\` needs ${missing.join(", ")}.`);
1644
+ }
1645
+ return out;
1646
+ }
1647
+ function help(command) {
1648
+ if (!command) {
1649
+ const groups = [...new Set(COMMANDS.map((c) => c.group))].sort();
1650
+ return [
1651
+ "pidgeon <group> <command> [--flags]",
1652
+ "",
1653
+ "Groups:",
1654
+ ...groups.map((group) => {
1655
+ const names = COMMANDS.filter((c) => c.group === group).map((c) => c.name);
1656
+ return ` ${group.padEnd(14)}${names.join(", ")}`;
1657
+ }),
1658
+ "",
1659
+ "An API key goes in PIDGEON_API_KEY. `pidgeon <group> <command> --help`",
1660
+ "describes one command."
1661
+ ].join("\n");
1662
+ }
1663
+ const flags = command.flags.map((flag) => {
1664
+ const label = ` --${flag.name}${flag.kind === "boolean" ? "" : ` <${flag.kind}>`}`;
1665
+ const note = [flag.required ? "required" : null, flag.describe].filter(Boolean).join(" \u2014 ");
1666
+ return note ? `${label.padEnd(34)}${note}` : label;
1667
+ });
1668
+ return [
1669
+ `pidgeon ${command.group} ${command.name} [--flags]`,
1670
+ "",
1671
+ ` ${command.summary}`,
1672
+ ` ${command.method} ${command.path}`,
1673
+ "",
1674
+ ...flags.length > 0 ? ["Flags:", ...flags] : ["Takes no flags."]
1675
+ ].join("\n");
1676
+ }
1677
+ function find(group, name) {
1678
+ return COMMANDS.find((c) => c.group === group && c.name === name);
1679
+ }
1680
+ async function run(argv, env) {
1681
+ const [group, name, ...rest] = argv;
1682
+ if (!group || group === "--help" || group === "help") return help();
1683
+ const command = find(group, name);
1684
+ if (!command) {
1685
+ const known = COMMANDS.filter((c) => c.group === group);
1686
+ if (known.length === 0) throw new UsageError(`No such group "${group}".
1687
+
1688
+ ${help()}`);
1689
+ throw new UsageError(
1690
+ `\`${group}\` has no "${name ?? ""}" command. It has: ${known.map((c) => c.name).join(", ")}.`
1691
+ );
1692
+ }
1693
+ if (rest.includes("--help")) return help(command);
1694
+ const apiKey = env.PIDGEON_API_KEY;
1695
+ if (!apiKey) {
1696
+ throw new UsageError(
1697
+ "PIDGEON_API_KEY is not set. Create a key at https://pidgeon.ai/app/developers/keys."
1698
+ );
1699
+ }
1700
+ const parsed = parse(command, rest);
1701
+ client.setConfig(
1702
+ createConfig({ baseUrl: env.PIDGEON_BASE_URL ?? DEFAULT_BASE_URL, auth: () => apiKey })
1703
+ );
1704
+ const call = dist_exports[command.operationId];
1705
+ if (typeof call !== "function") {
1706
+ throw new Error(`The SDK does not export \`${command.operationId}\`. Run \`pnpm sdk\`.`);
1707
+ }
1708
+ const { data, error, response } = await call({
1709
+ ...Object.keys(parsed.path).length > 0 ? { path: parsed.path } : {},
1710
+ ...Object.keys(parsed.query).length > 0 ? { query: parsed.query } : {},
1711
+ ...Object.keys(parsed.body).length > 0 ? { body: parsed.body } : {}
1712
+ });
1713
+ if (error !== void 0) {
1714
+ const detail = error.error;
1715
+ throw new UsageError(detail?.message ?? `The request failed with ${response.status}.`);
1716
+ }
1717
+ return JSON.stringify(data, null, 2);
1718
+ }
1719
+
1720
+ export {
1721
+ UsageError,
1722
+ parse,
1723
+ help,
1724
+ find,
1725
+ run
1726
+ };
1727
+ //# sourceMappingURL=chunk-ODQKQOJ7.js.map