comty.js 0.59.2 → 0.60.3

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.
Files changed (48) hide show
  1. package/dist/handlers/measurePing.js +0 -0
  2. package/dist/handlers/request.js +0 -0
  3. package/dist/helpers/handleAfterRequest.js +14 -14
  4. package/dist/helpers/handleBeforeRequest.js +3 -9
  5. package/dist/helpers/handleRegenerationEvent.js +0 -0
  6. package/dist/helpers/measurePing.js +62 -0
  7. package/dist/helpers/refreshToken.js +42 -0
  8. package/dist/helpers/withSettings.js +0 -0
  9. package/dist/helpers/withStorage.js +0 -0
  10. package/dist/hooks/useRequest/index.js +3 -4
  11. package/dist/index.js +107 -87
  12. package/dist/models/auth/index.js +115 -33
  13. package/dist/models/chats/index.js +37 -0
  14. package/dist/models/feed/index.js +46 -14
  15. package/dist/models/follows/index.js +36 -18
  16. package/dist/models/index.js +1 -4
  17. package/dist/models/livestream/index.js +0 -0
  18. package/dist/models/music/getters/featuredPlaylists.js +11 -0
  19. package/dist/models/music/getters/index.js +36 -0
  20. package/dist/models/music/getters/myReleases.js +26 -0
  21. package/dist/models/music/getters/playlistData.js +11 -0
  22. package/dist/models/music/getters/playlistItem.js +11 -0
  23. package/dist/models/music/getters/playlists.js +29 -0
  24. package/dist/models/music/getters/releaseData.js +11 -0
  25. package/dist/models/music/getters/releases.js +29 -0
  26. package/dist/models/music/getters/search.js +26 -0
  27. package/dist/models/music/getters/trackData.js +12 -0
  28. package/dist/models/music/getters/trackLyrics.js +31 -0
  29. package/dist/models/music/getters/tracks.js +29 -0
  30. package/dist/models/music/index.js +95 -240
  31. package/dist/models/nfc/index.js +27 -1
  32. package/dist/models/playlists/index.js +0 -0
  33. package/dist/models/post/index.js +133 -70
  34. package/dist/models/search/index.js +17 -4
  35. package/dist/models/session/index.js +105 -56
  36. package/dist/models/sync/cores/spotifyCore.js +0 -0
  37. package/dist/models/sync/index.js +9 -15
  38. package/dist/models/sync/services/spotify.js +0 -0
  39. package/dist/models/sync/services/tidal.js +1 -1
  40. package/dist/models/sync/services/vrc.js +0 -0
  41. package/dist/models/user/index.js +78 -100
  42. package/dist/models/widget/index.js +0 -0
  43. package/dist/remote.js +43 -0
  44. package/dist/remotes.js +5 -63
  45. package/dist/request.js +51 -0
  46. package/dist/utils/generateRequest.js +52 -0
  47. package/dist/utils/importFrom.js +22 -0
  48. package/package.json +5 -4
@@ -1,8 +1,16 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _session = require('../session'); var _session2 = _interopRequireDefault(_session);
2
- var _request = require('../../handlers/request'); var _request2 = _interopRequireDefault(_request);
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }var _session = require('../session'); var _session2 = _interopRequireDefault(_session);
2
+ var _request = require('../../request'); var _request2 = _interopRequireDefault(_request);
3
3
 
