nylas 7.0.0-beta.0 → 7.0.0-beta.2

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 (204) hide show
  1. package/README.md +27 -19
  2. package/lib/cjs/apiClient.js +114 -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/package.json +3 -0
  17. package/lib/cjs/resources/applications.js +30 -0
  18. package/lib/cjs/resources/auth.js +153 -0
  19. package/lib/cjs/resources/calendars.js +78 -0
  20. package/lib/cjs/resources/events.js +69 -0
  21. package/lib/cjs/resources/grants.js +65 -0
  22. package/lib/cjs/resources/redirectUris.js +64 -0
  23. package/lib/cjs/resources/resource.js +111 -0
  24. package/lib/cjs/resources/webhooks.js +98 -0
  25. package/lib/cjs/utils.js +58 -0
  26. package/lib/cjs/version.js +5 -0
  27. package/lib/esm/apiClient.js +111 -0
  28. package/lib/esm/config.js +29 -0
  29. package/lib/esm/models/applicationDetails.js +1 -0
  30. package/lib/esm/models/auth.js +1 -0
  31. package/lib/esm/models/availability.js +8 -0
  32. package/lib/esm/models/calendars.js +1 -0
  33. package/lib/esm/models/error.js +45 -0
  34. package/lib/esm/models/events.js +1 -0
  35. package/lib/esm/models/grants.js +1 -0
  36. package/lib/esm/models/listQueryParams.js +1 -0
  37. package/lib/esm/models/redirectUri.js +1 -0
  38. package/lib/esm/models/response.js +1 -0
  39. package/lib/esm/models/webhooks.js +15 -0
  40. package/lib/esm/nylas.js +31 -0
  41. package/lib/esm/package.json +3 -0
  42. package/lib/esm/resources/applications.js +26 -0
  43. package/lib/esm/resources/auth.js +149 -0
  44. package/lib/esm/resources/calendars.js +74 -0
  45. package/lib/esm/resources/events.js +65 -0
  46. package/lib/esm/resources/grants.js +61 -0
  47. package/lib/esm/resources/redirectUris.js +60 -0
  48. package/lib/esm/resources/resource.js +107 -0
  49. package/lib/esm/resources/webhooks.js +94 -0
  50. package/lib/esm/utils.js +53 -0
  51. package/lib/esm/version.js +2 -0
  52. package/lib/types/apiClient.d.ts +65 -0
  53. package/lib/types/config.d.ts +50 -0
  54. package/lib/types/models/applicationDetails.d.ts +93 -0
  55. package/lib/types/models/auth.d.ts +196 -0
  56. package/lib/types/models/availability.d.ts +159 -0
  57. package/lib/types/models/calendars.d.ts +121 -0
  58. package/lib/types/models/error.d.ts +104 -0
  59. package/lib/types/models/events.d.ts +494 -0
  60. package/lib/types/models/grants.d.ts +134 -0
  61. package/lib/types/models/listQueryParams.d.ts +4 -0
  62. package/lib/types/models/redirectUri.d.ts +71 -0
  63. package/lib/types/models/response.d.ts +40 -0
  64. package/lib/types/models/webhooks.d.ts +45 -0
  65. package/lib/types/nylas.d.ts +44 -0
  66. package/lib/types/resources/applications.d.ts +26 -0
  67. package/lib/types/resources/auth.d.ts +66 -0
  68. package/lib/types/resources/calendars.d.ts +97 -0
  69. package/lib/types/resources/events.d.ts +87 -0
  70. package/lib/types/resources/grants.d.ts +63 -0
  71. package/lib/types/resources/redirectUris.d.ts +63 -0
  72. package/lib/types/resources/resource.d.ts +55 -0
  73. package/lib/types/resources/webhooks.d.ts +79 -0
  74. package/lib/types/utils.d.ts +22 -0
  75. package/lib/types/version.d.ts +1 -0
  76. package/package.json +33 -42
  77. package/lib/config.d.ts +0 -70
  78. package/lib/config.js +0 -68
  79. package/lib/models/access-token.d.ts +0 -18
  80. package/lib/models/access-token.js +0 -56
  81. package/lib/models/account.d.ts +0 -27
  82. package/lib/models/account.js +0 -73
  83. package/lib/models/application-details.d.ts +0 -14
  84. package/lib/models/application-details.js +0 -47
  85. package/lib/models/attributes.d.ts +0 -151
  86. package/lib/models/attributes.js +0 -382
  87. package/lib/models/calendar-availability.d.ts +0 -76
  88. package/lib/models/calendar-availability.js +0 -121
  89. package/lib/models/calendar-restful-model-collection.d.ts +0 -17
  90. package/lib/models/calendar-restful-model-collection.js +0 -181
  91. package/lib/models/calendar.d.ts +0 -31
  92. package/lib/models/calendar.js +0 -93
  93. package/lib/models/component-restful-model-collection.d.ts +0 -9
  94. package/lib/models/component-restful-model-collection.js +0 -34
  95. package/lib/models/component.d.ts +0 -37
  96. package/lib/models/component.js +0 -91
  97. package/lib/models/connect.d.ts +0 -73
  98. package/lib/models/connect.js +0 -193
  99. package/lib/models/contact-restful-model-collection.d.ts +0 -9
  100. package/lib/models/contact-restful-model-collection.js +0 -60
  101. package/lib/models/contact.d.ts +0 -129
  102. package/lib/models/contact.js +0 -289
  103. package/lib/models/delta-collection.d.ts +0 -17
  104. package/lib/models/delta-collection.js +0 -139
  105. package/lib/models/delta-stream.d.ts +0 -32
  106. package/lib/models/delta-stream.js +0 -250
  107. package/lib/models/delta.d.ts +0 -28
  108. package/lib/models/delta.js +0 -88
  109. package/lib/models/deltas.d.ts +0 -17
  110. package/lib/models/deltas.js +0 -49
  111. package/lib/models/draft.d.ts +0 -27
  112. package/lib/models/draft.js +0 -156
  113. package/lib/models/email-participant.d.ts +0 -13
  114. package/lib/models/email-participant.js +0 -46
  115. package/lib/models/event-conferencing.d.ts +0 -34
  116. package/lib/models/event-conferencing.js +0 -71
  117. package/lib/models/event-notification.d.ts +0 -27
  118. package/lib/models/event-notification.js +0 -62
  119. package/lib/models/event-participant.d.ts +0 -19
  120. package/lib/models/event-participant.js +0 -56
  121. package/lib/models/event.d.ts +0 -96
  122. package/lib/models/event.js +0 -297
  123. package/lib/models/file.d.ts +0 -29
  124. package/lib/models/file.js +0 -136
  125. package/lib/models/folder.d.ts +0 -21
  126. package/lib/models/folder.js +0 -69
  127. package/lib/models/free-busy.d.ts +0 -58
  128. package/lib/models/free-busy.js +0 -132
  129. package/lib/models/job-status-restful-model-collection.d.ts +0 -9
  130. package/lib/models/job-status-restful-model-collection.js +0 -38
  131. package/lib/models/job-status.d.ts +0 -24
  132. package/lib/models/job-status.js +0 -68
  133. package/lib/models/management-account.d.ts +0 -63
  134. package/lib/models/management-account.js +0 -187
  135. package/lib/models/management-model-collection.d.ts +0 -10
  136. package/lib/models/management-model-collection.js +0 -39
  137. package/lib/models/management-model.d.ts +0 -6
  138. package/lib/models/management-model.js +0 -29
  139. package/lib/models/message-restful-model-collection.d.ts +0 -26
  140. package/lib/models/message-restful-model-collection.js +0 -80
  141. package/lib/models/message.d.ts +0 -57
  142. package/lib/models/message.js +0 -173
  143. package/lib/models/model-collection.d.ts +0 -25
  144. package/lib/models/model-collection.js +0 -201
  145. package/lib/models/model.d.ts +0 -12
  146. package/lib/models/model.js +0 -64
  147. package/lib/models/neural-categorizer.d.ts +0 -28
  148. package/lib/models/neural-categorizer.js +0 -139
  149. package/lib/models/neural-clean-conversation.d.ts +0 -16
  150. package/lib/models/neural-clean-conversation.js +0 -114
  151. package/lib/models/neural-ocr.d.ts +0 -14
  152. package/lib/models/neural-ocr.js +0 -50
  153. package/lib/models/neural-sentiment-analysis.d.ts +0 -20
  154. package/lib/models/neural-sentiment-analysis.js +0 -56
  155. package/lib/models/neural-signature-contact.d.ts +0 -43
  156. package/lib/models/neural-signature-contact.js +0 -142
  157. package/lib/models/neural-signature-extraction.d.ts +0 -17
  158. package/lib/models/neural-signature-extraction.js +0 -54
  159. package/lib/models/neural.d.ts +0 -36
  160. package/lib/models/neural.js +0 -163
  161. package/lib/models/nylas-api-error.d.ts +0 -26
  162. package/lib/models/nylas-api-error.js +0 -61
  163. package/lib/models/outbox-job-status.d.ts +0 -20
  164. package/lib/models/outbox-job-status.js +0 -64
  165. package/lib/models/outbox-message.d.ts +0 -16
  166. package/lib/models/outbox-message.js +0 -54
  167. package/lib/models/outbox.d.ts +0 -35
  168. package/lib/models/outbox.js +0 -158
  169. package/lib/models/resource.d.ts +0 -22
  170. package/lib/models/resource.js +0 -66
  171. package/lib/models/restful-model-collection.d.ts +0 -15
  172. package/lib/models/restful-model-collection.js +0 -169
  173. package/lib/models/restful-model-instance.d.ts +0 -9
  174. package/lib/models/restful-model-instance.js +0 -37
  175. package/lib/models/restful-model.d.ts +0 -36
  176. package/lib/models/restful-model.js +0 -146
  177. package/lib/models/scheduler-booking-request.d.ts +0 -64
  178. package/lib/models/scheduler-booking-request.js +0 -148
  179. package/lib/models/scheduler-restful-model-collection.d.ts +0 -26
  180. package/lib/models/scheduler-restful-model-collection.js +0 -133
  181. package/lib/models/scheduler-time-slot.d.ts +0 -20
  182. package/lib/models/scheduler-time-slot.js +0 -53
  183. package/lib/models/scheduler.d.ts +0 -226
  184. package/lib/models/scheduler.js +0 -446
  185. package/lib/models/thread.d.ts +0 -49
  186. package/lib/models/thread.js +0 -127
  187. package/lib/models/webhook-notification.d.ts +0 -108
  188. package/lib/models/webhook-notification.js +0 -239
  189. package/lib/models/webhook.d.ts +0 -50
  190. package/lib/models/webhook.js +0 -101
  191. package/lib/models/when.d.ts +0 -23
  192. package/lib/models/when.js +0 -65
  193. package/lib/nylas-connection.d.ts +0 -71
  194. package/lib/nylas-connection.js +0 -258
  195. package/lib/nylas.d.ts +0 -57
  196. package/lib/nylas.js +0 -210
  197. package/lib/server-bindings/express-binding.d.ts +0 -18
  198. package/lib/server-bindings/express-binding.js +0 -163
  199. package/lib/server-bindings/server-binding.d.ts +0 -65
  200. package/lib/server-bindings/server-binding.js +0 -87
  201. package/lib/services/routes.d.ts +0 -26
  202. package/lib/services/routes.js +0 -95
  203. package/lib/services/tunnel.d.ts +0 -29
  204. package/lib/services/tunnel.js +0 -112
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,13 +19,19 @@ Here are some resources to help you get started:
20
19
 
