dnf-api 0.5.22 → 0.6.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 -21
- package/README.md +313 -313
- package/bun.lockb +0 -0
- package/dist/index.js +22 -35
- package/jest.config.js +12 -12
- package/package.json +37 -41
- package/src/api/auction.ts +67 -61
- package/src/api/characters.equip.ts +81 -53
- package/src/api/characters.skill.ts +52 -52
- package/src/api/characters.ts +91 -60
- package/src/api/index.ts +9 -9
- package/src/api/items.ts +27 -9
- package/src/api/server.ts +9 -9
- package/src/api/setitems.ts +34 -29
- package/src/index.ts +29 -18
- package/src/model/character.ts +51 -3
- package/src/model/index.ts +86 -62
- package/src/model/item.ts +74 -22
- package/src/model/setitem.ts +31 -31
- package/src/util/config.ts +20 -19
- package/src/util/index.ts +6 -6
- package/src/util/params.ts +14 -5
- package/src/util/query.ts +103 -109
- package/src/util/static.ts +51 -45
- package/dist/api/auction.d.ts +0 -24
- package/dist/api/auction.js +0 -58
- package/dist/api/characters.d.ts +0 -32
- package/dist/api/characters.equip.d.ts +0 -29
- package/dist/api/characters.equip.js +0 -51
- package/dist/api/characters.js +0 -58
- package/dist/api/characters.skill.d.ts +0 -29
- package/dist/api/characters.skill.js +0 -51
- package/dist/api/index.d.ts +0 -8
- package/dist/api/index.js +0 -23
- package/dist/api/items.d.ts +0 -15
- package/dist/api/items.js +0 -40
- package/dist/api/server.d.ts +0 -2
- package/dist/api/server.js +0 -9
- package/dist/api/setitems.d.ts +0 -15
- package/dist/api/setitems.js +0 -28
- package/dist/index.d.ts +0 -14
- package/dist/model/character.d.ts +0 -41
- package/dist/model/character.js +0 -2
- package/dist/model/index.d.ts +0 -56
- package/dist/model/index.js +0 -15
- package/dist/model/item.d.ts +0 -45
- package/dist/model/item.js +0 -2
- package/dist/model/setitem.d.ts +0 -24
- package/dist/model/setitem.js +0 -2
- package/dist/util/config.d.ts +0 -11
- package/dist/util/config.js +0 -12
- package/dist/util/index.d.ts +0 -5
- package/dist/util/index.js +0 -20
- package/dist/util/params.d.ts +0 -67
- package/dist/util/params.js +0 -2
- package/dist/util/query.d.ts +0 -14
- package/dist/util/query.js +0 -132
- package/dist/util/static.d.ts +0 -44
- package/dist/util/static.js +0 -53
- package/src/index.tmp.js +0 -48
package/src/model/index.ts
CHANGED
|
@@ -1,62 +1,86 @@
|
|
|
1
|
-
import * as Char from "./character";
|
|
2
|
-
import * as Item from "./item";
|
|
3
|
-
import * as SetItem from "./setitem";
|
|
4
|
-
|
|
5
|
-
export { Char, Item, SetItem };
|
|
6
|
-
|
|
7
|
-
export type DnfErrorResponse = {
|
|
8
|
-
url: string;
|
|
9
|
-
status: number;
|
|
10
|
-
statusText: string;
|
|
11
|
-
code: string;
|
|
12
|
-
message: string;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
1
|
+
import * as Char from "./character";
|
|
2
|
+
import * as Item from "./item";
|
|
3
|
+
import * as SetItem from "./setitem";
|
|
4
|
+
|
|
5
|
+
export { Char, Item, SetItem };
|
|
6
|
+
|
|
7
|
+
export type DnfErrorResponse = {
|
|
8
|
+
url: string;
|
|
9
|
+
status: number;
|
|
10
|
+
statusText: string;
|
|
11
|
+
code: string;
|
|
12
|
+
message: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type DnfSuccess<T> = {
|
|
16
|
+
data: T;
|
|
17
|
+
error?: never;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type DnfError = {
|
|
21
|
+
data?: never;
|
|
22
|
+
error: DnfErrorResponse;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export type DnfResponse<T> = DnfSuccess<T> | DnfError;
|
|
26
|
+
|
|
27
|
+
export type Auction = {
|
|
28
|
+
auctionNo: number;
|
|
29
|
+
regDate: Date;
|
|
30
|
+
expireDate: Date;
|
|
31
|
+
itemId: string;
|
|
32
|
+
itemName: string;
|
|
33
|
+
itemAvailableLevel: number;
|
|
34
|
+
itemRarity: string;
|
|
35
|
+
itemTypeId: string;
|
|
36
|
+
itemType: string;
|
|
37
|
+
itemTypeDetailId: string;
|
|
38
|
+
itemTypeDetail: string;
|
|
39
|
+
refine: number;
|
|
40
|
+
reinforce: number;
|
|
41
|
+
amplificationName: string;
|
|
42
|
+
fame: number;
|
|
43
|
+
count: number;
|
|
44
|
+
regCount: number;
|
|
45
|
+
price: number;
|
|
46
|
+
currentPrice: number;
|
|
47
|
+
unitPrice: number;
|
|
48
|
+
averagePrice: number;
|
|
49
|
+
upgrade?: number;
|
|
50
|
+
upgradeMax?: number;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export type AuctionSolid = {
|
|
54
|
+
soldDate: string;
|
|
55
|
+
itemId: string;
|
|
56
|
+
itemName: string;
|
|
57
|
+
itemAvailableLevel: number;
|
|
58
|
+
itemRarity: string;
|
|
59
|
+
itemTypeId: string;
|
|
60
|
+
itemType: string;
|
|
61
|
+
itemTypeDetailId: string;
|
|
62
|
+
itemTypeDetail: string;
|
|
63
|
+
refine: number;
|
|
64
|
+
reinforce: number;
|
|
65
|
+
amplificationName: string | null;
|
|
66
|
+
fame: number;
|
|
67
|
+
count: number;
|
|
68
|
+
price: number;
|
|
69
|
+
unitPrice: number;
|
|
70
|
+
upgrade?: number;
|
|
71
|
+
upgradeMax?: number;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export type Rows<T> = {
|
|
75
|
+
rows: T[];
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export type Server = {
|
|
79
|
+
serverId: string;
|
|
80
|
+
serverName: string;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export type NameValue = {
|
|
84
|
+
name: string;
|
|
85
|
+
value: string | number;
|
|
86
|
+
};
|
package/src/model/item.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import * as Static from "../util/static";
|
|
1
|
+
import type * as Static from "../util/static";
|
|
2
|
+
import type { NameValue } from "./";
|
|
3
|
+
|
|
4
|
+
export enum ItemDetailKind {
|
|
5
|
+
Material = "material",
|
|
6
|
+
Equip = "equip",
|
|
7
|
+
}
|
|
2
8
|
|
|
3
9
|
export type Item = {
|
|
4
10
|
itemId: string;
|
|
@@ -9,44 +15,90 @@ export type Item = {
|
|
|
9
15
|
itemAvailableLevel: number;
|
|
10
16
|
};
|
|
11
17
|
|
|
12
|
-
export type Detail =
|
|
18
|
+
export type Detail = MaterialDetail | EquipDetail;
|
|
19
|
+
|
|
20
|
+
export type MaterialDetail = {
|
|
21
|
+
kind: ItemDetailKind.Material;
|
|
13
22
|
itemId: string;
|
|
14
23
|
itemName: string;
|
|
15
|
-
itemRarity:
|
|
24
|
+
itemRarity: string;
|
|
25
|
+
itemTypeId: string;
|
|
16
26
|
itemType: string;
|
|
27
|
+
itemTypeDetailId: string;
|
|
17
28
|
itemTypeDetail: string;
|
|
18
29
|
itemAvailableLevel: number;
|
|
19
|
-
itemObtainInfo: string;
|
|
20
30
|
itemExplain: string;
|
|
21
31
|
itemExplainDetail: string;
|
|
22
32
|
itemFlavorText: string;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
33
|
+
fame: number;
|
|
34
|
+
setItemId: string | null;
|
|
35
|
+
setItemName: string | null;
|
|
36
|
+
obtainInfo: ObtainInfo;
|
|
27
37
|
};
|
|
28
38
|
|
|
29
|
-
export type
|
|
30
|
-
|
|
31
|
-
|
|
39
|
+
export type EquipDetail = {
|
|
40
|
+
kind: ItemDetailKind.Equip;
|
|
41
|
+
itemId: string;
|
|
42
|
+
itemName: string;
|
|
43
|
+
itemRarity: string;
|
|
44
|
+
itemTypeId: string;
|
|
45
|
+
itemType: string;
|
|
46
|
+
itemTypeDetailId: string;
|
|
47
|
+
itemTypeDetail: string;
|
|
48
|
+
itemAvailableLevel: number;
|
|
49
|
+
itemExplain: string;
|
|
50
|
+
itemExplainDetail: string;
|
|
51
|
+
itemFlavorText: string;
|
|
52
|
+
fame: number;
|
|
53
|
+
setItemId: string | null;
|
|
54
|
+
setItemName: string | null;
|
|
55
|
+
itemStatus: NameValue[];
|
|
56
|
+
tune: Tune;
|
|
57
|
+
itemBuff: ItemBuff;
|
|
58
|
+
hashtag: string[];
|
|
59
|
+
obtainInfo: ObtainInfoDetail;
|
|
32
60
|
};
|
|
33
61
|
|
|
34
|
-
export type
|
|
35
|
-
|
|
36
|
-
|
|
62
|
+
export type Tune = {
|
|
63
|
+
level: number;
|
|
64
|
+
setPoint: number;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export type ItemBuff = {
|
|
68
|
+
explain: string;
|
|
69
|
+
explainDetail: string;
|
|
70
|
+
reinforceSkill: any[];
|
|
71
|
+
status: any | null;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export type ObtainInfo = {
|
|
75
|
+
dungeon: string | null;
|
|
76
|
+
shop: ShopInfo[];
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export type ObtainInfoDetail = {
|
|
80
|
+
dungeon: Dungeon[];
|
|
81
|
+
shop: ShopDetail[];
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export type Dungeon = {
|
|
85
|
+
type: string;
|
|
86
|
+
rows: DungeonRow[];
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export type DungeonRow = {
|
|
90
|
+
name: string;
|
|
37
91
|
};
|
|
38
92
|
|
|
39
|
-
export type
|
|
40
|
-
|
|
41
|
-
slotName: string;
|
|
93
|
+
export type ShopInfo = {
|
|
94
|
+
type: string;
|
|
42
95
|
};
|
|
43
96
|
|
|
44
|
-
export type
|
|
45
|
-
|
|
46
|
-
upgrade: number;
|
|
97
|
+
export type ShopDetail = {
|
|
98
|
+
rows: ShopRow[];
|
|
47
99
|
};
|
|
48
100
|
|
|
49
|
-
export type
|
|
101
|
+
export type ShopRow = {
|
|
50
102
|
name: string;
|
|
51
|
-
|
|
103
|
+
details: string[];
|
|
52
104
|
};
|
package/src/model/setitem.ts
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
export type SetItem = {
|
|
2
|
-
setItemId: string;
|
|
3
|
-
setItemName: string;
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
export type Detail = {
|
|
7
|
-
setItemId: string;
|
|
8
|
-
setItemName: string;
|
|
9
|
-
setItems: [
|
|
10
|
-
{
|
|
11
|
-
slotId: string;
|
|
12
|
-
slotName: string;
|
|
13
|
-
itemId: string;
|
|
14
|
-
itemName: string;
|
|
15
|
-
itemRarity: string;
|
|
16
|
-
}
|
|
17
|
-
];
|
|
18
|
-
setItemOption: [
|
|
19
|
-
{
|
|
20
|
-
optionNo: number;
|
|
21
|
-
explain: string;
|
|
22
|
-
detailExplain: string;
|
|
23
|
-
status: [
|
|
24
|
-
{
|
|
25
|
-
name: string;
|
|
26
|
-
value: number;
|
|
27
|
-
}
|
|
28
|
-
];
|
|
29
|
-
}
|
|
30
|
-
];
|
|
31
|
-
};
|
|
1
|
+
export type SetItem = {
|
|
2
|
+
setItemId: string;
|
|
3
|
+
setItemName: string;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
export type Detail = {
|
|
7
|
+
setItemId: string;
|
|
8
|
+
setItemName: string;
|
|
9
|
+
setItems: [
|
|
10
|
+
{
|
|
11
|
+
slotId: string;
|
|
12
|
+
slotName: string;
|
|
13
|
+
itemId: string;
|
|
14
|
+
itemName: string;
|
|
15
|
+
itemRarity: string;
|
|
16
|
+
}
|
|
17
|
+
];
|
|
18
|
+
setItemOption: [
|
|
19
|
+
{
|
|
20
|
+
optionNo: number;
|
|
21
|
+
explain: string;
|
|
22
|
+
detailExplain: string;
|
|
23
|
+
status: [
|
|
24
|
+
{
|
|
25
|
+
name: string;
|
|
26
|
+
value: number;
|
|
27
|
+
}
|
|
28
|
+
];
|
|
29
|
+
}
|
|
30
|
+
];
|
|
31
|
+
};
|
package/src/util/config.ts
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
export interface IConfig {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
export interface IConfig {
|
|
2
|
+
key: string | undefined;
|
|
3
|
+
hideOnErrorApiKey: boolean;
|
|
4
|
+
hideKeyText: string;
|
|
5
|
+
timeout: number;
|
|
6
|
+
returnJSON: boolean;
|
|
7
|
+
responseHeader: boolean;
|
|
8
|
+
showURL: boolean;
|
|
9
|
+
}
|
|
10
|
+
// biome-ignore lint/style/useConst: <explanation>
|
|
11
|
+
let defaultConfig: IConfig = {
|
|
12
|
+
key: "",
|
|
13
|
+
hideOnErrorApiKey: true,
|
|
14
|
+
hideKeyText: "{HIDE_KEY}",
|
|
15
|
+
timeout: 5000,
|
|
16
|
+
returnJSON: false,
|
|
17
|
+
responseHeader: false,
|
|
18
|
+
showURL: false,
|
|
19
|
+
};
|
|
20
|
+
export default defaultConfig;
|
package/src/util/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import Config from "./config";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import * as Static from "./static";
|
|
5
|
-
|
|
6
|
-
export { Config, Query, Static, Params };
|
|
1
|
+
import Config from "./config";
|
|
2
|
+
import * as Params from "./params";
|
|
3
|
+
import Query from "./query";
|
|
4
|
+
import * as Static from "./static";
|
|
5
|
+
|
|
6
|
+
export { Config, Query, Static, Params };
|
package/src/util/params.ts
CHANGED
|
@@ -1,21 +1,24 @@
|
|
|
1
|
-
import * as Static from "./static";
|
|
2
|
-
export interface QueryOptions {
|
|
1
|
+
import type * as Static from "./static";
|
|
2
|
+
export interface QueryOptions<T = any> {
|
|
3
3
|
base: string;
|
|
4
|
-
params?:
|
|
4
|
+
params?: T;
|
|
5
5
|
}
|
|
6
6
|
export interface ICharParams {
|
|
7
7
|
characterName?: string;
|
|
8
8
|
jobId?: string;
|
|
9
9
|
jobGrowId?: string;
|
|
10
|
+
isAllJobGrow?: boolean;
|
|
10
11
|
wordType?: Static.CharactersWordType;
|
|
11
12
|
limit?: number;
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
export interface ITimeLine {
|
|
16
|
+
serverId?: Static.Server;
|
|
17
|
+
characterId?: string;
|
|
15
18
|
startDate?: Date;
|
|
16
19
|
endDate?: Date;
|
|
17
20
|
limit?: number;
|
|
18
|
-
code?: string;
|
|
21
|
+
code?: string[];
|
|
19
22
|
next?: string;
|
|
20
23
|
}
|
|
21
24
|
|
|
@@ -25,6 +28,8 @@ export interface IAuction {
|
|
|
25
28
|
itemId?: string;
|
|
26
29
|
itemName?: string;
|
|
27
30
|
wordType?: Static.AuctionWordType;
|
|
31
|
+
wordShort?: boolean;
|
|
32
|
+
q?: IAuctionQuery;
|
|
28
33
|
}
|
|
29
34
|
export interface IAuctionSort {
|
|
30
35
|
unitPrice?: Static.Sort;
|
|
@@ -35,10 +40,13 @@ export interface IAuctionQuery {
|
|
|
35
40
|
minLevel?: number;
|
|
36
41
|
maxLevel?: number;
|
|
37
42
|
raity?: Static.Rarity;
|
|
43
|
+
reinforceTypeId: Static.reinforceType;
|
|
38
44
|
minReinforce?: number;
|
|
39
45
|
maxReinforce?: number;
|
|
40
46
|
minRefine?: number;
|
|
41
47
|
maxRefine?: number;
|
|
48
|
+
minFame?: number;
|
|
49
|
+
maxFame?: number;
|
|
42
50
|
}
|
|
43
51
|
|
|
44
52
|
export interface IActionSoldOption {
|
|
@@ -52,6 +60,7 @@ export interface IActionSoldOption {
|
|
|
52
60
|
export interface IItem {
|
|
53
61
|
limit?: number;
|
|
54
62
|
itemName?: string;
|
|
63
|
+
hashtag?: string[];
|
|
55
64
|
wordType?: Static.AuctionWordType;
|
|
56
65
|
q?: IItemQuery;
|
|
57
66
|
}
|
|
@@ -59,7 +68,7 @@ export interface IItemQuery {
|
|
|
59
68
|
minLevel?: number;
|
|
60
69
|
maxLevel?: number;
|
|
61
70
|
rarity?: Static.Rarity;
|
|
62
|
-
trade?: boolean;
|
|
71
|
+
// trade?: boolean;
|
|
63
72
|
}
|
|
64
73
|
|
|
65
74
|
export interface ISetItem {
|
package/src/util/query.ts
CHANGED
|
@@ -1,109 +1,103 @@
|
|
|
1
|
-
import
|
|
2
|
-
import querystring from "
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
public static makeItemQuery(query: any) {
|
|
106
|
-
// return JSON.stringify(query).replace(/\"|\{|\}/gi, "");
|
|
107
|
-
return encodeURI(query);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
1
|
+
import consola from "consola";
|
|
2
|
+
import querystring from "query-string";
|
|
3
|
+
import { Client, request } from "undici";
|
|
4
|
+
|
|
5
|
+
import type * as Model from "../model";
|
|
6
|
+
import * as Util from "./";
|
|
7
|
+
|
|
8
|
+
const apiUrl = new URL("https://api.neople.co.kr");
|
|
9
|
+
// const client = new Client("https://api.neople.co.kr", {
|
|
10
|
+
// connectTimeout: Util.Config.timeout,
|
|
11
|
+
// // allowH2: true,
|
|
12
|
+
// });
|
|
13
|
+
|
|
14
|
+
const sender = async <T>(path: string, method: "GET" | "POST", query: any) => {
|
|
15
|
+
// const res = await client.request<Model.DnfResponse<T>>({
|
|
16
|
+
// const res = await client.request<T>({
|
|
17
|
+
// path,
|
|
18
|
+
// method,
|
|
19
|
+
// query,
|
|
20
|
+
// });
|
|
21
|
+
apiUrl.pathname = path;
|
|
22
|
+
apiUrl.search = querystring.stringify(query);
|
|
23
|
+
|
|
24
|
+
const res = await request<Model.DnfResponse<T>>(apiUrl.href, {
|
|
25
|
+
method,
|
|
26
|
+
});
|
|
27
|
+
return res;
|
|
28
|
+
};
|
|
29
|
+
const showUrl = (url: string): string => {
|
|
30
|
+
if (Util.Config.key) {
|
|
31
|
+
return url.replace(Util.Config.key, Util.Config.hideKeyText);
|
|
32
|
+
} else {
|
|
33
|
+
return url;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// biome-ignore lint/complexity/noStaticOnlyClass: <explanation>
|
|
38
|
+
export default class Request {
|
|
39
|
+
public static UriBuilder(...args: any[]): string {
|
|
40
|
+
return args.join("/");
|
|
41
|
+
}
|
|
42
|
+
public static QueryBuilder(query: string[] | number[]): string {
|
|
43
|
+
const qString: string[] = [];
|
|
44
|
+
for (const key in query) {
|
|
45
|
+
qString.push(`${key}:${query[key]},`);
|
|
46
|
+
}
|
|
47
|
+
return qString.join(",");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 던전앤파이터 API 서버에 응답을 요청하는 함수 입니다.
|
|
52
|
+
* 해당 함수를 직접 호출 하는것을 권장하지 않습니다.
|
|
53
|
+
*
|
|
54
|
+
* @param {object} opt (요청을 보낼 Parameter값)
|
|
55
|
+
* @returns
|
|
56
|
+
*/
|
|
57
|
+
public static async Request<T>(
|
|
58
|
+
opt: any = {},
|
|
59
|
+
method: "GET" | "POST" = "GET",
|
|
60
|
+
): Promise<Model.DnfResponse<T>> {
|
|
61
|
+
if (!Util.Config.key || Util.Config.key === "") {
|
|
62
|
+
consola.error("Please change to your api key. ");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (opt.params === undefined) opt.params = {};
|
|
66
|
+
if (opt.params.q) opt.params.q = Request.QueryBuilder(opt.params.q);
|
|
67
|
+
|
|
68
|
+
opt.params.apikey = Util.Config.key;
|
|
69
|
+
|
|
70
|
+
if (Util.Config.showURL)
|
|
71
|
+
consola.log(
|
|
72
|
+
"request url:",
|
|
73
|
+
showUrl(`${opt.base}?${querystring.stringify(opt.params)}`),
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
const res = await sender<Model.DnfResponse<T>>(
|
|
77
|
+
opt.base,
|
|
78
|
+
method,
|
|
79
|
+
opt.params,
|
|
80
|
+
);
|
|
81
|
+
if (res.statusCode !== 200) {
|
|
82
|
+
const resBody = (await res.body.json()) as Model.DnfResponse<T>;
|
|
83
|
+
const error: Model.DnfErrorResponse = {
|
|
84
|
+
url: showUrl(opt.url),
|
|
85
|
+
status: res.statusCode || 0,
|
|
86
|
+
statusText: "",
|
|
87
|
+
code: resBody.error?.code || "",
|
|
88
|
+
message: resBody.error?.message || "",
|
|
89
|
+
};
|
|
90
|
+
return { error };
|
|
91
|
+
} else {
|
|
92
|
+
const resBody = (await res.body.json()) as T;
|
|
93
|
+
return {
|
|
94
|
+
data: resBody,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
public static makeItemQuery(query: any) {
|
|
100
|
+
// return JSON.stringify(query).replace(/\"|\{|\}/gi, "");
|
|
101
|
+
return encodeURI(query);
|
|
102
|
+
}
|
|
103
|
+
}
|