@wwdrew/expo-spotify-sdk 0.3.0 → 0.3.1

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.
@@ -9,7 +9,6 @@ export interface SpotifyConfig {
9
9
  scopes: SpotifyScope[];
10
10
  tokenSwapURL?: string;
11
11
  tokenRefreshURL?: string;
12
- shouldRequestAccessToken?: boolean;
13
12
  }
14
13
  export type SpotifyScope = "ugc-image-upload" | "user-read-playback-state" | "user-modify-playback-state" | "user-read-currently-playing" | "app-remote-control" | "streaming" | "playlist-read-private" | "playlist-read-collaborative" | "playlist-modify-private" | "playlist-modify-public" | "user-follow-modify" | "user-follow-read" | "user-top-read" | "user-read-recently-played" | "user-library-modify" | "user-library-read" | "user-read-email" | "user-read-private";
15
14
  //# sourceMappingURL=ExpoSpotifySDK.types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ExpoSpotifySDK.types.d.ts","sourceRoot":"","sources":["../src/ExpoSpotifySDK.types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,YAAY,EAAE,CAAC;CACxB;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,YAAY,EAAE,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,wBAAwB,CAAC,EAAE,OAAO,CAAC;CACpC;AAED,MAAM,MAAM,YAAY,GACpB,kBAAkB,GAClB,0BAA0B,GAC1B,4BAA4B,GAC5B,6BAA6B,GAC7B,oBAAoB,GACpB,WAAW,GACX,uBAAuB,GACvB,6BAA6B,GAC7B,yBAAyB,GACzB,wBAAwB,GACxB,oBAAoB,GACpB,kBAAkB,GAClB,eAAe,GACf,2BAA2B,GAC3B,qBAAqB,GACrB,mBAAmB,GACnB,iBAAiB,GACjB,mBAAmB,CAAC"}
1
+ {"version":3,"file":"ExpoSpotifySDK.types.d.ts","sourceRoot":"","sources":["../src/ExpoSpotifySDK.types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,YAAY,EAAE,CAAC;CACxB;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,YAAY,EAAE,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,MAAM,YAAY,GACpB,kBAAkB,GAClB,0BAA0B,GAC1B,4BAA4B,GAC5B,6BAA6B,GAC7B,oBAAoB,GACpB,WAAW,GACX,uBAAuB,GACvB,6BAA6B,GAC7B,yBAAyB,GACzB,wBAAwB,GACxB,oBAAoB,GACpB,kBAAkB,GAClB,eAAe,GACf,2BAA2B,GAC3B,qBAAqB,GACrB,mBAAmB,GACnB,iBAAiB,GACjB,mBAAmB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"ExpoSpotifySDK.types.js","sourceRoot":"","sources":["../src/ExpoSpotifySDK.types.ts"],"names":[],"mappings":"","sourcesContent":["export interface SpotifySession {\n accessToken: string;\n refreshToken: string;\n expirationDate: number;\n isExpired: boolean;\n scopes: SpotifyScope[];\n}\n\nexport interface SpotifyConfig {\n scopes: SpotifyScope[];\n tokenSwapURL?: string;\n tokenRefreshURL?: string;\n shouldRequestAccessToken?: boolean;\n}\n\nexport type SpotifyScope =\n | \"ugc-image-upload\"\n | \"user-read-playback-state\"\n | \"user-modify-playback-state\"\n | \"user-read-currently-playing\"\n | \"app-remote-control\"\n | \"streaming\"\n | \"playlist-read-private\"\n | \"playlist-read-collaborative\"\n | \"playlist-modify-private\"\n | \"playlist-modify-public\"\n | \"user-follow-modify\"\n | \"user-follow-read\"\n | \"user-top-read\"\n | \"user-read-recently-played\"\n | \"user-library-modify\"\n | \"user-library-read\"\n | \"user-read-email\"\n | \"user-read-private\";\n"]}
1
+ {"version":3,"file":"ExpoSpotifySDK.types.js","sourceRoot":"","sources":["../src/ExpoSpotifySDK.types.ts"],"names":[],"mappings":"","sourcesContent":["export interface SpotifySession {\n accessToken: string;\n refreshToken: string;\n expirationDate: number;\n isExpired: boolean;\n scopes: SpotifyScope[];\n}\n\nexport interface SpotifyConfig {\n scopes: SpotifyScope[];\n tokenSwapURL?: string;\n tokenRefreshURL?: string;\n}\n\nexport type SpotifyScope =\n | \"ugc-image-upload\"\n | \"user-read-playback-state\"\n | \"user-modify-playback-state\"\n | \"user-read-currently-playing\"\n | \"app-remote-control\"\n | \"streaming\"\n | \"playlist-read-private\"\n | \"playlist-read-collaborative\"\n | \"playlist-modify-private\"\n | \"playlist-modify-public\"\n | \"user-follow-modify\"\n | \"user-follow-read\"\n | \"user-top-read\"\n | \"user-read-recently-played\"\n | \"user-library-modify\"\n | \"user-library-read\"\n | \"user-read-email\"\n | \"user-read-private\";\n"]}
@@ -2,44 +2,38 @@ import ExpoModulesCore
2
2
  import SpotifyiOS
