podcast-api 2.0.3 → 3.0.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/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "podcast-api",
3
- "version": "2.0.3",
3
+ "version": "3.0.0",
4
4
  "description": "JavaScript bindings for the Listen Notes Podcast API",
5
5
  "main": "src/PodcastApiClient.js",
6
6
  "scripts": {
7
7
  "clean": "rm -rf ./.nyc_output ./node_modules/.cache",
8
- "lint": "eslint --ext .js,.jsx .",
8
+ "lint": "eslint .",
9
9
  "test": "jest --config jest.config.node.json && jest --config jest.config.minifare.json",
10
10
  "test-node": "jest --config jest.config.node.json",
11
11
  "test-workers": "jest --config jest.config.minifare.json"
@@ -24,7 +24,7 @@
24
24
  "Node.js"
25
25
  ],
26
26
  "engines": {
27
- "node": ">=10.*"
27
+ "node": ">=22"
28
28
  },
29
29
  "author": "Listen Notes, Inc. <hello@listennotes.com> (https://www.listennotes.com/)",
30
30
  "license": "MIT",
@@ -33,15 +33,14 @@
33
33
  },
34
34
  "homepage": "https://www.listennotes.com/api/",
35
35
  "dependencies": {
36
- "axios": "^0.21.1"
36
+ "axios": "1.19.0"
37
37
  },
38
38
  "devDependencies": {
39
- "eslint": "^7.25.0",
40
- "eslint-plugin-import": "^2.22.1",
41
- "eslint-plugin-jsx-a11y": "^6.4.1",
42
- "jest": "^26.6.3",
43
- "jest-environment-miniflare": "^2.10.0",
44
- "mocha": "^8.3.2",
45
- "prettier": "^2.2.1"
46
- }
39
+ "@eslint/js": "10.0.1",
40
+ "eslint": "10.10.0",
41
+ "jest": "30.5.1",
42
+ "jest-environment-miniflare": "2.14.3",
43
+ "prettier": "3.9.8"
44
+ },
45
+ "packageManager": "yarn@3.3.1"
47
46
  }
@@ -3,24 +3,25 @@ const { addApiMethodsToClient } = require('./PodcastApiMethods');
3
3
 
