-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ead7e01
commit 88a0d8f
Showing
18 changed files
with
5,732 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
}] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v18.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"singleQuote": true, | ||
"trailingComma": "es5", | ||
"semi": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.