dnf-api 0.6.5 → 1.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.
@@ -1,81 +1,81 @@
1
- import type * as Static from "./static";
2
- export interface QueryOptions<T = any> {
3
- base: string;
4
- params?: T;
5
- }
6
- export interface ICharParams {
7
- characterName?: string;
8
- jobId?: string;
9
- jobGrowId?: string;
10
- isAllJobGrow?: boolean;
11
- wordType?: Static.CharactersWordType;
12
- limit?: number;
13
- }
14
-
15
- export interface ITimeLine {
16
- serverId?: Static.Server;
17
- characterId?: string;
18
- startDate?: Date;
19
- endDate?: Date;
20
- limit?: number;
21
- code?: string[];
22
- next?: string;
23
- }
24
-
25
- export interface IAuction {
26
- limit?: number;
27
- sort?: IAuctionSort;
28
- itemId?: string;
29
- itemName?: string;
30
- wordType?: Static.AuctionWordType;
31
- wordShort?: boolean;
32
- q?: IAuctionQuery;
33
- }
34
- export interface IAuctionSort {
35
- unitPrice?: Static.Sort;
36
- reinforce?: Static.Sort;
37
- auctionNo?: Static.Sort;
38
- }
39
- export interface IAuctionQuery {
40
- minLevel?: number;
41
- maxLevel?: number;
42
- raity?: Static.Rarity;
43
- reinforceTypeId: Static.reinforceType;
44
- minReinforce?: number;
45
- maxReinforce?: number;
46
- minRefine?: number;
47
- maxRefine?: number;
48
- minFame?: number;
49
- maxFame?: number;
50
- }
51
-
52
- export interface IActionSoldOption {
53
- limit?: number;
54
- wordType?: Static.AuctionWordType;
55
- wordShort?: boolean;
56
- itemId?: string;
57
- itemName?: string;
58
- }
59
-
60
- export interface IItem {
61
- limit?: number;
62
- itemName?: string;
63
- hashtag?: string[];
64
- wordType?: Static.AuctionWordType;
65
- q?: IItemQuery;
66
- }
67
- export interface IItemQuery {
68
- minLevel?: number;
69
- maxLevel?: number;
70
- rarity?: Static.Rarity;
71
- // trade?: boolean;
72
- }
73
-
74
- export interface ISetItem {
75
- setItemName?: string;
76
- limit?: number;
77
- wordType?: Static.AuctionWordType;
78
- }
79
- export interface ISkill {
80
- jobGrowId: string;
81
- }
1
+ import type * as staticUtil from "./static";
2
+ export interface QueryOptions<T = any> {
3
+ base: string;
4
+ params?: T;
5
+ }
6
+ export interface ICharParams {
7
+ characterName?: string;
8
+ jobId?: string;
9
+ jobGrowId?: string;
10
+ isAllJobGrow?: boolean;
11
+ wordType?: staticUtil.charactersWordType;
12
+ limit?: number;
13
+ }
14
+
15
+ export interface ITimeLine {
16
+ serverId?: staticUtil.server;
17
+ characterId?: string;
18
+ startDate?: Date;
19
+ endDate?: Date;
20
+ limit?: number;
21
+ code?: string[];
22
+ next?: string;
23
+ }
24
+
25
+ export interface IAuction {
26
+ limit?: number;
27
+ sort?: IAuctionSort;
28
+ itemId?: string;
29
+ itemName?: string;
30
+ wordType?: staticUtil.auctionWordType;
31
+ wordShort?: boolean;
32
+ q?: IAuctionQuery;
33
+ }
34
+ export interface IAuctionSort {
35
+ unitPrice?: staticUtil.sort;
36
+ reinforce?: staticUtil.sort;
37
+ auctionNo?: staticUtil.sort;
38
+ }
39
+ export interface IAuctionQuery {
40
+ minLevel?: number;
41
+ maxLevel?: number;
42
+ raity?: staticUtil.rarity;
43
+ reinforceTypeId: staticUtil.reinforceType;
44
+ minReinforce?: number;
45
+ maxReinforce?: number;
46
+ minRefine?: number;
47
+ maxRefine?: number;
48
+ minFame?: number;
49
+ maxFame?: number;
50
+ }
51
+
52
+ export interface IActionSoldOption {
53
+ limit?: number;
54
+ wordType?: staticUtil.auctionWordType;
55
+ wordShort?: boolean;
56
+ itemId?: string;
57
+ itemName?: string;
58
+ }
59
+
60
+ export interface IItem {
61
+ limit?: number;
62
+ itemName?: string;
63
+ hashtag?: string[];
64
+ wordType?: staticUtil.auctionWordType;
65
+ q?: IItemQuery;
66
+ }
67
+ export interface IItemQuery {
68
+ minLevel?: number;
69
+ maxLevel?: number;
70
+ rarity?: staticUtil.rarity;
71
+ // trade?: boolean;
72
+ }
73
+
74
+ export interface ISetItem {
75
+ setItemName?: string;
76
+ limit?: number;
77
+ wordType?: staticUtil.auctionWordType;
78
+ }
79
+ export interface ISkill {
80
+ jobGrowId: string;
81
+ }
package/src/util/query.ts CHANGED
@@ -1,103 +1,93 @@
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
- }
1
+ import consola from "consola";
2
+ import querystring from "query-string";
3
+ import { 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
+ apiUrl.pathname = path;
16
+ apiUrl.search = querystring.stringify(query);
17
+ const res = await request<model.IDnfResponse<T>>(apiUrl.href, {
18
+ method,
19
+ });
20
+ return res;
21
+ };
22
+
23
+ const showUrl = (url: string): string => {
24
+ if (Util.config.key) {
25
+ return url?.replace(Util.config.key, Util.config.hideKeyText);
26
+ } else {
27
+ return url;
28
+ }
29
+ };
30
+
31
+ // biome-ignore lint/complexity/noStaticOnlyClass: <explanation>
32
+ export default class Request {
33
+ public static UriBuilder(...args: any[]): string {
34
+ return args.join("/");
35
+ }
36
+ public static QueryBuilder(query: string[] | number[]): string {
37
+ const qString: string[] = [];
38
+ for (const key in query) {
39
+ qString.push(`${key}:${query[key]},`);
40
+ }
41
+ return qString.join(",");
42
+ }
43
+
44
+ /**
45
+ * 던전앤파이터 API 서버에 응답을 요청하는 함수 입니다.
46
+ * 해당 함수를 직접 호출 하는것을 권장하지 않습니다.
47
+ *
48
+ * @param {object} opt (요청을 보낼 Parameter값)
49
+ * @returns
50
+ */
51
+ public static async Request<T>(
52
+ opt: any = {},
53
+ method: "GET" | "POST" = "GET"
54
+ ): Promise<model.IDnfResponse<T>> {
55
+ if (!Util.config.key || Util.config.key === "") {
56
+ consola.error("Please change to your api key. ");
57
+ }
58
+
59
+ if (opt.params === undefined) opt.params = {};
60
+ if (opt.params.q) opt.params.q = Request.QueryBuilder(opt.params.q);
61
+
62
+ opt.params.apikey = Util.config.key;
63
+
64
+ if (Util.config.showURL)
65
+ consola.log(
66
+ "request url:",
67
+ showUrl(`${opt.base}?${querystring.stringify(opt.params)}`)
68
+ );
69
+
70
+ const res = await sender<T>(opt.base, method, opt.params);
71
+ if (res.statusCode !== 200) {
72
+ const resBody = (await res.body.json()) as model.IDnfResponse<T>;
73
+ const error: model.IDnfErrorResponse = {
74
+ url: showUrl(opt.url ?? ""),
75
+ status: res.statusCode || 0,
76
+ statusText: "",
77
+ code: resBody.error?.code || "",
78
+ message: resBody.error?.message || "",
79
+ };
80
+ return { error };
81
+ } else {
82
+ const resBody = (await res.body.json()) as T;
83
+ return {
84
+ data: resBody,
85
+ };
86
+ }
87
+ }
88
+
89
+ public static makeItemQuery(query: any) {
90
+ // return JSON.stringify(query).replace(/\"|\{|\}/gi, "");
91
+ return encodeURI(query);
92
+ }
93
+ }
@@ -1,4 +1,4 @@
1
- export enum Server {
1
+ export enum server {
2
2
  Cain = "cain",
3
3
  Diregie = "diregie",
4
4
  Siroco = "siroco",
@@ -8,11 +8,11 @@ export enum Server {
8
8
  Anton = "anton",
9
9
  Bakal = "bakal",
10
10
  }
11
- export enum Sort {
11
+ export enum sort {
12
12
  Asc = "asc",
13
13
  Desc = "desc",
14
14
  }
15
- export enum Rarity {
15
+ export enum rarity {
16
16
  Common = "커먼",
17
17
  Uncommon = "언커먼",
18
18
  Rare = "레어",
@@ -22,21 +22,21 @@ export enum Rarity {
22
22
  Legendary = "레전더리",
23
23
  }
24
24
 
25
- export enum AuctionWordType {
25
+ export enum auctionWordType {
26
26
  Match = "match",
27
27
  Front = "front",
28
28
  Full = "full",
29
29
  }
30
- export enum WordType {
30
+ export enum wordType {
31
31
  Match = "match",
32
32
  Front = "front",
33
33
  Full = "full",
34
34
  }
35
- export enum CharactersWordType {
35
+ export enum charactersWordType {
36
36
  Match = "match",
37
37
  Full = "full",
38
38
  }
39
- export enum BaseUri {
39
+ export enum baseUri {
40
40
  Servers = "df/servers",
41
41
  Auction = "df/auction",
42
42
  AuctionSold = "df/auction-sold",