From 8c78fb7fc012cd689d48255cc935f97c84475bf1 Mon Sep 17 00:00:00 2001 From: Benjamin Okkema Date: Tue, 27 Aug 2024 20:00:54 -0500 Subject: [PATCH] feat: add sentry to function --- package-lock.json | 200 ++++++++++++++++++----------- package.json | 1 + src/env.d.ts | 4 +- src/functions/index.ts | 78 ++++++----- src/pages/api/subscribe/confirm.ts | 2 +- src/pages/api/subscribe/index.ts | 2 +- src/pages/img/[...slug].ts | 2 +- terraform/.terraform.lock.hcl | 23 ++++ terraform/main.tf | 20 ++- terraform/variables.tf | 1 + wrangler.toml | 2 +- 11 files changed, 216 insertions(+), 119 deletions(-) diff --git a/package-lock.json b/package-lock.json index f554f58..51a3471 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,6 +15,7 @@ "@cloudflare/workers-types": "^4.20240620.0", "@giscus/svelte": "^3.0.0", "@okkema/worker": "^2.0.0", + "@sentry/cloudflare": "^8.26.0", "@types/js-yaml": "^4.0.9", "astro": "^4.11.3", "autoprefixer": "^10.4.19", @@ -2661,9 +2662,9 @@ "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==" }, "node_modules/@rollup/rollup-android-arm-eabi": { - "version": "4.21.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.21.0.tgz", - "integrity": "sha512-WTWD8PfoSAJ+qL87lE7votj3syLavxunWhzCnx3XFxFiI/BA/r3X7MUM8dVrH8rb2r4AiO8jJsr3ZjdaftmnfA==", + "version": "4.21.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.21.1.tgz", + "integrity": "sha512-2thheikVEuU7ZxFXubPDOtspKn1x0yqaYQwvALVtEcvFhMifPADBrgRPyHV0TF3b+9BgvgjgagVyvA/UqPZHmg==", "cpu": [ "arm" ], @@ -2673,9 +2674,9 @@ ] }, "node_modules/@rollup/rollup-android-arm64": { - "version": "4.21.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.21.0.tgz", - "integrity": "sha512-a1sR2zSK1B4eYkiZu17ZUZhmUQcKjk2/j9Me2IDjk1GHW7LB5Z35LEzj9iJch6gtUfsnvZs1ZNyDW2oZSThrkA==", + "version": "4.21.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.21.1.tgz", + "integrity": "sha512-t1lLYn4V9WgnIFHXy1d2Di/7gyzBWS8G5pQSXdZqfrdCGTwi1VasRMSS81DTYb+avDs/Zz4A6dzERki5oRYz1g==", "cpu": [ "arm64" ], @@ -2685,9 +2686,9 @@ ] }, "node_modules/@rollup/rollup-darwin-arm64": { - "version": "4.21.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.21.0.tgz", - "integrity": "sha512-zOnKWLgDld/svhKO5PD9ozmL6roy5OQ5T4ThvdYZLpiOhEGY+dp2NwUmxK0Ld91LrbjrvtNAE0ERBwjqhZTRAA==", + "version": "4.21.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.21.1.tgz", + "integrity": "sha512-AH/wNWSEEHvs6t4iJ3RANxW5ZCK3fUnmf0gyMxWCesY1AlUj8jY7GC+rQE4wd3gwmZ9XDOpL0kcFnCjtN7FXlA==", "cpu": [ "arm64" ], @@ -2697,9 +2698,9 @@ ] }, "node_modules/@rollup/rollup-darwin-x64": { - "version": "4.21.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.21.0.tgz", - "integrity": "sha512-7doS8br0xAkg48SKE2QNtMSFPFUlRdw9+votl27MvT46vo44ATBmdZdGysOevNELmZlfd+NEa0UYOA8f01WSrg==", + "version": "4.21.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.21.1.tgz", + "integrity": "sha512-dO0BIz/+5ZdkLZrVgQrDdW7m2RkrLwYTh2YMFG9IpBtlC1x1NPNSXkfczhZieOlOLEqgXOFH3wYHB7PmBtf+Bg==", "cpu": [ "x64" ], @@ -2709,9 +2710,9 @@ ] }, "node_modules/@rollup/rollup-linux-arm-gnueabihf": { - "version": "4.21.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.21.0.tgz", - "integrity": "sha512-pWJsfQjNWNGsoCq53KjMtwdJDmh/6NubwQcz52aEwLEuvx08bzcy6tOUuawAOncPnxz/3siRtd8hiQ32G1y8VA==", + "version": "4.21.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.21.1.tgz", + "integrity": "sha512-sWWgdQ1fq+XKrlda8PsMCfut8caFwZBmhYeoehJ05FdI0YZXk6ZyUjWLrIgbR/VgiGycrFKMMgp7eJ69HOF2pQ==", "cpu": [ "arm" ], @@ -2721,9 +2722,9 @@ ] }, "node_modules/@rollup/rollup-linux-arm-musleabihf": { - "version": "4.21.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-musleabihf/-/rollup-linux-arm-musleabihf-4.21.0.tgz", - "integrity": "sha512-efRIANsz3UHZrnZXuEvxS9LoCOWMGD1rweciD6uJQIx2myN3a8Im1FafZBzh7zk1RJ6oKcR16dU3UPldaKd83w==", + "version": "4.21.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-musleabihf/-/rollup-linux-arm-musleabihf-4.21.1.tgz", + "integrity": "sha512-9OIiSuj5EsYQlmwhmFRA0LRO0dRRjdCVZA3hnmZe1rEwRk11Jy3ECGGq3a7RrVEZ0/pCsYWx8jG3IvcrJ6RCew==", "cpu": [ "arm" ], @@ -2733,9 +2734,9 @@ ] }, "node_modules/@rollup/rollup-linux-arm64-gnu": { - "version": "4.21.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.21.0.tgz", - "integrity": "sha512-ZrPhydkTVhyeGTW94WJ8pnl1uroqVHM3j3hjdquwAcWnmivjAwOYjTEAuEDeJvGX7xv3Z9GAvrBkEzCgHq9U1w==", + "version": "4.21.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.21.1.tgz", + "integrity": "sha512-0kuAkRK4MeIUbzQYu63NrJmfoUVicajoRAL1bpwdYIYRcs57iyIV9NLcuyDyDXE2GiZCL4uhKSYAnyWpjZkWow==", "cpu": [ "arm64" ], @@ -2745,9 +2746,9 @@ ] }, "node_modules/@rollup/rollup-linux-arm64-musl": { - "version": "4.21.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.21.0.tgz", - "integrity": "sha512-cfaupqd+UEFeURmqNP2eEvXqgbSox/LHOyN9/d2pSdV8xTrjdg3NgOFJCtc1vQ/jEke1qD0IejbBfxleBPHnPw==", + "version": "4.21.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.21.1.tgz", + "integrity": "sha512-/6dYC9fZtfEY0vozpc5bx1RP4VrtEOhNQGb0HwvYNwXD1BBbwQ5cKIbUVVU7G2d5WRE90NfB922elN8ASXAJEA==", "cpu": [ "arm64" ], @@ -2757,9 +2758,9 @@ ] }, "node_modules/@rollup/rollup-linux-powerpc64le-gnu": { - "version": "4.21.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-powerpc64le-gnu/-/rollup-linux-powerpc64le-gnu-4.21.0.tgz", - "integrity": "sha512-ZKPan1/RvAhrUylwBXC9t7B2hXdpb/ufeu22pG2psV7RN8roOfGurEghw1ySmX/CmDDHNTDDjY3lo9hRlgtaHg==", + "version": "4.21.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-powerpc64le-gnu/-/rollup-linux-powerpc64le-gnu-4.21.1.tgz", + "integrity": "sha512-ltUWy+sHeAh3YZ91NUsV4Xg3uBXAlscQe8ZOXRCVAKLsivGuJsrkawYPUEyCV3DYa9urgJugMLn8Z3Z/6CeyRQ==", "cpu": [ "ppc64" ], @@ -2769,9 +2770,9 @@ ] }, "node_modules/@rollup/rollup-linux-riscv64-gnu": { - "version": "4.21.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.21.0.tgz", - "integrity": "sha512-H1eRaCwd5E8eS8leiS+o/NqMdljkcb1d6r2h4fKSsCXQilLKArq6WS7XBLDu80Yz+nMqHVFDquwcVrQmGr28rg==", + "version": "4.21.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.21.1.tgz", + "integrity": "sha512-BggMndzI7Tlv4/abrgLwa/dxNEMn2gC61DCLrTzw8LkpSKel4o+O+gtjbnkevZ18SKkeN3ihRGPuBxjaetWzWg==", "cpu": [ "riscv64" ], @@ -2781,9 +2782,9 @@ ] }, "node_modules/@rollup/rollup-linux-s390x-gnu": { - "version": "4.21.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.21.0.tgz", - "integrity": "sha512-zJ4hA+3b5tu8u7L58CCSI0A9N1vkfwPhWd/puGXwtZlsB5bTkwDNW/+JCU84+3QYmKpLi+XvHdmrlwUwDA6kqw==", + "version": "4.21.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.21.1.tgz", + "integrity": "sha512-z/9rtlGd/OMv+gb1mNSjElasMf9yXusAxnRDrBaYB+eS1shFm6/4/xDH1SAISO5729fFKUkJ88TkGPRUh8WSAA==", "cpu": [ "s390x" ], @@ -2793,9 +2794,9 @@ ] }, "node_modules/@rollup/rollup-linux-x64-gnu": { - "version": "4.21.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.21.0.tgz", - "integrity": "sha512-e2hrvElFIh6kW/UNBQK/kzqMNY5mO+67YtEh9OA65RM5IJXYTWiXjX6fjIiPaqOkBthYF1EqgiZ6OXKcQsM0hg==", + "version": "4.21.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.21.1.tgz", + "integrity": "sha512-kXQVcWqDcDKw0S2E0TmhlTLlUgAmMVqPrJZR+KpH/1ZaZhLSl23GZpQVmawBQGVhyP5WXIsIQ/zqbDBBYmxm5w==", "cpu": [ "x64" ], @@ -2805,9 +2806,9 @@ ] }, "node_modules/@rollup/rollup-linux-x64-musl": { - "version": "4.21.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.21.0.tgz", - "integrity": "sha512-1vvmgDdUSebVGXWX2lIcgRebqfQSff0hMEkLJyakQ9JQUbLDkEaMsPTLOmyccyC6IJ/l3FZuJbmrBw/u0A0uCQ==", + "version": "4.21.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.21.1.tgz", + "integrity": "sha512-CbFv/WMQsSdl+bpX6rVbzR4kAjSSBuDgCqb1l4J68UYsQNalz5wOqLGYj4ZI0thGpyX5kc+LLZ9CL+kpqDovZA==", "cpu": [ "x64" ], @@ -2817,9 +2818,9 @@ ] }, "node_modules/@rollup/rollup-win32-arm64-msvc": { - "version": "4.21.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.21.0.tgz", - "integrity": "sha512-s5oFkZ/hFcrlAyBTONFY1TWndfyre1wOMwU+6KCpm/iatybvrRgmZVM+vCFwxmC5ZhdlgfE0N4XorsDpi7/4XQ==", + "version": "4.21.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.21.1.tgz", + "integrity": "sha512-3Q3brDgA86gHXWHklrwdREKIrIbxC0ZgU8lwpj0eEKGBQH+31uPqr0P2v11pn0tSIxHvcdOWxa4j+YvLNx1i6g==", "cpu": [ "arm64" ], @@ -2829,9 +2830,9 @@ ] }, "node_modules/@rollup/rollup-win32-ia32-msvc": { - "version": "4.21.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.21.0.tgz", - "integrity": "sha512-G9+TEqRnAA6nbpqyUqgTiopmnfgnMkR3kMukFBDsiyy23LZvUCpiUwjTRx6ezYCjJODXrh52rBR9oXvm+Fp5wg==", + "version": "4.21.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.21.1.tgz", + "integrity": "sha512-tNg+jJcKR3Uwe4L0/wY3Ro0H+u3nrb04+tcq1GSYzBEmKLeOQF2emk1whxlzNqb6MMrQ2JOcQEpuuiPLyRcSIw==", "cpu": [ "ia32" ], @@ -2841,9 +2842,9 @@ ] }, "node_modules/@rollup/rollup-win32-x64-msvc": { - "version": "4.21.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.21.0.tgz", - "integrity": "sha512-2jsCDZwtQvRhejHLfZ1JY6w6kEuEtfF9nzYsZxzSlNVKDX+DpsDJ+Rbjkm74nvg2rdx0gwBS+IMdvwJuq3S9pQ==", + "version": "4.21.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.21.1.tgz", + "integrity": "sha512-xGiIH95H1zU7naUyTKEyOA/I0aexNMUdO9qRv0bLKN3qu25bBdrxZHqA3PTJ24YNN/GdMzG4xkDcd/GvjuhfLg==", "cpu": [ "x64" ], @@ -2852,6 +2853,53 @@ "win32" ] }, + "node_modules/@sentry/cloudflare": { + "version": "8.26.0", + "resolved": "https://registry.npmjs.org/@sentry/cloudflare/-/cloudflare-8.26.0.tgz", + "integrity": "sha512-DHM2pNEwmrQ8/24ZtDPBsWOPwcZsJiZVRzn8T9M9Pp7XiOAax7cdX0CaJnY7ohECq8aEVL4WmF1JwPGWi2NP5w==", + "dependencies": { + "@sentry/core": "8.26.0", + "@sentry/types": "8.26.0", + "@sentry/utils": "8.26.0" + }, + "engines": { + "node": ">=14.18" + }, + "optionalDependencies": { + "@cloudflare/workers-types": "^4.x" + } + }, + "node_modules/@sentry/core": { + "version": "8.26.0", + "resolved": "https://registry.npmjs.org/@sentry/core/-/core-8.26.0.tgz", + "integrity": "sha512-g/tVmTZD4GNbLFf++hKJfBpcCAtduFEMLnbfa9iT/QEZjlmP+EzY+GsH9bafM5VsNe8DiOUp+kJKWtShzlVdBA==", + "dependencies": { + "@sentry/types": "8.26.0", + "@sentry/utils": "8.26.0" + }, + "engines": { + "node": ">=14.18" + } + }, + "node_modules/@sentry/types": { + "version": "8.26.0", + "resolved": "https://registry.npmjs.org/@sentry/types/-/types-8.26.0.tgz", + "integrity": "sha512-zKmh6SWsJh630rpt7a9vP4Cm4m1C2gDTUqUiH565CajCL/4cePpNWYrNwalSqsOSL7B9OrczA1+n6a6XvND+ng==", + "engines": { + "node": ">=14.18" + } + }, + "node_modules/@sentry/utils": { + "version": "8.26.0", + "resolved": "https://registry.npmjs.org/@sentry/utils/-/utils-8.26.0.tgz", + "integrity": "sha512-xvlPU9Hd2BlyT+FhWHGNwnxWqdVRk2AHnDtVcW4Ma0Ri5EwS+uy4Jeik5UkSv8C5RVb9VlxFmS8LN3I1MPJsLw==", + "dependencies": { + "@sentry/types": "8.26.0" + }, + "engines": { + "node": ">=14.18" + } + }, "node_modules/@shikijs/core": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/@shikijs/core/-/core-1.14.1.tgz", @@ -5175,9 +5223,9 @@ "integrity": "sha512-lbBcvtIJ4J6sS4tb5TLp1b4LyfCdMkwStzXPyAgVgTRAsep4bvrAGaBOP7ZJtQMNJpSQ9SqG4brWOroNaQtm7Q==" }, "node_modules/emoji-regex": { - "version": "10.3.0", - "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-10.3.0.tgz", - "integrity": "sha512-QpLs9D9v9kArv4lfDEgg1X/gN5XLnf/A6l9cs8SPZLRZR3ZkY9+kwIQTxm+fsSej5UMYGE8fdoaZVIBlqG0XTw==" + "version": "10.4.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-10.4.0.tgz", + "integrity": "sha512-EC+0oUMY1Rqm4O6LLrgjtYDvcVYTy7chDnM4Q7030tP4Kwj3u/pR6gP9ygnp2CJMK5Gq+9Q2oqmrFJAz01DXjw==" }, "node_modules/entities": { "version": "4.5.0", @@ -6883,9 +6931,9 @@ } }, "node_modules/marked": { - "version": "14.0.0", - "resolved": "https://registry.npmjs.org/marked/-/marked-14.0.0.tgz", - "integrity": "sha512-uIj4+faQ+MgHgwUW1l2PsPglZLOLOT1uErt06dAPtx2kjteLAkbsd/0FiYg/MGS+i7ZKLb7w2WClxHkzOOuryQ==", + "version": "14.1.0", + "resolved": "https://registry.npmjs.org/marked/-/marked-14.1.0.tgz", + "integrity": "sha512-P93GikH/Pde0hM5TAXEd8I4JAYi8IB03n8qzW8Bh1BIEFpEyBoYxi/XWZA53LSpTeLBiMQOoSMj0u5E/tiVYTA==", "bin": { "marked": "bin/marked.js" }, @@ -8780,9 +8828,9 @@ } }, "node_modules/retext-smartypants": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/retext-smartypants/-/retext-smartypants-6.1.0.tgz", - "integrity": "sha512-LDPXg95346bqFZnDMHo0S7Rq5p64+B+N8Vz733+wPMDtwb9rCOs9LIdIEhrUOU+TAywX9St+ocQWJt8wrzivcQ==", + "version": "6.1.1", + "resolved": "https://registry.npmjs.org/retext-smartypants/-/retext-smartypants-6.1.1.tgz", + "integrity": "sha512-onsHf34i/GzgElJgtT1K2V+31yEhWs7NJboKNxXJcmVMMPxLpgxZ9iADoMdydd6j/bHic5F/aNq0CGqElEtu2g==", "dependencies": { "@types/nlcst": "^2.0.0", "nlcst-to-string": "^4.0.0", @@ -8822,9 +8870,9 @@ "integrity": "sha512-MjOWxM065+WswwnmNONOT+bD1nXzY9Km6u3kzvnx8F8/HXGZdz3T6e6vZJ8Q/RIMUSp/nxqjH3GwvJDy8ijeQQ==" }, "node_modules/rollup": { - "version": "4.21.0", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.21.0.tgz", - "integrity": "sha512-vo+S/lfA2lMS7rZ2Qoubi6I5hwZwzXeUIctILZLbHI+laNtvhhOIon2S1JksA5UEDQ7l3vberd0fxK44lTYjbQ==", + "version": "4.21.1", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.21.1.tgz", + "integrity": "sha512-ZnYyKvscThhgd3M5+Qt3pmhO4jIRR5RGzaSovB6Q7rGNrK5cUncrtLmcTTJVSdcKXyZjW8X8MB0JMSuH9bcAJg==", "dependencies": { "@types/estree": "1.0.5" }, @@ -8836,22 +8884,22 @@ "npm": ">=8.0.0" }, "optionalDependencies": { - "@rollup/rollup-android-arm-eabi": "4.21.0", - "@rollup/rollup-android-arm64": "4.21.0", - "@rollup/rollup-darwin-arm64": "4.21.0", - "@rollup/rollup-darwin-x64": "4.21.0", - "@rollup/rollup-linux-arm-gnueabihf": "4.21.0", - "@rollup/rollup-linux-arm-musleabihf": "4.21.0", - "@rollup/rollup-linux-arm64-gnu": "4.21.0", - "@rollup/rollup-linux-arm64-musl": "4.21.0", - "@rollup/rollup-linux-powerpc64le-gnu": "4.21.0", - "@rollup/rollup-linux-riscv64-gnu": "4.21.0", - "@rollup/rollup-linux-s390x-gnu": "4.21.0", - "@rollup/rollup-linux-x64-gnu": "4.21.0", - "@rollup/rollup-linux-x64-musl": "4.21.0", - "@rollup/rollup-win32-arm64-msvc": "4.21.0", - "@rollup/rollup-win32-ia32-msvc": "4.21.0", - "@rollup/rollup-win32-x64-msvc": "4.21.0", + "@rollup/rollup-android-arm-eabi": "4.21.1", + "@rollup/rollup-android-arm64": "4.21.1", + "@rollup/rollup-darwin-arm64": "4.21.1", + "@rollup/rollup-darwin-x64": "4.21.1", + "@rollup/rollup-linux-arm-gnueabihf": "4.21.1", + "@rollup/rollup-linux-arm-musleabihf": "4.21.1", + "@rollup/rollup-linux-arm64-gnu": "4.21.1", + "@rollup/rollup-linux-arm64-musl": "4.21.1", + "@rollup/rollup-linux-powerpc64le-gnu": "4.21.1", + "@rollup/rollup-linux-riscv64-gnu": "4.21.1", + "@rollup/rollup-linux-s390x-gnu": "4.21.1", + "@rollup/rollup-linux-x64-gnu": "4.21.1", + "@rollup/rollup-linux-x64-musl": "4.21.1", + "@rollup/rollup-win32-arm64-msvc": "4.21.1", + "@rollup/rollup-win32-ia32-msvc": "4.21.1", + "@rollup/rollup-win32-x64-msvc": "4.21.1", "fsevents": "~2.3.2" } }, diff --git a/package.json b/package.json index 72caf64..0560c9f 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "@cloudflare/workers-types": "^4.20240620.0", "@giscus/svelte": "^3.0.0", "@okkema/worker": "^2.0.0", + "@sentry/cloudflare": "^8.26.0", "@types/js-yaml": "^4.0.9", "astro": "^4.11.3", "autoprefixer": "^10.4.19", diff --git a/src/env.d.ts b/src/env.d.ts index c850396..a8b30a4 100644 --- a/src/env.d.ts +++ b/src/env.d.ts @@ -7,12 +7,14 @@ export type Environment = { MAILJET_API_KEY: string MAILJET_SECRET_KEY: string ADMIN_EMAIL: string - BUCKET: R2Bucket + BLOG: R2Bucket RSA_PUBLIC_KEY: string RSA_PRIVATE_KEY: string CF_PAGES_COMMIT_SHA: string; STRAVA: R2Bucket DB: D1Database + SENTRY_DSN: string + WORKER_SCHEDULE: string } type Runtime = import("@astrojs/cloudflare").Runtime diff --git a/src/functions/index.ts b/src/functions/index.ts index d5c51a3..113782f 100644 --- a/src/functions/index.ts +++ b/src/functions/index.ts @@ -1,45 +1,55 @@ -import type { ExecutionContext, ScheduledController } from "@cloudflare/workers-types" +import type { D1Database, ExecutionContext, R2Bucket, ScheduledController } from "@cloudflare/workers-types" import type { Environment } from "@env" import type { Gear } from "@schemas/strava" import { GearService, PostService } from "@services" import { parseMarkdown } from "@utils" +import * as Sentry from "@sentry/cloudflare" const GearRegex = /gear\/([b0-9]+).meta.json/ const PostsRegex = /posts\/([A-Za-z0-9\-]+).md/ -export default { - async scheduled(controller: ScheduledController, env: Environment, ctx: ExecutionContext) { - const gear = await env.STRAVA.list({ prefix: "gear" }) - for (const object of gear.objects) { - const key = object.key - const id = GearRegex.exec(key)?.[1] - if (!id) { - console.log("Unable to extract id from key", key) - continue - } - const body = await env.STRAVA.get(key) - if (!body) { - console.log("This should never happen...", key) - continue - } - const gear = await body.json() - const service = GearService(env.DB) - await service.upsert(gear) +async function processBuckets(blog: R2Bucket, strava: R2Bucket, db: D1Database) { + const posts = await blog.list({ prefix: "posts" }) + for (const object of posts.objects) { + const key = object.key + const slug = PostsRegex.exec(key)?.[1] + if (!slug) { + console.log("Unable to extract slug from key", key) + continue } - - const posts = await env.BUCKET.list({ prefix: "posts" }) - for (const object of posts.objects) { - const key = object.key - const slug = PostsRegex.exec(key)?.[1] - if (!slug) { - console.log("Unable to extract slug from key", key) - continue - } - const body = await env.BUCKET.get(key) - const raw = await body!.text() - const post = parseMarkdown(raw, slug) - const service = PostService(env.DB) - await service.upsert(post) + const body = await blog.get(key) + const raw = await body!.text() + const post = parseMarkdown(raw, slug) + const service = PostService(db) + await service.upsert(post) + } + + const gear = await strava.list({ prefix: "gear" }) + for (const object of gear.objects) { + const key = object.key + const id = GearRegex.exec(key)?.[1] + if (!id) { + console.log("Unable to extract id from key", key) + continue + } + const body = await strava.get(key) + if (!body) { + console.log("This should never happen...", key) + continue } + const gear = await body.json() + const service = GearService(db) + await service.upsert(gear) + } +} + +export default Sentry.withSentry(function(env) { + return { + dsn: env.SENTRY_DSN + } +}, { + async scheduled(controller: ScheduledController, env: Environment, ctx: ExecutionContext) { + const db = Sentry.instrumentD1WithSentry(env.DB) + ctx.waitUntil(processBuckets(env.BLOG, env.STRAVA, db)) } -} \ No newline at end of file +}) \ No newline at end of file diff --git a/src/pages/api/subscribe/confirm.ts b/src/pages/api/subscribe/confirm.ts index 008930b..74e6087 100644 --- a/src/pages/api/subscribe/confirm.ts +++ b/src/pages/api/subscribe/confirm.ts @@ -12,7 +12,7 @@ export async function GET(context: APIContext) { ok: false, message: "Something doesn't look right here....", }) - const subscribers = R2Repository(env.BUCKET, "subscribers") + const subscribers = R2Repository(env.BLOG, "subscribers") const subscriber = await subscribers.get(email) if (!subscriber || id !== subscriber.id) { return json({ diff --git a/src/pages/api/subscribe/index.ts b/src/pages/api/subscribe/index.ts index d818905..b5a628c 100644 --- a/src/pages/api/subscribe/index.ts +++ b/src/pages/api/subscribe/index.ts @@ -6,7 +6,7 @@ import type { Subscriber } from "@schemas" export async function POST(context: APIContext) { const { env } = context.locals.runtime const site = context.site?.hostname - const subscribers = R2Repository(env.BUCKET, "subscribers") + const subscribers = R2Repository(env.BLOG, "subscribers") const data = await context.request.json<{ email: string }>() const { email } = data const subscriber = await subscribers.get(email) diff --git a/src/pages/img/[...slug].ts b/src/pages/img/[...slug].ts index 84a0c22..14bb721 100644 --- a/src/pages/img/[...slug].ts +++ b/src/pages/img/[...slug].ts @@ -2,7 +2,7 @@ import type { APIContext } from "astro" export async function GET(context: APIContext) { const slug = context.params.slug - const object = await context.locals.runtime.env.BUCKET.get(`img/${slug}`) + const object = await context.locals.runtime.env.BLOG.get(`img/${slug}`) if (!object) return new Response("Not Found", { status: 404 }) const headers = new Headers() // https://github.com/cloudflare/workers-sdk/issues/6047 diff --git a/terraform/.terraform.lock.hcl b/terraform/.terraform.lock.hcl index c3091a7..5da1fc9 100644 --- a/terraform/.terraform.lock.hcl +++ b/terraform/.terraform.lock.hcl @@ -46,6 +46,29 @@ provider "registry.terraform.io/integrations/github" { ] } +provider "registry.terraform.io/jianyuan/sentry" { + version = "0.13.1" + constraints = "~> 0.12" + hashes = [ + "h1:tPFv6cLf04pWB9YVi9IYha4PjwXwgho06wjZ9tG7NZw=", + "zh:0dde99e7b343fa01f8eefc378171fb8621bedb20f59157d6cc8e3d46c738105f", + "zh:30ed398792e511f41555be5f3a3ae024858972b05a6e3c5ff31d9a745d6a8d08", + "zh:497ddbe21689fb08145b79f7a1a9d499997b24ec458f0b4f63e3dc4454830207", + "zh:50f8ad867e9367c2bb99c09003a85f1db7b0db381e7e34644468d67cf516958a", + "zh:54b24ae567d08a6d8af0688be22e0b8e74077f21101bdc936e8b0913f6847122", + "zh:65bdc167e23fc978336e934b481c984e4696eaeadf6753332cab39a2f969fdd2", + "zh:689cafb3b7033d84a2c951f1a76fe3f6b79a9313c9725162bf9b01c817b5d79e", + "zh:7b34307a54a1a390251a5429c799d4bc43d84ea29439f0a14d8f2b6c500ea897", + "zh:7ed669e745e7a40773a6d9f6559b42ac1b2b9b06ca757700c6c2d5f31a9f79bb", + "zh:8f808a6653bf998ee17ccc9d1f7b40036e2611c04371fa57830ad48053852dd6", + "zh:b376cd99f4b5b7e18754a859e13d911edeb1db57b7518974f40a221036d50ab6", + "zh:bcb86759ce8761fb88a3652772f8eceb9b83238a3ea249e65dffab9212790f36", + "zh:be4b848c74285c9b023e85b15df46b16076be1cf418efd2fc28d370d65c095e2", + "zh:d628d39faaacd5b7dc6cd34d7984b3ae7a0dd5d81803be6e72058954d3261303", + "zh:e7b48d7de5dd1133dc0f500320e2a626478fd88656b15aa13d4cd51582cb764a", + ] +} + provider "registry.terraform.io/killmeplz/sodium" { version = "0.0.3" constraints = "~> 0.0.3" diff --git a/terraform/main.tf b/terraform/main.tf index cd6827f..d614d3a 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -50,7 +50,7 @@ module "page" { } production_buckets = { - BUCKET = var.github_repository + BLOG = var.github_repository STRAVA = "strava" } @@ -83,13 +83,25 @@ module "worker" { env_vars = [ { name = "WORKER_SCHEDULE", value = var.WORKER_SCHEDULE } ] + secrets = [ + { name = "SENTRY_DSN", value = module.sentry.dsn } + ] buckets = [ - { binding = "STRAVA", name = "strava" }, - { binding = "BUCKET", name = var.github_repository } + { binding = "BLOG", name = var.github_repository }, + { binding = "STRAVA", name = "strava" } ] databases = [ { binding = "DB", id = module.database.id } ] - depends_on = [module.database] + depends_on = [module.database, module.sentry] +} + +module "sentry" { + source = "app.terraform.io/okkema/project/sentry" + version = "~> 0.3" + + github_organization = var.github_owner + github_repository = var.github_repository + default_user = var.sentry_default_user } \ No newline at end of file diff --git a/terraform/variables.tf b/terraform/variables.tf index 9ad7665..ea0d888 100644 --- a/terraform/variables.tf +++ b/terraform/variables.tf @@ -3,6 +3,7 @@ variable "cloudflare_zone_id" {} variable "github_owner" {} variable "github_repository" {} variable "pages_hostname" {} +variable "sentry_default_user" {} # Environment Variables variable "HCAPTCHA_SITEKEY" {} diff --git a/wrangler.toml b/wrangler.toml index a6f92e4..47042a6 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -3,7 +3,7 @@ compatibility_date = "2024-07-01" compatibility_flags = [ "nodejs_compat" ] [[r2_buckets]] -binding = "BUCKET" +binding = "BLOG" preview_bucket_name = "blog" bucket_name = "blog"