patchwork-os 0.2.0-alpha.36 → 0.2.0-alpha.37

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.
@@ -33,105 +33,175 @@ export function tryHandlePublicConnectorRoute(req, res, parsedUrl) {
33
33
  if (parsedUrl.pathname === "/connections/github/callback" &&
34
34
  req.method === "GET") {
35
35
  void (async () => {
36
- const { handleGithubCallback } = await import("./connectors/github.js");
37
- const code = parsedUrl.searchParams.get("code");
38
- const state = parsedUrl.searchParams.get("state");
39
- const error = parsedUrl.searchParams.get("error");
40
- const result = await handleGithubCallback(code, state, error);
41
- res.writeHead(result.status, {
42
- "Content-Type": result.contentType ?? "application/json",
43
- });
44
- res.end(result.body);
36
+ try {
37
+ const { handleGithubCallback } = await import("./connectors/github.js");
38
+ const code = parsedUrl.searchParams.get("code");
39
+ const state = parsedUrl.searchParams.get("state");
40
+ const error = parsedUrl.searchParams.get("error");
41
+ const result = await handleGithubCallback(code, state, error);
42
+ res.writeHead(result.status, {
43
+ "Content-Type": result.contentType ?? "application/json",
44
+ });
45
+ res.end(result.body);
46
+ }
47
+ catch (err) {
48
+ if (!res.headersSent) {
49
+ res.writeHead(500, { "Content-Type": "application/json" });
50
+ res.end(JSON.stringify({
51
+ error: err instanceof Error ? err.message : String(err),
52
+ }));
53
+ }
54
+ }
45
55
  })();
46
56
  return true;
47
57
  }
48
58
  if (parsedUrl.pathname === "/connections/linear/callback" &&
49
59
  req.method === "GET") {
50
60
  void (async () => {
51
- const { handleLinearCallback } = await import("./connectors/linear.js");
52
- const code = parsedUrl.searchParams.get("code");
53
- const state = parsedUrl.searchParams.get("state");
54
- const error = parsedUrl.searchParams.get("error");
55
- const result = await handleLinearCallback(code, state, error);
56
- res.writeHead(result.status, {
57
- "Content-Type": result.contentType ?? "application/json",
58
- });
59
- res.end(result.body);
61
+ try {
62
+ const { handleLinearCallback } = await import("./connectors/linear.js");
63
+ const code = parsedUrl.searchParams.get("code");
64
+ const state = parsedUrl.searchParams.get("state");
65
+ const error = parsedUrl.searchParams.get("error");
66
+ const result = await handleLinearCallback(code, state, error);
67
+ res.writeHead(result.status, {
68
+ "Content-Type": result.contentType ?? "application/json",
69
+ });
70
+ res.end(result.body);
71
+ }
72
+ catch (err) {
73
+ if (!res.headersSent) {
74
+ res.writeHead(500, { "Content-Type": "application/json" });
75
+ res.end(JSON.stringify({
76
+ error: err instanceof Error ? err.message : String(err),
77
+ }));
78
+ }
79
+ }
60
80
  })();
61
81
  return true;
62
82
  }
63
83
  if (parsedUrl.pathname === "/connections/sentry/callback" &&
64
84
  req.method === "GET") {
65
85
  void (async () => {
66
- const { handleSentryCallback } = await import("./connectors/sentry.js");
67
- const code = parsedUrl.searchParams.get("code");
68
- const state = parsedUrl.searchParams.get("state");
69
- const error = parsedUrl.searchParams.get("error");
70
- const result = await handleSentryCallback(code, state, error);
71
- res.writeHead(result.status, {
72
- "Content-Type": result.contentType ?? "application/json",
73
- });
74
- res.end(result.body);
86
+ try {
87
+ const { handleSentryCallback } = await import("./connectors/sentry.js");
88
+ const code = parsedUrl.searchParams.get("code");
89
+ const state = parsedUrl.searchParams.get("state");
90
+ const error = parsedUrl.searchParams.get("error");
91
+ const result = await handleSentryCallback(code, state, error);
92
+ res.writeHead(result.status, {
93
+ "Content-Type": result.contentType ?? "application/json",
94
+ });
95
+ res.end(result.body);
96
+ }
97
+ catch (err) {
98
+ if (!res.headersSent) {
99
+ res.writeHead(500, { "Content-Type": "application/json" });
100
+ res.end(JSON.stringify({
101
+ error: err instanceof Error ? err.message : String(err),
102
+ }));
103
+ }
104
+ }
75
105
  })();
76
106
  return true;
77
107
  }
78
108
  if (parsedUrl.pathname === "/connections/google-calendar/callback" &&
79
109
  req.method === "GET") {
80
110
  void (async () => {
81
- const { handleCalendarCallback } = await import("./connectors/googleCalendar.js");
82
- const code = parsedUrl.searchParams.get("code");
83
- const state = parsedUrl.searchParams.get("state");
84
- const error = parsedUrl.searchParams.get("error");
85
- const result = await handleCalendarCallback(code, state, error);
86
- res.writeHead(result.status, {
87
- "Content-Type": result.contentType ?? "application/json",
88
- });
89
- res.end(result.body);
111
+ try {
112
+ const { handleCalendarCallback } = await import("./connectors/googleCalendar.js");
113
+ const code = parsedUrl.searchParams.get("code");
114
+ const state = parsedUrl.searchParams.get("state");
115
+ const error = parsedUrl.searchParams.get("error");
116
+ const result = await handleCalendarCallback(code, state, error);
117
+ res.writeHead(result.status, {
118
+ "Content-Type": result.contentType ?? "application/json",
119
+ });
120
+ res.end(result.body);
121
+ }
122
+ catch (err) {
123
+ if (!res.headersSent) {
124
+ res.writeHead(500, { "Content-Type": "application/json" });
125
+ res.end(JSON.stringify({
126
+ error: err instanceof Error ? err.message : String(err),
127
+ }));
128
+ }
129
+ }
90
130
  })();
91
131
  return true;
92
132
  }
93
133
  if (parsedUrl.pathname === "/connections/google-drive/callback" &&
94
134
  req.method === "GET") {
95
135
  void (async () => {
96
- const { handleDriveCallback } = await import("./connectors/googleDrive.js");
97
- const code = parsedUrl.searchParams.get("code");
98
- const state = parsedUrl.searchParams.get("state");
99
- const error = parsedUrl.searchParams.get("error");
100
- const result = await handleDriveCallback(code, state, error);
101
- res.writeHead(result.status, {
102
- "Content-Type": result.contentType ?? "application/json",
103
- });
104
- res.end(result.body);
136
+ try {
137
+ const { handleDriveCallback } = await import("./connectors/googleDrive.js");
138
+ const code = parsedUrl.searchParams.get("code");
139
+ const state = parsedUrl.searchParams.get("state");
140
+ const error = parsedUrl.searchParams.get("error");
141
+ const result = await handleDriveCallback(code, state, error);
142
+ res.writeHead(result.status, {
143
+ "Content-Type": result.contentType ?? "application/json",
144
+ });
145
+ res.end(result.body);
146
+ }
147
+ catch (err) {
148
+ if (!res.headersSent) {
149
+ res.writeHead(500, { "Content-Type": "application/json" });
150
+ res.end(JSON.stringify({
151
+ error: err instanceof Error ? err.message : String(err),
152
+ }));
153
+ }
154
+ }
105
155
  })();
106
156
  return true;
107
157
  }
108
158
  if (parsedUrl.pathname === "/connections/slack/callback" &&
109
159
  req.method === "GET") {
110
160
  void (async () => {
111
- const { handleSlackCallback } = await import("./connectors/slack.js");
112
- const code = parsedUrl.searchParams.get("code");
113
- const state = parsedUrl.searchParams.get("state");
114
- const error = parsedUrl.searchParams.get("error");
115
- const result = await handleSlackCallback(code, state, error);
116
- res.writeHead(result.status, {
117
- "Content-Type": result.contentType ?? "application/json",
118
- });
119
- res.end(result.body);
161
+ try {
162
+ const { handleSlackCallback } = await import("./connectors/slack.js");
163
+ const code = parsedUrl.searchParams.get("code");
164
+ const state = parsedUrl.searchParams.get("state");
165
+ const error = parsedUrl.searchParams.get("error");
166
+ const result = await handleSlackCallback(code, state, error);
167
+ res.writeHead(result.status, {
168
+ "Content-Type": result.contentType ?? "application/json",
169
+ });
170
+ res.end(result.body);
171
+ }
172
+ catch (err) {
173
+ if (!res.headersSent) {
174
+ res.writeHead(500, { "Content-Type": "application/json" });
175
+ res.end(JSON.stringify({
176
+ error: err instanceof Error ? err.message : String(err),
177
+ }));
178
+ }
179
+ }
120
180
  })();
121
181
  return true;
122
182
  }
123
183
  if (parsedUrl.pathname === "/connections/gmail/callback" &&
124
184
  req.method === "GET") {
125
185
  void (async () => {
126
- const { handleGmailCallback } = await import("./connectors/gmail.js");
127
- const code = parsedUrl.searchParams.get("code");
128
- const state = parsedUrl.searchParams.get("state");
129
- const error = parsedUrl.searchParams.get("error");
130
- const result = await handleGmailCallback(code, state, error);
131
- res.writeHead(result.status, {
132
- "Content-Type": result.contentType ?? "text/html",
133
- });
134
- res.end(result.body);
186
+ try {
187
+ const { handleGmailCallback } = await import("./connectors/gmail.js");
188
+ const code = parsedUrl.searchParams.get("code");
189
+ const state = parsedUrl.searchParams.get("state");
190
+ const error = parsedUrl.searchParams.get("error");
191
+ const result = await handleGmailCallback(code, state, error);
192
+ res.writeHead(result.status, {
193
+ "Content-Type": result.contentType ?? "text/html",
194
+ });
195
+ res.end(result.body);
196
+ }
197
+ catch (err) {
198
+ if (!res.headersSent) {
199
+ res.writeHead(500, { "Content-Type": "application/json" });
200
+ res.end(JSON.stringify({
201
+ error: err instanceof Error ? err.message : String(err),
202
+ }));
203
+ }
204
+ }
135
205
  })();
136
206
  return true;
137
207
  }
@@ -150,53 +220,93 @@ export function tryHandleConnectorRoute(req, res, parsedUrl) {
150
220
  // ── Gmail / Connections endpoints ───────────────────────────────────────
151
221
  if (parsedUrl.pathname === "/connections" && req.method === "GET") {
152
222
  void (async () => {
153
- const { handleConnectionsList } = await import("./connectors/gmail.js");
154
- const result = await handleConnectionsList();
155
- res.writeHead(result.status, {
156
- "Content-Type": result.contentType ?? "application/json",
157
- });
158
- res.end(result.body);
223
+ try {
224
+ const { handleConnectionsList } = await import("./connectors/gmail.js");
225
+ const result = await handleConnectionsList();
226
+ res.writeHead(result.status, {
227
+ "Content-Type": result.contentType ?? "application/json",
228
+ });
229
+ res.end(result.body);
230
+ }
231
+ catch (err) {
232
+ if (!res.headersSent) {
233
+ res.writeHead(500, { "Content-Type": "application/json" });
234
+ res.end(JSON.stringify({
235
+ error: err instanceof Error ? err.message : String(err),
236
+ }));
237
+ }
238
+ }
159
239
  })();
160
240
  return true;
161
241
  }
162
242
  if (parsedUrl.pathname === "/connections/gmail/auth" &&
163
243
  req.method === "GET") {
164
244
  void (async () => {
165
- const { handleGmailAuthRedirect } = await import("./connectors/gmail.js");
166
- const result = handleGmailAuthRedirect();
167
- if (result.redirect) {
168
- res.writeHead(302, { Location: result.redirect });
169
- res.end();
245
+ try {
246
+ const { handleGmailAuthRedirect } = await import("./connectors/gmail.js");
247
+ const result = handleGmailAuthRedirect();
248
+ if (result.redirect) {
249
+ res.writeHead(302, { Location: result.redirect });
250
+ res.end();
251
+ }
252
+ else {
253
+ res.writeHead(result.status, {
254
+ "Content-Type": result.contentType ?? "application/json",
255
+ });
256
+ res.end(result.body);
257
+ }
170
258
  }
171
- else {
172
- res.writeHead(result.status, {
173
- "Content-Type": result.contentType ?? "application/json",
174
- });
175
- res.end(result.body);
259
+ catch (err) {
260
+ if (!res.headersSent) {
261
+ res.writeHead(500, { "Content-Type": "application/json" });
262
+ res.end(JSON.stringify({
263
+ error: err instanceof Error ? err.message : String(err),
264
+ }));
265
+ }
176
266
  }
177
267
  })();
178
268
  return true;
179
269
  }
180
270
  if (parsedUrl.pathname === "/connections/gmail" && req.method === "DELETE") {
181
271
  void (async () => {
182
- const { handleGmailDisconnect } = await import("./connectors/gmail.js");
183
- const result = await handleGmailDisconnect();
184
- res.writeHead(result.status, {
185
- "Content-Type": result.contentType ?? "application/json",
186
- });
187
- res.end(result.body);
272
+ try {
273
+ const { handleGmailDisconnect } = await import("./connectors/gmail.js");
274
+ const result = await handleGmailDisconnect();
275
+ res.writeHead(result.status, {
276
+ "Content-Type": result.contentType ?? "application/json",
277
+ });
278
+ res.end(result.body);
279
+ }
280
+ catch (err) {
281
+ if (!res.headersSent) {
282
+ res.writeHead(500, { "Content-Type": "application/json" });
283
+ res.end(JSON.stringify({
284
+ error: err instanceof Error ? err.message : String(err),
285
+ }));
286
+ }
287
+ }
188
288
  })();
189
289
  return true;
190
290
  }
191
291
  if (parsedUrl.pathname === "/connections/gmail/test" &&
192
292
  req.method === "POST") {
193
293
  void (async () => {
194
- const { handleGmailTest } = await import("./connectors/gmail.js");
195
- const result = await handleGmailTest();
196
- res.writeHead(result.status, {
197
- "Content-Type": result.contentType ?? "application/json",
198
- });
199
- res.end(result.body);
294
+ try {
295
+ const { handleGmailTest } = await import("./connectors/gmail.js");
296
+ const result = await handleGmailTest();
297
+ res.writeHead(result.status, {
298
+ "Content-Type": result.contentType ?? "application/json",
299
+ });
300
+ res.end(result.body);
301
+ }
302
+ catch (err) {
303
+ if (!res.headersSent) {
304
+ res.writeHead(500, { "Content-Type": "application/json" });
305
+ res.end(JSON.stringify({
306
+ error: err instanceof Error ? err.message : String(err),
307
+ }));
308
+ }
309
+ }
200
310
  })();
201
311
  return true;
202
312
  }
@@ -204,17 +314,27 @@ export function tryHandleConnectorRoute(req, res, parsedUrl) {
204
314
  if (parsedUrl.pathname === "/connections/github/auth" &&
205
315
  req.method === "GET") {
206
316
  void (async () => {
207
- const { handleGithubAuthorize } = await import("./connectors/github.js");
208
- const result = await handleGithubAuthorize();
209
- if (result.redirect) {
210
- res.writeHead(302, { Location: result.redirect });
211
- res.end();
317
+ try {
318
+ const { handleGithubAuthorize } = await import("./connectors/github.js");
319
+ const result = await handleGithubAuthorize();
320
+ if (result.redirect) {
321
+ res.writeHead(302, { Location: result.redirect });
322
+ res.end();
323
+ }
324
+ else {
325
+ res.writeHead(result.status, {
326
+ "Content-Type": result.contentType ?? "application/json",
327
+ });
328
+ res.end(result.body);
329
+ }
212
330
  }
213
- else {
214
- res.writeHead(result.status, {
215
- "Content-Type": result.contentType ?? "application/json",
216
- });
217
- res.end(result.body);
331
+ catch (err) {
332
+ if (!res.headersSent) {
333
+ res.writeHead(500, { "Content-Type": "application/json" });
334
+ res.end(JSON.stringify({
335
+ error: err instanceof Error ? err.message : String(err),
336
+ }));
337
+ }
218
338
  }
219
339
  })();
220
340
  return true;
@@ -222,23 +342,43 @@ export function tryHandleConnectorRoute(req, res, parsedUrl) {
222
342
  if (parsedUrl.pathname === "/connections/github/test" &&
223
343
  req.method === "POST") {
224
344
  void (async () => {
225
- const { handleGithubTest } = await import("./connectors/github.js");
226
- const result = await handleGithubTest();
227
- res.writeHead(result.status, {
228
- "Content-Type": result.contentType ?? "application/json",
229
- });
230
- res.end(result.body);
345
+ try {
346
+ const { handleGithubTest } = await import("./connectors/github.js");
347
+ const result = await handleGithubTest();
348
+ res.writeHead(result.status, {
349
+ "Content-Type": result.contentType ?? "application/json",
350
+ });
351
+ res.end(result.body);
352
+ }
353
+ catch (err) {
354
+ if (!res.headersSent) {
355
+ res.writeHead(500, { "Content-Type": "application/json" });
356
+ res.end(JSON.stringify({
357
+ error: err instanceof Error ? err.message : String(err),
358
+ }));
359
+ }
360
+ }
231
361
  })();
232
362
  return true;
233
363
  }
234
364
  if (parsedUrl.pathname === "/connections/github" && req.method === "DELETE") {
235
365
  void (async () => {
236
- const { handleGithubDisconnect } = await import("./connectors/github.js");
237
- const result = await handleGithubDisconnect();
238
- res.writeHead(result.status, {
239
- "Content-Type": result.contentType ?? "application/json",
240
- });
241
- res.end(result.body);
366
+ try {
367
+ const { handleGithubDisconnect } = await import("./connectors/github.js");
368
+ const result = await handleGithubDisconnect();
369
+ res.writeHead(result.status, {
370
+ "Content-Type": result.contentType ?? "application/json",
371
+ });
372
+ res.end(result.body);
373
+ }
374
+ catch (err) {
375
+ if (!res.headersSent) {
376
+ res.writeHead(500, { "Content-Type": "application/json" });
377
+ res.end(JSON.stringify({
378
+ error: err instanceof Error ? err.message : String(err),
379
+ }));
380
+ }
381
+ }
242
382
  })();
243
383
  return true;
244
384
  }
@@ -246,17 +386,27 @@ export function tryHandleConnectorRoute(req, res, parsedUrl) {
246
386
  if (parsedUrl.pathname === "/connections/sentry/auth" &&
247
387
  req.method === "GET") {
248
388
  void (async () => {
249
- const { handleSentryAuthorize } = await import("./connectors/sentry.js");
250
- const result = await handleSentryAuthorize();
251
- if (result.redirect) {
252
- res.writeHead(302, { Location: result.redirect });
253
- res.end();
389
+ try {
390
+ const { handleSentryAuthorize } = await import("./connectors/sentry.js");
391
+ const result = await handleSentryAuthorize();
392
+ if (result.redirect) {
393
+ res.writeHead(302, { Location: result.redirect });
394
+ res.end();
395
+ }
396
+ else {
397
+ res.writeHead(result.status, {
398
+ "Content-Type": result.contentType ?? "application/json",
399
+ });
400
+ res.end(result.body);
401
+ }
254
402
  }
255
- else {
256
- res.writeHead(result.status, {
257
- "Content-Type": result.contentType ?? "application/json",
258
- });
259
- res.end(result.body);
403
+ catch (err) {
404
+ if (!res.headersSent) {
405
+ res.writeHead(500, { "Content-Type": "application/json" });
406
+ res.end(JSON.stringify({
407
+ error: err instanceof Error ? err.message : String(err),
408
+ }));
409
+ }
260
410
  }
261
411
  })();
262
412
  return true;
@@ -264,38 +414,68 @@ export function tryHandleConnectorRoute(req, res, parsedUrl) {
264
414
  if (parsedUrl.pathname === "/connections/sentry/callback" &&
265
415
  req.method === "GET") {
266
416
  void (async () => {
267
- const { handleSentryCallback } = await import("./connectors/sentry.js");
268
- const code = parsedUrl.searchParams.get("code");
269
- const state = parsedUrl.searchParams.get("state");
270
- const error = parsedUrl.searchParams.get("error");
271
- const result = await handleSentryCallback(code, state, error);
272
- res.writeHead(result.status, {
273
- "Content-Type": result.contentType ?? "application/json",
274
- });
275
- res.end(result.body);
417
+ try {
418
+ const { handleSentryCallback } = await import("./connectors/sentry.js");
419
+ const code = parsedUrl.searchParams.get("code");
420
+ const state = parsedUrl.searchParams.get("state");
421
+ const error = parsedUrl.searchParams.get("error");
422
+ const result = await handleSentryCallback(code, state, error);
423
+ res.writeHead(result.status, {
424
+ "Content-Type": result.contentType ?? "application/json",
425
+ });
426
+ res.end(result.body);
427
+ }
428
+ catch (err) {
429
+ if (!res.headersSent) {
430
+ res.writeHead(500, { "Content-Type": "application/json" });
431
+ res.end(JSON.stringify({
432
+ error: err instanceof Error ? err.message : String(err),
433
+ }));
434
+ }
435
+ }
276
436
  })();
277
437
  return true;
278
438
  }
279
439
  if (parsedUrl.pathname === "/connections/sentry/test" &&
280
440
  req.method === "POST") {
281
441
  void (async () => {
282
- const { handleSentryTest } = await import("./connectors/sentry.js");
283
- const result = await handleSentryTest();
284
- res.writeHead(result.status, {
285
- "Content-Type": result.contentType ?? "application/json",
286
- });
287
- res.end(result.body);
442
+ try {
443
+ const { handleSentryTest } = await import("./connectors/sentry.js");
444
+ const result = await handleSentryTest();
445
+ res.writeHead(result.status, {
446
+ "Content-Type": result.contentType ?? "application/json",
447
+ });
448
+ res.end(result.body);
449
+ }
450
+ catch (err) {
451
+ if (!res.headersSent) {
452
+ res.writeHead(500, { "Content-Type": "application/json" });
453
+ res.end(JSON.stringify({
454
+ error: err instanceof Error ? err.message : String(err),
455
+ }));
456
+ }
457
+ }
288
458
  })();
289
459
  return true;
290
460
  }
291
461
  if (parsedUrl.pathname === "/connections/sentry" && req.method === "DELETE") {
292
462
  void (async () => {
293
- const { handleSentryDisconnect } = await import("./connectors/sentry.js");
294
- const result = await handleSentryDisconnect();
295
- res.writeHead(result.status, {
296
- "Content-Type": result.contentType ?? "application/json",
297
- });
298
- res.end(result.body);
463
+ try {
464
+ const { handleSentryDisconnect } = await import("./connectors/sentry.js");
465
+ const result = await handleSentryDisconnect();
466
+ res.writeHead(result.status, {
467
+ "Content-Type": result.contentType ?? "application/json",
468
+ });
469
+ res.end(result.body);
470
+ }
471
+ catch (err) {
472
+ if (!res.headersSent) {
473
+ res.writeHead(500, { "Content-Type": "application/json" });
474
+ res.end(JSON.stringify({
475
+ error: err instanceof Error ? err.message : String(err),
476
+ }));
477
+ }
478
+ }
299
479
  })();
300
480
  return true;
301
481
  }
@@ -303,17 +483,27 @@ export function tryHandleConnectorRoute(req, res, parsedUrl) {
303
483
  if (parsedUrl.pathname === "/connections/linear/auth" &&
304
484
  req.method === "GET") {
305
485
  void (async () => {
306
- const { handleLinearAuthorize } = await import("./connectors/linear.js");
307
- const result = await handleLinearAuthorize();
308
- if (result.redirect) {
309
- res.writeHead(302, { Location: result.redirect });
310
- res.end();
486
+ try {
487
+ const { handleLinearAuthorize } = await import("./connectors/linear.js");
488
+ const result = await handleLinearAuthorize();
489
+ if (result.redirect) {
490
+ res.writeHead(302, { Location: result.redirect });
491
+ res.end();
492
+ }
493
+ else {
494
+ res.writeHead(result.status, {
495
+ "Content-Type": result.contentType ?? "application/json",
496
+ });
497
+ res.end(result.body);
498
+ }
311
499
  }
312
- else {
313
- res.writeHead(result.status, {
314
- "Content-Type": result.contentType ?? "application/json",
315
- });
316
- res.end(result.body);
500
+ catch (err) {
501
+ if (!res.headersSent) {
502
+ res.writeHead(500, { "Content-Type": "application/json" });
503
+ res.end(JSON.stringify({
504
+ error: err instanceof Error ? err.message : String(err),
505
+ }));
506
+ }
317
507
  }
318
508
  })();
319
509
  return true;
@@ -321,38 +511,68 @@ export function tryHandleConnectorRoute(req, res, parsedUrl) {
321
511
  if (parsedUrl.pathname === "/connections/linear/callback" &&
322
512
  req.method === "GET") {
323
513
  void (async () => {
324
- const { handleLinearCallback } = await import("./connectors/linear.js");
325
- const code = parsedUrl.searchParams.get("code");
326
- const state = parsedUrl.searchParams.get("state");
327
- const error = parsedUrl.searchParams.get("error");
328
- const result = await handleLinearCallback(code, state, error);
329
- res.writeHead(result.status, {
330
- "Content-Type": result.contentType ?? "application/json",
331
- });
332
- res.end(result.body);
514
+ try {
515
+ const { handleLinearCallback } = await import("./connectors/linear.js");
516
+ const code = parsedUrl.searchParams.get("code");
517
+ const state = parsedUrl.searchParams.get("state");
518
+ const error = parsedUrl.searchParams.get("error");
519
+ const result = await handleLinearCallback(code, state, error);
520
+ res.writeHead(result.status, {
521
+ "Content-Type": result.contentType ?? "application/json",
522
+ });
523
+ res.end(result.body);
524
+ }
525
+ catch (err) {
526
+ if (!res.headersSent) {
527
+ res.writeHead(500, { "Content-Type": "application/json" });
528
+ res.end(JSON.stringify({
529
+ error: err instanceof Error ? err.message : String(err),
530
+ }));
531
+ }
532
+ }
333
533
  })();
334
534
  return true;
335
535
  }
336
536
  if (parsedUrl.pathname === "/connections/linear/test" &&
337
537
  req.method === "POST") {
338
538
  void (async () => {
339
- const { handleLinearTest } = await import("./connectors/linear.js");
340
- const result = await handleLinearTest();
341
- res.writeHead(result.status, {
342
- "Content-Type": result.contentType ?? "application/json",
343
- });
344
- res.end(result.body);
539
+ try {
540
+ const { handleLinearTest } = await import("./connectors/linear.js");
541
+ const result = await handleLinearTest();
542
+ res.writeHead(result.status, {
543
+ "Content-Type": result.contentType ?? "application/json",
544
+ });
545
+ res.end(result.body);
546
+ }
547
+ catch (err) {
548
+ if (!res.headersSent) {
549
+ res.writeHead(500, { "Content-Type": "application/json" });
550
+ res.end(JSON.stringify({
551
+ error: err instanceof Error ? err.message : String(err),
552
+ }));
553
+ }
554
+ }
345
555
  })();
346
556
  return true;
347
557
  }
348
558
  if (parsedUrl.pathname === "/connections/linear" && req.method === "DELETE") {
349
559
  void (async () => {
350
- const { handleLinearDisconnect } = await import("./connectors/linear.js");
351
- const result = await handleLinearDisconnect();
352
- res.writeHead(result.status, {
353
- "Content-Type": result.contentType ?? "application/json",
354
- });
355
- res.end(result.body);
560
+ try {
561
+ const { handleLinearDisconnect } = await import("./connectors/linear.js");
562
+ const result = await handleLinearDisconnect();
563
+ res.writeHead(result.status, {
564
+ "Content-Type": result.contentType ?? "application/json",
565
+ });
566
+ res.end(result.body);
567
+ }
568
+ catch (err) {
569
+ if (!res.headersSent) {
570
+ res.writeHead(500, { "Content-Type": "application/json" });
571
+ res.end(JSON.stringify({
572
+ error: err instanceof Error ? err.message : String(err),
573
+ }));
574
+ }
575
+ }
356
576
  })();
357
577
  return true;
358
578
  }
@@ -361,17 +581,27 @@ export function tryHandleConnectorRoute(req, res, parsedUrl) {
361
581
  parsedUrl.pathname === "/connections/slack/authorize") &&
362
582
  req.method === "GET") {
363
583
  void (async () => {
364
- const { handleSlackAuthorize } = await import("./connectors/slack.js");
365
- const result = handleSlackAuthorize();
366
- if (result.redirect) {
367
- res.writeHead(302, { Location: result.redirect });
368
- res.end();
584
+ try {
585
+ const { handleSlackAuthorize } = await import("./connectors/slack.js");
586
+ const result = handleSlackAuthorize();
587
+ if (result.redirect) {
588
+ res.writeHead(302, { Location: result.redirect });
589
+ res.end();
590
+ }
591
+ else {
592
+ res.writeHead(result.status, {
593
+ "Content-Type": result.contentType ?? "application/json",
594
+ });
595
+ res.end(result.body);
596
+ }
369
597
  }
370
- else {
371
- res.writeHead(result.status, {
372
- "Content-Type": result.contentType ?? "application/json",
373
- });
374
- res.end(result.body);
598
+ catch (err) {
599
+ if (!res.headersSent) {
600
+ res.writeHead(500, { "Content-Type": "application/json" });
601
+ res.end(JSON.stringify({
602
+ error: err instanceof Error ? err.message : String(err),
603
+ }));
604
+ }
375
605
  }
376
606
  })();
377
607
  return true;
@@ -379,23 +609,43 @@ export function tryHandleConnectorRoute(req, res, parsedUrl) {
379
609
  if (parsedUrl.pathname === "/connections/slack/test" &&
380
610
  req.method === "POST") {
381
611
  void (async () => {
382
- const { handleSlackTest } = await import("./connectors/slack.js");
383
- const result = await handleSlackTest();
384
- res.writeHead(result.status, {
385
- "Content-Type": result.contentType ?? "application/json",
386
- });
387
- res.end(result.body);
612
+ try {
613
+ const { handleSlackTest } = await import("./connectors/slack.js");
614
+ const result = await handleSlackTest();
615
+ res.writeHead(result.status, {
616
+ "Content-Type": result.contentType ?? "application/json",
617
+ });
618
+ res.end(result.body);
619
+ }
620
+ catch (err) {
621
+ if (!res.headersSent) {
622
+ res.writeHead(500, { "Content-Type": "application/json" });
623
+ res.end(JSON.stringify({
624
+ error: err instanceof Error ? err.message : String(err),
625
+ }));
626
+ }
627
+ }
388
628
  })();
389
629
  return true;
390
630
  }
391
631
  if (parsedUrl.pathname === "/connections/slack" && req.method === "DELETE") {
392
632
  void (async () => {
393
- const { handleSlackDisconnect } = await import("./connectors/slack.js");
394
- const result = handleSlackDisconnect();
395
- res.writeHead(result.status, {
396
- "Content-Type": result.contentType ?? "application/json",
397
- });
398
- res.end(result.body);
633
+ try {
634
+ const { handleSlackDisconnect } = await import("./connectors/slack.js");
635
+ const result = handleSlackDisconnect();
636
+ res.writeHead(result.status, {
637
+ "Content-Type": result.contentType ?? "application/json",
638
+ });
639
+ res.end(result.body);
640
+ }
641
+ catch (err) {
642
+ if (!res.headersSent) {
643
+ res.writeHead(500, { "Content-Type": "application/json" });
644
+ res.end(JSON.stringify({
645
+ error: err instanceof Error ? err.message : String(err),
646
+ }));
647
+ }
648
+ }
399
649
  })();
400
650
  return true;
401
651
  }
@@ -404,17 +654,27 @@ export function tryHandleConnectorRoute(req, res, parsedUrl) {
404
654
  parsedUrl.pathname === "/connections/discord/authorize") &&
405
655
  req.method === "GET") {
406
656
  void (async () => {
407
- const { handleDiscordAuthorize } = await import("./connectors/discord.js");
408
- const result = handleDiscordAuthorize();
409
- if (result.redirect) {
410
- res.writeHead(302, { Location: result.redirect });
411
- res.end();
657
+ try {
658
+ const { handleDiscordAuthorize } = await import("./connectors/discord.js");
659
+ const result = handleDiscordAuthorize();
660
+ if (result.redirect) {
661
+ res.writeHead(302, { Location: result.redirect });
662
+ res.end();
663
+ }
664
+ else {
665
+ res.writeHead(result.status, {
666
+ "Content-Type": result.contentType ?? "application/json",
667
+ });
668
+ res.end(result.body);
669
+ }
412
670
  }
413
- else {
414
- res.writeHead(result.status, {
415
- "Content-Type": result.contentType ?? "application/json",
416
- });
417
- res.end(result.body);
671
+ catch (err) {
672
+ if (!res.headersSent) {
673
+ res.writeHead(500, { "Content-Type": "application/json" });
674
+ res.end(JSON.stringify({
675
+ error: err instanceof Error ? err.message : String(err),
676
+ }));
677
+ }
418
678
  }
419
679
  })();
420
680
  return true;
@@ -422,39 +682,69 @@ export function tryHandleConnectorRoute(req, res, parsedUrl) {
422
682
  if (parsedUrl.pathname === "/connections/discord/callback" &&
423
683
  req.method === "GET") {
424
684
  void (async () => {
425
- const { handleDiscordCallback } = await import("./connectors/discord.js");
426
- const code = parsedUrl.searchParams.get("code");
427
- const state = parsedUrl.searchParams.get("state");
428
- const error = parsedUrl.searchParams.get("error");
429
- const result = await handleDiscordCallback(code, state, error);
430
- res.writeHead(result.status, {
431
- "Content-Type": result.contentType ?? "text/html",
432
- });
433
- res.end(result.body);
685
+ try {
686
+ const { handleDiscordCallback } = await import("./connectors/discord.js");
687
+ const code = parsedUrl.searchParams.get("code");
688
+ const state = parsedUrl.searchParams.get("state");
689
+ const error = parsedUrl.searchParams.get("error");
690
+ const result = await handleDiscordCallback(code, state, error);
691
+ res.writeHead(result.status, {
692
+ "Content-Type": result.contentType ?? "text/html",
693
+ });
694
+ res.end(result.body);
695
+ }
696
+ catch (err) {
697
+ if (!res.headersSent) {
698
+ res.writeHead(500, { "Content-Type": "application/json" });
699
+ res.end(JSON.stringify({
700
+ error: err instanceof Error ? err.message : String(err),
701
+ }));
702
+ }
703
+ }
434
704
  })();
435
705
  return true;
436
706
  }
437
707
  if (parsedUrl.pathname === "/connections/discord/test" &&
438
708
  req.method === "POST") {
439
709
  void (async () => {
440
- const { handleDiscordTest } = await import("./connectors/discord.js");
441
- const result = await handleDiscordTest();
442
- res.writeHead(result.status, {
443
- "Content-Type": result.contentType ?? "application/json",
444
- });
445
- res.end(result.body);
710
+ try {
711
+ const { handleDiscordTest } = await import("./connectors/discord.js");
712
+ const result = await handleDiscordTest();
713
+ res.writeHead(result.status, {
714
+ "Content-Type": result.contentType ?? "application/json",
715
+ });
716
+ res.end(result.body);
717
+ }
718
+ catch (err) {
719
+ if (!res.headersSent) {
720
+ res.writeHead(500, { "Content-Type": "application/json" });
721
+ res.end(JSON.stringify({
722
+ error: err instanceof Error ? err.message : String(err),
723
+ }));
724
+ }
725
+ }
446
726
  })();
447
727
  return true;
448
728
  }
449
729
  if (parsedUrl.pathname === "/connections/discord" &&
450
730
  req.method === "DELETE") {
451
731
  void (async () => {
452
- const { handleDiscordDisconnect } = await import("./connectors/discord.js");
453
- const result = await handleDiscordDisconnect();
454
- res.writeHead(result.status, {
455
- "Content-Type": result.contentType ?? "application/json",
456
- });
457
- res.end(result.body);
732
+ try {
733
+ const { handleDiscordDisconnect } = await import("./connectors/discord.js");
734
+ const result = await handleDiscordDisconnect();
735
+ res.writeHead(result.status, {
736
+ "Content-Type": result.contentType ?? "application/json",
737
+ });
738
+ res.end(result.body);
739
+ }
740
+ catch (err) {
741
+ if (!res.headersSent) {
742
+ res.writeHead(500, { "Content-Type": "application/json" });
743
+ res.end(JSON.stringify({
744
+ error: err instanceof Error ? err.message : String(err),
745
+ }));
746
+ }
747
+ }
458
748
  })();
459
749
  return true;
460
750
  }
@@ -463,17 +753,27 @@ export function tryHandleConnectorRoute(req, res, parsedUrl) {
463
753
  parsedUrl.pathname === "/connections/asana/authorize") &&
464
754
  req.method === "GET") {
465
755
  void (async () => {
466
- const { handleAsanaAuthorize } = await import("./connectors/asana.js");
467
- const result = handleAsanaAuthorize();
468
- if (result.redirect) {
469
- res.writeHead(302, { Location: result.redirect });
470
- res.end();
756
+ try {
757
+ const { handleAsanaAuthorize } = await import("./connectors/asana.js");
758
+ const result = handleAsanaAuthorize();
759
+ if (result.redirect) {
760
+ res.writeHead(302, { Location: result.redirect });
761
+ res.end();
762
+ }
763
+ else {
764
+ res.writeHead(result.status, {
765
+ "Content-Type": result.contentType ?? "application/json",
766
+ });
767
+ res.end(result.body);
768
+ }
471
769
  }
472
- else {
473
- res.writeHead(result.status, {
474
- "Content-Type": result.contentType ?? "application/json",
475
- });
476
- res.end(result.body);
770
+ catch (err) {
771
+ if (!res.headersSent) {
772
+ res.writeHead(500, { "Content-Type": "application/json" });
773
+ res.end(JSON.stringify({
774
+ error: err instanceof Error ? err.message : String(err),
775
+ }));
776
+ }
477
777
  }
478
778
  })();
479
779
  return true;
@@ -481,38 +781,68 @@ export function tryHandleConnectorRoute(req, res, parsedUrl) {
481
781
  if (parsedUrl.pathname === "/connections/asana/callback" &&
482
782
  req.method === "GET") {
483
783
  void (async () => {
484
- const { handleAsanaCallback } = await import("./connectors/asana.js");
485
- const code = parsedUrl.searchParams.get("code");
486
- const state = parsedUrl.searchParams.get("state");
487
- const error = parsedUrl.searchParams.get("error");
488
- const result = await handleAsanaCallback(code, state, error);
489
- res.writeHead(result.status, {
490
- "Content-Type": result.contentType ?? "text/html",
491
- });
492
- res.end(result.body);
784
+ try {
785
+ const { handleAsanaCallback } = await import("./connectors/asana.js");
786
+ const code = parsedUrl.searchParams.get("code");
787
+ const state = parsedUrl.searchParams.get("state");
788
+ const error = parsedUrl.searchParams.get("error");
789
+ const result = await handleAsanaCallback(code, state, error);
790
+ res.writeHead(result.status, {
791
+ "Content-Type": result.contentType ?? "text/html",
792
+ });
793
+ res.end(result.body);
794
+ }
795
+ catch (err) {
796
+ if (!res.headersSent) {
797
+ res.writeHead(500, { "Content-Type": "application/json" });
798
+ res.end(JSON.stringify({
799
+ error: err instanceof Error ? err.message : String(err),
800
+ }));
801
+ }
802
+ }
493
803
  })();
494
804
  return true;
495
805
  }
496
806
  if (parsedUrl.pathname === "/connections/asana/test" &&
497
807
  req.method === "POST") {
498
808
  void (async () => {
499
- const { handleAsanaTest } = await import("./connectors/asana.js");
500
- const result = await handleAsanaTest();
501
- res.writeHead(result.status, {
502
- "Content-Type": result.contentType ?? "application/json",
503
- });
504
- res.end(result.body);
809
+ try {
810
+ const { handleAsanaTest } = await import("./connectors/asana.js");
811
+ const result = await handleAsanaTest();
812
+ res.writeHead(result.status, {
813
+ "Content-Type": result.contentType ?? "application/json",
814
+ });
815
+ res.end(result.body);
816
+ }
817
+ catch (err) {
818
+ if (!res.headersSent) {
819
+ res.writeHead(500, { "Content-Type": "application/json" });
820
+ res.end(JSON.stringify({
821
+ error: err instanceof Error ? err.message : String(err),
822
+ }));
823
+ }
824
+ }
505
825
  })();
506
826
  return true;
507
827
  }
508
828
  if (parsedUrl.pathname === "/connections/asana" && req.method === "DELETE") {
509
829
  void (async () => {
510
- const { handleAsanaDisconnect } = await import("./connectors/asana.js");
511
- const result = await handleAsanaDisconnect();
512
- res.writeHead(result.status, {
513
- "Content-Type": result.contentType ?? "application/json",
514
- });
515
- res.end(result.body);
830
+ try {
831
+ const { handleAsanaDisconnect } = await import("./connectors/asana.js");
832
+ const result = await handleAsanaDisconnect();
833
+ res.writeHead(result.status, {
834
+ "Content-Type": result.contentType ?? "application/json",
835
+ });
836
+ res.end(result.body);
837
+ }
838
+ catch (err) {
839
+ if (!res.headersSent) {
840
+ res.writeHead(500, { "Content-Type": "application/json" });
841
+ res.end(JSON.stringify({
842
+ error: err instanceof Error ? err.message : String(err),
843
+ }));
844
+ }
845
+ }
516
846
  })();
517
847
  return true;
518
848
  }
@@ -521,17 +851,27 @@ export function tryHandleConnectorRoute(req, res, parsedUrl) {
521
851
  parsedUrl.pathname === "/connections/gitlab/authorize") &&
522
852
  req.method === "GET") {
523
853
  void (async () => {
524
- const { handleGitLabAuthorize } = await import("./connectors/gitlab.js");
525
- const result = handleGitLabAuthorize();
526
- if (result.redirect) {
527
- res.writeHead(302, { Location: result.redirect });
528
- res.end();
854
+ try {
855
+ const { handleGitLabAuthorize } = await import("./connectors/gitlab.js");
856
+ const result = handleGitLabAuthorize();
857
+ if (result.redirect) {
858
+ res.writeHead(302, { Location: result.redirect });
859
+ res.end();
860
+ }
861
+ else {
862
+ res.writeHead(result.status, {
863
+ "Content-Type": result.contentType ?? "application/json",
864
+ });
865
+ res.end(result.body);
866
+ }
529
867
  }
530
- else {
531
- res.writeHead(result.status, {
532
- "Content-Type": result.contentType ?? "application/json",
533
- });
534
- res.end(result.body);
868
+ catch (err) {
869
+ if (!res.headersSent) {
870
+ res.writeHead(500, { "Content-Type": "application/json" });
871
+ res.end(JSON.stringify({
872
+ error: err instanceof Error ? err.message : String(err),
873
+ }));
874
+ }
535
875
  }
536
876
  })();
537
877
  return true;
@@ -539,38 +879,68 @@ export function tryHandleConnectorRoute(req, res, parsedUrl) {
539
879
  if (parsedUrl.pathname === "/connections/gitlab/callback" &&
540
880
  req.method === "GET") {
541
881
  void (async () => {
542
- const { handleGitLabCallback } = await import("./connectors/gitlab.js");
543
- const code = parsedUrl.searchParams.get("code");
544
- const state = parsedUrl.searchParams.get("state");
545
- const error = parsedUrl.searchParams.get("error");
546
- const result = await handleGitLabCallback(code, state, error);
547
- res.writeHead(result.status, {
548
- "Content-Type": result.contentType ?? "text/html",
549
- });
550
- res.end(result.body);
882
+ try {
883
+ const { handleGitLabCallback } = await import("./connectors/gitlab.js");
884
+ const code = parsedUrl.searchParams.get("code");
885
+ const state = parsedUrl.searchParams.get("state");
886
+ const error = parsedUrl.searchParams.get("error");
887
+ const result = await handleGitLabCallback(code, state, error);
888
+ res.writeHead(result.status, {
889
+ "Content-Type": result.contentType ?? "text/html",
890
+ });
891
+ res.end(result.body);
892
+ }
893
+ catch (err) {
894
+ if (!res.headersSent) {
895
+ res.writeHead(500, { "Content-Type": "application/json" });
896
+ res.end(JSON.stringify({
897
+ error: err instanceof Error ? err.message : String(err),
898
+ }));
899
+ }
900
+ }
551
901
  })();
552
902
  return true;
553
903
  }
554
904
  if (parsedUrl.pathname === "/connections/gitlab/test" &&
555
905
  req.method === "POST") {
556
906
  void (async () => {
557
- const { handleGitLabTest } = await import("./connectors/gitlab.js");
558
- const result = await handleGitLabTest();
559
- res.writeHead(result.status, {
560
- "Content-Type": result.contentType ?? "application/json",
561
- });
562
- res.end(result.body);
907
+ try {
908
+ const { handleGitLabTest } = await import("./connectors/gitlab.js");
909
+ const result = await handleGitLabTest();
910
+ res.writeHead(result.status, {
911
+ "Content-Type": result.contentType ?? "application/json",
912
+ });
913
+ res.end(result.body);
914
+ }
915
+ catch (err) {
916
+ if (!res.headersSent) {
917
+ res.writeHead(500, { "Content-Type": "application/json" });
918
+ res.end(JSON.stringify({
919
+ error: err instanceof Error ? err.message : String(err),
920
+ }));
921
+ }
922
+ }
563
923
  })();
564
924
  return true;
565
925
  }
566
926
  if (parsedUrl.pathname === "/connections/gitlab" && req.method === "DELETE") {
567
927
  void (async () => {
568
- const { handleGitLabDisconnect } = await import("./connectors/gitlab.js");
569
- const result = await handleGitLabDisconnect();
570
- res.writeHead(result.status, {
571
- "Content-Type": result.contentType ?? "application/json",
572
- });
573
- res.end(result.body);
928
+ try {
929
+ const { handleGitLabDisconnect } = await import("./connectors/gitlab.js");
930
+ const result = await handleGitLabDisconnect();
931
+ res.writeHead(result.status, {
932
+ "Content-Type": result.contentType ?? "application/json",
933
+ });
934
+ res.end(result.body);
935
+ }
936
+ catch (err) {
937
+ if (!res.headersSent) {
938
+ res.writeHead(500, { "Content-Type": "application/json" });
939
+ res.end(JSON.stringify({
940
+ error: err instanceof Error ? err.message : String(err),
941
+ }));
942
+ }
943
+ }
574
944
  })();
575
945
  return true;
576
946
  }
@@ -581,12 +951,22 @@ export function tryHandleConnectorRoute(req, res, parsedUrl) {
581
951
  req.on("data", (c) => chunks.push(c));
582
952
  req.on("end", () => {
583
953
  void (async () => {
584
- const { handleNotionConnect } = await import("./connectors/notion.js");
585
- const result = await handleNotionConnect(Buffer.concat(chunks).toString("utf-8"));
586
- res.writeHead(result.status, {
587
- "Content-Type": result.contentType ?? "application/json",
588
- });
589
- res.end(result.body);
954
+ try {
955
+ const { handleNotionConnect } = await import("./connectors/notion.js");
956
+ const result = await handleNotionConnect(Buffer.concat(chunks).toString("utf-8"));
957
+ res.writeHead(result.status, {
958
+ "Content-Type": result.contentType ?? "application/json",
959
+ });
960
+ res.end(result.body);
961
+ }
962
+ catch (err) {
963
+ if (!res.headersSent) {
964
+ res.writeHead(500, { "Content-Type": "application/json" });
965
+ res.end(JSON.stringify({
966
+ error: err instanceof Error ? err.message : String(err),
967
+ }));
968
+ }
969
+ }
590
970
  })();
591
971
  });
592
972
  return true;
@@ -594,23 +974,43 @@ export function tryHandleConnectorRoute(req, res, parsedUrl) {
594
974
  if (parsedUrl.pathname === "/connections/notion/test" &&
595
975
  req.method === "POST") {
596
976
  void (async () => {
597
- const { handleNotionTest } = await import("./connectors/notion.js");
598
- const result = await handleNotionTest();
599
- res.writeHead(result.status, {
600
- "Content-Type": result.contentType ?? "application/json",
601
- });
602
- res.end(result.body);
977
+ try {
978
+ const { handleNotionTest } = await import("./connectors/notion.js");
979
+ const result = await handleNotionTest();
980
+ res.writeHead(result.status, {
981
+ "Content-Type": result.contentType ?? "application/json",
982
+ });
983
+ res.end(result.body);
984
+ }
985
+ catch (err) {
986
+ if (!res.headersSent) {
987
+ res.writeHead(500, { "Content-Type": "application/json" });
988
+ res.end(JSON.stringify({
989
+ error: err instanceof Error ? err.message : String(err),
990
+ }));
991
+ }
992
+ }
603
993
  })();
604
994
  return true;
605
995
  }
606
996
  if (parsedUrl.pathname === "/connections/notion" && req.method === "DELETE") {
607
997
  void (async () => {
608
- const { handleNotionDisconnect } = await import("./connectors/notion.js");
609
- const result = handleNotionDisconnect();
610
- res.writeHead(result.status, {
611
- "Content-Type": result.contentType ?? "application/json",
612
- });
613
- res.end(result.body);
998
+ try {
999
+ const { handleNotionDisconnect } = await import("./connectors/notion.js");
1000
+ const result = handleNotionDisconnect();
1001
+ res.writeHead(result.status, {
1002
+ "Content-Type": result.contentType ?? "application/json",
1003
+ });
1004
+ res.end(result.body);
1005
+ }
1006
+ catch (err) {
1007
+ if (!res.headersSent) {
1008
+ res.writeHead(500, { "Content-Type": "application/json" });
1009
+ res.end(JSON.stringify({
1010
+ error: err instanceof Error ? err.message : String(err),
1011
+ }));
1012
+ }
1013
+ }
614
1014
  })();
615
1015
  return true;
616
1016
  }
@@ -621,12 +1021,22 @@ export function tryHandleConnectorRoute(req, res, parsedUrl) {
621
1021
  req.on("data", (c) => chunks.push(c));
622
1022
  req.on("end", () => {
623
1023
  void (async () => {
624
- const { handleConfluenceConnect } = await import("./connectors/confluence.js");
625
- const result = await handleConfluenceConnect(Buffer.concat(chunks).toString("utf-8"));
626
- res.writeHead(result.status, {
627
- "Content-Type": result.contentType ?? "application/json",
628
- });
629
- res.end(result.body);
1024
+ try {
1025
+ const { handleConfluenceConnect } = await import("./connectors/confluence.js");
1026
+ const result = await handleConfluenceConnect(Buffer.concat(chunks).toString("utf-8"));
1027
+ res.writeHead(result.status, {
1028
+ "Content-Type": result.contentType ?? "application/json",
1029
+ });
1030
+ res.end(result.body);
1031
+ }
1032
+ catch (err) {
1033
+ if (!res.headersSent) {
1034
+ res.writeHead(500, { "Content-Type": "application/json" });
1035
+ res.end(JSON.stringify({
1036
+ error: err instanceof Error ? err.message : String(err),
1037
+ }));
1038
+ }
1039
+ }
630
1040
  })();
631
1041
  });
632
1042
  return true;
@@ -634,24 +1044,44 @@ export function tryHandleConnectorRoute(req, res, parsedUrl) {
634
1044
  if (parsedUrl.pathname === "/connections/confluence/test" &&
635
1045
  req.method === "POST") {
636
1046
  void (async () => {
637
- const { handleConfluenceTest } = await import("./connectors/confluence.js");
638
- const result = await handleConfluenceTest();
639
- res.writeHead(result.status, {
640
- "Content-Type": result.contentType ?? "application/json",
641
- });
642
- res.end(result.body);
1047
+ try {
1048
+ const { handleConfluenceTest } = await import("./connectors/confluence.js");
1049
+ const result = await handleConfluenceTest();
1050
+ res.writeHead(result.status, {
1051
+ "Content-Type": result.contentType ?? "application/json",
1052
+ });
1053
+ res.end(result.body);
1054
+ }
1055
+ catch (err) {
1056
+ if (!res.headersSent) {
1057
+ res.writeHead(500, { "Content-Type": "application/json" });
1058
+ res.end(JSON.stringify({
1059
+ error: err instanceof Error ? err.message : String(err),
1060
+ }));
1061
+ }
1062
+ }
643
1063
  })();
644
1064
  return true;
645
1065
  }
646
1066
  if (parsedUrl.pathname === "/connections/confluence" &&
647
1067
  req.method === "DELETE") {
648
1068
  void (async () => {
649
- const { handleConfluenceDisconnect } = await import("./connectors/confluence.js");
650
- const result = handleConfluenceDisconnect();
651
- res.writeHead(result.status, {
652
- "Content-Type": result.contentType ?? "application/json",
653
- });
654
- res.end(result.body);
1069
+ try {
1070
+ const { handleConfluenceDisconnect } = await import("./connectors/confluence.js");
1071
+ const result = handleConfluenceDisconnect();
1072
+ res.writeHead(result.status, {
1073
+ "Content-Type": result.contentType ?? "application/json",
1074
+ });
1075
+ res.end(result.body);
1076
+ }
1077
+ catch (err) {
1078
+ if (!res.headersSent) {
1079
+ res.writeHead(500, { "Content-Type": "application/json" });
1080
+ res.end(JSON.stringify({
1081
+ error: err instanceof Error ? err.message : String(err),
1082
+ }));
1083
+ }
1084
+ }
655
1085
  })();
656
1086
  return true;
657
1087
  }
@@ -662,12 +1092,22 @@ export function tryHandleConnectorRoute(req, res, parsedUrl) {
662
1092
  req.on("data", (c) => chunks.push(c));
663
1093
  req.on("end", () => {
664
1094
  void (async () => {
665
- const { handleZendeskConnect } = await import("./connectors/zendesk.js");
666
- const result = await handleZendeskConnect(Buffer.concat(chunks).toString("utf-8"));
667
- res.writeHead(result.status, {
668
- "Content-Type": result.contentType ?? "application/json",
669
- });
670
- res.end(result.body);
1095
+ try {
1096
+ const { handleZendeskConnect } = await import("./connectors/zendesk.js");
1097
+ const result = await handleZendeskConnect(Buffer.concat(chunks).toString("utf-8"));
1098
+ res.writeHead(result.status, {
1099
+ "Content-Type": result.contentType ?? "application/json",
1100
+ });
1101
+ res.end(result.body);
1102
+ }
1103
+ catch (err) {
1104
+ if (!res.headersSent) {
1105
+ res.writeHead(500, { "Content-Type": "application/json" });
1106
+ res.end(JSON.stringify({
1107
+ error: err instanceof Error ? err.message : String(err),
1108
+ }));
1109
+ }
1110
+ }
671
1111
  })();
672
1112
  });
673
1113
  return true;
@@ -675,24 +1115,44 @@ export function tryHandleConnectorRoute(req, res, parsedUrl) {
675
1115
  if (parsedUrl.pathname === "/connections/zendesk/test" &&
676
1116
  req.method === "POST") {
677
1117
  void (async () => {
678
- const { handleZendeskTest } = await import("./connectors/zendesk.js");
679
- const result = await handleZendeskTest();
680
- res.writeHead(result.status, {
681
- "Content-Type": result.contentType ?? "application/json",
682
- });
683
- res.end(result.body);
1118
+ try {
1119
+ const { handleZendeskTest } = await import("./connectors/zendesk.js");
1120
+ const result = await handleZendeskTest();
1121
+ res.writeHead(result.status, {
1122
+ "Content-Type": result.contentType ?? "application/json",
1123
+ });
1124
+ res.end(result.body);
1125
+ }
1126
+ catch (err) {
1127
+ if (!res.headersSent) {
1128
+ res.writeHead(500, { "Content-Type": "application/json" });
1129
+ res.end(JSON.stringify({
1130
+ error: err instanceof Error ? err.message : String(err),
1131
+ }));
1132
+ }
1133
+ }
684
1134
  })();
685
1135
  return true;
686
1136
  }
687
1137
  if (parsedUrl.pathname === "/connections/zendesk" &&
688
1138
  req.method === "DELETE") {
689
1139
  void (async () => {
690
- const { handleZendeskDisconnect } = await import("./connectors/zendesk.js");
691
- const result = handleZendeskDisconnect();
692
- res.writeHead(result.status, {
693
- "Content-Type": result.contentType ?? "application/json",
694
- });
695
- res.end(result.body);
1140
+ try {
1141
+ const { handleZendeskDisconnect } = await import("./connectors/zendesk.js");
1142
+ const result = handleZendeskDisconnect();
1143
+ res.writeHead(result.status, {
1144
+ "Content-Type": result.contentType ?? "application/json",
1145
+ });
1146
+ res.end(result.body);
1147
+ }
1148
+ catch (err) {
1149
+ if (!res.headersSent) {
1150
+ res.writeHead(500, { "Content-Type": "application/json" });
1151
+ res.end(JSON.stringify({
1152
+ error: err instanceof Error ? err.message : String(err),
1153
+ }));
1154
+ }
1155
+ }
696
1156
  })();
697
1157
  return true;
698
1158
  }
@@ -703,12 +1163,22 @@ export function tryHandleConnectorRoute(req, res, parsedUrl) {
703
1163
  req.on("data", (c) => chunks.push(c));
704
1164
  req.on("end", () => {
705
1165
  void (async () => {
706
- const { handleIntercomConnect } = await import("./connectors/intercom.js");
707
- const result = await handleIntercomConnect(Buffer.concat(chunks).toString("utf-8"));
708
- res.writeHead(result.status, {
709
- "Content-Type": result.contentType ?? "application/json",
710
- });
711
- res.end(result.body);
1166
+ try {
1167
+ const { handleIntercomConnect } = await import("./connectors/intercom.js");
1168
+ const result = await handleIntercomConnect(Buffer.concat(chunks).toString("utf-8"));
1169
+ res.writeHead(result.status, {
1170
+ "Content-Type": result.contentType ?? "application/json",
1171
+ });
1172
+ res.end(result.body);
1173
+ }
1174
+ catch (err) {
1175
+ if (!res.headersSent) {
1176
+ res.writeHead(500, { "Content-Type": "application/json" });
1177
+ res.end(JSON.stringify({
1178
+ error: err instanceof Error ? err.message : String(err),
1179
+ }));
1180
+ }
1181
+ }
712
1182
  })();
713
1183
  });
714
1184
  return true;
@@ -716,24 +1186,44 @@ export function tryHandleConnectorRoute(req, res, parsedUrl) {
716
1186
  if (parsedUrl.pathname === "/connections/intercom/test" &&
717
1187
  req.method === "POST") {
718
1188
  void (async () => {
719
- const { handleIntercomTest } = await import("./connectors/intercom.js");
720
- const result = await handleIntercomTest();
721
- res.writeHead(result.status, {
722
- "Content-Type": result.contentType ?? "application/json",
723
- });
724
- res.end(result.body);
1189
+ try {
1190
+ const { handleIntercomTest } = await import("./connectors/intercom.js");
1191
+ const result = await handleIntercomTest();
1192
+ res.writeHead(result.status, {
1193
+ "Content-Type": result.contentType ?? "application/json",
1194
+ });
1195
+ res.end(result.body);
1196
+ }
1197
+ catch (err) {
1198
+ if (!res.headersSent) {
1199
+ res.writeHead(500, { "Content-Type": "application/json" });
1200
+ res.end(JSON.stringify({
1201
+ error: err instanceof Error ? err.message : String(err),
1202
+ }));
1203
+ }
1204
+ }
725
1205
  })();
726
1206
  return true;
727
1207
  }
728
1208
  if (parsedUrl.pathname === "/connections/intercom" &&
729
1209
  req.method === "DELETE") {
730
1210
  void (async () => {
731
- const { handleIntercomDisconnect } = await import("./connectors/intercom.js");
732
- const result = handleIntercomDisconnect();
733
- res.writeHead(result.status, {
734
- "Content-Type": result.contentType ?? "application/json",
735
- });
736
- res.end(result.body);
1211
+ try {
1212
+ const { handleIntercomDisconnect } = await import("./connectors/intercom.js");
1213
+ const result = handleIntercomDisconnect();
1214
+ res.writeHead(result.status, {
1215
+ "Content-Type": result.contentType ?? "application/json",
1216
+ });
1217
+ res.end(result.body);
1218
+ }
1219
+ catch (err) {
1220
+ if (!res.headersSent) {
1221
+ res.writeHead(500, { "Content-Type": "application/json" });
1222
+ res.end(JSON.stringify({
1223
+ error: err instanceof Error ? err.message : String(err),
1224
+ }));
1225
+ }
1226
+ }
737
1227
  })();
738
1228
  return true;
739
1229
  }
@@ -744,12 +1234,22 @@ export function tryHandleConnectorRoute(req, res, parsedUrl) {
744
1234
  req.on("data", (c) => chunks.push(c));
745
1235
  req.on("end", () => {
746
1236
  void (async () => {
747
- const { handleHubSpotConnect } = await import("./connectors/hubspot.js");
748
- const result = await handleHubSpotConnect(Buffer.concat(chunks).toString("utf-8"));
749
- res.writeHead(result.status, {
750
- "Content-Type": result.contentType ?? "application/json",
751
- });
752
- res.end(result.body);
1237
+ try {
1238
+ const { handleHubSpotConnect } = await import("./connectors/hubspot.js");
1239
+ const result = await handleHubSpotConnect(Buffer.concat(chunks).toString("utf-8"));
1240
+ res.writeHead(result.status, {
1241
+ "Content-Type": result.contentType ?? "application/json",
1242
+ });
1243
+ res.end(result.body);
1244
+ }
1245
+ catch (err) {
1246
+ if (!res.headersSent) {
1247
+ res.writeHead(500, { "Content-Type": "application/json" });
1248
+ res.end(JSON.stringify({
1249
+ error: err instanceof Error ? err.message : String(err),
1250
+ }));
1251
+ }
1252
+ }
753
1253
  })();
754
1254
  });
755
1255
  return true;
@@ -757,24 +1257,44 @@ export function tryHandleConnectorRoute(req, res, parsedUrl) {
757
1257
  if (parsedUrl.pathname === "/connections/hubspot/test" &&
758
1258
  req.method === "POST") {
759
1259
  void (async () => {
760
- const { handleHubSpotTest } = await import("./connectors/hubspot.js");
761
- const result = await handleHubSpotTest();
762
- res.writeHead(result.status, {
763
- "Content-Type": result.contentType ?? "application/json",
764
- });
765
- res.end(result.body);
1260
+ try {
1261
+ const { handleHubSpotTest } = await import("./connectors/hubspot.js");
1262
+ const result = await handleHubSpotTest();
1263
+ res.writeHead(result.status, {
1264
+ "Content-Type": result.contentType ?? "application/json",
1265
+ });
1266
+ res.end(result.body);
1267
+ }
1268
+ catch (err) {
1269
+ if (!res.headersSent) {
1270
+ res.writeHead(500, { "Content-Type": "application/json" });
1271
+ res.end(JSON.stringify({
1272
+ error: err instanceof Error ? err.message : String(err),
1273
+ }));
1274
+ }
1275
+ }
766
1276
  })();
767
1277
  return true;
768
1278
  }
769
1279
  if (parsedUrl.pathname === "/connections/hubspot" &&
770
1280
  req.method === "DELETE") {
771
1281
  void (async () => {
772
- const { handleHubSpotDisconnect } = await import("./connectors/hubspot.js");
773
- const result = handleHubSpotDisconnect();
774
- res.writeHead(result.status, {
775
- "Content-Type": result.contentType ?? "application/json",
776
- });
777
- res.end(result.body);
1282
+ try {
1283
+ const { handleHubSpotDisconnect } = await import("./connectors/hubspot.js");
1284
+ const result = handleHubSpotDisconnect();
1285
+ res.writeHead(result.status, {
1286
+ "Content-Type": result.contentType ?? "application/json",
1287
+ });
1288
+ res.end(result.body);
1289
+ }
1290
+ catch (err) {
1291
+ if (!res.headersSent) {
1292
+ res.writeHead(500, { "Content-Type": "application/json" });
1293
+ res.end(JSON.stringify({
1294
+ error: err instanceof Error ? err.message : String(err),
1295
+ }));
1296
+ }
1297
+ }
778
1298
  })();
779
1299
  return true;
780
1300
  }
@@ -785,12 +1305,22 @@ export function tryHandleConnectorRoute(req, res, parsedUrl) {
785
1305
  req.on("data", (c) => chunks.push(c));
786
1306
  req.on("end", () => {
787
1307
  void (async () => {
788
- const { handleDatadogConnect } = await import("./connectors/datadog.js");
789
- const result = await handleDatadogConnect(Buffer.concat(chunks).toString("utf-8"));
790
- res.writeHead(result.status, {
791
- "Content-Type": result.contentType ?? "application/json",
792
- });
793
- res.end(result.body);
1308
+ try {
1309
+ const { handleDatadogConnect } = await import("./connectors/datadog.js");
1310
+ const result = await handleDatadogConnect(Buffer.concat(chunks).toString("utf-8"));
1311
+ res.writeHead(result.status, {
1312
+ "Content-Type": result.contentType ?? "application/json",
1313
+ });
1314
+ res.end(result.body);
1315
+ }
1316
+ catch (err) {
1317
+ if (!res.headersSent) {
1318
+ res.writeHead(500, { "Content-Type": "application/json" });
1319
+ res.end(JSON.stringify({
1320
+ error: err instanceof Error ? err.message : String(err),
1321
+ }));
1322
+ }
1323
+ }
794
1324
  })();
795
1325
  });
796
1326
  return true;
@@ -798,24 +1328,44 @@ export function tryHandleConnectorRoute(req, res, parsedUrl) {
798
1328
  if (parsedUrl.pathname === "/connections/datadog/test" &&
799
1329
  req.method === "POST") {
800
1330
  void (async () => {
801
- const { handleDatadogTest } = await import("./connectors/datadog.js");
802
- const result = await handleDatadogTest();
803
- res.writeHead(result.status, {
804
- "Content-Type": result.contentType ?? "application/json",
805
- });
806
- res.end(result.body);
1331
+ try {
1332
+ const { handleDatadogTest } = await import("./connectors/datadog.js");
1333
+ const result = await handleDatadogTest();
1334
+ res.writeHead(result.status, {
1335
+ "Content-Type": result.contentType ?? "application/json",
1336
+ });
1337
+ res.end(result.body);
1338
+ }
1339
+ catch (err) {
1340
+ if (!res.headersSent) {
1341
+ res.writeHead(500, { "Content-Type": "application/json" });
1342
+ res.end(JSON.stringify({
1343
+ error: err instanceof Error ? err.message : String(err),
1344
+ }));
1345
+ }
1346
+ }
807
1347
  })();
808
1348
  return true;
809
1349
  }
810
1350
  if (parsedUrl.pathname === "/connections/datadog" &&
811
1351
  req.method === "DELETE") {
812
1352
  void (async () => {
813
- const { handleDatadogDisconnect } = await import("./connectors/datadog.js");
814
- const result = handleDatadogDisconnect();
815
- res.writeHead(result.status, {
816
- "Content-Type": result.contentType ?? "application/json",
817
- });
818
- res.end(result.body);
1353
+ try {
1354
+ const { handleDatadogDisconnect } = await import("./connectors/datadog.js");
1355
+ const result = handleDatadogDisconnect();
1356
+ res.writeHead(result.status, {
1357
+ "Content-Type": result.contentType ?? "application/json",
1358
+ });
1359
+ res.end(result.body);
1360
+ }
1361
+ catch (err) {
1362
+ if (!res.headersSent) {
1363
+ res.writeHead(500, { "Content-Type": "application/json" });
1364
+ res.end(JSON.stringify({
1365
+ error: err instanceof Error ? err.message : String(err),
1366
+ }));
1367
+ }
1368
+ }
819
1369
  })();
820
1370
  return true;
821
1371
  }
@@ -826,12 +1376,22 @@ export function tryHandleConnectorRoute(req, res, parsedUrl) {
826
1376
  req.on("data", (c) => chunks.push(c));
827
1377
  req.on("end", () => {
828
1378
  void (async () => {
829
- const { handlePagerDutyConnect } = await import("./connectors/pagerduty.js");
830
- const result = await handlePagerDutyConnect(Buffer.concat(chunks).toString("utf-8"));
831
- res.writeHead(result.status, {
832
- "Content-Type": result.contentType ?? "application/json",
833
- });
834
- res.end(result.body);
1379
+ try {
1380
+ const { handlePagerDutyConnect } = await import("./connectors/pagerduty.js");
1381
+ const result = await handlePagerDutyConnect(Buffer.concat(chunks).toString("utf-8"));
1382
+ res.writeHead(result.status, {
1383
+ "Content-Type": result.contentType ?? "application/json",
1384
+ });
1385
+ res.end(result.body);
1386
+ }
1387
+ catch (err) {
1388
+ if (!res.headersSent) {
1389
+ res.writeHead(500, { "Content-Type": "application/json" });
1390
+ res.end(JSON.stringify({
1391
+ error: err instanceof Error ? err.message : String(err),
1392
+ }));
1393
+ }
1394
+ }
835
1395
  })();
836
1396
  });
837
1397
  return true;
@@ -839,24 +1399,44 @@ export function tryHandleConnectorRoute(req, res, parsedUrl) {
839
1399
  if (parsedUrl.pathname === "/connections/pagerduty/test" &&
840
1400
  req.method === "POST") {
841
1401
  void (async () => {
842
- const { handlePagerDutyTest } = await import("./connectors/pagerduty.js");
843
- const result = await handlePagerDutyTest();
844
- res.writeHead(result.status, {
845
- "Content-Type": result.contentType ?? "application/json",
846
- });
847
- res.end(result.body);
1402
+ try {
1403
+ const { handlePagerDutyTest } = await import("./connectors/pagerduty.js");
1404
+ const result = await handlePagerDutyTest();
1405
+ res.writeHead(result.status, {
1406
+ "Content-Type": result.contentType ?? "application/json",
1407
+ });
1408
+ res.end(result.body);
1409
+ }
1410
+ catch (err) {
1411
+ if (!res.headersSent) {
1412
+ res.writeHead(500, { "Content-Type": "application/json" });
1413
+ res.end(JSON.stringify({
1414
+ error: err instanceof Error ? err.message : String(err),
1415
+ }));
1416
+ }
1417
+ }
848
1418
  })();
849
1419
  return true;
850
1420
  }
851
1421
  if (parsedUrl.pathname === "/connections/pagerduty" &&
852
1422
  req.method === "DELETE") {
853
1423
  void (async () => {
854
- const { handlePagerDutyDisconnect } = await import("./connectors/pagerduty.js");
855
- const result = handlePagerDutyDisconnect();
856
- res.writeHead(result.status, {
857
- "Content-Type": result.contentType ?? "application/json",
858
- });
859
- res.end(result.body);
1424
+ try {
1425
+ const { handlePagerDutyDisconnect } = await import("./connectors/pagerduty.js");
1426
+ const result = handlePagerDutyDisconnect();
1427
+ res.writeHead(result.status, {
1428
+ "Content-Type": result.contentType ?? "application/json",
1429
+ });
1430
+ res.end(result.body);
1431
+ }
1432
+ catch (err) {
1433
+ if (!res.headersSent) {
1434
+ res.writeHead(500, { "Content-Type": "application/json" });
1435
+ res.end(JSON.stringify({
1436
+ error: err instanceof Error ? err.message : String(err),
1437
+ }));
1438
+ }
1439
+ }
860
1440
  })();
861
1441
  return true;
862
1442
  }
@@ -869,12 +1449,22 @@ export function tryHandleConnectorRoute(req, res, parsedUrl) {
869
1449
  });
870
1450
  req.on("end", () => {
871
1451
  void (async () => {
872
- const { handleStripeConnect } = await import("./connectors/stripe.js");
873
- const result = await handleStripeConnect(body);
874
- res.writeHead(result.status, {
875
- "Content-Type": result.contentType ?? "application/json",
876
- });
877
- res.end(result.body);
1452
+ try {
1453
+ const { handleStripeConnect } = await import("./connectors/stripe.js");
1454
+ const result = await handleStripeConnect(body);
1455
+ res.writeHead(result.status, {
1456
+ "Content-Type": result.contentType ?? "application/json",
1457
+ });
1458
+ res.end(result.body);
1459
+ }
1460
+ catch (err) {
1461
+ if (!res.headersSent) {
1462
+ res.writeHead(500, { "Content-Type": "application/json" });
1463
+ res.end(JSON.stringify({
1464
+ error: err instanceof Error ? err.message : String(err),
1465
+ }));
1466
+ }
1467
+ }
878
1468
  })();
879
1469
  });
880
1470
  return true;
@@ -882,23 +1472,43 @@ export function tryHandleConnectorRoute(req, res, parsedUrl) {
882
1472
  if (parsedUrl.pathname === "/connections/stripe/test" &&
883
1473
  req.method === "POST") {
884
1474
  void (async () => {
885
- const { handleStripeTest } = await import("./connectors/stripe.js");
886
- const result = await handleStripeTest();
887
- res.writeHead(result.status, {
888
- "Content-Type": result.contentType ?? "application/json",
889
- });
890
- res.end(result.body);
1475
+ try {
1476
+ const { handleStripeTest } = await import("./connectors/stripe.js");
1477
+ const result = await handleStripeTest();
1478
+ res.writeHead(result.status, {
1479
+ "Content-Type": result.contentType ?? "application/json",
1480
+ });
1481
+ res.end(result.body);
1482
+ }
1483
+ catch (err) {
1484
+ if (!res.headersSent) {
1485
+ res.writeHead(500, { "Content-Type": "application/json" });
1486
+ res.end(JSON.stringify({
1487
+ error: err instanceof Error ? err.message : String(err),
1488
+ }));
1489
+ }
1490
+ }
891
1491
  })();
892
1492
  return true;
893
1493
  }
894
1494
  if (parsedUrl.pathname === "/connections/stripe" && req.method === "DELETE") {
895
1495
  void (async () => {
896
- const { handleStripeDisconnect } = await import("./connectors/stripe.js");
897
- const result = handleStripeDisconnect();
898
- res.writeHead(result.status, {
899
- "Content-Type": result.contentType ?? "application/json",
900
- });
901
- res.end(result.body);
1496
+ try {
1497
+ const { handleStripeDisconnect } = await import("./connectors/stripe.js");
1498
+ const result = handleStripeDisconnect();
1499
+ res.writeHead(result.status, {
1500
+ "Content-Type": result.contentType ?? "application/json",
1501
+ });
1502
+ res.end(result.body);
1503
+ }
1504
+ catch (err) {
1505
+ if (!res.headersSent) {
1506
+ res.writeHead(500, { "Content-Type": "application/json" });
1507
+ res.end(JSON.stringify({
1508
+ error: err instanceof Error ? err.message : String(err),
1509
+ }));
1510
+ }
1511
+ }
902
1512
  })();
903
1513
  return true;
904
1514
  }
@@ -906,17 +1516,27 @@ export function tryHandleConnectorRoute(req, res, parsedUrl) {
906
1516
  if (parsedUrl.pathname === "/connections/google-calendar/auth" &&
907
1517
  req.method === "GET") {
908
1518
  void (async () => {
909
- const { handleCalendarAuthRedirect } = await import("./connectors/googleCalendar.js");
910
- const result = handleCalendarAuthRedirect();
911
- if (result.redirect) {
912
- res.writeHead(302, { Location: result.redirect });
913
- res.end();
1519
+ try {
1520
+ const { handleCalendarAuthRedirect } = await import("./connectors/googleCalendar.js");
1521
+ const result = handleCalendarAuthRedirect();
1522
+ if (result.redirect) {
1523
+ res.writeHead(302, { Location: result.redirect });
1524
+ res.end();
1525
+ }
1526
+ else {
1527
+ res.writeHead(result.status, {
1528
+ "Content-Type": result.contentType ?? "application/json",
1529
+ });
1530
+ res.end(result.body);
1531
+ }
914
1532
  }
915
- else {
916
- res.writeHead(result.status, {
917
- "Content-Type": result.contentType ?? "application/json",
918
- });
919
- res.end(result.body);
1533
+ catch (err) {
1534
+ if (!res.headersSent) {
1535
+ res.writeHead(500, { "Content-Type": "application/json" });
1536
+ res.end(JSON.stringify({
1537
+ error: err instanceof Error ? err.message : String(err),
1538
+ }));
1539
+ }
920
1540
  }
921
1541
  })();
922
1542
  return true;
@@ -924,39 +1544,69 @@ export function tryHandleConnectorRoute(req, res, parsedUrl) {
924
1544
  if (parsedUrl.pathname === "/connections/google-calendar/callback" &&
925
1545
  req.method === "GET") {
926
1546
  void (async () => {
927
- const { handleCalendarCallback } = await import("./connectors/googleCalendar.js");
928
- const code = parsedUrl.searchParams.get("code");
929
- const state = parsedUrl.searchParams.get("state");
930
- const error = parsedUrl.searchParams.get("error");
931
- const result = await handleCalendarCallback(code, state, error);
932
- res.writeHead(result.status, {
933
- "Content-Type": result.contentType ?? "application/json",
934
- });
935
- res.end(result.body);
1547
+ try {
1548
+ const { handleCalendarCallback } = await import("./connectors/googleCalendar.js");
1549
+ const code = parsedUrl.searchParams.get("code");
1550
+ const state = parsedUrl.searchParams.get("state");
1551
+ const error = parsedUrl.searchParams.get("error");
1552
+ const result = await handleCalendarCallback(code, state, error);
1553
+ res.writeHead(result.status, {
1554
+ "Content-Type": result.contentType ?? "application/json",
1555
+ });
1556
+ res.end(result.body);
1557
+ }
1558
+ catch (err) {
1559
+ if (!res.headersSent) {
1560
+ res.writeHead(500, { "Content-Type": "application/json" });
1561
+ res.end(JSON.stringify({
1562
+ error: err instanceof Error ? err.message : String(err),
1563
+ }));
1564
+ }
1565
+ }
936
1566
  })();
937
1567
  return true;
938
1568
  }
939
1569
  if (parsedUrl.pathname === "/connections/google-calendar/test" &&
940
1570
  req.method === "POST") {
941
1571
  void (async () => {
942
- const { handleCalendarTest } = await import("./connectors/googleCalendar.js");
943
- const result = await handleCalendarTest();
944
- res.writeHead(result.status, {
945
- "Content-Type": result.contentType ?? "application/json",
946
- });
947
- res.end(result.body);
1572
+ try {
1573
+ const { handleCalendarTest } = await import("./connectors/googleCalendar.js");
1574
+ const result = await handleCalendarTest();
1575
+ res.writeHead(result.status, {
1576
+ "Content-Type": result.contentType ?? "application/json",
1577
+ });
1578
+ res.end(result.body);
1579
+ }
1580
+ catch (err) {
1581
+ if (!res.headersSent) {
1582
+ res.writeHead(500, { "Content-Type": "application/json" });
1583
+ res.end(JSON.stringify({
1584
+ error: err instanceof Error ? err.message : String(err),
1585
+ }));
1586
+ }
1587
+ }
948
1588
  })();
949
1589
  return true;
950
1590
  }
951
1591
  if (parsedUrl.pathname === "/connections/google-calendar" &&
952
1592
  req.method === "DELETE") {
953
1593
  void (async () => {
954
- const { handleCalendarDisconnect } = await import("./connectors/googleCalendar.js");
955
- const result = await handleCalendarDisconnect();
956
- res.writeHead(result.status, {
957
- "Content-Type": result.contentType ?? "application/json",
958
- });
959
- res.end(result.body);
1594
+ try {
1595
+ const { handleCalendarDisconnect } = await import("./connectors/googleCalendar.js");
1596
+ const result = await handleCalendarDisconnect();
1597
+ res.writeHead(result.status, {
1598
+ "Content-Type": result.contentType ?? "application/json",
1599
+ });
1600
+ res.end(result.body);
1601
+ }
1602
+ catch (err) {
1603
+ if (!res.headersSent) {
1604
+ res.writeHead(500, { "Content-Type": "application/json" });
1605
+ res.end(JSON.stringify({
1606
+ error: err instanceof Error ? err.message : String(err),
1607
+ }));
1608
+ }
1609
+ }
960
1610
  })();
961
1611
  return true;
962
1612
  }
@@ -964,17 +1614,27 @@ export function tryHandleConnectorRoute(req, res, parsedUrl) {
964
1614
  if (parsedUrl.pathname === "/connections/google-drive/auth" &&
965
1615
  req.method === "GET") {
966
1616
  void (async () => {
967
- const { handleDriveAuthRedirect } = await import("./connectors/googleDrive.js");
968
- const result = handleDriveAuthRedirect();
969
- if (result.redirect) {
970
- res.writeHead(302, { Location: result.redirect });
971
- res.end();
1617
+ try {
1618
+ const { handleDriveAuthRedirect } = await import("./connectors/googleDrive.js");
1619
+ const result = handleDriveAuthRedirect();
1620
+ if (result.redirect) {
1621
+ res.writeHead(302, { Location: result.redirect });
1622
+ res.end();
1623
+ }
1624
+ else {
1625
+ res.writeHead(result.status, {
1626
+ "Content-Type": result.contentType ?? "application/json",
1627
+ });
1628
+ res.end(result.body);
1629
+ }
972
1630
  }
973
- else {
974
- res.writeHead(result.status, {
975
- "Content-Type": result.contentType ?? "application/json",
976
- });
977
- res.end(result.body);
1631
+ catch (err) {
1632
+ if (!res.headersSent) {
1633
+ res.writeHead(500, { "Content-Type": "application/json" });
1634
+ res.end(JSON.stringify({
1635
+ error: err instanceof Error ? err.message : String(err),
1636
+ }));
1637
+ }
978
1638
  }
979
1639
  })();
980
1640
  return true;
@@ -982,39 +1642,69 @@ export function tryHandleConnectorRoute(req, res, parsedUrl) {
982
1642
  if (parsedUrl.pathname === "/connections/google-drive/callback" &&
983
1643
  req.method === "GET") {
984
1644
  void (async () => {
985
- const { handleDriveCallback } = await import("./connectors/googleDrive.js");
986
- const code = parsedUrl.searchParams.get("code");
987
- const state = parsedUrl.searchParams.get("state");
988
- const error = parsedUrl.searchParams.get("error");
989
- const result = await handleDriveCallback(code, state, error);
990
- res.writeHead(result.status, {
991
- "Content-Type": result.contentType ?? "application/json",
992
- });
993
- res.end(result.body);
1645
+ try {
1646
+ const { handleDriveCallback } = await import("./connectors/googleDrive.js");
1647
+ const code = parsedUrl.searchParams.get("code");
1648
+ const state = parsedUrl.searchParams.get("state");
1649
+ const error = parsedUrl.searchParams.get("error");
1650
+ const result = await handleDriveCallback(code, state, error);
1651
+ res.writeHead(result.status, {
1652
+ "Content-Type": result.contentType ?? "application/json",
1653
+ });
1654
+ res.end(result.body);
1655
+ }
1656
+ catch (err) {
1657
+ if (!res.headersSent) {
1658
+ res.writeHead(500, { "Content-Type": "application/json" });
1659
+ res.end(JSON.stringify({
1660
+ error: err instanceof Error ? err.message : String(err),
1661
+ }));
1662
+ }
1663
+ }
994
1664
  })();
995
1665
  return true;
996
1666
  }
997
1667
  if (parsedUrl.pathname === "/connections/google-drive/test" &&
998
1668
  req.method === "POST") {
999
1669
  void (async () => {
1000
- const { handleDriveTest } = await import("./connectors/googleDrive.js");
1001
- const result = await handleDriveTest();
1002
- res.writeHead(result.status, {
1003
- "Content-Type": result.contentType ?? "application/json",
1004
- });
1005
- res.end(result.body);
1670
+ try {
1671
+ const { handleDriveTest } = await import("./connectors/googleDrive.js");
1672
+ const result = await handleDriveTest();
1673
+ res.writeHead(result.status, {
1674
+ "Content-Type": result.contentType ?? "application/json",
1675
+ });
1676
+ res.end(result.body);
1677
+ }
1678
+ catch (err) {
1679
+ if (!res.headersSent) {
1680
+ res.writeHead(500, { "Content-Type": "application/json" });
1681
+ res.end(JSON.stringify({
1682
+ error: err instanceof Error ? err.message : String(err),
1683
+ }));
1684
+ }
1685
+ }
1006
1686
  })();
1007
1687
  return true;
1008
1688
  }
1009
1689
  if (parsedUrl.pathname === "/connections/google-drive" &&
1010
1690
  req.method === "DELETE") {
1011
1691
  void (async () => {
1012
- const { handleDriveDisconnect } = await import("./connectors/googleDrive.js");
1013
- const result = await handleDriveDisconnect();
1014
- res.writeHead(result.status, {
1015
- "Content-Type": result.contentType ?? "application/json",
1016
- });
1017
- res.end(result.body);
1692
+ try {
1693
+ const { handleDriveDisconnect } = await import("./connectors/googleDrive.js");
1694
+ const result = await handleDriveDisconnect();
1695
+ res.writeHead(result.status, {
1696
+ "Content-Type": result.contentType ?? "application/json",
1697
+ });
1698
+ res.end(result.body);
1699
+ }
1700
+ catch (err) {
1701
+ if (!res.headersSent) {
1702
+ res.writeHead(500, { "Content-Type": "application/json" });
1703
+ res.end(JSON.stringify({
1704
+ error: err instanceof Error ? err.message : String(err),
1705
+ }));
1706
+ }
1707
+ }
1018
1708
  })();
1019
1709
  return true;
1020
1710
  }