Skip to content

feat(magento): port newsletter/subscribe + product/stockAlert actions - #63

Merged
JonasJesus42 merged 1 commit into
mainfrom
JonasJesus42/magento-simple-actions
Jun 2, 2026
Merged

JonasJesus42 merged 1 commit into
mainfrom
JonasJesus42/magento-simple-actions

Conversation

@JonasJesus42

@JonasJesus42 JonasJesus42 commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

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

File Notes
magento/types.ts + NewsletterData + ProductStockAlertResponse
magento/actions/newsletter/subscribe.ts POST /rest/:site/V1/newsletter/subscribed
magento/actions/product/stockAlert.ts GraphQL ProductStockAlert mutation
magento/__tests__/newsletter-subscribe.test.ts 6 tests
magento/__tests__/product-stockAlert.test.ts 4 tests

Tests

 Test Files  7 passed (7)
      Tests  59 passed (59)

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 magentoFetch and adds typed responses.

  • New Features
    • Newsletter subscribe: POST /rest/:site/V1/newsletter/subscribed with { email, store_id: Number(storeId) }; returns payload on success, null on non-2xx or success:false.
    • Product stock alert: GraphQL mutation ProductStockAlert to <baseUrl>/graphql; returns { data: { productStockAlert } } or { error }.
    • Types: NewsletterData, ProductStockAlertResponse.

Written for commit d10e570. Summary will update on new commits.

Review in cubic

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]>
@JonasJesus42
JonasJesus42 requested a review from a team June 2, 2026 21:43
@JonasJesus42
JonasJesus42 merged commit 40edeff into main Jun 2, 2026
1 of 2 checks passed
@github-actions

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 2.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant