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
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Events = void 0;
4
+ const resource_js_1 = require("./resource.js");
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_js_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_js_1 = require("./resource.js");
5
+ /**
6
+ * Nylas Grants API
7
+ *
8
+ * The Nylas Grants API allows for the management of grants.
9
+ */
10
+ class Grants extends resource_js_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_js_1 = require("./resource.js");
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_js_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_js_1 = require("./resource.js");
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_js_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,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SDK_VERSION = void 0;
4
+ // This file is generated by scripts/exportVersion.js
5
+ exports.SDK_VERSION = '7.0.0-beta.2';
@@ -0,0 +1,111 @@
1
+ import fetch, { Request } from 'node-fetch';
2
+ import { NylasApiError, NylasOAuthError, NylasSdkTimeoutError, } from './models/error.js';
3
+ import { objKeysToCamelCase, objKeysToSnakeCase } from './utils.js';
4
+ import { SDK_VERSION } from './version.js';
5
+ /**
6
+ * The API client for communicating with the Nylas API
7
+ * @ignore Not for public use
8
+ */
9
+ export default class APIClient {
10
+ constructor({ apiKey, apiUri, timeout }) {
11
+ this.apiKey = apiKey;
12
+ this.serverUrl = apiUri;
13
+ this.timeout = timeout * 1000; // fetch timeout uses milliseconds
14
+ }
15
+ setRequestUrl({ overrides, path, queryParams, }) {
16
+ const url = new URL(`${overrides?.apiUri || this.serverUrl}${path}`);
17
+ return this.setQueryStrings(url, queryParams);
18
+ }
19
+ setQueryStrings(url, queryParams) {
20
+ if (queryParams) {
21
+ const snakeCaseParams = objKeysToSnakeCase(queryParams, ['metadataPair']);
22
+ for (const [key, value] of Object.entries(snakeCaseParams)) {
23
+ if (key == 'metadataPair') {
24
+ // The API understands a metadata_pair filter in the form of:
25
+ // <key>:<value>
26
+ const metadataPair = [];
27
+ for (const item in value) {
28
+ metadataPair.push(`${item}:${value[item]}`);
29
+ }
30
+ url.searchParams.set('metadata_pair', metadataPair.join(','));
31
+ }
32
+ else {
33
+ url.searchParams.set(key, value);
34
+ }
35
+ }
36
+ }
37
+ return url;
38
+ }
39
+ setRequestHeaders({ headers, overrides, }) {
40
+ return {
41
+ Accept: 'application/json',
42
+ 'User-Agent': `Nylas Node SDK v${SDK_VERSION}`,
43
+ Authorization: `Bearer ${overrides?.apiKey || this.apiKey}`,
44
+ ...headers,
45
+ };
46
+ }
47
+ requestOptions(optionParams) {
48
+ const requestOptions = {};
49
+ requestOptions.url = this.setRequestUrl(optionParams);
50
+ requestOptions.headers = this.setRequestHeaders(optionParams);
51
+ requestOptions.method = optionParams.method;
52
+ if (optionParams.body) {
53
+ requestOptions.body = JSON.stringify(objKeysToSnakeCase(optionParams.body));
54
+ requestOptions.headers['Content-Type'] = 'application/json';
55
+ }
56
+ return requestOptions;
57
+ }
58
+ newRequest(options) {
59
+ const newOptions = this.requestOptions(options);
60
+ return new Request(newOptions.url, {
61
+ method: newOptions.method,
62
+ headers: newOptions.headers,
63
+ body: newOptions.body,
64
+ });
65
+ }
66
+ async requestWithResponse(response) {
67
+ const text = await response.text();
68
+ try {
69
+ const responseJSON = JSON.parse(text);
70
+ return objKeysToCamelCase(responseJSON);
71
+ }
72
+ catch (e) {
73
+ throw new Error(`Could not parse response from the server: ${text}`);
74
+ }
75
+ }
76
+ async request(options) {
77
+ const req = this.newRequest(options);
78
+ const controller = new AbortController();
79
+ const timeout = setTimeout(() => {
80
+ controller.abort();
81
+ throw new NylasSdkTimeoutError(req.url, this.timeout);
82
+ }, this.timeout);
83
+ const response = await fetch(req, { signal: controller.signal });
84
+ clearTimeout(timeout);
85
+ if (typeof response === 'undefined') {
86
+ throw new Error('Failed to fetch response');
87
+ }
88
+ // handle error response
89
+ if (response.status > 299) {
90
+ const authErrorResponse = options.path.includes('connect/token') ||
91
+ options.path.includes('connect/revoke');
92
+ const text = await response.text();
93
+ let error;
94
+ try {
95
+ const parsedError = JSON.parse(text);
96
+ const camelCaseError = objKeysToCamelCase(parsedError);
97
+ if (authErrorResponse) {
98
+ error = new NylasOAuthError(camelCaseError, response.status);
99
+ }
100
+ else {
101
+ error = new NylasApiError(camelCaseError, response.status);
102
+ }
103
+ }
104
+ catch (e) {
105
+ throw new Error(`Received an error but could not parse response from the server: ${text}`);
106
+ }
107
+ throw error;
108
+ }
109
+ return this.requestWithResponse(response);
110
+ }
111
+ }
@@ -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 {};