@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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hszrdm/create-commerce",
3
- "version": "1.22.0",
3
+ "version": "1.24.0",
4
4
  "description": "Create a complete HSZRDM Commerce webshop project.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",
@@ -16,7 +16,7 @@
16
16
  "scripts": {
17
17
  "prepare:templates": "node ./scripts/prepare-templates.mjs",
18
18
  "prepack": "npm run prepare:templates",
19
- "test": "npm run prepare:templates && node --test"
19
+ "test": "npm run prepare:templates && node --test \"test/**/*.test.mjs\""
20
20
  },
21
21
  "engines": {
22
22
  "node": ">=22"
package/src/cli.mjs CHANGED
@@ -67,7 +67,13 @@ export async function main(argv = process.argv.slice(2)) {
67
67
 
68
68
  mkdirSync(destination, { recursive: true })
69
69
  cpSync(templates.backend, join(destination, "backend"), { recursive: true, dereference: false })
70
- cpSync(templates.storefront, join(destination, "storefront"), { recursive: true, dereference: false })
70
+ const standaloneLock = join(templates.storefront, "package-lock.json")
71
+ cpSync(templates.storefront, join(destination, "storefront"), {
72
+ recursive: true,
73
+ dereference: false,
74
+ // The generated storefront uses the customer's root workspace lockfile.
75
+ filter: (source) => source !== standaloneLock,
76
+ })
71
77
 
72
78
  configureProject(destination, settings)
73
79
  configureDocker(destination, settings)
@@ -23,7 +23,7 @@
23
23
  "start:prod": "cd .medusa/server && medusa start"
24
24
  },
25
25
  "dependencies": {
26
- "@hszrdm/core": "1.22.0",
26
+ "@hszrdm/core": "1.24.0",
27
27
  "@medusajs/admin-sdk": "2.22.2",
28
28
  "@medusajs/cli": "2.22.2",
29
29
  "@medusajs/draft-order": "2.22.2",
@@ -58,7 +58,8 @@ const pm2Names = target === "staging"
58
58
  ? `${shopName}-staging-backend,${shopName}-staging-storefront`
59
59
  : `${shopName}-backend,${shopName}-storefront`
60
60
 
61
- console.log(`HSZRDM ${action}:${target} | DB: ${new URL(envFile.DATABASE_URL).pathname.slice(1)}`)
61
+ const operation = `HSZRDM ${action}:${target}`
62
+ console.log(action === "restore" ? operation : `${operation} | DB: ${new URL(envFile.DATABASE_URL).pathname.slice(1)}`)
62
63
 
63
64
  function run(command, args) {
64
65
  const result = spawnSync(command, args, { cwd: root, env, stdio: "inherit" })
@@ -93,9 +94,15 @@ function parseEnv(src) {
93
94
  return result
94
95
  }
95
96
  function databaseIdentity(value) {
96
- const u = new URL(value)
97
- if (!["postgres:", "postgresql:"].includes(u.protocol)) throw new Error("DATABASE_URL must be PostgreSQL.")
98
- return `${u.hostname.toLowerCase()}:${u.port || "5432"}/${decodeURIComponent(u.pathname)}`
97
+ try {
98
+ const u = new URL(value)
99
+ if (["postgres:", "postgresql:"].includes(u.protocol)) {
100
+ return `${u.hostname.toLowerCase()}:${u.port || "5432"}/${decodeURIComponent(u.pathname)}`
101
+ }
102
+ } catch {
103
+ // Invalid URL errors can include credentials from the environment file.
104
+ }
105
+ throw new Error("A valid PostgreSQL DATABASE_URL is required.")
99
106
  }
100
107
  function devServer() {
101
108
  const children = []
@@ -124,7 +131,7 @@ if (action === "restore") {
124
131
  ? databaseFlag.slice("--confirm-database=".length)
125
132
  : databaseIndex >= 0 ? rest[databaseIndex + 1] : ""
126
133
  run(process.execPath, [restoreScript(), "--project-dir", root,
127
- "--database-url", envFile.DATABASE_URL, "--from", resolve(from),
134
+ "--from", resolve(from),
128
135
  ...(rest.includes("--yes") ? ["--yes"] : []),
129
136
  ...(databaseConfirmation ? ["--confirm-database", databaseConfirmation] : []),
130
137
  ...(rest.includes("--overwrite-files") ? ["--overwrite-files"] : []),
@@ -16,8 +16,8 @@ import {
16
16
  glsPrivateLabelDirectory,
17
17
  integrationSnapshotPath,
18
18
  loadRuntimeEnv,
19
- pgEnvironment,
20
19
  requireEncryptionKeyWhenNeeded,
20
+ resolveRestoreTarget,
21
21
  verifyManifest,
22
22
  } from "./lib/core-backup-common.mjs"
23
23
 
@@ -47,26 +47,25 @@ console.log("✅ Backup integritása rendben.")
47
47
 
48
48
  const env = loadRuntimeEnv(projectDir)
49
49
  requireEncryptionKeyWhenNeeded(manifest, env)
50
- const databaseUrl = String(args["database-url"] || env.DATABASE_URL || "").trim()
51
- const pg = pgEnvironment(databaseUrl, env)
50
+ const target = resolveRestoreTarget(args["database-url"] ?? env.DATABASE_URL, env)
52
51
 
53
- console.log(`- cél adatbázis: ${pg.database}`)
52
+ console.log(`- cél adatbázis: ${target.identity}`)
54
53
  console.log("- Integration Settings encryption key: jelen van (érték nincs kiírva)")
55
54
 
56
- if (!args.yes) {
55
+ if (args.yes !== true) {
57
56
  console.log("\nDRY RUN: adatbázist és fájlt nem módosítottam.")
58
- console.log("A tényleges, destruktív restore-hoz --yes ÉS --confirm-database=<cél DB> szükséges.")
57
+ console.log(`A destruktív restore jóváhagyása: --yes --confirm-database=${target.identity}`)
59
58
  process.exit(0)
60
59
  }
61
60
  // --yes on its own is not enough: require the operator to independently name
62
- // the target database. Never allow restoring into PostgreSQL system databases.
63
- if (["postgres", "template0", "template1"].includes(pg.database.toLowerCase()) ||
64
- String(args["confirm-database"] || "").trim() !== pg.database) {
61
+ // the full endpoint. Never allow restoring into PostgreSQL system databases.
62
+ if (["postgres", "template0", "template1"].includes(target.database.toLowerCase()) ||
63
+ args["confirm-database"] !== target.identity) {
65
64
  throw new Error(
66
- "Destruktív restore megtagadva. Add meg a pontos céladatbázist: --confirm-database=" + pg.database,
65
+ "Destruktív restore megtagadva. Ellenőrizd a céladatbázist (host:port/adatbázis), és erősítsd meg a --confirm-database kapcsolóval.",
67
66
  )
68
67
  }
69
- const restoreEnv = { ...env, DATABASE_URL: databaseUrl }
68
+ const restoreEnv = target.env
70
69
  assertRestoreTargets({ projectDir, bundleDir, env: restoreEnv, overwrite: Boolean(args["overwrite-files"]) })
71
70
 
72
71
  const dumpPath = join(bundleDir, "database.dump")
@@ -80,10 +79,11 @@ run(
80
79
  "--single-transaction",
81
80
  "--no-owner",
82
81
  "--no-acl",
83
- `--dbname=${pg.database}`,
82
+ "--no-password",
83
+ `--dbname=${target.database}`,
84
84
  dumpPath,
85
85
  ],
86
- pg.env,
86
+ restoreEnv,
87
87
  )
88
88
 
89
89
  const restoredCoreDir = join(projectDir, ".core")
@@ -100,7 +100,7 @@ restoreFiles({ projectDir, bundleDir, env: restoreEnv, overwrite: Boolean(args["
100
100
 
101
101
  if (args.migrate) {
102
102
  console.log("- Core migrációk futtatása...")
103
- runNpm(projectDir, ["run", "db:migrate"], env)
103
+ runNpm(projectDir, ["run", "db:migrate"], restoreEnv)
104
104
  }
105
105
 
106
106
  console.log("\n✅ Restore kész.")
@@ -186,12 +186,13 @@ function copyWithGuard(source, target, overwrite) {
186
186
  }
187
187
 
188
188
  function run(command, commandArgs, commandEnv, cwd) {
189
- const result = spawnSync(command, commandArgs, { env: commandEnv, cwd, stdio: "inherit" })
189
+ // Client errors may include secrets from connection settings or dump SQL.
190
+ const result = spawnSync(command, commandArgs, { env: commandEnv, cwd, stdio: "ignore" })
190
191
  if (result.error?.code === "ENOENT") {
191
- throw new Error(`${command} nem található. Telepítsd a PostgreSQL klienseszközöket.`)
192
+ throw new Error(`${command} nem található a PATH-ban.`)
192
193
  }
193
- if (result.error) throw result.error
194
- if (result.status !== 0) throw new Error(`${command} hibával leállt (${result.status}).`)
194
+ if (result.error) throw new Error(`${command} indítása sikertelen (${result.error.code}).`)
195
+ if (result.status !== 0) throw new Error(`${command} hibával leállt (${result.status ?? result.signal}).`)
195
196
  }
196
197
 
197
198
  function runNpm(cwd, commandArgs, commandEnv) {
@@ -225,5 +226,5 @@ function parseArgs(tokens) {
225
226
  }
226
227
 
227
228
  function printHelp() {
228
- console.log(`MEDUSA WEBSHOP CORE restore\n\nEllenőrzés / dry run:\n npm run core:restore -- --from backups/<bundle>\n\nTényleges restore:\n npm run core:restore -- --from backups/<bundle> --yes --confirm-database=<cél DB> [--overwrite-files] [--migrate]\n\nA restore destruktív PostgreSQL --clean műveletet használ, ezért --yes nélkül soha nem módosít adatot.\n`)
229
+ console.log(`MEDUSA WEBSHOP CORE restore\n\nEllenőrzés / dry run:\n npm run core:restore -- --from backups/<bundle>\n\nTényleges restore:\n npm run core:restore -- --from backups/<bundle> --yes --confirm-database=<host:port/adatbázis> [--overwrite-files] [--migrate]\n\nA cél URL-t a --database-url kapcsoló, ennek hiányában a DATABASE_URL adja meg. A jelszót tartalmazó URL-t környezeti változóként vagy a backend env fájljában add meg, mert az npm naplózhatja a parancssori argumentumokat. A restore destruktív PostgreSQL --clean műveletet használ.\n`)
229
230
  }
@@ -8,6 +8,7 @@ import {
8
8
  readdirSync,
9
9
  } from "node:fs"
10
10
  import { dirname, isAbsolute, join, resolve, sep } from "node:path"
11
+ import { userInfo } from "node:os"
11
12
 
12
13
  export const PORTABLE_ENV_KEYS = [
13
14
  "MEDUSA_BACKEND_URL",
@@ -135,6 +136,88 @@ export function pgEnvironment(databaseUrl, base = process.env) {
135
136
  }
136
137
  }
137
138
 
139
+ const RESTORE_PG_OPTIONS = new Map([
140
+ ["sslmode", "PGSSLMODE"],
141
+ ["sslcert", "PGSSLCERT"],
142
+ ["sslkey", "PGSSLKEY"],
143
+ ["sslrootcert", "PGSSLROOTCERT"],
144
+ ["application_name", "PGAPPNAME"],
145
+ ["options", "PGOPTIONS"],
146
+ ])
147
+
148
+ /** Resolve one TCP endpoint both libpq and Medusa's PostgreSQL driver can use. */
149
+ export function resolveRestoreTarget(databaseUrl, base) {
150
+ const value = required(databaseUrl, "DATABASE_URL")
151
+ const invalid = () => new Error("Érvénytelen vagy nem támogatott restore DATABASE_URL.")
152
+ if (/[\x00-\x20\x7f]/.test(value) ||
153
+ !/^postgres(?:ql)?:\/\/[^/?#]+\/[^/?#]+(?:\?[^#]*)?$/i.test(value)) {
154
+ throw invalid()
155
+ }
156
+
157
+ let url, database, encodedDatabase
158
+ try {
159
+ url = new URL(value)
160
+ database = decodeURIComponent(url.pathname.slice(1))
161
+ encodedDatabase = encodeURIComponent(database).replace(/[!'()*]/g, char =>
162
+ `%${char.charCodeAt(0).toString(16).toUpperCase()}`)
163
+ // node-postgres uses decodeURI for the path. Reject names the two
164
+ // clients would decode differently or libpq could treat as conninfo.
165
+ if (database !== decodeURI(encodedDatabase) || /[\x00-\x1f\x7f=]/.test(database)) {
166
+ throw invalid()
167
+ }
168
+ const user = decodeURIComponent(url.username) || userInfo().username
169
+ const password = decodeURIComponent(url.password)
170
+ if (/\0/.test(user + password)) throw invalid()
171
+ decodeURIComponent(url.search) // URLSearchParams alone tolerates malformed percent escapes.
172
+ url.username = encodeURIComponent(user)
173
+ url.password = encodeURIComponent(password)
174
+ } catch {
175
+ // URL and percent-decoding errors can include connection credentials.
176
+ throw invalid()
177
+ }
178
+
179
+ const host = url.hostname.toLowerCase()
180
+ const port = Number(url.port || 5432)
181
+ if (!database || !/^(?:[a-z0-9_][a-z0-9_.-]*|\[[a-f0-9:.]+\])$/.test(host) ||
182
+ port < 1 || port > 65535) {
183
+ throw invalid()
184
+ }
185
+
186
+ const options = new Map()
187
+ for (const [key, option] of url.searchParams) {
188
+ if (!RESTORE_PG_OPTIONS.has(key) || !option || options.has(key) || /[\x00-\x1f\x7f]/.test(option)) {
189
+ throw invalid()
190
+ }
191
+ options.set(key, option)
192
+ }
193
+ // Use the Core Medusa default when the operator hasn't specified a mode.
194
+ const sslMode = options.get("sslmode") || "disable"
195
+ if (!["disable", "prefer", "require", "verify-ca", "verify-full"].includes(sslMode)) throw invalid()
196
+ options.set("sslmode", sslMode)
197
+ for (const key of ["sslcert", "sslkey", "sslrootcert"]) {
198
+ if (options.has(key) && (sslMode === "disable" || !isAbsolute(options.get(key)))) throw invalid()
199
+ }
200
+
201
+ url.hostname = host
202
+ url.port = String(port)
203
+ url.pathname = `/${encodedDatabase}`
204
+ url.search = new URLSearchParams(options).toString()
205
+
206
+ // libpq can use PGHOSTADDR instead of PGHOST, or take defaults from a
207
+ // service file. Build the complete child environment from the selected URL.
208
+ const env = Object.fromEntries(Object.entries(base).filter(([key]) => !/^PG/i.test(key)))
209
+ env.DATABASE_URL = url.href
210
+ const pg = pgEnvironment(url.href, env)
211
+ pg.env.PGHOST = host.replace(/^\[|\]$/g, "")
212
+ for (const [key, variable] of RESTORE_PG_OPTIONS) {
213
+ pg.env[variable] = options.get(key) || ""
214
+ }
215
+ // Keep Medusa's dotenv load from reintroducing a different password file.
216
+ pg.env.PGPASSFILE = ""
217
+
218
+ return { database, identity: `${host}:${port}${url.pathname}`, env: pg.env }
219
+ }
220
+
138
221
  export function integrationSnapshotPath(projectDir, env) {
139
222
  const backendDir = backendProjectDir(projectDir)
140
223
  const configured = String(env.INTEGRATION_SETTINGS_FILE || "").trim()
@@ -11,7 +11,7 @@ cd "$ROOT"
11
11
  }
12
12
  FROM="${1:-}"
13
13
  [[ -n "$FROM" ]] || {
14
- echo "Usage: bash deploy/restore.sh <bundle-directory> --yes --confirm-database=<database> [--overwrite-files]" >&2
14
+ echo "Usage: bash deploy/restore.sh <bundle-directory> --yes --confirm-database=<host:port/database> [--overwrite-files] [--migrate]" >&2
15
15
  exit 2
16
16
  }
17
17
  [[ -d "$FROM" ]] || {
@@ -2,13 +2,17 @@
2
2
 
3
3
  Újrahasznosítható, teljes referencia-storefront a MEDUSA WEBSHOP CORE backendhez.
4
4
 
5
- A starter külön alkalmazás: nincs a backend root npm workspace-ben, így a Medusa deploy és lockfile nem kap Next.js/Stripe frontend függőségeket. Új webshopnál a `@hszrdm/create-commerce` generátor a teljes frontendrészt a külön ügyfélprojektbe másolja; ezután elsődlegesen a design/branding réteget kell cserélni, a `src/lib/core` integrációs contractokat és a kész commerce flow komponenseket érdemes megtartani.
5
+ A Core forrásrepójában a referencia-storefront külön npm-projekt, így a
6
+ backend lockfile-ja nem kap Next.js/Stripe frontendfüggőségeket. Új webshopban
7
+ a `@hszrdm/create-commerce` a storefrontot a webshop workspace-eként hozza létre.
8
+ A design és branding az ügyfélprojektben testre szabható a `src/lib/core`
9
+ integrációs contractok és a commerce flow komponensek megtartásával.
6
10
 
7
11
  ## Indítás
8
12
 
9
13
  ```bash
10
14
  cp .env.example .env.local
11
- npm install
15
+ npm ci
12
16
  npm run dev
13
17
  ```
14
18
 
@@ -125,19 +129,26 @@ A Packeta official widget ügyfél-designban a checkout `packeta.pickupPoint` ad
125
129
 
126
130
  ## Build és parity ellenőrzés
127
131
 
128
- A starter önálló app, ezért külön futtasd:
132
+ A referencia starter önálló app és saját lockfile-t használ. A generált
133
+ webshopban az `npm ci`-t a webshop gyökeréből futtasd, a gyökér-lockfile-ból.
134
+ A referenciánál az alábbi parancsokat a starter könyvtárában futtasd:
129
135
 
130
136
  ```bash
131
- npm install
137
+ npm ci
132
138
  npm run typecheck
133
139
  npm run build
140
+ npm ls next react react-dom
134
141
  ```
135
142
 
136
143
  A Core repo gyökerében a `npm run storefront:verify` statikus regressziós teszttel ellenőrzi, hogy a kötelező customer-facing Core capability-k tényleges UI/route bekötése megmaradjon. A `npm run core:verify` ezt is futtatja.
137
144
 
138
145
  ## Generator
139
146
 
140
- A `@hszrdm/create-commerce` template preparation a teljes `starters/storefront-next` könyvtárat másolja. Nincs külön, könnyen eldriftelő storefront template, ezért az itt működő referencia-flow-k az újonnan generált webshopba automatikusan bekerülnek.
147
+ A `@hszrdm/create-commerce` az itteni referenciából készíti a storefrontot.
148
+ A webshop közös npm lockfile-ja a generálás utáni gyökértelepítéskor jön
149
+ létre. Meglévő webshopnál a `frontend:sync` jelzi a függőségeltérést.
150
+ A biztonsági javításhoz ellenőrizd a shop Next.js-verzióját, frissítsd a
151
+ storefront dependencyjét és a gyökér-lockfile-t, majd futtass új buildet.
141
152
 
142
153
  ## Részletes funkcióleírások
143
154