4
4
  const ClientForNode = (config = {}) => {
5
5
  const axios = require('axios');
6
-
7
- axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
8
- this.httpClient = axios.create({
6
+ const httpClient = axios.create({
9
7
  baseURL: config.apiKey ? API_BASE_PROD : API_BASE_TEST,
10
8
  timeout: 30000,
11
9
  headers: {
12
10
  'X-ListenAPI-Key': config.apiKey || '',
13
11
  'User-Agent': config.userAgent || defaultUserAgent,
14
12
  },
13
+ // Use the same standard encoding as the Workers transport.
14
+ paramsSerializer: (params) => new URLSearchParams(params).toString(),
15
15
  });
16
-
17
- this.httpClient._get = (path, params) => this.httpClient.get(path, { params });
18
- this.httpClient._post = (path, params) => this.httpClient.post(path, new URLSearchParams(params).toString());
19
- this.httpClient._delete = (path) => this.httpClient.delete(path);
20
-
21
- return addApiMethodsToClient(this);
16
+ const formConfig = (params) => ({
17
+ params,
18
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
19
+ });
20
+ httpClient._get = (path, params) => httpClient.get(path, { params });
21
+ httpClient._post = (path, params, query) => httpClient.post(path, new URLSearchParams(params).toString(), formConfig(query));
22
+ httpClient._put = (path, params, query) => httpClient.put(path, new URLSearchParams(params).toString(), formConfig(query));
23
+ httpClient._delete = (path, params) => httpClient.delete(path, { params });
24
+ return addApiMethodsToClient({ httpClient });
22
25
  };
23
26
 
24
- module.exports = {
25
- ClientForNode,
26
- };
27
+ module.exports = { ClientForNode };
@@ -1,85 +1,41 @@
1
- const {API_BASE_PROD, API_BASE_TEST, defaultUserAgent} = require('./Constants');
2
- const {addApiMethodsToClient} = require('./PodcastApiMethods');
1
+ const { API_BASE_PROD, API_BASE_TEST, defaultUserAgent } = require('./Constants');
2
+ const { addApiMethodsToClient } = require('./PodcastApiMethods');
3
3
 
4
- const _fetch = (path, config, method = 'GET', queryParams = {}, formParams = null) => {
4
+ const _fetch = async (path, config, method, queryParams = {}, formParams = null) => {
5
5
  let url = `${config.apiKey ? API_BASE_PROD : API_BASE_TEST}${path}`;
6
6
  const headers = {
7
7
  'X-ListenAPI-Key': config.apiKey || '',
8
8
  'User-Agent': config.userAgent || defaultUserAgent,
9
9
  };
10
- const fetchConfig = {
11
- method,
12
- headers,
13
- };
14
- let formParamsString = null;
15
- if (formParams) {
16
- fetchConfig.body = formParams;
17
- formParamsString = [...formParams.entries()].map(
18
- x => `${encodeURIComponent(x[0])}=${encodeURIComponent(x[1])}`).join('&');
10
+ const query = new URLSearchParams(queryParams).toString();
11
+ if (query) url += `?${query}`;
12
+ const body = formParams === null ? null : new URLSearchParams(formParams).toString();
13
+ const fetchConfig = { method, headers };
14
+ if (body !== null) {
15
+ fetchConfig.body = body;
16
+ headers['Content-Type'] = 'application/x-www-form-urlencoded';
19
17
  }
20
- if (queryParams) {
21
- url = `${url}?${new URLSearchParams(queryParams).toString()}`
18
+ const responseConfig = { params: queryParams, data: body, url: path, method: method.toLowerCase() };
19
+ const response = await fetch(url, fetchConfig);
20
+ const responseHeaders = Object.fromEntries(response.headers.entries());
21
+ if (!response.ok) {
22
+ const error = new Error(`HTTP ${response.status}`);
23
+ error.response = { status: response.status, config: responseConfig, headers: responseHeaders };
24
+ throw error;
22
25
  }
23
- const responseConfig = {
24
- params: queryParams,
25
- data: formParamsString,
26
- url: path,
27
- method: method.toLowerCase(),
28
- };
29
- const responseHeaders = {};
30
- return fetch(url, fetchConfig).then((response) => {
31
- if (response.headers) {
32
- for (const pair of response.headers.entries()) {
33
- responseHeaders[pair[0]] = pair[1];
34
- }
35
- }
36
-
37
- if (response.ok) {
38
- return response;
39
- } else {
40
- const err = new Error(`HTTP ${response.status}`);
41
- err.response = {
42
- status: response.status,
43
- config: responseConfig,
44
- headers: responseHeaders,
45
- };
46
- throw err;
47
- }
48
- }).then((response) => {
49
- return response.json();
50
- }).then((data) => {
51
- return {
52
- config: responseConfig,
53
- headers: responseHeaders,
54
- data,
55
- }
56
- });
26
+ return { config: responseConfig, headers: responseHeaders, data: await response.json() };
57
27
  };
58
28
 
59
29
  const ClientForWorkers = (config = {}) => {
60
- this.httpClient = {
61
- _get: (path, params) => {
62
- return _fetch(path, config, 'GET', params);
63
- },
64
-
65
- _post: (path, params) => {
66
- let formData = null;
67
- if (params && Object.keys(params).length > 0) {
68
- formData = new FormData();
69
- Object.keys(params).forEach(function (key) {
70
- formData.append(key, params[key]);
71
- });
72
- }
73
- return _fetch(path, config, 'POST', {}, formData)
74
- },
75
-
76
- _delete: (path) => {
77
- return _fetch(path, config, 'DELETE')
78
- },
30
+ // Snapshot configuration so later clients or caller mutations cannot change it.
31
+ const settings = { ...config };
32
+ const httpClient = {
33
+ _get: (path, params) => _fetch(path, settings, 'GET', params),
34
+ _post: (path, params, query) => _fetch(path, settings, 'POST', query, params),
35
+ _put: (path, params, query) => _fetch(path, settings, 'PUT', query, params),
36
+ _delete: (path, params) => _fetch(path, settings, 'DELETE', params),
79
37
  };
80
- return addApiMethodsToClient(this);
38
+ return addApiMethodsToClient({ httpClient });
81
39
  };
82
40
 
83
- module.exports = {
84
- ClientForWorkers,
85
- };
41
+ module.exports = { ClientForWorkers };
@@ -1,82 +1,98 @@
1
- const addApiMethodsToClient = (client) => {
2
- client.search = (params) => client.httpClient._get('/search', params);
3
-
4
- client.typeahead = (params) => client.httpClient._get('/typeahead', params);
5
-
6
- client.spellcheck = (params) => client.httpClient._get('/spellcheck', params);
7
-
8
- client.fetchRelatedSearches = (params) => client.httpClient._get('/related_searches', params);
9
-
10
- client.fetchTrendingSearches = (params) => client.httpClient._get('/trending_searches', params);
11
-
12
- client.fetchBestPodcasts = (params) => client.httpClient._get('/best_podcasts', params);
13
-
14
- client.fetchPodcastById = (params) => {
15
- const { id, ...otherParams } = params;
16
- return client.httpClient._get(`/podcasts/${id}`, otherParams);
17
- };
18
-
19
- client.fetchEpisodeById = (params) => {
20
- const { id, ...otherParams } = params;
21
- return client.httpClient._get(`/episodes/${id}`, otherParams);
22
- };
23
-
24
- client.batchFetchPodcasts = (params) => client.httpClient._post('/podcasts', params);
25
-
26
- client.batchFetchEpisodes = (params) => client.httpClient._post('/episodes', params);
27
-
28
- client.fetchCuratedPodcastsListById = (params) => {
29
- const { id, ...otherParams } = params;
30
- return client.httpClient._get(`/curated_podcasts/${id}`, otherParams);
31
- };
32
-
33
- client.fetchCuratedPodcastsLists = (params) => client.httpClient._get('/curated_podcasts', params);
34
-
35
- client.fetchPodcastGenres = (params) => client.httpClient._get('/genres', params);
36
-
37
- client.fetchPodcastRegions = (params) => client.httpClient._get('/regions', params);
38
-
39
- client.fetchPodcastLanguages = (params) => client.httpClient._get('/languages', params);
40
-
41
- client.justListen = (params) => client.httpClient._get('/just_listen', params);
42
-
43
- client.fetchRecommendationsForPodcast = (params) => {
44
- const { id, ...otherParams } = params;
45
- return client.httpClient._get(`/podcasts/${id}/recommendations`, otherParams);
46
- };
47
-
48
- client.fetchRecommendationsForEpisode = (params) => {
49
- const { id, ...otherParams } = params;
50
- return client.httpClient._get(`/episodes/${id}/recommendations`, otherParams);
51
- };
52
-
53
- client.fetchPlaylistById = (params) => {
54
- const { id, ...otherParams } = params;
55
- return client.httpClient._get(`/playlists/${id}`, otherParams);
56
- };
57
-
58
- client.fetchMyPlaylists = (params) => client.httpClient._get('/playlists', params);
59
-
60
- client.submitPodcast = (params) => client.httpClient._post('/podcasts/submit', params);
61
-
62
- client.deletePodcast = (params) => {
63
- const { id, reason } = params;
64
- return client.httpClient._delete(`/podcasts/${id}?reason=${reason || ''}`);
65
- };
66
-
67
- client.fetchAudienceForPodcast = (params) => {
68
- const { id, ...otherParams } = params;
69
- return client.httpClient._get(`/podcasts/${id}/audience`, otherParams);
70
- };
71
-
72
- client.fetchPodcastsByDomain = (params) => {
73
- const { domain_name, ...otherParams } = params;
74
- return client.httpClient._get(`/podcasts/domains/${domain_name}`, otherParams);
75
- };
1
+ // Generated by listennotes/devtools/api-sdks/sync.py javascript. Do not edit.
2
+ const { request } = require('./Request');
76
3
 
4
+ const addApiMethodsToClient = (client) => {
5
+ client.search = (params = {}) => request(
6
+ client.httpClient, "GET", "/search",
7
+ {"path": [], "query": ["q", "sort_by_date", "type", "offset", "len_min", "len_max", "episode_count_min", "episode_count_max", "update_freq_min", "update_freq_max", "genre_ids", "published_before", "published_after", "only_in", "language", "region", "ocid", "ncid", "safe_mode", "unique_podcasts", "interviews_only", "sponsored_only", "page_size"], "body": []}, params);
8
+ client.typeahead = (params = {}) => request(
9
+ client.httpClient, "GET", "/typeahead",
10
+ {"path": [], "query": ["q", "show_podcasts", "show_genres", "safe_mode"], "body": []}, params);
11
+ client.searchEpisodeTitles = (params = {}) => request(
12
+ client.httpClient, "GET", "/search_episode_titles",
13
+ {"path": [], "query": ["q", "podcast_id", "podcast_id_type"], "body": []}, params);
14
+ client.spellcheck = (params = {}) => request(
15
+ client.httpClient, "GET", "/spellcheck",
16
+ {"path": [], "query": ["q"], "body": []}, params);
17
+ client.fetchRelatedSearches = (params = {}) => request(
18
+ client.httpClient, "GET", "/related_searches",
19
+ {"path": [], "query": ["q"], "body": []}, params);
20
+ client.fetchTrendingSearches = (params = {}) => request(
21
+ client.httpClient, "GET", "/trending_searches",
22
+ {"path": [], "query": [], "body": []}, params);
23
+ client.fetchBestPodcasts = (params = {}) => request(
24
+ client.httpClient, "GET", "/best_podcasts",
25
+ {"path": [], "query": ["genre_id", "page", "region", "publisher_region", "language", "sort", "safe_mode"], "body": []}, params);
26
+ client.fetchPodcastById = (params = {}) => request(
27
+ client.httpClient, "GET", "/podcasts/{id}",
28
+ {"path": ["id"], "query": ["next_episode_pub_date", "sort"], "body": []}, params);
29
+ client.deletePodcast = (params = {}) => request(
30
+ client.httpClient, "DELETE", "/podcasts/{id}",
31
+ {"path": ["id"], "query": ["reason"], "body": []}, params);
32
+ client.fetchEpisodeById = (params = {}) => request(
33
+ client.httpClient, "GET", "/episodes/{id}",
34
+ {"path": ["id"], "query": ["show_transcript"], "body": []}, params);
35
+ client.batchFetchEpisodes = (params = {}) => request(
36
+ client.httpClient, "POST", "/episodes",
37
+ {"path": [], "query": [], "body": ["ids"]}, params);
38
+ client.batchFetchPodcasts = (params = {}) => request(
39
+ client.httpClient, "POST", "/podcasts",
40
+ {"path": [], "query": [], "body": ["ids", "rsses", "itunes_ids", "spotify_ids", "show_latest_episodes", "next_episode_pub_date"]}, params);
41
+ client.fetchCuratedPodcastsListById = (params = {}) => request(
42
+ client.httpClient, "GET", "/curated_podcasts/{id}",
43
+ {"path": ["id"], "query": [], "body": []}, params);
44
+ client.fetchPodcastGenres = (params = {}) => request(
45
+ client.httpClient, "GET", "/genres",
46
+ {"path": [], "query": ["top_level_only"], "body": []}, params);
47
+ client.fetchPodcastRegions = (params = {}) => request(
48
+ client.httpClient, "GET", "/regions",
49
+ {"path": [], "query": [], "body": []}, params);
50
+ client.fetchPodcastLanguages = (params = {}) => request(
51
+ client.httpClient, "GET", "/languages",
52
+ {"path": [], "query": [], "body": []}, params);
53
+ client.justListen = (params = {}) => request(
54
+ client.httpClient, "GET", "/just_listen",
55
+ {"path": [], "query": [], "body": []}, params);
56
+ client.fetchCuratedPodcastsLists = (params = {}) => request(
57
+ client.httpClient, "GET", "/curated_podcasts",
58
+ {"path": [], "query": ["page"], "body": []}, params);
59
+ client.fetchRecommendationsForPodcast = (params = {}) => request(
60
+ client.httpClient, "GET", "/podcasts/{id}/recommendations",
61
+ {"path": ["id"], "query": ["safe_mode"], "body": []}, params);
62
+ client.fetchRecommendationsForEpisode = (params = {}) => request(
63
+ client.httpClient, "GET", "/episodes/{id}/recommendations",
64
+ {"path": ["id"], "query": ["safe_mode"], "body": []}, params);
65
+ client.submitPodcast = (params = {}) => request(
66
+ client.httpClient, "POST", "/podcasts/submit",
67
+ {"path": [], "query": [], "body": ["rss", "email"]}, params);
68
+ client.fetchPlaylistById = (params = {}) => request(
69
+ client.httpClient, "GET", "/playlists/{id}",
70
+ {"path": ["id"], "query": ["type", "last_timestamp_ms", "sort"], "body": []}, params);
71
+ client.fetchMyPlaylists = (params = {}) => request(
72
+ client.httpClient, "GET", "/playlists",
73
+ {"path": [], "query": ["sort", "page"], "body": []}, params);
74
+ client.fetchAudienceForPodcast = (params = {}) => request(
75
+ client.httpClient, "GET", "/podcasts/{id}/audience",
76
+ {"path": ["id"], "query": [], "body": []}, params);
77
+ client.fetchPodcastsByDomain = (params = {}) => request(
78
+ client.httpClient, "GET", "/podcasts/domains/{domain_name}",
79
+ {"path": ["domain_name"], "query": ["page"], "body": []}, params);
80
+ client.createPlaylist = (params = {}) => request(
81
+ client.httpClient, "POST", "/playlists",
82
+ {"path": [], "query": [], "body": ["name", "description", "visibility", "type"]}, params);
83
+ client.updatePlaylist = (params = {}) => request(
84
+ client.httpClient, "PUT", "/playlists/{id}",
85
+ {"path": ["id"], "query": [], "body": ["name", "description", "visibility", "type"]}, params);
86
+ client.addPlaylistItem = (params = {}) => request(
87
+ client.httpClient, "POST", "/playlists/{id}/items",
88
+ {"path": ["id"], "query": [], "body": ["episode_id", "podcast_id", "notes"]}, params);
89
+ client.deletePlaylistItem = (params = {}) => request(
90
+ client.httpClient, "DELETE", "/playlists/{id}/items/{item_id}",
91
+ {"path": ["id", "item_id"], "query": [], "body": []}, params);
92
+ client.updatePlaylistItemNotes = (params = {}) => request(
93
+ client.httpClient, "PUT", "/playlists/{id}/items/{item_id}",
94
+ {"path": ["id", "item_id"], "query": [], "body": ["notes"]}, params);
77
95
  return client;
78
96
  };
79
97
 
80
- module.exports = {
81
- addApiMethodsToClient,
82
- };
98
+ module.exports = { addApiMethodsToClient };
package/src/Request.js ADDED
@@ -0,0 +1,24 @@
1
+ // Shared transport dispatch. Endpoint locations come from the generated methods.
2
+ const request = (httpClient, method, template, locations, params) => {
3
+ const query = {};
4
+ const body = {};
5
+ const path = template.replace(/\{([^}]+)\}/g, (_, name) => {
6
+ if (params[name] === undefined || params[name] === null || params[name] === '') {
7
+ throw new Error(`Missing path parameter: ${name}`);
8
+ }
9
+ return encodeURIComponent(params[name]);
10
+ });
11
+ Object.keys(params).forEach((name) => {
12
+ const value = params[name];
13
+ if (locations.path.includes(name) || value === undefined || value === null) return;
14
+ // Unknown fields retain the historical query/body behavior for forward compatibility.
15
+ const target = locations.query.includes(name) || method === 'GET' || method === 'DELETE' ? query : body;
16
+ target[name] = value;
17
+ });
18
+ if (method === 'POST' || method === 'PUT') {
19
+ return httpClient[`_${method.toLowerCase()}`](path, body, query);
20
+ }
21
+ return httpClient[`_${method.toLowerCase()}`](path, query);
22
+ };
23
+
24
+ module.exports = { request };