# studiokit-caliper-js

> Common library of services used to instrument applications with Caliper JS

Latest version **1.0.27** (published 2025-11-11) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install studiokit-caliper-js
pnpm add studiokit-caliper-js
yarn add studiokit-caliper-js
bun add studiokit-caliper-js
```

## Health

**Score 45/100 (D)** — status: stable.

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

Warnings: low downloads; no esm support.

Negative: insecure dependencies.

## Facts

| | |
|---|---|
| Version | 1.0.27 |
| Published | 2025-11-11 |
| First published | 2017-04-04 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 9 |
| Unpacked size | 46.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | jkdufair, tragessere, itap-informatics, lilycarlson, caseywpurdue, gregstrasters, lane174, wgrauvog, builtbywill |
| Keywords | purdue, purdue-tlt, caliper, caliperjs, caliper-js, imsglobal |

## Links

- npm: https://www.npmjs.com/package/studiokit-caliper-js
- Repository: https://github.com/purdue-tlt/studiokit-caliper-js
- Homepage: https://github.com/purdue-tlt/studiokit-caliper-js#readme
- Issues: https://github.com/purdue-tlt/studiokit-caliper-js/issues
- npm.io page: https://npm.io/package/studiokit-caliper-js

## Dependencies (9)

- [uuid](https://npm.io/package/uuid.md) ^11.1.0
- [debug](https://npm.io/package/debug.md) ^4.3.1
- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [moment](https://npm.io/package/moment.md) ^2.30.1
- [bluebird](https://npm.io/package/bluebird.md) ^3.7.2
- [caliperjs](https://npm.io/package/caliperjs.md) git+https://gitlab.com/purdue-informatics/studiokit/caliper-js.git#1.1.1
- [@sentry/browser](https://npm.io/package/@sentry/browser.md) ^10.19.0
- [standard-http-error](https://npm.io/package/standard-http-error.md) ^2.0.1
- [local-storage-fallback](https://npm.io/package/local-storage-fallback.md) ^4.1.1

## Recent versions

- 1.0.27 (latest) — 2025-11-11
- 1.0.26-alpha.4 (alpha) — 2025-10-30
- 1.0.26 — 2025-11-11
- 1.0.26-alpha.3 — 2025-10-21
- 1.0.26-alpha.2 — 2025-10-21
- 1.0.26-alpha.1 — 2025-10-16
- 1.0.25 — 2024-06-07
- 1.0.24 — 2024-04-10
- 1.0.23 — 2021-04-12
- 1.0.22 — 2021-03-16
- 1.0.21 — 2020-10-26
- 1.0.20 — 2020-10-14
- 1.0.19 — 2020-06-24
- 1.0.18 — 2017-08-08
- 1.0.17 — 2017-07-13
- … 12 more at https://npm.io/package/studiokit-caliper-js/versions

## README

# studiokit-caliper-js

[![Coverage Status](https://coveralls.io/repos/purdue-tlt/studiokit-caliper-js/badge.svg?branch=master)](https://coveralls.io/r/purdue-tlt/studiokit-caliper-js?branch=master)

**studiokit-caliper-js** is a common library of services for implementing applications with the [caliper-js](https://github.com/purdue-tlt/caliper-js) Javascript client for [IMS Global Caliper Analytics](http://www.imsglobal.org/caliper) (an implementation of the Caliper SensorAPI™).

**studiokit-caliper-js** current supports **Caliper v1.0**

## Features

* **Persistent Queue**: Events and Entities are saved to a queue that is persisted to localStorage, or another storage method of your choice.
* **Convenience Methods**: Easily start and end Sessions with simplified methods.
* **Session Keep-Alive**: The current Session's `dateModified` is periodically updated and sent to the EventStore to track Session activity before it is ended.
* **Session Timeout**: Sessions are ended automatically (timed out) when the user is idle (no mouse, touch, keyboard, scroll events) or away from the app for longer than the `sessionTimeoutThreshold`. 

## Installation

```
npm install --save studiokit-caliper-js
```

## Implementation

### With Node

```
const StudioKit = require('studiokit-caliper-js');
// or
import StudioKit from 'studiokit-caliper-js';

const options = {...}; // see below
const caliperService = new StudioKit.CaliperService(options);
```

### Without Node

```
npm run build
```

This will create a browserified file in the `dist` folder.
Add this script to your HTML file like `<script src="dist/studiokit-caliper.js"></script>`.
You can then access the JavaScript global parameter `StudioKit`.

## Options

| name |  required | type | description | default value |
| --- | --- | --- | --- | --- |
| sensorId | **true** | string | The caliper-js Sensor Id |  |
| sensorOptions | **true** | Object | The caliper-js Sensor Options [see the node https docs](https://nodejs.org/api/https.html#https_https_request_options_callback) |  |
| appId | **true** | string (IRI) | The JSON-LD `@id` of the Caliper SoftwareApplication | |
| appName | **true** | string | The name of Caliper SoftwareApplication | |
| getToken | **true** | function | A function that is expected to return a `Promise`, which when complete, returns an OAuth Access Token response containing the following properties: <ul><li>`accessToken`: the OAuth token for the EventStore</li><li>`expires`: A date string representing when the token expires.</li></ul> | |
| storageService | **true** | Object | An object (or service) that provides data persistence, acting as a key-value store, e.g. LocalStorage. Must implement the following methods: <ul><li>`function getItem(key)`: return a saved object by key.</li><li>`function setItem(key, value)`: save an object by key.</li><li>`function removeItem(key)`: remove an object by key.</li></ul> | An in-memory placeholder, does not actually persist data. |
| autoSend | false | boolean | Whether or not to send the queue of Caliper events on a timer. | true |
| sendInterval | false | number (milliseconds) | How often a request containing the current queue of Caliper events is sent, enabled by `autoSend`. | `1000 * 10` // 10 seconds |
| sessionIriPrefix | false | string | The value with which to prefix all Caliper Session `@id` values. Will be prefixed to form valid IRI, e.g. `${sessionIriPrefix}/session/${uuid}` | `null`, defaults to `appId` |
| sessionTimeoutThreshold | false | number (milliseconds) | The amount of time a Session can be idle (e.g. no mouse, keyboard, touch, or scroll events) before the Session is ended as `TIMED_OUT`. | `1000 * 60 * 30` // 30 minutes |
| sessionKeepAliveThreshold | false | number (milliseconds) | How often activity should trigger the Session to be "kept alive" by having its `dateModified` updated, and sent to the EventStore. | `1000 * 60 * 15`  // 15 minutes |
| activityUpdateThreshold | false | number (milliseconds) | How often the activity sent to `onActivity()` (e.g. mouse, keyboard, touch, or scroll events, or manual calls) is processed. | `1000 * 60`  // 1 minute |
| onError | false | function | A function that is called when an error is encountered, e.g. `function(err) {}` | `null` |

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