@spfn/auth 0.2.0-beta.3 → 0.2.0-beta.31
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/README.md +689 -180
- package/dist/{dto-CLYtuAom.d.ts → authenticate-Brx2N-Ip.d.ts} +413 -147
- package/dist/config.d.ts +100 -44
- package/dist/config.js +64 -35
- package/dist/config.js.map +1 -1
- package/dist/errors.d.ts +16 -2
- package/dist/errors.js +12 -0
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +279 -100
- package/dist/index.js +47 -1
- package/dist/index.js.map +1 -1
- package/dist/nextjs/api.js +202 -1
- package/dist/nextjs/api.js.map +1 -1
- package/dist/nextjs/client.d.ts +28 -0
- package/dist/nextjs/client.js +80 -0
- package/dist/nextjs/client.js.map +1 -0
- package/dist/nextjs/server.d.ts +89 -2
- package/dist/nextjs/server.js +147 -22
- package/dist/nextjs/server.js.map +1 -1
- package/dist/server.d.ts +576 -360
- package/dist/server.js +1089 -484
- package/dist/server.js.map +1 -1
- package/migrations/0001_smooth_the_fury.sql +3 -0
- package/migrations/meta/0001_snapshot.json +1660 -0
- package/migrations/meta/_journal.json +7 -0
- package/package.json +14 -10
package/dist/errors.d.ts
CHANGED
|
@@ -132,6 +132,18 @@ declare class VerificationTokenTargetMismatchError extends ValidationError {
|
|
|
132
132
|
details?: Record<string, any>;
|
|
133
133
|
});
|
|
134
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Username Already Taken Error (409)
|
|
137
|
+
*
|
|
138
|
+
* Thrown when trying to set a username that is already in use
|
|
139
|
+
*/
|
|
140
|
+
declare class UsernameAlreadyTakenError extends ConflictError {
|
|
141
|
+
constructor(data?: {
|
|
142
|
+
username?: string;
|
|
143
|
+
message?: string;
|
|
144
|
+
details?: Record<string, any>;
|
|
145
|
+
});
|
|
146
|
+
}
|
|
135
147
|
/**
|
|
136
148
|
* Insufficient Permissions Error (403)
|
|
137
149
|
*
|
|
@@ -179,12 +191,14 @@ type authErrors_KeyExpiredError = KeyExpiredError;
|
|
|
179
191
|
declare const authErrors_KeyExpiredError: typeof KeyExpiredError;
|
|
180
192
|
type authErrors_TokenExpiredError = TokenExpiredError;
|
|
181
193
|
declare const authErrors_TokenExpiredError: typeof TokenExpiredError;
|
|
194
|
+
type authErrors_UsernameAlreadyTakenError = UsernameAlreadyTakenError;
|
|
195
|
+
declare const authErrors_UsernameAlreadyTakenError: typeof UsernameAlreadyTakenError;
|
|
182
196
|
type authErrors_VerificationTokenPurposeMismatchError = VerificationTokenPurposeMismatchError;
|
|
183
197
|
declare const authErrors_VerificationTokenPurposeMismatchError: typeof VerificationTokenPurposeMismatchError;
|
|
184
198
|
type authErrors_VerificationTokenTargetMismatchError = VerificationTokenTargetMismatchError;
|
|
185
199
|
declare const authErrors_VerificationTokenTargetMismatchError: typeof VerificationTokenTargetMismatchError;
|
|
186
200
|
declare namespace authErrors {
|
|
187
|
-
export { authErrors_AccountAlreadyExistsError as AccountAlreadyExistsError, authErrors_AccountDisabledError as AccountDisabledError, authErrors_InsufficientPermissionsError as InsufficientPermissionsError, authErrors_InsufficientRoleError as InsufficientRoleError, authErrors_InvalidCredentialsError as InvalidCredentialsError, authErrors_InvalidKeyFingerprintError as InvalidKeyFingerprintError, authErrors_InvalidTokenError as InvalidTokenError, authErrors_InvalidVerificationCodeError as InvalidVerificationCodeError, authErrors_InvalidVerificationTokenError as InvalidVerificationTokenError, authErrors_KeyExpiredError as KeyExpiredError, authErrors_TokenExpiredError as TokenExpiredError, authErrors_VerificationTokenPurposeMismatchError as VerificationTokenPurposeMismatchError, authErrors_VerificationTokenTargetMismatchError as VerificationTokenTargetMismatchError };
|
|
201
|
+
export { authErrors_AccountAlreadyExistsError as AccountAlreadyExistsError, authErrors_AccountDisabledError as AccountDisabledError, authErrors_InsufficientPermissionsError as InsufficientPermissionsError, authErrors_InsufficientRoleError as InsufficientRoleError, authErrors_InvalidCredentialsError as InvalidCredentialsError, authErrors_InvalidKeyFingerprintError as InvalidKeyFingerprintError, authErrors_InvalidTokenError as InvalidTokenError, authErrors_InvalidVerificationCodeError as InvalidVerificationCodeError, authErrors_InvalidVerificationTokenError as InvalidVerificationTokenError, authErrors_KeyExpiredError as KeyExpiredError, authErrors_TokenExpiredError as TokenExpiredError, authErrors_UsernameAlreadyTakenError as UsernameAlreadyTakenError, authErrors_VerificationTokenPurposeMismatchError as VerificationTokenPurposeMismatchError, authErrors_VerificationTokenTargetMismatchError as VerificationTokenTargetMismatchError };
|
|
188
202
|
}
|
|
189
203
|
|
|
190
204
|
/**
|
|
@@ -193,4 +207,4 @@ declare namespace authErrors {
|
|
|
193
207
|
|
|
194
208
|
declare const authErrorRegistry: ErrorRegistry;
|
|
195
209
|
|
|
196
|
-
export { AccountAlreadyExistsError, AccountDisabledError, authErrors as AuthError, InsufficientPermissionsError, InsufficientRoleError, InvalidCredentialsError, InvalidKeyFingerprintError, InvalidTokenError, InvalidVerificationCodeError, InvalidVerificationTokenError, KeyExpiredError, TokenExpiredError, VerificationTokenPurposeMismatchError, VerificationTokenTargetMismatchError, authErrorRegistry };
|
|
210
|
+
export { AccountAlreadyExistsError, AccountDisabledError, authErrors as AuthError, InsufficientPermissionsError, InsufficientRoleError, InvalidCredentialsError, InvalidKeyFingerprintError, InvalidTokenError, InvalidVerificationCodeError, InvalidVerificationTokenError, KeyExpiredError, TokenExpiredError, UsernameAlreadyTakenError, VerificationTokenPurposeMismatchError, VerificationTokenTargetMismatchError, authErrorRegistry };
|
package/dist/errors.js
CHANGED
|
@@ -21,6 +21,7 @@ __export(auth_errors_exports, {
|
|
|
21
21
|
InvalidVerificationTokenError: () => InvalidVerificationTokenError,
|
|
22
22
|
KeyExpiredError: () => KeyExpiredError,
|
|
23
23
|
TokenExpiredError: () => TokenExpiredError,
|
|
24
|
+
UsernameAlreadyTakenError: () => UsernameAlreadyTakenError,
|
|
24
25
|
VerificationTokenPurposeMismatchError: () => VerificationTokenPurposeMismatchError,
|
|
25
26
|
VerificationTokenTargetMismatchError: () => VerificationTokenTargetMismatchError
|
|
26
27
|
});
|
|
@@ -115,6 +116,15 @@ var VerificationTokenTargetMismatchError = class extends ValidationError {
|
|
|
115
116
|
this.name = "VerificationTokenTargetMismatchError";
|
|
116
117
|
}
|
|
117
118
|
};
|
|
119
|
+
var UsernameAlreadyTakenError = class extends ConflictError {
|
|
120
|
+
constructor(data = {}) {
|
|
121
|
+
super({
|
|
122
|
+
message: data.message || "Username is already taken",
|
|
123
|
+
details: { username: data.username, ...data.details }
|
|
124
|
+
});
|
|
125
|
+
this.name = "UsernameAlreadyTakenError";
|
|
126
|
+
}
|
|
127
|
+
};
|
|
118
128
|
var InsufficientPermissionsError = class extends ForbiddenError {
|
|
119
129
|
constructor(data = {}) {
|
|
120
130
|
const requiredPermissions = data.requiredPermissions || [];
|
|
@@ -145,6 +155,7 @@ authErrorRegistry.append([
|
|
|
145
155
|
KeyExpiredError,
|
|
146
156
|
AccountDisabledError,
|
|
147
157
|
AccountAlreadyExistsError,
|
|
158
|
+
UsernameAlreadyTakenError,
|
|
148
159
|
InvalidVerificationCodeError,
|
|
149
160
|
InvalidVerificationTokenError,
|
|
150
161
|
InvalidKeyFingerprintError,
|
|
@@ -166,6 +177,7 @@ export {
|
|
|
166
177
|
InvalidVerificationTokenError,
|
|
167
178
|
KeyExpiredError,
|
|
168
179
|
TokenExpiredError,
|
|
180
|
+
UsernameAlreadyTakenError,
|
|
169
181
|
VerificationTokenPurposeMismatchError,
|
|
170
182
|
VerificationTokenTargetMismatchError,
|
|
171
183
|
authErrorRegistry
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/errors/index.ts","../src/errors/auth-errors.ts"],"sourcesContent":["/**\n * Auth Error Exports\n */\n\nimport { ErrorRegistry } from \"@spfn/core/errors\";\n\nimport {\n InvalidCredentialsError,\n InvalidTokenError,\n TokenExpiredError,\n KeyExpiredError,\n AccountDisabledError,\n AccountAlreadyExistsError,\n InvalidVerificationCodeError,\n InvalidVerificationTokenError,\n InvalidKeyFingerprintError,\n VerificationTokenPurposeMismatchError,\n VerificationTokenTargetMismatchError,\n InsufficientPermissionsError,\n InsufficientRoleError,\n} from './auth-errors';\n\nexport {\n InvalidCredentialsError,\n InvalidTokenError,\n TokenExpiredError,\n KeyExpiredError,\n AccountDisabledError,\n AccountAlreadyExistsError,\n InvalidVerificationCodeError,\n InvalidVerificationTokenError,\n InvalidKeyFingerprintError,\n VerificationTokenPurposeMismatchError,\n VerificationTokenTargetMismatchError,\n InsufficientPermissionsError,\n InsufficientRoleError,\n} from './auth-errors';\n\nexport const authErrorRegistry = new ErrorRegistry();\nauthErrorRegistry.append([\n InvalidCredentialsError,\n InvalidTokenError,\n TokenExpiredError,\n KeyExpiredError,\n AccountDisabledError,\n AccountAlreadyExistsError,\n InvalidVerificationCodeError,\n InvalidVerificationTokenError,\n InvalidKeyFingerprintError,\n VerificationTokenPurposeMismatchError,\n VerificationTokenTargetMismatchError,\n InsufficientPermissionsError,\n InsufficientRoleError,\n]);\n\nexport * as AuthError from './auth-errors';","/**\n * Authentication & Authorization Error Classes\n *\n * Custom error classes for auth-specific scenarios\n */\n\nimport {\n ValidationError,\n UnauthorizedError,\n ForbiddenError,\n ConflictError\n} from '@spfn/core/errors';\n\n/**\n * Invalid Credentials Error (401)\n *\n * Thrown when login credentials are incorrect\n */\nexport class InvalidCredentialsError extends UnauthorizedError\n{\n constructor(data: { message?: string; details?: Record<string, any> } = {})\n {\n super({ message: data.message || 'Invalid credentials', details: data.details });\n this.name = 'InvalidCredentialsError';\n }\n}\n\n/**\n * Invalid Token Error (401)\n *\n * Thrown when authentication token is invalid or malformed\n */\nexport class InvalidTokenError extends UnauthorizedError\n{\n constructor(data: { message?: string; details?: Record<string, any> } = {})\n {\n super({ message: data.message || 'Invalid authentication token', details: data.details });\n this.name = 'InvalidTokenError';\n }\n}\n\n/**\n * Token Expired Error (401)\n *\n * Thrown when authentication token has expired\n */\nexport class TokenExpiredError extends UnauthorizedError\n{\n constructor(data: { message?: string; details?: Record<string, any> } = {})\n {\n super({ message: data.message || 'Authentication token has expired', details: data.details });\n this.name = 'TokenExpiredError';\n }\n}\n\n/**\n * Key Expired Error (401)\n *\n * Thrown when public key has expired\n */\nexport class KeyExpiredError extends UnauthorizedError\n{\n constructor(data: { message?: string; details?: Record<string, any> } = {})\n {\n super({ message: data.message || 'Public key has expired', details: data.details });\n this.name = 'KeyExpiredError';\n }\n}\n\n/**\n * Account Disabled Error (403)\n *\n * Thrown when user account is disabled or inactive\n */\nexport class AccountDisabledError extends ForbiddenError\n{\n constructor(data: { status?: string; message?: string; details?: Record<string, any> } = {})\n {\n const status = data.status || 'disabled';\n super({\n message: data.message || `Account is ${status}`,\n details: { status, ...data.details }\n });\n this.name = 'AccountDisabledError';\n }\n}\n\n/**\n * Account Already Exists Error (409)\n *\n * Thrown when trying to register with existing email/phone\n */\nexport class AccountAlreadyExistsError extends ConflictError\n{\n constructor(data: { identifier?: string; identifierType?: 'email' | 'phone'; message?: string; details?: Record<string, any> } = {})\n {\n super({\n message: data.message || 'Account already exists',\n details: {\n identifier: data.identifier,\n identifierType: data.identifierType,\n ...data.details\n }\n });\n this.name = 'AccountAlreadyExistsError';\n }\n}\n\n/**\n * Invalid Verification Code Error (400)\n *\n * Thrown when verification code is invalid, expired, or already used\n */\nexport class InvalidVerificationCodeError extends ValidationError\n{\n constructor(data: { message?: string; details?: Record<string, any> } = {})\n {\n super({ message: data.message || 'Invalid verification code', details: data.details });\n this.name = 'InvalidVerificationCodeError';\n }\n}\n\n/**\n * Invalid Verification Token Error (400)\n *\n * Thrown when verification token is invalid or expired\n */\nexport class InvalidVerificationTokenError extends ValidationError\n{\n constructor(data: { message?: string; details?: Record<string, any> } = {})\n {\n super({ message: data.message || 'Invalid or expired verification token', details: data.details });\n this.name = 'InvalidVerificationTokenError';\n }\n}\n\n/**\n * Invalid Key Fingerprint Error (400)\n *\n * Thrown when public key fingerprint doesn't match the public key\n */\nexport class InvalidKeyFingerprintError extends ValidationError\n{\n constructor(data: { message?: string; details?: Record<string, any> } = {})\n {\n super({ message: data.message || 'Invalid key fingerprint', details: data.details });\n this.name = 'InvalidKeyFingerprintError';\n }\n}\n\n/**\n * Verification Token Purpose Mismatch Error (400)\n *\n * Thrown when verification token purpose doesn't match expected purpose\n */\nexport class VerificationTokenPurposeMismatchError extends ValidationError\n{\n constructor(data: { expected?: string; actual?: string; message?: string; details?: Record<string, any> } = {})\n {\n const expected = data.expected || 'unknown';\n const actual = data.actual || 'unknown';\n super({\n message: data.message || `Verification token is for ${actual}, but ${expected} was expected`,\n details: { expected, actual, ...data.details }\n });\n this.name = 'VerificationTokenPurposeMismatchError';\n }\n}\n\n/**\n * Verification Token Target Mismatch Error (400)\n *\n * Thrown when verification token target doesn't match provided email/phone\n */\nexport class VerificationTokenTargetMismatchError extends ValidationError\n{\n constructor(data: { message?: string; details?: Record<string, any> } = {})\n {\n super({\n message: data.message || 'Verification token does not match provided email/phone',\n details: data.details\n });\n this.name = 'VerificationTokenTargetMismatchError';\n }\n}\n\n/**\n * Insufficient Permissions Error (403)\n *\n * Thrown when user lacks required permissions for the operation\n */\nexport class InsufficientPermissionsError extends ForbiddenError\n{\n constructor(data: { requiredPermissions?: string[]; message?: string; details?: Record<string, any> } = {})\n {\n const requiredPermissions = data.requiredPermissions || [];\n super({\n message: data.message || `Missing required permissions: ${requiredPermissions.join(', ')}`,\n details: { requiredPermissions, ...data.details }\n });\n this.name = 'InsufficientPermissionsError';\n }\n}\n\n/**\n * Insufficient Role Error (403)\n *\n * Thrown when user lacks required role for the operation\n */\nexport class InsufficientRoleError extends ForbiddenError\n{\n constructor(data: { requiredRoles?: string[]; message?: string; details?: Record<string, any> } = {})\n {\n const requiredRoles = data.requiredRoles || [];\n super({\n message: data.message || `Required roles: ${requiredRoles.join(', ')}`,\n details: { requiredRoles, ...data.details }\n });\n this.name = 'InsufficientRoleError';\n }\n}"],"mappings":";;;;;;;AAIA,SAAS,qBA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OAA4F,CAAC,GACzG;AACI,UAAM,sBAAsB,KAAK,uBAAuB,CAAC;AACzD,UAAM;AAAA,MACF,SAAS,KAAK,WAAW,iCAAiC,oBAAoB,KAAK,IAAI,CAAC;AAAA,MACxF,SAAS,EAAE,qBAAqB,GAAG,KAAK,QAAQ;AAAA,IACpD,CAAC;AACD,SAAK,OAAO;AAAA,EAChB;AACJ;AAOO,IAAM,wBAAN,cAAoC,eAC3C;AAAA,EACI,YAAY,OAAsF,CAAC,GACnG;AACI,UAAM,gBAAgB,KAAK,iBAAiB,CAAC;AAC7C,UAAM;AAAA,MACF,SAAS,KAAK,WAAW,mBAAmB,cAAc,KAAK,IAAI,CAAC;AAAA,MACpE,SAAS,EAAE,eAAe,GAAG,KAAK,QAAQ;AAAA,IAC9C,CAAC;AACD,SAAK,OAAO;AAAA,EAChB;AACJ;;;ADtLO,IAAM,oBAAoB,IAAI,cAAc;AACnD,kBAAkB,OAAO;AAAA,EACrB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACJ,CAAC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/errors/index.ts","../src/errors/auth-errors.ts"],"sourcesContent":["/**\n * Auth Error Exports\n */\n\nimport { ErrorRegistry } from \"@spfn/core/errors\";\n\nimport {\n InvalidCredentialsError,\n InvalidTokenError,\n TokenExpiredError,\n KeyExpiredError,\n AccountDisabledError,\n AccountAlreadyExistsError,\n UsernameAlreadyTakenError,\n InvalidVerificationCodeError,\n InvalidVerificationTokenError,\n InvalidKeyFingerprintError,\n VerificationTokenPurposeMismatchError,\n VerificationTokenTargetMismatchError,\n InsufficientPermissionsError,\n InsufficientRoleError,\n} from './auth-errors';\n\nexport {\n InvalidCredentialsError,\n InvalidTokenError,\n TokenExpiredError,\n KeyExpiredError,\n AccountDisabledError,\n AccountAlreadyExistsError,\n UsernameAlreadyTakenError,\n InvalidVerificationCodeError,\n InvalidVerificationTokenError,\n InvalidKeyFingerprintError,\n VerificationTokenPurposeMismatchError,\n VerificationTokenTargetMismatchError,\n InsufficientPermissionsError,\n InsufficientRoleError,\n} from './auth-errors';\n\nexport const authErrorRegistry = new ErrorRegistry();\nauthErrorRegistry.append([\n InvalidCredentialsError,\n InvalidTokenError,\n TokenExpiredError,\n KeyExpiredError,\n AccountDisabledError,\n AccountAlreadyExistsError,\n UsernameAlreadyTakenError,\n InvalidVerificationCodeError,\n InvalidVerificationTokenError,\n InvalidKeyFingerprintError,\n VerificationTokenPurposeMismatchError,\n VerificationTokenTargetMismatchError,\n InsufficientPermissionsError,\n InsufficientRoleError,\n]);\n\nexport * as AuthError from './auth-errors';","/**\n * Authentication & Authorization Error Classes\n *\n * Custom error classes for auth-specific scenarios\n */\n\nimport {\n ValidationError,\n UnauthorizedError,\n ForbiddenError,\n ConflictError\n} from '@spfn/core/errors';\n\n/**\n * Invalid Credentials Error (401)\n *\n * Thrown when login credentials are incorrect\n */\nexport class InvalidCredentialsError extends UnauthorizedError\n{\n constructor(data: { message?: string; details?: Record<string, any> } = {})\n {\n super({ message: data.message || 'Invalid credentials', details: data.details });\n this.name = 'InvalidCredentialsError';\n }\n}\n\n/**\n * Invalid Token Error (401)\n *\n * Thrown when authentication token is invalid or malformed\n */\nexport class InvalidTokenError extends UnauthorizedError\n{\n constructor(data: { message?: string; details?: Record<string, any> } = {})\n {\n super({ message: data.message || 'Invalid authentication token', details: data.details });\n this.name = 'InvalidTokenError';\n }\n}\n\n/**\n * Token Expired Error (401)\n *\n * Thrown when authentication token has expired\n */\nexport class TokenExpiredError extends UnauthorizedError\n{\n constructor(data: { message?: string; details?: Record<string, any> } = {})\n {\n super({ message: data.message || 'Authentication token has expired', details: data.details });\n this.name = 'TokenExpiredError';\n }\n}\n\n/**\n * Key Expired Error (401)\n *\n * Thrown when public key has expired\n */\nexport class KeyExpiredError extends UnauthorizedError\n{\n constructor(data: { message?: string; details?: Record<string, any> } = {})\n {\n super({ message: data.message || 'Public key has expired', details: data.details });\n this.name = 'KeyExpiredError';\n }\n}\n\n/**\n * Account Disabled Error (403)\n *\n * Thrown when user account is disabled or inactive\n */\nexport class AccountDisabledError extends ForbiddenError\n{\n constructor(data: { status?: string; message?: string; details?: Record<string, any> } = {})\n {\n const status = data.status || 'disabled';\n super({\n message: data.message || `Account is ${status}`,\n details: { status, ...data.details }\n });\n this.name = 'AccountDisabledError';\n }\n}\n\n/**\n * Account Already Exists Error (409)\n *\n * Thrown when trying to register with existing email/phone\n */\nexport class AccountAlreadyExistsError extends ConflictError\n{\n constructor(data: { identifier?: string; identifierType?: 'email' | 'phone'; message?: string; details?: Record<string, any> } = {})\n {\n super({\n message: data.message || 'Account already exists',\n details: {\n identifier: data.identifier,\n identifierType: data.identifierType,\n ...data.details\n }\n });\n this.name = 'AccountAlreadyExistsError';\n }\n}\n\n/**\n * Invalid Verification Code Error (400)\n *\n * Thrown when verification code is invalid, expired, or already used\n */\nexport class InvalidVerificationCodeError extends ValidationError\n{\n constructor(data: { message?: string; details?: Record<string, any> } = {})\n {\n super({ message: data.message || 'Invalid verification code', details: data.details });\n this.name = 'InvalidVerificationCodeError';\n }\n}\n\n/**\n * Invalid Verification Token Error (400)\n *\n * Thrown when verification token is invalid or expired\n */\nexport class InvalidVerificationTokenError extends ValidationError\n{\n constructor(data: { message?: string; details?: Record<string, any> } = {})\n {\n super({ message: data.message || 'Invalid or expired verification token', details: data.details });\n this.name = 'InvalidVerificationTokenError';\n }\n}\n\n/**\n * Invalid Key Fingerprint Error (400)\n *\n * Thrown when public key fingerprint doesn't match the public key\n */\nexport class InvalidKeyFingerprintError extends ValidationError\n{\n constructor(data: { message?: string; details?: Record<string, any> } = {})\n {\n super({ message: data.message || 'Invalid key fingerprint', details: data.details });\n this.name = 'InvalidKeyFingerprintError';\n }\n}\n\n/**\n * Verification Token Purpose Mismatch Error (400)\n *\n * Thrown when verification token purpose doesn't match expected purpose\n */\nexport class VerificationTokenPurposeMismatchError extends ValidationError\n{\n constructor(data: { expected?: string; actual?: string; message?: string; details?: Record<string, any> } = {})\n {\n const expected = data.expected || 'unknown';\n const actual = data.actual || 'unknown';\n super({\n message: data.message || `Verification token is for ${actual}, but ${expected} was expected`,\n details: { expected, actual, ...data.details }\n });\n this.name = 'VerificationTokenPurposeMismatchError';\n }\n}\n\n/**\n * Verification Token Target Mismatch Error (400)\n *\n * Thrown when verification token target doesn't match provided email/phone\n */\nexport class VerificationTokenTargetMismatchError extends ValidationError\n{\n constructor(data: { message?: string; details?: Record<string, any> } = {})\n {\n super({\n message: data.message || 'Verification token does not match provided email/phone',\n details: data.details\n });\n this.name = 'VerificationTokenTargetMismatchError';\n }\n}\n\n/**\n * Username Already Taken Error (409)\n *\n * Thrown when trying to set a username that is already in use\n */\nexport class UsernameAlreadyTakenError extends ConflictError\n{\n constructor(data: { username?: string; message?: string; details?: Record<string, any> } = {})\n {\n super({\n message: data.message || 'Username is already taken',\n details: { username: data.username, ...data.details }\n });\n this.name = 'UsernameAlreadyTakenError';\n }\n}\n\n/**\n * Insufficient Permissions Error (403)\n *\n * Thrown when user lacks required permissions for the operation\n */\nexport class InsufficientPermissionsError extends ForbiddenError\n{\n constructor(data: { requiredPermissions?: string[]; message?: string; details?: Record<string, any> } = {})\n {\n const requiredPermissions = data.requiredPermissions || [];\n super({\n message: data.message || `Missing required permissions: ${requiredPermissions.join(', ')}`,\n details: { requiredPermissions, ...data.details }\n });\n this.name = 'InsufficientPermissionsError';\n }\n}\n\n/**\n * Insufficient Role Error (403)\n *\n * Thrown when user lacks required role for the operation\n */\nexport class InsufficientRoleError extends ForbiddenError\n{\n constructor(data: { requiredRoles?: string[]; message?: string; details?: Record<string, any> } = {})\n {\n const requiredRoles = data.requiredRoles || [];\n super({\n message: data.message || `Required roles: ${requiredRoles.join(', ')}`,\n details: { requiredRoles, ...data.details }\n });\n this.name = 'InsufficientRoleError';\n }\n}"],"mappings":";;;;;;;AAIA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;AAAA,EACI,YAAY,OAA+E,CAAC,GAC5F;AACI,UAAM;AAAA,MACF,SAAS,KAAK,WAAW;AAAA,MACzB,SAAS,EAAE,UAAU,KAAK,UAAU,GAAG,KAAK,QAAQ;AAAA,IACxD,CAAC;AACD,SAAK,OAAO;AAAA,EAChB;AACJ;AAOO,IAAM,+BAAN,cAA2C,eAClD;AAAA,EACI,YAAY,OAA4F,CAAC,GACzG;AACI,UAAM,sBAAsB,KAAK,uBAAuB,CAAC;AACzD,UAAM;AAAA,MACF,SAAS,KAAK,WAAW,iCAAiC,oBAAoB,KAAK,IAAI,CAAC;AAAA,MACxF,SAAS,EAAE,qBAAqB,GAAG,KAAK,QAAQ;AAAA,IACpD,CAAC;AACD,SAAK,OAAO;AAAA,EAChB;AACJ;AAOO,IAAM,wBAAN,cAAoC,eAC3C;AAAA,EACI,YAAY,OAAsF,CAAC,GACnG;AACI,UAAM,gBAAgB,KAAK,iBAAiB,CAAC;AAC7C,UAAM;AAAA,MACF,SAAS,KAAK,WAAW,mBAAmB,cAAc,KAAK,IAAI,CAAC;AAAA,MACpE,SAAS,EAAE,eAAe,GAAG,KAAK,QAAQ;AAAA,IAC9C,CAAC;AACD,SAAK,OAAO;AAAA,EAChB;AACJ;;;ADrMO,IAAM,oBAAoB,IAAI,cAAc;AACnD,kBAAkB,OAAO;AAAA,EACrB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACJ,CAAC;","names":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,38 @@
|
|
|
1
1
|
import * as _spfn_core_nextjs from '@spfn/core/nextjs';
|
|
2
|
-
import { R as RoleConfig, P as PermissionConfig,
|
|
3
|
-
export { k as AuthInitOptions, A as AuthSession, I as INVITATION_STATUSES, n as InvitationStatus, K as KEY_ALGORITHM, l as KeyAlgorithmType, i as PERMISSION_CATEGORIES, j as PermissionCategory,
|
|
2
|
+
import { R as RoleConfig, P as PermissionConfig, C as CheckAccountExistsResult, S as SendVerificationCodeResult, a as RegisterResult, L as LoginResult, b as RotateKeyResult, O as OAuthStartResult, U as UserProfile, c as ProfileInfo, m as mainAuthRouter } from './authenticate-Brx2N-Ip.js';
|
|
3
|
+
export { k as AuthInitOptions, A as AuthSession, I as INVITATION_STATUSES, n as InvitationStatus, K as KEY_ALGORITHM, l as KeyAlgorithmType, i as PERMISSION_CATEGORIES, j as PermissionCategory, e as SOCIAL_PROVIDERS, p as SocialProvider, d as USER_STATUSES, o as UserStatus, h as VERIFICATION_PURPOSES, g as VERIFICATION_TARGET_TYPES, f as VerificationPurpose, V as VerificationTargetType } from './authenticate-Brx2N-Ip.js';
|
|
4
4
|
import * as _spfn_core_route from '@spfn/core/route';
|
|
5
|
+
import { HttpMethod } from '@spfn/core/route';
|
|
5
6
|
import * as _sinclair_typebox from '@sinclair/typebox';
|
|
6
7
|
import '@spfn/auth/server';
|
|
7
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Email regex pattern (RFC 5322 compliant)
|
|
11
|
+
* Validates: local-part@domain.tld
|
|
12
|
+
* - Local part: alphanumeric, dots, hyphens, underscores
|
|
13
|
+
* - Domain: alphanumeric, hyphens, dots
|
|
14
|
+
* - TLD: minimum 2 characters
|
|
15
|
+
*/
|
|
16
|
+
declare const EMAIL_PATTERN = "^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$";
|
|
17
|
+
/**
|
|
18
|
+
* Phone regex pattern (E.164 format)
|
|
19
|
+
* Format: +[country code][number] (1-15 digits total)
|
|
20
|
+
*/
|
|
21
|
+
declare const PHONE_PATTERN = "^\\+[1-9]\\d{1,14}$";
|
|
22
|
+
/**
|
|
23
|
+
* SHA-256 fingerprint pattern (64 hex characters)
|
|
24
|
+
*/
|
|
25
|
+
declare const FINGERPRINT_PATTERN = "^[a-f0-9]{64}$";
|
|
26
|
+
/**
|
|
27
|
+
* UUID v4 pattern (8-4-4-4-12 format)
|
|
28
|
+
*/
|
|
29
|
+
declare const UUID_PATTERN = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$";
|
|
30
|
+
/**
|
|
31
|
+
* Base64 pattern (DER encoded keys)
|
|
32
|
+
* Matches standard Base64 with padding
|
|
33
|
+
*/
|
|
34
|
+
declare const BASE64_PATTERN = "^[A-Za-z0-9+/]+=*$";
|
|
35
|
+
|
|
8
36
|
/**
|
|
9
37
|
* @spfn/auth - Built-in Roles and Permissions
|
|
10
38
|
*
|
|
@@ -31,31 +59,16 @@ type BuiltinRoleName = keyof typeof BUILTIN_ROLE_PERMISSIONS;
|
|
|
31
59
|
type BuiltinPermissionName = typeof BUILTIN_PERMISSIONS[keyof typeof BUILTIN_PERMISSIONS]['name'];
|
|
32
60
|
|
|
33
61
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* -
|
|
37
|
-
* - Domain: alphanumeric, hyphens, dots
|
|
38
|
-
* - TLD: minimum 2 characters
|
|
39
|
-
*/
|
|
40
|
-
declare const EMAIL_PATTERN = "^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$";
|
|
41
|
-
/**
|
|
42
|
-
* Phone regex pattern (E.164 format)
|
|
43
|
-
* Format: +[country code][number] (1-15 digits total)
|
|
44
|
-
*/
|
|
45
|
-
declare const PHONE_PATTERN = "^\\+[1-9]\\d{1,14}$";
|
|
46
|
-
/**
|
|
47
|
-
* SHA-256 fingerprint pattern (64 hex characters)
|
|
48
|
-
*/
|
|
49
|
-
declare const FINGERPRINT_PATTERN = "^[a-f0-9]{64}$";
|
|
50
|
-
/**
|
|
51
|
-
* UUID v4 pattern (8-4-4-4-12 format)
|
|
52
|
-
*/
|
|
53
|
-
declare const UUID_PATTERN = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$";
|
|
54
|
-
/**
|
|
55
|
-
* Base64 pattern (DER encoded keys)
|
|
56
|
-
* Matches standard Base64 with padding
|
|
62
|
+
* Route Map (Auto-generated)
|
|
63
|
+
*
|
|
64
|
+
* DO NOT EDIT - This file is generated by @spfn/core:route-map generator
|
|
57
65
|
*/
|
|
58
|
-
|
|
66
|
+
|
|
67
|
+
interface RouteInfo {
|
|
68
|
+
method: HttpMethod;
|
|
69
|
+
path: string;
|
|
70
|
+
}
|
|
71
|
+
declare const routeMap: Record<string, RouteInfo>;
|
|
59
72
|
|
|
60
73
|
/**
|
|
61
74
|
* Type-safe API client for auth routes
|
|
@@ -74,7 +87,140 @@ declare const BASE64_PATTERN = "^[A-Za-z0-9+/]+=*$";
|
|
|
74
87
|
* ```
|
|
75
88
|
*/
|
|
76
89
|
declare const authApi: _spfn_core_nextjs.Client<_spfn_core_route.Router<{
|
|
77
|
-
|
|
90
|
+
checkAccountExists: _spfn_core_route.RouteDef<{
|
|
91
|
+
body: _sinclair_typebox.TUnion<[_sinclair_typebox.TObject<{
|
|
92
|
+
email: _sinclair_typebox.TString;
|
|
93
|
+
}>, _sinclair_typebox.TObject<{
|
|
94
|
+
phone: _sinclair_typebox.TString;
|
|
95
|
+
}>]>;
|
|
96
|
+
}, {}, CheckAccountExistsResult>;
|
|
97
|
+
sendVerificationCode: _spfn_core_route.RouteDef<{
|
|
98
|
+
body: _sinclair_typebox.TObject<{
|
|
99
|
+
target: _sinclair_typebox.TString;
|
|
100
|
+
targetType: _sinclair_typebox.TUnion<[_sinclair_typebox.TLiteral<"email">, _sinclair_typebox.TLiteral<"phone">]>;
|
|
101
|
+
purpose: _sinclair_typebox.TUnion<[_sinclair_typebox.TLiteral<"registration">, _sinclair_typebox.TLiteral<"login">, _sinclair_typebox.TLiteral<"password_reset">, _sinclair_typebox.TLiteral<"email_change">, _sinclair_typebox.TLiteral<"phone_change">]>;
|
|
102
|
+
}>;
|
|
103
|
+
}, {}, SendVerificationCodeResult>;
|
|
104
|
+
verifyCode: _spfn_core_route.RouteDef<{
|
|
105
|
+
body: _sinclair_typebox.TObject<{
|
|
106
|
+
target: _sinclair_typebox.TString;
|
|
107
|
+
targetType: _sinclair_typebox.TUnion<[_sinclair_typebox.TLiteral<"email">, _sinclair_typebox.TLiteral<"phone">]>;
|
|
108
|
+
code: _sinclair_typebox.TString;
|
|
109
|
+
purpose: _sinclair_typebox.TUnion<[_sinclair_typebox.TLiteral<"registration">, _sinclair_typebox.TLiteral<"login">, _sinclair_typebox.TLiteral<"password_reset">, _sinclair_typebox.TLiteral<"email_change">, _sinclair_typebox.TLiteral<"phone_change">]>;
|
|
110
|
+
}>;
|
|
111
|
+
}, {}, {
|
|
112
|
+
valid: boolean;
|
|
113
|
+
verificationToken: string;
|
|
114
|
+
}>;
|
|
115
|
+
register: _spfn_core_route.RouteDef<{
|
|
116
|
+
body: _sinclair_typebox.TObject<{
|
|
117
|
+
email: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
|
|
118
|
+
phone: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
|
|
119
|
+
verificationToken: _sinclair_typebox.TString;
|
|
120
|
+
password: _sinclair_typebox.TString;
|
|
121
|
+
}>;
|
|
122
|
+
}, {
|
|
123
|
+
body: _sinclair_typebox.TObject<{
|
|
124
|
+
publicKey: _sinclair_typebox.TString;
|
|
125
|
+
keyId: _sinclair_typebox.TString;
|
|
126
|
+
fingerprint: _sinclair_typebox.TString;
|
|
127
|
+
algorithm: _sinclair_typebox.TUnion<_sinclair_typebox.TLiteral<"ES256" | "RS256">[]>;
|
|
128
|
+
}>;
|
|
129
|
+
}, RegisterResult>;
|
|
130
|
+
login: _spfn_core_route.RouteDef<{
|
|
131
|
+
body: _sinclair_typebox.TObject<{
|
|
132
|
+
email: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
|
|
133
|
+
phone: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
|
|
134
|
+
password: _sinclair_typebox.TString;
|
|
135
|
+
}>;
|
|
136
|
+
}, {
|
|
137
|
+
body: _sinclair_typebox.TObject<{
|
|
138
|
+
publicKey: _sinclair_typebox.TString;
|
|
139
|
+
keyId: _sinclair_typebox.TString;
|
|
140
|
+
fingerprint: _sinclair_typebox.TString;
|
|
141
|
+
algorithm: _sinclair_typebox.TUnion<_sinclair_typebox.TLiteral<"ES256" | "RS256">[]>;
|
|
142
|
+
oldKeyId: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
|
|
143
|
+
}>;
|
|
144
|
+
}, LoginResult>;
|
|
145
|
+
logout: _spfn_core_route.RouteDef<{}, {}, void>;
|
|
146
|
+
rotateKey: _spfn_core_route.RouteDef<{}, {
|
|
147
|
+
body: _sinclair_typebox.TObject<{
|
|
148
|
+
publicKey: _sinclair_typebox.TString;
|
|
149
|
+
keyId: _sinclair_typebox.TString;
|
|
150
|
+
fingerprint: _sinclair_typebox.TString;
|
|
151
|
+
algorithm: _sinclair_typebox.TUnion<_sinclair_typebox.TLiteral<"ES256" | "RS256">[]>;
|
|
152
|
+
}>;
|
|
153
|
+
}, RotateKeyResult>;
|
|
154
|
+
changePassword: _spfn_core_route.RouteDef<{
|
|
155
|
+
body: _sinclair_typebox.TObject<{
|
|
156
|
+
currentPassword: _sinclair_typebox.TString;
|
|
157
|
+
newPassword: _sinclair_typebox.TString;
|
|
158
|
+
}>;
|
|
159
|
+
}, {}, void>;
|
|
160
|
+
getAuthSession: _spfn_core_route.RouteDef<{}, {}, {
|
|
161
|
+
role: {
|
|
162
|
+
id: number;
|
|
163
|
+
name: string;
|
|
164
|
+
displayName: string;
|
|
165
|
+
priority: number;
|
|
166
|
+
};
|
|
167
|
+
permissions: {
|
|
168
|
+
id: number;
|
|
169
|
+
name: string;
|
|
170
|
+
displayName: string;
|
|
171
|
+
category: "auth" | "custom" | "user" | "rbac" | "system" | undefined;
|
|
172
|
+
}[];
|
|
173
|
+
userId: number;
|
|
174
|
+
email: string | null;
|
|
175
|
+
emailVerified: boolean;
|
|
176
|
+
phoneVerified: boolean;
|
|
177
|
+
}>;
|
|
178
|
+
oauthGoogleStart: _spfn_core_route.RouteDef<{
|
|
179
|
+
query: _sinclair_typebox.TObject<{
|
|
180
|
+
state: _sinclair_typebox.TString;
|
|
181
|
+
}>;
|
|
182
|
+
}, {}, Response>;
|
|
183
|
+
oauthGoogleCallback: _spfn_core_route.RouteDef<{
|
|
184
|
+
query: _sinclair_typebox.TObject<{
|
|
185
|
+
code: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
|
|
186
|
+
state: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
|
|
187
|
+
error: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
|
|
188
|
+
error_description: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
|
|
189
|
+
}>;
|
|
190
|
+
}, {}, Response>;
|
|
191
|
+
oauthStart: _spfn_core_route.RouteDef<{
|
|
192
|
+
body: _sinclair_typebox.TObject<{
|
|
193
|
+
provider: _sinclair_typebox.TUnion<_sinclair_typebox.TLiteral<"google" | "github" | "kakao" | "naver">[]>;
|
|
194
|
+
returnUrl: _sinclair_typebox.TString;
|
|
195
|
+
publicKey: _sinclair_typebox.TString;
|
|
196
|
+
keyId: _sinclair_typebox.TString;
|
|
197
|
+
fingerprint: _sinclair_typebox.TString;
|
|
198
|
+
algorithm: _sinclair_typebox.TUnion<_sinclair_typebox.TLiteral<"ES256" | "RS256">[]>;
|
|
199
|
+
}>;
|
|
200
|
+
}, {}, OAuthStartResult>;
|
|
201
|
+
oauthProviders: _spfn_core_route.RouteDef<{}, {}, {
|
|
202
|
+
providers: ("google" | "github" | "kakao" | "naver")[];
|
|
203
|
+
}>;
|
|
204
|
+
getGoogleOAuthUrl: _spfn_core_route.RouteDef<{
|
|
205
|
+
body: _sinclair_typebox.TObject<{
|
|
206
|
+
returnUrl: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
|
|
207
|
+
state: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
|
|
208
|
+
}>;
|
|
209
|
+
}, {}, {
|
|
210
|
+
authUrl: string;
|
|
211
|
+
}>;
|
|
212
|
+
oauthFinalize: _spfn_core_route.RouteDef<{
|
|
213
|
+
body: _sinclair_typebox.TObject<{
|
|
214
|
+
userId: _sinclair_typebox.TString;
|
|
215
|
+
keyId: _sinclair_typebox.TString;
|
|
216
|
+
returnUrl: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
|
|
217
|
+
}>;
|
|
218
|
+
}, {}, {
|
|
219
|
+
success: boolean;
|
|
220
|
+
userId: string;
|
|
221
|
+
keyId: string;
|
|
222
|
+
returnUrl: string;
|
|
223
|
+
}>;
|
|
78
224
|
getInvitation: _spfn_core_route.RouteDef<{
|
|
79
225
|
params: _sinclair_typebox.TObject<{
|
|
80
226
|
token: _sinclair_typebox.TString;
|
|
@@ -174,100 +320,133 @@ declare const authApi: _spfn_core_nextjs.Client<_spfn_core_route.Router<{
|
|
|
174
320
|
body: _sinclair_typebox.TObject<{
|
|
175
321
|
id: _sinclair_typebox.TNumber;
|
|
176
322
|
}>;
|
|
177
|
-
}, {},
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
email: _sinclair_typebox.TString;
|
|
181
|
-
}>, _sinclair_typebox.TObject<{
|
|
182
|
-
phone: _sinclair_typebox.TString;
|
|
183
|
-
}>]>;
|
|
184
|
-
}, {}, CheckAccountExistsResult>;
|
|
185
|
-
sendVerificationCode: _spfn_core_route.RouteDef<{
|
|
323
|
+
}, {}, void>;
|
|
324
|
+
getUserProfile: _spfn_core_route.RouteDef<{}, {}, UserProfile>;
|
|
325
|
+
updateUserProfile: _spfn_core_route.RouteDef<{
|
|
186
326
|
body: _sinclair_typebox.TObject<{
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
327
|
+
displayName: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
|
|
328
|
+
firstName: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
|
|
329
|
+
lastName: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
|
|
330
|
+
avatarUrl: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
|
|
331
|
+
bio: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
|
|
332
|
+
locale: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
|
|
333
|
+
timezone: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
|
|
334
|
+
dateOfBirth: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
|
|
335
|
+
gender: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
|
|
336
|
+
website: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
|
|
337
|
+
location: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
|
|
338
|
+
company: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
|
|
339
|
+
jobTitle: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
|
|
340
|
+
metadata: _sinclair_typebox.TOptional<_sinclair_typebox.TRecord<_sinclair_typebox.TString, _sinclair_typebox.TAny>>;
|
|
190
341
|
}>;
|
|
191
|
-
}, {},
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
targetType: _sinclair_typebox.TUnion<[_sinclair_typebox.TLiteral<"email">, _sinclair_typebox.TLiteral<"phone">]>;
|
|
196
|
-
code: _sinclair_typebox.TString;
|
|
197
|
-
purpose: _sinclair_typebox.TUnion<[_sinclair_typebox.TLiteral<"registration">, _sinclair_typebox.TLiteral<"login">, _sinclair_typebox.TLiteral<"password_reset">, _sinclair_typebox.TLiteral<"email_change">, _sinclair_typebox.TLiteral<"phone_change">]>;
|
|
342
|
+
}, {}, ProfileInfo>;
|
|
343
|
+
checkUsername: _spfn_core_route.RouteDef<{
|
|
344
|
+
query: _sinclair_typebox.TObject<{
|
|
345
|
+
username: _sinclair_typebox.TString;
|
|
198
346
|
}>;
|
|
199
347
|
}, {}, {
|
|
200
|
-
|
|
201
|
-
verificationToken: string;
|
|
348
|
+
available: boolean;
|
|
202
349
|
}>;
|
|
203
|
-
|
|
204
|
-
body: _sinclair_typebox.TObject<{
|
|
205
|
-
email: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
|
|
206
|
-
phone: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
|
|
207
|
-
verificationToken: _sinclair_typebox.TString;
|
|
208
|
-
password: _sinclair_typebox.TString;
|
|
209
|
-
}>;
|
|
210
|
-
}, {
|
|
211
|
-
body: _sinclair_typebox.TObject<{
|
|
212
|
-
publicKey: _sinclair_typebox.TString;
|
|
213
|
-
keyId: _sinclair_typebox.TString;
|
|
214
|
-
fingerprint: _sinclair_typebox.TString;
|
|
215
|
-
algorithm: _sinclair_typebox.TUnion<_sinclair_typebox.TLiteral<"ES256" | "RS256">[]>;
|
|
216
|
-
}>;
|
|
217
|
-
}, RegisterResult>;
|
|
218
|
-
login: _spfn_core_route.RouteDef<{
|
|
219
|
-
body: _sinclair_typebox.TObject<{
|
|
220
|
-
email: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
|
|
221
|
-
phone: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
|
|
222
|
-
password: _sinclair_typebox.TString;
|
|
223
|
-
}>;
|
|
224
|
-
}, {
|
|
350
|
+
updateUsername: _spfn_core_route.RouteDef<{
|
|
225
351
|
body: _sinclair_typebox.TObject<{
|
|
226
|
-
|
|
227
|
-
keyId: _sinclair_typebox.TString;
|
|
228
|
-
fingerprint: _sinclair_typebox.TString;
|
|
229
|
-
algorithm: _sinclair_typebox.TUnion<_sinclair_typebox.TLiteral<"ES256" | "RS256">[]>;
|
|
230
|
-
oldKeyId: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
|
|
352
|
+
username: _sinclair_typebox.TUnion<[_sinclair_typebox.TString, _sinclair_typebox.TNull]>;
|
|
231
353
|
}>;
|
|
232
|
-
},
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
354
|
+
}, {}, {
|
|
355
|
+
createdAt: Date;
|
|
356
|
+
updatedAt: Date;
|
|
357
|
+
id: number;
|
|
358
|
+
email: string | null;
|
|
359
|
+
phone: string | null;
|
|
360
|
+
username: string | null;
|
|
361
|
+
passwordHash: string | null;
|
|
362
|
+
passwordChangeRequired: boolean;
|
|
363
|
+
roleId: number;
|
|
364
|
+
status: "active" | "inactive" | "suspended";
|
|
365
|
+
emailVerifiedAt: Date | null;
|
|
366
|
+
phoneVerifiedAt: Date | null;
|
|
367
|
+
lastLoginAt: Date | null;
|
|
368
|
+
}>;
|
|
369
|
+
listRoles: _spfn_core_route.RouteDef<{
|
|
370
|
+
query: _sinclair_typebox.TObject<{
|
|
371
|
+
includeInactive: _sinclair_typebox.TOptional<_sinclair_typebox.TBoolean>;
|
|
244
372
|
}>;
|
|
245
|
-
},
|
|
246
|
-
|
|
373
|
+
}, {}, {
|
|
374
|
+
roles: {
|
|
375
|
+
description: string | null;
|
|
376
|
+
id: number;
|
|
377
|
+
name: string;
|
|
378
|
+
displayName: string;
|
|
379
|
+
isBuiltin: boolean;
|
|
380
|
+
isSystem: boolean;
|
|
381
|
+
isActive: boolean;
|
|
382
|
+
priority: number;
|
|
383
|
+
createdAt: Date;
|
|
384
|
+
updatedAt: Date;
|
|
385
|
+
}[];
|
|
386
|
+
}>;
|
|
387
|
+
createAdminRole: _spfn_core_route.RouteDef<{
|
|
247
388
|
body: _sinclair_typebox.TObject<{
|
|
248
|
-
|
|
249
|
-
|
|
389
|
+
name: _sinclair_typebox.TString;
|
|
390
|
+
displayName: _sinclair_typebox.TString;
|
|
391
|
+
description: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
|
|
392
|
+
priority: _sinclair_typebox.TOptional<_sinclair_typebox.TNumber>;
|
|
393
|
+
permissionIds: _sinclair_typebox.TOptional<_sinclair_typebox.TArray<_sinclair_typebox.TNumber>>;
|
|
250
394
|
}>;
|
|
251
|
-
}, {},
|
|
252
|
-
getAuthSession: _spfn_core_route.RouteDef<{}, {}, {
|
|
395
|
+
}, {}, {
|
|
253
396
|
role: {
|
|
397
|
+
description: string | null;
|
|
254
398
|
id: number;
|
|
255
399
|
name: string;
|
|
256
400
|
displayName: string;
|
|
401
|
+
isBuiltin: boolean;
|
|
402
|
+
isSystem: boolean;
|
|
403
|
+
isActive: boolean;
|
|
257
404
|
priority: number;
|
|
405
|
+
createdAt: Date;
|
|
406
|
+
updatedAt: Date;
|
|
258
407
|
};
|
|
259
|
-
|
|
408
|
+
}>;
|
|
409
|
+
updateAdminRole: _spfn_core_route.RouteDef<{
|
|
410
|
+
params: _sinclair_typebox.TObject<{
|
|
411
|
+
id: _sinclair_typebox.TNumber;
|
|
412
|
+
}>;
|
|
413
|
+
body: _sinclair_typebox.TObject<{
|
|
414
|
+
displayName: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
|
|
415
|
+
description: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
|
|
416
|
+
priority: _sinclair_typebox.TOptional<_sinclair_typebox.TNumber>;
|
|
417
|
+
isActive: _sinclair_typebox.TOptional<_sinclair_typebox.TBoolean>;
|
|
418
|
+
}>;
|
|
419
|
+
}, {}, {
|
|
420
|
+
role: {
|
|
421
|
+
description: string | null;
|
|
260
422
|
id: number;
|
|
261
423
|
name: string;
|
|
262
424
|
displayName: string;
|
|
263
|
-
|
|
264
|
-
|
|
425
|
+
isBuiltin: boolean;
|
|
426
|
+
isSystem: boolean;
|
|
427
|
+
isActive: boolean;
|
|
428
|
+
priority: number;
|
|
429
|
+
createdAt: Date;
|
|
430
|
+
updatedAt: Date;
|
|
431
|
+
};
|
|
432
|
+
}>;
|
|
433
|
+
deleteAdminRole: _spfn_core_route.RouteDef<{
|
|
434
|
+
params: _sinclair_typebox.TObject<{
|
|
435
|
+
id: _sinclair_typebox.TNumber;
|
|
436
|
+
}>;
|
|
437
|
+
}, {}, void>;
|
|
438
|
+
updateUserRole: _spfn_core_route.RouteDef<{
|
|
439
|
+
params: _sinclair_typebox.TObject<{
|
|
440
|
+
userId: _sinclair_typebox.TNumber;
|
|
441
|
+
}>;
|
|
442
|
+
body: _sinclair_typebox.TObject<{
|
|
443
|
+
roleId: _sinclair_typebox.TNumber;
|
|
444
|
+
}>;
|
|
445
|
+
}, {}, {
|
|
265
446
|
userId: number;
|
|
266
|
-
|
|
267
|
-
emailVerified: boolean;
|
|
268
|
-
phoneVerified: boolean;
|
|
447
|
+
roleId: number;
|
|
269
448
|
}>;
|
|
270
449
|
}>>;
|
|
271
450
|
type AuthRouter = typeof mainAuthRouter;
|
|
272
451
|
|
|
273
|
-
export { type AuthRouter, BASE64_PATTERN, BUILTIN_PERMISSIONS, BUILTIN_ROLES, BUILTIN_ROLE_PERMISSIONS, type BuiltinPermissionName, type BuiltinRoleName, EMAIL_PATTERN, FINGERPRINT_PATTERN, PHONE_PATTERN, PermissionConfig, RoleConfig, UUID_PATTERN, UserProfile, authApi };
|
|
452
|
+
export { type AuthRouter, BASE64_PATTERN, BUILTIN_PERMISSIONS, BUILTIN_ROLES, BUILTIN_ROLE_PERMISSIONS, type BuiltinPermissionName, type BuiltinRoleName, EMAIL_PATTERN, FINGERPRINT_PATTERN, PHONE_PATTERN, PermissionConfig, ProfileInfo, RoleConfig, UUID_PATTERN, UserProfile, authApi, routeMap as authRouteMap };
|
package/dist/index.js
CHANGED
|
@@ -102,6 +102,15 @@ var VerificationTokenTargetMismatchError = class extends ValidationError {
|
|
|
102
102
|
this.name = "VerificationTokenTargetMismatchError";
|
|
103
103
|
}
|
|
104
104
|
};
|
|
105
|
+
var UsernameAlreadyTakenError = class extends ConflictError {
|
|
106
|
+
constructor(data = {}) {
|
|
107
|
+
super({
|
|
108
|
+
message: data.message || "Username is already taken",
|
|
109
|
+
details: { username: data.username, ...data.details }
|
|
110
|
+
});
|
|
111
|
+
this.name = "UsernameAlreadyTakenError";
|
|
112
|
+
}
|
|
113
|
+
};
|
|
105
114
|
var InsufficientPermissionsError = class extends ForbiddenError {
|
|
106
115
|
constructor(data = {}) {
|
|
107
116
|
const requiredPermissions = data.requiredPermissions || [];
|
|
@@ -132,6 +141,7 @@ authErrorRegistry.append([
|
|
|
132
141
|
KeyExpiredError,
|
|
133
142
|
AccountDisabledError,
|
|
134
143
|
AccountAlreadyExistsError,
|
|
144
|
+
UsernameAlreadyTakenError,
|
|
135
145
|
InvalidVerificationCodeError,
|
|
136
146
|
InvalidVerificationTokenError,
|
|
137
147
|
InvalidKeyFingerprintError,
|
|
@@ -141,6 +151,41 @@ authErrorRegistry.append([
|
|
|
141
151
|
InsufficientRoleError
|
|
142
152
|
]);
|
|
143
153
|
|
|
154
|
+
// src/generated/route-map.ts
|
|
155
|
+
var routeMap = {
|
|
156
|
+
checkAccountExists: { method: "POST", path: "/_auth/exists" },
|
|
157
|
+
sendVerificationCode: { method: "POST", path: "/_auth/codes" },
|
|
158
|
+
verifyCode: { method: "POST", path: "/_auth/codes/verify" },
|
|
159
|
+
register: { method: "POST", path: "/_auth/register" },
|
|
160
|
+
login: { method: "POST", path: "/_auth/login" },
|
|
161
|
+
logout: { method: "POST", path: "/_auth/logout" },
|
|
162
|
+
rotateKey: { method: "POST", path: "/_auth/keys/rotate" },
|
|
163
|
+
changePassword: { method: "PUT", path: "/_auth/password" },
|
|
164
|
+
getAuthSession: { method: "GET", path: "/_auth/session" },
|
|
165
|
+
getInvitation: { method: "GET", path: "/_auth/invitations/:token" },
|
|
166
|
+
acceptInvitation: { method: "POST", path: "/_auth/invitations/accept" },
|
|
167
|
+
createInvitation: { method: "POST", path: "/_auth/invitations" },
|
|
168
|
+
listInvitations: { method: "GET", path: "/_auth/invitations" },
|
|
169
|
+
cancelInvitation: { method: "POST", path: "/_auth/invitations/cancel" },
|
|
170
|
+
resendInvitation: { method: "POST", path: "/_auth/invitations/resend" },
|
|
171
|
+
deleteInvitation: { method: "POST", path: "/_auth/invitations/delete" },
|
|
172
|
+
getUserProfile: { method: "GET", path: "/_auth/users/profile" },
|
|
173
|
+
updateUserProfile: { method: "PATCH", path: "/_auth/users/profile" },
|
|
174
|
+
checkUsername: { method: "GET", path: "/_auth/users/username/check" },
|
|
175
|
+
updateUsername: { method: "PATCH", path: "/_auth/users/username" },
|
|
176
|
+
oauthGoogleStart: { method: "GET", path: "/_auth/oauth/google" },
|
|
177
|
+
oauthGoogleCallback: { method: "GET", path: "/_auth/oauth/google/callback" },
|
|
178
|
+
oauthStart: { method: "POST", path: "/_auth/oauth/start" },
|
|
179
|
+
oauthProviders: { method: "GET", path: "/_auth/oauth/providers" },
|
|
180
|
+
getGoogleOAuthUrl: { method: "POST", path: "/_auth/oauth/google/url" },
|
|
181
|
+
oauthFinalize: { method: "POST", path: "/_auth/oauth/finalize" },
|
|
182
|
+
listRoles: { method: "GET", path: "/_auth/admin/roles" },
|
|
183
|
+
createAdminRole: { method: "POST", path: "/_auth/admin/roles" },
|
|
184
|
+
updateAdminRole: { method: "PATCH", path: "/_auth/admin/roles/:id" },
|
|
185
|
+
deleteAdminRole: { method: "DELETE", path: "/_auth/admin/roles/:id" },
|
|
186
|
+
updateUserRole: { method: "PATCH", path: "/_auth/admin/users/:userId/role" }
|
|
187
|
+
};
|
|
188
|
+
|
|
144
189
|
// src/lib/types.ts
|
|
145
190
|
var EMAIL_PATTERN = "^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$";
|
|
146
191
|
var PHONE_PATTERN = "^\\+[1-9]\\d{1,14}$";
|
|
@@ -2941,6 +2986,7 @@ export {
|
|
|
2941
2986
|
UUID_PATTERN,
|
|
2942
2987
|
VERIFICATION_PURPOSES,
|
|
2943
2988
|
VERIFICATION_TARGET_TYPES,
|
|
2944
|
-
authApi
|
|
2989
|
+
authApi,
|
|
2990
|
+
routeMap as authRouteMap
|
|
2945
2991
|
};
|
|
2946
2992
|
//# sourceMappingURL=index.js.map
|