diff --git a/package.json b/package.json index ed7948a..01a15a7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sprintpadawan", - "version": "2.0.3", + "version": "2.0.4", "description": "Plan. Sprint. Repeat.", "private": true, "scripts": { @@ -23,13 +23,13 @@ "@trpc/next": "10.37.1", "@trpc/react-query": "10.37.1", "@trpc/server": "10.37.1", - "@unkey/api": "^0.6.14", + "@unkey/api": "^0.6.16", "@upstash/ratelimit": "^0.4.3", "@upstash/redis": "^1.22.0", "ably": "^1.2.43", "autoprefixer": "^10.4.15", "dotenv": "^16.3.1", - "drizzle-orm": "^0.28.3", + "drizzle-orm": "^0.28.4", "json2csv": "6.0.0-alpha.2", "next": "^13.4.19", "nextjs-cors": "^2.1.2", @@ -46,7 +46,7 @@ "devDependencies": { "@types/eslint": "^8.44.2", "@types/json2csv": "^5.0.3", - "@types/node": "^20.5.3", + "@types/node": "^20.5.4", "@types/react": "^18.2.21", "@typescript-eslint/eslint-plugin": "^6.4.1", "@typescript-eslint/parser": "^6.4.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 280d7dd..b6f8b53 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -36,8 +36,8 @@ dependencies: specifier: 10.37.1 version: 10.37.1 '@unkey/api': - specifier: ^0.6.14 - version: 0.6.14 + specifier: ^0.6.16 + version: 0.6.16 '@upstash/ratelimit': specifier: ^0.4.3 version: 0.4.3 @@ -54,8 +54,8 @@ dependencies: specifier: ^16.3.1 version: 16.3.1 drizzle-orm: - specifier: ^0.28.3 - version: 0.28.3(@neondatabase/serverless@0.6.0)(pg@8.11.3) + specifier: ^0.28.4 + version: 0.28.4(@neondatabase/serverless@0.6.0)(pg@8.11.3) json2csv: specifier: 6.0.0-alpha.2 version: 6.0.0-alpha.2 @@ -101,8 +101,8 @@ devDependencies: specifier: ^5.0.3 version: 5.0.3 '@types/node': - specifier: ^20.5.3 - version: 20.5.3 + specifier: ^20.5.4 + version: 20.5.4 '@types/react': specifier: ^18.2.21 version: 18.2.21 @@ -1095,8 +1095,8 @@ packages: dev: false optional: true - /@noble/hashes@1.3.1: - resolution: {integrity: sha512-EbqwksQwz9xDRGfDST86whPBgM65E0OH/pCgqW0GBVzO22bNE+NuIbeTb714+IfSjU3aRk47EUvXIb5bTsenKA==} + /@noble/hashes@1.3.2: + resolution: {integrity: sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ==} engines: {node: '>= 16'} dev: false @@ -1208,7 +1208,7 @@ packages: '@octokit/request-error': 3.0.3 '@octokit/types': 9.3.2 is-plain-object: 5.0.0 - node-fetch: 2.6.13 + node-fetch: 2.7.0 universal-user-agent: 6.0.0 transitivePeerDependencies: - encoding @@ -1249,7 +1249,7 @@ packages: /@paralleldrive/cuid2@2.2.2: resolution: {integrity: sha512-ZOBkgDwEdoYVlSeRbYYXs0S9MejQofiVYoTbKzy/6GQa39/q5tQU2IX46+shYnUkpEl3wc+J6wRlar7r2EK2xA==} dependencies: - '@noble/hashes': 1.3.1 + '@noble/hashes': 1.3.2 dev: false /@peculiar/asn1-schema@2.3.6: @@ -1563,7 +1563,7 @@ packages: resolution: {integrity: sha512-ALYone6pm6QmwZoAgeyNksccT9Q4AWZQ6PvfwR37GT6r6FWUPguq6sUmNGSMV2Wr761oQoBxwGGa6DR5o1DC9g==} dependencies: '@types/connect': 3.4.35 - '@types/node': 20.5.3 + '@types/node': 20.5.4 dev: false /@types/cacheable-request@6.0.3: @@ -1571,14 +1571,14 @@ packages: dependencies: '@types/http-cache-semantics': 4.0.1 '@types/keyv': 3.1.4 - '@types/node': 20.5.3 + '@types/node': 20.5.4 '@types/responselike': 1.0.0 dev: false /@types/connect@3.4.35: resolution: {integrity: sha512-cdeYyv4KWoEgpBISTxWvqYsVy444DOqehiF3fM3ne10AmJ62RSyNkUnxMJXHQWRQQX2eR94m5y1IZyDwBjV9FQ==} dependencies: - '@types/node': 20.5.3 + '@types/node': 20.5.4 dev: false /@types/cookies@0.7.7: @@ -1587,7 +1587,7 @@ packages: '@types/connect': 3.4.35 '@types/express': 4.17.14 '@types/keygrip': 1.0.2 - '@types/node': 20.5.3 + '@types/node': 20.5.4 dev: false /@types/eslint@8.44.2: @@ -1604,7 +1604,7 @@ packages: /@types/express-serve-static-core@4.17.36: resolution: {integrity: sha512-zbivROJ0ZqLAtMzgzIUC4oNqDG9iF0lSsAqpOD9kbs5xcIM3dTiyuHvBc7R8MtWBp3AAWGaovJa+wzWPjLYW7Q==} dependencies: - '@types/node': 20.5.3 + '@types/node': 20.5.4 '@types/qs': 6.9.7 '@types/range-parser': 1.2.4 '@types/send': 0.17.1 @@ -1634,7 +1634,7 @@ packages: /@types/json2csv@5.0.3: resolution: {integrity: sha512-ZJEv6SzhPhgpBpxZU4n/TZekbZqI4EcyXXRwms1lAITG2kIAtj85PfNYafUOY1zy8bWs5ujaub0GU4copaA0sw==} dependencies: - '@types/node': 20.5.3 + '@types/node': 20.5.4 dev: true /@types/json5@0.0.29: @@ -1648,7 +1648,7 @@ packages: /@types/keyv@3.1.4: resolution: {integrity: sha512-BQ5aZNSCpj7D6K2ksrRCTmKRLEpnPvWDiLPfoGyhZ++8YtiK9d/3DBKPJgry359X/P1PfruyYwvnvwFjuEiEIg==} dependencies: - '@types/node': 20.5.3 + '@types/node': 20.5.4 dev: false /@types/mime@1.3.2: @@ -1662,7 +1662,7 @@ packages: /@types/node-fetch@2.6.2: resolution: {integrity: sha512-DHqhlq5jeESLy19TYhLakJ07kNumXWjcDdxXsLUMJZ6ue8VZJj4kLPQVE/2mdHh3xZziNF1xppu5lwmS53HR+A==} dependencies: - '@types/node': 20.5.3 + '@types/node': 20.5.4 form-data: 3.0.1 dev: false @@ -1674,8 +1674,8 @@ packages: resolution: {integrity: sha512-vmYJF0REqDyyU0gviezF/KHq/fYaUbFhkcNbQCuPGFQj6VTbXuHZoxs/Y7mutWe73C8AC6l9fFu8mSYiBAqkGA==} dev: false - /@types/node@20.5.3: - resolution: {integrity: sha512-ITI7rbWczR8a/S6qjAW7DMqxqFMjjTo61qZVWJ1ubPvbIQsL5D/TvwjYEalM8Kthpe3hTzOGrF2TGbAu2uyqeA==} + /@types/node@20.5.4: + resolution: {integrity: sha512-Y9vbIAoM31djQZrPYjpTLo0XlaSwOIsrlfE3LpulZeRblttsLQRFRlBAppW0LOxyT3ALj2M5vU1ucQQayQH3jA==} /@types/normalize-package-data@2.4.1: resolution: {integrity: sha512-Gj7cI7z+98M282Tqmp2K5EIsoouUEzbBJhQQzDE3jSIRk6r9gsz0oUokqIUR4u1R3dMHo0pDHM7sNOHyhulypw==} @@ -1684,7 +1684,7 @@ packages: /@types/pg@8.6.6: resolution: {integrity: sha512-O2xNmXebtwVekJDD+02udOncjVcMZQuTEQEMpKJ0ZRf5E7/9JJX3izhKUcUifBkyKpljyUM6BTgy2trmviKlpw==} dependencies: - '@types/node': 20.5.3 + '@types/node': 20.5.4 pg-protocol: 1.6.0 pg-types: 2.2.0 dev: false @@ -1712,7 +1712,7 @@ packages: /@types/responselike@1.0.0: resolution: {integrity: sha512-85Y2BjiufFzaMIlvJDvTTB8Fxl2xfLo4HgmHzVBz08w4wDePCTjYw66PdrolO0kzli3yam/YCgRufyo1DdQVTA==} dependencies: - '@types/node': 20.5.3 + '@types/node': 20.5.4 dev: false /@types/scheduler@0.16.3: @@ -1727,7 +1727,7 @@ packages: resolution: {integrity: sha512-Cwo8LE/0rnvX7kIIa3QHCkcuF21c05Ayb0ZfxPiv0W8VRiZiNW/WuRupHKpqqGVGf7SUA44QSOUKaEd9lIrd/Q==} dependencies: '@types/mime': 1.3.2 - '@types/node': 20.5.3 + '@types/node': 20.5.4 dev: false /@types/serve-static@1.15.2: @@ -1735,7 +1735,7 @@ packages: dependencies: '@types/http-errors': 2.0.1 '@types/mime': 3.0.1 - '@types/node': 20.5.3 + '@types/node': 20.5.4 dev: false /@typescript-eslint/eslint-plugin@6.4.1(@typescript-eslint/parser@6.4.1)(eslint@8.47.0)(typescript@5.1.6): @@ -1869,8 +1869,8 @@ packages: eslint-visitor-keys: 3.4.3 dev: true - /@unkey/api@0.6.14: - resolution: {integrity: sha512-d2tssSRf4Y4kCF44mloFcqphBenfWN5G2D1Iyz8EMmAoNi+ytvmHmmc1zZf4k3GhK68xLDA7uEO/b/1vtgD5qg==} + /@unkey/api@0.6.16: + resolution: {integrity: sha512-NaJDb9t5YwM9K/yaelMlrdIOuPbiUEkIbEoBGp4WidkHhagMpVWg1eAtWpuSHe3QWjd4+LzMLpnNjS4he6jYow==} dev: false /@upstash/core-analytics@0.0.6: @@ -2215,7 +2215,7 @@ packages: hasBin: true dependencies: caniuse-lite: 1.0.30001522 - electron-to-chromium: 1.4.499 + electron-to-chromium: 1.4.500 node-releases: 2.0.13 update-browserslist-db: 1.0.11(browserslist@4.21.10) dev: false @@ -2768,8 +2768,8 @@ packages: - supports-color dev: true - /drizzle-orm@0.28.3(@neondatabase/serverless@0.6.0)(pg@8.11.3): - resolution: {integrity: sha512-7LwNEBJH5EFvkD0vm7RdKWDZsFP9CYR4AWN2fMwns/ezexoX3+UNoVOWGRPJf1qsj357SESldrNEueFvUDfZxA==} + /drizzle-orm@0.28.4(@neondatabase/serverless@0.6.0)(pg@8.11.3): + resolution: {integrity: sha512-BEATAB0g0Y8PKbJHkHLLENlX2DXktO5XyeNyrXB6ktcNkg3dlMfePwB3LodBJkPY6d7GixFF+jvtdZsWjakJBQ==} peerDependencies: '@aws-sdk/client-rds-data': '>=3' '@cloudflare/workers-types': '>=3' @@ -2851,8 +2851,8 @@ packages: semver: 7.5.4 dev: false - /electron-to-chromium@1.4.499: - resolution: {integrity: sha512-0NmjlYBLKVHva4GABWAaHuPJolnDuL0AhV3h1hES6rcLCWEIbRL6/8TghfsVwkx6TEroQVdliX7+aLysUpKvjw==} + /electron-to-chromium@1.4.500: + resolution: {integrity: sha512-P38NO8eOuWOKY1sQk5yE0crNtrjgjJj6r3NrbIKtG18KzCHmHE2Bt+aQA7/y0w3uYsHWxDa6icOohzjLJ4vJ4A==} dev: false /emoji-regex@9.2.2: @@ -4166,7 +4166,7 @@ packages: /isomorphic-fetch@3.0.0: resolution: {integrity: sha512-qvUtwJ3j6qwsF3jLxkZ72qCgjMysPzDfeV240JHiGZsANBYd+EEuu35v7dfrJ9Up0Ak07D7GGSkGhCHTqg/5wA==} dependencies: - node-fetch: 2.6.13 + node-fetch: 2.7.0 whatwg-fetch: 3.6.17 transitivePeerDependencies: - encoding @@ -4615,8 +4615,8 @@ packages: whatwg-url: 5.0.0 dev: false - /node-fetch@2.6.13: - resolution: {integrity: sha512-StxNAxh15zr77QvvkmveSQ8uCQ4+v5FkvNTj0OESmiHu+VRi/gXArXtkWMElOsOUNLtUEvI4yS+rdtOHZTwlQA==} + /node-fetch@2.7.0: + resolution: {integrity: sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==} engines: {node: 4.x || >=6.0.0} peerDependencies: encoding: ^0.1.0 diff --git a/src/pages/api/webhooks/index.ts b/src/pages/api/webhooks/index.ts index 974346e..3448640 100644 --- a/src/pages/api/webhooks/index.ts +++ b/src/pages/api/webhooks/index.ts @@ -24,8 +24,8 @@ export default async function handler(req: NextRequest) { case WebhookEvents.USER_CREATED: success = await onUserCreatedHandler( data.id, - `${data.first_name} ${data.last_name}`, - data.email_addresses?.map((email) => email.email_address) || [] + data.email_addresses?.map((email) => email.email_address) || [], + `${data.first_name} ${data.last_name}` ); if (success) { return NextResponse.json( diff --git a/src/server/unkey.ts b/src/server/unkey.ts index 5157b74..6c5571a 100644 --- a/src/server/unkey.ts +++ b/src/server/unkey.ts @@ -1,31 +1,24 @@ -import { Unkey } from "@unkey/api"; +// import { Unkey, verifyKey } from "@unkey/api"; +import { verifyKey } from "@unkey/api"; import type { NextRequest } from "next/server"; -import { env } from "~/env.mjs"; +// import { env } from "~/env.mjs"; -export const unkey = new Unkey({ token: env.UNKEY_ROOT_KEY }); - -export const validateApiKey = async (key: string) => { - try { - const res = await unkey.keys.verify({ - key, - }); - return res.result?.valid || false; - } catch { - return false; - } -}; +// const unkey = new Unkey({token: env.UNKEY_ROOT_KEY}) export const validateRequest = async (req: NextRequest) => { - let isValidKey: boolean = false; - const authorization = req.headers.get("authorization"); // Get the auth bearer token if it exists if (authorization) { const key = authorization.split("Bearer ").at(1); if (key) { - isValidKey = await validateApiKey(key); + const { error, result } = await verifyKey(key); + + if (!error) { + console.log(result); + return result.valid; + } } } - return isValidKey; + return false; }; diff --git a/src/server/webhookHelpers.ts b/src/server/webhookHelpers.ts index ac460fd..f76c382 100644 --- a/src/server/webhookHelpers.ts +++ b/src/server/webhookHelpers.ts @@ -19,8 +19,8 @@ export const onUserDeletedHandler = async (userId: string) => { export const onUserCreatedHandler = async ( userId: string, - userName: string, - userEmails: string[] + userEmails: string[], + userName?: string ) => { const userUpdateResponse = await fetch( `https://api.clerk.com/v1/users/${userId}/metadata`, @@ -47,7 +47,7 @@ export const onUserCreatedHandler = async ( from: "no-reply@sprintpadawan.dev", to: userEmail, subject: "🎉 Welcome to Sprint Padawan! 🎉", - react: Welcome({ name: userName }), + react: Welcome({ name: userName ? userEmail : userEmail }), }); }); } diff --git a/src/utils/types.ts b/src/utils/types.ts index 1c3f2d9..be552bc 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -33,8 +33,8 @@ export const WebhookEventBodySchema = z.object({ }) ) .optional(), - first_name: z.string().optional(), - last_name: z.string().optional(), + first_name: z.string().nullable().optional(), + last_name: z.string().nullable().optional(), }), type: z.string(), }); diff --git a/tsconfig.json b/tsconfig.json index 2562b5c..03ebb74 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,7 +7,6 @@ "skipLibCheck": true, "strict": true, "forceConsistentCasingInFileNames": true, - "strictFunctionTypes": false, "noEmit": true, "esModuleInterop": true, "module": "esnext",