Skip to content

MarshallRJ/shesha-node-client

Repository files navigation

shesha-node-client

A Node.js/TypeScript client for the Shesha REST API. Provides typed services for authentication and entity querying, with integration tests that can be used as stress/load tests against a Shesha instance.

Prerequisites

  • Node.js 18+
  • npm 9+

Installation

npm install

Configuration

All tests read connection details from tests/config.json. Edit this file to point at your Shesha instance before running any tests.

tests/config.json

{
  "baseUrl": "https://your-shesha-instance.example.com",
  "username": "admin",
  "password": "your-password"
}
Field Description
baseUrl Root URL of your Shesha API (no trailing slash)
username Username or email address of the account used to authenticate
password Password for the above account

tests/config.json is not committed to source control — keep credentials out of git.

Running tests

# Run all tests once
npm test

# Run only the entity tests once
npm test -- --testPathPattern=entities

Stress testing a Shesha instance

The entities test (tests/entities.test.ts) fetches all Shesha.Core.Person records in batches of 50 across 10 concurrent runs. This makes it a useful load/stress test for measuring how a Shesha instance handles sustained parallel API traffic.

What the test does

  • Authenticates once using the credentials in tests/config.json
  • Spawns 10 concurrent fetch loops, each paging through every Person record in batches of 50
  • Asserts that the total fetched equals the server-reported totalCount on every run
  • Logs per-batch and per-run progress to the console

Running the stress test loop (1 000 iterations)

npm run test:entities:loop

This runs the entities test 1 000 times sequentially via scripts/loop-test.js. Each iteration prints a counter (=== Loop N/1000 ===) so you can track progress.

To change the number of iterations, edit scripts/loop-test.js:

const LOOPS = 1000; // change this value

Tuning the test parameters

Both values are constants at the top of tests/entities.test.ts:

const ENTITY_TYPE = 'Shesha.Core.Person'; // entity to query
const BATCH_SIZE = 50;                    // records per page (maxResultCount)

Increase BATCH_SIZE for fewer, larger requests. Decrease it for more, smaller requests. Change ENTITY_TYPE to stress-test a different entity.

The number of concurrent runs per iteration is controlled by the array passed to Promise.all near the bottom of the test:

await Promise.all([1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(run => runFetch(run)));

Add or remove entries to increase or decrease parallelism.

Project structure

src/
  auth/           AuthService — login and token management
  entities/       EntityService — getAll with pagination
  types/          Shared TypeScript interfaces
tests/
  config.json     Instance connection details (edit before running)
  entities.test.ts  Entity pagination + stress test
scripts/
  loop-test.js    Runs the entities test N times sequentially

Building

npm run build

Output is written to dist/.

About

A node client to access a shesha api

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages