@wwdrew/expo-spotify-sdk 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/README.md +62 -344
  2. package/android/src/main/java/expo/modules/spotifysdk/ExpoSpotifySDKModule.kt +3 -5
  3. package/android/src/main/java/expo/modules/spotifysdk/SpotifyAppRemoteCoordinator.kt +6 -64
  4. package/android/src/main/java/expo/modules/spotifysdk/SpotifyAppRemoteErrorMapping.kt +106 -0
  5. package/android/src/main/java/expo/modules/spotifysdk/SpotifyTokenSwapClient.kt +2 -7
  6. package/build/app-remote/index.d.ts.map +1 -1
  7. package/build/app-remote/index.js +11 -24
  8. package/build/app-remote/index.js.map +1 -1
  9. package/build/auth/index.d.ts.map +1 -1
  10. package/build/auth/index.js +17 -34
  11. package/build/auth/index.js.map +1 -1
  12. package/build/content/index.d.ts.map +1 -1
  13. package/build/content/index.js +12 -25
  14. package/build/content/index.js.map +1 -1
  15. package/build/hooks/index.d.ts +1 -1
  16. package/build/hooks/index.d.ts.map +1 -1
  17. package/build/hooks/index.js +38 -115
  18. package/build/hooks/index.js.map +1 -1
  19. package/build/images/index.d.ts +2 -2
  20. package/build/images/index.d.ts.map +1 -1
  21. package/build/images/index.js +12 -25
  22. package/build/images/index.js.map +1 -1
  23. package/build/index.d.ts +0 -18
  24. package/build/index.d.ts.map +1 -1
  25. package/build/index.js +0 -27
  26. package/build/index.js.map +1 -1
  27. package/build/internal/native-errors.d.ts +14 -0
  28. package/build/internal/native-errors.d.ts.map +1 -0
  29. package/build/internal/native-errors.js +29 -0
  30. package/build/internal/native-errors.js.map +1 -0
  31. package/build/internal/sync-external-store.d.ts +14 -0
  32. package/build/internal/sync-external-store.d.ts.map +1 -0
  33. package/build/internal/sync-external-store.js +36 -0
  34. package/build/internal/sync-external-store.js.map +1 -0
  35. package/build/player/index.d.ts.map +1 -1
  36. package/build/player/index.js +14 -27
  37. package/build/player/index.js.map +1 -1
  38. package/build/user/index.d.ts +2 -2
  39. package/build/user/index.d.ts.map +1 -1
  40. package/build/user/index.js +16 -26
  41. package/build/user/index.js.map +1 -1
  42. package/ios/ExpoSpotifySDKModule.swift +1 -1
  43. package/ios/SpotifyAppRemoteCoordinator.swift +29 -404
  44. package/ios/SpotifyAppRemoteErrorMapping.swift +110 -0
  45. package/ios/SpotifyAppRemoteErrors.swift +221 -0
  46. package/ios/SpotifyAppRemoteMappers.swift +88 -0
  47. package/package.json +4 -2
  48. package/plugin/index.d.ts +2 -0
  49. package/plugin/index.js +1 -0
