# @elodigit/client

> ELO Digital Office REST API Client

Latest version **0.2.0-elo23.5.1** (published 2025-02-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install @elodigit/client
pnpm add @elodigit/client
yarn add @elodigit/client
bun add @elodigit/client
```

## Health

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

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

Warnings: low downloads; pre 1.0.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0-elo23.5.1 |
| Published | 2025-02-08 |
| First published | 2023-12-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=18.0.0 |
| Dependencies | 1 |
| Unpacked size | 3.3 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | info@nwbc.de |
| Maintainers | mausch97, msc_de |
| Keywords | elo, elo-api, rest-client, rest |

## Links

- npm: https://www.npmjs.com/package/@elodigit/client
- Repository: https://git.elo.com/npm/elodigit/client
- npm.io page: https://npm.io/package/@elodigit/client

## Dependencies (1)

- [axios](https://npm.io/package/axios.md) ^1.6.2

## Recent versions

- 0.2.0-elo23.5.1 (latest) — 2025-02-08
- 0.1.6 — 2024-04-15
- 0.1.5 — 2024-04-08
- 0.1.4 — 2024-04-05
- 0.1.3 — 2024-04-04
- 0.1.2 — 2023-12-16
- 0.1.1 — 2023-12-13

## README

<div align="center">
    <h1>ELO Client for IX REST API</h1>
    <p>
        <b>A simple and easy to use client for the <a href="https://www.elo.com/">ELO IX REST API</a></b>
    </p>
    <br>
</div>

## Features

- ✅ Typescript support

- ✅ Node.js and browser support

- ✅ Easy to use and setup with npm

- ✅ All enpoints available

- ✅ Reuse of existing browser sessions

- ✅ Async/await support

## Installation

```shell
npm install @elodigit/client
```

## Usage

Import and initialize a client using **ELO login credentials**.

```js
import { Client } from "@elodigit/client";

// Initializing a client
const client = new Client({
  IX_URL: "http://playground.com/ix-Solutions",
  USERNAME: "Administrator",
  PASSWORD: "elo",
});
await client.connect();
```

OR reuse an existing **ELO session** (only available in browsers for e.g. web apps)

```js
const client = new Client({
  IX_URL: "http://playground.com/ix-Solutions",
  USE_SESSION: true,
  REDIRECT: true,
});
await client.connect();
```

Make a request to any ELO API service/endpoint.

> See the complete list of endpoints in the [IX API Documentation](https://forum.elo.com/javadoc/ix/21/)

```js
import { EditInfoC, LockC } from '@elodigit/client';

const response = await client.ix.checkoutSord({
  objId: "1",
  editInfoZ: EditInfoC.mbSord,
  lockZ: LockC.NO,
});

const sord = response.result?.sord;
```

Each method returns a Promise which resolves the response.

```js
console.log(response);
```

```
{
  result: {
    sord: {
      TStamp: "2023.02.24.10.48.35",
      acl: "75PYJA",
      childCount: 0,
      doc: 33,
      guid: "(804CE708-8221-716F-7452-4FA201E7F858)",
      id: 1,
      kind: 1,
      mask: 0,
      name: "Solutions",
      ownerId: 0,
      parentId: 1,
      ...
    }
  }
}
```

### Client options

The `Client` supports the following options on initialization. These options are all keys in the single constructor parameter.

| Option             | Default value                             | Type                       | Required | Description                                                                                                                                                  |
| ------------------ | ----------------------------------------- | -------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `IX_URL`           | `undefined`                               | `string`                   | `true`   | Url to the IX service for connection e.g. https://playground.com/ix-Solutions                                                                                |
| `USERNAME`         | `undefined`                               | `string` \| `Resolver`     | `false`  | ELO username for basic authentication. This authentication method is discouraged in the browser because there is no CSRF protection.                         |
| `PASSWORD`         | `undefined`                               | `string` \| `Resolver`     | `false`  | ELO password for basic authentication                                                                                                                        |
| `TIMEOUT`          | `10000`                                   | `number`                   | `false`  | Connection timeout to ELO server in ms.                                                                                                                      |
| `USE_SESSION`      | `false`                                   | `boolean`                  | `false`  | Reuses an existing session that's provided by e.g. the Java Client, Web Client, Mobile Client. This option is only available in browsers (e.g. for web apps) |
| `REDIRECT`         | `true`                                    | `boolean`                  | `false`  | Redirects to the login page if session expires. Works only in combination with `USE_SESSION`                                                                 |
| `KEEP_ALIVE`       | `true`                                    | `boolean`                  | `false`  | Tries to keep the session alive by pinging the server every 60 seconds. Works only in combination with `USE_SESSION` or `SESSION_TICKET`                     |
| `CLIENT_INFO`      | `language=en` `country=US` `timezone=UTC` | `ClientInfo` \| `Resolver` | `false`  | The `ClientInfo` object containing the users language and country                                                                                            |
| `ELO_APPROVED`     | `undefined`                               | `string` \| `Resolver`     | `false`  | CSRF token to send approved REST requests                                                                                                                    |
| `WITH_CREDENTIALS` | `true`                                    | `boolean`                  | `false`  | Option is used to include cookies in the request. Required for option `USE_SESSION`                                                                          |
| `SESSION_TICKET`   | `undefined`                               | `string` \| `Resolver`     | `false`  | Session ticket that is used as Bearer-Header for authentication                                                                                              |
| `HEADERS`          | `undefined`                               | `Headers` \| `Resolver`    | `false`  | Additional custom headers for request                                                                                                                        |

`Resolver` are async functions that can be passed instead of static values to the client. They provide the ability of resolving values at runtime.

```js
async (options: ApiRequestOptions, config: OpenAPIConfig) => {
  return "Administrator";
};
```

### Enable CORS

To enabled CORS add the "Access-Control-Allow-\*" headers as entries in the Indexserver **config.xml**. At least "Access-Control-Allow-Origin" is requried. Example:

> ```xml
> <entry key="Access-Control-Allow-Origin">*</entry>
> ```

### TypeScript

This package contains type definitions for all request parameters and responses.

### Constants

All ELO constants are available for e.g. endpoint requests.
LockC.NO, SordC.mbAllIndex, etc.

## Examples

### Upload streams - Checkin a document
To upload a document/file, first upload the file to a temporary storage on the server using `bUtility.upload`. Then, use a subsequent checkin request to associate the temporary file with the repository object. This example can be applied to any file upload. You upload the file to a temporary storage on the server in order to get the `streamId` and then use it in the following steps for other actions.

Node.js example to upload a file:
```ts
import { EditInfoC } from "@elodigit/client";
import { readFileSync } from "fs";

// Path to the file we want to upload
const filePath = "/my/file/path.txt";

// Read file into buffer and convert to Blob for upload
const fileBuffer = await readFileSync(filePath);
const fileBlob = new Blob([fileBuffer]);

// Upload file to ELO and get a temporary streamId
const fileUploadResult = await client.bUtility.upload(fileBlob);
const streamId = fileUploadResult.result?.streamId;
```

Broser example to upload a file:
```ts
import { EditInfoC } from "@elodigit/client";

// File we want to upload
const fileInput = document.getElementById('fileInput') as HTMLInputElement;

if (!fileInput.files || fileInput.files.length === 0) {
  console.log("No file selected");
  return;
}

const file = fileInput.files[0];

// Convert to Blob for upload
const fileBlob = new Blob([fileBuffer]);

// Upload file to ELO and get a temporary streamId
const fileUploadResult = await client.bUtility.upload(fileBlob);
const streamId = fileUploadResult.result?.streamId;
```

Folloing applies to both Node.js and Browser:
``` ts
// Create a new document in ELO (only metadata at this point)
const createDocResult = await client.ix.createDoc({
  parentId: "1",
  maskId: "0",
  editInfoZ: EditInfoC.mbSordDocAtt,
});

const sord = createDocResult.result?.sord;

if (!sord) {
  console.log("No sord found");
  return;
}

sord.name = "My Sord Name";

// Finally, attach the uploaded file to the document metadata
await client.ix.checkinDocEnd({
  sord,
  sordZ: EditInfoC.mbAll,
  document: {
    docs: [
      {
        version: "1.0",
        comment: "My Comment",
        contentType: "text/plain",
        fileData: {
          stream: {
            streamId, // <- Link to previously uploaded file
          },
        },
      },
    ],
  },
});
```

### Create path
To create a path in ELO, you can use the `checkinSordPath` method. This method creates a path in the repository and returns the sord ids of the created path segments.
```ts
import { Sord, SordC } from "@elodigit/client";

const arcPath = "the/path/to/create";

// Create an array of Sord objects for each path segment
const sords: Sord[] = arcPath.split("/").map<Sord>((name) => ({
  name,
}));

// Check in the path and get the sord ids
const result = await client.ix.checkinSordPath({
  parentId: "1",
  sords,
  sordZ: SordC.mbAll,
});
const sordIds = result.result;

console.log("Sord ids", sordIds);
```

### Execute Registered Function
Execute a registered function in ELO. The function name and parameters are passed as arguments to the `executeRegisteredFunctionString` method. Alternatively, you can use the `executeRegisteredFunction` method to pass the parameters as an Any object.
``` ts
const param = {
  param1: "value1",
  param2: "value2",
};

const result = await client.ix.executeRegisteredFunctionString({
  functionName: "RF_my_demo_function",
  param: JSON.stringify(param),
});
console.log(result);
```

## Versioning

The versioning follows the NPM standard versioning with an ELO IX version suffix structure:

```
<NPM_MAJOR>.<NPM_MINOR>.<NPM_PATCH>-elo<ELO_MAJOR>.<ELO_MINOR>.<ELO_PATCH>
```

Example for ELO IX Version 23.05.001 and your own version 1.0.0:

```
1.0.0-elo23.05.001
```

Meaning:

- `1.0.0` → Version of the generator that was used to generate the client
- `-elo23.05.001` → Indicates that this client was generated using ELO IX Version 23.05.001 and is compatible with it

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