feat(SW-2116): avoid passing entire booking object to Room client component

This commit is contained in:
Arvid Norlin
2025-04-23 15:47:18 +02:00
committed by Michael Zetterberg
parent a839d05e09
commit 7eeb0bbcac
11 changed files with 75 additions and 43 deletions

View File

@@ -7,8 +7,9 @@ import {
serviceProcedure,
} from "@/server/trpc"
import { calculateRefId } from "@/utils/refId"
import { getHotel } from "../hotels/utils"
import { encrypt } from "../utils/encryption"
import {
createRefIdInput,
getBookingInput,
@@ -169,7 +170,7 @@ export const bookingQueryRouter = router({
.input(createRefIdInput)
.mutation(async function ({ input }) {
const { confirmationNumber, lastName } = input
const encryptedRefId = encrypt(`${confirmationNumber},${lastName}`)
const encryptedRefId = calculateRefId(confirmationNumber, lastName)
if (!encryptedRefId) {
throw serverErrorByStatus(422, "Was not able to encrypt ref id")

View File

@@ -4,10 +4,10 @@ import { myStay } from "@/constants/routes/myStay"
import { env } from "@/env/server"
import * as api from "@/lib/api"
import { dt } from "@/lib/dt"
import { encrypt } from "@/server/routers/utils/encryption"
import { createCounter } from "@/server/telemetry"
import { cache } from "@/utils/cache"
import { encrypt } from "@/utils/encryption"
import * as maskValue from "@/utils/maskValue"
import { isValidSession } from "@/utils/session"
import { getCurrentWebUrl } from "@/utils/url"

View File

@@ -1,54 +0,0 @@
import "server-only"
import crypto from "crypto"
import { env } from "@/env/server"
export { decrypt, encrypt }
const algorithm = "DES-ECB"
const encryptionKey = env.BOOKING_ENCRYPTION_KEY
const bufferKey = Buffer.from(encryptionKey, "utf8")
function encrypt(originalString: string) {
try {
const cipher = crypto.createCipheriv(algorithm, bufferKey, null)
cipher.setAutoPadding(false)
const bufferString = Buffer.from(originalString, "utf8")
const paddingSize =
bufferKey.length - (bufferString.length % bufferKey.length)
const paddedStr = Buffer.concat([
bufferString,
Buffer.alloc(paddingSize, 0),
])
const buffers: Buffer[] = []
buffers.push(cipher.update(paddedStr))
buffers.push(cipher.final())
const result = Buffer.concat(buffers).toString("base64").replace(/\+/g, "-")
return result
} catch (e) {
console.log(e)
return ""
}
}
function decrypt(encryptedString: string) {
try {
const decipher = crypto.createDecipheriv(algorithm, bufferKey, null)
decipher.setAutoPadding(false)
const buffers: Buffer[] = []
buffers.push(decipher.update(encryptedString, "base64"))
buffers.push(decipher.final())
const result = Buffer.concat(buffers)
.toString("utf8")
/*
* Hexadecimal byte (null byte) replace. These occur when decrypting because
* we're disabling the auto padding for historical/compatibility reasons.
*/
.replace(/(\x00)*/g, "")
return result
} catch (e) {
console.log(e)
return ""
}
}