-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web): add database level request loggin (#60)
- Loading branch information
Showing
11 changed files
with
90 additions
and
24 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
apps/web/prisma/migrations/20230901064929_add_requests/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
-- CreateTable | ||
CREATE TABLE `ApiRequest` ( | ||
`id` VARCHAR(191) NOT NULL, | ||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), | ||
`type` ENUM('GET_CONFIG', 'TRACK_VIEW') NOT NULL, | ||
`hashedIp` VARCHAR(191) NOT NULL, | ||
`durationInMs` INTEGER NOT NULL, | ||
`projectId` VARCHAR(191) NOT NULL, | ||
|
||
INDEX `ApiRequest_projectId_idx`(`projectId`), | ||
PRIMARY KEY (`id`) | ||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; |
8 changes: 8 additions & 0 deletions
8
apps/web/prisma/migrations/20230901065851_remove_hashed_ip_field/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
Warnings: | ||
- You are about to drop the column `hashedIp` on the `ApiRequest` table. All the data in the column will be lost. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE `ApiRequest` DROP COLUMN `hashedIp`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { ApiRequest } from "@prisma/client"; | ||
import { hashString } from "utils/apiKey"; | ||
import { prisma } from "server/db/client"; | ||
|
||
export abstract class RequestService { | ||
static async storeRequest(request: Omit<ApiRequest, "id" | "createdAt">) { | ||
await prisma.apiRequest.create({ | ||
data: { | ||
...request, | ||
}, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,14 @@ | ||
import { createHmac, randomBytes } from "crypto"; | ||
import { env } from "env/server.mjs"; | ||
|
||
export function generateRandomString(length = 32): string { | ||
const apiKey = randomBytes(length).toString("hex"); | ||
return apiKey; | ||
} | ||
|
||
export function hashApiKey(apiKey: string): string { | ||
const hmac = createHmac( | ||
"sha256", | ||
"dieserkeyistsupergeheimbittenichtweitergebendanke" | ||
); | ||
hmac.update(apiKey); | ||
export function hashString(data: string): string { | ||
const hmac = createHmac("sha256", env.HASHING_SECRET); | ||
hmac.update(data); | ||
const hashKey = hmac.digest("hex"); | ||
return hashKey; | ||
} |
f0c99c4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
abby-opensource – ./apps/web
abby-opensource.vercel.app
abby-opensource-git-main-dynabase.vercel.app
preview.tryabby.com
abby-opensource-dynabase.vercel.app