@hszrdm/create-commerce 1.10.0 → 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/README.md +6 -0
- package/package.json +1 -1
- package/src/cli.mjs +20 -4
- package/src/upgrade.mjs +79 -4
- package/templates/backend/.env.example +8 -0
- package/templates/backend/package.json +2 -1
- package/templates/backend/scripts/commerce-instance-status.mjs +135 -0
- package/templates/backend/scripts/commerce-ops.mjs +61 -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/backend/src/scripts/sync-integration-runtime.ts +1 -0
- 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
|
@@ -3,11 +3,11 @@ import {
|
|
|
3
3
|
cpSync,
|
|
4
4
|
existsSync,
|
|
5
5
|
mkdirSync,
|
|
6
|
+
lstatSync,
|
|
6
7
|
readFileSync,
|
|
7
8
|
readdirSync,
|
|
8
|
-
statSync,
|
|
9
9
|
} from "node:fs"
|
|
10
|
-
import { dirname, isAbsolute, join, resolve } from "node:path"
|
|
10
|
+
import { dirname, isAbsolute, join, resolve, sep } from "node:path"
|
|
11
11
|
|
|
12
12
|
export const PORTABLE_ENV_KEYS = [
|
|
13
13
|
"MEDUSA_BACKEND_URL",
|
|
@@ -64,7 +64,16 @@ export function backendProjectDir(projectDir) {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
export function loadRuntimeEnv(projectDir, overrides = process.env) {
|
|
67
|
-
const
|
|
67
|
+
const appEnv = String(overrides.APP_ENV || "").trim() ||
|
|
68
|
+
(overrides.NODE_ENV === "production" ? "production" : "development")
|
|
69
|
+
const envName = appEnv === "production" ? ".env.production" :
|
|
70
|
+
appEnv === "staging" ? ".env.staging" : ".env"
|
|
71
|
+
const file = join(backendProjectDir(projectDir), envName)
|
|
72
|
+
// In deployed environments NEVER silently load development credentials,
|
|
73
|
+
// upload paths or encryption settings from backend/.env.
|
|
74
|
+
if (["production", "staging"].includes(appEnv) && !existsSync(file)) {
|
|
75
|
+
throw new Error("Hiányzik a környezet saját konfigurációja: " + file)
|
|
76
|
+
}
|
|
68
77
|
const fromFile = existsSync(file) ? parseEnv(readFileSync(file, "utf8")) : {}
|
|
69
78
|
const explicitOverrides = Object.fromEntries(
|
|
70
79
|
Object.entries(overrides).filter(([, value]) => value != null && String(value).trim() !== ""),
|
|
@@ -160,6 +169,12 @@ export function backupFileSources(projectDir, env) {
|
|
|
160
169
|
}
|
|
161
170
|
|
|
162
171
|
export function copyBackupSource(bundleDir, item) {
|
|
172
|
+
const sourceStat = lstatSync(item.source)
|
|
173
|
+
if (sourceStat.isSymbolicLink()) {
|
|
174
|
+
throw new Error("Symlink backup source not permitted: " + item.key)
|
|
175
|
+
}
|
|
176
|
+
if (sourceStat.isDirectory()) sha256Tree(item.source) // refuses nested symlinks
|
|
177
|
+
else if (!sourceStat.isFile()) throw new Error("Unsupported backup source: " + item.key)
|
|
163
178
|
const target = join(bundleDir, item.relative)
|
|
164
179
|
mkdirSync(dirname(target), { recursive: true })
|
|
165
180
|
cpSync(item.source, target, { recursive: true, force: true })
|
|
@@ -178,19 +193,79 @@ export function sha256Tree(path) {
|
|
|
178
193
|
return hash.digest("hex")
|
|
179
194
|
}
|
|
180
195
|
|
|
196
|
+
// Backup manifests are integrity metadata, not arbitrary read instructions.
|
|
197
|
+
// Restrict them to the known bundle schema and reject symlinks even within a
|
|
198
|
+
// checksum-covered directory; this guards dry-runs as well as real restores.
|
|
199
|
+
const ARTIFACT_KINDS = new Map([
|
|
200
|
+
["database.dump", "file"],
|
|
201
|
+
["portable-config.json", "file"],
|
|
202
|
+
["portable-config.env", "file"],
|
|
203
|
+
["webshop-bootstrap.json", "file"],
|
|
204
|
+
["files/integration-settings.enc", "file"],
|
|
205
|
+
["files/local-static", "directory"],
|
|
206
|
+
["files/file-upload-dir", "directory"],
|
|
207
|
+
])
|
|
208
|
+
const REQUIRED_ARTIFACTS = ["database.dump", "portable-config.json", "portable-config.env"]
|
|
209
|
+
|
|
181
210
|
export function verifyManifest(bundleDir, manifest) {
|
|
211
|
+
if (!manifest || !Array.isArray(manifest.artifacts) ||
|
|
212
|
+
manifest.database_format !== "postgres-custom") {
|
|
213
|
+
throw new Error("Érvénytelen Core backup manifest vagy adatbázis-formátum.")
|
|
214
|
+
}
|
|
182
215
|
const failures = []
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
216
|
+
const seen = new Set()
|
|
217
|
+
const root = resolve(bundleDir)
|
|
218
|
+
for (const artifact of manifest.artifacts) {
|
|
219
|
+
const name = artifact?.path
|
|
220
|
+
const expectedKind = ARTIFACT_KINDS.get(name)
|
|
221
|
+
if (typeof name !== "string" || !expectedKind ||
|
|
222
|
+
artifact.kind !== expectedKind ||
|
|
223
|
+
typeof artifact.sha256 !== "string" ||
|
|
224
|
+
!/^[0-9a-f]{64}$/.test(artifact.sha256) ||
|
|
225
|
+
seen.has(name)) {
|
|
226
|
+
failures.push("Érvénytelen/duplikált backup artifact: " + String(name))
|
|
227
|
+
continue
|
|
228
|
+
}
|
|
229
|
+
seen.add(name)
|
|
230
|
+
const target = resolve(root, name)
|
|
231
|
+
if (!target.startsWith(root + sep)) {
|
|
232
|
+
failures.push(name + ": érvénytelen célútvonal")
|
|
187
233
|
continue
|
|
188
234
|
}
|
|
189
|
-
|
|
190
|
-
|
|
235
|
+
// Reject symlinks in every path segment, including the leaf.
|
|
236
|
+
let unsafe = false
|
|
237
|
+
let current = root
|
|
238
|
+
for (const segment of name.split("/")) {
|
|
239
|
+
current = join(current, segment)
|
|
240
|
+
if (!existsSync(current)) {
|
|
241
|
+
failures.push(name + ": hiányzik")
|
|
242
|
+
unsafe = true
|
|
243
|
+
break
|
|
244
|
+
}
|
|
245
|
+
if (lstatSync(current).isSymbolicLink()) {
|
|
246
|
+
failures.push(name + ": szimbolikus link nem engedélyezett")
|
|
247
|
+
unsafe = true
|
|
248
|
+
break
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
if (unsafe) continue
|
|
252
|
+
if ((expectedKind === "file" && !lstatSync(target).isFile()) ||
|
|
253
|
+
(expectedKind === "directory" && !lstatSync(target).isDirectory())) {
|
|
254
|
+
failures.push(name + ": hibás fájltípus")
|
|
255
|
+
continue
|
|
256
|
+
}
|
|
257
|
+
try {
|
|
258
|
+
const actual = expectedKind === "directory" ? sha256Tree(target) : sha256File(target)
|
|
259
|
+
if (actual !== artifact.sha256) failures.push(name + ": checksum eltérés")
|
|
260
|
+
} catch (error) {
|
|
261
|
+
failures.push(name + ": " + (error instanceof Error ? error.message : String(error)))
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
for (const required of REQUIRED_ARTIFACTS) {
|
|
265
|
+
if (!seen.has(required)) failures.push(required + ": kötelező artifact hiányzik")
|
|
191
266
|
}
|
|
192
267
|
if (failures.length) {
|
|
193
|
-
throw new Error(
|
|
268
|
+
throw new Error("A backup integritásellenőrzése sikertelen:\n- " + failures.join("\n- "))
|
|
194
269
|
}
|
|
195
270
|
}
|
|
196
271
|
|
|
@@ -213,13 +288,18 @@ function hashDirectory(hash, root, current) {
|
|
|
213
288
|
for (const name of entries) {
|
|
214
289
|
const full = join(current, name)
|
|
215
290
|
const relative = full.slice(root.length + 1)
|
|
216
|
-
const stat =
|
|
291
|
+
const stat = lstatSync(full)
|
|
292
|
+
if (stat.isSymbolicLink()) {
|
|
293
|
+
throw new Error("Symlink not permitted in Core backup: " + relative)
|
|
294
|
+
}
|
|
217
295
|
if (stat.isDirectory()) {
|
|
218
296
|
hash.update(`D:${relative}\n`)
|
|
219
297
|
hashDirectory(hash, root, full)
|
|
220
298
|
} else if (stat.isFile()) {
|
|
221
299
|
hash.update(`F:${relative}:${stat.size}\n`)
|
|
222
300
|
hash.update(readFileSync(full))
|
|
301
|
+
} else {
|
|
302
|
+
throw new Error("Unsupported file type in Core backup: " + relative)
|
|
223
303
|
}
|
|
224
304
|
}
|
|
225
305
|
}
|
|
@@ -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" "$@"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "@hszrdm/core/scripts/sync-integration-runtime"
|
|
@@ -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
|
|