5 Modules
ulyxie edited this page 2026-11-09 10:50:04 +00:00

Modules

The package is split so an app carries only the handlers it uses. That matters most in the browser, where every handler is code the user downloads.

Core and modules

The core is the package root, @ulyxie/cs-rest: the Session, authentication, version detection and gating, the normaliser, and the handlers almost every app needs.

auth, categories, forms, members, nodes, permissions, search, server, uploads, versions, volumes

Everything else is a module, one subpath each:

Import Adds
@ulyxie/cs-rest/workflow session.workflow
@ulyxie/cs-rest/webreports session.webreports
@ulyxie/cs-rest/viewx session.viewx
@ulyxie/cs-rest/perspectives session.perspectives
@ulyxie/cs-rest/reminders session.reminders
@ulyxie/cs-rest/signatures session.signatures
@ulyxie/cs-rest/ai session.ai
@ulyxie/cs-rest/recman session.recman
@ulyxie/cs-rest/physical-objects session.physicalObjects
@ulyxie/cs-rest/classifications session.classifications
@ulyxie/cs-rest/video session.video
@ulyxie/cs-rest/wopi session.wopi
@ulyxie/cs-rest/office session.office
@ulyxie/cs-rest/email session.email
@ulyxie/cs-rest/forums session.forums
@ulyxie/cs-rest/notifications session.notifications
@ulyxie/cs-rest/pulse session.pulse
@ulyxie/cs-rest/regulated session.regulated
@ulyxie/cs-rest/salesforce session.salesforce
@ulyxie/cs-rest/sharepoint-archive session.sharePointArchive
@ulyxie/cs-rest/sharing session.sharing
@ulyxie/cs-rest/syndication session.syndication
@ulyxie/cs-rest/webedit session.webedit
@ulyxie/cs-rest/wiki session.wiki
@ulyxie/cs-rest/workspaces session.workspaces
@ulyxie/cs-rest/event-action-center session.eventActionCenter
@ulyxie/cs-rest/smart-document-types session.smartDocumentTypes
@ulyxie/cs-rest/government session.government
@ulyxie/cs-rest/admin session.admin
@ulyxie/cs-rest/rpc session.rhcore, session.rpcClient(), and RPCClient, RPCError, isRPCError
@ulyxie/cs-rest/classic session.classic - the Classic UI, Node/Bun only; see Classic UI

@ulyxie/cs-rest/axios is not a module but a transport; see Transports.

Using one

Import it once, anywhere in the app - typically next to where the Session is created. From then on every Session has its getter:

import { Session } from "@ulyxie/cs-rest";
import "@ulyxie/cs-rest/webreports";

const session = new Session({ baseUrl, otcsticket });
await session.webreports.runV1(12345);
  • TypeScript knows the getter exists once the import is anywhere in the program.

  • Without the import, the getter throws session.webreports needs its module: import "@ulyxie/cs-rest/webreports" once, anywhere in your app, and TypeScript reports it as a missing property.

  • Each module also exports its handler class, as default and by name, for typing and for use():

    import { WebReports } from "@ulyxie/cs-rest/webreports";
    const reports = session.use(WebReports); // the same object as session.webreports
    

What it costs

Measured with esbuild from the packed package, bundled for the browser, minified:

App imports Minified Gzipped
the core 66.6 KB 13.4 KB
the core and recman 70.2 KB 13.9 KB
everything 93.5 KB 17.8 KB

Before requests moved from axios to fetch, the core alone was 31.8 KB gzipped, axios being the larger part of it.

How it works

  • The build emits one ES module per source file (lib/), not a bundle. The core and every module then share a single Session class, which is what lets a module attach itself, and an app's bundler drops every file the app never imports.
  • A module file calls registerModule("webreports", WebReports), which defines the getter on Session.prototype, and augments the SessionModules interface so TypeScript sees it.
  • package.json lists lib/modules/*.js under sideEffects, so bundlers keep a bare import "@ulyxie/cs-rest/webreports" while still tree-shaking everything else.
  • Node-only code (reading an upload path, writing a download to disk) sits behind the #platform package import: the node condition (Node, Bun) gets the fs version, everything else a stub. No browser bundle ever references fs.
  • Package exports are ES modules only. A CommonJS copy beside them would give a mixed app two Session classes, and a module would attach to the wrong one.

A handler of your own

The same mechanism is public:

import { registerModule, ServiceAbstract } from "@ulyxie/cs-rest";

class Reports extends ServiceAbstract {
  async daily() {
    // gated() checks the target release and builds the URL; see Development.
    return this.session.get(await this.gated("GET", "/v1/webreports/{nickname}", "daily"));
  }
}

declare module "@ulyxie/cs-rest" {
  interface SessionModules {
    readonly reports: Reports;
  }
}

registerModule("reports", Reports);

await session.reports.daily();

Augment SessionModules, not Session: TypeScript merges an augmentation into an interface the package root re-exports, but not into a class.