@hszrdm/create-commerce 1.0.2 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/bin/create-commerce.mjs +9 -2
  2. package/package.json +1 -1
  3. package/src/cli.mjs +2 -2
  4. package/templates/backend/.env.example +66 -7
  5. package/templates/backend/medusa-config.ts +17 -1
  6. package/templates/backend/package.json +2 -1
  7. package/templates/backend/src/scripts/core-init.ts +13 -1
  8. package/templates/storefront/next-env.d.ts +4 -1
  9. package/templates/storefront/src/app/[countryCode]/categories/[handle]/page.tsx +9 -3
  10. package/templates/storefront/src/app/[countryCode]/products/[handle]/page.tsx +9 -5
  11. package/templates/storefront/src/app/[countryCode]/products/page.tsx +17 -10
  12. package/templates/storefront/src/app/checkout/page.tsx +12 -3
  13. package/templates/storefront/src/app/checkout/success/page.tsx +58 -18
  14. package/templates/storefront/src/app/layout.tsx +10 -3
  15. package/templates/storefront/src/app/legal/page.tsx +11 -5
  16. package/templates/storefront/src/app/page.tsx +18 -12
  17. package/templates/storefront/src/app/reset-password/page.tsx +8 -2
  18. package/templates/storefront/src/components/account-dashboard.tsx +197 -76
  19. package/templates/storefront/src/components/add-to-cart.tsx +24 -10
  20. package/templates/storefront/src/components/cart-provider.tsx +29 -12
  21. package/templates/storefront/src/components/cart-view.tsx +28 -20
  22. package/templates/storefront/src/components/checkout-analytics.tsx +23 -0
  23. package/templates/storefront/src/components/checkout-flow.tsx +354 -102
  24. package/templates/storefront/src/components/order-detail.tsx +84 -45
  25. package/templates/storefront/src/components/product-card.tsx +16 -8
  26. package/templates/storefront/src/components/reset-password-form.tsx +19 -13
  27. package/templates/storefront/src/components/storefront-header.tsx +25 -11
  28. package/templates/storefront/src/components/stripe-payment.tsx +20 -4
  29. package/templates/storefront/src/lib/core/catalog.ts +37 -5
  30. package/templates/storefront/src/lib/core/client.ts +5 -0
  31. package/templates/storefront/src/lib/core/cms.ts +112 -0
  32. package/templates/storefront/src/lib/core/commerce.ts +14 -4
  33. package/templates/storefront/src/lib/core/leads.ts +50 -0
  34. package/templates/storefront/src/lib/core/pricing.ts +68 -0
  35. package/templates/storefront/src/lib/core/quotes.ts +43 -0
  36. package/templates/storefront/src/lib/core/seo.ts +44 -6
  37. package/templates/storefront/src/lib/storefront-copy.ts +435 -0
  38. package/templates/storefront/src/lib/storefront-locale-server.ts +11 -0
  39. package/templates/storefront/src/lib/storefront-routes.ts +91 -0
  40. package/templates/storefront/src/proxy.ts +142 -0
  41. package/templates/storefront/tsconfig.json +23 -5
@@ -1,4 +1,5 @@
1
1
  import type { CoreConfig } from "./types"
2
+ import { localeFromPathname, medusaLocale } from "@/lib/storefront-routes"
2
3
 
