mattermost/webapp/platform/client
JG Heithcock df1c2920de
MM-65126: Allow admins to change CPA values for users from the system console (#33984)
* Update system_user_detail to enable editing of User Attributes

- This adds a `updateUserCustomProfileAttributesValues` method to client4 to allow updating attributes for a given userID, as a match to getUserCustomProfilesAttributesValues
- Fixed issue in saveCustomProfileAttributes where it used the version that did not take the passed in userId

* Fixes for tests

* Update saveCustomProfileAttribute mock in users.test.ts

The `saveCustomProfileAttribute` test was still using the old getCustomProfileAttributeValuesRoute instead of the same route that `getCustomProfileAttributeValues` uses.

* Adding e2e tests for editing User attributes (custom and system) in System Console

* Fix testing issue with selector for 'Authentication Method'

* workflows/server-ci-report.yml: security fixes by validating inputs (#33892)

* [MM-61899] Properly restrict users who previously shared a team from DMs/GMs when they no longer share a team. (#30094)

* [MM-61899] Properly restrict users who previously shared a team from DMs/GMs when they no longer share a team.

* Fix checks

* Fix test

* Fix i18n

* Added E2E tests

* Merge'd

* Add restricted DM check to more places

* Merge'd

* Restrict patching the channel (updating the channel)

* Update verbiage in the admin console

* Fix lint

* More tests

---------

Co-authored-by: Mattermost Build <build@mattermost.com>

* Mirror Postgres 14 docker image (#34009)

* ugprade to go 1.24.6 (#34004)

* Bump Postgres minimum supported version to 14 (#34010)

* Downgrade French language (#33826)

* Downgrade French language

* Update i18n.jsx

* Updates buildFieldAttrs to preseve existing attrs when editing a field (#33991)

* Updates buildFieldAttrs to preseve existing attrs when editing a field

* Fix preserve option issue for select/multiselect type fields

* Fix linter

---------

Co-authored-by: Miguel de la Cruz <miguel@ctrlz.es>

* MM-64423 - Removing the clear func on switch (#31214)

* MM-64423 - Removing the clear func on switch

* Select all teams by default

* Updating test

* Updating test

* Removing showFilterHaveBeenReset

* Removing search string

* Do not clear the search term

* Updating tests

---------

Co-authored-by: Mattermost Build <build@mattermost.com>

* Mm 65123 remove channel abac ff (#33953)

* MM-65123 - remove channel abac feature flag

* enable the channel scope access control to true

* fix linters

* adjust expected error in tests

* remove no longer needed comment

* Remove write_restrictable from core ABAC settings and fix channel access control logic

---------

Co-authored-by: Mattermost Build <build@mattermost.com>

* [MM-65837], [MM-65824] - Update Dependencies (#33972)

* Update github.com/mholt/archives

* Update github.com/spf13/viper

* make batch migration worker tests less flaky

---------

Co-authored-by: Jesse Hallam <jesse@mattermost.com>

* (a11y-test): team menu (#33998)

* MM-66071: Do not error on empty slice in /groups/names (#34021)

* Do not error on empty slice in /groups/names

If group_names is an empty slice, this should not be an invalid
parameter. We return what we were asked for: an empty array.

* Avoid requests to /groups/names if list is empty

If the list of group names is empty, we do not need to ask the server
for the corresponding groups: we already know it'll be an empty list.

* Fix ABAC not available for entry (#34027)

Automatic Merge

* Explicitly name Postgres container volume (#33954)

* Explicitly name Postgres container volume

* Remove unused server/docker-compose.yaml

This file doesn't seem to actually be used. When we run docker compose locally,
it uses docker-compose.makefile.yml merged with the output of
build/docker-compose-generator/main.go.

* Revert "Remove unused server/docker-compose.yaml"

This reverts commit 5a45965217.

* Update volume name

* Flag post API (#33765)

* Added enable/disable setting and feature flag

* added rest of notifgication settings

* Added backend for content flagging setting and populated notification values from server side defaults

* WIP user selector

* Added common reviewers UI

* Added additonal reviewers section

* WIP

* WIP

* Team table base

* Added search in teams

* Added search in teams

* Added additional settings section

* WIP

* Inbtegrated reviewers settings

* WIP

* WIP

* Added server side validation

* cleanup

* cleanup

* [skip ci]

* Some refactoring

* type fixes

* lint fix

* test: add content flagging settings test file

* test: add comprehensive unit tests for content flagging settings

* enhanced tests

* test: add test file for content flagging additional settings

* test: add comprehensive unit tests for ContentFlaggingAdditionalSettingsSection

* Added additoonal settings test

* test: add empty test file for team reviewers section

* test: add comprehensive unit tests for TeamReviewersSection component

* test: update tests to handle async data fetching in team reviewers section

* test: add empty test file for content reviewers component

* feat: add comprehensive unit tests for ContentFlaggingContentReviewers component

* Added ContentFlaggingContentReviewersContentFlaggingContentReviewers test

* test: add notification settings test file for content flagging

* test: add comprehensive unit tests for content flagging notification settings

* Added ContentFlaggingNotificationSettingsSection tests

* test: add user profile pill test file

* test: add comprehensive unit tests for UserProfilePill component

* refactor: Replace enzyme shallow with renderWithContext in user_profile_pill tests

* Added UserProfilePill tests

* test: add empty test file for content reviewers team option

* test: add comprehensive unit tests for TeamOptionComponent

* Added TeamOptionComponent tests

* test: add empty test file for reason_option component

* test: add comprehensive unit tests for ReasonOption component

* Added ReasonOption tests

* cleanup

* Fixed i18n error

* fixed e2e test lijnt issues

* Updated test cases

* Added snaoshot

* Updated snaoshot

* lint fix

* WIP

* lint fix

* Added post flagging properties setup

* review fixes

* updated snapshot

* CI

* Added base APIs

* Fetched team status data on load and team switch

* WIP

* Review fixes

* wip

* WIP

* Removed an test, updated comment

* CI

* Added tests

* Added tests

* Lint fix

* Added API specs

* Fixed types

* CI fixes

* API tests

* lint fixes

* Set env variable so API routes are regiustered

* Test update

* term renaming and disabling API tests on MySQL

* typo

* Updated store type definition

* Minor tweaks

* Added tests

* Removed error in app startup when content flaghging setup fails

* Updated sync condition:

* Flag message modal basE

* added post preview

* displaying options

* Adde comment input

* Updated tests and docs

* finction rename

* WIP

* Updated tests

* refactor

* lint fix

* MOved to data migration

* lint fix

* CI

* added new migration mocks

* Used setup for tests

* some comment

* Removed unnecesseery nil check

* Form validation

* WIP tests

* WIP tests

* WIP tests

* fix: mock content flagging config selector with correct reasons format

Co-authored-by: aider (anthropic/claude-sonnet-4-20250514) <aider@aider.chat>

* fix: add mock for getContentFlaggingConfig in flag post modal test

Co-authored-by: aider (anthropic/claude-sonnet-4-20250514) <aider@aider.chat>

* Updated error code order in API docs

* removed empty files

* Added tests

* lint fixes

* minor tweak

* lint fix

* type fix

* fixed test

* nit

* test enhancements

* API WIP

* API WIP

* creating values

* creating content flagging channel and properties

* Able to save properties

* Added another property field

* WIP

* WIP

* Added validations

* Added data validations and hidden post if confifgured to

* lint fixes

* Added API spec

* Added some tests

* Added tests for getContentReviewBot

* test: add comprehensive tests for getContentReviewChannels function

* Added more app layer tests

* Added TestCanFlagPost

* test: Add comprehensive tests for FlagPost function

* Added all app layer tests

* Removed a file that was reamoved downstream

* test: add content flagging test file

* test: add comprehensive tests for FlagContentRequest.IsValid method

* Added model tests

* test: add comprehensive tests for SqlPropertyValueStore.CreateMany

* test: add comprehensive tests for flagPost() API function

* Added API tests

* linter fix

* WIP

* sent post flagging confirmation message

* fixed i18n nissues

* fixed i18n nissues

* CI

* Updated test

* fix: reset contentFlaggingGroupId for test isolation in content flagging tests

* removed cached group ID

* removed debug log

* review fixes

* Used correct ot name

* CI

* Updated mobile text

* Handled JSON error

* fixerdf i18n

* CI

* Integrate flag post api (#33798)

* WIP

* WIP

* Added API call

* test: add test for Client4.flagPost API call in FlagPostModal

* fix: remove userEvent.setup() from flag post modal test

* test: wrap submit button click in act for proper state updates

* Updated tests

* lint fix

* CI

* Updated to allow special characters in comments

* Handled empty comment

* Used finally

* CI

* Fixed test

* Spillage card integration (#33832)

* Created getContentFlaggingFields API

* created getPostPropertyValues API

* WIP

* Created useContentFlaggingFields hook

* WIP

* WIP

* Added option to retain data for reviewers

* Displayed deleted post's preview

* DIsplayed all properties

* Adding field name i18n

* WIP - managing i18n able texts

* Finished displaying all fields

* Manual cleanup

* lint fixes

* team role filter logic fix

* Fixed tests

* created new API to fetch flagged posts

* lint fix

* Added new client methods

* test: add comprehensive tests for content flagging APIs

* Added new API tests

* fixed openapi spec

* Fixed DataSpillageReport tests

* Fixed PostMarkdown test

* Fixed PostPreviewPropertyRenderer test

* Added metadata to card renderer

* test fixes

* Added no comment placeholder

* Fixed test

* refactor: improve test mocking for data spillage report component

* test mock updates

* Updated reducer

* not resetting mocks

* WIP

* review fixes

* CI

* Fixed

* fixes

* Content flagging actions implementation (#33852)

* Added view detail button

* Created RemoveFlaggedMessageConfirmationModal modal

* Added key and remove flag request modal

* IMplemented delete flagged post

* Handled edge cases of deleting flagged post

* keep message

* UI integration

* Added WS event for post report update and handled deleted files of flagged post

* Added error handling in keep/remove forms

* i18n fixes

* Updated OpenAPI specs

* fixed types

* fixed types

* refactoring

* Fixed tests

* review fixes

* Added new property translations

* Improved test

* fixed test

* CI

* fixes

* CI

* fixed a test

* CI

---------

Co-authored-by: aider (anthropic/claude-sonnet-4-20250514) <aider@aider.chat>

* GH-34031: Add accessibility tests for Sidebar settings panel (#34041)

* Add accessibility tests for Sidebar settings panel

* Add aria snapshots and fix accessibility test expectations for sidebar settings

* Update system_user_detail to enable editing of User Attributes

- This adds a `updateUserCustomProfileAttributesValues` method to client4 to allow updating attributes for a given userID, as a match to getUserCustomProfilesAttributesValues
- Fixed issue in saveCustomProfileAttributes where it used the version that did not take the passed in userId

* Fixes for tests

* Update saveCustomProfileAttribute mock in users.test.ts

The `saveCustomProfileAttribute` test was still using the old getCustomProfileAttributeValuesRoute instead of the same route that `getCustomProfileAttributeValues` uses.

* Adding e2e tests for editing User attributes (custom and system) in System Console

* Fix testing issue with selector for 'Authentication Method'

* Fixes from PR suggestions

* Fix lint/export issues

* Fix playwright lint issue halting e2e smoke test

* Results from npm run prettier:fix (in e2e-tests/playwright folder)

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>
Co-authored-by: Devin Binnie <52460000+devinbinnie@users.noreply.github.com>
Co-authored-by: Alejandro García Montoro <alejandro.garciamontoro@gmail.com>
Co-authored-by: Jesse Hallam <jesse.hallam@gmail.com>
Co-authored-by: Amy Blais <29708087+amyblais@users.noreply.github.com>
Co-authored-by: Miguel de la Cruz <miguel@mcrx.me>
Co-authored-by: Miguel de la Cruz <miguel@ctrlz.es>
Co-authored-by: Asaad Mahmood <asaadmahmood@users.noreply.github.com>
Co-authored-by: Pablo Vélez <pablovv2012@gmail.com>
Co-authored-by: Eva Sarafianou <eva.sarafianou@gmail.com>
Co-authored-by: Jesse Hallam <jesse@mattermost.com>
Co-authored-by: sabril <5334504+saturninoabril@users.noreply.github.com>
Co-authored-by: Maria A Nunez <maria.nunez@mattermost.com>
Co-authored-by: Harrison Healey <harrisonmhealey@gmail.com>
Co-authored-by: Harshil Sharma <18575143+harshilsharma63@users.noreply.github.com>
Co-authored-by: aider (anthropic/claude-sonnet-4-20250514) <aider@aider.chat>
Co-authored-by: Mudit Sharma <ms1725@srmist.edu.in>
2025-10-06 15:41:29 -07:00
..
src MM-65126: Allow admins to change CPA values for users from the system console (#33984) 2025-10-06 15:41:29 -07:00
.eslintrc.json MM-52624/MM-57094 Update ESLint and our ESLint plugin (#26398) 2024-03-13 22:07:28 +00:00
babel.config.js Mono repo -> Master (#22553) 2023-03-22 17:22:27 -04:00
jest.config.js [MM-55294] Migrate jest v26 to v29 to speed up "web app CI PR / test" (#25192) 2023-11-07 11:41:26 +05:30
package.json Update web app and subpackage versions to 10.12.0 (#33771) 2025-09-02 09:08:48 -04:00
README.md Fix calling wrong method in README for ws (#26631) 2024-04-18 14:23:59 -04:00
setup_jest.ts [MM-55294] Migrate jest v26 to v29 to speed up "web app CI PR / test" (#25192) 2023-11-07 11:41:26 +05:30
tsconfig.build.json MM-52624/MM-57094 Update ESLint and our ESLint plugin (#26398) 2024-03-13 22:07:28 +00:00
tsconfig.json MM-52624/MM-57094 Update ESLint and our ESLint plugin (#26398) 2024-03-13 22:07:28 +00:00

Mattermost Client

npm version

This package contains the JavaScript/TypeScript client for Mattermost. It's used by the Mattermost web app and related projects.

Installation

JavaScript

$ npm install @mattermost/client

TypeScript

$ npm install @mattermost/client @mattermost/types

Usage

Rest Client

To use this client, create an instance of Client4, set the server URL, and log in, and then you can start making requests.

import {Client4} from '@mattermost/client';

const client = new Client4();
client.setUrl('https://mymattermostserver.example.com');

client.login('username', 'password').then((user) => {
    // ...
});

If you already have a session token or a user access token, you can call Client4.setToken instead of logging in.

import {Client4} from '@mattermost/client';

const client = new Client4();
client.setUrl('https://mymattermostserver.example.com');

client.setToken('accesstoken');

If needed, methods exist to set other headers such as the User-Agent (Client4.setUserAgent), the CSRF token (Client4.setCSRF), or any extra headers you wish to include (Client4.setHeader).

Methods of Client4 which make requests to the server return a Promise which does the following:

  • On success, the promise resolves to a ClientResponse<T> object which contains the the Response (response), a Map of headers (headers), and the data sent from the server (data).
  • On an error, the promise rejects with a ClientError which contains the error message and the URL being requested. If the error happened on the server, the status code and an error ID (server_error_id) are included.
let user;
try {
    user = (await client.getUser('userid')).data;
} catch (e) {
    console.error(`An error occurred when making a request to ${e.url}: ${e.message}`);
}

WebSocket Client

To use the WebSocket client, create an instance of WebSocketClient and then call its initialize method with the connection URL and an optional session token or user access token. After that, you can call the client's addMessageListener method to register a listener which will be called whenever a WebSocket message is received from the server.

import {WebSocketClient} from '@mattermost/client';

// If you already have an instance of Client4, you can call its getWebSocketUrl method to get this URL
const connectionUrl = 'https://mymattermostserver.example.com/api/v4/websocket';

// In a browser, the token may be passed automatically from a cookie
const authToken = process.env.TOKEN;

const wsClient = new WebSocketClient();
wsClient.initialize(connectionUrl, authToken);

wsClient.addMessageListener((msg) => {
    if (msg.event === 'posted') {
        console.log('New post received', JSON.parse(msg.data.post));
    }
});

Node.js

Note that WebSocketClient expects globalThis.WebSocket to be defined as it was originally written for use in the Mattermost web app. If you're using it in a Node.js environment, you should set globalThis.WebSocket before instantiating the WebSocketClient.

import WebSocket from 'ws';

if (!globalThis.WebSocket) {
    globalThis.WebSocket = WebSocket;
}

const wsClient = new WebSocketClient();

This can also be done using dynamic imports if you're using them.

if (!globalThis.WebSocket) {
    const {WebSocket} = await import('ws');
    globalThis.WebSocket = WebSocket;
}

const wsClient = new WebSocketClient();

Compilation and Packaging

As a member of Mattermost with write access to our NPM organization, you can build and publish this package by running the following commands:

npm run build --workspace=platform/client
npm publish --workspace=platform/client

Make sure to increment the version number in package.json first! You can add -0, -1, etc for pre-release versions.