@@ -0,0 +1,221 @@
1
+ import ExpoModulesCore
2
+ import Foundation
3
+
4
+ // MARK: — App Remote error types
5
+
6
+ enum AppRemoteError: Error {
7
+ case connectionFailed(String)
8
+ case connectionLost(String)
9
+ case notConnected(String)
10
+ case unknown(String)
11
+
12
+ var code: String {
13
+ switch self {
14
+ case .connectionFailed: return "CONNECTION_FAILED"
15
+ case .connectionLost: return "CONNECTION_LOST"
16
+ case .notConnected: return "NOT_CONNECTED"
17
+ case .unknown: return "UNKNOWN"
18
+ }
19
+ }
20
+
21
+ var message: String {
22
+ switch self {
23
+ case .connectionFailed(let m): return m
24
+ case .connectionLost(let m): return m
25
+ case .notConnected(let m): return m
26
+ case .unknown(let m): return m
27
+ }
28
+ }
29
+ }
30
+
31
+ /// Bridges an `AppRemoteError` through expo-modules-core's exception system so
32
+ /// JS callers receive a structured `code` and `reason`, not "undefined reason".
33
+ final class AppRemoteException: Exception, @unchecked Sendable {
34
+ private let appRemoteCode: String
35
+ private let appRemoteMessage: String
36
+
37
+ init(_ error: AppRemoteError, file: String = #fileID, line: UInt = #line, function: String = #function) {
38
+ self.appRemoteCode = error.code
39
+ self.appRemoteMessage = error.message
40
+ super.init(file: file, line: line, function: function)
41
+ }
42
+
43
+ override var code: String { appRemoteCode }
44
+ override var reason: String { appRemoteMessage }
45
+ }
46
+
47
+ // MARK: — Player error types
48
+
49
+ enum NativePlayerError: Error {
50
+ case notConnected(String)
51
+ case connectionLost(String)
52
+ case premiumRequired(String)
53
+ case invalidURI(String)
54
+ case invalidParameter(String)
55
+ case operationNotAllowed(String)
56
+ case unknown(String)
57
+
58
+ var code: String {
59
+ switch self {
60
+ case .notConnected: return "NOT_CONNECTED"
61
+ case .connectionLost: return "CONNECTION_LOST"
62
+ case .premiumRequired: return "PREMIUM_REQUIRED"
63
+ case .invalidURI: return "INVALID_URI"
64
+ case .invalidParameter: return "INVALID_PARAMETER"
65
+ case .operationNotAllowed: return "OPERATION_NOT_ALLOWED"
66
+ case .unknown: return "UNKNOWN"
67
+ }
68
+ }
69
+
70
+ var message: String {
71
+ switch self {
72
+ case .notConnected(let m): return m
73
+ case .connectionLost(let m): return m
74
+ case .premiumRequired(let m): return m
75
+ case .invalidURI(let m): return m
76
+ case .invalidParameter(let m): return m
77
+ case .operationNotAllowed(let m): return m
78
+ case .unknown(let m): return m
79
+ }
80
+ }
81
+ }
82
+
83
+ final class PlayerException: Exception, @unchecked Sendable {
84
+ private let playerCode: String
85
+ private let playerMessage: String
86
+
87
+ init(_ error: NativePlayerError, file: String = #fileID, line: UInt = #line, function: String = #function) {
88
+ self.playerCode = error.code
89
+ self.playerMessage = error.message
90
+ super.init(file: file, line: line, function: function)
91
+ }
92
+
93
+ override var code: String { playerCode }
94
+ override var reason: String { playerMessage }
95
+ }
96
+
97
+ // MARK: — User error types
98
+
99
+ enum NativeUserError: Error {
100
+ case notConnected(String)
101
+ case connectionLost(String)
102
+ case invalidURI(String)
103
+ case operationNotAllowed(String)
104
+ case unknown(String)
105
+
106
+ var code: String {
107
+ switch self {
108
+ case .notConnected: return "NOT_CONNECTED"
109
+ case .connectionLost: return "CONNECTION_LOST"
110
+ case .invalidURI: return "INVALID_URI"
111
+ case .operationNotAllowed: return "OPERATION_NOT_ALLOWED"
112
+ case .unknown: return "UNKNOWN"
113
+ }
114
+ }
115
+
116
+ var message: String {
117
+ switch self {
118
+ case .notConnected(let m): return m
119
+ case .connectionLost(let m): return m
120
+ case .invalidURI(let m): return m
121
+ case .operationNotAllowed(let m): return m
122
+ case .unknown(let m): return m
123
+ }
124
+ }
125
+ }
126
+
127
+ final class UserException: Exception, @unchecked Sendable {
128
+ private let userCode: String
129
+ private let userMessage: String
130
+
131
+ init(_ error: NativeUserError, file: String = #fileID, line: UInt = #line, function: String = #function) {
132
+ self.userCode = error.code
133
+ self.userMessage = error.message
134
+ super.init(file: file, line: line, function: function)
135
+ }
136
+
137
+ override var code: String { userCode }
138
+ override var reason: String { userMessage }
139
+ }
140
+
141
+ // MARK: — Content error types
142
+
143
+ enum NativeContentError: Error {
144
+ case notConnected(String)
145
+ case connectionLost(String)
146
+ case contentAPIUnavailable(String)
147
+ case unknown(String)
148
+
149
+ var code: String {
150
+ switch self {
151
+ case .notConnected: return "NOT_CONNECTED"
152
+ case .connectionLost: return "CONNECTION_LOST"
153
+ case .contentAPIUnavailable: return "CONTENT_API_UNAVAILABLE"
154
+ case .unknown: return "UNKNOWN"
155
+ }
156
+ }
157
+
158
+ var message: String {
159
+ switch self {
160
+ case .notConnected(let m): return m
161
+ case .connectionLost(let m): return m
162
+ case .contentAPIUnavailable(let m): return m
163
+ case .unknown(let m): return m
164
+ }
165
+ }
166
+ }
167
+
168
+ final class ContentException: Exception, @unchecked Sendable {
169
+ private let contentCode: String
170
+ private let contentMessage: String
171
+
172
+ init(_ error: NativeContentError, file: String = #fileID, line: UInt = #line, function: String = #function) {
173
+ self.contentCode = error.code
174
+ self.contentMessage = error.message
175
+ super.init(file: file, line: line, function: function)
176
+ }
177
+
178
+ override var code: String { contentCode }
179
+ override var reason: String { contentMessage }
180
+ }
181
+
182
+ // MARK: — Images error types
183
+
184
+ enum NativeImagesError: Error {
185
+ case notConnected(String)
186
+ case invalidURI(String)
187
+ case imageLoadFailed(String)
188
+ case unknown(String)
189
+
190
+ var code: String {
191
+ switch self {
192
+ case .notConnected: return "NOT_CONNECTED"
193
+ case .invalidURI: return "INVALID_URI"
194
+ case .imageLoadFailed: return "IMAGE_LOAD_FAILED"
195
+ case .unknown: return "UNKNOWN"
196
+ }
197
+ }
198
+
199
+ var message: String {
200
+ switch self {
201
+ case .notConnected(let m): return m
202
+ case .invalidURI(let m): return m
203
+ case .imageLoadFailed(let m): return m
204
+ case .unknown(let m): return m
205
+ }
206
+ }
207
+ }
208
+
209
+ final class ImagesException: Exception, @unchecked Sendable {
210
+ private let imagesCode: String
211
+ private let imagesMessage: String
212
+
213
+ init(_ error: NativeImagesError, file: String = #fileID, line: UInt = #line, function: String = #function) {
214
+ self.imagesCode = error.code
215
+ self.imagesMessage = error.message
216
+ super.init(file: file, line: line, function: function)
217
+ }
218
+
219
+ override var code: String { imagesCode }
220
+ override var reason: String { imagesMessage }
221
+ }
@@ -0,0 +1,88 @@
1
+ import Foundation
2
+ import SpotifyiOS
3
+ import UIKit
4
+
5
+ /// Serializes Spotify App Remote SDK objects into NSDictionary-compatible payloads
6
+ /// for the Expo JS bridge.
7
+ enum SpotifyAppRemoteMappers {
8
+ static func playerStateToMap(_ state: any SPTAppRemotePlayerState) -> [String: Any] {
9
+ let track = state.track
10
+ let restrictions = state.playbackRestrictions
11
+ let options = state.playbackOptions
12
+ return [
13
+ "track": [
14
+ "uri": track.uri,
15
+ "name": track.name,
16
+ "imageIdentifier": track.imageIdentifier,
17
+ "duration": track.duration,
18
+ "artist": ["name": track.artist.name, "uri": track.artist.uri],
19
+ "album": ["name": track.album.name, "uri": track.album.uri],
20
+ "isSaved": track.isSaved,
21
+ "isEpisode": track.isEpisode,
22
+ "isPodcast": track.isPodcast,
23
+ "isAdvertisement": track.isAdvertisement,
24
+ ] as [String: Any],
25
+ "playbackPosition": state.playbackPosition,
26
+ "playbackSpeed": state.playbackSpeed,
27
+ "isPaused": state.isPaused,
28
+ "playbackOptions": [
29
+ "isShuffling": options.isShuffling,
30
+ "repeatMode": options.repeatMode.rawValue,
31
+ ] as [String: Any],
32
+ "playbackRestrictions": [
33
+ "canSkipNext": restrictions.canSkipNext,
34
+ "canSkipPrevious": restrictions.canSkipPrevious,
35
+ "canRepeatTrack": restrictions.canRepeatTrack,
36
+ "canRepeatContext": restrictions.canRepeatContext,
37
+ "canToggleShuffle": restrictions.canToggleShuffle,
38
+ "canSeek": restrictions.canSeek,
39
+ ] as [String: Any],
40
+ "contextTitle": state.contextTitle,
41
+ "contextUri": state.contextURI.absoluteString,
42
+ ]
43
+ }
44
+
45
+ static func capabilitiesToMap(_ capabilities: any SPTAppRemoteUserCapabilities) -> [String: Any] {
46
+ ["canPlayOnDemand": capabilities.canPlayOnDemand]
47
+ }
48
+
49
+ static func libraryStateToMap(_ state: any SPTAppRemoteLibraryState) -> [String: Any] {
50
+ ["uri": state.uri, "isAdded": state.isAdded, "canAdd": state.canAdd]
51
+ }
52
+
53
+ static func mapContentType(_ type: String) -> String {
54
+ switch type {
55
+ case "navigation": return SPTAppRemoteContentTypeNavigation
56
+ case "fitness": return SPTAppRemoteContentTypeFitness
57
+ case "gaming": return SPTAppRemoteContentTypeGaming
58
+ default: return SPTAppRemoteContentTypeDefault
59
+ }
60
+ }
61
+
62
+ static func mapImageSize(_ size: String) -> CGSize {
63
+ switch size {
64
+ case "small": return CGSize(width: 64, height: 64)
65
+ case "medium": return CGSize(width: 300, height: 300)
66
+ default: return CGSize(width: 640, height: 640)
67
+ }
68
+ }
69
+
70
+ static func contentItemToMap(_ item: any SPTAppRemoteContentItem) -> [String: Any] {
71
+ var map: [String: Any] = [
72
+ "title": item.title as Any,
73
+ "subtitle": item.subtitle as Any,
74
+ "contentDescription": item.contentDescription as Any,
75
+ "identifier": item.identifier,
76
+ "uri": item.uri,
77
+ "imageIdentifier": item.imageIdentifier,
78
+ "isAvailableOffline": item.isAvailableOffline,
79
+ "isPlayable": item.isPlayable,
80
+ "isContainer": item.isContainer,
81
+ "isPinned": item.isPinned,
82
+ ]
83
+ if let children = item.children {
84
+ map["children"] = children.map(contentItemToMap)
85
+ }
86
+ return map
87
+ }
88
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wwdrew/expo-spotify-sdk",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "Expo module wrapping the native Spotify iOS (v5) and Android (v4) SDKs for OAuth authentication and App Remote playback control",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -19,7 +19,7 @@
19
19
  "build:plugin": "tsc -p plugin/tsconfig.json",
20
20
  "clean": "rm -rf build plugin/build",
21
21
  "lint": "eslint src",
22
- "test": "jest --rootDir plugin --config plugin/jest.config.js",
22
+ "test": "jest --config jest.config.js",
23
23
  "prepublishOnly": "yarn clean && yarn build && yarn build:plugin",
24
24
  "typecheck": "tsc --noEmit",
25
25
  "open:ios": "open -a \"Xcode\" example/ios",
@@ -33,6 +33,8 @@
33
33
  "Spotify"
34
34
  ],
35
35
  "files": [
36
+ "plugin/index.js",
37
+ "plugin/index.d.ts",
36
38
  "plugin/build",
37
39
  "build",
38
40
  "android",
@@ -0,0 +1,2 @@
1
+ export { default } from "./build/index";
2
+ export type { SpotifyConfig, SpotifyScopes } from "./build/types";
@@ -0,0 +1 @@
1
+ module.exports = require("./build").default;