@sqrzro/server 2.0.0-bz.10 → 2.0.0-bz.12

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 (84) hide show
  1. package/auth.d.ts +1 -1
  2. package/auth.js +1 -1
  3. package/cache.d.ts +1 -1
  4. package/cache.js +1 -1
  5. package/dist/auth.d.ts +100 -0
  6. package/dist/auth.js +891 -0
  7. package/dist/cache.d.ts +4 -0
  8. package/dist/cache.js +46 -0
  9. package/dist/forms.d.ts +46 -0
  10. package/dist/forms.js +327 -0
  11. package/dist/{lists/ListService.d.ts → lists.d.ts} +5 -3
  12. package/dist/lists.js +61 -0
  13. package/dist/mail.d.ts +12 -0
  14. package/dist/mail.js +97 -0
  15. package/dist/middleware.d.ts +5 -3
  16. package/dist/middleware.js +58 -22
  17. package/dist/{database/schema.d.ts → schema.d.ts} +38 -34
  18. package/dist/schema.js +77 -0
  19. package/dist/{url/URLService.d.ts → url.d.ts} +4 -2
  20. package/dist/url.js +56 -0
  21. package/forms.d.ts +1 -1
  22. package/forms.js +1 -1
  23. package/lists.d.ts +1 -1
  24. package/lists.js +1 -1
  25. package/mail.d.ts +1 -1
  26. package/mail.js +1 -1
  27. package/package.json +10 -11
  28. package/schema.d.ts +1 -1
  29. package/schema.js +1 -1
  30. package/url.d.ts +1 -1
  31. package/url.js +1 -1
  32. package/database.d.ts +0 -1
  33. package/database.js +0 -1
  34. package/dist/auth/AuthService.d.ts +0 -14
  35. package/dist/auth/AuthService.js +0 -135
  36. package/dist/auth/ClientService.d.ts +0 -11
  37. package/dist/auth/ClientService.js +0 -47
  38. package/dist/auth/LoginRequest.d.ts +0 -4
  39. package/dist/auth/LoginRequest.js +0 -8
  40. package/dist/auth/MFARequest.d.ts +0 -4
  41. package/dist/auth/MFARequest.js +0 -9
  42. package/dist/auth/MFAService.d.ts +0 -6
  43. package/dist/auth/MFAService.js +0 -105
  44. package/dist/auth/PasswordRequest.d.ts +0 -4
  45. package/dist/auth/PasswordRequest.js +0 -12
  46. package/dist/auth/PasswordResetRequest.d.ts +0 -4
  47. package/dist/auth/PasswordResetRequest.js +0 -13
  48. package/dist/auth/PasswordService.d.ts +0 -8
  49. package/dist/auth/PasswordService.js +0 -54
  50. package/dist/auth/SessionService.d.ts +0 -42
  51. package/dist/auth/SessionService.js +0 -127
  52. package/dist/auth/index.d.ts +0 -6
  53. package/dist/auth/index.js +0 -6
  54. package/dist/auth/interfaces.d.ts +0 -20
  55. package/dist/auth/interfaces.js +0 -1
  56. package/dist/cache/CacheService.d.ts +0 -2
  57. package/dist/cache/CacheService.js +0 -14
  58. package/dist/cache/index.d.ts +0 -1
  59. package/dist/cache/index.js +0 -1
  60. package/dist/database/DatabaseService.d.ts +0 -7
  61. package/dist/database/DatabaseService.js +0 -12
  62. package/dist/database/schema.js +0 -42
  63. package/dist/forms/FormService.d.ts +0 -16
  64. package/dist/forms/FormService.js +0 -78
  65. package/dist/forms/ImageService.d.ts +0 -7
  66. package/dist/forms/ImageService.js +0 -19
  67. package/dist/forms/ValidationError.d.ts +0 -4
  68. package/dist/forms/ValidationError.js +0 -7
  69. package/dist/forms/ValidationService.d.ts +0 -20
  70. package/dist/forms/ValidationService.js +0 -59
  71. package/dist/forms/index.d.ts +0 -3
  72. package/dist/forms/index.js +0 -3
  73. package/dist/forms/lang.d.ts +0 -2
  74. package/dist/forms/lang.js +0 -115
  75. package/dist/lists/ListService.js +0 -28
  76. package/dist/lists/index.d.ts +0 -1
  77. package/dist/lists/index.js +0 -1
  78. package/dist/mail/MailService.d.ts +0 -12
  79. package/dist/mail/MailService.js +0 -55
  80. package/dist/mail/index.d.ts +0 -1
  81. package/dist/mail/index.js +0 -1
  82. package/dist/url/URLService.js +0 -48
  83. package/dist/url/index.d.ts +0 -1
  84. package/dist/url/index.js +0 -1
package/auth.d.ts CHANGED
@@ -1 +1 @@
1
- export * from './dist/auth/index';
1
+ export * from './dist/auth';
package/auth.js CHANGED
@@ -1 +1 @@
1
- module.exports = require('./dist/auth/index');
1
+ module.exports = require('./dist/auth');
package/cache.d.ts CHANGED
@@ -1 +1 @@
1
- export * from './dist/cache/index';
1
+ export * from './dist/cache';
package/cache.js CHANGED
@@ -1 +1 @@
1
- module.exports = require('./dist/cache/index');
1
+ module.exports = require('./dist/cache');
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 };