4
4
  class User {
5
- static __initStatic() {this.data = async (payload = {}) => {
5
+ /**
6
+ * Retrieves the data of a user.
7
+ *
8
+ * @param {Object} payload - An object containing the username and user_id.
9
+ * @param {string} payload.username - The username of the user.
10
+ * @param {string} payload.user_id - The ID of the user.
11
+ * @return {Promise<Object>} - A promise that resolves with the data of the user.
12
+ */
13
+ static async data(payload = {}) {
6
14
  let {
7
15
  username,
8
16
  user_id,
@@ -16,7 +24,7 @@ var _request = require('../../handlers/request'); var _request2 = _interopRequir
16
24
  // resolve user_id from username
17
25
  const resolveResponse = await _request2.default.call(void 0, {
18
26
  method: "GET",
19
- url: `/user/user_id/${username}`,
27
+ url: `/users/${username}/resolve-user_id`,
20
28
  })
21
29
 
22
30
  user_id = resolveResponse.data.user_id
@@ -24,136 +32,106 @@ var _request = require('../../handlers/request'); var _request2 = _interopRequir
24
32
 
25
33
  const response = await _request2.default.call(void 0, {
26
34
  method: "GET",
27
- url: `/user/${user_id}/data`,
35
+ url: `/users/${user_id}/data`,
28
36
  })
29
37
 
30
38
  return response.data
31
- }}
32
-
33
- static __initStatic2() {this.updateData = async (payload) => {
39
+ }
40
+
41
+ /**
42
+ * Updates the user data with the given payload.
43
+ *
44
+ * @param {Object} payload - The data to update the user with.
45
+ * @return {Promise<Object>} - A promise that resolves with the updated user data.
46
+ */
47
+ static async updateData(payload) {
34
48
  const response = await _request2.default.call(void 0, {
35
49
  method: "POST",
36
- url: "/user/self/update_data",
50
+ url: "/users/self/update",
37
51
  data: {
38
52
  update: payload,
39
53
  },
40
54
  })
41
55
 
42
56
  return response.data
43
- }}
44
-
45
- static __initStatic3() {this.unsetFullName = async () => {
46
- const response = await _request2.default.call(void 0, {
47
- method: "DELETE",
48
- url: "/user/self/public_name",
57
+ }
58
+
59
+ /**
60
+ * Update the public name to null in the user data.
61
+ *
62
+ * @return {Promise} A Promise that resolves with the response data after updating the public name
63
+ */
64
+ static async unsetPublicName() {
65
+ return await User.updateData({
66
+ public_name: null,
49
67
  })
50
-
51
- return response.data
52
- }}
53
-
54
- static __initStatic4() {this.selfRoles = async () => {
68
+ }
69
+
70
+ /**
71
+ * Retrieves the roles of a user.
72
+ *
73
+ * @param {string} user_id - The ID of the user. If not provided, the current user ID will be used.
74
+ * @return {Promise<Array>} An array of roles for the user.
75
+ */
76
+ static async getRoles(user_id) {
55
77
  const response = await _request2.default.call(void 0, {
56
78
  method: "GET",
57
- url: "/roles/self",
79
+ url: `/users/${_nullishCoalesce(user_id, () => ( "self"))}/roles`,
58
80
  })
59
81
 
60
82
  return response.data
61
- }}
62
-
63
- static __initStatic5() {this.haveRole = async (role) => {
64
- const roles = await User.selfRoles()
65
-
66
- if (!roles) {
67
- return false
68
- }
69
-
70
- return Array.isArray(roles) && roles.includes(role)
71
- }}
72
-
73
- static __initStatic6() {this.haveAdmin = async () => {
74
- return User.haveRole("admin")
75
- }}
76
-
77
- static __initStatic7() {this.getUserBadges = async (user_id) => {
83
+ }
84
+
85
+ /**
86
+ * Retrieves the badges for a given user.
87
+ *
88
+ * @param {string} user_id - The ID of the user. If not provided, the current session user ID will be used.
89
+ * @return {Promise<Array>} An array of badges for the user.
90
+ */
91
+ static async getBadges(user_id) {
78
92
  if (!user_id) {
79
93
  user_id = _session2.default.user_id
80
94
  }
81
95
 
82
96
  const { data } = await _request2.default.call(void 0, {
83
97
  method: "GET",
84
- url: `/badge/user/${user_id}`,
85
- })
86
-
87
- return data
88
- }}
89
-
90
- static __initStatic8() {this.changePassword = async (payload) => {
91
- const { currentPassword, newPassword } = payload
92
-
93
- const { data } = await _request2.default.call(void 0, {
94
- method: "POST",
95
- url: "/user/self/update_password",
96
- data: {
97
- currentPassword,
98
- newPassword,
99
- }
100
- })
101
-
102
- return data
103
- }}
104
-
105
- static __initStatic9() {this.getUserFollowers = async ({
106
- user_id,
107
- limit = 20,
108
- offset = 0,
109
- }) => {
110
- // if user_id or username is not provided, set with current user
111
- if (!user_id && !username) {
112
- user_id = _session2.default.user_id
113
- }
114
-
115
- const { data } = await _request2.default.call(void 0, {
116
- method: "GET",
117
- url: `/user/${user_id}/followers`,
118
- params: {
119
- limit,
120
- offset,
121
- }
98
+ url: `/users/${user_id}/badges`,
122
99
  })
123
100
 
124
101
  return data
125
- }}
126
-
127
- static __initStatic10() {this.getConnectedUsersFollowing = async () => {
102
+ }
103
+
104
+ /**
105
+ * Retrive user config from server
106
+ *
107
+ * @param {type} key - A key of config
108
+ * @return {object} - Config object
109
+ */
110
+ static async getConfig(key) {
128
111
  const { data } = await _request2.default.call(void 0, {
129
112
  method: "GET",
130
- url: "/status/connected/following",
131
- })
132
-
133
- return data
134
- }}
135
-
136
- static __initStatic11() {this.checkUsernameAvailability = async (username) => {
137
- const { data } = await _request2.default.call(void 0, {
138
- method: "GET",
139
- url: `/user/username_available`,
113
+ url: "/users/self/config",
140
114
  params: {
141
- username,
115
+ key
142
116
  }
143
117
  })
144
118
 
145
119
  return data
146
- }}
147
-
148
- static __initStatic12() {this.checkEmailAvailability = async (email) => {
120
+ }
121
+
122
+ /**
123
+ * Update the configuration with the given update.
124
+ *
125
+ * @param {Object} update - The object containing the updated configuration data
126
+ * @return {Promise} A Promise that resolves with the response data after the configuration is updated
127
+ */
128
+ static async updateConfig(update) {
149
129
  const { data } = await _request2.default.call(void 0, {
150
- method: "GET",
151
- url: `/user/email_available`,
152
- params: {
153
- email,
154
- }
130
+ method: "PUT",
131
+ url: "/users/self/config",
132
+ data: update
155
133
  })
156
134
 
157
135
  return data
158
- }}
159
- } User.__initStatic(); User.__initStatic2(); User.__initStatic3(); User.__initStatic4(); User.__initStatic5(); User.__initStatic6(); User.__initStatic7(); User.__initStatic8(); User.__initStatic9(); User.__initStatic10(); User.__initStatic11(); User.__initStatic12(); exports.default = User;
136
+ }
137
+ } exports.default = User;
File without changes
package/dist/remote.js ADDED
@@ -0,0 +1,43 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } 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; }function getCurrentHostname() {
2
+ if (typeof window === "undefined") {
3
+ return "localhost"
4
+ }
5
+
6
+ return _nullishCoalesce(_optionalChain([window, 'optionalAccess', _ => _.location, 'optionalAccess', _2 => _2.hostname]), () => ( "localhost"))
7
+ }
8
+
9
+ function getCurrentProtocol() {
10
+ if (typeof window === "undefined") {
11
+ return "http"
12
+ }
13
+
14
+ return _nullishCoalesce(_optionalChain([window, 'optionalAccess', _3 => _3.location, 'optionalAccess', _4 => _4.protocol]), () => ( "http:"))
15
+ }
16
+
17
+ const envOrigins = {
18
+ "development": `${getCurrentProtocol()}//${getCurrentHostname()}:9000`,
19
+ "indev": "https://indev_api.comty.app",
20
+ "production": "https://api.comty.app",
21
+ }
22
+
23
+ exports. default = {
24
+ origin: envOrigins[_nullishCoalesce(process.env.NODE_ENV, () => ( "production"))],
25
+ websockets: [
26
+ {
27
+ namespace: "posts",
28
+ path: "/posts",
29
+ },
30
+ {
31
+ namespace: "main",
32
+ path: "/main",
33
+ },
34
+ {
35
+ namespace: "notifications",
36
+ path: "/notifications",
37
+ },
38
+ {
39
+ namespace: "chats",
40
+ path: "/chats",
41
+ }
42
+ ]
43
+ }
package/dist/remotes.js CHANGED
@@ -1,14 +1,4 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } 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; }function composeRemote(path) {
2
- if (typeof window !== "undefined") {
3
- if (window.localStorage.getItem("comty:use_indev") || window.location.hostname === "indev.comty.app") {
4
- return envOrigins["indev"][path]
5
- }
6
- }
7
-
8
- return envOrigins[_nullishCoalesce(globalThis._force_comtyjs_env, () => ( "production"))][path]
9
- }
10
-
11
- function getCurrentHostname() {
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } 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; }function getCurrentHostname() {
12
2
  if (typeof window === "undefined") {
13
3
  return "localhost"
14
4
  }
@@ -17,62 +7,14 @@ function getCurrentHostname() {
17
7
  }
18
8
 
19
9
  const envOrigins = {
20
- "development": {
21
- default: `http://${getCurrentHostname()}:3010`,
22
- chat: `http://${getCurrentHostname()}:3020`,
23
- livestreaming: `http://${getCurrentHostname()}:3030`,
24
- marketplace: `http://${getCurrentHostname()}:3040`,
25
- music: `http://${getCurrentHostname()}:3050`,
26
- files: `http://${getCurrentHostname()}:3060`,
27
- sync: `http://${getCurrentHostname()}:3070`,
28
- },
29
- "indev": {
30
- default: `https://indev_api.comty.app/main`,
31
- chat: `https://indev_api.comty.app/chat`,
32
- livestreaming: `https://indev_api.comty.app/livestreaming`,
33
- marketplace: `https://indev_api.comty.app/marketplace`,
34
- music: `https://indev_api.comty.app/music`,
35
- files: `https://indev_api.comty.app/files`,
36
- sync: `https://indev_api.comty.app/sync`,
37
- },
38
- "production": {
39
- default: "https://api.comty.app",
40
- chat: `https://chat_api.comty.app`,
41
- livestreaming: `https://livestreaming_api.comty.app`,
42
- marketplace: `https://marketplace_api.comty.app`,
43
- music: `https://music_api.comty.app`,
44
- files: `https://files_api.comty.app`,
45
- sync: `https://sync_api.comty.app`,
46
- }
10
+ "development": `http://${getCurrentHostname()}:9000`,
11
+ "indev": "https://indev_api.comty.app",
12
+ "production": "https://api.comty.app",
47
13
  }
48
14
 
49
15
  exports. default = {
50
16
  default: {
51
- origin: composeRemote("default"),
52
- hasWebsocket: true,
53
- },
54
- chat: {
55
- origin: composeRemote("chat"),
56
- hasWebsocket: true,
57
- },
58
- music: {
59
- origin: composeRemote("music"),
60
- hasWebsocket: true,
61
- },
62
- livestreaming: {
63
- origin: composeRemote("livestreaming"),
64
- hasWebsocket: false,
65
- },
66
- marketplace: {
67
- origin: composeRemote("marketplace"),
68
- hasWebsocket: false,
69
- },
70
- files: {
71
- origin: composeRemote("files"),
72
- hasWebsocket: false,
73
- },
74
- sync: {
75
- origin: composeRemote("sync"),
17
+ origin: envOrigins[_nullishCoalesce(process.env.NODE_ENV, () => ( "production"))],
76
18
  hasWebsocket: false,
77
19
  }
78
20
  }
@@ -0,0 +1,51 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }var _handleBeforeRequest = require('./helpers/handleBeforeRequest'); var _handleBeforeRequest2 = _interopRequireDefault(_handleBeforeRequest);
2
+ var _handleAfterRequest = require('./helpers/handleAfterRequest'); var _handleAfterRequest2 = _interopRequireDefault(_handleAfterRequest);
3
+
4
+ exports. default = async (
5
+ request = {
6
+ method: "GET",
7
+ },
8
+ ...args
9
+ ) => {
10
+ const instance = _nullishCoalesce(request.instance, () => ( __comty_shared_state.baseRequest))
11
+
12
+ if (!instance) {
13
+ throw new Error("No instance provided")
14
+ }
15
+
16
+ // handle before request
17
+ await _handleBeforeRequest2.default.call(void 0, request)
18
+
19
+ if (typeof request === "string") {
20
+ request = {
21
+ url: request,
22
+ }
23
+ }
24
+
25
+ if (typeof request.headers !== "object") {
26
+ request.headers = {}
27
+ }
28
+
29
+ let result = null
30
+
31
+ const makeRequest = async () => {
32
+ const _result = await instance(request, ...args)
33
+ .catch((error) => {
34
+ return error
35
+ })
36
+
37
+ result = _result
38
+ }
39
+
40
+ await makeRequest()
41
+
42
+ // handle after request
43
+ await _handleAfterRequest2.default.call(void 0, result, makeRequest)
44
+
45
+ // if error, throw it
46
+ if (result instanceof Error) {
47
+ throw result
48
+ }
49
+
50
+ return result
51
+ }
@@ -0,0 +1,52 @@
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
+ // create a regex to detect params with %% symbol, from the url
4
+ const paramMatchRegex = /(%[0-9a-f]{2}%)/g
5
+
6
+ exports. default = (method = "GET", url = "/", params, data) => {
7
+ return async function generatedRequest(arg0, arg1) {
8
+ const requestObj = {
9
+ method: method,
10
+ url: url,
11
+ params: params,
12
+ data: data,
13
+ }
14
+
15
+ // search url for params
16
+ // example: /namespace/search/[0]/data => /namespace/search/${arguments[0]}/data
17
+ // if no url matches, merge params with arg0 and override data in requestObj
18
+ if (url.match(paramMatchRegex)) {
19
+ requestObj.url = url.replace(paramMatchRegex, (match) => {
20
+ console.log(match)
21
+
22
+ // replace with arguments
23
+ const fnArgumentIndex = ""
24
+
25
+ return match
26
+ })
27
+ } else {
28
+ requestObj.params = {
29
+ ...requestObj.params,
30
+ ...arg0
31
+ }
32
+ requestObj.data = {
33
+ ...requestObj.data,
34
+ ...arg1
35
+ }
36
+ }
37
+
38
+ if (typeof requestObj.params === "object" && requestObj.params) {
39
+ Object.keys(requestObj.params).forEach((key) => {
40
+ if (requestObj.params && typeof requestObj.params[key] === "string") {
41
+
42
+ }
43
+ })
44
+ }
45
+
46
+
47
+ const response = await _request2.default.call(void 0, requestObj)
48
+
49
+ // @ts-ignore
50
+ return response.data
51
+ }
52
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});async function importFilesFrom(from) {
2
+ let paths = {
3
+ // @ts-ignore
4
+ ...import.meta.glob(`${from}/**.ts`),
5
+ // @ts-ignore
6
+ ...import.meta.glob(`${from}/**.js`),
7
+ }
8
+
9
+ let fns = {}
10
+
11
+ for (const path in paths) {
12
+ // @ts-ignore
13
+ const name = path.split("/").pop().replace(".ts", "").replace(".js", "")
14
+ const fn = await paths[path]()
15
+
16
+ fns[name] = fn.default
17
+ }
18
+
19
+ return fns
20
+ }
21
+
22
+ exports. default = importFilesFrom
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "comty.js",
3
- "version": "0.59.2",
3
+ "version": "0.60.3",
4
4
  "main": "./dist/index.js",
5
5
  "author": "RageStudio <support@ragestudio.net>",
6
6
  "scripts": {
7
+ "test": "ava",
7
8
  "build": "hermes build"
8
9
  },
9
10
  "files": [
@@ -12,6 +13,7 @@
12
13
  "license": "MIT",
13
14
  "dependencies": {
14
15
  "@foxify/events": "^2.1.0",
16
+ "ava": "^6.1.2",
15
17
  "axios": "^1.4.0",
16
18
  "js-cookie": "^3.0.5",
17
19
  "jsonwebtoken": "^9.0.0",
@@ -20,7 +22,6 @@
20
22
  "socket.io-client": "^4.6.1"
21
23
  },
22
24
  "devDependencies": {
23
- "@ragestudio/hermes": "^0.1.0",
24
- "corenode": "^0.28.26"
25
+ "@ragestudio/hermes": "^0.1.0"
25
26
  }
26
- }
27
+ }