nylas 7.3.0 → 7.5.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 +14 -3
- package/lib/cjs/resources/drafts.js +21 -6
- package/lib/cjs/resources/folders.js +2 -1
- 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 +14 -3
- package/lib/esm/resources/drafts.js +21 -6
- package/lib/esm/resources/folders.js +2 -1
- 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/models/attachments.d.ts +2 -1
- package/lib/types/models/auth.d.ts +4 -0
- package/lib/types/models/events.d.ts +9 -0
- package/lib/types/models/folders.d.ts +10 -0
- package/lib/types/models/messages.d.ts +38 -0
- package/lib/types/resources/folders.d.ts +4 -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
|
@@ -4,6 +4,7 @@ const node_fetch_1 = require("node-fetch");
|
|
|
4
4
|
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
|
+
const change_case_1 = require("change-case");
|
|
7
8
|
/**
|
|
8
9
|
* The API client for communicating with the Nylas API
|
|
9
10
|
* @ignore Not for public use
|
|
@@ -21,8 +22,8 @@ class APIClient {
|
|
|
21
22
|
}
|
|
22
23
|
setQueryStrings(url, queryParams) {
|
|
23
24
|
if (queryParams) {
|
|
24
|
-
const
|
|
25
|
-
|
|
25
|
+
for (const [key, value] of Object.entries(queryParams)) {
|
|
26
|
+
const snakeCaseKey = (0, change_case_1.snakeCase)(key);
|
|
26
27
|
if (key == 'metadataPair') {
|
|
27
28
|
// The API understands a metadata_pair filter in the form of:
|
|
28
29
|
// <key>:<value>
|
|
@@ -32,8 +33,18 @@ class APIClient {
|
|
|
32
33
|
}
|
|
33
34
|
url.searchParams.set('metadata_pair', metadataPair.join(','));
|
|
34
35
|
}
|
|
36
|
+
else if (Array.isArray(value)) {
|
|
37
|
+
for (const item of value) {
|
|
38
|
+
url.searchParams.append(snakeCaseKey, item);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else if (typeof value === 'object') {
|
|
42
|
+
for (const item in value) {
|
|
43
|
+
url.searchParams.append(snakeCaseKey, `${item}:${value[item]}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
35
46
|
else {
|
|
36
|
-
url.searchParams.set(
|
|
47
|
+
url.searchParams.set(snakeCaseKey, value);
|
|
37
48
|
}
|
|
38
49
|
}
|
|
39
50
|
}
|
|
@@ -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,
|
|
@@ -20,9 +20,10 @@ class Folders extends resource_js_1.Resource {
|
|
|
20
20
|
* Return all Folders
|
|
21
21
|
* @return A list of folders
|
|
22
22
|
*/
|
|
23
|
-
list({ identifier, overrides, }) {
|
|
23
|
+
list({ identifier, queryParams, overrides, }) {
|
|
24
24
|
return super._list({
|
|
25
25
|
overrides,
|
|
26
|
+
queryParams,
|
|
26
27
|
path: `/v3/grants/${identifier}/folders`,
|
|
27
28
|
});
|
|
28
29
|
}
|
|
@@ -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
|
@@ -2,6 +2,7 @@ import fetch, { Request } from 'node-fetch';
|
|
|
2
2
|
import { NylasApiError, NylasOAuthError, NylasSdkTimeoutError, } from './models/error.js';
|
|
3
3
|
import { objKeysToCamelCase, objKeysToSnakeCase } from './utils.js';
|
|
4
4
|
import { SDK_VERSION } from './version.js';
|
|
5
|
+
import { snakeCase } from 'change-case';
|
|
5
6
|
/**
|
|
6
7
|
* The API client for communicating with the Nylas API
|
|
7
8
|
* @ignore Not for public use
|
|
@@ -19,8 +20,8 @@ export default class APIClient {
|
|
|
19
20
|
}
|
|
20
21
|
setQueryStrings(url, queryParams) {
|
|
21
22
|
if (queryParams) {
|
|
22
|
-
const
|
|
23
|
-
|
|
23
|
+
for (const [key, value] of Object.entries(queryParams)) {
|
|
24
|
+
const snakeCaseKey = snakeCase(key);
|
|
24
25
|
if (key == 'metadataPair') {
|
|
25
26
|
// The API understands a metadata_pair filter in the form of:
|
|
26
27
|
// <key>:<value>
|
|
@@ -30,8 +31,18 @@ export default class APIClient {
|
|
|
30
31
|
}
|
|
31
32
|
url.searchParams.set('metadata_pair', metadataPair.join(','));
|
|
32
33
|
}
|
|
34
|
+
else if (Array.isArray(value)) {
|
|
35
|
+
for (const item of value) {
|
|
36
|
+
url.searchParams.append(snakeCaseKey, item);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
else if (typeof value === 'object') {
|
|
40
|
+
for (const item in value) {
|
|
41
|
+
url.searchParams.append(snakeCaseKey, `${item}:${value[item]}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
33
44
|
else {
|
|
34
|
-
url.searchParams.set(
|
|
45
|
+
url.searchParams.set(snakeCaseKey, value);
|
|
35
46
|
}
|
|
36
47
|
}
|
|
37
48
|
}
|
|
@@ -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,
|
|
@@ -17,9 +17,10 @@ export class Folders extends Resource {
|
|
|
17
17
|
* Return all Folders
|
|
18
18
|
* @return A list of folders
|
|
19
19
|
*/
|
|
20
|
-
list({ identifier, overrides, }) {
|
|
20
|
+
list({ identifier, queryParams, overrides, }) {
|
|
21
21
|
return super._list({
|
|
22
22
|
overrides,
|
|
23
|
+
queryParams,
|
|
23
24
|
path: `/v3/grants/${identifier}/folders`,
|
|
24
25
|
});
|
|
25
26
|
}
|
|
@@ -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.5.0';
|
|
@@ -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.
|
|
@@ -268,6 +268,11 @@ export interface ListEventQueryParams extends ListQueryParams {
|
|
|
268
268
|
* This value should be taken from the {@link NylasListResponse.nextCursor} response field.
|
|
269
269
|
*/
|
|
270
270
|
pageToken?: string;
|
|
271
|
+
/**
|
|
272
|
+
* (Google only) Filter events by event type.
|
|
273
|
+
* You can pass the query parameter multiple times to select or exclude multiple event types.
|
|
274
|
+
*/
|
|
275
|
+
eventType?: EventType[];
|
|
271
276
|
}
|
|
272
277
|
/**
|
|
273
278
|
* Interface representing of the query parameters for creating an event.
|
|
@@ -551,4 +556,8 @@ export interface EmailName {
|
|
|
551
556
|
*/
|
|
552
557
|
name?: string;
|
|
553
558
|
}
|
|
559
|
+
/**
|
|
560
|
+
* Type representing the event type to filter by.
|
|
561
|
+
*/
|
|
562
|
+
export type EventType = 'default' | 'outOfOffice' | 'focusTime' | 'workingLocation';
|
|
554
563
|
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ListQueryParams } from './listQueryParams.js';
|
|
1
2
|
/**
|
|
2
3
|
* Interface of a folder object from Nylas.
|
|
3
4
|
*/
|
|
@@ -75,4 +76,13 @@ export interface CreateFolderRequest {
|
|
|
75
76
|
*/
|
|
76
77
|
backgroundColor?: string;
|
|
77
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Interface representing the query parameters for listing folders.
|
|
81
|
+
*/
|
|
82
|
+
export interface ListFolderQueryParams extends ListQueryParams {
|
|
83
|
+
/**
|
|
84
|
+
* (Microsoft and EWS only.) Use the ID of a folder to find all child folders it contains.
|
|
85
|
+
*/
|
|
86
|
+
parentId?: string;
|
|
87
|
+
}
|
|
78
88
|
export type UpdateFolderRequest = Partial<CreateFolderRequest>;
|
|
@@ -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,13 +1,15 @@
|
|
|
1
1
|
import { Overrides } from '../config.js';
|
|
2
|
-
import { Folder, CreateFolderRequest, UpdateFolderRequest } from '../models/folders.js';
|
|
2
|
+
import { Folder, CreateFolderRequest, UpdateFolderRequest, ListFolderQueryParams } from '../models/folders.js';
|
|
3
3
|
import { NylasBaseResponse, NylasResponse, NylasListResponse } from '../models/response.js';
|
|
4
4
|
import { Resource, AsyncListResponse } from './resource.js';
|
|
5
5
|
/**
|
|
6
6
|
* The parameters for the {@link Folders.list} method
|
|
7
7
|
* @property identifier The identifier of the grant to act upon
|
|
8
|
+
* @property queryParams The query parameters to include in the request
|
|
8
9
|
*/
|
|
9
10
|
interface ListFoldersParams {
|
|
10
11
|
identifier: string;
|
|
12
|
+
queryParams?: ListFolderQueryParams;
|
|
11
13
|
}
|
|
12
14
|
/**
|
|
13
15
|
* The parameters for the {@link Folders.find} method
|
|
@@ -65,7 +67,7 @@ export declare class Folders extends Resource {
|
|
|
65
67
|
* Return all Folders
|
|
66
68
|
* @return A list of folders
|
|
67
69
|
*/
|
|
68
|
-
list({ identifier, overrides, }: ListFoldersParams & Overrides): AsyncListResponse<NylasListResponse<Folder>>;
|
|
70
|
+
list({ identifier, queryParams, overrides, }: ListFoldersParams & Overrides): AsyncListResponse<NylasListResponse<Folder>>;
|
|
69
71
|
/**
|
|
70
72
|
* Return a Folder
|
|
71
73
|
* @return The folder
|
|
@@ -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.5.0";
|