@rolder/kit-better-auth 0.1.0-alpha.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.
Files changed (39) hide show
  1. package/dist/client/index.d.ts +1 -0
  2. package/dist/client/tanstack/index.d.ts +1 -0
  3. package/dist/client/tanstack/useSessionUser.d.ts +1 -0
  4. package/dist/index.d.ts +2 -0
  5. package/dist/index.js +2 -0
  6. package/dist/server/defaultAuthServerConfig.d.ts +33 -0
  7. package/dist/server/env.d.ts +1 -0
  8. package/dist/server/index.d.ts +9 -0
  9. package/dist/server/surrealDbAdapter/adapter.d.ts +8 -0
  10. package/dist/server/surrealDbAdapter/db/getDB.d.ts +2 -0
  11. package/dist/server/surrealDbAdapter/db/getDBInstance.d.ts +3 -0
  12. package/dist/server/surrealDbAdapter/db/index.d.ts +1 -0
  13. package/dist/server/surrealDbAdapter/db/schema.d.ts +1 -0
  14. package/dist/server/surrealDbAdapter/index.d.ts +1 -0
  15. package/dist/server/surrealDbAdapter/methods/count.d.ts +2 -0
  16. package/dist/server/surrealDbAdapter/methods/create.d.ts +2 -0
  17. package/dist/server/surrealDbAdapter/methods/delete.d.ts +2 -0
  18. package/dist/server/surrealDbAdapter/methods/deleteMany.d.ts +2 -0
  19. package/dist/server/surrealDbAdapter/methods/findMany.d.ts +2 -0
  20. package/dist/server/surrealDbAdapter/methods/findOne.d.ts +2 -0
  21. package/dist/server/surrealDbAdapter/methods/index.d.ts +8 -0
  22. package/dist/server/surrealDbAdapter/methods/types.d.ts +56 -0
  23. package/dist/server/surrealDbAdapter/methods/update.d.ts +2 -0
  24. package/dist/server/surrealDbAdapter/methods/updateMany.d.ts +2 -0
  25. package/dist/server/surrealDbAdapter/types.d.ts +2 -0
  26. package/dist/server/surrealDbAdapter/utils/applyJoinMappings.d.ts +2 -0
  27. package/dist/server/surrealDbAdapter/utils/buildExpression.d.ts +3 -0
  28. package/dist/server/surrealDbAdapter/utils/buildJoinPlan.d.ts +9 -0
  29. package/dist/server/surrealDbAdapter/utils/buildSelectFields.d.ts +1 -0
  30. package/dist/server/surrealDbAdapter/utils/index.d.ts +6 -0
  31. package/dist/server/surrealDbAdapter/utils/normalizeOutputRecordIds.d.ts +2 -0
  32. package/dist/server/surrealDbAdapter/utils/normalizeRecordIds.d.ts +2 -0
  33. package/dist/server/surrealDbAdapter/utils/normalizeWhereValue.d.ts +2 -0
  34. package/dist/server/surrealDbAdapter/utils/types.d.ts +34 -0
  35. package/dist/server/tanstack/getSessionTokenTanstack.d.ts +1 -0
  36. package/dist/server/tanstack/getSessionUserTanstack.d.ts +1 -0
  37. package/dist/server/tanstack/index.d.ts +2 -0
  38. package/dist/server/types.d.ts +8 -0
  39. package/package.json +30 -0
