agentmail 0.2.17 → 0.2.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,681 +0,0 @@
1
- # Agentmail TypeScript Library
2
-
3
- [![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-Built%20with%20Fern-brightgreen)](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=https%3A%2F%2Fgithub.com%2Fagentmail-to%2Fagentmail-node)
4
- [![npm shield](https://img.shields.io/npm/v/agentmail)](https://www.npmjs.com/package/agentmail)
5
-
6
- The Agentmail TypeScript library provides convenient access to the Agentmail APIs from TypeScript.
7
-
8
- ## Table of Contents
9
-
10
- - [Installation](#installation)
11
- - [Reference](#reference)
12
- - [Usage](#usage)
13
- - [Request and Response Types](#request-and-response-types)
14
- - [Exception Handling](#exception-handling)
15
- - [Pagination](#pagination)
16
- - [Advanced](#advanced)
17
- - [Additional Headers](#additional-headers)
18
- - [Additional Query String Parameters](#additional-query-string-parameters)
19
- - [Retries](#retries)
20
- - [Timeouts](#timeouts)
21
- - [Aborting Requests](#aborting-requests)
22
- - [Access Raw Response Data](#access-raw-response-data)
23
- - [Logging](#logging)
24
- - [Runtime Compatibility](#runtime-compatibility)
25
- - [Contributing](#contributing)
26
- - [Binary Response](#binary-response)
27
-
28
- ## Installation
29
-
30
- ```sh
31
- npm i -s agentmail
32
- ```
33
-
34
- ## Reference
35
-
36
- A full reference for this library is available [here](https://github.com/agentmail-to/agentmail-node/blob/HEAD/./reference.md).
37
-
38
- ## Usage
39
-
40
- Instantiate and use the client with the following:
41
-
42
- ```typescript
43
- import { AgentMailClient } from "agentmail";
44
-
45
- const client = new AgentMailClient({ apiKey: "YOUR_API_KEY" });
46
- await client.inboxes.create(undefined);
47
- ```
48
-
49
- ## Request and Response Types
50
-
51
- The SDK exports all request and response types as TypeScript interfaces. Simply import them with the
52
- following namespace:
53
-
54
- ```typescript
55
- import { AgentMail } from "agentmail";
56
-
57
- const request: AgentMail.ListInboxesRequest = {
58
- ...
59
- };
60
- ```
61
-
62
- ## Exception Handling
63
-
64
- When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error
65
- will be thrown.
66
-
67
- ```typescript
68
- import { AgentMailError } from "agentmail";
69
-
70
- try {
71
- await client.inboxes.create(...);
72
- } catch (err) {
73
- if (err instanceof AgentMailError) {
74
- console.log(err.statusCode);
75
- console.log(err.message);
76
- console.log(err.body);
77
- console.log(err.rawResponse);
78
- }
79
- }
80
- ```
81
-
82
- ## Pagination
83
-
84
- List endpoints are paginated. The SDK provides an iterator so that you can simply loop over the items:
85
-
86
- ```typescript
87
- import { AgentMailClient } from "agentmail";
88
-
89
- const client = new AgentMailClient({ apiKey: "YOUR_API_KEY" });
90
- const pageableResponse = await client.inboxes.list();
91
- for await (const item of pageableResponse) {
92
- console.log(item);
93
- }
94
-
95
- // Or you can manually iterate page-by-page
96
- let page = await client.inboxes.list();
97
- while (page.hasNextPage()) {
98
- page = page.getNextPage();
99
- }
100
-
101
- // You can also access the underlying response
102
- const response = page.response;
103
- ```
104
-
105
- ## Advanced
106
-
107
- ### Additional Headers
108
-
109
- If you would like to send additional headers as part of the request, use the `headers` request option.
110
-
111
- ```typescript
112
- import { AgentMailClient } from "agentmail";
113
-
114
- const client = new AgentMailClient({
115
- ...
116
- headers: {
117
- 'X-Custom-Header': 'custom value'
118
- }
119
- });
120
-
121
- const response = await client.inboxes.create(..., {
122
- headers: {
123
- 'X-Custom-Header': 'custom value'
124
- }
125
- });
126
- ```
127
-
128
- ### Additional Query String Parameters
129
-
130
- If you would like to send additional query string parameters as part of the request, use the `queryParams` request option.
131
-
132
- ```typescript
133
- const response = await client.inboxes.create(..., {
134
- queryParams: {
135
- 'customQueryParamKey': 'custom query param value'
136
- }
137
- });
138
- ```
139
-
140
- ### Retries
141
-
142
- The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long
143
- as the request is deemed retryable and the number of retry attempts has not grown larger than the configured
144
- retry limit (default: 2).
145
-
146
- A request is deemed retryable when any of the following HTTP status codes is returned:
147
-
148
- - [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
149
- - [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
150
- - [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) (Internal Server Errors)
151
-
152
- Use the `maxRetries` request option to configure this behavior.
153
-
154
- ```typescript
155
- const response = await client.inboxes.create(..., {
156
- maxRetries: 0 // override maxRetries at the request level
157
- });
158
- ```
159
-
160
- ### Timeouts
161
-
162
- The SDK defaults to a 60 second timeout. Use the `timeoutInSeconds` option to configure this behavior.
163
-
164
- ```typescript
165
- const response = await client.inboxes.create(..., {
166
- timeoutInSeconds: 30 // override timeout to 30s
167
- });
168
- ```
169
-
170
- ### Aborting Requests
171
-
172
- The SDK allows users to abort requests at any point by passing in an abort signal.
173
-
174
- ```typescript
175
- const controller = new AbortController();
176
- const response = await client.inboxes.create(..., {
177
- abortSignal: controller.signal
178
- });
179
- controller.abort(); // aborts the request
180
- ```
181
-
182
- ### Access Raw Response Data
183
-
184
- The SDK provides access to raw response data, including headers, through the `.withRawResponse()` method.
185
- The `.withRawResponse()` method returns a promise that results to an object with a `data` and a `rawResponse` property.
186
-
187
- ```typescript
188
- const { data, rawResponse } = await client.inboxes.create(...).withRawResponse();
189
-
190
- console.log(data);
191
- console.log(rawResponse.headers['X-My-Header']);
192
- ```
193
-
194
- ### Logging
195
-
196
- The SDK supports logging. You can configure the logger by passing in a `logging` object to the client options.
197
-
198
- ```typescript
199
- import { AgentMailClient, logging } from "agentmail";
200
-
201
- const client = new AgentMailClient({
202
- ...
203
- logging: {
204
- level: logging.LogLevel.Debug, // defaults to logging.LogLevel.Info
205
- logger: new logging.ConsoleLogger(), // defaults to ConsoleLogger
206
- silent: false, // defaults to true, set to false to enable logging
207
- }
208
- });
209
- ```
210
- The `logging` object can have the following properties:
211
- - `level`: The log level to use. Defaults to `logging.LogLevel.Info`.
212
- - `logger`: The logger to use. Defaults to a `logging.ConsoleLogger`.
213
- - `silent`: Whether to silence the logger. Defaults to `true`.
214
-
215
- The `level` property can be one of the following values:
216
- - `logging.LogLevel.Debug`
217
- - `logging.LogLevel.Info`
218
- - `logging.LogLevel.Warn`
219
- - `logging.LogLevel.Error`
220
-
221
- To provide a custom logger, you can pass in an object that implements the `logging.ILogger` interface.
222
-
223
- <details>
224
- <summary>Custom logger examples</summary>
225
-
226
- Here's an example using the popular `winston` logging library.
227
- ```ts
228
- import winston from 'winston';
229
-
230
- const winstonLogger = winston.createLogger({...});
231
-
232
- const logger: logging.ILogger = {
233
- debug: (msg, ...args) => winstonLogger.debug(msg, ...args),
234
- info: (msg, ...args) => winstonLogger.info(msg, ...args),
235
- warn: (msg, ...args) => winstonLogger.warn(msg, ...args),
236
- error: (msg, ...args) => winstonLogger.error(msg, ...args),
237
- };
238
- ```
239
-
240
- Here's an example using the popular `pino` logging library.
241
-
242
- ```ts
243
- import pino from 'pino';
244
-
245
- const pinoLogger = pino({...});
246
-
247
- const logger: logging.ILogger = {
248
- debug: (msg, ...args) => pinoLogger.debug(args, msg),
249
- info: (msg, ...args) => pinoLogger.info(args, msg),
250
- warn: (msg, ...args) => pinoLogger.warn(args, msg),
251
- error: (msg, ...args) => pinoLogger.error(args, msg),
252
- };
253
- ```
254
- </details>
255
-
256
-
257
- ### Runtime Compatibility
258
-
259
-
260
- The SDK works in the following runtimes:
261
-
262
-
263
-
264
- - Node.js 18+
265
- - Vercel
266
- - Cloudflare Workers
267
- - Deno v1.25+
268
- - Bun 1.0+
269
- - React Native
270
-
271
- ### Customizing Fetch Client
272
-
273
- The SDK provides a way for you to customize the underlying HTTP client / Fetch function. If you're running in an
274
- unsupported environment, this provides a way for you to break glass and ensure the SDK works.
275
-
276
- ```typescript
277
- import { AgentMailClient } from "agentmail";
278
-
279
- const client = new AgentMailClient({
280
- ...
281
- fetcher: // provide your implementation here
282
- });
283
- ```
284
-
285
- ## Contributing
286
-
287
- While we value open-source contributions to this SDK, this library is generated programmatically.
288
- Additions made directly to this library would have to be moved over to our generation code,
289
- otherwise they would be overwritten upon the next generated release. Feel free to open a PR as
290
- a proof of concept, but know that we will not be able to merge it as-is. We suggest opening
291
- an issue first to discuss with us!
292
-
293
- On the other hand, contributions to the README are always very welcome!
294
- ## Binary Response
295
-
296
- You can consume binary data from endpoints using the `BinaryResponse` type which lets you choose how to consume the data:
297
-
298
- ```typescript
299
- const response = await client.domains.getZoneFile(...);
300
- const stream: ReadableStream<Uint8Array> = response.stream();
301
- // const arrayBuffer: ArrayBuffer = await response.arrayBuffer();
302
- // const blob: Blob = response.blob();
303
- // const bytes: Uint8Array = response.bytes();
304
- // You can only use the response body once, so you must choose one of the above methods.
305
- // If you want to check if the response body has been used, you can use the following property.
306
- const bodyUsed = response.bodyUsed;
307
- ```
308
- <details>
309
- <summary>Save binary response to a file</summary>
310
-
311
- <blockquote>
312
- <details>
313
- <summary>Node.js</summary>
314
-
315
- <blockquote>
316
- <details>
317
- <summary>ReadableStream (most-efficient)</summary>
318
-
319
- ```ts
320
- import { createWriteStream } from 'fs';
321
- import { Readable } from 'stream';
322
- import { pipeline } from 'stream/promises';
323
-
324
- const response = await client.domains.getZoneFile(...);
325
-
326
- const stream = response.stream();
327
- const nodeStream = Readable.fromWeb(stream);
328
- const writeStream = createWriteStream('path/to/file');
329
-
330
- await pipeline(nodeStream, writeStream);
331
- ```
332
-
333
- </details>
334
- </blockquote>
335
-
336
- <blockquote>
337
- <details>
338
- <summary>ArrayBuffer</summary>
339
-
340
- ```ts
341
- import { writeFile } from 'fs/promises';
342
-
343
- const response = await client.domains.getZoneFile(...);
344
-
345
- const arrayBuffer = await response.arrayBuffer();
346
- await writeFile('path/to/file', Buffer.from(arrayBuffer));
347
- ```
348
-
349
- </details>
350
- </blockquote>
351
-
352
- <blockquote>
353
- <details>
354
- <summary>Blob</summary>
355
-
356
- ```ts
357
- import { writeFile } from 'fs/promises';
358
-
359
- const response = await client.domains.getZoneFile(...);
360
-
361
- const blob = await response.blob();
362
- const arrayBuffer = await blob.arrayBuffer();
363
- await writeFile('output.bin', Buffer.from(arrayBuffer));
364
- ```
365
-
366
- </details>
367
- </blockquote>
368
-
369
- <blockquote>
370
- <details>
371
- <summary>Bytes (UIntArray8)</summary>
372
-
373
- ```ts
374
- import { writeFile } from 'fs/promises';
375
-
376
- const response = await client.domains.getZoneFile(...);
377
-
378
- const bytes = await response.bytes();
379
- await writeFile('path/to/file', bytes);
380
- ```
381
-
382
- </details>
383
- </blockquote>
384
-
385
- </details>
386
- </blockquote>
387
-
388
- <blockquote>
389
- <details>
390
- <summary>Bun</summary>
391
-
392
- <blockquote>
393
- <details>
394
- <summary>ReadableStream (most-efficient)</summary>
395
-
396
- ```ts
397
- const response = await client.domains.getZoneFile(...);
398
-
399
- const stream = response.stream();
400
- await Bun.write('path/to/file', stream);
401
- ```
402
-
403
- </details>
404
- </blockquote>
405
-
406
- <blockquote>
407
- <details>
408
- <summary>ArrayBuffer</summary>
409
-
410
- ```ts
411
- const response = await client.domains.getZoneFile(...);
412
-
413
- const arrayBuffer = await response.arrayBuffer();
414
- await Bun.write('path/to/file', arrayBuffer);
415
- ```
416
-
417
- </details>
418
- </blockquote>
419
-
420
- <blockquote>
421
- <details>
422
- <summary>Blob</summary>
423
-
424
- ```ts
425
- const response = await client.domains.getZoneFile(...);
426
-
427
- const blob = await response.blob();
428
- await Bun.write('path/to/file', blob);
429
- ```
430
-
431
- </details>
432
- </blockquote>
433
-
434
- <blockquote>
435
- <details>
436
- <summary>Bytes (UIntArray8)</summary>
437
-
438
- ```ts
439
- const response = await client.domains.getZoneFile(...);
440
-
441
- const bytes = await response.bytes();
442
- await Bun.write('path/to/file', bytes);
443
- ```
444
-
445
- </details>
446
- </blockquote>
447
-
448
- </details>
449
- </blockquote>
450
-
451
- <blockquote>
452
- <details>
453
- <summary>Deno</summary>
454
-
455
- <blockquote>
456
- <details>
457
- <summary>ReadableStream (most-efficient)</summary>
458
-
459
- ```ts
460
- const response = await client.domains.getZoneFile(...);
461
-
462
- const stream = response.stream();
463
- const file = await Deno.open('path/to/file', { write: true, create: true });
464
- await stream.pipeTo(file.writable);
465
- ```
466
-
467
- </details>
468
- </blockquote>
469
-
470
- <blockquote>
471
- <details>
472
- <summary>ArrayBuffer</summary>
473
-
474
- ```ts
475
- const response = await client.domains.getZoneFile(...);
476
-
477
- const arrayBuffer = await response.arrayBuffer();
478
- await Deno.writeFile('path/to/file', new Uint8Array(arrayBuffer));
479
- ```
480
-
481
- </details>
482
- </blockquote>
483
-
484
- <blockquote>
485
- <details>
486
- <summary>Blob</summary>
487
-
488
- ```ts
489
- const response = await client.domains.getZoneFile(...);
490
-
491
- const blob = await response.blob();
492
- const arrayBuffer = await blob.arrayBuffer();
493
- await Deno.writeFile('path/to/file', new Uint8Array(arrayBuffer));
494
- ```
495
-
496
- </details>
497
- </blockquote>
498
-
499
- <blockquote>
500
- <details>
501
- <summary>Bytes (UIntArray8)</summary>
502
-
503
- ```ts
504
- const response = await client.domains.getZoneFile(...);
505
-
506
- const bytes = await response.bytes();
507
- await Deno.writeFile('path/to/file', bytes);
508
- ```
509
-
510
- </details>
511
- </blockquote>
512
-
513
- </details>
514
- </blockquote>
515
-
516
- <blockquote>
517
- <details>
518
- <summary>Browser</summary>
519
-
520
- <blockquote>
521
- <details>
522
- <summary>Blob (most-efficient)</summary>
523
-
524
- ```ts
525
- const response = await client.domains.getZoneFile(...);
526
-
527
- const blob = await response.blob();
528
- const url = URL.createObjectURL(blob);
529
-
530
- // trigger download
531
- const a = document.createElement('a');
532
- a.href = url;
533
- a.download = 'filename';
534
- a.click();
535
- URL.revokeObjectURL(url);
536
- ```
537
-
538
- </details>
539
- </blockquote>
540
-
541
- <blockquote>
542
- <details>
543
- <summary>ReadableStream</summary>
544
-
545
- ```ts
546
- const response = await client.domains.getZoneFile(...);
547
-
548
- const stream = response.stream();
549
- const reader = stream.getReader();
550
- const chunks = [];
551
-
552
- while (true) {
553
- const { done, value } = await reader.read();
554
- if (done) break;
555
- chunks.push(value);
556
- }
557
-
558
- const blob = new Blob(chunks);
559
- const url = URL.createObjectURL(blob);
560
-
561
- // trigger download
562
- const a = document.createElement('a');
563
- a.href = url;
564
- a.download = 'filename';
565
- a.click();
566
- URL.revokeObjectURL(url);
567
- ```
568
-
569
- </details>
570
- </blockquote>
571
-
572
- <blockquote>
573
- <details>
574
- <summary>ArrayBuffer</summary>
575
-
576
- ```ts
577
- const response = await client.domains.getZoneFile(...);
578
-
579
- const arrayBuffer = await response.arrayBuffer();
580
- const blob = new Blob([arrayBuffer]);
581
- const url = URL.createObjectURL(blob);
582
-
583
- // trigger download
584
- const a = document.createElement('a');
585
- a.href = url;
586
- a.download = 'filename';
587
- a.click();
588
- URL.revokeObjectURL(url);
589
- ```
590
-
591
- </details>
592
- </blockquote>
593
-
594
- <blockquote>
595
- <details>
596
- <summary>Bytes (UIntArray8)</summary>
597
-
598
- ```ts
599
- const response = await client.domains.getZoneFile(...);
600
-
601
- const bytes = await response.bytes();
602
- const blob = new Blob([bytes]);
603
- const url = URL.createObjectURL(blob);
604
-
605
- // trigger download
606
- const a = document.createElement('a');
607
- a.href = url;
608
- a.download = 'filename';
609
- a.click();
610
- URL.revokeObjectURL(url);
611
- ```
612
-
613
- </details>
614
- </blockquote>
615
-
616
- </details>
617
- </blockquote>
618
-
619
- </details>
620
- </blockquote>
621
-
622
- <details>
623
- <summary>Convert binary response to text</summary>
624
-
625
- <blockquote>
626
- <details>
627
- <summary>ReadableStream</summary>
628
-
629
- ```ts
630
- const response = await client.domains.getZoneFile(...);
631
-
632
- const stream = response.stream();
633
- const text = await new Response(stream).text();
634
- ```
635
-
636
- </details>
637
- </blockquote>
638
-
639
- <blockquote>
640
- <details>
641
- <summary>ArrayBuffer</summary>
642
-
643
- ```ts
644
- const response = await client.domains.getZoneFile(...);
645
-
646
- const arrayBuffer = await response.arrayBuffer();
647
- const text = new TextDecoder().decode(arrayBuffer);
648
- ```
649
-
650
- </details>
651
- </blockquote>
652
-
653
- <blockquote>
654
- <details>
655
- <summary>Blob</summary>
656
-
657
- ```ts
658
- const response = await client.domains.getZoneFile(...);
659
-
660
- const blob = await response.blob();
661
- const text = await blob.text();
662
- ```
663
-
664
- </details>
665
- </blockquote>
666
-
667
- <blockquote>
668
- <details>
669
- <summary>Bytes (UIntArray8)</summary>
670
-
671
- ```ts
672
- const response = await client.domains.getZoneFile(...);
673
-
674
- const bytes = await response.bytes();
675
- const text = new TextDecoder().decode(bytes);
676
- ```
677
-
678
- </details>
679
- </blockquote>
680
-
681
- </details>
@@ -43,8 +43,8 @@ function normalizeClientOptions(options) {
43
43
  const headers = (0, headers_js_1.mergeHeaders)({
44
44
  "X-Fern-Language": "JavaScript",
45
45
  "X-Fern-SDK-Name": "agentmail",
46
- "X-Fern-SDK-Version": "0.2.17",
47
- "User-Agent": "agentmail/0.2.17",
46
+ "X-Fern-SDK-Version": "0.2.18",
47
+ "User-Agent": "agentmail/0.2.18",
48
48
  "X-Fern-Runtime": core.RUNTIME.type,
49
49
  "X-Fern-Runtime-Version": core.RUNTIME.version,
50
50
  }, options === null || options === void 0 ? void 0 : options.headers);
@@ -156,7 +156,13 @@ function getHeaders(args) {
156
156
  return __awaiter(this, void 0, void 0, function* () {
157
157
  var _a;
158
158
  const newHeaders = new Headers_js_1.Headers();
159
- newHeaders.set("Accept", args.responseType === "json" ? "application/json" : args.responseType === "text" ? "text/plain" : "*/*");
159
+ newHeaders.set("Accept", args.responseType === "json"
160
+ ? "application/json"
161
+ : args.responseType === "text"
162
+ ? "text/plain"
163
+ : args.responseType === "sse"
164
+ ? "text/event-stream"
165
+ : "*/*");
160
166
  if (args.body !== undefined && args.contentType != null) {
161
167
  newHeaders.set("Content-Type", args.contentType);
162
168
  }