21
20
  ## ⚙️ Install
22
21
 
23
- To install 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.
22
+ **Note:** The Nylas Node SDK requires Node.js v16 or later.
23
+
24
+ ### Set up using npm
25
+
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:
26
- `npm install nylas`
29
+ `npm install nylas@beta`
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,31 +42,34 @@ npm install
37
42
 
38
43
  ## ⚡️ Usage
39
44
 
40
- The SDK entrypoint and application resources (i.e., application accounts, authentication, webhooks) is accessed via an instance of `Nylas`. You can initialize a `Nylas` instance with your `clientId` and `clientSecret`.
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
- const nylasClient = new Nylas({
46
- clientId: CLIENT_ID,
47
- clientSecret: CLIENT_SECRET,
48
- });
49
- ```
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
50
 
51
- Every account resource (i.e., messages, events, contacts) is accessed via an instance of `NylasConnection`. To initialize an instance of `NylasConnection`, call `with` on your `Nylas` instance and pass it your `accessToken`.
51
+ ### 🚀 Making Your First Request
52
52
 
53
- ```javascript
54
- const nylasConnection = nylasClient.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
+ });
55
61
  ```
56
62
 
57
- Then, you can use Nylas to access information about a user's account:
58
- ```javascript
59
- nylasConnection.threads.list().then(threads => {
60
- 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);
61
67
  });
