Skip to content

Build v5.0.0#619

Draft
acasazza wants to merge 295 commits intomainfrom
v5.0.0
Draft

Build v5.0.0#619
acasazza wants to merge 295 commits intomainfrom
v5.0.0

Conversation

@acasazza
Copy link
Copy Markdown
Member

  • Create new core package
  • Add configuration and getPrices function
  • Add getPrices tests, biomejs, and global vitest config
  • Add new documentation folder
  • Add new getAccessToken function. Resolve Create getAccessToken function #617
  • Fix vite types env

@acasazza acasazza added this to the v5.0.0 milestone Mar 27, 2025
@acasazza acasazza added the breaking-change This potentially causes other components to fail label Mar 27, 2025
@acasazza acasazza self-assigned this Mar 27, 2025
@netlify
Copy link
Copy Markdown

netlify bot commented Mar 27, 2025

Deploy Preview for commercelayer-react-components failed.

Name Link
🔨 Latest commit 50d2431
🔍 Latest deploy log https://app.netlify.com/projects/commercelayer-react-components/deploys/69d91287c31a850008b06adb

acasazza and others added 11 commits March 26, 2026 17:55
…ucer

Closes #727. Replaces useReducer + getSku manual SDK calls with the useSkus
hook from @commercelayer/hooks. SkuReducer now only exports the SkuState type.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…drop old tests

Closes #728. Updates peerDependencies to react >=19.0.0, adds
babel-plugin-react-compiler to the vitest config, and removes all legacy
specs written against the React 18 + reducer architecture. New tests will
be added incrementally per feature.
- Add specs/skus/skus-container.spec.tsx with 6 tests covering code fields,
  count, name, image_url, empty skus, and queryParams filter
- Wrap each render with SWRConfig provider for isolated cache per test
- Fix clearSkus unhandled promise rejection by chaining .catch() on mutate
- Add babel-plugin-react-compiler and SWR to react-components vitest config
- Add workspace aliases for @commercelayer/hooks and @commercelayer/core
…hooks

- Add getSkuLists/retrieveSkuList functions to @commercelayer/core
- Add getSkuAvailability function to @commercelayer/core
- Create useSkuLists hook in @commercelayer/hooks (with SWR caching)
- Create useAvailability hook in @commercelayer/hooks (with SWR caching)
- Refactor SkuListsContainer to use useSkuLists — proper registration
  pattern via registerListId callback instead of direct array mutation
- Refactor AvailabilityContainer to use useAvailability, removing
  useReducer and AvailabilityReducer dependency
- Update SkuList to call registerListId instead of mutating listIds
- Update AvailabilityTemplate to import DeliveryLeadTime from core
- Fix Skus component to use sku.id as key instead of array index
- Fix AddToCartButton to use sku.code from typed Sku[] context
- Add sku_lists* to MSW bypass handlers
- Add tests: availability-container, sku-lists-container, core specs
- Add AvailabilityContext and SkuListsContext types

Closes #730
- Add specs for CommerceLayer auth component
- Add unit tests for SkusContainer, SkuListsContainer, AvailabilityContainer, AvailabilityTemplate, DeliveryLeadTime, SkuField, Parent components
- Add unit tests for useCustomContext hook
- Migrate vitest config to vitest.config.mts (drop _vitest.config.mts prefix)
- Remove outdated e2e specs replaced by unit tests
- Fix biome.json schema version (2.3.10 → 2.4.9) and downgrade pre-existing
  lint violations to warn so lint exits 0 without touching unrelated code
- Fix multiple React/SWR instance conflict in react-components vitest config
  by adding dedupe and explicit module aliases, removing react-compiler plugin
- Fix API rate-limiting in integration tests by caching tokens per grant type
  with undefined-sentinel, adding graceful null-token guards, and running
  packages sequentially (--workspace-concurrency=1)
- Add biome-ignore comments for pre-existing violations in address components
…iners-to-hooks

✨ feat(skus): migrate SkuListsContainer and AvailabilityContainer to hooks
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 31, 2026

npm i https://pkg.pr.new/@commercelayer/react-components@619

commit: 50d2431