3
3
 
4
4
  public class ExpoSpotifySDKModule: Module {
5
-
5
+
6
6
  public func definition() -> ModuleDefinition {
7
-
7
+
8
8
  let spotifySession = ExpoSpotifySessionManager.shared
9
-
9
+
10
10
  Name("ExpoSpotifySDK")
11
-
11
+
12
12
  Function("isAvailable") {
13
13
  return spotifySession.spotifyAppInstalled()
14
14
  }
15
-
15
+
16
16
  AsyncFunction("authenticateAsync") { (config: [String: Any], promise: Promise) in
17
17
  guard let scopes = config["scopes"] as? [String] else {
18
18
  promise.reject("INVALID_CONFIG", "Invalid SpotifyConfig object")
19
19
  return
20
20
  }
21
-
21
+
22
22
  let tokenSwapURL = config["tokenSwapURL"] as? String
23
23
  let tokenRefreshURL = config["tokenRefreshURL"] as? String
24
- let shouldRequestAccessToken = config["shouldRequestAccessToken"] as? Bool ?? true
25
-
26
- spotifySession.authenticate(scopes: scopes, tokenSwapURL: tokenSwapURL, tokenRefreshURL: tokenRefreshURL, shouldRequestAccessToken: shouldRequestAccessToken).done { result in
27
- switch result {
28
- case .session(let session):
29
- promise.resolve([
30
- "accessToken": session.accessToken,
31
- "refreshToken": session.refreshToken,
32
- "expirationDate": Int(session.expirationDate.timeIntervalSince1970 * 1000),
33
- "scopes": SPTScopeSerializer.serializeScopes(session.scope),
34
- "isExpired": session.isExpired
35
- ])
36
- case .authorizationCode(let code):
37
- promise.resolve(["code": code])
38
- }
24
+
25
+ spotifySession.authenticate(scopes: scopes, tokenSwapURL: tokenSwapURL, tokenRefreshURL: tokenRefreshURL).done { session in
26
+ promise.resolve([
27
+ "accessToken": session.accessToken,
28
+ "refreshToken": session.refreshToken,
29
+ "expirationDate": Int(session.expirationDate.timeIntervalSince1970 * 1000),
30
+ "scopes": SPTScopeSerializer.serializeScopes(session.scope),
31
+ "isExpired": session.isExpired
32
+ ])
39
33
  }.catch { error in
40
34
  promise.reject(error)
41
35
  }
42
36
  }
43
-
37
+
44
38
  }
45
39
  }
@@ -3,9 +3,7 @@ import SpotifyiOS
3
3
 
4
4
  extension ExpoSpotifySessionManager: SPTSessionManagerDelegate {
5
5
  public func sessionManager(manager _: SPTSessionManager, didInitiate session: SPTSession) {
6
- if shouldRequestAccessToken {
7
- authPromiseSeal?.fulfill(AuthenticationResult.session(session))
8
- }
6
+ authPromiseSeal?.fulfill(session)
9
7
  }
10
8
 
11
9
  public func sessionManager(manager _: SPTSessionManager, didFailWith error: Error) {
@@ -13,14 +11,6 @@ extension ExpoSpotifySessionManager: SPTSessionManagerDelegate {
13
11
  }
14
12
 
15
13
  public func sessionManager(manager _: SPTSessionManager, didRenew session: SPTSession) {
16
- authPromiseSeal?.fulfill(AuthenticationResult.session(session))
17
- }
18
-
19
- public func sessionManager(manager: SPTSessionManager, shouldRequestAccessTokenWith code: String) -> Bool {
20
- if !shouldRequestAccessToken {
21
- authPromiseSeal?.fulfill(AuthenticationResult.authorizationCode(code))
22
- }
23
-
24
- return shouldRequestAccessToken
14
+ authPromiseSeal?.fulfill(session)
25
15
  }
26
16
  }
@@ -2,11 +2,6 @@ import ExpoModulesCore
2
2
  import SpotifyiOS
3
3
  import PromiseKit
4
4
 
5
- enum AuthenticationResult {
6
- case session(SPTSession)
7
- case authorizationCode(String)
8
- }
9
-
10
5
  enum SessionManagerError: Error {
11
6
  case notInitialized
12
7
  case invalidConfiguration
@@ -14,12 +9,10 @@ enum SessionManagerError: Error {
14
9
 
15
10
  final class ExpoSpotifySessionManager: NSObject {
16
11
  weak var module: ExpoSpotifySDKModule?
17
- var authPromiseSeal: Resolver<AuthenticationResult>?
18
-
19
- var shouldRequestAccessToken: Bool = true
20
-
12
+ var authPromiseSeal: Resolver<SPTSession>?
13
+
21
14
  static let shared = ExpoSpotifySessionManager()
22
-
15
+
23
16
  private var expoSpotifyConfiguration: ExpoSpotifyConfiguration? {
24
17
  guard let expoSpotifySdkDict = Bundle.main.object(forInfoDictionaryKey: "ExpoSpotifySDK") as? [String: String],
25
18
  let clientID = expoSpotifySdkDict["clientID"],
@@ -28,30 +21,30 @@ final class ExpoSpotifySessionManager: NSObject {
28
21
  {
29
22
  return nil
30
23
  }
31
-
24
+
32
25
  return ExpoSpotifyConfiguration(clientID: clientID, host: host, scheme: scheme)
33
26
  }
34
-
27
+
35
28
  lazy var configuration: SPTConfiguration? = {
36
29
  guard let clientID = expoSpotifyConfiguration?.clientID,
37
30
  let redirectURL = expoSpotifyConfiguration?.redirectURL else {
38
31
  NSLog("Invalid Spotify configuration")
39
32
  return nil
40
33
  }
41
-
34
+
42
35
  return SPTConfiguration(clientID: clientID, redirectURL: redirectURL)
43
36
  }()
44
-
37
+
45
38
  lazy var sessionManager: SPTSessionManager? = {
46
39
  guard let configuration = configuration else {
47
40
  return nil
48
41
  }
49
-
42
+
50
43
  return SPTSessionManager(configuration: configuration, delegate: self)
51
44
  }()
52
-
53
-
54
- func authenticate(scopes: [String], tokenSwapURL: String?, tokenRefreshURL: String?, shouldRequestAccessToken: Bool = true) -> PromiseKit.Promise<AuthenticationResult> {
45
+
46
+
47
+ func authenticate(scopes: [String], tokenSwapURL: String?, tokenRefreshURL: String?) -> PromiseKit.Promise<SPTSession> {
55
48
  return Promise { seal in
56
49
  guard let clientID = expoSpotifyConfiguration?.clientID,
57
50
  let redirectURL = expoSpotifyConfiguration?.redirectURL else {
@@ -59,40 +52,39 @@ final class ExpoSpotifySessionManager: NSObject {
59
52
  seal.reject(SessionManagerError.invalidConfiguration)
60
53
  return
61
54
  }
62
- let configuration = SPTConfiguration(clientID: clientID, redirectURL: redirectURL)
63
55
 
56
+ let configuration = SPTConfiguration(clientID: clientID, redirectURL: redirectURL)
57
+
64
58
  if (tokenSwapURL != nil) {
65
59
  configuration.tokenSwapURL = URL(string: tokenSwapURL ?? "")
66
60
  }
67
-
61
+
68
62
  if (tokenRefreshURL != nil) {
69
63
  configuration.tokenRefreshURL = URL(string: tokenRefreshURL ?? "")
70
64
  }
71
-
72
- self.shouldRequestAccessToken = shouldRequestAccessToken
65
+
66
+ self.authPromiseSeal = seal
73
67
  self.configuration = configuration
74
68
  self.sessionManager = SPTSessionManager(configuration: configuration, delegate: self)
75
-
76
- self.authPromiseSeal = seal
77
-
69
+
78
70
  DispatchQueue.main.sync {
79
71
  sessionManager?.initiateSession(with: SPTScopeSerializer.deserializeScopes(scopes), options: .default)
80
72
  }
81
73
  }
82
74
  }
83
-
75
+
84
76
  func spotifyAppInstalled() -> Bool {
85
77
  guard let sessionManager = sessionManager else {
86
78
  NSLog("SPTSessionManager not initialized")
87
79
  return false
88
80
  }
89
-
81
+
90
82
  var isInstalled = false
91
-
83
+
92
84
  DispatchQueue.main.sync {
93
85
  isInstalled = sessionManager.isSpotifyAppInstalled
94
86
  }
95
-
87
+
96
88
  return isInstalled
97
89
  }
98
90
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wwdrew/expo-spotify-sdk",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Expo Module for native Spotify SDK",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",