export async function processRecord()

in lambda/recipes-responder/src/main.ts [38:128]


export async function processRecord({
	eventDetail,
	staticBucketName,
	fastlyApiKey,
	contentPrefix,
	outgoingEventBus,
}: {
	eventDetail: CrierEventDetail;
	staticBucketName: string;
	fastlyApiKey: string;
	contentPrefix: string;
	outgoingEventBus: string;
}): Promise<number> {
	if (eventDetail.channels && !eventDetail.channels.includes('feast')) {
		console.error(
			`Received a CrierEvent for channels ${eventDetail.channels.join()}, which did not include Feast! This is a configuration bug :(`,
		);
		return 0;
	}

	try {
		const evt = deserializeEvent(eventDetail.event);

		//we're only interested in content updates
		if (evt.itemType != ItemType.CONTENT) return 0;

		console.log(
			`DEBUG Received event of type ${evt.eventType} for item of type ${evt.itemType}`,
		);
		switch (evt.eventType) {
			case EventType.DELETE:
				if (
					filterProductionMonitoring &&
					evt.payloadId.startsWith('production-monitoring')
				) {
					return 0;
				}
				return handleTakedown({
					event: evt,
					staticBucketName,
					fastlyApiKey,
					contentPrefix,
					outgoingEventBus,
				});
			case EventType.UPDATE:
			case EventType.RETRIEVABLEUPDATE:
				switch (evt.payload?.kind) {
					case undefined: {
						console.log('DEBUG Event had no payload');
						break;
					}
					case 'content': {
						return handleContentUpdate({
							content: evt.payload.content,
							staticBucketName,
							fastlyApiKey,
							contentPrefix,
							outgoingEventBus,
						});
					}
					case 'retrievableContent': {
						const { capiUrl, contentType, internalRevision } =
							evt.payload.retrievableContent;
						return handleContentUpdateByCapiUrl({
							capiUrl,
							contentType,
							internalRevision,
							staticBucketName,
							fastlyApiKey,
							contentPrefix,
							outgoingEventBus,
						});
					}
					case 'deletedContent': {
						return handleDeletedContent(evt.payload.deletedContent);
					}
					default:
						break;
				}
				break;
			default:
				console.error('ERROR Unknown event type ', evt.eventType);
		}
		return 0; //if we get here, no action was taken
	} catch (err) {
		console.error(
			`ERROR Could not process data from Kinesis: ${(err as Error).toString()}`,
		);
		return 0;
	}
}