@hszrdm/create-commerce 1.2.0 → 1.4.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.
- package/README.md +92 -1
- package/package.json +2 -2
- package/templates/backend/.env.example +288 -76
- package/templates/backend/package.json +5 -3
- package/templates/backend/scripts/materialize-production.mjs +37 -0
- package/templates/backend/scripts/production-assets/backup.sh +56 -0
- package/templates/backend/scripts/production-assets/deploy.sh +67 -0
- package/templates/backend/scripts/production-assets/ecosystem.config.cjs.tpl +24 -0
- package/templates/backend/scripts/production-assets/install.sh +200 -0
- package/templates/backend/scripts/production-assets/restore.sh +68 -0
- package/templates/backend/scripts/verify-env-contract.mjs +58 -0
- package/templates/storefront/README.md +14 -1
- package/templates/storefront/src/app/[countryCode]/products/[handle]/page.tsx +2 -0
- package/templates/storefront/src/app/blog/[slug]/page.tsx +36 -0
- package/templates/storefront/src/app/blog/page.tsx +25 -0
- package/templates/storefront/src/app/contact/page.tsx +25 -0
- package/templates/storefront/src/app/customer-capabilities.css +60 -0
- package/templates/storefront/src/app/knowledge-base/[slug]/page.tsx +35 -0
- package/templates/storefront/src/app/knowledge-base/page.tsx +25 -0
- package/templates/storefront/src/app/layout.tsx +11 -2
- package/templates/storefront/src/app/pages/[slug]/page.tsx +35 -0
- package/templates/storefront/src/app/quote-request/page.tsx +20 -0
- package/templates/storefront/src/components/cms-content.tsx +75 -0
- package/templates/storefront/src/components/lead-form.tsx +203 -0
- package/templates/storefront/src/components/newsletter-signup.tsx +107 -0
- package/templates/storefront/src/components/product-reviews.tsx +150 -0
- package/templates/storefront/src/components/quote-request-form.tsx +212 -0
- package/templates/storefront/src/lib/core/cms.ts +5 -4
- package/templates/storefront/src/lib/storefront-routes.ts +30 -0
- package/templates/storefront/src/proxy.ts +22 -28
|
@@ -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,67 @@
|
|
|
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 "Install exact dependencies"
|
|
44
|
+
npm ci
|
|
45
|
+
npm --workspace backend run env:verify
|
|
46
|
+
|
|
47
|
+
log "Run database migrations"
|
|
48
|
+
npm run db:migrate
|
|
49
|
+
npm run core:init -- --yes
|
|
50
|
+
|
|
51
|
+
log "Build"
|
|
52
|
+
npm run build
|
|
53
|
+
|
|
54
|
+
log "Reload PM2"
|
|
55
|
+
pm2_run startOrReload ecosystem.config.cjs --env production
|
|
56
|
+
pm2_run save
|
|
57
|
+
|
|
58
|
+
BACKEND_URL="$(env_value backend/.env MEDUSA_BACKEND_URL)"
|
|
59
|
+
STOREFRONT_URL="$(env_value backend/.env STOREFRONT_URL)"
|
|
60
|
+
if [[ -n "$BACKEND_URL" ]]; then
|
|
61
|
+
curl --fail --silent --show-error --max-time 15 "${BACKEND_URL%/}/health" >/dev/null || fail "Backend healthcheck failed after deploy"
|
|
62
|
+
fi
|
|
63
|
+
if [[ -n "$STOREFRONT_URL" ]]; then
|
|
64
|
+
curl --fail --silent --show-error --max-time 15 "$STOREFRONT_URL" >/dev/null || fail "Storefront healthcheck failed after deploy"
|
|
65
|
+
fi
|
|
66
|
+
|
|
67
|
+
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,200 @@
|
|
|
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 "Install exact dependencies"
|
|
160
|
+
npm ci
|
|
161
|
+
|
|
162
|
+
log "Verify environment schema"
|
|
163
|
+
npm --workspace backend run env:verify
|
|
164
|
+
|
|
165
|
+
log "Run database migrations"
|
|
166
|
+
npm run db:migrate
|
|
167
|
+
|
|
168
|
+
log "Ensure Core bootstrap state"
|
|
169
|
+
npm run core:init -- --yes
|
|
170
|
+
|
|
171
|
+
# If this is a truly fresh server, create a Store API publishable key after the
|
|
172
|
+
# database/bootstrap exists. Existing storefront keys are never overwritten.
|
|
173
|
+
if [[ -z "$(env_value storefront/.env.local NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY)" ]]; then
|
|
174
|
+
log "Create storefront publishable API key"
|
|
175
|
+
KEY_OUTPUT="$(npm run storefront:key -- --title "$(metadata_value project.store_name) Storefront")"
|
|
176
|
+
PUBLISHABLE_KEY="$(printf '%s\n' "$KEY_OUTPUT" | sed -n 's/^HSZRDM_PUBLISHABLE_KEY=//p' | tail -n 1)"
|
|
177
|
+
[[ -n "$PUBLISHABLE_KEY" ]] || fail "Could not create storefront publishable API key"
|
|
178
|
+
set_env storefront/.env.local NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY "$PUBLISHABLE_KEY"
|
|
179
|
+
fi
|
|
180
|
+
|
|
181
|
+
log "Build backend and storefront"
|
|
182
|
+
npm run build
|
|
183
|
+
|
|
184
|
+
log "Start/reload PM2 applications"
|
|
185
|
+
pm2_run startOrReload ecosystem.config.cjs --env production
|
|
186
|
+
pm2_run save
|
|
187
|
+
|
|
188
|
+
BACKEND_URL="$(env_value backend/.env MEDUSA_BACKEND_URL)"
|
|
189
|
+
STOREFRONT_URL="$(env_value backend/.env STOREFRONT_URL)"
|
|
190
|
+
|
|
191
|
+
if [[ -n "$BACKEND_URL" ]]; then
|
|
192
|
+
log "Backend healthcheck"
|
|
193
|
+
curl --fail --silent --show-error --max-time 15 "${BACKEND_URL%/}/health" >/dev/null || fail "Backend healthcheck failed"
|
|
194
|
+
fi
|
|
195
|
+
if [[ -n "$STOREFRONT_URL" ]]; then
|
|
196
|
+
log "Storefront healthcheck"
|
|
197
|
+
curl --fail --silent --show-error --max-time 15 "$STOREFRONT_URL" >/dev/null || fail "Storefront healthcheck failed"
|
|
198
|
+
fi
|
|
199
|
+
|
|
200
|
+
log "Production install completed"
|
|
@@ -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
|
+
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 "Install, migrate and verify restored application"
|
|
63
|
+
npm ci
|
|
64
|
+
npm --workspace backend run env:verify
|
|
65
|
+
npm run db:migrate
|
|
66
|
+
npm run build
|
|
67
|
+
|
|
68
|
+
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
|
+
}
|
|
@@ -28,6 +28,8 @@ szükséges. A payment/shipping/legal/SEO/analytics capability-k a `GET /store/c
|
|
|
28
28
|
- teljes terméklista: keresés, kategóriaszűrés, rendezés, lapozás;
|
|
29
29
|
- kategória- és termékoldal Core SEO/JSON-LD contracttal;
|
|
30
30
|
- variáns- és mennyiségválasztás, Add to Cart;
|
|
31
|
+
- wishlist guest móddal, account merge-dzsel és saját wishlist oldallal;
|
|
32
|
+
- termékértékelések approved listával, aggregált értékeléssel és bejelentkezett ügyfél review beküldéssel;
|
|
31
33
|
- közös cart state, cart drawer és teljes kosároldal;
|
|
32
34
|
- kupon hozzáadás/eltávolítás;
|
|
33
35
|
- region automatikus feloldása a Core alapértelmezett országa alapján;
|
|
@@ -46,10 +48,21 @@ szükséges. A payment/shipping/legal/SEO/analytics capability-k a `GET /store/c
|
|
|
46
48
|
- címjegyzék CRUD;
|
|
47
49
|
- rendelési előzmények és rendelésrészlet;
|
|
48
50
|
- return / exchange / claim self-service;
|
|
51
|
+
- CMS referencia UI: blog lista/detail, generic page detail és tudástár lista/detail;
|
|
52
|
+
- newsletter signup a footerben, double-opt-in confirm és leiratkozó oldalakkal;
|
|
53
|
+
- általános ajánlatkérő oldal a Core extra meződefinícióival;
|
|
54
|
+
- dinamikus lead/contact form privacy consenttel, honeypottal és opcionális Cloudflare Turnstile támogatással;
|
|
49
55
|
- globális loading/error/404/empty state-ek;
|
|
56
|
+
- toast, share, accessibility preferences, keyboard/focus UX és reduced-motion támogatás;
|
|
50
57
|
- Consent Mode v2, GA4/GTM és e-commerce tracking;
|
|
51
58
|
- robots.txt / sitemap.xml proxy és Search Console verification.
|
|
52
59
|
|
|
60
|
+
## Customer-facing Core capability elv
|
|
61
|
+
|
|
62
|
+
A starter célja, hogy minden általános, customer-facing Core képességhez legyen design-semleges referencia UI vagy route. Az ügyfélprojektekben a vizuális réteg szabadon cserélhető, de a `src/lib/core` contractok és a referencia flow-k mutatják a támogatott integrációt.
|
|
63
|
+
|
|
64
|
+
Admin-, számlázási-, fulfillment-, audit-, integration-settings- és más háttérképességekhez nem tartozik storefront UI, mert azok nem customer-facing funkciók.
|
|
65
|
+
|
|
53
66
|
## Authority boundary
|
|
54
67
|
|
|
55
68
|
A starter **nem** számol újra:
|
|
@@ -105,4 +118,4 @@ npm run typecheck
|
|
|
105
118
|
npm run build
|
|
106
119
|
```
|
|
107
120
|
|
|
108
|
-
A backend unit suite statikus regressziós tesztje azt is ellenőrzi, hogy a kötelező starter route-ok és Core contractok megmaradjanak.
|
|
121
|
+
A backend unit suite statikus regressziós tesztje azt is ellenőrzi, hogy a kötelező starter route-ok, customer-facing Core capability-k és Core contractok megmaradjanak.
|
|
@@ -2,6 +2,7 @@ import { notFound } from "next/navigation"
|
|
|
2
2
|
import { AddToCart } from "@/components/add-to-cart"
|
|
3
3
|
import { Breadcrumbs } from "@/components/breadcrumbs"
|
|
4
4
|
import { ProductGallery } from "@/components/product-gallery"
|
|
5
|
+
import { ProductReviews } from "@/components/product-reviews"
|
|
5
6
|
import { ProductViewTracker } from "@/components/product-view-tracker"
|
|
6
7
|
import { ShareButton } from "@/components/share-button"
|
|
7
8
|
import { VariantPriceDisplay } from "@/components/variant-price-display"
|
|
@@ -82,6 +83,7 @@ export default async function ProductPage({ params }: { params: Promise<{ countr
|
|
|
82
83
|
<div className="product-meta">{product.subtitle ? <span>{stringValue(product.subtitle)}</span> : null}{product.material ? <span>{copy.material}: {stringValue(product.material)}</span> : null}{product.origin_country ? <span>{copy.origin}: {stringValue(product.origin_country)}</span> : null}</div>
|
|
83
84
|
</section>
|
|
84
85
|
</div>
|
|
86
|
+
{productId ? <ProductReviews productId={productId} locale={locale} /> : null}
|
|
85
87
|
</div>
|
|
86
88
|
)
|
|
87
89
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Metadata } from "next"
|
|
2
|
+
import { notFound } from "next/navigation"
|
|
3
|
+
import { Breadcrumbs } from "@/components/breadcrumbs"
|
|
4
|
+
import { CmsEntryBody, CmsEntryMeta } from "@/components/cms-content"
|
|
5
|
+
import { cmsEntrySeo, getBlogPost } from "@/lib/core/cms"
|
|
6
|
+
import { requestStorefrontLocale } from "@/lib/storefront-locale-server"
|
|
7
|
+
import { STOREFRONT_ROUTES, medusaLocale } from "@/lib/storefront-routes"
|
|
8
|
+
|
|
9
|
+
export async function generateMetadata({ params }: { params: Promise<{ slug: string }> }): Promise<Metadata> {
|
|
10
|
+
const { slug } = await params
|
|
11
|
+
const locale = await requestStorefrontLocale()
|
|
12
|
+
const result = await getBlogPost(slug, { locale: medusaLocale(locale) }).catch(() => null)
|
|
13
|
+
return result ? cmsEntrySeo(result.entry) : {}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default async function BlogPostPage({ params }: { params: Promise<{ slug: string }> }) {
|
|
17
|
+
const { slug } = await params
|
|
18
|
+
const locale = await requestStorefrontLocale()
|
|
19
|
+
const english = locale === "en"
|
|
20
|
+
const result = await getBlogPost(slug, { locale: medusaLocale(locale) }).catch(() => null)
|
|
21
|
+
if (!result) notFound()
|
|
22
|
+
const entry = result.entry
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<article className="stack page-section cms-detail">
|
|
26
|
+
<Breadcrumbs items={[{ label: english ? "Blog" : "Blog", href: STOREFRONT_ROUTES[locale].blog }, { label: entry.title }]} label={english ? "Breadcrumb" : "Morzsanavigáció"} />
|
|
27
|
+
<header className="stack-sm">
|
|
28
|
+
<CmsEntryMeta entry={entry} locale={locale} />
|
|
29
|
+
<h1>{entry.title}</h1>
|
|
30
|
+
{entry.excerpt ? <p className="lead">{entry.excerpt}</p> : null}
|
|
31
|
+
{entry.featured_image_url ? <img className="cms-hero-image" src={entry.featured_image_url} alt={entry.featured_image_alt || entry.title} /> : null}
|
|
32
|
+
</header>
|
|
33
|
+
<CmsEntryBody entry={entry} />
|
|
34
|
+
</article>
|
|
35
|
+
)
|
|
36
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { CmsEntryCard } from "@/components/cms-content"
|
|
2
|
+
import { listBlogPosts } from "@/lib/core/cms"
|
|
3
|
+
import { requestStorefrontLocale } from "@/lib/storefront-locale-server"
|
|
4
|
+
import { blogPostPath, medusaLocale } from "@/lib/storefront-routes"
|
|
5
|
+
|
|
6
|
+
export default async function BlogPage() {
|
|
7
|
+
const locale = await requestStorefrontLocale()
|
|
8
|
+
const english = locale === "en"
|
|
9
|
+
const { entries } = await listBlogPosts({ locale: medusaLocale(locale), limit: 50 }).catch(() => ({ entries: [] }))
|
|
10
|
+
|
|
11
|
+
return (
|
|
12
|
+
<div className="stack page-section">
|
|
13
|
+
<header className="stack-sm">
|
|
14
|
+
<p className="eyebrow">{english ? "Articles" : "Cikkek"}</p>
|
|
15
|
+
<h1>{english ? "Blog" : "Blog"}</h1>
|
|
16
|
+
<p className="muted">{english ? "News, guides and useful content from the store." : "Hírek, útmutatók és hasznos tartalmak a webáruháztól."}</p>
|
|
17
|
+
</header>
|
|
18
|
+
{entries.length ? (
|
|
19
|
+
<div className="cms-grid">
|
|
20
|
+
{entries.map((entry) => <CmsEntryCard key={entry.id} entry={entry} href={blogPostPath(locale, entry.slug)} locale={locale} />)}
|
|
21
|
+
</div>
|
|
22
|
+
) : <div className="empty-state">{english ? "No published articles yet." : "Még nincs publikált bejegyzés."}</div>}
|
|
23
|
+
</div>
|
|
24
|
+
)
|
|
25
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { LeadForm } from "@/components/lead-form"
|
|
2
|
+
import { leadFormConfig } from "@/lib/core/leads"
|
|
3
|
+
import { requestStorefrontLocale } from "@/lib/storefront-locale-server"
|
|
4
|
+
|
|
5
|
+
export default async function ContactPage() {
|
|
6
|
+
const locale = await requestStorefrontLocale()
|
|
7
|
+
const english = locale === "en"
|
|
8
|
+
const config = await leadFormConfig("contact").catch(() => ({ forms: [], spam_protection: { honeypot_field: "website", turnstile: { enabled: false, site_key: null } } }))
|
|
9
|
+
const form = config.forms.find((item) => item.enabled) || null
|
|
10
|
+
|
|
11
|
+
return (
|
|
12
|
+
<div className="stack page-section narrow-page">
|
|
13
|
+
<header className="stack-sm">
|
|
14
|
+
<p className="eyebrow">{english ? "Contact" : "Kapcsolat"}</p>
|
|
15
|
+
<h1>{form?.label || (english ? "Send us a message" : "Írj nekünk")}</h1>
|
|
16
|
+
<p className="muted">{english ? "Use the form below and the team will get back to you." : "Töltsd ki az űrlapot, és a csapat felveszi veled a kapcsolatot."}</p>
|
|
17
|
+
</header>
|
|
18
|
+
{form ? (
|
|
19
|
+
<LeadForm locale={locale} form={form} spamProtection={config.spam_protection} />
|
|
20
|
+
) : (
|
|
21
|
+
<div className="empty-state">{english ? "The contact form is currently unavailable." : "A kapcsolatfelvételi űrlap jelenleg nem elérhető."}</div>
|
|
22
|
+
)}
|
|
23
|
+
</div>
|
|
24
|
+
)
|
|
25
|
+
}
|