Skip to content

feat: adding session log - #3279

Merged
hellofanny merged 10 commits into
feat/vtex-dayfrom
session-log
Apr 16, 2026
Merged

hellofanny merged 10 commits into
feat/vtex-dayfrom
session-log

Conversation

@ommeirelles

@ommeirelles ommeirelles commented Apr 16, 2026 •

Copy link
Copy Markdown
Contributor

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.

@ommeirelles
ommeirelles requested a review from a team as a code owner April 16, 2026 00:08
@ommeirelles
ommeirelles requested review from hellofanny and lariciamota and removed request for a team April 16, 2026 00:08
@coderabbitai

coderabbitai Bot commented Apr 16, 2026 •

Copy link
Copy Markdown
Contributor

Walkthrough

validateSession now fetches localization via exported getSettings(), derives/normalizes a channel from session.channel plus settings.salesChannel, and may mutate the incoming session to update locale, currency, and channel before continuing with existing delivery/postal-code logic and the GraphQL validateSession request. Also: production/client source maps enabled (Next.js + Vite) and a trace log added in optimistic store code.

Changes

Cohort / File(s) Summary
Session validation & localization
packages/core/src/sdk/session/index.ts
validateSession now calls exported getSettings(), composes a channel value from session.channel JSON and settings.salesChannel, and conditionally mutates the passed session to update locale, currency, and channel when they differ (comparison: raw channel string, direct locale, deep-equal for currency). Runs before delivery/postal-code and GraphQL validate.
Localization helper export
packages/core/src/sdk/localization/useLocalizationConfig.tsx
`getSettings(params?: { url?: string
Source maps: Next.js
packages/core/next.config.js
Enabled productionBrowserSourceMaps: true and added a webpack source-map-loader pre-rule for .js under node_modules/@faststore/.
Source maps: Vite
packages/sdk/vite.config.mts
Enabled inline source maps by setting build.sourcemap = 'inline'.
Optimistic store logging
packages/sdk/src/store/optimistic.ts
Added console.trace(...) when a validated value is present and subscription active, logging value and validated before store.set(validated).

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • hellofanny
  • emersonlaurentino

Poem

🌐 A session wakes and checks its tongue and coin,
Channels stitched from JSON and a settings join.
Maps now whisper where the bugs might hide,
Traces leave footprints of the hopeful stride. ✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'feat: adding session log' is vague and does not accurately reflect the main changes. The PR modifies session validation logic, localization settings, source map configurations, and adds debugging output—not just logging. Revise the title to specifically describe the primary change, such as 'feat: integrate localization settings into session validation' or 'feat: enhance session validation with localization and diagnostics'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch session-log

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codesandbox-ci

codesandbox-ci Bot commented Apr 16, 2026 •

Copy link
Copy Markdown

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9115316 and 4037e02.

📒 Files selected for processing (1)
  • packages/core/src/sdk/session/index.ts

Comment thread packages/core/src/sdk/session/index.ts Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4037e02 and 1d6a193.

📒 Files selected for processing (2)
  • packages/core/next.config.js
  • packages/sdk/vite.config.mts
✅ Files skipped from review due to trivial changes (1)
  • packages/core/next.config.js

Comment thread packages/sdk/vite.config.mts Outdated
root: process.env.PWD ?? process.cwd(),
plugins: [dts()],
build: {
sourcemap: 'inline',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 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 2

Repository: 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.

Suggested change
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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 | 🟠 Major

Guard config.localization before first dereference.

getSettings now exported, but it dereferences config.localization before the null check. If localization is missing, this crashes with a generic TypeError instead 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

📥 Commits

Reviewing files that changed from the base of the PR and between 1d6a193 and 8436b4b.

📒 Files selected for processing (4)
  • packages/core/next.config.js
  • packages/core/src/sdk/localization/useLocalizationConfig.tsx
  • packages/core/src/sdk/session/index.ts
  • packages/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

Comment thread packages/sdk/src/store/optimistic.ts Resolved
@hellofanny
hellofanny merged commit e3cbeae into feat/vtex-day Apr 16, 2026
3 checks passed
@hellofanny
hellofanny deleted the session-log branch April 16, 2026 04:07
hellofanny pushed a commit that referenced this pull request Apr 23, 2026
<!-- 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 -->
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