From 666920e37b397f703c6bdcd50a06bca59e716427 Mon Sep 17 00:00:00 2001 From: Natalie Rose Date: Sat, 22 Aug 2026 10:23:23 +1000 Subject: [PATCH] Add get_body_status --- .gitignore | 1 + lib/__utils__/find-building.ts | 5 ++--- lib/__utils__/get-lacuna.ts | 5 ++--- lib/__utils__/tmpfile.ts | 3 +++ lib/endpoints/body.test.ts | 7 +++++++ lib/endpoints/body.ts | 4 ++++ lib/types/body.ts | 12 ++++++++++++ package-lock.json | 14 +++++++------- package.json | 2 +- tmp/.gitkeep | 0 10 files changed, 39 insertions(+), 14 deletions(-) create mode 100644 lib/__utils__/tmpfile.ts create mode 100644 tmp/.gitkeep diff --git a/.gitignore b/.gitignore index b6674dd..f87c9a3 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ coverage/ .DS_Store node_modules/ dist/ +tmp/ diff --git a/lib/__utils__/find-building.ts b/lib/__utils__/find-building.ts index 1fe281a..46b359d 100644 --- a/lib/__utils__/find-building.ts +++ b/lib/__utils__/find-building.ts @@ -1,9 +1,8 @@ import fs from 'node:fs'; -import os from 'node:os'; -import path from 'node:path'; import _ from 'lodash'; import Lacuna from '../lacuna'; import { int } from '../core/util'; +import { tmpfile } from './tmpfile'; // Nearly every buildings/*.test.ts file calls findBuilding() in its own // beforeAll, which would otherwise mean 1 empire.getStatus() + up to 4 @@ -12,7 +11,7 @@ import { int } from '../core/util'; // minute budget before any actual method under test even runs. The // building layout doesn't change during a read-only test run, so it's // fetched once and cached on disk for the rest of the run. -const CACHE_FILE = path.join(os.tmpdir(), 'tle-client-test-building-inventory.json'); +const CACHE_FILE = tmpfile('tle-client-test-building-inventory.json'); const INVENTORY_TTL_MS = 4 * 60 * 1000; type Inventory = Record>; // body_id -> building_id -> name diff --git a/lib/__utils__/get-lacuna.ts b/lib/__utils__/get-lacuna.ts index 09009b0..480efd0 100644 --- a/lib/__utils__/get-lacuna.ts +++ b/lib/__utils__/get-lacuna.ts @@ -1,14 +1,13 @@ import fs from 'node:fs'; -import os from 'node:os'; -import path from 'node:path'; import { Lacuna } from '../'; +import { tmpfile } from './tmpfile'; // The live server rate-limits to 200 requests/minute per empire. With one // Jest test *file* per endpoint module, having every file log in separately // burns a big chunk of that budget on nothing but auth. A session is cheap // to reuse across the whole test run, so it's cached on disk (keyed to this // account) and only refreshed once it's older than SESSION_TTL_MS. -const CACHE_FILE = path.join(os.tmpdir(), 'tle-client-test-session.json'); +const CACHE_FILE = tmpfile('tle-client-test-session.json'); const SESSION_TTL_MS = 4 * 60 * 1000; interface CachedSession { diff --git a/lib/__utils__/tmpfile.ts b/lib/__utils__/tmpfile.ts new file mode 100644 index 0000000..0181dd9 --- /dev/null +++ b/lib/__utils__/tmpfile.ts @@ -0,0 +1,3 @@ +import path from 'node:path'; + +export const tmpfile = (name: string) => path.resolve(path.join(__dirname, '../../tmp', name)); diff --git a/lib/endpoints/body.test.ts b/lib/endpoints/body.test.ts index 791e2ea..557fb34 100644 --- a/lib/endpoints/body.test.ts +++ b/lib/endpoints/body.test.ts @@ -42,3 +42,10 @@ test('getStatus', async () => { expect(result?.server).toBeDefined(); expectMatchesApiSchema('body', 'get_status', result); }); + +test('getBodyStatus', async () => { + // Using a known good body id from the homelab server to test this + const { result, error } = await lacuna.body.getBodyStatus({ body_id: 467646 }); + expect(result?.body).toBeDefined(); + expectMatchesApiSchema('body', 'get_body_status', result); +}); diff --git a/lib/endpoints/body.ts b/lib/endpoints/body.ts index 7f9f68a..283eca1 100644 --- a/lib/endpoints/body.ts +++ b/lib/endpoints/body.ts @@ -20,6 +20,10 @@ class Body extends Endpoint { return this.callWithSession('get_status', params); } + getBodyStatus(params: B.GetBodyStatusParams) { + return this.callWithSession('get_body_status', params); + } + rearrangeBuildings(params: B.RearrangeBuildingsParams) { return this.callWithSession('rearrange_buildings', params); } diff --git a/lib/types/body.ts b/lib/types/body.ts index 54fde8c..7cff0b1 100644 --- a/lib/types/body.ts +++ b/lib/types/body.ts @@ -30,6 +30,18 @@ export interface GetStatusParams { export interface GetStatusResponse extends StatusBlock {} +export interface GetBodyStatusParams { + body_id: number; +} + +export interface GetBodyStatusResponse { + body: components['schemas']['body_status']; + status: { + server: components['schemas']['server_status']; + empire: components['schemas']['empire_status']; + }; +} + export interface RearrangeBuildingsParams { body_id: number; arrangement: Array<{ diff --git a/package-lock.json b/package-lock.json index d81abba..d2acad5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,7 @@ "proper-url-join": "^2.1.2" }, "devDependencies": { - "@tlecommunity/api-spec": "^1.2.0", + "@tlecommunity/api-spec": "^1.2.2", "@types/jest": "^30.0.0", "@types/proper-url-join": "^2.1.5", "ajv": "^8.20.0", @@ -1541,9 +1541,9 @@ } }, "node_modules/@tlecommunity/api-spec": { - "version": "1.2.0", - "resolved": "https://gitea.allosaurus-chromatic.ts.net/api/packages/tlecommunity/npm/%40tlecommunity%2Fapi-spec/-/1.2.0/api-spec-1.2.0.tgz", - "integrity": "sha512-SYV0sQmU5UHGVyv2L1s3c/fQZyPNefEMJpSSjuA4ItAB3+97zxRdsFyAh3k3gqNRH3DTKNyRnhNBdrCQdufeBA==", + "version": "1.2.2", + "resolved": "https://gitea.allosaurus-chromatic.ts.net/api/packages/tlecommunity/npm/%40tlecommunity%2Fapi-spec/-/1.2.2/api-spec-1.2.2.tgz", + "integrity": "sha512-7gFjtbKOrvzjz2vfvRgzJZPlMy3KrhtHRHWlFki/46RPjOrC0wO6ncp625ehCSml/0m01CVSadTnEkfE5BXinw==", "dev": true, "license": "MIT" }, @@ -7169,9 +7169,9 @@ } }, "@tlecommunity/api-spec": { - "version": "1.2.0", - "resolved": "https://gitea.allosaurus-chromatic.ts.net/api/packages/tlecommunity/npm/%40tlecommunity%2Fapi-spec/-/1.2.0/api-spec-1.2.0.tgz", - "integrity": "sha512-SYV0sQmU5UHGVyv2L1s3c/fQZyPNefEMJpSSjuA4ItAB3+97zxRdsFyAh3k3gqNRH3DTKNyRnhNBdrCQdufeBA==", + "version": "1.2.2", + "resolved": "https://gitea.allosaurus-chromatic.ts.net/api/packages/tlecommunity/npm/%40tlecommunity%2Fapi-spec/-/1.2.2/api-spec-1.2.2.tgz", + "integrity": "sha512-7gFjtbKOrvzjz2vfvRgzJZPlMy3KrhtHRHWlFki/46RPjOrC0wO6ncp625ehCSml/0m01CVSadTnEkfE5BXinw==", "dev": true }, "@tybys/wasm-util": { diff --git a/package.json b/package.json index 4ec1aa0..a7a77bc 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "author": "Natalie Rose ", "license": "MIT", "devDependencies": { - "@tlecommunity/api-spec": "^1.2.0", + "@tlecommunity/api-spec": "^1.2.2", "@types/jest": "^30.0.0", "@types/proper-url-join": "^2.1.5", "ajv": "^8.20.0", diff --git a/tmp/.gitkeep b/tmp/.gitkeep new file mode 100644 index 0000000..e69de29 -- 2.51.2