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
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Events = void 0;
4
+ const resource_1 = require("./resource");
5
+ /**
6
+ * Nylas Events API
7
+ *
8
+ * The Nylas Events API allows you to create, update, and delete events on user calendars.
9
+ */
10
+ class Events extends resource_1.Resource {
11
+ /**
12
+ * Return all Events
13
+ * @return The list of Events
14
+ */
15
+ list({ identifier, queryParams, overrides, }) {
16
+ return super._list({
17
+ queryParams,
18
+ path: `/v3/grants/${identifier}/events`,
19
+ overrides,
20
+ });
21
+ }
22
+ /**
23
+ * Return an Event
24
+ * @return The Event
25
+ */
26
+ find({ identifier, eventId, queryParams, overrides, }) {
27
+ return super._find({
28
+ path: `/v3/grants/${identifier}/events/${eventId}`,
29
+ queryParams,
30
+ overrides,
31
+ });
32
+ }
33
+ /**
34
+ * Create an Event
35
+ * @return The created Event
36
+ */
37
+ create({ identifier, requestBody, queryParams, overrides, }) {
38
+ return super._create({
39
+ path: `/v3/grants/${identifier}/events`,
40
+ queryParams,
41
+ requestBody,
42
+ overrides,
43
+ });
44
+ }
45
+ /**
46
+ * Update an Event
47
+ * @return The updated Event
48
+ */
49
+ update({ identifier, eventId, requestBody, queryParams, overrides, }) {
50
+ return super._update({
51
+ path: `/v3/grants/${identifier}/events/${eventId}`,
52
+ queryParams,
53
+ requestBody,
54
+ overrides,
55
+ });
56
+ }
57
+ /**
58
+ * Delete an Event
59
+ * @return The deletion response
60
+ */
61
+ destroy({ identifier, eventId, queryParams, overrides, }) {
62
+ return super._destroy({
63
+ path: `/v3/grants/${identifier}/events/${eventId}`,
64
+ queryParams,
65
+ overrides,
66
+ });
67
+ }
68
+ }
69
+ exports.Events = Events;
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Grants = void 0;
4
+ const resource_1 = require("./resource");
5
+ /**
6
+ * Nylas Grants API
7
+ *
8
+ * The Nylas Grants API allows for the management of grants.
9
+ */
10
+ class Grants extends resource_1.Resource {
11
+ /**
12
+ * Return all Grants
13
+ * @return The list of Grants
14
+ */
15
+ async list({ overrides } = {}, queryParams) {
16
+ return super._list({
17
+ queryParams,
18
+ path: `/v3/grants`,
19
+ overrides,
20
+ });
21
+ }
22
+ /**
23
+ * Return a Grant
24
+ * @return The Grant
25
+ */
26
+ find({ grantId, overrides, }) {
27
+ return super._find({
28
+ path: `/v3/grants/${grantId}`,
29
+ overrides,
30
+ });
31
+ }
32
+ /**
33
+ * Create a Grant
34
+ * @return The created Grant
35
+ */
36
+ create({ requestBody, overrides, }) {
37
+ return super._create({
38
+ path: `/v3/grants`,
39
+ requestBody,
40
+ overrides,
41
+ });
42
+ }
43
+ /**
44
+ * Update a Grant
45
+ * @return The updated Grant
46
+ */
47
+ update({ grantId, requestBody, overrides, }) {
48
+ return super._updatePatch({
49
+ path: `/v3/grants/${grantId}`,
50
+ requestBody,
51
+ overrides,
52
+ });
53
+ }
54
+ /**
55
+ * Delete a Grant
56
+ * @return The deletion response
57
+ */
58
+ destroy({ grantId, overrides, }) {
59
+ return super._destroy({
60
+ path: `/v3/grants/${grantId}`,
61
+ overrides,
62
+ });
63
+ }
64
+ }
65
+ exports.Grants = Grants;
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RedirectUris = void 0;
4
+ const resource_1 = require("./resource");
5
+ /**
6
+ * A collection of redirect URI related API endpoints.
7
+ *
8
+ * These endpoints allows for the management of redirect URIs.
9
+ */
10
+ class RedirectUris extends resource_1.Resource {
11
+ /**
12
+ * Return all Redirect URIs
13
+ * @return The list of Redirect URIs
14
+ */
15
+ list({ overrides } = {}) {
16
+ return super._list({
17
+ overrides,
18
+ path: '/v3/applications/redirect-uris',
19
+ });
20
+ }
21
+ /**
22
+ * Return a Redirect URI
23
+ * @return The Redirect URI
24
+ */
25
+ find({ redirectUriId, overrides, }) {
26
+ return super._find({
27
+ overrides,
28
+ path: `/v3/applications/redirect-uris/${redirectUriId}`,
29
+ });
30
+ }
31
+ /**
32
+ * Create a Redirect URI
33
+ * @return The created Redirect URI
34
+ */
35
+ create({ requestBody, overrides, }) {
36
+ return super._create({
37
+ overrides,
38
+ path: '/v3/applications/redirect-uris',
39
+ requestBody,
40
+ });
41
+ }
42
+ /**
43
+ * Update a Redirect URI
44
+ * @return The updated Redirect URI
45
+ */
46
+ update({ redirectUriId, requestBody, overrides, }) {
47
+ return super._update({
48
+ overrides,
49
+ path: `/v3/applications/redirect-uris/${redirectUriId}`,
50
+ requestBody,
51
+ });
52
+ }
53
+ /**
54
+ * Delete a Redirect URI
55
+ * @return The deleted Redirect URI
56
+ */
57
+ destroy({ redirectUriId, overrides, }) {
58
+ return super._destroy({
59
+ overrides,
60
+ path: `/v1/redirect_uris/${redirectUriId}`,
61
+ });
62
+ }
63
+ }
64
+ exports.RedirectUris = RedirectUris;
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Resource = void 0;
4
+ /**
5
+ * Base class for Nylas API resources
6
+ *
7
+ * @ignore No public constructor or functions
8
+ */
9
+ class Resource {
10
+ /**
11
+ * @param apiClient client The configured Nylas API client
12
+ */
13
+ constructor(apiClient) {
14
+ this.apiClient = apiClient;
15
+ }
16
+ async fetchList({ queryParams, path, overrides, }) {
17
+ const res = await this.apiClient.request({
18
+ method: 'GET',
19
+ path,
20
+ queryParams,
21
+ overrides,
22
+ });
23
+ if (queryParams?.limit) {
24
+ let entriesRemaining = queryParams.limit;
25
+ while (res.data.length != queryParams.limit) {
26
+ entriesRemaining = queryParams.limit - res.data.length;
27
+ if (!res.nextCursor) {
28
+ break;
29
+ }
30
+ const nextRes = await this.apiClient.request({
31
+ method: 'GET',
32
+ path,
33
+ queryParams: {
34
+ ...queryParams,
35
+ limit: entriesRemaining,
36
+ pageToken: res.nextCursor,
37
+ },
38
+ overrides,
39
+ });
40
+ res.data = res.data.concat(nextRes.data);
41
+ res.requestId = nextRes.requestId;
42
+ res.nextCursor = nextRes.nextCursor;
43
+ }
44
+ }
45
+ return res;
46
+ }
47
+ async *listIterator(listParams) {
48
+ const first = await this.fetchList(listParams);
49
+ yield first;
50
+ let pageToken = first.nextCursor;
51
+ while (pageToken) {
52
+ const res = await this.fetchList({
53
+ ...listParams,
54
+ queryParams: pageToken
55
+ ? {
56
+ ...listParams.queryParams,
57
+ pageToken,
58
+ }
59
+ : listParams.queryParams,
60
+ });
61
+ yield res;
62
+ pageToken = res.nextCursor;
63
+ }
64
+ return undefined;
65
+ }
66
+ _list(listParams) {
67
+ const iterator = this.listIterator(listParams);
68
+ const first = iterator.next().then(res => ({
69
+ ...res.value,
70
+ next: iterator.next.bind(iterator),
71
+ }));
72
+ return Object.assign(first, {
73
+ [Symbol.asyncIterator]: this.listIterator.bind(this, listParams),
74
+ });
75
+ }
76
+ _find({ path, queryParams, overrides, }) {
77
+ return this.apiClient.request({
78
+ method: 'GET',
79
+ path,
80
+ queryParams,
81
+ overrides,
82
+ });
83
+ }
84
+ payloadRequest(method, { path, queryParams, requestBody, overrides }) {
85
+ return this.apiClient.request({
86
+ method,
87
+ path,
88
+ queryParams,
89
+ body: requestBody,
90
+ overrides,
91
+ });
92
+ }
93
+ _create(params) {
94
+ return this.payloadRequest('POST', params);
95
+ }
96
+ _update(params) {
97
+ return this.payloadRequest('PUT', params);
98
+ }
99
+ _updatePatch(params) {
100
+ return this.payloadRequest('PATCH', params);
101
+ }
102
+ _destroy({ path, queryParams, overrides, }) {
103
+ return this.apiClient.request({
104
+ method: 'DELETE',
105
+ path,
106
+ queryParams,
107
+ overrides,
108
+ });
109
+ }
110
+ }
111
+ exports.Resource = Resource;
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Webhooks = void 0;
4
+ const resource_1 = require("./resource");
5
+ /**
6
+ * Nylas Webhooks API
7
+ *
8
+ * The Nylas Webhooks API allows your application to receive notifications in real-time when certain events occur.
9
+ */
10
+ class Webhooks extends resource_1.Resource {
11
+ /**
12
+ * List all webhook destinations for the application
13
+ * @returns The list of webhook destinations
14
+ */
15
+ list({ overrides } = {}) {
16
+ return super._list({
17
+ overrides,
18
+ path: `/v3/webhooks`,
19
+ });
20
+ }
21
+ /**
22
+ * Return a webhook destination
23
+ * @return The webhook destination
24
+ */
25
+ find({ webhookId, overrides, }) {
26
+ return super._find({
27
+ path: `/v3/webhooks/${webhookId}`,
28
+ overrides,
29
+ });
30
+ }
31
+ /**
32
+ * Create a webhook destination
33
+ * @returns The created webhook destination
34
+ */
35
+ create({ requestBody, overrides, }) {
36
+ return super._create({
37
+ path: `/v3/webhooks`,
38
+ requestBody,
39
+ overrides,
40
+ });
41
+ }
42
+ /**
43
+ * Update a webhook destination
44
+ * @returns The updated webhook destination
45
+ */
46
+ update({ webhookId, requestBody, overrides, }) {
47
+ return super._update({
48
+ path: `/v3/webhooks/${webhookId}`,
49
+ requestBody,
50
+ overrides,
51
+ });
52
+ }
53
+ /**
54
+ * Delete a webhook destination
55
+ * @returns The deletion response
56
+ */
57
+ destroy({ webhookId, overrides, }) {
58
+ return super._destroy({
59
+ path: `/v3/webhooks/${webhookId}`,
60
+ overrides,
61
+ });
62
+ }
63
+ /**
64
+ * Update the webhook secret value for a destination
65
+ * @returns The updated webhook destination with the webhook secret
66
+ */
67
+ rotateSecret({ webhookId, overrides, }) {
68
+ return super._update({
69
+ path: `/v3/webhooks/${webhookId}/rotate-secret`,
70
+ requestBody: {},
71
+ overrides,
72
+ });
73
+ }
74
+ /**
75
+ * Get the current list of IP addresses that Nylas sends webhooks from
76
+ * @returns The list of IP addresses that Nylas sends webhooks from
77
+ */
78
+ ipAddresses({ overrides } = {}) {
79
+ return super._find({
80
+ path: `/v3/webhooks/ip-addresses`,
81
+ overrides,
82
+ });
83
+ }
84
+ /**
85
+ * Extract the challenge parameter from a URL
86
+ * @param url The URL sent by Nylas containing the challenge parameter
87
+ * @returns The challenge parameter
88
+ */
89
+ extractChallengeParameter(url) {
90
+ const urlObject = new URL(url);
91
+ const challengeParameter = urlObject.searchParams.get('challenge');
92
+ if (!challengeParameter) {
93
+ throw new Error('Invalid URL or no challenge parameter found.');
94
+ }
95
+ return challengeParameter;
96
+ }
97
+ }
98
+ exports.Webhooks = Webhooks;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.objKeysToSnakeCase = exports.objKeysToCamelCase = void 0;
4
+ const change_case_1 = require("change-case");
5
+ /**
6
+ * A utility function that recursively converts all keys in an object to a given case.
7
+ * @param obj The object to convert
8
+ * @param casingFunction The function to use to convert the keys
9
+ * @param excludeKeys An array of keys to exclude from conversion
10
+ * @returns The converted object
11
+ * @ignore Not for public use.
12
+ */
13
+ function convertCase(obj, casingFunction, excludeKeys) {
14
+ const newObj = {};
15
+ for (const key in obj) {
16
+ if (excludeKeys?.includes(key)) {
17
+ newObj[key] = obj[key];
18
+ }
19
+ else if (Array.isArray(obj[key])) {
20
+ newObj[casingFunction(key)] = obj[key].map(item => {
21
+ if (typeof item === 'object') {
22
+ return convertCase(item, casingFunction);
23
+ }
24
+ else {
25
+ return item;
26
+ }
27
+ });
28
+ }
29
+ else if (typeof obj[key] === 'object' && obj[key] !== null) {
30
+ newObj[casingFunction(key)] = convertCase(obj[key], casingFunction);
31
+ }
32
+ else {
33
+ newObj[casingFunction(key)] = obj[key];
34
+ }
35
+ }
36
+ return newObj;
37
+ }
38
+ /**
39
+ * A utility function that recursively converts all keys in an object to camelCase.
40
+ * @param obj The object to convert
41
+ * @param exclude An array of keys to exclude from conversion
42
+ * @returns The converted object
43
+ * @ignore Not for public use.
44
+ */
45
+ function objKeysToCamelCase(obj, exclude) {
46
+ return convertCase(obj, change_case_1.camelCase, exclude);
47
+ }
48
+ exports.objKeysToCamelCase = objKeysToCamelCase;
49
+ /**
50
+ * A utility function that recursively converts all keys in an object to snake_case.
51
+ * @param obj The object to convert
52
+ * @param exclude An array of keys to exclude from conversion
53
+ * @returns The converted object
54
+ */
55
+ function objKeysToSnakeCase(obj, exclude) {
56
+ return convertCase(obj, change_case_1.snakeCase, exclude);
57
+ }
58
+ exports.objKeysToSnakeCase = objKeysToSnakeCase;
@@ -0,0 +1,112 @@
1
+ import fetch, { Request } from 'node-fetch';
2
+ import { NylasApiError, NylasOAuthError, NylasSdkTimeoutError, } from './models/error';
3
+ import { objKeysToCamelCase, objKeysToSnakeCase } from './utils';
4
+ const PACKAGE_JSON = require('package.json').default;
5
+ const SDK_VERSION = PACKAGE_JSON.version;
6
+ /**
7
+ * The API client for communicating with the Nylas API
8
+ * @ignore Not for public use
9
+ */
10
+ export default class APIClient {
11
+ constructor({ apiKey, apiUri, timeout }) {
12
+ this.apiKey = apiKey;
13
+ this.serverUrl = apiUri;
14
+ this.timeout = timeout * 1000; // fetch timeout uses milliseconds
15
+ }
16
+ setRequestUrl({ overrides, path, queryParams, }) {
17
+ const url = new URL(`${overrides?.apiUri || this.serverUrl}${path}`);
18
+ return this.setQueryStrings(url, queryParams);
19
+ }
20
+ setQueryStrings(url, queryParams) {
21
+ if (queryParams) {
22
+ const snakeCaseParams = objKeysToSnakeCase(queryParams, ['metadataPair']);
23
+ for (const [key, value] of Object.entries(snakeCaseParams)) {
24
+ if (key == 'metadataPair') {
25
+ // The API understands a metadata_pair filter in the form of:
26
+ // <key>:<value>
27
+ const metadataPair = [];
28
+ for (const item in value) {
29
+ metadataPair.push(`${item}:${value[item]}`);
30
+ }
31
+ url.searchParams.set('metadata_pair', metadataPair.join(','));
32
+ }
33
+ else {
34
+ url.searchParams.set(key, value);
35
+ }
36
+ }
37
+ }
38
+ return url;
39
+ }
40
+ setRequestHeaders({ headers, overrides, }) {
41
+ return {
42
+ Accept: 'application/json',
43
+ 'User-Agent': `Nylas Node SDK v${SDK_VERSION}`,
44
+ Authorization: `Bearer ${overrides?.apiKey || this.apiKey}`,
45
+ ...headers,
46
+ };
47
+ }
48
+ requestOptions(optionParams) {
49
+ const requestOptions = {};
50
+ requestOptions.url = this.setRequestUrl(optionParams);
51
+ requestOptions.headers = this.setRequestHeaders(optionParams);
52
+ requestOptions.method = optionParams.method;
53
+ if (optionParams.body) {
54
+ requestOptions.body = JSON.stringify(objKeysToSnakeCase(optionParams.body));
55
+ requestOptions.headers['Content-Type'] = 'application/json';
56
+ }
57
+ return requestOptions;
58
+ }
59
+ newRequest(options) {
60
+ const newOptions = this.requestOptions(options);
61
+ return new Request(newOptions.url, {
62
+ method: newOptions.method,
63
+ headers: newOptions.headers,
64
+ body: newOptions.body,
65
+ });
66
+ }
67
+ async requestWithResponse(response) {
68
+ const text = await response.text();
69
+ try {
70
+ const responseJSON = JSON.parse(text);
71
+ return objKeysToCamelCase(responseJSON);
72
+ }
73
+ catch (e) {
74
+ throw new Error(`Could not parse response from the server: ${text}`);
75
+ }
76
+ }
77
+ async request(options) {
78
+ const req = this.newRequest(options);
79
+ const controller = new AbortController();
80
+ const timeout = setTimeout(() => {
81
+ controller.abort();
82
+ throw new NylasSdkTimeoutError(req.url, this.timeout);
83
+ }, this.timeout);
84
+ const response = await fetch(req, { signal: controller.signal });
85
+ clearTimeout(timeout);
86
+ if (typeof response === 'undefined') {
87
+ throw new Error('Failed to fetch response');
88
+ }
89
+ // handle error response
90
+ if (response.status > 299) {
91
+ const authErrorResponse = options.path.includes('connect/token') ||
92
+ options.path.includes('connect/revoke');
93
+ const text = await response.text();
94
+ let error;
95
+ try {
96
+ const parsedError = JSON.parse(text);
97
+ const camelCaseError = objKeysToCamelCase(parsedError);
98
+ if (authErrorResponse) {
99
+ error = new NylasOAuthError(camelCaseError, response.status);
100
+ }
101
+ else {
102
+ error = new NylasApiError(camelCaseError, response.status);
103
+ }
104
+ }
105
+ catch (e) {
106
+ throw new Error(`Received an error but could not parse response from the server: ${text}`);
107
+ }
108
+ throw error;
109
+ }
110
+ return this.requestWithResponse(response);
111
+ }
112
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Enum representing the available Nylas API regions.
3
+ */
4
+ export var Region;
5
+ (function (Region) {
6
+ Region["Us"] = "us";
7
+ Region["Eu"] = "eu";
8
+ })(Region || (Region = {}));
9
+ /**
10
+ * The default Nylas API region.
11
+ * @default Region.Us
12
+ */
13
+ export const DEFAULT_REGION = Region.Us;
14
+ /**
15
+ * The available preset configuration values for each Nylas API region.
16
+ */
17
+ export const REGION_CONFIG = {
18
+ [Region.Us]: {
19
+ nylasAPIUrl: 'https://api.us.nylas.com',
20
+ },
21
+ [Region.Eu]: {
22
+ nylasAPIUrl: 'https://api.eu.nylas.com',
23
+ },
24
+ };
25
+ /**
26
+ * The default Nylas API URL.
27
+ * @default https://api.us.nylas.com
28
+ */
29
+ export const DEFAULT_SERVER_URL = REGION_CONFIG[DEFAULT_REGION].nylasAPIUrl;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Enum representing the method used to determine availability for a meeting.
3
+ */
4
+ export var AvailabilityMethod;
5
+ (function (AvailabilityMethod) {
6
+ AvailabilityMethod["MaxFairness"] = "max-fairness";
7
+ AvailabilityMethod["MaxAvailability"] = "max-availability";
8
+ })(AvailabilityMethod || (AvailabilityMethod = {}));
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Base class for all Nylas API errors.
3
+ */
4
+ export class AbstractNylasApiError extends Error {
5
+ }
6
+ /**
7
+ * Base class for all Nylas SDK errors.
8
+ */
9
+ export class AbstractNylasSdkError extends Error {
10
+ }
11
+ /**
12
+ * Class representation of a general Nylas API error.
13
+ */
14
+ export class NylasApiError extends AbstractNylasApiError {
15
+ constructor(apiError, statusCode) {
16
+ super(apiError.error.message);
17
+ this.type = apiError.error.type;
18
+ this.requestId = apiError.requestId;
19
+ this.providerError = apiError.error.providerError;
20
+ this.statusCode = statusCode;
21
+ }
22
+ }
23
+ /**
24
+ * Class representing an OAuth error returned by the Nylas API.
25
+ */
26
+ export class NylasOAuthError extends AbstractNylasApiError {
27
+ constructor(apiError, statusCode) {
28
+ super(apiError.errorDescription);
29
+ this.error = apiError.error;
30
+ this.errorCode = apiError.errorCode;
31
+ this.errorDescription = apiError.errorDescription;
32
+ this.errorUri = apiError.errorUri;
33
+ this.statusCode = statusCode;
34
+ }
35
+ }
36
+ /**
37
+ * Error thrown when the Nylas SDK times out before receiving a response from the server
38
+ */
39
+ export class NylasSdkTimeoutError extends AbstractNylasSdkError {
40
+ constructor(url, timeout) {
41
+ super('Nylas SDK timed out before receiving a response from the server.');
42
+ this.url = url;
43
+ this.timeout = timeout;
44
+ }
45
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};