integrate-sdk 0.8.79-dev.0 → 0.8.80-dev.0

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.
@@ -57,6 +57,108 @@ var init_logger = __esm(() => {
57
57
  };
58
58
  });
59
59
 
60
+ // ../oauth/email-fetcher.ts
61
+ async function fetchUserEmail(provider, tokenData) {
62
+ try {
63
+ switch (provider.toLowerCase()) {
64
+ case "github":
65
+ return await fetchGitHubEmail(tokenData.accessToken);
66
+ case "gmail":
67
+ case "google":
68
+ return await fetchGoogleEmail(tokenData.accessToken);
69
+ case "notion":
70
+ return await fetchNotionEmail(tokenData.accessToken);
71
+ default:
72
+ return tokenData.email;
73
+ }
74
+ } catch (error) {
75
+ logger.error(`Failed to fetch email for ${provider}:`, error);
76
+ return;
77
+ }
78
+ }
79
+ async function fetchGitHubEmail(accessToken) {
80
+ try {
81
+ const userResponse = await fetch("https://api.github.com/user", {
82
+ headers: {
83
+ Authorization: `Bearer ${accessToken}`,
84
+ Accept: "application/vnd.github.v3+json"
85
+ }
86
+ });
87
+ if (!userResponse.ok) {
88
+ return;
89
+ }
90
+ const user = await userResponse.json();
91
+ if (user.email) {
92
+ return user.email;
93
+ }
94
+ const emailsResponse = await fetch("https://api.github.com/user/emails", {
95
+ headers: {
96
+ Authorization: `Bearer ${accessToken}`,
97
+ Accept: "application/vnd.github.v3+json"
98
+ }
99
+ });
100
+ if (!emailsResponse.ok) {
101
+ return;
102
+ }
103
+ const emails = await emailsResponse.json();
104
+ const primaryEmail = emails.find((e) => e.primary && e.verified);
105
+ if (primaryEmail) {
106
+ return primaryEmail.email;
107
+ }
108
+ const verifiedEmail = emails.find((e) => e.verified);
109
+ if (verifiedEmail) {
110
+ return verifiedEmail.email;
111
+ }
112
+ if (emails.length > 0 && emails[0]?.email) {
113
+ return emails[0].email;
114
+ }
115
+ return;
116
+ } catch (error) {
117
+ logger.error("Failed to fetch GitHub email:", error);
118
+ return;
119
+ }
120
+ }
121
+ async function fetchGoogleEmail(accessToken) {
122
+ try {
123
+ const response = await fetch("https://www.googleapis.com/oauth2/v2/userinfo", {
124
+ headers: {
125
+ Authorization: `Bearer ${accessToken}`
126
+ }
127
+ });
128
+ if (!response.ok) {
129
+ return;
130
+ }
131
+ const user = await response.json();
132
+ return user.email;
133
+ } catch (error) {
134
+ logger.error("Failed to fetch Google email:", error);
135
+ return;
136
+ }
137
+ }
138
+ async function fetchNotionEmail(accessToken) {
139
+ try {
140
+ const response = await fetch("https://api.notion.com/v1/users/me", {
141
+ headers: {
142
+ Authorization: `Bearer ${accessToken}`,
143
+ "Notion-Version": "2022-06-28"
144
+ }
145
+ });
146
+ if (!response.ok) {
147
+ return;
148
+ }
149
+ const user = await response.json();
150
+ return user.person?.email;
151
+ } catch (error) {
152
+ logger.error("Failed to fetch Notion email:", error);
153
+ return;
154
+ }
155
+ }
156
+ var logger;
157
+ var init_email_fetcher = __esm(() => {
158
+ init_logger();
159
+ logger = createLogger("EmailFetcher");
160
+ });
161
+
60
162
  // ../protocol/jsonrpc.ts
