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.
Files changed (60) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +313 -313
  3. package/bun.lockb +0 -0
  4. package/dist/index.js +22 -35
  5. package/jest.config.js +12 -12
  6. package/package.json +37 -41
  7. package/src/api/auction.ts +67 -61
  8. package/src/api/characters.equip.ts +81 -53
  9. package/src/api/characters.skill.ts +52 -52
  10. package/src/api/characters.ts +91 -60
  11. package/src/api/index.ts +9 -9
  12. package/src/api/items.ts +27 -9
  13. package/src/api/server.ts +9 -9
  14. package/src/api/setitems.ts +34 -29
  15. package/src/index.ts +29 -18
  16. package/src/model/character.ts +51 -3
  17. package/src/model/index.ts +86 -62
  18. package/src/model/item.ts +74 -22
  19. package/src/model/setitem.ts +31 -31
  20. package/src/util/config.ts +20 -19
  21. package/src/util/index.ts +6 -6
  22. package/src/util/params.ts +14 -5
  23. package/src/util/query.ts +103 -109
  24. package/src/util/static.ts +51 -45
  25. package/dist/api/auction.d.ts +0 -24
  26. package/dist/api/auction.js +0 -58
  27. package/dist/api/characters.d.ts +0 -32
  28. package/dist/api/characters.equip.d.ts +0 -29
  29. package/dist/api/characters.equip.js +0 -51
  30. package/dist/api/characters.js +0 -58
  31. package/dist/api/characters.skill.d.ts +0 -29
  32. package/dist/api/characters.skill.js +0 -51
  33. package/dist/api/index.d.ts +0 -8
  34. package/dist/api/index.js +0 -23
  35. package/dist/api/items.d.ts +0 -15
  36. package/dist/api/items.js +0 -40
  37. package/dist/api/server.d.ts +0 -2
  38. package/dist/api/server.js +0 -9
  39. package/dist/api/setitems.d.ts +0 -15
  40. package/dist/api/setitems.js +0 -28
  41. package/dist/index.d.ts +0 -14
  42. package/dist/model/character.d.ts +0 -41
  43. package/dist/model/character.js +0 -2
  44. package/dist/model/index.d.ts +0 -56
  45. package/dist/model/index.js +0 -15
  46. package/dist/model/item.d.ts +0 -45
  47. package/dist/model/item.js +0 -2
  48. package/dist/model/setitem.d.ts +0 -24
  49. package/dist/model/setitem.js +0 -2
  50. package/dist/util/config.d.ts +0 -11
  51. package/dist/util/config.js +0 -12
  52. package/dist/util/index.d.ts +0 -5
  53. package/dist/util/index.js +0 -20
  54. package/dist/util/params.d.ts +0 -67
  55. package/dist/util/params.js +0 -2
  56. package/dist/util/query.d.ts +0 -14
  57. package/dist/util/query.js +0 -132
  58. package/dist/util/static.d.ts +0 -44
  59. package/dist/util/static.js +0 -53
  60. package/src/index.tmp.js +0 -48
@@ -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
- export type DnfResponse<T> = {
15
- data?: T;
16
- error?: DnfErrorResponse;
17
- };
18
-
19
- export type Auction = {
20
- auctionNo: number;
21
- regDate: Date;
22
- expireDate: Date;
23
- itemId: string;
24
- itemName: string;
25
- itemAvailableLevel: number;
26
- itemRarity: string;
27
- itemType: string;
28
- itemTypeDetail: string;
29
- refine: number;
30
- reinforce: number;
31
- amplificationName: string;
32
- count: number;
33
- price: number;
34
- currentPrice: number;
35
- unitPrice: number;
36
- averagePrice: number;
37
- };
38
-
39
- export type AuctionSolid = {
40
- soldDate: string;
41
- itemId: string;
42
- itemName: string;
43
- itemAvailableLevel: number;
44
- itemRarity: string;
45
- itemType: string;
46
- itemTypeDetail: string;
47
- refine: number;
48
- reinforce: number;
49
- amplificationName: string | null;
50
- count: number;
51
- price: number;
52
- unitPrice: number;
53
- };
54
-
55
- export type Rows<T> = {
56
- rows: T[];
57
- };
58
-
59
- export type Server = {
60
- serverId: string;
61
- serverName: string;
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: Static.Rarity;
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
- setItemId: string;
24
- setItemName: string;
25
- itemStatus?: itemStatus[];
26
- cardInfo?: cardInfo[];
33
+ fame: number;
34
+ setItemId: string | null;
35
+ setItemName: string | null;
36
+ obtainInfo: ObtainInfo;
27
37
  };
28
38
 
