@wwdrew/expo-spotify-sdk 0.1.1 → 0.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.
@@ -4,5 +4,10 @@ export interface SpotifySession {
4
4
  expirationDate: number;
5
5
  isExpired: boolean;
6
6
  }
7
+ export interface SpotifyConfig {
8
+ scopes: SpotifyScope[];
9
+ tokenSwapURL?: string;
10
+ tokenRefreshURL?: string;
11
+ }
7
12
  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";
8
13
  //# 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;CACpB;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;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 +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 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}\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"]}
package/build/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { SpotifyScope, SpotifySession } from "./ExpoSpotifySDK.types";
1
+ import { SpotifyConfig, SpotifySession } from "./ExpoSpotifySDK.types";
2
2
  declare function isAvailable(): boolean;
3
- declare function authenticateAsync(scopes: SpotifyScope[]): Promise<SpotifySession>;
3
+ declare function authenticateAsync(config: SpotifyConfig): Promise<SpotifySession>;
4
4
  declare const Authenticate: {
5
5
  authenticateAsync: typeof authenticateAsync;
6
6
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAGtE,iBAAS,WAAW,IAAI,OAAO,CAE9B;AAED,iBAAS,iBAAiB,CAAC,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,cAAc,CAAC,CAE1E;AAED,QAAA,MAAM,YAAY;;CAEjB,CAAC;AAEF,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAGvE,iBAAS,WAAW,IAAI,OAAO,CAE9B;AAED,iBAAS,iBAAiB,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC,CAMzE;AAED,QAAA,MAAM,YAAY;;CAEjB,CAAC;AAEF,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,CAAC"}
package/build/index.js CHANGED
@@ -2,8 +2,11 @@ import ExpoSpotifySDKModule from "./ExpoSpotifySDKModule";
2
2
  function isAvailable() {
3
3
  return ExpoSpotifySDKModule.isAvailable();
4
4
  }
5
- function authenticateAsync(scopes) {
6
- return ExpoSpotifySDKModule.authenticate(scopes);
5
+ function authenticateAsync(config) {
6
+ if (!config.scopes || config.scopes?.length === 0) {
7
+ throw new Error("scopes are required");
8
+ }
9
+ return ExpoSpotifySDKModule.authenticateAsync(config);
7
10
  }
8
11
  const Authenticate = {
9
12
  authenticateAsync,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,oBAAoB,MAAM,wBAAwB,CAAC;AAE1D,SAAS,WAAW;IAClB,OAAO,oBAAoB,CAAC,WAAW,EAAE,CAAC;AAC5C,CAAC;AAED,SAAS,iBAAiB,CAAC,MAAsB;IAC/C,OAAO,oBAAoB,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;AACnD,CAAC;AAED,MAAM,YAAY,GAAG;IACnB,iBAAiB;CAClB,CAAC;AAEF,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,CAAC","sourcesContent":["import { SpotifyScope, SpotifySession } from \"./ExpoSpotifySDK.types\";\nimport ExpoSpotifySDKModule from \"./ExpoSpotifySDKModule\";\n\nfunction isAvailable(): boolean {\n return ExpoSpotifySDKModule.isAvailable();\n}\n\nfunction authenticateAsync(scopes: SpotifyScope[]): Promise<SpotifySession> {\n return ExpoSpotifySDKModule.authenticate(scopes);\n}\n\nconst Authenticate = {\n authenticateAsync,\n};\n\nexport { isAvailable, Authenticate };\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,oBAAoB,MAAM,wBAAwB,CAAC;AAE1D,SAAS,WAAW;IAClB,OAAO,oBAAoB,CAAC,WAAW,EAAE,CAAC;AAC5C,CAAC;AAED,SAAS,iBAAiB,CAAC,MAAqB;IAC9C,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,KAAK,CAAC,EAAE,CAAC;QAClD,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;IACzC,CAAC;IAED,OAAO,oBAAoB,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;AACxD,CAAC;AAED,MAAM,YAAY,GAAG;IACnB,iBAAiB;CAClB,CAAC;AAEF,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,CAAC","sourcesContent":["import { SpotifyConfig, SpotifySession } from \"./ExpoSpotifySDK.types\";\nimport ExpoSpotifySDKModule from \"./ExpoSpotifySDKModule\";\n\nfunction isAvailable(): boolean {\n return ExpoSpotifySDKModule.isAvailable();\n}\n\nfunction authenticateAsync(config: SpotifyConfig): Promise<SpotifySession> {\n if (!config.scopes || config.scopes?.length === 0) {\n throw new Error(\"scopes are required\");\n }\n\n return ExpoSpotifySDKModule.authenticateAsync(config);\n}\n\nconst Authenticate = {\n authenticateAsync,\n};\n\nexport { isAvailable, Authenticate };\n"]}
@@ -4,22 +4,17 @@ struct ExpoSpotifyConfiguration: Codable {
4
4
  let clientID: String
5
5
  let host: String
6
6
  let scheme: String
7
- let tokenRefreshURL: URL?
8
- let tokenSwapURL: URL?
9
-
7
+
10
8
  var redirectURL: URL? {
11
9
  return URL(string: "\(scheme)://\(host)")
12
10
  }
13
-
11
+
14
12
  init(clientID: String = "defaultClientID",
15
13
  host: String = "defaultHost",
16
- scheme: String = "defaultScheme",
17
- tokenRefreshURL: URL? = nil,
18
- tokenSwapURL: URL? = nil) {
14
+ scheme: String = "defaultScheme"
15
+ ) {
19
16
  self.clientID = clientID
20
17
  self.host = host
21
18
  self.scheme = scheme
22
- self.tokenRefreshURL = tokenRefreshURL
23
- self.tokenSwapURL = tokenSwapURL
24
19
  }
25
20
  }
@@ -3,7 +3,6 @@ import SpotifyiOS
3
3
 
4
4
  public class ExpoSpotifySDKModule: Module {
5
5
 
6
-
7
6
  public func definition() -> ModuleDefinition {
8
7
 
9
8
  let spotifySession = ExpoSpotifySessionManager.shared
@@ -14,8 +13,16 @@ public class ExpoSpotifySDKModule: Module {
14
13
  return spotifySession.spotifyAppInstalled()
15
14
  }
16
15
 
17
- AsyncFunction("authenticate") { (scopes: [String], promise: Promise) in
18
- spotifySession.authenticate(requestedScopes: scopes).done { session in
16
+ AsyncFunction("authenticateAsync") { (config: [String: Any], promise: Promise) in
17
+ guard let scopes = config["scopes"] as? [String] else {
18
+ promise.reject("INVALID_CONFIG", "Invalid SpotifyConfig object")
19
+ return
20
+ }
21
+
22
+ let tokenSwapURL = config["tokenSwapURL"] as? String
23
+ let tokenRefreshURL = config["tokenRefreshURL"] as? String
24
+
25
+ spotifySession.authenticate(scopes: scopes, tokenSwapURL: tokenSwapURL, tokenRefreshURL: tokenRefreshURL).done { session in
19
26
  let sessionData: [String: Any] = [
20
27
  "accessToken": session.accessToken,
21
28
  "refreshToken": session.refreshToken,
@@ -4,14 +4,15 @@ import PromiseKit
4
4
 
5
5
  enum SessionManagerError: Error {
6
6
  case notInitialized
7
+ case invalidConfiguration
7
8
  }
8
9
 
9
10
  final class ExpoSpotifySessionManager: NSObject {
10
11
  weak var module: ExpoSpotifySDKModule?
11
12
  var authPromiseSeal: Resolver<SPTSession>?
12
-
13
+
13
14
  static let shared = ExpoSpotifySessionManager()
14
-
15
+
15
16
  private var expoSpotifyConfiguration: ExpoSpotifyConfiguration? {
16
17
  guard let expoSpotifySdkDict = Bundle.main.object(forInfoDictionaryKey: "ExpoSpotifySDK") as? [String: String],
17
18
  let clientID = expoSpotifySdkDict["clientID"],
@@ -20,63 +21,64 @@ final class ExpoSpotifySessionManager: NSObject {
20
21
  {
21
22
  return nil
22
23
  }
23
-
24
- let tokenRefreshURL = URL(string: expoSpotifySdkDict["tokenRefreshURL"] ?? "")
25
- let tokenSwapURL = URL(string: expoSpotifySdkDict["tokenSwapURL"] ?? "")
26
-
27
- return ExpoSpotifyConfiguration(clientID: clientID, host: host, scheme: scheme, tokenRefreshURL: tokenRefreshURL, tokenSwapURL: tokenSwapURL)
24
+
25
+ return ExpoSpotifyConfiguration(clientID: clientID, host: host, scheme: scheme)
28
26
  }
29
-
27
+
30
28
  lazy var configuration: SPTConfiguration? = {
31
29
  guard let clientID = expoSpotifyConfiguration?.clientID,
32
30
  let redirectURL = expoSpotifyConfiguration?.redirectURL else {
33
31
  NSLog("Invalid Spotify configuration")
34
32
  return nil
35
33
  }
36
-
34
+
37
35
  return SPTConfiguration(clientID: clientID, redirectURL: redirectURL)
38
36
  }()
39
-
37
+
40
38
  lazy var sessionManager: SPTSessionManager? = {
41
39
  guard let configuration = configuration else {
42
40
  return nil
43
41
  }
44
-
45
- configuration.tokenSwapURL = expoSpotifyConfiguration?.tokenSwapURL
46
- configuration.tokenRefreshURL = expoSpotifyConfiguration?.tokenRefreshURL
47
-
42
+
48
43
  return SPTSessionManager(configuration: configuration, delegate: self)
49
44
  }()
50
-
51
-
52
- func authenticate(requestedScopes: [String]) -> PromiseKit.Promise<SPTSession> {
45
+
46
+
47
+ func authenticate(scopes: [String], tokenSwapURL: String?, tokenRefreshURL: String?) -> PromiseKit.Promise<SPTSession> {
53
48
  return Promise { seal in
54
- guard let sessionManager = sessionManager else {
55
- NSLog("Session manager not initialized")
56
- seal.reject(SessionManagerError.notInitialized)
49
+ guard let clientID = expoSpotifyConfiguration?.clientID,
50
+ let redirectURL = expoSpotifyConfiguration?.redirectURL else {
51
+ NSLog("Invalid Spotify configuration")
52
+ seal.reject(SessionManagerError.invalidConfiguration)
57
53
  return
58
54
  }
55
+ let configuration = SPTConfiguration(clientID: clientID, redirectURL: redirectURL)
59
56
 
57
+ configuration.tokenSwapURL = URL(string: tokenSwapURL ?? "")
58
+ configuration.tokenRefreshURL = URL(string: tokenRefreshURL ?? "")
59
+
60
+ self.sessionManager = SPTSessionManager(configuration: configuration, delegate: self)
61
+
60
62
  self.authPromiseSeal = seal
61
-
63
+
62
64
  DispatchQueue.main.sync {
63
- sessionManager.initiateSession(with: SPTScopeSerializer.deserializeScopes(requestedScopes), options: .default)
65
+ sessionManager?.initiateSession(with: SPTScopeSerializer.deserializeScopes(scopes), options: .default)
64
66
  }
65
67
  }
66
68
  }
67
-
69
+
68
70
  func spotifyAppInstalled() -> Bool {
69
71
  guard let sessionManager = sessionManager else {
70
- NSLog("Session manager not initialized")
72
+ NSLog("SPTSessionManager not initialized")
71
73
  return false
72
74
  }
73
-
75
+
74
76
  var isInstalled = false
75
-
77
+
76
78
  DispatchQueue.main.sync {
77
79
  isInstalled = sessionManager.isSpotifyAppInstalled
78
80
  }
79
-
81
+
80
82
  return isInstalled
81
83
  }
82
84
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wwdrew/expo-spotify-sdk",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "Expo Module for native Spotify SDK",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -5,13 +5,16 @@ const withSpotifyAndroidAppBuildGradle_1 = require("./android/withSpotifyAndroid
5
5
  const withSpotifyQueryScheme_1 = require("./ios/withSpotifyQueryScheme");
6
6
  const withSpotifyURLScheme_1 = require("./ios/withSpotifyURLScheme");
7
7
  const withSpotifyConfig_1 = require("./withSpotifyConfig");
8
- const withSpotifySdkConfig = (config, spotifyConfig = {
9
- clientID: "clientID",
10
- host: "host",
11
- scheme: "scheme",
12
- tokenRefreshURL: "tokenRefreshURL",
13
- tokenSwapURL: "tokenSwapURL",
14
- }) => {
8
+ const withSpotifySdkConfig = (config, spotifyConfig) => {
9
+ if (!spotifyConfig.host) {
10
+ throw new Error("Missing required Spotify config value: host");
11
+ }
12
+ if (!spotifyConfig.scheme) {
13
+ throw new Error("Missing required Spotify config value: scheme");
14
+ }
15
+ if (!spotifyConfig.clientID) {
16
+ throw new Error("Missing required Spotify config value: clientID");
17
+ }
15
18
  config = (0, withSpotifyConfig_1.withSpotifyConfig)(config, spotifyConfig);
16
19
  // Android specific
17
20
  config = (0, withSpotifyAndroidAppBuildGradle_1.withSpotifyAndroidAppBuildGradle)(config, spotifyConfig);
@@ -3,6 +3,4 @@ export interface SpotifyConfig {
3
3
  clientID: string;
4
4
  host: string;
5
5
  scheme: string;
6
- tokenRefreshURL: string;
7
- tokenSwapURL: string;
8
6
  }