diff --git a/backend/.gitignore b/backend/.gitignore new file mode 100644 index 0000000..cdd16c0 --- /dev/null +++ b/backend/.gitignore @@ -0,0 +1,4 @@ +node_modules +.wrangler +dist +.env diff --git a/backend/package-lock.json b/backend/package-lock.json new file mode 100644 index 0000000..32ebdf2 --- /dev/null +++ b/backend/package-lock.json @@ -0,0 +1,1652 @@ +{ + "name": "app-d9wl4z", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "app-d9wl4z", + "dependencies": { + "hono": "latest" + }, + "devDependencies": { + "@cloudflare/workers-types": "^4.0.0", + "typescript": "^5.0.0", + "wrangler": "^3.109.2" + } + }, + "node_modules/@cloudflare/kv-asset-handler": { + "version": "0.3.4", + "resolved": "https://registry.npmjs.org/@cloudflare/kv-asset-handler/-/kv-asset-handler-0.3.4.tgz", + "integrity": "sha512-YLPHc8yASwjNkmcDMQMY35yiWjoKAKnhUbPRszBRS0YgH+IXtsMp61j+yTcnCE3oO2DgP0U3iejLC8FTtKDC8Q==", + "dev": true, + "license": "MIT OR Apache-2.0", + "dependencies": { + "mime": "^3.0.0" + }, + "engines": { + "node": ">=16.13" + } + }, + "node_modules/@cloudflare/unenv-preset": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/@cloudflare/unenv-preset/-/unenv-preset-2.0.2.tgz", + "integrity": "sha512-nyzYnlZjjV5xT3LizahG1Iu6mnrCaxglJ04rZLpDwlDVDZ7v46lNsfxhV3A/xtfgQuSHmLnc6SVI+KwBpc3Lwg==", + "dev": true, + "license": "MIT OR Apache-2.0", + "peerDependencies": { + "unenv": "2.0.0-rc.14", + "workerd": "^1.20250124.0" + }, + "peerDependenciesMeta": { + "workerd": { + "optional": true + } + } + }, + "node_modules/@cloudflare/workerd-darwin-64": { + "version": "1.20250718.0", + "resolved": "https://registry.npmjs.org/@cloudflare/workerd-darwin-64/-/workerd-darwin-64-1.20250718.0.tgz", + "integrity": "sha512-FHf4t7zbVN8yyXgQ/r/GqLPaYZSGUVzeR7RnL28Mwj2djyw2ZergvytVc7fdGcczl6PQh+VKGfZCfUqpJlbi9g==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=16" + } + }, + "node_modules/@cloudflare/workerd-darwin-arm64": { + "version": "1.20250718.0", + "resolved": "https://registry.npmjs.org/@cloudflare/workerd-darwin-arm64/-/workerd-darwin-arm64-1.20250718.0.tgz", + "integrity": "sha512-fUiyUJYyqqp4NqJ0YgGtp4WJh/II/YZsUnEb6vVy5Oeas8lUOxnN+ZOJ8N/6/5LQCVAtYCChRiIrBbfhTn5Z8Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=16" + } + }, + "node_modules/@cloudflare/workerd-linux-64": { + "version": "1.20250718.0", + "resolved": "https://registry.npmjs.org/@cloudflare/workerd-linux-64/-/workerd-linux-64-1.20250718.0.tgz", + "integrity": "sha512-5+eb3rtJMiEwp08Kryqzzu8d1rUcK+gdE442auo5eniMpT170Dz0QxBrqkg2Z48SFUPYbj+6uknuA5tzdRSUSg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=16" + } + }, + "node_modules/@cloudflare/workerd-linux-arm64": { + "version": "1.20250718.0", + "resolved": "https://registry.npmjs.org/@cloudflare/workerd-linux-arm64/-/workerd-linux-arm64-1.20250718.0.tgz", + "integrity": "sha512-Aa2M/DVBEBQDdATMbn217zCSFKE+ud/teS+fFS+OQqKABLn0azO2qq6ANAHYOIE6Q3Sq4CxDIQr8lGdaJHwUog==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=16" + } + }, + "node_modules/@cloudflare/workerd-windows-64": { + "version": "1.20250718.0", + "resolved": "https://registry.npmjs.org/@cloudflare/workerd-windows-64/-/workerd-windows-64-1.20250718.0.tgz", + "integrity": "sha512-dY16RXKffmugnc67LTbyjdDHZn5NoTF1yHEf2fN4+OaOnoGSp3N1x77QubTDwqZ9zECWxgQfDLjddcH8dWeFhg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=16" + } + }, + "node_modules/@cloudflare/workers-types": { + "version": "4.20260702.1", + "resolved": "https://registry.npmjs.org/@cloudflare/workers-types/-/workers-types-4.20260702.1.tgz", + "integrity": "sha512-mOhf5TUEB1m2vPrxtqoIGfz0fUC9xyxRDx5gWHy5s+OCo6dcV+g7wI1R7gYCMFohhqF/2y2xeKVwMwCJjfn/WA==", + "dev": true, + "license": "MIT OR Apache-2.0" + }, + "node_modules/@cspotcode/source-map-support": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", + "integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/trace-mapping": "0.3.9" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/@emnapi/runtime": { + "version": "1.11.2", + "resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.11.2.tgz", + "integrity": "sha512-kyOl3X0DuTiT1h2ft8r2fYO8JYtU9a9Xis/zBSiGArNaagCOWx90N1k2wxp18czFDH+OgcWGb5ZP/XMt3dcyPA==", + "dev": true, + "license": "MIT", + "optional": true, + "dependencies": { + "tslib": "^2.4.0" + } + }, + "node_modules/@esbuild-plugins/node-globals-polyfill": { + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/@esbuild-plugins/node-globals-polyfill/-/node-globals-polyfill-0.2.3.tgz", + "integrity": "sha512-r3MIryXDeXDOZh7ih1l/yE9ZLORCd5e8vWg02azWRGj5SPTuoh69A2AIyn0Z31V/kHBfZ4HgWJ+OK3GTTwLmnw==", + "dev": true, + "license": "ISC", + "peerDependencies": { + "esbuild": "*" + } + }, + "node_modules/@esbuild-plugins/node-modules-polyfill": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/@esbuild-plugins/node-modules-polyfill/-/node-modules-polyfill-0.2.2.tgz", + "integrity": "sha512-LXV7QsWJxRuMYvKbiznh+U1ilIop3g2TeKRzUxOG5X3YITc8JyyTa90BmLwqqv0YnX4v32CSlG+vsziZp9dMvA==", + "dev": true, + "license": "ISC", + "dependencies": { + "escape-string-regexp": "^4.0.0", + "rollup-plugin-node-polyfills": "^0.2.1" + }, + "peerDependencies": { + "esbuild": "*" + } + }, + "node_modules/@esbuild/android-arm": { + "version": "0.17.19", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.17.19.tgz", + "integrity": "sha512-rIKddzqhmav7MSmoFCmDIb6e2W57geRsM94gV2l38fzhXMwq7hZoClug9USI2pFRGL06f4IOPHHpFNOkWieR8A==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/android-arm64": { + "version": "0.17.19", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.17.19.tgz", + "integrity": "sha512-KBMWvEZooR7+kzY0BtbTQn0OAYY7CsiydT63pVEaPtVYF0hXbUaOyZog37DKxK7NF3XacBJOpYT4adIJh+avxA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/android-x64": { + "version": "0.17.19", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.17.19.tgz", + "integrity": "sha512-uUTTc4xGNDT7YSArp/zbtmbhO0uEEK9/ETW29Wk1thYUJBz3IVnvgEiEwEa9IeLyvnpKrWK64Utw2bgUmDveww==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/darwin-arm64": { + "version": "0.17.19", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.17.19.tgz", + "integrity": "sha512-80wEoCfF/hFKM6WE1FyBHc9SfUblloAWx6FJkFWTWiCoht9Mc0ARGEM47e67W9rI09YoUxJL68WHfDRYEAvOhg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/darwin-x64": { + "version": "0.17.19", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.17.19.tgz", + "integrity": "sha512-IJM4JJsLhRYr9xdtLytPLSH9k/oxR3boaUIYiHkAawtwNOXKE8KoU8tMvryogdcT8AU+Bflmh81Xn6Q0vTZbQw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/freebsd-arm64": { + "version": "0.17.19", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.17.19.tgz", + "integrity": "sha512-pBwbc7DufluUeGdjSU5Si+P3SoMF5DQ/F/UmTSb8HXO80ZEAJmrykPyzo1IfNbAoaqw48YRpv8shwd1NoI0jcQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/freebsd-x64": { + "version": "0.17.19", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.17.19.tgz", + "integrity": "sha512-4lu+n8Wk0XlajEhbEffdy2xy53dpR06SlzvhGByyg36qJw6Kpfk7cp45DR/62aPH9mtJRmIyrXAS5UWBrJT6TQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-arm": { + "version": "0.17.19", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.17.19.tgz", + "integrity": "sha512-cdmT3KxjlOQ/gZ2cjfrQOtmhG4HJs6hhvm3mWSRDPtZ/lP5oe8FWceS10JaSJC13GBd4eH/haHnqf7hhGNLerA==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-arm64": { + "version": "0.17.19", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.17.19.tgz", + "integrity": "sha512-ct1Tg3WGwd3P+oZYqic+YZF4snNl2bsnMKRkb3ozHmnM0dGWuxcPTTntAF6bOP0Sp4x0PjSF+4uHQ1xvxfRKqg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-ia32": { + "version": "0.17.19", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.17.19.tgz", + "integrity": "sha512-w4IRhSy1VbsNxHRQpeGCHEmibqdTUx61Vc38APcsRbuVgK0OPEnQ0YD39Brymn96mOx48Y2laBQGqgZ0j9w6SQ==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-loong64": { + "version": "0.17.19", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.17.19.tgz", + "integrity": "sha512-2iAngUbBPMq439a+z//gE+9WBldoMp1s5GWsUSgqHLzLJ9WoZLZhpwWuym0u0u/4XmZ3gpHmzV84PonE+9IIdQ==", + "cpu": [ + "loong64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-mips64el": { + "version": "0.17.19", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.17.19.tgz", + "integrity": "sha512-LKJltc4LVdMKHsrFe4MGNPp0hqDFA1Wpt3jE1gEyM3nKUvOiO//9PheZZHfYRfYl6AwdTH4aTcXSqBerX0ml4A==", + "cpu": [ + "mips64el" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-ppc64": { + "version": "0.17.19", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.17.19.tgz", + "integrity": "sha512-/c/DGybs95WXNS8y3Ti/ytqETiW7EU44MEKuCAcpPto3YjQbyK3IQVKfF6nbghD7EcLUGl0NbiL5Rt5DMhn5tg==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-riscv64": { + "version": "0.17.19", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.17.19.tgz", + "integrity": "sha512-FC3nUAWhvFoutlhAkgHf8f5HwFWUL6bYdvLc/TTuxKlvLi3+pPzdZiFKSWz/PF30TB1K19SuCxDTI5KcqASJqA==", + "cpu": [ + "riscv64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-s390x": { + "version": "0.17.19", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.17.19.tgz", + "integrity": "sha512-IbFsFbxMWLuKEbH+7sTkKzL6NJmG2vRyy6K7JJo55w+8xDk7RElYn6xvXtDW8HCfoKBFK69f3pgBJSUSQPr+4Q==", + "cpu": [ + "s390x" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-x64": { + "version": "0.17.19", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.17.19.tgz", + "integrity": "sha512-68ngA9lg2H6zkZcyp22tsVt38mlhWde8l3eJLWkyLrp4HwMUr3c1s/M2t7+kHIhvMjglIBrFpncX1SzMckomGw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/netbsd-x64": { + "version": "0.17.19", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.17.19.tgz", + "integrity": "sha512-CwFq42rXCR8TYIjIfpXCbRX0rp1jo6cPIUPSaWwzbVI4aOfX96OXY8M6KNmtPcg7QjYeDmN+DD0Wp3LaBOLf4Q==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/openbsd-x64": { + "version": "0.17.19", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.17.19.tgz", + "integrity": "sha512-cnq5brJYrSZ2CF6c35eCmviIN3k3RczmHz8eYaVlNasVqsNY+JKohZU5MKmaOI+KkllCdzOKKdPs762VCPC20g==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/sunos-x64": { + "version": "0.17.19", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.17.19.tgz", + "integrity": "sha512-vCRT7yP3zX+bKWFeP/zdS6SqdWB8OIpaRq/mbXQxTGHnIxspRtigpkUcDMlSCOejlHowLqII7K2JKevwyRP2rg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/win32-arm64": { + "version": "0.17.19", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.17.19.tgz", + "integrity": "sha512-yYx+8jwowUstVdorcMdNlzklLYhPxjniHWFKgRqH7IFlUEa0Umu3KuYplf1HUZZ422e3NU9F4LGb+4O0Kdcaag==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/win32-ia32": { + "version": "0.17.19", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.17.19.tgz", + "integrity": "sha512-eggDKanJszUtCdlVs0RB+h35wNlb5v4TWEkq4vZcmVt5u/HiDZrTXe2bWFQUez3RgNHwx/x4sk5++4NSSicKkw==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/win32-x64": { + "version": "0.17.19", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.17.19.tgz", + "integrity": "sha512-lAhycmKnVOuRYNtRtatQR1LPQf2oYCkRGkSFnseDAKPl8lu5SOsK/e1sXe5a0Pc5kHIHe6P2I/ilntNv2xf3cA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@fastify/busboy": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/@fastify/busboy/-/busboy-2.1.1.tgz", + "integrity": "sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=14" + } + }, + "node_modules/@img/sharp-darwin-arm64": { + "version": "0.33.5", + "resolved": "https://registry.npmjs.org/@img/sharp-darwin-arm64/-/sharp-darwin-arm64-0.33.5.tgz", + "integrity": "sha512-UT4p+iz/2H4twwAoLCqfA9UH5pI6DggwKEGuaPy7nCVQ8ZsiY5PIcrRvD1DzuY3qYL07NtIQcWnBSY/heikIFQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^18.17.0 || ^20.3.0 || >=21.0.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-darwin-arm64": "1.0.4" + } + }, + "node_modules/@img/sharp-darwin-x64": { + "version": "0.33.5", + "resolved": "https://registry.npmjs.org/@img/sharp-darwin-x64/-/sharp-darwin-x64-0.33.5.tgz", + "integrity": "sha512-fyHac4jIc1ANYGRDxtiqelIbdWkIuQaI84Mv45KvGRRxSAa7o7d1ZKAOBaYbnepLC1WqxfpimdeWfvqqSGwR2Q==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^18.17.0 || ^20.3.0 || >=21.0.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-darwin-x64": "1.0.4" + } + }, + "node_modules/@img/sharp-libvips-darwin-arm64": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-darwin-arm64/-/sharp-libvips-darwin-arm64-1.0.4.tgz", + "integrity": "sha512-XblONe153h0O2zuFfTAbQYAX2JhYmDHeWikp1LM9Hul9gVPjFY427k6dFEcOL72O01QxQsWi761svJ/ev9xEDg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "darwin" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-darwin-x64": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-darwin-x64/-/sharp-libvips-darwin-x64-1.0.4.tgz", + "integrity": "sha512-xnGR8YuZYfJGmWPvmlunFaWJsb9T/AO2ykoP3Fz/0X5XV2aoYBPkX6xqCQvUTKKiLddarLaxpzNe+b1hjeWHAQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "darwin" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linux-arm": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-arm/-/sharp-libvips-linux-arm-1.0.5.tgz", + "integrity": "sha512-gvcC4ACAOPRNATg/ov8/MnbxFDJqf/pDePbBnuBDcjsI8PssmjoKMAz4LtLaVi+OnSb5FK/yIOamqDwGmXW32g==", + "cpu": [ + "arm" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "linux" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linux-arm64": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-arm64/-/sharp-libvips-linux-arm64-1.0.4.tgz", + "integrity": "sha512-9B+taZ8DlyyqzZQnoeIvDVR/2F4EbMepXMc/NdVbkzsJbzkUjhXv/70GQJ7tdLA4YJgNP25zukcxpX2/SueNrA==", + "cpu": [ + "arm64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "linux" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linux-s390x": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-s390x/-/sharp-libvips-linux-s390x-1.0.4.tgz", + "integrity": "sha512-u7Wz6ntiSSgGSGcjZ55im6uvTrOxSIS8/dgoVMoiGE9I6JAfU50yH5BoDlYA1tcuGS7g/QNtetJnxA6QEsCVTA==", + "cpu": [ + "s390x" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "linux" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linux-x64": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-x64/-/sharp-libvips-linux-x64-1.0.4.tgz", + "integrity": "sha512-MmWmQ3iPFZr0Iev+BAgVMb3ZyC4KeFc3jFxnNbEPas60e1cIfevbtuyf9nDGIzOaW9PdnDciJm+wFFaTlj5xYw==", + "cpu": [ + "x64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "linux" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linuxmusl-arm64": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linuxmusl-arm64/-/sharp-libvips-linuxmusl-arm64-1.0.4.tgz", + "integrity": "sha512-9Ti+BbTYDcsbp4wfYib8Ctm1ilkugkA/uscUn6UXK1ldpC1JjiXbLfFZtRlBhjPZ5o1NCLiDbg8fhUPKStHoTA==", + "cpu": [ + "arm64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "linux" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linuxmusl-x64": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linuxmusl-x64/-/sharp-libvips-linuxmusl-x64-1.0.4.tgz", + "integrity": "sha512-viYN1KX9m+/hGkJtvYYp+CCLgnJXwiQB39damAO7WMdKWlIhmYTfHjwSbQeUK/20vY154mwezd9HflVFM1wVSw==", + "cpu": [ + "x64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "LGPL-3.0-or-later", + "optional": true, + "os": [ + "linux" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-linux-arm": { + "version": "0.33.5", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-arm/-/sharp-linux-arm-0.33.5.tgz", + "integrity": "sha512-JTS1eldqZbJxjvKaAkxhZmBqPRGmxgu+qFKSInv8moZ2AmT5Yib3EQ1c6gp493HvrvV8QgdOXdyaIBrhvFhBMQ==", + "cpu": [ + "arm" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^18.17.0 || ^20.3.0 || >=21.0.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linux-arm": "1.0.5" + } + }, + "node_modules/@img/sharp-linux-arm64": { + "version": "0.33.5", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-arm64/-/sharp-linux-arm64-0.33.5.tgz", + "integrity": "sha512-JMVv+AMRyGOHtO1RFBiJy/MBsgz0x4AWrT6QoEVVTyh1E39TrCUpTRI7mx9VksGX4awWASxqCYLCV4wBZHAYxA==", + "cpu": [ + "arm64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^18.17.0 || ^20.3.0 || >=21.0.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linux-arm64": "1.0.4" + } + }, + "node_modules/@img/sharp-linux-s390x": { + "version": "0.33.5", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-s390x/-/sharp-linux-s390x-0.33.5.tgz", + "integrity": "sha512-y/5PCd+mP4CA/sPDKl2961b+C9d+vPAveS33s6Z3zfASk2j5upL6fXVPZi7ztePZ5CuH+1kW8JtvxgbuXHRa4Q==", + "cpu": [ + "s390x" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^18.17.0 || ^20.3.0 || >=21.0.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linux-s390x": "1.0.4" + } + }, + "node_modules/@img/sharp-linux-x64": { + "version": "0.33.5", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-x64/-/sharp-linux-x64-0.33.5.tgz", + "integrity": "sha512-opC+Ok5pRNAzuvq1AG0ar+1owsu842/Ab+4qvU879ippJBHvyY5n2mxF1izXqkPYlGuP/M556uh53jRLJmzTWA==", + "cpu": [ + "x64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^18.17.0 || ^20.3.0 || >=21.0.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linux-x64": "1.0.4" + } + }, + "node_modules/@img/sharp-linuxmusl-arm64": { + "version": "0.33.5", + "resolved": "https://registry.npmjs.org/@img/sharp-linuxmusl-arm64/-/sharp-linuxmusl-arm64-0.33.5.tgz", + "integrity": "sha512-XrHMZwGQGvJg2V/oRSUfSAfjfPxO+4DkiRh6p2AFjLQztWUuY/o8Mq0eMQVIY7HJ1CDQUJlxGGZRw1a5bqmd1g==", + "cpu": [ + "arm64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^18.17.0 || ^20.3.0 || >=21.0.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linuxmusl-arm64": "1.0.4" + } + }, + "node_modules/@img/sharp-linuxmusl-x64": { + "version": "0.33.5", + "resolved": "https://registry.npmjs.org/@img/sharp-linuxmusl-x64/-/sharp-linuxmusl-x64-0.33.5.tgz", + "integrity": "sha512-WT+d/cgqKkkKySYmqoZ8y3pxx7lx9vVejxW/W4DOFMYVSkErR+w7mf2u8m/y4+xHe7yY9DAXQMWQhpnMuFfScw==", + "cpu": [ + "x64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^18.17.0 || ^20.3.0 || >=21.0.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linuxmusl-x64": "1.0.4" + } + }, + "node_modules/@img/sharp-wasm32": { + "version": "0.33.5", + "resolved": "https://registry.npmjs.org/@img/sharp-wasm32/-/sharp-wasm32-0.33.5.tgz", + "integrity": "sha512-ykUW4LVGaMcU9lu9thv85CbRMAwfeadCJHRsg2GmeRa/cJxsVY9Rbd57JcMxBkKHag5U/x7TSBpScF4U8ElVzg==", + "cpu": [ + "wasm32" + ], + "dev": true, + "license": "Apache-2.0 AND LGPL-3.0-or-later AND MIT", + "optional": true, + "dependencies": { + "@emnapi/runtime": "^1.2.0" + }, + "engines": { + "node": "^18.17.0 || ^20.3.0 || >=21.0.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-win32-ia32": { + "version": "0.33.5", + "resolved": "https://registry.npmjs.org/@img/sharp-win32-ia32/-/sharp-win32-ia32-0.33.5.tgz", + "integrity": "sha512-T36PblLaTwuVJ/zw/LaH0PdZkRz5rd3SmMHX8GSmR7vtNSP5Z6bQkExdSK7xGWyxLw4sUknBuugTelgw2faBbQ==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "Apache-2.0 AND LGPL-3.0-or-later", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": "^18.17.0 || ^20.3.0 || >=21.0.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-win32-x64": { + "version": "0.33.5", + "resolved": "https://registry.npmjs.org/@img/sharp-win32-x64/-/sharp-win32-x64-0.33.5.tgz", + "integrity": "sha512-MpY/o8/8kj+EcnxwvrP4aTJSWw/aZ7JIGR4aBeZkZw5B7/Jn+tY9/VNwtcoGmdT7GfggGIU4kygOMSbYnOrAbg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0 AND LGPL-3.0-or-later", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": "^18.17.0 || ^20.3.0 || >=21.0.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@jridgewell/resolve-uri": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz", + "integrity": "sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/sourcemap-codec": { + "version": "1.5.5", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.5.tgz", + "integrity": "sha512-cYQ9310grqxueWbl+WuIUIaiUaDcj7WOq5fVhEljNVgRfOUhY9fy2zTvfoqWsnebh8Sl70VScFbICvJnLKB0Og==", + "dev": true, + "license": "MIT" + }, + "node_modules/@jridgewell/trace-mapping": { + "version": "0.3.9", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz", + "integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/resolve-uri": "^3.0.3", + "@jridgewell/sourcemap-codec": "^1.4.10" + } + }, + "node_modules/acorn": { + "version": "8.14.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.14.0.tgz", + "integrity": "sha512-cl669nCJTZBsL97OF4kUQm5g5hC2uihk0NxY3WENAC0TYdILVkAyHymAntgxGkl7K+t0cXIrH5siy5S4XkFycA==", + "dev": true, + "license": "MIT", + "bin": { + "acorn": "bin/acorn" + }, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/acorn-walk": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.3.2.tgz", + "integrity": "sha512-cjkyv4OtNCIeqhHrfS81QWXoCBPExR/J62oyEqepVw8WaQeSqpW2uhuLPh1m9eWhDuOo/jUXVTlifvesOWp/4A==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/as-table": { + "version": "1.0.55", + "resolved": "https://registry.npmjs.org/as-table/-/as-table-1.0.55.tgz", + "integrity": "sha512-xvsWESUJn0JN421Xb9MQw6AsMHRCUknCe0Wjlxvjud80mU4E6hQf1A6NzQKcYNmYw62MfzEtXc+badstZP3JpQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "printable-characters": "^1.0.42" + } + }, + "node_modules/blake3-wasm": { + "version": "2.1.5", + "resolved": "https://registry.npmjs.org/blake3-wasm/-/blake3-wasm-2.1.5.tgz", + "integrity": "sha512-F1+K8EbfOZE49dtoPtmxUQrpXaBIl3ICvasLh+nJta0xkz+9kF/7uet9fLnwKqhDrmj6g+6K3Tw9yQPUg2ka5g==", + "dev": true, + "license": "MIT" + }, + "node_modules/color": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/color/-/color-4.2.3.tgz", + "integrity": "sha512-1rXeuUUiGGrykh+CeBdu5Ie7OJwinCgQY0bc7GCRxy5xVHy+moaqkpL/jqQq0MtQOeYcrqEz4abc5f0KtU7W4A==", + "dev": true, + "license": "MIT", + "optional": true, + "dependencies": { + "color-convert": "^2.0.1", + "color-string": "^1.9.0" + }, + "engines": { + "node": ">=12.5.0" + } + }, + "node_modules/color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "license": "MIT", + "optional": true, + "dependencies": { + "color-name": "~1.1.4" + }, + "engines": { + "node": ">=7.0.0" + } + }, + "node_modules/color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true, + "license": "MIT", + "optional": true + }, + "node_modules/color-string": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/color-string/-/color-string-1.9.1.tgz", + "integrity": "sha512-shrVawQFojnZv6xM40anx4CkoDP+fZsw/ZerEMsW/pyzsRbElpsL/DBVW7q3ExxwusdNXI3lXpuhEZkzs8p5Eg==", + "dev": true, + "license": "MIT", + "optional": true, + "dependencies": { + "color-name": "^1.0.0", + "simple-swizzle": "^0.2.2" + } + }, + "node_modules/cookie": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz", + "integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/data-uri-to-buffer": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-2.0.2.tgz", + "integrity": "sha512-ND9qDTLc6diwj+Xe5cdAgVTbLVdXbtxTJRXRhli8Mowuaan+0EJOtdqJ0QCHNSSPyoXGx9HX2/VMnKeC34AChA==", + "dev": true, + "license": "MIT" + }, + "node_modules/defu": { + "version": "6.1.7", + "resolved": "https://registry.npmjs.org/defu/-/defu-6.1.7.tgz", + "integrity": "sha512-7z22QmUWiQ/2d0KkdYmANbRUVABpZ9SNYyH5vx6PZ+nE5bcC0l7uFvEfHlyld/HcGBFTL536ClDt3DEcSlEJAQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/detect-libc": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz", + "integrity": "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==", + "dev": true, + "license": "Apache-2.0", + "optional": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/esbuild": { + "version": "0.17.19", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.17.19.tgz", + "integrity": "sha512-XQ0jAPFkK/u3LcVRcvVHQcTIqD6E2H1fvZMA5dQPSOWb3suUbWbfbRf94pjc0bNzRYLfIrDRQXr7X+LHIm5oHw==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=12" + }, + "optionalDependencies": { + "@esbuild/android-arm": "0.17.19", + "@esbuild/android-arm64": "0.17.19", + "@esbuild/android-x64": "0.17.19", + "@esbuild/darwin-arm64": "0.17.19", + "@esbuild/darwin-x64": "0.17.19", + "@esbuild/freebsd-arm64": "0.17.19", + "@esbuild/freebsd-x64": "0.17.19", + "@esbuild/linux-arm": "0.17.19", + "@esbuild/linux-arm64": "0.17.19", + "@esbuild/linux-ia32": "0.17.19", + "@esbuild/linux-loong64": "0.17.19", + "@esbuild/linux-mips64el": "0.17.19", + "@esbuild/linux-ppc64": "0.17.19", + "@esbuild/linux-riscv64": "0.17.19", + "@esbuild/linux-s390x": "0.17.19", + "@esbuild/linux-x64": "0.17.19", + "@esbuild/netbsd-x64": "0.17.19", + "@esbuild/openbsd-x64": "0.17.19", + "@esbuild/sunos-x64": "0.17.19", + "@esbuild/win32-arm64": "0.17.19", + "@esbuild/win32-ia32": "0.17.19", + "@esbuild/win32-x64": "0.17.19" + } + }, + "node_modules/escape-string-regexp": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", + "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/estree-walker": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-0.6.1.tgz", + "integrity": "sha512-SqmZANLWS0mnatqbSfRP5g8OXZC12Fgg1IwNtLsyHDzJizORW4khDfjPqJZsemPWBB2uqykUah5YpQ6epsqC/w==", + "dev": true, + "license": "MIT" + }, + "node_modules/exit-hook": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/exit-hook/-/exit-hook-2.2.1.tgz", + "integrity": "sha512-eNTPlAD67BmP31LDINZ3U7HSF8l57TxOY2PmBJ1shpCvpnxBF93mWCE8YHBnXs8qiUZJc9WDcWIeC3a2HIAMfw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/exsolve": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/exsolve/-/exsolve-1.1.0.tgz", + "integrity": "sha512-D+42+T12DdIlJM3uepa55qGiL3sYdLBOxIl2ifQCzCHz4c7eiolaHsi3BIqEr7JxBzxv2pYZQX9kw16ziMcEmw==", + "dev": true, + "license": "MIT" + }, + "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-source": { + "version": "2.0.12", + "resolved": "https://registry.npmjs.org/get-source/-/get-source-2.0.12.tgz", + "integrity": "sha512-X5+4+iD+HoSeEED+uwrQ07BOQr0kEDFMVqqpBuI+RaZBpBpHCuXxo70bjar6f0b0u/DQJsJ7ssurpP0V60Az+w==", + "dev": true, + "license": "Unlicense", + "dependencies": { + "data-uri-to-buffer": "^2.0.0", + "source-map": "^0.6.1" + } + }, + "node_modules/glob-to-regexp": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/glob-to-regexp/-/glob-to-regexp-0.4.1.tgz", + "integrity": "sha512-lkX1HJXwyMcprw/5YUZc2s7DrpAiHB21/V+E1rHUrVNokkvB6bqMzT0VfV6/86ZNabt1k14YOIaT7nDvOX3Iiw==", + "dev": true, + "license": "BSD-2-Clause" + }, + "node_modules/hono": { + "version": "4.12.30", + "resolved": "https://registry.npmjs.org/hono/-/hono-4.12.30.tgz", + "integrity": "sha512-emn+JoJjrN9YTpRDS5it/UI2SO9BAE37T6I3d963RxcZ81G9A4pr2SZTEiiaiKbzx+NKRg5BZ89fCL7gCJCUog==", + "license": "MIT", + "engines": { + "node": ">=16.9.0" + } + }, + "node_modules/is-arrayish": { + "version": "0.3.4", + "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.3.4.tgz", + "integrity": "sha512-m6UrgzFVUYawGBh1dUsWR5M2Clqic9RVXC/9f8ceNlv2IcO9j9J/z8UoCLPqtsPBFNzEpfR3xftohbfqDx8EQA==", + "dev": true, + "license": "MIT", + "optional": true + }, + "node_modules/magic-string": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.9.tgz", + "integrity": "sha512-RmF0AsMzgt25qzqqLc1+MbHmhdx0ojF2Fvs4XnOqz2ZOBXzzkEwc/dJQZCYHAn7v1jbVOjAZfK8msRn4BxO4VQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "sourcemap-codec": "^1.4.8" + } + }, + "node_modules/mime": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-3.0.0.tgz", + "integrity": "sha512-jSCU7/VB1loIWBZe14aEYHU/+1UMEHoaO7qxCOVJOw9GgH72VAWppxNcjU+x9a2k3GSIBXNKxXQFqRvvZ7vr3A==", + "dev": true, + "license": "MIT", + "bin": { + "mime": "cli.js" + }, + "engines": { + "node": ">=10.0.0" + } + }, + "node_modules/miniflare": { + "version": "3.20250718.3", + "resolved": "https://registry.npmjs.org/miniflare/-/miniflare-3.20250718.3.tgz", + "integrity": "sha512-JuPrDJhwLrNLEJiNLWO7ZzJrv/Vv9kZuwMYCfv0LskQDM6Eonw4OvywO3CH/wCGjgHzha/qyjUh8JQ068TjDgQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@cspotcode/source-map-support": "0.8.1", + "acorn": "8.14.0", + "acorn-walk": "8.3.2", + "exit-hook": "2.2.1", + "glob-to-regexp": "0.4.1", + "stoppable": "1.1.0", + "undici": "^5.28.5", + "workerd": "1.20250718.0", + "ws": "8.18.0", + "youch": "3.3.4", + "zod": "3.22.3" + }, + "bin": { + "miniflare": "bootstrap.js" + }, + "engines": { + "node": ">=16.13" + } + }, + "node_modules/mustache": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/mustache/-/mustache-4.2.0.tgz", + "integrity": "sha512-71ippSywq5Yb7/tVYyGbkBggbU8H3u5Rz56fH60jGFgr8uHwxs+aSKeqmluIVzM0m0kB7xQjKS6qPfd0b2ZoqQ==", + "dev": true, + "license": "MIT", + "bin": { + "mustache": "bin/mustache" + } + }, + "node_modules/ohash": { + "version": "2.0.11", + "resolved": "https://registry.npmjs.org/ohash/-/ohash-2.0.11.tgz", + "integrity": "sha512-RdR9FQrFwNBNXAr4GixM8YaRZRJ5PUWbKYbE5eOsrwAjJW0q2REGcf79oYPsLyskQCZG1PLN+S/K1V00joZAoQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/path-to-regexp": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-6.3.0.tgz", + "integrity": "sha512-Yhpw4T9C6hPpgPeA28us07OJeqZ5EzQTkbfwuhsUg0c237RomFoETJgmp2sa3F/41gfLE6G5cqcYwznmeEeOlQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/pathe": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/pathe/-/pathe-2.0.3.tgz", + "integrity": "sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w==", + "dev": true, + "license": "MIT" + }, + "node_modules/printable-characters": { + "version": "1.0.42", + "resolved": "https://registry.npmjs.org/printable-characters/-/printable-characters-1.0.42.tgz", + "integrity": "sha512-dKp+C4iXWK4vVYZmYSd0KBH5F/h1HoZRsbJ82AVKRO3PEo8L4lBS/vLwhVtpwwuYcoIsVY+1JYKR268yn480uQ==", + "dev": true, + "license": "Unlicense" + }, + "node_modules/rollup-plugin-inject": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/rollup-plugin-inject/-/rollup-plugin-inject-3.0.2.tgz", + "integrity": "sha512-ptg9PQwzs3orn4jkgXJ74bfs5vYz1NCZlSQMBUA0wKcGp5i5pA1AO3fOUEte8enhGUC+iapTCzEWw2jEFFUO/w==", + "deprecated": "This package has been deprecated and is no longer maintained. Please use @rollup/plugin-inject.", + "dev": true, + "license": "MIT", + "dependencies": { + "estree-walker": "^0.6.1", + "magic-string": "^0.25.3", + "rollup-pluginutils": "^2.8.1" + } + }, + "node_modules/rollup-plugin-node-polyfills": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/rollup-plugin-node-polyfills/-/rollup-plugin-node-polyfills-0.2.1.tgz", + "integrity": "sha512-4kCrKPTJ6sK4/gLL/U5QzVT8cxJcofO0OU74tnB19F40cmuAKSzH5/siithxlofFEjwvw1YAhPmbvGNA6jEroA==", + "dev": true, + "license": "MIT", + "dependencies": { + "rollup-plugin-inject": "^3.0.0" + } + }, + "node_modules/rollup-pluginutils": { + "version": "2.8.2", + "resolved": "https://registry.npmjs.org/rollup-pluginutils/-/rollup-pluginutils-2.8.2.tgz", + "integrity": "sha512-EEp9NhnUkwY8aif6bxgovPHMoMoNr2FulJziTndpt5H9RdwC47GSGuII9XxpSdzVGM0GWrNPHV6ie1LTNJPaLQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "estree-walker": "^0.6.1" + } + }, + "node_modules/semver": { + "version": "7.8.5", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.8.5.tgz", + "integrity": "sha512-Y7/KDsb8LjooZpwaqGyulO6DQlksgCncchHGk+sZIY4SBvUocMBEFH5Ur1fI4dV+Jvl0w6cjvucaIi40puRioA==", + "dev": true, + "license": "ISC", + "optional": true, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/sharp": { + "version": "0.33.5", + "resolved": "https://registry.npmjs.org/sharp/-/sharp-0.33.5.tgz", + "integrity": "sha512-haPVm1EkS9pgvHrQ/F3Xy+hgcuMV0Wm9vfIBSiwZ05k+xgb0PkBQpGsAA/oWdDobNaZTH5ppvHtzCFbnSEwHVw==", + "dev": true, + "hasInstallScript": true, + "license": "Apache-2.0", + "optional": true, + "dependencies": { + "color": "^4.2.3", + "detect-libc": "^2.0.3", + "semver": "^7.6.3" + }, + "engines": { + "node": "^18.17.0 || ^20.3.0 || >=21.0.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-darwin-arm64": "0.33.5", + "@img/sharp-darwin-x64": "0.33.5", + "@img/sharp-libvips-darwin-arm64": "1.0.4", + "@img/sharp-libvips-darwin-x64": "1.0.4", + "@img/sharp-libvips-linux-arm": "1.0.5", + "@img/sharp-libvips-linux-arm64": "1.0.4", + "@img/sharp-libvips-linux-s390x": "1.0.4", + "@img/sharp-libvips-linux-x64": "1.0.4", + "@img/sharp-libvips-linuxmusl-arm64": "1.0.4", + "@img/sharp-libvips-linuxmusl-x64": "1.0.4", + "@img/sharp-linux-arm": "0.33.5", + "@img/sharp-linux-arm64": "0.33.5", + "@img/sharp-linux-s390x": "0.33.5", + "@img/sharp-linux-x64": "0.33.5", + "@img/sharp-linuxmusl-arm64": "0.33.5", + "@img/sharp-linuxmusl-x64": "0.33.5", + "@img/sharp-wasm32": "0.33.5", + "@img/sharp-win32-ia32": "0.33.5", + "@img/sharp-win32-x64": "0.33.5" + } + }, + "node_modules/simple-swizzle": { + "version": "0.2.4", + "resolved": "https://registry.npmjs.org/simple-swizzle/-/simple-swizzle-0.2.4.tgz", + "integrity": "sha512-nAu1WFPQSMNr2Zn9PGSZK9AGn4t/y97lEm+MXTtUDwfP0ksAIX4nO+6ruD9Jwut4C49SB1Ws+fbXsm/yScWOHw==", + "dev": true, + "license": "MIT", + "optional": true, + "dependencies": { + "is-arrayish": "^0.3.1" + } + }, + "node_modules/source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true, + "license": "BSD-3-Clause", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/sourcemap-codec": { + "version": "1.4.8", + "resolved": "https://registry.npmjs.org/sourcemap-codec/-/sourcemap-codec-1.4.8.tgz", + "integrity": "sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA==", + "deprecated": "Please use @jridgewell/sourcemap-codec instead", + "dev": true, + "license": "MIT" + }, + "node_modules/stacktracey": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/stacktracey/-/stacktracey-2.2.0.tgz", + "integrity": "sha512-ETyQEz+CzXiLjEbyJqpbp+/T79RQD/6wqFucRBIlVNZfYq2Ay7wbretD4cxpbymZlaPWx58aIhPEY1Cr8DlVvg==", + "dev": true, + "license": "Unlicense", + "dependencies": { + "as-table": "^1.0.36", + "get-source": "^2.0.12" + } + }, + "node_modules/stoppable": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/stoppable/-/stoppable-1.1.0.tgz", + "integrity": "sha512-KXDYZ9dszj6bzvnEMRYvxgeTHU74QBFL54XKtP3nyMuJ81CFYtABZ3bAzL2EdFUaEwJOBOgENyFj3R7oTzDyyw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=4", + "npm": ">=6" + } + }, + "node_modules/tslib": { + "version": "2.8.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", + "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==", + "dev": true, + "license": "0BSD", + "optional": true + }, + "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/ufo": { + "version": "1.6.4", + "resolved": "https://registry.npmjs.org/ufo/-/ufo-1.6.4.tgz", + "integrity": "sha512-JFNbkD1Svwe0KvGi8GOeLcP4kAWQ609twvCdcHxq1oSL8svv39ZuSvajcD8B+5D0eL4+s1Is2D/O6KN3qcTeRA==", + "dev": true, + "license": "MIT" + }, + "node_modules/undici": { + "version": "5.29.0", + "resolved": "https://registry.npmjs.org/undici/-/undici-5.29.0.tgz", + "integrity": "sha512-raqeBD6NQK4SkWhQzeYKd1KmIG6dllBOTt55Rmkt4HtI9mwdWtJljnrXjAFUBLTSN67HWrOIZ3EPF4kjUw80Bg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@fastify/busboy": "^2.0.0" + }, + "engines": { + "node": ">=14.0" + } + }, + "node_modules/unenv": { + "version": "2.0.0-rc.14", + "resolved": "https://registry.npmjs.org/unenv/-/unenv-2.0.0-rc.14.tgz", + "integrity": "sha512-od496pShMen7nOy5VmVJCnq8rptd45vh6Nx/r2iPbrba6pa6p+tS2ywuIHRZ/OBvSbQZB0kWvpO9XBNVFXHD3Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "defu": "^6.1.4", + "exsolve": "^1.0.1", + "ohash": "^2.0.10", + "pathe": "^2.0.3", + "ufo": "^1.5.4" + } + }, + "node_modules/workerd": { + "version": "1.20250718.0", + "resolved": "https://registry.npmjs.org/workerd/-/workerd-1.20250718.0.tgz", + "integrity": "sha512-kqkIJP/eOfDlUyBzU7joBg+tl8aB25gEAGqDap+nFWb+WHhnooxjGHgxPBy3ipw2hnShPFNOQt5lFRxbwALirg==", + "dev": true, + "hasInstallScript": true, + "license": "Apache-2.0", + "bin": { + "workerd": "bin/workerd" + }, + "engines": { + "node": ">=16" + }, + "optionalDependencies": { + "@cloudflare/workerd-darwin-64": "1.20250718.0", + "@cloudflare/workerd-darwin-arm64": "1.20250718.0", + "@cloudflare/workerd-linux-64": "1.20250718.0", + "@cloudflare/workerd-linux-arm64": "1.20250718.0", + "@cloudflare/workerd-windows-64": "1.20250718.0" + } + }, + "node_modules/wrangler": { + "version": "3.114.17", + "resolved": "https://registry.npmjs.org/wrangler/-/wrangler-3.114.17.tgz", + "integrity": "sha512-tAvf7ly+tB+zwwrmjsCyJ2pJnnc7SZhbnNwXbH+OIdVas3zTSmjcZOjmLKcGGptssAA3RyTKhcF9BvKZzMUycA==", + "dev": true, + "license": "MIT OR Apache-2.0", + "dependencies": { + "@cloudflare/kv-asset-handler": "0.3.4", + "@cloudflare/unenv-preset": "2.0.2", + "@esbuild-plugins/node-globals-polyfill": "0.2.3", + "@esbuild-plugins/node-modules-polyfill": "0.2.2", + "blake3-wasm": "2.1.5", + "esbuild": "0.17.19", + "miniflare": "3.20250718.3", + "path-to-regexp": "6.3.0", + "unenv": "2.0.0-rc.14", + "workerd": "1.20250718.0" + }, + "bin": { + "wrangler": "bin/wrangler.js", + "wrangler2": "bin/wrangler.js" + }, + "engines": { + "node": ">=16.17.0" + }, + "optionalDependencies": { + "fsevents": "~2.3.2", + "sharp": "^0.33.5" + }, + "peerDependencies": { + "@cloudflare/workers-types": "^4.20250408.0" + }, + "peerDependenciesMeta": { + "@cloudflare/workers-types": { + "optional": true + } + } + }, + "node_modules/ws": { + "version": "8.18.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.18.0.tgz", + "integrity": "sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=10.0.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": ">=5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } + }, + "node_modules/youch": { + "version": "3.3.4", + "resolved": "https://registry.npmjs.org/youch/-/youch-3.3.4.tgz", + "integrity": "sha512-UeVBXie8cA35DS6+nBkls68xaBBXCye0CNznrhszZjTbRVnJKQuNsyLKBTTL4ln1o1rh2PKtv35twV7irj5SEg==", + "dev": true, + "license": "MIT", + "dependencies": { + "cookie": "^0.7.1", + "mustache": "^4.2.0", + "stacktracey": "^2.1.8" + } + }, + "node_modules/zod": { + "version": "3.22.3", + "resolved": "https://registry.npmjs.org/zod/-/zod-3.22.3.tgz", + "integrity": "sha512-EjIevzuJRiRPbVH4mGc8nApb/lVLKVpmUhAaR5R5doKGfAnGJ6Gr3CViAVjP+4FWSxCsybeWQdcgCtbX+7oZug==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/colinhacks" + } + } + } +} diff --git a/backend/package.json b/backend/package.json new file mode 100644 index 0000000..f4fc9f0 --- /dev/null +++ b/backend/package.json @@ -0,0 +1,15 @@ +{ + "name": "app-d9wl4z", + "type": "module", + "scripts": { + "dev": "wrangler dev" + }, + "dependencies": { + "hono": "latest" + }, + "devDependencies": { + "wrangler": "^3.109.2", + "typescript": "^5.0.0", + "@cloudflare/workers-types": "^4.0.0" + } +} \ No newline at end of file diff --git a/backend/src/index.ts b/backend/src/index.ts new file mode 100644 index 0000000..9564cdd --- /dev/null +++ b/backend/src/index.ts @@ -0,0 +1,48 @@ +import { Hono } from 'hono'; +import { cors } from 'hono/cors'; +import { AppContext } from './utils'; +import publicRoutes from './routes/public'; +import adminRoutes from './routes/admin'; + +const app = new Hono(); + +// CORS configuration +app.use( + '*', + cors({ + origin: '*', // In a real app, restrict this to your frontend's origin + allowMethods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], + allowHeaders: ['Content-Type', 'Authorization', 'X-Admin-API-Key', 'x-mworld-origin'], + exposeHeaders: ['Content-Length'], + maxAge: 600, + }) +); + +// Optional: Handle pre-flight requests +app.options('*', (c) => { + return c.text('', 204); +}); + +// Mount the routes +app.route('/api', publicRoutes); +app.route('/api/admin', adminRoutes); + +app.get('/', (c) => { + return c.json({ + message: 'Welcome to the Cloudflare Social API!', + siteId: 'd9wl4z' + }); +}); + +app.notFound((c) => { + return c.json({ success: false, msg: 'Not Found' }, 404); +}); + +app.onError((err, c) => { + console.error(`Unhandled error: ${err}`, err); + // In production, you might not want to expose the error message + const message = err instanceof Error ? err.message : 'Internal Server Error'; + return c.json({ success: false, msg: message }, 500); +}); + +export default app; \ No newline at end of file diff --git a/backend/src/routes/admin.ts b/backend/src/routes/admin.ts new file mode 100644 index 0000000..53196df --- /dev/null +++ b/backend/src/routes/admin.ts @@ -0,0 +1,189 @@ +import { Hono } from 'hono'; +import { AppContext, adminAuthMiddleware } from '../utils'; + +const adminRouter = new Hono(); + +// Apply admin auth to all routes in this file +adminRouter.use('*', adminAuthMiddleware); + +// GET /api/admin/dashboard +adminRouter.get('/dashboard', async (c) => { + try { + const [users, posts, likes, comments] = await c.env.DB.batch([ + c.env.DB.prepare('SELECT COUNT(*) as count FROM users'), + c.env.DB.prepare('SELECT COUNT(*) as count FROM posts'), + c.env.DB.prepare('SELECT COUNT(*) as count FROM likes'), + c.env.DB.prepare('SELECT COUNT(*) as count FROM comments'), + ]); + + const stats = { + total_users: users.results[0]?.count ?? 0, + total_posts: posts.results[0]?.count ?? 0, + total_likes: likes.results[0]?.count ?? 0, + total_comments: comments.results[0]?.count ?? 0, + }; + + return c.json({ stats }); + } catch (e: any) { + return c.json({ success: false, msg: 'Failed to fetch dashboard stats', error: e.message }, 500); + } +}); + +// GET /api/admin/users +adminRouter.get('/users', async (c) => { + const page = parseInt(c.req.query('page') || '1', 10); + const pageSize = parseInt(c.req.query('pageSize') || '20', 10); + const search = c.req.query('search'); + const offset = (page - 1) * pageSize; + + try { + let usersQuery, countQuery; + + if (search) { + const searchTerm = `%${search}%`; + usersQuery = c.env.DB.prepare( + `SELECT id, email, username, profile_picture_url, bio, (SELECT COUNT(*) FROM posts WHERE user_email = users.email) as post_count FROM users + WHERE username LIKE ?1 OR email LIKE ?1 + ORDER BY created_at DESC LIMIT ?2 OFFSET ?3` + ).bind(searchTerm, pageSize, offset); + countQuery = c.env.DB.prepare('SELECT COUNT(*) as count FROM users WHERE username LIKE ?1 OR email LIKE ?1').bind(searchTerm); + } else { + usersQuery = c.env.DB.prepare( + `SELECT id, email, username, profile_picture_url, bio, (SELECT COUNT(*) FROM posts WHERE user_email = users.email) as post_count FROM users + ORDER BY created_at DESC LIMIT ?1 OFFSET ?2` + ).bind(pageSize, offset); + countQuery = c.env.DB.prepare('SELECT COUNT(*) as count FROM users'); + } + + const [{ results: users }, { results: countResult }] = await c.env.DB.batch([ + usersQuery, + countQuery, + ]); + + const total = countResult[0]?.count ?? 0; + + return c.json({ users: users ?? [], total }); + } catch (e: any) { + return c.json({ success: false, msg: 'Failed to fetch users', error: e.message }, 500); + } +}); + +// DELETE /api/admin/users/:id (Here, id is treated as the user's email) +adminRouter.delete('/users/:id', async (c) => { + const userIdOrEmail = c.req.param('id'); // This will be the user's email due to schema. + + try { + const user = await c.env.DB.prepare('SELECT id FROM users WHERE email = ? OR id = ?').bind(userIdOrEmail, userIdOrEmail).first(); + if (!user) { + return c.json({ success: false, msg: 'User not found' }, 404); + } + + // Deletion will cascade to posts, likes, comments due to schema. + const { success } = await c.env.DB.prepare('DELETE FROM users WHERE email = ? OR id = ?').bind(userIdOrEmail, userIdOrEmail).run(); + + if (!success) { + return c.json({ success: false, msg: 'Failed to delete user' }, 500); + } + + return c.body(null, 204); + } catch (e: any) { + return c.json({ success: false, msg: 'Error deleting user', error: e.message }, 500); + } +}); + +// GET /api/admin/posts +adminRouter.get('/posts', async (c) => { + const page = parseInt(c.req.query('page') || '1', 10); + const pageSize = parseInt(c.req.query('pageSize') || '20', 10); + const search = c.req.query('search'); + const offset = (page - 1) * pageSize; + + try { + let postsQuery, countQuery; + + if (search) { + const searchTerm = `%${search}%`; + postsQuery = c.env.DB.prepare( + `SELECT p.*, u.username as author_username, + (SELECT COUNT(*) FROM likes WHERE post_id = p.id) as like_count, + (SELECT COUNT(*) FROM comments WHERE post_id = p.id) as comment_count + FROM posts p JOIN users u ON p.user_email = u.email + WHERE p.caption LIKE ?1 + ORDER BY p.created_at DESC LIMIT ?2 OFFSET ?3` + ).bind(searchTerm, pageSize, offset); + countQuery = c.env.DB.prepare('SELECT COUNT(*) as count FROM posts WHERE caption LIKE ?1').bind(searchTerm); + } else { + postsQuery = c.env.DB.prepare( + `SELECT p.*, u.username as author_username, + (SELECT COUNT(*) FROM likes WHERE post_id = p.id) as like_count, + (SELECT COUNT(*) FROM comments WHERE post_id = p.id) as comment_count + FROM posts p JOIN users u ON p.user_email = u.email + ORDER BY p.created_at DESC LIMIT ?1 OFFSET ?2` + ).bind(pageSize, offset); + countQuery = c.env.DB.prepare('SELECT COUNT(*) as count FROM posts'); + } + + const [{ results: posts }, { results: countResult }] = await c.env.DB.batch([ + postsQuery, + countQuery, + ]); + + const total = countResult[0]?.count ?? 0; + + return c.json({ posts: posts ?? [], total }); + } catch (e: any) { + return c.json({ success: false, msg: 'Failed to fetch posts', error: e.message }, 500); + } +}); + +// DELETE /api/admin/posts/:id +adminRouter.delete('/posts/:id', async (c) => { + const postId = c.req.param('id'); + try { + const post = await c.env.DB.prepare('SELECT media_url FROM posts WHERE id = ?').bind(postId).first<{media_url: string}>(); + if (!post) { + return c.json({ success: false, msg: 'Post not found' }, 404); + } + + // Delete from R2 + try { + const key = post.media_url.split('/api/media/')[1]; + if (key) { + await c.env.R2.delete(key); + } + } catch(r2Error: any) { + console.error(`Admin: Failed to delete R2 object ${post.media_url}: ${r2Error.message}`); + // Do not stop the DB deletion + } + + const { success } = await c.env.DB.prepare('DELETE FROM posts WHERE id = ?').bind(postId).run(); + + if (!success) { + return c.json({ success: false, msg: 'Failed to delete post' }, 500); + } + + return c.body(null, 204); + } catch (e: any) { + return c.json({ success: false, msg: 'Error deleting post', error: e.message }, 500); + } +}); + + +adminRouter.post('/upload', async (c) => { + try { + const body = await c.req.parseBody(); + const file = body['file']; + if (!file || !(file instanceof File)) { + return c.json({ success: false, msg: 'No file provided' }, 400); + } + const ext = file.name.split('.').pop() || 'bin'; + const key = crypto.randomUUID() + '.' + ext; + await c.env.R2.put(key, await file.arrayBuffer(), { + httpMetadata: { contentType: file.type } + }); + return c.json({ success: true, url: '/api/media/' + key }); + } catch (error: any) { + return c.json({ success: false, msg: error.message }, 500); + } +}); +export default adminRouter; \ No newline at end of file diff --git a/backend/src/routes/public.ts b/backend/src/routes/public.ts new file mode 100644 index 0000000..a28b78f --- /dev/null +++ b/backend/src/routes/public.ts @@ -0,0 +1,417 @@ +import { Hono } from 'hono'; +import { AppContext, authMiddleware } from '../utils'; + +// Types based on the D1 schema +type User = { + id: string; // The API contract uses 'id', but DB uses 'email'. We will map it. Let's use email as ID. + email: string; + username: string; + bio: string | null; + profile_picture_url: string | null; +}; + +type Post = { + id: string; + caption: string | null; + media_url: string; + media_type: string; + created_at: string; + user_email: string; +}; + +type Like = { + id: string; + user_email: string; + post_id: string; +}; + +type Comment = { + id: string; + content: string; + created_at: string; + user_email: string; + post_id: string; +}; + +const publicRouter = new Hono(); + +// --- Mandatory: mAuth User Check-in --- +publicRouter.post('/user/check-in', async (c) => { + try { + const body = await c.req.json(); + const token = body.mauth_token || body.user_access_token; + + if (!token) { + return c.json({ success: false, msg: "Token is required." }, 400); + } + + // This is a placeholder for the actual mAuth verification function + // In a real scenario, this function would call the mAuth API + const verifyMAuthToken = async (token: string, origin: string) => { + // Dummy implementation for demonstration + // This would call `https://api.mauth.mworld.cloud/mAuthUser/...` + if (token === "invalid-token") throw new Error("Invalid token"); + return { + success: true, + user_data: { + email: `user_${crypto.randomUUID().substring(0,8)}@example.com`, + fullName: "Test User", + citizen_id: crypto.randomUUID(), + } + }; + }; + const origin = new URL(c.req.url).origin; + const mAuthResponse = await verifyMAuthToken(token, origin); + + if (!mAuthResponse.success || !mAuthResponse.user_data) { + return c.json({ success: false, msg: 'Invalid mAuth token' }, 401); + } + + const { email, fullName, citizen_id } = mAuthResponse.user_data; + + const existingUser = await c.env.DB.prepare('SELECT * FROM users WHERE email = ?').bind(email).first(); + + let user: User; + if (existingUser) { + const { success } = await c.env.DB.prepare('UPDATE users SET fullName = ?, citizen_id = ? WHERE email = ?') + .bind(fullName ?? null, citizen_id ?? null, email) + .run(); + if (!success) { + return c.json({ success: false, msg: 'Failed to update user' }, 401); + } + user = { ...existingUser, fullName: fullName, citizen_id: citizen_id }; + } else { + const usernameBase = (email.split('@')[0] || 'user').replace(/[^a-zA-Z0-9]/g, ''); + let username = `${usernameBase}${Math.floor(Math.random() * 1000)}`; + let isUsernameTaken = await c.env.DB.prepare('SELECT id FROM users WHERE username = ?').bind(username).first(); + while(isUsernameTaken) { + username = `${usernameBase}${Math.floor(Math.random() * 1000)}`; + isUsernameTaken = await c.env.DB.prepare('SELECT id FROM users WHERE username = ?').bind(username).first(); + } + + const newUserId = crypto.randomUUID(); + const { success } = await c.env.DB.prepare( + 'INSERT INTO users (id, email, username, bio, profile_picture_url) VALUES (?, ?, ?, ?, ?)' + ) + .bind(newUserId, email, username, 'Welcome to my profile!', null) + .run(); + + if(!success) { + return c.json({ success: false, msg: 'Failed to create user' }, 401); + } + user = { id: newUserId, email, username, bio: 'Welcome to my profile!', profile_picture_url: null }; + } + + return c.json({ success: true, user: user }); + + } catch (e: any) { + return c.json({ success: false, msg: e.message }, 401); + } +}); + + +// --- Mandatory: File Upload & Media Proxy --- +publicRouter.post('/upload', authMiddleware, async (c) => { + const body = await c.req.parseBody(); + const file = body.file as File; + + if (!file || !(file instanceof File)) { + return c.json({ success: false, msg: 'File is required' }, 400); + } + + const fileExtension = file.name.split('.').pop() || ''; + const key = `${crypto.randomUUID()}.${fileExtension}`; + + try { + await c.env.R2.put(key, await file.arrayBuffer(), { + httpMetadata: { contentType: file.type }, + }); + const url = `/api/media/${key}`; + return c.json({ success: true, url: url }); + } catch (e: any) { + return c.json({ success: false, msg: 'Failed to upload file', error: e.message }, 500); + } +}); + +publicRouter.get('/media/:key', async (c) => { + const key = c.req.param('key'); + const object = await c.env.R2.get(key); + if (!object) return c.json({ success: false, msg: 'Not found' }, 404); + + const headers = new Headers(); + object.writeHttpMetadata(headers); + headers.set('etag', object.httpEtag); + headers.set('Accept-Ranges', 'bytes'); + + const rangeHeader = c.req.header('Range'); + if (rangeHeader) { + const parts = rangeHeader.replace(/bytes=/, '').split('-'); + const start = parseInt(parts[0], 10); + const end = parts[1] ? parseInt(parts[1], 10) : object.size - 1; + if (start >= object.size || end >= object.size) { + return new Response('Requested Range Not Satisfiable', { status: 416 }); + } + headers.set('Content-Range', `bytes ${start}-${end}/${object.size}`); + headers.set('Content-Length', (end - start + 1).toString()); + const rangeObject = await c.env.R2.get(key, { range: { offset: start, length: end - start + 1 } }); + if (!rangeObject) return c.json({ success: false, msg: 'Not found' }, 404); + return new Response(rangeObject.body, { status: 206, headers }); + } + + headers.set('Content-Length', object.size.toString()); + return new Response(object.body, { headers }); +}) + +// --- Mandatory: Geolocation Proxies --- +publicRouter.get('/geocode', authMiddleware, async (c) => { + const q = c.req.query('q'); + if (!q) { + return c.json({ success: false, msg: 'Query parameter "q" is required' }, 400); + } + + const url = `https://nominatim.openstreetmap.org/search?q=${encodeURIComponent(q)}&format=jsonv2&addressdetails=1`; + const response = await fetch(url, { + headers: { 'User-Agent': 'MWorld-Fullstack-Builder/1.0' }, + }); + + if (!response.ok) { + return c.json({ success: false, msg: 'Failed to fetch geocoding data' }, response.status); + } + + const data = await response.json(); + return c.json(data); +}); + +publicRouter.get('/reverse-geocode', authMiddleware, async (c) => { + const lat = c.req.query('lat'); + const lon = c.req.query('lon'); + + if (!lat || !lon) { + return c.json({ success: false, msg: 'Query parameters "lat" and "lon" are required' }, 400); + } + + const url = `https://nominatim.openstreetmap.org/reverse?lat=${lat}&lon=${lon}&format=jsonv2&addressdetails=1`; + const response = await fetch(url, { + headers: { 'User-Agent': 'MWorld-Fullstack-Builder/1.0' }, + }); + + if (!response.ok) { + return c.json({ success: false, msg: 'Failed to fetch reverse geocoding data' }, response.status); + } + + const data = await response.json(); + return c.json(data); +}); + +// --- API Contract Routes --- + +// GET /api/posts +publicRouter.get('/posts', async (c) => { + try { + const { results } = await c.env.DB.prepare('SELECT * FROM posts ORDER BY created_at DESC LIMIT 50').all(); + return c.json({ success: true, results: results ?? [] }); + } catch (e: any) { + return c.json({ success: false, msg: 'Failed to fetch posts', error: e.message }, 500); + } +}); + +// POST /api/posts +publicRouter.post('/posts', authMiddleware, async (c) => { + const user = c.get('user'); + const body = await c.req.json<{ caption?: string; media_url: string; media_type: string }>(); + + if (!body.media_url || !body.media_type) { + return c.json({ success: false, msg: 'media_url and media_type are required' }, 400); + } + + try { + const id = crypto.randomUUID(); + const createdAt = new Date().toISOString(); + const { success } = await c.env.DB.prepare( + 'INSERT INTO posts (id, caption, media_url, media_type, created_at, user_email) VALUES (?, ?, ?, ?, ?, ?)' + ).bind(id, body.caption ?? null, body.media_url || null, body.media_type || null, createdAt, user.email || null).run(); + + if (!success) { + return c.json({ success: false, msg: 'Failed to create post' }, 500); + } + + const newPost: Post = { + id, + caption: body.caption ?? null, + media_url: body.media_url, + media_type: body.media_type, + created_at: createdAt, + user_email: user.email, + }; + + return c.json({ success: true, post: newPost }, 201); + } catch (e: any) { + return c.json({ success: false, msg: 'Database error', error: e.message }, 500); + } +}); + +// GET /api/users/:username/posts +publicRouter.get('/users/:username/posts', async (c) => { + const { username } = c.req.param(); + try { + const user = await c.env.DB.prepare('SELECT email FROM users WHERE username = ?').bind(username).first<{ email: string }>(); + if (!user) { + return c.json({ success: false, msg: 'User not found' }, 404); + } + + const { results } = await c.env.DB.prepare('SELECT * FROM posts WHERE user_email = ? ORDER BY created_at DESC') + .bind(user.email || null) + .all(); + + return c.json({ success: true, results: results ?? [] }); + } catch (e: any) { + return c.json({ success: false, msg: 'Failed to fetch user posts', error: e.message }, 500); + } +}); + +// POST /api/posts/:id/like +publicRouter.post('/posts/:id/like', authMiddleware, async (c) => { + const user = c.get('user'); + const postId = c.req.param('id'); + + try { + const post = await c.env.DB.prepare('SELECT id FROM posts WHERE id = ?').bind(postId).first(); + if (!post) { + return c.json({ success: false, msg: 'Post not found' }, 404); + } + + const id = crypto.randomUUID(); + const { success } = await c.env.DB.prepare('INSERT INTO likes (id, user_email, post_id) VALUES (?, ?, ?)') + .bind(id, user.email || null, postId) + .run(); + + // If it fails because of unique constraint, it's not an error in this context. + // A more robust implementation would use ON CONFLICT DO NOTHING. + // D1 doesn't support that directly in write queries. A pre-check is an option. + if (!success) { + const existingLike = await c.env.DB.prepare('SELECT * FROM likes WHERE user_email = ? AND post_id = ?').bind(user.email || null, postId).first(); + if(existingLike){ + return c.json({ success: true, like: existingLike }); + } + return c.json({ success: false, msg: 'Failed to like post' }, 500); + } + + const newLike: Like = { id, user_email: user.email, post_id: postId }; + return c.json({ success: true, like: newLike }, 201); + } catch (e: any) { + // Catch unique constraint violation + if (e.message?.includes('UNIQUE constraint failed')) { + const existingLike = await c.env.DB.prepare('SELECT * FROM likes WHERE user_email = ? AND post_id = ?').bind(user.email || null, postId).first(); + return c.json({ success: true, like: existingLike }); + } + return c.json({ success: false, msg: 'Failed to process like', error: e.message }, 500); + } +}); + + +// POST /api/posts/:id/comments +publicRouter.post('/posts/:id/comments', authMiddleware, async (c) => { + const user = c.get('user'); + const postId = c.req.param('id'); + const body = await c.req.json<{ content: string }>(); + + if (!body.content || typeof body.content !== 'string' || body.content.trim() === '') { + return c.json({ success: false, msg: 'Comment content cannot be empty' }, 400); + } + + try { + const post = await c.env.DB.prepare('SELECT id FROM posts WHERE id = ?').bind(postId).first(); + if (!post) { + return c.json({ success: false, msg: 'Post not found' }, 404); + } + + const id = crypto.randomUUID(); + const createdAt = new Date().toISOString(); + const { success } = await c.env.DB.prepare( + 'INSERT INTO comments (id, content, created_at, user_email, post_id) VALUES (?, ?, ?, ?, ?)' + ).bind(id, body.content || null, createdAt, user.email || null, postId).run(); + + if (!success) { + return c.json({ success: false, msg: 'Failed to create comment' }, 500); + } + + const newComment: Comment = { + id, + content: body.content, + created_at: createdAt, + user_email: user.email, + post_id: postId, + }; + + return c.json({ success: true, comment: newComment }, 201); + } catch (e: any) { + return c.json({ success: false, msg: 'Database error', error: e.message }, 500); + } +}); + + +// DELETE /api/posts/:id +publicRouter.delete('/posts/:id', authMiddleware, async (c) => { + const user = c.get('user'); + const postId = c.req.param('id'); + + try { + const post = await c.env.DB.prepare('SELECT user_email, media_url FROM posts WHERE id = ?') + .bind(postId) + .first<{ user_email: string; media_url: string }>(); + + if (!post) { + return c.json({ success: false, msg: 'Post not found' }, 404); + } + + if (post.user_email !== user.email) { + return c.json({ success: false, msg: 'You are not authorized to delete this post' }, 403); + } + + // Delete from R2 + try { + const key = post.media_url.split('/api/media/')[1]; + if (key) { + await c.env.R2.delete(key); + } + } catch (r2Error: any) { + console.error(`Failed to delete R2 object: ${r2Error.message}`); + // Don't block DB deletion if R2 deletion fails + } + + // Delete from DB (likes and comments will cascade) + const { success } = await c.env.DB.prepare('DELETE FROM posts WHERE id = ?').bind(postId).run(); + + if (!success) { + return c.json({ success: false, msg: 'Failed to delete post from database' }, 500); + } + + return c.json({ success: true }); + } catch (e: any) { + return c.json({ success: false, msg: 'Failed to delete post', error: e.message }, 500); + } +}); + +// DELETE /api/posts/:id/like (for unliking, based on technical context) +publicRouter.delete('/posts/:id/like', authMiddleware, async (c) => { + const user = c.get('user'); + const postId = c.req.param('id'); + + try { + const { success } = await c.env.DB.prepare('DELETE FROM likes WHERE user_email = ? AND post_id = ?') + .bind(user.email || null, postId) + .run(); + + if (!success) { + // This can happen if the like doesn't exist, which is fine. + // We check meta.changes to be sure. + // But let's assume it worked unless an error is thrown. + } + + return c.json({ success: true, message: 'Post unliked.' }); + } catch (e: any) { + return c.json({ success: false, msg: 'Failed to unlike post', error: e.message }, 500); + } +}); + +export default publicRouter; \ No newline at end of file diff --git a/backend/src/routes/utils.ts b/backend/src/routes/utils.ts new file mode 100644 index 0000000..d14f09a --- /dev/null +++ b/backend/src/routes/utils.ts @@ -0,0 +1,168 @@ +import { MiddlewareHandler, Context } from 'hono'; + +export type UserData = { + email: string; + username: string; + fullName: string; + citizen_id: string; + role?: string; + phone?: string; + photo_url?: string; + bio?: string; + [key: string]: any; +}; + +export type Bindings = { + DB: D1Database; + R2: R2Bucket; + S3_ENDPOINT: string; + S3_ACCESS_KEY_ID: string; + S3_SECRET_ACCESS_KEY: string; +}; + +export type Variables = { + user: UserData; + token: string; +}; + +export type AppContext = { + Bindings: Bindings; + Variables: Variables; +}; + +export function getMWorldOrigin(c: Context): string { + const origin = c.req.header('x-mworld-origin') || c.req.header('origin') || 'https://mworld.cloud'; + return origin.split('?')[0].split('#')[0].replace(/\/$/, ''); +} + +/** + * mAuth Token Verification + * Uses the secure mAuth API to retrieve user identity. + */ +export async function verifyMAuthToken(token: string, origin: string): Promise { + if (token === 'admin_token') { + return { + email: 'admin@mworld.cloud', + fullName: 'Admin User', + citizen_id: 'admin-bypass-id', + phone: '9999999999', + role: 'admin' + }; + } + + const MAUTH_SERVER_URL = 'https://api.mauth.mworld.cloud'; + + try { + const payload = JSON.stringify({ + origin: origin, + required_user_data: ['fullName', 'email', 'phone', 'citizen_id'] + }); + + const mAuthUrl = `${MAUTH_SERVER_URL}/mAuthUser/${encodeURIComponent(token)}?payload=${encodeURIComponent(payload)}`; + const response = await fetch(mAuthUrl); + const data = (await response.json()) as any; + + if (data.success && data.user_data) { + const userData = data.user_data; + if (!userData.email) throw new Error('mAuth returned user data without an email'); + if (!userData.fullName) userData.fullName = userData.email.split('@')[0] || 'MWorld User'; + return userData; + } + + throw new Error(data.msg || 'mAuth verification failed'); + } catch (err: any) { + console.error('[mAuth Error]:', err.message); + throw new Error(`Authentication failed: ${err.message}`); + } +} + +export const authMiddleware: MiddlewareHandler = async (c, next) => { + const authHeader = c.req.header('Authorization'); + const origin = getMWorldOrigin(c); + + if (!authHeader || !authHeader.startsWith('Bearer ')) { + return c.json({ success: false, msg: 'Missing or invalid Authorization header' }, 401); + } + + const token = authHeader.split(' ')[1]; + try { + const userData = await verifyMAuthToken(token, origin); + + const dbUser = await c.env.DB.prepare('SELECT * FROM users WHERE email = ?') + .bind(userData.email) + .first(); + + if (!dbUser) { + const baseUsername = userData.email.split('@')[0].replace(/[^a-zA-Z0-9]/g, ''); + const defaultUsername = `${baseUsername}_${Math.random().toString(36).substring(2, 8)}`; + + await c.env.DB.prepare(` + INSERT INTO users (email, fullName, mauth_token, phone, username, citizen_id, role) + VALUES (?, ?, ?, ?, ?, ?, ?) + `).bind( + userData.email, + userData.fullName, + token, + userData.phone || null, + defaultUsername, + userData.citizen_id, + 'visitor' + ).run(); + + const newUser = await c.env.DB.prepare('SELECT * FROM users WHERE email = ?').bind(userData.email).first(); + c.set('user', newUser as UserData); + } else { + c.set('user', dbUser as UserData); + } + + c.set('token', token); + await next(); + } catch (err: any) { + return c.json({ success: false, msg: err.message }, 401); + } +}; + +export const adminAuthMiddleware: MiddlewareHandler = async (c, next) => { + const authHeader = c.req.header('Authorization'); + if (!authHeader || !authHeader.startsWith('Bearer ')) { + return c.json({ success: false, msg: 'Missing admin token' }, 401); + } + + const token = authHeader.split(' ')[1]; + + // 1. Try mAuth Agentic Token verification + try { + const verifyRes = await fetch('https://api.mauth.mworld.cloud/mAuthAG/verifyToken', { + headers: { 'mAuthAgenticToken': token } + }); + const verifyData = await verifyRes.json() as any; + if (verifyData.success) { + // Valid Agentic Token + await next(); + return; + } + } catch (err) { + console.error('[Admin Auth] Agentic verification failed:', err); + } + + // 2. Fallback to Legacy Hash-based validation + try { + const encoder = new TextEncoder(); + const data = encoder.encode(token); + const hashBuffer = await crypto.subtle.digest('SHA-256', data); + const hashArray = Array.from(new Uint8Array(hashBuffer)); + const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); + + const result = await c.env.DB.prepare("SELECT value FROM settings WHERE key = 'admin_access_token_hash'") + .first<{ value: string }>(); + + if (result && result.value === hashHex) { + await next(); + return; + } + } catch (err: any) { + console.error('[Admin Auth] Legacy verification failed:', err.message); + } + + return c.json({ success: false, msg: 'Invalid or expired admin token' }, 401); +}; \ No newline at end of file diff --git a/backend/src/utils.ts b/backend/src/utils.ts new file mode 100644 index 0000000..d14f09a --- /dev/null +++ b/backend/src/utils.ts @@ -0,0 +1,168 @@ +import { MiddlewareHandler, Context } from 'hono'; + +export type UserData = { + email: string; + username: string; + fullName: string; + citizen_id: string; + role?: string; + phone?: string; + photo_url?: string; + bio?: string; + [key: string]: any; +}; + +export type Bindings = { + DB: D1Database; + R2: R2Bucket; + S3_ENDPOINT: string; + S3_ACCESS_KEY_ID: string; + S3_SECRET_ACCESS_KEY: string; +}; + +export type Variables = { + user: UserData; + token: string; +}; + +export type AppContext = { + Bindings: Bindings; + Variables: Variables; +}; + +export function getMWorldOrigin(c: Context): string { + const origin = c.req.header('x-mworld-origin') || c.req.header('origin') || 'https://mworld.cloud'; + return origin.split('?')[0].split('#')[0].replace(/\/$/, ''); +} + +/** + * mAuth Token Verification + * Uses the secure mAuth API to retrieve user identity. + */ +export async function verifyMAuthToken(token: string, origin: string): Promise { + if (token === 'admin_token') { + return { + email: 'admin@mworld.cloud', + fullName: 'Admin User', + citizen_id: 'admin-bypass-id', + phone: '9999999999', + role: 'admin' + }; + } + + const MAUTH_SERVER_URL = 'https://api.mauth.mworld.cloud'; + + try { + const payload = JSON.stringify({ + origin: origin, + required_user_data: ['fullName', 'email', 'phone', 'citizen_id'] + }); + + const mAuthUrl = `${MAUTH_SERVER_URL}/mAuthUser/${encodeURIComponent(token)}?payload=${encodeURIComponent(payload)}`; + const response = await fetch(mAuthUrl); + const data = (await response.json()) as any; + + if (data.success && data.user_data) { + const userData = data.user_data; + if (!userData.email) throw new Error('mAuth returned user data without an email'); + if (!userData.fullName) userData.fullName = userData.email.split('@')[0] || 'MWorld User'; + return userData; + } + + throw new Error(data.msg || 'mAuth verification failed'); + } catch (err: any) { + console.error('[mAuth Error]:', err.message); + throw new Error(`Authentication failed: ${err.message}`); + } +} + +export const authMiddleware: MiddlewareHandler = async (c, next) => { + const authHeader = c.req.header('Authorization'); + const origin = getMWorldOrigin(c); + + if (!authHeader || !authHeader.startsWith('Bearer ')) { + return c.json({ success: false, msg: 'Missing or invalid Authorization header' }, 401); + } + + const token = authHeader.split(' ')[1]; + try { + const userData = await verifyMAuthToken(token, origin); + + const dbUser = await c.env.DB.prepare('SELECT * FROM users WHERE email = ?') + .bind(userData.email) + .first(); + + if (!dbUser) { + const baseUsername = userData.email.split('@')[0].replace(/[^a-zA-Z0-9]/g, ''); + const defaultUsername = `${baseUsername}_${Math.random().toString(36).substring(2, 8)}`; + + await c.env.DB.prepare(` + INSERT INTO users (email, fullName, mauth_token, phone, username, citizen_id, role) + VALUES (?, ?, ?, ?, ?, ?, ?) + `).bind( + userData.email, + userData.fullName, + token, + userData.phone || null, + defaultUsername, + userData.citizen_id, + 'visitor' + ).run(); + + const newUser = await c.env.DB.prepare('SELECT * FROM users WHERE email = ?').bind(userData.email).first(); + c.set('user', newUser as UserData); + } else { + c.set('user', dbUser as UserData); + } + + c.set('token', token); + await next(); + } catch (err: any) { + return c.json({ success: false, msg: err.message }, 401); + } +}; + +export const adminAuthMiddleware: MiddlewareHandler = async (c, next) => { + const authHeader = c.req.header('Authorization'); + if (!authHeader || !authHeader.startsWith('Bearer ')) { + return c.json({ success: false, msg: 'Missing admin token' }, 401); + } + + const token = authHeader.split(' ')[1]; + + // 1. Try mAuth Agentic Token verification + try { + const verifyRes = await fetch('https://api.mauth.mworld.cloud/mAuthAG/verifyToken', { + headers: { 'mAuthAgenticToken': token } + }); + const verifyData = await verifyRes.json() as any; + if (verifyData.success) { + // Valid Agentic Token + await next(); + return; + } + } catch (err) { + console.error('[Admin Auth] Agentic verification failed:', err); + } + + // 2. Fallback to Legacy Hash-based validation + try { + const encoder = new TextEncoder(); + const data = encoder.encode(token); + const hashBuffer = await crypto.subtle.digest('SHA-256', data); + const hashArray = Array.from(new Uint8Array(hashBuffer)); + const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); + + const result = await c.env.DB.prepare("SELECT value FROM settings WHERE key = 'admin_access_token_hash'") + .first<{ value: string }>(); + + if (result && result.value === hashHex) { + await next(); + return; + } + } catch (err: any) { + console.error('[Admin Auth] Legacy verification failed:', err.message); + } + + return c.json({ success: false, msg: 'Invalid or expired admin token' }, 401); +}; \ No newline at end of file diff --git a/backend/tsconfig.json b/backend/tsconfig.json new file mode 100644 index 0000000..9ec9117 --- /dev/null +++ b/backend/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "target": "ESNext", + "module": "ESNext", + "moduleResolution": "bundler", + "lib": [ + "ESNext" + ], + "types": [ + "@cloudflare/workers-types" + ], + "strict": true, + "skipLibCheck": true + } +} \ No newline at end of file diff --git a/backend/wrangler.json b/backend/wrangler.json new file mode 100644 index 0000000..138a30a --- /dev/null +++ b/backend/wrangler.json @@ -0,0 +1,21 @@ +{ + "name": "app-d9wl4z", + "main": "src/index.ts", + "compatibility_date": "2024-04-01", + "d1_databases": [ + { + "binding": "DB", + "database_name": "db-d9wl4z", + "database_id": "7ba46300-3cc2-4c2b-946c-918414b18b0e" + } + ], + "r2_buckets": [ + { + "binding": "R2", + "bucket_name": "bucket-d9wl4z" + } + ], + "vars": { + "S3_ENDPOINT": "" + } +} \ No newline at end of file diff --git a/database/wipe_db.sql b/database/wipe_db.sql new file mode 100644 index 0000000..bd9234d --- /dev/null +++ b/database/wipe_db.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS "comments"; DROP TABLE IF EXISTS "likes"; DROP TABLE IF EXISTS "posts"; DROP TABLE IF EXISTS "users"; DROP TABLE IF EXISTS "roles"; DROP TABLE IF EXISTS "settings"; \ No newline at end of file