acasazza and others added 18 commits March 31, 2026 11:48
Merged latest v5.0.0 (including PR #731 - SKU hooks migration) into this
branch. Resolved conflicts by taking v5.0.0 versions for files that landed
via PR #731, and merging unique changes (security overrides) from both sides.
feat(core,hooks): add SKU resource and useSkus hook
…erver

- Upgrade all @storybook/* packages to ^10.3.4
- Add @storybook/addon-mcp with .mcp.json MCP server config
- Add stories/skus/001.skus.mdx with docs for all 5 SKU components
- Add stories/skus/skus.stories.tsx with 3 visual-test stories
- Add MSW mocks for /api/skus and /api/sku_lists/:id

Closes #733
…ok-v10

📚 docs(document): add SKUs story and upgrade Storybook to v10
…n-config

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
🐛 fix(HostedCart): refresh minicart URL when persistKey changes — v5 port (#740)
Replace all lodash imports with native JS/TS equivalents:
- isEmpty → local #utils/isEmpty utility
- isFunction → typeof fn === 'function'
- camelCase → String.replace with regex
- capitalize → inline helper
- compact → Array.filter(Boolean)
- differenceBy → Set-based filter
- first → arr[0]
- get → optional chaining with type cast
- has → Object.hasOwn
- isArray → Array.isArray
- isString → typeof val === 'string'
- keys → Object.keys
- last → Array.at(-1)
- map (object) → Object.entries().map
- map (array-like) → Array.from().forEach
- without → Array.filter with exclusion list

Also improve related types:
- label prop now correctly typed as string | ReactNode | (() => ReactNode)
  in SubmitButton, PlaceOrderButton, SaveAddressesButton
- infoMessage.text in PaypalPayment similarly updated

Closes #742
…add hook tests & stories

* refactor(availability): remove dead reducer, export SkuAvailability, add hook tests

- Delete AvailabilityReducer.ts (dead code, zero references)
- Re-export SkuAvailability from @commercelayer/core in public index
- Add useAvailability.test.ts with 8 test cases covering initial state,
  fetch by skuCode, clear, error handling, isLoading state, and null return

Closes #744

* fix(document): add Vite path aliases for react-components source

Storybook stories in the document package use internal helpers
(CommerceLayer, OrderStorage) that import via '#components/*' and
other path aliases defined in the react-components tsconfig. Because
those files live in the document package, vite-tsconfig-paths could
not match them to the react-components project scope and failed to
resolve the imports at pre-bundling time.

Fix by adding explicit 'resolve.alias' entries in viteFinal so all
'#components/*', '#context/*', '#hooks/*', '#typings/*', '#utils/*',
'#config/*', '#reducers/*' and '#components-utils/*' paths are
reliably resolved to the react-components source tree regardless of
which file triggers the import.

Also includes:
- Fix stories glob path (../stories → ../src/stories)
- New availability MDX docs and 9 interactive stories
- Add missing npm dependencies (@commercelayer/react-components,
  @commercelayer/js-auth, js-cookie, jwt-decode, @types/js-cookie)
The Storybook manager bundler uses esbuild with the classic JSX
transform, which requires React to be in scope. Tool.tsx used JSX
without importing React, causing 'React is not defined' at runtime.
- Fix MDX files: import from '@storybook/addon-docs/blocks' instead
  of '@storybook/addon-docs' (Meta and Source are only exported from
  the /blocks subpath in Storybook 10)
- Fix tsconfig.app.json: use '.storybook/**/*' glob instead of
  '.storybook' directory (TypeScript skips dotfolders in include)
…stsContainer params (#738)

* 📚 docs(document): add getting-started pages for core and hooks packages

* ⬆️ chore(document): upgrade storybook, update mock data and lockfile

* fix(document): await MSW worker startup and add availability mock handlers

- Replace fire-and-forget worker.start() with Storybook's beforeAll hook
  so the service worker is registered before any story renders
- Set onUnhandledRequest: 'bypass' to let auth calls (auth.commercelayer.io)
  pass through to the real network without console noise
- Add POLOMXXX000000FFFFFFLXXX to mock SKU data with inventory/delivery info
- Add GET /api/skus/:id handler so getSkuAvailability can retrieve
  individual SKU inventory (previously missing, causing silent failures)
- Filter GET /api/skus list by filter[code_in] query param

* chore(document): remove MSW mock server

- Delete mocks/ directory (browser.js, handlers.js, all data fixtures)
- Delete public/mockServiceWorker.js
- Remove msw devDependency, update-mocks script, and msw config block
- Remove worker import, beforeAll hook, and MSW imports from preview.tsx
- Stories now hit the real Commerce Layer API via useGetToken

* feat(react-components): add params prop to SkuListsContainer

Allow callers to customise the SKU fields fetched per list via an
optional params prop (QueryParamsRetrieve<SkuList>).

- include: ["skus"] is always enforced and merged with any
  caller-supplied includes
- fields.skus defaults to ["code"] when the caller omits it,
  preserving backwards-compat behaviour
- caller can pass fields: { skus: ["code", "name", "image_url"] }
  to render additional SKU attributes via SkuField
- params added to useEffect dependency array so fetches re-run
  when query params change

* fix(react-components): bridge SkuListsContext into SkuContext inside SkuList

Skus and SkuField were rendering nothing when used inside SkuList because
SkuList was only registering its ID but never populating SkuContext, which
is what the Skus component reads from.

- SkuList now reads skuLists[id] from SkuListsContext and wraps its
  children with SkuContext.Provider, bridging the fetched skus so that
  Skus and SkuField work identically to how they do under SkusContainer
- loading is true while skuLists[id] is undefined (not yet fetched)
- Update SkuListsContainer story to request name field via params so
  SkuField attribute="name" renders correctly

* refactor(react-components): remove dead SkuReducer, SkuListsReducer and getSkus util

All three files are no longer used after the hooks refactor:
- SkuListsReducer.ts — replaced by useSkuLists hook, no remaining imports
- SkuReducer.ts — only provided SkuState type to SkuContext; inlined there
- utils/getSkus.ts — SKU sorting helper, no remaining imports

SkuState is now defined inline in SkuContext.ts alongside the context it shapes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking-change This potentially causes other components to fail

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create getAccessToken function

3 participants