@eveshipfit/zkillboard 1.0.0

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 ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2023 EVEShipFit Team
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # @eveshipfit/zkillboard
2
+
3
+ A small client for [zKillboard](https://zkillboard.com)'s API.
4
+
5
+ Part of [EVEShip.fit](https://eveship.fit).
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ npm install @eveshipfit/zkillboard
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ import { ZKillboard } from "@eveshipfit/zkillboard";
17
+
18
+ const zkillboard = new ZKillboard();
19
+
20
+ await zkillboard.price(35834); // a Keepstar, in ISK
21
+ ```
22
+
23
+ zKillboard prices what ESI has no market price for, like capital modules and Keepstars. Requests go one at a time, a
24
+ second apart, and each type is asked for once.
25
+
26
+ ## License
27
+
28
+ MIT
@@ -0,0 +1,8 @@
1
+ //#region src/zkillboard.d.ts
2
+ /** A zKillboard client. */
3
+ export declare class ZKillboard {
4
+ #private;
5
+ /** zKillboard's current price of a type in ISK; undefined when it has none. */
6
+ price(typeId: number): Promise<number | undefined>;
7
+ }
8
+ //#endregion
package/dist/index.mjs ADDED
@@ -0,0 +1,32 @@
1
+ //#region src/zkillboard.ts
2
+ const baseUrl = "https://zkillboard.com/api";
3
+ const timeout = 1e4;
4
+ const spacing = 1e3;
5
+ /** A zKillboard client. */
6
+ var ZKillboard = class {
7
+ #prices = /* @__PURE__ */ new Map();
8
+ #queue = Promise.resolve();
9
+ /** zKillboard's current price of a type in ISK; undefined when it has none. */
10
+ price(typeId) {
11
+ let price = this.#prices.get(typeId);
12
+ if (price === void 0) {
13
+ price = this.#queued(() => fetchPrice(typeId));
14
+ this.#prices.set(typeId, price);
15
+ }
16
+ return price;
17
+ }
18
+ #queued(request) {
19
+ const result = this.#queue.then(request);
20
+ this.#queue = result.catch(() => {}).then(() => new Promise((resolve) => setTimeout(resolve, spacing)));
21
+ return result;
22
+ }
23
+ };
24
+ async function fetchPrice(typeId) {
25
+ const response = await fetch(`${baseUrl}/prices/${typeId}/`, { signal: AbortSignal.timeout(timeout) });
26
+ if (!response.ok) throw new Error(`zKillboard /prices/${typeId}/: HTTP ${response.status}`);
27
+ const { currentPrice } = await response.json();
28
+ const price = Number(currentPrice);
29
+ return price > .01 ? price : void 0;
30
+ }
31
+ //#endregion
32
+ export { ZKillboard };
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@eveshipfit/zkillboard",
3
+ "version": "1.0.0",
4
+ "description": "A small client for zKillboard",
5
+ "license": "MIT",
6
+ "author": "EVEShipFit Team <info@eveship.fit>",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/EVEShipFit/eveship.fit.git",
10
+ "directory": "packages/zkillboard"
11
+ },
12
+ "files": [
13
+ "dist"
14
+ ],
15
+ "type": "module",
16
+ "sideEffects": false,
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/index.d.mts",
20
+ "default": "./dist/index.mjs"
21
+ }
22
+ },
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "devDependencies": {
27
+ "@types/node": "^22.0.0",
28
+ "tsdown": "^0.23.0"
29
+ },
30
+ "scripts": {
31
+ "build": "tsdown"
32
+ }
33
+ }