const { TABLE_OPTIONS, column: c, index: i, uniqueIndex: u } = require('./helpers'); const table = (name, columns, primaryKey, indexes = []) => ({ name, group: 'oauth', wrapped: false, columns, primaryKey, indexes, foreignKeys: [], options: TABLE_OPTIONS }); const oauthTables = [ table('oauth_clients',[c('id','BIGINT UNSIGNED NOT NULL AUTO_INCREMENT','bigint unsigned',false,null,'auto_increment'),c('client_id','VARCHAR(128) NOT NULL','varchar(128)',false),c('client_name','VARCHAR(200) NOT NULL','varchar(200)',false),c('description','TEXT DEFAULT NULL','text',true),c('homepage_url','VARCHAR(500) DEFAULT NULL','varchar(500)',true),c('redirect_uris','JSON NOT NULL','json',false),c('allowed_scopes','JSON NOT NULL','json',false),c('public_client','TINYINT(1) NOT NULL DEFAULT 1','tinyint(1)',false,'1'),c('require_pkce','TINYINT(1) NOT NULL DEFAULT 1','tinyint(1)',false,'1'),c('client_secret','VARCHAR(256) DEFAULT NULL','varchar(256)',true),c('icon_filename','VARCHAR(200) DEFAULT NULL','varchar(200)',true),c('vip_days_balance','INT NOT NULL DEFAULT 0','int',false,'0'),c('is_active','TINYINT(1) NOT NULL DEFAULT 1','tinyint(1)',false,'1'),c('created_at','BIGINT UNSIGNED NOT NULL','bigint unsigned',false),c('updated_at','BIGINT UNSIGNED NOT NULL','bigint unsigned',false)],['id'],[u('uq_oauth_clients_client_id',['client_id']),i('idx_client_id',['client_id']),i('idx_is_active',['is_active'])]), table('oauth_app_stats',[c('id','BIGINT UNSIGNED NOT NULL AUTO_INCREMENT','bigint unsigned',false,null,'auto_increment'),c('client_id','VARCHAR(128) NOT NULL','varchar(128)',false),c('event_type','VARCHAR(32) NOT NULL','varchar(32)',false),c('user_id','VARCHAR(160) DEFAULT NULL','varchar(160)',true),c('metadata','JSON DEFAULT NULL','json',true),c('created_at','BIGINT UNSIGNED NOT NULL','bigint unsigned',false)],['id'],[i('idx_client_event',['client_id','event_type','created_at']),i('idx_created_at',['created_at'])]), table('oauth_vip_grants',[c('id','BIGINT UNSIGNED NOT NULL AUTO_INCREMENT','bigint unsigned',false,null,'auto_increment'),c('client_id','VARCHAR(128) NOT NULL','varchar(128)',false),c('user_id','VARCHAR(160) NOT NULL','varchar(160)',false),c('user_type','VARCHAR(16) NOT NULL','varchar(16)',false),c('user_id_only','VARCHAR(128) NOT NULL','varchar(128)',false),c('days_granted','INT UNSIGNED NOT NULL','int unsigned',false),c('access_key_value','VARCHAR(128) NOT NULL','varchar(128)',false),c('expires_at','DATETIME NOT NULL','datetime',false),c('granted_at','BIGINT UNSIGNED NOT NULL','bigint unsigned',false),c('revoked_at','BIGINT UNSIGNED DEFAULT NULL','bigint unsigned',true)],['id'],[i('idx_client_id',['client_id','granted_at']),i('idx_user_id',['user_id','granted_at']),i('idx_access_key',['access_key_value'])]), table('oauth_authorization_codes',[c('code_hash','CHAR(64) NOT NULL','char(64)',false),c('client_id','VARCHAR(191) NOT NULL','varchar(191)',false),c('user_id','VARCHAR(255) NOT NULL','varchar(255)',false),c('user_type',"ENUM('oauth', 'bip39') NOT NULL",'enum',false),c('session_id','VARCHAR(255) DEFAULT NULL','varchar(255)',true),c('scopes','TEXT NOT NULL','text',false),c('redirect_uri','TEXT NOT NULL','text',false),c('code_challenge','VARCHAR(255) DEFAULT NULL','varchar(255)',true),c('code_challenge_method','VARCHAR(20) DEFAULT NULL','varchar(20)',true),c('expires_at','DATETIME NOT NULL','datetime',false),c('used_at','DATETIME DEFAULT NULL','datetime',true),c('created_at','DATETIME DEFAULT CURRENT_TIMESTAMP','datetime',true,'CURRENT_TIMESTAMP')],['code_hash'],[i('idx_oauth_codes_client',['client_id']),i('idx_oauth_codes_user',['user_id','user_type']),i('idx_oauth_codes_expiry',['expires_at'])]), table('oauth_authorization_requests',[c('request_hash','CHAR(64) NOT NULL','char(64)',false),c('client_id','VARCHAR(191) NOT NULL','varchar(191)',false),c('redirect_uri','TEXT NOT NULL','text',false),c('response_type',"VARCHAR(20) NOT NULL DEFAULT 'code'",'varchar(20)',false,'code'),c('scopes','TEXT NOT NULL','text',false),c('state','TEXT','text',true),c('code_challenge','VARCHAR(255) DEFAULT NULL','varchar(255)',true),c('code_challenge_method','VARCHAR(20) DEFAULT NULL','varchar(20)',true),c('expires_at','DATETIME NOT NULL','datetime',false),c('consumed_at','DATETIME DEFAULT NULL','datetime',true),c('decision',"ENUM('approved', 'rejected') DEFAULT NULL",'enum',true),c('created_at','DATETIME DEFAULT CURRENT_TIMESTAMP','datetime',true,'CURRENT_TIMESTAMP'),c('last_seen_at','DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP','datetime',true,'CURRENT_TIMESTAMP','on update CURRENT_TIMESTAMP')],['request_hash'],[i('idx_oauth_requests_client',['client_id']),i('idx_oauth_requests_expiry',['expires_at']),i('idx_oauth_requests_consumed',['consumed_at'])]), table('oauth_access_tokens',[c('token_hash','CHAR(64) NOT NULL','char(64)',false),c('client_id','VARCHAR(191) NOT NULL','varchar(191)',false),c('user_id','VARCHAR(255) NOT NULL','varchar(255)',false),c('user_type',"ENUM('oauth', 'bip39') NOT NULL",'enum',false),c('session_id','VARCHAR(255) DEFAULT NULL','varchar(255)',true),c('scopes','TEXT NOT NULL','text',false),c('expires_at','DATETIME NOT NULL','datetime',false),c('revoked_at','DATETIME DEFAULT NULL','datetime',true),c('authorization_code_hash','CHAR(64) DEFAULT NULL','char(64)',true),c('created_at','DATETIME DEFAULT CURRENT_TIMESTAMP','datetime',true,'CURRENT_TIMESTAMP'),c('last_used_at','DATETIME DEFAULT CURRENT_TIMESTAMP','datetime',true,'CURRENT_TIMESTAMP')],['token_hash'],[i('idx_oauth_tokens_client',['client_id']),i('idx_oauth_tokens_user',['user_id','user_type']),i('idx_oauth_tokens_expiry',['expires_at'])]), ]; module.exports = { oauthTables };