61
163
  function parseMessage(message) {
62
164
  try {
@@ -122,7 +224,7 @@ class HttpSessionTransport {
122
224
  const sid = response.headers.get("mcp-session-id");
123
225
  if (sid) {
124
226
  this.sessionId = sid;
125
- logger.debug("Session established:", sid);
227
+ logger2.debug("Session established:", sid);
126
228
  this.startSSEListener();
127
229
  }
128
230
  }
@@ -172,7 +274,7 @@ class HttpSessionTransport {
172
274
  if (error instanceof Error && error.name === "AbortError") {
173
275
  return;
174
276
  }
175
- logger.error("SSE connection error:", error);
277
+ logger2.error("SSE connection error:", error);
176
278
  }
177
279
  }
178
280
  async processSSEStream(body) {
@@ -201,7 +303,7 @@ class HttpSessionTransport {
201
303
  if (error instanceof Error && error.name === "AbortError") {
202
304
  return;
203
305
  }
204
- logger.error("SSE stream error:", error);
306
+ logger2.error("SSE stream error:", error);
205
307
  } finally {
206
308
  reader.releaseLock();
207
309
  }
@@ -213,11 +315,11 @@ class HttpSessionTransport {
213
315
  try {
214
316
  handler(message);
215
317
  } catch (error) {
216
- logger.error("Error in message handler:", error);
318
+ logger2.error("Error in message handler:", error);
217
319
  }
218
320
  });
219
321
  } catch (error) {
220
- logger.error("Failed to parse notification:", error);
322
+ logger2.error("Failed to parse notification:", error);
221
323
  }
222
324
  }
223
325
  onMessage(handler) {
@@ -254,10 +356,10 @@ class HttpSessionTransport {
254
356
  return { ...this.headers };
255
357
  }
256
358
  }
257
- var logger;
359
+ var logger2;
258
360
  var init_http_session = __esm(() => {
259
361
  init_logger();
260
- logger = createLogger("HTTPSession");
362
+ logger2 = createLogger("HTTPSession");
261
363
  });
262
364
 
263
365
  // ../protocol/messages.ts
@@ -617,7 +719,7 @@ class OAuthWindowManager {
617
719
  const windowName = `oauth_popup_${Date.now()}`;
618
720
  this.popupWindow = window.open(url, windowName, features);
619
721
  if (!this.popupWindow) {
620
- logger2.warn("Popup was blocked by the browser. Please allow popups for this site.");
722
+ logger3.warn("Popup was blocked by the browser. Please allow popups for this site.");
621
723
  return null;
622
724
  }
623
725
  this.popupWindow.focus();
@@ -627,7 +729,7 @@ class OAuthWindowManager {
627
729
  if (!isBrowser()) {
628
730
  throw new Error("OAuthWindowManager.openRedirect() can only be used in browser environments");
629
731
  }
630
- logger2.debug("[OAuthWindowManager] Redirecting to:", url.substring(0, 100) + (url.length > 100 ? "..." : ""));
732
+ logger3.debug("[OAuthWindowManager] Redirecting to:", url.substring(0, 100) + (url.length > 100 ? "..." : ""));
631
733
  window.location.href = url;
632
734
  }
633
735
  listenForCallback(mode, timeoutMs = 5 * 60 * 1000) {
@@ -706,7 +808,7 @@ class OAuthWindowManager {
706
808
  window.history.replaceState(null, "", window.location.pathname + window.location.search);
707
809
  }
708
810
  } catch (e) {
709
- logger2.error("Failed to parse OAuth callback params from hash:", e);
811
+ logger3.error("Failed to parse OAuth callback params from hash:", e);
710
812
  }
711
813
  }
712
814
  if (!code && !error) {
@@ -719,7 +821,7 @@ class OAuthWindowManager {
719
821
  sessionStorage.removeItem("oauth_callback_params");
720
822
  }
721
823
  } catch (e) {
722
- logger2.error("Failed to parse OAuth callback params from sessionStorage:", e);
824
+ logger3.error("Failed to parse OAuth callback params from sessionStorage:", e);
723
825
  }
724
826
  }
725
827
  if (error) {
@@ -752,10 +854,10 @@ class OAuthWindowManager {
752
854
  this.cleanup();
753
855
  }
754
856
  }
