Compare commits
18
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b2034ebc52 | ||
|
|
837aa60a7d | ||
|
|
7b6a942e0c | ||
|
|
1a1834abc7 | ||
|
|
b5bb0d01ce | ||
|
|
fe23c9ff0f | ||
|
|
e24a5788c0 | ||
|
|
b89d351587 | ||
|
|
034d7a8d94 | ||
|
|
0aca4d63aa | ||
|
|
fb369a1afb | ||
|
|
78961fdb36 | ||
|
|
d2defe4cd3 | ||
|
|
7d117f6809 | ||
|
|
49dfd2ca6e | ||
|
|
65cbcf6e17 | ||
|
|
a56937cee2 | ||
|
|
4b01c320fa |
@@ -247,3 +247,13 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
docker compose -f docker-compose.ci.yml -p flight-ci down --remove-orphans -v || true
|
docker compose -f docker-compose.ci.yml -p flight-ci down --remove-orphans -v || true
|
||||||
docker network remove flight-ci-e2e 2>/dev/null || true
|
docker network remove flight-ci-e2e 2>/dev/null || true
|
||||||
|
|
||||||
|
# The shared runner dind still accumulates between runs what the steps above can't reach:
|
||||||
|
# dangling images/layers from the per-run flight-ops-ci rebuilds, BuildKit cache, and job
|
||||||
|
# containers leaked by interrupted runs. Prune them here (after stack + network cleanup).
|
||||||
|
# Deliberately NO --volumes: the daemon is shared with production and named volumes may hold
|
||||||
|
# other workflows' persistent data — this project's own flight-ci_flight-db volume is already
|
||||||
|
# dropped by the steps above. Non-fatal so a prune failure can never mask or break the run.
|
||||||
|
- name: Prune runner dind leftovers
|
||||||
|
if: always()
|
||||||
|
run: docker system prune -af || echo "::warning::dind prune failed — see logs"
|
||||||
|
|||||||
@@ -1,5 +1,42 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## v1.0.0 — 2026-09-24 14:20
|
||||||
|
- **Multiplayer step 1/12 (ISS-105): `players` table replaces the singleton `account`.** New `players` table (`id TEXT PK`, `provider`, `username`, `cash REAL`, `reputation REAL`) in the raw DDL (`lib/db/client.ts`) and a matching Drizzle entry (`lib/db/schema.ts`; `AccountRow` → `PlayerRow`). **One-time migration**: on every `open()`, if the legacy `account` table still exists (sqlite_master check, same guard style as the v0.12.0 contracts migration) AND `players` is empty, its single row is copied into a seeded local player — id `local`, provider `local`, username `kamilkrzywda` (so a later step can join players↔users on username) with cash/reputation carried over — and `account` is dropped. Idempotent: fresh DBs never have `account`, already-migrated files no longer do either, so it runs exactly once per legacy file. **Fresh worlds**: the DDL no longer creates `account`; first-run seeding (empty-check flipped from `COUNT(*) FROM account` to `players`) inserts the local player row directly with the same starting cash/reputation as before.
|
||||||
|
- **No behavior change — temporary single-player helper.** Every pre-multiplayer read/write of the singleton economy now goes through ONE small module, `lib/db/localPlayer.ts`: `getLocalPlayer(inst)` (resolves the `players` row where id = 'local', throws if missing) and `updateLocalPlayerEconomy(inst, {cash?, reputation?})`. Call sites converted: snapshot (`lib/game/state.ts`), all five actions (`flyPlane` refuel, abandon penalty, buy/sell plane, repair — `lib/game/actions.ts`), the engine's delivery awards + chain top-up + spawn reputation read (`lib/sim/engine.ts`), and the three test hooks (add-cash / set-cash / create-package). The `/api/state` snapshot keeps its exact `account: {cash, reputation}` field name and values, so OpenAPI is untouched — 17 paths, same schemas.
|
||||||
|
- **Tests.** Unit: fresh DB now asserts the seeded local player row (`local`/`local`/`kamilkrzywda`, starting cash/reputation) AND that no `account` table exists; new dedicated migration test builds a minimal legacy file containing only an `account` table and verifies open() copies its row into the local player, drops `account`, and is a no-op on second open. All existing suites (actions, engine, client, buy/sell/abandon routes) now read/write through the helper; the admin rows CRUD test's PK-less-table example moves from `account` to `sim_state` (the only remaining PK-less table), and the admin tables-list expectation swaps `account` → `players`. No new e2e spec — behavior is byte-identical and CI's existing suite covers the UI paths; a fresh-stack boot exercises the new seed path.
|
||||||
|
|
||||||
|
## v0.73.0 — 2026-09-24 12:24
|
||||||
|
- **New-package toasts removed.** The client-side snapshot diff in `lib/deriveEvents.ts` no longer emits "New package available" info toasts when a contract appears (the user was spammed by them); the first-snapshot guard and every other event type — delivered, expired, landed, bought, sold — are unchanged.
|
||||||
|
|
||||||
|
## v0.72.0 — 2026-09-24 11:44
|
||||||
|
- **Admin login fixed.** The seeded admin's scrypt digest in `lib/db/client.ts` was computed with different parameters than the verifier (`verifyPassword()` passes the salt as a plain string to `scryptSync(pw, saltHex, 32)`), so real logins failed with 401 "invalid credentials" since v0.71.0. The seed now carries a digest produced by exactly that call (the plaintext still exists nowhere in code, tests or comments). Because the seed is `INSERT … WHERE NOT EXISTS`, pre-existing databases keep their old row — so every `open()` also runs an idempotent rotation (`UPDATE users SET password_hash = ? WHERE id = 'admin-kamilkrzywda' AND password_hash != ?`): a no-op once healed, it repairs legacy rows at boot and is durable on the next persist. Unit tests cover the fresh seed with the new digest plus the rotate-on-open path (legacy file heals to the current digest; second open is a no-op).
|
||||||
|
|
||||||
|
## v0.71.0 — 2026-09-24 09:18
|
||||||
|
- **Admin panel.** A new "Admin" button on the right of the top bar opens a reusable modal (`components/Modal.tsx` — fixed overlay at z-index 60, above the z-50 toast stack; centered `role="dialog"` panel; closes on Escape and backdrop click) hosting `components/AdminPanel.tsx`. No new URL routes: everything lives behind that one button + modal.
|
||||||
|
- **Users + sessions tables.** New `users` (id PK, unique username, scrypt `salt$hex` password_hash, admin flag, created_at) and `sessions` (UUID id, user_id, 7-day expires_at) tables in the raw DDL (`lib/db/client.ts`) and typed Drizzle entries (`lib/db/schema.ts`). An **idempotent seeded admin** is inserted on every `open()` — user id `admin-kamilkrzywda`, username `kamilkrzywda`, admin=1, hash-only (the plaintext exists nowhere in code, tests or comments) — guarded by `WHERE NOT EXISTS` so pre-existing production DBs gain exactly one row and never a duplicate. The users table is also the foundation for multiplayer auth (#105/#107).
|
||||||
|
- **Auth API.** `POST /api/login {username,password}` verifies with node:crypto `scryptSync` + `timingSafeEqual`; an unknown username still runs one full scrypt against a fixed dummy digest so timing stays uniform. Success mints a 7-day session (lazy cleanup of expired rows) and returns `{sessionId, user:{username,admin}}`. `POST /api/logout` deletes the session named by the new `X-Flight-Session` header (idempotent); `GET /api/me` resolves it to the current user or 401. The client stores the sessionId in localStorage (`flight.session`) and sends the header on every authenticated request.
|
||||||
|
- **Generic whole-database CRUD behind the admin flag.** `lib/auth.ts`'s `requireAdmin` guard (no/expired session → 401, non-admin → 403) runs before any input is touched on: `GET /api/admin/tables` (user tables, sqlite_% excluded) and `GET|PUT|POST|DELETE /api/admin/tables/{name}/rows` — rows carry their rowid as `__rowid` so the PK-less tables (account, sim_state) are editable like any other; PUT updates only changed cells, POST inserts, DELETE removes by rowid. SQL safety: table names quoted only after sqlite_master validation, column names validated against PRAGMA table_info, values ALWAYS bound as parameters — no user input is ever concatenated into SQL.
|
||||||
|
- **UI.** The Admin modal shows a login form (wrong credentials show an error line), a "not an admin" notice for authenticated non-admins, or the grid: table list → per-table editable rows (each cell an input; per-row Save/Delete, "+ Add row", Refresh) with logout in the header area. Deliberately plain — it's a dev tool surface, not a product feature.
|
||||||
|
- **Test hook.** `POST /api/test/admin-session` (FLIGHT_TEST_HOOKS=1 gate like its siblings) mints a session for the seeded admin server-side and returns `{sessionId}` — so the e2e suite can exercise the authenticated panel WITHOUT the real admin password ever appearing in test code.
|
||||||
|
- **OpenAPI.** Five new paths documented (`/api/login`, `/api/logout`, `/api/me`, `/api/admin/tables`, `/api/admin/tables/{name}/rows` with all four verbs) plus their request/response schemas; endpoint count twelve → seventeen everywhere it is asserted (unit + e2e).
|
||||||
|
- **Tests.** Unit: the idempotent admin seed (fresh DB, reopen, and a legacy pre-v0.71.0 file), login success/wrong-password/unknown-username/malformed bodies with an in-test scrypt hash for a self-created user (the real admin's plaintext is never referenced), logout idempotency, /api/me with missing/unknown/expired/live sessions, the guard ladder (401 no header, 401 expired, 403 non-admin) and the full CRUD validation matrix (rows incl. `__rowid` for account, PUT-verified-by-refetch, POST+DELETE round-trip, unknown table 404, unknown column/bad limit/missing rowid 400). E2E (`e2e/admin.spec.ts`, CI-only): open modal → login form → wrong creds error → hook-minted session via localStorage → table list incl. packages/users → edit a cell + Save verified by an independent re-fetch → add + delete a users row → logout back to the login form.
|
||||||
|
|
||||||
|
## v0.70.0 — 2026-09-23 22:07
|
||||||
|
- **Default map view is now the whole world.** The initial camera in `components/Map.tsx` moves from the Europe overview `[10,52]` z4 to null island `[0,0]` (renamed constant `WORLD_CENTER`) at zoom 2 — at z2 the world is 2048 px wide and the Africa+Europe bounding box (lat −35..+71, lon −18..+52) spans ~800 px vertically in Web Mercator, so both continents are fully visible on a typical desktop map pane. `MIN_ZOOM` is lowered 3 → 0: when fully zoomed out the whole earth (512 px world) fits any viewport; `MAX_ZOOM = 11` and the flat-2D view are unchanged.
|
||||||
|
- **E2E.** The new default view shows both Africa + Europe with overlapping markers — LFRS's nearest neighbour (LFRB Brest, 254 km) is only ~13–19 px away at z2, so every marker-click spec now frames its target first: `e2e/map.spec.ts` gains a shared `frameLfrs` helper (`jumpTo` z5 + wait until the marker renders), used by all three of its click tests; `e2e/map-interactions.spec.ts` and `e2e/relocation.spec.ts` frame LFRS at z5 before their popup clicks. The plane-marker test in `e2e/map-interactions.spec.ts` fits EDDF+LEMD into the viewport first — `queryRenderedFeatures` is viewport-scoped and EDDF (50°N) sits right at the edge of the new default view. `e2e/hover.spec.ts`: the antimeridian test's `setMinZoom(0)` workaround is deleted — minZoom is natively 0 now, so `fitToAirports` can reach the z≈1 that EDDF→NFTF needs without lifting any floor. New assertion in `e2e/map.spec.ts` pins the initial camera to [0,0] z2; the wheel-clamp spec's MIN_ZOOM mirror is updated 3 → 0 (its zoom-out side now clamps at 0).
|
||||||
|
|
||||||
|
## v0.69.0 — 2026-09-23 21:54
|
||||||
|
- **Job ignore removed end-to-end.** The "Ignore" button on open jobs (v0.29.0, ISS-047 part B) is gone with everything behind it: the `POST /api/packages/{id}/ignore` route, the `ignorePackage` action, and `'ignored'` from the package status enum (schema, snapshot type, OpenAPI — now twelve endpoints). Packages can only be loaded, delivered, expired, or abandoned.
|
||||||
|
- **Legacy 'ignored' rows self-heal.** Production databases already contain rows with `status='ignored'`; nothing ever cleaned them up (`expireOpenPackages` only selected `'open'`). The sweep now selects `IN ('open','ignored')` and flips any row past `createdRealMs + JOB_LIFETIME_MS` to `'expired'`, so every legacy row heals on the first tick after its lifetime lapses (in practice: the first tick after deploy) and no new ones can ever be created. Reads before that first tick are safe: Drizzle does no runtime validation, nothing renders a non-open/loaded/expired package, and `GET /api/state` ticks first anyway.
|
||||||
|
- **Tests.** Unit: the `ignorePackage` suite is deleted; terminal-status fixtures drop their redundant `'ignored'` rows (delivered/abandoned already cover "terminal never flips"); the frozen-top-up drain now flips to `'expired'` mirroring `expireOpenPackages`; the taken-slot cooldown ladder keeps two stamped slots, both `'loaded'`. E2E: the Ignore UI test is deleted; `sim.spec.ts`'s soft-lock regression drains via the existing `/api/test/expire-package` hook (loading can't drain a pool — the starter's payload fits only the lightest band) and `expiry.spec.ts` cleans up its created packages through the same hook. OpenAPI endpoint count thirteen → twelve everywhere it is asserted.
|
||||||
|
|
||||||
|
## v0.68.0 — 2026-09-23 20:32
|
||||||
|
- **Special remote airports re-curated per #144.** The old remote pass kept EVERY non-large fixed-wing row with no large airport within 1000 km, so regions without big cities (central Australia, Canada edges) got filled with dozens of tiny strips. `scripts/build-world-airports.mjs` now greedily thins the same candidate pool to one special per ~1000 km region: candidates are sorted by priority (scheduled service first, then type rank medium < small < seaplane, then numeric id) and a candidate is accepted only if it is at least `REMOTE_RADIUS_KM` from EVERY already-accepted special — no special airport within 1000 km of another. This subsumes the old 40 km remote clustering (deleted). Regenerated `data/airports_world.csv`: 1483 → 1161 rows (1119 large unchanged, specials 364 → 42; min pairwise special distance 1001.6 km).
|
||||||
|
- **Tests.** New committed-dataset invariant in `lib/airports.test.ts` (same style as the existing remote-rule test): every pair of non-large rows is at least `REMOTE_RADIUS_KM` apart (pairwise haversine, O(n²) — n≈42). The existing "no large airport within 1000 km" invariant stays and still holds. No runtime code changes in `lib/airports.ts`.
|
||||||
|
|
||||||
|
## v0.67.0 — 2026-09-23 18:03
|
||||||
|
- **Prune runner dind leftovers after e2e.** The CI runner's full-dind daemon is shared with production and other workflows, so between runs it accumulates what the existing cleanup steps can't reach: dangling images/layers from the per-run `flight-ops-ci` rebuilds, BuildKit cache (persists by design), and job containers leaked by interrupted runs. A new non-fatal "Prune runner dind leftovers" step (`if: always()`, placed after the existing "Cleanup e2e stack + network") runs `docker system prune -af || echo "::warning::dind prune failed — see logs"` so a prune failure can never mask or break the run's real result. Deliberately NO `--volumes`: named volumes on the shared daemon may hold other workflows' persistent data — this project's own `flight-ci_flight-db` volume is already dropped by the existing cleanup steps. No app/TS changes; CI validates the workflow itself.
|
||||||
|
|
||||||
## v0.66.0 — 2026-09-23 17:06
|
## v0.66.0 — 2026-09-23 17:06
|
||||||
- **E2E results in the Gitea job summary (#141).** The run page's "Job summaries" panel showed vitest results (vitest's built-in `github-actions` reporter auto-appends `$GITHUB_STEP_SUMMARY` when `GITHUB_ACTIONS=true`) but nothing about the Playwright suite, so a failed e2e run required digging into raw logs to see which specs broke. The CI E2E step now also runs Playwright's built-in `json` reporter (`--reporter=list,json`, output pinned to git-ignored `test-results/e2e.json` via `PLAYWRIGHT_JSON_OUTPUT_FILE` — no new dependencies, no config/TS changes), and a new non-fatal "E2E job summary" step (`if: always()`) parses that report with an inline node script and appends spec-level passed/failed/skipped counts plus the file + title of every failed spec to `$GITHUB_STEP_SUMMARY` — mirroring exactly how vitest gets there. The append is guarded (`|| true`, missing/malformed report = silent no-op) so it can never fail or mask the e2e step's real exit code; test behavior, timeouts, workers and retries are untouched.
|
- **E2E results in the Gitea job summary (#141).** The run page's "Job summaries" panel showed vitest results (vitest's built-in `github-actions` reporter auto-appends `$GITHUB_STEP_SUMMARY` when `GITHUB_ACTIONS=true`) but nothing about the Playwright suite, so a failed e2e run required digging into raw logs to see which specs broke. The CI E2E step now also runs Playwright's built-in `json` reporter (`--reporter=list,json`, output pinned to git-ignored `test-results/e2e.json` via `PLAYWRIGHT_JSON_OUTPUT_FILE` — no new dependencies, no config/TS changes), and a new non-fatal "E2E job summary" step (`if: always()`) parses that report with an inline node script and appends spec-level passed/failed/skipped counts plus the file + title of every failed spec to `$GITHUB_STEP_SUMMARY` — mirroring exactly how vitest gets there. The append is guarded (`|| true`, missing/malformed report = silent no-op) so it can never fail or mask the e2e step's real exit code; test behavior, timeouts, workers and retries are untouched.
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,184 @@
|
|||||||
|
import fs from 'node:fs/promises';
|
||||||
|
import os from 'node:os';
|
||||||
|
import path from 'node:path';
|
||||||
|
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
||||||
|
import { getGameDb } from '@/lib/db/client';
|
||||||
|
import { createSession } from '@/lib/auth';
|
||||||
|
import { DELETE, GET, POST, PUT } from './route';
|
||||||
|
|
||||||
|
// v0.71.0 — generic DB CRUD route tests: rows fetch (incl. __rowid for PK-less tables),
|
||||||
|
// parameterized update/insert/delete, and the validation ladder (404 unknown table, 400 bad input).
|
||||||
|
|
||||||
|
let dir: string;
|
||||||
|
let adminSession = '';
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
dir = await fs.mkdtemp(path.join(os.tmpdir(), 'flight-admin-rows-'));
|
||||||
|
process.env.FLIGHT_DB_PATH = path.join(dir, 'rows.db');
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
delete process.env.FLIGHT_DB_PATH;
|
||||||
|
await fs.rm(dir, { recursive: true, force: true });
|
||||||
|
});
|
||||||
|
|
||||||
|
// adminSession is minted in beforeAll, so the header helpers read it at call time.
|
||||||
|
const authHeaders = () => ({ 'X-Flight-Session': adminSession });
|
||||||
|
|
||||||
|
// The route handlers take Next.js's dynamic-segment context; unit tests supply it directly.
|
||||||
|
const ctx = (name: string) => ({ params: Promise.resolve({ name }) });
|
||||||
|
|
||||||
|
const getRows = (name: string, query = '') =>
|
||||||
|
GET(new Request(`http://localhost/api/admin/tables/${encodeURIComponent(name)}/rows${query}`, { headers: authHeaders() }), ctx(name));
|
||||||
|
const putRow = (name: string, body: unknown) =>
|
||||||
|
PUT(
|
||||||
|
new Request(`http://localhost/api/admin/tables/${encodeURIComponent(name)}/rows`, {
|
||||||
|
method: 'PUT',
|
||||||
|
headers: { ...authHeaders(), 'content-type': 'application/json' },
|
||||||
|
body: JSON.stringify(body),
|
||||||
|
}),
|
||||||
|
ctx(name),
|
||||||
|
);
|
||||||
|
const postRow = (name: string, body: unknown) =>
|
||||||
|
POST(
|
||||||
|
new Request(`http://localhost/api/admin/tables/${encodeURIComponent(name)}/rows`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { ...authHeaders(), 'content-type': 'application/json' },
|
||||||
|
body: JSON.stringify(body),
|
||||||
|
}),
|
||||||
|
ctx(name),
|
||||||
|
);
|
||||||
|
const deleteRow = (name: string, rowid: number | null) =>
|
||||||
|
DELETE(
|
||||||
|
new Request(
|
||||||
|
`http://localhost/api/admin/tables/${encodeURIComponent(name)}/rows${rowid === null ? '' : `?rowid=${rowid}`}`,
|
||||||
|
{ method: 'DELETE', headers: authHeaders() },
|
||||||
|
),
|
||||||
|
ctx(name),
|
||||||
|
);
|
||||||
|
|
||||||
|
describe('admin rows CRUD', () => {
|
||||||
|
beforeAll(async () => {
|
||||||
|
adminSession = await createSession(await getGameDb(), 'admin-kamilkrzywda');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('GET returns columns + rows with __rowid for the PK-less sim_state table', async () => {
|
||||||
|
const res = await getRows('sim_state');
|
||||||
|
expect(res.status).toBe(200);
|
||||||
|
const body = (await res.json()) as { columns: string[]; rows: Array<Record<string, unknown>> };
|
||||||
|
expect(body.columns[0]).toBe('__rowid');
|
||||||
|
for (const col of ['clock_ms', 'time_scale']) expect(body.columns).toContain(col);
|
||||||
|
expect(body.rows).toHaveLength(1); // the single seeded sim_state row
|
||||||
|
expect(typeof body.rows[0].__rowid).toBe('number');
|
||||||
|
expect(typeof body.rows[0].clock_ms).toBe('number');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('PUT updates a cell and the change survives a re-fetch', async () => {
|
||||||
|
const before = await (await getRows('sim_state')).json();
|
||||||
|
const originalClockMs = (before as { rows: Array<Record<string, unknown>> }).rows[0].clock_ms;
|
||||||
|
|
||||||
|
const res = await putRow('sim_state', { rowid: 1, values: { clock_ms: 424_242 } });
|
||||||
|
expect(res.status).toBe(200);
|
||||||
|
expect(await res.json()).toEqual({ ok: true });
|
||||||
|
|
||||||
|
// Re-fetch through the same route — the persisted value is back.
|
||||||
|
const body = await (await getRows('sim_state')).json();
|
||||||
|
expect((body as { rows: Array<Record<string, unknown>> }).rows[0].clock_ms).toBe(424_242);
|
||||||
|
|
||||||
|
// Restore the original clock so later tests see a sane world.
|
||||||
|
const restore = await putRow('sim_state', { rowid: 1, values: { clock_ms: originalClockMs } });
|
||||||
|
expect(restore.status).toBe(200);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('PUT rejects unknown columns and empty values with 400', async () => {
|
||||||
|
const badCol = await putRow('sim_state', { rowid: 1, values: { no_such_column: 1 } });
|
||||||
|
expect(badCol.status).toBe(400);
|
||||||
|
expect(((await badCol.json()) as { error: string }).error).toMatch(/unknown column/i);
|
||||||
|
|
||||||
|
const empty = await putRow('sim_state', { rowid: 1, values: {} });
|
||||||
|
expect(empty.status).toBe(400);
|
||||||
|
|
||||||
|
const noRowid = await putRow('sim_state', { values: { clock_ms: 1 } });
|
||||||
|
expect(noRowid.status).toBe(400);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('POST inserts a row and DELETE removes it again (users table)', async () => {
|
||||||
|
const created = await postRow('users', {
|
||||||
|
values: { id: 'user-crud-test', username: 'crud-test-user', password_hash: 'aa$bb', created_at: Date.now() },
|
||||||
|
});
|
||||||
|
expect(created.status).toBe(200);
|
||||||
|
const body = (await created.json()) as { ok: boolean; rowid: number };
|
||||||
|
expect(body.ok).toBe(true);
|
||||||
|
expect(Number.isInteger(body.rowid)).toBe(true);
|
||||||
|
|
||||||
|
// Visible via GET…
|
||||||
|
let list = await (await getRows('users')).json();
|
||||||
|
const rows = (list as { rows: Array<Record<string, unknown>> }).rows;
|
||||||
|
expect(rows.some((r) => r.username === 'crud-test-user')).toBe(true);
|
||||||
|
|
||||||
|
// …and gone after DELETE.
|
||||||
|
const del = await deleteRow('users', body.rowid);
|
||||||
|
expect(del.status).toBe(200);
|
||||||
|
list = await (await getRows('users')).json();
|
||||||
|
expect((list as { rows: Array<Record<string, unknown>> }).rows.some((r) => r.username === 'crud-test-user')).toBe(false);
|
||||||
|
|
||||||
|
// DELETE is idempotent.
|
||||||
|
const again = await deleteRow('users', body.rowid);
|
||||||
|
expect(again.status).toBe(200);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('POST rejects unknown columns and empty values with 400', async () => {
|
||||||
|
const badCol = await postRow('users', { values: { id: 'x', no_such_column: 1 } });
|
||||||
|
expect(badCol.status).toBe(400);
|
||||||
|
expect(((await badCol.json()) as { error: string }).error).toMatch(/unknown column/i);
|
||||||
|
|
||||||
|
const empty = await postRow('users', { values: {} });
|
||||||
|
expect(empty.status).toBe(400);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('DELETE requires an integer rowid query parameter', async () => {
|
||||||
|
const missing = await deleteRow('users', null);
|
||||||
|
expect(missing.status).toBe(400);
|
||||||
|
const bad = await DELETE(
|
||||||
|
new Request('http://localhost/api/admin/tables/users/rows?rowid=abc', { method: 'DELETE', headers: authHeaders() }),
|
||||||
|
ctx('users'),
|
||||||
|
);
|
||||||
|
expect(bad.status).toBe(400);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns 404 for an unknown table on every verb', async () => {
|
||||||
|
const g = await getRows('no_such_table');
|
||||||
|
expect(g.status).toBe(404);
|
||||||
|
const p = await putRow('no_such_table', { rowid: 1, values: { x: 1 } });
|
||||||
|
expect(p.status).toBe(404);
|
||||||
|
const i = await postRow('no_such_table', { values: { x: 1 } });
|
||||||
|
expect(i.status).toBe(404);
|
||||||
|
const d = await deleteRow('no_such_table', 1);
|
||||||
|
expect(d.status).toBe(404);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('rejects a non-integer limit with 400 and caps at 1000', async () => {
|
||||||
|
const bad = await getRows('users', '?limit=abc');
|
||||||
|
expect(bad.status).toBe(400);
|
||||||
|
const capped = await getRows('users', '?limit=999999');
|
||||||
|
expect(capped.status).toBe(200);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('keeps the guard in front of everything: no header → 401, non-admin → 403', async () => {
|
||||||
|
const noHeader = await GET(new Request('http://localhost/api/admin/tables/users/rows'), ctx('users'));
|
||||||
|
expect(noHeader.status).toBe(401);
|
||||||
|
|
||||||
|
const inst = await getGameDb();
|
||||||
|
inst.raw.run(
|
||||||
|
`INSERT INTO users (id, username, password_hash, admin, created_at)
|
||||||
|
SELECT 'user-rows-nonadmin', 'rows-nonadmin', 'aa$bb', 0, ? WHERE NOT EXISTS (SELECT 1 FROM users WHERE id = 'user-rows-nonadmin')`,
|
||||||
|
[Date.now()],
|
||||||
|
);
|
||||||
|
const nonAdminSession = await createSession(inst, 'user-rows-nonadmin');
|
||||||
|
const forbidden = await GET(
|
||||||
|
new Request('http://localhost/api/admin/tables/users/rows', { headers: { 'X-Flight-Session': nonAdminSession } }),
|
||||||
|
ctx('users'),
|
||||||
|
);
|
||||||
|
expect(forbidden.status).toBe(403);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,219 @@
|
|||||||
|
import { persist } from '@/lib/db/client';
|
||||||
|
import type { GameDb } from '@/lib/db/client';
|
||||||
|
import { requireAdmin } from '@/lib/auth';
|
||||||
|
|
||||||
|
// v0.71.0 — generic whole-database CRUD for the Admin modal (admin only, guarded BEFORE any
|
||||||
|
// user input is touched). SQL safety: table names are quoted only after validation against
|
||||||
|
// sqlite_master, column names only after validation against PRAGMA table_info, and VALUES ARE
|
||||||
|
// ALWAYS BOUND AS PARAMETERS — no user input is ever concatenated into a SQL string.
|
||||||
|
|
||||||
|
const DEFAULT_LIMIT = 500;
|
||||||
|
const MAX_LIMIT = 1000;
|
||||||
|
|
||||||
|
function quoteIdent(name: string): string {
|
||||||
|
return '"' + name.replace(/"/g, '""') + '"';
|
||||||
|
}
|
||||||
|
|
||||||
|
// The app's own tables (sqlite_% internals excluded) — the only names ever accepted.
|
||||||
|
function tableNames(inst: GameDb): Set<string> {
|
||||||
|
const res = inst.raw.exec("SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'");
|
||||||
|
return new Set(res[0].values.map((r) => String(r[0])));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Column names of a validated table (name already checked against sqlite_master).
|
||||||
|
function columnsOf(inst: GameDb, name: string): string[] {
|
||||||
|
const res = inst.raw.exec(`PRAGMA table_info('${name.replace(/'/g, "''")}')`);
|
||||||
|
return res[0].values.map((r) => String(r[1]));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parameterized execute — the only way values reach SQL in this file.
|
||||||
|
function run(inst: GameDb, sql: string, values: unknown[]): void {
|
||||||
|
inst.raw.run(sql, values as never[]);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function readBody(req: Request): Promise<Record<string, unknown> | Response> {
|
||||||
|
let body: unknown;
|
||||||
|
try {
|
||||||
|
const text = await req.text();
|
||||||
|
body = text ? JSON.parse(text) : undefined;
|
||||||
|
} catch {
|
||||||
|
return Response.json({ error: 'invalid JSON body' }, { status: 400 });
|
||||||
|
}
|
||||||
|
if (typeof body !== 'object' || body === null || Array.isArray(body)) {
|
||||||
|
return Response.json({ error: 'body must be a JSON object' }, { status: 400 });
|
||||||
|
}
|
||||||
|
const input = body as Record<string, unknown>;
|
||||||
|
for (const key of Object.keys(input)) {
|
||||||
|
if (!ALLOWED_BODY_FIELDS.has(key)) {
|
||||||
|
return Response.json({ error: `unknown field "${key}"` }, { status: 400 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Per-method top-level body fields (strict, like the /api/test/* hooks).
|
||||||
|
const ALLOWED_BODY_FIELDS = new Set(['rowid', 'values']);
|
||||||
|
|
||||||
|
function valuesObject(input: Record<string, unknown>): Record<string, unknown> | Response {
|
||||||
|
const values = input.values;
|
||||||
|
if (typeof values !== 'object' || values === null || Array.isArray(values)) {
|
||||||
|
return Response.json({ error: 'values must be a JSON object of column → value' }, { status: 400 });
|
||||||
|
}
|
||||||
|
return values as Record<string, unknown>;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Constraint violations (NOT NULL / UNIQUE) are the expected failure mode of a dev-tool edit;
|
||||||
|
// anything else is a server error.
|
||||||
|
function sqlError(err: unknown): Response {
|
||||||
|
const msg = err instanceof Error ? err.message : String(err);
|
||||||
|
if (/NOT NULL|UNIQUE|constraint failed/i.test(msg)) {
|
||||||
|
return Response.json({ error: `database constraint: ${msg}` }, { status: 409 });
|
||||||
|
}
|
||||||
|
console.error('admin rows route failed', err);
|
||||||
|
return Response.json({ error: 'database error' }, { status: 500 });
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET /api/admin/tables/{name}/rows?limit=500 — column headers + up to `limit` rows (default
|
||||||
|
// 500, cap 1000). rowid is exposed as __rowid so the PK-less tables (sim_state) are editable
|
||||||
|
// like any other. Unknown table → 404; bad limit → 400.
|
||||||
|
export async function GET(req: Request, ctx: { params: Promise<{ name: string }> }) {
|
||||||
|
const guard = await requireAdmin(req);
|
||||||
|
if (!guard.ok) return guard.response;
|
||||||
|
|
||||||
|
const { name } = await ctx.params;
|
||||||
|
if (!tableNames(guard.inst).has(name)) {
|
||||||
|
return Response.json({ error: 'unknown table' }, { status: 404 });
|
||||||
|
}
|
||||||
|
let limit = DEFAULT_LIMIT;
|
||||||
|
const limitParam = new URL(req.url).searchParams.get('limit');
|
||||||
|
if (limitParam !== null) {
|
||||||
|
limit = Number(limitParam);
|
||||||
|
if (!Number.isInteger(limit) || limit < 1) {
|
||||||
|
return Response.json({ error: 'limit must be a positive integer' }, { status: 400 });
|
||||||
|
}
|
||||||
|
limit = Math.min(limit, MAX_LIMIT);
|
||||||
|
}
|
||||||
|
|
||||||
|
const cols = columnsOf(guard.inst, name);
|
||||||
|
const stmt = guard.inst.raw.prepare(`SELECT rowid AS __rowid, * FROM ${quoteIdent(name)} LIMIT ?`);
|
||||||
|
try {
|
||||||
|
stmt.bind([limit]);
|
||||||
|
const rows: Array<Record<string, unknown>> = [];
|
||||||
|
while (stmt.step()) rows.push(stmt.getAsObject() as Record<string, unknown>);
|
||||||
|
return Response.json({ columns: ['__rowid', ...cols], rows });
|
||||||
|
} catch (err) {
|
||||||
|
return sqlError(err);
|
||||||
|
} finally {
|
||||||
|
stmt.free();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// PUT /api/admin/tables/{name}/rows — body { rowid, values: { col: value } }. Updates only the
|
||||||
|
// given columns of that row. Unknown table → 404; unknown column or non-integer rowid or empty
|
||||||
|
// values → 400.
|
||||||
|
export async function PUT(req: Request, ctx: { params: Promise<{ name: string }> }) {
|
||||||
|
const guard = await requireAdmin(req);
|
||||||
|
if (!guard.ok) return guard.response;
|
||||||
|
|
||||||
|
const input = await readBody(req);
|
||||||
|
if (input instanceof Response) return input;
|
||||||
|
const rowid = input.rowid;
|
||||||
|
if (!Number.isInteger(rowid)) {
|
||||||
|
return Response.json({ error: 'rowid is required and must be an integer' }, { status: 400 });
|
||||||
|
}
|
||||||
|
const values = await valuesObject(input);
|
||||||
|
if (values instanceof Response) return values;
|
||||||
|
|
||||||
|
const { name } = await ctx.params;
|
||||||
|
if (!tableNames(guard.inst).has(name)) {
|
||||||
|
return Response.json({ error: 'unknown table' }, { status: 404 });
|
||||||
|
}
|
||||||
|
const cols = columnsOf(guard.inst, name);
|
||||||
|
for (const col of Object.keys(values)) {
|
||||||
|
if (!cols.includes(col)) {
|
||||||
|
return Response.json({ error: `unknown column "${col}"` }, { status: 400 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (Object.keys(values).length === 0) {
|
||||||
|
return Response.json({ error: 'values must contain at least one column' }, { status: 400 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const setClause = Object.keys(values).map((c) => `${quoteIdent(c)} = ?`).join(', ');
|
||||||
|
try {
|
||||||
|
run(guard.inst, `UPDATE ${quoteIdent(name)} SET ${setClause} WHERE rowid = ?`, [
|
||||||
|
...Object.values(values),
|
||||||
|
rowid,
|
||||||
|
]);
|
||||||
|
await persist(guard.inst);
|
||||||
|
return Response.json({ ok: true });
|
||||||
|
} catch (err) {
|
||||||
|
return sqlError(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// POST /api/admin/tables/{name}/rows — body { values: { col: value } }. Inserts a new row with
|
||||||
|
// exactly the given columns (others take their defaults or NULL). Returns the new rowid.
|
||||||
|
export async function POST(req: Request, ctx: { params: Promise<{ name: string }> }) {
|
||||||
|
const guard = await requireAdmin(req);
|
||||||
|
if (!guard.ok) return guard.response;
|
||||||
|
|
||||||
|
const input = await readBody(req);
|
||||||
|
if (input instanceof Response) return input;
|
||||||
|
const values = await valuesObject(input);
|
||||||
|
if (values instanceof Response) return values;
|
||||||
|
if (Object.keys(values).length === 0) {
|
||||||
|
return Response.json({ error: 'values must contain at least one column' }, { status: 400 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const { name } = await ctx.params;
|
||||||
|
if (!tableNames(guard.inst).has(name)) {
|
||||||
|
return Response.json({ error: 'unknown table' }, { status: 404 });
|
||||||
|
}
|
||||||
|
const cols = columnsOf(guard.inst, name);
|
||||||
|
for (const col of Object.keys(values)) {
|
||||||
|
if (!cols.includes(col)) {
|
||||||
|
return Response.json({ error: `unknown column "${col}"` }, { status: 400 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const keys = Object.keys(values);
|
||||||
|
try {
|
||||||
|
run(
|
||||||
|
guard.inst,
|
||||||
|
`INSERT INTO ${quoteIdent(name)} (${keys.map(quoteIdent).join(', ')}) VALUES (${keys.map(() => '?').join(', ')})`,
|
||||||
|
Object.values(values),
|
||||||
|
);
|
||||||
|
// Read the new rowid BEFORE persist(): sql.js's export() (inside persist) resets
|
||||||
|
// last_insert_rowid to 0 on this connection.
|
||||||
|
const res = guard.inst.raw.exec('SELECT last_insert_rowid()');
|
||||||
|
await persist(guard.inst);
|
||||||
|
return Response.json({ ok: true, rowid: Number(res[0].values[0][0]) });
|
||||||
|
} catch (err) {
|
||||||
|
return sqlError(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DELETE /api/admin/tables/{name}/rows?rowid=N — deletes that one row. Unknown table → 404;
|
||||||
|
// missing/non-integer rowid → 400. Deleting a non-existent rowid is still 200 (idempotent).
|
||||||
|
export async function DELETE(req: Request, ctx: { params: Promise<{ name: string }> }) {
|
||||||
|
const guard = await requireAdmin(req);
|
||||||
|
if (!guard.ok) return guard.response;
|
||||||
|
|
||||||
|
const { name } = await ctx.params;
|
||||||
|
if (!tableNames(guard.inst).has(name)) {
|
||||||
|
return Response.json({ error: 'unknown table' }, { status: 404 });
|
||||||
|
}
|
||||||
|
const rowidParam = new URL(req.url).searchParams.get('rowid');
|
||||||
|
const rowid = Number(rowidParam);
|
||||||
|
if (rowidParam === null || !Number.isInteger(rowid)) {
|
||||||
|
return Response.json({ error: 'rowid query parameter is required and must be an integer' }, { status: 400 });
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
run(guard.inst, `DELETE FROM ${quoteIdent(name)} WHERE rowid = ?`, [rowid]);
|
||||||
|
await persist(guard.inst);
|
||||||
|
return Response.json({ ok: true });
|
||||||
|
} catch (err) {
|
||||||
|
return sqlError(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
import fs from 'node:fs/promises';
|
||||||
|
import os from 'node:os';
|
||||||
|
import path from 'node:path';
|
||||||
|
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
||||||
|
import { getGameDb } from '@/lib/db/client';
|
||||||
|
import { createSession } from '@/lib/auth';
|
||||||
|
import { GET } from './route';
|
||||||
|
|
||||||
|
// v0.71.0 — admin guard + table list tests: no/expired session → 401, non-admin → 403,
|
||||||
|
// admin passes and sees every user table (sqlite_% excluded).
|
||||||
|
|
||||||
|
let dir: string;
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
dir = await fs.mkdtemp(path.join(os.tmpdir(), 'flight-admin-tables-'));
|
||||||
|
process.env.FLIGHT_DB_PATH = path.join(dir, 'tables.db');
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
delete process.env.FLIGHT_DB_PATH;
|
||||||
|
await fs.rm(dir, { recursive: true, force: true });
|
||||||
|
});
|
||||||
|
|
||||||
|
const get = (sessionId?: string) =>
|
||||||
|
GET(
|
||||||
|
new Request('http://localhost/api/admin/tables', {
|
||||||
|
headers: sessionId ? { 'X-Flight-Session': sessionId } : undefined,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
async function makeUser(username: string, admin: number): Promise<string> {
|
||||||
|
const inst = await getGameDb();
|
||||||
|
const id = `user-${username}`;
|
||||||
|
inst.raw.run(
|
||||||
|
`INSERT INTO users (id, username, password_hash, admin, created_at)
|
||||||
|
SELECT ?, ?, 'aa$bb', ?, ? WHERE NOT EXISTS (SELECT 1 FROM users WHERE id = ?)`,
|
||||||
|
[id, username, admin, Date.now(), id],
|
||||||
|
);
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('GET /api/admin/tables', () => {
|
||||||
|
it('returns 401 without a session header', async () => {
|
||||||
|
const res = await get();
|
||||||
|
expect(res.status).toBe(401);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns 401 for an expired session', async () => {
|
||||||
|
const inst = await getGameDb();
|
||||||
|
inst.raw.run('INSERT INTO sessions (id, user_id, expires_at) VALUES (?, ?, ?)', [
|
||||||
|
'expired-admin-session',
|
||||||
|
'admin-kamilkrzywda',
|
||||||
|
Date.now() - 1000,
|
||||||
|
]);
|
||||||
|
const res = await get('expired-admin-session');
|
||||||
|
expect(res.status).toBe(401);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns 403 for a valid non-admin session', async () => {
|
||||||
|
const userId = await makeUser('tables-nonadmin', 0);
|
||||||
|
const sessionId = await createSession(await getGameDb(), userId);
|
||||||
|
const res = await get(sessionId);
|
||||||
|
expect(res.status).toBe(403);
|
||||||
|
expect(((await res.json()) as { error: string }).error).toMatch(/admin/i);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('lists every user table for an admin, excluding sqlite_% internals', async () => {
|
||||||
|
const sessionId = await createSession(await getGameDb(), 'admin-kamilkrzywda');
|
||||||
|
const res = await get(sessionId);
|
||||||
|
expect(res.status).toBe(200);
|
||||||
|
const names = ((await res.json()) as Array<{ name: string }>).map((t) => t.name);
|
||||||
|
|
||||||
|
for (const expected of ['packages', 'players', 'planes', 'sessions', 'sim_state', 'users']) {
|
||||||
|
expect(names, `missing ${expected}`).toContain(expected);
|
||||||
|
}
|
||||||
|
expect(names.some((n) => n.startsWith('sqlite_'))).toBe(false);
|
||||||
|
// Name-ordered.
|
||||||
|
expect([...names].sort()).toEqual(names);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import { requireAdmin } from '@/lib/auth';
|
||||||
|
|
||||||
|
// v0.71.0 — GET /api/admin/tables (admin only). Lists every user table as [{ name }] in name
|
||||||
|
// order, excluding SQLite internals (sqlite_%). Feeds the Admin modal's table picker.
|
||||||
|
|
||||||
|
export async function GET(req: Request) {
|
||||||
|
const guard = await requireAdmin(req);
|
||||||
|
if (!guard.ok) return guard.response;
|
||||||
|
|
||||||
|
const res = guard.inst.raw.exec(
|
||||||
|
"SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%' ORDER BY name",
|
||||||
|
);
|
||||||
|
return Response.json(res[0].values.map((r) => ({ name: String(r[0]) })));
|
||||||
|
}
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
import { randomUUID, scryptSync } from 'node:crypto';
|
||||||
|
import fs from 'node:fs/promises';
|
||||||
|
import os from 'node:os';
|
||||||
|
import path from 'node:path';
|
||||||
|
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
||||||
|
import { getGameDb } from '@/lib/db/client';
|
||||||
|
import { SESSION_TTL_MS } from '@/lib/auth';
|
||||||
|
import { POST } from './route';
|
||||||
|
|
||||||
|
// v0.71.0 — login route tests. The test user is created HERE with a hash computed in-test via
|
||||||
|
// scryptSync; the seeded admin's plaintext password must never appear in any test code, so it
|
||||||
|
// is deliberately not exercised here (the e2e suite gets an admin session via /api/test/admin-session).
|
||||||
|
|
||||||
|
let dir: string;
|
||||||
|
const TEST_USER = 'unit-test-user';
|
||||||
|
const TEST_PASSWORD = 'right-horse-wrong-street-42';
|
||||||
|
const SALT_HEX = randomUUID().replace(/-/g, '').slice(0, 32); // 16-byte hex salt
|
||||||
|
const HASH = `${SALT_HEX}$${scryptSync(TEST_PASSWORD, SALT_HEX, 32).toString('hex')}`;
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
dir = await fs.mkdtemp(path.join(os.tmpdir(), 'flight-login-api-'));
|
||||||
|
process.env.FLIGHT_DB_PATH = path.join(dir, 'login.db');
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
delete process.env.FLIGHT_DB_PATH;
|
||||||
|
await fs.rm(dir, { recursive: true, force: true });
|
||||||
|
});
|
||||||
|
|
||||||
|
const post = (body: unknown) => POST(new Request('http://localhost/api/login', { method: 'POST', body: JSON.stringify(body) }));
|
||||||
|
|
||||||
|
async function createTestUser(): Promise<void> {
|
||||||
|
const inst = await getGameDb();
|
||||||
|
// Idempotent — two tests in this file both want the user.
|
||||||
|
inst.raw.run(
|
||||||
|
`INSERT INTO users (id, username, password_hash, admin, created_at)
|
||||||
|
SELECT 'user-unit-test', ?, ?, 0, ? WHERE NOT EXISTS (SELECT 1 FROM users WHERE username = ?)`,
|
||||||
|
[TEST_USER, HASH, Date.now(), TEST_USER],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('POST /api/login', () => {
|
||||||
|
it('rejects malformed bodies with 400', async () => {
|
||||||
|
for (const body of [{}, { username: 'x' }, { password: 'y' }, { username: '', password: 'p' }, { bogus: 1 }]) {
|
||||||
|
const res = await post(body);
|
||||||
|
expect(res.status).toBe(400);
|
||||||
|
expect(((await res.json()) as { error: string }).error).toBeTruthy();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns 401 for an unknown username (and still runs a scrypt)', async () => {
|
||||||
|
const res = await post({ username: 'no-such-user', password: TEST_PASSWORD });
|
||||||
|
expect(res.status).toBe(401);
|
||||||
|
expect(((await res.json()) as { error: string }).error).toMatch(/invalid credentials/i);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns 401 for a wrong password and mints no session', async () => {
|
||||||
|
await createTestUser();
|
||||||
|
const before = (await getGameDb()).raw.exec('SELECT COUNT(*) FROM sessions')[0].values[0][0];
|
||||||
|
|
||||||
|
const res = await post({ username: TEST_USER, password: 'definitely-wrong' });
|
||||||
|
expect(res.status).toBe(401);
|
||||||
|
|
||||||
|
const after = Number((await getGameDb()).raw.exec('SELECT COUNT(*) FROM sessions')[0].values[0][0]);
|
||||||
|
expect(after).toBe(Number(before));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('mints a ~7-day session on success and returns the user', async () => {
|
||||||
|
await createTestUser();
|
||||||
|
const t0 = Date.now();
|
||||||
|
|
||||||
|
const res = await post({ username: TEST_USER, password: TEST_PASSWORD });
|
||||||
|
expect(res.status).toBe(200);
|
||||||
|
const body = (await res.json()) as { sessionId: string; user: { username: string; admin: boolean } };
|
||||||
|
expect(body.user).toEqual({ username: TEST_USER, admin: false });
|
||||||
|
expect(body.sessionId).toMatch(/^[0-9a-f-]{36}$/);
|
||||||
|
|
||||||
|
const row = (await getGameDb()).raw.exec('SELECT user_id, expires_at FROM sessions WHERE id = ?', [body.sessionId])[0].values[0];
|
||||||
|
expect(String(row[0])).toBe('user-unit-test');
|
||||||
|
const ttl = Number(row[1]) - t0;
|
||||||
|
expect(ttl).toBeGreaterThan(SESSION_TTL_MS - 5_000); // ~7 days, minus test drift
|
||||||
|
expect(ttl).toBeLessThan(SESSION_TTL_MS + 5_000);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('login works for the seeded admin row too (hash verified without its plaintext)', async () => {
|
||||||
|
// The seeded admin's hash is a fixed string in client.ts; we can only prove the route
|
||||||
|
// ACCEPTS exactly that stored digest by checking verification against a known pair — which
|
||||||
|
// would require the plaintext. So instead: assert the seeded row is what login looks up, by
|
||||||
|
// confirming an unknown-password attempt for 'kamilkrzywda' yields 401 (row found, hash mismatch).
|
||||||
|
const res = await post({ username: 'kamilkrzywda', password: 'wrong-on-purpose' });
|
||||||
|
expect(res.status).toBe(401);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
import { getGameDb } from '@/lib/db/client';
|
||||||
|
import { createSession, verifyPassword, DUMMY_HASH_FOR_UNKNOWN_USER } from '@/lib/auth';
|
||||||
|
|
||||||
|
// v0.71.0 — POST /api/login
|
||||||
|
// body { username: string, password: string } (both required non-empty; unknown fields 400).
|
||||||
|
// Success → 200 { sessionId, user: { username, admin } }; the session row lives 7 days and is
|
||||||
|
// sent back as X-Flight-Session on later requests. Failure → 401 { error }. An unknown
|
||||||
|
// username still runs one full scrypt against a fixed dummy digest so timing stays uniform.
|
||||||
|
|
||||||
|
export async function POST(req: Request) {
|
||||||
|
let body: unknown;
|
||||||
|
try {
|
||||||
|
const text = await req.text();
|
||||||
|
body = text ? JSON.parse(text) : undefined;
|
||||||
|
} catch {
|
||||||
|
return Response.json({ error: 'invalid JSON body' }, { status: 400 });
|
||||||
|
}
|
||||||
|
if (typeof body !== 'object' || body === null || Array.isArray(body)) {
|
||||||
|
return Response.json({ error: 'body must be a JSON object' }, { status: 400 });
|
||||||
|
}
|
||||||
|
const input = body as Record<string, unknown>;
|
||||||
|
for (const key of Object.keys(input)) {
|
||||||
|
if (key !== 'username' && key !== 'password') {
|
||||||
|
return Response.json({ error: `unknown field "${key}"` }, { status: 400 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const username = input.username;
|
||||||
|
const password = input.password;
|
||||||
|
if (typeof username !== 'string' || username.length === 0) {
|
||||||
|
return Response.json({ error: 'username is required and must be a non-empty string' }, { status: 400 });
|
||||||
|
}
|
||||||
|
if (typeof password !== 'string' || password.length === 0) {
|
||||||
|
return Response.json({ error: 'password is required and must be a non-empty string' }, { status: 400 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const inst = await getGameDb();
|
||||||
|
const res = inst.raw.exec('SELECT id, password_hash, admin FROM users WHERE username = ?', [username]);
|
||||||
|
const row = res[0]?.values?.[0];
|
||||||
|
if (!row) {
|
||||||
|
verifyPassword(password, DUMMY_HASH_FOR_UNKNOWN_USER); // uniform timing — result discarded
|
||||||
|
return Response.json({ error: 'invalid credentials' }, { status: 401 });
|
||||||
|
}
|
||||||
|
if (!verifyPassword(password, String(row[1]))) {
|
||||||
|
return Response.json({ error: 'invalid credentials' }, { status: 401 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const sessionId = await createSession(inst, String(row[0]));
|
||||||
|
return Response.json({
|
||||||
|
sessionId,
|
||||||
|
user: { username, admin: Number(row[2]) === 1 },
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
import fs from 'node:fs/promises';
|
||||||
|
import os from 'node:os';
|
||||||
|
import path from 'node:path';
|
||||||
|
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
||||||
|
import { getGameDb } from '@/lib/db/client';
|
||||||
|
import { createSession } from '@/lib/auth';
|
||||||
|
import { POST } from './route';
|
||||||
|
|
||||||
|
// v0.71.0 — logout route tests: deletes the session named by X-Flight-Session, idempotently.
|
||||||
|
|
||||||
|
let dir: string;
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
dir = await fs.mkdtemp(path.join(os.tmpdir(), 'flight-logout-api-'));
|
||||||
|
process.env.FLIGHT_DB_PATH = path.join(dir, 'logout.db');
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
delete process.env.FLIGHT_DB_PATH;
|
||||||
|
await fs.rm(dir, { recursive: true, force: true });
|
||||||
|
});
|
||||||
|
|
||||||
|
const post = (sessionId?: string) =>
|
||||||
|
POST(
|
||||||
|
new Request('http://localhost/api/logout', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: sessionId ? { 'X-Flight-Session': sessionId } : undefined,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
async function mintSession(): Promise<string> {
|
||||||
|
const inst = await getGameDb();
|
||||||
|
return createSession(inst, 'admin-kamilkrzywda'); // any user id works — logout only deletes the session row
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('POST /api/logout', () => {
|
||||||
|
it('returns 401 without a session header', async () => {
|
||||||
|
const res = await post();
|
||||||
|
expect(res.status).toBe(401);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('deletes the named session and is idempotent on repeat calls', async () => {
|
||||||
|
const sessionId = await mintSession();
|
||||||
|
const count = (await getGameDb()).raw.exec('SELECT COUNT(*) FROM sessions WHERE id = ?', [sessionId])[0].values[0][0];
|
||||||
|
expect(Number(count)).toBe(1);
|
||||||
|
|
||||||
|
const first = await post(sessionId);
|
||||||
|
expect(first.status).toBe(200);
|
||||||
|
expect(await first.json()).toEqual({ ok: true });
|
||||||
|
|
||||||
|
// The row is gone…
|
||||||
|
const after = (await getGameDb()).raw.exec('SELECT COUNT(*) FROM sessions WHERE id = ?', [sessionId])[0].values[0][0];
|
||||||
|
expect(Number(after)).toBe(0);
|
||||||
|
|
||||||
|
// …and a second logout of the same (now unknown) session is still 200.
|
||||||
|
const second = await post(sessionId);
|
||||||
|
expect(second.status).toBe(200);
|
||||||
|
expect(await second.json()).toEqual({ ok: true });
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import { getGameDb, persist } from '@/lib/db/client';
|
||||||
|
import { SESSION_HEADER } from '@/lib/auth';
|
||||||
|
|
||||||
|
// v0.71.0 — POST /api/logout (no body). Deletes the session named by the X-Flight-Session
|
||||||
|
// header; idempotent — deleting an unknown or already-deleted session is still 200. A missing
|
||||||
|
// header has nothing to delete and gets 401 like every other unauthenticated request here.
|
||||||
|
|
||||||
|
export async function POST(req: Request) {
|
||||||
|
const sessionId = req.headers.get(SESSION_HEADER);
|
||||||
|
if (!sessionId) return Response.json({ error: 'authentication required' }, { status: 401 });
|
||||||
|
|
||||||
|
const inst = await getGameDb();
|
||||||
|
inst.raw.run('DELETE FROM sessions WHERE id = ?', [sessionId]);
|
||||||
|
await persist(inst);
|
||||||
|
return Response.json({ ok: true });
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@ import fs from 'node:fs/promises';
|
|||||||
import os from 'node:os';
|
import os from 'node:os';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
||||||
import * as schema from '@/lib/db/schema';
|
import { getLocalPlayer, updateLocalPlayerEconomy } from '@/lib/db/localPlayer';
|
||||||
import { getGameDb } from '@/lib/db/client';
|
import { getGameDb } from '@/lib/db/client';
|
||||||
import { PLANE_TYPES } from '@/lib/game/catalog';
|
import { PLANE_TYPES } from '@/lib/game/catalog';
|
||||||
import { POST } from './route';
|
import { POST } from './route';
|
||||||
@@ -38,14 +38,13 @@ describe('POST /api/market/buy-plane', () => {
|
|||||||
expect(((await res.json()) as { error: string }).error).toMatch(/insufficient funds/i);
|
expect(((await res.json()) as { error: string }).error).toMatch(/insufficient funds/i);
|
||||||
|
|
||||||
// Cash untouched by the failed attempt.
|
// Cash untouched by the failed attempt.
|
||||||
const account = (await (await getGameDb()).db.select().from(schema.account))[0];
|
expect((await getLocalPlayer(await getGameDb())).cash).toBe(20_000);
|
||||||
expect(account.cash).toBe(20_000);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('deducts the full price and adds a full-tank plane at EDDF to the snapshot', async () => {
|
it('deducts the full price and adds a full-tank plane at EDDF to the snapshot', async () => {
|
||||||
const { db } = await getGameDb();
|
const inst = await getGameDb();
|
||||||
// Single-row account table — top up cash so the purchase can succeed.
|
// Local player row — top up cash so the purchase can succeed.
|
||||||
await db.update(schema.account).set({ cash: 500_000 });
|
await updateLocalPlayerEconomy(inst, { cash: 500_000 });
|
||||||
|
|
||||||
const res = await post({ model: 'atr72' });
|
const res = await post({ model: 'atr72' });
|
||||||
expect(res.status).toBe(200);
|
expect(res.status).toBe(200);
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import path from 'node:path';
|
|||||||
import { eq } from 'drizzle-orm';
|
import { eq } from 'drizzle-orm';
|
||||||
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
||||||
import * as schema from '@/lib/db/schema';
|
import * as schema from '@/lib/db/schema';
|
||||||
|
import { getLocalPlayer } from '@/lib/db/localPlayer';
|
||||||
import { getGameDb } from '@/lib/db/client';
|
import { getGameDb } from '@/lib/db/client';
|
||||||
import { PLANE_TYPES, SELL_FRACTION } from '@/lib/game/catalog';
|
import { PLANE_TYPES, SELL_FRACTION } from '@/lib/game/catalog';
|
||||||
import { POST } from './route';
|
import { POST } from './route';
|
||||||
@@ -59,10 +60,10 @@ describe('POST /api/market/sell-plane', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('sells a grounded second plane for SELL_FRACTION of the catalog price', async () => {
|
it('sells a grounded second plane for SELL_FRACTION of the catalog price', async () => {
|
||||||
const { db } = await getGameDb();
|
const inst = await getGameDb();
|
||||||
// The previous test left 'plane-extra' in the DB (now flying) — ground it.
|
// The previous test left 'plane-extra' in the DB (now flying) — ground it.
|
||||||
await db.update(schema.planes).set({ status: 'available' }).where(eq(schema.planes.id, 'plane-extra'));
|
await inst.db.update(schema.planes).set({ status: 'available' }).where(eq(schema.planes.id, 'plane-extra'));
|
||||||
const cashBefore = (await db.select().from(schema.account))[0].cash;
|
const cashBefore = (await getLocalPlayer(inst)).cash;
|
||||||
|
|
||||||
const res = await post({ planeId: 'plane-extra' });
|
const res = await post({ planeId: 'plane-extra' });
|
||||||
expect(res.status).toBe(200);
|
expect(res.status).toBe(200);
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
import fs from 'node:fs/promises';
|
||||||
|
import os from 'node:os';
|
||||||
|
import path from 'node:path';
|
||||||
|
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
||||||
|
import { getGameDb } from '@/lib/db/client';
|
||||||
|
import { createSession } from '@/lib/auth';
|
||||||
|
import { GET } from './route';
|
||||||
|
|
||||||
|
// v0.71.0 — /api/me tests: resolves X-Flight-Session to its user, 401 otherwise.
|
||||||
|
|
||||||
|
let dir: string;
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
dir = await fs.mkdtemp(path.join(os.tmpdir(), 'flight-me-api-'));
|
||||||
|
process.env.FLIGHT_DB_PATH = path.join(dir, 'me.db');
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
delete process.env.FLIGHT_DB_PATH;
|
||||||
|
await fs.rm(dir, { recursive: true, force: true });
|
||||||
|
});
|
||||||
|
|
||||||
|
const get = (sessionId?: string) =>
|
||||||
|
GET(
|
||||||
|
new Request('http://localhost/api/me', {
|
||||||
|
headers: sessionId ? { 'X-Flight-Session': sessionId } : undefined,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
describe('GET /api/me', () => {
|
||||||
|
it('returns 401 without a session header', async () => {
|
||||||
|
const res = await get();
|
||||||
|
expect(res.status).toBe(401);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns 401 for an unknown session id', async () => {
|
||||||
|
const res = await get('00000000-0000-4000-8000-000000000000');
|
||||||
|
expect(res.status).toBe(401);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns 401 for an expired session', async () => {
|
||||||
|
const inst = await getGameDb();
|
||||||
|
// A session whose expiry is already in the past.
|
||||||
|
inst.raw.run('INSERT INTO sessions (id, user_id, expires_at) VALUES (?, ?, ?)', [
|
||||||
|
'expired-session-id',
|
||||||
|
'admin-kamilkrzywda',
|
||||||
|
Date.now() - 1000,
|
||||||
|
]);
|
||||||
|
const res = await get('expired-session-id');
|
||||||
|
expect(res.status).toBe(401);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns the user for a live session (admin flag included)', async () => {
|
||||||
|
const sessionId = await createSession(await getGameDb(), 'admin-kamilkrzywda');
|
||||||
|
const res = await get(sessionId);
|
||||||
|
expect(res.status).toBe(200);
|
||||||
|
expect(await res.json()).toEqual({ username: 'kamilkrzywda', admin: true });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('reports non-admin users as such', async () => {
|
||||||
|
const inst = await getGameDb();
|
||||||
|
inst.raw.run(
|
||||||
|
`INSERT INTO users (id, username, password_hash, admin, created_at)
|
||||||
|
SELECT 'user-me-test', 'me-test-user', 'aa$bb', 0, ? WHERE NOT EXISTS (SELECT 1 FROM users WHERE id = 'user-me-test')`,
|
||||||
|
[Date.now()],
|
||||||
|
);
|
||||||
|
const sessionId = await createSession(inst, 'user-me-test');
|
||||||
|
const res = await get(sessionId);
|
||||||
|
expect(res.status).toBe(200);
|
||||||
|
expect(await res.json()).toEqual({ username: 'me-test-user', admin: false });
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import { currentUser } from '@/lib/auth';
|
||||||
|
|
||||||
|
// v0.71.0 — GET /api/me (no body). Returns the user behind a valid X-Flight-Session header as
|
||||||
|
// { username, admin }, or 401 when the header is missing/unknown/expired. The client uses it to
|
||||||
|
// decide what the Admin modal shows on open.
|
||||||
|
|
||||||
|
export async function GET(req: Request) {
|
||||||
|
const user = await currentUser(req);
|
||||||
|
if (!user) return Response.json({ error: 'authentication required' }, { status: 401 });
|
||||||
|
return Response.json({ username: user.username, admin: user.admin });
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ import path from 'node:path';
|
|||||||
import { eq } from 'drizzle-orm';
|
import { eq } from 'drizzle-orm';
|
||||||
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
||||||
import * as schema from '@/lib/db/schema';
|
import * as schema from '@/lib/db/schema';
|
||||||
|
import { getLocalPlayer } from '@/lib/db/localPlayer';
|
||||||
import { getGameDb } from '@/lib/db/client';
|
import { getGameDb } from '@/lib/db/client';
|
||||||
import { POST } from './route';
|
import { POST } from './route';
|
||||||
|
|
||||||
@@ -84,8 +85,9 @@ describe('POST /api/packages/:id/abandon', () => {
|
|||||||
|
|
||||||
it('abandons a loaded package for the exact formula penalty and returns the full snapshot', async () => {
|
it('abandons a loaded package for the exact formula penalty and returns the full snapshot', async () => {
|
||||||
const times = await insertLoadedPackage('p-ab', 1_000); // created "now" → near the 15% floor
|
const times = await insertLoadedPackage('p-ab', 1_000); // created "now" → near the 15% floor
|
||||||
const { db } = await getGameDb();
|
const inst = await getGameDb();
|
||||||
const cashBefore = (await db.select().from(schema.account))[0].cash;
|
const { db } = inst;
|
||||||
|
const cashBefore = (await getLocalPlayer(inst)).cash;
|
||||||
|
|
||||||
const res = await post('p-ab');
|
const res = await post('p-ab');
|
||||||
expect(res.status).toBe(200);
|
expect(res.status).toBe(200);
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
import { ignorePackage, performAction } from '@/lib/game/actions';
|
|
||||||
|
|
||||||
// POST /api/packages/:id/ignore (v0.29.0, ISS-047 part B) — no body. Dismisses an OPEN job so it
|
|
||||||
// leaves the market permanently; the top-up logic spawns a replacement on the next tick. No penalty,
|
|
||||||
// nothing else changes. 404 unknown id; 409 unless open. On success returns the full state snapshot.
|
|
||||||
|
|
||||||
export async function POST(_req: Request, ctx: { params: Promise<{ id: string }> }) {
|
|
||||||
const { id } = await ctx.params;
|
|
||||||
return performAction((inst) => ignorePackage(inst, id));
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { getGameDb, persist } from '@/lib/db/client';
|
import { getGameDb, persist } from '@/lib/db/client';
|
||||||
import * as schema from '@/lib/db/schema';
|
import { getLocalPlayer, updateLocalPlayerEconomy } from '@/lib/db/localPlayer';
|
||||||
import { getStateSnapshot } from '@/lib/game/state';
|
import { getStateSnapshot } from '@/lib/game/state';
|
||||||
import { tickNow } from '@/lib/sim/engine';
|
import { tickNow } from '@/lib/sim/engine';
|
||||||
|
|
||||||
@@ -46,9 +46,8 @@ export async function POST(req: Request) {
|
|||||||
try {
|
try {
|
||||||
const inst = await getGameDb();
|
const inst = await getGameDb();
|
||||||
await tickNow(); // clock is current before the snapshot we return (same as siblings)
|
await tickNow(); // clock is current before the snapshot we return (same as siblings)
|
||||||
const account = (await inst.db.select().from(schema.account))[0];
|
const player = await getLocalPlayer(inst);
|
||||||
if (!account) throw new Error('account row missing');
|
await updateLocalPlayerEconomy(inst, { cash: Math.round((player.cash + amount) * 100) / 100 });
|
||||||
await inst.db.update(schema.account).set({ cash: Math.round((account.cash + amount) * 100) / 100 });
|
|
||||||
await persist(inst);
|
await persist(inst);
|
||||||
return Response.json(await getStateSnapshot());
|
return Response.json(await getStateSnapshot());
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
import { getGameDb } from '@/lib/db/client';
|
||||||
|
import { createSession } from '@/lib/auth';
|
||||||
|
|
||||||
|
// TEST-ONLY hook (v0.71.0) — mints a live session for the SEEDED admin user server-side and
|
||||||
|
// returns its id, so the e2e suite can exercise the authenticated Admin panel WITHOUT the real
|
||||||
|
// admin password ever appearing in test code (the spec forbids it). No body. Disabled unless
|
||||||
|
// FLIGHT_TEST_HOOKS=1 (set in docker-compose.ci.yml for the CI stack only); every other
|
||||||
|
// deployment 404s here, like its /api/test/* siblings.
|
||||||
|
|
||||||
|
export async function POST() {
|
||||||
|
if (process.env.FLIGHT_TEST_HOOKS !== '1') {
|
||||||
|
return Response.json({ error: 'test hooks disabled' }, { status: 404 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const inst = await getGameDb();
|
||||||
|
const res = inst.raw.exec("SELECT id FROM users WHERE username = 'kamilkrzywda'");
|
||||||
|
const userId = res[0]?.values?.[0]?.[0];
|
||||||
|
if (typeof userId !== 'string') {
|
||||||
|
return Response.json({ error: 'seeded admin user missing' }, { status: 500 });
|
||||||
|
}
|
||||||
|
const sessionId = await createSession(inst, userId);
|
||||||
|
return Response.json({ sessionId });
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import { randomInt, randomUUID } from 'node:crypto';
|
import { randomInt, randomUUID } from 'node:crypto';
|
||||||
import { getGameDb, persist } from '@/lib/db/client';
|
import { getGameDb, persist } from '@/lib/db/client';
|
||||||
|
import { getLocalPlayer } from '@/lib/db/localPlayer';
|
||||||
import * as schema from '@/lib/db/schema';
|
import * as schema from '@/lib/db/schema';
|
||||||
import { loadAirportsGeoJson } from '@/lib/airports';
|
import { loadAirportsGeoJson } from '@/lib/airports';
|
||||||
import { generatePackage, mulberry32 } from '@/lib/game/seed';
|
import { generatePackage, mulberry32 } from '@/lib/game/seed';
|
||||||
@@ -84,8 +85,7 @@ export async function POST(req: Request) {
|
|||||||
const rng = mulberry32(randomInt(0, 2 ** 31));
|
const rng = mulberry32(randomInt(0, 2 ** 31));
|
||||||
// v0.38.0 (ISS-072): hook-created packages carry the LIVE account reputation — same job quality
|
// v0.38.0 (ISS-072): hook-created packages carry the LIVE account reputation — same job quality
|
||||||
// as engine spawns; never force a fixed value here.
|
// as engine spawns; never force a fixed value here.
|
||||||
const account = (await inst.db.select().from(schema.account))[0];
|
const player = await getLocalPlayer(inst);
|
||||||
if (!account) throw new Error('account row missing');
|
|
||||||
const created = generatePackage({
|
const created = generatePackage({
|
||||||
id: randomUUID(),
|
id: randomUUID(),
|
||||||
airports,
|
airports,
|
||||||
@@ -97,7 +97,7 @@ export async function POST(req: Request) {
|
|||||||
weightKg: input.weightKg as number | undefined,
|
weightKg: input.weightKg as number | undefined,
|
||||||
// Omitted → force null (no roll) so existing e2e reward/rep assertions stay deterministic.
|
// Omitted → force null (no roll) so existing e2e reward/rep assertions stay deterministic.
|
||||||
special: input.special === undefined ? null : (input.special as string | null),
|
special: input.special === undefined ? null : (input.special as string | null),
|
||||||
reputation: account.reputation,
|
reputation: player.reputation,
|
||||||
});
|
});
|
||||||
await inst.db.insert(schema.packages).values(created);
|
await inst.db.insert(schema.packages).values(created);
|
||||||
await persist(inst);
|
await persist(inst);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { getGameDb, persist } from '@/lib/db/client';
|
import { getGameDb, persist } from '@/lib/db/client';
|
||||||
import * as schema from '@/lib/db/schema';
|
import { getLocalPlayer, updateLocalPlayerEconomy } from '@/lib/db/localPlayer';
|
||||||
import { getStateSnapshot } from '@/lib/game/state';
|
import { getStateSnapshot } from '@/lib/game/state';
|
||||||
import { tickNow } from '@/lib/sim/engine';
|
import { tickNow } from '@/lib/sim/engine';
|
||||||
|
|
||||||
@@ -42,9 +42,8 @@ export async function POST(req: Request) {
|
|||||||
try {
|
try {
|
||||||
const inst = await getGameDb();
|
const inst = await getGameDb();
|
||||||
await tickNow(); // clock is current before the snapshot we return (same as siblings)
|
await tickNow(); // clock is current before the snapshot we return (same as siblings)
|
||||||
const account = (await inst.db.select().from(schema.account))[0];
|
await getLocalPlayer(inst); // existence check — the snapshot below would fail anyway if it's gone
|
||||||
if (!account) throw new Error('account row missing');
|
await updateLocalPlayerEconomy(inst, { cash: Math.round(amount * 100) / 100 });
|
||||||
await inst.db.update(schema.account).set({ cash: Math.round(amount * 100) / 100 });
|
|
||||||
await persist(inst);
|
await persist(inst);
|
||||||
return Response.json(await getStateSnapshot());
|
return Response.json(await getStateSnapshot());
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
+139
@@ -588,3 +588,142 @@ body {
|
|||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
color: #f1f5f9;
|
color: #f1f5f9;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* v0.71.0 — Admin modal: overlay sits above the z-50 toast stack; panel matches the dark slate theme. */
|
||||||
|
.modal-overlay {
|
||||||
|
position: fixed;
|
||||||
|
inset: 0;
|
||||||
|
z-index: 60; /* above toasts (z-50) and everything else on screen */
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
background: rgba(2, 6, 23, 0.7);
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-panel {
|
||||||
|
width: min(920px, calc(100vw - 32px));
|
||||||
|
max-height: calc(100vh - 48px);
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
background: rgba(15, 23, 42, 0.97);
|
||||||
|
color: #e2e8f0;
|
||||||
|
border: 1px solid rgba(148, 163, 184, 0.4);
|
||||||
|
border-radius: 8px;
|
||||||
|
box-shadow: 0 12px 40px rgba(2, 6, 23, 0.6);
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 8px;
|
||||||
|
padding: 10px 14px;
|
||||||
|
border-bottom: 1px solid rgba(148, 163, 184, 0.25);
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-header h2 {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 15px;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* v0.71.0 — Admin panel content (login form + generic DB grid). */
|
||||||
|
.admin-panel {
|
||||||
|
padding: 14px;
|
||||||
|
overflow-y: auto;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-login {
|
||||||
|
max-width: 320px;
|
||||||
|
margin: 0 auto;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-panel label {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 4px;
|
||||||
|
font-size: 12px;
|
||||||
|
color: #cbd5e1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-panel input[type='text'],
|
||||||
|
.admin-panel input:not([type]),
|
||||||
|
.admin-login input {
|
||||||
|
font-size: 13px;
|
||||||
|
padding: 5px 8px;
|
||||||
|
border-radius: 4px;
|
||||||
|
border: 1px solid rgba(148, 163, 184, 0.4);
|
||||||
|
background: #1e293b;
|
||||||
|
color: #e2e8f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-message {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 13px;
|
||||||
|
color: #cbd5e1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-error {
|
||||||
|
font-size: 12px;
|
||||||
|
color: #fca5a5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-toolbar {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-table-list {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-rows-wrap {
|
||||||
|
overflow-x: auto;
|
||||||
|
border: 1px solid rgba(148, 163, 184, 0.25);
|
||||||
|
border-radius: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-rows {
|
||||||
|
width: 100%;
|
||||||
|
border-collapse: collapse;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-rows th,
|
||||||
|
.admin-rows td {
|
||||||
|
padding: 4px 6px;
|
||||||
|
text-align: left;
|
||||||
|
white-space: nowrap;
|
||||||
|
border-bottom: 1px solid rgba(148, 163, 184, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-rows th {
|
||||||
|
color: #94a3b8;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-cell {
|
||||||
|
width: 110px;
|
||||||
|
font-size: 12px;
|
||||||
|
padding: 2px 5px;
|
||||||
|
border-radius: 3px;
|
||||||
|
border: 1px solid rgba(148, 163, 184, 0.3);
|
||||||
|
background: #1e293b;
|
||||||
|
color: #e2e8f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-cell:disabled {
|
||||||
|
opacity: 0.55;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-row-actions {
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,414 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useCallback, useEffect, useState } from 'react';
|
||||||
|
|
||||||
|
// v0.71.0 — content of the Admin modal (opened by the top-bar "Admin" button). Three views:
|
||||||
|
// login form (no valid session), a "not an admin" notice, or the generic whole-database CRUD
|
||||||
|
// grid behind /api/admin/*. This is a dev tool surface — plain and functional on purpose.
|
||||||
|
|
||||||
|
const SESSION_STORAGE_KEY = 'flight.session';
|
||||||
|
|
||||||
|
interface Me {
|
||||||
|
username: string;
|
||||||
|
admin: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface RowsData {
|
||||||
|
columns: string[];
|
||||||
|
rows: Array<Record<string, unknown>>;
|
||||||
|
}
|
||||||
|
|
||||||
|
function readSession(): string | null {
|
||||||
|
try {
|
||||||
|
return window.localStorage.getItem(SESSION_STORAGE_KEY);
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function AdminPanel() {
|
||||||
|
const [session, setSession] = useState<string | null>(null);
|
||||||
|
const [me, setMe] = useState<Me | null>(null); // null while checking /api/me on mount
|
||||||
|
const [checking, setChecking] = useState(true);
|
||||||
|
|
||||||
|
// Login form state.
|
||||||
|
const [username, setUsername] = useState('');
|
||||||
|
const [password, setPassword] = useState('');
|
||||||
|
const [loginError, setLoginError] = useState<string | null>(null);
|
||||||
|
|
||||||
|
// Admin grid state.
|
||||||
|
const [tables, setTables] = useState<string[]>([]);
|
||||||
|
const [table, setTable] = useState<string | null>(null);
|
||||||
|
const [rowsData, setRowsData] = useState<RowsData | null>(null);
|
||||||
|
const [edits, setEdits] = useState<Record<string, string>>({}); // key `${rowIdx}:${col}`
|
||||||
|
const [newRow, setNewRow] = useState(false);
|
||||||
|
const [busy, setBusy] = useState(false);
|
||||||
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
|
const authHeaders = useCallback(
|
||||||
|
(s: string) => ({ 'X-Flight-Session': s }),
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
|
||||||
|
// On mount: a stored session decides between the grid and the login form.
|
||||||
|
useEffect(() => {
|
||||||
|
let cancelled = false;
|
||||||
|
const stored = readSession();
|
||||||
|
if (!stored) {
|
||||||
|
setChecking(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fetch('/api/me', { headers: authHeaders(stored) })
|
||||||
|
.then(async (res) => {
|
||||||
|
if (!res.ok || cancelled) {
|
||||||
|
window.localStorage.removeItem(SESSION_STORAGE_KEY);
|
||||||
|
setSession(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const body = (await res.json()) as Me;
|
||||||
|
setSession(stored);
|
||||||
|
setMe(body);
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
if (!cancelled) {
|
||||||
|
window.localStorage.removeItem(SESSION_STORAGE_KEY);
|
||||||
|
setSession(null);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
if (!cancelled) setChecking(false);
|
||||||
|
});
|
||||||
|
return () => {
|
||||||
|
cancelled = true;
|
||||||
|
};
|
||||||
|
}, [authHeaders]);
|
||||||
|
|
||||||
|
const loadTables = useCallback(async (s: string) => {
|
||||||
|
const res = await fetch('/api/admin/tables', { headers: authHeaders(s) });
|
||||||
|
if (!res.ok) throw new Error((await res.json().catch(() => null))?.error ?? `HTTP ${res.status}`);
|
||||||
|
setTables(((await res.json()) as Array<{ name: string }>).map((t) => t.name));
|
||||||
|
}, [authHeaders]);
|
||||||
|
|
||||||
|
const loadRows = useCallback(
|
||||||
|
async (s: string, name: string) => {
|
||||||
|
const res = await fetch(`/api/admin/tables/${encodeURIComponent(name)}/rows?limit=500`, { headers: authHeaders(s) });
|
||||||
|
if (!res.ok) throw new Error((await res.json().catch(() => null))?.error ?? `HTTP ${res.status}`);
|
||||||
|
setRowsData(await res.json());
|
||||||
|
},
|
||||||
|
[authHeaders],
|
||||||
|
);
|
||||||
|
|
||||||
|
// Enter the grid once /api/me confirms an admin.
|
||||||
|
useEffect(() => {
|
||||||
|
if (!session || !me?.admin) return;
|
||||||
|
let cancelled = false;
|
||||||
|
(async () => {
|
||||||
|
try {
|
||||||
|
await loadTables(session);
|
||||||
|
if (!cancelled) setBusy(false);
|
||||||
|
} catch (err) {
|
||||||
|
if (!cancelled) setError(err instanceof Error ? err.message : String(err));
|
||||||
|
} finally {
|
||||||
|
if (!cancelled) setBusy(false);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
return () => {
|
||||||
|
cancelled = true;
|
||||||
|
};
|
||||||
|
}, [session, me, loadTables]);
|
||||||
|
|
||||||
|
const openTable = async (name: string) => {
|
||||||
|
if (!session) return;
|
||||||
|
setBusy(true);
|
||||||
|
setError(null);
|
||||||
|
try {
|
||||||
|
await loadRows(session, name);
|
||||||
|
setTable(name);
|
||||||
|
setEdits({});
|
||||||
|
setNewRow(false);
|
||||||
|
} catch (err) {
|
||||||
|
setError(err instanceof Error ? err.message : String(err));
|
||||||
|
} finally {
|
||||||
|
setBusy(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const refresh = async () => {
|
||||||
|
if (!session || !table) return;
|
||||||
|
setBusy(true);
|
||||||
|
setError(null);
|
||||||
|
try {
|
||||||
|
await loadRows(session, table);
|
||||||
|
setEdits({});
|
||||||
|
setNewRow(false);
|
||||||
|
} catch (err) {
|
||||||
|
setError(err instanceof Error ? err.message : String(err));
|
||||||
|
} finally {
|
||||||
|
setBusy(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const login = async () => {
|
||||||
|
if (!username || !password) return;
|
||||||
|
setLoginError(null);
|
||||||
|
const res = await fetch('/api/login', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'content-type': 'application/json' },
|
||||||
|
body: JSON.stringify({ username, password }),
|
||||||
|
});
|
||||||
|
if (!res.ok) {
|
||||||
|
setLoginError((await res.json().catch(() => null))?.error ?? `HTTP ${res.status}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const body = (await res.json()) as { sessionId: string; user: Me };
|
||||||
|
window.localStorage.setItem(SESSION_STORAGE_KEY, body.sessionId);
|
||||||
|
setSession(body.sessionId);
|
||||||
|
setMe(body.user);
|
||||||
|
setUsername('');
|
||||||
|
setPassword('');
|
||||||
|
};
|
||||||
|
|
||||||
|
const logout = async () => {
|
||||||
|
if (session) await fetch('/api/logout', { method: 'POST', headers: authHeaders(session) }).catch(() => undefined);
|
||||||
|
window.localStorage.removeItem(SESSION_STORAGE_KEY);
|
||||||
|
setSession(null);
|
||||||
|
setMe(null);
|
||||||
|
setTable(null);
|
||||||
|
setRowsData(null);
|
||||||
|
setTables([]);
|
||||||
|
setError(null);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (checking) return <div className="admin-panel">loading…</div>;
|
||||||
|
|
||||||
|
// No valid session → login form.
|
||||||
|
if (!session || !me) {
|
||||||
|
return (
|
||||||
|
<form
|
||||||
|
className="admin-panel admin-login"
|
||||||
|
onSubmit={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
void login();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<label>
|
||||||
|
Username
|
||||||
|
<input data-testid="admin-username" value={username} onChange={(e) => setUsername(e.target.value)} autoComplete="username" />
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
Password
|
||||||
|
<input
|
||||||
|
data-testid="admin-password"
|
||||||
|
type="password"
|
||||||
|
value={password}
|
||||||
|
onChange={(e) => setPassword(e.target.value)}
|
||||||
|
autoComplete="current-password"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
{loginError && (
|
||||||
|
<div data-testid="admin-error" className="admin-error">
|
||||||
|
{loginError}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<button type="submit" data-testid="admin-login-submit" className="pane-btn">
|
||||||
|
Log in
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Authenticated but not an admin.
|
||||||
|
if (!me.admin) {
|
||||||
|
return (
|
||||||
|
<div className="admin-panel">
|
||||||
|
<p data-testid="admin-not-admin" className="admin-message">
|
||||||
|
Logged in as <strong>{me.username}</strong> — this account is not an admin.
|
||||||
|
</p>
|
||||||
|
<button type="button" data-testid="admin-logout" className="pane-btn" onClick={() => void logout()}>
|
||||||
|
Log out
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const columns = rowsData?.columns ?? [];
|
||||||
|
// Displayed grid: server rows plus one trailing empty row when "+ Add row" is active.
|
||||||
|
const rowCount = (rowsData?.rows.length ?? 0) + (newRow ? 1 : 0);
|
||||||
|
const cellValue = (rowIdx: number, col: string): string => {
|
||||||
|
if (col === '__rowid') return String(rowsData?.rows[rowIdx]?.[col] ?? '');
|
||||||
|
const key = `${rowIdx}:${col}`;
|
||||||
|
if (key in edits) return edits[key];
|
||||||
|
const raw = rowsData?.rows[rowIdx]?.[col];
|
||||||
|
return raw === null || raw === undefined ? '' : String(raw);
|
||||||
|
};
|
||||||
|
|
||||||
|
const saveRow = async (rowIdx: number) => {
|
||||||
|
if (!session || !table || !rowsData) return;
|
||||||
|
setBusy(true);
|
||||||
|
setError(null);
|
||||||
|
try {
|
||||||
|
if (newRow && rowIdx === rowsData.rows.length) {
|
||||||
|
// New row → POST the non-empty cells.
|
||||||
|
const values: Record<string, string> = {};
|
||||||
|
for (const col of columns) {
|
||||||
|
if (col === '__rowid') continue;
|
||||||
|
const v = cellValue(rowIdx, col);
|
||||||
|
if (v !== '') values[col] = v;
|
||||||
|
}
|
||||||
|
const res = await fetch(`/api/admin/tables/${encodeURIComponent(table)}/rows`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'content-type': 'application/json', ...authHeaders(session) },
|
||||||
|
body: JSON.stringify({ values }),
|
||||||
|
});
|
||||||
|
if (!res.ok) throw new Error((await res.json().catch(() => null))?.error ?? `HTTP ${res.status}`);
|
||||||
|
} else {
|
||||||
|
// Existing row → PUT only the changed cells (cleared cell = NULL).
|
||||||
|
const values: Record<string, string | null> = {};
|
||||||
|
for (const col of columns) {
|
||||||
|
if (col === '__rowid') continue;
|
||||||
|
const original = rowsData.rows[rowIdx]?.[col];
|
||||||
|
const origStr = original === null || original === undefined ? '' : String(original);
|
||||||
|
const v = cellValue(rowIdx, col);
|
||||||
|
if (v !== origStr) values[col] = v === '' ? null : v;
|
||||||
|
}
|
||||||
|
if (Object.keys(values).length === 0) return; // nothing changed
|
||||||
|
const res = await fetch(`/api/admin/tables/${encodeURIComponent(table)}/rows`, {
|
||||||
|
method: 'PUT',
|
||||||
|
headers: { 'content-type': 'application/json', ...authHeaders(session) },
|
||||||
|
body: JSON.stringify({ rowid: rowsData.rows[rowIdx]?.__rowid, values }),
|
||||||
|
});
|
||||||
|
if (!res.ok) throw new Error((await res.json().catch(() => null))?.error ?? `HTTP ${res.status}`);
|
||||||
|
}
|
||||||
|
await loadRows(session, table); // re-fetch so the grid shows server state (persistence check)
|
||||||
|
setEdits({});
|
||||||
|
setNewRow(false);
|
||||||
|
} catch (err) {
|
||||||
|
setError(err instanceof Error ? err.message : String(err));
|
||||||
|
} finally {
|
||||||
|
setBusy(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const deleteRow = async (rowIdx: number) => {
|
||||||
|
if (!session || !table || !rowsData?.rows[rowIdx]) return;
|
||||||
|
setBusy(true);
|
||||||
|
setError(null);
|
||||||
|
try {
|
||||||
|
const rowid = rowsData.rows[rowIdx]?.__rowid;
|
||||||
|
const res = await fetch(
|
||||||
|
`/api/admin/tables/${encodeURIComponent(table)}/rows?rowid=${encodeURIComponent(String(rowid))}`,
|
||||||
|
{ method: 'DELETE', headers: authHeaders(session) },
|
||||||
|
);
|
||||||
|
if (!res.ok) throw new Error((await res.json().catch(() => null))?.error ?? `HTTP ${res.status}`);
|
||||||
|
await loadRows(session, table);
|
||||||
|
setEdits({});
|
||||||
|
} catch (err) {
|
||||||
|
setError(err instanceof Error ? err.message : String(err));
|
||||||
|
} finally {
|
||||||
|
setBusy(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="admin-panel">
|
||||||
|
<div className="admin-toolbar">
|
||||||
|
<span data-testid="admin-user" className="admin-message">
|
||||||
|
{me.username} (admin)
|
||||||
|
</span>
|
||||||
|
<button type="button" data-testid="admin-logout" className="pane-btn" onClick={() => void logout()}>
|
||||||
|
Log out
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{!table && (
|
||||||
|
<>
|
||||||
|
<p className="admin-message">Pick a table:</p>
|
||||||
|
<div data-testid="admin-tables" className="admin-table-list">
|
||||||
|
{tables.map((t) => (
|
||||||
|
<button key={t} type="button" data-testid={`admin-table-${t}`} className="pane-btn" onClick={() => void openTable(t)}>
|
||||||
|
{t}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{table && rowsData && (
|
||||||
|
<>
|
||||||
|
<div className="admin-toolbar">
|
||||||
|
<strong data-testid="admin-current-table">{table}</strong>
|
||||||
|
<button type="button" data-testid="admin-back" className="pane-btn" onClick={() => setTable(null)}>
|
||||||
|
← tables
|
||||||
|
</button>
|
||||||
|
<button type="button" data-testid="admin-refresh" className="pane-btn" disabled={busy} onClick={() => void refresh()}>
|
||||||
|
Refresh
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
data-testid="admin-add-row"
|
||||||
|
className="pane-btn"
|
||||||
|
disabled={busy || newRow}
|
||||||
|
onClick={() => setNewRow(true)}
|
||||||
|
>
|
||||||
|
+ Add row
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="admin-rows-wrap">
|
||||||
|
<table data-testid="admin-rows" className="admin-rows">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
{columns.map((c) => (
|
||||||
|
<th key={c}>{c}</th>
|
||||||
|
))}
|
||||||
|
<th />
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{Array.from({ length: rowCount }, (_, i) => (
|
||||||
|
<tr key={i}>
|
||||||
|
{columns.map((c) => (
|
||||||
|
<td key={c}>
|
||||||
|
<input
|
||||||
|
data-testid={`admin-cell-${i}-${c}`}
|
||||||
|
className="admin-cell"
|
||||||
|
value={cellValue(i, c)}
|
||||||
|
disabled={busy || c === '__rowid'}
|
||||||
|
onChange={(e) => setEdits((prev) => ({ ...prev, [`${i}:${c}`]: e.target.value }))}
|
||||||
|
/>
|
||||||
|
</td>
|
||||||
|
))}
|
||||||
|
<td className="admin-row-actions">
|
||||||
|
<button type="button" data-testid={`admin-save-${i}`} className="pane-btn" disabled={busy} onClick={() => void saveRow(i)}>
|
||||||
|
Save
|
||||||
|
</button>{' '}
|
||||||
|
{!(newRow && i === rowsData.rows.length) && (
|
||||||
|
<>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
data-testid={`admin-delete-${i}`}
|
||||||
|
className="pane-btn"
|
||||||
|
disabled={busy}
|
||||||
|
onClick={() => void deleteRow(i)}
|
||||||
|
>
|
||||||
|
Delete
|
||||||
|
</button>{' '}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{error && (
|
||||||
|
<div data-testid="admin-error" className="admin-error">
|
||||||
|
{error}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
+19
-4
@@ -11,12 +11,17 @@ import type { HoverTarget } from './hoverTypes';
|
|||||||
import { hoverRouteGeoJson, hoverTraceGeoJson, planesGeoJson, queuedRoutesGeoJson, routesGeoJson, type AirportCoord, type PlaneFeatureProps } from '../lib/mapData';
|
import { hoverRouteGeoJson, hoverTraceGeoJson, planesGeoJson, queuedRoutesGeoJson, routesGeoJson, type AirportCoord, type PlaneFeatureProps } from '../lib/mapData';
|
||||||
import { weatherFor } from '../lib/weather';
|
import { weatherFor } from '../lib/weather';
|
||||||
import { approxLocalTime } from '../lib/localTime';
|
import { approxLocalTime } from '../lib/localTime';
|
||||||
|
import Modal from './Modal';
|
||||||
|
import AdminPanel from './AdminPanel';
|
||||||
|
|
||||||
const EUROPE_CENTER: [number, number] = [10, 52];
|
// v0.70.0 default view: null island [0,0] at zoom 2 — the world is 2048 px wide there and the
|
||||||
const INITIAL_ZOOM = 4;
|
// Africa+Europe bounding box (lat −35..+71, lon −18..+52) spans ~800 px vertically in Web Mercator,
|
||||||
|
// so both continents are fully visible on a typical desktop map pane.
|
||||||
|
const WORLD_CENTER: [number, number] = [0, 0];
|
||||||
|
const INITIAL_ZOOM = 2;
|
||||||
// Flat 2D view only. Max zoom ≈ ~100 km across a typical desktop viewport width at
|
// Flat 2D view only. Max zoom ≈ ~100 km across a typical desktop viewport width at
|
||||||
// European latitudes (~47 m/px at z11, 52°N); street-level zoom has no gameplay value.
|
// European latitudes (~47 m/px at z11, 52°N); street-level zoom has no gameplay value.
|
||||||
export const MIN_ZOOM = 3;
|
export const MIN_ZOOM = 0; // v0.70.0: fully zoomed out the whole earth (512 px world) fits any viewport
|
||||||
export const MAX_ZOOM = 11;
|
export const MAX_ZOOM = 11;
|
||||||
|
|
||||||
const AIRPORTS_SOURCE_ID = 'airports';
|
const AIRPORTS_SOURCE_ID = 'airports';
|
||||||
@@ -86,6 +91,9 @@ export default function FlightMap({ state, hovered, applySnapshot }: MapProps) {
|
|||||||
const airportsIndexRef = useRef<Map<string, AirportCoord> | null>(null);
|
const airportsIndexRef = useRef<Map<string, AirportCoord> | null>(null);
|
||||||
const [airportCount, setAirportCount] = useState<number | null>(null);
|
const [airportCount, setAirportCount] = useState<number | null>(null);
|
||||||
const [styleId, setStyleId] = useState<string>(DEFAULT_STYLE_ID);
|
const [styleId, setStyleId] = useState<string>(DEFAULT_STYLE_ID);
|
||||||
|
// v0.71.0: the Admin modal (top-bar button) — unmounted while closed so it re-checks the
|
||||||
|
// stored session on every open.
|
||||||
|
const [adminOpen, setAdminOpen] = useState(false);
|
||||||
|
|
||||||
// Push the latest planes/routes GeoJSON into whatever sources currently exist.
|
// Push the latest planes/routes GeoJSON into whatever sources currently exist.
|
||||||
// No-op until the map (and for routes: the airport index) is ready — the mount
|
// No-op until the map (and for routes: the airport index) is ready — the mount
|
||||||
@@ -218,7 +226,7 @@ export default function FlightMap({ state, hovered, applySnapshot }: MapProps) {
|
|||||||
const map = new maplibregl.Map({
|
const map = new maplibregl.Map({
|
||||||
container: containerRef.current,
|
container: containerRef.current,
|
||||||
style: styleUrlFor(initialId, available), // local pack or remote OFM fallback
|
style: styleUrlFor(initialId, available), // local pack or remote OFM fallback
|
||||||
center: EUROPE_CENTER,
|
center: WORLD_CENTER,
|
||||||
zoom: INITIAL_ZOOM,
|
zoom: INITIAL_ZOOM,
|
||||||
minZoom: MIN_ZOOM,
|
minZoom: MIN_ZOOM,
|
||||||
maxZoom: MAX_ZOOM,
|
maxZoom: MAX_ZOOM,
|
||||||
@@ -576,8 +584,15 @@ export default function FlightMap({ state, hovered, applySnapshot }: MapProps) {
|
|||||||
<span data-testid="airport-count">
|
<span data-testid="airport-count">
|
||||||
{airportCount === null ? 'loading airports…' : `${airportCount} world airports`}
|
{airportCount === null ? 'loading airports…' : `${airportCount} world airports`}
|
||||||
</span>
|
</span>
|
||||||
|
{/* v0.71.0: admin panel entry point — right side of the top bar, opens a modal (no URL). */}
|
||||||
|
<button type="button" data-testid="admin-btn" className="pane-btn" onClick={() => setAdminOpen(true)}>
|
||||||
|
Admin
|
||||||
|
</button>
|
||||||
</header>
|
</header>
|
||||||
<div ref={containerRef} data-testid="map" className="map-container" />
|
<div ref={containerRef} data-testid="map" className="map-container" />
|
||||||
|
<Modal open={adminOpen} onClose={() => setAdminOpen(false)} title="Admin">
|
||||||
|
<AdminPanel />
|
||||||
|
</Modal>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useEffect, type ReactNode } from 'react';
|
||||||
|
|
||||||
|
// v0.71.0 — reusable modal dialog: fixed overlay (z-index 60, above the z-50 toast stack),
|
||||||
|
// centered panel, closes on Escape and backdrop click (inner-panel clicks do not close it).
|
||||||
|
// Foundation for future modal-based features; keep this generic.
|
||||||
|
export default function Modal({ open, onClose, title, children }: { open: boolean; onClose: () => void; title: string; children: ReactNode }) {
|
||||||
|
useEffect(() => {
|
||||||
|
if (!open) return;
|
||||||
|
const onKey = (e: KeyboardEvent) => {
|
||||||
|
if (e.key === 'Escape') onClose();
|
||||||
|
};
|
||||||
|
window.addEventListener('keydown', onKey);
|
||||||
|
return () => window.removeEventListener('keydown', onKey);
|
||||||
|
}, [open, onClose]);
|
||||||
|
|
||||||
|
if (!open) return null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="modal-overlay" onClick={onClose}>
|
||||||
|
<div className="modal-panel" role="dialog" aria-modal="true" aria-label={title} onClick={(e) => e.stopPropagation()}>
|
||||||
|
<header className="modal-header">
|
||||||
|
<h2>{title}</h2>
|
||||||
|
<button type="button" data-testid="modal-close" className="pane-btn" onClick={onClose} aria-label="Close dialog">
|
||||||
|
×
|
||||||
|
</button>
|
||||||
|
</header>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -221,16 +221,6 @@ export default function RightPane({ state, loading, applySnapshot, onHover, onEr
|
|||||||
Load
|
Load
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
{/* ISS-047 part B (v0.29.0): dismiss the job — it leaves the market permanently, no penalty. */}
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
data-testid={`ignore-${pkg.id}`}
|
|
||||||
className="pane-btn"
|
|
||||||
disabled={busy}
|
|
||||||
onClick={() => void runAction(`/api/packages/${pkg.id}/ignore`)}
|
|
||||||
>
|
|
||||||
Ignore
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
<div className="contract-sub">
|
<div className="contract-sub">
|
||||||
<span data-testid={`open-package-reward-${pkg.id}`}>{formatCash(pkg.reward)}</span>
|
<span data-testid={`open-package-reward-${pkg.id}`}>{formatCash(pkg.reward)}</span>
|
||||||
|
|||||||
+25
-347
@@ -1118,367 +1118,45 @@
|
|||||||
"27241","ZYQQ","large_airport","Qiqihar Sanjiazi Airport","47.229969","123.914179","477","AS","CN","CN-23","Qiqihar","yes","ZYQQ","NDG","ZYQQ","","","https://en.wikipedia.org/wiki/Qiqihar_Airport","齐齐哈尔, 齐齐哈尔三家子机场"
|
"27241","ZYQQ","large_airport","Qiqihar Sanjiazi Airport","47.229969","123.914179","477","AS","CN","CN-23","Qiqihar","yes","ZYQQ","NDG","ZYQQ","","","https://en.wikipedia.org/wiki/Qiqihar_Airport","齐齐哈尔, 齐齐哈尔三家子机场"
|
||||||
"27242","ZYTL","large_airport","Dalian Zhoushuizi International Airport","38.965719","121.538477","107","AS","CN","CN-21","Dalian (Ganjingzi)","yes","ZYTL","DLC","ZYTL","","https://dlairport.com","https://en.wikipedia.org/wiki/Dalian_Zhoushuizi_International_Airport","Dalian Air Base"
|
"27242","ZYTL","large_airport","Dalian Zhoushuizi International Airport","38.965719","121.538477","107","AS","CN","CN-21","Dalian (Ganjingzi)","yes","ZYTL","DLC","ZYTL","","https://dlairport.com","https://en.wikipedia.org/wiki/Dalian_Zhoushuizi_International_Airport","Dalian Air Base"
|
||||||
"27243","ZYTX","large_airport","Shenyang Taoxian International Airport","41.6398","123.483668","198","AS","CN","CN-21","Shenyang","yes","ZYTX","SHE","ZYTX","","","https://en.wikipedia.org/wiki/Shenyang_Taoxian_International_Airport","沈阳, 沈阳桃仙国际机场"
|
"27243","ZYTX","large_airport","Shenyang Taoxian International Airport","41.6398","123.483668","198","AS","CN","CN-21","Shenyang","yes","ZYTX","SHE","ZYTX","","","https://en.wikipedia.org/wiki/Shenyang_Taoxian_International_Airport","沈阳, 沈阳桃仙国际机场"
|
||||||
"16155","AK62","seaplane_base","Naukati Bay Seaplane Base","55.849602","-133.227994","","NA","US","US-AK","Tuxekan Island","yes","","NKI","AK62","AK62","","https://en.wikipedia.org/wiki/Naukati_Bay_Seaplane_Base","62A, Nichin Cove Seaplane Base, WNC"
|
|
||||||
"8159","19P","seaplane_base","Port Protection Seaplane Base","56.3288","-133.610001","","NA","US","US-AK","Port Protection","yes","","PPV","19P","19P","","https://en.wikipedia.org/wiki/Port_Protection_Seaplane_Base","AK19"
|
|
||||||
"9296","2AK8","small_airport","Icy Cape Air Force Station Airport","70.293545","-161.907151","48","NA","US","US-AK","Icy Cape","no","","","2AK8","2AK8","","",""
|
|
||||||
"9902","2Z1","seaplane_base","Entrance Island Seaplane Base","57.412201","-133.43848","0","NA","US","US-AK","Entrance Island","no","","HBH","","","","","2Z1"
|
|
||||||
"5398","PAPG","medium_airport","Petersburg James A Johnson Airport","56.80170059","-132.9450073","111","NA","US","US-AK","Petersburg","yes","PAPG","PSG","PAPG","PSG","","https://en.wikipedia.org/wiki/Petersburg_James_A._Johnson_Airport",""
|
|
||||||
"5421","PAWG","medium_airport","Wrangell Airport","56.48429871","-132.3699951","49","NA","US","US-AK","Wrangell","yes","PAWG","WRG","PAWG","WRG","","https://en.wikipedia.org/wiki/Wrangell_Airport",""
|
|
||||||
"19240","KAE","seaplane_base","Kake Seaplane Base","56.973","-133.945999","","NA","US","US-AK","Kake","yes","","KAE","","KAE","","https://en.wikipedia.org/wiki/Kake_Seaplane_Base",""
|
|
||||||
"14860","PABU","small_airport","Bullen Point Short Range Radar Station Airport","70.170999","-146.844897","18","NA","US","US-AK","Kaktovik","no","","","PABU","8AK7","","https://en.wikipedia.org/wiki/Bullen_Point_Short_Range_Radar_Site",""
|
|
||||||
"307366","EGAR","small_airport","Rothera Research Station","-67.5675","-68.127403","9","AN","AQ","AQ-U-A","Rothera Research Station","no","EGAR","","EGAR","","http://www.antarctica.ac.uk/living_and_working/research_stations/rothera/","https://en.wikipedia.org/wiki/Rothera_Research_Station",""
|
|
||||||
"5405","PASC","medium_airport","Deadhorse Airport","70.19470215","-148.4649963","65","NA","US","US-AK","Deadhorse","yes","PASC","SCC","PASC","SCC","","https://en.wikipedia.org/wiki/Deadhorse_Airport",""
|
|
||||||
"5401","PAQT","medium_airport","Nuiqsut Airport","70.209999","-151.005998","38","NA","US","US-AK","Nuiqsut","yes","PAQT","NUI","PAQT","AQT","","https://en.wikipedia.org/wiki/Nuiqsut_Airport","10AK"
|
|
||||||
"312361","ANZ","small_airport","Angus Downs Airport","-25.0325","132.2748","1724","OC","AU","AU-NT","Angus Downs Station","no","","ANZ","YADN","","","",""
|
|
||||||
"39579","AQ-0001","small_airport","Novolazarevskaya Station","-70.8461","11.8472","390","AN","AQ","AQ-U-A","Queen Maud Land","no","","","AT17","","","https://en.wikipedia.org/wiki/Novolazarevskaya_Station",""
|
|
||||||
"42221","AQ-0002","small_airport","Troll Airfield","-71.95714","2.45257","4167","AN","AQ","AQ-U-A","Troll Station","no","","","ENOE","AT27","","https://en.wikipedia.org/wiki/Troll_airfield",""
|
|
||||||
"336951","AQBC","medium_airport","Boulder Clay Runway","-74.739373","164.03539","672","AN","AQ","AQ-U-A","Zucchelli Station","no","","","AQBC","","","https://en.wikipedia.org/wiki/Zucchelli_Station",""
|
|
||||||
"345862","AQ-0011","small_airport","Wolfs Fang Runway","-71.545026","8.798389","3707","AN","AQ","AQ-U-A","","no","","","","","https://white-desert.com/about-us/wolfsfang-runway-logistics/","https://en.wikipedia.org/wiki/Wolfs_Fang_Runway","AT98, Henrickson Nunatak, Queen Maud Land"
|
|
||||||
"5054","NZSP","medium_airport","Amundsen–Scott South Pole Station Airport","-90","-1","9300","AN","AQ","AQ-U-A","Amundsen-Scott South Pole Station","no","NZSP","","NZSP","","","https://en.wikipedia.org/wiki/Amundsen-Scott_South_Pole_Station",""
|
|
||||||
"603000","AQ-0016","medium_airport","Grandfather Skiway","-77.530242","-31.827393","","AN","AQ","AQ-U-A","Antartica","no","","","","","","",""
|
|
||||||
"336953","AT03","medium_airport","Concordia Skyway","-75.103278","123.35825","10725","AN","AQ","AQ-U-A","Concordia Station","no","","","AT03","","","https://en.wikipedia.org/wiki/Concordia_Station",""
|
|
||||||
"330063","AT25","small_airport","Showa Station Skiway","-69.006167","39.59","95","AN","AQ","AQ-U-A","Showa Station","no","","","AT25","","","https://en.wikipedia.org/wiki/Showa_Station_(Antarctica)","Syowa Station"
|
|
||||||
"336959","AT28","medium_airport","Vostok Skiway","-78.466139","106.84825","11447","AN","AQ","AQ-U-A","Vostok Station","no","","","AT28","","","https://en.wikipedia.org/wiki/Vostok_Station",""
|
|
||||||
"333856","AU-0112","small_airport","Aileron Airstrip","-22.652908","133.347244","2186","OC","AU","AU-NT","Anmatjere","no","","","YALR","","","",""
|
|
||||||
"351706","AU-0272","small_airport","Planet Downs OS","-25.872662","141.116788","","OC","AU","AU-QLD","Planet downs OS","no","","","","","","",""
|
|
||||||
"352795","AU-0345","small_airport","Hamilton Downs Airstrip","-23.507335","133.260577","","OC","AU","AU-NT","Burt Plain","no","","","","","","",""
|
|
||||||
"27846","YNPB","small_airport","Napperby Airport","-22.5312","132.7632","2135","OC","AU","AU-NT","Napperby","no","","NPP","YNPB","","","",""
|
|
||||||
"27793","YMNY","small_airport","Morney Airport","-25.358299255371094","141.43299865722656","104","OC","AU","AU-QLD","","no","YMNY","OXY","YMNY","","","",""
|
|
||||||
"507903","AU-0571","small_airport","Lake MacKay Airstrip","-23.670782","129.976158","","OC","AU","AU-NT","Lake MacKay","no","","","","","","",""
|
|
||||||
"508151","AU-0586","small_airport","homestead","-23.317075","138.587637","","OC","AU","AU-NT","Sturt QLD 4829","no","","","","","","",""
|
|
||||||
"38379","YHBY","small_airport","Henbury Airport","-24.584","133.236","","OC","AU","AU-NT","Ghan","no","YHBY","HRY","YHBY","","","",""
|
|
||||||
"31745","AU-KGR","small_airport","Kulgera Airport","-25.8428","133.292007","","OC","AU","AU-NT","Ghan","no","","KGR","","","","",""
|
|
||||||
"44051","BGDH","small_airport","Danmarkshavn Landing Strip","76.76667","-18.666668","","NA","GL","GL-NE","Danmarkshavn","no","","","BGDH","","","",""
|
|
||||||
"299843","BGMI","small_airport","Station Nord Landing Strip","81.601292","-16.679306","35","NA","GL","GL-NE","Station Nord","no","","","BGMI","","","https://en.wikipedia.org/wiki/Nord,_Greenland",""
|
|
||||||
"32004","BGQQ","medium_airport","Qaanaaq Airport","77.488602","-69.388702","51","NA","GL","GL-AV","Qaanaaq","yes","BGQQ","NAQ","BGQQ","","","https://en.wikipedia.org/wiki/Qaanaaq_Airport","Mittarfik Qaanaaq, Thule"
|
|
||||||
"116","BGTL","medium_airport","Pituffik Space Base","76.53063","-68.700541","251","NA","GL","GL-AV","Pituffik","no","BGTL","THU","BGTL","","","https://en.wikipedia.org/wiki/Pituffik_Space_Base","Thule Air Base"
|
|
||||||
"874","CEM3","small_airport","Whatì Airport","63.131699","-117.246002","882","NA","CA","CA-NT","Whatì","yes","","YLE","CEM3","CEM3","","https://en.wikipedia.org/wiki/What%C3%AC_Airport","EM3, Lac la Martre, Wha Ti"
|
|
||||||
"299911","CA-0504","small_airport","Mary River Aerodrome","71.324167","-79.356944","584","NA","CA","CA-NU","Mary River","no","","YMV","","CMR2","","https://en.wikipedia.org/wiki/Mary_River_Aerodrome",""
|
|
||||||
"316098","CA-0551","seaplane_base","Cameron Bay Water Aerodrome","66.06","-117.89","512","NA","CA","CA-NT","Cameron Bay","no","","","","EA7","","",""
|
|
||||||
"316114","CA-0554","seaplane_base","Clarence Lagoon Water Aerodrome","69.62","-140.81","0","NA","CA","CA-YT","","no","","","","EC7","","",""
|
|
||||||
"316197","CA-0556","seaplane_base","Boffa Lake Water Aerodrome","69.637","-116.196","338","NA","CA","CA-NU","","no","","","","EX6","","",""
|
|
||||||
"342506","CA-0737","small_airport","Seal River Airstrip","59.154598","-94.785554","20","NA","CA","CA-MB","Churchill","no","","","","","","",""
|
|
||||||
"342507","CA-0738","small_airport","Nester One Airstrip","58.6529","-93.19061","26","NA","CA","CA-MB","Churchill","no","","","","","","",""
|
|
||||||
"723","CBU2","small_airport","Eddontenajon / Iskut Village Airport","57.847994155","-129.983968735","3100","NA","CA","CA-BC","Eddontenajon","no","","","CBU2","CBU2","","https://en.wikipedia.org/wiki/Eddontenajon/Iskut_Village_Airport","BU2"
|
|
||||||
"349351","CA-0771","small_airport","Arctic Watch Lodge Airport","74.065757","-93.785965","","NA","CA","CA-NU","Somerset Island","no","","","CRW4","RW4","","https://en.wikipedia.org/wiki/Arctic_Watch_Lodge_Aerodrome",""
|
|
||||||
"430490","CA-0815","small_airport","Nuskenford Airstrip","69.863861","-126.843167","","NA","CA","CA-NT","Nuskenford","no","","","","","","",""
|
|
||||||
"524817","CA-0924","seaplane_base","Herschel Island Water Aerodrome","69.572","-138.93","0","NA","CA","CA-YT","Herschel","no","","","","EG8","","",""
|
|
||||||
"595702","CA-1179","small_airport","Cassiar Aerodrome","59.277137","-129.805044","3618","NA","CA","CA-BC","Cassiar","no","","","","AU9","","",""
|
|
||||||
"606385","CA-1249","small_airport","Fort Conger Airstrip","81.754925","-64.824958","15","NA","CA","CA-NU","Qikiqtaaluk Region","no","","","","CA1249","","","FCON"
|
|
||||||
"606387","CA-1250","small_airport","Lake Hazen Airstrip","81.823025","-71.360321","10","NA","CA","CA-NU","Qikiqtaaluk Region","no","","","","CA1250","","","LHAZ"
|
|
||||||
"606493","CA-1251","small_airport","McGill Arctic Research Station (MARS)","79.41596","-90.761018","","NA","CA","CA-NU","Axel Heiberg Island","no","","","","","","",""
|
|
||||||
"607046","CA-1252","small_airport","Ward Hunt Island Airport","83.091029","-74.138317","","NA","CA","CA-NU","Qikiqtaaluk Region","no","","","","CA1252","","https://en.wikipedia.org/wiki/Ward_Hunt_Island",""
|
|
||||||
"609524","CA-1259","small_airport","Bathurst Inlet Airport","66.836865","-108.011278","36","NA","CA","CA-NU","Bathurst Inlet/Qingaut","no","","","","","","","ᕿᙵᐅᓐ"
|
|
||||||
"28437","CAH9","seaplane_base","Telegraph Creek Seaplane Base","57.9071","-131.18946","1129","NA","CA","CA-BC","Telegraph Creek","no","","","CAH9","CAH9","","https://en.wikipedia.org/wiki/Telegraph_Creek_Water_Aerodrome","AH9"
|
|
||||||
"665","CBC2","small_airport","Ford Bay Airport","66.0374984741211","-124.71499633789062","673","NA","CA","CA-NT","Ford Bay","no","","","CBC2","CBC2","","https://en.wikipedia.org/wiki/Ford_Bay_Airport","BC2"
|
|
||||||
"672","CBD6","small_airport","Nahanni Butte Airport","61.029701232910156","-123.38899993896484","600","NA","CA","CA-NT","Nahanni Butte","no","","","CBD6","CBD6","","https://en.wikipedia.org/wiki/Nahanni_Butte_Airport","BD6"
|
|
||||||
"686","CBH4","small_airport","Prairie Creek Airport","61.564701080322266","-124.81500244140625","2950","NA","CA","CA-NT","Prairie Creek","no","","","CBH4","CBH4","","https://en.wikipedia.org/wiki/Prairie_Creek_Airport","BH4"
|
|
||||||
"736","CBX5","small_airport","Tungsten (Cantung) Airport","61.956901550293","-128.20300292969","3500","NA","CA","CA-NT","Tungsten","no","","TNS","CBX5","CBX5","","https://en.wikipedia.org/wiki/Tungsten_(Cantung)_Airport","BX5"
|
|
||||||
"814","CDK2","small_airport","Diavik Airport","64.5113983154","-110.289001465","1413","NA","CA","CA-NT","Diavik","no","","DVK","CDK2","CDK2","","https://en.wikipedia.org/wiki/Diavik_Airport","DK2"
|
|
||||||
"43879","CDL7","small_airport","Doris Lake","68.1252746582","-106.585281372","50","NA","CA","CA-NU","Hope Bay","no","","JOJ","","CDL7","","https://en.wikipedia.org/wiki/Doris_Lake_Aerodrome",""
|
|
||||||
"1802","CYLK","small_airport","Lutselk'e Airport","62.417823","-110.682793","596","NA","CA","CA-NT","Lutselk'e","yes","CYLK","YSG","CYLK","","","https://en.wikipedia.org/wiki/Lutselk'e_Airport","YLK, EL3, Snowdrift Airport"
|
|
||||||
"314953","CYVL","small_airport","Tommy Kochon Airport","67.02015","-126.128364","870","NA","CA","CA-NT","Colville Lake","yes","CYVL","YCK","CYVL","","","https://en.wikipedia.org/wiki/Colville_Lake/Tommy_Kochon_Aerodrome",""
|
|
||||||
"925","CFA7","small_airport","Taltheilei Narrows Airport","62.5980987549","-111.542999268","570","NA","CA","CA-NT","Taltheilei Narrows","no","","GSL","CFA7","CFA7","","https://en.wikipedia.org/wiki/Taltheilei_Narrows_Airport","FA7"
|
|
||||||
"1726","CYEV","medium_airport","Inuvik Mike Zubko Airport","68.30419921880001","-133.483001709","224","NA","CA","CA-NT","Inuvik","yes","CYEV","YEV","CYEV","","","https://en.wikipedia.org/wiki/Inuvik_(Mike_Zubko)_Airport",""
|
|
||||||
"1868","CYQH","medium_airport","Watson Lake Airport","60.116839","-128.821993","2255","NA","CA","CA-YT","Watson Lake","yes","CYQH","YQH","CYQH","","","https://en.wikipedia.org/wiki/Watson_Lake_Airport",""
|
|
||||||
"1948","CYWJ","small_airport","Déline Airport","65.211098","-123.435997","703","NA","CA","CA-NT","Déline","yes","CYWJ","YWJ","CYWJ","","","https://en.wikipedia.org/wiki/Deline_Airport","Délı̨nę, Fort Franklin"
|
|
||||||
"1993","CYZF","medium_airport","Yellowknife International Airport","62.462799","-114.440002","675","NA","CA","CA-NT","Yellowknife","yes","CYZF","YZF","CYZF","","https://www.inf.gov.nt.ca/en/services/airports/yellowknife-airport","https://en.wikipedia.org/wiki/Yellowknife_Airport",""
|
|
||||||
"28331","CEP9","seaplane_base","Namushka Lodge Seaplane Base","62.416698","-113.349998","670","NA","CA","CA-NT","","no","","","CEP9","CEP9","","https://en.wikipedia.org/wiki/Namushka_Lodge_Water_Aerodrome","EP9"
|
|
||||||
"1786","CYKD","small_airport","Aklavik/Freddie Carmichael Airport","68.223297","-135.00599","23","NA","CA","CA-NT","Aklavik","yes","CYKD","LAK","CYKD","","","https://en.wikipedia.org/wiki/Aklavik_Airport","YKD"
|
|
||||||
"28159","CES6","seaplane_base","Arctic Red River Seaplane Base","67.449997","-133.75","20","NA","CA","CA-NT","","no","","","","ES6","","https://en.wikipedia.org/wiki/Arctic_Red_River_Water_Aerodrome",""
|
|
||||||
"944","CFF4","small_airport","Great Bear Lake Airport","66.703053","-119.716816","562","NA","CA","CA-NT","Great Bear Lake","no","","DAS","CFF4","CFF4","","https://en.wikipedia.org/wiki/Great_Bear_Lake_Airport","FF4"
|
|
||||||
"1737","CYFS","medium_airport","Fort Simpson Airport","61.76020050048828","-121.23699951171875","555","NA","CA","CA-NT","Fort Simpson","yes","CYFS","YFS","CYFS","","","https://en.wikipedia.org/wiki/Fort_Simpson_Airport",""
|
|
||||||
"901","CET9","small_airport","Jean Marie River Airport","61.522449","-120.625334","470","NA","CA","CA-NT","Jean Marie River","no","","","CET9","CET9","","https://en.wikipedia.org/wiki/Jean_Marie_River_Airport","ET9"
|
|
||||||
"1940","CYVQ","medium_airport","Norman Wells Airport","65.28160095214844","-126.7979965209961","238","NA","CA","CA-NT","Norman Wells","yes","CYVQ","YVQ","CYVQ","","","https://en.wikipedia.org/wiki/Norman_Wells_Airport",""
|
|
||||||
"909","CEV9","small_airport","Snare River Airport","63.4333","-116.174963","700","NA","CA","CA-NT","Snare River","no","","","CEV9","CEV9","","https://en.wikipedia.org/wiki/Snare_River_Airport","EV9"
|
|
||||||
"1843","CYPC","small_airport","Paulatuk (Nora Aliqatchialuk Ruben) Airport","69.360838","-124.07547","15","NA","CA","CA-NT","Paulatuk","yes","CYPC","YPC","CYPC","","","https://en.wikipedia.org/wiki/Paulatuk_Airport",""
|
|
||||||
"933","CFC4","small_airport","Macmillan Pass Airport","63.181098938","-130.20199585","3810","NA","CA","CA-YT","Macmillan Pass","no","","XMP","CFC4","CFC4","","https://en.wikipedia.org/wiki/Macmillian_Pass_Airport","FC4"
|
|
||||||
"996","CFT3","small_airport","Finlayson Lake Airport","61.6913986206","-130.774002075","3094","NA","CA","CA-YT","Finlayson Lake","no","","","CFT3","CFT3","","https://en.wikipedia.org/wiki/Finlayson_Lake_Airport","FT3"
|
|
||||||
"997","CFT5","small_airport","Hyland Airport","61.52389907836914","-128.2689971923828","3000","NA","CA","CA-YT","Hyland","no","","","CFT5","CFT5","","https://en.wikipedia.org/wiki/Hyland_Airport","FT5"
|
|
||||||
"28459","CFV5","seaplane_base","Virginia Falls Seaplane Base","61.607575","-125.756272","1702","NA","CA","CA-NT","","no","","","CFV5","CFV5","","https://en.wikipedia.org/wiki/Virginia_Falls_Water_Aerodrome",""
|
|
||||||
"1021","CFY5","small_airport","Pine Lake","60.10309982299805","-130.9340057373047","3250","NA","CA","CA-YT","Pine Lake","no","","","CFY5","CFY5","","https://en.wikipedia.org/wiki/Daughney_Aerodrome","FY5"
|
|
||||||
"44373","CGK2","small_airport","Gahcho Kue","63.435198","-109.144812","1371","NA","CA","CA-NT","Kennedy Lake","no","","GHK","CGK2","CGK2","","https://en.wikipedia.org/wiki/Gahcho_Kue_Aerodrome","De Beers Canada"
|
|
||||||
"308297","CGR3","small_airport","George Lake Aerodrome","65.928056","-107.462222","1150","NA","CA","CA-NU","","no","","","CGR3","CGR3","","https://en.wikipedia.org/wiki/George_Lake_Aerodrome",""
|
|
||||||
"308296","CGS2","small_airport","Goose Lake Aerodrome","65.552778","-106.433611","907","NA","CA","CA-NU","","no","","","CGS2","CGS2","","https://en.wikipedia.org/wiki/Goose_Lake_Aerodrome",""
|
|
||||||
"308295","CHC5","small_airport","Hayes Camp Aerodrome","66.661012","-91.55346","780","NA","CA","CA-NU","","no","","","CHC5","CHC5","","https://en.wikipedia.org/wiki/Hayes_Camp_Aerodrome",""
|
|
||||||
"1685","CYCB","medium_airport","Cambridge Bay Airport","69.1081008911","-105.138000488","90","NA","CA","CA-NU","Cambridge Bay","yes","CYCB","YCB","CYCB","","","https://en.wikipedia.org/wiki/Cambridge_Bay_Airport",""
|
|
||||||
"1674","CYBK","medium_airport","Baker Lake Airport","64.29889678960001","-96.077796936","59","NA","CA","CA-NU","Baker Lake","yes","CYBK","YBK","CYBK","","","https://en.wikipedia.org/wiki/Baker_Lake_Airport",""
|
"1674","CYBK","medium_airport","Baker Lake Airport","64.29889678960001","-96.077796936","59","NA","CA","CA-NU","Baker Lake","yes","CYBK","YBK","CYBK","","","https://en.wikipedia.org/wiki/Baker_Lake_Airport",""
|
||||||
"28228","CJN8","seaplane_base","Fort Reliance Seaplane Base","62.7","-109.167","514","NA","CA","CA-NT","Fort Reliance","no","","YFL","CJN8","CJN8","","https://en.wikipedia.org/wiki/Fort_Reliance_Water_Aerodrome","JN8"
|
"1726","CYEV","medium_airport","Inuvik Mike Zubko Airport","68.30419921880001","-133.483001709","224","NA","CA","CA-NT","Inuvik","yes","CYEV","YEV","CYEV","","","https://en.wikipedia.org/wiki/Inuvik_(Mike_Zubko)_Airport",""
|
||||||
"1111","CJQ6","small_airport","Tanquary Fiord Airport","81.409422","-76.867901","50","NA","CA","CA-NU","Tanquary Fiord","no","","","CJQ6","CJQ6","","https://en.wikipedia.org/wiki/Tanquary_Fiord_Airport","JQ6"
|
|
||||||
"299180","CMB2","small_airport","Meadowbank Airport","65.0246615457","-96.06865882870001","475","NA","CA","CA-NU","Agnico-Eagle Meadowbank Gold Mine","no","","","CMB2","CMB2","","https://en.wikipedia.org/wiki/Meadowbank_Aerodrome",""
|
|
||||||
"1308","CNH2","small_airport","Natuashish Airport","55.913898","-61.184399","30","NA","CA","CA-NL","Natuashish","yes","","YNP","CNH2","CNH2","","https://en.wikipedia.org/wiki/Natuashish_Airport","NH2"
|
|
||||||
"1486","CRE2","small_airport","Edzo Airport","62.766701","-116.084","587","NA","CA","CA-NT","Rae-Edzo","no","","","CRE2","CRE2","","https://en.wikipedia.org/wiki/Rae/Edzo_Airport","RE2"
|
|
||||||
"1718","CYEK","small_airport","Arviat Airport","61.0942","-94.070801","32","NA","CA","CA-NU","Arviat","yes","CYEK","YEK","CYEK","","","https://en.wikipedia.org/wiki/Arviat_Airport",""
|
|
||||||
"1531","CSK6","small_airport","Snap Lake Airport","63.593601","-110.905998","1557","NA","CA","CA-NT","Snap Lake Mine","no","","YNX","","","","https://en.wikipedia.org/wiki/Snap_Lake_Airport","CSK6"
|
|
||||||
"316099","CTM7","small_airport","Tundra Mine/Salamita Mine Aerodrome","64.0725","-111.158","1445","NA","CA","CA-NT","Tundra and Salamita Mines","no","","","CTM7","CTM7","","https://en.wikipedia.org/wiki/Tundra_Mine/Salamita_Mine_Aerodrome",""
|
|
||||||
"1608","CTP9","small_airport","Donaldson Airport","61.662201","-73.321404","1902","NA","CA","CA-QC","Kattiniq","no","","YAU","CTP9","CTP9","","https://en.wikipedia.org/wiki/Kattiniq/Donaldson_Airport",""
|
|
||||||
"1712","CYDP","small_airport","Nain Airport","56.550778","-61.682224","22","NA","CA","CA-NL","Nain","yes","CYDP","YDP","CYDP","","","https://en.wikipedia.org/wiki/Nain_Airport",""
|
|
||||||
"300457","CWJC","small_airport","Ennadai Lake Airport","61.1333333333","-100.9","1021","NA","CA","CA-NU","Ennadai","no","","","CWJC","","","",""
|
|
||||||
"46596","CYAB","small_airport","Arctic Bay Airport","73.006101","-85.04616","72","NA","CA","CA-NU","Arctic Bay","yes","CYAB","YAB","CYAB","","","https://en.wikipedia.org/wiki/Arctic_Bay_Airport","CJX7"
|
|
||||||
"1659","CYAS","small_airport","Kangirsuk Airport","60.027199","-69.999199","403","NA","CA","CA-QC","Kangirsuk","yes","CYAS","YKG","CYAS","","","https://en.wikipedia.org/wiki/Kangirsuk_Airport","YAS"
|
|
||||||
"1668","CYBB","small_airport","Kugaaruk Airport","68.535711","-89.805508","56","NA","CA","CA-NU","Kugaaruk","yes","CYBB","YBB","CYBB","","","https://en.wikipedia.org/wiki/Kugaaruk_Airport","YBB, Pelly Bay Townsite Airport"
|
|
||||||
"1693","CYCO","small_airport","Kugluktuk Airport","67.816408","-115.14307","74","NA","CA","CA-NU","Kugluktuk","yes","CYCO","YCO","CYCO","","","https://en.wikipedia.org/wiki/Kugluktuk_Airport","Copper Mine Airport"
|
|
||||||
"1697","CYCS","small_airport","Chesterfield Inlet Airport","63.346901","-90.731102","32","NA","CA","CA-NU","Chesterfield Inlet","yes","CYCS","YCS","CYCS","","","https://en.wikipedia.org/wiki/Chesterfield_Inlet_Airport",""
|
|
||||||
"353838","CYD2","seaplane_base","Yellow Dog Lodge Seaplane Base","62.890556","-113.867778","725","NA","CA","CA-NT","Graham Lake","no","","","CYD2","CYD2","https://yellowdoglodge.ca/","https://en.wikipedia.org/wiki/Graham_Lake_(Yellow_Dog_Lodge)_Water_Aerodrome",""
|
|
||||||
"1708","CYDL","small_airport","Dease Lake Airport","58.422199","-130.031998","2600","NA","CA","CA-BC","Dease Lake","yes","CYDL","YDL","CYDL","","","https://en.wikipedia.org/wiki/Dease_Lake_Airport","YDL"
|
|
||||||
"1725","CYEU","small_airport","Eureka Airport","79.9946975708","-85.814201355","256","NA","CA","CA-NU","Eureka","no","CYEU","YEU","CYEU","","","https://en.wikipedia.org/wiki/Eureka_Aerodrome","YEU"
|
|
||||||
"1742","CYGH","small_airport","Fort Good Hope Airport","66.240658","-128.647757","268","NA","CA","CA-NT","Fort Good Hope","yes","CYGH","YGH","CYGH","","","https://en.wikipedia.org/wiki/Fort_Good_Hope_Airport",""
|
|
||||||
"1750","CYGT","small_airport","Igloolik Airport","69.3647","-81.816101","174","NA","CA","CA-NU","Igloolik","yes","CYGT","YGT","CYGT","","","https://en.wikipedia.org/wiki/Igloolik_Airport",""
|
|
||||||
"1752","CYGW","medium_airport","Kuujjuarapik Airport","55.281898498535156","-77.76529693603516","34","NA","CA","CA-QC","Kuujjuarapik","yes","CYGW","YGW","CYGW","","","https://en.wikipedia.org/wiki/Kuujjuarapik_Airport",""
|
"1752","CYGW","medium_airport","Kuujjuarapik Airport","55.281898498535156","-77.76529693603516","34","NA","CA","CA-QC","Kuujjuarapik","yes","CYGW","YGW","CYGW","","","https://en.wikipedia.org/wiki/Kuujjuarapik_Airport",""
|
||||||
"1754","CYGZ","small_airport","Grise Fiord Airport","76.425823","-82.908583","146","NA","CA","CA-NU","Grise Fiord","yes","CYGZ","YGZ","CYGZ","","","https://en.wikipedia.org/wiki/Grise_Fiord_Airport",""
|
|
||||||
"1761","CYHI","small_airport","Ulukhaktok Holman Airport","70.762802","-117.806","117","NA","CA","CA-NT","Ulukhaktok","yes","CYHI","YHI","CYHI","","","https://en.wikipedia.org/wiki/Ulukhaktok/Holman_Airport",""
|
|
||||||
"1762","CYHK","small_airport","Gjoa Haven Airport","68.635597","-95.849701","152","NA","CA","CA-NU","Gjoa Haven","yes","CYHK","YHK","CYHK","","","https://en.wikipedia.org/wiki/Gjoa_Haven_Airport",""
|
|
||||||
"1765","CYHO","small_airport","Hopedale Airport","55.448757","-60.228124","39","NA","CA","CA-NL","Hopedale","yes","CYHO","YHO","CYHO","","","https://en.wikipedia.org/wiki/Hopedale_Airport","CC5"
|
|
||||||
"1774","CYIK","small_airport","Ivujivik Airport","62.417301","-77.925301","126","NA","CA","CA-QC","Ivujivik","yes","CYIK","YIK","CYIK","","","https://en.wikipedia.org/wiki/Ivujivik_Airport",""
|
|
||||||
"1775","CYIO","small_airport","Pond Inlet Airport","72.689494","-77.968941","181","NA","CA","CA-NU","Pond Inlet","yes","CYIO","YIO","CYIO","","","https://en.wikipedia.org/wiki/Pond_Inlet_Airport",""
|
|
||||||
"1788","CYKG","small_airport","Kangiqsujuaq (Wakeham Bay) Airport","61.5886","-71.929398","501","NA","CA","CA-QC","Kangiqsujuaq","yes","CYKG","YWB","CYKG","","","https://en.wikipedia.org/wiki/Kangiqsujuaq_(Wakeham_Bay)_Airport",""
|
|
||||||
"1791","CYKO","small_airport","Akulivik Airport","60.8186","-78.148598","75","NA","CA","CA-QC","Akulivik","yes","CYKO","AKV","CYKO","","","https://en.wikipedia.org/wiki/Akulivik_Airport","YKO"
|
|
||||||
"1796","CYLA","small_airport","Aupaluk Airport","59.2967","-69.599701","119","NA","CA","CA-QC","Aupaluk","yes","CYLA","YPJ","CYLA","","","https://en.wikipedia.org/wiki/Aupaluk_Airport","YLA"
|
|
||||||
"1806","CYLT","medium_airport","Alert Airport","82.517263","-62.283037","100","NA","CA","CA-NU","Alert","no","CYLT","YLT","CYLT","","","https://en.wikipedia.org/wiki/Alert_Airport","YLT"
|
|
||||||
"1818","CYMU","small_airport","Umiujaq Airport","56.536098","-76.518303","250","NA","CA","CA-QC","Umiujaq","yes","CYMU","YUD","CYMU","","","https://en.wikipedia.org/wiki/Umiujaq_Airport","YMU"
|
|
||||||
"1847","CYPH","small_airport","Inukjuak Airport","58.471901","-78.076897","83","NA","CA","CA-QC","Inukjuak","yes","CYPH","YPH","CYPH","","","https://en.wikipedia.org/wiki/Inukjuak_Airport",""
|
|
||||||
"1860","CYPX","medium_airport","Puvirnituq Airport","60.050598","-77.286903","74","NA","CA","CA-QC","Puvirnituq","yes","CYPX","YPX","CYPX","","","https://en.wikipedia.org/wiki/Puvirnituq_Airport",""
|
|
||||||
"1884","CYRA","small_airport","Rae Lakes Airport","64.116096","-117.309998","723","NA","CA","CA-NT","Gamètì","yes","CYRA","YRA","CYRA","","","https://en.wikipedia.org/wiki/Gam%C3%A8t%C3%AC/Rae_Lakes_Airport",""
|
|
||||||
"1885","CYRB","medium_airport","Resolute Bay Airport","74.7169036865","-94.9693984985","215","NA","CA","CA-NU","Resolute Bay","yes","CYRB","YRB","CYRB","","","https://en.wikipedia.org/wiki/Resolute_Bay_Airport",""
|
"1885","CYRB","medium_airport","Resolute Bay Airport","74.7169036865","-94.9693984985","215","NA","CA","CA-NU","Resolute Bay","yes","CYRB","YRB","CYRB","","","https://en.wikipedia.org/wiki/Resolute_Bay_Airport",""
|
||||||
"1895","CYRT","medium_airport","Rankin Inlet Airport","62.8114013672","-92.1157989502","94","NA","CA","CA-NU","Rankin Inlet","yes","CYRT","YRT","CYRT","","","https://en.wikipedia.org/wiki/Rankin_Inlet_Airport",""
|
|
||||||
"1905","CYSK","small_airport","Sanikiluaq Airport","56.536891","-79.250221","104","NA","CA","CA-NU","Sanikiluaq","yes","CYSK","YSK","CYSK","","","https://en.wikipedia.org/wiki/Sanikiluaq_Airport",""
|
|
||||||
"1915","CYSY","small_airport","Sachs Harbour (David Nasogaluak Jr. Saaryuaq) Airport","71.993896","-125.242996","282","NA","CA","CA-NT","Sachs Harbour","yes","CYSY","YSY","CYSY","","","https://en.wikipedia.org/wiki/Sachs_Harbour_Airport",""
|
|
||||||
"1918","CYTE","small_airport","Cape Dorset Airport","64.230003","-76.526703","164","NA","CA","CA-NU","Kinngait","yes","CYTE","YTE","CYTE","","","https://en.wikipedia.org/wiki/Cape_Dorset_Airport",""
|
|
||||||
"1923","CYTQ","small_airport","Tasiujaq Airport","58.667801","-69.955803","122","NA","CA","CA-QC","Tasiujaq","yes","CYTQ","YTQ","CYTQ","","","https://en.wikipedia.org/wiki/Tasiujaq_Airport",""
|
|
||||||
"1927","CYUB","small_airport","Tuktoyaktuk / James Gruben Airport","69.433296","-133.026001","15","NA","CA","CA-NT","Tuktoyaktuk","no","CYUB","YUB","CYUB","","","https://en.wikipedia.org/wiki/Tuktoyaktuk/James_Gruben_Airport",""
|
|
||||||
"1929","CYUT","small_airport","Naujaat Airport","66.521024","-86.225166","80","NA","CA","CA-NU","Repulse Bay","yes","CYUT","YUT","CYUT","","","https://en.wikipedia.org/wiki/Repulse_Bay_Airport","Repulse Bay Airport"
|
|
||||||
"1930","CYUX","medium_airport","Hall Beach Airport","68.7761","-81.2425","30","NA","CA","CA-NU","Sanirajak","yes","CYUX","YUX","CYUX","","","https://en.wikipedia.org/wiki/Hall_Beach_Airport",""
|
|
||||||
"1939","CYVP","medium_airport","Kuujjuaq Airport","58.096099853515625","-68.4269027709961","129","NA","CA","CA-QC","Kuujjuaq","yes","CYVP","YVP","CYVP","","","https://en.wikipedia.org/wiki/Kuujjuaq_Airport",""
|
|
||||||
"954","CYWE","small_airport","Wekweètì Airport","64.190804","-114.077002","1208","NA","CA","CA-NT","Wekweètì","yes","CYWE","YFJ","CYWE","CFJ7","","https://en.wikipedia.org/wiki/Wekwe%C3%A8t%C3%AC_Airport","Wekweti, Snare Lake"
|
|
||||||
"1954","CYWY","medium_airport","Wrigley Airport","63.20940017700195","-123.43699645996094","489","NA","CA","CA-NT","Wrigley","no","CYWY","YWY","CYWY","","","https://en.wikipedia.org/wiki/Wrigley_Airport",""
|
|
||||||
"1962","CYXN","small_airport","Whale Cove Airport","62.240002","-92.598099","40","NA","CA","CA-NU","Whale Cove","yes","CYXN","YXN","CYXN","","","https://en.wikipedia.org/wiki/Whale_Cove_Airport",""
|
|
||||||
"1978","CYYH","small_airport","Taloyoak Airport","69.5467","-93.576698","92","NA","CA","CA-NU","Taloyoak","yes","CYYH","YYH","CYYH","","","https://en.wikipedia.org/wiki/Taloyoak_Airport","Spence Bay"
|
|
||||||
"1984","CYYQ","medium_airport","Churchill Airport","58.739200592041016","-94.06500244140625","94","NA","CA","CA-MB","Churchill","yes","CYYQ","YYQ","CYYQ","","","https://en.wikipedia.org/wiki/Churchill_Airport",""
|
|
||||||
"1994","CYZG","small_airport","Salluit Airport","62.179401","-75.667198","743","NA","CA","CA-QC","Salluit","yes","CYZG","YZG","CYZG","","","https://en.wikipedia.org/wiki/Salluit_Airport",""
|
|
||||||
"1998","CYZS","medium_airport","Coral Harbour Airport","64.1932983398","-83.3593978882","210","NA","CA","CA-NU","Coral Harbour","yes","CYZS","YZS","CYZS","","","https://en.wikipedia.org/wiki/Coral_Harbour_Airport",""
|
|
||||||
"2017","CZFM","small_airport","Fort Mcpherson Airport","67.406993","-134.860182","116","NA","CA","CA-NT","Fort Mcpherson","yes","CZFM","ZFM","CZFM","","","https://en.wikipedia.org/wiki/Fort_McPherson_Airport",""
|
|
||||||
"2018","CZFN","small_airport","Tulita Airport","64.909496","-125.570297","332","NA","CA","CA-NT","Tulita","yes","CZFN","ZFN","CZFN","","","https://en.wikipedia.org/wiki/Tulita_Airport","Fort Norman"
|
|
||||||
"307365","EGAH","small_airport","Halley Research Station","-75.567406","-25.516435","103","AN","AQ","AQ-U-A","Halley Research Station","no","EGAH","","EGAH","","","https://en.wikipedia.org/wiki/Halley_Research_Station","Halley, Antarctica, British Antarctic Survey"
|
|
||||||
"324046","EGAT","small_airport","Sky Blu Airstrip","-74.849722","-71.566666","4740","AN","AQ","AQ-U-A","Sky Blu","no","EGAT","","EGAT","","https://www.bas.ac.uk/polar-operations/sites-and-facilities/facility/rothera/sky-blu/","https://en.wikipedia.org/wiki/Sky_Blu",""
|
|
||||||
"31004","ENAS","small_airport","Ny-Ålesund Airport, Hamnerabben","78.927498","11.8743","50","EU","NO","NO-21","Ny-Ålesund","no","","","ENAS","","","https://en.wikipedia.org/wiki/Ny-%C3%85lesund_Airport,_Hamnerabben","Brøggerhalvøya Airport"
|
|
||||||
"2877","FHAW","medium_airport","RAF Ascension Island","-7.970179","-14.392744","278","AF","SH","SH-AC","Cat Hill","yes","FHAW","ASI","FHAW","","https://www.raf.mod.uk/our-organisation/stations/ascension-island-base/","https://en.wikipedia.org/wiki/RAF_Ascension_Island","Wideawake Airfield, Ascension Island Auxiliary Field"
|
"2877","FHAW","medium_airport","RAF Ascension Island","-7.970179","-14.392744","278","AF","SH","SH-AC","Cat Hill","yes","FHAW","ASI","FHAW","","https://www.raf.mod.uk/our-organisation/stations/ascension-island-base/","https://en.wikipedia.org/wiki/RAF_Ascension_Island","Wideawake Airfield, Ascension Island Auxiliary Field"
|
||||||
"318444","FHSH","medium_airport","Saint Helena International Airport","-15.958898","-5.646066","1017","AF","SH","SH-SH","Jamestown","yes","FHSH","HLE","FHSH","","http://sthelenaairport.com/","https://en.m.wikipedia.org/wiki/Saint_Helena_Airport#",""
|
|
||||||
"44073","GL-0006","small_airport","Summit Ice Landing Strip","72.616669","-38.5","10523","NA","GL","GL-NE","Summit Camp","no","","","","","","https://en.wikipedia.org/wiki/Summit_Camp","SUMUD"
|
|
||||||
"44064","GL-0003","small_airport","NorthGRIP Airport","75.099998","-42.316666","","NA","GL","GL-NE","NorthGRIP","no","","","","","","","GIRPA, North Greenland Ice Core Project"
|
|
||||||
"505046","GL-0014","small_airport","EastGRIP Airport","75.63","-35.99","","NA","GL","GL-NE","EastGRIP","no","","","","","","","East Greenland Ice-Core Project"
|
|
||||||
"4582","HL56","medium_airport","Matan al-Sarra Air Base","21.6877","21.8309","1769","AF","LY","LY-KF","","no","","","HL56","HL56","","https://en.wikipedia.org/wiki/Maaten_al-Sarra_Air_Base",""
|
|
||||||
"19520","KCN","seaplane_base","Chernofski Harbor Seaplane Base","53.402899","-167.520272","","NA","US","US-AK","Chernofski Harbor","no","","KCN","KCN","KCN","","http://wikimapia.org/6966644/Port-of-Chernofski-Harbor",""
|
|
||||||
"26910","YBIE","medium_airport","Bedourie Airport","-24.3461","139.460007","300","OC","AU","AU-QLD","Bedourie","yes","YBIE","BEU","YBIE","","","https://en.wikipedia.org/wiki/Bedourie_Airport",""
|
|
||||||
"308030","PAUT","small_airport","Akutan Airport","54.14459","-165.604332","133","NA","US","US-AK","Akutan","yes","PAUT","KQA","PAUT","7AK","https://web.archive.org/web/20100410064944/http://dot.alaska.gov/creg/akutan/assets/Akun_ALP_Sheet-Set-1-9.pdf","https://en.wikipedia.org/wiki/Akutan_Airport","Akun Airport"
|
|
||||||
"31907","NCMH","small_airport","Manihiki Island Airport","-10.38091","-160.999424","11","OC","CK","CK-U-A","Manihiki Island","yes","NCMH","MHX","NCMH","","","https://en.wikipedia.org/wiki/Manihiki_Island_Airport","Humphrey Island, Te Fuinga o Niva"
|
|
||||||
"32184","NCPY","small_airport","Tongareva Airport","-9.01437","-158.03241","8","OC","CK","CK-U-A","Penrhyn Island","no","NCPY","PYE","NCPY","","","https://en.wikipedia.org/wiki/Tongareva_Airport",""
|
|
||||||
"4986","NTGE","medium_airport","Reao Airport","-18.46652","-136.43855","12","OC","PF","PF-U-A","Reao","no","NTGE","REA","NTGE","","","https://en.wikipedia.org/wiki/Reao_Airport",""
|
|
||||||
"4989","NTGJ","medium_airport","Totegegie Airport","-23.07990074157715","-134.88999938964844","7","OC","PF","PF-U-A","","yes","NTGJ","GMR","NTGJ","","","https://en.wikipedia.org/wiki/Totegegie_Airport",""
|
"4989","NTGJ","medium_airport","Totegegie Airport","-23.07990074157715","-134.88999938964844","7","OC","PF","PF-U-A","","yes","NTGJ","GMR","NTGJ","","","https://en.wikipedia.org/wiki/Totegegie_Airport",""
|
||||||
"32456","NTGO","small_airport","Tatakoto Airport","-17.355226","-138.44734","12","OC","PF","PF-U-A","Tatakoto","yes","NTGO","TKV","NTGO","","","https://en.wikipedia.org/wiki/Tatakoto_Airport",""
|
|
||||||
"4992","NTGP","small_airport","Puka Puka Airport","-14.80955","-138.812621","5","OC","PF","PF-U-A","","yes","NTGP","PKP","NTGP","","","https://en.wikipedia.org/wiki/Puka-Puka_Airport",""
|
|
||||||
"32177","NTGQ","small_airport","Pukaruha Airport","-18.295726","-137.016291","5","OC","PF","PF-U-A","Pukaruha","no","NTGQ","PUK","NTGQ","","","https://en.wikipedia.org/wiki/Pukarua_Airport",""
|
|
||||||
"44636","NTGS","small_airport","Marutea Airport","-21.482194900512695","-135.63705444335938","10","OC","PF","PF-U-A","Auorotini","no","","","NTGS","","","https://en.wikipedia.org/wiki/Marutea_Sud",""
|
|
||||||
"32055","NTGW","small_airport","Nukutavake Airport","-19.284613","-138.768367","17","OC","PF","PF-U-A","Nukutavake","no","NTGW","NUK","NTGW","","","https://en.wikipedia.org/wiki/Nukutavake_Airport",""
|
|
||||||
"4996","NTGY","small_airport","Tureia Airport","-20.784262","-138.56796","12","OC","PF","PF-U-A","Tureia","no","NTGY","ZTA","NTGY","","","https://en.wikipedia.org/wiki/Tureia_Airport",""
|
|
||||||
"31128","NTKH","small_airport","Fakahina Airport","-15.992259","-140.164246","3","OC","PF","PF-U-A","Fakahina","yes","NTKH","FHZ","NTKH","","","https://en.wikipedia.org/wiki/Fakahina_Airfield",""
|
|
||||||
"5001","NTMD","medium_airport","Nuku Hiva Airport","-8.7956","-140.229004","220","OC","PF","PF-U-A","Nuku Hiva","yes","NTMD","NHV","NTMD","","","https://en.wikipedia.org/wiki/Nuku_Hiva_Airport",""
|
"5001","NTMD","medium_airport","Nuku Hiva Airport","-8.7956","-140.229004","220","OC","PF","PF-U-A","Nuku Hiva","yes","NTMD","NHV","NTMD","","","https://en.wikipedia.org/wiki/Nuku_Hiva_Airport",""
|
||||||
"5002","NTMN","medium_airport","Hiva Oa-Atuona Airport","-9.76879024506","-139.011001587","1481","OC","PF","PF-U-A","Hiva Oa Island","yes","NTMN","AUQ","NTMN","","","https://en.wikipedia.org/wiki/Atuona_Airport","HIX"
|
|
||||||
"32499","NTMP","small_airport","Ua Pou Airport","-9.35167","-140.078003","16","OC","PF","PF-U-A","Ua Pou","yes","NTMP","UAP","NTMP","","","https://en.wikipedia.org/wiki/Ua_Pou_Airport",""
|
|
||||||
"32497","NTMU","small_airport","Ua Huka Airport","-8.936228","-139.554062","160","OC","PF","PF-U-A","Ua Huka","yes","NTMU","UAH","NTMU","","","https://en.wikipedia.org/wiki/Ua_Huka_Airport",""
|
|
||||||
"32053","NTTX","small_airport","Moruroa Airport","-21.80978","-138.813385","7","OC","PF","PF-TG","Moruroa Atoll","no","NTTX","UOA","NTTX","","","","Mururoa, Mururura, Aopuni"
|
|
||||||
"32573","NTUV","small_airport","Vahitahi Airport","-18.780697","-138.85568","9","OC","PF","PF-U-A","Vahitahi","no","NTUV","VHZ","NTUV","","","https://en.wikipedia.org/wiki/Vahitahi_Airport",""
|
|
||||||
"11","NZ12","small_airport","Palmer Station Airport","-64.774582","-64.035907","149","AN","AQ","AQ-U-A","Palmer Station","no","","","NZ0B","NZ0B","","https://en.wikipedia.org/wiki/Palmer_Station",""
|
|
||||||
"340683","NZFX","small_airport","Phoenix Airfield","-77.956389","166.766667","18","AN","AQ","AQ-U-A","McMurdo Station","no","","","NZFX","","","https://en.wikipedia.org/wiki/Phoenix_Airfield",""
|
|
||||||
"16190","PAAK","small_airport","Atka Airport","52.220299","-174.205994","57","NA","US","US-AK","Atka","yes","PAAK","AKB","PAAK","AKA","","https://en.wikipedia.org/wiki/Atka_Airport","40A"
|
|
||||||
"5354","PADU","medium_airport","Tom Madsen (Dutch Harbor) Airport","53.89881","-166.544996","22","NA","US","US-AK","Unalaska","yes","PADU","DUT","PADU","DUT","","https://en.wikipedia.org/wiki/Unalaska_Airport","Dutch Harbor, Unalaska"
|
"5354","PADU","medium_airport","Tom Madsen (Dutch Harbor) Airport","53.89881","-166.544996","22","NA","US","US-AK","Unalaska","yes","PADU","DUT","PADU","DUT","","https://en.wikipedia.org/wiki/Unalaska_Airport","Dutch Harbor, Unalaska"
|
||||||
"16094","PAAP","seaplane_base","Port Alexander Seaplane Base","56.246799","-134.647995","","NA","US","US-AK","Port Alexander","yes","PAAP","PTD","PAAP","AHP","","https://en.wikipedia.org/wiki/Port_Alexander_Seaplane_Base","AK15"
|
|
||||||
"5337","PABA","medium_airport","Barter Island Long Range Radar Station Airport","70.134003","-143.582001","2","NA","US","US-AK","Barter Island","yes","PABA","BTI","PABA","BTI","","https://en.wikipedia.org/wiki/Barter_Island_LRRS_Airport",""
|
|
||||||
"5342","PABR","medium_airport","Wiley Post Will Rogers Memorial Airport","71.285402","-156.766008","44","NA","US","US-AK","Utqiaġvik","yes","PABR","BRW","PABR","BRW","","https://en.wikipedia.org/wiki/Wiley_Post-Will_Rogers_Memorial_Airport","Barrow"
|
|
||||||
"9088","PACS","small_airport","Cape Sarichef Airport","54.583934","-164.905727","291","NA","US","US-AK","Cape Sarichef","no","PACS","WSF","PACS","26AK","","https://en.wikipedia.org/wiki/Cape_Sarichef_Airport",""
|
|
||||||
"16092","PADK","medium_airport","Adak Airport","51.883564","-176.642783","18","NA","US","US-AK","Adak","yes","PADK","ADK","PADK","ADK","","https://en.wikipedia.org/wiki/Adak_Airport",""
|
|
||||||
"5368","PAGM","medium_airport","Gambell Airport","63.767694","-171.733303","27","NA","US","US-AK","Gambell","yes","PAGM","GAM","PAGM","GAM","","https://en.wikipedia.org/wiki/Gambell_Airport",""
|
"5368","PAGM","medium_airport","Gambell Airport","63.767694","-171.733303","27","NA","US","US-AK","Gambell","yes","PAGM","GAM","PAGM","GAM","","https://en.wikipedia.org/wiki/Gambell_Airport",""
|
||||||
"18251","PAIW","small_airport","Wales Airport","65.622593","-168.095","22","NA","US","US-AK","Wales","yes","PAIW","WAA","PAIW","IWK","","https://en.wikipedia.org/wiki/Wales_Airport_(Alaska)",""
|
"5398","PAPG","medium_airport","Petersburg James A Johnson Airport","56.80170059","-132.9450073","111","NA","US","US-AK","Petersburg","yes","PAPG","PSG","PAPG","PSG","","https://en.wikipedia.org/wiki/Petersburg_James_A._Johnson_Airport",""
|
||||||
"19891","PAKF","small_airport","False Pass Airport","54.84751","-163.407168","20","NA","US","US-AK","False Pass","yes","PAKF","KFP","PAKF","KFP","","https://en.wikipedia.org/wiki/False_Pass_Airport",""
|
"5506","PWAK","medium_airport","Wake Island Airfield","19.282437","166.636637","14","OC","UM","UM-79","Wake Island","yes","PWAK","AWK","PWAK","AWK","","https://en.wikipedia.org/wiki/Wake_Island_Airfield",""
|
||||||
"17980","PAKO","small_airport","Nikolski Air Station","52.941552","-168.849478","77","NA","US","US-AK","Nikolski","yes","PAKO","IKO","PAKO","IKO","","https://en.wikipedia.org/wiki/Nikolski_Air_Station",""
|
"6055","SEGS","medium_airport","Seymour Galapagos Ecological Airport","-0.453758","-90.2659","207","SA","EC","EC-W","Isla Baltra","yes","SEGS","GPS","SEGS","","https://ecogal.aero/en/","https://en.wikipedia.org/wiki/Seymour_Airport",""
|
||||||
"16165","PALN","small_airport","Point Lonely Short Range Radar Site Airfield","70.911118","-153.237766","17","NA","US","US-AK","Point Lonely","no","PALN","LNI","PALN","AK71","","https://en.wikipedia.org/wiki/Point_Lonely_Short_Range_Radar_Site","Lonely Air Station"
|
"6450","UEST","medium_airport","Tiksi Airport","71.697700500488","128.90299987793","26","AS","RU","RU-SA","Tiksi","yes","UEST","IKS","UEST","","","https://en.wikipedia.org/wiki/Tiksi_Airport","УЕСТ, Аеропорт Тикси"
|
||||||
"5385","PALU","medium_airport","Cape Lisburne LRRS Airport","68.875099","-166.110001","16","NA","US","US-AK","Cape Lisburne","yes","PALU","LUR","PALU","LUR","","https://en.wikipedia.org/wiki/Cape_Lisburne_LRRS_Airport",""
|
"6459","UHMP","medium_airport","Pevek Airport","69.783302","170.597","11","AS","RU","RU-CHU","Apapelgino","yes","UHMP","PWE","UHMP","","","https://en.wikipedia.org/wiki/Pevek_Airport","УХМП, Аэропорт Певек"
|
||||||
"5396","PAPB","medium_airport","St George Airport","56.577345","-169.663823","125","NA","US","US-AK","St George","yes","PAPB","STG","PAPB","PBV","","https://en.wikipedia.org/wiki/St._George_Airport_(Alaska)","A8L"
|
"26895","YAYE","medium_airport","Ayers Rock Connellan Airport","-25.185913","130.97703","1626","OC","AU","AU-NT","Yulara","yes","YAYE","AYQ","YAYE","","","https://en.wikipedia.org/wiki/Ayers_Rock_Airport","Ayers Rock, Uluru"
|
||||||
"24089","PAPO","small_airport","Point Hope Airport","68.348801","-166.798996","12","NA","US","US-AK","Point Hope","yes","PAPO","PHO","PAPO","PHO","","https://en.wikipedia.org/wiki/Point_Hope_Airport",""
|
"44659","UHMF","medium_airport","Omsukchan Airport","62.457001","155.744995","1732","AS","RU","RU-MAG","Omsukchan","yes","UHMF","","UHMF","","","https://en.wikipedia.org/wiki/Omsukchan_Airport","Аэропорт Омсукчан"
|
||||||
"5404","PASA","medium_airport","Savoonga Airport","63.686401","-170.492996","53","NA","US","US-AK","Savoonga","yes","PASA","SVA","PASA","SVA","","https://en.wikipedia.org/wiki/Savoonga_Airport",""
|
"318444","FHSH","medium_airport","Saint Helena International Airport","-15.958898","-5.646066","1017","AF","SH","SH-SH","Jamestown","yes","FHSH","HLE","FHSH","","http://sthelenaairport.com/","https://en.m.wikipedia.org/wiki/Saint_Helena_Airport#",""
|
||||||
"5410","PASN","medium_airport","St Paul Island Airport","57.166311","-170.222555","63","NA","US","US-AK","St Paul Island","yes","PASN","SNP","PASN","SNP","","https://en.wikipedia.org/wiki/St._Paul_Island_Airport","Pribilof"
|
"1308","CNH2","small_airport","Natuashish Airport","55.913898","-61.184399","30","NA","CA","CA-NL","Natuashish","yes","","YNP","CNH2","CNH2","","https://en.wikipedia.org/wiki/Natuashish_Airport","NH2"
|
||||||
|
"31907","NCMH","small_airport","Manihiki Island Airport","-10.38091","-160.999424","11","OC","CK","CK-U-A","Manihiki Island","yes","NCMH","MHX","NCMH","","","https://en.wikipedia.org/wiki/Manihiki_Island_Airport","Humphrey Island, Te Fuinga o Niva"
|
||||||
|
"1806","CYLT","medium_airport","Alert Airport","82.517263","-62.283037","100","NA","CA","CA-NU","Alert","no","CYLT","YLT","CYLT","","","https://en.wikipedia.org/wiki/Alert_Airport","YLT"
|
||||||
|
"4582","HL56","medium_airport","Matan al-Sarra Air Base","21.6877","21.8309","1769","AF","LY","LY-KF","","no","","","HL56","HL56","","https://en.wikipedia.org/wiki/Maaten_al-Sarra_Air_Base",""
|
||||||
|
"5054","NZSP","medium_airport","Amundsen–Scott South Pole Station Airport","-90","-1","9300","AN","AQ","AQ-U-A","Amundsen-Scott South Pole Station","no","NZSP","","NZSP","","","https://en.wikipedia.org/wiki/Amundsen-Scott_South_Pole_Station",""
|
||||||
|
"5059","NZWD","medium_airport","Williams Field Skiway","-77.867401","167.057007","68","AN","AQ","AQ-U-A","McMurdo Station","no","","","NZWD","","","https://en.wikipedia.org/wiki/Williams_Field","Willies Field"
|
||||||
"5413","PASY","medium_airport","Eareckson Air Station","52.71229935","174.1139984","95","NA","US","US-AK","Shemya","no","PASY","SYA","PASY","SYA","","https://en.wikipedia.org/wiki/Eareckson_Air_Station",""
|
"5413","PASY","medium_airport","Eareckson Air Station","52.71229935","174.1139984","95","NA","US","US-AK","Shemya","no","PASY","SYA","PASY","SYA","","https://en.wikipedia.org/wiki/Eareckson_Air_Station",""
|
||||||
"5416","PATQ","medium_airport","Atqasuk Edward Burnell Sr Memorial Airport","70.46704","-157.436013","96","NA","US","US-AK","Atqasuk","yes","PATQ","ATK","PATQ","ATK","","https://en.wikipedia.org/wiki/Atqasuk_Edward_Burnell_Sr._Memorial_Airport","Z46"
|
|
||||||
"5419","PAVL","small_airport","Kivalina Airport","67.734565","-164.559917","13","NA","US","US-AK","Kivalina","yes","PAVL","KVL","PAVL","KVL","","https://en.wikipedia.org/wiki/Kivalina_Airport",""
|
|
||||||
"5422","PAWI","medium_airport","Wainwright Airport","70.638","-159.994995","41","NA","US","US-AK","Wainwright","yes","PAWI","AIN","PAWI","AWI","","https://en.wikipedia.org/wiki/Wainwright_Airport_(Alaska)","5WW"
|
|
||||||
"5426","PCIS","medium_airport","Canton Island Airport","-2.7681200504300003","-171.710006714","9","OC","KI","KI-P","Abariringa","no","PCIS","CIS","PCIS","","","https://en.wikipedia.org/wiki/Canton_Island_Airport","Kanton Island"
|
"5426","PCIS","medium_airport","Canton Island Airport","-2.7681200504300003","-171.710006714","9","OC","KI","KI-P","Abariringa","no","PCIS","CIS","PCIS","","","https://en.wikipedia.org/wiki/Canton_Island_Airport","Kanton Island"
|
||||||
"5494","PMDY","medium_airport","Henderson Field","28.2017","-177.380997","13","OC","UM","UM-71","Sand Island","no","PMDY","MDY","PMDY","MDY","","https://en.wikipedia.org/wiki/Henderson_Field_(Midway_Atoll)",""
|
"5494","PMDY","medium_airport","Henderson Field","28.2017","-177.380997","13","OC","UM","UM-71","Sand Island","no","PMDY","MDY","PMDY","MDY","","https://en.wikipedia.org/wiki/Henderson_Field_(Midway_Atoll)",""
|
||||||
"5495","PPIZ","medium_airport","Point Lay LRRS Airport","69.732903","-163.005005","22","NA","US","US-AK","Point Lay","yes","PPIZ","PIZ","PPIZ","PIZ","","https://en.wikipedia.org/wiki/Point_Lay_LRRS_Airport",""
|
|
||||||
"5506","PWAK","medium_airport","Wake Island Airfield","19.282437","166.636637","14","OC","UM","UM-79","Wake Island","yes","PWAK","AWK","PWAK","AWK","","https://en.wikipedia.org/wiki/Wake_Island_Airfield",""
|
|
||||||
"5534","RJAM","small_airport","JMSDF Minami Torishima Air Base","24.2897","153.979004","22","AS","JP","JP-13","Ogasawara","no","RJAM","MUS","RJAM","","","https://en.wikipedia.org/wiki/Minami_Torishima_Airport","Marcus Island Airport"
|
|
||||||
"5535","RJAW","medium_airport","Ioto (Iwo Jima) Airbase","24.784153","141.32261","384","AS","JP","JP-13","Ogasawara","no","RJAW","IWO","RJAW","","","https://en.wikipedia.org/wiki/Central_Field_(Iwo_Jima)","Iwo Jima Airport, Central Field, Ioto, Iōtō"
|
"5535","RJAW","medium_airport","Ioto (Iwo Jima) Airbase","24.784153","141.32261","384","AS","JP","JP-13","Ogasawara","no","RJAW","IWO","RJAW","","","https://en.wikipedia.org/wiki/Central_Field_(Iwo_Jima)","Iwo Jima Airport, Central Field, Ioto, Iōtō"
|
||||||
"42980","UESU","medium_airport","Zyryanka Airport","65.7485","150.8889","140","AS","RU","RU-SA","Zyryanka","yes","UESU","ZKP","UESU","","","https://en.wikipedia.org/wiki/Zyryanka_Airport","УЕСУ, Аэропорт Зырянка"
|
"35041","UODN","medium_airport","Nagurskoye Airfield","80.803207","47.663586","59","AS","RU","RU-ARK","Alexandra Land","no","UODN","","UODN","","","https://en.wikipedia.org/wiki/Nagurskoye",""
|
||||||
"323626","RU-0472","small_airport","Lamutskoye Airport","65.538838","168.844848","601","AS","RU","RU-CHU","Lamutskoye","no","","","UHAL","UHAL","","","УХАЛ, Ламутское"
|
"336953","AT03","medium_airport","Concordia Skyway","-75.103278","123.35825","10725","AN","AQ","AQ-U-A","Concordia Station","no","","","AT03","","","https://en.wikipedia.org/wiki/Concordia_Station",""
|
||||||
"338091","RU-0543","small_airport","Tempa Airfield","75.76713","137.576637","3","EU","RU","RU-SA","Kotelny Island","no","","","","","","","Темп"
|
"603000","AQ-0016","medium_airport","Grandfather Skiway","-77.530242","-31.827393","","AN","AQ","AQ-U-A","Antartica","no","","","","","","",""
|
||||||
"6456","UHMA","medium_airport","Ugolny Yuri Ryktheu Airport","64.734902","177.740997","194","AS","RU","RU-CHU","Anadyr","yes","UHMA","DYR","UHMA","","","https://en.wikipedia.org/wiki/Ugolny_Airport","УХМА, Угольный, Аnadyr Airport, Аэропорт Анадырь"
|
"11","NZ12","small_airport","Palmer Station Airport","-64.774582","-64.035907","149","AN","AQ","AQ-U-A","Palmer Station","no","","","NZ0B","NZ0B","","https://en.wikipedia.org/wiki/Palmer_Station",""
|
||||||
"340795","RU-0605","small_airport","Uelkal Airstrip","65.530823","-179.287263","","EU","RU","RU-CHU","Uelkal","no","","","","","","",""
|
"1486","CRE2","small_airport","Edzo Airport","62.766701","-116.084","587","NA","CA","CA-NT","Rae-Edzo","no","","","CRE2","CRE2","","https://en.wikipedia.org/wiki/Rae/Edzo_Airport","RE2"
|
||||||
"340810","RU-0616","small_airport","Taymylyr Airstrip","72.607271","121.893179","","EU","RU","RU-SA","Taymylyr","no","","","","","","",""
|
"5534","RJAM","small_airport","JMSDF Minami Torishima Air Base","24.2897","153.979004","22","AS","JP","JP-13","Ogasawara","no","RJAM","MUS","RJAM","","","https://en.wikipedia.org/wiki/Minami_Torishima_Airport","Marcus Island Airport"
|
||||||
"341832","RU-0676","small_airport","Ayanka Airport","63.709269","167.584196","295","AS","RU","RU-KAM","Ayanka","no","","","","","","",""
|
|
||||||
"346936","RU-0727","small_airport","Khailino Airport","60.95206","166.83801","180","AS","RU","RU-KAM","Khailino","no","","","","UHPF","","","УХПФ, Хаилино"
|
|
||||||
"42940","UHPA","small_airport","Ust-Pakhachi Airport","60.556587","169.107707","10","AS","RU","RU-KAM","Ust-Pakhachi","no","UHPA","","UHPA","UHPA","","https://en.wikipedia.org/wiki/Ust-Pakhachi_Airport","УХПА, Аэропорт Усть-Пахачи, Пахачи, Pakhachi"
|
|
||||||
"346939","RU-0730","small_airport","Sredny Pakhachi Airport","60.81718","169.07555","","AS","RU","RU-KAM","Sredny Pakhachi","no","","","","","","",""
|
|
||||||
"346948","RU-0738","small_airport","Garmanda Airport","62.18334","159.08894","","AS","RU","RU-MAG","Garmanda","no","","","","","","","UEVE"
|
|
||||||
"347894","RU-0753","small_airport","Zhilinda Airport","70.15387","113.91756","489","EU","RU","RU-SA","Zhilinda","no","","","","","","",""
|
|
||||||
"347895","RU-0754","small_airport","Ebelyakh Airport","70.88319","113.58159","387","EU","RU","RU-SA","Ebelyakh","no","","","","","","",""
|
|
||||||
"347902","RU-0760","small_airport","Yukta Airport","63.38788","105.65577","680","EU","RU","RU-KYA","Yukta","no","","","","","","",""
|
|
||||||
"347903","RU-0761","small_airport","Nakanno Airport","62.89988","108.44788","816","EU","RU","RU-IRK","Nakanno","no","","","","","","",""
|
|
||||||
"347904","RU-0762","small_airport","Khamakar Airport","61.989","108.17978","889","EU","RU","RU-IRK","Khamakar","no","","","","","","",""
|
|
||||||
"601237","RU-10132","small_airport","Yagodnoye Airfield","62.54574","149.52257","1646","AS","RU","RU-MAG","Yagodnoye","no","","","UHGE","","","","УХГЕ, Ягодное,"
|
|
||||||
"602171","RU-10134","small_airport","Valunistoe (airport)","66.421687","177.582464","","AS","RU","RU-CHU","Rudnik Valunisty","no","","","","","","",""
|
|
||||||
"602186","RU-10135","small_airport","Valunistoe Mining Complex Airport","66.766633","164.319284","999","AS","RU","RU-CHU","Vesenny","no","","","","","","",""
|
|
||||||
"602304","RU-10136","small_airport","Verkhnee Penzhino Airport","64.222657","164.244866","1093","AS","RU","RU-KAM","Penzhinsky District","no","","","","","","","Верхнее Пенжино"
|
|
||||||
"609963","RU-10173","small_airport","Stadukhino Airfield","66.965897","166.82135","1905","AS","RU","RU-CHU","Stadukhino","no","","","","ZC8P","","","ЗЦ8П, Стадукхино"
|
|
||||||
"34989","RU-2510","small_airport","Greem Bell Air Base","81.15","64.33","30","EU","RU","RU-ARK","Graham Bell Island","no","","","","XLDG","","https://en.wikipedia.org/wiki/Greem_Bell","Graham Bell Airbase, Аэродром Греэм Белл, Аэродром Грээм Белл, ЬЛДГ"
|
|
||||||
"39078","SAYE","small_airport","Esperanza Base","-63.400002","-56.983299","75","AN","AQ","AQ-U-A","Fortín Sargento Cabral","no","","","SAYE","BET","","https://en.wikipedia.org/wiki/Esperanza_Base",""
|
|
||||||
"5830","SAWB","small_airport","Gustavo Marambio Airport","-64.238297","-56.630798","760","AN","AQ","AQ-U-A","Marambio Base","no","","","SAWB","MBI","","https://en.wikipedia.org/wiki/Marambio_Airport",""
|
|
||||||
"39076","SAWZ","small_airport","Matienzo Airfield","-64.976998","-60.108992","75","AN","AQ","AQ-U-A","Matienzo Base","no","","","SAWZ","BTM","","",""
|
|
||||||
"39077","SAYB","small_airport","Base Belgrano II Airport","-77.874055","-34.62616","820","AN","AQ","AQ-U-A","Base Belgrano II","no","","","SAYB","BEB","","https://en.wikipedia.org/wiki/Belgrano_II_Base",""
|
|
||||||
"6039","SCRM","small_airport","Teniente Rodolfo Marsh Martin Airport","-62.191026","-58.98669","147","AN","AQ","AQ-U-A","Villa Las Estrellas","no","SCRM","TNM","SCRM","","","https://en.wikipedia.org/wiki/Teniente_R._Marsh_Airport",""
|
|
||||||
"39080","SAYS","small_airport","San Martín Base Airfield","-68.116699","-67.099998","75","AN","AQ","AQ-U-A","San Martín Base","no","","","SAYS","BSM","","https://en.wikipedia.org/wiki/San_Martin_Base",""
|
|
||||||
"308226","SCBO","small_airport","General Bernardo O'Higgins Base Skyway","-63.344","-57.842","900","AN","AQ","AQ-U-A","General Bernardo O'Higgins Base","no","","","SCBO","","","",""
|
|
||||||
"6021","SCFX","small_airport","Isla San Felix Airport","-26.2939","-80.096199","165","SA","CL","CL-AT","Isla San Felix","no","","","SCFX","","","https://en.wikipedia.org/wiki/Isla_San_Felix_Airport",""
|
"6021","SCFX","small_airport","Isla San Felix Airport","-26.2939","-80.096199","165","SA","CL","CL-AT","Isla San Felix","no","","","SCFX","","","https://en.wikipedia.org/wiki/Isla_San_Felix_Airport",""
|
||||||
"45059","SCGC","small_airport","Union Glacier Blue-Ice Runway","-79.777778","-83.320833","2461","AN","AQ","AQ-U-A","Union Glacier","no","SCGC","UGL","SCGC","","","https://en.wikipedia.org/wiki/Union_Glacier_Blue-Ice_Runway",""
|
"27793","YMNY","small_airport","Morney Airport","-25.358299255371094","141.43299865722656","104","OC","AU","AU-QLD","","no","YMNY","OXY","YMNY","","","",""
|
||||||
"32268","SCPZ","small_airport","Patriot Hills Airport","-80.318307","-81.308128","2900","AN","AQ","AQ-U-A","Patriot Hills Base Camp","no","SCPZ","","SCPZ","","","https://es.wikipedia.org/wiki/Aer%C3%B3dromo_Patriot_Hills",""
|
"32268","SCPZ","small_airport","Patriot Hills Airport","-80.318307","-81.308128","2900","AN","AQ","AQ-U-A","Patriot Hills Base Camp","no","SCPZ","","SCPZ","","","https://es.wikipedia.org/wiki/Aer%C3%B3dromo_Patriot_Hills",""
|
||||||
"6055","SEGS","medium_airport","Seymour Galapagos Ecological Airport","-0.453758","-90.2659","207","SA","EC","EC-W","Isla Baltra","yes","SEGS","GPS","SEGS","","https://ecogal.aero/en/","https://en.wikipedia.org/wiki/Seymour_Airport",""
|
"39579","AQ-0001","small_airport","Novolazarevskaya Station","-70.8461","11.8472","390","AN","AQ","AQ-U-A","Queen Maud Land","no","","","AT17","","","https://en.wikipedia.org/wiki/Novolazarevskaya_Station",""
|
||||||
"41131","SEII","small_airport","General Villamil Airport","-0.942628","-90.953003","35","SA","EC","EC-W","Puerto Villamil","yes","SEII","IBB","SEII","","","",""
|
|
||||||
"32508","UEBN","small_airport","Nizhneyansk Airport","71.437822","136.189701","20","AS","RU","RU-SA","Nizhneyansk","no","","","UEBN","","","","Нижнея́нск"
|
|
||||||
"335165","UEKY","small_airport","Keng-Kyuyol Airport","68.076828","145.985126","","EU","RU","RU-SA","Keng-Kyuyol","no","","","UEKY","","","",""
|
|
||||||
"335179","UEMC","small_airport","Khatyngnakh Airport","67.489845","152.575679","","EU","RU","RU-SA","","no","","","UEMC","","","",""
|
|
||||||
"44597","UERO","small_airport","Olenyok Airport","68.514999","112.480003","847","AS","RU","RU-SA","Olenyok","no","","ONK","UERO","","","https://en.wikipedia.org/wiki/Olenyok_Airport","УЕРО, Olenek Airport, Аэропорт Оленёк, Аэропорт Оленек"
|
|
||||||
"44870","UERS","medium_airport","Saskylakh Airport","71.927902","114.080002","","AS","RU","RU-SA","Saskylakh","yes","UERS","SYS","UERS","","","https://en.wikipedia.org/wiki/Saskylakh_Airport","УЕРС, Аэропорт Саскылах"
|
|
||||||
"335193","UESC","small_airport","Berezovka Airport","67.120183","156.589766","","AS","RU","RU-SA","","no","","","UESC","","","","УЕСЦ, Берёзовка"
|
|
||||||
"43667","UESG","medium_airport","Belaya Gora Airport","68.556227","146.22784","118","AS","RU","RU-SA","Belaya Gora","no","UESG","BGN","UESG","","","https://en.wikipedia.org/wiki/Belaya_Gora_Airport","УЕСГ, Аэропорт Белая Гора"
|
|
||||||
"335194","UESH","small_airport","Argakhtakh Airport","68.443333","153.362222","65","AS","RU","RU-SA","Argakhtakh","no","","","UESH","","","","УЕСХ, Аргахтах"
|
|
||||||
"316761","UESK","medium_airport","Srednekolymsk Airport","67.4805","153.7364","60","AS","RU","RU-SA","Srednekolymsk","yes","","SEK","UESK","","","https://en.wikipedia.org/wiki/Srednekolymsk_Airport","УЕСК, Среднеколымск"
|
|
||||||
"335195","UESL","small_airport","Sylgy-Ytar Airport","67.848145","154.838862","164","AS","RU","RU-SA","","no","","","UESL","","","","УЕСЛ, Сылгы-Ытар"
|
|
||||||
"32514","UESO","medium_airport","Chokurdakh Airport","70.6231","147.901993","151","AS","RU","RU-SA","Chokurdah","yes","UESO","CKH","UESO","","","https://en.wikipedia.org/wiki/Chokurdakh_Airport","Chokurdah Airport, Cokurdah Airport, Аэропорт Чокурдах"
|
|
||||||
"335196","UESR","small_airport","Tumat Airport","70.72611","139.235833","","EU","RU","RU-SA","","no","","","UESR","","","",""
|
|
||||||
"30870","UESS","medium_airport","Cherskiy Airport","68.740601","161.337997","20","AS","RU","RU-SA","Cherskiy","yes","UESS","CYX","UESS","","","https://en.wikipedia.org/wiki/Chersky_Airport","УЕСС, Chersky Airport, Аэропорт Черский"
|
|
||||||
"6450","UEST","medium_airport","Tiksi Airport","71.697700500488","128.90299987793","26","AS","RU","RU-SA","Tiksi","yes","UEST","IKS","UEST","","","https://en.wikipedia.org/wiki/Tiksi_Airport","УЕСТ, Аеропорт Тикси"
|
|
||||||
"335197","UESV","small_airport","Svatay Airport","68.057338","151.79625","75","AS","RU","RU-SA","Svatay","no","","","UESW","","","","УЕСВ, Сватай"
|
|
||||||
"335198","UESX","small_airport","Aleko-Kyuyol Airport","68.676693","151.873798","82","AS","RU","RU-SA","","no","","","UESX","","","","УЕСЬ, Алеко-Кюель"
|
|
||||||
"335200","UESZ","small_airport","Kazachye Airport","70.746294","136.179271","","EU","RU","RU-SA","","no","","","UESZ","","","",""
|
|
||||||
"323629","UHAC","small_airport","Chuvanskoye Airport","65.172163","167.952484","644","AS","RU","RU-CHU","Chuvanskoye","no","","","UHAC","UHAC","","","УХАЦ, Чуванское"
|
|
||||||
"323630","UHAW","small_airport","Vayegi Airport","64.167442","171.057887","131","AS","RU","RU-CHU","Vayegi","no","","","UHAW","UHAW","","","УХАВ, Ваеги"
|
|
||||||
"324924","UHDW","small_airport","Vankarem Airport","67.838719","-175.8494283","3","EU","RU","RU-CHU","Vankarem","no","","","UHDW","","","","УХДВ, Ванкарем"
|
|
||||||
"530668","UHEI","small_airport","Ilirney Airport","67.255278","167.949167","1165","AS","RU","RU-CHU","","no","","","UHEI","","","",""
|
|
||||||
"525055","UHEK","small_airport","Kupol Airport","66.901667","169.56","1745","AS","RU","RU-CHU","","no","","","UHEK","","","https://en.wikipedia.org/wiki/Kupol_Airport",""
|
|
||||||
"596406","UHGL","small_airport","Glukharinoye Airfield","64.999872","153.096328","977","AS","RU","RU-MAG","Glukharinoye","no","","","UHGL","","","","УХГЛ, Глухариное, Глухариный"
|
|
||||||
"6457","UHMD","medium_airport","Provideniya Bay Airport","64.378098","-173.242996","72","AS","RU","RU-CHU","Chukotka","no","UHMD","PVS","UHMD","XHMD","","https://en.wikipedia.org/wiki/Provideniya_Bay_Airport","УХМД, ЬХМД, Bukhta Provideniya Airport, Urelik Airport, Ureliki Airport, Аэропорт Бухта Провидения, Аэропорт Урелики"
|
|
||||||
"43686","UHME","small_airport","Zaliv Kresta Airport","66.358398","-179.108393","22","AS","RU","RU-CHU","Egvekinot","no","","","UHME","","","","УХМЕ, Аэропорт Залив Креста"
|
|
||||||
"44659","UHMF","medium_airport","Omsukchan Airport","62.457001","155.744995","1732","AS","RU","RU-MAG","Omsukchan","yes","UHMF","","UHMF","","","https://en.wikipedia.org/wiki/Omsukchan_Airport","Аэропорт Омсукчан"
|
|
||||||
"35040","UHMI","small_airport","Mys Shmidta Airport","68.86808","-179.374183","20","AS","RU","RU-CHU","Mys Shmidta","no","UHMI","","UHMI","","","https://en.wikipedia.org/wiki/Mys_Shmidta_Airport","УХМИ, ЬХМИ, Мыс Шмидта"
|
|
||||||
"44473","UHMK","medium_airport","Keperveem Airport","67.845001","166.139999","623","AS","RU","RU-CHU","Keperveem","yes","UHMK","KPW","UHMK","","","https://en.wikipedia.org/wiki/Keperveyem_Airport","Keperveyem Airport, Аэропорт Кепервеем"
|
|
||||||
"42925","UHML","small_airport","Lavrentiya Airport","65.580426","-170.999177","30","AS","RU","RU-CHU","Lavrentiya","no","UHML","","UHML","","","https://en.wikipedia.org/wiki/Lavrentiya_Airport","УХМЛ, Залив Лаврентия, Lavrentiya Bay"
|
|
||||||
"44610","UHMN","small_airport","Omolon Airport","65.239998","160.539993","869","AS","RU","RU-CHU","Omolon","yes","UHMN","","UHMN","","","https://en.wikipedia.org/wiki/Omolon_Airport","УХМН, Аэропорт Омолон"
|
|
||||||
"44660","UHMO","small_airport","Markovo Airport","64.665446","170.417626","75","AS","RU","RU-CHU","Markovo","yes","UHMO","KVM","UHMO","","","https://en.wikipedia.org/wiki/Markovo_Airport","Аэропорт Марково"
|
|
||||||
"6459","UHMP","medium_airport","Pevek Airport","69.783302","170.597","11","AS","RU","RU-CHU","Apapelgino","yes","UHMP","PWE","UHMP","","","https://en.wikipedia.org/wiki/Pevek_Airport","УХМП, Аэропорт Певек"
|
|
||||||
"32518","UHMR","small_airport","Beringovskiy Airport","63.02","179.292999","3","AS","RU","RU-CHU","Beringovsky","no","UHMR","","UHMR","","","https://es.wikipedia.org/wiki/Aer%C3%B3dromo_de_Beringovski","УХМР, Аэропорт Беринговский"
|
|
||||||
"42963","UHMS","medium_airport","Seymchan Airport","62.92078","152.422775","679","AS","RU","RU-MAG","Seymchan","no","UHMS","","UHMS","","","https://en.wikipedia.org/wiki/Seymchan_Airport","УХМС, Аэропорт Сеймчан"
|
|
||||||
"324631","UHMZ","small_airport","Wrangel Island Airport","70.945356","-179.5","112","EU","RU","RU-CHU","Wrangel Island","no","","","UHMZ","UHMZ","","","УХМЗ, Остров Врангеля"
|
|
||||||
"339646","UHPN","small_airport","Manily Airport","62.485962","165.338917","33","AS","RU","RU-KAM","Manily","no","","","UHPN","","","",""
|
|
||||||
"597129","UHQE","small_airport","Slautnoye Airfield","63.176423","167.978281","","AS","RU","RU-KAM","Slautnoye","no","","","UHQE","","","","УХЯЕ, Слаутное"
|
|
||||||
"42926","UIKE","small_airport","Yerbogachen Airport","61.2750015259","108.029998779","400","AS","RU","RU-IRK","Erbogachen","no","UIKE","ERG","UIKE","","","https://en.wikipedia.org/wiki/Erbogachen_Airport","Yerbogachyon Airport, Erbogachyon Airport, Erbogachen Airport, Аэропорт Ербогачен, Аэропорт Ербогачён"
|
"42926","UIKE","small_airport","Yerbogachen Airport","61.2750015259","108.029998779","400","AS","RU","RU-IRK","Erbogachen","no","UIKE","ERG","UIKE","","","https://en.wikipedia.org/wiki/Erbogachen_Airport","Yerbogachyon Airport, Erbogachyon Airport, Erbogachen Airport, Аэропорт Ербогачен, Аэропорт Ербогачён"
|
||||||
"43672","ULDW","small_airport","Varandey Airport","68.848503","58.201401","23","AS","RU","RU-NEN","Varandey","no","ULDW","VRI","ULDW","","","https://en.wikipedia.org/wiki/Varandey_Airport","УЛДВ, Varandei Airport, Аэропорт Варандей"
|
"43672","ULDW","small_airport","Varandey Airport","68.848503","58.201401","23","AS","RU","RU-NEN","Varandey","no","ULDW","VRI","ULDW","","","https://en.wikipedia.org/wiki/Varandey_Airport","УЛДВ, Varandei Airport, Аэропорт Варандей"
|
||||||
"315363","UODL","small_airport","Cape Chelyuskin Airfield","77.712","104.24","60","AS","RU","RU-KYA","Chelyuskin Polar Station","no","","","UODL","UODL","","","УОДЛ, Челюскин"
|
"44051","BGDH","small_airport","Danmarkshavn Landing Strip","76.76667","-18.666668","","NA","GL","GL-NE","Danmarkshavn","no","","","BGDH","","","",""
|
||||||
"35041","UODN","medium_airport","Nagurskoye Airfield","80.803207","47.663586","59","AS","RU","RU-ARK","Alexandra Land","no","UODN","","UODN","","","https://en.wikipedia.org/wiki/Nagurskoye",""
|
|
||||||
"35086","UODS","small_airport","Sredniy Island Air Base","79.52958","91.07495","26","AS","RU","RU-KYA","Khatanga","no","UODS","","UODS","XODS","","https://en.wikipedia.org/wiki/Sredny_Ostrov","УОДС, Sredniy Ostrov Air Base, Аэродром Средний Остров, ЬОДС"
|
|
||||||
"301864","US-0200","small_airport","Kogru River Airfield","70.574196","-152.259478","","NA","US","US-AK","Kogru","no","","","","A41","","",""
|
|
||||||
"340805","US-3039","small_airport","Brownlow Point Airport","69.979281","-144.834986","","NA","US","US-AK","Brownlow Point","no","","","","","","",""
|
|
||||||
"340807","US-3041","small_airport","Demarcation Bay Airfield","69.882551","-142.305616","","NA","US","US-AK","Nuvagapak Point","no","","","","","","","Nuvagapak Point"
|
|
||||||
"316465","WAN","small_airport","Waverney Airport","-25.356917","141.925593","570","OC","AU","AU-QLD","Waverney","no","","","","","","","WAN"
|
|
||||||
"354533","YABL","small_airport","Ambalindum Airport","-23.35187","134.732434","1966","OC","AU","AU-NT","Ambalindum","no","","","YABL","","","",""
|
|
||||||
"27317","YADO","small_airport","Andado Airport","-25.407772","135.290794","549","OC","AU","AU-NT","Ghan","no","","","YADO","","","",""
|
|
||||||
"38224","YALC","small_airport","Alcoota Station Airport","-22.801963","134.4036","1994","OC","AU","AU-NT","Alcoota","no","","","YALC","","","","Engawala"
|
|
||||||
"38226","YALM","small_airport","Allambie Airport","-24.265335","134.402927","","OC","AU","AU-NT","","no","","","YALM","","","",""
|
|
||||||
"38229","YAMM","small_airport","Ammaroo Airport","-21.738300323486328","135.24200439453125","","OC","AU","AU-NT","","no","","AMX","YAMM","","","",""
|
|
||||||
"27328","YAMT","small_airport","Amata Airport","-26.097363","131.202732","695","OC","AU","AU-SA","","no","YAMT","AMT","YAMT","","","https://en.wikipedia.org/wiki/Amata_Airport",""
|
|
||||||
"38230","YANJ","small_airport","Angatja Airport","-26.100000381469727","130.39999389648438","","OC","AU","AU-SA","","no","","","YANJ","","","",""
|
|
||||||
"38231","YANN","small_airport","Anningie Airport","-21.83169937133789","133.125","","OC","AU","AU-NT","","no","","","YANN","","","",""
|
|
||||||
"27332","YANW","small_airport","Annitowa Airport","-21.200017","136.451139","901","OC","AU","AU-NT","","no","","","YANW","","","",""
|
|
||||||
"27336","YARD","small_airport","Argadargada Airport","-21.676700592041016","136.67799377441406","","OC","AU","AU-NT","","no","","","YARD","","","",""
|
|
||||||
"27340","YARN","small_airport","Areyonga Airport","-24.091565","132.271228","","OC","AU","AU-NT","Mereenie","no","","","YARN","","","",""
|
|
||||||
"38232","YARP","small_airport","Arapunya Airport","-22.316699981689453","135.6999969482422","","OC","AU","AU-NT","","no","","","YARP","","","",""
|
|
||||||
"38233","YATL","small_airport","Atula Airport","-23.255344","136.388955","915","OC","AU","AU-NT","Anatye","no","","","YATL","","","",""
|
|
||||||
"26895","YAYE","medium_airport","Ayers Rock Connellan Airport","-25.185913","130.97703","1626","OC","AU","AU-NT","Yulara","yes","YAYE","AYQ","YAYE","","","https://en.wikipedia.org/wiki/Ayers_Rock_Airport","Ayers Rock, Uluru"
|
|
||||||
"26900","YBAS","medium_airport","Alice Springs Airport","-23.806588","133.903427","1789","OC","AU","AU-NT","Alice Springs","yes","YBAS","ASP","YBAS","","http://www.alicespringsairport.com.au/","https://en.wikipedia.org/wiki/Alice_Springs_Airport",""
|
|
||||||
"26907","YBDV","medium_airport","Birdsville Airport","-25.897499084472656","139.34800720214844","159","OC","AU","AU-QLD","","yes","YBDV","BVI","YBDV","","","https://en.wikipedia.org/wiki/Birdsville_Airport",""
|
|
||||||
"27369","YBEO","small_airport","Betoota Airport","-25.694791","140.738339","91","OC","AU","AU-QLD","","no","YBEO","BTX","YBEO","","","",""
|
|
||||||
"38256","YBRC","small_airport","Barrow Creek Airport","-21.542202","133.871959","","OC","AU","AU-NT","","no","","","YBRC","","","",""
|
|
||||||
"27416","YBSR","small_airport","Blackstone Airport","-25.9867000579834","128.28799438476562","","OC","AU","AU-WA","","no","","","YBSR","","","",""
|
|
||||||
"38278","YCCK","small_airport","Canteen Creek Airport","-20.650800704956055","135.5850067138672","","OC","AU","AU-NT","","no","","","YCCK","","","",""
|
|
||||||
"38293","YCNS","small_airport","Coniston Airport","-22.13330078125","132.5330047607422","","OC","AU","AU-NT","","no","","","YCNS","","","",""
|
|
||||||
"348022","YCSK","small_airport","Casey Station Skiway","-66.288056","110.7575","1178","AN","AQ","AQ-U-A","Casey Station","no","","","YCSK","","","https://en.wikipedia.org/wiki/Casey_Station",""
|
|
||||||
"38304","YCSP","small_airport","Curtin Springs Airport","-25.333921","131.759308","","OC","AU","AU-NT","","no","","","YCSP","","","",""
|
|
||||||
"38308","YCUD","small_airport","Cuddapan Airport","-25.59000015258789","141.50799560546875","","OC","AU","AU-QLD","","no","","","YCUD","","","",""
|
|
||||||
"38460","YMDS","small_airport","Macdonald Downs Airport","-22.444000244099996","135.199005127","","OC","AU","AU-NT","","no","YMDS","MNW","YMDS","","","",""
|
|
||||||
"27532","YDRI","small_airport","Durrie Airport","-25.684999465942383","140.22799682617188","58","OC","AU","AU-QLD","","no","YDRI","DRR","YDRI","","","",""
|
|
||||||
"38330","YDRL","small_airport","De Rose Hill Airport","-26.435838","133.259954","","OC","AU","AU-SA","De Rose Hill","no","","","YDRL","","","",""
|
|
||||||
"27535","YDVR","small_airport","Docker River Airport","-24.859533","129.122209","589","OC","AU","AU-NT","Kaltukatjara","no","YDVR","DKV","YDVR","","","",""
|
|
||||||
"38334","YDYD","small_airport","Derry Downs Airport","-22.08329963684082","135.33299255371094","","OC","AU","AU-NT","","no","","","YDYD","","","",""
|
|
||||||
"38338","YELK","small_airport","Elkedra Airport","-21.172500610399997","135.444000244","","OC","AU","AU-NT","","no","","EKD","YELK","","","",""
|
|
||||||
"38342","YEPR","small_airport","Epenarra Airport","-20.433300018310547","135.26699829101562","","OC","AU","AU-NT","","no","","","YEPR","","","",""
|
|
||||||
"38345","YERL","small_airport","Erldunda Airport","-25.206106","133.254161","","OC","AU","AU-NT","Ghan","no","","EDD","YERL","","","",""
|
|
||||||
"27554","YERN","small_airport","Ernabella Airport","-26.2632999420166","132.1820068359375","707","OC","AU","AU-SA","","no","YERN","ERB","YERN","","","",""
|
|
||||||
"27559","YEVP","small_airport","Everard Park Airport","-27.038988","132.688585","1615","OC","AU","AU-SA","Mimili","no","","","YEVP","","","",""
|
|
||||||
"31129","YFNE","small_airport","Finke Airport","-25.5946998596","134.582992554","","OC","AU","AU-NT","Finke","no","YFNE","FIK","YFNE","","","",""
|
|
||||||
"27566","YFRG","small_airport","Fregon Airport","-26.774999618530273","132.01699829101562","528","OC","AU","AU-SA","","no","","","YFRG","","","",""
|
|
||||||
"26985","YFRT","medium_airport","Forrest Airport","-30.83662","128.112811","511","OC","AU","AU-WA","","no","YFRT","FOS","YFRT","","","https://en.wikipedia.org/wiki/Forrest_Airport",""
|
|
||||||
"27631","YIDK","small_airport","Indulkana Airport","-26.965435","133.321989","401","OC","AU","AU-SA","Indulkana","no","YIDK","IDK","YIDK","","","",""
|
|
||||||
"27594","YGLE","small_airport","Glengyle Airport","-24.808300018310547","139.60000610351562","91","OC","AU","AU-QLD","","no","YGLE","GLG","YGLE","","","",""
|
|
||||||
"27599","YGLS","small_airport","Giles Airport","-25.043699","128.296005","579","OC","AU","AU-WA","Warakurna","no","","","YGLS","","","https://en.wikipedia.org/wiki/Giles_Airport",""
|
|
||||||
"27612","YHAA","small_airport","Haasts Bluff Airport","-23.454999923706","131.85299682617","2269","OC","AU","AU-NT","","no","","","YHAA","","","",""
|
|
||||||
"27619","YHKT","small_airport","Huckitta Airport","-22.943300247192383","135.44700622558594","","OC","AU","AU-NT","","no","","","YHKT","","","",""
|
|
||||||
"27621","YHMB","small_airport","Hermannsburg Airport","-23.926485","132.807798","593","OC","AU","AU-NT","Hermannsburg (Ntaria)","no","YHMB","HMG","YHMB","","","",""
|
|
||||||
"38390","YHSB","small_airport","Horseshoe Bend Airport","-25.216699600219727","134.26699829101562","","OC","AU","AU-NT","","no","","","YHSB","","","",""
|
|
||||||
"38394","YHTS","small_airport","Harts Range Airport","-22.985000610351562","134.91799926757812","","OC","AU","AU-NT","","no","","","YHTS","","","",""
|
|
||||||
"27632","YIDR","small_airport","Idracowra Airport","-25.06329917907715","133.73300170898438","","OC","AU","AU-NT","","no","","","YIDR","","","",""
|
|
||||||
"38396","YIKL","small_airport","Baikal Airport","-22.7632999420166","136.16299438476562","","OC","AU","AU-NT","","no","","","YIKL","","","",""
|
|
||||||
"27647","YJAM","small_airport","Jameson Airport","-25.850000381469727","127.68299865722656","","OC","AU","AU-WA","","no","","","YJAM","","","",""
|
|
||||||
"38407","YKCA","small_airport","Kings Canyon Airport","-24.260229","131.488924","2100","OC","AU","AU-NT","Petermann","no","YKCA","KBJ","YKCA","","","",""
|
|
||||||
"38425","YLBG","small_airport","Mount Liebig Airport","-23.24329948425293","131.25999450683594","","OC","AU","AU-NT","","no","","","YLBG","","","",""
|
|
||||||
"27719","YLGN","small_airport","Loongana Airport","-30.940771","127.028781","","OC","AU","AU-WA","","no","","","YLGN","","","",""
|
|
||||||
"27727","YLLC","small_airport","Lilla Creek Airport","-25.55791","134.07114","","OC","AU","AU-NT","","no","","","YLLC","","","",""
|
|
||||||
"38444","YLSY","small_airport","Mount Lindsay Airport","-27.018299102783203","129.88499450683594","","OC","AU","AU-SA","","no","","","YLSY","","","",""
|
|
||||||
"27749","YMAD","small_airport","Madura Airport","-31.887825","127.025573","","OC","AU","AU-WA","","no","","","YMAD","","","",""
|
|
||||||
"32730","YMBX","small_airport","Mundrabilla Airport","-31.86720085144043","127.85399627685547","120","OC","AU","AU-WA","Mundrabilla","no","","","YMBX","","","",""
|
|
||||||
"38455","YMBZ","small_airport","Mount Ebenezer Airport","-25.169763","132.643107","","OC","AU","AU-NT","","no","","","YMBZ","","","",""
|
|
||||||
"27763","YMDV","small_airport","Mount Davies Airport","-26.16670036315918","129.13299560546875","","OC","AU","AU-SA","","no","","","YMDV","","","",""
|
|
||||||
"27789","YMNK","small_airport","Monkira Airport","-24.816699981689453","140.5330047607422","107","OC","AU","AU-QLD","","no","YMNK","ONR","YMNK","","","",""
|
|
||||||
"27185","YYND","small_airport","Yuendumu Airport","-22.2542","131.781998","2205","OC","AU","AU-NT","","no","YYND","YUE","YYND","","","https://en.wikipedia.org/wiki/Yuendumu_Airport",""
|
|
||||||
"31943","YMQA","small_airport","Marqua Airport","-22.80579948425293","137.25100708007812","","OC","AU","AU-NT","Marqua","no","YMQA","MQE","YMQA","","","",""
|
|
||||||
"38495","YMSK","small_airport","Mount Skinner Airport","-22.187801","134.171648","","OC","AU","AU-NT","","no","","","YMSK","","","",""
|
|
||||||
"27812","YMTX","small_airport","Mount Dare Airport","-26.06170082092285","135.2469940185547","","OC","AU","AU-SA","","no","","","YMTX","","","",""
|
|
||||||
"38500","YMUP","small_airport","Mulga Park Airport","-25.860000610399997","131.649993896","","OC","AU","AU-NT","","no","YMUP","MUP","YMUP","","","",""
|
|
||||||
"27823","YMWE","small_airport","Mount Wedge Airport","-22.737199783325195","132.1510009765625","559","OC","AU","AU-NT","","no","","","YMWE","","","",""
|
|
||||||
"38507","YMYV","small_airport","Maryvale Airport","-24.647992","134.026358","","OC","AU","AU-NT","","no","","","YMYV","","","",""
|
|
||||||
"38508","YMYW","small_airport","Murray Downs Airport","-21.04829978942871","134.68299865722656","","OC","AU","AU-NT","","no","","","YMYW","","","",""
|
|
||||||
"38513","YNHV","small_airport","New Haven Airport","-22.728300094604492","131.14500427246094","","OC","AU","AU-NT","","no","","","YNHV","","","",""
|
|
||||||
"27850","YNRR","small_airport","Nyrripi Airport","-22.645299911499023","130.56500244140625","","OC","AU","AU-NT","","no","","","YNRR","","","",""
|
|
||||||
"38523","YNUE","small_airport","Numery Airport","-23.983299255371094","135.39999389648438","","OC","AU","AU-NT","","no","","","YNUE","","","",""
|
|
||||||
"38528","YNWT","small_airport","Narwietooma Airport","-23.228786","132.629378","","OC","AU","AU-NT","","no","","","YNWT","","","",""
|
|
||||||
"38535","YORA","small_airport","Moonerah Airport","-31.691413","126.590523","","OC","AU","AU-WA","","no","","","YORA","","","",""
|
|
||||||
"38537","YORT","small_airport","Ooratippra Airport","-21.905799865722656","136.06900024414062","","OC","AU","AU-NT","","no","","","YORT","","","",""
|
|
||||||
"354815","YPHS","small_airport","Pine Hill Station Airport","-22.386977","133.06025","2142","OC","AU","AU-NT","Anmatjere","no","","","YPHS","","","",""
|
|
||||||
"27924","YRNW","small_airport","Ringwood Airport","-23.82830047607422","134.96200561523438","","OC","AU","AU-NT","","no","","","YRNW","","","",""
|
|
||||||
"27991","YTIT","small_airport","Ti Tree Airport","-22.131701","133.419998","","OC","AU","AU-NT","","no","","","YTIT","","","https://en.wikipedia.org/wiki/Ti-Tree_Airfield",""
|
|
||||||
"38607","YTJU","small_airport","Tjuntjuntjarra Airport","-29.344938","127.107348","740","OC","AU","AU-WA","","no","","","YTJU","","","",""
|
|
||||||
"38609","YTLT","small_airport","Tarlton Downs Airport","-22.63330078125","136.8000030517578","","OC","AU","AU-NT","","no","","","YTLT","","","",""
|
|
||||||
"32491","YTMY","small_airport","Tobermorey Airport","-22.255800247192383","137.9530029296875","","OC","AU","AU-NT","Tobermorey","no","YTMY","TYP","YTMY","","","",""
|
|
||||||
"28014","YTYN","small_airport","Tieyon Airport","-26.216699600219727","133.91700744628906","","OC","AU","AU-SA","","no","","","YTYN","","","",""
|
|
||||||
"38623","YUMB","small_airport","Umbeara Airport","-25.746700286865234","133.70199584960938","","OC","AU","AU-NT","","no","","","YUMB","","","",""
|
|
||||||
"38625","YUTP","small_airport","Utopia Airport","-22.05500030517578","134.7899932861328","","OC","AU","AU-NT","","no","","","YUTP","","","",""
|
|
||||||
"38629","YVNS","small_airport","Vaughan Springs Airport","-22.33329963684082","130.86700439453125","","OC","AU","AU-NT","","no","","","YVNS","","","",""
|
|
||||||
"27165","YWBR","small_airport","Warburton Airport","-26.125538","126.583158","1500","OC","AU","AU-WA","Warburton","no","","","YWBR","","","https://en.wikipedia.org/wiki/Warburton_Airport",""
|
|
||||||
"302312","YWKS","small_airport","Wilkins Runway","-66.690833","111.523611","2529","AN","AQ","AQ-U-A","Preston Heath","no","","","YWKS","","","https://en.wikipedia.org/wiki/Wilkins_Runway",""
|
"302312","YWKS","small_airport","Wilkins Runway","-66.690833","111.523611","2529","AN","AQ","AQ-U-A","Preston Heath","no","","","YWKS","","","https://en.wikipedia.org/wiki/Wilkins_Runway",""
|
||||||
"38645","YWLA","small_airport","Willowra Airport","-21.27669906616211","132.6230010986328","","OC","AU","AU-NT","","no","","","YWLA","","","",""
|
"330063","AT25","small_airport","Showa Station Skiway","-69.006167","39.59","95","AN","AQ","AQ-U-A","Showa Station","no","","","AT25","","","https://en.wikipedia.org/wiki/Showa_Station_(Antarctica)","Syowa Station"
|
||||||
"38647","YWLH","small_airport","Wallara Ranch Airport","-24.649999618530273","132.31700134277344","","OC","AU","AU-NT","","no","","","YWLH","","","",""
|
|
||||||
|
|||||||
|
@@ -0,0 +1,111 @@
|
|||||||
|
import { expect, test } from '@playwright/test';
|
||||||
|
|
||||||
|
// v0.71.0 — Admin panel e2e: top-bar button → modal with login form; wrong credentials show an
|
||||||
|
// error; a session minted by the /api/test/admin-session hook (FLIGHT_TEST_HOOKS=1) authenticates
|
||||||
|
// WITHOUT the real admin password ever appearing in test code; then the generic DB grid is
|
||||||
|
// exercised end-to-end: table list → edit + save a cell (verified by an independent re-fetch) →
|
||||||
|
// add a row → delete it → logout back to the login form.
|
||||||
|
|
||||||
|
const SESSION_KEY = 'flight.session'; // must match components/AdminPanel.tsx
|
||||||
|
|
||||||
|
async function mintAdminSession(page: import('@playwright/test').Page): Promise<string> {
|
||||||
|
const res = await page.request.post('/api/test/admin-session');
|
||||||
|
expect(res.status(), 'admin-session hook should be enabled in the CI stack (FLIGHT_TEST_HOOKS=1)').toBe(200);
|
||||||
|
return ((await res.json()) as { sessionId: string }).sessionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
test('admin panel: login form, wrong-creds error, session auth, DB grid CRUD, logout', async ({ page }) => {
|
||||||
|
await page.goto('/');
|
||||||
|
const adminBtn = page.getByTestId('admin-btn');
|
||||||
|
await expect(adminBtn).toBeVisible({ timeout: 30_000 });
|
||||||
|
|
||||||
|
// --- Open the modal: no stored session → login form.
|
||||||
|
await adminBtn.click();
|
||||||
|
const dialog = page.locator('[role="dialog"]');
|
||||||
|
await expect(dialog).toBeVisible();
|
||||||
|
await expect(page.getByTestId('admin-username')).toBeVisible();
|
||||||
|
await expect(page.getByTestId('admin-password')).toBeVisible();
|
||||||
|
|
||||||
|
// --- Wrong credentials → error line (the seeded admin's plaintext is never used here).
|
||||||
|
await page.getByTestId('admin-username').fill('kamilkrzywda');
|
||||||
|
await page.getByTestId('admin-password').fill('wrong-password-on-purpose');
|
||||||
|
await page.getByTestId('admin-login-submit').click();
|
||||||
|
await expect(page.getByTestId('admin-error')).toBeVisible({ timeout: 10_000 });
|
||||||
|
|
||||||
|
// --- Authenticate via the test hook + localStorage, then reopen the panel.
|
||||||
|
const sessionId = await mintAdminSession(page);
|
||||||
|
// Both values must be passed as arguments — the function runs in the browser, where Node-side
|
||||||
|
// variables are not in scope.
|
||||||
|
await page.evaluate(([key, sid]) => window.localStorage.setItem(key, sid), [SESSION_KEY, sessionId]);
|
||||||
|
await page.reload();
|
||||||
|
await expect(adminBtn).toBeVisible({ timeout: 30_000 });
|
||||||
|
await adminBtn.click();
|
||||||
|
|
||||||
|
// --- Authenticated admin → table list including packages and users.
|
||||||
|
const tables = page.getByTestId('admin-tables');
|
||||||
|
await expect(tables).toBeVisible({ timeout: 30_000 });
|
||||||
|
await expect(page.getByTestId('admin-table-packages')).toBeVisible();
|
||||||
|
await expect(page.getByTestId('admin-table-users')).toBeVisible();
|
||||||
|
|
||||||
|
// --- Open packages, edit one cell, Save; verify via an INDEPENDENT re-fetch of the same route.
|
||||||
|
await page.getByTestId('admin-table-packages').click();
|
||||||
|
const grid = page.getByTestId('admin-rows');
|
||||||
|
await expect(grid).toBeVisible({ timeout: 30_000 });
|
||||||
|
|
||||||
|
const rowidCell = page.getByTestId('admin-cell-0-__rowid');
|
||||||
|
const originalRowid = Number(await rowidCell.inputValue());
|
||||||
|
expect(Number.isInteger(originalRowid)).toBeTruthy();
|
||||||
|
|
||||||
|
const rewardCell = page.getByTestId('admin-cell-0-reward');
|
||||||
|
await rewardCell.fill('987654');
|
||||||
|
await page.getByTestId('admin-save-0').click();
|
||||||
|
|
||||||
|
// The grid re-fetches after save — the edited cell shows the new value…
|
||||||
|
await expect(rewardCell).toHaveValue('987654', { timeout: 15_000 });
|
||||||
|
// …and an independent request (not the grid's) confirms it persisted server-side.
|
||||||
|
const check = await page.request.get('/api/admin/tables/packages/rows?limit=500', {
|
||||||
|
headers: { 'X-Flight-Session': sessionId },
|
||||||
|
});
|
||||||
|
expect(check.status()).toBe(200);
|
||||||
|
const fetched = (await check.json()) as { rows: Array<Record<string, unknown>> };
|
||||||
|
const row = fetched.rows.find((r) => Number(r.__rowid) === originalRowid);
|
||||||
|
expect(row, 'edited packages row must still exist').toBeTruthy();
|
||||||
|
expect(Number(row?.reward)).toBe(987654);
|
||||||
|
|
||||||
|
// --- Add a row (users table — fewest required columns), then delete it again.
|
||||||
|
await page.getByTestId('admin-back').click();
|
||||||
|
await expect(tables).toBeVisible();
|
||||||
|
await page.getByTestId('admin-table-users').click();
|
||||||
|
const usersGrid = page.getByTestId('admin-rows');
|
||||||
|
await expect(usersGrid).toBeVisible({ timeout: 30_000 });
|
||||||
|
|
||||||
|
const existingRows = await page.getByTestId(/admin-save-\d+/).count();
|
||||||
|
await page.getByTestId('admin-add-row').click();
|
||||||
|
const n = existingRows; // the new empty row is appended last
|
||||||
|
await page.getByTestId(`admin-cell-${n}-id`).fill('user-e2e-admin-test');
|
||||||
|
await page.getByTestId(`admin-cell-${n}-username`).fill('e2e-admin-user');
|
||||||
|
await page.getByTestId(`admin-cell-${n}-password_hash`).fill('aa$bb'); // any string — dev-tool insert, not a real credential
|
||||||
|
await page.getByTestId(`admin-cell-${n}-created_at`).fill(String(Date.now()));
|
||||||
|
await page.getByTestId(`admin-save-${n}`).click();
|
||||||
|
|
||||||
|
// The inserted row is visible after the grid's post-save re-fetch.
|
||||||
|
const bodyRows = usersGrid.locator('tbody tr');
|
||||||
|
const findUserRow = async (): Promise<number> => {
|
||||||
|
const count = await bodyRows.count();
|
||||||
|
for (let i = 0; i < count; i++) {
|
||||||
|
if ((await page.getByTestId(`admin-cell-${i}-username`).inputValue()) === 'e2e-admin-user') return i;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
};
|
||||||
|
await expect.poll(findUserRow, { timeout: 15_000 }).toBeGreaterThanOrEqual(0);
|
||||||
|
const addedIdx = await findUserRow();
|
||||||
|
|
||||||
|
// Delete it again — gone after the post-delete re-fetch.
|
||||||
|
await page.getByTestId(`admin-delete-${addedIdx}`).click();
|
||||||
|
await expect.poll(findUserRow, { timeout: 15_000 }).toBe(-1);
|
||||||
|
|
||||||
|
// --- Logout returns to the login form.
|
||||||
|
await page.getByTestId('admin-logout').click();
|
||||||
|
await expect(page.getByTestId('admin-username')).toBeVisible({ timeout: 10_000 });
|
||||||
|
await expect(tables).toBeHidden();
|
||||||
|
});
|
||||||
+8
-3
@@ -13,21 +13,26 @@ test('GET /api/version returns the app version from package.json', async ({ page
|
|||||||
expect(body.version).toBe(pkg.version);
|
expect(body.version).toBe(pkg.version);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('GET /api/openapi serves the spec with all thirteen endpoints and the package.json version', async ({ page }) => {
|
test('GET /api/openapi serves the spec with all seventeen endpoints and the package.json version', async ({ page }) => {
|
||||||
const res = await page.request.get('/api/openapi');
|
const res = await page.request.get('/api/openapi');
|
||||||
expect(res.status()).toBe(200);
|
expect(res.status()).toBe(200);
|
||||||
expect(res.headers()['content-type']).toContain('application/json');
|
expect(res.headers()['content-type']).toContain('application/json');
|
||||||
const spec = (await res.json()) as { info: { title: string; version: string }; paths: Record<string, unknown> };
|
const spec = (await res.json()) as { info: { title: string; version: string }; paths: Record<string, unknown> };
|
||||||
expect(spec.info.title).toBe('Flight Ops API');
|
expect(spec.info.title).toBe('Flight Ops API');
|
||||||
expect(spec.info.version).toBe(pkg.version);
|
expect(spec.info.version).toBe(pkg.version);
|
||||||
// v0.12.0 swaps the contract accept/dispatch pair for package load/abandon + plane fly.
|
// v0.12.0 swaps the contract accept/dispatch pair for package load/abandon + plane fly;
|
||||||
|
// v0.71.0 adds the admin panel (login/logout/me + guarded DB CRUD).
|
||||||
expect(Object.keys(spec.paths).sort()).toEqual([
|
expect(Object.keys(spec.paths).sort()).toEqual([
|
||||||
|
'/api/admin/tables', // v0.71.0 — admin panel
|
||||||
|
'/api/admin/tables/{name}/rows', // v0.71.0 — GET+PUT+POST+DELETE on one path
|
||||||
'/api/airports',
|
'/api/airports',
|
||||||
'/api/events', // v0.57.0 (ISS-129) — SSE state stream
|
'/api/events', // v0.57.0 (ISS-129) — SSE state stream
|
||||||
|
'/api/login', // v0.71.0 — admin panel auth
|
||||||
|
'/api/logout', // v0.71.0
|
||||||
'/api/market/buy-plane',
|
'/api/market/buy-plane',
|
||||||
'/api/market/sell-plane',
|
'/api/market/sell-plane',
|
||||||
|
'/api/me', // v0.71.0
|
||||||
'/api/packages/{id}/abandon',
|
'/api/packages/{id}/abandon',
|
||||||
'/api/packages/{id}/ignore', // v0.29.0 (ISS-047 part B)
|
|
||||||
'/api/packages/{id}/load',
|
'/api/packages/{id}/load',
|
||||||
'/api/planes/{planeId}/fly',
|
'/api/planes/{planeId}/fly',
|
||||||
'/api/planes/{planeId}/queue',
|
'/api/planes/{planeId}/queue',
|
||||||
|
|||||||
+1
-1
@@ -12,7 +12,7 @@ interface StateBody {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ISS-133 (v0.59.0): frames carry only the package statuses the client renders — terminal history
|
// ISS-133 (v0.59.0): frames carry only the package statuses the client renders — terminal history
|
||||||
// (delivered/abandoned/ignored) is unbounded in the DB and must never leak into a pushed frame.
|
// (delivered/abandoned) is unbounded in the DB and must never leak into a pushed frame.
|
||||||
const ALLOWED_PACKAGE_STATUSES = new Set(['open', 'loaded', 'expired']);
|
const ALLOWED_PACKAGE_STATUSES = new Set(['open', 'loaded', 'expired']);
|
||||||
|
|
||||||
test('GET /api/events streams state snapshots over SSE', async () => {
|
test('GET /api/events streams state snapshots over SSE', async () => {
|
||||||
|
|||||||
+3
-3
@@ -63,10 +63,10 @@ test('long-leg priority packages always expire after travel time at max speed +
|
|||||||
created.push(pkg);
|
created.push(pkg);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
// Cleanup: dismiss every package this test created so it leaves no trace on the shared board.
|
// Cleanup: age out every package this test created so it leaves no trace on the shared board.
|
||||||
for (const pkg of created) {
|
for (const pkg of created) {
|
||||||
const r = await page.request.post(`/api/packages/${pkg.id}/ignore`);
|
const r = await page.request.post('/api/test/expire-package', { data: { packageId: pkg.id } });
|
||||||
expect(r.ok(), `ignoring ${pkg.id}`).toBeTruthy();
|
expect(r.ok(), `expiring ${pkg.id}`).toBeTruthy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
+7
-9
@@ -162,8 +162,8 @@ async function unhover(page: Page): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fit the map so all given airports are in-viewport — queryRenderedFeatures only returns
|
// Fit the map so all given airports are in-viewport — queryRenderedFeatures only returns
|
||||||
// features rendered inside the CURRENT viewport, and the default Frankfurt-centered view leaves
|
// features rendered inside the CURRENT viewport, and the v0.70.0 default world view ([0,0] z2) leaves
|
||||||
// far endpoints (LEMD) off-screen even when they match a layer filter.
|
// far endpoints (e.g. NFTF) off-screen even when they match a layer filter.
|
||||||
async function fitToAirports(page: Page, icaos: string[]): Promise<void> {
|
async function fitToAirports(page: Page, icaos: string[]): Promise<void> {
|
||||||
const fc = (await (await page.request.get('/api/airports')).json()) as {
|
const fc = (await (await page.request.get('/api/airports')).json()) as {
|
||||||
features: Array<{ properties: { icao: string; lat: number; lon: number } }>;
|
features: Array<{ properties: { icao: string; lat: number; lon: number } }>;
|
||||||
@@ -321,8 +321,7 @@ test('hovering an open package highlights its endpoint airports', async ({ page
|
|||||||
const row = page.locator(`li[data-testid="open-package-${pkg.id}"]`);
|
const row = page.locator(`li[data-testid="open-package-${pkg.id}"]`);
|
||||||
await expect(row, 'the hook-created package appears in the list').toBeVisible({ timeout: 15_000 });
|
await expect(row, 'the hook-created package appears in the list').toBeVisible({ timeout: 15_000 });
|
||||||
|
|
||||||
// Both endpoints must be in-viewport for queryRenderedFeatures to see them (LEMD is off-screen
|
// Both endpoints must be in-viewport for queryRenderedFeatures to see them.
|
||||||
// at the default Frankfurt-centered view).
|
|
||||||
await fitToAirports(page, [HUB, DEST]);
|
await fitToAirports(page, [HUB, DEST]);
|
||||||
|
|
||||||
expect(await renderedFeatures(page, ['airports-highlight'])).toHaveLength(0);
|
expect(await renderedFeatures(page, ['airports-highlight'])).toHaveLength(0);
|
||||||
@@ -379,11 +378,10 @@ test('hovering an antimeridian-crossing package draws one continuous trace, no c
|
|||||||
const row = page.locator(`li[data-testid="open-package-${pkg.id}"]`);
|
const row = page.locator(`li[data-testid="open-package-${pkg.id}"]`);
|
||||||
await expect(row, 'the hook-created package appears in the list').toBeVisible({ timeout: 15_000 });
|
await expect(row, 'the hook-created package appears in the list').toBeVisible({ timeout: 15_000 });
|
||||||
|
|
||||||
// fitToAirports unwraps crossing pairs (ISS-120) so both endpoints are in-viewport.
|
// fitToAirports unwraps crossing pairs (ISS-120) so both endpoints are in-viewport. EDDF→NFTF spans
|
||||||
// EDDF→NFTF spans ~176° of longitude — it can't fit at MIN_ZOOM=3 (components/Map.tsx), so the camera
|
// ~176° of longitude — fitting it needs z≈1, below the old MIN_ZOOM=3 floor; since v0.70.0 minZoom is
|
||||||
// clamps to z=3 and both endpoints are off-viewport → queryRenderedFeatures never sees the trace.
|
// natively 0 (components/Map.tsx), no setMinZoom workaround is needed anymore. Quantization stays
|
||||||
// Lift the floor for this test's camera; quantization stays ≤~0.02° even near z=0, below EPS (:214–228).
|
// ≤~0.02° even near z=0, below EPS (:214–228).
|
||||||
await page.evaluate(() => (window as any).__flightMap?.setMinZoom(0));
|
|
||||||
await fitToAirports(page, [HUB, 'NFTF']);
|
await fitToAirports(page, [HUB, 'NFTF']);
|
||||||
|
|
||||||
await row.hover();
|
await row.hover();
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ async function loadAndFly(page: Page, fromIcao: string, toIcao: string): Promise
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Features in LOADED tiles only — MapLibre loads GeoJSON per viewport tile, so the camera must be over
|
// Features in LOADED tiles only — MapLibre loads GeoJSON per viewport tile, so the camera must be over
|
||||||
// the area of interest first ([] until then). Same trap as run-176: Europe view + Pacific plane = [].
|
// the area of interest first ([] until then). Same trap as run-176: default world view + Pacific plane = [].
|
||||||
function sourceFeatures(page: Page, sourceId: string) {
|
function sourceFeatures(page: Page, sourceId: string) {
|
||||||
return page.evaluate((srcId: string) => {
|
return page.evaluate((srcId: string) => {
|
||||||
const m = (window as any).__flightMap;
|
const m = (window as any).__flightMap;
|
||||||
@@ -155,7 +155,23 @@ test('airport popup shows name, ICAO, local time and generated weather', async (
|
|||||||
{ timeout: 15_000 },
|
{ timeout: 15_000 },
|
||||||
).toBeGreaterThan(0);
|
).toBeGreaterThan(0);
|
||||||
|
|
||||||
// LFRS Nantes Atlantique — same isolated marker as e2e/map.spec.ts.
|
// LFRS Nantes Atlantique — same isolated marker as e2e/map.spec.ts. The v0.70.0 default view
|
||||||
|
// ([0,0] z2) shows both Africa + Europe with overlapping markers (nearest neighbour LFRB Brest is
|
||||||
|
// only ~13–19 px away at z2), so frame LFRS at z5 first — its nearest marker is then ~104 px away.
|
||||||
|
await page.evaluate(() => {
|
||||||
|
(window as any).__flightMap.jumpTo({ center: [-1.61073, 47.153198], zoom: 5 });
|
||||||
|
});
|
||||||
|
// Wait until LFRS's marker is actually rendered at the new camera before clicking it.
|
||||||
|
await expect.poll(async () =>
|
||||||
|
page.evaluate(() => {
|
||||||
|
const map = (window as any).__flightMap;
|
||||||
|
const p = map.project([-1.61073, 47.153198]);
|
||||||
|
return (map.queryRenderedFeatures([p.x, p.y], { layers: ['airports-circles'] }) as Array<{ properties?: Record<string, unknown> }>)
|
||||||
|
.some((f) => f.properties?.icao === 'LFRS');
|
||||||
|
}),
|
||||||
|
{ timeout: 15_000 },
|
||||||
|
).toBe(true);
|
||||||
|
|
||||||
const pt = await page.evaluate(() => {
|
const pt = await page.evaluate(() => {
|
||||||
const map = (window as any).__flightMap;
|
const map = (window as any).__flightMap;
|
||||||
const p = map.project([-1.61073, 47.153198]); // LFRS Nantes Atlantique
|
const p = map.project([-1.61073, 47.153198]); // LFRS Nantes Atlantique
|
||||||
@@ -281,6 +297,11 @@ test('plane markers move while flying and the plane popup shows status + route',
|
|||||||
}, { timeout: 15_000, message: 'waiting for the scale-1 clock to slow the plane to click-safe drift' })
|
}, { timeout: 15_000, message: 'waiting for the scale-1 clock to slow the plane to click-safe drift' })
|
||||||
.toBe(true);
|
.toBe(true);
|
||||||
|
|
||||||
|
// queryRenderedFeatures is viewport-scoped, and at the v0.70.0 default view ([0,0] z2) this pane
|
||||||
|
// only shows latitudes ~±51° — EDDF (50°N) sits right at its edge, so frame both endpoints of the
|
||||||
|
// leg to guarantee the plane marker is rendered wherever it is on it.
|
||||||
|
await fitToAirports(page, [HUB, DEST]);
|
||||||
|
|
||||||
// Click the RENDERED marker position, not a fresh /api/state fetch. With the clock at scale 1
|
// Click the RENDERED marker position, not a fresh /api/state fetch. With the clock at scale 1
|
||||||
// above the server's analytic position barely moves — but the map renders from its own ~1 s
|
// above the server's analytic position barely moves — but the map renders from its own ~1 s
|
||||||
// poll, so right after the freeze confirmation the last rendered frame can still be up to
|
// poll, so right after the freeze confirmation the last rendered frame can still be up to
|
||||||
@@ -500,8 +521,8 @@ test('plane marker stays continuous across the antimeridian (no 360° teleport)'
|
|||||||
await setScale(page, SCALE);
|
await setScale(page, SCALE);
|
||||||
console.log(`[antimeridian] AFTER dispatch: ${fmtPlane((await getState(page)).planes.find((x) => x.id === 'plane-starter')!)}`);
|
console.log(`[antimeridian] AFTER dispatch: ${fmtPlane((await getState(page)).planes.find((x) => x.id === 'plane-starter')!)}`);
|
||||||
|
|
||||||
// querySourceFeatures only sees LOADED tiles — the default view is over Europe and this leg is in the
|
// querySourceFeatures only sees LOADED tiles — the v0.70.0 default view ([0,0] z2) doesn't cover this
|
||||||
// Pacific: fit the camera over both endpoints first or the plane feature never appears in queries.
|
// Pacific leg: fit the camera over both endpoints first or the plane feature never appears in queries.
|
||||||
await fitToAirports(page, [ORIGIN, CROSS_DEST]);
|
await fitToAirports(page, [ORIGIN, CROSS_DEST]);
|
||||||
|
|
||||||
// Wait until SERVER state shows plane-starter flying on THIS specific leg (origin/dest pair match) AND
|
// Wait until SERVER state shows plane-starter flying on THIS specific leg (origin/dest pair match) AND
|
||||||
|
|||||||
+58
-17
@@ -8,9 +8,32 @@ const APP_URL = '/';
|
|||||||
const pkg = JSON.parse(readFileSync(join(__dirname, '..', 'package.json'), 'utf8')) as { version: string };
|
const pkg = JSON.parse(readFileSync(join(__dirname, '..', 'package.json'), 'utf8')) as { version: string };
|
||||||
|
|
||||||
// Must match MIN_ZOOM / MAX_ZOOM exported from components/Map.tsx.
|
// Must match MIN_ZOOM / MAX_ZOOM exported from components/Map.tsx.
|
||||||
const MIN_ZOOM = 3;
|
const MIN_ZOOM = 0; // v0.70.0: lowered 3 → 0 so the whole earth is visible when fully zoomed out
|
||||||
const MAX_ZOOM = 11;
|
const MAX_ZOOM = 11;
|
||||||
|
|
||||||
|
// LFRS Nantes Atlantique — the marker-click target of this file (and e2e/map-interactions.spec.ts,
|
||||||
|
// e2e/relocation.spec.ts). The v0.70.0 default view ([0,0] z2) shows both Africa + Europe with
|
||||||
|
// overlapping markers (nearest neighbour LFRB Brest is only ~13–19 px away at z2), so every click
|
||||||
|
// test first frames LFRS at z5 — its nearest marker is then ~104 px away and the projected center
|
||||||
|
// cannot hit a neighbouring circle.
|
||||||
|
const LFRS: [number, number] = [-1.61073, 47.153198];
|
||||||
|
|
||||||
|
async function frameLfrs(page: Page): Promise<void> {
|
||||||
|
await page.evaluate((c) => (window as any).__flightMap.jumpTo({ center: c, zoom: 5 }), LFRS);
|
||||||
|
// Wait until LFRS's marker is actually rendered at the new camera before clicking it. The
|
||||||
|
// coordinate is passed AS AN ARGUMENT — evaluate callbacks run in the browser, where Node-scope
|
||||||
|
// values don't exist (same trap as e2e/relocation.spec.ts).
|
||||||
|
await expect.poll(async () =>
|
||||||
|
page.evaluate((c) => {
|
||||||
|
const map = (window as any).__flightMap;
|
||||||
|
const p = map.project(c);
|
||||||
|
return (map.queryRenderedFeatures([p.x, p.y], { layers: ['airports-circles'] }) as Array<{ properties?: Record<string, unknown> }>)
|
||||||
|
.some((f) => f.properties?.icao === 'LFRS');
|
||||||
|
}, LFRS),
|
||||||
|
{ timeout: 15_000 },
|
||||||
|
).toBe(true);
|
||||||
|
}
|
||||||
|
|
||||||
async function waitForAirportCount(page: Page): Promise<number> {
|
async function waitForAirportCount(page: Page): Promise<number> {
|
||||||
const countEl = page.getByTestId('airport-count');
|
const countEl = page.getByTestId('airport-count');
|
||||||
await expect.poll(async () => {
|
await expect.poll(async () => {
|
||||||
@@ -27,6 +50,16 @@ test('page loads with the map and world airport count', async ({ page }) => {
|
|||||||
await expect(page.getByTestId('map')).toBeVisible();
|
await expect(page.getByTestId('map')).toBeVisible();
|
||||||
const count = await waitForAirportCount(page);
|
const count = await waitForAirportCount(page);
|
||||||
expect(count).toBeGreaterThan(0);
|
expect(count).toBeGreaterThan(0);
|
||||||
|
|
||||||
|
// v0.70.0 default view: null island [0,0] at zoom 2 (Africa + Europe both visible). The map
|
||||||
|
// instance exists by the time the airport count renders — it is created before airports load.
|
||||||
|
const view = await page.evaluate(() => {
|
||||||
|
const m = (window as any).__flightMap;
|
||||||
|
return { lng: m.getCenter().lng, lat: m.getCenter().lat, z: m.getZoom() };
|
||||||
|
});
|
||||||
|
expect(view.z).toBeCloseTo(2);
|
||||||
|
expect(view.lng).toBeCloseTo(0);
|
||||||
|
expect(view.lat).toBeCloseTo(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('header shows the app version sourced from package.json', async ({ page }) => {
|
test('header shows the app version sourced from package.json', async ({ page }) => {
|
||||||
@@ -56,18 +89,15 @@ test('clicking an airport marker opens a popup with name and ICAO', async ({ pag
|
|||||||
{ timeout: 15_000 },
|
{ timeout: 15_000 },
|
||||||
).toBeGreaterThan(0);
|
).toBeGreaterThan(0);
|
||||||
|
|
||||||
// Project LFRS (Nantes Atlantique) to screen space via the dev hook, then click it.
|
// Frame LFRS (Nantes Atlantique) so its marker is isolated again — see frameLfrs above for why
|
||||||
// Nantes is used because the v0.9.0 three-pane layout narrows the map column (~560 px at the
|
// the v0.70.0 default view needs this — then project it to screen space via the dev hook and click.
|
||||||
// default 1280×720 viewport), which puts most of the world outside the initial view; LFRS stays
|
await frameLfrs(page);
|
||||||
// isolated in it even with the v0.44.0 world dataset — its nearest markers are LFRB Brest and
|
const pt = await page.evaluate((c) => {
|
||||||
// LFBD Bordeaux, ~39 px away at the initial zoom [10,52] z4 (verified against data/airports_world.csv),
|
|
||||||
// so its marker cannot be overlapped by a neighbouring circle.
|
|
||||||
const pt = await page.evaluate(() => {
|
|
||||||
const map = (window as any).__flightMap;
|
const map = (window as any).__flightMap;
|
||||||
const p = map.project([-1.61073, 47.153198]); // LFRS Nantes Atlantique — see the marker-click test above for why
|
const p = map.project(c); // LFRS Nantes Atlantique — see frameLfrs above for why it's framed at z5
|
||||||
const rect = map.getContainer().getBoundingClientRect();
|
const rect = map.getContainer().getBoundingClientRect();
|
||||||
return { x: rect.left + p.x, y: rect.top + p.y };
|
return { x: rect.left + p.x, y: rect.top + p.y };
|
||||||
});
|
}, LFRS);
|
||||||
await page.mouse.click(pt.x, pt.y);
|
await page.mouse.click(pt.x, pt.y);
|
||||||
|
|
||||||
const popup = page.getByTestId('airport-popup');
|
const popup = page.getByTestId('airport-popup');
|
||||||
@@ -138,12 +168,18 @@ test('wheel zoom is clamped between min and max zoom', async ({ page }) => {
|
|||||||
await waitForStableZoom();
|
await waitForStableZoom();
|
||||||
expect(await getZoom()).toBeCloseTo(MAX_ZOOM);
|
expect(await getZoom()).toBeCloseTo(MAX_ZOOM);
|
||||||
|
|
||||||
// Zoom out well below MIN_ZOOM with several large deltas.
|
// Zoom out to the effective minimum. MapLibre won't zoom out past the point where
|
||||||
await jumpTo(MIN_ZOOM + 1);
|
// the world no longer covers the viewport height (fit floor = log2(h/512)), so with
|
||||||
await wheelToLimit(600, (z) => z <= MIN_ZOOM + 1e-9);
|
// MIN_ZOOM=0 the reachable limit is max(MIN_ZOOM, fitFloor) — "just far enough to see
|
||||||
|
// the whole Earth", which is exactly what min zoom should give.
|
||||||
|
const mapBox = await page.getByTestId('map').boundingBox();
|
||||||
|
if (!mapBox) throw new Error('map bounding box unavailable');
|
||||||
|
const minLimit = Math.max(MIN_ZOOM, Math.log2(mapBox.height / 512));
|
||||||
|
await jumpTo(minLimit + 1);
|
||||||
|
await wheelToLimit(600, (z) => z <= minLimit + 1e-9);
|
||||||
await waitForStableZoom();
|
await waitForStableZoom();
|
||||||
const zoom = await getZoom();
|
const zoom = await getZoom();
|
||||||
expect(zoom).toBeCloseTo(MIN_ZOOM);
|
expect(zoom).toBeCloseTo(minLimit);
|
||||||
expect(zoom).toBeGreaterThanOrEqual(MIN_ZOOM);
|
expect(zoom).toBeGreaterThanOrEqual(MIN_ZOOM);
|
||||||
expect(zoom).toBeLessThanOrEqual(MAX_ZOOM);
|
expect(zoom).toBeLessThanOrEqual(MAX_ZOOM);
|
||||||
});
|
});
|
||||||
@@ -189,6 +225,9 @@ test('style switcher defaults to Fiord, switches styles, and keeps the airports
|
|||||||
await expect(page.getByTestId('airport-count')).toContainText(/world airports/);
|
await expect(page.getByTestId('airport-count')).toContainText(/world airports/);
|
||||||
await expect.poll(renderedCircles, { timeout: 15_000 }).toBeGreaterThan(0);
|
await expect.poll(renderedCircles, { timeout: 15_000 }).toBeGreaterThan(0);
|
||||||
|
|
||||||
|
// Frame LFRS at z5 first — see frameLfrs above for why the v0.70.0 default view needs this.
|
||||||
|
await frameLfrs(page);
|
||||||
|
|
||||||
// Clicking a marker after the switch opens exactly one popup (the click handler is
|
// Clicking a marker after the switch opens exactly one popup (the click handler is
|
||||||
// re-wired idempotently — no duplicate listeners). MapLibre's diff-based setStyle removes our
|
// re-wired idempotently — no duplicate listeners). MapLibre's diff-based setStyle removes our
|
||||||
// custom source/layer before ensureAirportsLayer re-adds it on the next styledata event, so
|
// custom source/layer before ensureAirportsLayer re-adds it on the next styledata event, so
|
||||||
@@ -258,12 +297,14 @@ test('falls back to remote OFM styles when the local asset pack is absent', asyn
|
|||||||
{ timeout: 15_000 },
|
{ timeout: 15_000 },
|
||||||
).toBeGreaterThan(0);
|
).toBeGreaterThan(0);
|
||||||
|
|
||||||
const pt = await page.evaluate(() => {
|
// Frame LFRS at z5 first — see frameLfrs above for why the v0.70.0 default view needs this.
|
||||||
|
await frameLfrs(page);
|
||||||
|
const pt = await page.evaluate((c) => {
|
||||||
const map = (window as any).__flightMap;
|
const map = (window as any).__flightMap;
|
||||||
const p = map.project([-1.61073, 47.153198]); // LFRS Nantes Atlantique — see the marker-click test above for why
|
const p = map.project(c); // LFRS Nantes Atlantique — see frameLfrs above for why it's framed at z5
|
||||||
const rect = map.getContainer().getBoundingClientRect();
|
const rect = map.getContainer().getBoundingClientRect();
|
||||||
return { x: rect.left + p.x, y: rect.top + p.y };
|
return { x: rect.left + p.x, y: rect.top + p.y };
|
||||||
});
|
}, LFRS);
|
||||||
await page.mouse.click(pt.x, pt.y);
|
await page.mouse.click(pt.x, pt.y);
|
||||||
|
|
||||||
const popup = page.getByTestId('airport-popup');
|
const popup = page.getByTestId('airport-popup');
|
||||||
|
|||||||
+25
-2
@@ -12,10 +12,27 @@ import { expect, test } from '@playwright/test';
|
|||||||
const SCALE = 1000; // test rate for fast-forwarding legs — keeps cleanup flights to seconds of real time
|
const SCALE = 1000; // test rate for fast-forwarding legs — keeps cleanup flights to seconds of real time
|
||||||
const WORLD = 24; // the fixed world rate (ISS-117) — must match lib/worldClock.ts
|
const WORLD = 24; // the fixed world rate (ISS-117) — must match lib/worldClock.ts
|
||||||
const HUB = 'EDDF'; // Frankfurt Main — the seeded starter plane's home base (lib/game/seed.ts)
|
const HUB = 'EDDF'; // Frankfurt Main — the seeded starter plane's home base (lib/game/seed.ts)
|
||||||
// LFRS Nantes Atlantique — same isolated marker as e2e/map.spec.ts: its nearest neighbour is ~78 px
|
// LFRS Nantes Atlantique — same isolated marker as e2e/map.spec.ts. The v0.70.0 default view ([0,0] z2)
|
||||||
// away at the initial zoom, so a click on its projected center cannot hit another circle.
|
// shows both Africa + Europe with overlapping markers (LFRS's nearest neighbour LFRB Brest is only
|
||||||
|
// ~13–19 px away at z2), so framePopupAirport below frames it at z5 first — its nearest marker is then
|
||||||
|
// ~104 px away and a click on the projected center cannot hit another circle.
|
||||||
const POPUP_AIRPORT = { icao: 'LFRS', lon: -1.61073, lat: 47.153198 };
|
const POPUP_AIRPORT = { icao: 'LFRS', lon: -1.61073, lat: 47.153198 };
|
||||||
|
|
||||||
|
async function framePopupAirport(page: Page): Promise<void> {
|
||||||
|
await page.evaluate((a) => (window as any).__flightMap.jumpTo({ center: [a.lon, a.lat], zoom: 5 }), POPUP_AIRPORT);
|
||||||
|
// Wait until the marker is actually rendered at the new camera before clicking it. The airport is
|
||||||
|
// passed AS AN ARGUMENT — evaluate callbacks run in the browser, where Node-scope values don't exist.
|
||||||
|
await expect.poll(async () =>
|
||||||
|
page.evaluate((a) => {
|
||||||
|
const map = (window as any).__flightMap;
|
||||||
|
const p = map.project([a.lon, a.lat]);
|
||||||
|
return (map.queryRenderedFeatures([p.x, p.y], { layers: ['airports-circles'] }) as Array<{ properties?: Record<string, unknown> }>)
|
||||||
|
.some((f) => f.properties?.icao === a.icao);
|
||||||
|
}, POPUP_AIRPORT),
|
||||||
|
{ timeout: 15_000 },
|
||||||
|
).toBe(true);
|
||||||
|
}
|
||||||
|
|
||||||
interface StateBody {
|
interface StateBody {
|
||||||
planes: Array<{ id: string; status: string; maxFuel: number; locationIcao: string; destIcao: string | null; queue: string[] }>;
|
planes: Array<{ id: string; status: string; maxFuel: number; locationIcao: string; destIcao: string | null; queue: string[] }>;
|
||||||
}
|
}
|
||||||
@@ -161,6 +178,9 @@ test('airport popup offers Relocate options for grounded planes', async ({ page
|
|||||||
{ timeout: 15_000 },
|
{ timeout: 15_000 },
|
||||||
).toBe(true);
|
).toBe(true);
|
||||||
|
|
||||||
|
// Frame the popup airport at z5 first — see framePopupAirport above for why the v0.70.0 default view needs this.
|
||||||
|
await framePopupAirport(page);
|
||||||
|
|
||||||
// Click the LFRS marker (projected center — same pattern as e2e/map.spec.ts). The constant is
|
// Click the LFRS marker (projected center — same pattern as e2e/map.spec.ts). The constant is
|
||||||
// passed AS AN ARGUMENT: the evaluate callback runs in the browser, where Node-scope values don't exist.
|
// passed AS AN ARGUMENT: the evaluate callback runs in the browser, where Node-scope values don't exist.
|
||||||
const pt = await page.evaluate(({ lon, lat }) => {
|
const pt = await page.evaluate(({ lon, lat }) => {
|
||||||
@@ -241,6 +261,9 @@ test('airport popup Relocate queues a leg for a flying plane', async ({ page })
|
|||||||
{ timeout: 15_000 },
|
{ timeout: 15_000 },
|
||||||
).toBe(true);
|
).toBe(true);
|
||||||
|
|
||||||
|
// Frame the popup airport at z5 first — see framePopupAirport above for why the v0.70.0 default view needs this.
|
||||||
|
await framePopupAirport(page);
|
||||||
|
|
||||||
const pt = await page.evaluate(({ lon, lat }) => {
|
const pt = await page.evaluate(({ lon, lat }) => {
|
||||||
const map = (window as any).__flightMap;
|
const map = (window as any).__flightMap;
|
||||||
const p = map.project([lon, lat]);
|
const p = map.project([lon, lat]);
|
||||||
|
|||||||
+1
-33
@@ -40,7 +40,7 @@ interface PackageState {
|
|||||||
originName: string;
|
originName: string;
|
||||||
destName: string;
|
destName: string;
|
||||||
reward: number;
|
reward: number;
|
||||||
status: 'open' | 'loaded' | 'delivered' | 'expired' | 'abandoned' | 'ignored'; // v0.29.0 (ISS-047 part B)
|
status: 'open' | 'loaded' | 'delivered' | 'expired' | 'abandoned';
|
||||||
planeId: string | null;
|
planeId: string | null;
|
||||||
createdSimTime: number;
|
createdSimTime: number;
|
||||||
deadlineSimTime: number;
|
deadlineSimTime: number;
|
||||||
@@ -447,38 +447,6 @@ test('dispatch auto-refuels: a low tank tops up to 150% of the leg requirement a
|
|||||||
expect((await page.request.post('/api/test/set-fuel', { data: { planeId: 'plane-starter', fuel: entry.maxFuel } })).status()).toBe(200);
|
expect((await page.request.post('/api/test/set-fuel', { data: { planeId: 'plane-starter', fuel: entry.maxFuel } })).status()).toBe(200);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Ignore removes an open job from the list permanently (ISS-047 part B)', async ({ page }) => {
|
|
||||||
test.setTimeout(300_000); // self-heal can take minutes after an interrupted run
|
|
||||||
await flyHomeViaApi(page); // deterministic: the starter sits at EDDF
|
|
||||||
|
|
||||||
const nearest = await nearestToHub(page);
|
|
||||||
const pkg = await createPackage(page, HUB, nearest.icao, 24 * 3_600_000);
|
|
||||||
|
|
||||||
await page.goto('/');
|
|
||||||
const row = page.locator(`li[data-testid="open-package-${pkg.id}"]`);
|
|
||||||
await expect(row, 'the hook-created package appears in the list').toBeVisible({ timeout: 15_000 });
|
|
||||||
|
|
||||||
// Ignore through the UI — the post-action snapshot lands immediately (no poll wait).
|
|
||||||
const ignoreBtn = page.getByTestId(`ignore-${pkg.id}`);
|
|
||||||
await expect(ignoreBtn, 'the row has an Ignore button').toBeEnabled();
|
|
||||||
await ignoreBtn.click();
|
|
||||||
|
|
||||||
// Server truth: the package is 'ignored'…
|
|
||||||
await expect
|
|
||||||
.poll(async () => (await getState(page)).packages.find((p) => p.id === pkg.id)?.status, {
|
|
||||||
timeout: 15_000,
|
|
||||||
message: 'waiting for the ignored status in /api/state',
|
|
||||||
})
|
|
||||||
.toBe('ignored');
|
|
||||||
|
|
||||||
// …and the row is gone from the open list (the section filters status==='open').
|
|
||||||
await expect(row).not.toBeVisible({ timeout: 15_000 });
|
|
||||||
|
|
||||||
// A second ignore attempt on the same id is a 409 — 'ignored' is terminal.
|
|
||||||
const again = await page.request.post(`/api/packages/${pkg.id}/ignore`);
|
|
||||||
expect(again.status()).toBe(409);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Planes market tab lists all plane types with tech specs', async ({ page }) => {
|
test('Planes market tab lists all plane types with tech specs', async ({ page }) => {
|
||||||
await page.goto('/');
|
await page.goto('/');
|
||||||
const body = await getState(page); // authoritative catalog — v0.28.0 ships six types
|
const body = await getState(page); // authoritative catalog — v0.28.0 ships six types
|
||||||
|
|||||||
+11
-10
@@ -84,7 +84,7 @@ test('a fully grounded fleet freezes the world clock (#135)', async ({ page }) =
|
|||||||
expect(after.simState.clockMs - c0, 'the grounded clock must stay frozen').toBe(0);
|
expect(after.simState.clockMs - c0, 'the grounded clock must stay frozen').toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('a grounded fleet never starves: ignoring every open package cannot empty the market (#135 follow-up)', async ({ page }) => {
|
test('a grounded fleet never starves: draining every open package cannot empty the market (#135 follow-up)', async ({ page }) => {
|
||||||
// Self-heal to a fully grounded fleet first — that is what freezes the world clock (#135), and
|
// Self-heal to a fully grounded fleet first — that is what freezes the world clock (#135), and
|
||||||
// the freeze is exactly what used to let the drain stick (no frozen tick spawned replacements).
|
// the freeze is exactly what used to let the drain stick (no frozen tick spawned replacements).
|
||||||
await expect
|
await expect
|
||||||
@@ -100,23 +100,24 @@ test('a grounded fleet never starves: ignoring every open package cannot empty t
|
|||||||
expect(before.planes.every((p) => p.status === 'available'), 'fleet should be grounded at spec start').toBe(true);
|
expect(before.planes.every((p) => p.status === 'available'), 'fleet should be grounded at spec start').toBe(true);
|
||||||
const clockBefore = before.simState.clockMs;
|
const clockBefore = before.simState.clockMs;
|
||||||
|
|
||||||
// Drain: ignore every open package, pass after pass. Pre-fix (v0.62.0) a frozen tick never
|
// Drain: expire every open package via the test hook (FLIGHT_TEST_HOOKS=1), pass after pass —
|
||||||
// spawned replacements, so this reached zero and stayed there — the soft-lock. Post-fix every
|
// ignore was removed in v0.69.0 and loading can't drain a pool either (the starter's payload fits
|
||||||
// request's tick re-tops-up BEFORE its removal, so the market can never empty; cap the passes to
|
// only the lightest band). Pre-fix (v0.62.0) a frozen tick never spawned replacements, so this
|
||||||
// bound runtime either way (a zero-open snapshot would mean the bug is back). v0.65.0: ignoring
|
// reached zero and stayed there — the soft-lock. Post-fix every request's tick re-tops-up around
|
||||||
// starts each slot's refill cooldown (seconds in CI via FLIGHT_JOB_*_REFILL_MS), so the board
|
// its removal, so the market can never empty; cap the passes to bound runtime either way (a
|
||||||
// comes back a few seconds after the drain, not instantly.
|
// zero-open snapshot would mean the bug is back). Expired slots carry no refill cooldown, so the
|
||||||
|
// board comes back on the very next tick.
|
||||||
for (let pass = 0; pass < 3; pass++) {
|
for (let pass = 0; pass < 3; pass++) {
|
||||||
const s = await getState(page);
|
const s = await getState(page);
|
||||||
const open = s.packages.filter((p) => p.status === 'open');
|
const open = s.packages.filter((p) => p.status === 'open');
|
||||||
if (open.length === 0) break; // drained — the pre-fix soft-lock state
|
if (open.length === 0) break; // drained — the pre-fix soft-lock state
|
||||||
for (const p of open) {
|
for (const p of open) {
|
||||||
expect((await page.request.post(`/api/packages/${p.id}/ignore`)).status()).toBe(200);
|
expect((await page.request.post('/api/test/expire-package', { data: { packageId: p.id } })).status()).toBe(200);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The ~1 s background tick must refill the pool once the cooldowns lapse — within ~15 s of real
|
// Expired slots respawn immediately (no cooldown), so the ~1 s background tick must refill the
|
||||||
// time (CI's heavy-job refill delay is 5 s, so allow headroom for dind slowness)…
|
// pool right away — within ~15 s of real time, with headroom for dind slowness…
|
||||||
let topped: StateBody | undefined;
|
let topped: StateBody | undefined;
|
||||||
await expect
|
await expect
|
||||||
.poll(async () => {
|
.poll(async () => {
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ interface PackageState {
|
|||||||
id: string;
|
id: string;
|
||||||
originIcao: string;
|
originIcao: string;
|
||||||
destIcao: string;
|
destIcao: string;
|
||||||
status: 'open' | 'loaded' | 'delivered' | 'expired' | 'abandoned' | 'ignored';
|
status: 'open' | 'loaded' | 'delivered' | 'expired' | 'abandoned';
|
||||||
planeId: string | null;
|
planeId: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { promises as fs } from 'node:fs';
|
|||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import { describe, expect, it } from 'vitest';
|
import { describe, expect, it } from 'vitest';
|
||||||
import { assertUniqueIcaos, filterWorldAirports, isRemote, parseCsv, toGeoJson, airportsHandler, REMOTE_RADIUS_KM } from './airports';
|
import { assertUniqueIcaos, filterWorldAirports, isRemote, parseCsv, toGeoJson, airportsHandler, REMOTE_RADIUS_KM } from './airports';
|
||||||
|
import { haversineKm } from './geo';
|
||||||
|
|
||||||
const HEADER =
|
const HEADER =
|
||||||
'"id","ident","type","name","latitude_deg","longitude_deg","elevation_ft","continent","iso_country","iso_region","municipality","scheduled_service","icao_code","iata_code","gps_code","local_code","home_link","wikipedia_link","keywords"';
|
'"id","ident","type","name","latitude_deg","longitude_deg","elevation_ft","continent","iso_country","iso_region","municipality","scheduled_service","icao_code","iata_code","gps_code","local_code","home_link","wikipedia_link","keywords"';
|
||||||
@@ -191,4 +192,20 @@ describe('isRemote (v0.61.0 — ISS-097 special remote airports)', () => {
|
|||||||
expect(isRemote([...large, self], self.icao), `${self.icao} (${r.name}) must be remote`).toBe(true);
|
expect(isRemote([...large, self], self.icao), `${self.icao} (${r.name}) must be remote`).toBe(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('committed dataset sparsity rule: every pair of non-large rows is at least REMOTE_RADIUS_KM apart', async () => {
|
||||||
|
const text = await fs.readFile(path.join(process.cwd(), 'data', 'airports_world.csv'), 'utf8');
|
||||||
|
const rows = filterWorldAirports(parseCsv(text));
|
||||||
|
// v0.68.0 (ISS-144): specials are greedily thinned to one per ~REMOTE_RADIUS_KM region, so no
|
||||||
|
// two non-large rows may sit closer than the radius. n≈dozens makes O(n²) trivial.
|
||||||
|
const nonLarge = rows.filter((r) => r.type !== 'large_airport').map((r) => ({ icao: r.icao_code || r.ident, lat: +r.latitude_deg, lon: +r.longitude_deg }));
|
||||||
|
expect(nonLarge.length).toBeGreaterThan(0);
|
||||||
|
|
||||||
|
for (let i = 0; i < nonLarge.length; i++) {
|
||||||
|
for (let j = i + 1; j < nonLarge.length; j++) {
|
||||||
|
const d = haversineKm(nonLarge[i].lat, nonLarge[i].lon, nonLarge[j].lat, nonLarge[j].lon);
|
||||||
|
expect(d, `${nonLarge[i].icao} ↔ ${nonLarge[j].icao}: ${d.toFixed(1)} km < ${REMOTE_RADIUS_KM}`).toBeGreaterThanOrEqual(REMOTE_RADIUS_KM);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
+74
@@ -0,0 +1,74 @@
|
|||||||
|
import { randomUUID, scryptSync, timingSafeEqual } from 'node:crypto';
|
||||||
|
import { getGameDb, persist, type GameDb } from '@/lib/db/client';
|
||||||
|
|
||||||
|
// v0.71.0 — session auth for the admin panel (and later multiplayer). Sessions are opaque
|
||||||
|
// UUIDs in a DB table; the client stores one in localStorage ('flight.session') and sends it
|
||||||
|
// as the X-Flight-Session header on every authenticated request. No JWT, no cookies: this is
|
||||||
|
// a single-origin dev tool surface, not a public auth system.
|
||||||
|
|
||||||
|
export const SESSION_HEADER = 'x-flight-session';
|
||||||
|
export const SESSION_TTL_MS = 7 * 24 * 60 * 60 * 1000; // 7 days from creation
|
||||||
|
|
||||||
|
// Fixed digest compared against when the username is unknown, so every failed login runs one
|
||||||
|
// full scrypt and the timing shape stays uniform (no user-existence oracle).
|
||||||
|
export const DUMMY_HASH_FOR_UNKNOWN_USER = '0123456789abcdef0123456789abcdef$b9813a9a95c67878bd5b2c703bce6d57416b5d7e48496dfbf603bc4c6d59137f';
|
||||||
|
|
||||||
|
export interface AuthUser {
|
||||||
|
id: string;
|
||||||
|
username: string;
|
||||||
|
admin: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify a plaintext password against a stored "salt$hex" scrypt digest (16-byte hex salt,
|
||||||
|
// 32-byte hash). Malformed digests never match.
|
||||||
|
export function verifyPassword(password: string, storedHash: string): boolean {
|
||||||
|
const [saltHex, hashHex] = storedHash.split('$');
|
||||||
|
if (!saltHex || !hashHex || hashHex.length !== 64) return false;
|
||||||
|
const computed = scryptSync(password, saltHex, 32).toString('hex');
|
||||||
|
try {
|
||||||
|
return timingSafeEqual(Buffer.from(computed, 'hex'), Buffer.from(hashHex, 'hex'));
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mint a session row for the user and lazily prune expired sessions. Persists so a restart
|
||||||
|
// doesn't silently log everyone out mid-session.
|
||||||
|
export async function createSession(inst: GameDb, userId: string): Promise<string> {
|
||||||
|
const id = randomUUID();
|
||||||
|
inst.raw.run('DELETE FROM sessions WHERE expires_at < ?', [Date.now()]);
|
||||||
|
inst.raw.run('INSERT INTO sessions (id, user_id, expires_at) VALUES (?, ?, ?)', [
|
||||||
|
id,
|
||||||
|
userId,
|
||||||
|
Date.now() + SESSION_TTL_MS,
|
||||||
|
]);
|
||||||
|
await persist(inst);
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Resolve the X-Flight-Session header to a live (non-expired) user, or null.
|
||||||
|
export async function currentUser(req: Request): Promise<AuthUser | null> {
|
||||||
|
const sessionId = req.headers.get(SESSION_HEADER);
|
||||||
|
if (!sessionId) return null;
|
||||||
|
const inst = await getGameDb();
|
||||||
|
const res = inst.raw.exec(
|
||||||
|
'SELECT u.id, u.username, u.admin FROM sessions s JOIN users u ON u.id = s.user_id WHERE s.id = ? AND s.expires_at > ?',
|
||||||
|
[sessionId, Date.now()],
|
||||||
|
);
|
||||||
|
const row = res[0]?.values?.[0];
|
||||||
|
if (!row) return null;
|
||||||
|
return { id: String(row[0]), username: String(row[1]), admin: Number(row[2]) === 1 };
|
||||||
|
}
|
||||||
|
|
||||||
|
export type AdminGuard = { ok: true; inst: GameDb; user: AuthUser } | { ok: false; response: Response };
|
||||||
|
|
||||||
|
// Guard for every /api/admin/* route — runs BEFORE any user input is touched.
|
||||||
|
// No/expired session → 401, valid non-admin session → 403.
|
||||||
|
export async function requireAdmin(req: Request): Promise<AdminGuard> {
|
||||||
|
const user = await currentUser(req);
|
||||||
|
if (!user) return { ok: false, response: Response.json({ error: 'authentication required' }, { status: 401 }) };
|
||||||
|
if (!user.admin) {
|
||||||
|
return { ok: false, response: Response.json({ error: 'admin access required' }, { status: 403 }) };
|
||||||
|
}
|
||||||
|
return { ok: true, inst: await getGameDb(), user };
|
||||||
|
}
|
||||||
+117
-11
@@ -4,10 +4,14 @@ import path from 'node:path';
|
|||||||
import initSqlJs from 'sql.js';
|
import initSqlJs from 'sql.js';
|
||||||
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
||||||
import { WORLD_TIME_SCALE } from '@/lib/worldClock';
|
import { WORLD_TIME_SCALE } from '@/lib/worldClock';
|
||||||
import { STARTING_CLOCK_MS } from '@/lib/game/seed';
|
import { STARTING_CASH, STARTING_CLOCK_MS, STARTING_REPUTATION } from '@/lib/game/seed';
|
||||||
import { openGameDb, persist } from './client';
|
import { openGameDb, persist } from './client';
|
||||||
|
import { getLocalPlayer, updateLocalPlayerEconomy } from './localPlayer';
|
||||||
import * as schema from './schema';
|
import * as schema from './schema';
|
||||||
|
|
||||||
|
// v1.0.0 (ISS-105): the local player row every fresh/migrated world must carry.
|
||||||
|
const LOCAL_PLAYER_ROW = { id: 'local', provider: 'local', username: 'kamilkrzywda' };
|
||||||
|
|
||||||
// The v0.6.0 DDL — used to build a "legacy" DB file for the migration test.
|
// The v0.6.0 DDL — used to build a "legacy" DB file for the migration test.
|
||||||
const LEGACY_DDL = `
|
const LEGACY_DDL = `
|
||||||
CREATE TABLE planes (
|
CREATE TABLE planes (
|
||||||
@@ -110,8 +114,13 @@ describe('openGameDb', () => {
|
|||||||
expect(packages.length).toBeGreaterThanOrEqual(8);
|
expect(packages.length).toBeGreaterThanOrEqual(8);
|
||||||
expect(packages.every((p) => p.status === 'open')).toBe(true);
|
expect(packages.every((p) => p.status === 'open')).toBe(true);
|
||||||
|
|
||||||
const account = (await inst.db.select().from(schema.account))[0];
|
// v1.0.0 (ISS-105): the singleton economy is now a seeded local player row…
|
||||||
expect(account?.cash).toBeGreaterThan(0);
|
expect(await getLocalPlayer(inst)).toEqual({ ...LOCAL_PLAYER_ROW, cash: STARTING_CASH, reputation: STARTING_REPUTATION });
|
||||||
|
// …and fresh DBs never create an `account` table.
|
||||||
|
const tables = new Set(
|
||||||
|
inst.raw.exec("SELECT name FROM sqlite_master WHERE type='table'")[0].values.map((r) => String(r[0])),
|
||||||
|
);
|
||||||
|
expect(tables.has('account')).toBe(false);
|
||||||
const sim = (await inst.db.select().from(schema.simState))[0];
|
const sim = (await inst.db.select().from(schema.simState))[0];
|
||||||
// ISS-117: fresh worlds start at the year-2000 game clock with the fixed world rate.
|
// ISS-117: fresh worlds start at the year-2000 game clock with the fixed world rate.
|
||||||
expect(sim?.clockMs).toBe(STARTING_CLOCK_MS);
|
expect(sim?.clockMs).toBe(STARTING_CLOCK_MS);
|
||||||
@@ -126,25 +135,25 @@ describe('openGameDb', () => {
|
|||||||
const file = path.join(dir, 'reopen.db');
|
const file = path.join(dir, 'reopen.db');
|
||||||
const first = await openGameDb(file);
|
const first = await openGameDb(file);
|
||||||
const packages1 = (await first.db.select().from(schema.packages)).map((p) => p.id).sort();
|
const packages1 = (await first.db.select().from(schema.packages)).map((p) => p.id).sort();
|
||||||
const account1 = (await first.db.select().from(schema.account))[0];
|
const player1 = await getLocalPlayer(first);
|
||||||
|
|
||||||
// Simulate a process restart: brand-new instance over the same file.
|
// Simulate a process restart: brand-new instance over the same file.
|
||||||
const second = await openGameDb(file);
|
const second = await openGameDb(file);
|
||||||
const packages2 = (await second.db.select().from(schema.packages)).map((p) => p.id).sort();
|
const packages2 = (await second.db.select().from(schema.packages)).map((p) => p.id).sort();
|
||||||
expect(packages2).toEqual(packages1);
|
expect(packages2).toEqual(packages1);
|
||||||
expect((await second.db.select().from(schema.account))[0]).toEqual(account1);
|
expect(await getLocalPlayer(second)).toEqual(player1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('persist() durably saves writes made after open', async () => {
|
it('persist() durably saves writes made after open', async () => {
|
||||||
const file = path.join(dir, 'write.db');
|
const file = path.join(dir, 'write.db');
|
||||||
const inst = await openGameDb(file);
|
const inst = await openGameDb(file);
|
||||||
|
|
||||||
await inst.db.update(schema.account).set({ cash: 12345 });
|
await updateLocalPlayerEconomy(inst, { cash: 12345 });
|
||||||
await persist(inst);
|
await persist(inst);
|
||||||
|
|
||||||
// A fresh instance over the same file sees the update.
|
// A fresh instance over the same file sees the update.
|
||||||
const reloaded = await openGameDb(file);
|
const reloaded = await openGameDb(file);
|
||||||
expect((await reloaded.db.select().from(schema.account))[0]?.cash).toBe(12345);
|
expect((await getLocalPlayer(reloaded)).cash).toBe(12345);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('migrates a pre-v0.7.0 database: adds new columns and fixes last_real_tick_ms', async () => {
|
it('migrates a pre-v0.7.0 database: adds new columns and fixes last_real_tick_ms', async () => {
|
||||||
@@ -161,8 +170,8 @@ describe('openGameDb', () => {
|
|||||||
|
|
||||||
const inst = await openGameDb(file);
|
const inst = await openGameDb(file);
|
||||||
|
|
||||||
// Not re-seeded (account row exists)…
|
// Not re-seeded (the legacy account row was migrated into the local player)…
|
||||||
expect((await inst.db.select().from(schema.account))[0]?.cash).toBe(20000);
|
expect((await getLocalPlayer(inst)).cash).toBe(20000);
|
||||||
// …but the new columns exist and are usable…
|
// …but the new columns exist and are usable…
|
||||||
const plane = (await inst.db.select().from(schema.planes))[0];
|
const plane = (await inst.db.select().from(schema.planes))[0];
|
||||||
expect(plane?.departureSimTime ?? null).toBeNull();
|
expect(plane?.departureSimTime ?? null).toBeNull();
|
||||||
@@ -194,8 +203,8 @@ describe('openGameDb', () => {
|
|||||||
|
|
||||||
const inst = await openGameDb(file);
|
const inst = await openGameDb(file);
|
||||||
|
|
||||||
// Wallet + sim clock survive byte-identical…
|
// Wallet (migrated into the local player) + sim clock survive byte-identical…
|
||||||
expect((await inst.db.select().from(schema.account))[0]).toEqual({ cash: 54020.34, reputation: 62.57 });
|
expect(await getLocalPlayer(inst)).toEqual({ ...LOCAL_PLAYER_ROW, cash: 54020.34, reputation: 62.57 });
|
||||||
expect((await inst.db.select().from(schema.simState))[0]?.clockMs).toBe(1_789_706_016_605);
|
expect((await inst.db.select().from(schema.simState))[0]?.clockMs).toBe(1_789_706_016_605);
|
||||||
|
|
||||||
// …the in-flight plane is reset to GROUNDED at its locationIcao (it "lands" back where it took off)…
|
// …the in-flight plane is reset to GROUNDED at its locationIcao (it "lands" back where it took off)…
|
||||||
@@ -222,6 +231,77 @@ describe('openGameDb', () => {
|
|||||||
expect(cols.has('dest_icao')).toBe(true);
|
expect(cols.has('dest_icao')).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// v0.71.0: the seeded admin row — hash-only, idempotent across every open().
|
||||||
|
const ADMIN_HASH = '339149a14282ff3a2ed94534f9722aa4$abaf94cf073c5aafc892b4a39dce97aaf53ab6f7c662a588815bda1bc1771caf';
|
||||||
|
// The v0.71.0 digest — computed with different scrypt parameters than verifyPassword(),
|
||||||
|
// so it never verified; production DBs seeded by that version carry exactly this value.
|
||||||
|
const LEGACY_HASH = '8dbed630b49a15073e8be571367c1858$0e5207dae2e3c813a7172a5f610fd47a90e8ff17513180ab1e0a7779c3766ef0';
|
||||||
|
|
||||||
|
it('seeds exactly one admin user on first open and never duplicates on reopen', async () => {
|
||||||
|
const file = path.join(dir, 'admin-seed.db');
|
||||||
|
const inst = await openGameDb(file);
|
||||||
|
|
||||||
|
let rows = inst.raw.exec("SELECT id, username, password_hash, admin FROM users WHERE username = 'kamilkrzywda'");
|
||||||
|
expect(rows[0].values).toHaveLength(1);
|
||||||
|
expect(rows[0].values[0]).toEqual(['admin-kamilkrzywda', 'kamilkrzywda', ADMIN_HASH, 1]);
|
||||||
|
|
||||||
|
// Simulate a process restart: brand-new instance over the same file.
|
||||||
|
const second = await openGameDb(file);
|
||||||
|
rows = second.raw.exec('SELECT COUNT(*) FROM users');
|
||||||
|
expect(Number(rows[0].values[0][0])).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('seeds the admin into a legacy DB that predates the users table', async () => {
|
||||||
|
// A pre-v0.71.0 file: no users/sessions tables at all (the v0.6.0 DDL has none).
|
||||||
|
const SQL = await initSqlJs();
|
||||||
|
const raw = new SQL.Database();
|
||||||
|
raw.exec(LEGACY_DDL);
|
||||||
|
raw.exec(`INSERT INTO planes VALUES ('plane-starter', 'atr72', 'available', 6300, 6300, 'EDDF', NULL, 50.03, 8.57)`);
|
||||||
|
raw.exec(`INSERT INTO account VALUES (20000, 10)`);
|
||||||
|
raw.exec('INSERT INTO sim_state VALUES (1750000000000, 50, 0)');
|
||||||
|
const file = path.join(dir, 'legacy-admin.db');
|
||||||
|
await fs.writeFile(file, Buffer.from(raw.export()));
|
||||||
|
|
||||||
|
const inst = await openGameDb(file);
|
||||||
|
const rows = inst.raw.exec("SELECT id, username, admin FROM users WHERE username = 'kamilkrzywda'");
|
||||||
|
expect(rows[0].values).toHaveLength(1);
|
||||||
|
expect(rows[0].values[0]).toEqual(['admin-kamilkrzywda', 'kamilkrzywda', 1]);
|
||||||
|
// The game world is untouched by the seed (its account row migrated to the local player).
|
||||||
|
expect((await getLocalPlayer(inst)).cash).toBe(20000);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('rotates a v0.71.0 legacy admin digest on open (idempotent)', async () => {
|
||||||
|
// A file exactly as v0.71.0 left production: an admin row carrying the old, incompatible digest.
|
||||||
|
const SQL = await initSqlJs();
|
||||||
|
const raw = new SQL.Database();
|
||||||
|
raw.exec(`CREATE TABLE users (
|
||||||
|
id TEXT PRIMARY KEY NOT NULL,
|
||||||
|
username TEXT NOT NULL UNIQUE,
|
||||||
|
password_hash TEXT NOT NULL,
|
||||||
|
admin INTEGER NOT NULL DEFAULT 0,
|
||||||
|
created_at INTEGER NOT NULL
|
||||||
|
)`);
|
||||||
|
raw.run('INSERT INTO users VALUES (?, ?, ?, 1, ?)', [
|
||||||
|
'admin-kamilkrzywda',
|
||||||
|
'kamilkrzywda',
|
||||||
|
LEGACY_HASH,
|
||||||
|
Date.now(),
|
||||||
|
]);
|
||||||
|
const file = path.join(dir, 'admin-rotate.db');
|
||||||
|
await fs.writeFile(file, Buffer.from(raw.export()));
|
||||||
|
|
||||||
|
// First open heals the row to the current digest…
|
||||||
|
const first = await openGameDb(file);
|
||||||
|
let rows = first.raw.exec("SELECT password_hash FROM users WHERE id = 'admin-kamilkrzywda'");
|
||||||
|
expect(rows[0].values).toHaveLength(1);
|
||||||
|
expect(rows[0].values[0][0]).toBe(ADMIN_HASH);
|
||||||
|
|
||||||
|
// …and a second open is a no-op (idempotent rotation).
|
||||||
|
const second = await openGameDb(file);
|
||||||
|
rows = second.raw.exec("SELECT password_hash FROM users WHERE id = 'admin-kamilkrzywda'");
|
||||||
|
expect(rows[0].values[0][0]).toBe(ADMIN_HASH);
|
||||||
|
});
|
||||||
|
|
||||||
it('does not re-run the v0.12 plane reset on later opens (migration is one-shot)', async () => {
|
it('does not re-run the v0.12 plane reset on later opens (migration is one-shot)', async () => {
|
||||||
const file = path.join(dir, 'pre-v12-reopen.db');
|
const file = path.join(dir, 'pre-v12-reopen.db');
|
||||||
const SQL = await initSqlJs();
|
const SQL = await initSqlJs();
|
||||||
@@ -244,4 +324,30 @@ describe('openGameDb', () => {
|
|||||||
expect(plane.status).toBe('flying');
|
expect(plane.status).toBe('flying');
|
||||||
expect(plane.destIcao).toBe('LEMD');
|
expect(plane.destIcao).toBe('LEMD');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('migrates a pre-v1.0.0 database: copies the singleton account into the local player and drops it', async () => {
|
||||||
|
// Minimal legacy file — just an `account` table; open() creates everything else from DDL.
|
||||||
|
const SQL = await initSqlJs();
|
||||||
|
const raw = new SQL.Database();
|
||||||
|
raw.exec(`CREATE TABLE account (cash REAL NOT NULL, reputation REAL NOT NULL)`);
|
||||||
|
raw.exec(`INSERT INTO account VALUES (77123.45, 88.5)`);
|
||||||
|
const file = path.join(dir, 'pre-v1.db');
|
||||||
|
await fs.writeFile(file, Buffer.from(raw.export()));
|
||||||
|
|
||||||
|
const inst = await openGameDb(file);
|
||||||
|
expect(await getLocalPlayer(inst)).toEqual({ ...LOCAL_PLAYER_ROW, cash: 77123.45, reputation: 88.5 });
|
||||||
|
let tables = new Set(
|
||||||
|
inst.raw.exec("SELECT name FROM sqlite_master WHERE type='table'")[0].values.map((r) => String(r[0])),
|
||||||
|
);
|
||||||
|
expect(tables.has('account')).toBe(false);
|
||||||
|
|
||||||
|
// Second open is a no-op (idempotent): the row survives unchanged, still exactly one player.
|
||||||
|
const second = await openGameDb(file);
|
||||||
|
expect(await getLocalPlayer(second)).toEqual({ ...LOCAL_PLAYER_ROW, cash: 77123.45, reputation: 88.5 });
|
||||||
|
tables = new Set(
|
||||||
|
second.raw.exec("SELECT name FROM sqlite_master WHERE type='table'")[0].values.map((r) => String(r[0])),
|
||||||
|
);
|
||||||
|
expect(tables.has('account')).toBe(false);
|
||||||
|
expect(Number(second.raw.exec('SELECT COUNT(*) FROM players')[0].values[0][0])).toBe(1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
+68
-5
@@ -5,6 +5,7 @@ import { drizzle, type SQLJsDatabase } from 'drizzle-orm/sql-js';
|
|||||||
import initSqlJs, { type Database as RawSqlJsDatabase } from 'sql.js';
|
import initSqlJs, { type Database as RawSqlJsDatabase } from 'sql.js';
|
||||||
import { loadAirportsGeoJson } from '@/lib/airports';
|
import { loadAirportsGeoJson } from '@/lib/airports';
|
||||||
import { buildSeed, mulberry32 } from '@/lib/game/seed';
|
import { buildSeed, mulberry32 } from '@/lib/game/seed';
|
||||||
|
import { LOCAL_PLAYER } from './localPlayer';
|
||||||
import * as schema from './schema';
|
import * as schema from './schema';
|
||||||
|
|
||||||
// SQLite via sql.js (WASM) — no native compilation, so it builds and runs in the
|
// SQLite via sql.js (WASM) — no native compilation, so it builds and runs in the
|
||||||
@@ -51,7 +52,12 @@ CREATE TABLE IF NOT EXISTS packages (
|
|||||||
created_real_ms INTEGER NOT NULL DEFAULT 0,
|
created_real_ms INTEGER NOT NULL DEFAULT 0,
|
||||||
slot_free_at_real_ms INTEGER
|
slot_free_at_real_ms INTEGER
|
||||||
);
|
);
|
||||||
CREATE TABLE IF NOT EXISTS account (
|
-- v1.0.0 (ISS-105): per-player economy — replaces the singleton account table; the local
|
||||||
|
-- single-player row is seeded by seedEmpty() or migrated from account in open().
|
||||||
|
CREATE TABLE IF NOT EXISTS players (
|
||||||
|
id TEXT PRIMARY KEY NOT NULL,
|
||||||
|
provider TEXT NOT NULL,
|
||||||
|
username TEXT NOT NULL,
|
||||||
cash REAL NOT NULL,
|
cash REAL NOT NULL,
|
||||||
reputation REAL NOT NULL
|
reputation REAL NOT NULL
|
||||||
);
|
);
|
||||||
@@ -62,8 +68,46 @@ CREATE TABLE IF NOT EXISTS sim_state (
|
|||||||
last_real_tick_ms INTEGER NOT NULL DEFAULT 0,
|
last_real_tick_ms INTEGER NOT NULL DEFAULT 0,
|
||||||
last_selected_time_scale REAL NOT NULL DEFAULT 1
|
last_selected_time_scale REAL NOT NULL DEFAULT 1
|
||||||
);
|
);
|
||||||
|
-- v0.71.0: accounts + login sessions for the admin panel (and later multiplayer auth).
|
||||||
|
CREATE TABLE IF NOT EXISTS users (
|
||||||
|
id TEXT PRIMARY KEY NOT NULL,
|
||||||
|
username TEXT NOT NULL UNIQUE,
|
||||||
|
password_hash TEXT NOT NULL,
|
||||||
|
admin INTEGER NOT NULL DEFAULT 0,
|
||||||
|
created_at INTEGER NOT NULL
|
||||||
|
);
|
||||||
|
CREATE TABLE IF NOT EXISTS sessions (
|
||||||
|
id TEXT PRIMARY KEY NOT NULL,
|
||||||
|
user_id TEXT NOT NULL,
|
||||||
|
expires_at INTEGER NOT NULL
|
||||||
|
);
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
// v0.71.0: the seeded admin's scrypt hash (salt$hex). The plaintext exists only in the
|
||||||
|
// operator's head — never in code, tests or comments; login verifies against this string.
|
||||||
|
// v0.72.0: recomputed with exactly the same call as verifyPassword() — salt passed as a
|
||||||
|
// plain string, scryptSync(pw, saltHex, 32) — because the v0.71.0 digest used different
|
||||||
|
// parameters and real logins failed with 401.
|
||||||
|
const ADMIN_SEED_HASH = '339149a14282ff3a2ed94534f9722aa4$abaf94cf073c5aafc892b4a39dce97aaf53ab6f7c662a588815bda1bc1771caf';
|
||||||
|
|
||||||
|
// v0.71.0: idempotent admin seed — runs on every open(), no-ops when the row exists, so
|
||||||
|
// pre-existing production DBs gain exactly one admin row and never a duplicate.
|
||||||
|
function seedAdminUser(raw: RawSqlJsDatabase): void {
|
||||||
|
raw.run(
|
||||||
|
`INSERT INTO users (id, username, password_hash, admin, created_at)
|
||||||
|
SELECT 'admin-kamilkrzywda', 'kamilkrzywda', ?, 1, ?
|
||||||
|
WHERE NOT EXISTS (SELECT 1 FROM users WHERE username = 'kamilkrzywda')`,
|
||||||
|
[ADMIN_SEED_HASH, Date.now()],
|
||||||
|
);
|
||||||
|
// v0.72.0: v0.71.0 seeded an incompatible digest into production DBs and the INSERT above
|
||||||
|
// can't overwrite them (WHERE NOT EXISTS), so rotate any legacy row to the current digest
|
||||||
|
// at boot — a no-op once healed, durable on the next persist().
|
||||||
|
raw.run(
|
||||||
|
`UPDATE users SET password_hash = ? WHERE id = 'admin-kamilkrzywda' AND password_hash != ?`,
|
||||||
|
[ADMIN_SEED_HASH, ADMIN_SEED_HASH],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// v0.7.0: DBs created by earlier versions lack the new columns; CREATE TABLE IF
|
// v0.7.0: DBs created by earlier versions lack the new columns; CREATE TABLE IF
|
||||||
// NOT EXISTS won't add them, so ALTER (guarded by PRAGMA table_info). Fresh DBs
|
// NOT EXISTS won't add them, so ALTER (guarded by PRAGMA table_info). Fresh DBs
|
||||||
// already have everything from DDL above and this is a no-op for them.
|
// already have everything from DDL above and this is a no-op for them.
|
||||||
@@ -144,6 +188,17 @@ function migrateContractsToPackages(raw: RawSqlJsDatabase): void {
|
|||||||
raw.exec('DROP TABLE contracts');
|
raw.exec('DROP TABLE contracts');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// v1.0.0 (ISS-105) one-time migration: singleton `account` row → seeded local player, then drop
|
||||||
|
// the table. Detected by sqlite_master like migrateContractsToPackages — fresh DBs never have
|
||||||
|
// `account`, so this runs exactly once per legacy file and is a no-op on later opens.
|
||||||
|
function migrateAccountToPlayers(raw: RawSqlJsDatabase): void {
|
||||||
|
raw.run(
|
||||||
|
'INSERT INTO players (id, provider, username, cash, reputation) SELECT ?, ?, ?, cash, reputation FROM account',
|
||||||
|
[LOCAL_PLAYER.id, LOCAL_PLAYER.provider, LOCAL_PLAYER.username],
|
||||||
|
);
|
||||||
|
raw.exec('DROP TABLE account');
|
||||||
|
}
|
||||||
|
|
||||||
// FLIGHT_DB_PATH override exists so unit tests can point at a temp file instead
|
// FLIGHT_DB_PATH override exists so unit tests can point at a temp file instead
|
||||||
// of the real ./db/flight.db.
|
// of the real ./db/flight.db.
|
||||||
export function defaultDbPath(): string {
|
export function defaultDbPath(): string {
|
||||||
@@ -161,6 +216,7 @@ async function open(file: string): Promise<GameDb> {
|
|||||||
const raw = bytes ? new SQL.Database(new Uint8Array(bytes)) : new SQL.Database();
|
const raw = bytes ? new SQL.Database(new Uint8Array(bytes)) : new SQL.Database();
|
||||||
raw.exec(DDL); // no-op for tables that already exist in an older file
|
raw.exec(DDL); // no-op for tables that already exist in an older file
|
||||||
migrateColumns(raw);
|
migrateColumns(raw);
|
||||||
|
seedAdminUser(raw); // v0.71.0 — idempotent; safe on pre-existing production DBs
|
||||||
|
|
||||||
// v0.12.0: run BEFORE the seed check — a pre-v0.12.0 file has account rows, so
|
// v0.12.0: run BEFORE the seed check — a pre-v0.12.0 file has account rows, so
|
||||||
// without this it would keep the dead contracts table forever.
|
// without this it would keep the dead contracts table forever.
|
||||||
@@ -170,12 +226,18 @@ async function open(file: string): Promise<GameDb> {
|
|||||||
if (tables.has('contracts')) {
|
if (tables.has('contracts')) {
|
||||||
migrateContractsToPackages(raw);
|
migrateContractsToPackages(raw);
|
||||||
}
|
}
|
||||||
|
// v1.0.0 (ISS-105): legacy files still carry the singleton `account` table — copy its row into a
|
||||||
|
// seeded local player and drop it. The players-empty guard makes this idempotent even if a file
|
||||||
|
// somehow had both tables; fresh DBs never have `account`, so this runs exactly once per file.
|
||||||
|
const playerCount = Number(raw.exec('SELECT COUNT(*) FROM players')[0].values[0]?.[0] ?? 0);
|
||||||
|
if (tables.has('account') && playerCount === 0) {
|
||||||
|
migrateAccountToPlayers(raw);
|
||||||
|
}
|
||||||
|
|
||||||
const instance: GameDb = { db: drizzle(raw, { schema }), raw, file };
|
const instance: GameDb = { db: drizzle(raw, { schema }), raw, file };
|
||||||
|
|
||||||
// First-run seed: only when the DB is empty (no account row yet).
|
// First-run seed: only when the DB is empty (no player row yet).
|
||||||
const res = raw.exec('SELECT COUNT(*) FROM account');
|
if (playerCount === 0 && !tables.has('account')) {
|
||||||
if (Number(res[0]?.values?.[0]?.[0] ?? 0) === 0) {
|
|
||||||
console.warn(`flight db: no existing world at ${file} — seeding a fresh one`);
|
console.warn(`flight db: no existing world at ${file} — seeding a fresh one`);
|
||||||
await seedEmpty(instance);
|
await seedEmpty(instance);
|
||||||
}
|
}
|
||||||
@@ -207,7 +269,8 @@ async function seedEmpty(instance: GameDb): Promise<void> {
|
|||||||
const { queue, ...planeCols } = data.plane;
|
const { queue, ...planeCols } = data.plane;
|
||||||
await instance.db.insert(schema.planes).values({ ...planeCols, queue: JSON.stringify(queue ?? []) });
|
await instance.db.insert(schema.planes).values({ ...planeCols, queue: JSON.stringify(queue ?? []) });
|
||||||
await instance.db.insert(schema.packages).values(data.packages);
|
await instance.db.insert(schema.packages).values(data.packages);
|
||||||
await instance.db.insert(schema.account).values(data.account);
|
// v1.0.0 (ISS-105): the singleton economy now lives in a seeded local player row.
|
||||||
|
await instance.db.insert(schema.players).values({ ...LOCAL_PLAYER, cash: data.account.cash, reputation: data.account.reputation });
|
||||||
await instance.db.insert(schema.simState).values(data.simState);
|
await instance.db.insert(schema.simState).values(data.simState);
|
||||||
await persist(instance);
|
await persist(instance);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
import { eq } from 'drizzle-orm';
|
||||||
|
import type { GameDb } from './client';
|
||||||
|
import * as schema from './schema';
|
||||||
|
|
||||||
|
// v1.0.0 (ISS-105): TEMPORARY single-player economy access — resolves the local player row so all
|
||||||
|
// pre-multiplayer code keeps working while `account` is replaced by `players`. A later step
|
||||||
|
// parameterizes these by playerId for real multiplayer; until then every read/write of the
|
||||||
|
// singleton economy goes through this file and nowhere else.
|
||||||
|
|
||||||
|
export const LOCAL_PLAYER = { id: 'local', provider: 'local', username: 'kamilkrzywda' } as const;
|
||||||
|
|
||||||
|
export async function getLocalPlayer(inst: GameDb): Promise<schema.PlayerRow> {
|
||||||
|
const [row] = await inst.db.select().from(schema.players).where(eq(schema.players.id, LOCAL_PLAYER.id));
|
||||||
|
if (!row) throw new Error('local player row missing');
|
||||||
|
return row;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function updateLocalPlayerEconomy(
|
||||||
|
inst: GameDb,
|
||||||
|
patch: { cash?: number; reputation?: number },
|
||||||
|
): Promise<void> {
|
||||||
|
await inst.db.update(schema.players).set(patch).where(eq(schema.players.id, LOCAL_PLAYER.id));
|
||||||
|
}
|
||||||
+30
-5
@@ -53,21 +53,26 @@ export const packages = sqliteTable('packages', {
|
|||||||
deadlineSimTime: integer('deadline_sim_time').notNull(),
|
deadlineSimTime: integer('deadline_sim_time').notNull(),
|
||||||
// 'expired' = an open OR loaded package whose deadline passed on a tick. Loaded
|
// 'expired' = an open OR loaded package whose deadline passed on a tick. Loaded
|
||||||
// expired packages keep occupying their slot, deliver no reward, and abandon free.
|
// expired packages keep occupying their slot, deliver no reward, and abandon free.
|
||||||
// 'ignored' (v0.29.0, ISS-047 part B) = a dismissed open job — terminal, leaves the market.
|
status: text('status', { enum: ['open', 'loaded', 'delivered', 'expired', 'abandoned'] }).notNull(),
|
||||||
status: text('status', { enum: ['open', 'loaded', 'delivered', 'expired', 'abandoned', 'ignored'] }).notNull(),
|
|
||||||
planeId: text('plane_id'),
|
planeId: text('plane_id'),
|
||||||
createdSimTime: integer('created_sim_time').notNull(),
|
createdSimTime: integer('created_sim_time').notNull(),
|
||||||
// Real-time (Date.now()) epoch ms of creation (v0.65.0) — open jobs live on the WALL clock, not the sim
|
// Real-time (Date.now()) epoch ms of creation (v0.65.0) — open jobs live on the WALL clock, not the sim
|
||||||
// clock: they expire JOB_LIFETIME_MS after this regardless of time scale or fleet state. Legacy rows
|
// clock: they expire JOB_LIFETIME_MS after this regardless of time scale or fleet state. Legacy rows
|
||||||
// backfill to seed time so they get a fresh full lifetime instead of expiring on the first tick.
|
// backfill to seed time so they get a fresh full lifetime instead of expiring on the first tick.
|
||||||
createdRealMs: integer('created_real_ms').notNull().default(0),
|
createdRealMs: integer('created_real_ms').notNull().default(0),
|
||||||
// Real-time epoch ms when this (origin, band) slot was last taken — loaded or ignored (v0.65.0). The pool
|
// Real-time epoch ms when this (origin, band) slot was last taken — loaded (v0.65.0). The pool
|
||||||
// spawner holds that slot for the band's refill delay after; NULL = never taken / no cooldown. Expired open
|
// spawner holds that slot for the band's refill delay after; NULL = never taken / no cooldown. Expired open
|
||||||
// jobs set nothing: an untaken job's slot respawns immediately.
|
// jobs set nothing: an untaken job's slot respawns immediately.
|
||||||
slotFreeAtRealMs: integer('slot_free_at_real_ms'),
|
slotFreeAtRealMs: integer('slot_free_at_real_ms'),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const account = sqliteTable('account', {
|
// v1.0.0 (ISS-105): per-player economy — replaces the singleton `account` table. The local
|
||||||
|
// single-player row (id 'local') is seeded on first run / migrated from `account` by open();
|
||||||
|
// all pre-multiplayer code reaches it via lib/db/localPlayer.ts only.
|
||||||
|
export const players = sqliteTable('players', {
|
||||||
|
id: text('id').primaryKey().notNull(),
|
||||||
|
provider: text('provider').notNull(),
|
||||||
|
username: text('username').notNull(),
|
||||||
cash: real('cash').notNull(),
|
cash: real('cash').notNull(),
|
||||||
reputation: real('reputation').notNull(),
|
reputation: real('reputation').notNull(),
|
||||||
});
|
});
|
||||||
@@ -85,7 +90,27 @@ export const simState = sqliteTable('sim_state', {
|
|||||||
lastSelectedTimeScale: real('last_selected_time_scale').notNull().default(1),
|
lastSelectedTimeScale: real('last_selected_time_scale').notNull().default(1),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// v0.71.0: accounts + login sessions for the admin panel (and later multiplayer auth).
|
||||||
|
// The seeded admin row is inserted by lib/db/client.ts on every open() — hash-only, see there.
|
||||||
|
export const users = sqliteTable('users', {
|
||||||
|
id: text('id').primaryKey().notNull(),
|
||||||
|
username: text('username').notNull().unique(),
|
||||||
|
// scrypt digest as "salt$hex" (16-byte hex salt, 32-byte hex hash) — verified with node:crypto.
|
||||||
|
passwordHash: text('password_hash').notNull(),
|
||||||
|
admin: integer('admin', { mode: 'boolean' }).notNull().default(false),
|
||||||
|
createdAt: integer('created_at').notNull(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const sessions = sqliteTable('sessions', {
|
||||||
|
id: text('id').primaryKey().notNull(),
|
||||||
|
userId: text('user_id').notNull(),
|
||||||
|
// Real-time (Date.now()) epoch ms — 7 days from creation; expired rows are pruned lazily on login.
|
||||||
|
expiresAt: integer('expires_at').notNull(),
|
||||||
|
});
|
||||||
|
|
||||||
export type PlaneRow = typeof planes.$inferSelect;
|
export type PlaneRow = typeof planes.$inferSelect;
|
||||||
export type PackageRow = typeof packages.$inferSelect;
|
export type PackageRow = typeof packages.$inferSelect;
|
||||||
export type AccountRow = typeof account.$inferSelect;
|
export type PlayerRow = typeof players.$inferSelect;
|
||||||
export type SimStateRow = typeof simState.$inferSelect;
|
export type SimStateRow = typeof simState.$inferSelect;
|
||||||
|
export type UserRow = typeof users.$inferSelect;
|
||||||
|
export type SessionRow = typeof sessions.$inferSelect;
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ describe('diffSnapshots', () => {
|
|||||||
expect(diffSnapshots(prev, next)).toEqual([]);
|
expect(diffSnapshots(prev, next)).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns [] for the first snapshot (no baseline — no "new package" spam on page load)', () => {
|
it('returns [] for the first snapshot (no baseline to diff against)', () => {
|
||||||
const next = snapshot({ packages: [basePackage('pkg-1'), basePackage('pkg-2')] });
|
const next = snapshot({ packages: [basePackage('pkg-1'), basePackage('pkg-2')] });
|
||||||
expect(diffSnapshots(null, next)).toEqual([]);
|
expect(diffSnapshots(null, next)).toEqual([]);
|
||||||
});
|
});
|
||||||
@@ -113,14 +113,6 @@ describe('diffSnapshots', () => {
|
|||||||
expect(fromLoaded).toEqual([{ kind: 'info', message: 'Package expired: Frankfurt → Madrid–Barajas' }]);
|
expect(fromLoaded).toEqual([{ kind: 'info', message: 'Package expired: Frankfurt → Madrid–Barajas' }]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('emits a new-package event for ids only in the next snapshot', () => {
|
|
||||||
const prev = snapshot({ packages: [basePackage('pkg-1')] });
|
|
||||||
const next = snapshot({ packages: [basePackage('pkg-1'), basePackage('pkg-2')] });
|
|
||||||
expect(diffSnapshots(prev, next)).toEqual([
|
|
||||||
{ kind: 'info', message: 'New package available: Frankfurt → Madrid–Barajas' },
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('emits bought/sold events when the plane id set changes (with the model name)', () => {
|
it('emits bought/sold events when the plane id set changes (with the model name)', () => {
|
||||||
const bought = diffSnapshots(
|
const bought = diffSnapshots(
|
||||||
snapshot(),
|
snapshot(),
|
||||||
|
|||||||
+4
-9
@@ -15,8 +15,7 @@ export interface GameEvent {
|
|||||||
const planeName = (model: string): string => PLANE_TYPES[model]?.name ?? model;
|
const planeName = (model: string): string => PLANE_TYPES[model]?.name ?? model;
|
||||||
|
|
||||||
export function diffSnapshots(prev: StateSnapshot | null, next: StateSnapshot): GameEvent[] {
|
export function diffSnapshots(prev: StateSnapshot | null, next: StateSnapshot): GameEvent[] {
|
||||||
// No baseline yet (first snapshot after load) — nothing to compare against. Emitting a
|
// No baseline yet (first snapshot after load) — nothing to diff against, so no events.
|
||||||
// "new package" event for every existing row would spam the stack on page load.
|
|
||||||
if (prev === null) return [];
|
if (prev === null) return [];
|
||||||
|
|
||||||
const events: GameEvent[] = [];
|
const events: GameEvent[] = [];
|
||||||
@@ -40,16 +39,12 @@ export function diffSnapshots(prev: StateSnapshot | null, next: StateSnapshot):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Packages: delivered (loaded → delivered, reward paid out in the same tick), expired
|
// Packages: delivered (loaded → delivered, reward paid out in the same tick) and expired
|
||||||
// (open|loaded → expired), newly appeared (id only in next — terminal packages are never
|
// (open|loaded → expired). Ids that appear for the first time emit nothing.
|
||||||
// deleted, so an id appearing is always a genuinely new one).
|
|
||||||
const prevPackages = new Map(prev.packages.map((p) => [p.id, p]));
|
const prevPackages = new Map(prev.packages.map((p) => [p.id, p]));
|
||||||
for (const pkg of next.packages) {
|
for (const pkg of next.packages) {
|
||||||
const before = prevPackages.get(pkg.id);
|
const before = prevPackages.get(pkg.id);
|
||||||
if (!before) {
|
if (!before) continue;
|
||||||
events.push({ kind: 'info', message: `New package available: ${pkg.originName} → ${pkg.destName}` });
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (before.status === 'loaded' && pkg.status === 'delivered') {
|
if (before.status === 'loaded' && pkg.status === 'delivered') {
|
||||||
events.push({ kind: 'info', message: `Package delivered: +${formatCash(pkg.reward)}` });
|
events.push({ kind: 'info', message: `Package delivered: +${formatCash(pkg.reward)}` });
|
||||||
} else if ((before.status === 'open' || before.status === 'loaded') && pkg.status === 'expired') {
|
} else if ((before.status === 'open' || before.status === 'loaded') && pkg.status === 'expired') {
|
||||||
|
|||||||
+36
-66
@@ -5,6 +5,7 @@ import { eq } from 'drizzle-orm';
|
|||||||
import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest';
|
import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest';
|
||||||
import { openGameDb, type GameDb } from '@/lib/db/client';
|
import { openGameDb, type GameDb } from '@/lib/db/client';
|
||||||
import * as schema from '@/lib/db/schema';
|
import * as schema from '@/lib/db/schema';
|
||||||
|
import { getLocalPlayer, updateLocalPlayerEconomy } from '@/lib/db/localPlayer';
|
||||||
import { loadAirportsGeoJson } from '@/lib/airports';
|
import { loadAirportsGeoJson } from '@/lib/airports';
|
||||||
import { haversineKm, initialBearingDeg } from '@/lib/geo';
|
import { haversineKm, initialBearingDeg } from '@/lib/geo';
|
||||||
import { weatherFor } from '@/lib/weather';
|
import { weatherFor } from '@/lib/weather';
|
||||||
@@ -28,7 +29,6 @@ import {
|
|||||||
cancelQueuedLeg,
|
cancelQueuedLeg,
|
||||||
flyPlane,
|
flyPlane,
|
||||||
GameActionError,
|
GameActionError,
|
||||||
ignorePackage,
|
|
||||||
loadPackage,
|
loadPackage,
|
||||||
queueLeg,
|
queueLeg,
|
||||||
repairPlane,
|
repairPlane,
|
||||||
@@ -205,14 +205,14 @@ describe('flyPlane', () => {
|
|||||||
const inst = await freshDb('fly-broken.db'); // EDDF → LEMD
|
const inst = await freshDb('fly-broken.db'); // EDDF → LEMD
|
||||||
const fuelBefore = PLANE_TYPES.atr72.maxFuel; // seeded full tank
|
const fuelBefore = PLANE_TYPES.atr72.maxFuel; // seeded full tank
|
||||||
await inst.db.update(schema.planes).set({ health: 0 }).where(eq(schema.planes.id, 'plane-starter'));
|
await inst.db.update(schema.planes).set({ health: 0 }).where(eq(schema.planes.id, 'plane-starter'));
|
||||||
const cashBefore = (await inst.db.select().from(schema.account))[0].cash;
|
const cashBefore = (await getLocalPlayer(inst)).cash;
|
||||||
|
|
||||||
await expectActionError(flyPlane(inst, 'plane-starter', 'LEMD'), 409, /broken \(health 0\)/);
|
await expectActionError(flyPlane(inst, 'plane-starter', 'LEMD'), 409, /broken \(health 0\)/);
|
||||||
|
|
||||||
const plane = (await inst.db.select().from(schema.planes))[0];
|
const plane = (await inst.db.select().from(schema.planes))[0];
|
||||||
expect(plane.status).toBe('available'); // still grounded…
|
expect(plane.status).toBe('available'); // still grounded…
|
||||||
expect(plane.fuel).toBe(fuelBefore); // …no auto-refuel ran — the tank is untouched…
|
expect(plane.fuel).toBe(fuelBefore); // …no auto-refuel ran — the tank is untouched…
|
||||||
expect((await inst.db.select().from(schema.account))[0].cash).toBe(cashBefore); // …and no cash left the account
|
expect((await getLocalPlayer(inst)).cash).toBe(cashBefore); // …and no cash left the account
|
||||||
});
|
});
|
||||||
|
|
||||||
it('still flies a worn-but-not-broken plane (health > 0) with plain burn', async () => {
|
it('still flies a worn-but-not-broken plane (health > 0) with plain burn', async () => {
|
||||||
@@ -250,8 +250,8 @@ describe('flyPlane', () => {
|
|||||||
const startFuel = Math.round(required / 2); // partial tank below the requirement
|
const startFuel = Math.round(required / 2); // partial tank below the requirement
|
||||||
await inst.db.update(schema.planes).set({ fuel: startFuel }).where(eq(schema.planes.id, 'plane-starter'));
|
await inst.db.update(schema.planes).set({ fuel: startFuel }).where(eq(schema.planes.id, 'plane-starter'));
|
||||||
// Elevated rep → non-zero discount rate; expectations computed with the SAME helpers flyPlane uses.
|
// Elevated rep → non-zero discount rate; expectations computed with the SAME helpers flyPlane uses.
|
||||||
await inst.db.update(schema.account).set({ reputation: 30 });
|
await updateLocalPlayerEconomy(inst, { reputation: 30 });
|
||||||
const cashBefore = (await inst.db.select().from(schema.account))[0].cash;
|
const cashBefore = (await getLocalPlayer(inst)).cash;
|
||||||
|
|
||||||
await flyPlane(inst, 'plane-starter', 'LEMD');
|
await flyPlane(inst, 'plane-starter', 'LEMD');
|
||||||
|
|
||||||
@@ -264,22 +264,22 @@ describe('flyPlane', () => {
|
|||||||
const plane = (await inst.db.select().from(schema.planes))[0];
|
const plane = (await inst.db.select().from(schema.planes))[0];
|
||||||
expect(plane.status).toBe('flying');
|
expect(plane.status).toBe('flying');
|
||||||
expect(plane.fuel).toBeCloseTo(target, 6); // topped up to exactly the 150% target…
|
expect(plane.fuel).toBeCloseTo(target, 6); // topped up to exactly the 150% target…
|
||||||
const account = (await inst.db.select().from(schema.account))[0];
|
const player = await getLocalPlayer(inst);
|
||||||
expect(account.cash).toBeCloseTo(cashBefore - expectedCost, 6); // …at exactly the rep-discounted cost
|
expect(player.cash).toBeCloseTo(cashBefore - expectedCost, 6); // …at exactly the rep-discounted cost
|
||||||
});
|
});
|
||||||
|
|
||||||
it('is a free no-op when the tank already covers the 150% target (cash unchanged)', async () => {
|
it('is a free no-op when the tank already covers the 150% target (cash unchanged)', async () => {
|
||||||
const inst = await freshDb('fly-autorefuel-full.db'); // seeded starter is full at EDDF
|
const inst = await freshDb('fly-autorefuel-full.db'); // seeded starter is full at EDDF
|
||||||
const required = await adjustedRequiredForHubToLemd();
|
const required = await adjustedRequiredForHubToLemd();
|
||||||
expect(required * 1.5).toBeLessThan(PLANE_TYPES.atr72.maxFuel); // sanity: the target stays below a full tank
|
expect(required * 1.5).toBeLessThan(PLANE_TYPES.atr72.maxFuel); // sanity: the target stays below a full tank
|
||||||
const cashBefore = (await inst.db.select().from(schema.account))[0].cash;
|
const cashBefore = (await getLocalPlayer(inst)).cash;
|
||||||
|
|
||||||
await flyPlane(inst, 'plane-starter', 'LEMD');
|
await flyPlane(inst, 'plane-starter', 'LEMD');
|
||||||
|
|
||||||
const plane = (await inst.db.select().from(schema.planes))[0];
|
const plane = (await inst.db.select().from(schema.planes))[0];
|
||||||
expect(plane.status).toBe('flying');
|
expect(plane.status).toBe('flying');
|
||||||
expect(plane.fuel).toBe(PLANE_TYPES.atr72.maxFuel); // untouched…
|
expect(plane.fuel).toBe(PLANE_TYPES.atr72.maxFuel); // untouched…
|
||||||
expect((await inst.db.select().from(schema.account))[0].cash).toBe(cashBefore); // …and free
|
expect((await getLocalPlayer(inst)).cash).toBe(cashBefore); // …and free
|
||||||
});
|
});
|
||||||
|
|
||||||
it('rejects dispatch with 409 insufficient funds when cash cannot cover the top-up — nothing mutated', async () => {
|
it('rejects dispatch with 409 insufficient funds when cash cannot cover the top-up — nothing mutated', async () => {
|
||||||
@@ -287,7 +287,7 @@ describe('flyPlane', () => {
|
|||||||
const required = await adjustedRequiredForHubToLemd();
|
const required = await adjustedRequiredForHubToLemd();
|
||||||
const startFuel = Math.round(required / 2);
|
const startFuel = Math.round(required / 2);
|
||||||
await inst.db.update(schema.planes).set({ fuel: startFuel }).where(eq(schema.planes.id, 'plane-starter'));
|
await inst.db.update(schema.planes).set({ fuel: startFuel }).where(eq(schema.planes.id, 'plane-starter'));
|
||||||
await inst.db.update(schema.account).set({ cash: 0 });
|
await updateLocalPlayerEconomy(inst, { cash: 0 });
|
||||||
|
|
||||||
await expectActionError(flyPlane(inst, 'plane-starter', 'LEMD'), 409, /insufficient funds/i);
|
await expectActionError(flyPlane(inst, 'plane-starter', 'LEMD'), 409, /insufficient funds/i);
|
||||||
|
|
||||||
@@ -452,7 +452,7 @@ describe('abandonPackage', () => {
|
|||||||
|
|
||||||
it('charges exactly 15% of the payout right after creation (clock at createdSimTime)', async () => {
|
it('charges exactly 15% of the payout right after creation (clock at createdSimTime)', async () => {
|
||||||
const inst = await setupLoaded('ab-start.db');
|
const inst = await setupLoaded('ab-start.db');
|
||||||
const cashBefore = (await inst.db.select().from(schema.account))[0].cash;
|
const cashBefore = (await getLocalPlayer(inst)).cash;
|
||||||
|
|
||||||
const { penalty } = await abandonPackage(inst, 'p-ab');
|
const { penalty } = await abandonPackage(inst, 'p-ab');
|
||||||
|
|
||||||
@@ -460,8 +460,8 @@ describe('abandonPackage', () => {
|
|||||||
const row = (await inst.db.select().from(schema.packages).where(eq(schema.packages.id, 'p-ab')))[0];
|
const row = (await inst.db.select().from(schema.packages).where(eq(schema.packages.id, 'p-ab')))[0];
|
||||||
expect(row.status).toBe('abandoned');
|
expect(row.status).toBe('abandoned');
|
||||||
expect(row.planeId).toBeNull(); // slot freed
|
expect(row.planeId).toBeNull(); // slot freed
|
||||||
const account = (await inst.db.select().from(schema.account))[0];
|
const player = await getLocalPlayer(inst);
|
||||||
expect(account.cash).toBeCloseTo(cashBefore - penalty, 6);
|
expect(player.cash).toBeCloseTo(cashBefore - penalty, 6);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('scales to exactly 37.5% at the midpoint of the window', async () => {
|
it('scales to exactly 37.5% at the midpoint of the window', async () => {
|
||||||
@@ -488,24 +488,24 @@ describe('abandonPackage', () => {
|
|||||||
|
|
||||||
it('is free for an already-expired package', async () => {
|
it('is free for an already-expired package', async () => {
|
||||||
const inst = await setupLoaded('ab-expired.db', 'expired');
|
const inst = await setupLoaded('ab-expired.db', 'expired');
|
||||||
const cashBefore = (await inst.db.select().from(schema.account))[0].cash;
|
const cashBefore = (await getLocalPlayer(inst)).cash;
|
||||||
|
|
||||||
const { penalty } = await abandonPackage(inst, 'p-ab');
|
const { penalty } = await abandonPackage(inst, 'p-ab');
|
||||||
|
|
||||||
expect(penalty).toBe(0);
|
expect(penalty).toBe(0);
|
||||||
expect((await inst.db.select().from(schema.account))[0].cash).toBe(cashBefore);
|
expect((await getLocalPlayer(inst)).cash).toBe(cashBefore);
|
||||||
const row = (await inst.db.select().from(schema.packages).where(eq(schema.packages.id, 'p-ab')))[0];
|
const row = (await inst.db.select().from(schema.packages).where(eq(schema.packages.id, 'p-ab')))[0];
|
||||||
expect(row.status).toBe('abandoned');
|
expect(row.status).toBe('abandoned');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('floors cash at €0 — no debt', async () => {
|
it('floors cash at €0 — no debt', async () => {
|
||||||
const inst = await setupLoaded('ab-floor.db');
|
const inst = await setupLoaded('ab-floor.db');
|
||||||
await inst.db.update(schema.account).set({ cash: 10 }); // penalty is 150 > 10
|
await updateLocalPlayerEconomy(inst, { cash: 10 }); // penalty is 150 > 10
|
||||||
|
|
||||||
const { penalty } = await abandonPackage(inst, 'p-ab');
|
const { penalty } = await abandonPackage(inst, 'p-ab');
|
||||||
|
|
||||||
expect(penalty).toBe(150);
|
expect(penalty).toBe(150);
|
||||||
expect((await inst.db.select().from(schema.account))[0].cash).toBe(0);
|
expect((await getLocalPlayer(inst)).cash).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('rejects abandoning while the plane is in flight with 409', async () => {
|
it('rejects abandoning while the plane is in flight with 409', async () => {
|
||||||
@@ -530,46 +530,16 @@ describe('abandonPackage', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('ignorePackage', () => {
|
|
||||||
it('flips an open package to ignored — no penalty, nothing else changes', async () => {
|
|
||||||
const inst = await freshDb('ig-open.db');
|
|
||||||
await insertOpenPackage(inst, 'p-ig');
|
|
||||||
const cashBefore = (await inst.db.select().from(schema.account))[0].cash;
|
|
||||||
|
|
||||||
await ignorePackage(inst, 'p-ig');
|
|
||||||
|
|
||||||
const row = (await inst.db.select().from(schema.packages).where(eq(schema.packages.id, 'p-ig')))[0];
|
|
||||||
expect(row.status).toBe('ignored');
|
|
||||||
expect(row.planeId).toBeNull(); // was never bound
|
|
||||||
expect((await inst.db.select().from(schema.account))[0].cash).toBe(cashBefore); // no penalty
|
|
||||||
});
|
|
||||||
|
|
||||||
it.each(['loaded', 'delivered', 'expired', 'abandoned', 'ignored'] as const)(
|
|
||||||
'rejects a %s package with 409 (must be open)',
|
|
||||||
async (status) => {
|
|
||||||
const inst = await freshDb(`ig-${status}.db`);
|
|
||||||
await insertOpenPackage(inst, 'p-x', { status });
|
|
||||||
|
|
||||||
await expectActionError(ignorePackage(inst, 'p-x'), 409, new RegExp(status));
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
it('rejects an unknown id with 404', async () => {
|
|
||||||
const inst = await freshDb('ig-unknown.db');
|
|
||||||
await expectActionError(ignorePackage(inst, 'nope'), 404);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('buyPlane', () => {
|
describe('buyPlane', () => {
|
||||||
it('deducts the full price and delivers a full-tank plane at the home base', async () => {
|
it('deducts the full price and delivers a full-tank plane at the home base', async () => {
|
||||||
const inst = await freshDb('buy-ok.db');
|
const inst = await freshDb('buy-ok.db');
|
||||||
await inst.db.update(schema.account).set({ cash: 500_000 });
|
await updateLocalPlayerEconomy(inst, { cash: 500_000 });
|
||||||
|
|
||||||
const before = (await inst.db.select().from(schema.planes)).length;
|
const before = (await inst.db.select().from(schema.planes)).length;
|
||||||
const { planeId } = await buyPlane(inst, 'atr72');
|
const { planeId } = await buyPlane(inst, 'atr72');
|
||||||
|
|
||||||
const account = (await inst.db.select().from(schema.account))[0];
|
const player = await getLocalPlayer(inst);
|
||||||
expect(account.cash).toBe(500_000 - PLANE_TYPES.atr72.price);
|
expect(player.cash).toBe(500_000 - PLANE_TYPES.atr72.price);
|
||||||
|
|
||||||
const planes = await inst.db.select().from(schema.planes);
|
const planes = await inst.db.select().from(schema.planes);
|
||||||
expect(planes.length).toBe(before + 1);
|
expect(planes.length).toBe(before + 1);
|
||||||
@@ -598,7 +568,7 @@ describe('buyPlane', () => {
|
|||||||
it('deducts the reputation-scaled cost at elevated rep (v0.38.0)', async () => {
|
it('deducts the reputation-scaled cost at elevated rep (v0.38.0)', async () => {
|
||||||
const inst = await freshDb('buy-rep.db');
|
const inst = await freshDb('buy-rep.db');
|
||||||
// rep 30 → rate exactly 0.2 → ATR costs 160k, not 200k.
|
// rep 30 → rate exactly 0.2 → ATR costs 160k, not 200k.
|
||||||
await inst.db.update(schema.account).set({ cash: 500_000, reputation: 30 });
|
await updateLocalPlayerEconomy(inst, { cash: 500_000, reputation: 30 });
|
||||||
|
|
||||||
const before = (await inst.db.select().from(schema.planes)).length;
|
const before = (await inst.db.select().from(schema.planes)).length;
|
||||||
await buyPlane(inst, 'atr72');
|
await buyPlane(inst, 'atr72');
|
||||||
@@ -607,23 +577,23 @@ describe('buyPlane', () => {
|
|||||||
expect(rate).toBeCloseTo(0.2, 12); // sanity pin on the formula input
|
expect(rate).toBeCloseTo(0.2, 12); // sanity pin on the formula input
|
||||||
const expectedCost = Math.round(PLANE_TYPES.atr72.price * (1 - rate) * 100) / 100;
|
const expectedCost = Math.round(PLANE_TYPES.atr72.price * (1 - rate) * 100) / 100;
|
||||||
expect(expectedCost).toBe(160_000); // 200k × 0.8 — exact value pin
|
expect(expectedCost).toBe(160_000); // 200k × 0.8 — exact value pin
|
||||||
const account = (await inst.db.select().from(schema.account))[0];
|
const player = await getLocalPlayer(inst);
|
||||||
expect(account.cash).toBeCloseTo(500_000 - expectedCost, 6);
|
expect(player.cash).toBeCloseTo(500_000 - expectedCost, 6);
|
||||||
expect((await inst.db.select().from(schema.planes)).length).toBe(before + 1);
|
expect((await inst.db.select().from(schema.planes)).length).toBe(before + 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('buys with cash between the discounted and full price; rejects below the discounted cost (v0.38.0)', async () => {
|
it('buys with cash between the discounted and full price; rejects below the discounted cost (v0.38.0)', async () => {
|
||||||
const inst = await freshDb('buy-boundary.db');
|
const inst = await freshDb('buy-boundary.db');
|
||||||
// rep 30 → discounted cost 160k: 170k is enough now, though it was not before v0.38.0.
|
// rep 30 → discounted cost 160k: 170k is enough now, though it was not before v0.38.0.
|
||||||
await inst.db.update(schema.account).set({ cash: 170_000, reputation: 30 });
|
await updateLocalPlayerEconomy(inst, { cash: 170_000, reputation: 30 });
|
||||||
|
|
||||||
const { planeId } = await buyPlane(inst, 'atr72');
|
const { planeId } = await buyPlane(inst, 'atr72');
|
||||||
expect(planeId).toBeTruthy(); // the old full-price check would have rejected this
|
expect(planeId).toBeTruthy(); // the old full-price check would have rejected this
|
||||||
const account = (await inst.db.select().from(schema.account))[0];
|
const player = await getLocalPlayer(inst);
|
||||||
expect(account.cash).toBeCloseTo(170_000 - 160_000, 6);
|
expect(player.cash).toBeCloseTo(170_000 - 160_000, 6);
|
||||||
|
|
||||||
const inst2 = await freshDb('buy-boundary-poor.db'); // just below the discounted cost
|
const inst2 = await freshDb('buy-boundary-poor.db'); // just below the discounted cost
|
||||||
await inst2.db.update(schema.account).set({ cash: 159_999.99, reputation: 30 });
|
await updateLocalPlayerEconomy(inst2, { cash: 159_999.99, reputation: 30 });
|
||||||
await expectActionError(buyPlane(inst2, 'atr72'), 409, /insufficient funds/i);
|
await expectActionError(buyPlane(inst2, 'atr72'), 409, /insufficient funds/i);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -636,13 +606,13 @@ describe('sellPlane', () => {
|
|||||||
id: 'plane-extra', model: 'atr72', status: 'available', fuel: 100, maxFuel: PLANE_TYPES.atr72.maxFuel,
|
id: 'plane-extra', model: 'atr72', status: 'available', fuel: 100, maxFuel: PLANE_TYPES.atr72.maxFuel,
|
||||||
locationIcao: HUB_ICAO, destIcao: null, lat: 50, lon: 8, departureSimTime: null,
|
locationIcao: HUB_ICAO, destIcao: null, lat: 50, lon: 8, departureSimTime: null,
|
||||||
});
|
});
|
||||||
const cashBefore = (await inst.db.select().from(schema.account))[0].cash;
|
const cashBefore = (await getLocalPlayer(inst)).cash;
|
||||||
|
|
||||||
const { payout } = await sellPlane(inst, 'plane-extra');
|
const { payout } = await sellPlane(inst, 'plane-extra');
|
||||||
|
|
||||||
expect(payout).toBe(Math.round(PLANE_TYPES.atr72.price * SELL_FRACTION * 100) / 100);
|
expect(payout).toBe(Math.round(PLANE_TYPES.atr72.price * SELL_FRACTION * 100) / 100);
|
||||||
const account = (await inst.db.select().from(schema.account))[0];
|
const player = await getLocalPlayer(inst);
|
||||||
expect(account.cash).toBeCloseTo(cashBefore + payout, 6);
|
expect(player.cash).toBeCloseTo(cashBefore + payout, 6);
|
||||||
const ids = (await inst.db.select().from(schema.planes)).map((p) => p.id);
|
const ids = (await inst.db.select().from(schema.planes)).map((p) => p.id);
|
||||||
expect(ids).not.toContain('plane-extra'); // row deleted
|
expect(ids).not.toContain('plane-extra'); // row deleted
|
||||||
expect(ids).toContain('plane-starter');
|
expect(ids).toContain('plane-starter');
|
||||||
@@ -699,7 +669,7 @@ describe('repairPlane (v0.39.0, ISS-069; gradual since v0.45.0, ISS-089)', () =>
|
|||||||
it('charges exactly REPAIR_COST and grounds the plane for REPAIR_DURATION_MS without touching health yet', async () => {
|
it('charges exactly REPAIR_COST and grounds the plane for REPAIR_DURATION_MS without touching health yet', async () => {
|
||||||
const inst = await freshDb('repair-ok.db');
|
const inst = await freshDb('repair-ok.db');
|
||||||
await inst.db.update(schema.planes).set({ health: 42 }).where(eq(schema.planes.id, 'plane-starter'));
|
await inst.db.update(schema.planes).set({ health: 42 }).where(eq(schema.planes.id, 'plane-starter'));
|
||||||
const cashBefore = (await inst.db.select().from(schema.account))[0].cash;
|
const cashBefore = (await getLocalPlayer(inst)).cash;
|
||||||
|
|
||||||
const { cost } = await repairPlane(inst, 'plane-starter');
|
const { cost } = await repairPlane(inst, 'plane-starter');
|
||||||
|
|
||||||
@@ -708,13 +678,13 @@ describe('repairPlane (v0.39.0, ISS-069; gradual since v0.45.0, ISS-089)', () =>
|
|||||||
expect(plane.status).toBe('repairing');
|
expect(plane.status).toBe('repairing');
|
||||||
expect(plane.health).toBe(42); // NOT restored yet — the engine's finishRepairs pass heals it gradually…
|
expect(plane.health).toBe(42); // NOT restored yet — the engine's finishRepairs pass heals it gradually…
|
||||||
expect(plane.repairUntilSimTime).toBe(STARTING_CLOCK_MS + REPAIR_DURATION_MS); // …with the gate set from the seeded game clock (ISS-117; no tick in direct calls)
|
expect(plane.repairUntilSimTime).toBe(STARTING_CLOCK_MS + REPAIR_DURATION_MS); // …with the gate set from the seeded game clock (ISS-117; no tick in direct calls)
|
||||||
const account = (await inst.db.select().from(schema.account))[0];
|
const player = await getLocalPlayer(inst);
|
||||||
expect(account.cash).toBeCloseTo(cashBefore - REPAIR_COST, 6);
|
expect(player.cash).toBeCloseTo(cashBefore - REPAIR_COST, 6);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('is a free no-op when health is already full', async () => {
|
it('is a free no-op when health is already full', async () => {
|
||||||
const inst = await freshDb('repair-full.db'); // seeded starter at 100
|
const inst = await freshDb('repair-full.db'); // seeded starter at 100
|
||||||
const cashBefore = (await inst.db.select().from(schema.account))[0].cash;
|
const cashBefore = (await getLocalPlayer(inst)).cash;
|
||||||
|
|
||||||
const { cost } = await repairPlane(inst, 'plane-starter');
|
const { cost } = await repairPlane(inst, 'plane-starter');
|
||||||
|
|
||||||
@@ -723,7 +693,7 @@ describe('repairPlane (v0.39.0, ISS-069; gradual since v0.45.0, ISS-089)', () =>
|
|||||||
expect(plane.status).toBe('available'); // not grounded…
|
expect(plane.status).toBe('available'); // not grounded…
|
||||||
expect(plane.health).toBe(100);
|
expect(plane.health).toBe(100);
|
||||||
expect(plane.repairUntilSimTime ?? null).toBeNull(); // …and no gate set
|
expect(plane.repairUntilSimTime ?? null).toBeNull(); // …and no gate set
|
||||||
expect((await inst.db.select().from(schema.account))[0].cash).toBe(cashBefore);
|
expect((await getLocalPlayer(inst)).cash).toBe(cashBefore);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('rejects a flying plane with 409', async () => {
|
it('rejects a flying plane with 409', async () => {
|
||||||
@@ -763,7 +733,7 @@ describe('repairPlane (v0.39.0, ISS-069; gradual since v0.45.0, ISS-089)', () =>
|
|||||||
it('rejects the repair when cash is below REPAIR_COST with 409', async () => {
|
it('rejects the repair when cash is below REPAIR_COST with 409', async () => {
|
||||||
const inst = await freshDb('repair-poor.db');
|
const inst = await freshDb('repair-poor.db');
|
||||||
await inst.db.update(schema.planes).set({ health: 50 }).where(eq(schema.planes.id, 'plane-starter'));
|
await inst.db.update(schema.planes).set({ health: 50 }).where(eq(schema.planes.id, 'plane-starter'));
|
||||||
await inst.db.update(schema.account).set({ cash: REPAIR_COST - 1 });
|
await updateLocalPlayerEconomy(inst, { cash: REPAIR_COST - 1 });
|
||||||
|
|
||||||
await expectActionError(repairPlane(inst, 'plane-starter'), 409, /insufficient funds/i);
|
await expectActionError(repairPlane(inst, 'plane-starter'), 409, /insufficient funds/i);
|
||||||
});
|
});
|
||||||
|
|||||||
+19
-40
@@ -1,6 +1,7 @@
|
|||||||
import { randomUUID } from 'node:crypto';
|
import { randomUUID } from 'node:crypto';
|
||||||
import { and, eq, inArray } from 'drizzle-orm';
|
import { and, eq, inArray } from 'drizzle-orm';
|
||||||
import * as schema from '@/lib/db/schema';
|
import * as schema from '@/lib/db/schema';
|
||||||
|
import { getLocalPlayer, updateLocalPlayerEconomy } from '@/lib/db/localPlayer';
|
||||||
import { persist, type GameDb } from '@/lib/db/client';
|
import { persist, type GameDb } from '@/lib/db/client';
|
||||||
import { loadAirportsGeoJson } from '@/lib/airports';
|
import { loadAirportsGeoJson } from '@/lib/airports';
|
||||||
import { haversineKm, initialBearingDeg } from '@/lib/geo';
|
import { haversineKm, initialBearingDeg } from '@/lib/geo';
|
||||||
@@ -140,11 +141,10 @@ export async function flyPlane(inst: GameDb, planeId: string, destIcao: string):
|
|||||||
// any mutation, so a 409 leaves fuel and cash untouched.
|
// any mutation, so a 409 leaves fuel and cash untouched.
|
||||||
const target = Math.min(plane.maxFuel, Math.max(plane.fuel, requiredL * 1.5));
|
const target = Math.min(plane.maxFuel, Math.max(plane.fuel, requiredL * 1.5));
|
||||||
const liters = Math.max(0, target - plane.fuel);
|
const liters = Math.max(0, target - plane.fuel);
|
||||||
const account = (await inst.db.select().from(schema.account))[0];
|
const player = await getLocalPlayer(inst);
|
||||||
if (!account) throw new Error('account row missing');
|
const cost = Math.round(liters * FUEL_PRICE_PER_L * (1 - repRate(player.reputation, FUEL_DISCOUNT_PER_REP, MAX_FUEL_DISCOUNT)) * 100) / 100;
|
||||||
const cost = Math.round(liters * FUEL_PRICE_PER_L * (1 - repRate(account.reputation, FUEL_DISCOUNT_PER_REP, MAX_FUEL_DISCOUNT)) * 100) / 100;
|
if (cost > 0 && player.cash < cost) {
|
||||||
if (cost > 0 && account.cash < cost) {
|
throw new GameActionError(409, `insufficient funds: refueling costs ${cost}, you have ${Math.round(player.cash)}`);
|
||||||
throw new GameActionError(409, `insufficient funds: refueling costs ${cost}, you have ${Math.round(account.cash)}`);
|
|
||||||
}
|
}
|
||||||
// Backstop: a leg that doesn't fit even a full tank is unflyable (target caps at maxFuel).
|
// Backstop: a leg that doesn't fit even a full tank is unflyable (target caps at maxFuel).
|
||||||
if (requiredL > target) {
|
if (requiredL > target) {
|
||||||
@@ -173,7 +173,7 @@ export async function flyPlane(inst: GameDb, planeId: string, destIcao: string):
|
|||||||
})
|
})
|
||||||
.where(eq(schema.planes.id, planeId));
|
.where(eq(schema.planes.id, planeId));
|
||||||
if (cost > 0) {
|
if (cost > 0) {
|
||||||
await inst.db.update(schema.account).set({ cash: Math.round((account.cash - cost) * 100) / 100 });
|
await updateLocalPlayerEconomy(inst, { cash: Math.round((player.cash - cost) * 100) / 100 });
|
||||||
}
|
}
|
||||||
await persist(inst);
|
await persist(inst);
|
||||||
}
|
}
|
||||||
@@ -255,31 +255,13 @@ export async function abandonPackage(inst: GameDb, packageId: string): Promise<{
|
|||||||
if (!sim) throw new Error('sim_state row missing');
|
if (!sim) throw new Error('sim_state row missing');
|
||||||
const penalty = abandonPenalty(pkg, sim.clockMs);
|
const penalty = abandonPenalty(pkg, sim.clockMs);
|
||||||
|
|
||||||
const account = (await inst.db.select().from(schema.account))[0];
|
const player = await getLocalPlayer(inst);
|
||||||
if (!account) throw new Error('account row missing');
|
await updateLocalPlayerEconomy(inst, { cash: Math.max(0, Math.round((player.cash - penalty) * 100) / 100) });
|
||||||
await inst.db.update(schema.account).set({ cash: Math.max(0, Math.round((account.cash - penalty) * 100) / 100) });
|
|
||||||
await inst.db.update(schema.packages).set({ status: 'abandoned', planeId: null }).where(eq(schema.packages.id, packageId));
|
await inst.db.update(schema.packages).set({ status: 'abandoned', planeId: null }).where(eq(schema.packages.id, packageId));
|
||||||
await persist(inst);
|
await persist(inst);
|
||||||
return { penalty };
|
return { penalty };
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Ignore (POST /api/packages/:id/ignore) — ISS-047 part B ---
|
|
||||||
|
|
||||||
// Dismiss an OPEN job so it leaves the market permanently; no penalty, nothing else
|
|
||||||
// changes. The pool spawner refills this (origin, band) slot after its refill delay —
|
|
||||||
// ignoring starts that cooldown via slotFreeAtRealMs (v0.65.0). 404 unknown id; 409 unless open.
|
|
||||||
export async function ignorePackage(inst: GameDb, packageId: string): Promise<void> {
|
|
||||||
const pkgRows = await inst.db.select().from(schema.packages).where(eq(schema.packages.id, packageId));
|
|
||||||
const pkg = pkgRows[0];
|
|
||||||
if (!pkg) throw new GameActionError(404, `package ${packageId} not found`);
|
|
||||||
if (pkg.status !== 'open') {
|
|
||||||
throw new GameActionError(409, `package is ${pkg.status}, only open packages can be ignored`);
|
|
||||||
}
|
|
||||||
|
|
||||||
await inst.db.update(schema.packages).set({ status: 'ignored', slotFreeAtRealMs: Date.now() }).where(eq(schema.packages.id, packageId));
|
|
||||||
await persist(inst);
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- Market (POST /api/market/buy-plane {model}) ---
|
// --- Market (POST /api/market/buy-plane {model}) ---
|
||||||
|
|
||||||
// Buy a catalog model at its reputation-scaled price (v0.38.0, ISS-072 — discount grows with
|
// Buy a catalog model at its reputation-scaled price (v0.38.0, ISS-072 — discount grows with
|
||||||
@@ -289,12 +271,11 @@ export async function buyPlane(inst: GameDb, model: string): Promise<{ planeId:
|
|||||||
const type = PLANE_TYPES[model];
|
const type = PLANE_TYPES[model];
|
||||||
if (!type) throw new GameActionError(400, `unknown plane model "${model}"`);
|
if (!type) throw new GameActionError(400, `unknown plane model "${model}"`);
|
||||||
|
|
||||||
const account = (await inst.db.select().from(schema.account))[0];
|
const player = await getLocalPlayer(inst);
|
||||||
if (!account) throw new Error('account row missing');
|
|
||||||
// v0.38.0 (ISS-072): the EFFECTIVE cost drives both the funds check and the deduction.
|
// v0.38.0 (ISS-072): the EFFECTIVE cost drives both the funds check and the deduction.
|
||||||
const cost = Math.round(type.price * (1 - repRate(account.reputation, PLANE_DISCOUNT_PER_REP, MAX_PLANE_DISCOUNT)) * 100) / 100;
|
const cost = Math.round(type.price * (1 - repRate(player.reputation, PLANE_DISCOUNT_PER_REP, MAX_PLANE_DISCOUNT)) * 100) / 100;
|
||||||
if (account.cash < cost) {
|
if (player.cash < cost) {
|
||||||
throw new GameActionError(409, `insufficient funds: a ${type.name} costs ${cost}, you have ${Math.round(account.cash)}`);
|
throw new GameActionError(409, `insufficient funds: a ${type.name} costs ${cost}, you have ${Math.round(player.cash)}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const fc = await loadAirportsGeoJson();
|
const fc = await loadAirportsGeoJson();
|
||||||
@@ -315,7 +296,7 @@ export async function buyPlane(inst: GameDb, model: string): Promise<{ planeId:
|
|||||||
departureSimTime: null,
|
departureSimTime: null,
|
||||||
health: 100, // new planes arrive at full health (v0.39.0, ISS-069)
|
health: 100, // new planes arrive at full health (v0.39.0, ISS-069)
|
||||||
});
|
});
|
||||||
await inst.db.update(schema.account).set({ cash: Math.round((account.cash - cost) * 100) / 100 });
|
await updateLocalPlayerEconomy(inst, { cash: Math.round((player.cash - cost) * 100) / 100 });
|
||||||
await persist(inst);
|
await persist(inst);
|
||||||
return { planeId };
|
return { planeId };
|
||||||
}
|
}
|
||||||
@@ -354,9 +335,8 @@ export async function sellPlane(inst: GameDb, planeId: string): Promise<{ payout
|
|||||||
const payout = Math.round(type.price * SELL_FRACTION * 100) / 100;
|
const payout = Math.round(type.price * SELL_FRACTION * 100) / 100;
|
||||||
|
|
||||||
await inst.db.delete(schema.planes).where(eq(schema.planes.id, planeId));
|
await inst.db.delete(schema.planes).where(eq(schema.planes.id, planeId));
|
||||||
const account = (await inst.db.select().from(schema.account))[0];
|
const player = await getLocalPlayer(inst);
|
||||||
if (!account) throw new Error('account row missing');
|
await updateLocalPlayerEconomy(inst, { cash: Math.round((player.cash + payout) * 100) / 100 });
|
||||||
await inst.db.update(schema.account).set({ cash: Math.round((account.cash + payout) * 100) / 100 });
|
|
||||||
await persist(inst);
|
await persist(inst);
|
||||||
return { payout };
|
return { payout };
|
||||||
}
|
}
|
||||||
@@ -381,17 +361,16 @@ export async function repairPlane(inst: GameDb, planeId: string): Promise<{ cost
|
|||||||
|
|
||||||
const sim = (await inst.db.select().from(schema.simState))[0];
|
const sim = (await inst.db.select().from(schema.simState))[0];
|
||||||
if (!sim) throw new Error('sim_state row missing');
|
if (!sim) throw new Error('sim_state row missing');
|
||||||
const account = (await inst.db.select().from(schema.account))[0];
|
const player = await getLocalPlayer(inst);
|
||||||
if (!account) throw new Error('account row missing');
|
if (player.cash < REPAIR_COST) {
|
||||||
if (account.cash < REPAIR_COST) {
|
throw new GameActionError(409, `insufficient funds: repair costs ${REPAIR_COST}, you have ${Math.round(player.cash)}`);
|
||||||
throw new GameActionError(409, `insufficient funds: repair costs ${REPAIR_COST}, you have ${Math.round(account.cash)}`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Health is NOT set here — the engine's finishRepairs pass heals it gradually along the gate.
|
// Health is NOT set here — the engine's finishRepairs pass heals it gradually along the gate.
|
||||||
await inst.db.update(schema.planes)
|
await inst.db.update(schema.planes)
|
||||||
.set({ status: 'repairing', repairUntilSimTime: sim.clockMs + REPAIR_DURATION_MS })
|
.set({ status: 'repairing', repairUntilSimTime: sim.clockMs + REPAIR_DURATION_MS })
|
||||||
.where(eq(schema.planes.id, planeId));
|
.where(eq(schema.planes.id, planeId));
|
||||||
await inst.db.update(schema.account).set({ cash: Math.round((account.cash - REPAIR_COST) * 100) / 100 });
|
await updateLocalPlayerEconomy(inst, { cash: Math.round((player.cash - REPAIR_COST) * 100) / 100 });
|
||||||
await persist(inst);
|
await persist(inst);
|
||||||
return { cost: REPAIR_COST };
|
return { cost: REPAIR_COST };
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -122,7 +122,7 @@ function envMs(name: string, fallback: number): number {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const JOB_LIFETIME_MS = envMs('FLIGHT_JOB_LIFETIME_MS', 3_600_000); // 1 h wall clock
|
export const JOB_LIFETIME_MS = envMs('FLIGHT_JOB_LIFETIME_MS', 3_600_000); // 1 h wall clock
|
||||||
// Refill cooldown after a job is TAKEN (loaded or ignored): the slot stays empty this long so the
|
// Refill cooldown after a job is TAKEN (loaded): the slot stays empty this long so the
|
||||||
// board visibly refreshes instead of instantly refilling. Expired/delivered/abandoned never block —
|
// board visibly refreshes instead of instantly refilling. Expired/delivered/abandoned never block —
|
||||||
// an untaken job's slot respawns immediately. Small jobs (<4 t) refill faster; they're common.
|
// an untaken job's slot respawns immediately. Small jobs (<4 t) refill faster; they're common.
|
||||||
export const REFILL_DELAY_MS = envMs('FLIGHT_JOB_REFILL_MS', 15 * 60_000); // 15 min wall clock
|
export const REFILL_DELAY_MS = envMs('FLIGHT_JOB_REFILL_MS', 15 * 60_000); // 15 min wall clock
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ describe('sseFrame', () => {
|
|||||||
pkg('loaded', 'p-loaded'),
|
pkg('loaded', 'p-loaded'),
|
||||||
pkg('abandoned', 'p-abandoned'),
|
pkg('abandoned', 'p-abandoned'),
|
||||||
pkg('expired', 'p-expired'),
|
pkg('expired', 'p-expired'),
|
||||||
pkg('ignored', 'p-ignored'),
|
|
||||||
];
|
];
|
||||||
const frame = sseFrame(snapshot(all));
|
const frame = sseFrame(snapshot(all));
|
||||||
expect(frame.packages.map((p) => p.id)).toEqual(['p-open', 'p-loaded', 'p-expired']);
|
expect(frame.packages.map((p) => p.id)).toEqual(['p-open', 'p-loaded', 'p-expired']);
|
||||||
|
|||||||
+11
-9
@@ -2,6 +2,7 @@ import { loadAirportsGeoJson } from '@/lib/airports';
|
|||||||
import { haversineKm, initialBearingDeg } from '@/lib/geo';
|
import { haversineKm, initialBearingDeg } from '@/lib/geo';
|
||||||
import { weatherFor } from '@/lib/weather';
|
import { weatherFor } from '@/lib/weather';
|
||||||
import { getGameDb } from '@/lib/db/client';
|
import { getGameDb } from '@/lib/db/client';
|
||||||
|
import { getLocalPlayer } from '@/lib/db/localPlayer';
|
||||||
import * as schema from '@/lib/db/schema';
|
import * as schema from '@/lib/db/schema';
|
||||||
import { catalogEntries, FUEL_PRICE_PER_L, PLANE_TYPES, SELL_FRACTION, type CatalogEntry } from './catalog';
|
import { catalogEntries, FUEL_PRICE_PER_L, PLANE_TYPES, SELL_FRACTION, type CatalogEntry } from './catalog';
|
||||||
import { fuelAtWeighted, progressAt, positionAt, windBurnFactor } from '@/lib/sim/movement';
|
import { fuelAtWeighted, progressAt, positionAt, windBurnFactor } from '@/lib/sim/movement';
|
||||||
@@ -81,8 +82,7 @@ export interface PackageState {
|
|||||||
// Great-circle leg distance in km (v0.48.0, ISS-095) — computed from airport coords, not stored.
|
// Great-circle leg distance in km (v0.48.0, ISS-095) — computed from airport coords, not stored.
|
||||||
distanceKm: number;
|
distanceKm: number;
|
||||||
deadlineSimTime: number;
|
deadlineSimTime: number;
|
||||||
// 'ignored' (v0.29.0, ISS-047 part B) = a dismissed open job — terminal, leaves the market.
|
status: 'open' | 'loaded' | 'delivered' | 'expired' | 'abandoned';
|
||||||
status: 'open' | 'loaded' | 'delivered' | 'expired' | 'abandoned' | 'ignored';
|
|
||||||
planeId: string | null;
|
planeId: string | null;
|
||||||
createdSimTime: number;
|
createdSimTime: number;
|
||||||
// Wall-clock expiry of an OPEN job (v0.65.0) — createdRealMs + JOB_LIFETIME_MS, shown as a live
|
// Wall-clock expiry of an OPEN job (v0.65.0) — createdRealMs + JOB_LIFETIME_MS, shown as a live
|
||||||
@@ -106,7 +106,7 @@ export interface StateSnapshot {
|
|||||||
|
|
||||||
// ISS-133 (v0.59.0): the SSE projection of a snapshot — only the package statuses any component
|
// ISS-133 (v0.59.0): the SSE projection of a snapshot — only the package statuses any component
|
||||||
// renders: open (market list), loaded + expired (on-board cargo, which keeps its payload slot).
|
// renders: open (market list), loaded + expired (on-board cargo, which keeps its payload slot).
|
||||||
// Terminal history (delivered/abandoned/ignored) is unbounded in the DB and never read by the
|
// Terminal history (delivered/abandoned) is unbounded in the DB and never read by the
|
||||||
// client, so it stays out of every pushed frame; /api/state and action responses keep the full set.
|
// client, so it stays out of every pushed frame; /api/state and action responses keep the full set.
|
||||||
export const SSE_PACKAGE_STATUSES = ['open', 'loaded', 'expired'] as const;
|
export const SSE_PACKAGE_STATUSES = ['open', 'loaded', 'expired'] as const;
|
||||||
|
|
||||||
@@ -115,19 +115,21 @@ export function sseFrame(snapshot: StateSnapshot): StateSnapshot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getStateSnapshot(): Promise<StateSnapshot> {
|
export async function getStateSnapshot(): Promise<StateSnapshot> {
|
||||||
const { db } = await getGameDb();
|
const inst = await getGameDb();
|
||||||
|
const { db } = inst;
|
||||||
// NOTE: use plain select(), not the relational db.query.* API — in drizzle-orm
|
// NOTE: use plain select(), not the relational db.query.* API — in drizzle-orm
|
||||||
// 0.45.x the sql-js driver drops the result mapper for relational queries and
|
// 0.45.x the sql-js driver drops the result mapper for relational queries and
|
||||||
// returns raw rows keyed by SQL column names (snake_case, no type decoding).
|
// returns raw rows keyed by SQL column names (snake_case, no type decoding).
|
||||||
const [accountRows, simRows, planeRows, packageRows] = await Promise.all([
|
// v1.0.0 (ISS-105): the snapshot's `account` field is now the local player row — same shape,
|
||||||
db.select().from(schema.account),
|
// resolved through the temporary single-player helper until multiplayer lands.
|
||||||
|
const [player, simRows, planeRows, packageRows] = await Promise.all([
|
||||||
|
getLocalPlayer(inst),
|
||||||
db.select().from(schema.simState),
|
db.select().from(schema.simState),
|
||||||
db.select().from(schema.planes),
|
db.select().from(schema.planes),
|
||||||
db.select().from(schema.packages),
|
db.select().from(schema.packages),
|
||||||
]);
|
]);
|
||||||
const accountRow = accountRows[0];
|
|
||||||
const simRow = simRows[0];
|
const simRow = simRows[0];
|
||||||
if (!accountRow || !simRow) throw new Error('game state missing account/sim_state row');
|
if (!simRow) throw new Error('game state missing sim_state row');
|
||||||
|
|
||||||
const fc = await loadAirportsGeoJson();
|
const fc = await loadAirportsGeoJson();
|
||||||
const nameByIcao = new Map(fc.features.map((f) => [f.properties.icao, f.properties.name]));
|
const nameByIcao = new Map(fc.features.map((f) => [f.properties.icao, f.properties.name]));
|
||||||
@@ -170,7 +172,7 @@ export async function getStateSnapshot(): Promise<StateSnapshot> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
account: { cash: accountRow.cash, reputation: accountRow.reputation },
|
account: { cash: player.cash, reputation: player.reputation },
|
||||||
simState: { clockMs: simRow.clockMs },
|
simState: { clockMs: simRow.clockMs },
|
||||||
catalog: catalogEntries(),
|
catalog: catalogEntries(),
|
||||||
fuelPricePerL: FUEL_PRICE_PER_L,
|
fuelPricePerL: FUEL_PRICE_PER_L,
|
||||||
|
|||||||
+56
-3
@@ -3,14 +3,18 @@ import { describe, expect, it } from 'vitest';
|
|||||||
import { openApiSpec } from './openapi';
|
import { openApiSpec } from './openapi';
|
||||||
|
|
||||||
describe('OpenAPI spec', () => {
|
describe('OpenAPI spec', () => {
|
||||||
it('documents exactly the thirteen public endpoints (4 read + 9 player actions)', () => {
|
it('documents exactly the seventeen public endpoints (6 read + 8 player actions + 2 auth + 1 admin CRUD)', () => {
|
||||||
expect(Object.keys(openApiSpec.paths).sort()).toEqual([
|
expect(Object.keys(openApiSpec.paths).sort()).toEqual([
|
||||||
|
'/api/admin/tables', // v0.71.0 — admin panel
|
||||||
|
'/api/admin/tables/{name}/rows', // v0.71.0 — GET+PUT+POST+DELETE on one path
|
||||||
'/api/airports',
|
'/api/airports',
|
||||||
'/api/events', // v0.57.0 (ISS-129) — SSE state stream
|
'/api/events', // v0.57.0 (ISS-129) — SSE state stream
|
||||||
|
'/api/login', // v0.71.0 — admin panel auth
|
||||||
|
'/api/logout', // v0.71.0
|
||||||
'/api/market/buy-plane',
|
'/api/market/buy-plane',
|
||||||
'/api/market/sell-plane',
|
'/api/market/sell-plane',
|
||||||
|
'/api/me', // v0.71.0
|
||||||
'/api/packages/{id}/abandon',
|
'/api/packages/{id}/abandon',
|
||||||
'/api/packages/{id}/ignore', // v0.29.0 (ISS-047 part B)
|
|
||||||
'/api/packages/{id}/load',
|
'/api/packages/{id}/load',
|
||||||
'/api/planes/{planeId}/fly',
|
'/api/planes/{planeId}/fly',
|
||||||
'/api/planes/{planeId}/queue', // v0.25.0 (ISS-043)
|
'/api/planes/{planeId}/queue', // v0.25.0 (ISS-043)
|
||||||
@@ -153,7 +157,7 @@ describe('OpenAPI spec', () => {
|
|||||||
expect(Object.keys(sim).sort()).toEqual(['clockMs']);
|
expect(Object.keys(sim).sort()).toEqual(['clockMs']);
|
||||||
|
|
||||||
const packageStatus = openApiSpec.components.schemas.PackageState.properties.status;
|
const packageStatus = openApiSpec.components.schemas.PackageState.properties.status;
|
||||||
expect(packageStatus.enum.sort()).toEqual(['abandoned', 'delivered', 'expired', 'ignored', 'loaded', 'open']); // v0.29.0 (ISS-047 part B)
|
expect(packageStatus.enum.sort()).toEqual(['abandoned', 'delivered', 'expired', 'loaded', 'open']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('documents the eight action endpoints: snapshot on 200, Error on their 4xx paths', () => {
|
it('documents the eight action endpoints: snapshot on 200, Error on their 4xx paths', () => {
|
||||||
@@ -243,4 +247,53 @@ describe('OpenAPI spec', () => {
|
|||||||
expect(sell.required).toEqual(['planeId']);
|
expect(sell.required).toEqual(['planeId']);
|
||||||
expect(sell.properties.planeId.type).toBe('string');
|
expect(sell.properties.planeId.type).toBe('string');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('documents the v0.71.0 admin-panel endpoints: auth + guarded DB CRUD', () => {
|
||||||
|
const paths = openApiSpec.paths as Record<string, Record<string, { responses: Record<string, unknown>; requestBody?: unknown; parameters?: Array<{ name: string }> }>>;
|
||||||
|
|
||||||
|
// Error codes per endpoint (401/403 on every admin route — the guard runs before input).
|
||||||
|
const codes = (p: string, m: string) => Object.keys(paths[p][m].responses).sort();
|
||||||
|
expect(codes('/api/login', 'post')).toEqual(['200', '400', '401']);
|
||||||
|
expect(codes('/api/logout', 'post')).toEqual(['200', '401']);
|
||||||
|
expect(codes('/api/me', 'get')).toEqual(['200', '401']);
|
||||||
|
expect(codes('/api/admin/tables', 'get')).toEqual(['200', '401', '403']);
|
||||||
|
for (const m of ['get', 'put', 'post', 'delete'] as const) {
|
||||||
|
expect(codes(`/api/admin/tables/{name}/rows`, m), `${m} rows`).toContain('401');
|
||||||
|
expect(codes(`/api/admin/tables/{name}/rows`, m), `${m} rows`).toContain('403');
|
||||||
|
expect(codes(`/api/admin/tables/{name}/rows`, m), `${m} rows`).toContain('404');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Success shapes.
|
||||||
|
const ok = (p: string, m: string) => paths[p][m].responses['200'] as { content: Record<string, { schema: unknown }> };
|
||||||
|
expect((ok('/api/login', 'post').content['application/json'].schema as { $ref: string }).$ref).toBe('#/components/schemas/LoginResponse');
|
||||||
|
expect((ok('/api/me', 'get').content['application/json'].schema as { $ref: string }).$ref).toBe('#/components/schemas/SessionUser');
|
||||||
|
const tables = ok('/api/admin/tables', 'get').content['application/json'].schema as { type: string; items: { $ref: string } };
|
||||||
|
expect(tables.type).toBe('array');
|
||||||
|
expect(tables.items.$ref).toBe('#/components/schemas/AdminTable');
|
||||||
|
const rows = ok('/api/admin/tables/{name}/rows', 'get').content['application/json'].schema as { $ref: string };
|
||||||
|
expect(rows.$ref).toBe('#/components/schemas/AdminRowsResponse');
|
||||||
|
|
||||||
|
// Request bodies + path parameter.
|
||||||
|
const bodyRef = (p: string, m: string) =>
|
||||||
|
((paths[p][m].requestBody ?? {}) as { content?: Record<string, { schema: { $ref: string } }> }).content?.['application/json']
|
||||||
|
?.schema.$ref;
|
||||||
|
expect(bodyRef('/api/login', 'post')).toBe('#/components/schemas/LoginRequest');
|
||||||
|
expect(bodyRef('/api/admin/tables/{name}/rows', 'put')).toBe('#/components/schemas/UpdateRowRequest');
|
||||||
|
expect(bodyRef('/api/admin/tables/{name}/rows', 'post')).toBe('#/components/schemas/InsertRowRequest');
|
||||||
|
for (const m of ['get', 'put', 'post', 'delete'] as const) {
|
||||||
|
expect(paths['/api/admin/tables/{name}/rows'][m].parameters?.map((x) => x.name)).toContain('name');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Request schema shapes.
|
||||||
|
const login = openApiSpec.components.schemas.LoginRequest;
|
||||||
|
expect(login.required).toEqual(['username', 'password']);
|
||||||
|
expect(login.properties.username.type).toBe('string');
|
||||||
|
expect(login.properties.password.type).toBe('string');
|
||||||
|
const sessionUser = openApiSpec.components.schemas.SessionUser;
|
||||||
|
expect(sessionUser.required.sort()).toEqual(['admin', 'username']);
|
||||||
|
expect(sessionUser.properties.admin.type).toBe('boolean');
|
||||||
|
const updateRow = openApiSpec.components.schemas.UpdateRowRequest;
|
||||||
|
expect(updateRow.required).toEqual(['rowid', 'values']);
|
||||||
|
expect(updateRow.properties.rowid.type).toBe('integer');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
+326
-29
@@ -8,7 +8,7 @@ export const openApiSpec = {
|
|||||||
info: {
|
info: {
|
||||||
title: 'Flight Ops API',
|
title: 'Flight Ops API',
|
||||||
description:
|
description:
|
||||||
'JSON API for Flight Ops — world airport data for the map, the live game-state snapshot, player actions (load / fly / abandon / buy / sell), and app metadata. Every action endpoint ticks the sim clock first and returns the full state snapshot on success.',
|
'JSON API for Flight Ops — world airport data for the map, the live game-state snapshot, player actions (load / fly / abandon / buy / sell), admin-panel auth + whole-database tooling (v0.71.0), and app metadata. Every action endpoint ticks the sim clock first and returns the full state snapshot on success.',
|
||||||
// Sourced from package.json so it stays in sync with every version bump.
|
// Sourced from package.json so it stays in sync with every version bump.
|
||||||
version: pkg.version,
|
version: pkg.version,
|
||||||
},
|
},
|
||||||
@@ -147,31 +147,6 @@ export const openApiSpec = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
'/api/packages/{id}/ignore': {
|
|
||||||
post: {
|
|
||||||
summary: 'Ignore an open job',
|
|
||||||
description:
|
|
||||||
'Dismiss an OPEN job so it leaves the market permanently (v0.29.0, ISS-047 part B). No penalty and nothing else changes — the top-up logic spawns a replacement on the next tick. No body.',
|
|
||||||
operationId: 'ignorePackage',
|
|
||||||
parameters: [
|
|
||||||
{ name: 'id', in: 'path', required: true, schema: { type: 'string' } },
|
|
||||||
],
|
|
||||||
responses: {
|
|
||||||
200: {
|
|
||||||
description: 'Ignored — full state snapshot (package "ignored", gone from the open list)',
|
|
||||||
content: { 'application/json': { schema: { $ref: '#/components/schemas/StateSnapshot' } } },
|
|
||||||
},
|
|
||||||
404: {
|
|
||||||
description: 'Unknown package id',
|
|
||||||
content: { 'application/json': { schema: { $ref: '#/components/schemas/Error' } } },
|
|
||||||
},
|
|
||||||
409: {
|
|
||||||
description: 'Package not "open"',
|
|
||||||
content: { 'application/json': { schema: { $ref: '#/components/schemas/Error' } } },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
'/api/planes/{planeId}/fly': {
|
'/api/planes/{planeId}/fly': {
|
||||||
post: {
|
post: {
|
||||||
summary: 'Fly a plane to an airport',
|
summary: 'Fly a plane to an airport',
|
||||||
@@ -367,7 +342,244 @@ export const openApiSpec = {
|
|||||||
content: { 'application/json': { schema: { $ref: '#/components/schemas/Error' } } },
|
content: { 'application/json': { schema: { $ref: '#/components/schemas/Error' } } },
|
||||||
},
|
},
|
||||||
409: {
|
409: {
|
||||||
description: 'Plane is not grounded (flying or already repairing), or cash is insufficient for the repair cost',
|
description: 'Plane is not grounded (flying or already repairing), or cash is insufficient for the repair cost',
|
||||||
|
content: { 'application/json': { schema: { $ref: '#/components/schemas/Error' } } },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// v0.71.0 — admin panel: session auth + generic whole-database CRUD behind the admin flag.
|
||||||
|
'/api/login': {
|
||||||
|
post: {
|
||||||
|
summary: 'Log in',
|
||||||
|
description:
|
||||||
|
'Verify username/password (scrypt) and mint a 7-day session. The client stores the returned sessionId in localStorage and sends it as the X-Flight-Session header on later requests. An unknown username still runs one full scrypt against a fixed dummy digest, so timing stays uniform.',
|
||||||
|
operationId: 'login',
|
||||||
|
requestBody: {
|
||||||
|
required: true,
|
||||||
|
content: {
|
||||||
|
'application/json': {
|
||||||
|
schema: { $ref: '#/components/schemas/LoginRequest' },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
responses: {
|
||||||
|
200: {
|
||||||
|
description: 'Authenticated — new session id + the user',
|
||||||
|
content: { 'application/json': { schema: { $ref: '#/components/schemas/LoginResponse' } } },
|
||||||
|
},
|
||||||
|
400: {
|
||||||
|
description: 'Invalid body (not an object, unknown field, or missing/non-string username/password)',
|
||||||
|
content: { 'application/json': { schema: { $ref: '#/components/schemas/Error' } } },
|
||||||
|
},
|
||||||
|
401: {
|
||||||
|
description: 'Unknown username or wrong password',
|
||||||
|
content: { 'application/json': { schema: { $ref: '#/components/schemas/Error' } } },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'/api/logout': {
|
||||||
|
post: {
|
||||||
|
summary: 'Log out',
|
||||||
|
description:
|
||||||
|
'Delete the session named by the X-Flight-Session header (no body). Idempotent — deleting an unknown or already-deleted session is still 200.',
|
||||||
|
operationId: 'logout',
|
||||||
|
responses: {
|
||||||
|
200: {
|
||||||
|
description: 'Session deleted (or was already gone)',
|
||||||
|
content: { 'application/json': { schema: { $ref: '#/components/schemas/OkResponse' } } },
|
||||||
|
},
|
||||||
|
401: {
|
||||||
|
description: 'Missing X-Flight-Session header',
|
||||||
|
content: { 'application/json': { schema: { $ref: '#/components/schemas/Error' } } },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'/api/me': {
|
||||||
|
get: {
|
||||||
|
summary: 'Current user',
|
||||||
|
description:
|
||||||
|
'Resolve the X-Flight-Session header to its user, or 401 when the session is missing/unknown/expired. The client uses it to decide what the Admin modal shows on open.',
|
||||||
|
operationId: 'getMe',
|
||||||
|
responses: {
|
||||||
|
200: {
|
||||||
|
description: 'The authenticated user',
|
||||||
|
content: { 'application/json': { schema: { $ref: '#/components/schemas/SessionUser' } } },
|
||||||
|
},
|
||||||
|
401: {
|
||||||
|
description: 'Missing, unknown or expired session',
|
||||||
|
content: { 'application/json': { schema: { $ref: '#/components/schemas/Error' } } },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'/api/admin/tables': {
|
||||||
|
get: {
|
||||||
|
summary: 'List database tables (admin)',
|
||||||
|
description:
|
||||||
|
'Every user table as [{ name }] in name order, excluding SQLite internals. Requires a valid X-Flight-Session of an ADMIN user — 401 without a live session, 403 for non-admins.',
|
||||||
|
operationId: 'listAdminTables',
|
||||||
|
responses: {
|
||||||
|
200: {
|
||||||
|
description: 'The table names',
|
||||||
|
content: {
|
||||||
|
'application/json': {
|
||||||
|
schema: { type: 'array', items: { $ref: '#/components/schemas/AdminTable' } },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
401: {
|
||||||
|
description: 'Missing, unknown or expired session',
|
||||||
|
content: { 'application/json': { schema: { $ref: '#/components/schemas/Error' } } },
|
||||||
|
},
|
||||||
|
403: {
|
||||||
|
description: 'Valid session but the user is not an admin',
|
||||||
|
content: { 'application/json': { schema: { $ref: '#/components/schemas/Error' } } },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'/api/admin/tables/{name}/rows': {
|
||||||
|
get: {
|
||||||
|
summary: 'Read table rows (admin)',
|
||||||
|
description:
|
||||||
|
'Column headers + up to `limit` rows of the named table (default 500, cap 1000). rowid is exposed as __rowid so the PK-less tables (sim_state) are editable like any other. Table names are validated against sqlite_master and values are always bound as parameters.',
|
||||||
|
operationId: 'listAdminRows',
|
||||||
|
parameters: [
|
||||||
|
{ name: 'name', in: 'path', required: true, schema: { type: 'string' } },
|
||||||
|
{ name: 'limit', in: 'query', required: false, schema: { type: 'integer', minimum: 1, maximum: 1000 } },
|
||||||
|
],
|
||||||
|
responses: {
|
||||||
|
200: {
|
||||||
|
description: 'Column headers + rows (each row carries its __rowid)',
|
||||||
|
content: { 'application/json': { schema: { $ref: '#/components/schemas/AdminRowsResponse' } } },
|
||||||
|
},
|
||||||
|
400: {
|
||||||
|
description: 'limit is not a positive integer',
|
||||||
|
content: { 'application/json': { schema: { $ref: '#/components/schemas/Error' } } },
|
||||||
|
},
|
||||||
|
401: {
|
||||||
|
description: 'Missing, unknown or expired session',
|
||||||
|
content: { 'application/json': { schema: { $ref: '#/components/schemas/Error' } } },
|
||||||
|
},
|
||||||
|
403: {
|
||||||
|
description: 'Valid session but the user is not an admin',
|
||||||
|
content: { 'application/json': { schema: { $ref: '#/components/schemas/Error' } } },
|
||||||
|
},
|
||||||
|
404: {
|
||||||
|
description: 'Unknown table name',
|
||||||
|
content: { 'application/json': { schema: { $ref: '#/components/schemas/Error' } } },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
put: {
|
||||||
|
summary: 'Update a row (admin)',
|
||||||
|
description:
|
||||||
|
'Body { rowid, values }: update only the given columns of that row. Column names are validated against PRAGMA table_info; values are always bound as parameters.',
|
||||||
|
operationId: 'updateAdminRow',
|
||||||
|
parameters: [{ name: 'name', in: 'path', required: true, schema: { type: 'string' } }],
|
||||||
|
requestBody: {
|
||||||
|
required: true,
|
||||||
|
content: {
|
||||||
|
'application/json': {
|
||||||
|
schema: { $ref: '#/components/schemas/UpdateRowRequest' },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
responses: {
|
||||||
|
200: {
|
||||||
|
description: 'Updated',
|
||||||
|
content: { 'application/json': { schema: { $ref: '#/components/schemas/OkResponse' } } },
|
||||||
|
},
|
||||||
|
400: {
|
||||||
|
description: 'Invalid body, non-integer rowid, unknown column, or empty values',
|
||||||
|
content: { 'application/json': { schema: { $ref: '#/components/schemas/Error' } } },
|
||||||
|
},
|
||||||
|
401: {
|
||||||
|
description: 'Missing, unknown or expired session',
|
||||||
|
content: { 'application/json': { schema: { $ref: '#/components/schemas/Error' } } },
|
||||||
|
},
|
||||||
|
403: {
|
||||||
|
description: 'Valid session but the user is not an admin',
|
||||||
|
content: { 'application/json': { schema: { $ref: '#/components/schemas/Error' } } },
|
||||||
|
},
|
||||||
|
404: {
|
||||||
|
description: 'Unknown table name',
|
||||||
|
content: { 'application/json': { schema: { $ref: '#/components/schemas/Error' } } },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
post: {
|
||||||
|
summary: 'Insert a row (admin)',
|
||||||
|
description:
|
||||||
|
'Body { values }: insert a new row with exactly the given columns (others take their defaults or NULL). Returns the new rowid.',
|
||||||
|
operationId: 'insertAdminRow',
|
||||||
|
parameters: [{ name: 'name', in: 'path', required: true, schema: { type: 'string' } }],
|
||||||
|
requestBody: {
|
||||||
|
required: true,
|
||||||
|
content: {
|
||||||
|
'application/json': {
|
||||||
|
schema: { $ref: '#/components/schemas/InsertRowRequest' },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
responses: {
|
||||||
|
200: {
|
||||||
|
description: 'Inserted — the new rowid',
|
||||||
|
content: { 'application/json': { schema: { $ref: '#/components/schemas/InsertRowResponse' } } },
|
||||||
|
},
|
||||||
|
400: {
|
||||||
|
description: 'Invalid body, unknown column, or empty values',
|
||||||
|
content: { 'application/json': { schema: { $ref: '#/components/schemas/Error' } } },
|
||||||
|
},
|
||||||
|
401: {
|
||||||
|
description: 'Missing, unknown or expired session',
|
||||||
|
content: { 'application/json': { schema: { $ref: '#/components/schemas/Error' } } },
|
||||||
|
},
|
||||||
|
403: {
|
||||||
|
description: 'Valid session but the user is not an admin',
|
||||||
|
content: { 'application/json': { schema: { $ref: '#/components/schemas/Error' } } },
|
||||||
|
},
|
||||||
|
404: {
|
||||||
|
description: 'Unknown table name',
|
||||||
|
content: { 'application/json': { schema: { $ref: '#/components/schemas/Error' } } },
|
||||||
|
},
|
||||||
|
409: {
|
||||||
|
description: 'Database constraint violation (NOT NULL / UNIQUE)',
|
||||||
|
content: { 'application/json': { schema: { $ref: '#/components/schemas/Error' } } },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
delete: {
|
||||||
|
summary: 'Delete a row (admin)',
|
||||||
|
description:
|
||||||
|
'Query parameter rowid=N deletes that one row. Idempotent — deleting a non-existent rowid is still 200.',
|
||||||
|
operationId: 'deleteAdminRow',
|
||||||
|
parameters: [
|
||||||
|
{ name: 'name', in: 'path', required: true, schema: { type: 'string' } },
|
||||||
|
{ name: 'rowid', in: 'query', required: true, schema: { type: 'integer' } },
|
||||||
|
],
|
||||||
|
responses: {
|
||||||
|
200: {
|
||||||
|
description: 'Deleted (or was already gone)',
|
||||||
|
content: { 'application/json': { schema: { $ref: '#/components/schemas/OkResponse' } } },
|
||||||
|
},
|
||||||
|
400: {
|
||||||
|
description: 'Missing or non-integer rowid query parameter',
|
||||||
|
content: { 'application/json': { schema: { $ref: '#/components/schemas/Error' } } },
|
||||||
|
},
|
||||||
|
401: {
|
||||||
|
description: 'Missing, unknown or expired session',
|
||||||
|
content: { 'application/json': { schema: { $ref: '#/components/schemas/Error' } } },
|
||||||
|
},
|
||||||
|
403: {
|
||||||
|
description: 'Valid session but the user is not an admin',
|
||||||
|
content: { 'application/json': { schema: { $ref: '#/components/schemas/Error' } } },
|
||||||
|
},
|
||||||
|
404: {
|
||||||
|
description: 'Unknown table name',
|
||||||
content: { 'application/json': { schema: { $ref: '#/components/schemas/Error' } } },
|
content: { 'application/json': { schema: { $ref: '#/components/schemas/Error' } } },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -521,6 +733,92 @@ export const openApiSpec = {
|
|||||||
},
|
},
|
||||||
required: ['planeId'],
|
required: ['planeId'],
|
||||||
},
|
},
|
||||||
|
// v0.71.0 — admin panel auth + DB tooling schemas.
|
||||||
|
LoginRequest: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
username: { type: 'string', description: 'Account username (non-empty).' },
|
||||||
|
password: { type: 'string', description: 'Plaintext password — verified server-side with scrypt, never stored.' },
|
||||||
|
},
|
||||||
|
required: ['username', 'password'],
|
||||||
|
},
|
||||||
|
SessionUser: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
username: { type: 'string' },
|
||||||
|
admin: { type: 'boolean', description: 'Whether this account may use the /api/admin/* endpoints.' },
|
||||||
|
},
|
||||||
|
required: ['username', 'admin'],
|
||||||
|
},
|
||||||
|
LoginResponse: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
sessionId: { type: 'string', description: 'Opaque session id — store it and send it back as the X-Flight-Session header. Valid 7 days.' },
|
||||||
|
user: { $ref: '#/components/schemas/SessionUser' },
|
||||||
|
},
|
||||||
|
required: ['sessionId', 'user'],
|
||||||
|
},
|
||||||
|
OkResponse: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
ok: { const: true },
|
||||||
|
},
|
||||||
|
required: ['ok'],
|
||||||
|
},
|
||||||
|
AdminTable: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
name: { type: 'string', description: 'SQLite table name (sqlite_% internals excluded).' },
|
||||||
|
},
|
||||||
|
required: ['name'],
|
||||||
|
},
|
||||||
|
AdminRowsResponse: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
columns: {
|
||||||
|
type: 'array',
|
||||||
|
items: { type: 'string' },
|
||||||
|
description: 'Column names; the first entry is always __rowid (the rowid pseudo-column).',
|
||||||
|
},
|
||||||
|
rows: {
|
||||||
|
type: 'array',
|
||||||
|
items: { type: 'object', additionalProperties: true },
|
||||||
|
description: 'Up to `limit` rows, each keyed by column name including __rowid.',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
required: ['columns', 'rows'],
|
||||||
|
},
|
||||||
|
UpdateRowRequest: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
rowid: { type: 'integer', description: 'The __rowid of the row to update.' },
|
||||||
|
values: {
|
||||||
|
type: 'object',
|
||||||
|
additionalProperties: true,
|
||||||
|
description: 'Only the columns to change (validated against PRAGMA table_info); others are untouched.',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
required: ['rowid', 'values'],
|
||||||
|
},
|
||||||
|
InsertRowRequest: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
values: {
|
||||||
|
type: 'object',
|
||||||
|
additionalProperties: true,
|
||||||
|
description: 'Exactly the columns to set; others take their defaults or NULL.',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
required: ['values'],
|
||||||
|
},
|
||||||
|
InsertRowResponse: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
ok: { const: true },
|
||||||
|
rowid: { type: 'integer', description: 'The __rowid of the inserted row.' },
|
||||||
|
},
|
||||||
|
required: ['ok', 'rowid'],
|
||||||
|
},
|
||||||
Error: {
|
Error: {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: {
|
properties: {
|
||||||
@@ -604,8 +902,7 @@ export const openApiSpec = {
|
|||||||
deadlineSimTime: { type: 'integer', description: 'Sim-clock epoch ms (game time)' },
|
deadlineSimTime: { type: 'integer', description: 'Sim-clock epoch ms (game time)' },
|
||||||
// 'expired' = an open OR loaded package whose deadline passed on a tick;
|
// 'expired' = an open OR loaded package whose deadline passed on a tick;
|
||||||
// loaded expired packages keep their slot, deliver no reward, abandon free.
|
// loaded expired packages keep their slot, deliver no reward, abandon free.
|
||||||
// 'ignored' (v0.29.0, ISS-047 part B) = a dismissed open job — terminal, leaves the market.
|
status: { enum: ['open', 'loaded', 'delivered', 'expired', 'abandoned'] },
|
||||||
status: { enum: ['open', 'loaded', 'delivered', 'expired', 'abandoned', 'ignored'] },
|
|
||||||
planeId: { type: ['string', 'null'] },
|
planeId: { type: ['string', 'null'] },
|
||||||
createdSimTime: { type: 'integer' },
|
createdSimTime: { type: 'integer' },
|
||||||
expiresRealMs: { type: ['integer', 'null'], description: 'Wall-clock epoch ms when an OPEN job expires (v0.65.0) — createdRealMs + lifetime; null for every non-open status.' },
|
expiresRealMs: { type: ['integer', 'null'], description: 'Wall-clock epoch ms when an OPEN job expires (v0.65.0) — createdRealMs + lifetime; null for every non-open status.' },
|
||||||
|
|||||||
+34
-35
@@ -5,6 +5,7 @@ import { eq } from 'drizzle-orm';
|
|||||||
import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest';
|
import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest';
|
||||||
import { openGameDb } from '@/lib/db/client';
|
import { openGameDb } from '@/lib/db/client';
|
||||||
import * as schema from '@/lib/db/schema';
|
import * as schema from '@/lib/db/schema';
|
||||||
|
import { getLocalPlayer, updateLocalPlayerEconomy } from '@/lib/db/localPlayer';
|
||||||
import { loadAirportsGeoJson } from '@/lib/airports';
|
import { loadAirportsGeoJson } from '@/lib/airports';
|
||||||
import { haversineKm, initialBearingDeg } from '@/lib/geo';
|
import { haversineKm, initialBearingDeg } from '@/lib/geo';
|
||||||
import { weatherFor } from '@/lib/weather';
|
import { weatherFor } from '@/lib/weather';
|
||||||
@@ -152,7 +153,6 @@ describe('expireLoadedPackages (sim clock)', () => {
|
|||||||
{ id: 'p-loaded-future', originIcao: 'EDDF', destIcao: 'LEMD', reward: 1, cargoType: 'Mail', cargoCount: 1, deadlineSimTime: clock + 1, status: 'loaded', planeId: 'plane-starter', createdSimTime: STARTING_CLOCK_MS },
|
{ id: 'p-loaded-future', originIcao: 'EDDF', destIcao: 'LEMD', reward: 1, cargoType: 'Mail', cargoCount: 1, deadlineSimTime: clock + 1, status: 'loaded', planeId: 'plane-starter', createdSimTime: STARTING_CLOCK_MS },
|
||||||
{ id: 'p-delivered-past', originIcao: 'EDDF', destIcao: 'LEMD', reward: 1, cargoType: 'Mail', cargoCount: 1, deadlineSimTime: clock - 1, status: 'delivered', planeId: null, createdSimTime: STARTING_CLOCK_MS },
|
{ id: 'p-delivered-past', originIcao: 'EDDF', destIcao: 'LEMD', reward: 1, cargoType: 'Mail', cargoCount: 1, deadlineSimTime: clock - 1, status: 'delivered', planeId: null, createdSimTime: STARTING_CLOCK_MS },
|
||||||
{ id: 'p-abandoned-past', originIcao: 'EDDF', destIcao: 'LEMD', reward: 1, cargoType: 'Mail', cargoCount: 1, deadlineSimTime: clock - 1, status: 'abandoned', planeId: null, createdSimTime: STARTING_CLOCK_MS },
|
{ id: 'p-abandoned-past', originIcao: 'EDDF', destIcao: 'LEMD', reward: 1, cargoType: 'Mail', cargoCount: 1, deadlineSimTime: clock - 1, status: 'abandoned', planeId: null, createdSimTime: STARTING_CLOCK_MS },
|
||||||
{ id: 'p-ignored-past', originIcao: 'EDDF', destIcao: 'LEMD', reward: 1, cargoType: 'Mail', cargoCount: 1, deadlineSimTime: clock - 1, status: 'ignored', planeId: null, createdSimTime: STARTING_CLOCK_MS },
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const n = await expireLoadedPackages(inst, clock);
|
const n = await expireLoadedPackages(inst, clock);
|
||||||
@@ -163,7 +163,6 @@ describe('expireLoadedPackages (sim clock)', () => {
|
|||||||
expect(byId.get('p-loaded-future')).toBe('loaded'); // deadline not reached yet
|
expect(byId.get('p-loaded-future')).toBe('loaded'); // deadline not reached yet
|
||||||
expect(byId.get('p-delivered-past')).toBe('delivered'); // terminal — never flips
|
expect(byId.get('p-delivered-past')).toBe('delivered'); // terminal — never flips
|
||||||
expect(byId.get('p-abandoned-past')).toBe('abandoned'); // terminal — never flips
|
expect(byId.get('p-abandoned-past')).toBe('abandoned'); // terminal — never flips
|
||||||
expect(byId.get('p-ignored-past')).toBe('ignored'); // v0.29.0 (ISS-047 part B) — terminal, never flips
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('a deadline exactly at the clock counts as expired', async () => {
|
it('a deadline exactly at the clock counts as expired', async () => {
|
||||||
@@ -230,20 +229,20 @@ describe('deliverPackages (v0.12.0 arrival delivery)', () => {
|
|||||||
|
|
||||||
it('does nothing before the arrival time', async () => {
|
it('does nothing before the arrival time', async () => {
|
||||||
const { inst, km, type } = await setupFlight('deliver-early.db');
|
const { inst, km, type } = await setupFlight('deliver-early.db');
|
||||||
const accountBefore = (await inst.db.select().from(schema.account))[0]!;
|
const playerBefore = (await getLocalPlayer(inst));
|
||||||
|
|
||||||
const clock = T0 + travelMs(km, type.speedKmh) - 1; // one ms before arrival
|
const clock = T0 + travelMs(km, type.speedKmh) - 1; // one ms before arrival
|
||||||
expect(await deliverPackages(inst, clock)).toBe(0);
|
expect(await deliverPackages(inst, clock)).toBe(0);
|
||||||
|
|
||||||
const plane = (await inst.db.select().from(schema.planes))[0];
|
const plane = (await inst.db.select().from(schema.planes))[0];
|
||||||
const account = (await inst.db.select().from(schema.account))[0]!;
|
const player = (await getLocalPlayer(inst));
|
||||||
expect(plane.status).toBe('flying');
|
expect(plane.status).toBe('flying');
|
||||||
expect(account.cash).toBe(accountBefore.cash); // no award before landing
|
expect(player.cash).toBe(playerBefore.cash); // no award before landing
|
||||||
});
|
});
|
||||||
|
|
||||||
it('delivers in-deadline cargo, unbinds expired cargo for free, keeps other-dest cargo bound', async () => {
|
it('delivers in-deadline cargo, unbinds expired cargo for free, keeps other-dest cargo bound', async () => {
|
||||||
const { inst, from, to, km, type } = await setupFlight('deliver-mixed.db');
|
const { inst, from, to, km, type } = await setupFlight('deliver-mixed.db');
|
||||||
const accountBefore = (await inst.db.select().from(schema.account))[0]!;
|
const playerBefore = (await getLocalPlayer(inst));
|
||||||
|
|
||||||
// Three packages on the plane: one in-deadline for TO, one expired for TO,
|
// Three packages on the plane: one in-deadline for TO, one expired for TO,
|
||||||
// one loaded for a DIFFERENT airport (stays bound for a later leg).
|
// one loaded for a DIFFERENT airport (stays bound for a later leg).
|
||||||
@@ -276,23 +275,23 @@ describe('deliverPackages (v0.12.0 arrival delivery)', () => {
|
|||||||
expect(byId.get('p-elsewhere')!.status).toBe('loaded'); // not this airport's cargo…
|
expect(byId.get('p-elsewhere')!.status).toBe('loaded'); // not this airport's cargo…
|
||||||
expect(byId.get('p-elsewhere')!.planeId).toBe('plane-starter'); // …stays bound for the next leg
|
expect(byId.get('p-elsewhere')!.planeId).toBe('plane-starter'); // …stays bound for the next leg
|
||||||
|
|
||||||
const account = (await inst.db.select().from(schema.account))[0]!;
|
const player = (await getLocalPlayer(inst));
|
||||||
expect(account.cash).toBeCloseTo(accountBefore.cash + 5_000, 9); // ONLY p-pay paid out
|
expect(player.cash).toBeCloseTo(playerBefore.cash + 5_000, 9); // ONLY p-pay paid out
|
||||||
expect(account.reputation).toBeCloseTo(
|
expect(player.reputation).toBeCloseTo(
|
||||||
Math.round((accountBefore.reputation + reputationGainFor(km)) * 100) / 100,
|
Math.round((playerBefore.reputation + reputationGainFor(km)) * 100) / 100,
|
||||||
9,
|
9,
|
||||||
);
|
);
|
||||||
|
|
||||||
// A later tick must not award again — the plane is no longer 'flying'.
|
// A later tick must not award again — the plane is no longer 'flying'.
|
||||||
expect(await deliverPackages(inst, clock + 3_600_000)).toBe(0);
|
expect(await deliverPackages(inst, clock + 3_600_000)).toBe(0);
|
||||||
const accountAfter = (await inst.db.select().from(schema.account))[0]!;
|
const playerAfter = (await getLocalPlayer(inst));
|
||||||
expect(accountAfter.cash).toBe(account.cash);
|
expect(playerAfter.cash).toBe(player.cash);
|
||||||
expect(accountAfter.reputation).toBe(account.reputation);
|
expect(playerAfter.reputation).toBe(player.reputation);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('delivers every in-deadline package for the arrival airport with per-package rewards', async () => {
|
it('delivers every in-deadline package for the arrival airport with per-package rewards', async () => {
|
||||||
const { inst, km } = await setupFlight('deliver-multi.db');
|
const { inst, km } = await setupFlight('deliver-multi.db');
|
||||||
const accountBefore = (await inst.db.select().from(schema.account))[0]!;
|
const playerBefore = (await getLocalPlayer(inst));
|
||||||
|
|
||||||
await inst.db.insert(schema.packages).values([
|
await inst.db.insert(schema.packages).values([
|
||||||
{ id: 'p-a', originIcao: FROM, destIcao: TO, reward: 1_000, cargoType: 'Mail', cargoCount: 1, deadlineSimTime: T0 + 24 * 3_600_000, status: 'loaded', planeId: 'plane-starter', createdSimTime: T0 },
|
{ id: 'p-a', originIcao: FROM, destIcao: TO, reward: 1_000, cargoType: 'Mail', cargoCount: 1, deadlineSimTime: T0 + 24 * 3_600_000, status: 'loaded', planeId: 'plane-starter', createdSimTime: T0 },
|
||||||
@@ -302,17 +301,17 @@ describe('deliverPackages (v0.12.0 arrival delivery)', () => {
|
|||||||
const clock = T0 + travelMs(km, PLANE_TYPES.atr72.speedKmh);
|
const clock = T0 + travelMs(km, PLANE_TYPES.atr72.speedKmh);
|
||||||
expect(await deliverPackages(inst, clock)).toBe(1);
|
expect(await deliverPackages(inst, clock)).toBe(1);
|
||||||
|
|
||||||
const account = (await inst.db.select().from(schema.account))[0]!;
|
const player = (await getLocalPlayer(inst));
|
||||||
expect(account.cash).toBeCloseTo(accountBefore.cash + 3_500, 9); // both rewards
|
expect(player.cash).toBeCloseTo(playerBefore.cash + 3_500, 9); // both rewards
|
||||||
expect(account.reputation).toBeCloseTo(
|
expect(player.reputation).toBeCloseTo(
|
||||||
Math.round((accountBefore.reputation + reputationGainFor(km) * 2) * 100) / 100,
|
Math.round((playerBefore.reputation + reputationGainFor(km) * 2) * 100) / 100,
|
||||||
9,
|
9,
|
||||||
); // rep per delivered package
|
); // rep per delivered package
|
||||||
});
|
});
|
||||||
|
|
||||||
it('adds the registry rep bonus for a special package at delivery (v0.37.0)', async () => {
|
it('adds the registry rep bonus for a special package at delivery (v0.37.0)', async () => {
|
||||||
const { inst, km } = await setupFlight('deliver-special.db');
|
const { inst, km } = await setupFlight('deliver-special.db');
|
||||||
const accountBefore = (await inst.db.select().from(schema.account))[0]!;
|
const playerBefore = (await getLocalPlayer(inst));
|
||||||
|
|
||||||
await inst.db.insert(schema.packages).values([
|
await inst.db.insert(schema.packages).values([
|
||||||
{ id: 'p-prio', originIcao: FROM, destIcao: TO, reward: 5_000, cargoType: 'Mail', cargoCount: 10, special: 'priority', deadlineSimTime: T0 + 24 * 3_600_000, status: 'loaded', planeId: 'plane-starter', createdSimTime: T0 },
|
{ id: 'p-prio', originIcao: FROM, destIcao: TO, reward: 5_000, cargoType: 'Mail', cargoCount: 10, special: 'priority', deadlineSimTime: T0 + 24 * 3_600_000, status: 'loaded', planeId: 'plane-starter', createdSimTime: T0 },
|
||||||
@@ -321,11 +320,11 @@ describe('deliverPackages (v0.12.0 arrival delivery)', () => {
|
|||||||
const clock = T0 + travelMs(km, PLANE_TYPES.atr72.speedKmh); // exactly at arrival
|
const clock = T0 + travelMs(km, PLANE_TYPES.atr72.speedKmh); // exactly at arrival
|
||||||
expect(await deliverPackages(inst, clock)).toBe(1);
|
expect(await deliverPackages(inst, clock)).toBe(1);
|
||||||
|
|
||||||
const account = (await inst.db.select().from(schema.account))[0]!;
|
const player = (await getLocalPlayer(inst));
|
||||||
expect(account.cash).toBeCloseTo(accountBefore.cash + 5_000, 9);
|
expect(player.cash).toBeCloseTo(playerBefore.cash + 5_000, 9);
|
||||||
// Distance-based gain + the registry rep bonus — double-rounded like every other award.
|
// Distance-based gain + the registry rep bonus — double-rounded like every other award.
|
||||||
expect(account.reputation).toBeCloseTo(
|
expect(player.reputation).toBeCloseTo(
|
||||||
Math.round((accountBefore.reputation + reputationGainFor(km) + SPECIALS.priority.repBonus) * 100) / 100,
|
Math.round((playerBefore.reputation + reputationGainFor(km) + SPECIALS.priority.repBonus) * 100) / 100,
|
||||||
9,
|
9,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -383,7 +382,7 @@ describe('deliverPackages (v0.12.0 arrival delivery)', () => {
|
|||||||
.set({ fuel: depFuel, queue: JSON.stringify(['EHAM']) })
|
.set({ fuel: depFuel, queue: JSON.stringify(['EHAM']) })
|
||||||
.where(eq(schema.planes.id, 'plane-starter'));
|
.where(eq(schema.planes.id, 'plane-starter'));
|
||||||
|
|
||||||
const accountBefore = (await inst.db.select().from(schema.account))[0]!; // seeded €20k — the top-up is affordable
|
const playerBefore = (await getLocalPlayer(inst)); // seeded €20k — the top-up is affordable
|
||||||
const clock = T0 + travelMs(km, type.speedKmh); // exactly at arrival
|
const clock = T0 + travelMs(km, type.speedKmh); // exactly at arrival
|
||||||
expect(await deliverPackages(inst, clock)).toBe(1);
|
expect(await deliverPackages(inst, clock)).toBe(1);
|
||||||
|
|
||||||
@@ -404,7 +403,7 @@ describe('deliverPackages (v0.12.0 arrival delivery)', () => {
|
|||||||
const target = Math.min(type.maxFuel, Math.max(landedFuel, nextRequiredL * 1.5));
|
const target = Math.min(type.maxFuel, Math.max(landedFuel, nextRequiredL * 1.5));
|
||||||
const liters = Math.max(0, target - landedFuel);
|
const liters = Math.max(0, target - landedFuel);
|
||||||
expect(liters).toBeGreaterThan(0); // the hop genuinely needs more than what's left
|
expect(liters).toBeGreaterThan(0); // the hop genuinely needs more than what's left
|
||||||
const rate = repRate(accountBefore.reputation, FUEL_DISCOUNT_PER_REP, MAX_FUEL_DISCOUNT);
|
const rate = repRate(playerBefore.reputation, FUEL_DISCOUNT_PER_REP, MAX_FUEL_DISCOUNT);
|
||||||
const expectedCost = Math.round(liters * FUEL_PRICE_PER_L * (1 - rate) * 100) / 100;
|
const expectedCost = Math.round(liters * FUEL_PRICE_PER_L * (1 - rate) * 100) / 100;
|
||||||
|
|
||||||
const plane = (await inst.db.select().from(schema.planes))[0];
|
const plane = (await inst.db.select().from(schema.planes))[0];
|
||||||
@@ -414,21 +413,21 @@ describe('deliverPackages (v0.12.0 arrival delivery)', () => {
|
|||||||
expect(JSON.parse(plane.queue)).toEqual([]); // …leg consumed, rest kept in order
|
expect(JSON.parse(plane.queue)).toEqual([]); // …leg consumed, rest kept in order
|
||||||
expect(plane.fuel).toBeCloseTo(target, 6); // …departing with the post-top-up level
|
expect(plane.fuel).toBeCloseTo(target, 6); // …departing with the post-top-up level
|
||||||
|
|
||||||
const account = (await inst.db.select().from(schema.account))[0]!;
|
const player = (await getLocalPlayer(inst));
|
||||||
expect(account.cash).toBeCloseTo(accountBefore.cash - expectedCost, 9); // exactly the rep-discounted cost
|
expect(player.cash).toBeCloseTo(playerBefore.cash - expectedCost, 9); // exactly the rep-discounted cost
|
||||||
});
|
});
|
||||||
|
|
||||||
it('grounds with the queue intact when cash cannot cover the auto top-up (ISS-082)', async () => {
|
it('grounds with the queue intact when cash cannot cover the auto top-up (ISS-082)', async () => {
|
||||||
const { inst, from, to, km, type } = await setupFlight('chain-nofuel-poor.db');
|
const { inst, from, to, km, type } = await setupFlight('chain-nofuel-poor.db');
|
||||||
|
|
||||||
// Same empty-tank landing as above, but the account is broke — the top-up is unaffordable.
|
// Same empty-tank landing as above, but the player is broke — the top-up is unaffordable.
|
||||||
const w = weatherFor(FROM);
|
const w = weatherFor(FROM);
|
||||||
const f = windBurnFactor(w.windKt, w.windDirDeg, initialBearingDeg(from.lat, from.lon, to.lat, to.lon));
|
const f = windBurnFactor(w.windKt, w.windDirDeg, initialBearingDeg(from.lat, from.lon, to.lat, to.lon));
|
||||||
const depFuel = requiredFuelFor(type.burnPerKm * f, type.emptyWeightKg, type.maxFuel, km);
|
const depFuel = requiredFuelFor(type.burnPerKm * f, type.emptyWeightKg, type.maxFuel, km);
|
||||||
await inst.db.update(schema.planes)
|
await inst.db.update(schema.planes)
|
||||||
.set({ fuel: depFuel, queue: JSON.stringify(['EHAM']) })
|
.set({ fuel: depFuel, queue: JSON.stringify(['EHAM']) })
|
||||||
.where(eq(schema.planes.id, 'plane-starter'));
|
.where(eq(schema.planes.id, 'plane-starter'));
|
||||||
await inst.db.update(schema.account).set({ cash: 0 });
|
await updateLocalPlayerEconomy(inst, { cash: 0 });
|
||||||
|
|
||||||
const clock = T0 + travelMs(km, type.speedKmh); // exactly at arrival
|
const clock = T0 + travelMs(km, type.speedKmh); // exactly at arrival
|
||||||
expect(await deliverPackages(inst, clock)).toBe(1);
|
expect(await deliverPackages(inst, clock)).toBe(1);
|
||||||
@@ -440,7 +439,7 @@ describe('deliverPackages (v0.12.0 arrival delivery)', () => {
|
|||||||
expect(JSON.parse(plane.queue)).toEqual(['EHAM']); // …queue kept for a later dispatch
|
expect(JSON.parse(plane.queue)).toEqual(['EHAM']); // …queue kept for a later dispatch
|
||||||
const landedFuel = fuelAtWeighted(depFuel, type.burnPerKm * f, type.emptyWeightKg, type.maxFuel, km, 1);
|
const landedFuel = fuelAtWeighted(depFuel, type.burnPerKm * f, type.emptyWeightKg, type.maxFuel, km, 1);
|
||||||
expect(plane.fuel).toBeCloseTo(landedFuel, 6); // no top-up happened — the tank is untouched
|
expect(plane.fuel).toBeCloseTo(landedFuel, 6); // no top-up happened — the tank is untouched
|
||||||
expect((await inst.db.select().from(schema.account))[0]!.cash).toBe(0);
|
expect((await getLocalPlayer(inst)).cash).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('grounds as before when the queue is empty', async () => {
|
it('grounds as before when the queue is empty', async () => {
|
||||||
@@ -673,12 +672,12 @@ describe('grounded fleet freezes the world clock (#135)', () => {
|
|||||||
|
|
||||||
it('a frozen tick still refills the pool so a grounded fleet never starves (#135 follow-up)', async () => {
|
it('a frozen tick still refills the pool so a grounded fleet never starves (#135 follow-up)', async () => {
|
||||||
const inst = await freshDb('frozen-topup.db'); // seeded starter is on the ground → frozen
|
const inst = await freshDb('frozen-topup.db'); // seeded starter is on the ground → frozen
|
||||||
// Drain the open market to zero the way repeated ignores would (removal paths run while frozen).
|
// Drain the open market the way wall-clock expiry would (removal paths run while frozen).
|
||||||
// Direct status flip WITHOUT slotFreeAtRealMs: models "slots are empty", not "taken" — a real
|
// Direct status flip WITHOUT slotFreeAtRealMs, mirroring expireOpenPackages: models "slots are
|
||||||
// ignore stamps the cooldown and would block this refill for REFILL_DELAY_MS.
|
// empty", not "taken" — a real load stamps the cooldown and would block this refill for REFILL_DELAY_MS.
|
||||||
for (const p of await inst.db.select().from(schema.packages)) {
|
for (const p of await inst.db.select().from(schema.packages)) {
|
||||||
if (p.status === 'open') {
|
if (p.status === 'open') {
|
||||||
await inst.db.update(schema.packages).set({ status: 'ignored' }).where(eq(schema.packages.id, p.id));
|
await inst.db.update(schema.packages).set({ status: 'expired' }).where(eq(schema.packages.id, p.id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -807,7 +806,7 @@ describe('spawnPoolPackages (v0.65.0 per-airport pools)', () => {
|
|||||||
const small = all.find((p) => p.status === 'open' && poolBandOf(p.weightKg) === 0)!;
|
const small = all.find((p) => p.status === 'open' && poolBandOf(p.weightKg) === 0)!;
|
||||||
const heavy = all.find((p) => p.status === 'open' && poolBandOf(p.weightKg) >= 2)!;
|
const heavy = all.find((p) => p.status === 'open' && poolBandOf(p.weightKg) >= 2)!;
|
||||||
await inst.db.update(schema.packages).set({ status: 'loaded', planeId: 'plane-starter', slotFreeAtRealMs: T0 }).where(eq(schema.packages.id, small.id));
|
await inst.db.update(schema.packages).set({ status: 'loaded', planeId: 'plane-starter', slotFreeAtRealMs: T0 }).where(eq(schema.packages.id, small.id));
|
||||||
await inst.db.update(schema.packages).set({ status: 'ignored', slotFreeAtRealMs: T0 }).where(eq(schema.packages.id, heavy.id));
|
await inst.db.update(schema.packages).set({ status: 'loaded', planeId: 'plane-starter', slotFreeAtRealMs: T0 }).where(eq(schema.packages.id, heavy.id));
|
||||||
|
|
||||||
// While the cooldown runs (real = T0), nothing refills — even though two slots are empty.
|
// While the cooldown runs (real = T0), nothing refills — even though two slots are empty.
|
||||||
expect(await spawnPoolPackages(inst, T0 + 5_000, mulberry32(7), T0)).toBe(0);
|
expect(await spawnPoolPackages(inst, T0 + 5_000, mulberry32(7), T0)).toBe(0);
|
||||||
|
|||||||
+21
-19
@@ -1,6 +1,7 @@
|
|||||||
import { randomInt, randomUUID } from 'node:crypto';
|
import { randomInt, randomUUID } from 'node:crypto';
|
||||||
import { eq } from 'drizzle-orm';
|
import { eq, sql } from 'drizzle-orm';
|
||||||
import { getGameDb, persist, type GameDb } from '@/lib/db/client';
|
import { getGameDb, persist, type GameDb } from '@/lib/db/client';
|
||||||
|
import { getLocalPlayer, updateLocalPlayerEconomy } from '@/lib/db/localPlayer';
|
||||||
import * as schema from '@/lib/db/schema';
|
import * as schema from '@/lib/db/schema';
|
||||||
import { loadAirportsGeoJson } from '@/lib/airports';
|
import { loadAirportsGeoJson } from '@/lib/airports';
|
||||||
import { haversineKm, initialBearingDeg } from '@/lib/geo';
|
import { haversineKm, initialBearingDeg } from '@/lib/geo';
|
||||||
@@ -111,7 +112,7 @@ export async function tickOnce(inst: GameDb): Promise<schema.SimStateRow> {
|
|||||||
await finishRepairs(inst, clockMs);
|
await finishRepairs(inst, clockMs);
|
||||||
}
|
}
|
||||||
// v0.65.0: market refresh runs on EVERY tick — frozen ones included (#135 follow-up carried over) —
|
// v0.65.0: market refresh runs on EVERY tick — frozen ones included (#135 follow-up carried over) —
|
||||||
// because while grounded nothing else creates packages but removal paths (ignore) still run; without
|
// because while grounded nothing else creates packages but removal paths (open-job expiry) still run; without
|
||||||
// this a grounded fleet could drain its pools to zero and soft-lock forever. Open jobs age on the
|
// this a grounded fleet could drain its pools to zero and soft-lock forever. Open jobs age on the
|
||||||
// WALL clock (JOB_LIFETIME_MS after createdRealMs), so even a fully paused world refreshes its board;
|
// WALL clock (JOB_LIFETIME_MS after createdRealMs), so even a fully paused world refreshes its board;
|
||||||
// both passes are idempotent no-ops when satisfied, so advancing ticks behave exactly as before.
|
// both passes are idempotent no-ops when satisfied, so advancing ticks behave exactly as before.
|
||||||
@@ -147,9 +148,13 @@ export async function expireLoadedPackages(inst: GameDb, clockMs: number): Promi
|
|||||||
// v0.65.0: open jobs live on the WALL clock — JOB_LIFETIME_MS after createdRealMs they expire
|
// v0.65.0: open jobs live on the WALL clock — JOB_LIFETIME_MS after createdRealMs they expire
|
||||||
// regardless of time scale or fleet state, so a paused/frozen world still refreshes its board. Runs
|
// regardless of time scale or fleet state, so a paused/frozen world still refreshes its board. Runs
|
||||||
// every tick (~1 s), outside the advance gate. An expired job's slot respawns immediately (no
|
// every tick (~1 s), outside the advance gate. An expired job's slot respawns immediately (no
|
||||||
// slotFreeAtRealMs is set — only TAKEN jobs start a refill cooldown). Returns the count flipped.
|
// slotFreeAtRealMs is set — only TAKEN jobs start a refill cooldown). v0.69.0: legacy 'ignored' rows
|
||||||
|
// (pre-v0.69.0 dismissals) are swept in too — each self-heals to 'expired' on the first tick past its
|
||||||
|
// lifetime, and no new ones can ever be created. Returns the count flipped.
|
||||||
export async function expireOpenPackages(inst: GameDb, nowMs: number): Promise<number> {
|
export async function expireOpenPackages(inst: GameDb, nowMs: number): Promise<number> {
|
||||||
const rows = await inst.db.select().from(schema.packages).where(eq(schema.packages.status, 'open'));
|
// Raw SQL on purpose: 'ignored' is no longer in the status enum (v0.69.0) — it only exists as a
|
||||||
|
// legacy value in pre-v0.69.0 databases, so the typed column can't express the query.
|
||||||
|
const rows = await inst.db.select().from(schema.packages).where(sql`${schema.packages.status} IN ('open', 'ignored')`);
|
||||||
let n = 0;
|
let n = 0;
|
||||||
for (const p of rows) {
|
for (const p of rows) {
|
||||||
if (p.createdRealMs + JOB_LIFETIME_MS <= nowMs) {
|
if (p.createdRealMs + JOB_LIFETIME_MS <= nowMs) {
|
||||||
@@ -246,13 +251,12 @@ export async function deliverPackages(inst: GameDb, clockMs: number): Promise<nu
|
|||||||
for (const pk of onBoard) {
|
for (const pk of onBoard) {
|
||||||
if (pk.status === 'loaded' && clockMs <= pk.deadlineSimTime) {
|
if (pk.status === 'loaded' && clockMs <= pk.deadlineSimTime) {
|
||||||
await inst.db.update(schema.packages).set({ status: 'delivered' }).where(eq(schema.packages.id, pk.id));
|
await inst.db.update(schema.packages).set({ status: 'delivered' }).where(eq(schema.packages.id, pk.id));
|
||||||
// Fresh account read per award so multiple deliveries in one tick all count.
|
// Fresh player read per award so multiple deliveries in one tick all count.
|
||||||
const fresh = (await inst.db.select().from(schema.account))[0];
|
const fresh = await getLocalPlayer(inst);
|
||||||
if (!fresh) throw new Error('account row missing');
|
|
||||||
// v0.37.0 (ISS-073): special packages add the registry's flat rep bonus on top of the
|
// v0.37.0 (ISS-073): special packages add the registry's flat rep bonus on top of the
|
||||||
// distance-based gain — same double-rounding convention as before (gain rounded to cents, total re-rounded).
|
// distance-based gain — same double-rounding convention as before (gain rounded to cents, total re-rounded).
|
||||||
const repBonus = pk.special ? SPECIALS[pk.special]?.repBonus ?? 0 : 0;
|
const repBonus = pk.special ? SPECIALS[pk.special]?.repBonus ?? 0 : 0;
|
||||||
await inst.db.update(schema.account).set({
|
await updateLocalPlayerEconomy(inst, {
|
||||||
cash: fresh.cash + pk.reward,
|
cash: fresh.cash + pk.reward,
|
||||||
reputation: Math.round((fresh.reputation + reputationGainFor(distanceKm) + repBonus) * 100) / 100,
|
reputation: Math.round((fresh.reputation + reputationGainFor(distanceKm) + repBonus) * 100) / 100,
|
||||||
});
|
});
|
||||||
@@ -302,15 +306,14 @@ export async function deliverPackages(inst: GameDb, clockMs: number): Promise<nu
|
|||||||
// ISS-082: auto top-up — same target/price terms as flyPlane's dispatch refuel.
|
// ISS-082: auto top-up — same target/price terms as flyPlane's dispatch refuel.
|
||||||
const target = Math.min(type.maxFuel, Math.max(landedFuel, nextRequiredL * 1.5));
|
const target = Math.min(type.maxFuel, Math.max(landedFuel, nextRequiredL * 1.5));
|
||||||
const liters = Math.max(0, target - landedFuel);
|
const liters = Math.max(0, target - landedFuel);
|
||||||
// Fresh account read (same pattern as the delivery awards above) so a top-up in this tick sees current cash.
|
// Fresh player read (same pattern as the delivery awards above) so a top-up in this tick sees current cash.
|
||||||
const fresh = (await inst.db.select().from(schema.account))[0];
|
const fresh = await getLocalPlayer(inst);
|
||||||
if (!fresh) throw new Error('account row missing');
|
|
||||||
const cost = Math.round(liters * FUEL_PRICE_PER_L * (1 - repRate(fresh.reputation, FUEL_DISCOUNT_PER_REP, MAX_FUEL_DISCOUNT)) * 100) / 100;
|
const cost = Math.round(liters * FUEL_PRICE_PER_L * (1 - repRate(fresh.reputation, FUEL_DISCOUNT_PER_REP, MAX_FUEL_DISCOUNT)) * 100) / 100;
|
||||||
if (cost === 0 || fresh.cash >= cost) {
|
if (cost === 0 || fresh.cash >= cost) {
|
||||||
queue.shift();
|
queue.shift();
|
||||||
chainedTo = nextDest;
|
chainedTo = nextDest;
|
||||||
topUpFuel = target;
|
topUpFuel = target;
|
||||||
if (cost > 0) await inst.db.update(schema.account).set({ cash: Math.round((fresh.cash - cost) * 100) / 100 });
|
if (cost > 0) await updateLocalPlayerEconomy(inst, { cash: Math.round((fresh.cash - cost) * 100) / 100 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -352,7 +355,7 @@ export async function deliverPackages(inst: GameDb, clockMs: number): Promise<nu
|
|||||||
// (v0.8.0). Every airport where a plane can take work — grounded there, flying TO it, or queued for
|
// (v0.8.0). Every airport where a plane can take work — grounded there, flying TO it, or queued for
|
||||||
// it (poolAirports in lib/game/state.ts) — keeps the POOL_BANDS composition of open packages: each
|
// it (poolAirports in lib/game/state.ts) — keeps the POOL_BANDS composition of open packages: each
|
||||||
// band is topped back up to its count using generatePoolPackage, so seeded and spawned packages are
|
// band is topped back up to its count using generatePoolPackage, so seeded and spawned packages are
|
||||||
// indistinguishable. A TAKEN slot (loaded/ignored) stays empty for the band's refill delay after
|
// indistinguishable. A TAKEN slot (loaded) stays empty for the band's refill delay after
|
||||||
// slotFreeAtRealMs; expired/delivered/abandoned never block, so an untaken job's slot respawns on
|
// slotFreeAtRealMs; expired/delivered/abandoned never block, so an untaken job's slot respawns on
|
||||||
// the next tick. Orphaned pools (plane left without taking a job) simply expire out — no cleanup.
|
// the next tick. Orphaned pools (plane left without taking a job) simply expire out — no cleanup.
|
||||||
// RNG and wall-clock now are injectable for deterministic tests. Returns the number created.
|
// RNG and wall-clock now are injectable for deterministic tests. Returns the number created.
|
||||||
@@ -379,14 +382,13 @@ export async function spawnPoolPackages(
|
|||||||
lon: f.properties.lon,
|
lon: f.properties.lon,
|
||||||
}));
|
}));
|
||||||
const rand = rng ?? mulberry32(randomInt(0, 2 ** 31));
|
const rand = rng ?? mulberry32(randomInt(0, 2 ** 31));
|
||||||
// v0.38.0 (ISS-072): spawned jobs carry the account's CURRENT reputation quality — read once per spawn batch.
|
// v0.38.0 (ISS-072): spawned jobs carry the local player's CURRENT reputation quality — read once per spawn batch.
|
||||||
const account = (await inst.db.select().from(schema.account))[0];
|
const player = await getLocalPlayer(inst);
|
||||||
if (!account) throw new Error('account row missing');
|
|
||||||
|
|
||||||
let n = 0;
|
let n = 0;
|
||||||
for (const originIcao of pool) {
|
for (const originIcao of pool) {
|
||||||
// Open counts and refill cooldowns per band at this airport. Only open/loaded/ignored rows matter:
|
// Open counts and refill cooldowns per band at this airport. Only open/loaded rows matter:
|
||||||
// terminal statuses never block a slot, and loaded/ignored carry the slotFreeAtRealMs stamp.
|
// terminal statuses never block a slot, and loaded carries the slotFreeAtRealMs stamp.
|
||||||
const openByBand = [0, 0, 0, 0];
|
const openByBand = [0, 0, 0, 0];
|
||||||
let blockedUntil: number | null = null;
|
let blockedUntil: number | null = null;
|
||||||
for (const p of packageRows) {
|
for (const p of packageRows) {
|
||||||
@@ -411,7 +413,7 @@ export async function spawnPoolPackages(
|
|||||||
clockMs,
|
clockMs,
|
||||||
id: randomUUID(),
|
id: randomUUID(),
|
||||||
createdRealMs: real,
|
createdRealMs: real,
|
||||||
reputation: account.reputation,
|
reputation: player.reputation,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
openByBand[bandIdx]++;
|
openByBand[bandIdx]++;
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "flight-ops",
|
"name": "flight-ops",
|
||||||
"version": "0.66.0",
|
"version": "1.0.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev -p 3000",
|
"dev": "next dev -p 3000",
|
||||||
|
|||||||
@@ -3,10 +3,10 @@
|
|||||||
//
|
//
|
||||||
// Pipeline: download → keep `large_airport` rows only (same density curation as the EU file,
|
// Pipeline: download → keep `large_airport` rows only (same density curation as the EU file,
|
||||||
// v0.2.8) → greedy 40 km haversine clustering → one airport per cluster ("the biggest").
|
// v0.2.8) → greedy 40 km haversine clustering → one airport per cluster ("the biggest").
|
||||||
// v0.61.0 (ISS-097): additionally keeps every non-large fixed-wing row that is REMOTE — no other
|
// v0.68.0 (ISS-144): additionally keeps a sparse set of "special" remote airports — non-large
|
||||||
// airport within 1000 km of the kept set (lib/airports.ts isRemote) — so Antarctica, the high
|
// fixed-wing rows with no large airport within 1000 km, greedily thinned to one per ~1000 km
|
||||||
// Arctic, Alaska, northern Canada and far islands are represented even though they carry no
|
// region (scheduled service + larger types preferred) so Antarctica, the high Arctic, Alaska,
|
||||||
// large_airport; same-station twins collapse via the same 40 km clustering.
|
// northern Canada and far islands are represented without over-filling empty regions.
|
||||||
// The output keeps the exact OurAirports header so lib/airports.ts parses it unchanged.
|
// The output keeps the exact OurAirports header so lib/airports.ts parses it unchanged.
|
||||||
//
|
//
|
||||||
// Usage: node scripts/build-world-airports.mjs (writes data/airports_world.csv, prints stats)
|
// Usage: node scripts/build-world-airports.mjs (writes data/airports_world.csv, prints stats)
|
||||||
@@ -141,12 +141,25 @@ for (const c of largeClusters) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// v0.61.0 (ISS-097): "special" remote airports — every non-large fixed-wing row with no other
|
// v0.68.0 (ISS-144): "special" remote airports — one per ~REMOTE_RADIUS_KM region. Candidates are
|
||||||
// airport within REMOTE_RADIUS_KM of the kept set joins the dataset, so empty regions get their
|
// the non-large fixed-wing rows with no large airport within REMOTE_RADIUS_KM (unchanged), sorted
|
||||||
// real (small) airports instead of nothing. Same-station twins (two strips <40 km apart at one
|
// by priority (scheduled service, then type rank medium < small < seaplane, then numeric id) and
|
||||||
// base) collapse via the same greedy clustering as above.
|
// accepted greedily: a candidate joins only if it is at least REMOTE_RADIUS_KM from EVERY already
|
||||||
const remote = fixed.filter((r) => r.type !== 'large_airport' && isRemoteRow(r, kept));
|
// accepted special — no special airport within 1000 km of another. One per ~1000 km region, so
|
||||||
const { winners: remoteKept } = clusterWinners(remote);
|
// central Australia / Canada edges get a handful of well-chosen strips instead of dozens; this
|
||||||
|
// subsumes the old 40 km remote clustering (deleted).
|
||||||
|
const TYPE_RANK = { medium_airport: 0, small_airport: 1, seaplane_base: 2 }; // legacy 'airport' ranks last
|
||||||
|
const candidates = fixed.filter((r) => r.type !== 'large_airport' && isRemoteRow(r, kept));
|
||||||
|
candidates.sort(
|
||||||
|
(a, b) =>
|
||||||
|
Number(b.scheduled_service === 'yes') - Number(a.scheduled_service === 'yes') ||
|
||||||
|
(TYPE_RANK[a.type] ?? 3) - (TYPE_RANK[b.type] ?? 3) ||
|
||||||
|
Number(a.id) - Number(b.id),
|
||||||
|
);
|
||||||
|
const remoteKept = [];
|
||||||
|
for (const c of candidates) {
|
||||||
|
if (remoteKept.every((k) => haversineKm(c, k) >= REMOTE_RADIUS_KM)) remoteKept.push(c);
|
||||||
|
}
|
||||||
|
|
||||||
// --- Guards (fail loud before writing anything) ---
|
// --- Guards (fail loud before writing anything) ---
|
||||||
const finalRows = [...kept, ...remoteKept];
|
const finalRows = [...kept, ...remoteKept];
|
||||||
|
|||||||
Reference in New Issue
Block a user