sponsorshipType: getSponsorshipTypeNames()

in lib/recipes-data/src/lib/transform.ts [112:164]


							sponsorshipType: getSponsorshipTypeNames(sponsor.sponsorshipType),
							validFrom: sponsor.validFrom?.iso8601,
							validTo: sponsor.validTo?.iso8601,
							targeting: sponsor.targeting?.publishedSince?.iso8601,
						};
				  }),
	});
};

export const addRecipeDatesTransform: (
	recipeDates: RecipeDates,
) => RecipeTransformationFunction = (recipeDates) => {
	return (recipeData) => ({
		...recipeData,
		lastModifiedDate: recipeDates.lastModifiedDate
			? recipeDates.lastModifiedDate.toISOString()
			: undefined,
		firstPublishedDate: recipeDates.firstPublishedDate
			? recipeDates.firstPublishedDate.toISOString()
			: undefined,
		publishedDate: recipeDates.publishedDate
			? recipeDates.publishedDate.toISOString()
			: undefined,
	});
};

export const replaceCanonicalArticle: (
	canonicalArticle: string,
) => RecipeTransformationFunction = (canonicalArticle) => (recipeData) => ({
	...recipeData,
	canonicalArticle,
});

/**
 * Replace the featured and preview image URLs, which are by convention full-resolution crops,
 * with Fastly resizer urls. Allows us to serve lower resolution assets to the app.
 */
export const replaceImageUrlsWithFastly = <
	R extends Record<string, unknown> & RecipeWithImageData,
>(
	recipe: R,
): R => {
	if (
		typeof recipe.featuredImage === 'string' ||
		typeof recipe.previewImage === 'string'
	) {
		return recipe;
	}

	try {
		return {
			...recipe,
			previewImage: replaceFastlyUrl({