755
- var logger2;
857
+ var logger3;
756
858
  var init_window_manager = __esm(() => {
757
859
  init_logger();
758
- logger2 = createLogger("OAuthWindowManager");
860
+ logger3 = createLogger("OAuthWindowManager");
759
861
  });
760
862
 
761
863
  // ../oauth/indexeddb-storage.ts
@@ -932,108 +1034,6 @@ class IndexedDBStorage {
932
1034
  }
933
1035
  var DB_NAME = "integrate_oauth_tokens", DB_VERSION = 1, STORE_NAME = "tokens";
934
1036
 
935
- // ../oauth/email-fetcher.ts
936
- async function fetchUserEmail(provider, tokenData) {
937
- try {
938
- switch (provider.toLowerCase()) {
939
- case "github":
940
- return await fetchGitHubEmail(tokenData.accessToken);
941
- case "gmail":
942
- case "google":
943
- return await fetchGoogleEmail(tokenData.accessToken);
944
- case "notion":
945
- return await fetchNotionEmail(tokenData.accessToken);
946
- default:
947
- return tokenData.email;
948
- }
949
- } catch (error) {
950
- logger3.error(`Failed to fetch email for ${provider}:`, error);
951
- return;
952
- }
953
- }
954
- async function fetchGitHubEmail(accessToken) {
955
- try {
956
- const userResponse = await fetch("https://api.github.com/user", {
957
- headers: {
958
- Authorization: `Bearer ${accessToken}`,
959
- Accept: "application/vnd.github.v3+json"
960
- }
961
- });
962
- if (!userResponse.ok) {
963
- return;
964
- }
965
- const user = await userResponse.json();
966
- if (user.email) {
967
- return user.email;
968
- }
969
- const emailsResponse = await fetch("https://api.github.com/user/emails", {
970
- headers: {
971
- Authorization: `Bearer ${accessToken}`,
972
- Accept: "application/vnd.github.v3+json"
973
- }
974
- });
975
- if (!emailsResponse.ok) {
976
- return;
977
- }
978
- const emails = await emailsResponse.json();
979
- const primaryEmail = emails.find((e) => e.primary && e.verified);
980
- if (primaryEmail) {
981
- return primaryEmail.email;
982
- }
983
- const verifiedEmail = emails.find((e) => e.verified);
984
- if (verifiedEmail) {
985
- return verifiedEmail.email;
986
- }
987
- if (emails.length > 0 && emails[0]?.email) {
988
- return emails[0].email;
989
- }
990
- return;
991
- } catch (error) {
992
- logger3.error("Failed to fetch GitHub email:", error);
993
- return;
994
- }
995
- }
996
- async function fetchGoogleEmail(accessToken) {
997
- try {
998
- const response = await fetch("https://www.googleapis.com/oauth2/v2/userinfo", {
999
- headers: {
1000
- Authorization: `Bearer ${accessToken}`
1001
- }
1002
- });
1003
- if (!response.ok) {
1004
- return;
1005
- }
1006
- const user = await response.json();
1007
- return user.email;
1008
- } catch (error) {
1009
- logger3.error("Failed to fetch Google email:", error);
1010
- return;
1011
- }
1012
- }
1013
- async function fetchNotionEmail(accessToken) {
1014
- try {
1015
- const response = await fetch("https://api.notion.com/v1/users/me", {
1016
- headers: {
1017
- Authorization: `Bearer ${accessToken}`,
1018
- "Notion-Version": "2022-06-28"
1019
- }
1020
- });
1021
- if (!response.ok) {
1022
- return;
1023
- }
1024
- const user = await response.json();
1025
- return user.person?.email;
1026
- } catch (error) {
1027
- logger3.error("Failed to fetch Notion email:", error);
1028
- return;
1029
- }
1030
- }
1031
- var logger3;
1032
- var init_email_fetcher = __esm(() => {
1033
- init_logger();
1034
- logger3 = createLogger("EmailFetcher");
1035
- });
1036
-
1037
1037
  // ../oauth/manager.ts
