eve-esi-types 2.2.1 → 2.2.4

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/esi-types-util.md CHANGED
@@ -8,19 +8,34 @@
8
8
 
9
9
  ## ESI Types Utility Definitions
10
10
 
11
- ### IsParameterizedPath
11
+ ### TESIRequestFunctionSignature
12
12
 
13
- `IsParameterizedPath<EP, A, B>` is a type to determine if a path is parameterized. If it is, it returns `A`, otherwise it returns `B`.
13
+ `TESIRequestFunctionSignature<ActualOpt>` is a type that defines the signature of an ESI request function,
14
+ which sends a request to a specified endpoint and returns a response.
14
15
 
15
- ```typescript
16
- type IsParameterizedPath<EP, A, B> = EP extends `${string}/{${string}}/${string | ""}` ? A : B;
16
+ ```ts
17
+ type TESIRequestFunctionSignature<ActualOpt> = <
18
+ M extends TESIEntryMethod,
19
+ EP extends keyof TESIResponseOKMap[M],
20
+ P2 extends IfParameterizedPath<EP, Opt>,
21
+ Opt extends IdentifyParameters<TESIResponseOKMap[M][EP], ActualOpt>,
22
+ R extends InferESIResponseResult<M, EP>
23
+ >(method: M, endpoint: EP, pathParams?: P2, options?: Opt) => Promise<R>;
24
+ ```
25
+
26
+ ### IfParameterizedPath
27
+
28
+ `IfParameterizedPath<EP, Opt>` if parameterized path then specify number type, otherwise will be `Opt` type.
29
+
30
+ ```ts
31
+ type IfParameterizedPath<EP, Opt> = EP extends `${string}/{${string}}/${string | ""}` ? number | number[]: Opt;
17
32
  ```
18
33
 
19
34
  ### IdentifyParameters
20
35
 
21
36
  `IdentifyParameters<Entry, Opt>` is a type to identify the required parameters for a given entry type.
22
37
 
23
- ```typescript
38
+ ```ts
24
39
  type IdentifyParameters<Entry, Opt> = Opt & Pick<Entry, Exclude<keyof Entry, "result">>;
25
40
  ```
26
41
 
@@ -28,7 +43,7 @@ type IdentifyParameters<Entry, Opt> = Opt & Pick<Entry, Exclude<keyof Entry, "re
28
43
 
29
44
  `InferESIResponseResult<M extends TESIEntryMethod, EP extends keyof TESIResponseOKMap[M]>` is a type to infer the result type of an ESI response based on the method and endpoint.
30
45
 
31
- ```typescript
46
+ ```ts
32
47
  type InferESIResponseResult<
33
48
  M extends TESIEntryMethod,
34
49
  EP extends keyof TESIResponseOKMap[M]
@@ -39,7 +54,7 @@ type InferESIResponseResult<
39
54
 
40
55
  `TESIEntryMethod` represents the HTTP methods supported by ESI.
41
56
 
42
- ```typescript
57
+ ```ts
43
58
  type TESIEntryMethod = keyof TESIResponseOKMap;
44
59
  ```
45
60
 
@@ -47,7 +62,7 @@ type TESIEntryMethod = keyof TESIResponseOKMap;
47
62
 
48
63
  `TEndPointGet` represents the endpoints for the "get" method.
49
64
 
50
- ```typescript
65
+ ```ts
51
66
  type TEndPointGet = keyof TESIResponseOKMap["get"];
52
67
  ```
53
68
 
@@ -55,7 +70,7 @@ type TEndPointGet = keyof TESIResponseOKMap["get"];
55
70
 
56
71
  `TEndPointPost` represents the endpoints for the "post" method.
57
72
 
58
- ```typescript
73
+ ```ts
59
74
  type TEndPointPost = keyof TESIResponseOKMap["post"];
60
75
  ```
61
76
 
@@ -63,7 +78,7 @@ type TEndPointPost = keyof TESIResponseOKMap["post"];
63
78
 
64
79
  `TEndPointPut` represents the endpoints for the "put" method.
65
80
 
66
- ```typescript
81
+ ```ts
67
82
  type TEndPointPut = keyof TESIResponseOKMap["put"];
68
83
  ```
