@hszrdm/create-commerce 1.4.0 → 1.5.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 (25) hide show
  1. package/package.json +1 -1
  2. package/templates/backend/.env.example +13 -0
  3. package/templates/backend/README.md +4 -0
  4. package/templates/backend/package.json +3 -1
  5. package/templates/backend/scripts/core-backup.mjs +281 -0
  6. package/templates/backend/scripts/core-restore.mjs +179 -0
  7. package/templates/backend/scripts/lib/core-backup-common.mjs +237 -0
  8. package/templates/backend/scripts/production-assets/deploy.sh +2 -1
  9. package/templates/backend/scripts/production-assets/install.sh +2 -1
  10. package/templates/backend/scripts/production-assets/restore.sh +4 -1
  11. package/templates/backend/src/scripts/core-init.ts +3 -1
  12. package/templates/storefront/src/app/cart-recovery/page.tsx +35 -0
  13. package/templates/storefront/src/app/ertekeles/page.tsx +25 -0
  14. package/templates/storefront/src/app/fiok-aktivalas/page.tsx +35 -0
  15. package/templates/storefront/src/components/abandoned-cart-recovery.tsx +139 -0
  16. package/templates/storefront/src/components/account-activation-form.tsx +333 -0
  17. package/templates/storefront/src/components/add-to-cart.tsx +56 -0
  18. package/templates/storefront/src/components/analytics.tsx +15 -2
  19. package/templates/storefront/src/components/review-request-form.tsx +419 -0
  20. package/templates/storefront/src/lib/core/abandoned-cart.ts +47 -0
  21. package/templates/storefront/src/lib/core/account-activation.ts +75 -0
  22. package/templates/storefront/src/lib/core/back-in-stock.ts +25 -0
  23. package/templates/storefront/src/lib/core/reviews.ts +37 -5
  24. package/templates/storefront/src/lib/storefront-routes.ts +3 -0
  25. package/templates/storefront/src/proxy.ts +4 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hszrdm/create-commerce",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "description": "Create a complete HSZRDM Commerce webshop project.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",
@@ -297,6 +297,7 @@ PACKETA_TIMEOUT_MS=15000
297
297
  PACKETA_DEFAULT_WEIGHT_KG=1
298
298
  PACKETA_LABEL_FORMAT=A6 on A6
299
299
  PACKETA_LANGUAGE=hu
300
+ PACKETA_WEBHOOK_SIGNING_KEY=
300
301
 
301
302
  DPD_ENABLED=false
302
303
  DPD_SANDBOX=true
@@ -321,11 +322,20 @@ DPD_DEFAULT_WEIGHT_KG=1
321
322
  DPD_LABEL_SIZE=A6
322
323
  DPD_PRINT_FORMAT=PDF
323
324
  DPD_LABEL_DPI=203
325
+ DPD_STATUSDATA_ENABLED=false
326
+ DPD_STATUSDATA_FTP_HOST=
327
+ DPD_STATUSDATA_FTP_PORT=21
328
+ DPD_STATUSDATA_FTP_USERNAME=
329
+ DPD_STATUSDATA_FTP_PASSWORD=
330
+ DPD_STATUSDATA_FTP_DIR=
331
+ DPD_STATUSDATA_FTP_TIMEOUT_MS=15000
324
332
 
325
333
  MPL_ENABLED=false
326
334
  MPL_SANDBOX=true
327
335
  MPL_API_URL=
328
336
  MPL_TRACKING_API_URL=
337
+ MPL_PUSH_TRACKING_API_URL=
338
+ MPL_PUSH_TRACKING_STREAM_URL=https://net.posta.hu/tracking/public/tracking/TrackingData
329
339
  MPL_TOKEN_URL=
330
340
  MPL_API_KEY=
331
341
  MPL_API_SECRET=
@@ -351,6 +361,9 @@ MPL_DEFAULT_WEIGHT_KG=1
351
361
  MPL_LABEL_TYPE=A6
