@objectstack/plugin-auth 4.0.3 → 4.0.5

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 (40) hide show
  1. package/README.md +4 -1
  2. package/dist/index.d.mts +345 -19928
  3. package/dist/index.d.ts +345 -19928
  4. package/dist/index.js +411 -857
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +415 -837
  7. package/dist/index.mjs.map +1 -1
  8. package/package.json +35 -12
  9. package/.turbo/turbo-build.log +0 -78
  10. package/ARCHITECTURE.md +0 -176
  11. package/CHANGELOG.md +0 -325
  12. package/IMPLEMENTATION_SUMMARY.md +0 -192
  13. package/examples/basic-usage.ts +0 -107
  14. package/objectstack.config.ts +0 -24
  15. package/src/auth-manager.test.ts +0 -758
  16. package/src/auth-manager.ts +0 -338
  17. package/src/auth-plugin.test.ts +0 -443
  18. package/src/auth-plugin.ts +0 -292
  19. package/src/auth-schema-config.ts +0 -339
  20. package/src/index.ts +0 -16
  21. package/src/objectql-adapter.test.ts +0 -281
  22. package/src/objectql-adapter.ts +0 -279
  23. package/src/objects/auth-account.object.ts +0 -7
  24. package/src/objects/auth-session.object.ts +0 -7
  25. package/src/objects/auth-user.object.ts +0 -7
  26. package/src/objects/auth-verification.object.ts +0 -7
  27. package/src/objects/index.ts +0 -40
  28. package/src/objects/sys-account.object.ts +0 -111
  29. package/src/objects/sys-api-key.object.ts +0 -104
  30. package/src/objects/sys-invitation.object.ts +0 -93
  31. package/src/objects/sys-member.object.ts +0 -68
  32. package/src/objects/sys-organization.object.ts +0 -82
  33. package/src/objects/sys-session.object.ts +0 -84
  34. package/src/objects/sys-team-member.object.ts +0 -61
  35. package/src/objects/sys-team.object.ts +0 -69
  36. package/src/objects/sys-two-factor.object.ts +0 -73
  37. package/src/objects/sys-user-preference.object.ts +0 -82
  38. package/src/objects/sys-user.object.ts +0 -91
  39. package/src/objects/sys-verification.object.ts +0 -75
  40. package/tsconfig.json +0 -18
