From 858248847723b7073bd8683b86cf606318dbbbce Mon Sep 17 00:00:00 2001 From: Natalie McCallum Date: Thu, 14 Aug 2025 19:35:33 +1000 Subject: [PATCH] Updates now that I have my own server running --- .nvmrc | 2 +- LICENSE | 2 +- lib/__utils__/get-lacuna.ts | 4 +- lib/core/config.ts | 4 +- lib/core/log.test.ts | 2 +- lib/endpoints/buildings/shipyard.test.ts | 9 ++- lib/endpoints/buildings/shipyard.ts | 18 +++-- lib/endpoints/buildings/space-port.test.ts | 58 +++++---------- lib/endpoints/buildings/space-port.ts | 40 +++++------ lib/endpoints/empire.test.ts | 8 +-- lib/lacuna.test.ts | 10 +-- lib/lacuna.ts | 2 +- lib/types/index.ts | 2 +- lib/types/shipyard.ts | 9 +-- lib/types/space-port.ts | 83 ++++++++-------------- package-lock.json | 8 +-- package.json | 6 +- 17 files changed, 108 insertions(+), 159 deletions(-) diff --git a/.nvmrc b/.nvmrc index 209e3ef..2bd5a0a 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -20 +22 diff --git a/LICENSE b/LICENSE index 7473d2e..38cbe10 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2022 Natalie McCallum +Copyright (c) 2022 Natalie Rose Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/lib/__utils__/get-lacuna.ts b/lib/__utils__/get-lacuna.ts index 4c4da42..7a0b9d2 100644 --- a/lib/__utils__/get-lacuna.ts +++ b/lib/__utils__/get-lacuna.ts @@ -1,7 +1,7 @@ import { Lacuna } from '../'; export const getLacuna = async () => { - const lacuna = new Lacuna({ serverUrl: 'http://localhost:8080/' }); - await lacuna.authenticate('natalie', '1234qwer'); + const lacuna = new Lacuna(); + await lacuna.authenticate('nataliethistime', '1234qwer'); return lacuna; }; diff --git a/lib/core/config.ts b/lib/core/config.ts index 2c2af5e..1f277cf 100644 --- a/lib/core/config.ts +++ b/lib/core/config.ts @@ -5,14 +5,14 @@ import { ensureTrailingSlash } from './util'; class Config { lacuna: Lacuna; - serverUrl = ''; + serverUrl = 'https://lacuna.ocean74.net/'; apiKey = 'anonymous'; fingerprintToken = 'TODO'; constructor(lacuna: Lacuna, config: LacunaConfig) { this.lacuna = lacuna; - this.serverUrl = ensureTrailingSlash(config.serverUrl); + if (config.serverUrl) this.serverUrl = ensureTrailingSlash(config.serverUrl); if (config.apiKey) this.apiKey = config.apiKey; if (config.fingerprintToken) this.fingerprintToken = config.fingerprintToken; } diff --git a/lib/core/log.test.ts b/lib/core/log.test.ts index affdc88..03564ca 100644 --- a/lib/core/log.test.ts +++ b/lib/core/log.test.ts @@ -3,7 +3,7 @@ import { Lacuna } from '../'; let lacuna: Lacuna; beforeAll(() => { - lacuna = new Lacuna({ serverUrl: 'localhost' }); + lacuna = new Lacuna(); }); test('debug', () => { diff --git a/lib/endpoints/buildings/shipyard.test.ts b/lib/endpoints/buildings/shipyard.test.ts index 4042be7..76b3bcc 100644 --- a/lib/endpoints/buildings/shipyard.test.ts +++ b/lib/endpoints/buildings/shipyard.test.ts @@ -21,23 +21,22 @@ beforeAll(async () => { .value(); }); -test.skip('view', async () => { +test('view', async () => { const { result } = await lacuna.shipyard.view({ building_id: int(buildingId) }); expect(result?.building).toBeDefined(); expect(result?.building.name).toBe('Shipyard'); }); -test.skip('viewBuildQueue', async () => { +test('viewBuildQueue', async () => { const { result } = await lacuna.shipyard.viewBuildQueue({ building_id: int(buildingId) }); expect(result?.cost_to_subsidize).toBeDefined(); - expect(result?.fleets_building).toBeDefined(); - expect(result?.number_of_fleets_building).toBeDefined(); + expect(result?.ships_building).toBeDefined(); expect(result?.number_of_ships_building).toBeDefined(); }); -test.skip('getBuildable', async () => { +test('getBuildable', async () => { const { result } = await lacuna.shipyard.getBuildable({ building_id: int(buildingId) }); expect(result?.buildable).toBeDefined(); diff --git a/lib/endpoints/buildings/shipyard.ts b/lib/endpoints/buildings/shipyard.ts index 1dac947..6d5e541 100644 --- a/lib/endpoints/buildings/shipyard.ts +++ b/lib/endpoints/buildings/shipyard.ts @@ -8,19 +8,27 @@ class Shipyard extends Building { } viewBuildQueue(params: SY.ViewBuildQueueParams) { - return this.callWithSession('view_build_queue', params); + return this.callWithSession('view_build_queue', [ + params.building_id, + params.page_number ?? 0, + ]); } subsidizeBuildQueue(params: SY.SubsidizeBuildQueueParams) { - return this.callWithSession('subsidize_build_queue', params); + return this.callWithSession('subsidize_build_queue', [ + params.building_id, + ]); } getBuildable(params: SY.GetBuildableParams) { - return this.callWithSession('get_buildable', params); + return this.callWithSession( + 'get_buildable', + params.tag ? [params.building_id, params.tag] : [params.building_id] + ); } - buildFleet(params: SY.BuildFleetParams) { - return this.callWithSession('build_fleet', params); + buildShip(params: SY.BuildShipParams) { + return this.callWithSession('build_ship', params); } } diff --git a/lib/endpoints/buildings/space-port.test.ts b/lib/endpoints/buildings/space-port.test.ts index ea635f8..87286dc 100644 --- a/lib/endpoints/buildings/space-port.test.ts +++ b/lib/endpoints/buildings/space-port.test.ts @@ -5,77 +5,51 @@ import { int } from '../../core/util'; let lacuna: Lacuna; let buildingId: string; -let homePlanetId: number; -let testPlanetId: number; beforeAll(async () => { lacuna = await getLacuna(); const { result: { empire }, } = await lacuna.empire.getStatus(); - homePlanetId = empire.home_planet_id; const { result: { buildings }, - } = await lacuna.body.getBuildings({ body_id: homePlanetId }); + } = await lacuna.body.getBuildings({ body_id: empire.home_planet_id }); buildingId = _.chain(buildings) .keys() .filter((key) => buildings[key].name === 'Space Port') .first() .value(); - - const testPlanet = _.chain(empire.bodies.colonies) - .filter((colony) => colony.id != homePlanetId) - .first() - .value(); - - if (testPlanet) testPlanetId = testPlanet.id; }); -test.skip('view', async () => { +test('view', async () => { const { result } = await lacuna.spacePort.view({ building_id: int(buildingId) }); - expect(result?.building).toBeDefined(); - expect(result?.building.name).toBe('Space Port'); -}); - -test.skip('viewAllFleets', async () => { - const { result } = await lacuna.spacePort.viewAllFleets({ building_id: int(buildingId) }); - - expect(result?.fleets).toBeDefined(); - expect(result?.number_of_fleets).toBeDefined(); -}); - -test.skip('viewAvailableFleets', async () => { - const { result } = await lacuna.spacePort.viewAvailableFleets({ - target: { body_id: testPlanetId }, - body_id: homePlanetId, - }); - expect(result).toBeDefined(); + expect(result.building).toBeDefined(); + expect(result.building.name).toBe('Space Port'); }); -test.skip('viewUnavailableFleets', async () => { - const { result } = await lacuna.spacePort.viewUnavailableFleets({ - target: { body_id: testPlanetId }, - body_id: homePlanetId, - }); +test('viewAllShips', async () => { + const { result } = await lacuna.spacePort.viewAllShips({ building_id: int(buildingId) }); expect(result).toBeDefined(); + expect(result.ships).toBeDefined(); + expect(result.number_of_ships).toBeDefined(); }); -test.skip('viewOrbitingFleets', async () => { - const { result } = await lacuna.spacePort.viewOrbitingFleets({ - target: { body_id: testPlanetId }, - }); +test('viewOrbitingShips', async () => { + const { result } = await lacuna.spacePort.viewOrbitingShips({ building_id: int(buildingId) }); expect(result).toBeDefined(); + expect(result.number_of_ships).toBeDefined(); + expect(result.ships).toBeDefined(); }); -test.skip('viewIncomingFleets', async () => { - const { result } = await lacuna.spacePort.viewIncomingFleets({ - target: { body_id: testPlanetId }, - }); +test('viewForeignShips', async () => { + const { result } = await lacuna.spacePort.viewForeignShips({ building_id: int(buildingId) }); expect(result).toBeDefined(); + expect(result.number_of_ships).toBeDefined(); + expect(result.ships).toBeDefined(); }); diff --git a/lib/endpoints/buildings/space-port.ts b/lib/endpoints/buildings/space-port.ts index 137979d..6a28f41 100644 --- a/lib/endpoints/buildings/space-port.ts +++ b/lib/endpoints/buildings/space-port.ts @@ -7,35 +7,33 @@ class SpacePort extends Building { super(lacuna, url); } - viewAllFleets(params: SP.ViewAllFleetsParams) { - return this.callWithSession('view_all_fleets', params); + viewAllShips(params: SP.ViewAllShipsParams) { + return this.callWithSession('view_all_ships', [params.building_id]); } - viewTravellingFleets(params: SP.ViewTravellingFleetsParams) { - return this.callWithSession('view_travelling_fleets', params); + viewTravellingShips(params: SP.ViewTravellingShipsParams) { + return this.callWithSession('view_ships_travelling', [ + params.building_id, + params.page_number ?? 0, + ]); } - viewAvailableFleets(params: SP.ViewAvailableFleetsParams) { - return this.callWithSession('view_available_fleets', params); + viewOrbitingShips(params: SP.ViewOrbitingShipsParams) { + return this.callWithSession('view_ships_orbiting', [ + params.building_id, + params.page_number ?? 0, + ]); } - viewUnavailableFleets(params: SP.ViewUnavailableFleetsParams) { - return this.callWithSession( - 'view_unavailable_fleets', - params - ); + viewForeignShips(params: SP.ViewForeignShipsParams) { + return this.callWithSession('view_foreign_ships', [ + params.building_id, + params.page_number ?? 0, + ]); } - viewOrbitingFleets(params: SP.ViewOrbitingFleetsParams) { - return this.callWithSession('view_orbiting_fleets', params); - } - - viewIncomingFleets(params: SP.ViewIncomingFleetsParams) { - return this.callWithSession('view_incoming_fleets', params); - } - - sendFleet(params: SP.SendFleetParams) { - return this.callWithSession('send_fleet', params); + sendShip(params: SP.SendShipParams) { + return this.callWithSession('send_ship', params); } } diff --git a/lib/endpoints/empire.test.ts b/lib/endpoints/empire.test.ts index 33f28d7..9e3a3fd 100644 --- a/lib/endpoints/empire.test.ts +++ b/lib/endpoints/empire.test.ts @@ -2,7 +2,7 @@ import { Lacuna } from '../'; import { getLacuna } from '../__utils__/get-lacuna'; test('login with errors', async () => { - const lacuna = new Lacuna({ serverUrl: 'http://localhost:8080/' }); + const lacuna = new Lacuna(); console.error = jest.fn(); const { error } = await lacuna.empire.login({ @@ -17,9 +17,9 @@ test('login with errors', async () => { }); test('login', async () => { - const lacuna = new Lacuna({ serverUrl: 'http://localhost:8080/' }); + const lacuna = new Lacuna(); const { result } = await lacuna.empire.login({ - name: 'natalie', + name: 'nataliethistime', password: '1234qwer', browser: 'todo', api_key: 'anonymous', @@ -55,7 +55,7 @@ test('getStatus', async () => { expect(result?.empire).toBeDefined(); expect(result?.server).toBeDefined(); - expect(result?.empire.name).toBe('natalie'); + expect(result?.empire.name).toBe('nataliethistime'); }); test('setBoost', async () => { diff --git a/lib/lacuna.test.ts b/lib/lacuna.test.ts index 2a07fd6..0433aba 100644 --- a/lib/lacuna.test.ts +++ b/lib/lacuna.test.ts @@ -15,15 +15,15 @@ const modules = [ test('authenticate', async () => { console.info = jest.fn(); - const lacuna = new Lacuna({ serverUrl: 'http://localhost:8080' }); + const lacuna = new Lacuna(); - await lacuna.authenticate('natalie', '1234qwer'); + await lacuna.authenticate('nataliethistime', '1234qwer'); expect(lacuna.session.get()).not.toEqual(''); }); test('buildingFromUrl', () => { - const lacuna = new Lacuna({ serverUrl: 'localhost' }); + const lacuna = new Lacuna(); const pcc = lacuna.buildingFromUrl('planetarycommand'); @@ -32,13 +32,13 @@ test('buildingFromUrl', () => { }); test('version', () => { - const lacuna = new Lacuna({ serverUrl: 'localhost' }); + const lacuna = new Lacuna(); expect(lacuna.version).toBeDefined(); }); test('modules', () => { - const lacuna = new Lacuna({ serverUrl: '' }); + const lacuna = new Lacuna(); modules.forEach((module) => expect(lacuna[module]).toBeDefined()); }); diff --git a/lib/lacuna.ts b/lib/lacuna.ts index b4f774a..7cb87f5 100644 --- a/lib/lacuna.ts +++ b/lib/lacuna.ts @@ -32,7 +32,7 @@ class Lacuna { stats: Stats; university: Building; - constructor(config: LacunaConfig) { + constructor(config: LacunaConfig = {}) { this.log = new Log(this); this.config = new Config(this, config); this.server = new Server(this); diff --git a/lib/types/index.ts b/lib/types/index.ts index 3b6e308..8a0a593 100644 --- a/lib/types/index.ts +++ b/lib/types/index.ts @@ -18,7 +18,7 @@ export interface LacunaConfig { password?: string; apiKey?: string; fingerprintToken?: string; - serverUrl: string; + serverUrl?: string; } export { Body, Building, Captcha, Empire, EssentiaVein, Shipyard, SpacePort, Stats, Status }; diff --git a/lib/types/shipyard.ts b/lib/types/shipyard.ts index bafb4dc..4cb0388 100644 --- a/lib/types/shipyard.ts +++ b/lib/types/shipyard.ts @@ -42,15 +42,12 @@ export interface FleetBeingWorkedOn { export interface ViewBuildQueueParams { building_id: number; page_number?: number; - items_per_page?: number; - no_paging?: IntBool; } export interface ViewBuildQueueResponse { - number_of_fleets_building: number; number_of_ships_building: number; cost_to_subsidize: number; - fleets_building: Array; + ships_building: Array; } export interface GetBuildableParams { @@ -67,14 +64,14 @@ export interface GetBuildableResponse { }; } -export interface BuildFleetParams { +export interface BuildShipParams { building_ids: number[]; type: string; quantity: number; auto_select: string; } -export interface BuildFleetResponse extends ViewBuildQueueResponse {} +export interface BuildShipResponse extends ViewBuildQueueResponse {} export interface SubsidizeBuildQueueParams { building_id: number; diff --git a/lib/types/space-port.ts b/lib/types/space-port.ts index cc8df25..bce6f5d 100644 --- a/lib/types/space-port.ts +++ b/lib/types/space-port.ts @@ -3,22 +3,23 @@ import { ServerDate, IntBool } from '.'; export type Target = | { body_id: number } | { body_name: string } - | { bookmark: string } | { star_id: number } | { star_name: string } | { x: number; y: number }; export type Paging = { - page_number: number; - items_per_page: number; + page_number?: number; + items_per_page?: number; + no_paging?: IntBool; }; export type Filter = { task?: string; + type?: string; tag?: string; }; -export type Fleet = { +export type Ship = { task: string; id: number; quantity: number; @@ -81,82 +82,54 @@ export type Fleet = { }; }; -export interface ViewAllFleetsParams { +export interface ViewAllShipsParams { building_id: number; paging?: Paging; filter?: Filter; sort?: string; } -export interface ViewAllFleetsResponse { - fleets: Fleet[]; - number_of_fleets: number; +export interface ViewAllShipsResponse { + ships: Ship[]; + number_of_ships: number; } -export interface ViewTravellingFleetsParams { +export interface ViewTravellingShipsParams { building_id: number; - paging?: Paging; - filter?: Filter; - sort?: string; + page_number?: number; } -export interface ViewTravellingFleetsResponse { - travelling: Fleet[]; - number_of_fleets_travelling: number; +export interface ViewTravellingShipsResponse { + ships_travelling: Ship[]; number_of_ships_travelling: number; } -export interface ViewAvailableFleetsParams { - body_id: number; - target: Target; - filter?: Filter; - sort?: string; -} - -export interface ViewAvailableFleetsResponse { - available: Fleet[]; -} - -export interface ViewUnavailableFleetsParams { - body_id: number; - target: Target; - filter?: Filter; - sort?: string; -} - -export interface ViewUnavailableFleetsResponse { - unavailable: Fleet[]; -} - -export interface ViewOrbitingFleetsParams { - target: Target; - filter?: Filter; - sort?: string; +export interface ViewOrbitingShipsParams { + building_id: number; + page_number?: number; } -export interface ViewOrbitingFleetsResponse { - orbiting: Fleet[]; +export interface ViewOrbitingShipsResponse { + ships: Ship[]; + number_of_ships: number; } -export interface ViewIncomingFleetsParams { - target: Target; - filter?: Filter; - sort?: string; +export interface ViewForeignShipsParams { + building_id: number; + page_number?: number; } -export interface ViewIncomingFleetsResponse { - incoming: Fleet[]; - number_of_incoming_fleets: number; - number_of_incoming_ships: number; +export interface ViewForeignShipsResponse { + ships: Ship[]; + number_of_ships: number; } -export interface SendFleetParams { - fleet_id: number; +export interface SendShipParams { + ship_id: number; target: Target; - quantity: number; } -export interface SendFleetResponse { +export interface SendShipResponse { // "id" : "id-goes-here", // "quantity" : 1, // "task" : "Travelling", diff --git a/package-lock.json b/package-lock.json index 1918c1e..de9db29 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@tlecommunity/client", - "version": "0.4.0", + "version": "0.4.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@tlecommunity/client", - "version": "0.4.0", + "version": "0.4.2", "license": "MIT", "dependencies": { "@types/lodash": "^4.14.202", @@ -25,8 +25,8 @@ "vite-plugin-dts": "^3.7.0" }, "engines": { - "node": ">=20", - "npm": ">=8" + "node": ">=22", + "npm": ">=10" } }, "node_modules/@ampproject/remapping": { diff --git a/package.json b/package.json index 785ba3f..2a27230 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "lint": "prettier --check **/*.{ts,tsx,md,js,jsx,css,scss,yml}", "lint:fix": "prettier --write **/*.{ts,tsx,md,js,jsx,css,scss,yml}" }, - "author": "Natalie McCallum ", + "author": "Natalie Rose ", "license": "MIT", "devDependencies": { "@types/jest": "^29.5.11", @@ -36,8 +36,8 @@ "vite-plugin-dts": "^3.7.0" }, "engines": { - "node": ">=20", - "npm": ">=8" + "node": ">=22", + "npm": ">=10" }, "dependencies": { "@types/lodash": "^4.14.202", -- 2.51.2