rblx.js
Version:
A JavaScript wrapper for interacting with the ROBLOX OpenCloud API.
52 lines (51 loc) • 2.36 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const urlcat_1 = __importDefault(require("urlcat"));
const axios_1 = __importDefault(require("axios"));
const BASE_URL = "https://apis.roblox.com/datastores/v1/universes";
async function main(apiKey, universeid, datastoreName, entryKey, newValue, matchVersion, exclusiveCreate) {
try {
BigInt(universeid);
}
catch (e) {
throw new Error("Invalid universeid: " + universeid);
}
if (universeid) {
const res_url = (0, urlcat_1.default)(BASE_URL, "/:universeid/standard-datastores/datastore/entries/entry?datastoreName=:datastoreName&entryKey=:entryKey", { universeid, datastoreName, entryKey });
const config = {
headers: {
"x-api-key": apiKey,
"content-type": "application/json"
}
};
const response = await axios_1.default.post(res_url, newValue, config);
return await response.data;
}
if (matchVersion) {
const res_url = (0, urlcat_1.default)(BASE_URL, "/:universeid/standard-datastores/datastore/entries/entry?datastoreName=:datastoreName&entryKey=:entryKey&matchVersion=:matchVersion", { universeid, datastoreName, entryKey, matchVersion });
const config = {
headers: {
"x-api-key": apiKey
}
};
const response = await axios_1.default.post(res_url, newValue, config);
return await response.data;
}
if (exclusiveCreate) {
const res_url = (0, urlcat_1.default)(BASE_URL, "/:universeid/standard-datastores/datastore/entries/entry?datastoreName=:datastoreName&entryKey=:entryKey&exclusiveCreate=:exclusiveCreate", { universeid, datastoreName, entryKey, exclusiveCreate });
const config = {
headers: {
"x-api-key": apiKey
}
};
const response = await axios_1.default.post(res_url, newValue, config);
return await response.data;
}
if (exclusiveCreate && matchVersion) {
throw new Error("You cannot use both matchVersion and exclusiveCreate.");
}
}
exports.default = main;