Skip to content
This repository was archived by the owner on Sep 2, 2022. It is now read-only.

Commit f7bb72b

Browse files
committed
Add first versions of the middleware packages
Three npm packages: - `@apilytics/express` for Express - `@apilytics/next` for Next.js - `@apilytics/core` for shared functionality and other Node frameworks 100% test coverage, tested against Node.js 12, 14, 16, and 17.
1 parent 515439e commit f7bb72b

33 files changed

Lines changed: 6273 additions & 0 deletions

.eslintrc.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/* eslint @typescript-eslint/no-var-requires: "off" */
2+
const builtins = require('module').builtinModules.join('|');
3+
4+
module.exports = {
5+
env: {
6+
node: true,
7+
},
8+
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
9+
parser: '@typescript-eslint/parser',
10+
plugins: ['@typescript-eslint', 'simple-import-sort', 'import'],
11+
rules: {
12+
'@typescript-eslint/ban-ts-comment': 'off',
13+
'@typescript-eslint/no-empty-function': 'off',
14+
'@typescript-eslint/consistent-type-imports': 'error',
15+
'no-return-await': 'error',
16+
'import/no-duplicates': 'error',
17+
'simple-import-sort/imports': [
18+
'error',
19+
{
20+
groups: [
21+
['^\\u0000'],
22+
[`^(${builtins})(/.*)?(?<!\\u0000)$`, `^(${builtins})(/.*)?\\u0000$`],
23+
['(?<!\\u0000)$', '(?<=\\u0000)$'],
24+
['^\\.', '^\\..*\\u0000$'],
25+
],
26+
},
27+
],
28+
},
29+
overrides: [
30+
{
31+
files: ['*.ts'],
32+
rules: {
33+
'@typescript-eslint/explicit-function-return-type': ['error'],
34+
},
35+
},
36+
],
37+
ignorePatterns: ['dist/', 'coverage/'],
38+
};

.github/check_commits.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/sh
2+
3+
head="$(git remote show origin | awk '/HEAD branch/ {print $NF}')"
4+
current="$(git rev-parse HEAD)"
5+
6+
if ! git merge-base --is-ancestor "origin/${head}" "$current"; then
7+
printf "Forgotten to rebase on top of %s.\nExiting with error!\n" "$head"
8+
exit 1
9+
fi
10+
11+
if [ "$(git rev-list --count --merges "origin/${head}..${current}")" -ne 0 ]; then
12+
printf "There are merge commits on the branch.\nExiting with error!\n"
13+
exit 1
14+
fi
15+
16+
echo Branch up-to-date and commits ok.

.github/workflows/ci.yml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: "CI"
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
8+
concurrency:
9+
group: ci-${{ github.head_ref }}
10+
cancel-in-progress: true
11+
12+
jobs:
13+
commits:
14+
name: "Commits"
15+
if: ${{ github.event_name == 'pull_request' }}
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: "Checkout code"
19+
uses: actions/checkout@v2
20+
with:
21+
ref: ${{ github.event.pull_request.head.sha }}
22+
fetch-depth: 0
23+
24+
- name: "Check commits of the PR branch"
25+
run: ./.github/check_commits.sh
26+
27+
linters:
28+
name: "Linters"
29+
needs: commits
30+
if: ${{ !failure() }}
31+
runs-on: ubuntu-latest
32+
steps:
33+
- name: "Checkout code"
34+
uses: actions/checkout@v2
35+
36+
- name: "Set up Node"
37+
uses: actions/setup-node@v2
38+
with:
39+
node-version: '12'
40+
cache: 'yarn'
41+
42+
- name: "Install dependencies"
43+
run: yarn install --frozen-lockfile
44+
45+
- name: "Run linters"
46+
run: yarn lint
47+
48+
build:
49+
name: "Build"
50+
needs: commits
51+
if: ${{ !failure() }}
52+
runs-on: ubuntu-latest
53+
steps:
54+
- name: "Checkout code"
55+
uses: actions/checkout@v2
56+
57+
- name: "Set up Node"
58+
uses: actions/setup-node@v2
59+
with:
60+
node-version: '12'
61+
cache: 'yarn'
62+
63+
- name: "Install dependencies"
64+
run: yarn install --frozen-lockfile
65+
66+
- name: "Build the sources"
67+
run: yarn build
68+
69+
tests:
70+
name: "Tests"
71+
if: ${{ !failure() }}
72+
needs: [linters, build]
73+
strategy:
74+
fail-fast: true
75+
matrix:
76+
node-version: ['12', '14', '16', '17']
77+
78+
runs-on: ubuntu-latest
79+
steps:
80+
- name: "Checkout code"
81+
uses: actions/checkout@v2
82+
83+
- name: "Set up Node ${{ matrix.node-version }}"
84+
uses: actions/setup-node@v2
85+
with:
86+
node-version: ${{ matrix.node-version }}
87+
cache: 'yarn'
88+
89+
- name: "Install dependencies"
90+
run: yarn install --frozen-lockfile
91+
92+
- name: "Run type-checking"
93+
run: yarn type-check
94+
95+
- name: "Run tests"
96+
run: yarn test:cov
97+
98+
- name: "Upload coverage"
99+
if: matrix.node-version == '12'
100+
uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.DS_Store
2+
3+
node_modules/
4+
5+
dist/
6+
*.tgz
7+
*.tsbuildinfo
8+
9+
coverage/
10+
*.log
11+
12+
.idea/
13+
.vscode/

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist/
2+
coverage/

