Repository navigation
fix: Update sdk version locales - #3205
Conversation
WalkthroughThe changes include a dependency version bump for Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 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
🤖 Fix all issues with AI agents
In `@packages/core/src/sdk/localization/types.ts`:
- Around line 5-14: The JSDoc on isDefault currently claims "exactly one per
locale" but that constraint isn't enforced; update the comment in
packages/core/src/sdk/localization/types.ts to document the actual runtime
fallback (i.e., when no binding has isDefault the code uses find((b) =>
b.isDefault) ?? matches[0]) and state that generate-i18n/SDK will fall back to
the first match rather than enforcing a single default; alternatively, if you
prefer enforcement, add a validation step in generate-i18n that checks bindings
per locale and emits a warning/error when zero or multiple isDefault=true are
found (reference generate-i18n and the runtime selection logic using find((b) =>
b.isDefault) ?? matches[0] when implementing the check).
| /** | ||
| * When true, this binding is preferred for its locale in two cases: | ||
| * (1) When the URL does not match any binding, the default locale's binding | ||
| * with isDefault is used for session/settings. | ||
| * (2) When resolving locale+currency and multiple bindings match (e.g. same | ||
| * currency, different URLs), the one with isDefault is chosen. | ||
| * Each locale should have exactly one binding with isDefault: true to avoid | ||
| * ambiguous resolution. | ||
| */ | ||
| isDefault: boolean |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# Search for isDefault usage and any validation logic
rg -n 'isDefault' --type ts -g '!**/node_modules/**' -g '!**/*.d.ts' | head -50Repository: vtex/faststore
Length of output: 4921
🏁 Script executed:
# Search for validation logic related to bindings or locales
rg -n -A 5 'validate|check.*binding|default.*per.*locale' --type ts -g '!**/node_modules/**' -g '!**/*.d.ts' | head -80Repository: vtex/faststore
Length of output: 7358
🏁 Script executed:
# Look for generate-i18n command or similar CLI generation logic
fd -e ts -g '!**/node_modules/**' | xargs grep -l 'generate.*i18n\|generate.*localization' 2>/dev/nullRepository: vtex/faststore
Length of output: 42
🏁 Script executed:
# Search for generate-i18n in all files
rg -n 'generate-i18n' --type ts --type js -g '!**/node_modules/**'Repository: vtex/faststore
Length of output: 724
🏁 Script executed:
# Check for any validation/enforcement of binding constraints
rg -n 'exactly one|one.*default|constraint.*binding|each locale' --type ts -g '!**/node_modules/**'Repository: vtex/faststore
Length of output: 557
🏁 Script executed:
# Look at the CLI package structure for i18n generation
find packages/cli -name '*i18n*' -o -name '*locali*' 2>/dev/null | head -20Repository: vtex/faststore
Length of output: 148
🏁 Script executed:
# Check bindingSelector.test.ts to understand the fallback behavior
sed -n '168,180p' packages/core/test/sdk/localization/bindingSelector.test.tsRepository: vtex/faststore
Length of output: 534
🏁 Script executed:
# Read the generate-i18n.ts file to see what validation it performs
cat packages/cli/src/commands/generate-i18n.tsRepository: vtex/faststore
Length of output: 4181
🏁 Script executed:
# Also check the test file to understand expected behavior
cat packages/cli/src/commands/generate-i18n.test.tsRepository: vtex/faststore
Length of output: 7562
The "exactly one per locale" constraint is not validated — update JSDoc or add runtime checks.
No validation exists in generate-i18n or the SDK to enforce this constraint. The test data itself includes violations (e.g., it-IT, en-CA have no isDefault: true binding). The code handles missing defaults gracefully via fallbacks (find((b) => b.isDefault) ?? matches[0]), but the JSDoc claims a constraint that isn't actually enforced. Either:
- Add validation in
generate-i18nto warn/error on constraint violations, or - Update the JSDoc to document the actual fallback behavior instead of prescribing an unenforceable rule.
🤖 Prompt for AI Agents
In `@packages/core/src/sdk/localization/types.ts` around lines 5 - 14, The JSDoc
on isDefault currently claims "exactly one per locale" but that constraint isn't
enforced; update the comment in packages/core/src/sdk/localization/types.ts to
document the actual runtime fallback (i.e., when no binding has isDefault the
code uses find((b) => b.isDefault) ?? matches[0]) and state that
generate-i18n/SDK will fall back to the first match rather than enforcing a
single default; alternatively, if you prefer enforcement, add a validation step
in generate-i18n that checks bindings per locale and emits a warning/error when
zero or multiple isDefault=true are found (reference generate-i18n and the
runtime selection logic using find((b) => b.isDefault) ?? matches[0] when
implementing the check).
There was a problem hiding this comment.
This is already being validated in the sdk, so I didn't add any extra test for it.
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Search for imports from `@vtex/faststore-sdk` and any validation-related code
echo "=== Searching for SDK imports and usage ==="
rg -n '@vtex/faststore-sdk' --type ts -A 5 | head -100
echo -e "\n=== Searching for binding validation or locale validation calls ==="
rg -n 'validate.*binding|validate.*locale|validateBinding|validateLocale' --type ts -C 3 | head -80
echo -e "\n=== Check if SDK exports validation functions ==="
rg -n 'from.*@vtex/faststore-sdk.*import' --type ts | head -30
Length of output: 5825
🏁 Script executed:
#!/bin/bash
# Check how FastStoreSDK is used in generate-i18n command
echo "=== FastStoreSDK usage in generate-i18n.ts ==="
sed -n '1,120p' packages/cli/src/commands/generate-i18n.ts | grep -A 10 -B 2 'FastStoreSDK\|sdk\.'
Length of output: 600
@hellofanny Got it — I can't inspect the external SDK's validation logic from this repo, so I'll defer to your knowledge of the SDK implementation. Thanks for clarifying!
🧬 Code Graph Analysis Results
-
File: packages/core/src/sdk/localization/index.ts, lines 1-1
- Snippet:
Binding
- Snippet:
-
File: packages/core/src/sdk/localization/index.ts, lines 1-1
- Snippet:
Locale
- Snippet:
-
File: packages/core/src/sdk/localization/index.ts, lines 1-1
- Snippet:
BindingSelectorError
- Snippet:
There was a problem hiding this comment.
We could update the test data
There was a problem hiding this comment.
Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!
## What's the purpose of this pull request? Removing hardcoded labels: - #3099 - #3102 - #3107 - #3104 - #3103 - #3125 - #3131 - #3116 - #3142 - #3192 Setting Up locales - #3141 - #3143 - #3147 - #3156 - #3162 - #3145 - #3164 - #3169 - #3171 - #3176 - #3180 - #3169 custom path - #3185 - #3162 - #3156 - #3170 Components - #3093 - #3175 Fetching content - #3165 Others - #3176 - #3171 - #3181 - #3189 - #3205 ## How to test locally? - Run `pnpm I` (install all the new dependencies and needed packages) - If you want to try localization feature, go to`/discovery.config.default.js`: Enable localization: ``` localization: { enabled: true } ``` - Run `node packages/cli/bin/run.js generate-i18n ./packages/core` to fetch the bindings If the contentSource is not set to content platform yet, you will see a message to update to it. > contentSource: { > type: 'CP', > },⚠️ Note: Ensure the url is set to localhost for local testing. These locale bindings are generated in `discovery.config` after running the generate-i18n command. ```diff localization: { enabled: true, defaultLocale: 'en-US', regions: {...}, locales: { 'pt-BR': { ... bindings: [ { currencyCode: 'BRL', - url: 'https://brandless.fast.store/pt-BR', + url: 'http://localhost:3000/pt-BR', salesChannel: '2', isDefault: true, locales: [ { code: 'pt-BR', isDefault: true, }, ], }, ], }, 'it-IT': { ... bindings: [ { currencyCode: 'EUR', - url: 'https://brandless.fast.store/it-IT', + url: 'http://localhost:3000/it-IT', salesChannel: '3', isDefault: true, locales: [ { code: 'it-IT', isDefault: true, }, ], }, { currencyCode: 'EUR', - url: 'https://brandless.fast.store/europe/it', + url: 'http://localhost:3000/europe/it', salesChannel: '3', isDefault: false, locales: [ { code: 'it-IT', isDefault: true, }, ], }, ], }, 'en-US': { code: 'en-US', name: 'English', languageCode: 'en', languageName: 'English', script: 'Latn', textDirection: 'ltr', regionCode: 'US', bindings: [ { currencyCode: 'USD', - url: 'https://brandless.fast.store', + url: 'http://localhost:3000, salesChannel: '1', isDefault: true, locales: [ { code: 'en-US', isDefault: true, }, ], }, ], }, ... } ``` - Go to /packages/core and run `npmn dev` --------- Co-authored-by: Larícia Mota <[email protected]> Co-authored-by: Leandro Rodrigues <[email protected]> Co-authored-by: Otavio Moreira Meirelles <[email protected]> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
What's the purpose of this pull request?
Updates the faststore-sdk version to the latest with isDefault locale fix.
It might have been cause some inconsistencies in our testing.
How it works?
We should have only one
isDefault: trueper binding.How to test it?
node packages/cli/bin/run.js generate-i18n ./packages/coreisDefault:true.Starters Deploy Preview
starter preview: https://brandless-cma5xay4001f6dn4xjwato8b4-hk7s7lz52.b.vtex.app/
References
Summary by CodeRabbit
New Features
Chores