@hszrdm/create-commerce 1.7.0 → 1.9.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 (45) hide show
  1. package/package.json +1 -1
  2. package/src/cli.mjs +3 -0
  3. package/templates/backend/.env.example +24 -1
  4. package/templates/backend/package.json +8 -7
  5. package/templates/backend/scripts/sync-env-example.mjs +55 -0
  6. package/templates/backend/scripts/verify-env-contract.mjs +6 -5
  7. package/templates/backend/src/scripts/verify-runtime-modules.ts +1 -0
  8. package/templates/storefront/.env.example +6 -0
  9. package/templates/storefront/.env.local +3 -0
  10. package/templates/storefront/package.json +2 -1
  11. package/templates/storefront/src/app/[countryCode]/categories/[handle]/page.tsx +5 -1
  12. package/templates/storefront/src/app/[countryCode]/products/[handle]/page.tsx +14 -5
  13. package/templates/storefront/src/app/[countryCode]/products/page.tsx +10 -1
  14. package/templates/storefront/src/app/account/orders/[id]/page.tsx +17 -2
  15. package/templates/storefront/src/app/checkout/success/page.tsx +5 -0
  16. package/templates/storefront/src/app/documents/page.tsx +27 -0
  17. package/templates/storefront/src/app/layout.tsx +8 -1
  18. package/templates/storefront/src/components/add-to-cart.tsx +16 -14
  19. package/templates/storefront/src/components/arukereso-backlink.tsx +43 -0
  20. package/templates/storefront/src/components/arukereso-trusted-shop-widget.tsx +81 -0
  21. package/templates/storefront/src/components/arukereso-trusted-shop.tsx +71 -0
  22. package/templates/storefront/src/components/carrier-pickup-adapter.ts +93 -0
  23. package/templates/storefront/src/components/carrier-pickup-dialog.tsx +119 -0
  24. package/templates/storefront/src/components/carrier-pickup-map.tsx +200 -0
  25. package/templates/storefront/src/components/cart-view.tsx +4 -2
  26. package/templates/storefront/src/components/category-documents.tsx +18 -0
  27. package/templates/storefront/src/components/checkout-analytics.tsx +22 -0
  28. package/templates/storefront/src/components/checkout-flow.tsx +75 -115
  29. package/templates/storefront/src/components/document-list.tsx +47 -0
  30. package/templates/storefront/src/components/google-ads-cart-remarketing.tsx +71 -0
  31. package/templates/storefront/src/components/google-ads-purchase.tsx +37 -0
  32. package/templates/storefront/src/components/price-display.tsx +39 -0
  33. package/templates/storefront/src/components/product-card.tsx +7 -6
  34. package/templates/storefront/src/components/product-documents.tsx +18 -0
  35. package/templates/storefront/src/components/product-view-tracker.tsx +17 -2
  36. package/templates/storefront/src/components/reorder-button.tsx +74 -0
  37. package/templates/storefront/src/components/variant-price-display.tsx +7 -11
  38. package/templates/storefront/src/lib/core/catalog.ts +6 -2
  39. package/templates/storefront/src/lib/core/commerce.ts +51 -0
  40. package/templates/storefront/src/lib/core/documents.ts +37 -0
  41. package/templates/storefront/src/lib/core/google-ads.ts +154 -7
  42. package/templates/storefront/src/lib/core/reorder.ts +26 -0
  43. package/templates/storefront/src/lib/storefront-routes.ts +3 -0
  44. package/templates/storefront/src/proxy.ts +2 -0
  45. package/templates/storefront/tests/carrier-pickup-adapter.test.mjs +69 -0
@@ -1,31 +1,27 @@
1
1
  "use client"
2
2
 
3
3
  import { useEffect, useState } from "react"
4
- import { formatMoney } from "@/lib/core/commerce"
4
+ import { PriceDisplay } from "./price-display"
5
+ import type { PriceBreakdown } from "@/lib/core/commerce"
5
6
 
