fix(SW-2116): add compatibility with RefId from Current Web

This commit is contained in:
Michael Zetterberg
2025-05-08 13:36:27 +02:00
parent baee0ee40c
commit 8cb63c4947

View File

@@ -9,12 +9,20 @@ export function calculateRefId(confirmationNumber: string, lastName: string) {
} }
export function parseRefId(refId: string) { export function parseRefId(refId: string) {
// Some external systems that link to us do not encode the refId parameter // RefId is DES-ECB encryption + Base64 encoding. For legacy reasons we have
// properly, so we reverse the decoding of plus sign into spaces. // to do some manual handling here to get a proper Base64 string.
// Slash and equal sign are not decoded into anything, so no action needed. //
// We only need to cater for those three (plus, slash, equals) as RefId is // - Use case: Current web replaced plus sign with hyphens when generating RefIds.
// Base64 encoded which only has these three special characters. // Handling: We replace hyphens with plus signs.
const data = decrypt(refId.replace(/ /g, "+")) //
// - Use case: Incoming links in the wild do not encode the RefId properly.
// Handling: We replace spaces with plus signs. Effectively, reversing the
// decoding of plus signs into spaces that Next.js does for us for incoming
// search params.
// Slash and equal sign are not decoded into anything, so no action needed.
// We only need to cater for those three (plus, slash, equals) as RefId is
// Base64 encoded which only has these three special characters.
const data = decrypt(refId.replace(/ |-/g, "+"))
const parts = data.split(",") const parts = data.split(",")
if (parts.length !== 2) { if (parts.length !== 2) {
throw new Error("Invalid refId format") throw new Error("Invalid refId format")