@@ -0,0 +1 @@
1
+ export * from './tanstack';
@@ -0,0 +1 @@
1
+ export * from './useSessionUser';
@@ -0,0 +1 @@
1
+ export declare const useSessionUser: <TUser = unknown>() => TUser | undefined;
@@ -0,0 +1,2 @@
1
+ export * from './client';
2
+ export * from './server';
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./client/index.js";
2
+ export * from "./server/index.js";
@@ -0,0 +1,33 @@
1
+ export declare const defaultAuthServerPluginOptions: {
2
+ admin: {
3
+ bannedUserMessage: string;
4
+ };
5
+ surrealDBjwt: {
6
+ jwks: {
7
+ keyPairConfig: {
8
+ alg: "EdDSA";
9
+ crv: "Ed25519";
10
+ };
11
+ };
12
+ jwt: {
13
+ issuer: string;
14
+ audience: string;
15
+ expirationTime: string;
16
+ definePayload: () => {
17
+ ns: string | undefined;
18
+ db: string | undefined;
19
+ ac: string;
20
+ };
21
+ };
22
+ };
23
+ };
24
+ export declare const defaultAuthServerConfig: {
25
+ baseURL: string;
26
+ secret: string | undefined;
27
+ };
28
+ export declare const defaultSurrealDBAdaperConfig: {
29
+ database: (options: Parameters<import("better-auth/adapters").AdapterFactory>[0]) => import("better-auth").DBAdapter<import("better-auth").BetterAuthOptions>;
30
+ experimental: {
31
+ joins: boolean;
32
+ };
33
+ };
@@ -0,0 +1 @@
1
+ export declare const baseUrl: string;
@@ -0,0 +1,9 @@
1
+ export * from 'better-auth/client/plugins';
2
+ export { betterAuth as betterAuthServer } from 'better-auth/minimal';
3
+ export * from 'better-auth/plugins';
4
+ export * from 'better-auth/plugins/admin/access';
5
+ export * from 'better-auth/react';
6
+ export { tanstackStartCookies } from 'better-auth/tanstack-start';
7
+ export * from './defaultAuthServerConfig';
8
+ export * from './tanstack';
9
+ export * from './types';
@@ -0,0 +1,8 @@
1
+ import type { SurrealDBProps } from '@rolder/kit-surreal-db';
2
+ import { type DBAdapterDebugLogOption } from 'better-auth/adapters';
3
+ type SurrealAdapterConfig = {
4
+ surrealDbProps?: SurrealDBProps;
5
+ debugLogs?: DBAdapterDebugLogOption | boolean;
6
+ };
7
+ export declare const surrealDbAdapter: ({ surrealDbProps, debugLogs, }?: SurrealAdapterConfig | undefined) => (options: Parameters<import("better-auth/adapters").AdapterFactory>[0]) => import("better-auth").DBAdapter<import("better-auth").BetterAuthOptions>;
8
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { SurrealDBProps } from '@rolder/kit-surreal-db';
2
+ export declare const getDb: (props?: SurrealDBProps) => Promise<import("surrealdb").Surreal>;
@@ -0,0 +1,3 @@
1
+ import type { SurrealDBProps } from '@rolder/kit-surreal-db';
2
+ import { Surreal } from 'surrealdb';
3
+ export declare const getDBInstance: (params?: SurrealDBProps | undefined) => Promise<Surreal>;
@@ -0,0 +1 @@
1
+ export * from './getDB';
@@ -0,0 +1 @@
1
+ export declare const schema = "\n// Better Auth JWT Access\nDEFINE ACCESS IF NOT EXISTS better_auth_jwt ON DATABASE TYPE RECORD\n WITH JWT URL $BETTER_AUTH_JWKS_URL\n AUTHENTICATE {\n IF $token.sub {\n RETURN SELECT * FROM ONLY <RECORD>(\"user:\"+ $token.sub);\n } ELSE {\n THROW \"There is no user id at $token.sub\"\n }\n }\n;\n\n// User\nDEFINE TABLE IF NOT EXISTS user TYPE NORMAL SCHEMAFULL PERMISSIONS FULL;\nDEFINE FIELD IF NOT EXISTS name ON user TYPE string;\nDEFINE FIELD IF NOT EXISTS email ON user TYPE option<string> ASSERT $value = NONE OR string::is_email($value);\nDEFINE FIELD IF NOT EXISTS email_address ON user TYPE option<string> ASSERT $value = NONE OR string::is_email($value);\nDEFINE INDEX IF NOT EXISTS userUserUnique ON user COLUMNS email UNIQUE;\nDEFINE FIELD IF NOT EXISTS emailVerified ON user TYPE bool;\nDEFINE FIELD IF NOT EXISTS image ON user TYPE option<string>;\nDEFINE FIELD IF NOT EXISTS createdAt ON user TYPE option<datetime> DEFAULT time::now();\nDEFINE FIELD IF NOT EXISTS updatedAt ON user TYPE option<datetime> DEFAULT time::now();\n-- Admin plugin\nDEFINE FIELD IF NOT EXISTS role ON user TYPE option<string>;\nDEFINE FIELD IF NOT EXISTS banned ON user TYPE option<bool>;\nDEFINE FIELD IF NOT EXISTS banReason ON user TYPE option<string> | NULL;\nDEFINE FIELD IF NOT EXISTS banExpires ON user TYPE option<datetime> | NULL;\n-- Username plugin\nDEFINE FIELD IF NOT EXISTS username ON user TYPE option<string>;\nDEFINE FIELD IF NOT EXISTS displayUsername ON user TYPE option<string>;\n-- Custom\nDEFINE FIELD IF NOT EXISTS accounts ON user COMPUTED <~account;\nDEFINE FIELD IF NOT EXISTS sessions ON user COMPUTED <~session;\n\n-- // Session\nDEFINE TABLE IF NOT EXISTS session TYPE NORMAL SCHEMAFULL PERMISSIONS FULL;\nDEFINE FIELD IF NOT EXISTS expiresAt ON session TYPE datetime;\nDEFINE FIELD IF NOT EXISTS token ON session TYPE string;\nDEFINE INDEX IF NOT EXISTS sessionSessionUnique ON session COLUMNS token UNIQUE;\nDEFINE FIELD IF NOT EXISTS createdAt ON session TYPE option<datetime> DEFAULT time::now();\nDEFINE FIELD IF NOT EXISTS updatedAt ON session TYPE option<datetime> DEFAULT time::now();\nDEFINE FIELD IF NOT EXISTS ipAddress ON session TYPE option<string>;\nDEFINE FIELD IF NOT EXISTS userAgent ON session TYPE option<string>;\nDEFINE FIELD IF NOT EXISTS userId ON session TYPE record<user> REFERENCE ON DELETE IGNORE;\n-- Admin plugin\nDEFINE FIELD IF NOT EXISTS impersonatedBy ON user TYPE option<record<user>>;\n\n-- // Account\nDEFINE TABLE IF NOT EXISTS account TYPE NORMAL SCHEMAFULL PERMISSIONS FULL;\nDEFINE FIELD IF NOT EXISTS accountId ON account TYPE string;\nDEFINE FIELD IF NOT EXISTS providerId ON account TYPE string;\nDEFINE FIELD IF NOT EXISTS accessToken ON account TYPE option<string>;\nDEFINE FIELD IF NOT EXISTS refreshToken ON account TYPE option<string>;\nDEFINE FIELD IF NOT EXISTS idToken ON account TYPE option<string>;\nDEFINE FIELD IF NOT EXISTS accessTokenExpiresAt ON account TYPE option<datetime>;\nDEFINE FIELD IF NOT EXISTS refreshTokenExpiresAt ON account TYPE option<datetime>;\nDEFINE FIELD IF NOT EXISTS scope ON account TYPE option<string>;\nDEFINE FIELD IF NOT EXISTS password ON account TYPE option<string>;\nDEFINE FIELD IF NOT EXISTS createdAt ON account TYPE option<datetime> DEFAULT time::now();\nDEFINE FIELD IF NOT EXISTS updatedAt ON account TYPE option<datetime> DEFAULT time::now();\n-- Custom\nDEFINE FIELD IF NOT EXISTS userId ON account TYPE record<user> REFERENCE ON DELETE IGNORE;\n\n// Verification\nDEFINE TABLE IF NOT EXISTS verification TYPE NORMAL SCHEMAFULL PERMISSIONS FULL;\nDEFINE FIELD IF NOT EXISTS identifier ON verification TYPE string;\nDEFINE FIELD IF NOT EXISTS value ON verification TYPE string;\nDEFINE FIELD IF NOT EXISTS expiresAt ON verification TYPE datetime;\nDEFINE FIELD IF NOT EXISTS createdAt ON verification TYPE option<datetime> DEFAULT time::now();\nDEFINE FIELD IF NOT EXISTS updatedAt ON verification TYPE option<datetime> DEFAULT time::now();\n\n// JWKS\nDEFINE TABLE IF NOT EXISTS jwks TYPE NORMAL SCHEMAFULL PERMISSIONS FULL;\nDEFINE FIELD IF NOT EXISTS publicKey ON jwks TYPE string;\nDEFINE FIELD IF NOT EXISTS privateKey ON jwks TYPE string;\nDEFINE FIELD IF NOT EXISTS createdAt ON jwks TYPE option<datetime> DEFAULT time::now();\nDEFINE FIELD IF NOT EXISTS updatedAt ON jwks TYPE option<datetime> DEFAULT time::now();\n\n// Root auth user\nIF !user:root.* {\n CREATE user:root CONTENT {\n \tname: '\u0421\u0438\u0441\u0442\u0435\u043C\u043D\u0430\u044F \u0443\u0447\u0435\u0442\u043D\u0430\u044F \u0437\u0430\u043F\u0438\u0441\u044C',\n \trole: 'admin',\n \tusername: 'root',\n \tdisplayUsername: 'Root',\n \temail: 'mail@rolder.dev',\n \temailVerified: true,\n \tbanned: false,\n };\n};\n\nIF !account:root.* {\n CREATE account:root CONTENT {\n \taccountId: 'root',\n \tuserId: user:root,\n \tpassword: '52c2da6bc1a525ee0f6a298e228a1314:c7ba714b9467d4582c5848947c2536340ff9f85ff6ca6c9ee022f68cd5eb60e227ba0cbadd3d46e9316c4562cef9d7551c957192809bf2a4b27f2a2b1365a08e',\n providerId: 'credential',\n };\n};";
@@ -0,0 +1 @@
1
+ export * from './adapter';
@@ -0,0 +1,2 @@
1
+ import type { Count } from './types';
2
+ export declare const count: ({ model, where, surrealDbProps, ...args }: Count) => Promise<number>;
@@ -0,0 +1,2 @@
1
+ import type { Create } from './types';
2
+ export declare const create: <T extends Record<string, unknown>>({ model, data, surrealDbProps, ...args }: Create<T>) => Promise<T>;
@@ -0,0 +1,2 @@
1
+ import type { Delete } from './types';
2
+ export declare const deleteFn: ({ model, where, surrealDbProps, ...args }: Delete) => Promise<void>;
@@ -0,0 +1,2 @@
1
+ import type { DeleteMany } from './types';
2
+ export declare const deleteMany: ({ model, where, surrealDbProps, ...args }: DeleteMany) => Promise<number>;
@@ -0,0 +1,2 @@
1
+ import type { FindMany } from './types';
2
+ export declare const findMany: <T>({ model, where, limit, offset, sortBy, join, surrealDbProps, ...args }: FindMany) => Promise<T[]>;
@@ -0,0 +1,2 @@
1
+ import type { FindOne } from './types';
2
+ export declare const findOne: <T>({ model, where, select, join, surrealDbProps, ...args }: FindOne) => Promise<T | null>;
@@ -0,0 +1,8 @@
1
+ export * from './count';
2
+ export * from './create';
3
+ export * from './delete';
4
+ export * from './deleteMany';
5
+ export * from './findMany';
6
+ export * from './findOne';
7
+ export * from './update';
8
+ export * from './updateMany';
@@ -0,0 +1,56 @@
1
+ import type { SurrealDBProps } from '@rolder/kit-surreal-db';
2
+ import type { AdapterFactoryCustomizeAdapterCreator, JoinConfig, Where } from 'better-auth/adapters';
3
+ type Args = Parameters<AdapterFactoryCustomizeAdapterCreator>[0];
4
+ export type Create<T> = Args & {
5
+ model: string;
6
+ data: T;
7
+ surrealDbProps?: SurrealDBProps;
8
+ };
9
+ export type FindOne = Args & {
10
+ model: string;
11
+ where: Required<Where>[];
12
+ select?: string[];
13
+ join?: JoinConfig;
14
+ surrealDbProps?: SurrealDBProps;
15
+ };
16
+ export type SortBy = {
17
+ field: string;
18
+ direction: 'asc' | 'desc';
19
+ };
20
+ export type FindMany = Args & {
21
+ model: string;
22
+ where?: Required<Where>[];
23
+ limit: number;
24
+ offset?: number;
25
+ sortBy?: SortBy;
26
+ join?: JoinConfig;
27
+ surrealDbProps?: SurrealDBProps;
28
+ };
29
+ export type Update<T> = Args & {
30
+ model: string;
31
+ where: Required<Where>[];
32
+ update: T;
33
+ surrealDbProps?: SurrealDBProps;
34
+ };
35
+ export type UpdateMany = Args & {
36
+ model: string;
37
+ where: Required<Where>[];
38
+ update: Record<string, unknown>;
39
+ surrealDbProps?: SurrealDBProps;
40
+ };
41
+ export type Delete = Args & {
42
+ model: string;
43
+ where: Required<Where>[];
44
+ surrealDbProps?: SurrealDBProps;
45
+ };
46
+ export type DeleteMany = Args & {
47
+ model: string;
48
+ where: Required<Where>[];
49
+ surrealDbProps?: SurrealDBProps;
50
+ };
51
+ export type Count = Args & {
52
+ model: string;
53
+ where?: Required<Where>[];
54
+ surrealDbProps?: SurrealDBProps;
55
+ };
56
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { Update } from './types';
2
+ export declare const update: <T>({ model, where, update, surrealDbProps, ...args }: Update<T>) => Promise<T | null>;
@@ -0,0 +1,2 @@
1
+ import type { UpdateMany } from './types';
2
+ export declare const updateMany: ({ model, where, update, surrealDbProps, ...args }: UpdateMany) => Promise<number>;
@@ -0,0 +1,2 @@
1
+ import type { AdapterFactoryCustomizeAdapterCreator } from 'better-auth/adapters';
2
+ export type Args = Parameters<AdapterFactoryCustomizeAdapterCreator>[0];
@@ -0,0 +1,2 @@
1
+ import type { ApplyJoinMappings } from './types';
2
+ export declare const applyJoinMappings: ({ row, mappings, ...args }: ApplyJoinMappings) => object | null;
@@ -0,0 +1,3 @@
1
+ import { type Expr } from 'surrealdb';
2
+ import type { BuildExpression } from './types';
3
+ export declare const buildExpression: ({ model, where, ...args }: BuildExpression) => Expr | undefined;
@@ -0,0 +1,9 @@
1
+ import type { BuildJoinPlan } from './types';
2
+ export declare const buildJoinPlan: ({ model, join, getDefaultModelName, }: BuildJoinPlan) => {
3
+ selectFields: string[];
4
+ fetchFields: Set<string>;
5
+ mappings: {
6
+ modelName: string;
7
+ sourceField: string;
8
+ }[];
9
+ };
@@ -0,0 +1 @@
1
+ export declare const buildSelectFields: (select: string[] | undefined, mapField: (field: string) => string) => string;
@@ -0,0 +1,6 @@
1
+ export * from './applyJoinMappings';
2
+ export * from './buildExpression';
3
+ export * from './buildJoinPlan';
4
+ export * from './buildSelectFields';
5
+ export * from './normalizeOutputRecordIds';
6
+ export * from './normalizeRecordIds';
@@ -0,0 +1,2 @@
1
+ import type { NormalizeOutputRecordIds } from './types';
2
+ export declare const normalizeOutputRecordIds: ({ model, data, getDefaultModelName, getDefaultFieldName, getFieldAttributes, }: NormalizeOutputRecordIds) => Record<string, unknown> | null;
@@ -0,0 +1,2 @@
1
+ import type { NormalizeRecordIds } from './types';
2
+ export declare const normalizeRecordIds: ({ model, data, getDefaultModelName, getDefaultFieldName, getFieldAttributes, getModelName, }: NormalizeRecordIds) => Record<string, unknown>;
@@ -0,0 +1,2 @@
1
+ import type { NormalizeWhereValue } from './types';
2
+ export declare const normalizeWhereValue: ({ model, field, value, getDefaultModelName, getDefaultFieldName, getModelName, getFieldAttributes, }: NormalizeWhereValue) => unknown;
@@ -0,0 +1,34 @@
1
+ import type { JoinConfig, Where } from 'better-auth/adapters';
2
+ import type { Args } from '../types';
3
+ export type NormalizeRecordIds = Args & {
4
+ model: string;
5
+ data: object;
6
+ };
7
+ export type NormalizeOutputRecordIds = Args & {
8
+ model: string;
9
+ data: object | null;
10
+ };
11
+ export type NormalizeWhereValue = Args & {
12
+ model: string;
13
+ field: string;
14
+ value: unknown;
15
+ };
16
+ export type BuildExpression = Args & {
17
+ model: string;
18
+ where: Required<Where>[] | undefined;
19
+ };
20
+ export type BuildJoinPlan = Args & {
21
+ model: string;
22
+ join?: JoinConfig;
23
+ };
24
+ export type ApplyJoinMappings = Args & {
25
+ row: object | null;
26
+ mappings: Array<{
27
+ modelName: string;
28
+ sourceField: string;
29
+ }>;
30
+ };
31
+ export type SortBy = {
32
+ field: string;
33
+ direction: 'asc' | 'desc';
34
+ };
@@ -0,0 +1 @@
1
+ export declare const getSessionTokenTanstack: import("@tanstack/react-start").OptionalFetcher<undefined, undefined, Promise<string | undefined>>;
@@ -0,0 +1 @@
1
+ export declare function getSessionUser<TUser = unknown>(): Promise<TUser | undefined>;
@@ -0,0 +1,2 @@
1
+ export * from './getSessionTokenTanstack';
2
+ export * from './getSessionUserTanstack';
@@ -0,0 +1,8 @@
1
+ export type * from 'better-auth/client/plugins';
2
+ export type * from 'better-auth/minimal';
3
+ export type * from 'better-auth/plugins';
4
+ export type InferUserWithRoles<TInferredUser extends {
5
+ role?: string | null;
6
+ }, TRoles extends Record<string, unknown>> = Omit<TInferredUser, 'role'> & {
7
+ role: keyof TRoles;
8
+ };
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@rolder/kit-better-auth",
3
+ "version": "0.1.0-alpha.0",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": {
7
+ "types": "./dist/index.d.ts",
8
+ "import": "./dist/index.js"
9
+ }
10
+ },
11
+ "sideEffects": false,
12
+ "files": [
13
+ "dist"
14
+ ],
15
+ "scripts": {
16
+ "build": "rslib build",
17
+ "dev": "rslib build --watch",
18
+ "prepublishOnly": "bun run build",
19
+ "check": "biome check --write && tsc --noEmit"
20
+ },
21
+ "devDependencies": {
22
+ "@rolder/kit-surreal-db": "0.1.0-alpha.0"
23
+ },
24
+ "dependencies": {
25
+ "better-auth": "^1.4.18"
26
+ },
27
+ "peerDependencies": {
28
+ "@rolder/kit-surreal-db": "*"
29
+ }
30
+ }