@bernouy/socle 0.0.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.
- package/LICENSE +21 -0
- package/README.md +1 -0
- package/dist/app.d.ts +1 -0
- package/dist/default/AuthenticationProvider/Authentication.d.ts +69 -0
- package/dist/default/AuthenticationProvider/api/adminAccounts.d.ts +5 -0
- package/dist/default/AuthenticationProvider/api/changePasswordSubmit.d.ts +2 -0
- package/dist/default/AuthenticationProvider/api/loginSubmit.d.ts +2 -0
- package/dist/default/AuthenticationProvider/api/logoutHandler.d.ts +2 -0
- package/dist/default/AuthenticationProvider/api/recoverSubmit.d.ts +2 -0
- package/dist/default/AuthenticationProvider/api/registerSubmit.d.ts +2 -0
- package/dist/default/AuthenticationProvider/api/resetSubmit.d.ts +2 -0
- package/dist/default/AuthenticationProvider/api/setupSubmit.d.ts +6 -0
- package/dist/default/AuthenticationProvider/interfaces/default-provider/AuthRepositoryProvider.d.ts +26 -0
- package/dist/default/AuthenticationProvider/interfaces/repository/AuthRepository.d.ts +23 -0
- package/dist/default/AuthenticationProvider/utilities/send_html.d.ts +1 -0
- package/dist/default/MailerProvider/ConsoleMailerProvider.d.ts +12 -0
- package/dist/default/MailerProvider/SmtpMailerProvider.d.ts +24 -0
- package/dist/default/RunnerProvider.d.ts +15 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +43481 -0
- package/dist/interfaces/AuthInterface.d.ts +49 -0
- package/dist/interfaces/MailerInterface.d.ts +21 -0
- package/dist/interfaces/RunnerInterface.d.ts +40 -0
- package/package.json +34 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { Middleware } from "./RunnerInterface";
|
|
2
|
+
export interface IBe5_Subject {
|
|
3
|
+
identifier: string;
|
|
4
|
+
role: 'admin' | 'user';
|
|
5
|
+
}
|
|
6
|
+
/** A richer account view returned by listAccounts (admin UI). */
|
|
7
|
+
export interface IBe5_AccountSummary extends IBe5_Subject {
|
|
8
|
+
createdAt?: Date;
|
|
9
|
+
}
|
|
10
|
+
export interface IBe5_Authentication {
|
|
11
|
+
readonly loginPage: string;
|
|
12
|
+
readonly registerPage: string;
|
|
13
|
+
readonly recoverPage: string;
|
|
14
|
+
readonly resetPage: string;
|
|
15
|
+
readonly logoutPage: string;
|
|
16
|
+
readonly setupPage: string;
|
|
17
|
+
readonly adminAccountsPage: string;
|
|
18
|
+
/** True when the Authentication was constructed with an IBe5_Mailer. */
|
|
19
|
+
readonly mailEnabled: boolean;
|
|
20
|
+
withRedirect(page: string, path: string): string;
|
|
21
|
+
getSubject(req: Request): Promise<IBe5_Subject | null>;
|
|
22
|
+
isAuthenticated(req: Request): Promise<boolean>;
|
|
23
|
+
guardAuthenticated(req: Request): Promise<IBe5_Subject>;
|
|
24
|
+
guardAdmin(req: Request): Promise<IBe5_Subject>;
|
|
25
|
+
/** Middleware that 401s unauthenticated requests. */
|
|
26
|
+
readonly requireAuthenticated: Middleware;
|
|
27
|
+
/** Middleware that 401s unauthenticated and 403s non-admins. */
|
|
28
|
+
readonly requireAdmin: Middleware;
|
|
29
|
+
/** Clears the session cookie. Always safe to call. */
|
|
30
|
+
logout(): Response;
|
|
31
|
+
/**
|
|
32
|
+
* Generates a password reset token and emails it to the user.
|
|
33
|
+
* No-op (throws) if the Authentication has no mailer configured.
|
|
34
|
+
* Never reveals whether the email exists.
|
|
35
|
+
*/
|
|
36
|
+
requestPasswordReset(email: string): Promise<void>;
|
|
37
|
+
/** Consumes a reset token and applies a new password. */
|
|
38
|
+
resetPassword(token: string, newPassword: string): Promise<void>;
|
|
39
|
+
/** Updates the password of the currently-authenticated subject. */
|
|
40
|
+
changePassword(req: Request, currentPassword: string, newPassword: string): Promise<void>;
|
|
41
|
+
/** Admin-only: list every registered account. */
|
|
42
|
+
listAccounts(): Promise<IBe5_AccountSummary[]>;
|
|
43
|
+
/** Admin-only: create a new account with an explicit role. */
|
|
44
|
+
createAccount(identifier: string, password: string, role: 'admin' | 'user'): Promise<IBe5_Subject>;
|
|
45
|
+
/** Admin-only: delete an account by identifier (email). */
|
|
46
|
+
deleteAccount(identifier: string): Promise<void>;
|
|
47
|
+
/** Admin-only: change the role of an account. */
|
|
48
|
+
setAccountRole(identifier: string, role: 'admin' | 'user'): Promise<void>;
|
|
49
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A single outbound email message.
|
|
3
|
+
*/
|
|
4
|
+
export type Be5_MailMessage = {
|
|
5
|
+
to: string;
|
|
6
|
+
subject: string;
|
|
7
|
+
html: string;
|
|
8
|
+
text?: string;
|
|
9
|
+
/** Overrides the provider's default "from" address. */
|
|
10
|
+
from?: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Contract for sending transactional email on behalf of the Be5 platform.
|
|
14
|
+
*
|
|
15
|
+
* The Authentication provider consumes this optionally: features that need
|
|
16
|
+
* to email the user (password reset, etc.) are disabled when no mailer is
|
|
17
|
+
* supplied.
|
|
18
|
+
*/
|
|
19
|
+
export interface IBe5_Mailer {
|
|
20
|
+
send(message: Be5_MailMessage): Promise<void>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** * Represents the handler function for an endpoint.
|
|
2
|
+
* It can return a standard Response or a Promise of a Response.
|
|
3
|
+
*/
|
|
4
|
+
export type RouteHandler = (req: Request) => Response | Promise<Response>;
|
|
5
|
+
/**
|
|
6
|
+
* Middleware function that can transform a request or intercept a response.
|
|
7
|
+
*/
|
|
8
|
+
export type Middleware = (req: Request, next: () => Promise<Response>) => Promise<Response>;
|
|
9
|
+
export interface IBe5_Runner {
|
|
10
|
+
/** * Registers a new HTTP endpoint.
|
|
11
|
+
* @param method HTTP verb (GET, POST, PUT, DELETE, etc.)
|
|
12
|
+
* @param path The URL path (can include dynamic segments like /article/:id)
|
|
13
|
+
* @param handler The function to execute when the route is matched
|
|
14
|
+
*/
|
|
15
|
+
addEndpoint(method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH', path: string, handler: RouteHandler, middleware?: Middleware[]): void;
|
|
16
|
+
/** * Adds a global middleware that runs before every request.
|
|
17
|
+
* Useful for logging, CORS, or global security headers.
|
|
18
|
+
*/
|
|
19
|
+
use(middleware: Middleware): void;
|
|
20
|
+
/** * Groups routes under a common prefix and/or middleware.
|
|
21
|
+
* Useful for plugins that provide multiple endpoints (e.g., /api/v1/auth/*)
|
|
22
|
+
*/
|
|
23
|
+
group(prefix: string, callback: (runner: IBe5_Runner) => void, middlewares?: Middleware[]): void;
|
|
24
|
+
/** * Helper for quick GET route registration
|
|
25
|
+
*/
|
|
26
|
+
get(path: string, handler: RouteHandler, middlewares?: Middleware[]): void;
|
|
27
|
+
/** * Helper for quick POST route registration
|
|
28
|
+
*/
|
|
29
|
+
post(path: string, handler: RouteHandler, middlewares?: Middleware[]): void;
|
|
30
|
+
/** * Helper for quick Patch route registration
|
|
31
|
+
*/
|
|
32
|
+
patch(path: string, handler: RouteHandler, middlewares?: Middleware[]): void;
|
|
33
|
+
/** * Helper for quick Delete route registration
|
|
34
|
+
*/
|
|
35
|
+
delete(path: string, handler: RouteHandler, middlewares?: Middleware[]): void;
|
|
36
|
+
/** * Helper for quick Put route registration
|
|
37
|
+
*/
|
|
38
|
+
put(path: string, handler: RouteHandler, middlewares?: Middleware[]): void;
|
|
39
|
+
start(): void;
|
|
40
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bernouy/socle",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist/"
|
|
9
|
+
],
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"bun:build": "bun build.ts"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@types/bun": "latest",
|
|
21
|
+
"bun-types": "^1.3.6"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"typescript": "^5.9.3"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"bcryptjs": "^3.0.3",
|
|
28
|
+
"file-type": "^21.3.3",
|
|
29
|
+
"jose": "^6.2.1",
|
|
30
|
+
"mongodb": "7.1",
|
|
31
|
+
"nodemailer": "^6.9.16",
|
|
32
|
+
"sharp": "^0.34.5"
|
|
33
|
+
}
|
|
34
|
+
}
|