@gftdcojp/gftd-orm
Version:
Enterprise-grade real-time data platform with ksqlDB, inspired by Supabase architecture
143 lines • 3.36 kB
TypeScript
/**
* 匿名キーシステム - Supabase風の公開キー管理
*/
import { UserPayload } from './types';
/**
* キーの種類
*/
export declare enum KeyType {
ANON = "anon",
SERVICE_ROLE = "service_role"
}
/**
* キー設定
*/
interface KeyConfig {
key: string;
type: KeyType;
permissions: string[];
description: string;
createdAt: Date;
expiresAt?: Date;
isActive: boolean;
}
/**
* 匿名キー管理クラス
*/
export declare class AnonKeyManager {
private static instance;
private keys;
private keyPrefix;
private constructor();
/**
* シングルトンインスタンスを取得
*/
static getInstance(): AnonKeyManager;
/**
* デフォルトキーを初期化
*/
private initializeDefaultKeys;
/**
* キーを生成
*/
private generateKey;
/**
* キーを検証
*/
validateKey(key: string): KeyConfig | null;
/**
* キーからユーザーペイロードを作成
*/
createUserFromKey(key: string, userId?: string): UserPayload | null;
/**
* キーベースの認証を実行
*/
authenticateWithKey(key: string, userId?: string): {
success: boolean;
user?: UserPayload;
token?: string;
error?: string;
};
/**
* 権限をチェック
*/
checkPermission(key: string, permission: string): boolean;
/**
* 新しいキーを生成
*/
createKey(type: KeyType, permissions: string[], description: string, expiresAt?: Date): string;
/**
* キーを無効化
*/
revokeKey(key: string): boolean;
/**
* キー一覧を取得
*/
listKeys(): KeyConfig[];
/**
* 匿名キーを取得
*/
getAnonKey(): string | null;
/**
* サービスロールキーを取得
*/
getServiceRoleKey(): string | null;
/**
* 期限切れキーをクリーンアップ
*/
cleanupExpiredKeys(): void;
}
/**
* Express.js ミドルウェア: 匿名キー認証
*/
export declare function anonKeyAuthMiddleware(options?: {
requireAuth?: boolean;
requiredPermissions?: string[];
}): (req: any, res: any, next: any) => any;
/**
* 匿名キーシステムのヘルパー関数
*/
export declare const anonKeySystem: {
/**
* マネージャーインスタンスを取得
*/
manager: () => AnonKeyManager;
/**
* 匿名キーで認証
*/
authenticateAnon: (userId?: string) => {
success: boolean;
user?: UserPayload;
token?: string;
error?: string;
};
/**
* サービスロールキーで認証
*/
authenticateService: (userId?: string) => {
success: boolean;
user?: UserPayload;
token?: string;
error?: string;
};
/**
* 権限チェック
*/
checkPermission: (key: string, permission: string) => boolean;
/**
* 新しいキーを作成
*/
createKey: (type: KeyType, permissions: string[], description: string, expiresAt?: Date) => string;
/**
* キーを無効化
*/
revokeKey: (key: string) => boolean;
/**
* 公開キーを取得
*/
getPublicKeys: () => {
anonKey: string | null;
};
};
export {};
//# sourceMappingURL=anon-key-system.d.ts.map