refactor: little light renaming

This commit is contained in:
Andy Burke 2025-06-24 16:17:00 -07:00
parent eef7b29223
commit 6f69695758
7 changed files with 31 additions and 31 deletions

View file

@ -10,7 +10,7 @@ export type PASSWORD_ENTRY = {
}; };
}; };
export const PASSWORD_ENTRY_STORE = new FSDB_COLLECTION<PASSWORD_ENTRY>({ export const PASSWORD_ENTRIES = new FSDB_COLLECTION<PASSWORD_ENTRY>({
name: 'password_entries', name: 'password_entries',
id_field: 'user_id' id_field: 'user_id'
}); });

View file

@ -9,7 +9,7 @@ export type TOTP_ENTRY = {
}; };
}; };
export const TOTP_ENTRY_STORE = new FSDB_COLLECTION<TOTP_ENTRY>({ export const TOTP_ENTRIES = new FSDB_COLLECTION<TOTP_ENTRY>({
name: 'totp_entries', name: 'totp_entries',
id_field: 'user_id' id_field: 'user_id'
}); });

View file

@ -11,7 +11,7 @@ export type USER = {
}; };
}; };
export const USER_STORE = new FSDB_COLLECTION<USER>({ export const USERS = new FSDB_COLLECTION<USER>({
name: 'users', name: 'users',
indexers: { indexers: {
// email: new FSDB_INDEXER_SYMLINKS<USER>({ // email: new FSDB_INDEXER_SYMLINKS<USER>({

View file

@ -9,7 +9,7 @@ export type USER_PERMISSIONS = {
}; };
}; };
export const USER_PERMISSIONS_STORE = new FSDB_COLLECTION<USER_PERMISSIONS>({ export const PERMISSIONS_STORE = new FSDB_COLLECTION<USER_PERMISSIONS>({
name: 'user_permissions', name: 'user_permissions',
id_field: 'user_id' id_field: 'user_id'
}); });

View file

@ -1,11 +1,11 @@
import { PASSWORD_ENTRY_STORE } from '../../../models/password_entry.ts'; import { PASSWORD_ENTRIES } from '../../../models/password_entry.ts';
import { USER, USER_STORE } from '../../../models/user.ts'; import { USER, USERS } from '../../../models/user.ts';
import { generateSecret } from 'jsr:@stdext/crypto/utils'; import { generateSecret } from 'jsr:@stdext/crypto/utils';
import { encodeBase32 } from 'jsr:@std/encoding'; import { encodeBase32 } from 'jsr:@std/encoding';
import { verify } from 'jsr:@stdext/crypto/hash'; import { verify } from 'jsr:@stdext/crypto/hash';
import lurid from 'jsr:@andyburke/lurid'; import lurid from 'jsr:@andyburke/lurid';
import { SESSION, SESSIONS } from '../../../models/session.ts'; import { SESSION, SESSIONS } from '../../../models/session.ts';
import { TOTP_ENTRY_STORE } from '../../../models/totp_entry.ts'; import { TOTP_ENTRIES } from '../../../models/totp_entry.ts';
import { verifyTotp } from 'jsr:@stdext/crypto/totp'; import { verifyTotp } from 'jsr:@stdext/crypto/totp';
import { encodeBase64 } from 'jsr:@std/encoding/base64'; import { encodeBase64 } from 'jsr:@std/encoding/base64';
import parse_body from '../../../utils/bodyparser.ts'; import parse_body from '../../../utils/bodyparser.ts';
@ -52,11 +52,11 @@ export async function POST(req: Request, meta: Record<string, any>): Promise<Res
let user: USER | undefined = undefined; let user: USER | undefined = undefined;
if (email.length) { if (email.length) {
user = (await USER_STORE.find({ user = (await USERS.find({
email email
})).shift(); })).shift();
} else if (username.length) { } else if (username.length) {
user = (await USER_STORE.find({ user = (await USERS.find({
username username
})).shift(); })).shift();
} }
@ -72,7 +72,7 @@ export async function POST(req: Request, meta: Record<string, any>): Promise<Res
}); });
} }
const password_entry = await PASSWORD_ENTRY_STORE.get(user.id); const password_entry = await PASSWORD_ENTRIES.get(user.id);
if (!password_entry) { if (!password_entry) {
return Response.json({ return Response.json({
error: { error: {
@ -96,7 +96,7 @@ export async function POST(req: Request, meta: Record<string, any>): Promise<Res
}); });
} }
const totp_entry = await TOTP_ENTRY_STORE.get(user.id); const totp_entry = await TOTP_ENTRIES.get(user.id);
if (totp_entry) { if (totp_entry) {
if (typeof totp !== 'string' || !totp.length) { if (typeof totp !== 'string' || !totp.length) {
return Response.json({ return Response.json({

View file

@ -1,7 +1,7 @@
import { PASSWORD_ENTRY, PASSWORD_ENTRY_STORE } from '../../../../models/password_entry.ts'; import { PASSWORD_ENTRIES, PASSWORD_ENTRY } from '../../../../models/password_entry.ts';
import { SESSIONS } from '../../../../models/session.ts'; import { SESSIONS } from '../../../../models/session.ts';
import { USER, USER_STORE } from '../../../../models/user.ts'; import { USER, USERS } from '../../../../models/user.ts';
import { USER_PERMISSIONS, USER_PERMISSIONS_STORE } from '../../../../models/user_permissions.ts'; import { PERMISSIONS_STORE, USER_PERMISSIONS } from '../../../../models/user_permissions.ts';
import parse_body from '../../../../utils/bodyparser.ts'; import parse_body from '../../../../utils/bodyparser.ts';
export const PERMISSIONS: Record<string, (req: Request, meta: Record<string, any>) => Promise<boolean>> = {}; export const PERMISSIONS: Record<string, (req: Request, meta: Record<string, any>) => Promise<boolean>> = {};
@ -16,7 +16,7 @@ PERMISSIONS.GET = (_req: Request, meta: Record<string, any>): Promise<boolean> =
}; };
export async function GET(_req: Request, meta: Record<string, any>): Promise<Response> { export async function GET(_req: Request, meta: Record<string, any>): Promise<Response> {
const user_id: string = meta.params?.id?.toLowerCase().trim() ?? ''; const user_id: string = meta.params?.id?.toLowerCase().trim() ?? '';
const user: USER | null = user_id.length === 49 ? await USER_STORE.get(user_id) : null; // lurid is 49 chars as we use them, eg: "also-play-flow-want-form-wide-thus-work-burn-same" const user: USER | null = user_id.length === 49 ? await USERS.get(user_id) : null; // lurid is 49 chars as we use them, eg: "also-play-flow-want-form-wide-thus-work-burn-same"
if (!user) { if (!user) {
return Response.json({ return Response.json({
@ -60,7 +60,7 @@ PERMISSIONS.PUT = (_req: Request, meta: Record<string, any>): Promise<boolean> =
export async function PUT(req: Request, meta: { params: Record<string, any> }): Promise<Response> { export async function PUT(req: Request, meta: { params: Record<string, any> }): Promise<Response> {
const now = new Date().toISOString(); const now = new Date().toISOString();
const id: string = meta.params.id ?? ''; const id: string = meta.params.id ?? '';
const existing = await USER_STORE.get(id); const existing = await USERS.get(id);
if (!existing) { if (!existing) {
return Response.json({ return Response.json({
@ -84,7 +84,7 @@ export async function PUT(req: Request, meta: { params: Record<string, any> }):
} }
}; };
await USER_STORE.update(updated); await USERS.update(updated);
return Response.json(updated, { return Response.json(updated, {
status: 200 status: 200
}); });
@ -111,7 +111,7 @@ PERMISSIONS.DELETE = (_req: Request, meta: Record<string, any>): Promise<boolean
export async function DELETE(_req: Request, meta: { params: Record<string, any> }): Promise<Response> { export async function DELETE(_req: Request, meta: { params: Record<string, any> }): Promise<Response> {
const user_id: string = meta.params.id ?? ''; const user_id: string = meta.params.id ?? '';
const user: USER | null = await USER_STORE.get(user_id); const user: USER | null = await USERS.get(user_id);
if (!user) { if (!user) {
return Response.json({ return Response.json({
error: { error: {
@ -123,13 +123,13 @@ export async function DELETE(_req: Request, meta: { params: Record<string, any>
}); });
} }
const password_entry: PASSWORD_ENTRY | null = await PASSWORD_ENTRY_STORE.get(user_id); const password_entry: PASSWORD_ENTRY | null = await PASSWORD_ENTRIES.get(user_id);
if (password_entry) { if (password_entry) {
await PASSWORD_ENTRY_STORE.delete(password_entry); await PASSWORD_ENTRIES.delete(password_entry);
} }
const user_permissions: USER_PERMISSIONS | null = await USER_PERMISSIONS_STORE.get(user_id); const user_permissions: USER_PERMISSIONS | null = await PERMISSIONS_STORE.get(user_id);
if (user_permissions) { if (user_permissions) {
await USER_PERMISSIONS_STORE.delete(user_permissions); await PERMISSIONS_STORE.delete(user_permissions);
} }
const sessions = await SESSIONS.find({ const sessions = await SESSIONS.find({
@ -139,7 +139,7 @@ export async function DELETE(_req: Request, meta: { params: Record<string, any>
await SESSIONS.delete(session); await SESSIONS.delete(session);
} }
await USER_STORE.delete(user); await USERS.delete(user);
return Response.json({ return Response.json({
deleted: true deleted: true

View file

@ -1,6 +1,6 @@
import { PASSWORD_ENTRY, PASSWORD_ENTRY_STORE } from '../../../models/password_entry.ts'; import { PASSWORD_ENTRIES, PASSWORD_ENTRY } from '../../../models/password_entry.ts';
import { USER, USER_STORE } from '../../../models/user.ts'; import { USER, USERS } from '../../../models/user.ts';
import { USER_PERMISSIONS, USER_PERMISSIONS_STORE } from '../../../models/user_permissions.ts'; import { PERMISSIONS_STORE, USER_PERMISSIONS } from '../../../models/user_permissions.ts';
import { generateSecret } from 'jsr:@stdext/crypto/utils'; import { generateSecret } from 'jsr:@stdext/crypto/utils';
import { hash } from 'jsr:@stdext/crypto/hash'; import { hash } from 'jsr:@stdext/crypto/hash';
import lurid from 'jsr:@andyburke/lurid'; import lurid from 'jsr:@andyburke/lurid';
@ -45,7 +45,7 @@ export async function GET(_req: Request, meta: Record<string, any>): Promise<Res
} }
const limit = Math.min(parseInt(query.get('limit') ?? '10'), 100); const limit = Math.min(parseInt(query.get('limit') ?? '10'), 100);
const users = await USER_STORE.find({ const users = await USERS.find({
id: partial_id id: partial_id
}, { }, {
limit limit
@ -65,7 +65,7 @@ export async function POST(req: Request, meta: Record<string, any>): Promise<Res
const username: string = body.username?.trim() ?? ''; const username: string = body.username?.trim() ?? '';
const normalized_username = username.toLowerCase(); const normalized_username = username.toLowerCase();
const existing_user_with_username = (await USER_STORE.find({ const existing_user_with_username = (await USERS.find({
normalized_username normalized_username
})).shift(); })).shift();
if (existing_user_with_username) { if (existing_user_with_username) {
@ -104,7 +104,7 @@ export async function POST(req: Request, meta: Record<string, any>): Promise<Res
} }
}; };
await USER_STORE.create(user); await USERS.create(user);
const salt = generateSecret(); const salt = generateSecret();
const hashed_password_value = hash('bcrypt', `${password_hash}${salt}`); const hashed_password_value = hash('bcrypt', `${password_hash}${salt}`);
@ -119,7 +119,7 @@ export async function POST(req: Request, meta: Record<string, any>): Promise<Res
} }
}; };
await PASSWORD_ENTRY_STORE.create(password_entry); await PASSWORD_ENTRIES.create(password_entry);
const user_permissions: USER_PERMISSIONS = { const user_permissions: USER_PERMISSIONS = {
user_id: user.id, user_id: user.id,
@ -130,7 +130,7 @@ export async function POST(req: Request, meta: Record<string, any>): Promise<Res
} }
}; };
await USER_PERMISSIONS_STORE.create(user_permissions); await PERMISSIONS_STORE.create(user_permissions);
const session_result: SESSION_RESULT = await get_session({ const session_result: SESSION_RESULT = await get_session({
user, user,