@wwdrew/expo-spotify-sdk 0.2.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.
package/README.md CHANGED
@@ -24,9 +24,7 @@ Include the `expo-spotify-sdk` plugin in your `app.json/app.config.js` file with
24
24
  ["@wwdrew/expo-spotify-sdk", {
25
25
  "clientID": "<your-spotify-client-id>",
26
26
  "scheme": "expo-spotify-sdk-example",
27
- "host": "authenticate",
28
- "tokenSwapURL": "http://192.168.0.5:3000/swap",
29
- "tokenRefreshURL": "http://192.168.0.5:3000/swap"
27
+ "host": "authenticate"
30
28
  }]
31
29
  ],
32
30
  ...
@@ -37,23 +35,27 @@ Required:
37
35
  - `clientID`: &lt;string&gt; the Spotify Client ID for your application
38
36
  - `scheme`: &lt;string&gt; the [URL scheme](https://docs.expo.dev/versions/latest/config/app/#scheme) to link into your app as part of the redirect URI
39
37
  - `host`: &lt;string&gt; the path of the redirect URI
40
- - `tokenSwapURL` (optional): &lt;string&gt; The URL to use for attempting to swap an authorization code for an access token
41
- - `tokenRefreshURL` (optional): &lt;string&gt; The URL to use for attempting to renew an access token with a refresh token
42
38
 
43
39
  ## API Reference
44
40
 
45
- `isAvailable(): boolean`
41
+ ```typescript
42
+ isAvailable(): boolean`
43
+ ```
46
44
 
47
45
  Determines if the Spotify app is installed on the target device.
48
46
 
49
47
  ---
50
48
 
51
- `authenticateAsync(scopes: SpotifyScope[]): Promise<SpotifySesson>`
49
+ ```typescript
50
+ authenticateAsync(config: SpotifyConfig): Promise<SpotifySession>
51
+ ```
52
52
 
53
53
  Starts the authentication process. Requires an array of OAuth scopes. If the Spotify app is installed on the target device it will interact directly with it, otherwise it will open a web view to authenticate with the Spotify website.
54
54
 
55
55
  ### Parameters
56
56
 
57
+ - `tokenSwapURL` (optional): &lt;string&gt; The URL to use for attempting to swap an authorization code for an access token
58
+ - `tokenRefreshURL` (optional): &lt;string&gt; The URL to use for attempting to renew an access token with a refresh token
57
59
  - `scopes`: An array of OAuth scopes that declare how your app wants to access a user's account. See [Spotify Scopes](https://developer.spotify.com/web-api/using-scopes/) for more information.
58
60
 
59
61
  **Note**: The following scopes are not available to Expo Spotify SDK:
@@ -68,11 +70,18 @@ Starts the authentication process. Requires an array of OAuth scopes. If the Spo
68
70
  ### Types
69
71
 
70
72
  ```typescript
73
+ interface SpotifyConfig {
74
+ scopes: SpotifyScope[];
75
+ tokenSwapURL?: string;
76
+ tokenRefreshURL?: string;
77
+ }
78
+
71
79
  interface SpotifySession {
72
80
  accessToken: string;
73
81
  refreshToken: string;
74
82
  expirationDate: number;
75
83
  isExpired: boolean;
84
+ scopes: SpotifyScopes[];
76
85
  }
77
86
 
78
87
  type SpotifyScopes =
@@ -94,12 +103,11 @@ type SpotifyScopes =
94
103
  | "user-library-read"
95
104
  | "user-read-email"
96
105
  | "user-read-private";
97
-
98
106
  ```
99
107
 
100
108
  ## Acknowledgments
101
109
 
102
- This project has been heavily inspired by the following projects.
110
+ This project has been heavily inspired by the following projects:
103
111
 
104
112
  * [react-native-spotify-remote](https://github.com/cjam/react-native-spotify-remote)
105
113
  * [expo-spotify](https://github.com/kvbalib/expo-spotify)
@@ -3,6 +3,7 @@ export interface SpotifySession {
3
3
  refreshToken: string;
4
4
  expirationDate: number;
5
5
  isExpired: boolean;
6
+ scopes: SpotifyScope[];
6
7
  }
7
8
  export interface SpotifyConfig {
8
9
  scopes: SpotifyScope[];
@@ -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;CACpB;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
+ {"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}\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"]}
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"]}
@@ -23,17 +23,17 @@ public class ExpoSpotifySDKModule: Module {
23
23
  let tokenRefreshURL = config["tokenRefreshURL"] as? String
24
24
 
25
25
  spotifySession.authenticate(scopes: scopes, tokenSwapURL: tokenSwapURL, tokenRefreshURL: tokenRefreshURL).done { session in
26
- let sessionData: [String: Any] = [
26
+ promise.resolve([
27
27
  "accessToken": session.accessToken,
28
28
  "refreshToken": session.refreshToken,
29
29
  "expirationDate": Int(session.expirationDate.timeIntervalSince1970 * 1000),
30
30
  "scopes": SPTScopeSerializer.serializeScopes(session.scope),
31
31
  "isExpired": session.isExpired
32
- ]
33
- promise.resolve(sessionData)
32
+ ])
34
33
  }.catch { error in
35
34
  promise.reject(error)
36
35
  }
37
36
  }
37
+
38
38
  }
39
39
  }
@@ -5,11 +5,11 @@ extension ExpoSpotifySessionManager: SPTSessionManagerDelegate {
5
5
  public func sessionManager(manager _: SPTSessionManager, didInitiate session: SPTSession) {
6
6
  authPromiseSeal?.fulfill(session)
7
7
  }
8
-
8
+
9
9
  public func sessionManager(manager _: SPTSessionManager, didFailWith error: Error) {
10
10
  authPromiseSeal?.reject(error)
11
11
  }
12
-
12
+
13
13
  public func sessionManager(manager _: SPTSessionManager, didRenew session: SPTSession) {
14
14
  authPromiseSeal?.fulfill(session)
15
15
  }
@@ -10,9 +10,9 @@ enum SessionManagerError: Error {
10
10
  final class ExpoSpotifySessionManager: NSObject {
11
11
  weak var module: ExpoSpotifySDKModule?
12
12
  var authPromiseSeal: Resolver<SPTSession>?
13
-
13
+
14
14
  static let shared = ExpoSpotifySessionManager()
15
-
15
+
16
16
  private var expoSpotifyConfiguration: ExpoSpotifyConfiguration? {
17
17
  guard let expoSpotifySdkDict = Bundle.main.object(forInfoDictionaryKey: "ExpoSpotifySDK") as? [String: String],
18
18
  let clientID = expoSpotifySdkDict["clientID"],
@@ -21,29 +21,29 @@ final class ExpoSpotifySessionManager: NSObject {
21
21
  {
22
22
  return nil
23
23
  }
24
-
24
+
25
25
  return ExpoSpotifyConfiguration(clientID: clientID, host: host, scheme: scheme)
26
26
  }
27
-
27
+
28
28
  lazy var configuration: SPTConfiguration? = {
29
29
  guard let clientID = expoSpotifyConfiguration?.clientID,
30
30
  let redirectURL = expoSpotifyConfiguration?.redirectURL else {
31
31
  NSLog("Invalid Spotify configuration")
32
32
  return nil
33
33
  }
34
-
34
+
35
35
  return SPTConfiguration(clientID: clientID, redirectURL: redirectURL)
36
36
  }()
37
-
37
+
38
38
  lazy var sessionManager: SPTSessionManager? = {
39
39
  guard let configuration = configuration else {
40
40
  return nil
41
41
  }
42
-
42
+
43
43
  return SPTSessionManager(configuration: configuration, delegate: self)
44
44
  }()
45
-
46
-
45
+
46
+
47
47
  func authenticate(scopes: [String], tokenSwapURL: String?, tokenRefreshURL: String?) -> PromiseKit.Promise<SPTSession> {
48
48
  return Promise { seal in
49
49
  guard let clientID = expoSpotifyConfiguration?.clientID,
@@ -52,33 +52,39 @@ final class ExpoSpotifySessionManager: NSObject {
52
52
  seal.reject(SessionManagerError.invalidConfiguration)
53
53
  return
54
54
  }
55
+
55
56
  let configuration = SPTConfiguration(clientID: clientID, redirectURL: redirectURL)
56
57
 
57
- configuration.tokenSwapURL = URL(string: tokenSwapURL ?? "")
58
- configuration.tokenRefreshURL = URL(string: tokenRefreshURL ?? "")
59
-
60
- self.sessionManager = SPTSessionManager(configuration: configuration, delegate: self)
61
-
58
+ if (tokenSwapURL != nil) {
59
+ configuration.tokenSwapURL = URL(string: tokenSwapURL ?? "")
60
+ }
61
+
62
+ if (tokenRefreshURL != nil) {
63
+ configuration.tokenRefreshURL = URL(string: tokenRefreshURL ?? "")
64
+ }
65
+
62
66
  self.authPromiseSeal = seal
63
-
67
+ self.configuration = configuration
68
+ self.sessionManager = SPTSessionManager(configuration: configuration, delegate: self)
69
+
64
70
  DispatchQueue.main.sync {
65
71
  sessionManager?.initiateSession(with: SPTScopeSerializer.deserializeScopes(scopes), options: .default)
66
72
  }
67
73
  }
68
74
  }
69
-
75
+
70
76
  func spotifyAppInstalled() -> Bool {
71
77
  guard let sessionManager = sessionManager else {
72
78
  NSLog("SPTSessionManager not initialized")
73
79
  return false
74
80
  }
75
-
81
+
76
82
  var isInstalled = false
77
-
83
+
78
84
  DispatchQueue.main.sync {
79
85
  isInstalled = sessionManager.isSpotifyAppInstalled
80
86
  }
81
-
87
+
82
88
  return isInstalled
83
89
  }
84
90
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wwdrew/expo-spotify-sdk",
3
- "version": "0.2.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",