@dchighs/dc-config 0.0.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/LICENSE +21 -0
- package/README.md +87 -0
- package/dist/dc-config.d.ts +25 -0
- package/dist/dc-config.js +46 -0
- package/dist/dtos/game-config.d.ts +3489 -0
- package/dist/dtos/game-config.js +2 -0
- package/dist/dtos/index.d.ts +1 -0
- package/dist/dtos/index.js +17 -0
- package/dist/enums/config-filter.d.ts +2 -0
- package/dist/enums/config-filter.js +5 -0
- package/dist/enums/config-language.d.ts +2 -0
- package/dist/enums/config-language.js +5 -0
- package/dist/enums/config-platform.d.ts +2 -0
- package/dist/enums/config-platform.js +5 -0
- package/dist/enums/index.d.ts +3 -0
- package/dist/enums/index.js +19 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +19 -0
- package/package.json +34 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Marcuth
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# @dchighs/dc-config
|
|
2
|
+
|
|
3
|
+
**@dchighs/dc-config** is a package for accessing game configuration data from [Dragon City](https://dragoncitygame.com/) (this is not an official SocialPoint library; it is fan-made).
|
|
4
|
+
|
|
5
|
+
## 📦 Installation
|
|
6
|
+
|
|
7
|
+
Installation is straightforward—simply use your preferred package manager. Here is an example using NPM:
|
|
8
|
+
|
|
9
|
+
```cmd
|
|
10
|
+
npm i @dchighs/dc-config
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## 🚀 Usage
|
|
15
|
+
|
|
16
|
+
<a href="https://www.buymeacoffee.com/marcuth">
|
|
17
|
+
<img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" width="200">
|
|
18
|
+
</a>
|
|
19
|
+
|
|
20
|
+
### Fetching configuration for specific parameters
|
|
21
|
+
|
|
22
|
+
To create a `Config` instance, you need to provide credentials or use the static `.create()` method by providing the necessary parameters:
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { Config, ConfigLanguage, ConfigPlatform, ConfigFilter } from "@dchighs/dc-config"
|
|
26
|
+
|
|
27
|
+
;(async () => {
|
|
28
|
+
const userId = process.env.USER_ID
|
|
29
|
+
const authToken = process.env.AUTH_TOKEN
|
|
30
|
+
const url = process.env.URL
|
|
31
|
+
|
|
32
|
+
const config = await Config.create({
|
|
33
|
+
url: url,
|
|
34
|
+
userId: userId,
|
|
35
|
+
authToken: authToken,
|
|
36
|
+
language: ConfigLanguage.Turkish, // optional - "en" is default
|
|
37
|
+
platform: ConfigPlatform.Android, // optional - "ios" is default
|
|
38
|
+
filter: [ConfigFilter.Items] // optional - undefined is default
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
const data = config.data
|
|
42
|
+
|
|
43
|
+
console.log(data)
|
|
44
|
+
})();
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
### Loading a saved configuration from a file
|
|
51
|
+
|
|
52
|
+
If you have a saved JSON file containing configuration data and want to load it to perform operations using the class, you can do it as follows:
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import { Config, ConfigLanguage, ConfigPlatform, GameConfigDto } from "@dchighs/dc-config"
|
|
56
|
+
import fs from "node:fs"
|
|
57
|
+
|
|
58
|
+
;(async () => {
|
|
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
|
+
})
|
|
68
|
+
})();
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## 🤝 Contributing
|
|
75
|
+
|
|
76
|
+
* Want to contribute? Follow these steps:
|
|
77
|
+
* Fork the repository.
|
|
78
|
+
* Create a new branch (`git checkout -b feature-new`).
|
|
79
|
+
* Commit your changes (`git commit -m 'Add new feature'`).
|
|
80
|
+
* Push to the branch (`git push origin feature-new`).
|
|
81
|
+
* Open a Pull Request.
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## 📝 License
|
|
86
|
+
|
|
87
|
+
This project is licensed under the MIT License.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ConfigFilter, ConfigLanguage, ConfigPlatform } from "./enums";
|
|
2
|
+
import { GameConfigDto } from "./dtos/game-config";
|
|
3
|
+
export type ConfigOptions = {
|
|
4
|
+
language: ConfigLanguage | `${ConfigLanguage}`;
|
|
5
|
+
filter?: Array<ConfigFilter | `${ConfigFilter}`>;
|
|
6
|
+
platform: ConfigPlatform | `${ConfigPlatform}`;
|
|
7
|
+
data: GameConfigDto;
|
|
8
|
+
};
|
|
9
|
+
export type CreateOptions = Omit<Omit<ConfigOptions, "platform" | "language"> & {
|
|
10
|
+
authToken: string;
|
|
11
|
+
userId: string;
|
|
12
|
+
url: string;
|
|
13
|
+
language?: ConfigLanguage | `${ConfigLanguage}`;
|
|
14
|
+
platform?: ConfigPlatform | `${ConfigPlatform}`;
|
|
15
|
+
}, "data">;
|
|
16
|
+
export type FetchOptions = CreateOptions;
|
|
17
|
+
export declare class Config {
|
|
18
|
+
readonly platform: ConfigPlatform;
|
|
19
|
+
readonly langauge: ConfigLanguage;
|
|
20
|
+
readonly filter?: ConfigFilter[];
|
|
21
|
+
readonly data: GameConfigDto;
|
|
22
|
+
constructor({ data, language, platform, filter }: ConfigOptions);
|
|
23
|
+
static create({ authToken, userId, filter, language, platform, url }: CreateOptions): Promise<Config>;
|
|
24
|
+
static fetch({ authToken, userId, filter, language, platform, url }: FetchOptions): Promise<GameConfigDto>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Config = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const enums_1 = require("./enums");
|
|
9
|
+
class Config {
|
|
10
|
+
constructor({ data, language, platform, filter }) {
|
|
11
|
+
this.data = data;
|
|
12
|
+
this.langauge = language;
|
|
13
|
+
this.platform = platform;
|
|
14
|
+
this.filter = filter ? filter : undefined;
|
|
15
|
+
}
|
|
16
|
+
static async create({ authToken, userId, filter, language, platform, url }) {
|
|
17
|
+
const data = await Config.fetch({
|
|
18
|
+
authToken: authToken,
|
|
19
|
+
userId: userId,
|
|
20
|
+
filter: filter,
|
|
21
|
+
language: language,
|
|
22
|
+
platform: platform,
|
|
23
|
+
url: url
|
|
24
|
+
});
|
|
25
|
+
return new Config({
|
|
26
|
+
data: data,
|
|
27
|
+
filter: filter,
|
|
28
|
+
language: language !== null && language !== void 0 ? language : enums_1.ConfigLanguage.Default,
|
|
29
|
+
platform: platform !== null && platform !== void 0 ? platform : enums_1.ConfigPlatform.Default
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
static async fetch({ authToken, userId, filter, language, platform, url }) {
|
|
33
|
+
const response = await axios_1.default.post(url, null, {
|
|
34
|
+
params: {
|
|
35
|
+
authToken: authToken,
|
|
36
|
+
userId: userId,
|
|
37
|
+
filter: filter === null || filter === void 0 ? void 0 : filter.join(","),
|
|
38
|
+
platform: platform,
|
|
39
|
+
language: language
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
const data = response.data;
|
|
43
|
+
return data;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.Config = Config;
|