{"version":3,"file":"DArtistCard-3a33c3af.js","sources":["../../client/packages/utils/src/normalizers/artist.ts"],"sourcesContent":["import type {ArtistCard, StoryArtist, ArtistListType, ArtistSong, ArtistCardSong} from \"@songfinch/types\";\n\nexport const NormalizeStoryArtistToArtistCard = (\n artist: StoryArtist,\n): ArtistCard => {\n const cardObject: ArtistCard = {\n id: artist.id.toString(),\n name: artist.fullName,\n photo: artist.photo,\n exclusivity: !!artist.exclusivity,\n };\n\n if (artist.city || artist.state) {\n cardObject.location = [artist.city, artist.state]\n .filter(Boolean)\n .join(\", \");\n }\n\n if (artist.genres) {\n cardObject.genres = artist.genres.map((genre) => genre.name).join(\", \");\n }\n\n return cardObject;\n};\n\nexport const NormalizeArtistSong = (\n song: ArtistSong | undefined,\n artistName?: string,\n): ArtistCardSong | undefined => {\n if (!song) return undefined;\n return {\n url: song.audio_url,\n artist: artistName,\n title: song.title,\n genres: song.genres,\n };\n};\n\nexport const normalizeArtistQuickestDeliveryTime = (deliveryDayArray: string[]) => {\n return (deliveryDayArray).reduce((quickestTurnArround: number | undefined, deliveryDayAmount) => {\n const deliveryTime = Number(deliveryDayAmount) || undefined;\n if (!deliveryTime) return quickestTurnArround;\n if (!quickestTurnArround || quickestTurnArround > deliveryTime) return deliveryTime;\n return quickestTurnArround;\n }, undefined);\n};\n\n\nexport const NormalizeArtistListTypeToArtistCard = (\n artist: ArtistListType,\n): ArtistCard => { \n const quickestDeliveryTime = normalizeArtistQuickestDeliveryTime(artist?.available_delivery_days || []);\n const availableDeliveryTime = quickestDeliveryTime ? `${quickestDeliveryTime * 24}hr` : undefined;\n\n return {\n id: artist.id.toString(),\n name: artist.artist_name,\n location: undefined,\n song: NormalizeArtistSong(artist.songs?.[0], artist.artist_name),\n genres: artist.genres ? Object.values(artist.genres).join(\", \") : undefined,\n photo: artist.photo,\n availableDeliveryTime: availableDeliveryTime,\n exclusivity: !!artist.exclusivity,\n artistApplauseRating: artist.artist_applause_rating,\n songsCompleted: artist.songs_completed,\n };\n};\n\nconst isStoryArtist = (artist: unknown): artist is StoryArtist =>\n !!(artist as StoryArtist).fullName;\n\nconst isArtistListType = (artist: unknown): artist is ArtistListType =>\n !!(artist as ArtistListType).artist_name;\n\nexport const normalizeArtistCard = (\n artist: StoryArtist | ArtistListType,\n): ArtistCard | undefined => {\n if (isStoryArtist(artist)) {\n return NormalizeStoryArtistToArtistCard(artist);\n }\n if (isArtistListType(artist)) {\n return NormalizeArtistListTypeToArtistCard(artist);\n }\n return undefined;\n};"],"names":["NormalizeStoryArtistToArtistCard","artist","cardObject","genre","NormalizeArtistSong","song","artistName","normalizeArtistQuickestDeliveryTime","deliveryDayArray","quickestTurnArround","deliveryDayAmount","deliveryTime","NormalizeArtistListTypeToArtistCard","quickestDeliveryTime","availableDeliveryTime","_a","isStoryArtist","isArtistListType","normalizeArtistCard"],"mappings":"o+BAEa,MAAAA,EACTC,GACa,CACb,MAAMC,EAAyB,CAC3B,GAAID,EAAO,GAAG,SAAS,EACvB,KAAMA,EAAO,SACb,MAAOA,EAAO,MACd,YAAa,CAAC,CAACA,EAAO,WAAA,EAGtB,OAAAA,EAAO,MAAQA,EAAO,SACXC,EAAA,SAAW,CAACD,EAAO,KAAMA,EAAO,KAAK,EAC3C,OAAO,OAAO,EACd,KAAK,IAAI,GAGdA,EAAO,SACIC,EAAA,OAASD,EAAO,OAAO,IAAKE,GAAUA,EAAM,IAAI,EAAE,KAAK,IAAI,GAGnED,CACX,EAEaE,EAAsB,CAC/BC,EACAC,IAC6B,CAC7B,GAAKD,EACE,MAAA,CACH,IAAKA,EAAK,UACV,OAAQC,EACR,MAAOD,EAAK,MACZ,OAAQA,EAAK,MAAA,CAErB,EAEaE,EAAuCC,GACxCA,EAAkB,OAAO,CAACC,EAAyCC,IAAsB,CACvF,MAAAC,EAAe,OAAOD,CAAiB,GAAK,OAClD,OAAKC,IACD,CAACF,GAAuBA,EAAsBE,GAAqBA,EAD7CF,CAEnB,EACR,MAAS,EAIHG,EACTX,GACa,OAC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