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
package/README.md
CHANGED
|
@@ -4,18 +4,22 @@
|
|
|
4
4
|
|
|
5
5
|
# Nylas Node.js SDK
|
|
6
6
|
|
|
7
|
+
[
|
|
8
|
+
](https://www.npmjs.com/package/nylas/v/beta@)
|
|
7
9
|
[](https://codecov.io/gh/nylas/nylas-nodejs)
|
|
8
10
|
|
|
9
|
-
This is the GitHub repository for the Nylas Node SDK
|
|
11
|
+
This is the GitHub repository for the Nylas Node SDK. This repo is primarily for anyone who wants to make contributions to the SDK, or install it from source. If you are looking to use Node to access the Nylas Email, Calendar, or Contacts API you should refer to our official [Node SDK Quickstart Guide](https://developer.nylas.com/docs/developer-tools/sdk/node-sdk/).
|
|
10
12
|
|
|
11
13
|
The Nylas Communications Platform provides REST APIs for [Email](https://developer.nylas.com/docs/connectivity/email/), [Calendar](https://developer.nylas.com/docs/connectivity/calendar/), and [Contacts](https://developer.nylas.com/docs/connectivity/contacts/), and the Node SDK is the quickest way to build your integration using JavaScript.
|
|
12
14
|
|
|
13
15
|
Here are some resources to help you get started:
|
|
14
16
|
|
|
15
|
-
- [Nylas
|
|
16
|
-
- [
|
|
17
|
+
- [Sign up for your free Nylas account](https://dashboard.nylas.com/register)
|
|
18
|
+
- [Sign up for the Nylas v3 Beta program to access the v3 Dashboard](https://info.nylas.com/apiv3betasignup.html?utm_source=github&utm_medium=devrel-surfaces&utm_campaign=&utm_content=node-sdk-upgrade)
|
|
19
|
+
- [Nylas API v3 Quickstart Guide](https://developer.nylas.com/docs/v3-beta/v3-quickstart/)
|
|
20
|
+
- [Nylas SDK Reference](https://nylas-nodejs-sdk-reference.pages.dev/)
|
|
17
21
|
- [Nylas API Reference](https://developer.nylas.com/docs/api/)
|
|
18
|
-
|
|
22
|
+
- [Nylas Samples repo for code samples and example applications](https://github.com/orgs/nylas-samples/repositories?q=&type=all&language=javascript)
|
|
19
23
|
|
|
20
24
|
## ⚙️ Install
|
|
21
25
|
|
|
@@ -23,12 +27,12 @@ Here are some resources to help you get started:
|
|
|
23
27
|
|
|
24
28
|
### Set up using npm
|
|
25
29
|
|
|
26
|
-
To run the Nylas Node SDK,
|
|
30
|
+
To run the Nylas Node SDK, first install [Node](https://nodejs.org/en/download/) and [npm](https://www.npmjs.com/get-npm) on your machine.
|
|
27
31
|
|
|
28
32
|
Then, head to the nearest command line and run the following:
|
|
29
33
|
`npm install nylas@beta`
|
|
30
34
|
|
|
31
|
-
Alternatively,
|
|
35
|
+
Alternatively, you can use [Yarn](https://yarnpkg.com/en/) to install the Nylas Node SDK by running the `yarn add nylas` command.
|
|
32
36
|
|
|
33
37
|
### Build from source
|
|
34
38
|
|
|
@@ -50,7 +54,7 @@ For code examples that demonstrate how to use this SDK, take a look at our [Node
|
|
|
50
54
|
|
|
51
55
|
### 🚀 Making Your First Request
|
|
52
56
|
|
|
53
|
-
|
|
57
|
+
You access Nylas resources (messages, calendars, events, contacts) through an instance of `Nylas`. The `Nylas` object must be initialized with your Nylas API key, and you can provide other additional configurations such as the Nylas API url and the timeout.
|
|
54
58
|
|
|
55
59
|
```typescript
|
|
56
60
|
import Nylas from "nylas";
|
|
@@ -61,6 +65,7 @@ const nylas = new Nylas({
|
|
|
61
65
|
```
|
|
62
66
|
|
|
63
67
|
Once initialized you can use the object to make requests for a given account's resources, for example to list all the calendars for a given account:
|
|
68
|
+
|
|
64
69
|
```typescript
|
|
65
70
|
nylas.calendars.list({ identifier: "GRANT_ID" }).then(calendars => {
|
|
66
71
|
console.log(calendars);
|
|
@@ -71,12 +76,16 @@ nylas.calendars.list({ identifier: "GRANT_ID" }).then(calendars => {
|
|
|
71
76
|
|
|
72
77
|
Nylas maintains a [reference guide for the Node SDK](https://nylas-nodejs-sdk-reference.pages.dev/) to help you get familiar with the available methods and classes.
|
|
73
78
|
|
|
79
|
+
## ✨ Upgrading from 6.x
|
|
80
|
+
|
|
81
|
+
See [UPGRADE.md](UPGRADE.md) for instructions on upgrading from 6.x to 7.x.
|
|
82
|
+
|
|
83
|
+
**Note**: The Node SDK v7.x is not compatible with the Nylas API earlier than v3-beta.
|
|
84
|
+
|
|
74
85
|
## 💙 Contributing
|
|
75
86
|
|
|
76
87
|
Please refer to [Contributing](Contributing.md) for information about how to make contributions to this project. We welcome questions, bug reports, and pull requests.
|
|
77
88
|
|
|
78
89
|
## 📝 License
|
|
79
90
|
|
|
80
|
-
This project is licensed under the terms of the MIT license. Please refer to [LICENSE](LICENSE.txt) for the full terms.
|
|
81
|
-
|
|
82
|
-
|
|
91
|
+
This project is licensed under the terms of the MIT license. Please refer to [LICENSE](LICENSE.txt) for the full terms.
|
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);
|
|
@@ -55,6 +96,13 @@ class APIClient {
|
|
|
55
96
|
requestOptions.body = JSON.stringify((0, utils_js_1.objKeysToSnakeCase)(optionParams.body));
|
|
56
97
|
requestOptions.headers['Content-Type'] = 'application/json';
|
|
57
98
|
}
|
|
99
|
+
if (optionParams.form) {
|
|
100
|
+
requestOptions.body = optionParams.form;
|
|
101
|
+
requestOptions.headers = {
|
|
102
|
+
...requestOptions.headers,
|
|
103
|
+
...optionParams.form.getHeaders(),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
58
106
|
return requestOptions;
|
|
59
107
|
}
|
|
60
108
|
newRequest(options) {
|
|
@@ -76,39 +124,16 @@ class APIClient {
|
|
|
76
124
|
}
|
|
77
125
|
}
|
|
78
126
|
async request(options) {
|
|
79
|
-
const
|
|
80
|
-
const controller = new AbortController();
|
|
81
|
-
const timeout = setTimeout(() => {
|
|
82
|
-
controller.abort();
|
|
83
|
-
throw new error_js_1.NylasSdkTimeoutError(req.url, this.timeout);
|
|
84
|
-
}, this.timeout);
|
|
85
|
-
const response = await (0, node_fetch_1.default)(req, { signal: controller.signal });
|
|
86
|
-
clearTimeout(timeout);
|
|
87
|
-
if (typeof response === 'undefined') {
|
|
88
|
-
throw new Error('Failed to fetch response');
|
|
89
|
-
}
|
|
90
|
-
// handle error response
|
|
91
|
-
if (response.status > 299) {
|
|
92
|
-
const authErrorResponse = options.path.includes('connect/token') ||
|
|
93
|
-
options.path.includes('connect/revoke');
|
|
94
|
-
const text = await response.text();
|
|
95
|
-
let error;
|
|
96
|
-
try {
|
|
97
|
-
const parsedError = JSON.parse(text);
|
|
98
|
-
const camelCaseError = (0, utils_js_1.objKeysToCamelCase)(parsedError);
|
|
99
|
-
if (authErrorResponse) {
|
|
100
|
-
error = new error_js_1.NylasOAuthError(camelCaseError, response.status);
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
error = new error_js_1.NylasApiError(camelCaseError, response.status);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
catch (e) {
|
|
107
|
-
throw new Error(`Received an error but could not parse response from the server: ${text}`);
|
|
108
|
-
}
|
|
109
|
-
throw error;
|
|
110
|
-
}
|
|
127
|
+
const response = await this.sendRequest(options);
|
|
111
128
|
return this.requestWithResponse(response);
|
|
112
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
|
+
}
|
|
113
138
|
}
|
|
114
139
|
exports.default = APIClient;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CredentialType = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Enum representing the type of credential
|
|
6
|
+
*/
|
|
7
|
+
var CredentialType;
|
|
8
|
+
(function (CredentialType) {
|
|
9
|
+
CredentialType["ADMINCONSENT"] = "adminconsent";
|
|
10
|
+
CredentialType["SERVICEACCOUNT"] = "serviceaccount";
|
|
11
|
+
CredentialType["CONNECTOR"] = "connector";
|
|
12
|
+
})(CredentialType = exports.CredentialType || (exports.CredentialType = {}));
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FreeBusyType = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Enum representing the type of free/busy information returned for a calendar.
|
|
6
|
+
*/
|
|
7
|
+
var FreeBusyType;
|
|
8
|
+
(function (FreeBusyType) {
|
|
9
|
+
FreeBusyType["FREE_BUSY"] = "free_busy";
|
|
10
|
+
FreeBusyType["ERROR"] = "error";
|
|
11
|
+
})(FreeBusyType = exports.FreeBusyType || (exports.FreeBusyType = {}));
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MessageFields = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Enum representing the message fields that can be included in a response.
|
|
6
|
+
*/
|
|
7
|
+
var MessageFields;
|
|
8
|
+
(function (MessageFields) {
|
|
9
|
+
MessageFields["STANDARD"] = "standard";
|
|
10
|
+
MessageFields["INCLUDE_HEADERS"] = "include_headers";
|
|
11
|
+
})(MessageFields = exports.MessageFields || (exports.MessageFields = {}));
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.WebhookTriggers = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Enum representing the available webhook triggers.
|
|
6
|
+
*/
|
|
4
7
|
var WebhookTriggers;
|
|
5
8
|
(function (WebhookTriggers) {
|
|
6
9
|
WebhookTriggers["CalendarCreated"] = "calendar.created";
|
package/lib/cjs/nylas.js
CHANGED
|
@@ -7,6 +7,14 @@ const events_js_1 = require("./resources/events.js");
|
|
|
7
7
|
const auth_js_1 = require("./resources/auth.js");
|
|
8
8
|
const webhooks_js_1 = require("./resources/webhooks.js");
|
|
9
9
|
const applications_js_1 = require("./resources/applications.js");
|
|
10
|
+
const messages_js_1 = require("./resources/messages.js");
|
|
11
|
+
const drafts_js_1 = require("./resources/drafts.js");
|
|
12
|
+
const threads_js_1 = require("./resources/threads.js");
|
|
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");
|
|
10
18
|
/**
|
|
11
19
|
* The entry point to the Node SDK
|
|
12
20
|
*
|
|
@@ -26,8 +34,16 @@ class Nylas {
|
|
|
26
34
|
this.applications = new applications_js_1.Applications(this.apiClient);
|
|
27
35
|
this.auth = new auth_js_1.Auth(this.apiClient);
|
|
28
36
|
this.calendars = new calendars_js_1.Calendars(this.apiClient);
|
|
37
|
+
this.connectors = new connectors_js_1.Connectors(this.apiClient);
|
|
38
|
+
this.drafts = new drafts_js_1.Drafts(this.apiClient);
|
|
29
39
|
this.events = new events_js_1.Events(this.apiClient);
|
|
40
|
+
this.grants = new grants_js_1.Grants(this.apiClient);
|
|
41
|
+
this.messages = new messages_js_1.Messages(this.apiClient);
|
|
42
|
+
this.threads = new threads_js_1.Threads(this.apiClient);
|
|
30
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);
|
|
31
47
|
return this;
|
|
32
48
|
}
|
|
33
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;
|
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Auth = void 0;
|
|
4
4
|
const uuid_1 = require("uuid");
|
|
5
|
-
const
|
|
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
|
|
@@ -74,7 +65,7 @@ class Auth extends resource_js_1.Resource {
|
|
|
74
65
|
url.searchParams.set('code_challenge_method', 's256');
|
|
75
66
|
const secret = (0, uuid_1.v4)();
|
|
76
67
|
const secretHash = this.hashPKCESecret(secret);
|
|
77
|
-
url.searchParams.set('code_challenge',
|
|
68
|
+
url.searchParams.set('code_challenge', secretHash);
|
|
78
69
|
// Return the url with secret & hashed secret
|
|
79
70
|
return { secret, secretHash, url: url.toString() };
|
|
80
71
|
}
|
|
@@ -90,6 +81,18 @@ class Auth extends resource_js_1.Resource {
|
|
|
90
81
|
url.searchParams.set('credential_id', config.credentialId);
|
|
91
82
|
return url.toString();
|
|
92
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* Create a grant via Custom Authentication
|
|
86
|
+
* @return The created grant
|
|
87
|
+
*/
|
|
88
|
+
customAuthentication({ requestBody, overrides, }) {
|
|
89
|
+
return this.apiClient.request({
|
|
90
|
+
method: 'POST',
|
|
91
|
+
path: `/v3/connect/custom`,
|
|
92
|
+
body: requestBody,
|
|
93
|
+
overrides,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
93
96
|
/**
|
|
94
97
|
* Revoke a token (and the grant attached to the token)
|
|
95
98
|
* @param token The token to revoke
|
|
@@ -113,7 +116,7 @@ class Auth extends resource_js_1.Resource {
|
|
|
113
116
|
async detectProvider(params) {
|
|
114
117
|
return this.apiClient.request({
|
|
115
118
|
method: 'POST',
|
|
116
|
-
path: `/v3/
|
|
119
|
+
path: `/v3/providers/detect`,
|
|
117
120
|
queryParams: params,
|
|
118
121
|
});
|
|
119
122
|
}
|
|
@@ -138,16 +141,18 @@ class Auth extends resource_js_1.Resource {
|
|
|
138
141
|
if (config.prompt) {
|
|
139
142
|
url.searchParams.set('prompt', config.prompt);
|
|
140
143
|
}
|
|
141
|
-
if (config.metadata) {
|
|
142
|
-
url.searchParams.set('metadata', config.metadata);
|
|
143
|
-
}
|
|
144
144
|
if (config.state) {
|
|
145
145
|
url.searchParams.set('state', config.state);
|
|
146
146
|
}
|
|
147
147
|
return url;
|
|
148
148
|
}
|
|
149
149
|
hashPKCESecret(secret) {
|
|
150
|
-
|
|
150
|
+
const hash = (0, node_crypto_1.createHash)('sha256')
|
|
151
|
+
.update(secret)
|
|
152
|
+
.digest('hex');
|
|
153
|
+
return Buffer.from(hash)
|
|
154
|
+
.toString('base64')
|
|
155
|
+
.replace(/=+$/, '');
|
|
151
156
|
}
|
|
152
157
|
}
|
|
153
158
|
exports.Auth = Auth;
|
|
@@ -74,5 +74,17 @@ class Calendars extends resource_js_1.Resource {
|
|
|
74
74
|
overrides,
|
|
75
75
|
});
|
|
76
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Get the free/busy schedule for a list of email addresses
|
|
79
|
+
* @return The free/busy response
|
|
80
|
+
*/
|
|
81
|
+
getFreeBusy({ identifier, requestBody, overrides, }) {
|
|
82
|
+
return this.apiClient.request({
|
|
83
|
+
method: 'POST',
|
|
84
|
+
path: `/v3/grants/${identifier}/calendars/free-busy`,
|
|
85
|
+
body: requestBody,
|
|
86
|
+
overrides,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
77
89
|
}
|
|
78
90
|
exports.Calendars = Calendars;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Connectors = void 0;
|
|
4
|
+
const resource_js_1 = require("./resource.js");
|
|
5
|
+
const credentials_js_1 = require("./credentials.js");
|
|
6
|
+
class Connectors extends resource_js_1.Resource {
|
|
7
|
+
/**
|
|
8
|
+
* @param apiClient client The configured Nylas API client
|
|
9
|
+
*/
|
|
10
|
+
constructor(apiClient) {
|
|
11
|
+
super(apiClient);
|
|
12
|
+
this.credentials = new credentials_js_1.Credentials(apiClient);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Return all connectors
|
|
16
|
+
* @return A list of connectors
|
|
17
|
+
*/
|
|
18
|
+
list({ queryParams, overrides, }) {
|
|
19
|
+
return super._list({
|
|
20
|
+
queryParams,
|
|
21
|
+
overrides,
|
|
22
|
+
path: `/v3/connectors`,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Return a connector
|
|
27
|
+
* @return The connector
|
|
28
|
+
*/
|
|
29
|
+
find({ provider, overrides, }) {
|
|
30
|
+
return super._find({
|
|
31
|
+
path: `/v3/connectors/${provider}`,
|
|
32
|
+
overrides,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Create a connector
|
|
37
|
+
* @return The created connector
|
|
38
|
+
*/
|
|
39
|
+
create({ requestBody, overrides, }) {
|
|
40
|
+
return super._create({
|
|
41
|
+
path: `/v3/connectors`,
|
|
42
|
+
requestBody,
|
|
43
|
+
overrides,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Update a connector
|
|
48
|
+
* @return The updated connector
|
|
49
|
+
*/
|
|
50
|
+
update({ provider, requestBody, overrides, }) {
|
|
51
|
+
return super._update({
|
|
52
|
+
path: `/v3/connectors/${provider}`,
|
|
53
|
+
requestBody,
|
|
54
|
+
overrides,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Delete a connector
|
|
59
|
+
* @return The deleted connector
|
|
60
|
+
*/
|
|
61
|
+
destroy({ provider, overrides, }) {
|
|
62
|
+
return super._destroy({
|
|
63
|
+
path: `/v3/connectors/${provider}`,
|
|
64
|
+
overrides,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.Connectors = Connectors;
|
|
@@ -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;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Credentials = void 0;
|
|
4
|
+
const resource_js_1 = require("./resource.js");
|
|
5
|
+
class Credentials extends resource_js_1.Resource {
|
|
6
|
+
/**
|
|
7
|
+
* Return all credentials
|
|
8
|
+
* @return A list of credentials
|
|
9
|
+
*/
|
|
10
|
+
list({ provider, queryParams, overrides, }) {
|
|
11
|
+
return super._list({
|
|
12
|
+
queryParams,
|
|
13
|
+
overrides,
|
|
14
|
+
path: `/v3/credentials/${provider}/creds`,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Return a credential
|
|
19
|
+
* @return The credential
|
|
20
|
+
*/
|
|
21
|
+
find({ provider, credentialsId, overrides, }) {
|
|
22
|
+
return super._find({
|
|
23
|
+
path: `/v3/credentials/${provider}/creds/${credentialsId}`,
|
|
24
|
+
overrides,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Create a credential
|
|
29
|
+
* @return The created credential
|
|
30
|
+
*/
|
|
31
|
+
create({ provider, requestBody, overrides, }) {
|
|
32
|
+
return super._create({
|
|
33
|
+
path: `/v3/credentials/${provider}/creds`,
|
|
34
|
+
requestBody,
|
|
35
|
+
overrides,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Update a credential
|
|
40
|
+
* @return The updated credential
|
|
41
|
+
*/
|
|
42
|
+
update({ provider, credentialsId, requestBody, overrides, }) {
|
|
43
|
+
return super._update({
|
|
44
|
+
path: `/v3/credentials/${provider}/creds/${credentialsId}}`,
|
|
45
|
+
requestBody,
|
|
46
|
+
overrides,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Delete a credential
|
|
51
|
+
* @return The deleted credential
|
|
52
|
+
*/
|
|
53
|
+
destroy({ provider, credentialsId, overrides, }) {
|
|
54
|
+
return super._destroy({
|
|
55
|
+
path: `/v3/credentials/${provider}/creds/${credentialsId}}`,
|
|
56
|
+
overrides,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.Credentials = Credentials;
|