@dudgy/podcast-widget 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.
@@ -0,0 +1,65 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }// src/podcast-index/auth.ts
2
+ var _crypto = require('crypto'); var _crypto2 = _interopRequireDefault(_crypto);
3
+ function createPodcastIndexHeaders(apiKey, apiSecret) {
4
+ const authDate = Math.floor(Date.now() / 1e3).toString();
5
+ const dataToHash = apiKey + apiSecret + authDate;
6
+ const hash = _crypto2.default.createHash("sha1").update(dataToHash).digest("hex").toLowerCase();
7
+ return {
8
+ "X-Auth-Key": apiKey,
9
+ "X-Auth-Date": authDate,
10
+ Authorization: hash,
11
+ "User-Agent": "PodcastWidget/1.0"
12
+ };
13
+ }
14
+
15
+ // src/podcast-index/client.ts
16
+ var BASE_URL = "https://api.podcastindex.org/api/1.0";
17
+ var PodcastIndexClient = class {
18
+
19
+
20
+ constructor(apiKey, apiSecret) {
21
+ if (!apiKey || !apiSecret) {
22
+ throw new Error("PodcastIndexClient: missing API credentials");
23
+ }
24
+ this.apiKey = apiKey;
25
+ this.apiSecret = apiSecret;
26
+ }
27
+ headers() {
28
+ return createPodcastIndexHeaders(this.apiKey, this.apiSecret);
29
+ }
30
+ async fetchJson(path) {
31
+ const res = await fetch(`${BASE_URL}${path}`, { headers: this.headers() });
32
+ if (!res.ok) throw new Error(`PodcastIndex API ${res.status}: ${res.statusText}`);
33
+ return res.json();
34
+ }
35
+ /** Get the latest episode(s) for a feed. */
36
+ async getEpisodes(feedId, max = 1) {
37
+ const data = await this.fetchJson(
38
+ `/episodes/byfeedid?id=${encodeURIComponent(feedId)}&max=${max}`
39
+ );
40
+ return _nullishCoalesce(data.items, () => ( []));
41
+ }
42
+ /** Convenience: get the single latest episode, or null if none. */
43
+ async getLatestEpisode(feedId) {
44
+ const eps = await this.getEpisodes(feedId, 1);
45
+ return _nullishCoalesce(eps[0], () => ( null));
46
+ }
47
+ /** Get feed metadata. */
48
+ async getFeedInfo(feedId) {
49
+ const data = await this.fetchJson(
50
+ `/podcasts/byfeedid?id=${encodeURIComponent(feedId)}`
51
+ );
52
+ return data.feed;
53
+ }
54
+ /** Search podcasts by term. */
55
+ async search(query) {
56
+ const data = await this.fetchJson(
57
+ `/search/byterm?q=${encodeURIComponent(query)}`
58
+ );
59
+ return _nullishCoalesce(data.feeds, () => ( []));
60
+ }
61
+ };
62
+
63
+
64
+
65
+ exports.PodcastIndexClient = PodcastIndexClient; exports.createPodcastIndexHeaders = createPodcastIndexHeaders;
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Creates PodcastIndex API auth headers (HMAC-SHA1).
3
+ * Server-only — uses Node's crypto module.
4
+ */
5
+ declare function createPodcastIndexHeaders(apiKey: string, apiSecret: string): Record<string, string>;
6
+
7
+ interface PodcastIndexEpisode {
8
+ id: number;
9
+ title: string;
10
+ description: string;
11
+ enclosureUrl: string;
12
+ datePublished: number;
13
+ duration: number;
14
+ image: string;
15
+ feedId: number;
16
+ }
17
+ interface PodcastIndexFeed {
18
+ id: number;
19
+ title: string;
20
+ description: string;
21
+ author: string;
22
+ artwork: string;
23
+ image: string;
24
+ link: string;
25
+ language: string;
26
+ categories: Record<string, string>;
27
+ episodeCount: number;
28
+ lastUpdateTime: number;
29
+ }
30
+ interface SearchResult {
31
+ id: number;
32
+ title: string;
33
+ author: string;
34
+ url: string;
35
+ artwork: string;
36
+ description: string;
37
+ }
38
+ /**
39
+ * Typed client for the PodcastIndex API. Server-only (uses Node crypto for auth).
40
+ */
41
+ declare class PodcastIndexClient {
42
+ private apiKey;
43
+ private apiSecret;
44
+ constructor(apiKey: string, apiSecret: string);
45
+ private headers;
46
+ private fetchJson;
47
+ /** Get the latest episode(s) for a feed. */
48
+ getEpisodes(feedId: number, max?: number): Promise<PodcastIndexEpisode[]>;
49
+ /** Convenience: get the single latest episode, or null if none. */
50
+ getLatestEpisode(feedId: number): Promise<PodcastIndexEpisode | null>;
51
+ /** Get feed metadata. */
52
+ getFeedInfo(feedId: number): Promise<PodcastIndexFeed>;
53
+ /** Search podcasts by term. */
54
+ search(query: string): Promise<SearchResult[]>;
55
+ }
56
+
57
+ export { PodcastIndexClient, type PodcastIndexEpisode, type PodcastIndexFeed, type SearchResult, createPodcastIndexHeaders };
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Creates PodcastIndex API auth headers (HMAC-SHA1).
3
+ * Server-only — uses Node's crypto module.
4
+ */
5
+ declare function createPodcastIndexHeaders(apiKey: string, apiSecret: string): Record<string, string>;
6
+
7
+ interface PodcastIndexEpisode {
8
+ id: number;
9
+ title: string;
10
+ description: string;
11
+ enclosureUrl: string;
12
+ datePublished: number;
13
+ duration: number;
14
+ image: string;
15
+ feedId: number;
16
+ }
17
+ interface PodcastIndexFeed {
18
+ id: number;
19
+ title: string;
20
+ description: string;
21
+ author: string;
22
+ artwork: string;
23
+ image: string;
24
+ link: string;
25
+ language: string;
26
+ categories: Record<string, string>;
27
+ episodeCount: number;
28
+ lastUpdateTime: number;
29
+ }
30
+ interface SearchResult {
31
+ id: number;
32
+ title: string;
33
+ author: string;
34
+ url: string;
35
+ artwork: string;
36
+ description: string;
37
+ }
38
+ /**
39
+ * Typed client for the PodcastIndex API. Server-only (uses Node crypto for auth).
40
+ */
41
+ declare class PodcastIndexClient {
42
+ private apiKey;
43
+ private apiSecret;
44
+ constructor(apiKey: string, apiSecret: string);
45
+ private headers;
46
+ private fetchJson;
47
+ /** Get the latest episode(s) for a feed. */
48
+ getEpisodes(feedId: number, max?: number): Promise<PodcastIndexEpisode[]>;
49
+ /** Convenience: get the single latest episode, or null if none. */
50
+ getLatestEpisode(feedId: number): Promise<PodcastIndexEpisode | null>;
51
+ /** Get feed metadata. */
52
+ getFeedInfo(feedId: number): Promise<PodcastIndexFeed>;
53
+ /** Search podcasts by term. */
54
+ search(query: string): Promise<SearchResult[]>;
55
+ }
56
+
57
+ export { PodcastIndexClient, type PodcastIndexEpisode, type PodcastIndexFeed, type SearchResult, createPodcastIndexHeaders };
@@ -0,0 +1,65 @@
1
+ // src/podcast-index/auth.ts
2
+ import crypto from "crypto";
3
+ function createPodcastIndexHeaders(apiKey, apiSecret) {
4
+ const authDate = Math.floor(Date.now() / 1e3).toString();
5
+ const dataToHash = apiKey + apiSecret + authDate;
6
+ const hash = crypto.createHash("sha1").update(dataToHash).digest("hex").toLowerCase();
7
+ return {
8
+ "X-Auth-Key": apiKey,
9
+ "X-Auth-Date": authDate,
10
+ Authorization: hash,
11
+ "User-Agent": "PodcastWidget/1.0"
12
+ };
13
+ }
14
+
15
+ // src/podcast-index/client.ts
16
+ var BASE_URL = "https://api.podcastindex.org/api/1.0";
17
+ var PodcastIndexClient = class {
18
+ apiKey;
19
+ apiSecret;
20
+ constructor(apiKey, apiSecret) {
21
+ if (!apiKey || !apiSecret) {
22
+ throw new Error("PodcastIndexClient: missing API credentials");
23
+ }
24
+ this.apiKey = apiKey;
25
+ this.apiSecret = apiSecret;
26
+ }
27
+ headers() {
28
+ return createPodcastIndexHeaders(this.apiKey, this.apiSecret);
29
+ }
30
+ async fetchJson(path) {
31
+ const res = await fetch(`${BASE_URL}${path}`, { headers: this.headers() });
32
+ if (!res.ok) throw new Error(`PodcastIndex API ${res.status}: ${res.statusText}`);
33
+ return res.json();
34
+ }
35
+ /** Get the latest episode(s) for a feed. */
36
+ async getEpisodes(feedId, max = 1) {
37
+ const data = await this.fetchJson(
38
+ `/episodes/byfeedid?id=${encodeURIComponent(feedId)}&max=${max}`
39
+ );
40
+ return data.items ?? [];
41
+ }
42
+ /** Convenience: get the single latest episode, or null if none. */
43
+ async getLatestEpisode(feedId) {
44
+ const eps = await this.getEpisodes(feedId, 1);
45
+ return eps[0] ?? null;
46
+ }
47
+ /** Get feed metadata. */
48
+ async getFeedInfo(feedId) {
49
+ const data = await this.fetchJson(
50
+ `/podcasts/byfeedid?id=${encodeURIComponent(feedId)}`
51
+ );
52
+ return data.feed;
53
+ }
54
+ /** Search podcasts by term. */
55
+ async search(query) {
56
+ const data = await this.fetchJson(
57
+ `/search/byterm?q=${encodeURIComponent(query)}`
58
+ );
59
+ return data.feeds ?? [];
60
+ }
61
+ };
62
+ export {
63
+ PodcastIndexClient,
64
+ createPodcastIndexHeaders
65
+ };