@oboapp/source-toplo-bg 0.2.0 → 0.2.1

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/README.md CHANGED
@@ -4,7 +4,11 @@ Collects heating incidents from the HTML listing at `https://toplo.bg/accidents-
4
4
 
5
5
  Pass `createSource` and the isolated `metadata` entrypoint to Obo's scheduled source runner. Create one instance per scan. `discoverItems` emits the exact historical synthetic identifiers, such as `https://toplo.bg/incidents/item-1`. `fetchItem` reads content from that instance's listing cache and makes no request to the synthetic URL. Discovery items have no payload, so large geometries remain available without exceeding the SDK's 256 KiB discovery payload limit. `close` clears the cache and cancels active requests.
6
6
 
7
- The package preserves Bulgarian content formatting, publication dates, heating categories, empty detail links, timespan fallback rules, and precomputed geometry. It keeps the legacy handling of Point, LineString and Polygon features: fix swapped Sofia coordinates, discard invalid features, retain other valid features, and skip incidents whose features are all invalid. An empty FeatureCollection remains valid. The same Sofia bounds as the legacy validator are used to recognize swapped coordinates. Malformed incident blocks, invalid geometry and coordinate corrections emit warnings.
7
+ Heating notifications start with the incident type and affected area, followed by the expected restoration time when Toplo supplies one. The Markdown detail shows the start, expected restoration and addresses. Type 0 displays as „Авария“, type 1 as „Ремонт“, and unfamiliar or missing types as „Прекъсване“. Toplo identifies the two known types in its [listing legend](https://toplo.bg/accidents-and-maintenance) and [map script](https://toplo.bg/Portal.ToploTheme/js/accidents/accidentsMap.js).
8
+
9
+ The alert uses the same clock as Toplo's listing. For example, the provider displays `2026-11-28T11:00:00Z` as `11:00`. This applies in both winter and summer and on hosts in any timezone. The stored ISO fields keep the provider timestamps.
10
+
11
+ The package preserves publication dates, heating categories, empty detail links, timespan fallback rules, and precomputed geometry. It fixes swapped Sofia coordinates, discards invalid Point, LineString and Polygon features, retains other valid features, and skips incidents whose features are all invalid. An empty FeatureCollection remains valid. The same Sofia bounds as the legacy validator are used to recognize swapped coordinates. Malformed incident blocks, invalid geometry and coordinate corrections emit warnings.
8
12
 
9
13
  An optional `onListing` callback observes the same fetched HTML before content parsing. It receives `{ html, observedAt }`, where `observedAt` is an ISO timestamp recorded after the response body is read. Return `{ count }` with a nonnegative safe integer for the complete listing, including incidents without usable geometry. The callback can be synchronous or asynchronous. A failed callback fails discovery, and cancellation is checked again after it completes.
10
14
 
@@ -19,8 +23,8 @@ const source = createSource(context, {
19
23
 
20
24
  The observer owns complete-listing validation before returning zero. A verified zero permits an empty discovery. Without an observer, or when it reports a positive count, a listing with no parsed incidents fails. A zero count that contradicts parsed incidents also fails. A positive count can exceed the geometry-filtered discovery count. Observation uses the existing response without another provider request. The package owns the request timeout and instance cache.
21
25
 
22
- Dates in text use the process timezone, matching the existing crawler. Invalid or pre-2025 starts fall back to the current time for the timespan; missing or invalid ends fall back to the start. The original `datePublished` and title remain unchanged. Obo controls content validation before storage.
26
+ The text omits missing, invalid and pre-2025 dates. The stored timespan keeps its existing fallbacks. An invalid or pre-2025 start falls back to the current time, and a missing, invalid or pre-2025 end falls back to the start. The package retains the original `datePublished`. Obo controls content validation before storage.
23
27
 
24
- The frozen listing and expected content fixtures come from Obo's pre-refactor Toplo contract. Tests cover literal identity, content, geometry cleanup, large cached incidents, failure handling, cancellation, ESM/CommonJS entrypoints, listing observation and verified empty listings.
28
+ The listing fixture comes from Obo's original Toplo contract. Tests cover Bulgarian alert text and Markdown, literal identifiers, geometry cleanup, large cached incidents, failure handling, cancellation, ESM/CommonJS entrypoints, listing observation and verified empty listings.
25
29
 
26
30
  Obo owns deduplication, storage, scheduling, source ID and locality validation. Keep the existing `toplo-bg` job and emergent schedule when integrating. Publish this package through the reviewed release process in the repository's `RELEASING.md`, then install the exact npm version in a separate Obo integration PR. Roll back the integration by restoring the previous crawler entrypoint and redeploying; stored identifiers stay compatible.
@@ -2,31 +2,63 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildContent = buildContent;
4
4
  const MINIMUM_DATE = Date.UTC(2025, 0, 1);
5
+ // Toplo labels its published local clock times with Z. UTC formatting preserves the clock shown on its site.
6
+ const displayDate = new Intl.DateTimeFormat("bg-BG", { dateStyle: "long", timeZone: "UTC" });
7
+ const displayTime = new Intl.DateTimeFormat("bg-BG", { hour: "2-digit", minute: "2-digit", timeZone: "UTC" });
8
+ function incidentTypeLabel(type) {
9
+ switch (type) {
10
+ case 0:
11
+ return "Авария";
12
+ case 1:
13
+ return "Ремонт";
14
+ default:
15
+ return "Прекъсване";
16
+ }
17
+ }
5
18
  function formatDate(value) {
6
- return new Date(value).toLocaleString("bg-BG", {
7
- year: "numeric",
8
- month: "long",
9
- day: "numeric",
10
- hour: "2-digit",
11
- minute: "2-digit",
12
- });
19
+ return `${displayDate.format(value)}, ${displayTime.format(value)}`;
20
+ }
21
+ function providerDate(value) {
22
+ if (!value) {
23
+ return undefined;
24
+ }
25
+ const date = new Date(value);
26
+ return date.getTime() >= MINIMUM_DATE ? date : undefined;
13
27
  }
14
- function timespanDate(value, fallback) {
15
- const parsed = value ? new Date(value) : fallback;
16
- return parsed.getTime() >= MINIMUM_DATE ? parsed : fallback;
28
+ function incidentTitle(incident) {
29
+ const area = incident.name.trim();
30
+ const kind = incidentTypeLabel(incident.type);
31
+ return area && area !== kind ? `${kind} в ${area}` : kind;
17
32
  }
18
33
  function buildContent(incident) {
19
- const parts = [incident.name, "", formatDate(incident.fromDate), incident.addresses];
20
- if (incident.untilDate) {
21
- parts.push("", `Очаквано възстановяване на ${formatDate(incident.untilDate)}`);
34
+ const title = incidentTitle(incident);
35
+ const start = providerDate(incident.fromDate);
36
+ const end = providerDate(incident.untilDate);
37
+ const timespanStart = start ?? new Date();
38
+ const timespanEnd = end ?? timespanStart;
39
+ const summary = [`${title}.`];
40
+ const details = [];
41
+ const markdownDates = [];
42
+ if (start) {
43
+ const startTime = formatDate(start);
44
+ details.push(`Начало: ${startTime}`);
45
+ markdownDates.push(`**Начало:** ${startTime}`);
46
+ }
47
+ if (end) {
48
+ const endTime = formatDate(end);
49
+ summary.push(`Очаквано възстановяване на ${endTime}.`);
50
+ markdownDates.push(`**Очаквано възстановяване:** ${endTime}`);
51
+ }
52
+ const addresses = incident.addresses.replaceAll(/\r\n?/g, "\n").trim();
53
+ const markdown = [`**${title}**`, markdownDates.join(" \n")];
54
+ if (addresses) {
55
+ details.push(addresses);
56
+ markdown.push(addresses.replaceAll("\n", " \n"));
22
57
  }
23
- const message = parts.join("\n");
24
- const timespanStart = timespanDate(incident.fromDate, new Date());
25
- const timespanEnd = timespanDate(incident.untilDate, timespanStart);
26
58
  return {
27
- title: incident.name,
28
- message,
29
- markdownText: message,
59
+ title,
60
+ message: [summary.join(" "), details.join("\n")].filter(Boolean).join("\n\n"),
61
+ markdownText: markdown.filter(Boolean).join("\n\n"),
30
62
  datePublished: incident.fromDate,
31
63
  timespanStart: timespanStart.toISOString(),
32
64
  timespanEnd: timespanEnd.toISOString(),
@@ -2,6 +2,7 @@ import type { JsonValue } from "@oboapp/source-sdk";
2
2
  import { type ToploWarning } from "./geometry.js";
3
3
  export interface ToploIncident {
4
4
  identifier: string;
5
+ type: number | undefined;
5
6
  name: string;
6
7
  addresses: string;
7
8
  fromDate: string;
@@ -32,6 +32,7 @@ function parseIncidents(html, warn = (message) => globalThis.console.warn(messag
32
32
  }
33
33
  incidents.push({
34
34
  identifier: `https://toplo.bg/incidents/${info.ContentItemId}`,
35
+ type: "Type" in info && typeof info.Type === "number" ? info.Type : undefined,
35
36
  name: info.Name,
36
37
  addresses: info.Addresses,
37
38
  fromDate: info.FromDate,
@@ -1,29 +1,61 @@
1
1
  const MINIMUM_DATE = Date.UTC(2025, 0, 1);
2
+ // Toplo labels its published local clock times with Z. UTC formatting preserves the clock shown on its site.
3
+ const displayDate = new Intl.DateTimeFormat("bg-BG", { dateStyle: "long", timeZone: "UTC" });
4
+ const displayTime = new Intl.DateTimeFormat("bg-BG", { hour: "2-digit", minute: "2-digit", timeZone: "UTC" });
5
+ function incidentTypeLabel(type) {
6
+ switch (type) {
7
+ case 0:
8
+ return "Авария";
9
+ case 1:
10
+ return "Ремонт";
11
+ default:
12
+ return "Прекъсване";
13
+ }
14
+ }
2
15
  function formatDate(value) {
3
- return new Date(value).toLocaleString("bg-BG", {
4
- year: "numeric",
5
- month: "long",
6
- day: "numeric",
7
- hour: "2-digit",
8
- minute: "2-digit",
9
- });
16
+ return `${displayDate.format(value)}, ${displayTime.format(value)}`;
17
+ }
18
+ function providerDate(value) {
19
+ if (!value) {
20
+ return undefined;
21
+ }
22
+ const date = new Date(value);
23
+ return date.getTime() >= MINIMUM_DATE ? date : undefined;
10
24
  }
11
- function timespanDate(value, fallback) {
12
- const parsed = value ? new Date(value) : fallback;
13
- return parsed.getTime() >= MINIMUM_DATE ? parsed : fallback;
25
+ function incidentTitle(incident) {
26
+ const area = incident.name.trim();
27
+ const kind = incidentTypeLabel(incident.type);
28
+ return area && area !== kind ? `${kind} в ${area}` : kind;
14
29
  }
15
30
  export function buildContent(incident) {
16
- const parts = [incident.name, "", formatDate(incident.fromDate), incident.addresses];
17
- if (incident.untilDate) {
18
- parts.push("", `Очаквано възстановяване на ${formatDate(incident.untilDate)}`);
31
+ const title = incidentTitle(incident);
32
+ const start = providerDate(incident.fromDate);
33
+ const end = providerDate(incident.untilDate);
34
+ const timespanStart = start ?? new Date();
35
+ const timespanEnd = end ?? timespanStart;
36
+ const summary = [`${title}.`];
37
+ const details = [];
38
+ const markdownDates = [];
39
+ if (start) {
40
+ const startTime = formatDate(start);
41
+ details.push(`Начало: ${startTime}`);
42
+ markdownDates.push(`**Начало:** ${startTime}`);
43
+ }
44
+ if (end) {
45
+ const endTime = formatDate(end);
46
+ summary.push(`Очаквано възстановяване на ${endTime}.`);
47
+ markdownDates.push(`**Очаквано възстановяване:** ${endTime}`);
48
+ }
49
+ const addresses = incident.addresses.replaceAll(/\r\n?/g, "\n").trim();
50
+ const markdown = [`**${title}**`, markdownDates.join(" \n")];
51
+ if (addresses) {
52
+ details.push(addresses);
53
+ markdown.push(addresses.replaceAll("\n", " \n"));
19
54
  }
20
- const message = parts.join("\n");
21
- const timespanStart = timespanDate(incident.fromDate, new Date());
22
- const timespanEnd = timespanDate(incident.untilDate, timespanStart);
23
55
  return {
24
- title: incident.name,
25
- message,
26
- markdownText: message,
56
+ title,
57
+ message: [summary.join(" "), details.join("\n")].filter(Boolean).join("\n\n"),
58
+ markdownText: markdown.filter(Boolean).join("\n\n"),
27
59
  datePublished: incident.fromDate,
28
60
  timespanStart: timespanStart.toISOString(),
29
61
  timespanEnd: timespanEnd.toISOString(),
@@ -2,6 +2,7 @@ import type { JsonValue } from "@oboapp/source-sdk";
2
2
  import { type ToploWarning } from "./geometry.js";
3
3
  export interface ToploIncident {
4
4
  identifier: string;
5
+ type: number | undefined;
5
6
  name: string;
6
7
  addresses: string;
7
8
  fromDate: string;
@@ -29,6 +29,7 @@ export function parseIncidents(html, warn = (message) => globalThis.console.warn
29
29
  }
30
30
  incidents.push({
31
31
  identifier: `https://toplo.bg/incidents/${info.ContentItemId}`,
32
+ type: "Type" in info && typeof info.Type === "number" ? info.Type : undefined,
32
33
  name: info.Name,
33
34
  addresses: info.Addresses,
34
35
  fromDate: info.FromDate,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oboapp/source-toplo-bg",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Listing-only heating incidents from Toplofikatsia Sofia",
5
5
  "license": "Unlicense",
6
6
  "type": "module",