20 lines
612 B
TypeScript
20 lines
612 B
TypeScript
export const getAnalysisElementMedusaProductIds = (products: ({ metadata?: { analysisElementMedusaProductIds?: string } | null } | null)[]) => {
|
|
if (!products) {
|
|
return [];
|
|
}
|
|
|
|
const mapped = products
|
|
.flatMap((product) => {
|
|
const value = product?.metadata?.analysisElementMedusaProductIds;
|
|
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)];
|
|
}
|