69
84
 
@@ -71,7 +86,7 @@ type TEndPointPut = keyof TESIResponseOKMap["put"];
71
86
 
72
87
  `TEndPointDelete` represents the endpoints for the "delete" method.
73
88
 
74
- ```typescript
89
+ ```ts
75
90
  type TEndPointDelete = keyof TESIResponseOKMap["delete"];
76
91
  ```
77
92
 
@@ -79,7 +94,7 @@ type TEndPointDelete = keyof TESIResponseOKMap["delete"];
79
94
 
80
95
  `TESIResponseGetEntry<K extends TEndPointGet>` represents the entry details for the "get" method.
81
96
 
82
- ```typescript
97
+ ```ts
83
98
  type TESIResponseGetEntry<K extends TEndPointGet> = TESIResponseOKMap["get"][K];
84
99
  ```
85
100
 
@@ -87,7 +102,7 @@ type TESIResponseGetEntry<K extends TEndPointGet> = TESIResponseOKMap["get"][K];
87
102
 
88
103
  `TESIResponsePutEntry<K extends TEndPointPut>` represents the entry details for the "put" method.
89
104
 
90
- ```typescript
105
+ ```ts
91
106
  type TESIResponsePutEntry<K extends TEndPointPut> = TESIResponseOKMap["put"][K];
92
107
  ```
93
108
 
@@ -95,7 +110,7 @@ type TESIResponsePutEntry<K extends TEndPointPut> = TESIResponseOKMap["put"][K];
95
110
 
96
111
  `TESIResponsePostEntry<K extends TEndPointPost>` represents the entry details for the "post" method.
97
112
 
98
- ```typescript
113
+ ```ts
99
114
  type TESIResponsePostEntry<K extends TEndPointPost> = TESIResponseOKMap["post"][K];
100
115
  ```
101
116
 
