@pradip1995/commerce-core 1.0.0 → 1.1.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pradip1995/commerce-core",
3
- "version": "1.0.0",
3
+ "version": "1.1.4",
4
4
  "description": "Medusa storefront commerce logic — data, domain, hooks, types, utils",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -67,6 +67,13 @@ export interface DynamicConfig {
67
67
  }
68
68
  }
69
69
 
70
+ /** Treat empty strings from dynamic config as missing so theme defaults apply. */
71
+ function nonEmpty(value: string | null | undefined): string | null {
72
+ if (value == null) return null
73
+ const trimmed = value.trim()
74
+ return trimmed.length > 0 ? trimmed : null
75
+ }
76
+
70
77
  export const getDynamicConfig = cache(async (): Promise<DynamicConfig | null> => {
71
78
  try {
72
79
  const publishableKey = process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY
@@ -113,7 +120,7 @@ export const getLogoFromConfig = async (): Promise<string | null> => {
113
120
  const config = await getDynamicConfig()
114
121
  const logo = config?.["homepage-config"]?.logo
115
122
 
116
- return logo || null
123
+ return nonEmpty(logo)
117
124
  } catch (error) {
118
125
  return null
119
126
  }
@@ -178,14 +185,14 @@ export const getHomeBannersFromConfig = async (): Promise<Array<{
178
185
  return bannerArray.map((item) => {
179
186
  const banner = item["homepage-banner"]
180
187
  return {
181
- image: banner?.["homepage-banner-image"],
182
- title: banner?.["homepage-banner-title"],
183
- subtitle: banner?.["homepage-banner-subtitle"],
184
- description: banner?.["homepage-banner-description"],
185
- buttonName: banner?.["homepage-banner-button-name"],
186
- buttonLink: banner?.["homepage-banner-button-link"],
188
+ image: nonEmpty(banner?.["homepage-banner-image"]) ?? undefined,
189
+ title: nonEmpty(banner?.["homepage-banner-title"]) ?? undefined,
190
+ subtitle: nonEmpty(banner?.["homepage-banner-subtitle"]) ?? undefined,
191
+ description: nonEmpty(banner?.["homepage-banner-description"]) ?? undefined,
192
+ buttonName: nonEmpty(banner?.["homepage-banner-button-name"]) ?? undefined,
193
+ buttonLink: nonEmpty(banner?.["homepage-banner-button-link"]) ?? undefined,
187
194
  }
188
- })
195
+ }).filter((b) => b.image || b.title || b.subtitle)
189
196
  }
190
197
  return null
191
198
  } catch (error) {
@@ -209,14 +216,14 @@ export const getAppBannersFromConfig = async (): Promise<Array<{
209
216
  return bannerArray.map((item) => {
210
217
  const banner = item["app-banner"]
211
218
  return {
212
- image: banner?.["app-banner-image"],
213
- title: banner?.["app-banner-title"],
214
- subtitle: banner?.["app-banner-subtitle"],
215
- description: banner?.["app-banner-description"],
216
- buttonName: banner?.["app-banner-button-name"],
217
- buttonLink: banner?.["app-banner-button-link"],
219
+ image: nonEmpty(banner?.["app-banner-image"]) ?? undefined,
220
+ title: nonEmpty(banner?.["app-banner-title"]) ?? undefined,
221
+ subtitle: nonEmpty(banner?.["app-banner-subtitle"]) ?? undefined,
222
+ description: nonEmpty(banner?.["app-banner-description"]) ?? undefined,
223
+ buttonName: nonEmpty(banner?.["app-banner-button-name"]) ?? undefined,
224
+ buttonLink: nonEmpty(banner?.["app-banner-button-link"]) ?? undefined,
218
225
  }
219
- })
226
+ }).filter((b) => b.image || b.title || b.subtitle)
220
227
  }
221
228
  return null
222
229
  } catch (error) {
@@ -0,0 +1,26 @@
1
+ export type ThemeDefaultAssets = {
2
+ logo: string
3
+ heroDesktop: string
4
+ heroMobile: string
5
+ }
6
+
7
+ /** Static fallbacks when dynamic config has no image URL. Copied to public/theme-defaults/<theme>/ on scaffold. */
8
+ export const THEME_DEFAULT_ASSETS: Record<string, ThemeDefaultAssets> = {
9
+ valero: {
10
+ logo: "/theme-defaults/valero/logo.svg",
11
+ heroDesktop: "/theme-defaults/valero/hero-desktop.svg",
12
+ heroMobile: "/theme-defaults/valero/hero-mobile.svg",
13
+ },
14
+ impulse: {
15
+ logo: "/theme-defaults/impulse/logo.svg",
16
+ heroDesktop: "/theme-defaults/impulse/hero-desktop.svg",
17
+ heroMobile: "/theme-defaults/impulse/hero-mobile.svg",
18
+ },
19
+ }
20
+
21
+ export function getThemeDefaultAssets(theme?: string): ThemeDefaultAssets {
22
+ const slug = (theme || process.env.NEXT_PUBLIC_STOREFRONT_THEME || "valero")
23
+ .toLowerCase()
24
+ .trim()
25
+ return THEME_DEFAULT_ASSETS[slug] ?? THEME_DEFAULT_ASSETS.valero
26
+ }