@aglyn/aglyn 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +11 -11
- package/src/lib/app-utils/health-report.d.ts +39 -0
- package/src/lib/app-utils/health-report.js +41 -0
- package/src/lib/app-utils/health-report.js.map +1 -1
- package/src/lib/app-utils/weekly-summary.d.ts +15 -4
- package/src/lib/app-utils/weekly-summary.js +76 -21
- package/src/lib/app-utils/weekly-summary.js.map +1 -1
- package/src/lib/plugin-manager/plugin-figures.d.ts +22 -2
- package/src/lib/plugin-manager/plugin-figures.js +5 -0
- package/src/lib/plugin-manager/plugin-figures.js.map +1 -1
|
@@ -76,11 +76,19 @@ export declare function figureStat(table: PluginFigureTable, row: PluginFigureRo
|
|
|
76
76
|
many: string;
|
|
77
77
|
};
|
|
78
78
|
}): PluginFigureSummaryStat;
|
|
79
|
-
/** The named rows with the most of `key`, as ranked rows; `[]` when none has any. */
|
|
79
|
+
/** The named rows with the most of `key`, as ranked rows with their change; `[]` when none has any. */
|
|
80
80
|
export declare function figureRanked(table: PluginFigureTable, nameKey: string, key: string, rows?: readonly PluginFigureRow[]): Array<{
|
|
81
81
|
label: string;
|
|
82
82
|
value: string;
|
|
83
|
+
change?: number;
|
|
83
84
|
}>;
|
|
85
|
+
/** A table of days as a chart, oldest first, the busiest marked; `[]` for a week with nothing in it. */
|
|
86
|
+
export declare function figureBars(table: PluginFigureTable, dayKey: string, key: string): NonNullable<PluginFigureSummaryPart['bars']>;
|
|
87
|
+
/** A row's label as a person reads it, and the page it names, when it names one. */
|
|
88
|
+
export declare function weeklySummaryRowLink(label: string, siteUrl: string | null): {
|
|
89
|
+
label: string;
|
|
90
|
+
url: string | null;
|
|
91
|
+
};
|
|
84
92
|
/** "1 order", "18 orders". */
|
|
85
93
|
export declare function figurePlural(count: number, one: string, many: string): string;
|
|
86
94
|
/** One site's figures for the week. */
|
|
@@ -149,7 +157,7 @@ export interface WeeklySummarySectionBar {
|
|
|
149
157
|
display: string;
|
|
150
158
|
marked: boolean;
|
|
151
159
|
}
|
|
152
|
-
/** One topic of
|
|
160
|
+
/** One topic of a weekly email, told once: what stood out, and the figures behind it. */
|
|
153
161
|
export interface WeeklySummarySection {
|
|
154
162
|
title: string;
|
|
155
163
|
/** Where the figures can be seen in full. */
|
|
@@ -162,13 +170,14 @@ export interface WeeklySummarySection {
|
|
|
162
170
|
headline: string | null;
|
|
163
171
|
text: string | null;
|
|
164
172
|
}>;
|
|
173
|
+
stats?: readonly PluginFigureSummaryStat[];
|
|
165
174
|
rows?: readonly WeeklySummarySectionRow[];
|
|
166
175
|
bars?: readonly WeeklySummarySectionBar[];
|
|
167
176
|
}
|
|
168
177
|
/** Tiles on their own, for an email that leads with its headline figures. */
|
|
169
178
|
export declare function weeklySummaryTilesHtml(stats: readonly PluginFigureSummaryStat[], colors: WeeklySummaryColors): string;
|
|
170
|
-
/**
|
|
171
|
-
export declare function weeklySummarySectionsHtml(sections: readonly WeeklySummarySection[], colors: WeeklySummaryColors): string;
|
|
179
|
+
/** A weekly email's topics, a hairline between them; `following` when something already sits above the first. */
|
|
180
|
+
export declare function weeklySummarySectionsHtml(sections: readonly WeeklySummarySection[], colors: WeeklySummaryColors, following?: boolean): string;
|
|
172
181
|
/** The small print under the button, with its one link. */
|
|
173
182
|
export declare function weeklySummaryFootnoteHtml(text: string, link: {
|
|
174
183
|
label: string;
|
|
@@ -183,6 +192,8 @@ export interface WeeklySummaryEmail {
|
|
|
183
192
|
period: string;
|
|
184
193
|
/** The figures, drawn. */
|
|
185
194
|
html: string;
|
|
195
|
+
/** The small print under the button. */
|
|
196
|
+
footnote: string;
|
|
186
197
|
/** The whole email as plain text, closing line included. */
|
|
187
198
|
text: string;
|
|
188
199
|
buttonLabel: string;
|
|
@@ -105,15 +105,38 @@ const ISO_DAY = /\b\d{4}-\d{2}-\d{2}\b/g;
|
|
|
105
105
|
}, options.total)
|
|
106
106
|
} : {});
|
|
107
107
|
}
|
|
108
|
-
/** The named rows with the most of `key`, as ranked rows; `[]` when none has any. */ export function figureRanked(table, nameKey, key, rows = table.rows) {
|
|
108
|
+
/** The named rows with the most of `key`, as ranked rows with their change; `[]` when none has any. */ export function figureRanked(table, nameKey, key, rows = table.rows) {
|
|
109
109
|
return rows.filter((row)=>typeof row[nameKey] === 'string' && figureCount(row[key]) > 0).slice(0, WEEKLY_SUMMARY_TOP_ROWS).map((row)=>{
|
|
110
110
|
var _row_key;
|
|
111
|
-
|
|
111
|
+
const change = row['change'];
|
|
112
|
+
return _extends({
|
|
112
113
|
label: String(row[nameKey]),
|
|
113
114
|
value: pluginFigureCellText(table, key, (_row_key = row[key]) != null ? _row_key : 0)
|
|
115
|
+
}, typeof change === 'number' ? {
|
|
116
|
+
change
|
|
117
|
+
} : {});
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
/** A table of days as a chart, oldest first, the busiest marked; `[]` for a week with nothing in it. */ export function figureBars(table, dayKey, key) {
|
|
121
|
+
const most = Math.max(...table.rows.map((row)=>figureCount(row[key])), 0);
|
|
122
|
+
if (!most) return [];
|
|
123
|
+
return table.rows.map((row)=>{
|
|
124
|
+
var _row_key;
|
|
125
|
+
return {
|
|
126
|
+
label: weeklySummaryWeekday(String(row[dayKey])),
|
|
127
|
+
value: figureCount(row[key]),
|
|
128
|
+
display: pluginFigureCellText(table, key, (_row_key = row[key]) != null ? _row_key : 0),
|
|
129
|
+
marked: figureCount(row[key]) === most
|
|
114
130
|
};
|
|
115
131
|
});
|
|
116
132
|
}
|
|
133
|
+
/** A row's label as a person reads it, and the page it names, when it names one. */ export function weeklySummaryRowLink(label, siteUrl) {
|
|
134
|
+
const page = label.startsWith('/');
|
|
135
|
+
return {
|
|
136
|
+
label: label === '/' ? 'Home' : label,
|
|
137
|
+
url: page && siteUrl ? `${siteUrl}${label === '/' ? '' : label}` : null
|
|
138
|
+
};
|
|
139
|
+
}
|
|
117
140
|
/** "1 order", "18 orders". */ export function figurePlural(count, one, many) {
|
|
118
141
|
return `${count.toLocaleString('en-US')} ${count === 1 ? one : many}`;
|
|
119
142
|
}
|
|
@@ -218,10 +241,6 @@ function changeHtml(change, colors) {
|
|
|
218
241
|
});
|
|
219
242
|
return `<table role="presentation" style="width:100%;border-collapse:separate;border-spacing:0;table-layout:fixed;">${rows.join('')}</table>`;
|
|
220
243
|
}
|
|
221
|
-
/** A ranked list: the label left, its figure right, a hairline between. */ function rowsHtml(rows, colors) {
|
|
222
|
-
const trs = rows.map((row, index)=>`<tr>` + `<td style="font-family:${FONT};font-size:14px;line-height:1.4;color:${colors.text};padding:8px 12px 8px 0;` + `${index < rows.length - 1 ? `border-bottom:1px solid ${colors.border};` : ''}word-break:break-word;">${unlinked(row.label)}</td>` + `<td style="font-family:${FONT};font-size:14px;line-height:1.4;font-weight:600;color:${colors.text};padding:8px 0;text-align:right;white-space:nowrap;` + `${index < rows.length - 1 ? `border-bottom:1px solid ${colors.border};` : ''}">${esc(row.value)}</td>` + `</tr>`);
|
|
223
|
-
return `<table role="presentation" style="width:100%;border-collapse:collapse;">${trs.join('')}</table>`;
|
|
224
|
-
}
|
|
225
244
|
function sectionTitleHtml(title, colors) {
|
|
226
245
|
return `<div style="font-family:${FONT};font-size:12px;line-height:1.4;font-weight:700;letter-spacing:0.06em;` + `text-transform:uppercase;color:${colors.muted};padding:0 0 8px;">${esc(title)}</div>`;
|
|
227
246
|
}
|
|
@@ -259,20 +278,36 @@ function sectionRowsHtml(rows, colors) {
|
|
|
259
278
|
return `<table role="presentation" style="width:100%;border-collapse:collapse;margin-top:8px;">${trs.join('')}</table>`;
|
|
260
279
|
}
|
|
261
280
|
function sectionHtml(section, colors, first) {
|
|
262
|
-
var _section_rows, _section_bars;
|
|
281
|
+
var _section_stats, _section_rows, _section_bars;
|
|
263
282
|
const link = section.link ? `<td style="padding:0;text-align:right;vertical-align:baseline;white-space:nowrap;">` + `<a href="${esc(section.link.url)}" style="font-family:${FONT};font-size:13px;line-height:1.4;font-weight:600;color:${colors.link};text-decoration:none;">${esc(section.link.label)} →</a>` + `</td>` : '';
|
|
264
283
|
const points = section.points.map((point)=>`<div style="padding:6px 0 0;">` + (point.headline ? `<div style="font-family:${FONT};font-size:16px;line-height:1.35;font-weight:700;color:${colors.text};">${unlinked(point.headline)}</div>` : '') + (point.text ? `<div style="font-family:${FONT};font-size:14px;line-height:1.5;color:${colors.muted};">${figuresHtml(point.text, colors)}</div>` : '') + `</div>`);
|
|
265
|
-
return `<div style="padding:${first ? '8px' : '18px'} 0 18px;${first ? '' : `border-top:1px solid ${colors.border};`}">` + `<table role="presentation" style="width:100%;border-collapse:collapse;"><tr>` + `<td style="font-family:${FONT};font-size:12px;line-height:1.4;font-weight:700;letter-spacing:0.06em;text-transform:uppercase;color:${colors.muted};padding:0;">${esc(section.title)}</td>` + link + `</tr></table>` + points.join('') + (((_section_rows = section.rows) == null ? void 0 : _section_rows.length) ? sectionRowsHtml(section.rows, colors) : '') + (((_section_bars = section.bars) == null ? void 0 : _section_bars.length) ? sectionBarsHtml(section.bars, colors) : '') + `</div>`;
|
|
284
|
+
return `<div style="padding:${first ? '8px' : '18px'} 0 18px;${first ? '' : `border-top:1px solid ${colors.border};`}">` + `<table role="presentation" style="width:100%;border-collapse:collapse;"><tr>` + `<td style="font-family:${FONT};font-size:12px;line-height:1.4;font-weight:700;letter-spacing:0.06em;text-transform:uppercase;color:${colors.muted};padding:0;">${esc(section.title)}</td>` + link + `</tr></table>` + points.join('') + (((_section_stats = section.stats) == null ? void 0 : _section_stats.length) ? `<div style="padding:8px 0 0;">${tilesHtml(section.stats, colors)}</div>` : '') + (((_section_rows = section.rows) == null ? void 0 : _section_rows.length) ? sectionRowsHtml(section.rows, colors) : '') + (((_section_bars = section.bars) == null ? void 0 : _section_bars.length) ? sectionBarsHtml(section.bars, colors) : '') + `</div>`;
|
|
266
285
|
}
|
|
267
|
-
/**
|
|
268
|
-
return sections.map((section, index)=>sectionHtml(section, colors, index === 0)).join('');
|
|
286
|
+
/** A weekly email's topics, a hairline between them; `following` when something already sits above the first. */ export function weeklySummarySectionsHtml(sections, colors, following = false) {
|
|
287
|
+
return sections.map((section, index)=>sectionHtml(section, colors, index === 0 && !following)).join('');
|
|
269
288
|
}
|
|
270
289
|
/** The small print under the button, with its one link. */ export function weeklySummaryFootnoteHtml(text, link, colors) {
|
|
271
290
|
return `<div style="font-family:${FONT};font-size:12px;line-height:1.5;color:${colors.muted};padding:12px 0 0;">` + esc(text) + (link ? ` <a href="${esc(link.url)}" style="color:${colors.link};text-decoration:underline;">${esc(link.label)}</a>` : '') + `</div>`;
|
|
272
291
|
}
|
|
273
|
-
function
|
|
274
|
-
var
|
|
275
|
-
|
|
292
|
+
/** A reader's part as a section of the email, its page rows linked to the site. */ function partSection(part, siteUrl) {
|
|
293
|
+
var _part_link;
|
|
294
|
+
var _part_stats, _part_rows, _part_bars;
|
|
295
|
+
return _extends({
|
|
296
|
+
title: part.title,
|
|
297
|
+
link: (_part_link = part.link) != null ? _part_link : null,
|
|
298
|
+
points: part.note ? [
|
|
299
|
+
{
|
|
300
|
+
headline: null,
|
|
301
|
+
text: part.note
|
|
302
|
+
}
|
|
303
|
+
] : []
|
|
304
|
+
}, ((_part_stats = part.stats) == null ? void 0 : _part_stats.length) ? {
|
|
305
|
+
stats: part.stats
|
|
306
|
+
} : {}, ((_part_rows = part.rows) == null ? void 0 : _part_rows.length) ? {
|
|
307
|
+
rows: part.rows.map((row)=>_extends({}, row, weeklySummaryRowLink(row.label, siteUrl)))
|
|
308
|
+
} : {}, ((_part_bars = part.bars) == null ? void 0 : _part_bars.length) ? {
|
|
309
|
+
bars: part.bars
|
|
310
|
+
} : {});
|
|
276
311
|
}
|
|
277
312
|
/** "aglyn.com · Aglyn LLC": which site, linked, and whose. */ function addressHtml(site, workspaceName, colors) {
|
|
278
313
|
const address = site.address ? `<a href="${esc(site.address.url)}" style="color:${colors.link};text-decoration:underline;font-weight:600;">${esc(site.address.label)}</a>` : `<span style="font-weight:600;">${esc(site.name)}</span>`;
|
|
@@ -282,7 +317,7 @@ function insightsHtml(url, colors) {
|
|
|
282
317
|
return `<div style="margin:16px 0 0;background-color:${colors.surface};border-left:3px solid ${colors.accent};border-radius:4px;padding:14px 16px;">` + `<div style="font-family:${FONT};font-size:14px;line-height:1.5;font-weight:700;color:${colors.text};">Want to know why the numbers moved?</div>` + `<div style="font-family:${FONT};font-size:14px;line-height:1.5;color:${colors.text};">` + `AI weekly insights explain each site's week in a few plain sentences. ` + `<a href="${esc(url)}" style="color:${colors.link};text-decoration:underline;">Turn them on from Ask about your numbers</a>.` + `</div></div>`;
|
|
283
318
|
}
|
|
284
319
|
function partText(part) {
|
|
285
|
-
var _part_stats, _part_rows;
|
|
320
|
+
var _part_stats, _part_rows, _part_bars;
|
|
286
321
|
const lines = [
|
|
287
322
|
part.title.toUpperCase()
|
|
288
323
|
];
|
|
@@ -291,9 +326,20 @@ function partText(part) {
|
|
|
291
326
|
const said = weeklySummaryChange(stat.change);
|
|
292
327
|
lines.push(`${stat.label}: ${stat.value}${said ? ` (${said.text})` : ''}`);
|
|
293
328
|
}
|
|
294
|
-
for (const row of (_part_rows = part.rows) != null ? _part_rows : [])
|
|
329
|
+
for (const row of (_part_rows = part.rows) != null ? _part_rows : []){
|
|
330
|
+
const said = weeklySummaryChange(row.change);
|
|
331
|
+
lines.push(`- ${row.label}: ${row.value}${said ? ` (${said.text})` : ''}`);
|
|
332
|
+
}
|
|
333
|
+
for (const bar of (_part_bars = part.bars) != null ? _part_bars : [])lines.push(`- ${bar.label}: ${bar.display}`);
|
|
334
|
+
if (part.link) lines.push(`${part.link.label}: ${part.link.url}`);
|
|
295
335
|
return lines;
|
|
296
336
|
}
|
|
337
|
+
function footnote(input) {
|
|
338
|
+
return weeklySummaryFootnoteHtml('', {
|
|
339
|
+
label: 'Change what you are emailed about',
|
|
340
|
+
url: input.settingsUrl
|
|
341
|
+
}, input.colors);
|
|
342
|
+
}
|
|
297
343
|
function closing(input) {
|
|
298
344
|
return [
|
|
299
345
|
'',
|
|
@@ -305,16 +351,21 @@ function closing(input) {
|
|
|
305
351
|
* carries the workspace's own parts when this site's email stands in for the
|
|
306
352
|
* overview, in a workspace with one active site.
|
|
307
353
|
*/ export function composeWeeklySummarySiteEmail(input) {
|
|
308
|
-
var _input_workspace, _input_site_url;
|
|
354
|
+
var _input_workspace, _ref, _input_site_url;
|
|
355
|
+
var _input_site_address;
|
|
309
356
|
const workspace = (_input_workspace = input.workspace) != null ? _input_workspace : [];
|
|
310
357
|
if (!weeklySummaryHasNews(input.site) && !workspace.length) return null;
|
|
311
358
|
const lead = headline([
|
|
312
359
|
input.site
|
|
313
360
|
]);
|
|
314
361
|
const subject = lead ? `${input.site.name} last week: ${lead}` : `${input.site.name} last week`;
|
|
315
|
-
const
|
|
316
|
-
|
|
317
|
-
|
|
362
|
+
const siteUrl = (_ref = (_input_site_address = input.site.address) == null ? void 0 : _input_site_address.url) != null ? _ref : null;
|
|
363
|
+
const html = addressHtml(input.site, input.workspaceName, input.colors) + weeklySummarySectionsHtml([
|
|
364
|
+
...input.site.parts.map((part)=>partSection(part, siteUrl)),
|
|
365
|
+
...workspace.map((part)=>partSection(_extends({}, part, {
|
|
366
|
+
title: `${input.workspaceName} · ${part.title}`
|
|
367
|
+
}), null))
|
|
368
|
+
], input.colors) + (input.aiInsightsUrl ? insightsHtml(input.aiInsightsUrl, input.colors) : '');
|
|
318
369
|
const text = [
|
|
319
370
|
`${input.site.name} last week, ${input.periodLabel}. A change in brackets is against the week before.`,
|
|
320
371
|
`Site: ${input.site.address ? `${input.site.address.label} (${input.site.address.url})` : input.site.name} · ${input.workspaceName}`,
|
|
@@ -343,6 +394,7 @@ function closing(input) {
|
|
|
343
394
|
title: `${input.site.name} last week`,
|
|
344
395
|
period: `${input.periodLabel}, compared with the week before`,
|
|
345
396
|
html,
|
|
397
|
+
footnote: footnote(input),
|
|
346
398
|
text,
|
|
347
399
|
buttonLabel: `Open ${input.site.name}`,
|
|
348
400
|
url: (_input_site_url = input.site.url) != null ? _input_site_url : ''
|
|
@@ -376,14 +428,16 @@ function closing(input) {
|
|
|
376
428
|
}).join(' · ');
|
|
377
429
|
const quietCount = input.sites.length - active.length;
|
|
378
430
|
const quiet = quietCount ? `${figurePlural(quietCount, 'other site', 'other sites')} had nothing to report.` : '';
|
|
379
|
-
const sitesHtml = active.length ? `<div style="padding:
|
|
431
|
+
const sitesHtml = active.length ? `<div style="padding:18px 0 8px;${totalsPart ? `border-top:1px solid ${colors.border};` : ''}">` + sectionTitleHtml('Your sites', colors) + `<table role="presentation" style="width:100%;border-collapse:collapse;">` + active.map((site, index)=>{
|
|
380
432
|
const border = index < active.length - 1 ? `border-bottom:1px solid ${colors.border};` : '';
|
|
381
433
|
const name = site.url ? `<a href="${esc(site.url)}" style="color:${colors.link};text-decoration:none;font-weight:700;">${esc(site.name)}</a>` : `<span style="font-weight:700;">${esc(site.name)}</span>`;
|
|
382
434
|
const line = siteLine(site);
|
|
383
435
|
const address = site.address ? ` <a href="${esc(site.address.url)}" style="color:${colors.muted};text-decoration:underline;font-size:13px;font-weight:400;">${esc(site.address.label)}</a>` : '';
|
|
384
436
|
return `<tr><td style="font-family:${FONT};font-size:15px;line-height:1.4;color:${colors.text};padding:10px 0;${border}">` + name + address + (line ? `<div style="font-size:13px;line-height:1.5;color:${colors.muted};">${esc(line)}</div>` : '') + `</td></tr>`;
|
|
385
437
|
}).join('') + `</table>` + (quiet ? `<div style="font-family:${FONT};font-size:13px;line-height:1.5;color:${colors.muted};padding:4px 0 0;">${esc(quiet)}</div>` : '') + `</div>` : '';
|
|
386
|
-
const html = (totalsPart ?
|
|
438
|
+
const html = (totalsPart ? weeklySummarySectionsHtml([
|
|
439
|
+
partSection(totalsPart, null)
|
|
440
|
+
], colors) : '') + sitesHtml + weeklySummarySectionsHtml(input.workspace.map((part)=>partSection(part, null)), colors, Boolean(totalsPart || sitesHtml)) + (active.length > 1 ? `<div style="font-family:${FONT};font-size:13px;line-height:1.5;color:${colors.muted};padding:8px 0 0;">Each site's own summary arrives beside this one.</div>` : '') + (input.aiInsightsUrl ? insightsHtml(input.aiInsightsUrl, colors) : '');
|
|
387
441
|
const text = [
|
|
388
442
|
`Here is how ${input.workspaceName} did last week, ${input.periodLabel}. A change in brackets is against the week before.`,
|
|
389
443
|
...totalsPart ? [
|
|
@@ -413,6 +467,7 @@ function closing(input) {
|
|
|
413
467
|
title: `${input.workspaceName} last week`,
|
|
414
468
|
period: `${input.periodLabel}, compared with the week before`,
|
|
415
469
|
html,
|
|
470
|
+
footnote: footnote(input),
|
|
416
471
|
text,
|
|
417
472
|
buttonLabel: `Open ${input.workspaceName}`,
|
|
418
473
|
url: input.url
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/weekly-summary.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n pluginFigureCellText,\n pluginFigureIsoWeek,\n pluginFigureWindows,\n type PluginFigureCell,\n type PluginFigureRow,\n type PluginFigureSummaryPart,\n type PluginFigureSummaryStat,\n type PluginFigureTable,\n} from '../plugin-manager/plugin-figures'\n\n/**\n * THE WEEKLY SUMMARY (AGL-3867): the free Monday emails that say how a\n * workspace did the week before — one for each site that had something to\n * report, and an overview of the workspace that adds the sites up.\n *\n * They spend nothing. Every figure comes from a `plugin-figures` reader that\n * declares a `weeklySummary`, and that reader's owner says what its table\n * means as tiles and ranked rows, so each plugin's counting rules decide what\n * a figure is and nothing here names one. AI weekly insights (AGL-2915) are\n * the paid version that explains the figures, and stay opt-in because each\n * one spends the workspace's AI credits.\n *\n * This module is the period, the wording helpers the readers use, and both\n * emails' words and layout; the reads and the sends are\n * `@aglyn/tenant-data-admin/server/weekly-summary`. The layout is drawn as\n * email-safe tables with inline styles, in colors the caller resolves from\n * the email theme.\n */\n\n/** The key a person's switch is stored under in `users/{uid}.digestPrefs`; on until turned off. */\nexport const WEEKLY_SUMMARY_DIGEST_KEY = 'weeklySummary'\n\n/** The window every figure is read over. */\nexport const WEEKLY_SUMMARY_DAYS = 7\n\n/** Rows a ranked list names. */\nexport const WEEKLY_SUMMARY_TOP_ROWS = 5\n\n/** Counts a subject line or the overview's tiles lead with, at most. */\nexport const WEEKLY_SUMMARY_HEADLINE_COUNTS = 3\n\n/** Tiles in one row of an email. */\nconst TILES_PER_ROW = 3\n\n/**\n * The week a run reports on: the seven whole UTC days before the day it runs,\n * so a Monday run covers Monday to Sunday and never a part-day of today.\n * `now` is what each reader is handed; `week` keys the run's marker.\n */\nexport function weeklySummaryPeriod(runAt: Date): {\n now: Date\n week: string\n from: string\n to: string\n label: string\n} {\n const startOfToday = Date.UTC(runAt.getUTCFullYear(), runAt.getUTCMonth(), runAt.getUTCDate())\n const now = new Date(startOfToday - 1)\n const { current } = pluginFigureWindows(now, WEEKLY_SUMMARY_DAYS)\n return {\n now,\n week: pluginFigureIsoWeek(now),\n from: current.from,\n to: current.to,\n label: `${weeklySummaryDay(current.from)} – ${weeklySummaryDay(current.to)}`,\n }\n}\n\n/** `2026-10-05` as \"Oct 5\". */\nexport function weeklySummaryDay(day: string): string {\n const at = new Date(`${day}T00:00:00Z`)\n return at.toLocaleDateString('en-US', { month: 'short', day: 'numeric', timeZone: 'UTC' })\n}\n\n/** `2026-10-26` as \"Mon, Oct 26\". */\nexport function weeklySummaryWeekday(day: string): string {\n const at = new Date(`${day}T00:00:00Z`)\n return at.toLocaleDateString('en-US', { weekday: 'short', month: 'short', day: 'numeric', timeZone: 'UTC' })\n}\n\nconst ISO_DAY = /\\b\\d{4}-\\d{2}-\\d{2}\\b/g\n\n/**\n * A sentence's dates as a person says them: \"Monday 2026-10-26\" as \"Monday,\n * Oct 26\". Tables hand the model their dates in ISO form, and it copies them.\n */\nexport function weeklySummaryPlainDates(text: string): string {\n const said = (day: string) => {\n const words = weeklySummaryDay(day)\n return words === 'Invalid Date' ? day : words\n }\n return text\n .replace(/\\b((?:Mon|Tues|Wednes|Thurs|Fri|Satur|Sun)day),? (\\d{4}-\\d{2}-\\d{2})\\b/g, (_, weekday: string, day: string) => `${weekday}, ${said(day)}`)\n .replace(ISO_DAY, said)\n}\n\n// ── Helpers the readers word their parts with ──────────────────────────────\n\n/** A cell as a number, `0` for anything that is not one. */\nexport function figureCount(value: PluginFigureCell | undefined): number {\n return typeof value === 'number' && Number.isFinite(value) ? value : 0\n}\n\n/** The row whose `key` cell is `label`: \"Visitors\" in a table of figures. */\nexport function figureRow(table: PluginFigureTable, key: string, label: string): PluginFigureRow | undefined {\n return table.rows.find((row) => row[key] === label)\n}\n\n/** Whether a table carries a column, so a reader that changed shape is noticed rather than misread. */\nexport function figureHasColumn(table: PluginFigureTable, key: string): boolean {\n return table.columns.some((column) => column.key === key)\n}\n\n/** A cell as a tile, with its change when the table has one. */\nexport function figureStat(\n table: PluginFigureTable,\n row: PluginFigureRow,\n key: string,\n label: string,\n options: { change?: string; total?: { one: string; many: string } } = {},\n): PluginFigureSummaryStat {\n const change = options.change ? row[options.change] : undefined\n return {\n label,\n value: pluginFigureCellText(table, key, row[key] ?? 0),\n ...(typeof change === 'number' ? { change } : {}),\n ...(options.total ? { total: { count: figureCount(row[key]), ...options.total } } : {}),\n }\n}\n\n/** The named rows with the most of `key`, as ranked rows; `[]` when none has any. */\nexport function figureRanked(\n table: PluginFigureTable,\n nameKey: string,\n key: string,\n rows: readonly PluginFigureRow[] = table.rows,\n): Array<{ label: string; value: string }> {\n return rows\n .filter((row) => typeof row[nameKey] === 'string' && figureCount(row[key]) > 0)\n .slice(0, WEEKLY_SUMMARY_TOP_ROWS)\n .map((row) => ({ label: String(row[nameKey]), value: pluginFigureCellText(table, key, row[key] ?? 0) }))\n}\n\n/** \"1 order\", \"18 orders\". */\nexport function figurePlural(count: number, one: string, many: string): string {\n return `${count.toLocaleString('en-US')} ${count === 1 ? one : many}`\n}\n\n// ── The emails ─────────────────────────────────────────────────────────────\n\n/** One site's figures for the week. */\nexport interface WeeklySummarySite {\n name: string\n /** The site's dashboard in the console, absolute; `null` with no origin to build it from. */\n url: string | null\n /**\n * Where the site itself is, so a reader knows which site this is: its\n * custom domain when it serves on one, else its platform address. `null`\n * for a site with no address yet.\n */\n address?: { label: string; url: string } | null\n parts: readonly PluginFigureSummaryPart[]\n}\n\n/** The colors an email is drawn in, resolved from its theme by the caller. */\nexport interface WeeklySummaryColors {\n text: string\n muted: string\n border: string\n /** A tile's ground. */\n surface: string\n /** The accent rule beside a callout. */\n accent: string\n /** Links: the email theme's own link color, the one every other link in the email wears. */\n link: string\n /** A rise and a fall. */\n up: string\n down: string\n}\n\n/** A site with anything to say. */\nexport function weeklySummaryHasNews(site: Pick<WeeklySummarySite, 'parts'>): boolean {\n return site.parts.length > 0\n}\n\n/** The counts the readers offered for adding up, summed by noun, in the order they were first given. */\nexport function weeklySummaryTotals(\n sites: ReadonlyArray<Pick<WeeklySummarySite, 'parts'>>,\n): Array<{ count: number; one: string; many: string }> {\n const sums = new Map<string, { count: number; one: string; many: string }>()\n for (const site of sites) {\n for (const part of site.parts) {\n for (const stat of part.stats ?? []) {\n if (!stat.total || stat.total.count <= 0) continue\n const sum = sums.get(stat.total.one)\n sums.set(stat.total.one, sum ? { ...sum, count: sum.count + stat.total.count } : { ...stat.total })\n }\n }\n }\n return [...sums.values()]\n}\n\nfunction headline(sites: ReadonlyArray<Pick<WeeklySummarySite, 'parts'>>): string {\n return weeklySummaryTotals(sites)\n .slice(0, WEEKLY_SUMMARY_HEADLINE_COUNTS)\n .map(({ count, one, many }) => figurePlural(count, one, many))\n .join(', ')\n}\n\n/** \"+12.5%\", \"−27.9%\", \"no change\"; `null` with nothing to compare with. */\nexport function weeklySummaryChange(change: number | null | undefined): { text: string; sign: 1 | -1 | 0 } | null {\n if (typeof change !== 'number' || !Number.isFinite(change)) return null\n if (change === 0) return { text: 'no change', sign: 0 }\n const amount = Math.abs(change).toLocaleString('en-US', { maximumFractionDigits: 1 })\n return change > 0 ? { text: `+${amount}%`, sign: 1 } : { text: `−${amount}%`, sign: -1 }\n}\n\nconst esc = (value: string): string =>\n value.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/\"/g, '"')\n\nconst FONT = 'Helvetica, Arial, sans-serif'\n\nconst capitalized = (value: string): string => value.charAt(0).toUpperCase() + value.slice(1)\n\n/**\n * A label that reads like an address — `www.google.com` — kept from being\n * turned into a link by the inbox, which would draw it in the inbox's own\n * blue beside the theme's links. A zero-width space after each dot breaks\n * the detection and nothing a reader sees.\n */\nconst unlinked = (value: string): string => esc(value).replace(/\\./g, '.\\u200b')\n\nfunction changeHtml(change: number | null | undefined, colors: WeeklySummaryColors): string {\n const said = weeklySummaryChange(change)\n if (!said) return ''\n const color = said.sign > 0 ? colors.up : said.sign < 0 ? colors.down : colors.muted\n const arrow = said.sign > 0 ? '▲ ' : said.sign < 0 ? '▼ ' : ''\n return `<div style=\"font-family:${FONT};font-size:13px;line-height:1.4;font-weight:600;color:${color};\">${arrow}${esc(said.text)}</div>`\n}\n\n/**\n * How many tiles share each row: one row of up to three, two rows of two for\n * four, then rows of three — so a row is never left with an empty slot\n * beside two tiles.\n */\nexport function weeklySummaryTileRows(count: number): number[] {\n if (count <= 0) return []\n if (count <= TILES_PER_ROW) return [count]\n if (count === 4) return [2, 2]\n const rows: number[] = []\n for (let left = count; left > 0; left -= TILES_PER_ROW) rows.push(Math.min(TILES_PER_ROW, left))\n return rows\n}\n\n/** The gap between tiles, across and down. */\nconst TILE_GAP_PX = 8\n\n/** A cell that is only a gap: nothing in it may hold it open. */\nconst TILE_GAP = 'font-size:0;line-height:0;padding:0;'\n\n/**\n * Tiles, each a value, its label and its change, filling the width of their\n * row. The tile is the table cell itself, so a row's tiles are one height\n * whichever of them wraps, in every mail client; the gaps are cells of their own.\n */\nfunction tilesHtml(stats: readonly PluginFigureSummaryStat[], colors: WeeklySummaryColors): string {\n const sizes = weeklySummaryTileRows(stats.length)\n const rows: string[] = []\n let at = 0\n sizes.forEach((size) => {\n const cells = stats.slice(at, at + size)\n at += size\n // A tile alone takes half the row, not all of it, so it reads as a tile.\n const columns = Math.max(size, 2)\n const width = `${Math.floor(100 / columns)}%`\n const tds: string[] = []\n for (let index = 0; index < columns; index += 1) {\n if (index > 0) tds.push(`<td style=\"width:${TILE_GAP_PX}px;${TILE_GAP}\"> </td>`)\n const stat = cells[index]\n tds.push(\n stat\n ? `<td style=\"width:${width};background-color:${colors.surface};border:1px solid ${colors.border};border-radius:8px;padding:12px 14px;vertical-align:top;\">` +\n `<div style=\"font-family:${FONT};font-size:24px;line-height:1.2;font-weight:700;color:${colors.text};\">${esc(stat.value)}</div>` +\n `<div style=\"font-family:${FONT};font-size:13px;line-height:1.4;color:${colors.muted};\">${esc(stat.label)}</div>` +\n changeHtml(stat.change, colors) +\n `</td>`\n : `<td style=\"width:${width};\"></td>`,\n )\n }\n rows.push(`<tr>${tds.join('')}</tr>`)\n rows.push(`<tr><td colspan=\"${columns * 2 - 1}\" style=\"height:${TILE_GAP_PX}px;${TILE_GAP}\"> </td></tr>`)\n })\n return `<table role=\"presentation\" style=\"width:100%;border-collapse:separate;border-spacing:0;table-layout:fixed;\">${rows.join('')}</table>`\n}\n\n/** A ranked list: the label left, its figure right, a hairline between. */\nfunction rowsHtml(rows: ReadonlyArray<{ label: string; value: string }>, colors: WeeklySummaryColors): string {\n const trs = rows.map(\n (row, index) =>\n `<tr>` +\n `<td style=\"font-family:${FONT};font-size:14px;line-height:1.4;color:${colors.text};padding:8px 12px 8px 0;` +\n `${index < rows.length - 1 ? `border-bottom:1px solid ${colors.border};` : ''}word-break:break-word;\">${unlinked(row.label)}</td>` +\n `<td style=\"font-family:${FONT};font-size:14px;line-height:1.4;font-weight:600;color:${colors.text};padding:8px 0;text-align:right;white-space:nowrap;` +\n `${index < rows.length - 1 ? `border-bottom:1px solid ${colors.border};` : ''}\">${esc(row.value)}</td>` +\n `</tr>`,\n )\n return `<table role=\"presentation\" style=\"width:100%;border-collapse:collapse;\">${trs.join('')}</table>`\n}\n\nfunction sectionTitleHtml(title: string, colors: WeeklySummaryColors): string {\n return (\n `<div style=\"font-family:${FONT};font-size:12px;line-height:1.4;font-weight:700;letter-spacing:0.06em;` +\n `text-transform:uppercase;color:${colors.muted};padding:0 0 8px;\">${esc(title)}</div>`\n )\n}\n\n/** A figure in a sentence: a count, a sum or a percent, never the digits in a path or a date. */\nconst FIGURE =\n /(?<![\\p{L}\\p{N}_./-])(?<!(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) )[+\\-−]?[$€£¥]?(?:\\d{1,3}(?:,\\d{3})+|\\d+)(?:\\.\\d+)?%?(?![\\p{L}\\p{N}_/-])/gu\n\n/** A sentence with its figures in bold, so an eye running down the email lands on them. */\nfunction figuresHtml(text: string, colors: WeeklySummaryColors): string {\n let html = ''\n let at = 0\n for (const match of text.matchAll(FIGURE)) {\n html += `${unlinked(text.slice(at, match.index))}<strong style=\"font-weight:700;color:${colors.text};\">${esc(match[0])}</strong>`\n at = match.index + match[0].length\n }\n return html + unlinked(text.slice(at))\n}\n\n/** A figure a digest section lists: a page and its views. */\nexport interface WeeklySummarySectionRow {\n label: string\n /** Where the label goes: the page itself. */\n url?: string | null\n value: string\n change?: number | null\n}\n\n/** One day of a section's chart; `marked` when it is a day the section is about. */\nexport interface WeeklySummarySectionBar {\n label: string\n value: number\n /** The value as a person reads it. */\n display: string\n marked: boolean\n}\n\n/** One topic of an AI digest, told once: what stood out, and the figures behind it. */\nexport interface WeeklySummarySection {\n title: string\n /** Where the figures can be seen in full. */\n link?: { label: string; url: string } | null\n /** What was said about it: a line to scan and, if it needs one, the sentence behind it. */\n points: ReadonlyArray<{ headline: string | null; text: string | null }>\n rows?: readonly WeeklySummarySectionRow[]\n bars?: readonly WeeklySummarySectionBar[]\n}\n\n/** Tiles on their own, for an email that leads with its headline figures. */\nexport function weeklySummaryTilesHtml(stats: readonly PluginFigureSummaryStat[], colors: WeeklySummaryColors): string {\n return stats.length ? `<div style=\"padding:12px 0 8px;\">${tilesHtml(stats, colors)}</div>` : ''\n}\n\nfunction sectionRowsHtml(rows: readonly WeeklySummarySectionRow[], colors: WeeklySummaryColors): string {\n const cell = `font-family:${FONT};font-size:14px;line-height:1.4;padding:7px 0;`\n // No column for a change no row has, so the figures reach the edge.\n const changes = rows.some((row) => weeklySummaryChange(row.change))\n const trs = rows.map((row, index) => {\n const border = index > 0 ? `border-top:1px solid ${colors.border};` : ''\n const label = row.url\n ? `<a href=\"${esc(row.url)}\" style=\"color:${colors.link};text-decoration:none;font-weight:600;\">${unlinked(row.label)}</a>`\n : unlinked(row.label)\n return (\n `<tr>` +\n `<td style=\"${cell}${border}color:${colors.text};word-break:break-word;\">${label}</td>` +\n `<td style=\"${cell}${border}color:${colors.text};font-weight:600;padding-left:12px;text-align:right;white-space:nowrap;\">${esc(row.value)}</td>` +\n (changes\n ? `<td style=\"${cell}${border}padding-left:12px;text-align:right;white-space:nowrap;\">${changeHtml(row.change, colors)}</td>`\n : '') +\n `</tr>`\n )\n })\n return `<table role=\"presentation\" style=\"width:100%;border-collapse:collapse;margin-top:8px;\">${trs.join('')}</table>`\n}\n\n/** Horizontal bars, drawn in table cells so every mail client keeps them. */\nfunction sectionBarsHtml(bars: readonly WeeklySummarySectionBar[], colors: WeeklySummaryColors): string {\n const most = Math.max(...bars.map((bar) => bar.value), 1)\n const trs = bars.map((bar) => {\n const text = `font-family:${FONT};font-size:13px;line-height:1.3;color:${bar.marked ? colors.text : colors.muted};white-space:nowrap;`\n const weight = bar.marked ? 'font-weight:700;' : ''\n return (\n `<tr>` +\n `<td style=\"${text}${weight}padding:3px 10px 3px 0;width:1%;\">${esc(bar.label)}</td>` +\n `<td style=\"padding:3px 0;\"><div style=\"background-color:${bar.marked ? colors.accent : colors.border};border-radius:2px;font-size:0;height:10px;line-height:0;width:${Math.max(1, Math.round((bar.value / most) * 100))}%;\"> </div></td>` +\n `<td style=\"${text}${weight}padding:3px 0 3px 10px;text-align:right;width:1%;\">${esc(bar.display)}</td>` +\n `</tr>`\n )\n })\n return `<table role=\"presentation\" style=\"width:100%;border-collapse:collapse;margin-top:8px;\">${trs.join('')}</table>`\n}\n\nfunction sectionHtml(section: WeeklySummarySection, colors: WeeklySummaryColors, first: boolean): string {\n const link = section.link\n ? `<td style=\"padding:0;text-align:right;vertical-align:baseline;white-space:nowrap;\">` +\n `<a href=\"${esc(section.link.url)}\" style=\"font-family:${FONT};font-size:13px;line-height:1.4;font-weight:600;color:${colors.link};text-decoration:none;\">${esc(section.link.label)} →</a>` +\n `</td>`\n : ''\n const points = section.points.map(\n (point) =>\n `<div style=\"padding:6px 0 0;\">` +\n (point.headline\n ? `<div style=\"font-family:${FONT};font-size:16px;line-height:1.35;font-weight:700;color:${colors.text};\">${unlinked(point.headline)}</div>`\n : '') +\n (point.text\n ? `<div style=\"font-family:${FONT};font-size:14px;line-height:1.5;color:${colors.muted};\">${figuresHtml(point.text, colors)}</div>`\n : '') +\n `</div>`,\n )\n return (\n `<div style=\"padding:${first ? '8px' : '18px'} 0 18px;${first ? '' : `border-top:1px solid ${colors.border};`}\">` +\n `<table role=\"presentation\" style=\"width:100%;border-collapse:collapse;\"><tr>` +\n `<td style=\"font-family:${FONT};font-size:12px;line-height:1.4;font-weight:700;letter-spacing:0.06em;text-transform:uppercase;color:${colors.muted};padding:0;\">${esc(section.title)}</td>` +\n link +\n `</tr></table>` +\n points.join('') +\n (section.rows?.length ? sectionRowsHtml(section.rows, colors) : '') +\n (section.bars?.length ? sectionBarsHtml(section.bars, colors) : '') +\n `</div>`\n )\n}\n\n/** An AI digest's topics, a hairline between them. */\nexport function weeklySummarySectionsHtml(sections: readonly WeeklySummarySection[], colors: WeeklySummaryColors): string {\n return sections.map((section, index) => sectionHtml(section, colors, index === 0)).join('')\n}\n\n/** The small print under the button, with its one link. */\nexport function weeklySummaryFootnoteHtml(\n text: string,\n link: { label: string; url: string } | null,\n colors: WeeklySummaryColors,\n): string {\n return (\n `<div style=\"font-family:${FONT};font-size:12px;line-height:1.5;color:${colors.muted};padding:12px 0 0;\">` +\n esc(text) +\n (link ? ` <a href=\"${esc(link.url)}\" style=\"color:${colors.link};text-decoration:underline;\">${esc(link.label)}</a>` : '') +\n `</div>`\n )\n}\n\nfunction partHtml(part: PluginFigureSummaryPart, colors: WeeklySummaryColors): string {\n return (\n `<div style=\"padding:16px 0 8px;\">` +\n sectionTitleHtml(part.title, colors) +\n (part.note\n ? `<div style=\"font-family:${FONT};font-size:13px;line-height:1.5;color:${colors.muted};padding:0 0 8px;\">${esc(part.note)}</div>`\n : '') +\n (part.stats?.length ? tilesHtml(part.stats, colors) : '') +\n (part.rows?.length ? rowsHtml(part.rows, colors) : '') +\n `</div>`\n )\n}\n\n/** \"aglyn.com · Aglyn LLC\": which site, linked, and whose. */\nfunction addressHtml(site: WeeklySummarySite, workspaceName: string, colors: WeeklySummaryColors): string {\n const address = site.address\n ? `<a href=\"${esc(site.address.url)}\" style=\"color:${colors.link};text-decoration:underline;font-weight:600;\">${esc(site.address.label)}</a>`\n : `<span style=\"font-weight:600;\">${esc(site.name)}</span>`\n return (\n `<div style=\"font-family:${FONT};font-size:14px;line-height:1.5;color:${colors.muted};padding:0 0 4px;\">` +\n `${address} · ${esc(workspaceName)}</div>`\n )\n}\n\nfunction insightsHtml(url: string, colors: WeeklySummaryColors): string {\n return (\n `<div style=\"margin:16px 0 0;background-color:${colors.surface};border-left:3px solid ${colors.accent};border-radius:4px;padding:14px 16px;\">` +\n `<div style=\"font-family:${FONT};font-size:14px;line-height:1.5;font-weight:700;color:${colors.text};\">Want to know why the numbers moved?</div>` +\n `<div style=\"font-family:${FONT};font-size:14px;line-height:1.5;color:${colors.text};\">` +\n `AI weekly insights explain each site's week in a few plain sentences. ` +\n `<a href=\"${esc(url)}\" style=\"color:${colors.link};text-decoration:underline;\">Turn them on from Ask about your numbers</a>.` +\n `</div></div>`\n )\n}\n\nfunction partText(part: PluginFigureSummaryPart): string[] {\n const lines = [part.title.toUpperCase()]\n if (part.note) lines.push(part.note)\n for (const stat of part.stats ?? []) {\n const said = weeklySummaryChange(stat.change)\n lines.push(`${stat.label}: ${stat.value}${said ? ` (${said.text})` : ''}`)\n }\n for (const row of part.rows ?? []) lines.push(`- ${row.label}: ${row.value}`)\n return lines\n}\n\n/** What a send fills a weekly summary email's tokens with. */\nexport interface WeeklySummaryEmail {\n subject: string\n /** The heading: \"Aglyn last week\". */\n title: string\n /** \"Oct 5 – Oct 11, compared with the week before\". */\n period: string\n /** The figures, drawn. */\n html: string\n /** The whole email as plain text, closing line included. */\n text: string\n buttonLabel: string\n /** Where the button goes; `''` when there is no console origin to link to. */\n url: string\n}\n\ninterface CommonInput {\n workspaceName: string\n productName: string\n periodLabel: string\n colors: WeeklySummaryColors\n /** Where AI weekly insights are turned on, when the plan includes them and this person has not; else `null`. */\n aiInsightsUrl: string | null\n settingsUrl: string\n}\n\nfunction closing(input: CommonInput): string[] {\n return [\n '',\n `You get this summary because you manage ${input.workspaceName}. Turn it off in Notifications: ${input.settingsUrl}`,\n ]\n}\n\n/**\n * One site's email, or `null` for a site with nothing to report. `workspace`\n * carries the workspace's own parts when this site's email stands in for the\n * overview, in a workspace with one active site.\n */\nexport function composeWeeklySummarySiteEmail(\n input: CommonInput & { site: WeeklySummarySite; workspace?: readonly PluginFigureSummaryPart[] },\n): WeeklySummaryEmail | null {\n const workspace = input.workspace ?? []\n if (!weeklySummaryHasNews(input.site) && !workspace.length) return null\n const lead = headline([input.site])\n const subject = lead ? `${input.site.name} last week: ${lead}` : `${input.site.name} last week`\n const html =\n addressHtml(input.site, input.workspaceName, input.colors) +\n input.site.parts.map((part) => partHtml(part, input.colors)).join('') +\n (workspace.length\n ? `<div style=\"border-top:1px solid ${input.colors.border};margin:16px 0 0;\"></div>` +\n workspace.map((part) => partHtml({ ...part, title: `${input.workspaceName} · ${part.title}` }, input.colors)).join('')\n : '') +\n (input.aiInsightsUrl ? insightsHtml(input.aiInsightsUrl, input.colors) : '')\n const text = [\n `${input.site.name} last week, ${input.periodLabel}. A change in brackets is against the week before.`,\n `Site: ${input.site.address ? `${input.site.address.label} (${input.site.address.url})` : input.site.name} · ${input.workspaceName}`,\n ...input.site.parts.flatMap((part) => ['', ...partText(part)]),\n ...workspace.flatMap((part) => ['', ...partText({ ...part, title: `${input.workspaceName} · ${part.title}` })]),\n ...(input.site.url ? ['', `Open ${input.site.name} in ${input.productName}: ${input.site.url}`] : []),\n ...(input.aiInsightsUrl\n ? ['', `Want to know why the numbers moved? Turn on AI weekly insights from Ask about your numbers: ${input.aiInsightsUrl}`]\n : []),\n ...closing(input),\n ].join('\\n')\n return {\n subject,\n title: `${input.site.name} last week`,\n period: `${input.periodLabel}, compared with the week before`,\n html,\n text,\n buttonLabel: `Open ${input.site.name}`,\n url: input.site.url ?? '',\n }\n}\n\n/**\n * The workspace overview: the week's totals across its sites, a line for each\n * site, and the workspace's own figures, or `null` when nothing anywhere has\n * anything to report.\n */\nexport function composeWeeklySummaryOverviewEmail(\n input: CommonInput & {\n sites: readonly WeeklySummarySite[]\n workspace: readonly PluginFigureSummaryPart[]\n /** The workspace's home in the console, absolute; `''` with no origin. */\n url: string\n },\n): WeeklySummaryEmail | null {\n const active = input.sites.filter(weeklySummaryHasNews)\n if (!active.length && !input.workspace.length) return null\n const totals = weeklySummaryTotals(active)\n const lead = totals\n .slice(0, WEEKLY_SUMMARY_HEADLINE_COUNTS)\n .map(({ count, one, many }) => figurePlural(count, one, many))\n .join(', ')\n const subject = lead ? `Your week at ${input.workspaceName}: ${lead}` : `Your week at ${input.workspaceName}`\n const { colors } = input\n const totalsPart: PluginFigureSummaryPart | null = totals.length\n ? {\n title: active.length === 1 ? 'At a glance' : `Across ${active.length} sites`,\n stats: totals.slice(0, TILES_PER_ROW * 2).map(({ count, one, many }) => ({\n label: capitalized(count === 1 ? one : many),\n value: count.toLocaleString('en-US'),\n })),\n }\n : null\n const siteLine = (site: WeeklySummarySite): string =>\n site.parts\n .flatMap((part) => part.stats ?? [])\n .filter((stat) => stat.total && stat.total.count > 0)\n .slice(0, WEEKLY_SUMMARY_HEADLINE_COUNTS)\n .map((stat) => {\n const total = stat.total as NonNullable<PluginFigureSummaryStat['total']>\n const said = weeklySummaryChange(stat.change)\n return `${figurePlural(total.count, total.one, total.many)}${said ? ` (${said.text})` : ''}`\n })\n .join(' · ')\n const quietCount = input.sites.length - active.length\n const quiet = quietCount\n ? `${figurePlural(quietCount, 'other site', 'other sites')} had nothing to report.`\n : ''\n const sitesHtml = active.length\n ? `<div style=\"padding:16px 0 8px;\">` +\n sectionTitleHtml('Your sites', colors) +\n `<table role=\"presentation\" style=\"width:100%;border-collapse:collapse;\">` +\n active\n .map((site, index) => {\n const border = index < active.length - 1 ? `border-bottom:1px solid ${colors.border};` : ''\n const name = site.url\n ? `<a href=\"${esc(site.url)}\" style=\"color:${colors.link};text-decoration:none;font-weight:700;\">${esc(site.name)}</a>`\n : `<span style=\"font-weight:700;\">${esc(site.name)}</span>`\n const line = siteLine(site)\n const address = site.address\n ? ` <a href=\"${esc(site.address.url)}\" style=\"color:${colors.muted};text-decoration:underline;font-size:13px;font-weight:400;\">${esc(site.address.label)}</a>`\n : ''\n return (\n `<tr><td style=\"font-family:${FONT};font-size:15px;line-height:1.4;color:${colors.text};padding:10px 0;${border}\">` +\n name +\n address +\n (line ? `<div style=\"font-size:13px;line-height:1.5;color:${colors.muted};\">${esc(line)}</div>` : '') +\n `</td></tr>`\n )\n })\n .join('') +\n `</table>` +\n (quiet\n ? `<div style=\"font-family:${FONT};font-size:13px;line-height:1.5;color:${colors.muted};padding:4px 0 0;\">${esc(quiet)}</div>`\n : '') +\n `</div>`\n : ''\n const html =\n (totalsPart ? partHtml(totalsPart, colors) : '') +\n sitesHtml +\n input.workspace.map((part) => partHtml(part, colors)).join('') +\n (active.length > 1\n ? `<div style=\"font-family:${FONT};font-size:13px;line-height:1.5;color:${colors.muted};padding:8px 0 0;\">Each site's own summary arrives beside this one.</div>`\n : '') +\n (input.aiInsightsUrl ? insightsHtml(input.aiInsightsUrl, colors) : '')\n const text = [\n `Here is how ${input.workspaceName} did last week, ${input.periodLabel}. A change in brackets is against the week before.`,\n ...(totalsPart ? ['', ...partText(totalsPart)] : []),\n ...(active.length\n ? [\n '',\n 'YOUR SITES',\n ...active.map(\n (site) =>\n `- ${site.name}${site.address ? ` (${site.address.label})` : ''}: ${siteLine(site) || 'see its summary'}` +\n (site.url ? ` · ${site.url}` : ''),\n ),\n ...(quiet ? [quiet] : []),\n ]\n : []),\n ...input.workspace.flatMap((part) => ['', ...partText(part)]),\n ...(input.aiInsightsUrl\n ? ['', `Want to know why the numbers moved? Turn on AI weekly insights from Ask about your numbers: ${input.aiInsightsUrl}`]\n : []),\n ...closing(input),\n ].join('\\n')\n return {\n subject,\n title: `${input.workspaceName} last week`,\n period: `${input.periodLabel}, compared with the week before`,\n html,\n text,\n buttonLabel: `Open ${input.workspaceName}`,\n url: input.url,\n }\n}\n"],"names":["pluginFigureCellText","pluginFigureIsoWeek","pluginFigureWindows","WEEKLY_SUMMARY_DIGEST_KEY","WEEKLY_SUMMARY_DAYS","WEEKLY_SUMMARY_TOP_ROWS","WEEKLY_SUMMARY_HEADLINE_COUNTS","TILES_PER_ROW","weeklySummaryPeriod","runAt","startOfToday","Date","UTC","getUTCFullYear","getUTCMonth","getUTCDate","now","current","week","from","to","label","weeklySummaryDay","day","at","toLocaleDateString","month","timeZone","weeklySummaryWeekday","weekday","ISO_DAY","weeklySummaryPlainDates","text","said","words","replace","_","figureCount","value","Number","isFinite","figureRow","table","key","rows","find","row","figureHasColumn","columns","some","column","figureStat","options","change","undefined","total","count","figureRanked","nameKey","filter","slice","map","String","figurePlural","one","many","toLocaleString","weeklySummaryHasNews","site","parts","length","weeklySummaryTotals","sites","sums","Map","part","stat","stats","sum","get","set","values","headline","join","weeklySummaryChange","sign","amount","Math","abs","maximumFractionDigits","esc","FONT","capitalized","charAt","toUpperCase","unlinked","changeHtml","colors","color","up","down","muted","arrow","weeklySummaryTileRows","left","push","min","TILE_GAP_PX","TILE_GAP","tilesHtml","sizes","forEach","size","cells","max","width","floor","tds","index","surface","border","rowsHtml","trs","sectionTitleHtml","title","FIGURE","figuresHtml","html","match","matchAll","weeklySummaryTilesHtml","sectionRowsHtml","cell","changes","url","link","sectionBarsHtml","bars","most","bar","marked","weight","accent","round","display","sectionHtml","section","first","points","point","weeklySummarySectionsHtml","sections","weeklySummaryFootnoteHtml","partHtml","note","addressHtml","workspaceName","address","name","insightsHtml","partText","lines","closing","input","settingsUrl","composeWeeklySummarySiteEmail","workspace","lead","subject","aiInsightsUrl","periodLabel","flatMap","productName","period","buttonLabel","composeWeeklySummaryOverviewEmail","active","totals","totalsPart","siteLine","quietCount","quiet","sitesHtml","line"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,oBAAoB,EACpBC,mBAAmB,EACnBC,mBAAmB,QAMd,sCAAkC;AAEzC;;;;;;;;;;;;;;;;;CAiBC,GAED,iGAAiG,GACjG,OAAO,MAAMC,4BAA4B,gBAAe;AAExD,0CAA0C,GAC1C,OAAO,MAAMC,sBAAsB,EAAC;AAEpC,8BAA8B,GAC9B,OAAO,MAAMC,0BAA0B,EAAC;AAExC,sEAAsE,GACtE,OAAO,MAAMC,iCAAiC,EAAC;AAE/C,kCAAkC,GAClC,MAAMC,gBAAgB;AAEtB;;;;CAIC,GACD,OAAO,SAASC,oBAAoBC,KAAW;IAO7C,MAAMC,eAAeC,KAAKC,GAAG,CAACH,MAAMI,cAAc,IAAIJ,MAAMK,WAAW,IAAIL,MAAMM,UAAU;IAC3F,MAAMC,MAAM,IAAIL,KAAKD,eA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ACZ,CAAChF,IAAI,CAAC;IACP,OAAO;QACLqF;QACA5C,OAAO,GAAGuC,MAAMP,aAAa,CAAC,UAAU,CAAC;QACzCiB,QAAQ,GAAGV,MAAMO,WAAW,CAAC,+BAA+B,CAAC;QAC7D3C;QACA/F;QACA8I,aAAa,CAAC,KAAK,EAAEX,MAAMP,aAAa,EAAE;QAC1CtB,KAAK6B,MAAM7B,GAAG;IAChB;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/weekly-summary.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n pluginFigureCellText,\n pluginFigureIsoWeek,\n pluginFigureWindows,\n type PluginFigureCell,\n type PluginFigureRow,\n type PluginFigureSummaryPart,\n type PluginFigureSummaryStat,\n type PluginFigureTable,\n} from '../plugin-manager/plugin-figures'\n\n/**\n * THE WEEKLY SUMMARY (AGL-3867): the free Monday emails that say how a\n * workspace did the week before — one for each site that had something to\n * report, and an overview of the workspace that adds the sites up.\n *\n * They spend nothing. Every figure comes from a `plugin-figures` reader that\n * declares a `weeklySummary`, and that reader's owner says what its table\n * means as tiles and ranked rows, so each plugin's counting rules decide what\n * a figure is and nothing here names one. AI weekly insights (AGL-2915) are\n * the paid version that explains the figures, and stay opt-in because each\n * one spends the workspace's AI credits.\n *\n * This module is the period, the wording helpers the readers use, and both\n * emails' words and layout; the reads and the sends are\n * `@aglyn/tenant-data-admin/server/weekly-summary`. The layout is drawn as\n * email-safe tables with inline styles, in colors the caller resolves from\n * the email theme.\n */\n\n/** The key a person's switch is stored under in `users/{uid}.digestPrefs`; on until turned off. */\nexport const WEEKLY_SUMMARY_DIGEST_KEY = 'weeklySummary'\n\n/** The window every figure is read over. */\nexport const WEEKLY_SUMMARY_DAYS = 7\n\n/** Rows a ranked list names. */\nexport const WEEKLY_SUMMARY_TOP_ROWS = 5\n\n/** Counts a subject line or the overview's tiles lead with, at most. */\nexport const WEEKLY_SUMMARY_HEADLINE_COUNTS = 3\n\n/** Tiles in one row of an email. */\nconst TILES_PER_ROW = 3\n\n/**\n * The week a run reports on: the seven whole UTC days before the day it runs,\n * so a Monday run covers Monday to Sunday and never a part-day of today.\n * `now` is what each reader is handed; `week` keys the run's marker.\n */\nexport function weeklySummaryPeriod(runAt: Date): {\n now: Date\n week: string\n from: string\n to: string\n label: string\n} {\n const startOfToday = Date.UTC(runAt.getUTCFullYear(), runAt.getUTCMonth(), runAt.getUTCDate())\n const now = new Date(startOfToday - 1)\n const { current } = pluginFigureWindows(now, WEEKLY_SUMMARY_DAYS)\n return {\n now,\n week: pluginFigureIsoWeek(now),\n from: current.from,\n to: current.to,\n label: `${weeklySummaryDay(current.from)} – ${weeklySummaryDay(current.to)}`,\n }\n}\n\n/** `2026-10-05` as \"Oct 5\". */\nexport function weeklySummaryDay(day: string): string {\n const at = new Date(`${day}T00:00:00Z`)\n return at.toLocaleDateString('en-US', { month: 'short', day: 'numeric', timeZone: 'UTC' })\n}\n\n/** `2026-10-26` as \"Mon, Oct 26\". */\nexport function weeklySummaryWeekday(day: string): string {\n const at = new Date(`${day}T00:00:00Z`)\n return at.toLocaleDateString('en-US', { weekday: 'short', month: 'short', day: 'numeric', timeZone: 'UTC' })\n}\n\nconst ISO_DAY = /\\b\\d{4}-\\d{2}-\\d{2}\\b/g\n\n/**\n * A sentence's dates as a person says them: \"Monday 2026-10-26\" as \"Monday,\n * Oct 26\". Tables hand the model their dates in ISO form, and it copies them.\n */\nexport function weeklySummaryPlainDates(text: string): string {\n const said = (day: string) => {\n const words = weeklySummaryDay(day)\n return words === 'Invalid Date' ? day : words\n }\n return text\n .replace(/\\b((?:Mon|Tues|Wednes|Thurs|Fri|Satur|Sun)day),? (\\d{4}-\\d{2}-\\d{2})\\b/g, (_, weekday: string, day: string) => `${weekday}, ${said(day)}`)\n .replace(ISO_DAY, said)\n}\n\n// ── Helpers the readers word their parts with ──────────────────────────────\n\n/** A cell as a number, `0` for anything that is not one. */\nexport function figureCount(value: PluginFigureCell | undefined): number {\n return typeof value === 'number' && Number.isFinite(value) ? value : 0\n}\n\n/** The row whose `key` cell is `label`: \"Visitors\" in a table of figures. */\nexport function figureRow(table: PluginFigureTable, key: string, label: string): PluginFigureRow | undefined {\n return table.rows.find((row) => row[key] === label)\n}\n\n/** Whether a table carries a column, so a reader that changed shape is noticed rather than misread. */\nexport function figureHasColumn(table: PluginFigureTable, key: string): boolean {\n return table.columns.some((column) => column.key === key)\n}\n\n/** A cell as a tile, with its change when the table has one. */\nexport function figureStat(\n table: PluginFigureTable,\n row: PluginFigureRow,\n key: string,\n label: string,\n options: { change?: string; total?: { one: string; many: string } } = {},\n): PluginFigureSummaryStat {\n const change = options.change ? row[options.change] : undefined\n return {\n label,\n value: pluginFigureCellText(table, key, row[key] ?? 0),\n ...(typeof change === 'number' ? { change } : {}),\n ...(options.total ? { total: { count: figureCount(row[key]), ...options.total } } : {}),\n }\n}\n\n/** The named rows with the most of `key`, as ranked rows with their change; `[]` when none has any. */\nexport function figureRanked(\n table: PluginFigureTable,\n nameKey: string,\n key: string,\n rows: readonly PluginFigureRow[] = table.rows,\n): Array<{ label: string; value: string; change?: number }> {\n return rows\n .filter((row) => typeof row[nameKey] === 'string' && figureCount(row[key]) > 0)\n .slice(0, WEEKLY_SUMMARY_TOP_ROWS)\n .map((row) => {\n const change = row['change']\n return {\n label: String(row[nameKey]),\n value: pluginFigureCellText(table, key, row[key] ?? 0),\n ...(typeof change === 'number' ? { change } : {}),\n }\n })\n}\n\n/** A table of days as a chart, oldest first, the busiest marked; `[]` for a week with nothing in it. */\nexport function figureBars(\n table: PluginFigureTable,\n dayKey: string,\n key: string,\n): NonNullable<PluginFigureSummaryPart['bars']> {\n const most = Math.max(...table.rows.map((row) => figureCount(row[key])), 0)\n if (!most) return []\n return table.rows.map((row) => ({\n label: weeklySummaryWeekday(String(row[dayKey])),\n value: figureCount(row[key]),\n display: pluginFigureCellText(table, key, row[key] ?? 0),\n marked: figureCount(row[key]) === most,\n }))\n}\n\n/** A row's label as a person reads it, and the page it names, when it names one. */\nexport function weeklySummaryRowLink(label: string, siteUrl: string | null): { label: string; url: string | null } {\n const page = label.startsWith('/')\n return { label: label === '/' ? 'Home' : label, url: page && siteUrl ? `${siteUrl}${label === '/' ? '' : label}` : null }\n}\n\n/** \"1 order\", \"18 orders\". */\nexport function figurePlural(count: number, one: string, many: string): string {\n return `${count.toLocaleString('en-US')} ${count === 1 ? one : many}`\n}\n\n// ── The emails ─────────────────────────────────────────────────────────────\n\n/** One site's figures for the week. */\nexport interface WeeklySummarySite {\n name: string\n /** The site's dashboard in the console, absolute; `null` with no origin to build it from. */\n url: string | null\n /**\n * Where the site itself is, so a reader knows which site this is: its\n * custom domain when it serves on one, else its platform address. `null`\n * for a site with no address yet.\n */\n address?: { label: string; url: string } | null\n parts: readonly PluginFigureSummaryPart[]\n}\n\n/** The colors an email is drawn in, resolved from its theme by the caller. */\nexport interface WeeklySummaryColors {\n text: string\n muted: string\n border: string\n /** A tile's ground. */\n surface: string\n /** The accent rule beside a callout. */\n accent: string\n /** Links: the email theme's own link color, the one every other link in the email wears. */\n link: string\n /** A rise and a fall. */\n up: string\n down: string\n}\n\n/** A site with anything to say. */\nexport function weeklySummaryHasNews(site: Pick<WeeklySummarySite, 'parts'>): boolean {\n return site.parts.length > 0\n}\n\n/** The counts the readers offered for adding up, summed by noun, in the order they were first given. */\nexport function weeklySummaryTotals(\n sites: ReadonlyArray<Pick<WeeklySummarySite, 'parts'>>,\n): Array<{ count: number; one: string; many: string }> {\n const sums = new Map<string, { count: number; one: string; many: string }>()\n for (const site of sites) {\n for (const part of site.parts) {\n for (const stat of part.stats ?? []) {\n if (!stat.total || stat.total.count <= 0) continue\n const sum = sums.get(stat.total.one)\n sums.set(stat.total.one, sum ? { ...sum, count: sum.count + stat.total.count } : { ...stat.total })\n }\n }\n }\n return [...sums.values()]\n}\n\nfunction headline(sites: ReadonlyArray<Pick<WeeklySummarySite, 'parts'>>): string {\n return weeklySummaryTotals(sites)\n .slice(0, WEEKLY_SUMMARY_HEADLINE_COUNTS)\n .map(({ count, one, many }) => figurePlural(count, one, many))\n .join(', ')\n}\n\n/** \"+12.5%\", \"−27.9%\", \"no change\"; `null` with nothing to compare with. */\nexport function weeklySummaryChange(change: number | null | undefined): { text: string; sign: 1 | -1 | 0 } | null {\n if (typeof change !== 'number' || !Number.isFinite(change)) return null\n if (change === 0) return { text: 'no change', sign: 0 }\n const amount = Math.abs(change).toLocaleString('en-US', { maximumFractionDigits: 1 })\n return change > 0 ? { text: `+${amount}%`, sign: 1 } : { text: `−${amount}%`, sign: -1 }\n}\n\nconst esc = (value: string): string =>\n value.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/\"/g, '"')\n\nconst FONT = 'Helvetica, Arial, sans-serif'\n\nconst capitalized = (value: string): string => value.charAt(0).toUpperCase() + value.slice(1)\n\n/**\n * A label that reads like an address — `www.google.com` — kept from being\n * turned into a link by the inbox, which would draw it in the inbox's own\n * blue beside the theme's links. A zero-width space after each dot breaks\n * the detection and nothing a reader sees.\n */\nconst unlinked = (value: string): string => esc(value).replace(/\\./g, '.\\u200b')\n\nfunction changeHtml(change: number | null | undefined, colors: WeeklySummaryColors): string {\n const said = weeklySummaryChange(change)\n if (!said) return ''\n const color = said.sign > 0 ? colors.up : said.sign < 0 ? colors.down : colors.muted\n const arrow = said.sign > 0 ? '▲ ' : said.sign < 0 ? '▼ ' : ''\n return `<div style=\"font-family:${FONT};font-size:13px;line-height:1.4;font-weight:600;color:${color};\">${arrow}${esc(said.text)}</div>`\n}\n\n/**\n * How many tiles share each row: one row of up to three, two rows of two for\n * four, then rows of three — so a row is never left with an empty slot\n * beside two tiles.\n */\nexport function weeklySummaryTileRows(count: number): number[] {\n if (count <= 0) return []\n if (count <= TILES_PER_ROW) return [count]\n if (count === 4) return [2, 2]\n const rows: number[] = []\n for (let left = count; left > 0; left -= TILES_PER_ROW) rows.push(Math.min(TILES_PER_ROW, left))\n return rows\n}\n\n/** The gap between tiles, across and down. */\nconst TILE_GAP_PX = 8\n\n/** A cell that is only a gap: nothing in it may hold it open. */\nconst TILE_GAP = 'font-size:0;line-height:0;padding:0;'\n\n/**\n * Tiles, each a value, its label and its change, filling the width of their\n * row. The tile is the table cell itself, so a row's tiles are one height\n * whichever of them wraps, in every mail client; the gaps are cells of their own.\n */\nfunction tilesHtml(stats: readonly PluginFigureSummaryStat[], colors: WeeklySummaryColors): string {\n const sizes = weeklySummaryTileRows(stats.length)\n const rows: string[] = []\n let at = 0\n sizes.forEach((size) => {\n const cells = stats.slice(at, at + size)\n at += size\n // A tile alone takes half the row, not all of it, so it reads as a tile.\n const columns = Math.max(size, 2)\n const width = `${Math.floor(100 / columns)}%`\n const tds: string[] = []\n for (let index = 0; index < columns; index += 1) {\n if (index > 0) tds.push(`<td style=\"width:${TILE_GAP_PX}px;${TILE_GAP}\"> </td>`)\n const stat = cells[index]\n tds.push(\n stat\n ? `<td style=\"width:${width};background-color:${colors.surface};border:1px solid ${colors.border};border-radius:8px;padding:12px 14px;vertical-align:top;\">` +\n `<div style=\"font-family:${FONT};font-size:24px;line-height:1.2;font-weight:700;color:${colors.text};\">${esc(stat.value)}</div>` +\n `<div style=\"font-family:${FONT};font-size:13px;line-height:1.4;color:${colors.muted};\">${esc(stat.label)}</div>` +\n changeHtml(stat.change, colors) +\n `</td>`\n : `<td style=\"width:${width};\"></td>`,\n )\n }\n rows.push(`<tr>${tds.join('')}</tr>`)\n rows.push(`<tr><td colspan=\"${columns * 2 - 1}\" style=\"height:${TILE_GAP_PX}px;${TILE_GAP}\"> </td></tr>`)\n })\n return `<table role=\"presentation\" style=\"width:100%;border-collapse:separate;border-spacing:0;table-layout:fixed;\">${rows.join('')}</table>`\n}\n\nfunction sectionTitleHtml(title: string, colors: WeeklySummaryColors): string {\n return (\n `<div style=\"font-family:${FONT};font-size:12px;line-height:1.4;font-weight:700;letter-spacing:0.06em;` +\n `text-transform:uppercase;color:${colors.muted};padding:0 0 8px;\">${esc(title)}</div>`\n )\n}\n\n/** A figure in a sentence: a count, a sum or a percent, never the digits in a path or a date. */\nconst FIGURE =\n /(?<![\\p{L}\\p{N}_./-])(?<!(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) )[+\\-−]?[$€£¥]?(?:\\d{1,3}(?:,\\d{3})+|\\d+)(?:\\.\\d+)?%?(?![\\p{L}\\p{N}_/-])/gu\n\n/** A sentence with its figures in bold, so an eye running down the email lands on them. */\nfunction figuresHtml(text: string, colors: WeeklySummaryColors): string {\n let html = ''\n let at = 0\n for (const match of text.matchAll(FIGURE)) {\n html += `${unlinked(text.slice(at, match.index))}<strong style=\"font-weight:700;color:${colors.text};\">${esc(match[0])}</strong>`\n at = match.index + match[0].length\n }\n return html + unlinked(text.slice(at))\n}\n\n/** A figure a digest section lists: a page and its views. */\nexport interface WeeklySummarySectionRow {\n label: string\n /** Where the label goes: the page itself. */\n url?: string | null\n value: string\n change?: number | null\n}\n\n/** One day of a section's chart; `marked` when it is a day the section is about. */\nexport interface WeeklySummarySectionBar {\n label: string\n value: number\n /** The value as a person reads it. */\n display: string\n marked: boolean\n}\n\n/** One topic of a weekly email, told once: what stood out, and the figures behind it. */\nexport interface WeeklySummarySection {\n title: string\n /** Where the figures can be seen in full. */\n link?: { label: string; url: string } | null\n /** What was said about it: a line to scan and, if it needs one, the sentence behind it. */\n points: ReadonlyArray<{ headline: string | null; text: string | null }>\n stats?: readonly PluginFigureSummaryStat[]\n rows?: readonly WeeklySummarySectionRow[]\n bars?: readonly WeeklySummarySectionBar[]\n}\n\n/** Tiles on their own, for an email that leads with its headline figures. */\nexport function weeklySummaryTilesHtml(stats: readonly PluginFigureSummaryStat[], colors: WeeklySummaryColors): string {\n return stats.length ? `<div style=\"padding:12px 0 8px;\">${tilesHtml(stats, colors)}</div>` : ''\n}\n\nfunction sectionRowsHtml(rows: readonly WeeklySummarySectionRow[], colors: WeeklySummaryColors): string {\n const cell = `font-family:${FONT};font-size:14px;line-height:1.4;padding:7px 0;`\n // No column for a change no row has, so the figures reach the edge.\n const changes = rows.some((row) => weeklySummaryChange(row.change))\n const trs = rows.map((row, index) => {\n const border = index > 0 ? `border-top:1px solid ${colors.border};` : ''\n const label = row.url\n ? `<a href=\"${esc(row.url)}\" style=\"color:${colors.link};text-decoration:none;font-weight:600;\">${unlinked(row.label)}</a>`\n : unlinked(row.label)\n return (\n `<tr>` +\n `<td style=\"${cell}${border}color:${colors.text};word-break:break-word;\">${label}</td>` +\n `<td style=\"${cell}${border}color:${colors.text};font-weight:600;padding-left:12px;text-align:right;white-space:nowrap;\">${esc(row.value)}</td>` +\n (changes\n ? `<td style=\"${cell}${border}padding-left:12px;text-align:right;white-space:nowrap;\">${changeHtml(row.change, colors)}</td>`\n : '') +\n `</tr>`\n )\n })\n return `<table role=\"presentation\" style=\"width:100%;border-collapse:collapse;margin-top:8px;\">${trs.join('')}</table>`\n}\n\n/** Horizontal bars, drawn in table cells so every mail client keeps them. */\nfunction sectionBarsHtml(bars: readonly WeeklySummarySectionBar[], colors: WeeklySummaryColors): string {\n const most = Math.max(...bars.map((bar) => bar.value), 1)\n const trs = bars.map((bar) => {\n const text = `font-family:${FONT};font-size:13px;line-height:1.3;color:${bar.marked ? colors.text : colors.muted};white-space:nowrap;`\n const weight = bar.marked ? 'font-weight:700;' : ''\n return (\n `<tr>` +\n `<td style=\"${text}${weight}padding:3px 10px 3px 0;width:1%;\">${esc(bar.label)}</td>` +\n `<td style=\"padding:3px 0;\"><div style=\"background-color:${bar.marked ? colors.accent : colors.border};border-radius:2px;font-size:0;height:10px;line-height:0;width:${Math.max(1, Math.round((bar.value / most) * 100))}%;\"> </div></td>` +\n `<td style=\"${text}${weight}padding:3px 0 3px 10px;text-align:right;width:1%;\">${esc(bar.display)}</td>` +\n `</tr>`\n )\n })\n return `<table role=\"presentation\" style=\"width:100%;border-collapse:collapse;margin-top:8px;\">${trs.join('')}</table>`\n}\n\nfunction sectionHtml(section: WeeklySummarySection, colors: WeeklySummaryColors, first: boolean): string {\n const link = section.link\n ? `<td style=\"padding:0;text-align:right;vertical-align:baseline;white-space:nowrap;\">` +\n `<a href=\"${esc(section.link.url)}\" style=\"font-family:${FONT};font-size:13px;line-height:1.4;font-weight:600;color:${colors.link};text-decoration:none;\">${esc(section.link.label)} →</a>` +\n `</td>`\n : ''\n const points = section.points.map(\n (point) =>\n `<div style=\"padding:6px 0 0;\">` +\n (point.headline\n ? `<div style=\"font-family:${FONT};font-size:16px;line-height:1.35;font-weight:700;color:${colors.text};\">${unlinked(point.headline)}</div>`\n : '') +\n (point.text\n ? `<div style=\"font-family:${FONT};font-size:14px;line-height:1.5;color:${colors.muted};\">${figuresHtml(point.text, colors)}</div>`\n : '') +\n `</div>`,\n )\n return (\n `<div style=\"padding:${first ? '8px' : '18px'} 0 18px;${first ? '' : `border-top:1px solid ${colors.border};`}\">` +\n `<table role=\"presentation\" style=\"width:100%;border-collapse:collapse;\"><tr>` +\n `<td style=\"font-family:${FONT};font-size:12px;line-height:1.4;font-weight:700;letter-spacing:0.06em;text-transform:uppercase;color:${colors.muted};padding:0;\">${esc(section.title)}</td>` +\n link +\n `</tr></table>` +\n points.join('') +\n (section.stats?.length ? `<div style=\"padding:8px 0 0;\">${tilesHtml(section.stats, colors)}</div>` : '') +\n (section.rows?.length ? sectionRowsHtml(section.rows, colors) : '') +\n (section.bars?.length ? sectionBarsHtml(section.bars, colors) : '') +\n `</div>`\n )\n}\n\n/** A weekly email's topics, a hairline between them; `following` when something already sits above the first. */\nexport function weeklySummarySectionsHtml(\n sections: readonly WeeklySummarySection[],\n colors: WeeklySummaryColors,\n following = false,\n): string {\n return sections.map((section, index) => sectionHtml(section, colors, index === 0 && !following)).join('')\n}\n\n/** The small print under the button, with its one link. */\nexport function weeklySummaryFootnoteHtml(\n text: string,\n link: { label: string; url: string } | null,\n colors: WeeklySummaryColors,\n): string {\n return (\n `<div style=\"font-family:${FONT};font-size:12px;line-height:1.5;color:${colors.muted};padding:12px 0 0;\">` +\n esc(text) +\n (link ? ` <a href=\"${esc(link.url)}\" style=\"color:${colors.link};text-decoration:underline;\">${esc(link.label)}</a>` : '') +\n `</div>`\n )\n}\n\n/** A reader's part as a section of the email, its page rows linked to the site. */\nfunction partSection(part: PluginFigureSummaryPart, siteUrl: string | null): WeeklySummarySection {\n return {\n title: part.title,\n link: part.link ?? null,\n points: part.note ? [{ headline: null, text: part.note }] : [],\n ...(part.stats?.length ? { stats: part.stats } : {}),\n ...(part.rows?.length ? { rows: part.rows.map((row) => ({ ...row, ...weeklySummaryRowLink(row.label, siteUrl) })) } : {}),\n ...(part.bars?.length ? { bars: part.bars } : {}),\n }\n}\n\n/** \"aglyn.com · Aglyn LLC\": which site, linked, and whose. */\nfunction addressHtml(site: WeeklySummarySite, workspaceName: string, colors: WeeklySummaryColors): string {\n const address = site.address\n ? `<a href=\"${esc(site.address.url)}\" style=\"color:${colors.link};text-decoration:underline;font-weight:600;\">${esc(site.address.label)}</a>`\n : `<span style=\"font-weight:600;\">${esc(site.name)}</span>`\n return (\n `<div style=\"font-family:${FONT};font-size:14px;line-height:1.5;color:${colors.muted};padding:0 0 4px;\">` +\n `${address} · ${esc(workspaceName)}</div>`\n )\n}\n\nfunction insightsHtml(url: string, colors: WeeklySummaryColors): string {\n return (\n `<div style=\"margin:16px 0 0;background-color:${colors.surface};border-left:3px solid ${colors.accent};border-radius:4px;padding:14px 16px;\">` +\n `<div style=\"font-family:${FONT};font-size:14px;line-height:1.5;font-weight:700;color:${colors.text};\">Want to know why the numbers moved?</div>` +\n `<div style=\"font-family:${FONT};font-size:14px;line-height:1.5;color:${colors.text};\">` +\n `AI weekly insights explain each site's week in a few plain sentences. ` +\n `<a href=\"${esc(url)}\" style=\"color:${colors.link};text-decoration:underline;\">Turn them on from Ask about your numbers</a>.` +\n `</div></div>`\n )\n}\n\nfunction partText(part: PluginFigureSummaryPart): string[] {\n const lines = [part.title.toUpperCase()]\n if (part.note) lines.push(part.note)\n for (const stat of part.stats ?? []) {\n const said = weeklySummaryChange(stat.change)\n lines.push(`${stat.label}: ${stat.value}${said ? ` (${said.text})` : ''}`)\n }\n for (const row of part.rows ?? []) {\n const said = weeklySummaryChange(row.change)\n lines.push(`- ${row.label}: ${row.value}${said ? ` (${said.text})` : ''}`)\n }\n for (const bar of part.bars ?? []) lines.push(`- ${bar.label}: ${bar.display}`)\n if (part.link) lines.push(`${part.link.label}: ${part.link.url}`)\n return lines\n}\n\n/** What a send fills a weekly summary email's tokens with. */\nexport interface WeeklySummaryEmail {\n subject: string\n /** The heading: \"Aglyn last week\". */\n title: string\n /** \"Oct 5 – Oct 11, compared with the week before\". */\n period: string\n /** The figures, drawn. */\n html: string\n /** The small print under the button. */\n footnote: string\n /** The whole email as plain text, closing line included. */\n text: string\n buttonLabel: string\n /** Where the button goes; `''` when there is no console origin to link to. */\n url: string\n}\n\ninterface CommonInput {\n workspaceName: string\n productName: string\n periodLabel: string\n colors: WeeklySummaryColors\n /** Where AI weekly insights are turned on, when the plan includes them and this person has not; else `null`. */\n aiInsightsUrl: string | null\n settingsUrl: string\n}\n\nfunction footnote(input: CommonInput): string {\n return weeklySummaryFootnoteHtml('', { label: 'Change what you are emailed about', url: input.settingsUrl }, input.colors)\n}\n\nfunction closing(input: CommonInput): string[] {\n return [\n '',\n `You get this summary because you manage ${input.workspaceName}. Turn it off in Notifications: ${input.settingsUrl}`,\n ]\n}\n\n/**\n * One site's email, or `null` for a site with nothing to report. `workspace`\n * carries the workspace's own parts when this site's email stands in for the\n * overview, in a workspace with one active site.\n */\nexport function composeWeeklySummarySiteEmail(\n input: CommonInput & { site: WeeklySummarySite; workspace?: readonly PluginFigureSummaryPart[] },\n): WeeklySummaryEmail | null {\n const workspace = input.workspace ?? []\n if (!weeklySummaryHasNews(input.site) && !workspace.length) return null\n const lead = headline([input.site])\n const subject = lead ? `${input.site.name} last week: ${lead}` : `${input.site.name} last week`\n const siteUrl = input.site.address?.url ?? null\n const html =\n addressHtml(input.site, input.workspaceName, input.colors) +\n weeklySummarySectionsHtml(\n [\n ...input.site.parts.map((part) => partSection(part, siteUrl)),\n ...workspace.map((part) => partSection({ ...part, title: `${input.workspaceName} · ${part.title}` }, null)),\n ],\n input.colors,\n ) +\n (input.aiInsightsUrl ? insightsHtml(input.aiInsightsUrl, input.colors) : '')\n const text = [\n `${input.site.name} last week, ${input.periodLabel}. A change in brackets is against the week before.`,\n `Site: ${input.site.address ? `${input.site.address.label} (${input.site.address.url})` : input.site.name} · ${input.workspaceName}`,\n ...input.site.parts.flatMap((part) => ['', ...partText(part)]),\n ...workspace.flatMap((part) => ['', ...partText({ ...part, title: `${input.workspaceName} · ${part.title}` })]),\n ...(input.site.url ? ['', `Open ${input.site.name} in ${input.productName}: ${input.site.url}`] : []),\n ...(input.aiInsightsUrl\n ? ['', `Want to know why the numbers moved? Turn on AI weekly insights from Ask about your numbers: ${input.aiInsightsUrl}`]\n : []),\n ...closing(input),\n ].join('\\n')\n return {\n subject,\n title: `${input.site.name} last week`,\n period: `${input.periodLabel}, compared with the week before`,\n html,\n footnote: footnote(input),\n text,\n buttonLabel: `Open ${input.site.name}`,\n url: input.site.url ?? '',\n }\n}\n\n/**\n * The workspace overview: the week's totals across its sites, a line for each\n * site, and the workspace's own figures, or `null` when nothing anywhere has\n * anything to report.\n */\nexport function composeWeeklySummaryOverviewEmail(\n input: CommonInput & {\n sites: readonly WeeklySummarySite[]\n workspace: readonly PluginFigureSummaryPart[]\n /** The workspace's home in the console, absolute; `''` with no origin. */\n url: string\n },\n): WeeklySummaryEmail | null {\n const active = input.sites.filter(weeklySummaryHasNews)\n if (!active.length && !input.workspace.length) return null\n const totals = weeklySummaryTotals(active)\n const lead = totals\n .slice(0, WEEKLY_SUMMARY_HEADLINE_COUNTS)\n .map(({ count, one, many }) => figurePlural(count, one, many))\n .join(', ')\n const subject = lead ? `Your week at ${input.workspaceName}: ${lead}` : `Your week at ${input.workspaceName}`\n const { colors } = input\n const totalsPart: PluginFigureSummaryPart | null = totals.length\n ? {\n title: active.length === 1 ? 'At a glance' : `Across ${active.length} sites`,\n stats: totals.slice(0, TILES_PER_ROW * 2).map(({ count, one, many }) => ({\n label: capitalized(count === 1 ? one : many),\n value: count.toLocaleString('en-US'),\n })),\n }\n : null\n const siteLine = (site: WeeklySummarySite): string =>\n site.parts\n .flatMap((part) => part.stats ?? [])\n .filter((stat) => stat.total && stat.total.count > 0)\n .slice(0, WEEKLY_SUMMARY_HEADLINE_COUNTS)\n .map((stat) => {\n const total = stat.total as NonNullable<PluginFigureSummaryStat['total']>\n const said = weeklySummaryChange(stat.change)\n return `${figurePlural(total.count, total.one, total.many)}${said ? ` (${said.text})` : ''}`\n })\n .join(' · ')\n const quietCount = input.sites.length - active.length\n const quiet = quietCount\n ? `${figurePlural(quietCount, 'other site', 'other sites')} had nothing to report.`\n : ''\n const sitesHtml = active.length\n ? `<div style=\"padding:18px 0 8px;${totalsPart ? `border-top:1px solid ${colors.border};` : ''}\">` +\n sectionTitleHtml('Your sites', colors) +\n `<table role=\"presentation\" style=\"width:100%;border-collapse:collapse;\">` +\n active\n .map((site, index) => {\n const border = index < active.length - 1 ? `border-bottom:1px solid ${colors.border};` : ''\n const name = site.url\n ? `<a href=\"${esc(site.url)}\" style=\"color:${colors.link};text-decoration:none;font-weight:700;\">${esc(site.name)}</a>`\n : `<span style=\"font-weight:700;\">${esc(site.name)}</span>`\n const line = siteLine(site)\n const address = site.address\n ? ` <a href=\"${esc(site.address.url)}\" style=\"color:${colors.muted};text-decoration:underline;font-size:13px;font-weight:400;\">${esc(site.address.label)}</a>`\n : ''\n return (\n `<tr><td style=\"font-family:${FONT};font-size:15px;line-height:1.4;color:${colors.text};padding:10px 0;${border}\">` +\n name +\n address +\n (line ? `<div style=\"font-size:13px;line-height:1.5;color:${colors.muted};\">${esc(line)}</div>` : '') +\n `</td></tr>`\n )\n })\n .join('') +\n `</table>` +\n (quiet\n ? `<div style=\"font-family:${FONT};font-size:13px;line-height:1.5;color:${colors.muted};padding:4px 0 0;\">${esc(quiet)}</div>`\n : '') +\n `</div>`\n : ''\n const html =\n (totalsPart ? weeklySummarySectionsHtml([partSection(totalsPart, null)], colors) : '') +\n sitesHtml +\n weeklySummarySectionsHtml(\n input.workspace.map((part) => partSection(part, null)),\n colors,\n Boolean(totalsPart || sitesHtml),\n ) +\n (active.length > 1\n ? `<div style=\"font-family:${FONT};font-size:13px;line-height:1.5;color:${colors.muted};padding:8px 0 0;\">Each site's own summary arrives beside this one.</div>`\n : '') +\n (input.aiInsightsUrl ? insightsHtml(input.aiInsightsUrl, colors) : '')\n const text = [\n `Here is how ${input.workspaceName} did last week, ${input.periodLabel}. A change in brackets is against the week before.`,\n ...(totalsPart ? ['', ...partText(totalsPart)] : []),\n ...(active.length\n ? [\n '',\n 'YOUR SITES',\n ...active.map(\n (site) =>\n `- ${site.name}${site.address ? ` (${site.address.label})` : ''}: ${siteLine(site) || 'see its summary'}` +\n (site.url ? ` · ${site.url}` : ''),\n ),\n ...(quiet ? [quiet] : []),\n ]\n : []),\n ...input.workspace.flatMap((part) => ['', ...partText(part)]),\n ...(input.aiInsightsUrl\n ? ['', `Want to know why the numbers moved? Turn on AI weekly insights from Ask about your numbers: ${input.aiInsightsUrl}`]\n : []),\n ...closing(input),\n ].join('\\n')\n return {\n subject,\n title: `${input.workspaceName} last week`,\n period: `${input.periodLabel}, compared with the week before`,\n html,\n footnote: footnote(input),\n text,\n buttonLabel: `Open ${input.workspaceName}`,\n url: input.url,\n }\n}\n"],"names":["pluginFigureCellText","pluginFigureIsoWeek","pluginFigureWindows","WEEKLY_SUMMARY_DIGEST_KEY","WEEKLY_SUMMARY_DAYS","WEEKLY_SUMMARY_TOP_ROWS","WEEKLY_SUMMARY_HEADLINE_COUNTS","TILES_PER_ROW","weeklySummaryPeriod","runAt","startOfToday","Date","UTC","getUTCFullYear","getUTCMonth","getUTCDate","now","current","week","from","to","label","weeklySummaryDay","day","at","toLocaleDateString","month","timeZone","weeklySummaryWeekday","weekday","ISO_DAY","weeklySummaryPlainDates","text","said","words","replace","_","figureCount","value","Number","isFinite","figureRow","table","key","rows","find","row","figureHasColumn","columns","some","column","figureStat","options","change","undefined","total","count","figureRanked","nameKey","filter","slice","map","String","figureBars","dayKey","most","Math","max","display","marked","weeklySummaryRowLink","siteUrl","page","startsWith","url","figurePlural","one","many","toLocaleString","weeklySummaryHasNews","site","parts","length","weeklySummaryTotals","sites","sums","Map","part","stat","stats","sum","get","set","values","headline","join","weeklySummaryChange","sign","amount","abs","maximumFractionDigits","esc","FONT","capitalized","charAt","toUpperCase","unlinked","changeHtml","colors","color","up","down","muted","arrow","weeklySummaryTileRows","left","push","min","TILE_GAP_PX","TILE_GAP","tilesHtml","sizes","forEach","size","cells","width","floor","tds","index","surface","border","sectionTitleHtml","title","FIGURE","figuresHtml","html","match","matchAll","weeklySummaryTilesHtml","sectionRowsHtml","cell","changes","trs","link","sectionBarsHtml","bars","bar","weight","accent","round","sectionHtml","section","first","points","point","weeklySummarySectionsHtml","sections","following","weeklySummaryFootnoteHtml","partSection","note","addressHtml","workspaceName","address","name","insightsHtml","partText","lines","footnote","input","settingsUrl","closing","composeWeeklySummarySiteEmail","workspace","lead","subject","aiInsightsUrl","periodLabel","flatMap","productName","period","buttonLabel","composeWeeklySummaryOverviewEmail","active","totals","totalsPart","siteLine","quietCount","quiet","sitesHtml","line","Boolean"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,oBAAoB,EACpBC,mBAAmB,EACnBC,mBAAmB,QAMd,sCAAkC;AAEzC;;;;;;;;;;;;;;;;;CAiBC,GAED,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KmF,OAAO,CAAC9I,KAAK,CAAC,CAAC,CAAC,GAAG,GAAG,EAAE,EAAEqK,SAAS1G,SAAS,mBAAmB,GACxGA,CAAAA,KAAKN,GAAG,GAAG,CAAC,GAAG,EAAEM,KAAKN,GAAG,EAAE,GAAG,EAAC;eAEhCkH,QAAQ;gBAACA;aAAM,GAAG,EAAE;SACzB,GACD,EAAE;WACHnB,MAAMI,SAAS,CAACK,OAAO,CAAC,CAAC3F,OAAS;gBAAC;mBAAO+E,SAAS/E;aAAM;WACxDkF,MAAMO,aAAa,GACnB;YAAC;YAAI,CAAC,4FAA4F,EAAEP,MAAMO,aAAa,EAAE;SAAC,GAC1H,EAAE;WACHL,QAAQF;KACZ,CAAC1E,IAAI,CAAC;IACP,OAAO;QACLgF;QACA3C,OAAO,GAAGqC,MAAMP,aAAa,CAAC,UAAU,CAAC;QACzCkB,QAAQ,GAAGX,MAAMQ,WAAW,CAAC,+BAA+B,CAAC;QAC7D1C;QACAiC,UAAUA,SAASC;QACnBzI;QACAqJ,aAAa,CAAC,KAAK,EAAEZ,MAAMP,aAAa,EAAE;QAC1CxF,KAAK+F,MAAM/F,GAAG;IAChB;AACF"}
|
|
@@ -193,19 +193,39 @@ export interface PluginFigureSummaryStat {
|
|
|
193
193
|
many: string;
|
|
194
194
|
};
|
|
195
195
|
}
|
|
196
|
-
/** One reader's part of a weekly summary: a titled block of tiles, ranked rows, or
|
|
196
|
+
/** One reader's part of a weekly summary: a titled block of tiles, ranked rows, a chart of days, or some of each. */
|
|
197
197
|
export interface PluginFigureSummaryPart {
|
|
198
198
|
/** The block's heading: "Traffic", "Top pages". */
|
|
199
199
|
title: string;
|
|
200
200
|
stats?: readonly PluginFigureSummaryStat[];
|
|
201
|
-
/** A ranked list, most first: a page and its views, a form and its submissions. */
|
|
201
|
+
/** A ranked list, most first: a page and its views, a form and its submissions, each with its change when the table has one. */
|
|
202
202
|
rows?: ReadonlyArray<{
|
|
203
203
|
label: string;
|
|
204
204
|
value: string;
|
|
205
|
+
change?: number | null;
|
|
205
206
|
}>;
|
|
207
|
+
/** A chart of days, oldest first; `marked` picks out the day the chart is about. */
|
|
208
|
+
bars?: ReadonlyArray<{
|
|
209
|
+
label: string;
|
|
210
|
+
value: number;
|
|
211
|
+
display: string;
|
|
212
|
+
marked: boolean;
|
|
213
|
+
}>;
|
|
214
|
+
/** Where the figures can be seen in full. The weekly summary sets it from the table's own source. */
|
|
215
|
+
link?: {
|
|
216
|
+
label: string;
|
|
217
|
+
url: string;
|
|
218
|
+
} | null;
|
|
206
219
|
/** One plain sentence the figures need. */
|
|
207
220
|
note?: string;
|
|
208
221
|
}
|
|
222
|
+
/** The console page a table's figures come from, under the site or the workspace; `null` when the table names none. */
|
|
223
|
+
export declare function pluginFigureSourceHref(source: {
|
|
224
|
+
path: string | null;
|
|
225
|
+
}, scope: PluginFigureScope, where: {
|
|
226
|
+
orgSlug: string;
|
|
227
|
+
host: string | null;
|
|
228
|
+
}): string | null;
|
|
209
229
|
/** A reader's part in the weekly summary. */
|
|
210
230
|
export interface PluginFigureWeeklySummary {
|
|
211
231
|
/**
|
|
@@ -26,6 +26,11 @@ export const PLUGIN_FIGURE_COLUMN_KINDS = [
|
|
|
26
26
|
'duration',
|
|
27
27
|
'date'
|
|
28
28
|
];
|
|
29
|
+
/** The console page a table's figures come from, under the site or the workspace; `null` when the table names none. */ export function pluginFigureSourceHref(source, scope, where) {
|
|
30
|
+
if (!source.path || !where.orgSlug) return null;
|
|
31
|
+
if (scope === 'org') return `/${where.orgSlug}/${source.path}`;
|
|
32
|
+
return where.host ? `/${where.orgSlug}/hosts/${where.host}/${source.path}` : null;
|
|
33
|
+
}
|
|
29
34
|
export const PLUGIN_FIGURES = definePluginServiceContract('core.figures', {
|
|
30
35
|
multiple: true
|
|
31
36
|
});
|