# @emarketeer/ts-microservice-commons

> A common config for eMarketeer TypeScript microservice

Latest version **10.9.1** (published 2026-11-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install @emarketeer/ts-microservice-commons
pnpm add @emarketeer/ts-microservice-commons
yarn add @emarketeer/ts-microservice-commons
bun add @emarketeer/ts-microservice-commons
```

Provides the command `em-commons`.

## Health

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

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

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 10.9.1 |
| Published | 2026-11-26 |
| First published | 2020-10-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=20 |
| Dependencies | 18 |
| Unpacked size | 769.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | eMarketeer AB |
| Maintainers | tomashelmroos, ayankovsky, mbaudin |

## Links

- npm: https://www.npmjs.com/package/@emarketeer/ts-microservice-commons
- npm.io page: https://npm.io/package/@emarketeer/ts-microservice-commons

## Dependencies (18)

- [jest](https://npm.io/package/jest.md) 29.7.0
- [eslint](https://npm.io/package/eslint.md) 7.32.0
- [esbuild](https://npm.io/package/esbuild.md) ^0.25.2
- [ts-jest](https://npm.io/package/ts-jest.md) 29.4.9
- [cross-env](https://npm.io/package/cross-env.md) ^6.0.0
- [typescript](https://npm.io/package/typescript.md) 5.9.3
- [@types/jest](https://npm.io/package/@types/jest.md) 29.5.14
- [cross-spawn](https://npm.io/package/cross-spawn.md) ^7.0.1
- [jest-circus](https://npm.io/package/jest-circus.md) 29.7.0
- [jest-extended](https://npm.io/package/jest-extended.md) 3.2.4
- [eslint-plugin-jest](https://npm.io/package/eslint-plugin-jest.md) 27.9.0
- [eslint-plugin-import](https://npm.io/package/eslint-plugin-import.md) 2.32.0
- [eslint-plugin-sonarjs](https://npm.io/package/eslint-plugin-sonarjs.md) 0.11.0
- [@typescript-eslint/parser](https://npm.io/package/@typescript-eslint/parser.md) 5.62.0
- [eslint-config-airbnb-base](https://npm.io/package/eslint-config-airbnb-base.md) 15.0.0
- [eslint-plugin-eslint-comments](https://npm.io/package/eslint-plugin-eslint-comments.md) 3.2.0
- [@emarketeer/esbuild-plugin-tsc](https://npm.io/package/@emarketeer/esbuild-plugin-tsc.md) ^0.4.1
- [@typescript-eslint/eslint-plugin](https://npm.io/package/@typescript-eslint/eslint-plugin.md) 5.62.0

## Recent versions

- 10.9.1 (latest) — 2026-11-26
- 6.7.2 (release-6.x) — 2026-05-07
- 7.1.0-beta.42 (beta) — 2026-04-15
- 6.0.4-knex-fix.1 (knex-fix) — 2023-12-21
- 10.9.0 — 2026-10-29
- 10.8.1 — 2026-10-05
- 10.8.0 — 2026-09-23
- 10.7.0 — 2026-09-15
- 10.6.1 — 2026-09-02
- 10.6.0 — 2026-08-29
- 10.5.4 — 2026-08-13
- 10.5.3 — 2026-08-12
- 6.7.1 — 2026-05-07
- 10.5.2 — 2026-05-07
- 10.5.1 — 2026-05-07
- … 200 more at https://npm.io/package/@emarketeer/ts-microservice-commons/versions

## README

# eMarketeer TypeScript Microservice Commons

A common config for eMarketeer TypeScript microservice

### Contents ###

- Common `ts.config.json`
- Common webpack config
- Common parts of `serverless.yml` including Epsagon configuration
- Common eslint config. A property whose decorator says `nullable: true` must have `null` in its type — a nullable column hydrates as `null`, so write `T | null`, never `?: T` or plain `T`. Applies to MikroORM and TypeORM columns anywhere in a service; relations are exempt (DV-4596)
- Common jest config
- **AWS CDK v2 constructs and utilities** (see [CDK README](src/cdk/README.md))

### How to use ###

1. Clone `em-ts-microservice-starter`
2. Rename all occurences of `em-ts-microservice-starter` to whatever your service is going to be named


### Scripts ###

Following commands are available:

- `em-commons lint`
- `em-commons tsc`
- `em-commons jest`
- `em-commons deploy`
- `em-commons invoke-local`


#### jest ####

Usage:

```
em-commons jest <tier?> <pattern...> [jest flags...]
```

The first argument may be a tier: `unit`, `func`, or `full-cycle`. It selects that tier's
files precisely — `func` means `*.func.test.ts` or `*-func.test.ts`, not "any path containing
func".

Every positional argument after the tier narrows the run further. Terms are combined with
AND, so adding an argument can only ever shrink the selected set:

```
em-commons jest func              # every *.func.test.ts
em-commons jest func contacts     # only *.func.test.ts files whose path contains contacts
em-commons jest func contacts sendout
em-commons jest func 'contacts|billing'
```

Arguments from the first `-`-prefixed one onward are forwarded to jest verbatim, so
`em-commons jest func contacts -t 'creates'` filters by test name as usual. Every narrowing
term must therefore come before the first flag: anything positional after a flag goes straight
to jest, which ORs it back into the same pattern space and widens the run — for example
`em-commons jest func -t 'creates' contacts` runs the entire func tier OR anything matching
`contacts`, unit and full-cycle files included, against dev AWS. `--testPathPattern` itself is
rejected outright for the same reason.

Use `--listTests` to preview exactly which files a run will execute before starting it —
useful for `func` and `full-cycle`, which run against real dev AWS:

```
em-commons jest func contacts --listTests
```

Matching is case-insensitive against the absolute path, which is jest's own behaviour. In a
repo checked out at `~/dev/contacts-service` the term `contacts` therefore matches every
file.

Please note that tests will run in parallel. The shared jest config does a global
setup/teardown before/after running your tests, except for the `unit` tier — unit tests don't
need the dev-AWS setup that func and full-cycle tests do. The decision is driven by the
`EM_JEST_TIER` environment variable, which the CLI sets from the resolved tier word before
invoking jest:

```json
  "globalSetup": "<rootDir>/src/utils/func-test-setup.ts",
  "globalTeardown": "<rootDir>/src/utils/func-test-teardown.ts",
```

If a service supplies its own `jest.config.js` instead of the shared one, make the same
decision with `process.env.EM_JEST_TIER !== 'unit'`.

Example `func-test-setup.ts` file:

```typescript
import { addCurrentHostToSecurityGroup, initTestRuntime } from './test.utils'

const setup = async () => {
  await initTestRuntime()
  await addCurrentHostToSecurityGroup('...', ...)
}

export default setup
```

Example `func-test-teardown.ts` file:

```typescript
import { removeCurrentHostFromSecurityGroup } from './test.utils'

const teardown = async () => {
  await removeCurrentHostFromSecurityGroup('...', ...)
}

export default teardown
```


#### invoke-local ####

This command runs a lambda locally. 

Example usage:

`yarn invoke-local -f example-handler  -d "hello world"`

Where `-f` is the function name and `-d` is the request data.

More information on arguments is available here: https://www.serverless.com/framework/docs/providers/aws/cli-reference/invoke-local/

#### test local ####
In this directory:

`yarn build`

`yarn link`

In project directory:
`yarn link @emarketeer/ts-microservice-commons`

To unlink:
`yarn unlink @emarketeer/ts-microservice-commons`


#### release ####
Create a commit following the syntax of https://github.com/semantic-release/semantic-release#commit-message-format

## CDK v2 Support

This package now includes comprehensive AWS CDK v2 constructs and utilities for building microservices infrastructure.

See the [CDK Documentation](src/cdk/README.md) for:
- Lambda, DynamoDB, API Gateway, SQS, SNS, and EventBridge constructs
- Utility functions for naming, tagging, IAM policies, and logging
- Best practices and migration guidance from Serverless Framework
- Complete examples and usage patterns

Quick example:

```typescript
import { EmLambdaFunction, EmDynamoDBTable } from '@emarketeer/ts-microservice-commons/cdk'

const lambda = new EmLambdaFunction(this, 'MyFunction', {
  stage: 'dev',
  serviceName: 'my-service',
  functionName: 'handler',
  handler: 'index.handler',
  codePath: './dist/handlers/handler'
})

const table = new EmDynamoDBTable(this, 'MyTable', {
  stage: 'dev',
  serviceName: 'my-service',
  tableName: 'data',
  partitionKey: { name: 'id', type: AttributeType.STRING }
})
```

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