@wwdrew/expo-spotify-sdk 2.0.0 → 2.2.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 (126) hide show
  1. package/README.md +94 -346
  2. package/android/build.gradle +4 -5
  3. package/android/libs/SETUP.md +9 -24
  4. package/android/spotify-native-sdk.gradle +118 -0
  5. package/android/src/main/java/expo/modules/spotifysdk/ExpoSpotifySDKModule.kt +14 -5
  6. package/android/src/main/java/expo/modules/spotifysdk/SpotifyAppRemoteCoordinator.kt +38 -64
  7. package/android/src/main/java/expo/modules/spotifysdk/SpotifyAppRemoteErrorMapping.kt +106 -0
  8. package/android/src/main/java/expo/modules/spotifysdk/SpotifyTokenSwapClient.kt +2 -7
  9. package/build/app-remote/index.d.ts +34 -0
  10. package/build/app-remote/index.d.ts.map +1 -1
  11. package/build/app-remote/index.js +47 -24
  12. package/build/app-remote/index.js.map +1 -1
  13. package/build/auth/index.d.ts.map +1 -1
  14. package/build/auth/index.js +17 -34
  15. package/build/auth/index.js.map +1 -1
  16. package/build/content/index.d.ts.map +1 -1
  17. package/build/content/index.js +12 -25
  18. package/build/content/index.js.map +1 -1
  19. package/build/hooks/index.d.ts +1 -1
  20. package/build/hooks/index.d.ts.map +1 -1
  21. package/build/hooks/index.js +38 -115
  22. package/build/hooks/index.js.map +1 -1
  23. package/build/images/index.d.ts +2 -2
  24. package/build/images/index.d.ts.map +1 -1
  25. package/build/images/index.js +12 -25
  26. package/build/images/index.js.map +1 -1
  27. package/build/index.d.ts +0 -18
  28. package/build/index.d.ts.map +1 -1
  29. package/build/index.js +0 -27
  30. package/build/index.js.map +1 -1
  31. package/build/internal/native-errors.d.ts +14 -0
  32. package/build/internal/native-errors.d.ts.map +1 -0
  33. package/build/internal/native-errors.js +29 -0
  34. package/build/internal/native-errors.js.map +1 -0
  35. package/build/internal/sync-external-store.d.ts +14 -0
  36. package/build/internal/sync-external-store.d.ts.map +1 -0
  37. package/build/internal/sync-external-store.js +36 -0
  38. package/build/internal/sync-external-store.js.map +1 -0
  39. package/build/player/index.d.ts.map +1 -1
  40. package/build/player/index.js +14 -27
  41. package/build/player/index.js.map +1 -1
  42. package/build/user/index.d.ts +2 -2
  43. package/build/user/index.d.ts.map +1 -1
  44. package/build/user/index.js +16 -26
  45. package/build/user/index.js.map +1 -1
  46. package/ios/ExpoSpotifyAppDelegate.swift +8 -1
  47. package/ios/ExpoSpotifySDK.podspec +26 -2
  48. package/ios/ExpoSpotifySDKModule.swift +16 -1
  49. package/ios/SpotifyAppRemoteCoordinator.swift +137 -404
  50. package/ios/SpotifyAppRemoteErrorMapping.swift +110 -0
  51. package/ios/SpotifyAppRemoteErrors.swift +221 -0
  52. package/ios/SpotifyAppRemoteMappers.swift +88 -0
  53. package/ios/spotify-native-sdk-versions.json +12 -0
  54. package/package.json +13 -5
  55. package/plugin/index.d.ts +2 -0
  56. package/plugin/index.js +1 -0
  57. package/ios/SpotifySDK/Licenses/MPMessagePack-LICENSE.md +0 -20
  58. package/ios/SpotifySDK/SpotifyiOS.xcframework/Info.plist +0 -40
  59. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64/SpotifyiOS.framework/Headers/SPTAppRemote.h +0 -287
  60. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64/SpotifyiOS.framework/Headers/SPTAppRemoteAlbum.h +0 -18
  61. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64/SpotifyiOS.framework/Headers/SPTAppRemoteArtist.h +0 -18
  62. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64/SpotifyiOS.framework/Headers/SPTAppRemoteCommon.h +0 -37
  63. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64/SpotifyiOS.framework/Headers/SPTAppRemoteConnectionParams.h +0 -65
  64. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64/SpotifyiOS.framework/Headers/SPTAppRemoteConnectivityAPI.h +0 -55
  65. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64/SpotifyiOS.framework/Headers/SPTAppRemoteConnectivityState.h +0 -15
  66. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64/SpotifyiOS.framework/Headers/SPTAppRemoteContentAPI.h +0 -78
  67. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64/SpotifyiOS.framework/Headers/SPTAppRemoteContentItem.h +0 -49
  68. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64/SpotifyiOS.framework/Headers/SPTAppRemoteCrossfadeState.h +0 -18
  69. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64/SpotifyiOS.framework/Headers/SPTAppRemoteImageAPI.h +0 -25
  70. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64/SpotifyiOS.framework/Headers/SPTAppRemoteImageRepresentable.h +0 -16
  71. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64/SpotifyiOS.framework/Headers/SPTAppRemoteLibraryState.h +0 -19
  72. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64/SpotifyiOS.framework/Headers/SPTAppRemotePlaybackOptions.h +0 -32
  73. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64/SpotifyiOS.framework/Headers/SPTAppRemotePlaybackRestrictions.h +0 -32
  74. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64/SpotifyiOS.framework/Headers/SPTAppRemotePlayerAPI.h +0 -267
  75. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64/SpotifyiOS.framework/Headers/SPTAppRemotePlayerState.h +0 -40
  76. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64/SpotifyiOS.framework/Headers/SPTAppRemotePodcastPlaybackSpeed.h +0 -15
  77. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64/SpotifyiOS.framework/Headers/SPTAppRemoteTrack.h +0 -52
  78. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64/SpotifyiOS.framework/Headers/SPTAppRemoteUserAPI.h +0 -102
  79. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64/SpotifyiOS.framework/Headers/SPTAppRemoteUserCapabilities.h +0 -15
  80. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64/SpotifyiOS.framework/Headers/SPTConfiguration.h +0 -66
  81. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64/SpotifyiOS.framework/Headers/SPTError.h +0 -31
  82. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64/SpotifyiOS.framework/Headers/SPTLogin.h +0 -10
  83. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64/SpotifyiOS.framework/Headers/SPTMacros.h +0 -125
  84. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64/SpotifyiOS.framework/Headers/SPTScope.h +0 -75
  85. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64/SpotifyiOS.framework/Headers/SPTSession.h +0 -33
  86. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64/SpotifyiOS.framework/Headers/SPTSessionManager.h +0 -170
  87. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64/SpotifyiOS.framework/Headers/SpotifyAppRemote.h +0 -28
  88. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64/SpotifyiOS.framework/Headers/SpotifyiOS.h +0 -7
  89. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64/SpotifyiOS.framework/Info.plist +0 -0
  90. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64/SpotifyiOS.framework/Modules/module.modulemap +0 -5
  91. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64/SpotifyiOS.framework/PrivacyInfo.xcprivacy +0 -14
  92. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64/SpotifyiOS.framework/SpotifyiOS +0 -0
  93. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64_x86_64-simulator/SpotifyiOS.framework/Headers/SPTAppRemote.h +0 -287
  94. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64_x86_64-simulator/SpotifyiOS.framework/Headers/SPTAppRemoteAlbum.h +0 -18
  95. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64_x86_64-simulator/SpotifyiOS.framework/Headers/SPTAppRemoteArtist.h +0 -18
  96. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64_x86_64-simulator/SpotifyiOS.framework/Headers/SPTAppRemoteCommon.h +0 -37
  97. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64_x86_64-simulator/SpotifyiOS.framework/Headers/SPTAppRemoteConnectionParams.h +0 -65
  98. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64_x86_64-simulator/SpotifyiOS.framework/Headers/SPTAppRemoteConnectivityAPI.h +0 -55
  99. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64_x86_64-simulator/SpotifyiOS.framework/Headers/SPTAppRemoteConnectivityState.h +0 -15
  100. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64_x86_64-simulator/SpotifyiOS.framework/Headers/SPTAppRemoteContentAPI.h +0 -78
  101. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64_x86_64-simulator/SpotifyiOS.framework/Headers/SPTAppRemoteContentItem.h +0 -49
  102. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64_x86_64-simulator/SpotifyiOS.framework/Headers/SPTAppRemoteCrossfadeState.h +0 -18
  103. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64_x86_64-simulator/SpotifyiOS.framework/Headers/SPTAppRemoteImageAPI.h +0 -25
  104. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64_x86_64-simulator/SpotifyiOS.framework/Headers/SPTAppRemoteImageRepresentable.h +0 -16
  105. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64_x86_64-simulator/SpotifyiOS.framework/Headers/SPTAppRemoteLibraryState.h +0 -19
  106. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64_x86_64-simulator/SpotifyiOS.framework/Headers/SPTAppRemotePlaybackOptions.h +0 -32
  107. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64_x86_64-simulator/SpotifyiOS.framework/Headers/SPTAppRemotePlaybackRestrictions.h +0 -32
  108. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64_x86_64-simulator/SpotifyiOS.framework/Headers/SPTAppRemotePlayerAPI.h +0 -267
  109. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64_x86_64-simulator/SpotifyiOS.framework/Headers/SPTAppRemotePlayerState.h +0 -40
  110. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64_x86_64-simulator/SpotifyiOS.framework/Headers/SPTAppRemotePodcastPlaybackSpeed.h +0 -15
  111. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64_x86_64-simulator/SpotifyiOS.framework/Headers/SPTAppRemoteTrack.h +0 -52
  112. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64_x86_64-simulator/SpotifyiOS.framework/Headers/SPTAppRemoteUserAPI.h +0 -102
  113. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64_x86_64-simulator/SpotifyiOS.framework/Headers/SPTAppRemoteUserCapabilities.h +0 -15
  114. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64_x86_64-simulator/SpotifyiOS.framework/Headers/SPTConfiguration.h +0 -66
  115. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64_x86_64-simulator/SpotifyiOS.framework/Headers/SPTError.h +0 -31
  116. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64_x86_64-simulator/SpotifyiOS.framework/Headers/SPTLogin.h +0 -10
  117. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64_x86_64-simulator/SpotifyiOS.framework/Headers/SPTMacros.h +0 -125
  118. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64_x86_64-simulator/SpotifyiOS.framework/Headers/SPTScope.h +0 -75
  119. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64_x86_64-simulator/SpotifyiOS.framework/Headers/SPTSession.h +0 -33
  120. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64_x86_64-simulator/SpotifyiOS.framework/Headers/SPTSessionManager.h +0 -170
  121. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64_x86_64-simulator/SpotifyiOS.framework/Headers/SpotifyAppRemote.h +0 -28
  122. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64_x86_64-simulator/SpotifyiOS.framework/Headers/SpotifyiOS.h +0 -7
  123. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64_x86_64-simulator/SpotifyiOS.framework/Info.plist +0 -0
  124. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64_x86_64-simulator/SpotifyiOS.framework/Modules/module.modulemap +0 -5
  125. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64_x86_64-simulator/SpotifyiOS.framework/PrivacyInfo.xcprivacy +0 -14
  126. package/ios/SpotifySDK/SpotifyiOS.xcframework/ios-arm64_x86_64-simulator/SpotifyiOS.framework/SpotifyiOS +0 -0
