Compare commits

..

21 Commits

Author SHA1 Message Date
eb8bee65d9 Fix module res?
All checks were successful
Publish Package / build-and-publish (push) Successful in 7s
2026-04-27 23:48:08 +01:00
fc4c8745a6 Fix the date validator, was checking indexes, not values!
All checks were successful
Publish Package / build-and-publish (push) Successful in 8s
2026-04-27 23:39:36 +01:00
0474973588 Fix path to train module
All checks were successful
Publish Package / build-and-publish (push) Successful in 8s
2026-04-27 23:31:43 +01:00
7f2cb2c413 Fix path to helpers.js
All checks were successful
Publish Package / build-and-publish (push) Successful in 8s
2026-04-27 23:29:31 +01:00
3c81b5225f Add trains endpoint handler
All checks were successful
Publish Package / build-and-publish (push) Successful in 8s
2026-04-27 22:28:55 +01:00
d10dabf604 Adjust generateGeohash from static to standard method to support singleton approach in Svelte without additonal import/exports
All checks were successful
Publish Package / build-and-publish (push) Successful in 3s
2026-03-30 22:57:57 +01:00
26886f8a7d Fix pathing to stationDate.js file
All checks were successful
Publish Package / build-and-publish (push) Successful in 3s
2026-03-30 22:52:09 +01:00
46dcf65de6 Ensure StationDataModule is exported
All checks were successful
Publish Package / build-and-publish (push) Successful in 2s
2026-03-30 22:49:53 +01:00
d160ad87f9 Ensure staitionData module is available in Client
All checks were successful
Publish Package / build-and-publish (push) Successful in 2s
2026-03-30 22:11:33 +01:00
fc74e933d6 Add StationDataModule, implementing getNearestStations & a Geohash generator method
All checks were successful
Publish Package / build-and-publish (push) Successful in 6s
2026-03-30 21:53:01 +01:00
ad355fe15e Re-export API Schema types
All checks were successful
Publish Package / build-and-publish (push) Successful in 4s
2026-03-25 10:22:34 +00:00
4dd8bd1108 Fix import paths
All checks were successful
Publish Package / build-and-publish (push) Successful in 3s
2026-03-24 12:40:07 +00:00
e2f4433042 Add LocationFilterModule
All checks were successful
Publish Package / build-and-publish (push) Successful in 7s
2026-03-24 00:53:29 +00:00
7775abbbca Adjust tagging strategy
All checks were successful
Publish Package / build-and-publish (push) Successful in 7s
2026-03-19 20:04:21 +00:00
f340c57ffd Ensure dynamic versioning for NPM pubslishing
Some checks failed
Publish Package / build-and-publish (push) Failing after 5s
2026-03-19 19:55:47 +00:00
6c6a603cd8 Ensure all paths are relative
Some checks failed
Publish Package / build-and-publish (push) Failing after 7s
2026-03-19 19:51:41 +00:00
35167f1853 And again...
All checks were successful
Publish Package / build-and-publish (push) Successful in 7s
2026-03-19 10:52:46 +00:00
815ae473db Try again
Some checks failed
Publish Package / build-and-publish (push) Failing after 6s
2026-03-19 10:49:43 +00:00
ff3052f3b0 Fix casing in NPM configuration for build/push job
Some checks failed
Publish Package / build-and-publish (push) Failing after 5s
2026-03-19 10:46:12 +00:00
0985e40ead Attempt another registry push pattern
Some checks failed
Publish Package / build-and-publish (push) Failing after 7s
2026-03-19 10:40:10 +00:00
23afe71752 Attempt force auth
Some checks failed
Publish Package / build-and-publish (push) Failing after 6s
2026-03-18 21:08:00 +00:00
12 changed files with 249 additions and 30 deletions

View File

