sonamu 0.8.24 → 0.8.26
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/api/__tests__/config.test.js +189 -0
- package/dist/api/config.d.ts.map +1 -1
- package/dist/api/config.js +7 -2
- package/dist/api/sonamu.d.ts.map +1 -1
- package/dist/api/sonamu.js +14 -10
- package/dist/auth/index.d.ts +1 -0
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +2 -1
- package/dist/auth/knex-adapter.d.ts +23 -0
- package/dist/auth/knex-adapter.d.ts.map +1 -0
- package/dist/auth/knex-adapter.js +163 -0
- package/dist/auth/plugins/wrappers/admin.d.ts +2 -2
- package/dist/bin/__tests__/ts-loader-register.test.js +45 -0
- package/dist/bin/cli.js +47 -9
- package/dist/bin/ts-loader-register.js +3 -29
- package/dist/bin/ts-loader-registration.d.ts +2 -0
- package/dist/bin/ts-loader-registration.d.ts.map +1 -0
- package/dist/bin/ts-loader-registration.js +42 -0
- package/dist/cone/cone-generator.js +3 -3
- package/dist/database/puri-subset.test-d.js +9 -1
- package/dist/database/puri-subset.types.d.ts +1 -1
- package/dist/database/puri-subset.types.d.ts.map +1 -1
- package/dist/database/puri-subset.types.js +1 -1
- package/dist/testing/fixture-generator.js +5 -5
- package/dist/ui/ai-client.js +2 -2
- package/dist/ui/api.d.ts.map +1 -1
- package/dist/ui/api.js +14 -14
- package/dist/ui/cdd-service.d.ts +15 -18
- package/dist/ui/cdd-service.d.ts.map +1 -1
- package/dist/ui/cdd-service.js +246 -222
- package/dist/ui/cdd-types.d.ts +41 -68
- package/dist/ui/cdd-types.d.ts.map +1 -1
- package/dist/ui/cdd-types.js +2 -2
- package/dist/ui-web/assets/index-CKo0Z2Iu.css +1 -0
- package/dist/ui-web/assets/{index-CxiydzeC.js → index-DK-2aacv.js} +83 -83
- package/dist/ui-web/index.html +2 -2
- package/package.json +6 -2
- package/src/api/__tests__/config.test.ts +225 -0
- package/src/api/config.ts +10 -4
- package/src/api/sonamu.ts +16 -13
- package/src/auth/index.ts +1 -0
- package/src/auth/knex-adapter.ts +208 -0
- package/src/bin/__tests__/ts-loader-register.test.ts +62 -0
- package/src/bin/cli.ts +52 -9
- package/src/bin/ts-loader-register.ts +2 -32
- package/src/bin/ts-loader-registration.ts +55 -0
- package/src/cone/cone-generator.ts +2 -2
- package/src/database/puri-subset.test-d.ts +102 -0
- package/src/database/puri-subset.types.ts +1 -1
- package/src/skills/commands/sonamu-skills.md +20 -0
- package/src/skills/sonamu/SKILL.md +179 -137
- package/src/skills/sonamu/ai-agents.md +69 -69
- package/src/skills/sonamu/api.md +147 -147
- package/src/skills/sonamu/auth-migration.md +220 -220
- package/src/skills/sonamu/auth-plugins.md +83 -83
- package/src/skills/sonamu/auth.md +106 -106
- package/src/skills/sonamu/cdd.md +65 -200
- package/src/skills/sonamu/cone.md +138 -138
- package/src/skills/sonamu/config.md +191 -191
- package/src/skills/sonamu/create-sonamu.md +66 -66
- package/src/skills/sonamu/database.md +158 -158
- package/src/skills/sonamu/entity-basic.md +292 -293
- package/src/skills/sonamu/entity-relations.md +246 -246
- package/src/skills/sonamu/entity-validation-checklist.md +124 -124
- package/src/skills/sonamu/fixture-cli.md +231 -231
- package/src/skills/sonamu/framework-change.md +37 -37
- package/src/skills/sonamu/frontend.md +223 -223
- package/src/skills/sonamu/i18n.md +82 -82
- package/src/skills/sonamu/migration.md +77 -77
- package/src/skills/sonamu/model.md +222 -222
- package/src/skills/sonamu/naite.md +86 -86
- package/src/skills/sonamu/project-init.md +228 -228
- package/src/skills/sonamu/puri.md +122 -122
- package/src/skills/sonamu/scaffolding.md +154 -154
- package/src/skills/sonamu/skill-contribution.md +124 -124
- package/src/skills/sonamu/subset.md +46 -46
- package/src/skills/sonamu/tasks.md +82 -82
- package/src/skills/sonamu/testing-devrunner.md +147 -147
- package/src/skills/sonamu/testing.md +673 -673
- package/src/skills/sonamu/upsert.md +79 -79
- package/src/skills/sonamu/vector.md +67 -67
- package/src/testing/fixture-generator.ts +4 -4
- package/src/ui/ai-client.ts +1 -1
- package/src/ui/api.ts +18 -17
- package/src/ui/cdd-service.ts +264 -254
- package/src/ui/cdd-types.ts +40 -75
- package/dist/ui-web/assets/index-BrQKU3j9.css +0 -1
- package/src/skills/sonamu/workflow.md +0 -317
|
@@ -1,64 +1,64 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: sonamu-auth-plugins
|
|
3
|
-
description: better-auth
|
|
3
|
+
description: better-auth plugin wrappers and automatic entity generation. Includes Sonamu snake_case schema mapping. Use when adding auth plugins like admin, organization, 2fa, passkey, phone-number, jwt, api-key, sso, username, anonymous.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
# better-auth
|
|
6
|
+
# better-auth Plugin Guide
|
|
7
7
|
|
|
8
|
-
Sonamu
|
|
9
|
-
`auth generate --plugins`
|
|
8
|
+
Sonamu wraps better-auth plugins with snake_case schema mapping.
|
|
9
|
+
Use the `auth generate --plugins` command to auto-generate plugin entities.
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
11
|
+
**Source code:**
|
|
12
|
+
- Wrappers: `modules/sonamu/src/auth/plugins/wrappers/`
|
|
13
|
+
- Entity definitions: `modules/sonamu/src/auth/plugins/entity-definitions/`
|
|
14
|
+
- Generator: `modules/sonamu/src/auth/auth-generator.ts`
|
|
15
15
|
|
|
16
16
|
---
|
|
17
17
|
|
|
18
|
-
##
|
|
19
|
-
|
|
20
|
-
|
|
|
21
|
-
|
|
22
|
-
| `admin` | `admin()` | `better-auth/plugins` |
|
|
23
|
-
| `organization` | `organization()` | `better-auth/plugins` |
|
|
24
|
-
| `2fa` | `twoFactor()` | `better-auth/plugins` | TOTP
|
|
25
|
-
| `username` | `username()` | `better-auth/plugins` |
|
|
26
|
-
| `phone-number` | `phoneNumber()` | `better-auth/plugins` |
|
|
27
|
-
| `api-key` | `apiKey()` | `better-auth/plugins` | API
|
|
28
|
-
| `jwt` | `jwt()` | `better-auth/plugins` | JWT
|
|
29
|
-
| `passkey` | `passkey()` | `@better-auth/passkey` | WebAuthn/Passkey
|
|
30
|
-
| `sso` | `sso()` | `@better-auth/sso` | OIDC/SAML SSO
|
|
31
|
-
| `anonymous` | `anonymous()` | `better-auth/plugins` |
|
|
18
|
+
## Supported Plugins
|
|
19
|
+
|
|
20
|
+
| Plugin ID | Wrapper function | Package | Purpose |
|
|
21
|
+
|-----------|-----------------|---------|---------|
|
|
22
|
+
| `admin` | `admin()` | `better-auth/plugins` | Admin features, user ban/unban, session impersonation |
|
|
23
|
+
| `organization` | `organization()` | `better-auth/plugins` | Organization, team, member, and invitation management |
|
|
24
|
+
| `2fa` | `twoFactor()` | `better-auth/plugins` | TOTP-based two-factor authentication |
|
|
25
|
+
| `username` | `username()` | `better-auth/plugins` | Username-based authentication |
|
|
26
|
+
| `phone-number` | `phoneNumber()` | `better-auth/plugins` | Phone number authentication |
|
|
27
|
+
| `api-key` | `apiKey()` | `better-auth/plugins` | API key issuance/management, rate limiting |
|
|
28
|
+
| `jwt` | `jwt()` | `better-auth/plugins` | JWT tokens + JWKS key management |
|
|
29
|
+
| `passkey` | `passkey()` | `@better-auth/passkey` | WebAuthn/Passkey authentication |
|
|
30
|
+
| `sso` | `sso()` | `@better-auth/sso` | OIDC/SAML SSO integration |
|
|
31
|
+
| `anonymous` | `anonymous()` | `better-auth/plugins` | Anonymous user support |
|
|
32
32
|
|
|
33
33
|
---
|
|
34
34
|
|
|
35
|
-
## CLI
|
|
35
|
+
## CLI Usage
|
|
36
36
|
|
|
37
37
|
```bash
|
|
38
|
-
#
|
|
38
|
+
# Base entities only (User, Session, Account, Verification)
|
|
39
39
|
pnpm sonamu auth generate
|
|
40
40
|
|
|
41
|
-
#
|
|
41
|
+
# With plugins
|
|
42
42
|
pnpm sonamu auth generate --plugins admin,organization
|
|
43
43
|
|
|
44
|
-
#
|
|
44
|
+
# Multiple plugins
|
|
45
45
|
pnpm sonamu auth generate --plugins admin,2fa,phone-number,username
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
-
###
|
|
48
|
+
### How It Works
|
|
49
49
|
|
|
50
|
-
1.
|
|
51
|
-
2.
|
|
52
|
-
- `entities`:
|
|
53
|
-
- `additionalProps`:
|
|
54
|
-
- `additionalIndexes`:
|
|
55
|
-
3.
|
|
50
|
+
1. **Base entities** are created/updated (User, Session, Account, Verification)
|
|
51
|
+
2. **Per-plugin** processing:
|
|
52
|
+
- `entities`: creates new tables (e.g. Organization → organizations, members, invitations, teams, team_members)
|
|
53
|
+
- `additionalProps`: adds fields to existing entities (e.g. admin → adds ban_reason, ban_expires to User)
|
|
54
|
+
- `additionalIndexes`: adds indexes to existing entities
|
|
55
|
+
3. Entities that already exist have **only missing fields added**; existing fields are preserved
|
|
56
56
|
|
|
57
57
|
---
|
|
58
58
|
|
|
59
|
-
##
|
|
59
|
+
## Wrapper Usage (sonamu.config.ts)
|
|
60
60
|
|
|
61
|
-
Sonamu
|
|
61
|
+
Using Sonamu wrappers automatically applies snake_case schema mapping.
|
|
62
62
|
|
|
63
63
|
```typescript
|
|
64
64
|
// sonamu.config.ts
|
|
@@ -79,45 +79,45 @@ export default defineConfig({
|
|
|
79
79
|
});
|
|
80
80
|
```
|
|
81
81
|
|
|
82
|
-
**CRITICAL: `better-auth/plugins
|
|
82
|
+
**CRITICAL: Do not import directly from `better-auth/plugins`.** You must go through the Sonamu wrapper for snake_case mapping to apply.
|
|
83
83
|
|
|
84
84
|
```typescript
|
|
85
|
-
// WRONG - snake_case
|
|
85
|
+
// WRONG - snake_case mapping not applied
|
|
86
86
|
import { admin } from "better-auth/plugins";
|
|
87
87
|
|
|
88
|
-
// CORRECT - Sonamu
|
|
88
|
+
// CORRECT - Sonamu wrapper
|
|
89
89
|
import { admin } from "sonamu/auth/plugins";
|
|
90
90
|
```
|
|
91
91
|
|
|
92
92
|
---
|
|
93
93
|
|
|
94
|
-
##
|
|
94
|
+
## Per-Plugin Details
|
|
95
95
|
|
|
96
96
|
### admin
|
|
97
97
|
|
|
98
|
-
|
|
99
|
-
**
|
|
100
|
-
**
|
|
98
|
+
**Additional entities:** None
|
|
99
|
+
**Fields added to User:** `role`, `banned`, `ban_reason`, `ban_expires`
|
|
100
|
+
**Fields added to Session:** `impersonated_by`
|
|
101
101
|
|
|
102
102
|
```typescript
|
|
103
103
|
import { admin } from "sonamu/auth/plugins";
|
|
104
104
|
|
|
105
|
-
//
|
|
105
|
+
// Basic usage
|
|
106
106
|
admin()
|
|
107
107
|
|
|
108
|
-
//
|
|
108
|
+
// Customize options (schema mapping is automatically merged)
|
|
109
109
|
admin({ defaultRole: "user" })
|
|
110
110
|
```
|
|
111
111
|
|
|
112
|
-
|
|
112
|
+
Schema mapping:
|
|
113
113
|
- `banReason` → `ban_reason`
|
|
114
114
|
- `banExpires` → `ban_expires`
|
|
115
115
|
- `impersonatedBy` → `impersonated_by`
|
|
116
116
|
|
|
117
117
|
### organization
|
|
118
118
|
|
|
119
|
-
|
|
120
|
-
**
|
|
119
|
+
**Additional entities:** Organization, Member, Invitation, Team, TeamMember
|
|
120
|
+
**Fields added to Session:** `active_organization_id`, `active_team_id`
|
|
121
121
|
|
|
122
122
|
```typescript
|
|
123
123
|
import { organization } from "sonamu/auth/plugins";
|
|
@@ -125,8 +125,8 @@ import { organization } from "sonamu/auth/plugins";
|
|
|
125
125
|
organization()
|
|
126
126
|
```
|
|
127
127
|
|
|
128
|
-
|
|
129
|
-
-
|
|
128
|
+
Schema mapping:
|
|
129
|
+
- All tables: `createdAt` → `created_at`
|
|
130
130
|
- Member: `userId` → `user_id`, `organizationId` → `organization_id`
|
|
131
131
|
- Invitation: `inviterId` → `inviter_id`, `organizationId` → `organization_id`, `teamId` → `team_id`, `expiresAt` → `expires_at`
|
|
132
132
|
- Team: `organizationId` → `organization_id`, `updatedAt` → `updated_at`
|
|
@@ -135,8 +135,8 @@ organization()
|
|
|
135
135
|
|
|
136
136
|
### 2fa (twoFactor)
|
|
137
137
|
|
|
138
|
-
|
|
139
|
-
**
|
|
138
|
+
**Additional entities:** TwoFactor
|
|
139
|
+
**Fields added to User:** `two_factor_enabled`
|
|
140
140
|
|
|
141
141
|
```typescript
|
|
142
142
|
import { twoFactor } from "sonamu/auth/plugins";
|
|
@@ -144,13 +144,13 @@ import { twoFactor } from "sonamu/auth/plugins";
|
|
|
144
144
|
twoFactor()
|
|
145
145
|
```
|
|
146
146
|
|
|
147
|
-
|
|
147
|
+
Schema mapping:
|
|
148
148
|
- User: `twoFactorEnabled` → `two_factor_enabled`
|
|
149
149
|
- TwoFactor: `userId` → `user_id`, `backupCodes` → `backup_codes`
|
|
150
150
|
|
|
151
151
|
### username
|
|
152
152
|
|
|
153
|
-
**
|
|
153
|
+
**Fields added to User:** `display_username`
|
|
154
154
|
|
|
155
155
|
```typescript
|
|
156
156
|
import { username } from "sonamu/auth/plugins";
|
|
@@ -158,26 +158,26 @@ import { username } from "sonamu/auth/plugins";
|
|
|
158
158
|
username()
|
|
159
159
|
```
|
|
160
160
|
|
|
161
|
-
|
|
161
|
+
Schema mapping:
|
|
162
162
|
- `displayUsername` → `display_username`
|
|
163
163
|
|
|
164
164
|
### phone-number
|
|
165
165
|
|
|
166
|
-
**
|
|
166
|
+
**Fields added to User:** `phone_number`, `phone_number_verified`
|
|
167
167
|
|
|
168
168
|
```typescript
|
|
169
169
|
import { phoneNumber } from "sonamu/auth/plugins";
|
|
170
170
|
|
|
171
|
-
phoneNumber({ sendOTP: async ({ phoneNumber, otp }) => { /* SMS
|
|
171
|
+
phoneNumber({ sendOTP: async ({ phoneNumber, otp }) => { /* send SMS */ } })
|
|
172
172
|
```
|
|
173
173
|
|
|
174
|
-
|
|
174
|
+
Schema mapping:
|
|
175
175
|
- `phoneNumber` → `phone_number`
|
|
176
176
|
- `phoneNumberVerified` → `phone_number_verified`
|
|
177
177
|
|
|
178
178
|
### api-key
|
|
179
179
|
|
|
180
|
-
|
|
180
|
+
**Additional entities:** ApiKey (table: `api_keys`)
|
|
181
181
|
|
|
182
182
|
```typescript
|
|
183
183
|
import { apiKey } from "sonamu/auth/plugins";
|
|
@@ -185,7 +185,7 @@ import { apiKey } from "sonamu/auth/plugins";
|
|
|
185
185
|
apiKey()
|
|
186
186
|
```
|
|
187
187
|
|
|
188
|
-
|
|
188
|
+
Schema mapping:
|
|
189
189
|
- `userId` → `user_id`, `lastRequest` → `last_request`, `requestCount` → `request_count`
|
|
190
190
|
- `rateLimitEnabled` → `rate_limit_enabled`, `rateLimitTimeWindow` → `rate_limit_time_window`
|
|
191
191
|
- `rateLimitMax` → `rate_limit_max`, `refillInterval` → `refill_interval`
|
|
@@ -194,7 +194,7 @@ apiKey()
|
|
|
194
194
|
|
|
195
195
|
### jwt
|
|
196
196
|
|
|
197
|
-
|
|
197
|
+
**Additional entities:** Jwks (table: `jwks`)
|
|
198
198
|
|
|
199
199
|
```typescript
|
|
200
200
|
import { jwt } from "sonamu/auth/plugins";
|
|
@@ -202,14 +202,14 @@ import { jwt } from "sonamu/auth/plugins";
|
|
|
202
202
|
jwt()
|
|
203
203
|
```
|
|
204
204
|
|
|
205
|
-
|
|
205
|
+
Schema mapping:
|
|
206
206
|
- `publicKey` → `public_key`, `privateKey` → `private_key`
|
|
207
207
|
- `createdAt` → `created_at`, `expiresAt` → `expires_at`
|
|
208
208
|
|
|
209
209
|
### passkey
|
|
210
210
|
|
|
211
|
-
|
|
212
|
-
|
|
211
|
+
**Additional entities:** Passkey (table: `passkeys`)
|
|
212
|
+
**Package:** `@better-auth/passkey` (must be installed separately)
|
|
213
213
|
|
|
214
214
|
```bash
|
|
215
215
|
pnpm add @better-auth/passkey
|
|
@@ -221,13 +221,13 @@ import { passkey } from "sonamu/auth/plugins";
|
|
|
221
221
|
passkey({ rpID: "localhost", rpName: "My App" })
|
|
222
222
|
```
|
|
223
223
|
|
|
224
|
-
|
|
224
|
+
Schema mapping:
|
|
225
225
|
- `publicKey` → `public_key`, `userId` → `user_id`, `credentialID` → `credential_id`
|
|
226
226
|
- `deviceType` → `device_type`, `backedUp` → `backed_up`, `createdAt` → `created_at`
|
|
227
227
|
|
|
228
228
|
### sso
|
|
229
229
|
|
|
230
|
-
|
|
230
|
+
**Package:** `@better-auth/sso` (must be installed separately)
|
|
231
231
|
|
|
232
232
|
```bash
|
|
233
233
|
pnpm add @better-auth/sso
|
|
@@ -239,14 +239,14 @@ import { sso } from "sonamu/auth/plugins";
|
|
|
239
239
|
sso()
|
|
240
240
|
```
|
|
241
241
|
|
|
242
|
-
|
|
243
|
-
|
|
242
|
+
Table: `sso_providers`
|
|
243
|
+
Schema mapping:
|
|
244
244
|
- `oidcConfig` → `oidc_config`, `samlConfig` → `saml_config`
|
|
245
245
|
- `userId` → `user_id`, `providerId` → `provider_id`, `organizationId` → `organization_id`
|
|
246
246
|
|
|
247
247
|
### anonymous
|
|
248
248
|
|
|
249
|
-
**
|
|
249
|
+
**Fields added to User:** `is_anonymous`
|
|
250
250
|
|
|
251
251
|
```typescript
|
|
252
252
|
import { anonymous } from "sonamu/auth/plugins";
|
|
@@ -254,14 +254,14 @@ import { anonymous } from "sonamu/auth/plugins";
|
|
|
254
254
|
anonymous()
|
|
255
255
|
```
|
|
256
256
|
|
|
257
|
-
|
|
257
|
+
Schema mapping:
|
|
258
258
|
- `isAnonymous` → `is_anonymous`
|
|
259
259
|
|
|
260
260
|
---
|
|
261
261
|
|
|
262
|
-
##
|
|
262
|
+
## Custom Schema Options
|
|
263
263
|
|
|
264
|
-
|
|
264
|
+
Passing additional options to a wrapper function automatically merges them with Sonamu's default mapping:
|
|
265
265
|
|
|
266
266
|
```typescript
|
|
267
267
|
admin({
|
|
@@ -269,29 +269,29 @@ admin({
|
|
|
269
269
|
schema: {
|
|
270
270
|
user: {
|
|
271
271
|
fields: {
|
|
272
|
-
customField: "custom_field", //
|
|
272
|
+
customField: "custom_field", // additional mapping
|
|
273
273
|
},
|
|
274
274
|
},
|
|
275
275
|
},
|
|
276
276
|
})
|
|
277
277
|
```
|
|
278
278
|
|
|
279
|
-
|
|
279
|
+
Internally, `merge(ADMIN_SCHEMA, options.schema)` is executed to preserve the Sonamu mapping.
|
|
280
280
|
|
|
281
281
|
---
|
|
282
282
|
|
|
283
|
-
##
|
|
283
|
+
## Steps After Adding a Plugin
|
|
284
284
|
|
|
285
|
-
1. `pnpm sonamu auth generate --plugins
|
|
286
|
-
2.
|
|
287
|
-
3. `pnpm sonamu migrate run
|
|
288
|
-
4. `sonamu.config.ts
|
|
289
|
-
5.
|
|
285
|
+
1. `pnpm sonamu auth generate --plugins <plugin list>`
|
|
286
|
+
2. Confirm generated entities in Sonamu UI
|
|
287
|
+
3. Run migration with `pnpm sonamu migrate run`
|
|
288
|
+
4. Add wrapper functions to `sonamu.config.ts`
|
|
289
|
+
5. If needed, add plugin-specific permission logic to `guardHandler`
|
|
290
290
|
|
|
291
291
|
---
|
|
292
292
|
|
|
293
|
-
##
|
|
293
|
+
## References
|
|
294
294
|
|
|
295
|
-
-
|
|
296
|
-
- **PK
|
|
297
|
-
-
|
|
295
|
+
- **Basic auth configuration:** `auth.md`
|
|
296
|
+
- **Changing PK type (better-auth → string PK):** `auth-migration.md`
|
|
297
|
+
- **Source code:** `modules/sonamu/src/auth/plugins/`
|