From 1a098b2ca9249ee6d3f52fb7d190674a6c9be4f5 Mon Sep 17 00:00:00 2001 From: Alan Bixby Date: Thu, 18 Jul 2024 19:20:16 -0400 Subject: [PATCH 1/3] (fix): Remove checkDeveloperProductName reference from addDeveloperProduct (redundant and deprecated) --- lib/games/addDeveloperProduct.js | 44 +++++++------------------- lib/games/checkDeveloperProductName.js | 39 ----------------------- lib/index.js | 1 - typings/index.d.ts | 27 ++++++---------- 4 files changed, 21 insertions(+), 90 deletions(-) delete mode 100644 lib/games/checkDeveloperProductName.js diff --git a/lib/games/addDeveloperProduct.js b/lib/games/addDeveloperProduct.js index b15db2c5..6bd800cf 100644 --- a/lib/games/addDeveloperProduct.js +++ b/lib/games/addDeveloperProduct.js @@ -1,6 +1,5 @@ const http = require('../util/http.js').func const getGeneralToken = require('../util/getGeneralToken.js').func -const checkProductName = require('./checkDeveloperProductName.js').func exports.required = ['universeId', 'name', 'priceInRobux'] exports.optional = ['description', 'jar'] @@ -21,38 +20,19 @@ exports.optional = ['description', 'jar'] **/ const nextFunction = (jar, token, universeId, name, priceInRobux, description) => { - return checkProductName({ - universeId, - productName: name - }).then((res) => { - if (res.Success && res.Message === 'Name available') { - return http({ - url: '//apis.roblox.com/developer-products/v1/universes/' + universeId + '/developerproducts?name=' + name + '&description=' + description + '&priceInRobux=' + priceInRobux, - options: { - method: 'POST', - jar, - headers: { - 'X-CSRF-TOKEN': token - }, - resolveWithFullResponse: true - } - }).then((res) => { - console.log(res) - if (res.statusCode === 200) { - return { - universeId, - name, - priceInRobux, - description, - productId: typeof res.body === 'object' ? res.body.id : JSON.parse(res.body).id - } - } else { - throw new Error('Create product failed, ' + res.statusCode + ' ' + res.statusMessage + '') - } - }) - } else { - throw new Error('Product with this name already exists') + description = description || '' + return http({ + url: '//apis.roblox.com/developer-products/v1/universes/' + universeId + '/developerproducts?name=' + name + '&description=' + description + '&priceInRobux=' + priceInRobux, + options: { + method: 'POST', + jar, + headers: { + 'X-CSRF-TOKEN': token + }, + resolveWithFullResponse: true } + }).then(function (res) { + return res.body }) } diff --git a/lib/games/checkDeveloperProductName.js b/lib/games/checkDeveloperProductName.js deleted file mode 100644 index 0f270c89..00000000 --- a/lib/games/checkDeveloperProductName.js +++ /dev/null @@ -1,39 +0,0 @@ -const http = require('../util/http.js').func - -exports.required = ['universeId', 'productName'] -exports.optional = ['jar', 'productId'] - -// Docs -/** - * 🔐 Check if a provided name is in use by another developer product. - * @category Game - * @alias checkDeveloperProductName - * @param {number} universeId - The id of the universe. - * @param {string} productName - The name of the developer product. - * @param {number=} productId - The id of the developer product. - * @returns {Promise} - * @example const noblox = require("noblox.js") - * // Login using your cookie - * const productInfo = await noblox.checkDeveloperProductName(1, "A Developer Product") -**/ - -exports.func = (args) => { - const jar = args.jar - const universeId = parseInt(args.universeId) ? parseInt(args.universeId) : 0 - const productId = parseInt(args.productId) ? parseInt(args.productId) : 0 - - return http({ - url: '//www.roblox.com/places/check-developerproduct-name?universeId=' + universeId + '&developerProductId=' + productId + '&developerProductName=' + args.productName + '&_=1515792139751', - options: { - method: 'GET', - jar, - resolveWithFullResponse: true - } - }).then((res) => { - if (res.statusCode !== 200) { - throw new Error('You are not logged in') - } else { - return JSON.parse(res.body) - } - }) -} diff --git a/lib/index.js b/lib/index.js index 8d6b9a59..540aa6c9 100644 --- a/lib/index.js +++ b/lib/index.js @@ -85,7 +85,6 @@ noblox.removeFriend = require('./friends/removeFriend.js') noblox.sendFriendRequest = require('./friends/sendFriendRequest.js') noblox.unfollow = require('./friends/unfollow.js') noblox.addDeveloperProduct = require('./games/addDeveloperProduct.js') -noblox.checkDeveloperProductName = require('./games/checkDeveloperProductName.js') noblox.configureGamePass = require('./games/configureGamePass.js') noblox.getDeveloperProducts = require('./games/getDeveloperProducts.js') noblox.getGameInstances = require('./games/getGameInstances.js') diff --git a/typings/index.d.ts b/typings/index.d.ts index ac06f21d..ea704b9a 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -624,20 +624,18 @@ declare module "noblox.js" { } interface DeveloperProductAddResult { - universeId: number, + id: number, name: string, - priceInRobux: number, - description?: string, - productId: string + Description: string, // API does not return camelCase + shopId: number, + iconImageAssetId: number | null } - interface CheckDeveloperProductNameResult { - Success: boolean; - /** - * When success is true: "Name available" - * When success is false, you can get: "Product name already exists" - */ - Message: string; + interface DeveloperProductAddError { + errorCode: string, + errorMessage: string, + field: string, + hint: string | null } interface GamePassData { @@ -1826,13 +1824,6 @@ declare module "noblox.js" { */ function addDeveloperProduct(universeId: number, name: string, priceInRobux: number, description?: string, jar?: CookieJar): Promise; - /** - * 🔐 Checks to see if the provided `produceName` is able to be used on `productId`. - * - * NOTE: You actually need a valid `productId` and `universeId` otherwise, the http request returns a `404 Not Found` response. - */ - function checkDeveloperProductName(universeId: number, productName: string, jar?: CookieJar, productId?: number): Promise; - /** * 🔐 Configures a game pass with the id `gamePassId` to have a `name`, `description`, `price` in Robux, and `icon` image. If `name` is an empty string, only `price` is changed. Setting `price` to false, 0, or a negative value will place the game pass off-sale. * Returns a `GamePassResponse` with the changed attributes. From 863fbbc84e670db957c9eb25807fdbb793a3e885 Mon Sep 17 00:00:00 2001 From: Alan Bixby Date: Thu, 1 Aug 2024 19:03:46 -0400 Subject: [PATCH 2/3] (fix): throw error on non-http 200 responses --- lib/games/addDeveloperProduct.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/games/addDeveloperProduct.js b/lib/games/addDeveloperProduct.js index 6bd800cf..1178fd93 100644 --- a/lib/games/addDeveloperProduct.js +++ b/lib/games/addDeveloperProduct.js @@ -29,10 +29,18 @@ const nextFunction = (jar, token, universeId, name, priceInRobux, description) = headers: { 'X-CSRF-TOKEN': token }, - resolveWithFullResponse: true + resolveWithFullResponse: true, } }).then(function (res) { - return res.body + try { + const json = JSON.parse(res.body) + if (res.statusCode === 200) { + return json + } + throw new Error(json) + } catch (err) { + throw new Error(res.body) + } }) } From 59262bda2dda0a58fdcf90ec14d21acc9bc13583 Mon Sep 17 00:00:00 2001 From: Alan Bixby Date: Thu, 1 Aug 2024 19:09:41 -0400 Subject: [PATCH 3/3] (lint): remove trailing comma --- lib/games/addDeveloperProduct.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/games/addDeveloperProduct.js b/lib/games/addDeveloperProduct.js index 1178fd93..939b422f 100644 --- a/lib/games/addDeveloperProduct.js +++ b/lib/games/addDeveloperProduct.js @@ -29,7 +29,7 @@ const nextFunction = (jar, token, universeId, name, priceInRobux, description) = headers: { 'X-CSRF-TOKEN': token }, - resolveWithFullResponse: true, + resolveWithFullResponse: true } }).then(function (res) { try {