feat: scaffold supabase multi-tenant backend

This commit is contained in:
Codex
2026-06-21 21:54:43 +08:00
commit c9c767c7bd
99 changed files with 36660 additions and 0 deletions

12
packages/config/package-lock.json generated Normal file
View File

@@ -0,0 +1,12 @@
{
"name": "@tiku-saas/config",
"version": "0.1.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@tiku-saas/config",
"version": "0.1.0"
}
}
}

View File

@@ -0,0 +1,8 @@
{
"name": "@tiku-saas/config",
"version": "0.1.0",
"private": true,
"type": "module",
"main": "src/index.ts",
"types": "src/index.ts"
}

View File

@@ -0,0 +1,43 @@
import fs from 'node:fs';
import path from 'node:path';
export const DEFAULT_DATABASE_URL = 'postgresql://postgres:postgres@127.0.0.1:54322/postgres';
export const DEFAULT_TENANT_ID = '00000000-0000-0000-0000-000000000001';
export const DEFAULT_TENANT_SLUG = 'master';
export const DEFAULT_TENANT_NAME = '升本刷题通主租户';
export function loadDotenv(cwd = process.cwd()) {
const envPath = path.resolve(cwd, '.env');
if (!fs.existsSync(envPath))
return;
const content = fs.readFileSync(envPath, 'utf8');
for (const line of content.split(/\r?\n/)) {
const trimmed = line.trim();
if (!trimmed || trimmed.startsWith('#'))
continue;
const idx = trimmed.indexOf('=');
if (idx === -1)
continue;
const key = trimmed.slice(0, idx).trim();
const value = trimmed.slice(idx + 1).trim().replace(/^"|"$/g, '');
if (!process.env[key])
process.env[key] = value;
}
}
export function envString(key, fallback) {
return process.env[key] || fallback;
}
export function envNumber(key, fallback) {
const value = Number(process.env[key]);
return Number.isFinite(value) ? value : fallback;
}
export function envBoolean(key, fallback = false) {
const value = process.env[key];
if (value === undefined)
return fallback;
return ['true', '1', 'yes', 'y', 'on'].includes(value.toLowerCase());
}
export function envList(key, fallback = '') {
return (process.env[key] || fallback)
.split(',')
.map(value => value.trim())
.filter(Boolean);
}

View File

@@ -0,0 +1,45 @@
import fs from 'node:fs';
import path from 'node:path';
export const DEFAULT_DATABASE_URL = 'postgresql://postgres:postgres@127.0.0.1:54322/postgres';
export const DEFAULT_TENANT_ID = '00000000-0000-0000-0000-000000000001';
export const DEFAULT_TENANT_SLUG = 'master';
export const DEFAULT_TENANT_NAME = '升本刷题通主租户';
export function loadDotenv(cwd = process.cwd()) {
const envPath = path.resolve(cwd, '.env');
if (!fs.existsSync(envPath)) return;
const content = fs.readFileSync(envPath, 'utf8');
for (const line of content.split(/\r?\n/)) {
const trimmed = line.trim();
if (!trimmed || trimmed.startsWith('#')) continue;
const idx = trimmed.indexOf('=');
if (idx === -1) continue;
const key = trimmed.slice(0, idx).trim();
const value = trimmed.slice(idx + 1).trim().replace(/^"|"$/g, '');
if (!process.env[key]) process.env[key] = value;
}
}
export function envString(key: string, fallback: string) {
return process.env[key] || fallback;
}
export function envNumber(key: string, fallback: number) {
const value = Number(process.env[key]);
return Number.isFinite(value) ? value : fallback;
}
export function envBoolean(key: string, fallback = false) {
const value = process.env[key];
if (value === undefined) return fallback;
return ['true', '1', 'yes', 'y', 'on'].includes(value.toLowerCase());
}
export function envList(key: string, fallback = '') {
return (process.env[key] || fallback)
.split(',')
.map(value => value.trim())
.filter(Boolean);
}