6
7
  export function VariantPriceDisplay({
7
8
  initialPrice,
8
- initialCurrency,
9
9
  locale,
10
10
  }: {
11
- initialPrice: number
12
- initialCurrency: string
11
+ initialPrice: PriceBreakdown
13
12
  locale: string
14
13
  }) {
15
14
  const [price, setPrice] = useState(initialPrice)
16
- const [currency, setCurrency] = useState(initialCurrency)
17
15
 
18
16
  useEffect(() => {
19
17
  const listener = (event: Event) => {
20
- const detail = (event as CustomEvent<{ price?: number; currency?: string }>).detail
21
- const nextPrice = Number(detail?.price)
22
- if (Number.isFinite(nextPrice)) setPrice(nextPrice)
23
- if (detail?.currency) setCurrency(detail.currency)
18
+ const detail = (event as CustomEvent<{ price?: PriceBreakdown }>).detail
19
+ if (detail?.price && Number.isFinite(detail.price.amount)) setPrice(detail.price)
24
20
  }
25
21
  window.addEventListener("hszrdm:product-variant-change", listener)
26
22
  return () => window.removeEventListener("hszrdm:product-variant-change", listener)
27
23
  }, [])
28
24
 
29
- if (!Number.isFinite(price)) return null
30
- return <div className="product-price" aria-live="polite">{formatMoney(price, currency, locale)}</div>
25
+ if (!Number.isFinite(price.amount)) return null
26
+ return <div aria-live="polite"><PriceDisplay price={price} locale={locale} /></div>
31
27
  }