@@ -1,78 +0,0 @@
1
-
2
- > @objectstack/plugin-auth@4.0.3 build /home/runner/work/framework/framework/packages/plugins/plugin-auth
3
- > tsup --config ../../../tsup.config.ts
4
-
5
- ▲ [WARNING] The condition "types" here will never be used as it comes after both "import" and "require" [package.json]
6
-
7
- package.json:13:6:
8
- 13 │ "types": "./dist/index.d.ts"
9
- ╵ ~~~~~~~
10
-
11
- The "import" condition comes earlier and will be used for all "import" statements:
12
-
13
- package.json:11:6:
14
- 11 │ "import": "./dist/index.mjs",
15
- ╵ ~~~~~~~~
16
-
17
- The "require" condition comes earlier and will be used for all "require" calls:
18
-
19
- package.json:12:6:
20
- 12 │ "require": "./dist/index.js",
21
- ╵ ~~~~~~~~~
22
-
23
- CLI Building entry: src/index.ts
24
- CLI Using tsconfig: tsconfig.json
25
- CLI tsup v8.5.1
26
- CLI Using tsup config: /home/runner/work/framework/framework/tsup.config.ts
27
- CLI Target: es2020
28
- CLI Cleaning output folder
29
- ESM Build start
30
- CJS Build start
31
- [warn] ▲ [WARNING] The condition "types" here will never be used as it comes after both "import" and "require" [package.json]
32
-
33
- package.json:13:6:
34
-  13 │ "types": "./dist/index.d.ts"
35
- ╵ ~~~~~~~
36
-
37
- The "import" condition comes earlier and will be used for all "import" statements:
38
-
39
- package.json:11:6:
40
-  11 │ "import": "./dist/index.mjs",
41
- ╵ ~~~~~~~~
42
-
43
- The "require" condition comes earlier and will be used for all "require" calls:
44
-
45
- package.json:12:6:
46
-  12 │ "require": "./dist/index.js",
47
- ╵ ~~~~~~~~~
48
-
49
-
50
- [warn] ▲ [WARNING] The condition "types" here will never be used as it comes after both "import" and "require" [package.json]
51
-
52
- package.json:13:6:
53
-  13 │ "types": "./dist/index.d.ts"
54
- ╵ ~~~~~~~
55
-
56
- The "import" condition comes earlier and will be used for all "import" statements:
57
-
58
- package.json:11:6:
59
-  11 │ "import": "./dist/index.mjs",
60
- ╵ ~~~~~~~~
61
-
62
- The "require" condition comes earlier and will be used for all "require" calls:
63
-
64
- package.json:12:6:
65
-  12 │ "require": "./dist/index.js",
66
- ╵ ~~~~~~~~~
67
-
68
-
69
- CJS dist/index.js 48.18 KB
70
- CJS dist/index.js.map 99.34 KB
71
- CJS ⚡️ Build success in 86ms
72
- ESM dist/index.mjs 44.60 KB
73
- ESM dist/index.mjs.map 98.83 KB
74
- ESM ⚡️ Build success in 86ms
75
- DTS Build start
76
- DTS ⚡️ Build success in 5289ms
77
- DTS dist/index.d.mts 913.41 KB
78
- DTS dist/index.d.ts 913.41 KB
package/ARCHITECTURE.md DELETED
@@ -1,176 +0,0 @@
1
- # Better-Auth Integration: Direct Forwarding Approach
2
-
3
- ## Decision Summary
4
-
5
- **Chosen Approach:** Direct Request Forwarding
6
- **Implementation Date:** 2026-02-10
7
- **Status:** ✅ Implemented and Tested
8
-
9
- ## Problem Statement
10
-
11
- When integrating the better-auth library (v1.4.18) into `@objectstack/plugin-auth`, we needed to decide between two architectural approaches:
12
-
13
- 1. **Direct Forwarding**: Forward all HTTP requests directly to better-auth's universal handler
14
- 2. **Manual Implementation**: Implement wrapper methods for each authentication operation
15
-
16
- ## Analysis
17
-
18
- ### Better-Auth Architecture
19
-
20
- Better-auth v1.4.18 provides a **universal handler** pattern:
21
-
22
- ```typescript
23
- type Auth = {
24
- handler: (request: Request) => Promise<Response>;
25
- api: InferAPI<...>;
26
- // ...
27
- }
28
- ```
29
-
30
- This handler:
31
- - Accepts Web standard `Request` objects
32
- - Returns Web standard `Response` objects
33
- - Handles ALL authentication routes internally
34
- - Is framework-agnostic (works with Next.js, Hono, Express, etc.)
35
-
36
- ### Hono Framework Compatibility
37
-
38
- Our HTTP server uses Hono, which already uses Web standard Request/Response:
39
- - Hono Context provides `c.req.raw` → Web `Request`
40
- - Hono accepts Web `Response` objects directly
41
- - **No conversion needed!**
42
-
43
- ### Approach Comparison
44
-
45
- | Aspect | Direct Forwarding ✅ | Manual Implementation |
46
- |--------|---------------------|----------------------|
47
- | Code Size | ~100 lines | ~250 lines |
48
- | Maintenance | Minimal - better-auth handles it | High - must sync with better-auth updates |
49
- | Features | All better-auth features automatic | Must implement each feature manually |
50
- | Type Safety | Full TypeScript from better-auth | Custom types, may drift |
51
- | Bug Risk | Low - using library as designed | High - custom code, edge cases |
52
- | Updates | Get better-auth updates automatically | Must update wrapper code |
53
- | OAuth Support | Built-in, configured via options | Must implement OAuth flows |
54
- | 2FA Support | Built-in, configured via options | Must implement 2FA logic |
55
- | Passkeys | Built-in, configured via options | Must implement WebAuthn |
56
- | Magic Links | Built-in, configured via options | Must implement email flows |
57
-
58
- ## Decision: Direct Forwarding
59
-
60
- ### Rationale
61
-
62
- 1. **Library Design Intent**: Better-auth's universal handler is the **recommended integration pattern**
63
- 2. **Minimal Code**: ~150 lines removed, simpler to maintain
64
- 3. **Full Feature Support**: All better-auth features work automatically
65
- 4. **Future-Proof**: Better-auth updates require no code changes
66
- 5. **Type Safety**: Full TypeScript support from better-auth
67
- 6. **Standard Pattern**: Aligns with better-auth documentation examples
68
-
69
- ### Implementation
70
-
71
- #### Before (Manual Approach)
72
- ```typescript
73
- // Custom wrapper methods (200+ lines)
74
- httpServer.post('/auth/login', async (req, res) => {
75
- const result = await authManager.login(req.body);
76
- res.json(result);
77
- });
78
-
79
- httpServer.post('/auth/register', async (req, res) => {
80
- const result = await authManager.register(req.body);
81
- res.json(result);
82
- });
83
-
84
- // ... many more routes
85
- ```
86
-
87
- #### After (Direct Forwarding)
88
- ```typescript
89
- // Single wildcard route (~30 lines)
90
- rawApp.all('/api/v1/auth/*', async (c) => {
91
- const request = c.req.raw; // Web Request
92
- const authPath = url.pathname.replace(basePath, '');
93
- const rewrittenRequest = new Request(authPath, { ... });
94
- const response = await authManager.handleRequest(rewrittenRequest);
95
- return response; // Web Response
96
- });
97
- ```
98
-
99
- ### Trade-offs
100
-
101
- **Given Up:**
102
- - Fine-grained control over individual routes
103
- - Ability to easily intercept/modify requests
104
-
105
- **Solutions:**
106
- - Use Hono middleware for request interception if needed
107
- - Use better-auth plugins for custom behavior
108
- - Access `authManager.api` for programmatic operations
109
-
110
- ## Results
111
-
112
- ### Metrics
113
- - **Lines of Code Removed**: 156 (261 → 105 in auth-manager.ts)
114
- - **Test Coverage**: 11/11 tests passing
115
- - **Build Status**: ✅ Success
116
- - **Type Safety**: ✅ Full TypeScript support
117
-
118
- ### Features Enabled
119
- - ✅ Email/Password Authentication
120
- - ✅ OAuth Providers (Google, GitHub, etc.)
121
- - ✅ Session Management
122
- - ✅ Password Reset
123
- - ✅ Email Verification
124
- - ✅ 2FA (when enabled)
125
- - ✅ Passkeys (when enabled)
126
- - ✅ Magic Links (when enabled)
127
- - ✅ Organizations (when enabled)
128
-
129
- ## Usage Example
130
-
131
- ```typescript
132
- import { AuthPlugin } from '@objectstack/plugin-auth';
133
-
134
- const plugin = new AuthPlugin({
135
- secret: process.env.AUTH_SECRET,
136
- baseUrl: 'http://localhost:3000',
137
-
138
- // OAuth providers - just configuration, no implementation needed
139
- providers: [
140
- {
141
- id: 'google',
142
- clientId: process.env.GOOGLE_CLIENT_ID,
143
- clientSecret: process.env.GOOGLE_CLIENT_SECRET,
144
- }
145
- ],
146
-
147
- // Advanced features - just enable, no implementation needed
148
- plugins: {
149
- organization: true, // Multi-tenant support
150
- twoFactor: true, // 2FA
151
- passkeys: true, // WebAuthn
152
- magicLink: true, // Passwordless
153
- }
154
- });
155
- ```
156
-
157
- All better-auth endpoints work immediately:
158
- - `/api/v1/auth/sign-up/email`
159
- - `/api/v1/auth/sign-in/email`
160
- - `/api/v1/auth/authorize/google`
161
- - `/api/v1/auth/two-factor/enable`
162
- - `/api/v1/auth/passkey/register`
163
- - And many more...
164
-
165
- ## Lessons Learned
166
-
167
- 1. **Use Libraries as Designed**: Better-auth provides a universal handler for a reason
168
- 2. **Less Code = Less Bugs**: The simplest solution is often the best
169
- 3. **Trust the Framework**: Better-auth has battle-tested auth logic
170
- 4. **Embrace Standards**: Web standard Request/Response makes integration seamless
171
-
172
- ## References
173
-
174
- - [Better-Auth Documentation](https://www.better-auth.com/docs)
175
- - [PR #580](https://github.com/objectstack-ai/spec/pull/580) - Initial better-auth integration
176
- - Analysis Document: `/tmp/better-auth-approach-analysis.md`
package/CHANGELOG.md DELETED
@@ -1,325 +0,0 @@
1
- # Changelog
2
-
3
- ## 4.0.3
4
-
5
- ### Patch Changes
6
-
7
- - @objectstack/spec@4.0.3
8
- - @objectstack/core@4.0.3
9
-
10
- ## 4.0.2
11
-
12
- ### Patch Changes
13
-
14
- - Updated dependencies [5f659e9]
15
- - @objectstack/spec@4.0.2
16
- - @objectstack/core@4.0.2
17
-
18
- ## 4.0.0
19
-
20
- ### Patch Changes
21
-
22
- - e0b0a78: Deprecate DataEngineQueryOptions in favor of QueryAST-aligned EngineQueryOptions.
23
-
24
- Engine, Protocol, and Client now use standard QueryAST parameter names:
25
-
26
- - `filter` → `where`
27
- - `select` → `fields`
28
- - `sort` → `orderBy`
29
- - `skip` → `offset`
30
- - `populate` → `expand`
31
- - `top` → `limit`
32
-
33
- The old DataEngine\* schemas and types are preserved with `@deprecated` markers for backward compatibility.
34
-
35
- - Updated dependencies [f08ffc3]
36
- - Updated dependencies [e0b0a78]
37
- - @objectstack/spec@4.0.0
38
- - @objectstack/core@4.0.0
39
-
40
- ## 3.3.1
41
-
42
- ### Patch Changes
43
-
44
- - @objectstack/spec@3.3.1
45
- - @objectstack/core@3.3.1
46
-
47
- ## 3.3.0
48
-
49
- ### Minor Changes
50
-
51
- - 814a6c4: sql driver
52
-
53
- ### Patch Changes
54
-
55
- - @objectstack/spec@3.3.0
56
- - @objectstack/core@3.3.0
57
-
58
- ## 3.2.9
59
-
60
- ### Patch Changes
61
-
62
- - @objectstack/spec@3.2.9
63
- - @objectstack/core@3.2.9
64
-
65
- ## 3.2.8
66
-
67
- ### Patch Changes
68
-
69
- - 1fe5612: fix vercel
70
- - @objectstack/spec@3.2.8
71
- - @objectstack/core@3.2.8
72
-
73
- ## 3.2.7
74
-
75
- ### Patch Changes
76
-
77
- - 35a1ebb: fix auth
78
- - @objectstack/spec@3.2.7
79
- - @objectstack/core@3.2.7
80
-
81
- ## 3.2.6
82
-
83
- ### Patch Changes
84
-
85
- - @objectstack/spec@3.2.6
86
- - @objectstack/core@3.2.6
87
-
88
- ## 3.2.5
89
-
90
- ### Patch Changes
91
-
92
- - e854538: fix beyyer-auth
93
- - @objectstack/spec@3.2.5
94
- - @objectstack/core@3.2.5
95
-
96
- ## 3.2.4
97
-
98
- ### Patch Changes
99
-
100
- - f490991: fix better-auth
101
- - @objectstack/spec@3.2.4
102
- - @objectstack/core@3.2.4
103
-
104
- ## 3.2.3
105
-
106
- ### Patch Changes
107
-
108
- - 0b1d7c9: fix auth
109
- - @objectstack/spec@3.2.3
110
- - @objectstack/core@3.2.3
111
-
112
- ## 3.2.2
113
-
114
- ### Patch Changes
115
-
116
- - cfaabbb: fix: AuthPlugin error handling & database adapter config
117
-
118
- - `AuthManager.handleRequest()` now inspects `response.status >= 500` and logs the error body via `console.error`, since better-auth catches internal errors and returns 500 Responses without throwing.
119
- - `AuthPlugin.registerAuthRoutes()` also logs 500+ responses via `ctx.logger.error` for structured plugin logging.
120
- - `createDatabaseConfig()` now wraps the ObjectQL adapter as a `DBAdapterInstance` factory function so better-auth's `getBaseAdapter()` correctly recognises it (via `typeof database === "function"` check) instead of falling through to the Kysely adapter path.
121
-
122
- - Updated dependencies [46defbb]
123
- - @objectstack/spec@3.2.2
124
- - @objectstack/core@3.2.2
125
-
126
- ## 3.2.1
127
-
128
- ### Patch Changes
129
-
130
- - Updated dependencies [850b546]
131
- - @objectstack/spec@3.2.1
132
- - @objectstack/core@3.2.1
133
-
134
- ## 3.2.0
135
-
136
- ### Patch Changes
137
-
138
- - Updated dependencies [5901c29]
139
- - @objectstack/spec@3.2.0
140
- - @objectstack/core@3.2.0
141
-
142
- ## 3.1.1
143
-
144
- ### Patch Changes
145
-
146
- - Updated dependencies [953d667]
147
- - @objectstack/spec@3.1.1
148
- - @objectstack/core@3.1.1
149
-
150
- ## 3.1.0
151
-
152
- ### Patch Changes
153
-
154
- - Updated dependencies [0088830]
155
- - @objectstack/spec@3.1.0
156
- - @objectstack/core@3.1.0
157
-
158
- ## 3.0.11
159
-
160
- ### Patch Changes
161
-
162
- - Updated dependencies [92d9d99]
163
- - @objectstack/spec@3.0.11
164
- - @objectstack/core@3.0.11
165
-
166
- ## 3.0.10
167
-
168
- ### Patch Changes
169
-
170
- - Updated dependencies [d1e5d31]
171
- - @objectstack/spec@3.0.10
172
- - @objectstack/core@3.0.10
173
-
174
- ## 3.0.9
175
-
176
- ### Patch Changes
177
-
178
- - Updated dependencies [15e0df6]
179
- - @objectstack/spec@3.0.9
180
- - @objectstack/core@3.0.9
181
-
182
- ## 3.0.8
183
-
184
- ### Patch Changes
185
-
186
- - Updated dependencies [5a968a2]
187
- - @objectstack/spec@3.0.8
188
- - @objectstack/core@3.0.8
189
-
190
- ## 3.0.7
191
-
192
- ### Patch Changes
193
-
194
- - Updated dependencies [0119bd7]
195
- - Updated dependencies [5426bdf]
196
- - @objectstack/spec@3.0.7
197
- - @objectstack/core@3.0.7
198
-
199
- ## 3.0.6
200
-
201
- ### Patch Changes
202
-
203
- - Updated dependencies [5df254c]
204
- - @objectstack/spec@3.0.6
205
- - @objectstack/core@3.0.6
206
-
207
- ## 3.0.5
208
-
209
- ### Patch Changes
210
-
211
- - Updated dependencies [23a4a68]
212
- - @objectstack/spec@3.0.5
213
- - @objectstack/core@3.0.5
214
-
215
- ## 3.0.4
216
-
217
- ### Patch Changes
218
-
219
- - Updated dependencies [d738987]
220
- - @objectstack/spec@3.0.4
221
- - @objectstack/core@3.0.4
222
-
223
- ## 3.0.3
224
-
225
- ### Patch Changes
226
-
227
- - c7267f6: Patch release for maintenance updates and improvements.
228
- - Updated dependencies [c7267f6]
229
- - @objectstack/spec@3.0.3
230
- - @objectstack/core@3.0.3
231
-
232
- ## 3.0.2
233
-
234
- ### Patch Changes
235
-
236
- - Updated dependencies [28985f5]
237
- - @objectstack/spec@3.0.2
238
- - @objectstack/core@3.0.2
239
-
240
- ## 3.0.1
241
-
242
- ### Patch Changes
243
-
244
- - Updated dependencies [389725a]
245
- - @objectstack/spec@3.0.1
246
- - @objectstack/core@3.0.1
247
-
248
- ## 3.0.0
249
-
250
- ### Major Changes
251
-
252
- - Release v3.0.0 — unified version bump for all ObjectStack packages.
253
-
254
- ### Patch Changes
255
-
256
- - Updated dependencies
257
- - @objectstack/spec@3.0.0
258
- - @objectstack/core@3.0.0
259
-
260
- ## 2.0.7
261
-
262
- ### Patch Changes
263
-
264
- - Updated dependencies
265
- - @objectstack/spec@2.0.7
266
- - @objectstack/core@2.0.7
267
-
268
- ## 2.0.6
269
-
270
- ### Patch Changes
271
-
272
- - Patch release for maintenance and stability improvements
273
- - Updated dependencies
274
- - @objectstack/spec@2.0.6
275
- - @objectstack/core@2.0.6
276
-
277
- ## 2.0.5
278
-
279
- ### Patch Changes
280
-
281
- - Unify all package versions with a patch release
282
- - Updated dependencies
283
- - @objectstack/spec@2.0.5
284
- - @objectstack/core@2.0.5
285
-
286
- ## 2.0.3
287
-
288
- ### Patch Changes
289
-
290
- - Updated dependencies
291
- - @objectstack/spec@2.0.4
292
- - @objectstack/core@2.0.4
293
-
294
- All notable changes to `@objectstack/plugin-auth` will be documented in this file.
295
-
296
- The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
297
- and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
298
-
299
- ## [Unreleased]
300
-
301
- ## [2.0.2] - 2026-02-10
302
-
303
- ### Added
304
-
305
- - Initial release of Auth Plugin
306
- - Integration with better-auth library for robust authentication
307
- - Session management and user authentication
308
- - Support for OAuth providers (Google, GitHub, Microsoft, etc.)
309
- - Organization/team support for multi-tenant applications
310
- - Two-factor authentication (2FA)
311
- - Passkey support
312
- - Magic link authentication
313
- - Configurable session expiry and refresh
314
- - Automatic HTTP route registration
315
- - Comprehensive test coverage
316
-
317
- ### Security
318
-
319
- - Secure session token management
320
- - Encrypted secrets support
321
- - Rate limiting capabilities
322
- - CSRF protection
323
-
324
- [Unreleased]: https://github.com/objectstack-ai/spec/compare/v2.0.2...HEAD
325
- [2.0.2]: https://github.com/objectstack-ai/spec/releases/tag/v2.0.2