@hszrdm/create-commerce 1.10.1 → 1.11.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/package.json +1 -1
- package/src/cli.mjs +18 -3
- package/src/upgrade.mjs +39 -3
- package/templates/backend/.env.example +8 -0
- package/templates/backend/package.json +1 -1
- package/templates/backend/scripts/commerce-instance-status.mjs +135 -0
- package/templates/backend/scripts/commerce-ops.mjs +58 -2
- package/templates/backend/scripts/core-restore.mjs +40 -5
- package/templates/backend/scripts/lib/core-backup-common.mjs +91 -11
- package/templates/backend/scripts/production-assets/backup.sh +6 -51
- package/templates/backend/scripts/production-assets/deploy.sh +10 -62
- package/templates/backend/scripts/production-assets/install.sh +23 -195
- package/templates/backend/scripts/production-assets/restore.sh +17 -66
- package/templates/storefront/package.json +5 -1
- package/templates/storefront/src/app/checkout/success/page.tsx +2 -0
- package/templates/storefront/src/app/globals.css +32 -0
- package/templates/storefront/src/app/layout.tsx +7 -1
- package/templates/storefront/src/app/legal/page.tsx +3 -3
- package/templates/storefront/src/components/analytics.tsx +10 -8
- package/templates/storefront/src/components/checkout-flow.tsx +539 -75
- package/templates/storefront/src/components/fogyasztobarat-embed.tsx +6 -2
- package/templates/storefront/src/components/google-analytics-purchase.tsx +33 -0
- package/templates/storefront/src/components/stripe-payment.tsx +186 -62
- package/templates/storefront/src/lib/core/checkout-addresses.ts +166 -0
- package/templates/storefront/src/lib/core/checkout.ts +12 -0
- package/templates/storefront/src/lib/core/commerce.ts +12 -2
- package/templates/storefront/src/lib/core/company-tax.ts +132 -0
- package/templates/storefront/src/lib/core/ga4-bootstrap.ts +35 -0
- package/templates/storefront/src/lib/core/legal.ts +1 -0
- package/templates/storefront/src/lib/core/public-error.ts +1 -0
- package/templates/storefront/src/lib/core/stripe-checkout-phase.ts +23 -0
- package/templates/storefront/src/lib/core/tracking.ts +11 -2
- package/templates/storefront/tests/checkout-addresses.test.mjs +148 -0
- package/templates/storefront/tests/company-tax.test.mjs +68 -0
- package/templates/storefront/tests/ga4-bootstrap.test.mjs +74 -0
- package/templates/storefront/tests/stripe-checkout-phase.test.mjs +92 -0
|
@@ -1,56 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
+
# Compatibility entry point. Backups must use the encrypted-data-aware Core
|
|
3
|
+
# bundle format; never archive raw backend/.env production secrets.
|
|
2
4
|
set -Eeuo pipefail
|
|
3
|
-
|
|
4
5
|
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
5
6
|
cd "$ROOT"
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
|
7
|
+
[[ -f backend/.env.production ]] || {
|
|
8
|
+
echo "ERROR: backend/.env.production is required for production backup." >&2
|
|
9
|
+
exit 2
|
|
13
10
|
}
|
|
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'
|
|
11
|
+
exec npm run backup:prod
|
|
@@ -1,68 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
+
# Compatibility entry point. The environment-aware commerce-ops workflow is
|
|
3
|
+
# the only supported production deploy implementation.
|
|
2
4
|
set -Eeuo pipefail
|
|
3
|
-
|
|
4
5
|
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
5
6
|
cd "$ROOT"
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
|
7
|
+
[[ -f backend/.env.production ]] || {
|
|
8
|
+
echo "ERROR: backend/.env.production is required. Refusing to deploy using backend/.env (development)." >&2
|
|
9
|
+
exit 2
|
|
16
10
|
}
|
|
17
|
-
|
|
18
|
-
local
|
|
19
|
-
|
|
11
|
+
[[ -f storefront/.env.local ]] || {
|
|
12
|
+
echo "ERROR: storefront/.env.local is missing." >&2
|
|
13
|
+
exit 2
|
|
20
14
|
}
|
|
21
|
-
|
|
22
|
-
|
|
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"
|
|
15
|
+
echo "HSZRDM production deploy via canonical deploy:prod (no implicit git pull)."
|
|
16
|
+
exec npm run deploy:prod
|
|
@@ -1,201 +1,29 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
+
# Fresh production installation: explicit production env + canonical bootstrap
|
|
3
|
+
# deploy. Never populate a production database using a development .env.
|
|
2
4
|
set -Eeuo pipefail
|
|
3
|
-
|
|
4
5
|
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
5
6
|
cd "$ROOT"
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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"
|
|
7
|
+
[[ -f backend/.env.production ]] || {
|
|
8
|
+
echo "ERROR: configure backend/.env.production with a distinct production DATABASE_URL first." >&2
|
|
9
|
+
echo "Do NOT copy development DB credentials into production." >&2
|
|
10
|
+
exit 2
|
|
11
|
+
}
|
|
12
|
+
[[ -f storefront/.env.local ]] || {
|
|
13
|
+
echo "ERROR: create/configure storefront/.env.local before installation." >&2
|
|
14
|
+
exit 2
|
|
15
|
+
}
|
|
16
|
+
# Production admin credentials must be supplied deliberately, never copied from
|
|
17
|
+
# the generated developer .env or stored in the repository.
|
|
18
|
+
if [[ -z "${HSZRDM_INSTALL_ADMIN_EMAIL:-}" ]]; then
|
|
19
|
+
[[ -t 0 ]] || { echo "ERROR: set HSZRDM_INSTALL_ADMIN_EMAIL for non-interactive install." >&2; exit 2; }
|
|
20
|
+
read -r -p "First production Admin email: " HSZRDM_INSTALL_ADMIN_EMAIL
|
|
195
21
|
fi
|
|
196
|
-
if [[ -
|
|
197
|
-
|
|
198
|
-
|
|
22
|
+
if [[ -z "${HSZRDM_INSTALL_ADMIN_PASSWORD:-}" ]]; then
|
|
23
|
+
[[ -t 0 ]] || { echo "ERROR: set HSZRDM_INSTALL_ADMIN_PASSWORD for non-interactive install." >&2; exit 2; }
|
|
24
|
+
read -r -s -p "First production Admin password (12+ characters): " HSZRDM_INSTALL_ADMIN_PASSWORD
|
|
25
|
+
printf '\n'
|
|
199
26
|
fi
|
|
200
|
-
|
|
201
|
-
|
|
27
|
+
export HSZRDM_INSTALL_ADMIN_EMAIL HSZRDM_INSTALL_ADMIN_PASSWORD
|
|
28
|
+
echo "Fresh production bootstrap (database must exist; latest backup is made first)."
|
|
29
|
+
exec npm run deploy:prod -- --bootstrap
|
|
@@ -1,71 +1,22 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
+
# Compatibility entry point. Only Core bundle directories are supported.
|
|
3
|
+
# Legacy tar archives contain raw secrets and require a separate, reviewed
|
|
4
|
+
# migration procedure; never silently restore their backend/.env.
|
|
2
5
|
set -Eeuo pipefail
|
|
3
|
-
|
|
4
6
|
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
5
7
|
cd "$ROOT"
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
|
8
|
+
[[ -f backend/.env.production ]] || {
|
|
9
|
+
echo "ERROR: backend/.env.production is required for production restore." >&2
|
|
10
|
+
exit 2
|
|
13
11
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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"
|
|
12
|
+
FROM="${1:-}"
|
|
13
|
+
[[ -n "$FROM" ]] || {
|
|
14
|
+
echo "Usage: bash deploy/restore.sh <bundle-directory> --yes --confirm-database=<database> [--overwrite-files]" >&2
|
|
15
|
+
exit 2
|
|
16
|
+
}
|
|
17
|
+
[[ -d "$FROM" ]] || {
|
|
18
|
+
echo "ERROR: Core backup bundle DIRECTORY required. Legacy tar archives cannot be restored automatically." >&2
|
|
19
|
+
exit 2
|
|
20
|
+
}
|
|
21
|
+
shift
|
|
22
|
+
exec npm run restore:prod -- --from "$FROM" "$@"
|
|
@@ -9,7 +9,11 @@
|
|
|
9
9
|
"typecheck": "tsc --noEmit",
|
|
10
10
|
"test:pickup": "node --experimental-strip-types --test tests/carrier-pickup-adapter.test.mjs",
|
|
11
11
|
"test:validation": "node --experimental-strip-types --test tests/shipping-input-validation.test.mjs",
|
|
12
|
-
"test:errors": "node --experimental-strip-types --test tests/public-error.test.mjs"
|
|
12
|
+
"test:errors": "node --experimental-strip-types --test tests/public-error.test.mjs",
|
|
13
|
+
"test:addresses": "node --experimental-strip-types --test tests/checkout-addresses.test.mjs",
|
|
14
|
+
"test:stripe": "node --experimental-strip-types --test tests/stripe-checkout-phase.test.mjs",
|
|
15
|
+
"test:company-tax": "node --experimental-strip-types --test tests/company-tax.test.mjs",
|
|
16
|
+
"test:ga4": "node --experimental-strip-types --test tests/ga4-bootstrap.test.mjs"
|
|
13
17
|
},
|
|
14
18
|
"dependencies": {
|
|
15
19
|
"@stripe/react-stripe-js": "7.0.0",
|
|
@@ -2,6 +2,7 @@ import Link from "next/link"
|
|
|
2
2
|
import { notFound } from "next/navigation"
|
|
3
3
|
import { ArukeresoTrustedShop } from "@/components/arukereso-trusted-shop"
|
|
4
4
|
import { GoogleAdsPurchase } from "@/components/google-ads-purchase"
|
|
5
|
+
import { GoogleAnalyticsPurchase } from "@/components/google-analytics-purchase"
|
|
5
6
|
import { checkoutApi } from "@/lib/core/checkout"
|
|
6
7
|
import { endpoint, getCoreConfig, medusaFetch } from "@/lib/core/client"
|
|
7
8
|
import { asRecords, formatMoney, isRecord, stringValue, type JsonRecord } from "@/lib/core/commerce"
|
|
@@ -39,6 +40,7 @@ export default async function CheckoutSuccessPage({ searchParams }: { searchPara
|
|
|
39
40
|
|
|
40
41
|
return (
|
|
41
42
|
<div className="stack page-section narrow-page">
|
|
43
|
+
<GoogleAnalyticsPurchase analytics={config.analytics} order={order} />
|
|
42
44
|
<GoogleAdsPurchase googleAds={config.marketing.google_ads} order={order} />
|
|
43
45
|
<ArukeresoTrustedShop orderId={orderId} />
|
|
44
46
|
|
|
@@ -138,6 +138,38 @@ input[readonly] { background: var(--surface-soft); color: var(--muted); }
|
|
|
138
138
|
|
|
139
139
|
.checkout-layout { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 24px; align-items: start; }
|
|
140
140
|
.checkout-summary { position: sticky; top: 18px; }
|
|
141
|
+
|
|
142
|
+
/* Stripe SDK and Payment Element both have an explicit loading stage.
|
|
143
|
+
Keep Elements mounted (for onReady/confirmPayment) underneath the loader. */
|
|
144
|
+
.stripe-payment-stage { position: relative; min-height: 72px; }
|
|
145
|
+
.stripe-payment-fields { transition: opacity .16s ease; }
|
|
146
|
+
.stripe-payment-loading {
|
|
147
|
+
display: flex;
|
|
148
|
+
align-items: center;
|
|
149
|
+
gap: 12px;
|
|
150
|
+
min-height: 72px;
|
|
151
|
+
padding: 14px 16px;
|
|
152
|
+
border-radius: 12px;
|
|
153
|
+
border: 1px solid var(--line);
|
|
154
|
+
background: var(--surface-soft);
|
|
155
|
+
color: var(--muted);
|
|
156
|
+
font-size: .9rem;
|
|
157
|
+
font-weight: 650;
|
|
158
|
+
}
|
|
159
|
+
.stripe-loading-spinner {
|
|
160
|
+
flex: 0 0 auto;
|
|
161
|
+
width: 22px;
|
|
162
|
+
height: 22px;
|
|
163
|
+
border: 2px solid var(--line);
|
|
164
|
+
border-top-color: var(--brand);
|
|
165
|
+
border-radius: 50%;
|
|
166
|
+
animation: stripe-loading-spin .8s linear infinite;
|
|
167
|
+
}
|
|
168
|
+
@keyframes stripe-loading-spin { to { transform: rotate(360deg); } }
|
|
169
|
+
@media (prefers-reduced-motion: reduce) {
|
|
170
|
+
.stripe-loading-spinner { animation-duration: 2s; }
|
|
171
|
+
.stripe-payment-fields { transition: none; }
|
|
172
|
+
}
|
|
141
173
|
.section-title { display: flex; align-items: center; gap: 10px; }
|
|
142
174
|
.section-title h2 { margin: 0; }
|
|
143
175
|
.step-badge { display: grid; place-items: center; width: 31px; height: 31px; border-radius: 50%; background: var(--brand); color: white; font-size: .8rem; font-weight: 850; }
|
|
@@ -11,10 +11,12 @@ import { CartProvider } from "@/components/cart-provider"
|
|
|
11
11
|
import { ConsentBanner } from "@/components/consent-banner"
|
|
12
12
|
import { CustomerCartResumeGate } from "@/components/customer-cart-resume-gate"
|
|
13
13
|
import { GoogleAdsCartRemarketing } from "@/components/google-ads-cart-remarketing"
|
|
14
|
+
import { FogyasztobaratEmbed } from "@/components/fogyasztobarat-embed"
|
|
14
15
|
import { NewsletterSignup } from "@/components/newsletter-signup"
|
|
15
16
|
import { StorefrontHeader } from "@/components/storefront-header"
|
|
16
17
|
import { ToastProvider } from "@/components/toast-provider"
|
|
17
18
|
import { getCoreConfig } from "@/lib/core/client"
|
|
19
|
+
import { getLegalEmbed, type LegalEmbedConfig } from "@/lib/core/legal"
|
|
18
20
|
import { requestStorefrontLocale } from "@/lib/storefront-locale-server"
|
|
19
21
|
import { STOREFRONT_ROUTES } from "@/lib/storefront-routes"
|
|
20
22
|
|
|
@@ -47,9 +49,10 @@ export async function generateMetadata(): Promise<Metadata> {
|
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
export default async function RootLayout({ children }: Readonly<{ children: React.ReactNode }>) {
|
|
50
|
-
const [config, locale] = await Promise.all([
|
|
52
|
+
const [config, locale, fogyasztobarat] = await Promise.all([
|
|
51
53
|
getCoreConfig(),
|
|
52
54
|
requestStorefrontLocale(),
|
|
55
|
+
getLegalEmbed().catch((): LegalEmbedConfig => ({ enabled: false })),
|
|
53
56
|
])
|
|
54
57
|
const routes = STOREFRONT_ROUTES[locale]
|
|
55
58
|
const en = locale === "en"
|
|
@@ -95,6 +98,9 @@ export default async function RootLayout({ children }: Readonly<{ children: Reac
|
|
|
95
98
|
</footer>
|
|
96
99
|
<AnalyticsGate analytics={config.analytics} googleAds={config.marketing.google_ads} />
|
|
97
100
|
<ConsentBanner enabled={config.features.analytics || config.features.google_ads} />
|
|
101
|
+
{fogyasztobarat.enabled && fogyasztobarat.placement === "global" ? (
|
|
102
|
+
<FogyasztobaratEmbed embed={fogyasztobarat} />
|
|
103
|
+
) : null}
|
|
98
104
|
</CartProvider>
|
|
99
105
|
</ToastProvider>
|
|
100
106
|
</AccessibilityPreferencesProvider>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FogyasztobaratEmbed } from "@/components/fogyasztobarat-embed"
|
|
2
2
|
import { getCoreConfig } from "@/lib/core/client"
|
|
3
|
-
import { getLegalEmbed, listLegalDocuments } from "@/lib/core/legal"
|
|
3
|
+
import { getLegalEmbed, listLegalDocuments, type LegalEmbedConfig } from "@/lib/core/legal"
|
|
4
4
|
import { storefrontCopy } from "@/lib/storefront-copy"
|
|
5
5
|
import { requestStorefrontLocale } from "@/lib/storefront-locale-server"
|
|
6
6
|
|
|
@@ -12,7 +12,7 @@ export default async function LegalPage() {
|
|
|
12
12
|
const copy = storefrontCopy(locale)
|
|
13
13
|
const [{ documents }, embed] = await Promise.all([
|
|
14
14
|
listLegalDocuments(config),
|
|
15
|
-
getLegalEmbed().catch(() => ({ enabled: false })),
|
|
15
|
+
getLegalEmbed().catch((): LegalEmbedConfig => ({ enabled: false })),
|
|
16
16
|
])
|
|
17
17
|
const en = locale === "en"
|
|
18
18
|
|
|
@@ -22,7 +22,7 @@ export default async function LegalPage() {
|
|
|
22
22
|
<div><p className="eyebrow">{copy.legalEyebrow}</p><h1>{copy.legalTitle}</h1><p className="muted">{copy.legalDescription}</p></div>
|
|
23
23
|
</div>
|
|
24
24
|
|
|
25
|
-
{embed.enabled ? (
|
|
25
|
+
{embed.enabled && embed.placement !== "global" ? (
|
|
26
26
|
<section className="panel stack-sm">
|
|
27
27
|
<div>
|
|
28
28
|
<p className="eyebrow">{en ? "Consumer information" : "Fogyasztói tájékoztatás"}</p>
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
readConsentPreferences,
|
|
10
10
|
type ConsentPreferences,
|
|
11
11
|
} from "@/lib/core/consent"
|
|
12
|
+
import { ensureDirectGa4Initialized } from "@/lib/core/ga4-bootstrap"
|
|
12
13
|
import { analyticsTrackingMode, trackWebshopPageView } from "@/lib/core/tracking"
|
|
13
14
|
import type { CoreConfig } from "@/lib/core/types"
|
|
14
15
|
|
|
@@ -46,6 +47,8 @@ export function AnalyticsGate({
|
|
|
46
47
|
const [preferences, setPreferences] = useState<ConsentPreferences | null>(null)
|
|
47
48
|
const [ready, setReady] = useState(false)
|
|
48
49
|
const sensitivePath = SENSITIVE_ANALYTICS_PATHS.has(pathname)
|
|
50
|
+
const mode = analyticsTrackingMode(analytics)
|
|
51
|
+
const ga4Id = analytics.google_analytics.measurement_id
|
|
49
52
|
|
|
50
53
|
useEffect(() => {
|
|
51
54
|
const stored = readConsentPreferences()
|
|
@@ -71,9 +74,15 @@ export function AnalyticsGate({
|
|
|
71
74
|
trackWebshopPageView()
|
|
72
75
|
}, [pathname, sensitivePath])
|
|
73
76
|
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
if (!ready || sensitivePath || !preferences?.analytics || mode !== "ga4") return
|
|
79
|
+
// Configure GA4 in the same shared helper used by purchase/cart events.
|
|
80
|
+
// This avoids queued ecommerce hits running before the GA4 config command.
|
|
81
|
+
ensureDirectGa4Initialized(ga4Id, true)
|
|
82
|
+
}, [ready, sensitivePath, preferences?.analytics, mode, ga4Id])
|
|
83
|
+
|
|
74
84
|
if (!ready || sensitivePath) return null
|
|
75
85
|
|
|
76
|
-
const mode = analyticsTrackingMode(analytics)
|
|
77
86
|
const analyticsGranted = Boolean(preferences?.analytics)
|
|
78
87
|
const marketingGranted = Boolean(preferences?.marketing)
|
|
79
88
|
|
|
@@ -88,7 +97,6 @@ export function AnalyticsGate({
|
|
|
88
97
|
: loadDirectAds
|
|
89
98
|
? googleAds.conversion_id
|
|
90
99
|
: null
|
|
91
|
-
const configureGa4 = loadGa4
|
|
92
100
|
const configureAds = loadDirectAds
|
|
93
101
|
|
|
94
102
|
return (
|
|
@@ -101,12 +109,6 @@ export function AnalyticsGate({
|
|
|
101
109
|
/>
|
|
102
110
|
) : null}
|
|
103
111
|
|
|
104
|
-
{configureGa4 ? (
|
|
105
|
-
<Script id="core-ga4-config" strategy="afterInteractive">
|
|
106
|
-
{`gtag('js',new Date());gtag('config','${analytics.google_analytics.measurement_id}');`}
|
|
107
|
-
</Script>
|
|
108
|
-
) : null}
|
|
109
|
-
|
|
110
112
|
{configureAds ? (
|
|
111
113
|
<Script id="core-google-ads-config" strategy="afterInteractive">
|
|
112
114
|
{`gtag('config','${googleAds.conversion_id}',{'allow_ad_personalization_signals':${googleAds.remarketing_enabled ? "true" : "false"}});`}
|