comty.js 0.64.0 → 0.65.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.
package/dist/index.js CHANGED
@@ -42,7 +42,6 @@ if (globalThis.isServerMode) {
42
42
  mainOrigin: origin,
43
43
  baseRequest: null,
44
44
  ws: null,
45
- rest: null,
46
45
  version: _packagejson2.default.version,
47
46
  addons: new (0, _addons2.default)(),
48
47
  })
@@ -35,7 +35,7 @@ var _session = require('../session'); var _session2 = _interopRequireDefault(_se
35
35
  _session2.default.refreshToken = response.data.refreshToken
36
36
 
37
37
  if (typeof callback === "function") {
38
- await callback()
38
+ await callback(response.data)
39
39
  }
40
40
 
41
41
  __comty_shared_state.eventBus.emit("auth:login_success")
@@ -0,0 +1,30 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2
+ var _request = require('../../request'); var _request2 = _interopRequireDefault(_request);
3
+
4
+ class E2EModel {
5
+ static async getKeyPair() {
6
+ const response = await _request2.default.call(void 0, {
7
+ method: "GET",
8
+ url: "/users/self/keypair",
9
+ })
10
+
11
+ return response.data
12
+ }
13
+
14
+ // WARNING: updating keypair makes all decryption fail
15
+ static async updateKeyPair(str, { imSure = false } = {}) {
16
+ if (imSure !== true) {
17
+ throw new Error(
18
+ "Missing confirmation to update the keypair. Use `imSure = true` to proceed.",
19
+ )
20
+ }
21
+
22
+ const response = await _request2.default.call(void 0, {
23
+ method: "POST",
24
+ url: "/users/self/keypair",
25
+ data: { str: str },
26
+ })
27
+
28
+ return response.data
29
+ }
30
+ } exports.default = E2EModel;
@@ -0,0 +1,25 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _request = require('../../../request'); var _request2 = _interopRequireDefault(_request);
2
+
3
+ exports. default = async (type, item_id) => {
4
+ if (!type) {
5
+ throw new Error("type is required")
6
+ }
7
+
8
+ if (!item_id) {
9
+ throw new Error("item_id is required")
10
+ }
11
+
12
+ type = type.toLowerCase()
13
+
14
+ const response = await _request2.default.call(void 0, {
15
+ method: "GET",
16
+ url: `/music/my/library/favorite`,
17
+ params: {
18
+ kind: type,
19
+ item_id: item_id,
20
+ },
21
+ })
22
+
23
+ // @ts-ignore
24
+ return response.data
25
+ }
@@ -0,0 +1,44 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _request = require('../../../request'); var _request2 = _interopRequireDefault(_request);
2
+ var _processWithAddons = require('../../../helpers/processWithAddons'); var _processWithAddons2 = _interopRequireDefault(_processWithAddons);
3
+ var _standartListMerge = require('../../../utils/standartListMerge'); var _standartListMerge2 = _interopRequireDefault(_standartListMerge);
4
+
5
+ exports. default = async ({ limit = 100, offset = 0, order = "desc", kind }) => {
6
+ const addons = __comty_shared_state.addons.getByOperation("getMyLibrary")
7
+
8
+ const dividedLimit = limit / (addons.length + 1)
9
+
10
+ const { data } = await _request2.default.call(void 0, {
11
+ method: "GET",
12
+ url: "/music/my/library",
13
+ params: {
14
+ limit: dividedLimit,
15
+ offset: offset,
16
+ order: order,
17
+ kind: kind,
18
+ },
19
+ })
20
+
21
+ let results = await _processWithAddons2.default.call(void 0, {
22
+ operation: "getMyLibrary",
23
+ initialData: data,
24
+ fnArguments: [{ limit: dividedLimit, offset: offset, order: order }],
25
+ normalizeAddonResult: ({ currentData, addonResult }) => {
26
+ return _standartListMerge2.default.call(void 0, currentData, addonResult)
27
+ },
28
+ })
29
+
30
+ // sort tracks by liked_at
31
+ if (results.tracks) {
32
+ results.tracks.items.sort((a, b) => {
33
+ if (a.liked_at > b.liked_at) {
34
+ return -1
35
+ }
36
+ if (a.liked_at < b.liked_at) {
37
+ return 1
38
+ }
39
+ return 0
40
+ })
41
+ }
42
+
43
+ return results
44
+ }
@@ -6,21 +6,17 @@
6
6
 
7
7
 
8
8
 
9
- exports. default = async ({
10
- limit,
11
- offset,
12
- keywords,
13
- }) => {
14
- const response = await _request2.default.call(void 0, {
15
- method: "GET",
16
- url: "/music/releases/self",
17
- params: {
18
- limit: limit,
19
- offset: offset,
20
- keywords: keywords,
21
- }
22
- })
23
-
24
- // @ts-ignore
25
- return response.data
26
- }
9
+ exports. default = async ({ limit, offset, keywords }) => {
10
+ const response = await _request2.default.call(void 0, {
11
+ method: "GET",
12
+ url: "/music/my/releases",
13
+ params: {
14
+ limit: limit,
15
+ offset: offset,
16
+ keywords: keywords,
17
+ },
18
+ })
19
+
20
+ // @ts-ignore
21
+ return response.data
22
+ }
@@ -6,24 +6,17 @@
6
6
 
7
7
 
8
8
 
9
-
10
- exports. default = async ({
11
- keywords,
12
- user_id,
13
- limit,
14
- offset,
15
- }) => {
16
- const response = await _request2.default.call(void 0, {
17
- method: "GET",
18
- url: "/music/releases",
19
- params: {
20
- keywords: keywords,
21
- user_id: user_id,
22
- limit: limit,
23
- offset: offset,
24
- }
25
- })
26
-
27
- // @ts-ignore
28
- return response.data
29
- }
9
+ exports. default = async ({ user_id, limit, page }) => {
10
+ const response = await _request2.default.call(void 0, {
11
+ method: "GET",
12
+ url: "/music/releases",
13
+ params: {
14
+ user_id: user_id,
15
+ limit: limit,
16
+ page: page,
17
+ },
18
+ })
19
+
20
+ // @ts-ignore
21
+ return response.data
22
+ }
@@ -9,23 +9,23 @@
9
9
 
10
10
 
11
11
  exports. default = async (
12
- id,
13
- options = {
14
- preferTranslation: false,
15
- }
12
+ id,
13
+ options = {
14
+ preferTranslation: false,
15
+ },
16
16
  ) => {
17
- const requestParams = Object()
17
+ const requestParams = Object()
18
18
 
19
- if (options.preferTranslation) {
20
- requestParams.translate_lang = app.cores.settings.get("app:language")
21
- }
19
+ if (options.preferTranslation) {
20
+ requestParams.translate_lang = app.cores.settings.get("app:language")
21
+ }
22
22
 
23
- const response = await _request2.default.call(void 0, {
24
- method: "GET",
25
- url: `/music/lyrics/${id}`,
26
- params: requestParams
27
- })
23
+ const response = await _request2.default.call(void 0, {
24
+ method: "GET",
25
+ url: `/music/tracks/${id}/lyrics`,
26
+ params: requestParams,
27
+ })
28
28
 
29
- // @ts-ignore
30
- return response.data
31
- }
29
+ // @ts-ignore
30
+ return response.data
31
+ }
@@ -6,24 +6,17 @@
6
6
 
