Files
zeekay c671872b0b The packages this repo publishes carry our scope
webapp/platform publishes six packages and the channels app carries a seventh
in-tree, and every one of them went out under @mattermost — types, client,
components, shared, eslint-plugin, compass-icons and mattermost-redux — while
the plugin that consumes them already asks for @hanzoteam/types and
@hanzoteam/client by name. It could not build: it was asking a registry for a
package nobody publishes.

They are @hanzoteam/* now, and mattermost-redux is @hanzoteam/redux, moved to
src/packages/@hanzoteam/redux so the directory matches the alias that always
pointed there.

@mattermost/calls-common and @mattermost/desktop-api stay. Those are published
by someone else and resolved from npm; renaming a package we merely consume
would name a thing that does not exist.

The jest moduleNameMapper entries needed doing by hand — they spell the scope
inside a regex, so a sweep over the plain name walks straight past them, and a
missed one fails at require time rather than at build.
2026-08-28 23:44:39 -07:00

1.8 KiB
Raw Permalink Blame History

CLAUDE: platform/client/ (@hanzoteam/client)

Purpose

  • Implements the Client4 HTTP layer and WebSocket client used by all Mattermost web apps and plugins.
  • Source of truth for API endpoint definitions and low-level networking helpers.

Structure

  • src/client4.ts – REST endpoints, auth handling, retries.
  • src/websocket.ts – WebSocket manager for real-time events.
  • src/helpers.ts / errors.ts – shared logic for response parsing and error types.

Client4 Usage

Singleton HTTP client for all Mattermost API requests. Methods return Promise<ClientResponse<T>>:

interface ClientResponse<T> {
    response: Response;  // Fetch Response object
    headers: Headers;    // Response headers
    data: T;            // Parsed response data
}

Usage Rules

  1. Actions Only: Client4 should only be called from Redux actions, never directly in components.
  2. Error Handling: Always handle errors appropriately.

Adding New Endpoints

Add new API methods to client4.ts. Keep signatures Promise-based.

getSomething = (id: string) => {
    return this.doFetch<SomethingType>(
        `${this.getSomethingRoute(id)}`,
        {method: 'get'},
    );
};

Error Handling

  • Throw ClientError (see errors.ts) with enough context.
  • Include forceLogoutIfNecessary logic upstream in calling actions; do not couple that here.

WebSocket Client

websocket.ts provides real-time event handling, connection management, and automatic reconnection. Accessed via WebSocketClient wrapper in web app.

Guidelines

  • Follow webapp/STYLE_GUIDE.md → Networking.
  • Each new server API must be added here first, including TypeScript types and tests.
  • Never reference React or browser globals—this package must run in Node.