@kya-os/mcp-i-cloudflare 1.17.0 → 1.18.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.
@@ -7,7 +7,9 @@ export function oauthProfileString(value) {
7
7
  /** GitHub subjects are numeric IDs; preserve them as exact scalar strings. */
8
8
  export function normalizeOAuthSubject(value) {
9
9
  if (typeof value === "number") {
10
- return Number.isSafeInteger(value) && value >= 0 ? String(value) : undefined;
10
+ return Number.isSafeInteger(value) && value >= 0
11
+ ? String(value)
12
+ : undefined;
11
13
  }
12
14
  return oauthProfileString(value);
13
15
  }
@@ -21,4 +23,55 @@ export function oauthProfileSubject(profile) {
21
23
  normalizeOAuthSubject(claims.id) ??
22
24
  oauthProfileString(claims.login));
23
25
  }
26
+ const GITHUB_API_ORIGIN = "https://api.github.com";
27
+ /** The primary address from GitHub's /user/emails, only when GitHub verified it. */
28
+ function githubVerifiedPrimaryEmail(emails) {
29
+ if (!Array.isArray(emails))
30
+ return undefined;
31
+ const primary = emails.find((entry) => !!entry &&
32
+ typeof entry === "object" &&
33
+ "primary" in entry &&
34
+ entry.primary === true);
35
+ return primary?.verified === true
36
+ ? oauthProfileString(primary.email)
37
+ : undefined;
38
+ }
39
+ /**
40
+ * The email to send for identity linking, and whether the provider verified it.
41
+ *
42
+ * GitHub's /user has no verification flag, so for a profile read from the
43
+ * GitHub API the only verified email is the primary one on /user/emails (needs
44
+ * the `user:email` scope). A missing scope, an error or an unverified primary
45
+ * leaves the profile email unverified. The token only goes to the API that
46
+ * already served the profile. Other providers keep their explicit boolean claim.
47
+ */
48
+ export async function resolveOAuthEmail(params) {
49
+ const profileEmail = oauthProfileString(params.profile.email);
50
+ if (new URL(params.userInfoUrl).origin !== GITHUB_API_ORIGIN) {
51
+ return {
52
+ email: profileEmail,
53
+ emailVerified: params.profile.email_verified === true,
54
+ };
55
+ }
56
+ // Unbound: Workers throws "Illegal invocation" for fetch called as a method.
57
+ const { fetchImpl } = params;
58
+ try {
59
+ const response = await fetchImpl(`${GITHUB_API_ORIGIN}/user/emails`, {
60
+ headers: {
61
+ Authorization: `Bearer ${params.accessToken}`,
62
+ Accept: "application/vnd.github+json",
63
+ "User-Agent": params.userAgent,
64
+ },
65
+ });
66
+ const verified = response.ok
67
+ ? githubVerifiedPrimaryEmail(await response.json())
68
+ : undefined;
69
+ return verified
70
+ ? { email: verified, emailVerified: true }
71
+ : { email: profileEmail, emailVerified: false };
72
+ }
73
+ catch {
74
+ return { email: profileEmail, emailVerified: false };
75
+ }
76
+ }
24
77
  //# sourceMappingURL=oauth-profile.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"oauth-profile.js","sourceRoot":"","sources":["../../src/utils/oauth-profile.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,MAAM,UAAU,kBAAkB,CAAC,KAAc;IAC/C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC;QACzD,CAAC,CAAC,KAAK;QACP,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,qBAAqB,CAAC,KAAc;IAClD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC/E,CAAC;IACD,OAAO,kBAAkB,CAAC,KAAK,CAAC,CAAC;AACnC,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,mBAAmB,CAAC,OAAgB;IAClD,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QACtE,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,MAAM,GAAG,OAAkC,CAAC;I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,EAAE,CAAC;YACnD,CAAC,CAAC,SAAS,CAAC;QACd,OAAO,QAAQ;YACb,CAAC,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,IAAI,EAAE;YAC1C,CAAC,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC;IACpD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC;IACvD,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kya-os/mcp-i-cloudflare",
3
- "version": "1.17.0",
3
+ "version": "1.18.0",
4
4
  "description": "Cloudflare Workers adapter for MCP-I framework",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -31,8 +31,8 @@
31
31
  "prepublishOnly": "npm run build && node ../create-mcpi-app/scripts/validate-no-workspace.js"
32
32
  },
33
33
  "dependencies": {
34
- "@kya-os/consent": "^0.1.50",
35
- "@kya-os/contracts": "^1.13.1",
34
+ "@kya-os/consent": "^0.2.0",
35
+ "@kya-os/contracts": "^1.14.0",
36
36
  "@kya-os/mcp": "1.16.0",
37
37
  "@kya-os/mcp-i-core": "^1.9.4",
38
38
  "@kya-os/mcp-i-runtime": "^1.3.1",