Conversation
| prefix: string; | ||
| }; | ||
|
|
||
| export function determineLocale( |
There was a problem hiding this comment.
This ought to be in utilties, I think
| }; | ||
|
|
||
| export function determineLocale( | ||
| request: EW.ResponseProviderRequest, |
There was a problem hiding this comment.
Since you only need request for its headers, pass the headers instead of passing the request.
| const pathParts = url.pathname.split("/").filter(Boolean); | ||
| if (pathParts.length > 0) { | ||
| const possibleLocale = pathParts[0].toLowerCase(); | ||
| if (/^[a-z]{2}(-[a-z]{2})?$/.test(possibleLocale)) { |
There was a problem hiding this comment.
Add a comment explaining the regex in detail. Not just what it does but how it does it and why. That would help with maintainability.
|
|
||
| export const getPersonalizationData = async ( | ||
| request: EW.ResponseProviderRequest, | ||
| request: EW.ResponseProviderRequest, |
There was a problem hiding this comment.
Instead of passing around the request, extract what you need from the request and pass that into your functions.
| locale: Locale; | ||
| env: string; | ||
| url: URL; | ||
| request: EW.ResponseProviderRequest; |
There was a problem hiding this comment.
Instead of passing around the request, extract what you need from the request and pass that into your functions.
| }; | ||
|
|
||
| type VisitorStatusParams = { | ||
| request: EW.ResponseProviderRequest; |
There was a problem hiding this comment.
Instead of passing around the request, extract what you need from the request and pass that into your functions.
| type: "FragmentInstruction"; | ||
| selector: string; | ||
| val: string; | ||
| action: string; |
There was a problem hiding this comment.
Instead of allowing this to be any arbitrary string, make a type Action where you enumerate what the different actions can be
type Action = 'InsertBefore' | 'InsertAfter' | 'Delete' | 'Replace' // For example| type Cookies = Record<string, string>; | ||
|
|
||
| type CookieOptions = { | ||
| expires?: number | Date; | ||
| domain?: string; | ||
| }; |
There was a problem hiding this comment.
Remember to replace these with the types from Utils once #3 is merged
| function setCookie( | ||
| domain: string, | ||
| key: string, | ||
| value: string, | ||
| options: CookieOptions = {} | ||
| ): string { | ||
| const expires = options.expires; | ||
| const date = new Date(); | ||
|
|
||
| const expiresInDays = typeof expires === 'number' ? expires : 730; | ||
| date.setTime(date.getTime() + expiresInDays * 24 * 60 * 60 * 1000); | ||
|
|
||
| const expiresString = `expires=${date.toUTCString()}`; | ||
|
|
||
| const cookie = `${key}=${value}; ${expiresString}; path=/ ; domain=.${domain};`; | ||
| return cookie; | ||
| } |
There was a problem hiding this comment.
Remember to rewrite this to use the implementation in utils once #3 is merged.
Implemented getPersonalizationData
Filled the 'unknown' types with actual types for Personalize.ts and ParseInstructions.ts
Resolves:
MWPW-175569
MWPW-175576