@hszrdm/create-commerce 1.3.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 (30) hide show
  1. package/README.md +92 -1
  2. package/package.json +1 -1
  3. package/templates/backend/.env.example +271 -91
  4. package/templates/backend/README.md +4 -0
  5. package/templates/backend/package.json +6 -2
  6. package/templates/backend/scripts/core-backup.mjs +281 -0
  7. package/templates/backend/scripts/core-restore.mjs +179 -0
  8. package/templates/backend/scripts/lib/core-backup-common.mjs +237 -0
  9. package/templates/backend/scripts/materialize-production.mjs +37 -0
  10. package/templates/backend/scripts/production-assets/backup.sh +56 -0
  11. package/templates/backend/scripts/production-assets/deploy.sh +68 -0
  12. package/templates/backend/scripts/production-assets/ecosystem.config.cjs.tpl +24 -0
  13. package/templates/backend/scripts/production-assets/install.sh +201 -0
  14. package/templates/backend/scripts/production-assets/restore.sh +71 -0
  15. package/templates/backend/scripts/verify-env-contract.mjs +58 -0
  16. package/templates/backend/src/scripts/core-init.ts +3 -1
  17. package/templates/storefront/src/app/cart-recovery/page.tsx +35 -0
  18. package/templates/storefront/src/app/ertekeles/page.tsx +25 -0
  19. package/templates/storefront/src/app/fiok-aktivalas/page.tsx +35 -0
  20. package/templates/storefront/src/components/abandoned-cart-recovery.tsx +139 -0
  21. package/templates/storefront/src/components/account-activation-form.tsx +333 -0
  22. package/templates/storefront/src/components/add-to-cart.tsx +56 -0
  23. package/templates/storefront/src/components/analytics.tsx +15 -2
  24. package/templates/storefront/src/components/review-request-form.tsx +419 -0
  25. package/templates/storefront/src/lib/core/abandoned-cart.ts +47 -0
  26. package/templates/storefront/src/lib/core/account-activation.ts +75 -0
  27. package/templates/storefront/src/lib/core/back-in-stock.ts +25 -0
  28. package/templates/storefront/src/lib/core/reviews.ts +37 -5
  29. package/templates/storefront/src/lib/storefront-routes.ts +3 -0
  30. package/templates/storefront/src/proxy.ts +4 -0
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { chmodSync, copyFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs"
4
+ import { dirname, join, resolve } from "node:path"
5
+ import { fileURLToPath } from "node:url"
6
+
7
+ const backendRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..")
8
+ const root = resolve(backendRoot, "..")
9
+ const metadataPath = join(root, "hszrdm-commerce.json")
10
+ const assetsDir = join(backendRoot, "scripts", "production-assets")
11
+
12
+ // The starter itself may be installed in the Core monorepo. Only materialize
13
+ // production assets inside an actual generated client project.
14
+ if (!existsSync(metadataPath)) process.exit(0)
15
+
16
+ const metadata = JSON.parse(readFileSync(metadataPath, "utf8"))
17
+ const slug = String(metadata?.project?.slug || "hszrdm-commerce").trim() || "hszrdm-commerce"
18
+ const deployDir = join(root, "deploy")
19
+ mkdirSync(deployDir, { recursive: true })
20
+
21
+ for (const name of ["install.sh", "deploy.sh", "backup.sh", "restore.sh"]) {
22
+ const source = join(assetsDir, name)
23
+ const target = join(deployDir, name)
24
+ if (!existsSync(source)) throw new Error(`Missing production asset: ${source}`)
25
+ if (!existsSync(target)) copyFileSync(source, target)
26
+ try { chmodSync(target, 0o755) } catch {}
27
+ }
28
+
29
+ const ecosystemSource = join(assetsDir, "ecosystem.config.cjs.tpl")
30
+ const ecosystemTarget = join(root, "ecosystem.config.cjs")
31
+ if (!existsSync(ecosystemSource)) throw new Error(`Missing production asset: ${ecosystemSource}`)
32
+ if (!existsSync(ecosystemTarget)) {
33
+ const source = readFileSync(ecosystemSource, "utf8")
34
+ writeFileSync(ecosystemTarget, source.replaceAll("__HSZRDM_SLUG__", slug), "utf8")
35
+ }
36
+
37
+ console.log("✅ Production deploy assets are available in deploy/ and ecosystem.config.cjs")
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env bash
2
+ set -Eeuo pipefail
3
+
4
+ ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
5
+ cd "$ROOT"
6
+
7
+ log() { printf '\n==> %s\n' "$*"; }
8
+ fail() { printf '\nERROR: %s\n' "$*" >&2; exit 1; }
9
+ need() { command -v "$1" >/dev/null 2>&1 || fail "Missing required command: $1"; }
10
+ env_value() {
11
+ local file="$1" key="$2"
12
+ sed -n "s/^${key}=//p" "$file" | head -n 1
13
+ }
14
+
15
+ need pg_dump
16
+ need tar
17
+
18
+ [[ -f backend/.env ]] || fail "backend/.env is missing"
19
+ DATABASE_URL="$(env_value backend/.env DATABASE_URL)"
20
+ [[ -n "$DATABASE_URL" ]] || fail "DATABASE_URL is missing from backend/.env"
21
+
22
+ STAMP="$(date -u +%Y%m%dT%H%M%SZ)"
23
+ BACKUP_DIR="${HSZRDM_BACKUP_DIR:-$ROOT/backups}"
24
+ RETENTION="${HSZRDM_BACKUP_RETENTION:-5}"
25
+ mkdir -p "$BACKUP_DIR"
26
+ chmod 700 "$BACKUP_DIR" || true
27
+ TMP="$(mktemp -d)"
28
+ trap 'rm -rf "$TMP"' EXIT
29
+ mkdir -p "$TMP/config" "$TMP/runtime"
30
+
31
+ log "Database backup"
32
+ pg_dump --format=custom --no-owner --file "$TMP/database.dump" "$DATABASE_URL"
33
+
34
+ cp backend/.env "$TMP/config/backend.env"
35
+ [[ -f storefront/.env.local ]] && cp storefront/.env.local "$TMP/config/storefront.env.local"
36
+ [[ -f .env.docker ]] && cp .env.docker "$TMP/config/env.docker"
37
+ [[ -f hszrdm-commerce.json ]] && cp hszrdm-commerce.json "$TMP/config/hszrdm-commerce.json"
38
+ [[ -d backend/.core ]] && cp -R backend/.core "$TMP/runtime/core"
39
+
40
+ FILE_UPLOAD_DIR="$(env_value backend/.env FILE_UPLOAD_DIR)"
41
+ if [[ -n "$FILE_UPLOAD_DIR" && -d "$FILE_UPLOAD_DIR" ]]; then
42
+ cp -R "$FILE_UPLOAD_DIR" "$TMP/runtime/uploads"
43
+ elif [[ -d backend/uploads ]]; then
44
+ cp -R backend/uploads "$TMP/runtime/uploads"
45
+ fi
46
+
47
+ ARCHIVE="$BACKUP_DIR/hszrdm-commerce-$STAMP.tar.gz"
48
+ tar -C "$TMP" -czf "$ARCHIVE" .
49
+ chmod 600 "$ARCHIVE" || true
50
+
51
+ if [[ "$RETENTION" =~ ^[0-9]+$ ]] && (( RETENTION > 0 )); then
52
+ ls -1t "$BACKUP_DIR"/hszrdm-commerce-*.tar.gz 2>/dev/null | tail -n +$((RETENTION + 1)) | xargs -r rm -f
53
+ fi
54
+
55
+ log "Backup created: $ARCHIVE"
56
+ printf 'WARNING: this archive contains production secrets and customer data. Store it securely.\n'
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/env bash
2
+ set -Eeuo pipefail
3
+
4
+ ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
5
+ cd "$ROOT"
6
+
7
+ log() { printf '\n==> %s\n' "$*"; }
8
+ fail() { printf '\nERROR: %s\n' "$*" >&2; exit 1; }
9
+ need() { command -v "$1" >/dev/null 2>&1 || fail "Missing required command: $1"; }
10
+ pm2_run() {
11
+ if command -v pm2 >/dev/null 2>&1; then
12
+ pm2 "$@"
13
+ else
14
+ npx --yes pm2@6.0.13 "$@"
15
+ fi
16
+ }
17
+ env_value() {
18
+ local file="$1" key="$2"
19
+ sed -n "s/^${key}=//p" "$file" | head -n 1
20
+ }
21
+
22
+ log "HSZRDM Commerce deploy"
23
+ need git
24
+ need npm
25
+ need curl
26
+
27
+ [[ -f backend/.env ]] || fail "backend/.env is missing"
28
+ [[ -f storefront/.env.local ]] || fail "storefront/.env.local is missing"
29
+
30
+ if [[ -n "$(git status --porcelain --untracked-files=no)" ]]; then
31
+ fail "Tracked production files contain local changes. Commit/revert them before deploy."
32
+ fi
33
+
34
+ log "Backup before deploy"
35
+ bash deploy/backup.sh
36
+
37
+ OLD_SHA="$(git rev-parse HEAD)"
38
+ log "Pull latest code (fast-forward only)"
39
+ git pull --ff-only
40
+ NEW_SHA="$(git rev-parse HEAD)"
41
+ printf 'Deploying %s -> %s\n' "$OLD_SHA" "$NEW_SHA"
42
+
43
+ log "Clean dependency tree and install exact dependencies"
44
+ rm -rf node_modules
45
+ npm ci
46
+ npm --workspace backend run env:verify
47
+
48
+ log "Run database migrations"
49
+ npm run db:migrate
50
+ npm run core:init -- --yes
51
+
52
+ log "Build"
53
+ npm run build
54
+
55
+ log "Reload PM2"
56
+ pm2_run startOrReload ecosystem.config.cjs --env production
57
+ pm2_run save
58
+
59
+ BACKEND_URL="$(env_value backend/.env MEDUSA_BACKEND_URL)"
60
+ STOREFRONT_URL="$(env_value backend/.env STOREFRONT_URL)"
61
+ if [[ -n "$BACKEND_URL" ]]; then
62
+ curl --fail --silent --show-error --max-time 15 "${BACKEND_URL%/}/health" >/dev/null || fail "Backend healthcheck failed after deploy"
63
+ fi
64
+ if [[ -n "$STOREFRONT_URL" ]]; then
65
+ curl --fail --silent --show-error --max-time 15 "$STOREFRONT_URL" >/dev/null || fail "Storefront healthcheck failed after deploy"
66
+ fi
67
+
68
+ log "Deploy completed"
@@ -0,0 +1,24 @@
1
+ module.exports = {
2
+ apps: [
3
+ {
4
+ name: "__HSZRDM_SLUG__-backend",
5
+ cwd: __dirname,
6
+ script: "npm",
7
+ args: "--workspace backend run start:prod",
8
+ env: { NODE_ENV: "production" },
9
+ autorestart: true,
10
+ max_restarts: 10,
11
+ restart_delay: 2000,
12
+ },
13
+ {
14
+ name: "__HSZRDM_SLUG__-storefront",
15
+ cwd: __dirname,
16
+ script: "npm",
17
+ args: "--workspace storefront run start -- --hostname 127.0.0.1 --port 3000",
18
+ env: { NODE_ENV: "production" },
19
+ autorestart: true,
20
+ max_restarts: 10,
21
+ restart_delay: 2000,
22
+ },
23
+ ],
24
+ }
@@ -0,0 +1,201 @@
1
+ #!/usr/bin/env bash
2
+ set -Eeuo pipefail
3
+
4
+ ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
5
+ cd "$ROOT"
6
+
7
+ log() { printf '\n==> %s\n' "$*"; }
8
+ fail() { printf '\nERROR: %s\n' "$*" >&2; exit 1; }
9
+ need() { command -v "$1" >/dev/null 2>&1 || fail "Missing required command: $1"; }
10
+ pm2_run() {
11
+ if command -v pm2 >/dev/null 2>&1; then
12
+ pm2 "$@"
13
+ else
14
+ npx --yes pm2@6.0.13 "$@"
15
+ fi
16
+ }
17
+ env_value() {
18
+ local file="$1" key="$2"
19
+ sed -n "s/^${key}=//p" "$file" | head -n 1
20
+ }
21
+ set_env() {
22
+ local file="$1" key="$2" value="$3"
23
+ node - "$file" "$key" "$value" <<'NODE'
24
+ const fs = require("node:fs")
25
+ const [file, key, value] = process.argv.slice(2)
26
+ let source = fs.readFileSync(file, "utf8")
27
+ const escaped = key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
28
+ const pattern = new RegExp(`^${escaped}=.*$`, "m")
29
+ if (!pattern.test(source)) {
30
+ console.error(`Missing environment key in template: ${key}`)
31
+ process.exit(1)
32
+ }
33
+ source = source.replace(pattern, `${key}=${value}`)
34
+ fs.writeFileSync(file, source, { mode: 0o600 })
35
+ NODE
36
+ }
37
+ secret() {
38
+ node -e 'process.stdout.write(require("node:crypto").randomBytes(48).toString("base64url"))'
39
+ }
40
+ metadata_value() {
41
+ local expression="$1"
42
+ node - "$ROOT/hszrdm-commerce.json" "$expression" <<'NODE'
43
+ const fs = require("node:fs")
44
+ const [file, expression] = process.argv.slice(2)
45
+ const data = JSON.parse(fs.readFileSync(file, "utf8"))
46
+ const value = expression.split(".").reduce((current, key) => current?.[key], data)
47
+ process.stdout.write(value == null ? "" : String(value))
48
+ NODE
49
+ }
50
+ ask() {
51
+ local prompt="$1" default_value="$2" env_override="$3"
52
+ local override="${!env_override:-}"
53
+ if [[ -n "$override" ]]; then
54
+ printf '%s' "$override"
55
+ return
56
+ fi
57
+ if [[ ! -t 0 ]]; then
58
+ [[ -n "$default_value" ]] || fail "$env_override is required in non-interactive mode"
59
+ printf '%s' "$default_value"
60
+ return
61
+ fi
62
+ local answer
63
+ if [[ -n "$default_value" ]]; then
64
+ read -r -p "$prompt [$default_value]: " answer
65
+ printf '%s' "${answer:-$default_value}"
66
+ else
67
+ read -r -p "$prompt: " answer
68
+ [[ -n "$answer" ]] || fail "$prompt is required"
69
+ printf '%s' "$answer"
70
+ fi
71
+ }
72
+
73
+ bootstrap_env() {
74
+ [[ -f backend/.env.example ]] || fail "backend/.env.example is missing"
75
+ [[ -f storefront/.env.example ]] || fail "storefront/.env.example is missing"
76
+ [[ -f hszrdm-commerce.json ]] || fail "hszrdm-commerce.json is missing"
77
+
78
+ if [[ -f backend/.env ]]; then
79
+ log "Existing backend/.env found; preserving production secrets"
80
+ else
81
+ log "Create production backend/.env from canonical template"
82
+ cp backend/.env.example backend/.env
83
+ chmod 600 backend/.env
84
+
85
+ local slug store_name locale country currency metadata_backend metadata_storefront
86
+ slug="$(metadata_value project.slug)"
87
+ store_name="$(metadata_value project.store_name)"
88
+ locale="$(metadata_value locale)"
89
+ country="$(metadata_value country)"
90
+ currency="$(metadata_value currency)"
91
+ metadata_backend="$(metadata_value urls.backend)"
92
+ metadata_storefront="$(metadata_value urls.storefront)"
93
+
94
+ local database_url redis_url backend_url storefront_url email_domain upload_dir
95
+ database_url="$(ask "PostgreSQL DATABASE_URL" "" HSZRDM_INSTALL_DATABASE_URL)"
96
+ redis_url="$(ask "Redis REDIS_URL" "" HSZRDM_INSTALL_REDIS_URL)"
97
+ backend_url="$(ask "Public backend URL" "$metadata_backend" HSZRDM_INSTALL_BACKEND_URL)"
98
+ storefront_url="$(ask "Public storefront URL" "$metadata_storefront" HSZRDM_INSTALL_STOREFRONT_URL)"
99
+ upload_dir="${HSZRDM_INSTALL_UPLOAD_DIR:-/var/lib/hszrdm-commerce/${slug:-store}/uploads}"
100
+ email_domain="$(node -e 'try { process.stdout.write(new URL(process.argv[1]).hostname.replace(/^www\./, "")) } catch {}' "$storefront_url")"
101
+ [[ -n "$email_domain" ]] || email_domain="example.com"
102
+
103
+ set_env backend/.env DATABASE_URL "$database_url"
104
+ set_env backend/.env REDIS_URL "$redis_url"
105
+ set_env backend/.env MEDUSA_BACKEND_URL "$backend_url"
106
+ set_env backend/.env STOREFRONT_URL "$storefront_url"
107
+ set_env backend/.env FILE_UPLOAD_DIR "$upload_dir"
108
+ set_env backend/.env JWT_SECRET "$(secret)"
109
+ set_env backend/.env COOKIE_SECRET "$(secret)"
110
+ set_env backend/.env INTEGRATION_SETTINGS_ENCRYPTION_KEY "$(secret)"
111
+ set_env backend/.env SHIPPING_WEBHOOK_SECRET "$(secret)"
112
+ set_env backend/.env STORE_CORS "$storefront_url"
113
+ set_env backend/.env ADMIN_CORS "$backend_url"
114
+ set_env backend/.env AUTH_CORS "$storefront_url,$backend_url"
115
+ set_env backend/.env STORE_NAME "$store_name"
116
+ set_env backend/.env STORE_SLUG "$slug"
117
+ set_env backend/.env STORE_LOCALE "$locale"
118
+ set_env backend/.env STORE_DEFAULT_CURRENCY "$currency"
119
+ set_env backend/.env STORE_DEFAULT_COUNTRY "$country"
120
+ set_env backend/.env VITE_ADMIN_BRAND_NAME "$store_name – HSZRDM Commerce"
121
+ set_env backend/.env PLUGIN_ADMIN_BRAND_NAME "$store_name – HSZRDM Commerce"
122
+ set_env backend/.env ORDER_EMAIL "orders@$email_domain"
123
+ set_env backend/.env SUPPORT_EMAIL "support@$email_domain"
124
+ set_env backend/.env BILLING_EMAIL "billing@$email_domain"
125
+ set_env backend/.env SYSTEM_EMAIL "system@$email_domain"
126
+ set_env backend/.env SEO_STOREFRONT_URL "$storefront_url"
127
+ set_env backend/.env SEO_STORE_NAME "$store_name"
128
+ set_env backend/.env SEO_ORGANIZATION_NAME "$store_name"
129
+ set_env backend/.env SEO_ALLOW_INDEXING "true"
130
+
131
+ if mkdir -p "$upload_dir" 2>/dev/null; then
132
+ chmod 750 "$upload_dir" 2>/dev/null || true
133
+ else
134
+ log "WARNING: could not create FILE_UPLOAD_DIR=$upload_dir; create it before uploads are used"
135
+ fi
136
+ fi
137
+
138
+ if [[ -f storefront/.env.local ]]; then
139
+ log "Existing storefront/.env.local found; preserving it"
140
+ else
141
+ log "Create storefront/.env.local"
142
+ cp storefront/.env.example storefront/.env.local
143
+ chmod 600 storefront/.env.local
144
+ local backend_url
145
+ backend_url="$(env_value backend/.env MEDUSA_BACKEND_URL)"
146
+ set_env storefront/.env.local MEDUSA_BACKEND_URL "$backend_url"
147
+ set_env storefront/.env.local NEXT_PUBLIC_MEDUSA_BACKEND_URL "$backend_url"
148
+ fi
149
+ }
150
+
151
+ log "HSZRDM Commerce production install"
152
+ need node
153
+ need npm
154
+ need git
155
+ need curl
156
+
157
+ bootstrap_env
158
+
159
+ log "Clean dependency tree and install exact dependencies"
160
+ rm -rf node_modules
161
+ npm ci
162
+
163
+ log "Verify environment schema"
164
+ npm --workspace backend run env:verify
165
+
166
+ log "Run database migrations"
167
+ npm run db:migrate
168
+
169
+ log "Ensure Core bootstrap state"
170
+ npm run core:init -- --yes
171
+
172
+ # If this is a truly fresh server, create a Store API publishable key after the
173
+ # database/bootstrap exists. Existing storefront keys are never overwritten.
174
+ if [[ -z "$(env_value storefront/.env.local NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY)" ]]; then
175
+ log "Create storefront publishable API key"
176
+ KEY_OUTPUT="$(npm run storefront:key -- --title "$(metadata_value project.store_name) Storefront")"
177
+ PUBLISHABLE_KEY="$(printf '%s\n' "$KEY_OUTPUT" | sed -n 's/^HSZRDM_PUBLISHABLE_KEY=//p' | tail -n 1)"
178
+ [[ -n "$PUBLISHABLE_KEY" ]] || fail "Could not create storefront publishable API key"
179
+ set_env storefront/.env.local NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY "$PUBLISHABLE_KEY"
180
+ fi
181
+
182
+ log "Build backend and storefront"
183
+ npm run build
184
+
185
+ log "Start/reload PM2 applications"
186
+ pm2_run startOrReload ecosystem.config.cjs --env production
187
+ pm2_run save
188
+
189
+ BACKEND_URL="$(env_value backend/.env MEDUSA_BACKEND_URL)"
190
+ STOREFRONT_URL="$(env_value backend/.env STOREFRONT_URL)"
191
+
192
+ if [[ -n "$BACKEND_URL" ]]; then
193
+ log "Backend healthcheck"
194
+ curl --fail --silent --show-error --max-time 15 "${BACKEND_URL%/}/health" >/dev/null || fail "Backend healthcheck failed"
195
+ fi
196
+ if [[ -n "$STOREFRONT_URL" ]]; then
197
+ log "Storefront healthcheck"
198
+ curl --fail --silent --show-error --max-time 15 "$STOREFRONT_URL" >/dev/null || fail "Storefront healthcheck failed"
199
+ fi
200
+
201
+ log "Production install completed"
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env bash
2
+ set -Eeuo pipefail
3
+
4
+ ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
5
+ cd "$ROOT"
6
+
7
+ log() { printf '\n==> %s\n' "$*"; }
8
+ fail() { printf '\nERROR: %s\n' "$*" >&2; exit 1; }
9
+ need() { command -v "$1" >/dev/null 2>&1 || fail "Missing required command: $1"; }
10
+ env_value() {
11
+ local file="$1" key="$2"
12
+ sed -n "s/^${key}=//p" "$file" | head -n 1
13
+ }
14
+
15
+ need pg_restore
16
+ need tar
17
+ need npm
18
+
19
+ ARCHIVE="${1:-}"
20
+ CONFIRM="${2:-}"
21
+ [[ -n "$ARCHIVE" ]] || fail "Usage: bash deploy/restore.sh /path/to/backup.tar.gz --yes"
22
+ [[ "$CONFIRM" == "--yes" ]] || fail "Restore is destructive. Re-run with --yes."
23
+ [[ -f "$ARCHIVE" ]] || fail "Backup archive not found: $ARCHIVE"
24
+
25
+ TMP="$(mktemp -d)"
26
+ trap 'rm -rf "$TMP"' EXIT
27
+ tar -C "$TMP" -xzf "$ARCHIVE"
28
+ [[ -f "$TMP/database.dump" ]] || fail "Invalid backup: database.dump is missing"
29
+ [[ -f "$TMP/config/backend.env" ]] || fail "Invalid backup: backend env is missing"
30
+
31
+ log "Restore environment"
32
+ cp "$TMP/config/backend.env" backend/.env
33
+ chmod 600 backend/.env || true
34
+ if [[ -f "$TMP/config/storefront.env.local" ]]; then
35
+ cp "$TMP/config/storefront.env.local" storefront/.env.local
36
+ chmod 600 storefront/.env.local || true
37
+ fi
38
+ [[ -f "$TMP/config/env.docker" ]] && cp "$TMP/config/env.docker" .env.docker
39
+
40
+ DATABASE_URL="$(env_value backend/.env DATABASE_URL)"
41
+ [[ -n "$DATABASE_URL" ]] || fail "Restored backend/.env has no DATABASE_URL"
42
+
43
+ log "Restore database"
44
+ pg_restore --clean --if-exists --no-owner --dbname "$DATABASE_URL" "$TMP/database.dump"
45
+
46
+ rm -rf backend/.core
47
+ [[ -d "$TMP/runtime/core" ]] && cp -R "$TMP/runtime/core" backend/.core
48
+
49
+ if [[ -d "$TMP/runtime/uploads" ]]; then
50
+ FILE_UPLOAD_DIR="$(env_value backend/.env FILE_UPLOAD_DIR)"
51
+ if [[ -n "$FILE_UPLOAD_DIR" ]]; then
52
+ mkdir -p "$FILE_UPLOAD_DIR"
53
+ rm -rf "$FILE_UPLOAD_DIR"/*
54
+ cp -R "$TMP/runtime/uploads"/. "$FILE_UPLOAD_DIR"/
55
+ else
56
+ mkdir -p backend/uploads
57
+ rm -rf backend/uploads/*
58
+ cp -R "$TMP/runtime/uploads"/. backend/uploads/
59
+ fi
60
+ fi
61
+
62
+ log "Clean dependency tree and install exact dependencies"
63
+ rm -rf node_modules
64
+ npm ci
65
+
66
+ log "Migrate and verify restored application"
67
+ npm --workspace backend run env:verify
68
+ npm run db:migrate
69
+ npm run build
70
+
71
+ log "Restore completed. Start/reload with: npx pm2@6.0.13 startOrReload ecosystem.config.cjs --env production"
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { existsSync, readFileSync } from "node:fs"
4
+ import { resolve } from "node:path"
5
+
6
+ const backendRoot = resolve(import.meta.dirname, "..")
7
+ const examplePath = resolve(backendRoot, ".env.example")
8
+ const envPath = resolve(backendRoot, ".env")
9
+
10
+ if (!existsSync(examplePath)) {
11
+ throw new Error(`Hiányzik a kanonikus env minta: ${examplePath}`)
12
+ }
13
+
14
+ if (!existsSync(envPath)) {
15
+ throw new Error(`Hiányzik a backend .env: ${envPath}`)
16
+ }
17
+
18
+ const exampleKeys = envKeys(readFileSync(examplePath, "utf8"))
19
+ const envKeysActual = envKeys(readFileSync(envPath, "utf8"))
20
+
21
+ const missing = exampleKeys.filter((key) => !envKeysActual.includes(key))
22
+ const extra = envKeysActual.filter((key) => !exampleKeys.includes(key))
23
+
24
+ if (missing.length || extra.length) {
25
+ const details = [
26
+ missing.length ? `Hiányzik a .env-ből: ${missing.join(", ")}` : "",
27
+ extra.length ? `Nincs benne a .env.example-ban: ${extra.join(", ")}` : "",
28
+ ].filter(Boolean)
29
+
30
+ throw new Error(
31
+ `A backend/.env és backend/.env.example kulcslistája eltér. ${details.join(" | ")}`,
32
+ )
33
+ }
34
+
35
+ console.log(`✅ Env contract rendben: ${exampleKeys.length} kulcs 1:1 megegyezik.`)
36
+
37
+ function envKeys(source) {
38
+ const keys = []
39
+ const seen = new Set()
40
+
41
+ for (const rawLine of source.split(/\r?\n/)) {
42
+ const line = rawLine.trim()
43
+ if (!line || line.startsWith("#")) continue
44
+
45
+ const match = line.match(/^([A-Za-z_][A-Za-z0-9_]*)=/)
46
+ if (!match) continue
47
+
48
+ const key = match[1]
49
+ if (seen.has(key)) {
50
+ throw new Error(`Duplikált env kulcs: ${key}`)
51
+ }
52
+
53
+ seen.add(key)
54
+ keys.push(key)
55
+ }
56
+
57
+ return keys
58
+ }
@@ -5,7 +5,7 @@ import ensureShipping from "@hszrdm/core/scripts/ensure-shipping"
5
5
  import { normalizeMedusaExecArgs } from "@hszrdm/core/scripts/exec-args"
6
6
 
7
7
  export default async function runCoreInit(params: ExecArgs) {
8
- await coreInit({
8
+ const completed = await coreInit({
9
9
  ...params,
10
10
  args: normalizeMedusaExecArgs(params.args || [], {
11
11
  boolean: ["yes", "force"],
@@ -21,6 +21,8 @@ export default async function runCoreInit(params: ExecArgs) {
21
21
  }),
22
22
  })
23
23
 
24
+ if (!completed) return
25
+
24
26
  await ensureLocales({
25
27
  ...params,
26
28
  args: [],
@@ -0,0 +1,35 @@
1
+ import type { Metadata } from "next"
2
+ import { Suspense } from "react"
3
+ import { AbandonedCartRecovery } from "@/components/abandoned-cart-recovery"
4
+ import { getCoreConfig } from "@/lib/core/client"
5
+ import { requestStorefrontLocale } from "@/lib/storefront-locale-server"
6
+
7
+ export const metadata: Metadata = {
8
+ title: "Kosár visszaállítása",
9
+ robots: {
10
+ index: false,
11
+ follow: false,
12
+ },
13
+ referrer: "no-referrer",
14
+ }
15
+
16
+ export default async function CartRecoveryPage() {
17
+ const [config, locale] = await Promise.all([
18
+ getCoreConfig(),
19
+ requestStorefrontLocale(),
20
+ ])
21
+
22
+ return (
23
+ <div className="page-section narrow-page">
24
+ <Suspense
25
+ fallback={(
26
+ <div className="empty-state">
27
+ {locale === "en" ? "Restoring your cart…" : "A kosarad visszaállítása…"}
28
+ </div>
29
+ )}
30
+ >
31
+ <AbandonedCartRecovery config={config} />
32
+ </Suspense>
33
+ </div>
34
+ )
35
+ }
@@ -0,0 +1,25 @@
1
+ import type { Metadata } from "next"
2
+ import { Suspense } from "react"
3
+ import { ReviewRequestForm } from "@/components/review-request-form"
4
+ import { getCoreConfig } from "@/lib/core/client"
5
+
6
+ export const metadata: Metadata = {
7
+ title: "Értékelés",
8
+ robots: {
9
+ index: false,
10
+ follow: false,
11
+ },
12
+ referrer: "no-referrer",
13
+ }
14
+
15
+ export default async function ReviewRequestPage() {
16
+ const config = await getCoreConfig()
17
+
18
+ return (
19
+ <div className="page-section narrow-page">
20
+ <Suspense fallback={<div className="empty-state">Értékelési link ellenőrzése…</div>}>
21
+ <ReviewRequestForm config={config} />
22
+ </Suspense>
23
+ </div>
24
+ )
25
+ }
@@ -0,0 +1,35 @@
1
+ import type { Metadata } from "next"
2
+ import { Suspense } from "react"
3
+ import { AccountActivationForm } from "@/components/account-activation-form"
4
+ import { getCoreConfig } from "@/lib/core/client"
5
+ import { requestStorefrontLocale } from "@/lib/storefront-locale-server"
6
+
7
+ export const metadata: Metadata = {
8
+ title: "Fiókaktiválás",
9
+ robots: {
10
+ index: false,
11
+ follow: false,
12
+ },
13
+ referrer: "no-referrer",
14
+ }
15
+
16
+ export default async function AccountActivationPage() {
17
+ const [config, locale] = await Promise.all([
18
+ getCoreConfig(),
19
+ requestStorefrontLocale(),
20
+ ])
21
+
22
+ return (
23
+ <div className="page-section narrow-page">
24
+ <Suspense
25
+ fallback={(
26
+ <div className="empty-state">
27
+ {locale === "en" ? "Checking activation link…" : "Aktiváló link ellenőrzése…"}
28
+ </div>
29
+ )}
30
+ >
31
+ <AccountActivationForm config={config} />
32
+ </Suspense>
33
+ </div>
34
+ )
35
+ }