nylas 7.0.0-beta.2 → 7.0.0-beta.4
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 +19 -10
- package/lib/cjs/apiClient.js +57 -32
- package/lib/cjs/models/attachments.js +2 -0
- package/lib/cjs/models/connectors.js +2 -0
- package/lib/cjs/models/contacts.js +2 -0
- package/lib/cjs/models/credentials.js +12 -0
- package/lib/cjs/models/drafts.js +2 -0
- package/lib/cjs/models/files.js +2 -0
- package/lib/cjs/models/folders.js +2 -0
- package/lib/cjs/models/freeBusy.js +11 -0
- package/lib/cjs/models/messages.js +11 -0
- package/lib/cjs/models/smartCompose.js +2 -0
- package/lib/cjs/models/threads.js +2 -0
- package/lib/cjs/models/webhooks.js +3 -0
- package/lib/cjs/nylas.js +16 -0
- package/lib/cjs/resources/attachments.js +57 -0
- package/lib/cjs/resources/auth.js +21 -16
- package/lib/cjs/resources/calendars.js +12 -0
- package/lib/cjs/resources/connectors.js +68 -0
- package/lib/cjs/resources/contacts.js +76 -0
- package/lib/cjs/resources/credentials.js +60 -0
- package/lib/cjs/resources/drafts.js +81 -0
- package/lib/cjs/resources/events.js +14 -0
- package/lib/cjs/resources/folders.js +72 -0
- package/lib/cjs/resources/grants.js +0 -11
- package/lib/cjs/resources/messages.js +128 -0
- package/lib/cjs/resources/redirectUris.js +1 -1
- package/lib/cjs/resources/resource.js +16 -0
- package/lib/cjs/resources/smartCompose.js +34 -0
- package/lib/cjs/resources/threads.js +54 -0
- package/lib/cjs/utils.js +17 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/apiClient.js +57 -32
- package/lib/esm/models/attachments.js +1 -0
- package/lib/esm/models/connectors.js +1 -0
- package/lib/esm/models/contacts.js +1 -0
- package/lib/esm/models/credentials.js +9 -0
- package/lib/esm/models/drafts.js +1 -0
- package/lib/esm/models/files.js +1 -0
- package/lib/esm/models/folders.js +1 -0
- package/lib/esm/models/freeBusy.js +8 -0
- package/lib/esm/models/messages.js +8 -0
- package/lib/esm/models/smartCompose.js +1 -0
- package/lib/esm/models/threads.js +1 -0
- package/lib/esm/models/webhooks.js +3 -0
- package/lib/esm/nylas.js +16 -0
- package/lib/esm/resources/attachments.js +53 -0
- package/lib/esm/resources/auth.js +21 -16
- package/lib/esm/resources/calendars.js +12 -0
- package/lib/esm/resources/connectors.js +64 -0
- package/lib/esm/resources/contacts.js +72 -0
- package/lib/esm/resources/credentials.js +56 -0
- package/lib/esm/resources/drafts.js +77 -0
- package/lib/esm/resources/events.js +14 -0
- package/lib/esm/resources/folders.js +68 -0
- package/lib/esm/resources/grants.js +0 -11
- package/lib/esm/resources/messages.js +124 -0
- package/lib/esm/resources/redirectUris.js +1 -1
- package/lib/esm/resources/resource.js +16 -0
- package/lib/esm/resources/smartCompose.js +30 -0
- package/lib/esm/resources/threads.js +50 -0
- package/lib/esm/utils.js +15 -0
- package/lib/esm/version.js +1 -1
- package/lib/types/apiClient.d.ts +8 -1
- package/lib/types/models/attachments.d.ts +42 -0
- package/lib/types/models/auth.d.ts +5 -1
- package/lib/types/models/calendars.d.ts +1 -1
- package/lib/types/models/connectors.d.ts +123 -0
- package/lib/types/models/contacts.d.ts +148 -0
- package/lib/types/models/credentials.d.ts +151 -0
- package/lib/types/models/drafts.d.ts +92 -0
- package/lib/types/models/events.d.ts +14 -0
- package/lib/types/models/files.d.ts +17 -0
- package/lib/types/models/folders.d.ts +71 -0
- package/lib/types/models/freeBusy.d.ts +79 -0
- package/lib/types/models/messages.d.ts +271 -0
- package/lib/types/models/response.d.ts +6 -6
- package/lib/types/models/smartCompose.d.ts +18 -0
- package/lib/types/models/threads.d.ts +153 -0
- package/lib/types/models/webhooks.d.ts +80 -2
- package/lib/types/nylas.d.ts +40 -0
- package/lib/types/resources/attachments.d.ts +61 -0
- package/lib/types/resources/auth.d.ts +15 -11
- package/lib/types/resources/calendars.d.ts +18 -3
- package/lib/types/resources/connectors.d.ts +80 -0
- package/lib/types/resources/contacts.d.ts +92 -0
- package/lib/types/resources/credentials.d.ts +80 -0
- package/lib/types/resources/drafts.d.ts +87 -0
- package/lib/types/resources/events.d.ts +22 -3
- package/lib/types/resources/folders.d.ts +90 -0
- package/lib/types/resources/grants.d.ts +3 -14
- package/lib/types/resources/messages.d.ts +129 -0
- package/lib/types/resources/redirectUris.d.ts +2 -2
- package/lib/types/resources/resource.d.ts +4 -0
- package/lib/types/resources/smartCompose.d.ts +41 -0
- package/lib/types/resources/threads.d.ts +70 -0
- package/lib/types/resources/webhooks.d.ts +1 -1
- package/lib/types/utils.d.ts +2 -0
- package/lib/types/version.d.ts +1 -1
- package/package.json +5 -3
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Drafts = void 0;
|
|
4
|
+
const resource_js_1 = require("./resource.js");
|
|
5
|
+
const messages_js_1 = require("./messages.js");
|
|
6
|
+
/**
|
|
7
|
+
* Nylas Drafts API
|
|
8
|
+
*
|
|
9
|
+
* The Nylas Drafts API allows you to list, find, update, delete, and send drafts on user accounts.
|
|
10
|
+
*/
|
|
11
|
+
class Drafts extends resource_js_1.Resource {
|
|
12
|
+
/**
|
|
13
|
+
* Return all Drafts
|
|
14
|
+
* @return A list of drafts
|
|
15
|
+
*/
|
|
16
|
+
list({ identifier, queryParams, overrides, }) {
|
|
17
|
+
return super._list({
|
|
18
|
+
queryParams,
|
|
19
|
+
overrides,
|
|
20
|
+
path: `/v3/grants/${identifier}/drafts`,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Return a Draft
|
|
25
|
+
* @return The draft
|
|
26
|
+
*/
|
|
27
|
+
find({ identifier, draftId, overrides, }) {
|
|
28
|
+
return super._find({
|
|
29
|
+
path: `/v3/grants/${identifier}/drafts/${draftId}`,
|
|
30
|
+
overrides,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Return a Draft
|
|
35
|
+
* @return The draft
|
|
36
|
+
*/
|
|
37
|
+
create({ identifier, requestBody, overrides, }) {
|
|
38
|
+
const form = messages_js_1.Messages._buildFormRequest(requestBody);
|
|
39
|
+
return this.apiClient.request({
|
|
40
|
+
method: 'POST',
|
|
41
|
+
path: `/v3/grants/${identifier}/drafts`,
|
|
42
|
+
form,
|
|
43
|
+
overrides,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Update a Draft
|
|
48
|
+
* @return The updated draft
|
|
49
|
+
*/
|
|
50
|
+
update({ identifier, draftId, requestBody, overrides, }) {
|
|
51
|
+
const form = messages_js_1.Messages._buildFormRequest(requestBody);
|
|
52
|
+
return this.apiClient.request({
|
|
53
|
+
method: 'PUT',
|
|
54
|
+
path: `/v3/grants/${identifier}/drafts/${draftId}`,
|
|
55
|
+
form,
|
|
56
|
+
overrides,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Delete a Draft
|
|
61
|
+
* @return The deleted draft
|
|
62
|
+
*/
|
|
63
|
+
destroy({ identifier, draftId, overrides, }) {
|
|
64
|
+
return super._destroy({
|
|
65
|
+
path: `/v3/grants/${identifier}/drafts/${draftId}`,
|
|
66
|
+
overrides,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Send a Draft
|
|
71
|
+
* @return The sent draft
|
|
72
|
+
*/
|
|
73
|
+
send({ identifier, draftId, overrides, }) {
|
|
74
|
+
return super._create({
|
|
75
|
+
path: `/v3/grants/${identifier}/drafts/${draftId}`,
|
|
76
|
+
requestBody: {},
|
|
77
|
+
overrides,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.Drafts = Drafts;
|
|
@@ -65,5 +65,19 @@ class Events extends resource_js_1.Resource {
|
|
|
65
65
|
overrides,
|
|
66
66
|
});
|
|
67
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Send RSVP. Allows users to respond to events they have been added to as an attendee.
|
|
70
|
+
* You cannot send RSVP as an event owner/organizer.
|
|
71
|
+
* You cannot directly update events as an invitee, since you are not the owner/organizer.
|
|
72
|
+
* @return The send-rsvp response
|
|
73
|
+
*/
|
|
74
|
+
sendRsvp({ identifier, eventId, requestBody, queryParams, overrides, }) {
|
|
75
|
+
return super._create({
|
|
76
|
+
path: `/v3/grants/${identifier}/events/${eventId}/send-rsvp`,
|
|
77
|
+
queryParams,
|
|
78
|
+
requestBody,
|
|
79
|
+
overrides,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
68
82
|
}
|
|
69
83
|
exports.Events = Events;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Folders = void 0;
|
|
4
|
+
const resource_js_1 = require("./resource.js");
|
|
5
|
+
/**
|
|
6
|
+
* Nylas Folder API
|
|
7
|
+
*
|
|
8
|
+
* Email providers use folders to store and organize email messages. Examples of common system folders include Inbox, Sent, Drafts, etc.
|
|
9
|
+
*
|
|
10
|
+
* If your team is migrating from Nylas APIv2, there were previously two separate endpoints for interacting with Folders (Microsoft) and Labels (Google).
|
|
11
|
+
* In Nylas API v3, these endpoints are consolidated under Folders.
|
|
12
|
+
*
|
|
13
|
+
* To simplify the developer experience, Nylas uses the same folders commands to manage both folders and labels, using the folder_id key to refer to the folder's ID on the provider.
|
|
14
|
+
* The API also exposes provider-specific fields such as background_color (Google only).
|
|
15
|
+
*
|
|
16
|
+
* Depending on the provider (Google, some IMAP providers, etc.), a message can be contained in more than one folder.
|
|
17
|
+
*/
|
|
18
|
+
class Folders extends resource_js_1.Resource {
|
|
19
|
+
/**
|
|
20
|
+
* Return all Folders
|
|
21
|
+
* @return A list of folders
|
|
22
|
+
*/
|
|
23
|
+
list({ identifier, overrides, }) {
|
|
24
|
+
return super._list({
|
|
25
|
+
overrides,
|
|
26
|
+
path: `/v3/grants/${identifier}/folders`,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Return a Folder
|
|
31
|
+
* @return The folder
|
|
32
|
+
*/
|
|
33
|
+
find({ identifier, folderId, overrides, }) {
|
|
34
|
+
return super._find({
|
|
35
|
+
path: `/v3/grants/${identifier}/folders/${folderId}`,
|
|
36
|
+
overrides,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Create a Folder
|
|
41
|
+
* @return The created folder
|
|
42
|
+
*/
|
|
43
|
+
create({ identifier, requestBody, overrides, }) {
|
|
44
|
+
return super._create({
|
|
45
|
+
path: `/v3/grants/${identifier}/folders`,
|
|
46
|
+
requestBody,
|
|
47
|
+
overrides,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Update a Folder
|
|
52
|
+
* @return The updated Folder
|
|
53
|
+
*/
|
|
54
|
+
update({ identifier, folderId, requestBody, overrides, }) {
|
|
55
|
+
return super._update({
|
|
56
|
+
path: `/v3/grants/${identifier}/folders/${folderId}`,
|
|
57
|
+
requestBody,
|
|
58
|
+
overrides,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Delete a Folder
|
|
63
|
+
* @return The deleted Folder
|
|
64
|
+
*/
|
|
65
|
+
destroy({ identifier, folderId, overrides, }) {
|
|
66
|
+
return super._destroy({
|
|
67
|
+
path: `/v3/grants/${identifier}/folders/${folderId}`,
|
|
68
|
+
overrides,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.Folders = Folders;
|
|
@@ -29,17 +29,6 @@ class Grants extends resource_js_1.Resource {
|
|
|
29
29
|
overrides,
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
|
-
/**
|
|
33
|
-
* Create a Grant
|
|
34
|
-
* @return The created Grant
|
|
35
|
-
*/
|
|
36
|
-
create({ requestBody, overrides, }) {
|
|
37
|
-
return super._create({
|
|
38
|
-
path: `/v3/grants`,
|
|
39
|
-
requestBody,
|
|
40
|
-
overrides,
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
32
|
/**
|
|
44
33
|
* Update a Grant
|
|
45
34
|
* @return The updated Grant
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Messages = void 0;
|
|
4
|
+
const resource_js_1 = require("./resource.js");
|
|
5
|
+
const FormData = require("form-data");
|
|
6
|
+
const utils_js_1 = require("../utils.js");
|
|
7
|
+
const smartCompose_js_1 = require("./smartCompose.js");
|
|
8
|
+
/**
|
|
9
|
+
* Nylas Messages API
|
|
10
|
+
*
|
|
11
|
+
* The Nylas Messages API allows you to list, find, update, delete, schedule, and send messages on user accounts.
|
|
12
|
+
*/
|
|
13
|
+
class Messages extends resource_js_1.Resource {
|
|
14
|
+
constructor(apiClient) {
|
|
15
|
+
super(apiClient);
|
|
16
|
+
this.smartCompose = new smartCompose_js_1.SmartCompose(apiClient);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Return all Messages
|
|
20
|
+
* @return A list of messages
|
|
21
|
+
*/
|
|
22
|
+
list({ identifier, queryParams, overrides, }) {
|
|
23
|
+
return super._list({
|
|
24
|
+
queryParams,
|
|
25
|
+
overrides,
|
|
26
|
+
path: `/v3/grants/${identifier}/messages`,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Return a Message
|
|
31
|
+
* @return The message
|
|
32
|
+
*/
|
|
33
|
+
find({ identifier, messageId, overrides, }) {
|
|
34
|
+
return super._find({
|
|
35
|
+
path: `/v3/grants/${identifier}/messages/${messageId}`,
|
|
36
|
+
overrides,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Update a Message
|
|
41
|
+
* @return The updated message
|
|
42
|
+
*/
|
|
43
|
+
update({ identifier, messageId, requestBody, overrides, }) {
|
|
44
|
+
return super._update({
|
|
45
|
+
path: `/v3/grants/${identifier}/messages/${messageId}`,
|
|
46
|
+
requestBody,
|
|
47
|
+
overrides,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Delete a Message
|
|
52
|
+
* @return The deleted message
|
|
53
|
+
*/
|
|
54
|
+
destroy({ identifier, messageId, overrides, }) {
|
|
55
|
+
return super._destroy({
|
|
56
|
+
path: `/v3/grants/${identifier}/messages/${messageId}`,
|
|
57
|
+
overrides,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Send an email
|
|
62
|
+
* @return The sent message
|
|
63
|
+
*/
|
|
64
|
+
send({ identifier, requestBody, overrides, }) {
|
|
65
|
+
const form = Messages._buildFormRequest(requestBody);
|
|
66
|
+
return this.apiClient.request({
|
|
67
|
+
method: 'POST',
|
|
68
|
+
path: `/v3/grants/${identifier}/messages/send`,
|
|
69
|
+
form,
|
|
70
|
+
overrides,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Retrieve your scheduled messages
|
|
75
|
+
* @return A list of scheduled messages
|
|
76
|
+
*/
|
|
77
|
+
listScheduledMessages({ identifier, overrides, }) {
|
|
78
|
+
return super._find({
|
|
79
|
+
path: `/v3/grants/${identifier}/messages/schedules`,
|
|
80
|
+
overrides,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Retrieve a scheduled message
|
|
85
|
+
* @return The scheduled message
|
|
86
|
+
*/
|
|
87
|
+
findScheduledMessage({ identifier, scheduleId, overrides, }) {
|
|
88
|
+
return super._find({
|
|
89
|
+
path: `/v3/grants/${identifier}/messages/schedules/${scheduleId}`,
|
|
90
|
+
overrides,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Stop a scheduled message
|
|
95
|
+
* @return The confirmation of the stopped scheduled message
|
|
96
|
+
*/
|
|
97
|
+
stopScheduledMessage({ identifier, scheduleId, overrides, }) {
|
|
98
|
+
return super._destroy({
|
|
99
|
+
path: `/v3/grants/${identifier}/messages/schedules/${scheduleId}`,
|
|
100
|
+
overrides,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
static _buildFormRequest(requestBody) {
|
|
104
|
+
let form;
|
|
105
|
+
// FormData imports are funky, cjs needs to use .default, es6 doesn't
|
|
106
|
+
if (typeof FormData.default !== 'undefined') {
|
|
107
|
+
form = new FormData.default();
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
form = new FormData();
|
|
111
|
+
}
|
|
112
|
+
// Split out the message payload from the attachments
|
|
113
|
+
const messagePayload = {
|
|
114
|
+
...requestBody,
|
|
115
|
+
attachments: undefined,
|
|
116
|
+
};
|
|
117
|
+
form.append('message', JSON.stringify((0, utils_js_1.objKeysToSnakeCase)(messagePayload)));
|
|
118
|
+
// Add a separate form field for each attachment
|
|
119
|
+
requestBody.attachments?.forEach((attachment, index) => {
|
|
120
|
+
form.append(`file${index}`, attachment.content, {
|
|
121
|
+
filename: attachment.filename,
|
|
122
|
+
contentType: attachment.contentType,
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
return form;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
exports.Messages = Messages;
|
|
@@ -57,7 +57,7 @@ class RedirectUris extends resource_js_1.Resource {
|
|
|
57
57
|
destroy({ redirectUriId, overrides, }) {
|
|
58
58
|
return super._destroy({
|
|
59
59
|
overrides,
|
|
60
|
-
path: `/
|
|
60
|
+
path: `/v3/applications/redirect-uris/${redirectUriId}`,
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
63
|
}
|
|
@@ -107,5 +107,21 @@ class Resource {
|
|
|
107
107
|
overrides,
|
|
108
108
|
});
|
|
109
109
|
}
|
|
110
|
+
_getRaw({ path, queryParams, overrides, }) {
|
|
111
|
+
return this.apiClient.requestRaw({
|
|
112
|
+
method: 'GET',
|
|
113
|
+
path,
|
|
114
|
+
queryParams,
|
|
115
|
+
overrides,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
_getStream({ path, queryParams, overrides, }) {
|
|
119
|
+
return this.apiClient.requestStream({
|
|
120
|
+
method: 'GET',
|
|
121
|
+
path,
|
|
122
|
+
queryParams,
|
|
123
|
+
overrides,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
110
126
|
}
|
|
111
127
|
exports.Resource = Resource;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SmartCompose = void 0;
|
|
4
|
+
const resource_js_1 = require("./resource.js");
|
|
5
|
+
/**
|
|
6
|
+
* A collection of Smart Compose related API endpoints.
|
|
7
|
+
*
|
|
8
|
+
* These endpoints allow for the generation of message suggestions.
|
|
9
|
+
*/
|
|
10
|
+
class SmartCompose extends resource_js_1.Resource {
|
|
11
|
+
/**
|
|
12
|
+
* Compose a message
|
|
13
|
+
* @return The generated message
|
|
14
|
+
*/
|
|
15
|
+
composeMessage({ identifier, requestBody, overrides, }) {
|
|
16
|
+
return super._create({
|
|
17
|
+
path: `/v3/grants/${identifier}/messages/smart-compose`,
|
|
18
|
+
requestBody,
|
|
19
|
+
overrides,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Compose a message reply
|
|
24
|
+
* @return The generated message reply
|
|
25
|
+
*/
|
|
26
|
+
composeMessageReply({ identifier, messageId, requestBody, overrides, }) {
|
|
27
|
+
return super._create({
|
|
28
|
+
path: `/v3/grants/${identifier}/messages/${messageId}/smart-compose`,
|
|
29
|
+
requestBody,
|
|
30
|
+
overrides,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.SmartCompose = SmartCompose;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Threads = void 0;
|
|
4
|
+
const resource_js_1 = require("./resource.js");
|
|
5
|
+
/**
|
|
6
|
+
* Nylas Threads API
|
|
7
|
+
*
|
|
8
|
+
* The Nylas Threads API allows you to list, find, update, and delete threads on user accounts.
|
|
9
|
+
*/
|
|
10
|
+
class Threads extends resource_js_1.Resource {
|
|
11
|
+
/**
|
|
12
|
+
* Return all Threads
|
|
13
|
+
* @return A list of threads
|
|
14
|
+
*/
|
|
15
|
+
list({ identifier, queryParams, overrides, }) {
|
|
16
|
+
return super._list({
|
|
17
|
+
queryParams,
|
|
18
|
+
overrides,
|
|
19
|
+
path: `/v3/grants/${identifier}/threads`,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Return a Thread
|
|
24
|
+
* @return The thread
|
|
25
|
+
*/
|
|
26
|
+
find({ identifier, threadId, overrides, }) {
|
|
27
|
+
return super._find({
|
|
28
|
+
path: `/v3/grants/${identifier}/threads/${threadId}`,
|
|
29
|
+
overrides,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Update a Thread
|
|
34
|
+
* @return The updated thread
|
|
35
|
+
*/
|
|
36
|
+
update({ identifier, threadId, requestBody, overrides, }) {
|
|
37
|
+
return super._update({
|
|
38
|
+
path: `/v3/grants/${identifier}/threads/${threadId}`,
|
|
39
|
+
requestBody,
|
|
40
|
+
overrides,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Delete a Thread
|
|
45
|
+
* @return The deleted thread
|
|
46
|
+
*/
|
|
47
|
+
destroy({ identifier, threadId, overrides, }) {
|
|
48
|
+
return super._destroy({
|
|
49
|
+
path: `/v3/grants/${identifier}/threads/${threadId}`,
|
|
50
|
+
overrides,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.Threads = Threads;
|
package/lib/cjs/utils.js
CHANGED
|
@@ -1,7 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.objKeysToSnakeCase = exports.objKeysToCamelCase = void 0;
|
|
3
|
+
exports.objKeysToSnakeCase = exports.objKeysToCamelCase = exports.createFileRequestBuilder = void 0;
|
|
4
4
|
const change_case_1 = require("change-case");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
const mime = require("mime-types");
|
|
8
|
+
function createFileRequestBuilder(filePath) {
|
|
9
|
+
const stats = fs.statSync(filePath);
|
|
10
|
+
const filename = path.basename(filePath);
|
|
11
|
+
const contentType = mime.lookup(filePath) || 'application/octet-stream';
|
|
12
|
+
const content = fs.createReadStream(filePath);
|
|
13
|
+
return {
|
|
14
|
+
filename,
|
|
15
|
+
contentType,
|
|
16
|
+
content,
|
|
17
|
+
size: stats.size,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
exports.createFileRequestBuilder = createFileRequestBuilder;
|
|
5
21
|
/**
|
|
6
22
|
* A utility function that recursively converts all keys in an object to a given case.
|
|
7
23
|
* @param obj The object to convert
|
package/lib/cjs/version.js
CHANGED
package/lib/esm/apiClient.js
CHANGED
|
@@ -44,6 +44,47 @@ export default class APIClient {
|
|
|
44
44
|
...headers,
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
|
+
async sendRequest(options) {
|
|
48
|
+
const req = this.newRequest(options);
|
|
49
|
+
const controller = new AbortController();
|
|
50
|
+
const timeout = setTimeout(() => {
|
|
51
|
+
controller.abort();
|
|
52
|
+
throw new NylasSdkTimeoutError(req.url, this.timeout);
|
|
53
|
+
}, this.timeout);
|
|
54
|
+
try {
|
|
55
|
+
const response = await fetch(req, { signal: controller.signal });
|
|
56
|
+
clearTimeout(timeout);
|
|
57
|
+
if (typeof response === 'undefined') {
|
|
58
|
+
throw new Error('Failed to fetch response');
|
|
59
|
+
}
|
|
60
|
+
if (response.status > 299) {
|
|
61
|
+
const text = await response.text();
|
|
62
|
+
let error;
|
|
63
|
+
try {
|
|
64
|
+
const parsedError = JSON.parse(text);
|
|
65
|
+
const camelCaseError = objKeysToCamelCase(parsedError);
|
|
66
|
+
// Check if the request is an authentication request
|
|
67
|
+
const isAuthRequest = options.path.includes('connect/token') ||
|
|
68
|
+
options.path.includes('connect/revoke');
|
|
69
|
+
if (isAuthRequest) {
|
|
70
|
+
error = new NylasOAuthError(camelCaseError, response.status);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
error = new NylasApiError(camelCaseError, response.status);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
catch (e) {
|
|
77
|
+
throw new Error(`Received an error but could not parse response from the server: ${text}`);
|
|
78
|
+
}
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
return response;
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
clearTimeout(timeout);
|
|
85
|
+
throw error;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
47
88
|
requestOptions(optionParams) {
|
|
48
89
|
const requestOptions = {};
|
|
49
90
|
requestOptions.url = this.setRequestUrl(optionParams);
|
|
@@ -53,6 +94,13 @@ export default class APIClient {
|
|
|
53
94
|
requestOptions.body = JSON.stringify(objKeysToSnakeCase(optionParams.body));
|
|
54
95
|
requestOptions.headers['Content-Type'] = 'application/json';
|
|
55
96
|
}
|
|
97
|
+
if (optionParams.form) {
|
|
98
|
+
requestOptions.body = optionParams.form;
|
|
99
|
+
requestOptions.headers = {
|
|
100
|
+
...requestOptions.headers,
|
|
101
|
+
...optionParams.form.getHeaders(),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
56
104
|
return requestOptions;
|
|
57
105
|
}
|
|
58
106
|
newRequest(options) {
|
|
@@ -74,38 +122,15 @@ export default class APIClient {
|
|
|
74
122
|
}
|
|
75
123
|
}
|
|
76
124
|
async request(options) {
|
|
77
|
-
const
|
|
78
|
-
const controller = new AbortController();
|
|
79
|
-
const timeout = setTimeout(() => {
|
|
80
|
-
controller.abort();
|
|
81
|
-
throw new NylasSdkTimeoutError(req.url, this.timeout);
|
|
82
|
-
}, this.timeout);
|
|
83
|
-
const response = await fetch(req, { signal: controller.signal });
|
|
84
|
-
clearTimeout(timeout);
|
|
85
|
-
if (typeof response === 'undefined') {
|
|
86
|
-
throw new Error('Failed to fetch response');
|
|
87
|
-
}
|
|
88
|
-
// handle error response
|
|
89
|
-
if (response.status > 299) {
|
|
90
|
-
const authErrorResponse = options.path.includes('connect/token') ||
|
|
91
|
-
options.path.includes('connect/revoke');
|
|
92
|
-
const text = await response.text();
|
|
93
|
-
let error;
|
|
94
|
-
try {
|
|
95
|
-
const parsedError = JSON.parse(text);
|
|
96
|
-
const camelCaseError = objKeysToCamelCase(parsedError);
|
|
97
|
-
if (authErrorResponse) {
|
|
98
|
-
error = new NylasOAuthError(camelCaseError, response.status);
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
error = new NylasApiError(camelCaseError, response.status);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
catch (e) {
|
|
105
|
-
throw new Error(`Received an error but could not parse response from the server: ${text}`);
|
|
106
|
-
}
|
|
107
|
-
throw error;
|
|
108
|
-
}
|
|
125
|
+
const response = await this.sendRequest(options);
|
|
109
126
|
return this.requestWithResponse(response);
|
|
110
127
|
}
|
|
128
|
+
async requestRaw(options) {
|
|
129
|
+
const response = await this.sendRequest(options);
|
|
130
|
+
return response.buffer();
|
|
131
|
+
}
|
|
132
|
+
async requestStream(options) {
|
|
133
|
+
const response = await this.sendRequest(options);
|
|
134
|
+
return response.body;
|
|
135
|
+
}
|
|
111
136
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enum representing the type of credential
|
|
3
|
+
*/
|
|
4
|
+
export var CredentialType;
|
|
5
|
+
(function (CredentialType) {
|
|
6
|
+
CredentialType["ADMINCONSENT"] = "adminconsent";
|
|
7
|
+
CredentialType["SERVICEACCOUNT"] = "serviceaccount";
|
|
8
|
+
CredentialType["CONNECTOR"] = "connector";
|
|
9
|
+
})(CredentialType || (CredentialType = {}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enum representing the type of free/busy information returned for a calendar.
|
|
3
|
+
*/
|
|
4
|
+
export var FreeBusyType;
|
|
5
|
+
(function (FreeBusyType) {
|
|
6
|
+
FreeBusyType["FREE_BUSY"] = "free_busy";
|
|
7
|
+
FreeBusyType["ERROR"] = "error";
|
|
8
|
+
})(FreeBusyType || (FreeBusyType = {}));
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enum representing the message fields that can be included in a response.
|
|
3
|
+
*/
|
|
4
|
+
export var MessageFields;
|
|
5
|
+
(function (MessageFields) {
|
|
6
|
+
MessageFields["STANDARD"] = "standard";
|
|
7
|
+
MessageFields["INCLUDE_HEADERS"] = "include_headers";
|
|
8
|
+
})(MessageFields || (MessageFields = {}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/esm/nylas.js
CHANGED
|
@@ -5,6 +5,14 @@ import { Events } from './resources/events.js';
|
|
|
5
5
|
import { Auth } from './resources/auth.js';
|
|
6
6
|
import { Webhooks } from './resources/webhooks.js';
|
|
7
7
|
import { Applications } from './resources/applications.js';
|
|
8
|
+
import { Messages } from './resources/messages.js';
|
|
9
|
+
import { Drafts } from './resources/drafts.js';
|
|
10
|
+
import { Threads } from './resources/threads.js';
|
|
11
|
+
import { Connectors } from './resources/connectors.js';
|
|
12
|
+
import { Folders } from './resources/folders.js';
|
|
13
|
+
import { Grants } from './resources/grants.js';
|
|
14
|
+
import { Contacts } from './resources/contacts.js';
|
|
15
|
+
import { Attachments } from './resources/attachments.js';
|
|
8
16
|
/**
|
|
9
17
|
* The entry point to the Node SDK
|
|
10
18
|
*
|
|
@@ -24,8 +32,16 @@ export default class Nylas {
|
|
|
24
32
|
this.applications = new Applications(this.apiClient);
|
|
25
33
|
this.auth = new Auth(this.apiClient);
|
|
26
34
|
this.calendars = new Calendars(this.apiClient);
|
|
35
|
+
this.connectors = new Connectors(this.apiClient);
|
|
36
|
+
this.drafts = new Drafts(this.apiClient);
|
|
27
37
|
this.events = new Events(this.apiClient);
|
|
38
|
+
this.grants = new Grants(this.apiClient);
|
|
39
|
+
this.messages = new Messages(this.apiClient);
|
|
40
|
+
this.threads = new Threads(this.apiClient);
|
|
28
41
|
this.webhooks = new Webhooks(this.apiClient);
|
|
42
|
+
this.folders = new Folders(this.apiClient);
|
|
43
|
+
this.contacts = new Contacts(this.apiClient);
|
|
44
|
+
this.attachments = new Attachments(this.apiClient);
|
|
29
45
|
return this;
|
|
30
46
|
}
|
|
31
47
|
}
|