@hszrdm/create-commerce 1.3.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 CHANGED
@@ -16,7 +16,98 @@ The generator creates:
16
16
  - a publishable storefront API key linked to the Sales Channel;
17
17
  - the first HSZRDM Commerce admin user;
18
18
  - backend/storefront typecheck, test and build verification;
19
- - Git initialization with generated build artifacts ignored.
19
+ - Git initialization with generated build artifacts ignored;
20
+ - production deployment, backup and restore assets.
21
+
22
+ Generated project structure includes:
23
+
24
+ ```text
25
+ my-shop/
26
+ ├── backend/
27
+ ├── storefront/
28
+ ├── deploy/
29
+ │ ├── install.sh
30
+ │ ├── deploy.sh
31
+ │ ├── backup.sh
32
+ │ └── restore.sh
33
+ ├── ecosystem.config.cjs
34
+ ├── docker-compose.yml
35
+ ├── hszrdm-commerce.json
36
+ ├── package.json
37
+ └── README.md
38
+ ```
39
+
40
+ The `deploy/` directory and `ecosystem.config.cjs` are materialized automatically during the first `npm install`. If the generator is run with `--skip-install`, running `npm install` later creates them.
41
+
42
+ ## Production commands
43
+
44
+ ### Fresh server install
45
+
46
+ On a new VPS/server, `deploy/install.sh` can bootstrap the production environment automatically.
47
+
48
+ ```bash
49
+ bash deploy/install.sh
50
+ ```
51
+
52
+ If `backend/.env` does not exist, the installer:
53
+
54
+ 1. copies the canonical `backend/.env.example` to `backend/.env`;
55
+ 2. reads project identity from `hszrdm-commerce.json`;
56
+ 3. asks for PostgreSQL, Redis, public backend URL and public storefront URL;
57
+ 4. generates fresh JWT, cookie, integration-encryption and shipping-webhook secrets;
58
+ 5. fills store identity, CORS, SEO and default project e-mail values;
59
+ 6. creates `storefront/.env.local` from the storefront env example;
60
+ 7. runs `env:verify`, migrations and Core bootstrap;
61
+ 8. creates a Store API publishable key when the storefront does not already have one;
62
+ 9. builds and starts/reloads the apps through PM2;
63
+ 10. runs backend/storefront healthchecks.
64
+
65
+ If `backend/.env` or `storefront/.env.local` already exists, the installer preserves them instead of regenerating secrets.
66
+
67
+ For non-interactive/server automation, supply the server-specific values through:
68
+
69
+ ```bash
70
+ HSZRDM_INSTALL_DATABASE_URL='postgres://...' \
71
+ HSZRDM_INSTALL_REDIS_URL='redis://...' \
72
+ HSZRDM_INSTALL_BACKEND_URL='https://api.example.com' \
73
+ HSZRDM_INSTALL_STOREFRONT_URL='https://example.com' \
74
+ HSZRDM_INSTALL_UPLOAD_DIR='/var/lib/hszrdm-commerce/my-shop/uploads' \
75
+ bash deploy/install.sh
76
+ ```
77
+
78
+ `HSZRDM_INSTALL_UPLOAD_DIR` is optional. Its default is `/var/lib/hszrdm-commerce/<project-slug>/uploads`.
79
+
80
+ ### Normal deployment
81
+
82
+ ```bash
83
+ bash deploy/deploy.sh
84
+ ```
85
+
86
+ The deploy script creates a backup first, pulls with `git pull --ff-only`, installs exact dependencies, verifies the env contract, runs migrations/Core init, builds, reloads PM2 and performs healthchecks.
87
+
88
+ ### Manual backup
89
+
90
+ ```bash
91
+ bash deploy/backup.sh
92
+ ```
93
+
94
+ ### Restore an existing webshop
95
+
96
+ ```bash
97
+ bash deploy/restore.sh /path/to/hszrdm-commerce-YYYYMMDDTHHMMSSZ.tar.gz --yes
98
+ ```
99
+
100
+ For an existing webshop moved to another VPS, use **restore**, not a fresh env bootstrap. Restore brings back the original backend/storefront env files, database, encrypted Core runtime state and uploads. This preserves encryption keys and existing integration credentials.
101
+
102
+ Backups contain the PostgreSQL dump, backend/storefront environment files, encrypted Core runtime state and uploaded files when present. Backup archives therefore contain secrets and customer data and must be stored securely.
103
+
104
+ The default local backup retention is 5 archives. It can be changed with:
105
+
106
+ ```bash
107
+ HSZRDM_BACKUP_RETENTION=10 bash deploy/backup.sh
108
+ ```
109
+
110
+ A different backup directory can be supplied with `HSZRDM_BACKUP_DIR`.
20
111
 
21
112
  ## PostgreSQL and Redis
22
113
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hszrdm/create-commerce",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "Create a complete HSZRDM Commerce webshop project.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",
@@ -1,13 +1,15 @@
1
1
  # -----------------------------------------------------------------------------