62
68
  ```
63
69
 
64
- 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.
65
73
 
66
74
  ## 💙 Contributing
67
75
 
@@ -0,0 +1,114 @@
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
+ requestOptions(optionParams) {
50
+ const requestOptions = {};
51
+ requestOptions.url = this.setRequestUrl(optionParams);
52
+ requestOptions.headers = this.setRequestHeaders(optionParams);
53
+ requestOptions.method = optionParams.method;
54
+ if (optionParams.body) {
55
+ requestOptions.body = JSON.stringify((0, utils_js_1.objKeysToSnakeCase)(optionParams.body));
56
+ requestOptions.headers['Content-Type'] = 'application/json';
57
+ }
58
+ return requestOptions;
59
+ }
60
+ newRequest(options) {
61
+ const newOptions = this.requestOptions(options);
62
+ return new node_fetch_1.Request(newOptions.url, {
63
+ method: newOptions.method,
64
+ headers: newOptions.headers,
65
+ body: newOptions.body,
66
+ });
67
+ }
68
+ async requestWithResponse(response) {
69
+ const text = await response.text();
70
+ try {
71
+ const responseJSON = JSON.parse(text);
72
+ return (0, utils_js_1.objKeysToCamelCase)(responseJSON);
73
+ }
74
+ catch (e) {
75
+ throw new Error(`Could not parse response from the server: ${text}`);
76
+ }
77
+ }
78
+ async request(options) {
79
+ const req = this.newRequest(options);
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
+ }
111
+ return this.requestWithResponse(response);
112
+ }
113
+ }
114
+ 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_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
+ /**
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_js_1.default({
22
+ apiKey: config.apiKey,
23
+ apiUri: config.apiUri || config_js_1.DEFAULT_SERVER_URL,
24
+ timeout: config.timeout || 30,
25
+ });
26
+ this.applications = new applications_js_1.Applications(this.apiClient);
27
+ this.auth = new auth_js_1.Auth(this.apiClient);
28
+ this.calendars = new calendars_js_1.Calendars(this.apiClient);
29
+ this.events = new events_js_1.Events(this.apiClient);
30
+ this.webhooks = new webhooks_js_1.Webhooks(this.apiClient);
31
+ return this;
32
+ }
33
+ }
34
+ exports.default = Nylas;
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -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,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_js_1 = require("./resource.js");
7
+ const grants_js_1 = require("./grants.js");
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_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
+ /**
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_js_1 = require("./resource.js");
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_js_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;