rozod 2.1.1 → 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.
Files changed (66) hide show
  1. package/lib/cache.d.ts +19 -6
  2. package/lib/cache.js +77 -14
  3. package/lib/endpoints/accountinformationv1.js +135 -135
  4. package/lib/endpoints/accountsettingsv1.js +162 -156
  5. package/lib/endpoints/assetdeliveryv1.js +34 -27
  6. package/lib/endpoints/assetdeliveryv2.js +39 -30
  7. package/lib/endpoints/authv1.js +400 -274
  8. package/lib/endpoints/authv2.js +269 -219
  9. package/lib/endpoints/authv3.js +15 -8
  10. package/lib/endpoints/avatarv1.js +168 -145
  11. package/lib/endpoints/avatarv2.js +87 -74
  12. package/lib/endpoints/avatarv3.js +57 -46
  13. package/lib/endpoints/badgesv1.js +78 -64
  14. package/lib/endpoints/catalogv1.js +145 -112
  15. package/lib/endpoints/chatv2.js +203 -196
  16. package/lib/endpoints/developv1.js +278 -525
  17. package/lib/endpoints/developv2.js +55 -37
  18. package/lib/endpoints/economyv1.js +6 -7
  19. package/lib/endpoints/friendsv1.js +161 -136
  20. package/lib/endpoints/gamejoinv1.js +88 -80
  21. package/lib/endpoints/gamesv1.js +253 -205
  22. package/lib/endpoints/gamesv2.js +42 -24
  23. package/lib/endpoints/groupsv1.js +466 -392
  24. package/lib/endpoints/groupsv2.js +62 -47
  25. package/lib/endpoints/inventoryv1.js +60 -47
  26. package/lib/endpoints/inventoryv2.js +46 -29
  27. package/lib/endpoints/itemconfigurationv1.js +563 -0
  28. package/lib/endpoints/presencev1.js +40 -35
  29. package/lib/endpoints/privatemessagesv1.js +87 -74
  30. package/lib/endpoints/thumbnailsv1.js +80 -62
  31. package/lib/endpoints/tradesv1.js +73 -63
  32. package/lib/endpoints/translationsv1.js +11 -13
  33. package/lib/endpoints/usersv1.js +304 -87
  34. package/lib/index.d.ts +52 -22
  35. package/lib/index.js +26 -18
  36. package/package.json +50 -45
  37. package/lib/endpoints/accountinformationv1.d.ts +0 -666
  38. package/lib/endpoints/accountsettingsv1.d.ts +0 -690
  39. package/lib/endpoints/assetdeliveryv1.d.ts +0 -1176
  40. package/lib/endpoints/assetdeliveryv2.d.ts +0 -1357
  41. package/lib/endpoints/authv1.d.ts +0 -1601
  42. package/lib/endpoints/authv2.d.ts +0 -1462
  43. package/lib/endpoints/authv3.d.ts +0 -46
  44. package/lib/endpoints/avatarv1.d.ts +0 -2021
  45. package/lib/endpoints/avatarv2.d.ts +0 -1132
  46. package/lib/endpoints/avatarv3.d.ts +0 -694
  47. package/lib/endpoints/badgesv1.d.ts +0 -767
  48. package/lib/endpoints/catalogv1.d.ts +0 -1977
  49. package/lib/endpoints/chatv2.d.ts +0 -2379
  50. package/lib/endpoints/developv1.d.ts +0 -2693
  51. package/lib/endpoints/developv2.d.ts +0 -692
  52. package/lib/endpoints/economyv1.d.ts +0 -23
  53. package/lib/endpoints/friendsv1.d.ts +0 -1349
  54. package/lib/endpoints/gamejoinv1.d.ts +0 -2321
  55. package/lib/endpoints/gamesv1.d.ts +0 -3220
  56. package/lib/endpoints/gamesv2.d.ts +0 -707
  57. package/lib/endpoints/groupsv1.d.ts +0 -6368
  58. package/lib/endpoints/groupsv2.d.ts +0 -583
  59. package/lib/endpoints/inventoryv1.d.ts +0 -589
  60. package/lib/endpoints/inventoryv2.d.ts +0 -341
  61. package/lib/endpoints/presencev1.d.ts +0 -155
  62. package/lib/endpoints/privatemessagesv1.d.ts +0 -702
  63. package/lib/endpoints/thumbnailsv1.d.ts +0 -1328
  64. package/lib/endpoints/tradesv1.d.ts +0 -566
  65. package/lib/endpoints/translationsv1.d.ts +0 -129
  66. package/lib/endpoints/usersv1.d.ts +0 -510
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 cache;
3
- get(key: string): T | null;
4
- set(key: string, value: T, ttl?: number): void;
5
- delete(key: string): void;
6
- clear(): void;
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<any>;
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
- constructor() {
6
- this.cache = {};
65
+ store;
66
+ constructor(store) {
67
+ this.store = store;
7
68
  }
8
- get(key) {
9
- const entry = this.cache[key];
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
- delete this.cache[key];
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.cache[key] = {
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
- delete this.cache[key];
86
+ async delete(key) {
87
+ await this.store.delete(key);
27
88
  }
28
- clear() {
29
- this.cache = {};
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());