Skip to content

Commit 9318034

Browse files
committed
fix: FlexCard compilation error when StylingConfiguration was defined as empty string
1 parent 889aefd commit 9318034

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

packages/vlocity-deploy/src/flexCard/flexCardDefinition.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export interface FlexCardDefinition {
1515
Type?: 'flex' | 'classic';
1616
UniqueName?: string;
1717
PropertySetConfig: string | object;
18-
StylingConfiguration?: any;
18+
StylingConfiguration?: string | object;
1919
Attachments?: any[];
2020
Label?: Record<string, string>;
2121
}
@@ -111,7 +111,7 @@ export namespace FlexCardDefinition {
111111
Type: 'flex',
112112
UniqueName: record.UniqueName,
113113
PropertySetConfig: asString(record.PropertySetConfig),
114-
StylingConfiguration: asString(record.StylingConfiguration)
114+
StylingConfiguration: parseAsJsonString(record.StylingConfiguration),
115115
};
116116
}
117117

@@ -127,9 +127,28 @@ export namespace FlexCardDefinition {
127127
IsChildCard: record.IsChildCard,
128128
Type: record.CardType,
129129
PropertySetConfig: asString(record.Definition),
130-
StylingConfiguration: asString(record.Styles)
130+
StylingConfiguration: parseAsJsonString(record.Styles)
131131
};
132132
}
133+
134+
// eslint-disable-next-line
135+
function parseAsJsonString(data: string | object | undefined): string | undefined {
136+
if (typeof data === 'string') {
137+
try {
138+
const parsed = JSON.parse(data);
139+
if (typeof parsed === 'object') {
140+
return JSON.stringify(parsed);
141+
}
142+
} catch {
143+
// If parsing fails, return the original string if it is not empty
144+
return undefined;
145+
}
146+
}
147+
if (typeof data === 'object' && data) {
148+
return JSON.stringify(data);
149+
}
150+
return undefined;
151+
}
133152
}
134153

135154
export type FlexCardIdentifier = string | { name: string, isChildCard?: boolean, author?: string, version?: number, active?: boolean };

0 commit comments

Comments
 (0)