diff --git a/.env.example b/.env.example index 682c6f1..b9bb015 100644 --- a/.env.example +++ b/.env.example @@ -8,3 +8,7 @@ ADMIN_EMAILS="admin@winninghunter.local" # Authorized redirect URI: {NEXT_PUBLIC_APP_URL}/api/auth/google/callback GOOGLE_CLIENT_ID= GOOGLE_CLIENT_SECRET= + +# Apify Meta Ads ingestion (runtime secret; do not expose to the browser) +APIFY_TOKEN= +APIFY_ACTOR_ID=solidcode~meta-ads-library-scraper diff --git a/.env.production.example b/.env.production.example index a921946..4e1ace6 100644 --- a/.env.production.example +++ b/.env.production.example @@ -9,6 +9,10 @@ ADMIN_EMAILS="admin@winninghunter.local" GOOGLE_CLIENT_ID= GOOGLE_CLIENT_SECRET= +# Apify Meta Ads ingestion (runtime secret; do not expose to the browser) +APIFY_TOKEN= +APIFY_ACTOR_ID=solidcode~meta-ads-library-scraper + # For docker-compose POSTGRES_PASSWORD="change-this-long-random-password" PORT=3000 diff --git a/docker-compose.yml b/docker-compose.yml index c56e4cc..7ecf9b3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -29,6 +29,8 @@ services: ADMIN_EMAILS: admin@winninghunter.local GOOGLE_CLIENT_ID: ${GOOGLE_CLIENT_ID:-} GOOGLE_CLIENT_SECRET: ${GOOGLE_CLIENT_SECRET:-} + APIFY_TOKEN: ${APIFY_TOKEN:-} + APIFY_ACTOR_ID: ${APIFY_ACTOR_ID:-solidcode~meta-ads-library-scraper} ports: - "${PORT:-3000}:3000" command: sh -c "npx prisma db push && npm run start" diff --git a/package-lock.json b/package-lock.json index 871aadc..0ca08c0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,7 +24,7 @@ "postcss": "8.4.47", "prisma": "5.22.0", "tailwindcss": "3.4.13", - "tsx": "4.19.1", + "tsx": "4.23.4", "typescript": "^6.0.3" } }, @@ -52,9 +52,9 @@ } }, "node_modules/@esbuild/aix-ppc64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.23.1.tgz", - "integrity": "sha512-6VhYk1diRqrhBAqpJEdjASR/+WVRtfjpqKuNw11cLiaWpAT/Uu+nokB+UJnevzy/P9C/ty6AOe0dwueMrGh/iQ==", + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.28.1.tgz", + "integrity": "sha512-Svl7tq8k/08+p6CXPpRjQ1fKX+1odH/BQbb48fV6fj3CWHhsoIOoY87w1oHXm0qEpkIK3ZfVgp0hed3XBXzXMQ==", "cpu": [ "ppc64" ], @@ -69,9 +69,9 @@ } }, "node_modules/@esbuild/android-arm": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.23.1.tgz", - "integrity": "sha512-uz6/tEy2IFm9RYOyvKl88zdzZfwEfKZmnX9Cj1BHjeSGNuGLuMD1kR8y5bteYmwqKm1tj8m4cb/aKEorr6fHWQ==", + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.28.1.tgz", + "integrity": "sha512-0k2F129Xdio1TdJfzJ8sy1Q47vUD2NnwdhiAf7drUN1EBTfPf4hsFCtmMgu/6m8JSzsBrlmVjudMBQqOfG8usQ==", "cpu": [ "arm" ], @@ -86,9 +86,9 @@ } }, "node_modules/@esbuild/android-arm64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.23.1.tgz", - "integrity": "sha512-xw50ipykXcLstLeWH7WRdQuysJqejuAGPd30vd1i5zSyKK3WE+ijzHmLKxdiCMtH1pHz78rOg0BKSYOSB/2Khw==", + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.28.1.tgz", + "integrity": "sha512-34EGEbCIAgosYz6goLcopX6Mo7NyGv9tfwEM2/7Ce2VcVRk568iSvniGWcUXIy7wEDR1wzolcxcriFVrWYcwBg==", "cpu": [ "arm64" ], @@ -103,9 +103,9 @@ } }, "node_modules/@esbuild/android-x64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.23.1.tgz", - "integrity": "sha512-nlN9B69St9BwUoB+jkyU090bru8L0NA3yFvAd7k8dNsVH8bi9a8cUAUSEcEEgTp2z3dbEDGJGfP6VUnkQnlReg==", + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.28.1.tgz", + "integrity": "sha512-dbwY7ltSMDWsRatcRpCnES4F+im88OCUgGZjy52shC7GqHRE/cYlxNbB4Z4UpJswpcc4Qxd2oE/ufM0p61IKng==", "cpu": [ "x64" ], @@ -120,9 +120,9 @@ } }, "node_modules/@esbuild/darwin-arm64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.23.1.tgz", - "integrity": "sha512-YsS2e3Wtgnw7Wq53XXBLcV6JhRsEq8hkfg91ESVadIrzr9wO6jJDMZnCQbHm1Guc5t/CdDiFSSfWP58FNuvT3Q==", + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.28.1.tgz", + "integrity": "sha512-TZbWkQY7kvTAXbXUT7uVACR5cMHsDiSz9z7ZKAX/RTq/WJEk3QyRr0wZpNhBDX+/0CtdqUIJlOiodQcta6tY3Q==", "cpu": [ "arm64" ], @@ -137,9 +137,9 @@ } }, "node_modules/@esbuild/darwin-x64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.23.1.tgz", - "integrity": "sha512-aClqdgTDVPSEGgoCS8QDG37Gu8yc9lTHNAQlsztQ6ENetKEO//b8y31MMu2ZaPbn4kVsIABzVLXYLhCGekGDqw==", + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.28.1.tgz", + "integrity": "sha512-zfdzgK9ACBNZLI/CyHTOx81SyNbM6YXn7rxSgX97VjyiPl9W1i4Ka4fgKECEoFCKGpvBj5qArWIGgQjOwkgskQ==", "cpu": [ "x64" ], @@ -154,9 +154,9 @@ } }, "node_modules/@esbuild/freebsd-arm64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.23.1.tgz", - "integrity": "sha512-h1k6yS8/pN/NHlMl5+v4XPfikhJulk4G+tKGFIOwURBSFzE8bixw1ebjluLOjfwtLqY0kewfjLSrO6tN2MgIhA==", + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.28.1.tgz", + "integrity": "sha512-wG2EA8ENdEI0qhkSZMjfqrdY+ziCYCPMmtZjjIwOmXFjmyzEHn+UUxk5of+SYsjtfs3VpnlC7QLzSI5hY/rOAw==", "cpu": [ "arm64" ], @@ -171,9 +171,9 @@ } }, "node_modules/@esbuild/freebsd-x64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.23.1.tgz", - "integrity": "sha512-lK1eJeyk1ZX8UklqFd/3A60UuZ/6UVfGT2LuGo3Wp4/z7eRTRYY+0xOu2kpClP+vMTi9wKOfXi2vjUpO1Ro76g==", + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.28.1.tgz", + "integrity": "sha512-i7dZ9vQgnvSCzi/rYCXNgtF/U+eKZNJBzu3eTQbRgHnM7tNSizLOkRFAl3qzVc/Op/u5YkHHa4pf/3DOYHthLQ==", "cpu": [ "x64" ], @@ -188,9 +188,9 @@ } }, "node_modules/@esbuild/linux-arm": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.23.1.tgz", - "integrity": "sha512-CXXkzgn+dXAPs3WBwE+Kvnrf4WECwBdfjfeYHpMeVxWE0EceB6vhWGShs6wi0IYEqMSIzdOF1XjQ/Mkm5d7ZdQ==", + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.28.1.tgz", + "integrity": "sha512-qVXBOHQS+d5Y722GwJzJUtOLlX7km3CraOaGormF1pDtPd2C/l1SHRPgjLunLGe51Sh5YYWKMFDyV4SxgMQYTQ==", "cpu": [ "arm" ], @@ -205,9 +205,9 @@ } }, "node_modules/@esbuild/linux-arm64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.23.1.tgz", - "integrity": "sha512-/93bf2yxencYDnItMYV/v116zff6UyTjo4EtEQjUBeGiVpMmffDNUyD9UN2zV+V3LRV3/on4xdZ26NKzn6754g==", + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.28.1.tgz", + "integrity": "sha512-yHs+0uc8+nvEAfAfxrWQKK5peSNzBc4PegcMO0EJ2hT71uA7vB8Ihg2e77R2P7SG5uYjPbHlLLmve4LLLRCf0g==", "cpu": [ "arm64" ], @@ -222,9 +222,9 @@ } }, "node_modules/@esbuild/linux-ia32": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.23.1.tgz", - "integrity": "sha512-VTN4EuOHwXEkXzX5nTvVY4s7E/Krz7COC8xkftbbKRYAl96vPiUssGkeMELQMOnLOJ8k3BY1+ZY52tttZnHcXQ==", + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.28.1.tgz", + "integrity": "sha512-d1z4ZuP0ajrfz/FhGT4vv278rX8KnPPJx8i5+AtK7TYbx9Le9F1hyzurZpkEyjkGa9dUGhQow4C1NmeGvqxN2w==", "cpu": [ "ia32" ], @@ -239,9 +239,9 @@ } }, "node_modules/@esbuild/linux-loong64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.23.1.tgz", - "integrity": "sha512-Vx09LzEoBa5zDnieH8LSMRToj7ir/Jeq0Gu6qJ/1GcBq9GkfoEAoXvLiW1U9J1qE/Y/Oyaq33w5p2ZWrNNHNEw==", + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.28.1.tgz", + "integrity": "sha512-M5sRjUVZrkm1OAPR3dlOYzNmN+loZKGVi1VUQGrwuqLcbR6qeAz+famMhjASeH3YVKvZz+zT1jlh/keC3Rj/lg==", "cpu": [ "loong64" ], @@ -256,9 +256,9 @@ } }, "node_modules/@esbuild/linux-mips64el": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.23.1.tgz", - "integrity": "sha512-nrFzzMQ7W4WRLNUOU5dlWAqa6yVeI0P78WKGUo7lg2HShq/yx+UYkeNSE0SSfSure0SqgnsxPvmAUu/vu0E+3Q==", + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.28.1.tgz", + "integrity": "sha512-mRObBZeHh2OxcBFPWE/FjylkRgZdYuiTR3vaTozquCGOH14iP9oN4x4Ge81CoIDYQrXmIxpFumJBu5MtZpnQJQ==", "cpu": [ "mips64el" ], @@ -273,9 +273,9 @@ } }, "node_modules/@esbuild/linux-ppc64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.23.1.tgz", - "integrity": "sha512-dKN8fgVqd0vUIjxuJI6P/9SSSe/mB9rvA98CSH2sJnlZ/OCZWO1DJvxj8jvKTfYUdGfcq2dDxoKaC6bHuTlgcw==", + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.28.1.tgz", + "integrity": "sha512-slScBsMAb3GFDcdrCgLwZtPYRoH2H/youv10QiZyRjmsP48fznoveWytSgCI/R0ZcUgpc0ZhIUEx6LHts8yrfQ==", "cpu": [ "ppc64" ], @@ -290,9 +290,9 @@ } }, "node_modules/@esbuild/linux-riscv64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.23.1.tgz", - "integrity": "sha512-5AV4Pzp80fhHL83JM6LoA6pTQVWgB1HovMBsLQ9OZWLDqVY8MVobBXNSmAJi//Csh6tcY7e7Lny2Hg1tElMjIA==", + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.28.1.tgz", + "integrity": "sha512-kw0owk1o0GFETUJyW0jc0G4Yzs0BHZn0JDZ8JRT088vjJYX777BAs1fDGxAC+q831qOs2DTC96mNsG2opdfyyQ==", "cpu": [ "riscv64" ], @@ -307,9 +307,9 @@ } }, "node_modules/@esbuild/linux-s390x": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.23.1.tgz", - "integrity": "sha512-9ygs73tuFCe6f6m/Tb+9LtYxWR4c9yg7zjt2cYkjDbDpV/xVn+68cQxMXCjUpYwEkze2RcU/rMnfIXNRFmSoDw==", + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.28.1.tgz", + "integrity": "sha512-/lAIjX8aYFRByhh6L5rYtPEDRqa9de/4V/juOXcta5frjvzXO4/sqEtyytse0g3zZFuWu5cDN0MkLz2qRDD2Ag==", "cpu": [ "s390x" ], @@ -324,9 +324,9 @@ } }, "node_modules/@esbuild/linux-x64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.23.1.tgz", - "integrity": "sha512-EV6+ovTsEXCPAp58g2dD68LxoP/wK5pRvgy0J/HxPGB009omFPv3Yet0HiaqvrIrgPTBuC6wCH1LTOY91EO5hQ==", + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.28.1.tgz", + "integrity": "sha512-u/anNYF2mmVOEDwLtnQ1wOr3EZ9sTNGLWrsYGYwHWzGA3Si84IOkHXlbWTD1NB+9/1lcnweYKO54uhxZydNzfA==", "cpu": [ "x64" ], @@ -340,10 +340,27 @@ "node": ">=18" } }, + "node_modules/@esbuild/netbsd-arm64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.28.1.tgz", + "integrity": "sha512-oks0DYbLwWMmaakTsCb+zL4E+aHRVLom9IJZOAthMQEPiQmydXHkziYEsGYRx0uNV/IjEKGAV941JzH02pflqw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, "node_modules/@esbuild/netbsd-x64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.23.1.tgz", - "integrity": "sha512-aevEkCNu7KlPRpYLjwmdcuNz6bDFiE7Z8XC4CPqExjTvrHugh28QzUXVOZtiYghciKUacNktqxdpymplil1beA==", + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.28.1.tgz", + "integrity": "sha512-aeL6lAnN89Hz43Mlh1G8ARasbuoYvSITDEx0tHh5b7jJnHcssqgjy9Yx430GDpmCa6OyrKoS0aNRjKundRizGg==", "cpu": [ "x64" ], @@ -358,9 +375,9 @@ } }, "node_modules/@esbuild/openbsd-arm64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.23.1.tgz", - "integrity": "sha512-3x37szhLexNA4bXhLrCC/LImN/YtWis6WXr1VESlfVtVeoFJBRINPJ3f0a/6LV8zpikqoUg4hyXw0sFBt5Cr+Q==", + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.28.1.tgz", + "integrity": "sha512-MEFJe5C3R8pwXdZ5Y21oo6m7ePiS0d9pWucn99O/wvyJZChoIQKrQDxKrGeW8F5+T0okTHesAmDeiHDTIq0V/Q==", "cpu": [ "arm64" ], @@ -375,9 +392,9 @@ } }, "node_modules/@esbuild/openbsd-x64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.23.1.tgz", - "integrity": "sha512-aY2gMmKmPhxfU+0EdnN+XNtGbjfQgwZj43k8G3fyrDM/UdZww6xrWxmDkuz2eCZchqVeABjV5BpildOrUbBTqA==", + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.28.1.tgz", + "integrity": "sha512-i/ZLIOafE0Z8cI/XANJAixoJL/uRAoS2xOA3rb0xN+KK0K177cMAsQYkzHtBrtMXAKuAc7HGgcWiZ/sRC1Nxgw==", "cpu": [ "x64" ], @@ -391,10 +408,27 @@ "node": ">=18" } }, + "node_modules/@esbuild/openharmony-arm64": { + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.28.1.tgz", + "integrity": "sha512-ge+Z7EXFNt2BO1oAMsVpiQ8EwndV9i1xXerAeTIK7AtPs3bKFXQM7nlRxDSIUIMeueR1CNXxqztLzdNeReKBJg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ], + "engines": { + "node": ">=18" + } + }, "node_modules/@esbuild/sunos-x64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.23.1.tgz", - "integrity": "sha512-RBRT2gqEl0IKQABT4XTj78tpk9v7ehp+mazn2HbUeZl1YMdaGAQqhapjGTCe7uw7y0frDi4gS0uHzhvpFuI1sA==", + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.28.1.tgz", + "integrity": "sha512-BEjgtECkL3vY+SaSQ6nzVfiALUeFxpawyp8Jmf5PtYhf1Ug40N1h/hxlhts+f1FvSvarEigdxS3BlSMI2PJLcQ==", "cpu": [ "x64" ], @@ -409,9 +443,9 @@ } }, "node_modules/@esbuild/win32-arm64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.23.1.tgz", - "integrity": "sha512-4O+gPR5rEBe2FpKOVyiJ7wNDPA8nGzDuJ6gN4okSA1gEOYZ67N8JPk58tkWtdtPeLz7lBnY6I5L3jdsr3S+A6A==", + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.28.1.tgz", + "integrity": "sha512-lCv9eK/H6ZJWbE7bh2nw54CZ9M2nupBxJcTsdk/QQnWkdSjKGuxmmH8/GWrlT1eMmZfn4dGcCjRte397WqfQXA==", "cpu": [ "arm64" ], @@ -426,9 +460,9 @@ } }, "node_modules/@esbuild/win32-ia32": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.23.1.tgz", - "integrity": "sha512-BcaL0Vn6QwCwre3Y717nVHZbAa4UBEigzFm6VdsVdT/MbZ38xoj1X9HPkZhbmaBGUD1W8vxAfffbDe8bA6AKnQ==", + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.28.1.tgz", + "integrity": "sha512-zvb/mB2bSCoJOpoCBgYKKpX6YM6mJBlBUVUtVj41DlZJVEB6/0CKlRYxP5wWl1C1ILiCoAU5wZZ4q1P3qeS6Eg==", "cpu": [ "ia32" ], @@ -443,9 +477,9 @@ } }, "node_modules/@esbuild/win32-x64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.23.1.tgz", - "integrity": "sha512-BHpFFeslkWrXWyUPnbKm+xYYVYruCinGcftSBaa8zoF9hZO4BcSCFUvHVTtzpIY6YzUnYtuEhZ+C9iEXjxnasg==", + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.28.1.tgz", + "integrity": "sha512-bm4Mowrv+GXMlpWX++EcXw/iLyd1o3+bJkC2DkWXYVvgZCqD/bSj9ctZeAMC3cIxgjRVR2Dufaiu4YPxr5gW1A==", "cpu": [ "x64" ], @@ -1540,9 +1574,9 @@ } }, "node_modules/esbuild": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.23.1.tgz", - "integrity": "sha512-VVNz/9Sa0bs5SELtn3f7qhJCDPCF5oMEl5cO9/SSinpE9hbPVvxbd572HH5AKiP7WD8INO53GgfDDhRjkylHEg==", + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.28.1.tgz", + "integrity": "sha512-HrJrvZv5ayxBzPfwphOoNzkzOIIlifzk0KJrGK2c8R4+LKpMtpYLQeUdjnwjWv/LZlkH2laZk+4w78pi99D4Vw==", "dev": true, "hasInstallScript": true, "license": "MIT", @@ -1553,30 +1587,32 @@ "node": ">=18" }, "optionalDependencies": { - "@esbuild/aix-ppc64": "0.23.1", - "@esbuild/android-arm": "0.23.1", - "@esbuild/android-arm64": "0.23.1", - "@esbuild/android-x64": "0.23.1", - "@esbuild/darwin-arm64": "0.23.1", - "@esbuild/darwin-x64": "0.23.1", - "@esbuild/freebsd-arm64": "0.23.1", - "@esbuild/freebsd-x64": "0.23.1", - "@esbuild/linux-arm": "0.23.1", - "@esbuild/linux-arm64": "0.23.1", - "@esbuild/linux-ia32": "0.23.1", - "@esbuild/linux-loong64": "0.23.1", - "@esbuild/linux-mips64el": "0.23.1", - "@esbuild/linux-ppc64": "0.23.1", - "@esbuild/linux-riscv64": "0.23.1", - "@esbuild/linux-s390x": "0.23.1", - "@esbuild/linux-x64": "0.23.1", - "@esbuild/netbsd-x64": "0.23.1", - "@esbuild/openbsd-arm64": "0.23.1", - "@esbuild/openbsd-x64": "0.23.1", - "@esbuild/sunos-x64": "0.23.1", - "@esbuild/win32-arm64": "0.23.1", - "@esbuild/win32-ia32": "0.23.1", - "@esbuild/win32-x64": "0.23.1" + "@esbuild/aix-ppc64": "0.28.1", + "@esbuild/android-arm": "0.28.1", + "@esbuild/android-arm64": "0.28.1", + "@esbuild/android-x64": "0.28.1", + "@esbuild/darwin-arm64": "0.28.1", + "@esbuild/darwin-x64": "0.28.1", + "@esbuild/freebsd-arm64": "0.28.1", + "@esbuild/freebsd-x64": "0.28.1", + "@esbuild/linux-arm": "0.28.1", + "@esbuild/linux-arm64": "0.28.1", + "@esbuild/linux-ia32": "0.28.1", + "@esbuild/linux-loong64": "0.28.1", + "@esbuild/linux-mips64el": "0.28.1", + "@esbuild/linux-ppc64": "0.28.1", + "@esbuild/linux-riscv64": "0.28.1", + "@esbuild/linux-s390x": "0.28.1", + "@esbuild/linux-x64": "0.28.1", + "@esbuild/netbsd-arm64": "0.28.1", + "@esbuild/netbsd-x64": "0.28.1", + "@esbuild/openbsd-arm64": "0.28.1", + "@esbuild/openbsd-x64": "0.28.1", + "@esbuild/openharmony-arm64": "0.28.1", + "@esbuild/sunos-x64": "0.28.1", + "@esbuild/win32-arm64": "0.28.1", + "@esbuild/win32-ia32": "0.28.1", + "@esbuild/win32-x64": "0.28.1" } }, "node_modules/escalade": { @@ -1681,19 +1717,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/get-tsconfig": { - "version": "4.14.0", - "resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.14.0.tgz", - "integrity": "sha512-yTb+8DXzDREzgvYmh6s9vHsSVCHeC0G3PI5bEXNBHtmshPnO+S5O7qgLEOn0I5QvMy6kpZN8K1NKGyilLb93wA==", - "dev": true, - "license": "MIT", - "dependencies": { - "resolve-pkg-maps": "^1.0.0" - }, - "funding": { - "url": "https://github.com/privatenumber/get-tsconfig?sponsor=1" - } - }, "node_modules/glob-parent": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz", @@ -2267,16 +2290,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "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/reusify": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.1.0.tgz", @@ -2629,14 +2642,13 @@ "license": "0BSD" }, "node_modules/tsx": { - "version": "4.19.1", - "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.19.1.tgz", - "integrity": "sha512-0flMz1lh74BR4wOvBjuh9olbnwqCPc35OOlfyzHba0Dc+QNUeWX/Gq2YTbnwcWPO3BMd8fkzRVrHcsR+a7z7rA==", + "version": "4.23.4", + "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.23.4.tgz", + "integrity": "sha512-ZiUQ8oT/KzN51mJUWPqARYqwFLFJZtGZipRkw1ynHMr9vy3eU77m5yfF3Gzm6meEg/beW+lUu3fHYgskTN2oVQ==", "dev": true, "license": "MIT", "dependencies": { - "esbuild": "~0.23.0", - "get-tsconfig": "^4.7.5" + "esbuild": "~0.28.0" }, "bin": { "tsx": "dist/cli.mjs" diff --git a/package.json b/package.json index 8a4d6f8..2c773f1 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "postcss": "8.4.47", "prisma": "5.22.0", "tailwindcss": "3.4.13", - "tsx": "4.19.1", + "tsx": "4.23.4", "typescript": "^6.0.3" } } diff --git a/src/app/api/admin/ingest/apify/route.ts b/src/app/api/admin/ingest/apify/route.ts new file mode 100644 index 0000000..0bff621 --- /dev/null +++ b/src/app/api/admin/ingest/apify/route.ts @@ -0,0 +1,44 @@ +import { NextResponse } from "next/server"; +import { z } from "zod"; +import { getApiAdmin, requestAuditContext } from "@/lib/admin-api"; +import { importApifyAds, runApifyActor } from "@/lib/apify"; +import { prisma } from "@/lib/db"; + +const schema = z.object({ + searchTerms: z.array(z.string().trim().min(2).max(100)).min(1).max(10), + country: z.string().trim().toUpperCase().refine((value) => value === "ALL" || /^[A-Z]{2}$/.test(value)), + adActiveStatus: z.enum(["ACTIVE", "INACTIVE", "ALL"]).default("ACTIVE"), + mediaType: z.enum(["ALL", "IMAGE", "VIDEO", "MEME", "NONE"]).default("ALL"), + maxResults: z.coerce.number().int().min(1).max(1000).default(100), + scrapeAdDetails: z.boolean().default(true), + includeAboutPage: z.boolean().default(false), + maxCostUsd: z.coerce.number().min(0.1).max(10).default(1) +}); + +export async function POST(request: Request) { + const actor = await getApiAdmin(); + if (!actor) return NextResponse.json({ error: "FORBIDDEN" }, { status: 403 }); + const parsed = schema.safeParse(await request.json().catch(() => null)); + if (!parsed.success) return NextResponse.json({ error: "INVALID_INPUT" }, { status: 400 }); + const auditContext = requestAuditContext(request); + const job = await prisma.ingestJob.create({ + data: { source: "apify", type: "meta-ads-library", status: "RUNNING", startedAt: new Date(), metadata: { searchTerms: parsed.data.searchTerms, country: parsed.data.country, maxResults: parsed.data.maxResults } } + }); + try { + const records = await runApifyActor(parsed.data); + const result = await importApifyAds(records); + await prisma.$transaction([ + prisma.ingestJob.update({ where: { id: job.id }, data: { status: "COMPLETED", finishedAt: new Date(), recordsImported: result.imported, recordsFailed: result.failed, metadata: { searchTerms: parsed.data.searchTerms, country: parsed.data.country, received: records.length } } }), + prisma.adminAuditLog.create({ data: { actorId: actor.id, actorEmail: actor.email, action: "APIFY_INGEST_COMPLETED", targetType: "IngestJob", targetId: job.id, summary: `${result.imported} Meta reklamı Apify üzerinden işlendi.`, details: { ...result, received: records.length, searchTerms: parsed.data.searchTerms, country: parsed.data.country }, ...auditContext } }) + ]); + return NextResponse.json({ ok: true, jobId: job.id, ...result, received: records.length }); + } catch (error) { + const code = error instanceof Error && /^APIFY_[A-Z0-9_]+$/.test(error.message) ? error.message : "APIFY_INGEST_FAILED"; + await prisma.$transaction([ + prisma.ingestJob.update({ where: { id: job.id }, data: { status: "FAILED", finishedAt: new Date(), errorMessage: code } }), + prisma.adminAuditLog.create({ data: { actorId: actor.id, actorEmail: actor.email, action: "APIFY_INGEST_FAILED", targetType: "IngestJob", targetId: job.id, summary: `Apify ingest başarısız: ${code}`, details: { searchTerms: parsed.data.searchTerms, country: parsed.data.country }, ...auditContext } }) + ]); + return NextResponse.json({ error: code }, { status: code === "APIFY_NOT_CONFIGURED" ? 503 : 502 }); + } +} + diff --git a/src/app/dashboard/admin/data/page.tsx b/src/app/dashboard/admin/data/page.tsx index c6d647a..4f70755 100644 --- a/src/app/dashboard/admin/data/page.tsx +++ b/src/app/dashboard/admin/data/page.tsx @@ -2,9 +2,10 @@ import { requireAdmin } from "@/lib/auth/current-user"; import { prisma } from "@/lib/db"; import { Card } from "@/components/ui/card"; import { AdminNav } from "@/components/admin/admin-nav"; +import { ApifyIngestForm } from "@/components/admin/apify-ingest-form"; export default async function AdminDataPage() { await requireAdmin(); const [ads, stores, users, jobs] = await Promise.all([prisma.ad.count(), prisma.store.count(), prisma.user.count(), prisma.ingestJob.findMany({ orderBy: { createdAt: "desc" }, take: 10 })]); - return

