@sockethub/platform-feeds 4.0.0-alpha.10 → 4.0.0-alpha.12

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sockethub/platform-feeds",
3
3
  "description": "A sockethub platform module implementing RSS/Atom functionality",
4
- "version": "4.0.0-alpha.10",
4
+ "version": "4.0.0-alpha.12",
5
5
  "type": "module",
6
6
  "private": false,
7
7
  "author": "Nick Jennings <nick@silverbucket.net>",
@@ -43,7 +43,8 @@
43
43
  "homepage": "https://github.com/sockethub/sockethub/tree/master/packages/platform-feeds",
44
44
  "scripts": {
45
45
  "build": "bun build src/index.ts --outdir dist --target node --format esm --sourcemap=external",
46
- "clean": "rm -rf dist"
46
+ "clean": "rm -rf dist",
47
+ "clean:deps": "rm -rf node_modules"
47
48
  },
48
49
  "dependencies": {
49
50
  "html-tags": "^3.3.1",
@@ -51,17 +52,16 @@
51
52
  "podparse": "^1.6.0"
52
53
  },
53
54
  "devDependencies": {
54
- "@sockethub/schemas": "^3.0.0-alpha.10",
55
- "@types/bun": "latest",
56
- "debug": "^4.4.3"
55
+ "@sockethub/schemas": "^3.0.0-alpha.12",
56
+ "@types/bun": "latest"
57
57
  },
58
58
  "peerDependencies": {
59
- "@sockethub/server": "5.0.0-alpha.10"
59
+ "@sockethub/server": "5.0.0-alpha.12"
60
60
  },
61
61
  "peerDependenciesMeta": {
62
62
  "@sockethub/server": {
63
63
  "optional": true
64
64
  }
65
65
  },
66
- "gitHead": "8e1abf116b2a6b57d33c6e1a4af9143870517bae"
66
+ "gitHead": "f039dab3c3f67cbbf204476fc397532e973f82a8"
67
67
  }
package/src/index.test.ts CHANGED
@@ -2,13 +2,17 @@ import { beforeEach, describe, expect, it } from "bun:test";
2
2
  import { RSSFeed} from "./index.test.data";
3
3
  import Feeds from "./index";
4
4
  import { ASCollection, PlatformSession } from "@sockethub/schemas";
5
- import debug from "debug";
6
5
 
