@sqrzro/server 2.0.0-bz.1 → 2.0.0-bz.11
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 +1 -1
- package/README.md +25 -1
- package/auth.d.ts +1 -0
- package/auth.js +1 -0
- package/cache.d.ts +1 -0
- package/cache.js +1 -0
- package/dist/auth.d.ts +100 -0
- package/dist/auth.js +891 -0
- package/dist/cache.d.ts +4 -0
- package/dist/cache.js +46 -0
- package/dist/forms.d.ts +46 -0
- package/dist/forms.js +327 -0
- package/dist/lists.d.ts +18 -0
- package/dist/lists.js +61 -0
- package/dist/mail.d.ts +12 -0
- package/dist/mail.js +97 -0
- package/dist/middleware.d.ts +5 -0
- package/dist/middleware.js +66 -0
- package/dist/schema.d.ts +288 -0
- package/dist/schema.js +77 -0
- package/dist/url.d.ts +28 -0
- package/dist/url.js +56 -0
- package/forms.d.ts +1 -0
- package/forms.js +1 -0
- package/lists.d.ts +1 -0
- package/lists.js +1 -0
- package/mail.d.ts +1 -0
- package/mail.js +1 -0
- package/middleware.d.ts +1 -0
- package/middleware.js +1 -0
- package/package.json +67 -44
- package/schema.d.ts +1 -0
- package/schema.js +1 -0
- package/url.d.ts +1 -0
- package/url.js +1 -0
- package/dist/AuthService.d.ts +0 -10
- package/dist/AuthService.js +0 -36
- package/dist/DataService.d.ts +0 -29
- package/dist/DataService.js +0 -64
- package/dist/LoginRequest.d.ts +0 -4
- package/dist/LoginRequest.js +0 -11
- package/dist/PasswordService.d.ts +0 -6
- package/dist/PasswordService.js +0 -63
- package/dist/RequestService.d.ts +0 -21
- package/dist/RequestService.js +0 -121
- package/dist/SessionService.d.ts +0 -5
- package/dist/SessionService.js +0 -56
- package/dist/index.d.ts +0 -7
- package/dist/index.js +0 -10
- package/dist/interfaces.d.ts +0 -11
- package/dist/interfaces.js +0 -2
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright
|
|
1
|
+
Copyright 2024 Richard Carter
|
|
2
2
|
|
|
3
3
|
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
|
|
4
4
|
|
package/README.md
CHANGED
|
@@ -1 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
<h1>
|
|
4
|
+
<img src="assets/logo.svg" alt="" width="64" style="margin-bottom: 5px">
|
|
5
|
+
<br />
|
|
6
|
+
Square Zero Server
|
|
7
|
+
</h1>
|
|
8
|
+
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
<hr />
|
|
12
|
+
|
|
13
|
+
## @sqrzro/server/auth
|
|
14
|
+
|
|
15
|
+
## @sqrzro/server/cache
|
|
16
|
+
|
|
17
|
+
## @sqrzro/server/db
|
|
18
|
+
|
|
19
|
+
## @sqrzro/server/forms
|
|
20
|
+
|
|
21
|
+
## @sqrzro/server/lists
|
|
22
|
+
|
|
23
|
+
## @sqrzro/server/mail
|
|
24
|
+
|
|
25
|
+
## @sqrzro/server/url
|
package/auth.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/auth/index';
|
package/auth.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/auth/index');
|
package/cache.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/cache/index';
|
package/cache.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/cache/index');
|
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { Errorable } from '@sqrzro/interfaces';
|
|
2
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
3
|
+
import { AuthClient, Scope } from './schema.js';
|
|
4
|
+
import { Lucia } from 'lucia';
|
|
5
|
+
import 'drizzle-orm/pg-core';
|
|
6
|
+
|
|
7
|
+
interface LoginFormFields {
|
|
8
|
+
email: string;
|
|
9
|
+
password: string;
|
|
10
|
+
}
|
|
11
|
+
interface MFAFormFields {
|
|
12
|
+
token: string;
|
|
13
|
+
}
|
|
14
|
+
interface PasswordFormFields {
|
|
15
|
+
email: string;
|
|
16
|
+
}
|
|
17
|
+
interface PasswordResetFormFields {
|
|
18
|
+
password: string;
|
|
19
|
+
token: string;
|
|
20
|
+
}
|
|
21
|
+
interface UserObject {
|
|
22
|
+
id: string;
|
|
23
|
+
email: string;
|
|
24
|
+
password?: string | null;
|
|
25
|
+
role?: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
declare function handleLogout(): Promise<void>;
|
|
29
|
+
declare function getAllowedRoles(): number[];
|
|
30
|
+
declare function handleLoginForm(formData: LoginFormFields): Promise<Errorable<string>>;
|
|
31
|
+
interface RegisterUserArgs {
|
|
32
|
+
email: string;
|
|
33
|
+
password?: string;
|
|
34
|
+
role?: number;
|
|
35
|
+
}
|
|
36
|
+
declare function registerUser({ email, password, role, }: RegisterUserArgs): Promise<UserObject | null>;
|
|
37
|
+
declare function handlePasswordForm(formData: PasswordFormFields, mailFn: (email: string, token: string) => Promise<boolean>): Promise<Errorable<boolean>>;
|
|
38
|
+
declare function handlePasswordResetForm(formData: PasswordResetFormFields): Promise<Errorable<string | null>>;
|
|
39
|
+
|
|
40
|
+
declare function getClientByID(id: string): Promise<AuthClient | null>;
|
|
41
|
+
interface RegisterClientArgs {
|
|
42
|
+
alias: string;
|
|
43
|
+
id?: string;
|
|
44
|
+
secret?: string;
|
|
45
|
+
}
|
|
46
|
+
declare function registerClient({ alias, id, secret, }: RegisterClientArgs): Promise<AuthClient | null>;
|
|
47
|
+
declare function handleClientAuth(request: NextRequest): Promise<AuthClient | null>;
|
|
48
|
+
|
|
49
|
+
declare function checkMFAEnabled(): boolean;
|
|
50
|
+
declare function generateMFA(name: string, email?: string): Promise<string | null>;
|
|
51
|
+
declare function checkUserHasMFA(user: UserObject): Promise<boolean>;
|
|
52
|
+
declare function handleMFAForm(formData: MFAFormFields): Promise<Errorable<boolean>>;
|
|
53
|
+
|
|
54
|
+
interface ScopeData {
|
|
55
|
+
allowedRoute?: string;
|
|
56
|
+
redirectOnAuth?: string;
|
|
57
|
+
redirectOnUnauth?: string;
|
|
58
|
+
}
|
|
59
|
+
type ScopeObject = Record<Scope, ScopeData>;
|
|
60
|
+
interface DatabaseSessionAttributes {
|
|
61
|
+
scope: Scope;
|
|
62
|
+
}
|
|
63
|
+
interface DatabaseUserAttributes {
|
|
64
|
+
email: string;
|
|
65
|
+
role: number;
|
|
66
|
+
}
|
|
67
|
+
declare module 'lucia' {
|
|
68
|
+
interface Register {
|
|
69
|
+
Lucia: typeof lucia;
|
|
70
|
+
DatabaseSessionAttributes: DatabaseSessionAttributes;
|
|
71
|
+
DatabaseUserAttributes: DatabaseUserAttributes;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
declare const lucia: Lucia<DatabaseSessionAttributes, DatabaseUserAttributes>;
|
|
75
|
+
declare function generateID(length?: number): string;
|
|
76
|
+
declare function invalidateSession(id: string): Promise<void>;
|
|
77
|
+
declare function invalidateUserSessions(id: string): Promise<void>;
|
|
78
|
+
declare function createUserSession(id: string, scope?: Scope): Promise<boolean>;
|
|
79
|
+
declare function getSessionID(): string | null;
|
|
80
|
+
declare function checkSessionExists(): boolean;
|
|
81
|
+
declare function getSessionUser(): Promise<{
|
|
82
|
+
id: string;
|
|
83
|
+
email: string;
|
|
84
|
+
role: number;
|
|
85
|
+
} | null>;
|
|
86
|
+
declare function checkRouteAllowed(pathname: string, route?: string): boolean;
|
|
87
|
+
declare function getScopes(): Promise<ScopeObject>;
|
|
88
|
+
declare function getScopeByID(id: Scope): Promise<ScopeData>;
|
|
89
|
+
declare function setScopes(customScopes?: Partial<ScopeObject>): Promise<void>;
|
|
90
|
+
declare function handleSession(request: NextRequest, customScopes?: Partial<ScopeObject>): Promise<NextResponse>;
|
|
91
|
+
|
|
92
|
+
type PasswordRule = 'lower' | 'min' | 'number' | 'symbol' | 'upper';
|
|
93
|
+
type PasswordRuleObject = Partial<Record<PasswordRule, number>>;
|
|
94
|
+
type PasswordValidityObject = Record<PasswordRule, boolean>;
|
|
95
|
+
declare function hashPassword(password: string): Promise<string>;
|
|
96
|
+
declare function verifyPassword(data?: string, encrypted?: string): Promise<boolean>;
|
|
97
|
+
declare function getPasswordComplexity(password: string, rules?: Partial<PasswordRuleObject>): Promise<Partial<PasswordValidityObject>>;
|
|
98
|
+
declare function checkPasswordComplexity(password: string, rules?: Partial<PasswordRuleObject>): Promise<Partial<boolean>>;
|
|
99
|
+
|
|
100
|
+
export { type LoginFormFields, type MFAFormFields, type PasswordFormFields, type PasswordResetFormFields, type PasswordRuleObject, type ScopeObject, type UserObject, checkMFAEnabled, checkPasswordComplexity, checkRouteAllowed, checkSessionExists, checkUserHasMFA, createUserSession, generateID, generateMFA, getAllowedRoles, getClientByID, getPasswordComplexity, getScopeByID, getScopes, getSessionID, getSessionUser, handleClientAuth, handleLoginForm, handleLogout, handleMFAForm, handlePasswordForm, handlePasswordResetForm, handleSession, hashPassword, invalidateSession, invalidateUserSessions, lucia, registerClient, registerUser, setScopes, verifyPassword };
|