Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@akanshaa-18
Copy link

Implemented getPersonalizationData
Filled the 'unknown' types with actual types for Personalize.ts and ParseInstructions.ts

Resolves:
MWPW-175569
MWPW-175576

prefix: string;
};

export function determineLocale(
Copy link
Collaborator

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,
Copy link
Collaborator

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)) {
Copy link
Collaborator

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,
Copy link
Collaborator

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;
Copy link
Collaborator

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;
Copy link
Collaborator

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;
Copy link
Collaborator

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

Comment on lines +169 to +174
type Cookies = Record<string, string>;

type CookieOptions = {
expires?: number | Date;
domain?: string;
};
Copy link
Collaborator

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

Comment on lines +724 to +740
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;
}
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants