Merged in feature/wrap-logging (pull request #2511)

Feature/wrap logging

* feat: change all logging to go through our own logger function so that we can control log levels

* move packages/trpc to using our own logger

* merge


Approved-by: Linus Flood
This commit is contained in:
Joakim Jäderberg
2025-07-03 12:37:04 +00:00
parent 7e32ed294d
commit daf765f3d5
110 changed files with 681 additions and 441 deletions

View File

@@ -2,12 +2,15 @@ import "server-only"
import crypto from "crypto"
import { createLogger } from "@scandic-hotels/common/logger/createLogger"
import { env } from "../../env/server"
const algorithm = "DES-ECB"
const encryptionKey = env.BOOKING_ENCRYPTION_KEY
const bufferKey = Buffer.from(encryptionKey, "utf8")
const encryptionLogger = createLogger("encryption")
export function encrypt(originalString: string) {
try {
const cipher = crypto.createCipheriv(algorithm, bufferKey, null)
@@ -25,7 +28,7 @@ export function encrypt(originalString: string) {
const result = Buffer.concat(buffers).toString("base64")
return result
} catch (e) {
console.log(e)
encryptionLogger.error("encryption error", e)
return ""
}
}
@@ -46,7 +49,7 @@ export function decrypt(encryptedString: string) {
.replace(/(\x00)*/g, "")
return result
} catch (e) {
console.log(e)
encryptionLogger.error("decryption error", e)
return ""
}
}

View File

@@ -1,24 +1,27 @@
import "server-only"
import { createLogger } from "@scandic-hotels/common/logger/createLogger"
import type { Session } from "next-auth"
export function isValidSession(session: Session | null): session is Session {
const sessionLogger = createLogger("session")
if (!session) {
return false
}
if (session.error) {
console.log(`Session error: ${session.error}`)
sessionLogger.error(`Session error: ${session.error}`)
return false
}
const token = session.token
if (token?.error) {
console.log(`Session token error: ${token.error}`)
sessionLogger.error(`Session token error: ${token.error}`)
return false
}
if (token?.expires_at && token.expires_at < Date.now()) {
console.log(`Session expired: ${session.token.expires_at}`)
sessionLogger.debug(`Session expired: ${session.token.expires_at}`)
return false
}