nylas 6.10.0 → 7.0.0-beta.1

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.
Files changed (197) hide show
  1. package/README.md +26 -14
  2. package/lib/cjs/apiClient.js +115 -0
  3. package/lib/cjs/config.js +32 -0
  4. package/lib/cjs/models/applicationDetails.js +2 -0
  5. package/lib/cjs/models/auth.js +2 -0
  6. package/lib/cjs/models/availability.js +11 -0
  7. package/lib/cjs/models/calendars.js +2 -0
  8. package/lib/cjs/models/error.js +53 -0
  9. package/lib/cjs/models/events.js +2 -0
  10. package/lib/cjs/models/grants.js +2 -0
  11. package/lib/cjs/models/listQueryParams.js +2 -0
  12. package/lib/cjs/models/redirectUri.js +2 -0
  13. package/lib/cjs/models/response.js +2 -0
  14. package/lib/cjs/models/webhooks.js +18 -0
  15. package/lib/cjs/nylas.js +34 -0
  16. package/lib/cjs/resources/applications.js +30 -0
  17. package/lib/cjs/resources/auth.js +153 -0
  18. package/lib/cjs/resources/calendars.js +78 -0
  19. package/lib/cjs/resources/events.js +69 -0
  20. package/lib/cjs/resources/grants.js +65 -0
  21. package/lib/cjs/resources/redirectUris.js +64 -0
  22. package/lib/cjs/resources/resource.js +111 -0
  23. package/lib/cjs/resources/webhooks.js +98 -0
  24. package/lib/cjs/utils.js +58 -0
  25. package/lib/esm/apiClient.js +112 -0
  26. package/lib/esm/config.js +29 -0
  27. package/lib/esm/models/applicationDetails.js +1 -0
  28. package/lib/esm/models/auth.js +1 -0
  29. package/lib/esm/models/availability.js +8 -0
  30. package/lib/esm/models/calendars.js +1 -0
  31. package/lib/esm/models/error.js +45 -0
  32. package/lib/esm/models/events.js +1 -0
  33. package/lib/esm/models/grants.js +1 -0
  34. package/lib/esm/models/listQueryParams.js +1 -0
  35. package/lib/esm/models/redirectUri.js +1 -0
  36. package/lib/esm/models/response.js +1 -0
  37. package/lib/esm/models/webhooks.js +15 -0
  38. package/lib/esm/nylas.js +31 -0
  39. package/lib/esm/resources/applications.js +26 -0
  40. package/lib/esm/resources/auth.js +149 -0
  41. package/lib/esm/resources/calendars.js +74 -0
  42. package/lib/esm/resources/events.js +65 -0
  43. package/lib/esm/resources/grants.js +61 -0
  44. package/lib/esm/resources/redirectUris.js +60 -0
  45. package/lib/esm/resources/resource.js +107 -0
  46. package/lib/esm/resources/webhooks.js +94 -0
  47. package/lib/esm/utils.js +53 -0
  48. package/lib/types/apiClient.d.ts +65 -0
  49. package/lib/types/config.d.ts +50 -0
  50. package/lib/types/models/applicationDetails.d.ts +93 -0
  51. package/lib/types/models/auth.d.ts +196 -0
  52. package/lib/types/models/availability.d.ts +159 -0
  53. package/lib/types/models/calendars.d.ts +121 -0
  54. package/lib/types/models/error.d.ts +104 -0
  55. package/lib/types/models/events.d.ts +494 -0
  56. package/lib/types/models/grants.d.ts +134 -0
  57. package/lib/types/models/listQueryParams.d.ts +4 -0
  58. package/lib/types/models/redirectUri.d.ts +71 -0
  59. package/lib/types/models/response.d.ts +40 -0
  60. package/lib/types/models/webhooks.d.ts +45 -0
  61. package/lib/types/nylas.d.ts +44 -0
  62. package/lib/types/resources/applications.d.ts +26 -0
  63. package/lib/types/resources/auth.d.ts +66 -0
  64. package/lib/types/resources/calendars.d.ts +97 -0
  65. package/lib/types/resources/events.d.ts +87 -0
  66. package/lib/types/resources/grants.d.ts +63 -0
  67. package/lib/types/resources/redirectUris.d.ts +63 -0
  68. package/lib/types/resources/resource.d.ts +55 -0
  69. package/lib/types/resources/webhooks.d.ts +79 -0
  70. package/lib/types/utils.d.ts +22 -0
  71. package/package.json +28 -39
  72. package/lib/config.d.ts +0 -52
  73. package/lib/config.js +0 -47
  74. package/lib/models/access-token.d.ts +0 -18
  75. package/lib/models/access-token.js +0 -56
  76. package/lib/models/account.d.ts +0 -27
  77. package/lib/models/account.js +0 -73
  78. package/lib/models/application-details.d.ts +0 -14
  79. package/lib/models/application-details.js +0 -47
  80. package/lib/models/attributes.d.ts +0 -151
  81. package/lib/models/attributes.js +0 -382
  82. package/lib/models/calendar-availability.d.ts +0 -76
  83. package/lib/models/calendar-availability.js +0 -121
  84. package/lib/models/calendar-restful-model-collection.d.ts +0 -17
  85. package/lib/models/calendar-restful-model-collection.js +0 -181
  86. package/lib/models/calendar.d.ts +0 -33
  87. package/lib/models/calendar.js +0 -97
  88. package/lib/models/component-restful-model-collection.d.ts +0 -9
  89. package/lib/models/component-restful-model-collection.js +0 -34
  90. package/lib/models/component.d.ts +0 -37
  91. package/lib/models/component.js +0 -91
  92. package/lib/models/connect.d.ts +0 -73
  93. package/lib/models/connect.js +0 -193
  94. package/lib/models/contact-restful-model-collection.d.ts +0 -9
  95. package/lib/models/contact-restful-model-collection.js +0 -60
  96. package/lib/models/contact.d.ts +0 -129
  97. package/lib/models/contact.js +0 -289
  98. package/lib/models/delta-collection.d.ts +0 -17
  99. package/lib/models/delta-collection.js +0 -139
  100. package/lib/models/delta-stream.d.ts +0 -32
  101. package/lib/models/delta-stream.js +0 -250
  102. package/lib/models/delta.d.ts +0 -28
  103. package/lib/models/delta.js +0 -88
  104. package/lib/models/deltas.d.ts +0 -17
  105. package/lib/models/deltas.js +0 -49
  106. package/lib/models/draft.d.ts +0 -27
  107. package/lib/models/draft.js +0 -156
  108. package/lib/models/email-participant.d.ts +0 -13
  109. package/lib/models/email-participant.js +0 -46
  110. package/lib/models/event-conferencing.d.ts +0 -34
  111. package/lib/models/event-conferencing.js +0 -71
  112. package/lib/models/event-notification.d.ts +0 -27
  113. package/lib/models/event-notification.js +0 -62
  114. package/lib/models/event-participant.d.ts +0 -19
  115. package/lib/models/event-participant.js +0 -56
  116. package/lib/models/event-reminder-method.d.ts +0 -18
  117. package/lib/models/event-reminder-method.js +0 -47
  118. package/lib/models/event.d.ts +0 -104
  119. package/lib/models/event.js +0 -308
  120. package/lib/models/file.d.ts +0 -29
  121. package/lib/models/file.js +0 -136
  122. package/lib/models/folder.d.ts +0 -21
  123. package/lib/models/folder.js +0 -69
  124. package/lib/models/free-busy.d.ts +0 -58
  125. package/lib/models/free-busy.js +0 -132
  126. package/lib/models/job-status-restful-model-collection.d.ts +0 -9
  127. package/lib/models/job-status-restful-model-collection.js +0 -38
  128. package/lib/models/job-status.d.ts +0 -24
  129. package/lib/models/job-status.js +0 -68
  130. package/lib/models/management-account.d.ts +0 -63
  131. package/lib/models/management-account.js +0 -187
  132. package/lib/models/management-model-collection.d.ts +0 -10
  133. package/lib/models/management-model-collection.js +0 -39
  134. package/lib/models/management-model.d.ts +0 -6
  135. package/lib/models/management-model.js +0 -29
  136. package/lib/models/message-restful-model-collection.d.ts +0 -26
  137. package/lib/models/message-restful-model-collection.js +0 -80
  138. package/lib/models/message.d.ts +0 -57
  139. package/lib/models/message.js +0 -173
  140. package/lib/models/model-collection.d.ts +0 -25
  141. package/lib/models/model-collection.js +0 -201
  142. package/lib/models/model.d.ts +0 -12
  143. package/lib/models/model.js +0 -64
  144. package/lib/models/neural-categorizer.d.ts +0 -28
  145. package/lib/models/neural-categorizer.js +0 -139
  146. package/lib/models/neural-clean-conversation.d.ts +0 -16
  147. package/lib/models/neural-clean-conversation.js +0 -114
  148. package/lib/models/neural-ocr.d.ts +0 -14
  149. package/lib/models/neural-ocr.js +0 -50
  150. package/lib/models/neural-sentiment-analysis.d.ts +0 -20
  151. package/lib/models/neural-sentiment-analysis.js +0 -56
  152. package/lib/models/neural-signature-contact.d.ts +0 -43
  153. package/lib/models/neural-signature-contact.js +0 -142
  154. package/lib/models/neural-signature-extraction.d.ts +0 -17
  155. package/lib/models/neural-signature-extraction.js +0 -54
  156. package/lib/models/neural.d.ts +0 -36
  157. package/lib/models/neural.js +0 -163
  158. package/lib/models/nylas-api-error.d.ts +0 -26
  159. package/lib/models/nylas-api-error.js +0 -62
  160. package/lib/models/outbox-job-status.d.ts +0 -20
  161. package/lib/models/outbox-job-status.js +0 -64
  162. package/lib/models/outbox-message.d.ts +0 -16
  163. package/lib/models/outbox-message.js +0 -54
  164. package/lib/models/outbox.d.ts +0 -35
  165. package/lib/models/outbox.js +0 -158
  166. package/lib/models/rate-limit-error.d.ts +0 -26
  167. package/lib/models/rate-limit-error.js +0 -47
  168. package/lib/models/resource.d.ts +0 -22
  169. package/lib/models/resource.js +0 -66
  170. package/lib/models/restful-model-collection.d.ts +0 -15
  171. package/lib/models/restful-model-collection.js +0 -169
  172. package/lib/models/restful-model-instance.d.ts +0 -9
  173. package/lib/models/restful-model-instance.js +0 -37
  174. package/lib/models/restful-model.d.ts +0 -36
  175. package/lib/models/restful-model.js +0 -146
  176. package/lib/models/scheduler-booking-request.d.ts +0 -64
  177. package/lib/models/scheduler-booking-request.js +0 -148
  178. package/lib/models/scheduler-restful-model-collection.d.ts +0 -26
  179. package/lib/models/scheduler-restful-model-collection.js +0 -133
  180. package/lib/models/scheduler-time-slot.d.ts +0 -20
  181. package/lib/models/scheduler-time-slot.js +0 -53
  182. package/lib/models/scheduler.d.ts +0 -226
  183. package/lib/models/scheduler.js +0 -446
  184. package/lib/models/thread.d.ts +0 -49
  185. package/lib/models/thread.js +0 -127
  186. package/lib/models/webhook-notification.d.ts +0 -133
  187. package/lib/models/webhook-notification.js +0 -314
  188. package/lib/models/webhook.d.ts +0 -50
  189. package/lib/models/webhook.js +0 -101
  190. package/lib/models/when.d.ts +0 -29
  191. package/lib/models/when.js +0 -76
  192. package/lib/nylas-connection.d.ts +0 -71
  193. package/lib/nylas-connection.js +0 -282
  194. package/lib/nylas.d.ts +0 -34
  195. package/lib/nylas.js +0 -199
  196. package/lib/services/tunnel.d.ts +0 -28
  197. package/lib/services/tunnel.js +0 -89
