Repository navigation
feat: adding session log - #3279
Conversation
WalkthroughvalidateSession now fetches localization via exported Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Caller
participant getSettings as getSettings()
participant Session as validateSession(session)
participant GraphQL as validateSessionGraphQL
Note over Caller,Session: validateSession invoked with session
Caller->>getSettings: request localization settings
getSettings-->>Caller: return settings (salesChannel, locale, currency)
Caller->>Session: derive channel from session.channel + settings.salesChannel
alt Differences found (locale/currency/channel)
Session->>Session: mutate session.locale, session.currency, session.channel
end
Session->>GraphQL: continue to existing validateSession GraphQL request
GraphQL-->>Session: response
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/core/src/sdk/session/index.ts`:
- Around line 157-162: Remove the unconditional console.trace in the session
setter hot path (the `console.trace('Session Set %o', {...})` call) — either
delete it or gate it behind a development-only check (e.g.,
NODE_ENV==='development') and move it so it runs after the deep-equal early
return that prevents no-op updates; update the code around the session setter
(the trace call and the deep-equal guard) so production builds do not execute
this logging and only actual state changes in development produce the trace.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 2ad042a2-3b38-4f68-9e0e-2eb8c18db87d
📒 Files selected for processing (1)
packages/core/src/sdk/session/index.ts
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/sdk/vite.config.mts`:
- Line 11: The vite config currently sets sourcemap: 'inline' which embeds
source maps into shipped bundles; change this to produce external/hidden maps
for published SDKs by replacing the inline setting with a production-safe option
(e.g., use 'hidden' or generate external maps) inside the exported Vite config
(look for the sourcemap property in the defineConfig/export default block).
Optionally gate inline maps behind a debug flag (check process.env.DEBUG or
similar) so during local debugging you can keep 'inline' but for npm publishes
use 'hidden' or external maps.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: c52bd453-8eca-4526-afdf-133b37a870ed
📒 Files selected for processing (2)
packages/core/next.config.jspackages/sdk/vite.config.mts
✅ Files skipped from review due to trivial changes (1)
- packages/core/next.config.js
| root: process.env.PWD ?? process.cwd(), | ||
| plugins: [dts()], | ||
| build: { | ||
| sourcemap: 'inline', |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Verify how SDK artifacts are published and whether dist is exposed.
cat packages/sdk/package.json | jq '{name, version, files, main, module, exports, types}'
# Check sourcemap settings currently present in build-related configs.
rg -n --type=ts --type=js '\bsourcemap\b|productionBrowserSourceMaps'Repository: vtex/faststore
Length of output: 273
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Verify how SDK artifacts are published
echo "=== SDK Package Configuration ==="
cat packages/sdk/package.json | jq '{name, version, files, main, module, exports, types}' 2>/dev/null || cat packages/sdk/package.json | jq '.' | head -30
# Check the vite config to understand the build context
echo -e "\n=== Vite Config (packages/sdk/vite.config.mts) ==="
cat packages/sdk/vite.config.mts
# Check sourcemap settings in build-related configs
echo -e "\n=== Sourcemap Settings in Codebase ==="
rg -n 'sourcemap|productionBrowserSourceMaps' --type ts --type js --type json -A 2Repository: vtex/faststore
Length of output: 1841
Use external or hidden sourcemaps for SDK distribution.
The SDK is published to npm (included in files), so sourcemap: 'inline' at Line 11 embeds maps directly into the CJS/ESM bundles shipped to consumers. This inflates artifact size and exposes full source. Other packages in this monorepo use external sourcemaps instead.
Use sourcemap: 'hidden' for production or gate inline maps behind a debug flag:
Suggested fix
build: {
- sourcemap: 'inline',
+ sourcemap: process.env.DEBUG_SOURCEMAP === 'true' ? 'inline' : 'hidden',
outDir: './dist',📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| sourcemap: 'inline', | |
| build: { | |
| sourcemap: process.env.DEBUG_SOURCEMAP === 'true' ? 'inline' : 'hidden', | |
| outDir: './dist', |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/sdk/vite.config.mts` at line 11, The vite config currently sets
sourcemap: 'inline' which embeds source maps into shipped bundles; change this
to produce external/hidden maps for published SDKs by replacing the inline
setting with a production-safe option (e.g., use 'hidden' or generate external
maps) inside the exported Vite config (look for the sourcemap property in the
defineConfig/export default block). Optionally gate inline maps behind a debug
flag (check process.env.DEBUG or similar) so during local debugging you can keep
'inline' but for npm publishes use 'hidden' or external maps.
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/core/src/sdk/localization/useLocalizationConfig.tsx (1)
91-95:⚠️ Potential issue | 🟠 MajorGuard
config.localizationbefore first dereference.
getSettingsnow exported, but it dereferencesconfig.localizationbefore the null check. If localization is missing, this crashes with a genericTypeErrorinstead of your explicit error path.Suggested fix
export function getSettings(params?: { url?: string | URL }) { + if (!config.localization) { + const err = new Error( + 'Missing localization configuration in faststore config file.' + ) + console.error(err) + throw err + } + let url = params?.url ?? '' - const defaultConfig = config.localization.locales[ - config.localization.defaultLocale - ] as ConfigType + const defaultConfig = config.localization.locales[ + config.localization.defaultLocale + ] as ConfigType @@ - if (!config.localization) { - const Err = new Error( - 'Missing localization configuration in faststore config file.' - ) - console.error(Err) - throw Err - } - const { config: regionConfig, binding } = matchURLBinding(url)Also applies to: 118-124
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/core/src/sdk/localization/useLocalizationConfig.tsx` around lines 91 - 95, The function getSettings dereferences config.localization immediately (used to compute defaultConfig), causing a TypeError when localization is undefined; update getSettings to first guard that config.localization exists and throw the explicit error path if not, then proceed to read config.localization.defaultLocale and config.localization.locales; apply the same guard/explicit-error pattern for the other block referenced around the code that reads config.localization at the later section (the code around the logic that computes defaultConfig and any subsequent access to config.localization in this file) so all uses check for config.localization before dereferencing.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/sdk/src/store/optimistic.ts`:
- Around line 22-26: The console.trace call in
packages/sdk/src/store/optimistic.ts is logging full payloads (value, validated)
and a stack trace on every validation; remove that raw logging or gate it behind
a dev-only flag and redact sensitive fields. Update the optimistic validation
path (where console.trace is called) to either delete the console.trace
invocation entirely or replace it with a conditional debug logger that only runs
when an explicit DEV_DEBUG or similar env/flag is true, and ensure logged
objects have sensitive keys redacted before logging (reference the optimistic
validation block and the variables value and validated to locate the change).
---
Outside diff comments:
In `@packages/core/src/sdk/localization/useLocalizationConfig.tsx`:
- Around line 91-95: The function getSettings dereferences config.localization
immediately (used to compute defaultConfig), causing a TypeError when
localization is undefined; update getSettings to first guard that
config.localization exists and throw the explicit error path if not, then
proceed to read config.localization.defaultLocale and
config.localization.locales; apply the same guard/explicit-error pattern for the
other block referenced around the code that reads config.localization at the
later section (the code around the logic that computes defaultConfig and any
subsequent access to config.localization in this file) so all uses check for
config.localization before dereferencing.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 6bbe7cf4-ae09-483c-9092-62860fe27496
📒 Files selected for processing (4)
packages/core/next.config.jspackages/core/src/sdk/localization/useLocalizationConfig.tsxpackages/core/src/sdk/session/index.tspackages/sdk/src/store/optimistic.ts
✅ Files skipped from review due to trivial changes (1)
- packages/core/src/sdk/session/index.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/core/next.config.js
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Session validation now keeps locale, currency and sales channel in sync for a more consistent user experience. * Made localization settings retrieval available for integrations. * **Chores** * Added diagnostic trace logging to aid debugging. * Enabled production client-side source maps and inline source maps for the SDK build. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Summary by CodeRabbit
New Features
Chores