-
Notifications
You must be signed in to change notification settings - Fork 0
SparkLayer #2
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: development
Are you sure you want to change the base?
SparkLayer #2
Conversation
Summary of ChangesHello @tomheaton, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request primarily focuses on integrating and configuring the SparkLayer B2B e-commerce solution within the application. It updates site identifiers, establishes a secure method for retrieving and exposing a SparkLayer authentication token to the client-side, and transitions the SparkLayer script loading to a production-ready CDN, ensuring the B2B features are correctly initialized and accessible. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request introduces changes for SparkLayer integration, including configuration updates and new logic to fetch an authentication token. My review identifies several areas for improvement, primarily in app/routes/members-area.my-account/route.tsx. The feedback focuses on removing debugging artifacts, avoiding risky practices like monkey-patching global objects, and adopting more robust solutions for handling external URLs and global variables to enhance code quality and maintainability.
| const originalFetch = globalThis.fetch; | ||
|
|
||
| globalThis.fetch = async (input: RequestInfo | URL, init?: RequestInit) => { | ||
| const headers = init?.headers instanceof Headers | ||
| ? Object.fromEntries(init.headers.entries()) | ||
| : init?.headers; | ||
|
|
||
| console.log('[fetch] Request:', request); | ||
|
|
||
| return originalFetch(input, init); | ||
| }; |
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.
Monkey-patching globalThis.fetch is a dangerous practice, especially in a server-side context. It can lead to unpredictable side effects and race conditions if requests are handled concurrently. This code appears to be for debugging and should be removed. If you need to inspect fetch requests during development, consider using a debugging proxy or other less intrusive methods.
| }; | ||
|
|
||
| // const response = await api.getWixClient().fetchWithAuth('https://03bf7894-a496-4460-b500-af40b7038e79.wix-app.run/functions/spark-current-member?siteId=wixcodux&siteEnv=live') | ||
| const response = await api.getWixClient().fetchWithAuth('https://9da4afbf-fe40-444f-9554-aadcd186caf8.wix-app.run/functions/spark-current-member?siteId=wixcodux&siteEnv=live') |
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 URL is hardcoded. Hardcoding configuration values like URLs makes it difficult to manage different environments (development, staging, production). It's a best practice to store such values in environment variables. For example, you could define SPARK_CURRENT_MEMBER_URL in your .env file.
| const response = await api.getWixClient().fetchWithAuth('https://9da4afbf-fe40-444f-9554-aadcd186caf8.wix-app.run/functions/spark-current-member?siteId=wixcodux&siteEnv=live') | |
| const response = await api.getWixClient().fetchWithAuth(process.env.SPARK_CURRENT_MEMBER_URL!) |
| // eslint-disable-next-line no-console | ||
| console.log('HTTP_PROXY', process.env.HTTP_PROXY); | ||
|
|
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.
| if (token) { | ||
| // eslint-disable-next-line no-console | ||
| console.log('token is defined', token); | ||
| // @ts-expect-error sparkWixToken is not defined on window | ||
| window.sparkWixToken = token; | ||
| } else { | ||
| // eslint-disable-next-line no-console | ||
| console.log('token is not defined'); | ||
| } |
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 block contains some temporary code that should be cleaned up:
- Debug logs: The
console.logstatements on lines 69 and 74 appear to be for debugging and should be removed. - Unsafe global assignment: Assigning to
window.sparkWixTokendirectly is not type-safe, as indicated by the@ts-expect-error. To fix this, you should extend theWindowinterface to make TypeScript aware of this property. You can do this by adding the following to a declaration file (e.g.,remix.env.d.ts):declare global { interface Window { sparkWixToken?: string; } } export {};
This will provide type safety and allow you to remove the // @ts-expect-error comment.
if (token) {
window.sparkWixToken = token;
}
Changes summary
Risks
Manual testing done