3
4
  type CoreFetchInit = RequestInit & {
4
5
  next?: { revalidate?: number; tags?: string[] }
@@ -38,6 +39,10 @@ export async function medusaRawFetch(
38
39
  const key = publishableKey()
39
40
  if (key) headers.set("x-publishable-api-key", key)
40
41
 
42
+ if (!headers.has("x-medusa-locale") && typeof window !== "undefined") {
43
+ headers.set("x-medusa-locale", medusaLocale(localeFromPathname(window.location.pathname)))
44
+ }
45
+
41
46
  return fetch(`${getBackendUrl()}${normalizePath(path)}`, {
42
47
  ...init,
43
48
  headers,
@@ -0,0 +1,112 @@
1
+ import { medusaFetch } from "./client"
2
+
3
+ export type CmsTaxonomyTerm = {
4
+ id: string
5
+ taxonomy: "category" | "tag"
6
+ name: string
7
+ slug: string
8
+ description?: string | null
9
+ locale: string
10
+ metadata?: Record<string, unknown> | null
11
+ }
12
+
13
+ export type CmsEntry = {
14
+ id: string
15
+ content_type: string
16
+ title: string
17
+ slug: string
18
+ excerpt?: string | null
19
+ body?: string | null
20
+ body_format: "markdown" | "html" | "blocks"
21
+ blocks?: unknown
22
+ locale: string
23
+ featured_image_url?: string | null
24
+ featured_image_alt?: string | null
25
+ author_name?: string | null
26
+ seo_title?: string | null
27
+ seo_description?: string | null
28
+ canonical_url?: string | null
29
+ noindex: boolean
30
+ og_image_url?: string | null
31
+ published_at?: string | null
32
+ sort_order: number
33
+ custom_fields?: Record<string, unknown> | null
34
+ terms: CmsTaxonomyTerm[]
35
+ created_at?: string
36
+ updated_at?: string
37
+ }
38
+
39
+ export type CmsListOptions = {
40
+ contentType?: string
41
+ locale?: string
42
+ category?: string
43
+ tag?: string
44
+ q?: string
45
+ limit?: number
46
+ offset?: number
47
+ }
48
+
49
+ export function cmsConfig() {
50
+ return medusaFetch<{
51
+ enabled: true
52
+ default_locale: string
53
+ content_types: Array<{ key: string; label: string }>
54
+ body_formats: string[]
55
+ taxonomies: string[]
56
+ }>("/store/cms/config", { next: { revalidate: 300 } })
57
+ }
58
+
59
+ export function listCmsEntries(options: CmsListOptions = {}) {
60
+ const params = new URLSearchParams()
61
+ if (options.contentType) params.set("content_type", options.contentType)
62
+ if (options.locale) params.set("locale", options.locale)
63
+ if (options.category) params.set("category", options.category)
64
+ if (options.tag) params.set("tag", options.tag)
65
+ if (options.q) params.set("q", options.q)
66
+ if (options.limit != null) params.set("limit", String(options.limit))
67
+ if (options.offset != null) params.set("offset", String(options.offset))
68
+ const query = params.toString()
69
+ return medusaFetch<{ entries: CmsEntry[]; count: number; limit: number; offset: number }>(
70
+ `/store/cms/entries${query ? `?${query}` : ""}`,
71
+ { next: { revalidate: 60 } },
72
+ )
73
+ }
74
+
75
+ export function getCmsEntry(slug: string, options: { contentType?: string; locale?: string } = {}) {
76
+ const params = new URLSearchParams()
77
+ if (options.contentType) params.set("content_type", options.contentType)
78
+ if (options.locale) params.set("locale", options.locale)
79
+ const query = params.toString()
80
+ return medusaFetch<{ entry: CmsEntry }>(
81
+ `/store/cms/entries/${encodeURIComponent(slug)}${query ? `?${query}` : ""}`,
82
+ { next: { revalidate: 60 } },
83
+ )
84
+ }
85
+
86
+ export function listCmsTaxonomy(options: { taxonomy?: "category" | "tag"; locale?: string } = {}) {
87
+ const params = new URLSearchParams()
88
+ if (options.taxonomy) params.set("taxonomy", options.taxonomy)
89
+ if (options.locale) params.set("locale", options.locale)
90
+ const query = params.toString()
91
+ return medusaFetch<{ terms: CmsTaxonomyTerm[]; count: number }>(
92
+ `/store/cms/taxonomy${query ? `?${query}` : ""}`,
93
+ { next: { revalidate: 300 } },
94
+ )
95
+ }
96
+
97
+ export function cmsEntrySeo(entry: CmsEntry) {
98
+ return {
99
+ title: entry.seo_title || entry.title,
100
+ description: entry.seo_description || entry.excerpt || undefined,
101
+ alternates: entry.canonical_url ? { canonical: entry.canonical_url } : undefined,
102
+ robots: entry.noindex ? { index: false, follow: false } : undefined,
103
+ openGraph: {
104
+ title: entry.seo_title || entry.title,
105
+ description: entry.seo_description || entry.excerpt || undefined,
106
+ images: entry.og_image_url || entry.featured_image_url
107
+ ? [entry.og_image_url || entry.featured_image_url]
108
+ : undefined,
109
+ type: entry.content_type === "blog_post" ? "article" : "website",
110
+ },
111
+ }
112
+ }
@@ -137,12 +137,22 @@ export function orderDisplayId(order: JsonRecord) {
137
137
  return stringValue(order.display_id || order.id)
138
138
  }
139
139
 
140
- export function providerLabel(id: string, cod = false) {
140
+ export function providerLabel(
141
+ id: string,
142
+ cod = false,
143
+ locale = typeof document !== "undefined" ? document.documentElement.lang : "hu",
144
+ ) {
141
145
  const normalized = id.toLowerCase()
142
- if (normalized.startsWith("pp_stripe_") || normalized.includes("stripe")) return "Bankkártya (Stripe)"
143
- if (normalized.startsWith("pp_simplepay_") || normalized.includes("simplepay")) return "Bankkártya (OTP SimplePay)"
146
+ const english = locale.toLowerCase().startsWith("en")
147
+ if (normalized.startsWith("pp_stripe_") || normalized.includes("stripe")) {
148
+ return english ? "Card (Stripe)" : "Bankkártya (Stripe)"
149
+ }
150
+ if (normalized.startsWith("pp_simplepay_") || normalized.includes("simplepay")) {
151
+ return english ? "Card (OTP SimplePay)" : "Bankkártya (OTP SimplePay)"
152
+ }
144
153
  if (normalized.startsWith("pp_system_default") || normalized.includes("system")) {
145
- return cod ? "Utánvét" : "Banki átutalás / manuális fizetés"
154
+ if (cod) return english ? "Cash on delivery" : "Utánvét"
155
+ return english ? "Bank transfer / manual payment" : "Banki átutalás / manuális fizetés"
146
156
  }
147
157
  return id
148
158
  }
@@ -0,0 +1,50 @@
1
+ import { medusaFetch } from "./client"
2
+
3
+ export type LeadFieldDefinition = {
4
+ key: string
5
+ label: string
6
+ type: "text" | "textarea" | "email" | "phone" | "number" | "boolean" | "select"
7
+ required: boolean
8
+ options?: string[]
9
+ }
10
+
11
+ export type LeadFormDefinition = {
12
+ key: string
13
+ label: string
14
+ enabled: boolean
15
+ fields: LeadFieldDefinition[]
16
+ required_standard_fields: Array<"name" | "email" | "phone" | "company" | "message">
17
+ privacy: { required: boolean; version: string; url: string | null; label: string }
18
+ }
19
+
20
+ export function leadFormConfig(formKey?: string) {
21
+ const query = formKey ? `?form_key=${encodeURIComponent(formKey)}` : ""
22
+ return medusaFetch<{
23
+ forms: LeadFormDefinition[]
24
+ spam_protection: { honeypot_field: string; turnstile: { enabled: boolean; site_key?: string | null } }
25
+ }>(`/store/leads/config${query}`, { next: { revalidate: 300 } })
26
+ }
27
+
28
+ export function submitLead(input: {
29
+ form_key: string
30
+ name?: string
31
+ email?: string
32
+ phone?: string
33
+ company?: string
34
+ message?: string
35
+ fields?: Record<string, unknown>
36
+ source?: string
37
+ page_url?: string
38
+ referrer?: string
39
+ utm?: Record<string, string>
40
+ privacy_consent: boolean
41
+ form_started_at?: string
42
+ turnstile_token?: string
43
+ [key: string]: unknown
44
+ }) {
45
+ return medusaFetch<{ lead: { id: string; status: string } }>("/store/leads", {
46
+ method: "POST",
47
+ body: JSON.stringify(input),
48
+ cache: "no-store",
49
+ })
50
+ }
@@ -0,0 +1,68 @@
1
+ import { medusaFetch } from "./client"
2
+
3
+ export type PricingTier = {
4
+ min_quantity: number
5
+ max_quantity: number | null
6
+ unit_amount: number
7
+ original_unit_amount: number | null
8
+ currency_code: string
9
+ price_list_type: string | null
10
+ tax_inclusive: boolean | null
11
+ }
12
+
13
+ export type VariantPricingTiers = {
14
+ variant_id: string
15
+ product_id: string | null
16
+ currency_code: string
17
+ region_id: string | null
18
+ customer_context: "anonymous" | "authenticated"
19
+ has_tiered_pricing: boolean
20
+ tiers: PricingTier[]
21
+ }
22
+
23
+ export function getVariantPricingTiers(
24
+ variantId: string,
25
+ options: { regionId?: string; currencyCode?: string } = {},
26
+ ) {
27
+ const params = new URLSearchParams()
28
+ if (options.regionId?.trim()) params.set("region_id", options.regionId.trim())
29
+ if (options.currencyCode?.trim()) {
30
+ params.set("currency_code", options.currencyCode.trim().toLowerCase())
31
+ }
32
+ const suffix = params.size ? `?${params.toString()}` : ""
33
+ return medusaFetch<VariantPricingTiers>(
34
+ `/store/core/pricing/variants/${encodeURIComponent(variantId)}${suffix}`,
35
+ { cache: "no-store" },
36
+ )
37
+ }
38
+
39
+ export function findPricingTierForQuantity(
40
+ tiers: PricingTier[],
41
+ quantity: number,
42
+ ) {
43
+ const normalized = Math.max(1, Math.trunc(Number(quantity) || 1))
44
+ return tiers.find((tier) =>
45
+ normalized >= tier.min_quantity &&
46
+ (tier.max_quantity == null || normalized <= tier.max_quantity)
47
+ ) || null
48
+ }
49
+
50
+ export function formatPricingTierRange(tier: Pick<PricingTier, "min_quantity" | "max_quantity">) {
51
+ return tier.max_quantity == null
52
+ ? `${tier.min_quantity}+`
53
+ : tier.min_quantity === tier.max_quantity
54
+ ? String(tier.min_quantity)
55
+ : `${tier.min_quantity}–${tier.max_quantity}`
56
+ }
57
+
58
+ export function formatPricingAmount(
59
+ amount: number,
60
+ currencyCode: string,
61
+ locale = "hu-HU",
62
+ ) {
63
+ return new Intl.NumberFormat(locale, {
64
+ style: "currency",
65
+ currency: currencyCode.toUpperCase(),
66
+ maximumFractionDigits: 2,
67
+ }).format(amount)
68
+ }
@@ -0,0 +1,43 @@
1
+ import { medusaFetch } from "./client"
2
+
3
+ export type QuoteRequestItemInput = {
4
+ product_id?: string
5
+ variant_id?: string
6
+ sku?: string
7
+ title: string
8
+ quantity: number
9
+ unit_label?: string
10
+ custom_request?: string
11
+ is_custom?: boolean
12
+ reference_unit_price?: number
13
+ }
14
+
15
+ export type QuoteRequestInput = {
16
+ company_name?: string
17
+ tax_number?: string
18
+ company_address?: string
19
+ contact_name: string
20
+ contact_email: string
21
+ contact_phone?: string
22
+ order_type?: "one_time" | "recurring"
23
+ recurrence?: string
24
+ note?: string
25
+ items: QuoteRequestItemInput[]
26
+ extra_fields?: Record<string, unknown>
27
+ currency_code?: string
28
+ }
29
+
30
+ export function quoteRequestConfig() {
31
+ return medusaFetch<{
32
+ enabled: boolean
33
+ order_types: string[]
34
+ extra_fields: Array<Record<string, unknown>>
35
+ }>("/store/quote-requests/config", { cache: "no-store" })
36
+ }
37
+
38
+ export function submitQuoteRequest(input: QuoteRequestInput) {
39
+ return medusaFetch<{ quote_request: Record<string, unknown> }>("/store/quote-requests", {
40
+ method: "POST",
41
+ body: JSON.stringify(input),
42
+ })
43
+ }
@@ -1,6 +1,12 @@
1
1
  import type { Metadata } from "next"
2
2
  import { medusaFetch } from "./client"
3
3
  import type { CoreConfig, SeoContractResponse } from "./types"
4
+ import {
5
+ categoryPath,
6
+ medusaLocale,
7
+ productPath,
8
+ storefrontLocale,
9
+ } from "@/lib/storefront-routes"
4
10
 
5
11
  type SeoEntityQuery = {
6
12
  type: "product" | "category"
@@ -11,12 +17,13 @@ type SeoEntityQuery = {
11
17
  export async function getSeoContract(
12
18
  config: CoreConfig,
13
19
  query:
14
- | { type: "product" | "category"; handle: string }
15
- | { type: "page"; path: string },
20
+ | { type: "product" | "category"; handle: string; locale?: string }
21
+ | { type: "page"; path: string; locale?: string },
16
22
  ) {
17
23
  const params = new URLSearchParams({ type: query.type })
18
24
  if ("handle" in query) params.set("handle", query.handle)
19
25
  if ("path" in query) params.set("path", query.path)
26
+ if (query.locale) params.set("locale", query.locale)
20
27
  return medusaFetch<SeoContractResponse>(
21
28
  `${config.seo.metadata_endpoint}?${params.toString()}`,
22
29
  { next: { revalidate: 60 } },
@@ -26,13 +33,14 @@ export async function getSeoContract(
26
33
  export async function getStructuredData(
27
34
  config: CoreConfig,
28
35
  query:
29
- | { type: "site" }
30
- | { type: "product" | "category"; handle: string }
31
- | { type: "page"; path: string },
36
+ | { type: "site"; locale?: string }
37
+ | { type: "product" | "category"; handle: string; locale?: string }
38
+ | { type: "page"; path: string; locale?: string },
32
39
  ) {
33
40
  const params = new URLSearchParams({ type: query.type })
34
41
  if ("handle" in query) params.set("handle", query.handle)
35
42
  if ("path" in query) params.set("path", query.path)
43
+ if (query.locale) params.set("locale", query.locale)
36
44
  return medusaFetch<Record<string, unknown>>(
37
45
  `${config.seo.structured_data_endpoint}?${params.toString()}`,
38
46
  { next: { revalidate: 60 } },
@@ -69,11 +77,23 @@ export async function metadataFromCore(
69
77
  query: SeoEntityQuery,
70
78
  ): Promise<Metadata> {
71
79
  if (!config.seo.enabled) return {}
80
+ const publicLocale = storefrontLocale(query.countryCode || config.store.locale)
81
+ const locale = medusaLocale(publicLocale)
72
82
  const response = await getSeoContract(config, {
73
83
  type: query.type,
74
84
  handle: query.handle,
85
+ locale,
75
86
  })
76
- return toNextMetadata(response, config)
87
+ const metadata = toNextMetadata(response, config)
88
+ const languages = localizedAlternates(config, query)
89
+
90
+ return {
91
+ ...metadata,
92
+ alternates: {
93
+ ...(metadata.alternates || {}),
94
+ ...(languages ? { languages } : {}),
95
+ },
96
+ }
77
97
  }
78
98
 
79
99
  export async function structuredDataForEntity(
@@ -81,8 +101,26 @@ export async function structuredDataForEntity(
81
101
  query: SeoEntityQuery,
82
102
  ) {
83
103
  if (!config.seo.enabled) return null
104
+ const locale = medusaLocale(storefrontLocale(query.countryCode || config.store.locale))
84
105
  return getStructuredData(config, {
85
106
  type: query.type,
86
107
  handle: query.handle,
108
+ locale,
87
109
  })
88
110
  }
111
+
112
+ function localizedAlternates(config: CoreConfig, query: SeoEntityQuery) {
113
+ const base = config.seo.storefront_url
114
+ if (!base) return undefined
115
+
116
+ const pathFor = query.type === "product" ? productPath : categoryPath
117
+ const absolute = (path: string) => new URL(path, `${base.replace(/\/$/, "")}/`).toString()
118
+ const hu = absolute(pathFor("hu", query.handle))
119
+ const en = absolute(pathFor("en", query.handle))
120
+
121
+ return {
122
+ "hu-HU": hu,
123
+ "en-US": en,
124
+ "x-default": hu,
125
+ }
126
+ }