nylas 7.0.0-canary.4 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +50 -28
- package/lib/cjs/apiClient.js +139 -0
- package/lib/cjs/config.js +32 -0
- package/lib/cjs/models/applicationDetails.js +2 -0
- package/lib/cjs/models/attachments.js +2 -0
- package/lib/cjs/models/auth.js +2 -0
- package/lib/cjs/models/availability.js +11 -0
- package/lib/cjs/models/calendars.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/error.js +53 -0
- package/lib/cjs/models/events.js +13 -0
- package/lib/cjs/models/folders.js +2 -0
- package/lib/cjs/models/freeBusy.js +11 -0
- package/lib/cjs/models/grants.js +2 -0
- package/lib/cjs/models/listQueryParams.js +2 -0
- package/lib/cjs/models/messages.js +11 -0
- package/lib/cjs/models/redirectUri.js +2 -0
- package/lib/cjs/models/response.js +2 -0
- package/lib/cjs/models/smartCompose.js +2 -0
- package/lib/cjs/models/threads.js +2 -0
- package/lib/cjs/models/webhooks.js +21 -0
- package/lib/cjs/nylas.js +50 -0
- package/lib/cjs/package.json +3 -0
- package/lib/cjs/resources/applications.js +30 -0
- package/lib/cjs/resources/attachments.js +57 -0
- package/lib/cjs/resources/auth.js +160 -0
- package/lib/cjs/resources/calendars.js +90 -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 +83 -0
- package/lib/cjs/resources/folders.js +72 -0
- package/lib/cjs/resources/grants.js +54 -0
- package/lib/cjs/resources/messages.js +128 -0
- package/lib/cjs/resources/redirectUris.js +64 -0
- package/lib/cjs/resources/resource.js +127 -0
- package/lib/cjs/resources/smartCompose.js +34 -0
- package/lib/cjs/resources/threads.js +54 -0
- package/lib/cjs/resources/webhooks.js +98 -0
- package/lib/cjs/utils.js +74 -0
- package/lib/cjs/version.js +5 -0
- package/lib/esm/apiClient.js +136 -0
- package/lib/esm/config.js +29 -0
- package/lib/esm/models/applicationDetails.js +1 -0
- package/lib/esm/models/attachments.js +1 -0
- package/lib/esm/models/auth.js +1 -0
- package/lib/esm/models/availability.js +8 -0
- package/lib/esm/models/calendars.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/error.js +45 -0
- package/lib/esm/models/events.js +10 -0
- package/lib/esm/models/folders.js +1 -0
- package/lib/esm/models/freeBusy.js +8 -0
- package/lib/esm/models/grants.js +1 -0
- package/lib/esm/models/listQueryParams.js +1 -0
- package/lib/esm/models/messages.js +8 -0
- package/lib/esm/models/redirectUri.js +1 -0
- package/lib/esm/models/response.js +1 -0
- package/lib/esm/models/smartCompose.js +1 -0
- package/lib/esm/models/threads.js +1 -0
- package/lib/esm/models/webhooks.js +18 -0
- package/lib/esm/nylas.js +47 -0
- package/lib/esm/package.json +3 -0
- package/lib/esm/resources/applications.js +26 -0
- package/lib/esm/resources/attachments.js +53 -0
- package/lib/esm/resources/auth.js +156 -0
- package/lib/esm/resources/calendars.js +86 -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 +79 -0
- package/lib/esm/resources/folders.js +68 -0
- package/lib/esm/resources/grants.js +50 -0
- package/lib/esm/resources/messages.js +124 -0
- package/lib/esm/resources/redirectUris.js +60 -0
- package/lib/esm/resources/resource.js +123 -0
- package/lib/esm/resources/smartCompose.js +30 -0
- package/lib/esm/resources/threads.js +50 -0
- package/lib/esm/resources/webhooks.js +94 -0
- package/lib/esm/utils.js +68 -0
- package/lib/esm/version.js +2 -0
- package/lib/types/apiClient.d.ts +72 -0
- package/lib/types/config.d.ts +50 -0
- package/lib/types/models/applicationDetails.d.ts +93 -0
- package/lib/types/models/attachments.d.ts +66 -0
- package/lib/types/models/auth.d.ts +200 -0
- package/lib/types/models/availability.d.ts +159 -0
- package/lib/types/models/calendars.d.ts +121 -0
- package/lib/types/models/connectors.d.ts +123 -0
- package/lib/types/models/contacts.d.ts +147 -0
- package/lib/types/models/credentials.d.ts +151 -0
- package/lib/types/models/drafts.d.ts +97 -0
- package/lib/types/models/error.d.ts +104 -0
- package/lib/types/models/events.d.ts +545 -0
- package/lib/types/models/folders.d.ts +71 -0
- package/lib/types/models/freeBusy.d.ts +79 -0
- package/lib/types/models/grants.d.ts +134 -0
- package/lib/types/models/listQueryParams.d.ts +4 -0
- package/lib/types/models/messages.d.ts +271 -0
- package/lib/types/models/redirectUri.d.ts +71 -0
- package/lib/types/models/response.d.ts +40 -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 +123 -0
- package/lib/types/nylas.d.ts +84 -0
- package/lib/types/resources/applications.d.ts +26 -0
- package/lib/types/resources/attachments.d.ts +61 -0
- package/lib/types/resources/auth.d.ts +70 -0
- package/lib/types/resources/calendars.d.ts +111 -0
- 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 +88 -0
- package/lib/types/resources/events.d.ts +106 -0
- package/lib/types/resources/folders.d.ts +90 -0
- package/lib/types/resources/grants.d.ts +51 -0
- package/lib/types/resources/messages.d.ts +129 -0
- package/lib/types/resources/redirectUris.d.ts +62 -0
- package/lib/types/resources/resource.d.ts +59 -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 +78 -0
- package/lib/types/utils.d.ts +24 -0
- package/lib/types/version.d.ts +1 -0
- package/package.json +35 -41
- package/lib/config.d.ts +0 -70
- package/lib/config.js +0 -68
- package/lib/models/access-token.d.ts +0 -18
- package/lib/models/access-token.js +0 -56
- package/lib/models/account.d.ts +0 -27
- package/lib/models/account.js +0 -73
- package/lib/models/application-details.d.ts +0 -14
- package/lib/models/application-details.js +0 -47
- package/lib/models/attributes.d.ts +0 -151
- package/lib/models/attributes.js +0 -382
- package/lib/models/calendar-availability.d.ts +0 -76
- package/lib/models/calendar-availability.js +0 -121
- package/lib/models/calendar-restful-model-collection.d.ts +0 -17
- package/lib/models/calendar-restful-model-collection.js +0 -181
- package/lib/models/calendar.d.ts +0 -31
- package/lib/models/calendar.js +0 -93
- package/lib/models/component-restful-model-collection.d.ts +0 -9
- package/lib/models/component-restful-model-collection.js +0 -34
- package/lib/models/component.d.ts +0 -37
- package/lib/models/component.js +0 -91
- package/lib/models/connect.d.ts +0 -73
- package/lib/models/connect.js +0 -193
- package/lib/models/contact-restful-model-collection.d.ts +0 -9
- package/lib/models/contact-restful-model-collection.js +0 -60
- package/lib/models/contact.d.ts +0 -129
- package/lib/models/contact.js +0 -289
- package/lib/models/delta-collection.d.ts +0 -17
- package/lib/models/delta-collection.js +0 -139
- package/lib/models/delta-stream.d.ts +0 -32
- package/lib/models/delta-stream.js +0 -250
- package/lib/models/delta.d.ts +0 -28
- package/lib/models/delta.js +0 -88
- package/lib/models/deltas.d.ts +0 -17
- package/lib/models/deltas.js +0 -49
- package/lib/models/draft.d.ts +0 -27
- package/lib/models/draft.js +0 -156
- package/lib/models/email-participant.d.ts +0 -13
- package/lib/models/email-participant.js +0 -46
- package/lib/models/event-conferencing.d.ts +0 -34
- package/lib/models/event-conferencing.js +0 -71
- package/lib/models/event-notification.d.ts +0 -27
- package/lib/models/event-notification.js +0 -62
- package/lib/models/event-participant.d.ts +0 -19
- package/lib/models/event-participant.js +0 -57
- package/lib/models/event.d.ts +0 -88
- package/lib/models/event.js +0 -279
- package/lib/models/file.d.ts +0 -29
- package/lib/models/file.js +0 -136
- package/lib/models/folder.d.ts +0 -21
- package/lib/models/folder.js +0 -69
- package/lib/models/free-busy.d.ts +0 -58
- package/lib/models/free-busy.js +0 -132
- package/lib/models/job-status-restful-model-collection.d.ts +0 -9
- package/lib/models/job-status-restful-model-collection.js +0 -38
- package/lib/models/job-status.d.ts +0 -22
- package/lib/models/job-status.js +0 -65
- package/lib/models/management-account.d.ts +0 -63
- package/lib/models/management-account.js +0 -187
- package/lib/models/management-model-collection.d.ts +0 -10
- package/lib/models/management-model-collection.js +0 -39
- package/lib/models/management-model.d.ts +0 -6
- package/lib/models/management-model.js +0 -29
- package/lib/models/message-restful-model-collection.d.ts +0 -26
- package/lib/models/message-restful-model-collection.js +0 -80
- package/lib/models/message.d.ts +0 -57
- package/lib/models/message.js +0 -173
- package/lib/models/model-collection.d.ts +0 -25
- package/lib/models/model-collection.js +0 -201
- package/lib/models/model.d.ts +0 -12
- package/lib/models/model.js +0 -64
- package/lib/models/neural-categorizer.d.ts +0 -28
- package/lib/models/neural-categorizer.js +0 -139
- package/lib/models/neural-clean-conversation.d.ts +0 -16
- package/lib/models/neural-clean-conversation.js +0 -114
- package/lib/models/neural-ocr.d.ts +0 -14
- package/lib/models/neural-ocr.js +0 -50
- package/lib/models/neural-sentiment-analysis.d.ts +0 -20
- package/lib/models/neural-sentiment-analysis.js +0 -56
- package/lib/models/neural-signature-contact.d.ts +0 -43
- package/lib/models/neural-signature-contact.js +0 -142
- package/lib/models/neural-signature-extraction.d.ts +0 -17
- package/lib/models/neural-signature-extraction.js +0 -54
- package/lib/models/neural.d.ts +0 -36
- package/lib/models/neural.js +0 -163
- package/lib/models/nylas-api-error.d.ts +0 -26
- package/lib/models/nylas-api-error.js +0 -61
- package/lib/models/outbox-job-status.d.ts +0 -20
- package/lib/models/outbox-job-status.js +0 -64
- package/lib/models/outbox-message.d.ts +0 -16
- package/lib/models/outbox-message.js +0 -54
- package/lib/models/outbox.d.ts +0 -35
- package/lib/models/outbox.js +0 -158
- package/lib/models/resource.d.ts +0 -22
- package/lib/models/resource.js +0 -66
- package/lib/models/restful-model-collection.d.ts +0 -15
- package/lib/models/restful-model-collection.js +0 -169
- package/lib/models/restful-model-instance.d.ts +0 -9
- package/lib/models/restful-model-instance.js +0 -37
- package/lib/models/restful-model.d.ts +0 -36
- package/lib/models/restful-model.js +0 -146
- package/lib/models/scheduler-booking-request.d.ts +0 -64
- package/lib/models/scheduler-booking-request.js +0 -148
- package/lib/models/scheduler-restful-model-collection.d.ts +0 -26
- package/lib/models/scheduler-restful-model-collection.js +0 -133
- package/lib/models/scheduler-time-slot.d.ts +0 -20
- package/lib/models/scheduler-time-slot.js +0 -53
- package/lib/models/scheduler.d.ts +0 -223
- package/lib/models/scheduler.js +0 -433
- package/lib/models/thread.d.ts +0 -49
- package/lib/models/thread.js +0 -127
- package/lib/models/webhook-notification.d.ts +0 -108
- package/lib/models/webhook-notification.js +0 -239
- package/lib/models/webhook.d.ts +0 -50
- package/lib/models/webhook.js +0 -101
- package/lib/models/when.d.ts +0 -23
- package/lib/models/when.js +0 -65
- package/lib/nylas-connection.d.ts +0 -71
- package/lib/nylas-connection.js +0 -258
- package/lib/nylas.d.ts +0 -57
- package/lib/nylas.js +0 -210
- package/lib/server-bindings/express-binding.d.ts +0 -18
- package/lib/server-bindings/express-binding.js +0 -163
- package/lib/server-bindings/server-binding.d.ts +0 -65
- package/lib/server-bindings/server-binding.js +0 -87
- package/lib/services/routes.d.ts +0 -26
- package/lib/services/routes.js +0 -95
- package/lib/services/tunnel.d.ts +0 -29
- package/lib/services/tunnel.js +0 -106
package/README.md
CHANGED
|
@@ -1,26 +1,40 @@
|
|
|
1
|
+
<a href="https://www.nylas.com/">
|
|
2
|
+
<img src="https://brand.nylas.com/assets/downloads/logo_horizontal_png/Nylas-Logo-Horizontal-Blue_.png" alt="Aimeos logo" title="Aimeos" align="right" height="60" />
|
|
3
|
+
</a>
|
|
4
|
+
|
|
1
5
|
# Nylas Node.js SDK
|
|
2
6
|
|
|
3
|
-
[
|
|
8
|
+
](https://www.npmjs.com/package/nylas)
|
|
9
|
+
[](https://codecov.io/gh/nylas/nylas-nodejs)
|
|
4
10
|
|
|
5
|
-
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/).
|
|
6
12
|
|
|
7
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.
|
|
8
14
|
|
|
9
15
|
Here are some resources to help you get started:
|
|
10
16
|
|
|
11
|
-
- [Nylas
|
|
12
|
-
- [
|
|
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/)
|
|
13
21
|
- [Nylas API Reference](https://developer.nylas.com/docs/api/)
|
|
22
|
+
- [Nylas Samples repo for code samples and example applications](https://github.com/orgs/nylas-samples/repositories?q=&type=all&language=javascript)
|
|
23
|
+
|
|
24
|
+
## ⚙️ Install
|
|
14
25
|
|
|
26
|
+
**Note:** The Nylas Node SDK requires Node.js v16 or later.
|
|
15
27
|
|
|
16
|
-
|
|
28
|
+
### Set up using npm
|
|
17
29
|
|
|
18
|
-
To
|
|
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.
|
|
19
31
|
|
|
20
32
|
Then, head to the nearest command line and run the following:
|
|
21
33
|
`npm install nylas`
|
|
22
34
|
|
|
23
|
-
Alternatively,
|
|
35
|
+
Alternatively, you can use [Yarn](https://yarnpkg.com/en/) to install the Nylas Node SDK by running the `yarn add nylas` command.
|
|
36
|
+
|
|
37
|
+
### Build from source
|
|
24
38
|
|
|
25
39
|
To install this package from source, clone this repo and run `npm install` from inside the project directory.
|
|
26
40
|
|
|
@@ -30,40 +44,48 @@ cd nylas-nodejs
|
|
|
30
44
|
npm install
|
|
31
45
|
```
|
|
32
46
|
|
|
33
|
-
|
|
47
|
+
## ⚡️ Usage
|
|
34
48
|
|
|
35
|
-
|
|
49
|
+
To use this SDK, you must first [get a free Nylas account](https://dashboard.nylas.com/register).
|
|
36
50
|
|
|
37
|
-
|
|
38
|
-
const Nylas = require('nylas');
|
|
51
|
+
Then, follow the Quickstart guide to [set up your first app and get your API keys](https://developer.nylas.com/docs/v3-beta/v3-quickstart/).
|
|
39
52
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
53
|
+
For code examples that demonstrate how to use this SDK, take a look at our [Node repos in the Nylas Samples collection](https://github.com/orgs/nylas-samples/repositories?q=&type=all&language=javascript&sort=).
|
|
54
|
+
|
|
55
|
+
### 🚀 Making Your First Request
|
|
56
|
+
|
|
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.
|
|
45
58
|
|
|
46
|
-
|
|
59
|
+
```typescript
|
|
60
|
+
import Nylas from "nylas";
|
|
47
61
|
|
|
48
|
-
|
|
49
|
-
|
|
62
|
+
const nylas = new Nylas({
|
|
63
|
+
apiKey: "NYLAS_API_KEY",
|
|
64
|
+
});
|
|
50
65
|
```
|
|
51
66
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
nylas.calendars.list({ identifier: "GRANT_ID" }).then(calendars => {
|
|
71
|
+
console.log(calendars);
|
|
56
72
|
});
|
|
57
73
|
```
|
|
58
74
|
|
|
59
|
-
|
|
75
|
+
## 📚 Documentation
|
|
60
76
|
|
|
61
|
-
|
|
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.
|
|
62
78
|
|
|
63
|
-
|
|
79
|
+
## ✨ Upgrading from 6.x
|
|
64
80
|
|
|
65
|
-
|
|
81
|
+
See [UPGRADE.md](UPGRADE.md) for instructions on upgrading from 6.x to 7.x.
|
|
66
82
|
|
|
67
|
-
|
|
83
|
+
**Note**: The Node SDK v7.x is not compatible with the Nylas API earlier than v3-beta.
|
|
84
|
+
|
|
85
|
+
## 💙 Contributing
|
|
86
|
+
|
|
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.
|
|
68
88
|
|
|
89
|
+
## 📝 License
|
|
69
90
|
|
|
91
|
+
This project is licensed under the terms of the MIT license. Please refer to [LICENSE](LICENSE.txt) for the full terms.
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const node_fetch_1 = require("node-fetch");
|
|
4
|
+
const error_js_1 = require("./models/error.js");
|
|
5
|
+
const utils_js_1 = require("./utils.js");
|
|
6
|
+
const version_js_1 = require("./version.js");
|
|
7
|
+
/**
|
|
8
|
+
* The API client for communicating with the Nylas API
|
|
9
|
+
* @ignore Not for public use
|
|
10
|
+
*/
|
|
11
|
+
class APIClient {
|
|
12
|
+
constructor({ apiKey, apiUri, timeout }) {
|
|
13
|
+
this.apiKey = apiKey;
|
|
14
|
+
this.serverUrl = apiUri;
|
|
15
|
+
this.timeout = timeout * 1000; // fetch timeout uses milliseconds
|
|
16
|
+
}
|
|
17
|
+
setRequestUrl({ overrides, path, queryParams, }) {
|
|
18
|
+
const url = new URL(`${overrides?.apiUri || this.serverUrl}${path}`);
|
|
19
|
+
return this.setQueryStrings(url, queryParams);
|
|
20
|
+
}
|
|
21
|
+
setQueryStrings(url, queryParams) {
|
|
22
|
+
if (queryParams) {
|
|
23
|
+
const snakeCaseParams = (0, utils_js_1.objKeysToSnakeCase)(queryParams, ['metadataPair']);
|
|
24
|
+
for (const [key, value] of Object.entries(snakeCaseParams)) {
|
|
25
|
+
if (key == 'metadataPair') {
|
|
26
|
+
// The API understands a metadata_pair filter in the form of:
|
|
27
|
+
// <key>:<value>
|
|
28
|
+
const metadataPair = [];
|
|
29
|
+
for (const item in value) {
|
|
30
|
+
metadataPair.push(`${item}:${value[item]}`);
|
|
31
|
+
}
|
|
32
|
+
url.searchParams.set('metadata_pair', metadataPair.join(','));
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
url.searchParams.set(key, value);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return url;
|
|
40
|
+
}
|
|
41
|
+
setRequestHeaders({ headers, overrides, }) {
|
|
42
|
+
return {
|
|
43
|
+
Accept: 'application/json',
|
|
44
|
+
'User-Agent': `Nylas Node SDK v${version_js_1.SDK_VERSION}`,
|
|
45
|
+
Authorization: `Bearer ${overrides?.apiKey || this.apiKey}`,
|
|
46
|
+
...headers,
|
|
47
|
+
};
|
|
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
|
+
}
|
|
90
|
+
requestOptions(optionParams) {
|
|
91
|
+
const requestOptions = {};
|
|
92
|
+
requestOptions.url = this.setRequestUrl(optionParams);
|
|
93
|
+
requestOptions.headers = this.setRequestHeaders(optionParams);
|
|
94
|
+
requestOptions.method = optionParams.method;
|
|
95
|
+
if (optionParams.body) {
|
|
96
|
+
requestOptions.body = JSON.stringify((0, utils_js_1.objKeysToSnakeCase)(optionParams.body));
|
|
97
|
+
requestOptions.headers['Content-Type'] = 'application/json';
|
|
98
|
+
}
|
|
99
|
+
if (optionParams.form) {
|
|
100
|
+
requestOptions.body = optionParams.form;
|
|
101
|
+
requestOptions.headers = {
|
|
102
|
+
...requestOptions.headers,
|
|
103
|
+
...optionParams.form.getHeaders(),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
return requestOptions;
|
|
107
|
+
}
|
|
108
|
+
newRequest(options) {
|
|
109
|
+
const newOptions = this.requestOptions(options);
|
|
110
|
+
return new node_fetch_1.Request(newOptions.url, {
|
|
111
|
+
method: newOptions.method,
|
|
112
|
+
headers: newOptions.headers,
|
|
113
|
+
body: newOptions.body,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
async requestWithResponse(response) {
|
|
117
|
+
const text = await response.text();
|
|
118
|
+
try {
|
|
119
|
+
const responseJSON = JSON.parse(text);
|
|
120
|
+
return (0, utils_js_1.objKeysToCamelCase)(responseJSON);
|
|
121
|
+
}
|
|
122
|
+
catch (e) {
|
|
123
|
+
throw new Error(`Could not parse response from the server: ${text}`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
async request(options) {
|
|
127
|
+
const response = await this.sendRequest(options);
|
|
128
|
+
return this.requestWithResponse(response);
|
|
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
|
+
}
|
|
138
|
+
}
|
|
139
|
+
exports.default = APIClient;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_SERVER_URL = exports.REGION_CONFIG = exports.DEFAULT_REGION = exports.Region = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Enum representing the available Nylas API regions.
|
|
6
|
+
*/
|
|
7
|
+
var Region;
|
|
8
|
+
(function (Region) {
|
|
9
|
+
Region["Us"] = "us";
|
|
10
|
+
Region["Eu"] = "eu";
|
|
11
|
+
})(Region = exports.Region || (exports.Region = {}));
|
|
12
|
+
/**
|
|
13
|
+
* The default Nylas API region.
|
|
14
|
+
* @default Region.Us
|
|
15
|
+
*/
|
|
16
|
+
exports.DEFAULT_REGION = Region.Us;
|
|
17
|
+
/**
|
|
18
|
+
* The available preset configuration values for each Nylas API region.
|
|
19
|
+
*/
|
|
20
|
+
exports.REGION_CONFIG = {
|
|
21
|
+
[Region.Us]: {
|
|
22
|
+
nylasAPIUrl: 'https://api.us.nylas.com',
|
|
23
|
+
},
|
|
24
|
+
[Region.Eu]: {
|
|
25
|
+
nylasAPIUrl: 'https://api.eu.nylas.com',
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* The default Nylas API URL.
|
|
30
|
+
* @default https://api.us.nylas.com
|
|
31
|
+
*/
|
|
32
|
+
exports.DEFAULT_SERVER_URL = exports.REGION_CONFIG[exports.DEFAULT_REGION].nylasAPIUrl;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AvailabilityMethod = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Enum representing the method used to determine availability for a meeting.
|
|
6
|
+
*/
|
|
7
|
+
var AvailabilityMethod;
|
|
8
|
+
(function (AvailabilityMethod) {
|
|
9
|
+
AvailabilityMethod["MaxFairness"] = "max-fairness";
|
|
10
|
+
AvailabilityMethod["MaxAvailability"] = "max-availability";
|
|
11
|
+
})(AvailabilityMethod = exports.AvailabilityMethod || (exports.AvailabilityMethod = {}));
|
|
@@ -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,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NylasSdkTimeoutError = exports.NylasOAuthError = exports.NylasApiError = exports.AbstractNylasSdkError = exports.AbstractNylasApiError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Base class for all Nylas API errors.
|
|
6
|
+
*/
|
|
7
|
+
class AbstractNylasApiError extends Error {
|
|
8
|
+
}
|
|
9
|
+
exports.AbstractNylasApiError = AbstractNylasApiError;
|
|
10
|
+
/**
|
|
11
|
+
* Base class for all Nylas SDK errors.
|
|
12
|
+
*/
|
|
13
|
+
class AbstractNylasSdkError extends Error {
|
|
14
|
+
}
|
|
15
|
+
exports.AbstractNylasSdkError = AbstractNylasSdkError;
|
|
16
|
+
/**
|
|
17
|
+
* Class representation of a general Nylas API error.
|
|
18
|
+
*/
|
|
19
|
+
class NylasApiError extends AbstractNylasApiError {
|
|
20
|
+
constructor(apiError, statusCode) {
|
|
21
|
+
super(apiError.error.message);
|
|
22
|
+
this.type = apiError.error.type;
|
|
23
|
+
this.requestId = apiError.requestId;
|
|
24
|
+
this.providerError = apiError.error.providerError;
|
|
25
|
+
this.statusCode = statusCode;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.NylasApiError = NylasApiError;
|
|
29
|
+
/**
|
|
30
|
+
* Class representing an OAuth error returned by the Nylas API.
|
|
31
|
+
*/
|
|
32
|
+
class NylasOAuthError extends AbstractNylasApiError {
|
|
33
|
+
constructor(apiError, statusCode) {
|
|
34
|
+
super(apiError.errorDescription);
|
|
35
|
+
this.error = apiError.error;
|
|
36
|
+
this.errorCode = apiError.errorCode;
|
|
37
|
+
this.errorDescription = apiError.errorDescription;
|
|
38
|
+
this.errorUri = apiError.errorUri;
|
|
39
|
+
this.statusCode = statusCode;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.NylasOAuthError = NylasOAuthError;
|
|
43
|
+
/**
|
|
44
|
+
* Error thrown when the Nylas SDK times out before receiving a response from the server
|
|
45
|
+
*/
|
|
46
|
+
class NylasSdkTimeoutError extends AbstractNylasSdkError {
|
|
47
|
+
constructor(url, timeout) {
|
|
48
|
+
super('Nylas SDK timed out before receiving a response from the server.');
|
|
49
|
+
this.url = url;
|
|
50
|
+
this.timeout = timeout;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.NylasSdkTimeoutError = NylasSdkTimeoutError;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
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 = {}));
|
|
@@ -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 = {}));
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WebhookTriggers = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Enum representing the available webhook triggers.
|
|
6
|
+
*/
|
|
7
|
+
var WebhookTriggers;
|
|
8
|
+
(function (WebhookTriggers) {
|
|
9
|
+
WebhookTriggers["CalendarCreated"] = "calendar.created";
|
|
10
|
+
WebhookTriggers["CalendarUpdated"] = "calendar.updated";
|
|
11
|
+
WebhookTriggers["CalendarDeleted"] = "calendar.deleted";
|
|
12
|
+
WebhookTriggers["EventCreated"] = "event.created";
|
|
13
|
+
WebhookTriggers["EventUpdated"] = "event.updated";
|
|
14
|
+
WebhookTriggers["EventDeleted"] = "event.deleted";
|
|
15
|
+
WebhookTriggers["GrantCreated"] = "grant.created";
|
|
16
|
+
WebhookTriggers["GrantUpdated"] = "grant.updated";
|
|
17
|
+
WebhookTriggers["GrantDeleted"] = "grant.deleted";
|
|
18
|
+
WebhookTriggers["GrantExpired"] = "grant.expired";
|
|
19
|
+
WebhookTriggers["MessageSendSuccess"] = "message.send_success";
|
|
20
|
+
WebhookTriggers["MessageSendFailed"] = "message.send_failed";
|
|
21
|
+
})(WebhookTriggers = exports.WebhookTriggers || (exports.WebhookTriggers = {}));
|
package/lib/cjs/nylas.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const apiClient_js_1 = require("./apiClient.js");
|
|
4
|
+
const config_js_1 = require("./config.js");
|
|
5
|
+
const calendars_js_1 = require("./resources/calendars.js");
|
|
6
|
+
const events_js_1 = require("./resources/events.js");
|
|
7
|
+
const auth_js_1 = require("./resources/auth.js");
|
|
8
|
+
const webhooks_js_1 = require("./resources/webhooks.js");
|
|
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");
|
|
18
|
+
/**
|
|
19
|
+
* The entry point to the Node SDK
|
|
20
|
+
*
|
|
21
|
+
* A Nylas instance holds a configured http client pointing to a base URL and is intended to be reused and shared
|
|
22
|
+
* across threads and time.
|
|
23
|
+
*/
|
|
24
|
+
class Nylas {
|
|
25
|
+
/**
|
|
26
|
+
* @param config Configuration options for the Nylas SDK
|
|
27
|
+
*/
|
|
28
|
+
constructor(config) {
|
|
29
|
+
this.apiClient = new apiClient_js_1.default({
|
|
30
|
+
apiKey: config.apiKey,
|
|
31
|
+
apiUri: config.apiUri || config_js_1.DEFAULT_SERVER_URL,
|
|
32
|
+
timeout: config.timeout || 30,
|
|
33
|
+
});
|
|
34
|
+
this.applications = new applications_js_1.Applications(this.apiClient);
|
|
35
|
+
this.auth = new auth_js_1.Auth(this.apiClient);
|
|
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);
|
|
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);
|
|
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);
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.default = Nylas;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Applications = void 0;
|
|
4
|
+
const resource_js_1 = require("./resource.js");
|
|
5
|
+
const redirectUris_js_1 = require("./redirectUris.js");
|
|
6
|
+
/**
|
|
7
|
+
* Nylas Applications API
|
|
8
|
+
*
|
|
9
|
+
* This endpoint allows for getting application details as well as redirect URI operations.
|
|
10
|
+
*/
|
|
11
|
+
class Applications extends resource_js_1.Resource {
|
|
12
|
+
/**
|
|
13
|
+
* @param apiClient client The configured Nylas API client
|
|
14
|
+
*/
|
|
15
|
+
constructor(apiClient) {
|
|
16
|
+
super(apiClient);
|
|
17
|
+
this.redirectUris = new redirectUris_js_1.RedirectUris(apiClient);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Get application details
|
|
21
|
+
* @returns The application details
|
|
22
|
+
*/
|
|
23
|
+
getDetails({ overrides } = {}) {
|
|
24
|
+
return super._find({
|
|
25
|
+
path: `/v3/applications`,
|
|
26
|
+
overrides,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.Applications = Applications;
|
|
@@ -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;
|