22 lines
505 B
TypeScript
22 lines
505 B
TypeScript
import "server-only"
|
|
|
|
import { decrypt, encrypt } from "./encryption"
|
|
|
|
export function calculateRefId(confirmationNumber: string, lastName: string) {
|
|
const encryptedRefId = encrypt(`${confirmationNumber},${lastName}`)
|
|
|
|
return encryptedRefId
|
|
}
|
|
|
|
export function parseRefId(refId: string) {
|
|
const data = decrypt(refId)
|
|
const parts = data.split(",")
|
|
if (parts.length !== 2) {
|
|
throw new Error("Invalid refId format")
|
|
}
|
|
return {
|
|
confirmationNumber: parts[0],
|
|
lastName: parts[1],
|
|
}
|
|
}
|