fp/services/our/src/utils/patreonTiers.ts
CJ_Clippy 5f3902d1e2
Some checks failed
ci / build (push) Failing after 0s
ci / Tests & Checks (push) Failing after 1s
auto set admin
2025-06-17 10:44:05 -08:00

50 lines
1.5 KiB
TypeScript

import { PatreonUserResponse, RoleName, PatreonIncluded } from '../types'
export const PatreonTiers = [
{ name: 'ArchiveSupporter', id: '8154170', role: 'supporterTier1' },
{ name: 'StealthSupporter', id: '9561793', role: 'supporterTier1' },
{ name: 'TuneItUp', id: '9184994', role: 'supporterTier2' },
{ name: 'MaxQ', id: '22529959', role: 'supporterTier3' },
{ name: 'ArchiveCollector', id: '8154171', role: 'supporterTier4' },
{ name: 'AdvancedArchiveSupporter', id: '8686045', role: 'supporterTier4' },
{ name: 'QuantumSupporter', id: '8694826', role: 'supporterTier5' },
{ name: 'SneakyQuantumSupporter', id: '9560538', role: 'supporterTier5' },
{ name: 'LuberPlusPlus', id: '8686022', role: 'supporterTier6' }
];
const admins = [
'20828619' // CJ_Clippy
]
const TierIdToRoleMap = new Map(
PatreonTiers.map(tier => [tier.id, tier.role])
);
export function getRoles(data: PatreonUserResponse): string[] {
const roles = new Set<string>(['user']);
// Add admin role if the user's Patreon ID is in the admins list
if (admins.includes(data.data.id)) {
roles.add('admin');
}
const entitledTierIds = data.included
?.filter((item): item is PatreonIncluded => item.type === 'member')
.flatMap(member =>
member.relationships?.currently_entitled_tiers?.data?.map(tier => tier.id) || []
) ?? [];
for (const tierId of entitledTierIds) {
const role = TierIdToRoleMap.get(tierId);
if (role) roles.add(role);
}
return [...roles];
}