@farm.js/better-auth 0.1.61 → 0.1.62

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/dist/index.d.ts CHANGED
@@ -1,20 +1,40 @@
1
1
  import type { FarmIntegrationLogger } from "@farm.js/core";
2
2
  export interface BetterAuthInstance {
3
3
  handler(request: Request): Promise<Response> | Response;
4
+ /** Present on every `betterAuth()` instance; Farm reads sessions through it. */
5
+ api?: {
6
+ getSession?(input: {
7
+ headers: Headers;
8
+ }): Promise<unknown> | unknown;
9
+ };
4
10
  }
5
11
  export interface BetterAuthIntegrationInput {
6
12
  instance: BetterAuthInstance;
7
13
  log?: FarmIntegrationLogger;
8
14
  }
9
- export declare function betterAuth(input: BetterAuthIntegrationInput): import("@farm.js/core").DefinedIntegration<{
10
- category: "auth";
15
+ /** What Farm's session contract reads: the session id, its user, and when it expires. */
16
+ export interface BetterAuthIntegrationSession {
17
+ id: string;
18
+ userId?: string;
19
+ expiresAt?: Date;
20
+ }
21
+ export declare function betterAuth(input: BetterAuthIntegrationInput): {
22
+ /**
23
+ * Who the request's cookies sign in, through Better Auth's `api.getSession`. Mobile session
24
+ * tokens use it to issue and refresh native screens' device tokens.
25
+ */
26
+ session(request: Request): Promise<BetterAuthIntegrationSession | null>;
11
27
  type: string;
12
- instance: BetterAuthInstance;
13
28
  log: import("@farm.js/core/integrations").FarmIntegrationLogger | undefined;
29
+ instance: BetterAuthInstance;
14
30
  routes: {
15
31
  path: string;
16
32
  methods: import("@farm.js/core/integrations").FarmIntegrationRouteMethod[];
17
33
  handler(request: Request, context: import("@farm.js/core").FarmIntegrationHandlerContext): Response | Promise<Response>;
18
34
  }[];
19
- }>;
35
+ kind: "farm-integration";
36
+ category: import("@farm.js/core").FarmIntegrationCategory;
37
+ slot: import("@farm.js/core").FarmIntegrationCategory;
38
+ api: import("@farm.js/core").FarmIntegrationAPI | undefined;
39
+ };
20
40
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAG3D,MAAM,WAAW,kBAAkB;IACjC,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAC;CACzD;AAED,MAAM,WAAW,0BAA0B;IACzC,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,GAAG,CAAC,EAAE,qBAAqB,CAAC;CAC7B;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,0BAA0B;;;;;;;;;;GAW3D"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAG3D,MAAM,WAAW,kBAAkB;IACjC,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAC;IACxD,gFAAgF;IAChF,GAAG,CAAC,EAAE;QACJ,UAAU,CAAC,CAAC,KAAK,EAAE;YAAE,OAAO,EAAE,OAAO,CAAA;SAAE,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;KACtE,CAAC;CACH;AAED,MAAM,WAAW,0BAA0B;IACzC,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,GAAG,CAAC,EAAE,qBAAqB,CAAC;CAC7B;AAED,yFAAyF;AACzF,MAAM,WAAW,4BAA4B;IAC3C,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,IAAI,CAAC;CAClB;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,0BAA0B;IAaxD;;;OAGG;qBACoB,OAAO,GAAG,OAAO,CAAC,4BAA4B,GAAG,IAAI,CAAC;;;;;;;;;;;;;EAkBhF"}
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { createAuthRouteIntegration } from "@farm.js/integration-utils";
2
2
  export function betterAuth(input) {
3
- return createAuthRouteIntegration({
3
+ const integration = createAuthRouteIntegration({
4
4
  type: "better-auth",
5
5
  instance: input.instance,
6
6
  log: input.log,
@@ -10,4 +10,29 @@ export function betterAuth(input) {
10
10
  return input.instance.handler(request);
11
11
  },
12
12
  });
13
+ return {
14
+ ...integration,
15
+ /**
16
+ * Who the request's cookies sign in, through Better Auth's `api.getSession`. Mobile session
17
+ * tokens use it to issue and refresh native screens' device tokens.
18
+ */
19
+ async session(request) {
20
+ const getSession = input.instance.api?.getSession;
21
+ if (typeof getSession !== "function")
22
+ return null;
23
+ const result = (await getSession.call(input.instance.api, {
24
+ headers: request.headers,
25
+ }));
26
+ const session = result?.session;
27
+ if (!session || typeof session.id !== "string")
28
+ return null;
29
+ return {
30
+ id: session.id,
31
+ userId: typeof session.userId === "string" ? session.userId : undefined,
32
+ expiresAt: session.expiresAt === undefined
33
+ ? undefined
34
+ : new Date(session.expiresAt),
35
+ };
36
+ },
37
+ };
13
38
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farm.js/better-auth",
3
- "version": "0.1.61",
3
+ "version": "0.1.62",
4
4
  "description": "Better Auth integration for Farm.js",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -25,8 +25,8 @@
25
25
  "access": "public"
26
26
  },
27
27
  "dependencies": {
28
- "@farm.js/core": "0.1.61",
29
- "@farm.js/integration-utils": "0.1.61"
28
+ "@farm.js/core": "0.1.62",
29
+ "@farm.js/integration-utils": "0.1.62"
30
30
  },
31
31
  "scripts": {
32
32
  "build": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\" && tsc",