@wwdrew/expo-apple-music 1.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.
Files changed (452) hide show
  1. package/ATTRIBUTION.md +24 -0
  2. package/LICENSE +190 -0
  3. package/NOTICE +7 -0
  4. package/README.md +81 -0
  5. package/android/build.gradle +26 -0
  6. package/android/libs/mediaplayback-release-1.1.1.aar +0 -0
  7. package/android/libs/musickitauth-release-1.1.2.aar +0 -0
  8. package/android/src/main/AndroidManifest.xml +16 -0
  9. package/android/src/main/java/expo/modules/applemusic/AndroidCatalogService.kt +86 -0
  10. package/android/src/main/java/expo/modules/applemusic/AndroidDeveloperToken.kt +39 -0
  11. package/android/src/main/java/expo/modules/applemusic/AndroidHistoryService.kt +24 -0
  12. package/android/src/main/java/expo/modules/applemusic/AndroidLibraryMutationsService.kt +30 -0
  13. package/android/src/main/java/expo/modules/applemusic/AndroidLibraryService.kt +61 -0
  14. package/android/src/main/java/expo/modules/applemusic/AndroidPlaybackController.kt +484 -0
  15. package/android/src/main/java/expo/modules/applemusic/AndroidPlaybackObserver.kt +173 -0
  16. package/android/src/main/java/expo/modules/applemusic/AndroidQueueService.kt +78 -0
  17. package/android/src/main/java/expo/modules/applemusic/AndroidRatingsService.kt +27 -0
  18. package/android/src/main/java/expo/modules/applemusic/AndroidRecommendationsService.kt +15 -0
  19. package/android/src/main/java/expo/modules/applemusic/AndroidSubscriptionService.kt +24 -0
  20. package/android/src/main/java/expo/modules/applemusic/AppleMusicErrorCodes.kt +13 -0
  21. package/android/src/main/java/expo/modules/applemusic/AppleMusicErrors.kt +46 -0
  22. package/android/src/main/java/expo/modules/applemusic/AppleMusicHttpMethod.kt +8 -0
  23. package/android/src/main/java/expo/modules/applemusic/AppleMusicJsonMapper.kt +258 -0
  24. package/android/src/main/java/expo/modules/applemusic/AppleMusicNativeLoader.kt +32 -0
  25. package/android/src/main/java/expo/modules/applemusic/AppleMusicRestJson.kt +40 -0
  26. package/android/src/main/java/expo/modules/applemusic/AppleMusicRestQuery.kt +12 -0
  27. package/android/src/main/java/expo/modules/applemusic/AppleMusicRestStack.kt +19 -0
  28. package/android/src/main/java/expo/modules/applemusic/AppleMusicRestTransport.kt +118 -0
  29. package/android/src/main/java/expo/modules/applemusic/AuthenticatedSession.kt +57 -0
  30. package/android/src/main/java/expo/modules/applemusic/BridgeResponses.kt +55 -0
  31. package/android/src/main/java/expo/modules/applemusic/CatalogRestClient.kt +306 -0
  32. package/android/src/main/java/expo/modules/applemusic/ExpoAppleMusicModule.kt +152 -0
  33. package/android/src/main/java/expo/modules/applemusic/HistoryRestClient.kt +60 -0
  34. package/android/src/main/java/expo/modules/applemusic/LibraryIds.kt +6 -0
  35. package/android/src/main/java/expo/modules/applemusic/LibraryMutationsRestClient.kt +95 -0
  36. package/android/src/main/java/expo/modules/applemusic/LibraryRestClient.kt +195 -0
  37. package/android/src/main/java/expo/modules/applemusic/MusicKitAuthContract.kt +78 -0
  38. package/android/src/main/java/expo/modules/applemusic/MusicKitAuthStorage.kt +76 -0
  39. package/android/src/main/java/expo/modules/applemusic/MusicKitTokenProvider.kt +13 -0
  40. package/android/src/main/java/expo/modules/applemusic/PaginationOptions.kt +14 -0
  41. package/android/src/main/java/expo/modules/applemusic/RatingsRestClient.kt +72 -0
  42. package/android/src/main/java/expo/modules/applemusic/RecommendationsRestClient.kt +37 -0
  43. package/android/src/main/java/expo/modules/applemusic/StorefrontRestClient.kt +44 -0
  44. package/android/src/main/java/expo/modules/applemusic/bridge/ExpoBridgeAuth.kt +69 -0
  45. package/android/src/main/java/expo/modules/applemusic/bridge/ExpoBridgeCatalog.kt +76 -0
  46. package/android/src/main/java/expo/modules/applemusic/bridge/ExpoBridgeHistory.kt +35 -0
  47. package/android/src/main/java/expo/modules/applemusic/bridge/ExpoBridgeLibrary.kt +54 -0
  48. package/android/src/main/java/expo/modules/applemusic/bridge/ExpoBridgeLibraryMutations.kt +30 -0
  49. package/android/src/main/java/expo/modules/applemusic/bridge/ExpoBridgePlayer.kt +89 -0
  50. package/android/src/main/java/expo/modules/applemusic/bridge/ExpoBridgeRatings.kt +29 -0
  51. package/android/src/main/java/expo/modules/applemusic/bridge/ExpoBridgeRecommendations.kt +18 -0
  52. package/app.plugin.js +1 -0
  53. package/build/ExpoAppleMusicModule.web.d.ts +15 -0
  54. package/build/ExpoAppleMusicModule.web.d.ts.map +1 -0
  55. package/build/ExpoAppleMusicModule.web.js +33 -0
  56. package/build/ExpoAppleMusicModule.web.js.map +1 -0
  57. package/build/api/call-native.d.ts +6 -0
  58. package/build/api/call-native.d.ts.map +1 -0
  59. package/build/api/call-native.js +35 -0
  60. package/build/api/call-native.js.map +1 -0
  61. package/build/api/decode-jwt-exp.d.ts +5 -0
  62. package/build/api/decode-jwt-exp.d.ts.map +1 -0
  63. package/build/api/decode-jwt-exp.js +28 -0
  64. package/build/api/decode-jwt-exp.js.map +1 -0
  65. package/build/api/library-ids.d.ts +4 -0
  66. package/build/api/library-ids.d.ts.map +1 -0
  67. package/build/api/library-ids.js +11 -0
  68. package/build/api/library-ids.js.map +1 -0
  69. package/build/api/pagination.d.ts +12 -0
  70. package/build/api/pagination.d.ts.map +1 -0
  71. package/build/api/pagination.js +13 -0
  72. package/build/api/pagination.js.map +1 -0
  73. package/build/api/parse-authorize-result.d.ts +3 -0
  74. package/build/api/parse-authorize-result.d.ts.map +1 -0
  75. package/build/api/parse-authorize-result.js +27 -0
  76. package/build/api/parse-authorize-result.js.map +1 -0
  77. package/build/api/require-music-user-token.d.ts +2 -0
  78. package/build/api/require-music-user-token.d.ts.map +1 -0
  79. package/build/api/require-music-user-token.js +14 -0
  80. package/build/api/require-music-user-token.js.map +1 -0
  81. package/build/api/sync-developer-token.d.ts +4 -0
  82. package/build/api/sync-developer-token.d.ts.map +1 -0
  83. package/build/api/sync-developer-token.js +27 -0
  84. package/build/api/sync-developer-token.js.map +1 -0
  85. package/build/bridge/bridge-methods.d.ts +17 -0
  86. package/build/bridge/bridge-methods.d.ts.map +1 -0
  87. package/build/bridge/bridge-methods.js +71 -0
  88. package/build/bridge/bridge-methods.js.map +1 -0
  89. package/build/bridge/bridge-responses.d.ts +64 -0
  90. package/build/bridge/bridge-responses.d.ts.map +1 -0
  91. package/build/bridge/bridge-responses.js +67 -0
  92. package/build/bridge/bridge-responses.js.map +1 -0
  93. package/build/bridge/handlers/auth-bridge.d.ts +11 -0
  94. package/build/bridge/handlers/auth-bridge.d.ts.map +1 -0
  95. package/build/bridge/handlers/auth-bridge.js +49 -0
  96. package/build/bridge/handlers/auth-bridge.js.map +1 -0
  97. package/build/bridge/handlers/catalog-bridge.d.ts +34 -0
  98. package/build/bridge/handlers/catalog-bridge.d.ts.map +1 -0
  99. package/build/bridge/handlers/catalog-bridge.js +58 -0
  100. package/build/bridge/handlers/catalog-bridge.js.map +1 -0
  101. package/build/bridge/handlers/history-bridge.d.ts +19 -0
  102. package/build/bridge/handlers/history-bridge.d.ts.map +1 -0
  103. package/build/bridge/handlers/history-bridge.js +31 -0
  104. package/build/bridge/handlers/history-bridge.js.map +1 -0
  105. package/build/bridge/handlers/index.d.ts +124 -0
  106. package/build/bridge/handlers/index.d.ts.map +1 -0
  107. package/build/bridge/handlers/index.js +21 -0
  108. package/build/bridge/handlers/index.js.map +1 -0
  109. package/build/bridge/handlers/library-bridge.d.ts +23 -0
  110. package/build/bridge/handlers/library-bridge.d.ts.map +1 -0
  111. package/build/bridge/handlers/library-bridge.js +41 -0
  112. package/build/bridge/handlers/library-bridge.js.map +1 -0
  113. package/build/bridge/handlers/library-mutations-bridge.d.ts +16 -0
  114. package/build/bridge/handlers/library-mutations-bridge.d.ts.map +1 -0
  115. package/build/bridge/handlers/library-mutations-bridge.js +20 -0
  116. package/build/bridge/handlers/library-mutations-bridge.js.map +1 -0
  117. package/build/bridge/handlers/player-bridge.d.ts +18 -0
  118. package/build/bridge/handlers/player-bridge.d.ts.map +1 -0
  119. package/build/bridge/handlers/player-bridge.js +42 -0
  120. package/build/bridge/handlers/player-bridge.js.map +1 -0
  121. package/build/bridge/handlers/ratings-bridge.d.ts +15 -0
  122. package/build/bridge/handlers/ratings-bridge.d.ts.map +1 -0
  123. package/build/bridge/handlers/ratings-bridge.js +16 -0
  124. package/build/bridge/handlers/ratings-bridge.js.map +1 -0
  125. package/build/bridge/handlers/recommendations-bridge.d.ts +10 -0
  126. package/build/bridge/handlers/recommendations-bridge.d.ts.map +1 -0
  127. package/build/bridge/handlers/recommendations-bridge.js +14 -0
  128. package/build/bridge/handlers/recommendations-bridge.js.map +1 -0
  129. package/build/constants/apple-music-error-codes.d.ts +22 -0
  130. package/build/constants/apple-music-error-codes.d.ts.map +1 -0
  131. package/build/constants/apple-music-error-codes.js +21 -0
  132. package/build/constants/apple-music-error-codes.js.map +1 -0
  133. package/build/hooks/use-current-song.d.ts +10 -0
  134. package/build/hooks/use-current-song.d.ts.map +1 -0
  135. package/build/hooks/use-current-song.js +35 -0
  136. package/build/hooks/use-current-song.js.map +1 -0
  137. package/build/hooks/use-is-playing.d.ts +6 -0
  138. package/build/hooks/use-is-playing.d.ts.map +1 -0
  139. package/build/hooks/use-is-playing.js +21 -0
  140. package/build/hooks/use-is-playing.js.map +1 -0
  141. package/build/hooks/use-playback-state.d.ts +12 -0
  142. package/build/hooks/use-playback-state.d.ts.map +1 -0
  143. package/build/hooks/use-playback-state.js +41 -0
  144. package/build/hooks/use-playback-state.js.map +1 -0
  145. package/build/index.d.ts +52 -0
  146. package/build/index.d.ts.map +1 -0
  147. package/build/index.js +44 -0
  148. package/build/index.js.map +1 -0
  149. package/build/mappers/apple-music-json-mapper.d.ts +94 -0
  150. package/build/mappers/apple-music-json-mapper.d.ts.map +1 -0
  151. package/build/mappers/apple-music-json-mapper.js +212 -0
  152. package/build/mappers/apple-music-json-mapper.js.map +1 -0
  153. package/build/modules/auth.d.ts +32 -0
  154. package/build/modules/auth.d.ts.map +1 -0
  155. package/build/modules/auth.js +60 -0
  156. package/build/modules/auth.js.map +1 -0
  157. package/build/modules/catalog.d.ts +46 -0
  158. package/build/modules/catalog.d.ts.map +1 -0
  159. package/build/modules/catalog.js +47 -0
  160. package/build/modules/catalog.js.map +1 -0
  161. package/build/modules/history.d.ts +17 -0
  162. package/build/modules/history.d.ts.map +1 -0
  163. package/build/modules/history.js +28 -0
  164. package/build/modules/history.js.map +1 -0
  165. package/build/modules/library-mutations.d.ts +9 -0
  166. package/build/modules/library-mutations.d.ts.map +1 -0
  167. package/build/modules/library-mutations.js +41 -0
  168. package/build/modules/library-mutations.js.map +1 -0
  169. package/build/modules/library.d.ts +21 -0
  170. package/build/modules/library.d.ts.map +1 -0
  171. package/build/modules/library.js +38 -0
  172. package/build/modules/library.js.map +1 -0
  173. package/build/modules/player.d.ts +53 -0
  174. package/build/modules/player.d.ts.map +1 -0
  175. package/build/modules/player.js +68 -0
  176. package/build/modules/player.js.map +1 -0
  177. package/build/modules/ratings.d.ts +10 -0
  178. package/build/modules/ratings.d.ts.map +1 -0
  179. package/build/modules/ratings.js +37 -0
  180. package/build/modules/ratings.js.map +1 -0
  181. package/build/modules/recommendations.d.ts +7 -0
  182. package/build/modules/recommendations.d.ts.map +1 -0
  183. package/build/modules/recommendations.js +15 -0
  184. package/build/modules/recommendations.js.map +1 -0
  185. package/build/native-module.d.ts +5 -0
  186. package/build/native-module.d.ts.map +1 -0
  187. package/build/native-module.js +5 -0
  188. package/build/native-module.js.map +1 -0
  189. package/build/native-module.web.d.ts +11 -0
  190. package/build/native-module.web.d.ts.map +1 -0
  191. package/build/native-module.web.js +11 -0
  192. package/build/native-module.web.js.map +1 -0
  193. package/build/rest/apple-music-rest-stack.d.ts +21 -0
  194. package/build/rest/apple-music-rest-stack.d.ts.map +1 -0
  195. package/build/rest/apple-music-rest-stack.js +21 -0
  196. package/build/rest/apple-music-rest-stack.js.map +1 -0
  197. package/build/rest/apple-music-rest-transport.d.ts +8 -0
  198. package/build/rest/apple-music-rest-transport.d.ts.map +1 -0
  199. package/build/rest/apple-music-rest-transport.js +2 -0
  200. package/build/rest/apple-music-rest-transport.js.map +1 -0
  201. package/build/rest/catalog-rest-client.d.ts +38 -0
  202. package/build/rest/catalog-rest-client.d.ts.map +1 -0
  203. package/build/rest/catalog-rest-client.js +189 -0
  204. package/build/rest/catalog-rest-client.js.map +1 -0
  205. package/build/rest/history-rest-client.d.ts +37 -0
  206. package/build/rest/history-rest-client.d.ts.map +1 -0
  207. package/build/rest/history-rest-client.js +30 -0
  208. package/build/rest/history-rest-client.js.map +1 -0
  209. package/build/rest/library-ids.d.ts +2 -0
  210. package/build/rest/library-ids.d.ts.map +1 -0
  211. package/build/rest/library-ids.js +2 -0
  212. package/build/rest/library-ids.js.map +1 -0
  213. package/build/rest/library-mutations-rest-client.d.ts +22 -0
  214. package/build/rest/library-mutations-rest-client.d.ts.map +1 -0
  215. package/build/rest/library-mutations-rest-client.js +37 -0
  216. package/build/rest/library-mutations-rest-client.js.map +1 -0
  217. package/build/rest/library-rest-client.d.ts +59 -0
  218. package/build/rest/library-rest-client.d.ts.map +1 -0
  219. package/build/rest/library-rest-client.js +141 -0
  220. package/build/rest/library-rest-client.js.map +1 -0
  221. package/build/rest/ratings-rest-client.d.ts +18 -0
  222. package/build/rest/ratings-rest-client.d.ts.map +1 -0
  223. package/build/rest/ratings-rest-client.js +37 -0
  224. package/build/rest/ratings-rest-client.js.map +1 -0
  225. package/build/rest/recommendations-rest-client.d.ts +32 -0
  226. package/build/rest/recommendations-rest-client.d.ts.map +1 -0
  227. package/build/rest/recommendations-rest-client.js +26 -0
  228. package/build/rest/recommendations-rest-client.js.map +1 -0
  229. package/build/rest/resource-ids-query.d.ts +2 -0
  230. package/build/rest/resource-ids-query.d.ts.map +1 -0
  231. package/build/rest/resource-ids-query.js +10 -0
  232. package/build/rest/resource-ids-query.js.map +1 -0
  233. package/build/rest/rest-json.d.ts +11 -0
  234. package/build/rest/rest-json.d.ts.map +1 -0
  235. package/build/rest/rest-json.js +29 -0
  236. package/build/rest/rest-json.js.map +1 -0
  237. package/build/rest/storefront-rest-client.d.ts +14 -0
  238. package/build/rest/storefront-rest-client.d.ts.map +1 -0
  239. package/build/rest/storefront-rest-client.js +36 -0
  240. package/build/rest/storefront-rest-client.js.map +1 -0
  241. package/build/types/album.d.ts +8 -0
  242. package/build/types/album.d.ts.map +1 -0
  243. package/build/types/album.js +2 -0
  244. package/build/types/album.js.map +1 -0
  245. package/build/types/albums-response.d.ts +5 -0
  246. package/build/types/albums-response.d.ts.map +1 -0
  247. package/build/types/albums-response.js +2 -0
  248. package/build/types/albums-response.js.map +1 -0
  249. package/build/types/android-authorize-options.d.ts +18 -0
  250. package/build/types/android-authorize-options.d.ts.map +1 -0
  251. package/build/types/android-authorize-options.js +2 -0
  252. package/build/types/android-authorize-options.js.map +1 -0
  253. package/build/types/artist.d.ts +9 -0
  254. package/build/types/artist.d.ts.map +1 -0
  255. package/build/types/artist.js +2 -0
  256. package/build/types/artist.js.map +1 -0
  257. package/build/types/auth-status.d.ts +19 -0
  258. package/build/types/auth-status.d.ts.map +1 -0
  259. package/build/types/auth-status.js +18 -0
  260. package/build/types/auth-status.js.map +1 -0
  261. package/build/types/authorize-result.d.ts +8 -0
  262. package/build/types/authorize-result.d.ts.map +1 -0
  263. package/build/types/authorize-result.js +2 -0
  264. package/build/types/authorize-result.js.map +1 -0
  265. package/build/types/catalog-album-tracks.d.ts +5 -0
  266. package/build/types/catalog-album-tracks.d.ts.map +1 -0
  267. package/build/types/catalog-album-tracks.js +2 -0
  268. package/build/types/catalog-album-tracks.js.map +1 -0
  269. package/build/types/catalog-charts.d.ts +25 -0
  270. package/build/types/catalog-charts.d.ts.map +1 -0
  271. package/build/types/catalog-charts.js +7 -0
  272. package/build/types/catalog-charts.js.map +1 -0
  273. package/build/types/catalog-resource-type.d.ts +11 -0
  274. package/build/types/catalog-resource-type.d.ts.map +1 -0
  275. package/build/types/catalog-resource-type.js +10 -0
  276. package/build/types/catalog-resource-type.js.map +1 -0
  277. package/build/types/catalog-search.d.ts +24 -0
  278. package/build/types/catalog-search.d.ts.map +1 -0
  279. package/build/types/catalog-search.js +9 -0
  280. package/build/types/catalog-search.js.map +1 -0
  281. package/build/types/check-subscription.d.ts +31 -0
  282. package/build/types/check-subscription.d.ts.map +1 -0
  283. package/build/types/check-subscription.js +5 -0
  284. package/build/types/check-subscription.js.map +1 -0
  285. package/build/types/library-music-videos.d.ts +5 -0
  286. package/build/types/library-music-videos.d.ts.map +1 -0
  287. package/build/types/library-music-videos.js +2 -0
  288. package/build/types/library-music-videos.js.map +1 -0
  289. package/build/types/library-mutations.d.ts +21 -0
  290. package/build/types/library-mutations.d.ts.map +1 -0
  291. package/build/types/library-mutations.js +8 -0
  292. package/build/types/library-mutations.js.map +1 -0
  293. package/build/types/library-search.d.ts +22 -0
  294. package/build/types/library-search.d.ts.map +1 -0
  295. package/build/types/library-search.js +9 -0
  296. package/build/types/library-search.js.map +1 -0
  297. package/build/types/music-item.d.ts +8 -0
  298. package/build/types/music-item.d.ts.map +1 -0
  299. package/build/types/music-item.js +7 -0
  300. package/build/types/music-item.js.map +1 -0
  301. package/build/types/music-video.d.ts +8 -0
  302. package/build/types/music-video.d.ts.map +1 -0
  303. package/build/types/music-video.js +2 -0
  304. package/build/types/music-video.js.map +1 -0
  305. package/build/types/pagination.d.ts +11 -0
  306. package/build/types/pagination.d.ts.map +1 -0
  307. package/build/types/pagination.js +2 -0
  308. package/build/types/pagination.js.map +1 -0
  309. package/build/types/playback-state.d.ts +9 -0
  310. package/build/types/playback-state.d.ts.map +1 -0
  311. package/build/types/playback-state.js +2 -0
  312. package/build/types/playback-state.js.map +1 -0
  313. package/build/types/playback-status.d.ts +10 -0
  314. package/build/types/playback-status.d.ts.map +1 -0
  315. package/build/types/playback-status.js +9 -0
  316. package/build/types/playback-status.js.map +1 -0
  317. package/build/types/playlist.d.ts +15 -0
  318. package/build/types/playlist.d.ts.map +1 -0
  319. package/build/types/playlist.js +2 -0
  320. package/build/types/playlist.js.map +1 -0
  321. package/build/types/rating.d.ts +34 -0
  322. package/build/types/rating.d.ts.map +1 -0
  323. package/build/types/rating.js +26 -0
  324. package/build/types/rating.js.map +1 -0
  325. package/build/types/recent-resource.d.ts +11 -0
  326. package/build/types/recent-resource.d.ts.map +1 -0
  327. package/build/types/recent-resource.js +2 -0
  328. package/build/types/recent-resource.js.map +1 -0
  329. package/build/types/recommendation.d.ts +37 -0
  330. package/build/types/recommendation.d.ts.map +1 -0
  331. package/build/types/recommendation.js +2 -0
  332. package/build/types/recommendation.js.map +1 -0
  333. package/build/types/song.d.ts +8 -0
  334. package/build/types/song.d.ts.map +1 -0
  335. package/build/types/song.js +2 -0
  336. package/build/types/song.js.map +1 -0
  337. package/build/types/station.d.ts +9 -0
  338. package/build/types/station.d.ts.map +1 -0
  339. package/build/types/station.js +2 -0
  340. package/build/types/station.js.map +1 -0
  341. package/build/types/storefront.d.ts +4 -0
  342. package/build/types/storefront.d.ts.map +1 -0
  343. package/build/types/storefront.js +2 -0
  344. package/build/types/storefront.js.map +1 -0
  345. package/build/types/tracks-from-library.d.ts +11 -0
  346. package/build/types/tracks-from-library.d.ts.map +1 -0
  347. package/build/types/tracks-from-library.js +2 -0
  348. package/build/types/tracks-from-library.js.map +1 -0
  349. package/build/utils/apple-music-error.d.ts +10 -0
  350. package/build/utils/apple-music-error.d.ts.map +1 -0
  351. package/build/utils/apple-music-error.js +13 -0
  352. package/build/utils/apple-music-error.js.map +1 -0
  353. package/build/utils/get-error-message.d.ts +2 -0
  354. package/build/utils/get-error-message.d.ts.map +1 -0
  355. package/build/utils/get-error-message.js +21 -0
  356. package/build/utils/get-error-message.js.map +1 -0
  357. package/build/utils/is-library-item.d.ts +2 -0
  358. package/build/utils/is-library-item.d.ts.map +1 -0
  359. package/build/utils/is-library-item.js +4 -0
  360. package/build/utils/is-library-item.js.map +1 -0
  361. package/build/utils/normalize-resource-ids.d.ts +4 -0
  362. package/build/utils/normalize-resource-ids.d.ts.map +1 -0
  363. package/build/utils/normalize-resource-ids.js +12 -0
  364. package/build/utils/normalize-resource-ids.js.map +1 -0
  365. package/build/web/MusicKitLoader.d.ts +11 -0
  366. package/build/web/MusicKitLoader.d.ts.map +1 -0
  367. package/build/web/MusicKitLoader.js +135 -0
  368. package/build/web/MusicKitLoader.js.map +1 -0
  369. package/build/web/WebAppleMusicApiClient.d.ts +151 -0
  370. package/build/web/WebAppleMusicApiClient.d.ts.map +1 -0
  371. package/build/web/WebAppleMusicApiClient.js +139 -0
  372. package/build/web/WebAppleMusicApiClient.js.map +1 -0
  373. package/build/web/WebAppleMusicRestTransport.d.ts +9 -0
  374. package/build/web/WebAppleMusicRestTransport.d.ts.map +1 -0
  375. package/build/web/WebAppleMusicRestTransport.js +31 -0
  376. package/build/web/WebAppleMusicRestTransport.js.map +1 -0
  377. package/build/web/WebPlaybackController.d.ts +12 -0
  378. package/build/web/WebPlaybackController.d.ts.map +1 -0
  379. package/build/web/WebPlaybackController.js +90 -0
  380. package/build/web/WebPlaybackController.js.map +1 -0
  381. package/build/web/WebPlaybackObserver.d.ts +22 -0
  382. package/build/web/WebPlaybackObserver.d.ts.map +1 -0
  383. package/build/web/WebPlaybackObserver.js +106 -0
  384. package/build/web/WebPlaybackObserver.js.map +1 -0
  385. package/build/web/WebQueueService.d.ts +10 -0
  386. package/build/web/WebQueueService.d.ts.map +1 -0
  387. package/build/web/WebQueueService.js +53 -0
  388. package/build/web/WebQueueService.js.map +1 -0
  389. package/build/web/WebSubscriptionService.d.ts +7 -0
  390. package/build/web/WebSubscriptionService.d.ts.map +1 -0
  391. package/build/web/WebSubscriptionService.js +24 -0
  392. package/build/web/WebSubscriptionService.js.map +1 -0
  393. package/build/web/apple-music-errors.d.ts +11 -0
  394. package/build/web/apple-music-errors.d.ts.map +1 -0
  395. package/build/web/apple-music-errors.js +31 -0
  396. package/build/web/apple-music-errors.js.map +1 -0
  397. package/build/web/extract-music-user-token.d.ts +4 -0
  398. package/build/web/extract-music-user-token.d.ts.map +1 -0
  399. package/build/web/extract-music-user-token.js +15 -0
  400. package/build/web/extract-music-user-token.js.map +1 -0
  401. package/build/web/map-auth-status.d.ts +17 -0
  402. package/build/web/map-auth-status.d.ts.map +1 -0
  403. package/build/web/map-auth-status.js +85 -0
  404. package/build/web/map-auth-status.js.map +1 -0
  405. package/build/web/music-kit-api.d.ts +18 -0
  406. package/build/web/music-kit-api.d.ts.map +1 -0
  407. package/build/web/music-kit-api.js +120 -0
  408. package/build/web/music-kit-api.js.map +1 -0
  409. package/build/web/musickit-types.d.ts +70 -0
  410. package/build/web/musickit-types.d.ts.map +1 -0
  411. package/build/web/musickit-types.js +3 -0
  412. package/build/web/musickit-types.js.map +1 -0
  413. package/build/web/pagination.d.ts +2 -0
  414. package/build/web/pagination.d.ts.map +1 -0
  415. package/build/web/pagination.js +2 -0
  416. package/build/web/pagination.js.map +1 -0
  417. package/expo-module.config.json +19 -0
  418. package/ios/AppleMusicBridgeError.swift +60 -0
  419. package/ios/AppleMusicErrorCodes.swift +11 -0
  420. package/ios/AppleMusicRestClient.swift +213 -0
  421. package/ios/AuthenticatedSession.swift +64 -0
  422. package/ios/BridgePagination.swift +17 -0
  423. package/ios/BridgeResponses.swift +82 -0
  424. package/ios/CatalogSearchStore.swift +13 -0
  425. package/ios/CatalogSearchStoreFactory.swift +31 -0
  426. package/ios/CatalogService.swift +307 -0
  427. package/ios/ExpoAppleMusic.podspec +29 -0
  428. package/ios/ExpoAppleMusicModule.swift +505 -0
  429. package/ios/HistoryService.swift +53 -0
  430. package/ios/LibraryMutationsService.swift +63 -0
  431. package/ios/LibraryService.swift +313 -0
  432. package/ios/MusicItemMapper.swift +171 -0
  433. package/ios/MusicKitAuthStorage.swift +38 -0
  434. package/ios/MusicKitCatalogSearchStore.swift +62 -0
  435. package/ios/PlaybackController.swift +201 -0
  436. package/ios/PlaybackObserver.swift +225 -0
  437. package/ios/QueueService.swift +166 -0
  438. package/ios/RatingsService.swift +66 -0
  439. package/ios/RecommendationsService.swift +34 -0
  440. package/ios/RestCatalogSearchStore.swift +62 -0
  441. package/ios/RestJsonMapper.swift +268 -0
  442. package/ios/StorefrontService.swift +55 -0
  443. package/ios/SubscriptionService.swift +119 -0
  444. package/ios/bridge/ExpoBridgeCatalog.swift +98 -0
  445. package/ios/bridge/ExpoBridgeHistory.swift +71 -0
  446. package/ios/bridge/ExpoBridgeLibrary.swift +93 -0
  447. package/ios/bridge/ExpoBridgeRecommendations.swift +28 -0
  448. package/package.json +89 -0
  449. package/plugin/build/index.d.ts +5 -0
  450. package/plugin/build/index.js +10 -0
  451. package/plugin/build/with-expo-apple-music.d.ts +10 -0
  452. package/plugin/build/with-expo-apple-music.js +50 -0