@@ -103,6 +118,6 @@ type TESIResponsePostEntry<K extends TEndPointPost> = TESIResponseOKMap["post"][
103
118
 
104
119
  `TESIResponseDeleteEntry<K extends TEndPointDelete>` represents the entry details for the "delete" method.
105
120
 
106
- ```typescript
121
+ ```ts
107
122
  type TESIResponseDeleteEntry<K extends TEndPointDelete> = TESIResponseOKMap["delete"][K];
108
123
  ```
package/minimal-rq.d.mts CHANGED
@@ -6,16 +6,19 @@
6
6
  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7
7
  */
8
8
  import * as util from "./rq-util.mjs";
9
+ import type { IESIRequestFunction } from "./v2";
9
10
  /**
10
11
  * @typedef {import("./v2").TESIResponseOKMap} TESIResponseOKMap
11
12
  * @typedef {import("./rq-util.mjs").ESIRequestOptions} ESIRequestOptions
13
+ * @typedef {import("./v2").IESIRequestFunction<util.ESIRequestOptions>} IESIRequestFunction
14
+ * @typedef {import("./v2").TESIRequestFunctionMethods<util.ESIRequestOptions>} TESIRequestFunctionMethods
12
15
  */
13
16
  /** #### Sample of `TESIRequestFunctionSignature`
14
17
  *
15
18
  * + This is a minimal implementation using `TESIRequestFunctionSignature`.
16
19
  * If the response contains "page", only the first page can be retrieved.
17
20
  *
18
- * @type {TESIRequestFunctionSignature<ESIRequestOptions>}
21
+ * @type {IESIRequestFunction}
19
22
  * @param method - The HTTP method to use for the request
20
23
  * @param endpoint - The Path of the ESI endpoint to send the request to
21
24
  * @param pathParams - An object of parameters to include in the request
@@ -23,4 +26,4 @@ import * as util from "./rq-util.mjs";
23
26
  * @returns A Promise object containing the response data
24
27
  * @throws {ESIRequesError}
25
28
  */
26
- export declare const request: TESIRequestFunctionSignature<util.ESIRequestOptions>;
29
+ export declare const request: IESIRequestFunction<util.ESIRequestOptions>;
package/minimal-rq.mjs CHANGED
@@ -19,17 +19,18 @@ const DEBUG = util.isDebug();
19
19
  /**
20
20
  * @typedef {import("./v2").TESIResponseOKMap} TESIResponseOKMap
21
21
  * @typedef {import("./rq-util.mjs").ESIRequestOptions} ESIRequestOptions
22
+ * @typedef {import("./v2").IESIRequestFunction<util.ESIRequestOptions>} IESIRequestFunction
23
+ * @typedef {import("./v2").TESIRequestFunctionMethods<util.ESIRequestOptions>} TESIRequestFunctionMethods
22
24
  */
23
25
  // - - - - - - - - - - - - - - - - - - - -
24
26
  // main functions
25
27
  // - - - - - - - - - - - - - - - - - - - -
26
- // node scripts/minimal-rq.mjs
27
28
  /** #### Sample of `TESIRequestFunctionSignature`
28
29
  *
29
30
  * + This is a minimal implementation using `TESIRequestFunctionSignature`.
30
31
  * If the response contains "page", only the first page can be retrieved.
31
32
  *
32
- * @type {TESIRequestFunctionSignature<ESIRequestOptions>}
33
+ * @type {IESIRequestFunction}
33
34
  * @param method - The HTTP method to use for the request
34
35
  * @param endpoint - The Path of the ESI endpoint to send the request to
35
36
  * @param pathParams - An object of parameters to include in the request
@@ -37,39 +38,94 @@ const DEBUG = util.isDebug();
37
38
  * @returns A Promise object containing the response data
38
39
  * @throws {ESIRequesError}
39
40
  */
41
+ // @ts-expect-error
40
42
  export const request = (method, endpoint, pathParams, opt) => {
41
43
  if (typeof pathParams === "number") {
42
- // @ts-ignore
44
+ // @ts-expect-error
43
45
  pathParams = [pathParams];
44
46
  }
45
47
  if (Array.isArray(pathParams)) {
46
- // @ts-ignore actualy endp is string
48
+ // @ts-expect-error actualy endp is string
47
49
  endpoint = util.replaceCbt(endpoint, pathParams);
48
50
  }
49
51
  // When only options are provided
50
- // @ts-ignore
51
- const actualOpt = /** @type {ESIRequestOptions} */ (opt || pathParams || {});
52
+ const actualOpt = /** @type {NonNullable<typeof opt>} */ (opt || pathParams || {});
52
53
  const { rqopt, qss } = util.initOptions(method, actualOpt);
53
- // @ts-ignore actualy endp is string
54
+ // @ts-expect-error actualy endp is string
54
55
  const endpointUrl = util.curl(endpoint);
55
- const url = `${endpointUrl}?${new URLSearchParams(qss) + ""}`;
56
+ const up = new URLSearchParams(qss);
57
+ const url = `${endpointUrl}${up.size ? `?${up}` : ""}`;
56
58
  DEBUG && log(url);
57
59
  return fetch(url, rqopt).then(res => res.json()).catch(reason => {
58
60
  throw new util.ESIRequesError(reason.message ? reason.message : reason);
59
61
  });
60
62
  };
63
+ //
64
+ // implements rest methods of `request` (IESIRequestFunction)
65
+ //
66
+ /** @type {TESIEntryMethod[]} */ (["get", "post", "put", "delete"]).forEach((method) => {
67
+ request[method] = /** @type {TESIRequestFunctionEachMethod<typeof method>} */ (function (endpoint, params, opt) {
68
+ return this(method, endpoint, params, opt);
69
+ });
70
+ });
71
+ //
72
+ // Delegates implementation to `request` (TESIRequestFunctionMethods)
73
+ //
74
+ const esiMethods = /** @type {TESIRequestFunctionMethods} */ ({});
75
+ ["get", "post", "put", "delete"].forEach((method) => {
76
+ esiMethods[method] = function (endpoint, params, opt) {
77
+ // @ts-ignore
78
+ return request(method, endpoint, params, opt);
79
+ };
80
+ });
61
81
  // It should complete correctly.
62
82
  /**
63
- * @param {TESIRequestFunctionSignature<ESIRequestOptions>} fn
83
+ * @param {IESIRequestFunction} fn
64
84
  */
65
85
  async function getEVEStatus(fn) {
66
- const sdeVersion = await util.getSDEVersion();
67
- log(`sdeVersion: ${sdeVersion}`.blue);
86
+ await util.getSDEVersion().then(sdeVersion => log(`sdeVersion: ${sdeVersion}`.blue));
68
87
  await util.fireRequestsDoesNotRequireAuth(fn);
69
- return fn("get", "/status/");
88
+ CaseIESIRequestFunctionMethods: {
89
+ await util.fireRequestsDoesNotRequireAuth(esiMethods);
90
+ }
91
+ const { clog, rlog } = util.getLogger();
92
+ CaseIESIRequestFunction: {
93
+ // - - - - - - - - - - - -
94
+ // Character
95
+ // - - - - - - - - - - - -
96
+ // Here, I borrow data from "CCP Zoetrope".
97
+ rlog("- - - - - - - > run as IESIRequestFunction<ESIRequestOptions>".red);
98
+ clog();
99
+ await fn.get("/characters/{character_id}/", 2112625428).then(log);
100
+ clog('(portrait)');
101
+ await fn.get("/characters/{character_id}/portrait/", 2112625428).then(log);
102
+ clog('(affiliation)');
103
+ const affiliation = await fn.post("/characters/affiliation/", { body: [2112625428] });
104
+ log(affiliation);
105
+ clog('(corporation)');
106
+ await fn.get("/corporations/{corporation_id}/", affiliation[0].corporation_id).then(log);
107
+ rlog("get:/incursions/".green);
108
+ await fn.get("/incursions/").then(log);
109
+ // - - - - - - - - - - - -
110
+ // Miscellaneous
111
+ // - - - - - - - - - - - -
112
+ rlog("post:/universe/ids/".green);
113
+ const ids = await fn.post("/universe/ids/", { body: ["the forge", "plex"] });
114
+ log(ids.inventory_types, ids.regions);
115
+ rlog(`get:/markets/${ids?.regions?.[0].id}/orders/?type_id=${ids?.inventory_types?.[0].id}, item PLEX`.green);
116
+ const orders = await fn.get("/markets/{region_id}/orders/", ids?.regions?.[0].id, {
117
+ query: {
118
+ // page: 1,
119
+ order_type: "sell",
120
+ type_id: ids?.inventory_types?.[0].id
121
+ }
122
+ });
123
+ log(orders.sort((a, b) => a.price - b.price).slice(0, 2));
124
+ }
125
+ return fn.get("/status/");
70
126
  }
71
127
  // type following and run
72
- // node minimal-rq.mjs
128
+ // node minimal-rq.mjs -debug
73
129
  getEVEStatus(request).then(eveStatus => log(eveStatus));
74
130
  // {
75
131
  // "players": 16503,
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "eve-esi-types",
3
- "version": "2.2.1",
3
+ "version": "2.2.4",
4
4
  "description": "Extracted the main type of ESI. use for ESI request response types (version 2 only)",
5
5
  "main": "v2/index.d.ts",
6
6
  "scripts": {
7
- "test": "node v2.mjs"
7
+ "test": "node v2.mjs -debug",
8
+ "test:mini": "node minimal-rq.mjs -debug"
8
9
  },
9
10
  "repository": {
10
11
  "type": "git",
@@ -13,9 +14,7 @@
13
14
  "files": [
14
15
  "v2",
15
16
  "*.d.mts",
16
- "v2.mjs",
17
- "rq-util.mjs",
18
- "minimal-rq.mjs",
17
+ "*.mjs",
19
18
  "LICENSE",
20
19
  "*.md",
21
20
  "package.json",
@@ -37,6 +36,6 @@
37
36
  },
38
37
  "homepage": "https://github.com/jeffy-g/eve-esi-types#readme",
39
38
  "devDependencies": {
40
- "colors": "^1.4.0"
39
+ "colors.ts": "^1.0.20"
41
40
  }
42
41
  }
package/rq-util.d.mts CHANGED
@@ -5,7 +5,8 @@
5
5
  // https://opensource.org/licenses/mit-license.php
6
6
  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7
7
  */
8
- import "colors";
8
+ import "colors.ts";
9
+ import type { TESIRequestFunctionMethods } from "./v2";
9
10
  /**
10
11
  * this always `https://esi.evetech.net`
11
12
  */
@@ -62,8 +63,8 @@ export declare class ESIErrorLimitReachedError extends ESIRequesError {
62
63
  */
63
64
  export declare const isDebug: () => boolean;
64
65
  /**
65
- * @param method
66
- * @param opt
66
+ * @param {string} method
67
+ * @param {ESIRequestOptions} opt
67
68
  * @returns
68
69
  */
69
70
  export declare const initOptions: (method: string, opt: ESIRequestOptions) => {
@@ -77,11 +78,11 @@ export declare const initOptions: (method: string, opt: ESIRequestOptions) => {
77
78
  *
78
79
  * @param {string} endpointUrl
79
80
  * @param {RequestInit} rqopt request options
80
- * @param {Record<string, any>} qs queries
81
+ * @param {URLSearchParams} rqp queries
81
82
  * @param {number} pc pageCount
82
83
  * @param {(minus?: number) => void=} increment
83
84
  */
84
- export declare const fetchP: <T extends unknown>(endpointUrl: string, rqopt: RequestInit, qs: Record<string, any>, pc: number, increment?: (minus?: Truthy) => void) => Promise<T | null>;
85
+ export declare const fetchP: <T extends unknown>(endpointUrl: string, rqopt: RequestInit, rqp: URLSearchParams, pc: number, increment?: (minus?: Truthy) => void) => Promise<T | null>;
85
86
  /** ### replace (C)urly (B)races (T)oken
86
87
  *
87
88
  * @example
@@ -97,18 +98,22 @@ export declare const replaceCbt: (endpoint: string, ids: number[]) => string;
97
98
  /**
98
99
  *
99
100
  * @param {string} endp this means endpoint url fragment like `/characters/{character_id}/` or `/characters/{character_id}/agents_research/`
100
- * + The version parameter can be omitted by using `<version>/<endpoint>`
101
+ * + The version parameter is forced to apply `latest`
101
102
  */
102
103
  export declare const curl: (endp: string) => string;
103
104
  /**
104
105
  * @date 2020/03/31
105
- * @version 2.0 fix version date string problem (v1.0
106
+ * @version 2.1
106
107
  * @type {() => Promise<string>}
107
108
  */
108
109
  export declare function getSDEVersion(): Promise<string>;
110
+ export declare function getLogger(): {
111
+ clog: (...args: any[]) => void;
112
+ rlog: (...args: any[]) => void;
113
+ };
109
114
  /**
110
115
  * #### Fire a request that does not require authentication.
111
116
  *
112
- * @param {TESIRequestFunctionSignature<ESIRequestOptions>} fn
117
+ * @param {TESIRequestFunctionSignature<ESIRequestOptions> | TESIRequestFunctionMethods} fn
113
118
  */
114
- export declare function fireRequestsDoesNotRequireAuth(fn: TESIRequestFunctionSignature<ESIRequestOptions>): Promise<void>;
119
+ export declare function fireRequestsDoesNotRequireAuth(fn: TESIRequestFunctionSignature<ESIRequestOptions> | TESIRequestFunctionMethods<ESIRequestOptions>): Promise<void>;
package/rq-util.mjs CHANGED
@@ -5,10 +5,11 @@
5
5
  // https://opensource.org/licenses/mit-license.php
6
6
  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7
7
  */
8
+ /// <reference types="./v2"/>
8
9
  // - - - - - - - - - - - - - - - - - - - -
9
10
  // imports
10
11
  // - - - - - - - - - - - - - - - - - - - -
11
- import "colors";
12
+ import "colors.ts";
12
13
  // - - - - - - - - - - - - - - - - - - - -
13
14
  // constants, types
14
15
  // - - - - - - - - - - - - - - - - - - - -
@@ -49,8 +50,8 @@ export const isDebug = () => {
49
50
  return process.argv.includes("-debug");
50
51
  };
51
52
  /**
52
- * @param method
53
- * @param opt
53
+ * @param {string} method
54
+ * @param {ESIRequestOptions} opt
54
55
  * @returns
55
56
  */
56
57
  export const initOptions = (method, opt) => {
@@ -59,12 +60,11 @@ export const initOptions = (method, opt) => {
59
60
  method,
60
61
  mode: "cors",
61
62
  cache: "no-cache",
62
- // @ts-ignore
63
63
  signal: opt.cancelable?.signal,
64
64
  headers: {}
65
65
  };
66
66
  const qss = {
67
- language: "en",
67
+ // language: "en",
68
68
  };
69
69
  if (opt.query) {
70
70
  // Object.assign(query, options.query); Object.assign is too slow
@@ -89,13 +89,12 @@ export const initOptions = (method, opt) => {
89
89
  *
90
90
  * @param {string} endpointUrl
91
91
  * @param {RequestInit} rqopt request options
92
- * @param {Record<string, any>} qs queries
92
+ * @param {URLSearchParams} rqp queries
93
93
  * @param {number} pc pageCount
94
94
  * @param {(minus?: number) => void=} increment
95
95
  */
96
- export const fetchP = async (endpointUrl, rqopt, qs, pc, increment = () => { }) => {
96
+ export const fetchP = async (endpointUrl, rqopt, rqp, pc, increment = () => { }) => {
97
97
  const rqs = [];
98
- const rqp = new URLSearchParams(qs);
99
98
  for (let i = 2; i <= pc;) {
100
99
  rqp.set("page", (i++) + "");
101
100
  increment();
@@ -143,7 +142,7 @@ export const replaceCbt = (endpoint, ids) => {
143
142
  /**
144
143
  *
145
144
  * @param {string} endp this means endpoint url fragment like `/characters/{character_id}/` or `/characters/{character_id}/agents_research/`
146
- * + The version parameter can be omitted by using `<version>/<endpoint>`
145
+ * + The version parameter is forced to apply `latest`
147
146
  */
148
147
  export const curl = (endp) => {
149
148
  endp = endp.replace(/^\/+|\/+$/g, "");
@@ -151,79 +150,104 @@ export const curl = (endp) => {
151
150
  };
152
151
  /**
153
152
  * @date 2020/03/31
154
- * @version 2.0 fix version date string problem (v1.0
153
+ * @version 2.1
155
154
  * @type {() => Promise<string>}
156
155
  */
157
156
  export async function getSDEVersion() {
158
157
  const sdeZipUrl = "https://eve-static-data-export.s3-eu-west-1.amazonaws.com/tranquility/sde.zip";
159
- const date = await fetch(sdeZipUrl, { method: "head", mode: "cors" }).then((/** @type {Response} */ res) => res.headers.get("last-modified")).catch(reason => {
160
- console.log(reason);
161
- return new Date();
162
- });
163
- if (date) {
164
- const YMD = new Date(date).toLocaleString(void 0, {
165
- year: "numeric",
166
- month: "2-digit",
167
- day: "2-digit",
168
- // DEVNOTE: 191215 - "-" character appeared in node v13.3.0 (maybe
169
- }).replace(/(-|\/|:| )/g, (match, $1) => {
170
- switch ($1) {
171
- case "-":
172
- case "/":
173
- case ":": return "";
174
- case " ": return "@";
175
- }
176
- return match;
177
- });
178
- return `sde-${YMD}-TRANQUILITY`;
158
+ try {
159
+ const res = await fetch(sdeZipUrl, { method: "head", mode: "cors" });
160
+ const date = res.headers.get("last-modified");
161
+ if (date) {
162
+ const YMD = new Date(date).toLocaleDateString('en-CA').replace(/-/g, '');
163
+ return `sde-${YMD}-TRANQUILITY`;
164
+ }
165
+ else {
166
+ console.error("Failed to retrieve 'last-modified' header.");
167
+ return "sde-202Xxxxx-TRANQUILITY";
168
+ }
179
169
  }
180
- else {
170
+ catch (e) {
171
+ console.error("Error fetching SDE version:", e);
181
172
  return "sde-202Xxxxx-TRANQUILITY";
182
173
  }
183
174
  }
175
+ export function getLogger() {
176
+ const clog = console.log.bind(console, '- - -> Get the character data of "CCP Zoetrope"'.magenta);
177
+ const rlog = console.log.bind(console, '- - -> Run ESI request'.cyan);
178
+ return { clog, rlog };
179
+ }
180
+ /**
181
+ * Need typescript v5.5 later
182
+ * @import * as ESI from "./v2";
183
+ * @typedef {ESI.TESIResponseOKMap} TESIResponseOKMap
184
+ * @typedef {ESI.IESIRequestFunction<ESIRequestOptions>} IESIRequestFunction
185
+ * @typedef {ESI.TESIRequestFunctionMethods<ESIRequestOptions>} TESIRequestFunctionMethods
186
+ */
187
+ /**
188
+ * #### Fire a request that does not require authentication.
189
+ *
190
+ * @template {TESIEntryMethod} M
191
+ * @template {keyof TESIResponseOKMap[M]} EP
192
+ * @template {IfParameterizedPath<EP, Opt>} P2
193
+ * @template {IdentifyParameters<TESIResponseOKMap[M][EP], ESIRequestOptions>} Opt
194
+ * @template {InferESIResponseResult<M, EP>} R
195
+ *
196
+ * @param {TESIRequestFunctionSignature<ESIRequestOptions> | TESIRequestFunctionMethods} fn
197
+ * @param {M} method
198
+ * @param {EP} endpoint
199
+ * @param {P2} [pathParams]
200
+ * @param {Opt} [opt]
201
+ * @returns {Promise<R>}
202
+ */
203
+ function fireWithoutAuth(fn, method, endpoint, pathParams, opt) {
204
+ if (typeof fn === "function") {
205
+ return fn(method, endpoint, pathParams, opt);
206
+ }
207
+ return fn[method](endpoint, pathParams, opt);
208
+ }
184
209
  // It should complete correctly.
185
210
  /**
186
211
  * #### Fire a request that does not require authentication.
187
212
  *
188
- * @param {TESIRequestFunctionSignature<ESIRequestOptions>} fn
213
+ * @param {TESIRequestFunctionSignature<ESIRequestOptions> | TESIRequestFunctionMethods} fn
189
214
  */
190
215
  export async function fireRequestsDoesNotRequireAuth(fn) {
191
- const clog = console.log.bind(console, '- - -> Get the character data of "CCP Zoetrope"'.magenta);
192
- const rlog = console.log.bind(console, '- - -> Run ESI request'.cyan);
216
+ const { clog, rlog } = getLogger();
193
217
  try {
194
218
  // - - - - - - - - - - - -
195
219
  // Character
196
220
  // - - - - - - - - - - - -
197
221
  // Here, I borrow data from "CCP Zoetrope".
198
222
  clog();
199
- await fn("get", "/characters/{character_id}/", 2112625428).then(log);
223
+ await fireWithoutAuth(fn, "get", "/characters/{character_id}/", 2112625428).then(log);
200
224
  clog('(portrait)');
201
- await fn("get", "/characters/{character_id}/portrait/", 2112625428).then(log);
225
+ await fireWithoutAuth(fn, "get", "/characters/{character_id}/portrait/", 2112625428).then(log);
202
226
  clog('(affiliation)');
203
- const affiliation = await fn("post", "/characters/affiliation/", { body: [2112625428] });
227
+ const affiliation = await fireWithoutAuth(fn, "post", "/characters/affiliation/", { body: [2112625428] });
204
228
  log(affiliation);
205
229
  clog('(corporation)');
206
- await fn("get", "/corporations/{corporation_id}/", affiliation[0].corporation_id).then(log);
230
+ await fireWithoutAuth(fn, "get", "/corporations/{corporation_id}/", affiliation[0].corporation_id).then(log);
207
231
  rlog("get:/incursions/".green);
208
- await fn("get", "/incursions/").then(log);
232
+ await fireWithoutAuth(fn, "get", "/incursions/").then(log);
209
233
  // - - - - - - - - - - - -
210
234
  // Miscellaneous
211
235
  // - - - - - - - - - - - -
212
236
  rlog("post:/universe/ids/".green);
213
- const ids = await fn("post", "/universe/ids/", { body: ["the forge", "plex"] });
214
- log(ids);
237
+ const ids = await fireWithoutAuth(fn, "post", "/universe/ids/", { body: ["the forge", "plex"] });
238
+ log(ids.inventory_types, ids.regions);
215
239
  rlog(`get:/markets/${ids?.regions?.[0].id}/orders/?type_id=${ids?.inventory_types?.[0].id}, item PLEX`.green);
216
- const orders = await fn("get", "/markets/{region_id}/orders/", ids?.regions?.[0].id, {
240
+ const orders = await fireWithoutAuth(fn, "get", "/markets/{region_id}/orders/", ids?.regions?.[0].id, {
217
241
  query: {
218
242
  // page: 1,
219
243
  order_type: "sell",
220
244
  type_id: ids?.inventory_types?.[0].id
221
245
  }
222
246
  });
223
- log(orders.sort((a, b) => a.price - b.price).slice(0, 5));
247
+ log(orders.sort((a, b) => a.price - b.price).slice(0, 2));
224
248
  rlog("get:/universe/structures/?filter=market".green);
225
249
  // query patameter `filter` is optional
226
- const structures = await fn("get", "/universe/structures/", {
250
+ const structures = await fireWithoutAuth(fn, "get", "/universe/structures/", {
227
251
  query: {
228
252
  filter: "market"
229
253
  }
@@ -233,13 +257,13 @@ export async function fireRequestsDoesNotRequireAuth(fn) {
233
257
  // The following is code to observe the behavior of completion by generics.
234
258
  // Authentication is required, so an error will occur.
235
259
  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
236
- let ok = await fn("get", "/characters/{character_id}/ship/", 994562, {
260
+ let ok = await fireWithoutAuth(fn, "get", "/characters/{character_id}/ship/", 994562, {
237
261
  auth: true,
238
262
  ignoreError: true,
239
263
  token: "token.token.token"
240
264
  });
241
265
  // in this case, "categories" and "search" is required
242
- await fn("get", "/characters/{character_id}/search/", 994562, {
266
+ await fireWithoutAuth(fn, "get", "/characters/{character_id}/search/", 994562, {
243
267
  query: {
244
268
  categories: ["agent"],
245
269
  search: "ok"
@@ -247,13 +271,13 @@ export async function fireRequestsDoesNotRequireAuth(fn) {
247
271
  auth: true
248
272
  });
249
273
  // in this case, "order_type" is required
250
- await fn("get", "/markets/{region_id}/orders/", 994562, {
274
+ await fireWithoutAuth(fn, "get", "/markets/{region_id}/orders/", 994562, {
251
275
  query: {
252
276
  order_type: "all"
253
277
  },
254
278
  });
255
279
  // TODO: want TypeScript semantics to throw an error because there is a required query parameter, but it's not possible
256
- await fn("get", "/characters/{character_id}/search/");
280
+ await fireWithoutAuth(fn, "get", "/characters/{character_id}/search/");
257
281
  log(ok);
258
282
  }
259
283
  catch (e) {
package/tsconfig.json CHANGED
@@ -20,5 +20,7 @@
20
20
  "include": [
21
21
  "./scripts/*.mts"
22
22
  ],
23
- "exclude": []
23
+ "exclude": [
24
+ "./scripts/auth-*"
25
+ ]
24
26
  }