1038
1038
  class OAuthManager {
1039
1039
  pendingAuths = new Map;
@@ -11754,7 +11754,11 @@ class OAuthHandler {
11754
11754
  expiresAt: result.expiresAt,
11755
11755
  scopes: result.scopes ? result.scopes.flatMap((s) => s.split(" ").filter(Boolean)) : result.scopes
11756
11756
  };
11757
- await this.config.setProviderToken(callbackRequest.provider, tokenData, undefined, context);
11757
+ const email = result.email || await fetchUserEmail(callbackRequest.provider, tokenData);
11758
+ if (email) {
11759
+ tokenData.email = email;
11760
+ }
11761
+ await this.config.setProviderToken(callbackRequest.provider, tokenData, email, context);
11758
11762
  } catch (error) {}
11759
11763
  }
11760
11764
  if (webRequest) {
@@ -11871,6 +11875,7 @@ class OAuthHandler {
11871
11875
  }
11872
11876
  var SERVER_LOG_CONTEXT2 = "server", logger32, MCP_SERVER_URL2 = "https://mcp.integrate.dev/api/v1/mcp";
11873
11877
  var init_base_handler = __esm(() => {
11878
+ init_email_fetcher();
11874
11879
  init_logger();
11875
11880
  logger32 = createLogger("OAuthHandler", SERVER_LOG_CONTEXT2);
11876
11881
  });
@@ -153,6 +153,8 @@ export interface CallbackResponse {
153
153
  expiresIn: number;
154
154
  expiresAt?: string;
155
155
  scopes?: string[];
156
+ /** Connected account email (populated for Google providers via id_token) */
157
+ email?: string;
156
158
  /** Optional Set-Cookie header value to clear context cookie */
157
159
  clearCookie?: string;
158
160
  }
@@ -1 +1 @@
1
- {"version":3,"file":"base-handler.d.ts","sourceRoot":"","sources":["../../../src/adapters/base-handler.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAc3D;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,uCAAuC;IACvC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE;QACxB,iDAAiD;QACjD,QAAQ,EAAE,MAAM,CAAC;QACjB,qDAAqD;QACrD,YAAY,EAAE,MAAM,CAAC;QACrB,qCAAqC;QACrC,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,8CAA8C;QAC9C,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;QAClB,6DAA6D;QAC7D,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;QAC1B,kFAAkF;QAClF,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KAC9B,CAAC,CAAC;IACH;;;OAGG;IACH,S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BAAiB,CAAC;IA0ItF;;;;;;;;;;OAUG;IACG,cAAc,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAqHnF;;;;;;;;;OASG;IACG,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IA4BlF;;;;;;;;;;;OAWG;IACG,gBAAgB,CAAC,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,kBAAkB,CAAC;IA4D1H;;;;;;;;;;;;;;OAcG;IACG,cAAc,CAClB,OAAO,EAAE,eAAe,EACxB,UAAU,EAAE,MAAM,GAAG,IAAI,EACzB,kBAAkB,CAAC,EAAE,MAAM,GAAG,IAAI,GACjC,OAAO,CAAC,gBAAgB,CAAC;CA0D7B"}
@@ -57,6 +57,108 @@ var init_logger = __esm(() => {
57
57
  };
58
58
  });
59
59
 
60
+ // ../oauth/email-fetcher.ts
61
+ async function fetchUserEmail(provider, tokenData) {
62
+ try {
63
+ switch (provider.toLowerCase()) {
64
+ case "github":
65
+ return await fetchGitHubEmail(tokenData.accessToken);
66
+ case "gmail":
67
+ case "google":
68
+ return await fetchGoogleEmail(tokenData.accessToken);
69
+ case "notion":
70
+ return await fetchNotionEmail(tokenData.accessToken);
71
+ default:
72
+ return tokenData.email;
73
+ }
74
+ } catch (error) {
75
+ logger.error(`Failed to fetch email for ${provider}:`, error);
76
+ return;
77
+ }
78
+ }
79
+ async function fetchGitHubEmail(accessToken) {
80
+ try {
81
+ const userResponse = await fetch("https://api.github.com/user", {
82
+ headers: {
83
+ Authorization: `Bearer ${accessToken}`,
84
+ Accept: "application/vnd.github.v3+json"
85
+ }
86
+ });
87
+ if (!userResponse.ok) {
88
+ return;
89
+ }
90
+ const user = await userResponse.json();
91
+ if (user.email) {
92
+ return user.email;
93
+ }
94
+ const emailsResponse = await fetch("https://api.github.com/user/emails", {
95
+ headers: {
96
+ Authorization: `Bearer ${accessToken}`,
97
+ Accept: "application/vnd.github.v3+json"
98
+ }
99
+ });
100
+ if (!emailsResponse.ok) {
101
+ return;
102
+ }
103
+ const emails = await emailsResponse.json();
104
+ const primaryEmail = emails.find((e) => e.primary && e.verified);
105
+ if (primaryEmail) {
106
+ return primaryEmail.email;
107
+ }
108
+ const verifiedEmail = emails.find((e) => e.verified);
109
+ if (verifiedEmail) {
110
+ return verifiedEmail.email;
111
+ }
112
+ if (emails.length > 0 && emails[0]?.email) {
113
+ return emails[0].email;
114
+ }
115
+ return;
116
+ } catch (error) {
117
+ logger.error("Failed to fetch GitHub email:", error);
118
+ return;
119
+ }
120
+ }
121
+ async function fetchGoogleEmail(accessToken) {
122
+ try {
123
+ const response = await fetch("https://www.googleapis.com/oauth2/v2/userinfo", {
124
+ headers: {
125
+ Authorization: `Bearer ${accessToken}`
126
+ }
127
+ });
128
+ if (!response.ok) {
129
+ return;
130
+ }
131
+ const user = await response.json();
132
+ return user.email;
133
+ } catch (error) {
134
+ logger.error("Failed to fetch Google email:", error);
135
+ return;
136
+ }
137
+ }
138
+ async function fetchNotionEmail(accessToken) {
139
+ try {
140
+ const response = await fetch("https://api.notion.com/v1/users/me", {
141
+ headers: {
142
+ Authorization: `Bearer ${accessToken}`,
143
+ "Notion-Version": "2022-06-28"
144
+ }
145
+ });
146
+ if (!response.ok) {
147
+ return;
148
+ }
149
+ const user = await response.json();
150
+ return user.person?.email;
151
+ } catch (error) {
152
+ logger.error("Failed to fetch Notion email:", error);
153
+ return;
154
+ }
155
+ }
156
+ var logger;
157
+ var init_email_fetcher = __esm(() => {
158
+ init_logger();
159
+ logger = createLogger("EmailFetcher");
160
+ });
161
+
60
162
  // ../protocol/jsonrpc.ts
61
163
  function parseMessage(message) {
62
164
  try {
@@ -122,7 +224,7 @@ class HttpSessionTransport {
122
224
  const sid = response.headers.get("mcp-session-id");
123
225
  if (sid) {
124
226
  this.sessionId = sid;
125
- logger.debug("Session established:", sid);
227
+ logger2.debug("Session established:", sid);
126
228
  this.startSSEListener();
127
229
  }
128
230
  }
@@ -172,7 +274,7 @@ class HttpSessionTransport {
172
274
  if (error instanceof Error && error.name === "AbortError") {
173
275
  return;
174
276
  }
175
- logger.error("SSE connection error:", error);
277
+ logger2.error("SSE connection error:", error);
176
278
  }
177
279
  }
178
280
  async processSSEStream(body) {
@@ -201,7 +303,7 @@ class HttpSessionTransport {
201
303
  if (error instanceof Error && error.name === "AbortError") {
202
304
  return;
203
305
  }
204
- logger.error("SSE stream error:", error);
306
+ logger2.error("SSE stream error:", error);
205
307
  } finally {
206
308
  reader.releaseLock();
207
309
  }
@@ -213,11 +315,11 @@ class HttpSessionTransport {
213
315
  try {
214
316
  handler(message);
215
317
  } catch (error) {
216
- logger.error("Error in message handler:", error);
318
+ logger2.error("Error in message handler:", error);
217
319
  }
218
320
  });
219
321
  } catch (error) {
220
- logger.error("Failed to parse notification:", error);
322
+ logger2.error("Failed to parse notification:", error);
221
323
  }
222
324
  }