7
7
 
8
8
 
9
-
10
- exports. default = async ({
11
- keywords,
12
- user_id,
13
- limit,
14
- offset,
15
- }) => {
16
- const response = await _request2.default.call(void 0, {
17
- method: "GET",
18
- url: "/music/tracks",
19
- params: {
20
- keywords: keywords,
21
- user_id: user_id,
22
- limit: limit,
23
- offset: offset,
24
- }
25
- })
26
-
27
- // @ts-ignore
28
- return response.data
29
- }
9
+ exports. default = async ({ user_id, limit, page }) => {
10
+ const response = await _request2.default.call(void 0, {
11
+ method: "GET",
12
+ url: "/music/tracks",
13
+ params: {
14
+ user_id: user_id,
15
+ limit: limit,
16
+ page: page,
17
+ },
18
+ })
19
+
20
+ // @ts-ignore
21
+ return response.data
22
+ }
@@ -2,150 +2,37 @@
2
2
  var _setters = require('./setters'); var _setters2 = _interopRequireDefault(_setters);
3
3
 
4
4
  class MusicModel {
5
- static __initStatic() {this.Getters = _getters2.default}
6
- static __initStatic2() {this.Setters = _setters2.default}
7
-
8
- /**
9
- * Performs a search based on the provided keywords, with optional parameters for limiting the number of results and pagination.
10
- *
11
- * @param {string} keywords - The keywords to search for.
12
- * @param {object} options - An optional object containing additional parameters.
13
- * @param {number} options.limit - The maximum number of results to return. Defaults to 5.
14
- * @param {number} options.offset - The offset to start returning results from. Defaults to 0.
15
- * @param {boolean} options.useTidal - Whether to use Tidal for the search. Defaults to false.
16
- * @return {Promise<Object>} The search results.
17
- */
18
- static __initStatic3() {this.search = _getters2.default.search}
19
-
20
- /**
21
- * Retrieves playlist items based on the provided parameters.
22
- *
23
- * @param {Object} options - The options object.
24
- * @param {string} options.playlist_id - The ID of the playlist.
25
- * @param {string} options.service - The service from which to retrieve the playlist items.
26
- * @param {number} options.limit - The maximum number of items to retrieve.
27
- * @param {number} options.offset - The number of items to skip before retrieving.
28
- * @return {Promise<Object>} Playlist items data.
29
- */
30
- static __initStatic4() {this.getPlaylistItems = _getters2.default.PlaylistItems}
31
-
32
- /**
33
- * Retrieves playlist data based on the provided parameters.
34
- *
35
- * @param {Object} options - The options object.
36
- * @param {string} options.playlist_id - The ID of the playlist.
37
- * @param {string} options.service - The service to use.
38
- * @param {number} options.limit - The maximum number of items to retrieve.
39
- * @param {number} options.offset - The offset for pagination.
40
- * @return {Promise<Object>} Playlist data.
41
- */
42
- static __initStatic5() {this.getPlaylistData = _getters2.default.PlaylistData}
43
-
44
- /**
45
- * Retrieves releases based on the provided parameters.
46
- * If user_id is not provided, it will retrieve self authenticated user releases.
47
- *
48
- * @param {object} options - The options for retrieving releases.
49
- * @param {string} options.user_id - The ID of the user.
50
- * @param {string[]} options.keywords - The keywords to filter releases by.
51
- * @param {number} options.limit - The maximum number of releases to retrieve.
52
- * @param {number} options.offset - The offset for paginated results.
53
- * @return {Promise<Object>} - A promise that resolves to the retrieved releases.
54
- */
55
- static __initStatic6() {this.getReleases = _getters2.default.releases}
56
-
57
- /**
58
- * Retrieves self releases.
59
- *
60
- * @param {object} options - The options for retrieving my releases.
61
- * @param {number} options.limit - The maximum number of releases to retrieve.
62
- * @param {number} options.offset - The offset for paginated results.
63
- * @return {Promise<Object>} - A promise that resolves to the retrieved releases.
64
- */
65
- static __initStatic7() {this.getMyReleases = _getters2.default.myReleases}
66
-
67
- /**
68
- * Retrieves release data by ID.
69
- *
70
- * @param {number} id - The ID of the release.
71
- * @return {Promise<Object>} The release data.
72
- */
73
- static __initStatic8() {this.getReleaseData = _getters2.default.releaseData}
74
-
75
- /**
76
- * Retrieves track data for a given ID.
77
- *
78
- * @param {string} id - The ID of the track or multiple IDs separated by commas.
79
- * @return {Promise<Object>} The track data.
80
- */
81
- static __initStatic9() {this.getTrackData = _getters2.default.trackData}
82
-
83
- /**
84
- * Retrieves the official featured playlists.
85
- *
86
- * @return {Promise<Object>} The data containing the featured playlists.
87
- */
88
- static __initStatic10() {this.getFeaturedPlaylists = _getters2.default.featuredPlaylists}
89
-
90
- /**
91
- * Retrieves track lyrics for a given ID.
92
- *
93
- * @param {string} id - The ID of the track.
94
- * @return {Promise<Object>} The track lyrics.
95
- */
96
- static __initStatic11() {this.getTrackLyrics = _getters2.default.trackLyrics}
97
-
98
-
99
- static __initStatic12() {this.putTrackLyrics = _setters2.default.putTrackLyrics}
100
-
101
- /**
102
- * Create or modify a track.
103
- *
104
- * @param {object} TrackManifest - The track manifest.
105
- * @return {Promise<Object>} The result track data.
106
- */
107
- static __initStatic13() {this.putTrack = _setters2.default.putTrack}
108
-
109
- /**
110
- * Create or modify a release.
111
- *
112
- * @param {object} ReleaseManifest - The release manifest.
113
- * @return {Promise<Object>} The result release data.
114
- */
115
- static __initStatic14() {this.putRelease = _setters2.default.putRelease}
116
-
117
- /**
118
- * Deletes a release by its ID.
119
- *
120
- * @param {string} id - The ID of the release to delete.
121
- * @return {Promise<Object>} - A Promise that resolves to the data returned by the API.
122
- */
123
- static __initStatic15() {this.deleteRelease = _setters2.default.deleteRelease}
124
-
125
- /**
126
- * Retrieves the favourite tracks of the current user.
127
- *
128
- * @return {Promise<Object>} The favorite tracks data.
129
- */
130
- static __initStatic16() {this.getFavouriteTracks = null}
131
-
132
- /**
133
- * Retrieves the favourite tracks/playlists/releases of the current user.
134
- *
135
- * @return {Promise<Object>} The favorite playlists data.
136
- */
137
- static __initStatic17() {this.getFavouriteFolder = _getters2.default.favouriteFolder}
138
-
139
- /**
140
- * Toggles the favourite status of a track, playlist or folder.
141
- *
142
- * @param {string} track_id - The ID of the track to toggle the favorite status.
143
- * @throws {Error} If the track_id is not provided.
144
- * @return {Promise<Object>} The response data after toggling the favorite status.
145
- */
146
- static __initStatic18() {this.toggleItemFavourite = _setters2.default.toggleItemFavourite}
147
-
148
- static __initStatic19() {this.isItemFavourited = _getters2.default.isItemFavourited}
149
-
150
- static __initStatic20() {this.getRecentyPlayed = _getters2.default.recentlyPlayed}
151
- } MusicModel.__initStatic(); MusicModel.__initStatic2(); MusicModel.__initStatic3(); MusicModel.__initStatic4(); MusicModel.__initStatic5(); MusicModel.__initStatic6(); MusicModel.__initStatic7(); MusicModel.__initStatic8(); MusicModel.__initStatic9(); MusicModel.__initStatic10(); MusicModel.__initStatic11(); MusicModel.__initStatic12(); MusicModel.__initStatic13(); MusicModel.__initStatic14(); MusicModel.__initStatic15(); MusicModel.__initStatic16(); MusicModel.__initStatic17(); MusicModel.__initStatic18(); MusicModel.__initStatic19(); MusicModel.__initStatic20(); exports.default = MusicModel;
5
+ static __initStatic() {this.Getters = _getters2.default}
6
+ static __initStatic2() {this.Setters = _setters2.default}
7
+
8
+ // track related methods
9
+ static __initStatic3() {this.getMyTracks = null}
10
+ static __initStatic4() {this.getAllTracks = _getters2.default.tracks}
11
+ static __initStatic5() {this.getTrackData = _getters2.default.trackData}
12
+ static __initStatic6() {this.putTrack = _setters2.default.putTrack}
13
+ static __initStatic7() {this.deleteTrack = null}
14
+
15
+ // lyrics related methods
16
+ static __initStatic8() {this.getTrackLyrics = _getters2.default.trackLyrics}
17
+ static __initStatic9() {this.putTrackLyrics = _setters2.default.putTrackLyrics}
18
+
19
+ // release related methods
20
+ static __initStatic10() {this.getMyReleases = _getters2.default.myReleases}
21
+ static __initStatic11() {this.getAllReleases = _getters2.default.releases}
22
+ static __initStatic12() {this.getReleaseData = _getters2.default.releaseData}
23
+ static __initStatic13() {this.putRelease = _setters2.default.putRelease}
24
+ static __initStatic14() {this.deleteRelease = _setters2.default.deleteRelease}
25
+
26
+ // library related methods
27
+ static __initStatic15() {this.getMyLibrary = _getters2.default.library}
28
+ static __initStatic16() {this.toggleItemFavorite = _setters2.default.toggleItemFavorite}
29
+ static __initStatic17() {this.isItemFavorited = _getters2.default.isItemFavorited}
30
+
31
+ // other methods
32
+ static __initStatic18() {this.getRecentyPlayed = _getters2.default.recentlyPlayed}
33
+ static __initStatic19() {this.search = _getters2.default.search}
34
+
35
+ // aliases
36
+ static __initStatic20() {this.toggleItemFavourite = MusicModel.toggleItemFavorite}
37
+ static __initStatic21() {this.isItemFavourited = MusicModel.isItemFavorited}
38
+ } MusicModel.__initStatic(); MusicModel.__initStatic2(); MusicModel.__initStatic3(); MusicModel.__initStatic4(); MusicModel.__initStatic5(); MusicModel.__initStatic6(); MusicModel.__initStatic7(); MusicModel.__initStatic8(); MusicModel.__initStatic9(); MusicModel.__initStatic10(); MusicModel.__initStatic11(); MusicModel.__initStatic12(); MusicModel.__initStatic13(); MusicModel.__initStatic14(); MusicModel.__initStatic15(); MusicModel.__initStatic16(); MusicModel.__initStatic17(); MusicModel.__initStatic18(); MusicModel.__initStatic19(); MusicModel.__initStatic20(); MusicModel.__initStatic21(); exports.default = MusicModel;
@@ -1,12 +1,12 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _request = require('../../../request'); var _request2 = _interopRequireDefault(_request);
2
2
 
