# @reapit/api-key-verify

> Common Package for Reapit Foundation

Latest version **0.0.3** (published 2021-07-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install @reapit/api-key-verify
pnpm add @reapit/api-key-verify
yarn add @reapit/api-key-verify
bun add @reapit/api-key-verify
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2021-07-07 |
| First published | 2021-06-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 60.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Reapit Ltd |
| Maintainers | wmcvayreapit, dawsonscott |

## Links

- npm: https://www.npmjs.com/package/@reapit/api-key-verify
- Repository: git@github.com:reapit/foundations
- npm.io page: https://npm.io/package/@reapit/api-key-verify

## Dependencies (4)

- [aws](https://npm.io/package/aws.md) ^0.0.3-2
- [@aws/dynamodb-data-mapper](https://npm.io/package/@aws/dynamodb-data-mapper.md) ^0.7.3
- [@reapit/foundations-ts-definitions](https://npm.io/package/@reapit/foundations-ts-definitions.md) 1.3.7
- [@aws/dynamodb-data-mapper-annotations](https://npm.io/package/@aws/dynamodb-data-mapper-annotations.md) ^0.7.3

## Recent versions

- 0.0.3 (latest) — 2021-07-07
- 0.0.2 — 2021-07-07
- 0.0.1 — 2021-06-28

## README

# Api-key-verify 

## Install

```bash
$ yarn add @reapit/api-key-verify
```

### Get the api key

```ts
import { getApiKey } from '@reapit/api-key-verify'
import { DynamoDB } from 'aws-sdk'
import { DataMapper } from '@aws/dynamodb-data-mapper'

const dynamoMapper = new DataMapper({
  client: new DynamoDB(),
})

const apiKey = getApiKey(dynamoMapper)('x-api-key-from-your-header')

console.log(apiKey) // undefined || ApiKeyModel

```

### validating apiKey

this function will return the api key or throw an exception

```ts
import { resolveApiKey } from '@reapit/api-key-verify'
import { DynamoDB } from 'aws-sdk'
import { DataMapper } from '@aws/dynamodb-data-mapper'

const dynamoMapper = new DataMapper({
  client: new DynamoDB(),
})

export const myLambda = (req, res) => {

  try {
    const apiKey = resolveApiKey(dynamoMapper)(req.headers['x-api-key'])
  } catch(e: ApiKeyExpiredException | ApiKeyNotFoundException) {
    res.statusCode(401)
    res.send(e.message) // not found || expired
  }
}

```

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