223
325
  onMessage(handler) {
@@ -254,10 +356,10 @@ class HttpSessionTransport {
254
356
  return { ...this.headers };
255
357
  }
256
358
  }
257
- var logger;
359
+ var logger2;
258
360
  var init_http_session = __esm(() => {
259
361
  init_logger();
260
- logger = createLogger("HTTPSession");
362
+ logger2 = createLogger("HTTPSession");
261
363
  });
262
364
 
263
365
  // ../protocol/messages.ts
@@ -617,7 +719,7 @@ class OAuthWindowManager {
617
719
  const windowName = `oauth_popup_${Date.now()}`;
618
720
  this.popupWindow = window.open(url, windowName, features);
619
721
  if (!this.popupWindow) {
620
- logger2.warn("Popup was blocked by the browser. Please allow popups for this site.");
722
+ logger3.warn("Popup was blocked by the browser. Please allow popups for this site.");
621
723
  return null;
622
724
  }
623
725
  this.popupWindow.focus();
@@ -627,7 +729,7 @@ class OAuthWindowManager {
627
729
  if (!isBrowser()) {
628
730
  throw new Error("OAuthWindowManager.openRedirect() can only be used in browser environments");
629
731
  }
630
- logger2.debug("[OAuthWindowManager] Redirecting to:", url.substring(0, 100) + (url.length > 100 ? "..." : ""));
732
+ logger3.debug("[OAuthWindowManager] Redirecting to:", url.substring(0, 100) + (url.length > 100 ? "..." : ""));
631
733
  window.location.href = url;
632
734
  }
633
735
  listenForCallback(mode, timeoutMs = 5 * 60 * 1000) {
@@ -706,7 +808,7 @@ class OAuthWindowManager {
706
808
  window.history.replaceState(null, "", window.location.pathname + window.location.search);
707
809
  }
708
810
  } catch (e) {
709
- logger2.error("Failed to parse OAuth callback params from hash:", e);
811
+ logger3.error("Failed to parse OAuth callback params from hash:", e);
710
812
  }
711
813
  }