@@ -0,0 +1,110 @@
1
+ import Foundation
2
+ import SpotifyiOS
3
+
4
+ /// Maps `SPTAppRemote` NSError payloads into per-namespace native error enums.
5
+ /// Keep aligned with [docs/app-remote-error-mapping.md](../docs/app-remote-error-mapping.md).
6
+ enum SpotifyAppRemoteErrorMapping {
7
+ private static func isSPTError(_ error: NSError) -> Bool {
8
+ error.domain == SPTAppRemoteErrorDomain
9
+ }
10
+
11
+ private static func isConnectionTerminated(_ error: NSError) -> Bool {
12
+ isSPTError(error) && error.code == SPTAppRemoteErrorCode.connectionTerminatedError.rawValue
13
+ }
14
+
15
+ private static func isInvalidArguments(_ error: NSError) -> Bool {
16
+ isSPTError(error) && error.code == SPTAppRemoteErrorCode.invalidArgumentsError.rawValue
17
+ }
18
+
19
+ private static func isRequestFailed(_ error: NSError) -> Bool {
20
+ isSPTError(error) && error.code == SPTAppRemoteErrorCode.requestFailedError.rawValue
21
+ }
22
+
23
+ private static func connectionLostMessage(callsite: String) -> String {
24
+ "\(callsite): connection to Spotify app was terminated"
25
+ }
26
+
27
+ private static func containsRestriction(_ description: String) -> Bool {
28
+ let desc = description.lowercased()
29
+ return desc.contains("not allowed") || desc.contains("restriction")
30
+ }
31
+
32
+ static func mapPlayerError(_ error: NSError, callsite: String) -> NativePlayerError {
33
+ guard isSPTError(error) else {
34
+ return .unknown(error.localizedDescription)
35
+ }
36
+ if isConnectionTerminated(error) {
37
+ return .connectionLost(connectionLostMessage(callsite: callsite))
38
+ }
39
+ if isInvalidArguments(error) {
40
+ let desc = error.localizedDescription.lowercased()
41
+ if desc.contains("uri") {
42
+ return .invalidURI("\(callsite): \(error.localizedDescription)")
43
+ }
44
+ return .invalidParameter(error.localizedDescription)
45
+ }
46
+ if isRequestFailed(error) {
47
+ let desc = error.localizedDescription.lowercased()
48
+ if desc.contains("premium") {
49
+ return .premiumRequired("\(callsite): Spotify Premium is required for on-demand playback")
50
+ }
51
+ if containsRestriction(error.localizedDescription) {
52
+ return .operationNotAllowed("\(callsite): \(error.localizedDescription)")
53
+ }
54
+ return .unknown(error.localizedDescription)
55
+ }
56
+ return .unknown(error.localizedDescription)
57
+ }
58
+
59
+ static func mapUserError(_ error: NSError, callsite: String) -> NativeUserError {
60
+ guard isSPTError(error) else {
61
+ return .unknown(error.localizedDescription)
62
+ }
63
+ if isConnectionTerminated(error) {
64
+ return .connectionLost(connectionLostMessage(callsite: callsite))
65
+ }
66
+ if isInvalidArguments(error) {
67
+ return .invalidURI("\(callsite): \(error.localizedDescription)")
68
+ }
69
+ if isRequestFailed(error) {
70
+ if containsRestriction(error.localizedDescription) {
71
+ return .operationNotAllowed("\(callsite): \(error.localizedDescription)")
72
+ }
73
+ return .unknown(error.localizedDescription)
74
+ }
75
+ return .unknown(error.localizedDescription)
76
+ }
77
+
78
+ static func mapContentError(_ error: NSError, callsite: String) -> NativeContentError {
79
+ guard isSPTError(error) else {
80
+ return .unknown(error.localizedDescription)
81
+ }
82
+ if isConnectionTerminated(error) {
83
+ return .connectionLost(connectionLostMessage(callsite: callsite))
84
+ }
85
+ if isRequestFailed(error) {
86
+ let desc = error.localizedDescription.lowercased()
87
+ if desc.contains("not supported") || desc.contains("unsupported") {
88
+ return .contentAPIUnavailable("\(callsite): content API is unavailable on this Spotify app version")
89
+ }
90
+ return .unknown(error.localizedDescription)
91
+ }
92
+ return .unknown(error.localizedDescription)
93
+ }
94
+
95
+ static func mapImagesError(_ error: NSError, callsite: String) -> NativeImagesError {
96
+ guard isSPTError(error) else {
97
+ return .unknown(error.localizedDescription)
98
+ }
99
+ if isConnectionTerminated(error) {
100
+ return .notConnected(connectionLostMessage(callsite: callsite))
101
+ }
102
+ if isInvalidArguments(error) {
103
+ return .invalidURI("\(callsite): invalid image identifier")
104
+ }
105
+ if isRequestFailed(error) {
106
+ return .imageLoadFailed("\(callsite): Spotify rejected image request")
107
+ }
108
+ return .unknown(error.localizedDescription)
109
+ }
110
+ }
@@ -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
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "ios": {
3
+ "spmRepositoryUrl": "https://github.com/spotify/ios-sdk.git",
4
+ "spmVersion": "5.0.1",
5
+ "spmProduct": "SpotifyiOS"
6
+ },
7
+ "android": {
8
+ "appRemoteVersion": "0.8.0",
9
+ "appRemoteReleaseTag": "v0.8.0-appremote_v2.1.0-auth",
10
+ "appRemoteSha256": "b5a6dd880eaf01f63a871cba9ef7af77c341f8a94ffc8fdf2e9021f9a9d4c198"
11
+ }
12
+ }
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.2.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",
@@ -17,9 +17,9 @@
17
17
  "scripts": {
18
18
  "build": "tsc",
19
19
  "build:plugin": "tsc -p plugin/tsconfig.json",
20
- "clean": "rm -rf build plugin/build",
20
+ "clean": "rm -rf build plugin/build android/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,10 +33,18 @@
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
- "android",
39
- "ios",
40
+ "android/build.gradle",
41
+ "android/spotify-native-sdk.gradle",
42
+ "android/consumer-rules.pro",
43
+ "android/src",
44
+ "android/libs/SETUP.md",
45
+ "ios/spotify-native-sdk-versions.json",
46
+ "ios/*.swift",
47
+ "ios/*.podspec",
40
48
  "app.plugin.js",
41
49
  "expo-module.config.json"
42
50
  ],
