Repository navigation
feat(magento): port newsletter/subscribe + product/stockAlert actions - #63
Merged
Merged
Conversation
Third PR in the magento-port series (after #61 scaffold + #62 utils foundation). Lands the two simplest actions — both are self-contained HTTP/GraphQL POSTs with no Granado-specific dependencies. Files (4 new, 1 modified): magento/types.ts (modified) + NewsletterData { success, message } + ProductStockAlertResponse { data?: { productStockAlert: ... } } magento/actions/newsletter/subscribe.ts (new) POSTs to /rest/:site/V1/newsletter/subscribed with the customer email and the resolved storeId. Verbatim port of the legacy 3-arg loader, but reads config from getMagentoConfig() and uses magentoFetch (so auth/origin/Referer headers come along automatically on same-origin). Returns null on success:false or non-2xx; payload otherwise — matches prod behavior. magento/actions/product/stockAlert.ts (new) Fires the ProductStockAlert GraphQL mutation against <baseUrl>/ graphql. The legacy version called ctx.clientGraphql.query with a STALE cache hint, but mutations are write-only — no cache effect. Port omits the hint; behavior is observationally identical from a consumer's perspective. Returns { data: { productStockAlert } } or { error: string }. magento/__tests__/newsletter-subscribe.test.ts (new — 6 tests) - POSTs to encoded path - Body shape { email, store_id: number } - storeId coerced to number even when CMS holds it as string - Returns payload on success - Returns null on success:false (Magento failure shape) - Returns null on non-2xx HTTP status magento/__tests__/product-stockAlert.test.ts (new — 4 tests) - POSTs to <baseUrl>/graphql with the mutation body - Returns { data: { productStockAlert } } on success - Returns { error } when GraphQL payload lacks productStockAlert - Returns { error } when fetch throws Test totals: 7 files / 59 tests passing in ~165ms. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
🎉 This PR is included in version 2.3.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
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.
Summary
Third PR in the magento-port series (after #61 scaffold + #62 utils foundation). Lands the two simplest actions — both self-contained HTTP/GraphQL POSTs with no transform/cart utils dependency.
Files
magento/types.tsNewsletterData+ProductStockAlertResponsemagento/actions/newsletter/subscribe.tsmagento/actions/product/stockAlert.tsmagento/__tests__/newsletter-subscribe.test.tsmagento/__tests__/product-stockAlert.test.tsTests
10 new tests pin: REST path with encoded site, JSON body shape, storeId coerced to number (defensive vs string-shaped CMS values), null/error responses on failure modes, GraphQL request body shape with the mutation string.
🤖 Generated with Claude Code
Summary by cubic
Ports Magento newsletter subscribe and product stock-alert actions to the Node/TanStack app, preserving legacy behavior. Routes requests through
magentoFetchand adds typed responses./rest/:site/V1/newsletter/subscribedwith{ email, store_id: Number(storeId) }; returns payload on success,nullon non-2xx orsuccess:false.ProductStockAlertto<baseUrl>/graphql; returns{ data: { productStockAlert } }or{ error }.NewsletterData,ProductStockAlertResponse.Written for commit d10e570. Summary will update on new commits.