@spfn/auth 0.1.0-alpha.0 → 0.1.0-alpha.1

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 (67) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +70 -12
  3. package/dist/api-BcQM4WKb.d.ts +45 -0
  4. package/dist/client.d.ts +2 -0
  5. package/dist/client.js +1 -0
  6. package/dist/client.js.map +1 -0
  7. package/dist/index.d.ts +57 -0
  8. package/dist/index.js +8966 -0
  9. package/dist/index.js.map +1 -0
  10. package/dist/lib/contracts/auth.d.ts +262 -0
  11. package/dist/lib/contracts/auth.js +2923 -0
  12. package/dist/lib/contracts/auth.js.map +1 -0
  13. package/dist/lib/contracts/index.d.ts +3 -0
  14. package/dist/lib/contracts/index.js +3162 -0
  15. package/dist/lib/contracts/index.js.map +1 -0
  16. package/dist/lib/contracts/invitation.d.ts +243 -0
  17. package/dist/lib/contracts/invitation.js +2883 -0
  18. package/dist/lib/contracts/invitation.js.map +1 -0
  19. package/dist/plugin.d.ts +12 -0
  20. package/dist/plugin.js +8949 -0
  21. package/dist/plugin.js.map +1 -0
  22. package/dist/server/entities/index.d.ts +10 -0
  23. package/dist/server/entities/index.js +399 -0
  24. package/dist/server/entities/index.js.map +1 -0
  25. package/dist/server/entities/invitations.d.ts +241 -0
  26. package/dist/server/entities/invitations.js +181 -0
  27. package/dist/server/entities/invitations.js.map +1 -0
  28. package/dist/server/entities/permissions.d.ts +196 -0
  29. package/dist/server/entities/permissions.js +44 -0
  30. package/dist/server/entities/permissions.js.map +1 -0
  31. package/dist/server/entities/role-permissions.d.ts +107 -0
  32. package/dist/server/entities/role-permissions.js +112 -0
  33. package/dist/server/entities/role-permissions.js.map +1 -0
  34. package/dist/server/entities/roles.d.ts +196 -0
  35. package/dist/server/entities/roles.js +45 -0
  36. package/dist/server/entities/roles.js.map +1 -0
  37. package/dist/server/entities/user-permissions.d.ts +163 -0
  38. package/dist/server/entities/user-permissions.js +191 -0
  39. package/dist/server/entities/user-permissions.js.map +1 -0
  40. package/dist/server/entities/user-public-keys.d.ts +227 -0
  41. package/dist/server/entities/user-public-keys.js +153 -0
  42. package/dist/server/entities/user-public-keys.js.map +1 -0
  43. package/dist/server/entities/user-social-accounts.d.ts +189 -0
  44. package/dist/server/entities/user-social-accounts.js +146 -0
  45. package/dist/server/entities/user-social-accounts.js.map +1 -0
  46. package/dist/server/entities/users.d.ts +235 -0
  47. package/dist/server/entities/users.js +113 -0
  48. package/dist/server/entities/users.js.map +1 -0
  49. package/dist/server/entities/verification-codes.d.ts +191 -0
  50. package/dist/server/entities/verification-codes.js +44 -0
  51. package/dist/server/entities/verification-codes.js.map +1 -0
  52. package/dist/server/routes/auth/index.d.ts +10 -0
  53. package/dist/server/routes/auth/index.js +4475 -0
  54. package/dist/server/routes/auth/index.js.map +1 -0
  55. package/dist/server/routes/index.d.ts +6 -0
  56. package/dist/server/routes/index.js +6352 -0
  57. package/dist/server/routes/index.js.map +1 -0
  58. package/dist/server/routes/invitations/index.d.ts +10 -0
  59. package/dist/server/routes/invitations/index.js +4209 -0
  60. package/dist/server/routes/invitations/index.js.map +1 -0
  61. package/dist/server.d.ts +1243 -0
  62. package/dist/server.js +2281 -0
  63. package/dist/server.js.map +1 -0
  64. package/migrations/0000_tired_gambit.sql +165 -0
  65. package/migrations/meta/0000_snapshot.json +1395 -0
  66. package/migrations/meta/_journal.json +13 -0
  67. package/package.json +32 -24
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 INFLIKE Inc.
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 CHANGED
@@ -1166,8 +1166,8 @@ if (shouldRotate) {
1166
1166
 
1167
1167
  ```bash
1168
1168
  # .env
1169
- JWT_SECRET=your-secret-key-change-in-production # For legacy tokens
1170
- JWT_EXPIRES_IN=7d # Token expiry
1169
+ SPFN_AUTH_JWT_SECRET=your-secret-key-change-in-production # For legacy tokens
1170
+ SPFN_AUTH_JWT_EXPIRES_IN=7d # Token expiry
1171
1171
  ```
1172
1172
 
1173
1173
  ---
@@ -1196,12 +1196,70 @@ This creates the auth schema with 8 tables:
1196
1196
 
1197
1197
  ### 2. Configure Environment Variables
1198
1198
 
1199
+ #### Core Settings (Required)
1200
+
1199
1201
  ```bash
1200
1202
  # .env
1201
- JWT_SECRET=your-secret-key-change-in-production
1202
- JWT_EXPIRES_IN=7d
1203
+
1204
+ # ========================================
1205
+ # Core Authentication Settings (Required)
1206
+ # ========================================
1207
+
1208
+ # JWT Token Settings
1209
+ SPFN_AUTH_JWT_SECRET=your-secret-key-change-in-production # JWT signing secret (REQUIRED)
1210
+ SPFN_AUTH_JWT_EXPIRES_IN=7d # JWT token expiry (default: 7d)
1211
+
1212
+ # Verification Token Settings
1213
+ SPFN_AUTH_VERIFICATION_TOKEN_SECRET=separate-secret-key # Optional: separate secret for verification tokens
1214
+ # If not set, uses SPFN_AUTH_JWT_SECRET
1215
+
1216
+ # Password Hashing
1217
+ SPFN_AUTH_BCRYPT_SALT_ROUNDS=10 # bcrypt salt rounds (default: 10)
1218
+ # Higher = more secure but slower (10-12 recommended)
1219
+
1220
+ # ========================================
1221
+ # Client-Side Settings (Optional)
1222
+ # ========================================
1223
+
1224
+ # Session Management (for client-side session encryption)
1225
+ SPFN_AUTH_SESSION_SECRET=session-encryption-key # Required if using client-side session features
1226
+
1227
+ # API URL Configuration (for client-side API calls)
1228
+ SPFN_API_URL=http://localhost:8790 # SPFN API server URL
1229
+ NEXT_PUBLIC_API_URL=http://localhost:8790 # Next.js public API URL (takes precedence)
1230
+
1231
+ # Environment
1232
+ NODE_ENV=production # production | development
1203
1233
  ```
1204
1234
 
1235
+ #### Admin Account Creation (Optional)
1236
+
1237
+ See [Section 3: Create Initial Admin Accounts](#3-create-initial-admin-accounts-optional) below for details.
1238
+
1239
+ d---
1240
+
1241
+ ### Legacy Environment Variables (Backward Compatibility)
1242
+
1243
+ For backward compatibility, the package also supports legacy environment variable names without the `SPFN_AUTH_` prefix. The new prefixed versions take precedence:
1244
+
1245
+ ```bash
1246
+ # Legacy (still supported, but deprecated)
1247
+ JWT_SECRET=...
1248
+ JWT_EXPIRES_IN=...
1249
+ VERIFICATION_TOKEN_SECRET=...
1250
+ BCRYPT_SALT_ROUNDS=...
1251
+ SESSION_SECRET=...
1252
+
1253
+ ADMIN_ACCOUNTS=...
1254
+ ADMIN_EMAILS=...
1255
+ ADMIN_PASSWORDS=...
1256
+ ADMIN_ROLES=...
1257
+ ADMIN_EMAIL=...
1258
+ ADMIN_PASSWORD=...
1259
+ ```
1260
+
1261
+ **Recommendation:** Use the new `SPFN_AUTH_*` prefixed variables to avoid conflicts with other packages.
1262
+
1205
1263
  ### 3. Create Initial Admin Accounts (Optional)
1206
1264
 
1207
1265
  You can automatically create admin accounts on server startup using environment variables. Three formats are supported:
@@ -1212,7 +1270,7 @@ Allows full control over each account's configuration.
1212
1270
 
1213
1271
  ```bash
1214
1272
  # .env
1215
- ADMIN_ACCOUNTS='[
1273
+ SPFN_AUTH_ADMIN_ACCOUNTS='[
1216
1274
  {
1217
1275
  "email": "super@example.com",
1218
1276
  "password": "super-password",
@@ -1249,14 +1307,14 @@ Quick setup for multiple accounts with basic configuration.
1249
1307
 
1250
1308
  ```bash
1251
1309
  # .env
1252
- ADMIN_EMAILS=super@example.com,admin@example.com,user@example.com
1253
- ADMIN_PASSWORDS=super-pass,admin-pass,user-pass
1254
- ADMIN_ROLES=superadmin,admin,user # Optional, defaults to 'user'
1310
+ SPFN_AUTH_ADMIN_EMAILS=super@example.com,admin@example.com,user@example.com
1311
+ SPFN_AUTH_ADMIN_PASSWORDS=super-pass,admin-pass,user-pass
1312
+ SPFN_AUTH_ADMIN_ROLES=superadmin,admin,user # Optional, defaults to 'user'
1255
1313
  ```
1256
1314
 
1257
1315
  **Requirements:**
1258
- - `ADMIN_EMAILS` and `ADMIN_PASSWORDS` must have the same number of items
1259
- - `ADMIN_ROLES` is optional (defaults to `user` for each account)
1316
+ - `SPFN_AUTH_ADMIN_EMAILS` and `SPFN_AUTH_ADMIN_PASSWORDS` must have the same number of items
1317
+ - `SPFN_AUTH_ADMIN_ROLES` is optional (defaults to `user` for each account)
1260
1318
  - All accounts will have `passwordChangeRequired: true`
1261
1319
 
1262
1320
  ---
@@ -1267,8 +1325,8 @@ For backward compatibility, you can create a single superadmin account.
1267
1325
 
1268
1326
  ```bash
1269
1327
  # .env
1270
- ADMIN_EMAIL=admin@example.com
1271
- ADMIN_PASSWORD=secure-password
1328
+ SPFN_AUTH_ADMIN_EMAIL=admin@example.com
1329
+ SPFN_AUTH_ADMIN_PASSWORD=secure-password
1272
1330
  ```
1273
1331
 
1274
1332
  This creates a single account with:
@@ -0,0 +1,45 @@
1
+ /**
2
+ * @spfn/auth - API Response Types
3
+ *
4
+ * Auth-specific types for API endpoints
5
+ * For standard response types, import from '@spfn/core/route'
6
+ */
7
+ /**
8
+ * Session types
9
+ */
10
+ interface SessionPayload {
11
+ userId: string;
12
+ role?: string;
13
+ }
14
+ /**
15
+ * RBAC types
16
+ */
17
+ interface Permission {
18
+ resource: string;
19
+ action: string;
20
+ }
21
+ /**
22
+ * API Response Types for specific endpoints
23
+ */
24
+ interface CheckAccountExistsData {
25
+ exists: boolean;
26
+ identifier: string;
27
+ identifierType: 'email' | 'phone';
28
+ }
29
+ interface LoginData {
30
+ token: string;
31
+ user: {
32
+ id: string;
33
+ email?: string;
34
+ phone?: string;
35
+ role: string;
36
+ emailVerifiedAt?: string;
37
+ phoneVerifiedAt?: string;
38
+ };
39
+ passwordChangeRequired: boolean;
40
+ }
41
+ interface ChangePasswordData {
42
+ success: boolean;
43
+ }
44
+
45
+ export type { CheckAccountExistsData as C, LoginData as L, Permission as P, SessionPayload as S, ChangePasswordData as a };
@@ -0,0 +1,2 @@
1
+
2
+ export { }
package/dist/client.js ADDED
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,57 @@
1
+ export { spfnPlugin } from './plugin.js';
2
+ export { a as ChangePasswordData, C as CheckAccountExistsData, L as LoginData, P as Permission, S as SessionPayload } from './api-BcQM4WKb.js';
3
+ import * as _sinclair_typebox from '@sinclair/typebox';
4
+ import { TObject } from '@sinclair/typebox';
5
+ export { NewUser, User, UserStatus, UserWithVerification, users } from './server/entities/users.js';
6
+ export { NewUserSocialAccount, UserSocialAccount, userSocialAccounts } from './server/entities/user-social-accounts.js';
7
+ export { NewUserPublicKey, UserPublicKey, userPublicKeys } from './server/entities/user-public-keys.js';
8
+ export { NewVerificationCode, VerificationCode, verificationCodes } from './server/entities/verification-codes.js';
9
+ export { NewRole, NewRoleEntity, Role, RoleEntity, roles } from './server/entities/roles.js';
10
+ export { NewPermissionEntity, PermissionEntity, permissions } from './server/entities/permissions.js';
11
+ export { NewRolePermission, RolePermission, rolePermissions } from './server/entities/role-permissions.js';
12
+ export { NewUserPermission, UserPermission, userPermissions } from './server/entities/user-permissions.js';
13
+ import '@spfn/core/server';
14
+ import 'drizzle-orm/pg-core';
15
+
16
+ /**
17
+ * Success response schema wrapper
18
+ *
19
+ * Wraps a data schema with success: true and optional message
20
+ */
21
+ declare const SuccessResponseSchema: <T extends TObject>(dataSchema: T) => TObject<{
22
+ success: _sinclair_typebox.TLiteral<true>;
23
+ data: T;
24
+ message: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
25
+ }>;
26
+ /**
27
+ * Error response schema
28
+ *
29
+ * Standard error format with code, message, and optional details
30
+ */
31
+ declare const ErrorResponseSchema: TObject<{
32
+ success: _sinclair_typebox.TLiteral<false>;
33
+ error: TObject<{
34
+ code: _sinclair_typebox.TString;
35
+ message: _sinclair_typebox.TString;
36
+ details: _sinclair_typebox.TOptional<_sinclair_typebox.TAny>;
37
+ }>;
38
+ }>;
39
+ /**
40
+ * API Response schema (union of success and error)
41
+ *
42
+ * Use this to define contract responses that can be either success or error
43
+ */
44
+ declare const ApiResponseSchema: <T extends TObject>(dataSchema: T) => _sinclair_typebox.TUnion<[TObject<{
45
+ success: _sinclair_typebox.TLiteral<true>;
46
+ data: T;
47
+ message: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
48
+ }>, TObject<{
49
+ success: _sinclair_typebox.TLiteral<false>;
50
+ error: TObject<{
51
+ code: _sinclair_typebox.TString;
52
+ message: _sinclair_typebox.TString;
53
+ details: _sinclair_typebox.TOptional<_sinclair_typebox.TAny>;
54
+ }>;
55
+ }>]>;
56
+
57
+ export { ApiResponseSchema, ErrorResponseSchema, SuccessResponseSchema };