@@ -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;
@@ -1,20 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2014 Gabriel Handford
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy of
6
- this software and associated documentation files (the "Software"), to deal in
7
- the Software without restriction, including without limitation the rights to
8
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
- the Software, and to permit persons to whom the Software is furnished to do so,
10
- subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
- FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
- COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
- IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,40 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
- <plist version="1.0">
4
- <dict>
5
- <key>AvailableLibraries</key>
6
- <array>
7
- <dict>
8
- <key>LibraryIdentifier</key>
9
- <string>ios-arm64</string>
10
- <key>LibraryPath</key>
11
- <string>SpotifyiOS.framework</string>
12
- <key>SupportedArchitectures</key>
13
- <array>
14
- <string>arm64</string>
15
- </array>
16
- <key>SupportedPlatform</key>
17
- <string>ios</string>
18
- </dict>
19
- <dict>
20
- <key>LibraryIdentifier</key>
21
- <string>ios-arm64_x86_64-simulator</string>
22
- <key>LibraryPath</key>
23
- <string>SpotifyiOS.framework</string>
24
- <key>SupportedArchitectures</key>
25
- <array>
26
- <string>arm64</string>
27
- <string>x86_64</string>
28
- </array>
29
- <key>SupportedPlatform</key>
30
- <string>ios</string>
31
- <key>SupportedPlatformVariant</key>
32
- <string>simulator</string>
33
- </dict>
34
- </array>
35
- <key>CFBundlePackageType</key>
36
- <string>XFWK</string>
37
- <key>XCFrameworkFormatVersion</key>
38
- <string>1.0</string>
39
- </dict>
40
- </plist>