@oboapp/source-sredec-sofia-org 0.0.0-stage → 0.1.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/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0
4
+
5
+ - Extract Sredets discovery and article collection into a database-free source package.
6
+ - Preserve all five category feeds, pagination safeguards, historical URL spelling, publication dates, content selectors, and request delays.
7
+ - Provide isolated catalog metadata and ESM/CommonJS entrypoints through the source SDK.
package/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ This is free and unencumbered software released into the public domain.
2
+
3
+ Anyone is free to copy, modify, publish, use, compile, sell, or
4
+ distribute this software, either in source code form or as a compiled
5
+ binary, for any purpose, commercial or non-commercial, and by any
6
+ means.
7
+
8
+ In jurisdictions that recognize copyright laws, the author or authors
9
+ of this software dedicate any and all copyright interest in the
10
+ software to the public domain. We make this dedication for the benefit
11
+ of the public at large and to the detriment of our heirs and
12
+ successors. We intend this dedication to be an overt act of
13
+ relinquishment in perpetuity of all present and future rights to this
14
+ software under copyright law.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ For more information, please refer to <https://unlicense.org>
package/README.md CHANGED
@@ -1,3 +1,39 @@
1
- # Temporary Holding Version
1
+ # Sredets source
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ `@oboapp/source-sredec-sofia-org` collects public notices from Sofia district Sredets. Its persisted source ID is `sredec-sofia-org`, with locality `bg.sofia`.
4
+
5
+ ## Install and use
6
+
7
+ Use Node.js 20.3 or later and install the package with `pnpm add @oboapp/source-sredec-sofia-org`. Article collection uses Playwright Chromium. Install the browser revision required by `@oboapp/source-web-utils` and its operating-system dependencies in the runtime image.
8
+
9
+ ```ts
10
+ import { createSource } from "@oboapp/source-sredec-sofia-org";
11
+ import { metadata } from "@oboapp/source-sredec-sofia-org/metadata";
12
+
13
+ const source = await createSource({ locality: "bg.sofia" });
14
+ try {
15
+ const page = await source.discoverItems();
16
+ for (const item of page.items) {
17
+ const content = await source.fetchItem(item);
18
+ console.log(metadata.id, item.identifier, content);
19
+ }
20
+ } finally {
21
+ await source.close?.();
22
+ }
23
+ ```
24
+
25
+ The `/metadata` entrypoint is safe for browser catalogs and does not load collection code. Obo owns scheduling, historical-record lookup, validation, persistence, and ingestion.
26
+
27
+ ## Discovery and coverage
28
+
29
+ Discovery reads five category feeds: useful information, news, announcements, investment notices, and public discussions. It follows `?paged=` links within each category and returns one complete discovery page. URLs keep the legacy parser's spelling, including percent encoding and query strings. Cross-category duplicates retain the metadata from the first configured feed that listed them.
30
+
31
+ The scan covers items newer than midnight UTC minus 90 days, using the same strict age boundary as the existing collector. It waits two seconds before each feed request and stops a feed at an empty page, a later-page HTTP 404, or a page containing older items. A missing first page, a repeated page, another provider failure, or more than 100 pages makes discovery fail. The next scheduled scan lists again from the beginning.
32
+
33
+ Article content is fetched in a reused browser. The page title is preferred, with the feed title as fallback; the publication date always comes from RSS. Scripts and styles are removed, and content is converted to Markdown. A successful article request is followed by a two-second delay. Each opened article page is closed after success or failure, and `close()` releases the shared browser.
34
+
35
+ Feed history and provider removals limit available notices to the current 90-day window. Article output retains document links for ingestion. Obo skips known identifiers, including after package updates, and historical identifiers remain unchanged across versions.
36
+
37
+ ## Checks and releases
38
+
39
+ Run `pnpm check` from the sources repository root. Tests cover captured category feeds, pagination and age boundaries, exact identifiers and content, browser cleanup, and ESM/CommonJS entrypoints. See [RELEASING.md](../../RELEASING.md) for package inspection and independent SemVer releases. Obo's migration is tracked in [#586](https://github.com/oboapp/oboapp/issues/586) and [#609](https://github.com/oboapp/oboapp/issues/609).
@@ -0,0 +1,10 @@
1
+ import { fetchFeedXml, type RssFeedItem } from "@oboapp/source-web-utils/rss";
2
+ export declare const FEED_URLS: string[];
3
+ export interface DiscoveryDependencies {
4
+ fetchFeed: typeof fetchFeedXml;
5
+ delay: (milliseconds: number) => Promise<void>;
6
+ now: () => Date;
7
+ }
8
+ export declare function extractFeedItems(xml: string): RssFeedItem[];
9
+ /** Read the complete listing before returning candidates to the platform. */
10
+ export declare function discoverRecentItems(overrides?: Partial<DiscoveryDependencies>): Promise<RssFeedItem[]>;
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FEED_URLS = void 0;
4
+ exports.extractFeedItems = extractFeedItems;
5
+ exports.discoverRecentItems = discoverRecentItems;
6
+ const rss_1 = require("@oboapp/source-web-utils/rss");
7
+ exports.FEED_URLS = [
8
+ "публикации/полезна-информация",
9
+ "новини",
10
+ "публикации/saobshtenia",
11
+ "публикации/инвестиционни-намерения",
12
+ "обществениобсъждания",
13
+ ].map((category) => `https://sredec-sofia.org/category/${category}/feed/`);
14
+ const MAX_PAGES_PER_FEED = 100;
15
+ const REQUEST_DELAY_MS = 2000;
16
+ const MAX_AGE_MS = 90 * 24 * 60 * 60 * 1000;
17
+ const defaults = {
18
+ fetchFeed: rss_1.fetchFeedXml,
19
+ delay: (milliseconds) => new Promise((resolve) => {
20
+ setTimeout(resolve, milliseconds);
21
+ }),
22
+ now: () => new Date(),
23
+ };
24
+ function extractFeedItems(xml) {
25
+ return (0, rss_1.parseRssFeedItems)(xml, { hostname: "sredec-sofia.org" });
26
+ }
27
+ async function readPage(url, page, readFeed) {
28
+ try {
29
+ return extractFeedItems(await readFeed(url));
30
+ }
31
+ catch (error) {
32
+ if (page > 1 && error instanceof rss_1.RssFeedHttpError && error.status === 404) {
33
+ return [];
34
+ }
35
+ throw error;
36
+ }
37
+ }
38
+ async function discoverFeed(feedUrl, cutoff, dependencies) {
39
+ const found = new Map();
40
+ for (let page = 1; page <= MAX_PAGES_PER_FEED; page++) {
41
+ await dependencies.delay(REQUEST_DELAY_MS);
42
+ const url = new URL(feedUrl);
43
+ if (page > 1) {
44
+ url.searchParams.set("paged", String(page));
45
+ }
46
+ const items = await readPage(url.toString(), page, dependencies.fetchFeed);
47
+ if (items.length === 0) {
48
+ return [...found.values()];
49
+ }
50
+ const recent = items.filter((item) => Date.parse(item.date) > cutoff);
51
+ const newItems = recent.filter((item) => !found.has(item.url));
52
+ for (const item of newItems) {
53
+ found.set(item.url, item);
54
+ }
55
+ if (recent.length < items.length) {
56
+ return [...found.values()];
57
+ }
58
+ if (newItems.length === 0) {
59
+ throw new Error(`RSS pagination repeated a page for ${feedUrl}`);
60
+ }
61
+ }
62
+ throw new Error(`RSS pagination exceeded ${MAX_PAGES_PER_FEED} pages for ${feedUrl}`);
63
+ }
64
+ /** Read the complete listing before returning candidates to the platform. */
65
+ async function discoverRecentItems(overrides = {}) {
66
+ const dependencies = { ...defaults, ...overrides };
67
+ const midnight = new Date(dependencies.now());
68
+ midnight.setUTCHours(0, 0, 0, 0);
69
+ const cutoff = midnight.getTime() - MAX_AGE_MS;
70
+ const found = new Map();
71
+ for (const feedUrl of exports.FEED_URLS) {
72
+ const items = await discoverFeed(feedUrl, cutoff, dependencies);
73
+ for (const item of items) {
74
+ if (!found.has(item.url)) {
75
+ found.set(item.url, item);
76
+ }
77
+ }
78
+ }
79
+ return [...found.values()];
80
+ }
@@ -0,0 +1,5 @@
1
+ import type { CreateSource, DataSource } from "@oboapp/source-sdk";
2
+ import { type HybridDependencies } from "@oboapp/source-web-utils";
3
+ import { type DiscoveryDependencies } from "./discovery.js";
4
+ export declare function createSourceWithDependencies(browserDependencies?: HybridDependencies, discoveryDependencies?: Partial<DiscoveryDependencies>): DataSource;
5
+ export declare const createSource: CreateSource;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createSource = void 0;
4
+ exports.createSourceWithDependencies = createSourceWithDependencies;
5
+ const source_web_utils_1 = require("@oboapp/source-web-utils");
6
+ const discovery_js_1 = require("./discovery.js");
7
+ function createSourceWithDependencies(browserDependencies, discoveryDependencies = {}) {
8
+ return (0, source_web_utils_1.createHybridSource)({
9
+ discoverItems: () => (0, discovery_js_1.discoverRecentItems)(discoveryDependencies),
10
+ selectors: {
11
+ TITLE: "h1.single-post-title",
12
+ CONTENT: ".single-blog-content.entry",
13
+ },
14
+ unwantedElements: ["script", "style"],
15
+ }, browserDependencies);
16
+ }
17
+ const createSource = () => createSourceWithDependencies();
18
+ exports.createSource = createSource;
@@ -0,0 +1,2 @@
1
+ import type { SourceMetadata } from "@oboapp/source-sdk/metadata";
2
+ export declare const metadata: SourceMetadata;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.metadata = void 0;
4
+ exports.metadata = {
5
+ id: "sredec-sofia-org",
6
+ url: "https://sredec-sofia.org/",
7
+ name: 'Столична община, Район "Средец"',
8
+ localities: ["bg.sofia"],
9
+ };
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,10 @@
1
+ import { fetchFeedXml, type RssFeedItem } from "@oboapp/source-web-utils/rss";
2
+ export declare const FEED_URLS: string[];
3
+ export interface DiscoveryDependencies {
4
+ fetchFeed: typeof fetchFeedXml;
5
+ delay: (milliseconds: number) => Promise<void>;
6
+ now: () => Date;
7
+ }
8
+ export declare function extractFeedItems(xml: string): RssFeedItem[];
9
+ /** Read the complete listing before returning candidates to the platform. */
10
+ export declare function discoverRecentItems(overrides?: Partial<DiscoveryDependencies>): Promise<RssFeedItem[]>;
@@ -0,0 +1,75 @@
1
+ import { fetchFeedXml, parseRssFeedItems, RssFeedHttpError, } from "@oboapp/source-web-utils/rss";
2
+ export const FEED_URLS = [
3
+ "публикации/полезна-информация",
4
+ "новини",
5
+ "публикации/saobshtenia",
6
+ "публикации/инвестиционни-намерения",
7
+ "обществениобсъждания",
8
+ ].map((category) => `https://sredec-sofia.org/category/${category}/feed/`);
9
+ const MAX_PAGES_PER_FEED = 100;
10
+ const REQUEST_DELAY_MS = 2000;
11
+ const MAX_AGE_MS = 90 * 24 * 60 * 60 * 1000;
12
+ const defaults = {
13
+ fetchFeed: fetchFeedXml,
14
+ delay: (milliseconds) => new Promise((resolve) => {
15
+ setTimeout(resolve, milliseconds);
16
+ }),
17
+ now: () => new Date(),
18
+ };
19
+ export function extractFeedItems(xml) {
20
+ return parseRssFeedItems(xml, { hostname: "sredec-sofia.org" });
21
+ }
22
+ async function readPage(url, page, readFeed) {
23
+ try {
24
+ return extractFeedItems(await readFeed(url));
25
+ }
26
+ catch (error) {
27
+ if (page > 1 && error instanceof RssFeedHttpError && error.status === 404) {
28
+ return [];
29
+ }
30
+ throw error;
31
+ }
32
+ }
33
+ async function discoverFeed(feedUrl, cutoff, dependencies) {
34
+ const found = new Map();
35
+ for (let page = 1; page <= MAX_PAGES_PER_FEED; page++) {
36
+ await dependencies.delay(REQUEST_DELAY_MS);
37
+ const url = new URL(feedUrl);
38
+ if (page > 1) {
39
+ url.searchParams.set("paged", String(page));
40
+ }
41
+ const items = await readPage(url.toString(), page, dependencies.fetchFeed);
42
+ if (items.length === 0) {
43
+ return [...found.values()];
44
+ }
45
+ const recent = items.filter((item) => Date.parse(item.date) > cutoff);
46
+ const newItems = recent.filter((item) => !found.has(item.url));
47
+ for (const item of newItems) {
48
+ found.set(item.url, item);
49
+ }
50
+ if (recent.length < items.length) {
51
+ return [...found.values()];
52
+ }
53
+ if (newItems.length === 0) {
54
+ throw new Error(`RSS pagination repeated a page for ${feedUrl}`);
55
+ }
56
+ }
57
+ throw new Error(`RSS pagination exceeded ${MAX_PAGES_PER_FEED} pages for ${feedUrl}`);
58
+ }
59
+ /** Read the complete listing before returning candidates to the platform. */
60
+ export async function discoverRecentItems(overrides = {}) {
61
+ const dependencies = { ...defaults, ...overrides };
62
+ const midnight = new Date(dependencies.now());
63
+ midnight.setUTCHours(0, 0, 0, 0);
64
+ const cutoff = midnight.getTime() - MAX_AGE_MS;
65
+ const found = new Map();
66
+ for (const feedUrl of FEED_URLS) {
67
+ const items = await discoverFeed(feedUrl, cutoff, dependencies);
68
+ for (const item of items) {
69
+ if (!found.has(item.url)) {
70
+ found.set(item.url, item);
71
+ }
72
+ }
73
+ }
74
+ return [...found.values()];
75
+ }
@@ -0,0 +1,5 @@
1
+ import type { CreateSource, DataSource } from "@oboapp/source-sdk";
2
+ import { type HybridDependencies } from "@oboapp/source-web-utils";
3
+ import { type DiscoveryDependencies } from "./discovery.js";
4
+ export declare function createSourceWithDependencies(browserDependencies?: HybridDependencies, discoveryDependencies?: Partial<DiscoveryDependencies>): DataSource;
5
+ export declare const createSource: CreateSource;
@@ -0,0 +1,13 @@
1
+ import { createHybridSource } from "@oboapp/source-web-utils";
2
+ import { discoverRecentItems } from "./discovery.js";
3
+ export function createSourceWithDependencies(browserDependencies, discoveryDependencies = {}) {
4
+ return createHybridSource({
5
+ discoverItems: () => discoverRecentItems(discoveryDependencies),
6
+ selectors: {
7
+ TITLE: "h1.single-post-title",
8
+ CONTENT: ".single-blog-content.entry",
9
+ },
10
+ unwantedElements: ["script", "style"],
11
+ }, browserDependencies);
12
+ }
13
+ export const createSource = () => createSourceWithDependencies();
@@ -0,0 +1,2 @@
1
+ import type { SourceMetadata } from "@oboapp/source-sdk/metadata";
2
+ export declare const metadata: SourceMetadata;
@@ -0,0 +1,6 @@
1
+ export const metadata = {
2
+ id: "sredec-sofia-org",
3
+ url: "https://sredec-sofia.org/",
4
+ name: 'Столична община, Район "Средец"',
5
+ localities: ["bg.sofia"],
6
+ };
package/package.json CHANGED
@@ -1,6 +1,67 @@
1
1
  {
2
2
  "name": "@oboapp/source-sredec-sofia-org",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Paginated RSS and webpage source for Sofia district Sredets",
5
+ "main": "./dist/cjs/index.js",
6
+ "license": "Unlicense",
7
+ "type": "module",
8
+ "types": "./dist/cjs/index.d.ts",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/oboapp/sources.git",
12
+ "directory": "packages/source-sredec-sofia-org"
13
+ },
14
+ "engines": {
15
+ "node": ">=20.3"
16
+ },
17
+ "publishConfig": {
18
+ "access": "public"
19
+ },
20
+ "files": [
21
+ "dist",
22
+ "LICENSE",
23
+ "README.md",
24
+ "CHANGELOG.md"
25
+ ],
26
+ "sideEffects": false,
27
+ "typesVersions": {
28
+ "*": {
29
+ "metadata": [
30
+ "dist/cjs/metadata.d.ts"
31
+ ]
32
+ }
33
+ },
34
+ "exports": {
35
+ ".": {
36
+ "import": {
37
+ "types": "./dist/esm/index.d.ts",
38
+ "default": "./dist/esm/index.js"
39
+ },
40
+ "require": {
41
+ "types": "./dist/cjs/index.d.ts",
42
+ "default": "./dist/cjs/index.js"
43
+ }
44
+ },
45
+ "./metadata": {
46
+ "import": {
47
+ "types": "./dist/esm/metadata.d.ts",
48
+ "default": "./dist/esm/metadata.js"
49
+ },
50
+ "require": {
51
+ "types": "./dist/cjs/metadata.d.ts",
52
+ "default": "./dist/cjs/metadata.js"
53
+ }
54
+ }
55
+ },
56
+ "dependencies": {
57
+ "@oboapp/source-sdk": "0.1.1",
58
+ "@oboapp/source-web-utils": "0.1.0"
59
+ },
60
+ "devDependencies": {
61
+ "happy-dom": "20.0.11"
62
+ },
63
+ "scripts": {
64
+ "test": "tsc -p test/tsconfig.json && tsx --test test/*.test.ts",
65
+ "build": "tsc -p tsconfig.json && tsc -p tsconfig.cjs.json && node scripts/finalize-build.mjs"
66
+ }
6
67
  }