package/README.md CHANGED
@@ -4,7 +4,6 @@
4
4
 
5
5
  # Nylas Node.js SDK
6
6
 
7
- [![Travis build status](https://travis-ci.org/nylas/nylas-nodejs.svg?branch=master)](https://travis-ci.org/nylas/nylas-nodejs)
8
7
  [![codecov](https://codecov.io/gh/nylas/nylas-nodejs/branch/main/graph/badge.svg?token=94IMGU4F09)](https://codecov.io/gh/nylas/nylas-nodejs)
9
8
 
10
9
  This is the GitHub repository for the Nylas Node SDK and 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/).
@@ -20,6 +19,10 @@ Here are some resources to help you get started:
20
19
 
21
20
  ## ⚙️ Install
22
21
 
22
+ **Note:** The Nylas Node SDK requires Node.js v16 or later.
23
+
24
+ ### Set up using npm
25
+
23
26
  To run the Nylas Node SDK, you will first need to have [Node](https://nodejs.org/en/download/) and [npm](https://www.npmjs.com/get-npm) installed on your machine.
24
27
 
25
28
  Then, head to the nearest command line and run the following:
@@ -27,6 +30,8 @@ Then, head to the nearest command line and run the following:
27
30
 
28
31
  Alternatively, if you prefer to use [Yarn](https://yarnpkg.com/en/), you can install the Nylas Node SDK with `yarn add nylas`
29
32
 
33
+ ### Build from source
34
+
30
35
  To install this package from source, clone this repo and run `npm install` from inside the project directory.
31
36
 
32
37
  ```bash
@@ -37,27 +42,34 @@ npm install
37
42
 
38
43
  ## ⚡️ Usage
39
44
 
40
- Every resource (i.e., messages, events, contacts) is accessed via an instance of `Nylas`. Before making any requests, be sure to call `config` and initialize the `Nylas` instance with your `clientId` and `clientSecret`. Then, call `with` and pass it your `accessToken`. The `accessToken` allows `Nylas` to make requests for a given account's resources.
45
+ To use this SDK, you must first [get a free Nylas account](https://dashboard.nylas.com/register).
41
46
 
42
- ```javascript
43
- const Nylas = require('nylas');
47
+ 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/).
44
48
 
45
- Nylas.config({
46
- clientId: CLIENT_ID,
47
- clientSecret: CLIENT_SECRET,
48
- });
49
+ 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=).
50
+
51
+ ### 🚀 Making Your First Request
49
52
 
50
- const nylas = Nylas.with(ACCESS_TOKEN);
53
+ Every resource (i.e., messages, events, contacts) is accessed via 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
+
55
+ ```typescript
56
+ import Nylas from "nylas";
57
+
58
+ const nylas = new Nylas({
59
+ apiKey: "NYLAS_API_KEY",
60
+ });
51
61
  ```
52
62
 
53
- Then, you can use Nylas to access information about a user's account:
54
- ```javascript
55
- nylas.threads.list({}).then(threads => {
56
- console.log(threads.length);
63
+ 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:
64
+ ```typescript
65
+ nylas.calendars.list({ identifier: "GRANT_ID" }).then(calendars => {
66
+ console.log(calendars);
57
67
  });
58
68
  ```
59
69
 
60
- For more information about how to use the Nylas Node SDK, [take a look at our quickstart guide](https://developer.nylas.com/docs/developer-tools/sdk/node-sdk/).
70
+ ## 📚 Documentation
71
+
72
+ 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.
61
73
 
62
74
  ## 💙 Contributing
63
75
 
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const node_fetch_1 = require("node-fetch");
4
+ const error_1 = require("./models/error");
5
+ const utils_1 = require("./utils");
6
+ const PACKAGE_JSON = require('package.json').default;
7
+ const SDK_VERSION = PACKAGE_JSON.version;
8
+ /**
9
+ * The API client for communicating with the Nylas API
10
+ * @ignore Not for public use
11
+ */
12
+ class APIClient {
13
+ constructor({ apiKey, apiUri, timeout }) {
14
+ this.apiKey = apiKey;
15
+ this.serverUrl = apiUri;
16
+ this.timeout = timeout * 1000; // fetch timeout uses milliseconds
17
+ }
18
+ setRequestUrl({ overrides, path, queryParams, }) {
19
+ const url = new URL(`${overrides?.apiUri || this.serverUrl}${path}`);
20
+ return this.setQueryStrings(url, queryParams);
21
+ }
22
+ setQueryStrings(url, queryParams) {
23
+ if (queryParams) {
24
+ const snakeCaseParams = (0, utils_1.objKeysToSnakeCase)(queryParams, ['metadataPair']);
25
+ for (const [key, value] of Object.entries(snakeCaseParams)) {
26
+ if (key == 'metadataPair') {
27
+ // The API understands a metadata_pair filter in the form of:
28
+ // <key>:<value>
29
+ const metadataPair = [];
30
+ for (const item in value) {
31
+ metadataPair.push(`${item}:${value[item]}`);
32
+ }
33
+ url.searchParams.set('metadata_pair', metadataPair.join(','));
34
+ }
35
+ else {
36
+ url.searchParams.set(key, value);
37
+ }
38
+ }
39
+ }
40
+ return url;
41
+ }
42
+ setRequestHeaders({ headers, overrides, }) {
43
+ return {
44
+ Accept: 'application/json',
45
+ 'User-Agent': `Nylas Node SDK v${SDK_VERSION}`,
46
+ Authorization: `Bearer ${overrides?.apiKey || this.apiKey}`,
47
+ ...headers,
48
+ };
49
+ }
50
+ requestOptions(optionParams) {
51
+ const requestOptions = {};
52
+ requestOptions.url = this.setRequestUrl(optionParams);
53
+ requestOptions.headers = this.setRequestHeaders(optionParams);
54
+ requestOptions.method = optionParams.method;
55
+ if (optionParams.body) {
56
+ requestOptions.body = JSON.stringify((0, utils_1.objKeysToSnakeCase)(optionParams.body));
57
+ requestOptions.headers['Content-Type'] = 'application/json';
58
+ }
59
+ return requestOptions;
60
+ }
61
+ newRequest(options) {
62
+ const newOptions = this.requestOptions(options);
63
+ return new node_fetch_1.Request(newOptions.url, {
64
+ method: newOptions.method,
65
+ headers: newOptions.headers,
66
+ body: newOptions.body,
67
+ });
68
+ }
69
+ async requestWithResponse(response) {
70
+ const text = await response.text();
71
+ try {
72
+ const responseJSON = JSON.parse(text);
73
+ return (0, utils_1.objKeysToCamelCase)(responseJSON);
74
+ }
75
+ catch (e) {
76
+ throw new Error(`Could not parse response from the server: ${text}`);
77
+ }
78
+ }
79
+ async request(options) {
80
+ const req = this.newRequest(options);
81
+ const controller = new AbortController();
82
+ const timeout = setTimeout(() => {
83
+ controller.abort();
84
+ throw new error_1.NylasSdkTimeoutError(req.url, this.timeout);
85
+ }, this.timeout);
86
+ const response = await (0, node_fetch_1.default)(req, { signal: controller.signal });
87
+ clearTimeout(timeout);
88
+ if (typeof response === 'undefined') {
89
+ throw new Error('Failed to fetch response');
90
+ }
91
+ // handle error response
92
+ if (response.status > 299) {
93
+ const authErrorResponse = options.path.includes('connect/token') ||
94
+ options.path.includes('connect/revoke');
95
+ const text = await response.text();
96
+ let error;
97
+ try {
98
+ const parsedError = JSON.parse(text);
99
+ const camelCaseError = (0, utils_1.objKeysToCamelCase)(parsedError);
100
+ if (authErrorResponse) {
101
+ error = new error_1.NylasOAuthError(camelCaseError, response.status);
102
+ }
103
+ else {
104
+ error = new error_1.NylasApiError(camelCaseError, response.status);
105
+ }
106
+ }
107
+ catch (e) {
108
+ throw new Error(`Received an error but could not parse response from the server: ${text}`);
109
+ }
110
+ throw error;
111
+ }
112
+ return this.requestWithResponse(response);
113
+ }
114
+ }
115
+ 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,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WebhookTriggers = void 0;
4
+ var WebhookTriggers;
5
+ (function (WebhookTriggers) {
6
+ WebhookTriggers["CalendarCreated"] = "calendar.created";
7
+ WebhookTriggers["CalendarUpdated"] = "calendar.updated";
8
+ WebhookTriggers["CalendarDeleted"] = "calendar.deleted";
9
+ WebhookTriggers["EventCreated"] = "event.created";
10
+ WebhookTriggers["EventUpdated"] = "event.updated";
11
+ WebhookTriggers["EventDeleted"] = "event.deleted";
12
+ WebhookTriggers["GrantCreated"] = "grant.created";
13
+ WebhookTriggers["GrantUpdated"] = "grant.updated";
14
+ WebhookTriggers["GrantDeleted"] = "grant.deleted";
15
+ WebhookTriggers["GrantExpired"] = "grant.expired";
16
+ WebhookTriggers["MessageSendSuccess"] = "message.send_success";
17
+ WebhookTriggers["MessageSendFailed"] = "message.send_failed";
18
+ })(WebhookTriggers = exports.WebhookTriggers || (exports.WebhookTriggers = {}));
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const apiClient_1 = require("./apiClient");
4
+ const config_1 = require("./config");
5
+ const calendars_1 = require("./resources/calendars");
6
+ const events_1 = require("./resources/events");
7
+ const auth_1 = require("./resources/auth");
8
+ const webhooks_1 = require("./resources/webhooks");
9
+ const applications_1 = require("./resources/applications");
10
+ /**
11
+ * The entry point to the Node SDK
12
+ *
13
+ * A Nylas instance holds a configured http client pointing to a base URL and is intended to be reused and shared
14
+ * across threads and time.
15
+ */
16
+ class Nylas {
17
+ /**
18
+ * @param config Configuration options for the Nylas SDK
19
+ */
20
+ constructor(config) {
21
+ this.apiClient = new apiClient_1.default({
22
+ apiKey: config.apiKey,
23
+ apiUri: config.apiUri || config_1.DEFAULT_SERVER_URL,
24
+ timeout: config.timeout || 30,
25
+ });
26
+ this.applications = new applications_1.Applications(this.apiClient);
27
+ this.auth = new auth_1.Auth(this.apiClient);
28
+ this.calendars = new calendars_1.Calendars(this.apiClient);
29
+ this.events = new events_1.Events(this.apiClient);
30
+ this.webhooks = new webhooks_1.Webhooks(this.apiClient);
31
+ return this;
32
+ }
33
+ }
34
+ 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_1 = require("./resource");
5
+ const redirectUris_1 = require("./redirectUris");
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_1.Resource {
12
+ /**
13
+ * @param apiClient client The configured Nylas API client
14
+ */
15
+ constructor(apiClient) {
16
+ super(apiClient);
17
+ this.redirectUris = new redirectUris_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,153 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Auth = void 0;
4
+ const uuid_1 = require("uuid");
5
+ const sha256_1 = require("sha256");
6
+ const resource_1 = require("./resource");
7
+ const grants_1 = require("./grants");
8
+ /**
9
+ * A collection of authentication related API endpoints
10
+ *
11
+ * These endpoints allow for various functionality related to authentication.
12
+ * Also contains the Grants API and collection of provider API endpoints.
13
+ */
14
+ class Auth extends resource_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_1.Grants(apiClient);
22
+ }
23
+ /**
24
+ * Build the URL for authenticating users to your application with OAuth 2.0
25
+ * @param config The configuration for building the URL
26
+ * @return The URL for hosted authentication
27
+ */
28
+ urlForOAuth2(config) {
29
+ return this.urlAuthBuilder(config).toString();
30
+ }
31
+ /**
32
+ * Exchange an authorization code for an access token
33
+ * @param request The request parameters for the code exchange
34
+ * @return Information about the Nylas application
35
+ */
36
+ exchangeCodeForToken(request) {
37
+ const body = {
38
+ ...request,
39
+ grantType: 'authorization_code',
40
+ };
41
+ if (request.codeVerifier) {
42
+ body.codeVerifier = request.codeVerifier;
43
+ }
44
+ return this.apiClient.request({
45
+ method: 'POST',
46
+ path: `/v3/connect/token`,
47
+ body,
48
+ });
49
+ }
50
+ /**
51
+ * Refresh an access token
52
+ * @param request The refresh token request
53
+ * @return The response containing the new access token
54
+ */
55
+ refreshAccessToken(request) {
56
+ return this.apiClient.request({
57
+ method: 'POST',
58
+ path: `/v3/connect/token`,
59
+ body: {
60
+ ...request,
61
+ grantType: 'refresh_token',
62
+ },
63
+ });
64
+ }
65
+ /**
66
+ * Build the URL for authenticating users to your application with OAuth 2.0 and PKCE
67
+ * IMPORTANT: YOU WILL NEED TO STORE THE 'secret' returned to use it inside the CodeExchange flow
68
+ * @param config The configuration for building the URL
69
+ * @return The URL for hosted authentication
70
+ */
71
+ urlForOAuth2PKCE(config) {
72
+ const url = this.urlAuthBuilder(config);
73
+ // Add code challenge to URL generation
74
+ url.searchParams.set('code_challenge_method', 's256');
75
+ const secret = (0, uuid_1.v4)();
76
+ const secretHash = this.hashPKCESecret(secret);
77
+ url.searchParams.set('code_challenge', secret);
78
+ // Return the url with secret & hashed secret
79
+ return { secret, secretHash, url: url.toString() };
80
+ }
81
+ /**
82
+ * Build the URL for admin consent authentication for Microsoft
83
+ * @param config The configuration for building the URL
84
+ * @return The URL for admin consent authentication
85
+ */
86
+ urlForAdminConsent(config) {
87
+ const configWithProvider = { ...config, provider: 'microsoft' };
88
+ const url = this.urlAuthBuilder(configWithProvider);
89
+ url.searchParams.set('response_type', 'adminconsent');
90
+ url.searchParams.set('credential_id', config.credentialId);
91
+ return url.toString();
92
+ }
93
+ /**
94
+ * Revoke a token (and the grant attached to the token)
95
+ * @param token The token to revoke
96
+ * @return True if the token was revoked successfully
97
+ */
98
+ async revoke(token) {
99
+ await this.apiClient.request({
100
+ method: 'POST',
101
+ path: `/v3/connect/revoke`,
102
+ queryParams: {
103
+ token,
104
+ },
105
+ });
106
+ return true;
107
+ }
108
+ /**
109
+ * Detect provider from email address
110
+ * @param params The parameters to include in the request
111
+ * @return The detected provider, if found
112
+ */
113
+ async detectProvider(params) {
114
+ return this.apiClient.request({
115
+ method: 'POST',
116
+ path: `/v3/grants/providers/detect`,
117
+ queryParams: params,
118
+ });
119
+ }
120
+ urlAuthBuilder(config) {
121
+ const url = new URL(`${this.apiClient.serverUrl}/v3/connect/auth`);
122
+ url.searchParams.set('client_id', config.clientId);
123
+ url.searchParams.set('redirect_uri', config.redirectUri);
124
+ url.searchParams.set('access_type', config.accessType ? config.accessType : 'online');
125
+ url.searchParams.set('response_type', 'code');
126
+ if (config.provider) {
127
+ url.searchParams.set('provider', config.provider);
128
+ }
129
+ if (config.loginHint) {
130
+ url.searchParams.set('login_hint', config.loginHint);
131
+ if (config.includeGrantScopes) {
132
+ url.searchParams.set('include_grant_scopes', config.includeGrantScopes.toString());
133
+ }
134
+ }
135
+ if (config.scope) {
136
+ url.searchParams.set('scope', config.scope.join(' '));
137
+ }
138
+ if (config.prompt) {
139
+ url.searchParams.set('prompt', config.prompt);
140
+ }
141
+ if (config.metadata) {
142
+ url.searchParams.set('metadata', config.metadata);
143
+ }
144
+ if (config.state) {
145
+ url.searchParams.set('state', config.state);
146
+ }
147
+ return url;
148
+ }
149
+ hashPKCESecret(secret) {
150
+ return Buffer.from((0, sha256_1.default)(secret)).toString('base64');
151
+ }
152
+ }
153
+ exports.Auth = Auth;
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Calendars = void 0;
4
+ const resource_1 = require("./resource");
5
+ /**
6
+ * Nylas Calendar API
7
+ *
8
+ * The Nylas calendar API allows you to create new calendars or manage existing ones.
9
+ * A calendar can be accessed by one, or several people, and can contain events.
10
+ */
11
+ class Calendars extends resource_1.Resource {
12
+ /**
13
+ * Return all Calendars
14
+ * @return A list of calendars
15
+ */
16
+ list({ identifier, queryParams, overrides, }) {
17
+ return super._list({
18
+ queryParams,
19
+ overrides,
20
+ path: `/v3/grants/${identifier}/calendars`,
21
+ });
22
+ }
23
+ /**
24
+ * Return a Calendar
25
+ * @return The calendar
26
+ */
27
+ find({ identifier, calendarId, overrides, }) {
28
+ return super._find({
29
+ path: `/v3/grants/${identifier}/calendars/${calendarId}`,
30
+ overrides,
31
+ });
32
+ }
33
+ /**
34
+ * Create a Calendar
35
+ * @return The created calendar
36
+ */
37
+ create({ identifier, requestBody, overrides, }) {
38
+ return super._create({
39
+ path: `/v3/grants/${identifier}/calendars`,
40
+ requestBody,
41
+ overrides,
42
+ });
43
+ }
44
+ /**
45
+ * Update a Calendar
46
+ * @return The updated Calendar
47
+ */
48
+ update({ calendarId, identifier, requestBody, overrides, }) {
49
+ return super._update({
50
+ path: `/v3/grants/${identifier}/calendars/${calendarId}`,
51
+ requestBody,
52
+ overrides,
53
+ });
54
+ }
55
+ /**
56
+ * Delete a Calendar
57
+ * @return The deleted Calendar
58
+ */
59
+ destroy({ identifier, calendarId, overrides, }) {
60
+ return super._destroy({
61
+ path: `/v3/grants/${identifier}/calendars/${calendarId}`,
62
+ overrides,
63
+ });
64
+ }
65
+ /**
66
+ * Get Availability for a given account / accounts
67
+ * @return The availability response
68
+ */
69
+ getAvailability({ requestBody, overrides, }) {
70
+ return this.apiClient.request({
71
+ method: 'POST',
72
+ path: `/v3/calendars/availability`,
73
+ body: requestBody,
74
+ overrides,
75
+ });
76
+ }
77
+ }
78
+ exports.Calendars = Calendars;