nylas 7.2.1 → 7.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/apiClient.js +8 -2
- package/lib/cjs/nylas.js +1 -0
- package/lib/cjs/resources/auth.js +3 -3
- package/lib/cjs/resources/drafts.js +21 -6
- package/lib/cjs/resources/messages.js +25 -4
- package/lib/cjs/utils.js +36 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/apiClient.js +8 -2
- package/lib/esm/nylas.js +1 -0
- package/lib/esm/resources/auth.js +3 -3
- package/lib/esm/resources/drafts.js +21 -6
- package/lib/esm/resources/messages.js +26 -5
- package/lib/esm/utils.js +34 -0
- package/lib/esm/version.js +1 -1
- package/lib/types/apiClient.d.ts +5 -1
- package/lib/types/config.d.ts +2 -0
- package/lib/types/models/attachments.d.ts +2 -1
- package/lib/types/models/auth.d.ts +4 -0
- package/lib/types/models/drafts.d.ts +14 -0
- package/lib/types/models/events.d.ts +15 -6
- package/lib/types/models/messages.d.ts +38 -0
- package/lib/types/resources/events.d.ts +2 -2
- package/lib/types/resources/messages.d.ts +15 -1
- package/lib/types/utils.d.ts +6 -0
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
package/lib/cjs/apiClient.js
CHANGED
|
@@ -9,10 +9,11 @@ const version_js_1 = require("./version.js");
|
|
|
9
9
|
* @ignore Not for public use
|
|
10
10
|
*/
|
|
11
11
|
class APIClient {
|
|
12
|
-
constructor({ apiKey, apiUri, timeout }) {
|
|
12
|
+
constructor({ apiKey, apiUri, timeout, headers }) {
|
|
13
13
|
this.apiKey = apiKey;
|
|
14
14
|
this.serverUrl = apiUri;
|
|
15
15
|
this.timeout = timeout * 1000; // fetch timeout uses milliseconds
|
|
16
|
+
this.headers = headers;
|
|
16
17
|
}
|
|
17
18
|
setRequestUrl({ overrides, path, queryParams, }) {
|
|
18
19
|
const url = new URL(`${overrides?.apiUri || this.serverUrl}${path}`);
|
|
@@ -39,11 +40,16 @@ class APIClient {
|
|
|
39
40
|
return url;
|
|
40
41
|
}
|
|
41
42
|
setRequestHeaders({ headers, overrides, }) {
|
|
43
|
+
const mergedHeaders = {
|
|
44
|
+
...headers,
|
|
45
|
+
...this.headers,
|
|
46
|
+
...overrides?.headers,
|
|
47
|
+
};
|
|
42
48
|
return {
|
|
43
49
|
Accept: 'application/json',
|
|
44
50
|
'User-Agent': `Nylas Node SDK v${version_js_1.SDK_VERSION}`,
|
|
45
51
|
Authorization: `Bearer ${overrides?.apiKey || this.apiKey}`,
|
|
46
|
-
...
|
|
52
|
+
...mergedHeaders,
|
|
47
53
|
};
|
|
48
54
|
}
|
|
49
55
|
async sendRequest(options) {
|
package/lib/cjs/nylas.js
CHANGED
|
@@ -45,6 +45,7 @@ class Nylas {
|
|
|
45
45
|
apiKey: config.apiKey,
|
|
46
46
|
apiUri: config.apiUri || config_js_1.DEFAULT_SERVER_URL,
|
|
47
47
|
timeout: config.timeout || 90,
|
|
48
|
+
headers: config.headers || {},
|
|
48
49
|
});
|
|
49
50
|
this.applications = new applications_js_1.Applications(this.apiClient);
|
|
50
51
|
this.auth = new auth_js_1.Auth(this.apiClient);
|
|
@@ -149,9 +149,9 @@ class Auth extends resource_js_1.Resource {
|
|
|
149
149
|
}
|
|
150
150
|
if (config.loginHint) {
|
|
151
151
|
url.searchParams.set('login_hint', config.loginHint);
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
152
|
+
}
|
|
153
|
+
if (config.includeGrantScopes !== undefined) {
|
|
154
|
+
url.searchParams.set('include_grant_scopes', config.includeGrantScopes.toString());
|
|
155
155
|
}
|
|
156
156
|
if (config.scope) {
|
|
157
157
|
url.searchParams.set('scope', config.scope.join(' '));
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Drafts = void 0;
|
|
4
4
|
const messages_js_1 = require("./messages.js");
|
|
5
5
|
const resource_js_1 = require("./resource.js");
|
|
6
|
+
const utils_js_1 = require("../utils.js");
|
|
6
7
|
/**
|
|
7
8
|
* Nylas Drafts API
|
|
8
9
|
*
|
|
@@ -34,11 +35,11 @@ class Drafts extends resource_js_1.Resource {
|
|
|
34
35
|
* Return a Draft
|
|
35
36
|
* @return The draft
|
|
36
37
|
*/
|
|
37
|
-
create({ identifier, requestBody, overrides, }) {
|
|
38
|
+
async create({ identifier, requestBody, overrides, }) {
|
|
38
39
|
const path = `/v3/grants/${identifier}/drafts`;
|
|
39
40
|
// Use form data only if the attachment size is greater than 3mb
|
|
40
|
-
const attachmentSize = requestBody.attachments?.reduce(
|
|
41
|
-
return attachment.size || 0;
|
|
41
|
+
const attachmentSize = requestBody.attachments?.reduce((total, attachment) => {
|
|
42
|
+
return total + (attachment.size || 0);
|
|
42
43
|
}, 0) || 0;
|
|
43
44
|
if (attachmentSize >= messages_js_1.Messages.MAXIMUM_JSON_ATTACHMENT_SIZE) {
|
|
44
45
|
const form = messages_js_1.Messages._buildFormRequest(requestBody);
|
|
@@ -49,6 +50,13 @@ class Drafts extends resource_js_1.Resource {
|
|
|
49
50
|
overrides,
|
|
50
51
|
});
|
|
51
52
|
}
|
|
53
|
+
else if (requestBody.attachments) {
|
|
54
|
+
const processedAttachments = await (0, utils_js_1.encodeAttachmentStreams)(requestBody.attachments);
|
|
55
|
+
requestBody = {
|
|
56
|
+
...requestBody,
|
|
57
|
+
attachments: processedAttachments,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
52
60
|
return super._create({
|
|
53
61
|
path,
|
|
54
62
|
requestBody,
|
|
@@ -59,11 +67,11 @@ class Drafts extends resource_js_1.Resource {
|
|
|
59
67
|
* Update a Draft
|
|
60
68
|
* @return The updated draft
|
|
61
69
|
*/
|
|
62
|
-
update({ identifier, draftId, requestBody, overrides, }) {
|
|
70
|
+
async update({ identifier, draftId, requestBody, overrides, }) {
|
|
63
71
|
const path = `/v3/grants/${identifier}/drafts/${draftId}`;
|
|
64
72
|
// Use form data only if the attachment size is greater than 3mb
|
|
65
|
-
const attachmentSize = requestBody.attachments?.reduce(
|
|
66
|
-
return attachment.size || 0;
|
|
73
|
+
const attachmentSize = requestBody.attachments?.reduce((total, attachment) => {
|
|
74
|
+
return total + (attachment.size || 0);
|
|
67
75
|
}, 0) || 0;
|
|
68
76
|
if (attachmentSize >= messages_js_1.Messages.MAXIMUM_JSON_ATTACHMENT_SIZE) {
|
|
69
77
|
const form = messages_js_1.Messages._buildFormRequest(requestBody);
|
|
@@ -74,6 +82,13 @@ class Drafts extends resource_js_1.Resource {
|
|
|
74
82
|
overrides,
|
|
75
83
|
});
|
|
76
84
|
}
|
|
85
|
+
else if (requestBody.attachments) {
|
|
86
|
+
const processedAttachments = await (0, utils_js_1.encodeAttachmentStreams)(requestBody.attachments);
|
|
87
|
+
requestBody = {
|
|
88
|
+
...requestBody,
|
|
89
|
+
attachments: processedAttachments,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
77
92
|
return super._update({
|
|
78
93
|
path,
|
|
79
94
|
requestBody,
|
|
@@ -62,7 +62,7 @@ class Messages extends resource_js_1.Resource {
|
|
|
62
62
|
* Send an email
|
|
63
63
|
* @return The sent message
|
|
64
64
|
*/
|
|
65
|
-
send({ identifier, requestBody, overrides, }) {
|
|
65
|
+
async send({ identifier, requestBody, overrides, }) {
|
|
66
66
|
const path = `/v3/grants/${identifier}/messages/send`;
|
|
67
67
|
const requestOptions = {
|
|
68
68
|
method: 'POST',
|
|
@@ -70,14 +70,23 @@ class Messages extends resource_js_1.Resource {
|
|
|
70
70
|
overrides,
|
|
71
71
|
};
|
|
72
72
|
// Use form data only if the attachment size is greater than 3mb
|
|
73
|
-
const attachmentSize = requestBody.attachments?.reduce(
|
|
74
|
-
return attachment.size || 0;
|
|
73
|
+
const attachmentSize = requestBody.attachments?.reduce((total, attachment) => {
|
|
74
|
+
return total + (attachment.size || 0);
|
|
75
75
|
}, 0) || 0;
|
|
76
76
|
if (attachmentSize >= Messages.MAXIMUM_JSON_ATTACHMENT_SIZE) {
|
|
77
77
|
requestOptions.form = Messages._buildFormRequest(requestBody);
|
|
78
78
|
}
|
|
79
79
|
else {
|
|
80
|
-
|
|
80
|
+
if (requestBody.attachments) {
|
|
81
|
+
const processedAttachments = await (0, utils_js_1.encodeAttachmentStreams)(requestBody.attachments);
|
|
82
|
+
requestOptions.body = {
|
|
83
|
+
...requestBody,
|
|
84
|
+
attachments: processedAttachments,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
requestOptions.body = requestBody;
|
|
89
|
+
}
|
|
81
90
|
}
|
|
82
91
|
return this.apiClient.request(requestOptions);
|
|
83
92
|
}
|
|
@@ -111,6 +120,18 @@ class Messages extends resource_js_1.Resource {
|
|
|
111
120
|
overrides,
|
|
112
121
|
});
|
|
113
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* Remove extra information from a list of messages
|
|
125
|
+
* @return The list of cleaned messages
|
|
126
|
+
*/
|
|
127
|
+
cleanMessages({ identifier, requestBody, overrides, }) {
|
|
128
|
+
return this.apiClient.request({
|
|
129
|
+
method: 'PUT',
|
|
130
|
+
path: `/v3/grants/${identifier}/messages/clean`,
|
|
131
|
+
body: requestBody,
|
|
132
|
+
overrides,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
114
135
|
static _buildFormRequest(requestBody) {
|
|
115
136
|
let form;
|
|
116
137
|
// FormData imports are funky, cjs needs to use .default, es6 doesn't
|
package/lib/cjs/utils.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.objKeysToSnakeCase = exports.objKeysToCamelCase = exports.createFileRequestBuilder = void 0;
|
|
3
|
+
exports.objKeysToSnakeCase = exports.objKeysToCamelCase = exports.encodeAttachmentStreams = exports.createFileRequestBuilder = void 0;
|
|
4
4
|
const change_case_1 = require("change-case");
|
|
5
5
|
const fs = require("fs");
|
|
6
6
|
const path = require("path");
|
|
7
7
|
const mime = require("mime-types");
|
|
8
|
+
const stream_1 = require("stream");
|
|
8
9
|
function createFileRequestBuilder(filePath) {
|
|
9
10
|
const stats = fs.statSync(filePath);
|
|
10
11
|
const filename = path.basename(filePath);
|
|
@@ -18,6 +19,40 @@ function createFileRequestBuilder(filePath) {
|
|
|
18
19
|
};
|
|
19
20
|
}
|
|
20
21
|
exports.createFileRequestBuilder = createFileRequestBuilder;
|
|
22
|
+
/**
|
|
23
|
+
* Converts a ReadableStream to a base64 encoded string.
|
|
24
|
+
* @param stream The ReadableStream containing the binary data.
|
|
25
|
+
* @returns The stream base64 encoded to a string.
|
|
26
|
+
*/
|
|
27
|
+
function streamToBase64(stream) {
|
|
28
|
+
return new Promise((resolve, reject) => {
|
|
29
|
+
const chunks = [];
|
|
30
|
+
stream.on('data', (chunk) => {
|
|
31
|
+
chunks.push(chunk);
|
|
32
|
+
});
|
|
33
|
+
stream.on('end', () => {
|
|
34
|
+
const base64 = Buffer.concat(chunks).toString('base64');
|
|
35
|
+
resolve(base64);
|
|
36
|
+
});
|
|
37
|
+
stream.on('error', err => {
|
|
38
|
+
reject(err);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Encodes the content of each attachment stream to base64.
|
|
44
|
+
* @param attachments The attachments to encode.
|
|
45
|
+
* @returns The attachments with their content encoded to base64.
|
|
46
|
+
*/
|
|
47
|
+
async function encodeAttachmentStreams(attachments) {
|
|
48
|
+
return await Promise.all(attachments.map(async (attachment) => {
|
|
49
|
+
const base64EncodedContent = attachment.content instanceof stream_1.Readable
|
|
50
|
+
? await streamToBase64(attachment.content)
|
|
51
|
+
: attachment.content;
|
|
52
|
+
return { ...attachment, content: base64EncodedContent }; // Replace the stream with its base64 string
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
55
|
+
exports.encodeAttachmentStreams = encodeAttachmentStreams;
|
|
21
56
|
/**
|
|
22
57
|
* Applies the casing function and ensures numeric parts are preceded by underscores in snake_case.
|
|
23
58
|
* @param casingFunction The original casing function.
|
package/lib/cjs/version.js
CHANGED
package/lib/esm/apiClient.js
CHANGED
|
@@ -7,10 +7,11 @@ import { SDK_VERSION } from './version.js';
|
|
|
7
7
|
* @ignore Not for public use
|
|
8
8
|
*/
|
|
9
9
|
export default class APIClient {
|
|
10
|
-
constructor({ apiKey, apiUri, timeout }) {
|
|
10
|
+
constructor({ apiKey, apiUri, timeout, headers }) {
|
|
11
11
|
this.apiKey = apiKey;
|
|
12
12
|
this.serverUrl = apiUri;
|
|
13
13
|
this.timeout = timeout * 1000; // fetch timeout uses milliseconds
|
|
14
|
+
this.headers = headers;
|
|
14
15
|
}
|
|
15
16
|
setRequestUrl({ overrides, path, queryParams, }) {
|
|
16
17
|
const url = new URL(`${overrides?.apiUri || this.serverUrl}${path}`);
|
|
@@ -37,11 +38,16 @@ export default class APIClient {
|
|
|
37
38
|
return url;
|
|
38
39
|
}
|
|
39
40
|
setRequestHeaders({ headers, overrides, }) {
|
|
41
|
+
const mergedHeaders = {
|
|
42
|
+
...headers,
|
|
43
|
+
...this.headers,
|
|
44
|
+
...overrides?.headers,
|
|
45
|
+
};
|
|
40
46
|
return {
|
|
41
47
|
Accept: 'application/json',
|
|
42
48
|
'User-Agent': `Nylas Node SDK v${SDK_VERSION}`,
|
|
43
49
|
Authorization: `Bearer ${overrides?.apiKey || this.apiKey}`,
|
|
44
|
-
...
|
|
50
|
+
...mergedHeaders,
|
|
45
51
|
};
|
|
46
52
|
}
|
|
47
53
|
async sendRequest(options) {
|
package/lib/esm/nylas.js
CHANGED
|
@@ -29,6 +29,7 @@ export default class Nylas {
|
|
|
29
29
|
apiKey: config.apiKey,
|
|
30
30
|
apiUri: config.apiUri || DEFAULT_SERVER_URL,
|
|
31
31
|
timeout: config.timeout || 90,
|
|
32
|
+
headers: config.headers || {},
|
|
32
33
|
});
|
|
33
34
|
this.applications = new Applications(this.apiClient);
|
|
34
35
|
this.auth = new Auth(this.apiClient);
|
|
@@ -146,9 +146,9 @@ export class Auth extends Resource {
|
|
|
146
146
|
}
|
|
147
147
|
if (config.loginHint) {
|
|
148
148
|
url.searchParams.set('login_hint', config.loginHint);
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
149
|
+
}
|
|
150
|
+
if (config.includeGrantScopes !== undefined) {
|
|
151
|
+
url.searchParams.set('include_grant_scopes', config.includeGrantScopes.toString());
|
|
152
152
|
}
|
|
153
153
|
if (config.scope) {
|
|
154
154
|
url.searchParams.set('scope', config.scope.join(' '));
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Messages } from './messages.js';
|
|
2
2
|
import { Resource } from './resource.js';
|
|
3
|
+
import { encodeAttachmentStreams } from '../utils.js';
|
|
3
4
|
/**
|
|
4
5
|
* Nylas Drafts API
|
|
5
6
|
*
|
|
@@ -31,11 +32,11 @@ export class Drafts extends Resource {
|
|
|
31
32
|
* Return a Draft
|
|
32
33
|
* @return The draft
|
|
33
34
|
*/
|
|
34
|
-
create({ identifier, requestBody, overrides, }) {
|
|
35
|
+
async create({ identifier, requestBody, overrides, }) {
|
|
35
36
|
const path = `/v3/grants/${identifier}/drafts`;
|
|
36
37
|
// Use form data only if the attachment size is greater than 3mb
|
|
37
|
-
const attachmentSize = requestBody.attachments?.reduce(
|
|
38
|
-
return attachment.size || 0;
|
|
38
|
+
const attachmentSize = requestBody.attachments?.reduce((total, attachment) => {
|
|
39
|
+
return total + (attachment.size || 0);
|
|
39
40
|
}, 0) || 0;
|
|
40
41
|
if (attachmentSize >= Messages.MAXIMUM_JSON_ATTACHMENT_SIZE) {
|
|
41
42
|
const form = Messages._buildFormRequest(requestBody);
|
|
@@ -46,6 +47,13 @@ export class Drafts extends Resource {
|
|
|
46
47
|
overrides,
|
|
47
48
|
});
|
|
48
49
|
}
|
|
50
|
+
else if (requestBody.attachments) {
|
|
51
|
+
const processedAttachments = await encodeAttachmentStreams(requestBody.attachments);
|
|
52
|
+
requestBody = {
|
|
53
|
+
...requestBody,
|
|
54
|
+
attachments: processedAttachments,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
49
57
|
return super._create({
|
|
50
58
|
path,
|
|
51
59
|
requestBody,
|
|
@@ -56,11 +64,11 @@ export class Drafts extends Resource {
|
|
|
56
64
|
* Update a Draft
|
|
57
65
|
* @return The updated draft
|
|
58
66
|
*/
|
|
59
|
-
update({ identifier, draftId, requestBody, overrides, }) {
|
|
67
|
+
async update({ identifier, draftId, requestBody, overrides, }) {
|
|
60
68
|
const path = `/v3/grants/${identifier}/drafts/${draftId}`;
|
|
61
69
|
// Use form data only if the attachment size is greater than 3mb
|
|
62
|
-
const attachmentSize = requestBody.attachments?.reduce(
|
|
63
|
-
return attachment.size || 0;
|
|
70
|
+
const attachmentSize = requestBody.attachments?.reduce((total, attachment) => {
|
|
71
|
+
return total + (attachment.size || 0);
|
|
64
72
|
}, 0) || 0;
|
|
65
73
|
if (attachmentSize >= Messages.MAXIMUM_JSON_ATTACHMENT_SIZE) {
|
|
66
74
|
const form = Messages._buildFormRequest(requestBody);
|
|
@@ -71,6 +79,13 @@ export class Drafts extends Resource {
|
|
|
71
79
|
overrides,
|
|
72
80
|
});
|
|
73
81
|
}
|
|
82
|
+
else if (requestBody.attachments) {
|
|
83
|
+
const processedAttachments = await encodeAttachmentStreams(requestBody.attachments);
|
|
84
|
+
requestBody = {
|
|
85
|
+
...requestBody,
|
|
86
|
+
attachments: processedAttachments,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
74
89
|
return super._update({
|
|
75
90
|
path,
|
|
76
91
|
requestBody,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Resource } from './resource.js';
|
|
2
2
|
import * as FormData from 'form-data';
|
|
3
|
-
import { objKeysToSnakeCase } from '../utils.js';
|
|
3
|
+
import { encodeAttachmentStreams, objKeysToSnakeCase } from '../utils.js';
|
|
4
4
|
import { SmartCompose } from './smartCompose.js';
|
|
5
5
|
/**
|
|
6
6
|
* Nylas Messages API
|
|
@@ -59,7 +59,7 @@ export class Messages extends Resource {
|
|
|
59
59
|
* Send an email
|
|
60
60
|
* @return The sent message
|
|
61
61
|
*/
|
|
62
|
-
send({ identifier, requestBody, overrides, }) {
|
|
62
|
+
async send({ identifier, requestBody, overrides, }) {
|
|
63
63
|
const path = `/v3/grants/${identifier}/messages/send`;
|
|
64
64
|
const requestOptions = {
|
|
65
65
|
method: 'POST',
|
|
@@ -67,14 +67,23 @@ export class Messages extends Resource {
|
|
|
67
67
|
overrides,
|
|
68
68
|
};
|
|
69
69
|
// Use form data only if the attachment size is greater than 3mb
|
|
70
|
-
const attachmentSize = requestBody.attachments?.reduce(
|
|
71
|
-
return attachment.size || 0;
|
|
70
|
+
const attachmentSize = requestBody.attachments?.reduce((total, attachment) => {
|
|
71
|
+
return total + (attachment.size || 0);
|
|
72
72
|
}, 0) || 0;
|
|
73
73
|
if (attachmentSize >= Messages.MAXIMUM_JSON_ATTACHMENT_SIZE) {
|
|
74
74
|
requestOptions.form = Messages._buildFormRequest(requestBody);
|
|
75
75
|
}
|
|
76
76
|
else {
|
|
77
|
-
|
|
77
|
+
if (requestBody.attachments) {
|
|
78
|
+
const processedAttachments = await encodeAttachmentStreams(requestBody.attachments);
|
|
79
|
+
requestOptions.body = {
|
|
80
|
+
...requestBody,
|
|
81
|
+
attachments: processedAttachments,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
requestOptions.body = requestBody;
|
|
86
|
+
}
|
|
78
87
|
}
|
|
79
88
|
return this.apiClient.request(requestOptions);
|
|
80
89
|
}
|
|
@@ -108,6 +117,18 @@ export class Messages extends Resource {
|
|
|
108
117
|
overrides,
|
|
109
118
|
});
|
|
110
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* Remove extra information from a list of messages
|
|
122
|
+
* @return The list of cleaned messages
|
|
123
|
+
*/
|
|
124
|
+
cleanMessages({ identifier, requestBody, overrides, }) {
|
|
125
|
+
return this.apiClient.request({
|
|
126
|
+
method: 'PUT',
|
|
127
|
+
path: `/v3/grants/${identifier}/messages/clean`,
|
|
128
|
+
body: requestBody,
|
|
129
|
+
overrides,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
111
132
|
static _buildFormRequest(requestBody) {
|
|
112
133
|
let form;
|
|
113
134
|
// FormData imports are funky, cjs needs to use .default, es6 doesn't
|
package/lib/esm/utils.js
CHANGED
|
@@ -2,6 +2,7 @@ import { camelCase, snakeCase } from 'change-case';
|
|
|
2
2
|
import * as fs from 'fs';
|
|
3
3
|
import * as path from 'path';
|
|
4
4
|
import * as mime from 'mime-types';
|
|
5
|
+
import { Readable } from 'stream';
|
|
5
6
|
export function createFileRequestBuilder(filePath) {
|
|
6
7
|
const stats = fs.statSync(filePath);
|
|
7
8
|
const filename = path.basename(filePath);
|
|
@@ -14,6 +15,39 @@ export function createFileRequestBuilder(filePath) {
|
|
|
14
15
|
size: stats.size,
|
|
15
16
|
};
|
|
16
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Converts a ReadableStream to a base64 encoded string.
|
|
20
|
+
* @param stream The ReadableStream containing the binary data.
|
|
21
|
+
* @returns The stream base64 encoded to a string.
|
|
22
|
+
*/
|
|
23
|
+
function streamToBase64(stream) {
|
|
24
|
+
return new Promise((resolve, reject) => {
|
|
25
|
+
const chunks = [];
|
|
26
|
+
stream.on('data', (chunk) => {
|
|
27
|
+
chunks.push(chunk);
|
|
28
|
+
});
|
|
29
|
+
stream.on('end', () => {
|
|
30
|
+
const base64 = Buffer.concat(chunks).toString('base64');
|
|
31
|
+
resolve(base64);
|
|
32
|
+
});
|
|
33
|
+
stream.on('error', err => {
|
|
34
|
+
reject(err);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Encodes the content of each attachment stream to base64.
|
|
40
|
+
* @param attachments The attachments to encode.
|
|
41
|
+
* @returns The attachments with their content encoded to base64.
|
|
42
|
+
*/
|
|
43
|
+
export async function encodeAttachmentStreams(attachments) {
|
|
44
|
+
return await Promise.all(attachments.map(async (attachment) => {
|
|
45
|
+
const base64EncodedContent = attachment.content instanceof Readable
|
|
46
|
+
? await streamToBase64(attachment.content)
|
|
47
|
+
: attachment.content;
|
|
48
|
+
return { ...attachment, content: base64EncodedContent }; // Replace the stream with its base64 string
|
|
49
|
+
}));
|
|
50
|
+
}
|
|
17
51
|
/**
|
|
18
52
|
* Applies the casing function and ensures numeric parts are preceded by underscores in snake_case.
|
|
19
53
|
* @param casingFunction The original casing function.
|
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 = '7.
|
|
2
|
+
export const SDK_VERSION = '7.4.0';
|
package/lib/types/apiClient.d.ts
CHANGED
|
@@ -57,7 +57,11 @@ export default class APIClient {
|
|
|
57
57
|
* The timeout for requests to the Nylas API, in seconds
|
|
58
58
|
*/
|
|
59
59
|
timeout: number;
|
|
60
|
-
|
|
60
|
+
/**
|
|
61
|
+
* Additional headers to send with outgoing requests
|
|
62
|
+
*/
|
|
63
|
+
headers: Record<string, string>;
|
|
64
|
+
constructor({ apiKey, apiUri, timeout, headers }: Required<NylasConfig>);
|
|
61
65
|
private setRequestUrl;
|
|
62
66
|
private setQueryStrings;
|
|
63
67
|
private setRequestHeaders;
|
package/lib/types/config.d.ts
CHANGED
|
@@ -3,11 +3,13 @@
|
|
|
3
3
|
* @property apiKey The Nylas API key to use for authentication
|
|
4
4
|
* @property apiUri The URL to use for communicating with the Nylas API
|
|
5
5
|
* @property timeout The timeout for requests to the Nylas API, in seconds
|
|
6
|
+
* @property headers Additional headers to send with outgoing requests
|
|
6
7
|
*/
|
|
7
8
|
export type NylasConfig = {
|
|
8
9
|
apiKey: string;
|
|
9
10
|
apiUri?: string;
|
|
10
11
|
timeout?: number;
|
|
12
|
+
headers?: Record<string, string>;
|
|
11
13
|
};
|
|
12
14
|
/**
|
|
13
15
|
* The options that can override the default Nylas API client configuration.
|
|
@@ -34,8 +34,9 @@ interface BaseAttachment {
|
|
|
34
34
|
export interface CreateAttachmentRequest extends BaseAttachment {
|
|
35
35
|
/**
|
|
36
36
|
* Content of the attachment.
|
|
37
|
+
* It can either be a readable stream or a base64 encoded string.
|
|
37
38
|
*/
|
|
38
|
-
content: NodeJS.ReadableStream;
|
|
39
|
+
content: NodeJS.ReadableStream | string;
|
|
39
40
|
}
|
|
40
41
|
/**
|
|
41
42
|
* Interface of an attachment object from Nylas.
|
|
@@ -158,6 +158,10 @@ export interface CodeExchangeResponse {
|
|
|
158
158
|
* Currently always Bearer.
|
|
159
159
|
*/
|
|
160
160
|
tokenType?: string;
|
|
161
|
+
/**
|
|
162
|
+
* The provider that the code was exchanged with.
|
|
163
|
+
*/
|
|
164
|
+
provider?: Provider;
|
|
161
165
|
}
|
|
162
166
|
/**
|
|
163
167
|
* Interface representing the object used to set parameters for detecting a provider.
|
|
@@ -2,6 +2,16 @@ import { BaseMessage } from './messages.js';
|
|
|
2
2
|
import { ListQueryParams } from './listQueryParams.js';
|
|
3
3
|
import { EmailName } from './events.js';
|
|
4
4
|
import { CreateAttachmentRequest } from './attachments.js';
|
|
5
|
+
export interface CustomHeader {
|
|
6
|
+
/**
|
|
7
|
+
* The name of the custom header.
|
|
8
|
+
*/
|
|
9
|
+
name: string;
|
|
10
|
+
/**
|
|
11
|
+
* The value of the custom header.
|
|
12
|
+
*/
|
|
13
|
+
value: string;
|
|
14
|
+
}
|
|
5
15
|
/**
|
|
6
16
|
* Interface representing a request to create a draft.
|
|
7
17
|
*/
|
|
@@ -55,6 +65,10 @@ export interface CreateDraftRequest {
|
|
|
55
65
|
* Options for tracking opens, links, and thread replies.
|
|
56
66
|
*/
|
|
57
67
|
trackingOptions?: TrackingOptions;
|
|
68
|
+
/**
|
|
69
|
+
* An array of custom headers to add to the message.
|
|
70
|
+
*/
|
|
71
|
+
customHeaders?: CustomHeader[];
|
|
58
72
|
}
|
|
59
73
|
/**
|
|
60
74
|
* Interface representing a request to send a message.
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { ListQueryParams } from './listQueryParams.js';
|
|
2
2
|
import { Subset } from '../utils.js';
|
|
3
|
+
import { NylasBaseResponse } from './response.js';
|
|
4
|
+
import { NylasApiErrorResponseData } from './error.js';
|
|
3
5
|
/**
|
|
4
6
|
* Interface representing a Nylas Event object.
|
|
5
7
|
*/
|
|
@@ -192,6 +194,13 @@ export type UpdateEventRequest = Subset<CreateEventRequest>;
|
|
|
192
194
|
export type SendRsvpRequest = {
|
|
193
195
|
status: RsvpStatus;
|
|
194
196
|
};
|
|
197
|
+
/**
|
|
198
|
+
* Interface representing the response from sending RSVP to an event.
|
|
199
|
+
* @property sendIcsError If the send-rsvp request succeeded but the ICS email could not be sent, this will contain the error.
|
|
200
|
+
*/
|
|
201
|
+
export interface SendRsvpResponse extends NylasBaseResponse {
|
|
202
|
+
sendIcsError?: NylasApiErrorResponseData;
|
|
203
|
+
}
|
|
195
204
|
/**
|
|
196
205
|
* Interface representing the query parameters for listing events.
|
|
197
206
|
*/
|
|
@@ -329,7 +338,7 @@ type When = Time | Timespan | Date | Datespan;
|
|
|
329
338
|
/**
|
|
330
339
|
* Type representing the different objects representing time and duration when creating events.
|
|
331
340
|
*/
|
|
332
|
-
type CreateWhen = Omit<Time, '
|
|
341
|
+
type CreateWhen = Omit<Time, 'object'> | Omit<Timespan, 'object'> | Omit<Date, 'object'> | Omit<Datespan, 'object'>;
|
|
333
342
|
/**
|
|
334
343
|
* Enum representing the different types of when objects.
|
|
335
344
|
*/
|
|
@@ -409,7 +418,7 @@ export interface Time {
|
|
|
409
418
|
/**
|
|
410
419
|
* The type of 'when' object.
|
|
411
420
|
*/
|
|
412
|
-
|
|
421
|
+
object: WhenType.Time;
|
|
413
422
|
}
|
|
414
423
|
/**
|
|
415
424
|
* Class representation of a time span with start and end times.
|
|
@@ -439,7 +448,7 @@ export interface Timespan {
|
|
|
439
448
|
/**
|
|
440
449
|
* The type of 'when' object.
|
|
441
450
|
*/
|
|
442
|
-
|
|
451
|
+
object: WhenType.Timespan;
|
|
443
452
|
}
|
|
444
453
|
/**
|
|
445
454
|
* Class representation of an entire day spans without specific times.
|
|
@@ -454,7 +463,7 @@ export interface Date {
|
|
|
454
463
|
/**
|
|
455
464
|
* The type of 'when' object.
|
|
456
465
|
*/
|
|
457
|
-
|
|
466
|
+
object: WhenType.Date;
|
|
458
467
|
}
|
|
459
468
|
/**
|
|
460
469
|
* Class representation of a specific dates without clock-based start or end times.
|
|
@@ -474,7 +483,7 @@ export interface Datespan {
|
|
|
474
483
|
/**
|
|
475
484
|
* The type of 'when' object.
|
|
476
485
|
*/
|
|
477
|
-
|
|
486
|
+
object: WhenType.Datespan;
|
|
478
487
|
}
|
|
479
488
|
/**
|
|
480
489
|
* Interface representing an Event participant.
|
|
@@ -523,7 +532,7 @@ export interface ReminderOverride {
|
|
|
523
532
|
* The number of minutes before the event start time when a user wants a reminder for this event.
|
|
524
533
|
* Reminder minutes are in the following format: "[20]".
|
|
525
534
|
*/
|
|
526
|
-
reminderMinutes:
|
|
535
|
+
reminderMinutes: number;
|
|
527
536
|
/**
|
|
528
537
|
* Method to remind the user about the event. (Google only).
|
|
529
538
|
*/
|
|
@@ -273,3 +273,41 @@ export interface FindMessageQueryParams {
|
|
|
273
273
|
*/
|
|
274
274
|
fields?: MessageFields;
|
|
275
275
|
}
|
|
276
|
+
/**
|
|
277
|
+
* Interface representing the request to clean a message.
|
|
278
|
+
*/
|
|
279
|
+
export interface CleanMessagesRequest {
|
|
280
|
+
/**
|
|
281
|
+
* IDs of the email messages to clean.
|
|
282
|
+
*/
|
|
283
|
+
messageId: string[];
|
|
284
|
+
/**
|
|
285
|
+
* If true, removes link-related tags (<a>) from the email message while keeping the text.
|
|
286
|
+
*/
|
|
287
|
+
ignoreLinks?: boolean;
|
|
288
|
+
/**
|
|
289
|
+
* If true, removes images from the email message.
|
|
290
|
+
*/
|
|
291
|
+
ignoreImages?: boolean;
|
|
292
|
+
/**
|
|
293
|
+
* If true, converts images in the email message to Markdown.
|
|
294
|
+
*/
|
|
295
|
+
imagesAsMarkdown?: boolean;
|
|
296
|
+
/**
|
|
297
|
+
* If true, removes table-related tags (<table>, <th>, <td>, <tr>) from the email message while keeping rows.
|
|
298
|
+
*/
|
|
299
|
+
ignoreTables?: boolean;
|
|
300
|
+
/**
|
|
301
|
+
* If true, removes phrases such as "Best" and "Regards" in the email message signature.
|
|
302
|
+
*/
|
|
303
|
+
removeConclusionPhrases?: boolean;
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Interface representing the response after cleaning a message.
|
|
307
|
+
*/
|
|
308
|
+
export interface CleanMessagesResponse extends Message {
|
|
309
|
+
/**
|
|
310
|
+
* The cleaned HTML message body.
|
|
311
|
+
*/
|
|
312
|
+
conversation: string;
|
|
313
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Overrides } from '../config.js';
|
|
2
|
-
import { CreateEventQueryParams, CreateEventRequest, DestroyEventQueryParams, Event, FindEventQueryParams, ListEventQueryParams, SendRsvpQueryParams, SendRsvpRequest, UpdateEventQueryParams, UpdateEventRequest } from '../models/events.js';
|
|
2
|
+
import { CreateEventQueryParams, CreateEventRequest, DestroyEventQueryParams, Event, FindEventQueryParams, ListEventQueryParams, SendRsvpQueryParams, SendRsvpRequest, SendRsvpResponse, UpdateEventQueryParams, UpdateEventRequest } from '../models/events.js';
|
|
3
3
|
import { NylasBaseResponse, NylasResponse, NylasListResponse } from '../models/response.js';
|
|
4
4
|
import { AsyncListResponse, Resource } from './resource.js';
|
|
5
5
|
/**
|
|
@@ -101,6 +101,6 @@ export declare class Events extends Resource {
|
|
|
101
101
|
* You cannot directly update events as an invitee, since you are not the owner/organizer.
|
|
102
102
|
* @return The send-rsvp response
|
|
103
103
|
*/
|
|
104
|
-
sendRsvp({ identifier, eventId, requestBody, queryParams, overrides, }: SendRsvpParams & Overrides): Promise<
|
|
104
|
+
sendRsvp({ identifier, eventId, requestBody, queryParams, overrides, }: SendRsvpParams & Overrides): Promise<SendRsvpResponse>;
|
|
105
105
|
}
|
|
106
106
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AsyncListResponse, Resource } from './resource.js';
|
|
2
|
-
import { FindMessageQueryParams, ListMessagesQueryParams, Message, ScheduledMessage, ScheduledMessagesList, StopScheduledMessageResponse, UpdateMessageRequest } from '../models/messages.js';
|
|
2
|
+
import { CleanMessagesRequest, CleanMessagesResponse, FindMessageQueryParams, ListMessagesQueryParams, Message, ScheduledMessage, ScheduledMessagesList, StopScheduledMessageResponse, UpdateMessageRequest } from '../models/messages.js';
|
|
3
3
|
import { Overrides } from '../config.js';
|
|
4
4
|
import { NylasBaseResponse, NylasListResponse, NylasResponse } from '../models/response.js';
|
|
5
5
|
import { CreateDraftRequest, SendMessageRequest, UpdateDraftRequest } from '../models/drafts.js';
|
|
@@ -77,6 +77,15 @@ export interface FindScheduledMessageParams {
|
|
|
77
77
|
* @property scheduleId The id of the scheduled message to destroy.
|
|
78
78
|
*/
|
|
79
79
|
export type StopScheduledMessageParams = FindScheduledMessageParams;
|
|
80
|
+
/**
|
|
81
|
+
* The parameters for the {@link Messages.cleanMessages} method
|
|
82
|
+
* @property identifier The identifier of the grant to act upon
|
|
83
|
+
* @property requestBody The values to clean the message with
|
|
84
|
+
*/
|
|
85
|
+
export interface CleanMessagesParams {
|
|
86
|
+
identifier: string;
|
|
87
|
+
requestBody: CleanMessagesRequest;
|
|
88
|
+
}
|
|
80
89
|
/**
|
|
81
90
|
* Nylas Messages API
|
|
82
91
|
*
|
|
@@ -126,5 +135,10 @@ export declare class Messages extends Resource {
|
|
|
126
135
|
* @return The confirmation of the stopped scheduled message
|
|
127
136
|
*/
|
|
128
137
|
stopScheduledMessage({ identifier, scheduleId, overrides, }: StopScheduledMessageParams & Overrides): Promise<NylasResponse<StopScheduledMessageResponse>>;
|
|
138
|
+
/**
|
|
139
|
+
* Remove extra information from a list of messages
|
|
140
|
+
* @return The list of cleaned messages
|
|
141
|
+
*/
|
|
142
|
+
cleanMessages({ identifier, requestBody, overrides, }: CleanMessagesParams & Overrides): Promise<NylasListResponse<CleanMessagesResponse>>;
|
|
129
143
|
static _buildFormRequest(requestBody: CreateDraftRequest | UpdateDraftRequest | SendMessageRequest): FormData;
|
|
130
144
|
}
|
package/lib/types/utils.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { CreateAttachmentRequest } from './models/attachments.js';
|
|
2
2
|
export declare function createFileRequestBuilder(filePath: string): CreateAttachmentRequest;
|
|
3
|
+
/**
|
|
4
|
+
* Encodes the content of each attachment stream to base64.
|
|
5
|
+
* @param attachments The attachments to encode.
|
|
6
|
+
* @returns The attachments with their content encoded to base64.
|
|
7
|
+
*/
|
|
8
|
+
export declare function encodeAttachmentStreams(attachments: CreateAttachmentRequest[]): Promise<CreateAttachmentRequest[]>;
|
|
3
9
|
/**
|
|
4
10
|
* A utility function that recursively converts all keys in an object to camelCase.
|
|
5
11
|
* @param obj The object to convert
|
package/lib/types/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "7.
|
|
1
|
+
export declare const SDK_VERSION = "7.4.0";
|