# @contrast/core

> Preconfigured Contrast agent core services and models

Latest version **1.68.0** (published 2026-08-19) · SEE LICENSE IN LICENSE license · 0 weekly downloads

## Install

```sh
npm install @contrast/core
pnpm add @contrast/core
yarn add @contrast/core
bun add @contrast/core
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 1.68.0 |
| Published | 2026-08-19 |
| First published | 2022-06-16 |
| Weekly downloads | 0 |
| License | SEE LICENSE IN LICENSE |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=18.7.0 |
| Dependencies | 5 |
| Unpacked size | 12.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Contrast Security |
| Maintainers | tough-griff, chrisdunne, contrast_admin, jcolekaplan, contrastsec, mhenry-contrast, nbuckwalt |

## Links

- npm: https://www.npmjs.com/package/@contrast/core
- npm.io page: https://npm.io/package/@contrast/core

## Dependencies (5)

- [@contrast/perf](https://npm.io/package/@contrast/perf.md) 1.4.2
- [@contrast/common](https://npm.io/package/@contrast/common.md) 1.42.0
- [@contrast/logger](https://npm.io/package/@contrast/logger.md) 1.41.0
- [@contrast/patcher](https://npm.io/package/@contrast/patcher.md) 1.40.0
- [@contrast/fn-inspect](https://npm.io/package/@contrast/fn-inspect.md) 5.0.2

## Recent versions

- 1.68.0 (latest) — 2026-08-19
- 1.67.0 — 2026-07-31
- 1.66.0 — 2026-07-13
- 1.65.0 — 2026-06-16
- 1.64.0 — 2026-06-12
- 1.63.3 — 2026-06-01
- 1.63.2 — 2026-04-17
- 1.63.1 — 2026-03-31
- 1.63.0 — 2026-03-26
- 1.62.1 — 2026-03-06
- 1.62.0 — 2026-03-03
- 1.61.0 — 2026-02-04
- 1.60.1 — 2026-01-23
- 1.60.0 — 2025-12-16
- 1.59.1 — 2025-12-02
- … 89 more at https://npm.io/package/@contrast/core/versions

## README

# `@contrast/core`

Discovers Contrast configuration data (yaml, env vars, etc) and preconfigures a common set of APIs to be used for agent and tooling development.

## Basic Usage

The module exports a factory function.

```typescript
const core = require('@contrast/core')();

```
### What You Get

- Logging

  ```typescript
  core.logger.info('...');
  ```

  See more about the `@contrast/logger` service [here](../logger/README.md).

- Monkey-patching

  ```typescript
  core.patcher.patch(res, 'end', {
    name: 'http.ServerResponse.end',
    patchType: 'http-things',
    pre(data) {
      // ...
    }
  });
  ```

  See more about the `@contrast/patcher` service [here](../patcher/README.md).
  

- Code rewriting

  ```typescript
  core.rewriter.addTransforms({
    CallExpression(path, state) {
      // ...
    };
  });
  core.rewriter.rewrite('function() { ...');
  ```

  See more about the `@contrast/rewriter` service [here](../rewriter/README.md).


- Dependency hooks

  ```typescript
  core.depHooks.resolve({ name: 'http' }, http => {
    // implemention details
  });
  ```

  See more about the `@contrast/dep-hooks` service [here](../dep-hooks/README.md).


- Models and factories

  The construction of model data _can_ rely on configuration and therefore can be stateful. So, we provide the models and their factories as services that can be used by consumers as if static.

  ```typescript
  // stackframe filtration is configurable, thus stateful
  const snap = core.models.StacktraceFactory.createSnapshot();
  const frames = snap();
  ```

  See more about the `@contrast/models` service [here](../models/README.md).

- Report messages

  ```typescript
  // configuration will tell which reporters become active
  core.reporters.install();
  core.messages.emit('ProtectInputTracingEvent', { ... });
  ```

  See more about the `@contrast/reporter` service [here](../reporter/README.md).

- Other stuff

  There are some utility-type functions that rely on configuration state.

  ```typescript
  // This uses core.config.stack_trace_filters (new to v5)
  core.isAgentPath('/foo'); 
  ```

## Related

- `@contrast/agentify`: Integrate core services and instrumentation into an application. See more [here](../agentify/README.md).

<br><br>

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