This commit is contained in:
Wuesteon 2025-12-04 00:32:13 +01:00
parent 16cb8e753b
commit e9caa4a217
46 changed files with 1784 additions and 728 deletions

View file

@ -21,6 +21,8 @@ export const typescriptConfig = [
parserOptions: {
ecmaVersion: 2022,
sourceType: 'module',
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
plugins: {

View file

@ -1,4 +1,4 @@
import { createParamDecorator, ExecutionContext } from '@nestjs/common';
import { createParamDecorator, type ExecutionContext } from '@nestjs/common';
export interface JwtPayload {
sub: string;

View file

@ -1,4 +1,4 @@
import { ModuleMetadata, Type } from '@nestjs/common';
import { type ModuleMetadata, type Type } from '@nestjs/common';
export interface ManaCoreModuleOptions {
/**

View file

@ -106,12 +106,17 @@ export class CreditClientService {
return this.getDefaultBalance();
}
const data = (await response.json()) as CreditBalance;
const {
balance = 0,
freeCreditsRemaining = 0,
totalEarned = 0,
totalSpent = 0,
} = (await response.json()) as CreditBalance;
return {
balance: data.balance || 0,
freeCreditsRemaining: data.freeCreditsRemaining || 0,
totalEarned: data.totalEarned || 0,
totalSpent: data.totalSpent || 0,
balance,
freeCreditsRemaining,
totalEarned,
totalSpent,
};
} catch (error) {
this.logger.error(`Failed to get balance for user ${userId}:`, error);

View file

@ -1,4 +1,4 @@
import { drizzle, PostgresJsDatabase } from 'drizzle-orm/postgres-js';
import { drizzle, type PostgresJsDatabase } from 'drizzle-orm/postgres-js';
import postgres from 'postgres';
import * as schema from './schema';

View file

@ -3,8 +3,6 @@
* Generic types for creating auth stores with custom user types
*/
import type { AuthResult as BaseAuthResult } from '@manacore/shared-types';
/**
* Base user interface that all app-specific user types must extend
*/

View file

@ -106,10 +106,6 @@ export function createAuthService(config: AuthServiceConfig) {
*/
async signUp(email: string, password: string): Promise<AuthResult> {
try {
const storage = getStorageAdapter();
const deviceAdapter = getDeviceAdapter();
const deviceInfo = await deviceAdapter.getDeviceInfo();
const response = await fetch(`${baseUrl}${endpoints.signUp}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
@ -128,7 +124,8 @@ export function createAuthService(config: AuthServiceConfig) {
return { success: false, error: errorData.message || 'Sign up failed' };
}
const responseData = await response.json();
// Consume response to avoid unhandled promise
await response.json();
// Mana Core Auth returns user data immediately on registration
// User needs to sign in separately to get tokens

View file

@ -30,7 +30,7 @@ export function decodeToken(token: string): DecodedToken | null {
/**
* Check if a token is valid locally (not expired)
*/
export function isTokenValidLocally(token: string, bufferSeconds: number = 10): boolean {
export function isTokenValidLocally(token: string, bufferSeconds = 10): boolean {
try {
const payload = decodeToken(token);
if (!payload || !payload.exp) {

View file

@ -118,7 +118,7 @@ export function getEnv(
*/
export function getBoolEnv(
key: string,
defaultValue: boolean = false,
defaultValue = false,
env: NodeJS.ProcessEnv = process.env
): boolean {
const value = env[key];

View file

@ -99,7 +99,7 @@ export function createFeatureFlags<T extends Record<string, FeatureFlag>>(
*/
export function isFeatureEnabled(
featureName: string,
defaultValue: boolean = false,
defaultValue = false,
env: NodeJS.ProcessEnv = process.env
): boolean {
const envVar = `FEATURE_${featureName.toUpperCase().replace(/[^A-Z0-9]/g, '_')}`;

View file

@ -230,10 +230,7 @@ export function createCreditService(config: CreditServiceConfig) {
/**
* Calculate cost for multiple units of an operation
*/
async function calculateCost(
operation: StandardOperationType,
quantity: number = 1
): Promise<number> {
async function calculateCost(operation: StandardOperationType, quantity = 1): Promise<number> {
const unitCost = await getOperationCost(operation);
return unitCost * quantity;
}
@ -241,7 +238,7 @@ export function createCreditService(config: CreditServiceConfig) {
/**
* Calculate cost synchronously (uses cached values)
*/
function calculateCostSync(operation: StandardOperationType, quantity: number = 1): number {
function calculateCostSync(operation: StandardOperationType, quantity = 1): number {
const unitCost = getOperationCostSync(operation);
return unitCost * quantity;
}
@ -288,7 +285,7 @@ export function createCreditService(config: CreditServiceConfig) {
/**
* Format credit amount for display
*/
function formatCredits(amount: number, locale: string = 'en-US'): string {
function formatCredits(amount: number, locale = 'en-US'): string {
return new Intl.NumberFormat(locale).format(amount);
}

View file

@ -4,8 +4,6 @@
* Types for credit/mana operations across all apps
*/
import type { OperationPricing, ManaBalance } from '@manacore/shared-subscription-types';
/**
* Credit balance with additional metadata
*/

View file

@ -1,4 +1,8 @@
import { ErrorCode, ERROR_CODE_TO_HTTP_STATUS, ERROR_CODE_RETRYABLE } from '../types/error-codes';
import {
type ErrorCode,
ERROR_CODE_TO_HTTP_STATUS,
ERROR_CODE_RETRYABLE,
} from '../types/error-codes';
/**
* Additional context that can be attached to errors.

View file

@ -7,7 +7,7 @@ import {
Logger,
} from '@nestjs/common';
import type { Request, Response } from 'express';
import { AppError } from '../errors/app-error';
import { type AppError } from '../errors/app-error';
import { isAppError, isCreditError, isRateLimitError } from '../guards/type-guards';
import { ErrorCode } from '../types/error-codes';

View file

@ -18,7 +18,6 @@
*/
import type {
Feedback,
CreateFeedbackInput,
FeedbackQueryParams,
FeedbackResponse,

View file

@ -1,5 +1,5 @@
import { createParamDecorator, ExecutionContext } from '@nestjs/common';
import { CurrentUserData } from '../types';
import { createParamDecorator, type ExecutionContext } from '@nestjs/common';
import { type CurrentUserData } from '../types';
/**
* Parameter decorator to extract the current user from the request.

View file

@ -4,7 +4,7 @@
* This package provides a unified Supabase client and common database utilities.
*/
import { createClient, SupabaseClient } from '@supabase/supabase-js';
import { createClient, type SupabaseClient } from '@supabase/supabase-js';
import type { SupabaseConfig } from '@manacore/shared-types';
export { SupabaseClient } from '@supabase/supabase-js';

View file

@ -111,11 +111,7 @@ export function createUserSettingsStore(config: UserSettingsStoreConfig): UserSe
/**
* Make an API request to the settings endpoint
*/
async function apiRequest<T>(
method: string,
path: string,
body?: object
): Promise<T | null> {
async function apiRequest<T>(method: string, path: string, body?: object): Promise<T | null> {
const token = await getAccessToken();
if (!token) {
console.warn('No access token available for settings API');

View file

@ -17,7 +17,7 @@ export type LocaleKey = keyof typeof locales;
*/
export function formatDate(
date: string | Date,
formatStr: string = 'PPP',
formatStr = 'PPP',
locale: LocaleKey = 'de'
): string {
const dateObj = typeof date === 'string' ? parseISO(date) : date;

View file

@ -93,7 +93,7 @@ export function formatDurationHumanReadable(seconds: number, locale: 'en' | 'de'
/**
* Format file size from bytes to human readable string
*/
export function formatFileSize(bytes: number, decimals: number = 1): string {
export function formatFileSize(bytes: number, decimals = 1): string {
if (bytes === 0) return '0 B';
if (!Number.isFinite(bytes) || bytes < 0) return '--';
@ -107,18 +107,14 @@ export function formatFileSize(bytes: number, decimals: number = 1): string {
/**
* Format number with thousands separator
*/
export function formatNumber(num: number, locale: string = 'de-DE'): string {
export function formatNumber(num: number, locale = 'de-DE'): string {
return num.toLocaleString(locale);
}
/**
* Format currency
*/
export function formatCurrency(
amount: number,
currency: string = 'EUR',
locale: string = 'de-DE'
): string {
export function formatCurrency(amount: number, currency = 'EUR', locale = 'de-DE'): string {
return new Intl.NumberFormat(locale, {
style: 'currency',
currency,
@ -128,11 +124,7 @@ export function formatCurrency(
/**
* Format percentage
*/
export function formatPercent(
value: number,
decimals: number = 0,
locale: string = 'de-DE'
): string {
export function formatPercent(value: number, decimals = 0, locale = 'de-DE'): string {
return new Intl.NumberFormat(locale, {
style: 'percent',
minimumFractionDigits: decimals,

View file

@ -21,7 +21,7 @@ export function capitalize(str: string): string {
/**
* Generate a random string ID
*/
export function generateId(length: number = 8): string {
export function generateId(length = 8): string {
const chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
let result = '';
for (let i = 0; i < length; i++) {