@pradip1995/framework-runtime 0.2.4 → 0.2.5

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.4",
3
+ "version": "0.2.5",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -16,7 +16,7 @@
16
16
  "dependencies": {
17
17
  "@pradip1995/framework-core": "0.2.1",
18
18
  "@pradip1995/plugin-sdk": "0.2.1",
19
- "@pradip1995/medusa-connector": "0.2.1"
19
+ "@pradip1995/medusa-connector": "0.2.2"
20
20
  },
21
21
  "peerDependencies": {
22
22
  "next": ">=15",
@@ -1,12 +1,19 @@
1
1
  import { buildRouteContext } from "@pradip1995/framework-core"
2
2
  import { resolveServices } from "./register-services"
3
- import { applyBuilderDataToWorkflow, getSegmentProps } from "./segment-props"
3
+ import {
4
+ applyChromeSegmentData,
5
+ applyBuilderDataToWorkflow,
6
+ resolveSegmentProps,
7
+ type ChromeSegmentRef,
8
+ } from "./segment-props"
4
9
  import type { BuilderSegmentDataFile } from "./builder-data"
5
10
  import type { ComponentType, ReactNode } from "react"
6
11
 
7
12
  export type SegmentEntry = {
8
13
  pkg: string
9
14
  Component: ComponentType<Record<string, unknown>>
15
+ /** CMS values from pages.config.json, shaped by segment builder.settings.json */
16
+ data?: Record<string, unknown>
10
17
  }
11
18
 
12
19
  export type ConfiguredPage = {
@@ -25,7 +32,11 @@ export type RenderConfiguredPageInput = {
25
32
  countryCode: string
26
33
  slug: string[]
27
34
  searchParams: Record<string, string | string[] | undefined>
28
- /** CMS overrides from storefront/builder/segment-data.json */
35
+ /** Global layout chrome from pages.config.json chrome[] */
36
+ chrome?: ChromeSegmentRef[] | null
37
+ /** @deprecated legacy global overlay */
38
+ pageSegmentData?: BuilderSegmentDataFile | null
39
+ /** @deprecated use chrome + inline segment data */
29
40
  builderSegmentData?: BuilderSegmentDataFile | null
30
41
  }
31
42
 
@@ -46,7 +57,13 @@ export async function renderConfiguredPage(input: RenderConfiguredPageInput): Pr
46
57
  const route = buildRouteContext(input.countryCode, input.slug, input.searchParams)
47
58
  const services = await resolveServices()
48
59
  const workflowData = await input.page.workflow.execute({ route, services })
49
- const data = applyBuilderDataToWorkflow(workflowData, input.builderSegmentData)
60
+
61
+ const legacyOverlay = input.pageSegmentData ?? input.builderSegmentData
62
+ let data = legacyOverlay
63
+ ? applyBuilderDataToWorkflow(workflowData, legacyOverlay)
64
+ : workflowData
65
+ data = applyChromeSegmentData(data, input.chrome)
66
+
50
67
  const Layout = input.page.layout
51
68
 
52
69
  if (data.notFound) {
@@ -62,8 +79,8 @@ export async function renderConfiguredPage(input: RenderConfiguredPageInput): Pr
62
79
  )
63
80
  }
64
81
 
65
- const segmentElements = input.page.segments.map(({ pkg, Component: Segment }) => {
66
- const props = getSegmentProps(pkg, data)
82
+ const segmentElements = input.page.segments.map(({ pkg, Component: Segment, data: inline }) => {
83
+ const props = resolveSegmentProps(pkg, data, inline)
67
84
  return <Segment key={pkg} {...props} />
68
85
  })
69
86
 
@@ -13,7 +13,9 @@ export type RenderPageInput = {
13
13
  searchParams: Record<string, string | string[] | undefined>
14
14
  routeManifest: PageConfigEntry[]
15
15
  importMap: ImportMap
16
- /** CMS overrides from storefront/builder/segment-data.json */
16
+ /** CMS values from pages.config.json segmentData */
17
+ pageSegmentData?: BuilderSegmentDataFile | null
18
+ /** @deprecated use pageSegmentData */
17
19
  builderSegmentData?: BuilderSegmentDataFile | null
18
20
  }
19
21
 
@@ -46,7 +48,8 @@ export async function renderPage(input: RenderPageInput): Promise<ReactNode> {
46
48
  }
47
49
 
48
50
  const workflowData = await workflowMod.default.execute({ route, services })
49
- const data = applyBuilderDataToWorkflow(workflowData, input.builderSegmentData)
51
+ const pageSegmentData = input.pageSegmentData ?? input.builderSegmentData
52
+ const data = applyBuilderDataToWorkflow(workflowData, pageSegmentData)
50
53
 
51
54
  const layoutMod = (await resolvePlugin(input.importMap, page!.layout)) as {
52
55
  default: ComponentType<{ data: Record<string, unknown>; children: ReactNode }>
@@ -55,6 +55,89 @@ export function getSegmentProps(
55
55
  return { [key]: value }
56
56
  }
57
57
 
58
+ function mergeSegmentRecords(
59
+ base: Record<string, unknown>,
60
+ overlay: Record<string, unknown>
61
+ ): Record<string, unknown> {
62
+ const result = { ...base }
63
+ for (const [key, value] of Object.entries(overlay)) {
64
+ const existing = result[key]
65
+ if (
66
+ value &&
67
+ typeof value === "object" &&
68
+ !Array.isArray(value) &&
69
+ existing &&
70
+ typeof existing === "object" &&
71
+ !Array.isArray(existing)
72
+ ) {
73
+ result[key] = mergeSegmentRecords(
74
+ existing as Record<string, unknown>,
75
+ value as Record<string, unknown>
76
+ )
77
+ } else {
78
+ result[key] = value
79
+ }
80
+ }
81
+ return result
82
+ }
83
+
84
+ export function resolveSegmentProps(
85
+ segmentPkg: string,
86
+ workflowData: Record<string, unknown>,
87
+ inlineData?: Record<string, unknown> | null
88
+ ): Record<string, unknown> {
89
+ const base = getSegmentProps(segmentPkg, workflowData)
90
+
91
+ const layoutCart = workflowData.cart
92
+ if (
93
+ layoutCart &&
94
+ typeof layoutCart === "object" &&
95
+ (segmentPkg === "@pradip1995/segment-product-actions" ||
96
+ segmentPkg === "@pradip1995/segment-product-info") &&
97
+ !("cart" in base)
98
+ ) {
99
+ base.cart = layoutCart
100
+ }
101
+
102
+ if (!inlineData || Object.keys(inlineData).length === 0) return base
103
+ return mergeSegmentRecords(base, inlineData)
104
+ }
105
+
106
+ export type ChromeSegmentRef = string | { package: string; data?: Record<string, unknown> }
107
+
108
+ function chromePackageName(ref: ChromeSegmentRef): string {
109
+ return typeof ref === "string" ? ref : ref.package
110
+ }
111
+
112
+ function chromeInlineData(ref: ChromeSegmentRef): Record<string, unknown> | undefined {
113
+ return typeof ref === "string" ? undefined : ref.data
114
+ }
115
+
116
+ /** Merge global chrome segment data (nav, footer, promo) into workflow output for layout. */
117
+ export function applyChromeSegmentData(
118
+ workflowData: Record<string, unknown>,
119
+ chrome: ChromeSegmentRef[] | null | undefined
120
+ ): Record<string, unknown> {
121
+ if (!chrome?.length) return workflowData
122
+ const merged = { ...workflowData }
123
+
124
+ for (const ref of chrome) {
125
+ const pkg = chromePackageName(ref)
126
+ const data = chromeInlineData(ref)
127
+ const key = SEGMENT_DATA_KEYS[pkg]
128
+ if (!key || !data || Object.keys(data).length === 0) continue
129
+
130
+ const existing = merged[key]
131
+ if (existing && typeof existing === "object" && !Array.isArray(existing)) {
132
+ merged[key] = mergeSegmentRecords(existing as Record<string, unknown>, data)
133
+ } else {
134
+ merged[key] = { ...data }
135
+ }
136
+ }
137
+
138
+ return merged
139
+ }
140
+
58
141
  export function applyBuilderDataToWorkflow(
59
142
  workflowData: Record<string, unknown>,
60
143
  builderData: BuilderSegmentDataFile | null | undefined