@better-auth/cimd 1.7.0-rc.2 → 1.7.0-rc.3

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.
@@ -0,0 +1,14 @@
1
+ import { ClientMetadataResourceFetch } from "@better-auth/oauth-provider";
2
+ //#region src/node.d.ts
3
+ /**
4
+ * Fetch a CIMD-owned HTTPS resource with resolve-once DNS validation and
5
+ * connection pinning.
6
+ *
7
+ * Every DNS answer must be public-routable. The selected answer is pinned for
8
+ * the connection while the original hostname remains the HTTP Host, TLS SNI,
9
+ * and certificate-verification identity. Redirect responses are returned to
10
+ * the caller and are never followed.
11
+ */
12
+ declare const fetchClientMetadataResource: ClientMetadataResourceFetch;
13
+ //#endregion
14
+ export { fetchClientMetadataResource };
package/dist/node.mjs ADDED
@@ -0,0 +1,66 @@
1
+ import { isPublicRoutableHost } from "@better-auth/core/utils/host";
2
+ import { lookup } from "node:dns/promises";
3
+ import { request } from "node:https";
4
+ import { isIP } from "node:net";
5
+ import { Readable } from "node:stream";
6
+ //#region src/node.ts
7
+ const BODY_FORBIDDEN_RESPONSE_STATUSES = /* @__PURE__ */ new Set([
8
+ 204,
9
+ 205,
10
+ 304
11
+ ]);
12
+ function responseHeaders(headers) {
13
+ const result = new Headers();
14
+ for (const [name, value] of Object.entries(headers)) if (Array.isArray(value)) for (const item of value) result.append(name, item);
15
+ else if (value !== void 0) result.append(name, value);
16
+ return result;
17
+ }
18
+ /**
19
+ * Fetch a CIMD-owned HTTPS resource with resolve-once DNS validation and
20
+ * connection pinning.
21
+ *
22
+ * Every DNS answer must be public-routable. The selected answer is pinned for
23
+ * the connection while the original hostname remains the HTTP Host, TLS SNI,
24
+ * and certificate-verification identity. Redirect responses are returned to
25
+ * the caller and are never followed.
26
+ */
27
+ const fetchClientMetadataResource = async (input, init) => {
28
+ const webRequest = new Request(input, init);
29
+ const url = new URL(webRequest.url);
30
+ if (url.protocol !== "https:") throw new TypeError("CIMD Node transport requires an HTTPS URL");
31
+ if (webRequest.method !== "GET" && webRequest.method !== "HEAD") throw new TypeError("CIMD Node transport supports only GET and HEAD");
32
+ const addresses = await lookup(url.hostname, {
33
+ all: true,
34
+ verbatim: true
35
+ });
36
+ if (addresses.length === 0) throw new TypeError("metadata hostname returned no DNS addresses");
37
+ for (const result of addresses) if (!isPublicRoutableHost(result.address)) throw new TypeError("metadata hostname must resolve only to public-routable addresses");
38
+ const pinnedAddress = addresses[0];
39
+ const headers = Object.fromEntries(webRequest.headers.entries());
40
+ headers.host = url.host;
41
+ const signal = init?.signal ?? (input instanceof Request ? input.signal : webRequest.signal);
42
+ return new Promise((resolve, reject) => {
43
+ const request$1 = request(url, {
44
+ agent: false,
45
+ headers,
46
+ method: webRequest.method,
47
+ servername: isIP(url.hostname.replace(/^\[|\]$/g, "")) === 0 ? url.hostname : void 0,
48
+ signal,
49
+ lookup: (_hostname, _options, callback) => {
50
+ callback(null, pinnedAddress.address, pinnedAddress.family);
51
+ }
52
+ }, (response) => {
53
+ const status = response.statusCode ?? 500;
54
+ const body = webRequest.method === "HEAD" || BODY_FORBIDDEN_RESPONSE_STATUSES.has(status) ? null : Readable.toWeb(response);
55
+ resolve(new Response(body, {
56
+ headers: responseHeaders(response.headers),
57
+ status,
58
+ statusText: response.statusMessage
59
+ }));
60
+ });
61
+ request$1.once("error", reject);
62
+ request$1.end();
63
+ });
64
+ };
65
+ //#endregion
66
+ export { fetchClientMetadataResource };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@better-auth/cimd",
3
- "version": "1.7.0-rc.2",
3
+ "version": "1.7.0-rc.3",
4
4
  "description": "Client ID Metadata Document plugin for Better Auth",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -36,27 +36,38 @@
36
36
  "dev-source": "./src/index.ts",
37
37
  "types": "./dist/index.d.mts",
38
38
  "default": "./dist/index.mjs"
39
+ },
40
+ "./node": {
41
+ "dev-source": "./src/node.ts",
42
+ "types": "./dist/node.d.mts",
43
+ "default": "./dist/node.mjs"
39
44
  }
40
45
  },
41
46
  "typesVersions": {
42
47
  "*": {
43
48
  "*": [
44
49
  "./dist/index.d.mts"
50
+ ],
51
+ "node": [
52
+ "./dist/node.d.mts"
45
53
  ]
46
54
  }
47
55
  },
48
56
  "devDependencies": {
57
+ "@modelcontextprotocol/client": "2.0.0",
58
+ "@modelcontextprotocol/server": "2.0.0",
49
59
  "listhen": "^1.9.0",
50
60
  "tsdown": "0.22.7",
51
- "@better-auth/core": "1.7.0-rc.2",
52
- "@better-auth/oauth-provider": "1.7.0-rc.2",
53
- "better-auth": "1.7.0-rc.2"
61
+ "@better-auth/core": "1.7.0-rc.3",
62
+ "@better-auth/mcp": "1.7.0-rc.3",
63
+ "@better-auth/oauth-provider": "1.7.0-rc.3",
64
+ "better-auth": "1.7.0-rc.3"
54
65
  },
55
66
  "peerDependencies": {
56
67
  "better-call": "1.3.7",
57
- "@better-auth/core": "^1.7.0-rc.2",
58
- "@better-auth/oauth-provider": "^1.7.0-rc.2",
59
- "better-auth": "^1.7.0-rc.2"
68
+ "@better-auth/core": "^1.7.0-rc.3",
69
+ "@better-auth/oauth-provider": "^1.7.0-rc.3",
70
+ "better-auth": "^1.7.0-rc.3"
60
71
  },
61
72
  "scripts": {
62
73
  "build": "tsdown",