@lenne.tech/nest-server 11.21.3 → 11.22.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/.claude/rules/architecture.md +79 -0
- package/.claude/rules/better-auth.md +262 -0
- package/.claude/rules/configurable-features.md +308 -0
- package/.claude/rules/core-modules.md +205 -0
- package/.claude/rules/migration-guides.md +149 -0
- package/.claude/rules/module-deprecation.md +214 -0
- package/.claude/rules/module-inheritance.md +97 -0
- package/.claude/rules/package-management.md +112 -0
- package/.claude/rules/role-system.md +146 -0
- package/.claude/rules/testing.md +120 -0
- package/.claude/rules/versioning.md +53 -0
- package/CLAUDE.md +172 -0
- package/dist/core/common/interfaces/server-options.interface.d.ts +10 -0
- package/dist/core/modules/error-code/error-code.module.js.map +1 -1
- package/dist/core.module.d.ts +3 -3
- package/dist/core.module.js +17 -4
- package/dist/core.module.js.map +1 -1
- package/dist/server/server.module.js +6 -6
- package/dist/server/server.module.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/docs/REQUEST-LIFECYCLE.md +1256 -0
- package/docs/error-codes.md +446 -0
- package/migration-guides/11.10.x-to-11.11.x.md +266 -0
- package/migration-guides/11.11.x-to-11.12.x.md +323 -0
- package/migration-guides/11.12.x-to-11.13.0.md +612 -0
- package/migration-guides/11.13.x-to-11.14.0.md +348 -0
- package/migration-guides/11.14.x-to-11.15.0.md +262 -0
- package/migration-guides/11.15.0-to-11.15.3.md +118 -0
- package/migration-guides/11.15.x-to-11.16.0.md +497 -0
- package/migration-guides/11.16.x-to-11.17.0.md +130 -0
- package/migration-guides/11.17.x-to-11.18.0.md +393 -0
- package/migration-guides/11.18.x-to-11.19.0.md +151 -0
- package/migration-guides/11.19.x-to-11.20.0.md +170 -0
- package/migration-guides/11.20.x-to-11.21.0.md +216 -0
- package/migration-guides/11.21.0-to-11.21.1.md +194 -0
- package/migration-guides/11.21.1-to-11.21.2.md +114 -0
- package/migration-guides/11.21.2-to-11.21.3.md +175 -0
- package/migration-guides/11.21.x-to-11.22.0.md +224 -0
- package/migration-guides/11.3.x-to-11.4.x.md +233 -0
- package/migration-guides/11.6.x-to-11.7.x.md +394 -0
- package/migration-guides/11.7.x-to-11.8.x.md +318 -0
- package/migration-guides/11.8.x-to-11.9.x.md +322 -0
- package/migration-guides/11.9.x-to-11.10.x.md +571 -0
- package/migration-guides/TEMPLATE.md +113 -0
- package/package.json +8 -3
- package/src/core/common/interfaces/server-options.interface.ts +83 -16
- package/src/core/modules/better-auth/CUSTOMIZATION.md +24 -17
- package/src/core/modules/better-auth/INTEGRATION-CHECKLIST.md +5 -5
- package/src/core/modules/error-code/INTEGRATION-CHECKLIST.md +42 -12
- package/src/core/modules/error-code/error-code.module.ts +4 -9
- package/src/core.module.ts +52 -10
- package/src/server/server.module.ts +7 -9
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
---
|
|
2
|
+
paths: src/core/modules/**
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Core Module Development Rules
|
|
6
|
+
|
|
7
|
+
These rules apply when working in `src/core/modules/`.
|
|
8
|
+
|
|
9
|
+
## Naming Conventions
|
|
10
|
+
|
|
11
|
+
- Base classes: `Core` prefix (e.g., `CoreAuthService`, `CoreBetterAuthResolver`)
|
|
12
|
+
- Interfaces: `I` prefix (e.g., `IBetterAuth`, `IServerOptions`)
|
|
13
|
+
- Models: `*Model` suffix for GraphQL types
|
|
14
|
+
- Inputs: `*Input` suffix for input types
|
|
15
|
+
- Args: `*Args` suffix for query arguments
|
|
16
|
+
|
|
17
|
+
## Method Visibility
|
|
18
|
+
|
|
19
|
+
- Use `protected` for methods that should be overridable
|
|
20
|
+
- Use `public` for API methods
|
|
21
|
+
- Avoid `private` for methods that projects might need to customize
|
|
22
|
+
|
|
23
|
+
## Module Registration
|
|
24
|
+
|
|
25
|
+
### Override Pattern (Recommended)
|
|
26
|
+
|
|
27
|
+
Core modules that support customization should accept `controller`/`resolver`/`service` parameters
|
|
28
|
+
in their `forRoot()` method. `CoreModule.forRoot()` passes these through via the `ICoreModuleOverrides` parameter:
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
// In core module
|
|
32
|
+
static forRoot(config?: { controller?: Type; service?: Type }): DynamicModule {
|
|
33
|
+
const ControllerClass = config?.controller || CoreDefaultController;
|
|
34
|
+
const ServiceClass = config?.service || CoreDefaultService;
|
|
35
|
+
return { module: MyModule, controllers: [ControllerClass], providers: [...] };
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
New modules must add their override fields to `ICoreModuleOverrides` in `server-options.interface.ts`
|
|
40
|
+
and pass them through in `CoreModule.forRoot()`.
|
|
41
|
+
|
|
42
|
+
### Auto-Registration
|
|
43
|
+
|
|
44
|
+
Always support both registration modes:
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
// In module class
|
|
48
|
+
static forRoot(options: ModuleOptions): DynamicModule {
|
|
49
|
+
// Check autoRegister option
|
|
50
|
+
if (options.config?.autoRegister === true) {
|
|
51
|
+
// Auto-registration logic
|
|
52
|
+
}
|
|
53
|
+
// Manual registration is default
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Export Requirements
|
|
58
|
+
|
|
59
|
+
All public classes must be exported in `src/index.ts`:
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
// src/index.ts
|
|
63
|
+
export { CoreAuthService } from './core/modules/auth/services/core-auth.service';
|
|
64
|
+
export { CoreBetterAuthResolver } from './core/modules/better-auth/core-better-auth.resolver';
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Documentation
|
|
68
|
+
|
|
69
|
+
Each core module should have:
|
|
70
|
+
|
|
71
|
+
1. README.md in module directory
|
|
72
|
+
2. JSDoc comments on public methods
|
|
73
|
+
3. Interface documentation in `server-options.interface.ts`
|
|
74
|
+
|
|
75
|
+
## Logging
|
|
76
|
+
|
|
77
|
+
Use NestJS Logger with module name:
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
private readonly logger = new Logger(ModuleName.name);
|
|
81
|
+
|
|
82
|
+
// Use appropriate log levels
|
|
83
|
+
this.logger.log('Important info'); // Normal operations
|
|
84
|
+
this.logger.warn('Warning message'); // Potential issues
|
|
85
|
+
this.logger.error('Error occurred'); // Errors
|
|
86
|
+
this.logger.debug('Debug info'); // Development only (sparingly)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Optional Constructor Parameters
|
|
90
|
+
|
|
91
|
+
Use the **options object pattern** for optional constructor parameters in Core classes:
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
// Define options interface
|
|
95
|
+
export interface CoreUserServiceOptions {
|
|
96
|
+
betterAuthUserMapper?: BetterAuthUserMapper;
|
|
97
|
+
// Future optional params can be added without breaking changes
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Core class constructor
|
|
101
|
+
protected constructor(
|
|
102
|
+
// Required params first
|
|
103
|
+
protected readonly configService: ConfigService,
|
|
104
|
+
protected readonly emailService: EmailService,
|
|
105
|
+
// Options object last
|
|
106
|
+
protected readonly options?: CoreUserServiceOptions,
|
|
107
|
+
) {
|
|
108
|
+
super();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Usage in methods
|
|
112
|
+
if (this.options?.betterAuthUserMapper) {
|
|
113
|
+
await this.options.betterAuthUserMapper.syncEmail(...);
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
**Why this pattern:**
|
|
118
|
+
- New optional parameters can be added without breaking existing implementations
|
|
119
|
+
- No need to pass `null` or `undefined` for unused optional parameters
|
|
120
|
+
- Order of optional parameters doesn't matter
|
|
121
|
+
- Clear distinction between required and optional dependencies
|
|
122
|
+
|
|
123
|
+
**Implementation in extending classes:**
|
|
124
|
+
```typescript
|
|
125
|
+
constructor(
|
|
126
|
+
// ... required params ...
|
|
127
|
+
@Optional() private readonly betterAuthUserMapper?: BetterAuthUserMapper,
|
|
128
|
+
) {
|
|
129
|
+
super(configService, emailService, mainDbModel, mainModelConstructor, { betterAuthUserMapper });
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Testing
|
|
134
|
+
|
|
135
|
+
- Create story tests in `tests/stories/`
|
|
136
|
+
- Test through API (REST/GraphQL), not direct service calls
|
|
137
|
+
- Include security tests for authentication/authorization
|
|
138
|
+
|
|
139
|
+
## Integration Documentation (Required for All Core Modules)
|
|
140
|
+
|
|
141
|
+
Every core module that requires project integration MUST have an `INTEGRATION-CHECKLIST.md` file.
|
|
142
|
+
|
|
143
|
+
### Purpose
|
|
144
|
+
|
|
145
|
+
This checklist helps developers (and AI assistants like Claude Code) integrate the module into their projects. It should be optimized for:
|
|
146
|
+
- Quick understanding of required steps
|
|
147
|
+
- Clear references to working code (no duplicates)
|
|
148
|
+
- Critical "WHY" explanations for non-obvious steps
|
|
149
|
+
|
|
150
|
+
### Required Structure
|
|
151
|
+
|
|
152
|
+
```markdown
|
|
153
|
+
# [ModuleName] Integration Checklist
|
|
154
|
+
|
|
155
|
+
## Reference Implementation
|
|
156
|
+
- Local: `node_modules/@lenne.tech/nest-server/src/server/modules/[module]/`
|
|
157
|
+
- GitHub: https://github.com/lenneTech/nest-server/tree/develop/src/server/modules/[module]
|
|
158
|
+
|
|
159
|
+
## Required Files (Create in Order)
|
|
160
|
+
### 1. [FileName]
|
|
161
|
+
**Create:** `src/server/modules/[module]/[file].ts`
|
|
162
|
+
**Copy from:** Reference implementation
|
|
163
|
+
[Optional: WHY explanation for critical/non-obvious steps]
|
|
164
|
+
|
|
165
|
+
## Verification Checklist
|
|
166
|
+
- [ ] Build succeeds
|
|
167
|
+
- [ ] Tests pass
|
|
168
|
+
- [ ] [Module-specific checks]
|
|
169
|
+
|
|
170
|
+
## Common Mistakes
|
|
171
|
+
| Mistake | Symptom | Fix |
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Key Principles
|
|
175
|
+
|
|
176
|
+
1. **No Code Duplication**: Never include full code examples that duplicate `src/server/`
|
|
177
|
+
- Reference files exist in `src/server/modules/` and are included in the npm package
|
|
178
|
+
- Claude Code can read these files directly from `node_modules/`
|
|
179
|
+
- Only include small code snippets for DIFFs (changes to existing files)
|
|
180
|
+
|
|
181
|
+
2. **Single Source of Truth**: The reference implementation in `src/server/` is always current
|
|
182
|
+
- Documentation never becomes outdated
|
|
183
|
+
- Copy-paste from reference is always correct
|
|
184
|
+
|
|
185
|
+
3. **WHY Explanations**: Include for critical/non-obvious steps
|
|
186
|
+
- Example: "WHY must decorators be re-declared?" → GraphQL schema registration
|
|
187
|
+
- Example: "WHY inject this mapper?" → Bidirectional sync between systems
|
|
188
|
+
|
|
189
|
+
4. **Verification Checklist**: Help verify successful integration
|
|
190
|
+
- Build/test commands
|
|
191
|
+
- Module-specific functional checks
|
|
192
|
+
|
|
193
|
+
5. **Common Mistakes Table**: Document known pitfalls with symptoms and fixes
|
|
194
|
+
|
|
195
|
+
### Example
|
|
196
|
+
|
|
197
|
+
See `src/core/modules/better-auth/INTEGRATION-CHECKLIST.md` as the reference template.
|
|
198
|
+
|
|
199
|
+
### When to Create
|
|
200
|
+
|
|
201
|
+
Create an `INTEGRATION-CHECKLIST.md` when the module:
|
|
202
|
+
- Requires files to be created in the consuming project
|
|
203
|
+
- Has non-obvious integration steps
|
|
204
|
+
- Extends Core classes that need decorator re-declaration
|
|
205
|
+
- Requires changes to existing project files (UserService, ServerModule, etc.)
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# Migration Guide Creation Process
|
|
2
|
+
|
|
3
|
+
This document describes the process for creating migration guides when releasing new versions of @lenne.tech/nest-server.
|
|
4
|
+
|
|
5
|
+
## When to Create a Migration Guide
|
|
6
|
+
|
|
7
|
+
**Versioning Context:** The MAJOR version mirrors NestJS (e.g., `11.x.x` = NestJS 11). This means MINOR can contain breaking changes and PATCH can contain new features.
|
|
8
|
+
|
|
9
|
+
**Create a migration guide when consuming projects need to:**
|
|
10
|
+
- Change code, configuration, or usage to use new features
|
|
11
|
+
- Modify anything to keep the application working after update
|
|
12
|
+
- Adapt to breaking changes or new requirements
|
|
13
|
+
|
|
14
|
+
**Examples:**
|
|
15
|
+
- `11.6.x → 11.7.x` - Required (new BetterAuth module, new CoreModule signature)
|
|
16
|
+
- `11.7.0 → 11.7.1` - Required if new features need configuration changes
|
|
17
|
+
- `11.7.1 → 11.7.2` - Not required if purely internal bugfixes with no user action needed
|
|
18
|
+
|
|
19
|
+
**Rule of thumb:** If a developer needs to do anything beyond `pnpm update` to benefit from or accommodate the changes, create a migration guide.
|
|
20
|
+
|
|
21
|
+
## Migration Guide Location
|
|
22
|
+
|
|
23
|
+
All migration guides are stored in `migration-guides/`:
|
|
24
|
+
- `migration-guides/11.6.x-to-11.7.x.md`
|
|
25
|
+
- `migration-guides/TEMPLATE.md` - Template for new guides
|
|
26
|
+
|
|
27
|
+
## Creation Process
|
|
28
|
+
|
|
29
|
+
### Step 1: Gather Project Information
|
|
30
|
+
|
|
31
|
+
**Always analyze these sources:**
|
|
32
|
+
1. Local `src/server/` - Internal test implementation
|
|
33
|
+
2. [nest-server-starter](https://github.com/lenneTech/nest-server-starter) - Reference project
|
|
34
|
+
|
|
35
|
+
**Ask developer for additional projects:**
|
|
36
|
+
```
|
|
37
|
+
Which projects should I analyze for migration compatibility?
|
|
38
|
+
Please provide paths to projects using @lenne.tech/nest-server.
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Step 2: Analyze Projects
|
|
42
|
+
|
|
43
|
+
Focus on files affected by the version changes:
|
|
44
|
+
- Module files (`*.module.ts`)
|
|
45
|
+
- Service files (`*.service.ts`)
|
|
46
|
+
- Resolver files (`*.resolver.ts`)
|
|
47
|
+
- Controller files (`*.controller.ts`)
|
|
48
|
+
- Configuration files (`config.env.ts`)
|
|
49
|
+
|
|
50
|
+
Look for:
|
|
51
|
+
- Module inheritance patterns (extending Core* classes)
|
|
52
|
+
- Method overrides
|
|
53
|
+
- Custom implementations
|
|
54
|
+
- Version-specific features in use
|
|
55
|
+
|
|
56
|
+
### Step 3: Identify Changes
|
|
57
|
+
|
|
58
|
+
Categorize all changes:
|
|
59
|
+
|
|
60
|
+
| Category | Description |
|
|
61
|
+
|----------|-------------|
|
|
62
|
+
| **Breaking Changes** | Changes that require code modifications |
|
|
63
|
+
| **New Features** | New functionality (opt-in) |
|
|
64
|
+
| **Bugfixes** | Corrections to existing behavior |
|
|
65
|
+
| **Deprecations** | Features marked for future removal |
|
|
66
|
+
|
|
67
|
+
### Step 4: Write the Guide
|
|
68
|
+
|
|
69
|
+
Use `migration-guides/TEMPLATE.md` as starting point.
|
|
70
|
+
|
|
71
|
+
**Required Sections:**
|
|
72
|
+
1. **Overview** - Summary table with categories and effort
|
|
73
|
+
2. **Quick Migration** - For non-breaking updates
|
|
74
|
+
3. **What's New** - New features with examples
|
|
75
|
+
4. **Breaking Changes** - Before/after code samples
|
|
76
|
+
5. **Compatibility Notes** - Common patterns and their status
|
|
77
|
+
6. **Troubleshooting** - Known issues and solutions
|
|
78
|
+
7. **Module Documentation** - Links to affected module docs (README.md, INTEGRATION-CHECKLIST.md)
|
|
79
|
+
|
|
80
|
+
**Rules:**
|
|
81
|
+
- **Write ALL content in English** - This includes section titles, descriptions, explanations, and code comments. Technical terms and code identifiers remain unchanged.
|
|
82
|
+
- Do NOT name specific customer projects (except nest-server-starter as reference)
|
|
83
|
+
- Keep information general and pattern-based
|
|
84
|
+
- Include code examples for all changes
|
|
85
|
+
- Mention `npm run update` if package.json dependencies changed
|
|
86
|
+
|
|
87
|
+
### Step 5: Update References
|
|
88
|
+
|
|
89
|
+
After creating the guide, verify references in:
|
|
90
|
+
- `CLAUDE.md` - Should link to migration-guides/
|
|
91
|
+
- `CHANGELOG.md` - If it exists
|
|
92
|
+
|
|
93
|
+
### Step 6: Link Module Documentation
|
|
94
|
+
|
|
95
|
+
For each affected module, check for and link to:
|
|
96
|
+
- `src/core/modules/<module>/README.md` - Module overview and usage
|
|
97
|
+
- `src/core/modules/<module>/INTEGRATION-CHECKLIST.md` - Integration steps
|
|
98
|
+
- `src/server/modules/<module>/` - Reference implementation
|
|
99
|
+
|
|
100
|
+
Find existing documentation:
|
|
101
|
+
```bash
|
|
102
|
+
# Find all module READMEs
|
|
103
|
+
ls src/core/modules/**/README.md
|
|
104
|
+
|
|
105
|
+
# Find all integration checklists
|
|
106
|
+
ls src/core/modules/**/INTEGRATION-CHECKLIST.md
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Guide Quality Checklist
|
|
110
|
+
|
|
111
|
+
- [ ] **Written entirely in English**
|
|
112
|
+
- [ ] Overview table is complete
|
|
113
|
+
- [ ] Quick migration path provided
|
|
114
|
+
- [ ] All breaking changes documented with before/after
|
|
115
|
+
- [ ] New features have usage examples
|
|
116
|
+
- [ ] Compatibility notes cover common patterns
|
|
117
|
+
- [ ] Troubleshooting section addresses likely issues
|
|
118
|
+
- [ ] Module documentation section links to affected modules
|
|
119
|
+
- [ ] No customer project names mentioned
|
|
120
|
+
- [ ] Code examples are tested
|
|
121
|
+
|
|
122
|
+
## Example Analysis Output
|
|
123
|
+
|
|
124
|
+
```markdown
|
|
125
|
+
## Analysis Summary
|
|
126
|
+
|
|
127
|
+
### Pattern: AuthResolver Extension
|
|
128
|
+
- Found in: 4/4 analyzed projects
|
|
129
|
+
- Status: Compatible
|
|
130
|
+
- Notes: Projects override signIn() calling authService directly
|
|
131
|
+
|
|
132
|
+
### Pattern: Custom Role Enums
|
|
133
|
+
- Found in: 1/4 analyzed projects
|
|
134
|
+
- Status: Compatible
|
|
135
|
+
- Notes: CompanyRoles used instead of RoleEnum
|
|
136
|
+
|
|
137
|
+
### Potential Issues: None identified
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Automation
|
|
141
|
+
|
|
142
|
+
When asked to create a migration guide, Claude Code should:
|
|
143
|
+
|
|
144
|
+
1. Prompt for project paths (unless already provided)
|
|
145
|
+
2. Read auth, user, and configuration files from each project
|
|
146
|
+
3. Compare patterns against new version requirements
|
|
147
|
+
4. Generate compatibility report
|
|
148
|
+
5. Create migration guide using template
|
|
149
|
+
6. Verify all tests pass with new version
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
# Module Deprecation & Migration Roadmap
|
|
2
|
+
|
|
3
|
+
This document describes the deprecation strategy for Legacy Auth and the migration path to BetterAuth (IAM).
|
|
4
|
+
|
|
5
|
+
## Authentication System Roadmap
|
|
6
|
+
|
|
7
|
+
### v11.x (Current - Backward Compatible)
|
|
8
|
+
|
|
9
|
+
- **Legacy Auth** (CoreAuthService) is available for backwards compatibility
|
|
10
|
+
- **BetterAuth** (IAM) can run standalone or alongside Legacy Auth
|
|
11
|
+
- **GraphQL Subscriptions** work with both systems (IAM uses BetterAuth sessions)
|
|
12
|
+
- Both systems share the same user database with bidirectional sync
|
|
13
|
+
- Password hashes use different algorithms (Legacy: `bcrypt(sha256(pw))`, IAM: `scrypt(sha256(pw))`)
|
|
14
|
+
|
|
15
|
+
**Key Configuration:**
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
// config.env.ts
|
|
19
|
+
{
|
|
20
|
+
// Legacy Auth configuration (optional, for backwards compatibility)
|
|
21
|
+
jwt: {
|
|
22
|
+
secret: 'YOUR_JWT_SECRET',
|
|
23
|
+
refresh: { secret: 'YOUR_REFRESH_SECRET' }
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
// BetterAuth configuration (optional, runs in parallel)
|
|
27
|
+
betterAuth: {
|
|
28
|
+
enabled: true,
|
|
29
|
+
secret: 'YOUR_BETTERAUTH_SECRET',
|
|
30
|
+
// ...
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
// NEW in v11.7.x: Disable legacy endpoints after migration
|
|
34
|
+
auth: {
|
|
35
|
+
legacyEndpoints: {
|
|
36
|
+
enabled: true // Set to false after all users migrated
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
**CoreModule.forRoot Signatures:**
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
// IAM-Only (recommended for new projects)
|
|
46
|
+
CoreModule.forRoot(envConfig)
|
|
47
|
+
|
|
48
|
+
// Legacy + IAM (for existing projects during migration)
|
|
49
|
+
CoreModule.forRoot(CoreAuthService, AuthModule.forRoot(envConfig.jwt), envConfig)
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Future Version (Planned - Breaking Change)
|
|
53
|
+
|
|
54
|
+
- **BetterAuth** (IAM) becomes the default authentication system
|
|
55
|
+
- **Legacy Auth** becomes optional (must be explicitly enabled)
|
|
56
|
+
- Simplified CoreModule.forRoot signature becomes the only option
|
|
57
|
+
- Legacy Auth removed from codebase
|
|
58
|
+
|
|
59
|
+
**New Configuration:**
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
// config.env.ts
|
|
63
|
+
{
|
|
64
|
+
// BetterAuth is now the default
|
|
65
|
+
betterAuth: {
|
|
66
|
+
secret: 'YOUR_BETTERAUTH_SECRET',
|
|
67
|
+
// ...
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
// Legacy Auth is optional (enable only if needed)
|
|
71
|
+
auth: {
|
|
72
|
+
legacy: {
|
|
73
|
+
enabled: false // Explicitly enable if still needed
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
**Simplified CoreModule.forRoot Signature:**
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
// Future version: Single parameter
|
|
83
|
+
CoreModule.forRoot(envConfig)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Migration Path for Projects
|
|
87
|
+
|
|
88
|
+
### Phase 1: Enable BetterAuth (v11.x)
|
|
89
|
+
|
|
90
|
+
1. Ensure `betterAuth` is configured in `config.env.ts`
|
|
91
|
+
2. Integrate BetterAuthModule in your project (see INTEGRATION-CHECKLIST.md)
|
|
92
|
+
3. Both auth systems run in parallel
|
|
93
|
+
|
|
94
|
+
### Phase 2: Monitor Migration
|
|
95
|
+
|
|
96
|
+
Use the `betterAuthMigrationStatus` GraphQL query (admin only):
|
|
97
|
+
|
|
98
|
+
```graphql
|
|
99
|
+
query {
|
|
100
|
+
betterAuthMigrationStatus {
|
|
101
|
+
totalUsers
|
|
102
|
+
fullyMigratedUsers
|
|
103
|
+
pendingMigrationUsers
|
|
104
|
+
migrationPercentage
|
|
105
|
+
canDisableLegacyAuth
|
|
106
|
+
pendingUserEmails
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Users migrate automatically when they:
|
|
112
|
+
- Sign in via BetterAuth (IAM) endpoints
|
|
113
|
+
- Use social login (if configured)
|
|
114
|
+
- Use passkey authentication (if configured)
|
|
115
|
+
|
|
116
|
+
### Phase 3: Disable Legacy Endpoints
|
|
117
|
+
|
|
118
|
+
Once `canDisableLegacyAuth` is `true`:
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
// config.env.ts
|
|
122
|
+
auth: {
|
|
123
|
+
legacyEndpoints: {
|
|
124
|
+
enabled: false // Disable all legacy endpoints
|
|
125
|
+
// Or disable selectively:
|
|
126
|
+
// graphql: false // Disable only GraphQL endpoints
|
|
127
|
+
// rest: false // Disable only REST endpoints
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Legacy endpoint calls will return HTTP 410 Gone.
|
|
133
|
+
|
|
134
|
+
### Phase 4: Upgrade to Future Version
|
|
135
|
+
|
|
136
|
+
When upgrading to the future version with BetterAuth as default:
|
|
137
|
+
|
|
138
|
+
1. Update `package.json` dependency
|
|
139
|
+
2. Simplify `CoreModule.forRoot` call:
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
// Before (v11.x)
|
|
143
|
+
CoreModule.forRoot(CoreAuthService, AuthModule.forRoot(envConfig.jwt), envConfig)
|
|
144
|
+
|
|
145
|
+
// After (future version)
|
|
146
|
+
CoreModule.forRoot(envConfig)
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
3. Remove Legacy Auth configuration if no longer needed
|
|
150
|
+
|
|
151
|
+
## Password Hash Incompatibility
|
|
152
|
+
|
|
153
|
+
**Why parallel operation is necessary:**
|
|
154
|
+
|
|
155
|
+
| System | Hash Algorithm |
|
|
156
|
+
|--------|----------------|
|
|
157
|
+
| Legacy Auth | `bcrypt(sha256(password))` |
|
|
158
|
+
| BetterAuth | `scrypt(sha256(password))` |
|
|
159
|
+
|
|
160
|
+
These algorithms are **one-way** - there is no migration script possible.
|
|
161
|
+
Users must sign in at least once via BetterAuth to create a new hash.
|
|
162
|
+
|
|
163
|
+
## Configuration Reference
|
|
164
|
+
|
|
165
|
+
### auth.legacyEndpoints (v11.7.x+)
|
|
166
|
+
|
|
167
|
+
| Property | Type | Default | Description |
|
|
168
|
+
|----------|------|---------|-------------|
|
|
169
|
+
| `enabled` | boolean | `true` | Enable/disable all legacy endpoints |
|
|
170
|
+
| `graphql` | boolean | inherits `enabled` | Enable/disable GraphQL endpoints only |
|
|
171
|
+
| `rest` | boolean | inherits `enabled` | Enable/disable REST endpoints only |
|
|
172
|
+
|
|
173
|
+
### Legacy Endpoints Affected
|
|
174
|
+
|
|
175
|
+
**GraphQL Mutations:**
|
|
176
|
+
- `signIn` - Sign in via email/password
|
|
177
|
+
- `signUp` - Register new account
|
|
178
|
+
- `logout` - Sign out
|
|
179
|
+
- `refreshToken` - Refresh JWT tokens
|
|
180
|
+
|
|
181
|
+
**REST Endpoints:**
|
|
182
|
+
- `POST /auth/signin` - Sign in via email/password
|
|
183
|
+
- `POST /auth/signup` - Register new account
|
|
184
|
+
- `GET /auth/logout` - Sign out
|
|
185
|
+
- `GET /auth/refresh-token` - Refresh JWT tokens
|
|
186
|
+
|
|
187
|
+
## IAuthProvider Interface (v11.7.x+)
|
|
188
|
+
|
|
189
|
+
The `IAuthProvider` interface abstracts authentication operations:
|
|
190
|
+
|
|
191
|
+
```typescript
|
|
192
|
+
interface IAuthProvider {
|
|
193
|
+
decodeJwt(token: string): JwtPayload;
|
|
194
|
+
validateUser(payload: JwtPayload): Promise<any>;
|
|
195
|
+
signToken(user: any, expiresIn?: string): string;
|
|
196
|
+
}
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
In a future version, this interface will be used by CoreModule.forRoot to support
|
|
200
|
+
both Legacy Auth and BetterAuth transparently.
|
|
201
|
+
|
|
202
|
+
## Timeline
|
|
203
|
+
|
|
204
|
+
| Version | Status | Changes |
|
|
205
|
+
|---------|--------|---------|
|
|
206
|
+
| v11.6.x | Released | BetterAuth introduced |
|
|
207
|
+
| v11.7.x | Current | Legacy endpoint controls, IAuthProvider, migration status |
|
|
208
|
+
| Future | Planned | BetterAuth default, simplified API, Legacy optional |
|
|
209
|
+
|
|
210
|
+
## Related Documentation
|
|
211
|
+
|
|
212
|
+
- [BetterAuth Integration Checklist](../../src/core/modules/better-auth/INTEGRATION-CHECKLIST.md)
|
|
213
|
+
- [Module Inheritance Pattern](./module-inheritance.md)
|
|
214
|
+
- [Role System](./role-system.md)
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# Module Inheritance Pattern
|
|
2
|
+
|
|
3
|
+
**This is a fundamental architectural pattern that MUST be followed for all new modules in `src/core/modules/`.**
|
|
4
|
+
|
|
5
|
+
## Why Inheritance Over Hooks/Events
|
|
6
|
+
|
|
7
|
+
Core modules (like `AuthModule`, `BetterAuthModule`, `FileModule`) are designed to be **extended through inheritance** in consuming projects, not manipulated through hooks, events, or other workarounds. This provides:
|
|
8
|
+
|
|
9
|
+
1. **Full Control**: Projects can override methods and precisely define what happens before/after `super()` calls
|
|
10
|
+
2. **Flexibility**: Parts of the parent implementation can be skipped entirely for custom logic
|
|
11
|
+
3. **Type Safety**: TypeScript inheritance ensures proper typing and IDE support
|
|
12
|
+
4. **Robustness**: No runtime event systems or hooks that can fail silently
|
|
13
|
+
|
|
14
|
+
## Pattern Structure
|
|
15
|
+
|
|
16
|
+
```typescript
|
|
17
|
+
// src/core/modules/example/core-example.resolver.ts (in nest-server)
|
|
18
|
+
@Resolver()
|
|
19
|
+
export class CoreExampleResolver {
|
|
20
|
+
async someMethod() { /* base implementation */ }
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// src/server/modules/example/example.resolver.ts (in consuming project)
|
|
24
|
+
@Resolver()
|
|
25
|
+
export class ExampleResolver extends CoreExampleResolver {
|
|
26
|
+
override async someMethod() {
|
|
27
|
+
// Custom pre-processing
|
|
28
|
+
const result = await super.someMethod(); // Or skip for full override
|
|
29
|
+
// Custom post-processing
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Module Registration Options
|
|
36
|
+
|
|
37
|
+
Core modules should support both:
|
|
38
|
+
|
|
39
|
+
1. **Auto-registration** (`autoRegister: true`) - For simple projects without customization
|
|
40
|
+
2. **Manual registration** (`autoRegister: false`, default) - Projects integrate via extended module
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
// config.env.ts - auto-registration for simple projects
|
|
44
|
+
betterAuth: { autoRegister: true }
|
|
45
|
+
|
|
46
|
+
// server.module.ts - manual registration with custom resolver (recommended)
|
|
47
|
+
BetterAuthModule.forRoot({ config, resolver: CustomResolver })
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Examples in Codebase
|
|
51
|
+
|
|
52
|
+
- `CoreAuthService` → extended by project's `AuthService`
|
|
53
|
+
- `CoreBetterAuthResolver` → extended by project's `BetterAuthResolver`
|
|
54
|
+
- `CoreUserService` → extended by project's `UserService`
|
|
55
|
+
|
|
56
|
+
## Critical: Call Protected Helper Methods When Overriding
|
|
57
|
+
|
|
58
|
+
When overriding methods that have **protected helper methods** in the parent class, you MUST call these helpers in your override. Otherwise, important functionality (guards, checks, validation) will be bypassed.
|
|
59
|
+
|
|
60
|
+
### Example: AuthResolver Override Pattern
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
// WRONG: Missing checkLegacyGraphQLEnabled call
|
|
64
|
+
@Mutation(() => Auth)
|
|
65
|
+
override async signIn(...): Promise<Auth> {
|
|
66
|
+
// Bug: Legacy endpoint check is bypassed!
|
|
67
|
+
const result = await this.authService.signIn(input, serviceOptions);
|
|
68
|
+
return this.processCookies(ctx, result);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// CORRECT: Call the protected check method
|
|
72
|
+
@Mutation(() => Auth)
|
|
73
|
+
override async signIn(...): Promise<Auth> {
|
|
74
|
+
this.checkLegacyGraphQLEnabled('signIn'); // Required!
|
|
75
|
+
const result = await this.authService.signIn(input, serviceOptions);
|
|
76
|
+
return this.processCookies(ctx, result);
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Protected Helper Methods to Call
|
|
81
|
+
|
|
82
|
+
| Core Class | Method | Purpose |
|
|
83
|
+
|------------|--------|---------|
|
|
84
|
+
| `CoreAuthResolver` | `checkLegacyGraphQLEnabled(name)` | Throws HTTP 410 if legacy endpoints disabled |
|
|
85
|
+
| `CoreAuthController` | `checkLegacyRESTEnabled(name)` | Throws HTTP 410 if legacy endpoints disabled |
|
|
86
|
+
|
|
87
|
+
**Rule**: When you override a method, check if the parent calls any `protected` helper methods. If so, call them in your override too.
|
|
88
|
+
|
|
89
|
+
## Checklist for New Core Modules
|
|
90
|
+
|
|
91
|
+
When adding new core modules, ensure:
|
|
92
|
+
|
|
93
|
+
- [ ] Base classes in `src/core/modules/` with `Core` prefix
|
|
94
|
+
- [ ] Methods are `protected` or `public` (not `private`) to allow override
|
|
95
|
+
- [ ] `autoRegister` option defaults to `false`
|
|
96
|
+
- [ ] Clear documentation for extension points
|
|
97
|
+
- [ ] Export base classes via `src/index.ts`
|