29
- export type itemStatus = {
30
- name: string;
31
- value: number;
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 cardInfo = {
35
- slots: cardInfoSlot[];
36
- enchant: cardInfoEnchant[];
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 cardInfoSlot = {
40
- slotId: string;
41
- slotName: string;
93
+ export type ShopInfo = {
94
+ type: string;
42
95
  };
43
96
 
44
- export type cardInfoEnchant = {
45
- status: cardInfoEnchantStatus[];
46
- upgrade: number;
97
+ export type ShopDetail = {
98
+ rows: ShopRow[];
47
99
  };
48
100
 
49
- export type cardInfoEnchantStatus = {
101
+ export type ShopRow = {
50
102
  name: string;
51
- value: number;
103
+ details: string[];
52
104
  };
@@ -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
+ };
@@ -1,19 +1,20 @@
1
- export interface IConfig {
2
- key: string;
3
- hideOnErrorApiKey: boolean;
4
- hidekeyText: string;
5
- axiosTimeout: number;
6
- returnJSON: boolean;
7
- responeHeader: boolean;
8
- showURL: boolean
9
- }
10
- let defaultConfig: IConfig = {
11
- key: "",
12
- hideOnErrorApiKey: true,
13
- hidekeyText: "{HIDEKEY}",
14
- axiosTimeout: 5000,
15
- returnJSON: false,
16
- responeHeader: false,
17
- showURL: false
18
- };
19
- export default defaultConfig;
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 Query from "./query";
3
- import * as Params from "./params";
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 };
@@ -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?: any;
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 axios, { AxiosResponse } from "axios";
2
- import querystring from "querystring";
3
- // import urlencode from "urlencode";
4
- // import consola from "consola";
5
- const consola = require("consola");
6
-
7
- import * as Util from "./";
8
- import * as Model from "../model";
9
-
10
- const sender = axios.create({
11
- baseURL: "https://api.neople.co.kr",
12
- timeout: Util.Config.axiosTimeout,
13
- });
14
- const showUrl = (url: string): string => {
15
- return url.replace(Util.Config.key, Util.Config.hidekeyText);
16
- };
17
-
18
- export default class Request {
19
- public static UriBuilder(...args: any[]): string {
20
- return args.join("/");
21
- }
22
- public static queryBuilder(query: any): string {
23
- let qString: string[] = [];
24
- for (let key in query) {
25
- qString.push(`${key}:${query[key]},`);
26
- }
27
- return qString.join(",");
28
- }
29
-
30
- /**
31
- * 던전앤파이터 API 서버에 응답을 요청하는 함수 입니다.
32
- * 해당 함수를 직접 호출 하는것을 권장하지 않습니다.
33
- *
34
- * @param {object} opt (요청을 보낼 Parameter값)
35
- * @returns
36
- */
37
- public static async Request<T>(opt: any = {}, method: string = "GET"): Promise<Model.DnfResponse<T>> {
38
- if (!Util.Config.key || Util.Config.key == "") {
39
- consola.error("Please change to your api key. ");
40
- }
41
-
42
- if (opt.params == undefined) opt.params = {};
43
- if (opt.params.q) opt.params.q = this.queryBuilder(opt.params.q);
44
-
45
- opt.params.apikey = Util.Config.key;
46
- opt.url = `${opt.base}?${querystring.stringify(opt.params)}`;
47
-
48
- if (Util.Config.showURL) console.log(showUrl(opt.url));
49
-
50
- let responseData: Model.DnfResponse<T>;
51
- switch (method.toLowerCase()) {
52
- case "post":
53
- responseData = await sender
54
- .post(opt.url)
55
- .then((res: any) => {
56
- let data: T;
57
- if (res.data.rows) data = res.data.rows;
58
- else data = res.data;
59
- return { data };
60
- })
61
- .catch((err: any) => {
62
- if (err.response) {
63
- let error: Model.DnfErrorResponse = {
64
- url: showUrl(opt.url),
65
- status: err.response.status || 0,
66
- statusText: err.response.statusText,
67
- code: err.response.data.error.code,
68
- message: err.response.data.error.message,
69
- };
70
- return { error };
71
- } else {
72
- return { err: err };
73
- }
74
- });
75
- break;
76
- case "get":
77
- default:
78
- responseData = await sender
79
- .get(opt.url)
80
- .then((res: any) => {
81
- let data: T;
82
- if (res.data.rows) data = res.data.rows;
83
- else data = res.data;
84
- return { data };
85
- })
86
- .catch((err: any) => {
87
- if (err.response) {
88
- let error: Model.DnfErrorResponse = {
89
- url: showUrl(opt.url),
90
- status: err.response.status || 0,
91
- statusText: err.response.statusText,
92
- code: err.response.data.error.code,
93
- message: err.response.data.error.message,
94
- };
95
- return { error };
96
- } else {
97
- return { err: err };
98
- }
99
- });
100
- break;
101
- }
102
- return responseData;
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
+ }