noblox-asset.js 7.4.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.
Files changed (272) hide show
  1. package/.github/ISSUE_TEMPLATE/bug_report.md +29 -0
  2. package/.github/ISSUE_TEMPLATE/feature_request.md +22 -0
  3. package/.github/workflows/doc-publish.yml +33 -0
  4. package/.github/workflows/npmpublish.yml +72 -0
  5. package/.github/workflows/run-tests.yml +49 -0
  6. package/CODE_OF_CONDUCT.md +76 -0
  7. package/LICENSE +21 -0
  8. package/README.md +182 -0
  9. package/eslint.config.mjs +34 -0
  10. package/examples/cleanPlayers.js +130 -0
  11. package/examples/cleanWall.js +110 -0
  12. package/examples/revertRanks.js +100 -0
  13. package/examples/savePlayers.js +119 -0
  14. package/examples/saveWall.js +96 -0
  15. package/img/moderatedThumbnails/moderatedThumbnail_100x100.png +0 -0
  16. package/img/moderatedThumbnails/moderatedThumbnail_110x110.png +0 -0
  17. package/img/moderatedThumbnails/moderatedThumbnail_140x140.png +0 -0
  18. package/img/moderatedThumbnails/moderatedThumbnail_150x150.png +0 -0
  19. package/img/moderatedThumbnails/moderatedThumbnail_150x200.png +0 -0
  20. package/img/moderatedThumbnails/moderatedThumbnail_180x180.png +0 -0
  21. package/img/moderatedThumbnails/moderatedThumbnail_250x250.png +0 -0
  22. package/img/moderatedThumbnails/moderatedThumbnail_30x30.png +0 -0
  23. package/img/moderatedThumbnails/moderatedThumbnail_352x352.png +0 -0
  24. package/img/moderatedThumbnails/moderatedThumbnail_420x420.png +0 -0
  25. package/img/moderatedThumbnails/moderatedThumbnail_48x48.png +0 -0
  26. package/img/moderatedThumbnails/moderatedThumbnail_50x50.png +0 -0
  27. package/img/moderatedThumbnails/moderatedThumbnail_60x60.png +0 -0
  28. package/img/moderatedThumbnails/moderatedThumbnail_720x720.png +0 -0
  29. package/img/moderatedThumbnails/moderatedThumbnail_75x75.png +0 -0
  30. package/img/noblox-js-small.png +0 -0
  31. package/img/noblox-js.png +0 -0
  32. package/img/thumbnailSizes.png +0 -0
  33. package/jsDocsConfig.json +55 -0
  34. package/lib/accountinformation/getUserSocialLinks.js +40 -0
  35. package/lib/accountsettings/block.js +53 -0
  36. package/lib/accountsettings/unblock.js +53 -0
  37. package/lib/asset/deleteFromInventory.js +56 -0
  38. package/lib/asset/getGamePassProductInfo.js +50 -0
  39. package/lib/asset/getProductInfo.js +46 -0
  40. package/lib/asset/uploadAnimation.js +103 -0
  41. package/lib/asset/uploadItem.js +83 -0
  42. package/lib/asset/uploadModel.js +90 -0
  43. package/lib/avatar/avatarRules.js +39 -0
  44. package/lib/avatar/currentlyWearing.js +33 -0
  45. package/lib/avatar/getAvatar.js +36 -0
  46. package/lib/avatar/getCurrentAvatar.js +38 -0
  47. package/lib/avatar/getRecentItems.js +36 -0
  48. package/lib/avatar/outfitDetails.js +33 -0
  49. package/lib/avatar/outfits.js +38 -0
  50. package/lib/avatar/redrawAvatar.js +47 -0
  51. package/lib/avatar/removeAssetId.js +51 -0
  52. package/lib/avatar/setAvatarBodyColors.js +61 -0
  53. package/lib/avatar/setAvatarScales.js +61 -0
  54. package/lib/avatar/setPlayerAvatarType.js +51 -0
  55. package/lib/avatar/setWearingAssets.js +51 -0
  56. package/lib/avatar/wearAssetId.js +51 -0
  57. package/lib/badges/getAwardedTimestamps.js +49 -0
  58. package/lib/badges/getBadgeInfo.js +44 -0
  59. package/lib/badges/getGameBadges.js +63 -0
  60. package/lib/badges/getPlayerBadges.js +28 -0
  61. package/lib/badges/updateBadgeInfo.js +75 -0
  62. package/lib/cache/add.js +14 -0
  63. package/lib/cache/addIf.js +26 -0
  64. package/lib/cache/clear.js +8 -0
  65. package/lib/cache/get.js +28 -0
  66. package/lib/cache/index.js +17 -0
  67. package/lib/cache/new.js +12 -0
  68. package/lib/cache/wrap.js +25 -0
  69. package/lib/chat/addUsersToConversation.js +58 -0
  70. package/lib/chat/chatSettings.js +34 -0
  71. package/lib/chat/getChatMessages.js +41 -0
  72. package/lib/chat/getConversations.js +44 -0
  73. package/lib/chat/getRolloutSettings.js +36 -0
  74. package/lib/chat/getUnreadConversationCount.js +34 -0
  75. package/lib/chat/getUnreadMessages.js +39 -0
  76. package/lib/chat/getUserConversations.js +38 -0
  77. package/lib/chat/markChatAsRead.js +53 -0
  78. package/lib/chat/markChatAsSeen.js +51 -0
  79. package/lib/chat/multiGetLatestMessages.js +38 -0
  80. package/lib/chat/onNewConversation.js +50 -0
  81. package/lib/chat/onNewMessage.js +53 -0
  82. package/lib/chat/onNewMessageBySelf.js +50 -0
  83. package/lib/chat/onUserOnline.js +50 -0
  84. package/lib/chat/onUserTyping.js +54 -0
  85. package/lib/chat/removeFromGroupConversation.js +59 -0
  86. package/lib/chat/renameGroupConversation.js +58 -0
  87. package/lib/chat/sendChatMessage.js +58 -0
  88. package/lib/chat/setChatUserTyping.js +58 -0
  89. package/lib/chat/start121Conversation.js +51 -0
  90. package/lib/chat/startCloudEditConversation.js +51 -0
  91. package/lib/chat/startGroupConversation.js +59 -0
  92. package/lib/client/onNotification.js +86 -0
  93. package/lib/client/setAPIKey.js +18 -0
  94. package/lib/client/setCookie.js +38 -0
  95. package/lib/datastores/deleteDatastoreEntry.js +56 -0
  96. package/lib/datastores/getDatastoreEntry.js +88 -0
  97. package/lib/datastores/getDatastoreEntryVersions.js +73 -0
  98. package/lib/datastores/getDatastoreKeys.js +63 -0
  99. package/lib/datastores/getDatastores.js +62 -0
  100. package/lib/datastores/incrementDatastoreEntry.js +83 -0
  101. package/lib/datastores/setDatastoreEntry.js +80 -0
  102. package/lib/develop/canManage.js +42 -0
  103. package/lib/develop/configureItem.js +210 -0
  104. package/lib/develop/updateUniverse.js +52 -0
  105. package/lib/develop/updateUniverseAccess.js +54 -0
  106. package/lib/economy/getGroupFunds.js +42 -0
  107. package/lib/economy/getGroupPayoutEligibility.js +55 -0
  108. package/lib/economy/getGroupRevenueSummary.js +42 -0
  109. package/lib/economy/getGroupTransactions.js +32 -0
  110. package/lib/economy/getResaleData.js +48 -0
  111. package/lib/economy/getResellers.js +35 -0
  112. package/lib/economy/getUserFunds.js +43 -0
  113. package/lib/economy/getUserTransactions.js +34 -0
  114. package/lib/economy/onGroupTransaction.js +74 -0
  115. package/lib/friends/acceptFriendRequest.js +54 -0
  116. package/lib/friends/declineAllFriendRequests.js +52 -0
  117. package/lib/friends/declineFriendRequest.js +54 -0
  118. package/lib/friends/getFollowerCount.js +35 -0
  119. package/lib/friends/getFollowers.js +56 -0
  120. package/lib/friends/getFollowingCount.js +35 -0
  121. package/lib/friends/getFollowings.js +56 -0
  122. package/lib/friends/getFriendCount.js +35 -0
  123. package/lib/friends/getFriendRequests.js +51 -0
  124. package/lib/friends/getFriends.js +48 -0
  125. package/lib/friends/onFriendRequest.js +58 -0
  126. package/lib/friends/removeFriend.js +53 -0
  127. package/lib/friends/sendFriendRequest.js +54 -0
  128. package/lib/friends/unfollow.js +53 -0
  129. package/lib/games/addDeveloperProduct.js +53 -0
  130. package/lib/games/configureGamePass.js +126 -0
  131. package/lib/games/getDeveloperProducts.js +44 -0
  132. package/lib/games/getGameInstances.js +31 -0
  133. package/lib/games/getGamePasses.js +39 -0
  134. package/lib/games/getGameRevenue.js +48 -0
  135. package/lib/games/getGameSocialLinks.js +42 -0
  136. package/lib/games/getGroupGames.js +30 -0
  137. package/lib/games/getPlaceInfo.js +47 -0
  138. package/lib/games/getUniverseInfo.js +50 -0
  139. package/lib/games/publishToTopic.js +52 -0
  140. package/lib/games/sendUserNotification.js +65 -0
  141. package/lib/games/updateDeveloperProduct.js +56 -0
  142. package/lib/groups/banFromGroup.js +47 -0
  143. package/lib/groups/changeRank.js +59 -0
  144. package/lib/groups/deleteWallPost.js +59 -0
  145. package/lib/groups/deleteWallPostsByUser.js +55 -0
  146. package/lib/groups/demote.js +25 -0
  147. package/lib/groups/exile.js +55 -0
  148. package/lib/groups/getAuditLog.js +64 -0
  149. package/lib/groups/getGroup.js +50 -0
  150. package/lib/groups/getGroupBans.js +37 -0
  151. package/lib/groups/getGroupSocialLinks.js +41 -0
  152. package/lib/groups/getGroups.js +82 -0
  153. package/lib/groups/getJoinRequest.js +47 -0
  154. package/lib/groups/getJoinRequests.js +53 -0
  155. package/lib/groups/getPlayers.js +103 -0
  156. package/lib/groups/getRankInGroup.js +45 -0
  157. package/lib/groups/getRankNameInGroup.js +44 -0
  158. package/lib/groups/getRole.js +64 -0
  159. package/lib/groups/getRolePermissions.js +48 -0
  160. package/lib/groups/getRoles.js +53 -0
  161. package/lib/groups/getShout.js +47 -0
  162. package/lib/groups/getWall.js +56 -0
  163. package/lib/groups/groupPayout.js +103 -0
  164. package/lib/groups/handleJoinRequest.js +57 -0
  165. package/lib/groups/handleJoinRequests.js +61 -0
  166. package/lib/groups/leaveGroup.js +56 -0
  167. package/lib/groups/onAuditLog.js +62 -0
  168. package/lib/groups/onJoinRequest.js +63 -0
  169. package/lib/groups/onJoinRequestHandle.js +105 -0
  170. package/lib/groups/onShout.js +57 -0
  171. package/lib/groups/onWallPost.js +58 -0
  172. package/lib/groups/promote.js +25 -0
  173. package/lib/groups/searchGroups.js +32 -0
  174. package/lib/groups/setGroupDescription.js +58 -0
  175. package/lib/groups/setGroupName.js +59 -0
  176. package/lib/groups/setRank.js +74 -0
  177. package/lib/groups/setRoleInfo.js +84 -0
  178. package/lib/groups/shout.js +58 -0
  179. package/lib/groups/unbanFromGroup.js +41 -0
  180. package/lib/index.js +212 -0
  181. package/lib/internal/levelOneCopy.js +16 -0
  182. package/lib/internal/queue.js +61 -0
  183. package/lib/internal/timeout.js +30 -0
  184. package/lib/internal/wrap.js +78 -0
  185. package/lib/inventory/getCollectibles.js +31 -0
  186. package/lib/inventory/getInventory.js +32 -0
  187. package/lib/inventory/getInventoryById.js +31 -0
  188. package/lib/inventory/getOwnership.js +47 -0
  189. package/lib/inventory/getUAIDs.js +47 -0
  190. package/lib/itemconfiguration/getGroupAssets.js +32 -0
  191. package/lib/options.js +26 -0
  192. package/lib/party/onPartyDeleted.js +53 -0
  193. package/lib/party/onPartyInvite.js +53 -0
  194. package/lib/party/onPartyJoinedGame.js +53 -0
  195. package/lib/party/onPartyLeftGame.js +53 -0
  196. package/lib/party/onPartySelfJoined.js +53 -0
  197. package/lib/party/onPartySelfLeft.js +53 -0
  198. package/lib/party/onPartyUserJoined.js +53 -0
  199. package/lib/party/onPartyUserLeft.js +53 -0
  200. package/lib/premiumfeatures/getPremium.js +46 -0
  201. package/lib/presence/getPresences.js +60 -0
  202. package/lib/privatemessages/getMessages.js +55 -0
  203. package/lib/privatemessages/message.js +75 -0
  204. package/lib/privatemessages/onMessage.js +89 -0
  205. package/lib/thumbnails/getLogo.js +56 -0
  206. package/lib/thumbnails/getPlayerThumbnail.js +120 -0
  207. package/lib/thumbnails/getThumbnails.js +92 -0
  208. package/lib/trades/acceptTrade.js +52 -0
  209. package/lib/trades/canTradeWith.js +43 -0
  210. package/lib/trades/counterTrade.js +78 -0
  211. package/lib/trades/declineTrade.js +52 -0
  212. package/lib/trades/getTradeInfo.js +47 -0
  213. package/lib/trades/getTrades.js +37 -0
  214. package/lib/trades/sendTrade.js +76 -0
  215. package/lib/users/getBlurb.js +37 -0
  216. package/lib/users/getIdFromUsername.js +56 -0
  217. package/lib/users/getPlayerInfo.js +128 -0
  218. package/lib/users/getUserInfo.js +35 -0
  219. package/lib/users/getUsernameFromId.js +45 -0
  220. package/lib/users/getUsernameHistory.js +42 -0
  221. package/lib/users/onBlurbChange.js +46 -0
  222. package/lib/users/searchUsers.js +41 -0
  223. package/lib/util/apiError.js +50 -0
  224. package/lib/util/clearSession.js +32 -0
  225. package/lib/util/generalRequest.js +61 -0
  226. package/lib/util/getAction.js +45 -0
  227. package/lib/util/getAuthenticatedUser.js +41 -0
  228. package/lib/util/getCurrentUser.js +58 -0
  229. package/lib/util/getGeneralToken.js +52 -0
  230. package/lib/util/getHash.js +29 -0
  231. package/lib/util/getInputs.js +37 -0
  232. package/lib/util/getPageResults.js +86 -0
  233. package/lib/util/getSenderUserId.js +30 -0
  234. package/lib/util/getSession.js +38 -0
  235. package/lib/util/getVerification.js +60 -0
  236. package/lib/util/getVerificationInputs.js +31 -0
  237. package/lib/util/http.js +138 -0
  238. package/lib/util/jar.js +25 -0
  239. package/lib/util/refreshCookie.js +52 -0
  240. package/lib/util/relog.js +81 -0
  241. package/lib/util/setOptions.js +54 -0
  242. package/lib/util/shortPoll.js +102 -0
  243. package/package.json +76 -0
  244. package/postinstall.mjs +1 -0
  245. package/settings.json +115 -0
  246. package/test/accountinformation.test.js +27 -0
  247. package/test/accountsettings.test.js +27 -0
  248. package/test/asset.test.js +81 -0
  249. package/test/assets/Great-White-Shark-Fin.rbxm +0 -0
  250. package/test/assets/KeyframeSequence.rbxm +0 -0
  251. package/test/avatar.test.js +164 -0
  252. package/test/badges.test.js +96 -0
  253. package/test/chat.test.js +104 -0
  254. package/test/datastore.test.js +105 -0
  255. package/test/develop.test.js +53 -0
  256. package/test/economy.test.js +143 -0
  257. package/test/friends.test.js +146 -0
  258. package/test/games.test.js +229 -0
  259. package/test/groups.test.js +405 -0
  260. package/test/inventory.test.js +98 -0
  261. package/test/itemconfiguration.test.js +24 -0
  262. package/test/premiumfeatures.test.js +17 -0
  263. package/test/presence.test.js +25 -0
  264. package/test/privatemessages.test.js +33 -0
  265. package/test/thumbnails.test.js +53 -0
  266. package/test/users.test.js +110 -0
  267. package/tutorials/Authentication.md +75 -0
  268. package/tutorials/Event Emitters.md +26 -0
  269. package/tutorials/Promises.md +86 -0
  270. package/tutorials/VPS Authentication.md +72 -0
  271. package/typings/index.d.ts +2639 -0
  272. package/typings/jsDocs.ts +1987 -0
