@jazim/test 2.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) 2025
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,143 @@
1
+ # TypeORM Adapter for Better-Auth
2
+
3
+ A TypeORM database adapter for [Better-Auth](https://github.com/better-auth/better-auth), providing seamless authentication with TypeORM.
4
+
5
+ ## Features
6
+
7
+ - ✅ Full TypeORM integration
8
+ - ✅ TypeScript support with full type safety
9
+ - ✅ Schema generation via Better-Auth CLI
10
+ - ✅ Configurable table names (singular/plural)
11
+ - ✅ Transaction support
12
+ - ✅ Supports all major databases (PostgreSQL, MySQL, SQLite, SQL Server, Oracle, MongoDB)
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ npm install typeorm-adapter-betterauth typeorm better-auth
18
+ # or
19
+ pnpm add typeorm-adapter-betterauth typeorm better-auth
20
+ # or
21
+ yarn add typeorm-adapter-betterauth typeorm better-auth
22
+ ```
23
+
24
+ ## Quick Start
25
+
26
+ ### 1. Generate TypeORM Entities and Migrations
27
+
28
+ Run the Better-Auth CLI to generate TypeORM entity and migration files:
29
+
30
+ ```bash
31
+ npx @better-auth/cli@latest generate
32
+ ```
33
+
34
+ This will create:
35
+ - **Entity file** (e.g., `auth-schema.ts`) with TypeORM decorators for all Better-Auth tables
36
+ - **Migration file** (e.g., `migrations/1234567890-InitialSchema.ts`) for creating tables in production
37
+
38
+ ### 2. Set Up TypeORM DataSource
39
+
40
+ Import the generated entities and create your DataSource:
41
+
42
+ ```typescript
43
+ import { DataSource } from \"typeorm\";
44
+ import { User, Session, Account, Verification } from \"./auth-schema\"; // generated file
45
+
46
+ const dataSource = new DataSource({
47
+ type: \"postgres\", // or \"mysql\", \"sqlite\", etc.
48
+ host: \"localhost\",
49
+ port: 5432,
50
+ username: \"user\",
51
+ password: \"password\",
52
+ database: \"myapp\",
53
+ entities: [User, Session, Account, Verification],
54
+ migrations: [\"./migrations/*.ts\"], // Include generated migrations
55
+ synchronize: false, // Use migrations in production
56
+ });
57
+
58
+ await dataSource.initialize();
59
+ ```
60
+
61
+ ### 3. Run Migrations
62
+
63
+ For production, run migrations instead of using `synchronize: true`:
64
+
65
+ ```bash
66
+ # Run migrations
67
+ npx typeorm migration:run -d ./data-source.ts
68
+
69
+ # Revert last migration
70
+ npx typeorm migration:revert -d ./data-source.ts
71
+ ```
72
+
73
+ ### 4. Initialize Better-Auth with TypeORM Adapter
74
+
75
+ ```typescript
76
+ import { betterAuth } from \"better-auth\";
77
+ import { typeormAdapter } from \"typeorm-adapter-betterauth\";
78
+
79
+ const auth = betterAuth({
80
+ database: typeormAdapter(dataSource, {
81
+ provider: \"postgres\", // must match your DataSource type
82
+ }),
83
+ // ... other better-auth config
84
+ });
85
+ ```
86
+
87
+ ## Configuration
88
+
89
+ ### Adapter Options
90
+
91
+ ```typescript
92
+ typeormAdapter(dataSource, {
93
+ provider: \"postgres\", // Required: \"postgres\" | \"mysql\" | \"sqlite\" | \"mssql\" | \"oracle\" | \"mongodb\"
94
+ usePlural: false, // Use plural table names (users, sessions, etc.)
95
+ debugLogs: false, // Enable debug logs
96
+ transaction: false, // Enable transaction support
97
+ });
98
+ ```
99
+
100
+ ## Complete Example
101
+
102
+ ```typescript
103
+ import { betterAuth } from \"better-auth\";
104
+ import { typeormAdapter } from \"typeorm-adapter-betterauth\";
105
+ import { DataSource } from \"typeorm\";
106
+ import { User, Session, Account, Verification } from \"./auth-schema\";
107
+
108
+ // 1. Create DataSource
109
+ const dataSource = new DataSource({
110
+ type: \"postgres\",
111
+ host: process.env.DB_HOST,
112
+ port: parseInt(process.env.DB_PORT || \"5432\"),
113
+ username: process.env.DB_USER,
114
+ password: process.env.DB_PASSWORD,
115
+ database: process.env.DB_NAME,
116
+ entities: [User, Session, Account, Verification],
117
+ migrations: [\"./migrations/*.ts\"],
118
+ synchronize: false, // Use migrations in production
119
+ logging: process.env.NODE_ENV !== \"production\",
120
+ });
121
+
122
+ await dataSource.initialize();
123
+
124
+ // Run migrations in production
125
+ if (process.env.NODE_ENV === \"production\") {
126
+ await dataSource.runMigrations();
127
+ }
128
+
129
+ // 2. Create Better-Auth instance
130
+ export const auth = betterAuth({
131
+ database: typeormAdapter(dataSource, {
132
+ provider: \"postgres\",
133
+ transaction: true,
134
+ }),
135
+ emailAndPassword: {
136
+ enabled: true,
137
+ },
138
+ });
139
+ ```
140
+
141
+ ## License
142
+
143
+ MIT
@@ -0,0 +1,53 @@
1
+ import * as better_auth from 'better-auth';
2
+ import { BetterAuthOptions } from 'better-auth';
3
+ import { DataSource } from 'typeorm';
4
+ import { AdapterFactoryConfig } from 'better-auth/adapters';
5
+
6
+ type Provider = "mysql" | "postgres" | "sqlite";
7
+ interface TypeOrmAdapterConfig extends Pick<AdapterFactoryConfig, "debugLogs" | "usePlural" | "transaction"> {
8
+ /**
9
+ * Database provider.
10
+ *
11
+ * @default "postgres"
12
+ */
13
+ provider?: Provider;
14
+ /**
15
+ * Custom entity names for the adapter models.
16
+ *
17
+ * @default
18
+ * {
19
+ * user: "User",
20
+ * account: "Account",
21
+ * session: "Session",
22
+ * verification: "Verification"
23
+ * }
24
+ */
25
+ entities?: {
26
+ user?: string;
27
+ account?: string;
28
+ session?: string;
29
+ verification?: string;
30
+ };
31
+ /**
32
+ * Generate entities and migrations files.
33
+ * @default true
34
+ */
35
+ generateEntities?: boolean;
36
+ /**
37
+ * Generate migration files.
38
+ * @default true
39
+ */
40
+ generateMigrations?: boolean;
41
+ /**
42
+ * Path to save generated entities
43
+ */
44
+ entitiesPath?: string;
45
+ /**
46
+ * Path to save generated migrations
47
+ */
48
+ migrationsPath?: string;
49
+ }
50
+
51
+ declare const typeormAdapter: (dataSource: DataSource, config?: TypeOrmAdapterConfig) => (options: BetterAuthOptions) => better_auth.DBAdapter<BetterAuthOptions>;
52
+
53
+ export { typeormAdapter };
@@ -0,0 +1,53 @@
1
+ import * as better_auth from 'better-auth';
2
+ import { BetterAuthOptions } from 'better-auth';
3
+ import { DataSource } from 'typeorm';
4
+ import { AdapterFactoryConfig } from 'better-auth/adapters';
5
+
6
+ type Provider = "mysql" | "postgres" | "sqlite";
7
+ interface TypeOrmAdapterConfig extends Pick<AdapterFactoryConfig, "debugLogs" | "usePlural" | "transaction"> {
8
+ /**
9
+ * Database provider.
10
+ *
11
+ * @default "postgres"
12
+ */
13
+ provider?: Provider;
14
+ /**
15
+ * Custom entity names for the adapter models.
16
+ *
17
+ * @default
18
+ * {
19
+ * user: "User",
20
+ * account: "Account",
21
+ * session: "Session",
22
+ * verification: "Verification"
23
+ * }
24
+ */
25
+ entities?: {
26
+ user?: string;
27
+ account?: string;
28
+ session?: string;
29
+ verification?: string;
30
+ };
31
+ /**
32
+ * Generate entities and migrations files.
33
+ * @default true
34
+ */
35
+ generateEntities?: boolean;
36
+ /**
37
+ * Generate migration files.
38
+ * @default true
39
+ */
40
+ generateMigrations?: boolean;
41
+ /**
42
+ * Path to save generated entities
43
+ */
44
+ entitiesPath?: string;
45
+ /**
46
+ * Path to save generated migrations
47
+ */
48
+ migrationsPath?: string;
49
+ }
50
+
51
+ declare const typeormAdapter: (dataSource: DataSource, config?: TypeOrmAdapterConfig) => (options: BetterAuthOptions) => better_auth.DBAdapter<BetterAuthOptions>;
52
+
53
+ export { typeormAdapter };