Conversation
Member
acasazza
commented
Mar 27, 2025
- 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
❌ Deploy Preview for commercelayer-react-components failed.
|
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
… and fix useEffect deps
…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.
…gout in My Account Closes #687
- Replace open !== isOpen check with prevOpenRef to only call setOpen when the open prop itself changes, not on unrelated effect re-runs - Fix subscription leak: store openCartHandler in a named variable so unsubscribe passes the same reference as subscribe Closes #686 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace synchronous href + onClick with useEffect that resolves org config on mount, falling back to getApplicationLink.
…-cart-v5 fix(MyAccountLink): add returnUrl prop + fix HostedCart minicart glitch
…rces - Rewrite getSdk in packages/core: uses jwtDecode for org slug, accepts optional interceptors?, applies request/response/rawReader interceptors via SDK client methods, returns CommerceLayerBundle - Add InterceptorManager type built from SDK public exports (RequestObj, ResponseObj, ErrorObj) - Export getSdk and InterceptorManager from packages/core index - Add interceptors? to RequestConfig base type so all resource functions inherit it automatically - Thread interceptors through all 9 resource functions: getSkus, retrieveSku, updateSku, getPrices, retrievePrice, updatePrice, getSkuLists, retrieveSkuList, getSkuAvailability - 🧪 Add getSdk.spec.ts with 8 unit tests (100% coverage) - 🧪 Add *.interceptors.spec.ts for every resource function - 🎯 Achieve 100% statement/branch/function/line coverage across core Closes #748 (partial - core package step)
…rage - Apply biome format/organizeImports fixes across core and hooks packages - Add clearSkuLists, retrieveSkuList error, and cache mutation tests for useSkuLists - Add map-branch and fallback-branch tests for useSkus updateSku mutate callback - Add c8 ignore to untestable defensive catch callbacks in useAvailability, useSkus, useSkuLists - Add organizeImports biome action to .vscode/settings.json
…s, remove endpoint
feat(#748): add interceptors prop to SDK hooks and CommerceLayer component
…cate PricesContainer (#752) * ♻️ refactor(sdk): remove local getSdk, migrate to @commercelayer/core - Delete utils/getSdk.ts — no longer needed - Replace all local getSdk imports with getSdk from @commercelayer/core - Remove endpoint from CommerceLayerContext usage across all components/reducers - Derive org slug/domain from JWT instead of endpoint string - Fix Price.tsx TS return type (wrap loader/pricesComponent in fragments) - Update @commercelayer/sdk to 7.9.0 to align with @commercelayer/core peer dep - Fix Storybook prices: stale hooks/core dist was root cause of missing prices fetch - Fix HostedCart: move jwt() decode inside async handlers to avoid invalid token error - Update hosted-cart.spec.tsx to use valid JWT structure *⚠️ deprecate(prices): mark PricesContainer as deprecated Will be removed in a future major release. Replacement: use <Price skuCode="MY-SKU" /> standalone, or usePrices hook for batched multi-SKU requests. * ✨ feat(prices): standalone Price with module-level batch store Replace PricesContainer-required pattern with a provider-free batching architecture so <Price> works standalone and auto-batches SKU requests. - Add pricesBatchStore.ts: module-level Map keyed by accessToken; collects SKU codes via registerSku/unregisterSku with 50 ms debounce; notifies useSyncExternalStore listeners on each flush; cleans up store entry when last subscriber unmounts - Rewrite usePrices: subscribe to batch store via useSyncExternalStore; auto-call fetchPrices when snapshot changes; expose registerSku/unregisterSku wrappers; SWR deduplicates identical param calls to one HTTP request - Add 'DOM' to hooks/tsconfig.json lib (required for setTimeout types) - Update Price.tsx: detect standalone mode (setSkuCodes == null); call usePrices directly with real token; filter batchPrices by sku_code - Add pricesBatchStore.test.ts (11 tests, 100 % coverage) - Add/extend usePrices.test.ts (20 tests, 100 % coverage) - Rewrite price.spec.tsx: mock @commercelayer/hooks to avoid React 19 act() deadlock from useSyncExternalStore + SWR; 5 tests cover all branches including filter callback and accessToken ?? '' fallback * 📖 docs(prices): add standalone Price story without PricesContainer Add StandalonePrice story showing 3 <Price> components used directly without a PricesContainer parent. All three auto-batch into a single API request via the module-level debounce store in usePrices. * 🐛 fix(prices): replace object literals with JSX fragments in Price render { loader } and { pricesComponent } were JS object expressions, not JSX. React 19 correctly throws when an object is returned as a child. Replace with <>{loader}</> and <>{pricesComponent}</> fragments. * ♻️ refactor(prices): return ReactNode from Price, drop unnecessary fragments - Change Price return type JSX.Element → ReactNode (React 19 idiomatic) - Return loader and pricesComponent directly without <></> wrappers - Fix price.spec.tsx: use ReturnType<typeof usePrices> instead of unexported UsePricesReturn interface * 📝 docs(prices): update stories with standalone Price + deprecate PricesContainer - Add StandalonePrice story showing 3 <Price> components without container - Update 001.prices.mdx: standalone pattern first, deprecation notices - Add loader prop to props table - Add migration hints from PricesContainer to standalone <Price> * 📝 docs(containers): deprecate container pattern, promote standalone components - Add deprecation notice for PricesContainer and container pattern in general - Show before/after code examples (old container vs new standalone) - Fix typos: 'To amultiple', 'documentend' - Keep Hierarchy section intact
* 🔧 chore(ci): update GitHub Actions to latest versions Closes #753 - gh-pages.yaml: pnpm/action-setup @V3→@v4 (8→10), setup-node @V3→@v5 (latest→20.x) - pgk-pr-new.yaml: pnpm/action-setup @V3→@v4 (9.x→10), setup-node @v4→@v5 - release.yaml: softprops/action-gh-release @v1→@v2 * 🔧 chore(ci): set Node.js 20 for Netlify builds Netlify defaults to Node 18 which is too old for Storybook (requires 20.19+ or 22.12+) * 🔧 chore(ci): temporarily disable gh-pages auto deploy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.