Skip to content

Commit

Permalink
First commit - it's working
Browse files Browse the repository at this point in the history
  • Loading branch information
osirisguitar committed May 29, 2024
1 parent ead7e01 commit 88a0d8f
Show file tree
Hide file tree
Showing 18 changed files with 5,732 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint", "eslint-plugin-node"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
"plugin:import/typescript",
"plugin:node/recommended"
],
"parserOptions": {
"ecmaVersion": 2020,
"project": "**/tsconfig.json"
},
"env": {
"node": true
},
"settings": {
"node": {
"tryExtensions": [".js", ".ts"]
}
},
"rules": {
"node/no-unsupported-features/es-syntax": ["error", { "ignores": ["modules"] }]
},
"overrides": [{
"files": "src/**/*.test.ts",
"rules": {
"node/no-unpublished-import": 0
}
}]
}
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
./node_modules
./build
build
node_modules
.env
config.json
.DS_Store

# Jetbrains IDE
.idea/

.vscode
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v18.*
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"tabWidth": 2,
"useTabs": false,
"singleQuote": true,
"trailingComma": "es5",
"semi": false
}
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# onecore-utilities

Useful utilities used in various places in the ONECore platform.

## logger

A logger that logs to the console and to ElasticSearch.

### General use

```
import { logger } from 'onecore-utilities'
logger.warn(aMessage)
logger.info(anObject, aMessage)
```

### Koa request logging

loggerMiddlewares.pre will log all incoming requests at the start of the request
loggerMiddlewares.post will log all incoming requests at the end of the request

```
import { loggerMiddlewares } from 'onecore-utilities'
// Log the start and completion of all incoming requests
app.use(loggerMiddlewares.pre)
app.use(loggerMiddlewares.post)
```

### Configuration

Set environment variable `ELASTICSEARCH_LOGGING_HOST` to the full url of your ElasticSearch server.

## loggedAxios

A standard Axios with interceptors for request and response that logs all requests and their
completions to logger, with a subset of fields from the Axios request and response objects.

### Configuration

Set environment variable `ELASTICSEARCH_LOGGING_HOST` to the full url of your ElasticSearch server.

### General use

Use as you would use standard Axios.

```
import { loggedAxios as axios } from 'onecore-utilities'
const response = await axios('http://localhost')
```
14 changes: 14 additions & 0 deletions dist/index.d.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import pino from 'pino';
import Koa from 'koa';
import * as axios from 'axios';

declare const logger: pino.Logger<never>;

declare const middlewares: {
pre: (ctx: Koa.ParameterizedContext<Koa.DefaultState, Koa.DefaultContext, any>, next: Koa.Next) => Promise<any>;
post: (ctx: Koa.ParameterizedContext<Koa.DefaultState, Koa.DefaultContext, any>, next: Koa.Next) => Promise<void>;
};

declare const instance: axios.AxiosInstance;

export { instance as loggedAxios, logger, middlewares as loggerMiddlewares };
14 changes: 14 additions & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import pino from 'pino';
import Koa from 'koa';
import * as axios from 'axios';

declare const logger: pino.Logger<never>;

declare const middlewares: {
pre: (ctx: Koa.ParameterizedContext<Koa.DefaultState, Koa.DefaultContext, any>, next: Koa.Next) => Promise<any>;
post: (ctx: Koa.ParameterizedContext<Koa.DefaultState, Koa.DefaultContext, any>, next: Koa.Next) => Promise<void>;
};

declare const instance: axios.AxiosInstance;

export { instance as loggedAxios, logger, middlewares as loggerMiddlewares };
159 changes: 159 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 88a0d8f

Please sign in to comment.