8 Development
ulyxie edited this page 2026-11-09 12:25:14 +00:00

Development

Working on the library itself.

Layout

Path What it is
src/Session.ts Version resolution, form helpers, the core handlers' getters, use(), registerModule() and the placeholders for module getters
src/handlers/ One class per handler, core and optional alike; service-abstract.ts holds what they share
src/modules/ One entry per optional module: registers its handler's getter and augments SessionModules. Each is a subpath in package.json exports
src/http/ The request layer: client.ts (URLs, bodies, sign-in, ticket, decoding, HTTPError), fetch-transport.ts, node-transport.ts (Node's default, reached only through #platform), multipart.ts (the streamed form encoding), types.ts
src/transports/axios.ts The optional axios transport, @ulyxie/cs-rest/axios
src/platform/ node.ts and browser.ts, chosen by the #platform entry of package.json imports: file paths, the streamed form encoding and the default transport on Node and Bun; stubs and fetch elsewhere
src/normalize/ The readers behind response.result
src/types/cs-rest-types/schema.ts Generated. OpenAPI types from the newest spec
src/types/capabilities.ts Generated. The release each operation arrived in, and was dropped after
src/types/responses.ts TOk / TPathOk lookups into the schema
specs/ One published OpenAPI document per Content Server release, 20.3 - 26.2, plus content-server-rest-api-26.1-live.yaml (see below)
scripts/ The two generators, the coverage report and check-dts.mjs
test/ node:test suites, run against the built package through its own exports map; test/types/ for the declaration check
CHANGELOG.md What changed for users

Scripts

Command Does
npm run build tsc -p tsconfig.build.json: one ES module per source file into lib/, with declarations and source maps
npm test Runs test/**/*.test.mjs against lib/, so build first
npm run check:dts Compiles test/types/ against the shipped declarations as a consumer would: strict, skipLibCheck off, bundler and nodenext resolution
npm run test:live The live smoke test against a real server, configured by .env (see below)
npm run test:live:large The live large-file test: 512 MB ordinary uploads and a Large File Upload just over the server's minimum, checking checksums and that memory stays flat
npm run coverage Which spec operations have a method. -- --missing, -- --skipped, -- --tag <tag> for detail
npm run generate:types Rebuilds schema.ts from the newest spec
npm run generate:capabilities Rebuilds capabilities.ts from every spec

Adding a method

Every request goes through ServiceAbstract.gated(), which checks the operation against the target release and builds the URL from the same template, so the two cannot disagree:

// From nodes.ts
async update(id: number, body: TNodeUpdate): Promise<TResponse<TOk<"updateNode2">>> {
  return this.session.putBody<TOk<"updateNode2">>(await this.gated("PUT", "/v2/nodes/{id}", id), body);
}

async node(id: number, params = {}): Promise<TResult<TOk<"getNode2">, TNode | undefined>> {
  return this.withResult(
    this.session.get<TOk<"getNode2">>(await this.gated("GET", "/v2/nodes/{id}", id), { params }),
    normalize.node,
  );
}
  • Write the template exactly as the spec does: leading slash, {placeholders}, no api prefix. Coverage and gating both key on it.

  • Name it by the rule: unsuffixed for v2, V1 for v1, V3 for v3. Mark a v1 method @deprecated only when a v2 twin exists.

  • Give it an explicit return type naming TOk<"operationId">. Inferred types bloat the declarations.

  • If it returns a node, version, member, volume, permission or category, wrap it in withResult(request, normalize.x).

  • Uploads go through toBlob() and multipart(), downloads through fetchContent() or downloadTo().

  • Add a row for it to test/requests.test.mjs: the call, and the method and URL it must send, plus the query or fields where they matter. It runs against a fake fetch, so no server is needed. If the method is in a module, import the module at the top of the file.

  • Relative imports carry their .js extension ("./service-abstract.js"): the output is unbundled ES modules, which Node resolves only by full path.

  • Nothing outside src/platform/ may import a Node built-in. Browser bundles would break on it; add what you need to both platform files instead.

  • To leave a spec operation unwrapped on purpose, say so where it would live, and coverage reports it as a decision rather than a gap:

    // coverage-skip: GET /v2/nodes/actions - POST covers it without URL limits
    

Live tests

test/live/ runs against a real Content Server; neither script is part of npm test. Both read .env in the repository root (ignored by git, left out of the package):

Variable Meaning
CS_BASE_URL https://server/otcs/cs.exe
CS_IPV4 Optional: connect to this address instead of resolving the hostname. TLS is still checked against the hostname
CS_CA_FILE Optional: a PEM file of CAs to trust as well as the usual ones
CS_USERNAME, CS_PASSWORD An account that may write in the test folder
CS_TEST_PARENT_ID The folder everything is created in

Each creates one scratch folder under CS_TEST_PARENT_ID, and deletes it and purges it from the Recycle Bin at the end, so a run leaves nothing on the server. test/live/setup.mjs builds the https.Agent (and, for the custom-fetch steps, the undici dispatcher) both use.

Adding a module

A handler belongs in a module when an everyday app would not use it - a separately licensed feature, administration, a niche API.

  1. Write the handler in src/handlers/, as any other.
  2. Add src/modules/<subpath>.ts, modelled on src/modules/webreports.ts: import the class, augment SessionModules with the getter, call registerModule("<getter>", Class), and export the class by name and as default.
  3. Add "./<subpath>" to exports in package.json, pointing at lib/modules/<subpath>.js and its .d.ts.
  4. Add the getter and subpath to MODULES in src/Session.ts, so it throws a helpful error before the import, and to GETTERS in test/modules.test.mjs.
  5. Add a line to covers in the wiki's tools/gen-handlers.mjs and regenerate Handlers.

Adding a Content Server release

  1. Save the release's OpenAPI document as specs/content-server-rest-api-<major>.<minor>.yaml (or .json).
  2. Run npm run generate:types && npm run generate:capabilities.
  3. Run npm run coverage -- --missing and wrap anything new.
  4. Commit the spec together with both generated files.

CI regenerates both files and fails if that changes anything. Neither generated file can drift from specs/ unnoticed.

The live route list

specs/content-server-rest-api-26.1-live.yaml is not a published OpenText spec. It is every /api route a live Content Server 26.1 installation registers, pulled on 2026-09-25 from the route maps of its installed OSpaces: 1361 operations, against the 349 the published 26.2 spec documents.

  • It includes routes OpenText does not document, such as GET /v3/status, /v3/token/expiry and /v3/app/container/{id}.
  • Routes were read from the installation, not called, so a listed route can still refuse a request.
  • It has no response schemas, because the server source does not declare them. Each operation names its OScript handler under x-contentserver.
  • info and the top-level x-source block mark its provenance.

npm run generate:types and plain npm run coverage read only content-server-rest-api-<release>.(yaml|json), so the -live file never affects types or the published-spec coverage. Use it to find out whether a server really has an endpoint, and which handler serves it.

npm run generate:capabilities reads it for one thing only: evidence against a removal. An operation the published specs stop documenting is not marked removedAfter if a live list from a later release still has it. OpenText dropped GET /v1/nodes/{id}/parameters and GET /v1/webreports/{nickname}/destination from its specs after 20.4, but 26.1 still serves both; without this, gating refused them on every later release. The generated file says so in a comment above each such entry.

CI

Pull requests run, in order: install (yarn --frozen-lockfile), build, test, check:dts, and the generated-files check. CI uses yarn v1; keep yarn.lock in step with package.json.

To check what a browser app would ship, npm pack and install the tarball into a scratch app outside the repository, then bundle it there (esbuild app.mjs --bundle --minify --platform=browser). Bundling from inside the repository picks up its tsconfig.json, whose paths entry sends #platform to the Node file; the published package has no tsconfig, so consumers never see that.

Conventions

  • Line endings are LF, enforced by .gitattributes whatever your core.autocrlf says.
  • Node 20.19+ (engines), Bun and current browsers. Requests use the built-in fetch, FormData and Blob; no runtime dependencies.
  • ES modules only. No CommonJS copy, because two copies of Session would break module registration.
  • Warnings go through utils/warn.ts: [cs-rest] prefix, yellow on a terminal, plain otherwise or under NO_COLOR.
  • Deprecations go through utils/deprecate.ts, which warns once per method.