Repository navigation
feat!: faststore v4 - #3111
feat!: faststore v4#3111
Conversation
35f28db to
4856212
Compare
Merge the changes from main
## What's the purpose of this pull request? With these changes, if merchants remove the footer logo the entire footer component will not be hid anymore, it will throw a console error but the component should be displayed with no logo.
#3077) ## What's the purpose of this pull request? This PR fixes the `border-radius` of the Slider thumb in Firefox. The current CSS rule for Mozilla uses an inexistent variable, making the browser render a square instead of a circle: <img width="1028" height="181" alt="image" src="https://github.com/user-attachments/assets/50c08d79-a6a9-4d31-b2e7-5ef9e287080f" /> ## How it works? The `--fs-slider-thumb-radius` variable is replaced by `--fs-slider-thumb-border-radius`, the one that is defined in the default thumb variables. ## How to test it? - Use the `Local Install Instructions` from the [CodeSandbox CI](https://ci.codesandbox.io/status/vtex/faststore/pr/3077) to add this version in the `package.json` of a store. - Import the `Slider` atom (and styles) in a component following the docs: https://developers.vtex.com/docs/guides/faststore/atoms-slider - Run the store in development mode and browse it in Mozilla Firefox. ### Starters Deploy Preview I'm unable to generate a preview link but here's a screenshot from localhost: <img width="1287" height="617" alt="image" src="https://github.com/user-attachments/assets/f0a5a5e9-d657-41db-9415-303b5d17fefd" /> ## Checklist **PR Title and Commit Messages** - [x] PR title and commit messages follow the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) specification - Available prefixes: `feat`, `fix`, `chore`, `docs`, `style`, `refactor`, `ci` and `test` **PR Description** - [ ] Added a label according to the PR goal - `breaking change`, `bug`, `contributing`, `performance`, `documentation`.. _(No permissions. It's a bug though.)_ **Dependencies** - [N/A] Committed the `pnpm-lock.yaml` file when there were changes to the packages **Documentation** - [x] PR description - [N/A] For documentation changes, ping `@Mariana-Caetano` to review and update (Or submit a doc request)
- Add RTL Support --------- Co-authored-by: Larícia Mota <[email protected]> Co-authored-by: Leandro Rodrigues <[email protected]> Co-authored-by: Eduardo Formiga <[email protected]> Co-authored-by: vtexgithubbot <[email protected]> Co-authored-by: Lucas Feijó <[email protected]>
4856212 to
c8a37d9
Compare
## What's the purpose of this pull request? Upgrading next version to 15 --------- Co-authored-by: Larícia Mota <[email protected]> Co-authored-by: Matheus P. Silva <[email protected]> Co-authored-by: Leandro Rodrigues <[email protected]> Co-authored-by: Eduardo Formiga <[email protected]> Co-authored-by: vtexgithubbot <[email protected]> Co-authored-by: Lucas Feijó <[email protected]> Co-authored-by: Luiz Falcão <[email protected]> Co-authored-by: Fanny Chien <[email protected]>
|
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. |
Externalizing crypto module from vite to correct import it
Added run scripts to run core package. - dev script build script cant be commited as CI would fail cause it needs the cli do be build before, and the cli only runs after the core as it is a direct dep. So turbo doesn't allow circular dependency on scripts
|
Important Review skippedToo many files! This PR contains 281 files, which is 131 over the limit of 150. ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (19)
📒 Files selected for processing (281)
You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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 |
Updated dependencies: - "@testing-library/jest-dom" - "@lhci/cli": "^0.15.1", - "@graphql-codegen/cli": 6.1.1 - Updated to V6 as it was triggering warns in respect to their dependencies - [REMOVED] @types/cypress - Its not necessary on our current version of cypress anymore - [REMOVED] "@storybook/addon-interactions": "^8.6.14" - Is part of core storybook package now - [REMOVED] "@storybook/test": "^8.6.14" - Is part of core storybook package now - Removed unnecessary storybook addons that is part of storybook@9. - Migrate packages tests that used jest to vitest, Removed vite configurations and created vitest. - Updated pnpm to latest version stable. [NOW] <img width="1112" height="140" alt="image" src="https://github.com/user-attachments/assets/89d318b8-7ba8-49e9-b1c6-9c3a17a8ff98" /> [BEFORE] <img width="2615" height="350" alt="image" src="https://github.com/user-attachments/assets/29d1cb09-5e58-4add-85fc-e8d72ba065ea" /> - Deps unable to fix: > [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected] <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Tests** * Migrated component and SDK test suites from Jest to Vitest, added Vitest configs and centralized setup, and updated tests to use Vitest APIs and matchers. * **Chores** * Upgraded Storybook to 10.2.3 and simplified addons. * Updated development dependencies and package manager entries across packages. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Fixing sass dart deprecations usage. This Fix deprecations warnings from sass on the new dart version. Caveats: - include-media uses a lot of sass if and this is deprecated, as we cant do anything to fix it right now the warning for this deprecation only was disabled: `if-function` - Next uses a load sass ja api depracated, as we cant change it this warning was also disabled `legacy-js-api` - Before we imported the utilities in every sass file. This increased our style as we include in some files that didnt needed it. now this is not true anymore, any sass usage that require a utility must import it and prefix the mixins and variables with the module name. THIS RESULTS IN A BREAKING CHANGE FOR CLIENTS THAT PRESUME THAT UTILITIES ARE PRESENT AT ALL TIME. BEFORE vs AFTER <img width="1222" height="842" alt="image" src="https://github.com/user-attachments/assets/e371ee89-86c6-418f-8b33-138fd8c6709f" /> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Chores** * Updated styling system to use the Sass module/meta loader and unified how component styles and utilities are applied, improving consistency across responsive and utility-driven styles. * Adjusted Sass importer behavior to improve import resolution and suppress certain deprecation warnings. * **Dependencies** * Upgraded Sass and include-media; reorganized dependency vs. dev/peer placements across packages for clearer runtime vs. development usage. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Larícia Mota <[email protected]>
## What's the purpose of this pull request? Stores configured with i18n custom paths (e.g. `https://store.com/europe/it`) returned **404** in production whenever the URL did not match the canonical locale code (e.g. `/it-IT`). The same URLs worked locally with `yarn dev`, but failed after `yarn build && yarn start` and on the standalone production deploy. Three independent issues were colliding: 1. **`faststore start` was loading the wrong Next config.** `next start` was being spawned without the `.faststore` directory, so Next loaded a default config from the project root with `i18n = null`. Without `i18n`, the proxy threw `TypeError` on locale rewrites. 2. **Partytown was missing from production builds.** `partytown copylib` only ran via `predev`, so `/~partytown/partytown.js` was never copied into `public/` during `build` and the asset 404'd in production. 3. **Hostname validation was broken in standalone mode.** `request.nextUrl.hostname` resolves to the server bind address (`0.0.0.0` from the `HOSTNAME` env var set by the Dockerfile), not the client-facing host. The proxy compared this against binding hostnames (e.g. `brandless.fast.store`), so all binding rules were skipped and the catch-all returned 404. ## How it works? **1. `packages/cli/src/commands/start.ts`** — pass `tmpDir` (the `.faststore` directory) as a positional argument to `next start`, so it loads the correct `next.config.js` with the `i18n` config derived from `discovery.config.js`. Using a positional arg (instead of changing `cwd`) keeps `next` resolvable from the project root via workspace hoisting. ```ts return spawn(`${packageManager} next start ${tmpDir} -p ${port}`, { ... }) ``` **2. `packages/cli/src/utils/generate.ts`** — mirror `predev` with a `prebuild` hook so Partytown is copied into `public/~partytown/` before the build, ensuring it ships in the standalone output. ```ts predev: 'na run partytown', prebuild: 'na run partytown', ``` **3. `packages/core/src/proxy.ts`** — read the hostname from the `Host` header instead of `request.nextUrl.hostname`, so binding lookup works consistently in both `next start` and standalone (`node server.js`) environments. `shouldValidateHostname` stays enabled. ```ts const { pathname, search } = request.nextUrl // In standalone, request.nextUrl.hostname is the server bind address // (e.g. "0.0.0.0"), not the client-facing host. Use the Host header. const hostname = request.headers.get('host') ``` ## How to test it? The PR is already deployed on `brandless.fast.store`, where both fixes can be verified: - Open <https://brandless.fast.store/europe/it> → page renders correctly (no 404), confirming the custom path is resolved. - DevTools → Network → `GET /~partytown/partytown.js` → **200 OK**, confirming Partytown is shipped with the build. - Response of the page request includes the `x-middleware-rewrite` header pointing to the locale-prefixed path (e.g. `/it-IT/...`). <img width="469" height="134" alt="image" src="https://github.com/user-attachments/assets/49413f43-bbb5-48ba-8fba-0893d3b2bb8a" /> - Canonical locale paths (`/it-IT`, `/en-GB`, `/pt-BR`) keep returning 200 — no regression. ## References - Jira: [SFS-3110 — i18n custom paths](https://vtex-dev.atlassian.net/jira/software/c/projects/SFS/boards/1051?selectedIssue=SFS-3110) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **Refactor** * Centralized hostname extraction logic across API endpoints for improved consistency and reliability. * **Tests** * Added comprehensive test suite for hostname normalization utility covering edge cases and fallback scenarios. * **Chores** * Added partytown prebuild script to the build process. * Improved CLI start command execution with better process handling. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
## What's the purpose of this pull request? Locale switching already worked on live pages backed by the Content Platform data plane, but preview still fetched locale-agnostic content. That made localized preview sessions fall back to default-locale content even when the route and session had already switched locale. This change threads the active Next.js locale through FastStore preview fetching so preview content can resolve the same locale-aware way as live routes. ## How it works? The preview content pipeline now accepts an optional `locale` in FastStore content params and passes it through shared CMS helpers, page loaders, and Content Platform fetches. `ContentService` now forwards locale directly in Content Platform request params, and the shared global sections, landing page, search, and my account loaders now forward `context.locale` whenever preview content is requested. The preview API also accepts an optional `locale` while validating preview content, but preview cookies remain locator-based so locale still comes from the route/request context instead of preview payload state. ## How to test it? - Start FastStore with the companion `client-cp` and `content-platform` locale-preview changes available. - To test locally, you can start start the Control Plane API and set the `controlPlaneApiUrl` in the ClientCP construction on https://github.com/vtex/faststore/blob/feat/locales-on-preview-flow/packages/core/src/server/content/service.ts to your localhost URL. - Enable preview for localized content such as `home`, `landingPage`, `plp`, or `pdp`. - Open the preview page in the default locale and confirm content renders as expected. - Switch to another locale using the locale-prefixed route or the language selector and confirm the preview content changes to the selected locale. - Verify localized preview content is applied to shared global sections as well as the main page content. - Verify preview still works for home, landing pages, PLP, PDP, search, and the account pages that reuse global sections. - Call `/api/preview` with `locale=<locale>` during preview activation and confirm preview enablement still resolves the target content correctly. ### Starters Deploy Preview ## References - [CP-1182](https://vtex-dev.atlassian.net/browse/CP-1182) - Companion `@vtex/client-cp` changes to forward `locale` on control-plane preview requests. - Companion `content-platform` control-plane changes to resolve localized preview payloads and localized preview slugs. ## Checklist <em>You may erase this after checking them all 😉</em> **PR Title and Commit Messages** - [ ] PR title and commit messages follow the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) specification - Available prefixes: `feat`, `fix`, `chore`, `docs`, `style`, `refactor`, `ci` and `test` **PR Description** - [ ] Added a label according to the PR goal - `breaking change`, `bug`, `contributing`, `performance`, `documentation`.. **Dependencies** - [ ] Committed the `pnpm-lock.yaml` file when there were changes to the packages **Documentation** - [ ] PR description - [ ] For documentation changes, ping `@Mariana-Caetano` to review and update (Or submit a doc request) [CP-1182]: https://vtex-dev.atlassian.net/browse/CP-1182?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Locale-aware content retrieval propagated to pages, templates, and preview flows for improved multilingual rendering. * **Refactor** * Unified content request context to consolidate preview and locale handling across content fetches and helpers. * **Chores** * Updated core client dependency to a newer release. * **Tests** * Added tests for slug-to-parameter mapping and locale precedence/propagation in content option generation and preview handling. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
## What's the purpose of this pull request? In Next.js Version 14, domains configuration has been deprecated in favour of remotePatterns. ## How it works? Migrate from images.domains to images.remotePatterns in `next.config.js` file ## How to test it? Locally and in the preview deployment, remote images behave the same as before the images.remotePatterns change (load correctly, no regressions). ### Starters Deploy Preview https://sfj-cfc4309--brandless.preview.vtex.app/ [PR](vtex-sites/brandless.store#160) ## References https://nextjs.org/docs/messages/next-image-unconfigured-host <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Chores** * Updated image configuration settings for enhanced compatibility and security with image serving infrastructure. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
@faststore/api
@faststore/cli
@faststore/components
@faststore/core
@faststore/diagnostics
@faststore/lighthouse
@faststore/sdk
@faststore/ui
commit: |
…alization flag (#3296) ## What's the purpose of this pull request? This pull request introduces a conditional check for localization settings in the `validateSession` function to ensure that localization-related session updates only occur when localization is enabled. This helps prevent unnecessary or incorrect modifications to session data when localization is not in use. Session validation improvements: * Added a check for `storeConfig.localization?.enabled` before updating session currency and channel based on localization settings in `validateSession` in `session/index.ts`. [[1]](diffhunk://#diff-290ea657fb800da722fad84e0fc08d57ce2ad6614f0751450af0c10f7a813ddeR143) [[2]](diffhunk://#diff-290ea657fb800da722fad84e0fc08d57ce2ad6614f0751450af0c10f7a813ddeR159) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Enhanced session validation performance by optimizing localization enrichment logic to execute conditionally based on configuration settings. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
## What's the purpose of this pull request? This pull request introduces improvements to the sorting component and fixes to landing page retrieval logic. The main changes include providing default sort options, making the sort label and options optional, and correcting how landing pages are matched and queried by slug. Enhancements to sorting functionality: * Added a `DEFAULT_OPTIONS` object for sort options, making the `label` and `options` props of the `Sort` component optional and providing sensible defaults if they are not specified. (`packages/core/src/components/search/Sort/Sort.tsx`) * Ensured that the sort options fallback to defaults if a custom label or options are not provided, improving component usability and robustness. (`packages/core/src/components/search/Sort/Sort.tsx`) Bug fixes for landing page slug matching: * Fixed the landing page lookup to correctly compare slugs by prepending a `/` to the input slug, ensuring accurate page retrieval. (`packages/core/src/components/templates/LandingPage/LandingPage.tsx`) * Corrected the filter structure in the landing page query to nest the slug filter inside a `filters` object, aligning with expected API requirements. (`packages/core/src/components/templates/LandingPage/LandingPage.tsx`) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Fixed landing page slug matching to ensure correct URL path resolution and page loading. * **Refactor** * Improved Sort control flexibility with sensible defaults and support for partial customization of sort options. * **Chores** * Standardized CMS content filtering and fetch behavior for more reliable content loading. * Tightened content API typings for consistent filter handling. * **Style** * Centered preview icon layout and removed fixed sizing for improved visual alignment. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: fanny <[email protected]>
## What's the purpose of this pull request? Fixes the multi-language race condition where the `LocalizationSelector` would briefly flicker (or stay stuck on the wrong value) right after page load, because IDB-hydrated sessions could overwrite the URL-derived locale before the session reached a stable state. This was previously mitigated by a workaround in the V4 Canary (#3111) that rewrote `session.locale/currency/channel` inside `validateSession` before sending the mutation. That kept the backend in sync but still allowed a visible flicker, since the local store transiently held the stale value. This PR removes the workaround and addresses the root cause. ## How it works? Two coordinated changes inside `packages/core/src/sdk/session/`: 1. **`getInitialSession()`** seeds `defaultStore` with the URL-derived `locale` / `currency` / `salesChannel` at module load (instead of the default values from `discovery.config.session`). First-visit and SSR are unaffected. 2. **`installLocaleCorrector()`** registers a one-shot subscriber AFTER the `optimistic` middleware. When the persisted middleware later hydrates from IDB with a stale locale, the corrector re-enters `store.set(corrected)` synchronously. The base store's `cancelations.forEach(cancel)` flips the `cancel` flag on the just-enqueued `validateSession(stale)` handler — so it bails before reaching the network — and a fresh handler is enqueued with the corrected locale. The result: **exactly one `validateSession` call**, with the right locale, and no flicker in `useSession()`. Both helpers were extracted to `packages/core/src/sdk/session/initialSession.ts` to keep them framework-free and unit-testable. The workaround block inside `validateSession` (PR #3111) is no longer needed and was removed. ## How to test it? 1. Enable localization in a starter / local environment (e.g. via the `faststore-core-i18n-setup` skill or by setting `localization.enabled = true` in `discovery.config.js` with at least two locale bindings). 2. Open the storefront on a non-default binding (e.g. `/en-US/`) in a fresh browser tab or after clearing IDB (`fs::session`). 3. Open DevTools → Network and filter by `ValidateSession`. Expected: **a single mutation** with the URL-aligned locale. Before the fix, two were issued (one with the default/stale locale, one with the URL locale). 4. Watch the `LocalizationSelector` in the header — it should render the correct locale immediately, with no transient flicker. 5. Switch locales via the selector and confirm the value stays consistent after navigation, and that hard-reload on the new binding doesn't trigger the issue again. Automated coverage: ```bash cd packages/core pnpm vitest run test/sdk/session/getInitialSession.browser.test.ts pnpm vitest run test/sdk/session/installLocaleCorrector.browser.test.ts ``` - `getInitialSession.browser.test.ts` (6 tests) — URL-aware seeding, channel merge, fallback paths. - `installLocaleCorrector.browser.test.ts` (6 tests) — the cancellation property, one-shot behavior, unsubscribe. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Improved automatic locale and currency detection from the current URL for more accurate regional content and pricing. * Session initialization now respects URL-derived localization so users see correct locale, currency, and sales channel on load. * **Bug Fixes** * Prevents stale persisted sessions from overriding URL-aware localization; corrections apply once and preserve other session data. * **Tests** * Added browser-focused tests covering initialization, hydration correction, and edge cases (malformed session data). <!-- review_stack_entry_start --> [](https://app.coderabbit.ai/change-stack/vtex/faststore/pull/3281?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack) <!-- review_stack_entry_end --> <!-- end of auto-generated comment: release notes by coderabbit.ai --> tested in https://brandless.fast.store/ References Task https://vtex-dev.atlassian.net/jira/software/c/projects/SFS/boards/1051?selectedIssue=SFS-3145 --------- Co-authored-by: Leandro Rodrigues <[email protected]>
## What's the purpose of this pull request? Restores the `account, path, port` positional argument order on the `faststore dev` command, matching `build` (`account, path`), `serve` (`account, path, port`) and the [FastStore Platform Spec](https://github.com/vtex/faststore-platform/blob/main/docs/specification.md). The inversion was an unintended side effect of the oclif migration in #3111: `static args` went from an array to an object, and since positional order now follows key order, `path` ended up ahead of `account` — on `dev` only. `build` and `serve` were migrated in the same commit and kept the original order (introduced deliberately in #2491 to comply with the spec). The impact is on the FastStore Platform CLI, which calls the module commands positionally: ```ts // vtex/faststore-platform packages/cli/src/commands/dev.ts return dev.run([account, path, port?.toString() ?? '']) ``` With the current v4 order, the account name lands in `args.path`, so `getBasePath()` resolves the base path to a directory named after the account. `build.run([account, path])` and `serve.run([account, path, port])` are unaffected because those commands kept the correct order. ## Is this a breaking change? No known consumer depends on the current v4 order: - **Stores:** a code search for `"faststore dev"` in `package.json` across GitHub returns 50+ stores, all using `"dev": "faststore dev"` with no positional arguments. Since all three args are optional, those are unaffected. - **Programmatic callers:** searching for `loadedCli` across the `vtex` org returns only `vtex/faststore-platform`, which already uses the spec order for `dev`, `build` and `serve`. - **This monorepo:** nothing invokes `faststore dev` with positional arguments. `@faststore/core`'s `dev` script is `next dev`, and the internal spawns inside `dev.ts` target `generate-types`, `cache-graphql` and `generate-i18n` with an explicit `basePath`. - **CI/CD:** pipelines run `build` and `serve`, never `dev`. Passing a path as the single positional (`faststore dev ./store`) never worked on v3 either, since `account` has always been the first argument there. `account` remains a noop — `run()` only reads `args.path` and `args.port` — so this changes nothing beyond the positional mapping. ## How to test it? Install the version generated by the codesandbox check in a monorepo store and run `fsp dev <account>`. The dev server should start at the module path declared in `faststore.json` instead of failing to resolve a directory named after the account. For a single store, `yarn dev` (i.e. `faststore dev` with no arguments) should behave exactly as before. ## References - Spec: https://github.com/vtex/faststore-platform/blob/main/docs/specification.md - Order introduced in #2491 - Order accidentally inverted in #3111 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Documentation** * Updated the `faststore dev` command documentation to list `ACCOUNT` before `PATH`. * Revised the command usage, heading, index, and argument descriptions. * **Bug Fixes** * Corrected positional argument ordering for the `faststore dev` command: `ACCOUNT`, `PATH`, then `PORT`. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Co-authored-by: Cursor <[email protected]>
…3524) ## What's the purpose of this pull request? Since v4, the `@auth` and `@cacheControl` directives have **no effect on fields declared by a store** in its GraphQL extensions (`src/graphql/{vtex,thirdParty}/typeDefs`). The annotation compiles and shows up in the schema, but the store resolver is never wrapped: - `@auth` doesn't validate the shopper session, so the field answers any caller; - `@cacheControl` doesn't contribute to the response `cache-control` header, so the route falls back to its default rule even when the field is annotated `private`. Native FastStore fields are not affected. In v3 both directives worked on store fields, and the public guides (*Authentication in API extensions*, *Displaying an order summary for the signed-in shopper*) rely on that behavior. The regression came with the v4 schema assembly ([#3111](#3111)): `GraphqlVtexSchema` applies the directive transformers to the native schema and merges the store schema **afterwards**, so store fields are never visited by the transformers. ## How it works? **`packages/api/src/platforms/vtex/index.ts` — `GraphqlVtexSchema`** 1. Build the native executable schema with the directive definitions but **without** applying the transformers. 2. If a store schema is passed, merge it (`mergeSchemas`, unchanged). 3. Apply the transformers (`cacheControl`, then `auth`, same order as before so `@auth` runs first at request time) **once**, on the final schema. This is the v3 semantics (one transformation over native + store fields). Two wrong variants were ruled out, and the tests catch both: - transforming the store schema before the merge: it carries the native type definitions but no native resolvers, so its wrappers would override the real native resolvers; - transforming again after the merge while keeping the pre-merge transformation: native fields would be wrapped twice (`@auth` would call VTEX ID twice per field). **`packages/api/src/directives/{auth,cacheControl}.ts`** The wrappers called `originalResolver?.(...)`, so an annotated field with no explicit resolver always resolved to `undefined`. They now fall back to `defaultFieldResolver`. Native annotated fields all have resolvers (no change); this keeps store fields read from the parent object (e.g. a field of a store-owned type) working once the directives apply. **No public API change**: `GraphqlVtexSchema` keeps its signature and call sites (`@faststore/core`, CLI type generation, api local server and tests are untouched). `withDirectives` stays exported and unchanged. ###⚠️ Behavior change for stores Stores that already annotate their fields will see the annotations take effect after upgrading, as in v3 and as documented: - `@auth` fields start returning `401 UnauthorizedError` to signed-out callers; - `@cacheControl` fields start driving the `cache-control` header (still forced `private` when the auth cookie is present). This should go in the release notes. ### Authentication mechanism change — explicit human approval required Per `AGENTS.md` (Security & Data Handling) and `packages/api/AGENTS.md`, changes to authentication mechanisms require explicit human approval recorded in the PR description. - [ ] Approved by: _reviewer name / date_ ## How to test it? **Automated** — new `packages/api/test/integration/directives.test.ts` builds the final schema the same way `getFinalAPISchema` does in `@faststore/core` (native type defs + store type defs, store resolvers only, then `GraphqlVtexSchema(storeSchema)`) and checks: - store `@auth`: rejected without session (resolver not called), resolves with session; - store field with `@auth` and no resolver: returns the parent value once authorized; - store `@cacheControl`: sets the field policy; aggregates with a native field (min values, most restrictive scope); - `@auth` runs before `@cacheControl` on the same field; - native `validateUser` (with and without a store schema): keeps its resolver, rejects without session, validates the session **exactly once**. ```bash cd packages/api pnpm vitest run test/integration/directives.test.ts pnpm test ``` Results: - on the current `dev` code, the 6 store tests fail and the 4 native tests pass (bug reproduced); - with the fix, all 10 pass and the full api suite is green (362 unit, 88 integration, no snapshot changes); - the tests fail against each of the wrong variants described above. **Manual (store)** — in a store using the CodeSandbox build of this PR, add to `src/graphql/thirdParty/typeDefs`: ```graphql extend type Query { directiveProbeAuth: String @auth directiveProbeCache: String @CacheControl(scope: "private", sMaxAge: 7, staleWhileRevalidate: 11) } ``` with resolvers returning any string, run `faststore dev` and `POST /api/graphql` without cookies: | Request | Before (4.10.x) | Expected with this PR | | --- | --- | --- | | `{ directiveProbeAuth }` | `200` with the resolver value | `401 UnauthorizedError` | | `{ directiveProbeCache }` | `cache-control: no-cache, no-store` | `cache-control: private, s-maxage=7, stale-while-revalidate=11` | | `{ listCreditCards { ... } }` (native control) | `401` | `401` (unchanged) | ### Starters Deploy Preview Validated on brandless.store with the CodeSandbox build of this PR (`50f91f6a`) against 4.10.0: all results matched the expected table above. Full before/after results: #3524 (comment) ## References - Jira: SO-696 - Regression origin: [#3111](#3111) (v4 schema assembly); design introduced on `canary` in [#3063](#3063) - v3 reference: `getFinalAPISchema` in `packages/core/src/server/index.ts` applied `[cacheControlDirective, authDirective]` to the single native + store schema (last unaffected tag `v3.100.5`) --------- Co-authored-by: Cursor <[email protected]>
New canary branch with reduced v4 scope