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',
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',
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',
indexers: {
// 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',
id_field: 'user_id'
});

View file

@ -1,11 +1,11 @@
import { PASSWORD_ENTRY_STORE } from '../../../models/password_entry.ts';
import { USER, USER_STORE } from '../../../models/user.ts';
import { PASSWORD_ENTRIES } from '../../../models/password_entry.ts';
import { USER, USERS } from '../../../models/user.ts';
import { generateSecret } from 'jsr:@stdext/crypto/utils';
import { encodeBase32 } from 'jsr:@std/encoding';
import { verify } from 'jsr:@stdext/crypto/hash';
import lurid from 'jsr:@andyburke/lurid';
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 { encodeBase64 } from 'jsr:@std/encoding/base64';
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;
if (email.length) {
user = (await USER_STORE.find({
user = (await USERS.find({
email
})).shift();
} else if (username.length) {
user = (await USER_STORE.find({
user = (await USERS.find({
username
})).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) {
return Response.json({
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 (typeof totp !== 'string' || !totp.length) {
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 { USER, USER_STORE } from '../../../../models/user.ts';
import { USER_PERMISSIONS, USER_PERMISSIONS_STORE } from '../../../../models/user_permissions.ts';
import { USER, USERS } from '../../../../models/user.ts';
import { PERMISSIONS_STORE, USER_PERMISSIONS } from '../../../../models/user_permissions.ts';
import parse_body from '../../../../utils/bodyparser.ts';
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> {
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) {
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> {
const now = new Date().toISOString();
const id: string = meta.params.id ?? '';
const existing = await USER_STORE.get(id);
const existing = await USERS.get(id);
if (!existing) {
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, {
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> {
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) {
return Response.json({
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) {
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) {
await USER_PERMISSIONS_STORE.delete(user_permissions);
await PERMISSIONS_STORE.delete(user_permissions);
}
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 USER_STORE.delete(user);
await USERS.delete(user);
return Response.json({
deleted: true

View file

@ -1,6 +1,6 @@
import { PASSWORD_ENTRY, PASSWORD_ENTRY_STORE } from '../../../models/password_entry.ts';
import { USER, USER_STORE } from '../../../models/user.ts';
import { USER_PERMISSIONS, USER_PERMISSIONS_STORE } from '../../../models/user_permissions.ts';
import { PASSWORD_ENTRIES, PASSWORD_ENTRY } from '../../../models/password_entry.ts';
import { USER, USERS } from '../../../models/user.ts';
import { PERMISSIONS_STORE, USER_PERMISSIONS } from '../../../models/user_permissions.ts';
import { generateSecret } from 'jsr:@stdext/crypto/utils';
import { hash } from 'jsr:@stdext/crypto/hash';
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 users = await USER_STORE.find({
const users = await USERS.find({
id: partial_id
}, {
limit
@ -65,7 +65,7 @@ export async function POST(req: Request, meta: Record<string, any>): Promise<Res
const username: string = body.username?.trim() ?? '';
const normalized_username = username.toLowerCase();
const existing_user_with_username = (await USER_STORE.find({
const existing_user_with_username = (await USERS.find({
normalized_username
})).shift();
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 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 = {
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({
user,