3
3
  exports. default = async (track_id, data) => {
4
- const response = await _request2.default.call(void 0, {
5
- method: "put",
6
- url: `/music/lyrics/${track_id}`,
7
- data: data,
8
- })
4
+ const response = await _request2.default.call(void 0, {
5
+ method: "put",
6
+ url: `/music/tracks/${track_id}/lyrics`,
7
+ data: data,
8
+ })
9
9
 
10
- // @ts-ignore
11
- return response.data
12
- }
10
+ // @ts-ignore
11
+ return response.data
12
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _request = require('../../../request'); var _request2 = _interopRequireDefault(_request);
2
+
3
+ exports. default = async (type, item_id, to) => {
4
+ if (!type) {
5
+ throw new Error("type is required")
6
+ }
7
+
8
+ if (!item_id) {
9
+ throw new Error("item_id is required")
10
+ }
11
+
12
+ type = type.toLowerCase()
13
+
14
+ const response = await _request2.default.call(void 0, {
15
+ method: "PUT",
16
+ url: `/music/my/library/favorite`,
17
+ data: {
18
+ item_id: item_id,
19
+ kind: type,
20
+ to: to,
21
+ },
22
+ })
23
+
24
+ // @ts-ignore
25
+ return response.data
26
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _request = require('../../../request'); var _request2 = _interopRequireDefault(_request);
2
+
3
+ exports. default = async () => {
4
+ const { data } = await _request2.default.call(void 0, {
5
+ method: "GET",
6
+ url: "/music/radio/trendings",
7
+ })
8
+
9
+ return data
10
+ }
@@ -1,5 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _list = require('./getters/list'); var _list2 = _interopRequireDefault(_list);
2
+ var _trendings = require('./getters/trendings'); var _trendings2 = _interopRequireDefault(_trendings);
2
3
 
3
4
  class Radio {
4
5
  static __initStatic() {this.getRadioList = _list2.default}
5
- } Radio.__initStatic(); exports.default = Radio;
6
+ static __initStatic2() {this.getTrendings = _trendings2.default}
7
+ } Radio.__initStatic(); Radio.__initStatic2(); exports.default = Radio;
@@ -3,163 +3,168 @@ var _request = require('../../request'); var _request2 = _interopRequireDefault(
3
3
  var _withStorage = require('../../helpers/withStorage'); var _withStorage2 = _interopRequireDefault(_withStorage);
4
4
 
5
5
  class Session {
6
- static __initStatic() {this.storageTokenKey = "token"}
7
- static __initStatic2() {this.storageRefreshTokenKey = "refreshToken"}
8
-
9
- /**
10
- * Retrieves the token from the storage engine.
11
- *
12
- * @return {type} description of return value
13
- */
14
- static get token() {
15
- return _withStorage2.default.engine.get(this.storageTokenKey)
16
- }
17
-
18
- /**
19
- * Sets the token in the storage engine.
20
- *
21
- * @param {string} token - The token to be set.
22
- * @return {Promise<void>} A promise that resolves when the token is successfully set.
23
- */
24
- static set token(token) {
25
- return _withStorage2.default.engine.set(this.storageTokenKey, token)
26
- }
27
-
28
- /**
29
- * Retrieves the refresh token from the storage engine.
30
- *
31
- * @return {string} The refresh token stored in the storage engine.
32
- */
33
- static get refreshToken() {
34
- return _withStorage2.default.engine.get(this.storageRefreshTokenKey)
35
- }
36
-
37
- /**
38
- * Sets the refresh token in the storage engine.
39
- *
40
- * @param {string} token - The refresh token to be set.
41
- * @return {Promise<void>} A promise that resolves when the refresh token is successfully set.
42
- */
43
- static set refreshToken(token) {
44
- return _withStorage2.default.engine.set(this.storageRefreshTokenKey, token)
45
- }
46
-
47
- /**
48
- * Retrieves the roles from the decoded token object.
49
- *
50
- * @return {Array<string>|undefined} The roles if they exist, otherwise undefined.
51
- */
52
- static get roles() {
53
- return _optionalChain([this, 'access', _ => _.getDecodedToken, 'call', _2 => _2(), 'optionalAccess', _3 => _3.roles])
54
- }
55
-
56
- /**
57
- * Retrieves the user ID from the decoded token object.
58
- *
59
- * @return {string|undefined} The user ID if it exists, otherwise undefined.
60
- */
61
- static get user_id() {
62
- return _optionalChain([this, 'access', _4 => _4.getDecodedToken, 'call', _5 => _5(), 'optionalAccess', _6 => _6.user_id])
63
- }
64
-
65
- /**
66
- * Retrieves the session UUID from the decoded token object.
67
- *
68
- * @return {string} The session UUID if it exists, otherwise undefined.
69
- */
70
- static get session_uuid() {
71
- return _optionalChain([this, 'access', _7 => _7.getDecodedToken, 'call', _8 => _8(), 'optionalAccess', _9 => _9.session_uuid])
72
- }
73
-
74
- /**
75
- * Retrieves the decoded token from the session storage.
76
- *
77
- * @return {Object|null} The decoded token object if it exists, otherwise null.
78
- */
79
- static getDecodedToken() {
80
- const token = this.token
81
-
82
- return token && _jwtdecode.jwtDecode.call(void 0, token)
83
- }
84
-
85
- /**
86
- * Removes the token from the storage engine.
87
- *
88
- * @return {Promise<void>} A promise that resolves when the token is successfully removed.
89
- */
90
- static removeToken() {
91
- return _withStorage2.default.engine.remove(Session.storageTokenKey)
92
- }
93
-
94
- /**
95
- * Retrieves all sessions from the server.
96
- *
97
- * @return {Promise<Object>} The data of all sessions.
98
- */
99
- static async getAllSessions() {
100
- const response = await _request2.default.call(void 0, {
101
- method: "get",
102
- url: "/sessions/all"
103
- })
104
-
105
- return response.data
106
- }
107
-
108
- /**
109
- * Retrieves the current session from the server.
110
- *
111
- * @return {Promise<Object>} The data of the current session.
112
- */
113
- static async getCurrentSession() {
114
- const response = await _request2.default.call(void 0, {
115
- method: "get",
116
- url: "/sessions/current"
117
- })
118
-
119
- return response.data
120
- }
121
-
122
- /**
123
- * Destroys the current session by deleting it from the server.
124
- *
125
- * @return {Promise<Object>} The response data from the server after deleting the session.
126
- */
127
- static async destroyCurrentSession() {
128
- const token = await Session.token
129
- const session = await Session.getDecodedToken()
130
-
131
- if (!session || !token) {
132
- return false
133
- }
134
-
135
- const response = await _request2.default.call(void 0, {
136
- method: "delete",
137
- url: "/sessions/current"
138
- }).catch((error) => {
139
- console.error(error)
140
-
141
- return false
142
- })
143
-
144
- Session.removeToken()
145
-
146
- __comty_shared_state.eventBus.emit("session.destroyed")
147
-
148
- return response.data
149
- }
150
-
151
- static async destroyAllSessions() {
152
- throw new Error("Not implemented")
153
- }
154
-
155
- /**
156
- * Retrieves the validity of the current token.
157
- *
158
- * @return {boolean} The validity status of the current token.
159
- */
160
- static async isCurrentTokenValid() {
161
- const health = await Session.getTokenValidation()
162
-
163
- return health.valid
164
- }
165
- } Session.__initStatic(); Session.__initStatic2(); exports.default = Session;
6
+ static __initStatic() {this.storageTokenKey = "token"}
7
+ static __initStatic2() {this.storageRefreshTokenKey = "refreshToken"}
8
+
9
+ /**
10
+ * Retrieves the token from the storage engine.
11
+ *
12
+ * @return {type} description of return value
13
+ */
14
+ static get token() {
15
+ return _withStorage2.default.engine.get(this.storageTokenKey)
16
+ }
17
+
18
+ /**
19
+ * Sets the token in the storage engine.
20
+ *
21
+ * @param {string} token - The token to be set.
22
+ * @return {Promise<void>} A promise that resolves when the token is successfully set.
23
+ */
24
+ static set token(token) {
25
+ return _withStorage2.default.engine.set(this.storageTokenKey, token)
26
+ }
27
+
28
+ /**
29
+ * Retrieves the refresh token from the storage engine.
30
+ *
31
+ * @return {string} The refresh token stored in the storage engine.
32
+ */
33
+ static get refreshToken() {
34
+ return _withStorage2.default.engine.get(this.storageRefreshTokenKey)
35
+ }
36
+
37
+ /**
38
+ * Sets the refresh token in the storage engine.
39
+ *
40
+ * @param {string} token - The refresh token to be set.
41
+ * @return {Promise<void>} A promise that resolves when the refresh token is successfully set.
42
+ */
43
+ static set refreshToken(token) {
44
+ return _withStorage2.default.engine.set(this.storageRefreshTokenKey, token)
45
+ }
46
+
47
+ /**
48
+ * Retrieves the roles from the decoded token object.
49
+ *
50
+ * @return {Array<string>|undefined} The roles if they exist, otherwise undefined.
51
+ */
52
+ static get roles() {
53
+ return _optionalChain([this, 'access', _ => _.getDecodedToken, 'call', _2 => _2(), 'optionalAccess', _3 => _3.roles])
54
+ }
55
+
56
+ /**
57
+ * Retrieves the user ID from the decoded token object.
58
+ *
59
+ * @return {string|undefined} The user ID if it exists, otherwise undefined.
60
+ */
61
+ static get user_id() {
62
+ return _optionalChain([this, 'access', _4 => _4.getDecodedToken, 'call', _5 => _5(), 'optionalAccess', _6 => _6.user_id])
63
+ }
64
+
65
+ /**
66
+ * Retrieves the session UUID from the decoded token object.
67
+ *
68
+ * @return {string} The session UUID if it exists, otherwise undefined.
69
+ */
70
+ static get session_uuid() {
71
+ return _optionalChain([this, 'access', _7 => _7.getDecodedToken, 'call', _8 => _8(), 'optionalAccess', _9 => _9.session_uuid])
72
+ }
73
+
74
+ /**
75
+ * Retrieves the decoded token from the session storage.
76
+ *
77
+ * @return {Object|null} The decoded token object if it exists, otherwise null.
78
+ */
79
+ static getDecodedToken() {
80
+ const token = this.token
81
+
82
+ return token && _jwtdecode.jwtDecode.call(void 0, token)
83
+ }
84
+
85
+ /**
86
+ * Removes the token from the storage engine.
87
+ *
88
+ * @return {Promise<void>} A promise that resolves when the token is successfully removed.
89
+ */
90
+ static removeToken() {
91
+ return _withStorage2.default.engine.remove(Session.storageTokenKey)
92
+ }
93
+
94
+ /**
95
+ * Retrieves all sessions from the server.
96
+ *
97
+ * @return {Promise<Object>} The data of all sessions.
98
+ */
99
+ static async getAllSessions() {
100
+ const response = await _request2.default.call(void 0, {
101
+ method: "get",
102
+ url: "/sessions/all",
103
+ })
104
+
105
+ return response.data
106
+ }
107
+
108
+ /**
109
+ * Retrieves the current session from the server.
110
+ *
111
+ * @return {Promise<Object>} The data of the current session.
112
+ */
113
+ static async getCurrentSession() {
114
+ const response = await _request2.default.call(void 0, {
115
+ method: "get",
116
+ url: "/sessions/current",
117
+ })
118
+
119
+ return response.data
120
+ }
121
+
122
+ /**
123
+ * Destroys the current session by deleting it from the server.
124
+ *
125
+ * @return {Promise<Object>} The response data from the server after deleting the session.
126
+ */
127
+ static async destroyCurrentSession() {
128
+ const token = await Session.token
129
+ const session = await Session.getDecodedToken()
130
+
131
+ if (!session || !token) {
132
+ return false
133
+ }
134
+
135
+ const response = await _request2.default.call(void 0, {
136
+ method: "delete",
137
+ url: "/sessions/current",
138
+ }).catch((error) => {
139
+ console.error(error)
140
+
141
+ return false
142
+ })
143
+
144
+ Session.removeToken()
145
+
146
+ __comty_shared_state.eventBus.emit("session.destroyed")
147
+
148
+ return response.data
149
+ }
150
+
151
+ static async destroyAll() {
152
+ const response = await _request2.default.call(void 0, {
153
+ method: "delete",
154
+ url: "/sessions/all",
155
+ })
156
+
157
+ return response.data
158
+ }
159
+
160
+ /**
161
+ * Retrieves the validity of the current token.
162
+ *
163
+ * @return {boolean} The validity status of the current token.
164
+ */
165
+ static async isCurrentTokenValid() {
166
+ const health = await Session.getTokenValidation()
167
+
168
+ return health.valid
169
+ }
170
+ } Session.__initStatic(); Session.__initStatic2(); exports.default = Session;
@@ -1,8 +1,8 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _axios = require('axios'); var _axios2 = _interopRequireDefault(_axios);
2
+ var _src = require('linebridge-client/src');
3
+
2
4
  var _session = require('../session'); var _session2 = _interopRequireDefault(_session);
