Skip to content

Commit 51395c3

Browse files
Release/patch (#22)
* feat: updated getSubstackFeedByLink method signature now returns raw XML string when no callback is passed * 1.0.3 * fix: updated declaration file * 1.0.4 * fix: updated declaration * 1.0.5 * fix: updated parsing for non browser calls - updated non browser calls - added jest config and test * 1.0.6 * fix: updated parsing for non browser calls * 1.0.7 * fix: determine client or server call * 1.0.8 * chore: fixed error in package.json * 1.0.9 * chore: fixed build issues * 1.0.10 * fix: fixed issues with client and server fetching * 1.0.11 * chore: removed .tgz * 1.0.12 * Pre-version bump changes * 1.0.13 * chore: cleanup removed logs * 1.0.14 * chore: updated types * 1.1.1 * chore: added property to goodreads feed added book_large_image_url to goodreads feed * 1.1.2 * fix: updated proxy * 1.1.3 * 1.1.3 * feat: udpated proxy - updated proxy - updated libs * 1.1.4 --------- Co-authored-by: GitHub Actions <actions@github.com>
1 parent 6563450 commit 51395c3

6 files changed

Lines changed: 1312 additions & 809 deletions

File tree

jest.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// eslint-disable-next-line @typescript-eslint/no-require-imports
12
require("tsconfig-paths/register");
23

34
// jest.config.js

lib/goodreads/goodreads.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,14 @@ const getRawXMLGoodreadsFeed = async (feedUrl: string) => {
4141
: feedUrl;
4242
const promise = await fetch(path);
4343
if (promise.ok) return isBrowser ? promise.json() : promise.text();
44-
} catch (e) {
45-
throw new Error("Error occurred fetching Feed from Goodreads");
44+
} catch (error) {
45+
throw new Error("Error occurred fetching Feed from Goodreads", error);
4646
}
4747
};
4848

4949
// Goodreads Public API
5050
export const getGoodreadsFeed = async (
5151
feedUrl: string,
52-
/* eslint-disable @typescript-eslint/no-explicit-any */
5352
callback?: (err: Error | null, result: unknown) => void,
5453
): Promise<unknown> => {
5554
const rawXML = await getRawXMLGoodreadsFeed(feedUrl);

lib/goodreads/types.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@ export type RawGoodreadsFeed = {
77

88
export type RawGoodreadsFeedRSS = {
99
channel: RawGoodreadsFeedChannel[];
10-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1110
[key: string]: unknown;
1211
};
1312

1413
export type RawGoodreadsFeedChannel = {
1514
title: string[];
1615
item: RawGoodreadsItem[];
17-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1816
[key: string]: unknown;
1917
};
2018

@@ -24,14 +22,12 @@ export type RawGoodreadsItem = {
2422
book_image_url: string[];
2523
author_name: string[];
2624
book_description: string[];
27-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2825
[key: string]: unknown;
2926
};
3027

3128
export type GoodreadsFeedChannel = {
3229
title: string;
3330
item: GoodreadsItem[];
34-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
3531
[key: string]: unknown;
3632
};
3733

@@ -41,6 +37,5 @@ export type GoodreadsItem = {
4137
book_image_url: string;
4238
author_name: string;
4339
book_description: string;
44-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4540
[key: string]: unknown;
4641
};

lib/main.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
SubstackItem,
1818
} from "./types";
1919

20-
const CORS_PROXY = "https://www.whateverorigin.org/get?url=";
20+
const CORS_PROXY = "https://lol-origin-84f24d4beb26.herokuapp.com/get?url=";
2121
const isBrowser = typeof document !== "undefined";
2222

2323
// Internal API
@@ -29,7 +29,8 @@ const getRawXMLSubstackFeed = async (feedUrl: string) => {
2929
: feedUrl;
3030
const promise = await fetch(path);
3131
if (promise.ok) return isBrowser ? promise.json() : promise.text();
32-
} catch (e) {
32+
} catch (error) {
33+
console.error(error);
3334
throw new Error("Error occurred fetching Feed from Substack");
3435
}
3536
};
@@ -56,7 +57,6 @@ const transformRawItem = (item: RawItem): SubstackItem => {
5657

5758
export const getSubstackFeed = async (
5859
feedUrl: string,
59-
/* eslint-disable @typescript-eslint/no-explicit-any */
6060
callback?: (err: Error | null, result: unknown) => void,
6161
): Promise<unknown> => {
6262
const rawXML = await getRawXMLSubstackFeed(feedUrl);
@@ -78,8 +78,10 @@ export const getFeedByLink = (
7878
return rawFeed.rss.channel
7979
.filter(isRawFeedChannel)
8080
.filter((channel) => channel.link[0] === link);
81-
} catch (e) {
82-
throw new Error(`Error occurred fetching Feed by Link: ${link}`);
81+
} catch (e: unknown) {
82+
const error = new Error(`Error occurred fetching Feed by Link: ${link}`);
83+
(error as any).cause = e;
84+
throw error;
8385
}
8486
};
8587
export const getPosts = (channels: RawFeedChannel[]) => {
@@ -108,15 +110,15 @@ const getRawXMLGoodreadsFeed = async (feedUrl: string, proxy?: string) => {
108110
: feedUrl;
109111
const promise = await fetch(path);
110112
if (promise.ok) return isBrowser ? promise.json() : promise.text();
111-
} catch (e) {
113+
} catch (error) {
114+
console.error(error);
112115
throw new Error("Error occurred fetching Feed from Goodreads");
113116
}
114117
};
115118

116119
// Public API
117120
export const getGoodreadsFeed = async (
118121
feedUrl: string,
119-
/* eslint-disable @typescript-eslint/no-explicit-any */
120122
callback?: (err: Error | null, result: unknown) => void,
121123
proxy?: string,
122124
): Promise<unknown> => {

0 commit comments

Comments
 (0)