2
- # HSZRDM COMMERCE - environment
2
+ # HSZRDM COMMERCE - canonical environment template
3
3
  # -----------------------------------------------------------------------------
4
- # APP_ENV is optional. Empty/unset means the Core follows NODE_ENV automatically.
5
- # Use an explicit override only when you intentionally need it.
6
- # APP_ENV=development
7
- # NODE_ENV=development
8
- # Never enable this in a normal production deployment. It only exists for an
9
- # explicitly approved temporary sandbox runtime.
10
- # ALLOW_PRODUCTION_SANDBOX=false
4
+ # This is the single source of truth for environment variables used by the Core,
5
+ # the reference backend and generated shops.
6
+ #
7
+ # Required for every shop: DATABASE_URL, JWT_SECRET, COOKIE_SECRET,
8
+ # STORE_CORS, ADMIN_CORS, AUTH_CORS.
9
+ #
10
+ # External integrations are preferably configured in HSZRDM Commerce Admin
11
+ # (Settings -> Integrációk). Environment variables below are fallback/bootstrap
12
+ # options only. Do not copy unused integration secrets into production.
11
13
 
12
14
  # -----------------------------------------------------------------------------
13
15
  # Runtime / infrastructure
@@ -17,49 +19,37 @@ REDIS_URL=redis://localhost:6379
17
19
  MEDUSA_BACKEND_URL=http://localhost:9000
18
20
  STOREFRONT_URL=http://localhost:3000
19
21
  MEDUSA_ADMIN_PATH=/app
20
-
21
- # Local development can leave this empty. Production requires an absolute,
22
- # durable path, for example /var/lib/hszrdm-commerce/uploads.
23
22
  FILE_UPLOAD_DIR=
24
23
  RELEASE_SHA=development
24
+ # APP_ENV=development
25
+ # NODE_ENV=development
26
+ # ALLOW_PRODUCTION_SANDBOX=false
25
27
 
26
28
  # -----------------------------------------------------------------------------
27
- # Security
29
+ # Required security
28
30
  # -----------------------------------------------------------------------------
29
31
  JWT_SECRET=replace-with-at-least-32-random-characters
30
32
  COOKIE_SECRET=replace-with-at-least-32-random-characters
31
-
32
33
  STORE_CORS=http://localhost:3000
33
34
  ADMIN_CORS=http://localhost:9000,http://localhost:7001
34
35
  AUTH_CORS=http://localhost:3000,http://localhost:9000,http://localhost:7001
35
36
 
36
- # Settings -> Integrations encrypts provider secrets in the database and in the
37
- # runtime snapshot. Use a separate, stable key in production.
37
+ # Encrypts secrets stored by Settings -> Integrációk.
38
38
  INTEGRATION_SETTINGS_ENCRYPTION_KEY=replace-with-at-least-32-random-characters
39
- # Optional explicit snapshot path. Empty = .core/ locally, or the durable upload
40
- # directory parent when FILE_UPLOAD_DIR is configured.
41
39
  INTEGRATION_SETTINGS_FILE=
42
-
43
- # Shared secret for supported inbound shipping callbacks (currently FOXPOST/GLS).
44
- # Required only when an integration using these callbacks is enabled.
40
+ # Shared inbound shipping callback secret. Required only for enabled callback-based providers.
45
41
  SHIPPING_WEBHOOK_SECRET=
46
42
 
47
43
  # -----------------------------------------------------------------------------
48
- # Store identity
44
+ # Store identity / localization
49
45
  # -----------------------------------------------------------------------------
50
46
  STORE_NAME=Example Store
51
47
  STORE_SLUG=example-store
52
- # Medusa content locale. Native Translation Module is enabled by HSZRDM Core.
53
48
  STORE_LOCALE=hu-HU
54
- # Comma-separated Store locales provisioned by `core:init`.
55
49
  STORE_SUPPORTED_LOCALES=hu-HU,en-US
56
50
  STORE_DEFAULT_CURRENCY=HUF
57
- # Commercial country/region context. This is intentionally separate from locale.
58
51
  STORE_DEFAULT_COUNTRY=HU
59
- # Direct/reference admin customization fallback.
60
52
  VITE_ADMIN_BRAND_NAME=HSZRDM Commerce
61
- # @hszrdm/core is a Medusa plugin, so plugin admin environment variables are
62
- # provided by the host application with the PLUGIN_ prefix.
63
53
  PLUGIN_ADMIN_BRAND_NAME=HSZRDM Commerce
64
54
 
65
55
  ORDER_EMAIL=orders@example.com
@@ -68,25 +58,39 @@ BILLING_EMAIL=billing@example.com
68
58
  SYSTEM_EMAIL=system@example.com
69
59
 
70
60
  # -----------------------------------------------------------------------------
71
- # Email Center / transactional email / newsletter campaigns
61
+ # HSZRDM Store MCP - optional read-only AI access
72
62
  # -----------------------------------------------------------------------------
