in poller-lambdas/src/pollers/ap/apPoller.ts [148:216]
function itemWithContentToDesiredOutput({
feedItem,
originalXmlContent,
contentFromNitf,
}: {
feedItem: Contentitem;
originalXmlContent: string;
contentFromNitf: ContentFromNitf;
}): IngestorPayload {
/**
* We want our external id to be unique for each revision of a content item; the 'etag' field fits the criteria:
* "The ETag value is a unique token for each revision of a content item, which changes not only when there are updates to the story body or item metadata, but also to any item component; for example, if new linked curated media or media renditions are added to the content item."
* https://api.ap.org/media/v/docs/#t=Managing_Revisions_and_Duplicates.htm
*/
const externalId = feedItem.altids?.etag ?? 'no-external-id';
const {
type,
pubstatus,
title,
headline,
editorialpriority,
firstcreated,
versioncreated,
bylines,
ednote,
subject,
keywords,
associations,
} = feedItem;
const { abstract, bodyContentHtml } = contentFromNitf;
const bylineToUse = bylines
? [...bylines].map((byline) => byline.by).join(', ')
: contentFromNitf.byline;
const directSubjects =
subject?.filter((s) => s.rels?.includes('direct')).map((s) => s.name) ?? [];
const keywordsAsArray = keywords?.flatMap((k) => k.split(' ')) ?? [];
const amalgamatedKeywords = [...directSubjects, ...keywordsAsArray];
return {
externalId,
body: {
'source-feed': 'AP-Newswires',
version: feedItem.version?.toString() ?? '0',
type: type,
status: pubstatus,
firstVersion: firstcreated,
versionCreated: versioncreated,
headline: title ?? headline ?? contentFromNitf.headline,
byline: bylineToUse,
priority: editorialpriority,
keywords: amalgamatedKeywords,
body_text: bodyContentHtml,
abstract,
originalContentText: originalXmlContent,
ednote,
imageIds: associations
? Object.keys(associations)
.filter((key) => associations[key]?.type === 'picture')
.map((key) => associations[key]?.altids?.itemid)
.filter((item): item is string => item !== undefined)
: [],
},
};
}