nylas 7.0.0-beta.2 → 7.0.0-beta.3
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 +7 -0
- package/lib/cjs/models/connectors.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/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 +8 -0
- package/lib/cjs/resources/auth.js +8 -6
- package/lib/cjs/resources/calendars.js +12 -0
- package/lib/cjs/resources/connectors.js +68 -0
- package/lib/cjs/resources/credentials.js +60 -0
- package/lib/cjs/resources/drafts.js +81 -0
- package/lib/cjs/resources/grants.js +2 -2
- package/lib/cjs/resources/messages.js +121 -0
- package/lib/cjs/resources/redirectUris.js +1 -1
- 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 +7 -0
- package/lib/esm/models/connectors.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/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 +8 -0
- package/lib/esm/resources/auth.js +8 -6
- package/lib/esm/resources/calendars.js +12 -0
- package/lib/esm/resources/connectors.js +64 -0
- package/lib/esm/resources/credentials.js +56 -0
- package/lib/esm/resources/drafts.js +77 -0
- package/lib/esm/resources/grants.js +2 -2
- package/lib/esm/resources/messages.js +117 -0
- package/lib/esm/resources/redirectUris.js +1 -1
- 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 +3 -1
- package/lib/types/models/auth.d.ts +1 -1
- package/lib/types/models/calendars.d.ts +1 -1
- package/lib/types/models/connectors.d.ts +127 -0
- package/lib/types/models/credentials.d.ts +151 -0
- package/lib/types/models/drafts.d.ts +92 -0
- package/lib/types/models/files.d.ts +17 -0
- package/lib/types/models/freeBusy.d.ts +79 -0
- package/lib/types/models/messages.d.ts +271 -0
- 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 +20 -0
- package/lib/types/resources/calendars.d.ts +16 -1
- package/lib/types/resources/connectors.d.ts +80 -0
- package/lib/types/resources/credentials.d.ts +80 -0
- package/lib/types/resources/drafts.d.ts +87 -0
- package/lib/types/resources/grants.d.ts +1 -1
- package/lib/types/resources/messages.d.ts +129 -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,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
|
@@ -53,6 +53,13 @@ export default class APIClient {
|
|
|
53
53
|
requestOptions.body = JSON.stringify(objKeysToSnakeCase(optionParams.body));
|
|
54
54
|
requestOptions.headers['Content-Type'] = 'application/json';
|
|
55
55
|
}
|
|
56
|
+
if (optionParams.form) {
|
|
57
|
+
requestOptions.body = optionParams.form;
|
|
58
|
+
requestOptions.headers = {
|
|
59
|
+
...requestOptions.headers,
|
|
60
|
+
...optionParams.form.getHeaders(),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
56
63
|
return requestOptions;
|
|
57
64
|
}
|
|
58
65
|
newRequest(options) {
|
|
@@ -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,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,10 @@ 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';
|
|
8
12
|
/**
|
|
9
13
|
* The entry point to the Node SDK
|
|
10
14
|
*
|
|
@@ -24,7 +28,11 @@ export default class Nylas {
|
|
|
24
28
|
this.applications = new Applications(this.apiClient);
|
|
25
29
|
this.auth = new Auth(this.apiClient);
|
|
26
30
|
this.calendars = new Calendars(this.apiClient);
|
|
31
|
+
this.connectors = new Connectors(this.apiClient);
|
|
32
|
+
this.drafts = new Drafts(this.apiClient);
|
|
27
33
|
this.events = new Events(this.apiClient);
|
|
34
|
+
this.messages = new Messages(this.apiClient);
|
|
35
|
+
this.threads = new Threads(this.apiClient);
|
|
28
36
|
this.webhooks = new Webhooks(this.apiClient);
|
|
29
37
|
return this;
|
|
30
38
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { v4 as uuid } from 'uuid';
|
|
2
|
-
import
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
3
|
import { Resource } from './resource.js';
|
|
4
4
|
import { Grants } from './grants.js';
|
|
5
5
|
/**
|
|
@@ -71,7 +71,7 @@ export class Auth extends Resource {
|
|
|
71
71
|
url.searchParams.set('code_challenge_method', 's256');
|
|
72
72
|
const secret = uuid();
|
|
73
73
|
const secretHash = this.hashPKCESecret(secret);
|
|
74
|
-
url.searchParams.set('code_challenge',
|
|
74
|
+
url.searchParams.set('code_challenge', secretHash);
|
|
75
75
|
// Return the url with secret & hashed secret
|
|
76
76
|
return { secret, secretHash, url: url.toString() };
|
|
77
77
|
}
|
|
@@ -135,15 +135,17 @@ export class Auth extends Resource {
|
|
|
135
135
|
if (config.prompt) {
|
|
136
136
|
url.searchParams.set('prompt', config.prompt);
|
|
137
137
|
}
|
|
138
|
-
if (config.metadata) {
|
|
139
|
-
url.searchParams.set('metadata', config.metadata);
|
|
140
|
-
}
|
|
141
138
|
if (config.state) {
|
|
142
139
|
url.searchParams.set('state', config.state);
|
|
143
140
|
}
|
|
144
141
|
return url;
|
|
145
142
|
}
|
|
146
143
|
hashPKCESecret(secret) {
|
|
147
|
-
|
|
144
|
+
const hash = createHash('sha256')
|
|
145
|
+
.update(secret)
|
|
146
|
+
.digest('hex');
|
|
147
|
+
return Buffer.from(hash)
|
|
148
|
+
.toString('base64')
|
|
149
|
+
.replace(/=+$/, '');
|
|
148
150
|
}
|
|
149
151
|
}
|
|
@@ -71,4 +71,16 @@ export class Calendars extends Resource {
|
|
|
71
71
|
overrides,
|
|
72
72
|
});
|
|
73
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Get the free/busy schedule for a list of email addresses
|
|
76
|
+
* @return The free/busy response
|
|
77
|
+
*/
|
|
78
|
+
getFreeBusy({ identifier, requestBody, overrides, }) {
|
|
79
|
+
return this.apiClient.request({
|
|
80
|
+
method: 'POST',
|
|
81
|
+
path: `/v3/grants/${identifier}/calendars/free-busy`,
|
|
82
|
+
body: requestBody,
|
|
83
|
+
overrides,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
74
86
|
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Resource } from './resource.js';
|
|
2
|
+
import { Credentials } from './credentials.js';
|
|
3
|
+
export class Connectors extends Resource {
|
|
4
|
+
/**
|
|
5
|
+
* @param apiClient client The configured Nylas API client
|
|
6
|
+
*/
|
|
7
|
+
constructor(apiClient) {
|
|
8
|
+
super(apiClient);
|
|
9
|
+
this.credentials = new Credentials(apiClient);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Return all connectors
|
|
13
|
+
* @return A list of connectors
|
|
14
|
+
*/
|
|
15
|
+
list({ queryParams, overrides, }) {
|
|
16
|
+
return super._list({
|
|
17
|
+
queryParams,
|
|
18
|
+
overrides,
|
|
19
|
+
path: `/v3/connectors`,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Return a connector
|
|
24
|
+
* @return The connector
|
|
25
|
+
*/
|
|
26
|
+
find({ provider, overrides, }) {
|
|
27
|
+
return super._find({
|
|
28
|
+
path: `/v3/connectors/${provider}`,
|
|
29
|
+
overrides,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Create a connector
|
|
34
|
+
* @return The created connector
|
|
35
|
+
*/
|
|
36
|
+
create({ requestBody, overrides, }) {
|
|
37
|
+
return super._create({
|
|
38
|
+
path: `/v3/connectors`,
|
|
39
|
+
requestBody,
|
|
40
|
+
overrides,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Update a connector
|
|
45
|
+
* @return The updated connector
|
|
46
|
+
*/
|
|
47
|
+
update({ provider, requestBody, overrides, }) {
|
|
48
|
+
return super._update({
|
|
49
|
+
path: `/v3/connectors/${provider}`,
|
|
50
|
+
requestBody,
|
|
51
|
+
overrides,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Delete a connector
|
|
56
|
+
* @return The deleted connector
|
|
57
|
+
*/
|
|
58
|
+
destroy({ provider, overrides, }) {
|
|
59
|
+
return super._destroy({
|
|
60
|
+
path: `/v3/connectors/${provider}`,
|
|
61
|
+
overrides,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Resource } from './resource.js';
|
|
2
|
+
export class Credentials extends Resource {
|
|
3
|
+
/**
|
|
4
|
+
* Return all credentials
|
|
5
|
+
* @return A list of credentials
|
|
6
|
+
*/
|
|
7
|
+
list({ provider, queryParams, overrides, }) {
|
|
8
|
+
return super._list({
|
|
9
|
+
queryParams,
|
|
10
|
+
overrides,
|
|
11
|
+
path: `/v3/credentials/${provider}/creds`,
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Return a credential
|
|
16
|
+
* @return The credential
|
|
17
|
+
*/
|
|
18
|
+
find({ provider, credentialsId, overrides, }) {
|
|
19
|
+
return super._find({
|
|
20
|
+
path: `/v3/credentials/${provider}/creds/${credentialsId}`,
|
|
21
|
+
overrides,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Create a credential
|
|
26
|
+
* @return The created credential
|
|
27
|
+
*/
|
|
28
|
+
create({ provider, requestBody, overrides, }) {
|
|
29
|
+
return super._create({
|
|
30
|
+
path: `/v3/credentials/${provider}/creds`,
|
|
31
|
+
requestBody,
|
|
32
|
+
overrides,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Update a credential
|
|
37
|
+
* @return The updated credential
|
|
38
|
+
*/
|
|
39
|
+
update({ provider, credentialsId, requestBody, overrides, }) {
|
|
40
|
+
return super._update({
|
|
41
|
+
path: `/v3/credentials/${provider}/creds/${credentialsId}}`,
|
|
42
|
+
requestBody,
|
|
43
|
+
overrides,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Delete a credential
|
|
48
|
+
* @return The deleted credential
|
|
49
|
+
*/
|
|
50
|
+
destroy({ provider, credentialsId, overrides, }) {
|
|
51
|
+
return super._destroy({
|
|
52
|
+
path: `/v3/credentials/${provider}/creds/${credentialsId}}`,
|
|
53
|
+
overrides,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Resource } from './resource.js';
|
|
2
|
+
import { Messages } from './messages.js';
|
|
3
|
+
/**
|
|
4
|
+
* Nylas Drafts API
|
|
5
|
+
*
|
|
6
|
+
* The Nylas Drafts API allows you to list, find, update, delete, and send drafts on user accounts.
|
|
7
|
+
*/
|
|
8
|
+
export class Drafts extends Resource {
|
|
9
|
+
/**
|
|
10
|
+
* Return all Drafts
|
|
11
|
+
* @return A list of drafts
|
|
12
|
+
*/
|
|
13
|
+
list({ identifier, queryParams, overrides, }) {
|
|
14
|
+
return super._list({
|
|
15
|
+
queryParams,
|
|
16
|
+
overrides,
|
|
17
|
+
path: `/v3/grants/${identifier}/drafts`,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Return a Draft
|
|
22
|
+
* @return The draft
|
|
23
|
+
*/
|
|
24
|
+
find({ identifier, draftId, overrides, }) {
|
|
25
|
+
return super._find({
|
|
26
|
+
path: `/v3/grants/${identifier}/drafts/${draftId}`,
|
|
27
|
+
overrides,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Return a Draft
|
|
32
|
+
* @return The draft
|
|
33
|
+
*/
|
|
34
|
+
create({ identifier, requestBody, overrides, }) {
|
|
35
|
+
const form = Messages._buildFormRequest(requestBody);
|
|
36
|
+
return this.apiClient.request({
|
|
37
|
+
method: 'POST',
|
|
38
|
+
path: `/v3/grants/${identifier}/drafts`,
|
|
39
|
+
form,
|
|
40
|
+
overrides,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Update a Draft
|
|
45
|
+
* @return The updated draft
|
|
46
|
+
*/
|
|
47
|
+
update({ identifier, draftId, requestBody, overrides, }) {
|
|
48
|
+
const form = Messages._buildFormRequest(requestBody);
|
|
49
|
+
return this.apiClient.request({
|
|
50
|
+
method: 'PUT',
|
|
51
|
+
path: `/v3/grants/${identifier}/drafts/${draftId}`,
|
|
52
|
+
form,
|
|
53
|
+
overrides,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Delete a Draft
|
|
58
|
+
* @return The deleted draft
|
|
59
|
+
*/
|
|
60
|
+
destroy({ identifier, draftId, overrides, }) {
|
|
61
|
+
return super._destroy({
|
|
62
|
+
path: `/v3/grants/${identifier}/drafts/${draftId}`,
|
|
63
|
+
overrides,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Send a Draft
|
|
68
|
+
* @return The sent draft
|
|
69
|
+
*/
|
|
70
|
+
send({ identifier, draftId, overrides, }) {
|
|
71
|
+
return super._create({
|
|
72
|
+
path: `/v3/grants/${identifier}/drafts/${draftId}`,
|
|
73
|
+
requestBody: {},
|
|
74
|
+
overrides,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -27,12 +27,12 @@ export class Grants extends Resource {
|
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
|
-
* Create a Grant
|
|
30
|
+
* Create a Grant via Custom Authentication
|
|
31
31
|
* @return The created Grant
|
|
32
32
|
*/
|
|
33
33
|
create({ requestBody, overrides, }) {
|
|
34
34
|
return super._create({
|
|
35
|
-
path: `/v3/
|
|
35
|
+
path: `/v3/connect/custom`,
|
|
36
36
|
requestBody,
|
|
37
37
|
overrides,
|
|
38
38
|
});
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { Resource } from './resource.js';
|
|
2
|
+
import * as FormData from 'form-data';
|
|
3
|
+
import { objKeysToSnakeCase } from '../utils.js';
|
|
4
|
+
import { SmartCompose } from './smartCompose.js';
|
|
5
|
+
/**
|
|
6
|
+
* Nylas Messages API
|
|
7
|
+
*
|
|
8
|
+
* The Nylas Messages API allows you to list, find, update, delete, schedule, and send messages on user accounts.
|
|
9
|
+
*/
|
|
10
|
+
export class Messages extends Resource {
|
|
11
|
+
constructor(apiClient) {
|
|
12
|
+
super(apiClient);
|
|
13
|
+
this.smartCompose = new SmartCompose(apiClient);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Return all Messages
|
|
17
|
+
* @return A list of messages
|
|
18
|
+
*/
|
|
19
|
+
list({ identifier, queryParams, overrides, }) {
|
|
20
|
+
return super._list({
|
|
21
|
+
queryParams,
|
|
22
|
+
overrides,
|
|
23
|
+
path: `/v3/grants/${identifier}/messages`,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Return a Message
|
|
28
|
+
* @return The message
|
|
29
|
+
*/
|
|
30
|
+
find({ identifier, messageId, overrides, }) {
|
|
31
|
+
return super._find({
|
|
32
|
+
path: `/v3/grants/${identifier}/messages/${messageId}`,
|
|
33
|
+
overrides,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Update a Message
|
|
38
|
+
* @return The updated message
|
|
39
|
+
*/
|
|
40
|
+
update({ identifier, messageId, requestBody, overrides, }) {
|
|
41
|
+
return super._update({
|
|
42
|
+
path: `/v3/grants/${identifier}/messages/${messageId}`,
|
|
43
|
+
requestBody,
|
|
44
|
+
overrides,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Delete a Message
|
|
49
|
+
* @return The deleted message
|
|
50
|
+
*/
|
|
51
|
+
destroy({ identifier, messageId, overrides, }) {
|
|
52
|
+
return super._destroy({
|
|
53
|
+
path: `/v3/grants/${identifier}/messages/${messageId}`,
|
|
54
|
+
overrides,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Send an email
|
|
59
|
+
* @return The sent message
|
|
60
|
+
*/
|
|
61
|
+
send({ identifier, requestBody, overrides, }) {
|
|
62
|
+
const form = Messages._buildFormRequest(requestBody);
|
|
63
|
+
return this.apiClient.request({
|
|
64
|
+
method: 'POST',
|
|
65
|
+
path: `/v3/grants/${identifier}/messages/send`,
|
|
66
|
+
form,
|
|
67
|
+
overrides,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Retrieve your scheduled messages
|
|
72
|
+
* @return A list of scheduled messages
|
|
73
|
+
*/
|
|
74
|
+
listScheduledMessages({ identifier, overrides, }) {
|
|
75
|
+
return super._find({
|
|
76
|
+
path: `/v3/grants/${identifier}/messages/schedules`,
|
|
77
|
+
overrides,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Retrieve a scheduled message
|
|
82
|
+
* @return The scheduled message
|
|
83
|
+
*/
|
|
84
|
+
findScheduledMessage({ identifier, scheduleId, overrides, }) {
|
|
85
|
+
return super._find({
|
|
86
|
+
path: `/v3/grants/${identifier}/messages/schedules/${scheduleId}`,
|
|
87
|
+
overrides,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Stop a scheduled message
|
|
92
|
+
* @return The confirmation of the stopped scheduled message
|
|
93
|
+
*/
|
|
94
|
+
stopScheduledMessage({ identifier, scheduleId, overrides, }) {
|
|
95
|
+
return super._destroy({
|
|
96
|
+
path: `/v3/grants/${identifier}/messages/schedules/${scheduleId}`,
|
|
97
|
+
overrides,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
static _buildFormRequest(requestBody) {
|
|
101
|
+
const form = new FormData();
|
|
102
|
+
// Split out the message payload from the attachments
|
|
103
|
+
const messagePayload = {
|
|
104
|
+
...requestBody,
|
|
105
|
+
attachments: undefined,
|
|
106
|
+
};
|
|
107
|
+
form.append('message', JSON.stringify(objKeysToSnakeCase(messagePayload)));
|
|
108
|
+
// Add a separate form field for each attachment
|
|
109
|
+
requestBody.attachments?.forEach((attachment, index) => {
|
|
110
|
+
form.append(`file${index}`, attachment.content, {
|
|
111
|
+
filename: attachment.filename,
|
|
112
|
+
contentType: attachment.contentType,
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
return form;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Resource } from './resource.js';
|
|
2
|
+
/**
|
|
3
|
+
* A collection of Smart Compose related API endpoints.
|
|
4
|
+
*
|
|
5
|
+
* These endpoints allow for the generation of message suggestions.
|
|
6
|
+
*/
|
|
7
|
+
export class SmartCompose extends Resource {
|
|
8
|
+
/**
|
|
9
|
+
* Compose a message
|
|
10
|
+
* @return The generated message
|
|
11
|
+
*/
|
|
12
|
+
composeMessage({ identifier, requestBody, overrides, }) {
|
|
13
|
+
return super._create({
|
|
14
|
+
path: `/v3/grants/${identifier}/messages/smart-compose`,
|
|
15
|
+
requestBody,
|
|
16
|
+
overrides,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Compose a message reply
|
|
21
|
+
* @return The generated message reply
|
|
22
|
+
*/
|
|
23
|
+
composeMessageReply({ identifier, messageId, requestBody, overrides, }) {
|
|
24
|
+
return super._create({
|
|
25
|
+
path: `/v3/grants/${identifier}/messages/${messageId}/smart-compose`,
|
|
26
|
+
requestBody,
|
|
27
|
+
overrides,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Resource } from './resource.js';
|
|
2
|
+
/**
|
|
3
|
+
* Nylas Threads API
|
|
4
|
+
*
|
|
5
|
+
* The Nylas Threads API allows you to list, find, update, and delete threads on user accounts.
|
|
6
|
+
*/
|
|
7
|
+
export class Threads extends Resource {
|
|
8
|
+
/**
|
|
9
|
+
* Return all Threads
|
|
10
|
+
* @return A list of threads
|
|
11
|
+
*/
|
|
12
|
+
list({ identifier, queryParams, overrides, }) {
|
|
13
|
+
return super._list({
|
|
14
|
+
queryParams,
|
|
15
|
+
overrides,
|
|
16
|
+
path: `/v3/grants/${identifier}/threads`,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Return a Thread
|
|
21
|
+
* @return The thread
|
|
22
|
+
*/
|
|
23
|
+
find({ identifier, threadId, overrides, }) {
|
|
24
|
+
return super._find({
|
|
25
|
+
path: `/v3/grants/${identifier}/threads/${threadId}`,
|
|
26
|
+
overrides,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Update a Thread
|
|
31
|
+
* @return The updated thread
|
|
32
|
+
*/
|
|
33
|
+
update({ identifier, threadId, requestBody, overrides, }) {
|
|
34
|
+
return super._update({
|
|
35
|
+
path: `/v3/grants/${identifier}/threads/${threadId}`,
|
|
36
|
+
requestBody,
|
|
37
|
+
overrides,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Delete a Thread
|
|
42
|
+
* @return The deleted thread
|
|
43
|
+
*/
|
|
44
|
+
destroy({ identifier, threadId, overrides, }) {
|
|
45
|
+
return super._destroy({
|
|
46
|
+
path: `/v3/grants/${identifier}/threads/${threadId}`,
|
|
47
|
+
overrides,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
package/lib/esm/utils.js
CHANGED
|
@@ -1,4 +1,19 @@
|
|
|
1
1
|
import { camelCase, snakeCase } from 'change-case';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
import * as mime from 'mime-types';
|
|
5
|
+
export function createFileRequestBuilder(filePath) {
|
|
6
|
+
const stats = fs.statSync(filePath);
|
|
7
|
+
const filename = path.basename(filePath);
|
|
8
|
+
const contentType = mime.lookup(filePath) || 'application/octet-stream';
|
|
9
|
+
const content = fs.createReadStream(filePath);
|
|
10
|
+
return {
|
|
11
|
+
filename,
|
|
12
|
+
contentType,
|
|
13
|
+
content,
|
|
14
|
+
size: stats.size,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
2
17
|
/**
|
|
3
18
|
* A utility function that recursively converts all keys in an object to a given case.
|
|
4
19
|
* @param obj The object to convert
|