nylas 8.1.0 โ 8.1.2
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 +117 -46
- package/lib/cjs/apiClient.js +2 -2
- package/lib/cjs/models/messages.js +1 -0
- package/lib/cjs/resources/attachments.js +26 -4
- package/lib/cjs/resources/messages.js +3 -2
- package/lib/cjs/utils.js +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/apiClient.js +1 -1
- package/lib/esm/models/messages.js +1 -0
- package/lib/esm/resources/attachments.js +26 -4
- package/lib/esm/resources/messages.js +3 -2
- package/lib/esm/utils.js +1 -1
- package/lib/esm/version.js +1 -1
- package/lib/types/models/messages.d.ts +10 -0
- package/lib/types/resources/attachments.d.ts +17 -4
- package/lib/types/resources/messages.d.ts +4 -2
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,59 +2,63 @@
|
|
|
2
2
|
<a href="https://www.nylas.com/">
|
|
3
3
|
<img src="/diagrams/nylas-logo.png" alt="Nylas" height="80" />
|
|
4
4
|
</a>
|
|
5
|
-
|
|
5
|
+
|
|
6
6
|
<h1>Nylas Node.js SDK</h1>
|
|
7
|
-
|
|
7
|
+
|
|
8
8
|
<p>
|
|
9
|
-
<strong>The official Node.js SDK for the
|
|
9
|
+
<strong>The official Node.js SDK for Nylas โ the infrastructure that powers communications</strong>
|
|
10
10
|
</p>
|
|
11
|
-
|
|
11
|
+
|
|
12
12
|
<p>
|
|
13
13
|
<a href="https://www.npmjs.com/package/nylas"><img src="https://img.shields.io/npm/v/nylas" alt="npm version" /></a>
|
|
14
14
|
<a href="https://codecov.io/gh/nylas/nylas-nodejs"><img src="https://codecov.io/gh/nylas/nylas-nodejs/branch/main/graph/badge.svg?token=94IMGU4F09" alt="code coverage" /></a>
|
|
15
15
|
<a href="https://www.npmjs.com/package/nylas"><img src="https://img.shields.io/npm/dm/nylas" alt="downloads" /></a>
|
|
16
16
|
<a href="LICENSE.txt"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="license" /></a>
|
|
17
17
|
</p>
|
|
18
|
-
|
|
18
|
+
|
|
19
19
|
<p>
|
|
20
|
-
<a href="https://developer.nylas.com/docs/v3/sdks/node/">๐
|
|
21
|
-
<a href="https://
|
|
22
|
-
<a href="https://
|
|
23
|
-
<a href="https://
|
|
20
|
+
<a href="https://developer.nylas.com/docs/v3/sdks/node/">๐ SDK Guide</a> ยท
|
|
21
|
+
<a href="https://developer.nylas.com/docs/api/v3/">๐ API Reference</a> ยท
|
|
22
|
+
<a href="https://dashboard-v3.nylas.com/register">๐ Sign up</a> ยท
|
|
23
|
+
<a href="https://github.com/orgs/nylas-samples/repositories?q=node">๐ก Samples</a> ยท
|
|
24
|
+
<a href="https://forums.nylas.com">๐ฌ Forum</a>
|
|
24
25
|
</p>
|
|
25
26
|
</div>
|
|
26
27
|
|
|
27
28
|
<br />
|
|
28
29
|
|
|
29
|
-
|
|
30
|
+
The official Node.js SDK for [Nylas](https://developer.nylas.com/docs/v3/) โ the infrastructure that powers communications. Integrate with Gmail, Microsoft, IMAP, Zoom, and 250+ email, calendar, and meeting providers in 5 minutes. Covers [Email](https://developer.nylas.com/docs/v3/email/), [Calendar](https://developer.nylas.com/docs/v3/calendar/), [Contacts](https://developer.nylas.com/docs/v3/email/contacts/), [Scheduler](https://developer.nylas.com/docs/v3/scheduler/), [Notetaker](https://developer.nylas.com/docs/v3/notetaker/), and [Agent Accounts](https://developer.nylas.com/docs/v3/agent-accounts/).
|
|
30
31
|
|
|
31
|
-
|
|
32
|
+
This repository is for contributors and anyone installing the SDK from source. If you just want to use the SDK in your app, head straight to the [**Node.js SDK guide**](https://developer.nylas.com/docs/v3/sdks/node/) on developer.nylas.com.
|
|
32
33
|
|
|
33
|
-
|
|
34
|
+
## Get started
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
- [Nylas SDK Reference](https://nylas-nodejs-sdk-reference.pages.dev/)
|
|
39
|
-
- [Nylas API Reference](https://developer.nylas.com/docs/api/)
|
|
40
|
-
- [Nylas Samples repo for code samples and example applications](https://github.com/orgs/nylas-samples/repositories?q=&type=all&language=javascript)
|
|
36
|
+
1. [Sign up for a free Nylas account](https://dashboard-v3.nylas.com/register) and grab your API key from the [Nylas Dashboard](https://dashboard-v3.nylas.com/).
|
|
37
|
+
2. Read the [Getting started guide](https://developer.nylas.com/docs/v3/getting-started/) for the core concepts (applications, grants, API keys).
|
|
38
|
+
3. Install the SDK and make your first request โ see below.
|
|
41
39
|
|
|
42
|
-
|
|
40
|
+
You can also bootstrap from the terminal:
|
|
43
41
|
|
|
44
|
-
|
|
42
|
+
```bash
|
|
43
|
+
brew install nylas/nylas-cli/nylas
|
|
44
|
+
nylas init
|
|
45
|
+
```
|
|
45
46
|
|
|
46
|
-
|
|
47
|
+
More options in the [CLI getting-started guide](https://cli.nylas.com/guides/getting-started).
|
|
47
48
|
|
|
48
|
-
|
|
49
|
+
## โ๏ธ Install
|
|
49
50
|
|
|
50
|
-
|
|
51
|
-
`npm install nylas`
|
|
51
|
+
> **Requirements:** Node.js v18 or later.
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
```bash
|
|
54
|
+
npm install nylas
|
|
55
|
+
# or
|
|
56
|
+
yarn add nylas
|
|
57
|
+
```
|
|
54
58
|
|
|
55
|
-
|
|
59
|
+
The package ships its own TypeScript types โ no `@types/nylas` needed. It's a hybrid ESM + CommonJS package, so both `import` and `require` work.
|
|
56
60
|
|
|
57
|
-
To install
|
|
61
|
+
To install from source:
|
|
58
62
|
|
|
59
63
|
```bash
|
|
60
64
|
git clone https://github.com/nylas/nylas-nodejs.git
|
|
@@ -62,48 +66,115 @@ cd nylas-nodejs
|
|
|
62
66
|
npm install
|
|
63
67
|
```
|
|
64
68
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
To use this SDK, you must first [get a free Nylas account](https://dashboard.nylas.com/register).
|
|
68
|
-
|
|
69
|
-
Then, follow the Quickstart guide to [set up your first app and get your API keys](https://developer.nylas.com/docs/v3-beta/v3-quickstart/).
|
|
69
|
+
### Runtime support
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
Tested on Node.js 18+. Also runs on AWS Lambda, Cloudflare Workers, and Vite/edge environments โ see the [`examples/`](examples/) directory for working setups.
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
## โก๏ธ Usage
|
|
74
74
|
|
|
75
|
-
You access Nylas resources (messages, calendars, events, contacts) through an instance of `Nylas`.
|
|
75
|
+
You access Nylas resources (messages, calendars, events, contacts, โฆ) through an instance of `Nylas`. Initialize it with your API key โ and optionally an `apiUri` matching your [data residency](https://developer.nylas.com/docs/dev-guide/platform/data-residency/).
|
|
76
76
|
|
|
77
77
|
```typescript
|
|
78
78
|
import Nylas from "nylas";
|
|
79
|
+
// or: const Nylas = require("nylas").default;
|
|
79
80
|
|
|
80
81
|
const nylas = new Nylas({
|
|
81
|
-
apiKey:
|
|
82
|
+
apiKey: process.env.NYLAS_API_KEY,
|
|
83
|
+
apiUri: process.env.NYLAS_API_URI, // e.g. https://api.us.nylas.com
|
|
84
|
+
timeout: 30, // optional, in seconds
|
|
82
85
|
});
|
|
83
86
|
```
|
|
84
87
|
|
|
85
|
-
Once initialized
|
|
88
|
+
Once initialized, use it to make requests against a [grant](https://developer.nylas.com/docs/v3/auth/) (an authenticated end-user account):
|
|
86
89
|
|
|
87
90
|
```typescript
|
|
88
|
-
nylas.calendars.list({
|
|
89
|
-
|
|
91
|
+
const calendars = await nylas.calendars.list({
|
|
92
|
+
identifier: process.env.NYLAS_GRANT_ID,
|
|
90
93
|
});
|
|
94
|
+
console.log(calendars);
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Error handling
|
|
98
|
+
|
|
99
|
+
The SDK throws typed errors you can catch and inspect. Every API error carries a `requestId` and `flowId` โ include both when filing a support ticket so we can trace the request end-to-end.
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
import { NylasApiError, NylasOAuthError, NylasSdkTimeoutError } from "nylas";
|
|
103
|
+
|
|
104
|
+
try {
|
|
105
|
+
await nylas.calendars.list({ identifier: grantId });
|
|
106
|
+
} catch (err) {
|
|
107
|
+
if (err instanceof NylasApiError) {
|
|
108
|
+
console.error(err.statusCode, err.type, err.message, err.requestId, err.flowId);
|
|
109
|
+
} else if (err instanceof NylasSdkTimeoutError) {
|
|
110
|
+
console.error("Timed out:", err.url, err.timeout);
|
|
111
|
+
} else {
|
|
112
|
+
throw err;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
91
115
|
```
|
|
92
116
|
|
|
93
|
-
|
|
117
|
+
Step-by-step walkthroughs in the SDK guide:
|
|
94
118
|
|
|
95
|
-
|
|
119
|
+
- [Send and receive email](https://developer.nylas.com/docs/v3/sdks/node/send-email/)
|
|
120
|
+
- [Read messages and threads](https://developer.nylas.com/docs/v3/sdks/node/read-messages-threads/)
|
|
121
|
+
- [Manage events on a calendar](https://developer.nylas.com/docs/v3/sdks/node/manage-events/)
|
|
122
|
+
- [Manage contacts](https://developer.nylas.com/docs/v3/sdks/node/manage-contacts/)
|
|
123
|
+
- [Manage folders and labels](https://developer.nylas.com/docs/v3/sdks/node/manage-folders-labels/)
|
|
124
|
+
- [Test webhooks locally](https://developer.nylas.com/docs/v3/sdks/node/webhook-testing/)
|
|
96
125
|
|
|
97
|
-
##
|
|
126
|
+
## ๐ก Examples
|
|
98
127
|
|
|
99
|
-
|
|
128
|
+
Runnable examples live in [`examples/`](examples/) โ including [agent accounts](examples/agent-accounts/), [attachments](examples/attachments/) (incl. large attachments), [calendars](examples/calendars/), [folders](examples/folders/), [grants](examples/grants/), [messages](examples/messages/), [notetakers](examples/notetakers/), and edge runtimes ([AWS Lambda](examples/aws-lambda/), [Cloudflare + Vite](examples/cloudflare-vite-calendars/), [generic edge](examples/edge-environment/)).
|
|
100
129
|
|
|
101
|
-
|
|
130
|
+
For full sample apps and product quickstarts, browse [**nylas-samples** on GitHub](https://github.com/orgs/nylas-samples/repositories?q=node) โ every official SDK has Email, Calendar, Contacts, Scheduler, and Webhooks quickstarts.
|
|
131
|
+
|
|
132
|
+
## ๐ค AI agents
|
|
133
|
+
|
|
134
|
+
[nylas/skills](https://github.com/nylas/skills) drops Nylas into Claude Code, Cursor, Codex, and other agents that support the skills format:
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
npx skills add nylas/skills
|
|
138
|
+
/plugin marketplace add nylas/skills # Claude Code
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
The CLI also installs an MCP server for Claude Desktop, Claude Code, Cursor, Windsurf, or VS Code:
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
brew install nylas/nylas-cli/nylas
|
|
145
|
+
nylas mcp install
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Walkthrough: [give AI agents email access via MCP](https://cli.nylas.com/guides/give-ai-agents-email-access-via-mcp).
|
|
149
|
+
|
|
150
|
+
## ๐ Reference
|
|
151
|
+
|
|
152
|
+
- **SDK guide:** [developer.nylas.com/docs/v3/sdks/node](https://developer.nylas.com/docs/v3/sdks/node/)
|
|
153
|
+
- **API reference:** [developer.nylas.com/docs/api/v3](https://developer.nylas.com/docs/api/v3/)
|
|
154
|
+
- **TypeDoc reference:** [nylas-nodejs-sdk-reference.pages.dev](https://nylas-nodejs-sdk-reference.pages.dev/) โ generated method/class docs for this SDK
|
|
155
|
+
- **Webhooks (notifications):** [developer.nylas.com/docs/v3/notifications](https://developer.nylas.com/docs/v3/notifications/)
|
|
156
|
+
- **Auth flows:** [developer.nylas.com/docs/v3/auth](https://developer.nylas.com/docs/v3/auth/)
|
|
157
|
+
- **Dev guide & best practices:** [developer.nylas.com/docs/dev-guide](https://developer.nylas.com/docs/dev-guide/)
|
|
158
|
+
- **Changelog:** [CHANGELOG.md](CHANGELOG.md)
|
|
159
|
+
|
|
160
|
+
## โจ Upgrading
|
|
161
|
+
|
|
162
|
+
See [`CHANGELOG.md`](CHANGELOG.md) for per-release notes. Older upgrade guidance lives in [`UPGRADE.md`](UPGRADE.md).
|
|
102
163
|
|
|
103
164
|
## ๐ Contributing
|
|
104
165
|
|
|
105
|
-
|
|
166
|
+
Issues, ideas, and pull requests welcome โ see [Contributing.md](Contributing.md). Before opening a large change, please open an issue or post in the [forum](https://forums.nylas.com) so we can sanity-check the direction.
|
|
167
|
+
|
|
168
|
+
## ๐ Security
|
|
169
|
+
|
|
170
|
+
Found a vulnerability? Please **don't** open a public issue. Report it through our [Vulnerability Disclosure Policy](https://www.nylas.com/security/vulnerability-disclosure-policy/).
|
|
171
|
+
|
|
172
|
+
## ๐ Other Nylas SDKs
|
|
173
|
+
|
|
174
|
+
- [nylas-python](https://github.com/nylas/nylas-python) ยท `pip install nylas`
|
|
175
|
+
- [nylas-ruby](https://github.com/nylas/nylas-ruby) ยท `gem install nylas`
|
|
176
|
+
- [nylas-java](https://github.com/nylas/nylas-java) ยท Maven / Gradle (Kotlin too)
|
|
106
177
|
|
|
107
178
|
## ๐ License
|
|
108
179
|
|
|
109
|
-
|
|
180
|
+
MIT โ see [LICENSE.txt](LICENSE.txt).
|
package/lib/cjs/apiClient.js
CHANGED
|
@@ -5,7 +5,7 @@ const error_js_1 = require("./models/error.js");
|
|
|
5
5
|
const utils_js_1 = require("./utils.js");
|
|
6
6
|
const version_js_1 = require("./version.js");
|
|
7
7
|
const form_data_encoder_1 = require("form-data-encoder");
|
|
8
|
-
const
|
|
8
|
+
const node_stream_1 = require("node:stream");
|
|
9
9
|
const change_case_1 = require("change-case");
|
|
10
10
|
/**
|
|
11
11
|
* The header key for the debugging flow ID
|
|
@@ -164,7 +164,7 @@ class APIClient {
|
|
|
164
164
|
// Set the Content-Type header with the boundary from the encoder
|
|
165
165
|
requestOptions.headers['Content-Type'] = encoder.contentType;
|
|
166
166
|
// Convert the encoded form data to a readable stream for the request body
|
|
167
|
-
requestOptions.body =
|
|
167
|
+
requestOptions.body = node_stream_1.Readable.from(encoder);
|
|
168
168
|
// Node.js native fetch requires duplex: 'half' when sending a streaming body
|
|
169
169
|
requestOptions.duplex = 'half';
|
|
170
170
|
}
|
|
@@ -7,6 +7,7 @@ exports.MessageFields = void 0;
|
|
|
7
7
|
var MessageFields;
|
|
8
8
|
(function (MessageFields) {
|
|
9
9
|
MessageFields["STANDARD"] = "standard";
|
|
10
|
+
MessageFields["INCLUDE_BASIC_HEADERS"] = "include_basic_headers";
|
|
10
11
|
MessageFields["INCLUDE_HEADERS"] = "include_headers";
|
|
11
12
|
MessageFields["INCLUDE_TRACKING_OPTIONS"] = "include_tracking_options";
|
|
12
13
|
MessageFields["RAW_MIME"] = "raw_mime";
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Attachments = void 0;
|
|
4
4
|
const utils_js_1 = require("../utils.js");
|
|
5
5
|
const resource_js_1 = require("./resource.js");
|
|
6
|
+
const node_stream_1 = require("node:stream");
|
|
6
7
|
/**
|
|
7
8
|
* Nylas Attachments API
|
|
8
9
|
*
|
|
@@ -23,15 +24,15 @@ class Attachments extends resource_js_1.Resource {
|
|
|
23
24
|
/**
|
|
24
25
|
* Download the attachment data
|
|
25
26
|
*
|
|
26
|
-
* This method returns a
|
|
27
|
+
* This method returns a Web ReadableStream which can be used to stream the attachment data.
|
|
27
28
|
* This is particularly useful for handling large attachments efficiently, as it avoids loading
|
|
28
|
-
* the entire file into memory.
|
|
29
|
-
*
|
|
29
|
+
* the entire file into memory. In Node.js, convert it with Readable.fromWeb() when a
|
|
30
|
+
* NodeJS.ReadableStream is required.
|
|
30
31
|
*
|
|
31
32
|
* @param identifier Grant ID or email account to query
|
|
32
33
|
* @param attachmentId The id of the attachment to download.
|
|
33
34
|
* @param queryParams The query parameters to include in the request
|
|
34
|
-
* @returns {
|
|
35
|
+
* @returns {ReadableStream<Uint8Array>} The ReadableStream containing the file data.
|
|
35
36
|
*/
|
|
36
37
|
download({ identifier, attachmentId, queryParams, overrides, }) {
|
|
37
38
|
return this._getStream({
|
|
@@ -40,6 +41,27 @@ class Attachments extends resource_js_1.Resource {
|
|
|
40
41
|
overrides,
|
|
41
42
|
});
|
|
42
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Download the attachment data as a Node.js readable stream.
|
|
46
|
+
*
|
|
47
|
+
* This is a Node.js convenience wrapper around {@link Attachments.download}. Use
|
|
48
|
+
* {@link Attachments.download} directly in Fetch-native runtimes, such as Cloudflare Workers,
|
|
49
|
+
* where Web ReadableStreams are the standard stream primitive.
|
|
50
|
+
*
|
|
51
|
+
* @param identifier Grant ID or email account to query
|
|
52
|
+
* @param attachmentId The id of the attachment to download.
|
|
53
|
+
* @param queryParams The query parameters to include in the request
|
|
54
|
+
* @returns {NodeJS.ReadableStream} The Node.js readable stream containing the file data.
|
|
55
|
+
*/
|
|
56
|
+
async downloadNodeStream({ identifier, attachmentId, queryParams, overrides, }) {
|
|
57
|
+
const stream = await this.download({
|
|
58
|
+
identifier,
|
|
59
|
+
attachmentId,
|
|
60
|
+
queryParams,
|
|
61
|
+
overrides,
|
|
62
|
+
});
|
|
63
|
+
return node_stream_1.Readable.fromWeb(stream);
|
|
64
|
+
}
|
|
43
65
|
/**
|
|
44
66
|
* Download the attachment as a byte array
|
|
45
67
|
* @param identifier Grant ID or email account to query
|
|
@@ -81,13 +81,14 @@ class Messages extends resource_js_1.Resource {
|
|
|
81
81
|
* Send an email
|
|
82
82
|
* @return The sent message
|
|
83
83
|
*/
|
|
84
|
-
async send({ identifier, requestBody, overrides, }) {
|
|
84
|
+
async send({ identifier, requestBody, queryParams, overrides, }) {
|
|
85
85
|
const path = (0, utils_js_1.makePathParams)('/v3/grants/{identifier}/messages/send', {
|
|
86
86
|
identifier,
|
|
87
87
|
});
|
|
88
88
|
const requestOptions = {
|
|
89
89
|
method: 'POST',
|
|
90
90
|
path,
|
|
91
|
+
queryParams,
|
|
91
92
|
overrides,
|
|
92
93
|
};
|
|
93
94
|
// Use form data if the total payload size (body + attachments) is greater than 3mb
|
|
@@ -162,7 +163,7 @@ class Messages extends resource_js_1.Resource {
|
|
|
162
163
|
...requestBody,
|
|
163
164
|
attachments: undefined,
|
|
164
165
|
};
|
|
165
|
-
form.append('message', JSON.stringify((0, utils_js_1.objKeysToSnakeCase)(messagePayload)));
|
|
166
|
+
form.append('message', JSON.stringify((0, utils_js_1.objKeysToSnakeCase)(messagePayload, ['metadata'])));
|
|
166
167
|
// Add a separate form field for each attachment
|
|
167
168
|
if (requestBody.attachments && requestBody.attachments.length > 0) {
|
|
168
169
|
requestBody.attachments.map((attachment, index) => {
|
package/lib/cjs/utils.js
CHANGED
|
@@ -249,7 +249,7 @@ function calculateTotalPayloadSize(requestBody) {
|
|
|
249
249
|
...requestBody,
|
|
250
250
|
attachments: undefined,
|
|
251
251
|
};
|
|
252
|
-
const messagePayloadString = JSON.stringify(objKeysToSnakeCase(messagePayloadWithoutAttachments));
|
|
252
|
+
const messagePayloadString = JSON.stringify(objKeysToSnakeCase(messagePayloadWithoutAttachments, ['metadata']));
|
|
253
253
|
totalSize += Buffer.byteLength(messagePayloadString, 'utf8');
|
|
254
254
|
// Add attachment sizes
|
|
255
255
|
const attachmentSize = requestBody.attachments?.reduce((total, attachment) => {
|
package/lib/cjs/version.js
CHANGED
package/lib/esm/apiClient.js
CHANGED
|
@@ -2,7 +2,7 @@ import { NylasApiError, NylasOAuthError, NylasSdkTimeoutError, } from './models/
|
|
|
2
2
|
import { objKeysToCamelCase, objKeysToSnakeCase } from './utils.js';
|
|
3
3
|
import { SDK_VERSION } from './version.js';
|
|
4
4
|
import { FormDataEncoder } from 'form-data-encoder';
|
|
5
|
-
import { Readable } from 'stream';
|
|
5
|
+
import { Readable } from 'node:stream';
|
|
6
6
|
import { snakeCase } from 'change-case';
|
|
7
7
|
/**
|
|
8
8
|
* The header key for the debugging flow ID
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
export var MessageFields;
|
|
5
5
|
(function (MessageFields) {
|
|
6
6
|
MessageFields["STANDARD"] = "standard";
|
|
7
|
+
MessageFields["INCLUDE_BASIC_HEADERS"] = "include_basic_headers";
|
|
7
8
|
MessageFields["INCLUDE_HEADERS"] = "include_headers";
|
|
8
9
|
MessageFields["INCLUDE_TRACKING_OPTIONS"] = "include_tracking_options";
|
|
9
10
|
MessageFields["RAW_MIME"] = "raw_mime";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { makePathParams } from '../utils.js';
|
|
2
2
|
import { Resource } from './resource.js';
|
|
3
|
+
import { Readable } from 'node:stream';
|
|
3
4
|
/**
|
|
4
5
|
* Nylas Attachments API
|
|
5
6
|
*
|
|
@@ -20,15 +21,15 @@ export class Attachments extends Resource {
|
|
|
20
21
|
/**
|
|
21
22
|
* Download the attachment data
|
|
22
23
|
*
|
|
23
|
-
* This method returns a
|
|
24
|
+
* This method returns a Web ReadableStream which can be used to stream the attachment data.
|
|
24
25
|
* This is particularly useful for handling large attachments efficiently, as it avoids loading
|
|
25
|
-
* the entire file into memory.
|
|
26
|
-
*
|
|
26
|
+
* the entire file into memory. In Node.js, convert it with Readable.fromWeb() when a
|
|
27
|
+
* NodeJS.ReadableStream is required.
|
|
27
28
|
*
|
|
28
29
|
* @param identifier Grant ID or email account to query
|
|
29
30
|
* @param attachmentId The id of the attachment to download.
|
|
30
31
|
* @param queryParams The query parameters to include in the request
|
|
31
|
-
* @returns {
|
|
32
|
+
* @returns {ReadableStream<Uint8Array>} The ReadableStream containing the file data.
|
|
32
33
|
*/
|
|
33
34
|
download({ identifier, attachmentId, queryParams, overrides, }) {
|
|
34
35
|
return this._getStream({
|
|
@@ -37,6 +38,27 @@ export class Attachments extends Resource {
|
|
|
37
38
|
overrides,
|
|
38
39
|
});
|
|
39
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Download the attachment data as a Node.js readable stream.
|
|
43
|
+
*
|
|
44
|
+
* This is a Node.js convenience wrapper around {@link Attachments.download}. Use
|
|
45
|
+
* {@link Attachments.download} directly in Fetch-native runtimes, such as Cloudflare Workers,
|
|
46
|
+
* where Web ReadableStreams are the standard stream primitive.
|
|
47
|
+
*
|
|
48
|
+
* @param identifier Grant ID or email account to query
|
|
49
|
+
* @param attachmentId The id of the attachment to download.
|
|
50
|
+
* @param queryParams The query parameters to include in the request
|
|
51
|
+
* @returns {NodeJS.ReadableStream} The Node.js readable stream containing the file data.
|
|
52
|
+
*/
|
|
53
|
+
async downloadNodeStream({ identifier, attachmentId, queryParams, overrides, }) {
|
|
54
|
+
const stream = await this.download({
|
|
55
|
+
identifier,
|
|
56
|
+
attachmentId,
|
|
57
|
+
queryParams,
|
|
58
|
+
overrides,
|
|
59
|
+
});
|
|
60
|
+
return Readable.fromWeb(stream);
|
|
61
|
+
}
|
|
40
62
|
/**
|
|
41
63
|
* Download the attachment as a byte array
|
|
42
64
|
* @param identifier Grant ID or email account to query
|
|
@@ -78,13 +78,14 @@ export class Messages extends Resource {
|
|
|
78
78
|
* Send an email
|
|
79
79
|
* @return The sent message
|
|
80
80
|
*/
|
|
81
|
-
async send({ identifier, requestBody, overrides, }) {
|
|
81
|
+
async send({ identifier, requestBody, queryParams, overrides, }) {
|
|
82
82
|
const path = makePathParams('/v3/grants/{identifier}/messages/send', {
|
|
83
83
|
identifier,
|
|
84
84
|
});
|
|
85
85
|
const requestOptions = {
|
|
86
86
|
method: 'POST',
|
|
87
87
|
path,
|
|
88
|
+
queryParams,
|
|
88
89
|
overrides,
|
|
89
90
|
};
|
|
90
91
|
// Use form data if the total payload size (body + attachments) is greater than 3mb
|
|
@@ -159,7 +160,7 @@ export class Messages extends Resource {
|
|
|
159
160
|
...requestBody,
|
|
160
161
|
attachments: undefined,
|
|
161
162
|
};
|
|
162
|
-
form.append('message', JSON.stringify(objKeysToSnakeCase(messagePayload)));
|
|
163
|
+
form.append('message', JSON.stringify(objKeysToSnakeCase(messagePayload, ['metadata'])));
|
|
163
164
|
// Add a separate form field for each attachment
|
|
164
165
|
if (requestBody.attachments && requestBody.attachments.length > 0) {
|
|
165
166
|
requestBody.attachments.map((attachment, index) => {
|
package/lib/esm/utils.js
CHANGED
|
@@ -204,7 +204,7 @@ export function calculateTotalPayloadSize(requestBody) {
|
|
|
204
204
|
...requestBody,
|
|
205
205
|
attachments: undefined,
|
|
206
206
|
};
|
|
207
|
-
const messagePayloadString = JSON.stringify(objKeysToSnakeCase(messagePayloadWithoutAttachments));
|
|
207
|
+
const messagePayloadString = JSON.stringify(objKeysToSnakeCase(messagePayloadWithoutAttachments, ['metadata']));
|
|
208
208
|
totalSize += Buffer.byteLength(messagePayloadString, 'utf8');
|
|
209
209
|
// Add attachment sizes
|
|
210
210
|
const attachmentSize = requestBody.attachments?.reduce((total, attachment) => {
|
package/lib/esm/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// This file is generated by scripts/exportVersion.js
|
|
2
|
-
export const SDK_VERSION = '8.1.
|
|
2
|
+
export const SDK_VERSION = '8.1.2';
|
|
@@ -177,6 +177,7 @@ export interface MessageHeaders {
|
|
|
177
177
|
*/
|
|
178
178
|
export declare enum MessageFields {
|
|
179
179
|
STANDARD = "standard",
|
|
180
|
+
INCLUDE_BASIC_HEADERS = "include_basic_headers",
|
|
180
181
|
INCLUDE_HEADERS = "include_headers",
|
|
181
182
|
INCLUDE_TRACKING_OPTIONS = "include_tracking_options",
|
|
182
183
|
RAW_MIME = "raw_mime"
|
|
@@ -304,6 +305,15 @@ export interface FindMessageQueryParams {
|
|
|
304
305
|
*/
|
|
305
306
|
fields?: MessageFields;
|
|
306
307
|
}
|
|
308
|
+
/**
|
|
309
|
+
* Interface representing the query parameters for sending a message.
|
|
310
|
+
*/
|
|
311
|
+
export interface SendMessageQueryParams {
|
|
312
|
+
/**
|
|
313
|
+
* Allows you to specify to return the sent message with headers included.
|
|
314
|
+
*/
|
|
315
|
+
fields?: MessageFields;
|
|
316
|
+
}
|
|
307
317
|
/**
|
|
308
318
|
* Interface representing the request to clean a message.
|
|
309
319
|
*/
|
|
@@ -52,17 +52,30 @@ export declare class Attachments extends Resource {
|
|
|
52
52
|
/**
|
|
53
53
|
* Download the attachment data
|
|
54
54
|
*
|
|
55
|
-
* This method returns a
|
|
55
|
+
* This method returns a Web ReadableStream which can be used to stream the attachment data.
|
|
56
56
|
* This is particularly useful for handling large attachments efficiently, as it avoids loading
|
|
57
|
-
* the entire file into memory.
|
|
58
|
-
*
|
|
57
|
+
* the entire file into memory. In Node.js, convert it with Readable.fromWeb() when a
|
|
58
|
+
* NodeJS.ReadableStream is required.
|
|
59
59
|
*
|
|
60
60
|
* @param identifier Grant ID or email account to query
|
|
61
61
|
* @param attachmentId The id of the attachment to download.
|
|
62
62
|
* @param queryParams The query parameters to include in the request
|
|
63
|
-
* @returns {
|
|
63
|
+
* @returns {ReadableStream<Uint8Array>} The ReadableStream containing the file data.
|
|
64
64
|
*/
|
|
65
65
|
download({ identifier, attachmentId, queryParams, overrides, }: DownloadAttachmentParams & Overrides): Promise<ReadableStream<Uint8Array>>;
|
|
66
|
+
/**
|
|
67
|
+
* Download the attachment data as a Node.js readable stream.
|
|
68
|
+
*
|
|
69
|
+
* This is a Node.js convenience wrapper around {@link Attachments.download}. Use
|
|
70
|
+
* {@link Attachments.download} directly in Fetch-native runtimes, such as Cloudflare Workers,
|
|
71
|
+
* where Web ReadableStreams are the standard stream primitive.
|
|
72
|
+
*
|
|
73
|
+
* @param identifier Grant ID or email account to query
|
|
74
|
+
* @param attachmentId The id of the attachment to download.
|
|
75
|
+
* @param queryParams The query parameters to include in the request
|
|
76
|
+
* @returns {NodeJS.ReadableStream} The Node.js readable stream containing the file data.
|
|
77
|
+
*/
|
|
78
|
+
downloadNodeStream({ identifier, attachmentId, queryParams, overrides, }: DownloadAttachmentParams & Overrides): Promise<NodeJS.ReadableStream>;
|
|
66
79
|
/**
|
|
67
80
|
* Download the attachment as a byte array
|
|
68
81
|
* @param identifier Grant ID or email account to query
|
|
@@ -2,7 +2,7 @@ import { FormData } from 'formdata-node';
|
|
|
2
2
|
import APIClient from '../apiClient.js';
|
|
3
3
|
import { Overrides } from '../config.js';
|
|
4
4
|
import { CreateDraftRequest, SendMessageRequest, UpdateDraftRequest } from '../models/drafts.js';
|
|
5
|
-
import { CleanMessagesRequest, CleanMessagesResponse, FindMessageQueryParams, ListMessagesQueryParams, Message, ScheduledMessage, ScheduledMessagesList, StopScheduledMessageResponse, UpdateMessageRequest } from '../models/messages.js';
|
|
5
|
+
import { CleanMessagesRequest, CleanMessagesResponse, FindMessageQueryParams, ListMessagesQueryParams, Message, ScheduledMessage, ScheduledMessagesList, SendMessageQueryParams, StopScheduledMessageResponse, UpdateMessageRequest } from '../models/messages.js';
|
|
6
6
|
import { NylasBaseResponse, NylasListResponse, NylasResponse } from '../models/response.js';
|
|
7
7
|
import { AsyncListResponse, Resource } from './resource.js';
|
|
8
8
|
import { SmartCompose } from './smartCompose.js';
|
|
@@ -50,10 +50,12 @@ export interface DestroyMessageParams {
|
|
|
50
50
|
* The parameters for the {@link Messages.send} method
|
|
51
51
|
* @property identifier The identifier of the grant to act upon
|
|
52
52
|
* @property requestBody The message to send
|
|
53
|
+
* @property queryParams The query parameters to include in the request
|
|
53
54
|
*/
|
|
54
55
|
export interface SendMessageParams {
|
|
55
56
|
identifier: string;
|
|
56
57
|
requestBody: SendMessageRequest;
|
|
58
|
+
queryParams?: SendMessageQueryParams;
|
|
57
59
|
}
|
|
58
60
|
/**
|
|
59
61
|
* The parameters for the {@link Messages.listScheduledMessages} method
|
|
@@ -119,7 +121,7 @@ export declare class Messages extends Resource {
|
|
|
119
121
|
* Send an email
|
|
120
122
|
* @return The sent message
|
|
121
123
|
*/
|
|
122
|
-
send({ identifier, requestBody, overrides, }: SendMessageParams & Overrides): Promise<NylasResponse<Message>>;
|
|
124
|
+
send({ identifier, requestBody, queryParams, overrides, }: SendMessageParams & Overrides): Promise<NylasResponse<Message>>;
|
|
123
125
|
/**
|
|
124
126
|
* Retrieve your scheduled messages
|
|
125
127
|
* @return A list of scheduled messages
|
package/lib/types/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "8.1.
|
|
1
|
+
export declare const SDK_VERSION = "8.1.2";
|