@dchighs/dc-config 0.0.10 → 0.1.1
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/README.md +52 -28
- package/dist/dc-config.d.ts +21 -0
- package/dist/dc-config.js +45 -0
- package/dist/dtos/game-config.d.ts +43 -42
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,13 +10,12 @@ Installation is straightforward—simply use your preferred package manager. Her
|
|
|
10
10
|
|
|
11
11
|
```cmd
|
|
12
12
|
npm i @dchighs/dc-config
|
|
13
|
-
|
|
14
13
|
```
|
|
15
14
|
|
|
16
15
|
## 🚀 Usage
|
|
17
16
|
|
|
18
17
|
<a href="https://www.buymeacoffee.com/marcuth">
|
|
19
|
-
|
|
18
|
+
<img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" width="200">
|
|
20
19
|
</a>
|
|
21
20
|
|
|
22
21
|
### Fetching configuration for specific parameters
|
|
@@ -27,24 +26,23 @@ To create a `Config` instance, you need to provide credentials or use the static
|
|
|
27
26
|
import { Config, ConfigLanguage, ConfigPlatform, ConfigFilter } from "@dchighs/dc-config"
|
|
28
27
|
|
|
29
28
|
;(async () => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
29
|
+
const userId = process.env.USER_ID
|
|
30
|
+
const authToken = process.env.AUTH_TOKEN
|
|
31
|
+
const url = process.env.URL
|
|
32
|
+
|
|
33
|
+
const config = await Config.create({
|
|
34
|
+
url: url,
|
|
35
|
+
userId: userId,
|
|
36
|
+
authToken: authToken,
|
|
37
|
+
language: ConfigLanguage.Turkish, // optional - "en" is default
|
|
38
|
+
platform: ConfigPlatform.Android, // optional - "ios" is default
|
|
39
|
+
filter: [ConfigFilter.Items] // optional - undefined is default
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
const data = config.data
|
|
43
|
+
|
|
44
|
+
console.log(data)
|
|
46
45
|
})();
|
|
47
|
-
|
|
48
46
|
```
|
|
49
47
|
|
|
50
48
|
---
|
|
@@ -58,17 +56,43 @@ import { Config, ConfigLanguage, ConfigPlatform, GameConfigDto } from "@dchighs/
|
|
|
58
56
|
import fs from "node:fs"
|
|
59
57
|
|
|
60
58
|
;(async () => {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
59
|
+
const filePath = "config.json"
|
|
60
|
+
const contentString = await fs.promises.readFile(filePath, { encoding: "utf-8" })
|
|
61
|
+
const data = JSON.parse(contentString) as GameConfigDto
|
|
62
|
+
|
|
63
|
+
const config = new Config({
|
|
64
|
+
language: ConfigLanguage.Turkish,
|
|
65
|
+
platform: ConfigPlatform.Android,
|
|
66
|
+
data: data
|
|
67
|
+
})
|
|
70
68
|
})();
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
### Fetching a raw configuration from a URL
|
|
71
74
|
|
|
75
|
+
If you have a full raw JSON file and want to fetch it and filter specific keys:
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
import { Config, ConfigFilter, ConfigLanguage } from "@dchighs/dc-config"
|
|
79
|
+
|
|
80
|
+
;(async () => {
|
|
81
|
+
const rawUrl = "https://example.com/config.json"
|
|
82
|
+
|
|
83
|
+
// Using createRaw to get a Config instance
|
|
84
|
+
const config = await Config.createRaw({
|
|
85
|
+
url: rawUrl,
|
|
86
|
+
filter: [ConfigFilter.Items],
|
|
87
|
+
language: ConfigLanguage.English
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
// Or using fetchRaw to get just the data (GameConfigDto)
|
|
91
|
+
const data = await Config.fetchRaw({
|
|
92
|
+
url: rawUrl,
|
|
93
|
+
filter: [ConfigFilter.Items]
|
|
94
|
+
})
|
|
95
|
+
})();
|
|
72
96
|
```
|
|
73
97
|
|
|
74
98
|
---
|
package/dist/dc-config.d.ts
CHANGED
|
@@ -13,13 +13,34 @@ export type CreateOptions = Omit<Omit<ConfigOptions, "platform" | "language"> &
|
|
|
13
13
|
language?: ConfigLanguage | `${ConfigLanguage}`;
|
|
14
14
|
platform?: ConfigPlatform | `${ConfigPlatform}`;
|
|
15
15
|
}, "data">;
|
|
16
|
+
export type CreateRawOptions = {
|
|
17
|
+
url: string;
|
|
18
|
+
filter?: Array<ConfigFilter | `${ConfigFilter}`>;
|
|
19
|
+
language?: ConfigLanguage | `${ConfigLanguage}`;
|
|
20
|
+
platform?: ConfigPlatform | `${ConfigPlatform}`;
|
|
21
|
+
};
|
|
16
22
|
export type FetchOptions = CreateOptions;
|
|
23
|
+
export type FetchRawOptions = Pick<CreateRawOptions, "url" | "filter">;
|
|
17
24
|
export declare class Config {
|
|
18
25
|
readonly platform: ConfigPlatform;
|
|
19
26
|
readonly langauge: ConfigLanguage;
|
|
20
27
|
readonly filter?: ConfigFilter[];
|
|
21
28
|
readonly data: GameConfigDto;
|
|
22
29
|
constructor({ data, language, platform, filter }: ConfigOptions);
|
|
30
|
+
/**
|
|
31
|
+
* Creates a new Config instance by fetching data from the API with authentication.
|
|
32
|
+
*/
|
|
23
33
|
static create({ authToken, userId, filter, language, platform, url }: CreateOptions): Promise<Config>;
|
|
34
|
+
/**
|
|
35
|
+
* Creates a new Config instance by fetching a raw JSON file from a URL.
|
|
36
|
+
*/
|
|
37
|
+
static createRaw({ url, filter, language, platform }: CreateRawOptions): Promise<Config>;
|
|
38
|
+
/**
|
|
39
|
+
* Fetches configuration from the API with authentication.
|
|
40
|
+
*/
|
|
24
41
|
static fetch({ authToken, userId, filter, language, platform, url }: FetchOptions): Promise<GameConfigDto>;
|
|
42
|
+
/**
|
|
43
|
+
* Fetches a raw config file from a URL and filters its contents.
|
|
44
|
+
*/
|
|
45
|
+
static fetchRaw({ url, filter }: FetchRawOptions): Promise<GameConfigDto>;
|
|
25
46
|
}
|
package/dist/dc-config.js
CHANGED
|
@@ -13,6 +13,9 @@ class Config {
|
|
|
13
13
|
this.platform = platform;
|
|
14
14
|
this.filter = filter ? filter : undefined;
|
|
15
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Creates a new Config instance by fetching data from the API with authentication.
|
|
18
|
+
*/
|
|
16
19
|
static async create({ authToken, userId, filter, language, platform, url }) {
|
|
17
20
|
const data = await Config.fetch({
|
|
18
21
|
authToken: authToken,
|
|
@@ -29,6 +32,21 @@ class Config {
|
|
|
29
32
|
platform: platform !== null && platform !== void 0 ? platform : enums_1.ConfigPlatform.Default
|
|
30
33
|
});
|
|
31
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Creates a new Config instance by fetching a raw JSON file from a URL.
|
|
37
|
+
*/
|
|
38
|
+
static async createRaw({ url, filter, language, platform }) {
|
|
39
|
+
const data = await Config.fetchRaw({ url, filter });
|
|
40
|
+
return new Config({
|
|
41
|
+
data: data,
|
|
42
|
+
filter: filter,
|
|
43
|
+
language: language !== null && language !== void 0 ? language : enums_1.ConfigLanguage.Default,
|
|
44
|
+
platform: platform !== null && platform !== void 0 ? platform : enums_1.ConfigPlatform.Default
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Fetches configuration from the API with authentication.
|
|
49
|
+
*/
|
|
32
50
|
static async fetch({ authToken, userId, filter, language, platform, url }) {
|
|
33
51
|
const response = await axios_1.default.post(url, null, {
|
|
34
52
|
params: {
|
|
@@ -42,5 +60,32 @@ class Config {
|
|
|
42
60
|
const data = response.data;
|
|
43
61
|
return data;
|
|
44
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Fetches a raw config file from a URL and filters its contents.
|
|
65
|
+
*/
|
|
66
|
+
static async fetchRaw({ url, filter }) {
|
|
67
|
+
const response = await axios_1.default.get(url);
|
|
68
|
+
const fullData = response.data;
|
|
69
|
+
if (!filter || filter.length === 0) {
|
|
70
|
+
return {
|
|
71
|
+
game_data: {
|
|
72
|
+
config: fullData.game_data.config
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
const filteredData = {};
|
|
77
|
+
filter.forEach((key) => {
|
|
78
|
+
var _a, _b;
|
|
79
|
+
const value = (_b = (_a = fullData.game_data) === null || _a === void 0 ? void 0 : _a.config) === null || _b === void 0 ? void 0 : _b[key];
|
|
80
|
+
if (value !== undefined) {
|
|
81
|
+
filteredData[key] = value;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
return {
|
|
85
|
+
game_data: {
|
|
86
|
+
config: filteredData
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
45
90
|
}
|
|
46
91
|
exports.Config = Config;
|
|
@@ -2169,26 +2169,28 @@ export interface MazeIslandReward {
|
|
|
2169
2169
|
export interface News {
|
|
2170
2170
|
"0": The0;
|
|
2171
2171
|
"1": The1;
|
|
2172
|
-
"2":
|
|
2173
|
-
"3":
|
|
2174
|
-
"4":
|
|
2175
|
-
"5":
|
|
2176
|
-
"6":
|
|
2177
|
-
"7":
|
|
2178
|
-
"8":
|
|
2179
|
-
"9":
|
|
2172
|
+
"2": The10;
|
|
2173
|
+
"3": The12;
|
|
2174
|
+
"4": The12;
|
|
2175
|
+
"5": The10;
|
|
2176
|
+
"6": The12;
|
|
2177
|
+
"7": The10;
|
|
2178
|
+
"8": The12;
|
|
2179
|
+
"9": The12;
|
|
2180
2180
|
"10": The10;
|
|
2181
2181
|
"11": The11;
|
|
2182
|
-
"12":
|
|
2183
|
-
"13":
|
|
2184
|
-
"14":
|
|
2182
|
+
"12": The12;
|
|
2183
|
+
"13": The10;
|
|
2184
|
+
"14": The10;
|
|
2185
2185
|
"15": The15;
|
|
2186
|
+
"16": The16;
|
|
2186
2187
|
canvas: Canva[];
|
|
2187
2188
|
}
|
|
2188
2189
|
export interface The0 {
|
|
2189
2190
|
active_platforms: ValueClass;
|
|
2190
2191
|
allow_island_tutorial: number;
|
|
2191
2192
|
assets_name: string;
|
|
2193
|
+
direct_to_shop: number;
|
|
2192
2194
|
end_ts: string;
|
|
2193
2195
|
hud_button: The0_HudButton;
|
|
2194
2196
|
id: number;
|
|
@@ -2201,6 +2203,7 @@ export interface The0 {
|
|
|
2201
2203
|
export interface The0_HudButton {
|
|
2202
2204
|
file: string;
|
|
2203
2205
|
title: string;
|
|
2206
|
+
viral_icon_tier: number;
|
|
2204
2207
|
}
|
|
2205
2208
|
export interface The0_Slide {
|
|
2206
2209
|
content_localized_key: string;
|
|
@@ -2215,6 +2218,23 @@ export interface The0_Slide {
|
|
|
2215
2218
|
times_to_show?: number;
|
|
2216
2219
|
}
|
|
2217
2220
|
export interface The1 {
|
|
2221
|
+
active_platforms: ValueClass;
|
|
2222
|
+
allow_island_tutorial: number;
|
|
2223
|
+
assets_name: string;
|
|
2224
|
+
end_ts: string;
|
|
2225
|
+
hud_button: The1_HudButton;
|
|
2226
|
+
id: number;
|
|
2227
|
+
min_level: number;
|
|
2228
|
+
popup_type: string;
|
|
2229
|
+
show_on_startup: number;
|
|
2230
|
+
slides: The0_Slide[];
|
|
2231
|
+
start_ts: string;
|
|
2232
|
+
}
|
|
2233
|
+
export interface The1_HudButton {
|
|
2234
|
+
file: string;
|
|
2235
|
+
title: string;
|
|
2236
|
+
}
|
|
2237
|
+
export interface The10 {
|
|
2218
2238
|
active_platforms: ValueClass;
|
|
2219
2239
|
allow_island_tutorial: number;
|
|
2220
2240
|
assets_name: string;
|
|
@@ -2228,10 +2248,10 @@ export interface The1 {
|
|
|
2228
2248
|
popup_type: string;
|
|
2229
2249
|
priority: number | null;
|
|
2230
2250
|
show_on_startup: number;
|
|
2231
|
-
slides:
|
|
2251
|
+
slides: The10_Slide[];
|
|
2232
2252
|
start_ts: string;
|
|
2233
2253
|
}
|
|
2234
|
-
export interface
|
|
2254
|
+
export interface The10_Slide {
|
|
2235
2255
|
content_localized_key: string;
|
|
2236
2256
|
custom_title_localized_key: string;
|
|
2237
2257
|
header_localized_key: string;
|
|
@@ -2279,14 +2299,14 @@ export declare enum Style {
|
|
|
2279
2299
|
export declare enum SlideType {
|
|
2280
2300
|
FullImage = "FullImage"
|
|
2281
2301
|
}
|
|
2282
|
-
export interface
|
|
2302
|
+
export interface The11 {
|
|
2283
2303
|
active_platforms: ValueClass;
|
|
2284
2304
|
allow_island_tutorial: number;
|
|
2285
2305
|
assets_name: string;
|
|
2286
2306
|
direct_to_shop: number;
|
|
2287
2307
|
end_ts: string;
|
|
2288
2308
|
filter_category: null;
|
|
2289
|
-
hud_button:
|
|
2309
|
+
hud_button: The0_HudButton;
|
|
2290
2310
|
id: number;
|
|
2291
2311
|
label_text_tid: null;
|
|
2292
2312
|
label_title_tid: null;
|
|
@@ -2295,15 +2315,10 @@ export interface The10 {
|
|
|
2295
2315
|
popup_type: string;
|
|
2296
2316
|
priority: null;
|
|
2297
2317
|
show_on_startup: number;
|
|
2298
|
-
slides:
|
|
2318
|
+
slides: The11_Slide[];
|
|
2299
2319
|
start_ts: string;
|
|
2300
2320
|
}
|
|
2301
|
-
export interface
|
|
2302
|
-
file: string;
|
|
2303
|
-
title: string;
|
|
2304
|
-
viral_icon_tier: number;
|
|
2305
|
-
}
|
|
2306
|
-
export interface The10_Slide {
|
|
2321
|
+
export interface The11_Slide {
|
|
2307
2322
|
content_localized_key: string;
|
|
2308
2323
|
custom_title_localized_key: string;
|
|
2309
2324
|
forceClose?: boolean;
|
|
@@ -2313,7 +2328,7 @@ export interface The10_Slide {
|
|
|
2313
2328
|
times_to_show: number;
|
|
2314
2329
|
type: SlideType;
|
|
2315
2330
|
}
|
|
2316
|
-
export interface
|
|
2331
|
+
export interface The12 {
|
|
2317
2332
|
active_platforms: ValueClass;
|
|
2318
2333
|
allow_island_tutorial: number;
|
|
2319
2334
|
assets_name: string;
|
|
@@ -2324,10 +2339,10 @@ export interface The11 {
|
|
|
2324
2339
|
popup_frequency: string;
|
|
2325
2340
|
popup_type: string;
|
|
2326
2341
|
show_on_startup: number;
|
|
2327
|
-
slides:
|
|
2342
|
+
slides: The11_Slide[];
|
|
2328
2343
|
start_ts: string;
|
|
2329
2344
|
}
|
|
2330
|
-
export interface
|
|
2345
|
+
export interface The15 {
|
|
2331
2346
|
active_platforms: ValueClass;
|
|
2332
2347
|
allow_island_tutorial: number;
|
|
2333
2348
|
assets_name: string;
|
|
@@ -2342,7 +2357,7 @@ export interface The14 {
|
|
|
2342
2357
|
slides: The0_Slide[];
|
|
2343
2358
|
start_ts: string;
|
|
2344
2359
|
}
|
|
2345
|
-
export interface
|
|
2360
|
+
export interface The16 {
|
|
2346
2361
|
active_platforms: ValueClass;
|
|
2347
2362
|
allow_island_tutorial: number;
|
|
2348
2363
|
assets_name: string;
|
|
@@ -2356,21 +2371,7 @@ export interface The15 {
|
|
|
2356
2371
|
popup_type: string;
|
|
2357
2372
|
priority: null;
|
|
2358
2373
|
show_on_startup: number;
|
|
2359
|
-
slides:
|
|
2360
|
-
start_ts: string;
|
|
2361
|
-
}
|
|
2362
|
-
export interface The3 {
|
|
2363
|
-
active_platforms: ValueClass;
|
|
2364
|
-
allow_island_tutorial: number;
|
|
2365
|
-
assets_name: string;
|
|
2366
|
-
direct_to_shop: number;
|
|
2367
|
-
end_ts: string;
|
|
2368
|
-
id: number;
|
|
2369
|
-
min_level: number;
|
|
2370
|
-
popup_frequency: string;
|
|
2371
|
-
popup_type: string;
|
|
2372
|
-
show_on_startup: number;
|
|
2373
|
-
slides: The10_Slide[];
|
|
2374
|
+
slides: The11_Slide[];
|
|
2374
2375
|
start_ts: string;
|
|
2375
2376
|
}
|
|
2376
2377
|
export interface Canva {
|
|
@@ -3323,8 +3324,8 @@ export interface MultiplierTime {
|
|
|
3323
3324
|
multiplier_time: number;
|
|
3324
3325
|
}
|
|
3325
3326
|
export interface TreeOfLifePowerupRaritySeed {
|
|
3326
|
-
rarity: Rarity;
|
|
3327
3327
|
max_rarity_seeds_per_grade: number[];
|
|
3328
|
+
rarity: Rarity;
|
|
3328
3329
|
}
|
|
3329
3330
|
export interface Visual {
|
|
3330
3331
|
id: number;
|