@@ -0,0 +1,92 @@
1
+ // Includes
2
+ const http = require('../util/http.js').func
3
+ const { thumbnail: settings } = require('../../settings.json')
4
+ const RobloxAPIError = require('../util/apiError.js')
5
+
6
+ // Args
7
+ exports.required = ['thumbnailRequests']
8
+ exports.optional = []
9
+
10
+ // Docs
11
+ /**
12
+ * ✅ Get thumbnails for assets/players.
13
+ * @category Assets
14
+ * @alias getThumbnails
15
+ * @param {Array<ThumbnailRequest>} thumbnailRequests - The id or an array ids of thumbnails to be retrieved; 100
16
+ * @returns {Promise<ThumbnailData[]>}
17
+ * @example const noblox = require("noblox.js")
18
+ * const playerThumbnails = noblox.getThumbnails([
19
+ * {
20
+ * type: "AvatarHeadShot",
21
+ * token: "270FF19ECB1AFCF25383A6F37C6AD307",
22
+ * format: "png",
23
+ * size: "150x150"
24
+ * }, {
25
+ * type: "AvatarBust",
26
+ * targetId: 55549140,
27
+ * isCircular: true,
28
+ * format: "png",
29
+ * size: "150x150"
30
+ * }
31
+ * ])
32
+ **/
33
+
34
+ // Define
35
+ function getThumbnails (requests, retryCount = settings.maxRetries) {
36
+ if (!Array.isArray(requests)) {
37
+ throw new Error('thumbnailRequests are not an array')
38
+ }
39
+
40
+ requests = [...new Set(requests)]
41
+ if (requests.length > 100) {
42
+ throw new Error(`Too many thumbnailRequests provided (${requests.length}); maximum 100`)
43
+ }
44
+
45
+ for (const request of requests) {
46
+ if (!request.size || !request.type) {
47
+ throw new Error('thumbnailRequest must have a size and type')
48
+ } else if (request.format && (request.format.toLowerCase() !== 'png' && request.format.toLowerCase() !== 'jpeg')) {
49
+ throw new Error(`Invalid image type provided: ${request.format} | Use: png, jpeg`)
50
+ }
51
+ }
52
+
53
+ return http({
54
+ url: 'https://thumbnails.roblox.com/v1/batch',
55
+ options: {
56
+ method: 'POST',
57
+ json: requests,
58
+ resolveWithFullResponse: true,
59
+ followRedirect: true
60
+ }
61
+ })
62
+ .then(async (res) => {
63
+ let { data } = res.body
64
+ if (res.statusCode === 200) {
65
+ if (retryCount > 0) {
66
+ const pendingThumbnails = data.filter(obj => { return obj.state === 'Pending' }).map(obj => obj.targetId) // Get 'Pending' thumbnails as array of userIds
67
+ if (pendingThumbnails.length > 0) {
68
+ await timeout(settings.retryDelay) // small delay helps cache populate on Roblox's end; default 500ms
69
+ const updatedPending = await getThumbnails(pendingThumbnails, --retryCount) // Recursively retry for # of maxRetries attempts; default 2
70
+ data = data.map(obj => updatedPending.find(o => o.targetId === obj.targetId) || obj) // Update primary array's values
71
+ }
72
+ }
73
+ data = data.map(obj => {
74
+ if (obj.state !== 'Completed') {
75
+ obj.imageUrl = settings.failedUrl[obj.state.toLowerCase()] || obj.imageUrl
76
+ }
77
+ return obj
78
+ })
79
+ return data
80
+ } else {
81
+ throw new RobloxAPIError(res)
82
+ }
83
+ })
84
+ }
85
+
86
+ function timeout (ms) {
87
+ return new Promise(resolve => { setTimeout(resolve, ms) })
88
+ }
89
+
90
+ exports.func = function ({ thumbnailRequests }) {
91
+ return getThumbnails(thumbnailRequests)
92
+ }
@@ -0,0 +1,52 @@
1
+ // Includes
2
+ const http = require('../util/http.js').func
3
+ const getGeneralToken = require('../util/getGeneralToken.js').func
4
+ const RobloxAPIError = require('../util/apiError.js')
5
+
6
+ // Args
7
+ exports.required = ['tradeId']
8
+ exports.optional = ['jar']
9
+
10
+ // Docs
11
+ /**
12
+ * 🔐 Accept an active trade.
13
+ * @category Trade
14
+ * @alias acceptTrade
15
+ * @param {number} tradeId - The tradeId to accept.
16
+ * @returns {Promise<void>}
17
+ * @example const noblox = require("noblox.js")
18
+ * // Login using your cookie
19
+ * noblox.acceptTrade(1234)
20
+ **/
21
+
22
+ // Define
23
+ function acceptTrade (tradeId, jar, xcsrf) {
24
+ return new Promise((resolve, reject) => {
25
+ http({
26
+ url: '//trades.roblox.com/v1/trades/' + tradeId + '/accept',
27
+ options: {
28
+ method: 'POST',
29
+ resolveWithFullResponse: true,
30
+ jar,
31
+ headers: {
32
+ 'X-CSRF-TOKEN': xcsrf,
33
+ 'Content-Type': 'application/json'
34
+ }
35
+ }
36
+ }).then((res) => {
37
+ if (res.statusCode === 200) {
38
+ resolve()
39
+ } else {
40
+ reject(new RobloxAPIError(res))
41
+ }
42
+ }).catch(error => reject(error))
43
+ })
44
+ }
45
+
46
+ exports.func = function (args) {
47
+ const jar = args.jar
48
+ return getGeneralToken({ jar })
49
+ .then(function (xcsrf) {
50
+ return acceptTrade(args.tradeId, jar, xcsrf)
51
+ })
52
+ }
@@ -0,0 +1,43 @@
1
+ // Includes
2
+ const http = require('../util/http.js').func
3
+ const RobloxAPIError = require('../util/apiError.js')
4
+
5
+ // Args
6
+ exports.required = ['userId']
7
+ exports.optional = ['jar']
8
+
9
+ // Docs
10
+ /**
11
+ * 🔐 Check if the signed in user can trade with another user.
12
+ * @category Trade
13
+ * @alias canTradeWith
14
+ * @param {number} userId - The id of the user.
15
+ * @returns {Promise<CanTradeResponse>}
16
+ * @example const noblox = require("noblox.js")
17
+ * // Login using your cookie
18
+ * const canTrade = await noblox.canTradeWith(1234)
19
+ **/
20
+
21
+ // Define
22
+ function canTradeWith (jar, userId) {
23
+ return new Promise((resolve, reject) => {
24
+ http({
25
+ url: '//trades.roblox.com/v1/users/' + userId + '/can-trade-with',
26
+ options: {
27
+ method: 'GET',
28
+ resolveWithFullResponse: true,
29
+ jar
30
+ }
31
+ }).then((res) => {
32
+ if (res.statusCode === 200) {
33
+ resolve(JSON.parse(res.body))
34
+ } else {
35
+ reject(new RobloxAPIError(res))
36
+ }
37
+ }).catch(error => reject(error))
38
+ })
39
+ }
40
+
41
+ exports.func = (args) => {
42
+ return canTradeWith(args.jar, args.userId)
43
+ }
@@ -0,0 +1,78 @@
1
+ // Includes
2
+ const http = require('../util/http.js').func
3
+ const getGeneralToken = require('../util/getGeneralToken.js').func
4
+ const getCurrentUser = require('../util/getCurrentUser.js').func
5
+ const RobloxAPIError = require('../util/apiError.js')
6
+
7
+ // Args
8
+ exports.required = ['tradeId', 'targetUserId', 'sendingOffer', 'receivingOffer']
9
+ exports.optional = ['jar']
10
+
11
+ // Docs
12
+ /**
13
+ * 🔐 Counter an active incoming trade.
14
+ * @category Trade
15
+ * @alias counterTrade
16
+ * @param {number} tradeId - The id of the active trade
17
+ * @param {number} targetUserId - The user to send the trade to.
18
+ * @param {TradeOffer} sendingOffer - The offer to send to the other user.
19
+ * @param {TradeOffer} recievingOffer - The offer you are requesting from the other user.
20
+ * @returns {Promise<SendTradeResponse>}
21
+ * @example const noblox = require("noblox.js")
22
+ * // Login using your cookie
23
+ * noblox.counterTrade(1234, 80231025, { userAssetIds: [23289506393] }, { userAssetIds: [32924150919] })
24
+ **/
25
+
26
+ // Define
27
+ function counterTrade (tradeId, targetUserId, sendingOffer, receivingOffer, jar, xcsrf, loggedInUser) {
28
+ return new Promise((resolve, reject) => {
29
+ if (!sendingOffer.userAssetIds || !receivingOffer.userAssetIds) {
30
+ reject(new Error('Both offers must includes userAssetIds.'))
31
+ }
32
+
33
+ if (!sendingOffer.robux) sendingOffer.robux = 0
34
+ if (!receivingOffer.robux) receivingOffer.robux = 0
35
+
36
+ http({
37
+ url: '//trades.roblox.com/v1/trades/' + tradeId + '/counter',
38
+ options: {
39
+ method: 'POST',
40
+ resolveWithFullResponse: true,
41
+ jar,
42
+ headers: {
43
+ 'X-CSRF-TOKEN': xcsrf,
44
+ 'Content-Type': 'application/json'
45
+ },
46
+ body: JSON.stringify({
47
+ offers: [
48
+ {
49
+ userId: targetUserId,
50
+ ...receivingOffer
51
+ },
52
+ {
53
+ userId: loggedInUser,
54
+ ...sendingOffer
55
+ }
56
+ ]
57
+ })
58
+ }
59
+ }).then((res) => {
60
+ if (res.statusCode === 200) {
61
+ resolve(JSON.parse(res.body))
62
+ } else {
63
+ reject(new RobloxAPIError(res))
64
+ }
65
+ }).catch(error => reject(error))
66
+ })
67
+ }
68
+
69
+ exports.func = function (args) {
70
+ const jar = args.jar
71
+ return Promise.all([
72
+ getGeneralToken({ jar }),
73
+ getCurrentUser({ jar, option: 'UserID' })
74
+ ])
75
+ .then(function (resolvedPromises) {
76
+ return counterTrade(args.tradeId, args.targetUserId, args.sendingOffer, args.receivingOffer, jar, resolvedPromises[0], resolvedPromises[1])
77
+ })
78
+ }
@@ -0,0 +1,52 @@
1
+ // Includes
2
+ const http = require('../util/http.js').func
3
+ const getGeneralToken = require('../util/getGeneralToken.js').func
4
+ const RobloxAPIError = require('../util/apiError.js')
5
+
6
+ // Args
7
+ exports.required = ['tradeId']
8
+ exports.optional = ['jar']
9
+
10
+ // Docs
11
+ /**
12
+ * 🔐 Decline an active trade.
13
+ * @category Trade
14
+ * @alias declineTrade
15
+ * @param {number} tradeId - The tradeId to decline.
16
+ * @returns {Promise<void>}
17
+ * @example const noblox = require("noblox.js")
18
+ * // Login using your cookie
19
+ * noblox.declineTrade(1234)
20
+ **/
21
+
22
+ // Define
23
+ function declineTrade (tradeId, jar, xcsrf) {
24
+ return new Promise((resolve, reject) => {
25
+ http({
26
+ url: '//trades.roblox.com/v1/trades/' + tradeId + '/decline',
27
+ options: {
28
+ method: 'POST',
29
+ resolveWithFullResponse: true,
30
+ jar,
31
+ headers: {
32
+ 'X-CSRF-TOKEN': xcsrf,
33
+ 'Content-Type': 'application/json'
34
+ }
35
+ }
36
+ }).then((res) => {
37
+ if (res.statusCode === 200) {
38
+ resolve()
39
+ } else {
40
+ reject(new RobloxAPIError(res))
41
+ }
42
+ }).catch(error => reject(error))
43
+ })
44
+ }
45
+
46
+ exports.func = function (args) {
47
+ const jar = args.jar
48
+ return getGeneralToken({ jar })
49
+ .then(function (xcsrf) {
50
+ return declineTrade(args.tradeId, jar, xcsrf)
51
+ })
52
+ }
@@ -0,0 +1,47 @@
1
+ // Includes
2
+ const http = require('../util/http.js').func
3
+ const RobloxAPIError = require('../util/apiError.js')
4
+
5
+ // Args
6
+ exports.required = ['tradeId']
7
+ exports.optional = ['jar']
8
+
9
+ // Docs
10
+ /**
11
+ * 🔐 Get detailed information for a specific trade.
12
+ * @category Trade
13
+ * @alias getTradeInfo
14
+ * @param {number} tradeId - The id of the trade.
15
+ * @returns {Promise<TradeInfo>}
16
+ * @example const noblox = require("noblox.js")
17
+ * // Login using your cookie
18
+ * const tradeInfo = await noblox.getTradeInfo(1234)
19
+ **/
20
+
21
+ // Define
22
+ const getTradeInfo = (jar, tradeId) => {
23
+ return new Promise((resolve, reject) => {
24
+ http({
25
+ url: '//trades.roblox.com/v1/trades/' + tradeId,
26
+ options: {
27
+ method: 'GET',
28
+ resolveWithFullResponse: true,
29
+ jar
30
+ }
31
+ }).then((res) => {
32
+ if (res.statusCode === 200) {
33
+ const body = JSON.parse(res.body)
34
+ body.created = new Date(body.created)
35
+ if (body.expiration) body.expiration = new Date(body.expiration)
36
+
37
+ resolve(body)
38
+ } else {
39
+ reject(new RobloxAPIError(res))
40
+ }
41
+ }).catch(error => reject(error))
42
+ })
43
+ }
44
+
45
+ exports.func = (args) => {
46
+ return getTradeInfo(args.jar, args.tradeId)
47
+ }
@@ -0,0 +1,37 @@
1
+ // Includes
2
+ const getPageResults = require('../util/getPageResults.js').func
3
+
4
+ // Args
5
+ exports.required = ['tradeStatusType']
6
+ exports.optional = ['sortOrder', 'limit', 'jar']
7
+
8
+ // Docs
9
+ /**
10
+ * 🔐 Get the trades for a specific category.
11
+ * @category Trade
12
+ * @alias getTrades
13
+ * @param {string} tradeStatusType - The status of the trades to get [Inbound, Outbound, Complete, Inactive].
14
+ * @param {SortOrder=} [sortOrder=Asc] - The order that the data will be returned in (Asc or Desc)
15
+ * @param {Limit=} [limit=10] - The number of assets returned in each request (10, 25, 50, or 100)
16
+ * @returns {Promise<TradeAsset[]>}
17
+ * @example const noblox = require("noblox.js")
18
+ * // Login using your cookie
19
+ * const trades = await noblox.getTrades("Inbound")
20
+ **/
21
+
22
+ // Define
23
+ exports.func = function (args) {
24
+ return getPageResults({
25
+ jar: args.jar,
26
+ url: `//trades.roblox.com/v1/trades/${args.tradeStatusType}`,
27
+ sortOrder: args.sortOrder,
28
+ limit: args.limit
29
+ }).then(function (results) {
30
+ results.forEach(result => {
31
+ result.created = new Date(result.created)
32
+ if (result.expiration) result.expiration = new Date(result.expiration)
33
+ })
34
+
35
+ return results
36
+ })
37
+ }
@@ -0,0 +1,76 @@
1
+ // Includes
2
+ const http = require('../util/http.js').func
3
+ const getGeneralToken = require('../util/getGeneralToken.js').func
4
+ const getCurrentUser = require('../util/getCurrentUser.js').func
5
+ const RobloxAPIError = require('../util/apiError.js')
6
+
7
+ // Args
8
+ exports.required = ['targetUserId', 'sendingOffer', 'receivingOffer']
9
+ exports.optional = ['jar']
10
+
11
+ // Docs
12
+ /**
13
+ * 🔐 Send a trade to another user.
14
+ * @category Trade
15
+ * @alias sendTrade
16
+ * @param {number} targetUserId - The user to send the trade to.
17
+ * @param {TradeOffer} sendingOffer - The offer to send to the other user.
18
+ * @param {TradeOffer} recievingOffer - The offer you are requesting from the other user.
19
+ * @returns {Promise<SendTradeResponse>}
20
+ * @example const noblox = require("noblox.js")
21
+ * noblox.sendTrade(80231025, { userAssetIds: [23289506393] }, { userAssetIds: [32924150919] })
22
+ **/
23
+
24
+ // Define
25
+ function sendTrade (targetUserId, sendingOffer, receivingOffer, jar, xcsrf, loggedInUser) {
26
+ return new Promise((resolve, reject) => {
27
+ if (!sendingOffer.userAssetIds || !receivingOffer.userAssetIds) {
28
+ reject(new Error('Both offers must includes userAssetIds.'))
29
+ }
30
+
31
+ if (!sendingOffer.robux) sendingOffer.robux = 0
32
+ if (!receivingOffer.robux) receivingOffer.robux = 0
33
+
34
+ http({
35
+ url: '//trades.roblox.com/v1/trades/send',
36
+ options: {
37
+ method: 'POST',
38
+ resolveWithFullResponse: true,
39
+ jar,
40
+ headers: {
41
+ 'X-CSRF-TOKEN': xcsrf,
42
+ 'Content-Type': 'application/json'
43
+ },
44
+ body: JSON.stringify({
45
+ offers: [
46
+ {
47
+ userId: targetUserId,
48
+ ...receivingOffer
49
+ },
50
+ {
51
+ userId: loggedInUser,
52
+ ...sendingOffer
53
+ }
54
+ ]
55
+ })
56
+ }
57
+ }).then((res) => {
58
+ if (res.statusCode === 200) {
59
+ resolve(JSON.parse(res.body))
60
+ } else {
61
+ reject(new RobloxAPIError(res))
62
+ }
63
+ }).catch(error => reject(error))
64
+ })
65
+ }
66
+
67
+ exports.func = function (args) {
68
+ const jar = args.jar
69
+ return Promise.all([
70
+ getGeneralToken({ jar }),
71
+ getCurrentUser({ jar, option: 'UserID' })
72
+ ])
73
+ .then(function (resolvedPromises) {
74
+ return sendTrade(args.targetUserId, args.sendingOffer, args.receivingOffer, jar, resolvedPromises[0], resolvedPromises[1])
75
+ })
76
+ }
@@ -0,0 +1,37 @@
1
+ // Includes
2
+ const http = require('../util/http.js').func
3
+ const RobloxAPIError = require('../util/apiError.js')
4
+
5
+ // Args
6
+ exports.required = ['userId']
7
+
8
+ // Docs
9
+ /**
10
+ * ✅ Get a user's blurb - a user's description.
11
+ * @category User
12
+ * @deprecated Obsolete function, will be deleted in future version. Use getPlayerInfo instead.
13
+ * @alias getBlurb
14
+ * @param {number} userId - The id of the user's blurb that is being retrieved.
15
+ * @returns {Promise<string>}
16
+ * @example const noblox = require("noblox.js")
17
+ * let blurb = await noblox.getBlurb({ userId: 123456 })
18
+ **/
19
+
20
+ // Define
21
+ exports.func = function (args) {
22
+ return http({
23
+ url: `//users.roblox.com/v1/users/${args.userId}`,
24
+ options: {
25
+ resolveWithFullResponse: true,
26
+ followRedirect: false
27
+ }
28
+ })
29
+ .then(function (res) {
30
+ if (res.statusCode === 200) {
31
+ const parsedBody = JSON.parse(res.body)
32
+ return parsedBody.description
33
+ } else {
34
+ throw new RobloxAPIError(res)
35
+ }
36
+ })
37
+ }
@@ -0,0 +1,56 @@
1
+ // Includes
2
+ const http = require('../util/http.js').func
3
+ const cache = require('../cache')
4
+ const RobloxAPIError = require('../util/apiError.js')
5
+
6
+ // Args
7
+ exports.required = ['username']
8
+
9
+ // Docs
10
+ /**
11
+ * ✅ Get a user's id from their username.
12
+ * @category User
13
+ * @alias getIdFromUsername
14
+ * @param {string | string[]} usernames - The username or usernames of the account(s) whose id(s) is being fetched.
15
+ * @returns {Promise<number> | Promise<number[]>}
16
+ * @example const noblox = require("noblox.js")
17
+ * let ids = await noblox.getIdFromUsername(["ROBLOX", "Qxest", "builderman"])
18
+ **/
19
+
20
+ // Define
21
+ function getIdFromUsername (usernames) {
22
+ usernames = Array.isArray(usernames) ? usernames : [usernames] // cast usernames to array if necessary
23
+
24
+ const httpOpt = {
25
+ url: 'https://users.roblox.com/v1/usernames/users',
26
+ options: {
27
+ method: 'POST',
28
+ json: {
29
+ usernames,
30
+ excludeBannedUsers: false
31
+ },
32
+ resolveWithFullResponse: true
33
+ }
34
+ }
35
+ return http(httpOpt)
36
+ .then(function (res) {
37
+ if (res.statusCode !== 200) throw new RobloxAPIError(res)
38
+ const data = res.body.data
39
+
40
+ let results = usernames.map((username) => {
41
+ return data.find((result) => result.requestedUsername === username)
42
+ })
43
+
44
+ results = results.map((result) => result !== undefined ? result.id : null)
45
+
46
+ return results.length > 1 ? results : results[0]
47
+ })
48
+ }
49
+
50
+ exports.func = function (args) {
51
+ const usernames = Array.isArray(args.username) ? args.username : [args.username] // cast usernames to array if necessary
52
+ // Case does not affect the result and should not affect the cache
53
+ return cache.wrap('IDFromName', usernames.map(username => username.toLowerCase()), function () {
54
+ return getIdFromUsername(usernames)
55
+ })
56
+ }