352
362
  MPL_PACKAGE_RETENTION=5
353
363
  MPL_TRACKING_ENABLED=false
364
+ MPL_PUSH_TRACKING_ENABLED=false
365
+ MPL_TRACKING_ACCOUNT_CODE=
366
+ MPL_PUSH_READ_WINDOW_MS=8000
354
367
  MPL_TRACKING_LANGUAGE=hu
355
368
 
356
369
  # -----------------------------------------------------------------------------
@@ -2,6 +2,10 @@
2
2
 
3
3
  Minimal Medusa v2 host application for `@hszrdm/core`.
4
4
 
5
+ This directory is the canonical backend skeleton used by `@hszrdm/create-commerce`. New shops are generated from this starter and receive the exact current `@hszrdm/core` package version during template preparation.
6
+
5
7
  Shared commerce functionality comes from `@hszrdm/core`. Webshop-specific backend code belongs in `src/project/` only. `medusa-config.ts` deliberately stays thin and delegates shared configuration to `createHszrdmCommerceConfig()`.
6
8
 
9
+ The repository reference host in `apps/backend` intentionally has additional development/test tooling, but the shared host contract must stay identical for `instrumentation.ts`, `medusa-config.ts`, `src/project/**` and `src/scripts/**`. Run `npm run backend:parity` from the repository root to verify this contract.
10
+
7
11
  Generated projects should create `.env` from `.env.example`, install dependencies, run `npm run db:migrate`, then `npm run core:init -- --yes`.
@@ -12,6 +12,8 @@
12
12
  "start": "medusa start",
13
13
  "typecheck": "npm run env:verify && npm run prepare:project && tsc --noEmit",
14
14
  "core:init": "npm run prepare:project && medusa exec ./src/scripts/core-init.ts",
15
+ "core:backup": "node ./scripts/core-backup.mjs --project-dir .",
16
+ "core:restore": "node ./scripts/core-restore.mjs --project-dir .",
15
17
  "storefront:key": "npm run prepare:project && medusa exec ./src/scripts/create-storefront-key.ts",
16
18
  "bootstrap:assert": "npm run prepare:project && medusa exec ./src/scripts/verify-bootstrap.ts",
17
19
  "db:migrate": "npm run prepare:project && medusa db:migrate",
@@ -19,7 +21,7 @@
19
21
  "start:prod": "cd .medusa/server && medusa start"
20
22
  },