712
814
  if (!code && !error) {
@@ -719,7 +821,7 @@ class OAuthWindowManager {
719
821
  sessionStorage.removeItem("oauth_callback_params");
720
822
  }
721
823
  } catch (e) {
722
- logger2.error("Failed to parse OAuth callback params from sessionStorage:", e);
824
+ logger3.error("Failed to parse OAuth callback params from sessionStorage:", e);
723
825
  }
724
826
  }
725
827
  if (error) {
@@ -752,10 +854,10 @@ class OAuthWindowManager {
752
854
  this.cleanup();
753
855
  }
754
856
  }
755
- var logger2;
857
+ var logger3;
756
858
  var init_window_manager = __esm(() => {
757
859
  init_logger();
758
- logger2 = createLogger("OAuthWindowManager");
860
+ logger3 = createLogger("OAuthWindowManager");
759
861
  });
760
862
 
761
863
  // ../oauth/indexeddb-storage.ts
@@ -932,108 +1034,6 @@ class IndexedDBStorage {
932
1034
  }
933
1035
  var DB_NAME = "integrate_oauth_tokens", DB_VERSION = 1, STORE_NAME = "tokens";
934
1036
 
935
- // ../oauth/email-fetcher.ts
936
- async function fetchUserEmail(provider, tokenData) {
937
- try {
938
- switch (provider.toLowerCase()) {
939
- case "github":
940
- return await fetchGitHubEmail(tokenData.accessToken);
941
- case "gmail":
942
- case "google":
943
- return await fetchGoogleEmail(tokenData.accessToken);
944
- case "notion":
945
- return await fetchNotionEmail(tokenData.accessToken);
946
- default:
947
- return tokenData.email;
948
- }
949
- } catch (error) {
950
- logger3.error(`Failed to fetch email for ${provider}:`, error);
951
- return;
952
- }
953
- }
954
- async function fetchGitHubEmail(accessToken) {
955
- try {
956
- const userResponse = await fetch("https://api.github.com/user", {
957
- headers: {
958
- Authorization: `Bearer ${accessToken}`,
959
- Accept: "application/vnd.github.v3+json"
960
- }
961
- });
962
- if (!userResponse.ok) {
963
- return;
964
- }
965
- const user = await userResponse.json();
966
- if (user.email) {
967
- return user.email;
968
- }
969
- const emailsResponse = await fetch("https://api.github.com/user/emails", {
970
- headers: {
971
- Authorization: `Bearer ${accessToken}`,
972
- Accept: "application/vnd.github.v3+json"
973
- }
974
- });
975
- if (!emailsResponse.ok) {
976
- return;
977
- }
978
- const emails = await emailsResponse.json();
979
- const primaryEmail = emails.find((e) => e.primary && e.verified);
980
- if (primaryEmail) {
981
- return primaryEmail.email;
982
- }
983
- const verifiedEmail = emails.find((e) => e.verified);
984
- if (verifiedEmail) {
985
- return verifiedEmail.email;
986
- }
987
- if (emails.length > 0 && emails[0]?.email) {
988
- return emails[0].email;
989
- }
990
- return;
991
- } catch (error) {
992
- logger3.error("Failed to fetch GitHub email:", error);
993
- return;
994
- }
995
- }
996
- async function fetchGoogleEmail(accessToken) {
997
- try {
998
- const response = await fetch("https://www.googleapis.com/oauth2/v2/userinfo", {
999
- headers: {
1000
- Authorization: `Bearer ${accessToken}`
1001
- }
1002
- });
1003
- if (!response.ok) {
1004
- return;
1005
- }
1006
- const user = await response.json();
1007
- return user.email;
1008
- } catch (error) {
1009
- logger3.error("Failed to fetch Google email:", error);
1010
- return;
1011
- }
1012
- }
1013
- async function fetchNotionEmail(accessToken) {
1014
- try {
1015
- const response = await fetch("https://api.notion.com/v1/users/me", {
1016
- headers: {
1017
- Authorization: `Bearer ${accessToken}`,
1018
- "Notion-Version": "2022-06-28"
1019
- }
1020
- });
1021
- if (!response.ok) {
1022
- return;
1023
- }
1024
- const user = await response.json();
1025
- return user.person?.email;
1026
- } catch (error) {
1027
- logger3.error("Failed to fetch Notion email:", error);
1028
- return;
1029
- }
1030
- }
1031
- var logger3;
1032
- var init_email_fetcher = __esm(() => {
1033
- init_logger();
1034
- logger3 = createLogger("EmailFetcher");
1035
- });
1036
-
1037
1037
  // ../oauth/manager.ts
