export async function removeRecipeContent()

in lib/recipes-data/src/lib/s3.ts [113:174]


export async function removeRecipeContent({
	recipeSHA,
	staticBucketName,
	fastlyApiKey,
	contentPrefix,
	purgeType,
	attempt,
}: {
	recipeSHA: string;
	staticBucketName: string;
	fastlyApiKey: string;
	contentPrefix: string;
	purgeType?: PurgeType;
	attempt?: number;
}): Promise<void> {
	const realAttempt = attempt ?? 1;

	const Key = `content/${recipeSHA}`;

	const req = new DeleteObjectCommand({
		Bucket: staticBucketName,
		Key,
	});

	try {
		await s3Client.send(req);
		await sendFastlyPurgeRequestWithRetries({
			contentPath: Key,
			apiKey: fastlyApiKey,
			contentPrefix,
			purgeType: purgeType ?? 'hard',
		});
	} catch (err) {
		if (err instanceof NoSuchKey) {
			console.log(
				`removeRecipeContent: No recipe existed at version ${recipeSHA} so I could not remove it.`,
			);
			return;
		} else if (err instanceof S3ServiceException) {
			console.warn(`Unable to delete from S3 on attempt ${realAttempt}: `, err);
			if (
				MaximumRetries &&
				!isNaN(MaximumRetries) &&
				realAttempt < MaximumRetries
			) {
				await awaitableDelay();
				return removeRecipeContent({
					recipeSHA,
					staticBucketName: staticBucketName,
					fastlyApiKey,
					contentPrefix,
					purgeType,
					attempt: realAttempt + 1,
				});
			} else {
				throw new Error('Could not delete from S3, see logs for details.');
			}
		} else {
			throw err;
		}
	}
}