diff --git a/components/factorial_api_keys/factorial_api_keys.app.mjs b/components/factorial_api_keys/factorial_api_keys.app.mjs index 1c592a13f0175..42a2f2ab26534 100644 --- a/components/factorial_api_keys/factorial_api_keys.app.mjs +++ b/components/factorial_api_keys/factorial_api_keys.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/flowii/flowii.app.mjs b/components/flowii/flowii.app.mjs index 6dd8c468fec51..98b67ac555bcc 100644 --- a/components/flowii/flowii.app.mjs +++ b/components/flowii/flowii.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/hailey_hr/hailey_hr.app.mjs b/components/hailey_hr/hailey_hr.app.mjs index b52c4fb9c956a..02e5eac742489 100644 --- a/components/hailey_hr/hailey_hr.app.mjs +++ b/components/hailey_hr/hailey_hr.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/nuvemshop/nuvemshop.app.mjs b/components/nuvemshop/nuvemshop.app.mjs index b7d227d1b8855..a6a7124efaae2 100644 --- a/components/nuvemshop/nuvemshop.app.mjs +++ b/components/nuvemshop/nuvemshop.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/simpleem/simpleem.app.mjs b/components/simpleem/simpleem.app.mjs index 2745e0be8a3bf..a70ef6dd45b1a 100644 --- a/components/simpleem/simpleem.app.mjs +++ b/components/simpleem/simpleem.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/spotify/actions/add-items-to-playlist/add-items-to-playlist.mjs b/components/spotify/actions/add-items-to-playlist/add-items-to-playlist.mjs index c4e35ba8c03fc..cefab130af30d 100644 --- a/components/spotify/actions/add-items-to-playlist/add-items-to-playlist.mjs +++ b/components/spotify/actions/add-items-to-playlist/add-items-to-playlist.mjs @@ -1,12 +1,10 @@ -import { axios } from "@pipedream/platform"; -import get from "lodash/get.js"; import spotify from "../../spotify.app.mjs"; export default { name: "Add Items to a Playlist", description: "Add one or more items to a user’s playlist. [See the docs here](https://developer.spotify.com/documentation/web-api/reference/#/operations/add-tracks-to-playlist).", key: "spotify-add-items-to-playlist", - version: "0.1.4", + version: "0.1.5", annotations: { destructiveHint: false, openWorldHint: true, @@ -46,14 +44,15 @@ export default { uris: this.spotify.sanitizedArray(uris), }; - const resp = await axios($, this.spotify._getAxiosParams({ + const { data: resp } = await this.spotify._makeRequest({ + $, method: "POST", - path: `/playlists/${get(playlistId, "value", playlistId)}/tracks`, + url: `/playlists/${playlistId.value ?? playlistId}/tracks`, data, - })); + }); // eslint-disable-next-line multiline-ternary - $.export("$summary", `Successfully added ${data.uris.length} ${data.uris.length == 1 ? "item" : "items"} to "${get(playlistId, "label", playlistId)}"`); + $.export("$summary", `Successfully added ${data.uris.length} ${data.uris.length == 1 ? "item" : "items"} to "${playlistId.label ?? playlistId}"`); return resp; }, diff --git a/components/spotify/actions/create-playlist/create-playlist.mjs b/components/spotify/actions/create-playlist/create-playlist.mjs index d930126c8787d..af739031b8f32 100644 --- a/components/spotify/actions/create-playlist/create-playlist.mjs +++ b/components/spotify/actions/create-playlist/create-playlist.mjs @@ -1,11 +1,10 @@ -import { axios } from "@pipedream/platform"; import spotify from "../../spotify.app.mjs"; export default { name: "Create a Playlist", description: "Create a playlist for a Spotify user. The playlist will be empty until you add tracks. [See the docs here](https://developer.spotify.com/documentation/web-api/reference/#/operations/create-playlist).", key: "spotify-create-playlist", - version: "0.1.4", + version: "0.1.5", annotations: { destructiveHint: false, openWorldHint: true, @@ -53,11 +52,12 @@ export default { collaborative: isCollaborative, }; - const resp = await axios($, this.spotify._getAxiosParams({ + const { data: resp } = await this.spotify._makeRequest({ + $, method: "POST", - path: `/users/${this.spotify.$auth.oauth_uid}/playlists`, + url: `/users/${this.spotify.$auth.oauth_uid}/playlists`, data, - })); + }); $.export("$summary", `Successfully created a new playlist, "${data.name}"`); diff --git a/components/spotify/actions/get-album-tracks/get-album-tracks.mjs b/components/spotify/actions/get-album-tracks/get-album-tracks.mjs index 6da8f56c22ff2..9dcb3d2e31be6 100644 --- a/components/spotify/actions/get-album-tracks/get-album-tracks.mjs +++ b/components/spotify/actions/get-album-tracks/get-album-tracks.mjs @@ -1,13 +1,14 @@ -import { axios } from "@pipedream/platform"; import spotify from "../../spotify.app.mjs"; -import { ITEM_TYPES } from "../../common/constants.mjs"; -const DEFAULT_LIMIT = 20; +import { + ITEM_TYPES, + PAGE_SIZE, +} from "../../common/constants.mjs"; export default { name: "Get Album Tracks", description: "Get all tracks in an album. [See the docs here](https://developer.spotify.com/documentation/web-api/reference/get-an-albums-tracks)", key: "spotify-get-album-tracks", - version: "0.0.5", + version: "0.0.6", annotations: { destructiveHint: false, openWorldHint: true, @@ -25,12 +26,11 @@ export default { query, page, }) { - const limit = DEFAULT_LIMIT; const albums = await this.spotify.getItems( ITEM_TYPES.ALBUM, query, - limit, - limit * page, + PAGE_SIZE, + PAGE_SIZE * page, ); return { options: albums.map((album) => ({ @@ -43,19 +43,20 @@ export default { }, async run({ $ }) { const params = { - limit: DEFAULT_LIMIT, + limit: PAGE_SIZE, offset: 0, }; const tracks = []; let total = 0; do { - const { items } = await axios($, this.spotify._getAxiosParams({ - path: `/albums/${this.albumId}/tracks`, + const { data } = await this.spotify._makeRequest({ + $, + url: `/albums/${this.albumId}/tracks`, params, - })); - tracks.push(...items); - total = items.length; + }); + tracks.push(...data.items); + total = data.items.length; params.offset += params.limit; } while (total === params.limit); diff --git a/components/spotify/actions/get-all-tracks-by-artist/get-all-tracks-by-artist.mjs b/components/spotify/actions/get-all-tracks-by-artist/get-all-tracks-by-artist.mjs index de9f86f4ca784..8cf171d7ec192 100644 --- a/components/spotify/actions/get-all-tracks-by-artist/get-all-tracks-by-artist.mjs +++ b/components/spotify/actions/get-all-tracks-by-artist/get-all-tracks-by-artist.mjs @@ -1,11 +1,10 @@ -import get from "lodash/get.js"; import spotify from "../../spotify.app.mjs"; export default { name: "Get All Tracks by Artist", description: "Get Spotify tracks information related with an artist's. [see docs here](https://developer.spotify.com/documentation/web-api/reference/#/operations/get-multiple-albums).", key: "spotify-get-all-tracks-by-artist", - version: "0.1.4", + version: "0.1.5", annotations: { destructiveHint: false, openWorldHint: true, @@ -34,16 +33,18 @@ export default { } = this; const chunksOfAlbumIds = await this.spotify.fetchChunksOfAlbumsIds({ + $, artistId, market, }); const tracks = await this.spotify.getAllTracksByChunksOfAlbumIds({ + $, chunksOfAlbumIds, market, }); - $.export("$summary", `Successfully fetched ${tracks.length} tracks for "${get(artistId, "label", artistId)}"`); + $.export("$summary", `Successfully fetched ${tracks.length} tracks for "${artistId.label ?? artistId}"`); return tracks; }, diff --git a/components/spotify/actions/get-artist-top-tracks/get-artist-top-tracks.mjs b/components/spotify/actions/get-artist-top-tracks/get-artist-top-tracks.mjs index 6b4e01c2434b2..5e6b87bc4cce8 100644 --- a/components/spotify/actions/get-artist-top-tracks/get-artist-top-tracks.mjs +++ b/components/spotify/actions/get-artist-top-tracks/get-artist-top-tracks.mjs @@ -1,12 +1,10 @@ -import { axios } from "@pipedream/platform"; -import get from "lodash/get.js"; import spotify from "../../spotify.app.mjs"; export default { name: "Get an Artist's Top Tracks", - description: "Get Spotify catalog information about an artist’s top tracks by country. [See the docs here](https://developer.spotify.com/documentation/web-api/reference/#/operations/get-an-artists-top-tracks).", + description: "Get Spotify catalog information about an artist's top tracks by country. [See the docs here](https://developer.spotify.com/documentation/web-api/reference/#/operations/get-an-artists-top-tracks).", key: "spotify-get-artist-top-tracks", - version: "0.1.4", + version: "0.1.5", annotations: { destructiveHint: false, openWorldHint: true, @@ -34,16 +32,16 @@ export default { market, } = this; - const res = await axios($, this.spotify._getAxiosParams({ - method: "GET", - path: `/artists/${get(artistId, "value", artistId)}/top-tracks`, + const { data } = await this.spotify._makeRequest({ + $, + url: `/artists/${artistId.value ?? artistId}/top-tracks`, params: { market, }, - })); + }); - $.export("$summary", `Successfully fetched top tracks for "${get(artistId, "label", artistId)}"`); + $.export("$summary", `Successfully fetched top tracks for "${artistId.label ?? artistId}"`); - return get(res, "tracks", []); + return data?.tracks ?? []; }, }; diff --git a/components/spotify/actions/get-audio-features-for-a-track/get-audio-features-for-a-track.mjs b/components/spotify/actions/get-audio-features-for-a-track/get-audio-features-for-a-track.mjs index ecbfaee7d46c0..38f5955689005 100644 --- a/components/spotify/actions/get-audio-features-for-a-track/get-audio-features-for-a-track.mjs +++ b/components/spotify/actions/get-audio-features-for-a-track/get-audio-features-for-a-track.mjs @@ -1,12 +1,10 @@ -import { axios } from "@pipedream/platform"; -import get from "lodash/get.js"; import spotify from "../../spotify.app.mjs"; export default { name: "Get Audio Features for a Track", description: "Get audio feature information for a single track identified by its unique Spotify ID. [See the docs here](https://developer.spotify.com/documentation/web-api/reference/#/operations/get-audio-features).", key: "spotify-get-audio-features-for-a-track", - version: "0.1.4", + version: "0.1.5", annotations: { destructiveHint: false, openWorldHint: true, @@ -24,13 +22,13 @@ export default { }, async run({ $ }) { const { trackId } = this; - const resp = await axios($, this.spotify._getAxiosParams({ - method: "GET", - path: `/audio-features/${get(trackId, "value", trackId)}`, - })); + const { data } = await this.spotify._makeRequest({ + $, + url: `/audio-features/${trackId.value ?? trackId}`, + }); - $.export("$summary", `Successfully fetched audio info for the track, "${get(trackId, "label", trackId)}"`); + $.export("$summary", `Successfully fetched audio info for the track, "${trackId.label ?? trackId}"`); - return resp; + return data; }, }; diff --git a/components/spotify/actions/get-categorys-playlist/get-categorys-playlist.mjs b/components/spotify/actions/get-categorys-playlist/get-categorys-playlist.mjs index b7a14fffc87ce..3ef8aebd498d7 100644 --- a/components/spotify/actions/get-categorys-playlist/get-categorys-playlist.mjs +++ b/components/spotify/actions/get-categorys-playlist/get-categorys-playlist.mjs @@ -1,12 +1,10 @@ -import { axios } from "@pipedream/platform"; -import get from "lodash/get.js"; import spotify from "../../spotify.app.mjs"; export default { name: "Get a Category's Playlists", description: "Get a list of Spotify playlists tagged with a particular category. [See the docs here](https://developer.spotify.com/documentation/web-api/reference/#/operations/get-a-categories-playlists).", key: "spotify-get-categorys-playlist", - version: "0.1.4", + version: "0.1.5", annotations: { destructiveHint: false, openWorldHint: true, @@ -51,18 +49,18 @@ export default { offset, } = this; - const res = await axios($, this.spotify._getAxiosParams({ - method: "GET", - path: `/browse/categories/${get(categoryId, "value", categoryId)}/playlists`, + const { data } = await this.spotify._makeRequest({ + $, + url: `/browse/categories/${categoryId.value ?? categoryId}/playlists`, params: { limit, offset, country: market, }, - })); + }); - $.export("$summary", `Successfully fetched playlists for the "${get(categoryId, "label", categoryId)}" category`); + $.export("$summary", `Successfully fetched playlists for the "${categoryId.label ?? categoryId}" category`); - return get(res, "playlists.items", []); + return data?.playlists?.items ?? []; }, }; diff --git a/components/spotify/actions/get-currently-playing-track/get-currently-playing-track.mjs b/components/spotify/actions/get-currently-playing-track/get-currently-playing-track.mjs index af3cf7821d852..cb4fb8136156f 100644 --- a/components/spotify/actions/get-currently-playing-track/get-currently-playing-track.mjs +++ b/components/spotify/actions/get-currently-playing-track/get-currently-playing-track.mjs @@ -1,4 +1,3 @@ -import { axios } from "@pipedream/platform"; import spotify from "../../spotify.app.mjs"; import { ITEM_TYPES } from "../../common/constants.mjs"; @@ -7,7 +6,7 @@ export default { description: "Get the object currently being played on the user's Spotify account. [See the documentation](https://developer.spotify.com/documentation/web-api/reference/get-the-users-currently-playing-track)", key: "spotify-get-currently-playing-track", - version: "0.0.5", + version: "0.0.6", annotations: { destructiveHint: false, openWorldHint: true, @@ -28,20 +27,17 @@ export default { const { market } = this; try { - const res = await axios( + const { data: res } = await this.spotify._makeRequest({ $, - this.spotify._getAxiosParams({ - method: "GET", - path: "/me/player/currently-playing", - params: { - market, - additional_types: [ - ITEM_TYPES.TRACK, - ITEM_TYPES.EPISODE, - ].join(","), - }, - }), - ); + url: "/me/player/currently-playing", + params: { + market, + additional_types: [ + ITEM_TYPES.TRACK, + ITEM_TYPES.EPISODE, + ].join(","), + }, + }); const itemType = res?.currently_playing_type || "track"; const itemName = res?.item?.name || "Nothing"; diff --git a/components/spotify/actions/get-playlist-items/get-playlist-items.mjs b/components/spotify/actions/get-playlist-items/get-playlist-items.mjs index 8b60e1c394464..7d602ccca46d2 100644 --- a/components/spotify/actions/get-playlist-items/get-playlist-items.mjs +++ b/components/spotify/actions/get-playlist-items/get-playlist-items.mjs @@ -1,12 +1,10 @@ -import { axios } from "@pipedream/platform"; -import get from "lodash/get.js"; import spotify from "../../spotify.app.mjs"; export default { name: "Get a Playlist's Items", description: "Get full details of the items of a playlist owned by a Spotify user. [See the docs here](https://developer.spotify.com/documentation/web-api/reference/#/operations/get-playlists-tracks).", key: "spotify-get-playlist-items", - version: "0.1.4", + version: "0.1.5", annotations: { destructiveHint: false, openWorldHint: true, @@ -53,27 +51,25 @@ export default { async run({ $ }) { const { playlistId, - market, fields, limit, offset, additionalTypes, } = this; - const res = await axios($, this.spotify._getAxiosParams({ - method: "GET", - path: `/playlists/${get(playlistId, "value", playlistId)}/tracks`, + const { data } = await this.spotify._makeRequest({ + $, + url: `/playlists/${playlistId.value ?? playlistId}/tracks`, params: { fields, - market, limit, offset, additional_types: additionalTypes && additionalTypes.join(",").toLowerCase(), }, - })); + }); - $.export("$summary", `Successfully fetched details for "${get(playlistId, "label", playlistId)}"`); + $.export("$summary", `Successfully fetched details for "${playlistId.label ?? playlistId}"`); - return get(res, "items", []); + return data?.items ?? []; }, }; diff --git a/components/spotify/actions/get-playlist/get-playlist.mjs b/components/spotify/actions/get-playlist/get-playlist.mjs index 0339fe37f48c5..2fc1683207a4e 100644 --- a/components/spotify/actions/get-playlist/get-playlist.mjs +++ b/components/spotify/actions/get-playlist/get-playlist.mjs @@ -4,7 +4,7 @@ export default { name: "Get a Playlist", description: "Get a playlist owned by a Spotify user. [See the documentation](https://developer.spotify.com/documentation/web-api/reference/get-playlist).", key: "spotify-get-playlist", - version: "0.0.5", + version: "0.0.6", annotations: { destructiveHint: false, openWorldHint: true, diff --git a/components/spotify/actions/get-recommendations/get-recommendations.mjs b/components/spotify/actions/get-recommendations/get-recommendations.mjs index dcdf965f87b2c..00e095908c8de 100644 --- a/components/spotify/actions/get-recommendations/get-recommendations.mjs +++ b/components/spotify/actions/get-recommendations/get-recommendations.mjs @@ -5,7 +5,7 @@ export default { name: "Get Recommendations", description: "Create a list of recommendations based on the available information for a given seed entity and matched against similar artists and tracks. If there is sufficient information about the provided seeds, a list of tracks will be returned together with pool size details. [See the docs here](https://developer.spotify.com/documentation/web-api/reference/#/operations/get-recommendations).", key: "spotify-get-recommendations", - version: "0.1.4", + version: "0.1.5", annotations: { destructiveHint: false, openWorldHint: true, @@ -60,7 +60,7 @@ export default { const numSeeds = seedArtists.length + seedGenres.length + seedTracks.length; if (numSeeds > 5 || numSeeds < 1) { - throw new ConfigurationError("Must provide between 1 and 5 seeds in in any combination of `seedArtists`, `seedTracks` and `seedGenres`."); + throw new ConfigurationError("Must provide between 1 and 5 seeds in any combination of `seedArtists`, `seedTracks` and `seedGenres`."); } const params = { @@ -70,13 +70,16 @@ export default { limit, }; - const response = await this.spotify.getRecommendations(params, $); + const { data } = await this.spotify.getRecommendations({ + $, + ...params, + }); - if (response.tracks.length === 0) { + if (data?.tracks?.length === 0) { $.export("$summary", "No recommendations found"); return; } - $.export("$summary", `Successfully retrieved ${response.tracks.length} recommendation(s).`); - return response; + $.export("$summary", `Successfully retrieved ${data?.tracks?.length} recommendation(s).`); + return data; }, }; diff --git a/components/spotify/actions/get-track/get-track.mjs b/components/spotify/actions/get-track/get-track.mjs index 93b83f702f6d2..fc8c5484a4f14 100644 --- a/components/spotify/actions/get-track/get-track.mjs +++ b/components/spotify/actions/get-track/get-track.mjs @@ -1,12 +1,10 @@ -import { axios } from "@pipedream/platform"; -import get from "lodash/get.js"; import spotify from "../../spotify.app.mjs"; export default { name: "Get a Track", description: "Get a track by its name or ID. [See the docs here](https://developer.spotify.com/documentation/web-api/reference/#/operations/search)", key: "spotify-get-track", - version: "0.1.4", + version: "0.1.5", annotations: { destructiveHint: false, openWorldHint: true, @@ -35,16 +33,16 @@ export default { market, } = this; - const res = await axios($, this.spotify._getAxiosParams({ - method: "GET", - path: `/tracks/${get(trackId, "value", trackId)}`, + const { data } = await this.spotify._makeRequest({ + $, + url: `/tracks/${trackId.value ?? trackId}`, params: { market, }, - })); + }); - $.export("$summary", `Successfully fetched info for the track, "${res.name}"`); + $.export("$summary", `Successfully fetched info for the track, "${data?.name}"`); - return res; + return data ?? {}; }, }; diff --git a/components/spotify/actions/remove-items-from-playlist/remove-items-from-playlist.mjs b/components/spotify/actions/remove-items-from-playlist/remove-items-from-playlist.mjs index b859d55933537..bc2406c665bdb 100644 --- a/components/spotify/actions/remove-items-from-playlist/remove-items-from-playlist.mjs +++ b/components/spotify/actions/remove-items-from-playlist/remove-items-from-playlist.mjs @@ -1,12 +1,10 @@ -import { axios } from "@pipedream/platform"; -import get from "lodash/get.js"; import spotify from "../../spotify.app.mjs"; export default { name: "Remove Items from a Playlist", - description: "Remove one or more items from a user’s playlist. [See the docs here](https://developer.spotify.com/documentation/web-api/reference/#/operations/remove-tracks-playlist)", + description: "Remove one or more items from a user's playlist. [See the docs here](https://developer.spotify.com/documentation/web-api/reference/#/operations/remove-tracks-playlist)", key: "spotify-remove-items-from-playlist", - version: "0.1.4", + version: "0.1.5", annotations: { destructiveHint: true, openWorldHint: true, @@ -33,7 +31,7 @@ export default { snapshotId: { type: "string", label: "Snapshot ID", - description: "The playlist’s snapshot ID against which you want to make the changes. The API will validate that the specified items exist and in the specified positions and make the changes, even if more recent changes have been made to the playlist.", + description: "The playlist's snapshot ID against which you want to make the changes. The API will validate that the specified items exist and in the specified positions and make the changes, even if more recent changes have been made to the playlist.", optional: true, }, }, @@ -53,14 +51,15 @@ export default { snapshot_id: snapshotId, }; - const resp = await axios($, this.spotify._getAxiosParams({ + const { data: resp } = await this.spotify._makeRequest({ + $, method: "DELETE", - path: `/playlists/${get(playlistId, "value", playlistId)}/tracks`, + url: `/playlists/${playlistId.value ?? playlistId}/tracks`, data, - })); + }); // eslint-disable-next-line multiline-ternary - $.export("$summary", `Successfully removed ${tracks.length} ${tracks.length == 1 ? "item" : "items"} from the playlist, "${get(playlistId, "label", playlistId)}"`); + $.export("$summary", `Successfully removed ${tracks.length} ${tracks.length == 1 ? "item" : "items"} from the playlist, "${playlistId.label ?? playlistId}"`); return resp; }, diff --git a/components/spotify/actions/remove-user-saved-tracks/remove-user-saved-tracks.mjs b/components/spotify/actions/remove-user-saved-tracks/remove-user-saved-tracks.mjs index 0ca9f0e067413..69cc86c92e917 100644 --- a/components/spotify/actions/remove-user-saved-tracks/remove-user-saved-tracks.mjs +++ b/components/spotify/actions/remove-user-saved-tracks/remove-user-saved-tracks.mjs @@ -1,11 +1,10 @@ -import { axios } from "@pipedream/platform"; import spotify from "../../spotify.app.mjs"; export default { name: "Remove User's Saved Tracks", - description: "Remove one or more tracks from the current user’s ‘Your Music’ library. [See the docs here](https://developer.spotify.com/documentation/web-api/reference/#/operations/remove-tracks-user)", + description: "Remove one or more tracks from the current user's 'Your Music' library. [See the docs here](https://developer.spotify.com/documentation/web-api/reference/#/operations/remove-tracks-user)", key: "spotify-remove-user-saved-tracks", - version: "0.1.4", + version: "0.1.5", annotations: { destructiveHint: true, openWorldHint: true, @@ -26,17 +25,18 @@ export default { const ids = this.spotify.sanitizedArray(savedUserTracksId); - const resp = await axios($, this.spotify._getAxiosParams({ + const { data } = await this.spotify._makeRequest({ + $, method: "DELETE", - path: "/me/tracks", + url: "/me/tracks", data: { ids, }, - })); + }); // eslint-disable-next-line multiline-ternary $.export("$summary", `Successfully removed ${ids.length} ${ids.length == 1 ? "item" : "items"} from "Liked Songs"`); - return resp; + return data; }, }; diff --git a/components/spotify/actions/save-track/save-track.mjs b/components/spotify/actions/save-track/save-track.mjs index 3b542078d9319..e5d1bc52d6d1b 100644 --- a/components/spotify/actions/save-track/save-track.mjs +++ b/components/spotify/actions/save-track/save-track.mjs @@ -1,12 +1,10 @@ -import { axios } from "@pipedream/platform"; -import isEmpty from "lodash/isEmpty.js"; import spotify from "../../spotify.app.mjs"; export default { name: "Save Tracks for User", - description: "Save one or more tracks to the current user’s \"Your Music\" library. [See the docs here](https://developer.spotify.com/documentation/web-api/reference/#/operations/save-tracks-user).", + description: "Save one or more tracks to the current user's \"Your Music\" library. [See the docs here](https://developer.spotify.com/documentation/web-api/reference/#/operations/save-tracks-user).", key: "spotify-save-track", - version: "0.1.4", + version: "0.1.5", annotations: { destructiveHint: false, openWorldHint: true, @@ -27,18 +25,19 @@ export default { }, async run({ $ }) { const ids = this.spotify.sanitizedArray(this.trackIds); - const res = await axios($, this.spotify._getAxiosParams({ + const { data: res } = await this.spotify._makeRequest({ + $, method: "PUT", - path: "/me/tracks", + url: "/me/tracks", data: { ids, }, - })); + }); // eslint-disable-next-line multiline-ternary $.export("$summary", `Successfully saved ${ids.length} ${ids.length == 1 ? "track" : "tracks"} to "Liked Songs"`); - return isEmpty(res) + return !res || Object.keys(res).length === 0 ? ids : res; }, diff --git a/components/spotify/actions/search/search.mjs b/components/spotify/actions/search/search.mjs index a9781352b65ab..dc6e9a69bca9a 100644 --- a/components/spotify/actions/search/search.mjs +++ b/components/spotify/actions/search/search.mjs @@ -1,14 +1,16 @@ import { ConfigurationError } from "@pipedream/platform"; import spotify from "../../spotify.app.mjs"; import { - ITEM_TYPES_LIST, ITEM_TYPES, + ITEM_TYPES_LIST, + ITEM_TYPES, + PAGE_SIZE, } from "../../common/constants.mjs"; export default { key: "spotify-search", name: "Search", description: "Search for items on Spotify (tracks, albums, artists, playlists, shows, or episodes). [See the docs here](https://developer.spotify.com/documentation/web-api/reference/search)", - version: "0.0.2", + version: "0.0.3", type: "action", annotations: { destructiveHint: false, @@ -44,7 +46,7 @@ export default { "limit", ], description: "The maximum number of results to return per type.", - default: 20, + default: PAGE_SIZE, max: 50, }, offset: { @@ -73,6 +75,7 @@ export default { } const res = await this.spotify.search({ + $, q: this.query, type: this.type.join(","), market: this.market, diff --git a/components/spotify/common/constants.mjs b/components/spotify/common/constants.mjs index ccd3994fd1cad..405317c04d4dd 100644 --- a/components/spotify/common/constants.mjs +++ b/components/spotify/common/constants.mjs @@ -42,3 +42,5 @@ export const ITEM_TYPES_RESULT_NAME = { [ITEM_TYPES.SHOW]: "shows", [ITEM_TYPES.EPISODE]: "episodes", }; + +export const PAGE_SIZE = 50; diff --git a/components/spotify/package.json b/components/spotify/package.json index 602156221b1dd..a324804d29986 100644 --- a/components/spotify/package.json +++ b/components/spotify/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/spotify", - "version": "0.7.5", + "version": "0.7.6", "description": "Pipedream Spotify Components", "main": "spotify.app.mjs", "keywords": [ @@ -14,7 +14,6 @@ "access": "public" }, "dependencies": { - "@pipedream/platform": "^3.1.1", - "lodash": "^4.17.21" + "@pipedream/platform": "^3.1.1" } } diff --git a/components/spotify/sources/new-playlist/new-playlist.mjs b/components/spotify/sources/new-playlist/new-playlist.mjs index 93aea65f57390..e12ecda97e9af 100644 --- a/components/spotify/sources/new-playlist/new-playlist.mjs +++ b/components/spotify/sources/new-playlist/new-playlist.mjs @@ -6,7 +6,7 @@ export default { key: "spotify-new-playlist", name: "New Playlist", description: "Emit new event when a new playlist is created or followed by the current Spotify user.", - version: "0.1.3", + version: "0.1.4", props: { ...common.props, }, diff --git a/components/spotify/sources/new-saved-track/new-saved-track.mjs b/components/spotify/sources/new-saved-track/new-saved-track.mjs index 4831c5ff14604..25fb26257bc31 100644 --- a/components/spotify/sources/new-saved-track/new-saved-track.mjs +++ b/components/spotify/sources/new-saved-track/new-saved-track.mjs @@ -6,7 +6,7 @@ export default { key: "spotify-new-saved-track", name: "New Saved Track", description: "Emit new event for each new track saved to the current Spotify user's Music Library.", - version: "0.1.3", + version: "0.1.4", props: { ...common.props, db: "$.service.db", diff --git a/components/spotify/sources/new-track-by-artist/new-track-by-artist.mjs b/components/spotify/sources/new-track-by-artist/new-track-by-artist.mjs index 7029529f3b701..eebc1ac217f20 100644 --- a/components/spotify/sources/new-track-by-artist/new-track-by-artist.mjs +++ b/components/spotify/sources/new-track-by-artist/new-track-by-artist.mjs @@ -7,7 +7,7 @@ export default { key: "spotify-new-track-by-artist", name: "New Track by Artist", description: "Emit new event for each new Spotify track related with an artist. [see docs here](https://developer.spotify.com/documentation/web-api/reference/#/operations/get-multiple-albums)", - version: "0.1.3", + version: "0.1.4", props: { ...common.props, db: "$.service.db", diff --git a/components/spotify/sources/new-track-in-playlist/new-track-in-playlist.mjs b/components/spotify/sources/new-track-in-playlist/new-track-in-playlist.mjs index 7377eb086e230..b52f048ad7287 100644 --- a/components/spotify/sources/new-track-in-playlist/new-track-in-playlist.mjs +++ b/components/spotify/sources/new-track-in-playlist/new-track-in-playlist.mjs @@ -7,7 +7,7 @@ export default { key: "spotify-new-track-in-playlist", name: "New Track in Playlist", description: "Emit new event for each new Spotify track added to a playlist", - version: "0.1.3", + version: "0.1.4", props: { ...common.props, db: "$.service.db", diff --git a/components/spotify/spotify.app.mjs b/components/spotify/spotify.app.mjs index f5d0633a14a5b..580bd21f8f03b 100644 --- a/components/spotify/spotify.app.mjs +++ b/components/spotify/spotify.app.mjs @@ -1,13 +1,9 @@ import { axios } from "@pipedream/platform"; -import get from "lodash/get.js"; -import isArray from "lodash/isArray.js"; -import isEmpty from "lodash/isEmpty.js"; -import isNil from "lodash/isNil.js"; -import isString from "lodash/isString.js"; import { promisify } from "util"; import { ITEM_TYPES, ITEM_TYPES_RESULT_NAME, + PAGE_SIZE, } from "./common/constants.mjs"; import Countries from "./country-codes.mjs"; @@ -31,11 +27,10 @@ export default { async options({ page, playlistId, }) { - const limit = 20; const items = await this.getPlaylistItems({ - limit, - offset: limit * page, - playlistId: get(playlistId, "value", playlistId), + limit: PAGE_SIZE, + offset: PAGE_SIZE * page, + playlistId: playlistId.value ?? playlistId, }); return { @@ -52,10 +47,9 @@ export default { description: "Search saved user tracks in \"Liked Songs\" or enter a custom expression to reference specific [Spotify ID](https://developer.spotify.com/documentation/web-api/#spotify-uris-and-ids) for the track. For example: `4iV5W9uYEdYUVa79Axb7Rh`. Maximum: 50 IDs.", withLabel: true, async options({ page }) { - const limit = 20; const items = await this.getUserTracks({ - limit, - offset: limit * page, + limit: PAGE_SIZE, + offset: PAGE_SIZE * page, }); return { @@ -76,12 +70,11 @@ export default { query, page, }) { - const limit = 20; const artists = await this.getItems( ITEM_TYPES.ARTIST, query, - limit, - limit * page, + PAGE_SIZE, + PAGE_SIZE * page, ); return { options: artists.map((artist) => ({ @@ -96,10 +89,9 @@ export default { label: "Playlist ID", description: "Select an existing playlist or pass a custom expression to reference a specific [`playlist_id`](https://developer.spotify.com/documentation/web-api/#spotify-uris-and-ids) (for example, `3cEYpjA9oz9GiPac4AsH4n`).", async options({ page }) { - const limit = 20; const playlists = await this.getPlaylists({ - limit, - offset: limit * page, + limit: PAGE_SIZE, + offset: PAGE_SIZE * page, }); return { options: playlists.map((playlist) => ({ @@ -115,10 +107,9 @@ export default { description: "Type to search for a category or enter a custom expression to reference a specific [category ID](https://developer.spotify.com/documentation/web-api/#spotify-uris-and-ids) (for example, `party`).", withLabel: true, async options({ page }) { - const limit = 20; const categories = await this.getCategories({ - limit, - offset: limit * page, + limit: PAGE_SIZE, + offset: PAGE_SIZE * page, }); return { options: categories.map((category) => ({ @@ -138,12 +129,11 @@ export default { query, page, }) { - const limit = 20; const tracks = await this.getItems( ITEM_TYPES.TRACK, query, - limit, - limit * page, + PAGE_SIZE, + PAGE_SIZE * page, ); return { options: tracks.map((track) => ({ @@ -163,15 +153,14 @@ export default { query, page, }) { - const limit = 20; const items = await this.getItems( [ ITEM_TYPES.TRACK, ITEM_TYPES.EPISODE, ], query, - limit, - limit * page, + PAGE_SIZE, + PAGE_SIZE * page, ); return { options: items.map((item) => ({ @@ -207,14 +196,14 @@ export default { }, methods: { sanitizedArray(value) { - if (isArray(value)) { - return value.map((item) => get(item, "value", item)); + if (Array.isArray(value)) { + return value.map((item) => item.value ?? item); } // If is string, try to convert it in an array - if (isString(value)) { + if (typeof value === "string") { // Return an empty array if string is empty - if (isEmpty(value)) { + if (value === "") { return []; } @@ -223,41 +212,14 @@ export default { throw new Error(`${value} is not an array or an array-like`); }, - _getAxiosParams(opts) { - return { - ...opts, - url: this._getBaseUrl() + opts.path + this._getQuery(opts.params), - headers: this._getHeaders(), - }; - }, - _getBaseUrl() { - return "https://api.spotify.com/v1"; - }, _getHeaders() { return { Authorization: `Bearer ${this.$auth.oauth_access_token}`, }; }, - _getQuery(params) { - if (!params) { - return ""; - } - - let query = "?"; - const keys = Object.keys(params); - for (let i = 0; i < keys.length; i++) { - // Explicity looking for nil values to avoid false negative for Boolean(false) - if (!isNil(params[keys[i]])) { - query += `${keys[i]}=${params[keys[i]]}&`; - } - } - - // It removes the last string char, it can be ? or & - return query.substr(0, query.length - 1); - }, async _paginate(resourceFn, params = {}) { let data = []; - params.limit = 20; + params.limit = PAGE_SIZE; params.offset = 0; do { @@ -288,34 +250,40 @@ export default { const artists = track.artists.map((artist) => artist.name).join(", "); return `${track.name} [${artists}]`; }, - async _makeRequest(method, endpoint, params) { + _getBaseUrl() { + return "https://api.spotify.com/v1"; + }, + async _makeRequest({ + $ = this, + headers, + ...args + } = {}) { const config = { - method, - url: `${await this._getBaseUrl()}${endpoint}`, - headers: await this._getHeaders(), - params, + baseURL: this._getBaseUrl(), + headers: { + ...headers, + ...this._getHeaders(), + }, + ...args, }; - return await this.retry(config); + return await this.retry($, config); }, // Retry axios request if not successful - async retry(config, retries = 3) { - let response; + async retry($, config, retries = 0) { try { - return await axios(this, { + return await axios($, { ...config, returnFullResponse: true, }); } catch (err) { - if (retries <= 1) { - throw new Error(err); + if (err?.status !== 429 || retries >= 3) { + $?.export?.("response", err); + throw new Error("Error response exported in the \"response\" object"); } - // if rate limit is exceeded, Retry-After will contain the # of seconds - // to wait before retrying - const delay = (response && response.status == 429) - ? (response.headers["Retry-After"] * 1000) - : 500; + + const delay = retries * 5000; await pause(delay); - return this.retry(config, retries - 1); + return this.retry($, config, retries + 1); } }, async getItems(types, q, limit, offset) { @@ -340,9 +308,13 @@ export default { offset, }; - const res = await this._makeRequest("GET", "/search", params); + const res = await this._makeRequest({ + method: "GET", + url: "/search", + params, + }); return types.reduce((accumulator, type) => ( - accumulator.concat(get(res, `data.${ITEM_TYPES_RESULT_NAME[type]}.items`, [])) + accumulator.concat(res.data?.[ITEM_TYPES_RESULT_NAME[type]]?.items ?? []) ), []); }, getItemOptionLabel(item) { @@ -356,59 +328,89 @@ export default { } }, async getPlaylist({ - playlistId, params, + playlistId, ...args }) { - const res = await this._makeRequest("GET", `/playlists/${playlistId}`, params); - return get(res, "data", {}); - }, - async getPlaylists(params) { - const res = await this._makeRequest("GET", "/me/playlists", params); - return get(res, "data.items", null); - }, - async getCategories(params) { - const res = await this._makeRequest("GET", "/browse/categories", params); - return get(res, "data.categories.items", []); - }, - async getUserTracks(params) { - const res = await this._makeRequest("GET", "/me/tracks", params); - return get(res, "data.items", []); - }, - async getPlaylistItems(params) { - const { playlistId } = params; - const res = await this._makeRequest("GET", `/playlists/${playlistId}/tracks`, params); - return get(res, "data.items", []); - }, - async getGenres() { - const { data } = await this._makeRequest("GET", "/recommendations/available-genre-seeds"); - return data.genres; + const { data } = await this._makeRequest({ + url: `/playlists/${playlistId}`, + ...args, + }); + return data; }, - async getRecommendations(params) { - const { data } = await this._makeRequest("GET", "/recommendations", params); + async getPlaylists(args) { + const { data } = await this._makeRequest({ + url: "/me/playlists", + ...args, + }); + return data?.items ?? []; + }, + async getCategories(args) { + const { data } = await this._makeRequest({ + url: "/browse/categories", + ...args, + }); + return data?.categories?.items ?? []; + }, + async getUserTracks(args) { + const { data } = await this._makeRequest({ + url: "/me/tracks", + ...args, + }); + return data?.items ?? []; + }, + async getPlaylistItems({ + $, playlistId, ...args + }) { + const { data } = await this._makeRequest({ + $, + url: `/playlists/${playlistId}/tracks`, + ...args, + }); + return data?.items ?? []; + }, + async getGenres(args) { + const { data } = await this._makeRequest({ + url: "/recommendations/available-genre-seeds", + ...args, + }); + return data?.genres; + }, + async getRecommendations(args) { + const { data } = await this._makeRequest({ + url: "/recommendations", + ...args, + }); return data; }, - async search(params) { - const { data } = await this._makeRequest("GET", "/search", params); + async search({ + $, ...params + }) { + const { data } = await this._makeRequest({ + $, + method: "GET", + url: "/search", + params, + }); return data; }, async fetchChunksOfAlbumsIds({ + $, artistId, market, }) { const albums = []; - const limit = 20; let page = 0; let next = undefined; do { - const { data } = await this._makeRequest( - "GET", - `/artists/${get(artistId, "value", artistId)}/albums`, - { + const { data } = await this._makeRequest({ + $, + url: `/artists/${artistId.value ?? artistId}/albums`, + params: { market, - limit, - offset: limit * page, + limit: PAGE_SIZE, + offset: PAGE_SIZE * page, include_groups: "album,single", }, - ); + }); albums.push([ ...data.items.map((album) => album.id), ]); @@ -418,19 +420,20 @@ export default { return albums; }, async getAllTracksByChunksOfAlbumIds({ + $, chunksOfAlbumIds, market, }) { const tracks = []; for (const albumIds of chunksOfAlbumIds) { - const { data } = await this._makeRequest( - "GET", - "/albums", - { + const { data } = await this._makeRequest({ + $, + url: "/albums", + params: { market, ids: albumIds.join(","), }, - ); + }); tracks.push([ ...data.albums.map((album) => album.tracks.items).flat(), ]); diff --git a/components/suitecrm/suitecrm.app.mjs b/components/suitecrm/suitecrm.app.mjs index 9e5e5b656cb7b..871fb1154d3e8 100644 --- a/components/suitecrm/suitecrm.app.mjs +++ b/components/suitecrm/suitecrm.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d92200a61323c..813ec724df15d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14323,9 +14323,6 @@ importers: '@pipedream/platform': specifier: ^3.1.1 version: 3.1.1 - lodash: - specifier: ^4.17.21 - version: 4.17.21 components/spotlightr: dependencies: