comty.js 0.52.2 → 0.55.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.
@@ -0,0 +1,37 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _request = require('../../handlers/request'); var _request2 = _interopRequireDefault(_request);
2
+
3
+ class MusicModel {
4
+ static get api_instance() {
5
+ return globalThis.__comty_shared_state.instances["music"]
6
+ }
7
+
8
+ static __initStatic() {this.getFavorites = async () => {
9
+ const { data } = await _request2.default.call(void 0, {
10
+ instance: MusicModel.api_instance,
11
+ method: "GET",
12
+ url: `/tracks/liked`,
13
+ })
14
+
15
+ return data
16
+ }}
17
+
18
+ static __initStatic2() {this.search = async (keywords, {
19
+ limit = 5,
20
+ offset = 0,
21
+ useTidal = false,
22
+ }) => {
23
+ const { data } = await _request2.default.call(void 0, {
24
+ instance: MusicModel.api_instance,
25
+ method: "GET",
26
+ url: `/search`,
27
+ params: {
28
+ keywords,
29
+ limit,
30
+ offset,
31
+ useTidal,
32
+ }
33
+ })
34
+
35
+ return data
36
+ }}
37
+ } MusicModel.__initStatic(); MusicModel.__initStatic2(); exports.default = MusicModel;
@@ -1,11 +1,47 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _spotifyCore = require('./cores/spotifyCore'); var _spotifyCore2 = _interopRequireDefault(_spotifyCore);
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _spotify = require('./services/spotify'); var _spotify2 = _interopRequireDefault(_spotify);
2
+ var _tidal = require('./services/tidal'); var _tidal2 = _interopRequireDefault(_tidal);
3
+
4
+ const namespacesServices = {
5
+ spotify: _spotify2.default,
6
+ tidal: _tidal2.default
7
+ }
2
8
 
3
9
  class SyncModel {
4
- static get bridge() {
5
- return _optionalChain([window, 'access', _ => _.app, 'optionalAccess', _2 => _2.cores, 'access', _3 => _3.api, 'access', _4 => _4.withEndpoints, 'call', _5 => _5()])
10
+ static get spotifyCore() {
11
+ return namespacesServices.spotify
6
12
  }
7
13
 
8
- static get spotifyCore() {
9
- return _spotifyCore2.default
14
+ static get tidalCore() {
15
+ return namespacesServices.tidal
16
+ }
17
+
18
+ static async linkService(namespace) {
19
+ const service = namespacesServices[namespace]
20
+
21
+ if (!service || typeof service.linkAccount !== "function") {
22
+ throw new Error(`Service ${namespace} not found or not accepting linking.`)
23
+ }
24
+
25
+ return await service.linkAccount()
26
+ }
27
+
28
+ static async unlinkService(namespace) {
29
+ const service = namespacesServices[namespace]
30
+
31
+ if (!service || typeof service.unlinkAccount !== "function") {
32
+ throw new Error(`Service ${namespace} not found or not accepting unlinking.`)
33
+ }
34
+
35
+ return await service.unlinkAccount()
36
+ }
37
+
38
+ static async hasServiceLinked(namespace) {
39
+ const service = namespacesServices[namespace]
40
+
41
+ if (!service || typeof service.isActive !== "function") {
42
+ throw new Error(`Service ${namespace} not found or not accepting linking.`)
43
+ }
44
+
45
+ return await service.isActive()
10
46
  }
11
47
  } exports.default = SyncModel;
@@ -0,0 +1,87 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); class SpotifySyncModel {
2
+ static get spotify_redirect_uri() {
3
+ return window.location.origin + "/callbacks/sync/spotify"
4
+ }
5
+
6
+ static get spotify_authorize_endpoint() {
7
+ return "https://accounts.spotify.com/authorize?response_type=code&client_id={{client_id}}&scope={{scope}}&redirect_uri={{redirect_uri}}&response_type=code"
8
+ }
9
+
10
+ static async authorizeAccount() {
11
+ const scopes = [
12
+ "user-read-private",
13
+ "user-modify-playback-state",
14
+ "user-read-currently-playing",
15
+ "user-read-playback-state",
16
+ "streaming",
17
+ ]
18
+
19
+ const { client_id } = await SpotifySyncModel.get_client_id()
20
+
21
+ const parsedUrl = SpotifySyncModel.spotify_authorize_endpoint
22
+ .replace("{{client_id}}", client_id)
23
+ .replace("{{scope}}", scopes.join(" "))
24
+ .replace("{{redirect_uri}}", SpotifySyncModel.spotify_redirect_uri)
25
+
26
+ // open on a new tab
27
+ window.open(parsedUrl, "_blank")
28
+ }
29
+
30
+ static async get_client_id() {
31
+ const { data } = await app.cores.api.customRequest({
32
+ method: "GET",
33
+ url: `/sync/spotify/client_id`,
34
+ })
35
+
36
+ return data
37
+ }
38
+
39
+ static async syncAuthCode(code) {
40
+ const { data } = await app.cores.api.customRequest({
41
+ method: "POST",
42
+ url: `/sync/spotify/auth`,
43
+ data: {
44
+ redirect_uri: SpotifySyncModel.spotify_redirect_uri,
45
+ code,
46
+ },
47
+ })
48
+
49
+ return data
50
+ }
51
+
52
+ static async unlinkAccount() {
53
+ const { data } = await app.cores.api.customRequest({
54
+ method: "POST",
55
+ url: `/sync/spotify/unlink`,
56
+ })
57
+
58
+ return data
59
+ }
60
+
61
+ static async isAuthorized() {
62
+ const { data } = await app.cores.api.customRequest({
63
+ method: "GET",
64
+ url: `/sync/spotify/is_authorized`,
65
+ })
66
+
67
+ return data
68
+ }
69
+
70
+ static async getData() {
71
+ const { data } = await app.cores.api.customRequest({
72
+ method: "GET",
73
+ url: `/sync/spotify/data`,
74
+ })
75
+
76
+ return data
77
+ }
78
+
79
+ static async getCurrentPlaying() {
80
+ const { data } = await app.cores.api.customRequest({
81
+ method: "GET",
82
+ url: `/sync/spotify/currently_playing`,
83
+ })
84
+
85
+ return data
86
+ }
87
+ } exports.default = SpotifySyncModel;
@@ -0,0 +1,83 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _request = require('../../../handlers/request'); var _request2 = _interopRequireDefault(_request);
2
+
3
+ class TidalService {
4
+ static get api_instance() {
5
+ return globalThis.__comty_shared_state.instances["sync"]
6
+ }
7
+
8
+ static async linkAccount() {
9
+ if (!window) {
10
+ throw new Error("This method is only available in the browser.")
11
+ }
12
+
13
+ const { data } = await _request2.default.call(void 0, {
14
+ instance: TidalService.api_instance,
15
+ method: "GET",
16
+ url: `/services/tidal/create_link`,
17
+ })
18
+
19
+ if (data.auth_url) {
20
+ window.open(data.auth_url, "_blank")
21
+ }
22
+
23
+ return data
24
+ }
25
+
26
+ static async unlinkAccount() {
27
+ if (!window) {
28
+ throw new Error("This method is only available in the browser.")
29
+ }
30
+
31
+ const { data } = await _request2.default.call(void 0, {
32
+ instance: TidalService.api_instance,
33
+ method: "POST",
34
+ url: `/services/tidal/delete_link`,
35
+ })
36
+
37
+ return data
38
+ }
39
+
40
+ static async isActive() {
41
+ if (!window) {
42
+ throw new Error("This method is only available in the browser.")
43
+ }
44
+
45
+ const { data } = await _request2.default.call(void 0, {
46
+ instance: TidalService.api_instance,
47
+ method: "GET",
48
+ url: `/services/tidal/is_active`,
49
+ })
50
+
51
+ return data
52
+ }
53
+
54
+ static async getCurrentUser() {
55
+ const { data } = await _request2.default.call(void 0, {
56
+ instance: TidalService.api_instance,
57
+ method: "GET",
58
+ url: `/services/tidal/current`,
59
+ })
60
+
61
+ return data
62
+ }
63
+
64
+ static async getPlaybackUrl(track_id) {
65
+ const { data } = await _request2.default.call(void 0, {
66
+ instance: TidalService.api_instance,
67
+ method: "GET",
68
+ url: `/services/tidal/playback/${track_id}`,
69
+ })
70
+
71
+ return data
72
+ }
73
+
74
+ static async getTrackManifest(track_id) {
75
+ const { data } = await _request2.default.call(void 0, {
76
+ instance: TidalService.api_instance,
77
+ method: "GET",
78
+ url: `/services/tidal/manifest/${track_id}`,
79
+ })
80
+
81
+ return data
82
+ }
83
+ } exports.default = TidalService;
package/dist/remotes.js CHANGED
@@ -24,14 +24,16 @@ const envOrigins = {
24
24
  marketplace: `http://${getCurrentHostname()}:3040`,
25
25
  music: `http://${getCurrentHostname()}:3050`,
26
26
  files: `http://${getCurrentHostname()}:3060`,
27
+ sync: `http://${getCurrentHostname()}:3070`,
27
28
  },
28
29
  "indev": {
29
- default: `https://indev_api.comty.app/default`,
30
+ default: `https://indev_api.comty.app/main`,
30
31
  chat: `https://indev_api.comty.app/chat`,
31
32
  livestreaming: `https://indev_api.comty.app/livestreaming`,
32
33
  marketplace: `https://indev_api.comty.app/marketplace`,
33
34
  music: `https://indev_api.comty.app/music`,
34
35
  files: `https://indev_api.comty.app/files`,
36
+ sync: `https://indev_api.comty.app/sync`,
35
37
  },
36
38
  "production": {
37
39
  default: "https://api.comty.app",
@@ -40,6 +42,7 @@ const envOrigins = {
40
42
  marketplace: `https://marketplace_api.comty.app`,
41
43
  music: `https://music_api.comty.app`,
42
44
  files: `https://files_api.comty.app`,
45
+ sync: `https://sync_api.comty.app`,
43
46
  }
44
47
  }
45
48
 
@@ -67,5 +70,9 @@ exports. default = {
67
70
  files: {
68
71
  origin: composeRemote("files"),
69
72
  hasWebsocket: false,
73
+ },
74
+ sync: {
75
+ origin: composeRemote("sync"),
76
+ hasWebsocket: false,
70
77
  }
71
78
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "comty.js",
3
- "version": "0.52.2",
3
+ "version": "0.55.0",
4
4
  "main": "./dist/index.js",
5
5
  "author": "RageStudio <support@ragestudio.net>",
6
6
  "scripts": {