7
6
  describe("platform-feeds", () => {
8
7
  let platform;
9
8
  beforeEach(() => {
10
9
  platform = new Feeds({
11
- debug: debug("sockethub:platform:feeds")
10
+ log: {
11
+ error: () => {},
12
+ warn: () => {},
13
+ info: () => {},
14
+ debug: () => {},
15
+ }
12
16
  } as unknown as PlatformSession);
13
17
 
14
18
  platform.makeRequest = (
@@ -120,14 +124,14 @@ describe("platform-feeds", () => {
120
124
  expect(err).toBeNull();
121
125
 
122
126
  // Validate required ASCollection properties
123
- expect(results).toHaveProperty("context");
127
+ expect(results).toHaveProperty("@context");
124
128
  expect(results).toHaveProperty("type", "collection");
125
129
  expect(results).toHaveProperty("summary");
126
130
  expect(results).toHaveProperty("totalItems");
127
131
  expect(results).toHaveProperty("items");
128
132
 
129
133
  // Validate types
130
- expect(typeof results.context).toBe("string");
134
+ expect(Array.isArray(results["@context"])).toBe(true);
131
135
  expect(typeof results.summary).toBe("string");
132
136
  expect(typeof results.totalItems).toBe("number");
133
137
  expect(Array.isArray(results.items)).toBe(true);
package/src/index.ts CHANGED
@@ -16,9 +16,6 @@
16
16
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
17
  */
18
18
 
19
- import htmlTags from "html-tags";
20
- import getPodcastFromFeed, { type Episode, type Meta } from "podparse";
21
-
22
19
  import type {
23
20
  ActivityStream,
24
21
  Logger,
@@ -28,6 +25,9 @@ import type {
28
25
  PlatformSchemaStruct,
29
26
  PlatformSession,
30
27
  } from "@sockethub/schemas";
28
+ import { buildCanonicalContext } from "@sockethub/schemas";
29
+ import htmlTags from "html-tags";
30
+ import getPodcastFromFeed, { type Episode, type Meta } from "podparse";
31
31
 
32
32
  import PlatformSchema from "./schema.js";
33
33
  import {
@@ -39,6 +39,7 @@ import {
39
39
  } from "./types.js";
40
40
 
41
41
  const MAX_NOTE_LENGTH = 256;
42
+ const FEEDS_CONTEXT = buildCanonicalContext(PlatformSchema.contextUrl);
42
43
 
43
44
  const basic = /\s?<!doctype html>|(<html\b[^>]*>|<body\b[^>]*>|<x-[^>]+>)+/i;
44
45
  const full = new RegExp(
@@ -70,7 +71,7 @@ function isHtml(s: string): boolean {
70
71
  */
71
72
  export default class Feeds implements PlatformInterface {
72
73
  id: string;
73
- debug: Logger;
74
+ private readonly log: Logger;
74
75
  config: PlatformConfig = {
75
76
  persist: false,
76
77
  connectTimeoutMs: 5000,
@@ -81,13 +82,20 @@ export default class Feeds implements PlatformInterface {
81
82
  * @param session - a unique session object for this platform instance
82
83
  */
83
84
  constructor(session: PlatformSession) {
84
- this.debug = session.debug;
85
+ this.log = session.log;
85
86
  }
86
87
 
87
88
  get schema(): PlatformSchemaStruct {
88
89
  return PlatformSchema;
89
90
  }
90
91
 
92
+ /**
93
+ * Stateless platforms are always ready to handle jobs.
94
+ */
95
+ isInitialized(): boolean {
96
+ return true;
97
+ }
98
+
91
99
  /**
92
100
  * Fetch feeds from specified source. Upon completion, it will send back a
93
101
  * response to the original request with a complete ActivityStreams Collection
@@ -99,7 +107,7 @@ export default class Feeds implements PlatformInterface {
99
107
  * @example
100
108
  * Request:
101
109
  * {
102
- * context: "feeds",
110
+ * "@context": ["https://www.w3.org/ns/activitystreams", "https://sockethub.org/ns/context/v1.jsonld", "https://sockethub.org/ns/context/platform/feeds/v1.jsonld"],
103
111
  * type: "fetch",
104
112
  * actor: {
105
113
  * id: 'http://blog.example.com/rss',
@@ -169,7 +177,7 @@ export default class Feeds implements PlatformInterface {
169
177
  .then((results) => {
170
178
  return done(null, {
171
179
  id: job.id || null,
172
- context: "feeds",
180
+ "@context": FEEDS_CONTEXT,
173
181
  type: "collection",
174
182
  summary:
175
183
  results.length > 0 && results[0]?.actor?.name
@@ -193,9 +201,7 @@ export default class Feeds implements PlatformInterface {
193
201
  }
194
202
 
195
203
  private async makeRequest(url: string): Promise<string> {
196
- const opts = {
197
- signal: undefined,
198
- };
204
+ const opts: RequestInit = {};
199
205
  if (this.config.connectTimeoutMs) {
200
206
  opts.signal = AbortSignal.timeout(this.config.connectTimeoutMs);
201
207
  }
@@ -209,7 +215,7 @@ export default class Feeds implements PlatformInterface {
209
215
  url: string,
210
216
  id: string,
211
217
  ): Promise<Array<PlatformFeedsActivityStream>> {
212
- this.debug(`fetching ${url}`);
218
+ this.log.debug(`fetching ${url}`);
213
219
  const res = await this.makeRequest(url);
214
220
  const feed = getPodcastFromFeed(res);
215
221
  const actor = buildFeedChannel(url, feed.meta);
@@ -221,7 +227,7 @@ export default class Feeds implements PlatformInterface {
221
227
  article.object = buildFeedItem(item as FeedItem);
222
228
  articles.push(article);
223
229
  }
224
- this.debug(`fetched ${articles.length} articles`);
230
+ this.log.debug(`fetched ${articles.length} articles`);
225
231
  return articles;
226
232
  }
227
233
  }
@@ -260,7 +266,7 @@ function buildFeedStruct(
260
266
  actor: PlatformFeedsActivityActor,
261
267
  ): PlatformFeedsActivityStream {
262
268
  return {
263
- context: ASFeedType.FEEDS,
269
+ "@context": FEEDS_CONTEXT,
264
270
  actor: actor,
265
271
  type: "post",
266
272
  };
package/src/schema.ts CHANGED
@@ -3,6 +3,9 @@ import packageJSON from "../package.json" with { type: "json" };
3
3
  export default {
4
4
  name: "feeds",
5
5
  version: packageJSON.version,
6
+ contextUrl: "https://sockethub.org/ns/context/platform/feeds/v1.jsonld",
7
+ contextVersion: "1",
8
+ schemaVersion: "1",
6
9
  messages: {
7
10
  required: ["type"],
8
11
  properties: {
@@ -18,5 +21,17 @@ export default {
18
21
  ],
19
22
  },
20
23
  },
24
+ definitions: {
25
+ objectTypes: {
26
+ "feed-parameters-date": {
27
+ type: "object",
28
+ additionalProperties: true,
29
+ },
30
+ "feed-parameters-url": {
31
+ type: "object",
32
+ additionalProperties: true,
33
+ },
34
+ },
35
+ },
21
36
  },
22
37
  };
package/src/types.ts CHANGED
@@ -1,10 +1,9 @@
1
- import type { Author } from "podparse";
2
-
3
1
  import type {
4
2
  ActivityActor,
5
3
  ActivityObject,
6
4
  ActivityStream,
7
5
  } from "@sockethub/schemas";
6
+ import type { Author } from "podparse";
8
7
 
9
8
  export enum ASFeedType {
10
9
  FEED_CHANNEL = "feed",
@@ -30,7 +29,7 @@ export interface PlatformFeedsActivityActor extends ActivityActor {
30
29
 
31
30
  export interface PlatformFeedsActivityStream extends ActivityStream {
32
31
  id?: string;
33
- context: ASFeedType.FEEDS;
32
+ "@context": Array<string>;
34
33
  actor: PlatformFeedsActivityActor;
35
34
  type: string;
36
35
  object?: PlatformFeedsActivityObject;