@hszrdm/create-commerce 1.22.0 → 1.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. package/package.json +2 -2
  2. package/src/cli.mjs +7 -1
  3. package/templates/backend/package.json +1 -1
  4. package/templates/backend/scripts/commerce-ops.mjs +12 -5
  5. package/templates/backend/scripts/core-restore.mjs +20 -19
  6. package/templates/backend/scripts/lib/core-backup-common.mjs +83 -0
  7. package/templates/backend/scripts/production-assets/restore.sh +1 -1
  8. package/templates/storefront/README.md +16 -5
  9. package/templates/storefront/package-lock.json +1646 -0
  10. package/templates/storefront/package.json +5 -2
  11. package/templates/storefront/src/app/api/checkout/trusted-shop/route.ts +19 -0
  12. package/templates/storefront/src/app/checkout/success/actions.ts +17 -0
  13. package/templates/storefront/src/app/checkout/success/page.tsx +32 -22
  14. package/templates/storefront/src/components/arukereso-trusted-shop.tsx +5 -5
  15. package/templates/storefront/src/components/checkout-flow.tsx +7 -1
  16. package/templates/storefront/src/components/cms-content.tsx +3 -1
  17. package/templates/storefront/src/components/order-detail.tsx +79 -47
  18. package/templates/storefront/src/lib/core/abandoned-cart.ts +5 -1
  19. package/templates/storefront/src/lib/core/after-sales.ts +50 -13
  20. package/templates/storefront/src/lib/core/checkout-confirmation-server.ts +16 -0
  21. package/templates/storefront/src/lib/core/checkout-proof.ts +16 -0
  22. package/templates/storefront/src/lib/core/checkout.ts +5 -10
  23. package/templates/storefront/src/lib/core/sanitize-cms-html.ts +30 -0
  24. package/templates/storefront/src/lib/storefront-copy.ts +8 -0
  25. package/templates/storefront/tests/cms-html.test.mjs +49 -0
  26. package/templates/storefront/tests/ga4-bootstrap.test.mjs +1 -1
@@ -0,0 +1,49 @@
1
+ import assert from "node:assert/strict"
2
+ import { readFileSync } from "node:fs"
3
+ import test from "node:test"
4
+ import { createElement } from "react"
5
+ import { renderToStaticMarkup } from "react-dom/server"
6
+ import { sanitizeCmsHtml } from "../src/lib/core/sanitize-cms-html.ts"
7
+
8
+ test("CMS sanitizer removes executable markup and unsafe URL attributes", () => {
9
+ const html = [
10
+ '<script>console.log("script fixture")</script>',
11
+ '<img src="/safe.png" onerror="console.log(1)">',
12
+ '<p style="color:red" onclick="console.log(1)">Hello</p>',
13
+ '<a href="javascript:void(0)">link</a>',
14
+ '<a href="&#106;avascript:void(0)">encoded</a>',
15
+ '<img src="data:text/html,fixture">',
16
+ '<svg onload="console.log(1)"></svg>',
17
+ '<math><mi>sample</mi></math>',
18
+ '<iframe src="https://example.test"></iframe>',
19
+ '<p><b>Nested<p>paragraph',
20
+ ].join("")
21
+ const result = sanitizeCmsHtml(html)
22
+ assert.doesNotMatch(result, /<\/?(?:script|svg|math|iframe)\b|\son\w+=|\sstyle=|javascript:|data:text|console\.log/i)
23
+ assert.match(result, /src="\/safe\.png"/)
24
+ assert.match(result, /Nested/)
25
+ assert.match(result, /paragraph/)
26
+ })
27
+
28
+ test("SSR preserves localized formatting, links and images with the same policy", () => {
29
+ const html = '<h2>Árvíztűrő tükörfúrógép</h2><p><strong>English</strong> <em>CMS</em></p>' +
30
+ '<ol><li>One</li></ol><blockquote>Quote</blockquote>' +
31
+ '<a href="https://example.test/help" target="_blank">Link</a>' +
32
+ '<img src="/uploads/guide.png" alt="Útmutató">'
33
+ const result = renderToStaticMarkup(createElement("div", {
34
+ dangerouslySetInnerHTML: { __html: sanitizeCmsHtml(html) },
35
+ }))
36
+ assert.match(result, /<h2>Árvíztűrő tükörfúrógép<\/h2>/)
37
+ assert.match(result, /<strong>English<\/strong> <em>CMS<\/em>/)
38
+ assert.match(result, /<ol><li>One<\/li><\/ol><blockquote>Quote<\/blockquote>/)
39
+ assert.match(result, /<a href="https:\/\/example\.test\/help" rel="noopener noreferrer">Link<\/a>/)
40
+ assert.match(result, /<img src="\/uploads\/guide\.png" alt="Útmutató"/)
41
+ assert.doesNotMatch(result, /target=/)
42
+ })
43
+
44
+ test("the shared CMS component sanitizes HTML and React-escapes the text and block paths", () => {
45
+ const component = readFileSync(new URL("../src/components/cms-content.tsx", import.meta.url), "utf8")
46
+ assert.match(component, /__html: sanitizeCmsHtml\(entry\.body\)/)
47
+ assert.match(component, /<p key=\{index\}>\{paragraph\}<\/p>/)
48
+ assert.match(component, /<blockquote>\{text\}<\/blockquote>/)
49
+ })
@@ -57,7 +57,7 @@ test("payment success replays the purchase for GA4 and consent changes without c
57
57
  const checkout = readFileSync(new URL("../src/lib/core/checkout.ts", import.meta.url), "utf8")
58
58
  const tracking = readFileSync(new URL("../src/lib/core/tracking.ts", import.meta.url), "utf8")
59
59
 
60
- assert.match(success, /<GoogleAnalyticsPurchase analytics=\{config\.analytics\} order=\{order\}/)
60
+ assert.match(success, /<GoogleAnalyticsPurchase analytics=\{config\.analytics\} order=\{analyticsOrder\}/)
61
61
  assert.match(component, /trackPurchase\(analytics, order\)/)
62
62
  assert.match(component, /window\.addEventListener\(COOKIE_CONSENT_EVENT, send\)/)
63
63
  assert.match(checkout, /trackPurchase\(config\.analytics, result\.order\)/)