73
- # Shared template, campaign and delivery layer on top of Medusa Notification.
74
- EMAIL_CENTER_ENABLED=true
63
+ # Empty token = MCP disabled.
64
+ HSZRDM_MCP_TOKEN=
65
+ HSZRDM_MCP_ALLOWED_ORIGINS=
66
+ HSZRDM_MCP_ALLOWED_HOSTS=
67
+ HSZRDM_MCP_RATE_LIMIT_PER_MINUTE=120
75
68
 
76
- # Raw e-mail delivery provider. Supported: sendgrid, resend. Leave blank during
77
- # local development to keep Medusa's local notification provider on e-mail.
78
- # Generic credentials override provider-specific legacy variables.
69
+ # -----------------------------------------------------------------------------
70
+ # AI-assisted translations
71
+ # -----------------------------------------------------------------------------
72
+ # Suggestions are generated by AI; approved values remain in Medusa Translation.
73
+ AI_TRANSLATION_ENABLED=false
74
+ AI_TRANSLATION_PROVIDER=openai
75
+ AI_TRANSLATION_MODEL=gpt-6-astra
76
+ OPENAI_API_KEY=
77
+ OPENAI_BASE_URL=https://api.openai.com/v1
78
+
79
+ # -----------------------------------------------------------------------------
80
+ # Email Center / transactional email
81
+ # -----------------------------------------------------------------------------
82
+ EMAIL_CENTER_ENABLED=true
83
+ # Supported provider values: sendgrid, resend. Empty = local Medusa provider.
79
84
  EMAIL_PROVIDER=
80
85
  EMAIL_API_KEY=
81
86
  EMAIL_FROM=
82
87
  EMAIL_REPLY_TO=
83
- # Provider-specific fallbacks if EMAIL_API_KEY / EMAIL_FROM are left empty.
88
+ # Optional provider-specific fallbacks.
84
89
  RESEND_API_KEY=
85
90
  RESEND_FROM_EMAIL=
91
+ SENDGRID_API_KEY=
92
+ SENDGRID_FROM_EMAIL=
86
93
 
87
- # Optional per-event overrides. Empty means Email Center defaults apply; with
88
- # EMAIL_CENTER_ENABLED=true the customer/order transactional contracts are on.
89
- # Set a specific switch to false to disable only that event.
90
94
  EMAIL_CUSTOMER_WELCOME_ENABLED=
91
95
  EMAIL_REGISTRATION_VERIFICATION_ENABLED=
92
96
  EMAIL_PASSWORD_RESET_ENABLED=
@@ -101,51 +105,53 @@ EMAIL_SHIPMENT_CREATED_ENABLED=
101
105
  EMAIL_ORDER_CANCELED_ENABLED=
102
106
  EMAIL_PAYMENT_REFUNDED_ENABLED=
103
107
 
104
- # Optional public logo URL shown in the shared email layout.
105
108
  EMAIL_LOGO_URL=
106
- # Open/click tracking is signed. Empty EMAIL_TRACKING_SECRET falls back to the
107
- # generated COOKIE_SECRET, then JWT_SECRET. Production has no weak built-in key.
108
109
  EMAIL_TRACKING_ENABLED=true
109
110
  EMAIL_TRACKING_BASE_URL=
110
111
  EMAIL_TRACKING_SECRET=
111
- # Optional secret for POST /hooks/email/status. A provider-specific adapter can
112
- # normalize delivered/bounced/failed callbacks to this internal endpoint.
113
112
  EMAIL_WEBHOOK_SECRET=
114
113
 
115
114
  # -----------------------------------------------------------------------------
116
- # Customer after-sales self-service
115
+ # Newsletter
116
+ # -----------------------------------------------------------------------------
117
+ NEWSLETTER_ENABLED=true
118
+ NEWSLETTER_DOUBLE_OPT_IN=false
119
+ NEWSLETTER_EMAIL_ENABLED=true
120
+ NEWSLETTER_CONSENT_VERSION=1
121
+ NEWSLETTER_CONSENT_URL=
122
+ NEWSLETTER_CONFIRM_TTL_HOURS=72
123
+ NEWSLETTER_CONFIRM_PATH=/newsletter/confirm
124
+ NEWSLETTER_UNSUBSCRIBE_PATH=/newsletter/unsubscribe
125
+ NEWSLETTER_TOKEN_SECRET=
126
+
127
+ # -----------------------------------------------------------------------------
128
+ # Product reviews
129
+ # -----------------------------------------------------------------------------
130
+ PRODUCT_REVIEWS_ENABLED=true
131
+ # false = any signed-in customer can review; true = verified purchase required.
132
+ PRODUCT_REVIEWS_REQUIRE_VERIFIED_PURCHASE=false
133
+
134
+ # -----------------------------------------------------------------------------
135
+ # Customer after-sales
117
136
  # -----------------------------------------------------------------------------
118
- # These switches expose customer endpoints backed by Medusa's native
119
- # return/exchange/claim workflows. They do not auto-approve or auto-refund.
120
137
  AFTER_SALES_ENABLED=true
