From d44b9ebebe7c80900934f4cf66974aa1a3c69490 Mon Sep 17 00:00:00 2001 From: Alan Bixby Date: Thu, 1 Aug 2024 19:19:37 -0400 Subject: [PATCH] Remove checkDeveloperProductName reference from addDeveloperPoduct (redundant and deprecated) (#814) * (fix): Remove checkDeveloperProductName reference from addDeveloperProduct (redundant and deprecated) * (fix): throw error on non-http 200 responses * (lint): remove trailing comma --- lib/games/addDeveloperProduct.js | 52 ++++++++++---------------- lib/games/checkDeveloperProductName.js | 39 ------------------- lib/index.js | 1 - typings/index.d.ts | 27 +++++-------- 4 files changed, 29 insertions(+), 90 deletions(-) delete mode 100644 lib/games/checkDeveloperProductName.js diff --git a/lib/games/addDeveloperProduct.js b/lib/games/addDeveloperProduct.js index b15db2c50..939b422fa 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,37 +20,26 @@ 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) { + try { + const json = JSON.parse(res.body) + if (res.statusCode === 200) { + return json + } + throw new Error(json) + } catch (err) { + throw new Error(res.body) } }) } diff --git a/lib/games/checkDeveloperProductName.js b/lib/games/checkDeveloperProductName.js deleted file mode 100644 index 0f270c89b..000000000 --- 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 485410ca7..341ca5ace 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 26dc9e8a9..3fed27fc3 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 { @@ -1832,13 +1830,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.