This document was generated by scanning the repository and summarises the codebase, architecture, public surface, implementation details, and practical notes for contributors and automated agents.
- Provide a concise, machine- and human-readable overview of the SDK so agents (or new contributors) can quickly understand responsibilities, extension points, and where to make safe changes.
- Scan the codebase and produce a comprehensive understanding.
- Add
AGENTS.mdto the repository root with a clear summary and guidance.
The repository implements a small, modular TypeScript SDK for the Altus 4 service (AI-enhanced MySQL full-text search). It exposes a single top-level SDK class (Altus4SDK) that composes multiple service clients. Core areas:
client/— Base HTTP client, configuration defaults and re-exports.services/— Service-specific classes (Auth, ApiKeys, Database, Analytics, Management).types/— Centralised TypeScript types and interfaces (auth, api keys, analytics, database, management, common).utils/— Validation, formatting and date helpers used by services and consumers.src/index.ts— Main SDK entry point and convenience exports +altus4default instance.tests/— Basic unit tests validating SDK instantiation and token helpers.
-
Altus4SDKclass (default export) — central SDK instance that exposes:.auth—AuthService.apiKeys—ApiKeysService.database—DatabaseService.analytics—AnalyticsService.management—ManagementService- Helpers:
login,register,logout,getCurrentUser,isAuthenticated,setToken,clearToken,setBaseURL.
-
createAltus4SDK(config?)— factory helper. -
altus4— a default SDK instance (constructed with no config).
-
HTTP transport uses
axiosand a singleBaseClientwrapper that configures interceptors for adding anAuthorizationheader and basic 401 handling. -
Token storage is currently implemented as in-memory fields on
AuthServiceand also viaBaseClientmethods that read/writelocalStoragewhenwindowis available. This creates two storage places:AuthService.token/tokenExpiry(in-memory) used to determine authentication state and refresh tokens.BaseClient.getToken/setToken/clearTokenuselocalStoragewhen running in a browser environment. (Note: server-side usage will not persist tokens.)
-
Services call
this.request(...)which expects the API to respond with anApiResponse<T>shape (defined undertypes/common). Error handling returns the API response body when present, otherwise a network-error shaped object. -
Many services provide a
setBaseURLoverride that delegates to theBaseClientto updateaxiosdefaults — allowing runtime reconfiguration.
package.json— scripts for build/test/lint and dependencies:axios,formlinkin runtime;typescript,jest,eslint, etc. in dev.tsconfig.json— strict TypeScript configuration, output todistwith declaration files.src/client/base-client.ts— core HTTP client and interceptors.src/client/config.ts—ClientConfigandDEFAULT_CONFIG.src/services/*.ts— small, focused API wrappers that map to REST endpoints.src/utils/validators.ts— many input validations used by services or callers.src/index.ts— re-exports andAltus4SDKimplementation.
- The server API uses a consistent
ApiResponse<T>envelope. Services call endpoints such as/auth/login,/keys,/databases,/analytics/*, and/health. - The code assumes browser-like runtime for token persistence (via
localStorage) but will still operate server-side with in-memory tokens. - Error handling is intentionally tolerant: network or non-JSON responses are wrapped into a standardized error object.
These commands come from package.json:
- Install dependencies:
npm install- Build (clean + TypeScript compile):
npm run build- Typecheck only:
npm run typecheck- Tests (Jest):
npm test- Lint:
npm run lint- Add integration tests that stub HTTP responses (e.g. msw or axios-mock-adapter) to validate service methods' behavior.
- Consider consolidating token persistence strategy (pick
localStorage+ optional adapter for Node.js) to avoid the in-memory vs storage mismatch. - Add small README sections in
services/describing endpoint contracts (request/response shapes). Typedoc is configured (docsscript) and can be used to generate API docs.
BaseClient.getToken()returns null on Node.js — callers relying on persistent tokens server-side will findAuthorizationnot included unlesssetTokenis called programmatically.AuthService.isAuthenticated()is based on the in-memory token and expiry fields. If a page is reloaded, the in-memory token is lost unlessBaseClient.getToken()andAuthService.setToken()are reconciled.- Validation helpers are permissive but should be reused by callers before sending sensitive operations.
- Instantiate with custom base URL:
import { Altus4SDK } from './src';
const sdk = new Altus4SDK({ baseURL: 'https://api.altus4.com/api/v1' });
await sdk.login('me@example.com', 'password');- I inferred runtime behaviour for token persistence (browser localStorage) from
BaseClientandAuthServiceimplementations. - I assumed
ApiResponse<T>envelope is used consistently by the server based on usage inBaseClient.requestand service return types.
- Add a central token adapter that reads from
localStoragein the browser and from an injectable storage for server-side usage. - Add integration tests for
AuthServicerefresh flow and forApiKeysServicecreate/regenerate endpoints. - Expand README with example of using
altus4default instance and recommended auth flow.
- "Scan through this code, get a full and comprehensive understanding of this codebase" — Done (files inspected:
package.json,README.md,tsconfig.json,src/*key files,tests/). - "Add an AGENTS.md file to the root of the directory" — Done (this file).
- Added:
AGENTS.md— high level overview and guidance for agents and contributors.
If you want, I can now:
- run the test suite locally to verify everything still passes, or
- open a follow-up patch to convert token persistence to a configurable adapter.