/** * Payment-icon serving — Phase 5.x icon hosting. * * Backend wraps the `idn-finlogos` npm package and serves its SVGs at * `/assets/payment-icons/.svg`. The catalog endpoint returns * `icon_url: "/assets/payment-icons/.svg"`; the client app fetches + * caches with `flutter_cache_manager`. No bundled icons in the app anymore. * * License: idn-finlogos ships under CC-BY-NC-4.0 for the assets (per-brand * permission still required for production use). Code under MIT. See * `backend/node_modules/idn-finlogos/LICENSE-ASSETS` + `NOTICE`. * * Slug set is loaded ONCE at module init from `dist/icons/*.svg` filenames so * the request path stays a single Set.has() lookup. Bump the package version * to add/replace icons; restart the backend to refresh the slug set. */ import { readdirSync } from 'fs' import { dirname, join } from 'path' import { createRequire } from 'module' const require = createRequire(import.meta.url) const PACKAGE_DIR = dirname(require.resolve('idn-finlogos/package.json')) const ICONS_DIR = join(PACKAGE_DIR, 'dist', 'icons') const SLUGS = new Set( readdirSync(ICONS_DIR) .filter((f) => f.endsWith('.svg')) .map((f) => f.slice(0, -4)), ) export const hasIconSlug = (slug) => typeof slug === 'string' && SLUGS.has(slug) export const resolveIconPath = (slug) => { if (!hasIconSlug(slug)) return null return join(ICONS_DIR, `${slug}.svg`) } /** Sorted slug list for the CC dropdown. */ export const listIconSlugs = () => Array.from(SLUGS).sort()