# @mvf/servicer

> ## Usage

Latest version **5.9.4** (published 2025-04-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install @mvf/servicer
pnpm add @mvf/servicer
yarn add @mvf/servicer
bun add @mvf/servicer
```

## Health

**Score 40/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.9.4 |
| Published | 2025-04-15 |
| First published | 2019-11-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 7 |
| Unpacked size | 227 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | dovydas.rupsys, michaelkingmvf, john.felton, jrrsmvf, russellwind-mvf, laleh.koupaei, arnicsm, gijserensteinmvf, btmvf |

## Links

- npm: https://www.npmjs.com/package/@mvf/servicer
- npm.io page: https://npm.io/package/@mvf/servicer

## Dependencies (7)

- [yargs](https://npm.io/package/yargs.md) ^17.3.1
- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [commander](https://npm.io/package/commander.md) ^9.0.0
- [@mvf/logger](https://npm.io/package/@mvf/logger.md) ^1.0.3
- [@types/yargs](https://npm.io/package/@types/yargs.md) ^17.0.8
- [@types/lodash](https://npm.io/package/@types/lodash.md) ^4.14.178
- [@apollo/datasource-rest](https://npm.io/package/@apollo/datasource-rest.md) ^6.3.0

## Recent versions

- 5.9.4 (latest) — 2025-04-15
- 4.0.2 (servicer-v1) — 2022-02-10
- 5.9.3 — 2025-04-15
- 5.9.2 — 2025-04-15
- 5.9.1 — 2025-04-02
- 5.8.0 — 2024-11-28
- 5.7.1 — 2024-11-28
- 5.7.0 — 2024-06-25
- 5.6.11 — 2024-04-03
- 5.6.10 — 2024-04-02
- 5.6.9 — 2024-03-28
- 5.6.8 — 2024-03-28
- 5.6.7 — 2024-03-28
- 5.6.6 — 2024-03-28
- 5.6.5 — 2024-03-28
- … 41 more at https://npm.io/package/@mvf/servicer/versions

## README

# Servicer package

## Usage

* [Introduction](./docs/introduction.md)
* [express-api](https://bitbucket.org/mvfglobal/servicer-express/src/master/README.md)
* [express-apollo](https://bitbucket.org/mvfglobal/servicer-apollo/src/master/README.md)
* [express-exec](https://bitbucket.org/mvfglobal/servicer-exec/src/master/README.md)
* [express-sqs](https://bitbucket.org/mvfglobal/servicer-sqs/src/master/README.md)

### To install the package
Run `npm install @mvf/servicer`

## Contributing

### Setup
- Run `make` to build the container
- Run `make shell` to enter the container
- Run `npm install` to install dependencies

Refer to package.json for commands

### After merging
After you have merged a PR to master, you need to rebuild and publish your changes.

1. Checkout master `git checkout master && git pull`
2. Use one of the following make publish commands to publish changes:
    - `make publish kind=patch` - Use this if your change is a bug fix and is backwards compatible.
    - `make publish kind=minor` - Use this if your change adds new functionality and is backwards compatible.
    - `make publish kind=major` - Use this if your change is not backwards compatible.

## Setup Tests

- In RestEvents, CommandEvents or BackendEvents, add import `bindSimulator`:
    - `import { bindSimulator } from '@mvf/servicer';`
- Then use `bindSimulator` to create a `simulate` function:
    - `export const simulate = bindSimulator(RestEvents);`
- In the tests it is then possible to call actions using the simulate function:
  `const result = await simulate(ActionConstant, { headers }, { body });`

### Success response
```ts
const result = await simulate(ActionConstant, { headers }, { body });
result.output.output; // will contain response from Action
```

### Error response

#### Response with Status code & Error message
```ts
const err = await catchAsyncError(async () => {
  await simulate(ActionConstant,{headers},{body});
});

expect(err.status).toBe(400);
expect(err.message).toBe('Error message');
```
#### Response with type of error
```ts
await expect(simulate(ActionConstant, {headers}, {body})).rejects.toThrow(BadRequestError);
```

---
_Source: https://npm.io/package/@mvf/servicer · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