1038
1038
  class OAuthManager {
1039
1039
  pendingAuths = new Map;
@@ -11754,7 +11754,11 @@ class OAuthHandler {
11754
11754
  expiresAt: result.expiresAt,
11755
11755
  scopes: result.scopes ? result.scopes.flatMap((s) => s.split(" ").filter(Boolean)) : result.scopes
11756
11756
  };
11757
- await this.config.setProviderToken(callbackRequest.provider, tokenData, undefined, context);
11757
+ const email = result.email || await fetchUserEmail(callbackRequest.provider, tokenData);
11758
+ if (email) {
11759
+ tokenData.email = email;
11760
+ }
11761
+ await this.config.setProviderToken(callbackRequest.provider, tokenData, email, context);
11758
11762
  } catch (error) {}
11759
11763
  }
11760
11764
  if (webRequest) {
@@ -11871,6 +11875,7 @@ class OAuthHandler {
11871
11875
  }
11872
11876
  var SERVER_LOG_CONTEXT2 = "server", logger32, MCP_SERVER_URL2 = "https://mcp.integrate.dev/api/v1/mcp";
11873
11877
  var init_base_handler = __esm(() => {
11878
+ init_email_fetcher();
11874
11879
  init_logger();
11875
11880
  logger32 = createLogger("OAuthHandler", SERVER_LOG_CONTEXT2);
11876
11881
  });