@hszrdm/create-commerce 1.0.3 → 1.2.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/bin/create-commerce.mjs +9 -2
- package/package.json +1 -1
- package/src/cli.mjs +5 -2
- package/templates/backend/.env.example +66 -7
- package/templates/backend/medusa-config.ts +17 -1
- package/templates/backend/package.json +2 -1
- package/templates/backend/src/scripts/core-init.ts +13 -1
- package/templates/storefront/next-env.d.ts +4 -1
- package/templates/storefront/src/app/[countryCode]/categories/[handle]/page.tsx +9 -3
- package/templates/storefront/src/app/[countryCode]/products/[handle]/page.tsx +46 -10
- package/templates/storefront/src/app/[countryCode]/products/page.tsx +17 -10
- package/templates/storefront/src/app/account/page.tsx +12 -1
- package/templates/storefront/src/app/account/wishlist/page.tsx +9 -0
- package/templates/storefront/src/app/checkout/page.tsx +12 -3
- package/templates/storefront/src/app/checkout/success/page.tsx +58 -18
- package/templates/storefront/src/app/core-ux.css +244 -0
- package/templates/storefront/src/app/layout.tsx +40 -14
- package/templates/storefront/src/app/legal/page.tsx +11 -5
- package/templates/storefront/src/app/newsletter/confirm/page.tsx +19 -0
- package/templates/storefront/src/app/newsletter/unsubscribe/page.tsx +19 -0
- package/templates/storefront/src/app/page.tsx +18 -12
- package/templates/storefront/src/app/reset-password/page.tsx +8 -2
- package/templates/storefront/src/components/accessibility-preferences.tsx +126 -0
- package/templates/storefront/src/components/accessible-dialog.tsx +88 -0
- package/templates/storefront/src/components/accessible-dropdown.tsx +98 -0
- package/templates/storefront/src/components/account-dashboard.tsx +197 -76
- package/templates/storefront/src/components/account-wishlist.tsx +95 -0
- package/templates/storefront/src/components/add-to-cart.tsx +127 -18
- package/templates/storefront/src/components/back-to-top.tsx +26 -0
- package/templates/storefront/src/components/breadcrumbs.tsx +26 -0
- package/templates/storefront/src/components/cart-provider.tsx +29 -12
- package/templates/storefront/src/components/cart-view.tsx +96 -32
- package/templates/storefront/src/components/checkout-analytics.tsx +23 -0
- package/templates/storefront/src/components/checkout-flow.tsx +354 -102
- package/templates/storefront/src/components/form-ux.tsx +47 -0
- package/templates/storefront/src/components/free-shipping-progress.tsx +35 -0
- package/templates/storefront/src/components/newsletter-action.tsx +66 -0
- package/templates/storefront/src/components/order-detail.tsx +84 -45
- package/templates/storefront/src/components/product-card.tsx +16 -8
- package/templates/storefront/src/components/product-gallery.tsx +64 -0
- package/templates/storefront/src/components/quantity-stepper.tsx +41 -0
- package/templates/storefront/src/components/reset-password-form.tsx +19 -13
- package/templates/storefront/src/components/share-button.tsx +63 -0
- package/templates/storefront/src/components/storefront-header.tsx +88 -20
- package/templates/storefront/src/components/stripe-payment.tsx +20 -4
- package/templates/storefront/src/components/tier-progress-hint.tsx +32 -0
- package/templates/storefront/src/components/toast-provider.tsx +92 -0
- package/templates/storefront/src/components/variant-price-display.tsx +31 -0
- package/templates/storefront/src/components/wishlist-button.tsx +88 -0
- package/templates/storefront/src/lib/core/account.ts +3 -0
- package/templates/storefront/src/lib/core/catalog.ts +37 -5
- package/templates/storefront/src/lib/core/client.ts +5 -0
- package/templates/storefront/src/lib/core/cms-contract.ts +35 -0
- package/templates/storefront/src/lib/core/cms.ts +171 -0
- package/templates/storefront/src/lib/core/commerce.ts +14 -4
- package/templates/storefront/src/lib/core/form-ux.ts +57 -0
- package/templates/storefront/src/lib/core/leads.ts +50 -0
- package/templates/storefront/src/lib/core/newsletter.ts +53 -0
- package/templates/storefront/src/lib/core/pricing.ts +68 -0
- package/templates/storefront/src/lib/core/quotes.ts +43 -0
- package/templates/storefront/src/lib/core/reviews.ts +40 -0
- package/templates/storefront/src/lib/core/seo.ts +44 -6
- package/templates/storefront/src/lib/core/share.ts +57 -0
- package/templates/storefront/src/lib/core/wishlist.ts +88 -0
- package/templates/storefront/src/lib/storefront-copy.ts +435 -0
- package/templates/storefront/src/lib/storefront-locale-server.ts +11 -0
- package/templates/storefront/src/lib/storefront-routes.ts +94 -0
- package/templates/storefront/src/proxy.ts +145 -0
- package/templates/storefront/tsconfig.json +23 -5
|
@@ -5,10 +5,20 @@ export type ProductListQuery = {
|
|
|
5
5
|
categoryId?: string
|
|
6
6
|
order?: string
|
|
7
7
|
regionId?: string
|
|
8
|
+
locale?: string
|
|
8
9
|
limit?: number
|
|
9
10
|
offset?: number
|
|
10
11
|
}
|
|
11
12
|
|
|
13
|
+
export type FeaturedProduct = {
|
|
14
|
+
id: string
|
|
15
|
+
title?: string | null
|
|
16
|
+
handle?: string | null
|
|
17
|
+
subtitle?: string | null
|
|
18
|
+
thumbnail?: string | null
|
|
19
|
+
featured_order: number
|
|
20
|
+
}
|
|
21
|
+
|
|
12
22
|
export function listProducts(query: ProductListQuery = {}) {
|
|
13
23
|
const params = new URLSearchParams()
|
|
14
24
|
params.set("limit", String(query.limit ?? 24))
|
|
@@ -18,6 +28,7 @@ export function listProducts(query: ProductListQuery = {}) {
|
|
|
18
28
|
if (query.categoryId?.trim()) params.set("category_id", query.categoryId.trim())
|
|
19
29
|
if (query.order?.trim()) params.set("order", query.order.trim())
|
|
20
30
|
if (query.regionId?.trim()) params.set("region_id", query.regionId.trim())
|
|
31
|
+
if (query.locale?.trim()) params.set("locale", query.locale.trim())
|
|
21
32
|
return medusaFetch<{
|
|
22
33
|
products: Array<Record<string, unknown>>
|
|
23
34
|
count?: number
|
|
@@ -26,29 +37,50 @@ export function listProducts(query: ProductListQuery = {}) {
|
|
|
26
37
|
}>(`/store/products?${params.toString()}`, { cache: "no-store" })
|
|
27
38
|
}
|
|
28
39
|
|
|
29
|
-
export function
|
|
40
|
+
export function listFeaturedProducts(limit = 8, locale?: string) {
|
|
41
|
+
const normalizedLimit = Number.isFinite(limit)
|
|
42
|
+
? Math.max(1, Math.min(100, Math.trunc(limit)))
|
|
43
|
+
: 8
|
|
44
|
+
const params = new URLSearchParams({ limit: String(normalizedLimit) })
|
|
45
|
+
if (locale?.trim()) params.set("locale", locale.trim())
|
|
46
|
+
|
|
47
|
+
return medusaFetch<{
|
|
48
|
+
products: FeaturedProduct[]
|
|
49
|
+
count: number
|
|
50
|
+
limit: number
|
|
51
|
+
}>(`/store/featured-products?${params.toString()}`, {
|
|
52
|
+
next: { revalidate: 60 },
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function listCategories(locale?: string) {
|
|
57
|
+
const params = new URLSearchParams({ limit: "100", order: "rank" })
|
|
58
|
+
if (locale?.trim()) params.set("locale", locale.trim())
|
|
30
59
|
return medusaFetch<{
|
|
31
60
|
product_categories: Array<Record<string, unknown>>
|
|
32
61
|
count?: number
|
|
33
|
-
}>(
|
|
62
|
+
}>(`/store/product-categories?${params.toString()}`, {
|
|
34
63
|
next: { revalidate: 60 },
|
|
35
64
|
})
|
|
36
65
|
}
|
|
37
66
|
|
|
38
|
-
export function getCategoryByHandle(handle: string) {
|
|
67
|
+
export function getCategoryByHandle(handle: string, locale?: string) {
|
|
68
|
+
const params = new URLSearchParams({ handle, limit: "1" })
|
|
69
|
+
if (locale?.trim()) params.set("locale", locale.trim())
|
|
39
70
|
return medusaFetch<{ product_categories: Array<Record<string, unknown>> }>(
|
|
40
|
-
`/store/product-categories
|
|
71
|
+
`/store/product-categories?${params.toString()}`,
|
|
41
72
|
{ next: { revalidate: 60 } },
|
|
42
73
|
)
|
|
43
74
|
}
|
|
44
75
|
|
|
45
|
-
export function getProductByHandle(handle: string, regionId?: string) {
|
|
76
|
+
export function getProductByHandle(handle: string, regionId?: string, locale?: string) {
|
|
46
77
|
const params = new URLSearchParams({
|
|
47
78
|
handle,
|
|
48
79
|
limit: "1",
|
|
49
80
|
fields: "+variants.calculated_price,+categories,+images",
|
|
50
81
|
})
|
|
51
82
|
if (regionId) params.set("region_id", regionId)
|
|
83
|
+
if (locale?.trim()) params.set("locale", locale.trim())
|
|
52
84
|
return medusaFetch<{ products: Array<Record<string, unknown>> }>(
|
|
53
85
|
`/store/products?${params.toString()}`,
|
|
54
86
|
{ next: { revalidate: 60 } },
|
|
@@ -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,35 @@
|
|
|
1
|
+
export const CORE_CMS_CONTENT_TYPES = {
|
|
2
|
+
BLOG_POST: "blog_post",
|
|
3
|
+
PAGE: "page",
|
|
4
|
+
KNOWLEDGE_BASE: "knowledge_base",
|
|
5
|
+
} as const
|
|
6
|
+
|
|
7
|
+
export type CoreCmsContentType =
|
|
8
|
+
typeof CORE_CMS_CONTENT_TYPES[keyof typeof CORE_CMS_CONTENT_TYPES]
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Built-in HSZRDM Commerce CMS content types.
|
|
12
|
+
*
|
|
13
|
+
* Projects may still persist and query arbitrary custom content_type strings.
|
|
14
|
+
* This type keeps the built-ins discoverable without restricting extensions.
|
|
15
|
+
*/
|
|
16
|
+
export type CmsContentType = CoreCmsContentType | (string & {})
|
|
17
|
+
|
|
18
|
+
export const CORE_CMS_CONTENT_TYPE_OPTIONS = [
|
|
19
|
+
{
|
|
20
|
+
value: CORE_CMS_CONTENT_TYPES.BLOG_POST,
|
|
21
|
+
label: "Blogbejegyzés",
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
value: CORE_CMS_CONTENT_TYPES.PAGE,
|
|
25
|
+
label: "Oldal",
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
value: CORE_CMS_CONTENT_TYPES.KNOWLEDGE_BASE,
|
|
29
|
+
label: "Tudástár",
|
|
30
|
+
},
|
|
31
|
+
] as const
|
|
32
|
+
|
|
33
|
+
export function isCoreCmsContentType(value: string): value is CoreCmsContentType {
|
|
34
|
+
return (Object.values(CORE_CMS_CONTENT_TYPES) as string[]).includes(value)
|
|
35
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { medusaFetch } from "./client"
|
|
2
|
+
import {
|
|
3
|
+
CORE_CMS_CONTENT_TYPES,
|
|
4
|
+
type CmsContentType,
|
|
5
|
+
} from "./cms-contract"
|
|
6
|
+
|
|
7
|
+
export {
|
|
8
|
+
CORE_CMS_CONTENT_TYPES,
|
|
9
|
+
CORE_CMS_CONTENT_TYPE_OPTIONS,
|
|
10
|
+
isCoreCmsContentType,
|
|
11
|
+
type CoreCmsContentType,
|
|
12
|
+
type CmsContentType,
|
|
13
|
+
} from "./cms-contract"
|
|
14
|
+
|
|
15
|
+
export type CmsTaxonomyTerm = {
|
|
16
|
+
id: string
|
|
17
|
+
taxonomy: "category" | "tag"
|
|
18
|
+
name: string
|
|
19
|
+
slug: string
|
|
20
|
+
description?: string | null
|
|
21
|
+
locale: string | null
|
|
22
|
+
metadata?: Record<string, unknown> | null
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type CmsEntry = {
|
|
26
|
+
id: string
|
|
27
|
+
content_type: CmsContentType
|
|
28
|
+
title: string
|
|
29
|
+
slug: string
|
|
30
|
+
excerpt?: string | null
|
|
31
|
+
body?: string | null
|
|
32
|
+
body_format: "markdown" | "html" | "blocks"
|
|
33
|
+
blocks?: unknown
|
|
34
|
+
locale: string | null
|
|
35
|
+
featured_image_url?: string | null
|
|
36
|
+
featured_image_alt?: string | null
|
|
37
|
+
author_name?: string | null
|
|
38
|
+
seo_title?: string | null
|
|
39
|
+
seo_description?: string | null
|
|
40
|
+
canonical_url?: string | null
|
|
41
|
+
noindex: boolean
|
|
42
|
+
og_image_url?: string | null
|
|
43
|
+
published_at?: string | null
|
|
44
|
+
sort_order: number
|
|
45
|
+
custom_fields?: Record<string, unknown> | null
|
|
46
|
+
terms: CmsTaxonomyTerm[]
|
|
47
|
+
created_at?: string
|
|
48
|
+
updated_at?: string
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export type CmsListOptions = {
|
|
52
|
+
contentType?: CmsContentType
|
|
53
|
+
locale?: string
|
|
54
|
+
category?: string
|
|
55
|
+
tag?: string
|
|
56
|
+
q?: string
|
|
57
|
+
limit?: number
|
|
58
|
+
offset?: number
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export type CmsEntryOptions = {
|
|
62
|
+
contentType?: CmsContentType
|
|
63
|
+
locale?: string
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function cmsConfig() {
|
|
67
|
+
return medusaFetch<{
|
|
68
|
+
enabled: true
|
|
69
|
+
default_locale: string
|
|
70
|
+
content_types: Array<{ key: CmsContentType; label: string }>
|
|
71
|
+
body_formats: string[]
|
|
72
|
+
taxonomies: string[]
|
|
73
|
+
}>("/store/cms/config", { next: { revalidate: 300 } })
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function listCmsEntries(options: CmsListOptions = {}) {
|
|
77
|
+
const params = new URLSearchParams()
|
|
78
|
+
if (options.contentType) params.set("content_type", options.contentType)
|
|
79
|
+
if (options.locale) params.set("locale", options.locale)
|
|
80
|
+
if (options.category) params.set("category", options.category)
|
|
81
|
+
if (options.tag) params.set("tag", options.tag)
|
|
82
|
+
if (options.q) params.set("q", options.q)
|
|
83
|
+
if (options.limit != null) params.set("limit", String(options.limit))
|
|
84
|
+
if (options.offset != null) params.set("offset", String(options.offset))
|
|
85
|
+
const query = params.toString()
|
|
86
|
+
return medusaFetch<{ entries: CmsEntry[]; count: number; limit: number; offset: number }>(
|
|
87
|
+
`/store/cms/entries${query ? `?${query}` : ""}`,
|
|
88
|
+
{ next: { revalidate: 60 } },
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function getCmsEntry(slug: string, options: CmsEntryOptions = {}) {
|
|
93
|
+
const params = new URLSearchParams()
|
|
94
|
+
if (options.contentType) params.set("content_type", options.contentType)
|
|
95
|
+
if (options.locale) params.set("locale", options.locale)
|
|
96
|
+
const query = params.toString()
|
|
97
|
+
return medusaFetch<{ entry: CmsEntry }>(
|
|
98
|
+
`/store/cms/entries/${encodeURIComponent(slug)}${query ? `?${query}` : ""}`,
|
|
99
|
+
{ next: { revalidate: 60 } },
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function listBlogPosts(options: Omit<CmsListOptions, "contentType"> = {}) {
|
|
104
|
+
return listCmsEntries({
|
|
105
|
+
...options,
|
|
106
|
+
contentType: CORE_CMS_CONTENT_TYPES.BLOG_POST,
|
|
107
|
+
})
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function getBlogPost(slug: string, options: Omit<CmsEntryOptions, "contentType"> = {}) {
|
|
111
|
+
return getCmsEntry(slug, {
|
|
112
|
+
...options,
|
|
113
|
+
contentType: CORE_CMS_CONTENT_TYPES.BLOG_POST,
|
|
114
|
+
})
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function listCmsPages(options: Omit<CmsListOptions, "contentType"> = {}) {
|
|
118
|
+
return listCmsEntries({
|
|
119
|
+
...options,
|
|
120
|
+
contentType: CORE_CMS_CONTENT_TYPES.PAGE,
|
|
121
|
+
})
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function getCmsPage(slug: string, options: Omit<CmsEntryOptions, "contentType"> = {}) {
|
|
125
|
+
return getCmsEntry(slug, {
|
|
126
|
+
...options,
|
|
127
|
+
contentType: CORE_CMS_CONTENT_TYPES.PAGE,
|
|
128
|
+
})
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function listKnowledgeBaseEntries(options: Omit<CmsListOptions, "contentType"> = {}) {
|
|
132
|
+
return listCmsEntries({
|
|
133
|
+
...options,
|
|
134
|
+
contentType: CORE_CMS_CONTENT_TYPES.KNOWLEDGE_BASE,
|
|
135
|
+
})
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function getKnowledgeBaseEntry(slug: string, options: Omit<CmsEntryOptions, "contentType"> = {}) {
|
|
139
|
+
return getCmsEntry(slug, {
|
|
140
|
+
...options,
|
|
141
|
+
contentType: CORE_CMS_CONTENT_TYPES.KNOWLEDGE_BASE,
|
|
142
|
+
})
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export function listCmsTaxonomy(options: { taxonomy?: "category" | "tag"; locale?: string } = {}) {
|
|
146
|
+
const params = new URLSearchParams()
|
|
147
|
+
if (options.taxonomy) params.set("taxonomy", options.taxonomy)
|
|
148
|
+
if (options.locale) params.set("locale", options.locale)
|
|
149
|
+
const query = params.toString()
|
|
150
|
+
return medusaFetch<{ terms: CmsTaxonomyTerm[]; count: number }>(
|
|
151
|
+
`/store/cms/taxonomy${query ? `?${query}` : ""}`,
|
|
152
|
+
{ next: { revalidate: 300 } },
|
|
153
|
+
)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export function cmsEntrySeo(entry: CmsEntry) {
|
|
157
|
+
return {
|
|
158
|
+
title: entry.seo_title || entry.title,
|
|
159
|
+
description: entry.seo_description || entry.excerpt || undefined,
|
|
160
|
+
alternates: entry.canonical_url ? { canonical: entry.canonical_url } : undefined,
|
|
161
|
+
robots: entry.noindex ? { index: false, follow: false } : undefined,
|
|
162
|
+
openGraph: {
|
|
163
|
+
title: entry.seo_title || entry.title,
|
|
164
|
+
description: entry.seo_description || entry.excerpt || undefined,
|
|
165
|
+
images: entry.og_image_url || entry.featured_image_url
|
|
166
|
+
? [entry.og_image_url || entry.featured_image_url]
|
|
167
|
+
: undefined,
|
|
168
|
+
type: entry.content_type === CORE_CMS_CONTENT_TYPES.BLOG_POST ? "article" : "website",
|
|
169
|
+
},
|
|
170
|
+
}
|
|
171
|
+
}
|
|
@@ -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(
|
|
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
|
-
|
|
143
|
-
if (normalized.startsWith("
|
|
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
|
-
|
|
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,57 @@
|
|
|
1
|
+
export function focusFirstInvalidField(root?: ParentNode) {
|
|
2
|
+
if (typeof document === "undefined") return null
|
|
3
|
+
const targetRoot = root || document
|
|
4
|
+
const invalid = targetRoot.querySelector<HTMLElement>(
|
|
5
|
+
"[aria-invalid='true'], input:invalid, select:invalid, textarea:invalid",
|
|
6
|
+
)
|
|
7
|
+
invalid?.focus()
|
|
8
|
+
invalid?.scrollIntoView({ behavior: prefersReducedMotion() ? "auto" : "smooth", block: "center" })
|
|
9
|
+
return invalid || null
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function fieldErrorId(fieldName: string) {
|
|
13
|
+
return `field-error-${fieldName.replace(/[^a-zA-Z0-9_-]+/g, "-")}`
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function humanizeStorefrontError(error: unknown, locale: "hu" | "en" = "hu") {
|
|
17
|
+
const fallback = locale === "en"
|
|
18
|
+
? "Something went wrong. Please try again."
|
|
19
|
+
: "Hiba történt. Kérjük, próbáld újra."
|
|
20
|
+
if (!(error instanceof Error)) return fallback
|
|
21
|
+
|
|
22
|
+
const message = error.message.trim()
|
|
23
|
+
if (!message) return fallback
|
|
24
|
+
if (/network|fetch failed|failed to fetch|econn|timeout/i.test(message)) {
|
|
25
|
+
return locale === "en"
|
|
26
|
+
? "The service is temporarily unavailable. Please try again shortly."
|
|
27
|
+
: "A szolgáltatás átmenetileg nem érhető el. Kérjük, próbáld újra rövidesen."
|
|
28
|
+
}
|
|
29
|
+
if (/unauthorized|401/i.test(message)) {
|
|
30
|
+
return locale === "en" ? "Please sign in to continue." : "A folytatáshoz jelentkezz be."
|
|
31
|
+
}
|
|
32
|
+
if (/forbidden|403/i.test(message)) {
|
|
33
|
+
return locale === "en" ? "You don't have permission for this action." : "Ehhez a művelethez nincs jogosultságod."
|
|
34
|
+
}
|
|
35
|
+
return message.length <= 240 ? message : fallback
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function prefersReducedMotion() {
|
|
39
|
+
if (typeof window === "undefined" || typeof window.matchMedia !== "function") return false
|
|
40
|
+
const override = document.documentElement.dataset.motion
|
|
41
|
+
if (override === "reduced") return true
|
|
42
|
+
if (override === "full") return false
|
|
43
|
+
return window.matchMedia("(prefers-reduced-motion: reduce)").matches
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function accessibilityProps(input: {
|
|
47
|
+
name: string
|
|
48
|
+
error?: string | null
|
|
49
|
+
required?: boolean
|
|
50
|
+
}) {
|
|
51
|
+
const errorId = fieldErrorId(input.name)
|
|
52
|
+
return {
|
|
53
|
+
"aria-invalid": input.error ? true : undefined,
|
|
54
|
+
"aria-describedby": input.error ? errorId : undefined,
|
|
55
|
+
"aria-required": input.required || undefined,
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -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,53 @@
|
|
|
1
|
+
import { medusaFetch } from "./client"
|
|
2
|
+
|
|
3
|
+
export type NewsletterConfig = {
|
|
4
|
+
enabled: boolean
|
|
5
|
+
double_opt_in: boolean
|
|
6
|
+
consent_version: string
|
|
7
|
+
consent_url: string | null
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type NewsletterSubscriptionState = {
|
|
11
|
+
subscriber: {
|
|
12
|
+
id: string
|
|
13
|
+
status: "pending" | "subscribed" | "unsubscribed"
|
|
14
|
+
double_opt_in?: boolean
|
|
15
|
+
}
|
|
16
|
+
message: string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function newsletterConfig() {
|
|
20
|
+
return medusaFetch<NewsletterConfig>("/store/newsletter/config", {
|
|
21
|
+
next: { revalidate: 300 },
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function subscribeNewsletter(input: {
|
|
26
|
+
email: string
|
|
27
|
+
consent: true
|
|
28
|
+
source?: string
|
|
29
|
+
page_url?: string
|
|
30
|
+
utm?: Partial<Record<"utm_source" | "utm_medium" | "utm_campaign" | "utm_term" | "utm_content", string>>
|
|
31
|
+
}) {
|
|
32
|
+
return medusaFetch<NewsletterSubscriptionState>("/store/newsletter", {
|
|
33
|
+
method: "POST",
|
|
34
|
+
body: JSON.stringify(input),
|
|
35
|
+
cache: "no-store",
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function confirmNewsletter(token: string) {
|
|
40
|
+
return medusaFetch<NewsletterSubscriptionState>("/store/newsletter/confirm", {
|
|
41
|
+
method: "POST",
|
|
42
|
+
body: JSON.stringify({ token }),
|
|
43
|
+
cache: "no-store",
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function unsubscribeNewsletter(token: string) {
|
|
48
|
+
return medusaFetch<NewsletterSubscriptionState>("/store/newsletter/unsubscribe", {
|
|
49
|
+
method: "POST",
|
|
50
|
+
body: JSON.stringify({ token }),
|
|
51
|
+
cache: "no-store",
|
|
52
|
+
})
|
|
53
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { medusaFetch } from "./client"
|
|
2
|
+
|
|
3
|
+
export type ProductReview = {
|
|
4
|
+
id: string
|
|
5
|
+
product_id: string
|
|
6
|
+
customer_name: string
|
|
7
|
+
rating: number
|
|
8
|
+
body: string
|
|
9
|
+
verified_purchase: boolean
|
|
10
|
+
status?: "pending" | "approved" | "rejected"
|
|
11
|
+
created_at?: string
|
|
12
|
+
updated_at?: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type ProductReviewSummary = {
|
|
16
|
+
average: number
|
|
17
|
+
count: number
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function listProductReviews(productId: string, options: { limit?: number; offset?: number } = {}) {
|
|
21
|
+
const params = new URLSearchParams()
|
|
22
|
+
if (options.limit != null) params.set("limit", String(options.limit))
|
|
23
|
+
if (options.offset != null) params.set("offset", String(options.offset))
|
|
24
|
+
const query = params.toString()
|
|
25
|
+
return medusaFetch<{
|
|
26
|
+
reviews: ProductReview[]
|
|
27
|
+
summary: ProductReviewSummary
|
|
28
|
+
limit: number
|
|
29
|
+
offset: number
|
|
30
|
+
}>(`/store/products/${encodeURIComponent(productId)}/reviews${query ? `?${query}` : ""}`, {
|
|
31
|
+
cache: "no-store",
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function submitProductReview(productId: string, input: { rating: number; body: string }) {
|
|
36
|
+
return medusaFetch<{ review: ProductReview }>(`/store/products/${encodeURIComponent(productId)}/reviews`, {
|
|
37
|
+
method: "POST",
|
|
38
|
+
body: JSON.stringify(input),
|
|
39
|
+
})
|
|
40
|
+
}
|