121
138
  AFTER_SALES_RETURNS_ENABLED=true
122
139
  AFTER_SALES_EXCHANGES_ENABLED=true
123
140
  AFTER_SALES_CLAIMS_ENABLED=true
124
-
125
- # Optional merchant policy page and text inserted into approved return e-mails.
126
- # The Core intentionally does not hard-code legal return windows or eligibility.
127
141
  AFTER_SALES_POLICY_URL=
128
142
  AFTER_SALES_RETURN_INSTRUCTIONS=
129
143
 
130
144
  # -----------------------------------------------------------------------------
131
- # RFQ / quote requests
145
+ # Quote requests / RFQ
132
146
  # -----------------------------------------------------------------------------
133
- # Generic B2B / custom-product quote layer. The storefront may build any design
134
- # on top of /store/quote-requests and /store/quote-requests/config.
135
147
  QUOTE_REQUESTS_ENABLED=true
136
148
  QUOTE_EMAIL_ENABLED=true
137
- # One or more merchant recipients, separated with comma or semicolon.
138
149
  QUOTE_ADMIN_EMAILS=
139
- # Optional JSON array of additional fields exposed by the Core quote config.
140
- # Supported types: text, textarea, number, boolean, select.
141
- # Example:
142
- # QUOTE_EXTRA_FIELDS_JSON=[{"key":"delivery_deadline","label":"Kért szállítási határidő","type":"text","required":false},{"key":"industry","label":"Iparág","type":"select","required":false,"options":["Élelmiszer","Ipar","Kereskedelem"]}]
143
150
  QUOTE_EXTRA_FIELDS_JSON=
144
151
 
145
152
  # -----------------------------------------------------------------------------
146
- # Lead / web form backend
153
+ # Leads / forms
147
154
  # -----------------------------------------------------------------------------
148
- # Generic backend for contact, callback, B2B lead and project-specific forms.
149
155
  LEADS_ENABLED=true
150
156
  LEAD_EMAIL_ENABLED=true
151
157
  LEAD_CUSTOMER_EMAIL_ENABLED=false
@@ -153,38 +159,24 @@ LEAD_ADMIN_EMAILS=
153
159
  LEAD_HONEYPOT_FIELD=website
154
160
  LEAD_RATE_LIMIT_MAX=8
155
161
  LEAD_RATE_LIMIT_WINDOW_SECONDS=600
156
- # Optional dedicated HMAC secret for anonymized request fingerprints. If empty,
157
- # COOKIE_SECRET is used. Raw IP addresses are never persisted by the lead module.
158
162
  LEAD_SPAM_HASH_SECRET=
159
- # Optional Cloudflare Turnstile. Both values are required to enable it.
160
163
  LEAD_TURNSTILE_SITE_KEY=
161
164
  LEAD_TURNSTILE_SECRET_KEY=
162
165
  LEAD_PRIVACY_POLICY_VERSION=1
163
166
  LEAD_PRIVACY_POLICY_URL=
164
167
  LEAD_PRIVACY_POLICY_LABEL=Elfogadom az adatkezelési tájékoztatót.
165
- # Optional JSON array defining one or more forms and custom fields.
166
- # Empty = built-in `contact` form with name, email and message required.
167
168
  LEAD_FORMS_JSON=
168
169
 
169
170
  # -----------------------------------------------------------------------------
170
- # CMS / blog engine
171
+ # CMS / blog
171
172
  # -----------------------------------------------------------------------------
172
- # Generic content engine for blog posts, pages, guides, news and custom types.
173
173
  CMS_ENABLED=true
174
- # Empty = STORE_LOCALE, then hu-HU fallback.
175
174
  CMS_DEFAULT_LOCALE=
176
- # Optional JSON array of content types shown to storefront/admin integrations.
177
- # Content entries still store a free-form content_type, so projects can add
178
- # project-specific types without changing the Core schema.
179
- # Example:
180
- # CMS_CONTENT_TYPES_JSON=[{"key":"blog_post","label":"Blogbejegyzés"},{"key":"page","label":"Oldal"},{"key":"guide","label":"Tudástár"}]
181
175
  CMS_CONTENT_TYPES_JSON=
182
176
 
183
177
  # -----------------------------------------------------------------------------
184
- # Technical SEO - optional overrides
178
+ # Technical SEO
185
179
  # -----------------------------------------------------------------------------
186
- # Country remains the commercial region country. Locale controls public language
187
- # and localized URL segments independently.
188
180
  SEO_STOREFRONT_URL=
189
181
  SEO_STORE_NAME=
190
182
  SEO_ORGANIZATION_NAME=
@@ -193,29 +185,204 @@ SEO_DEFAULT_COUNTRY=
193
185
  SEO_DEFAULT_CURRENCY=
194
186
  SEO_DEFAULT_LOCALE=hu
195
187
  SEO_SUPPORTED_LOCALES=hu,en
