rozod 3.0.0 → 3.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/lib/cache.d.ts +19 -6
- package/lib/cache.js +77 -14
- package/lib/index.d.ts +1 -0
- package/lib/index.js +19 -11
- package/package.json +50 -50
- package/lib/endpoints/accountinformationv1.d.ts +0 -634
- package/lib/endpoints/accountsettingsv1.d.ts +0 -696
- package/lib/endpoints/assetdeliveryv1.d.ts +0 -578
- package/lib/endpoints/assetdeliveryv2.d.ts +0 -621
- package/lib/endpoints/authv1.d.ts +0 -1344
- package/lib/endpoints/authv2.d.ts +0 -1003
- package/lib/endpoints/authv3.d.ts +0 -37
- package/lib/endpoints/avatarv1.d.ts +0 -924
- package/lib/endpoints/avatarv2.d.ts +0 -394
- package/lib/endpoints/avatarv3.d.ts +0 -238
- package/lib/endpoints/badgesv1.d.ts +0 -401
- package/lib/endpoints/catalogv1.d.ts +0 -896
- package/lib/endpoints/chatv2.d.ts +0 -1006
- package/lib/endpoints/developv1.d.ts +0 -1457
- package/lib/endpoints/developv2.d.ts +0 -291
- package/lib/endpoints/economyv1.d.ts +0 -30
- package/lib/endpoints/friendsv1.d.ts +0 -854
- package/lib/endpoints/gamejoinv1.d.ts +0 -681
- package/lib/endpoints/gamesv1.d.ts +0 -1420
- package/lib/endpoints/gamesv2.d.ts +0 -266
- package/lib/endpoints/groupsv1.d.ts +0 -2719
- package/lib/endpoints/groupsv2.d.ts +0 -198
- package/lib/endpoints/inventoryv1.d.ts +0 -360
- package/lib/endpoints/inventoryv2.d.ts +0 -151
- package/lib/endpoints/itemconfigurationv1.d.ts +0 -333
- package/lib/endpoints/presencev1.d.ts +0 -101
- package/lib/endpoints/privatemessagesv1.d.ts +0 -392
- package/lib/endpoints/thumbnailsv1.d.ts +0 -795
- package/lib/endpoints/tradesv1.d.ts +0 -345
- package/lib/endpoints/translationsv1.d.ts +0 -99
- package/lib/endpoints/usersv1.d.ts +0 -567
package/lib/cache.d.ts
CHANGED
|
@@ -1,9 +1,22 @@
|
|
|
1
|
+
type CacheEntry<T> = {
|
|
2
|
+
value: T;
|
|
3
|
+
expiresAt?: number;
|
|
4
|
+
};
|
|
5
|
+
interface CacheStore<T> {
|
|
6
|
+
get(key: string): Promise<CacheEntry<T> | null>;
|
|
7
|
+
set(key: string, value: CacheEntry<T>): Promise<void>;
|
|
8
|
+
delete(key: string): Promise<void>;
|
|
9
|
+
clear(): Promise<void>;
|
|
10
|
+
}
|
|
1
11
|
declare class Cache<T> {
|
|
2
|
-
private
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
12
|
+
private store;
|
|
13
|
+
constructor(store: CacheStore<T>);
|
|
14
|
+
get(key: string): Promise<T | null>;
|
|
15
|
+
set(key: string, value: T, ttl?: number): Promise<void>;
|
|
16
|
+
delete(key: string): Promise<void>;
|
|
17
|
+
clear(): Promise<void>;
|
|
7
18
|
}
|
|
8
|
-
export declare const cache: Cache<
|
|
19
|
+
export declare const cache: Cache<unknown>;
|
|
20
|
+
export declare const localStorageCache: Cache<unknown>;
|
|
21
|
+
export declare const chromeStorageCache: Cache<unknown>;
|
|
9
22
|
export {};
|
package/lib/cache.js
CHANGED
|
@@ -1,32 +1,95 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.cache = void 0;
|
|
3
|
+
exports.chromeStorageCache = exports.localStorageCache = exports.cache = void 0;
|
|
4
|
+
class MemoryStore {
|
|
5
|
+
store = {};
|
|
6
|
+
async get(key) {
|
|
7
|
+
return this.store[key] || null;
|
|
8
|
+
}
|
|
9
|
+
async set(key, value) {
|
|
10
|
+
this.store[key] = value;
|
|
11
|
+
}
|
|
12
|
+
async delete(key) {
|
|
13
|
+
delete this.store[key];
|
|
14
|
+
}
|
|
15
|
+
async clear() {
|
|
16
|
+
this.store = {};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
class LocalStorageStore {
|
|
20
|
+
async get(key) {
|
|
21
|
+
const value = localStorage.getItem(key);
|
|
22
|
+
return value ? JSON.parse(value) : null;
|
|
23
|
+
}
|
|
24
|
+
async set(key, value) {
|
|
25
|
+
localStorage.setItem(key, JSON.stringify(value));
|
|
26
|
+
}
|
|
27
|
+
async delete(key) {
|
|
28
|
+
localStorage.removeItem(key);
|
|
29
|
+
}
|
|
30
|
+
async clear() {
|
|
31
|
+
localStorage.clear();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
class ChromeStore {
|
|
35
|
+
async get(key) {
|
|
36
|
+
return new Promise((resolve) => {
|
|
37
|
+
// @ts-ignore
|
|
38
|
+
chrome.storage.local.get(key, (result) => {
|
|
39
|
+
resolve(result[key]);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
async set(key, value) {
|
|
44
|
+
return new Promise((resolve) => {
|
|
45
|
+
let item = {};
|
|
46
|
+
item[key] = value;
|
|
47
|
+
// @ts-ignore
|
|
48
|
+
chrome.storage.local.set(item, resolve);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
async delete(key) {
|
|
52
|
+
return new Promise((resolve) => {
|
|
53
|
+
// @ts-ignore
|
|
54
|
+
chrome.storage.local.remove(key, resolve);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
async clear() {
|
|
58
|
+
return new Promise((resolve) => {
|
|
59
|
+
// @ts-ignore
|
|
60
|
+
chrome.storage.local.clear(resolve);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
4
64
|
class Cache {
|
|
5
|
-
|
|
6
|
-
|
|
65
|
+
store;
|
|
66
|
+
constructor(store) {
|
|
67
|
+
this.store = store;
|
|
7
68
|
}
|
|
8
|
-
get(key) {
|
|
9
|
-
const entry = this.
|
|
69
|
+
async get(key) {
|
|
70
|
+
const entry = await this.store.get(key);
|
|
10
71
|
if (!entry) {
|
|
11
72
|
return null;
|
|
12
73
|
}
|
|
13
74
|
if (entry.expiresAt && entry.expiresAt < Date.now()) {
|
|
14
|
-
|
|
75
|
+
await this.delete(key);
|
|
15
76
|
return null;
|
|
16
77
|
}
|
|
17
78
|
return entry.value;
|
|
18
79
|
}
|
|
19
|
-
set(key, value, ttl) {
|
|
20
|
-
this.
|
|
80
|
+
async set(key, value, ttl) {
|
|
81
|
+
await this.store.set(key, {
|
|
21
82
|
value,
|
|
22
83
|
expiresAt: ttl ? Date.now() + ttl : undefined,
|
|
23
|
-
};
|
|
84
|
+
});
|
|
24
85
|
}
|
|
25
|
-
delete(key) {
|
|
26
|
-
|
|
86
|
+
async delete(key) {
|
|
87
|
+
await this.store.delete(key);
|
|
27
88
|
}
|
|
28
|
-
clear() {
|
|
29
|
-
this.
|
|
89
|
+
async clear() {
|
|
90
|
+
await this.store.clear();
|
|
30
91
|
}
|
|
31
92
|
}
|
|
32
|
-
exports.cache = new Cache();
|
|
93
|
+
exports.cache = new Cache(new MemoryStore());
|
|
94
|
+
exports.localStorageCache = new Cache(new LocalStorageStore());
|
|
95
|
+
exports.chromeStorageCache = new Cache(new ChromeStore());
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -8,11 +8,10 @@ const endpoint = (endpoint) => {
|
|
|
8
8
|
};
|
|
9
9
|
exports.endpoint = endpoint;
|
|
10
10
|
function extractDefaultValues(endpoint) {
|
|
11
|
-
var _a;
|
|
12
11
|
const defaultValues = {};
|
|
13
12
|
const paramKeys = Object.keys(endpoint.parameters || {});
|
|
14
13
|
for (const key of paramKeys) {
|
|
15
|
-
const schema =
|
|
14
|
+
const schema = endpoint.parameters?.[key];
|
|
16
15
|
if (schema instanceof zod_1.z.ZodDefault) {
|
|
17
16
|
defaultValues[key] = schema._def.defaultValue();
|
|
18
17
|
}
|
|
@@ -98,21 +97,30 @@ async function handleRetryFetch(url, requestOptions, retries, retryDelay, body,
|
|
|
98
97
|
* @returns The response from the endpoint.
|
|
99
98
|
*/
|
|
100
99
|
async function fetchApi(endpoint, params, requestOptions = { mode: 'cors', credentials: 'include' }) {
|
|
101
|
-
var _a, _b, _c, _d;
|
|
102
100
|
const { method, requestFormat = 'json' } = endpoint;
|
|
103
101
|
const defaultValues = extractDefaultValues(endpoint);
|
|
104
102
|
const extendedParams = { ...defaultValues, ...params };
|
|
105
103
|
const url = prepareRequestUrl(endpoint, extendedParams);
|
|
106
|
-
const body = prepareRequestBody(method, requestFormat, params
|
|
104
|
+
const body = prepareRequestBody(method, requestFormat, params?.body);
|
|
107
105
|
const cacheKey = requestOptions.cacheKey;
|
|
108
|
-
|
|
106
|
+
let cacheToUse;
|
|
107
|
+
if (requestOptions.cacheType === 'local') {
|
|
108
|
+
cacheToUse = cache_1.localStorageCache;
|
|
109
|
+
}
|
|
110
|
+
else if (requestOptions.cacheType === 'chrome') {
|
|
111
|
+
cacheToUse = cache_1.chromeStorageCache;
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
cacheToUse = cache_1.cache;
|
|
115
|
+
}
|
|
116
|
+
const cachedResponse = cacheKey && cacheToUse.get(cacheKey);
|
|
109
117
|
if (cachedResponse) {
|
|
110
118
|
return cachedResponse;
|
|
111
119
|
}
|
|
112
|
-
const retries =
|
|
113
|
-
const retryDelay =
|
|
120
|
+
const retries = requestOptions.retries ?? 0;
|
|
121
|
+
const retryDelay = requestOptions.retryDelay ?? 0;
|
|
114
122
|
const response = await handleRetryFetch(url, requestOptions, retries, retryDelay, body, method);
|
|
115
|
-
const error =
|
|
123
|
+
const error = endpoint.errors?.find(({ status }) => status === response.status);
|
|
116
124
|
if (error) {
|
|
117
125
|
if (requestOptions.throwOnError) {
|
|
118
126
|
throw new Error(error.description);
|
|
@@ -125,11 +133,11 @@ async function fetchApi(endpoint, params, requestOptions = { mode: 'cors', crede
|
|
|
125
133
|
const responseClone = response.clone();
|
|
126
134
|
const cacheTime = requestOptions.cacheTime;
|
|
127
135
|
setTimeout(() => {
|
|
128
|
-
|
|
136
|
+
cacheToUse.delete(cacheKey);
|
|
129
137
|
}, cacheTime);
|
|
130
|
-
|
|
138
|
+
cacheToUse.set(cacheKey, requestFormat === 'json' ? await responseClone.json() : await responseClone.text(), cacheTime);
|
|
131
139
|
}
|
|
132
|
-
if (requestFormat === 'json' && !
|
|
140
|
+
if (requestFormat === 'json' && !response.headers.get('content-type')?.includes('application/json')) {
|
|
133
141
|
throw new Error('Invalid response data');
|
|
134
142
|
}
|
|
135
143
|
return requestFormat === 'json' ? await response.json() : await response.text();
|
package/package.json
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "rozod",
|
|
3
|
-
"version": "3.
|
|
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",
|
|
14
|
-
"version": "npm run format && git add -A src",
|
|
15
|
-
"generate": "node ./zodios-endpoints.js"
|
|
16
|
-
},
|
|
17
|
-
"author": "alexop1000",
|
|
18
|
-
"license": "ISC",
|
|
19
|
-
"dependencies": {
|
|
20
|
-
"@alexop/openapi-zod-client": "^1.10.2",
|
|
21
|
-
"@babel/generator": "^7.22.9",
|
|
22
|
-
"@babel/parser": "^7.22.7",
|
|
23
|
-
"@babel/traverse": "^7.22.8",
|
|
24
|
-
"p-limit": "^3.0.0",
|
|
25
|
-
"zod": "^3.21.4",
|
|
26
|
-
"zod-to-ts": "^1.1.4"
|
|
27
|
-
},
|
|
28
|
-
"repository": {
|
|
29
|
-
"url": "https://github.com/alexop1000/RoZod"
|
|
30
|
-
},
|
|
31
|
-
"devDependencies": {
|
|
32
|
-
"@apidevtools/swagger-parser": "^10.1.0",
|
|
33
|
-
"@thepotato97/openapi-zod-client": "^1.6.4",
|
|
34
|
-
"@types/jest": "^29.5.1",
|
|
35
|
-
"@zodios/plugins": "^10.6.0",
|
|
36
|
-
"jest": "^29.5.0",
|
|
37
|
-
"prettier": "^2.8.8",
|
|
38
|
-
"swagger2openapi": "^7.0.8",
|
|
39
|
-
"ts-jest": "^29.1.0",
|
|
40
|
-
"tslint": "^6.1.3",
|
|
41
|
-
"tslint-config-prettier": "^1.18.0",
|
|
42
|
-
"typedoc": "^0.24.6",
|
|
43
|
-
"typescript": "^5.0.4"
|
|
44
|
-
},
|
|
45
|
-
"type": "module",
|
|
46
|
-
"keywords": [],
|
|
47
|
-
"files": [
|
|
48
|
-
"lib/**/*"
|
|
49
|
-
]
|
|
50
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "rozod",
|
|
3
|
+
"version": "3.1.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 && tsc --project tsconfig.declarations.json",
|
|
10
|
+
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
|
|
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",
|
|
18
|
+
"license": "ISC",
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@alexop/openapi-zod-client": "^1.10.2",
|
|
21
|
+
"@babel/generator": "^7.22.9",
|
|
22
|
+
"@babel/parser": "^7.22.7",
|
|
23
|
+
"@babel/traverse": "^7.22.8",
|
|
24
|
+
"p-limit": "^3.0.0",
|
|
25
|
+
"zod": "^3.21.4",
|
|
26
|
+
"zod-to-ts": "^1.1.4"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"url": "https://github.com/alexop1000/RoZod"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@apidevtools/swagger-parser": "^10.1.0",
|
|
33
|
+
"@thepotato97/openapi-zod-client": "^1.6.4",
|
|
34
|
+
"@types/jest": "^29.5.1",
|
|
35
|
+
"@zodios/plugins": "^10.6.0",
|
|
36
|
+
"jest": "^29.5.0",
|
|
37
|
+
"prettier": "^2.8.8",
|
|
38
|
+
"swagger2openapi": "^7.0.8",
|
|
39
|
+
"ts-jest": "^29.1.0",
|
|
40
|
+
"tslint": "^6.1.3",
|
|
41
|
+
"tslint-config-prettier": "^1.18.0",
|
|
42
|
+
"typedoc": "^0.24.6",
|
|
43
|
+
"typescript": "^5.0.4"
|
|
44
|
+
},
|
|
45
|
+
"type": "module",
|
|
46
|
+
"keywords": [],
|
|
47
|
+
"files": [
|
|
48
|
+
"lib/**/*"
|
|
49
|
+
]
|
|
50
|
+
}
|