@@ -5,6 +5,7 @@ export type ProductListQuery = {
5
5
  categoryId?: string
6
6
  order?: string
7
7
  regionId?: string
8
+ countryCode?: string
8
9
  locale?: string
9
10
  limit?: number
10
11
  offset?: number
@@ -28,6 +29,7 @@ export function listProducts(query: ProductListQuery = {}) {
28
29
  if (query.categoryId?.trim()) params.set("category_id", query.categoryId.trim())
29
30
  if (query.order?.trim()) params.set("order", query.order.trim())
30
31
  if (query.regionId?.trim()) params.set("region_id", query.regionId.trim())
32
+ if (query.countryCode?.trim()) params.set("country_code", query.countryCode.trim().toLowerCase())
31
33
  if (query.locale?.trim()) params.set("locale", query.locale.trim())
32
34
  return medusaFetch<{
33
35
  products: Array<Record<string, unknown>>
@@ -73,13 +75,14 @@ export function getCategoryByHandle(handle: string, locale?: string) {
73
75
  )
74
76
  }
75
77
 
76
- export function getProductByHandle(handle: string, regionId?: string, locale?: string) {
78
+ export function getProductByHandle(handle: string, regionId?: string, locale?: string, countryCode?: string) {
77
79
  const params = new URLSearchParams({
78
80
  handle,
79
81
  limit: "1",
80
82
  fields: "+variants.calculated_price,+categories,+images",
81
83
  })
82
84
  if (regionId) params.set("region_id", regionId)
85
+ if (countryCode?.trim()) params.set("country_code", countryCode.trim().toLowerCase())
83
86
  if (locale?.trim()) params.set("locale", locale.trim())
84
87
  return medusaFetch<{ products: Array<Record<string, unknown>> }>(
85
88
  `/store/products?${params.toString()}`,
@@ -87,11 +90,12 @@ export function getProductByHandle(handle: string, regionId?: string, locale?: s
87
90
  )
88
91
  }
89
92
 
90
- export function getProductById(productId: string, regionId?: string, locale?: string) {
93
+ export function getProductById(productId: string, regionId?: string, locale?: string, countryCode?: string) {
91
94
  const params = new URLSearchParams({
92
95
  fields: "+variants.calculated_price,+categories,+images",
93
96
  })
94
97
  if (regionId) params.set("region_id", regionId)
98
+ if (countryCode?.trim()) params.set("country_code", countryCode.trim().toLowerCase())
95
99
  if (locale?.trim()) params.set("locale", locale.trim())
96
100
  return medusaFetch<{ product: Record<string, unknown> }>(
97
101
  `/store/products/${encodeURIComponent(productId)}?${params.toString()}`,
@@ -1,5 +1,15 @@
1
1
  export type JsonRecord = Record<string, unknown>
2
2
 
3
+ export type PriceBreakdown = {
4
+ amount: number
5
+ grossAmount: number
6
+ netAmount: number
7
+ taxAmount: number
8
+ taxRate: number
9
+ currency: string
10
+ hasTaxBreakdown: boolean
11
+ }
12
+
3
13
  export function isRecord(value: unknown): value is JsonRecord {
4
14
  return Boolean(value && typeof value === "object" && !Array.isArray(value))
5
15
  }
@@ -107,6 +117,23 @@ export function lineTotal(item: JsonRecord) {
107
117
  return lineUnitPrice(item) * numberValue(item.quantity, 1)
108
118
  }
109
119
 
120
+ export function linePriceBreakdown(item: JsonRecord, currency: string): PriceBreakdown {
121
+ const grossAmount = lineTotal(item)
122
+ const taxAmount = numberValue(item.tax_total, 0)
123
+ const netAmount = Number.isFinite(grossAmount) ? grossAmount - taxAmount : Number.NaN
124
+ const hasTaxBreakdown = Number.isFinite(netAmount) && taxAmount > 0
125
+ const taxRate = hasTaxBreakdown && netAmount > 0 ? (taxAmount / netAmount) * 100 : Number.NaN
126
+ return {
127
+ amount: grossAmount,
128
+ grossAmount,
129
+ netAmount,
130
+ taxAmount,
131
+ taxRate,
132
+ currency: currency.toUpperCase(),
133
+ hasTaxBreakdown,
134
+ }
135
+ }
136
+
110
137
  export function formatMoney(
111
138
  amount: number,
112
139
  currency: string,
@@ -133,6 +160,30 @@ export function productVariantCurrency(variant: JsonRecord | null | undefined, f
133
160
  return stringValue(price?.currency_code || fallback).toUpperCase()
134
161
  }
135
162
 
163
+ export function productVariantPriceBreakdown(
164
+ variant: JsonRecord | null | undefined,
165
+ fallbackCurrency: string,
166
+ ): PriceBreakdown {
167
+ const price = isRecord(variant?.calculated_price) ? variant.calculated_price : null
168
+ const amount = price ? numberValue(price.calculated_amount, Number.NaN) : Number.NaN
169
+ const withTax = price ? numberValue(price.calculated_amount_with_tax, Number.NaN) : Number.NaN
170
+ const withoutTax = price ? numberValue(price.calculated_amount_without_tax, Number.NaN) : Number.NaN
171
+ const grossAmount = Number.isFinite(withTax) ? withTax : amount
172
+ const netAmount = Number.isFinite(withoutTax) ? withoutTax : amount
173
+ const hasTaxBreakdown = Number.isFinite(withTax) && Number.isFinite(withoutTax)
174
+ const taxAmount = hasTaxBreakdown ? Math.max(0, withTax - withoutTax) : Number.NaN
175
+ const taxRate = hasTaxBreakdown && withoutTax > 0 ? (taxAmount / withoutTax) * 100 : Number.NaN
176
+ return {
177
+ amount: grossAmount,
178
+ grossAmount,
179
+ netAmount,
180
+ taxAmount,
181
+ taxRate,
182
+ currency: productVariantCurrency(variant, fallbackCurrency),
183
+ hasTaxBreakdown,
184
+ }
185
+ }
186
+
136
187
  export function orderDisplayId(order: JsonRecord) {
137
188
  return stringValue(order.display_id || order.id)
138
189
  }
@@ -0,0 +1,37 @@
1
+ import { medusaFetch } from "./client"
2
+
3
+ export type StoreDocument = {
4
+ id: string
5
+ title: string
6
+ description?: string | null
7
+ document_type: string
8
+ file_url: string
9
+ file_name: string
10
+ mime_type?: string | null
11
+ file_size?: number | null
12
+ locale?: string | null
13
+ version?: string | null
14
+ valid_from?: string | null
15
+ valid_until?: string | null
16
+ product_ids: string[]
17
+ category_ids: string[]
18
+ }
19
+
20
+ export async function getDocuments(input: {
21
+ productId?: string
22
+ categoryId?: string
23
+ documentType?: string
24
+ locale?: string
25
+ limit?: number
26
+ } = {}) {
27
+ const params = new URLSearchParams()
28
+ if (input.productId) params.set("product_id", input.productId)
29
+ if (input.categoryId) params.set("category_id", input.categoryId)
30
+ if (input.documentType) params.set("document_type", input.documentType)
31
+ if (input.locale) params.set("locale", input.locale)
32
+ params.set("limit", String(input.limit || 200))
33
+ return medusaFetch<{ documents: StoreDocument[]; count: number }>(
34
+ `/store/documents?${params.toString()}`,
35
+ { next: { revalidate: 60 } },
36
+ )
37
+ }
@@ -1,4 +1,5 @@
1
1
  import { readConsentPreferences } from "./consent"
2
+ import type { EcommerceItem, EcommercePayload, EcommerceEventName } from "./tracking"
2
3
  import type { CoreConfig } from "./types"
3
4
 
4
5
  export function trackGoogleAdsPurchase(
@@ -15,18 +16,20 @@ export function trackGoogleAdsPurchase(
15
16
  const dedupeKey = `core:google-ads:purchase:${transactionId}`
16
17
  if (window.localStorage.getItem(dedupeKey) === "sent") return false
17
18
 
18
- const payload = {
19
+ const purchaseEcommerce = googleAdsRemarketingFromSource(order)
20
+ const items = purchaseEcommerce.items
21
+ .map(dynamicRemarketingItem)
22
+ .filter((item): item is NonNullable<ReturnType<typeof dynamicRemarketingItem>> => Boolean(item))
23
+
24
+ const payload = clean({
19
25
  send_to: googleAds.purchase_send_to,
20
26
  transaction_id: transactionId,
21
27
  value: finite(order.total),
22
28
  currency: text(order.currency_code).toUpperCase() || "HUF",
23
- }
29
+ items: items.length ? items : undefined,
30
+ })
24
31
 
25
- const target = window as typeof window & {
26
- dataLayer?: Array<Record<string, unknown> | unknown[]>
27
- gtag?: (...args: unknown[]) => void
28
- }
29
- target.dataLayer = target.dataLayer || []
32
+ const target = googleTarget()
30
33
 
31
34
  if (googleAds.google_tag_manager_enabled) {
32
35
  target.dataLayer.push({
@@ -46,6 +49,150 @@ export function trackGoogleAdsPurchase(
46
49
  return false
47
50
  }
48
51
 
52
+ export function trackGoogleAdsRemarketing(
53
+ googleAds: CoreConfig["marketing"]["google_ads"],
54
+ event: Extract<EcommerceEventName, "view_item" | "add_to_cart" | "begin_checkout" | "purchase">,
55
+ ecommerce: EcommercePayload,
56
+ options: { dedupeKey?: string; sessionDedupe?: boolean } = {},
57
+ ) {
58
+ if (typeof window === "undefined") return false
59
+ if (!googleAds.enabled || !googleAds.remarketing_enabled) return false
60
+ if (!readConsentPreferences()?.marketing) return false
61
+
62
+ const items = ecommerce.items
63
+ .map(dynamicRemarketingItem)
64
+ .filter((item): item is NonNullable<ReturnType<typeof dynamicRemarketingItem>> => Boolean(item))
65
+ if (!items.length) return false
66
+
67
+ const storage = options.sessionDedupe ? window.sessionStorage : window.localStorage
68
+ const dedupeKey = options.dedupeKey
69
+ ? `core:google-ads:remarketing:${event}:${options.dedupeKey}`
70
+ : null
71
+ if (dedupeKey && storage.getItem(dedupeKey) === "sent") return false
72
+
73
+ const payload = clean({
74
+ currency: normalizeCurrency(ecommerce.currency),
75
+ value: finite(ecommerce.value),
76
+ items,
77
+ })
78
+ const target = googleTarget()
79
+
80
+ if (googleAds.google_tag_manager_enabled) {
81
+ target.dataLayer.push({
82
+ event: `google_ads_${event}`,
83
+ google_ads_remarketing: payload,
84
+ })
85
+ if (dedupeKey) storage.setItem(dedupeKey, "sent")
86
+ return true
87
+ }
88
+
89
+ if (typeof target.gtag === "function") {
90
+ target.gtag("event", event, payload)
91
+ if (dedupeKey) storage.setItem(dedupeKey, "sent")
92
+ return true
93
+ }
94
+
95
+ return false
96
+ }
97
+
98
+ export function googleAdsRemarketingItemFromProduct(input: {
99
+ product: Record<string, unknown>
100
+ variant?: Record<string, unknown> | null
101
+ quantity?: number
102
+ }): EcommerceItem | null {
103
+ const variant = input.variant || null
104
+ const itemId = text(variant?.id)
105
+ if (!itemId) return null
106
+ const calculatedPrice = record(variant?.calculated_price)
107
+ const price = finite(calculatedPrice?.calculated_amount)
108
+ return clean({
109
+ item_id: itemId,
110
+ item_name: text(input.product.title) || "Termék",
111
+ item_variant: text(variant?.title),
112
+ price,
113
+ quantity: Math.max(1, Math.trunc(input.quantity || 1)),
114
+ }) as EcommerceItem
115
+ }
116
+
117
+ export function googleAdsRemarketingFromSource(source: Record<string, unknown>): EcommercePayload {
118
+ const items = sourceItems(source)
119
+ .map((line) => googleAdsRemarketingItemFromLine(line))
120
+ .filter((item): item is EcommerceItem => Boolean(item))
121
+ const currency = normalizeCurrency(source.currency_code)
122
+ const value = items.reduce(
123
+ (sum, item) => sum + (item.price || 0) * (item.quantity || 1),
124
+ 0,
125
+ )
126
+ return { currency, value: Number(value.toFixed(6)), items }
127
+ }
128
+
129
+ function googleAdsRemarketingItemFromLine(line: Record<string, unknown>): EcommerceItem | null {
130
+ const itemId = text(line.variant_id)
131
+ if (!itemId) return null
132
+ const quantity = Math.max(1, Math.trunc(finite(line.quantity) || 1))
133
+ const unitPrice =
134
+ finite(line.unit_price) ??
135
+ divide(finite(line.subtotal), finite(line.quantity)) ??
136
+ divide(finite(line.total), finite(line.quantity))
137
+ return clean({
138
+ item_id: itemId,
139
+ item_name: text(line.product_title) || text(line.title) || "Termék",
140
+ item_variant: text(line.variant_title),
141
+ price: unitPrice,
142
+ quantity,
143
+ }) as EcommerceItem
144
+ }
145
+
146
+ function dynamicRemarketingItem(item: EcommerceItem) {
147
+ const id = text(item.item_id)
148
+ if (!id) return null
149
+ return clean({
150
+ id,
151
+ item_id: id,
152
+ google_business_vertical: "retail",
153
+ price: finite(item.price),
154
+ quantity: finite(item.quantity),
155
+ })
156
+ }
157
+
158
+ function sourceItems(source: Record<string, unknown>) {
159
+ return Array.isArray(source.items)
160
+ ? source.items.filter(isRecord)
161
+ : []
162
+ }
163
+
164
+ function googleTarget() {
165
+ const target = window as typeof window & {
166
+ dataLayer?: Array<Record<string, unknown> | unknown[]>
167
+ gtag?: (...args: unknown[]) => void
168
+ }
169
+ target.dataLayer = target.dataLayer || []
170
+ return target as typeof target & { dataLayer: Array<Record<string, unknown> | unknown[]> }
171
+ }
172
+
173
+ function normalizeCurrency(value: unknown) {
174
+ return text(value).toUpperCase() || "HUF"
175
+ }
176
+
177
+ function divide(a?: number, b?: number) {
178
+ if (a === undefined || b === undefined || b === 0) return undefined
179
+ return a / b
180
+ }
181
+
182
+ function record(value: unknown): Record<string, unknown> | undefined {
183
+ return isRecord(value) ? value : undefined
184
+ }
185
+
186
+ function isRecord(value: unknown): value is Record<string, unknown> {
187
+ return Boolean(value && typeof value === "object" && !Array.isArray(value))
188
+ }
189
+
190
+ function clean<T extends Record<string, unknown>>(value: T) {
191
+ return Object.fromEntries(
192
+ Object.entries(value).filter(([, entry]) => entry !== undefined && entry !== null && entry !== ""),
193
+ )
194
+ }
195
+
49
196
  function text(value: unknown) {
50
197
  return typeof value === "string" || typeof value === "number"
51
198
  ? String(value).trim()
@@ -0,0 +1,26 @@
1
+ import { medusaFetch } from "./client"
2
+ import type { JsonRecord } from "./commerce"
3
+
4
+ export type ReorderSkippedItem = {
5
+ order_item_id: string
6
+ title: string
7
+ variant_id: string | null
8
+ quantity: number
9
+ reason: string
10
+ }
11
+
12
+ export type ReorderResult = {
13
+ cart: JsonRecord
14
+ added_count: number
15
+ skipped_items: ReorderSkippedItem[]
16
+ }
17
+
18
+ export function reorderOrder(orderId: string) {
19
+ return medusaFetch<ReorderResult>(
20
+ `/store/account/orders/${encodeURIComponent(orderId)}/reorder`,
21
+ {
22
+ method: "POST",
23
+ body: JSON.stringify({}),
24
+ },
25
+ )
26
+ }
@@ -14,6 +14,7 @@ export const STOREFRONT_ROUTES = {
14
14
  orders: "/hu/fiokom/rendelesek",
15
15
  resetPassword: "/hu/jelszo-visszaallitas",
16
16
  legal: "/hu/jogi",
17
+ documents: "/hu/dokumentumok",
17
18
  blog: "/hu/blog",
18
19
  knowledgeBase: "/hu/tudastar",
19
20
  cmsPages: "/hu/oldalak",
@@ -35,6 +36,7 @@ export const STOREFRONT_ROUTES = {
35
36
  orders: "/en/account/orders",
36
37
  resetPassword: "/en/reset-password",
37
38
  legal: "/en/legal",
39
+ documents: "/en/documents",
38
40
  blog: "/en/blog",
39
41
  knowledgeBase: "/en/knowledge-base",
40
42
  cmsPages: "/en/pages",
@@ -123,6 +125,7 @@ export function equivalentLocalePath(
123
125
  }
124
126
  if (pathname === source.resetPassword) return target.resetPassword
125
127
  if (pathname === source.legal) return target.legal
128
+ if (pathname === source.documents) return target.documents
126
129
  if (pathname === source.blog) return target.blog
127
130
  if (pathname.startsWith(`${source.blog}/`)) return `${target.blog}/${pathname.slice(source.blog.length + 1)}`
128
131
  if (pathname === source.knowledgeBase) return target.knowledgeBase
@@ -63,6 +63,7 @@ function legacyRedirect(pathname: string, locale: StorefrontLocale) {
63
63
  if (pathname.startsWith("/account/orders/")) return `${STOREFRONT_ROUTES[locale].orders}/${pathname.slice("/account/orders/".length)}`
64
64
  if (pathname === "/reset-password") return STOREFRONT_ROUTES[locale].resetPassword
65
65
  if (pathname === "/legal") return STOREFRONT_ROUTES[locale].legal
66
+ if (pathname === "/documents") return STOREFRONT_ROUTES[locale].documents
66
67
  if (pathname === "/blog") return STOREFRONT_ROUTES[locale].blog
67
68
  if (pathname.startsWith("/blog/")) return `${STOREFRONT_ROUTES[locale].blog}/${pathname.slice("/blog/".length)}`
68
69
  if (pathname === "/knowledge-base") return STOREFRONT_ROUTES[locale].knowledgeBase
@@ -114,6 +115,7 @@ function internalRewrite(pathname: string, locale: StorefrontLocale) {
114
115
  if (pathname.startsWith(`${routes.orders}/`)) return `/account/orders/${pathname.slice(routes.orders.length + 1)}`
115
116
  if (pathname === routes.resetPassword) return "/reset-password"
116
117
  if (pathname === routes.legal) return "/legal"
118
+ if (pathname === routes.documents) return "/documents"
117
119
  if (pathname === routes.blog) return "/blog"
118
120
  if (pathname.startsWith(`${routes.blog}/`)) return `/blog/${pathname.slice(routes.blog.length + 1)}`
119
121
  if (pathname === routes.knowledgeBase) return "/knowledge-base"
@@ -0,0 +1,69 @@
1
+ import assert from "node:assert/strict"
2
+ import test from "node:test"
3
+ import { normalizeCarrierPickupPoint, carrierPointToShippingData } from "../src/components/carrier-pickup-adapter.ts"
4
+
5
+ test("FOXPOST 2in1 point preserves operator and place ID", () => {
6
+ const point = normalizeCarrierPickupPoint("foxpost", {
7
+ place_id: 1250198, operator_id: "hu5516", name: "Gabi Cukrászat",
8
+ zip: "9081", city: "Győrújbarát", address: "9081 Győrújbarát, István utca 67.",
9
+ })
10
+ assert.ok(point)
11
+ const payload = carrierPointToShippingData(point)
12
+ assert.equal(payload.foxpost.locker.operatorId, "hu5516")
13
+ assert.equal(payload.foxpost.locker.placeId, "1250198")
14
+ assert.equal(payload.foxpost.locker.postalCode, "9081")
15
+ })
16
+
17
+ test("GLS map detail uses contact country/zip/city/address", () => {
18
+ const point = normalizeCarrierPickupPoint("gls", {
19
+ id: "1011-ALPHAZOOKF", name: "Alpha Zoo", contact: {
20
+ countryCode: "HU", postalCode: "1011", city: "Budapest", address: "Batthyány tér 5.",
21
+ },
22
+ })
23
+ assert.ok(point)
24
+ const payload = carrierPointToShippingData(point)
25
+ assert.equal(payload.gls.deliveryPoint.id, "1011-ALPHAZOOKF")
26
+ assert.equal(payload.gls.deliveryPoint.postalCode, "1011")
27
+ assert.equal(payload.gls.deliveryPoint.address, "Batthyány tér 5.")
28
+ })
29
+
30
+ test("Packeta widget keeps carrier pickup point metadata", () => {
31
+ const point = normalizeCarrierPickupPoint("packeta", {
32
+ id: 12345, name: "Z-BOX", zip: "8000", city: "Székesfehérvár",
33
+ street: "Kossuth utca 1.", carrierId: 10, carrierPickupPoint: "10-12345",
34
+ })
35
+ assert.ok(point)
36
+ const payload = carrierPointToShippingData(point)
37
+ assert.equal(payload.packeta.pickupPoint.id, "12345")
38
+ assert.equal(payload.packeta.pickupPoint.carrierId, "10")
39
+ })
40
+
41
+ test("DPD pickup ID survives provider payload conversion", () => {
42
+ const point = normalizeCarrierPickupPoint("dpd", {
43
+ id: "HU1234", name: "DPD Pickup", zipCode: "8000",
44
+ city: "Székesfehérvár", street: "Fő utca 1.", countryCode: "HU",
45
+ })
46
+ assert.ok(point)
47
+ const payload = carrierPointToShippingData(point)
48
+ assert.equal(payload.dpd.pickupPoint.id, "HU1234")
49
+ assert.equal(payload.dpd.pickupPoint.countryCode, "HU")
50
+ })
51
+
52
+ test("MPL PostaPont callback keeps official point ID and location", () => {
53
+ const point = normalizeCarrierPickupPoint("mpl", {
54
+ id: "PP123", name: "PostaPont", zip: "8000",
55
+ country: "Székesfehérvár", address: "Fő utca 1.", group: "10_posta",
56
+ deliveryMode: "PM",
57
+ })
58
+ assert.ok(point)
59
+ const payload = carrierPointToShippingData(point)
60
+ assert.equal(payload.mpl.pickupPoint.id, "PP123")
61
+ assert.equal(payload.mpl.pickupPoint.city, "Székesfehérvár")
62
+ assert.equal(payload.mpl.pickupPoint.deliveryMode, "PM")
63
+ })
64
+
65
+ test("invalid or incomplete widget selection is rejected", () => {
66
+ assert.equal(normalizeCarrierPickupPoint("foxpost", { name: "Incomplete", city: "Budapest" }), null)
67
+ assert.equal(normalizeCarrierPickupPoint("gls", { id: "X", name: "Incomplete" }), null)
68
+ assert.equal(normalizeCarrierPickupPoint("packeta", null), null)
69
+ })