mirror of
https://github.com/nestriness/nestri.git
synced 2025-12-13 01:05:37 +02:00
⭐ feat: New account system with improved team management (#273)
Description <!-- Briefly describe the purpose and scope of your changes --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced comprehensive account management with combined user and team info. - Added advanced, context-aware logging utilities. - Implemented invite code generation for teams with uniqueness guarantees. - Expanded example data for users, teams, subscriptions, sessions, and games. - **Enhancements** - Refined user, team, member, and Steam account schemas for richer data and validation. - Streamlined user creation, login acknowledgment, and error handling. - Improved API authentication and unified actor context management. - Added persistent shared temporary volume support to API and auth services. - Enhanced Steam account management with create, update, and event notifications. - Refined team listing and serialization integrating Steam accounts as members. - Simplified event, context, and logging systems. - Updated API and auth middleware for better token handling and actor provisioning. - **Bug Fixes** - Fixed multiline log output to prefix each line with log level. - **Removals** - Removed machine and subscription management features, including schemas and DB tables. - Disabled machine-based authentication and removed related subject schemas. - Removed deprecated fields and legacy logic from member and team management. - Removed legacy event and error handling related to teams and members. - **Chores** - Reorganized and cleaned exports across utility and API modules. - Updated database schemas for users, teams, members, and Steam accounts. - Improved internal code structure, imports, and error messaging. - Moved logger patching to earlier initialization for consistent logging. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -3,13 +3,18 @@ import { ulid } from "ulid";
|
||||
export const prefixes = {
|
||||
user: "usr",
|
||||
team: "tem",
|
||||
task: "tsk",
|
||||
product: "prd",
|
||||
session: "ses",
|
||||
machine: "mch",
|
||||
member: "mbr",
|
||||
steam: "stm",
|
||||
variant: "var",
|
||||
gpu: "gpu",
|
||||
game: "gme",
|
||||
usage: "usg",
|
||||
subscription: "sub",
|
||||
invite: "inv",
|
||||
product: "prd",
|
||||
// task: "tsk",
|
||||
// invite: "inv",
|
||||
// product: "prd",
|
||||
} as const;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,2 +1,4 @@
|
||||
export * from "./fn"
|
||||
export * from "./id"
|
||||
export * from "./log"
|
||||
export * from "./id"
|
||||
export * from "./invite"
|
||||
32
packages/core/src/utils/invite.ts
Normal file
32
packages/core/src/utils/invite.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
export namespace Invite {
|
||||
/**
|
||||
* Generates a random invite code for teams
|
||||
* @param length The length of the invite code (default: 8)
|
||||
* @returns A string containing alphanumeric characters (excluding confusing characters)
|
||||
*/
|
||||
export function generateCode(length: number = 8): string {
|
||||
// Use only unambiguous characters (no 0/O, 1/l/I confusion)
|
||||
const characters = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789';
|
||||
let result = '';
|
||||
|
||||
// Create a Uint32Array of the required length for randomness
|
||||
const randomValues = new Uint32Array(length);
|
||||
|
||||
// Fill with cryptographically strong random values if available
|
||||
if (typeof crypto !== 'undefined' && crypto.getRandomValues) {
|
||||
crypto.getRandomValues(randomValues);
|
||||
} else {
|
||||
// Fallback for environments without crypto
|
||||
for (let i = 0; i < length; i++) {
|
||||
randomValues[i] = Math.floor(Math.random() * 2 ** 32);
|
||||
}
|
||||
}
|
||||
|
||||
// Use the random values to select characters
|
||||
for (let i = 0; i < length; i++) {
|
||||
result += characters.charAt(randomValues[i] % characters.length);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
76
packages/core/src/utils/log.ts
Normal file
76
packages/core/src/utils/log.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
import { createContext } from "../context";
|
||||
|
||||
export namespace Log {
|
||||
const ctx = createContext<{
|
||||
tags: Record<string, any>;
|
||||
}>();
|
||||
|
||||
export function create(tags?: Record<string, any>) {
|
||||
tags = tags || {};
|
||||
|
||||
const result = {
|
||||
info(msg: string, extra?: Record<string, any>) {
|
||||
const prefix = Object.entries({
|
||||
...use().tags,
|
||||
...tags,
|
||||
...extra,
|
||||
})
|
||||
.map(([key, value]) => `${key}=${value}`)
|
||||
.join(" ");
|
||||
console.log(prefix, msg);
|
||||
return result;
|
||||
},
|
||||
warn(msg: string, extra?: Record<string, any>) {
|
||||
const prefix = Object.entries({
|
||||
...use().tags,
|
||||
...tags,
|
||||
...extra,
|
||||
})
|
||||
.map(([key, value]) => `${key}=${value}`)
|
||||
.join(" ");
|
||||
console.warn(prefix, msg);
|
||||
return result;
|
||||
},
|
||||
error(error: Error) {
|
||||
const prefix = Object.entries({
|
||||
...use().tags,
|
||||
...tags,
|
||||
})
|
||||
.map(([key, value]) => `${key}=${value}`)
|
||||
.join(" ");
|
||||
console.error(prefix, error);
|
||||
return result;
|
||||
},
|
||||
tag(key: string, value: string) {
|
||||
// Immutable update: return a fresh logger with updated tags
|
||||
return Log.create({ ...tags, [key]: value });
|
||||
},
|
||||
clone() {
|
||||
return Log.create({ ...tags });
|
||||
},
|
||||
};
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export function provide<R>(tags: Record<string, any>, cb: () => R) {
|
||||
const existing = use();
|
||||
return ctx.provide(
|
||||
{
|
||||
tags: {
|
||||
...existing.tags,
|
||||
...tags,
|
||||
},
|
||||
},
|
||||
cb,
|
||||
);
|
||||
}
|
||||
|
||||
function use() {
|
||||
try {
|
||||
return ctx.use();
|
||||
} catch (e) {
|
||||
return { tags: {} };
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user