feat: initialisation projet Hono.js + TypeScript + Vitest

This commit is contained in:
Hermann_Kitio 2026-04-16 06:37:25 +03:00
parent b06970c9ae
commit 708517edef
13 changed files with 3125 additions and 131 deletions

0
src/controllers/.gitkeep Normal file
View file

14
src/index.ts Normal file
View file

@ -0,0 +1,14 @@
import { Hono } from 'hono'
import { serve } from '@hono/node-server'
const app = new Hono()
app.get('/', (c) => {
return c.json({ message: 'Expria API — OK' }, 200)
})
const port = Number(process.env.PORT) || 3000
serve({ fetch: app.fetch, port }, () => {
console.log(`Expria API listening on port ${port}`)
})

View file

74
src/lib/access.ts Normal file
View file

@ -0,0 +1,74 @@
export type Plan = 'free' | 'standard' | 'premium'
export type Feature =
| 'oral_t2_live'
| 'detailed_report'
| 'tips'
| 'dashboard'
| 'exam_mode'
| 'pattern_analysis'
| 'preparation_index'
| 'basic_report'
export const PLANS = {
free: {
simulations_lifetime: 5,
oral_t2_live: false,
detailed_report: false,
tips: false,
dashboard: false,
exam_mode: false,
pattern_analysis: false,
preparation_index: false,
},
standard: {
simulations_lifetime: null,
oral_t2_live: false,
detailed_report: true,
tips: true,
dashboard: true,
exam_mode: false,
pattern_analysis: false,
preparation_index: false,
},
premium: {
simulations_lifetime: null,
oral_t2_live: true,
detailed_report: true,
tips: true,
dashboard: true,
exam_mode: true,
pattern_analysis: true,
preparation_index: true,
},
}
export function getPlanPermissions(plan: Plan) {
const perms = PLANS[plan]
if (!perms) {
throw new Error(`Plan inconnu : ${plan}`)
}
return perms
}
export function canUserSimulate(user: { plan: string; simulations_used: number }): {
allowed: boolean
reason?: string
} {
if (!(user.plan in PLANS)) {
return { allowed: false, reason: 'invalid_plan' }
}
const plan = user.plan as Plan
const perms = PLANS[plan]
if (perms.simulations_lifetime !== null && user.simulations_used >= perms.simulations_lifetime) {
return { allowed: false, reason: 'quota_reached' }
}
return { allowed: true }
}
export function checkFeatureAccess(plan: Plan, feature: Feature): boolean {
if (feature === 'basic_report') return true
const perms = PLANS[plan]
if (!perms) return false
return perms[feature as keyof typeof perms] === true
}

0
src/middleware/.gitkeep Normal file
View file

0
src/routes/.gitkeep Normal file
View file

0
src/types/.gitkeep Normal file
View file