rozod 3.1.6 → 4.1.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/LICENSE +15 -15
- package/README.md +121 -121
- package/lib/cache.d.ts +20 -4
- package/lib/cache.js +5 -4
- package/lib/index.d.ts +8 -0
- package/lib/index.js +46 -13
- package/package.json +16 -16
- package/lib/endpoints/accountinformationv1.d.ts +0 -788
- package/lib/endpoints/accountsettingsv1.d.ts +0 -881
- package/lib/endpoints/assetdeliveryv1.d.ts +0 -847
- package/lib/endpoints/assetdeliveryv2.d.ts +0 -849
- package/lib/endpoints/authv1.d.ts +0 -1615
- package/lib/endpoints/authv2.d.ts +0 -1374
- package/lib/endpoints/authv3.d.ts +0 -59
- package/lib/endpoints/avatarv1.d.ts +0 -936
- package/lib/endpoints/avatarv2.d.ts +0 -393
- package/lib/endpoints/avatarv3.d.ts +0 -279
- package/lib/endpoints/badgesv1.d.ts +0 -483
- package/lib/endpoints/catalogv1.d.ts +0 -1079
- package/lib/endpoints/chatv2.d.ts +0 -911
- package/lib/endpoints/developv1.d.ts +0 -1923
- package/lib/endpoints/developv2.d.ts +0 -418
- package/lib/endpoints/economyv1.d.ts +0 -32
- package/lib/endpoints/friendsv1.d.ts +0 -1124
- package/lib/endpoints/gamejoinv1.d.ts +0 -424
- package/lib/endpoints/gamesv1.d.ts +0 -1807
- package/lib/endpoints/gamesv2.d.ts +0 -389
- package/lib/endpoints/groupsv1.d.ts +0 -3438
- package/lib/endpoints/groupsv2.d.ts +0 -259
- package/lib/endpoints/inventoryv1.d.ts +0 -610
- package/lib/endpoints/inventoryv2.d.ts +0 -331
- package/lib/endpoints/itemconfigurationv1.d.ts +0 -563
- package/lib/endpoints/presencev1.d.ts +0 -116
- package/lib/endpoints/privatemessagesv1.d.ts +0 -420
- package/lib/endpoints/thumbnailsv1.d.ts +0 -1054
- package/lib/endpoints/tradesv1.d.ts +0 -534
- package/lib/endpoints/translationsv1.d.ts +0 -174
- package/lib/endpoints/usersv1.d.ts +0 -693
package/LICENSE
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
ISC License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2023 Alex Op
|
|
4
|
-
|
|
5
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
-
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
-
copyright notice and this permission notice appear in all copies.
|
|
8
|
-
|
|
9
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
-
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
-
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
-
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
-
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
-
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
15
|
-
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Alex Op
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
15
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,121 +1,121 @@
|
|
|
1
|
-
<h1 align="center" style="height: 200; overflow: 'hidden'">
|
|
2
|
-
<img src="https://github.com/alexop1000/RoZod/assets/46445843/1c2a6cb5-b1d6-4784-b084-0679d81109c3" alt="RoZod" width="400" />
|
|
3
|
-
<br>
|
|
4
|
-
|
|
5
|
-
</h1>
|
|
6
|
-
|
|
7
|
-
<h4 align="center">A TypeScript package designed to simplify fully type-safe data fetching from the Roblox API.</h4>
|
|
8
|
-
|
|
9
|
-
<p align="center">
|
|
10
|
-
<a href="https://www.npmjs.com/package/rozod"><img alt="npm bundle size" src="https://img.shields.io/bundlephobia/minzip/rozod?style=for-the-badge"></a>
|
|
11
|
-
<a href="https://www.npmjs.com/package/rozod"><img alt="npm" src="https://img.shields.io/npm/v/rozod?style=for-the-badge"></a>
|
|
12
|
-
<a href="https://www.npmjs.com/package/rozod"><img alt="npm" src="https://img.shields.io/npm/dt/rozod?style=for-the-badge"></a>
|
|
13
|
-
</p>
|
|
14
|
-
<p align="center">
|
|
15
|
-
<a href="#about">About</a> •
|
|
16
|
-
<a href="#features">Features</a> •
|
|
17
|
-
<a href="#installation">Installation</a> •
|
|
18
|
-
<a href="#usage">Usage</a> •
|
|
19
|
-
<a href="#credits">Credits</a> •
|
|
20
|
-
<a href="#disclaimer">Disclaimer</a>
|
|
21
|
-
</p>
|
|
22
|
-
|
|
23
|
-
---
|
|
24
|
-
|
|
25
|
-
## About
|
|
26
|
-
`RoZod` is a TypeScript package designed to simplify fetching data from the Roblox API. It provides the functions `fetchApi`, `fetchApiPages`, and `fetchApliSplit`.
|
|
27
|
-
These allow you to get fully typesafe data from the Roblox API with minimal effort. You can also make custom endpoints to use in any context.
|
|
28
|
-
|
|
29
|
-
## Features
|
|
30
|
-
|
|
31
|
-
- Type-safe API requests and responses
|
|
32
|
-
- Automatic validation of request and response data
|
|
33
|
-
- Helper functions for paginated requests and splitting requests
|
|
34
|
-
|
|
35
|
-
## Installation
|
|
36
|
-
|
|
37
|
-
To install the package, run the following command:
|
|
38
|
-
|
|
39
|
-
```bash
|
|
40
|
-
npm install rozod
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
---
|
|
44
|
-
|
|
45
|
-
## Usage
|
|
46
|
-
First, import the necessary functions and an example endpoint from the RoZod package:
|
|
47
|
-
|
|
48
|
-
```ts
|
|
49
|
-
import { fetchApi, fetchApiSplit, fetchApiPages, fetchApiPagesGenerator } from 'rozod';
|
|
50
|
-
import { getTradesTradestatustype } from 'rozod/lib/endpoints/tradesv1';
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
### Simple API Request
|
|
54
|
-
|
|
55
|
-
To make a simple API request, use the `fetchApi` function, and any endpoint from our exports:
|
|
56
|
-
|
|
57
|
-
```ts
|
|
58
|
-
const response = await fetchApi(getTradesTradestatustype, { tradeStatusType: 1 });
|
|
59
|
-
console.log(response);
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
### Split API Request
|
|
63
|
-
To split a request into multiple requests based on specified parameters, use the `fetchApiSplit` function:
|
|
64
|
-
|
|
65
|
-
```ts
|
|
66
|
-
const data = await fetchApiSplit(getGamesIcons, { universeIds: [1534453623, 65241, ...] }, { universeIds: 100 });
|
|
67
|
-
console.log(data);
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
### Fetching All Pages
|
|
71
|
-
To fetch all pages of a paginated endpoint, use the `fetchApiPages` function:
|
|
72
|
-
|
|
73
|
-
```ts
|
|
74
|
-
const allPages = await fetchApiPages(getGroupsGroupidWallPosts, { groupId: 11479637 });
|
|
75
|
-
console.log(allPages);
|
|
76
|
-
```
|
|
77
|
-
### Fetching Pages with a Generator
|
|
78
|
-
To fetch pages one at a time using an async generator, use the `fetchApiPagesGenerator` function:
|
|
79
|
-
|
|
80
|
-
```ts
|
|
81
|
-
const pages = fetchApiPagesGenerator(getGroupsGroupidWallPosts, { groupId: 11479637 });
|
|
82
|
-
for await (const page of pages) {
|
|
83
|
-
console.log(page);
|
|
84
|
-
}
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
### Custom Endpoints
|
|
88
|
-
To create a custom endpoint, define an EndpointSchema object and export it. Here's an example of an endpoint from tradesv1.ts:
|
|
89
|
-
```ts
|
|
90
|
-
import { z, endpoint } from 'zod';
|
|
91
|
-
|
|
92
|
-
export const getV1tradesTradeStatusType = endpoint({
|
|
93
|
-
method: 'get' as const,
|
|
94
|
-
path: '/v1/trades/:tradeStatusType', // Path parameters are optional
|
|
95
|
-
baseUrl: 'https://trades.roblox.com',
|
|
96
|
-
requestFormat: 'json' as const,
|
|
97
|
-
parameters: {
|
|
98
|
-
tradeStatusType: z.union([z.literal(1), z.literal(2), z.literal(3), z.literal(4)]),
|
|
99
|
-
limit: z
|
|
100
|
-
.union([z.literal(10), z.literal(25), z.literal(50), z.literal(100)])
|
|
101
|
-
.optional()
|
|
102
|
-
.default(10),
|
|
103
|
-
cursor: z.string().optional(),
|
|
104
|
-
sortOrder: z.enum(['Asc', 'Desc']).optional().default('Asc'),
|
|
105
|
-
}, // Parameters are optional
|
|
106
|
-
response: ..., // Zod schema
|
|
107
|
-
};
|
|
108
|
-
```
|
|
109
|
-
You can then use the endpoint with the `fetchApi` function:
|
|
110
|
-
```ts
|
|
111
|
-
const response = await fetchApi(getV1tradesTradeStatusType, { tradeStatusType: 1 });
|
|
112
|
-
console.log(response);
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
---
|
|
116
|
-
|
|
117
|
-
## Credits
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
## Disclaimer
|
|
121
|
-
RoZod is not affiliated with, maintained, authorized, endorsed, or sponsored by Roblox Corporation or any of its affiliates.
|
|
1
|
+
<h1 align="center" style="height: 200; overflow: 'hidden'">
|
|
2
|
+
<img src="https://github.com/alexop1000/RoZod/assets/46445843/1c2a6cb5-b1d6-4784-b084-0679d81109c3" alt="RoZod" width="400" />
|
|
3
|
+
<br>
|
|
4
|
+
|
|
5
|
+
</h1>
|
|
6
|
+
|
|
7
|
+
<h4 align="center">A TypeScript package designed to simplify fully type-safe data fetching from the Roblox API.</h4>
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
<a href="https://www.npmjs.com/package/rozod"><img alt="npm bundle size" src="https://img.shields.io/bundlephobia/minzip/rozod?style=for-the-badge"></a>
|
|
11
|
+
<a href="https://www.npmjs.com/package/rozod"><img alt="npm" src="https://img.shields.io/npm/v/rozod?style=for-the-badge"></a>
|
|
12
|
+
<a href="https://www.npmjs.com/package/rozod"><img alt="npm" src="https://img.shields.io/npm/dt/rozod?style=for-the-badge"></a>
|
|
13
|
+
</p>
|
|
14
|
+
<p align="center">
|
|
15
|
+
<a href="#about">About</a> •
|
|
16
|
+
<a href="#features">Features</a> •
|
|
17
|
+
<a href="#installation">Installation</a> •
|
|
18
|
+
<a href="#usage">Usage</a> •
|
|
19
|
+
<a href="#credits">Credits</a> •
|
|
20
|
+
<a href="#disclaimer">Disclaimer</a>
|
|
21
|
+
</p>
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## About
|
|
26
|
+
`RoZod` is a TypeScript package designed to simplify fetching data from the Roblox API. It provides the functions `fetchApi`, `fetchApiPages`, and `fetchApliSplit`.
|
|
27
|
+
These allow you to get fully typesafe data from the Roblox API with minimal effort. You can also make custom endpoints to use in any context.
|
|
28
|
+
|
|
29
|
+
## Features
|
|
30
|
+
|
|
31
|
+
- Type-safe API requests and responses
|
|
32
|
+
- Automatic validation of request and response data
|
|
33
|
+
- Helper functions for paginated requests and splitting requests
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
To install the package, run the following command:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npm install rozod
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## Usage
|
|
46
|
+
First, import the necessary functions and an example endpoint from the RoZod package:
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
import { fetchApi, fetchApiSplit, fetchApiPages, fetchApiPagesGenerator } from 'rozod';
|
|
50
|
+
import { getTradesTradestatustype } from 'rozod/lib/endpoints/tradesv1';
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Simple API Request
|
|
54
|
+
|
|
55
|
+
To make a simple API request, use the `fetchApi` function, and any endpoint from our exports:
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
const response = await fetchApi(getTradesTradestatustype, { tradeStatusType: 1 });
|
|
59
|
+
console.log(response);
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Split API Request
|
|
63
|
+
To split a request into multiple requests based on specified parameters, use the `fetchApiSplit` function:
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
const data = await fetchApiSplit(getGamesIcons, { universeIds: [1534453623, 65241, ...] }, { universeIds: 100 });
|
|
67
|
+
console.log(data);
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Fetching All Pages
|
|
71
|
+
To fetch all pages of a paginated endpoint, use the `fetchApiPages` function:
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
const allPages = await fetchApiPages(getGroupsGroupidWallPosts, { groupId: 11479637 });
|
|
75
|
+
console.log(allPages);
|
|
76
|
+
```
|
|
77
|
+
### Fetching Pages with a Generator
|
|
78
|
+
To fetch pages one at a time using an async generator, use the `fetchApiPagesGenerator` function:
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
const pages = fetchApiPagesGenerator(getGroupsGroupidWallPosts, { groupId: 11479637 });
|
|
82
|
+
for await (const page of pages) {
|
|
83
|
+
console.log(page);
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Custom Endpoints
|
|
88
|
+
To create a custom endpoint, define an EndpointSchema object and export it. Here's an example of an endpoint from tradesv1.ts:
|
|
89
|
+
```ts
|
|
90
|
+
import { z, endpoint } from 'zod';
|
|
91
|
+
|
|
92
|
+
export const getV1tradesTradeStatusType = endpoint({
|
|
93
|
+
method: 'get' as const,
|
|
94
|
+
path: '/v1/trades/:tradeStatusType', // Path parameters are optional
|
|
95
|
+
baseUrl: 'https://trades.roblox.com',
|
|
96
|
+
requestFormat: 'json' as const,
|
|
97
|
+
parameters: {
|
|
98
|
+
tradeStatusType: z.union([z.literal(1), z.literal(2), z.literal(3), z.literal(4)]),
|
|
99
|
+
limit: z
|
|
100
|
+
.union([z.literal(10), z.literal(25), z.literal(50), z.literal(100)])
|
|
101
|
+
.optional()
|
|
102
|
+
.default(10),
|
|
103
|
+
cursor: z.string().optional(),
|
|
104
|
+
sortOrder: z.enum(['Asc', 'Desc']).optional().default('Asc'),
|
|
105
|
+
}, // Parameters are optional
|
|
106
|
+
response: ..., // Zod schema
|
|
107
|
+
};
|
|
108
|
+
```
|
|
109
|
+
You can then use the endpoint with the `fetchApi` function:
|
|
110
|
+
```ts
|
|
111
|
+
const response = await fetchApi(getV1tradesTradeStatusType, { tradeStatusType: 1 });
|
|
112
|
+
console.log(response);
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## Credits
|
|
118
|
+
This repository is maintained by Alrovi ApS, the company behind RoGold.
|
|
119
|
+
|
|
120
|
+
## Disclaimer
|
|
121
|
+
RoZod is not affiliated with, maintained, authorized, endorsed, or sponsored by Roblox Corporation or any of its affiliates.
|
package/lib/cache.d.ts
CHANGED
|
@@ -8,7 +8,26 @@ interface CacheStore<T> {
|
|
|
8
8
|
delete(key: string): Promise<void>;
|
|
9
9
|
clear(): Promise<void>;
|
|
10
10
|
}
|
|
11
|
-
declare class
|
|
11
|
+
export declare class MemoryStore<T> implements CacheStore<T> {
|
|
12
|
+
private store;
|
|
13
|
+
get(key: string): Promise<CacheEntry<T> | null>;
|
|
14
|
+
set(key: string, value: CacheEntry<T>): Promise<void>;
|
|
15
|
+
delete(key: string): Promise<void>;
|
|
16
|
+
clear(): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
export declare class LocalStorageStore<T> implements CacheStore<T> {
|
|
19
|
+
get(key: string): Promise<CacheEntry<T> | null>;
|
|
20
|
+
set(key: string, value: CacheEntry<T>): Promise<void>;
|
|
21
|
+
delete(key: string): Promise<void>;
|
|
22
|
+
clear(): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
export declare class ChromeStore<T> implements CacheStore<T> {
|
|
25
|
+
get(key: string): Promise<CacheEntry<T> | null>;
|
|
26
|
+
set(key: string, value: CacheEntry<T>): Promise<void>;
|
|
27
|
+
delete(key: string): Promise<void>;
|
|
28
|
+
clear(): Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
export declare class Cache<T> {
|
|
12
31
|
private store;
|
|
13
32
|
constructor(store: CacheStore<T>);
|
|
14
33
|
get(key: string): Promise<T | null>;
|
|
@@ -16,7 +35,4 @@ declare class Cache<T> {
|
|
|
16
35
|
delete(key: string): Promise<void>;
|
|
17
36
|
clear(): Promise<void>;
|
|
18
37
|
}
|
|
19
|
-
export declare const cache: Cache<unknown>;
|
|
20
|
-
export declare const localStorageCache: Cache<unknown>;
|
|
21
|
-
export declare const chromeStorageCache: Cache<unknown>;
|
|
22
38
|
export {};
|
package/lib/cache.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.Cache = exports.ChromeStore = exports.LocalStorageStore = exports.MemoryStore = void 0;
|
|
4
4
|
class MemoryStore {
|
|
5
5
|
store = {};
|
|
6
6
|
async get(key) {
|
|
@@ -16,6 +16,7 @@ class MemoryStore {
|
|
|
16
16
|
this.store = {};
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
+
exports.MemoryStore = MemoryStore;
|
|
19
20
|
class LocalStorageStore {
|
|
20
21
|
async get(key) {
|
|
21
22
|
const value = localStorage.getItem(key);
|
|
@@ -31,6 +32,7 @@ class LocalStorageStore {
|
|
|
31
32
|
localStorage.clear();
|
|
32
33
|
}
|
|
33
34
|
}
|
|
35
|
+
exports.LocalStorageStore = LocalStorageStore;
|
|
34
36
|
class ChromeStore {
|
|
35
37
|
async get(key) {
|
|
36
38
|
return new Promise((resolve) => {
|
|
@@ -61,6 +63,7 @@ class ChromeStore {
|
|
|
61
63
|
});
|
|
62
64
|
}
|
|
63
65
|
}
|
|
66
|
+
exports.ChromeStore = ChromeStore;
|
|
64
67
|
class Cache {
|
|
65
68
|
store;
|
|
66
69
|
constructor(store) {
|
|
@@ -90,6 +93,4 @@ class Cache {
|
|
|
90
93
|
await this.store.clear();
|
|
91
94
|
}
|
|
92
95
|
}
|
|
93
|
-
exports.
|
|
94
|
-
exports.localStorageCache = new Cache(new LocalStorageStore());
|
|
95
|
-
exports.chromeStorageCache = new Cache(new ChromeStore());
|
|
96
|
+
exports.Cache = Cache;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { HBAClient } from 'roblox-bat';
|
|
2
3
|
type RequestMethod = 'get' | 'post' | 'put' | 'delete' | 'patch';
|
|
3
4
|
type RequestFormat = 'json' | 'text' | 'form-data';
|
|
4
5
|
type SerializationMethod = Record<string, {
|
|
@@ -72,6 +73,13 @@ type CacheOptions = {
|
|
|
72
73
|
cacheType?: 'memory' | 'local' | 'chrome';
|
|
73
74
|
};
|
|
74
75
|
type RequestOptions = RequestInit & RetryOptions & ErrorOptions & CacheOptions;
|
|
76
|
+
export declare const hbaClient: HBAClient;
|
|
77
|
+
/**
|
|
78
|
+
* Allows you to change the Crypto Key pair used by the internal hardware-based authentication signatures. This should only be used in a NodeJS context.
|
|
79
|
+
*
|
|
80
|
+
* @param keys The crypto key pair.
|
|
81
|
+
*/
|
|
82
|
+
export declare function changeHBAKeys(keys?: CryptoKeyPair): void;
|
|
75
83
|
/**
|
|
76
84
|
* Fetches the data from the given endpoint and returns it.
|
|
77
85
|
*
|
package/lib/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.endpoint = exports.fetchApiPagesGenerator = exports.fetchApiPages = exports.fetchApiSplit = exports.fetchApi = void 0;
|
|
3
|
+
exports.endpoint = exports.fetchApiPagesGenerator = exports.fetchApiPages = exports.fetchApiSplit = exports.fetchApi = exports.changeHBAKeys = exports.hbaClient = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const cache_1 = require("./cache");
|
|
6
|
+
const roblox_bat_1 = require("roblox-bat");
|
|
6
7
|
const endpoint = (endpoint) => {
|
|
7
8
|
return endpoint;
|
|
8
9
|
};
|
|
@@ -26,7 +27,7 @@ function replacePathParam(path, key, value) {
|
|
|
26
27
|
// A helper function to serialize a value into a query parameter
|
|
27
28
|
function serializeQueryParam(key, value, serializationMethod) {
|
|
28
29
|
const mapStr = (v, joiner) => v.map(String).join(joiner);
|
|
29
|
-
if (!serializationMethod
|
|
30
|
+
if (!serializationMethod?.[key]) {
|
|
30
31
|
return Array.isArray(value) ? mapStr(value, ',') : String(value);
|
|
31
32
|
}
|
|
32
33
|
const { style, explode } = serializationMethod[key];
|
|
@@ -46,6 +47,8 @@ function prepareRequestUrl(endpoint, extendedParams) {
|
|
|
46
47
|
for (const key in extendedParams) {
|
|
47
48
|
if (!{}.hasOwnProperty.call(extendedParams, key))
|
|
48
49
|
continue;
|
|
50
|
+
if (key === 'body')
|
|
51
|
+
continue;
|
|
49
52
|
const value = extendedParams[key];
|
|
50
53
|
processedPath = replacePathParam(processedPath, key, value);
|
|
51
54
|
const serializedValue = serializeQueryParam(key, value, endpoint.serializationMethod);
|
|
@@ -67,6 +70,29 @@ function prepareRequestBody(method, requestFormat, body) {
|
|
|
67
70
|
}
|
|
68
71
|
return body;
|
|
69
72
|
}
|
|
73
|
+
exports.hbaClient = new roblox_bat_1.HBAClient({
|
|
74
|
+
onSite: 'document' in globalThis && globalThis.location.href.includes('.roblox.com'),
|
|
75
|
+
});
|
|
76
|
+
async function fetch(url, info) {
|
|
77
|
+
const headers = new Headers(info?.headers);
|
|
78
|
+
const setHeaders = await exports.hbaClient.generateBaseHeaders(url, info?.body);
|
|
79
|
+
for (const key in setHeaders) {
|
|
80
|
+
headers.set(key, setHeaders[key]);
|
|
81
|
+
}
|
|
82
|
+
return globalThis.fetch(url, {
|
|
83
|
+
...info,
|
|
84
|
+
headers,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Allows you to change the Crypto Key pair used by the internal hardware-based authentication signatures. This should only be used in a NodeJS context.
|
|
89
|
+
*
|
|
90
|
+
* @param keys The crypto key pair.
|
|
91
|
+
*/
|
|
92
|
+
function changeHBAKeys(keys) {
|
|
93
|
+
exports.hbaClient.suppliedCryptoKeyPair = keys;
|
|
94
|
+
}
|
|
95
|
+
exports.changeHBAKeys = changeHBAKeys;
|
|
70
96
|
async function handleRetryFetch(url, requestOptions, retries, retryDelay, body, method) {
|
|
71
97
|
let response = undefined;
|
|
72
98
|
while (response === undefined) {
|
|
@@ -88,6 +114,9 @@ async function handleRetryFetch(url, requestOptions, retries, retryDelay, body,
|
|
|
88
114
|
}
|
|
89
115
|
return response;
|
|
90
116
|
}
|
|
117
|
+
const localStorageCache = new cache_1.Cache(new cache_1.LocalStorageStore());
|
|
118
|
+
const chromeStorageCache = new cache_1.Cache(new cache_1.ChromeStore());
|
|
119
|
+
const cache = new cache_1.Cache(new cache_1.MemoryStore());
|
|
91
120
|
/**
|
|
92
121
|
* Fetches the data from the given endpoint and returns it.
|
|
93
122
|
*
|
|
@@ -105,13 +134,13 @@ async function fetchApi(endpoint, params, requestOptions = { mode: 'cors', crede
|
|
|
105
134
|
const cacheKey = requestOptions.cacheKey;
|
|
106
135
|
let cacheToUse;
|
|
107
136
|
if (requestOptions.cacheType === 'local') {
|
|
108
|
-
cacheToUse =
|
|
137
|
+
cacheToUse = localStorageCache;
|
|
109
138
|
}
|
|
110
139
|
else if (requestOptions.cacheType === 'chrome') {
|
|
111
|
-
cacheToUse =
|
|
140
|
+
cacheToUse = chromeStorageCache;
|
|
112
141
|
}
|
|
113
142
|
else {
|
|
114
|
-
cacheToUse =
|
|
143
|
+
cacheToUse = cache;
|
|
115
144
|
}
|
|
116
145
|
const cachedResponse = cacheKey && cacheToUse.get(cacheKey);
|
|
117
146
|
if (cachedResponse) {
|
|
@@ -122,13 +151,16 @@ async function fetchApi(endpoint, params, requestOptions = { mode: 'cors', crede
|
|
|
122
151
|
const response = await handleRetryFetch(url, requestOptions, retries, retryDelay, body, method);
|
|
123
152
|
const error = endpoint.errors?.find(({ status }) => status === response.status);
|
|
124
153
|
if (error) {
|
|
125
|
-
if (requestOptions.throwOnError) {
|
|
154
|
+
if (requestOptions.throwOnError === false) {
|
|
126
155
|
throw new Error(error.description);
|
|
127
156
|
}
|
|
128
157
|
else {
|
|
129
|
-
return
|
|
158
|
+
return error.description;
|
|
130
159
|
}
|
|
131
160
|
}
|
|
161
|
+
if (requestFormat === 'json' && !response.headers.get('content-type')?.includes('application/json')) {
|
|
162
|
+
throw new Error('Invalid response data');
|
|
163
|
+
}
|
|
132
164
|
if (requestOptions.cacheTime && cacheKey) {
|
|
133
165
|
const responseClone = response.clone();
|
|
134
166
|
const cacheTime = requestOptions.cacheTime;
|
|
@@ -137,9 +169,6 @@ async function fetchApi(endpoint, params, requestOptions = { mode: 'cors', crede
|
|
|
137
169
|
}, cacheTime);
|
|
138
170
|
cacheToUse.set(cacheKey, requestFormat === 'json' ? await responseClone.json() : await responseClone.text(), cacheTime);
|
|
139
171
|
}
|
|
140
|
-
if (requestFormat === 'json' && !response.headers.get('content-type')?.includes('application/json')) {
|
|
141
|
-
throw new Error('Invalid response data');
|
|
142
|
-
}
|
|
143
172
|
return requestFormat === 'json' ? await response.json() : await response.text();
|
|
144
173
|
}
|
|
145
174
|
exports.fetchApi = fetchApi;
|
|
@@ -168,7 +197,7 @@ async function fetchApiSplit(endpoint, params, max, transform = (response) => re
|
|
|
168
197
|
}
|
|
169
198
|
const splitParams = [];
|
|
170
199
|
for (const key in max) {
|
|
171
|
-
if (!
|
|
200
|
+
if (!Object.hasOwn(max, key) || !{}.hasOwnProperty.call(params, key)) {
|
|
172
201
|
continue;
|
|
173
202
|
}
|
|
174
203
|
const maxItems = max[key];
|
|
@@ -203,8 +232,12 @@ exports.fetchApiSplit = fetchApiSplit;
|
|
|
203
232
|
*/
|
|
204
233
|
async function fetchApiPages(endpoint, initialParams, requestOptions, limit = 1000) {
|
|
205
234
|
const allResults = [];
|
|
206
|
-
for await (const
|
|
207
|
-
|
|
235
|
+
for await (const response of fetchApiPagesGenerator(endpoint, initialParams, requestOptions, limit)) {
|
|
236
|
+
if (response === null || response === undefined) {
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
const { nextPageCursor, ...rest } = response;
|
|
240
|
+
allResults.push(rest);
|
|
208
241
|
if (allResults.length >= limit || nextPageCursor === null || nextPageCursor === undefined) {
|
|
209
242
|
break;
|
|
210
243
|
}
|
package/package.json
CHANGED
|
@@ -1,36 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rozod",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "A TypeScript wrapper for the Roblox API",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
7
|
-
"
|
|
8
|
-
"test": "jest --config jestconfig.json",
|
|
9
|
-
"build": "tsc && tsc --project tsconfig.declarations.json",
|
|
10
|
-
"format": "prettier --write \"src/**/*.ts\"",
|
|
11
|
-
"lint": "tslint -p tsconfig.json",
|
|
12
|
-
"prepare": "npm run build",
|
|
13
|
-
"prepublishOnly": "npm test",
|
|
14
|
-
"version": "npm run format && git add -A src",
|
|
15
|
-
"generate": "node ./zodios-endpoints.js"
|
|
16
|
-
},
|
|
17
|
-
"author": "alexop1000",
|
|
7
|
+
"author": "AlroviOfficial",
|
|
18
8
|
"license": "ISC",
|
|
19
9
|
"dependencies": {
|
|
20
10
|
"@alexop/openapi-zod-client": "^1.10.2",
|
|
21
11
|
"p-limit": "^3.0.0",
|
|
12
|
+
"roblox-bat": "^0.1.1",
|
|
22
13
|
"zod": "^3.21.4"
|
|
23
14
|
},
|
|
24
15
|
"repository": {
|
|
25
|
-
"url": "https://github.com/
|
|
16
|
+
"url": "https://github.com/AlroviOfficial/RoZod"
|
|
26
17
|
},
|
|
27
18
|
"bugs": {
|
|
28
|
-
"url": "https://github.com/
|
|
19
|
+
"url": "https://github.com/AlroviOfficial/RoZod/issues"
|
|
29
20
|
},
|
|
30
21
|
"devDependencies": {
|
|
31
22
|
"@apidevtools/swagger-parser": "^10.1.0",
|
|
32
23
|
"@thepotato97/openapi-zod-client": "^1.6.4",
|
|
33
24
|
"@types/jest": "^29.5.1",
|
|
25
|
+
"@types/jsdom": "^21.1.2",
|
|
34
26
|
"@zodios/plugins": "^10.6.0",
|
|
35
27
|
"jest": "^29.5.0",
|
|
36
28
|
"prettier": "^2.8.8",
|
|
@@ -51,5 +43,13 @@
|
|
|
51
43
|
],
|
|
52
44
|
"files": [
|
|
53
45
|
"lib/**/*"
|
|
54
|
-
]
|
|
55
|
-
|
|
46
|
+
],
|
|
47
|
+
"scripts": {
|
|
48
|
+
"test": "jest --config jestconfig.json",
|
|
49
|
+
"build": "tsc && tsc --project tsconfig.declarations.json",
|
|
50
|
+
"format": "prettier --write \"src/**/*.ts\"",
|
|
51
|
+
"lint": "tslint -p tsconfig.json",
|
|
52
|
+
"version": "npm run format && git add -A src",
|
|
53
|
+
"generate": "node ./zodios-endpoints.js"
|
|
54
|
+
}
|
|
55
|
+
}
|