first commit
Some checks failed
Code quality checks / biome (push) Failing after 11s

This commit is contained in:
creations 2025-06-10 13:42:39 -04:00
commit 421043c9b5
Signed by: creations
GPG key ID: 8F553AA4320FC711
67 changed files with 3455 additions and 0 deletions

32
types/config/auth.ts Normal file
View file

@ -0,0 +1,32 @@
type JWTConfig = {
secret: string;
expiration: string | number;
issuer: string;
algorithm: string;
};
interface CookieOptions {
secure?: boolean;
httpOnly?: boolean;
sameSite?: "Strict" | "Lax" | "None";
path?: string;
domain?: string;
}
interface UserSession {
id: string;
username: string;
email: string;
isVerified: boolean;
displayName: string | null;
createdAt: string; // ISO date string
updatedAt?: string; // ISO date string, optional
iat?: number; // issued at (added by JWT libs)
exp?: number; // expiration (added by JWT libs)
}
interface SessionData extends UserSession {
userAgent: string;
}
export type { JWTConfig, CookieOptions, UserSession, SessionData };

25
types/config/database.ts Normal file
View file

@ -0,0 +1,25 @@
type CassandraConfig = {
host: string;
port: number;
keyspace: string;
username: string;
password: string;
datacenter: string;
contactPoints: string[];
authEnabled: boolean;
};
type SqlMigration = {
id: string;
name: string;
upSql: string;
downSql?: string | undefined;
};
type ConnectionOptions = {
withKeyspace?: boolean;
timeout?: number;
logging?: boolean;
};
export type { CassandraConfig, SqlMigration, ConnectionOptions };

View file

@ -0,0 +1,7 @@
type Environment = {
port: number;
host: string;
development: boolean;
};
export type { Environment };

3
types/config/index.ts Normal file
View file

@ -0,0 +1,3 @@
export * from "./environment";
export * from "./database";
export * from "./auth";

3
types/index.ts Normal file
View file

@ -0,0 +1,3 @@
export * from "./server";
export * from "./config";
export * from "./lib";

1
types/lib/index.ts Normal file
View file

@ -0,0 +1 @@
export * from "./validation";

13
types/lib/validation.ts Normal file
View file

@ -0,0 +1,13 @@
type genericValidation = {
length: { min: number; max: number };
regex: RegExp;
};
type validationResult = {
valid: boolean;
error?: string;
username?: string;
name?: string;
};
export type { genericValidation, validationResult };

3
types/server/index.ts Normal file
View file

@ -0,0 +1,3 @@
export * from "./server";
export * from "./routes";
export * from "./requests";

View file

@ -0,0 +1 @@
export * from "./user";

View file

@ -0,0 +1,28 @@
interface BaseResponse {
code: number;
success: boolean;
error?: string;
message?: string;
}
interface UserResponse {
id: string;
username: string;
email: string;
isVerified: boolean;
createdAt: string;
displayName: string | null;
}
interface UserRow {
id: string;
username: string;
display_name: string | null;
email: string;
password: string;
is_verified: boolean;
created_at: Date;
updated_at: Date;
}
export type { BaseResponse, UserResponse, UserRow };

View file

@ -0,0 +1,6 @@
export * from "./base";
export * from "./responses";
export * from "./register";
export * from "./login";
export * from "./update";

View file

@ -0,0 +1,12 @@
import type { BaseResponse, UserResponse } from "./base";
interface LoginRequest {
identifier: string; // Username or email
password: string;
}
interface LoginResponse extends BaseResponse {
user?: UserResponse;
}
export type { LoginRequest, LoginResponse };

View file

@ -0,0 +1,7 @@
interface UpdatePasswordRequest {
currentPassword: string;
newPassword: string;
logoutAllSessions?: boolean; // defaults to false
}
export type { UpdatePasswordRequest };

View file

@ -0,0 +1,14 @@
import type { BaseResponse, UserResponse } from "./base";
interface RegisterRequest {
username: string;
displayName: string | null;
email: string;
password: string;
}
interface RegisterResponse extends BaseResponse {
user?: UserResponse;
}
export type { RegisterRequest, RegisterResponse };

View file

@ -0,0 +1,7 @@
import type { BaseResponse, UserResponse } from "./base";
interface UserInfoResponse extends BaseResponse {
user?: UserResponse;
}
export type { UserInfoResponse };

View file

@ -0,0 +1,2 @@
export * from "./info";
export * from "./password";

View file

@ -0,0 +1,13 @@
import type { BaseResponse, UserResponse } from "../base";
interface UpdateInfoRequest {
username?: string;
displayName?: string | null;
email?: string;
}
interface UpdateInfoResponse extends BaseResponse {
user?: UserResponse;
}
export type { UpdateInfoRequest, UpdateInfoResponse };

View file

@ -0,0 +1,14 @@
import type { BaseResponse, UserResponse } from "../base";
interface UpdatePasswordRequest {
currentPassword: string;
newPassword: string;
logoutAllSessions?: boolean; // defaults to false
}
interface UpdatePasswordResponse extends BaseResponse {
user?: UserResponse;
loggedOutSessions?: number;
}
export type { UpdatePasswordRequest, UpdatePasswordResponse };

20
types/server/routes.ts Normal file
View file

@ -0,0 +1,20 @@
import type { Server } from "bun";
import type { ExtendedRequest } from "./server";
type RouteDef = {
method: string | string[];
accepts: string | null | string[];
returns: string;
needsBody?: "multipart" | "json";
};
type RouteModule = {
handler: (
request: Request | ExtendedRequest,
requestBody: unknown,
server: Server,
) => Promise<Response> | Response;
routeDef: RouteDef;
};
export type { RouteDef, RouteModule };

10
types/server/server.ts Normal file
View file

@ -0,0 +1,10 @@
type Query = Record<string, string>;
type Params = Record<string, string>;
interface ExtendedRequest extends Request {
startPerf: number;
query: Query;
params: Params;
}
export type { ExtendedRequest, Query, Params };