- 删除 SimCFApi / WMAILHUB_SIM_CF / isRealOAuth / POST /api/oauth/cloudflare/sim/approve - 删除前端 OAuthSim 模拟授权页与 /oauth/sim/authorize 路由;账号页「添加账号」整页跳 Cloudflare - 迁移 0005 删除 cf_sim_resources 表 - 未配置 CF_OAUTH_CLIENT_ID/SECRET 时 start/callback 一律 503(不再降级出假账号假资源) - 修 OAuth 回调端点:跨站重定向不携带 SameSite=Strict 会话 cookie,改为由一次性 state 承担 CSRF 防护 - 测试改用 tests/cf-mock.ts 在 fetch 层拦截 Cloudflare API,断言真实 HTTP 调用(72/72 通过) - 本地 dev 无账号时只拉起 Console 并提示人工授权,不再自动造账号
83 lines
3.0 KiB
TypeScript
83 lines
3.0 KiB
TypeScript
/**
|
|
* Console 运行环境类型:同时兼容 Cloudflare Workers 与本地 Bun 运行时。
|
|
* D1Database / R2Bucket 为本项目实际用到的最小接口子集。
|
|
*/
|
|
|
|
/** # 成员变量: D1 预处理语句最小接口 **/
|
|
export interface D1PreparedStatement {
|
|
bind(...values: unknown[]): D1PreparedStatement;
|
|
first<T = Record<string, unknown>>(colName?: string): Promise<T | null>;
|
|
all<T = Record<string, unknown>>(): Promise<{ results: T[]; success?: boolean; meta?: unknown }>;
|
|
run(): Promise<{ success: boolean; meta: { changes?: number; last_row_id?: number } }>;
|
|
}
|
|
|
|
/** # 成员变量: D1 数据库最小接口 **/
|
|
export interface D1Database {
|
|
prepare(query: string): D1PreparedStatement;
|
|
batch<T = unknown>(statements: D1PreparedStatement[]): Promise<T[]>;
|
|
exec(query: string): Promise<unknown>;
|
|
}
|
|
|
|
/** # 成员变量: R2 对象最小接口 **/
|
|
export interface R2ObjectBody {
|
|
arrayBuffer(): Promise<ArrayBuffer>;
|
|
text(): Promise<string>;
|
|
json(): Promise<unknown>;
|
|
}
|
|
|
|
/** # 成员变量: R2 桶最小接口 **/
|
|
export interface R2Bucket {
|
|
put(
|
|
key: string,
|
|
value: ArrayBuffer | Uint8Array | string | ReadableStream | Blob,
|
|
options?: { httpMetadata?: Record<string, string> },
|
|
): Promise<unknown>;
|
|
get(key: string): Promise<R2ObjectBody | null>;
|
|
delete(keys: string | string[]): Promise<void>;
|
|
head(key: string): Promise<{ key: string; size: number } | null>;
|
|
}
|
|
|
|
/** # 成员变量: Console env 绑定 **/
|
|
export interface Env {
|
|
/** D1 数据库(本地运行时由 LocalD1 提供) **/
|
|
DB: D1Database;
|
|
/** R2 桶(本地运行时由 LocalR2 提供) **/
|
|
R2: R2Bucket;
|
|
/** Workers 静态资源绑定(本地运行时为空,由 Bun 直接读文件) **/
|
|
ASSETS?: { fetch(request: Request): Promise<Response> };
|
|
/** 会话/加密主密钥;未提供时自动生成并持久化到 settings 表 **/
|
|
SESSION_SECRET?: string;
|
|
/** Console 对外地址(用于 OAuth redirect_uri 与展示) **/
|
|
PUBLIC_BASE_URL?: string;
|
|
/** Cloudflare OAuth 客户端;两个都配置时走真实 OAuth,否则进入本地 sim 模式 **/
|
|
CF_OAUTH_CLIENT_ID?: string;
|
|
CF_OAUTH_CLIENT_SECRET?: string;
|
|
CF_OAUTH_REDIRECT_URI?: string;
|
|
/** 本地联调:允许 webhook endpoint 指向私网/localhost("1"),生产严禁开启 **/
|
|
WMAILHUB_ALLOW_PRIVATE_WEBHOOKS?: string;
|
|
}
|
|
|
|
/** # 成员变量: Workers 执行上下文最小接口 **/
|
|
export interface WorkersExecutionContext {
|
|
waitUntil(promise: Promise<unknown>): void;
|
|
passThroughOnException(): void;
|
|
}
|
|
|
|
/** # 成员变量: Workers Cron 触发事件最小接口 **/
|
|
export interface ScheduledEvent {
|
|
cron: string;
|
|
scheduledTime: number;
|
|
}
|
|
|
|
/** # 成员变量: Hono context 变量 **/
|
|
export interface AppVars {
|
|
/** 已登录用户 ID(cookie 会话) **/
|
|
userId?: string;
|
|
/** internal 路由中已读出的原始请求体(workerAuth 中间件缓存) **/
|
|
rawBody?: Uint8Array;
|
|
/** internal 路由中通过校验的 worker credential id **/
|
|
workerCredentialId?: string;
|
|
/** internal 路由中 credential 所属的 Console 账号 id **/
|
|
workerAccountId?: string;
|
|
}
|