import type {PluginGameSourceDraft, XLibraryPlugin} from '@xlibrary/plugin-sdk'; function getExternalId(input: {externalId?: string; url?: string}): string { if (input.externalId?.trim()) return input.externalId.trim(); const url = input.url ? new URL(input.url) : undefined; const slug = url?.pathname.split('/').filter(Boolean).at(-1); if (!slug) throw new Error('A game id or HTTPS URL is required'); return decodeURIComponent(slug); } function createDraft(input: {externalId?: string; url?: string; name?: string}): PluginGameSourceDraft { const externalId = getExternalId(input); return { externalId, canonicalUrl: input.url || `https://catalog.example/games/${encodeURIComponent(externalId)}`, name: input.name || `Demo Game (${externalId})`, tags: [], screenshotUrls: [], isPartial: false, missingFields: [], metadata: {}, }; } const plugin: XLibraryPlugin = { invoke(invocation) { if (invocation.method === 'game-sources.search') { return { candidates: [{ identity: { externalId: 'demo-game', canonicalUrl: 'https://catalog.example/games/demo-game', }, title: `Demo result for ${invocation.payload.query}`, summary: 'Replace this deterministic result with your catalog request.', }], }; } if (invocation.method === 'game-sources.resolve') { return createDraft(invocation.payload); } throw new Error(`Unsupported plugin method: ${invocation.method}`); }, }; export default plugin;