196
-
197
- # Optional explicit Medusa region / sales channel for Product Offer JSON-LD.
198
188
  SEO_REGION_ID=
199
189
  SEO_SALES_CHANNEL_ID=
200
-
201
- # Defaults generate /hu/termekek/... and /en/products/... from the same template.
202
190
  SEO_PRODUCT_PATH_TEMPLATE=/{locale}/{products_segment}/{handle}
203
191
  SEO_CATEGORY_PATH_TEMPLATE=/{locale}/{categories_segment}/{handle}
204
-
205
- # Empty = enabled only in NODE_ENV=production. Set explicitly only when needed.
206
192
  SEO_ALLOW_INDEXING=
207
- # Extra comma-separated Disallow paths. Core defaults already include both HU and
208
- # EN account/cart/checkout paths plus the legacy aliases.
209
193
  SEO_ROBOTS_DISALLOW=
210
194
 
211
195
  # -----------------------------------------------------------------------------
212
- # External integrations
196
+ # Payment fallback/bootstrap settings
197
+ # Prefer Admin -> Settings -> Integrációk.
213
198
  # -----------------------------------------------------------------------------
214
- # Do NOT copy every provider secret into the main .env.
215
- # Configure integrations in HSZRDM Commerce Admin: Settings -> Integrációk.
216
- #
217
- # Legacy/bootstrap/fallback variable reference:
218
- # apps/backend/.env.integrations.example
219
- #
220
- # The encrypted runtime snapshot is loaded before provider configuration and
221
- # overrides matching fallback env values.
199
+ STRIPE_ENABLED=false
200
+ STRIPE_API_KEY=
201
+ STRIPE_WEBHOOK_SECRET=
202
+ STRIPE_WEBHOOK_URL=http://localhost:9000/hooks/payment/stripe_stripe
203
+
204
+ SIMPLEPAY_ENABLED=false
205
+ SIMPLEPAY_SANDBOX=true
206
+ SIMPLEPAY_HUF_MERCHANT=
207
+ SIMPLEPAY_HUF_SECRET_KEY=
208
+ SIMPLEPAY_EUR_MERCHANT=
209
+ SIMPLEPAY_EUR_SECRET_KEY=
210
+ SIMPLEPAY_USD_MERCHANT=
211
+ SIMPLEPAY_USD_SECRET_KEY=
212
+ SIMPLEPAY_RETURN_BASE_URL=http://localhost:9000/store/simplepay/back
213
+ SIMPLEPAY_STOREFRONT_URL=http://localhost:3000
214
+ SIMPLEPAY_TIMEOUT_MS=15000
215
+
216
+ BANK_TRANSFER_ENABLED=false
217
+ BANK_TRANSFER_BANK_NAME=
218
+ BANK_TRANSFER_ACCOUNT_HOLDER=
219
+ BANK_TRANSFER_ACCOUNT_NUMBER=
220
+ BANK_TRANSFER_IBAN=
221
+ BANK_TRANSFER_BIC=
222
+ BANK_TRANSFER_DUE_DAYS=3
223
+ BANK_TRANSFER_REFERENCE_PREFIX=
224
+ BANK_TRANSFER_EMAIL_ENABLED=true
225
+ BANK_TRANSFER_BILLINGO_PROFORMA=false
226
+ BANK_TRANSFER_BILLINGO_PROFORMA_SEND=true
227
+
228
+ # -----------------------------------------------------------------------------
229
+ # Billingo fallback/bootstrap settings
230
+ # -----------------------------------------------------------------------------
231
+ BILLINGO_ENABLED=false
232
+ BILLINGO_API_URL=https://api.billingo.hu/v3
233
+ BILLINGO_API_KEY=
234
+ BILLINGO_DOCUMENT_BLOCK_ID=
235
+ BILLINGO_BANK_ACCOUNT_ID=
236
+ BILLINGO_PAYMENT_METHOD=stripe
237
+ BILLINGO_LANGUAGE=hu
238
+ BILLINGO_ELECTRONIC=true
239
+ BILLINGO_DUE_DAYS=0
240
+ BILLINGO_UNIT=db
241
+ BILLINGO_TIMEOUT_MS=15000
242
+ BILLINGO_AUTO_INVOICE=true
243
+ BILLINGO_AUTO_SEND=true
244
+ BILLINGO_AUTO_CANCEL_ON_ORDER_CANCELED=false
245
+ BILLINGO_INVOICE_TRIGGER=payment_captured
246
+
247
+ # -----------------------------------------------------------------------------
248
+ # Shipping fallback/bootstrap settings
249
+ # Prefer Admin -> Settings -> Integrációk.
250
+ # -----------------------------------------------------------------------------
251
+ FOXPOST_ENABLED=false
252
+ FOXPOST_API_URL=
253
+ FOXPOST_API_USERNAME=
254
+ FOXPOST_API_PASSWORD=
255
+ FOXPOST_API_KEY=
256
+ FOXPOST_SANDBOX=true
257
+ FOXPOST_LOCKER_FEED_URL=https://cdn.foxpost.hu/foxplus.json
258
+ FOXPOST_LOCKER_PRICE_HUF=1290
259
+ FOXPOST_HOME_DELIVERY_PRICE_HUF=1990
260
+ FOXPOST_FREE_SHIPPING_THRESHOLD_HUF=
261
+ FOXPOST_TIMEOUT_MS=10000
262
+
263
+ GLS_ENABLED=false
264
+ GLS_API_URL=https://api.test.mygls.hu
265
+ GLS_USERNAME=
266
+ GLS_PASSWORD=
267
+ GLS_CLIENT_NUMBER=
268
+ GLS_SANDBOX=true
269
+ GLS_DELIVERY_POINTS_URL=https://map.gls-hungary.com/data/deliveryPoints/hu.json
270
+ GLS_POINT_PRICE_HUF=1490
271
+ GLS_HOME_DELIVERY_PRICE_HUF=1990
272
+ GLS_FREE_SHIPPING_THRESHOLD_HUF=
273
+ GLS_TIMEOUT_MS=15000
274
+ GLS_PRINTER_TYPE=A4_2x2
275
+ GLS_WEBSHOP_ENGINE=HSZRDM Commerce
276
+ GLS_PICKUP_NAME=Example Store
277
+ GLS_PICKUP_STREET=
278
+ GLS_PICKUP_HOUSE_NUMBER=
279
+ GLS_PICKUP_HOUSE_NUMBER_INFO=
280
+ GLS_PICKUP_CITY=
281
+ GLS_PICKUP_POSTAL_CODE=
282
+ GLS_PICKUP_COUNTRY_CODE=HU
283
+ GLS_PICKUP_CONTACT_NAME=
284
+ GLS_PICKUP_PHONE=
285
+ GLS_PICKUP_EMAIL=
286
+
287
+ PACKETA_ENABLED=false
288
+ PACKETA_API_URL=https://www.zasilkovna.cz/api/rest
289
+ PACKETA_API_KEY=
290
+ PACKETA_API_PASSWORD=
291
+ PACKETA_SENDER_INDICATION=
292
+ PACKETA_HOME_CARRIER_ID=
293
+ PACKETA_POINT_PRICE_HUF=1290
294
+ PACKETA_HOME_DELIVERY_PRICE_HUF=1990
295
+ PACKETA_FREE_SHIPPING_THRESHOLD_HUF=
296
+ PACKETA_TIMEOUT_MS=15000
297
+ PACKETA_DEFAULT_WEIGHT_KG=1
298
+ PACKETA_LABEL_FORMAT=A6 on A6
299
+ PACKETA_LANGUAGE=hu
300
+
301
+ DPD_ENABLED=false
302
+ DPD_SANDBOX=true
303
+ DPD_API_URL=
304
+ DPD_TOKEN=
305
+ DPD_BU_CODE=
306
+ DPD_CUSTOMER_ID=
307
+ DPD_SENDER_ADDRESS_ID=
308
+ DPD_HOME_SERVICE_CODE=
309
+ DPD_COD_PAYMENT_TYPE=Cash
310
+ DPD_PUDO_SOURCE=disabled
311
+ DPD_PUDO_SERVICE_CODE=
312
+ DPD_PUDO_LOCATOR_URL=
313
+ DPD_PUDO_DELIS_ID=
314
+ DPD_PUDO_PASSWORD=
315
+ DPD_PUDO_MESSAGE_LANGUAGE=en_US
316
+ DPD_POINT_PRICE_HUF=1490
317
+ DPD_HOME_DELIVERY_PRICE_HUF=1990
318
+ DPD_FREE_SHIPPING_THRESHOLD_HUF=
319
+ DPD_TIMEOUT_MS=15000
320
+ DPD_DEFAULT_WEIGHT_KG=1
321
+ DPD_LABEL_SIZE=A6
322
+ DPD_PRINT_FORMAT=PDF
323
+ DPD_LABEL_DPI=203
324
+
325
+ MPL_ENABLED=false
326
+ MPL_SANDBOX=true
327
+ MPL_API_URL=
328
+ MPL_TRACKING_API_URL=
329
+ MPL_TOKEN_URL=
330
+ MPL_API_KEY=
331
+ MPL_API_SECRET=
332
+ MPL_AGREEMENT=
333
+ MPL_ACCOUNT_NO=
334
+ MPL_SENDER_NAME=Example Store
335
+ MPL_SENDER_EMAIL=orders@example.com
336
+ MPL_SENDER_PHONE=
337
+ MPL_SENDER_POST_CODE=
338
+ MPL_SENDER_CITY=
339
+ MPL_SENDER_ADDRESS=
340
+ MPL_DEVELOPER=HSZRDM Commerce
341
+ MPL_BASIC_SERVICE_CODE=
342
+ MPL_EXTRA_SERVICES=
343
+ MPL_PAYMENT_MODE=
344
+ MPL_TAG=
345
+ MPL_HOME_DELIVERY_MODE=HA
346
+ MPL_POINT_PRICE_HUF=1290
347
+ MPL_HOME_DELIVERY_PRICE_HUF=1990
348
+ MPL_FREE_SHIPPING_THRESHOLD_HUF=
349
+ MPL_TIMEOUT_MS=15000
350
+ MPL_DEFAULT_WEIGHT_KG=1
351
+ MPL_LABEL_TYPE=A6
352
+ MPL_PACKAGE_RETENTION=5
353
+ MPL_TRACKING_ENABLED=false
354
+ MPL_TRACKING_LANGUAGE=hu
355
+
356
+ # -----------------------------------------------------------------------------
357
+ # Product feeds / trust widgets - optional
358
+ # -----------------------------------------------------------------------------
359
+ GOOGLE_MERCHANT_ENABLED=false
360
+ GOOGLE_MERCHANT_COUNTRY_CODE=HU
361
+ GOOGLE_MERCHANT_CURRENCY_CODE=HUF
362
+ GOOGLE_MERCHANT_LOCALE=hu-HU
363
+ GOOGLE_MERCHANT_STOREFRONT_URL=
364
+ GOOGLE_MERCHANT_PRODUCT_PATH_TEMPLATE=/{locale}/{products_segment}/{handle}?v_id={variant_id}
365
+ GOOGLE_MERCHANT_SALES_CHANNEL_ID=
366
+ GOOGLE_MERCHANT_FEED_TITLE=
367
+ GOOGLE_MERCHANT_FEED_DESCRIPTION=
368
+ GOOGLE_MERCHANT_DEFAULT_BRAND=
369
+ GOOGLE_MERCHANT_DEFAULT_CONDITION=new
370
+ GOOGLE_MERCHANT_INCLUDE_OUT_OF_STOCK=true
371
+
372
+ ARUKERESO_ENABLED=false
373
+ ARUKERESO_STOREFRONT_URL=
374
+ ARUKERESO_PRODUCT_PATH_TEMPLATE=/hu/termekek/{handle}?v_id={variant_id}
375
+ ARUKERESO_SALES_CHANNEL_ID=
376
+ ARUKERESO_DEFAULT_MANUFACTURER=
377
+ ARUKERESO_USE_SKU_AS_PRODUCT_NUMBER=false
378
+ ARUKERESO_INCLUDE_OUT_OF_STOCK=true
379
+ ARUKERESO_DEFAULT_DELIVERY_TIME=
380
+ ARUKERESO_DEFAULT_DELIVERY_COST=
381
+
382
+ FOGYASZTOBARAT_ENABLED=false
383
+ FOGYASZTOBARAT_DATA_ID=
384
+
385
+ # -----------------------------------------------------------------------------
386
+ # Generator only (not used by a running shop)
387
+ # -----------------------------------------------------------------------------
388
+ # HSZRDM_MIN_FREE_GB=8
@@ -3,12 +3,14 @@
3
3
  "version": "0.0.0",
