-
Notifications
You must be signed in to change notification settings - Fork 4
Implemented getPersonalizationData #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| prefix: string; | ||
| }; | ||
|
|
||
| export function determineLocale( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ought to be in utilties, I think
| }; | ||
|
|
||
| export function determineLocale( | ||
| request: EW.ResponseProviderRequest, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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