3
5
  var _user = require('../user'); var _user2 = _interopRequireDefault(_user);
4
- var _src = require('linebridge-client/src');
5
- //import { RTEngineClient } from "../../../../linebridge/client/src"
6
6
 
7
7
  async function injectUserDataOnList(list) {
8
8
  if (!Array.isArray(list)) {
@@ -73,7 +73,7 @@ async function injectUserDataOnList(list) {
73
73
 
74
74
  const { data } = await Streaming.base({
75
75
  method: "get",
76
- url: `/streaming/${stream_id}`,
76
+ url: `/stream/${stream_id}/data`,
77
77
  })
78
78
 
79
79
  return data
@@ -81,37 +81,51 @@ async function injectUserDataOnList(list) {
81
81
 
82
82
  static async getOwnProfiles() {
83
83
  const { data } = await Streaming.base({
84
- method: "get",
84
+ method: "GET",
85
85
  url: "/streaming/profiles/self",
86
86
  })
87
87
 
88
88
  return data
89
89
  }
90
90
 
91
- static async getProfile({ profile_id }) {
91
+ static async getProfile(profile_id) {
92
92
  if (!profile_id) {
93
93
  return null
94
94
  }
95
95
 
96
96
  const { data } = await Streaming.base({
97
- method: "get",
97
+ method: "GET",
98
98
  url: `/streaming/profiles/${profile_id}`,
99
99
  })
100
100
 
101
101
  return data
102
102
  }
103
103
 
104
- static async createOrUpdateProfile(update) {
104
+ static async createProfile(payload) {
105
105
  const { data } = await Streaming.base({
106
- method: "put",
107
- url: `/streaming/profiles/self`,
106
+ method: "POST",
107
+ url: "/streaming/profiles/new",
108
+ data: payload,
109
+ })
110
+
111
+ return data
112
+ }
113
+
114
+ static async updateProfile(profile_id, update) {
115
+ if (!profile_id) {
116
+ return null
117
+ }
118
+
119
+ const { data } = await Streaming.base({
120
+ method: "PUT",
121
+ url: `/streaming/profiles/${profile_id}`,
108
122
  data: update,
109
123
  })
110
124
 
111
125
  return data
112
126
  }
113
127
 
114
- static async deleteProfile({ profile_id }) {
128
+ static async deleteProfile(profile_id) {
115
129
  if (!profile_id) {
116
130
  return null
117
131
  }
@@ -124,6 +138,36 @@ async function injectUserDataOnList(list) {
124
138
  return data
125
139
  }
126
140
 
141
+ static async addRestreamToProfile(profileId, restreamData) {
142
+ if (!profileId) {
143
+ console.error("profileId is required to add a restream")
144
+ return null
145
+ }
146
+
147
+ const { data } = await Streaming.base({
148
+ method: "put",
149
+ url: `/streaming/profiles/${profileId}/restreams`,
150
+ data: restreamData,
151
+ })
152
+
153
+ return data
154
+ }
155
+
156
+ static async deleteRestreamFromProfile(profileId, restreamIndexData) {
157
+ if (!profileId) {
158
+ console.error("profileId is required to delete a restream")
159
+ return null
160
+ }
161
+
162
+ const { data } = await Streaming.base({
163
+ method: "delete",
164
+ url: `/streaming/profiles/${profileId}/restreams`,
165
+ data: restreamIndexData,
166
+ })
167
+
168
+ return data
169
+ }
170
+
127
171
  static async list({ limit, offset } = {}) {
128
172
  let { data } = await Streaming.base({
129
173
  method: "get",
@@ -145,11 +189,7 @@ async function injectUserDataOnList(list) {
145
189
  return null
146
190
  }
147
191
 
148
- const client = new (0, _src.RTEngineClient)({
149
- ...params,
150
- url: Streaming.apiHostname,
151
- token: _session2.default.token,
152
- })
192
+ const client = Streaming.createWebsocket(params)
153
193
 
154
194
  client._destroy = client.destroy
155
195
 
@@ -171,4 +211,14 @@ async function injectUserDataOnList(list) {
171
211
 
172
212
  return client
173
213
  }
214
+
215
+ static createWebsocket(params = {}) {
216
+ const client = new (0, _src.RTEngineClient)({
217
+ ...params,
218
+ url: Streaming.apiHostname,
219
+ token: _session2.default.token,
220
+ })
221
+
222
+ return client
223
+ }
174
224
  } Streaming.__initStatic(); exports.default = Streaming;
@@ -14,7 +14,15 @@ var _request = require('../../request'); var _request2 = _interopRequireDefault(
14
14
  let { username, user_id, basic = false } = payload
15
15
 
16
16
  if (!username && !user_id) {
17
- user_id = _session2.default.user_id
17
+ const response = await _request2.default.call(void 0, {
18
+ method: "GET",
19
+ url: `/users/self`,
20
+ params: {
21
+ basic,
22
+ },
23
+ })
24
+
25
+ return response.data
18
26
  }
19
27
 
20
28
  if (username && !user_id) {
@@ -132,4 +140,29 @@ var _request = require('../../request'); var _request2 = _interopRequireDefault(
132
140
 
133
141
  return data
134
142
  }
143
+
144
+ static async getPublicKey(user_id) {
145
+ if (!user_id) {
146
+ user_id = _session2.default.user_id
147
+ }
148
+
149
+ const { data } = await _request2.default.call(void 0, {
150
+ method: "GET",
151
+ url: `/users/${user_id}/public-key`,
152
+ })
153
+
154
+ return data
155
+ }
156
+
157
+ static async updatePublicKey(public_key) {
158
+ const { data } = await _request2.default.call(void 0, {
159
+ method: "PUT",
160
+ url: `/users/self/public-key`,
161
+ data: {
162
+ public_key: public_key,
163
+ },
164
+ })
165
+
166
+ return data
167
+ }
135
168
  } exports.default = User;
@@ -31,15 +31,18 @@ const fetchers = {
31
31
  resolve("failed")
32
32
  }, 5000)
33
33
 
34
- globalThis.__comty_shared_state.ws.sockets
35
- .get("main")
36
- .once("pong", () => {
37
- failTimeout && clearTimeout(failTimeout)
34
+ const sockets = globalThis.__comty_shared_state.ws.sockets
35
+ let firstSocket = sockets.keys().next().value
38
36
 
39
- resolve(Date.now() - start)
40
- })
37
+ firstSocket = sockets.get(firstSocket)
38
+
39
+ firstSocket.once("pong", () => {
40
+ failTimeout && clearTimeout(failTimeout)
41
+
42
+ resolve(Date.now() - start)
43
+ })
41
44
 
42
- globalThis.__comty_shared_state.ws.sockets.get("main").emit("ping")
45
+ firstSocket.emit("ping")
43
46
  }),
44
47
  }
45
48
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "comty.js",
3
- "version": "0.64.0",
3
+ "version": "0.65.0",
4
4
  "main": "./dist/index.js",
5
5
  "description": "Official Comty API for JavaScript",
6
6
  "homepage": "https://github.com/ragestudio/comty.js",