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