nylas 7.0.0-beta.3 → 7.0.0-beta.5
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 +50 -32
- package/lib/cjs/models/contacts.js +2 -0
- package/lib/cjs/models/events.js +11 -0
- package/lib/cjs/models/folders.js +2 -0
- package/lib/cjs/nylas.js +8 -0
- package/lib/cjs/resources/attachments.js +57 -0
- package/lib/cjs/resources/auth.js +22 -17
- package/lib/cjs/resources/contacts.js +76 -0
- package/lib/cjs/resources/drafts.js +2 -2
- 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 +8 -1
- package/lib/cjs/resources/resource.js +16 -0
- package/lib/cjs/version.js +1 -1
- package/lib/esm/apiClient.js +50 -32
- package/lib/esm/models/contacts.js +1 -0
- package/lib/esm/models/events.js +10 -1
- package/lib/esm/models/folders.js +1 -0
- package/lib/esm/nylas.js +8 -0
- package/lib/esm/resources/attachments.js +53 -0
- package/lib/esm/resources/auth.js +22 -17
- package/lib/esm/resources/contacts.js +72 -0
- package/lib/esm/resources/drafts.js +2 -2
- 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 +8 -1
- package/lib/esm/resources/resource.js +16 -0
- package/lib/esm/version.js +1 -1
- package/lib/types/apiClient.d.ts +5 -0
- package/lib/types/models/attachments.d.ts +66 -0
- package/lib/types/models/auth.d.ts +8 -4
- package/lib/types/models/connectors.d.ts +0 -4
- package/lib/types/models/contacts.d.ts +147 -0
- package/lib/types/models/drafts.d.ts +9 -4
- package/lib/types/models/events.d.ts +69 -18
- package/lib/types/models/folders.d.ts +71 -0
- package/lib/types/models/messages.d.ts +17 -17
- package/lib/types/models/response.d.ts +6 -6
- package/lib/types/nylas.d.ts +20 -0
- package/lib/types/resources/attachments.d.ts +61 -0
- package/lib/types/resources/auth.d.ts +16 -12
- package/lib/types/resources/calendars.d.ts +9 -10
- package/lib/types/resources/connectors.d.ts +2 -2
- package/lib/types/resources/contacts.d.ts +92 -0
- package/lib/types/resources/credentials.d.ts +2 -2
- package/lib/types/resources/drafts.d.ts +6 -5
- package/lib/types/resources/events.d.ts +27 -8
- package/lib/types/resources/folders.d.ts +90 -0
- package/lib/types/resources/grants.d.ts +6 -18
- package/lib/types/resources/messages.d.ts +2 -2
- package/lib/types/resources/redirectUris.d.ts +6 -7
- package/lib/types/resources/resource.d.ts +4 -0
- package/lib/types/resources/threads.d.ts +2 -2
- package/lib/types/resources/webhooks.d.ts +4 -5
- package/lib/types/utils.d.ts +2 -2
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
- package/lib/types/models/files.d.ts +0 -17
- /package/lib/cjs/models/{files.js → attachments.js} +0 -0
- /package/lib/esm/models/{files.js → attachments.js} +0 -0
package/lib/cjs/apiClient.js
CHANGED
|
@@ -46,6 +46,47 @@ class APIClient {
|
|
|
46
46
|
...headers,
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
|
+
async sendRequest(options) {
|
|
50
|
+
const req = this.newRequest(options);
|
|
51
|
+
const controller = new AbortController();
|
|
52
|
+
const timeout = setTimeout(() => {
|
|
53
|
+
controller.abort();
|
|
54
|
+
throw new error_js_1.NylasSdkTimeoutError(req.url, this.timeout);
|
|
55
|
+
}, this.timeout);
|
|
56
|
+
try {
|
|
57
|
+
const response = await (0, node_fetch_1.default)(req, { signal: controller.signal });
|
|
58
|
+
clearTimeout(timeout);
|
|
59
|
+
if (typeof response === 'undefined') {
|
|
60
|
+
throw new Error('Failed to fetch response');
|
|
61
|
+
}
|
|
62
|
+
if (response.status > 299) {
|
|
63
|
+
const text = await response.text();
|
|
64
|
+
let error;
|
|
65
|
+
try {
|
|
66
|
+
const parsedError = JSON.parse(text);
|
|
67
|
+
const camelCaseError = (0, utils_js_1.objKeysToCamelCase)(parsedError);
|
|
68
|
+
// Check if the request is an authentication request
|
|
69
|
+
const isAuthRequest = options.path.includes('connect/token') ||
|
|
70
|
+
options.path.includes('connect/revoke');
|
|
71
|
+
if (isAuthRequest) {
|
|
72
|
+
error = new error_js_1.NylasOAuthError(camelCaseError, response.status);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
error = new error_js_1.NylasApiError(camelCaseError, response.status);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
catch (e) {
|
|
79
|
+
throw new Error(`Received an error but could not parse response from the server: ${text}`);
|
|
80
|
+
}
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
return response;
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
clearTimeout(timeout);
|
|
87
|
+
throw error;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
49
90
|
requestOptions(optionParams) {
|
|
50
91
|
const requestOptions = {};
|
|
51
92
|
requestOptions.url = this.setRequestUrl(optionParams);
|
|
@@ -83,39 +124,16 @@ class APIClient {
|
|
|
83
124
|
}
|
|
84
125
|
}
|
|
85
126
|
async request(options) {
|
|
86
|
-
const
|
|
87
|
-
const controller = new AbortController();
|
|
88
|
-
const timeout = setTimeout(() => {
|
|
89
|
-
controller.abort();
|
|
90
|
-
throw new error_js_1.NylasSdkTimeoutError(req.url, this.timeout);
|
|
91
|
-
}, this.timeout);
|
|
92
|
-
const response = await (0, node_fetch_1.default)(req, { signal: controller.signal });
|
|
93
|
-
clearTimeout(timeout);
|
|
94
|
-
if (typeof response === 'undefined') {
|
|
95
|
-
throw new Error('Failed to fetch response');
|
|
96
|
-
}
|
|
97
|
-
// handle error response
|
|
98
|
-
if (response.status > 299) {
|
|
99
|
-
const authErrorResponse = options.path.includes('connect/token') ||
|
|
100
|
-
options.path.includes('connect/revoke');
|
|
101
|
-
const text = await response.text();
|
|
102
|
-
let error;
|
|
103
|
-
try {
|
|
104
|
-
const parsedError = JSON.parse(text);
|
|
105
|
-
const camelCaseError = (0, utils_js_1.objKeysToCamelCase)(parsedError);
|
|
106
|
-
if (authErrorResponse) {
|
|
107
|
-
error = new error_js_1.NylasOAuthError(camelCaseError, response.status);
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
error = new error_js_1.NylasApiError(camelCaseError, response.status);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
catch (e) {
|
|
114
|
-
throw new Error(`Received an error but could not parse response from the server: ${text}`);
|
|
115
|
-
}
|
|
116
|
-
throw error;
|
|
117
|
-
}
|
|
127
|
+
const response = await this.sendRequest(options);
|
|
118
128
|
return this.requestWithResponse(response);
|
|
119
129
|
}
|
|
130
|
+
async requestRaw(options) {
|
|
131
|
+
const response = await this.sendRequest(options);
|
|
132
|
+
return response.buffer();
|
|
133
|
+
}
|
|
134
|
+
async requestStream(options) {
|
|
135
|
+
const response = await this.sendRequest(options);
|
|
136
|
+
return response.body;
|
|
137
|
+
}
|
|
120
138
|
}
|
|
121
139
|
exports.default = APIClient;
|
package/lib/cjs/models/events.js
CHANGED
|
@@ -1,2 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WhenType = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Enum representing the different types of when objects.
|
|
6
|
+
*/
|
|
7
|
+
var WhenType;
|
|
8
|
+
(function (WhenType) {
|
|
9
|
+
WhenType["Time"] = "time";
|
|
10
|
+
WhenType["Timespan"] = "timespan";
|
|
11
|
+
WhenType["Date"] = "date";
|
|
12
|
+
WhenType["Datespan"] = "datespan";
|
|
13
|
+
})(WhenType = exports.WhenType || (exports.WhenType = {}));
|
package/lib/cjs/nylas.js
CHANGED
|
@@ -11,6 +11,10 @@ const messages_js_1 = require("./resources/messages.js");
|
|
|
11
11
|
const drafts_js_1 = require("./resources/drafts.js");
|
|
12
12
|
const threads_js_1 = require("./resources/threads.js");
|
|
13
13
|
const connectors_js_1 = require("./resources/connectors.js");
|
|
14
|
+
const folders_js_1 = require("./resources/folders.js");
|
|
15
|
+
const grants_js_1 = require("./resources/grants.js");
|
|
16
|
+
const contacts_js_1 = require("./resources/contacts.js");
|
|
17
|
+
const attachments_js_1 = require("./resources/attachments.js");
|
|
14
18
|
/**
|
|
15
19
|
* The entry point to the Node SDK
|
|
16
20
|
*
|
|
@@ -33,9 +37,13 @@ class Nylas {
|
|
|
33
37
|
this.connectors = new connectors_js_1.Connectors(this.apiClient);
|
|
34
38
|
this.drafts = new drafts_js_1.Drafts(this.apiClient);
|
|
35
39
|
this.events = new events_js_1.Events(this.apiClient);
|
|
40
|
+
this.grants = new grants_js_1.Grants(this.apiClient);
|
|
36
41
|
this.messages = new messages_js_1.Messages(this.apiClient);
|
|
37
42
|
this.threads = new threads_js_1.Threads(this.apiClient);
|
|
38
43
|
this.webhooks = new webhooks_js_1.Webhooks(this.apiClient);
|
|
44
|
+
this.folders = new folders_js_1.Folders(this.apiClient);
|
|
45
|
+
this.contacts = new contacts_js_1.Contacts(this.apiClient);
|
|
46
|
+
this.attachments = new attachments_js_1.Attachments(this.apiClient);
|
|
39
47
|
return this;
|
|
40
48
|
}
|
|
41
49
|
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Attachments = void 0;
|
|
4
|
+
const resource_js_1 = require("./resource.js");
|
|
5
|
+
/**
|
|
6
|
+
* Nylas Attachments API
|
|
7
|
+
*
|
|
8
|
+
* The Nylas Attachments API allows you to retrieve metadata and download attachments.
|
|
9
|
+
*/
|
|
10
|
+
class Attachments extends resource_js_1.Resource {
|
|
11
|
+
/**
|
|
12
|
+
* Returns an attachment by ID.
|
|
13
|
+
* @return The Attachment metadata
|
|
14
|
+
*/
|
|
15
|
+
find({ identifier, attachmentId, queryParams, overrides, }) {
|
|
16
|
+
return super._find({
|
|
17
|
+
path: `/v3/grants/${identifier}/attachments/${attachmentId}`,
|
|
18
|
+
queryParams,
|
|
19
|
+
overrides,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Download the attachment data
|
|
24
|
+
*
|
|
25
|
+
* This method returns a NodeJS.ReadableStream which can be used to stream the attachment data.
|
|
26
|
+
* This is particularly useful for handling large attachments efficiently, as it avoids loading
|
|
27
|
+
* the entire file into memory. The stream can be piped to a file stream or used in any other way
|
|
28
|
+
* that Node.js streams are typically used.
|
|
29
|
+
*
|
|
30
|
+
* @param identifier Grant ID or email account to query
|
|
31
|
+
* @param attachmentId The id of the attachment to download.
|
|
32
|
+
* @param queryParams The query parameters to include in the request
|
|
33
|
+
* @returns {NodeJS.ReadableStream} The ReadableStream containing the file data.
|
|
34
|
+
*/
|
|
35
|
+
download({ identifier, attachmentId, queryParams, overrides, }) {
|
|
36
|
+
return this._getStream({
|
|
37
|
+
path: `/v3/grants/${identifier}/attachments/${attachmentId}/download`,
|
|
38
|
+
queryParams,
|
|
39
|
+
overrides,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Download the attachment as a byte array
|
|
44
|
+
* @param identifier Grant ID or email account to query
|
|
45
|
+
* @param attachmentId The id of the attachment to download.
|
|
46
|
+
* @param queryParams The query parameters to include in the request
|
|
47
|
+
* @return The raw file data
|
|
48
|
+
*/
|
|
49
|
+
downloadBytes({ identifier, attachmentId, queryParams, overrides, }) {
|
|
50
|
+
return super._getRaw({
|
|
51
|
+
path: `/v3/grants/${identifier}/attachments/${attachmentId}/download`,
|
|
52
|
+
queryParams,
|
|
53
|
+
overrides,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.Attachments = Attachments;
|
|
@@ -4,7 +4,6 @@ exports.Auth = void 0;
|
|
|
4
4
|
const uuid_1 = require("uuid");
|
|
5
5
|
const node_crypto_1 = require("node:crypto");
|
|
6
6
|
const resource_js_1 = require("./resource.js");
|
|
7
|
-
const grants_js_1 = require("./grants.js");
|
|
8
7
|
/**
|
|
9
8
|
* A collection of authentication related API endpoints
|
|
10
9
|
*
|
|
@@ -12,14 +11,6 @@ const grants_js_1 = require("./grants.js");
|
|
|
12
11
|
* Also contains the Grants API and collection of provider API endpoints.
|
|
13
12
|
*/
|
|
14
13
|
class Auth extends resource_js_1.Resource {
|
|
15
|
-
/**
|
|
16
|
-
* @param apiClient The configured Nylas API client
|
|
17
|
-
*/
|
|
18
|
-
constructor(apiClient) {
|
|
19
|
-
super(apiClient);
|
|
20
|
-
this.apiClient = apiClient;
|
|
21
|
-
this.grants = new grants_js_1.Grants(apiClient);
|
|
22
|
-
}
|
|
23
14
|
/**
|
|
24
15
|
* Build the URL for authenticating users to your application with OAuth 2.0
|
|
25
16
|
* @param config The configuration for building the URL
|
|
@@ -34,17 +25,16 @@ class Auth extends resource_js_1.Resource {
|
|
|
34
25
|
* @return Information about the Nylas application
|
|
35
26
|
*/
|
|
36
27
|
exchangeCodeForToken(request) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
grantType: 'authorization_code',
|
|
40
|
-
};
|
|
41
|
-
if (request.codeVerifier) {
|
|
42
|
-
body.codeVerifier = request.codeVerifier;
|
|
28
|
+
if (!request.clientSecret) {
|
|
29
|
+
request.clientSecret = this.apiClient.apiKey;
|
|
43
30
|
}
|
|
44
31
|
return this.apiClient.request({
|
|
45
32
|
method: 'POST',
|
|
46
33
|
path: `/v3/connect/token`,
|
|
47
|
-
body
|
|
34
|
+
body: {
|
|
35
|
+
...request,
|
|
36
|
+
grantType: 'authorization_code',
|
|
37
|
+
},
|
|
48
38
|
});
|
|
49
39
|
}
|
|
50
40
|
/**
|
|
@@ -53,6 +43,9 @@ class Auth extends resource_js_1.Resource {
|
|
|
53
43
|
* @return The response containing the new access token
|
|
54
44
|
*/
|
|
55
45
|
refreshAccessToken(request) {
|
|
46
|
+
if (!request.clientSecret) {
|
|
47
|
+
request.clientSecret = this.apiClient.apiKey;
|
|
48
|
+
}
|
|
56
49
|
return this.apiClient.request({
|
|
57
50
|
method: 'POST',
|
|
58
51
|
path: `/v3/connect/token`,
|
|
@@ -90,6 +83,18 @@ class Auth extends resource_js_1.Resource {
|
|
|
90
83
|
url.searchParams.set('credential_id', config.credentialId);
|
|
91
84
|
return url.toString();
|
|
92
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Create a grant via Custom Authentication
|
|
88
|
+
* @return The created grant
|
|
89
|
+
*/
|
|
90
|
+
customAuthentication({ requestBody, overrides, }) {
|
|
91
|
+
return this.apiClient.request({
|
|
92
|
+
method: 'POST',
|
|
93
|
+
path: `/v3/connect/custom`,
|
|
94
|
+
body: requestBody,
|
|
95
|
+
overrides,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
93
98
|
/**
|
|
94
99
|
* Revoke a token (and the grant attached to the token)
|
|
95
100
|
* @param token The token to revoke
|
|
@@ -113,7 +118,7 @@ class Auth extends resource_js_1.Resource {
|
|
|
113
118
|
async detectProvider(params) {
|
|
114
119
|
return this.apiClient.request({
|
|
115
120
|
method: 'POST',
|
|
116
|
-
path: `/v3/
|
|
121
|
+
path: `/v3/providers/detect`,
|
|
117
122
|
queryParams: params,
|
|
118
123
|
});
|
|
119
124
|
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Contacts = void 0;
|
|
4
|
+
const resource_js_1 = require("./resource.js");
|
|
5
|
+
/**
|
|
6
|
+
* Nylas Contacts API
|
|
7
|
+
*
|
|
8
|
+
* The Nylas Contacts API allows you to create, update, and delete contacts.
|
|
9
|
+
*/
|
|
10
|
+
class Contacts extends resource_js_1.Resource {
|
|
11
|
+
/**
|
|
12
|
+
* Return all Contacts
|
|
13
|
+
* @return The list of Contacts
|
|
14
|
+
*/
|
|
15
|
+
list({ identifier, queryParams, overrides, }) {
|
|
16
|
+
return super._list({
|
|
17
|
+
queryParams,
|
|
18
|
+
path: `/v3/grants/${identifier}/contacts`,
|
|
19
|
+
overrides,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Return a Contact
|
|
24
|
+
* @return The Contact
|
|
25
|
+
*/
|
|
26
|
+
find({ identifier, contactId, queryParams, overrides, }) {
|
|
27
|
+
return super._find({
|
|
28
|
+
path: `/v3/grants/${identifier}/contacts/${contactId}`,
|
|
29
|
+
queryParams,
|
|
30
|
+
overrides,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Create a Contact
|
|
35
|
+
* @return The created Contact
|
|
36
|
+
*/
|
|
37
|
+
create({ identifier, requestBody, overrides, }) {
|
|
38
|
+
return super._create({
|
|
39
|
+
path: `/v3/grants/${identifier}/contacts`,
|
|
40
|
+
requestBody,
|
|
41
|
+
overrides,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Update a Contact
|
|
46
|
+
* @return The updated Contact
|
|
47
|
+
*/
|
|
48
|
+
update({ identifier, contactId, requestBody, overrides, }) {
|
|
49
|
+
return super._update({
|
|
50
|
+
path: `/v3/grants/${identifier}/contacts/${contactId}`,
|
|
51
|
+
requestBody,
|
|
52
|
+
overrides,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Delete a Contact
|
|
57
|
+
* @return The deletion response
|
|
58
|
+
*/
|
|
59
|
+
destroy({ identifier, contactId, overrides, }) {
|
|
60
|
+
return super._destroy({
|
|
61
|
+
path: `/v3/grants/${identifier}/contacts/${contactId}`,
|
|
62
|
+
overrides,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Return a Contact Group
|
|
67
|
+
* @return The list of Contact Groups
|
|
68
|
+
*/
|
|
69
|
+
groups({ identifier, overrides, }) {
|
|
70
|
+
return super._list({
|
|
71
|
+
path: `/v3/grants/${identifier}/contacts/groups`,
|
|
72
|
+
overrides,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.Contacts = Contacts;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Drafts = void 0;
|
|
4
|
-
const resource_js_1 = require("./resource.js");
|
|
5
4
|
const messages_js_1 = require("./messages.js");
|
|
5
|
+
const resource_js_1 = require("./resource.js");
|
|
6
6
|
/**
|
|
7
7
|
* Nylas Drafts API
|
|
8
8
|
*
|
|
@@ -68,7 +68,7 @@ class Drafts extends resource_js_1.Resource {
|
|
|
68
68
|
}
|
|
69
69
|
/**
|
|
70
70
|
* Send a Draft
|
|
71
|
-
* @return The sent
|
|
71
|
+
* @return The sent message
|
|
72
72
|
*/
|
|
73
73
|
send({ identifier, draftId, overrides, }) {
|
|
74
74
|
return super._create({
|
|
@@ -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 via Custom Authentication
|
|
34
|
-
* @return The created Grant
|
|
35
|
-
*/
|
|
36
|
-
create({ requestBody, overrides, }) {
|
|
37
|
-
return super._create({
|
|
38
|
-
path: `/v3/connect/custom`,
|
|
39
|
-
requestBody,
|
|
40
|
-
overrides,
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
32
|
/**
|
|
44
33
|
* Update a Grant
|
|
45
34
|
* @return The updated Grant
|
|
@@ -101,7 +101,14 @@ class Messages extends resource_js_1.Resource {
|
|
|
101
101
|
});
|
|
102
102
|
}
|
|
103
103
|
static _buildFormRequest(requestBody) {
|
|
104
|
-
|
|
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
|
+
}
|
|
105
112
|
// Split out the message payload from the attachments
|
|
106
113
|
const messagePayload = {
|
|
107
114
|
...requestBody,
|
|
@@ -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;
|
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);
|
|
@@ -81,38 +122,15 @@ export default class APIClient {
|
|
|
81
122
|
}
|
|
82
123
|
}
|
|
83
124
|
async request(options) {
|
|
84
|
-
const
|
|
85
|
-
const controller = new AbortController();
|
|
86
|
-
const timeout = setTimeout(() => {
|
|
87
|
-
controller.abort();
|
|
88
|
-
throw new NylasSdkTimeoutError(req.url, this.timeout);
|
|
89
|
-
}, this.timeout);
|
|
90
|
-
const response = await fetch(req, { signal: controller.signal });
|
|
91
|
-
clearTimeout(timeout);
|
|
92
|
-
if (typeof response === 'undefined') {
|
|
93
|
-
throw new Error('Failed to fetch response');
|
|
94
|
-
}
|
|
95
|
-
// handle error response
|
|
96
|
-
if (response.status > 299) {
|
|
97
|
-
const authErrorResponse = options.path.includes('connect/token') ||
|
|
98
|
-
options.path.includes('connect/revoke');
|
|
99
|
-
const text = await response.text();
|
|
100
|
-
let error;
|
|
101
|
-
try {
|
|
102
|
-
const parsedError = JSON.parse(text);
|
|
103
|
-
const camelCaseError = objKeysToCamelCase(parsedError);
|
|
104
|
-
if (authErrorResponse) {
|
|
105
|
-
error = new NylasOAuthError(camelCaseError, response.status);
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
error = new NylasApiError(camelCaseError, response.status);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
catch (e) {
|
|
112
|
-
throw new Error(`Received an error but could not parse response from the server: ${text}`);
|
|
113
|
-
}
|
|
114
|
-
throw error;
|
|
115
|
-
}
|
|
125
|
+
const response = await this.sendRequest(options);
|
|
116
126
|
return this.requestWithResponse(response);
|
|
117
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
|
+
}
|
|
118
136
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/esm/models/events.js
CHANGED
|
@@ -1 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Enum representing the different types of when objects.
|
|
3
|
+
*/
|
|
4
|
+
export var WhenType;
|
|
5
|
+
(function (WhenType) {
|
|
6
|
+
WhenType["Time"] = "time";
|
|
7
|
+
WhenType["Timespan"] = "timespan";
|
|
8
|
+
WhenType["Date"] = "date";
|
|
9
|
+
WhenType["Datespan"] = "datespan";
|
|
10
|
+
})(WhenType || (WhenType = {}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/esm/nylas.js
CHANGED
|
@@ -9,6 +9,10 @@ import { Messages } from './resources/messages.js';
|
|
|
9
9
|
import { Drafts } from './resources/drafts.js';
|
|
10
10
|
import { Threads } from './resources/threads.js';
|
|
11
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';
|
|
12
16
|
/**
|
|
13
17
|
* The entry point to the Node SDK
|
|
14
18
|
*
|
|
@@ -31,9 +35,13 @@ export default class Nylas {
|
|
|
31
35
|
this.connectors = new Connectors(this.apiClient);
|
|
32
36
|
this.drafts = new Drafts(this.apiClient);
|
|
33
37
|
this.events = new Events(this.apiClient);
|
|
38
|
+
this.grants = new Grants(this.apiClient);
|
|
34
39
|
this.messages = new Messages(this.apiClient);
|
|
35
40
|
this.threads = new Threads(this.apiClient);
|
|
36
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);
|
|
37
45
|
return this;
|
|
38
46
|
}
|
|
39
47
|
}
|