@miso.ai/server-feed 0.6.3-beta.2

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/cli/index.js ADDED
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env node
2
+ import { yargs, stream } from '@miso.ai/server-commons';
3
+ import version from '../src/version.js';
4
+ import { stream as createFeedStream } from '../src/index.js';
5
+
6
+ yargs.build(yargs => {
7
+ yargs
8
+ .env('MISO_FEED')
9
+ .option('url', {
10
+ type: 'string',
11
+ })
12
+ .option('auth', {
13
+ alias: 'u',
14
+ type: 'string',
15
+ })
16
+ .option('debug', {
17
+ type: 'boolean',
18
+ default: false,
19
+ })
20
+ .hide('debug')
21
+ .command({
22
+ command: '* [url]',
23
+ description: 'Read items from feed',
24
+ handler: run,
25
+ })
26
+ .version(version);
27
+ });
28
+
29
+ async function run({ url, auth } = {}) {
30
+ await stream.pipeline(
31
+ await createFeedStream(url, { fetch: { auth } }),
32
+ new stream.OutputStream(),
33
+ );
34
+ }
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@miso.ai/server-feed",
3
+ "description": "Miso RSS/Atom feed data tools",
4
+ "type": "module",
5
+ "main": "src/index.js",
6
+ "bin": {
7
+ "miso-feed": "cli/index.js"
8
+ },
9
+ "publishConfig": {
10
+ "access": "public"
11
+ },
12
+ "scripts": {},
13
+ "repository": "MisoAI/miso-server-js-sdk",
14
+ "license": "MIT",
15
+ "contributors": [
16
+ "simonpai <simon.pai@askmiso.com>"
17
+ ],
18
+ "dependencies": {
19
+ "@miso.ai/server-commons": "0.6.3-beta.2",
20
+ "feedparser": "^2.2.10",
21
+ "node-fetch": "^3.3.2"
22
+ },
23
+ "version": "0.6.3-beta.2"
24
+ }
package/src/index.js ADDED
@@ -0,0 +1 @@
1
+ export { default as stream } from './stream.js';
package/src/stream.js ADDED
@@ -0,0 +1,28 @@
1
+ import { Buffer } from 'buffer';
2
+ import fetch, { Headers } from 'node-fetch';
3
+ import FeedParser from 'feedparser';
4
+
5
+ export default async function stream(url, { fetch: fetchOptions, parse: parseOptions } = {}) {
6
+ const { status, body } = await fetch(url, buildFetchOptions(fetchOptions));
7
+ if (status !== 200) {
8
+ throw new Error(`Failed to fetch ${url}: ${status}`);
9
+ }
10
+ return body.pipe(new FeedParser(parseOptions));
11
+ }
12
+
13
+ function buildFetchOptions({ headers, auth, ...options } = {}) {
14
+ headers = new Headers(headers);
15
+ if (auth) {
16
+ if (typeof auth === 'object' && auth.username && auth.password) {
17
+ auth = `${auth.username}:${auth.password}`;
18
+ }
19
+ if (typeof auth !== 'string') {
20
+ throw new TypeError(`Invalid auth: must me a string or an object.`);
21
+ }
22
+ headers.set('Authorization', 'Basic ' + Buffer.from(auth).toString('base64'));
23
+ }
24
+ return {
25
+ ...options,
26
+ headers,
27
+ };
28
+ }
package/src/version.js ADDED
@@ -0,0 +1 @@
1
+ export default '0.6.3-beta.2';