diff --git a/lib/routes/microsoft/message-center.ts b/lib/routes/microsoft/message-center.ts index 8a720fb41faf..5661ae68b35f 100644 --- a/lib/routes/microsoft/message-center.ts +++ b/lib/routes/microsoft/message-center.ts @@ -46,7 +46,8 @@ export const route: Route = { url: 'mc.merill.net', categories: ['program-update'], example: '/microsoft/message-center', - description: 'Microsoft 365 Message Center archive entries from mc.merill.net.', + description: + 'Microsoft 365 Message Center archive entries from mc.merill.net. The item guid carries the last modification time, so an updated post appears as a new item. The bare message ID (e.g. MC1234567) is in the author field.', features: { requireConfig: false, requirePuppeteer: false, @@ -73,13 +74,12 @@ async function handler(ctx) { const { data: messages }: { data: MessageCenterMessage[] } = await got(dataUrl); if (!Array.isArray(messages)) { - throw new Error('Failed to fetch Microsoft 365 Message Center archive data.'); + throw new TypeError('Failed to fetch Microsoft 365 Message Center archive data.'); } const item = messages - .filter(isMessageCenterMessage) - .slice() - .sort((a, b) => getTimestamp(b) - getTimestamp(a)) + .filter((message) => isMessageCenterMessage(message)) + .toSorted((a, b) => getTimestamp(b) - getTimestamp(a)) .slice(0, pageSize) .map((message): DataItem => { const link = `${rootUrl}/message/${message.Id}`; @@ -93,7 +93,8 @@ async function handler(ctx) { return { title: message.Title, link, - guid: message.Id, + guid: getVersionedGuid(message), + author: message.Id, description, pubDate, updated, @@ -113,6 +114,12 @@ async function handler(ctx) { }; } +function getVersionedGuid(message: MessageCenterMessage) { + const version = message.LastModifiedDateTime || message.StartDateTime; + + return version ? `${message.Id}@${version}` : message.Id; +} + function getTimestamp(message: MessageCenterMessage) { const date = message.LastModifiedDateTime || message.StartDateTime; @@ -120,23 +127,16 @@ function getTimestamp(message: MessageCenterMessage) { } function getCategories(message: MessageCenterMessage, messageCenterCategory?: string) { - const categories = [ - messageCenterCategory, - message.Severity, - ...(message.Services ?? []), - ...(message.Tags ?? []), - ].filter((category): category is string => Boolean(category)); + const categories = [messageCenterCategory, message.Severity, ...(message.Services ?? []), ...(message.Tags ?? [])].filter((category): category is string => !!category); return categories.length ? [...new Set(categories)] : undefined; } function getContent(description: string, messageCenterCategory?: string, severity?: string, endDate?: Date) { const endDateValue = endDate && !Number.isNaN(endDate.getTime()) ? endDate.toISOString() : undefined; - const metadata = [ - messageCenterCategory ? `MessageCenterCategory: ${messageCenterCategory}` : undefined, - severity ? `Severity: ${severity}` : undefined, - endDateValue ? `EndDateTime: ${endDateValue}` : undefined, - ].filter((value): value is string => Boolean(value)); + const metadata = [messageCenterCategory ? `MessageCenterCategory: ${messageCenterCategory}` : undefined, severity ? `Severity: ${severity}` : undefined, endDateValue ? `EndDateTime: ${endDateValue}` : undefined].filter( + (value): value is string => !!value + ); if (!metadata.length) { return { @@ -159,7 +159,7 @@ function getDetailValue(message: MessageCenterMessage, name: string) { } function getMessageCenterCategory(category?: string) { - return category ? categoryLabels[category] ?? category : undefined; + return category ? (categoryLabels[category] ?? category) : undefined; } function getImages(description: string) { @@ -229,7 +229,7 @@ function getAbsoluteUrl(url: string) { try { return new URL(url, rootUrl).href; } catch { - return undefined; + return; } } @@ -260,10 +260,5 @@ function isRoadmapTitle(title: string) { } function escapeHtml(value: string) { - return value - .replaceAll('&', '&') - .replaceAll('<', '<') - .replaceAll('>', '>') - .replaceAll('"', '"') - .replaceAll("'", '''); + return value.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>').replaceAll('"', '"').replaceAll("'", '''); }