4
4
  "private": true,
5
5
  "scripts": {
6
+ "postinstall": "node ./scripts/materialize-production.mjs",
6
7
  "prepare:project": "node ./scripts/prepare-project.mjs",
8
+ "env:verify": "node ./scripts/verify-env-contract.mjs",
7
9
  "dev": "npm run prepare:project && medusa develop",
8
10
  "build": "npm run prepare:project && NODE_ENV=production medusa build",
9
11
  "verify:build": "APP_ENV=test npm run build",
10
12
  "start": "medusa start",
11
- "typecheck": "npm run prepare:project && tsc --noEmit",
13
+ "typecheck": "npm run env:verify && npm run prepare:project && tsc --noEmit",
12
14
  "core:init": "npm run prepare:project && medusa exec ./src/scripts/core-init.ts",
13
15
  "storefront:key": "npm run prepare:project && medusa exec ./src/scripts/create-storefront-key.ts",
14
16
  "bootstrap:assert": "npm run prepare:project && medusa exec ./src/scripts/verify-bootstrap.ts",
@@ -17,7 +19,7 @@
17
19
  "start:prod": "cd .medusa/server && medusa start"
18
20
  },
19
21
  "dependencies": {
20
- "@hszrdm/core": "1.1.0",
22
+ "@hszrdm/core": "1.4.0",
21
23
  "@medusajs/admin-sdk": "2.21.2",
22
24
  "@medusajs/cli": "2.21.2",
23
25
  "@medusajs/draft-order": "2.21.2",
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { chmodSync, copyFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs"
4
+ import { dirname, join, resolve } from "node:path"
5
+ import { fileURLToPath } from "node:url"
6
+
7
+ const backendRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..")
8
+ const root = resolve(backendRoot, "..")
9
+ const metadataPath = join(root, "hszrdm-commerce.json")
10
+ const assetsDir = join(backendRoot, "scripts", "production-assets")
11
+
12
+ // The starter itself may be installed in the Core monorepo. Only materialize
13
+ // production assets inside an actual generated client project.
14
+ if (!existsSync(metadataPath)) process.exit(0)
15
+
16
+ const metadata = JSON.parse(readFileSync(metadataPath, "utf8"))
17
+ const slug = String(metadata?.project?.slug || "hszrdm-commerce").trim() || "hszrdm-commerce"
18
+ const deployDir = join(root, "deploy")
19
+ mkdirSync(deployDir, { recursive: true })
20
+
21
+ for (const name of ["install.sh", "deploy.sh", "backup.sh", "restore.sh"]) {
22
+ const source = join(assetsDir, name)
23
+ const target = join(deployDir, name)
24
+ if (!existsSync(source)) throw new Error(`Missing production asset: ${source}`)
25
+ if (!existsSync(target)) copyFileSync(source, target)
26
+ try { chmodSync(target, 0o755) } catch {}
27
+ }
28
+
29
+ const ecosystemSource = join(assetsDir, "ecosystem.config.cjs.tpl")
30
+ const ecosystemTarget = join(root, "ecosystem.config.cjs")
31
+ if (!existsSync(ecosystemSource)) throw new Error(`Missing production asset: ${ecosystemSource}`)
32
+ if (!existsSync(ecosystemTarget)) {
33
+ const source = readFileSync(ecosystemSource, "utf8")
34
+ writeFileSync(ecosystemTarget, source.replaceAll("__HSZRDM_SLUG__", slug), "utf8")
35
+ }
36
+
37
+ console.log("✅ Production deploy assets are available in deploy/ and ecosystem.config.cjs")
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env bash
2
+ set -Eeuo pipefail
3
+
4
+ ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
5
+ cd "$ROOT"
6
+
7
+ log() { printf '\n==> %s\n' "$*"; }
8
+ fail() { printf '\nERROR: %s\n' "$*" >&2; exit 1; }
9
+ need() { command -v "$1" >/dev/null 2>&1 || fail "Missing required command: $1"; }
10
+ env_value() {
11
+ local file="$1" key="$2"
12
+ sed -n "s/^${key}=//p" "$file" | head -n 1
13
+ }
14
+
15
+ need pg_dump
16
+ need tar
17
+
18
+ [[ -f backend/.env ]] || fail "backend/.env is missing"
19
+ DATABASE_URL="$(env_value backend/.env DATABASE_URL)"
20
+ [[ -n "$DATABASE_URL" ]] || fail "DATABASE_URL is missing from backend/.env"
21
+
22
+ STAMP="$(date -u +%Y%m%dT%H%M%SZ)"
23
+ BACKUP_DIR="${HSZRDM_BACKUP_DIR:-$ROOT/backups}"
24
+ RETENTION="${HSZRDM_BACKUP_RETENTION:-5}"
25
+ mkdir -p "$BACKUP_DIR"
26
+ chmod 700 "$BACKUP_DIR" || true
27
+ TMP="$(mktemp -d)"
28
+ trap 'rm -rf "$TMP"' EXIT
29
+ mkdir -p "$TMP/config" "$TMP/runtime"
30
+
31
+ log "Database backup"
32
+ pg_dump --format=custom --no-owner --file "$TMP/database.dump" "$DATABASE_URL"
33
+
34
+ cp backend/.env "$TMP/config/backend.env"
35
+ [[ -f storefront/.env.local ]] && cp storefront/.env.local "$TMP/config/storefront.env.local"
36
+ [[ -f .env.docker ]] && cp .env.docker "$TMP/config/env.docker"
37
+ [[ -f hszrdm-commerce.json ]] && cp hszrdm-commerce.json "$TMP/config/hszrdm-commerce.json"
38
+ [[ -d backend/.core ]] && cp -R backend/.core "$TMP/runtime/core"
39
+
40
+ FILE_UPLOAD_DIR="$(env_value backend/.env FILE_UPLOAD_DIR)"
41
+ if [[ -n "$FILE_UPLOAD_DIR" && -d "$FILE_UPLOAD_DIR" ]]; then
42
+ cp -R "$FILE_UPLOAD_DIR" "$TMP/runtime/uploads"
43
+ elif [[ -d backend/uploads ]]; then
44
+ cp -R backend/uploads "$TMP/runtime/uploads"
45
+ fi
46
+
47
+ ARCHIVE="$BACKUP_DIR/hszrdm-commerce-$STAMP.tar.gz"
48
+ tar -C "$TMP" -czf "$ARCHIVE" .
49
+ chmod 600 "$ARCHIVE" || true
50
+
51
+ if [[ "$RETENTION" =~ ^[0-9]+$ ]] && (( RETENTION > 0 )); then
52
+ ls -1t "$BACKUP_DIR"/hszrdm-commerce-*.tar.gz 2>/dev/null | tail -n +$((RETENTION + 1)) | xargs -r rm -f
53
+ fi
54
+
55
+ log "Backup created: $ARCHIVE"
56
+ printf 'WARNING: this archive contains production secrets and customer data. Store it securely.\n'
@@ -0,0 +1,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
+ }