# sengi-client

> A library that simplifies calling a Sengi-based service.

Latest version **10.0.0** (published 2021-03-14) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install sengi-client
pnpm add sengi-client
yarn add sengi-client
bun add sengi-client
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 10.0.0 |
| Published | 2021-03-14 |
| First published | 2020-10-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 42.6 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Karl Hulme |
| Maintainers | karlhulme |

## Links

- npm: https://www.npmjs.com/package/sengi-client
- Repository: https://github.com/karlhulme/sengi
- Homepage: https://github.com/karlhulme/sengi#readme
- Issues: https://github.com/karlhulme/sengi/issues
- npm.io page: https://npm.io/package/sengi-client

## Dependencies (2)

- [node-fetch](https://npm.io/package/node-fetch.md) 2.6.1
- [@types/node-fetch](https://npm.io/package/@types/node-fetch.md) 1.6.9

## Recent versions

- 10.0.0 (latest) — 2021-03-14
- 9.1.0 — 2021-02-28
- 9.0.0 — 2021-02-27
- 8.5.0 — 2021-02-24
- 8.4.4 — 2021-02-21
- 8.4.3 — 2021-02-17
- 8.4.2 — 2021-02-04
- 8.4.1 — 2021-02-04
- 8.4.0 — 2021-02-04
- 8.3.0 — 2021-02-03
- 8.2.0 — 2021-02-03
- 8.1.1 — 2021-01-20
- 8.1.0 — 2021-01-20
- 8.0.0 — 2021-01-20
- 7.7.3 — 2021-01-17
- … 39 more at https://npm.io/package/sengi-client/versions

## README

# Sengi Client
 
> This package is part of the [Sengi](https://github.com/karlhulme/sengi) family.

![](https://github.com/karlhulme/sengi/workflows/CD/badge.svg)
[![npm](https://img.shields.io/npm/v/sengi-client.svg)](https://www.npmjs.com/package/sengi-client)

A client library for reading and writing documents managed by a Sengi-based service.

## Installation

```bash
npm install sengi-client
```

## Usage

The `SengiClient` provides a simple Promised-based interface for accessing a Sengi-based service.  It automatically retries transitory errors.

To instantiate a `SengiClient` you have to provide the following parameters:

* **fetch** - A fetch function.  If undefined, the node-fetch library is used by default.  (This property is used during testing and it's unlikely you need to specify this.)

* **roleNames** - An array of the role names held by the user that is making the request.

* **retryIntervals** - An array of integers that specify the time to wait before trying again.  If undefined, the default retry strategy is [100, 250, 500, 1000, 2000, 4000, 8000, 15000, 30000].

* **url** - The url of the Sengi service.

* **logToConsole** - True if the client should log out the contents of any fetch calls just before they are invoked.  A call is only logged once, even if it has to be repeated due to transitory errors.

```javascript
const client = new SengiClient({
  roleNames: ['admin'],
  url: 'https://localhost:1234'
})
```

## Methods

This section describes the methods available on the sengi client.

Document Methods | Description
---|---
createDocument | Create a new document using a DocType constructor.
deleteByDocumentId | Delete a document using it's id.
getDocumentById | Retrieve a single document using the documents id.
operateOnDocument | Invoke a DocType operation on a document.
patchDocument | Apply a merge patch to a document.
queryAllDocuments | Retrieve all the documents in a collection, specifying the fields to include in the result.
queryDocumentsByFilter | Retrieve the documents in a collection that match a DocType filter, specifying the fields to include in the result.
queryDocumentsByIds | Retrieve the documents in a collection with the given ids, specifying the fields to include in the result.
upsertDocument | Insert a new document (without calling the DocType constructor) or replace an existing document in the collection.

All of the above methods allow you to supply the following parameters:

* **pathComponents** - An array of path components that will be added to the url used to initialise the Sengi-Client.
* **roleNames** - An array of data service role names.  If supplied these are the only role names that will be sent with the request.  If omitted, the role names supplied with the Sengi-Client was constructed will be used.

Enum Methods | Description
---|---
getEnumTypeItems | Retrieve the items that are defined within an enum identified by it's fully qualified name.

## Development

Written in Typescript.

Tests are written using Jest with 100% coverage.

```bash
npm test
```

The errors are tested using a mock Sengi service and the supertest framework.

The happy route is tested by spinning up a live Sengi service (using sengi-express) and hitting the end-points over the wire.

## Continuous Deployment

Any pushes or pull-requests on non-master branches will trigger the test runner.

Any pushes to master will cause the family of libraries to be re-published.

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