@@ -0,0 +1,60 @@
1
+ package expo.modules.applemusic
2
+
3
+ import kotlinx.coroutines.Dispatchers
4
+ import kotlinx.coroutines.withContext
5
+
6
+ /** History-domain Apple Music REST (recently played, heavy rotation). */
7
+ internal class HistoryRestClient(
8
+ private val transport: AppleMusicRestTransport,
9
+ ) {
10
+ suspend fun getRecentlyPlayed(musicUserToken: String): List<Map<String, Any?>> =
11
+ withContext(Dispatchers.IO) {
12
+ val json =
13
+ transport.getJson(musicUserToken, "/v1/me/recent/played", mapOf("limit" to "10"))
14
+ mapTopLevelResourceArray(json) { AppleMusicJsonMapper.mapRecentlyPlayed(it) }
15
+ }
16
+
17
+ suspend fun getRecentlyPlayedTracks(musicUserToken: String, limit: Int): List<Map<String, Any?>> =
18
+ withContext(Dispatchers.IO) {
19
+ val json =
20
+ transport.getJson(
21
+ musicUserToken,
22
+ "/v1/me/recent/played/tracks",
23
+ mapOf("limit" to limit.toString()),
24
+ )
25
+ mapTopLevelResourceArray(json) { AppleMusicJsonMapper.mapSong(it) }
26
+ }
27
+
28
+ suspend fun getHeavyRotation(musicUserToken: String, limit: Int): List<Map<String, Any?>> =
29
+ withContext(Dispatchers.IO) {
30
+ val json =
31
+ transport.getJson(
32
+ musicUserToken,
33
+ "/v1/me/history/heavy-rotation",
34
+ mapOf("limit" to limit.toString()),
35
+ )
36
+ mapTopLevelResourceArray(json) { AppleMusicJsonMapper.mapRecentResource(it) }
37
+ }
38
+
39
+ suspend fun getRecentlyPlayedStations(musicUserToken: String, limit: Int): List<Map<String, Any?>> =
40
+ withContext(Dispatchers.IO) {
41
+ val json =
42
+ transport.getJson(
43
+ musicUserToken,
44
+ "/v1/me/recent/radio-stations",
45
+ mapOf("limit" to limit.toString()),
46
+ )
47
+ mapTopLevelResourceArray(json) { AppleMusicJsonMapper.mapStation(it) }
48
+ }
49
+
50
+ suspend fun getRecentlyAdded(musicUserToken: String, limit: Int, offset: Int): List<Map<String, Any?>> =
51
+ withContext(Dispatchers.IO) {
52
+ val json =
53
+ transport.getJson(
54
+ musicUserToken,
55
+ "/v1/me/library/recently-added",
56
+ mapOf("limit" to limit.toString(), "offset" to offset.toString()),
57
+ )
58
+ mapTopLevelResourceArray(json) { AppleMusicJsonMapper.mapRecentResource(it) }
59
+ }
60
+ }
@@ -0,0 +1,6 @@
1
+ package expo.modules.applemusic
2
+
3
+ internal object LibraryIds {
4
+ fun isLibraryId(itemId: String): Boolean =
5
+ itemId.startsWith("l.") || itemId.startsWith("i.") || itemId.startsWith("p.")
6
+ }
@@ -0,0 +1,95 @@
1
+ package expo.modules.applemusic
2
+
3
+ import kotlinx.coroutines.Dispatchers
4
+ import kotlinx.coroutines.withContext
5
+ import org.json.JSONArray
6
+ import org.json.JSONObject
7
+
8
+ /** Library write/mutation Apple Music REST. */
9
+ internal class LibraryMutationsRestClient(
10
+ private val transport: AppleMusicRestTransport,
11
+ ) {
12
+ suspend fun addToLibrary(musicUserToken: String, resourceIds: Map<String, List<String>>): Unit =
13
+ withContext(Dispatchers.IO) {
14
+ transport.request(
15
+ musicUserToken,
16
+ AppleMusicHttpMethod.POST,
17
+ "/v1/me/library",
18
+ query = buildIdsQuery(resourceIds),
19
+ )
20
+ }
21
+
22
+ suspend fun createLibraryPlaylist(
23
+ musicUserToken: String,
24
+ name: String,
25
+ description: String?,
26
+ isPublic: Boolean,
27
+ tracks: List<Map<String, String>>?,
28
+ ): Map<String, Any?> =
29
+ withContext(Dispatchers.IO) {
30
+ val attributes =
31
+ JSONObject()
32
+ .put("name", name)
33
+ .put("isPublic", isPublic)
34
+ if (!description.isNullOrBlank()) {
35
+ attributes.put(
36
+ "description",
37
+ JSONObject().put("standard", description),
38
+ )
39
+ }
40
+
41
+ val payload = JSONObject().put("attributes", attributes)
42
+ if (!tracks.isNullOrEmpty()) {
43
+ val trackData = JSONArray()
44
+ tracks.forEach { track ->
45
+ trackData.put(
46
+ JSONObject()
47
+ .put("id", track["id"])
48
+ .put("type", track["type"]),
49
+ )
50
+ }
51
+ payload.put(
52
+ "relationships",
53
+ JSONObject().put(
54
+ "tracks",
55
+ JSONObject().put("data", trackData),
56
+ ),
57
+ )
58
+ }
59
+
60
+ val json =
61
+ transport.request(
62
+ musicUserToken,
63
+ AppleMusicHttpMethod.POST,
64
+ "/v1/me/library/playlists",
65
+ body = payload,
66
+ )
67
+ val data = requireDataArray(json)
68
+ if (data.length() == 0) {
69
+ throw AppleMusicErrors.apiError("Create playlist returned no data")
70
+ }
71
+ AppleMusicJsonMapper.mapPlaylist(data.getJSONObject(0))
72
+ }
73
+
74
+ suspend fun addTracksToLibraryPlaylist(
75
+ musicUserToken: String,
76
+ playlistId: String,
77
+ tracks: List<Map<String, String>>,
78
+ ): Unit =
79
+ withContext(Dispatchers.IO) {
80
+ val trackData = JSONArray()
81
+ tracks.forEach { track ->
82
+ trackData.put(
83
+ JSONObject()
84
+ .put("id", track["id"])
85
+ .put("type", track["type"]),
86
+ )
87
+ }
88
+ transport.request(
89
+ musicUserToken,
90
+ AppleMusicHttpMethod.POST,
91
+ "/v1/me/library/playlists/$playlistId/tracks",
92
+ body = JSONObject().put("data", trackData),
93
+ )
94
+ }
95
+ }
@@ -0,0 +1,195 @@
1
+ package expo.modules.applemusic
2
+
3
+ import kotlinx.coroutines.Dispatchers
4
+ import kotlinx.coroutines.withContext
5
+ import org.json.JSONArray
6
+ import org.json.JSONObject
7
+
8
+ /** Library-domain Apple Music REST (user collection reads + playback id resolution). */
9
+ internal class LibraryRestClient(
10
+ private val transport: AppleMusicRestTransport,
11
+ ) {
12
+ suspend fun getLibraryPlaylists(musicUserToken: String, limit: Int, offset: Int): List<Map<String, Any?>> =
13
+ withContext(Dispatchers.IO) {
14
+ val json =
15
+ transport.getJson(
16
+ musicUserToken,
17
+ "/v1/me/library/playlists",
18
+ mapOf("limit" to limit.toString(), "offset" to offset.toString()),
19
+ )
20
+ mapTopLevelResourceArray(json) { AppleMusicJsonMapper.mapPlaylist(it) }
21
+ }
22
+
23
+ suspend fun getLibrarySongs(musicUserToken: String, limit: Int, offset: Int): List<Map<String, Any?>> =
24
+ withContext(Dispatchers.IO) {
25
+ val json =
26
+ transport.getJson(
27
+ musicUserToken,
28
+ "/v1/me/library/songs",
29
+ mapOf("limit" to limit.toString(), "offset" to offset.toString()),
30
+ )
31
+ mapTopLevelResourceArray(json) { AppleMusicJsonMapper.mapSong(it) }
32
+ }
33
+
34
+ suspend fun getPlaylistTracks(musicUserToken: String, playlistId: String): List<Map<String, Any?>> =
35
+ withContext(Dispatchers.IO) {
36
+ val json = transport.getJson(
37
+ musicUserToken,
38
+ "/v1/me/library/playlists/$playlistId/tracks")
39
+ val data = requireDataArray(json)
40
+ buildList {
41
+ for (i in 0 until data.length()) {
42
+ val resource = data.getJSONObject(i)
43
+ if (resource.optString("type", "").contains("song")) {
44
+ add(AppleMusicJsonMapper.mapSong(resource))
45
+ }
46
+ }
47
+ }
48
+ }
49
+
50
+ private fun librarySearchTypeParam(type: String): String? =
51
+ when (type) {
52
+ "library-songs", "songs" -> "library-songs"
53
+ "library-albums", "albums" -> "library-albums"
54
+ "library-artists", "artists" -> "library-artists"
55
+ "library-playlists", "playlists" -> "library-playlists"
56
+ "library-music-videos", "music-videos", "musicVideos" -> "library-music-videos"
57
+ else -> null
58
+ }
59
+
60
+ suspend fun getLibraryArtists(musicUserToken: String, limit: Int, offset: Int): List<Map<String, Any?>> =
61
+ withContext(Dispatchers.IO) {
62
+ val json =
63
+ transport.getJson(
64
+ musicUserToken,
65
+ "/v1/me/library/artists",
66
+ mapOf("limit" to limit.toString(), "offset" to offset.toString()),
67
+ )
68
+ mapTopLevelResourceArray(json) { AppleMusicJsonMapper.mapArtist(it) }
69
+ }
70
+
71
+ suspend fun getLibraryAlbums(musicUserToken: String, limit: Int, offset: Int): List<Map<String, Any?>> =
72
+ withContext(Dispatchers.IO) {
73
+ val json =
74
+ transport.getJson(
75
+ musicUserToken,
76
+ "/v1/me/library/albums",
77
+ mapOf("limit" to limit.toString(), "offset" to offset.toString()),
78
+ )
79
+ mapTopLevelResourceArray(json) { AppleMusicJsonMapper.mapAlbum(it) }
80
+ }
81
+
82
+ data class LibrarySearchResult(
83
+ val songs: List<Map<String, Any?>>,
84
+ val albums: List<Map<String, Any?>>,
85
+ val artists: List<Map<String, Any?>>,
86
+ val playlists: List<Map<String, Any?>>,
87
+ val musicVideos: List<Map<String, Any?>>,
88
+ )
89
+
90
+ suspend fun getLibraryMusicVideos(musicUserToken: String, limit: Int, offset: Int): List<Map<String, Any?>> =
91
+ withContext(Dispatchers.IO) {
92
+ val json =
93
+ transport.getJson(
94
+ musicUserToken,
95
+ "/v1/me/library/music-videos",
96
+ mapOf("limit" to limit.toString(), "offset" to offset.toString()),
97
+ )
98
+ mapTopLevelResourceArray(json) { AppleMusicJsonMapper.mapMusicVideo(it) }
99
+ }
100
+
101
+ suspend fun searchLibrary(
102
+ musicUserToken: String,
103
+ term: String,
104
+ types: List<String>,
105
+ limit: Int,
106
+ offset: Int,
107
+ ): LibrarySearchResult =
108
+ withContext(Dispatchers.IO) {
109
+ val typeParam =
110
+ types
111
+ .mapNotNull { librarySearchTypeParam(it) }
112
+ .distinct()
113
+ .sorted()
114
+ .joinToString(",")
115
+ .ifEmpty { "library-songs,library-albums" }
116
+
117
+ val json =
118
+ transport.getJson(
119
+ musicUserToken,
120
+ "/v1/me/library/search",
121
+ mapOf(
122
+ "term" to term,
123
+ "types" to typeParam,
124
+ "limit" to limit.toString(),
125
+ "offset" to offset.toString(),
126
+ ),
127
+ )
128
+
129
+ val results = json.optJSONObject("results") ?: JSONObject()
130
+ LibrarySearchResult(
131
+ songs =
132
+ mapResourceArray(results.optJSONObject("library-songs")?.optJSONArray("data")) {
133
+ AppleMusicJsonMapper.mapSong(it)
134
+ },
135
+ albums =
136
+ mapResourceArray(results.optJSONObject("library-albums")?.optJSONArray("data")) {
137
+ AppleMusicJsonMapper.mapAlbum(it)
138
+ },
139
+ artists =
140
+ mapResourceArray(results.optJSONObject("library-artists")?.optJSONArray("data")) {
141
+ AppleMusicJsonMapper.mapArtist(it)
142
+ },
143
+ playlists =
144
+ mapResourceArray(results.optJSONObject("library-playlists")?.optJSONArray("data")) {
145
+ AppleMusicJsonMapper.mapPlaylist(it)
146
+ },
147
+ musicVideos =
148
+ mapResourceArray(results.optJSONObject("library-music-videos")?.optJSONArray("data")) {
149
+ AppleMusicJsonMapper.mapMusicVideo(it)
150
+ },
151
+ )
152
+ }
153
+
154
+ suspend fun probeLibraryAccess(musicUserToken: String): Boolean =
155
+ withContext(Dispatchers.IO) {
156
+ try {
157
+ transport.getJson(
158
+ musicUserToken,
159
+ "/v1/me/library/songs", mapOf("limit" to "1"))
160
+ true
161
+ } catch (_: Exception) {
162
+ false
163
+ }
164
+ }
165
+
166
+ suspend fun resolveCatalogPlaybackId(musicUserToken: String, libraryId: String, mediaType: String): String =
167
+ withContext(Dispatchers.IO) {
168
+ val path =
169
+ when (mediaType) {
170
+ "song" -> "/v1/me/library/songs/$libraryId"
171
+ "album" -> "/v1/me/library/albums/$libraryId"
172
+ "playlist" -> "/v1/me/library/playlists/$libraryId"
173
+ else -> throw AppleMusicErrors.unknownMediaType(mediaType)
174
+ }
175
+ val json = transport.getJson(musicUserToken, path)
176
+ val resource = json.getJSONArray("data").getJSONObject(0)
177
+ AppleMusicJsonMapper.catalogPlaybackId(resource)
178
+ ?: throw AppleMusicErrors.itemNotFound(mediaType.replaceFirstChar { it.uppercase() }, true)
179
+ }
180
+
181
+ suspend fun resolveLibrarySongCatalogIds(musicUserToken: String, playlistId: String): List<String> =
182
+ withContext(Dispatchers.IO) {
183
+ val json = transport.getJson(
184
+ musicUserToken,
185
+ "/v1/me/library/playlists/$playlistId/tracks")
186
+ val data = requireDataArray(json)
187
+ buildList {
188
+ for (i in 0 until data.length()) {
189
+ val resource = data.getJSONObject(i)
190
+ if (!resource.optString("type", "").contains("song")) continue
191
+ AppleMusicJsonMapper.catalogPlaybackId(resource)?.let { add(it) }
192
+ }
193
+ }
194
+ }
195
+ }
@@ -0,0 +1,78 @@
1
+ package expo.modules.applemusic
2
+
3
+ import android.app.Activity
4
+ import android.content.Context
5
+ import android.content.Intent
6
+ import com.apple.android.sdk.authentication.AuthenticationFactory
7
+ import com.apple.android.sdk.authentication.TokenError
8
+ import com.apple.android.sdk.authentication.TokenResult
9
+ import expo.modules.kotlin.activityresult.AppContextActivityResultContract
10
+ import java.io.Serializable
11
+
12
+ internal data class MusicKitAuthInput(
13
+ val developerToken: String,
14
+ val startScreenMessage: String? = null,
15
+ val hideStartScreen: Boolean = false,
16
+ ) : Serializable
17
+
18
+ internal data class MusicKitAuthOutput(
19
+ val status: String,
20
+ val musicUserToken: String? = null,
21
+ ) : Serializable
22
+
23
+ internal class MusicKitAuthContract(
24
+ private val contextProvider: () -> Context,
25
+ ) : AppContextActivityResultContract<MusicKitAuthInput, MusicKitAuthOutput> {
26
+ override fun createIntent(context: Context, input: MusicKitAuthInput): Intent {
27
+ val manager = AuthenticationFactory.createAuthenticationManager(context)
28
+ val builder =
29
+ manager
30
+ .createIntentBuilder(input.developerToken)
31
+ .setHideStartScreen(input.hideStartScreen)
32
+
33
+ if (!input.hideStartScreen) {
34
+ val message = input.startScreenMessage?.trim()
35
+ if (!message.isNullOrEmpty()) {
36
+ builder.setStartScreenMessage(message)
37
+ }
38
+ }
39
+
40
+ return builder.build()
41
+ }
42
+
43
+ override fun parseResult(
44
+ input: MusicKitAuthInput,
45
+ resultCode: Int,
46
+ intent: Intent?,
47
+ ): MusicKitAuthOutput {
48
+ // SDK cancel paths: upsell X (USER_CANCELLED intent), Apple Music back (no intent / empty token).
49
+ if (intent == null) {
50
+ return MusicKitAuthOutput(status = "denied")
51
+ }
52
+
53
+ val manager = AuthenticationFactory.createAuthenticationManager(contextProvider())
54
+ return mapTokenResult(manager.handleTokenResult(intent))
55
+ }
56
+
57
+ private fun mapTokenResult(result: TokenResult): MusicKitAuthOutput {
58
+ if (result.isError) {
59
+ val status =
60
+ when (result.error) {
61
+ TokenError.USER_CANCELLED -> "denied"
62
+ TokenError.NO_SUBSCRIPTION, TokenError.SUBSCRIPTION_EXPIRED -> "restricted"
63
+ TokenError.TOKEN_FETCH_ERROR -> "unknown"
64
+ // handleTokenResult() uses UNKNOWN when the intent has no token or error extras.
65
+ TokenError.UNKNOWN -> "denied"
66
+ }
67
+ return MusicKitAuthOutput(status = status)
68
+ }
69
+
70
+ val token = result.musicUserToken
71
+ if (token.isNullOrBlank()) {
72
+ // Apple Music cancel can return RESULT_OK with an empty music_user_token extra.
73
+ return MusicKitAuthOutput(status = "denied")
74
+ }
75
+
76
+ return MusicKitAuthOutput(status = "authorized", musicUserToken = token)
77
+ }
78
+ }
@@ -0,0 +1,76 @@
1
+ package expo.modules.applemusic
2
+
3
+ import android.content.Context
4
+
5
+ internal object MusicKitAuthStorage {
6
+ private const val PREFS_NAME = "expo.modules.applemusic.auth"
7
+ private const val KEY_DEVELOPER_TOKEN = "developerToken"
8
+ private const val KEY_MUSIC_USER_TOKEN = "musicUserToken"
9
+
10
+ fun saveDeveloperToken(context: Context, token: String) {
11
+ context
12
+ .getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
13
+ .edit()
14
+ .putString(KEY_DEVELOPER_TOKEN, token)
15
+ .apply()
16
+ invalidateSession(context)
17
+ }
18
+
19
+ /** Persists for native playback SDK (iOS [MusicKitAuthStorage] parity); JS still owns long-term storage. */
20
+ fun saveMusicUserToken(context: Context, token: String) {
21
+ val trimmed = token.trim()
22
+ context
23
+ .getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
24
+ .edit()
25
+ .putString(KEY_MUSIC_USER_TOKEN, trimmed)
26
+ .apply()
27
+ AuthenticatedSessionCache.rememberMusicUserToken(trimmed)
28
+ }
29
+
30
+ fun getMusicUserToken(context: Context): String? {
31
+ AuthenticatedSessionCache.musicUserToken?.let { return it }
32
+ val stored =
33
+ context
34
+ .getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
35
+ .getString(KEY_MUSIC_USER_TOKEN, null)
36
+ ?.trim()
37
+ ?.takeIf { it.isNotEmpty() }
38
+ if (stored != null) {
39
+ AuthenticatedSessionCache.rememberMusicUserToken(stored)
40
+ }
41
+ return stored
42
+ }
43
+
44
+ private fun invalidateSession(context: Context) {
45
+ AuthenticatedSessionCache.invalidate()
46
+ context
47
+ .getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
48
+ .edit()
49
+ .remove(KEY_MUSIC_USER_TOKEN)
50
+ .apply()
51
+ AndroidPlaybackController.resetInstance()
52
+ }
53
+
54
+ fun getDeveloperToken(context: Context): String? =
55
+ context
56
+ .getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
57
+ .getString(KEY_DEVELOPER_TOKEN, null)
58
+
59
+ fun clearDeveloperToken(context: Context) {
60
+ context
61
+ .getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
62
+ .edit()
63
+ .remove(KEY_DEVELOPER_TOKEN)
64
+ .apply()
65
+ invalidateSession(context)
66
+ }
67
+
68
+ fun clearAll(context: Context) {
69
+ context
70
+ .getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
71
+ .edit()
72
+ .clear()
73
+ .apply()
74
+ invalidateSession(context)
75
+ }
76
+ }
@@ -0,0 +1,13 @@
1
+ package expo.modules.applemusic
2
+
3
+ import android.content.Context
4
+ import com.apple.android.sdk.authentication.TokenProvider
5
+
6
+ internal class MusicKitTokenProvider(
7
+ private val context: Context,
8
+ ) : TokenProvider {
9
+ override fun getDeveloperToken(): String = AndroidDeveloperToken.requireStored(context)
10
+
11
+ override fun getUserToken(): String =
12
+ MusicKitAuthStorage.getMusicUserToken(context).orEmpty()
13
+ }
@@ -0,0 +1,14 @@
1
+ package expo.modules.applemusic
2
+
3
+ internal data class PaginationOptions(
4
+ val limit: Int,
5
+ val offset: Int,
6
+ ) {
7
+ companion object {
8
+ fun fromMap(options: Map<String, Any?>): PaginationOptions {
9
+ val limit = (options["limit"] as? Number)?.toInt()?.coerceAtLeast(1) ?: 25
10
+ val offset = (options["offset"] as? Number)?.toInt()?.coerceAtLeast(0) ?: 0
11
+ return PaginationOptions(limit, offset)
12
+ }
13
+ }
14
+ }
@@ -0,0 +1,72 @@
1
+ package expo.modules.applemusic
2
+
3
+ import kotlinx.coroutines.Dispatchers
4
+ import kotlinx.coroutines.withContext
5
+ import org.json.JSONObject
6
+
7
+ /** Ratings and favorites Apple Music REST. */
8
+ internal class RatingsRestClient(
9
+ private val transport: AppleMusicRestTransport,
10
+ ) {
11
+ suspend fun getRating(musicUserToken: String, resourceType: String, id: String): Map<String, Any?>? =
12
+ withContext(Dispatchers.IO) {
13
+ try {
14
+ val json = transport.getJson(
15
+ musicUserToken,
16
+ "/v1/me/ratings/$resourceType/$id")
17
+ AppleMusicJsonMapper.mapRating(json)
18
+ } catch (error: expo.modules.kotlin.exception.CodedException) {
19
+ if (error.message?.contains("(404)") == true) {
20
+ return@withContext null
21
+ }
22
+ throw error
23
+ }
24
+ }
25
+
26
+ suspend fun setRating(musicUserToken: String, resourceType: String, id: String, value: Int): Map<String, Any?> =
27
+ withContext(Dispatchers.IO) {
28
+ val body =
29
+ JSONObject()
30
+ .put("type", "rating")
31
+ .put(
32
+ "attributes",
33
+ JSONObject().put("value", value),
34
+ )
35
+ val json =
36
+ transport.request(
37
+ musicUserToken,
38
+ AppleMusicHttpMethod.PUT,
39
+ "/v1/me/ratings/$resourceType/$id",
40
+ body = body,
41
+ )
42
+ AppleMusicJsonMapper.mapRating(json)
43
+ ?: throw AppleMusicErrors.apiError("Invalid Apple Music API response")
44
+ }
45
+
46
+ suspend fun clearRating(musicUserToken: String, resourceType: String, id: String): Unit =
47
+ withContext(Dispatchers.IO) {
48
+ transport.request(
49
+ musicUserToken,
50
+ AppleMusicHttpMethod.DELETE, "/v1/me/ratings/$resourceType/$id")
51
+ }
52
+
53
+ suspend fun addToFavorites(musicUserToken: String, resourceIds: Map<String, List<String>>): Unit =
54
+ withContext(Dispatchers.IO) {
55
+ transport.request(
56
+ musicUserToken,
57
+ AppleMusicHttpMethod.POST,
58
+ "/v1/me/favorites",
59
+ query = buildIdsQuery(resourceIds),
60
+ )
61
+ }
62
+
63
+ suspend fun removeFromFavorites(musicUserToken: String, resourceIds: Map<String, List<String>>): Unit =
64
+ withContext(Dispatchers.IO) {
65
+ transport.request(
66
+ musicUserToken,
67
+ AppleMusicHttpMethod.DELETE,
68
+ "/v1/me/favorites",
69
+ query = buildIdsQuery(resourceIds),
70
+ )
71
+ }
72
+ }
@@ -0,0 +1,37 @@
1
+ package expo.modules.applemusic
2
+
3
+ import kotlinx.coroutines.Dispatchers
4
+ import kotlinx.coroutines.withContext
5
+
6
+ /** Recommendations and Replay Apple Music REST. */
7
+ internal class RecommendationsRestClient(
8
+ private val transport: AppleMusicRestTransport,
9
+ ) {
10
+ suspend fun getRecommendations(musicUserToken: String, ids: List<String>?): List<Map<String, Any?>> =
11
+ withContext(Dispatchers.IO) {
12
+ val query =
13
+ if (!ids.isNullOrEmpty()) {
14
+ mapOf("ids" to ids.joinToString(","))
15
+ } else {
16
+ emptyMap()
17
+ }
18
+ val json = transport.getJson(
19
+ musicUserToken,
20
+ "/v1/me/recommendations", query)
21
+ mapTopLevelResourceArray(json) { AppleMusicJsonMapper.mapRecommendation(it) }
22
+ }
23
+
24
+ suspend fun getReplay(musicUserToken: String, year: Int?): List<Map<String, Any?>> =
25
+ withContext(Dispatchers.IO) {
26
+ val query =
27
+ if (year != null) {
28
+ mapOf("filter[year]" to year.toString())
29
+ } else {
30
+ emptyMap()
31
+ }
32
+ val json = transport.getJson(
33
+ musicUserToken,
34
+ "/v1/me/music-summaries", query)
35
+ mapTopLevelResourceArray(json) { AppleMusicJsonMapper.mapReplaySummary(it) }
36
+ }
37
+ }