@@ -19,7 +19,8 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: 20
registry-url: "https://registry.npmjs.org"
registry-url: 'https://git.fjla.uk/api/packages/owlboard/npm'
scope: '@OwlBoard'
- name: Install Dependencies
run: npm ci
@@ -27,12 +28,10 @@ jobs:
- name: Build
run: npm run build
# - name: Publish to NPM
# run: npm publish --access public
# env:
# NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish to Gitea Repo
run: npm publish --registry=https://git.fjla.uk
env:
NODE_AUTH_TOKEN: ${{ secrets.REPO_TOKEN }}
run: |
VERSION=${GITHUB_REF_NAME#v}
npm version $VERSION --no-git-tag-version
npm config set //git.fjla.uk/api/packages/owlboard/npm/:_authToken ${{ secrets.REPO_TOKEN }}
npm config set //git.fjla.uk/api/packages/OwlBoard/npm/:_authToken ${{ secrets.REPO_TOKEN }}
npm publish --registry=https://git.fjla.uk

30
package-lock.json generated
View File

@@ -1,15 +1,19 @@
{
"name": "owlboard-ts",
"name": "@owlboard/owlboard-ts",
"version": "3.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "owlboard-ts",
"name": "@owlboard/owlboard-ts",
"version": "3.0.0",
"license": "GPL-3.0",
"dependencies": {
"@owlboard/api-schema-types": "^3.0.3-alpha1",
"latlon-geohash": "^2.0.0"
},
"devDependencies": {
"@owlboard/api-schema-types": "^3.0.1-alpha3",
"@types/latlon-geohash": "^2.0.4",
"@types/node": "^25.3.0",
"ts-node": "^10.9.2",
"tsx": "^4.21.0",
@@ -500,10 +504,9 @@
}
},
"node_modules/@owlboard/api-schema-types": {
"version": "3.0.1-alpha3",
"resolved": "https://git.fjla.uk/api/packages/OwlBoard/npm/%40owlboard%2Fapi-schema-types/-/3.0.1-alpha3/api-schema-types-3.0.1-alpha3.tgz",
"integrity": "sha512-5CVm1k/C++/VrtAw4NkvclDunH+RmYLnDZZMSWTM1mm+WlEVnmD+MVnTgC/FhcsAmsNHV8swm66RCqkCuhbOnA==",
"dev": true,
"version": "3.0.3-alpha1",
"resolved": "https://git.fjla.uk/api/packages/OwlBoard/npm/%40owlboard%2Fapi-schema-types/-/3.0.3-alpha1/api-schema-types-3.0.3-alpha1.tgz",
"integrity": "sha512-UWe2nbJWb2B/LuZW1UXHJ2lpqOGwugiXTa4G6X5xLiaws3ISEdciweorX8kr2/JAz5+iFYIe1xXRFAWsFtpn/w==",
"license": "MIT"
},
"node_modules/@tsconfig/node10": {
@@ -534,6 +537,13 @@
"dev": true,
"license": "MIT"
},
"node_modules/@types/latlon-geohash": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/@types/latlon-geohash/-/latlon-geohash-2.0.4.tgz",
"integrity": "sha512-R/wb/V8lhhI0hyRGDTkT6F4C3lynkF/D29iMSN5B4bYswaa4R+wajgcTv9z73BotGArf4Q8BnDNtmLeI+WiKkQ==",
"dev": true,
"license": "MIT"
},
"node_modules/@types/node": {
"version": "25.3.0",
"resolved": "https://registry.npmjs.org/@types/node/-/node-25.3.0.tgz",
@@ -664,6 +674,12 @@
"url": "https://github.com/privatenumber/get-tsconfig?sponsor=1"
}
},
"node_modules/latlon-geohash": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/latlon-geohash/-/latlon-geohash-2.0.0.tgz",
"integrity": "sha512-OKBswTwrvTdtenV+9C9euBmvgGuqyjJNAzpQCarRz1m8/pYD2nz9fKkXmLs2S3jeXaLi3Ry76twQplKKUlgS/g==",
"license": "MIT"
},
"node_modules/make-error": {
"version": "1.3.6",
"resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz",

View File

@@ -6,7 +6,9 @@
"type": "module",
"sideEffects": false,
"types": "./dist/index.d.ts",
"files": ["dist"],
"files": [
"dist"
],
"exports": {
".": {
"types": "./dist/index.d.ts",
@@ -28,9 +30,11 @@
"author": "Frederick Boniface",
"license": "GPL-3.0",
"dependencies": {
"@owlboard/api-schema-types": "^3.0.1-alpha3"
"@owlboard/api-schema-types": "^3.0.3-alpha1",
"latlon-geohash": "^2.0.0"
},
"devDependencies": {
"@types/latlon-geohash": "^2.0.4",
"@types/node": "^25.3.0",
"ts-node": "^10.9.2",
"tsx": "^4.21.0",

View File

@@ -1,5 +1,11 @@
export * from './lib/base.js';
export * from './lib/client.js';
export * from './lib/errors.js';
export { OwlBoardClient } from './lib/client.js';
export { ValidationError, ApiError } from './lib/errors.js';
export * from './modules/pis.js';
// Re-export API Schema types
export type * from '@owlboard/api-schema-types'
// Useful exports for Type Hinting
export { PisModule } from './modules/pis.js';
export { LocationFilterModule } from './modules/locationFilter.js';
export { StationDataModule } from './modules/stationData.js';
export { TrainsModule } from './modules/trains.js';

View File

@@ -1,12 +1,21 @@
import { BaseClient } from "./base.js";
import { PisModule } from "../modules/pis.js";
import { LocationFilterModule } from "../modules/locationFilter.js";
import { StationDataModule } from "../modules/stationData.js";
import { TrainsModule } from "../modules/trains.js";
export class OwlBoardClient extends BaseClient {
public readonly pis: PisModule;
public readonly locationFilter: LocationFilterModule;
public readonly stationData: StationDataModule;
public readonly trains: TrainsModule;
constructor(baseUrl: string, apiKey?: string) {
super(baseUrl, apiKey);
this.pis = new PisModule(this);
this.locationFilter = new LocationFilterModule(this);
this.stationData = new StationDataModule(this);
this.trains = new TrainsModule(this);
}
}

20
src/lib/helpers.ts Normal file
View File

@@ -0,0 +1,20 @@
/**
* Normalises input to YYYY-MM-DD string
* - Strings are passed through as is
* - Date objects are converted to UK time
*/
export const ensureDateString = (input: Date | string): string => {
if (typeof input === 'string') return input.trim();
const d = new Intl.DateTimeFormat('en-GB', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
timeZone: 'Europe/London'
}).formatToParts(input);
const part = (type: string) => d.find(p => p.type === type)?.value;
return `${part('year')}-${part('month')}-${part('day')}`
}

View File

@@ -1,6 +1,17 @@
/**
* Checks if a string is a valid CRS
* Checks if a character code is a digit
*/
const isDigit = (c: number) => c >= 48 && c <= 57;
/**
* Checks if a character code is an upper case letter
*/
const isUpper = (c: number) => c >= 65 && c <= 90;
/**
* Checks if a string is a valid CRS (Syntactically Only)
* using byte level checking for max performance
* @param CRS The CRS Code to be validated
*/
export const IsValidCrs = (CRS: string): boolean => {
if (CRS.length !== 3) return false;
@@ -15,8 +26,9 @@ export const IsValidCrs = (CRS: string): boolean => {
}
/**
* Checks if a string is a valid TIPLOC
* Checks if a string is a valid TIPLOC (Syntactically Only)
* using byte level checking for max performance
* @param TIPLOC The TIPLOC to be validated
*/
export const IsValidTiploc = (TIPLOC: string): boolean => {
const l = TIPLOC.length;
@@ -33,9 +45,10 @@ export const IsValidTiploc = (TIPLOC: string): boolean => {
}
/**
* Checks if a string is a valid PIS Code
* Checks if a string is a valid PIS Code (Syntactically Only)
* using byte level checking for max performance
* ONLY GWR (4-digit) CODES SUPPORTED
* @param PIS The PIS Code to be validated
*/
export const IsValidPis = (PIS: string): boolean => {
if (PIS.length !== 4) return false;
@@ -45,3 +58,68 @@ export const IsValidPis = (PIS: string): boolean => {
}
return true;
}
/**
* Checks if a string is the correct format for a Headcode
* USes byte level checking for max performance
* @param Headcode The headcode to be validated
*/
export const IsValidHeadcode = (Headcode: string): boolean => {
if (Headcode.length !== 4) return false;
const c0 = Headcode.charCodeAt(0);
const c1 = Headcode.charCodeAt(1);
const c2 = Headcode.charCodeAt(2);
const c3 = Headcode.charCodeAt(3);
return isDigit(c0) && isUpper(c1) && isDigit(c2) && isDigit(c3)
}
/**
* Checks if a string is the correct format for a TOC Code
*/
export const IsValidToc = (toc: string): boolean => {
if (toc.length !== 2) {
return false;
}
const c0 = toc.charCodeAt(0);
const c1 = toc.charCodeAt(1);
return isUpper(c0) && isUpper(c1);
}
/**
* Checks if a string is the correct format, and is a valid date
*/
export const IsValidDateStr = (s: string): boolean => {
if (s.length !== 10) return false;
if (s[4] !== '-' || s[7] !== '-') return false;
for (let i = 0; i < 10; i++) {
if (i === 4 || i === 7) continue;
const c = s.charCodeAt(i);
if (!isDigit(c)) return false;
}
const y = parseInt(s.substring(0, 4), 10);
const m = parseInt(s.substring(5, 7), 10) - 1; // JS months are 0-11
const d = parseInt(s.substring(8, 10), 10);
const date = new Date(y, m, d);
return (
date.getFullYear() === y &&
date.getMonth() === m &&
date.getDate() === d
);
}
/**
* Validates Geohash string against standard b32 alphabet
* (Syntactically Only validation)
* @param hash The geohash to be validated
* @param maxLen Defaults to 6 - which is enforced by the server, should not need changing
*/
export const IsValidGeoHash = (hash: string, maxLen: number = 6): boolean => {
const geoHashRegex = new RegExp(`^[0-9bcdefghjkmnpqrstuvwxyz]{1,${maxLen}}$`, 'i');
return geoHashRegex.test(hash);
}

View File

@@ -0,0 +1,15 @@
import { ApiLocationFilter } from "@owlboard/api-schema-types";
import type { BaseClient, ApiResult } from '../lib/base.js';
export class LocationFilterModule {
constructor(private client: BaseClient) {}
async getLocationFilterData(): Promise<ApiResult<ApiLocationFilter.LocationFilterObject[]>> {
const path = '/locationFilter/data';
return this.client.request<ApiLocationFilter.LocationFilterObject[]>(
path,
{method: "GET"}
);
}
}

View File

@@ -1,7 +1,7 @@
import { ApiPisObject } from '@owlboard/api-schema-types';
import type { BaseClient, ApiResult } from '../lib/base.js';
import { IsValidCrs, IsValidTiploc, IsValidPis } from 'src/lib/validation.js';
import { ValidationError } from 'src/lib/errors.js';
import { IsValidCrs, IsValidPis } from '../lib/validation.js';
import { ValidationError } from '../lib/errors.js';
export class PisModule {
constructor(private client: BaseClient) {}

View File

@@ -0,0 +1,37 @@
import { ApiStationsNearestStations } from '@owlboard/api-schema-types';
import type { BaseClient, ApiResult } from '../lib/base.js';
import { IsValidGeoHash } from '../lib/validation.js';
import { ValidationError } from '../lib/errors.js';
import Geohash from 'latlon-geohash';
export class StationDataModule {
constructor(private client: BaseClient) {}
/**
* Generates a 6-char Geohash for the given co-ordinates
* @param lt Latitude
* @param ln Longitude
* @returns Geohash as string
*/
generateGeohash(lt: number, ln: number): string {
return Geohash.encode(lt, ln, 6);
}
/**
*
* @param geohash Geohash as string (up to six characters), generate using this.generateGeohash()
* @returns Nearest Stations API Response (CRS, Name)
*/
async getNearestStations(geohash: string): Promise<ApiResult<ApiStationsNearestStations.StationsNearestStations[]>> {
if (!IsValidGeoHash(geohash)) {
throw new ValidationError("hash", "Invalid Geohash requested");
}
const path = `/stationData/nearest/${geohash}`;
return this.client.request<ApiStationsNearestStations.StationsNearestStations[]>(path, {
method: 'GET',
})
}
// getStationSate(crs: string){}
}

34
src/modules/trains.ts Normal file
View File

@@ -0,0 +1,34 @@
import { ApiTrainsTrainByHeadcode } from '@owlboard/api-schema-types';
import type { BaseClient, ApiResult } from '../lib/base.js';
import { IsValidHeadcode, IsValidToc, IsValidDateStr } from '../lib/validation.js';
import { ensureDateString } from '../lib/helpers.js';
import { ValidationError } from '../lib/errors.js';
export class TrainsModule {
constructor(private client: BaseClient) { }
async getByHeadcode(headcode: string, date: string | Date = new Date, toc: string = ""): Promise<ApiResult<ApiTrainsTrainByHeadcode.TrainByHeadcodeResponse[]>> {
if (!IsValidHeadcode(headcode)) {
throw new ValidationError("headcode", "Invalid headcode format")
}
if (toc !== "" && !IsValidToc(toc)) {
throw new ValidationError("TOC", "Invalid TOC Format, needs to be two characters");
}
const dateStr = ensureDateString(date);
if (!IsValidDateStr(dateStr)) {
throw new ValidationError("Date", "Invalid date format, need YYYY-MM-DD");
}
const searchParams = new URLSearchParams();
searchParams.append('d', dateStr);
searchParams.append('h', headcode);
if (toc) searchParams.append('t', toc);
const path = `/trains?${searchParams.toString()}`;
return this.client.request<ApiTrainsTrainByHeadcode.TrainByHeadcodeResponse[]>(path, {
method: 'GET',
});
}
}

View File

@@ -7,9 +7,9 @@
// Environment Settings
// See also https://aka.ms/tsconfig/module
"module": "esnext",
"module": "nodenext",
"target": "esnext",
"moduleResolution": "bundler",
"moduleResolution": "nodenext",
"baseUrl": ".",
"types": [],
// For nodejs:
@@ -21,6 +21,7 @@
"sourceMap": true,
"declaration": true,
"declarationMap": true,
"composite": true,
// Stricter Typechecking Options
"noUncheckedIndexedAccess": true,