Veri İşleri

Reklam, mağaza ve ingest operasyonları.

{ads}
Ads
{stores}
Stores
{users}
Users

Ingest Jobs

{jobs.map((j) =>
{j.source} · {j.type} · {j.status} · {j.recordsImported} records
)}
; + return

Veri İşleri

Reklam, mağaza ve ingest operasyonları.

{ads}
Ads
{stores}
Stores
{users}
Users

Apify · Meta Ads Library

Anahtar kelimeyle gerçek Meta reklamlarını çekin. Her çalışmada maliyet üst sınırı uygulanır ve tekrar eden reklamlar güncellenir.

Ingest Jobs

{jobs.map((j) =>
{j.source} · {j.type}
{j.status} · {j.recordsImported} başarılı · {j.recordsFailed} hatalı
{j.errorMessage &&
{j.errorMessage}
}
)}{!jobs.length &&

Henüz ingest işi yok.

}
; } diff --git a/src/components/admin/apify-ingest-form.tsx b/src/components/admin/apify-ingest-form.tsx new file mode 100644 index 0000000..64caca0 --- /dev/null +++ b/src/components/admin/apify-ingest-form.tsx @@ -0,0 +1,52 @@ +"use client"; + +import { FormEvent, useState } from "react"; +import { useRouter } from "next/navigation"; + +export function ApifyIngestForm({ configured }: { configured: boolean }) { + const router = useRouter(); + const [busy, setBusy] = useState(false); + const [message, setMessage] = useState(""); + const [error, setError] = useState(false); + + async function submit(event: FormEvent) { + event.preventDefault(); + const form = new FormData(event.currentTarget); + const searchTerms = String(form.get("searchTerms") || "").split(",").map((term) => term.trim()).filter(Boolean); + const maxResults = Number(form.get("maxResults")); + const maxCostUsd = Number(form.get("maxCostUsd")); + if (!window.confirm(`${searchTerms.join(", ")} için en fazla ${maxResults} reklam çekilsin mi? Apify harcama üst sınırı $${maxCostUsd.toFixed(2)}.`)) return; + setBusy(true); setMessage(""); + try { + const response = await fetch("/api/admin/ingest/apify", { + method: "POST", headers: { "content-type": "application/json" }, + body: JSON.stringify({ searchTerms, country: form.get("country"), adActiveStatus: form.get("adActiveStatus"), mediaType: form.get("mediaType"), maxResults, maxCostUsd, scrapeAdDetails: form.get("scrapeAdDetails") === "on", includeAboutPage: form.get("includeAboutPage") === "on" }) + }); + const data = await response.json().catch(() => ({})); + if (!response.ok) throw new Error(data.error || "APIFY_INGEST_FAILED"); + setError(false); setMessage(`${data.imported} reklam işlendi, ${data.failed} kayıt atlandı.`); router.refresh(); + } catch (caught) { + setError(true); setMessage(caught instanceof Error ? caught.message : "İşlem başarısız"); + } finally { setBusy(false); } + } + + return ( +
+ +
+ + +
+
+ + +
+ + + + + {message &&

{message}

} +
+ ); +} + diff --git a/src/lib/apify.ts b/src/lib/apify.ts new file mode 100644 index 0000000..d3d9d42 --- /dev/null +++ b/src/lib/apify.ts @@ -0,0 +1,215 @@ +import { AdSource, AdStatus, MediaType, Prisma } from "@prisma/client"; +import { prisma } from "@/lib/db"; + +const APIFY_API_BASE = "https://api.apify.com/v2"; +const DEFAULT_ACTOR_ID = "solidcode~meta-ads-library-scraper"; + +export type ApifyIngestInput = { + searchTerms: string[]; + country: string; + adActiveStatus: "ACTIVE" | "INACTIVE" | "ALL"; + mediaType: "ALL" | "IMAGE" | "VIDEO" | "MEME" | "NONE"; + maxResults: number; + scrapeAdDetails: boolean; + includeAboutPage: boolean; + maxCostUsd: number; +}; + +type JsonRecord = Record; + +function stringValue(record: JsonRecord, ...keys: string[]) { + for (const key of keys) { + const value = record[key]; + if (typeof value === "string" && value.trim()) return value.trim(); + } + return null; +} + +function numberValue(value: unknown) { + if (typeof value === "number" && Number.isFinite(value)) return Math.round(value); + if (typeof value === "string" && value.trim() && Number.isFinite(Number(value))) return Math.round(Number(value)); + if (value && typeof value === "object") { + const object = value as JsonRecord; + return numberValue(object.lower_bound ?? object.lowerBound ?? object.min); + } + return null; +} + +function stringArray(record: JsonRecord, ...keys: string[]) { + for (const key of keys) { + const value = record[key]; + if (Array.isArray(value)) return value.filter((item): item is string => typeof item === "string" && item.length > 0); + } + return []; +} + +function dateValue(value: unknown) { + if (typeof value !== "string" || !value) return null; + const date = new Date(value); + return Number.isNaN(date.getTime()) ? null : date; +} + +function firstMediaUrl(record: JsonRecord) { + const arrays = ["videoUrls", "videos", "imageUrls", "images", "videoPreviewImageUrls"]; + for (const key of arrays) { + const values = stringArray(record, key); + if (values[0]) return values[0]; + } + return stringValue(record, "videoHdUrl", "videoUrl", "imageUrl", "adSnapshotUrl", "snapshotUrl"); +} + +function firstThumbnailUrl(record: JsonRecord) { + for (const key of ["videoPreviewImageUrls", "imageUrls", "images"]) { + const values = stringArray(record, key); + if (values[0]) return values[0]; + } + return stringValue(record, "thumbnailUrl", "imageUrl", "pageProfilePictureURL"); +} + +function mappedMediaType(record: JsonRecord): MediaType { + const raw = stringValue(record, "mediaType", "media_type", "adFormat")?.toUpperCase(); + if (raw === "VIDEO") return MediaType.VIDEO; + if (raw === "IMAGE" || raw === "MEME") return MediaType.IMAGE; + if (raw === "CAROUSEL" || raw === "DPA") return MediaType.CAROUSEL; + if (stringArray(record, "videoUrls", "videos").length) return MediaType.VIDEO; + if (stringArray(record, "imageUrls", "images").length) return MediaType.IMAGE; + return MediaType.UNKNOWN; +} + +export function normalizeApifyAd(record: JsonRecord) { + const externalAdId = stringValue(record, "adArchiveID", "adArchiveId", "ad_archive_id", "id"); + if (!externalAdId) return null; + const pageId = stringValue(record, "pageID", "pageId", "page_id"); + const pageName = stringValue(record, "pageName", "page_name", "advertiserName") || "Bilinmeyen reklamveren"; + const firstSeenAt = dateValue(record.startDate ?? record.start_date ?? record.adDeliveryStartTime); + const endDate = dateValue(record.endDate ?? record.end_date ?? record.adDeliveryStopTime); + const referenceDate = endDate || new Date(); + const daysRunning = firstSeenAt ? Math.max(1, Math.ceil((referenceDate.getTime() - firstSeenAt.getTime()) / 86_400_000)) : null; + const statusText = stringValue(record, "adStatus", "status", "ad_active_status")?.toUpperCase(); + const status = statusText === "ACTIVE" ? AdStatus.ACTIVE : statusText === "INACTIVE" ? AdStatus.INACTIVE : AdStatus.UNKNOWN; + const primaryText = stringValue(record, "adText", "primaryText", "bodyText") || stringArray(record, "adCreativeBodies", "ad_creative_bodies")[0] || null; + const countries = stringArray(record, "countries", "reachedCountries", "ad_reached_countries"); + const country = stringValue(record, "country", "pageCountry"); + if (!countries.length && country) countries.push(country); + + return { + externalAdId, + pageId, + pageName, + pageUrl: stringValue(record, "pageURL", "pageUrl"), + pageLogoUrl: stringValue(record, "pageProfilePictureURL", "pageProfilePictureUrl"), + pageLikes: numberValue(record.pageLikes), + pageFollowers: numberValue(record.pageInstagramFollowers), + status, + mediaType: mappedMediaType(record), + primaryText, + headline: stringValue(record, "ctaHeadline", "headline", "title"), + description: stringValue(record, "ctaDescription", "description"), + ctaText: stringValue(record, "ctaText", "ctaType", "callToAction"), + landingUrl: stringValue(record, "ctaUrl", "landingUrl", "linkUrl"), + productUrl: stringValue(record, "adLibraryURL", "adLibraryUrl"), + language: stringValue(record, "language"), + countries, + firstSeenAt, + lastSeenAt: endDate, + createdAtSource: dateValue(record.adCreationTime ?? record.ad_creation_time), + daysRunning, + estimatedReachMin: numberValue(record.reachEstimate), + estimatedSpendMin: numberValue(record.spend), + creativeUrl: firstMediaUrl(record), + thumbnailUrl: firstThumbnailUrl(record), + raw: record as Prisma.InputJsonValue + }; +} + +function apifyConfig() { + const token = process.env.APIFY_TOKEN?.trim(); + const actorId = (process.env.APIFY_ACTOR_ID?.trim() || DEFAULT_ACTOR_ID).replace("/", "~"); + if (!token) throw new Error("APIFY_NOT_CONFIGURED"); + if (!/^[a-zA-Z0-9_-]+~[a-zA-Z0-9_-]+$/.test(actorId)) throw new Error("APIFY_ACTOR_INVALID"); + return { token, actorId }; +} + +export async function runApifyActor(input: ApifyIngestInput) { + const { token, actorId } = apifyConfig(); + const query = new URLSearchParams({ + clean: "true", + timeout: "180", + maxItems: String(input.maxResults), + maxTotalChargeUsd: String(input.maxCostUsd) + }); + const controller = new AbortController(); + const timeout = setTimeout(() => controller.abort(), 210_000); + try { + const response = await fetch(`${APIFY_API_BASE}/actors/${actorId}/run-sync-get-dataset-items?${query}`, { + method: "POST", + headers: { authorization: `Bearer ${token}`, "content-type": "application/json", accept: "application/json" }, + body: JSON.stringify({ + searchTerms: input.searchTerms, + country: input.country, + adActiveStatus: input.adActiveStatus, + mediaType: input.mediaType, + adType: "ALL", + maxResults: input.maxResults, + scrapeAdDetails: input.scrapeAdDetails, + includeAboutPage: input.includeAboutPage + }), + signal: controller.signal, + cache: "no-store" + }); + if (!response.ok) throw new Error(`APIFY_HTTP_${response.status}`); + const payload: unknown = await response.json(); + if (!Array.isArray(payload)) throw new Error("APIFY_INVALID_RESPONSE"); + return payload.filter((item): item is JsonRecord => Boolean(item) && typeof item === "object" && !Array.isArray(item)); + } catch (error) { + if (error instanceof Error && error.name === "AbortError") throw new Error("APIFY_TIMEOUT"); + throw error; + } finally { + clearTimeout(timeout); + } +} + +export async function importApifyAds(records: JsonRecord[]) { + let imported = 0; + let failed = 0; + for (const record of records) { + const item = normalizeApifyAd(record); + if (!item) { failed += 1; continue; } + try { + let brandPageId: string | null = null; + if (item.pageId) { + const brand = await prisma.brandPage.upsert({ + where: { source_externalPageId: { source: AdSource.META, externalPageId: item.pageId } }, + create: { source: AdSource.META, externalPageId: item.pageId, name: item.pageName, pageUrl: item.pageUrl, logoUrl: item.pageLogoUrl, fbLikes: item.pageLikes, igFollowers: item.pageFollowers }, + update: { name: item.pageName, pageUrl: item.pageUrl, logoUrl: item.pageLogoUrl, fbLikes: item.pageLikes, igFollowers: item.pageFollowers } + }); + brandPageId = brand.id; + } + const creative = item.creativeUrl ? { type: item.mediaType, url: item.creativeUrl, thumbnailUrl: item.thumbnailUrl } : null; + await prisma.ad.upsert({ + where: { source_externalAdId: { source: AdSource.META, externalAdId: item.externalAdId } }, + create: { + source: AdSource.META, externalAdId: item.externalAdId, brandPageId, status: item.status, mediaType: item.mediaType, + primaryText: item.primaryText, headline: item.headline, description: item.description, ctaText: item.ctaText, + landingUrl: item.landingUrl, productUrl: item.productUrl, language: item.language, countries: item.countries, + firstSeenAt: item.firstSeenAt, lastSeenAt: item.lastSeenAt, createdAtSource: item.createdAtSource, daysRunning: item.daysRunning, + estimatedReachMin: item.estimatedReachMin, estimatedSpendMin: item.estimatedSpendMin, raw: item.raw, + ...(creative ? { creatives: { create: creative } } : {}) + }, + update: { + brandPageId, status: item.status, mediaType: item.mediaType, primaryText: item.primaryText, headline: item.headline, + description: item.description, ctaText: item.ctaText, landingUrl: item.landingUrl, productUrl: item.productUrl, + language: item.language, countries: item.countries, firstSeenAt: item.firstSeenAt, lastSeenAt: item.lastSeenAt, + createdAtSource: item.createdAtSource, daysRunning: item.daysRunning, estimatedReachMin: item.estimatedReachMin, + estimatedSpendMin: item.estimatedSpendMin, raw: item.raw, + ...(creative ? { creatives: { deleteMany: {}, create: creative } } : {}) + } + }); + imported += 1; + } catch { + failed += 1; + } + } + return { imported, failed }; +} +