21
23
  "dependencies": {
22
- "@hszrdm/core": "1.4.0",
24
+ "@hszrdm/core": "1.5.0",
23
25
  "@medusajs/admin-sdk": "2.21.2",
24
26
  "@medusajs/cli": "2.21.2",
25
27
  "@medusajs/draft-order": "2.21.2",
@@ -0,0 +1,281 @@
1
+ #!/usr/bin/env node
2
+
3
+ import {
4
+ existsSync,
5
+ mkdirSync,
6
+ readFileSync,
7
+ readdirSync,
8
+ renameSync,
9
+ statSync,
10
+ writeFileSync,
11
+ } from "node:fs"
12
+ import { dirname, isAbsolute, join, resolve } from "node:path"
13
+ import { spawnSync } from "node:child_process"
14
+ import process from "node:process"
15
+
16
+ import {
17
+ CORE_DB_MODULES,
18
+ backendProjectDir,
19
+ backupFileSources,
20
+ backupTimestamp,
21
+ copyBackupSource,
22
+ loadRuntimeEnv,
23
+ pgEnvironment,
24
+ portableConfig,
25
+ portableEnvText,
26
+ sha256File,
27
+ sha256Tree,
28
+ } from "./lib/core-backup-common.mjs"
29
+
30
+ const args = parseArgs(process.argv.slice(2))
31
+ if (args.help) {
32
+ printHelp()
33
+ process.exit(0)
34
+ }
35
+
36
+ const projectDir = resolve(args["project-dir"] || process.cwd())
37
+ const env = loadRuntimeEnv(projectDir)
38
+ const databaseUrl = String(args["database-url"] || env.DATABASE_URL || "").trim()
39
+ const outputRoot = resolvePath(
40
+ projectDir,
41
+ args.output || env.CORE_BACKUP_DIR || "backups",
42
+ )
43
+ const stateDir = resolvePath(
44
+ projectDir,
45
+ env.CORE_RUNTIME_STATE_DIR || ".core",
46
+ )
47
+ const statusPath = resolvePath(
48
+ projectDir,
49
+ args["status-file"] || env.CORE_BACKUP_STATUS_FILE || join(stateDir, "backup-status.json"),
50
+ )
51
+ const storeSlug = safePart(env.STORE_SLUG || "webshop")
52
+ const bundleName = String(args.name || `${storeSlug}-${backupTimestamp()}`).trim()
53
+ const bundleDir = join(outputRoot, bundleName)
54
+ const startedAt = new Date().toISOString()
55
+
56
+ writeBackupStatus({
57
+ schema_version: 1,
58
+ status: "running",
59
+ started_at: startedAt,
60
+ finished_at: null,
61
+ bundle_name: bundleName,
62
+ bundle_dir: bundleDir,
63
+ created_at: null,
64
+ size_bytes: null,
65
+ database_dump: false,
66
+ manifest_path: null,
67
+ error: null,
68
+ })
69
+
70
+ try {
71
+ runBackup()
72
+ } catch (error) {
73
+ const message = error instanceof Error ? error.message : String(error)
74
+ writeBackupStatus({
75
+ schema_version: 1,
76
+ status: "failed",
77
+ started_at: startedAt,
78
+ finished_at: new Date().toISOString(),
79
+ bundle_name: bundleName,
80
+ bundle_dir: bundleDir,
81
+ created_at: null,
82
+ size_bytes: existsSync(bundleDir) ? directorySize(bundleDir) : null,
83
+ database_dump: existsSync(join(bundleDir, "database.dump")),
84
+ manifest_path: existsSync(join(bundleDir, "manifest.json"))
85
+ ? join(bundleDir, "manifest.json")
86
+ : null,
87
+ error: message,
88
+ })
89
+ console.error(`\n❌ Backup sikertelen: ${message}`)
90
+ process.exitCode = 1
91
+ }
92
+
93
+ function runBackup() {
94
+ if (existsSync(bundleDir)) {
95
+ throw new Error(`A backup cél már létezik: ${bundleDir}`)
96
+ }
97
+ mkdirSync(bundleDir, { recursive: true, mode: 0o700 })
98
+
99
+ const pg = pgEnvironment(databaseUrl, env)
100
+ const dumpPath = join(bundleDir, "database.dump")
101
+ console.log(`\nMEDUSA WEBSHOP CORE backup: ${bundleName}`)
102
+ console.log("- PostgreSQL custom dump készítése...")
103
+ run("pg_dump", ["--format=custom", "--no-owner", "--no-acl", `--file=${dumpPath}`], pg.env)
104
+
105
+ const portable = portableConfig(env)
106
+ const portableJsonPath = join(bundleDir, "portable-config.json")
107
+ const portableEnvPath = join(bundleDir, "portable-config.env")
108
+ writeFileSync(
109
+ portableJsonPath,
110
+ `${JSON.stringify({ schema_version: 1, values: portable }, null, 2)}\n`,
111
+ { encoding: "utf8", mode: 0o600 },
112
+ )
113
+ writeFileSync(portableEnvPath, portableEnvText(portable), { encoding: "utf8", mode: 0o600 })
114
+
115
+ const bootstrapSource = join(backendProjectDir(projectDir), ".core", "webshop-bootstrap.json")
116
+ if (existsSync(bootstrapSource)) {
117
+ writeFileSync(
118
+ join(bundleDir, "webshop-bootstrap.json"),
119
+ readFileSync(bootstrapSource),
120
+ { mode: 0o600 },
121
+ )
122
+ }
123
+
124
+ const copiedFiles = []
125
+ for (const item of backupFileSources(projectDir, env)) {
126
+ console.log(`- ${item.key} mentése...`)
127
+ const target = copyBackupSource(bundleDir, item)
128
+ copiedFiles.push({ ...item, target })
129
+ }
130
+
131
+ const artifacts = [
132
+ artifact(bundleDir, "database.dump", "file"),
133
+ artifact(bundleDir, "portable-config.json", "file"),
134
+ artifact(bundleDir, "portable-config.env", "file"),
135
+ ]
136
+ if (existsSync(join(bundleDir, "webshop-bootstrap.json"))) {
137
+ artifacts.push(artifact(bundleDir, "webshop-bootstrap.json", "file"))
138
+ }
139
+ for (const item of copiedFiles) {
140
+ artifacts.push(
141
+ artifact(
142
+ bundleDir,
143
+ item.relative,
144
+ statSync(item.target).isDirectory() ? "directory" : "file",
145
+ item.key,
146
+ ),
147
+ )
148
+ }
149
+
150
+ const packageJson = JSON.parse(readFileSync(join(projectDir, "package.json"), "utf8"))
151
+ const createdAt = new Date().toISOString()
152
+ const manifest = {
153
+ schema_version: 1,
154
+ created_at: createdAt,
155
+ store_slug: env.STORE_SLUG || null,
156
+ store_name: env.STORE_NAME || null,
157
+ database_name: pg.database,
158
+ core_release: env.RELEASE_SHA || process.env.RELEASE_SHA || "unknown",
159
+ package_version: packageJson.version || null,
160
+ node_version: process.version,
161
+ database_format: "postgres-custom",
162
+ core_database_modules: CORE_DB_MODULES,
163
+ portable_config: "portable-config.json",
164
+ requires_integration_encryption_key: true,
165
+ encryption_key_included: false,
166
+ secret_plaintext_exported: false,
167
+ artifacts,
168
+ restore_notes: [
169
+ "Az eredeti INTEGRATION_SETTINGS_ENCRYPTION_KEY külön secret store-ból szükséges.",
170
+ "A cél PostgreSQL adatbázist a restore előtt létre kell hozni.",
171
+ "Ajánlott ugyanarra a Core release-re visszaállítani, majd migrációval frissíteni.",
172
+ ],
173
+ }
174
+ const manifestPath = join(bundleDir, "manifest.json")
175
+ writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`, {
176
+ encoding: "utf8",
177
+ mode: 0o600,
178
+ })
179
+
180
+ const sizeBytes = directorySize(bundleDir)
181
+ writeBackupStatus({
182
+ schema_version: 1,
183
+ status: "success",
184
+ started_at: startedAt,
185
+ finished_at: new Date().toISOString(),
186
+ bundle_name: bundleName,
187
+ bundle_dir: bundleDir,
188
+ created_at: createdAt,
189
+ size_bytes: sizeBytes,
190
+ database_dump: existsSync(dumpPath),
191
+ manifest_path: manifestPath,
192
+ error: null,
193
+ })
194
+
195
+ console.log("\n✅ Backup kész.")
196
+ console.log(`- bundle: ${bundleDir}`)
197
+ console.log(`- DB: ${pg.database}`)
198
+ console.log(`- artifactok: ${artifacts.length}`)
199
+ console.log(`- méret: ${sizeBytes} byte`)
200
+ console.log("- plaintext provider secret: NEM exportálva")
201
+ console.log("- encryption key: NINCS a backupban")
202
+ }
203
+
204
+ function artifact(root, relative, kind, role) {
205
+ const path = join(root, relative)
206
+ return {
207
+ path: relative,
208
+ kind,
209
+ ...(role ? { role } : {}),
210
+ sha256: kind === "directory" ? sha256Tree(path) : sha256File(path),
211
+ }
212
+ }
213
+
214
+ function run(command, commandArgs, commandEnv) {
215
+ const result = spawnSync(command, commandArgs, {
216
+ env: commandEnv,
217
+ stdio: "inherit",
218
+ })
219
+ if (result.error?.code === "ENOENT") {
220
+ throw new Error(`${command} nem található. Telepítsd a PostgreSQL klienseszközöket.`)
221
+ }
222
+ if (result.error) throw result.error
223
+ if (result.status !== 0) throw new Error(`${command} hibával leállt (${result.status}).`)
224
+ }
225
+
226
+ function writeBackupStatus(payload) {
227
+ mkdirSync(dirname(statusPath), { recursive: true, mode: 0o700 })
228
+ const temp = `${statusPath}.${process.pid}.tmp`
229
+ writeFileSync(temp, `${JSON.stringify(payload, null, 2)}\n`, {
230
+ encoding: "utf8",
231
+ mode: 0o600,
232
+ })
233
+ renameSync(temp, statusPath)
234
+ }
235
+
236
+ function directorySize(path) {
237
+ if (!existsSync(path)) return 0
238
+ const stat = statSync(path)
239
+ if (stat.isFile()) return stat.size
240
+ if (!stat.isDirectory()) return 0
241
+ return readdirSync(path).reduce(
242
+ (sum, entry) => sum + directorySize(join(path, entry)),
243
+ 0,
244
+ )
245
+ }
246
+
247
+ function resolvePath(root, value) {
248
+ const raw = String(value || "").trim()
249
+ return isAbsolute(raw) ? raw : resolve(root, raw)
250
+ }
251
+
252
+ function safePart(value) {
253
+ return String(value || "webshop")
254
+ .toLowerCase()
255
+ .replace(/[^a-z0-9_-]+/g, "-")
256
+ .replace(/^-+|-+$/g, "") || "webshop"
257
+ }
258
+
259
+ function parseArgs(tokens) {
260
+ const result = {}
261
+ for (let index = 0; index < tokens.length; index++) {
262
+ const raw = tokens[index]
263
+ if (!raw.startsWith("--")) continue
264
+ const token = raw.slice(2)
265
+ const eq = token.indexOf("=")
266
+ if (eq >= 0) {
267
+ result[token.slice(0, eq)] = token.slice(eq + 1)
268
+ continue
269
+ }
270
+ const next = tokens[index + 1]
271
+ if (next && !next.startsWith("--")) {
272
+ result[token] = next
273
+ index++
274
+ } else result[token] = true
275
+ }
276
+ return result
277
+ }
278
+
279
+ function printHelp() {
280
+ console.log(`MEDUSA WEBSHOP CORE backup\n\nHasználat:\n npm run core:backup -- [--output backups] [--name nightly] [--database-url ...] [--status-file .core/backup-status.json]\n\nA backup állapotát a Rendszerfelügyelet számára státuszfájlba írja. Plaintext provider secretet vagy encryption key-t továbbra sem exportál.\n`)
281
+ }
@@ -0,0 +1,179 @@
1
+ #!/usr/bin/env node
2
+
3
+ import {
4
+ cpSync,
5
+ existsSync,
6
+ mkdirSync,
7
+ readFileSync,
8
+ writeFileSync,
9
+ } from "node:fs"
10
+ import { dirname, isAbsolute, join, resolve } from "node:path"
11
+ import { spawnSync } from "node:child_process"
12
+ import process from "node:process"
13
+
14
+ import {
15
+ backendProjectDir,
16
+ integrationSnapshotPath,
17
+ loadRuntimeEnv,
18
+ pgEnvironment,
19
+ requireEncryptionKeyWhenNeeded,
20
+ verifyManifest,
21
+ } from "./lib/core-backup-common.mjs"
22
+
23
+ const args = parseArgs(process.argv.slice(2))
24
+ if (args.help) {
25
+ printHelp()
26
+ process.exit(0)
27
+ }
28
+
29
+ const projectDir = resolve(args["project-dir"] || process.cwd())
30
+ const bundleDir = resolve(required(args.from, "--from"))
31
+ const manifestPath = join(bundleDir, "manifest.json")
32
+ if (!existsSync(manifestPath)) throw new Error(`manifest.json nem található: ${bundleDir}`)
33
+
34
+ const manifest = JSON.parse(readFileSync(manifestPath, "utf8"))
35
+ if (manifest.schema_version !== 1) {
36
+ throw new Error(`Nem támogatott backup schema: ${manifest.schema_version}`)
37
+ }
38
+
39
+ console.log(`\nMEDUSA WEBSHOP CORE restore ellenőrzés`)
40
+ console.log(`- backup: ${bundleDir}`)
41
+ console.log(`- létrehozva: ${manifest.created_at || "ismeretlen"}`)
42
+ console.log(`- Core release: ${manifest.core_release || "ismeretlen"}`)
43
+ console.log("- checksumok ellenőrzése...")
44
+ verifyManifest(bundleDir, manifest)
45
+ console.log("✅ Backup integritása rendben.")
46
+
47
+ const env = loadRuntimeEnv(projectDir)
48
+ requireEncryptionKeyWhenNeeded(manifest, env)
49
+ const databaseUrl = String(args["database-url"] || env.DATABASE_URL || "").trim()
50
+ const pg = pgEnvironment(databaseUrl, env)
51
+
52
+ console.log(`- cél adatbázis: ${pg.database}`)
53
+ console.log("- Integration Settings encryption key: jelen van (érték nincs kiírva)")
54
+
55
+ if (!args.yes) {
56
+ console.log("\nDRY RUN: adatbázist és fájlt nem módosítottam.")
57
+ console.log("A tényleges, destruktív restore-hoz futtasd újra --yes kapcsolóval.")
58
+ process.exit(0)
59
+ }
60
+
61
+ const dumpPath = join(bundleDir, "database.dump")
62
+ console.log("\n- PostgreSQL visszaállítása (--clean --if-exists)...")
63
+ run(
64
+ "pg_restore",
65
+ [
66
+ "--clean",
67
+ "--if-exists",
68
+ "--no-owner",
69
+ "--no-acl",
70
+ `--dbname=${pg.database}`,
71
+ dumpPath,
72
+ ],
73
+ pg.env,
74
+ )
75
+
76
+ const restoredCoreDir = join(projectDir, ".core")
77
+ mkdirSync(restoredCoreDir, { recursive: true, mode: 0o700 })
78
+ const portableSource = join(bundleDir, "portable-config.env")
79
+ if (existsSync(portableSource)) {
80
+ const target = join(restoredCoreDir, "restored-portable.env")
81
+ writeFileSync(target, readFileSync(portableSource), { mode: 0o600 })
82
+ console.log(`- portable config kiírva: ${target}`)
83
+ console.log(" (szándékosan nincs automatikusan bemásolva a production .env-be)")
84
+ }
85
+
86
+ restoreFiles({ projectDir, bundleDir, env, overwrite: Boolean(args["overwrite-files"]) })
87
+
88
+ if (args.migrate) {
89
+ console.log("- Core migrációk futtatása...")
90
+ runNpm(projectDir, ["run", "db:migrate"], env)
91
+ }
92
+
93
+ console.log("\n✅ Restore kész.")
94
+ console.log("Következő lépések:")
95
+ console.log("1. Ellenőrizd/merge-eld a .core/restored-portable.env értékeket a cél .env-be.")
96
+ console.log("2. Ellenőrizd, hogy az eredeti INTEGRATION_SETTINGS_ENCRYPTION_KEY van használatban.")
97
+ console.log("3. Indítsd a backendet, majd futtasd a Production readiness ellenőrzést.")
98
+ console.log("4. Futtasd az E2E/smoke tesztet egy staging restore-on production indítás előtt.")
99
+
100
+ function restoreFiles({ projectDir, bundleDir, env, overwrite }) {
101
+ const snapshotSource = join(bundleDir, "files", "integration-settings.enc")
102
+ if (existsSync(snapshotSource)) {
103
+ const target = integrationSnapshotPath(projectDir, env)
104
+ copyWithGuard(snapshotSource, target, overwrite)
105
+ console.log(`- Integration Settings runtime snapshot visszaállítva: ${target}`)
106
+ }
107
+
108
+ const localStaticSource = join(bundleDir, "files", "local-static")
109
+ if (existsSync(localStaticSource)) {
110
+ const target = join(backendProjectDir(projectDir), "static")
111
+ copyWithGuard(localStaticSource, target, overwrite)
112
+ console.log(`- lokális file storage visszaállítva: ${target}`)
113
+ }
114
+
115
+ const uploadSource = join(bundleDir, "files", "file-upload-dir")
116
+ if (existsSync(uploadSource)) {
117
+ const configured = String(env.FILE_UPLOAD_DIR || "").trim()
118
+ if (!configured || !isAbsolute(configured)) {
119
+ throw new Error(
120
+ "A backup külön FILE_UPLOAD_DIR tartalmat is tartalmaz. Állíts be abszolút FILE_UPLOAD_DIR értéket a cél környezetben, majd futtasd újra a restore-t.",
121
+ )
122
+ }
123
+ copyWithGuard(uploadSource, configured, overwrite)
124
+ console.log(`- FILE_UPLOAD_DIR visszaállítva: ${configured}`)
125
+ }
126
+ }
127
+
128
+ function copyWithGuard(source, target, overwrite) {
129
+ if (existsSync(target) && !overwrite) {
130
+ throw new Error(
131
+ `A restore célfájl/könyvtár már létezik: ${target}. Tudatos felülíráshoz add meg a --overwrite-files kapcsolót.`,
132
+ )
133
+ }
134
+ mkdirSync(dirname(target), { recursive: true })
135
+ cpSync(source, target, { recursive: true, force: overwrite, errorOnExist: !overwrite })
136
+ }
137
+
138
+ function run(command, commandArgs, commandEnv) {
139
+ const result = spawnSync(command, commandArgs, { env: commandEnv, stdio: "inherit" })
140
+ if (result.error?.code === "ENOENT") {
141
+ throw new Error(`${command} nem található. Telepítsd a PostgreSQL klienseszközöket.`)
142
+ }
143
+ if (result.error) throw result.error
144
+ if (result.status !== 0) throw new Error(`${command} hibával leállt (${result.status}).`)
145
+ }
146
+
147
+ function runNpm(cwd, commandArgs, commandEnv) {
148
+ run(process.platform === "win32" ? "npm.cmd" : "npm", commandArgs, commandEnv)
149
+ }
150
+
151
+ function required(value, flag) {
152
+ const text = String(value || "").trim()
153
+ if (!text) throw new Error(`${flag} kötelező.`)
154
+ return text
155
+ }
156
+
157
+ function parseArgs(tokens) {
158
+ const result = {}
159
+ for (let index = 0; index < tokens.length; index++) {
160
+ const raw = tokens[index]
161
+ if (!raw.startsWith("--")) continue
162
+ const token = raw.slice(2)
163
+ const eq = token.indexOf("=")
164
+ if (eq >= 0) {
165
+ result[token.slice(0, eq)] = raw.slice(raw.indexOf("=") + 1)
166
+ continue
167
+ }
168
+ const next = tokens[index + 1]
169
+ if (next && !next.startsWith("--")) {
170
+ result[token] = next
171
+ index++
172
+ } else result[token] = true
173
+ }
174
+ return result
175
+ }
176
+
177
+ function printHelp() {
178
+ 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 --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`)
179
+ }