@pradip1995/framework-runtime 0.2.6 → 0.2.8

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/framework-runtime",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -14,9 +14,9 @@
14
14
  "./render-page": "./src/render-page.tsx"
15
15
  },
16
16
  "dependencies": {
17
- "@pradip1995/plugin-sdk": "0.2.1",
18
- "@pradip1995/framework-core": "0.2.1",
19
- "@pradip1995/medusa-connector": "0.2.2"
17
+ "@pradip1995/framework-core": "^0.2.1",
18
+ "@pradip1995/plugin-sdk": "^0.2.2",
19
+ "@pradip1995/medusa-connector": "^0.2.4"
20
20
  },
21
21
  "peerDependencies": {
22
22
  "next": ">=15",
package/src/index.ts CHANGED
@@ -8,4 +8,5 @@ export {
8
8
  export { mergeBuilderSegmentData } from "./builder-data"
9
9
  export type { RenderPageInput } from "./render-page"
10
10
  export type { ConfiguredPage, RenderConfiguredPageInput, SegmentEntry } from "./render-configured-page"
11
+ export type { SiteConfig } from "./segment-props"
11
12
  export type { BuilderSegmentDataFile } from "./builder-data"
@@ -3,8 +3,10 @@ import { resolveServices } from "./register-services"
3
3
  import {
4
4
  applyChromeSegmentData,
5
5
  applyBuilderDataToWorkflow,
6
+ applySiteConfig,
6
7
  resolveSegmentProps,
7
8
  type ChromeSegmentRef,
9
+ type SiteConfig,
8
10
  } from "./segment-props"
9
11
  import type { BuilderSegmentDataFile } from "./builder-data"
10
12
  import type { ComponentType, ReactNode } from "react"
@@ -34,6 +36,8 @@ export type RenderConfiguredPageInput = {
34
36
  searchParams: Record<string, string | string[] | undefined>
35
37
  /** Global layout chrome from pages.config.json chrome[] */
36
38
  chrome?: ChromeSegmentRef[] | null
39
+ /** Store branding defaults from pages.config.json site */
40
+ site?: SiteConfig | null
37
41
  /** @deprecated legacy global overlay */
38
42
  pageSegmentData?: BuilderSegmentDataFile | null
39
43
  /** @deprecated use chrome + inline segment data */
@@ -63,6 +67,7 @@ export async function renderConfiguredPage(input: RenderConfiguredPageInput): Pr
63
67
  ? applyBuilderDataToWorkflow(workflowData, legacyOverlay)
64
68
  : workflowData
65
69
  data = applyChromeSegmentData(data, input.chrome)
70
+ data = applySiteConfig(data, input.site)
66
71
 
67
72
  const Layout = input.page.layout
68
73
 
@@ -108,12 +108,92 @@ export function resolveSegmentProps(
108
108
  base.cart = layoutCart
109
109
  }
110
110
 
111
- if (!inlineData || Object.keys(inlineData).length === 0) return base
112
- return mergeSegmentRecords(base, inlineData)
111
+ if (!inlineData || Object.keys(inlineData).length === 0) {
112
+ return applyStorefrontDefaults(base, workflowData)
113
+ }
114
+ return applyStorefrontDefaults(mergeSegmentRecords(base, inlineData), workflowData)
115
+ }
116
+
117
+ function applyStorefrontDefaults(
118
+ props: Record<string, unknown>,
119
+ workflowData: Record<string, unknown>
120
+ ): Record<string, unknown> {
121
+ const next = { ...props }
122
+ const variant = workflowData.productCardVariant
123
+ if (
124
+ (variant === "beauty" || variant === "default") &&
125
+ next.variant === undefined
126
+ ) {
127
+ next.variant = variant
128
+ }
129
+
130
+ if (next.shopName === undefined) {
131
+ const nav = workflowData.nav
132
+ const footer = workflowData.footer
133
+ const checkout = workflowData.checkout
134
+ const siteName =
135
+ (nav && typeof nav === "object" && (nav as Record<string, unknown>).shopName) ||
136
+ (footer && typeof footer === "object" && (footer as Record<string, unknown>).shopName) ||
137
+ (checkout && typeof checkout === "object" && (checkout as Record<string, unknown>).shopName)
138
+ if (typeof siteName === "string" && siteName.trim()) {
139
+ next.shopName = siteName
140
+ }
141
+ }
142
+
143
+ if (next.wishlistProductIds === undefined) {
144
+ const ids = workflowData.wishlistProductIds
145
+ if (Array.isArray(ids)) {
146
+ next.wishlistProductIds = ids
147
+ }
148
+ }
149
+
150
+ return next
151
+ }
152
+
153
+ /** Apply pages.config site defaults when chrome/workflow did not set layout fields. */
154
+ export function applySiteConfig(
155
+ workflowData: Record<string, unknown>,
156
+ site: SiteConfig | null | undefined
157
+ ): Record<string, unknown> {
158
+ if (!site) return workflowData
159
+ const merged = { ...workflowData }
160
+
161
+ if (site.productCardVariant) {
162
+ merged.productCardVariant = site.productCardVariant
163
+ }
164
+
165
+ if (site.name) {
166
+ if (merged.nav && typeof merged.nav === "object" && !Array.isArray(merged.nav)) {
167
+ const nav = merged.nav as Record<string, unknown>
168
+ if (!nav.shopName) merged.nav = { ...nav, shopName: site.name }
169
+ }
170
+ if (merged.footer && typeof merged.footer === "object" && !Array.isArray(merged.footer)) {
171
+ const footer = merged.footer as Record<string, unknown>
172
+ if (!footer.shopName) merged.footer = { ...footer, shopName: site.name }
173
+ }
174
+ if (site.name && merged.checkout && typeof merged.checkout === "object" && !Array.isArray(merged.checkout)) {
175
+ const checkout = merged.checkout as Record<string, unknown>
176
+ if (!checkout.shopName) merged.checkout = { ...checkout, shopName: site.name }
177
+ }
178
+ }
179
+
180
+ if (site.description && merged.footer && typeof merged.footer === "object" && !Array.isArray(merged.footer)) {
181
+ const footer = merged.footer as Record<string, unknown>
182
+ if (!footer.description) merged.footer = { ...footer, description: site.description }
183
+ }
184
+
185
+ return merged
113
186
  }
114
187
 
115
188
  export type ChromeSegmentRef = string | { package: string; data?: Record<string, unknown> }
116
189
 
190
+ export type SiteConfig = {
191
+ name?: string
192
+ description?: string
193
+ locale?: string
194
+ productCardVariant?: "default" | "beauty"
195
+ }
196
+
117
197
  function chromePackageName(ref: ChromeSegmentRef): string {
118
198
  return typeof ref === "string" ? ref : ref.package
119
199
  }