diff --git a/bridge/.env.example b/bridge/.env.example new file mode 100644 index 0000000..438cc21 --- /dev/null +++ b/bridge/.env.example @@ -0,0 +1,22 @@ +# Bridge server port (default: 3200) +PORT=3200 + +# Host/domain used when no Host header is present (dev fallback) +DEFAULT_HOST=localhost + +# Absolute path to config/domains/ directory +DOMAINS_CONFIG_PATH=../config/domains + +# Redis connection URL (optional; if unset, in-process Map cache is used) +REDIS_URL=redis://127.0.0.1:6379 + +# Cache TTLs (seconds) +CACHE_FRESH_TTL=60 +CACHE_STALE_TTL=300 + +# Rate limit: max requests per window per IP +RATE_LIMIT_MAX=100 +RATE_LIMIT_WINDOW_MS=60000 + +# Log level: fatal | error | warn | info | debug | trace +LOG_LEVEL=info diff --git a/bridge/.gitignore b/bridge/.gitignore new file mode 100644 index 0000000..deed335 --- /dev/null +++ b/bridge/.gitignore @@ -0,0 +1,3 @@ +node_modules/ +dist/ +.env diff --git a/bridge/package-lock.json b/bridge/package-lock.json new file mode 100644 index 0000000..09eabc9 --- /dev/null +++ b/bridge/package-lock.json @@ -0,0 +1,1255 @@ +{ + "name": "news-bridge", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "news-bridge", + "version": "1.0.0", + "dependencies": { + "@fastify/cors": "^9.0.1", + "@fastify/rate-limit": "^9.1.0", + "fastify": "^4.28.1", + "ioredis": "^5.4.1" + }, + "devDependencies": { + "@types/node": "^20.14.0", + "tsx": "^4.15.0", + "typescript": "^5.4.5" + } + }, + "node_modules/@esbuild/aix-ppc64": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.27.4.tgz", + "integrity": "sha512-cQPwL2mp2nSmHHJlCyoXgHGhbEPMrEEU5xhkcy3Hs/O7nGZqEpZ2sUtLaL9MORLtDfRvVl2/3PAuEkYZH0Ty8Q==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "aix" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.27.4.tgz", + "integrity": "sha512-X9bUgvxiC8CHAGKYufLIHGXPJWnr0OCdR0anD2e21vdvgCI8lIfqFbnoeOz7lBjdrAGUhqLZLcQo6MLhTO2DKQ==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm64": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.27.4.tgz", + "integrity": "sha512-gdLscB7v75wRfu7QSm/zg6Rx29VLdy9eTr2t44sfTW7CxwAtQghZ4ZnqHk3/ogz7xao0QAgrkradbBzcqFPasw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-x64": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.27.4.tgz", + "integrity": "sha512-PzPFnBNVF292sfpfhiyiXCGSn9HZg5BcAz+ivBuSsl6Rk4ga1oEXAamhOXRFyMcjwr2DVtm40G65N3GLeH1Lvw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-arm64": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.27.4.tgz", + "integrity": "sha512-b7xaGIwdJlht8ZFCvMkpDN6uiSmnxxK56N2GDTMYPr2/gzvfdQN8rTfBsvVKmIVY/X7EM+/hJKEIbbHs9oA4tQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-x64": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.27.4.tgz", + "integrity": "sha512-sR+OiKLwd15nmCdqpXMnuJ9W2kpy0KigzqScqHI3Hqwr7IXxBp3Yva+yJwoqh7rE8V77tdoheRYataNKL4QrPw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-arm64": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.27.4.tgz", + "integrity": "sha512-jnfpKe+p79tCnm4GVav68A7tUFeKQwQyLgESwEAUzyxk/TJr4QdGog9sqWNcUbr/bZt/O/HXouspuQDd9JxFSw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-x64": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.27.4.tgz", + "integrity": "sha512-2kb4ceA/CpfUrIcTUl1wrP/9ad9Atrp5J94Lq69w7UwOMolPIGrfLSvAKJp0RTvkPPyn6CIWrNy13kyLikZRZQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.27.4.tgz", + "integrity": "sha512-aBYgcIxX/wd5n2ys0yESGeYMGF+pv6g0DhZr3G1ZG4jMfruU9Tl1i2Z+Wnj9/KjGz1lTLCcorqE2viePZqj4Eg==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm64": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.27.4.tgz", + "integrity": "sha512-7nQOttdzVGth1iz57kxg9uCz57dxQLHWxopL6mYuYthohPKEK0vU0C3O21CcBK6KDlkYVcnDXY099HcCDXd9dA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ia32": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.27.4.tgz", + "integrity": "sha512-oPtixtAIzgvzYcKBQM/qZ3R+9TEUd1aNJQu0HhGyqtx6oS7qTpvjheIWBbes4+qu1bNlo2V4cbkISr8q6gRBFA==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-loong64": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.27.4.tgz", + "integrity": "sha512-8mL/vh8qeCoRcFH2nM8wm5uJP+ZcVYGGayMavi8GmRJjuI3g1v6Z7Ni0JJKAJW+m0EtUuARb6Lmp4hMjzCBWzA==", + "cpu": [ + "loong64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-mips64el": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.27.4.tgz", + "integrity": "sha512-1RdrWFFiiLIW7LQq9Q2NES+HiD4NyT8Itj9AUeCl0IVCA459WnPhREKgwrpaIfTOe+/2rdntisegiPWn/r/aAw==", + "cpu": [ + "mips64el" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ppc64": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.27.4.tgz", + "integrity": "sha512-tLCwNG47l3sd9lpfyx9LAGEGItCUeRCWeAx6x2Jmbav65nAwoPXfewtAdtbtit/pJFLUWOhpv0FpS6GQAmPrHA==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-riscv64": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.27.4.tgz", + "integrity": "sha512-BnASypppbUWyqjd1KIpU4AUBiIhVr6YlHx/cnPgqEkNoVOhHg+YiSVxM1RLfiy4t9cAulbRGTNCKOcqHrEQLIw==", + "cpu": [ + "riscv64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-s390x": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.27.4.tgz", + "integrity": "sha512-+eUqgb/Z7vxVLezG8bVB9SfBie89gMueS+I0xYh2tJdw3vqA/0ImZJ2ROeWwVJN59ihBeZ7Tu92dF/5dy5FttA==", + "cpu": [ + "s390x" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-x64": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.27.4.tgz", + "integrity": "sha512-S5qOXrKV8BQEzJPVxAwnryi2+Iq5pB40gTEIT69BQONqR7JH1EPIcQ/Uiv9mCnn05jff9umq/5nqzxlqTOg9NA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-arm64": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.27.4.tgz", + "integrity": "sha512-xHT8X4sb0GS8qTqiwzHqpY00C95DPAq7nAwX35Ie/s+LO9830hrMd3oX0ZMKLvy7vsonee73x0lmcdOVXFzd6Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-x64": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.27.4.tgz", + "integrity": "sha512-RugOvOdXfdyi5Tyv40kgQnI0byv66BFgAqjdgtAKqHoZTbTF2QqfQrFwa7cHEORJf6X2ht+l9ABLMP0dnKYsgg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-arm64": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.27.4.tgz", + "integrity": "sha512-2MyL3IAaTX+1/qP0O1SwskwcwCoOI4kV2IBX1xYnDDqthmq5ArrW94qSIKCAuRraMgPOmG0RDTA74mzYNQA9ow==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-x64": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.27.4.tgz", + "integrity": "sha512-u8fg/jQ5aQDfsnIV6+KwLOf1CmJnfu1ShpwqdwC0uA7ZPwFws55Ngc12vBdeUdnuWoQYx/SOQLGDcdlfXhYmXQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openharmony-arm64": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.27.4.tgz", + "integrity": "sha512-JkTZrl6VbyO8lDQO3yv26nNr2RM2yZzNrNHEsj9bm6dOwwu9OYN28CjzZkH57bh4w0I2F7IodpQvUAEd1mbWXg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/sunos-x64": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.27.4.tgz", + "integrity": "sha512-/gOzgaewZJfeJTlsWhvUEmUG4tWEY2Spp5M20INYRg2ZKl9QPO3QEEgPeRtLjEWSW8FilRNacPOg8R1uaYkA6g==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-arm64": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.27.4.tgz", + "integrity": "sha512-Z9SExBg2y32smoDQdf1HRwHRt6vAHLXcxD2uGgO/v2jK7Y718Ix4ndsbNMU/+1Qiem9OiOdaqitioZwxivhXYg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-ia32": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.27.4.tgz", + "integrity": "sha512-DAyGLS0Jz5G5iixEbMHi5KdiApqHBWMGzTtMiJ72ZOLhbu/bzxgAe8Ue8CTS3n3HbIUHQz/L51yMdGMeoxXNJw==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-x64": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.27.4.tgz", + "integrity": "sha512-+knoa0BDoeXgkNvvV1vvbZX4+hizelrkwmGJBdT17t8FNPwG2lKemmuMZlmaNQ3ws3DKKCxpb4zRZEIp3UxFCg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@fastify/ajv-compiler": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/@fastify/ajv-compiler/-/ajv-compiler-3.6.0.tgz", + "integrity": "sha512-LwdXQJjmMD+GwLOkP7TVC68qa+pSSogeWWmznRJ/coyTcfe9qA05AHFSe1eZFwK6q+xVRpChnvFUkf1iYaSZsQ==", + "license": "MIT", + "dependencies": { + "ajv": "^8.11.0", + "ajv-formats": "^2.1.1", + "fast-uri": "^2.0.0" + } + }, + "node_modules/@fastify/cors": { + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/@fastify/cors/-/cors-9.0.1.tgz", + "integrity": "sha512-YY9Ho3ovI+QHIL2hW+9X4XqQjXLjJqsU+sMV/xFsxZkE8p3GNnYVFpoOxF7SsP5ZL76gwvbo3V9L+FIekBGU4Q==", + "license": "MIT", + "dependencies": { + "fastify-plugin": "^4.0.0", + "mnemonist": "0.39.6" + } + }, + "node_modules/@fastify/error": { + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/@fastify/error/-/error-3.4.1.tgz", + "integrity": "sha512-wWSvph+29GR783IhmvdwWnN4bUxTD01Vm5Xad4i7i1VuAOItLvbPAb69sb0IQ2N57yprvhNIwAP5B6xfKTmjmQ==", + "license": "MIT" + }, + "node_modules/@fastify/fast-json-stringify-compiler": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/@fastify/fast-json-stringify-compiler/-/fast-json-stringify-compiler-4.3.0.tgz", + "integrity": "sha512-aZAXGYo6m22Fk1zZzEUKBvut/CIIQe/BapEORnxiD5Qr0kPHqqI69NtEMCme74h+at72sPhbkb4ZrLd1W3KRLA==", + "license": "MIT", + "dependencies": { + "fast-json-stringify": "^5.7.0" + } + }, + "node_modules/@fastify/merge-json-schemas": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/@fastify/merge-json-schemas/-/merge-json-schemas-0.1.1.tgz", + "integrity": "sha512-fERDVz7topgNjtXsJTTW1JKLy0rhuLRcquYqNR9rF7OcVpCa2OVW49ZPDIhaRRCaUuvVxI+N416xUoF76HNSXA==", + "license": "MIT", + "dependencies": { + "fast-deep-equal": "^3.1.3" + } + }, + "node_modules/@fastify/rate-limit": { + "version": "9.1.0", + "resolved": "https://registry.npmjs.org/@fastify/rate-limit/-/rate-limit-9.1.0.tgz", + "integrity": "sha512-h5dZWCkuZXN0PxwqaFQLxeln8/LNwQwH9popywmDCFdKfgpi4b/HoMH1lluy6P+30CG9yzzpSpwTCIPNB9T1JA==", + "license": "MIT", + "dependencies": { + "@lukeed/ms": "^2.0.1", + "fastify-plugin": "^4.0.0", + "toad-cache": "^3.3.1" + } + }, + "node_modules/@ioredis/commands": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/@ioredis/commands/-/commands-1.5.1.tgz", + "integrity": "sha512-JH8ZL/ywcJyR9MmJ5BNqZllXNZQqQbnVZOqpPQqE1vHiFgAw4NHbvE0FOduNU8IX9babitBT46571OnPTT0Zcw==", + "license": "MIT" + }, + "node_modules/@lukeed/ms": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/@lukeed/ms/-/ms-2.0.2.tgz", + "integrity": "sha512-9I2Zn6+NJLfaGoz9jN3lpwDgAYvfGeNYdbAIjJOqzs4Tpc+VU3Jqq4IofSUBKajiDS8k9fZIg18/z13mpk1bsA==", + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/@pinojs/redact": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/@pinojs/redact/-/redact-0.4.0.tgz", + "integrity": "sha512-k2ENnmBugE/rzQfEcdWHcCY+/FM3VLzH9cYEsbdsoqrvzAKRhUZeRNhAZvB8OitQJ1TBed3yqWtdjzS6wJKBwg==", + "license": "MIT" + }, + "node_modules/@types/node": { + "version": "20.19.37", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.19.37.tgz", + "integrity": "sha512-8kzdPJ3FsNsVIurqBs7oodNnCEVbni9yUEkaHbgptDACOPW04jimGagZ51E6+lXUwJjgnBw+hyko/lkFWCldqw==", + "dev": true, + "license": "MIT", + "dependencies": { + "undici-types": "~6.21.0" + } + }, + "node_modules/abstract-logging": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/abstract-logging/-/abstract-logging-2.0.1.tgz", + "integrity": "sha512-2BjRTZxTPvheOvGbBslFSYOUkr+SjPtOnrLP33f+VIWLzezQpZcqVg7ja3L4dBXmzzgwT+a029jRx5PCi3JuiA==", + "license": "MIT" + }, + "node_modules/ajv": { + "version": "8.18.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.18.0.tgz", + "integrity": "sha512-PlXPeEWMXMZ7sPYOHqmDyCJzcfNrUr3fGNKtezX14ykXOEIvyK81d+qydx89KY5O71FKMPaQ2vBfBFI5NHR63A==", + "license": "MIT", + "dependencies": { + "fast-deep-equal": "^3.1.3", + "fast-uri": "^3.0.1", + "json-schema-traverse": "^1.0.0", + "require-from-string": "^2.0.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, + "node_modules/ajv-formats": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.1.tgz", + "integrity": "sha512-Wx0Kx52hxE7C18hkMEggYlEifqWZtYaRgouJor+WMdPnQyEK13vgEWyVNup7SoeeoLMsr4kf5h6dOW11I15MUA==", + "license": "MIT", + "dependencies": { + "ajv": "^8.0.0" + }, + "peerDependencies": { + "ajv": "^8.0.0" + }, + "peerDependenciesMeta": { + "ajv": { + "optional": true + } + } + }, + "node_modules/ajv/node_modules/fast-uri": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.1.0.tgz", + "integrity": "sha512-iPeeDKJSWf4IEOasVVrknXpaBV0IApz/gp7S2bb7Z4Lljbl2MGJRqInZiUrQwV16cpzw/D3S5j5Julj/gT52AA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "BSD-3-Clause" + }, + "node_modules/atomic-sleep": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/atomic-sleep/-/atomic-sleep-1.0.0.tgz", + "integrity": "sha512-kNOjDqAh7px0XWNI+4QbzoiR/nTkHAWNud2uvnJquD1/x5a7EQZMJT0AczqK0Qn67oY/TTQ1LbUKajZpp3I9tQ==", + "license": "MIT", + "engines": { + "node": ">=8.0.0" + } + }, + "node_modules/avvio": { + "version": "8.4.0", + "resolved": "https://registry.npmjs.org/avvio/-/avvio-8.4.0.tgz", + "integrity": "sha512-CDSwaxINFy59iNwhYnkvALBwZiTydGkOecZyPkqBpABYR1KqGEsET0VOOYDwtleZSUIdeY36DC2bSZ24CO1igA==", + "license": "MIT", + "dependencies": { + "@fastify/error": "^3.3.0", + "fastq": "^1.17.1" + } + }, + "node_modules/cluster-key-slot": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/cluster-key-slot/-/cluster-key-slot-1.1.2.tgz", + "integrity": "sha512-RMr0FhtfXemyinomL4hrWcYJxmX6deFdCxpJzhDttxgO1+bcCnkk+9drydLVDmAMG7NE6aN/fl4F7ucU/90gAA==", + "license": "Apache-2.0", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/cookie": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz", + "integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/debug": { + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", + "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/denque": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/denque/-/denque-2.1.0.tgz", + "integrity": "sha512-HVQE3AAb/pxF8fQAoiqpvg9i3evqug3hoiwakOyZAwJm+6vZehbkYXZ0l4JxS+I3QxM97v5aaRNhj8v5oBhekw==", + "license": "Apache-2.0", + "engines": { + "node": ">=0.10" + } + }, + "node_modules/esbuild": { + "version": "0.27.4", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.27.4.tgz", + "integrity": "sha512-Rq4vbHnYkK5fws5NF7MYTU68FPRE1ajX7heQ/8QXXWqNgqqJ/GkmmyxIzUnf2Sr/bakf8l54716CcMGHYhMrrQ==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "@esbuild/aix-ppc64": "0.27.4", + "@esbuild/android-arm": "0.27.4", + "@esbuild/android-arm64": "0.27.4", + "@esbuild/android-x64": "0.27.4", + "@esbuild/darwin-arm64": "0.27.4", + "@esbuild/darwin-x64": "0.27.4", + "@esbuild/freebsd-arm64": "0.27.4", + "@esbuild/freebsd-x64": "0.27.4", + "@esbuild/linux-arm": "0.27.4", + "@esbuild/linux-arm64": "0.27.4", + "@esbuild/linux-ia32": "0.27.4", + "@esbuild/linux-loong64": "0.27.4", + "@esbuild/linux-mips64el": "0.27.4", + "@esbuild/linux-ppc64": "0.27.4", + "@esbuild/linux-riscv64": "0.27.4", + "@esbuild/linux-s390x": "0.27.4", + "@esbuild/linux-x64": "0.27.4", + "@esbuild/netbsd-arm64": "0.27.4", + "@esbuild/netbsd-x64": "0.27.4", + "@esbuild/openbsd-arm64": "0.27.4", + "@esbuild/openbsd-x64": "0.27.4", + "@esbuild/openharmony-arm64": "0.27.4", + "@esbuild/sunos-x64": "0.27.4", + "@esbuild/win32-arm64": "0.27.4", + "@esbuild/win32-ia32": "0.27.4", + "@esbuild/win32-x64": "0.27.4" + } + }, + "node_modules/fast-content-type-parse": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/fast-content-type-parse/-/fast-content-type-parse-1.1.0.tgz", + "integrity": "sha512-fBHHqSTFLVnR61C+gltJuE5GkVQMV0S2nqUO8TJ+5Z3qAKG8vAx4FKai1s5jq/inV1+sREynIWSuQ6HgoSXpDQ==", + "license": "MIT" + }, + "node_modules/fast-decode-uri-component": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/fast-decode-uri-component/-/fast-decode-uri-component-1.0.1.tgz", + "integrity": "sha512-WKgKWg5eUxvRZGwW8FvfbaH7AXSh2cL+3j5fMGzUMCxWBJ3dV3a7Wz8y2f/uQ0e3B6WmodD3oS54jTQ9HVTIIg==", + "license": "MIT" + }, + "node_modules/fast-deep-equal": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", + "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", + "license": "MIT" + }, + "node_modules/fast-json-stringify": { + "version": "5.16.1", + "resolved": "https://registry.npmjs.org/fast-json-stringify/-/fast-json-stringify-5.16.1.tgz", + "integrity": "sha512-KAdnLvy1yu/XrRtP+LJnxbBGrhN+xXu+gt3EUvZhYGKCr3lFHq/7UFJHHFgmJKoqlh6B40bZLEv7w46B0mqn1g==", + "license": "MIT", + "dependencies": { + "@fastify/merge-json-schemas": "^0.1.0", + "ajv": "^8.10.0", + "ajv-formats": "^3.0.1", + "fast-deep-equal": "^3.1.3", + "fast-uri": "^2.1.0", + "json-schema-ref-resolver": "^1.0.1", + "rfdc": "^1.2.0" + } + }, + "node_modules/fast-json-stringify/node_modules/ajv-formats": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-3.0.1.tgz", + "integrity": "sha512-8iUql50EUR+uUcdRQ3HDqa6EVyo3docL8g5WJ3FNcWmu62IbkGUue/pEyLBW8VGKKucTPgqeks4fIU1DA4yowQ==", + "license": "MIT", + "dependencies": { + "ajv": "^8.0.0" + }, + "peerDependencies": { + "ajv": "^8.0.0" + }, + "peerDependenciesMeta": { + "ajv": { + "optional": true + } + } + }, + "node_modules/fast-querystring": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/fast-querystring/-/fast-querystring-1.1.2.tgz", + "integrity": "sha512-g6KuKWmFXc0fID8WWH0jit4g0AGBoJhCkJMb1RmbsSEUNvQ+ZC8D6CUZ+GtF8nMzSPXnhiePyyqqipzNNEnHjg==", + "license": "MIT", + "dependencies": { + "fast-decode-uri-component": "^1.0.1" + } + }, + "node_modules/fast-uri": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-2.4.0.tgz", + "integrity": "sha512-ypuAmmMKInk5q7XcepxlnUWDLWv4GFtaJqAzWKqn62IpQ3pejtr5dTVbt3vwqVaMKmkNR55sTT+CqUKIaT21BA==", + "license": "MIT" + }, + "node_modules/fastify": { + "version": "4.29.1", + "resolved": "https://registry.npmjs.org/fastify/-/fastify-4.29.1.tgz", + "integrity": "sha512-m2kMNHIG92tSNWv+Z3UeTR9AWLLuo7KctC7mlFPtMEVrfjIhmQhkQnT9v15qA/BfVq3vvj134Y0jl9SBje3jXQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "MIT", + "dependencies": { + "@fastify/ajv-compiler": "^3.5.0", + "@fastify/error": "^3.4.0", + "@fastify/fast-json-stringify-compiler": "^4.3.0", + "abstract-logging": "^2.0.1", + "avvio": "^8.3.0", + "fast-content-type-parse": "^1.1.0", + "fast-json-stringify": "^5.8.0", + "find-my-way": "^8.0.0", + "light-my-request": "^5.11.0", + "pino": "^9.0.0", + "process-warning": "^3.0.0", + "proxy-addr": "^2.0.7", + "rfdc": "^1.3.0", + "secure-json-parse": "^2.7.0", + "semver": "^7.5.4", + "toad-cache": "^3.3.0" + } + }, + "node_modules/fastify-plugin": { + "version": "4.5.1", + "resolved": "https://registry.npmjs.org/fastify-plugin/-/fastify-plugin-4.5.1.tgz", + "integrity": "sha512-stRHYGeuqpEZTL1Ef0Ovr2ltazUT9g844X5z/zEBFLG8RYlpDiOCIG+ATvYEp+/zmc7sN29mcIMp8gvYplYPIQ==", + "license": "MIT" + }, + "node_modules/fastq": { + "version": "1.20.1", + "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.20.1.tgz", + "integrity": "sha512-GGToxJ/w1x32s/D2EKND7kTil4n8OVk/9mycTc4VDza13lOvpUZTGX3mFSCtV9ksdGBVzvsyAVLM6mHFThxXxw==", + "license": "ISC", + "dependencies": { + "reusify": "^1.0.4" + } + }, + "node_modules/find-my-way": { + "version": "8.2.2", + "resolved": "https://registry.npmjs.org/find-my-way/-/find-my-way-8.2.2.tgz", + "integrity": "sha512-Dobi7gcTEq8yszimcfp/R7+owiT4WncAJ7VTTgFH1jYJ5GaG1FbhjwDG820hptN0QDFvzVY3RfCzdInvGPGzjA==", + "license": "MIT", + "dependencies": { + "fast-deep-equal": "^3.1.3", + "fast-querystring": "^1.0.0", + "safe-regex2": "^3.1.0" + }, + "engines": { + "node": ">=14" + } + }, + "node_modules/forwarded": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", + "integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, + "node_modules/get-tsconfig": { + "version": "4.13.7", + "resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.13.7.tgz", + "integrity": "sha512-7tN6rFgBlMgpBML5j8typ92BKFi2sFQvIdpAqLA2beia5avZDrMs0FLZiM5etShWq5irVyGcGMEA1jcDaK7A/Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "resolve-pkg-maps": "^1.0.0" + }, + "funding": { + "url": "https://github.com/privatenumber/get-tsconfig?sponsor=1" + } + }, + "node_modules/ioredis": { + "version": "5.10.1", + "resolved": "https://registry.npmjs.org/ioredis/-/ioredis-5.10.1.tgz", + "integrity": "sha512-HuEDBTI70aYdx1v6U97SbNx9F1+svQKBDo30o0b9fw055LMepzpOOd0Ccg9Q6tbqmBSJaMuY0fB7yw9/vjBYCA==", + "license": "MIT", + "dependencies": { + "@ioredis/commands": "1.5.1", + "cluster-key-slot": "^1.1.0", + "debug": "^4.3.4", + "denque": "^2.1.0", + "lodash.defaults": "^4.2.0", + "lodash.isarguments": "^3.1.0", + "redis-errors": "^1.2.0", + "redis-parser": "^3.0.0", + "standard-as-callback": "^2.1.0" + }, + "engines": { + "node": ">=12.22.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/ioredis" + } + }, + "node_modules/ipaddr.js": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", + "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==", + "license": "MIT", + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/json-schema-ref-resolver": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/json-schema-ref-resolver/-/json-schema-ref-resolver-1.0.1.tgz", + "integrity": "sha512-EJAj1pgHc1hxF6vo2Z3s69fMjO1INq6eGHXZ8Z6wCQeldCuwxGK9Sxf4/cScGn3FZubCVUehfWtcDM/PLteCQw==", + "license": "MIT", + "dependencies": { + "fast-deep-equal": "^3.1.3" + } + }, + "node_modules/json-schema-traverse": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", + "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", + "license": "MIT" + }, + "node_modules/light-my-request": { + "version": "5.14.0", + "resolved": "https://registry.npmjs.org/light-my-request/-/light-my-request-5.14.0.tgz", + "integrity": "sha512-aORPWntbpH5esaYpGOOmri0OHDOe3wC5M2MQxZ9dvMLZm6DnaAn0kJlcbU9hwsQgLzmZyReKwFwwPkR+nHu5kA==", + "license": "BSD-3-Clause", + "dependencies": { + "cookie": "^0.7.0", + "process-warning": "^3.0.0", + "set-cookie-parser": "^2.4.1" + } + }, + "node_modules/lodash.defaults": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/lodash.defaults/-/lodash.defaults-4.2.0.tgz", + "integrity": "sha512-qjxPLHd3r5DnsdGacqOMU6pb/avJzdh9tFX2ymgoZE27BmjXrNy/y4LoaiTeAb+O3gL8AfpJGtqfX/ae2leYYQ==", + "license": "MIT" + }, + "node_modules/lodash.isarguments": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/lodash.isarguments/-/lodash.isarguments-3.1.0.tgz", + "integrity": "sha512-chi4NHZlZqZD18a0imDHnZPrDeBbTtVN7GXMwuGdRH9qotxAjYs3aVLKc7zNOG9eddR5Ksd8rvFEBc9SsggPpg==", + "license": "MIT" + }, + "node_modules/mnemonist": { + "version": "0.39.6", + "resolved": "https://registry.npmjs.org/mnemonist/-/mnemonist-0.39.6.tgz", + "integrity": "sha512-A/0v5Z59y63US00cRSLiloEIw3t5G+MiKz4BhX21FI+YBJXBOGW0ohFxTxO08dsOYlzxo87T7vGfZKYp2bcAWA==", + "license": "MIT", + "dependencies": { + "obliterator": "^2.0.1" + } + }, + "node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" + }, + "node_modules/obliterator": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/obliterator/-/obliterator-2.0.5.tgz", + "integrity": "sha512-42CPE9AhahZRsMNslczq0ctAEtqk8Eka26QofnqC346BZdHDySk3LWka23LI7ULIw11NmltpiLagIq8gBozxTw==", + "license": "MIT" + }, + "node_modules/on-exit-leak-free": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/on-exit-leak-free/-/on-exit-leak-free-2.1.2.tgz", + "integrity": "sha512-0eJJY6hXLGf1udHwfNftBqH+g73EU4B504nZeKpz1sYRKafAghwxEJunB2O7rDZkL4PGfsMVnTXZ2EjibbqcsA==", + "license": "MIT", + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/pino": { + "version": "9.14.0", + "resolved": "https://registry.npmjs.org/pino/-/pino-9.14.0.tgz", + "integrity": "sha512-8OEwKp5juEvb/MjpIc4hjqfgCNysrS94RIOMXYvpYCdm/jglrKEiAYmiumbmGhCvs+IcInsphYDFwqrjr7398w==", + "license": "MIT", + "dependencies": { + "@pinojs/redact": "^0.4.0", + "atomic-sleep": "^1.0.0", + "on-exit-leak-free": "^2.1.0", + "pino-abstract-transport": "^2.0.0", + "pino-std-serializers": "^7.0.0", + "process-warning": "^5.0.0", + "quick-format-unescaped": "^4.0.3", + "real-require": "^0.2.0", + "safe-stable-stringify": "^2.3.1", + "sonic-boom": "^4.0.1", + "thread-stream": "^3.0.0" + }, + "bin": { + "pino": "bin.js" + } + }, + "node_modules/pino-abstract-transport": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/pino-abstract-transport/-/pino-abstract-transport-2.0.0.tgz", + "integrity": "sha512-F63x5tizV6WCh4R6RHyi2Ml+M70DNRXt/+HANowMflpgGFMAym/VKm6G7ZOQRjqN7XbGxK1Lg9t6ZrtzOaivMw==", + "license": "MIT", + "dependencies": { + "split2": "^4.0.0" + } + }, + "node_modules/pino-std-serializers": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/pino-std-serializers/-/pino-std-serializers-7.1.0.tgz", + "integrity": "sha512-BndPH67/JxGExRgiX1dX0w1FvZck5Wa4aal9198SrRhZjH3GxKQUKIBnYJTdj2HDN3UQAS06HlfcSbQj2OHmaw==", + "license": "MIT" + }, + "node_modules/pino/node_modules/process-warning": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/process-warning/-/process-warning-5.0.0.tgz", + "integrity": "sha512-a39t9ApHNx2L4+HBnQKqxxHNs1r7KF+Intd8Q/g1bUh6q0WIp9voPXJ/x0j+ZL45KF1pJd9+q2jLIRMfvEshkA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "MIT" + }, + "node_modules/process-warning": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/process-warning/-/process-warning-3.0.0.tgz", + "integrity": "sha512-mqn0kFRl0EoqhnL0GQ0veqFHyIN1yig9RHh/InzORTUiZHFRAur+aMtRkELNwGs9aNwKS6tg/An4NYBPGwvtzQ==", + "license": "MIT" + }, + "node_modules/proxy-addr": { + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", + "integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==", + "license": "MIT", + "dependencies": { + "forwarded": "0.2.0", + "ipaddr.js": "1.9.1" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/quick-format-unescaped": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/quick-format-unescaped/-/quick-format-unescaped-4.0.4.tgz", + "integrity": "sha512-tYC1Q1hgyRuHgloV/YXs2w15unPVh8qfu/qCTfhTYamaw7fyhumKa2yGpdSo87vY32rIclj+4fWYQXUMs9EHvg==", + "license": "MIT" + }, + "node_modules/real-require": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/real-require/-/real-require-0.2.0.tgz", + "integrity": "sha512-57frrGM/OCTLqLOAh0mhVA9VBMHd+9U7Zb2THMGdBUoZVOtGbJzjxsYGDJ3A9AYYCP4hn6y1TVbaOfzWtm5GFg==", + "license": "MIT", + "engines": { + "node": ">= 12.13.0" + } + }, + "node_modules/redis-errors": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/redis-errors/-/redis-errors-1.2.0.tgz", + "integrity": "sha512-1qny3OExCf0UvUV/5wpYKf2YwPcOqXzkwKKSmKHiE6ZMQs5heeE/c8eXK+PNllPvmjgAbfnsbpkGZWy8cBpn9w==", + "license": "MIT", + "engines": { + "node": ">=4" + } + }, + "node_modules/redis-parser": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/redis-parser/-/redis-parser-3.0.0.tgz", + "integrity": "sha512-DJnGAeenTdpMEH6uAJRK/uiyEIH9WVsUmoLwzudwGJUwZPp80PDBWPHXSAGNPwNvIXAbe7MSUB1zQFugFml66A==", + "license": "MIT", + "dependencies": { + "redis-errors": "^1.0.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/require-from-string": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", + "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/resolve-pkg-maps": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz", + "integrity": "sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/privatenumber/resolve-pkg-maps?sponsor=1" + } + }, + "node_modules/ret": { + "version": "0.4.3", + "resolved": "https://registry.npmjs.org/ret/-/ret-0.4.3.tgz", + "integrity": "sha512-0f4Memo5QP7WQyUEAYUO3esD/XjOc3Zjjg5CPsAq1p8sIu0XPeMbHJemKA0BO7tV0X7+A0FoEpbmHXWxPyD3wQ==", + "license": "MIT", + "engines": { + "node": ">=10" + } + }, + "node_modules/reusify": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.1.0.tgz", + "integrity": "sha512-g6QUff04oZpHs0eG5p83rFLhHeV00ug/Yf9nZM6fLeUrPguBTkTQOdpAWWspMh55TZfVQDPaN3NQJfbVRAxdIw==", + "license": "MIT", + "engines": { + "iojs": ">=1.0.0", + "node": ">=0.10.0" + } + }, + "node_modules/rfdc": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/rfdc/-/rfdc-1.4.1.tgz", + "integrity": "sha512-q1b3N5QkRUWUl7iyylaaj3kOpIT0N2i9MqIEQXP73GVsN9cw3fdx8X63cEmWhJGi2PPCF23Ijp7ktmd39rawIA==", + "license": "MIT" + }, + "node_modules/safe-regex2": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/safe-regex2/-/safe-regex2-3.1.0.tgz", + "integrity": "sha512-RAAZAGbap2kBfbVhvmnTFv73NWLMvDGOITFYTZBAaY8eR+Ir4ef7Up/e7amo+y1+AH+3PtLkrt9mvcTsG9LXug==", + "license": "MIT", + "dependencies": { + "ret": "~0.4.0" + } + }, + "node_modules/safe-stable-stringify": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/safe-stable-stringify/-/safe-stable-stringify-2.5.0.tgz", + "integrity": "sha512-b3rppTKm9T+PsVCBEOUR46GWI7fdOs00VKZ1+9c1EWDaDMvjQc6tUwuFyIprgGgTcWoVHSKrU8H31ZHA2e0RHA==", + "license": "MIT", + "engines": { + "node": ">=10" + } + }, + "node_modules/secure-json-parse": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/secure-json-parse/-/secure-json-parse-2.7.0.tgz", + "integrity": "sha512-6aU+Rwsezw7VR8/nyvKTx8QpWH9FrcYiXXlqC4z5d5XQBDRqtbfsRjnwGyqbi3gddNtWHuEk9OANUotL26qKUw==", + "license": "BSD-3-Clause" + }, + "node_modules/semver": { + "version": "7.7.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.4.tgz", + "integrity": "sha512-vFKC2IEtQnVhpT78h1Yp8wzwrf8CM+MzKMHGJZfBtzhZNycRFnXsHk6E5TxIkkMsgNS7mdX3AGB7x2QM2di4lA==", + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/set-cookie-parser": { + "version": "2.7.2", + "resolved": "https://registry.npmjs.org/set-cookie-parser/-/set-cookie-parser-2.7.2.tgz", + "integrity": "sha512-oeM1lpU/UvhTxw+g3cIfxXHyJRc/uidd3yK1P242gzHds0udQBYzs3y8j4gCCW+ZJ7ad0yctld8RYO+bdurlvw==", + "license": "MIT" + }, + "node_modules/sonic-boom": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/sonic-boom/-/sonic-boom-4.2.1.tgz", + "integrity": "sha512-w6AxtubXa2wTXAUsZMMWERrsIRAdrK0Sc+FUytWvYAhBJLyuI4llrMIC1DtlNSdI99EI86KZum2MMq3EAZlF9Q==", + "license": "MIT", + "dependencies": { + "atomic-sleep": "^1.0.0" + } + }, + "node_modules/split2": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/split2/-/split2-4.2.0.tgz", + "integrity": "sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==", + "license": "ISC", + "engines": { + "node": ">= 10.x" + } + }, + "node_modules/standard-as-callback": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/standard-as-callback/-/standard-as-callback-2.1.0.tgz", + "integrity": "sha512-qoRRSyROncaz1z0mvYqIE4lCd9p2R90i6GxW3uZv5ucSu8tU7B5HXUP1gG8pVZsYNVaXjk8ClXHPttLyxAL48A==", + "license": "MIT" + }, + "node_modules/thread-stream": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/thread-stream/-/thread-stream-3.1.0.tgz", + "integrity": "sha512-OqyPZ9u96VohAyMfJykzmivOrY2wfMSf3C5TtFJVgN+Hm6aj+voFhlK+kZEIv2FBh1X6Xp3DlnCOfEQ3B2J86A==", + "license": "MIT", + "dependencies": { + "real-require": "^0.2.0" + } + }, + "node_modules/toad-cache": { + "version": "3.7.0", + "resolved": "https://registry.npmjs.org/toad-cache/-/toad-cache-3.7.0.tgz", + "integrity": "sha512-/m8M+2BJUpoJdgAHoG+baCwBT+tf2VraSfkBgl0Y00qIWt41DJ8R5B8nsEw0I58YwF5IZH6z24/2TobDKnqSWw==", + "license": "MIT", + "engines": { + "node": ">=12" + } + }, + "node_modules/tsx": { + "version": "4.21.0", + "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.21.0.tgz", + "integrity": "sha512-5C1sg4USs1lfG0GFb2RLXsdpXqBSEhAaA/0kPL01wxzpMqLILNxIxIOKiILz+cdg/pLnOUxFYOR5yhHU666wbw==", + "dev": true, + "license": "MIT", + "dependencies": { + "esbuild": "~0.27.0", + "get-tsconfig": "^4.7.5" + }, + "bin": { + "tsx": "dist/cli.mjs" + }, + "engines": { + "node": ">=18.0.0" + }, + "optionalDependencies": { + "fsevents": "~2.3.3" + } + }, + "node_modules/typescript": { + "version": "5.9.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", + "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, + "node_modules/undici-types": { + "version": "6.21.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz", + "integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==", + "dev": true, + "license": "MIT" + } + } +} diff --git a/bridge/package.json b/bridge/package.json new file mode 100644 index 0000000..3696924 --- /dev/null +++ b/bridge/package.json @@ -0,0 +1,24 @@ +{ + "name": "news-bridge", + "version": "1.0.0", + "description": "WordPress REST API bridge for the news platform", + "type": "module", + "main": "dist/server.js", + "scripts": { + "dev": "tsx watch src/server.ts", + "build": "tsc", + "start": "node dist/server.js", + "typecheck": "tsc --noEmit" + }, + "dependencies": { + "@fastify/cors": "^9.0.1", + "@fastify/rate-limit": "^9.1.0", + "fastify": "^4.28.1", + "ioredis": "^5.4.1" + }, + "devDependencies": { + "@types/node": "^20.14.0", + "tsx": "^4.15.0", + "typescript": "^5.4.5" + } +} diff --git a/bridge/src/config/domain.ts b/bridge/src/config/domain.ts new file mode 100644 index 0000000..29916eb --- /dev/null +++ b/bridge/src/config/domain.ts @@ -0,0 +1,58 @@ +import { existsSync, readFileSync } from 'node:fs'; +import { resolve, join } from 'node:path'; +import type { DomainConfig } from '../types.js'; + +const DOMAINS_DIR = resolve( + process.env['DOMAINS_CONFIG_PATH'] ?? join(process.cwd(), '..', 'config', 'domains'), +); + +const config_cache = new Map(); + +function load_domain_file(host: string): DomainConfig | null { + const file_path = join(DOMAINS_DIR, `${host}.json`); + if (!existsSync(file_path)) return null; + try { + const raw = readFileSync(file_path, 'utf-8'); + return JSON.parse(raw) as DomainConfig; + } catch (err) { + throw new Error(`Failed to parse domain config for "${host}": ${(err as Error).message}`); + } +} + +/** + * Resolve and return the DomainConfig for a given Host header value. + * Falls back to DEFAULT_HOST (env) then "localhost" if no match found. + * + * Configs are cached in-process after first read; restart bridge to reload. + */ +export function get_domain_config(host_header: string): DomainConfig { + // Strip port number (e.g. "localhost:3200" → "localhost") + const host = host_header.replace(/:\d+$/, '').toLowerCase(); + + const cached = config_cache.get(host); + if (cached) return cached; + + const config = load_domain_file(host); + if (config) { + config_cache.set(host, config); + return config; + } + + // Fall back to DEFAULT_HOST + const default_host = (process.env['DEFAULT_HOST'] ?? 'localhost').toLowerCase(); + if (host !== default_host) { + const fallback = get_domain_config(default_host); + config_cache.set(host, fallback); + return fallback; + } + + throw new Error( + `No domain config found for "${host}" and no fallback available. ` + + `Expected file: ${join(DOMAINS_DIR, `${host}.json`)}`, + ); +} + +/** Clear the in-process config cache (useful in tests). */ +export function clear_domain_cache(): void { + config_cache.clear(); +} diff --git a/bridge/src/routes/articles.ts b/bridge/src/routes/articles.ts new file mode 100644 index 0000000..03f280c --- /dev/null +++ b/bridge/src/routes/articles.ts @@ -0,0 +1,136 @@ +import type { FastifyInstance, FastifyRequest } from 'fastify'; +import { get_domain_config } from '../config/domain.js'; +import { WpClient } from '../services/wp-client.js'; +import { swr_fetch } from '../services/cache.js'; +import type { ArticleListItem, PaginatedResponse } from '../types.js'; + +type ArticleListQuery = { + category?: string; + page?: string; + per_page?: string; + search?: string; +}; + +type SlugParams = { + slug: string; +}; + +type RelatedQuery = { + limit?: string; +}; + +async function resolve_category_id( + client: WpClient, + category_slug: string, + cache_key_prefix: string, +): Promise { + try { + const cats = await swr_fetch(`${cache_key_prefix}:categories:all`, () => client.get_categories()); + const match = cats.find(c => c.slug === category_slug); + return match?.id; + } catch { + return undefined; + } +} + +export async function articles_routes(app: FastifyInstance): Promise { + // GET /articles — paginated list, optional category/search filter + app.get( + '/articles', + async (req: FastifyRequest<{ Querystring: ArticleListQuery }>, reply) => { + const host = req.hostname ?? 'localhost'; + const config = get_domain_config(host); + const client = new WpClient(config.wp_endpoint); + const cache_prefix = `${host}:wp`; + + const page = parseInt(req.query.page ?? '1', 10); + const per_page = Math.min(parseInt(req.query.per_page ?? '12', 10), 100); + const search = req.query.search; + let categories: number | undefined; + + if (req.query.category) { + categories = await resolve_category_id(client, req.query.category, cache_prefix); + } + + const cache_key = `${cache_prefix}:posts:p${page}:pp${per_page}:cat${categories ?? ''}:q${search ?? ''}`; + + const result = await swr_fetch>( + cache_key, + async () => { + const { items, total } = await client.get_posts({ page, per_page, categories, search }); + return { + items, + total, + page, + per_page, + total_pages: Math.ceil(total / per_page), + }; + }, + ); + + return reply.send(result); + }, + ); + + // GET /articles/:slug — single article + app.get( + '/articles/:slug', + async (req: FastifyRequest<{ Params: SlugParams }>, reply) => { + const host = req.hostname ?? 'localhost'; + const config = get_domain_config(host); + const client = new WpClient(config.wp_endpoint); + const { slug } = req.params; + + const article = await swr_fetch( + `${host}:wp:post:${slug}`, + () => client.get_post_by_slug(slug), + ); + + return reply.send(article); + }, + ); + + // GET /articles/:slug/related — related articles (same category, excluding current) + app.get( + '/articles/:slug/related', + async (req: FastifyRequest<{ Params: SlugParams; Querystring: RelatedQuery }>, reply) => { + const host = req.hostname ?? 'localhost'; + const config = get_domain_config(host); + const client = new WpClient(config.wp_endpoint); + const { slug } = req.params; + const limit = Math.min(parseInt(req.query.limit ?? '4', 10), 10); + + // Fetch the article first to get its category + const article = await swr_fetch( + `${host}:wp:post:${slug}`, + () => client.get_post_by_slug(slug), + ); + + const related = await swr_fetch( + `${host}:wp:related:${slug}:${limit}`, + async () => { + const posts = await client.get_posts_by_category_id(article.category.id, limit + 1); + return posts.filter(p => p.slug !== slug).slice(0, limit); + }, + ); + + return reply.send(related); + }, + ); + + // GET /api/posts — alias for /articles (issue-spec route) + app.get( + '/api/posts', + async (req: FastifyRequest<{ Querystring: ArticleListQuery }>, reply) => { + return reply.redirect(`/articles?${new URLSearchParams(req.query as Record).toString()}`); + }, + ); + + // GET /api/posts/:slug — alias for /articles/:slug + app.get( + '/api/posts/:slug', + async (req: FastifyRequest<{ Params: SlugParams }>, reply) => { + return reply.redirect(`/articles/${req.params.slug}`); + }, + ); +} diff --git a/bridge/src/routes/categories.ts b/bridge/src/routes/categories.ts new file mode 100644 index 0000000..0f9ef87 --- /dev/null +++ b/bridge/src/routes/categories.ts @@ -0,0 +1,116 @@ +import type { FastifyInstance, FastifyRequest } from 'fastify'; +import { get_domain_config } from '../config/domain.js'; +import { WpClient } from '../services/wp-client.js'; +import { swr_fetch } from '../services/cache.js'; +import type { ArticleListItem, PaginatedResponse } from '../types.js'; + +type SlugParams = { + slug: string; +}; + +type CategoryPostsQuery = { + page?: string; + per_page?: string; +}; + +export async function categories_routes(app: FastifyInstance): Promise { + // GET /categories — all categories + app.get('/categories', async (req: FastifyRequest, reply) => { + const host = req.hostname ?? 'localhost'; + const config = get_domain_config(host); + const client = new WpClient(config.wp_endpoint); + + const categories = await swr_fetch( + `${host}:wp:categories:all`, + () => client.get_categories(), + ); + + return reply.send(categories); + }); + + // GET /categories/:slug — single category + its posts + app.get( + '/categories/:slug', + async (req: FastifyRequest<{ Params: SlugParams; Querystring: CategoryPostsQuery }>, reply) => { + const host = req.hostname ?? 'localhost'; + const config = get_domain_config(host); + const client = new WpClient(config.wp_endpoint); + const { slug } = req.params; + const page = parseInt(req.query.page ?? '1', 10); + const per_page = Math.min(parseInt(req.query.per_page ?? '12', 10), 100); + + const category = await swr_fetch( + `${host}:wp:category:${slug}`, + () => client.get_category_by_slug(slug), + ); + + const posts_result = await swr_fetch>( + `${host}:wp:category:${slug}:posts:p${page}:pp${per_page}`, + async () => { + const { items, total } = await client.get_posts({ + page, + per_page, + categories: category.id, + }); + return { + items, + total, + page, + per_page, + total_pages: Math.ceil(total / per_page), + }; + }, + ); + + return reply.send({ ...category, posts: posts_result }); + }, + ); + + // GET /api/categories and /api/categories/:slug — aliases per issue spec + app.get('/api/categories', async (req: FastifyRequest, reply) => { + return reply.redirect('/categories'); + }); + + app.get( + '/api/categories/:slug', + async (req: FastifyRequest<{ Params: SlugParams }>, reply) => { + return reply.redirect(`/categories/${req.params.slug}`); + }, + ); + + // GET /api/tags — all tags + app.get('/api/tags', async (req: FastifyRequest, reply) => { + const host = req.hostname ?? 'localhost'; + const config = get_domain_config(host); + const client = new WpClient(config.wp_endpoint); + + const tags = await swr_fetch( + `${host}:wp:tags:all`, + () => client.get_tags(), + ); + + return reply.send(tags); + }); + + // GET /api/media/:id — image metadata + app.get( + '/api/media/:id', + async (req: FastifyRequest<{ Params: { id: string } }>, reply) => { + const host = req.hostname ?? 'localhost'; + const config = get_domain_config(host); + const client = new WpClient(config.wp_endpoint); + const media_id = parseInt(req.params.id, 10); + + if (isNaN(media_id) || media_id <= 0) { + return reply.code(400).send({ error: 'Invalid media ID' }); + } + + const media = await swr_fetch( + `${host}:wp:media:${media_id}`, + () => client.get_media(media_id), + ); + + return reply.send(media); + }, + ); +} diff --git a/bridge/src/routes/health.ts b/bridge/src/routes/health.ts new file mode 100644 index 0000000..8714788 --- /dev/null +++ b/bridge/src/routes/health.ts @@ -0,0 +1,7 @@ +import type { FastifyInstance } from 'fastify'; + +export async function health_routes(app: FastifyInstance): Promise { + app.get('/health', async (_req, reply) => { + return reply.send({ status: 'ok', timestamp: new Date().toISOString() }); + }); +} diff --git a/bridge/src/routes/homepage.ts b/bridge/src/routes/homepage.ts new file mode 100644 index 0000000..3d4ab6c --- /dev/null +++ b/bridge/src/routes/homepage.ts @@ -0,0 +1,94 @@ +import type { FastifyInstance, FastifyRequest } from 'fastify'; +import { get_domain_config } from '../config/domain.js'; +import { WpClient } from '../services/wp-client.js'; +import { swr_fetch } from '../services/cache.js'; +import type { ArticleListItem, HomepageData } from '../types.js'; + +// Number of articles per section +const HERO_COUNT = 3; +const TRENDING_COUNT = 5; +const FEATURED_COUNT = 4; +const LATEST_COUNT = 12; +const BY_CATEGORY_COUNT = 4; + +export async function homepage_routes(app: FastifyInstance): Promise { + app.get('/homepage', async (req: FastifyRequest, reply) => { + const host = req.hostname ?? 'localhost'; + const config = get_domain_config(host); + const client = new WpClient(config.wp_endpoint); + + const data = await swr_fetch( + `${host}:homepage`, + async () => { + // Fetch in parallel where possible + const [sticky_posts, latest_result, categories_list] = await Promise.all([ + client.get_sticky_posts(HERO_COUNT).catch((): ArticleListItem[] => []), + client.get_posts({ per_page: LATEST_COUNT + TRENDING_COUNT }), + client.get_categories().catch(() => []), + ]); + + const all_latest = latest_result.items; + + // Hero = sticky posts (or first N from latest if none) + const hero = sticky_posts.length >= HERO_COUNT + ? sticky_posts.slice(0, HERO_COUNT) + : [...sticky_posts, ...all_latest.slice(0, HERO_COUNT - sticky_posts.length)]; + + // Trending = most recent posts marked is_trending (first N for now; can swap with view-count logic later) + const trending: ArticleListItem[] = all_latest + .slice(0, TRENDING_COUNT) + .map(p => ({ ...p, is_trending: true })); + + // Featured = first FEATURED_COUNT from latest + const featured: ArticleListItem[] = all_latest.slice(0, FEATURED_COUNT).map(p => ({ ...p, is_featured: true })); + + // Latest = all fetched + const latest = all_latest.slice(0, LATEST_COUNT); + + // Per-category sections using domain config categories + const category_slugs = config.categories.map(c => c.slug); + const by_category: Record = {}; + + const category_posts = await Promise.allSettled( + category_slugs.map(async (slug) => { + const cat = categories_list.find(c => c.slug === slug); + if (!cat) return { slug, items: [] as ArticleListItem[] }; + const items = await client.get_posts_by_category_id(cat.id, BY_CATEGORY_COUNT); + return { slug, items }; + }), + ); + + for (const result of category_posts) { + if (result.status === 'fulfilled') { + by_category[result.value.slug] = result.value.items; + } + } + + return { hero, trending, featured, latest, by_category }; + }, + ); + + return reply.send(data); + }); + + // GET /trending — convenience endpoint + app.get( + '/trending', + async (req: FastifyRequest<{ Querystring: { limit?: string } }>, reply) => { + const host = req.hostname ?? 'localhost'; + const config = get_domain_config(host); + const client = new WpClient(config.wp_endpoint); + const limit = Math.min(parseInt(req.query.limit ?? '5', 10), 20); + + const items = await swr_fetch( + `${host}:trending:${limit}`, + async () => { + const { items: posts } = await client.get_posts({ per_page: limit }); + return posts.map(p => ({ ...p, is_trending: true })); + }, + ); + + return reply.send(items); + }, + ); +} diff --git a/bridge/src/routes/site-config.ts b/bridge/src/routes/site-config.ts new file mode 100644 index 0000000..ba0cd8a --- /dev/null +++ b/bridge/src/routes/site-config.ts @@ -0,0 +1,10 @@ +import type { FastifyInstance, FastifyRequest } from 'fastify'; +import { get_domain_config } from '../config/domain.js'; + +export async function site_config_routes(app: FastifyInstance): Promise { + app.get('/api/site-config', async (req: FastifyRequest, reply) => { + const host = req.hostname ?? 'localhost'; + const config = get_domain_config(host); + return reply.send(config); + }); +} diff --git a/bridge/src/server.ts b/bridge/src/server.ts new file mode 100644 index 0000000..c906f22 --- /dev/null +++ b/bridge/src/server.ts @@ -0,0 +1,74 @@ +import Fastify from 'fastify'; +import cors from '@fastify/cors'; +import rate_limit from '@fastify/rate-limit'; + +import { health_routes } from './routes/health.js'; +import { site_config_routes } from './routes/site-config.js'; +import { articles_routes } from './routes/articles.js'; +import { categories_routes } from './routes/categories.js'; +import { homepage_routes } from './routes/homepage.js'; + +const PORT = parseInt(process.env['PORT'] ?? '3200', 10); +const LOG_LEVEL = process.env['LOG_LEVEL'] ?? 'info'; + +const app = Fastify({ + logger: { + level: LOG_LEVEL, + transport: process.env['NODE_ENV'] !== 'production' + ? { target: 'pino-pretty', options: { colorize: true } } + : undefined, + }, + disableRequestLogging: false, +}); + +await app.register(cors, { origin: true }); + +await app.register(rate_limit, { + global: true, + max: parseInt(process.env['RATE_LIMIT_MAX'] ?? '100', 10), + timeWindow: parseInt(process.env['RATE_LIMIT_WINDOW_MS'] ?? '60000', 10), + keyGenerator: (req) => req.ip, +}); + +// Global error handler — map known error types to HTTP status codes +app.setErrorHandler((err, req, reply) => { + const msg = err.message ?? 'Internal server error'; + const is_not_found = msg.includes('not found') || msg.includes('Not Found'); + const is_wp_down = msg.startsWith('WP API') || err.name === 'TimeoutError' || msg.includes('fetch failed'); + + if (is_not_found) { + return reply.code(404).send({ error: msg }); + } + + if (is_wp_down) { + app.log.warn({ url: req.url, err: msg }, 'WP upstream unavailable'); + return reply.code(503).send({ error: 'Upstream unavailable', detail: msg }); + } + + if (err.statusCode && err.statusCode < 500) { + return reply.code(err.statusCode).send({ error: msg }); + } + + app.log.error({ url: req.url, err }, 'Unhandled error'); + return reply.code(500).send({ error: 'Internal server error' }); +}); + +// Register route plugins +await app.register(health_routes); +await app.register(site_config_routes); +await app.register(articles_routes); +await app.register(categories_routes); +await app.register(homepage_routes); + +// 404 fallback +app.setNotFoundHandler((_req, reply) => { + return reply.code(404).send({ error: 'Route not found' }); +}); + +try { + await app.listen({ port: PORT, host: '0.0.0.0' }); + app.log.info(`Bridge API running on port ${PORT}`); +} catch (err) { + app.log.error(err); + process.exit(1); +} diff --git a/bridge/src/services/cache.ts b/bridge/src/services/cache.ts new file mode 100644 index 0000000..25df01d --- /dev/null +++ b/bridge/src/services/cache.ts @@ -0,0 +1,139 @@ +import { Redis } from 'ioredis'; + +interface CacheEntry { + data: unknown; + stale_at: number; + expires_at: number; +} + +const FRESH_TTL_MS = (parseInt(process.env['CACHE_FRESH_TTL'] ?? '60', 10)) * 1000; +const STALE_TTL_MS = (parseInt(process.env['CACHE_STALE_TTL'] ?? '300', 10)) * 1000; + +// In-process fallback map (used when Redis is unavailable or not configured) +const local_map = new Map(); + +let redis_client: Redis | null = null; + +function get_redis(): Redis | null { + const url = process.env['REDIS_URL']; + if (!url) return null; + + if (redis_client) return redis_client; + + redis_client = new Redis(url, { + lazyConnect: true, + enableOfflineQueue: false, + maxRetriesPerRequest: 1, + }); + + redis_client.on('error', (err: Error) => { + // Log but do not crash — fall back to local cache + console.error('[cache] Redis error, falling back to in-process cache:', err.message); + }); + + return redis_client; +} + +async function read_redis(key: string): Promise { + const redis = get_redis(); + if (!redis) return null; + try { + const raw = await redis.get(key); + if (!raw) return null; + return JSON.parse(raw) as CacheEntry; + } catch { + return null; + } +} + +async function write_redis(key: string, entry: CacheEntry): Promise { + const redis = get_redis(); + if (!redis) return; + try { + const ttl_seconds = Math.ceil((entry.expires_at - Date.now()) / 1000); + if (ttl_seconds <= 0) return; + await redis.set(key, JSON.stringify(entry), 'EX', ttl_seconds); + } catch { + // ignore write failures + } +} + +async function read_local(key: string): Promise { + return local_map.get(key) ?? null; +} + +function write_local(key: string, entry: CacheEntry): void { + local_map.set(key, entry); +} + +async function get_entry(key: string): Promise { + const redis_entry = await read_redis(key); + if (redis_entry) return redis_entry; + return read_local(key); +} + +async function set_entry(key: string, data: unknown): Promise { + const now = Date.now(); + const entry: CacheEntry = { + data, + stale_at: now + FRESH_TTL_MS, + expires_at: now + STALE_TTL_MS, + }; + write_local(key, entry); + await write_redis(key, entry); +} + +/** + * Stale-while-revalidate cache. + * + * - Returns fresh data immediately if available. + * - Returns stale data and revalidates in the background if TTL exceeded but hard-expiry not reached. + * - Fetches synchronously if cold or hard-expired. + * - On fetch error, returns last known stale value (serve from cache) or throws. + */ +export async function swr_fetch( + key: string, + fetcher: () => Promise, +): Promise { + const now = Date.now(); + const entry = await get_entry(key); + + if (entry && now < entry.stale_at) { + return entry.data as T; + } + + if (entry && now < entry.expires_at) { + // Revalidate in background; return stale immediately + revalidate(key, fetcher).catch(() => null); + return entry.data as T; + } + + return revalidate(key, fetcher, entry); +} + +async function revalidate( + key: string, + fetcher: () => Promise, + stale_entry?: CacheEntry | null, +): Promise { + try { + const data = await fetcher(); + await set_entry(key, data); + return data; + } catch (err) { + if (stale_entry) { + // WP is down but we have something in cache — serve it + return stale_entry.data as T; + } + throw err; + } +} + +/** Invalidate a key from all layers. */ +export async function cache_invalidate(key: string): Promise { + local_map.delete(key); + const redis = get_redis(); + if (redis) { + try { await redis.del(key); } catch { /* ignore */ } + } +} diff --git a/bridge/src/services/wp-client.ts b/bridge/src/services/wp-client.ts new file mode 100644 index 0000000..2a644d0 --- /dev/null +++ b/bridge/src/services/wp-client.ts @@ -0,0 +1,195 @@ +import type { + Article, + ArticleListItem, + Author, + Category, + Tag, + WpMedia, + WpPost, + WpTerm, + WpUser, +} from '../types.js'; + +const EMBED = '_embed=wp:featuredmedia,author,wp:term'; + +function strip_html(html: string): string { + return html.replace(/<[^>]+>/g, '').replace(/&[a-z]+;/gi, ' ').trim(); +} + +function estimate_reading_time(html: string): number { + const words = strip_html(html).split(/\s+/).filter(Boolean).length; + return Math.max(1, Math.round(words / 200)); +} + +function pick_image_url(media: WpMedia): string { + const sizes = media.media_details?.sizes ?? {}; + return ( + sizes['medium_large']?.source_url ?? + sizes['large']?.source_url ?? + sizes['medium']?.source_url ?? + media.source_url + ); +} + +function normalize_author(user?: WpUser): Author { + if (!user) { + return { id: 0, name: 'Unknown', slug: 'unknown', avatar: null }; + } + const avatars = user.avatar_urls ?? {}; + const avatar = avatars['96'] ?? avatars['48'] ?? null; + return { id: user.id, name: user.name, slug: user.slug, avatar }; +} + +function normalize_category(term?: WpTerm): Category { + if (!term) { + return { id: 0, slug: 'uncategorised', name: 'Uncategorised', description: '', count: 0 }; + } + return { + id: term.id, + slug: term.slug, + name: term.name, + description: strip_html(term.description), + count: term.count, + }; +} + +function normalize_tag(term: WpTerm): Tag { + return { id: term.id, slug: term.slug, name: term.name }; +} + +function normalize_post_list_item(post: WpPost): ArticleListItem { + const author = normalize_author(post._embedded?.author?.[0]); + + // wp:term[0] = categories, wp:term[1] = tags + const category_terms = post._embedded?.['wp:term']?.[0] ?? []; + const category = normalize_category(category_terms[0]); + + let featured_image: string | null = null; + let featured_image_alt = ''; + const media = post._embedded?.['wp:featuredmedia']?.[0]; + if (media && media.source_url) { + featured_image = pick_image_url(media); + featured_image_alt = media.alt_text || strip_html(post.title.rendered); + } + + return { + id: post.id, + slug: post.slug, + title: strip_html(post.title.rendered), + excerpt: strip_html(post.excerpt.rendered), + featured_image, + featured_image_alt, + author, + category, + published_at: post.date, + reading_time: estimate_reading_time(post.content.rendered), + is_featured: post.sticky, + is_trending: false, // determined by call-site / view count; WP has no native field + }; +} + +function normalize_post(post: WpPost): Article { + const list_item = normalize_post_list_item(post); + + const tag_terms = post._embedded?.['wp:term']?.[1] ?? []; + const tags: Tag[] = tag_terms.map(normalize_tag); + + return { + ...list_item, + content: post.content.rendered, + updated_at: post.modified, + tags, + }; +} + +export class WpClient { + private readonly base: string; + + constructor(wp_endpoint: string) { + // wp_endpoint from config is e.g. "http://localhost:8080/wp-json" + this.base = wp_endpoint.replace(/\/$/, ''); + } + + private async fetch_json(path: string): Promise<{ data: T; headers: Headers }> { + const url = `${this.base}${path}`; + const res = await fetch(url, { + headers: { Accept: 'application/json' }, + signal: AbortSignal.timeout(8000), + }); + if (!res.ok) { + throw new Error(`WP API ${res.status} ${res.statusText}: ${url}`); + } + const data = (await res.json()) as T; + return { data, headers: res.headers }; + } + + async get_posts(params: { + page?: number; + per_page?: number; + categories?: number; + search?: string; + } = {}): Promise<{ items: ArticleListItem[]; total: number }> { + const qs = new URLSearchParams({ [EMBED]: '' }); + if (params.page) qs.set('page', String(params.page)); + if (params.per_page) qs.set('per_page', String(params.per_page)); + if (params.categories) qs.set('categories', String(params.categories)); + if (params.search) qs.set('search', params.search); + + const path = `/wp/v2/posts?${qs.toString().replace('%3D=', '=')}`; + const { data, headers } = await this.fetch_json(path); + const total = parseInt(headers.get('x-wp-total') ?? '0', 10); + return { items: data.map(normalize_post_list_item), total }; + } + + async get_post_by_slug(slug: string): Promise
{ + const qs = new URLSearchParams({ slug, [EMBED]: '' }); + const path = `/wp/v2/posts?${qs.toString().replace('%3D=', '=')}`; + const { data } = await this.fetch_json(path); + const post = data[0]; + if (!post) throw new Error(`Post not found: ${slug}`); + return normalize_post(post); + } + + async get_categories(): Promise { + const { data } = await this.fetch_json('/wp/v2/categories?per_page=100&hide_empty=true'); + return data.map(normalize_category); + } + + async get_category_by_slug(slug: string): Promise { + const { data } = await this.fetch_json(`/wp/v2/categories?slug=${encodeURIComponent(slug)}`); + const term = data[0]; + if (!term) throw new Error(`Category not found: ${slug}`); + return normalize_category(term); + } + + async get_tags(): Promise { + const { data } = await this.fetch_json('/wp/v2/tags?per_page=100&hide_empty=true'); + return data.map(normalize_tag); + } + + async get_media(id: number): Promise { + const { data } = await this.fetch_json(`/wp/v2/media/${id}`); + return data; + } + + async get_sticky_posts(limit = 3): Promise { + const qs = new URLSearchParams({ sticky: 'true', per_page: String(limit), [EMBED]: '' }); + const path = `/wp/v2/posts?${qs.toString().replace('%3D=', '=')}`; + const { data } = await this.fetch_json(path); + return data.map(p => ({ ...normalize_post_list_item(p), is_featured: true })); + } + + async get_posts_by_category_id( + category_id: number, + per_page = 4, + ): Promise { + const qs = new URLSearchParams({ + categories: String(category_id), + per_page: String(per_page), + [EMBED]: '', + }); + const path = `/wp/v2/posts?${qs.toString().replace('%3D=', '=')}`; + const { data } = await this.fetch_json(path); + return data.map(normalize_post_list_item); + } +} diff --git a/bridge/src/types.ts b/bridge/src/types.ts new file mode 100644 index 0000000..e97d0b5 --- /dev/null +++ b/bridge/src/types.ts @@ -0,0 +1,127 @@ +export interface DomainConfig { + site_name: string; + tagline: string; + theme: string; + logo: string; + favicon: string; + primary_color: string; + secondary_color: string; + accent_color: string; + categories: CategoryConfig[]; + bridge_endpoint: string; + wp_endpoint: string; + locale: string; + timezone: string; + ads_enabled: boolean; + analytics_id: string | null; +} + +export interface CategoryConfig { + slug: string; + label: string; +} + +export interface Author { + id: number; + name: string; + slug: string; + avatar: string | null; +} + +export interface Category { + id: number; + slug: string; + name: string; + description: string; + count: number; +} + +export interface Tag { + id: number; + slug: string; + name: string; +} + +export interface ArticleListItem { + id: number; + slug: string; + title: string; + excerpt: string; + featured_image: string | null; + featured_image_alt: string; + author: Author; + category: Category; + published_at: string; + reading_time: number; + is_featured: boolean; + is_trending: boolean; +} + +export interface Article extends ArticleListItem { + content: string; + updated_at: string; + tags: Tag[]; +} + +export interface PaginatedResponse { + items: T[]; + total: number; + page: number; + per_page: number; + total_pages: number; +} + +export interface HomepageData { + hero: ArticleListItem[]; + trending: ArticleListItem[]; + featured: ArticleListItem[]; + latest: ArticleListItem[]; + by_category: Record; +} + +// Raw WordPress REST API types (minimal subset we use) +export interface WpPost { + id: number; + date: string; + modified: string; + slug: string; + status: string; + title: { rendered: string }; + excerpt: { rendered: string }; + content: { rendered: string }; + featured_media: number; + sticky: boolean; + categories: number[]; + tags: number[]; + _embedded?: { + author?: WpUser[]; + 'wp:term'?: WpTerm[][]; + 'wp:featuredmedia'?: WpMedia[]; + }; +} + +export interface WpUser { + id: number; + name: string; + slug: string; + avatar_urls?: Record; +} + +export interface WpTerm { + id: number; + link: string; + name: string; + slug: string; + taxonomy: string; + description: string; + count: number; +} + +export interface WpMedia { + id: number; + source_url: string; + alt_text: string; + media_details?: { + sizes?: Record; + }; +} diff --git a/bridge/tsconfig.json b/bridge/tsconfig.json new file mode 100644 index 0000000..2c632d7 --- /dev/null +++ b/bridge/tsconfig.json @@ -0,0 +1,18 @@ +{ + "compilerOptions": { + "target": "ES2022", + "module": "NodeNext", + "moduleResolution": "NodeNext", + "outDir": "dist", + "rootDir": "src", + "strict": true, + "esModuleInterop": true, + "skipLibCheck": true, + "resolveJsonModule": true, + "declaration": true, + "declarationMap": true, + "sourceMap": true + }, + "include": ["src/**/*"], + "exclude": ["node_modules", "dist"] +} diff --git a/config/domains/localhost.json b/config/domains/localhost.json new file mode 100644 index 0000000..b1a6577 --- /dev/null +++ b/config/domains/localhost.json @@ -0,0 +1,23 @@ +{ + "site_name": "Sports News (Dev)", + "tagline": "The latest sports news, live scores and transfers", + "theme": "sports", + "logo": "/assets/logo.svg", + "favicon": "/favicon.svg", + "primary_color": "#e63946", + "secondary_color": "#1d3557", + "accent_color": "#f1faee", + "categories": [ + { "slug": "football", "label": "Football" }, + { "slug": "basketball", "label": "Basketball" }, + { "slug": "formula1", "label": "Formula 1" }, + { "slug": "tennis", "label": "Tennis" }, + { "slug": "mma", "label": "MMA" } + ], + "bridge_endpoint": "http://localhost:3200", + "wp_endpoint": "http://localhost:8080/wp-json", + "locale": "en-US", + "timezone": "Europe/Lisbon", + "ads_enabled": false, + "analytics_id": null +}