24 lines
644 B
TypeScript
24 lines
644 B
TypeScript
export const getAnalysisElementMedusaProductIds = (products: ({
|
|
metadata?: {
|
|
analysisElementMedusaProductIds?: string;
|
|
} | null;
|
|
} | null)[]) => {
|
|
if (!products) {
|
|
return [];
|
|
}
|
|
|
|
const mapped = products
|
|
.flatMap((product) => {
|
|
const value = product?.metadata?.analysisElementMedusaProductIds?.replaceAll("'", '"');
|
|
try {
|
|
return JSON.parse(value as string);
|
|
} catch (e) {
|
|
console.error("Failed to parse analysisElementMedusaProductIds from analysis package, possibly invalid format", e);
|
|
return [];
|
|
}
|
|
})
|
|
.filter(Boolean) as string[];
|
|
|
|
return [...new Set(mapped)];
|
|
}
|