rozod 1.0.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.
- package/lib/endpoints/accountinformationv1.d.ts +551 -0
- package/lib/endpoints/accountinformationv1.js +652 -0
- package/lib/endpoints/accountsettingsv1.d.ts +548 -0
- package/lib/endpoints/accountsettingsv1.js +712 -0
- package/lib/endpoints/assetdeliveryv1.d.ts +599 -0
- package/lib/endpoints/assetdeliveryv1.js +268 -0
- package/lib/endpoints/assetdeliveryv2.d.ts +780 -0
- package/lib/endpoints/assetdeliveryv2.js +271 -0
- package/lib/endpoints/authv1.d.ts +1328 -0
- package/lib/endpoints/authv1.js +1168 -0
- package/lib/endpoints/authv2.d.ts +1239 -0
- package/lib/endpoints/authv2.js +1057 -0
- package/lib/endpoints/authv3.d.ts +35 -0
- package/lib/endpoints/authv3.js +41 -0
- package/lib/endpoints/avatarv1.d.ts +1841 -0
- package/lib/endpoints/avatarv1.js +726 -0
- package/lib/endpoints/avatarv2.d.ts +1077 -0
- package/lib/endpoints/avatarv2.js +316 -0
- package/lib/endpoints/avatarv3.d.ts +656 -0
- package/lib/endpoints/avatarv3.js +219 -0
- package/lib/endpoints/badgesv1.d.ts +641 -0
- package/lib/endpoints/badgesv1.js +345 -0
- package/lib/endpoints/catalogv1.d.ts +1715 -0
- package/lib/endpoints/catalogv1.js +792 -0
- package/lib/endpoints/chatv2.d.ts +2179 -0
- package/lib/endpoints/chatv2.js +721 -0
- package/lib/endpoints/developv1.d.ts +2097 -0
- package/lib/endpoints/developv1.js +1537 -0
- package/lib/endpoints/developv2.d.ts +619 -0
- package/lib/endpoints/developv2.js +316 -0
- package/lib/endpoints/economyv1.d.ts +20 -0
- package/lib/endpoints/economyv1.js +28 -0
- package/lib/endpoints/friendsv1.d.ts +1093 -0
- package/lib/endpoints/friendsv1.js +818 -0
- package/lib/endpoints/gamesv1.d.ts +2749 -0
- package/lib/endpoints/gamesv1.js +1294 -0
- package/lib/endpoints/gamesv2.d.ts +582 -0
- package/lib/endpoints/gamesv2.js +258 -0
- package/lib/endpoints/groupsv1.d.ts +5528 -0
- package/lib/endpoints/groupsv1.js +2434 -0
- package/lib/endpoints/groupsv2.d.ts +530 -0
- package/lib/endpoints/groupsv2.js +201 -0
- package/lib/endpoints/inventoryv1.d.ts +436 -0
- package/lib/endpoints/inventoryv1.js +434 -0
- package/lib/endpoints/inventoryv2.d.ts +256 -0
- package/lib/endpoints/inventoryv2.js +241 -0
- package/lib/endpoints/presencev1.d.ts +134 -0
- package/lib/endpoints/presencev1.js +93 -0
- package/lib/endpoints/privatemessagesv1.d.ts +620 -0
- package/lib/endpoints/privatemessagesv1.js +338 -0
- package/lib/endpoints/thumbnailsv1.d.ts +897 -0
- package/lib/endpoints/thumbnailsv1.js +560 -0
- package/lib/endpoints/tradesv1.d.ts +473 -0
- package/lib/endpoints/tradesv1.js +403 -0
- package/lib/endpoints/translationsv1.d.ts +80 -0
- package/lib/endpoints/translationsv1.js +122 -0
- package/lib/endpoints/usersv1.d.ts +391 -0
- package/lib/endpoints/usersv1.js +344 -0
- package/lib/index.d.ts +85 -0
- package/lib/index.js +293 -0
- package/package.json +39 -0
- package/readme.md +99 -0
package/lib/index.js
ADDED
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
50
|
+
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
51
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
52
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
53
|
+
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
54
|
+
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
|
55
|
+
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
56
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
57
|
+
function fulfill(value) { resume("next", value); }
|
|
58
|
+
function reject(value) { resume("throw", value); }
|
|
59
|
+
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
60
|
+
};
|
|
61
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
62
|
+
exports.fetchApiPagesGenerator = exports.fetchApiPages = exports.fetchApiSplit = exports.fetchApi = void 0;
|
|
63
|
+
var zod_1 = require("zod");
|
|
64
|
+
function extractDefaultValues(endpoint) {
|
|
65
|
+
var defaultValues = {};
|
|
66
|
+
var paramKeys = Object.keys(endpoint.parameters);
|
|
67
|
+
for (var _i = 0, paramKeys_1 = paramKeys; _i < paramKeys_1.length; _i++) {
|
|
68
|
+
var key = paramKeys_1[_i];
|
|
69
|
+
var schema = endpoint.parameters[key];
|
|
70
|
+
if (schema instanceof zod_1.z.ZodDefault) {
|
|
71
|
+
defaultValues[key] = schema._def.defaultValue();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return defaultValues;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Fetches the data from the given endpoint and returns it.
|
|
78
|
+
*
|
|
79
|
+
* @param endpoint The endpoint to fetch from.
|
|
80
|
+
* @param params The parameters to pass to the endpoint.
|
|
81
|
+
* @param requestOptions Any additional options to pass to fetch.
|
|
82
|
+
* @returns The response from the endpoint.
|
|
83
|
+
*/
|
|
84
|
+
function fetchApi(endpoint, params, requestOptions) {
|
|
85
|
+
if (requestOptions === void 0) { requestOptions = { mode: 'cors', credentials: 'include' }; }
|
|
86
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
87
|
+
var method, path, requestFormat, defaultValues, extendedParams, body, query, response, error, data, validationResult;
|
|
88
|
+
return __generator(this, function (_a) {
|
|
89
|
+
switch (_a.label) {
|
|
90
|
+
case 0:
|
|
91
|
+
method = endpoint.method, path = endpoint.path, requestFormat = endpoint.requestFormat;
|
|
92
|
+
defaultValues = extractDefaultValues(endpoint);
|
|
93
|
+
extendedParams = __assign(__assign({}, defaultValues), params);
|
|
94
|
+
query = '';
|
|
95
|
+
if (method !== 'get' && requestFormat === 'json') {
|
|
96
|
+
body = JSON.stringify(extendedParams);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
query = '?' + new URLSearchParams(extendedParams).toString();
|
|
100
|
+
}
|
|
101
|
+
return [4 /*yield*/, fetch(endpoint.baseUrl + path + query, __assign({ method: method, body: body }, requestOptions))];
|
|
102
|
+
case 1:
|
|
103
|
+
response = _a.sent();
|
|
104
|
+
error = endpoint.errors.find(function (_a) {
|
|
105
|
+
var status = _a.status;
|
|
106
|
+
return status === response.status;
|
|
107
|
+
});
|
|
108
|
+
if (error) {
|
|
109
|
+
throw new Error(error.description);
|
|
110
|
+
}
|
|
111
|
+
return [4 /*yield*/, response.json()];
|
|
112
|
+
case 2:
|
|
113
|
+
data = _a.sent();
|
|
114
|
+
validationResult = endpoint.response.safeParse(data);
|
|
115
|
+
if (!validationResult.success) {
|
|
116
|
+
throw new Error('Invalid response data');
|
|
117
|
+
}
|
|
118
|
+
return [2 /*return*/, validationResult.data];
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
exports.fetchApi = fetchApi;
|
|
124
|
+
/**
|
|
125
|
+
* Fetches the data from the given endpoint, but splits the request into multiple requests if the specified parameter is larger than max specified.
|
|
126
|
+
*
|
|
127
|
+
* @param endpoint The endpoint to fetch from.
|
|
128
|
+
* @param params The parameters to pass to the endpoint.
|
|
129
|
+
* @param max The maximum number of items to pass to the endpoint.
|
|
130
|
+
* @param transform A function that accepts the endpoint response and transforms it into the desired type.
|
|
131
|
+
* @param requestOptions Any additional options to pass to fetch.
|
|
132
|
+
* @returns The transformed response from the endpoint.
|
|
133
|
+
* @example
|
|
134
|
+
* ```ts
|
|
135
|
+
* const data = await fetchApiSplit(getV1gamesicons, { universeIds: [1, 2, 3, 4, 5] }, { universeIds: 100 }, (response) => response.data);
|
|
136
|
+
* console.log(data); // [[{ "targetId": 0, "state": "Completed", "imageUrl": "..." }], ...]
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
function fetchApiSplit(endpoint, params, max, transform, requestOptions) {
|
|
140
|
+
if (transform === void 0) { transform = function (response) { return response; }; }
|
|
141
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
142
|
+
var fetchTransformed, splitParams, key, maxItems, items, i, itemsSubset, newParams, allResults, _i, splitParams_1, splitParam, transformedResponse;
|
|
143
|
+
var _a;
|
|
144
|
+
var _this = this;
|
|
145
|
+
return __generator(this, function (_b) {
|
|
146
|
+
switch (_b.label) {
|
|
147
|
+
case 0:
|
|
148
|
+
fetchTransformed = function (transformparams) { return __awaiter(_this, void 0, void 0, function () {
|
|
149
|
+
var response;
|
|
150
|
+
return __generator(this, function (_a) {
|
|
151
|
+
switch (_a.label) {
|
|
152
|
+
case 0: return [4 /*yield*/, fetchApi(endpoint, transformparams, requestOptions)];
|
|
153
|
+
case 1:
|
|
154
|
+
response = _a.sent();
|
|
155
|
+
return [2 /*return*/, transform ? transform(response) : response];
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
}); };
|
|
159
|
+
if (!!max) return [3 /*break*/, 2];
|
|
160
|
+
return [4 /*yield*/, fetchTransformed(params)];
|
|
161
|
+
case 1: return [2 /*return*/, [_b.sent()]];
|
|
162
|
+
case 2:
|
|
163
|
+
splitParams = [];
|
|
164
|
+
for (key in max) {
|
|
165
|
+
if (!{}.hasOwnProperty.call(max, key) || !{}.hasOwnProperty.call(params, key)) {
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
maxItems = max[key];
|
|
169
|
+
items = params[key];
|
|
170
|
+
if (Array.isArray(items)) {
|
|
171
|
+
// eslint-disable-next-line max-depth
|
|
172
|
+
for (i = 0; i < items.length; i = i + (maxItems || 1)) {
|
|
173
|
+
itemsSubset = items.slice(i, i + (maxItems || 1));
|
|
174
|
+
newParams = __assign(__assign({}, params), (_a = {}, _a[key] = itemsSubset, _a));
|
|
175
|
+
splitParams.push(newParams);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (!(splitParams.length === 0)) return [3 /*break*/, 4];
|
|
180
|
+
return [4 /*yield*/, fetchTransformed(params)];
|
|
181
|
+
case 3: return [2 /*return*/, [_b.sent()]];
|
|
182
|
+
case 4:
|
|
183
|
+
allResults = [];
|
|
184
|
+
_i = 0, splitParams_1 = splitParams;
|
|
185
|
+
_b.label = 5;
|
|
186
|
+
case 5:
|
|
187
|
+
if (!(_i < splitParams_1.length)) return [3 /*break*/, 8];
|
|
188
|
+
splitParam = splitParams_1[_i];
|
|
189
|
+
return [4 /*yield*/, fetchTransformed(splitParam)];
|
|
190
|
+
case 6:
|
|
191
|
+
transformedResponse = _b.sent();
|
|
192
|
+
allResults.push(transformedResponse);
|
|
193
|
+
_b.label = 7;
|
|
194
|
+
case 7:
|
|
195
|
+
_i++;
|
|
196
|
+
return [3 /*break*/, 5];
|
|
197
|
+
case 8: return [2 /*return*/, allResults];
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
exports.fetchApiSplit = fetchApiSplit;
|
|
203
|
+
/**
|
|
204
|
+
* Fetches all pages of results for the given endpoint and parameters.
|
|
205
|
+
*
|
|
206
|
+
* @param endpoint The endpoint to fetch.
|
|
207
|
+
* @param initialParams The initial parameters to use for the endpoint.
|
|
208
|
+
* @param requestOptions The options to use when making requests.
|
|
209
|
+
* @param limit The maximum number of pages to fetch.
|
|
210
|
+
* @returns An array of all results.
|
|
211
|
+
*/
|
|
212
|
+
function fetchApiPages(endpoint, initialParams, requestOptions, limit) {
|
|
213
|
+
if (limit === void 0) { limit = 1000; }
|
|
214
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
215
|
+
var cursor, allResults, paramsWithCursor, response;
|
|
216
|
+
return __generator(this, function (_a) {
|
|
217
|
+
switch (_a.label) {
|
|
218
|
+
case 0:
|
|
219
|
+
allResults = [];
|
|
220
|
+
_a.label = 1;
|
|
221
|
+
case 1:
|
|
222
|
+
if (!true) return [3 /*break*/, 3];
|
|
223
|
+
paramsWithCursor = __assign(__assign({}, initialParams), { cursor: cursor });
|
|
224
|
+
return [4 /*yield*/, fetchApi(endpoint, paramsWithCursor, requestOptions)];
|
|
225
|
+
case 2:
|
|
226
|
+
response = _a.sent();
|
|
227
|
+
allResults.push(response);
|
|
228
|
+
if ('nextPageCursor' in response) {
|
|
229
|
+
cursor = response.nextPageCursor;
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
return [3 /*break*/, 3];
|
|
233
|
+
}
|
|
234
|
+
if (allResults.length >= limit) {
|
|
235
|
+
return [3 /*break*/, 3];
|
|
236
|
+
}
|
|
237
|
+
return [3 /*break*/, 1];
|
|
238
|
+
case 3: return [2 /*return*/, allResults];
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
exports.fetchApiPages = fetchApiPages;
|
|
244
|
+
/**
|
|
245
|
+
* Fetches all pages of results for the given endpoint and parameters.
|
|
246
|
+
* This is a generator function that yields each page as it is fetched.
|
|
247
|
+
*
|
|
248
|
+
* @param endpoint The endpoint to fetch.
|
|
249
|
+
* @param initialParams The initial parameters to use for the endpoint.
|
|
250
|
+
* @param requestOptions The options to use when making requests.
|
|
251
|
+
* @param limit The maximum number of pages to fetch.
|
|
252
|
+
* @returns An array of all results.
|
|
253
|
+
* @yields The next page of results.
|
|
254
|
+
* @example
|
|
255
|
+
* ```ts
|
|
256
|
+
* const pages = fetchApiPagesGenerator(getV1badgesicons, { badgeIds: [1, 2, 3] });
|
|
257
|
+
* for await (const page of pages) {
|
|
258
|
+
* console.log(page.data);
|
|
259
|
+
* }
|
|
260
|
+
* ```
|
|
261
|
+
*/
|
|
262
|
+
function fetchApiPagesGenerator(endpoint, initialParams, requestOptions, limit) {
|
|
263
|
+
if (limit === void 0) { limit = 1000; }
|
|
264
|
+
return __asyncGenerator(this, arguments, function fetchApiPagesGenerator_1() {
|
|
265
|
+
var cursor, paramsWithCursor, response;
|
|
266
|
+
return __generator(this, function (_a) {
|
|
267
|
+
switch (_a.label) {
|
|
268
|
+
case 0:
|
|
269
|
+
if (!true) return [3 /*break*/, 4];
|
|
270
|
+
paramsWithCursor = __assign(__assign({}, initialParams), { cursor: cursor });
|
|
271
|
+
return [4 /*yield*/, __await(fetchApi(endpoint, paramsWithCursor, requestOptions))];
|
|
272
|
+
case 1:
|
|
273
|
+
response = _a.sent();
|
|
274
|
+
return [4 /*yield*/, __await(response)];
|
|
275
|
+
case 2: return [4 /*yield*/, _a.sent()];
|
|
276
|
+
case 3:
|
|
277
|
+
_a.sent();
|
|
278
|
+
if ('nextPageCursor' in response) {
|
|
279
|
+
cursor = response.nextPageCursor;
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
return [3 /*break*/, 4];
|
|
283
|
+
}
|
|
284
|
+
if (limit-- <= 0) {
|
|
285
|
+
return [3 /*break*/, 4];
|
|
286
|
+
}
|
|
287
|
+
return [3 /*break*/, 0];
|
|
288
|
+
case 4: return [2 /*return*/];
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
exports.fetchApiPagesGenerator = fetchApiPagesGenerator;
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "rozod",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Wrapper for Roblox API using Zod and custom API Client using fetch",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "jest --config jestconfig.json",
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
|
|
11
|
+
"lint": "tslint -p tsconfig.json",
|
|
12
|
+
"prepare" : "npm run build",
|
|
13
|
+
"prepublishOnly" : "npm test && npm run lint",
|
|
14
|
+
"preversion" : "npm run lint",
|
|
15
|
+
"version" : "npm run format && git add -A src"
|
|
16
|
+
},
|
|
17
|
+
"author": "alexop1000",
|
|
18
|
+
"license": "ISC",
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"zod": "^3.21.4"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@apidevtools/swagger-parser": "^10.1.0",
|
|
24
|
+
"@types/jest": "^29.5.1",
|
|
25
|
+
"@zodios/plugins": "^10.6.0",
|
|
26
|
+
"jest": "^29.5.0",
|
|
27
|
+
"openapi-zod-client": "^1.6.3",
|
|
28
|
+
"prettier": "^2.8.8",
|
|
29
|
+
"swagger2openapi": "^7.0.8",
|
|
30
|
+
"ts-jest": "^29.1.0",
|
|
31
|
+
"tslint": "^6.1.3",
|
|
32
|
+
"tslint-config-prettier": "^1.18.0",
|
|
33
|
+
"typescript": "^5.0.4"
|
|
34
|
+
},
|
|
35
|
+
"keywords": [],
|
|
36
|
+
"files": [
|
|
37
|
+
"lib/**/*"
|
|
38
|
+
]
|
|
39
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# RoZod
|
|
2
|
+
|
|
3
|
+
RoZod is a TypeScript package designed to simplify fetching data from the Roblox API. It provides a set of utility functions that automatically validate request and response data using the Zod validation library.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Type-safe API requests and responses
|
|
8
|
+
- Automatic validation of request and response data
|
|
9
|
+
- Helper functions for paginated requests and splitting requests
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
To install the package, run the following command:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install rozod
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
First, import the necessary functions and an example endpoint from the RoZod package:
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { fetchApi, fetchApiSplit, fetchApiPages, fetchApiPagesGenerator } from 'rozod';
|
|
24
|
+
import { getV1tradesTradeStatusType } from 'rozod/endpoints/tradesv1';
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Simple API Request
|
|
28
|
+
|
|
29
|
+
To make a simple API request, use the `fetchApi` function, and any endpoint from our exports:
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
const response = await fetchApi(getV1tradesTradeStatusType, { tradeStatusType: 1 });
|
|
33
|
+
console.log(response);
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Split API Request
|
|
37
|
+
To split a request into multiple requests based on specified parameters, use the `fetchApiSplit` function:
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
const data = await fetchApiSplit(getV1gamesicons, { universeIds: [1534453623, 65241, ...] }, { universeIds: 100 });
|
|
41
|
+
console.log(data);
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Fetching All Pages
|
|
45
|
+
To fetch all pages of a paginated endpoint, use the `fetchApiPages` function:
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
const allPages = await fetchApiPages(getV2groupsGroupIdgames, { groupId: 11479637 });
|
|
49
|
+
console.log(allPages);
|
|
50
|
+
```
|
|
51
|
+
### Fetching Pages with a Generator
|
|
52
|
+
To fetch pages one at a time using an async generator, use the `fetchApiPagesGenerator` function:
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
const allPages = await fetchApiPages(getV2groupsGroupIdgames, { groupId: 11479637 });
|
|
56
|
+
console.log(allPages);
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Custom Endpoints
|
|
60
|
+
To create a custom endpoint, define an EndpointSchema object and export it. Here's an example of an endpoint from tradesv1.ts:
|
|
61
|
+
```ts
|
|
62
|
+
import { z } from 'zod';
|
|
63
|
+
|
|
64
|
+
export const getV1tradesTradeStatusType = {
|
|
65
|
+
method: 'get' as const,
|
|
66
|
+
path: '/v1/trades/:tradeStatusType',
|
|
67
|
+
baseUrl: 'https://trades.roblox.com',
|
|
68
|
+
requestFormat: 'json' as const,
|
|
69
|
+
parameters: {
|
|
70
|
+
tradeStatusType: z.union([z.literal(1), z.literal(2), z.literal(3), z.literal(4)]),
|
|
71
|
+
limit: z
|
|
72
|
+
.union([z.literal(10), z.literal(25), z.literal(50), z.literal(100)])
|
|
73
|
+
.optional()
|
|
74
|
+
.default(10),
|
|
75
|
+
cursor: z.string().optional(),
|
|
76
|
+
sortOrder: z.enum(['Asc', 'Desc']).optional().default('Asc'),
|
|
77
|
+
},
|
|
78
|
+
response: ...,
|
|
79
|
+
errors: [
|
|
80
|
+
{
|
|
81
|
+
status: 400,
|
|
82
|
+
description: `1: Invalid trade status type.`,
|
|
83
|
+
schema: z.void(),
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
status: 401,
|
|
87
|
+
description: `0: Authorization has been denied for this request.`,
|
|
88
|
+
schema: z.void(),
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
};
|
|
92
|
+
```
|
|
93
|
+
Replace the response with your own Zod schema to validate the response data.
|
|
94
|
+
|
|
95
|
+
## Support
|
|
96
|
+
If you encounter any issues or have questions, feel free to open an issue on the GitHub repository. We'll do our best to assist you.
|
|
97
|
+
|
|
98
|
+
## Disclaimer
|
|
99
|
+
RoZod is not affiliated with, maintained, authorized, endorsed, or sponsored by Roblox Corporation or any of its affiliates.
|