@relkit/better-auth 0.0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 rel-kit
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # @relkit/better-auth
2
+
3
+ Better Auth integration for RELKIT routes.
4
+
5
+ See [@relkit/app](https://github.com/rel-kit/relkit) for supported application APIs.
@@ -0,0 +1,24 @@
1
+ import type { RawHttpHandler } from "@relkit/routes";
2
+ export declare const BETTER_AUTH_HANDLER: unique symbol;
3
+ export interface BetterAuthLike<Session = unknown> {
4
+ readonly handler: (request: Request) => Promise<Response>;
5
+ readonly api: {
6
+ readonly getSession: (options: {
7
+ readonly headers: Headers;
8
+ }) => Promise<Session | null>;
9
+ };
10
+ }
11
+ export interface BetterAuthRegistration<Session = unknown> {
12
+ readonly kind: "better-auth";
13
+ readonly auth: BetterAuthLike<Session>;
14
+ readonly protected: readonly string[];
15
+ }
16
+ export type BetterAuthHandler<Session = unknown> = RawHttpHandler & {
17
+ readonly [BETTER_AUTH_HANDLER]: BetterAuthRegistration<Session>;
18
+ };
19
+ export type InferBetterAuthSession<Handler> = Handler extends BetterAuthHandler<infer Session> ? Session : never;
20
+ export interface BetterAuthAdapterOptions {
21
+ readonly protected?: readonly string[];
22
+ }
23
+ export declare function betterAuthAdapter<Session>(auth: BetterAuthLike<Session>, options?: BetterAuthAdapterOptions): BetterAuthHandler<Session>;
24
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAErD,eAAO,MAAM,mBAAmB,eAA2C,CAAC;AAE5E,MAAM,WAAW,cAAc,CAAC,OAAO,GAAG,OAAO;IAC/C,QAAQ,CAAC,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC1D,QAAQ,CAAC,GAAG,EAAE;QACZ,QAAQ,CAAC,UAAU,EAAE,CAAC,OAAO,EAAE;YAAE,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;SAAE,KAAK,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;KAC1F,CAAC;CACH;AAED,MAAM,WAAW,sBAAsB,CAAC,OAAO,GAAG,OAAO;IACvD,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC;IACvC,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;CACvC;AAED,MAAM,MAAM,iBAAiB,CAAC,OAAO,GAAG,OAAO,IAAI,cAAc,GAAG;IAClE,QAAQ,CAAC,CAAC,mBAAmB,CAAC,EAAE,sBAAsB,CAAC,OAAO,CAAC,CAAC;CACjE,CAAC;AAEF,MAAM,MAAM,sBAAsB,CAAC,OAAO,IACxC,OAAO,SAAS,iBAAiB,CAAC,MAAM,OAAO,CAAC,GAAG,OAAO,GAAG,KAAK,CAAC;AAErE,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACxC;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EACvC,IAAI,EAAE,cAAc,CAAC,OAAO,CAAC,EAC7B,OAAO,GAAE,wBAA6B,GACrC,iBAAiB,CAAC,OAAO,CAAC,CAa5B"}
package/dist/index.js ADDED
@@ -0,0 +1,23 @@
1
+ export const BETTER_AUTH_HANDLER = Symbol.for("relkit.better-auth.handler");
2
+ export function betterAuthAdapter(auth, options = {}) {
3
+ if (typeof auth?.handler !== "function" || typeof auth.api?.getSession !== "function") {
4
+ throw new TypeError("betterAuthAdapter requires a Better Auth instance");
5
+ }
6
+ const protectedPaths = Object.freeze([...new Set(options.protected ?? [])].map(validatePattern).sort());
7
+ const handler = ((request) => auth.handler(request));
8
+ Object.defineProperty(handler, BETTER_AUTH_HANDLER, {
9
+ value: Object.freeze({ kind: "better-auth", auth, protected: protectedPaths }),
10
+ enumerable: false,
11
+ });
12
+ return Object.freeze(handler);
13
+ }
14
+ function validatePattern(value) {
15
+ if (!value.startsWith("/") || value.includes("?") || value.includes("#")) {
16
+ throw new TypeError(`Invalid protected route pattern "${value}"`);
17
+ }
18
+ if (value.includes("*") && !value.endsWith("/*")) {
19
+ throw new TypeError(`Protected route wildcard must end the pattern: "${value}"`);
20
+ }
21
+ return value;
22
+ }
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CAAC,GAAG,C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,mDAAmD,KAAK,GAAG,CAAC,CAAC;IACnF,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@relkit/better-auth",
3
+ "version": "0.0.0",
4
+ "description": "Better Auth integration for RELKIT routes.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/rel-kit/relkit.git",
9
+ "directory": "packages/better-auth"
10
+ },
11
+ "homepage": "https://github.com/rel-kit/relkit#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/rel-kit/relkit/issues"
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "publishConfig": {
19
+ "access": "public"
20
+ },
21
+ "engines": {
22
+ "bun": ">=1.3.10"
23
+ },
24
+ "type": "module",
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/index.d.ts",
28
+ "import": "./dist/index.js"
29
+ }
30
+ },
31
+ "dependencies": {
32
+ "@relkit/routes": "0.0.0",
33
+ "better-auth": "1.7.1"
34
+ },
35
+ "scripts": {
36
+ "build": "tsc -b",
37
+ "check": "tsc -b --pretty false",
38
+ "typecheck": "tsc -b --pretty false"
39
+ }
40
+ }