.prettierrc.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "all"
4+
}

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
### Added
11+
12+
- Initial version with Express and Next.js support.

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# apilytics-node
2+
3+
[![ci](https://github.com/apilytics/apilytics-node/actions/workflows/ci.yml/badge.svg)](https://github.com/apilytics/apilytics-node/actions/workflows/ci.yml)
4+
[![codecov](https://codecov.io/gh/apilytics/apilytics-node/branch/master/graph/badge.svg?token=K592YR52WQ)](https://codecov.io/gh/apilytics/apilytics-node)
5+
[![typescript](https://badgen.net/badge/icon/typescript?icon=typescript&label&color=007acc)](https://www.typescriptlang.org)
6+
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
7+
[![license](https://img.shields.io/badge/license-MIT-green)](https://github.com/apilytics/apilytics-node/blob/master/LICENSE)
8+
9+
## Installation
10+
11+
1. Sign up and get your API key from https://apilytics.io - we offer a completely free trial with no credit card required!
12+
13+
2. Check installation directions for your specific framework:
14+
15+
- [**Express**](./packages/express/README.md#installation)
16+
17+
- [**Next.js**](./packages/next/README.md#installation)
18+
19+
- [**Other Node.js Frameworks**](./packages/core/README.md#installation)

jest.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
2+
module.exports = {
3+
preset: 'ts-jest',
4+
testEnvironment: 'node',
5+
moduleDirectories: ['node_modules'],
6+
collectCoverageFrom: ['**/src/**/*.ts'],
7+
};

package.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"private": true,
3+
"workspaces": [
4+
"packages/*"
5+
],
6+
"scripts": {
7+
"prebuild": "yarn --cwd=packages/core build",
8+
"build": "for dir in packages/*; do echo \"$dir\" && yarn --cwd=\"$dir\" build; done",
9+
"clean": "for dir in packages/*; do echo \"$dir\" && yarn --cwd=\"$dir\" clean; done",
10+
"format": "prettier --write '**/*.{ts,js,json}' && eslint --fix --max-warnings=0 --ext=.ts,.js .",
11+
"lint": "prettier --check '**/*.{ts,js,json}' && eslint --max-warnings=0 --ext=.ts,.js .",
12+
"type-check": "yarn tsc --noEmit",
13+
"test": "jest --verbose",
14+
"test:cov": "yarn test --coverage",
15+
"postinstall": "yarn prebuild"
16+
},
17+
"devDependencies": {
18+
"@types/jest": "27.4.0",
19+
"@types/supertest": "2.0.11",
20+
"@typescript-eslint/eslint-plugin": "5.9.0",
21+
"@typescript-eslint/parser": "5.9.0",
22+
"eslint": "8.6.0",
23+
"eslint-plugin-import": "2.25.4",
24+
"eslint-plugin-simple-import-sort": "7.0.0",
25+
"jest": "27.4.7",
26+
"prettier": "2.5.1",
27+
"supertest": "6.1.6",
28+
"ts-jest": "27.1.2",
29+
"typescript": "4.5.4"
30+
}
31+
}

0 commit comments

Comments
 (0)